Spaces:
Running
Running
feat: rename companion to Auri, remove typewriter sound, add JRPG dialogue box, async AI fallback, and unit tests
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- ai_cache.py +101 -0
- ai_provider.py +425 -0
- algospaced-ui/dist/assets/{Auth-57SPE0Nq.js → Auth-B-5KpNfK.js} +1 -1
- algospaced-ui/dist/assets/{CreateProblemForm-D59LwEcw.js → CreateProblemForm-C2nCqjgj.js} +1 -1
- algospaced-ui/dist/assets/{FileExplorer-CniQ6MSb.js → FileExplorer-BX57bI-L.js} +1 -1
- algospaced-ui/dist/assets/{GitHubSyncWindow-B_tOfthS.js → GitHubSyncWindow-D0t6e3o3.js} +1 -1
- algospaced-ui/dist/assets/{JourneyPath-EVMcgmrl.js → JourneyPath-DO-UXRtH.js} +0 -0
- algospaced-ui/dist/assets/{KatexRenderer-CnXeuUOr.js → KatexRenderer-DnoTdlgI.js} +1 -1
- algospaced-ui/dist/assets/{MarkdownRenderer-CWg4XXNt.js → MarkdownRenderer-CC5nUs7-.js} +2 -2
- algospaced-ui/dist/assets/{MySQLPlayground-Co730-U0.js → MySQLPlayground-CA-QZxQM.js} +1 -1
- algospaced-ui/dist/assets/{OnboardingModal-CySUf-WA.js → OnboardingModal-hhKaj0In.js} +1 -1
- algospaced-ui/dist/assets/PrincessChamber-CyKVnuqB.js +0 -1
- algospaced-ui/dist/assets/PrincessChamber-IJaaUuL1.js +1 -0
- algospaced-ui/dist/assets/ProblemSpecPanel-CoULhmZo.js +0 -4
- algospaced-ui/dist/assets/ProblemSpecPanel-Df-cRYRz.js +4 -0
- algospaced-ui/dist/assets/{PythonChallenge-8UlYXBt_.js → PythonChallenge-BUhtEPkm.js} +1 -1
- algospaced-ui/dist/assets/ReviewQueue-BsWCZFit.js +0 -5
- algospaced-ui/dist/assets/ReviewQueue-C250a4ib.js +5 -0
- algospaced-ui/dist/assets/{Settings-LIc5x45z.js → Settings-mOsQagfT.js} +1 -1
- algospaced-ui/dist/assets/{TerminalEmulator-CUwPFl2P.js → TerminalEmulator-DUo8J_0j.js} +1 -1
- algospaced-ui/dist/assets/{index-DttZMwvA.js → index-DYMSjoUb.js} +0 -0
- algospaced-ui/dist/assets/index-Di-5TpeG.css +0 -0
- algospaced-ui/dist/assets/index-supjX07i.css +0 -0
- algospaced-ui/dist/assets/{vendor-react-yvPwY2Sj.js → vendor-react-qmUj3JUi.js} +0 -0
- algospaced-ui/dist/index.html +53 -53
- algospaced-ui/dist/sw.js +1 -1
- algospaced-ui/src/App.tsx +1 -5
- algospaced-ui/src/components/PrincessDialoguePopup.tsx +0 -5
- algospaced-ui/src/components/Settings.tsx +1 -1
- algospaced-ui/src/components/desktop/DesktopStartMenu.tsx +1 -1
- algospaced-ui/src/components/desktop/DesktopTaskbar.tsx +5 -6
- algospaced-ui/src/components/desktop/DesktopWindowContainer.tsx +16 -26
- algospaced-ui/src/components/desktop/MobileMetroScreen.tsx +2 -2
- algospaced-ui/src/features/companion/components/CharacterStage.tsx +44 -59
- algospaced-ui/src/features/companion/components/DialogueBubble.tsx +50 -172
- algospaced-ui/src/features/companion/components/JRPGDialogueBox.tsx +479 -0
- algospaced-ui/src/features/companion/components/PrincessChamber.tsx +170 -147
- algospaced-ui/src/features/companion/components/PrincessToast.tsx +0 -4
- algospaced-ui/src/features/companion/index.ts +1 -0
- algospaced-ui/src/utils/rpgAudio.ts +21 -32
- data/companion_telemetry.json +376 -0
- llm_reviewer.py +480 -0
- pyproject.toml +2 -1
- routers/challenges.py +75 -47
- routers/companion.py +58 -12
- routers/explorer.py +284 -249
- routers/github_sync.py +154 -24
- routers/journey.py +12 -10
- routers/reviews.py +124 -90
- routers/sync.py +5 -3
ai_cache.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import logging
|
| 2 |
import re
|
| 3 |
import threading
|
|
@@ -60,6 +61,44 @@ def get_cached_item(cache_key: str) -> Any | None:
|
|
| 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:
|
|
@@ -85,6 +124,31 @@ def set_cached_item(cache_key: str, value: Any, ttl_seconds: int = 86400 * 30):
|
|
| 85 |
logger.debug(f"Firestore cache set skipped/failed: {e}")
|
| 86 |
|
| 87 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
# --- High-level cache helpers ---
|
| 89 |
|
| 90 |
|
|
@@ -92,33 +156,70 @@ 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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import asyncio
|
| 2 |
import logging
|
| 3 |
import re
|
| 4 |
import threading
|
|
|
|
| 61 |
return None
|
| 62 |
|
| 63 |
|
| 64 |
+
async def get_cached_item_async(cache_key: str) -> Any | None:
|
| 65 |
+
"""Non-blocking async variant checking Memory -> Redis -> Firestore."""
|
| 66 |
+
# Fast in-memory check (no I/O)
|
| 67 |
+
with _cache_lock:
|
| 68 |
+
if cache_key in _memory_cache:
|
| 69 |
+
return _memory_cache[cache_key]
|
| 70 |
+
|
| 71 |
+
def _fetch_remote():
|
| 72 |
+
# Redis (if available)
|
| 73 |
+
try:
|
| 74 |
+
val = cache.get_cache(f"ai_cache:{cache_key}")
|
| 75 |
+
if val:
|
| 76 |
+
with _cache_lock:
|
| 77 |
+
_memory_cache[cache_key] = val
|
| 78 |
+
return val
|
| 79 |
+
except Exception:
|
| 80 |
+
pass
|
| 81 |
+
|
| 82 |
+
# Firestore (if available)
|
| 83 |
+
try:
|
| 84 |
+
firestore_client = db.init_firebase()
|
| 85 |
+
if firestore_client:
|
| 86 |
+
doc_ref = firestore_client.collection("ai_cache").document(cache_key)
|
| 87 |
+
doc = doc_ref.get()
|
| 88 |
+
if doc.exists:
|
| 89 |
+
data = doc.to_dict()
|
| 90 |
+
cached_val = data.get("payload") if data and "payload" in data else data
|
| 91 |
+
if cached_val:
|
| 92 |
+
with _cache_lock:
|
| 93 |
+
_memory_cache[cache_key] = cached_val
|
| 94 |
+
return cached_val
|
| 95 |
+
except Exception as e:
|
| 96 |
+
logger.debug(f"Firestore cache fetch skipped/failed: {e}")
|
| 97 |
+
return None
|
| 98 |
+
|
| 99 |
+
return await asyncio.to_thread(_fetch_remote)
|
| 100 |
+
|
| 101 |
+
|
| 102 |
def set_cached_item(cache_key: str, value: Any, ttl_seconds: int = 86400 * 30):
|
| 103 |
"""Saves to Memory -> Redis -> Firestore."""
|
| 104 |
if not value or not cache_key:
|
|
|
|
| 124 |
logger.debug(f"Firestore cache set skipped/failed: {e}")
|
| 125 |
|
| 126 |
|
| 127 |
+
async def set_cached_item_async(cache_key: str, value: Any, ttl_seconds: int = 86400 * 30):
|
| 128 |
+
"""Non-blocking async variant saving to Memory -> Redis -> Firestore."""
|
| 129 |
+
if not value or not cache_key:
|
| 130 |
+
return
|
| 131 |
+
|
| 132 |
+
with _cache_lock:
|
| 133 |
+
_memory_cache[cache_key] = value
|
| 134 |
+
|
| 135 |
+
def _persist_remote():
|
| 136 |
+
try:
|
| 137 |
+
cache.set_cache(f"ai_cache:{cache_key}", value, ttl_seconds=ttl_seconds)
|
| 138 |
+
except Exception:
|
| 139 |
+
pass
|
| 140 |
+
|
| 141 |
+
try:
|
| 142 |
+
firestore_client = db.init_firebase()
|
| 143 |
+
if firestore_client:
|
| 144 |
+
doc_ref = firestore_client.collection("ai_cache").document(cache_key)
|
| 145 |
+
doc_ref.set({"payload": value, "cached_at": datetime.now(UTC).isoformat()})
|
| 146 |
+
except Exception as e:
|
| 147 |
+
logger.debug(f"Firestore cache set skipped/failed: {e}")
|
| 148 |
+
|
| 149 |
+
await asyncio.to_thread(_persist_remote)
|
| 150 |
+
|
| 151 |
+
|
| 152 |
# --- High-level cache helpers ---
|
| 153 |
|
| 154 |
|
|
|
|
| 156 |
return get_cached_item(f"daily_python_{date_str}")
|
| 157 |
|
| 158 |
|
| 159 |
+
async def get_daily_python_challenge_async(date_str: str) -> dict[str, Any] | None:
|
| 160 |
+
return await get_cached_item_async(f"daily_python_{date_str}")
|
| 161 |
+
|
| 162 |
+
|
| 163 |
def set_daily_python_challenge(date_str: str, challenge: dict[str, Any]):
|
| 164 |
set_cached_item(f"daily_python_{date_str}", challenge, ttl_seconds=86400 * 7)
|
| 165 |
|
| 166 |
|
| 167 |
+
async def set_daily_python_challenge_async(date_str: str, challenge: dict[str, Any]):
|
| 168 |
+
await set_cached_item_async(f"daily_python_{date_str}", challenge, ttl_seconds=86400 * 7)
|
| 169 |
+
|
| 170 |
+
|
| 171 |
def get_daily_sql_challenge(date_str: str) -> dict[str, Any] | None:
|
| 172 |
return get_cached_item(f"daily_sql_{date_str}")
|
| 173 |
|
| 174 |
|
| 175 |
+
async def get_daily_sql_challenge_async(date_str: str) -> dict[str, Any] | None:
|
| 176 |
+
return await get_cached_item_async(f"daily_sql_{date_str}")
|
| 177 |
+
|
| 178 |
+
|
| 179 |
def set_daily_sql_challenge(date_str: str, challenge: dict[str, Any]):
|
| 180 |
set_cached_item(f"daily_sql_{date_str}", challenge, ttl_seconds=86400 * 7)
|
| 181 |
|
| 182 |
|
| 183 |
+
async def set_daily_sql_challenge_async(date_str: str, challenge: dict[str, Any]):
|
| 184 |
+
await set_cached_item_async(f"daily_sql_{date_str}", challenge, ttl_seconds=86400 * 7)
|
| 185 |
+
|
| 186 |
+
|
| 187 |
def get_leetcode_problem(slug_or_url: str) -> dict[str, Any] | None:
|
| 188 |
slug = normalize_slug(slug_or_url)
|
| 189 |
return get_cached_item(f"leetcode_meta_{slug}")
|
| 190 |
|
| 191 |
|
| 192 |
+
async def get_leetcode_problem_async(slug_or_url: str) -> dict[str, Any] | None:
|
| 193 |
+
slug = normalize_slug(slug_or_url)
|
| 194 |
+
return await get_cached_item_async(f"leetcode_meta_{slug}")
|
| 195 |
+
|
| 196 |
+
|
| 197 |
def set_leetcode_problem(slug_or_url: str, data: dict[str, Any]):
|
| 198 |
slug = normalize_slug(slug_or_url)
|
| 199 |
set_cached_item(f"leetcode_meta_{slug}", data, ttl_seconds=86400 * 90)
|
| 200 |
|
| 201 |
|
| 202 |
+
async def set_leetcode_problem_async(slug_or_url: str, data: dict[str, Any]):
|
| 203 |
+
slug = normalize_slug(slug_or_url)
|
| 204 |
+
await set_cached_item_async(f"leetcode_meta_{slug}", data, ttl_seconds=86400 * 90)
|
| 205 |
+
|
| 206 |
+
|
| 207 |
def get_leetcode_intuition(slug_or_title: str) -> dict[str, Any] | None:
|
| 208 |
slug = normalize_slug(slug_or_title)
|
| 209 |
return get_cached_item(f"leetcode_intuition_{slug}")
|
| 210 |
|
| 211 |
|
| 212 |
+
async def get_leetcode_intuition_async(slug_or_title: str) -> dict[str, Any] | None:
|
| 213 |
+
slug = normalize_slug(slug_or_title)
|
| 214 |
+
return await get_cached_item_async(f"leetcode_intuition_{slug}")
|
| 215 |
+
|
| 216 |
+
|
| 217 |
def set_leetcode_intuition(slug_or_title: str, data: dict[str, Any]):
|
| 218 |
slug = normalize_slug(slug_or_title)
|
| 219 |
set_cached_item(f"leetcode_intuition_{slug}", data, ttl_seconds=86400 * 90)
|
| 220 |
+
|
| 221 |
+
|
| 222 |
+
async def set_leetcode_intuition_async(slug_or_title: str, data: dict[str, Any]):
|
| 223 |
+
slug = normalize_slug(slug_or_title)
|
| 224 |
+
await set_cached_item_async(f"leetcode_intuition_{slug}", data, ttl_seconds=86400 * 90)
|
| 225 |
+
|
ai_provider.py
CHANGED
|
@@ -5,6 +5,8 @@ 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")
|
|
@@ -422,3 +424,426 @@ def stream_ai_content(
|
|
| 422 |
custom_api_key=custom_api_key,
|
| 423 |
)
|
| 424 |
yield text, provider
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
import urllib.request
|
| 6 |
from typing import Any
|
| 7 |
|
| 8 |
+
import httpx
|
| 9 |
+
|
| 10 |
from gdrive_sync import get_secret
|
| 11 |
|
| 12 |
logger = logging.getLogger("ai_provider")
|
|
|
|
| 424 |
custom_api_key=custom_api_key,
|
| 425 |
)
|
| 426 |
yield text, provider
|
| 427 |
+
|
| 428 |
+
|
| 429 |
+
def generate_text(
|
| 430 |
+
prompt: str,
|
| 431 |
+
custom_api_key: str | None = None,
|
| 432 |
+
custom_provider: str | None = None,
|
| 433 |
+
) -> dict[str, Any]:
|
| 434 |
+
"""Helper for single-prompt text generation."""
|
| 435 |
+
try:
|
| 436 |
+
text, provider = generate_ai_content(
|
| 437 |
+
system_instruction="You are an expert programming assistant.",
|
| 438 |
+
user_prompt=prompt,
|
| 439 |
+
is_json=False,
|
| 440 |
+
custom_provider=custom_provider,
|
| 441 |
+
custom_api_key=custom_api_key,
|
| 442 |
+
)
|
| 443 |
+
return {"text": text, "provider": provider}
|
| 444 |
+
except Exception as e:
|
| 445 |
+
logger.error(f"Error in generate_text: {e}")
|
| 446 |
+
return {"text": "", "error": str(e)}
|
| 447 |
+
|
| 448 |
+
|
| 449 |
+
async def generate_text_async(
|
| 450 |
+
prompt: str,
|
| 451 |
+
custom_api_key: str | None = None,
|
| 452 |
+
custom_provider: str | None = None,
|
| 453 |
+
) -> dict[str, Any]:
|
| 454 |
+
"""Helper for async single-prompt text generation."""
|
| 455 |
+
try:
|
| 456 |
+
text, provider = await generate_ai_content_async(
|
| 457 |
+
system_instruction="You are an expert programming assistant.",
|
| 458 |
+
user_prompt=prompt,
|
| 459 |
+
is_json=False,
|
| 460 |
+
custom_provider=custom_provider,
|
| 461 |
+
custom_api_key=custom_api_key,
|
| 462 |
+
)
|
| 463 |
+
return {"text": text, "provider": provider}
|
| 464 |
+
except Exception as e:
|
| 465 |
+
logger.error(f"Error in generate_text_async: {e}")
|
| 466 |
+
return {"text": "", "error": str(e)}
|
| 467 |
+
|
| 468 |
+
|
| 469 |
+
async def call_gemini_async(
|
| 470 |
+
api_key: str, system_instruction: str, user_prompt: str, is_json: bool = False
|
| 471 |
+
) -> str:
|
| 472 |
+
"""Calls Google Gemini API asynchronously with fallback models."""
|
| 473 |
+
models = [
|
| 474 |
+
"gemini-3.5-flash-lite",
|
| 475 |
+
"gemini-2.5-flash",
|
| 476 |
+
"gemini-3.7-flash",
|
| 477 |
+
"gemini-2.5-flash-lite",
|
| 478 |
+
"gemini-3.5-flash",
|
| 479 |
+
"gemini-2.5-pro",
|
| 480 |
+
"gemini-2.0-flash",
|
| 481 |
+
"gemini-1.5-flash",
|
| 482 |
+
]
|
| 483 |
+
|
| 484 |
+
# If official SDK is available
|
| 485 |
+
if genai is not None:
|
| 486 |
+
client = genai.Client(api_key=api_key)
|
| 487 |
+
last_err = None
|
| 488 |
+
for model_name in models:
|
| 489 |
+
try:
|
| 490 |
+
config = (
|
| 491 |
+
types.GenerateContentConfig(
|
| 492 |
+
system_instruction=system_instruction,
|
| 493 |
+
response_mime_type="application/json",
|
| 494 |
+
)
|
| 495 |
+
if is_json
|
| 496 |
+
else types.GenerateContentConfig(
|
| 497 |
+
system_instruction=system_instruction,
|
| 498 |
+
)
|
| 499 |
+
)
|
| 500 |
+
response = await client.aio.models.generate_content(
|
| 501 |
+
model=model_name, contents=user_prompt, config=config
|
| 502 |
+
)
|
| 503 |
+
if response and hasattr(response, "text") and response.text:
|
| 504 |
+
return response.text
|
| 505 |
+
except Exception as e:
|
| 506 |
+
last_err = e
|
| 507 |
+
logger.warning(f"Gemini async model {model_name} failed: {e}")
|
| 508 |
+
continue
|
| 509 |
+
if last_err:
|
| 510 |
+
raise last_err
|
| 511 |
+
raise RuntimeError("Gemini failed to return text")
|
| 512 |
+
|
| 513 |
+
# Fallback to direct REST call via httpx if SDK missing
|
| 514 |
+
last_err = None
|
| 515 |
+
async with httpx.AsyncClient(timeout=30.0) as http_client:
|
| 516 |
+
for model_name in models:
|
| 517 |
+
try:
|
| 518 |
+
url = f"https://generativelanguage.googleapis.com/v1beta/models/{model_name}:generateContent?key={api_key}"
|
| 519 |
+
payload = {
|
| 520 |
+
"contents": [{"parts": [{"text": user_prompt}]}],
|
| 521 |
+
"systemInstruction": {"parts": [{"text": system_instruction}]},
|
| 522 |
+
}
|
| 523 |
+
if is_json:
|
| 524 |
+
payload["generationConfig"] = {"responseMimeType": "application/json"}
|
| 525 |
+
|
| 526 |
+
resp = await http_client.post(
|
| 527 |
+
url, json=payload, headers={"Content-Type": "application/json"}
|
| 528 |
+
)
|
| 529 |
+
if resp.status_code == 200:
|
| 530 |
+
data = resp.json()
|
| 531 |
+
candidates = data.get("candidates", [])
|
| 532 |
+
if candidates:
|
| 533 |
+
parts = candidates[0].get("content", {}).get("parts", [])
|
| 534 |
+
if parts:
|
| 535 |
+
return parts[0].get("text", "")
|
| 536 |
+
else:
|
| 537 |
+
err_text = resp.text[:300]
|
| 538 |
+
last_err = RuntimeError(f"Gemini {model_name} HTTP {resp.status_code}: {err_text}")
|
| 539 |
+
logger.warning(f"Gemini async REST model {model_name} returned {resp.status_code}: {err_text}")
|
| 540 |
+
except Exception as e:
|
| 541 |
+
last_err = e
|
| 542 |
+
continue
|
| 543 |
+
if last_err:
|
| 544 |
+
raise last_err
|
| 545 |
+
raise RuntimeError("Gemini REST API failed")
|
| 546 |
+
|
| 547 |
+
|
| 548 |
+
async def stream_gemini_async(
|
| 549 |
+
api_key: str, system_instruction: str, user_prompt: str, is_json: bool = False
|
| 550 |
+
):
|
| 551 |
+
"""Streams Google Gemini API responses chunk by chunk asynchronously."""
|
| 552 |
+
models = [
|
| 553 |
+
"gemini-2.5-flash",
|
| 554 |
+
"gemini-3.5-flash-lite",
|
| 555 |
+
"gemini-3.7-flash",
|
| 556 |
+
"gemini-2.5-flash-lite",
|
| 557 |
+
"gemini-3.5-flash",
|
| 558 |
+
"gemini-2.0-flash",
|
| 559 |
+
"gemini-1.5-flash",
|
| 560 |
+
]
|
| 561 |
+
if genai is not None:
|
| 562 |
+
client = genai.Client(api_key=api_key)
|
| 563 |
+
for model_name in models:
|
| 564 |
+
has_yielded = False
|
| 565 |
+
try:
|
| 566 |
+
config = (
|
| 567 |
+
types.GenerateContentConfig(
|
| 568 |
+
system_instruction=system_instruction,
|
| 569 |
+
response_mime_type="application/json",
|
| 570 |
+
)
|
| 571 |
+
if is_json
|
| 572 |
+
else types.GenerateContentConfig(
|
| 573 |
+
system_instruction=system_instruction,
|
| 574 |
+
)
|
| 575 |
+
)
|
| 576 |
+
response = await client.aio.models.generate_content_stream(
|
| 577 |
+
model=model_name, contents=user_prompt, config=config
|
| 578 |
+
)
|
| 579 |
+
async for chunk in response:
|
| 580 |
+
if chunk and hasattr(chunk, "text") and chunk.text:
|
| 581 |
+
has_yielded = True
|
| 582 |
+
yield chunk.text
|
| 583 |
+
if has_yielded:
|
| 584 |
+
return
|
| 585 |
+
except Exception as e:
|
| 586 |
+
logger.warning(f"Gemini async streaming model {model_name} failed: {e}")
|
| 587 |
+
if has_yielded:
|
| 588 |
+
# Stream has already partially sent data to client; do not duplicate
|
| 589 |
+
return
|
| 590 |
+
continue
|
| 591 |
+
|
| 592 |
+
# Fallback to standard async call if streaming fails or SDK missing
|
| 593 |
+
full_text = await call_gemini_async(api_key, system_instruction, user_prompt, is_json=is_json)
|
| 594 |
+
if full_text:
|
| 595 |
+
yield full_text
|
| 596 |
+
|
| 597 |
+
|
| 598 |
+
async def call_groq_async(
|
| 599 |
+
api_key: str, system_instruction: str, user_prompt: str, is_json: bool = False
|
| 600 |
+
) -> str:
|
| 601 |
+
"""Calls Groq Cloud API asynchronously."""
|
| 602 |
+
models = [
|
| 603 |
+
"qwen/qwen3.8-27b",
|
| 604 |
+
"openai/gpt-oss-20b",
|
| 605 |
+
"qwen/qwen3.6-27b",
|
| 606 |
+
"openai/gpt-oss-120b",
|
| 607 |
+
"groq/compound-mini",
|
| 608 |
+
"groq/compound",
|
| 609 |
+
]
|
| 610 |
+
url = "https://api.groq.com/openai/v1/chat/completions"
|
| 611 |
+
last_err = None
|
| 612 |
+
|
| 613 |
+
async with httpx.AsyncClient(timeout=30.0) as http_client:
|
| 614 |
+
for model_name in models:
|
| 615 |
+
try:
|
| 616 |
+
payload: dict[str, Any] = {
|
| 617 |
+
"model": model_name,
|
| 618 |
+
"messages": [
|
| 619 |
+
{"role": "system", "content": system_instruction},
|
| 620 |
+
{"role": "user", "content": user_prompt},
|
| 621 |
+
],
|
| 622 |
+
"temperature": 0.2,
|
| 623 |
+
}
|
| 624 |
+
if is_json:
|
| 625 |
+
payload["response_format"] = {"type": "json_object"}
|
| 626 |
+
|
| 627 |
+
headers = {
|
| 628 |
+
"Content-Type": "application/json",
|
| 629 |
+
"Authorization": f"Bearer {api_key}",
|
| 630 |
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AlgoSpaced/1.0",
|
| 631 |
+
}
|
| 632 |
+
resp = await http_client.post(url, json=payload, headers=headers)
|
| 633 |
+
if resp.status_code == 200:
|
| 634 |
+
data = resp.json()
|
| 635 |
+
choices = data.get("choices", [])
|
| 636 |
+
if choices:
|
| 637 |
+
content = choices[0].get("message", {}).get("content", "")
|
| 638 |
+
if content:
|
| 639 |
+
return content
|
| 640 |
+
else:
|
| 641 |
+
err_text = resp.text[:300]
|
| 642 |
+
last_err = RuntimeError(f"Groq {model_name} HTTP {resp.status_code}: {err_text}")
|
| 643 |
+
logger.warning(f"Groq async model {model_name} returned {resp.status_code}: {err_text}")
|
| 644 |
+
except Exception as e:
|
| 645 |
+
last_err = e
|
| 646 |
+
logger.warning(f"Groq async model {model_name} failed: {e}")
|
| 647 |
+
continue
|
| 648 |
+
|
| 649 |
+
if last_err:
|
| 650 |
+
raise last_err
|
| 651 |
+
raise RuntimeError("Groq failed to return content")
|
| 652 |
+
|
| 653 |
+
|
| 654 |
+
async def call_openrouter_async(
|
| 655 |
+
api_key: str, system_instruction: str, user_prompt: str, is_json: bool = False
|
| 656 |
+
) -> str:
|
| 657 |
+
"""Calls OpenRouter API asynchronously."""
|
| 658 |
+
models = [
|
| 659 |
+
"openrouter/free",
|
| 660 |
+
"deepseek/deepseek-chat",
|
| 661 |
+
"meta-llama/llama-3.3-70b-instruct",
|
| 662 |
+
"minimax/minimax-m2.7:free",
|
| 663 |
+
"google/gemma-4-31b-it:free",
|
| 664 |
+
"meta-llama/llama-3.1-8b-instruct:free",
|
| 665 |
+
]
|
| 666 |
+
url = "https://openrouter.ai/api/v1/chat/completions"
|
| 667 |
+
last_err = None
|
| 668 |
+
|
| 669 |
+
async with httpx.AsyncClient(timeout=30.0) as http_client:
|
| 670 |
+
for model_name in models:
|
| 671 |
+
try:
|
| 672 |
+
payload: dict[str, Any] = {
|
| 673 |
+
"model": model_name,
|
| 674 |
+
"messages": [
|
| 675 |
+
{"role": "system", "content": system_instruction},
|
| 676 |
+
{"role": "user", "content": user_prompt},
|
| 677 |
+
],
|
| 678 |
+
"temperature": 0.2,
|
| 679 |
+
}
|
| 680 |
+
if is_json:
|
| 681 |
+
payload["response_format"] = {"type": "json_object"}
|
| 682 |
+
|
| 683 |
+
headers = {
|
| 684 |
+
"Content-Type": "application/json",
|
| 685 |
+
"Authorization": f"Bearer {api_key}",
|
| 686 |
+
"HTTP-Referer": "https://algospaced.io",
|
| 687 |
+
"X-Title": "AlgoSpaced DSA",
|
| 688 |
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AlgoSpaced/1.0",
|
| 689 |
+
}
|
| 690 |
+
resp = await http_client.post(url, json=payload, headers=headers)
|
| 691 |
+
if resp.status_code == 200:
|
| 692 |
+
data = resp.json()
|
| 693 |
+
choices = data.get("choices", [])
|
| 694 |
+
if choices:
|
| 695 |
+
content = choices[0].get("message", {}).get("content", "")
|
| 696 |
+
if content:
|
| 697 |
+
return content
|
| 698 |
+
else:
|
| 699 |
+
err_text = resp.text[:300]
|
| 700 |
+
last_err = RuntimeError(f"OpenRouter {model_name} HTTP {resp.status_code}: {err_text}")
|
| 701 |
+
logger.warning(f"OpenRouter async model {model_name} returned {resp.status_code}: {err_text}")
|
| 702 |
+
except Exception as e:
|
| 703 |
+
last_err = e
|
| 704 |
+
logger.warning(f"OpenRouter async model {model_name} failed: {e}")
|
| 705 |
+
continue
|
| 706 |
+
|
| 707 |
+
if last_err:
|
| 708 |
+
raise last_err
|
| 709 |
+
raise RuntimeError("OpenRouter failed to return content")
|
| 710 |
+
|
| 711 |
+
|
| 712 |
+
async def generate_ai_content_async(
|
| 713 |
+
system_instruction: str,
|
| 714 |
+
user_prompt: str,
|
| 715 |
+
is_json: bool = False,
|
| 716 |
+
custom_provider: str | None = None,
|
| 717 |
+
custom_api_key: str | None = None,
|
| 718 |
+
) -> tuple[str, str]:
|
| 719 |
+
"""
|
| 720 |
+
Unified multi-provider AI dispatcher with automatic failover (async).
|
| 721 |
+
Returns tuple of (response_text, provider_used).
|
| 722 |
+
"""
|
| 723 |
+
# 1. Custom BYOK Request
|
| 724 |
+
if custom_api_key and custom_api_key.strip():
|
| 725 |
+
key = custom_api_key.strip()
|
| 726 |
+
provider = detect_provider(custom_provider, key)
|
| 727 |
+
if provider == "groq":
|
| 728 |
+
text = await call_groq_async(key, system_instruction, user_prompt, is_json=is_json)
|
| 729 |
+
return text, "groq (custom)"
|
| 730 |
+
elif provider == "openrouter":
|
| 731 |
+
text = await call_openrouter_async(
|
| 732 |
+
key, system_instruction, user_prompt, is_json=is_json
|
| 733 |
+
)
|
| 734 |
+
return text, "openrouter (custom)"
|
| 735 |
+
else:
|
| 736 |
+
text = await call_gemini_async(key, system_instruction, user_prompt, is_json=is_json)
|
| 737 |
+
return text, "gemini (custom)"
|
| 738 |
+
|
| 739 |
+
# 2. Server Shared Default Tier (Multi-Provider Fallback Chain)
|
| 740 |
+
gemini_key = get_secret("GEMINI_API_KEY")
|
| 741 |
+
groq_key = get_secret("GROQ_API_KEY")
|
| 742 |
+
openrouter_key = get_secret("OPENROUTER_API_KEY")
|
| 743 |
+
|
| 744 |
+
errors: list[str] = []
|
| 745 |
+
|
| 746 |
+
# Priority 1: Gemini
|
| 747 |
+
if gemini_key:
|
| 748 |
+
try:
|
| 749 |
+
text = await call_gemini_async(
|
| 750 |
+
gemini_key, system_instruction, user_prompt, is_json=is_json
|
| 751 |
+
)
|
| 752 |
+
return text, "gemini (server)"
|
| 753 |
+
except Exception as e:
|
| 754 |
+
err_msg = f"Gemini server key failed: {e}"
|
| 755 |
+
logger.warning(err_msg)
|
| 756 |
+
errors.append(err_msg)
|
| 757 |
+
|
| 758 |
+
# Priority 2: Groq (if available on server)
|
| 759 |
+
if groq_key:
|
| 760 |
+
try:
|
| 761 |
+
text = await call_groq_async(groq_key, system_instruction, user_prompt, is_json=is_json)
|
| 762 |
+
return text, "groq (server fallback)"
|
| 763 |
+
except Exception as e:
|
| 764 |
+
err_msg = f"Groq server key failed: {e}"
|
| 765 |
+
logger.warning(err_msg)
|
| 766 |
+
errors.append(err_msg)
|
| 767 |
+
|
| 768 |
+
# Priority 3: OpenRouter (if available on server)
|
| 769 |
+
if openrouter_key:
|
| 770 |
+
try:
|
| 771 |
+
text = await call_openrouter_async(
|
| 772 |
+
openrouter_key, system_instruction, user_prompt, is_json=is_json
|
| 773 |
+
)
|
| 774 |
+
return text, "openrouter (server fallback)"
|
| 775 |
+
except Exception as e:
|
| 776 |
+
err_msg = f"OpenRouter server key failed: {e}"
|
| 777 |
+
logger.warning(err_msg)
|
| 778 |
+
errors.append(err_msg)
|
| 779 |
+
|
| 780 |
+
if not (gemini_key or groq_key or openrouter_key):
|
| 781 |
+
raise RuntimeError(
|
| 782 |
+
"No AI API keys configured on server. Please configure your API key in Settings."
|
| 783 |
+
)
|
| 784 |
+
|
| 785 |
+
raise RuntimeError(f"All AI providers failed. Summary of errors: {'; '.join(errors)}")
|
| 786 |
+
|
| 787 |
+
|
| 788 |
+
async def stream_ai_content_async(
|
| 789 |
+
system_instruction: str,
|
| 790 |
+
user_prompt: str,
|
| 791 |
+
is_json: bool = False,
|
| 792 |
+
custom_provider: str | None = None,
|
| 793 |
+
custom_api_key: str | None = None,
|
| 794 |
+
):
|
| 795 |
+
"""
|
| 796 |
+
Streams AI content chunks asynchronously. Yields tuples of (chunk_text, provider_name).
|
| 797 |
+
"""
|
| 798 |
+
# 1. Custom BYOK Request
|
| 799 |
+
if custom_api_key and custom_api_key.strip():
|
| 800 |
+
key = custom_api_key.strip()
|
| 801 |
+
provider = detect_provider(custom_provider, key)
|
| 802 |
+
if provider == "gemini":
|
| 803 |
+
async for chunk in stream_gemini_async(
|
| 804 |
+
key, system_instruction, user_prompt, is_json=is_json
|
| 805 |
+
):
|
| 806 |
+
yield chunk, "gemini (custom)"
|
| 807 |
+
return
|
| 808 |
+
elif provider == "groq":
|
| 809 |
+
text = await call_groq_async(key, system_instruction, user_prompt, is_json=is_json)
|
| 810 |
+
yield text, "groq (custom)"
|
| 811 |
+
return
|
| 812 |
+
elif provider == "openrouter":
|
| 813 |
+
text = await call_openrouter_async(
|
| 814 |
+
key, system_instruction, user_prompt, is_json=is_json
|
| 815 |
+
)
|
| 816 |
+
yield text, "openrouter (custom)"
|
| 817 |
+
return
|
| 818 |
+
else:
|
| 819 |
+
async for chunk in stream_gemini_async(
|
| 820 |
+
key, system_instruction, user_prompt, is_json=is_json
|
| 821 |
+
):
|
| 822 |
+
yield chunk, "gemini (custom)"
|
| 823 |
+
return
|
| 824 |
+
|
| 825 |
+
# 2. Server Shared Default Tier
|
| 826 |
+
gemini_key = get_secret("GEMINI_API_KEY")
|
| 827 |
+
has_yielded_server = False
|
| 828 |
+
if gemini_key:
|
| 829 |
+
try:
|
| 830 |
+
async for chunk in stream_gemini_async(
|
| 831 |
+
gemini_key, system_instruction, user_prompt, is_json=is_json
|
| 832 |
+
):
|
| 833 |
+
has_yielded_server = True
|
| 834 |
+
yield chunk, "gemini (server)"
|
| 835 |
+
return
|
| 836 |
+
except Exception as e:
|
| 837 |
+
logger.warning(f"Gemini server async stream failed: {e}")
|
| 838 |
+
if has_yielded_server:
|
| 839 |
+
return
|
| 840 |
+
|
| 841 |
+
# Fallback to standard async generation
|
| 842 |
+
text, provider = await generate_ai_content_async(
|
| 843 |
+
system_instruction=system_instruction,
|
| 844 |
+
user_prompt=user_prompt,
|
| 845 |
+
is_json=is_json,
|
| 846 |
+
custom_provider=custom_provider,
|
| 847 |
+
custom_api_key=custom_api_key,
|
| 848 |
+
)
|
| 849 |
+
yield text, provider
|
algospaced-ui/dist/assets/{Auth-57SPE0Nq.js → Auth-B-5KpNfK.js}
RENAMED
|
@@ -1 +1 @@
|
|
| 1 |
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Lt as t,Tt as n,U as r,V as i,j as a,q as o,s,x as c,yt as l,zt as u}from"./vendor-react-yvPwY2Sj.js";import{t as d}from"./firebaseClient-G7klkuBb.js";var f=e(u(),1),p=t();function m(){let[e,t]=(0,f.useState)(!1),[u,m]=(0,f.useState)(``),[h,g]=(0,f.useState)(``),[_,v]=(0,f.useState)(``),[y,b]=(0,f.useState)(!1),[x,S]=(0,f.useState)(!1),[C,w]=(0,f.useState)(null),T=h.length>=8,E=/[A-Z]/.test(h),D=/[a-z]/.test(h),O=/[0-9]/.test(h),k=/[!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?~`]/.test(h),A=h.length>0&&h===_,j=T&&E&&D&&O&&k;return(0,p.jsxs)(`div`,{className:`fixed inset-0 w-full h-full max-h-[100dvh] overflow-y-auto overscroll-contain custom-scrollbar flex flex-col items-center px-3 pt-3 pb-8 sm:px-4 sm:py-6 md:p-8 relative isolate selection:bg-highlight-pink selection:text-white`,children:[(0,p.jsx)(`div`,{className:`fixed inset-0 w-full h-full bg-cover bg-center z-0 saturate-150 contrast-125 pointer-events-none`,style:{backgroundImage:`url('/wallpapers/default.webp')`}}),(0,p.jsxs)(`div`,{className:`w-full max-w-md bg-paper-white border-[4px] border-ink-black window-shadow z-10 flex flex-col overflow-hidden shadow-[inset_2px_2px_0px_rgba(255,255,255,0.8)] relative my-auto shrink-0`,children:[(0,p.jsx)(`div`,{className:`bg-[#0ea5e9] border-b-[4px] border-ink-black px-3 sm:px-4 py-2 sm:py-2.5 flex justify-between items-center text-ink-black select-none`,children:(0,p.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,p.jsx)(`span`,{className:`material-symbols-outlined select-none text-base sm:text-xl`,style:{fontVariationSettings:`'FILL' 1`},children:`sports_esports`}),(0,p.jsx)(`span`,{className:`font-window-title text-xs sm:text-base font-bold tracking-wide`,children:`System_Setup.exe`})]})}),(0,p.jsxs)(`div`,{className:`p-4 sm:p-6 bg-[#fdf8e1] flex-1 flex flex-col`,children:[typeof window<`u`&&window.self!==window.top&&(0,p.jsxs)(`div`,{className:`mb-4 sm:mb-5 p-3 sm:p-3.5 border-[3px] border-[#ea580c] bg-[#ffedd5] text-[#9a3412] text-xs font-bold font-arcade leading-relaxed shadow-[2px_2px_0px_0px_rgba(30,41,59,1)]`,children:[`⚠️ RUNNING INSIDE IFRAME`,(0,p.jsx)(`p`,{className:`mt-1 font-sans text-[11px] font-normal text-ink-black normal-case leading-normal`,children:`If Google Sign-In popup is restricted inside Hugging Face wrapper, open the standalone link below:`}),(0,p.jsx)(`a`,{href:`https://iamfebin-algospaced-dsa.hf.space/`,target:`_top`,className:`mt-2.5 inline-block w-full text-center bg-[#ea580c] hover:bg-[#c2410c] text-white border-[2.5px] border-ink-black py-1.5 px-3 rounded-lg font-window-title text-xs font-bold transition-all shadow-[1.5px_1.5px_0px_rgba(0,0,0,1)] active:translate-y-0.5 active:shadow-none`,children:`OPEN FULLSCREEN / DIRECT SITE`})]}),(0,p.jsxs)(`div`,{className:`flex flex-col items-center mb-4 sm:mb-6`,children:[(0,p.jsx)(`div`,{className:`w-12 h-12 sm:w-16 sm:h-16 bg-paper-white border-[3px] border-ink-black flex items-center justify-center gadget-shadow shadow-[inset_2px_2px_0px_rgba(255,255,255,0.8)] mb-2.5 sm:mb-4`,children:(0,p.jsx)(c,{className:`w-7 h-7 sm:w-9 sm:h-9 text-primary`})}),(0,p.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,p.jsx)(`h2`,{className:`text-2xl sm:text-3xl font-extrabold tracking-tight text-ink-black font-headline-md leading-none m-0`,children:`AlgoSpaced`}),(0,p.jsx)(`span`,{className:`text-[9px] sm:text-[10px] font-arcade bg-[#facc15] text-ink-black font-extrabold px-1.5 sm:px-2 py-0.5 border-[2px] border-ink-black shadow-[2px_2px_0px_0px_#1E293B] uppercase rotate-[-3deg]`,children:`BETA`})]}),(0,p.jsx)(`p`,{className:`text-[10px] sm:text-xs font-arcade text-trash-gray mt-1.5 sm:mt-2 tracking-wide uppercase text-center`,children:`Spaced Repetition for DSA`})]}),(0,p.jsxs)(`div`,{className:`flex gap-2 mb-4 sm:mb-6 font-arcade text-[9px] sm:text-[10px]`,children:[(0,p.jsx)(`button`,{onClick:()=>{t(!1),w(null)},className:`flex-1 py-2 sm:py-2.5 border-[3px] border-ink-black cursor-pointer font-bold tracking-wider outline-none transition-all shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] active:shadow-none active:translate-y-0.5 ${e?`bg-white text-slate-700 hover:bg-surface-container`:`bg-secondary-container text-ink-black translate-y-0.5 shadow-[1px_1px_0px_0px_rgba(30,41,59,1)]`}`,children:`SIGN IN`}),(0,p.jsx)(`button`,{onClick:()=>{t(!0),w(null)},className:`flex-1 py-2 sm:py-2.5 border-[3px] border-ink-black cursor-pointer font-bold tracking-wider outline-none transition-all shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] active:shadow-none active:translate-y-0.5 ${e?`bg-secondary-container text-ink-black translate-y-0.5 shadow-[1px_1px_0px_0px_rgba(30,41,59,1)]`:`bg-white text-slate-700 hover:bg-surface-container`}`,children:`CREATE ACCOUNT`})]}),C&&(0,p.jsxs)(`div`,{className:`mb-4 sm:mb-6 p-3 sm:p-4 border-[3px] border-ink-black text-xs font-arcade leading-relaxed ${C.type===`error`?`bg-red-100 border-red-500 text-error shadow-[2px_2px_0px_0px_rgba(30,41,59,1)]`:C.type===`unverified`?`bg-amber-100 border-amber-500 text-amber-900 shadow-[2px_2px_0px_0px_rgba(30,41,59,1)]`:`bg-emerald-100 border-emerald-500 text-emerald-700 shadow-[2px_2px_0px_0px_rgba(30,41,59,1)]`}`,children:[(0,p.jsx)(`p`,{children:C.text}),C.type===`unverified`&&(0,p.jsxs)(`button`,{type:`button`,onClick:async()=>{if(!u.trim()||!h){w({type:`error`,text:`Please enter your email and password above to resend the verification link.`});return}try{S(!0),await d.resendVerificationEmail(u.trim(),h),w({type:`success`,text:`Verification email resent to ${u.trim()}! Please check your inbox and spam folder.`})}catch(e){w({type:`error`,text:e.message||`Failed to resend verification email. Check your credentials.`})}finally{S(!1)}},disabled:x,className:`mt-3 w-full bg-amber-500 hover:bg-amber-600 text-white font-window-title text-xs font-bold py-2 px-3 border-[2px] border-ink-black rounded flex items-center justify-center gap-2 cursor-pointer shadow-[2px_2px_0px_0px_rgba(0,0,0,1)] active:translate-y-0.5 active:shadow-none uppercase disabled:opacity-50`,children:[(0,p.jsx)(a,{className:`w-3.5 h-3.5 ${x?`animate-spin`:``}`}),x?`SENDING LINK...`:`RESEND VERIFICATION EMAIL`]})]}),(0,p.jsxs)(`form`,{onSubmit:async n=>{n.preventDefault(),b(!0),w(null);let r=u.trim();if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(r)){w({type:`error`,text:`Please enter a valid email address.`}),b(!1);return}if(e){if(!j){w({type:`error`,text:`Password does not meet the security criteria. Please check the requirements below.`}),b(!1);return}if(h!==_){w({type:`error`,text:`Passwords do not match. Please re-enter.`}),b(!1);return}try{await d.signUpWithEmail(r,h),w({type:`success`,text:`Registration successful! A verification link has been sent to your email. Please verify your email before logging in.`}),t(!1),g(``),v(``)}catch(e){let t=e,n=t.message||`An error occurred during registration.`;t.code===`auth/email-already-in-use`?n=`This email address is already registered. Please sign in instead.`:t.code===`auth/invalid-email`?n=`The email address format is invalid.`:t.code===`auth/weak-password`&&(n=`Firebase requires a stronger password.`),w({type:`error`,text:n})}finally{b(!1)}}else try{await d.signInWithEmail(r,h)}catch(e){let t=e;if(t.code===`auth/email-not-verified`)w({type:`unverified`,text:`Your email address is not verified yet. Please check your inbox for the activation link.`});else{let e=t.message||`An error occurred during sign in.`;t.code===`auth/invalid-credential`||t.code===`auth/user-not-found`||t.code===`auth/wrong-password`?e=`Invalid email or password. Please check your credentials.`:t.code===`auth/too-many-requests`&&(e=`Access temporarily locked due to many failed attempts. Try again later or reset password.`),w({type:`error`,text:e})}}finally{b(!1)}},className:`space-y-3 sm:space-y-4`,children:[(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{htmlFor:`auth-email`,className:`block text-[11px] sm:text-xs font-bold text-ink-black uppercase tracking-wider mb-1.5 sm:mb-2 font-headline-md`,children:`Email Address`}),(0,p.jsxs)(`div`,{className:`relative`,children:[(0,p.jsx)(i,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-3.5 h-3.5 sm:w-4 sm:h-4 text-ink-black`}),(0,p.jsx)(`input`,{id:`auth-email`,type:`email`,required:!0,value:u,onChange:e=>m(e.target.value),placeholder:`name@arcade.com`,"aria-label":`Email Address`,className:`w-full bg-white border-[3px] border-ink-black rounded-lg py-2 sm:py-2.5 pl-9 sm:pl-10 pr-3 sm:pr-4 text-ink-black placeholder-trash-gray focus:outline-none focus:bg-white text-xs sm:text-sm font-code-mono shadow-[inset_2px_2px_0px_rgba(0,0,0,0.1)]`})]})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{htmlFor:`auth-password`,className:`block text-[11px] sm:text-xs font-bold text-ink-black uppercase tracking-wider mb-1.5 sm:mb-2 font-headline-md`,children:`Password`}),(0,p.jsxs)(`div`,{className:`relative`,children:[(0,p.jsx)(r,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-3.5 h-3.5 sm:w-4 sm:h-4 text-ink-black`}),(0,p.jsx)(`input`,{id:`auth-password`,type:`password`,required:!0,value:h,onChange:e=>g(e.target.value),placeholder:`••••••••`,"aria-label":`Password`,className:`w-full bg-white border-[3px] border-ink-black rounded-lg py-2 sm:py-2.5 pl-9 sm:pl-10 pr-3 sm:pr-4 text-ink-black placeholder-trash-gray focus:outline-none focus:bg-white text-xs sm:text-sm font-code-mono shadow-[inset_2px_2px_0px_rgba(0,0,0,0.1)]`})]})]}),e&&(0,p.jsxs)(p.Fragment,{children:[(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{htmlFor:`auth-confirm-password`,className:`block text-[11px] sm:text-xs font-bold text-ink-black uppercase tracking-wider mb-1.5 sm:mb-2 font-headline-md`,children:`Confirm Password`}),(0,p.jsxs)(`div`,{className:`relative`,children:[(0,p.jsx)(o,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-3.5 h-3.5 sm:w-4 sm:h-4 text-ink-black`}),(0,p.jsx)(`input`,{id:`auth-confirm-password`,type:`password`,required:!0,value:_,onChange:e=>v(e.target.value),placeholder:`••••••••`,"aria-label":`Confirm Password`,className:`w-full bg-white border-[3px] border-ink-black rounded-lg py-2 sm:py-2.5 pl-9 sm:pl-10 pr-3 sm:pr-4 text-ink-black placeholder-trash-gray focus:outline-none focus:bg-white text-xs sm:text-sm font-code-mono shadow-[inset_2px_2px_0px_rgba(0,0,0,0.1)]`})]})]}),(0,p.jsxs)(`div`,{className:`p-2.5 sm:p-3 bg-white border-[2px] border-ink-black rounded-lg text-[9px] sm:text-[10px] font-code-mono space-y-1 shadow-[inset_1px_1px_0px_rgba(0,0,0,0.05)]`,children:[(0,p.jsx)(`div`,{className:`font-bold font-arcade uppercase text-[8px] sm:text-[9px] text-trash-gray mb-1 sm:mb-1.5`,children:`Password Security Requirements:`}),(0,p.jsxs)(`div`,{className:`flex items-center gap-1.5 ${T?`text-emerald-700 font-bold`:`text-slate-500`}`,children:[T?(0,p.jsx)(l,{className:`w-3 h-3 text-emerald-600 shrink-0 stroke-[3]`}):(0,p.jsx)(s,{className:`w-3 h-3 text-slate-400 shrink-0`}),(0,p.jsx)(`span`,{children:`Minimum 8 characters`})]}),(0,p.jsxs)(`div`,{className:`flex items-center gap-1.5 ${E&&D?`text-emerald-700 font-bold`:`text-slate-500`}`,children:[E&&D?(0,p.jsx)(l,{className:`w-3 h-3 text-emerald-600 shrink-0 stroke-[3]`}):(0,p.jsx)(s,{className:`w-3 h-3 text-slate-400 shrink-0`}),(0,p.jsx)(`span`,{children:`Uppercase & lowercase letters (A-Z, a-z)`})]}),(0,p.jsxs)(`div`,{className:`flex items-center gap-1.5 ${O?`text-emerald-700 font-bold`:`text-slate-500`}`,children:[O?(0,p.jsx)(l,{className:`w-3 h-3 text-emerald-600 shrink-0 stroke-[3]`}):(0,p.jsx)(s,{className:`w-3 h-3 text-slate-400 shrink-0`}),(0,p.jsx)(`span`,{children:`At least 1 number (0-9)`})]}),(0,p.jsxs)(`div`,{className:`flex items-center gap-1.5 ${k?`text-emerald-700 font-bold`:`text-slate-500`}`,children:[k?(0,p.jsx)(l,{className:`w-3 h-3 text-emerald-600 shrink-0 stroke-[3]`}):(0,p.jsx)(s,{className:`w-3 h-3 text-slate-400 shrink-0`}),(0,p.jsx)(`span`,{children:`At least 1 special character (!@#$%^&*...)`})]}),_.length>0&&(0,p.jsxs)(`div`,{className:`flex items-center gap-1.5 ${A?`text-emerald-700 font-bold`:`text-red-600 font-bold`}`,children:[A?(0,p.jsx)(l,{className:`w-3 h-3 text-emerald-600 shrink-0 stroke-[3]`}):(0,p.jsx)(s,{className:`w-3 h-3 text-red-500 shrink-0 stroke-[3]`}),(0,p.jsx)(`span`,{children:A?`Passwords match`:`Passwords do not match`})]})]})]}),(0,p.jsxs)(`button`,{type:`submit`,disabled:y||e&&(!j||!A),className:`w-full bg-[#ffcc00] hover:bg-yellow-400 border-[3px] sm:border-[4px] border-ink-black rounded-xl py-2.5 sm:py-3.5 font-window-title text-sm sm:text-base text-ink-black arcade-btn cursor-pointer disabled:opacity-50 flex items-center justify-center gap-2 uppercase font-bold tracking-wide transition-all shadow-[3px_3px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none`,children:[y?`PROCESSING...`:e?`CREATE ACCOUNT`:`SIGN IN`,!y&&(0,p.jsx)(n,{className:`w-4 h-4 stroke-[3px]`})]})]}),(0,p.jsxs)(`div`,{className:`relative my-3.5 sm:my-5 select-none`,children:[(0,p.jsx)(`div`,{className:`absolute inset-0 flex items-center`,children:(0,p.jsx)(`div`,{className:`w-full border-t-[3px] border-ink-black border-dashed`})}),(0,p.jsx)(`div`,{className:`relative flex justify-center text-[9px] sm:text-[10px] uppercase font-arcade`,children:(0,p.jsx)(`span`,{className:`bg-[#fdf8e1] px-2 sm:px-3 text-trash-gray font-bold`,children:`OR CONTINUE WITH`})})]}),(0,p.jsxs)(`button`,{onClick:async()=>{try{b(!0),w(null),await d.signInWithGoogle()}catch(e){w({type:`error`,text:e.message||`Google Sign-In failed to initialize`}),b(!1)}},disabled:y,className:`w-full bg-white hover:bg-slate-100 border-[3px] border-ink-black text-ink-black font-bold py-2.5 sm:py-3 px-3 sm:px-4 rounded-xl flex items-center justify-center gap-2.5 sm:gap-3 transition-all text-[11px] sm:text-xs cursor-pointer shadow-[3px_3px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none`,children:[(0,p.jsxs)(`svg`,{className:`w-4 h-4 shrink-0`,viewBox:`0 0 24 24`,fill:`currentColor`,children:[(0,p.jsx)(`path`,{d:`M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z`,fill:`#4285F4`}),(0,p.jsx)(`path`,{d:`M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z`,fill:`#34A853`}),(0,p.jsx)(`path`,{d:`M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.06H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.94l2.85-2.22.81-.63z`,fill:`#FBBC05`}),(0,p.jsx)(`path`,{d:`M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.06l3.66 2.84c.87-2.6 3.3-4.52 6.16-4.52z`,fill:`#EA4335`})]}),`SIGN IN WITH GOOGLE`]}),(0,p.jsxs)(`button`,{onClick:()=>{d.enterSandbox()},disabled:y,className:`mt-2.5 sm:mt-3 w-full bg-[#10b981] hover:bg-emerald-600 text-white font-window-title py-2.5 sm:py-3 px-3 sm:px-4 border-[3px] border-ink-black rounded-xl flex items-center justify-center gap-2 cursor-pointer shadow-[3px_3px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none uppercase font-bold text-[11px] sm:text-xs`,children:[(0,p.jsx)(`span`,{className:`material-symbols-outlined text-sm font-bold`,children:`sports_esports`}),`Enter Sandbox Mode (No Login)`]})]})]})]})}export{m as default};
|
|
|
|
| 1 |
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{A as t,Lt as n,Tt as r,U as i,V as a,q as o,s,x as c,yt as l,zt as u}from"./vendor-react-qmUj3JUi.js";import{t as d}from"./firebaseClient-G7klkuBb.js";var f=e(u(),1),p=n();function m(){let[e,n]=(0,f.useState)(!1),[u,m]=(0,f.useState)(``),[h,g]=(0,f.useState)(``),[_,v]=(0,f.useState)(``),[y,b]=(0,f.useState)(!1),[x,S]=(0,f.useState)(!1),[C,w]=(0,f.useState)(null),T=h.length>=8,E=/[A-Z]/.test(h),D=/[a-z]/.test(h),O=/[0-9]/.test(h),k=/[!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?~`]/.test(h),A=h.length>0&&h===_,j=T&&E&&D&&O&&k;return(0,p.jsxs)(`div`,{className:`fixed inset-0 w-full h-full max-h-[100dvh] overflow-y-auto overscroll-contain custom-scrollbar flex flex-col items-center px-3 pt-3 pb-8 sm:px-4 sm:py-6 md:p-8 relative isolate selection:bg-highlight-pink selection:text-white`,children:[(0,p.jsx)(`div`,{className:`fixed inset-0 w-full h-full bg-cover bg-center z-0 saturate-150 contrast-125 pointer-events-none`,style:{backgroundImage:`url('/wallpapers/default.webp')`}}),(0,p.jsxs)(`div`,{className:`w-full max-w-md bg-paper-white border-[4px] border-ink-black window-shadow z-10 flex flex-col overflow-hidden shadow-[inset_2px_2px_0px_rgba(255,255,255,0.8)] relative my-auto shrink-0`,children:[(0,p.jsx)(`div`,{className:`bg-[#0ea5e9] border-b-[4px] border-ink-black px-3 sm:px-4 py-2 sm:py-2.5 flex justify-between items-center text-ink-black select-none`,children:(0,p.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,p.jsx)(`span`,{className:`material-symbols-outlined select-none text-base sm:text-xl`,style:{fontVariationSettings:`'FILL' 1`},children:`sports_esports`}),(0,p.jsx)(`span`,{className:`font-window-title text-xs sm:text-base font-bold tracking-wide`,children:`System_Setup.exe`})]})}),(0,p.jsxs)(`div`,{className:`p-4 sm:p-6 bg-[#fdf8e1] flex-1 flex flex-col`,children:[typeof window<`u`&&window.self!==window.top&&(0,p.jsxs)(`div`,{className:`mb-4 sm:mb-5 p-3 sm:p-3.5 border-[3px] border-[#ea580c] bg-[#ffedd5] text-[#9a3412] text-xs font-bold font-arcade leading-relaxed shadow-[2px_2px_0px_0px_rgba(30,41,59,1)]`,children:[`⚠️ RUNNING INSIDE IFRAME`,(0,p.jsx)(`p`,{className:`mt-1 font-sans text-[11px] font-normal text-ink-black normal-case leading-normal`,children:`If Google Sign-In popup is restricted inside Hugging Face wrapper, open the standalone link below:`}),(0,p.jsx)(`a`,{href:`https://iamfebin-algospaced-dsa.hf.space/`,target:`_top`,className:`mt-2.5 inline-block w-full text-center bg-[#ea580c] hover:bg-[#c2410c] text-white border-[2.5px] border-ink-black py-1.5 px-3 rounded-lg font-window-title text-xs font-bold transition-all shadow-[1.5px_1.5px_0px_rgba(0,0,0,1)] active:translate-y-0.5 active:shadow-none`,children:`OPEN FULLSCREEN / DIRECT SITE`})]}),(0,p.jsxs)(`div`,{className:`flex flex-col items-center mb-4 sm:mb-6`,children:[(0,p.jsx)(`div`,{className:`w-12 h-12 sm:w-16 sm:h-16 bg-paper-white border-[3px] border-ink-black flex items-center justify-center gadget-shadow shadow-[inset_2px_2px_0px_rgba(255,255,255,0.8)] mb-2.5 sm:mb-4`,children:(0,p.jsx)(c,{className:`w-7 h-7 sm:w-9 sm:h-9 text-primary`})}),(0,p.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,p.jsx)(`h2`,{className:`text-2xl sm:text-3xl font-extrabold tracking-tight text-ink-black font-headline-md leading-none m-0`,children:`AlgoSpaced`}),(0,p.jsx)(`span`,{className:`text-[9px] sm:text-[10px] font-arcade bg-[#facc15] text-ink-black font-extrabold px-1.5 sm:px-2 py-0.5 border-[2px] border-ink-black shadow-[2px_2px_0px_0px_#1E293B] uppercase rotate-[-3deg]`,children:`BETA`})]}),(0,p.jsx)(`p`,{className:`text-[10px] sm:text-xs font-arcade text-trash-gray mt-1.5 sm:mt-2 tracking-wide uppercase text-center`,children:`Spaced Repetition for DSA`})]}),(0,p.jsxs)(`div`,{className:`flex gap-2 mb-4 sm:mb-6 font-arcade text-[9px] sm:text-[10px]`,children:[(0,p.jsx)(`button`,{onClick:()=>{n(!1),w(null)},className:`flex-1 py-2 sm:py-2.5 border-[3px] border-ink-black cursor-pointer font-bold tracking-wider outline-none transition-all shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] active:shadow-none active:translate-y-0.5 ${e?`bg-white text-slate-700 hover:bg-surface-container`:`bg-secondary-container text-ink-black translate-y-0.5 shadow-[1px_1px_0px_0px_rgba(30,41,59,1)]`}`,children:`SIGN IN`}),(0,p.jsx)(`button`,{onClick:()=>{n(!0),w(null)},className:`flex-1 py-2 sm:py-2.5 border-[3px] border-ink-black cursor-pointer font-bold tracking-wider outline-none transition-all shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] active:shadow-none active:translate-y-0.5 ${e?`bg-secondary-container text-ink-black translate-y-0.5 shadow-[1px_1px_0px_0px_rgba(30,41,59,1)]`:`bg-white text-slate-700 hover:bg-surface-container`}`,children:`CREATE ACCOUNT`})]}),C&&(0,p.jsxs)(`div`,{className:`mb-4 sm:mb-6 p-3 sm:p-4 border-[3px] border-ink-black text-xs font-arcade leading-relaxed ${C.type===`error`?`bg-red-100 border-red-500 text-error shadow-[2px_2px_0px_0px_rgba(30,41,59,1)]`:C.type===`unverified`?`bg-amber-100 border-amber-500 text-amber-900 shadow-[2px_2px_0px_0px_rgba(30,41,59,1)]`:`bg-emerald-100 border-emerald-500 text-emerald-700 shadow-[2px_2px_0px_0px_rgba(30,41,59,1)]`}`,children:[(0,p.jsx)(`p`,{children:C.text}),C.type===`unverified`&&(0,p.jsxs)(`button`,{type:`button`,onClick:async()=>{if(!u.trim()||!h){w({type:`error`,text:`Please enter your email and password above to resend the verification link.`});return}try{S(!0),await d.resendVerificationEmail(u.trim(),h),w({type:`success`,text:`Verification email resent to ${u.trim()}! Please check your inbox and spam folder.`})}catch(e){w({type:`error`,text:e.message||`Failed to resend verification email. Check your credentials.`})}finally{S(!1)}},disabled:x,className:`mt-3 w-full bg-amber-500 hover:bg-amber-600 text-white font-window-title text-xs font-bold py-2 px-3 border-[2px] border-ink-black rounded flex items-center justify-center gap-2 cursor-pointer shadow-[2px_2px_0px_0px_rgba(0,0,0,1)] active:translate-y-0.5 active:shadow-none uppercase disabled:opacity-50`,children:[(0,p.jsx)(t,{className:`w-3.5 h-3.5 ${x?`animate-spin`:``}`}),x?`SENDING LINK...`:`RESEND VERIFICATION EMAIL`]})]}),(0,p.jsxs)(`form`,{onSubmit:async t=>{t.preventDefault(),b(!0),w(null);let r=u.trim();if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(r)){w({type:`error`,text:`Please enter a valid email address.`}),b(!1);return}if(e){if(!j){w({type:`error`,text:`Password does not meet the security criteria. Please check the requirements below.`}),b(!1);return}if(h!==_){w({type:`error`,text:`Passwords do not match. Please re-enter.`}),b(!1);return}try{await d.signUpWithEmail(r,h),w({type:`success`,text:`Registration successful! A verification link has been sent to your email. Please verify your email before logging in.`}),n(!1),g(``),v(``)}catch(e){let t=e,n=t.message||`An error occurred during registration.`;t.code===`auth/email-already-in-use`?n=`This email address is already registered. Please sign in instead.`:t.code===`auth/invalid-email`?n=`The email address format is invalid.`:t.code===`auth/weak-password`&&(n=`Firebase requires a stronger password.`),w({type:`error`,text:n})}finally{b(!1)}}else try{await d.signInWithEmail(r,h)}catch(e){let t=e;if(t.code===`auth/email-not-verified`)w({type:`unverified`,text:`Your email address is not verified yet. Please check your inbox for the activation link.`});else{let e=t.message||`An error occurred during sign in.`;t.code===`auth/invalid-credential`||t.code===`auth/user-not-found`||t.code===`auth/wrong-password`?e=`Invalid email or password. Please check your credentials.`:t.code===`auth/too-many-requests`&&(e=`Access temporarily locked due to many failed attempts. Try again later or reset password.`),w({type:`error`,text:e})}}finally{b(!1)}},className:`space-y-3 sm:space-y-4`,children:[(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{htmlFor:`auth-email`,className:`block text-[11px] sm:text-xs font-bold text-ink-black uppercase tracking-wider mb-1.5 sm:mb-2 font-headline-md`,children:`Email Address`}),(0,p.jsxs)(`div`,{className:`relative`,children:[(0,p.jsx)(a,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-3.5 h-3.5 sm:w-4 sm:h-4 text-ink-black`}),(0,p.jsx)(`input`,{id:`auth-email`,type:`email`,required:!0,value:u,onChange:e=>m(e.target.value),placeholder:`name@arcade.com`,"aria-label":`Email Address`,className:`w-full bg-white border-[3px] border-ink-black rounded-lg py-2 sm:py-2.5 pl-9 sm:pl-10 pr-3 sm:pr-4 text-ink-black placeholder-trash-gray focus:outline-none focus:bg-white text-xs sm:text-sm font-code-mono shadow-[inset_2px_2px_0px_rgba(0,0,0,0.1)]`})]})]}),(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{htmlFor:`auth-password`,className:`block text-[11px] sm:text-xs font-bold text-ink-black uppercase tracking-wider mb-1.5 sm:mb-2 font-headline-md`,children:`Password`}),(0,p.jsxs)(`div`,{className:`relative`,children:[(0,p.jsx)(i,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-3.5 h-3.5 sm:w-4 sm:h-4 text-ink-black`}),(0,p.jsx)(`input`,{id:`auth-password`,type:`password`,required:!0,value:h,onChange:e=>g(e.target.value),placeholder:`••••••••`,"aria-label":`Password`,className:`w-full bg-white border-[3px] border-ink-black rounded-lg py-2 sm:py-2.5 pl-9 sm:pl-10 pr-3 sm:pr-4 text-ink-black placeholder-trash-gray focus:outline-none focus:bg-white text-xs sm:text-sm font-code-mono shadow-[inset_2px_2px_0px_rgba(0,0,0,0.1)]`})]})]}),e&&(0,p.jsxs)(p.Fragment,{children:[(0,p.jsxs)(`div`,{children:[(0,p.jsx)(`label`,{htmlFor:`auth-confirm-password`,className:`block text-[11px] sm:text-xs font-bold text-ink-black uppercase tracking-wider mb-1.5 sm:mb-2 font-headline-md`,children:`Confirm Password`}),(0,p.jsxs)(`div`,{className:`relative`,children:[(0,p.jsx)(o,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-3.5 h-3.5 sm:w-4 sm:h-4 text-ink-black`}),(0,p.jsx)(`input`,{id:`auth-confirm-password`,type:`password`,required:!0,value:_,onChange:e=>v(e.target.value),placeholder:`••••••••`,"aria-label":`Confirm Password`,className:`w-full bg-white border-[3px] border-ink-black rounded-lg py-2 sm:py-2.5 pl-9 sm:pl-10 pr-3 sm:pr-4 text-ink-black placeholder-trash-gray focus:outline-none focus:bg-white text-xs sm:text-sm font-code-mono shadow-[inset_2px_2px_0px_rgba(0,0,0,0.1)]`})]})]}),(0,p.jsxs)(`div`,{className:`p-2.5 sm:p-3 bg-white border-[2px] border-ink-black rounded-lg text-[9px] sm:text-[10px] font-code-mono space-y-1 shadow-[inset_1px_1px_0px_rgba(0,0,0,0.05)]`,children:[(0,p.jsx)(`div`,{className:`font-bold font-arcade uppercase text-[8px] sm:text-[9px] text-trash-gray mb-1 sm:mb-1.5`,children:`Password Security Requirements:`}),(0,p.jsxs)(`div`,{className:`flex items-center gap-1.5 ${T?`text-emerald-700 font-bold`:`text-slate-500`}`,children:[T?(0,p.jsx)(l,{className:`w-3 h-3 text-emerald-600 shrink-0 stroke-[3]`}):(0,p.jsx)(s,{className:`w-3 h-3 text-slate-400 shrink-0`}),(0,p.jsx)(`span`,{children:`Minimum 8 characters`})]}),(0,p.jsxs)(`div`,{className:`flex items-center gap-1.5 ${E&&D?`text-emerald-700 font-bold`:`text-slate-500`}`,children:[E&&D?(0,p.jsx)(l,{className:`w-3 h-3 text-emerald-600 shrink-0 stroke-[3]`}):(0,p.jsx)(s,{className:`w-3 h-3 text-slate-400 shrink-0`}),(0,p.jsx)(`span`,{children:`Uppercase & lowercase letters (A-Z, a-z)`})]}),(0,p.jsxs)(`div`,{className:`flex items-center gap-1.5 ${O?`text-emerald-700 font-bold`:`text-slate-500`}`,children:[O?(0,p.jsx)(l,{className:`w-3 h-3 text-emerald-600 shrink-0 stroke-[3]`}):(0,p.jsx)(s,{className:`w-3 h-3 text-slate-400 shrink-0`}),(0,p.jsx)(`span`,{children:`At least 1 number (0-9)`})]}),(0,p.jsxs)(`div`,{className:`flex items-center gap-1.5 ${k?`text-emerald-700 font-bold`:`text-slate-500`}`,children:[k?(0,p.jsx)(l,{className:`w-3 h-3 text-emerald-600 shrink-0 stroke-[3]`}):(0,p.jsx)(s,{className:`w-3 h-3 text-slate-400 shrink-0`}),(0,p.jsx)(`span`,{children:`At least 1 special character (!@#$%^&*...)`})]}),_.length>0&&(0,p.jsxs)(`div`,{className:`flex items-center gap-1.5 ${A?`text-emerald-700 font-bold`:`text-red-600 font-bold`}`,children:[A?(0,p.jsx)(l,{className:`w-3 h-3 text-emerald-600 shrink-0 stroke-[3]`}):(0,p.jsx)(s,{className:`w-3 h-3 text-red-500 shrink-0 stroke-[3]`}),(0,p.jsx)(`span`,{children:A?`Passwords match`:`Passwords do not match`})]})]})]}),(0,p.jsxs)(`button`,{type:`submit`,disabled:y||e&&(!j||!A),className:`w-full bg-[#ffcc00] hover:bg-yellow-400 border-[3px] sm:border-[4px] border-ink-black rounded-xl py-2.5 sm:py-3.5 font-window-title text-sm sm:text-base text-ink-black arcade-btn cursor-pointer disabled:opacity-50 flex items-center justify-center gap-2 uppercase font-bold tracking-wide transition-all shadow-[3px_3px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none`,children:[y?`PROCESSING...`:e?`CREATE ACCOUNT`:`SIGN IN`,!y&&(0,p.jsx)(r,{className:`w-4 h-4 stroke-[3px]`})]})]}),(0,p.jsxs)(`div`,{className:`relative my-3.5 sm:my-5 select-none`,children:[(0,p.jsx)(`div`,{className:`absolute inset-0 flex items-center`,children:(0,p.jsx)(`div`,{className:`w-full border-t-[3px] border-ink-black border-dashed`})}),(0,p.jsx)(`div`,{className:`relative flex justify-center text-[9px] sm:text-[10px] uppercase font-arcade`,children:(0,p.jsx)(`span`,{className:`bg-[#fdf8e1] px-2 sm:px-3 text-trash-gray font-bold`,children:`OR CONTINUE WITH`})})]}),(0,p.jsxs)(`button`,{onClick:async()=>{try{b(!0),w(null),await d.signInWithGoogle()}catch(e){w({type:`error`,text:e.message||`Google Sign-In failed to initialize`}),b(!1)}},disabled:y,className:`w-full bg-white hover:bg-slate-100 border-[3px] border-ink-black text-ink-black font-bold py-2.5 sm:py-3 px-3 sm:px-4 rounded-xl flex items-center justify-center gap-2.5 sm:gap-3 transition-all text-[11px] sm:text-xs cursor-pointer shadow-[3px_3px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none`,children:[(0,p.jsxs)(`svg`,{className:`w-4 h-4 shrink-0`,viewBox:`0 0 24 24`,fill:`currentColor`,children:[(0,p.jsx)(`path`,{d:`M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z`,fill:`#4285F4`}),(0,p.jsx)(`path`,{d:`M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z`,fill:`#34A853`}),(0,p.jsx)(`path`,{d:`M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.06H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.94l2.85-2.22.81-.63z`,fill:`#FBBC05`}),(0,p.jsx)(`path`,{d:`M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.06l3.66 2.84c.87-2.6 3.3-4.52 6.16-4.52z`,fill:`#EA4335`})]}),`SIGN IN WITH GOOGLE`]}),(0,p.jsxs)(`button`,{onClick:()=>{d.enterSandbox()},disabled:y,className:`mt-2.5 sm:mt-3 w-full bg-[#10b981] hover:bg-emerald-600 text-white font-window-title py-2.5 sm:py-3 px-3 sm:px-4 border-[3px] border-ink-black rounded-xl flex items-center justify-center gap-2 cursor-pointer shadow-[3px_3px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none uppercase font-bold text-[11px] sm:text-xs`,children:[(0,p.jsx)(`span`,{className:`material-symbols-outlined text-sm font-bold`,children:`sports_esports`}),`Enter Sandbox Mode (No Login)`]})]})]})]})}export{m as default};
|
algospaced-ui/dist/assets/{CreateProblemForm-D59LwEcw.js → CreateProblemForm-C2nCqjgj.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Lt as t,zt as n}from"./vendor-react-
|
| 2 |
`):String(n.constraints):``),[te,ne]=(0,i.useState)(()=>n?.how_to_solve||``),[N,P]=(0,i.useState)(()=>{if(n?.reference_code)return n.reference_code;try{let e=localStorage.getItem(`algospaced_prefill_draft`);if(e)return JSON.parse(e).code||``}catch{}return``}),[F,I]=(0,i.useState)(()=>{if(n?.solutions&&Array.isArray(n.solutions)&&n.solutions.length>0)return n.solutions.map((e,t)=>({id:e.id||`sol-${t+1}`,name:e.name||`Method ${t+1}`,pattern:e.pattern||n.pattern||`Arrays & Hashing`,time_complexity:e.time_complexity||n.optimal_time||`O(N)`,space_complexity:e.space_complexity||n.optimal_space||`O(1)`,code:e.code||``,explanation:e.explanation||``,is_optimal:e.is_optimal??t===0}));let e=n?.reference_code||``,t=n?.pattern||`Arrays & Hashing`;try{let n=localStorage.getItem(`algospaced_prefill_draft`);if(n){let r=JSON.parse(n);r.code&&!e&&(e=r.code),r.pattern&&!t&&(t=r.pattern)}}catch{}return[{id:`sol-1`,name:`Optimal Method`,pattern:t,time_complexity:n?.optimal_time||`O(N)`,space_complexity:n?.optimal_space||`O(1)`,code:e,explanation:n?.how_to_solve||``,is_optimal:!0}]}),[L,R]=(0,i.useState)(0),z=F[L]||F[0]||{id:`sol-1`,name:`Method 1`,pattern:`Arrays & Hashing`,time_complexity:`O(N)`,space_complexity:`O(1)`,code:``,explanation:``,is_optimal:!0},B=e=>{I(t=>{let n=[...t],r=L<n.length?L:0;return n[r]={...n[r],...e},e.is_optimal&&(n.forEach((e,t)=>{t!==r&&(e.is_optimal=!1)}),n[r].time_complexity&&w(n[r].time_complexity),n[r].space_complexity&&E(n[r].space_complexity),n[r].pattern&&b(n[r].pattern)),n})},re=()=>{let e=F.length+1,t={id:s(),name:`Method ${e}`,pattern:y||`Arrays & Hashing`,time_complexity:`O(N)`,space_complexity:`O(1)`,code:``,explanation:``,is_optimal:F.length===0};I(e=>[...e,t]),R(F.length)},ie=e=>{F.length<=1||(I(t=>{let n=t.filter((t,n)=>n!==e);return n.some(e=>e.is_optimal)||(n[0].is_optimal=!0),n}),L>=F.length-1&&R(Math.max(0,F.length-2)))},[V,ae]=(0,i.useState)(!0),[H,U]=(0,i.useState)(``),[W,G]=(0,i.useState)(``),[K,q]=(0,i.useState)(!1),[J,Y]=(0,i.useState)(!1),[X,Z]=(0,i.useState)(!1),[oe,se]=(0,i.useState)(!1);i.useEffect(()=>{l||localStorage.removeItem(`algospaced_prefill_draft`)},[l]);let Q=async()=>{let{data:{session:e}}=await r.auth.getSession(),t=e?e.access_token:`sandbox`,n=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"&&n&&n.trim()&&(a[`x-custom-api-key`]=n.trim(),a[`x-gemini-api-key`]=n.trim(),a[`x-ai-provider`]=i),a},ce=async()=>{if(f.trim()){m(!0),U(``);try{let e=await Q(),t=await fetch(`/api/explorer/problems/fetch-leetcode`,{method:`POST`,headers:e,body:JSON.stringify({query:f.trim()})});if(t.ok){let e=await t.json();e.problem_number!==void 0&&e.problem_number!==null&&v(e.problem_number),e.title&&g(e.title),e.difficulty&&S(e.difficulty),e.pattern&&b(e.pattern),e.optimal_time&&w(e.optimal_time),e.optimal_space&&E(e.optimal_space),e.description&&O(e.description),e.how_to_solve&&ne(e.how_to_solve),e.starter_code&&!N.trim()&&P(e.starter_code),I(t=>{let n=[...t],r={...n[L]};return e.pattern&&(r.pattern=e.pattern),e.optimal_time&&(r.time_complexity=e.optimal_time),e.optimal_space&&(r.space_complexity=e.optimal_space),e.how_to_solve&&(r.explanation=e.how_to_solve),e.starter_code&&!r.code?.trim()&&(r.code=e.starter_code),n[L]=r,n}),Array.isArray(e.examples)&&e.examples.length>0&&A(e.examples),Array.isArray(e.constraints)?M(e.constraints.join(`
|
| 3 |
`)):typeof e.constraints==`string`&&M(e.constraints)}else{let e=await t.json();U(e.detail||`Failed to fetch LeetCode problem data.`)}}catch{U(`Fetch request failed due to connection error.`)}finally{m(!1)}}},le=async()=>{let e=z.code||N;if(h.trim()||e.trim()){se(!0),U(``);try{let t=await Q(),n=await fetch(`/api/explorer/problems/prefill`,{method:`POST`,headers:t,body:JSON.stringify({name:h,code:e})});if(n.ok){let t=await n.json();t.problem_number!==void 0&&t.problem_number!==null&&v(t.problem_number),t.title&&!h&&g(t.title),t.pattern&&b(t.pattern),t.difficulty&&S(t.difficulty),t.optimal_time&&w(t.optimal_time),t.optimal_space&&E(t.optimal_space),t.description&&O(t.description),t.reference_code&&!e.trim()&&P(t.reference_code),I(e=>{let n=[...e],r={...n[L]};return t.pattern&&(r.pattern=t.pattern),t.optimal_time&&(r.time_complexity=t.optimal_time),t.optimal_space&&(r.space_complexity=t.optimal_space),t.reference_code&&!r.code?.trim()&&(r.code=t.reference_code),n[L]=r,n})}else{let e=await n.json();U(e.detail||`Prefill failed.`)}}catch{U(`Prefill request failed due to connection error.`)}finally{se(!1)}}},ue=async()=>{let e=z.code||N;if(!h.trim()&&!e.trim()){U(`Please enter a problem name or code first.`);return}Y(!0),U(``);try{let t=await Q(),n=await fetch(`/api/explorer/problems/assist-field`,{method:`POST`,headers:t,body:JSON.stringify({field:`intuition`,title:h,code:e,description:D})});if(n.ok){let e=await n.json();e.how_to_solve&&(ne(e.how_to_solve),B({explanation:e.how_to_solve}))}else{let e=await n.json();U(e.detail||`Failed to generate intuition.`)}}catch{U(`Intuition generator failed due to connection error.`)}finally{Y(!1)}},de=async()=>{let e=z.code||N;if(!e.trim()){U(`Please enter some Python code to format.`);return}Z(!0),U(``);try{let t=await Q(),n=await fetch(`/api/explorer/problems/assist-field`,{method:`POST`,headers:t,body:JSON.stringify({field:`comments`,title:h,code:e})});if(n.ok){let e=await n.json();e.formatted_code&&(P(e.formatted_code),B({code:e.formatted_code}))}else{let e=await n.json();U(e.detail||`Failed to format code.`)}}catch{U(`Code formatter failed due to connection error.`)}finally{Z(!1)}},fe=async r=>{if(r.preventDefault(),!h.trim()){U(`Problem name cannot be empty`);return}q(!0),U(``),G(``);try{let r=await Q(),i=j.split(`
|
| 4 |
`).map(e=>e.trim()).filter(Boolean),a=F.find(e=>e.is_optimal)||F[0],o=a?.pattern||y.trim()||`General`,s=a?.code||N,c=a?.explanation||te,u=C||a?.time_complexity||`O(N)`,d=T||a?.space_complexity||`O(1)`,f;if(l&&n){let e=n.id||(n.problem_number?String(n.problem_number):``)||h.trim();f=await fetch(`/api/explorer/problems/${encodeURIComponent(e)}`,{method:`PUT`,headers:r,body:JSON.stringify({name:h.trim(),pattern:o,difficulty:x,reference_code:s,description:D,problem_number:_===``?null:Number(_),optimal_time:u,optimal_space:d,examples:k.filter(e=>e.input.trim()||e.output.trim()),constraints:i,how_to_solve:c,solutions:F})})}else f=await fetch(`/api/explorer/problems/create`,{method:`POST`,headers:r,body:JSON.stringify({name:h.trim(),pattern:o,difficulty:x,reference_code:s,description:D,problem_number:_===``?null:Number(_),optimal_time:u,optimal_space:d,examples:k.filter(e=>e.input.trim()||e.output.trim()),constraints:i,how_to_solve:c,sync_to_gdoc:V,solutions:F})});let p=await f.json();f.ok&&(p.success||p.problem_id)?(G(l?`Problem updated successfully!`:`Problem saved and synced successfully!`),setTimeout(()=>{t(),e()},1e3)):U(p.detail||(l?`Failed to update problem.`:`Failed to create problem.`))}catch{U(`Connection timed out.`)}finally{q(!1)}},pe=()=>{A([...k,{input:``,output:``,explanation:``}])},me=e=>{k.length<=1||A(k.filter((t,n)=>n!==e))},$=(e,t,n)=>{let r=[...k];r[e]={...r[e],[t]:n},A(r)};return(0,a.jsxs)(`form`,{onSubmit:fe,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:l?`Edit Problem Specification`:`Problem & Note Studio`}),l&&(0,a.jsx)(`span`,{className:`text-[9px] bg-primary-purple/10 text-primary-purple font-mono px-1.5 py-0.5 rounded border border-primary-purple/30 font-bold`,children:`EDIT MODE`})]}),(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:()=>d(`form`),className:`px-3 py-1 text-[10px] font-bold uppercase transition-colors ${u===`form`?`bg-primary-purple text-white`:`hover:bg-slate-100`}`,children:`✏️ Editor`}),(0,a.jsx)(`button`,{type:`button`,onClick:()=>d(`preview`),className:`px-3 py-1 text-[10px] font-bold uppercase transition-colors ${u===`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:f,onChange:e=>p(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),ce())},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:ce,disabled:ee||!f.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:`⚡`}),` `,ee?`FETCHING...`:`FETCH LEETCODE`]})]})]}),H&&(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:[`⚠️ `,H]}),W&&(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:[`✅ `,W]}),(0,a.jsx)(`div`,{className:`flex-1 overflow-y-auto custom-scrollbar p-3 space-y-3`,children:u===`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:_,onChange:e=>v(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:le,disabled:oe||!h.trim()&&!z.code?.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:`✦`}),` `,oe?`...`:`AUTO-FILL`]})]}),(0,a.jsx)(`input`,{type:`text`,required:!0,value:h,onChange:e=>g(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:x,onChange:e=>S(e.target.value),className:`border-2 border-ink-black p-1.5 text-xs font-bold outline-none cursor-pointer ${x===`Easy`?`bg-emerald-100 text-emerald-900`:x===`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-2 gap-2 bg-[#f6edd2] p-2 border-2 border-ink-black rounded`,children:[(0,a.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,a.jsxs)(`div`,{className:`flex items-center justify-between`,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:`⏱️`}),` Target Optimal Time:`]}),(0,a.jsx)(`span`,{className:`text-[8px] font-mono text-slate-500`,children:`(hidden behind spoiler on review)`})]}),(0,a.jsx)(`input`,{type:`text`,value:C,onChange:e=>w(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-mono font-bold`})]}),(0,a.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,a.jsxs)(`div`,{className:`flex items-center justify-between`,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:`📦`}),` Target Optimal Space:`]}),(0,a.jsx)(`span`,{className:`text-[8px] font-mono text-slate-500`,children:`(hidden behind spoiler on review)`})]}),(0,a.jsx)(`input`,{type:`text`,value:T,onChange:e=>E(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-mono font-bold`})]})]}),(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:D,onChange:e=>O(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 (`,k.length,`)`]}),(0,a.jsx)(`button`,{type:`button`,onClick:pe,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`})]}),k.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,`:`]}),k.length>1&&(0,a.jsx)(`button`,{type:`button`,onClick:()=>me(t),className:`text-[10px] text-red-600 hover:text-red-800 font-bold cursor-pointer`,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:j,onChange:e=>M(e.target.value),placeholder:`2 <= nums.length <= 10^4
|
|
|
|
| 1 |
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Lt as t,zt as n}from"./vendor-react-qmUj3JUi.js";import{r}from"./firebaseClient-G7klkuBb.js";var i=e(n(),1),a=t(),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(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`sol-${crypto.randomUUID()}`:`sol-${Date.now()}`}function c({onClose:e,onSuccess:t,initialProblem:n,mode:c=n?`edit`:`create`}){let l=c===`edit`||!!n,[u,d]=(0,i.useState)(`form`),[f,p]=(0,i.useState)(``),[ee,m]=(0,i.useState)(!1),[h,g]=(0,i.useState)(()=>{if(n?.name)return n.name;try{let e=localStorage.getItem(`algospaced_prefill_draft`);if(e)return JSON.parse(e).name||``}catch{}return``}),[_,v]=(0,i.useState)(()=>n?.problem_number!==void 0&&n?.problem_number!==null?n.problem_number:``),[y,b]=(0,i.useState)(()=>{if(n?.pattern)return n.pattern;try{let e=localStorage.getItem(`algospaced_prefill_draft`);if(e)return JSON.parse(e).pattern||``}catch{}return`Arrays & Hashing`}),[x,S]=(0,i.useState)(()=>n?.difficulty===`Easy`||n?.difficulty===`Medium`||n?.difficulty===`Hard`?n.difficulty:`Medium`),[C,w]=(0,i.useState)(()=>n?.optimal_time||`O(N)`),[T,E]=(0,i.useState)(()=>n?.optimal_space||`O(1)`),[D,O]=(0,i.useState)(()=>n?.description||``),[k,A]=(0,i.useState)(()=>n?.examples&&Array.isArray(n.examples)&&n.examples.length>0?n.examples.map(e=>typeof e==`string`?{input:e,output:``,explanation:``}:{input:String(e?.input??``),output:String(e?.output??``),explanation:e?.explanation||``}):[{input:``,output:``,explanation:``}]),[j,M]=(0,i.useState)(()=>n?.constraints?Array.isArray(n.constraints)?n.constraints.join(`
|
| 2 |
`):String(n.constraints):``),[te,ne]=(0,i.useState)(()=>n?.how_to_solve||``),[N,P]=(0,i.useState)(()=>{if(n?.reference_code)return n.reference_code;try{let e=localStorage.getItem(`algospaced_prefill_draft`);if(e)return JSON.parse(e).code||``}catch{}return``}),[F,I]=(0,i.useState)(()=>{if(n?.solutions&&Array.isArray(n.solutions)&&n.solutions.length>0)return n.solutions.map((e,t)=>({id:e.id||`sol-${t+1}`,name:e.name||`Method ${t+1}`,pattern:e.pattern||n.pattern||`Arrays & Hashing`,time_complexity:e.time_complexity||n.optimal_time||`O(N)`,space_complexity:e.space_complexity||n.optimal_space||`O(1)`,code:e.code||``,explanation:e.explanation||``,is_optimal:e.is_optimal??t===0}));let e=n?.reference_code||``,t=n?.pattern||`Arrays & Hashing`;try{let n=localStorage.getItem(`algospaced_prefill_draft`);if(n){let r=JSON.parse(n);r.code&&!e&&(e=r.code),r.pattern&&!t&&(t=r.pattern)}}catch{}return[{id:`sol-1`,name:`Optimal Method`,pattern:t,time_complexity:n?.optimal_time||`O(N)`,space_complexity:n?.optimal_space||`O(1)`,code:e,explanation:n?.how_to_solve||``,is_optimal:!0}]}),[L,R]=(0,i.useState)(0),z=F[L]||F[0]||{id:`sol-1`,name:`Method 1`,pattern:`Arrays & Hashing`,time_complexity:`O(N)`,space_complexity:`O(1)`,code:``,explanation:``,is_optimal:!0},B=e=>{I(t=>{let n=[...t],r=L<n.length?L:0;return n[r]={...n[r],...e},e.is_optimal&&(n.forEach((e,t)=>{t!==r&&(e.is_optimal=!1)}),n[r].time_complexity&&w(n[r].time_complexity),n[r].space_complexity&&E(n[r].space_complexity),n[r].pattern&&b(n[r].pattern)),n})},re=()=>{let e=F.length+1,t={id:s(),name:`Method ${e}`,pattern:y||`Arrays & Hashing`,time_complexity:`O(N)`,space_complexity:`O(1)`,code:``,explanation:``,is_optimal:F.length===0};I(e=>[...e,t]),R(F.length)},ie=e=>{F.length<=1||(I(t=>{let n=t.filter((t,n)=>n!==e);return n.some(e=>e.is_optimal)||(n[0].is_optimal=!0),n}),L>=F.length-1&&R(Math.max(0,F.length-2)))},[V,ae]=(0,i.useState)(!0),[H,U]=(0,i.useState)(``),[W,G]=(0,i.useState)(``),[K,q]=(0,i.useState)(!1),[J,Y]=(0,i.useState)(!1),[X,Z]=(0,i.useState)(!1),[oe,se]=(0,i.useState)(!1);i.useEffect(()=>{l||localStorage.removeItem(`algospaced_prefill_draft`)},[l]);let Q=async()=>{let{data:{session:e}}=await r.auth.getSession(),t=e?e.access_token:`sandbox`,n=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"&&n&&n.trim()&&(a[`x-custom-api-key`]=n.trim(),a[`x-gemini-api-key`]=n.trim(),a[`x-ai-provider`]=i),a},ce=async()=>{if(f.trim()){m(!0),U(``);try{let e=await Q(),t=await fetch(`/api/explorer/problems/fetch-leetcode`,{method:`POST`,headers:e,body:JSON.stringify({query:f.trim()})});if(t.ok){let e=await t.json();e.problem_number!==void 0&&e.problem_number!==null&&v(e.problem_number),e.title&&g(e.title),e.difficulty&&S(e.difficulty),e.pattern&&b(e.pattern),e.optimal_time&&w(e.optimal_time),e.optimal_space&&E(e.optimal_space),e.description&&O(e.description),e.how_to_solve&&ne(e.how_to_solve),e.starter_code&&!N.trim()&&P(e.starter_code),I(t=>{let n=[...t],r={...n[L]};return e.pattern&&(r.pattern=e.pattern),e.optimal_time&&(r.time_complexity=e.optimal_time),e.optimal_space&&(r.space_complexity=e.optimal_space),e.how_to_solve&&(r.explanation=e.how_to_solve),e.starter_code&&!r.code?.trim()&&(r.code=e.starter_code),n[L]=r,n}),Array.isArray(e.examples)&&e.examples.length>0&&A(e.examples),Array.isArray(e.constraints)?M(e.constraints.join(`
|
| 3 |
`)):typeof e.constraints==`string`&&M(e.constraints)}else{let e=await t.json();U(e.detail||`Failed to fetch LeetCode problem data.`)}}catch{U(`Fetch request failed due to connection error.`)}finally{m(!1)}}},le=async()=>{let e=z.code||N;if(h.trim()||e.trim()){se(!0),U(``);try{let t=await Q(),n=await fetch(`/api/explorer/problems/prefill`,{method:`POST`,headers:t,body:JSON.stringify({name:h,code:e})});if(n.ok){let t=await n.json();t.problem_number!==void 0&&t.problem_number!==null&&v(t.problem_number),t.title&&!h&&g(t.title),t.pattern&&b(t.pattern),t.difficulty&&S(t.difficulty),t.optimal_time&&w(t.optimal_time),t.optimal_space&&E(t.optimal_space),t.description&&O(t.description),t.reference_code&&!e.trim()&&P(t.reference_code),I(e=>{let n=[...e],r={...n[L]};return t.pattern&&(r.pattern=t.pattern),t.optimal_time&&(r.time_complexity=t.optimal_time),t.optimal_space&&(r.space_complexity=t.optimal_space),t.reference_code&&!r.code?.trim()&&(r.code=t.reference_code),n[L]=r,n})}else{let e=await n.json();U(e.detail||`Prefill failed.`)}}catch{U(`Prefill request failed due to connection error.`)}finally{se(!1)}}},ue=async()=>{let e=z.code||N;if(!h.trim()&&!e.trim()){U(`Please enter a problem name or code first.`);return}Y(!0),U(``);try{let t=await Q(),n=await fetch(`/api/explorer/problems/assist-field`,{method:`POST`,headers:t,body:JSON.stringify({field:`intuition`,title:h,code:e,description:D})});if(n.ok){let e=await n.json();e.how_to_solve&&(ne(e.how_to_solve),B({explanation:e.how_to_solve}))}else{let e=await n.json();U(e.detail||`Failed to generate intuition.`)}}catch{U(`Intuition generator failed due to connection error.`)}finally{Y(!1)}},de=async()=>{let e=z.code||N;if(!e.trim()){U(`Please enter some Python code to format.`);return}Z(!0),U(``);try{let t=await Q(),n=await fetch(`/api/explorer/problems/assist-field`,{method:`POST`,headers:t,body:JSON.stringify({field:`comments`,title:h,code:e})});if(n.ok){let e=await n.json();e.formatted_code&&(P(e.formatted_code),B({code:e.formatted_code}))}else{let e=await n.json();U(e.detail||`Failed to format code.`)}}catch{U(`Code formatter failed due to connection error.`)}finally{Z(!1)}},fe=async r=>{if(r.preventDefault(),!h.trim()){U(`Problem name cannot be empty`);return}q(!0),U(``),G(``);try{let r=await Q(),i=j.split(`
|
| 4 |
`).map(e=>e.trim()).filter(Boolean),a=F.find(e=>e.is_optimal)||F[0],o=a?.pattern||y.trim()||`General`,s=a?.code||N,c=a?.explanation||te,u=C||a?.time_complexity||`O(N)`,d=T||a?.space_complexity||`O(1)`,f;if(l&&n){let e=n.id||(n.problem_number?String(n.problem_number):``)||h.trim();f=await fetch(`/api/explorer/problems/${encodeURIComponent(e)}`,{method:`PUT`,headers:r,body:JSON.stringify({name:h.trim(),pattern:o,difficulty:x,reference_code:s,description:D,problem_number:_===``?null:Number(_),optimal_time:u,optimal_space:d,examples:k.filter(e=>e.input.trim()||e.output.trim()),constraints:i,how_to_solve:c,solutions:F})})}else f=await fetch(`/api/explorer/problems/create`,{method:`POST`,headers:r,body:JSON.stringify({name:h.trim(),pattern:o,difficulty:x,reference_code:s,description:D,problem_number:_===``?null:Number(_),optimal_time:u,optimal_space:d,examples:k.filter(e=>e.input.trim()||e.output.trim()),constraints:i,how_to_solve:c,sync_to_gdoc:V,solutions:F})});let p=await f.json();f.ok&&(p.success||p.problem_id)?(G(l?`Problem updated successfully!`:`Problem saved and synced successfully!`),setTimeout(()=>{t(),e()},1e3)):U(p.detail||(l?`Failed to update problem.`:`Failed to create problem.`))}catch{U(`Connection timed out.`)}finally{q(!1)}},pe=()=>{A([...k,{input:``,output:``,explanation:``}])},me=e=>{k.length<=1||A(k.filter((t,n)=>n!==e))},$=(e,t,n)=>{let r=[...k];r[e]={...r[e],[t]:n},A(r)};return(0,a.jsxs)(`form`,{onSubmit:fe,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:l?`Edit Problem Specification`:`Problem & Note Studio`}),l&&(0,a.jsx)(`span`,{className:`text-[9px] bg-primary-purple/10 text-primary-purple font-mono px-1.5 py-0.5 rounded border border-primary-purple/30 font-bold`,children:`EDIT MODE`})]}),(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:()=>d(`form`),className:`px-3 py-1 text-[10px] font-bold uppercase transition-colors ${u===`form`?`bg-primary-purple text-white`:`hover:bg-slate-100`}`,children:`✏️ Editor`}),(0,a.jsx)(`button`,{type:`button`,onClick:()=>d(`preview`),className:`px-3 py-1 text-[10px] font-bold uppercase transition-colors ${u===`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:f,onChange:e=>p(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),ce())},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:ce,disabled:ee||!f.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:`⚡`}),` `,ee?`FETCHING...`:`FETCH LEETCODE`]})]})]}),H&&(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:[`⚠️ `,H]}),W&&(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:[`✅ `,W]}),(0,a.jsx)(`div`,{className:`flex-1 overflow-y-auto custom-scrollbar p-3 space-y-3`,children:u===`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:_,onChange:e=>v(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:le,disabled:oe||!h.trim()&&!z.code?.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:`✦`}),` `,oe?`...`:`AUTO-FILL`]})]}),(0,a.jsx)(`input`,{type:`text`,required:!0,value:h,onChange:e=>g(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:x,onChange:e=>S(e.target.value),className:`border-2 border-ink-black p-1.5 text-xs font-bold outline-none cursor-pointer ${x===`Easy`?`bg-emerald-100 text-emerald-900`:x===`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-2 gap-2 bg-[#f6edd2] p-2 border-2 border-ink-black rounded`,children:[(0,a.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,a.jsxs)(`div`,{className:`flex items-center justify-between`,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:`⏱️`}),` Target Optimal Time:`]}),(0,a.jsx)(`span`,{className:`text-[8px] font-mono text-slate-500`,children:`(hidden behind spoiler on review)`})]}),(0,a.jsx)(`input`,{type:`text`,value:C,onChange:e=>w(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-mono font-bold`})]}),(0,a.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,a.jsxs)(`div`,{className:`flex items-center justify-between`,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:`📦`}),` Target Optimal Space:`]}),(0,a.jsx)(`span`,{className:`text-[8px] font-mono text-slate-500`,children:`(hidden behind spoiler on review)`})]}),(0,a.jsx)(`input`,{type:`text`,value:T,onChange:e=>E(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-mono font-bold`})]})]}),(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:D,onChange:e=>O(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 (`,k.length,`)`]}),(0,a.jsx)(`button`,{type:`button`,onClick:pe,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`})]}),k.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,`:`]}),k.length>1&&(0,a.jsx)(`button`,{type:`button`,onClick:()=>me(t),className:`text-[10px] text-red-600 hover:text-red-800 font-bold cursor-pointer`,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:j,onChange:e=>M(e.target.value),placeholder:`2 <= nums.length <= 10^4
|
algospaced-ui/dist/assets/{FileExplorer-CniQ6MSb.js → FileExplorer-BX57bI-L.js}
RENAMED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Lt as t,zt as n}from"./vendor-react-
|
| 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:r,pattern:i,difficulty:a,code:t,description:u})),n&&n()}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:()=>n&&n(),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};
|
|
|
|
| 1 |
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Lt as t,zt as n}from"./vendor-react-qmUj3JUi.js";import{r}from"./firebaseClient-G7klkuBb.js";var i=e(n(),1),a=t(),o=[{name:`Retro Arcade Grid.img`,url:`/wallpapers/default.webp`,desc:`Default AlgoSpaced purple grid and pixel theme background.`},{name:`Classic Board Logo.img`,url:`/icons/computer.webp`,desc:`System info and arcade machine diagram wallpaper.`},{name:`Terminal Console Icon.img`,url:`/icons/terminal.webp`,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:n,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 n=t[0];e.target.value=``,D(!0),k(``),j(``);try{let{data:{session:e}}=await r.auth.getSession(),t=e?e.access_token:`sandbox`,i=new FormData;i.append(`file`,n);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 r.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 r.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 r.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(),r=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:r,pattern:i,difficulty:a,code:t,description:u})),n&&n()}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:()=>n&&n(),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/{GitHubSyncWindow-B_tOfthS.js → GitHubSyncWindow-D0t6e3o3.js}
RENAMED
|
@@ -1 +1 @@
|
|
| 1 |
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{$ as t,H as n,Lt as r,X as i,Y as a,Z as o,et as s,ft as c,j as l,mt as u,o as d,st as f,tt as p,yt as m,zt as h}from"./vendor-react-yvPwY2Sj.js";import{a as g,c as _,i as v,l as y,n as b,o as x,r as S,s as C,t as w}from"./githubSyncService-DQdE4J2L.js";var T=e(h(),1),E=r(),D=({onClose:e,currentProblem:r})=>{let[h,D]=(0,T.useState)(()=>S()),[O,k]=(0,T.useState)(()=>v()),[A,j]=(0,T.useState)(``),[M,N]=(0,T.useState)(!1),[P,F]=(0,T.useState)(!1),[I,L]=(0,T.useState)(!1),[R,z]=(0,T.useState)(!1),[B,V]=(0,T.useState)(!1),[H,U]=(0,T.useState)(!1),[W,G]=(0,T.useState)(!1),[K,q]=(0,T.useState)(null),J=!!(h.token&&(h.username||O?.login));(0,T.useEffect)(()=>{h.token&&!O&&y(h.token).then(e=>{e.valid&&e.user&&(k(e.user),C({username:e.user.login},e.user))})},[h.token,O]);let Y=async()=>{L(!0),q(null);try{let{token:e,user:t}=await b();k(t);let n=S();D(n);try{await g(e,n.repoName,n.isPrivate)}catch{}q({type:`success`,text:`Connected successfully to GitHub as @${t.login}!`,linkUrl:t.html_url})}catch(e){q({type:`error`,text:e.message||`GitHub OAuth authorization failed.`})}finally{L(!1)}},X=async()=>{let e=A.trim();if(!e){q({type:`error`,text:`Please enter a valid GitHub token.`});return}z(!0),q(null);try{let t=await y(e);if(t.valid&&t.user){k(t.user),C({token:e,username:t.user.login},t.user),D(S());try{await g(e,h.repoName,h.isPrivate)}catch{}j(``),N(!1),q({type:`success`,text:`Verified and connected as @${t.user.login}!`,linkUrl:t.user.html_url})}else q({type:`error`,text:t.error||`Token verification failed. Please check permissions.`})}catch(e){q({type:`error`,text:e.message||`Failed to connect with token.`})}finally{z(!1)}},Z=async()=>{if(h.token){V(!0),q(null);try{let e=await g(h.token,h.repoName,h.isPrivate);C({repoName:h.repoName}),q({type:`success`,text:e.created?`Created new repository ${e.full_name} on GitHub!`:`Connected to existing repository ${e.full_name}!`,linkUrl:e.html_url})}catch(e){q({type:`error`,text:e.message||`Failed to initialize repository.`})}finally{V(!1)}}},Q=async()=>{if(h.token&&h.repoName){U(!0),q(null);try{let e=await _(h.token,h.repoName,h.branch);q({type:`success`,text:e.message||`Synced ${e.synced_count} solutions to ${h.repoName}!`,linkUrl:e.repo_url})}catch(e){q({type:`error`,text:e.message||`Batch sync failed.`})}finally{U(!1)}}},$=async()=>{if(!r||!h.token)return;let e=r.code||r.reference_code;if(!e||!e.trim()){q({type:`error`,text:`Current problem has no code to push. Write or save code first!`});return}G(!0),q(null);try{let t={token:h.token,repo:h.repoName,branch:h.branch,problem_number:r.problem_number,problem_name:r.name||`Algorithm Problem`,difficulty:r.difficulty||`Medium`,pattern:r.pattern||`Algorithms`,optimal_time:r.optimal_time||`O(N)`,optimal_space:r.optimal_space||`O(1)`,description:r.description||``,code:e},n=await x(t);q({type:`success`,text:`Committed ${r.name} to GitHub!`,linkUrl:n.html_url})}catch(e){q({type:`error`,text:e.message||`Failed to push current solution.`})}finally{G(!1)}},ee=e=>{C({autoCommit:e}),D(t=>({...t,autoCommit:e})),q({type:`info`,text:e?`Auto-commit ENABLED: Solutions will sync automatically on submission.`:`Auto-commit DISABLED: You can still push manually any time.`})};return(0,E.jsxs)(`div`,{className:`w-full h-full bg-[#fdf8e1] p-4 sm:p-6 flex flex-col justify-between select-none font-sans text-ink-black overflow-y-auto custom-scrollbar`,children:[(0,E.jsxs)(`div`,{className:`space-y-4`,children:[(0,E.jsxs)(`div`,{className:`flex items-center justify-between border-b-[3px] border-ink-black pb-3`,children:[(0,E.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,E.jsx)(`div`,{className:`w-9 h-9 bg-ink-black rounded border-2 border-ink-black flex items-center justify-center text-white shadow-[2px_2px_0px_0px_rgba(0,0,0,0.15)]`,children:(0,E.jsx)(`svg`,{className:`w-5 h-5 fill-white`,viewBox:`0 0 19 19`,children:(0,E.jsx)(`path`,{fillRule:`evenodd`,d:`M9.356 1.85C5.05 1.85 1.57 5.356 1.57 9.694a7.84 7.84 0 0 0 5.324 7.44c.387.079.528-.168.528-.376 0-.182-.013-.805-.013-1.454-2.165.467-2.616-.935-2.616-.935-.349-.91-.864-1.143-.864-1.143-.71-.48.051-.48.051-.48.787.051 1.2.805 1.2.805.695 1.194 1.817.857 2.268.649.064-.507.27-.857.49-1.052-1.728-.182-3.545-.857-3.545-3.87 0-.857.31-1.558.8-2.104-.078-.195-.349-1 .077-2.078 0 0 .657-.208 2.14.805a7.5 7.5 0 0 1 1.946-.26c.657 0 1.328.092 1.946.26 1.483-1.013 2.14-.805 2.14-.805.426 1.078.155 1.883.078 2.078.502.546.799 1.247.799 2.104 0 3.013-1.818 3.675-3.558 3.87.284.247.528.714.528 1.454 0 1.052-.012 1.896-.012 2.156 0 .208.142.455.528.377a7.84 7.84 0 0 0 5.324-7.441c.013-4.338-3.48-7.844-7.773-7.844`,clipRule:`evenodd`})})}),(0,E.jsxs)(`div`,{children:[(0,E.jsx)(`h3`,{className:`font-headline-md font-bold text-sm uppercase m-0 flex items-center gap-2`,children:`GitHub Solutions Station`}),(0,E.jsx)(`p`,{className:`text-[11px] text-trash-gray font-semibold m-0`,children:`Sync algorithm solutions & auto-commit to your personal portfolio repository`})]})]}),(0,E.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,E.jsx)(`span`,{className:`px-2.5 py-1 text-[9px] font-bold font-arcade uppercase border-2 border-ink-black ${J?`bg-emerald-300 text-emerald-950`:`bg-amber-200 text-amber-950`}`,children:J?`CONNECTED`:`DISCONNECTED`})})]}),J?(0,E.jsxs)(`div`,{className:`space-y-4`,children:[(0,E.jsxs)(`div`,{className:`bg-white border-[3px] border-ink-black p-4 shadow-[4px_4px_0px_0px_rgba(30,41,59,1)] flex flex-col sm:flex-row items-start sm:items-center justify-between gap-3`,children:[(0,E.jsxs)(`div`,{className:`flex items-center gap-3`,children:[O?.avatar_url?(0,E.jsx)(`img`,{src:O.avatar_url,alt:O.login,className:`w-10 h-10 rounded-full border-2 border-ink-black shadow-[1px_1px_0px_0px_#1E293B]`}):(0,E.jsx)(`div`,{className:`w-10 h-10 bg-slate-200 rounded-full border-2 border-ink-black flex items-center justify-center font-bold`,children:`GH`}),(0,E.jsxs)(`div`,{children:[(0,E.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,E.jsx)(`span`,{className:`font-bold text-xs text-ink-black`,children:O?.name||O?.login||h.username}),(0,E.jsxs)(`span`,{className:`text-[10px] text-trash-gray font-mono`,children:[`(@`,O?.login||h.username,`)`]})]}),(0,E.jsxs)(`div`,{className:`text-[11px] text-slate-600 font-medium flex items-center gap-1 mt-0.5`,children:[(0,E.jsx)(o,{className:`w-3.5 h-3.5 text-blue-600 shrink-0`}),(0,E.jsxs)(`span`,{className:`font-semibold text-ink-black`,children:[h.username||O?.login,`/`,h.repoName]}),(0,E.jsxs)(`span`,{className:`text-slate-400`,children:[`(`,h.branch,`)`]})]})]})]}),(0,E.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,E.jsxs)(`a`,{href:`https://github.com/${h.username||O?.login}/${h.repoName}`,target:`_blank`,rel:`noopener noreferrer`,className:`px-3 py-1.5 bg-slate-50 hover:bg-slate-100 border-2 border-ink-black text-xs font-bold text-ink-black flex items-center gap-1 shadow-[2px_2px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none no-underline cursor-pointer`,children:[(0,E.jsx)(p,{className:`w-3.5 h-3.5`}),(0,E.jsx)(`span`,{children:`View Repo`})]}),(0,E.jsxs)(`button`,{onClick:()=>{window.confirm(`Disconnect your GitHub account from AlgoSpaced?`)&&(w(),D(S()),k(null),q({type:`info`,text:`Disconnected from GitHub.`}))},className:`px-3 py-1.5 bg-white hover:bg-rose-50 border-2 border-rose-300 text-rose-700 text-xs font-bold flex items-center gap-1 cursor-pointer transition-all`,title:`Disconnect GitHub`,children:[(0,E.jsx)(n,{className:`w-3 h-3`}),(0,E.jsx)(`span`,{children:`Disconnect`})]})]})]}),(0,E.jsxs)(`div`,{className:`bg-white border-[3px] border-ink-black p-4 shadow-[4px_4px_0px_0px_rgba(30,41,59,1)] space-y-3`,children:[(0,E.jsxs)(`div`,{className:`flex items-center justify-between border-b pb-2 border-slate-200`,children:[(0,E.jsxs)(`span`,{className:`font-headline-md font-bold text-xs uppercase text-ink-black flex items-center gap-1.5`,children:[(0,E.jsx)(i,{className:`w-3.5 h-3.5 text-ink-black`}),`Target Repository & Branch`]}),(0,E.jsxs)(`button`,{onClick:Z,disabled:B,className:`px-2.5 py-1 bg-yellow-100 hover:bg-yellow-200 border border-ink-black text-[10px] font-bold text-ink-black flex items-center gap-1 cursor-pointer disabled:opacity-50 shadow-[1px_1px_0px_0px_#1E293B]`,children:[B?(0,E.jsx)(l,{className:`w-3 h-3 animate-spin`}):(0,E.jsx)(m,{className:`w-3 h-3 text-emerald-700`}),(0,E.jsx)(`span`,{children:`Verify / Init Repo`})]})]}),(0,E.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[(0,E.jsxs)(`div`,{children:[(0,E.jsx)(`label`,{className:`block text-[10px] font-bold text-trash-gray uppercase mb-1`,children:`Repository Name`}),(0,E.jsx)(`input`,{type:`text`,value:h.repoName,onChange:e=>{let t=e.target.value;D(e=>({...e,repoName:t})),C({repoName:t})},placeholder:`algospaced-solutions`,className:`w-full bg-slate-50 border-2 border-ink-black rounded py-1.5 px-2.5 text-xs font-mono font-medium focus:outline-none focus:bg-white`})]}),(0,E.jsxs)(`div`,{children:[(0,E.jsx)(`label`,{className:`block text-[10px] font-bold text-trash-gray uppercase mb-1`,children:`Branch Name`}),(0,E.jsx)(`input`,{type:`text`,value:h.branch,onChange:e=>{let t=e.target.value;D(e=>({...e,branch:t})),C({branch:t})},placeholder:`main`,className:`w-full bg-slate-50 border-2 border-ink-black rounded py-1.5 px-2.5 text-xs font-mono font-medium focus:outline-none focus:bg-white`})]})]}),(0,E.jsxs)(`div`,{className:`pt-2 border-t border-slate-100 flex items-center justify-between`,children:[(0,E.jsxs)(`div`,{className:`flex items-start gap-2.5`,children:[(0,E.jsx)(d,{className:`w-4 h-4 text-amber-500 shrink-0 mt-0.5`}),(0,E.jsxs)(`div`,{children:[(0,E.jsx)(`span`,{className:`text-xs font-bold text-ink-black block`,children:`Auto-commit on every submission`}),(0,E.jsx)(`span`,{className:`text-[10px] text-trash-gray font-medium`,children:`Automatically push code to your repo when grading a review card or saving a solution.`})]})]}),(0,E.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer select-none`,children:[(0,E.jsx)(`input`,{type:`checkbox`,checked:h.autoCommit,onChange:e=>ee(e.target.checked),className:`sr-only peer`}),(0,E.jsx)(`div`,{className:`w-9 h-5 bg-slate-300 peer-focus:outline-none border-2 border-ink-black rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-2 after:border-ink-black after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-emerald-500`})]})]})]}),(0,E.jsxs)(`div`,{className:`bg-[#fffdf0] border-[3px] border-ink-black p-4 shadow-[4px_4px_0px_0px_rgba(30,41,59,1)] space-y-3`,children:[(0,E.jsxs)(`span`,{className:`font-headline-md font-bold text-xs uppercase text-ink-black flex items-center gap-1.5`,children:[(0,E.jsx)(f,{className:`w-3.5 h-3.5 text-ink-black`}),`Manual Push & Sync Operations`]}),(0,E.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[(0,E.jsxs)(`button`,{onClick:$,disabled:W||!r,className:`p-3 bg-white hover:bg-emerald-50 border-2 border-ink-black text-left flex flex-col justify-between gap-1 shadow-[2px_2px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none cursor-pointer transition-all disabled:opacity-50`,children:[(0,E.jsxs)(`div`,{className:`flex items-center justify-between w-full`,children:[(0,E.jsxs)(`span`,{className:`font-bold text-xs text-ink-black font-headline-md flex items-center gap-1.5`,children:[W?(0,E.jsx)(l,{className:`w-3.5 h-3.5 animate-spin text-emerald-600`}):(0,E.jsx)(a,{className:`w-3.5 h-3.5 text-emerald-600`}),`Push Active Problem`]}),r?.problem_number&&(0,E.jsxs)(`span`,{className:`text-[9px] font-mono px-1.5 py-0.5 bg-emerald-100 text-emerald-800 rounded font-bold`,children:[`#`,r.problem_number]})]}),(0,E.jsx)(`span`,{className:`text-[10px] text-slate-500 line-clamp-1`,children:r?.name||`No active problem open in review`})]}),(0,E.jsxs)(`button`,{onClick:Q,disabled:H,className:`p-3 bg-[#ffe24c] hover:bg-yellow-300 border-2 border-ink-black text-left flex flex-col justify-between gap-1 shadow-[2px_2px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none cursor-pointer transition-all disabled:opacity-50`,children:[(0,E.jsxs)(`div`,{className:`flex items-center justify-between w-full`,children:[(0,E.jsxs)(`span`,{className:`font-bold text-xs text-ink-black font-headline-md flex items-center gap-1.5`,children:[H?(0,E.jsx)(l,{className:`w-3.5 h-3.5 animate-spin text-ink-black`}):(0,E.jsx)(o,{className:`w-3.5 h-3.5 text-ink-black`}),`Sync Entire Library`]}),(0,E.jsx)(`span`,{className:`text-[8px] font-arcade uppercase font-bold bg-white px-1.5 py-0.5 border border-ink-black`,children:`BATCH`})]}),(0,E.jsx)(`span`,{className:`text-[10px] text-slate-700`,children:`Push all solved problems + generate root README index`})]})]})]})]}):(0,E.jsxs)(`div`,{className:`space-y-4`,children:[(0,E.jsxs)(`div`,{className:`bg-white border-[3px] border-ink-black p-5 sm:p-6 shadow-[4px_4px_0px_0px_rgba(30,41,59,1)] text-center space-y-4`,children:[(0,E.jsxs)(`div`,{className:`max-w-md mx-auto space-y-2`,children:[(0,E.jsx)(`h4`,{className:`font-headline-md font-bold text-sm uppercase text-ink-black m-0`,children:`Connect Your GitHub Account`}),(0,E.jsx)(`p`,{className:`text-xs text-trash-gray font-medium leading-relaxed m-0`,children:`Sync all your DSA solutions directly to your GitHub repository. Commit automatically on review completion or push anytime with 1-click.`})]}),(0,E.jsxs)(`div`,{className:`pt-2 flex flex-col items-center`,children:[(0,E.jsx)(`button`,{onClick:Y,disabled:I,className:`w-full sm:w-auto px-6 py-3 bg-[#24292e] hover:bg-black text-white font-bold text-xs uppercase font-headline-md border-[3px] border-ink-black shadow-[3px_3px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none flex items-center justify-center gap-2.5 transition-all cursor-pointer disabled:opacity-50`,children:I?(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(l,{className:`w-4 h-4 animate-spin text-yellow-300`}),(0,E.jsx)(`span`,{children:`AUTHORIZING WITH GITHUB...`})]}):(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`svg`,{className:`w-4 h-4 fill-white`,viewBox:`0 0 19 19`,children:(0,E.jsx)(`path`,{fillRule:`evenodd`,d:`M9.356 1.85C5.05 1.85 1.57 5.356 1.57 9.694a7.84 7.84 0 0 0 5.324 7.44c.387.079.528-.168.528-.376 0-.182-.013-.805-.013-1.454-2.165.467-2.616-.935-2.616-.935-.349-.91-.864-1.143-.864-1.143-.71-.48.051-.48.051-.48.787.051 1.2.805 1.2.805.695 1.194 1.817.857 2.268.649.064-.507.27-.857.49-1.052-1.728-.182-3.545-.857-3.545-3.87 0-.857.31-1.558.8-2.104-.078-.195-.349-1 .077-2.078 0 0 .657-.208 2.14.805a7.5 7.5 0 0 1 1.946-.26c.657 0 1.328.092 1.946.26 1.483-1.013 2.14-.805 2.14-.805.426 1.078.155 1.883.078 2.078.502.546.799 1.247.799 2.104 0 3.013-1.818 3.675-3.558 3.87.284.247.528.714.528 1.454 0 1.052-.012 1.896-.012 2.156 0 .208.142.455.528.377a7.84 7.84 0 0 0 5.324-7.441c.013-4.338-3.48-7.844-7.773-7.844`,clipRule:`evenodd`})}),(0,E.jsx)(`span`,{children:`CONNECT WITH GITHUB (1-CLICK)`})]})}),(0,E.jsxs)(`span`,{className:`text-[10px] text-trash-gray mt-2`,children:[`Direct 1-click OAuth (works for guest and signed-in users). Requests `,(0,E.jsx)(`code`,{children:`repo`}),` access.`]})]})]}),(0,E.jsxs)(`div`,{className:`bg-white border-[3px] border-ink-black p-4 shadow-[4px_4px_0px_0px_rgba(30,41,59,1)]`,children:[(0,E.jsxs)(`button`,{type:`button`,onClick:()=>N(!M),className:`w-full flex items-center justify-between text-left text-xs font-bold text-ink-black font-headline-md uppercase cursor-pointer bg-transparent border-0 p-0`,children:[(0,E.jsx)(`span`,{children:`Or connect via Personal Access Token (PAT)`}),(0,E.jsx)(`span`,{className:`text-slate-500`,children:M?`▲ Hide`:`▼ Show`})]}),M&&(0,E.jsxs)(`div`,{className:`mt-3 pt-3 border-t border-slate-200 space-y-3`,children:[(0,E.jsxs)(`div`,{className:`flex items-center justify-between text-[11px]`,children:[(0,E.jsx)(`span`,{className:`font-semibold text-slate-700`,children:`Personal Access Token:`}),(0,E.jsxs)(`a`,{href:`https://github.com/settings/tokens/new?scopes=repo&description=AlgoSpaced%20Solutions%20Sync`,target:`_blank`,rel:`noopener noreferrer`,className:`text-blue-600 hover:text-blue-800 font-bold flex items-center gap-1 no-underline text-[10px]`,children:[(0,E.jsx)(`span`,{children:`Generate token with repo scope`}),(0,E.jsx)(p,{className:`w-3 h-3`})]})]}),(0,E.jsxs)(`div`,{className:`relative`,children:[(0,E.jsx)(`input`,{type:P?`text`:`password`,value:A,onChange:e=>j(e.target.value),placeholder:`ghp_... or github_pat_...`,className:`w-full bg-slate-50 border-2 border-ink-black rounded py-2 pl-3 pr-9 text-xs font-mono focus:outline-none focus:bg-white`}),(0,E.jsx)(`button`,{type:`button`,onClick:()=>F(!P),className:`absolute right-2.5 top-1/2 -translate-y-1/2 text-slate-400 hover:text-ink-black cursor-pointer bg-transparent border-0 p-1`,children:P?(0,E.jsx)(s,{className:`w-3.5 h-3.5`}):(0,E.jsx)(t,{className:`w-3.5 h-3.5`})})]}),(0,E.jsx)(`button`,{onClick:X,disabled:R||!A.trim(),className:`px-4 py-2 bg-[#ffe24c] hover:bg-yellow-300 text-ink-black font-bold text-xs uppercase border-2 border-ink-black shadow-[2px_2px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none cursor-pointer disabled:opacity-50 flex items-center gap-1.5`,children:R?(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(l,{className:`w-3.5 h-3.5 animate-spin`}),(0,E.jsx)(`span`,{children:`VERIFYING TOKEN...`})]}):(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(m,{className:`w-3.5 h-3.5`}),(0,E.jsx)(`span`,{children:`SAVE & CONNECT TOKEN`})]})})]})]})]}),K&&(0,E.jsxs)(`div`,{className:`p-3 border-[2px] border-ink-black text-xs font-semibold rounded flex items-center justify-between gap-2 ${K.type===`success`?`bg-emerald-100 text-emerald-900 border-emerald-600`:K.type===`error`?`bg-rose-100 text-rose-900 border-rose-600`:`bg-sky-100 text-sky-900 border-sky-600`}`,children:[(0,E.jsxs)(`div`,{className:`flex items-center gap-2`,children:[K.type===`success`?(0,E.jsx)(c,{className:`w-4 h-4 shrink-0`}):(0,E.jsx)(u,{className:`w-4 h-4 shrink-0`}),(0,E.jsx)(`span`,{children:K.text})]}),K.linkUrl&&(0,E.jsxs)(`a`,{href:K.linkUrl,target:`_blank`,rel:`noopener noreferrer`,className:`px-2 py-0.5 bg-white border border-ink-black text-[10px] font-bold text-ink-black hover:bg-slate-50 no-underline shrink-0 flex items-center gap-1`,children:[(0,E.jsx)(`span`,{children:`Open`}),(0,E.jsx)(p,{className:`w-3 h-3`})]})]})]}),(0,E.jsx)(`div`,{className:`pt-4 border-t border-slate-300 flex justify-end`,children:(0,E.jsx)(`button`,{onClick:e,className:`px-4 py-2 bg-white hover:bg-slate-100 border-[2px] border-ink-black text-xs font-bold text-ink-black shadow-[2px_2px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none cursor-pointer uppercase`,children:`CLOSE`})})]})};export{D as GitHubSyncWindow,D as default};
|
|
|
|
| 1 |
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{$ as t,A as n,H as r,Lt as i,X as a,Y as o,Z as s,et as c,ft as l,mt as u,o as d,st as f,tt as p,yt as m,zt as h}from"./vendor-react-qmUj3JUi.js";import{a as g,c as _,i as v,l as y,n as b,o as x,r as S,s as C,t as w}from"./githubSyncService-DQdE4J2L.js";var T=e(h(),1),E=i(),D=({onClose:e,currentProblem:i})=>{let[h,D]=(0,T.useState)(()=>S()),[O,k]=(0,T.useState)(()=>v()),[A,j]=(0,T.useState)(``),[M,N]=(0,T.useState)(!1),[P,F]=(0,T.useState)(!1),[I,L]=(0,T.useState)(!1),[R,z]=(0,T.useState)(!1),[B,V]=(0,T.useState)(!1),[H,U]=(0,T.useState)(!1),[W,G]=(0,T.useState)(!1),[K,q]=(0,T.useState)(null),J=!!(h.token&&(h.username||O?.login));(0,T.useEffect)(()=>{h.token&&!O&&y(h.token).then(e=>{e.valid&&e.user&&(k(e.user),C({username:e.user.login},e.user))})},[h.token,O]);let Y=async()=>{L(!0),q(null);try{let{token:e,user:t}=await b();k(t);let n=S();D(n);try{await g(e,n.repoName,n.isPrivate)}catch{}q({type:`success`,text:`Connected successfully to GitHub as @${t.login}!`,linkUrl:t.html_url})}catch(e){q({type:`error`,text:e.message||`GitHub OAuth authorization failed.`})}finally{L(!1)}},X=async()=>{let e=A.trim();if(!e){q({type:`error`,text:`Please enter a valid GitHub token.`});return}z(!0),q(null);try{let t=await y(e);if(t.valid&&t.user){k(t.user),C({token:e,username:t.user.login},t.user),D(S());try{await g(e,h.repoName,h.isPrivate)}catch{}j(``),N(!1),q({type:`success`,text:`Verified and connected as @${t.user.login}!`,linkUrl:t.user.html_url})}else q({type:`error`,text:t.error||`Token verification failed. Please check permissions.`})}catch(e){q({type:`error`,text:e.message||`Failed to connect with token.`})}finally{z(!1)}},Z=async()=>{if(h.token){V(!0),q(null);try{let e=await g(h.token,h.repoName,h.isPrivate);C({repoName:h.repoName}),q({type:`success`,text:e.created?`Created new repository ${e.full_name} on GitHub!`:`Connected to existing repository ${e.full_name}!`,linkUrl:e.html_url})}catch(e){q({type:`error`,text:e.message||`Failed to initialize repository.`})}finally{V(!1)}}},Q=async()=>{if(h.token&&h.repoName){U(!0),q(null);try{let e=await _(h.token,h.repoName,h.branch);q({type:`success`,text:e.message||`Synced ${e.synced_count} solutions to ${h.repoName}!`,linkUrl:e.repo_url})}catch(e){q({type:`error`,text:e.message||`Batch sync failed.`})}finally{U(!1)}}},$=async()=>{if(!i||!h.token)return;let e=i.code||i.reference_code;if(!e||!e.trim()){q({type:`error`,text:`Current problem has no code to push. Write or save code first!`});return}G(!0),q(null);try{let t={token:h.token,repo:h.repoName,branch:h.branch,problem_number:i.problem_number,problem_name:i.name||`Algorithm Problem`,difficulty:i.difficulty||`Medium`,pattern:i.pattern||`Algorithms`,optimal_time:i.optimal_time||`O(N)`,optimal_space:i.optimal_space||`O(1)`,description:i.description||``,code:e},n=await x(t);q({type:`success`,text:`Committed ${i.name} to GitHub!`,linkUrl:n.html_url})}catch(e){q({type:`error`,text:e.message||`Failed to push current solution.`})}finally{G(!1)}},ee=e=>{C({autoCommit:e}),D(t=>({...t,autoCommit:e})),q({type:`info`,text:e?`Auto-commit ENABLED: Solutions will sync automatically on submission.`:`Auto-commit DISABLED: You can still push manually any time.`})};return(0,E.jsxs)(`div`,{className:`w-full h-full bg-[#fdf8e1] p-4 sm:p-6 flex flex-col justify-between select-none font-sans text-ink-black overflow-y-auto custom-scrollbar`,children:[(0,E.jsxs)(`div`,{className:`space-y-4`,children:[(0,E.jsxs)(`div`,{className:`flex items-center justify-between border-b-[3px] border-ink-black pb-3`,children:[(0,E.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,E.jsx)(`div`,{className:`w-9 h-9 bg-ink-black rounded border-2 border-ink-black flex items-center justify-center text-white shadow-[2px_2px_0px_0px_rgba(0,0,0,0.15)]`,children:(0,E.jsx)(`svg`,{className:`w-5 h-5 fill-white`,viewBox:`0 0 19 19`,children:(0,E.jsx)(`path`,{fillRule:`evenodd`,d:`M9.356 1.85C5.05 1.85 1.57 5.356 1.57 9.694a7.84 7.84 0 0 0 5.324 7.44c.387.079.528-.168.528-.376 0-.182-.013-.805-.013-1.454-2.165.467-2.616-.935-2.616-.935-.349-.91-.864-1.143-.864-1.143-.71-.48.051-.48.051-.48.787.051 1.2.805 1.2.805.695 1.194 1.817.857 2.268.649.064-.507.27-.857.49-1.052-1.728-.182-3.545-.857-3.545-3.87 0-.857.31-1.558.8-2.104-.078-.195-.349-1 .077-2.078 0 0 .657-.208 2.14.805a7.5 7.5 0 0 1 1.946-.26c.657 0 1.328.092 1.946.26 1.483-1.013 2.14-.805 2.14-.805.426 1.078.155 1.883.078 2.078.502.546.799 1.247.799 2.104 0 3.013-1.818 3.675-3.558 3.87.284.247.528.714.528 1.454 0 1.052-.012 1.896-.012 2.156 0 .208.142.455.528.377a7.84 7.84 0 0 0 5.324-7.441c.013-4.338-3.48-7.844-7.773-7.844`,clipRule:`evenodd`})})}),(0,E.jsxs)(`div`,{children:[(0,E.jsx)(`h3`,{className:`font-headline-md font-bold text-sm uppercase m-0 flex items-center gap-2`,children:`GitHub Solutions Station`}),(0,E.jsx)(`p`,{className:`text-[11px] text-trash-gray font-semibold m-0`,children:`Sync algorithm solutions & auto-commit to your personal portfolio repository`})]})]}),(0,E.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,E.jsx)(`span`,{className:`px-2.5 py-1 text-[9px] font-bold font-arcade uppercase border-2 border-ink-black ${J?`bg-emerald-300 text-emerald-950`:`bg-amber-200 text-amber-950`}`,children:J?`CONNECTED`:`DISCONNECTED`})})]}),J?(0,E.jsxs)(`div`,{className:`space-y-4`,children:[(0,E.jsxs)(`div`,{className:`bg-white border-[3px] border-ink-black p-4 shadow-[4px_4px_0px_0px_rgba(30,41,59,1)] flex flex-col sm:flex-row items-start sm:items-center justify-between gap-3`,children:[(0,E.jsxs)(`div`,{className:`flex items-center gap-3`,children:[O?.avatar_url?(0,E.jsx)(`img`,{src:O.avatar_url,alt:O.login,className:`w-10 h-10 rounded-full border-2 border-ink-black shadow-[1px_1px_0px_0px_#1E293B]`}):(0,E.jsx)(`div`,{className:`w-10 h-10 bg-slate-200 rounded-full border-2 border-ink-black flex items-center justify-center font-bold`,children:`GH`}),(0,E.jsxs)(`div`,{children:[(0,E.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,E.jsx)(`span`,{className:`font-bold text-xs text-ink-black`,children:O?.name||O?.login||h.username}),(0,E.jsxs)(`span`,{className:`text-[10px] text-trash-gray font-mono`,children:[`(@`,O?.login||h.username,`)`]})]}),(0,E.jsxs)(`div`,{className:`text-[11px] text-slate-600 font-medium flex items-center gap-1 mt-0.5`,children:[(0,E.jsx)(s,{className:`w-3.5 h-3.5 text-blue-600 shrink-0`}),(0,E.jsxs)(`span`,{className:`font-semibold text-ink-black`,children:[h.username||O?.login,`/`,h.repoName]}),(0,E.jsxs)(`span`,{className:`text-slate-400`,children:[`(`,h.branch,`)`]})]})]})]}),(0,E.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,E.jsxs)(`a`,{href:`https://github.com/${h.username||O?.login}/${h.repoName}`,target:`_blank`,rel:`noopener noreferrer`,className:`px-3 py-1.5 bg-slate-50 hover:bg-slate-100 border-2 border-ink-black text-xs font-bold text-ink-black flex items-center gap-1 shadow-[2px_2px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none no-underline cursor-pointer`,children:[(0,E.jsx)(p,{className:`w-3.5 h-3.5`}),(0,E.jsx)(`span`,{children:`View Repo`})]}),(0,E.jsxs)(`button`,{onClick:()=>{window.confirm(`Disconnect your GitHub account from AlgoSpaced?`)&&(w(),D(S()),k(null),q({type:`info`,text:`Disconnected from GitHub.`}))},className:`px-3 py-1.5 bg-white hover:bg-rose-50 border-2 border-rose-300 text-rose-700 text-xs font-bold flex items-center gap-1 cursor-pointer transition-all`,title:`Disconnect GitHub`,children:[(0,E.jsx)(r,{className:`w-3 h-3`}),(0,E.jsx)(`span`,{children:`Disconnect`})]})]})]}),(0,E.jsxs)(`div`,{className:`bg-white border-[3px] border-ink-black p-4 shadow-[4px_4px_0px_0px_rgba(30,41,59,1)] space-y-3`,children:[(0,E.jsxs)(`div`,{className:`flex items-center justify-between border-b pb-2 border-slate-200`,children:[(0,E.jsxs)(`span`,{className:`font-headline-md font-bold text-xs uppercase text-ink-black flex items-center gap-1.5`,children:[(0,E.jsx)(a,{className:`w-3.5 h-3.5 text-ink-black`}),`Target Repository & Branch`]}),(0,E.jsxs)(`button`,{onClick:Z,disabled:B,className:`px-2.5 py-1 bg-yellow-100 hover:bg-yellow-200 border border-ink-black text-[10px] font-bold text-ink-black flex items-center gap-1 cursor-pointer disabled:opacity-50 shadow-[1px_1px_0px_0px_#1E293B]`,children:[B?(0,E.jsx)(n,{className:`w-3 h-3 animate-spin`}):(0,E.jsx)(m,{className:`w-3 h-3 text-emerald-700`}),(0,E.jsx)(`span`,{children:`Verify / Init Repo`})]})]}),(0,E.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[(0,E.jsxs)(`div`,{children:[(0,E.jsx)(`label`,{className:`block text-[10px] font-bold text-trash-gray uppercase mb-1`,children:`Repository Name`}),(0,E.jsx)(`input`,{type:`text`,value:h.repoName,onChange:e=>{let t=e.target.value;D(e=>({...e,repoName:t})),C({repoName:t})},placeholder:`algospaced-solutions`,className:`w-full bg-slate-50 border-2 border-ink-black rounded py-1.5 px-2.5 text-xs font-mono font-medium focus:outline-none focus:bg-white`})]}),(0,E.jsxs)(`div`,{children:[(0,E.jsx)(`label`,{className:`block text-[10px] font-bold text-trash-gray uppercase mb-1`,children:`Branch Name`}),(0,E.jsx)(`input`,{type:`text`,value:h.branch,onChange:e=>{let t=e.target.value;D(e=>({...e,branch:t})),C({branch:t})},placeholder:`main`,className:`w-full bg-slate-50 border-2 border-ink-black rounded py-1.5 px-2.5 text-xs font-mono font-medium focus:outline-none focus:bg-white`})]})]}),(0,E.jsxs)(`div`,{className:`pt-2 border-t border-slate-100 flex items-center justify-between`,children:[(0,E.jsxs)(`div`,{className:`flex items-start gap-2.5`,children:[(0,E.jsx)(d,{className:`w-4 h-4 text-amber-500 shrink-0 mt-0.5`}),(0,E.jsxs)(`div`,{children:[(0,E.jsx)(`span`,{className:`text-xs font-bold text-ink-black block`,children:`Auto-commit on every submission`}),(0,E.jsx)(`span`,{className:`text-[10px] text-trash-gray font-medium`,children:`Automatically push code to your repo when grading a review card or saving a solution.`})]})]}),(0,E.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer select-none`,children:[(0,E.jsx)(`input`,{type:`checkbox`,checked:h.autoCommit,onChange:e=>ee(e.target.checked),className:`sr-only peer`}),(0,E.jsx)(`div`,{className:`w-9 h-5 bg-slate-300 peer-focus:outline-none border-2 border-ink-black rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-2 after:border-ink-black after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-emerald-500`})]})]})]}),(0,E.jsxs)(`div`,{className:`bg-[#fffdf0] border-[3px] border-ink-black p-4 shadow-[4px_4px_0px_0px_rgba(30,41,59,1)] space-y-3`,children:[(0,E.jsxs)(`span`,{className:`font-headline-md font-bold text-xs uppercase text-ink-black flex items-center gap-1.5`,children:[(0,E.jsx)(f,{className:`w-3.5 h-3.5 text-ink-black`}),`Manual Push & Sync Operations`]}),(0,E.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[(0,E.jsxs)(`button`,{onClick:$,disabled:W||!i,className:`p-3 bg-white hover:bg-emerald-50 border-2 border-ink-black text-left flex flex-col justify-between gap-1 shadow-[2px_2px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none cursor-pointer transition-all disabled:opacity-50`,children:[(0,E.jsxs)(`div`,{className:`flex items-center justify-between w-full`,children:[(0,E.jsxs)(`span`,{className:`font-bold text-xs text-ink-black font-headline-md flex items-center gap-1.5`,children:[W?(0,E.jsx)(n,{className:`w-3.5 h-3.5 animate-spin text-emerald-600`}):(0,E.jsx)(o,{className:`w-3.5 h-3.5 text-emerald-600`}),`Push Active Problem`]}),i?.problem_number&&(0,E.jsxs)(`span`,{className:`text-[9px] font-mono px-1.5 py-0.5 bg-emerald-100 text-emerald-800 rounded font-bold`,children:[`#`,i.problem_number]})]}),(0,E.jsx)(`span`,{className:`text-[10px] text-slate-500 line-clamp-1`,children:i?.name||`No active problem open in review`})]}),(0,E.jsxs)(`button`,{onClick:Q,disabled:H,className:`p-3 bg-[#ffe24c] hover:bg-yellow-300 border-2 border-ink-black text-left flex flex-col justify-between gap-1 shadow-[2px_2px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none cursor-pointer transition-all disabled:opacity-50`,children:[(0,E.jsxs)(`div`,{className:`flex items-center justify-between w-full`,children:[(0,E.jsxs)(`span`,{className:`font-bold text-xs text-ink-black font-headline-md flex items-center gap-1.5`,children:[H?(0,E.jsx)(n,{className:`w-3.5 h-3.5 animate-spin text-ink-black`}):(0,E.jsx)(s,{className:`w-3.5 h-3.5 text-ink-black`}),`Sync Entire Library`]}),(0,E.jsx)(`span`,{className:`text-[8px] font-arcade uppercase font-bold bg-white px-1.5 py-0.5 border border-ink-black`,children:`BATCH`})]}),(0,E.jsx)(`span`,{className:`text-[10px] text-slate-700`,children:`Push all solved problems + generate root README index`})]})]})]})]}):(0,E.jsxs)(`div`,{className:`space-y-4`,children:[(0,E.jsxs)(`div`,{className:`bg-white border-[3px] border-ink-black p-5 sm:p-6 shadow-[4px_4px_0px_0px_rgba(30,41,59,1)] text-center space-y-4`,children:[(0,E.jsxs)(`div`,{className:`max-w-md mx-auto space-y-2`,children:[(0,E.jsx)(`h4`,{className:`font-headline-md font-bold text-sm uppercase text-ink-black m-0`,children:`Connect Your GitHub Account`}),(0,E.jsx)(`p`,{className:`text-xs text-trash-gray font-medium leading-relaxed m-0`,children:`Sync all your DSA solutions directly to your GitHub repository. Commit automatically on review completion or push anytime with 1-click.`})]}),(0,E.jsxs)(`div`,{className:`pt-2 flex flex-col items-center`,children:[(0,E.jsx)(`button`,{onClick:Y,disabled:I,className:`w-full sm:w-auto px-6 py-3 bg-[#24292e] hover:bg-black text-white font-bold text-xs uppercase font-headline-md border-[3px] border-ink-black shadow-[3px_3px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none flex items-center justify-center gap-2.5 transition-all cursor-pointer disabled:opacity-50`,children:I?(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(n,{className:`w-4 h-4 animate-spin text-yellow-300`}),(0,E.jsx)(`span`,{children:`AUTHORIZING WITH GITHUB...`})]}):(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`svg`,{className:`w-4 h-4 fill-white`,viewBox:`0 0 19 19`,children:(0,E.jsx)(`path`,{fillRule:`evenodd`,d:`M9.356 1.85C5.05 1.85 1.57 5.356 1.57 9.694a7.84 7.84 0 0 0 5.324 7.44c.387.079.528-.168.528-.376 0-.182-.013-.805-.013-1.454-2.165.467-2.616-.935-2.616-.935-.349-.91-.864-1.143-.864-1.143-.71-.48.051-.48.051-.48.787.051 1.2.805 1.2.805.695 1.194 1.817.857 2.268.649.064-.507.27-.857.49-1.052-1.728-.182-3.545-.857-3.545-3.87 0-.857.31-1.558.8-2.104-.078-.195-.349-1 .077-2.078 0 0 .657-.208 2.14.805a7.5 7.5 0 0 1 1.946-.26c.657 0 1.328.092 1.946.26 1.483-1.013 2.14-.805 2.14-.805.426 1.078.155 1.883.078 2.078.502.546.799 1.247.799 2.104 0 3.013-1.818 3.675-3.558 3.87.284.247.528.714.528 1.454 0 1.052-.012 1.896-.012 2.156 0 .208.142.455.528.377a7.84 7.84 0 0 0 5.324-7.441c.013-4.338-3.48-7.844-7.773-7.844`,clipRule:`evenodd`})}),(0,E.jsx)(`span`,{children:`CONNECT WITH GITHUB (1-CLICK)`})]})}),(0,E.jsxs)(`span`,{className:`text-[10px] text-trash-gray mt-2`,children:[`Direct 1-click OAuth (works for guest and signed-in users). Requests `,(0,E.jsx)(`code`,{children:`repo`}),` access.`]})]})]}),(0,E.jsxs)(`div`,{className:`bg-white border-[3px] border-ink-black p-4 shadow-[4px_4px_0px_0px_rgba(30,41,59,1)]`,children:[(0,E.jsxs)(`button`,{type:`button`,onClick:()=>N(!M),className:`w-full flex items-center justify-between text-left text-xs font-bold text-ink-black font-headline-md uppercase cursor-pointer bg-transparent border-0 p-0`,children:[(0,E.jsx)(`span`,{children:`Or connect via Personal Access Token (PAT)`}),(0,E.jsx)(`span`,{className:`text-slate-500`,children:M?`▲ Hide`:`▼ Show`})]}),M&&(0,E.jsxs)(`div`,{className:`mt-3 pt-3 border-t border-slate-200 space-y-3`,children:[(0,E.jsxs)(`div`,{className:`flex items-center justify-between text-[11px]`,children:[(0,E.jsx)(`span`,{className:`font-semibold text-slate-700`,children:`Personal Access Token:`}),(0,E.jsxs)(`a`,{href:`https://github.com/settings/tokens/new?scopes=repo&description=AlgoSpaced%20Solutions%20Sync`,target:`_blank`,rel:`noopener noreferrer`,className:`text-blue-600 hover:text-blue-800 font-bold flex items-center gap-1 no-underline text-[10px]`,children:[(0,E.jsx)(`span`,{children:`Generate token with repo scope`}),(0,E.jsx)(p,{className:`w-3 h-3`})]})]}),(0,E.jsxs)(`div`,{className:`relative`,children:[(0,E.jsx)(`input`,{type:P?`text`:`password`,value:A,onChange:e=>j(e.target.value),placeholder:`ghp_... or github_pat_...`,className:`w-full bg-slate-50 border-2 border-ink-black rounded py-2 pl-3 pr-9 text-xs font-mono focus:outline-none focus:bg-white`}),(0,E.jsx)(`button`,{type:`button`,onClick:()=>F(!P),className:`absolute right-2.5 top-1/2 -translate-y-1/2 text-slate-400 hover:text-ink-black cursor-pointer bg-transparent border-0 p-1`,children:P?(0,E.jsx)(c,{className:`w-3.5 h-3.5`}):(0,E.jsx)(t,{className:`w-3.5 h-3.5`})})]}),(0,E.jsx)(`button`,{onClick:X,disabled:R||!A.trim(),className:`px-4 py-2 bg-[#ffe24c] hover:bg-yellow-300 text-ink-black font-bold text-xs uppercase border-2 border-ink-black shadow-[2px_2px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none cursor-pointer disabled:opacity-50 flex items-center gap-1.5`,children:R?(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(n,{className:`w-3.5 h-3.5 animate-spin`}),(0,E.jsx)(`span`,{children:`VERIFYING TOKEN...`})]}):(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(m,{className:`w-3.5 h-3.5`}),(0,E.jsx)(`span`,{children:`SAVE & CONNECT TOKEN`})]})})]})]})]}),K&&(0,E.jsxs)(`div`,{className:`p-3 border-[2px] border-ink-black text-xs font-semibold rounded flex items-center justify-between gap-2 ${K.type===`success`?`bg-emerald-100 text-emerald-900 border-emerald-600`:K.type===`error`?`bg-rose-100 text-rose-900 border-rose-600`:`bg-sky-100 text-sky-900 border-sky-600`}`,children:[(0,E.jsxs)(`div`,{className:`flex items-center gap-2`,children:[K.type===`success`?(0,E.jsx)(l,{className:`w-4 h-4 shrink-0`}):(0,E.jsx)(u,{className:`w-4 h-4 shrink-0`}),(0,E.jsx)(`span`,{children:K.text})]}),K.linkUrl&&(0,E.jsxs)(`a`,{href:K.linkUrl,target:`_blank`,rel:`noopener noreferrer`,className:`px-2 py-0.5 bg-white border border-ink-black text-[10px] font-bold text-ink-black hover:bg-slate-50 no-underline shrink-0 flex items-center gap-1`,children:[(0,E.jsx)(`span`,{children:`Open`}),(0,E.jsx)(p,{className:`w-3 h-3`})]})]})]}),(0,E.jsx)(`div`,{className:`pt-4 border-t border-slate-300 flex justify-end`,children:(0,E.jsx)(`button`,{onClick:e,className:`px-4 py-2 bg-white hover:bg-slate-100 border-[2px] border-ink-black text-xs font-bold text-ink-black shadow-[2px_2px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none cursor-pointer uppercase`,children:`CLOSE`})})]})};export{D as GitHubSyncWindow,D as default};
|
algospaced-ui/dist/assets/{JourneyPath-EVMcgmrl.js → JourneyPath-DO-UXRtH.js}
RENAMED
|
The diff for this file is too large to render.
See raw diff
|
|
|
algospaced-ui/dist/assets/{KatexRenderer-CnXeuUOr.js → KatexRenderer-DnoTdlgI.js}
RENAMED
|
@@ -1 +1 @@
|
|
| 1 |
-
import"./rolldown-runtime-hePW80VL.js";import{Lt as e,zt as t}from"./vendor-react-
|
|
|
|
| 1 |
+
import"./rolldown-runtime-hePW80VL.js";import{Lt as e,zt as t}from"./vendor-react-qmUj3JUi.js";import{t as n}from"./vendor-katex-Balf574a.js";t();var r=e(),i=({math:e,displayMode:t=!1,className:i=``})=>{let a=``;try{a=n.renderToString(e.trim(),{displayMode:t,throwOnError:!1,output:`html`})}catch{a=`<span class="katex-error text-rose-600 font-mono text-[11px]">${e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`)}</span>`}return(0,r.jsx)(`span`,{className:i,dangerouslySetInnerHTML:{__html:a}})};export{i as KatexRenderer,i as default};
|
algospaced-ui/dist/assets/{MarkdownRenderer-CWg4XXNt.js → MarkdownRenderer-CC5nUs7-.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/KatexRenderer-
|
| 2 |
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Lt as t,zt as n}from"./vendor-react-
|
| 3 |
`),r=e===-1?``:n.slice(3,e).trim(),i=e===-1?n.slice(3,-3).trim():n.slice(e+1,-3).trimEnd();return(0,a.jsxs)(`div`,{className:`my-3 rounded-md overflow-hidden border-[2px] border-ink-black shadow-[3px_3px_0px_0px_#1E293B] bg-[#1E293B]`,children:[r&&(0,a.jsxs)(`div`,{className:`bg-slate-800 text-slate-400 px-3 py-1 text-[9px] font-arcade uppercase tracking-wider border-b border-slate-700 flex justify-between items-center`,children:[(0,a.jsx)(`span`,{children:r}),(0,a.jsx)(`span`,{className:`text-[8px] opacity-70`,children:`SNIPPET`})]}),(0,a.jsx)(`pre`,{className:`p-3 overflow-x-auto font-mono text-[11px] text-[#4ADE80] leading-relaxed custom-scrollbar selection:bg-[#4ADE80] selection:text-[#1E293B]`,children:(0,a.jsx)(`code`,{children:i})})]},`code-${t}`)}if(n.startsWith(`$$`)&&n.endsWith(`$$`)&&n.length>=4||n.startsWith(`\\[`)&&n.endsWith(`\\]`)&&n.length>=4){let e=n.slice(2,-2);return(0,a.jsx)(`div`,{className:`my-3 p-3 bg-slate-50 border-2 border-ink-black rounded overflow-x-auto text-center shadow-[2px_2px_0px_0px_rgba(30,41,59,0.3)] custom-scrollbar`,children:(0,a.jsx)(i.Suspense,{fallback:(0,a.jsx)(`span`,{className:`font-mono text-xs opacity-75`,children:e}),children:(0,a.jsx)(c,{math:e,displayMode:!0})})},`math-${t}`)}let r=e.split(`
|
| 4 |
`),o=[],l=0;for(;l<r.length;){let e=r[l],n=e.trim(),i=`${t}-${l}`;if(n===``){o.push((0,a.jsx)(`div`,{className:`h-1`},i)),l++;continue}if(n.startsWith(`|`)&&n.endsWith(`|`)&&l+1<r.length&&r[l+1].trim().startsWith(`|`)){let e=[];for(;l<r.length&&r[l].trim().startsWith(`|`)&&r[l].trim().endsWith(`|`);)e.push(r[l].trim()),l++;if(e.length>=2){let t=e[0].slice(1,-1).split(`|`).map(e=>e.trim()),n=e.slice(2).map(e=>e.slice(1,-1).split(`|`).map(e=>e.trim()));o.push((0,a.jsx)(`div`,{className:`my-3 overflow-x-auto border-2 border-ink-black rounded shadow-[2px_2px_0px_0px_#1E293B]`,children:(0,a.jsxs)(`table`,{className:`w-full text-left border-collapse text-xs`,children:[(0,a.jsx)(`thead`,{children:(0,a.jsx)(`tr`,{className:`bg-slate-200 border-b-2 border-ink-black`,children:t.map((e,t)=>(0,a.jsx)(`th`,{className:`p-2 font-bold font-headline-md border-r last:border-r-0 border-ink-black`,children:s(e)},t))})}),(0,a.jsx)(`tbody`,{children:n.map((e,t)=>(0,a.jsx)(`tr`,{className:`border-b border-slate-300 last:border-b-0 ${t%2==1?`bg-slate-50`:`bg-white`}`,children:e.map((e,t)=>(0,a.jsx)(`td`,{className:`p-2 border-r last:border-r-0 border-slate-200 font-medium`,children:s(e)},t))},t))})]})},`table-${i}`));continue}}if(n.startsWith(`#### `)){o.push((0,a.jsx)(`h4`,{className:`text-xs font-bold text-ink-black mt-3 mb-1 font-headline-md`,children:s(n.substring(5))},i)),l++;continue}if(n.startsWith(`### `)){o.push((0,a.jsxs)(`h3`,{className:`text-xs font-bold text-primary mt-4 mb-1.5 uppercase font-arcade tracking-wide flex items-center gap-1.5`,children:[(0,a.jsx)(`span`,{className:`w-2 h-2 bg-primary inline-block rounded-xs`}),s(n.substring(4))]},i)),l++;continue}if(n.startsWith(`## `)){o.push((0,a.jsx)(`h2`,{className:`text-sm font-extrabold text-ink-black mt-4 mb-2 font-headline-md border-b-2 border-ink-black pb-1`,children:s(n.substring(3))},i)),l++;continue}if(n.startsWith(`# `)){o.push((0,a.jsx)(`h1`,{className:`text-base font-black text-ink-black mt-5 mb-2 font-headline-md`,children:s(n.substring(2))},i)),l++;continue}if(n===`---`||n===`***`||n===`___`){o.push((0,a.jsx)(`hr`,{className:`my-3 border-t-2 border-dashed border-slate-300`},i)),l++;continue}if(e.trim().startsWith(`>`)){o.push((0,a.jsx)(`blockquote`,{className:`border-l-4 border-primary pl-3 py-1 my-2 bg-slate-50 italic text-slate-700`,children:s(e.trim().substring(1).trim())},i)),l++;continue}if(n.startsWith(`- `)||n.startsWith(`* `)||n.startsWith(`+ `)){let t=e.search(/\S/)>=2?`pl-6`:`pl-2`;o.push((0,a.jsxs)(`div`,{className:`flex items-start gap-2 my-1 ${t}`,children:[(0,a.jsx)(`span`,{className:`text-primary font-bold mt-0.5 shrink-0`,children:`•`}),(0,a.jsx)(`div`,{className:`text-ink-black leading-relaxed flex-1 font-medium`,children:s(n.substring(2))})]},i)),l++;continue}let c=n.match(/^(\d+)\.\s+(.*)$/);if(c){let t=e.search(/\S/)>=2?`pl-6`:`pl-2`;o.push((0,a.jsxs)(`div`,{className:`flex items-start gap-2 my-1 ${t}`,children:[(0,a.jsx)(`span`,{className:`text-primary font-arcade text-[9px] font-bold mt-1 shrink-0 px-1 py-0.2 bg-slate-100 border border-ink-black rounded-xs`,children:c[1]}),(0,a.jsx)(`div`,{className:`text-ink-black leading-relaxed flex-1 font-medium`,children:s(c[2])})]},i)),l++;continue}o.push((0,a.jsx)(`p`,{className:`text-ink-black my-1 font-medium leading-relaxed`,children:s(e)},i)),l++}return(0,a.jsx)(i.Fragment,{children:o},`block-${t}`)})})};export{s as n,l as t};
|
|
|
|
| 1 |
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/KatexRenderer-DnoTdlgI.js","assets/rolldown-runtime-hePW80VL.js","assets/vendor-react-qmUj3JUi.js","assets/vendor-codemirror-By0wlJeM.js","assets/vendor-katex-Balf574a.js","assets/vendor-katex-DtkCqjBQ.css"])))=>i.map(i=>d[i]);
|
| 2 |
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Lt as t,zt as n}from"./vendor-react-qmUj3JUi.js";import{t as r}from"./index-DYMSjoUb.js";var i=e(n(),1),a=t(),o=(0,i.lazy)(()=>r(()=>import(`./KatexRenderer-DnoTdlgI.js`),__vite__mapDeps([0,1,2,3,4,5])));function s(e){return e?e.split(/(\$\$[\s\S]*?\$\$|\\\[[\s\S]*?\\\]|\\\([\s\S]*?\\\)|\$(?:\\\$|[^$\n])+?\$|`[^`\n]+`|\*\*[^*\n]+\*\*|__[^_\n]+__|(?<!\*)\*[^*\n]+(?<!\*)\*|(?<!_)_[^_\n]+(?<!_)_|\[[^\]\n]+\]\([^)\n]+\))/g).map((e,t)=>{if(!e)return null;if(e.startsWith(`$$`)&&e.endsWith(`$$`)&&e.length>=4){let n=e.slice(2,-2);return n.trim()?(0,a.jsx)(i.Suspense,{fallback:(0,a.jsx)(`span`,{className:`font-mono text-xs opacity-75`,children:n}),children:(0,a.jsx)(o,{math:n,displayMode:!0,className:`inline-block my-1 px-1 overflow-x-auto align-middle`})},t):e}if(e.startsWith(`\\[`)&&e.endsWith(`\\]`)&&e.length>=4){let n=e.slice(2,-2);return n.trim()?(0,a.jsx)(i.Suspense,{fallback:(0,a.jsx)(`span`,{className:`font-mono text-xs opacity-75`,children:n}),children:(0,a.jsx)(o,{math:n,displayMode:!0,className:`inline-block my-1 px-1 overflow-x-auto align-middle`})},t):e}if(e.startsWith(`\\(`)&&e.endsWith(`\\)`)&&e.length>=4){let n=e.slice(2,-2);return n.trim()?(0,a.jsx)(i.Suspense,{fallback:(0,a.jsx)(`span`,{className:`font-mono text-xs opacity-75`,children:n}),children:(0,a.jsx)(o,{math:n,displayMode:!1,className:`inline-katex px-0.5 align-baseline`})},t):e}if(e.startsWith(`$`)&&e.endsWith(`$`)&&e.length>=2){let n=e.slice(1,-1);return n.trim()?(0,a.jsx)(i.Suspense,{fallback:(0,a.jsx)(`span`,{className:`font-mono text-xs opacity-75`,children:n}),children:(0,a.jsx)(o,{math:n,displayMode:!1,className:`inline-katex px-0.5 align-baseline`})},t):e}if(e.startsWith("`")&&e.endsWith("`")&&e.length>=2)return(0,a.jsx)(`code`,{className:`bg-[#1E293B] text-[#4ADE80] px-1.5 py-0.5 rounded text-[11px] font-mono border border-ink-black shadow-[1px_1px_0px_0px_#000]`,children:e.slice(1,-1)},t);if(e.startsWith(`**`)&&e.endsWith(`**`)&&e.length>=4||e.startsWith(`__`)&&e.endsWith(`__`)&&e.length>=4)return(0,a.jsx)(`strong`,{className:`text-ink-black font-extrabold`,children:s(e.slice(2,-2))},t);if(e.startsWith(`*`)&&e.endsWith(`*`)&&e.length>=2||e.startsWith(`_`)&&e.endsWith(`_`)&&e.length>=2)return(0,a.jsx)(`em`,{className:`italic text-slate-800`,children:s(e.slice(1,-1))},t);let n=e.match(/^\[([^\]]+)\]\(([^)]+)\)$/);return n?(0,a.jsx)(`a`,{href:n[2],target:`_blank`,rel:`noopener noreferrer`,className:`text-primary underline hover:text-primary/80 font-bold`,children:n[1]},t):e}):[]}var c=(0,i.lazy)(()=>r(()=>import(`./KatexRenderer-DnoTdlgI.js`),__vite__mapDeps([0,1,2,3,4,5]))),l=({content:e,className:t=``})=>{if(!e)return null;let n=e.split(/(```[\s\S]*?```|\$\$[\s\S]*?\$\$|\\\[[\s\S]*?\\\])/g);return(0,a.jsx)(`div`,{className:`markdown-content space-y-2.5 text-ink-black text-xs leading-relaxed font-sans ${t}`,children:n.map((e,t)=>{if(!e)return null;let n=e.trim();if(n.startsWith("```")&&n.endsWith("```")&&n.length>=6){let e=n.indexOf(`
|
| 3 |
`),r=e===-1?``:n.slice(3,e).trim(),i=e===-1?n.slice(3,-3).trim():n.slice(e+1,-3).trimEnd();return(0,a.jsxs)(`div`,{className:`my-3 rounded-md overflow-hidden border-[2px] border-ink-black shadow-[3px_3px_0px_0px_#1E293B] bg-[#1E293B]`,children:[r&&(0,a.jsxs)(`div`,{className:`bg-slate-800 text-slate-400 px-3 py-1 text-[9px] font-arcade uppercase tracking-wider border-b border-slate-700 flex justify-between items-center`,children:[(0,a.jsx)(`span`,{children:r}),(0,a.jsx)(`span`,{className:`text-[8px] opacity-70`,children:`SNIPPET`})]}),(0,a.jsx)(`pre`,{className:`p-3 overflow-x-auto font-mono text-[11px] text-[#4ADE80] leading-relaxed custom-scrollbar selection:bg-[#4ADE80] selection:text-[#1E293B]`,children:(0,a.jsx)(`code`,{children:i})})]},`code-${t}`)}if(n.startsWith(`$$`)&&n.endsWith(`$$`)&&n.length>=4||n.startsWith(`\\[`)&&n.endsWith(`\\]`)&&n.length>=4){let e=n.slice(2,-2);return(0,a.jsx)(`div`,{className:`my-3 p-3 bg-slate-50 border-2 border-ink-black rounded overflow-x-auto text-center shadow-[2px_2px_0px_0px_rgba(30,41,59,0.3)] custom-scrollbar`,children:(0,a.jsx)(i.Suspense,{fallback:(0,a.jsx)(`span`,{className:`font-mono text-xs opacity-75`,children:e}),children:(0,a.jsx)(c,{math:e,displayMode:!0})})},`math-${t}`)}let r=e.split(`
|
| 4 |
`),o=[],l=0;for(;l<r.length;){let e=r[l],n=e.trim(),i=`${t}-${l}`;if(n===``){o.push((0,a.jsx)(`div`,{className:`h-1`},i)),l++;continue}if(n.startsWith(`|`)&&n.endsWith(`|`)&&l+1<r.length&&r[l+1].trim().startsWith(`|`)){let e=[];for(;l<r.length&&r[l].trim().startsWith(`|`)&&r[l].trim().endsWith(`|`);)e.push(r[l].trim()),l++;if(e.length>=2){let t=e[0].slice(1,-1).split(`|`).map(e=>e.trim()),n=e.slice(2).map(e=>e.slice(1,-1).split(`|`).map(e=>e.trim()));o.push((0,a.jsx)(`div`,{className:`my-3 overflow-x-auto border-2 border-ink-black rounded shadow-[2px_2px_0px_0px_#1E293B]`,children:(0,a.jsxs)(`table`,{className:`w-full text-left border-collapse text-xs`,children:[(0,a.jsx)(`thead`,{children:(0,a.jsx)(`tr`,{className:`bg-slate-200 border-b-2 border-ink-black`,children:t.map((e,t)=>(0,a.jsx)(`th`,{className:`p-2 font-bold font-headline-md border-r last:border-r-0 border-ink-black`,children:s(e)},t))})}),(0,a.jsx)(`tbody`,{children:n.map((e,t)=>(0,a.jsx)(`tr`,{className:`border-b border-slate-300 last:border-b-0 ${t%2==1?`bg-slate-50`:`bg-white`}`,children:e.map((e,t)=>(0,a.jsx)(`td`,{className:`p-2 border-r last:border-r-0 border-slate-200 font-medium`,children:s(e)},t))},t))})]})},`table-${i}`));continue}}if(n.startsWith(`#### `)){o.push((0,a.jsx)(`h4`,{className:`text-xs font-bold text-ink-black mt-3 mb-1 font-headline-md`,children:s(n.substring(5))},i)),l++;continue}if(n.startsWith(`### `)){o.push((0,a.jsxs)(`h3`,{className:`text-xs font-bold text-primary mt-4 mb-1.5 uppercase font-arcade tracking-wide flex items-center gap-1.5`,children:[(0,a.jsx)(`span`,{className:`w-2 h-2 bg-primary inline-block rounded-xs`}),s(n.substring(4))]},i)),l++;continue}if(n.startsWith(`## `)){o.push((0,a.jsx)(`h2`,{className:`text-sm font-extrabold text-ink-black mt-4 mb-2 font-headline-md border-b-2 border-ink-black pb-1`,children:s(n.substring(3))},i)),l++;continue}if(n.startsWith(`# `)){o.push((0,a.jsx)(`h1`,{className:`text-base font-black text-ink-black mt-5 mb-2 font-headline-md`,children:s(n.substring(2))},i)),l++;continue}if(n===`---`||n===`***`||n===`___`){o.push((0,a.jsx)(`hr`,{className:`my-3 border-t-2 border-dashed border-slate-300`},i)),l++;continue}if(e.trim().startsWith(`>`)){o.push((0,a.jsx)(`blockquote`,{className:`border-l-4 border-primary pl-3 py-1 my-2 bg-slate-50 italic text-slate-700`,children:s(e.trim().substring(1).trim())},i)),l++;continue}if(n.startsWith(`- `)||n.startsWith(`* `)||n.startsWith(`+ `)){let t=e.search(/\S/)>=2?`pl-6`:`pl-2`;o.push((0,a.jsxs)(`div`,{className:`flex items-start gap-2 my-1 ${t}`,children:[(0,a.jsx)(`span`,{className:`text-primary font-bold mt-0.5 shrink-0`,children:`•`}),(0,a.jsx)(`div`,{className:`text-ink-black leading-relaxed flex-1 font-medium`,children:s(n.substring(2))})]},i)),l++;continue}let c=n.match(/^(\d+)\.\s+(.*)$/);if(c){let t=e.search(/\S/)>=2?`pl-6`:`pl-2`;o.push((0,a.jsxs)(`div`,{className:`flex items-start gap-2 my-1 ${t}`,children:[(0,a.jsx)(`span`,{className:`text-primary font-arcade text-[9px] font-bold mt-1 shrink-0 px-1 py-0.2 bg-slate-100 border border-ink-black rounded-xs`,children:c[1]}),(0,a.jsx)(`div`,{className:`text-ink-black leading-relaxed flex-1 font-medium`,children:s(c[2])})]},i)),l++;continue}o.push((0,a.jsx)(`p`,{className:`text-ink-black my-1 font-medium leading-relaxed`,children:s(e)},i)),l++}return(0,a.jsx)(i.Fragment,{children:o},`block-${t}`)})})};export{s as n,l as t};
|
algospaced-ui/dist/assets/{MySQLPlayground-Co730-U0.js → MySQLPlayground-CA-QZxQM.js}
RENAMED
|
@@ -1 +1 @@
|
|
| 1 |
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Lt as t,zt as n}from"./vendor-react-yvPwY2Sj.js";import{r}from"./firebaseClient-G7klkuBb.js";var i=e(n(),1),a=t();function o(){let[e,t]=(0,i.useState)(null),[n,o]=(0,i.useState)(``),[s,c]=(0,i.useState)(!1),[l,u]=(0,i.useState)(!0),[d,f]=(0,i.useState)(``),[p,m]=(0,i.useState)(null),h=async()=>{u(!0),f(``);try{let{data:{session:e}}=await r.auth.getSession();if(!e){f(`Unauthenticated session`);return}let n=await fetch(`/api/challenges/mysql/status`,{headers:{Authorization:`Bearer ${e.access_token}`}});if(n.ok){let e=await n.json();e.active?t(e):t(null)}else f(`Failed to fetch playground status.`)}catch{f(`Connection timed out.`)}finally{u(!1)}},g=async(e=!1)=>{u(!0),f(``),m(null);try{let{data:{session:n}}=await r.auth.getSession();if(!n){f(`Unauthenticated session`);return}let i=await fetch(`/api/challenges/mysql/init${e?`?refresh=true`:``}`,{method:`POST`,headers:{Authorization:`Bearer ${n.access_token}`}});if(i.ok){let e=await i.json();t({active:!0,title:e.title,objective:e.objective,points:e.points,schema:e.schema,challenge_type:e.challenge_type,completed:!1,total_score:e.total_score})}else f(`Failed to initialize mock database playground.`)}catch{f(`Server connection error.`)}finally{u(!1)}};return(0,i.useEffect)(()=>{h()},[]),l?(0,a.jsxs)(`div`,{className:`w-full h-full bg-paper-white p-6 flex flex-col items-center justify-center font-arcade text-[10px]`,children:[(0,a.jsx)(`div`,{className:`animate-bounce mb-2`,children:`INITIALIZING SQL PLAYGROUND...`}),(0,a.jsx)(`div`,{className:`w-48 h-4 bg-white border-[3px] border-ink-black overflow-hidden relative`,children:(0,a.jsx)(`div`,{className:`absolute inset-y-0 left-0 bg-[#0ea5e9] w-1/2 animate-pulse border-r-2 border-ink-black`})})]}):e?(0,a.jsx)(`div`,{className:`w-full h-full bg-paper-white text-ink-black flex flex-col overflow-hidden text-xs md:text-sm`,children:(0,a.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-4 custom-scrollbar flex flex-col gap-4`,children:[(0,a.jsxs)(`div`,{className:`flex justify-between items-center bg-slate-100 border-[3px] border-ink-black p-3 shrink-0`,children:[(0,a.jsxs)(`div`,{className:`flex gap-2`,children:[(0,a.jsx)(`span`,{className:`bg-blue-100 text-blue-800 px-2 py-0.5 border-2 border-ink-black font-bold text-[9px] uppercase`,children:e.challenge_type}),(0,a.jsxs)(`span`,{className:`bg-yellow-100 text-yellow-800 px-2 py-0.5 border-2 border-ink-black font-bold text-[9px]`,children:[`+`,e.points,` PTS`]}),e.completed?(0,a.jsx)(`span`,{className:`bg-emerald-500 text-white px-2 py-0.5 border-2 border-ink-black font-bold text-[9px]`,children:`SOLVED`}):(0,a.jsx)(`span`,{className:`bg-rose-500 text-white px-2 py-0.5 border-2 border-ink-black font-bold text-[9px]`,children:`UNSOLVED`})]}),(0,a.jsxs)(`div`,{className:`font-arcade text-[8px] text-sky-700 font-bold bg-white border-2 border-ink-black px-2 py-0.5 shadow-[1px_1px_0_0_#1E293B]`,children:[`SCORE: `,e.total_score]})]}),(0,a.jsxs)(`div`,{className:`border-[3px] border-yellow-400 bg-yellow-50 p-3 rounded font-sans leading-relaxed text-xs`,children:[(0,a.jsx)(`h4`,{className:`font-arcade text-[9px] text-yellow-800 mb-1`,children:`PROBLEM`}),(0,a.jsx)(`p`,{className:`font-bold text-slate-800`,children:e.objective})]}),(0,a.jsxs)(`div`,{className:`border-[3px] border-ink-black bg-white p-3`,children:[(0,a.jsxs)(`div`,{className:`font-bold text-[10px] border-b border-slate-300 pb-1 mb-2 flex items-center gap-1.5`,children:[(0,a.jsx)(`span`,{className:`material-symbols-outlined text-sm`,children:`schema`}),(0,a.jsx)(`span`,{children:`SCHEMA EXPLORER (MOCK INSTANCE)`})]}),(0,a.jsx)(`div`,{className:`grid grid-cols-2 gap-3 max-h-[140px] overflow-y-auto custom-scrollbar font-mono text-[10px]`,children:Object.entries(e.schema).map(([e,t])=>(0,a.jsxs)(`div`,{className:`border border-slate-300 p-2 bg-slate-50`,children:[(0,a.jsxs)(`div`,{className:`font-bold text-blue-700 border-b border-slate-200 pb-0.5 mb-1 flex items-center gap-1`,children:[(0,a.jsx)(`span`,{className:`material-symbols-outlined text-[12px]`,children:`table_chart`}),e]}),(0,a.jsx)(`ul`,{className:`space-y-0.5 text-slate-600 text-[9px]`,children:t.map((e,t)=>(0,a.jsxs)(`li`,{className:`flex justify-between`,children:[(0,a.jsx)(`span`,{children:e.name}),(0,a.jsx)(`span`,{className:`text-slate-400 italic text-[8px]`,children:e.type})]},t))})]},e))})]}),(0,a.jsxs)(`div`,{className:`flex flex-col min-h-[120px]`,children:[(0,a.jsxs)(`div`,{className:`font-bold text-[10px] mb-1 tracking-wide uppercase flex items-center gap-1`,children:[(0,a.jsx)(`span`,{className:`material-symbols-outlined text-sm text-sky-600`,children:`terminal`}),(0,a.jsx)(`span`,{children:`Enter SQL Query:`})]}),(0,a.jsx)(`textarea`,{value:n,onChange:e=>o(e.target.value),className:`flex-1 w-full bg-slate-900 text-[#4ADE80] font-mono p-3 border-[3px] border-ink-black rounded outline-none focus:ring-2 focus:ring-sky-500 text-xs leading-relaxed resize-none`,placeholder:`SELECT * FROM customers WHERE score > 100;`,spellCheck:`false`})]}),(0,a.jsxs)(`div`,{className:`flex gap-3`,children:[(0,a.jsx)(`button`,{onClick:()=>g(!0),className:`flex-1 bg-white hover:bg-slate-100 text-ink-black border-[3px] border-ink-black font-bold font-window-title text-xs py-2 shadow-[3px_3px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none cursor-pointer`,children:`NEW PROBLEM`}),(0,a.jsx)(`button`,{disabled:s,onClick:async()=>{if(n.trim()){c(!0),f(``),m(null);try{let{data:{session:e}}=await r.auth.getSession();if(!e){f(`Unauthenticated session`);return}let i=await fetch(`/api/challenges/mysql/query`,{method:`POST`,headers:{"Content-Type":`application/json`,Authorization:`Bearer ${e.access_token}`},body:JSON.stringify({query:n})});if(i.ok){let e=await i.json();e.success?(m({columns:e.columns,rows:e.rows,rowsAffected:e.rows_affected,isCorrect:e.is_correct}),e.is_correct&&t(t=>t?{...t,completed:!0,total_score:e.total_score}:null),e.schema&&t(t=>t?{...t,schema:e.schema}:null)):f(e.error)}else f(`Database server query failure.`)}catch{f(`Query connection lost.`)}finally{c(!1)}}},className:`flex-[2] bg-highlight-pink text-white font-window-title font-bold py-2 border-[3px] border-ink-black shadow-[3px_3px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none hover:bg-pink-400 transition-all disabled:opacity-50 cursor-pointer text-center text-xs`,children:s?`EXECUTING SQL...`:`EXECUTE SQL QUERY`})]}),d&&(0,a.jsxs)(`div`,{className:`border-[3px] border-red-500 bg-red-50 text-red-800 p-3 font-mono text-xs whitespace-pre-wrap`,children:[(0,a.jsx)(`div`,{className:`font-bold mb-1`,children:`SQL RUNTIME / SYNTAX ERROR:`}),d]}),p&&(0,a.jsxs)(`div`,{className:`border-[3px] border-ink-black bg-white p-3 flex flex-col`,children:[(0,a.jsxs)(`div`,{className:`font-bold text-[10px] border-b border-slate-300 pb-1 mb-2 flex justify-between items-center`,children:[(0,a.jsx)(`span`,{children:`QUERY OUTPUT BUFFER`}),p.isCorrect&&(0,a.jsx)(`span`,{className:`text-green-600 font-bold animate-bounce text-[9px]`,children:`✓ ACCEPTED!`})]}),(0,a.jsxs)(`div`,{className:`text-[9px] text-slate-500 mb-2 font-mono`,children:[`Rows Affected: `,p.rowsAffected,` | Total Returned: `,p.rows.length]}),p.rows.length>0?(0,a.jsx)(`div`,{className:`overflow-x-auto border border-slate-300 max-h-[180px] custom-scrollbar`,children:(0,a.jsxs)(`table`,{className:`border-collapse w-full font-mono text-[9px] min-w-full`,children:[(0,a.jsx)(`thead`,{children:(0,a.jsx)(`tr`,{className:`bg-slate-100 border-b border-slate-300`,children:p.columns.map((e,t)=>(0,a.jsx)(`th`,{className:`border-r border-slate-300 p-1.5 text-left font-bold text-slate-700`,children:e},t))})}),(0,a.jsx)(`tbody`,{className:`divide-y divide-slate-200`,children:p.rows.map((e,t)=>(0,a.jsx)(`tr`,{className:`hover:bg-slate-50`,children:p.columns.map((t,n)=>(0,a.jsx)(`td`,{className:`border-r border-slate-200 p-1.5 text-slate-800 whitespace-nowrap`,children:e[t]===null?(0,a.jsx)(`span`,{className:`text-slate-300 italic`,children:`NULL`}):String(e[t])},n))},t))})]})}):(0,a.jsx)(`div`,{className:`p-3 border border-dashed border-slate-300 text-center text-slate-400 italic font-sans text-xs`,children:`Query executed successfully. Result set is empty (or modification completed).`})]})]})}):(0,a.jsxs)(`div`,{className:`w-full h-full bg-paper-white p-6 flex flex-col justify-between items-center text-center text-ink-black text-xs md:text-sm font-sans select-none`,children:[(0,a.jsxs)(`div`,{className:`flex-1 flex flex-col justify-center items-center gap-4`,children:[(0,a.jsx)(`div`,{className:`w-16 h-16 bg-white border-[3px] border-ink-black flex items-center justify-center shadow-[4px_4px_0_0_#1E293B]`,children:(0,a.jsx)(`span`,{className:`material-symbols-outlined text-4xl text-[#0ea5e9]`,style:{fontVariationSettings:`'FILL' 1`},children:`database`})}),(0,a.jsx)(`h3`,{className:`font-headline-md font-bold text-lg`,children:`Interactive MySQL Playground`}),(0,a.jsx)(`p`,{className:`max-w-md text-slate-600 leading-relaxed font-semibold`,children:`Practice SQL queries against realistic schema tables. Includes full support for:`}),(0,a.jsxs)(`div`,{className:`flex flex-wrap justify-center gap-2 font-mono text-[10px] text-slate-700 font-bold uppercase mt-1`,children:[(0,a.jsx)(`span`,{className:`bg-blue-100 border border-blue-400 px-2 py-0.5`,children:`SELECT / JOIN`}),(0,a.jsx)(`span`,{className:`bg-emerald-100 border border-emerald-400 px-2 py-0.5`,children:`UPDATE / DELETE`}),(0,a.jsx)(`span`,{className:`bg-purple-100 border border-purple-400 px-2 py-0.5`,children:`WINDOW FUNCTIONS`})]})]}),(0,a.jsx)(`div`,{className:`w-full border-t border-slate-200 pt-4 flex flex-col gap-2 shrink-0`,children:(0,a.jsx)(`button`,{onClick:()=>g(!1),className:`w-full py-2.5 bg-[#0ea5e9] hover:bg-sky-400 text-white font-window-title font-bold text-xs uppercase border-[3px] border-ink-black shadow-[4px_4px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none transition-all cursor-pointer text-center`,children:`CREATE NEW DATABASE`})})]})}export{o as default};
|
|
|
|
| 1 |
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Lt as t,zt as n}from"./vendor-react-qmUj3JUi.js";import{r}from"./firebaseClient-G7klkuBb.js";var i=e(n(),1),a=t();function o(){let[e,t]=(0,i.useState)(null),[n,o]=(0,i.useState)(``),[s,c]=(0,i.useState)(!1),[l,u]=(0,i.useState)(!0),[d,f]=(0,i.useState)(``),[p,m]=(0,i.useState)(null),h=async()=>{u(!0),f(``);try{let{data:{session:e}}=await r.auth.getSession();if(!e){f(`Unauthenticated session`);return}let n=await fetch(`/api/challenges/mysql/status`,{headers:{Authorization:`Bearer ${e.access_token}`}});if(n.ok){let e=await n.json();e.active?t(e):t(null)}else f(`Failed to fetch playground status.`)}catch{f(`Connection timed out.`)}finally{u(!1)}},g=async(e=!1)=>{u(!0),f(``),m(null);try{let{data:{session:n}}=await r.auth.getSession();if(!n){f(`Unauthenticated session`);return}let i=await fetch(`/api/challenges/mysql/init${e?`?refresh=true`:``}`,{method:`POST`,headers:{Authorization:`Bearer ${n.access_token}`}});if(i.ok){let e=await i.json();t({active:!0,title:e.title,objective:e.objective,points:e.points,schema:e.schema,challenge_type:e.challenge_type,completed:!1,total_score:e.total_score})}else f(`Failed to initialize mock database playground.`)}catch{f(`Server connection error.`)}finally{u(!1)}};return(0,i.useEffect)(()=>{h()},[]),l?(0,a.jsxs)(`div`,{className:`w-full h-full bg-paper-white p-6 flex flex-col items-center justify-center font-arcade text-[10px]`,children:[(0,a.jsx)(`div`,{className:`animate-bounce mb-2`,children:`INITIALIZING SQL PLAYGROUND...`}),(0,a.jsx)(`div`,{className:`w-48 h-4 bg-white border-[3px] border-ink-black overflow-hidden relative`,children:(0,a.jsx)(`div`,{className:`absolute inset-y-0 left-0 bg-[#0ea5e9] w-1/2 animate-pulse border-r-2 border-ink-black`})})]}):e?(0,a.jsx)(`div`,{className:`w-full h-full bg-paper-white text-ink-black flex flex-col overflow-hidden text-xs md:text-sm`,children:(0,a.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-4 custom-scrollbar flex flex-col gap-4`,children:[(0,a.jsxs)(`div`,{className:`flex justify-between items-center bg-slate-100 border-[3px] border-ink-black p-3 shrink-0`,children:[(0,a.jsxs)(`div`,{className:`flex gap-2`,children:[(0,a.jsx)(`span`,{className:`bg-blue-100 text-blue-800 px-2 py-0.5 border-2 border-ink-black font-bold text-[9px] uppercase`,children:e.challenge_type}),(0,a.jsxs)(`span`,{className:`bg-yellow-100 text-yellow-800 px-2 py-0.5 border-2 border-ink-black font-bold text-[9px]`,children:[`+`,e.points,` PTS`]}),e.completed?(0,a.jsx)(`span`,{className:`bg-emerald-500 text-white px-2 py-0.5 border-2 border-ink-black font-bold text-[9px]`,children:`SOLVED`}):(0,a.jsx)(`span`,{className:`bg-rose-500 text-white px-2 py-0.5 border-2 border-ink-black font-bold text-[9px]`,children:`UNSOLVED`})]}),(0,a.jsxs)(`div`,{className:`font-arcade text-[8px] text-sky-700 font-bold bg-white border-2 border-ink-black px-2 py-0.5 shadow-[1px_1px_0_0_#1E293B]`,children:[`SCORE: `,e.total_score]})]}),(0,a.jsxs)(`div`,{className:`border-[3px] border-yellow-400 bg-yellow-50 p-3 rounded font-sans leading-relaxed text-xs`,children:[(0,a.jsx)(`h4`,{className:`font-arcade text-[9px] text-yellow-800 mb-1`,children:`PROBLEM`}),(0,a.jsx)(`p`,{className:`font-bold text-slate-800`,children:e.objective})]}),(0,a.jsxs)(`div`,{className:`border-[3px] border-ink-black bg-white p-3`,children:[(0,a.jsxs)(`div`,{className:`font-bold text-[10px] border-b border-slate-300 pb-1 mb-2 flex items-center gap-1.5`,children:[(0,a.jsx)(`span`,{className:`material-symbols-outlined text-sm`,children:`schema`}),(0,a.jsx)(`span`,{children:`SCHEMA EXPLORER (MOCK INSTANCE)`})]}),(0,a.jsx)(`div`,{className:`grid grid-cols-2 gap-3 max-h-[140px] overflow-y-auto custom-scrollbar font-mono text-[10px]`,children:Object.entries(e.schema).map(([e,t])=>(0,a.jsxs)(`div`,{className:`border border-slate-300 p-2 bg-slate-50`,children:[(0,a.jsxs)(`div`,{className:`font-bold text-blue-700 border-b border-slate-200 pb-0.5 mb-1 flex items-center gap-1`,children:[(0,a.jsx)(`span`,{className:`material-symbols-outlined text-[12px]`,children:`table_chart`}),e]}),(0,a.jsx)(`ul`,{className:`space-y-0.5 text-slate-600 text-[9px]`,children:t.map((e,t)=>(0,a.jsxs)(`li`,{className:`flex justify-between`,children:[(0,a.jsx)(`span`,{children:e.name}),(0,a.jsx)(`span`,{className:`text-slate-400 italic text-[8px]`,children:e.type})]},t))})]},e))})]}),(0,a.jsxs)(`div`,{className:`flex flex-col min-h-[120px]`,children:[(0,a.jsxs)(`div`,{className:`font-bold text-[10px] mb-1 tracking-wide uppercase flex items-center gap-1`,children:[(0,a.jsx)(`span`,{className:`material-symbols-outlined text-sm text-sky-600`,children:`terminal`}),(0,a.jsx)(`span`,{children:`Enter SQL Query:`})]}),(0,a.jsx)(`textarea`,{value:n,onChange:e=>o(e.target.value),className:`flex-1 w-full bg-slate-900 text-[#4ADE80] font-mono p-3 border-[3px] border-ink-black rounded outline-none focus:ring-2 focus:ring-sky-500 text-xs leading-relaxed resize-none`,placeholder:`SELECT * FROM customers WHERE score > 100;`,spellCheck:`false`})]}),(0,a.jsxs)(`div`,{className:`flex gap-3`,children:[(0,a.jsx)(`button`,{onClick:()=>g(!0),className:`flex-1 bg-white hover:bg-slate-100 text-ink-black border-[3px] border-ink-black font-bold font-window-title text-xs py-2 shadow-[3px_3px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none cursor-pointer`,children:`NEW PROBLEM`}),(0,a.jsx)(`button`,{disabled:s,onClick:async()=>{if(n.trim()){c(!0),f(``),m(null);try{let{data:{session:e}}=await r.auth.getSession();if(!e){f(`Unauthenticated session`);return}let i=await fetch(`/api/challenges/mysql/query`,{method:`POST`,headers:{"Content-Type":`application/json`,Authorization:`Bearer ${e.access_token}`},body:JSON.stringify({query:n})});if(i.ok){let e=await i.json();e.success?(m({columns:e.columns,rows:e.rows,rowsAffected:e.rows_affected,isCorrect:e.is_correct}),e.is_correct&&t(t=>t?{...t,completed:!0,total_score:e.total_score}:null),e.schema&&t(t=>t?{...t,schema:e.schema}:null)):f(e.error)}else f(`Database server query failure.`)}catch{f(`Query connection lost.`)}finally{c(!1)}}},className:`flex-[2] bg-highlight-pink text-white font-window-title font-bold py-2 border-[3px] border-ink-black shadow-[3px_3px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none hover:bg-pink-400 transition-all disabled:opacity-50 cursor-pointer text-center text-xs`,children:s?`EXECUTING SQL...`:`EXECUTE SQL QUERY`})]}),d&&(0,a.jsxs)(`div`,{className:`border-[3px] border-red-500 bg-red-50 text-red-800 p-3 font-mono text-xs whitespace-pre-wrap`,children:[(0,a.jsx)(`div`,{className:`font-bold mb-1`,children:`SQL RUNTIME / SYNTAX ERROR:`}),d]}),p&&(0,a.jsxs)(`div`,{className:`border-[3px] border-ink-black bg-white p-3 flex flex-col`,children:[(0,a.jsxs)(`div`,{className:`font-bold text-[10px] border-b border-slate-300 pb-1 mb-2 flex justify-between items-center`,children:[(0,a.jsx)(`span`,{children:`QUERY OUTPUT BUFFER`}),p.isCorrect&&(0,a.jsx)(`span`,{className:`text-green-600 font-bold animate-bounce text-[9px]`,children:`✓ ACCEPTED!`})]}),(0,a.jsxs)(`div`,{className:`text-[9px] text-slate-500 mb-2 font-mono`,children:[`Rows Affected: `,p.rowsAffected,` | Total Returned: `,p.rows.length]}),p.rows.length>0?(0,a.jsx)(`div`,{className:`overflow-x-auto border border-slate-300 max-h-[180px] custom-scrollbar`,children:(0,a.jsxs)(`table`,{className:`border-collapse w-full font-mono text-[9px] min-w-full`,children:[(0,a.jsx)(`thead`,{children:(0,a.jsx)(`tr`,{className:`bg-slate-100 border-b border-slate-300`,children:p.columns.map((e,t)=>(0,a.jsx)(`th`,{className:`border-r border-slate-300 p-1.5 text-left font-bold text-slate-700`,children:e},t))})}),(0,a.jsx)(`tbody`,{className:`divide-y divide-slate-200`,children:p.rows.map((e,t)=>(0,a.jsx)(`tr`,{className:`hover:bg-slate-50`,children:p.columns.map((t,n)=>(0,a.jsx)(`td`,{className:`border-r border-slate-200 p-1.5 text-slate-800 whitespace-nowrap`,children:e[t]===null?(0,a.jsx)(`span`,{className:`text-slate-300 italic`,children:`NULL`}):String(e[t])},n))},t))})]})}):(0,a.jsx)(`div`,{className:`p-3 border border-dashed border-slate-300 text-center text-slate-400 italic font-sans text-xs`,children:`Query executed successfully. Result set is empty (or modification completed).`})]})]})}):(0,a.jsxs)(`div`,{className:`w-full h-full bg-paper-white p-6 flex flex-col justify-between items-center text-center text-ink-black text-xs md:text-sm font-sans select-none`,children:[(0,a.jsxs)(`div`,{className:`flex-1 flex flex-col justify-center items-center gap-4`,children:[(0,a.jsx)(`div`,{className:`w-16 h-16 bg-white border-[3px] border-ink-black flex items-center justify-center shadow-[4px_4px_0_0_#1E293B]`,children:(0,a.jsx)(`span`,{className:`material-symbols-outlined text-4xl text-[#0ea5e9]`,style:{fontVariationSettings:`'FILL' 1`},children:`database`})}),(0,a.jsx)(`h3`,{className:`font-headline-md font-bold text-lg`,children:`Interactive MySQL Playground`}),(0,a.jsx)(`p`,{className:`max-w-md text-slate-600 leading-relaxed font-semibold`,children:`Practice SQL queries against realistic schema tables. Includes full support for:`}),(0,a.jsxs)(`div`,{className:`flex flex-wrap justify-center gap-2 font-mono text-[10px] text-slate-700 font-bold uppercase mt-1`,children:[(0,a.jsx)(`span`,{className:`bg-blue-100 border border-blue-400 px-2 py-0.5`,children:`SELECT / JOIN`}),(0,a.jsx)(`span`,{className:`bg-emerald-100 border border-emerald-400 px-2 py-0.5`,children:`UPDATE / DELETE`}),(0,a.jsx)(`span`,{className:`bg-purple-100 border border-purple-400 px-2 py-0.5`,children:`WINDOW FUNCTIONS`})]})]}),(0,a.jsx)(`div`,{className:`w-full border-t border-slate-200 pt-4 flex flex-col gap-2 shrink-0`,children:(0,a.jsx)(`button`,{onClick:()=>g(!1),className:`w-full py-2.5 bg-[#0ea5e9] hover:bg-sky-400 text-white font-window-title font-bold text-xs uppercase border-[3px] border-ink-black shadow-[4px_4px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none transition-all cursor-pointer text-center`,children:`CREATE NEW DATABASE`})})]})}export{o as default};
|
algospaced-ui/dist/assets/{OnboardingModal-CySUf-WA.js → OnboardingModal-hhKaj0In.js}
RENAMED
|
@@ -1 +1 @@
|
|
| 1 |
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Et as t,Lt as n,St as r,_ as i,ft as a,ht as o,it as s,j as c,o as l,s as u,v as d,vt as f,w as p,y as m,yt as h,zt as g}from"./vendor-react-yvPwY2Sj.js";import{a as _,i as v,l as y,o as b}from"./index-DttZMwvA.js";var x=e(g(),1),S=n(),C=[217,242,1,49,20];function w({isOpen:e,onClose:n,onCompleted:g,userId:w}){let[T,E]=(0,x.useState)(`welcome`),[D,O]=(0,x.useState)(new Set),[k,A]=(0,x.useState)(``),[j,M]=(0,x.useState)(`ALL`),[N,P]=(0,x.useState)({}),[F,I]=(0,x.useState)(!1),[L,R]=(0,x.useState)(null),[z,B]=(0,x.useState)(null),V=()=>`algospaced_onboarding_done_${w===`sandbox-user-id`?`sandbox`:w||`sandbox`}`;(0,x.useEffect)(()=>{if(e){let e=localStorage.getItem(V());E(e?`checklist`:`welcome`),B(null),R(null)}},[e,w]);let H=(0,x.useMemo)(()=>v(),[]),U=(0,x.useMemo)(()=>_(),[]),W=(0,x.useMemo)(()=>{let e=k.trim().toLowerCase();return H.filter(t=>j!==`ALL`&&t.pattern!==j?!1:!e||t.name.toLowerCase().includes(e)||t.problem_number.toString().includes(e)||t.pattern.toLowerCase().includes(e)||t.difficulty.toLowerCase().includes(e))},[H,k,j]),G=(0,x.useMemo)(()=>{let e=new Map;for(let t of W){let n=e.get(t.pattern)||[];n.push(t),e.set(t.pattern,n)}return e},[W]);if(!e)return null;let K=()=>{localStorage.setItem(V(),`true`)},q=async()=>{I(!0),B(null),R(`Enrolling 5 foundational starter problems...`);try{let e=C.map(e=>b(e)).filter(e=>e!==void 0);await y(e),K(),R(`All 5 starter problems enrolled into Box 1!`),setTimeout(()=>{g(),n()},700)}catch(e){console.error(`Failed to start from scratch:`,e),B(e instanceof Error?e.message:`Failed to enroll starter problems`),I(!1)}},J=e=>{O(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},Y=e=>{let t=H.filter(t=>t.pattern===e),n=t.every(e=>D.has(e.problem_number));O(e=>{let r=new Set(e);for(let e of t)n?r.delete(e.problem_number):r.add(e.problem_number);return r})},X=e=>{O(t=>{let n=new Set(t);for(let t of H)t.difficulty===e&&n.add(t.problem_number);return n})},Z=()=>{O(new Set(H.map(e=>e.problem_number)))},Q=()=>{O(new Set)},$=e=>{P(t=>({...t,[e]:!t[e]}))};return(0,S.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/75 backdrop-blur-sm p-3 sm:p-6 overflow-y-auto`,children:(0,S.jsxs)(`div`,{className:`w-full max-w-4xl max-h-[92vh] bg-paper-white border-[4px] border-ink-black gadget-shadow flex flex-col relative overflow-hidden text-ink-black`,children:[(0,S.jsxs)(`div`,{className:`h-10 bg-gradient-to-r from-amber-400 via-amber-300 to-grass-green border-b-[3px] border-ink-black px-4 flex items-center justify-between shrink-0`,children:[(0,S.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,S.jsx)(`span`,{className:`w-3 h-3 rounded-full bg-rose-500 border border-ink-black`}),(0,S.jsx)(`span`,{className:`w-3 h-3 rounded-full bg-amber-500 border border-ink-black`}),(0,S.jsx)(`span`,{className:`w-3 h-3 rounded-full bg-emerald-500 border border-ink-black`}),(0,S.jsxs)(`span`,{className:`font-arcade text-[11px] font-bold tracking-wider text-ink-black uppercase ml-2 flex items-center gap-1.5`,children:[(0,S.jsx)(s,{className:`w-4 h-4 text-amber-900`}),`GET STARTED`]})]}),(0,S.jsx)(`button`,{onClick:()=>{K(),n()},disabled:F,className:`p-1 hover:bg-black/10 rounded transition-colors text-ink-black cursor-pointer border-0`,title:`Dismiss for now`,children:(0,S.jsx)(u,{className:`w-4 h-4`})})]}),T===`welcome`&&(0,S.jsxs)(`div`,{className:`p-6 sm:p-10 space-y-8 overflow-y-auto custom-scrollbar text-center`,children:[(0,S.jsxs)(`div`,{className:`space-y-3`,children:[(0,S.jsxs)(`div`,{className:`inline-flex items-center gap-2 px-3 py-1 bg-amber-100 border-2 border-ink-black font-arcade text-[10px] font-bold text-amber-900 uppercase`,children:[(0,S.jsx)(m,{className:`w-3.5 h-3.5 text-amber-700`}),`WELCOME TO ALGOSPACED`]}),(0,S.jsx)(`h1`,{className:`font-headline-md text-2xl sm:text-4xl font-extrabold text-ink-black tracking-tight`,children:`How would you like to begin your journey?`}),(0,S.jsx)(`p`,{className:`font-sans text-xs sm:text-sm text-trash-gray max-w-xl mx-auto leading-relaxed font-semibold`,children:`AlgoSpaced uses a 5-box Leitner spaced repetition engine. Choose how to seed your active practice cards.`})]}),(0,S.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-6 max-w-2xl mx-auto text-left`,children:[(0,S.jsxs)(`div`,{className:`p-5 sm:p-6 bg-gradient-to-br from-emerald-50 to-emerald-100/60 border-[3px] border-ink-black gadget-shadow hover:translate-y-[-2px] transition-all flex flex-col justify-between space-y-4`,children:[(0,S.jsxs)(`div`,{className:`space-y-3`,children:[(0,S.jsx)(`div`,{className:`w-12 h-12 bg-grass-green border-2 border-ink-black rounded-xl flex items-center justify-center shadow-[2px_2px_0px_0px_rgba(30,41,59,1)]`,children:(0,S.jsx)(r,{className:`w-6 h-6 text-ink-black stroke-[2.5]`})}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`span`,{className:`font-arcade text-[8px] font-bold text-emerald-800 uppercase tracking-wide`,children:`RECOMMENDED FOR BEGINNERS`}),(0,S.jsx)(`h2`,{className:`font-headline-md text-lg sm:text-xl font-bold text-ink-black mt-0.5`,children:`🌱 Start From Scratch`})]}),(0,S.jsx)(`p`,{className:`font-sans text-xs text-trash-gray leading-relaxed font-semibold`,children:`Begin with the 5 foundational starter problems: Contains Duplicate, Valid Anagram, Two Sum, Group Anagrams, and Valid Parentheses.`})]}),(0,S.jsx)(`button`,{onClick:q,disabled:F,className:`w-full py-3 bg-grass-green hover:bg-emerald-400 text-ink-black font-arcade text-[10px] font-bold border-2 border-ink-black shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none transition-all cursor-pointer flex items-center justify-center gap-2 disabled:opacity-50`,children:F?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(c,{className:`w-4 h-4 animate-spin`}),(0,S.jsx)(`span`,{children:`INITIALIZING...`})]}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(h,{className:`w-4 h-4 stroke-[3]`}),(0,S.jsx)(`span`,{children:`START FRESH (5 PROBLEMS)`})]})})]}),(0,S.jsxs)(`div`,{className:`p-5 sm:p-6 bg-gradient-to-br from-amber-50 to-orange-100/60 border-[3px] border-ink-black gadget-shadow hover:translate-y-[-2px] transition-all flex flex-col justify-between space-y-4`,children:[(0,S.jsxs)(`div`,{className:`space-y-3`,children:[(0,S.jsx)(`div`,{className:`w-12 h-12 bg-amber-400 border-2 border-ink-black rounded-xl flex items-center justify-center shadow-[2px_2px_0px_0px_rgba(30,41,59,1)]`,children:(0,S.jsx)(l,{className:`w-6 h-6 text-ink-black stroke-[2.5]`})}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`span`,{className:`font-arcade text-[8px] font-bold text-amber-800 uppercase tracking-wide`,children:`IF YOU'VE ALREADY SOLVED SOME PROBLEMS ELSEWHERE`}),(0,S.jsx)(`h2`,{className:`font-headline-md text-lg sm:text-xl font-bold text-ink-black mt-0.5`,children:`⚡ Fast-Track Checklist`})]}),(0,S.jsx)(`p`,{className:`font-sans text-xs text-trash-gray leading-relaxed font-semibold`,children:`Already solved some problems? Check off problems you've already solved elsewhere to seed your review queue and update your progress.`})]}),(0,S.jsxs)(`button`,{onClick:()=>E(`checklist`),disabled:F,className:`w-full py-3 bg-amber-400 hover:bg-amber-300 text-ink-black font-arcade text-[10px] font-bold border-2 border-ink-black shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none transition-all cursor-pointer flex items-center justify-center gap-2`,children:[(0,S.jsx)(`span`,{children:`SELECT WHAT I KNOW (150 POOL)`}),(0,S.jsx)(t,{className:`w-4 h-4 rotate-180`})]})]})]}),L&&(0,S.jsx)(`p`,{className:`font-arcade text-[10px] text-emerald-700 font-bold animate-pulse`,children:L}),z&&(0,S.jsx)(`p`,{className:`font-arcade text-[10px] text-rose-600 font-bold`,children:z})]}),T===`checklist`&&(0,S.jsxs)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:[(0,S.jsxs)(`div`,{className:`p-3 sm:p-4 bg-amber-50/60 border-b-[2px] border-ink-black shrink-0 space-y-3`,children:[(0,S.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-3`,children:[(0,S.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,S.jsxs)(`button`,{onClick:()=>E(`welcome`),className:`px-2.5 py-1.5 bg-paper-white hover:bg-slate-100 border-2 border-ink-black font-arcade text-[9px] font-bold text-ink-black flex items-center gap-1 cursor-pointer transition-colors shadow-[1px_1px_0px_0px_rgba(30,41,59,1)]`,children:[(0,S.jsx)(t,{className:`w-3.5 h-3.5`}),`BACK`]}),(0,S.jsx)(`h2`,{className:`font-headline-md text-base sm:text-lg font-bold text-ink-black`,children:`Fast-Track Catalog Checklist`})]}),(0,S.jsxs)(`div`,{className:`flex items-center gap-2 bg-paper-white border-2 border-ink-black p-1.5 shadow-[2px_2px_0px_0px_rgba(30,41,59,1)]`,children:[(0,S.jsx)(`span`,{className:`font-arcade text-[8px] font-bold text-trash-gray px-1 uppercase`,children:`FSRS STATE:`}),(0,S.jsx)(`span`,{className:`px-2 py-1 font-arcade text-[9px] font-bold bg-amber-400 text-ink-black border border-ink-black`,children:`ALL START AS 'NEW'`})]})]}),(0,S.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-2 items-center justify-between`,children:[(0,S.jsxs)(`div`,{className:`relative w-full sm:w-72`,children:[(0,S.jsx)(p,{className:`w-3.5 h-3.5 text-trash-gray absolute left-3 top-1/2 -translate-y-1/2`}),(0,S.jsx)(`input`,{type:`text`,value:k,onChange:e=>A(e.target.value),placeholder:`Search by title, number, or pattern...`,"aria-label":`Search problems by title, number, or pattern`,className:`w-full pl-8 pr-3 py-1.5 bg-paper-white border-2 border-ink-black font-sans text-xs text-ink-black font-medium outline-none focus:bg-amber-50`}),k&&(0,S.jsx)(`button`,{onClick:()=>A(``),"aria-label":`Clear search`,className:`absolute right-2 top-1/2 -translate-y-1/2 text-trash-gray hover:text-ink-black p-0.5 cursor-pointer`,children:(0,S.jsx)(u,{className:`w-3 h-3`})})]}),(0,S.jsxs)(`div`,{className:`flex items-center gap-1.5 flex-wrap w-full sm:w-auto justify-end`,children:[(0,S.jsx)(`button`,{onClick:()=>X(`Easy`),className:`px-2 py-1 bg-emerald-100 hover:bg-emerald-200 border border-emerald-800 text-emerald-900 font-arcade text-[8px] font-bold cursor-pointer transition-colors`,children:`+ ALL EASY`}),(0,S.jsx)(`button`,{onClick:()=>X(`Medium`),className:`px-2 py-1 bg-amber-100 hover:bg-amber-200 border border-amber-800 text-amber-900 font-arcade text-[8px] font-bold cursor-pointer transition-colors`,children:`+ ALL MEDIUM`}),(0,S.jsx)(`button`,{onClick:Z,className:`px-2 py-1 bg-purple-100 hover:bg-purple-200 border border-purple-800 text-purple-900 font-arcade text-[8px] font-bold cursor-pointer transition-colors`,children:`SELECT ALL (150)`}),(0,S.jsx)(`button`,{onClick:Q,className:`px-2 py-1 bg-slate-100 hover:bg-slate-200 border border-slate-700 text-slate-800 font-arcade text-[8px] font-bold cursor-pointer transition-colors`,children:`CLEAR`})]})]}),(0,S.jsxs)(`div`,{className:`flex items-center gap-1.5 overflow-x-auto custom-scrollbar pb-1 text-[8px] font-arcade font-bold`,children:[(0,S.jsxs)(`button`,{onClick:()=>M(`ALL`),className:`px-2 py-0.5 border cursor-pointer shrink-0 transition-colors ${j===`ALL`?`bg-ink-black text-amber-300 border-ink-black`:`bg-paper-white text-trash-gray border-slate-300 hover:text-ink-black`}`,children:[`ALL PATTERNS (`,H.length,`)`]}),U.map(e=>{let t=H.filter(t=>t.pattern===e).length;return(0,S.jsxs)(`button`,{onClick:()=>M(e),className:`px-2 py-0.5 border cursor-pointer shrink-0 transition-colors ${j===e?`bg-ink-black text-amber-300 border-ink-black`:`bg-paper-white text-trash-gray border-slate-300 hover:text-ink-black`}`,children:[e.toUpperCase(),` (`,t,`)`]},e)})]})]}),(0,S.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-4 sm:p-6 custom-scrollbar space-y-4 bg-slate-50/50`,children:[Array.from(G.entries()).map(([e,t])=>{let n=t.filter(e=>D.has(e.problem_number)).length,r=n===t.length,a=N[e]!==!1;return(0,S.jsxs)(`div`,{className:`bg-paper-white border-2 border-ink-black gadget-shadow overflow-hidden`,children:[(0,S.jsxs)(`div`,{className:`px-3.5 py-2.5 bg-gradient-to-r from-amber-100 to-amber-50 border-b-2 border-ink-black flex items-center justify-between`,children:[(0,S.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,S.jsx)(`button`,{onClick:()=>$(e),className:`p-1 hover:bg-black/10 rounded cursor-pointer transition-colors text-ink-black`,children:a?(0,S.jsx)(o,{className:`w-3.5 h-3.5`}):(0,S.jsx)(f,{className:`w-3.5 h-3.5`})}),(0,S.jsx)(`span`,{className:`font-headline-md text-xs sm:text-sm font-bold text-ink-black`,children:e}),(0,S.jsxs)(`span`,{className:`font-arcade text-[8px] font-bold px-1.5 py-0.5 rounded bg-amber-900/10 text-amber-900 border border-amber-900/20`,children:[n,` / `,t.length,` selected`]})]}),(0,S.jsx)(`button`,{onClick:()=>Y(e),className:`px-2 py-1 font-arcade text-[8px] font-bold border border-ink-black bg-paper-white hover:bg-amber-200 transition-colors cursor-pointer flex items-center gap-1 shadow-[1px_1px_0px_0px_rgba(30,41,59,1)]`,children:r?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(d,{className:`w-3 h-3 text-emerald-600`}),(0,S.jsx)(`span`,{children:`DESELECT ALL`})]}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(i,{className:`w-3 h-3 text-slate-500`}),(0,S.jsx)(`span`,{children:`SELECT ALL`})]})})]}),a&&(0,S.jsx)(`div`,{className:`p-3 grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-2`,children:t.map(e=>{let t=D.has(e.problem_number);return(0,S.jsxs)(`div`,{onClick:()=>J(e.problem_number),className:`p-2.5 border-2 transition-all cursor-pointer select-none flex items-start gap-2.5 ${t?`bg-amber-50/80 border-amber-600 shadow-[2px_2px_0px_0px_#d97706]`:`bg-paper-white border-slate-300 hover:border-ink-black`}`,children:[(0,S.jsx)(`div`,{className:`mt-0.5 shrink-0`,children:t?(0,S.jsx)(d,{className:`w-4 h-4 text-emerald-600 stroke-[2.5]`}):(0,S.jsx)(i,{className:`w-4 h-4 text-slate-400 stroke-[2]`})}),(0,S.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,S.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,S.jsxs)(`span`,{className:`font-mono text-[9px] font-bold text-trash-gray`,children:[`#`,e.problem_number]}),(0,S.jsx)(`span`,{className:`px-1.5 py-0.2 rounded font-arcade text-[7px] font-bold uppercase text-white ${e.difficulty===`Easy`?`bg-emerald-600`:e.difficulty===`Medium`?`bg-amber-600`:`bg-rose-600`}`,children:e.difficulty})]}),(0,S.jsx)(`h3`,{className:`font-headline-md text-xs font-bold text-ink-black truncate mt-0.5`,children:e.name}),(0,S.jsxs)(`div`,{className:`text-[10px] font-code-mono text-slate-500 truncate mt-0.5`,children:[`T: `,e.time_complexity,` | S: `,e.space_complexity]})]})]},e.problem_number)})})]},e)}),G.size===0&&(0,S.jsxs)(`div`,{className:`p-8 text-center bg-paper-white border-2 border-dashed border-slate-300 text-trash-gray space-y-2`,children:[(0,S.jsx)(p,{className:`w-8 h-8 mx-auto text-slate-400`}),(0,S.jsx)(`p`,{className:`font-arcade text-xs font-bold`,children:`NO MATCHING PROBLEMS FOUND`}),(0,S.jsx)(`p`,{className:`text-xs font-sans`,children:`Try searching another keyword or clearing filters.`})]})]}),(0,S.jsxs)(`div`,{className:`p-3 sm:p-4 bg-paper-white border-t-[3px] border-ink-black shrink-0 flex flex-col sm:flex-row items-center justify-between gap-3 shadow-[0px_-4px_10px_rgba(0,0,0,0.05)]`,children:[(0,S.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,S.jsx)(`div`,{className:`w-7 h-7 rounded-lg bg-emerald-100 border border-emerald-800 flex items-center justify-center`,children:(0,S.jsx)(a,{className:`w-4 h-4 text-emerald-700`})}),(0,S.jsxs)(`div`,{children:[(0,S.jsxs)(`span`,{className:`font-arcade text-[10px] font-bold text-ink-black`,children:[D.size,` of `,H.length,` PROBLEMS SELECTED`]}),(0,S.jsx)(`div`,{className:`font-sans text-[11px] text-trash-gray font-semibold`,children:`Target: FSRS (New)`})]})]}),(0,S.jsxs)(`div`,{className:`flex items-center gap-2 w-full sm:w-auto justify-end`,children:[z&&(0,S.jsx)(`span`,{className:`font-arcade text-[9px] text-rose-600 font-bold mr-2 truncate`,children:z}),(0,S.jsx)(`button`,{onClick:async()=>{if(D.size!==0){I(!0),B(null),R(`Enrolling ${D.size} problems into FSRS...`);try{let e=H.filter(e=>D.has(e.problem_number));await y(e),K(),R(`Successfully enrolled ${e.length} problems!`),setTimeout(()=>{g(),n()},700)}catch(e){console.error(`Failed to batch activate:`,e),B(e instanceof Error?e.message:`Failed to enroll problems`),I(!1)}}},disabled:D.size===0||F,className:`w-full sm:w-auto px-6 py-2.5 bg-gradient-to-r from-amber-400 to-grass-green hover:from-amber-300 hover:to-emerald-400 text-ink-black font-arcade text-[10px] font-bold border-2 border-ink-black shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none transition-all cursor-pointer flex items-center justify-center gap-2 disabled:opacity-40 disabled:cursor-not-allowed`,children:F?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(c,{className:`w-3.5 h-3.5 animate-spin`}),(0,S.jsx)(`span`,{children:`ENROLLING...`})]}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(l,{className:`w-3.5 h-3.5 text-amber-900`}),(0,S.jsxs)(`span`,{children:[`ENROLL `,D.size,` PROBLEMS (FSRS)`]})]})})]})]})]})]})})}export{w as default};
|
|
|
|
| 1 |
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{A as t,C as n,Et as r,Lt as i,St as a,_ as o,ft as s,ht as c,it as l,o as u,s as d,v as f,vt as p,y as m,yt as h,zt as g}from"./vendor-react-qmUj3JUi.js";import{a as _,i as v,l as y,o as b}from"./index-DYMSjoUb.js";var x=e(g(),1),S=i(),C=[217,242,1,49,20];function w({isOpen:e,onClose:i,onCompleted:g,userId:w}){let[T,E]=(0,x.useState)(`welcome`),[D,O]=(0,x.useState)(new Set),[k,A]=(0,x.useState)(``),[j,M]=(0,x.useState)(`ALL`),[N,P]=(0,x.useState)({}),[F,I]=(0,x.useState)(!1),[L,R]=(0,x.useState)(null),[z,B]=(0,x.useState)(null),V=()=>`algospaced_onboarding_done_${w===`sandbox-user-id`?`sandbox`:w||`sandbox`}`;(0,x.useEffect)(()=>{if(e){let e=localStorage.getItem(V());E(e?`checklist`:`welcome`),B(null),R(null)}},[e,w]);let H=(0,x.useMemo)(()=>v(),[]),U=(0,x.useMemo)(()=>_(),[]),W=(0,x.useMemo)(()=>{let e=k.trim().toLowerCase();return H.filter(t=>j!==`ALL`&&t.pattern!==j?!1:!e||t.name.toLowerCase().includes(e)||t.problem_number.toString().includes(e)||t.pattern.toLowerCase().includes(e)||t.difficulty.toLowerCase().includes(e))},[H,k,j]),G=(0,x.useMemo)(()=>{let e=new Map;for(let t of W){let n=e.get(t.pattern)||[];n.push(t),e.set(t.pattern,n)}return e},[W]);if(!e)return null;let K=()=>{localStorage.setItem(V(),`true`)},q=async()=>{I(!0),B(null),R(`Enrolling 5 foundational starter problems...`);try{let e=C.map(e=>b(e)).filter(e=>e!==void 0);await y(e),K(),R(`All 5 starter problems enrolled into Box 1!`),setTimeout(()=>{g(),i()},700)}catch(e){console.error(`Failed to start from scratch:`,e),B(e instanceof Error?e.message:`Failed to enroll starter problems`),I(!1)}},J=e=>{O(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},Y=e=>{let t=H.filter(t=>t.pattern===e),n=t.every(e=>D.has(e.problem_number));O(e=>{let r=new Set(e);for(let e of t)n?r.delete(e.problem_number):r.add(e.problem_number);return r})},X=e=>{O(t=>{let n=new Set(t);for(let t of H)t.difficulty===e&&n.add(t.problem_number);return n})},Z=()=>{O(new Set(H.map(e=>e.problem_number)))},Q=()=>{O(new Set)},$=e=>{P(t=>({...t,[e]:!t[e]}))};return(0,S.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/75 backdrop-blur-sm p-3 sm:p-6 overflow-y-auto`,children:(0,S.jsxs)(`div`,{className:`w-full max-w-4xl max-h-[92vh] bg-paper-white border-[4px] border-ink-black gadget-shadow flex flex-col relative overflow-hidden text-ink-black`,children:[(0,S.jsxs)(`div`,{className:`h-10 bg-gradient-to-r from-amber-400 via-amber-300 to-grass-green border-b-[3px] border-ink-black px-4 flex items-center justify-between shrink-0`,children:[(0,S.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,S.jsx)(`span`,{className:`w-3 h-3 rounded-full bg-rose-500 border border-ink-black`}),(0,S.jsx)(`span`,{className:`w-3 h-3 rounded-full bg-amber-500 border border-ink-black`}),(0,S.jsx)(`span`,{className:`w-3 h-3 rounded-full bg-emerald-500 border border-ink-black`}),(0,S.jsxs)(`span`,{className:`font-arcade text-[11px] font-bold tracking-wider text-ink-black uppercase ml-2 flex items-center gap-1.5`,children:[(0,S.jsx)(l,{className:`w-4 h-4 text-amber-900`}),`GET STARTED`]})]}),(0,S.jsx)(`button`,{onClick:()=>{K(),i()},disabled:F,className:`p-1 hover:bg-black/10 rounded transition-colors text-ink-black cursor-pointer border-0`,title:`Dismiss for now`,children:(0,S.jsx)(d,{className:`w-4 h-4`})})]}),T===`welcome`&&(0,S.jsxs)(`div`,{className:`p-6 sm:p-10 space-y-8 overflow-y-auto custom-scrollbar text-center`,children:[(0,S.jsxs)(`div`,{className:`space-y-3`,children:[(0,S.jsxs)(`div`,{className:`inline-flex items-center gap-2 px-3 py-1 bg-amber-100 border-2 border-ink-black font-arcade text-[10px] font-bold text-amber-900 uppercase`,children:[(0,S.jsx)(m,{className:`w-3.5 h-3.5 text-amber-700`}),`WELCOME TO ALGOSPACED`]}),(0,S.jsx)(`h1`,{className:`font-headline-md text-2xl sm:text-4xl font-extrabold text-ink-black tracking-tight`,children:`How would you like to begin your journey?`}),(0,S.jsx)(`p`,{className:`font-sans text-xs sm:text-sm text-trash-gray max-w-xl mx-auto leading-relaxed font-semibold`,children:`AlgoSpaced uses a 5-box Leitner spaced repetition engine. Choose how to seed your active practice cards.`})]}),(0,S.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-6 max-w-2xl mx-auto text-left`,children:[(0,S.jsxs)(`div`,{className:`p-5 sm:p-6 bg-gradient-to-br from-emerald-50 to-emerald-100/60 border-[3px] border-ink-black gadget-shadow hover:translate-y-[-2px] transition-all flex flex-col justify-between space-y-4`,children:[(0,S.jsxs)(`div`,{className:`space-y-3`,children:[(0,S.jsx)(`div`,{className:`w-12 h-12 bg-grass-green border-2 border-ink-black rounded-xl flex items-center justify-center shadow-[2px_2px_0px_0px_rgba(30,41,59,1)]`,children:(0,S.jsx)(a,{className:`w-6 h-6 text-ink-black stroke-[2.5]`})}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`span`,{className:`font-arcade text-[8px] font-bold text-emerald-800 uppercase tracking-wide`,children:`RECOMMENDED FOR BEGINNERS`}),(0,S.jsx)(`h2`,{className:`font-headline-md text-lg sm:text-xl font-bold text-ink-black mt-0.5`,children:`🌱 Start From Scratch`})]}),(0,S.jsx)(`p`,{className:`font-sans text-xs text-trash-gray leading-relaxed font-semibold`,children:`Begin with the 5 foundational starter problems: Contains Duplicate, Valid Anagram, Two Sum, Group Anagrams, and Valid Parentheses.`})]}),(0,S.jsx)(`button`,{onClick:q,disabled:F,className:`w-full py-3 bg-grass-green hover:bg-emerald-400 text-ink-black font-arcade text-[10px] font-bold border-2 border-ink-black shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none transition-all cursor-pointer flex items-center justify-center gap-2 disabled:opacity-50`,children:F?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(t,{className:`w-4 h-4 animate-spin`}),(0,S.jsx)(`span`,{children:`INITIALIZING...`})]}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(h,{className:`w-4 h-4 stroke-[3]`}),(0,S.jsx)(`span`,{children:`START FRESH (5 PROBLEMS)`})]})})]}),(0,S.jsxs)(`div`,{className:`p-5 sm:p-6 bg-gradient-to-br from-amber-50 to-orange-100/60 border-[3px] border-ink-black gadget-shadow hover:translate-y-[-2px] transition-all flex flex-col justify-between space-y-4`,children:[(0,S.jsxs)(`div`,{className:`space-y-3`,children:[(0,S.jsx)(`div`,{className:`w-12 h-12 bg-amber-400 border-2 border-ink-black rounded-xl flex items-center justify-center shadow-[2px_2px_0px_0px_rgba(30,41,59,1)]`,children:(0,S.jsx)(u,{className:`w-6 h-6 text-ink-black stroke-[2.5]`})}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`span`,{className:`font-arcade text-[8px] font-bold text-amber-800 uppercase tracking-wide`,children:`IF YOU'VE ALREADY SOLVED SOME PROBLEMS ELSEWHERE`}),(0,S.jsx)(`h2`,{className:`font-headline-md text-lg sm:text-xl font-bold text-ink-black mt-0.5`,children:`⚡ Fast-Track Checklist`})]}),(0,S.jsx)(`p`,{className:`font-sans text-xs text-trash-gray leading-relaxed font-semibold`,children:`Already solved some problems? Check off problems you've already solved elsewhere to seed your review queue and update your progress.`})]}),(0,S.jsxs)(`button`,{onClick:()=>E(`checklist`),disabled:F,className:`w-full py-3 bg-amber-400 hover:bg-amber-300 text-ink-black font-arcade text-[10px] font-bold border-2 border-ink-black shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none transition-all cursor-pointer flex items-center justify-center gap-2`,children:[(0,S.jsx)(`span`,{children:`SELECT WHAT I KNOW (150 POOL)`}),(0,S.jsx)(r,{className:`w-4 h-4 rotate-180`})]})]})]}),L&&(0,S.jsx)(`p`,{className:`font-arcade text-[10px] text-emerald-700 font-bold animate-pulse`,children:L}),z&&(0,S.jsx)(`p`,{className:`font-arcade text-[10px] text-rose-600 font-bold`,children:z})]}),T===`checklist`&&(0,S.jsxs)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:[(0,S.jsxs)(`div`,{className:`p-3 sm:p-4 bg-amber-50/60 border-b-[2px] border-ink-black shrink-0 space-y-3`,children:[(0,S.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-3`,children:[(0,S.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,S.jsxs)(`button`,{onClick:()=>E(`welcome`),className:`px-2.5 py-1.5 bg-paper-white hover:bg-slate-100 border-2 border-ink-black font-arcade text-[9px] font-bold text-ink-black flex items-center gap-1 cursor-pointer transition-colors shadow-[1px_1px_0px_0px_rgba(30,41,59,1)]`,children:[(0,S.jsx)(r,{className:`w-3.5 h-3.5`}),`BACK`]}),(0,S.jsx)(`h2`,{className:`font-headline-md text-base sm:text-lg font-bold text-ink-black`,children:`Fast-Track Catalog Checklist`})]}),(0,S.jsxs)(`div`,{className:`flex items-center gap-2 bg-paper-white border-2 border-ink-black p-1.5 shadow-[2px_2px_0px_0px_rgba(30,41,59,1)]`,children:[(0,S.jsx)(`span`,{className:`font-arcade text-[8px] font-bold text-trash-gray px-1 uppercase`,children:`FSRS STATE:`}),(0,S.jsx)(`span`,{className:`px-2 py-1 font-arcade text-[9px] font-bold bg-amber-400 text-ink-black border border-ink-black`,children:`ALL START AS 'NEW'`})]})]}),(0,S.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-2 items-center justify-between`,children:[(0,S.jsxs)(`div`,{className:`relative w-full sm:w-72`,children:[(0,S.jsx)(n,{className:`w-3.5 h-3.5 text-trash-gray absolute left-3 top-1/2 -translate-y-1/2`}),(0,S.jsx)(`input`,{type:`text`,value:k,onChange:e=>A(e.target.value),placeholder:`Search by title, number, or pattern...`,"aria-label":`Search problems by title, number, or pattern`,className:`w-full pl-8 pr-3 py-1.5 bg-paper-white border-2 border-ink-black font-sans text-xs text-ink-black font-medium outline-none focus:bg-amber-50`}),k&&(0,S.jsx)(`button`,{onClick:()=>A(``),"aria-label":`Clear search`,className:`absolute right-2 top-1/2 -translate-y-1/2 text-trash-gray hover:text-ink-black p-0.5 cursor-pointer`,children:(0,S.jsx)(d,{className:`w-3 h-3`})})]}),(0,S.jsxs)(`div`,{className:`flex items-center gap-1.5 flex-wrap w-full sm:w-auto justify-end`,children:[(0,S.jsx)(`button`,{onClick:()=>X(`Easy`),className:`px-2 py-1 bg-emerald-100 hover:bg-emerald-200 border border-emerald-800 text-emerald-900 font-arcade text-[8px] font-bold cursor-pointer transition-colors`,children:`+ ALL EASY`}),(0,S.jsx)(`button`,{onClick:()=>X(`Medium`),className:`px-2 py-1 bg-amber-100 hover:bg-amber-200 border border-amber-800 text-amber-900 font-arcade text-[8px] font-bold cursor-pointer transition-colors`,children:`+ ALL MEDIUM`}),(0,S.jsx)(`button`,{onClick:Z,className:`px-2 py-1 bg-purple-100 hover:bg-purple-200 border border-purple-800 text-purple-900 font-arcade text-[8px] font-bold cursor-pointer transition-colors`,children:`SELECT ALL (150)`}),(0,S.jsx)(`button`,{onClick:Q,className:`px-2 py-1 bg-slate-100 hover:bg-slate-200 border border-slate-700 text-slate-800 font-arcade text-[8px] font-bold cursor-pointer transition-colors`,children:`CLEAR`})]})]}),(0,S.jsxs)(`div`,{className:`flex items-center gap-1.5 overflow-x-auto custom-scrollbar pb-1 text-[8px] font-arcade font-bold`,children:[(0,S.jsxs)(`button`,{onClick:()=>M(`ALL`),className:`px-2 py-0.5 border cursor-pointer shrink-0 transition-colors ${j===`ALL`?`bg-ink-black text-amber-300 border-ink-black`:`bg-paper-white text-trash-gray border-slate-300 hover:text-ink-black`}`,children:[`ALL PATTERNS (`,H.length,`)`]}),U.map(e=>{let t=H.filter(t=>t.pattern===e).length;return(0,S.jsxs)(`button`,{onClick:()=>M(e),className:`px-2 py-0.5 border cursor-pointer shrink-0 transition-colors ${j===e?`bg-ink-black text-amber-300 border-ink-black`:`bg-paper-white text-trash-gray border-slate-300 hover:text-ink-black`}`,children:[e.toUpperCase(),` (`,t,`)`]},e)})]})]}),(0,S.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-4 sm:p-6 custom-scrollbar space-y-4 bg-slate-50/50`,children:[Array.from(G.entries()).map(([e,t])=>{let n=t.filter(e=>D.has(e.problem_number)).length,r=n===t.length,i=N[e]!==!1;return(0,S.jsxs)(`div`,{className:`bg-paper-white border-2 border-ink-black gadget-shadow overflow-hidden`,children:[(0,S.jsxs)(`div`,{className:`px-3.5 py-2.5 bg-gradient-to-r from-amber-100 to-amber-50 border-b-2 border-ink-black flex items-center justify-between`,children:[(0,S.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,S.jsx)(`button`,{onClick:()=>$(e),className:`p-1 hover:bg-black/10 rounded cursor-pointer transition-colors text-ink-black`,children:i?(0,S.jsx)(c,{className:`w-3.5 h-3.5`}):(0,S.jsx)(p,{className:`w-3.5 h-3.5`})}),(0,S.jsx)(`span`,{className:`font-headline-md text-xs sm:text-sm font-bold text-ink-black`,children:e}),(0,S.jsxs)(`span`,{className:`font-arcade text-[8px] font-bold px-1.5 py-0.5 rounded bg-amber-900/10 text-amber-900 border border-amber-900/20`,children:[n,` / `,t.length,` selected`]})]}),(0,S.jsx)(`button`,{onClick:()=>Y(e),className:`px-2 py-1 font-arcade text-[8px] font-bold border border-ink-black bg-paper-white hover:bg-amber-200 transition-colors cursor-pointer flex items-center gap-1 shadow-[1px_1px_0px_0px_rgba(30,41,59,1)]`,children:r?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(f,{className:`w-3 h-3 text-emerald-600`}),(0,S.jsx)(`span`,{children:`DESELECT ALL`})]}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(o,{className:`w-3 h-3 text-slate-500`}),(0,S.jsx)(`span`,{children:`SELECT ALL`})]})})]}),i&&(0,S.jsx)(`div`,{className:`p-3 grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-2`,children:t.map(e=>{let t=D.has(e.problem_number);return(0,S.jsxs)(`div`,{onClick:()=>J(e.problem_number),className:`p-2.5 border-2 transition-all cursor-pointer select-none flex items-start gap-2.5 ${t?`bg-amber-50/80 border-amber-600 shadow-[2px_2px_0px_0px_#d97706]`:`bg-paper-white border-slate-300 hover:border-ink-black`}`,children:[(0,S.jsx)(`div`,{className:`mt-0.5 shrink-0`,children:t?(0,S.jsx)(f,{className:`w-4 h-4 text-emerald-600 stroke-[2.5]`}):(0,S.jsx)(o,{className:`w-4 h-4 text-slate-400 stroke-[2]`})}),(0,S.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,S.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,S.jsxs)(`span`,{className:`font-mono text-[9px] font-bold text-trash-gray`,children:[`#`,e.problem_number]}),(0,S.jsx)(`span`,{className:`px-1.5 py-0.2 rounded font-arcade text-[7px] font-bold uppercase text-white ${e.difficulty===`Easy`?`bg-emerald-600`:e.difficulty===`Medium`?`bg-amber-600`:`bg-rose-600`}`,children:e.difficulty})]}),(0,S.jsx)(`h3`,{className:`font-headline-md text-xs font-bold text-ink-black truncate mt-0.5`,children:e.name}),(0,S.jsxs)(`div`,{className:`text-[10px] font-code-mono text-slate-500 truncate mt-0.5`,children:[`T: `,e.time_complexity,` | S: `,e.space_complexity]})]})]},e.problem_number)})})]},e)}),G.size===0&&(0,S.jsxs)(`div`,{className:`p-8 text-center bg-paper-white border-2 border-dashed border-slate-300 text-trash-gray space-y-2`,children:[(0,S.jsx)(n,{className:`w-8 h-8 mx-auto text-slate-400`}),(0,S.jsx)(`p`,{className:`font-arcade text-xs font-bold`,children:`NO MATCHING PROBLEMS FOUND`}),(0,S.jsx)(`p`,{className:`text-xs font-sans`,children:`Try searching another keyword or clearing filters.`})]})]}),(0,S.jsxs)(`div`,{className:`p-3 sm:p-4 bg-paper-white border-t-[3px] border-ink-black shrink-0 flex flex-col sm:flex-row items-center justify-between gap-3 shadow-[0px_-4px_10px_rgba(0,0,0,0.05)]`,children:[(0,S.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,S.jsx)(`div`,{className:`w-7 h-7 rounded-lg bg-emerald-100 border border-emerald-800 flex items-center justify-center`,children:(0,S.jsx)(s,{className:`w-4 h-4 text-emerald-700`})}),(0,S.jsxs)(`div`,{children:[(0,S.jsxs)(`span`,{className:`font-arcade text-[10px] font-bold text-ink-black`,children:[D.size,` of `,H.length,` PROBLEMS SELECTED`]}),(0,S.jsx)(`div`,{className:`font-sans text-[11px] text-trash-gray font-semibold`,children:`Target: FSRS (New)`})]})]}),(0,S.jsxs)(`div`,{className:`flex items-center gap-2 w-full sm:w-auto justify-end`,children:[z&&(0,S.jsx)(`span`,{className:`font-arcade text-[9px] text-rose-600 font-bold mr-2 truncate`,children:z}),(0,S.jsx)(`button`,{onClick:async()=>{if(D.size!==0){I(!0),B(null),R(`Enrolling ${D.size} problems into FSRS...`);try{let e=H.filter(e=>D.has(e.problem_number));await y(e),K(),R(`Successfully enrolled ${e.length} problems!`),setTimeout(()=>{g(),i()},700)}catch(e){console.error(`Failed to batch activate:`,e),B(e instanceof Error?e.message:`Failed to enroll problems`),I(!1)}}},disabled:D.size===0||F,className:`w-full sm:w-auto px-6 py-2.5 bg-gradient-to-r from-amber-400 to-grass-green hover:from-amber-300 hover:to-emerald-400 text-ink-black font-arcade text-[10px] font-bold border-2 border-ink-black shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none transition-all cursor-pointer flex items-center justify-center gap-2 disabled:opacity-40 disabled:cursor-not-allowed`,children:F?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(t,{className:`w-3.5 h-3.5 animate-spin`}),(0,S.jsx)(`span`,{children:`ENROLLING...`})]}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(u,{className:`w-3.5 h-3.5 text-amber-900`}),(0,S.jsxs)(`span`,{children:[`ENROLL `,D.size,` PROBLEMS (FSRS)`]})]})})]})]})]})]})})}export{w as default};
|
algospaced-ui/dist/assets/PrincessChamber-CyKVnuqB.js
DELETED
|
@@ -1 +0,0 @@
|
|
| 1 |
-
import{n as e,r as t}from"./rolldown-runtime-hePW80VL.js";import{A as n,C as r,E as i,Lt as a,S as o,St as s,U as c,bt as l,c as u,ct as d,ft as f,k as p,l as m,o as h,p as g,s as _,y as v,zt as y}from"./vendor-react-yvPwY2Sj.js";import{C as b,S as x,_ as S,b as C,g as w,v as T,x as E,y as D}from"./index-DttZMwvA.js";var O=t(y(),1),k={1:{particleType:`pollen`,particleCount:16,particleColors:[`#FDE047`,`#FEF08A`,`#86EFAC`],gradientBg:`from-[#FFFDF0] via-[#FFF9E6] to-[#FEF3C7]`,glowColor:`rgba(251, 191, 36, 0.3)`,badgeLabel:`🌾 Plains Breeze`},2:{particleType:`leaves`,particleCount:18,particleColors:[`#86EFAC`,`#4ADE80`,`#22C55E`,`#A7F3D0`],gradientBg:`from-[#F0FDF4] via-[#DCFCE7] to-[#FEF9C3]`,glowColor:`rgba(34, 197, 94, 0.3)`,badgeLabel:`🍃 Whispering Leaves`},3:{particleType:`spores`,particleCount:22,particleColors:[`#67E8F9`,`#38BDF8`,`#818CF8`,`#C084FC`],gradientBg:`from-[#F0F9FF] via-[#E0F2FE] to-[#EDE9FE]`,glowColor:`rgba(56, 189, 248, 0.35)`,badgeLabel:`✨ Crystal Spores`},4:{particleType:`snow`,particleCount:28,particleColors:[`#FFFFFF`,`#E0F2FE`,`#BAE6FD`],gradientBg:`from-[#F8FAFC] via-[#F1F5F9] to-[#E2E8F0]`,glowColor:`rgba(186, 230, 253, 0.4)`,badgeLabel:`❄️ Alpine Snowfall`},5:{particleType:`runes`,particleCount:20,particleColors:[`#E879F9`,`#C084FC`,`#A855F7`,`#F472B6`],gradientBg:`from-[#FAF5FF] via-[#F3E8FF] to-[#FCE7F3]`,glowColor:`rgba(192, 132, 252, 0.4)`,badgeLabel:`🔮 Arcane Runes`},6:{particleType:`stardust`,particleCount:35,particleColors:[`#FDE047`,`#F59E0B`,`#E11D48`,`#818CF8`],gradientBg:`from-[#FFFBEB] via-[#FEF3C7] to-[#FFE4E6]`,glowColor:`rgba(245, 158, 11, 0.5)`,badgeLabel:`👑 Spire Gates`}};function A(e){return e<=30?k[1]:e<=60?k[2]:e<=90?k[3]:e<=120?k[4]:e<150?k[5]:k[6]}var j=a();function M({emotion:e,floor:t,rhythm:n,activity:r,isLoading:i=!1}){let a=D[e]||D.smiling_warmly,o=(0,O.useMemo)(()=>A(t),[t]),s=(0,O.useMemo)(()=>{switch(n){case`dawn`:return`from-amber-400/40 via-yellow-300/30 to-rose-300/20`;case`dusk`:return`from-orange-400/40 via-purple-400/30 to-amber-300/20`;case`night`:return`from-indigo-600/40 via-blue-500/30 to-amber-500/20`;default:return`from-amber-400/30 via-yellow-300/40 to-indigo-400/30`}},[n]);return(0,j.jsxs)(`div`,{className:`relative flex flex-col items-center justify-center my-auto w-full max-w-xl`,children:[(0,j.jsx)(`div`,{className:`absolute -inset-10 overflow-hidden pointer-events-none z-0`,children:Array.from({length:Math.min(18,o.particleCount)}).map((e,t)=>{let n=o.particleColors[t%o.particleColors.length],r=`${t*19%100}%`,i=`${6+t%5*2}s`,a=`${t*.7%4}s`,s=o.particleType===`leaves`||o.particleType===`runes`?`w-2.5 h-2.5`:`w-1.5 h-1.5`;return(0,j.jsx)(`span`,{className:`absolute rounded-full opacity-65 animate-pulse ${s}`,style:{backgroundColor:n,left:r,top:`${t*23%90}%`,boxShadow:`0 0 8px ${n}`,animationDuration:i,animationDelay:a}},t)})}),(0,j.jsxs)(`div`,{className:`relative group z-10`,children:[(0,j.jsx)(`div`,{className:`absolute -inset-2 bg-gradient-to-r ${s} rounded-2xl blur-md opacity-80 group-hover:opacity-100 transition duration-500`}),(0,j.jsxs)(`div`,{className:`relative w-36 h-44 sm:w-44 sm:h-52 bg-gradient-to-b from-amber-100 to-amber-200 border-[3px] border-ink-black rounded-xl overflow-hidden shadow-[4px_4px_0px_0px_#1E293B] transition-transform duration-300 flex items-center justify-center`,children:[(0,j.jsxs)(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center text-amber-700/40 pointer-events-none select-none`,children:[(0,j.jsx)(v,{className:`w-8 h-8 animate-pulse`}),(0,j.jsx)(`span`,{className:`font-arcade text-[10px] mt-2`,children:`Princess Aurelia`})]}),(0,j.jsx)(`img`,{src:a.imagePath,alt:a.label,loading:`eager`,className:`w-full h-full object-cover object-top transition-all duration-300 relative z-10 ${i?`scale-105 filter saturate-125`:`scale-100`}`,onError:e=>{let t=e.currentTarget;t.src.endsWith(`/sprites/princess/neutral.webp`)?t.style.display=`none`:t.src=`/sprites/princess/neutral.webp`}}),(0,j.jsxs)(`div`,{className:`absolute bottom-0 inset-x-0 bg-ink-black/85 backdrop-blur-xs text-[10px] text-amber-300 py-1 px-2 font-bold uppercase tracking-wider text-center flex items-center justify-center gap-1.5`,children:[(0,j.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full ${i?`bg-amber-400 animate-ping`:`bg-emerald-400`}`}),(0,j.jsx)(`span`,{children:i?`Pondering...`:a.label})]})]}),(0,j.jsx)(`div`,{className:`absolute -top-2 -right-2 bg-[#FFE24C] border-[2px] border-ink-black rounded-full p-1 shadow-[2px_2px_0px_0px_#1E293B]`,children:(0,j.jsx)(v,{className:`w-3.5 h-3.5 text-amber-800`})})]}),r&&(0,j.jsx)(`div`,{className:`mt-2 text-center max-w-sm px-2`,children:(0,j.jsxs)(`span`,{className:`text-[10px] font-semibold text-slate-700 bg-white/85 px-2.5 py-0.5 rounded-full border border-ink-black/20 shadow-xs inline-flex items-center gap-1`,children:[(0,j.jsx)(`span`,{children:`🏰`}),(0,j.jsx)(`span`,{className:`truncate`,children:r})]})})]})}function N({text:e,characterName:t,emotion:n,isLoading:r=!1,isStreaming:i=!1,toolCalls:a,onTypingStatusChange:o}){let[s,c]=(0,O.useState)(e),[l,u]=(0,O.useState)(!1),d=(0,O.useRef)(null),f=(0,O.useRef)(e),p=(0,O.useRef)(0),m=(0,O.useRef)(o);(0,O.useEffect)(()=>{m.current=o},[o]);let h=D[n]||D.smiling_warmly,g=e=>{u(e),m.current?.(e)};return(0,O.useEffect)(()=>{if(i){d.current&&clearInterval(d.current),c(e),g(!0),e.length-p.current>=4&&(p.current=e.length,S(e.length)),f.current=e;return}if(e!==f.current&&!r){let t=f.current.length>0&&e.startsWith(f.current);if(f.current=e,d.current&&clearInterval(d.current),t)c(e),g(!1);else{c(``),g(!0);let t=0;d.current=setInterval(()=>{t<e.length?(t++,c(e.slice(0,t)),t%2==0&&e[t-1]!==` `&&S(t)):(d.current&&clearInterval(d.current),g(!1))},22)}}else!r&&e===f.current&&!i&&(c(e),l&&g(!1));return()=>{d.current&&clearInterval(d.current)}},[e,r,i]),(0,j.jsxs)(`div`,{onClick:()=>{l&&(d.current&&clearInterval(d.current),c(e),g(!1))},className:`w-full max-w-xl mt-3 sm:mt-4 relative bg-white border-[3px] border-ink-black rounded-xl p-3.5 sm:p-4 shadow-[4px_4px_0px_0px_#1E293B] transition-all cursor-pointer group select-text`,children:[(0,j.jsx)(`div`,{className:`absolute -top-3 left-1/2 -translate-x-1/2 w-0 h-0 border-x-8 border-x-transparent border-b-8 border-b-ink-black pointer-events-none`}),(0,j.jsx)(`div`,{className:`absolute -top-2 left-1/2 -translate-x-1/2 w-0 h-0 border-x-6 border-x-transparent border-b-6 border-b-white pointer-events-none`}),(0,j.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-b border-amber-100 pb-1.5 mb-2 select-none`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,j.jsxs)(`span`,{className:`font-headline-md font-bold text-xs text-amber-900 flex items-center gap-1`,children:[`👑 `,t||`Princess Aurelia`]}),(0,j.jsx)(`span`,{className:`text-[9px] bg-amber-100 text-amber-800 font-bold px-1.5 py-0.2 rounded border border-amber-200`,children:h.label})]}),l&&(0,j.jsx)(`span`,{className:`text-[9px] text-trash-gray font-medium animate-pulse`,children:`Click bubble to skip`})]}),r?(0,j.jsxs)(`div`,{className:`flex items-center gap-2 py-2 text-xs font-medium text-trash-gray select-none`,children:[(0,j.jsx)(`span`,{className:`inline-block w-2 h-2 bg-amber-500 rounded-full animate-bounce`}),(0,j.jsx)(`span`,{className:`inline-block w-2 h-2 bg-amber-500 rounded-full animate-bounce [animation-delay:0.2s]`}),(0,j.jsx)(`span`,{className:`inline-block w-2 h-2 bg-amber-500 rounded-full animate-bounce [animation-delay:0.4s]`}),(0,j.jsxs)(`span`,{className:`ml-1 text-slate-600`,children:[t||`Princess Aurelia`,` is attuning the crystal relay...`]})]}):(0,j.jsxs)(`div`,{className:`text-xs sm:text-[13px] text-ink-black font-medium leading-relaxed whitespace-pre-wrap`,children:[(e=>e.split(/(\*[^*]+\*)/g).map((e,t)=>e.startsWith(`*`)&&e.endsWith(`*`)?(0,j.jsx)(`span`,{className:`text-amber-700 italic font-semibold mr-1 inline-block`,children:e},t):(0,j.jsx)(`span`,{children:e},t)))(s),l&&(0,j.jsx)(`span`,{className:`inline-block w-1.5 h-3.5 bg-amber-500 ml-1 animate-pulse align-middle`})]}),a&&a.length>0&&!r&&(0,j.jsx)(`div`,{className:`mt-2.5 pt-2 border-t border-amber-100/80 flex flex-wrap gap-1.5 select-none`,children:a.map((e,t)=>{let n=`✨ Enchantment: ${e.name}`;return e.name===`open_app_window`&&(n=`📜 Summoned: ${e.args?.window_id||`Grimoire`}`),e.name===`set_study_timer`&&(n=`⏳ Hourglass: ${e.args?.minutes||15}m rest`),e.name===`play_ambient_sound`&&(n=`🔥 Kindled: ${e.args?.soundscape||`Soundscape`}`),e.name===`write_spire_diary`&&(n=`📖 Chronicled in Spire Diary`),(0,j.jsx)(`span`,{className:`px-2 py-0.5 rounded-full bg-indigo-50 border border-indigo-200 text-[10px] font-bold text-indigo-800 flex items-center gap-1 shadow-xs`,children:(0,j.jsx)(`span`,{children:n})},t)})})]})}var P=[{label:`💪 Solved a Tough One`,prompt:`I just solved a really tough problem! Felt so good getting all test cases to pass.`},{label:`😩 Feeling Stuck`,prompt:`I feel really stuck and discouraged today. It feels like everyone else gets this except me.`},{label:`☕ Need a Breather`,prompt:`My brain is pretty fried from practicing today. Can we just take a short breather?`},{label:`🌙 Life Beyond the Tower`,prompt:`What’s the first thing you want to do once we break the seals and get you out of that tower?`}];function F({suggestions:e,isLoading:t=!1,onSendMessage:n,placeholder:i=`Speak with Princess Aurelia...`}){let[a,o]=(0,O.useState)(``),s=()=>{let e=a.trim();e&&!t&&(n(e),o(``))},c=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),s())},l=Array.isArray(e)&&e.length>0;return(0,j.jsxs)(`div`,{className:`w-full flex flex-col items-center gap-2 select-none z-10`,children:[(0,j.jsx)(`div`,{className:`w-full max-w-xl flex items-center justify-center gap-1.5 flex-wrap py-1.5 px-2`,children:l?e.map((e,r)=>(0,j.jsxs)(`button`,{type:`button`,onClick:()=>n(e),disabled:t,className:`px-2.5 py-1 bg-white hover:bg-amber-100 disabled:opacity-50 border-[1.5px] border-ink-black rounded-full text-[10px] sm:text-[11px] font-bold text-slate-800 cursor-pointer shadow-[1px_1px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none transition-all flex items-center gap-1`,children:[(0,j.jsx)(v,{className:`w-3 h-3 text-amber-600 shrink-0`}),(0,j.jsx)(`span`,{className:`truncate max-w-[200px]`,children:e})]},r)):P.map((e,r)=>(0,j.jsx)(`button`,{type:`button`,onClick:()=>n(e.prompt),disabled:t,className:`px-2.5 py-1 bg-white hover:bg-amber-100 disabled:opacity-50 border-[1.5px] border-ink-black rounded-full text-[10px] sm:text-[11px] font-bold text-slate-800 cursor-pointer shadow-[1px_1px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none transition-all`,children:e.label},r))}),(0,j.jsxs)(`div`,{className:`w-full bg-white border-t-[3px] border-ink-black p-3 sm:px-4 flex items-center gap-2 shrink-0`,children:[(0,j.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value),onKeyDown:c,disabled:t,placeholder:i,className:`flex-1 bg-[#FFFDF0] border-[2px] border-ink-black rounded-lg px-3.5 py-2 text-xs sm:text-sm font-medium text-ink-black placeholder-slate-400 focus:outline-none focus:border-amber-500 shadow-inner disabled:opacity-50`}),(0,j.jsxs)(`button`,{type:`button`,onClick:s,disabled:t||!a.trim(),className:`px-4 sm:px-5 py-2 bg-[#FFE24C] hover:bg-yellow-300 disabled:opacity-50 border-[2px] border-ink-black rounded-lg font-bold text-xs sm:text-sm text-ink-black shadow-[2px_2px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none transition-all cursor-pointer flex items-center gap-1.5 shrink-0`,children:[(0,j.jsx)(r,{className:`w-3.5 h-3.5`}),(0,j.jsx)(`span`,{children:`Send`})]})]})]})}function I({currentFloor:e,onClose:t}){let n=b(e),r=Math.min(100,Math.round(e/150*100));return(0,j.jsx)(`div`,{className:`absolute inset-0 z-50 bg-ink-black/40 backdrop-blur-xs flex items-center justify-center p-3 sm:p-4 animate-in fade-in duration-200 select-none`,onClick:t,children:(0,j.jsxs)(`div`,{className:`bg-[#FFFDF0] border-[3px] border-ink-black rounded-xl p-4 sm:p-5 max-w-md w-full shadow-[6px_6px_0px_0px_#1E293B] flex flex-col gap-3.5`,onClick:e=>e.stopPropagation(),children:[(0,j.jsxs)(`div`,{className:`flex items-center justify-between border-b-[2px] border-ink-black pb-2`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,j.jsx)(l,{className:`w-5 h-5 text-indigo-600`}),(0,j.jsx)(`h4`,{className:`font-headline-md font-bold text-sm text-ink-black m-0`,children:`Journey to the Big-O Spire`})]}),(0,j.jsx)(`button`,{type:`button`,onClick:t,className:`p-1 hover:bg-slate-200 rounded text-slate-700 cursor-pointer`,title:`Close`,children:(0,j.jsx)(_,{className:`w-4 h-4`})})]}),(0,j.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,j.jsxs)(`div`,{className:`flex items-center justify-between text-xs font-bold font-headline-md`,children:[(0,j.jsx)(`span`,{children:`Path Progress:`}),(0,j.jsxs)(`span`,{className:`font-arcade bg-indigo-100 text-indigo-900 px-2 py-0.5 rounded border border-indigo-300`,children:[e,` / 150 Leagues`]})]}),(0,j.jsx)(`div`,{className:`w-full bg-slate-200 h-4 border-[2px] border-ink-black rounded-full overflow-hidden p-0.5`,children:(0,j.jsx)(`div`,{className:`bg-gradient-to-r from-amber-400 via-yellow-400 to-emerald-400 h-full rounded-full transition-all duration-500`,style:{width:`${r}%`}})}),(0,j.jsxs)(`div`,{className:`flex items-center justify-between text-[11px] text-trash-gray font-medium`,children:[(0,j.jsxs)(`span`,{children:[`Progress: `,(0,j.jsxs)(`strong`,{children:[r,`%`]})]}),(0,j.jsxs)(`span`,{children:[`Distance to Tower: `,(0,j.jsxs)(`strong`,{children:[Math.max(0,150-e),` leagues`]})]})]})]}),(0,j.jsxs)(`div`,{className:`bg-white border-[2px] border-ink-black rounded-lg p-3 shadow-[2px_2px_0px_0px_#1E293B] flex flex-col gap-1`,children:[(0,j.jsx)(`div`,{className:`text-[10px] font-bold uppercase text-amber-700 tracking-wider`,children:`Current Realm:`}),(0,j.jsx)(`div`,{className:`font-bold text-xs text-ink-black`,children:n.title}),(0,j.jsx)(`p`,{className:`text-[11px] text-slate-600 m-0 leading-relaxed font-medium`,children:n.description}),(0,j.jsxs)(`div`,{className:`text-[10px] text-amber-900 bg-amber-50 p-1.5 rounded border border-amber-200 italic mt-1`,children:[`📜 `,n.bgLore]})]}),(0,j.jsx)(`div`,{className:`flex items-center justify-between gap-1 text-center`,children:[{floor:30,label:`Arrays`},{floor:60,label:`Pointers`},{floor:90,label:`Trees`},{floor:120,label:`Heaps`},{floor:150,label:`Spire`}].map(t=>{let n=e>=t.floor;return(0,j.jsxs)(`div`,{className:`flex-1 p-1.5 rounded border text-[10px] flex flex-col items-center ${n?`bg-emerald-100 border-emerald-600 text-emerald-900 font-bold`:`bg-slate-100 border-slate-300 text-slate-500`}`,children:[(0,j.jsx)(`span`,{children:n?`✓`:t.floor}),(0,j.jsx)(`span`,{className:`text-[9px] truncate w-full`,children:t.label})]},t.floor)})}),(0,j.jsx)(`div`,{className:`flex items-center justify-end border-t border-slate-200 pt-2 mt-1`,children:(0,j.jsx)(`button`,{type:`button`,onClick:t,className:`px-4 py-1.5 bg-white hover:bg-slate-100 border-[1.5px] border-ink-black rounded font-bold text-xs text-ink-black cursor-pointer shadow-xs active:translate-y-0.5`,children:`Done`})})]})})}function L({unlockedLetters:e,spireChronicles:t,currentFloor:n,heroCodex:r,episodicEvents:a,recentToolTelemetry:l,onRemoveCodexItem:u,onClose:p}){let[m,y]=(0,O.useState)(`letters`),[b,S]=(0,O.useState)(e[e.length-1]||null);return(0,j.jsx)(`div`,{className:`absolute inset-0 z-50 bg-ink-black/50 backdrop-blur-xs flex items-center justify-center p-3 sm:p-4 animate-in fade-in duration-200 select-none`,onClick:p,children:(0,j.jsxs)(`div`,{className:`bg-[#FFFDF0] border-[3px] border-ink-black rounded-xl max-w-lg w-full h-[85%] max-h-[560px] shadow-[6px_6px_0px_0px_#1E293B] flex flex-col overflow-hidden`,onClick:e=>e.stopPropagation(),children:[(0,j.jsxs)(`div`,{className:`bg-white border-b-[2px] border-ink-black px-4 py-2.5 flex items-center justify-between shrink-0`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,j.jsx)(i,{className:`w-5 h-5 text-amber-700`}),(0,j.jsx)(`h4`,{className:`font-headline-md font-bold text-sm text-ink-black m-0`,children:`The Royal Satchel`})]}),(0,j.jsx)(`button`,{type:`button`,onClick:p,className:`p-1 hover:bg-slate-200 rounded text-slate-700 cursor-pointer`,title:`Close`,children:(0,j.jsx)(_,{className:`w-4 h-4`})})]}),(0,j.jsxs)(`div`,{className:`flex border-b-2 border-ink-black bg-amber-100/70 shrink-0`,children:[(0,j.jsxs)(`button`,{type:`button`,onClick:()=>y(`letters`),className:`flex-1 py-2 text-xs font-bold font-headline-md flex items-center justify-center gap-1.5 transition-colors cursor-pointer border-r border-ink-black/20 ${m===`letters`?`bg-[#FFFDF0] text-amber-950 border-b-2 border-b-[#FFFDF0] -mb-[2px]`:`text-slate-600 hover:bg-amber-200/50`}`,children:[(0,j.jsx)(i,{className:`w-3.5 h-3.5`}),(0,j.jsxs)(`span`,{children:[`Missives (`,e.length,`/5)`]})]}),(0,j.jsxs)(`button`,{type:`button`,onClick:()=>y(`diary`),className:`flex-1 py-2 text-xs font-bold font-headline-md flex items-center justify-center gap-1.5 transition-colors cursor-pointer border-r border-ink-black/20 ${m===`diary`?`bg-[#FFFDF0] text-amber-950 border-b-2 border-b-[#FFFDF0] -mb-[2px]`:`text-slate-600 hover:bg-amber-200/50`}`,children:[(0,j.jsx)(s,{className:`w-3.5 h-3.5`}),(0,j.jsxs)(`span`,{children:[`Chronicles (`,t.length,`)`]})]}),(0,j.jsxs)(`button`,{type:`button`,onClick:()=>y(`codex`),className:`flex-1 py-2 text-xs font-bold font-headline-md flex items-center justify-center gap-1.5 transition-colors cursor-pointer ${m===`codex`?`bg-[#FFFDF0] text-amber-950 border-b-2 border-b-[#FFFDF0] -mb-[2px]`:`text-slate-600 hover:bg-amber-200/50`}`,children:[(0,j.jsx)(v,{className:`w-3.5 h-3.5 text-amber-700`}),(0,j.jsx)(`span`,{children:`Codex`})]})]}),(0,j.jsxs)(`div`,{className:`flex-1 p-3 sm:p-4 overflow-y-auto custom-scrollbar flex flex-col gap-3 min-h-0`,children:[m===`letters`&&(0,j.jsxs)(`div`,{className:`flex flex-col gap-3 flex-1`,children:[(0,j.jsx)(`div`,{className:`flex items-center gap-1.5 overflow-x-auto pb-1`,children:[30,60,90,120,150].map(e=>{let t=x[e],r=n>=e,i=b?.floor===e;return(0,j.jsxs)(`button`,{type:`button`,disabled:!r,onClick:()=>r&&S(t),className:`px-3 py-1 rounded-full text-[11px] font-bold border-[1.5px] border-ink-black flex items-center gap-1 shrink-0 transition-all cursor-pointer ${r?i?`bg-[#FFE24C] text-ink-black shadow-[1.5px_1.5px_0px_0px_#1E293B]`:`bg-white hover:bg-amber-100 text-slate-800`:`opacity-40 bg-slate-200 text-slate-500 cursor-not-allowed`}`,children:[r?(0,j.jsx)(`span`,{children:`📜`}):(0,j.jsx)(c,{className:`w-3 h-3`}),(0,j.jsxs)(`span`,{children:[`League `,e]})]},e)})}),b?(0,j.jsxs)(`div`,{className:`bg-[#FFF9E6] border-[2px] border-amber-900/40 rounded-lg p-4 shadow-sm flex-1 overflow-y-auto custom-scrollbar flex flex-col select-text`,children:[(0,j.jsxs)(`div`,{className:`border-b border-amber-800/20 pb-2 mb-3 flex items-center justify-between`,children:[(0,j.jsxs)(`div`,{children:[(0,j.jsxs)(`div`,{className:`text-[10px] font-bold text-amber-800 uppercase tracking-wider`,children:[b.chapterTitle,` • League `,b.floor]}),(0,j.jsx)(`h5`,{className:`font-headline-md font-bold text-sm text-amber-950 m-0`,children:b.title})]}),(0,j.jsx)(`span`,{className:`text-xl`,children:`🪶`})]}),(0,j.jsx)(`p`,{className:`text-xs sm:text-[13px] text-amber-950 font-serif leading-relaxed whitespace-pre-wrap flex-1 italic`,children:b.letterText})]}):(0,j.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center text-center p-6 text-slate-500`,children:[(0,j.jsx)(c,{className:`w-8 h-8 mb-2 text-slate-400`}),(0,j.jsx)(`p`,{className:`text-xs font-medium`,children:`Conquer 30 LeetCode problems along the path to receive your first Royal Missive from Aurelia.`})]})]}),m===`diary`&&(0,j.jsx)(`div`,{className:`flex flex-col gap-2.5 flex-1`,children:t.length>0?t.map(e=>(0,j.jsxs)(`div`,{className:`p-3 bg-white border-[1.5px] border-ink-black rounded-lg shadow-xs flex flex-col gap-1 select-text`,children:[(0,j.jsxs)(`div`,{className:`flex items-center justify-between text-[10px] text-amber-800 font-bold border-b border-slate-100 pb-1`,children:[(0,j.jsxs)(`span`,{children:[`League `,e.floor,` along the Path`]}),(0,j.jsx)(`span`,{children:new Date(e.timestamp).toLocaleDateString()})]}),(0,j.jsxs)(`p`,{className:`text-xs text-ink-black font-medium leading-relaxed m-0 italic font-serif`,children:[`“`,e.text,`”`]})]},e.id)):(0,j.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center text-center p-6 text-slate-500`,children:[(0,j.jsx)(s,{className:`w-8 h-8 mb-2 text-slate-400`}),(0,j.jsx)(`p`,{className:`text-xs font-medium`,children:`Aurelia records entries in her Spire Chronicles autonomously as you chat, rest, and cross chapter milestones.`})]})}),m===`codex`&&(0,j.jsxs)(`div`,{className:`flex flex-col gap-3 flex-1 select-text`,children:[(0,j.jsxs)(`div`,{className:`bg-white border-[1.5px] border-ink-black rounded-lg p-3 shadow-xs flex flex-col gap-2`,children:[(0,j.jsxs)(`div`,{className:`flex items-center justify-between border-b border-slate-100 pb-1.5`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,j.jsx)(v,{className:`w-4 h-4 text-amber-600`}),(0,j.jsx)(`h5`,{className:`font-headline-md font-bold text-xs text-ink-black m-0`,children:`Hero Codex (MemGPT & Mem0 Core Memory)`})]}),(0,j.jsx)(`span`,{className:`text-[10px] text-slate-400 font-mono`,children:`Cognitive Sync`})]}),(0,j.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2 text-xs`,children:[(0,j.jsxs)(`div`,{className:`bg-[#FFFDF0] border border-amber-900/20 rounded p-2`,children:[(0,j.jsx)(`span`,{className:`text-[10px] font-bold text-slate-500 uppercase tracking-wider block`,children:`Hero Alias`}),(0,j.jsx)(`span`,{className:`font-bold text-ink-black text-xs`,children:r?.heroName||`Champion`})]}),(0,j.jsxs)(`div`,{className:`bg-[#FFFDF0] border border-amber-900/20 rounded p-2`,children:[(0,j.jsx)(`span`,{className:`text-[10px] font-bold text-slate-500 uppercase tracking-wider block`,children:`Target Goal`}),(0,j.jsx)(`span`,{className:`font-bold text-amber-900 text-xs`,children:r?.targetGoal||`None shared yet (mention to Aurelia!)`})]})]}),r?.preferredLanguage&&(0,j.jsxs)(`div`,{className:`bg-[#FFFDF0] border border-amber-900/20 rounded p-2 text-xs`,children:[(0,j.jsx)(`span`,{className:`text-[10px] font-bold text-slate-500 uppercase tracking-wider block`,children:`Weapon of Choice (Language)`}),(0,j.jsx)(`span`,{className:`font-bold text-ink-black`,children:r.preferredLanguage})]})]}),(0,j.jsxs)(`div`,{className:`bg-white border-[1.5px] border-ink-black rounded-lg p-3 shadow-xs flex flex-col gap-2`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs font-bold text-emerald-800`,children:[(0,j.jsx)(f,{className:`w-3.5 h-3.5`}),(0,j.jsxs)(`span`,{children:[`Mastered Patterns (`,r?.strengths?.length||0,`)`]})]}),r?.strengths&&r.strengths.length>0?(0,j.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:r.strengths.map(e=>(0,j.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2.5 py-0.5 rounded-full text-[11px] font-bold bg-emerald-50 text-emerald-800 border border-emerald-300`,children:[e,u&&(0,j.jsx)(`button`,{type:`button`,onClick:()=>u(`strengths`,e),className:`hover:text-red-600 ml-0.5 cursor-pointer`,title:`Forget strength`,children:(0,j.jsx)(_,{className:`w-3 h-3`})})]},e))}):(0,j.jsx)(`p`,{className:`text-[11px] text-slate-400 italic m-0`,children:`Aurelia will note topics you conquer during your practice.`})]}),(0,j.jsxs)(`div`,{className:`bg-white border-[1.5px] border-ink-black rounded-lg p-3 shadow-xs flex flex-col gap-2`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs font-bold text-rose-800`,children:[(0,j.jsx)(o,{className:`w-3.5 h-3.5`}),(0,j.jsxs)(`span`,{children:[`Nemesis Patterns (`,r?.nemesisPatterns?.length||0,`)`]})]}),r?.nemesisPatterns&&r.nemesisPatterns.length>0?(0,j.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:r.nemesisPatterns.map(e=>(0,j.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2.5 py-0.5 rounded-full text-[11px] font-bold bg-rose-50 text-rose-800 border border-rose-300`,children:[e,u&&(0,j.jsx)(`button`,{type:`button`,onClick:()=>u(`nemesisPatterns`,e),className:`hover:text-red-700 ml-0.5 cursor-pointer`,title:`Forget nemesis`,children:(0,j.jsx)(_,{className:`w-3 h-3`})})]},e))}):(0,j.jsx)(`p`,{className:`text-[11px] text-slate-400 italic m-0`,children:`Aurelia tracks patterns that give you trouble to help you prepare targeted drills.`})]}),(0,j.jsxs)(`div`,{className:`bg-white border-[1.5px] border-ink-black rounded-lg p-3 shadow-xs flex flex-col gap-2`,children:[(0,j.jsx)(`div`,{className:`text-xs font-bold text-slate-800`,children:(0,j.jsxs)(`span`,{children:[`Personal Notes & Shared Lore (`,r?.personalNotes?.length||0,`)`]})}),r?.personalNotes&&r.personalNotes.length>0?(0,j.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:r.personalNotes.map(e=>(0,j.jsxs)(`div`,{className:`flex items-start justify-between gap-2 p-2 bg-slate-50 border border-slate-200 rounded text-[11px] text-slate-700`,children:[(0,j.jsxs)(`span`,{children:[`• `,e]}),u&&(0,j.jsx)(`button`,{type:`button`,onClick:()=>u(`personalNotes`,e),className:`text-slate-400 hover:text-red-600 shrink-0 cursor-pointer p-0.5`,title:`Forget note`,children:(0,j.jsx)(g,{className:`w-3 h-3`})})]},e))}):(0,j.jsx)(`p`,{className:`text-[11px] text-slate-400 italic m-0`,children:`Share your background or routine with Aurelia and she will hold it in her memory.`})]}),a&&a.length>0&&(0,j.jsxs)(`div`,{className:`bg-white border-[1.5px] border-ink-black rounded-lg p-3 shadow-xs flex flex-col gap-2`,children:[(0,j.jsxs)(`div`,{className:`flex items-center justify-between border-b border-slate-100 pb-1`,children:[(0,j.jsx)(`span`,{className:`text-xs font-bold text-slate-800`,children:`Episodic Memory Chain (EM-LLM)`}),(0,j.jsxs)(`span`,{className:`text-[10px] text-slate-400 font-mono`,children:[a.length,` events`]})]}),(0,j.jsx)(`div`,{className:`flex flex-col gap-2 max-h-40 overflow-y-auto custom-scrollbar`,children:a.slice(0,8).map(e=>(0,j.jsxs)(`div`,{className:`text-[11px] p-2 bg-[#FFFDF0] border border-amber-900/15 rounded flex flex-col gap-0.5`,children:[(0,j.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,j.jsx)(`span`,{className:`font-bold text-ink-black uppercase text-[9px] px-1.5 py-0.5 bg-amber-200/60 rounded`,children:e.eventType.replace(`_`,` `)}),(0,j.jsx)(`span`,{className:`text-[10px] text-slate-400`,children:new Date(e.timestamp).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})})]}),(0,j.jsx)(`div`,{className:`font-bold text-slate-800 mt-0.5`,children:e.title}),(0,j.jsx)(`div`,{className:`text-slate-600 text-[10px]`,children:e.description})]},e.id))})]}),(0,j.jsxs)(`div`,{className:`bg-white border-[1.5px] border-ink-black rounded-lg p-3 shadow-xs flex flex-col gap-2`,children:[(0,j.jsxs)(`div`,{className:`flex items-center justify-between border-b border-slate-100 pb-1`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs font-bold text-indigo-900`,children:[(0,j.jsx)(h,{className:`w-3.5 h-3.5 text-amber-500`}),(0,j.jsx)(`span`,{children:`Autonomous Enchantment Telemetry`})]}),(0,j.jsxs)(`span`,{className:`text-[10px] text-slate-400 font-mono`,children:[l?.length||0,` executed`]})]}),l&&l.length>0?(0,j.jsx)(`div`,{className:`flex flex-col gap-1.5 max-h-36 overflow-y-auto custom-scrollbar`,children:l.slice(0,10).map((e,t)=>(0,j.jsxs)(`div`,{className:`text-[11px] p-2 bg-indigo-50/50 border border-indigo-100 rounded flex items-center justify-between gap-2`,children:[(0,j.jsxs)(`div`,{className:`flex flex-col min-w-0`,children:[(0,j.jsxs)(`span`,{className:`font-bold text-indigo-950 font-mono text-[10px] truncate`,children:[e.tool_name,`()`]}),e.args&&Object.keys(e.args).length>0&&(0,j.jsx)(`span`,{className:`text-[9px] text-slate-500 truncate`,children:JSON.stringify(e.args).slice(0,50)})]}),(0,j.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[e.execution_time_ms!==void 0&&(0,j.jsxs)(`span`,{className:`text-[9px] text-slate-400 flex items-center gap-0.5 font-mono`,children:[(0,j.jsx)(d,{className:`w-2.5 h-2.5`}),e.execution_time_ms,`ms`]}),(0,j.jsx)(`span`,{className:`px-1.5 py-0.2 text-[9px] font-bold rounded ${e.success?`bg-emerald-100 text-emerald-800`:`bg-rose-100 text-rose-800`}`,children:e.success?`SUCCESS`:`ERR`})]})]},t))}):(0,j.jsx)(`p`,{className:`text-[11px] text-slate-400 italic m-0`,children:`No autonomous enchantments executed yet in this session.`})]})]})]}),(0,j.jsx)(`div`,{className:`bg-white border-t border-slate-200 px-4 py-2 flex items-center justify-end shrink-0`,children:(0,j.jsx)(`button`,{type:`button`,onClick:p,className:`px-4 py-1.5 bg-white hover:bg-slate-100 border-[1.5px] border-ink-black rounded font-bold text-xs text-ink-black cursor-pointer shadow-xs active:translate-y-0.5`,children:`Close`})})]})})}var R=e({default:()=>z});function z(){let e=E(),[t,r]=(0,O.useState)(w()),[a,o]=(0,O.useState)(!1),[s,c]=(0,O.useState)(!1),[d,f]=(0,O.useState)(!1);(0,O.useEffect)(()=>{C.syncWithBackend(),C.triggerProactiveGreeting()},[]);let h=()=>{let e=!t;r(e),T(e)},g=()=>{window.confirm(`Clear conversation transcript with Princess Aurelia?`)&&C.clearTranscript()},y=(0,O.useCallback)(e=>{C.setIsTyping(e)},[]),b=(0,O.useMemo)(()=>[...e.transcript].reverse().find(e=>e.sender===`princess`)||e.transcript[0],[e.transcript]);return(0,j.jsxs)(`div`,{className:`relative w-full h-full bg-gradient-to-b from-[#FFFDF0] via-[#FFF9E6] to-[#FFF3CD] flex flex-col select-none font-sans text-ink-black overflow-hidden`,children:[(0,j.jsxs)(`div`,{className:`h-12 bg-white/95 backdrop-blur-sm border-b-[3px] border-ink-black px-3 sm:px-4 flex items-center justify-between gap-2 shrink-0 shadow-sm z-20`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,j.jsx)(v,{className:`w-4 h-4 text-amber-500 shrink-0`}),(0,j.jsx)(`h3`,{className:`font-headline-md font-bold text-xs sm:text-sm text-ink-black m-0 truncate`,children:e.companionSettings.name||`Princess Aurelia`})]}),(0,j.jsx)(`span`,{className:`hidden sm:inline-flex px-2 py-0.5 rounded-full bg-amber-100 border border-amber-300 text-[10px] font-bold text-amber-900 shadow-inner shrink-0`,children:e.bondTier}),(0,j.jsx)(`span`,{className:`hidden md:inline-flex px-2 py-0.5 rounded-full bg-indigo-50 border border-indigo-200 text-[10px] font-bold text-indigo-800 shrink-0`,children:e.currentRhythm.toUpperCase()})]}),(0,j.jsxs)(`div`,{className:`flex items-center gap-1.5 sm:gap-2 shrink-0`,children:[(0,j.jsxs)(`button`,{type:`button`,onClick:()=>o(!0),className:`px-2.5 py-1 bg-amber-100 hover:bg-amber-200 border-[2px] border-ink-black rounded font-bold text-[11px] text-ink-black cursor-pointer shadow-[1.5px_1.5px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none transition-all flex items-center gap-1.5`,title:`View Spire Journey Progress`,children:[(0,j.jsx)(l,{className:`w-3.5 h-3.5 text-indigo-700`}),(0,j.jsxs)(`span`,{className:`font-arcade text-[9px] text-indigo-950`,children:[e.currentFloor,`/150 LC`]})]}),(0,j.jsxs)(`button`,{type:`button`,onClick:()=>c(!0),className:`px-2.5 py-1 bg-white hover:bg-amber-50 border-[2px] border-ink-black rounded font-bold text-[11px] text-ink-black cursor-pointer shadow-[1.5px_1.5px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none transition-all flex items-center gap-1.5`,title:`Open Royal Satchel (Missives & Diary)`,children:[(0,j.jsx)(i,{className:`w-3.5 h-3.5 text-amber-700`}),(0,j.jsx)(`span`,{className:`hidden md:inline`,children:`Satchel`}),e.unlockedLetters.length>0&&(0,j.jsx)(`span`,{className:`w-4 h-4 rounded-full bg-amber-400 text-ink-black text-[9px] font-extrabold flex items-center justify-center border border-ink-black`,children:e.unlockedLetters.length})]}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>f(!0),className:`p-1.5 bg-white hover:bg-slate-100 border-[2px] border-ink-black rounded text-ink-black cursor-pointer shadow-[1.5px_1.5px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none transition-all`,title:`View Transcript History`,children:(0,j.jsx)(n,{className:`w-3.5 h-3.5 text-slate-700`})}),(0,j.jsx)(`button`,{type:`button`,onClick:h,className:`p-1.5 border-[2px] border-ink-black rounded text-ink-black cursor-pointer shadow-[1.5px_1.5px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none transition-all ${t?`bg-slate-200 opacity-80`:`bg-[#FFE24C] hover:bg-yellow-300`}`,title:t?`Unmute Audio`:`Mute Audio`,children:t?(0,j.jsx)(u,{className:`w-3.5 h-3.5`}):(0,j.jsx)(m,{className:`w-3.5 h-3.5`})})]})]}),(0,j.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-start gap-3 sm:gap-4 p-3 sm:p-5 overflow-y-auto custom-scrollbar min-h-0 relative`,children:[(0,j.jsx)(M,{emotion:e.activeEmotion,floor:e.currentFloor,rhythm:e.currentRhythm,activity:e.currentActivity,isLoading:e.isLoading}),(0,j.jsx)(N,{text:b?.text||`I believe in you, champion!`,characterName:e.companionSettings.name,emotion:e.activeEmotion,isLoading:e.isLoading,isStreaming:b?.isStreaming,toolCalls:b?.toolCalls,onTypingStatusChange:y})]}),(0,j.jsx)(F,{suggestions:b?.choiceSuggestions,isLoading:e.isLoading,onSendMessage:e=>C.sendMessage(e),placeholder:`Speak with ${e.companionSettings.name||`Princess Aurelia`}...`}),a&&(0,j.jsx)(I,{currentFloor:e.currentFloor,totalSolved:e.totalSolved,onClose:()=>o(!1)}),s&&(0,j.jsx)(L,{unlockedLetters:e.unlockedLetters,spireChronicles:e.spireChronicles,currentFloor:e.currentFloor,heroCodex:e.heroCodex,episodicEvents:e.episodicEvents,recentToolTelemetry:e.recentToolTelemetry,onRemoveCodexItem:C.removeCodexItem,onClose:()=>c(!1)}),d&&(0,j.jsx)(`div`,{className:`absolute inset-0 z-50 bg-ink-black/40 backdrop-blur-xs flex items-center justify-center p-3 sm:p-4 animate-in fade-in duration-200`,onClick:()=>f(!1),children:(0,j.jsxs)(`div`,{className:`bg-[#FFFDF0] border-[3px] border-ink-black rounded-xl max-w-lg w-full h-[80%] max-h-[520px] shadow-[6px_6px_0px_0px_#1E293B] flex flex-col overflow-hidden`,onClick:e=>e.stopPropagation(),children:[(0,j.jsxs)(`div`,{className:`bg-white border-b-[2px] border-ink-black px-4 py-2.5 flex items-center justify-between shrink-0`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,j.jsx)(n,{className:`w-4 h-4 text-ink-black`}),(0,j.jsxs)(`h4`,{className:`font-headline-md font-bold text-xs sm:text-sm text-ink-black m-0`,children:[`Dialogue Transcript (`,e.transcript.length,` turns)`]})]}),(0,j.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,j.jsxs)(`button`,{type:`button`,onClick:g,className:`p-1 hover:bg-rose-100 text-rose-700 rounded text-[11px] font-bold flex items-center gap-1 cursor-pointer mr-1`,title:`Clear Chat History`,children:[(0,j.jsx)(p,{className:`w-3.5 h-3.5`}),(0,j.jsx)(`span`,{children:`Clear`})]}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>f(!1),className:`p-1 hover:bg-slate-200 rounded text-slate-700 cursor-pointer`,title:`Close`,children:(0,j.jsx)(_,{className:`w-4 h-4`})})]})]}),(0,j.jsx)(`div`,{className:`flex-1 p-3 sm:p-4 overflow-y-auto custom-scrollbar flex flex-col gap-2.5`,children:e.transcript.map((t,n)=>(0,j.jsxs)(`div`,{className:`p-2.5 rounded-lg border-[2px] border-ink-black shadow-[2px_2px_0px_0px_#1E293B] max-w-[90%] ${t.sender===`princess`?`bg-white text-ink-black self-start`:`bg-[#FFE24C] text-ink-black self-end`}`,children:[(0,j.jsx)(`div`,{className:`text-[10px] font-bold font-headline-md mb-1 text-slate-600`,children:t.sender===`princess`?e.companionSettings.name:`Hero`}),(0,j.jsx)(`p`,{className:`text-xs font-medium m-0 leading-relaxed whitespace-pre-wrap select-text`,children:t.text})]},t.id||n))})]})})]})}export{R as t};
|
|
|
|
|
|
algospaced-ui/dist/assets/PrincessChamber-IJaaUuL1.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
import{n as e,r as t}from"./rolldown-runtime-hePW80VL.js";import{I as n,Lt as r,O as i,S as a,St as o,T as s,U as c,bt as l,c as u,ct as d,ft as f,k as p,l as m,o as h,p as g,s as _,y as v,zt as y}from"./vendor-react-qmUj3JUi.js";import{C as b,S as x,_ as S,b as C,d as w,v as T,x as E,y as D}from"./index-DYMSjoUb.js";var O=t(y(),1),k={1:{particleType:`pollen`,particleCount:16,particleColors:[`#FDE047`,`#FEF08A`,`#86EFAC`],gradientBg:`from-[#FFFDF0] via-[#FFF9E6] to-[#FEF3C7]`,glowColor:`rgba(251, 191, 36, 0.3)`,badgeLabel:`🌾 Plains Breeze`},2:{particleType:`leaves`,particleCount:18,particleColors:[`#86EFAC`,`#4ADE80`,`#22C55E`,`#A7F3D0`],gradientBg:`from-[#F0FDF4] via-[#DCFCE7] to-[#FEF9C3]`,glowColor:`rgba(34, 197, 94, 0.3)`,badgeLabel:`🍃 Whispering Leaves`},3:{particleType:`spores`,particleCount:22,particleColors:[`#67E8F9`,`#38BDF8`,`#818CF8`,`#C084FC`],gradientBg:`from-[#F0F9FF] via-[#E0F2FE] to-[#EDE9FE]`,glowColor:`rgba(56, 189, 248, 0.35)`,badgeLabel:`✨ Crystal Spores`},4:{particleType:`snow`,particleCount:28,particleColors:[`#FFFFFF`,`#E0F2FE`,`#BAE6FD`],gradientBg:`from-[#F8FAFC] via-[#F1F5F9] to-[#E2E8F0]`,glowColor:`rgba(186, 230, 253, 0.4)`,badgeLabel:`❄️ Alpine Snowfall`},5:{particleType:`runes`,particleCount:20,particleColors:[`#E879F9`,`#C084FC`,`#A855F7`,`#F472B6`],gradientBg:`from-[#FAF5FF] via-[#F3E8FF] to-[#FCE7F3]`,glowColor:`rgba(192, 132, 252, 0.4)`,badgeLabel:`🔮 Arcane Runes`},6:{particleType:`stardust`,particleCount:35,particleColors:[`#FDE047`,`#F59E0B`,`#E11D48`,`#818CF8`],gradientBg:`from-[#FFFBEB] via-[#FEF3C7] to-[#FFE4E6]`,glowColor:`rgba(245, 158, 11, 0.5)`,badgeLabel:`👑 Spire Gates`}};function A(e){return e<=30?k[1]:e<=60?k[2]:e<=90?k[3]:e<=120?k[4]:e<150?k[5]:k[6]}var j=r();function M({emotion:e,floor:t,rhythm:n,activity:r,isLoading:i=!1,className:a=``,onClick:o}){let s=D[e]||D.smiling_warmly,c=(0,O.useMemo)(()=>A(t),[t]),l=(0,O.useMemo)(()=>{switch(n){case`dawn`:return`from-amber-400/30 via-yellow-300/20 to-transparent`;case`dusk`:return`from-orange-500/30 via-purple-500/20 to-transparent`;case`night`:return`from-indigo-600/30 via-blue-500/20 to-transparent`;default:return`from-amber-300/25 via-sky-300/20 to-transparent`}},[n]);return(0,j.jsxs)(`div`,{onClick:o,className:`relative flex flex-col items-center justify-end select-none pointer-events-auto transition-transform ${a}`,children:[(0,j.jsx)(`div`,{className:`absolute -inset-10 overflow-hidden pointer-events-none z-0`,children:Array.from({length:Math.min(16,c.particleCount)}).map((e,t)=>{let n=c.particleColors[t%c.particleColors.length],r=`${t*17%100}%`,i=`${7+t%5*2}s`,a=`${t*.8%4}s`,o=c.particleType===`leaves`||c.particleType===`runes`?`w-2 h-2`:`w-1.5 h-1.5`;return(0,j.jsx)(`span`,{className:`absolute rounded-full opacity-60 animate-pulse ${o}`,style:{backgroundColor:n,left:r,top:`${t*21%90}%`,boxShadow:`0 0 10px ${n}`,animationDuration:i,animationDelay:a}},t)})}),(0,j.jsx)(`div`,{className:`absolute bottom-4 inset-x-0 h-48 sm:h-72 md:h-96 bg-radial ${l} blur-2xl opacity-70 pointer-events-none z-0`}),(0,j.jsxs)(`div`,{className:`relative z-10 flex flex-col items-start justify-end`,children:[r&&(0,j.jsx)(`div`,{className:`mb-2 max-w-[120px] sm:max-w-xs text-center pointer-events-none animate-in fade-in duration-300`,children:(0,j.jsxs)(`span`,{className:`text-[9px] sm:text-[10px] font-mono font-medium text-[#bfe1ff] bg-[#101e2e]/85 px-2 sm:px-2.5 py-0.5 rounded-full border border-[#3e6080]/70 shadow-md inline-flex items-center gap-1 sm:gap-1.5 backdrop-blur-xs`,children:[(0,j.jsx)(`span`,{className:`text-amber-400`,children:`🏰`}),(0,j.jsx)(`span`,{className:`truncate`,children:r})]})}),(0,j.jsx)(`div`,{className:`relative h-[28vh] sm:h-[40vh] md:h-[46vh] lg:h-[50vh] max-h-[220px] sm:max-h-[380px] md:max-h-[460px] lg:max-h-[500px] min-h-[160px] sm:min-h-[240px] md:min-h-[300px] w-auto max-w-[110px] sm:max-w-[200px] md:max-w-[270px] lg:max-w-[320px] flex items-end justify-end`,children:(0,j.jsx)(`img`,{src:s.imagePath,alt:s.label,loading:`eager`,className:`h-full w-auto max-h-[85vh] object-contain object-bottom-left drop-shadow-[0_16px_32px_rgba(0,0,0,0.55)] transition-all duration-300 ${i?`scale-[1.02] filter brightness-110 saturate-125`:`scale-100`}`,onError:e=>{let t=e.currentTarget;t.src.endsWith(`/sprites/princess/smiling_warmly.webp`)?t.src.endsWith(`/sprites/princess/neutral.webp`)||(t.src=`/sprites/princess/neutral.webp`):t.src=`/sprites/princess/smiling_warmly.webp`}})})]})]})}var N=[`I solved a tough task today!`,`I'm feeling stuck on something.`,`Just need a breather.`],P={backgroundColor:`rgba(20, 36, 54, 0.94)`,boxShadow:`0 0 0 2px #0a1420, inset 0 0 0 3px #4c7396, inset 1px 1px 0 4px #8db7dc, inset -1px -1px 0 4px #1a2c3f, inset 0 0 0 5px #0c1724, 0 10px 28px rgba(0, 0, 0, 0.75)`};function F({characterName:e,text:t,isStreaming:r=!1,isLoading:i=!1,choices:a,toolCalls:o,onSelectChoice:c,onSendMessage:d,onTypingStatusChange:f,currentFloor:h,bondTier:g,satchelCount:y=0,isMuted:b=!1,onToggleMute:x,onOpenProgress:S,onOpenSatchel:C,onOpenHistory:w,onMinimize:T,onClose:E,className:D=``}){let[k,A]=(0,O.useState)(``),[M,F]=(0,O.useState)(!1),[I,L]=(0,O.useState)(0),[R,z]=(0,O.useState)(``),[B,V]=(0,O.useState)(!1),H=(0,O.useRef)(t),U=(0,O.useRef)(!1),W=(0,O.useRef)(null),G=(0,O.useRef)(null),K=r||M;(0,O.useEffect)(()=>{f?.(K)},[K,f]);let q=(0,O.useMemo)(()=>Array.isArray(a)&&a.length>0?a.slice(0,4):N,[a]),J=I<q.length?I:0,Y=!r&&M?k:t;(0,O.useEffect)(()=>{if(r){W.current&&=(clearInterval(W.current),null),U.current=!0,H.current=t;return}if(U.current){U.current=!1,H.current=t,W.current&&=(clearInterval(W.current),null);return}if(t!==H.current&&!i){if(H.current=t,!t){W.current&&=(clearInterval(W.current),null);return}W.current&&clearInterval(W.current);let e=0,n=setInterval(()=>{e++,A(t.slice(0,e)),F(!0),e>=t.length&&(clearInterval(n),W.current=null,F(!1))},20);return W.current=n,()=>{clearInterval(n),W.current=null,F(!1)}}},[t,i,r]);let X=(0,O.useCallback)(()=>{W.current&&=(clearInterval(W.current),null),F(!1)},[]),Z=()=>{let e=R.trim();!e||i||r||(d(e),z(``))};return(0,O.useEffect)(()=>{let e=e=>{if(e.key===`Escape`&&E){e.preventDefault(),E();return}if(!B){if(e.key>=`1`&&e.key<=String(q.length)){let t=parseInt(e.key,10)-1;q[t]&&!i&&!r&&(e.preventDefault(),c(q[t]));return}if(e.key===`ArrowUp`){e.preventDefault(),L(e=>(e-1+q.length)%q.length);return}if(e.key===`ArrowDown`){e.preventDefault(),L(e=>(e+1)%q.length);return}if(e.key===`Enter`){!i&&!r&&q[J]&&(e.preventDefault(),c(q[J]));return}e.key===` `&&K&&(e.preventDefault(),X())}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[B,q,J,i,r,K,c,X,E]),(0,j.jsxs)(`div`,{className:`relative flex flex-col gap-2 w-full ${D}`,children:[(0,j.jsxs)(`div`,{onClick:X,className:`relative w-full rounded-md sm:rounded-lg text-white pt-3.5 pb-3.5 pr-3.5 pl-8 sm:pt-5 sm:pb-5 sm:pr-5 sm:pl-14 md:pl-16 lg:pl-18 flex flex-col gap-2.5 backdrop-blur-md transition-all select-none cursor-pointer`,style:P,children:[(0,j.jsxs)(`div`,{className:`absolute -top-7 right-1 flex items-center gap-1 sm:gap-1.5 z-30`,onClick:e=>e.stopPropagation(),children:[S&&(0,j.jsxs)(`button`,{type:`button`,onClick:S,className:`px-2 py-0.5 bg-[#101e2e]/90 hover:bg-[#1f3750] border border-[#3e6080]/80 hover:border-[#67b1ec] rounded text-[10px] sm:text-[11px] font-mono font-bold text-[#8cb4db] hover:text-white transition-all cursor-pointer flex items-center gap-1 shadow-md`,title:`Spire Tower Road (Floor Progress)`,children:[(0,j.jsx)(l,{className:`w-3 h-3 text-amber-400`}),(0,j.jsxs)(`span`,{children:[h,`/150 LC`]})]}),C&&(0,j.jsxs)(`button`,{type:`button`,onClick:C,className:`px-2 py-0.5 bg-[#101e2e]/90 hover:bg-[#1f3750] border border-[#3e6080]/80 hover:border-[#67b1ec] rounded text-[10px] sm:text-[11px] font-mono font-bold text-[#8cb4db] hover:text-white transition-all cursor-pointer flex items-center gap-1 shadow-md`,title:`Open Royal Satchel`,children:[(0,j.jsx)(s,{className:`w-3 h-3 text-amber-400`}),(0,j.jsx)(`span`,{className:`hidden sm:inline`,children:`Satchel`}),y>0&&(0,j.jsxs)(`span`,{className:`text-[9px] text-[#f3cb65]`,children:[`(`,y,`)`]})]}),w&&(0,j.jsxs)(`button`,{type:`button`,onClick:w,className:`px-2 py-0.5 bg-[#101e2e]/90 hover:bg-[#1f3750] border border-[#3e6080]/80 hover:border-[#67b1ec] rounded text-[10px] sm:text-[11px] font-mono font-bold text-[#8cb4db] hover:text-white transition-all cursor-pointer flex items-center gap-1 shadow-md`,title:`Dialogue Transcript`,children:[(0,j.jsx)(p,{className:`w-3 h-3 text-[#8cb4db]`}),(0,j.jsx)(`span`,{className:`hidden sm:inline`,children:`Log`})]}),x&&(0,j.jsx)(`button`,{type:`button`,onClick:x,className:`p-1 bg-[#101e2e]/90 hover:bg-[#1f3750] border border-[#3e6080]/80 hover:border-[#67b1ec] rounded text-[#8cb4db] hover:text-white transition-all cursor-pointer shadow-md`,title:b?`Unmute Audio`:`Mute Audio`,children:b?(0,j.jsx)(u,{className:`w-3 h-3`}):(0,j.jsx)(m,{className:`w-3 h-3`})}),T&&(0,j.jsx)(`button`,{type:`button`,onClick:T,className:`p-1 bg-[#101e2e]/90 hover:bg-[#1f3750] border border-[#3e6080]/80 hover:border-[#67b1ec] rounded text-[#8cb4db] hover:text-white transition-all cursor-pointer shadow-md`,title:`Minimize to Taskbar`,children:(0,j.jsx)(n,{className:`w-3 h-3`})}),E&&(0,j.jsx)(`button`,{type:`button`,onClick:E,className:`p-1 bg-[#101e2e]/90 hover:bg-rose-900/70 border border-[#3e6080]/80 hover:border-rose-400 rounded text-[#8cb4db] hover:text-rose-200 transition-all cursor-pointer shadow-md`,title:`Leave Parlor (Esc)`,children:(0,j.jsx)(_,{className:`w-3 h-3`})})]}),(0,j.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,j.jsxs)(`span`,{className:`font-mono text-sm sm:text-base font-bold text-[#f3cb65] tracking-wide drop-shadow-[0_1px_2px_rgba(0,0,0,0.9)]`,children:[`-`,e||`Princess Aurelia`,`-`]}),g&&(0,j.jsx)(`span`,{className:`hidden md:inline-block text-[9px] font-mono text-[#8cb4db] bg-[#101d2c]/80 border border-[#3e6080]/60 px-1.5 py-0.2 rounded uppercase tracking-wider`,children:g})]}),(0,j.jsxs)(`div`,{className:`min-h-[48px] sm:min-h-[54px] flex flex-col justify-start`,children:[i?(0,j.jsxs)(`div`,{className:`flex items-center gap-2 py-1 text-xs sm:text-sm font-mono text-[#8cb4db]`,children:[(0,j.jsx)(`span`,{className:`inline-block w-2 h-2 bg-[#f3cb65] rounded-full animate-ping`}),(0,j.jsxs)(`span`,{children:[e||`Princess Aurelia`,` is attuning the crystal relay...`]})]}):(0,j.jsxs)(`div`,{className:`font-mono text-xs sm:text-sm md:text-[15px] leading-relaxed text-[#e6edf4] select-text`,children:[(e=>e.split(/(\*[^*]+\*)/g).map((e,t)=>e.startsWith(`*`)&&e.endsWith(`*`)?(0,j.jsx)(`span`,{className:`text-[#f3cb65] italic font-semibold mr-1 inline-block`,children:e},t):(0,j.jsx)(`span`,{children:e},t)))(Y),K&&(0,j.jsx)(`span`,{className:`inline-block w-1.5 h-3.5 bg-[#f3cb65] ml-1 animate-pulse align-middle`})]}),o&&o.length>0&&!i&&(0,j.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-1.5 select-none`,children:o.map((e,t)=>(0,j.jsxs)(`span`,{className:`px-2 py-0.5 rounded bg-[#102438] border border-[#44729b] text-[10px] font-mono font-bold text-[#bfe1ff] flex items-center gap-1`,children:[(0,j.jsx)(v,{className:`w-2.5 h-2.5 text-[#f3cb65]`}),(0,j.jsxs)(`span`,{children:[`Enchantment: `,e.name]})]},t))})]}),(0,j.jsx)(`div`,{className:`flex flex-col gap-1 pt-1`,onClick:e=>e.stopPropagation(),children:q.map((e,t)=>{let n=t+1,a=J===t;return(0,j.jsxs)(`button`,{type:`button`,disabled:i||r,onClick:()=>c(e),onMouseEnter:()=>L(t),className:`w-full sm:max-w-[90%] md:max-w-[85%] text-left flex items-center gap-2 px-2.5 py-1 rounded-xs sm:rounded-sm transition-all select-none font-mono text-xs sm:text-sm disabled:opacity-40 disabled:cursor-not-allowed ${a&&!i&&!r?`bg-[#1c3e61]/80 border border-[#4883b6]/80 shadow-[0_0_12px_rgba(72,131,182,0.25)] cursor-pointer`:`border border-transparent hover:bg-[#1c3e61]/35 cursor-pointer`}`,children:[(0,j.jsxs)(`span`,{className:`font-bold shrink-0 ${a?`text-[#e2ecf7]`:`text-[#b4c8dc]`}`,children:[n,`.`]}),(0,j.jsxs)(`span`,{className:`truncate font-medium ${a?`text-[#f3cb65]`:`text-[#dde7f2]`}`,children:[`[`,e,`]`]})]},t)})})]}),(0,j.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),Z()},onClick:e=>e.stopPropagation(),className:`w-full rounded-md sm:rounded-lg text-white py-2 sm:py-2.5 pr-3 sm:pr-4 pl-8 sm:pl-14 md:pl-16 lg:pl-18 flex items-center gap-2 backdrop-blur-md transition-all select-none`,style:P,children:[(0,j.jsx)(`span`,{className:`font-mono text-sm sm:text-base font-bold text-[#e2ecf7] select-none pl-0.5 shrink-0`,children:`>`}),(0,j.jsxs)(`div`,{className:`flex-1 flex items-center bg-[#101e2e]/90 border border-[#3b5d7d] rounded px-2.5 py-1 focus-within:border-[#67b1ec] focus-within:ring-1 focus-within:ring-[#67b1ec]/40 shadow-inner`,children:[(0,j.jsx)(`span`,{className:`text-[#f3cb65] font-mono text-xs sm:text-sm select-none mr-1.5 shrink-0`,children:`[`}),(0,j.jsx)(`input`,{ref:G,type:`text`,value:R,onChange:e=>z(e.target.value),onFocus:()=>V(!0),onBlur:()=>V(!1),disabled:i||r,placeholder:`Speak with ${e||`Princess Aurelia`}...`,className:`flex-1 bg-transparent border-none text-[#e2ecf7] placeholder-[#f3cb65]/70 font-mono text-xs sm:text-sm focus:outline-none disabled:opacity-50 disabled:cursor-not-allowed`}),(0,j.jsx)(`span`,{className:`text-[#f3cb65] font-mono text-xs sm:text-sm select-none ml-1.5 shrink-0`,children:`]`})]}),(0,j.jsxs)(`button`,{type:`submit`,disabled:i||r||!R.trim(),className:`bg-[#34597b] hover:bg-[#3f6990] active:bg-[#2b4c6e] disabled:opacity-40 disabled:cursor-not-allowed border border-[#5c8cb5] hover:border-[#8db7dc] rounded px-3 sm:px-4 py-1 text-xs sm:text-sm font-mono font-bold text-white transition-all cursor-pointer shadow-md select-none shrink-0 flex items-center`,children:[(0,j.jsx)(`span`,{className:`text-[#f3cb65]`,children:`[`}),(0,j.jsx)(`span`,{className:`text-white px-1`,children:`Send`}),(0,j.jsx)(`span`,{className:`text-[#f3cb65]`,children:`]`})]})]})]})}function I({currentFloor:e,onClose:t}){let n=b(e),r=Math.min(100,Math.round(e/150*100));return(0,j.jsx)(`div`,{className:`absolute inset-0 z-50 bg-ink-black/40 backdrop-blur-xs flex items-center justify-center p-3 sm:p-4 animate-in fade-in duration-200 select-none`,onClick:t,children:(0,j.jsxs)(`div`,{className:`bg-[#FFFDF0] border-[3px] border-ink-black rounded-xl p-4 sm:p-5 max-w-md w-full shadow-[6px_6px_0px_0px_#1E293B] flex flex-col gap-3.5`,onClick:e=>e.stopPropagation(),children:[(0,j.jsxs)(`div`,{className:`flex items-center justify-between border-b-[2px] border-ink-black pb-2`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,j.jsx)(l,{className:`w-5 h-5 text-indigo-600`}),(0,j.jsx)(`h4`,{className:`font-headline-md font-bold text-sm text-ink-black m-0`,children:`Journey to the Big-O Spire`})]}),(0,j.jsx)(`button`,{type:`button`,onClick:t,className:`p-1 hover:bg-slate-200 rounded text-slate-700 cursor-pointer`,title:`Close`,children:(0,j.jsx)(_,{className:`w-4 h-4`})})]}),(0,j.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,j.jsxs)(`div`,{className:`flex items-center justify-between text-xs font-bold font-headline-md`,children:[(0,j.jsx)(`span`,{children:`Path Progress:`}),(0,j.jsxs)(`span`,{className:`font-arcade bg-indigo-100 text-indigo-900 px-2 py-0.5 rounded border border-indigo-300`,children:[e,` / 150 Leagues`]})]}),(0,j.jsx)(`div`,{className:`w-full bg-slate-200 h-4 border-[2px] border-ink-black rounded-full overflow-hidden p-0.5`,children:(0,j.jsx)(`div`,{className:`bg-gradient-to-r from-amber-400 via-yellow-400 to-emerald-400 h-full rounded-full transition-all duration-500`,style:{width:`${r}%`}})}),(0,j.jsxs)(`div`,{className:`flex items-center justify-between text-[11px] text-trash-gray font-medium`,children:[(0,j.jsxs)(`span`,{children:[`Progress: `,(0,j.jsxs)(`strong`,{children:[r,`%`]})]}),(0,j.jsxs)(`span`,{children:[`Distance to Tower: `,(0,j.jsxs)(`strong`,{children:[Math.max(0,150-e),` leagues`]})]})]})]}),(0,j.jsxs)(`div`,{className:`bg-white border-[2px] border-ink-black rounded-lg p-3 shadow-[2px_2px_0px_0px_#1E293B] flex flex-col gap-1`,children:[(0,j.jsx)(`div`,{className:`text-[10px] font-bold uppercase text-amber-700 tracking-wider`,children:`Current Realm:`}),(0,j.jsx)(`div`,{className:`font-bold text-xs text-ink-black`,children:n.title}),(0,j.jsx)(`p`,{className:`text-[11px] text-slate-600 m-0 leading-relaxed font-medium`,children:n.description}),(0,j.jsxs)(`div`,{className:`text-[10px] text-amber-900 bg-amber-50 p-1.5 rounded border border-amber-200 italic mt-1`,children:[`📜 `,n.bgLore]})]}),(0,j.jsx)(`div`,{className:`flex items-center justify-between gap-1 text-center`,children:[{floor:30,label:`Arrays`},{floor:60,label:`Pointers`},{floor:90,label:`Trees`},{floor:120,label:`Heaps`},{floor:150,label:`Spire`}].map(t=>{let n=e>=t.floor;return(0,j.jsxs)(`div`,{className:`flex-1 p-1.5 rounded border text-[10px] flex flex-col items-center ${n?`bg-emerald-100 border-emerald-600 text-emerald-900 font-bold`:`bg-slate-100 border-slate-300 text-slate-500`}`,children:[(0,j.jsx)(`span`,{children:n?`✓`:t.floor}),(0,j.jsx)(`span`,{className:`text-[9px] truncate w-full`,children:t.label})]},t.floor)})}),(0,j.jsx)(`div`,{className:`flex items-center justify-end border-t border-slate-200 pt-2 mt-1`,children:(0,j.jsx)(`button`,{type:`button`,onClick:t,className:`px-4 py-1.5 bg-white hover:bg-slate-100 border-[1.5px] border-ink-black rounded font-bold text-xs text-ink-black cursor-pointer shadow-xs active:translate-y-0.5`,children:`Done`})})]})})}function L({unlockedLetters:e,spireChronicles:t,currentFloor:n,heroCodex:r,episodicEvents:i,recentToolTelemetry:l,onRemoveCodexItem:u,onClose:p}){let[m,y]=(0,O.useState)(`letters`),[b,S]=(0,O.useState)(e[e.length-1]||null);return(0,j.jsx)(`div`,{className:`absolute inset-0 z-50 bg-ink-black/50 backdrop-blur-xs flex items-center justify-center p-3 sm:p-4 animate-in fade-in duration-200 select-none`,onClick:p,children:(0,j.jsxs)(`div`,{className:`bg-[#FFFDF0] border-[3px] border-ink-black rounded-xl max-w-lg w-full h-[85%] max-h-[560px] shadow-[6px_6px_0px_0px_#1E293B] flex flex-col overflow-hidden`,onClick:e=>e.stopPropagation(),children:[(0,j.jsxs)(`div`,{className:`bg-white border-b-[2px] border-ink-black px-4 py-2.5 flex items-center justify-between shrink-0`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,j.jsx)(s,{className:`w-5 h-5 text-amber-700`}),(0,j.jsx)(`h4`,{className:`font-headline-md font-bold text-sm text-ink-black m-0`,children:`The Royal Satchel`})]}),(0,j.jsx)(`button`,{type:`button`,onClick:p,className:`p-1 hover:bg-slate-200 rounded text-slate-700 cursor-pointer`,title:`Close`,children:(0,j.jsx)(_,{className:`w-4 h-4`})})]}),(0,j.jsxs)(`div`,{className:`flex border-b-2 border-ink-black bg-amber-100/70 shrink-0`,children:[(0,j.jsxs)(`button`,{type:`button`,onClick:()=>y(`letters`),className:`flex-1 py-2 text-xs font-bold font-headline-md flex items-center justify-center gap-1.5 transition-colors cursor-pointer border-r border-ink-black/20 ${m===`letters`?`bg-[#FFFDF0] text-amber-950 border-b-2 border-b-[#FFFDF0] -mb-[2px]`:`text-slate-600 hover:bg-amber-200/50`}`,children:[(0,j.jsx)(s,{className:`w-3.5 h-3.5`}),(0,j.jsxs)(`span`,{children:[`Missives (`,e.length,`/5)`]})]}),(0,j.jsxs)(`button`,{type:`button`,onClick:()=>y(`diary`),className:`flex-1 py-2 text-xs font-bold font-headline-md flex items-center justify-center gap-1.5 transition-colors cursor-pointer border-r border-ink-black/20 ${m===`diary`?`bg-[#FFFDF0] text-amber-950 border-b-2 border-b-[#FFFDF0] -mb-[2px]`:`text-slate-600 hover:bg-amber-200/50`}`,children:[(0,j.jsx)(o,{className:`w-3.5 h-3.5`}),(0,j.jsxs)(`span`,{children:[`Chronicles (`,t.length,`)`]})]}),(0,j.jsxs)(`button`,{type:`button`,onClick:()=>y(`codex`),className:`flex-1 py-2 text-xs font-bold font-headline-md flex items-center justify-center gap-1.5 transition-colors cursor-pointer ${m===`codex`?`bg-[#FFFDF0] text-amber-950 border-b-2 border-b-[#FFFDF0] -mb-[2px]`:`text-slate-600 hover:bg-amber-200/50`}`,children:[(0,j.jsx)(v,{className:`w-3.5 h-3.5 text-amber-700`}),(0,j.jsx)(`span`,{children:`Codex`})]})]}),(0,j.jsxs)(`div`,{className:`flex-1 p-3 sm:p-4 overflow-y-auto custom-scrollbar flex flex-col gap-3 min-h-0`,children:[m===`letters`&&(0,j.jsxs)(`div`,{className:`flex flex-col gap-3 flex-1`,children:[(0,j.jsx)(`div`,{className:`flex items-center gap-1.5 overflow-x-auto pb-1`,children:[30,60,90,120,150].map(e=>{let t=x[e],r=n>=e,i=b?.floor===e;return(0,j.jsxs)(`button`,{type:`button`,disabled:!r,onClick:()=>r&&S(t),className:`px-3 py-1 rounded-full text-[11px] font-bold border-[1.5px] border-ink-black flex items-center gap-1 shrink-0 transition-all cursor-pointer ${r?i?`bg-[#FFE24C] text-ink-black shadow-[1.5px_1.5px_0px_0px_#1E293B]`:`bg-white hover:bg-amber-100 text-slate-800`:`opacity-40 bg-slate-200 text-slate-500 cursor-not-allowed`}`,children:[r?(0,j.jsx)(`span`,{children:`📜`}):(0,j.jsx)(c,{className:`w-3 h-3`}),(0,j.jsxs)(`span`,{children:[`League `,e]})]},e)})}),b?(0,j.jsxs)(`div`,{className:`bg-[#FFF9E6] border-[2px] border-amber-900/40 rounded-lg p-4 shadow-sm flex-1 overflow-y-auto custom-scrollbar flex flex-col select-text`,children:[(0,j.jsxs)(`div`,{className:`border-b border-amber-800/20 pb-2 mb-3 flex items-center justify-between`,children:[(0,j.jsxs)(`div`,{children:[(0,j.jsxs)(`div`,{className:`text-[10px] font-bold text-amber-800 uppercase tracking-wider`,children:[b.chapterTitle,` • League `,b.floor]}),(0,j.jsx)(`h5`,{className:`font-headline-md font-bold text-sm text-amber-950 m-0`,children:b.title})]}),(0,j.jsx)(`span`,{className:`text-xl`,children:`🪶`})]}),(0,j.jsx)(`p`,{className:`text-xs sm:text-[13px] text-amber-950 font-serif leading-relaxed whitespace-pre-wrap flex-1 italic`,children:b.letterText})]}):(0,j.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center text-center p-6 text-slate-500`,children:[(0,j.jsx)(c,{className:`w-8 h-8 mb-2 text-slate-400`}),(0,j.jsx)(`p`,{className:`text-xs font-medium`,children:`Conquer 30 LeetCode problems along the path to receive your first Royal Missive from Aurelia.`})]})]}),m===`diary`&&(0,j.jsx)(`div`,{className:`flex flex-col gap-2.5 flex-1`,children:t.length>0?t.map(e=>(0,j.jsxs)(`div`,{className:`p-3 bg-white border-[1.5px] border-ink-black rounded-lg shadow-xs flex flex-col gap-1 select-text`,children:[(0,j.jsxs)(`div`,{className:`flex items-center justify-between text-[10px] text-amber-800 font-bold border-b border-slate-100 pb-1`,children:[(0,j.jsxs)(`span`,{children:[`League `,e.floor,` along the Path`]}),(0,j.jsx)(`span`,{children:new Date(e.timestamp).toLocaleDateString()})]}),(0,j.jsxs)(`p`,{className:`text-xs text-ink-black font-medium leading-relaxed m-0 italic font-serif`,children:[`“`,e.text,`”`]})]},e.id)):(0,j.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center text-center p-6 text-slate-500`,children:[(0,j.jsx)(o,{className:`w-8 h-8 mb-2 text-slate-400`}),(0,j.jsx)(`p`,{className:`text-xs font-medium`,children:`Aurelia records entries in her Spire Chronicles autonomously as you chat, rest, and cross chapter milestones.`})]})}),m===`codex`&&(0,j.jsxs)(`div`,{className:`flex flex-col gap-3 flex-1 select-text`,children:[(0,j.jsxs)(`div`,{className:`bg-white border-[1.5px] border-ink-black rounded-lg p-3 shadow-xs flex flex-col gap-2`,children:[(0,j.jsxs)(`div`,{className:`flex items-center justify-between border-b border-slate-100 pb-1.5`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,j.jsx)(v,{className:`w-4 h-4 text-amber-600`}),(0,j.jsx)(`h5`,{className:`font-headline-md font-bold text-xs text-ink-black m-0`,children:`Hero Codex (MemGPT & Mem0 Core Memory)`})]}),(0,j.jsx)(`span`,{className:`text-[10px] text-slate-400 font-mono`,children:`Cognitive Sync`})]}),(0,j.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2 text-xs`,children:[(0,j.jsxs)(`div`,{className:`bg-[#FFFDF0] border border-amber-900/20 rounded p-2`,children:[(0,j.jsx)(`span`,{className:`text-[10px] font-bold text-slate-500 uppercase tracking-wider block`,children:`Hero Alias`}),(0,j.jsx)(`span`,{className:`font-bold text-ink-black text-xs`,children:r?.heroName||`Champion`})]}),(0,j.jsxs)(`div`,{className:`bg-[#FFFDF0] border border-amber-900/20 rounded p-2`,children:[(0,j.jsx)(`span`,{className:`text-[10px] font-bold text-slate-500 uppercase tracking-wider block`,children:`Target Goal`}),(0,j.jsx)(`span`,{className:`font-bold text-amber-900 text-xs`,children:r?.targetGoal||`None shared yet (mention to Aurelia!)`})]})]}),r?.preferredLanguage&&(0,j.jsxs)(`div`,{className:`bg-[#FFFDF0] border border-amber-900/20 rounded p-2 text-xs`,children:[(0,j.jsx)(`span`,{className:`text-[10px] font-bold text-slate-500 uppercase tracking-wider block`,children:`Weapon of Choice (Language)`}),(0,j.jsx)(`span`,{className:`font-bold text-ink-black`,children:r.preferredLanguage})]})]}),(0,j.jsxs)(`div`,{className:`bg-white border-[1.5px] border-ink-black rounded-lg p-3 shadow-xs flex flex-col gap-2`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs font-bold text-emerald-800`,children:[(0,j.jsx)(f,{className:`w-3.5 h-3.5`}),(0,j.jsxs)(`span`,{children:[`Mastered Patterns (`,r?.strengths?.length||0,`)`]})]}),r?.strengths&&r.strengths.length>0?(0,j.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:r.strengths.map(e=>(0,j.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2.5 py-0.5 rounded-full text-[11px] font-bold bg-emerald-50 text-emerald-800 border border-emerald-300`,children:[e,u&&(0,j.jsx)(`button`,{type:`button`,onClick:()=>u(`strengths`,e),className:`hover:text-red-600 ml-0.5 cursor-pointer`,title:`Forget strength`,children:(0,j.jsx)(_,{className:`w-3 h-3`})})]},e))}):(0,j.jsx)(`p`,{className:`text-[11px] text-slate-400 italic m-0`,children:`Aurelia will note topics you conquer during your practice.`})]}),(0,j.jsxs)(`div`,{className:`bg-white border-[1.5px] border-ink-black rounded-lg p-3 shadow-xs flex flex-col gap-2`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs font-bold text-rose-800`,children:[(0,j.jsx)(a,{className:`w-3.5 h-3.5`}),(0,j.jsxs)(`span`,{children:[`Nemesis Patterns (`,r?.nemesisPatterns?.length||0,`)`]})]}),r?.nemesisPatterns&&r.nemesisPatterns.length>0?(0,j.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:r.nemesisPatterns.map(e=>(0,j.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2.5 py-0.5 rounded-full text-[11px] font-bold bg-rose-50 text-rose-800 border border-rose-300`,children:[e,u&&(0,j.jsx)(`button`,{type:`button`,onClick:()=>u(`nemesisPatterns`,e),className:`hover:text-red-700 ml-0.5 cursor-pointer`,title:`Forget nemesis`,children:(0,j.jsx)(_,{className:`w-3 h-3`})})]},e))}):(0,j.jsx)(`p`,{className:`text-[11px] text-slate-400 italic m-0`,children:`Aurelia tracks patterns that give you trouble to help you prepare targeted drills.`})]}),(0,j.jsxs)(`div`,{className:`bg-white border-[1.5px] border-ink-black rounded-lg p-3 shadow-xs flex flex-col gap-2`,children:[(0,j.jsx)(`div`,{className:`text-xs font-bold text-slate-800`,children:(0,j.jsxs)(`span`,{children:[`Personal Notes & Shared Lore (`,r?.personalNotes?.length||0,`)`]})}),r?.personalNotes&&r.personalNotes.length>0?(0,j.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:r.personalNotes.map(e=>(0,j.jsxs)(`div`,{className:`flex items-start justify-between gap-2 p-2 bg-slate-50 border border-slate-200 rounded text-[11px] text-slate-700`,children:[(0,j.jsxs)(`span`,{children:[`• `,e]}),u&&(0,j.jsx)(`button`,{type:`button`,onClick:()=>u(`personalNotes`,e),className:`text-slate-400 hover:text-red-600 shrink-0 cursor-pointer p-0.5`,title:`Forget note`,children:(0,j.jsx)(g,{className:`w-3 h-3`})})]},e))}):(0,j.jsx)(`p`,{className:`text-[11px] text-slate-400 italic m-0`,children:`Share your background or routine with Aurelia and she will hold it in her memory.`})]}),i&&i.length>0&&(0,j.jsxs)(`div`,{className:`bg-white border-[1.5px] border-ink-black rounded-lg p-3 shadow-xs flex flex-col gap-2`,children:[(0,j.jsxs)(`div`,{className:`flex items-center justify-between border-b border-slate-100 pb-1`,children:[(0,j.jsx)(`span`,{className:`text-xs font-bold text-slate-800`,children:`Episodic Memory Chain (EM-LLM)`}),(0,j.jsxs)(`span`,{className:`text-[10px] text-slate-400 font-mono`,children:[i.length,` events`]})]}),(0,j.jsx)(`div`,{className:`flex flex-col gap-2 max-h-40 overflow-y-auto custom-scrollbar`,children:i.slice(0,8).map(e=>(0,j.jsxs)(`div`,{className:`text-[11px] p-2 bg-[#FFFDF0] border border-amber-900/15 rounded flex flex-col gap-0.5`,children:[(0,j.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,j.jsx)(`span`,{className:`font-bold text-ink-black uppercase text-[9px] px-1.5 py-0.5 bg-amber-200/60 rounded`,children:e.eventType.replace(`_`,` `)}),(0,j.jsx)(`span`,{className:`text-[10px] text-slate-400`,children:new Date(e.timestamp).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})})]}),(0,j.jsx)(`div`,{className:`font-bold text-slate-800 mt-0.5`,children:e.title}),(0,j.jsx)(`div`,{className:`text-slate-600 text-[10px]`,children:e.description})]},e.id))})]}),(0,j.jsxs)(`div`,{className:`bg-white border-[1.5px] border-ink-black rounded-lg p-3 shadow-xs flex flex-col gap-2`,children:[(0,j.jsxs)(`div`,{className:`flex items-center justify-between border-b border-slate-100 pb-1`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs font-bold text-indigo-900`,children:[(0,j.jsx)(h,{className:`w-3.5 h-3.5 text-amber-500`}),(0,j.jsx)(`span`,{children:`Autonomous Enchantment Telemetry`})]}),(0,j.jsxs)(`span`,{className:`text-[10px] text-slate-400 font-mono`,children:[l?.length||0,` executed`]})]}),l&&l.length>0?(0,j.jsx)(`div`,{className:`flex flex-col gap-1.5 max-h-36 overflow-y-auto custom-scrollbar`,children:l.slice(0,10).map((e,t)=>(0,j.jsxs)(`div`,{className:`text-[11px] p-2 bg-indigo-50/50 border border-indigo-100 rounded flex items-center justify-between gap-2`,children:[(0,j.jsxs)(`div`,{className:`flex flex-col min-w-0`,children:[(0,j.jsxs)(`span`,{className:`font-bold text-indigo-950 font-mono text-[10px] truncate`,children:[e.tool_name,`()`]}),e.args&&Object.keys(e.args).length>0&&(0,j.jsx)(`span`,{className:`text-[9px] text-slate-500 truncate`,children:JSON.stringify(e.args).slice(0,50)})]}),(0,j.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[e.execution_time_ms!==void 0&&(0,j.jsxs)(`span`,{className:`text-[9px] text-slate-400 flex items-center gap-0.5 font-mono`,children:[(0,j.jsx)(d,{className:`w-2.5 h-2.5`}),e.execution_time_ms,`ms`]}),(0,j.jsx)(`span`,{className:`px-1.5 py-0.2 text-[9px] font-bold rounded ${e.success?`bg-emerald-100 text-emerald-800`:`bg-rose-100 text-rose-800`}`,children:e.success?`SUCCESS`:`ERR`})]})]},t))}):(0,j.jsx)(`p`,{className:`text-[11px] text-slate-400 italic m-0`,children:`No autonomous enchantments executed yet in this session.`})]})]})]}),(0,j.jsx)(`div`,{className:`bg-white border-t border-slate-200 px-4 py-2 flex items-center justify-end shrink-0`,children:(0,j.jsx)(`button`,{type:`button`,onClick:p,className:`px-4 py-1.5 bg-white hover:bg-slate-100 border-[1.5px] border-ink-black rounded font-bold text-xs text-ink-black cursor-pointer shadow-xs active:translate-y-0.5`,children:`Close`})})]})})}var R=e({default:()=>z});function z({onClose:e,onMinimize:t,isActive:n=!0,onFocus:r,zIndex:a}){let o=E(),[s,c]=(0,O.useState)(S()),[l,u]=(0,O.useState)(!1),[d,f]=(0,O.useState)(!1),[m,h]=(0,O.useState)(!1);(0,O.useEffect)(()=>{C.syncWithBackend(),C.triggerProactiveGreeting()},[]);let g=(0,O.useCallback)(()=>{e?e():w.getState().closeWindow(`companion`)},[e]),v=(0,O.useCallback)(()=>{t?t():w.getState().minimizeWindow(`companion`)},[t]),y=(0,O.useCallback)(()=>{r?r():w.getState().setActiveWindow(`companion`)},[r]),b=(0,O.useCallback)(()=>{let e=!s;c(e),T(e)},[s]),x=(0,O.useCallback)(()=>{window.confirm(`Clear conversation transcript with Princess Aurelia?`)&&C.clearTranscript()},[]),D=(0,O.useCallback)(e=>{C.setIsTyping(e)},[]),k=(0,O.useMemo)(()=>[...o.transcript].reverse().find(e=>e.sender===`princess`)||o.transcript[0],[o.transcript]),A=`Welcome back to the Spire Tower Parlor. How is your day going today? Are you making progress, or could you use a hand?`,N=k?k.isStreaming?k.text:k.text||(o.isLoading?``:A):A,P=(0,O.useMemo)(()=>k?.choiceSuggestions&&k.choiceSuggestions.length>0?k.choiceSuggestions:[...o.transcript].reverse().find(e=>e.sender===`princess`&&e.choiceSuggestions&&e.choiceSuggestions.length>0)?.choiceSuggestions,[k,o.transcript]);return(0,j.jsxs)(`div`,{onClick:y,className:`fixed inset-x-0 top-0 bottom-[40px] select-none pointer-events-none overflow-hidden font-sans`,style:{zIndex:a??(n?40:30)},children:[(0,j.jsx)(`div`,{className:`absolute inset-x-0 bottom-0 h-44 bg-gradient-to-t from-slate-950/35 via-slate-900/10 to-transparent pointer-events-none z-0`}),(0,j.jsxs)(`div`,{className:`relative w-full h-full flex flex-col justify-end pointer-events-none pb-2 sm:pb-3 px-2 sm:px-4 md:px-8`,children:[(0,j.jsxs)(`div`,{className:`relative w-full max-w-5xl lg:max-w-6xl mx-auto flex items-end justify-start pointer-events-none`,children:[(0,j.jsx)(`div`,{className:`relative z-30 shrink-0 pointer-events-auto -mr-6 sm:-mr-10 md:-mr-12 lg:-mr-14`,children:(0,j.jsx)(M,{emotion:o.activeEmotion,floor:o.currentFloor,rhythm:o.currentRhythm,activity:o.currentActivity,isLoading:o.isLoading,onClick:y})}),(0,j.jsx)(`div`,{className:`relative z-20 flex-1 min-w-0 pointer-events-auto mb-1`,children:(0,j.jsx)(F,{characterName:o.companionSettings.name||`Princess Aurelia`,emotion:o.activeEmotion,text:N,isStreaming:k?.isStreaming,isLoading:o.isLoading,choices:P,toolCalls:k?.toolCalls,onSelectChoice:e=>C.sendMessage(e),onSendMessage:e=>C.sendMessage(e),onTypingStatusChange:D,currentFloor:o.currentFloor,bondTier:o.bondTier,satchelCount:o.unlockedLetters.length,isMuted:s,onToggleMute:b,onOpenProgress:()=>u(!0),onOpenSatchel:()=>f(!0),onOpenHistory:()=>h(!0),onMinimize:v,onClose:g})})]}),(0,j.jsxs)(`div`,{className:`absolute bottom-1 right-3.5 pointer-events-none z-30 hidden md:flex flex-col items-center gap-0.5 opacity-65 select-none`,children:[(0,j.jsx)(`svg`,{className:`w-8 h-8 text-[#9cbcdb] drop-shadow-[0_0_6px_rgba(156,188,219,0.5)] rotate-6`,viewBox:`0 0 24 24`,fill:`currentColor`,children:(0,j.jsx)(`path`,{d:`M12 2 C12 7.8 7.8 12 2 12 C7.8 12 12 16.2 12 22 C12 16.2 16.2 12 22 12 C16.2 12 12 7.8 12 2 Z`})}),(0,j.jsxs)(`div`,{className:`font-mono text-[9px] text-[#7ba4c8] tracking-tight leading-tight text-center`,children:[(0,j.jsx)(`div`,{children:`AlgoSpaced (Beta)`}),(0,j.jsx)(`div`,{children:`Build Jun24 preview`})]})]})]}),l&&(0,j.jsx)(`div`,{className:`pointer-events-auto`,children:(0,j.jsx)(I,{currentFloor:o.currentFloor,totalSolved:o.totalSolved,onClose:()=>u(!1)})}),d&&(0,j.jsx)(`div`,{className:`pointer-events-auto`,children:(0,j.jsx)(L,{unlockedLetters:o.unlockedLetters,spireChronicles:o.spireChronicles,currentFloor:o.currentFloor,heroCodex:o.heroCodex,episodicEvents:o.episodicEvents,recentToolTelemetry:o.recentToolTelemetry,onRemoveCodexItem:C.removeCodexItem,onClose:()=>f(!1)})}),m&&(0,j.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/60 backdrop-blur-xs flex items-center justify-center p-3 sm:p-4 animate-in fade-in duration-200 pointer-events-auto`,onClick:()=>h(!1),children:(0,j.jsxs)(`div`,{className:`bg-[#142335] border-[3px] border-[#5a80a2] rounded-xl max-w-lg w-full h-[80%] max-h-[520px] shadow-[0_16px_40px_rgba(0,0,0,0.85)] flex flex-col overflow-hidden text-white`,onClick:e=>e.stopPropagation(),style:{boxShadow:`inset 0 0 0 1px #0a1420, inset 0 1px 0 rgba(255, 255, 255, 0.15), 0 16px 40px rgba(0, 0, 0, 0.85)`},children:[(0,j.jsxs)(`div`,{className:`bg-[#101b2a] border-b border-[#304f6f] px-4 py-2.5 flex items-center justify-between shrink-0`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,j.jsx)(p,{className:`w-4 h-4 text-[#67b1ec]`}),(0,j.jsxs)(`h4`,{className:`font-mono font-bold text-xs sm:text-sm text-[#e6f0fa] m-0`,children:[`Dialogue Transcript (`,o.transcript.length,` turns)`]})]}),(0,j.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,j.jsxs)(`button`,{type:`button`,onClick:x,className:`px-2 py-0.5 bg-rose-950/60 hover:bg-rose-900 border border-rose-700/60 rounded text-[11px] font-mono font-bold text-rose-300 hover:text-white flex items-center gap-1 cursor-pointer mr-1 transition-colors`,title:`Clear Chat History`,children:[(0,j.jsx)(i,{className:`w-3 h-3`}),(0,j.jsx)(`span`,{children:`Clear`})]}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>h(!1),className:`p-1 hover:bg-[#203a55] rounded text-[#8cb4db] hover:text-white cursor-pointer transition-colors`,title:`Close`,children:(0,j.jsx)(_,{className:`w-4 h-4`})})]})]}),(0,j.jsx)(`div`,{className:`flex-1 p-3 sm:p-4 overflow-y-auto custom-scrollbar flex flex-col gap-2.5 bg-[#0e1824]/90`,children:o.transcript.map((e,t)=>(0,j.jsxs)(`div`,{className:`p-2.5 rounded-lg border font-mono text-xs max-w-[90%] shadow-md ${e.sender===`princess`?`bg-[#182c42] border-[#3e6080] text-[#e6f0fa] self-start`:`bg-[#214365] border-[#5a8bb9] text-white self-end`}`,children:[(0,j.jsx)(`div`,{className:`text-[10px] font-bold mb-1 text-[#f6d267]`,children:e.sender===`princess`?o.companionSettings.name:`Hero`}),(0,j.jsx)(`p`,{className:`font-medium m-0 leading-relaxed whitespace-pre-wrap select-text`,children:e.text})]},e.id||t))})]})})]})}export{R as t};
|
algospaced-ui/dist/assets/ProblemSpecPanel-CoULhmZo.js
DELETED
|
@@ -1,4 +0,0 @@
|
|
| 1 |
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{$ as t,G as n,Lt as r,M as ee,P as i,Q as te,St as a,U as ne,d as o,et as re,f as s,ft as ie,j as c,o as l,ot as u,p as ae,rt as d,s as oe,xt as se,y as f,zt as p}from"./vendor-react-yvPwY2Sj.js";import{u as m}from"./index-DttZMwvA.js";import{n as h,t as g}from"./MarkdownRenderer-CWg4XXNt.js";import{n as ce}from"./ReviewQueue-BsWCZFit.js";var _=e(p(),1),v=r(),le=[`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 y(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`sol-${crypto.randomUUID()}`:`sol-${Date.now()}`}var b=({leftTab:e,onSelectLeftTab:r,mobileView:p,isNarrow:b=!1,problem:x,parsed:S,userSolution:ue,officialSolution:de,effectiveReferenceCode:C,copiedSnippet:w,onCopyText:T,saveRefError:E,aiSolutionLoading:D,aiSolutionError:O,onFetchAiSolution:fe,explainLoading:k,explainError:A,explanationText:j,onExplainCode:pe,activeReview:M,onUpdateSolutions:N})=>{let[me,P]=(0,_.useState)(!1),[F,I]=(0,_.useState)(()=>x.id||x.name),[L,R]=(0,_.useState)(0),[z,B]=(0,_.useState)(!1),[V,H]=(0,_.useState)(null),[U,W]=(0,_.useState)({name:``,pattern:`Arrays & Hashing`,time_complexity:`O(N)`,space_complexity:`O(1)`,code:``,explanation:``,is_optimal:!1}),[G,K]=(0,_.useState)(!1),[q,J]=(0,_.useState)(null),Y=x.id||x.name;F!==Y&&(I(Y),P(!1),R(0),B(!1),H(null),J(null));let X=ce(x,de,ue),Z=L<X.length?L:0,Q=X[Z];(0,_.useEffect)(()=>{if(q){let e=setTimeout(()=>J(null),3500);return()=>clearTimeout(e)}},[q]);let he=async()=>{if(!U.name.trim()){J({type:`error`,message:`Solution name cannot be empty.`});return}if(!U.code.trim()){J({type:`error`,message:`Solution code cannot be empty.`});return}K(!0),J(null);try{let e;if(V)e=X.map(e=>e.id===V?{...e,name:U.name.trim(),pattern:U.pattern.trim()||`General Algorithm`,time_complexity:U.time_complexity.trim()||`O(N)`,space_complexity:U.space_complexity.trim()||`O(1)`,code:U.code,explanation:U.explanation.trim(),is_optimal:U.is_optimal}:U.is_optimal&&e.id!==V?{...e,is_optimal:!1}:e);else{let t={id:y(),name:U.name.trim(),pattern:U.pattern.trim()||`General Algorithm`,time_complexity:U.time_complexity.trim()||`O(N)`,space_complexity:U.space_complexity.trim()||`O(1)`,code:U.code,explanation:U.explanation.trim(),is_optimal:U.is_optimal||X.length===0};e=t.is_optimal?[...X.map(e=>({...e,is_optimal:!1})),t]:[...X,t]}let t=e.find(e=>e.is_optimal)||e[0];x.id&&await m(x.id,e,t?.time_complexity,t?.space_complexity,x),N?.(e),J({type:`success`,message:V?`Solution updated successfully!`:`New solution added to problem dossier!`}),B(!1),H(null),R(V?Z:e.length-1)}catch(e){let t=e instanceof Error?e.message:`Failed to save solution.`;J({type:`error`,message:t})}finally{K(!1)}},ge=async e=>{if(X.length<=1){J({type:`error`,message:`Problem must have at least one solution.`});return}if(window.confirm(`Are you sure you want to remove this solution?`)){K(!0);try{let t=X.filter(t=>t.id!==e);!t.some(e=>e.is_optimal)&&t.length>0&&(t[0].is_optimal=!0);let n=t.find(e=>e.is_optimal)||t[0];x.id&&await m(x.id,t,n?.time_complexity,n?.space_complexity,x),N?.(t),R(0),J({type:`success`,message:`Solution removed successfully.`})}catch(e){let t=e instanceof Error?e.message:`Failed to delete solution.`;J({type:`error`,message:t})}finally{K(!1)}}},$=e=>`cursor-pointer font-arcade text-[7.5px] min-[400px]:text-[8px] sm:text-[8.5px] transition-all flex items-center justify-center gap-1 sm:gap-1.5 focus:outline-none focus-visible:ring-2 focus-visible:ring-ink-black select-none whitespace-nowrap shrink-0 ${e?`h-10 px-2 sm:px-2.5 bg-paper-white text-ink-black font-extrabold border-t-2 border-x-2 border-b-0 border-ink-black relative z-10 -mb-[2px] pb-[10px] shadow-[0_-2px_0_0_rgba(30,41,59,0.06)] after:content-[''] after:absolute after:-bottom-[2px] after:left-0 after:right-0 after:h-[2.5px] after:bg-paper-white after:z-10`:`h-9 px-2 sm:px-2.5 bg-[#e8e4da] text-slate-700 hover:bg-[#efece3] hover:text-ink-black font-bold border-2 border-ink-black relative z-0 mb-0`}`;return(0,v.jsxs)(`div`,{className:`w-full ${b?`flex flex-1`:`lg:w-[49%] flex`} flex-col bg-paper-white border-b-[3px] lg:border-b-0 ${b?``:`lg:border-r-[3px]`} border-ink-black overflow-hidden ${b&&p!==`spec`&&p!==`ref`?`hidden`:`flex`}`,children:[(0,v.jsxs)(`div`,{className:`shrink-0 bg-[#f4f1ea] border-b-2 border-ink-black px-1.5 sm:px-2.5 pt-2 flex items-end gap-1 relative z-10 overflow-x-auto no-scrollbar`,children:[(0,v.jsxs)(`button`,{onClick:()=>r(`spec`),className:$(e===`spec`),children:[(0,v.jsx)(te,{className:`w-3 h-3 text-purple-700 shrink-0`}),(0,v.jsx)(`span`,{children:b?`SPEC`:`SPECIFICATIONS`})]}),(0,v.jsxs)(`button`,{onClick:()=>r(`ref`),className:$(e===`ref`),children:[(0,v.jsx)(u,{className:`w-3 h-3 text-blue-700 shrink-0`}),(0,v.jsx)(`span`,{children:b?`SOL (${X.length})`:`SOLUTIONS (${X.length})`})]}),(0,v.jsxs)(`button`,{onClick:()=>r(`leitner`),className:$(e===`leitner`),children:[(0,v.jsx)(s,{className:`w-3 h-3 text-emerald-700 shrink-0`}),(0,v.jsx)(`span`,{className:`whitespace-nowrap`,children:b?`FSRS`:`FSRS STATS`})]})]}),(0,v.jsxs)(`div`,{className:`flex-1 overflow-y-auto no-scrollbar p-4 sm:p-5 space-y-4`,children:[e===`spec`&&(0,v.jsxs)(`div`,{className:`space-y-4`,children:[(0,v.jsxs)(`div`,{className:`p-4 bg-white border-2 border-ink-black shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] space-y-3.5`,children:[(0,v.jsx)(`div`,{children:(0,v.jsx)(`h2`,{className:`text-base sm:text-lg font-extrabold text-ink-black font-headline-md leading-tight m-0 select-text`,children:x.name||`Algorithm Problem`})}),S.description&&(0,v.jsxs)(`div`,{className:`pt-3.5 border-t border-slate-200`,children:[(0,v.jsxs)(`div`,{className:`text-[9px] font-arcade text-trash-gray uppercase font-bold mb-2 flex items-center gap-1`,children:[(0,v.jsx)(a,{className:`w-3 h-3 text-primary`}),`PROBLEM DESCRIPTION`]}),(0,v.jsx)(`div`,{className:`font-sans text-xs sm:text-[13px] text-slate-800 leading-relaxed space-y-2 font-medium`,children:S.description.split(`
|
| 2 |
-
`).map((e,t)=>e.trim()?(0,v.jsx)(`p`,{className:`m-0 leading-relaxed whitespace-pre-wrap select-text`,children:h(e)},t):(0,v.jsx)(`div`,{className:`h-1.5`},t))})]}),S.examples.length>0&&(0,v.jsxs)(`div`,{className:`pt-3.5 border-t border-slate-200 space-y-2.5`,children:[(0,v.jsxs)(`div`,{className:`text-[9px] font-arcade text-trash-gray uppercase font-bold flex items-center gap-1.5`,children:[(0,v.jsx)(l,{className:`w-3 h-3 text-amber-500`}),`EXAMPLES (`,S.examples.length,`)`]}),(0,v.jsx)(`div`,{className:`space-y-2.5`,children:S.examples.map((e,t)=>(0,v.jsxs)(`div`,{className:`p-3 bg-slate-50 border border-slate-200 space-y-2 text-xs`,children:[(0,v.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,v.jsxs)(`span`,{className:`font-arcade text-[9px] font-bold text-primary`,children:[`EXAMPLE `,t+1]}),e.input&&(0,v.jsxs)(`button`,{onClick:()=>T(e.input,`ex-${t}`),className:`px-2 py-0.5 bg-white hover:bg-slate-100 border border-ink-black text-[9px] font-arcade text-ink-black flex items-center gap-1 cursor-pointer`,title:`Copy input data`,children:[(0,v.jsx)(d,{className:`w-2.5 h-2.5`}),w===`ex-${t}`?`COPIED!`:`COPY`]})]}),e.input&&(0,v.jsxs)(`div`,{className:`space-y-1`,children:[(0,v.jsx)(`span`,{className:`text-[9px] font-arcade text-trash-gray font-bold uppercase block`,children:`Input:`}),(0,v.jsx)(`div`,{className:`bg-[#1E293B] text-[#4ADE80] font-code-mono p-2 border border-ink-black text-[11px] break-all select-text`,children:e.input})]}),e.output&&(0,v.jsxs)(`div`,{className:`space-y-1`,children:[(0,v.jsx)(`span`,{className:`text-[9px] font-arcade text-trash-gray font-bold uppercase block`,children:`Output:`}),(0,v.jsx)(`div`,{className:`bg-[#1E293B] text-[#4ADE80] font-code-mono p-2 border border-ink-black text-[11px] break-all select-text`,children:e.output})]}),e.explanation&&(0,v.jsxs)(`div`,{className:`text-[11px] font-sans text-slate-600 bg-white p-2 border border-slate-200`,children:[(0,v.jsx)(`span`,{className:`font-bold text-slate-700`,children:`Explanation: `}),h(e.explanation)]})]},t))})]}),S.constraints.length>0&&(0,v.jsxs)(`div`,{className:`pt-3.5 border-t border-slate-200`,children:[(0,v.jsx)(`div`,{className:`text-[9px] font-arcade text-trash-gray uppercase font-bold mb-2`,children:`CONSTRAINTS`}),(0,v.jsx)(`ul`,{className:`space-y-1.5 list-none m-0 p-0`,children:S.constraints.map((e,t)=>(0,v.jsxs)(`li`,{className:`flex items-start gap-2 text-xs`,children:[(0,v.jsx)(`span`,{className:`text-primary font-bold select-none`,children:`•`}),(0,v.jsx)(`code`,{className:`bg-slate-100 text-ink-black font-code-mono px-2 py-0.5 border border-slate-300 text-[11px] select-text`,children:e})]},t))})]})]}),me?(0,v.jsxs)(`div`,{className:`p-3 bg-amber-50 border-2 border-ink-black shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] flex flex-wrap items-center justify-between gap-2`,children:[(0,v.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,v.jsx)(l,{className:`w-4 h-4 text-amber-600 shrink-0`}),(0,v.jsx)(`span`,{className:`font-arcade text-[9px] font-bold text-ink-black tracking-wide uppercase`,children:`OPTIMAL TARGET:`}),(0,v.jsxs)(`code`,{className:`bg-[#1E293B] text-[#4ADE80] font-code-mono px-2 py-0.5 text-[11px] border border-ink-black font-bold`,children:[`T: `,x.optimal_time||`O(N)`]}),(0,v.jsxs)(`code`,{className:`bg-[#1E293B] text-[#4ADE80] font-code-mono px-2 py-0.5 text-[11px] border border-ink-black font-bold`,children:[`S: `,x.optimal_space||`O(1)`]})]}),(0,v.jsxs)(`button`,{type:`button`,onClick:()=>P(!1),className:`px-2 py-0.5 bg-white hover:bg-slate-100 border border-ink-black font-arcade text-[8px] text-trash-gray hover:text-ink-black cursor-pointer flex items-center gap-1`,title:`Conceal target complexity`,children:[(0,v.jsx)(re,{className:`w-2.5 h-2.5`}),(0,v.jsx)(`span`,{children:`HIDE`})]})]}):(0,v.jsxs)(`div`,{className:`p-3 bg-amber-50/70 border-2 border-ink-black shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] flex items-center justify-between gap-2`,children:[(0,v.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,v.jsx)(ne,{className:`w-4 h-4 text-amber-700 shrink-0`}),(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`span`,{className:`font-arcade text-[9px] font-bold text-ink-black tracking-wide uppercase block`,children:`OPTIMAL COMPLEXITY TARGET`}),(0,v.jsx)(`span`,{className:`text-[10px] font-sans text-slate-600 font-semibold`,children:`Hidden to test active recall before coding`})]})]}),(0,v.jsxs)(`button`,{type:`button`,onClick:()=>P(!0),className:`px-2.5 py-1 bg-white hover:bg-amber-100 border-2 border-ink-black font-arcade text-[8.5px] font-bold text-ink-black shadow-[1.5px_1.5px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none transition-all cursor-pointer flex items-center gap-1.5 shrink-0`,title:`Click to reveal target time and space complexity`,children:[(0,v.jsx)(t,{className:`w-3 h-3 text-amber-700`}),(0,v.jsx)(`span`,{children:`REVEAL TARGET`})]})]})]}),e===`ref`&&(0,v.jsxs)(`div`,{className:`space-y-4`,children:[q&&(0,v.jsxs)(`div`,{className:`p-2.5 border-2 border-ink-black text-xs font-bold flex items-center justify-between shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] ${q.type===`success`?`bg-emerald-100 text-emerald-900 border-emerald-700`:`bg-rose-100 text-rose-900 border-rose-700`}`,children:[(0,v.jsxs)(`div`,{className:`flex items-center gap-2`,children:[q.type===`success`?(0,v.jsx)(ie,{className:`w-4 h-4 text-emerald-700 shrink-0`}):(0,v.jsx)(o,{className:`w-4 h-4 text-rose-700 shrink-0`}),(0,v.jsx)(`span`,{children:q.message})]}),(0,v.jsx)(`button`,{type:`button`,onClick:()=>J(null),className:`text-slate-600 hover:text-ink-black cursor-pointer`,children:(0,v.jsx)(oe,{className:`w-3.5 h-3.5`})})]}),(0,v.jsxs)(`div`,{className:`flex items-center gap-1 p-1 bg-slate-200/90 border-2 border-ink-black shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] overflow-x-auto no-scrollbar`,children:[X.map((e,t)=>(0,v.jsxs)(`button`,{type:`button`,onClick:()=>{R(t),B(!1),H(null)},className:`py-1 px-2 rounded-full font-arcade text-[8px] font-bold flex items-center justify-center gap-1 border-2 border-ink-black transition-all cursor-pointer whitespace-nowrap shrink-0 ${Z===t&&!z&&!V?`bg-sky-600 text-white shadow-[1px_1px_0px_0px_rgba(30,41,59,1)] -translate-y-0.5`:`bg-white text-ink-black hover:bg-sky-50 shadow-none`}`,title:e.name?`${e.name} (${e.pattern||`Algorithm`})`:`Solution ${t+1}`,children:[e.is_optimal?(0,v.jsx)(f,{className:`w-3 h-3 text-amber-300`}):(0,v.jsx)(a,{className:`w-3 h-3`}),(0,v.jsx)(`span`,{children:`Sol ${t+1}`}),e.is_optimal&&(0,v.jsx)(`span`,{className:`text-[6.5px] px-1 py-0.2 bg-amber-300 text-ink-black border border-ink-black font-extrabold rounded-full tracking-tight`,children:`OPTIMAL`})]},e.id||t)),(0,v.jsx)(`button`,{type:`button`,onClick:()=>{B(!0),H(null),W({name:`Method ${X.length+1}`,pattern:`Arrays & Hashing`,time_complexity:`O(N)`,space_complexity:`O(1)`,code:``,explanation:``,is_optimal:!1})},className:`h-6 w-6 rounded-full font-arcade text-[9px] font-bold flex items-center justify-center border-2 border-ink-black cursor-pointer shrink-0 active:translate-y-0.5 transition-all shadow-[1px_1px_0px_0px_rgba(30,41,59,1)] ${z?`bg-emerald-600 text-white`:`bg-amber-300 text-ink-black hover:bg-amber-200`}`,title:`Add another solution / method for this problem`,"aria-label":`Add Solution`,children:(0,v.jsx)(ee,{className:`w-3 h-3 stroke-[2.5]`})})]}),z||V?(0,v.jsxs)(`div`,{className:`p-4 bg-white border-2 border-ink-black shadow-[3px_3px_0px_0px_rgba(30,41,59,1)] space-y-3.5`,children:[(0,v.jsxs)(`div`,{className:`flex items-center justify-between pb-2 border-b-2 border-dashed border-ink-black`,children:[(0,v.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,v.jsx)(i,{className:`w-4 h-4 text-purple-700`}),(0,v.jsx)(`span`,{className:`font-arcade text-[10px] font-bold text-ink-black uppercase`,children:V?`EDIT SOLUTION`:`ADD NEW SOLUTION / METHOD`})]}),(0,v.jsx)(`button`,{type:`button`,onClick:()=>{B(!1),H(null)},className:`text-xs font-arcade text-trash-gray hover:text-rose-600 cursor-pointer font-bold`,children:`CANCEL`})]}),(0,v.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[(0,v.jsxs)(`div`,{className:`space-y-1`,children:[(0,v.jsx)(`label`,{className:`font-arcade text-[8.5px] font-bold text-trash-gray uppercase block`,children:`Solution / Method Name`}),(0,v.jsx)(`input`,{type:`text`,value:U.name,onChange:e=>W({...U,name:e.target.value}),placeholder:`e.g. One-Pass Hash Map, Two Pointers`,className:`w-full p-2 border-2 border-ink-black text-xs font-bold bg-[#fdf8e1] focus:outline-none focus:bg-white`})]}),(0,v.jsxs)(`div`,{className:`space-y-1`,children:[(0,v.jsx)(`label`,{className:`font-arcade text-[8.5px] font-bold text-trash-gray uppercase block`,children:`Pattern / Strategy`}),(0,v.jsx)(`select`,{value:U.pattern,onChange:e=>W({...U,pattern:e.target.value}),className:`w-full p-2 border-2 border-ink-black text-xs font-bold bg-[#fdf8e1] focus:outline-none focus:bg-white`,children:le.map(e=>(0,v.jsx)(`option`,{value:e,children:e},e))})]}),(0,v.jsxs)(`div`,{className:`space-y-1`,children:[(0,v.jsx)(`label`,{className:`font-arcade text-[8.5px] font-bold text-trash-gray uppercase block`,children:`Time Complexity`}),(0,v.jsx)(`input`,{type:`text`,value:U.time_complexity,onChange:e=>W({...U,time_complexity:e.target.value}),placeholder:`e.g. O(N), O(N log N), O(N^2)`,className:`w-full p-2 border-2 border-ink-black text-xs font-code-mono font-bold bg-[#fdf8e1] focus:outline-none focus:bg-white`})]}),(0,v.jsxs)(`div`,{className:`space-y-1`,children:[(0,v.jsx)(`label`,{className:`font-arcade text-[8.5px] font-bold text-trash-gray uppercase block`,children:`Space Complexity`}),(0,v.jsx)(`input`,{type:`text`,value:U.space_complexity,onChange:e=>W({...U,space_complexity:e.target.value}),placeholder:`e.g. O(1), O(N)`,className:`w-full p-2 border-2 border-ink-black text-xs font-code-mono font-bold bg-[#fdf8e1] focus:outline-none focus:bg-white`})]})]}),(0,v.jsxs)(`div`,{className:`space-y-1`,children:[(0,v.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,v.jsx)(`label`,{className:`font-arcade text-[8.5px] font-bold text-trash-gray uppercase`,children:`Python Reference Code`}),(0,v.jsx)(`button`,{type:`button`,onClick:()=>W({...U,code:C}),className:`text-[8.5px] font-arcade text-sky-700 hover:underline cursor-pointer`,children:`Paste Current Code`})]}),(0,v.jsx)(`textarea`,{rows:8,value:U.code,onChange:e=>W({...U,code:e.target.value}),placeholder:`class Solution:
|
| 3 |
-
def solve(self, nums):
|
| 4 |
-
...`,className:`w-full p-2.5 border-2 border-ink-black bg-[#1E293B] text-[#4ADE80] font-code-mono text-xs focus:outline-none no-scrollbar`})]}),(0,v.jsxs)(`div`,{className:`space-y-1`,children:[(0,v.jsx)(`label`,{className:`font-arcade text-[8.5px] font-bold text-trash-gray uppercase block`,children:`Intuition / How to Solve (Optional)`}),(0,v.jsx)(`textarea`,{rows:3,value:U.explanation,onChange:e=>W({...U,explanation:e.target.value}),placeholder:`Key insight, trade-offs, and state tracking notes...`,className:`w-full p-2 border-2 border-ink-black text-xs bg-[#fdf8e1] focus:outline-none focus:bg-white no-scrollbar`})]}),(0,v.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,v.jsx)(`input`,{type:`checkbox`,id:`is_optimal_solution`,checked:U.is_optimal,onChange:e=>W({...U,is_optimal:e.target.checked}),className:`w-4 h-4 border-2 border-ink-black rounded cursor-pointer accent-emerald-600`}),(0,v.jsx)(`label`,{htmlFor:`is_optimal_solution`,className:`font-arcade text-[9px] font-bold text-ink-black cursor-pointer`,children:`SET AS OPTIMAL / PRIMARY APPROACH FOR THIS PROBLEM`})]}),(0,v.jsxs)(`div`,{className:`flex items-center justify-end gap-2 pt-2 border-t-2 border-dashed border-ink-black`,children:[(0,v.jsx)(`button`,{type:`button`,onClick:()=>{B(!1),H(null)},className:`px-3 py-1.5 bg-slate-100 hover:bg-slate-200 border-2 border-ink-black font-arcade text-[9px] font-bold text-ink-black cursor-pointer`,children:`CANCEL`}),(0,v.jsxs)(`button`,{type:`button`,disabled:G,onClick:he,className:`px-4 py-1.5 bg-emerald-500 hover:bg-emerald-400 border-2 border-ink-black font-arcade text-[9px] font-bold text-white shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none transition-all cursor-pointer disabled:opacity-50 flex items-center gap-1.5`,children:[G&&(0,v.jsx)(c,{className:`w-3 h-3 animate-spin`}),(0,v.jsx)(`span`,{children:V?`UPDATE SOLUTION`:`SAVE SOLUTION`})]})]})]}):Q?(0,v.jsxs)(`div`,{className:`space-y-3.5`,children:[(0,v.jsxs)(`div`,{className:`p-4 bg-white border-2 border-ink-black shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] space-y-3.5`,children:[(0,v.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 pb-3 border-b border-slate-200`,children:[(0,v.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap min-w-0`,children:[(0,v.jsx)(`h3`,{className:`font-headline-md font-extrabold text-sm sm:text-base text-ink-black m-0 select-text break-words`,children:Q.name||`Solution ${Z+1}`}),Q.is_optimal&&(0,v.jsx)(`span`,{className:`px-2 py-0.5 bg-amber-300 border border-ink-black font-arcade text-[8px] font-bold text-ink-black shadow-[1px_1px_0px_0px_rgba(30,41,59,1)] shrink-0`,children:`★ OPTIMAL`})]}),(0,v.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap sm:ml-auto`,children:[(0,v.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,v.jsx)(`span`,{className:`font-arcade text-[8px] text-trash-gray uppercase`,children:`Pattern:`}),(0,v.jsx)(`span`,{className:`px-2 py-0.5 bg-purple-50 border border-purple-300 font-arcade text-[8.5px] text-purple-800 font-bold`,children:Q.pattern||`General Algorithm`})]}),(0,v.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,v.jsxs)(`code`,{className:`bg-[#1E293B] text-[#4ADE80] font-code-mono px-1.5 py-0.5 text-[11px] border border-ink-black font-bold`,children:[`T: `,Q.time_complexity||`O(N)`]}),(0,v.jsxs)(`code`,{className:`bg-[#1E293B] text-[#4ADE80] font-code-mono px-1.5 py-0.5 text-[11px] border border-ink-black font-bold`,children:[`S: `,Q.space_complexity||`O(1)`]})]}),(0,v.jsxs)(`div`,{className:`flex items-center gap-1 ml-auto`,children:[(0,v.jsxs)(`button`,{type:`button`,onClick:()=>{H(Q.id),B(!1),W({name:Q.name,pattern:Q.pattern,time_complexity:Q.time_complexity,space_complexity:Q.space_complexity,code:Q.code,explanation:Q.explanation||``,is_optimal:!!Q.is_optimal})},className:`px-2 py-1 bg-white hover:bg-slate-100 border border-ink-black text-ink-black font-arcade text-[8px] font-bold flex items-center gap-1 cursor-pointer`,title:`Edit this solution`,children:[(0,v.jsx)(i,{className:`w-3 h-3 text-slate-700`}),(0,v.jsx)(`span`,{className:`hidden sm:inline`,children:`EDIT`})]}),X.length>1&&(0,v.jsx)(`button`,{type:`button`,onClick:()=>ge(Q.id),className:`px-1.5 py-1 bg-white hover:bg-rose-50 border border-ink-black text-rose-700 font-arcade text-[8px] font-bold flex items-center gap-1 cursor-pointer`,title:`Delete this solution`,children:(0,v.jsx)(ae,{className:`w-3 h-3`})})]})]})]}),Q.code?(0,v.jsxs)(`div`,{className:`border border-ink-black bg-[#0f172a] overflow-hidden`,children:[(0,v.jsxs)(`div`,{className:`bg-[#1e293b] px-2.5 sm:px-3 py-1.5 border-b border-ink-black flex items-center justify-between gap-1.5 flex-wrap min-w-0`,children:[(0,v.jsx)(`span`,{className:`font-arcade text-[8px] text-slate-300 font-bold uppercase truncate min-w-0 flex-1`,children:b?`PYTHON 3`:`PYTHON 3 IMPLEMENTATION`}),(0,v.jsxs)(`div`,{className:`flex items-center gap-1.5 shrink-0`,children:[(0,v.jsxs)(`button`,{type:`button`,onClick:()=>pe(Q.code,Q.pattern,Q.time_complexity,Q.space_complexity),disabled:k,className:`px-2 py-0.5 bg-purple-50 hover:bg-purple-100 text-purple-800 border border-ink-black text-[9px] font-arcade font-bold flex items-center gap-1 cursor-pointer shrink-0 disabled:opacity-50 active:translate-y-0.5 transition-all`,title:`Explain this solution with AI`,children:[k?(0,v.jsx)(c,{className:`w-2.5 h-2.5 animate-spin text-purple-700`}):(0,v.jsx)(f,{className:`w-2.5 h-2.5 text-purple-600`}),(0,v.jsx)(`span`,{children:`Explain✦`})]}),(0,v.jsxs)(`button`,{onClick:()=>T(Q.code,`sol-${Q.id}`),className:`px-2 py-0.5 bg-white hover:bg-slate-100 text-ink-black border border-ink-black text-[9px] font-arcade font-bold flex items-center gap-1 cursor-pointer shrink-0 active:translate-y-0.5 transition-all`,title:`Copy solution code`,children:[(0,v.jsx)(d,{className:`w-2.5 h-2.5`}),w===`sol-${Q.id}`?`COPIED!`:`COPY`]})]})]}),(0,v.jsx)(`div`,{className:`p-3 text-xs overflow-x-auto max-h-80 no-scrollbar`,children:(0,v.jsx)(`pre`,{className:`font-code-mono text-[#4ADE80] text-[11px] leading-relaxed select-text m-0`,children:(0,v.jsx)(`code`,{children:Q.code})})})]}):(0,v.jsxs)(`div`,{className:`p-4 bg-amber-50 border border-dashed border-amber-300 text-center space-y-3`,children:[(0,v.jsx)(`p`,{className:`text-xs font-sans text-stone-700`,children:`No code implementation archived for this solution yet.`}),(0,v.jsx)(`button`,{onClick:fe,disabled:D,className:`px-4 py-2 bg-purple-600 hover:bg-purple-700 text-white font-arcade text-[9px] font-bold border-2 border-ink-black shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none transition-all cursor-pointer inline-flex items-center gap-2 disabled:opacity-50`,children:D?(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)(c,{className:`w-3.5 h-3.5 animate-spin`}),(0,v.jsx)(`span`,{children:`Generating solution...`})]}):(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)(f,{className:`w-3.5 h-3.5 text-amber-300`}),(0,v.jsx)(`span`,{children:`Generate solution`})]})}),O&&(0,v.jsx)(`div`,{className:`text-xs text-rose-600 font-medium`,children:O})]}),Q.explanation&&(0,v.jsxs)(`div`,{className:`pt-3.5 border-t border-slate-200 space-y-1.5 select-text`,children:[(0,v.jsx)(`span`,{className:`font-arcade text-[8.5px] text-trash-gray uppercase font-bold block`,children:`SOLUTION INTUITION & STRATEGY:`}),(0,v.jsx)(g,{content:Q.explanation})]})]}),Q.code&&(0,v.jsxs)(`div`,{className:`space-y-3`,children:[A&&(0,v.jsx)(`div`,{className:`p-3 border-2 border-rose-500 bg-rose-50 text-rose-800 text-xs font-semibold`,children:A}),j&&(0,v.jsxs)(`div`,{className:`p-4 bg-white border-2 border-ink-black shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] space-y-2 select-text`,children:[(0,v.jsxs)(`div`,{className:`flex items-center gap-1.5 pb-2 border-b-2 border-dashed border-ink-black`,children:[(0,v.jsx)(se,{className:`w-4 h-4 text-purple-600`}),(0,v.jsxs)(`span`,{className:`font-arcade text-[9px] font-bold text-ink-black uppercase`,children:[`Gemini Code Breakdown (`,Q.name,`)`]})]}),(0,v.jsx)(`div`,{className:`max-h-96 overflow-y-auto no-scrollbar pt-1 select-text`,children:(0,v.jsx)(g,{content:j})})]})]})]}):null,E&&(0,v.jsxs)(`div`,{className:`p-2.5 border-2 border-rose-500 bg-rose-50 text-rose-800 text-xs font-bold flex items-center gap-2 shadow-[2px_2px_0px_0px_rgba(244,63,94,1)]`,children:[(0,v.jsx)(o,{className:`w-4 h-4 text-rose-600 shrink-0`}),(0,v.jsx)(`div`,{className:`flex-1`,children:E})]})]}),e===`leitner`&&(0,v.jsxs)(`div`,{className:`space-y-4`,children:[(0,v.jsxs)(`div`,{className:`p-4 bg-white border-2 border-ink-black shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] space-y-3`,children:[(0,v.jsxs)(`div`,{className:`text-[9px] font-arcade text-trash-gray uppercase font-bold flex items-center gap-1.5`,children:[(0,v.jsx)(n,{className:`w-3 h-3 text-purple-600`}),`SPACED REPETITION PROGRESSION`]}),(0,v.jsx)(`div`,{className:`space-y-2`,children:[{state:0,label:`NEW`,color:`#3b82f6`},{state:1,label:`LEARNING`,color:`#f59e0b`},{state:2,label:`REVIEW`,color:`#10b981`},{state:3,label:`RELEARNING`,color:`#ef4444`}].map(e=>{let t=(M.fsrs_state??0)===e.state;return(0,v.jsxs)(`div`,{className:`p-2.5 border-2 border-ink-black flex items-center justify-between transition-all ${t?`bg-amber-100 shadow-[3px_3px_0px_0px_rgba(30,41,59,1)] translate-x-1 font-bold`:`bg-slate-50 opacity-70`}`,children:[(0,v.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,v.jsx)(`span`,{className:`w-5 h-5 border border-ink-black flex items-center justify-center font-arcade text-[9px] text-white font-bold`,style:{backgroundColor:e.color},children:e.state}),(0,v.jsx)(`span`,{className:`font-arcade text-[9px] text-ink-black`,children:e.label})]}),(0,v.jsx)(`div`,{className:`flex items-center gap-2`,children:t&&(0,v.jsx)(`span`,{className:`px-1.5 py-0.5 bg-emerald-500 text-white font-arcade text-[7px] border border-ink-black font-bold`,children:`CURRENT`})})]},e.state)})})]}),(0,v.jsxs)(`div`,{className:`p-4 bg-white border-2 border-ink-black shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] space-y-3`,children:[(0,v.jsxs)(`div`,{className:`text-[9px] font-arcade text-trash-gray uppercase font-bold flex items-center gap-1.5`,children:[(0,v.jsx)(s,{className:`w-3 h-3 text-emerald-600`}),`PERFORMANCE METRICS`]}),(0,v.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,v.jsxs)(`div`,{className:`p-2.5 bg-slate-50 border border-ink-black`,children:[(0,v.jsx)(`span`,{className:`font-arcade text-[8px] text-trash-gray block uppercase`,children:`Total Reviews`}),(0,v.jsx)(`span`,{className:`font-headline-md text-lg font-bold text-ink-black`,children:M.total_attempts||0})]}),(0,v.jsxs)(`div`,{className:`p-2.5 bg-slate-50 border border-ink-black`,children:[(0,v.jsx)(`span`,{className:`font-arcade text-[8px] text-trash-gray block uppercase`,children:`Correct Recall`}),(0,v.jsx)(`span`,{className:`font-headline-md text-lg font-bold text-emerald-600`,children:M.times_correct||0})]})]}),(0,v.jsxs)(`div`,{className:`text-xs font-sans text-slate-600 pt-1`,children:[`Next Due Date:`,` `,(0,v.jsx)(`span`,{className:`font-code-mono font-bold text-ink-black`,children:M.next_review?new Date(M.next_review).toLocaleDateString():`Today`})]})]})]})]})]})};export{b as ProblemSpecPanel};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
algospaced-ui/dist/assets/ProblemSpecPanel-Df-cRYRz.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{$ as t,A as n,G as ee,Lt as r,N as i,Q as a,St as o,U as te,d as s,et as ne,f as c,ft as re,j as ie,o as l,ot as ae,p as oe,rt as u,s as se,xt as ce,y as d,zt as f}from"./vendor-react-qmUj3JUi.js";import{u as p}from"./index-DYMSjoUb.js";import{n as m,t as h}from"./MarkdownRenderer-CC5nUs7-.js";import{n as le}from"./ReviewQueue-C250a4ib.js";var g=e(f(),1),_=r(),ue=[`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 v(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`sol-${crypto.randomUUID()}`:`sol-${Date.now()}`}var y=({leftTab:e,onSelectLeftTab:r,mobileView:f,isNarrow:y=!1,problem:b,parsed:x,userSolution:de,officialSolution:fe,effectiveReferenceCode:pe,copiedSnippet:S,onCopyText:C,saveRefError:w,aiSolutionLoading:T,aiSolutionError:E,onFetchAiSolution:D,explainLoading:O,explainError:k,explanationText:A,onExplainCode:me,activeReview:j,onUpdateSolutions:M})=>{let[N,P]=(0,g.useState)(!1),[F,I]=(0,g.useState)(()=>b.id||b.name),[L,R]=(0,g.useState)(0),[z,B]=(0,g.useState)(!1),[V,H]=(0,g.useState)(null),[U,W]=(0,g.useState)({name:``,pattern:`Arrays & Hashing`,time_complexity:`O(N)`,space_complexity:`O(1)`,code:``,explanation:``,is_optimal:!1}),[G,K]=(0,g.useState)(!1),[q,J]=(0,g.useState)(null),Y=b.id||b.name;F!==Y&&(I(Y),P(!1),R(0),B(!1),H(null),J(null));let X=le(b,fe,de),Z=L<X.length?L:0,Q=X[Z];(0,g.useEffect)(()=>{if(q){let e=setTimeout(()=>J(null),3500);return()=>clearTimeout(e)}},[q]);let he=async()=>{if(!U.name.trim()){J({type:`error`,message:`Solution name cannot be empty.`});return}if(!U.code.trim()){J({type:`error`,message:`Solution code cannot be empty.`});return}K(!0),J(null);try{let e;if(V)e=X.map(e=>e.id===V?{...e,name:U.name.trim(),pattern:U.pattern.trim()||`General Algorithm`,time_complexity:U.time_complexity.trim()||`O(N)`,space_complexity:U.space_complexity.trim()||`O(1)`,code:U.code,explanation:U.explanation.trim(),is_optimal:U.is_optimal}:U.is_optimal&&e.id!==V?{...e,is_optimal:!1}:e);else{let t={id:v(),name:U.name.trim(),pattern:U.pattern.trim()||`General Algorithm`,time_complexity:U.time_complexity.trim()||`O(N)`,space_complexity:U.space_complexity.trim()||`O(1)`,code:U.code,explanation:U.explanation.trim(),is_optimal:U.is_optimal||X.length===0};e=t.is_optimal?[...X.map(e=>({...e,is_optimal:!1})),t]:[...X,t]}let t=e.find(e=>e.is_optimal)||e[0];b.id&&await p(b.id,e,t?.time_complexity,t?.space_complexity,b),M?.(e),J({type:`success`,message:V?`Solution updated successfully!`:`New solution added to problem dossier!`}),B(!1),H(null),R(V?Z:e.length-1)}catch(e){let t=e instanceof Error?e.message:`Failed to save solution.`;J({type:`error`,message:t})}finally{K(!1)}},ge=async e=>{if(X.length<=1){J({type:`error`,message:`Problem must have at least one solution.`});return}if(window.confirm(`Are you sure you want to remove this solution?`)){K(!0);try{let t=X.filter(t=>t.id!==e);!t.some(e=>e.is_optimal)&&t.length>0&&(t[0].is_optimal=!0);let n=t.find(e=>e.is_optimal)||t[0];b.id&&await p(b.id,t,n?.time_complexity,n?.space_complexity,b),M?.(t),R(0),J({type:`success`,message:`Solution removed successfully.`})}catch(e){let t=e instanceof Error?e.message:`Failed to delete solution.`;J({type:`error`,message:t})}finally{K(!1)}}},$=e=>`cursor-pointer font-arcade text-[7.5px] min-[400px]:text-[8px] sm:text-[8.5px] transition-all flex items-center justify-center gap-1 sm:gap-1.5 focus:outline-none focus-visible:ring-2 focus-visible:ring-ink-black select-none whitespace-nowrap shrink-0 ${e?`h-10 px-2 sm:px-2.5 bg-paper-white text-ink-black font-extrabold border-t-2 border-x-2 border-b-0 border-ink-black relative z-10 -mb-[2px] pb-[10px] shadow-[0_-2px_0_0_rgba(30,41,59,0.06)] after:content-[''] after:absolute after:-bottom-[2px] after:left-0 after:right-0 after:h-[2.5px] after:bg-paper-white after:z-10`:`h-9 px-2 sm:px-2.5 bg-[#e8e4da] text-slate-700 hover:bg-[#efece3] hover:text-ink-black font-bold border-2 border-ink-black relative z-0 mb-0`}`;return(0,_.jsxs)(`div`,{className:`w-full ${y?`flex flex-1`:`lg:w-[49%] flex`} flex-col bg-paper-white border-b-[3px] lg:border-b-0 ${y?``:`lg:border-r-[3px]`} border-ink-black overflow-hidden ${y&&f!==`spec`&&f!==`ref`?`hidden`:`flex`}`,children:[(0,_.jsxs)(`div`,{className:`shrink-0 bg-[#f4f1ea] border-b-2 border-ink-black px-1.5 sm:px-2.5 pt-2 flex items-end gap-1 relative z-10 overflow-x-auto no-scrollbar`,children:[(0,_.jsxs)(`button`,{onClick:()=>r(`spec`),className:$(e===`spec`),children:[(0,_.jsx)(a,{className:`w-3 h-3 text-purple-700 shrink-0`}),(0,_.jsx)(`span`,{children:y?`SPEC`:`SPECIFICATIONS`})]}),(0,_.jsxs)(`button`,{onClick:()=>r(`ref`),className:$(e===`ref`),children:[(0,_.jsx)(ae,{className:`w-3 h-3 text-blue-700 shrink-0`}),(0,_.jsx)(`span`,{children:y?`SOL (${X.length})`:`SOLUTIONS (${X.length})`})]}),(0,_.jsxs)(`button`,{onClick:()=>r(`leitner`),className:$(e===`leitner`),children:[(0,_.jsx)(c,{className:`w-3 h-3 text-emerald-700 shrink-0`}),(0,_.jsx)(`span`,{className:`whitespace-nowrap`,children:y?`FSRS`:`FSRS STATS`})]})]}),(0,_.jsxs)(`div`,{className:`flex-1 overflow-y-auto no-scrollbar p-4 sm:p-5 space-y-4`,children:[e===`spec`&&(0,_.jsxs)(`div`,{className:`space-y-4`,children:[(0,_.jsxs)(`div`,{className:`p-4 bg-white border-2 border-ink-black shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] space-y-3.5`,children:[(0,_.jsx)(`div`,{children:(0,_.jsx)(`h2`,{className:`text-base sm:text-lg font-extrabold text-ink-black font-headline-md leading-tight m-0 select-text`,children:b.name||`Algorithm Problem`})}),x.description&&(0,_.jsxs)(`div`,{className:`pt-3.5 border-t border-slate-200`,children:[(0,_.jsxs)(`div`,{className:`text-[9px] font-arcade text-trash-gray uppercase font-bold mb-2 flex items-center gap-1`,children:[(0,_.jsx)(o,{className:`w-3 h-3 text-primary`}),`PROBLEM DESCRIPTION`]}),(0,_.jsx)(`div`,{className:`font-sans text-xs sm:text-[13px] text-slate-800 leading-relaxed space-y-2 font-medium`,children:x.description.split(`
|
| 2 |
+
`).map((e,t)=>e.trim()?(0,_.jsx)(`p`,{className:`m-0 leading-relaxed whitespace-pre-wrap select-text`,children:m(e)},t):(0,_.jsx)(`div`,{className:`h-1.5`},t))})]}),x.examples.length>0&&(0,_.jsxs)(`div`,{className:`pt-3.5 border-t border-slate-200 space-y-2.5`,children:[(0,_.jsxs)(`div`,{className:`text-[9px] font-arcade text-trash-gray uppercase font-bold flex items-center gap-1.5`,children:[(0,_.jsx)(l,{className:`w-3 h-3 text-amber-500`}),`EXAMPLES (`,x.examples.length,`)`]}),(0,_.jsx)(`div`,{className:`space-y-2.5`,children:x.examples.map((e,t)=>(0,_.jsxs)(`div`,{className:`p-3 bg-slate-50 border border-slate-200 space-y-2 text-xs`,children:[(0,_.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,_.jsxs)(`span`,{className:`font-arcade text-[9px] font-bold text-primary`,children:[`EXAMPLE `,t+1]}),e.input&&(0,_.jsxs)(`button`,{onClick:()=>C(e.input,`ex-${t}`),className:`px-2 py-0.5 bg-white hover:bg-slate-100 border border-ink-black text-[9px] font-arcade text-ink-black flex items-center gap-1 cursor-pointer`,title:`Copy input data`,children:[(0,_.jsx)(u,{className:`w-2.5 h-2.5`}),S===`ex-${t}`?`COPIED!`:`COPY`]})]}),e.input&&(0,_.jsxs)(`div`,{className:`space-y-1`,children:[(0,_.jsx)(`span`,{className:`text-[9px] font-arcade text-trash-gray font-bold uppercase block`,children:`Input:`}),(0,_.jsx)(`div`,{className:`bg-[#1E293B] text-[#4ADE80] font-code-mono p-2 border border-ink-black text-[11px] break-all select-text`,children:e.input})]}),e.output&&(0,_.jsxs)(`div`,{className:`space-y-1`,children:[(0,_.jsx)(`span`,{className:`text-[9px] font-arcade text-trash-gray font-bold uppercase block`,children:`Output:`}),(0,_.jsx)(`div`,{className:`bg-[#1E293B] text-[#4ADE80] font-code-mono p-2 border border-ink-black text-[11px] break-all select-text`,children:e.output})]}),e.explanation&&(0,_.jsxs)(`div`,{className:`text-[11px] font-sans text-slate-600 bg-white p-2 border border-slate-200`,children:[(0,_.jsx)(`span`,{className:`font-bold text-slate-700`,children:`Explanation: `}),m(e.explanation)]})]},t))})]}),x.constraints.length>0&&(0,_.jsxs)(`div`,{className:`pt-3.5 border-t border-slate-200`,children:[(0,_.jsx)(`div`,{className:`text-[9px] font-arcade text-trash-gray uppercase font-bold mb-2`,children:`CONSTRAINTS`}),(0,_.jsx)(`ul`,{className:`space-y-1.5 list-none m-0 p-0`,children:x.constraints.map((e,t)=>(0,_.jsxs)(`li`,{className:`flex items-start gap-2 text-xs`,children:[(0,_.jsx)(`span`,{className:`text-primary font-bold select-none`,children:`•`}),(0,_.jsx)(`code`,{className:`bg-slate-100 text-ink-black font-code-mono px-2 py-0.5 border border-slate-300 text-[11px] select-text`,children:e})]},t))})]})]}),N?(0,_.jsxs)(`div`,{className:`p-3 bg-amber-50 border-2 border-ink-black shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] flex flex-wrap items-center justify-between gap-2`,children:[(0,_.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,_.jsx)(l,{className:`w-4 h-4 text-amber-600 shrink-0`}),(0,_.jsx)(`span`,{className:`font-arcade text-[9px] font-bold text-ink-black tracking-wide uppercase`,children:`OPTIMAL TARGET:`}),(0,_.jsxs)(`code`,{className:`bg-[#1E293B] text-[#4ADE80] font-code-mono px-2 py-0.5 text-[11px] border border-ink-black font-bold`,children:[`T: `,b.optimal_time||`O(N)`]}),(0,_.jsxs)(`code`,{className:`bg-[#1E293B] text-[#4ADE80] font-code-mono px-2 py-0.5 text-[11px] border border-ink-black font-bold`,children:[`S: `,b.optimal_space||`O(1)`]})]}),(0,_.jsxs)(`button`,{type:`button`,onClick:()=>P(!1),className:`px-2 py-0.5 bg-white hover:bg-slate-100 border border-ink-black font-arcade text-[8px] text-trash-gray hover:text-ink-black cursor-pointer flex items-center gap-1`,title:`Conceal target complexity`,children:[(0,_.jsx)(ne,{className:`w-2.5 h-2.5`}),(0,_.jsx)(`span`,{children:`HIDE`})]})]}):(0,_.jsxs)(`div`,{className:`p-3 bg-amber-50/70 border-2 border-ink-black shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] flex items-center justify-between gap-2`,children:[(0,_.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,_.jsx)(te,{className:`w-4 h-4 text-amber-700 shrink-0`}),(0,_.jsxs)(`div`,{children:[(0,_.jsx)(`span`,{className:`font-arcade text-[9px] font-bold text-ink-black tracking-wide uppercase block`,children:`OPTIMAL COMPLEXITY TARGET`}),(0,_.jsx)(`span`,{className:`text-[10px] font-sans text-slate-600 font-semibold`,children:`Hidden to test active recall before coding`})]})]}),(0,_.jsxs)(`button`,{type:`button`,onClick:()=>P(!0),className:`px-2.5 py-1 bg-white hover:bg-amber-100 border-2 border-ink-black font-arcade text-[8.5px] font-bold text-ink-black shadow-[1.5px_1.5px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none transition-all cursor-pointer flex items-center gap-1.5 shrink-0`,title:`Click to reveal target time and space complexity`,children:[(0,_.jsx)(t,{className:`w-3 h-3 text-amber-700`}),(0,_.jsx)(`span`,{children:`REVEAL TARGET`})]})]})]}),e===`ref`&&(0,_.jsxs)(`div`,{className:`space-y-4`,children:[q&&(0,_.jsxs)(`div`,{className:`p-2.5 border-2 border-ink-black text-xs font-bold flex items-center justify-between shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] ${q.type===`success`?`bg-emerald-100 text-emerald-900 border-emerald-700`:`bg-rose-100 text-rose-900 border-rose-700`}`,children:[(0,_.jsxs)(`div`,{className:`flex items-center gap-2`,children:[q.type===`success`?(0,_.jsx)(re,{className:`w-4 h-4 text-emerald-700 shrink-0`}):(0,_.jsx)(s,{className:`w-4 h-4 text-rose-700 shrink-0`}),(0,_.jsx)(`span`,{children:q.message})]}),(0,_.jsx)(`button`,{type:`button`,onClick:()=>J(null),className:`text-slate-600 hover:text-ink-black cursor-pointer`,children:(0,_.jsx)(se,{className:`w-3.5 h-3.5`})})]}),(0,_.jsxs)(`div`,{className:`flex items-center gap-1 p-1 bg-slate-200/90 border-2 border-ink-black shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] overflow-x-auto no-scrollbar`,children:[X.map((e,t)=>(0,_.jsxs)(`button`,{type:`button`,onClick:()=>{R(t),B(!1),H(null)},className:`py-1 px-2 rounded-full font-arcade text-[8px] font-bold flex items-center justify-center gap-1 border-2 border-ink-black transition-all cursor-pointer whitespace-nowrap shrink-0 ${Z===t&&!z&&!V?`bg-sky-600 text-white shadow-[1px_1px_0px_0px_rgba(30,41,59,1)] -translate-y-0.5`:`bg-white text-ink-black hover:bg-sky-50 shadow-none`}`,title:e.name?`${e.name} (${e.pattern||`Algorithm`})`:`Solution ${t+1}`,children:[e.is_optimal?(0,_.jsx)(d,{className:`w-3 h-3 text-amber-300`}):(0,_.jsx)(o,{className:`w-3 h-3`}),(0,_.jsx)(`span`,{children:`Sol ${t+1}`}),e.is_optimal&&(0,_.jsx)(`span`,{className:`text-[6.5px] px-1 py-0.2 bg-amber-300 text-ink-black border border-ink-black font-extrabold rounded-full tracking-tight`,children:`OPTIMAL`})]},e.id||t)),(0,_.jsx)(`button`,{type:`button`,onClick:()=>{B(!0),H(null),W({name:`Method ${X.length+1}`,pattern:`Arrays & Hashing`,time_complexity:`O(N)`,space_complexity:`O(1)`,code:``,explanation:``,is_optimal:!1})},className:`h-6 w-6 rounded-full font-arcade text-[9px] font-bold flex items-center justify-center border-2 border-ink-black cursor-pointer shrink-0 active:translate-y-0.5 transition-all shadow-[1px_1px_0px_0px_rgba(30,41,59,1)] ${z?`bg-emerald-600 text-white`:`bg-amber-300 text-ink-black hover:bg-amber-200`}`,title:`Add another solution / method for this problem`,"aria-label":`Add Solution`,children:(0,_.jsx)(ie,{className:`w-3 h-3 stroke-[2.5]`})})]}),z||V?(0,_.jsxs)(`div`,{className:`p-4 bg-white border-2 border-ink-black shadow-[3px_3px_0px_0px_rgba(30,41,59,1)] space-y-3.5`,children:[(0,_.jsxs)(`div`,{className:`flex items-center justify-between pb-2 border-b-2 border-dashed border-ink-black`,children:[(0,_.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,_.jsx)(i,{className:`w-4 h-4 text-purple-700`}),(0,_.jsx)(`span`,{className:`font-arcade text-[10px] font-bold text-ink-black uppercase`,children:V?`EDIT SOLUTION`:`ADD NEW SOLUTION / METHOD`})]}),(0,_.jsx)(`button`,{type:`button`,onClick:()=>{B(!1),H(null)},className:`text-xs font-arcade text-trash-gray hover:text-rose-600 cursor-pointer font-bold`,children:`CANCEL`})]}),(0,_.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[(0,_.jsxs)(`div`,{className:`space-y-1`,children:[(0,_.jsx)(`label`,{className:`font-arcade text-[8.5px] font-bold text-trash-gray uppercase block`,children:`Solution / Method Name`}),(0,_.jsx)(`input`,{type:`text`,value:U.name,onChange:e=>W({...U,name:e.target.value}),placeholder:`e.g. One-Pass Hash Map, Two Pointers`,className:`w-full p-2 border-2 border-ink-black text-xs font-bold bg-[#fdf8e1] focus:outline-none focus:bg-white`})]}),(0,_.jsxs)(`div`,{className:`space-y-1`,children:[(0,_.jsx)(`label`,{className:`font-arcade text-[8.5px] font-bold text-trash-gray uppercase block`,children:`Pattern / Strategy`}),(0,_.jsx)(`select`,{value:U.pattern,onChange:e=>W({...U,pattern:e.target.value}),className:`w-full p-2 border-2 border-ink-black text-xs font-bold bg-[#fdf8e1] focus:outline-none focus:bg-white`,children:ue.map(e=>(0,_.jsx)(`option`,{value:e,children:e},e))})]}),(0,_.jsxs)(`div`,{className:`space-y-1`,children:[(0,_.jsx)(`label`,{className:`font-arcade text-[8.5px] font-bold text-trash-gray uppercase block`,children:`Time Complexity`}),(0,_.jsx)(`input`,{type:`text`,value:U.time_complexity,onChange:e=>W({...U,time_complexity:e.target.value}),placeholder:`e.g. O(N), O(N log N), O(N^2)`,className:`w-full p-2 border-2 border-ink-black text-xs font-code-mono font-bold bg-[#fdf8e1] focus:outline-none focus:bg-white`})]}),(0,_.jsxs)(`div`,{className:`space-y-1`,children:[(0,_.jsx)(`label`,{className:`font-arcade text-[8.5px] font-bold text-trash-gray uppercase block`,children:`Space Complexity`}),(0,_.jsx)(`input`,{type:`text`,value:U.space_complexity,onChange:e=>W({...U,space_complexity:e.target.value}),placeholder:`e.g. O(1), O(N)`,className:`w-full p-2 border-2 border-ink-black text-xs font-code-mono font-bold bg-[#fdf8e1] focus:outline-none focus:bg-white`})]})]}),(0,_.jsxs)(`div`,{className:`space-y-1`,children:[(0,_.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,_.jsx)(`label`,{className:`font-arcade text-[8.5px] font-bold text-trash-gray uppercase`,children:`Python Reference Code`}),(0,_.jsx)(`button`,{type:`button`,onClick:()=>W({...U,code:pe}),className:`text-[8.5px] font-arcade text-sky-700 hover:underline cursor-pointer`,children:`Paste Current Code`})]}),(0,_.jsx)(`textarea`,{rows:8,value:U.code,onChange:e=>W({...U,code:e.target.value}),placeholder:`class Solution:
|
| 3 |
+
def solve(self, nums):
|
| 4 |
+
...`,className:`w-full p-2.5 border-2 border-ink-black bg-[#1E293B] text-[#4ADE80] font-code-mono text-xs focus:outline-none no-scrollbar`})]}),(0,_.jsxs)(`div`,{className:`space-y-1`,children:[(0,_.jsx)(`label`,{className:`font-arcade text-[8.5px] font-bold text-trash-gray uppercase block`,children:`Intuition / How to Solve (Optional)`}),(0,_.jsx)(`textarea`,{rows:3,value:U.explanation,onChange:e=>W({...U,explanation:e.target.value}),placeholder:`Key insight, trade-offs, and state tracking notes...`,className:`w-full p-2 border-2 border-ink-black text-xs bg-[#fdf8e1] focus:outline-none focus:bg-white no-scrollbar`})]}),(0,_.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,_.jsx)(`input`,{type:`checkbox`,id:`is_optimal_solution`,checked:U.is_optimal,onChange:e=>W({...U,is_optimal:e.target.checked}),className:`w-4 h-4 border-2 border-ink-black rounded cursor-pointer accent-emerald-600`}),(0,_.jsx)(`label`,{htmlFor:`is_optimal_solution`,className:`font-arcade text-[9px] font-bold text-ink-black cursor-pointer`,children:`SET AS OPTIMAL / PRIMARY APPROACH FOR THIS PROBLEM`})]}),(0,_.jsxs)(`div`,{className:`flex items-center justify-end gap-2 pt-2 border-t-2 border-dashed border-ink-black`,children:[(0,_.jsx)(`button`,{type:`button`,onClick:()=>{B(!1),H(null)},className:`px-3 py-1.5 bg-slate-100 hover:bg-slate-200 border-2 border-ink-black font-arcade text-[9px] font-bold text-ink-black cursor-pointer`,children:`CANCEL`}),(0,_.jsxs)(`button`,{type:`button`,disabled:G,onClick:he,className:`px-4 py-1.5 bg-emerald-500 hover:bg-emerald-400 border-2 border-ink-black font-arcade text-[9px] font-bold text-white shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none transition-all cursor-pointer disabled:opacity-50 flex items-center gap-1.5`,children:[G&&(0,_.jsx)(n,{className:`w-3 h-3 animate-spin`}),(0,_.jsx)(`span`,{children:V?`UPDATE SOLUTION`:`SAVE SOLUTION`})]})]})]}):Q?(0,_.jsxs)(`div`,{className:`space-y-3.5`,children:[(0,_.jsxs)(`div`,{className:`p-4 bg-white border-2 border-ink-black shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] space-y-3.5`,children:[(0,_.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 pb-3 border-b border-slate-200`,children:[(0,_.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap min-w-0`,children:[(0,_.jsx)(`h3`,{className:`font-headline-md font-extrabold text-sm sm:text-base text-ink-black m-0 select-text break-words`,children:Q.name||`Solution ${Z+1}`}),Q.is_optimal&&(0,_.jsx)(`span`,{className:`px-2 py-0.5 bg-amber-300 border border-ink-black font-arcade text-[8px] font-bold text-ink-black shadow-[1px_1px_0px_0px_rgba(30,41,59,1)] shrink-0`,children:`★ OPTIMAL`})]}),(0,_.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap sm:ml-auto`,children:[(0,_.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,_.jsx)(`span`,{className:`font-arcade text-[8px] text-trash-gray uppercase`,children:`Pattern:`}),(0,_.jsx)(`span`,{className:`px-2 py-0.5 bg-purple-50 border border-purple-300 font-arcade text-[8.5px] text-purple-800 font-bold`,children:Q.pattern||`General Algorithm`})]}),(0,_.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,_.jsxs)(`code`,{className:`bg-[#1E293B] text-[#4ADE80] font-code-mono px-1.5 py-0.5 text-[11px] border border-ink-black font-bold`,children:[`T: `,Q.time_complexity||`O(N)`]}),(0,_.jsxs)(`code`,{className:`bg-[#1E293B] text-[#4ADE80] font-code-mono px-1.5 py-0.5 text-[11px] border border-ink-black font-bold`,children:[`S: `,Q.space_complexity||`O(1)`]})]}),(0,_.jsxs)(`div`,{className:`flex items-center gap-1 ml-auto`,children:[(0,_.jsxs)(`button`,{type:`button`,onClick:()=>{H(Q.id),B(!1),W({name:Q.name,pattern:Q.pattern,time_complexity:Q.time_complexity,space_complexity:Q.space_complexity,code:Q.code,explanation:Q.explanation||``,is_optimal:!!Q.is_optimal})},className:`px-2 py-1 bg-white hover:bg-slate-100 border border-ink-black text-ink-black font-arcade text-[8px] font-bold flex items-center gap-1 cursor-pointer`,title:`Edit this solution`,children:[(0,_.jsx)(i,{className:`w-3 h-3 text-slate-700`}),(0,_.jsx)(`span`,{className:`hidden sm:inline`,children:`EDIT`})]}),X.length>1&&(0,_.jsx)(`button`,{type:`button`,onClick:()=>ge(Q.id),className:`px-1.5 py-1 bg-white hover:bg-rose-50 border border-ink-black text-rose-700 font-arcade text-[8px] font-bold flex items-center gap-1 cursor-pointer`,title:`Delete this solution`,children:(0,_.jsx)(oe,{className:`w-3 h-3`})})]})]})]}),Q.code?(0,_.jsxs)(`div`,{className:`border border-ink-black bg-[#0f172a] overflow-hidden`,children:[(0,_.jsxs)(`div`,{className:`bg-[#1e293b] px-2.5 sm:px-3 py-1.5 border-b border-ink-black flex items-center justify-between gap-1.5 flex-wrap min-w-0`,children:[(0,_.jsx)(`span`,{className:`font-arcade text-[8px] text-slate-300 font-bold uppercase truncate min-w-0 flex-1`,children:y?`PYTHON 3`:`PYTHON 3 IMPLEMENTATION`}),(0,_.jsxs)(`div`,{className:`flex items-center gap-1.5 shrink-0`,children:[(0,_.jsxs)(`button`,{type:`button`,onClick:()=>me(Q.code,Q.pattern,Q.time_complexity,Q.space_complexity),disabled:O,className:`px-2 py-0.5 bg-purple-50 hover:bg-purple-100 text-purple-800 border border-ink-black text-[9px] font-arcade font-bold flex items-center gap-1 cursor-pointer shrink-0 disabled:opacity-50 active:translate-y-0.5 transition-all`,title:`Explain this solution with AI`,children:[O?(0,_.jsx)(n,{className:`w-2.5 h-2.5 animate-spin text-purple-700`}):(0,_.jsx)(d,{className:`w-2.5 h-2.5 text-purple-600`}),(0,_.jsx)(`span`,{children:`Explain✦`})]}),(0,_.jsxs)(`button`,{onClick:()=>C(Q.code,`sol-${Q.id}`),className:`px-2 py-0.5 bg-white hover:bg-slate-100 text-ink-black border border-ink-black text-[9px] font-arcade font-bold flex items-center gap-1 cursor-pointer shrink-0 active:translate-y-0.5 transition-all`,title:`Copy solution code`,children:[(0,_.jsx)(u,{className:`w-2.5 h-2.5`}),S===`sol-${Q.id}`?`COPIED!`:`COPY`]})]})]}),(0,_.jsx)(`div`,{className:`p-3 text-xs overflow-x-auto max-h-80 no-scrollbar`,children:(0,_.jsx)(`pre`,{className:`font-code-mono text-[#4ADE80] text-[11px] leading-relaxed select-text m-0`,children:(0,_.jsx)(`code`,{children:Q.code})})})]}):(0,_.jsxs)(`div`,{className:`p-4 bg-amber-50 border border-dashed border-amber-300 text-center space-y-3`,children:[(0,_.jsx)(`p`,{className:`text-xs font-sans text-stone-700`,children:`No code implementation archived for this solution yet.`}),(0,_.jsx)(`button`,{onClick:D,disabled:T,className:`px-4 py-2 bg-purple-600 hover:bg-purple-700 text-white font-arcade text-[9px] font-bold border-2 border-ink-black shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none transition-all cursor-pointer inline-flex items-center gap-2 disabled:opacity-50`,children:T?(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)(n,{className:`w-3.5 h-3.5 animate-spin`}),(0,_.jsx)(`span`,{children:`Generating solution...`})]}):(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)(d,{className:`w-3.5 h-3.5 text-amber-300`}),(0,_.jsx)(`span`,{children:`Generate solution`})]})}),E&&(0,_.jsx)(`div`,{className:`text-xs text-rose-600 font-medium`,children:E})]}),Q.explanation&&(0,_.jsxs)(`div`,{className:`pt-3.5 border-t border-slate-200 space-y-1.5 select-text`,children:[(0,_.jsx)(`span`,{className:`font-arcade text-[8.5px] text-trash-gray uppercase font-bold block`,children:`SOLUTION INTUITION & STRATEGY:`}),(0,_.jsx)(h,{content:Q.explanation})]})]}),Q.code&&(0,_.jsxs)(`div`,{className:`space-y-3`,children:[k&&(0,_.jsx)(`div`,{className:`p-3 border-2 border-rose-500 bg-rose-50 text-rose-800 text-xs font-semibold`,children:k}),A&&(0,_.jsxs)(`div`,{className:`p-4 bg-white border-2 border-ink-black shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] space-y-2 select-text`,children:[(0,_.jsxs)(`div`,{className:`flex items-center gap-1.5 pb-2 border-b-2 border-dashed border-ink-black`,children:[(0,_.jsx)(ce,{className:`w-4 h-4 text-purple-600`}),(0,_.jsxs)(`span`,{className:`font-arcade text-[9px] font-bold text-ink-black uppercase`,children:[`Gemini Code Breakdown (`,Q.name,`)`]})]}),(0,_.jsx)(`div`,{className:`max-h-96 overflow-y-auto no-scrollbar pt-1 select-text`,children:(0,_.jsx)(h,{content:A})})]})]})]}):null,w&&(0,_.jsxs)(`div`,{className:`p-2.5 border-2 border-rose-500 bg-rose-50 text-rose-800 text-xs font-bold flex items-center gap-2 shadow-[2px_2px_0px_0px_rgba(244,63,94,1)]`,children:[(0,_.jsx)(s,{className:`w-4 h-4 text-rose-600 shrink-0`}),(0,_.jsx)(`div`,{className:`flex-1`,children:w})]})]}),e===`leitner`&&(0,_.jsxs)(`div`,{className:`space-y-4`,children:[(0,_.jsxs)(`div`,{className:`p-4 bg-white border-2 border-ink-black shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] space-y-3`,children:[(0,_.jsxs)(`div`,{className:`text-[9px] font-arcade text-trash-gray uppercase font-bold flex items-center gap-1.5`,children:[(0,_.jsx)(ee,{className:`w-3 h-3 text-purple-600`}),`SPACED REPETITION PROGRESSION`]}),(0,_.jsx)(`div`,{className:`space-y-2`,children:[{state:0,label:`NEW`,color:`#3b82f6`},{state:1,label:`LEARNING`,color:`#f59e0b`},{state:2,label:`REVIEW`,color:`#10b981`},{state:3,label:`RELEARNING`,color:`#ef4444`}].map(e=>{let t=(j.fsrs_state??0)===e.state;return(0,_.jsxs)(`div`,{className:`p-2.5 border-2 border-ink-black flex items-center justify-between transition-all ${t?`bg-amber-100 shadow-[3px_3px_0px_0px_rgba(30,41,59,1)] translate-x-1 font-bold`:`bg-slate-50 opacity-70`}`,children:[(0,_.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,_.jsx)(`span`,{className:`w-5 h-5 border border-ink-black flex items-center justify-center font-arcade text-[9px] text-white font-bold`,style:{backgroundColor:e.color},children:e.state}),(0,_.jsx)(`span`,{className:`font-arcade text-[9px] text-ink-black`,children:e.label})]}),(0,_.jsx)(`div`,{className:`flex items-center gap-2`,children:t&&(0,_.jsx)(`span`,{className:`px-1.5 py-0.5 bg-emerald-500 text-white font-arcade text-[7px] border border-ink-black font-bold`,children:`CURRENT`})})]},e.state)})})]}),(0,_.jsxs)(`div`,{className:`p-4 bg-white border-2 border-ink-black shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] space-y-3`,children:[(0,_.jsxs)(`div`,{className:`text-[9px] font-arcade text-trash-gray uppercase font-bold flex items-center gap-1.5`,children:[(0,_.jsx)(c,{className:`w-3 h-3 text-emerald-600`}),`PERFORMANCE METRICS`]}),(0,_.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,_.jsxs)(`div`,{className:`p-2.5 bg-slate-50 border border-ink-black`,children:[(0,_.jsx)(`span`,{className:`font-arcade text-[8px] text-trash-gray block uppercase`,children:`Total Reviews`}),(0,_.jsx)(`span`,{className:`font-headline-md text-lg font-bold text-ink-black`,children:j.total_attempts||0})]}),(0,_.jsxs)(`div`,{className:`p-2.5 bg-slate-50 border border-ink-black`,children:[(0,_.jsx)(`span`,{className:`font-arcade text-[8px] text-trash-gray block uppercase`,children:`Correct Recall`}),(0,_.jsx)(`span`,{className:`font-headline-md text-lg font-bold text-emerald-600`,children:j.times_correct||0})]})]}),(0,_.jsxs)(`div`,{className:`text-xs font-sans text-slate-600 pt-1`,children:[`Next Due Date:`,` `,(0,_.jsx)(`span`,{className:`font-code-mono font-bold text-ink-black`,children:j.next_review?new Date(j.next_review).toLocaleDateString():`Today`})]})]})]})]})]})};export{y as ProblemSpecPanel};
|
algospaced-ui/dist/assets/{PythonChallenge-8UlYXBt_.js → PythonChallenge-BUhtEPkm.js}
RENAMED
|
@@ -1 +1 @@
|
|
| 1 |
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Lt as t,zt as n}from"./vendor-react-
|
|
|
|
| 1 |
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Lt as t,zt as n}from"./vendor-react-qmUj3JUi.js";import{r}from"./firebaseClient-G7klkuBb.js";import{t as i}from"./MarkdownRenderer-CC5nUs7-.js";var a=e(n(),1),o=t();function s(){let[e,t]=(0,a.useState)(null),[n,s]=(0,a.useState)(``),[c,l]=(0,a.useState)(!1),[u,d]=(0,a.useState)([]),[f,p]=(0,a.useState)(``),[m,h]=(0,a.useState)(!0),[g,_]=(0,a.useState)(0),v=async()=>{h(!0),p(``);try{let{data:{session:e}}=await r.auth.getSession();if(!e){p(`Unauthenticated session`);return}let n=await fetch(`/api/challenges/python/daily`,{headers:{Authorization:`Bearer ${e.access_token}`}});if(n.ok){let e=await n.json();t(e),s(e.starter_code),_(e.total_score)}else p(`Failed to load challenge from server.`)}catch{p(`Connection timed out.`)}finally{h(!1)}};return(0,a.useEffect)(()=>{v()},[]),m?(0,o.jsxs)(`div`,{className:`w-full h-full bg-paper-white p-6 flex flex-col items-center justify-center font-arcade text-[10px]`,children:[(0,o.jsx)(`div`,{className:`animate-bounce mb-2`,children:`LOADING CHALLENGE...`}),(0,o.jsx)(`div`,{className:`w-48 h-4 bg-white border-[3px] border-ink-black overflow-hidden relative`,children:(0,o.jsx)(`div`,{className:`absolute inset-y-0 left-0 bg-[#9d4edd] w-2/3 animate-pulse border-r-2 border-ink-black`})})]}):e?(0,o.jsx)(`div`,{className:`w-full h-full bg-paper-white text-ink-black flex flex-col overflow-hidden text-xs md:text-sm`,children:(0,o.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-4 custom-scrollbar flex flex-col gap-4`,children:[(0,o.jsxs)(`div`,{className:`flex justify-between items-center bg-slate-100 border-[3px] border-ink-black p-3`,children:[(0,o.jsxs)(`div`,{className:`flex gap-2`,children:[(0,o.jsx)(`span`,{className:`px-2 py-0.5 border-2 border-ink-black font-bold uppercase text-[9px] ${e.difficulty===`Easy`?`bg-green-200 text-green-800`:e.difficulty===`Medium`?`bg-yellow-200 text-yellow-800`:`bg-red-200 text-red-800`}`,children:e.difficulty}),(0,o.jsxs)(`span`,{className:`bg-blue-100 text-blue-800 px-2 py-0.5 border-2 border-ink-black font-bold text-[9px]`,children:[`+`,e.points,` PTS`]}),e.completed?(0,o.jsx)(`span`,{className:`bg-emerald-500 text-white px-2 py-0.5 border-2 border-ink-black font-bold text-[9px]`,children:`COMPLETED`}):(0,o.jsx)(`span`,{className:`bg-rose-500 text-white px-2 py-0.5 border-2 border-ink-black font-bold text-[9px]`,children:`INCOMPLETE`})]}),(0,o.jsxs)(`div`,{className:`font-arcade text-[8px] text-purple-700 font-bold bg-white border-2 border-ink-black px-2 py-0.5 shadow-[1px_1px_0_0_#1E293B]`,children:[`TOTAL SCORE: `,g]})]}),(0,o.jsxs)(`div`,{className:`border-2 border-ink-black bg-slate-50 p-3 rounded font-sans leading-relaxed text-xs`,children:[(0,o.jsxs)(`h3`,{className:`font-bold border-b border-slate-300 pb-1 mb-2 uppercase tracking-wide text-primary-purple flex items-center gap-1`,children:[(0,o.jsx)(`span`,{className:`material-symbols-outlined text-sm`,children:`description`}),`Problem: `,e.title]}),(0,o.jsx)(i,{content:e.description})]}),(0,o.jsxs)(`div`,{className:`flex flex-col flex-1 min-h-[220px]`,children:[(0,o.jsxs)(`div`,{className:`flex justify-between items-center mb-1`,children:[(0,o.jsxs)(`span`,{className:`font-bold text-[10px] tracking-wide uppercase flex items-center gap-1`,children:[(0,o.jsx)(`span`,{className:`material-symbols-outlined text-sm text-purple-600`,children:`code`}),`Write Python Solution:`]}),(0,o.jsx)(`button`,{onClick:()=>s(e.starter_code),className:`text-[9px] underline text-blue-600 hover:text-blue-800 cursor-pointer font-sans`,children:`Reset Starter Code`})]}),(0,o.jsx)(`textarea`,{value:n,onChange:e=>s(e.target.value),className:`flex-1 w-full bg-slate-900 text-[#4ADE80] font-mono p-3 border-[3px] border-ink-black rounded outline-none focus:ring-2 focus:ring-primary-purple text-xs leading-relaxed resize-none`,placeholder:`# Write your python code here`,spellCheck:`false`})]}),(0,o.jsx)(`div`,{className:`shrink-0`,children:(0,o.jsx)(`button`,{disabled:c,onClick:async()=>{l(!0),p(``),d([]);try{let{data:{session:e}}=await r.auth.getSession();if(!e){p(`Unauthenticated session`);return}let i=await fetch(`/api/challenges/python/submit`,{method:`POST`,headers:{"Content-Type":`application/json`,Authorization:`Bearer ${e.access_token}`},body:JSON.stringify({code:n})});if(i.ok){let e=await i.json();e.success?(d(e.results),e.all_passed&&(_(e.total_score),t(e=>e?{...e,completed:!0}:null))):p(e.error)}else p(`Submission failed at server host.`)}catch{p(`Network connection lost.`)}finally{l(!1)}},className:`w-full bg-highlight-pink text-white font-window-title font-bold py-2 px-4 border-[3px] border-ink-black shadow-[3px_3px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none hover:bg-pink-400 transition-all disabled:opacity-50 cursor-pointer text-center text-xs`,children:c?`EXECUTING TEST CASES...`:`SUBMIT SOLUTION`})}),f&&(0,o.jsxs)(`div`,{className:`border-[3px] border-red-500 bg-red-50 text-red-800 p-3 font-mono text-xs whitespace-pre-wrap`,children:[(0,o.jsx)(`div`,{className:`font-bold mb-1`,children:`COMPILER / RUNTIME ERROR:`}),f]}),u.length>0&&(0,o.jsxs)(`div`,{className:`border-[3px] border-ink-black bg-slate-100 p-3`,children:[(0,o.jsx)(`div`,{className:`font-bold text-[10px] border-b border-slate-300 pb-1 mb-2 uppercase`,children:`Test Case Executions:`}),(0,o.jsx)(`div`,{className:`space-y-1.5 font-mono text-xs`,children:u.map((e,t)=>(0,o.jsxs)(`div`,{className:`flex flex-col p-2 border border-slate-300 bg-white`,children:[(0,o.jsxs)(`div`,{className:`flex justify-between`,children:[(0,o.jsxs)(`span`,{className:`font-bold`,children:[`Test Case `,t+1,`:`]}),(0,o.jsx)(`span`,{className:`font-bold uppercase ${e.status===`passed`?`text-green-600`:`text-red-600`}`,children:e.status})]}),(0,o.jsxs)(`div`,{className:`text-[10px] text-slate-500 mt-1`,children:[(0,o.jsxs)(`div`,{children:[`Input: `,JSON.stringify(e.input)]}),e.status===`passed`&&(0,o.jsxs)(`div`,{children:[`Output: `,JSON.stringify(e.got)]}),e.status===`failed`&&(0,o.jsxs)(`div`,{className:`text-red-700`,children:[`Expected: `,JSON.stringify(e.expected),` | Got: `,JSON.stringify(e.got)]}),e.status===`error`&&(0,o.jsxs)(`div`,{className:`text-red-700 font-semibold`,children:[`Error: `,e.error]})]})]},t))})]})]})}):(0,o.jsxs)(`div`,{className:`w-full h-full bg-paper-white p-6 flex flex-col items-center justify-center font-sans text-center gap-3`,children:[(0,o.jsx)(`span`,{className:`material-symbols-outlined text-red-500 text-4xl`,children:`error`}),(0,o.jsx)(`div`,{className:`font-bold text-ink-black text-sm`,children:f||`No active challenge found.`}),(0,o.jsx)(`button`,{onClick:v,className:`px-3 py-1.5 bg-yellow-400 hover:bg-yellow-300 border-[3px] border-ink-black text-xs font-bold font-window-title cursor-pointer shadow-[2px_2px_0px_rgba(0,0,0,1)] active:translate-y-0.5 active:shadow-none`,children:`RETRY`})]})}export{s as default};
|
algospaced-ui/dist/assets/ReviewQueue-BsWCZFit.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
| 1 |
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ProblemSpecPanel-CoULhmZo.js","assets/rolldown-runtime-hePW80VL.js","assets/vendor-react-yvPwY2Sj.js","assets/vendor-codemirror-By0wlJeM.js","assets/index-DttZMwvA.js","assets/firebaseClient-G7klkuBb.js","assets/vendor-firebase-DSIO3PIf.js","assets/vendor-ui-ZXcm-2wU.js","assets/index-Di-5TpeG.css","assets/MarkdownRenderer-CWg4XXNt.js"])))=>i.map(i=>d[i]);
|
| 2 |
-
import{n as e,r as t}from"./rolldown-runtime-hePW80VL.js";import{Ct as n,D as r,J as i,Lt as a,N as o,P as s,Q as c,St as l,Z as u,d,dt as f,ft as p,gt as m,it as h,j as g,k as _,o as v,ot as y,p as b,t as ee,tt as x,u as S,ut as C,vt as w,y as T,yt as E,zt as D}from"./vendor-react-yvPwY2Sj.js";import{r as O}from"./firebaseClient-G7klkuBb.js";import{b as k,c as A,n as j,o as M,r as N,s as P,t as F}from"./index-DttZMwvA.js";import{o as I,r as L}from"./githubSyncService-DQdE4J2L.js";import{t as R}from"./confetti.module-Uxh4CK4s.js";import z from"./OnboardingModal-CySUf-WA.js";import"./MarkdownRenderer-CWg4XXNt.js";import"./PrincessChamber-CyKVnuqB.js";import{A as B,C as te,I as V,S as H,p as U,t as ne,x as re,y as ie}from"./vendor-codemirror-By0wlJeM.js";var W=t(D(),1),G=a();function ae(e){if(!e)return{description:``,examples:[],constraints:[]};let t=e.description||``,n=[],r=[];if(Array.isArray(e.examples)&&e.examples.length>0&&(n=e.examples.map(e=>typeof e==`string`?{input:e,output:``}:{input:e?.input||``,output:e?.output||``,explanation:e?.explanation||``})),Array.isArray(e.constraints)&&e.constraints.length>0?r=e.constraints.map(e=>String(e).replace(/^[\u2022\-*]\s*/,``).trim()).filter(Boolean):typeof e.constraints==`string`&&e.constraints.trim()&&(r=e.constraints.split(`
|
| 3 |
-
`).map(e=>e.replace(/^[\u2022\-*]\s*/,``).trim()).filter(Boolean)),n.length===0||r.length===0){let e=t.search(/\bExample\s*\d*:/i),i=t.search(/\bConstraints\s*:/i),a=-1;if(e!==-1&&i!==-1?a=Math.min(e,i):e===-1?i!==-1&&(a=i):a=e,a!==-1){let e=t.substring(0,a).trim(),i=t.substring(a),o=i,s=``,c=i.search(/\bConstraints\s*:/i);if(c!==-1&&(o=i.substring(0,c).trim(),s=i.substring(c).replace(/\bConstraints\s*:/i,``).trim()),n.length===0&&o){let e=/\bExample\s*(\d*)\s*:/gi,t=[],r;for(;(r=e.exec(o))!==null;)t.push({index:r.index,text:r[0]});for(let e=0;e<t.length;e++){let r=t[e].index+t[e].text.length,i=e+1<t.length?t[e+1].index:o.length,a=o.substring(r,i).trim(),s=a.match(/Input:\s*([\s\S]+?)(?=(?:Output:|Explanation:|$))/i),c=a.match(/Output:\s*([\s\S]+?)(?=(?:Explanation:|$))/i),l=a.match(/Explanation:\s*([\s\S]+)/i),u=s?s[1].trim():``,d=c?c[1].trim():``,f=l?l[1].trim():``;u||d?n.push({input:u,output:d,explanation:f}):a&&n.push({input:a,output:``,explanation:``})}}r.length===0&&s&&(r=s.split(`
|
| 4 |
-
`).map(e=>e.replace(/^[\u2022\-*]\s*/,``).trim()).filter(Boolean)),(n.length>0||r.length>0)&&(t=e)}}return{description:t,examples:n,constraints:r}}function oe(e,t,n,r){let i=e=>!e||/^Method\s*\d*$/i.test(e.trim())||e.trim().toLowerCase()===`standard`,a=(e||t||`Algorithm Problem`).trim(),o=null;if(t&&a.toLowerCase().startsWith(t.toLowerCase())){let e=a.slice(t.length).trim();if(a=t,e){let t=e.match(/^[-\s]*Method\s*(\d+)\s*\((.+)\)$/i);if(t){let e=parseInt(t[1],10),n=t[2].trim();i(n)?e>1&&(o=`Method ${e}`):o=n}else{let t=e.match(/^[-\s]*Method\s*(\d+)/i);if(t){let e=parseInt(t[1],10);e>1&&(o=`Method ${e}`)}else{let t=e.match(/^[-\s]*\((.+)\)$/);if(t){let e=t[1].trim();i(e)||(o=e)}else{let t=e.match(/^[-\s]+([^-]+)$/);t&&!i(t[1])&&(o=t[1].trim())}}}}}else{let e=a.match(/^(.*?)\s*-\s*Method\s*(\d+)\s*\((.+)\)$/i);if(e){a=e[1].trim();let t=parseInt(e[2],10),n=e[3].trim();i(n)?t>1&&(o=`Method ${t}`):o=n}else{let e=a.match(/^(.*?)\s*-\s*Method\s*(\d+)$/i);if(e){a=e[1].trim();let t=parseInt(e[2],10);t>1&&(o=`Method ${t}`)}else{let e=a.match(/^(.*?)\s*\(\s*Method\s*(\d+)\s*\)$/i);if(e){a=e[1].trim();let t=parseInt(e[2],10);t>1&&(o=`Method ${t}`)}}}}let s=`General Algorithm`;return i(n)?i(r)?o&&!i(o)&&(s=o):s=r.trim():s=n.trim(),{cleanTitle:a,approachVariant:o,pattern:s}}function se(e,t,n){if(!e)return[];if(Array.isArray(e.solutions)&&e.solutions.length>0)return e.solutions;let r=[],i=t||e.reference_code||``,a=e.pattern||`General Algorithm`,o=e.optimal_time||`O(N)`,s=e.optimal_space||`O(1)`;return(i||a)&&r.push({id:`sol-1`,name:e.approach_variant||`Optimal Solution`,pattern:a,time_complexity:o,space_complexity:s,code:i,explanation:e.how_to_solve||``,is_optimal:!0}),n&&n.trim()&&n.trim()!==i.trim()&&r.push({id:`sol-2`,name:`Personal Solution`,pattern:a,time_complexity:o,space_complexity:s,code:n,is_optimal:!1}),r}function ce({overrideProblemId:e,refreshTrigger:t,onClearOverride:n,onOpenOnboarding:r,setIsOnboardingOpen:i}){let[a,o]=(0,W.useState)([]),[s,c]=(0,W.useState)(!0),[l,u]=(0,W.useState)(!1),[d,f]=(0,W.useState)(null),[p,m]=(0,W.useState)(null),[h,g]=(0,W.useState)(``),[_,v]=(0,W.useState)(null),[y,b]=(0,W.useState)(!1),[ee,x]=(0,W.useState)(void 0),S=(0,W.useRef)(!1),C=(0,W.useRef)(r),w=(0,W.useRef)(i),T=(0,W.useRef)(n),E=(0,W.useRef)(!1);(0,W.useEffect)(()=>{C.current=r,w.current=i,T.current=n});let D=(0,W.useCallback)(()=>{C.current?C.current():w.current&&w.current(!0)},[]),j=(0,W.useCallback)(async(t=!0)=>{t?(c(!0),m(null),g(``),S.current=!1):m(null);try{let{data:{session:n}}=await O.auth.getSession(),r=n?n.access_token:`sandbox`;n?.user?.id&&x(n.user.id);let i={Authorization:`Bearer ${r}`},a=await fetch(`/api/reviews/due`,{headers:i}),s=a.ok?await a.json():[];if(Array.isArray(s)||(s=[]),e){let t=String(e).trim().toLowerCase(),n=s.findIndex(e=>{let n=e.problems;return!!(e.problem_id&&String(e.problem_id).trim().toLowerCase()===t||n?.id&&String(n.id).trim().toLowerCase()===t||n?.problem_number!==void 0&&n?.problem_number!==null&&String(n.problem_number)===t||n?.name&&n.name.trim().toLowerCase()===t)});if(n>0){let[e]=s.splice(n,1);s.unshift(e)}else if(n===-1){let t=null,n=await fetch(`/api/reviews/problems/id/${e}`,{headers:i});if(n.ok){let e=await n.json();Array.isArray(e)&&e.length>0&&(t=e[0])}if(!t){let n=/^\d+$/.test(e),r=N(n?parseInt(e,10):void 0,e);if(r)try{let e=await A(r);if(e?.problem_id){let n=await fetch(`/api/reviews/problems/id/${e.problem_id}`,{headers:i});if(n.ok){let e=await n.json();Array.isArray(e)&&e.length>0&&(t=e[0])}}}catch(e){console.error(`Failed to auto-activate problem for override review:`,e)}}t&&s.unshift(t)}}o(s);let c=n?.user?.id,l=c===`sandbox-user-id`||!c?`sandbox`:c;if(!localStorage.getItem(`algospaced_onboarding_done_${l}`)&&!e&&D(),s&&s.length>0){if(t){let e=s[0],t=e.problems,n=t?.problem_number??(/^\d+$/.test(e?.problem_id||``)?parseInt(e.problem_id,10):void 0),r=N(n,t?.id||e?.problem_id,t?.name)?.starter_code||t?.starter_code||``;g(r)}}else try{let e=await fetch(`/api/journey-progress`,{headers:i});if(e.ok){let t=await e.json();v(P(new Set(t))??null)}else v(P(new Set)??null)}catch{v(P(new Set)??null)}}catch(e){console.error(`Error fetching review queue:`,e)}finally{c(!1)}},[e,D]);(0,W.useEffect)(()=>{if(E.current){E.current=!1;return}let e=!1,t=setTimeout(()=>{e||j(!0)},0);return()=>{e=!0,clearTimeout(t)}},[j,t]),(0,W.useEffect)(()=>{if(!s&&a.length===0&&!e&&!S.current){S.current=!0;try{R({particleCount:90,spread:70,origin:{y:.6}})}catch{}}},[s,a.length,e]);let M=(0,W.useCallback)(async t=>{if(a.length===0||l)return;let n=a[0];if(!n||!n.id)return;u(!0),f(t),m(null);let r=[...a];try{let{data:{session:i}}=await O.auth.getSession(),a=i?i.access_token:`sandbox`,s=await fetch(`/api/reviews/complete`,{method:`POST`,headers:{"Content-Type":`application/json`,Authorization:`Bearer ${a}`},body:JSON.stringify({review_id:n.id,fsrs_state:n.fsrs_state??0,fsrs_stability:n.fsrs_stability??0,fsrs_difficulty:n.fsrs_difficulty??0,fsrs_elapsed_days:n.fsrs_elapsed_days??0,fsrs_scheduled_days:n.fsrs_scheduled_days??0,fsrs_reps:n.fsrs_reps??0,fsrs_lapses:n.fsrs_lapses??0,last_reviewed:n.last_reviewed,rating:t})});if(s.ok){let r=n?.problems?.name||``,i=n?.problems?.pattern||``,a=`Correct`;a=t===1?`Incorrect`:t===2?`Mixed`:`Correct`,k.addReviewEvent(a,r,i).catch(()=>{});let s=L(),c=h.trim()||n?.problems?.reference_code||``;s.token&&s.repoName&&s.autoCommit&&c&&I({token:s.token,repo:s.repoName,branch:s.branch,problem_number:n?.problems?.problem_number,problem_name:r||`Algorithm Problem`,pattern:i||`Algorithms`,difficulty:n?.problems?.difficulty||`Medium`,optimal_time:n?.problems?.optimal_time||`O(N)`,optimal_space:n?.problems?.optimal_space||`O(1)`,description:n?.problems?.description||``,code:c}).catch(e=>{console.warn(`GitHub background auto-commit failed:`,e)}),e&&T.current&&(E.current=!0,T.current()),o(e=>{let t=e.slice(1);if(t.length>0){let e=t[0],n=e.problems,r=n?.problem_number??(/^\d+$/.test(e?.problem_id||``)?parseInt(e.problem_id,10):void 0),i=N(r,n?.id||e?.problem_id,n?.name)?.starter_code||n?.starter_code||``;g(i)}else g(``);return t}),j(!1)}else{let e=await s.json().catch(()=>({}));m(e.detail||`Server returned error (${s.status}). Please try again.`),o(r)}}catch(e){console.error(`Error logging review completion:`,e);let t=e instanceof Error?e.message:`Network connection failed while logging review.`;m(t),o(r)}finally{u(!1),f(null)}},[a,l,e,j,h]),F=(0,W.useCallback)(async()=>{if(_&&!y){b(!0);try{await A(_),await j()}catch(e){console.error(`Failed to activate next milestone:`,e)}finally{b(!1)}}},[_,y,j]),z=(0,W.useCallback)(()=>{let e=a[0],t=e?.problems,n=t?.problem_number??(/^\d+$/.test(e?.problem_id||``)?parseInt(e.problem_id,10):void 0),r=N(n,t?.id||e?.problem_id,t?.name)?.starter_code||t?.starter_code||``;g(r)},[a]);return{reviews:a,setReviews:o,loading:s,submitting:l,submittingRating:d,gradeError:p,setGradeError:m,code:h,setCode:g,nextMilestone:_,activatingMilestone:y,currentUserId:ee,fetchQueue:j,handleGrade:M,handleSelectCard:(0,W.useCallback)(t=>{if(t<=0||t>=a.length||l)return;e&&T.current&&(E.current=!0,T.current());let n=a[t];if(!n)return;let r=n.problems,i=r?.problem_number??(/^\d+$/.test(n?.problem_id||``)?parseInt(n.problem_id,10):void 0),s=N(i,r?.id||n?.problem_id,r?.name)?.starter_code||r?.starter_code||``;g(s),o(e=>{let t=e.findIndex(e=>e.id&&e.id===n.id||e===n);return t<=0?e:[e[t],...e.slice(0,t),...e.slice(t+1)]})},[a,l,e]),handleActivateNextMilestone:F,handleResetStarterCode:z}}function le(){return{sandboxRunning:j(e=>e.sandboxRunning),sandboxResults:j(e=>e.sandboxResults),sandboxError:j(e=>e.sandboxError),savingReference:j(e=>e.savingReference),savedRefSuccess:j(e=>e.savedRefSuccess),saveRefError:j(e=>e.saveRefError),handleRunSandbox:j(e=>e.handleRunSandbox),handleSaveReference:j(e=>e.handleSaveReference),resetSandbox:j(e=>e.resetSandbox)}}function ue(){return{aiLoading:j(e=>e.aiLoading),aiResult:j(e=>e.aiResult),aiError:j(e=>e.aiError),explainLoading:j(e=>e.explainLoading),explanationText:j(e=>e.explanationText),explainError:j(e=>e.explainError),aiSolutionLoading:j(e=>e.aiSolutionLoading),aiSolutionError:j(e=>e.aiSolutionError),handleAiEvaluation:j(e=>e.handleAiEvaluation),handleExplainCode:j(e=>e.handleExplainCode),handleFetchAiSolution:j(e=>e.handleFetchAiSolution),resetAiState:j(e=>e.resetAiState)}}var de=({problem:e,totalInQueue:t,reviews:n=[],onSelectCard:r,onOpenCreateProblem:i,onOpenEditProblem:a})=>{let[c,l]=(0,W.useState)(!1),u=(0,W.useRef)(null);(0,W.useEffect)(()=>{let e=e=>{u.current&&!u.current.contains(e.target)&&l(!1)},t=e=>{e.key===`Escape`&&l(!1)};return c&&(document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t)),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[c]);let d=e.problem_number?`https://leetcode.com/problemset/all/?search=${e.problem_number}`:`https://leetcode.com/problemset/all/?search=${encodeURIComponent(e.name||``)}`;return(0,G.jsxs)(`div`,{className:`shrink-0 bg-paper-white border-b-[3px] border-ink-black px-2.5 sm:px-4 py-2 flex flex-wrap items-center justify-between gap-2 shadow-[0_2px_0_0_rgba(30,41,59,0.05)] relative z-40`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 sm:gap-2 flex-wrap min-w-0`,children:[(0,G.jsxs)(`div`,{className:`relative shrink-0`,ref:u,children:[(0,G.jsxs)(`button`,{onClick:()=>l(e=>!e),className:`h-7 inline-flex items-center gap-1.5 px-2 sm:px-2.5 bg-amber-300 hover:bg-amber-200 border-2 border-ink-black shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none transition-all cursor-pointer shrink-0`,title:`Click to view all cards due in today's queue`,children:[(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-emerald-500 animate-ping shrink-0`}),(0,G.jsx)(`span`,{className:`font-arcade text-[8px] sm:text-[9px] font-bold text-ink-black tracking-wide whitespace-nowrap`,children:`CARD 1 OF ${t}`}),t>1&&(0,G.jsx)(w,{className:`w-3 h-3 text-ink-black transition-transform shrink-0 ${c?`rotate-180`:``}`})]}),c&&n.length>0&&(0,G.jsxs)(`div`,{className:`absolute top-9 left-0 z-50 w-64 min-[400px]:w-72 sm:w-80 bg-paper-white border-[3px] border-ink-black gadget-shadow p-3 space-y-2 max-w-[calc(100vw-32px)]`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between border-b-2 border-ink-black pb-1.5 font-arcade text-[9px] font-bold text-ink-black`,children:[(0,G.jsx)(`span`,{children:`DAILY QUEUE (${n.length} CARDS)`}),(0,G.jsx)(`button`,{onClick:()=>l(!1),className:`px-1 hover:text-rose-600 font-bold cursor-pointer`,title:`Close`,children:`✕`})]}),(0,G.jsx)(`div`,{className:`text-[7.5px] font-arcade text-trash-gray uppercase -mt-0.5`,children:`Click any card to solve it now:`}),(0,G.jsx)(`div`,{className:`max-h-60 overflow-y-auto no-scrollbar space-y-1.5 pr-1`,children:n.map((e,t)=>{let n=e.problems,i=n?.problem_number,a=i==null?void 0:M(i),{cleanTitle:s,approachVariant:c}=oe(n?.name||``,a?.name),u=c?`${s} (${c})`:s,d=t===0,f=n?.difficulty,p=f?f.toUpperCase():`EASY`,m=f===`Easy`?`bg-emerald-600 text-white`:f===`Medium`?`bg-amber-400 text-ink-black`:`bg-rose-600 text-white`;return(0,G.jsxs)(`button`,{type:`button`,onClick:()=>{d||r?.(t),l(!1)},className:`group w-full text-left p-2 border-2 border-ink-black text-xs flex items-center justify-between gap-2 cursor-pointer transition-all duration-150 select-none ${d?`bg-amber-100 font-bold shadow-[2px_2px_0px_0px_rgba(30,41,59,1)]`:`bg-white hover:bg-amber-50 hover:translate-x-0.5 active:translate-y-0.5 active:shadow-none shadow-[2px_2px_0px_0px_rgba(30,41,59,0.25)]`}`,title:d?`Currently active card`:`Jump to #${t+1}: ${u}`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 truncate min-w-0`,children:[(0,G.jsxs)(`span`,{className:`font-arcade text-[9px] text-trash-gray shrink-0`,children:[`#`,t+1]}),i!=null&&(0,G.jsxs)(`span`,{className:`font-arcade text-[8px] font-bold px-1 py-0.2 bg-amber-300 border border-ink-black shrink-0`,children:[`LC #`,i]}),(0,G.jsx)(`span`,{className:`truncate`,children:u})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 shrink-0`,children:[d?(0,G.jsx)(`span`,{className:`text-[7.5px] font-arcade font-extrabold px-1 py-0.5 bg-amber-300 text-ink-black border border-ink-black shrink-0`,children:`NOW`}):(0,G.jsx)(o,{className:`w-2.5 h-2.5 fill-ink-black text-ink-black opacity-0 group-hover:opacity-100 transition-opacity shrink-0`}),(0,G.jsx)(`span`,{className:`text-[8px] font-arcade font-bold px-1.5 py-0.5 border border-ink-black shrink-0 ${m}`,children:p})]})]},e.id||t)})})]})]}),e.problem_number!==void 0&&e.problem_number!==null&&(0,G.jsx)(`span`,{className:`h-7 inline-flex items-center px-2 font-arcade text-[8px] sm:text-[9px] font-bold bg-amber-200 border-2 border-ink-black shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] text-ink-black shrink-0 select-none whitespace-nowrap`,children:e.problem_number>0?`LC #${e.problem_number}`:`CUSTOM`}),(0,G.jsx)(`span`,{className:`h-7 inline-flex items-center px-2 font-arcade text-[8px] sm:text-[9px] font-bold border-2 border-ink-black shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] shrink-0 select-none whitespace-nowrap ${e.difficulty===`Easy`?`bg-emerald-600 text-white`:e.difficulty===`Medium`?`bg-amber-400 text-ink-black`:`bg-rose-600 text-white`}`,children:e.difficulty?e.difficulty.toUpperCase():`EASY`})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 sm:gap-2 shrink-0 flex-wrap justify-end`,children:[(0,G.jsxs)(`button`,{onClick:i,className:`h-7 inline-flex items-center gap-1 px-2 sm:px-2.5 bg-white hover:bg-purple-50 border-2 border-ink-black text-ink-black text-[8px] sm:text-[9px] font-arcade font-bold shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none transition-all cursor-pointer shrink-0`,title:`Create or Import Problem`,children:[(0,G.jsx)(f,{className:`w-3 h-3 text-purple-600 shrink-0`}),(0,G.jsx)(`span`,{className:`hidden min-[480px]:inline`,children:`ADD`})]}),a&&(0,G.jsxs)(`button`,{onClick:a,className:`h-7 inline-flex items-center gap-1 px-2 sm:px-2.5 bg-white hover:bg-emerald-50 border-2 border-ink-black text-ink-black text-[8px] sm:text-[9px] font-arcade font-bold shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none transition-all cursor-pointer shrink-0`,title:`Edit Problem Specification`,children:[(0,G.jsx)(s,{className:`w-3 h-3 text-emerald-600 shrink-0`}),(0,G.jsx)(`span`,{className:`hidden min-[480px]:inline`,children:`EDIT`})]}),e.google_doc_url&&(0,G.jsxs)(`a`,{href:e.google_doc_url,target:`_blank`,rel:`noreferrer`,className:`h-7 inline-flex items-center gap-1 px-2 sm:px-2.5 bg-white hover:bg-slate-100 border-2 border-ink-black text-ink-black text-[8px] sm:text-[9px] font-arcade font-bold shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none transition-all cursor-pointer shrink-0`,title:`Open Google Doc Notes`,children:[(0,G.jsx)(`span`,{children:`DOC`}),(0,G.jsx)(x,{className:`w-2.5 h-2.5 text-primary shrink-0`})]}),(0,G.jsxs)(`a`,{href:d,target:`_blank`,rel:`noreferrer`,className:`h-7 inline-flex items-center gap-1 px-2 sm:px-2.5 bg-white hover:bg-slate-100 border-2 border-ink-black text-ink-black text-[8px] sm:text-[9px] font-arcade font-bold shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none transition-all cursor-pointer shrink-0`,title:`Search LeetCode`,children:[(0,G.jsx)(`span`,{children:`LC`}),(0,G.jsx)(x,{className:`w-2.5 h-2.5 text-amber-600 shrink-0`})]})]})]})},fe=re.mark({class:`cm-indent-dot cm-indent-dot-primary`}),pe=re.mark({class:`cm-indent-dot cm-indent-dot-secondary`});function me(e){let t=new V;for(let{from:n,to:r}of e.visibleRanges){let i=n;for(;i<r;){let n=e.state.doc.lineAt(i),r=n.text,a=0;for(;a<r.length&&(r[a]===` `||r[a]===` `);){let e=n.from+a,i=e+1,o=a%4==0||r[a]===` `;t.add(e,i,o?fe:pe),a++}i=n.to+1}}return t.finish()}var he=te.fromClass(class{decorations;constructor(e){this.decorations=me(e)}update(e){(e.docChanged||e.viewportChanged)&&(this.decorations=me(e.view))}},{decorations:e=>e.decorations}),ge=H.theme({"&":{backgroundColor:`#0c111d`,color:`#f1f5f9`,height:`100%`,fontSize:`13px`,fontFamily:`var(--font-code, "JetBrains Mono", "Fira Code", monospace)`},".cm-scroller":{overflow:`auto`,fontFamily:`inherit`,lineHeight:`1.65`},".cm-content":{caretColor:`#4ade80`,padding:`12px 0`},"&.cm-focused .cm-cursor":{borderLeftColor:`#4ade80`,borderLeftWidth:`2px`,filter:`drop-shadow(0 0 5px rgba(74, 222, 128, 0.8))`},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, ::selection":{backgroundColor:`rgba(56, 189, 248, 0.25) !important`},".cm-gutters":{backgroundColor:`#070a12`,color:`#475569`,borderRight:`2px solid #1e293b`,paddingRight:`6px`,userSelect:`none`},".cm-activeLineGutter":{backgroundColor:`#131b2e`,color:`#38bdf8`,fontWeight:`700`},".cm-activeLine, &.cm-focused .cm-activeLine":{backgroundColor:`#0f172a !important`},".cm-line":{padding:`0 10px`},".cm-indent-dot":{position:`relative`,display:`inline-block`},".cm-indent-dot::before":{position:`absolute`,top:`50%`,left:`50%`,transform:`translate(-50%, -50%)`,pointerEvents:`none`,userSelect:`none`,lineHeight:`0`,fontFamily:`monospace`},".cm-indent-dot-primary::before":{content:`"•"`,color:`#38bdf8`,fontSize:`9px`,opacity:`0.85`},".cm-indent-dot-secondary::before":{content:`"·"`,color:`#64748b`,fontSize:`11px`,opacity:`0.5`},"&.cm-focused .cm-matchingBracket, .cm-matchingBracket":{backgroundColor:`rgba(74, 222, 128, 0.2)`,outline:`1px solid #4ade80`,borderRadius:`2px`,color:`#86efac !important`},".cm-placeholder":{color:`#64748b`,fontStyle:`italic`},".cm-scroller::-webkit-scrollbar":{width:`6px`,height:`6px`},".cm-scroller::-webkit-scrollbar-track":{backgroundColor:`#070a12`},".cm-scroller::-webkit-scrollbar-thumb":{backgroundColor:`#1e293b`,borderRadius:`3px`,border:`1px solid #334155`},".cm-scroller::-webkit-scrollbar-thumb:hover":{backgroundColor:`#38bdf8`}}),K=[ne(),ie.of(` `),B.of([U]),he,ge,H.contentAttributes.of({"aria-label":`Python Code Editor`})],_e=[{id:`python`,name:`Python`,version:`3.14`}],ve=({className:e=`w-3.5 h-3.5`})=>(0,G.jsxs)(`svg`,{viewBox:`0 0 128 128`,className:e,xmlns:`http://www.w3.org/2000/svg`,children:[(0,G.jsx)(`path`,{d:`M63.454 4.018c-14.775 0-23.774 6.425-23.774 18.775v13.626h24.168v3.424H30.082C17.518 39.843 8 47.962 8 63.673c0 15.65 8.358 23.486 21.056 23.486h11.905v-16.89c0-13.064 11.233-24.113 24.331-24.113h23.773V32.793c0-11.83-9.988-19.775-23.773-19.775H63.454v-9zm-9.845 7.426a3.84 3.84 0 0 1 3.86 3.84 3.84 3.84 0 0 1-3.86 3.841 3.84 3.84 0 0 1-3.86-3.84 3.84 3.84 0 0 1 3.86-3.841z`,fill:`#387eb8`}),(0,G.jsx)(`path`,{d:`M64.546 123.982c14.775 0 23.774-6.425 23.774-18.775V91.581H64.152v-3.424h33.766c12.564 0 22.082-8.119 22.082-23.83 0-15.65-8.358-23.486-21.056-23.486H87.04v16.89c0 13.064-11.234 24.113-24.332 24.113H38.934v13.363c0 11.83 9.989 19.775 23.774 19.775h1.838v9zm9.845-7.426a3.84 3.84 0 0 1-3.86-3.84 3.84 3.84 0 0 1 3.86-3.841 3.84 3.84 0 0 1 3.86 3.84 3.84 3.84 0 0 1-3.86 3.841z`,fill:`#ffe052`})]}),ye=({mobileView:e,isNarrow:t=!1,isAutocompleteEnabled:a,onToggleAutocomplete:s,onResetStarterCode:c,code:l,onChangeCode:f,sandboxRunning:m,sandboxError:h,sandboxResults:v,onRunSandbox:y,savingReference:S,savedRefSuccess:D,saveRefError:O,onSaveReference:k,aiLoading:A,aiError:j,aiResult:M,onAiEvaluation:N,optimalTime:P,optimalSpace:F,onPushToGitHub:I,pushingToGitHub:L,githubPushedUrl:R,githubPushError:z})=>{let[B,te]=(0,W.useState)(`python`),[V,H]=(0,W.useState)(!1),U=(0,W.useRef)(null);(0,W.useEffect)(()=>{let e=e=>{U.current&&!U.current.contains(e.target)&&H(!1)},t=e=>{e.key===`Escape`&&H(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[]);let ne=_e.find(e=>e.id===B)??_e[0];return(0,G.jsxs)(`div`,{className:`w-full ${t?`flex flex-1`:`lg:w-[51%] flex`} flex-col bg-[#fffdfa] overflow-y-auto no-scrollbar ${t&&e!==`code`?`hidden`:`flex`}`,children:[(0,G.jsxs)(`div`,{className:`shrink-0 bg-[#f7f5ed] border-b-2 border-ink-black p-2 sm:px-3 flex flex-wrap items-center justify-between gap-1.5 sm:gap-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 sm:gap-2 flex-wrap`,children:[(0,G.jsxs)(`div`,{className:`relative`,ref:U,children:[(0,G.jsxs)(`button`,{type:`button`,onClick:()=>H(e=>!e),className:`h-7 px-2.5 bg-white hover:bg-slate-100 border-2 border-ink-black shadow-[1px_1px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none flex items-center gap-1.5 font-arcade text-[9px] font-bold text-ink-black cursor-pointer transition-all select-none`,title:`Select programming language`,"aria-expanded":V,"aria-haspopup":`listbox`,children:[(0,G.jsx)(ve,{className:`w-3.5 h-3.5 shrink-0`}),(0,G.jsx)(`span`,{children:ne.name}),(0,G.jsx)(w,{className:`w-3 h-3 text-ink-black transition-transform duration-150 ${V?`rotate-180`:``}`})]}),V&&(0,G.jsxs)(`div`,{className:`absolute top-full mt-1.5 left-0 z-50 w-52 bg-paper-white border-[3px] border-ink-black gadget-shadow p-1.5 space-y-1`,role:`listbox`,children:[(0,G.jsx)(`div`,{className:`px-2 py-1 text-[8px] font-arcade font-bold text-trash-gray uppercase border-b border-slate-200`,children:`SELECT LANGUAGE`}),_e.map(e=>{let t=B===e.id;return(0,G.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":t,onClick:()=>{te(e.id),H(!1)},className:`w-full flex items-center justify-between px-2.5 py-1.5 border-2 border-ink-black text-left transition-all cursor-pointer ${t?`bg-amber-200 shadow-[1px_1px_0px_0px_rgba(30,41,59,1)] font-bold text-ink-black`:`bg-white hover:bg-slate-100 text-slate-800`}`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 font-arcade text-[9px]`,children:[(0,G.jsx)(ve,{className:`w-3.5 h-3.5 shrink-0`}),(0,G.jsx)(`span`,{children:e.name})]}),(0,G.jsxs)(`span`,{className:`font-mono text-[8px] font-bold px-1.5 py-0.5 bg-white border border-ink-black text-slate-700 shadow-[1px_1px_0px_0px_rgba(30,41,59,0.3)]`,children:[`v`,e.version]})]},e.id)})]})]}),(0,G.jsx)(`div`,{className:`h-4 w-[2px] bg-slate-300 mx-0.5 hidden sm:block`}),(0,G.jsxs)(`label`,{className:`inline-flex items-center gap-1.5 cursor-pointer select-none`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:a,onChange:e=>s(e.target.checked),className:`sr-only peer`,"aria-label":`Toggle code editor autocompletion`}),(0,G.jsx)(`div`,{className:`relative w-7 h-3.5 bg-slate-300 border border-ink-black rounded-full peer peer-checked:bg-grass-green transition-all after:content-[''] after:absolute after:top-[1px] after:left-[2px] after:bg-white after:border after:border-ink-black after:rounded-full after:h-2 after:w-2 after:transition-all peer-checked:after:translate-x-3`}),(0,G.jsx)(`span`,{className:`text-[7.5px] min-[400px]:text-[8px] font-arcade font-bold text-trash-gray peer-checked:text-ink-black whitespace-nowrap`,children:`AUTOCOMPLETE`})]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 sm:gap-2`,children:[(0,G.jsx)(`button`,{onClick:c,className:`w-7 h-7 bg-white hover:bg-slate-100 border-2 border-ink-black shadow-[1px_1px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none text-ink-black flex items-center justify-center cursor-pointer transition-all`,title:`Reset to starter code`,"aria-label":`Reset to starter code`,children:(0,G.jsx)(_,{className:`w-3.5 h-3.5`})}),(0,G.jsx)(`button`,{onClick:()=>f(``),className:`w-7 h-7 bg-white hover:bg-rose-50 border-2 border-ink-black shadow-[1px_1px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none text-rose-700 flex items-center justify-center cursor-pointer transition-all`,title:`Clear editor`,"aria-label":`Clear editor`,children:(0,G.jsx)(b,{className:`w-3.5 h-3.5 text-rose-600`})}),k&&(0,G.jsx)(`button`,{onClick:k,disabled:S||!l.trim(),className:`w-7 h-7 border-2 border-ink-black shadow-[1px_1px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none flex items-center justify-center cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed transition-all ${D?`bg-emerald-600 hover:bg-emerald-500 text-white`:`bg-amber-400 hover:bg-amber-300 text-ink-black`}`,title:S?`Saving solution to personal database...`:D?`Saved to personal database!`:`Overwrite saved solution with studio code`,"aria-label":`Overwrite saved solution with studio code`,children:S?(0,G.jsx)(g,{className:`w-3.5 h-3.5 animate-spin text-ink-black`}):D?(0,G.jsx)(p,{className:`w-3.5 h-3.5 text-white`}):(0,G.jsx)(r,{className:`w-3.5 h-3.5 text-ink-black`})}),I&&(0,G.jsx)(`button`,{onClick:I,disabled:L||!l.trim(),className:`w-7 h-7 bg-[#24292e] hover:bg-black border-2 border-ink-black shadow-[1px_1px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none text-white flex items-center justify-center cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed transition-all`,title:L?`Pushing to GitHub...`:`Push solution to GitHub repository`,"aria-label":`Push to GitHub`,children:L?(0,G.jsx)(g,{className:`w-3.5 h-3.5 animate-spin text-yellow-300`}):(0,G.jsx)(u,{className:`w-3.5 h-3.5 text-yellow-300`})})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 sm:gap-2`,children:[(0,G.jsx)(`button`,{onClick:y,disabled:m||!l.trim(),className:`w-7 h-7 bg-emerald-600 hover:bg-emerald-500 border-2 border-ink-black shadow-[1px_1px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none text-white flex items-center justify-center cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed transition-all`,title:m?`Running sandbox tests...`:`Run tests in local sandbox`,"aria-label":`Run tests`,children:m?(0,G.jsx)(g,{className:`w-3.5 h-3.5 animate-spin`}):(0,G.jsx)(o,{className:`w-3.5 h-3.5 fill-white text-white ml-0.5`})}),(0,G.jsx)(`button`,{onClick:N,disabled:A||!l.trim(),className:`w-7 h-7 bg-purple-600 hover:bg-purple-500 border-2 border-ink-black shadow-[1px_1px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none text-white flex items-center justify-center cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed transition-all`,title:A?`Evaluating code with Gemini...`:`Gemini Eval (AI code review & complexity)`,"aria-label":`Gemini Eval`,children:A?(0,G.jsx)(g,{className:`w-3.5 h-3.5 animate-spin`}):(0,G.jsx)(T,{className:`w-3.5 h-3.5 text-amber-300`})})]})]}),(0,G.jsxs)(`div`,{className:`p-4 sm:p-5 flex-1 flex flex-col space-y-4`,children:[(0,G.jsx)(`div`,{className:`flex-1 flex flex-col min-h-[300px] sm:min-h-[360px] border-[3px] border-ink-black shadow-[4px_4px_0px_0px_rgba(30,41,59,1)] bg-[#0c111d] overflow-hidden`,children:(0,G.jsx)(`div`,{className:`flex-1 overflow-hidden relative`,children:(0,G.jsx)(ee,{value:l,onChange:f,placeholder:`def solve(nums):
|
| 5 |
-
# Write your solution from memory here...`,height:`100%`,theme:`dark`,extensions:K,basicSetup:{autocompletion:a,lineNumbers:!0,foldGutter:!0,dropCursor:!0,allowMultipleSelections:!0,indentOnInput:!0,bracketMatching:!0,closeBrackets:!0,rectangularSelection:!0,crosshairCursor:!0,highlightActiveLine:!0,highlightSelectionMatches:!0,closeBracketsKeymap:!0,defaultKeymap:!0,searchKeymap:!0,historyKeymap:!0,foldKeymap:!0,completionKeymap:!0,lintKeymap:!0},className:`w-full h-full text-xs font-code-mono`})})}),D&&(0,G.jsxs)(`div`,{className:`p-3 bg-[#f0fdf4] border-2 border-emerald-600 text-emerald-950 text-xs font-semibold flex items-center gap-2 shadow-[2px_2px_0px_0px_rgba(30,41,59,1)]`,children:[(0,G.jsx)(p,{className:`w-4 h-4 text-emerald-600 shrink-0`}),(0,G.jsx)(`span`,{children:`Successfully saved studio code as your personal reference solution!`})]}),O&&(0,G.jsxs)(`div`,{className:`p-3 bg-rose-50 border-2 border-rose-500 text-rose-800 text-xs font-semibold flex items-center gap-2 shadow-[2px_2px_0px_0px_rgba(30,41,59,1)]`,children:[(0,G.jsx)(d,{className:`w-4 h-4 text-rose-600 shrink-0`}),(0,G.jsx)(`span`,{children:O})]}),R&&(0,G.jsxs)(`div`,{className:`p-3 bg-[#f0fdf4] border-2 border-emerald-600 text-emerald-950 text-xs font-semibold flex items-center justify-between shadow-[2px_2px_0px_0px_rgba(30,41,59,1)]`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(p,{className:`w-4 h-4 text-emerald-600 shrink-0`}),(0,G.jsx)(`span`,{children:`Successfully pushed solution to your GitHub repository!`})]}),(0,G.jsxs)(`a`,{href:R,target:`_blank`,rel:`noopener noreferrer`,className:`text-[11px] font-bold text-blue-700 hover:text-blue-900 underline flex items-center gap-1`,children:[(0,G.jsx)(`span`,{children:`View on GitHub`}),(0,G.jsx)(x,{className:`w-3 h-3`})]})]}),z&&(0,G.jsxs)(`div`,{className:`p-3 bg-rose-50 border-2 border-rose-500 text-rose-800 text-xs font-semibold flex items-center gap-2 shadow-[2px_2px_0px_0px_rgba(30,41,59,1)]`,children:[(0,G.jsx)(d,{className:`w-4 h-4 text-rose-600 shrink-0`}),(0,G.jsx)(`span`,{children:z})]}),m&&(0,G.jsxs)(`div`,{className:`p-3 border-2 border-ink-black bg-emerald-50 shadow-[3px_3px_0px_0px_rgba(30,41,59,1)] flex items-center gap-3 animate-pulse`,children:[(0,G.jsx)(g,{className:`w-5 h-5 text-emerald-600 animate-spin shrink-0`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h4`,{className:`font-arcade text-[9px] font-bold text-ink-black uppercase`,children:`Running...`}),(0,G.jsx)(`p`,{className:`font-sans text-[11px] text-trash-gray font-semibold mt-0.5`,children:`Executing against test cases...`})]})]}),h&&(0,G.jsxs)(`div`,{className:`p-3 border-2 border-rose-500 bg-rose-50 text-rose-800 text-xs font-semibold shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] flex items-center gap-2`,children:[(0,G.jsx)(d,{className:`w-4 h-4 text-rose-600 shrink-0`}),(0,G.jsx)(`span`,{children:h})]}),v&&(0,G.jsxs)(`div`,{className:`border-[3px] border-ink-black p-4 sm:p-5 shadow-[4px_4px_0px_0px_rgba(30,41,59,1)] space-y-3.5 ${v.status===`passed`?`bg-[#f0fdf4]`:`bg-[#fff1f2]`}`,children:[(0,G.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-2 pb-2.5 border-b-2 border-dashed border-ink-black`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,G.jsx)(`div`,{className:`w-8 h-8 border-2 border-ink-black flex items-center justify-center font-bold shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] ${v.status===`passed`?`bg-grass-green text-ink-black`:`bg-rose-500 text-white`}`,children:v.status===`passed`?(0,G.jsx)(E,{className:`w-5 h-5 stroke-[3]`}):(0,G.jsx)(d,{className:`w-4 h-4`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`font-arcade text-[10px] font-bold text-ink-black flex items-center gap-1.5 uppercase`,children:v.status===`passed`?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{children:`ALL TESTS PASSED`}),(0,G.jsx)(p,{className:`w-3.5 h-3.5 text-emerald-600 inline`})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{children:v.status===`error`?`EXECUTION ERROR`:`TESTS FAILED`}),(0,G.jsx)(C,{className:`w-3.5 h-3.5 text-rose-600 inline`})]})}),(0,G.jsxs)(`div`,{className:`font-sans text-[11px] text-slate-600 font-semibold`,children:[v.passed_count??0,` of `,v.total_tests??0,` test cases passed (`,(v.duration_ms??0).toFixed(1),`ms)`]})]})]}),v.status===`passed`&&(0,G.jsxs)(`button`,{onClick:k,disabled:S,className:`px-3 py-1.5 bg-white hover:bg-emerald-100 border-2 border-ink-black text-ink-black font-arcade text-[8px] font-bold flex items-center gap-1.5 shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none transition-all cursor-pointer shrink-0 disabled:opacity-50`,children:[S?(0,G.jsx)(g,{className:`w-3 h-3 animate-spin`}):D?(0,G.jsx)(p,{className:`w-3.5 h-3.5 text-emerald-600`}):(0,G.jsx)(r,{className:`w-3.5 h-3.5 text-blue-600`}),(0,G.jsx)(`span`,{children:D?`SAVED TO DB!`:`SAVE AS OFFICIAL SOLUTION`})]})]}),O&&(0,G.jsx)(`div`,{className:`p-2 border border-rose-500 bg-rose-100 text-rose-800 text-[11px] font-semibold`,children:O}),v.results&&v.results.length>0&&(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsx)(`span`,{className:`font-arcade text-[8px] text-trash-gray uppercase font-bold block`,children:`TEST CASE BREAKDOWN:`}),(0,G.jsx)(`div`,{className:`space-y-1.5 max-h-56 overflow-y-auto custom-scrollbar`,children:v.results.map((e,t)=>(0,G.jsxs)(`div`,{className:`p-2.5 border-2 border-ink-black text-xs font-mono shadow-[2px_2px_0px_0px_rgba(30,41,59,0.3)] ${e.passed?`bg-white`:`bg-rose-50`}`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between font-arcade text-[8px] mb-1`,children:[(0,G.jsxs)(`span`,{className:`font-bold text-ink-black`,children:[`CASE #`,t+1]}),(0,G.jsx)(`span`,{className:e.passed?`text-emerald-700 font-bold`:`text-rose-700 font-bold`,children:e.passed?`✓ PASSED`:`✗ FAILED`})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-3 gap-1.5 text-[10px]`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-slate-500 block`,children:`Input:`}),(0,G.jsx)(`span`,{className:`font-code-mono text-ink-black font-semibold break-all`,children:JSON.stringify(e.input)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-slate-500 block`,children:`Expected:`}),(0,G.jsx)(`span`,{className:`font-code-mono text-emerald-700 font-semibold break-all`,children:JSON.stringify(e.expected)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`text-slate-500 block`,children:`Output:`}),(0,G.jsx)(`span`,{className:`font-code-mono font-semibold break-all ${e.passed?`text-emerald-700`:`text-rose-700`}`,children:e.output===void 0?`None`:JSON.stringify(e.output)})]})]}),e.error&&(0,G.jsx)(`div`,{className:`mt-1.5 p-1.5 bg-rose-100 text-rose-900 text-[10px] font-mono border border-rose-300 break-all`,children:e.error})]},t))})]}),v.error&&(0,G.jsx)(`div`,{className:`p-3 bg-[#1E293B] text-rose-400 font-code-mono text-[11px] border-2 border-ink-black overflow-x-auto whitespace-pre-wrap select-text`,children:v.error}),v.status===`passed`&&(0,G.jsx)(`div`,{className:`p-2 bg-emerald-100/70 border border-emerald-300 text-emerald-900 text-xs flex items-center justify-between`,children:(0,G.jsx)(`span`,{className:`font-sans font-medium`,children:`✨ All unit tests passed. Rate your recall below.`})})]}),A&&(0,G.jsxs)(`div`,{className:`p-4 border-2 border-ink-black bg-amber-50 shadow-[3px_3px_0px_0px_rgba(30,41,59,1)] flex items-center gap-3 animate-pulse`,children:[(0,G.jsx)(g,{className:`w-6 h-6 text-purple-600 animate-spin shrink-0`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h4`,{className:`font-arcade text-[9px] font-bold text-ink-black uppercase`,children:`ANALYZING...`}),(0,G.jsx)(`p`,{className:`font-sans text-[11px] text-trash-gray font-semibold mt-0.5`,children:`Checking edge cases, bounds, and Big-O efficiency against optimal constraints...`})]})]}),j&&(0,G.jsx)(`div`,{className:`p-3 border-2 border-rose-500 bg-rose-50 text-rose-800 text-xs font-semibold shadow-[2px_2px_0px_0px_rgba(30,41,59,1)]`,children:j}),M&&(0,G.jsxs)(`div`,{className:`border-[3px] border-ink-black bg-[#fefce8] p-4 sm:p-5 shadow-[4px_4px_0px_0px_rgba(30,41,59,1)] space-y-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between pb-3 border-b-2 border-dashed border-ink-black`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`div`,{className:`w-9 h-9 border-2 border-ink-black flex items-center justify-center font-bold shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] ${M.is_correct?`bg-grass-green text-ink-black`:`bg-rose-500 text-white`}`,children:M.is_correct?(0,G.jsx)(E,{className:`w-5 h-5 stroke-[3]`}):(0,G.jsx)(n,{className:`w-5 h-5`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`span`,{className:`font-arcade text-[10px] font-bold text-ink-black flex items-center gap-1.5`,children:M.is_correct?(0,G.jsxs)(G.Fragment,{children:[`STATUS: PASSED`,(0,G.jsx)(p,{className:`w-3.5 h-3.5 text-emerald-600 inline`})]}):(0,G.jsxs)(G.Fragment,{children:[`STATUS: FAILED`,(0,G.jsx)(C,{className:`w-3.5 h-3.5 text-rose-600 inline`})]})}),(0,G.jsx)(`span`,{className:`font-sans text-[11px] text-slate-600 font-semibold`,children:M.is_correct?`Algorithm matches expected logic and patterns.`:`Bugs or edge-case failures detected.`})]})]}),(0,G.jsx)(`span`,{className:`font-arcade text-[9px] px-2 py-1 border-2 border-ink-black uppercase font-bold shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] ${M.is_correct?`bg-emerald-100 text-emerald-800`:`bg-rose-100 text-rose-800`}`,children:M.is_correct?`CORRECT`:`INCORRECT`})]}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{className:`p-2.5 bg-white border-2 border-ink-black shadow-[2px_2px_0px_0px_rgba(30,41,59,1)]`,children:[(0,G.jsx)(`span`,{className:`font-arcade text-[8px] text-trash-gray block uppercase font-bold`,children:`Time Complexity`}),(0,G.jsxs)(`div`,{className:`flex items-baseline gap-2 mt-1`,children:[(0,G.jsx)(`span`,{className:`font-code-mono text-xs font-bold text-ink-black`,children:M.detected_complexity?.time||`N/A`}),(0,G.jsxs)(`span`,{className:`text-[10px] font-sans text-slate-500 font-semibold`,children:[`(Target: `,P||`O(N)`,`)`]})]})]}),(0,G.jsxs)(`div`,{className:`p-2.5 bg-white border-2 border-ink-black shadow-[2px_2px_0px_0px_rgba(30,41,59,1)]`,children:[(0,G.jsx)(`span`,{className:`font-arcade text-[8px] text-trash-gray block uppercase font-bold`,children:`Space Complexity`}),(0,G.jsxs)(`div`,{className:`flex items-baseline gap-2 mt-1`,children:[(0,G.jsx)(`span`,{className:`font-code-mono text-xs font-bold text-ink-black`,children:M.detected_complexity?.space||`N/A`}),(0,G.jsxs)(`span`,{className:`text-[10px] font-sans text-slate-500 font-semibold`,children:[`(Target: `,F||`O(1)`,`)`]})]})]})]}),M.bugs&&M.bugs.length>0&&(0,G.jsxs)(`div`,{className:`p-3 bg-white border-2 border-ink-black space-y-1.5 shadow-[2px_2px_0px_0px_rgba(30,41,59,1)]`,children:[(0,G.jsxs)(`span`,{className:`font-arcade text-[8px] text-rose-600 uppercase font-bold block flex items-center gap-1`,children:[(0,G.jsx)(d,{className:`w-3 h-3 text-rose-500`}),`TRACES & EDGE CASE ISSUES:`]}),(0,G.jsx)(`ul`,{className:`list-disc list-inside text-xs text-slate-800 space-y-1 font-semibold pl-1`,children:M.bugs.map((e,t)=>(0,G.jsx)(`li`,{className:`leading-relaxed select-text`,children:e},t))})]}),M.key_suggestion&&(0,G.jsxs)(`div`,{className:`p-3 bg-amber-50 border-2 border-ink-black space-y-1 shadow-[2px_2px_0px_0px_rgba(30,41,59,1)]`,children:[(0,G.jsxs)(`span`,{className:`font-arcade text-[8px] text-amber-700 uppercase font-bold block flex items-center gap-1`,children:[(0,G.jsx)(T,{className:`w-3 h-3 text-amber-500`}),`TIP:`]}),(0,G.jsx)(`p`,{className:`text-xs text-slate-800 font-medium leading-relaxed m-0 select-text`,children:M.key_suggestion})]}),(0,G.jsxs)(`div`,{className:`p-2.5 bg-white border-2 border-dashed border-ink-black flex items-center justify-between`,children:[(0,G.jsxs)(`span`,{className:`text-xs font-bold text-ink-black flex items-center gap-1.5`,children:[(0,G.jsx)(i,{className:`w-4 h-4 text-primary`}),`Recommendation:`]}),(0,G.jsx)(`span`,{className:`font-arcade text-[9px] font-bold text-purple-700`,children:M.is_correct?`Rate your recall below.`:`Review issues and rate recall below.`})]})]})]})]})},be=({gradeError:e,onDismissGradeError:t,submitting:n,submittingRating:r,onGrade:i})=>(0,G.jsx)(`div`,{className:`shrink-0 bg-[#f8f5eb] border-t-[3px] border-ink-black p-2 sm:p-3 flex flex-col items-stretch gap-1.5 sm:gap-2 shadow-[0_-3px_0_0_rgba(30,41,59,0.08)]`,children:(0,G.jsxs)(`div`,{className:`w-full flex flex-col`,children:[e&&(0,G.jsxs)(`div`,{className:`p-2.5 mb-2 bg-red-100 border-2 border-red-500 text-red-800 text-xs font-semibold shadow-[2px_2px_0px_0px_#1E293B] flex items-center justify-between`,children:[(0,G.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(d,{className:`w-4 h-4 text-red-600 shrink-0`}),e]}),(0,G.jsx)(`button`,{onClick:t,className:`text-red-900 font-bold hover:underline cursor-pointer ml-2 text-xs`,children:`Dismiss`})]}),(0,G.jsxs)(`div`,{className:`flex gap-1.5 sm:gap-2.5 w-full`,children:[(0,G.jsx)(`button`,{onClick:()=>i(1),disabled:n,className:`flex-1 min-w-0 bg-[#dc2626] hover:bg-[#b91c1c] border-2 sm:border-[3px] border-ink-black py-2 sm:py-2.5 px-1 sm:px-2 arcade-btn cursor-pointer disabled:opacity-60 text-white flex flex-col items-center justify-center font-bold transition-all select-none`,title:`Press 1 on keyboard`,children:r===1?(0,G.jsx)(`div`,{className:`flex items-center gap-1.5 font-arcade text-[10px]`,children:(0,G.jsx)(g,{className:`w-3.5 h-3.5 animate-spin`})}):(0,G.jsxs)(`div`,{className:`flex items-center gap-1 font-headline-md text-[10px] min-[400px]:text-xs sm:text-sm font-extrabold tracking-wide uppercase truncate`,children:[(0,G.jsx)(`span`,{className:`font-arcade text-[8px] sm:text-[9px] px-1 py-0.5 bg-black/20 rounded shrink-0`,children:`1`}),(0,G.jsx)(`span`,{className:`truncate`,children:`Again`})]})}),(0,G.jsx)(`button`,{onClick:()=>i(2),disabled:n,className:`flex-1 min-w-0 bg-[#ff9933] hover:bg-[#ff8000] border-2 sm:border-[3px] border-ink-black py-2 sm:py-2.5 px-1 sm:px-2 arcade-btn cursor-pointer disabled:opacity-60 text-ink-black flex flex-col items-center justify-center font-bold transition-all select-none`,title:`Press 2 on keyboard`,children:r===2?(0,G.jsx)(`div`,{className:`flex items-center gap-1.5 font-arcade text-[10px]`,children:(0,G.jsx)(g,{className:`w-3.5 h-3.5 animate-spin text-ink-black`})}):(0,G.jsxs)(`div`,{className:`flex items-center gap-1 font-headline-md text-[10px] min-[400px]:text-xs sm:text-sm font-extrabold tracking-wide uppercase truncate`,children:[(0,G.jsx)(`span`,{className:`font-arcade text-[8px] sm:text-[9px] px-1 py-0.5 bg-black/10 rounded shrink-0`,children:`2`}),(0,G.jsx)(`span`,{className:`truncate`,children:`Hard`})]})}),(0,G.jsx)(`button`,{onClick:()=>i(3),disabled:n,className:`flex-1 min-w-0 bg-[#4ade80] hover:bg-[#22c55e] border-2 sm:border-[3px] border-ink-black py-2 sm:py-2.5 px-1 sm:px-2 arcade-btn cursor-pointer disabled:opacity-60 text-ink-black flex flex-col items-center justify-center font-bold transition-all select-none`,title:`Press 3 on keyboard`,children:r===3?(0,G.jsx)(`div`,{className:`flex items-center gap-1.5 font-arcade text-[10px]`,children:(0,G.jsx)(g,{className:`w-3.5 h-3.5 animate-spin text-ink-black`})}):(0,G.jsxs)(`div`,{className:`flex items-center gap-1 font-headline-md text-[10px] min-[400px]:text-xs sm:text-sm font-extrabold tracking-wide uppercase truncate`,children:[(0,G.jsx)(`span`,{className:`font-arcade text-[8px] sm:text-[9px] px-1 py-0.5 bg-black/10 rounded shrink-0`,children:`3`}),(0,G.jsx)(`span`,{className:`truncate`,children:`Good`})]})}),(0,G.jsx)(`button`,{onClick:()=>i(4),disabled:n,className:`flex-1 min-w-0 bg-[#60a5fa] hover:bg-[#3b82f6] border-2 sm:border-[3px] border-ink-black py-2 sm:py-2.5 px-1 sm:px-2 arcade-btn cursor-pointer disabled:opacity-60 text-ink-black flex flex-col items-center justify-center font-bold transition-all select-none`,title:`Press 4 on keyboard`,children:r===4?(0,G.jsx)(`div`,{className:`flex items-center gap-1.5 font-arcade text-[10px]`,children:(0,G.jsx)(g,{className:`w-3.5 h-3.5 animate-spin text-ink-black`})}):(0,G.jsxs)(`div`,{className:`flex items-center gap-1 font-headline-md text-[10px] min-[400px]:text-xs sm:text-sm font-extrabold tracking-wide uppercase truncate`,children:[(0,G.jsx)(`span`,{className:`font-arcade text-[8px] sm:text-[9px] px-1 py-0.5 bg-black/10 rounded shrink-0`,children:`4`}),(0,G.jsx)(`span`,{className:`truncate`,children:`Easy`})]})})]})]})}),xe=({nextMilestone:e,activatingMilestone:t,onActivateNextMilestone:n,onOpenOnboarding:r,onOpenJourney:i,onOpenCreateProblem:a,onOpenWindow:o,overrideProblemId:s,onClearOverride:c,hasCustomOnboardingModal:u,isOnboardingOpen:d,onCloseOnboarding:p,onCompletedOnboarding:y,currentUserId:b})=>(0,G.jsx)(`div`,{className:`w-full h-full flex items-center justify-center bg-[#fdf8e1] p-6 overflow-y-auto custom-scrollbar`,children:(0,G.jsxs)(`div`,{className:`w-full max-w-lg bg-paper-white border-[4px] border-ink-black gadget-shadow p-6 sm:p-8 relative overflow-hidden text-center space-y-6`,children:[(0,G.jsx)(`div`,{className:`absolute top-0 left-0 right-0 h-3 bg-gradient-to-r from-grass-green via-amber-300 to-highlight-pink`}),(0,G.jsxs)(`div`,{className:`relative inline-block mt-2`,children:[(0,G.jsx)(`div`,{className:`w-20 h-20 bg-amber-300 border-[3px] border-ink-black rounded-2xl flex items-center justify-center mx-auto gadget-shadow rotate-[-3deg] hover:rotate-0 transition-transform`,children:(0,G.jsx)(S,{className:`w-10 h-10 text-ink-black stroke-[2.5]`})}),(0,G.jsx)(`div`,{className:`absolute -bottom-2 -right-2 bg-grass-green border-2 border-ink-black px-2 py-0.5 font-arcade text-[8px] text-ink-black font-bold uppercase shadow-[2px_2px_0px_0px_rgba(30,41,59,1)]`,children:`100% DONE`})]}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2.5 py-1 bg-emerald-100 border-2 border-ink-black text-emerald-800 font-arcade text-[9px] font-bold`,children:[(0,G.jsx)(E,{className:`w-3 h-3 stroke-[3]`}),` ALL CARDS COMPLETED FOR TODAY`]}),(0,G.jsx)(`h2`,{className:`text-2xl sm:text-3xl font-extrabold text-ink-black font-headline-md tracking-tight`,children:`You're all caught up for today. Keep it up.`}),(0,G.jsx)(`p`,{className:`text-xs sm:text-sm font-sans text-trash-gray max-w-md mx-auto leading-relaxed font-semibold`,children:`All reviews for today are finished. Next reviews are scheduled for tomorrow.`})]}),e&&(0,G.jsxs)(`div`,{className:`p-4 sm:p-5 bg-gradient-to-br from-amber-50 to-orange-50 border-[3px] border-ink-black gadget-shadow text-left space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`span`,{className:`font-arcade text-[9px] font-bold text-amber-800 uppercase tracking-wider flex items-center gap-1.5`,children:[(0,G.jsx)(h,{className:`w-3.5 h-3.5 text-amber-600`}),`NEXT UNEXPLORED MILESTONE`]}),(0,G.jsxs)(`span`,{className:`font-mono text-[10px] font-bold px-2 py-0.5 rounded bg-amber-900/10 text-amber-900 border border-amber-900/20`,children:[`LC #`,e.problem_number]})]}),(0,G.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-3`,children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`h3`,{className:`font-headline-md text-base sm:text-lg font-bold text-ink-black truncate`,children:e.name}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mt-1 flex-wrap`,children:[(0,G.jsx)(`span`,{className:`px-2 py-0.5 rounded font-arcade text-[8px] font-bold uppercase text-white ${e.difficulty===`Easy`?`bg-emerald-600`:e.difficulty===`Medium`?`bg-amber-600`:`bg-rose-600`}`,children:e.difficulty}),(0,G.jsx)(`span`,{className:`px-2 py-0.5 rounded font-arcade text-[8px] bg-purple-100 text-purple-800 border border-purple-300 font-bold`,children:e.pattern}),(0,G.jsxs)(`span`,{className:`text-[11px] font-code-mono text-slate-600`,children:[`T: `,e.time_complexity,` | S: `,e.space_complexity]})]})]}),(0,G.jsx)(`button`,{onClick:n,disabled:t,className:`px-4 py-2.5 bg-grass-green hover:bg-emerald-400 text-ink-black font-arcade text-[9px] font-bold border-2 border-ink-black shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none transition-all cursor-pointer shrink-0 flex items-center justify-center gap-1.5 disabled:opacity-50`,children:t?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(g,{className:`w-3.5 h-3.5 animate-spin`}),(0,G.jsx)(`span`,{children:`ACTIVATING...`})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(T,{className:`w-3.5 h-3.5 text-amber-700`}),(0,G.jsx)(`span`,{children:`ACTIVATE & REVIEW NOW`})]})})]})]}),(0,G.jsxs)(`div`,{className:`p-4 sm:p-5 bg-gradient-to-r from-amber-100 via-amber-200 to-yellow-100 border-[3px] border-ink-black gadget-shadow text-left flex flex-col sm:flex-row items-start sm:items-center justify-between gap-3`,children:[(0,G.jsxs)(`div`,{className:`space-y-1`,children:[(0,G.jsxs)(`span`,{className:`font-arcade text-[9px] font-bold text-amber-900 uppercase flex items-center gap-1.5`,children:[(0,G.jsx)(v,{className:`w-3.5 h-3.5 text-amber-700`}),`FAST-TRACK EXPEDITION ENROLLMENT`]}),(0,G.jsx)(`h3`,{className:`font-headline-md text-base sm:text-lg font-bold text-ink-black`,children:`Already Solved Problems Elsewhere?`}),(0,G.jsx)(`p`,{className:`font-sans text-xs text-trash-gray font-semibold max-w-md`,children:`Check off problems you've already solved elsewhere to seed your review queue.`})]}),(0,G.jsxs)(`button`,{onClick:r,className:`px-4 py-2.5 bg-amber-400 hover:bg-amber-300 text-ink-black font-arcade text-[9px] font-bold border-2 border-ink-black shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none transition-all cursor-pointer shrink-0 flex items-center gap-1.5`,children:[(0,G.jsx)(v,{className:`w-3.5 h-3.5 text-amber-900`}),(0,G.jsx)(`span`,{children:`OPEN 150-PROBLEM CHECKLIST`})]})]}),(0,G.jsxs)(`div`,{className:`border-t-[3px] border-dashed border-ink-black pt-5 space-y-3`,children:[(0,G.jsx)(`div`,{className:`text-[9px] font-arcade text-trash-gray uppercase font-bold text-left`,children:`CONTINUE PRACTICING:`}),(0,G.jsxs)(`div`,{className:`grid grid-cols-2 sm:grid-cols-4 gap-2.5`,children:[(0,G.jsxs)(`button`,{onClick:i,className:`p-3 bg-amber-100 hover:bg-amber-200 border-[3px] border-ink-black text-left flex flex-col justify-between gadget-shadow active:translate-y-1 active:shadow-none transition-all cursor-pointer`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(h,{className:`w-4 h-4 text-amber-600`}),(0,G.jsx)(m,{className:`w-3 h-3 text-ink-black`})]}),(0,G.jsxs)(`div`,{className:`mt-2`,children:[(0,G.jsx)(`div`,{className:`font-arcade text-[8px] font-bold text-ink-black uppercase`,children:`Journey Trail`}),(0,G.jsx)(`div`,{className:`font-sans text-[10px] text-trash-gray font-semibold`,children:`150 Curated nodes`})]})]}),(0,G.jsxs)(`button`,{onClick:a,className:`p-3 bg-purple-100 hover:bg-purple-200 border-[3px] border-ink-black text-left flex flex-col justify-between gadget-shadow active:translate-y-1 active:shadow-none transition-all cursor-pointer`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(f,{className:`w-4 h-4 text-purple-700`}),(0,G.jsx)(m,{className:`w-3 h-3 text-ink-black`})]}),(0,G.jsxs)(`div`,{className:`mt-2`,children:[(0,G.jsx)(`div`,{className:`font-arcade text-[8px] font-bold text-ink-black uppercase`,children:`Add Problem`}),(0,G.jsx)(`div`,{className:`font-sans text-[10px] text-trash-gray font-semibold`,children:`New LeetCode entry`})]})]}),(0,G.jsxs)(`button`,{onClick:()=>o?.(`companion`),className:`p-3 bg-yellow-100 hover:bg-yellow-200 border-[3px] border-ink-black text-left flex flex-col justify-between gadget-shadow active:translate-y-1 active:shadow-none transition-all cursor-pointer`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`span`,{className:`material-symbols-outlined text-amber-600 text-lg`,children:`castle`}),(0,G.jsx)(m,{className:`w-3 h-3 text-ink-black`})]}),(0,G.jsxs)(`div`,{className:`mt-2`,children:[(0,G.jsx)(`div`,{className:`font-arcade text-[8px] font-bold text-ink-black uppercase`,children:`Princess Tower`}),(0,G.jsx)(`div`,{className:`font-sans text-[10px] text-trash-gray font-semibold`,children:`Visit Aurelia`})]})]}),(0,G.jsxs)(`button`,{onClick:()=>o?.(`computer`),className:`p-3 bg-cyan-100 hover:bg-cyan-200 border-[3px] border-ink-black text-left flex flex-col justify-between gadget-shadow active:translate-y-1 active:shadow-none transition-all cursor-pointer`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(l,{className:`w-4 h-4 text-cyan-700`}),(0,G.jsx)(m,{className:`w-3 h-3 text-ink-black`})]}),(0,G.jsxs)(`div`,{className:`mt-2`,children:[(0,G.jsx)(`div`,{className:`font-arcade text-[8px] font-bold text-ink-black uppercase`,children:`File Explorer`}),(0,G.jsx)(`div`,{className:`font-sans text-[10px] text-trash-gray font-semibold`,children:`Browse all files`})]})]})]})]}),s&&c&&(0,G.jsxs)(`button`,{onClick:c,className:`mt-3 bg-white hover:bg-slate-100 border-[3px] border-ink-black text-ink-black font-bold px-4 py-2 text-xs uppercase tracking-wide shadow-[3px_3px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none transition-all cursor-pointer inline-flex items-center gap-2`,children:[(0,G.jsx)(_,{className:`w-3.5 h-3.5`}),` Return to Scheduled Queue`]}),!u&&(0,G.jsx)(z,{isOpen:d,onClose:p,onCompleted:y,userId:b})]})}),Se=e({default:()=>we}),Ce=(0,W.lazy)(()=>F(()=>import(`./ProblemSpecPanel-CoULhmZo.js`).then(e=>({default:e.ProblemSpecPanel})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9])));function we({overrideProblemId:e,onClearOverride:t,onOpenWindow:n,onOpenJourney:r,onOpenCreateProblem:i,onOpenEditProblem:a,onOpenOnboarding:o,refreshTrigger:s}){let[u,d]=(0,W.useState)(null),f=u!==null&&u<780,[p,m]=(0,W.useState)(`spec`),[h,_]=(0,W.useState)(`spec`),[v,b]=(0,W.useState)(null),ee=(0,W.useCallback)(e=>{e&&(d(e.clientWidth),new ResizeObserver(e=>{for(let t of e)d(t.contentRect.width)}).observe(e))},[]),[x,S]=(0,W.useState)(!1),[C,w]=(0,W.useState)(()=>localStorage.getItem(`isAutocompleteEnabled`)!==`false`),{reviews:T,setReviews:E,loading:D,submitting:O,submittingRating:k,gradeError:A,setGradeError:j,code:M,setCode:P,nextMilestone:F,activatingMilestone:R,currentUserId:B,fetchQueue:te,handleGrade:V,handleSelectCard:H,handleActivateNextMilestone:U,handleResetStarterCode:ne}=ce({overrideProblemId:e,refreshTrigger:s,onClearOverride:t,onOpenOnboarding:o,setIsOnboardingOpen:S}),{sandboxRunning:re,sandboxResults:ie,sandboxError:se,savingReference:fe,savedRefSuccess:pe,saveRefError:me,handleRunSandbox:he,handleSaveReference:ge,resetSandbox:K}=le(),{aiLoading:_e,aiResult:ve,aiError:Se,explainLoading:we,explanationText:Te,explainError:Ee,aiSolutionLoading:De,aiSolutionError:Oe,handleAiEvaluation:ke,handleExplainCode:Ae,handleFetchAiSolution:je,resetAiState:q}=ue(),[Me,Ne]=(0,W.useState)(!1),[Pe,Fe]=(0,W.useState)(null),[Ie,J]=(0,W.useState)(null),Le=(0,W.useCallback)(async()=>{if(T.length===0)return;let e=T[0]?.problems||{},t=M.trim()||e.reference_code||``;if(!t){J(`Please write or save code before pushing to GitHub.`),setTimeout(()=>J(null),4e3);return}let r=L();if(!r.token){n&&n(`github`);return}Ne(!0),J(null),Fe(null);try{let n=await I({token:r.token,repo:r.repoName,branch:r.branch,problem_number:e.problem_number,problem_name:e.name||`Algorithm Problem`,pattern:e.pattern||`Algorithms`,difficulty:e.difficulty||`Medium`,optimal_time:e.optimal_time||`O(N)`,optimal_space:e.optimal_space||`O(1)`,description:e.description||``,code:t});Fe(n.html_url),setTimeout(()=>Fe(null),8e3)}catch(e){J(e.message||`Failed to push solution to GitHub.`),setTimeout(()=>J(null),5e3)}finally{Ne(!1)}},[T,M,n]),Re=T[0]?.id||T[0]?.problem_id,ze=(0,W.useRef)(void 0);(0,W.useEffect)(()=>{Re&&ze.current!==Re&&(ze.current=Re,q(),K())},[Re,q,K]);let Y=(0,W.useCallback)(e=>{q(),K(),V(e)},[V,q,K]),Be=(0,W.useCallback)(e=>{q(),K(),H(e)},[H,q,K]);(0,W.useEffect)(()=>{let e=e=>{let t=e.target;t?.closest(`.cm-editor`)||t?.tagName===`INPUT`||t?.tagName===`TEXTAREA`||t?.isContentEditable||T.length===0||O||(e.key===`1`?(e.preventDefault(),Y(1)):e.key===`2`?(e.preventDefault(),Y(2)):e.key===`3`?(e.preventDefault(),Y(3)):e.key===`4`&&(e.preventDefault(),Y(4)))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[Y,T.length,O]);let Ve=(e,t)=>{navigator.clipboard.writeText(e),b(t),setTimeout(()=>b(null),1800)},He=(0,W.useCallback)(()=>{r?r():n?.(`journey`)},[r,n]),Ue=(0,W.useCallback)(()=>{i?i():n?.(`createProblem`)},[i,n]),We=(0,W.useCallback)(()=>{o?o():S(!0)},[o]),Ge=(0,W.useCallback)(e=>{E(t=>{if(t.length===0)return t;let n=[...t],r=n[0];return r&&r.problems&&(r.problems={...r.problems,solutions:e}),n})},[E]);if(D)return(0,G.jsx)(`div`,{className:`w-full h-full flex items-center justify-center bg-[#fdf8e1] text-ink-black`,children:(0,G.jsxs)(`div`,{className:`flex flex-col items-center gap-4 p-8 bg-paper-white border-[3px] border-ink-black gadget-shadow text-center max-w-xs`,children:[(0,G.jsx)(`div`,{className:`w-12 h-12 bg-amber-200 border-2 border-ink-black flex items-center justify-center animate-spin`,children:(0,G.jsx)(g,{className:`w-6 h-6 text-ink-black`})}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`font-arcade text-xs text-ink-black uppercase tracking-wider font-bold`,children:`LOADING QUEUE`}),(0,G.jsx)(`p`,{className:`font-sans text-[11px] text-trash-gray mt-1 font-semibold`,children:`Fetching scheduled FSRS review cards...`})]})]})});if(T.length===0)return(0,G.jsx)(xe,{nextMilestone:F,activatingMilestone:R,onActivateNextMilestone:U,onOpenOnboarding:We,onOpenJourney:He,onOpenCreateProblem:Ue,onOpenWindow:n,overrideProblemId:e,onClearOverride:t,hasCustomOnboardingModal:!!o,isOnboardingOpen:x,onCloseOnboarding:()=>S(!1),onCompletedOnboarding:te,currentUserId:B});let X=T[0],Z=X?.problems,Ke=Z?.problem_number??(/^\d+$/.test(X?.problem_id||``)?parseInt(X.problem_id,10):void 0),Q=N(Ke,Z?.id||X?.problem_id,Z?.name),{cleanTitle:qe,approachVariant:Je,pattern:Ye}=oe(Z?.name,Q?.name,Z?.pattern,Q?.pattern),$={...Q,...Z,id:Z?.id||Q?.id||X?.problem_id,name:qe,problem_number:Z?.problem_number??Q?.problem_number,pattern:Ye,approach_variant:Je,difficulty:Z?.difficulty||Q?.difficulty||`Medium`,reference_code:Z?.reference_code||Q?.reference_solution||``,starter_code:Q?.starter_code||Z?.starter_code||``,description:Z?.description||Q?.description||``,optimal_time:Z?.optimal_time||Q?.time_complexity||`O(N)`,optimal_space:Z?.optimal_space||Q?.space_complexity||`O(1)`,examples:Z?.examples&&Z.examples.length>0?Z.examples:Q?.examples,constraints:Z?.constraints||Q?.constraints,how_to_solve:Z?.how_to_solve||``,solutions:Z?.solutions&&Z.solutions.length>0?Z.solutions:Q?.solutions},Xe=ae({...Q,...$,examples:$.examples&&$.examples.length>0?$.examples:Q?.examples,constraints:$.constraints&&(Array.isArray($.constraints)?$.constraints.length>0:$.constraints)?$.constraints:Q?.constraints}),Ze=Q?.reference_solution||``,Qe=Z?.reference_code||``,$e=Qe&&(!Ze||Qe.trim()!==Ze.trim())?Qe:``,et=$e||Ze||Qe||``;return(0,G.jsxs)(`div`,{ref:ee,className:`w-full h-full bg-[#fdf8e1] flex flex-col overflow-hidden select-none`,children:[(0,G.jsx)(de,{problem:$,totalInQueue:T.length,reviews:T,overrideProblemId:e,onSelectCard:Be,onOpenCreateProblem:Ue,onOpenEditProblem:()=>{a?a($):n?.(`editProblem`)}}),(0,G.jsxs)(`div`,{className:`${f?`flex`:`hidden`} shrink-0 bg-amber-100 border-b-[3px] border-ink-black px-2.5 sm:px-3 py-1.5 gap-1.5 sm:gap-2 overflow-x-auto no-scrollbar`,children:[(0,G.jsxs)(`button`,{onClick:()=>{_(`spec`),m(`spec`)},className:`px-2.5 sm:px-3 py-1 text-[9px] font-arcade font-bold border-2 border-ink-black transition-all cursor-pointer flex items-center gap-1.5 whitespace-nowrap ${h===`spec`?`bg-paper-white translate-y-0.5 shadow-none text-ink-black`:`bg-white shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] text-trash-gray`}`,children:[(0,G.jsx)(c,{className:`w-3 h-3 shrink-0`}),(0,G.jsx)(`span`,{children:`SPEC`})]}),(0,G.jsxs)(`button`,{onClick:()=>_(`code`),className:`px-2.5 sm:px-3 py-1 text-[9px] font-arcade font-bold border-2 border-ink-black transition-all cursor-pointer flex items-center gap-1.5 whitespace-nowrap ${h===`code`?`bg-paper-white translate-y-0.5 shadow-none text-ink-black`:`bg-white shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] text-trash-gray`}`,children:[(0,G.jsx)(y,{className:`w-3 h-3 shrink-0`}),(0,G.jsx)(`span`,{children:`CODE STUDIO`})]}),(0,G.jsxs)(`button`,{onClick:()=>{_(`ref`),m(`ref`)},className:`px-2.5 sm:px-3 py-1 text-[9px] font-arcade font-bold border-2 border-ink-black transition-all cursor-pointer flex items-center gap-1.5 whitespace-nowrap ${h===`ref`?`bg-paper-white translate-y-0.5 shadow-none text-ink-black`:`bg-white shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] text-trash-gray`}`,children:[(0,G.jsx)(l,{className:`w-3 h-3 shrink-0`}),(0,G.jsx)(`span`,{children:`SOLUTION`})]})]}),(0,G.jsxs)(`div`,{className:`flex-1 flex ${f?`flex-col`:`flex-row`} overflow-hidden min-h-0`,children:[(0,G.jsx)(W.Suspense,{fallback:(0,G.jsx)(`div`,{className:`flex-1 flex flex-col items-center justify-center p-8 bg-paper-white ${f?`h-64`:`border-r-[4px] border-ink-black`} font-sans text-xs text-trash-gray select-none`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2 font-arcade text-[10px] text-ink-black`,children:[(0,G.jsx)(g,{className:`w-4 h-4 animate-spin text-[#0ea5e9]`}),(0,G.jsx)(`span`,{children:`Loading Problem Spec...`})]})}),children:(0,G.jsx)(Ce,{leftTab:p,onSelectLeftTab:e=>{m(e),e===`ref`?_(`ref`):e===`spec`&&_(`spec`)},mobileView:h,isNarrow:f,problem:$,parsed:Xe,userSolution:$e,officialSolution:Ze,effectiveReferenceCode:et,copiedSnippet:v,onCopyText:Ve,saveRefError:me,aiSolutionLoading:De,aiSolutionError:Oe,onFetchAiSolution:()=>je(X,e=>{E(t=>t.map((t,n)=>n===0?{...t,problems:{...$||{},...t.problems||{},reference_code:e}}:t))}),explainLoading:we,explainError:Ee,explanationText:Te,onExplainCode:(e,t,n,r)=>Ae(X,e,t,n,r),activeReview:X,onUpdateSolutions:Ge,onEditProblem:()=>{a?a($):n?.(`editProblem`)}})}),(0,G.jsx)(ye,{mobileView:h,isNarrow:f,isAutocompleteEnabled:C,onToggleAutocomplete:e=>{w(e),localStorage.setItem(`isAutocompleteEnabled`,String(e))},onResetStarterCode:ne,code:M,onChangeCode:P,sandboxRunning:re,sandboxError:se,sandboxResults:ie,onRunSandbox:()=>he(X,M),savingReference:fe,savedRefSuccess:pe,saveRefError:me,onSaveReference:()=>ge(X,M,(e,t)=>{E(n=>n.map((n,r)=>r===0?{...n,problem_id:t||n.problem_id,problems:{...$||{},...n.problems||{},id:t||n.problems?.id||n.problem_id,reference_code:e}}:n))}),aiLoading:_e,aiError:Se,aiResult:ve,onAiEvaluation:()=>ke(X,M),optimalTime:$.optimal_time||`O(N)`,optimalSpace:$.optimal_space||`O(1)`,onPushToGitHub:Le,pushingToGitHub:Me,githubPushedUrl:Pe,githubPushError:Ie})]}),(0,G.jsx)(be,{gradeError:A,onDismissGradeError:()=>j(null),submitting:O,submittingRating:k,onGrade:Y}),!o&&(0,G.jsx)(z,{isOpen:x,onClose:()=>S(!1),onCompleted:te,userId:B})]})}export{we as default,se as n,Se as t};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
algospaced-ui/dist/assets/ReviewQueue-C250a4ib.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ProblemSpecPanel-Df-cRYRz.js","assets/rolldown-runtime-hePW80VL.js","assets/vendor-react-qmUj3JUi.js","assets/vendor-codemirror-By0wlJeM.js","assets/index-DYMSjoUb.js","assets/firebaseClient-G7klkuBb.js","assets/vendor-firebase-DSIO3PIf.js","assets/vendor-ui-ZXcm-2wU.js","assets/index-supjX07i.css","assets/MarkdownRenderer-CC5nUs7-.js"])))=>i.map(i=>d[i]);
|
| 2 |
+
import{n as e,r as t}from"./rolldown-runtime-hePW80VL.js";import{A as n,Ct as r,E as i,J as a,Lt as o,M as s,N as c,O as l,Q as u,St as d,Z as f,d as p,dt as m,ft as h,gt as g,it as _,o as v,ot as y,p as b,t as ee,tt as x,u as S,ut as C,vt as w,y as T,yt as E,zt as D}from"./vendor-react-qmUj3JUi.js";import{r as O}from"./firebaseClient-G7klkuBb.js";import{b as k,c as A,n as j,o as M,r as N,s as P,t as te}from"./index-DYMSjoUb.js";import{o as F,r as I}from"./githubSyncService-DQdE4J2L.js";import{t as L}from"./confetti.module-Uxh4CK4s.js";import R from"./OnboardingModal-hhKaj0In.js";import"./MarkdownRenderer-CC5nUs7-.js";import"./PrincessChamber-IJaaUuL1.js";import{A as z,C as ne,I as B,S as V,p as H,t as re,x as ie,y as ae}from"./vendor-codemirror-By0wlJeM.js";var U=t(D(),1),W=o();function oe(e){if(!e)return{description:``,examples:[],constraints:[]};let t=e.description||``,n=[],r=[];if(Array.isArray(e.examples)&&e.examples.length>0&&(n=e.examples.map(e=>typeof e==`string`?{input:e,output:``}:{input:e?.input||``,output:e?.output||``,explanation:e?.explanation||``})),Array.isArray(e.constraints)&&e.constraints.length>0?r=e.constraints.map(e=>String(e).replace(/^[\u2022\-*]\s*/,``).trim()).filter(Boolean):typeof e.constraints==`string`&&e.constraints.trim()&&(r=e.constraints.split(`
|
| 3 |
+
`).map(e=>e.replace(/^[\u2022\-*]\s*/,``).trim()).filter(Boolean)),n.length===0||r.length===0){let e=t.search(/\bExample\s*\d*:/i),i=t.search(/\bConstraints\s*:/i),a=-1;if(e!==-1&&i!==-1?a=Math.min(e,i):e===-1?i!==-1&&(a=i):a=e,a!==-1){let e=t.substring(0,a).trim(),i=t.substring(a),o=i,s=``,c=i.search(/\bConstraints\s*:/i);if(c!==-1&&(o=i.substring(0,c).trim(),s=i.substring(c).replace(/\bConstraints\s*:/i,``).trim()),n.length===0&&o){let e=/\bExample\s*(\d*)\s*:/gi,t=[],r;for(;(r=e.exec(o))!==null;)t.push({index:r.index,text:r[0]});for(let e=0;e<t.length;e++){let r=t[e].index+t[e].text.length,i=e+1<t.length?t[e+1].index:o.length,a=o.substring(r,i).trim(),s=a.match(/Input:\s*([\s\S]+?)(?=(?:Output:|Explanation:|$))/i),c=a.match(/Output:\s*([\s\S]+?)(?=(?:Explanation:|$))/i),l=a.match(/Explanation:\s*([\s\S]+)/i),u=s?s[1].trim():``,d=c?c[1].trim():``,f=l?l[1].trim():``;u||d?n.push({input:u,output:d,explanation:f}):a&&n.push({input:a,output:``,explanation:``})}}r.length===0&&s&&(r=s.split(`
|
| 4 |
+
`).map(e=>e.replace(/^[\u2022\-*]\s*/,``).trim()).filter(Boolean)),(n.length>0||r.length>0)&&(t=e)}}return{description:t,examples:n,constraints:r}}function se(e,t,n,r){let i=e=>!e||/^Method\s*\d*$/i.test(e.trim())||e.trim().toLowerCase()===`standard`,a=(e||t||`Algorithm Problem`).trim(),o=null;if(t&&a.toLowerCase().startsWith(t.toLowerCase())){let e=a.slice(t.length).trim();if(a=t,e){let t=e.match(/^[-\s]*Method\s*(\d+)\s*\((.+)\)$/i);if(t){let e=parseInt(t[1],10),n=t[2].trim();i(n)?e>1&&(o=`Method ${e}`):o=n}else{let t=e.match(/^[-\s]*Method\s*(\d+)/i);if(t){let e=parseInt(t[1],10);e>1&&(o=`Method ${e}`)}else{let t=e.match(/^[-\s]*\((.+)\)$/);if(t){let e=t[1].trim();i(e)||(o=e)}else{let t=e.match(/^[-\s]+([^-]+)$/);t&&!i(t[1])&&(o=t[1].trim())}}}}}else{let e=a.match(/^(.*?)\s*-\s*Method\s*(\d+)\s*\((.+)\)$/i);if(e){a=e[1].trim();let t=parseInt(e[2],10),n=e[3].trim();i(n)?t>1&&(o=`Method ${t}`):o=n}else{let e=a.match(/^(.*?)\s*-\s*Method\s*(\d+)$/i);if(e){a=e[1].trim();let t=parseInt(e[2],10);t>1&&(o=`Method ${t}`)}else{let e=a.match(/^(.*?)\s*\(\s*Method\s*(\d+)\s*\)$/i);if(e){a=e[1].trim();let t=parseInt(e[2],10);t>1&&(o=`Method ${t}`)}}}}let s=`General Algorithm`;return i(n)?i(r)?o&&!i(o)&&(s=o):s=r.trim():s=n.trim(),{cleanTitle:a,approachVariant:o,pattern:s}}function ce(e,t,n){if(!e)return[];if(Array.isArray(e.solutions)&&e.solutions.length>0)return e.solutions;let r=[],i=t||e.reference_code||``,a=e.pattern||`General Algorithm`,o=e.optimal_time||`O(N)`,s=e.optimal_space||`O(1)`;return(i||a)&&r.push({id:`sol-1`,name:e.approach_variant||`Optimal Solution`,pattern:a,time_complexity:o,space_complexity:s,code:i,explanation:e.how_to_solve||``,is_optimal:!0}),n&&n.trim()&&n.trim()!==i.trim()&&r.push({id:`sol-2`,name:`Personal Solution`,pattern:a,time_complexity:o,space_complexity:s,code:n,is_optimal:!1}),r}function le({overrideProblemId:e,refreshTrigger:t,onClearOverride:n,onOpenOnboarding:r,setIsOnboardingOpen:i}){let[a,o]=(0,U.useState)([]),[s,c]=(0,U.useState)(!0),[l,u]=(0,U.useState)(!1),[d,f]=(0,U.useState)(null),[p,m]=(0,U.useState)(null),[h,g]=(0,U.useState)(``),[_,v]=(0,U.useState)(null),[y,b]=(0,U.useState)(!1),[ee,x]=(0,U.useState)(void 0),S=(0,U.useRef)(!1),C=(0,U.useRef)(r),w=(0,U.useRef)(i),T=(0,U.useRef)(n),E=(0,U.useRef)(!1);(0,U.useEffect)(()=>{C.current=r,w.current=i,T.current=n});let D=(0,U.useCallback)(()=>{C.current?C.current():w.current&&w.current(!0)},[]),j=(0,U.useCallback)(async(t=!0)=>{t?(c(!0),m(null),g(``),S.current=!1):m(null);try{let{data:{session:n}}=await O.auth.getSession(),r=n?n.access_token:`sandbox`;n?.user?.id&&x(n.user.id);let i={Authorization:`Bearer ${r}`},a=await fetch(`/api/reviews/due`,{headers:i}),s=a.ok?await a.json():[];if(Array.isArray(s)||(s=[]),e){let t=String(e).trim().toLowerCase(),n=s.findIndex(e=>{let n=e.problems;return!!(e.problem_id&&String(e.problem_id).trim().toLowerCase()===t||n?.id&&String(n.id).trim().toLowerCase()===t||n?.problem_number!==void 0&&n?.problem_number!==null&&String(n.problem_number)===t||n?.name&&n.name.trim().toLowerCase()===t)});if(n>0){let[e]=s.splice(n,1);s.unshift(e)}else if(n===-1){let t=null,n=await fetch(`/api/reviews/problems/id/${e}`,{headers:i});if(n.ok){let e=await n.json();Array.isArray(e)&&e.length>0&&(t=e[0])}if(!t){let n=/^\d+$/.test(e),r=N(n?parseInt(e,10):void 0,e);if(r)try{let e=await A(r);if(e?.problem_id){let n=await fetch(`/api/reviews/problems/id/${e.problem_id}`,{headers:i});if(n.ok){let e=await n.json();Array.isArray(e)&&e.length>0&&(t=e[0])}}}catch(e){console.error(`Failed to auto-activate problem for override review:`,e)}}t&&s.unshift(t)}}o(s);let c=n?.user?.id,l=c===`sandbox-user-id`||!c?`sandbox`:c;if(!localStorage.getItem(`algospaced_onboarding_done_${l}`)&&!e&&D(),s&&s.length>0){if(t){let e=s[0],t=e.problems,n=t?.problem_number??(/^\d+$/.test(e?.problem_id||``)?parseInt(e.problem_id,10):void 0),r=N(n,t?.id||e?.problem_id,t?.name)?.starter_code||t?.starter_code||``;g(r)}}else try{let e=await fetch(`/api/journey-progress`,{headers:i});if(e.ok){let t=await e.json();v(P(new Set(t))??null)}else v(P(new Set)??null)}catch{v(P(new Set)??null)}}catch(e){console.error(`Error fetching review queue:`,e)}finally{c(!1)}},[e,D]);(0,U.useEffect)(()=>{if(E.current){E.current=!1;return}let e=!1,t=setTimeout(()=>{e||j(!0)},0);return()=>{e=!0,clearTimeout(t)}},[j,t]),(0,U.useEffect)(()=>{if(!s&&a.length===0&&!e&&!S.current){S.current=!0;try{L({particleCount:90,spread:70,origin:{y:.6}})}catch{}}},[s,a.length,e]);let M=(0,U.useCallback)(async t=>{if(a.length===0||l)return;let n=a[0];if(!n||!n.id)return;u(!0),f(t),m(null);let r=[...a];try{let{data:{session:i}}=await O.auth.getSession(),a=i?i.access_token:`sandbox`,s=await fetch(`/api/reviews/complete`,{method:`POST`,headers:{"Content-Type":`application/json`,Authorization:`Bearer ${a}`},body:JSON.stringify({review_id:n.id,fsrs_state:n.fsrs_state??0,fsrs_stability:n.fsrs_stability??0,fsrs_difficulty:n.fsrs_difficulty??0,fsrs_elapsed_days:n.fsrs_elapsed_days??0,fsrs_scheduled_days:n.fsrs_scheduled_days??0,fsrs_reps:n.fsrs_reps??0,fsrs_lapses:n.fsrs_lapses??0,last_reviewed:n.last_reviewed,rating:t})});if(s.ok){let r=n?.problems?.name||``,i=n?.problems?.pattern||``,a=`Correct`;a=t===1?`Incorrect`:t===2?`Mixed`:`Correct`,k.addReviewEvent(a,r,i).catch(()=>{});let s=I(),c=h.trim()||n?.problems?.reference_code||``;s.token&&s.repoName&&s.autoCommit&&c&&F({token:s.token,repo:s.repoName,branch:s.branch,problem_number:n?.problems?.problem_number,problem_name:r||`Algorithm Problem`,pattern:i||`Algorithms`,difficulty:n?.problems?.difficulty||`Medium`,optimal_time:n?.problems?.optimal_time||`O(N)`,optimal_space:n?.problems?.optimal_space||`O(1)`,description:n?.problems?.description||``,code:c}).catch(e=>{console.warn(`GitHub background auto-commit failed:`,e)}),e&&T.current&&(E.current=!0,T.current()),o(e=>{let t=e.slice(1);if(t.length>0){let e=t[0],n=e.problems,r=n?.problem_number??(/^\d+$/.test(e?.problem_id||``)?parseInt(e.problem_id,10):void 0),i=N(r,n?.id||e?.problem_id,n?.name)?.starter_code||n?.starter_code||``;g(i)}else g(``);return t}),j(!1)}else{let e=await s.json().catch(()=>({}));m(e.detail||`Server returned error (${s.status}). Please try again.`),o(r)}}catch(e){console.error(`Error logging review completion:`,e);let t=e instanceof Error?e.message:`Network connection failed while logging review.`;m(t),o(r)}finally{u(!1),f(null)}},[a,l,e,j,h]),te=(0,U.useCallback)(async()=>{if(_&&!y){b(!0);try{await A(_),await j()}catch(e){console.error(`Failed to activate next milestone:`,e)}finally{b(!1)}}},[_,y,j]),R=(0,U.useCallback)(()=>{let e=a[0],t=e?.problems,n=t?.problem_number??(/^\d+$/.test(e?.problem_id||``)?parseInt(e.problem_id,10):void 0),r=N(n,t?.id||e?.problem_id,t?.name)?.starter_code||t?.starter_code||``;g(r)},[a]);return{reviews:a,setReviews:o,loading:s,submitting:l,submittingRating:d,gradeError:p,setGradeError:m,code:h,setCode:g,nextMilestone:_,activatingMilestone:y,currentUserId:ee,fetchQueue:j,handleGrade:M,handleSelectCard:(0,U.useCallback)(t=>{if(t<=0||t>=a.length||l)return;e&&T.current&&(E.current=!0,T.current());let n=a[t];if(!n)return;let r=n.problems,i=r?.problem_number??(/^\d+$/.test(n?.problem_id||``)?parseInt(n.problem_id,10):void 0),s=N(i,r?.id||n?.problem_id,r?.name)?.starter_code||r?.starter_code||``;g(s),o(e=>{let t=e.findIndex(e=>e.id&&e.id===n.id||e===n);return t<=0?e:[e[t],...e.slice(0,t),...e.slice(t+1)]})},[a,l,e]),handleActivateNextMilestone:te,handleResetStarterCode:R}}function ue(){return{sandboxRunning:j(e=>e.sandboxRunning),sandboxResults:j(e=>e.sandboxResults),sandboxError:j(e=>e.sandboxError),savingReference:j(e=>e.savingReference),savedRefSuccess:j(e=>e.savedRefSuccess),saveRefError:j(e=>e.saveRefError),handleRunSandbox:j(e=>e.handleRunSandbox),handleSaveReference:j(e=>e.handleSaveReference),resetSandbox:j(e=>e.resetSandbox)}}function de(){return{aiLoading:j(e=>e.aiLoading),aiResult:j(e=>e.aiResult),aiError:j(e=>e.aiError),explainLoading:j(e=>e.explainLoading),explanationText:j(e=>e.explanationText),explainError:j(e=>e.explainError),aiSolutionLoading:j(e=>e.aiSolutionLoading),aiSolutionError:j(e=>e.aiSolutionError),handleAiEvaluation:j(e=>e.handleAiEvaluation),handleExplainCode:j(e=>e.handleExplainCode),handleFetchAiSolution:j(e=>e.handleFetchAiSolution),resetAiState:j(e=>e.resetAiState)}}var fe=({problem:e,totalInQueue:t,reviews:n=[],onSelectCard:r,onOpenCreateProblem:i,onOpenEditProblem:a})=>{let[o,l]=(0,U.useState)(!1),u=(0,U.useRef)(null);(0,U.useEffect)(()=>{let e=e=>{u.current&&!u.current.contains(e.target)&&l(!1)},t=e=>{e.key===`Escape`&&l(!1)};return o&&(document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t)),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[o]);let d=e.problem_number?`https://leetcode.com/problemset/all/?search=${e.problem_number}`:`https://leetcode.com/problemset/all/?search=${encodeURIComponent(e.name||``)}`;return(0,W.jsxs)(`div`,{className:`shrink-0 bg-paper-white border-b-[3px] border-ink-black px-2.5 sm:px-4 py-2 flex flex-wrap items-center justify-between gap-2 shadow-[0_2px_0_0_rgba(30,41,59,0.05)] relative z-40`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-1.5 sm:gap-2 flex-wrap min-w-0`,children:[(0,W.jsxs)(`div`,{className:`relative shrink-0`,ref:u,children:[(0,W.jsxs)(`button`,{onClick:()=>l(e=>!e),className:`h-7 inline-flex items-center gap-1.5 px-2 sm:px-2.5 bg-amber-300 hover:bg-amber-200 border-2 border-ink-black shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none transition-all cursor-pointer shrink-0`,title:`Click to view all cards due in today's queue`,children:[(0,W.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-emerald-500 animate-ping shrink-0`}),(0,W.jsx)(`span`,{className:`font-arcade text-[8px] sm:text-[9px] font-bold text-ink-black tracking-wide whitespace-nowrap`,children:`CARD 1 OF ${t}`}),t>1&&(0,W.jsx)(w,{className:`w-3 h-3 text-ink-black transition-transform shrink-0 ${o?`rotate-180`:``}`})]}),o&&n.length>0&&(0,W.jsxs)(`div`,{className:`absolute top-9 left-0 z-50 w-64 min-[400px]:w-72 sm:w-80 bg-paper-white border-[3px] border-ink-black gadget-shadow p-3 space-y-2 max-w-[calc(100vw-32px)]`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between border-b-2 border-ink-black pb-1.5 font-arcade text-[9px] font-bold text-ink-black`,children:[(0,W.jsx)(`span`,{children:`DAILY QUEUE (${n.length} CARDS)`}),(0,W.jsx)(`button`,{onClick:()=>l(!1),className:`px-1 hover:text-rose-600 font-bold cursor-pointer`,title:`Close`,children:`✕`})]}),(0,W.jsx)(`div`,{className:`text-[7.5px] font-arcade text-trash-gray uppercase -mt-0.5`,children:`Click any card to solve it now:`}),(0,W.jsx)(`div`,{className:`max-h-60 overflow-y-auto no-scrollbar space-y-1.5 pr-1`,children:n.map((e,t)=>{let n=e.problems,i=n?.problem_number,a=i==null?void 0:M(i),{cleanTitle:o,approachVariant:c}=se(n?.name||``,a?.name),u=c?`${o} (${c})`:o,d=t===0,f=n?.difficulty,p=f?f.toUpperCase():`EASY`,m=f===`Easy`?`bg-emerald-600 text-white`:f===`Medium`?`bg-amber-400 text-ink-black`:`bg-rose-600 text-white`;return(0,W.jsxs)(`button`,{type:`button`,onClick:()=>{d||r?.(t),l(!1)},className:`group w-full text-left p-2 border-2 border-ink-black text-xs flex items-center justify-between gap-2 cursor-pointer transition-all duration-150 select-none ${d?`bg-amber-100 font-bold shadow-[2px_2px_0px_0px_rgba(30,41,59,1)]`:`bg-white hover:bg-amber-50 hover:translate-x-0.5 active:translate-y-0.5 active:shadow-none shadow-[2px_2px_0px_0px_rgba(30,41,59,0.25)]`}`,title:d?`Currently active card`:`Jump to #${t+1}: ${u}`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-1.5 truncate min-w-0`,children:[(0,W.jsxs)(`span`,{className:`font-arcade text-[9px] text-trash-gray shrink-0`,children:[`#`,t+1]}),i!=null&&(0,W.jsxs)(`span`,{className:`font-arcade text-[8px] font-bold px-1 py-0.2 bg-amber-300 border border-ink-black shrink-0`,children:[`LC #`,i]}),(0,W.jsx)(`span`,{className:`truncate`,children:u})]}),(0,W.jsxs)(`div`,{className:`flex items-center gap-1.5 shrink-0`,children:[d?(0,W.jsx)(`span`,{className:`text-[7.5px] font-arcade font-extrabold px-1 py-0.5 bg-amber-300 text-ink-black border border-ink-black shrink-0`,children:`NOW`}):(0,W.jsx)(s,{className:`w-2.5 h-2.5 fill-ink-black text-ink-black opacity-0 group-hover:opacity-100 transition-opacity shrink-0`}),(0,W.jsx)(`span`,{className:`text-[8px] font-arcade font-bold px-1.5 py-0.5 border border-ink-black shrink-0 ${m}`,children:p})]})]},e.id||t)})})]})]}),e.problem_number!==void 0&&e.problem_number!==null&&(0,W.jsx)(`span`,{className:`h-7 inline-flex items-center px-2 font-arcade text-[8px] sm:text-[9px] font-bold bg-amber-200 border-2 border-ink-black shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] text-ink-black shrink-0 select-none whitespace-nowrap`,children:e.problem_number>0?`LC #${e.problem_number}`:`CUSTOM`}),(0,W.jsx)(`span`,{className:`h-7 inline-flex items-center px-2 font-arcade text-[8px] sm:text-[9px] font-bold border-2 border-ink-black shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] shrink-0 select-none whitespace-nowrap ${e.difficulty===`Easy`?`bg-emerald-600 text-white`:e.difficulty===`Medium`?`bg-amber-400 text-ink-black`:`bg-rose-600 text-white`}`,children:e.difficulty?e.difficulty.toUpperCase():`EASY`})]}),(0,W.jsxs)(`div`,{className:`flex items-center gap-1.5 sm:gap-2 shrink-0 flex-wrap justify-end`,children:[(0,W.jsxs)(`button`,{onClick:i,className:`h-7 inline-flex items-center gap-1 px-2 sm:px-2.5 bg-white hover:bg-purple-50 border-2 border-ink-black text-ink-black text-[8px] sm:text-[9px] font-arcade font-bold shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none transition-all cursor-pointer shrink-0`,title:`Create or Import Problem`,children:[(0,W.jsx)(m,{className:`w-3 h-3 text-purple-600 shrink-0`}),(0,W.jsx)(`span`,{className:`hidden min-[480px]:inline`,children:`ADD`})]}),a&&(0,W.jsxs)(`button`,{onClick:a,className:`h-7 inline-flex items-center gap-1 px-2 sm:px-2.5 bg-white hover:bg-emerald-50 border-2 border-ink-black text-ink-black text-[8px] sm:text-[9px] font-arcade font-bold shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none transition-all cursor-pointer shrink-0`,title:`Edit Problem Specification`,children:[(0,W.jsx)(c,{className:`w-3 h-3 text-emerald-600 shrink-0`}),(0,W.jsx)(`span`,{className:`hidden min-[480px]:inline`,children:`EDIT`})]}),e.google_doc_url&&(0,W.jsxs)(`a`,{href:e.google_doc_url,target:`_blank`,rel:`noreferrer`,className:`h-7 inline-flex items-center gap-1 px-2 sm:px-2.5 bg-white hover:bg-slate-100 border-2 border-ink-black text-ink-black text-[8px] sm:text-[9px] font-arcade font-bold shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none transition-all cursor-pointer shrink-0`,title:`Open Google Doc Notes`,children:[(0,W.jsx)(`span`,{children:`DOC`}),(0,W.jsx)(x,{className:`w-2.5 h-2.5 text-primary shrink-0`})]}),(0,W.jsxs)(`a`,{href:d,target:`_blank`,rel:`noreferrer`,className:`h-7 inline-flex items-center gap-1 px-2 sm:px-2.5 bg-white hover:bg-slate-100 border-2 border-ink-black text-ink-black text-[8px] sm:text-[9px] font-arcade font-bold shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none transition-all cursor-pointer shrink-0`,title:`Search LeetCode`,children:[(0,W.jsx)(`span`,{children:`LC`}),(0,W.jsx)(x,{className:`w-2.5 h-2.5 text-amber-600 shrink-0`})]})]})]})},pe=ie.mark({class:`cm-indent-dot cm-indent-dot-primary`}),me=ie.mark({class:`cm-indent-dot cm-indent-dot-secondary`});function G(e){let t=new B;for(let{from:n,to:r}of e.visibleRanges){let i=n;for(;i<r;){let n=e.state.doc.lineAt(i),r=n.text,a=0;for(;a<r.length&&(r[a]===` `||r[a]===` `);){let e=n.from+a,i=e+1,o=a%4==0||r[a]===` `;t.add(e,i,o?pe:me),a++}i=n.to+1}}return t.finish()}var he=ne.fromClass(class{decorations;constructor(e){this.decorations=G(e)}update(e){(e.docChanged||e.viewportChanged)&&(this.decorations=G(e.view))}},{decorations:e=>e.decorations}),ge=V.theme({"&":{backgroundColor:`#0c111d`,color:`#f1f5f9`,height:`100%`,fontSize:`13px`,fontFamily:`var(--font-code, "JetBrains Mono", "Fira Code", monospace)`},".cm-scroller":{overflow:`auto`,fontFamily:`inherit`,lineHeight:`1.65`},".cm-content":{caretColor:`#4ade80`,padding:`12px 0`},"&.cm-focused .cm-cursor":{borderLeftColor:`#4ade80`,borderLeftWidth:`2px`,filter:`drop-shadow(0 0 5px rgba(74, 222, 128, 0.8))`},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, ::selection":{backgroundColor:`rgba(56, 189, 248, 0.25) !important`},".cm-gutters":{backgroundColor:`#070a12`,color:`#475569`,borderRight:`2px solid #1e293b`,paddingRight:`6px`,userSelect:`none`},".cm-activeLineGutter":{backgroundColor:`#131b2e`,color:`#38bdf8`,fontWeight:`700`},".cm-activeLine, &.cm-focused .cm-activeLine":{backgroundColor:`#0f172a !important`},".cm-line":{padding:`0 10px`},".cm-indent-dot":{position:`relative`,display:`inline-block`},".cm-indent-dot::before":{position:`absolute`,top:`50%`,left:`50%`,transform:`translate(-50%, -50%)`,pointerEvents:`none`,userSelect:`none`,lineHeight:`0`,fontFamily:`monospace`},".cm-indent-dot-primary::before":{content:`"•"`,color:`#38bdf8`,fontSize:`9px`,opacity:`0.85`},".cm-indent-dot-secondary::before":{content:`"·"`,color:`#64748b`,fontSize:`11px`,opacity:`0.5`},"&.cm-focused .cm-matchingBracket, .cm-matchingBracket":{backgroundColor:`rgba(74, 222, 128, 0.2)`,outline:`1px solid #4ade80`,borderRadius:`2px`,color:`#86efac !important`},".cm-placeholder":{color:`#64748b`,fontStyle:`italic`},".cm-scroller::-webkit-scrollbar":{width:`6px`,height:`6px`},".cm-scroller::-webkit-scrollbar-track":{backgroundColor:`#070a12`},".cm-scroller::-webkit-scrollbar-thumb":{backgroundColor:`#1e293b`,borderRadius:`3px`,border:`1px solid #334155`},".cm-scroller::-webkit-scrollbar-thumb:hover":{backgroundColor:`#38bdf8`}}),K=[re(),ae.of(` `),z.of([H]),he,ge,V.contentAttributes.of({"aria-label":`Python Code Editor`})],_e=[{id:`python`,name:`Python`,version:`3.14`}],ve=({className:e=`w-3.5 h-3.5`})=>(0,W.jsxs)(`svg`,{viewBox:`0 0 128 128`,className:e,xmlns:`http://www.w3.org/2000/svg`,children:[(0,W.jsx)(`path`,{d:`M63.454 4.018c-14.775 0-23.774 6.425-23.774 18.775v13.626h24.168v3.424H30.082C17.518 39.843 8 47.962 8 63.673c0 15.65 8.358 23.486 21.056 23.486h11.905v-16.89c0-13.064 11.233-24.113 24.331-24.113h23.773V32.793c0-11.83-9.988-19.775-23.773-19.775H63.454v-9zm-9.845 7.426a3.84 3.84 0 0 1 3.86 3.84 3.84 3.84 0 0 1-3.86 3.841 3.84 3.84 0 0 1-3.86-3.84 3.84 3.84 0 0 1 3.86-3.841z`,fill:`#387eb8`}),(0,W.jsx)(`path`,{d:`M64.546 123.982c14.775 0 23.774-6.425 23.774-18.775V91.581H64.152v-3.424h33.766c12.564 0 22.082-8.119 22.082-23.83 0-15.65-8.358-23.486-21.056-23.486H87.04v16.89c0 13.064-11.234 24.113-24.332 24.113H38.934v13.363c0 11.83 9.989 19.775 23.774 19.775h1.838v9zm9.845-7.426a3.84 3.84 0 0 1-3.86-3.84 3.84 3.84 0 0 1 3.86-3.841 3.84 3.84 0 0 1 3.86 3.84 3.84 3.84 0 0 1-3.86 3.841z`,fill:`#ffe052`})]}),ye=({mobileView:e,isNarrow:t=!1,isAutocompleteEnabled:o,onToggleAutocomplete:c,onResetStarterCode:u,code:d,onChangeCode:m,sandboxRunning:g,sandboxError:_,sandboxResults:v,onRunSandbox:y,savingReference:S,savedRefSuccess:D,saveRefError:O,onSaveReference:k,aiLoading:A,aiError:j,aiResult:M,onAiEvaluation:N,optimalTime:P,optimalSpace:te,onPushToGitHub:F,pushingToGitHub:I,githubPushedUrl:L,githubPushError:R})=>{let[z,ne]=(0,U.useState)(`python`),[B,V]=(0,U.useState)(!1),H=(0,U.useRef)(null);(0,U.useEffect)(()=>{let e=e=>{H.current&&!H.current.contains(e.target)&&V(!1)},t=e=>{e.key===`Escape`&&V(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[]);let re=_e.find(e=>e.id===z)??_e[0];return(0,W.jsxs)(`div`,{className:`w-full ${t?`flex flex-1`:`lg:w-[51%] flex`} flex-col bg-[#fffdfa] overflow-y-auto no-scrollbar ${t&&e!==`code`?`hidden`:`flex`}`,children:[(0,W.jsxs)(`div`,{className:`shrink-0 bg-[#f7f5ed] border-b-2 border-ink-black p-2 sm:px-3 flex flex-wrap items-center justify-between gap-1.5 sm:gap-2`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-1.5 sm:gap-2 flex-wrap`,children:[(0,W.jsxs)(`div`,{className:`relative`,ref:H,children:[(0,W.jsxs)(`button`,{type:`button`,onClick:()=>V(e=>!e),className:`h-7 px-2.5 bg-white hover:bg-slate-100 border-2 border-ink-black shadow-[1px_1px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none flex items-center gap-1.5 font-arcade text-[9px] font-bold text-ink-black cursor-pointer transition-all select-none`,title:`Select programming language`,"aria-expanded":B,"aria-haspopup":`listbox`,children:[(0,W.jsx)(ve,{className:`w-3.5 h-3.5 shrink-0`}),(0,W.jsx)(`span`,{children:re.name}),(0,W.jsx)(w,{className:`w-3 h-3 text-ink-black transition-transform duration-150 ${B?`rotate-180`:``}`})]}),B&&(0,W.jsxs)(`div`,{className:`absolute top-full mt-1.5 left-0 z-50 w-52 bg-paper-white border-[3px] border-ink-black gadget-shadow p-1.5 space-y-1`,role:`listbox`,children:[(0,W.jsx)(`div`,{className:`px-2 py-1 text-[8px] font-arcade font-bold text-trash-gray uppercase border-b border-slate-200`,children:`SELECT LANGUAGE`}),_e.map(e=>{let t=z===e.id;return(0,W.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":t,onClick:()=>{ne(e.id),V(!1)},className:`w-full flex items-center justify-between px-2.5 py-1.5 border-2 border-ink-black text-left transition-all cursor-pointer ${t?`bg-amber-200 shadow-[1px_1px_0px_0px_rgba(30,41,59,1)] font-bold text-ink-black`:`bg-white hover:bg-slate-100 text-slate-800`}`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-1.5 font-arcade text-[9px]`,children:[(0,W.jsx)(ve,{className:`w-3.5 h-3.5 shrink-0`}),(0,W.jsx)(`span`,{children:e.name})]}),(0,W.jsxs)(`span`,{className:`font-mono text-[8px] font-bold px-1.5 py-0.5 bg-white border border-ink-black text-slate-700 shadow-[1px_1px_0px_0px_rgba(30,41,59,0.3)]`,children:[`v`,e.version]})]},e.id)})]})]}),(0,W.jsx)(`div`,{className:`h-4 w-[2px] bg-slate-300 mx-0.5 hidden sm:block`}),(0,W.jsxs)(`label`,{className:`inline-flex items-center gap-1.5 cursor-pointer select-none`,children:[(0,W.jsx)(`input`,{type:`checkbox`,checked:o,onChange:e=>c(e.target.checked),className:`sr-only peer`,"aria-label":`Toggle code editor autocompletion`}),(0,W.jsx)(`div`,{className:`relative w-7 h-3.5 bg-slate-300 border border-ink-black rounded-full peer peer-checked:bg-grass-green transition-all after:content-[''] after:absolute after:top-[1px] after:left-[2px] after:bg-white after:border after:border-ink-black after:rounded-full after:h-2 after:w-2 after:transition-all peer-checked:after:translate-x-3`}),(0,W.jsx)(`span`,{className:`text-[7.5px] min-[400px]:text-[8px] font-arcade font-bold text-trash-gray peer-checked:text-ink-black whitespace-nowrap`,children:`AUTOCOMPLETE`})]})]}),(0,W.jsxs)(`div`,{className:`flex items-center gap-1.5 sm:gap-2`,children:[(0,W.jsx)(`button`,{onClick:u,className:`w-7 h-7 bg-white hover:bg-slate-100 border-2 border-ink-black shadow-[1px_1px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none text-ink-black flex items-center justify-center cursor-pointer transition-all`,title:`Reset to starter code`,"aria-label":`Reset to starter code`,children:(0,W.jsx)(l,{className:`w-3.5 h-3.5`})}),(0,W.jsx)(`button`,{onClick:()=>m(``),className:`w-7 h-7 bg-white hover:bg-rose-50 border-2 border-ink-black shadow-[1px_1px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none text-rose-700 flex items-center justify-center cursor-pointer transition-all`,title:`Clear editor`,"aria-label":`Clear editor`,children:(0,W.jsx)(b,{className:`w-3.5 h-3.5 text-rose-600`})}),k&&(0,W.jsx)(`button`,{onClick:k,disabled:S||!d.trim(),className:`w-7 h-7 border-2 border-ink-black shadow-[1px_1px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none flex items-center justify-center cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed transition-all ${D?`bg-emerald-600 hover:bg-emerald-500 text-white`:`bg-amber-400 hover:bg-amber-300 text-ink-black`}`,title:S?`Saving solution to personal database...`:D?`Saved to personal database!`:`Overwrite saved solution with studio code`,"aria-label":`Overwrite saved solution with studio code`,children:S?(0,W.jsx)(n,{className:`w-3.5 h-3.5 animate-spin text-ink-black`}):D?(0,W.jsx)(h,{className:`w-3.5 h-3.5 text-white`}):(0,W.jsx)(i,{className:`w-3.5 h-3.5 text-ink-black`})}),F&&(0,W.jsx)(`button`,{onClick:F,disabled:I||!d.trim(),className:`w-7 h-7 bg-[#24292e] hover:bg-black border-2 border-ink-black shadow-[1px_1px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none text-white flex items-center justify-center cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed transition-all`,title:I?`Pushing to GitHub...`:`Push solution to GitHub repository`,"aria-label":`Push to GitHub`,children:I?(0,W.jsx)(n,{className:`w-3.5 h-3.5 animate-spin text-yellow-300`}):(0,W.jsx)(f,{className:`w-3.5 h-3.5 text-yellow-300`})})]}),(0,W.jsxs)(`div`,{className:`flex items-center gap-1.5 sm:gap-2`,children:[(0,W.jsx)(`button`,{onClick:y,disabled:g||!d.trim(),className:`w-7 h-7 bg-emerald-600 hover:bg-emerald-500 border-2 border-ink-black shadow-[1px_1px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none text-white flex items-center justify-center cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed transition-all`,title:g?`Running sandbox tests...`:`Run tests in local sandbox`,"aria-label":`Run tests`,children:g?(0,W.jsx)(n,{className:`w-3.5 h-3.5 animate-spin`}):(0,W.jsx)(s,{className:`w-3.5 h-3.5 fill-white text-white ml-0.5`})}),(0,W.jsx)(`button`,{onClick:N,disabled:A||!d.trim(),className:`w-7 h-7 bg-purple-600 hover:bg-purple-500 border-2 border-ink-black shadow-[1px_1px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none text-white flex items-center justify-center cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed transition-all`,title:A?`Evaluating code with Gemini...`:`Gemini Eval (AI code review & complexity)`,"aria-label":`Gemini Eval`,children:A?(0,W.jsx)(n,{className:`w-3.5 h-3.5 animate-spin`}):(0,W.jsx)(T,{className:`w-3.5 h-3.5 text-amber-300`})})]})]}),(0,W.jsxs)(`div`,{className:`p-4 sm:p-5 flex-1 flex flex-col space-y-4`,children:[(0,W.jsx)(`div`,{className:`flex-1 flex flex-col min-h-[300px] sm:min-h-[360px] border-[3px] border-ink-black shadow-[4px_4px_0px_0px_rgba(30,41,59,1)] bg-[#0c111d] overflow-hidden`,children:(0,W.jsx)(`div`,{className:`flex-1 overflow-hidden relative`,children:(0,W.jsx)(ee,{value:d,onChange:m,placeholder:`def solve(nums):
|
| 5 |
+
# Write your solution from memory here...`,height:`100%`,theme:`dark`,extensions:K,basicSetup:{autocompletion:o,lineNumbers:!0,foldGutter:!0,dropCursor:!0,allowMultipleSelections:!0,indentOnInput:!0,bracketMatching:!0,closeBrackets:!0,rectangularSelection:!0,crosshairCursor:!0,highlightActiveLine:!0,highlightSelectionMatches:!0,closeBracketsKeymap:!0,defaultKeymap:!0,searchKeymap:!0,historyKeymap:!0,foldKeymap:!0,completionKeymap:!0,lintKeymap:!0},className:`w-full h-full text-xs font-code-mono`})})}),D&&(0,W.jsxs)(`div`,{className:`p-3 bg-[#f0fdf4] border-2 border-emerald-600 text-emerald-950 text-xs font-semibold flex items-center gap-2 shadow-[2px_2px_0px_0px_rgba(30,41,59,1)]`,children:[(0,W.jsx)(h,{className:`w-4 h-4 text-emerald-600 shrink-0`}),(0,W.jsx)(`span`,{children:`Successfully saved studio code as your personal reference solution!`})]}),O&&(0,W.jsxs)(`div`,{className:`p-3 bg-rose-50 border-2 border-rose-500 text-rose-800 text-xs font-semibold flex items-center gap-2 shadow-[2px_2px_0px_0px_rgba(30,41,59,1)]`,children:[(0,W.jsx)(p,{className:`w-4 h-4 text-rose-600 shrink-0`}),(0,W.jsx)(`span`,{children:O})]}),L&&(0,W.jsxs)(`div`,{className:`p-3 bg-[#f0fdf4] border-2 border-emerald-600 text-emerald-950 text-xs font-semibold flex items-center justify-between shadow-[2px_2px_0px_0px_rgba(30,41,59,1)]`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(h,{className:`w-4 h-4 text-emerald-600 shrink-0`}),(0,W.jsx)(`span`,{children:`Successfully pushed solution to your GitHub repository!`})]}),(0,W.jsxs)(`a`,{href:L,target:`_blank`,rel:`noopener noreferrer`,className:`text-[11px] font-bold text-blue-700 hover:text-blue-900 underline flex items-center gap-1`,children:[(0,W.jsx)(`span`,{children:`View on GitHub`}),(0,W.jsx)(x,{className:`w-3 h-3`})]})]}),R&&(0,W.jsxs)(`div`,{className:`p-3 bg-rose-50 border-2 border-rose-500 text-rose-800 text-xs font-semibold flex items-center gap-2 shadow-[2px_2px_0px_0px_rgba(30,41,59,1)]`,children:[(0,W.jsx)(p,{className:`w-4 h-4 text-rose-600 shrink-0`}),(0,W.jsx)(`span`,{children:R})]}),g&&(0,W.jsxs)(`div`,{className:`p-3 border-2 border-ink-black bg-emerald-50 shadow-[3px_3px_0px_0px_rgba(30,41,59,1)] flex items-center gap-3 animate-pulse`,children:[(0,W.jsx)(n,{className:`w-5 h-5 text-emerald-600 animate-spin shrink-0`}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h4`,{className:`font-arcade text-[9px] font-bold text-ink-black uppercase`,children:`Running...`}),(0,W.jsx)(`p`,{className:`font-sans text-[11px] text-trash-gray font-semibold mt-0.5`,children:`Executing against test cases...`})]})]}),_&&(0,W.jsxs)(`div`,{className:`p-3 border-2 border-rose-500 bg-rose-50 text-rose-800 text-xs font-semibold shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] flex items-center gap-2`,children:[(0,W.jsx)(p,{className:`w-4 h-4 text-rose-600 shrink-0`}),(0,W.jsx)(`span`,{children:_})]}),v&&(0,W.jsxs)(`div`,{className:`border-[3px] border-ink-black p-4 sm:p-5 shadow-[4px_4px_0px_0px_rgba(30,41,59,1)] space-y-3.5 ${v.status===`passed`?`bg-[#f0fdf4]`:`bg-[#fff1f2]`}`,children:[(0,W.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-2 pb-2.5 border-b-2 border-dashed border-ink-black`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,W.jsx)(`div`,{className:`w-8 h-8 border-2 border-ink-black flex items-center justify-center font-bold shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] ${v.status===`passed`?`bg-grass-green text-ink-black`:`bg-rose-500 text-white`}`,children:v.status===`passed`?(0,W.jsx)(E,{className:`w-5 h-5 stroke-[3]`}):(0,W.jsx)(p,{className:`w-4 h-4`})}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`div`,{className:`font-arcade text-[10px] font-bold text-ink-black flex items-center gap-1.5 uppercase`,children:v.status===`passed`?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`span`,{children:`ALL TESTS PASSED`}),(0,W.jsx)(h,{className:`w-3.5 h-3.5 text-emerald-600 inline`})]}):(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`span`,{children:v.status===`error`?`EXECUTION ERROR`:`TESTS FAILED`}),(0,W.jsx)(C,{className:`w-3.5 h-3.5 text-rose-600 inline`})]})}),(0,W.jsxs)(`div`,{className:`font-sans text-[11px] text-slate-600 font-semibold`,children:[v.passed_count??0,` of `,v.total_tests??0,` test cases passed (`,(v.duration_ms??0).toFixed(1),`ms)`]})]})]}),v.status===`passed`&&(0,W.jsxs)(`button`,{onClick:k,disabled:S,className:`px-3 py-1.5 bg-white hover:bg-emerald-100 border-2 border-ink-black text-ink-black font-arcade text-[8px] font-bold flex items-center gap-1.5 shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none transition-all cursor-pointer shrink-0 disabled:opacity-50`,children:[S?(0,W.jsx)(n,{className:`w-3 h-3 animate-spin`}):D?(0,W.jsx)(h,{className:`w-3.5 h-3.5 text-emerald-600`}):(0,W.jsx)(i,{className:`w-3.5 h-3.5 text-blue-600`}),(0,W.jsx)(`span`,{children:D?`SAVED TO DB!`:`SAVE AS OFFICIAL SOLUTION`})]})]}),O&&(0,W.jsx)(`div`,{className:`p-2 border border-rose-500 bg-rose-100 text-rose-800 text-[11px] font-semibold`,children:O}),v.results&&v.results.length>0&&(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(`span`,{className:`font-arcade text-[8px] text-trash-gray uppercase font-bold block`,children:`TEST CASE BREAKDOWN:`}),(0,W.jsx)(`div`,{className:`space-y-1.5 max-h-56 overflow-y-auto custom-scrollbar`,children:v.results.map((e,t)=>(0,W.jsxs)(`div`,{className:`p-2.5 border-2 border-ink-black text-xs font-mono shadow-[2px_2px_0px_0px_rgba(30,41,59,0.3)] ${e.passed?`bg-white`:`bg-rose-50`}`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between font-arcade text-[8px] mb-1`,children:[(0,W.jsxs)(`span`,{className:`font-bold text-ink-black`,children:[`CASE #`,t+1]}),(0,W.jsx)(`span`,{className:e.passed?`text-emerald-700 font-bold`:`text-rose-700 font-bold`,children:e.passed?`✓ PASSED`:`✗ FAILED`})]}),(0,W.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-3 gap-1.5 text-[10px]`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`span`,{className:`text-slate-500 block`,children:`Input:`}),(0,W.jsx)(`span`,{className:`font-code-mono text-ink-black font-semibold break-all`,children:JSON.stringify(e.input)})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`span`,{className:`text-slate-500 block`,children:`Expected:`}),(0,W.jsx)(`span`,{className:`font-code-mono text-emerald-700 font-semibold break-all`,children:JSON.stringify(e.expected)})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`span`,{className:`text-slate-500 block`,children:`Output:`}),(0,W.jsx)(`span`,{className:`font-code-mono font-semibold break-all ${e.passed?`text-emerald-700`:`text-rose-700`}`,children:e.output===void 0?`None`:JSON.stringify(e.output)})]})]}),e.error&&(0,W.jsx)(`div`,{className:`mt-1.5 p-1.5 bg-rose-100 text-rose-900 text-[10px] font-mono border border-rose-300 break-all`,children:e.error})]},t))})]}),v.error&&(0,W.jsx)(`div`,{className:`p-3 bg-[#1E293B] text-rose-400 font-code-mono text-[11px] border-2 border-ink-black overflow-x-auto whitespace-pre-wrap select-text`,children:v.error}),v.status===`passed`&&(0,W.jsx)(`div`,{className:`p-2 bg-emerald-100/70 border border-emerald-300 text-emerald-900 text-xs flex items-center justify-between`,children:(0,W.jsx)(`span`,{className:`font-sans font-medium`,children:`✨ All unit tests passed. Rate your recall below.`})})]}),A&&(0,W.jsxs)(`div`,{className:`p-4 border-2 border-ink-black bg-amber-50 shadow-[3px_3px_0px_0px_rgba(30,41,59,1)] flex items-center gap-3 animate-pulse`,children:[(0,W.jsx)(n,{className:`w-6 h-6 text-purple-600 animate-spin shrink-0`}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h4`,{className:`font-arcade text-[9px] font-bold text-ink-black uppercase`,children:`ANALYZING...`}),(0,W.jsx)(`p`,{className:`font-sans text-[11px] text-trash-gray font-semibold mt-0.5`,children:`Checking edge cases, bounds, and Big-O efficiency against optimal constraints...`})]})]}),j&&(0,W.jsx)(`div`,{className:`p-3 border-2 border-rose-500 bg-rose-50 text-rose-800 text-xs font-semibold shadow-[2px_2px_0px_0px_rgba(30,41,59,1)]`,children:j}),M&&(0,W.jsxs)(`div`,{className:`border-[3px] border-ink-black bg-[#fefce8] p-4 sm:p-5 shadow-[4px_4px_0px_0px_rgba(30,41,59,1)] space-y-4`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between pb-3 border-b-2 border-dashed border-ink-black`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,W.jsx)(`div`,{className:`w-9 h-9 border-2 border-ink-black flex items-center justify-center font-bold shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] ${M.is_correct?`bg-grass-green text-ink-black`:`bg-rose-500 text-white`}`,children:M.is_correct?(0,W.jsx)(E,{className:`w-5 h-5 stroke-[3]`}):(0,W.jsx)(r,{className:`w-5 h-5`})}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`span`,{className:`font-arcade text-[10px] font-bold text-ink-black flex items-center gap-1.5`,children:M.is_correct?(0,W.jsxs)(W.Fragment,{children:[`STATUS: PASSED`,(0,W.jsx)(h,{className:`w-3.5 h-3.5 text-emerald-600 inline`})]}):(0,W.jsxs)(W.Fragment,{children:[`STATUS: FAILED`,(0,W.jsx)(C,{className:`w-3.5 h-3.5 text-rose-600 inline`})]})}),(0,W.jsx)(`span`,{className:`font-sans text-[11px] text-slate-600 font-semibold`,children:M.is_correct?`Algorithm matches expected logic and patterns.`:`Bugs or edge-case failures detected.`})]})]}),(0,W.jsx)(`span`,{className:`font-arcade text-[9px] px-2 py-1 border-2 border-ink-black uppercase font-bold shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] ${M.is_correct?`bg-emerald-100 text-emerald-800`:`bg-rose-100 text-rose-800`}`,children:M.is_correct?`CORRECT`:`INCORRECT`})]}),(0,W.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,W.jsxs)(`div`,{className:`p-2.5 bg-white border-2 border-ink-black shadow-[2px_2px_0px_0px_rgba(30,41,59,1)]`,children:[(0,W.jsx)(`span`,{className:`font-arcade text-[8px] text-trash-gray block uppercase font-bold`,children:`Time Complexity`}),(0,W.jsxs)(`div`,{className:`flex items-baseline gap-2 mt-1`,children:[(0,W.jsx)(`span`,{className:`font-code-mono text-xs font-bold text-ink-black`,children:M.detected_complexity?.time||`N/A`}),(0,W.jsxs)(`span`,{className:`text-[10px] font-sans text-slate-500 font-semibold`,children:[`(Target: `,P||`O(N)`,`)`]})]})]}),(0,W.jsxs)(`div`,{className:`p-2.5 bg-white border-2 border-ink-black shadow-[2px_2px_0px_0px_rgba(30,41,59,1)]`,children:[(0,W.jsx)(`span`,{className:`font-arcade text-[8px] text-trash-gray block uppercase font-bold`,children:`Space Complexity`}),(0,W.jsxs)(`div`,{className:`flex items-baseline gap-2 mt-1`,children:[(0,W.jsx)(`span`,{className:`font-code-mono text-xs font-bold text-ink-black`,children:M.detected_complexity?.space||`N/A`}),(0,W.jsxs)(`span`,{className:`text-[10px] font-sans text-slate-500 font-semibold`,children:[`(Target: `,te||`O(1)`,`)`]})]})]})]}),M.bugs&&M.bugs.length>0&&(0,W.jsxs)(`div`,{className:`p-3 bg-white border-2 border-ink-black space-y-1.5 shadow-[2px_2px_0px_0px_rgba(30,41,59,1)]`,children:[(0,W.jsxs)(`span`,{className:`font-arcade text-[8px] text-rose-600 uppercase font-bold block flex items-center gap-1`,children:[(0,W.jsx)(p,{className:`w-3 h-3 text-rose-500`}),`TRACES & EDGE CASE ISSUES:`]}),(0,W.jsx)(`ul`,{className:`list-disc list-inside text-xs text-slate-800 space-y-1 font-semibold pl-1`,children:M.bugs.map((e,t)=>(0,W.jsx)(`li`,{className:`leading-relaxed select-text`,children:e},t))})]}),M.key_suggestion&&(0,W.jsxs)(`div`,{className:`p-3 bg-amber-50 border-2 border-ink-black space-y-1 shadow-[2px_2px_0px_0px_rgba(30,41,59,1)]`,children:[(0,W.jsxs)(`span`,{className:`font-arcade text-[8px] text-amber-700 uppercase font-bold block flex items-center gap-1`,children:[(0,W.jsx)(T,{className:`w-3 h-3 text-amber-500`}),`TIP:`]}),(0,W.jsx)(`p`,{className:`text-xs text-slate-800 font-medium leading-relaxed m-0 select-text`,children:M.key_suggestion})]}),(0,W.jsxs)(`div`,{className:`p-2.5 bg-white border-2 border-dashed border-ink-black flex items-center justify-between`,children:[(0,W.jsxs)(`span`,{className:`text-xs font-bold text-ink-black flex items-center gap-1.5`,children:[(0,W.jsx)(a,{className:`w-4 h-4 text-primary`}),`Recommendation:`]}),(0,W.jsx)(`span`,{className:`font-arcade text-[9px] font-bold text-purple-700`,children:M.is_correct?`Rate your recall below.`:`Review issues and rate recall below.`})]})]})]})]})},be=({gradeError:e,onDismissGradeError:t,submitting:r,submittingRating:i,onGrade:a})=>(0,W.jsx)(`div`,{className:`shrink-0 bg-[#f8f5eb] border-t-[3px] border-ink-black p-2 sm:p-3 flex flex-col items-stretch gap-1.5 sm:gap-2 shadow-[0_-3px_0_0_rgba(30,41,59,0.08)]`,children:(0,W.jsxs)(`div`,{className:`w-full flex flex-col`,children:[e&&(0,W.jsxs)(`div`,{className:`p-2.5 mb-2 bg-red-100 border-2 border-red-500 text-red-800 text-xs font-semibold shadow-[2px_2px_0px_0px_#1E293B] flex items-center justify-between`,children:[(0,W.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,W.jsx)(p,{className:`w-4 h-4 text-red-600 shrink-0`}),e]}),(0,W.jsx)(`button`,{onClick:t,className:`text-red-900 font-bold hover:underline cursor-pointer ml-2 text-xs`,children:`Dismiss`})]}),(0,W.jsxs)(`div`,{className:`flex gap-1.5 sm:gap-2.5 w-full`,children:[(0,W.jsx)(`button`,{onClick:()=>a(1),disabled:r,className:`flex-1 min-w-0 bg-[#dc2626] hover:bg-[#b91c1c] border-2 sm:border-[3px] border-ink-black py-2 sm:py-2.5 px-1 sm:px-2 arcade-btn cursor-pointer disabled:opacity-60 text-white flex flex-col items-center justify-center font-bold transition-all select-none`,title:`Press 1 on keyboard`,children:i===1?(0,W.jsx)(`div`,{className:`flex items-center gap-1.5 font-arcade text-[10px]`,children:(0,W.jsx)(n,{className:`w-3.5 h-3.5 animate-spin`})}):(0,W.jsxs)(`div`,{className:`flex items-center gap-1 font-headline-md text-[10px] min-[400px]:text-xs sm:text-sm font-extrabold tracking-wide uppercase truncate`,children:[(0,W.jsx)(`span`,{className:`font-arcade text-[8px] sm:text-[9px] px-1 py-0.5 bg-black/20 rounded shrink-0`,children:`1`}),(0,W.jsx)(`span`,{className:`truncate`,children:`Again`})]})}),(0,W.jsx)(`button`,{onClick:()=>a(2),disabled:r,className:`flex-1 min-w-0 bg-[#ff9933] hover:bg-[#ff8000] border-2 sm:border-[3px] border-ink-black py-2 sm:py-2.5 px-1 sm:px-2 arcade-btn cursor-pointer disabled:opacity-60 text-ink-black flex flex-col items-center justify-center font-bold transition-all select-none`,title:`Press 2 on keyboard`,children:i===2?(0,W.jsx)(`div`,{className:`flex items-center gap-1.5 font-arcade text-[10px]`,children:(0,W.jsx)(n,{className:`w-3.5 h-3.5 animate-spin text-ink-black`})}):(0,W.jsxs)(`div`,{className:`flex items-center gap-1 font-headline-md text-[10px] min-[400px]:text-xs sm:text-sm font-extrabold tracking-wide uppercase truncate`,children:[(0,W.jsx)(`span`,{className:`font-arcade text-[8px] sm:text-[9px] px-1 py-0.5 bg-black/10 rounded shrink-0`,children:`2`}),(0,W.jsx)(`span`,{className:`truncate`,children:`Hard`})]})}),(0,W.jsx)(`button`,{onClick:()=>a(3),disabled:r,className:`flex-1 min-w-0 bg-[#4ade80] hover:bg-[#22c55e] border-2 sm:border-[3px] border-ink-black py-2 sm:py-2.5 px-1 sm:px-2 arcade-btn cursor-pointer disabled:opacity-60 text-ink-black flex flex-col items-center justify-center font-bold transition-all select-none`,title:`Press 3 on keyboard`,children:i===3?(0,W.jsx)(`div`,{className:`flex items-center gap-1.5 font-arcade text-[10px]`,children:(0,W.jsx)(n,{className:`w-3.5 h-3.5 animate-spin text-ink-black`})}):(0,W.jsxs)(`div`,{className:`flex items-center gap-1 font-headline-md text-[10px] min-[400px]:text-xs sm:text-sm font-extrabold tracking-wide uppercase truncate`,children:[(0,W.jsx)(`span`,{className:`font-arcade text-[8px] sm:text-[9px] px-1 py-0.5 bg-black/10 rounded shrink-0`,children:`3`}),(0,W.jsx)(`span`,{className:`truncate`,children:`Good`})]})}),(0,W.jsx)(`button`,{onClick:()=>a(4),disabled:r,className:`flex-1 min-w-0 bg-[#60a5fa] hover:bg-[#3b82f6] border-2 sm:border-[3px] border-ink-black py-2 sm:py-2.5 px-1 sm:px-2 arcade-btn cursor-pointer disabled:opacity-60 text-ink-black flex flex-col items-center justify-center font-bold transition-all select-none`,title:`Press 4 on keyboard`,children:i===4?(0,W.jsx)(`div`,{className:`flex items-center gap-1.5 font-arcade text-[10px]`,children:(0,W.jsx)(n,{className:`w-3.5 h-3.5 animate-spin text-ink-black`})}):(0,W.jsxs)(`div`,{className:`flex items-center gap-1 font-headline-md text-[10px] min-[400px]:text-xs sm:text-sm font-extrabold tracking-wide uppercase truncate`,children:[(0,W.jsx)(`span`,{className:`font-arcade text-[8px] sm:text-[9px] px-1 py-0.5 bg-black/10 rounded shrink-0`,children:`4`}),(0,W.jsx)(`span`,{className:`truncate`,children:`Easy`})]})})]})]})}),xe=({nextMilestone:e,activatingMilestone:t,onActivateNextMilestone:r,onOpenOnboarding:i,onOpenJourney:a,onOpenCreateProblem:o,onOpenWindow:s,overrideProblemId:c,onClearOverride:u,hasCustomOnboardingModal:f,isOnboardingOpen:p,onCloseOnboarding:h,onCompletedOnboarding:y,currentUserId:b})=>(0,W.jsx)(`div`,{className:`w-full h-full flex items-center justify-center bg-[#fdf8e1] p-6 overflow-y-auto custom-scrollbar`,children:(0,W.jsxs)(`div`,{className:`w-full max-w-lg bg-paper-white border-[4px] border-ink-black gadget-shadow p-6 sm:p-8 relative overflow-hidden text-center space-y-6`,children:[(0,W.jsx)(`div`,{className:`absolute top-0 left-0 right-0 h-3 bg-gradient-to-r from-grass-green via-amber-300 to-highlight-pink`}),(0,W.jsxs)(`div`,{className:`relative inline-block mt-2`,children:[(0,W.jsx)(`div`,{className:`w-20 h-20 bg-amber-300 border-[3px] border-ink-black rounded-2xl flex items-center justify-center mx-auto gadget-shadow rotate-[-3deg] hover:rotate-0 transition-transform`,children:(0,W.jsx)(S,{className:`w-10 h-10 text-ink-black stroke-[2.5]`})}),(0,W.jsx)(`div`,{className:`absolute -bottom-2 -right-2 bg-grass-green border-2 border-ink-black px-2 py-0.5 font-arcade text-[8px] text-ink-black font-bold uppercase shadow-[2px_2px_0px_0px_rgba(30,41,59,1)]`,children:`100% DONE`})]}),(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2.5 py-1 bg-emerald-100 border-2 border-ink-black text-emerald-800 font-arcade text-[9px] font-bold`,children:[(0,W.jsx)(E,{className:`w-3 h-3 stroke-[3]`}),` ALL CARDS COMPLETED FOR TODAY`]}),(0,W.jsx)(`h2`,{className:`text-2xl sm:text-3xl font-extrabold text-ink-black font-headline-md tracking-tight`,children:`You're all caught up for today. Keep it up.`}),(0,W.jsx)(`p`,{className:`text-xs sm:text-sm font-sans text-trash-gray max-w-md mx-auto leading-relaxed font-semibold`,children:`All reviews for today are finished. Next reviews are scheduled for tomorrow.`})]}),e&&(0,W.jsxs)(`div`,{className:`p-4 sm:p-5 bg-gradient-to-br from-amber-50 to-orange-50 border-[3px] border-ink-black gadget-shadow text-left space-y-3`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,W.jsxs)(`span`,{className:`font-arcade text-[9px] font-bold text-amber-800 uppercase tracking-wider flex items-center gap-1.5`,children:[(0,W.jsx)(_,{className:`w-3.5 h-3.5 text-amber-600`}),`NEXT UNEXPLORED MILESTONE`]}),(0,W.jsxs)(`span`,{className:`font-mono text-[10px] font-bold px-2 py-0.5 rounded bg-amber-900/10 text-amber-900 border border-amber-900/20`,children:[`LC #`,e.problem_number]})]}),(0,W.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-3`,children:[(0,W.jsxs)(`div`,{className:`min-w-0`,children:[(0,W.jsx)(`h3`,{className:`font-headline-md text-base sm:text-lg font-bold text-ink-black truncate`,children:e.name}),(0,W.jsxs)(`div`,{className:`flex items-center gap-2 mt-1 flex-wrap`,children:[(0,W.jsx)(`span`,{className:`px-2 py-0.5 rounded font-arcade text-[8px] font-bold uppercase text-white ${e.difficulty===`Easy`?`bg-emerald-600`:e.difficulty===`Medium`?`bg-amber-600`:`bg-rose-600`}`,children:e.difficulty}),(0,W.jsx)(`span`,{className:`px-2 py-0.5 rounded font-arcade text-[8px] bg-purple-100 text-purple-800 border border-purple-300 font-bold`,children:e.pattern}),(0,W.jsxs)(`span`,{className:`text-[11px] font-code-mono text-slate-600`,children:[`T: `,e.time_complexity,` | S: `,e.space_complexity]})]})]}),(0,W.jsx)(`button`,{onClick:r,disabled:t,className:`px-4 py-2.5 bg-grass-green hover:bg-emerald-400 text-ink-black font-arcade text-[9px] font-bold border-2 border-ink-black shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none transition-all cursor-pointer shrink-0 flex items-center justify-center gap-1.5 disabled:opacity-50`,children:t?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(n,{className:`w-3.5 h-3.5 animate-spin`}),(0,W.jsx)(`span`,{children:`ACTIVATING...`})]}):(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(T,{className:`w-3.5 h-3.5 text-amber-700`}),(0,W.jsx)(`span`,{children:`ACTIVATE & REVIEW NOW`})]})})]})]}),(0,W.jsxs)(`div`,{className:`p-4 sm:p-5 bg-gradient-to-r from-amber-100 via-amber-200 to-yellow-100 border-[3px] border-ink-black gadget-shadow text-left flex flex-col sm:flex-row items-start sm:items-center justify-between gap-3`,children:[(0,W.jsxs)(`div`,{className:`space-y-1`,children:[(0,W.jsxs)(`span`,{className:`font-arcade text-[9px] font-bold text-amber-900 uppercase flex items-center gap-1.5`,children:[(0,W.jsx)(v,{className:`w-3.5 h-3.5 text-amber-700`}),`FAST-TRACK EXPEDITION ENROLLMENT`]}),(0,W.jsx)(`h3`,{className:`font-headline-md text-base sm:text-lg font-bold text-ink-black`,children:`Already Solved Problems Elsewhere?`}),(0,W.jsx)(`p`,{className:`font-sans text-xs text-trash-gray font-semibold max-w-md`,children:`Check off problems you've already solved elsewhere to seed your review queue.`})]}),(0,W.jsxs)(`button`,{onClick:i,className:`px-4 py-2.5 bg-amber-400 hover:bg-amber-300 text-ink-black font-arcade text-[9px] font-bold border-2 border-ink-black shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none transition-all cursor-pointer shrink-0 flex items-center gap-1.5`,children:[(0,W.jsx)(v,{className:`w-3.5 h-3.5 text-amber-900`}),(0,W.jsx)(`span`,{children:`OPEN 150-PROBLEM CHECKLIST`})]})]}),(0,W.jsxs)(`div`,{className:`border-t-[3px] border-dashed border-ink-black pt-5 space-y-3`,children:[(0,W.jsx)(`div`,{className:`text-[9px] font-arcade text-trash-gray uppercase font-bold text-left`,children:`CONTINUE PRACTICING:`}),(0,W.jsxs)(`div`,{className:`grid grid-cols-2 sm:grid-cols-4 gap-2.5`,children:[(0,W.jsxs)(`button`,{onClick:a,className:`p-3 bg-amber-100 hover:bg-amber-200 border-[3px] border-ink-black text-left flex flex-col justify-between gadget-shadow active:translate-y-1 active:shadow-none transition-all cursor-pointer`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,W.jsx)(_,{className:`w-4 h-4 text-amber-600`}),(0,W.jsx)(g,{className:`w-3 h-3 text-ink-black`})]}),(0,W.jsxs)(`div`,{className:`mt-2`,children:[(0,W.jsx)(`div`,{className:`font-arcade text-[8px] font-bold text-ink-black uppercase`,children:`Journey Trail`}),(0,W.jsx)(`div`,{className:`font-sans text-[10px] text-trash-gray font-semibold`,children:`150 Curated nodes`})]})]}),(0,W.jsxs)(`button`,{onClick:o,className:`p-3 bg-purple-100 hover:bg-purple-200 border-[3px] border-ink-black text-left flex flex-col justify-between gadget-shadow active:translate-y-1 active:shadow-none transition-all cursor-pointer`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,W.jsx)(m,{className:`w-4 h-4 text-purple-700`}),(0,W.jsx)(g,{className:`w-3 h-3 text-ink-black`})]}),(0,W.jsxs)(`div`,{className:`mt-2`,children:[(0,W.jsx)(`div`,{className:`font-arcade text-[8px] font-bold text-ink-black uppercase`,children:`Add Problem`}),(0,W.jsx)(`div`,{className:`font-sans text-[10px] text-trash-gray font-semibold`,children:`New LeetCode entry`})]})]}),(0,W.jsxs)(`button`,{onClick:()=>s?.(`companion`),className:`p-3 bg-yellow-100 hover:bg-yellow-200 border-[3px] border-ink-black text-left flex flex-col justify-between gadget-shadow active:translate-y-1 active:shadow-none transition-all cursor-pointer`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,W.jsx)(`span`,{className:`material-symbols-outlined text-amber-600 text-lg`,children:`castle`}),(0,W.jsx)(g,{className:`w-3 h-3 text-ink-black`})]}),(0,W.jsxs)(`div`,{className:`mt-2`,children:[(0,W.jsx)(`div`,{className:`font-arcade text-[8px] font-bold text-ink-black uppercase`,children:`Princess Tower`}),(0,W.jsx)(`div`,{className:`font-sans text-[10px] text-trash-gray font-semibold`,children:`Visit Aurelia`})]})]}),(0,W.jsxs)(`button`,{onClick:()=>s?.(`computer`),className:`p-3 bg-cyan-100 hover:bg-cyan-200 border-[3px] border-ink-black text-left flex flex-col justify-between gadget-shadow active:translate-y-1 active:shadow-none transition-all cursor-pointer`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,W.jsx)(d,{className:`w-4 h-4 text-cyan-700`}),(0,W.jsx)(g,{className:`w-3 h-3 text-ink-black`})]}),(0,W.jsxs)(`div`,{className:`mt-2`,children:[(0,W.jsx)(`div`,{className:`font-arcade text-[8px] font-bold text-ink-black uppercase`,children:`File Explorer`}),(0,W.jsx)(`div`,{className:`font-sans text-[10px] text-trash-gray font-semibold`,children:`Browse all files`})]})]})]})]}),c&&u&&(0,W.jsxs)(`button`,{onClick:u,className:`mt-3 bg-white hover:bg-slate-100 border-[3px] border-ink-black text-ink-black font-bold px-4 py-2 text-xs uppercase tracking-wide shadow-[3px_3px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none transition-all cursor-pointer inline-flex items-center gap-2`,children:[(0,W.jsx)(l,{className:`w-3.5 h-3.5`}),` Return to Scheduled Queue`]}),!f&&(0,W.jsx)(R,{isOpen:p,onClose:h,onCompleted:y,userId:b})]})}),Se=e({default:()=>we}),Ce=(0,U.lazy)(()=>te(()=>import(`./ProblemSpecPanel-Df-cRYRz.js`).then(e=>({default:e.ProblemSpecPanel})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9])));function we({overrideProblemId:e,onClearOverride:t,onOpenWindow:r,onOpenJourney:i,onOpenCreateProblem:a,onOpenEditProblem:o,onOpenOnboarding:s,refreshTrigger:c}){let[l,f]=(0,U.useState)(null),p=l!==null&&l<780,[m,h]=(0,U.useState)(`spec`),[g,_]=(0,U.useState)(`spec`),[v,b]=(0,U.useState)(null),ee=(0,U.useCallback)(e=>{e&&(f(e.clientWidth),new ResizeObserver(e=>{for(let t of e)f(t.contentRect.width)}).observe(e))},[]),[x,S]=(0,U.useState)(!1),[C,w]=(0,U.useState)(()=>localStorage.getItem(`isAutocompleteEnabled`)!==`false`),{reviews:T,setReviews:E,loading:D,submitting:O,submittingRating:k,gradeError:A,setGradeError:j,code:M,setCode:P,nextMilestone:te,activatingMilestone:L,currentUserId:z,fetchQueue:ne,handleGrade:B,handleSelectCard:V,handleActivateNextMilestone:H,handleResetStarterCode:re}=le({overrideProblemId:e,refreshTrigger:c,onClearOverride:t,onOpenOnboarding:s,setIsOnboardingOpen:S}),{sandboxRunning:ie,sandboxResults:ae,sandboxError:ce,savingReference:pe,savedRefSuccess:me,saveRefError:G,handleRunSandbox:he,handleSaveReference:ge,resetSandbox:K}=ue(),{aiLoading:_e,aiResult:ve,aiError:Se,explainLoading:we,explanationText:Te,explainError:Ee,aiSolutionLoading:De,aiSolutionError:Oe,handleAiEvaluation:ke,handleExplainCode:Ae,handleFetchAiSolution:je,resetAiState:q}=de(),[Me,Ne]=(0,U.useState)(!1),[Pe,Fe]=(0,U.useState)(null),[Ie,J]=(0,U.useState)(null),Le=(0,U.useCallback)(async()=>{if(T.length===0)return;let e=T[0]?.problems||{},t=M.trim()||e.reference_code||``;if(!t){J(`Please write or save code before pushing to GitHub.`),setTimeout(()=>J(null),4e3);return}let n=I();if(!n.token){r&&r(`github`);return}Ne(!0),J(null),Fe(null);try{let r=await F({token:n.token,repo:n.repoName,branch:n.branch,problem_number:e.problem_number,problem_name:e.name||`Algorithm Problem`,pattern:e.pattern||`Algorithms`,difficulty:e.difficulty||`Medium`,optimal_time:e.optimal_time||`O(N)`,optimal_space:e.optimal_space||`O(1)`,description:e.description||``,code:t});Fe(r.html_url),setTimeout(()=>Fe(null),8e3)}catch(e){J(e.message||`Failed to push solution to GitHub.`),setTimeout(()=>J(null),5e3)}finally{Ne(!1)}},[T,M,r]),Re=T[0]?.id||T[0]?.problem_id,ze=(0,U.useRef)(void 0);(0,U.useEffect)(()=>{Re&&ze.current!==Re&&(ze.current=Re,q(),K())},[Re,q,K]);let Y=(0,U.useCallback)(e=>{q(),K(),B(e)},[B,q,K]),Be=(0,U.useCallback)(e=>{q(),K(),V(e)},[V,q,K]);(0,U.useEffect)(()=>{let e=e=>{let t=e.target;t?.closest(`.cm-editor`)||t?.tagName===`INPUT`||t?.tagName===`TEXTAREA`||t?.isContentEditable||T.length===0||O||(e.key===`1`?(e.preventDefault(),Y(1)):e.key===`2`?(e.preventDefault(),Y(2)):e.key===`3`?(e.preventDefault(),Y(3)):e.key===`4`&&(e.preventDefault(),Y(4)))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[Y,T.length,O]);let Ve=(e,t)=>{navigator.clipboard.writeText(e),b(t),setTimeout(()=>b(null),1800)},He=(0,U.useCallback)(()=>{i?i():r?.(`journey`)},[i,r]),Ue=(0,U.useCallback)(()=>{a?a():r?.(`createProblem`)},[a,r]),We=(0,U.useCallback)(()=>{s?s():S(!0)},[s]),Ge=(0,U.useCallback)(e=>{E(t=>{if(t.length===0)return t;let n=[...t],r=n[0];return r&&r.problems&&(r.problems={...r.problems,solutions:e}),n})},[E]);if(D)return(0,W.jsx)(`div`,{className:`w-full h-full flex items-center justify-center bg-[#fdf8e1] text-ink-black`,children:(0,W.jsxs)(`div`,{className:`flex flex-col items-center gap-4 p-8 bg-paper-white border-[3px] border-ink-black gadget-shadow text-center max-w-xs`,children:[(0,W.jsx)(`div`,{className:`w-12 h-12 bg-amber-200 border-2 border-ink-black flex items-center justify-center animate-spin`,children:(0,W.jsx)(n,{className:`w-6 h-6 text-ink-black`})}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h3`,{className:`font-arcade text-xs text-ink-black uppercase tracking-wider font-bold`,children:`LOADING QUEUE`}),(0,W.jsx)(`p`,{className:`font-sans text-[11px] text-trash-gray mt-1 font-semibold`,children:`Fetching scheduled FSRS review cards...`})]})]})});if(T.length===0)return(0,W.jsx)(xe,{nextMilestone:te,activatingMilestone:L,onActivateNextMilestone:H,onOpenOnboarding:We,onOpenJourney:He,onOpenCreateProblem:Ue,onOpenWindow:r,overrideProblemId:e,onClearOverride:t,hasCustomOnboardingModal:!!s,isOnboardingOpen:x,onCloseOnboarding:()=>S(!1),onCompletedOnboarding:ne,currentUserId:z});let X=T[0],Z=X?.problems,Ke=Z?.problem_number??(/^\d+$/.test(X?.problem_id||``)?parseInt(X.problem_id,10):void 0),Q=N(Ke,Z?.id||X?.problem_id,Z?.name),{cleanTitle:qe,approachVariant:Je,pattern:Ye}=se(Z?.name,Q?.name,Z?.pattern,Q?.pattern),$={...Q,...Z,id:Z?.id||Q?.id||X?.problem_id,name:qe,problem_number:Z?.problem_number??Q?.problem_number,pattern:Ye,approach_variant:Je,difficulty:Z?.difficulty||Q?.difficulty||`Medium`,reference_code:Z?.reference_code||Q?.reference_solution||``,starter_code:Q?.starter_code||Z?.starter_code||``,description:Z?.description||Q?.description||``,optimal_time:Z?.optimal_time||Q?.time_complexity||`O(N)`,optimal_space:Z?.optimal_space||Q?.space_complexity||`O(1)`,examples:Z?.examples&&Z.examples.length>0?Z.examples:Q?.examples,constraints:Z?.constraints||Q?.constraints,how_to_solve:Z?.how_to_solve||``,solutions:Z?.solutions&&Z.solutions.length>0?Z.solutions:Q?.solutions},Xe=oe({...Q,...$,examples:$.examples&&$.examples.length>0?$.examples:Q?.examples,constraints:$.constraints&&(Array.isArray($.constraints)?$.constraints.length>0:$.constraints)?$.constraints:Q?.constraints}),Ze=Q?.reference_solution||``,Qe=Z?.reference_code||``,$e=Qe&&(!Ze||Qe.trim()!==Ze.trim())?Qe:``,et=$e||Ze||Qe||``;return(0,W.jsxs)(`div`,{ref:ee,className:`w-full h-full bg-[#fdf8e1] flex flex-col overflow-hidden select-none`,children:[(0,W.jsx)(fe,{problem:$,totalInQueue:T.length,reviews:T,overrideProblemId:e,onSelectCard:Be,onOpenCreateProblem:Ue,onOpenEditProblem:()=>{o?o($):r?.(`editProblem`)}}),(0,W.jsxs)(`div`,{className:`${p?`flex`:`hidden`} shrink-0 bg-amber-100 border-b-[3px] border-ink-black px-2.5 sm:px-3 py-1.5 gap-1.5 sm:gap-2 overflow-x-auto no-scrollbar`,children:[(0,W.jsxs)(`button`,{onClick:()=>{_(`spec`),h(`spec`)},className:`px-2.5 sm:px-3 py-1 text-[9px] font-arcade font-bold border-2 border-ink-black transition-all cursor-pointer flex items-center gap-1.5 whitespace-nowrap ${g===`spec`?`bg-paper-white translate-y-0.5 shadow-none text-ink-black`:`bg-white shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] text-trash-gray`}`,children:[(0,W.jsx)(u,{className:`w-3 h-3 shrink-0`}),(0,W.jsx)(`span`,{children:`SPEC`})]}),(0,W.jsxs)(`button`,{onClick:()=>_(`code`),className:`px-2.5 sm:px-3 py-1 text-[9px] font-arcade font-bold border-2 border-ink-black transition-all cursor-pointer flex items-center gap-1.5 whitespace-nowrap ${g===`code`?`bg-paper-white translate-y-0.5 shadow-none text-ink-black`:`bg-white shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] text-trash-gray`}`,children:[(0,W.jsx)(y,{className:`w-3 h-3 shrink-0`}),(0,W.jsx)(`span`,{children:`CODE STUDIO`})]}),(0,W.jsxs)(`button`,{onClick:()=>{_(`ref`),h(`ref`)},className:`px-2.5 sm:px-3 py-1 text-[9px] font-arcade font-bold border-2 border-ink-black transition-all cursor-pointer flex items-center gap-1.5 whitespace-nowrap ${g===`ref`?`bg-paper-white translate-y-0.5 shadow-none text-ink-black`:`bg-white shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] text-trash-gray`}`,children:[(0,W.jsx)(d,{className:`w-3 h-3 shrink-0`}),(0,W.jsx)(`span`,{children:`SOLUTION`})]})]}),(0,W.jsxs)(`div`,{className:`flex-1 flex ${p?`flex-col`:`flex-row`} overflow-hidden min-h-0`,children:[(0,W.jsx)(U.Suspense,{fallback:(0,W.jsx)(`div`,{className:`flex-1 flex flex-col items-center justify-center p-8 bg-paper-white ${p?`h-64`:`border-r-[4px] border-ink-black`} font-sans text-xs text-trash-gray select-none`,children:(0,W.jsxs)(`div`,{className:`flex items-center gap-2 font-arcade text-[10px] text-ink-black`,children:[(0,W.jsx)(n,{className:`w-4 h-4 animate-spin text-[#0ea5e9]`}),(0,W.jsx)(`span`,{children:`Loading Problem Spec...`})]})}),children:(0,W.jsx)(Ce,{leftTab:m,onSelectLeftTab:e=>{h(e),e===`ref`?_(`ref`):e===`spec`&&_(`spec`)},mobileView:g,isNarrow:p,problem:$,parsed:Xe,userSolution:$e,officialSolution:Ze,effectiveReferenceCode:et,copiedSnippet:v,onCopyText:Ve,saveRefError:G,aiSolutionLoading:De,aiSolutionError:Oe,onFetchAiSolution:()=>je(X,e=>{E(t=>t.map((t,n)=>n===0?{...t,problems:{...$||{},...t.problems||{},reference_code:e}}:t))}),explainLoading:we,explainError:Ee,explanationText:Te,onExplainCode:(e,t,n,r)=>Ae(X,e,t,n,r),activeReview:X,onUpdateSolutions:Ge,onEditProblem:()=>{o?o($):r?.(`editProblem`)}})}),(0,W.jsx)(ye,{mobileView:g,isNarrow:p,isAutocompleteEnabled:C,onToggleAutocomplete:e=>{w(e),localStorage.setItem(`isAutocompleteEnabled`,String(e))},onResetStarterCode:re,code:M,onChangeCode:P,sandboxRunning:ie,sandboxError:ce,sandboxResults:ae,onRunSandbox:()=>he(X,M),savingReference:pe,savedRefSuccess:me,saveRefError:G,onSaveReference:()=>ge(X,M,(e,t)=>{E(n=>n.map((n,r)=>r===0?{...n,problem_id:t||n.problem_id,problems:{...$||{},...n.problems||{},id:t||n.problems?.id||n.problem_id,reference_code:e}}:n))}),aiLoading:_e,aiError:Se,aiResult:ve,onAiEvaluation:()=>ke(X,M),optimalTime:$.optimal_time||`O(N)`,optimalSpace:$.optimal_space||`O(1)`,onPushToGitHub:Le,pushingToGitHub:Me,githubPushedUrl:Pe,githubPushError:Ie})]}),(0,W.jsx)(be,{gradeError:A,onDismissGradeError:()=>j(null),submitting:O,submittingRating:k,onGrade:Y}),!s&&(0,W.jsx)(R,{isOpen:x,onClose:()=>S(!1),onCompleted:ne,userId:z})]})}export{we as default,ce as n,Se as t};
|
algospaced-ui/dist/assets/{Settings-LIc5x45z.js → Settings-mOsQagfT.js}
RENAMED
|
@@ -1 +1 @@
|
|
| 1 |
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{$ as t,D as n,J as r,K as i,Lt as a,Z as o,at as s,d as c,et as l,ft as u,j as d,k as f,mt as p,nt as m,o as h,tt as g,x as ee,y as _,zt as v}from"./vendor-react-yvPwY2Sj.js";import{d as y,f as b,h as x,m as S,p as C,v as w}from"./index-DttZMwvA.js";import{a as te,i as ne,n as re,r as T,s as E,t as D}from"./githubSyncService-DQdE4J2L.js";var O=e(v(),1),k=a(),A=[{id:`default`,name:`Default`,desc:`Subject to Availability`},{id:`groq`,name:`Groq`,badge:`Fastest`,desc:`Llama 3.3 & Qwen`,keyPrefix:`gsk_...`,portalUrl:`https://console.groq.com/keys`},{id:`gemini`,name:`Google Gemini`,desc:`Gemini 2.5 / 3.5`,keyPrefix:`AIzaSy...`,portalUrl:`https://aistudio.google.com/app/apikey`},{id:`openrouter`,name:`OpenRouter`,desc:`Multi-Provider`,keyPrefix:`sk-or-v1-...`,portalUrl:`https://openrouter.ai/keys`}];function j(){let[e,a]=(0,O.useState)(()=>localStorage.getItem(`algospaced_custom_ai_provider`)||`default`),[v,j]=(0,O.useState)(()=>localStorage.getItem(`algospaced_custom_api_key`)||localStorage.getItem(`sandbox_gemini_api_key`)||``),[M,N]=(0,O.useState)(!1),[P,F]=(0,O.useState)(null),[I,L]=(0,O.useState)(()=>y()),[R,z]=(0,O.useState)(null),[B,V]=(0,O.useState)(()=>b().currentFloor),[H,U]=(0,O.useState)(()=>T()),[W,G]=(0,O.useState)(()=>ne()),[K,q]=(0,O.useState)(!1),[J,Y]=(0,O.useState)(null),X=!!(H.token&&(H.username||W?.login)),Z=!!(v.trim()&&e!=="default"),Q=e!=="default"&&!v.trim(),$=A.find(t=>t.id===e),ie=e=>{a(e),localStorage.setItem(`algospaced_custom_ai_provider`,e),F(e==="default"?{type:`info`,text:`Switched to Server Default (Shared Pool).`}:{type:`info`,text:`Switched to ${e.toUpperCase()}.`}),setTimeout(()=>F(null),3e3)},ae=()=>{let t=v.trim();if(!t){F({type:`error`,text:`Please enter an API key for ${e.toUpperCase()}.`}),setTimeout(()=>F(null),3e3);return}localStorage.setItem(`algospaced_custom_api_key`,t),localStorage.setItem(`sandbox_gemini_api_key`,t),localStorage.setItem(`algospaced_custom_ai_provider`,e),F({type:`success`,text:`${e.toUpperCase()} API key saved successfully.`}),setTimeout(()=>F(null),3e3)},oe=()=>{localStorage.removeItem(`algospaced_custom_api_key`),localStorage.removeItem(`sandbox_gemini_api_key`),j(``),F({type:`info`,text:`Cleared custom API key.`}),setTimeout(()=>F(null),3e3)},se=()=>{localStorage.removeItem(`algospaced_custom_api_key`),localStorage.removeItem(`sandbox_gemini_api_key`),localStorage.setItem(`algospaced_custom_ai_provider`,`default`),j(``),a(`default`),F({type:`info`,text:`Reset to Server Default provider.`}),setTimeout(()=>F(null),3e3)},ce=()=>{S(I),z({type:`success`,text:`Princess Companion settings saved!`}),setTimeout(()=>z(null),3e3)},le=()=>{L(x),S(x),z({type:`info`,text:`Reset companion to default settings.`}),setTimeout(()=>z(null),3e3)},ue=()=>{if(window.confirm(`Are you sure you want to reset your Spire Journey progress back to 0 problems?`)){let e=C();V(e.currentFloor),z({type:`info`,text:`Spire journey progress reset to 0 problems.`}),setTimeout(()=>z(null),3e3)}},de=async()=>{q(!0),Y(null);try{let{token:e,user:t}=await re();G(t);let n=T();U(n);try{await te(e,n.repoName,n.isPrivate)}catch{}Y({type:`success`,text:`Connected to GitHub as @${t.login}!`}),setTimeout(()=>Y(null),4e3)}catch(e){Y({type:`error`,text:e.message||`GitHub connection failed.`}),setTimeout(()=>Y(null),5e3)}finally{q(!1)}},fe=()=>{D(),U(T()),G(null),Y({type:`info`,text:`Disconnected from GitHub.`}),setTimeout(()=>Y(null),3e3)},pe=e=>{E({autoCommit:e}),U(t=>({...t,autoCommit:e})),Y({type:`info`,text:e?`Auto-commit enabled for review submissions.`:`Auto-commit disabled.`}),setTimeout(()=>Y(null),3e3)};return(0,k.jsxs)(`div`,{className:`w-full h-full bg-[#fdf8e1] p-5 sm:p-6 flex flex-col gap-4 select-none font-sans text-ink-black overflow-y-auto custom-scrollbar`,children:[(0,k.jsxs)(`div`,{className:`flex flex-col gap-0.5 border-b-[3px] border-ink-black pb-2.5`,children:[(0,k.jsxs)(`h3`,{className:`font-headline-md font-bold text-sm m-0 flex items-center gap-2 tracking-wide`,children:[(0,k.jsx)(i,{className:`w-4 h-4 text-ink-black`}),`API & AI Configuration`]}),(0,k.jsx)(`p`,{className:`text-[11px] text-trash-gray font-medium m-0`,children:`Configure your AI model provider..`})]}),(0,k.jsx)(`div`,{className:`px-4 py-3 border-[3px] border-ink-black shadow-[3px_3px_0px_0px_rgba(30,41,59,1)] transition-all ${Z?`bg-emerald-50`:Q?`bg-rose-50`:`bg-amber-50/70`}`,children:(0,k.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,k.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[Z?(0,k.jsx)(h,{className:`w-4 h-4 text-emerald-600 shrink-0`}):Q?(0,k.jsx)(p,{className:`w-4 h-4 text-rose-600 shrink-0`}):(0,k.jsx)(m,{className:`w-4 h-4 text-amber-600 shrink-0`}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`div`,{className:`text-xs font-bold font-headline-md text-ink-black flex items-center gap-1.5`,children:(0,k.jsxs)(`span`,{children:[`Active:`,` `,Z?`${e.toUpperCase()} (Custom Key)`:Q?`${e.toUpperCase()} (Key Required)`:`Default`]})}),(0,k.jsx)(`div`,{className:`text-[10px] text-trash-gray font-medium`,children:Z?`Requests are routed directly through your personal API key.`:Q?`Enter your API key below to activate this provider.`:`Using basic, free built-in developer keys with auto-failover.`})]})]}),(0,k.jsx)(`span`,{className:`px-2 py-0.5 text-[9px] font-bold font-arcade uppercase border-2 border-ink-black shrink-0 ${Z?`bg-emerald-300 text-emerald-950`:Q?`bg-rose-300 text-rose-950`:`bg-amber-200 text-amber-950`}`,children:Z?`ACTIVE`:Q?`NEEDS KEY`:`LIMITED`})]})}),(0,k.jsxs)(`div`,{className:`bg-white border-[3px] border-ink-black p-4 sm:p-5 shadow-[4px_4px_0px_0px_rgba(30,41,59,1)] flex flex-col gap-4`,children:[(0,k.jsxs)(`div`,{children:[(0,k.jsxs)(`label`,{className:`block text-xs font-bold text-ink-black uppercase tracking-wider mb-2 font-headline-md flex items-center gap-1.5`,children:[(0,k.jsx)(m,{className:`w-3.5 h-3.5 text-ink-black`}),`Select Provider`]}),(0,k.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-4 gap-2`,children:A.map(t=>{let n=e===t.id;return(0,k.jsxs)(`button`,{type:`button`,onClick:()=>ie(t.id),className:`p-2.5 border-[2px] text-left transition-all cursor-pointer flex flex-col justify-between rounded ${n?`border-ink-black bg-[#ffe24c] shadow-[2px_2px_0px_0px_#1E293B] font-bold`:`border-slate-300 bg-slate-50 hover:bg-slate-100 text-slate-700`}`,children:[(0,k.jsxs)(`div`,{className:`flex items-center justify-between w-full`,children:[(0,k.jsx)(`span`,{className:`text-xs font-bold font-headline-md`,children:t.name}),t.badge&&(0,k.jsx)(`span`,{className:`text-[8px] font-bold uppercase px-1 py-0.2 bg-orange-100 text-orange-700 rounded border border-orange-300`,children:t.badge})]}),(0,k.jsx)(`span`,{className:`text-[9px] mt-1 text-slate-600 leading-tight block`,children:t.desc})]},t.id)})})]}),e==="default"?(0,k.jsxs)(`div`,{className:`p-3.5 bg-slate-50 border border-slate-200 rounded flex items-start gap-3`,children:[(0,k.jsx)(c,{className:`w-4 h-4 text-amber-500 shrink-0 mt-0.5`}),(0,k.jsxs)(`div`,{className:`flex flex-col gap-1 text-xs text-slate-700`,children:[(0,k.jsxs)(`span`,{className:`font-bold text-ink-black`,children:[`Shared Quotas (`,(0,k.jsx)(`i`,{children:`limited`}),`)`]}),(0,k.jsx)(`p`,{className:`text-[11px] text-trash-gray m-0 leading-relaxed`,children:`Powered by shared, basic developer keys. Because limits are shared with everyone, requests may fail. Use your own provider keys above for stable performance.`})]})]}):(0,k.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,k.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,k.jsxs)(`label`,{className:`block text-xs font-bold text-ink-black uppercase tracking-wider font-headline-md flex items-center gap-1.5`,children:[(0,k.jsx)(i,{className:`w-3.5 h-3.5 text-ink-black`}),$?.name,` API Key`]}),$?.portalUrl&&(0,k.jsxs)(`a`,{href:$.portalUrl,target:`_blank`,rel:`noopener noreferrer`,className:`text-[10px] text-sky-600 hover:text-sky-800 font-medium flex items-center gap-1 no-underline`,children:[(0,k.jsx)(`span`,{children:`Get API Key`}),(0,k.jsx)(g,{className:`w-3 h-3`})]})]}),(0,k.jsxs)(`div`,{className:`relative`,children:[(0,k.jsx)(`input`,{type:M?`text`:`password`,value:v,onChange:e=>j(e.target.value),placeholder:`Enter ${$?.keyPrefix||`API Key`}`,className:`w-full bg-white border-[2px] border-ink-black rounded py-2 pl-3 pr-9 text-ink-black placeholder-slate-400 focus:outline-none focus:border-sky-600 text-xs font-code-mono`}),(0,k.jsx)(`button`,{type:`button`,onClick:()=>N(!M),className:`absolute right-2.5 top-1/2 -translate-y-1/2 text-trash-gray hover:text-ink-black cursor-pointer bg-transparent border-0 outline-none p-1`,title:M?`Hide API key`:`Show API key`,children:M?(0,k.jsx)(l,{className:`w-3.5 h-3.5`}):(0,k.jsx)(t,{className:`w-3.5 h-3.5`})})]}),(0,k.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-trash-gray font-medium`,children:[(0,k.jsx)(ee,{className:`w-3.5 h-3.5 text-emerald-600 shrink-0`}),(0,k.jsx)(`span`,{children:`Stored locally in your browser. Sent directly via request headers.`})]}),(0,k.jsxs)(`div`,{className:`flex gap-2 pt-1`,children:[(0,k.jsxs)(`button`,{onClick:ae,className:`flex-1 flex items-center justify-center gap-1.5 py-2 border-[2px] border-ink-black bg-[#ffe24c] hover:bg-yellow-300 text-xs font-bold text-ink-black shadow-[2px_2px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none transition-all cursor-pointer rounded uppercase`,children:[(0,k.jsx)(n,{className:`w-3.5 h-3.5`}),`Save Key`]}),v&&(0,k.jsx)(`button`,{onClick:oe,className:`px-3 py-2 border-[2px] border-slate-300 bg-white hover:bg-slate-50 text-xs font-bold text-slate-700 hover:text-rose-600 shadow-[2px_2px_0px_0px_rgba(0,0,0,0.05)] active:translate-y-0.5 active:shadow-none transition-all cursor-pointer rounded uppercase`,children:`Clear Key`})]})]}),P&&(0,k.jsxs)(`div`,{className:`p-2.5 border-[2px] border-ink-black text-xs font-medium rounded flex items-center gap-2 ${P.type===`success`?`bg-emerald-100 border-emerald-600 text-emerald-900`:P.type===`error`?`bg-rose-100 border-rose-600 text-rose-900`:`bg-sky-100 border-sky-600 text-sky-900`}`,children:[P.type===`success`?(0,k.jsx)(u,{className:`w-3.5 h-3.5 shrink-0`}):P.type===`error`?(0,k.jsx)(p,{className:`w-3.5 h-3.5 shrink-0`}):(0,k.jsx)(r,{className:`w-3.5 h-3.5 shrink-0`}),P.text]}),e!=="default"&&(0,k.jsx)(`div`,{className:`pt-2 border-t border-slate-200 flex justify-end`,children:(0,k.jsxs)(`button`,{onClick:se,className:`flex items-center gap-1.5 py-1.5 px-3 border border-slate-300 bg-slate-50 hover:bg-slate-100 text-[11px] font-bold text-slate-600 hover:text-ink-black transition-all cursor-pointer rounded`,children:[(0,k.jsx)(f,{className:`w-3 h-3 text-slate-500`}),`Reset to Server Default`]})})]}),(0,k.jsxs)(`div`,{className:`bg-white border-[3px] border-ink-black p-4 sm:p-5 shadow-[4px_4px_0px_0px_rgba(30,41,59,1)] flex flex-col gap-4`,children:[(0,k.jsxs)(`div`,{className:`flex items-center justify-between border-b-[2px] border-ink-black pb-3`,children:[(0,k.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,k.jsx)(`div`,{className:`w-8 h-8 rounded bg-[#24292e] border-[2px] border-ink-black flex items-center justify-center text-white shadow-[1px_1px_0px_0px_#1E293B]`,children:(0,k.jsx)(o,{className:`w-4 h-4 text-white`})}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`h4`,{className:`font-headline-md font-bold text-xs uppercase text-ink-black m-0 flex items-center gap-2`,children:`GitHub Solutions Sync & Auto-Commit`}),(0,k.jsx)(`p`,{className:`text-[10px] text-trash-gray font-medium m-0`,children:`Sync solutions to personal GitHub repository and commit automatically on submission`})]})]}),(0,k.jsx)(`span`,{className:`px-2 py-0.5 text-[9px] font-bold font-arcade uppercase border-2 border-ink-black shrink-0 ${X?`bg-emerald-300 text-emerald-950`:`bg-slate-200 text-slate-800`}`,children:X?`CONNECTED`:`DISCONNECTED`})]}),X?(0,k.jsxs)(`div`,{className:`space-y-3`,children:[(0,k.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-2 p-3 bg-slate-50 border border-slate-200 rounded`,children:[(0,k.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[W?.avatar_url&&(0,k.jsx)(`img`,{src:W.avatar_url,alt:W.login,className:`w-7 h-7 rounded-full border border-ink-black`}),(0,k.jsxs)(`div`,{children:[(0,k.jsxs)(`span`,{className:`text-xs font-bold text-ink-black`,children:[`@`,W?.login||H.username]}),(0,k.jsxs)(`span`,{className:`text-[11px] text-slate-600 font-mono block`,children:[H.username,`/`,H.repoName,` (`,H.branch,`)`]})]})]}),(0,k.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,k.jsxs)(`a`,{href:`https://github.com/${H.username}/${H.repoName}`,target:`_blank`,rel:`noopener noreferrer`,className:`px-2.5 py-1 text-[11px] font-bold bg-white hover:bg-slate-100 text-ink-black border border-slate-300 rounded no-underline flex items-center gap-1 cursor-pointer`,children:[(0,k.jsx)(g,{className:`w-3 h-3`}),(0,k.jsx)(`span`,{children:`View Repo`})]}),(0,k.jsx)(`button`,{type:`button`,onClick:fe,className:`px-2.5 py-1 text-[11px] font-bold bg-white hover:bg-rose-50 text-rose-700 border border-rose-300 rounded cursor-pointer`,children:`Disconnect`})]})]}),(0,k.jsxs)(`label`,{className:`flex items-center gap-2.5 p-2.5 bg-emerald-50/50 border border-emerald-300 rounded cursor-pointer`,children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:H.autoCommit,onChange:e=>pe(e.target.checked),className:`w-4 h-4 accent-emerald-600 cursor-pointer`}),(0,k.jsxs)(`div`,{className:`text-xs`,children:[(0,k.jsx)(`span`,{className:`font-bold text-ink-black block`,children:`Auto-commit on every submission`}),(0,k.jsxs)(`span`,{className:`text-[10px] text-trash-gray`,children:[`Automatically pushes your code to `,H.repoName,` whenever you grade a review card.`]})]})]})]}):(0,k.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start sm:items-center justify-between gap-3 p-3.5 bg-slate-50 border border-slate-200 rounded`,children:[(0,k.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,k.jsx)(`span`,{className:`text-xs font-bold text-ink-black block`,children:`Connect your GitHub Account (1-Click OAuth)`}),(0,k.jsx)(`p`,{className:`text-[11px] text-trash-gray m-0`,children:`Grant repository access to automatically sync your DSA problem solutions as you study.`})]}),(0,k.jsx)(`button`,{type:`button`,onClick:de,disabled:K,className:`px-4 py-2 bg-[#24292e] hover:bg-black text-white text-xs font-bold uppercase rounded border-2 border-ink-black shadow-[2px_2px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none flex items-center gap-2 shrink-0 cursor-pointer disabled:opacity-50`,children:K?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(d,{className:`w-3.5 h-3.5 animate-spin`}),(0,k.jsx)(`span`,{children:`CONNECTING...`})]}):(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(o,{className:`w-3.5 h-3.5 text-yellow-300`}),(0,k.jsx)(`span`,{children:`CONNECT GITHUB`})]})})]}),J&&(0,k.jsxs)(`div`,{className:`p-2.5 border-[2px] border-ink-black text-xs font-medium rounded flex items-center gap-2 ${J.type===`success`?`bg-emerald-100 border-emerald-600 text-emerald-900`:J.type===`error`?`bg-rose-100 border-rose-600 text-rose-900`:`bg-sky-100 border-sky-600 text-sky-900`}`,children:[J.type===`success`?(0,k.jsx)(u,{className:`w-3.5 h-3.5 shrink-0`}):J.type===`error`?(0,k.jsx)(p,{className:`w-3.5 h-3.5 shrink-0`}):(0,k.jsx)(r,{className:`w-3.5 h-3.5 shrink-0`}),J.text]})]}),(0,k.jsxs)(`div`,{className:`bg-[#FFFDF0] border-[3px] border-ink-black p-4 sm:p-5 shadow-[4px_4px_0px_0px_rgba(30,41,59,1)] flex flex-col gap-4`,children:[(0,k.jsxs)(`div`,{className:`flex items-center justify-between border-b-[2px] border-ink-black pb-3`,children:[(0,k.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,k.jsx)(`div`,{className:`w-7 h-7 rounded bg-[#FFE24C] border-[2px] border-ink-black flex items-center justify-center shadow-[1px_1px_0px_0px_#1E293B]`,children:(0,k.jsx)(_,{className:`w-4 h-4 text-ink-black`})}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`h4`,{className:`font-headline-md font-bold text-xs uppercase text-ink-black m-0`,children:`Princess AI Companion & RPG Settings`}),(0,k.jsx)(`p`,{className:`text-[10px] text-trash-gray font-medium m-0`,children:`Trapped Princess Persona, Study Break Timer & 8-bit RPG Audio`})]})]}),(0,k.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,k.jsx)(`span`,{className:`text-[11px] font-bold text-ink-black font-headline-md uppercase`,children:I.enabled?`Enabled`:`Disabled`}),(0,k.jsx)(`input`,{type:`checkbox`,checked:I.enabled,onChange:e=>L(t=>({...t,enabled:e.target.checked})),className:`w-4 h-4 accent-amber-500 cursor-pointer`})]})]}),(0,k.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[(0,k.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,k.jsx)(`label`,{className:`block text-xs font-bold text-ink-black uppercase tracking-wider font-headline-md`,children:`Companion Name`}),(0,k.jsx)(`input`,{type:`text`,value:I.name,onChange:e=>L(t=>({...t,name:e.target.value})),placeholder:`e.g. Princess Aurelia`,className:`bg-white border-[2px] border-ink-black rounded py-2 px-3 text-ink-black text-xs font-sans font-medium focus:outline-none focus:border-amber-600`})]}),(0,k.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,k.jsxs)(`label`,{className:`block text-xs font-bold text-ink-black uppercase tracking-wider font-headline-md flex items-center gap-1`,children:[(0,k.jsx)(s,{className:`w-3.5 h-3.5 text-amber-700`}),`Study Break Reminder`]}),(0,k.jsxs)(`select`,{value:I.breakIntervalMinutes,onChange:e=>L(t=>({...t,breakIntervalMinutes:Number(e.target.value)})),className:`bg-white border-[2px] border-ink-black rounded py-2 px-3 text-ink-black text-xs font-sans font-medium focus:outline-none focus:border-amber-600 cursor-pointer`,children:[(0,k.jsx)(`option`,{value:25,children:`Every 25 Minutes (Classic Pomodoro)`}),(0,k.jsx)(`option`,{value:45,children:`Every 45 Minutes`}),(0,k.jsx)(`option`,{value:60,children:`Every 60 Minutes`}),(0,k.jsx)(`option`,{value:0,children:`Disabled (No automatic break popups)`})]})]})]}),(0,k.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,k.jsx)(`label`,{className:`block text-xs font-bold text-ink-black uppercase tracking-wider font-headline-md`,children:`Princess Backstory & Persona Prompt`}),(0,k.jsx)(`textarea`,{rows:2,value:I.backstory,onChange:e=>L(t=>({...t,backstory:e.target.value})),placeholder:`Describe her background, tone, and connection to your DSA studies...`,className:`bg-white border-[2px] border-ink-black rounded p-2.5 text-ink-black text-xs font-sans font-medium focus:outline-none focus:border-amber-600 resize-y`})]}),(0,k.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3 pt-1`,children:[(0,k.jsxs)(`label`,{className:`flex items-center gap-2.5 p-2.5 bg-white border border-slate-300 rounded cursor-pointer hover:border-ink-black transition-all`,children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:I.soundEnabled,onChange:e=>{let t=e.target.checked;L(e=>({...e,soundEnabled:t})),w(!t)},className:`w-4 h-4 accent-amber-500 cursor-pointer`}),(0,k.jsxs)(`div`,{className:`text-xs`,children:[(0,k.jsx)(`span`,{className:`font-bold text-ink-black block`,children:`8-bit Sound Effects`}),(0,k.jsx)(`span`,{className:`text-[10px] text-trash-gray`,children:`Typewriter blips, chimes & fanfare`})]})]}),(0,k.jsxs)(`label`,{className:`flex items-center gap-2.5 p-2.5 bg-white border border-slate-300 rounded cursor-pointer hover:border-ink-black transition-all`,children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:I.autoPopupEnabled,onChange:e=>L(t=>({...t,autoPopupEnabled:e.target.checked})),className:`w-4 h-4 accent-amber-500 cursor-pointer`}),(0,k.jsxs)(`div`,{className:`text-xs`,children:[(0,k.jsx)(`span`,{className:`font-bold text-ink-black block`,children:`Spontaneous RPG Popups`}),(0,k.jsx)(`span`,{className:`text-[10px] text-trash-gray`,children:`Speech bubbles for breaks & milestones`})]})]})]}),(0,k.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 pt-2 border-t border-slate-200`,children:[(0,k.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,k.jsxs)(`button`,{type:`button`,onClick:ce,className:`flex items-center gap-1.5 py-2 px-4 border-[2px] border-ink-black bg-[#ffe24c] hover:bg-yellow-300 text-xs font-bold text-ink-black shadow-[2px_2px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none transition-all cursor-pointer rounded uppercase`,children:[(0,k.jsx)(n,{className:`w-3.5 h-3.5`}),`Save Companion Settings`]}),(0,k.jsx)(`button`,{type:`button`,onClick:le,className:`py-2 px-3 border border-slate-300 bg-white hover:bg-slate-50 text-xs font-bold text-slate-700 transition-all cursor-pointer rounded`,children:`Default Persona`})]}),(0,k.jsxs)(`button`,{type:`button`,onClick:ue,className:`flex items-center gap-1 py-1.5 px-3 border border-rose-300 bg-rose-50 hover:bg-rose-100 text-rose-700 text-[11px] font-bold transition-all cursor-pointer rounded`,children:[(0,k.jsx)(f,{className:`w-3 h-3 text-rose-500`}),(0,k.jsxs)(`span`,{children:[`Reset Journey (`,B,`/150 LC)`]})]})]}),R&&(0,k.jsxs)(`div`,{className:`p-2.5 border-[2px] border-ink-black text-xs font-medium rounded flex items-center gap-2 ${R.type===`success`?`bg-emerald-100 border-emerald-600 text-emerald-900`:`bg-sky-100 border-sky-600 text-sky-900`}`,children:[(0,k.jsx)(u,{className:`w-3.5 h-3.5 shrink-0`}),R.text]})]}),(0,k.jsxs)(`div`,{className:`bg-white border-[3px] border-ink-black p-4 shadow-[4px_4px_0px_0px_rgba(30,41,59,1)] flex flex-col gap-2.5`,children:[(0,k.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,k.jsx)(r,{className:`w-3.5 h-3.5 text-[#0ea5e9]`}),(0,k.jsx)(`h4`,{className:`text-xs font-bold uppercase font-headline-md m-0`,children:`Get Free API Keys`})]}),(0,k.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-2 text-[10px]`,children:[(0,k.jsxs)(`a`,{href:`https://console.groq.com/keys`,target:`_blank`,rel:`noopener noreferrer`,className:`p-2.5 border border-slate-200 hover:border-ink-black hover:bg-slate-50 rounded flex flex-col justify-between gap-1 transition-all no-underline text-inherit cursor-pointer`,children:[(0,k.jsxs)(`div`,{className:`flex items-center justify-between font-bold text-ink-black`,children:[(0,k.jsx)(`span`,{children:`Groq Cloud`}),(0,k.jsx)(g,{className:`w-3 h-3 text-slate-400`})]}),(0,k.jsx)(`p`,{className:`m-0 text-trash-gray leading-normal`,children:`Fast inference with generous free rate limits.`})]}),(0,k.jsxs)(`a`,{href:`https://aistudio.google.com/app/apikey`,target:`_blank`,rel:`noopener noreferrer`,className:`p-2.5 border border-slate-200 hover:border-ink-black hover:bg-slate-50 rounded flex flex-col justify-between gap-1 transition-all no-underline text-inherit cursor-pointer`,children:[(0,k.jsxs)(`div`,{className:`flex items-center justify-between font-bold text-ink-black`,children:[(0,k.jsx)(`span`,{children:`Google AI Studio`}),(0,k.jsx)(g,{className:`w-3 h-3 text-slate-400`})]}),(0,k.jsx)(`p`,{className:`m-0 text-trash-gray leading-normal`,children:`Free Gemini Flash API quota.`})]}),(0,k.jsxs)(`a`,{href:`https://openrouter.ai/keys`,target:`_blank`,rel:`noopener noreferrer`,className:`p-2.5 border border-slate-200 hover:border-ink-black hover:bg-slate-50 rounded flex flex-col justify-between gap-1 transition-all no-underline text-inherit cursor-pointer`,children:[(0,k.jsxs)(`div`,{className:`flex items-center justify-between font-bold text-ink-black`,children:[(0,k.jsx)(`span`,{children:`OpenRouter`}),(0,k.jsx)(g,{className:`w-3 h-3 text-slate-400`})]}),(0,k.jsx)(`p`,{className:`m-0 text-trash-gray leading-normal`,children:`Unified API for open-weights models.`})]})]})]})]})}export{j as default};
|
|
|
|
| 1 |
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{$ as t,A as n,E as r,J as i,K as a,Lt as o,O as s,Z as c,at as l,d as u,et as d,ft as f,mt as p,nt as m,o as h,tt as g,x as _,y as v,zt as y}from"./vendor-react-qmUj3JUi.js";import{f as ee,g as b,h as x,m as S,p as C,v as w}from"./index-DYMSjoUb.js";import{a as te,i as ne,n as T,r as E,s as re,t as D}from"./githubSyncService-DQdE4J2L.js";var O=e(y(),1),k=o(),A=[{id:`default`,name:`Default`,desc:`Subject to Availability`},{id:`groq`,name:`Groq`,badge:`Fastest`,desc:`Llama 3.3 & Qwen`,keyPrefix:`gsk_...`,portalUrl:`https://console.groq.com/keys`},{id:`gemini`,name:`Google Gemini`,desc:`Gemini 2.5 / 3.5`,keyPrefix:`AIzaSy...`,portalUrl:`https://aistudio.google.com/app/apikey`},{id:`openrouter`,name:`OpenRouter`,desc:`Multi-Provider`,keyPrefix:`sk-or-v1-...`,portalUrl:`https://openrouter.ai/keys`}];function j(){let[e,o]=(0,O.useState)(()=>localStorage.getItem(`algospaced_custom_ai_provider`)||`default`),[y,j]=(0,O.useState)(()=>localStorage.getItem(`algospaced_custom_api_key`)||localStorage.getItem(`sandbox_gemini_api_key`)||``),[M,N]=(0,O.useState)(!1),[P,F]=(0,O.useState)(null),[I,L]=(0,O.useState)(()=>ee()),[R,z]=(0,O.useState)(null),[B,V]=(0,O.useState)(()=>C().currentFloor),[H,U]=(0,O.useState)(()=>E()),[W,G]=(0,O.useState)(()=>ne()),[K,q]=(0,O.useState)(!1),[J,Y]=(0,O.useState)(null),X=!!(H.token&&(H.username||W?.login)),Z=!!(y.trim()&&e!=="default"),Q=e!=="default"&&!y.trim(),$=A.find(t=>t.id===e),ie=e=>{o(e),localStorage.setItem(`algospaced_custom_ai_provider`,e),F(e==="default"?{type:`info`,text:`Switched to Server Default (Shared Pool).`}:{type:`info`,text:`Switched to ${e.toUpperCase()}.`}),setTimeout(()=>F(null),3e3)},ae=()=>{let t=y.trim();if(!t){F({type:`error`,text:`Please enter an API key for ${e.toUpperCase()}.`}),setTimeout(()=>F(null),3e3);return}localStorage.setItem(`algospaced_custom_api_key`,t),localStorage.setItem(`sandbox_gemini_api_key`,t),localStorage.setItem(`algospaced_custom_ai_provider`,e),F({type:`success`,text:`${e.toUpperCase()} API key saved successfully.`}),setTimeout(()=>F(null),3e3)},oe=()=>{localStorage.removeItem(`algospaced_custom_api_key`),localStorage.removeItem(`sandbox_gemini_api_key`),j(``),F({type:`info`,text:`Cleared custom API key.`}),setTimeout(()=>F(null),3e3)},se=()=>{localStorage.removeItem(`algospaced_custom_api_key`),localStorage.removeItem(`sandbox_gemini_api_key`),localStorage.setItem(`algospaced_custom_ai_provider`,`default`),j(``),o(`default`),F({type:`info`,text:`Reset to Server Default provider.`}),setTimeout(()=>F(null),3e3)},ce=()=>{x(I),z({type:`success`,text:`Princess Companion settings saved!`}),setTimeout(()=>z(null),3e3)},le=()=>{L(b),x(b),z({type:`info`,text:`Reset companion to default settings.`}),setTimeout(()=>z(null),3e3)},ue=()=>{if(window.confirm(`Are you sure you want to reset your Spire Journey progress back to 0 problems?`)){let e=S();V(e.currentFloor),z({type:`info`,text:`Spire journey progress reset to 0 problems.`}),setTimeout(()=>z(null),3e3)}},de=async()=>{q(!0),Y(null);try{let{token:e,user:t}=await T();G(t);let n=E();U(n);try{await te(e,n.repoName,n.isPrivate)}catch{}Y({type:`success`,text:`Connected to GitHub as @${t.login}!`}),setTimeout(()=>Y(null),4e3)}catch(e){Y({type:`error`,text:e.message||`GitHub connection failed.`}),setTimeout(()=>Y(null),5e3)}finally{q(!1)}},fe=()=>{D(),U(E()),G(null),Y({type:`info`,text:`Disconnected from GitHub.`}),setTimeout(()=>Y(null),3e3)},pe=e=>{re({autoCommit:e}),U(t=>({...t,autoCommit:e})),Y({type:`info`,text:e?`Auto-commit enabled for review submissions.`:`Auto-commit disabled.`}),setTimeout(()=>Y(null),3e3)};return(0,k.jsxs)(`div`,{className:`w-full h-full bg-[#fdf8e1] p-5 sm:p-6 flex flex-col gap-4 select-none font-sans text-ink-black overflow-y-auto custom-scrollbar`,children:[(0,k.jsxs)(`div`,{className:`flex flex-col gap-0.5 border-b-[3px] border-ink-black pb-2.5`,children:[(0,k.jsxs)(`h3`,{className:`font-headline-md font-bold text-sm m-0 flex items-center gap-2 tracking-wide`,children:[(0,k.jsx)(a,{className:`w-4 h-4 text-ink-black`}),`API & AI Configuration`]}),(0,k.jsx)(`p`,{className:`text-[11px] text-trash-gray font-medium m-0`,children:`Configure your AI model provider..`})]}),(0,k.jsx)(`div`,{className:`px-4 py-3 border-[3px] border-ink-black shadow-[3px_3px_0px_0px_rgba(30,41,59,1)] transition-all ${Z?`bg-emerald-50`:Q?`bg-rose-50`:`bg-amber-50/70`}`,children:(0,k.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,k.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[Z?(0,k.jsx)(h,{className:`w-4 h-4 text-emerald-600 shrink-0`}):Q?(0,k.jsx)(p,{className:`w-4 h-4 text-rose-600 shrink-0`}):(0,k.jsx)(m,{className:`w-4 h-4 text-amber-600 shrink-0`}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`div`,{className:`text-xs font-bold font-headline-md text-ink-black flex items-center gap-1.5`,children:(0,k.jsxs)(`span`,{children:[`Active:`,` `,Z?`${e.toUpperCase()} (Custom Key)`:Q?`${e.toUpperCase()} (Key Required)`:`Default`]})}),(0,k.jsx)(`div`,{className:`text-[10px] text-trash-gray font-medium`,children:Z?`Requests are routed directly through your personal API key.`:Q?`Enter your API key below to activate this provider.`:`Using basic, free built-in developer keys with auto-failover.`})]})]}),(0,k.jsx)(`span`,{className:`px-2 py-0.5 text-[9px] font-bold font-arcade uppercase border-2 border-ink-black shrink-0 ${Z?`bg-emerald-300 text-emerald-950`:Q?`bg-rose-300 text-rose-950`:`bg-amber-200 text-amber-950`}`,children:Z?`ACTIVE`:Q?`NEEDS KEY`:`LIMITED`})]})}),(0,k.jsxs)(`div`,{className:`bg-white border-[3px] border-ink-black p-4 sm:p-5 shadow-[4px_4px_0px_0px_rgba(30,41,59,1)] flex flex-col gap-4`,children:[(0,k.jsxs)(`div`,{children:[(0,k.jsxs)(`label`,{className:`block text-xs font-bold text-ink-black uppercase tracking-wider mb-2 font-headline-md flex items-center gap-1.5`,children:[(0,k.jsx)(m,{className:`w-3.5 h-3.5 text-ink-black`}),`Select Provider`]}),(0,k.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-4 gap-2`,children:A.map(t=>{let n=e===t.id;return(0,k.jsxs)(`button`,{type:`button`,onClick:()=>ie(t.id),className:`p-2.5 border-[2px] text-left transition-all cursor-pointer flex flex-col justify-between rounded ${n?`border-ink-black bg-[#ffe24c] shadow-[2px_2px_0px_0px_#1E293B] font-bold`:`border-slate-300 bg-slate-50 hover:bg-slate-100 text-slate-700`}`,children:[(0,k.jsxs)(`div`,{className:`flex items-center justify-between w-full`,children:[(0,k.jsx)(`span`,{className:`text-xs font-bold font-headline-md`,children:t.name}),t.badge&&(0,k.jsx)(`span`,{className:`text-[8px] font-bold uppercase px-1 py-0.2 bg-orange-100 text-orange-700 rounded border border-orange-300`,children:t.badge})]}),(0,k.jsx)(`span`,{className:`text-[9px] mt-1 text-slate-600 leading-tight block`,children:t.desc})]},t.id)})})]}),e==="default"?(0,k.jsxs)(`div`,{className:`p-3.5 bg-slate-50 border border-slate-200 rounded flex items-start gap-3`,children:[(0,k.jsx)(u,{className:`w-4 h-4 text-amber-500 shrink-0 mt-0.5`}),(0,k.jsxs)(`div`,{className:`flex flex-col gap-1 text-xs text-slate-700`,children:[(0,k.jsxs)(`span`,{className:`font-bold text-ink-black`,children:[`Shared Quotas (`,(0,k.jsx)(`i`,{children:`limited`}),`)`]}),(0,k.jsx)(`p`,{className:`text-[11px] text-trash-gray m-0 leading-relaxed`,children:`Powered by shared, basic developer keys. Because limits are shared with everyone, requests may fail. Use your own provider keys above for stable performance.`})]})]}):(0,k.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,k.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,k.jsxs)(`label`,{className:`block text-xs font-bold text-ink-black uppercase tracking-wider font-headline-md flex items-center gap-1.5`,children:[(0,k.jsx)(a,{className:`w-3.5 h-3.5 text-ink-black`}),$?.name,` API Key`]}),$?.portalUrl&&(0,k.jsxs)(`a`,{href:$.portalUrl,target:`_blank`,rel:`noopener noreferrer`,className:`text-[10px] text-sky-600 hover:text-sky-800 font-medium flex items-center gap-1 no-underline`,children:[(0,k.jsx)(`span`,{children:`Get API Key`}),(0,k.jsx)(g,{className:`w-3 h-3`})]})]}),(0,k.jsxs)(`div`,{className:`relative`,children:[(0,k.jsx)(`input`,{type:M?`text`:`password`,value:y,onChange:e=>j(e.target.value),placeholder:`Enter ${$?.keyPrefix||`API Key`}`,className:`w-full bg-white border-[2px] border-ink-black rounded py-2 pl-3 pr-9 text-ink-black placeholder-slate-400 focus:outline-none focus:border-sky-600 text-xs font-code-mono`}),(0,k.jsx)(`button`,{type:`button`,onClick:()=>N(!M),className:`absolute right-2.5 top-1/2 -translate-y-1/2 text-trash-gray hover:text-ink-black cursor-pointer bg-transparent border-0 outline-none p-1`,title:M?`Hide API key`:`Show API key`,children:M?(0,k.jsx)(d,{className:`w-3.5 h-3.5`}):(0,k.jsx)(t,{className:`w-3.5 h-3.5`})})]}),(0,k.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-trash-gray font-medium`,children:[(0,k.jsx)(_,{className:`w-3.5 h-3.5 text-emerald-600 shrink-0`}),(0,k.jsx)(`span`,{children:`Stored locally in your browser. Sent directly via request headers.`})]}),(0,k.jsxs)(`div`,{className:`flex gap-2 pt-1`,children:[(0,k.jsxs)(`button`,{onClick:ae,className:`flex-1 flex items-center justify-center gap-1.5 py-2 border-[2px] border-ink-black bg-[#ffe24c] hover:bg-yellow-300 text-xs font-bold text-ink-black shadow-[2px_2px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none transition-all cursor-pointer rounded uppercase`,children:[(0,k.jsx)(r,{className:`w-3.5 h-3.5`}),`Save Key`]}),y&&(0,k.jsx)(`button`,{onClick:oe,className:`px-3 py-2 border-[2px] border-slate-300 bg-white hover:bg-slate-50 text-xs font-bold text-slate-700 hover:text-rose-600 shadow-[2px_2px_0px_0px_rgba(0,0,0,0.05)] active:translate-y-0.5 active:shadow-none transition-all cursor-pointer rounded uppercase`,children:`Clear Key`})]})]}),P&&(0,k.jsxs)(`div`,{className:`p-2.5 border-[2px] border-ink-black text-xs font-medium rounded flex items-center gap-2 ${P.type===`success`?`bg-emerald-100 border-emerald-600 text-emerald-900`:P.type===`error`?`bg-rose-100 border-rose-600 text-rose-900`:`bg-sky-100 border-sky-600 text-sky-900`}`,children:[P.type===`success`?(0,k.jsx)(f,{className:`w-3.5 h-3.5 shrink-0`}):P.type===`error`?(0,k.jsx)(p,{className:`w-3.5 h-3.5 shrink-0`}):(0,k.jsx)(i,{className:`w-3.5 h-3.5 shrink-0`}),P.text]}),e!=="default"&&(0,k.jsx)(`div`,{className:`pt-2 border-t border-slate-200 flex justify-end`,children:(0,k.jsxs)(`button`,{onClick:se,className:`flex items-center gap-1.5 py-1.5 px-3 border border-slate-300 bg-slate-50 hover:bg-slate-100 text-[11px] font-bold text-slate-600 hover:text-ink-black transition-all cursor-pointer rounded`,children:[(0,k.jsx)(s,{className:`w-3 h-3 text-slate-500`}),`Reset to Server Default`]})})]}),(0,k.jsxs)(`div`,{className:`bg-white border-[3px] border-ink-black p-4 sm:p-5 shadow-[4px_4px_0px_0px_rgba(30,41,59,1)] flex flex-col gap-4`,children:[(0,k.jsxs)(`div`,{className:`flex items-center justify-between border-b-[2px] border-ink-black pb-3`,children:[(0,k.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,k.jsx)(`div`,{className:`w-8 h-8 rounded bg-[#24292e] border-[2px] border-ink-black flex items-center justify-center text-white shadow-[1px_1px_0px_0px_#1E293B]`,children:(0,k.jsx)(c,{className:`w-4 h-4 text-white`})}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`h4`,{className:`font-headline-md font-bold text-xs uppercase text-ink-black m-0 flex items-center gap-2`,children:`GitHub Solutions Sync & Auto-Commit`}),(0,k.jsx)(`p`,{className:`text-[10px] text-trash-gray font-medium m-0`,children:`Sync solutions to personal GitHub repository and commit automatically on submission`})]})]}),(0,k.jsx)(`span`,{className:`px-2 py-0.5 text-[9px] font-bold font-arcade uppercase border-2 border-ink-black shrink-0 ${X?`bg-emerald-300 text-emerald-950`:`bg-slate-200 text-slate-800`}`,children:X?`CONNECTED`:`DISCONNECTED`})]}),X?(0,k.jsxs)(`div`,{className:`space-y-3`,children:[(0,k.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-2 p-3 bg-slate-50 border border-slate-200 rounded`,children:[(0,k.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[W?.avatar_url&&(0,k.jsx)(`img`,{src:W.avatar_url,alt:W.login,className:`w-7 h-7 rounded-full border border-ink-black`}),(0,k.jsxs)(`div`,{children:[(0,k.jsxs)(`span`,{className:`text-xs font-bold text-ink-black`,children:[`@`,W?.login||H.username]}),(0,k.jsxs)(`span`,{className:`text-[11px] text-slate-600 font-mono block`,children:[H.username,`/`,H.repoName,` (`,H.branch,`)`]})]})]}),(0,k.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,k.jsxs)(`a`,{href:`https://github.com/${H.username}/${H.repoName}`,target:`_blank`,rel:`noopener noreferrer`,className:`px-2.5 py-1 text-[11px] font-bold bg-white hover:bg-slate-100 text-ink-black border border-slate-300 rounded no-underline flex items-center gap-1 cursor-pointer`,children:[(0,k.jsx)(g,{className:`w-3 h-3`}),(0,k.jsx)(`span`,{children:`View Repo`})]}),(0,k.jsx)(`button`,{type:`button`,onClick:fe,className:`px-2.5 py-1 text-[11px] font-bold bg-white hover:bg-rose-50 text-rose-700 border border-rose-300 rounded cursor-pointer`,children:`Disconnect`})]})]}),(0,k.jsxs)(`label`,{className:`flex items-center gap-2.5 p-2.5 bg-emerald-50/50 border border-emerald-300 rounded cursor-pointer`,children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:H.autoCommit,onChange:e=>pe(e.target.checked),className:`w-4 h-4 accent-emerald-600 cursor-pointer`}),(0,k.jsxs)(`div`,{className:`text-xs`,children:[(0,k.jsx)(`span`,{className:`font-bold text-ink-black block`,children:`Auto-commit on every submission`}),(0,k.jsxs)(`span`,{className:`text-[10px] text-trash-gray`,children:[`Automatically pushes your code to `,H.repoName,` whenever you grade a review card.`]})]})]})]}):(0,k.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start sm:items-center justify-between gap-3 p-3.5 bg-slate-50 border border-slate-200 rounded`,children:[(0,k.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,k.jsx)(`span`,{className:`text-xs font-bold text-ink-black block`,children:`Connect your GitHub Account (1-Click OAuth)`}),(0,k.jsx)(`p`,{className:`text-[11px] text-trash-gray m-0`,children:`Grant repository access to automatically sync your DSA problem solutions as you study.`})]}),(0,k.jsx)(`button`,{type:`button`,onClick:de,disabled:K,className:`px-4 py-2 bg-[#24292e] hover:bg-black text-white text-xs font-bold uppercase rounded border-2 border-ink-black shadow-[2px_2px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none flex items-center gap-2 shrink-0 cursor-pointer disabled:opacity-50`,children:K?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(n,{className:`w-3.5 h-3.5 animate-spin`}),(0,k.jsx)(`span`,{children:`CONNECTING...`})]}):(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(c,{className:`w-3.5 h-3.5 text-yellow-300`}),(0,k.jsx)(`span`,{children:`CONNECT GITHUB`})]})})]}),J&&(0,k.jsxs)(`div`,{className:`p-2.5 border-[2px] border-ink-black text-xs font-medium rounded flex items-center gap-2 ${J.type===`success`?`bg-emerald-100 border-emerald-600 text-emerald-900`:J.type===`error`?`bg-rose-100 border-rose-600 text-rose-900`:`bg-sky-100 border-sky-600 text-sky-900`}`,children:[J.type===`success`?(0,k.jsx)(f,{className:`w-3.5 h-3.5 shrink-0`}):J.type===`error`?(0,k.jsx)(p,{className:`w-3.5 h-3.5 shrink-0`}):(0,k.jsx)(i,{className:`w-3.5 h-3.5 shrink-0`}),J.text]})]}),(0,k.jsxs)(`div`,{className:`bg-[#FFFDF0] border-[3px] border-ink-black p-4 sm:p-5 shadow-[4px_4px_0px_0px_rgba(30,41,59,1)] flex flex-col gap-4`,children:[(0,k.jsxs)(`div`,{className:`flex items-center justify-between border-b-[2px] border-ink-black pb-3`,children:[(0,k.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,k.jsx)(`div`,{className:`w-7 h-7 rounded bg-[#FFE24C] border-[2px] border-ink-black flex items-center justify-center shadow-[1px_1px_0px_0px_#1E293B]`,children:(0,k.jsx)(v,{className:`w-4 h-4 text-ink-black`})}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`h4`,{className:`font-headline-md font-bold text-xs uppercase text-ink-black m-0`,children:`Princess AI Companion & RPG Settings`}),(0,k.jsx)(`p`,{className:`text-[10px] text-trash-gray font-medium m-0`,children:`Trapped Princess Persona, Study Break Timer & 8-bit RPG Audio`})]})]}),(0,k.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,k.jsx)(`span`,{className:`text-[11px] font-bold text-ink-black font-headline-md uppercase`,children:I.enabled?`Enabled`:`Disabled`}),(0,k.jsx)(`input`,{type:`checkbox`,checked:I.enabled,onChange:e=>L(t=>({...t,enabled:e.target.checked})),className:`w-4 h-4 accent-amber-500 cursor-pointer`})]})]}),(0,k.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[(0,k.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,k.jsx)(`label`,{className:`block text-xs font-bold text-ink-black uppercase tracking-wider font-headline-md`,children:`Companion Name`}),(0,k.jsx)(`input`,{type:`text`,value:I.name,onChange:e=>L(t=>({...t,name:e.target.value})),placeholder:`e.g. Princess Aurelia`,className:`bg-white border-[2px] border-ink-black rounded py-2 px-3 text-ink-black text-xs font-sans font-medium focus:outline-none focus:border-amber-600`})]}),(0,k.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,k.jsxs)(`label`,{className:`block text-xs font-bold text-ink-black uppercase tracking-wider font-headline-md flex items-center gap-1`,children:[(0,k.jsx)(l,{className:`w-3.5 h-3.5 text-amber-700`}),`Study Break Reminder`]}),(0,k.jsxs)(`select`,{value:I.breakIntervalMinutes,onChange:e=>L(t=>({...t,breakIntervalMinutes:Number(e.target.value)})),className:`bg-white border-[2px] border-ink-black rounded py-2 px-3 text-ink-black text-xs font-sans font-medium focus:outline-none focus:border-amber-600 cursor-pointer`,children:[(0,k.jsx)(`option`,{value:25,children:`Every 25 Minutes (Classic Pomodoro)`}),(0,k.jsx)(`option`,{value:45,children:`Every 45 Minutes`}),(0,k.jsx)(`option`,{value:60,children:`Every 60 Minutes`}),(0,k.jsx)(`option`,{value:0,children:`Disabled (No automatic break popups)`})]})]})]}),(0,k.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,k.jsx)(`label`,{className:`block text-xs font-bold text-ink-black uppercase tracking-wider font-headline-md`,children:`Princess Backstory & Persona Prompt`}),(0,k.jsx)(`textarea`,{rows:2,value:I.backstory,onChange:e=>L(t=>({...t,backstory:e.target.value})),placeholder:`Describe her background, tone, and connection to your DSA studies...`,className:`bg-white border-[2px] border-ink-black rounded p-2.5 text-ink-black text-xs font-sans font-medium focus:outline-none focus:border-amber-600 resize-y`})]}),(0,k.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3 pt-1`,children:[(0,k.jsxs)(`label`,{className:`flex items-center gap-2.5 p-2.5 bg-white border border-slate-300 rounded cursor-pointer hover:border-ink-black transition-all`,children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:I.soundEnabled,onChange:e=>{let t=e.target.checked;L(e=>({...e,soundEnabled:t})),w(!t)},className:`w-4 h-4 accent-amber-500 cursor-pointer`}),(0,k.jsxs)(`div`,{className:`text-xs`,children:[(0,k.jsx)(`span`,{className:`font-bold text-ink-black block`,children:`8-bit Sound Effects`}),(0,k.jsx)(`span`,{className:`text-[10px] text-trash-gray`,children:`Audio chimes & fanfare`})]})]}),(0,k.jsxs)(`label`,{className:`flex items-center gap-2.5 p-2.5 bg-white border border-slate-300 rounded cursor-pointer hover:border-ink-black transition-all`,children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:I.autoPopupEnabled,onChange:e=>L(t=>({...t,autoPopupEnabled:e.target.checked})),className:`w-4 h-4 accent-amber-500 cursor-pointer`}),(0,k.jsxs)(`div`,{className:`text-xs`,children:[(0,k.jsx)(`span`,{className:`font-bold text-ink-black block`,children:`Spontaneous RPG Popups`}),(0,k.jsx)(`span`,{className:`text-[10px] text-trash-gray`,children:`Speech bubbles for breaks & milestones`})]})]})]}),(0,k.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 pt-2 border-t border-slate-200`,children:[(0,k.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,k.jsxs)(`button`,{type:`button`,onClick:ce,className:`flex items-center gap-1.5 py-2 px-4 border-[2px] border-ink-black bg-[#ffe24c] hover:bg-yellow-300 text-xs font-bold text-ink-black shadow-[2px_2px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none transition-all cursor-pointer rounded uppercase`,children:[(0,k.jsx)(r,{className:`w-3.5 h-3.5`}),`Save Companion Settings`]}),(0,k.jsx)(`button`,{type:`button`,onClick:le,className:`py-2 px-3 border border-slate-300 bg-white hover:bg-slate-50 text-xs font-bold text-slate-700 transition-all cursor-pointer rounded`,children:`Default Persona`})]}),(0,k.jsxs)(`button`,{type:`button`,onClick:ue,className:`flex items-center gap-1 py-1.5 px-3 border border-rose-300 bg-rose-50 hover:bg-rose-100 text-rose-700 text-[11px] font-bold transition-all cursor-pointer rounded`,children:[(0,k.jsx)(s,{className:`w-3 h-3 text-rose-500`}),(0,k.jsxs)(`span`,{children:[`Reset Journey (`,B,`/150 LC)`]})]})]}),R&&(0,k.jsxs)(`div`,{className:`p-2.5 border-[2px] border-ink-black text-xs font-medium rounded flex items-center gap-2 ${R.type===`success`?`bg-emerald-100 border-emerald-600 text-emerald-900`:`bg-sky-100 border-sky-600 text-sky-900`}`,children:[(0,k.jsx)(f,{className:`w-3.5 h-3.5 shrink-0`}),R.text]})]}),(0,k.jsxs)(`div`,{className:`bg-white border-[3px] border-ink-black p-4 shadow-[4px_4px_0px_0px_rgba(30,41,59,1)] flex flex-col gap-2.5`,children:[(0,k.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,k.jsx)(i,{className:`w-3.5 h-3.5 text-[#0ea5e9]`}),(0,k.jsx)(`h4`,{className:`text-xs font-bold uppercase font-headline-md m-0`,children:`Get Free API Keys`})]}),(0,k.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-2 text-[10px]`,children:[(0,k.jsxs)(`a`,{href:`https://console.groq.com/keys`,target:`_blank`,rel:`noopener noreferrer`,className:`p-2.5 border border-slate-200 hover:border-ink-black hover:bg-slate-50 rounded flex flex-col justify-between gap-1 transition-all no-underline text-inherit cursor-pointer`,children:[(0,k.jsxs)(`div`,{className:`flex items-center justify-between font-bold text-ink-black`,children:[(0,k.jsx)(`span`,{children:`Groq Cloud`}),(0,k.jsx)(g,{className:`w-3 h-3 text-slate-400`})]}),(0,k.jsx)(`p`,{className:`m-0 text-trash-gray leading-normal`,children:`Fast inference with generous free rate limits.`})]}),(0,k.jsxs)(`a`,{href:`https://aistudio.google.com/app/apikey`,target:`_blank`,rel:`noopener noreferrer`,className:`p-2.5 border border-slate-200 hover:border-ink-black hover:bg-slate-50 rounded flex flex-col justify-between gap-1 transition-all no-underline text-inherit cursor-pointer`,children:[(0,k.jsxs)(`div`,{className:`flex items-center justify-between font-bold text-ink-black`,children:[(0,k.jsx)(`span`,{children:`Google AI Studio`}),(0,k.jsx)(g,{className:`w-3 h-3 text-slate-400`})]}),(0,k.jsx)(`p`,{className:`m-0 text-trash-gray leading-normal`,children:`Free Gemini Flash API quota.`})]}),(0,k.jsxs)(`a`,{href:`https://openrouter.ai/keys`,target:`_blank`,rel:`noopener noreferrer`,className:`p-2.5 border border-slate-200 hover:border-ink-black hover:bg-slate-50 rounded flex flex-col justify-between gap-1 transition-all no-underline text-inherit cursor-pointer`,children:[(0,k.jsxs)(`div`,{className:`flex items-center justify-between font-bold text-ink-black`,children:[(0,k.jsx)(`span`,{children:`OpenRouter`}),(0,k.jsx)(g,{className:`w-3 h-3 text-slate-400`})]}),(0,k.jsx)(`p`,{className:`m-0 text-trash-gray leading-normal`,children:`Unified API for open-weights models.`})]})]})]})]})}export{j as default};
|
algospaced-ui/dist/assets/{TerminalEmulator-CUwPFl2P.js → TerminalEmulator-DUo8J_0j.js}
RENAMED
|
@@ -1 +1 @@
|
|
| 1 |
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Lt as t,zt as n}from"./vendor-react-
|
|
|
|
| 1 |
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Lt as t,zt as n}from"./vendor-react-qmUj3JUi.js";import{r}from"./firebaseClient-G7klkuBb.js";import{n as i}from"./index-DYMSjoUb.js";var a=e(n(),1),o=t();function s(e,t){if(e.length===0||t.length===0)return[`Empty result set.`];let n={};e.forEach(e=>{n[e]=e.length}),t.forEach(t=>{e.forEach(e=>{let r=t[e]!==null&&t[e]!==void 0?String(t[e]):`NULL`;r.length>(n[e]||0)&&(n[e]=r.length)})});let r=`+`+e.map(e=>`-`.repeat(n[e]+2)).join(`+`)+`+`,i=[r,`|`+e.map(e=>` ${e.padEnd(n[e])} `).join(`|`)+`|`,r];return t.forEach(t=>{let r=`|`+e.map(e=>` ${(t[e]!==null&&t[e]!==void 0?String(t[e]):`NULL`).padEnd(n[e])} `).join(`|`)+`|`;i.push(r)}),i.push(r),i}function c({onOpenWindow:e,onClose:t}){let[n,c]=(0,a.useState)([`AlgoSpaced OS [Version 1.0.24-beta]`,`(c) Retro Arcade Systems. All rights reserved.`,``,`Type "help" for a list of available commands.`,``]),[l,u]=(0,a.useState)(``),d=(0,a.useRef)(null);(0,a.useEffect)(()=>{d.current&&(d.current.scrollTop=d.current.scrollHeight)},[n]);let f=e=>{let t=e.trim(),n=/[^\s"']+|"([^"]*)"|'([^']*)'/g,r=[],i;for(;(i=n.exec(t))!==null;)r.push(i[1]||i[2]||i[0]);return{command:r[0]?.toLowerCase()||``,args:r.slice(1)}},p=async n=>{let a=n.trim();if(a===``){c(e=>[...e,`$`]);return}let{command:o,args:l}=f(a),u=[`$ ${a}`];switch(o){case`help`:u.push(`Available commands:`,` help - Display this documentation`,` ps - Inspect OS process table (PIDs & task states)`,` streak - Retrieve your active Leitner combo streak metrics`,` sync - Run google drive file import sync`,` reviews - Fetch Leetcode numbers due for daily review`,` python play - Open Daily Python Challenge window`,` sql play - Open Interactive SQL Playground window`,` db init - Initialize SQL session and open playground window`,` db status - Check active SQL session objectives`,` db query [Q] - Execute query and format results inside CLI`,` open - Open window (usage: open queue | journey | system | python | db)`,` clear - Clear terminal buffer`,` exit - Close the terminal shell`);break;case`ps`:case`top`:{let e=Object.values(i.getState().processes);if(e.length===0)u.push(`No background processes currently in table.`);else{u.push(`AlgoSpaced OS Process Table:`);let t=s([`PID`,`APP`,`STATUS`,`NAME`],e.map(e=>({PID:e.pid.substring(0,16),APP:e.appId,STATUS:e.status.toUpperCase(),NAME:e.title.substring(0,24)})));u.push(...t)}break}case`clear`:c([]);return;case`exit`:u.push(`Closing terminal session...`),setTimeout(()=>{t()},500);break;case`open`:{let t=l[0]?.toLowerCase();t===`queue`||t===`daily`||t===`reviews`?(e(`queue`),u.push(`Launching Daily Queue window...`)):t===`journey`||t===`path`||t===`map`?(e(`journey`),u.push(`Launching Journey Path window...`)):t===`system`||t===`computer`||t===`sys`?(e(`computer`),u.push(`Launching System Information window...`)):t===`python`||t===`challenge`?(e(`python`),u.push(`Launching Daily Python Challenge window...`)):t===`db`||t===`mysql`||t===`sql`?(e(`mysql`),u.push(`Launching MySQL Playground window...`)):u.push(`Usage: open [queue | journey | system | python | db]`);break}case`streak`:u.push(`Connecting to streak.sys database...`);try{let{data:{session:e}}=await r.auth.getSession();if(!e){u.push(`Error: Unauthenticated session`);break}let t=await fetch(`/api/streak`,{headers:{Authorization:`Bearer ${e.access_token}`}});if(t.ok){let e=await t.json();u.push(`Database Response:`,` Active Streak: ${e.current_streak} days`,` Max Combo: ${e.longest_streak} days`,` Last Activity: ${e.last_active_date?new Date(e.last_active_date).toLocaleDateString():`N/A`}`)}else u.push(`Error: Failed to query database endpoint`)}catch{u.push(`Error: Connection timed out`)}break;case`sync`:u.push(`Initializing Google Drive synchronization sync.exe...`);try{let{data:{session:e}}=await r.auth.getSession();if(!e){u.push(`Error: Unauthenticated session`);break}let t=await fetch(`/api/sync`,{method:`POST`,headers:{Authorization:`Bearer ${e.access_token}`}});if(t.ok){let e=await t.json();u.push(`Sync Result: ${e.message}`)}else u.push(`Error: Sync command failed at backend host`)}catch{u.push(`Error: Cloud host unreachable`)}break;case`reviews`:u.push(`Querying leitner_cards partition...`);try{let{data:{session:e}}=await r.auth.getSession();if(!e){u.push(`Error: Unauthenticated session`);break}let t=await fetch(`/api/reviews/due`,{headers:{Authorization:`Bearer ${e.access_token}`}});if(t.ok){let e=await t.json();e.length===0?u.push(`Queue status: CLEAR! 0 cards due.`):u.push(`Queue status: ${e.length} card(s) due:`,...e.map(e=>` - LeetCode ${e.problems?.problem_number??`?`}: ${e.problems?.name??`Unknown`} (Box ${e.box_level??1})`))}else u.push(`Error: Failed to fetch due items`)}catch{u.push(`Error: Database connection lost`)}break;case`python`:l[0]?.toLowerCase()===`play`?(u.push(`Launching Daily Python Challenge window...`),e(`python`)):u.push(`Usage: python play`);break;case`sql`:case`mysql`:case`db`:{let t=l[0]?.toLowerCase();if(t===`play`)u.push(`Launching MySQL Playground window...`),e(`mysql`);else if(t===`init`){u.push(`Initializing MySQL Playground and launching window...`),e(`mysql`);try{let{data:{session:e}}=await r.auth.getSession();if(!e){u.push(`Error: Unauthenticated session`);break}let t=await fetch(`/api/challenges/mysql/init?refresh=true`,{method:`POST`,headers:{Authorization:`Bearer ${e.access_token}`}});if(t.ok){let e=await t.json();u.push(`Database Session Created: "${e.title}"`,`Objective: ${e.objective}`)}else u.push(`Error: Failed to initialize DB session on backend host.`)}catch{u.push(`Error: Server connection lost.`)}}else if(t===`status`){u.push(`Fetching SQL playground status...`),e(`mysql`);try{let{data:{session:e}}=await r.auth.getSession();if(!e){u.push(`Error: Unauthenticated session`);break}let t=await fetch(`/api/challenges/mysql/status`,{headers:{Authorization:`Bearer ${e.access_token}`}});if(t.ok){let e=await t.json();e.active?u.push(`Active SQL Challenge: "${e.title}"`,`Objective: ${e.objective}`,`Status: ${e.completed?`COMPLETED (Done)`:`IN PROGRESS`}`):u.push(e.message)}else u.push(`Error: Failed to fetch DB status.`)}catch{u.push(`Error: Server timed out.`)}}else if(t===`query`){let t=a.toLowerCase().indexOf(`query`),n=t===-1?``:a.substring(t+5).trim().replace(/^["']|["']$/g,``);if(!n){u.push(`Usage: db query [SQL Statement] - Remember to wrap query in double quotes.`);break}u.push(`Running query: ${n}`),e(`mysql`);try{let{data:{session:e}}=await r.auth.getSession();if(!e){u.push(`Error: Unauthenticated session`);break}let t=await fetch(`/api/challenges/mysql/query`,{method:`POST`,headers:{"Content-Type":`application/json`,Authorization:`Bearer ${e.access_token}`},body:JSON.stringify({query:n})});if(t.ok){let e=await t.json();e.success?(u.push(`Query OK. Affected ${e.rows_affected} rows.`,...s(e.columns,e.rows)),e.is_correct&&u.push(`OBJECTIVE ACHIEVED! Congratulations.`)):u.push(`SQL Error: ${e.error}`)}else u.push(`Error: SQL execution failed.`)}catch{u.push(`Error: Database server unreachable.`)}}else u.push(`Usage: sql play | db init | db status | db query "SELECT..."`);break}default:u.push(`Command not recognized: "${o}". Type "help" for a list of available actions.`)}c(e=>[...e,...u,``])};return(0,o.jsxs)(`div`,{className:`w-full h-full bg-[#1E293B] text-[#4ADE80] font-code-mono p-4 flex flex-col overflow-hidden text-xs md:text-sm select-text`,children:[(0,o.jsx)(`div`,{ref:d,className:`flex-1 overflow-y-auto mb-2 custom-scrollbar space-y-1`,children:n.map((e,t)=>(0,o.jsx)(`div`,{className:`whitespace-pre-wrap leading-relaxed min-h-[1.2em]`,children:e},t))}),(0,o.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),p(l),u(``)},className:`flex items-center gap-1.5 border-t border-slate-700 pt-2 shrink-0 select-none`,children:[(0,o.jsx)(`span`,{className:`font-bold text-[#ffcc00]`,children:`$`}),(0,o.jsx)(`input`,{type:`text`,value:l,onChange:e=>u(e.target.value),className:`flex-1 bg-transparent text-[#4ADE80] outline-none border-none p-0 focus:ring-0 font-code-mono text-xs md:text-sm`,autoFocus:!0,placeholder:`Type command...`})]})]})}export{c as default};
|
algospaced-ui/dist/assets/{index-DttZMwvA.js → index-DYMSjoUb.js}
RENAMED
|
The diff for this file is too large to render.
See raw diff
|
|
|
algospaced-ui/dist/assets/index-Di-5TpeG.css
DELETED
|
The diff for this file is too large to render.
See raw diff
|
|
|
algospaced-ui/dist/assets/index-supjX07i.css
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
algospaced-ui/dist/assets/{vendor-react-yvPwY2Sj.js → vendor-react-qmUj3JUi.js}
RENAMED
|
The diff for this file is too large to render.
See raw diff
|
|
|
algospaced-ui/dist/index.html
CHANGED
|
@@ -1,59 +1,59 @@
|
|
| 1 |
-
<!doctype html>
|
| 2 |
-
<html lang="en">
|
| 3 |
-
|
| 4 |
-
<head>
|
| 5 |
-
<meta charset="UTF-8" />
|
| 6 |
-
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
| 7 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 8 |
-
<meta name="description" content="AlgoSpaced is a gamified spaced repetition and active recall web application for mastering Data Structures and Algorithms with AI review, code sandbox, and retro arcade aesthetic." />
|
| 9 |
-
<meta
|
| 10 |
-
http-equiv="Content-Security-Policy"
|
| 11 |
-
content="default-src 'self'; script-src 'self' https://apis.google.com https://*.firebaseapp.com https://www.gstatic.com https://*.gstatic.com https://cdn.jsdelivr.net; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com https://cdn.jsdelivr.net; font-src 'self' data: https://fonts.gstatic.com https://*.gstatic.com; img-src 'self' data: blob: https://*.googleusercontent.com https://images.unsplash.com https://avatars.githubusercontent.com https://raw.githubusercontent.com https://github.com https://*.firebasestorage.app https://firebasestorage.googleapis.com https://cdn.jsdelivr.net https://fastapi.tiangolo.com; connect-src 'self' http://localhost:* http://127.0.0.1:* ws://localhost:* ws://127.0.0.1:* wss: https://*.googleapis.com https://*.firebaseio.com https://*.firebaseapp.com https://*.firebasestorage.app https://firebasestorage.googleapis.com https://accounts.google.com https://generativelanguage.googleapis.com https://api.groq.com https://openrouter.ai https://api.github.com https://*.hf.space https://hf.space; frame-src 'self' https://accounts.google.com https://*.firebaseapp.com https://*.firebase.com https://*.google.com https://apis.google.com; worker-src 'self' blob:; media-src 'self' data: blob:; object-src 'none'; base-uri 'self';"
|
| 12 |
-
/>
|
| 13 |
-
<title>AlgoSpaced (Beta) - DSA Review</title>
|
| 14 |
-
|
| 15 |
-
<!-- External critical loader styles (eliminates inline styles for strict CSP compliance) -->
|
| 16 |
-
<link rel="stylesheet" href="/loader.css" />
|
| 17 |
-
|
| 18 |
-
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
| 19 |
-
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
| 20 |
-
<link
|
| 21 |
-
rel="stylesheet"
|
| 22 |
-
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:wght,FILL@100..700,0..1&family=Bricolage+Grotesque:opsz,wght@12..96,700;12..96,800&family=Be+Vietnam+Pro:wght@500;700&family=Courier+Prime:wght@400;700&family=Press+Start+2P&family=Cinzel:wght@500;700;900&family=Cinzel+Decorative:wght@700;900&family=EB+Garamond:ital,wght@0,400;0,600;1,400;1,600&family=Kalam:wght@400;700&display=swap"
|
| 23 |
-
/>
|
| 24 |
-
<script type="module" crossorigin src="/assets/index-
|
| 25 |
<link rel="modulepreload" crossorigin href="/assets/rolldown-runtime-hePW80VL.js">
|
| 26 |
<link rel="modulepreload" crossorigin href="/assets/vendor-codemirror-By0wlJeM.js">
|
| 27 |
-
<link rel="modulepreload" crossorigin href="/assets/vendor-react-
|
| 28 |
<link rel="modulepreload" crossorigin href="/assets/vendor-firebase-DSIO3PIf.js">
|
| 29 |
<link rel="modulepreload" crossorigin href="/assets/firebaseClient-G7klkuBb.js">
|
| 30 |
<link rel="modulepreload" crossorigin href="/assets/vendor-ui-ZXcm-2wU.js">
|
| 31 |
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
| 32 |
-
<link rel="manifest" href="/manifest.webmanifest"><script id="vite-plugin-pwa:register-sw" src="/registerSW.js"></script></head>
|
| 33 |
-
|
| 34 |
-
<body>
|
| 35 |
-
<div id="app-loader">
|
| 36 |
-
<div class="skel-container">
|
| 37 |
-
<div id="skel-bg" class="skel-bg"></div>
|
| 38 |
-
<div class="skel-spinner-container">
|
| 39 |
-
<div class="skel-spinner"></div>
|
| 40 |
-
<div class="skel-text">Loading Workspace...</div>
|
| 41 |
-
</div>
|
| 42 |
-
<div class="skel-taskbar">
|
| 43 |
-
<div class="skel-start-btn">
|
| 44 |
-
<span class="material-symbols-outlined skel-start-icon">sports_esports</span>
|
| 45 |
-
Start
|
| 46 |
-
</div>
|
| 47 |
-
<div class="skel-clock">
|
| 48 |
-
<div class="skel-pulse skel-pulse-sm"></div>
|
| 49 |
-
<div class="skel-pulse skel-pulse-sm"></div>
|
| 50 |
-
<div class="skel-pulse skel-pulse-md"></div>
|
| 51 |
-
</div>
|
| 52 |
-
</div>
|
| 53 |
-
</div>
|
| 54 |
-
</div>
|
| 55 |
-
<script src="/loader-init.js"></script>
|
| 56 |
-
<div id="root"></div>
|
| 57 |
-
</body>
|
| 58 |
-
|
| 59 |
</html>
|
|
|
|
| 1 |
+
<!doctype html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
|
| 4 |
+
<head>
|
| 5 |
+
<meta charset="UTF-8" />
|
| 6 |
+
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
| 7 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 8 |
+
<meta name="description" content="AlgoSpaced is a gamified spaced repetition and active recall web application for mastering Data Structures and Algorithms with AI review, code sandbox, and retro arcade aesthetic." />
|
| 9 |
+
<meta
|
| 10 |
+
http-equiv="Content-Security-Policy"
|
| 11 |
+
content="default-src 'self'; script-src 'self' https://apis.google.com https://*.firebaseapp.com https://www.gstatic.com https://*.gstatic.com https://cdn.jsdelivr.net; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com https://cdn.jsdelivr.net; font-src 'self' data: https://fonts.gstatic.com https://*.gstatic.com; img-src 'self' data: blob: https://*.googleusercontent.com https://images.unsplash.com https://avatars.githubusercontent.com https://raw.githubusercontent.com https://github.com https://*.firebasestorage.app https://firebasestorage.googleapis.com https://cdn.jsdelivr.net https://fastapi.tiangolo.com; connect-src 'self' http://localhost:* http://127.0.0.1:* ws://localhost:* ws://127.0.0.1:* wss: https://*.googleapis.com https://*.firebaseio.com https://*.firebaseapp.com https://*.firebasestorage.app https://firebasestorage.googleapis.com https://accounts.google.com https://generativelanguage.googleapis.com https://api.groq.com https://openrouter.ai https://api.github.com https://*.hf.space https://hf.space; frame-src 'self' https://accounts.google.com https://*.firebaseapp.com https://*.firebase.com https://*.google.com https://apis.google.com; worker-src 'self' blob:; media-src 'self' data: blob:; object-src 'none'; base-uri 'self';"
|
| 12 |
+
/>
|
| 13 |
+
<title>AlgoSpaced (Beta) - DSA Review</title>
|
| 14 |
+
|
| 15 |
+
<!-- External critical loader styles (eliminates inline styles for strict CSP compliance) -->
|
| 16 |
+
<link rel="stylesheet" href="/loader.css" />
|
| 17 |
+
|
| 18 |
+
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
| 19 |
+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
| 20 |
+
<link
|
| 21 |
+
rel="stylesheet"
|
| 22 |
+
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:wght,FILL@100..700,0..1&family=Bricolage+Grotesque:opsz,wght@12..96,700;12..96,800&family=Be+Vietnam+Pro:wght@500;700&family=Courier+Prime:wght@400;700&family=Press+Start+2P&family=Cinzel:wght@500;700;900&family=Cinzel+Decorative:wght@700;900&family=EB+Garamond:ital,wght@0,400;0,600;1,400;1,600&family=Kalam:wght@400;700&display=swap"
|
| 23 |
+
/>
|
| 24 |
+
<script type="module" crossorigin src="/assets/index-DYMSjoUb.js"></script>
|
| 25 |
<link rel="modulepreload" crossorigin href="/assets/rolldown-runtime-hePW80VL.js">
|
| 26 |
<link rel="modulepreload" crossorigin href="/assets/vendor-codemirror-By0wlJeM.js">
|
| 27 |
+
<link rel="modulepreload" crossorigin href="/assets/vendor-react-qmUj3JUi.js">
|
| 28 |
<link rel="modulepreload" crossorigin href="/assets/vendor-firebase-DSIO3PIf.js">
|
| 29 |
<link rel="modulepreload" crossorigin href="/assets/firebaseClient-G7klkuBb.js">
|
| 30 |
<link rel="modulepreload" crossorigin href="/assets/vendor-ui-ZXcm-2wU.js">
|
| 31 |
+
<link rel="stylesheet" crossorigin href="/assets/index-supjX07i.css">
|
| 32 |
+
<link rel="manifest" href="/manifest.webmanifest"><script id="vite-plugin-pwa:register-sw" src="/registerSW.js"></script></head>
|
| 33 |
+
|
| 34 |
+
<body>
|
| 35 |
+
<div id="app-loader">
|
| 36 |
+
<div class="skel-container">
|
| 37 |
+
<div id="skel-bg" class="skel-bg"></div>
|
| 38 |
+
<div class="skel-spinner-container">
|
| 39 |
+
<div class="skel-spinner"></div>
|
| 40 |
+
<div class="skel-text">Loading Workspace...</div>
|
| 41 |
+
</div>
|
| 42 |
+
<div class="skel-taskbar">
|
| 43 |
+
<div class="skel-start-btn">
|
| 44 |
+
<span class="material-symbols-outlined skel-start-icon">sports_esports</span>
|
| 45 |
+
Start
|
| 46 |
+
</div>
|
| 47 |
+
<div class="skel-clock">
|
| 48 |
+
<div class="skel-pulse skel-pulse-sm"></div>
|
| 49 |
+
<div class="skel-pulse skel-pulse-sm"></div>
|
| 50 |
+
<div class="skel-pulse skel-pulse-md"></div>
|
| 51 |
+
</div>
|
| 52 |
+
</div>
|
| 53 |
+
</div>
|
| 54 |
+
</div>
|
| 55 |
+
<script src="/loader-init.js"></script>
|
| 56 |
+
<div id="root"></div>
|
| 57 |
+
</body>
|
| 58 |
+
|
| 59 |
</html>
|
algospaced-ui/dist/sw.js
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
if(!self.define){let s,e={};const l=(l,r)=>(l=new URL(l+".js",r).href,e[l]||new Promise(e=>{if("document"in self){const s=document.createElement("script");s.src=l,s.onload=e,document.head.appendChild(s)}else s=l,importScripts(l),e()}).then(()=>{let s=e[l];if(!s)throw new Error(`Module ${l} didn’t register its module`);return s}));self.define=(r,n)=>{const i=s||("document"in self?document.currentScript.src:"")||location.href;if(e[i])return;let u={};const o=s=>l(s,i),t={module:{uri:i},exports:u,require:o};e[i]=Promise.all(r.map(s=>t[s]||o(s))).then(s=>(n(...s),u))}}define(["./workbox-9c191d2f"],function(s){"use strict";self.skipWaiting(),s.clientsClaim(),s.precacheAndRoute([{url:"registerSW.js",revision:"1872c500de691dce40960bb85481de07"},{url:"loader.css",revision:"
|
|
|
|
| 1 |
+
if(!self.define){let s,e={};const l=(l,r)=>(l=new URL(l+".js",r).href,e[l]||new Promise(e=>{if("document"in self){const s=document.createElement("script");s.src=l,s.onload=e,document.head.appendChild(s)}else s=l,importScripts(l),e()}).then(()=>{let s=e[l];if(!s)throw new Error(`Module ${l} didn’t register its module`);return s}));self.define=(r,n)=>{const i=s||("document"in self?document.currentScript.src:"")||location.href;if(e[i])return;let u={};const o=s=>l(s,i),t={module:{uri:i},exports:u,require:o};e[i]=Promise.all(r.map(s=>t[s]||o(s))).then(s=>(n(...s),u))}}define(["./workbox-9c191d2f"],function(s){"use strict";self.skipWaiting(),s.clientsClaim(),s.precacheAndRoute([{url:"registerSW.js",revision:"1872c500de691dce40960bb85481de07"},{url:"loader.css",revision:"fe561cfc0908978c7b17dcf5d0ce1075"},{url:"loader-init.js",revision:"3d0342fa97370ec97880bb98818cd608"},{url:"index.html",revision:"010de35215c32ceb299a2a3156cb5e1b"},{url:"assets/vendor-ui-ZXcm-2wU.js",revision:null},{url:"assets/vendor-react-qmUj3JUi.js",revision:null},{url:"assets/vendor-katex-DtkCqjBQ.css",revision:null},{url:"assets/vendor-katex-Balf574a.js",revision:null},{url:"assets/vendor-firebase-DSIO3PIf.js",revision:null},{url:"assets/vendor-codemirror-By0wlJeM.js",revision:null},{url:"assets/TerminalEmulator-DUo8J_0j.js",revision:null},{url:"assets/Settings-mOsQagfT.js",revision:null},{url:"assets/rolldown-runtime-hePW80VL.js",revision:null},{url:"assets/ReviewQueue-C250a4ib.js",revision:null},{url:"assets/PythonChallenge-BUhtEPkm.js",revision:null},{url:"assets/ProblemSpecPanel-Df-cRYRz.js",revision:null},{url:"assets/PrincessChamber-IJaaUuL1.js",revision:null},{url:"assets/OnboardingModal-hhKaj0In.js",revision:null},{url:"assets/MySQLPlayground-CA-QZxQM.js",revision:null},{url:"assets/MarkdownRenderer-CC5nUs7-.js",revision:null},{url:"assets/KatexRenderer-DnoTdlgI.js",revision:null},{url:"assets/JourneyPath-DO-UXRtH.js",revision:null},{url:"assets/index-supjX07i.css",revision:null},{url:"assets/index-DYMSjoUb.js",revision:null},{url:"assets/GitHubSyncWindow-D0t6e3o3.js",revision:null},{url:"assets/githubSyncService-DQdE4J2L.js",revision:null},{url:"assets/firebaseClient-G7klkuBb.js",revision:null},{url:"assets/FileExplorer-BX57bI-L.js",revision:null},{url:"assets/CreateProblemForm-C2nCqjgj.js",revision:null},{url:"assets/confetti.module-Uxh4CK4s.js",revision:null},{url:"assets/Auth-B-5KpNfK.js",revision:null},{url:"manifest.webmanifest",revision:"7c8ff056d2e188c868d851bcb349e28e"}],{}),s.cleanupOutdatedCaches(),s.registerRoute(new s.NavigationRoute(s.createHandlerBoundToURL("index.html")))});
|
algospaced-ui/src/App.tsx
CHANGED
|
@@ -229,11 +229,7 @@ export default function App() {
|
|
| 229 |
},
|
| 230 |
{
|
| 231 |
id: 'companion',
|
| 232 |
-
label:
|
| 233 |
-
<>
|
| 234 |
-
PRINCESS<br />TOWER
|
| 235 |
-
</>
|
| 236 |
-
),
|
| 237 |
iconImg: '/sprites/princess/smiling_warmly.webp',
|
| 238 |
badgeShadowColor: '#fde047',
|
| 239 |
action: () => openWindow('companion')
|
|
|
|
| 229 |
},
|
| 230 |
{
|
| 231 |
id: 'companion',
|
| 232 |
+
label: 'Auri',
|
|
|
|
|
|
|
|
|
|
|
|
|
| 233 |
iconImg: '/sprites/princess/smiling_warmly.webp',
|
| 234 |
badgeShadowColor: '#fde047',
|
| 235 |
action: () => openWindow('companion')
|
algospaced-ui/src/components/PrincessDialoguePopup.tsx
CHANGED
|
@@ -11,7 +11,6 @@ import {
|
|
| 11 |
getTowerProgress,
|
| 12 |
} from '../utils/companionService';
|
| 13 |
import {
|
| 14 |
-
playTypewriterBlip,
|
| 15 |
playPopupChime,
|
| 16 |
isAudioMuted,
|
| 17 |
setAudioMuted,
|
|
@@ -79,10 +78,6 @@ export default function PrincessDialoguePopup({
|
|
| 79 |
if (charIndex < fullText.length) {
|
| 80 |
charIndex++;
|
| 81 |
setDisplayedText(fullText.slice(0, charIndex));
|
| 82 |
-
// Play blip every 2nd or 3rd char for pleasant rhythm
|
| 83 |
-
if (charIndex % 2 === 0 && fullText[charIndex - 1] !== ' ') {
|
| 84 |
-
playTypewriterBlip(charIndex);
|
| 85 |
-
}
|
| 86 |
} else {
|
| 87 |
if (timerRef.current) clearInterval(timerRef.current);
|
| 88 |
setIsTyping(false);
|
|
|
|
| 11 |
getTowerProgress,
|
| 12 |
} from '../utils/companionService';
|
| 13 |
import {
|
|
|
|
| 14 |
playPopupChime,
|
| 15 |
isAudioMuted,
|
| 16 |
setAudioMuted,
|
|
|
|
| 78 |
if (charIndex < fullText.length) {
|
| 79 |
charIndex++;
|
| 80 |
setDisplayedText(fullText.slice(0, charIndex));
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
} else {
|
| 82 |
if (timerRef.current) clearInterval(timerRef.current);
|
| 83 |
setIsTyping(false);
|
algospaced-ui/src/components/Settings.tsx
CHANGED
|
@@ -612,7 +612,7 @@ export default function Settings() {
|
|
| 612 |
/>
|
| 613 |
<div className="text-xs">
|
| 614 |
<span className="font-bold text-ink-black block">8-bit Sound Effects</span>
|
| 615 |
-
<span className="text-[10px] text-trash-gray">
|
| 616 |
</div>
|
| 617 |
</label>
|
| 618 |
|
|
|
|
| 612 |
/>
|
| 613 |
<div className="text-xs">
|
| 614 |
<span className="font-bold text-ink-black block">8-bit Sound Effects</span>
|
| 615 |
+
<span className="text-[10px] text-trash-gray">Audio chimes & fanfare</span>
|
| 616 |
</div>
|
| 617 |
</label>
|
| 618 |
|
algospaced-ui/src/components/desktop/DesktopStartMenu.tsx
CHANGED
|
@@ -113,7 +113,7 @@ export const DesktopStartMenu = React.forwardRef<HTMLDivElement, DesktopStartMen
|
|
| 113 |
<span className="material-symbols-outlined text-lg text-[#f59e0b]" style={{ fontVariationSettings: "'FILL' 1" }}>
|
| 114 |
castle
|
| 115 |
</span>
|
| 116 |
-
|
| 117 |
</button>
|
| 118 |
<button
|
| 119 |
onClick={() => onOpenWindow('python')}
|
|
|
|
| 113 |
<span className="material-symbols-outlined text-lg text-[#f59e0b]" style={{ fontVariationSettings: "'FILL' 1" }}>
|
| 114 |
castle
|
| 115 |
</span>
|
| 116 |
+
Auri
|
| 117 |
</button>
|
| 118 |
<button
|
| 119 |
onClick={() => onOpenWindow('python')}
|
algospaced-ui/src/components/desktop/DesktopTaskbar.tsx
CHANGED
|
@@ -35,7 +35,7 @@ const TASKBAR_ITEMS: TaskbarItemDef[] = [
|
|
| 35 |
{ id: 'editProblem', title: 'Edit Problem', shortTitle: 'Edit', icon: 'edit_note', color: '#059669' },
|
| 36 |
{ id: 'python', title: 'Python Challenge', shortTitle: 'Python', icon: 'sports_esports' },
|
| 37 |
{ id: 'mysql', title: 'MySQL Playground', shortTitle: 'SQL', icon: 'database' },
|
| 38 |
-
{ id: 'companion', title: '
|
| 39 |
{ id: 'settings', title: 'API Config', shortTitle: 'API', icon: 'key', color: '#10b981' },
|
| 40 |
];
|
| 41 |
|
|
@@ -141,9 +141,8 @@ export const DesktopTaskbar: React.FC<DesktopTaskbarProps> = ({
|
|
| 141 |
e.stopPropagation();
|
| 142 |
handleToggleStart();
|
| 143 |
}}
|
| 144 |
-
className={`h-full ${
|
| 145 |
-
|
| 146 |
-
} flex items-center gap-2 border-r-[4px] border-ink-black bg-[#39ff14] text-ink-black hover:bg-[#28e007] active:bg-[#1fb304] transition-colors shadow-[inset_-3px_-3px_0px_rgba(0,0,0,0.2),inset_3px_3px_0px_rgba(255,255,255,0.5)] font-bold cursor-pointer`}
|
| 147 |
title="Start Menu"
|
| 148 |
aria-label="Start Menu"
|
| 149 |
>
|
|
@@ -232,13 +231,13 @@ export const DesktopTaskbar: React.FC<DesktopTaskbarProps> = ({
|
|
| 232 |
|
| 233 |
<span
|
| 234 |
className="material-symbols-outlined cursor-pointer select-none text-lg hover:text-cyan-200 transition-colors"
|
| 235 |
-
title="Sound:
|
| 236 |
>
|
| 237 |
volume_up
|
| 238 |
</span>
|
| 239 |
<span
|
| 240 |
className="material-symbols-outlined cursor-pointer select-none text-lg hover:text-cyan-200 transition-colors"
|
| 241 |
-
title="
|
| 242 |
>
|
| 243 |
network_wifi
|
| 244 |
</span>
|
|
|
|
| 35 |
{ id: 'editProblem', title: 'Edit Problem', shortTitle: 'Edit', icon: 'edit_note', color: '#059669' },
|
| 36 |
{ id: 'python', title: 'Python Challenge', shortTitle: 'Python', icon: 'sports_esports' },
|
| 37 |
{ id: 'mysql', title: 'MySQL Playground', shortTitle: 'SQL', icon: 'database' },
|
| 38 |
+
{ id: 'companion', title: 'Auri', shortTitle: 'Auri', icon: 'castle', color: '#d97706' },
|
| 39 |
{ id: 'settings', title: 'API Config', shortTitle: 'API', icon: 'key', color: '#10b981' },
|
| 40 |
];
|
| 41 |
|
|
|
|
| 141 |
e.stopPropagation();
|
| 142 |
handleToggleStart();
|
| 143 |
}}
|
| 144 |
+
className={`h-full ${isMobile ? 'px-3' : 'px-6'
|
| 145 |
+
} flex items-center gap-2 border-r-[4px] border-ink-black bg-[#39ff14] text-ink-black hover:bg-[#28e007] active:bg-[#1fb304] transition-colors shadow-[inset_-3px_-3px_0px_rgba(0,0,0,0.2),inset_3px_3px_0px_rgba(255,255,255,0.5)] font-bold cursor-pointer`}
|
|
|
|
| 146 |
title="Start Menu"
|
| 147 |
aria-label="Start Menu"
|
| 148 |
>
|
|
|
|
| 231 |
|
| 232 |
<span
|
| 233 |
className="material-symbols-outlined cursor-pointer select-none text-lg hover:text-cyan-200 transition-colors"
|
| 234 |
+
title="Sound: ON"
|
| 235 |
>
|
| 236 |
volume_up
|
| 237 |
</span>
|
| 238 |
<span
|
| 239 |
className="material-symbols-outlined cursor-pointer select-none text-lg hover:text-cyan-200 transition-colors"
|
| 240 |
+
title="Online"
|
| 241 |
>
|
| 242 |
network_wifi
|
| 243 |
</span>
|
algospaced-ui/src/components/desktop/DesktopWindowContainer.tsx
CHANGED
|
@@ -476,33 +476,23 @@ export const DesktopWindowContainer: React.FC<DesktopWindowContainerProps> = ({
|
|
| 476 |
</Suspense>
|
| 477 |
</WindowShell>
|
| 478 |
|
| 479 |
-
{/* 9. Princess Tower Companion
|
| 480 |
-
{windows.companion?.isOpen && (
|
| 481 |
-
<
|
| 482 |
-
|
| 483 |
-
|
| 484 |
-
|
| 485 |
-
|
| 486 |
-
|
| 487 |
-
onClose={() => closeWindow('companion')}
|
| 488 |
-
onMinimize={() => minimizeWindow('companion')}
|
| 489 |
-
activeWindow={activeWindow}
|
| 490 |
-
setActiveWindow={setActiveWindow}
|
| 491 |
-
defaultWidth="840px"
|
| 492 |
-
defaultHeight="600px"
|
| 493 |
-
titleBarColor="#f59e0b"
|
| 494 |
-
isMobile={isMobile}
|
| 495 |
>
|
| 496 |
-
<
|
| 497 |
-
|
| 498 |
-
|
| 499 |
-
|
| 500 |
-
|
| 501 |
-
}
|
| 502 |
-
>
|
| 503 |
-
|
| 504 |
-
</Suspense>
|
| 505 |
-
</WindowShell>
|
| 506 |
)}
|
| 507 |
|
| 508 |
</>
|
|
|
|
| 476 |
</Suspense>
|
| 477 |
</WindowShell>
|
| 478 |
|
| 479 |
+
{/* 9. Princess Tower Companion - JRPG Dialogue Stage */}
|
| 480 |
+
{windows.companion?.isOpen && !windows.companion.isMinimized && (
|
| 481 |
+
<Suspense
|
| 482 |
+
fallback={
|
| 483 |
+
<div className="fixed bottom-16 right-8 font-mono text-xs text-amber-300 bg-slate-900/90 p-4 border-2 border-slate-700 rounded z-40 animate-pulse">
|
| 484 |
+
Entering the Spire Tower Parlor...
|
| 485 |
+
</div>
|
| 486 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 487 |
>
|
| 488 |
+
<PrincessChamber
|
| 489 |
+
onClose={() => closeWindow('companion')}
|
| 490 |
+
onMinimize={() => minimizeWindow('companion')}
|
| 491 |
+
isActive={activeWindow === 'companion'}
|
| 492 |
+
onFocus={() => setActiveWindow('companion')}
|
| 493 |
+
isMobile={isMobile}
|
| 494 |
+
/>
|
| 495 |
+
</Suspense>
|
|
|
|
|
|
|
| 496 |
)}
|
| 497 |
|
| 498 |
</>
|
algospaced-ui/src/components/desktop/MobileMetroScreen.tsx
CHANGED
|
@@ -153,14 +153,14 @@ export const MobileMetroScreen: React.FC<MobileMetroScreenProps> = ({
|
|
| 153 |
className="bg-[#f59e0b] hover:bg-amber-600 text-ink-black border-[3px] border-ink-black p-4 flex flex-col justify-between aspect-square gadget-shadow active:translate-y-1 active:translate-x-1 active:shadow-none select-none text-left cursor-pointer transition-all"
|
| 154 |
>
|
| 155 |
<img
|
| 156 |
-
alt="
|
| 157 |
width={40}
|
| 158 |
height={40}
|
| 159 |
className="w-10 h-10 object-cover object-top border-2 border-ink-black bg-amber-100 rounded"
|
| 160 |
src="/sprites/princess/smiling_warmly.webp"
|
| 161 |
/>
|
| 162 |
<span className="font-arcade text-[8px] font-bold tracking-tight uppercase leading-tight">
|
| 163 |
-
|
| 164 |
</span>
|
| 165 |
</button>
|
| 166 |
|
|
|
|
| 153 |
className="bg-[#f59e0b] hover:bg-amber-600 text-ink-black border-[3px] border-ink-black p-4 flex flex-col justify-between aspect-square gadget-shadow active:translate-y-1 active:translate-x-1 active:shadow-none select-none text-left cursor-pointer transition-all"
|
| 154 |
>
|
| 155 |
<img
|
| 156 |
+
alt="Auri"
|
| 157 |
width={40}
|
| 158 |
height={40}
|
| 159 |
className="w-10 h-10 object-cover object-top border-2 border-ink-black bg-amber-100 rounded"
|
| 160 |
src="/sprites/princess/smiling_warmly.webp"
|
| 161 |
/>
|
| 162 |
<span className="font-arcade text-[8px] font-bold tracking-tight uppercase leading-tight">
|
| 163 |
+
AURI
|
| 164 |
</span>
|
| 165 |
</button>
|
| 166 |
|
algospaced-ui/src/features/companion/components/CharacterStage.tsx
CHANGED
|
@@ -2,14 +2,15 @@ import { useMemo } from 'react';
|
|
| 2 |
import type { PrincessEmotion, TowerRhythmState } from '../types';
|
| 3 |
import { PRINCESS_EMOTIONS } from '../types';
|
| 4 |
import { getChapterWeather } from '../data/chapterWeather';
|
| 5 |
-
import { Sparkles } from 'lucide-react';
|
| 6 |
|
| 7 |
-
interface CharacterStageProps {
|
| 8 |
emotion: PrincessEmotion;
|
| 9 |
floor: number;
|
| 10 |
rhythm: TowerRhythmState;
|
| 11 |
activity?: string;
|
| 12 |
isLoading?: boolean;
|
|
|
|
|
|
|
| 13 |
}
|
| 14 |
|
| 15 |
export default function CharacterStage({
|
|
@@ -18,6 +19,8 @@ export default function CharacterStage({
|
|
| 18 |
rhythm,
|
| 19 |
activity,
|
| 20 |
isLoading = false,
|
|
|
|
|
|
|
| 21 |
}: CharacterStageProps) {
|
| 22 |
const emotionMeta = PRINCESS_EMOTIONS[emotion] || PRINCESS_EMOTIONS.smiling_warmly;
|
| 23 |
const weather = useMemo(() => getChapterWeather(floor), [floor]);
|
|
@@ -26,37 +29,40 @@ export default function CharacterStage({
|
|
| 26 |
const rhythmGlow = useMemo(() => {
|
| 27 |
switch (rhythm) {
|
| 28 |
case 'dawn':
|
| 29 |
-
return 'from-amber-400/
|
| 30 |
case 'dusk':
|
| 31 |
-
return 'from-orange-
|
| 32 |
case 'night':
|
| 33 |
-
return 'from-indigo-600/
|
| 34 |
case 'day':
|
| 35 |
default:
|
| 36 |
-
return 'from-amber-
|
| 37 |
}
|
| 38 |
}, [rhythm]);
|
| 39 |
|
| 40 |
return (
|
| 41 |
-
<div
|
| 42 |
-
{
|
|
|
|
|
|
|
|
|
|
| 43 |
<div className="absolute -inset-10 overflow-hidden pointer-events-none z-0">
|
| 44 |
-
{Array.from({ length: Math.min(
|
| 45 |
const color = weather.particleColors[i % weather.particleColors.length];
|
| 46 |
-
const left = `${(i *
|
| 47 |
-
const duration = `${
|
| 48 |
-
const delay = `${(i * 0.
|
| 49 |
-
const size = weather.particleType === 'leaves' || weather.particleType === 'runes' ? 'w-2
|
| 50 |
|
| 51 |
return (
|
| 52 |
<span
|
| 53 |
key={i}
|
| 54 |
-
className={`absolute rounded-full opacity-
|
| 55 |
style={{
|
| 56 |
backgroundColor: color,
|
| 57 |
left,
|
| 58 |
-
top: `${(i *
|
| 59 |
-
boxShadow: `0 0
|
| 60 |
animationDuration: duration,
|
| 61 |
animationDelay: delay,
|
| 62 |
}}
|
|
@@ -65,63 +71,42 @@ export default function CharacterStage({
|
|
| 65 |
})}
|
| 66 |
</div>
|
| 67 |
|
| 68 |
-
{/*
|
| 69 |
-
<div
|
| 70 |
-
{
|
| 71 |
-
|
| 72 |
-
className={`absolute -inset-2 bg-gradient-to-r ${rhythmGlow} rounded-2xl blur-md opacity-80 group-hover:opacity-100 transition duration-500`}
|
| 73 |
-
/>
|
| 74 |
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
<span className="
|
|
|
|
|
|
|
|
|
|
| 81 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
<img
|
| 83 |
src={emotionMeta.imagePath}
|
| 84 |
alt={emotionMeta.label}
|
| 85 |
loading="eager"
|
| 86 |
-
className={`
|
| 87 |
-
|
| 88 |
-
}`}
|
| 89 |
onError={(e) => {
|
| 90 |
const target = e.currentTarget;
|
| 91 |
-
if (!target.src.endsWith('/sprites/princess/
|
|
|
|
|
|
|
| 92 |
target.src = '/sprites/princess/neutral.webp';
|
| 93 |
-
} else {
|
| 94 |
-
target.style.display = 'none';
|
| 95 |
}
|
| 96 |
}}
|
| 97 |
/>
|
| 98 |
-
|
| 99 |
-
{/* Status Ribbon Overlay on Image */}
|
| 100 |
-
<div className="absolute bottom-0 inset-x-0 bg-ink-black/85 backdrop-blur-xs text-[10px] text-amber-300 py-1 px-2 font-bold uppercase tracking-wider text-center flex items-center justify-center gap-1.5">
|
| 101 |
-
<span
|
| 102 |
-
className={`w-1.5 h-1.5 rounded-full ${
|
| 103 |
-
isLoading ? 'bg-amber-400 animate-ping' : 'bg-emerald-400'
|
| 104 |
-
}`}
|
| 105 |
-
/>
|
| 106 |
-
<span>{isLoading ? 'Pondering...' : emotionMeta.label}</span>
|
| 107 |
-
</div>
|
| 108 |
-
</div>
|
| 109 |
-
|
| 110 |
-
{/* Floating Sparkle Accessory Badge */}
|
| 111 |
-
<div className="absolute -top-2 -right-2 bg-[#FFE24C] border-[2px] border-ink-black rounded-full p-1 shadow-[2px_2px_0px_0px_#1E293B]">
|
| 112 |
-
<Sparkles className="w-3.5 h-3.5 text-amber-800" />
|
| 113 |
</div>
|
| 114 |
</div>
|
| 115 |
-
|
| 116 |
-
{/* Living Tower Activity Sub-Banner */}
|
| 117 |
-
{activity && (
|
| 118 |
-
<div className="mt-2 text-center max-w-sm px-2">
|
| 119 |
-
<span className="text-[10px] font-semibold text-slate-700 bg-white/85 px-2.5 py-0.5 rounded-full border border-ink-black/20 shadow-xs inline-flex items-center gap-1">
|
| 120 |
-
<span>🏰</span>
|
| 121 |
-
<span className="truncate">{activity}</span>
|
| 122 |
-
</span>
|
| 123 |
-
</div>
|
| 124 |
-
)}
|
| 125 |
</div>
|
| 126 |
);
|
| 127 |
}
|
|
|
|
| 2 |
import type { PrincessEmotion, TowerRhythmState } from '../types';
|
| 3 |
import { PRINCESS_EMOTIONS } from '../types';
|
| 4 |
import { getChapterWeather } from '../data/chapterWeather';
|
|
|
|
| 5 |
|
| 6 |
+
export interface CharacterStageProps {
|
| 7 |
emotion: PrincessEmotion;
|
| 8 |
floor: number;
|
| 9 |
rhythm: TowerRhythmState;
|
| 10 |
activity?: string;
|
| 11 |
isLoading?: boolean;
|
| 12 |
+
className?: string;
|
| 13 |
+
onClick?: () => void;
|
| 14 |
}
|
| 15 |
|
| 16 |
export default function CharacterStage({
|
|
|
|
| 19 |
rhythm,
|
| 20 |
activity,
|
| 21 |
isLoading = false,
|
| 22 |
+
className = '',
|
| 23 |
+
onClick,
|
| 24 |
}: CharacterStageProps) {
|
| 25 |
const emotionMeta = PRINCESS_EMOTIONS[emotion] || PRINCESS_EMOTIONS.smiling_warmly;
|
| 26 |
const weather = useMemo(() => getChapterWeather(floor), [floor]);
|
|
|
|
| 29 |
const rhythmGlow = useMemo(() => {
|
| 30 |
switch (rhythm) {
|
| 31 |
case 'dawn':
|
| 32 |
+
return 'from-amber-400/30 via-yellow-300/20 to-transparent';
|
| 33 |
case 'dusk':
|
| 34 |
+
return 'from-orange-500/30 via-purple-500/20 to-transparent';
|
| 35 |
case 'night':
|
| 36 |
+
return 'from-indigo-600/30 via-blue-500/20 to-transparent';
|
| 37 |
case 'day':
|
| 38 |
default:
|
| 39 |
+
return 'from-amber-300/25 via-sky-300/20 to-transparent';
|
| 40 |
}
|
| 41 |
}, [rhythm]);
|
| 42 |
|
| 43 |
return (
|
| 44 |
+
<div
|
| 45 |
+
onClick={onClick}
|
| 46 |
+
className={`relative flex flex-col items-center justify-end select-none pointer-events-auto transition-transform ${className}`}
|
| 47 |
+
>
|
| 48 |
+
{/* Chapter Ambient Weather Particle Layer */}
|
| 49 |
<div className="absolute -inset-10 overflow-hidden pointer-events-none z-0">
|
| 50 |
+
{Array.from({ length: Math.min(16, weather.particleCount) }).map((_, i) => {
|
| 51 |
const color = weather.particleColors[i % weather.particleColors.length];
|
| 52 |
+
const left = `${(i * 17) % 100}%`;
|
| 53 |
+
const duration = `${7 + (i % 5) * 2}s`;
|
| 54 |
+
const delay = `${(i * 0.8) % 4}s`;
|
| 55 |
+
const size = weather.particleType === 'leaves' || weather.particleType === 'runes' ? 'w-2 h-2' : 'w-1.5 h-1.5';
|
| 56 |
|
| 57 |
return (
|
| 58 |
<span
|
| 59 |
key={i}
|
| 60 |
+
className={`absolute rounded-full opacity-60 animate-pulse ${size}`}
|
| 61 |
style={{
|
| 62 |
backgroundColor: color,
|
| 63 |
left,
|
| 64 |
+
top: `${(i * 21) % 90}%`,
|
| 65 |
+
boxShadow: `0 0 10px ${color}`,
|
| 66 |
animationDuration: duration,
|
| 67 |
animationDelay: delay,
|
| 68 |
}}
|
|
|
|
| 71 |
})}
|
| 72 |
</div>
|
| 73 |
|
| 74 |
+
{/* Subtle Ambient Backlight Glow behind Princess */}
|
| 75 |
+
<div
|
| 76 |
+
className={`absolute bottom-4 inset-x-0 h-48 sm:h-72 md:h-96 bg-radial ${rhythmGlow} blur-2xl opacity-70 pointer-events-none z-0`}
|
| 77 |
+
/>
|
|
|
|
|
|
|
| 78 |
|
| 79 |
+
{/* Full Standing Visual Novel Bust Sprite */}
|
| 80 |
+
<div className="relative z-10 flex flex-col items-start justify-end">
|
| 81 |
+
{/* Living Tower Activity Sub-Banner (floating softly above her) */}
|
| 82 |
+
{activity && (
|
| 83 |
+
<div className="mb-2 max-w-[120px] sm:max-w-xs text-center pointer-events-none animate-in fade-in duration-300">
|
| 84 |
+
<span className="text-[9px] sm:text-[10px] font-mono font-medium text-[#bfe1ff] bg-[#101e2e]/85 px-2 sm:px-2.5 py-0.5 rounded-full border border-[#3e6080]/70 shadow-md inline-flex items-center gap-1 sm:gap-1.5 backdrop-blur-xs">
|
| 85 |
+
<span className="text-amber-400">🏰</span>
|
| 86 |
+
<span className="truncate">{activity}</span>
|
| 87 |
+
</span>
|
| 88 |
</div>
|
| 89 |
+
)}
|
| 90 |
+
|
| 91 |
+
{/* Character Portrait Sprite */}
|
| 92 |
+
<div className="relative h-[28vh] sm:h-[40vh] md:h-[46vh] lg:h-[50vh] max-h-[220px] sm:max-h-[380px] md:max-h-[460px] lg:max-h-[500px] min-h-[160px] sm:min-h-[240px] md:min-h-[300px] w-auto max-w-[110px] sm:max-w-[200px] md:max-w-[270px] lg:max-w-[320px] flex items-end justify-end">
|
| 93 |
<img
|
| 94 |
src={emotionMeta.imagePath}
|
| 95 |
alt={emotionMeta.label}
|
| 96 |
loading="eager"
|
| 97 |
+
className={`h-full w-auto max-h-[85vh] object-contain object-bottom-left drop-shadow-[0_16px_32px_rgba(0,0,0,0.55)] transition-all duration-300 ${isLoading ? 'scale-[1.02] filter brightness-110 saturate-125' : 'scale-100'
|
| 98 |
+
}`}
|
|
|
|
| 99 |
onError={(e) => {
|
| 100 |
const target = e.currentTarget;
|
| 101 |
+
if (!target.src.endsWith('/sprites/princess/smiling_warmly.webp')) {
|
| 102 |
+
target.src = '/sprites/princess/smiling_warmly.webp';
|
| 103 |
+
} else if (!target.src.endsWith('/sprites/princess/neutral.webp')) {
|
| 104 |
target.src = '/sprites/princess/neutral.webp';
|
|
|
|
|
|
|
| 105 |
}
|
| 106 |
}}
|
| 107 |
/>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
</div>
|
| 109 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
</div>
|
| 111 |
);
|
| 112 |
}
|
algospaced-ui/src/features/companion/components/DialogueBubble.tsx
CHANGED
|
@@ -1,9 +1,7 @@
|
|
| 1 |
-
import
|
| 2 |
import type { PrincessEmotion, CompanionToolCall } from '../types';
|
| 3 |
-
import { PRINCESS_EMOTIONS } from '../types';
|
| 4 |
-
import { playTypewriterBlip } from '../../../utils/rpgAudio';
|
| 5 |
|
| 6 |
-
interface DialogueBubbleProps {
|
| 7 |
text: string;
|
| 8 |
characterName: string;
|
| 9 |
emotion: PrincessEmotion;
|
|
@@ -11,6 +9,19 @@ interface DialogueBubbleProps {
|
|
| 11 |
isStreaming?: boolean;
|
| 12 |
toolCalls?: CompanionToolCall[];
|
| 13 |
onTypingStatusChange?: (isTyping: boolean) => void;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
}
|
| 15 |
|
| 16 |
export default function DialogueBubble({
|
|
@@ -21,175 +32,42 @@ export default function DialogueBubble({
|
|
| 21 |
isStreaming = false,
|
| 22 |
toolCalls,
|
| 23 |
onTypingStatusChange,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
}: DialogueBubbleProps) {
|
| 25 |
-
const [displayedText, setDisplayedText] = useState(text);
|
| 26 |
-
const [isTyping, setIsTyping] = useState(false);
|
| 27 |
-
const timerRef = useRef<ReturnType<typeof setInterval> | null>(null);
|
| 28 |
-
const prevTextRef = useRef<string>(text);
|
| 29 |
-
const lastBlipLenRef = useRef<number>(0);
|
| 30 |
-
const onTypingRef = useRef(onTypingStatusChange);
|
| 31 |
-
useEffect(() => {
|
| 32 |
-
onTypingRef.current = onTypingStatusChange;
|
| 33 |
-
}, [onTypingStatusChange]);
|
| 34 |
-
|
| 35 |
-
const emotionMeta = PRINCESS_EMOTIONS[emotion] || PRINCESS_EMOTIONS.smiling_warmly;
|
| 36 |
-
|
| 37 |
-
const setTypingState = (typing: boolean) => {
|
| 38 |
-
setIsTyping(typing);
|
| 39 |
-
onTypingRef.current?.(typing);
|
| 40 |
-
};
|
| 41 |
-
|
| 42 |
-
useEffect(() => {
|
| 43 |
-
// If streaming in real time
|
| 44 |
-
if (isStreaming) {
|
| 45 |
-
if (timerRef.current) clearInterval(timerRef.current);
|
| 46 |
-
setDisplayedText(text);
|
| 47 |
-
setTypingState(true);
|
| 48 |
-
|
| 49 |
-
// Play blip every ~4 characters
|
| 50 |
-
if (text.length - lastBlipLenRef.current >= 4) {
|
| 51 |
-
lastBlipLenRef.current = text.length;
|
| 52 |
-
playTypewriterBlip(text.length);
|
| 53 |
-
}
|
| 54 |
-
prevTextRef.current = text;
|
| 55 |
-
return;
|
| 56 |
-
}
|
| 57 |
-
|
| 58 |
-
// Stream just ended or static text updated
|
| 59 |
-
if (text !== prevTextRef.current && !isLoading) {
|
| 60 |
-
const wasStreaming = prevTextRef.current.length > 0 && text.startsWith(prevTextRef.current);
|
| 61 |
-
prevTextRef.current = text;
|
| 62 |
-
if (timerRef.current) clearInterval(timerRef.current);
|
| 63 |
-
|
| 64 |
-
if (wasStreaming) {
|
| 65 |
-
// Smoothly finalize without rewinding
|
| 66 |
-
setDisplayedText(text);
|
| 67 |
-
setTypingState(false);
|
| 68 |
-
} else {
|
| 69 |
-
// Standard typewriter for brand new non-streamed turns
|
| 70 |
-
setDisplayedText('');
|
| 71 |
-
setTypingState(true);
|
| 72 |
-
|
| 73 |
-
let charIndex = 0;
|
| 74 |
-
timerRef.current = setInterval(() => {
|
| 75 |
-
if (charIndex < text.length) {
|
| 76 |
-
charIndex++;
|
| 77 |
-
setDisplayedText(text.slice(0, charIndex));
|
| 78 |
-
if (charIndex % 2 === 0 && text[charIndex - 1] !== ' ') {
|
| 79 |
-
playTypewriterBlip(charIndex);
|
| 80 |
-
}
|
| 81 |
-
} else {
|
| 82 |
-
if (timerRef.current) clearInterval(timerRef.current);
|
| 83 |
-
setTypingState(false);
|
| 84 |
-
}
|
| 85 |
-
}, 22);
|
| 86 |
-
}
|
| 87 |
-
} else if (!isLoading && text === prevTextRef.current && !isStreaming) {
|
| 88 |
-
setDisplayedText(text);
|
| 89 |
-
if (isTyping) {
|
| 90 |
-
setTypingState(false);
|
| 91 |
-
}
|
| 92 |
-
}
|
| 93 |
-
|
| 94 |
-
return () => {
|
| 95 |
-
if (timerRef.current) clearInterval(timerRef.current);
|
| 96 |
-
};
|
| 97 |
-
}, [text, isLoading, isStreaming]);
|
| 98 |
-
|
| 99 |
-
const handleSkipTyping = () => {
|
| 100 |
-
if (isTyping) {
|
| 101 |
-
if (timerRef.current) clearInterval(timerRef.current);
|
| 102 |
-
setDisplayedText(text);
|
| 103 |
-
setTypingState(false);
|
| 104 |
-
}
|
| 105 |
-
};
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
// Helper to format *stage actions* with italicized amber styling
|
| 109 |
-
const renderFormattedDialogue = (raw: string) => {
|
| 110 |
-
const parts = raw.split(/(\*[^*]+\*)/g);
|
| 111 |
-
return parts.map((part, index) => {
|
| 112 |
-
if (part.startsWith('*') && part.endsWith('*')) {
|
| 113 |
-
return (
|
| 114 |
-
<span
|
| 115 |
-
key={index}
|
| 116 |
-
className="text-amber-700 italic font-semibold mr-1 inline-block"
|
| 117 |
-
>
|
| 118 |
-
{part}
|
| 119 |
-
</span>
|
| 120 |
-
);
|
| 121 |
-
}
|
| 122 |
-
return <span key={index}>{part}</span>;
|
| 123 |
-
});
|
| 124 |
-
};
|
| 125 |
-
|
| 126 |
return (
|
| 127 |
-
<
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
{
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
{
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
</span>
|
| 150 |
-
)}
|
| 151 |
-
</div>
|
| 152 |
-
|
| 153 |
-
{/* Bubble Content Body */}
|
| 154 |
-
{isLoading ? (
|
| 155 |
-
<div className="flex items-center gap-2 py-2 text-xs font-medium text-trash-gray select-none">
|
| 156 |
-
<span className="inline-block w-2 h-2 bg-amber-500 rounded-full animate-bounce" />
|
| 157 |
-
<span className="inline-block w-2 h-2 bg-amber-500 rounded-full animate-bounce [animation-delay:0.2s]" />
|
| 158 |
-
<span className="inline-block w-2 h-2 bg-amber-500 rounded-full animate-bounce [animation-delay:0.4s]" />
|
| 159 |
-
<span className="ml-1 text-slate-600">
|
| 160 |
-
{characterName || 'Princess Aurelia'} is attuning the crystal relay...
|
| 161 |
-
</span>
|
| 162 |
-
</div>
|
| 163 |
-
) : (
|
| 164 |
-
<div className="text-xs sm:text-[13px] text-ink-black font-medium leading-relaxed whitespace-pre-wrap">
|
| 165 |
-
{renderFormattedDialogue(displayedText)}
|
| 166 |
-
{isTyping && (
|
| 167 |
-
<span className="inline-block w-1.5 h-3.5 bg-amber-500 ml-1 animate-pulse align-middle" />
|
| 168 |
-
)}
|
| 169 |
-
</div>
|
| 170 |
-
)}
|
| 171 |
-
|
| 172 |
-
{/* Active Agent Tool Badges */}
|
| 173 |
-
{toolCalls && toolCalls.length > 0 && !isLoading && (
|
| 174 |
-
<div className="mt-2.5 pt-2 border-t border-amber-100/80 flex flex-wrap gap-1.5 select-none">
|
| 175 |
-
{toolCalls.map((tc, idx) => {
|
| 176 |
-
let label = `✨ Enchantment: ${tc.name}`;
|
| 177 |
-
if (tc.name === 'open_app_window') label = `📜 Summoned: ${tc.args?.window_id || 'Grimoire'}`;
|
| 178 |
-
if (tc.name === 'set_study_timer') label = `⏳ Hourglass: ${tc.args?.minutes || 15}m rest`;
|
| 179 |
-
if (tc.name === 'play_ambient_sound') label = `🔥 Kindled: ${tc.args?.soundscape || 'Soundscape'}`;
|
| 180 |
-
if (tc.name === 'write_spire_diary') label = `📖 Chronicled in Spire Diary`;
|
| 181 |
-
|
| 182 |
-
return (
|
| 183 |
-
<span
|
| 184 |
-
key={idx}
|
| 185 |
-
className="px-2 py-0.5 rounded-full bg-indigo-50 border border-indigo-200 text-[10px] font-bold text-indigo-800 flex items-center gap-1 shadow-xs"
|
| 186 |
-
>
|
| 187 |
-
<span>{label}</span>
|
| 188 |
-
</span>
|
| 189 |
-
);
|
| 190 |
-
})}
|
| 191 |
-
</div>
|
| 192 |
-
)}
|
| 193 |
-
</div>
|
| 194 |
);
|
| 195 |
}
|
|
|
|
| 1 |
+
import JRPGDialogueBox from './JRPGDialogueBox';
|
| 2 |
import type { PrincessEmotion, CompanionToolCall } from '../types';
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
export interface DialogueBubbleProps {
|
| 5 |
text: string;
|
| 6 |
characterName: string;
|
| 7 |
emotion: PrincessEmotion;
|
|
|
|
| 9 |
isStreaming?: boolean;
|
| 10 |
toolCalls?: CompanionToolCall[];
|
| 11 |
onTypingStatusChange?: (isTyping: boolean) => void;
|
| 12 |
+
choices?: string[];
|
| 13 |
+
onSelectChoice?: (choice: string) => void;
|
| 14 |
+
onSendMessage?: (message: string) => void;
|
| 15 |
+
currentFloor?: number;
|
| 16 |
+
bondTier?: string;
|
| 17 |
+
satchelCount?: number;
|
| 18 |
+
isMuted?: boolean;
|
| 19 |
+
onToggleMute?: () => void;
|
| 20 |
+
onOpenProgress?: () => void;
|
| 21 |
+
onOpenSatchel?: () => void;
|
| 22 |
+
onOpenHistory?: () => void;
|
| 23 |
+
onMinimize?: () => void;
|
| 24 |
+
onClose?: () => void;
|
| 25 |
}
|
| 26 |
|
| 27 |
export default function DialogueBubble({
|
|
|
|
| 32 |
isStreaming = false,
|
| 33 |
toolCalls,
|
| 34 |
onTypingStatusChange,
|
| 35 |
+
choices,
|
| 36 |
+
onSelectChoice,
|
| 37 |
+
onSendMessage,
|
| 38 |
+
currentFloor = 1,
|
| 39 |
+
bondTier = 'Acquaintance',
|
| 40 |
+
satchelCount = 0,
|
| 41 |
+
isMuted = false,
|
| 42 |
+
onToggleMute,
|
| 43 |
+
onOpenProgress,
|
| 44 |
+
onOpenSatchel,
|
| 45 |
+
onOpenHistory,
|
| 46 |
+
onMinimize,
|
| 47 |
+
onClose,
|
| 48 |
}: DialogueBubbleProps) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
return (
|
| 50 |
+
<JRPGDialogueBox
|
| 51 |
+
characterName={characterName}
|
| 52 |
+
emotion={emotion}
|
| 53 |
+
text={text}
|
| 54 |
+
isLoading={isLoading}
|
| 55 |
+
isStreaming={isStreaming}
|
| 56 |
+
toolCalls={toolCalls}
|
| 57 |
+
onTypingStatusChange={onTypingStatusChange}
|
| 58 |
+
choices={choices}
|
| 59 |
+
onSelectChoice={onSelectChoice || (() => {})}
|
| 60 |
+
onSendMessage={onSendMessage || (() => {})}
|
| 61 |
+
currentFloor={currentFloor}
|
| 62 |
+
bondTier={bondTier}
|
| 63 |
+
satchelCount={satchelCount}
|
| 64 |
+
isMuted={isMuted}
|
| 65 |
+
onToggleMute={onToggleMute}
|
| 66 |
+
onOpenProgress={onOpenProgress}
|
| 67 |
+
onOpenSatchel={onOpenSatchel}
|
| 68 |
+
onOpenHistory={onOpenHistory}
|
| 69 |
+
onMinimize={onMinimize}
|
| 70 |
+
onClose={onClose}
|
| 71 |
+
/>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
);
|
| 73 |
}
|
algospaced-ui/src/features/companion/components/JRPGDialogueBox.tsx
ADDED
|
@@ -0,0 +1,479 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { useState, useEffect, useRef, useCallback, useMemo } from 'react';
|
| 2 |
+
import type React from 'react';
|
| 3 |
+
import type { PrincessEmotion, CompanionToolCall } from '../types';
|
| 4 |
+
import {
|
| 5 |
+
Castle,
|
| 6 |
+
Scroll,
|
| 7 |
+
History,
|
| 8 |
+
Volume2,
|
| 9 |
+
VolumeX,
|
| 10 |
+
Minus,
|
| 11 |
+
X,
|
| 12 |
+
Sparkles,
|
| 13 |
+
} from 'lucide-react';
|
| 14 |
+
|
| 15 |
+
export interface JRPGDialogueBoxProps {
|
| 16 |
+
characterName: string;
|
| 17 |
+
emotion: PrincessEmotion;
|
| 18 |
+
text: string;
|
| 19 |
+
isStreaming?: boolean;
|
| 20 |
+
isLoading?: boolean;
|
| 21 |
+
choices?: string[];
|
| 22 |
+
toolCalls?: CompanionToolCall[];
|
| 23 |
+
onSelectChoice: (choiceText: string) => void;
|
| 24 |
+
onSendMessage: (text: string) => void;
|
| 25 |
+
onTypingStatusChange?: (isTyping: boolean) => void;
|
| 26 |
+
currentFloor: number;
|
| 27 |
+
bondTier: string;
|
| 28 |
+
satchelCount?: number;
|
| 29 |
+
isMuted?: boolean;
|
| 30 |
+
onToggleMute?: () => void;
|
| 31 |
+
onOpenProgress?: () => void;
|
| 32 |
+
onOpenSatchel?: () => void;
|
| 33 |
+
onOpenHistory?: () => void;
|
| 34 |
+
onMinimize?: () => void;
|
| 35 |
+
onClose?: () => void;
|
| 36 |
+
className?: string;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
const DEFAULT_JRPG_CHOICES: string[] = [
|
| 40 |
+
'I solved a tough task today!',
|
| 41 |
+
"I'm feeling stuck on something.",
|
| 42 |
+
'Just need a breather.',
|
| 43 |
+
];
|
| 44 |
+
|
| 45 |
+
const JRPG_FRAME_STYLE: React.CSSProperties = {
|
| 46 |
+
backgroundColor: 'rgba(20, 36, 54, 0.94)',
|
| 47 |
+
boxShadow:
|
| 48 |
+
'0 0 0 2px #0a1420, inset 0 0 0 3px #4c7396, inset 1px 1px 0 4px #8db7dc, inset -1px -1px 0 4px #1a2c3f, inset 0 0 0 5px #0c1724, 0 10px 28px rgba(0, 0, 0, 0.75)',
|
| 49 |
+
};
|
| 50 |
+
|
| 51 |
+
export default function JRPGDialogueBox({
|
| 52 |
+
characterName,
|
| 53 |
+
text,
|
| 54 |
+
isStreaming = false,
|
| 55 |
+
isLoading = false,
|
| 56 |
+
choices,
|
| 57 |
+
toolCalls,
|
| 58 |
+
onSelectChoice,
|
| 59 |
+
onSendMessage,
|
| 60 |
+
onTypingStatusChange,
|
| 61 |
+
currentFloor,
|
| 62 |
+
bondTier,
|
| 63 |
+
satchelCount = 0,
|
| 64 |
+
isMuted = false,
|
| 65 |
+
onToggleMute,
|
| 66 |
+
onOpenProgress,
|
| 67 |
+
onOpenSatchel,
|
| 68 |
+
onOpenHistory,
|
| 69 |
+
onMinimize,
|
| 70 |
+
onClose,
|
| 71 |
+
className = '',
|
| 72 |
+
}: JRPGDialogueBoxProps) {
|
| 73 |
+
const [typewriterSlice, setTypewriterSlice] = useState('');
|
| 74 |
+
const [isTypewriterActive, setIsTypewriterActive] = useState(false);
|
| 75 |
+
const [highlightedIndex, setHighlightedIndex] = useState(0);
|
| 76 |
+
const [inputText, setInputText] = useState('');
|
| 77 |
+
const [isInputFocused, setIsInputFocused] = useState(false);
|
| 78 |
+
|
| 79 |
+
const prevTextRef = useRef<string>(text);
|
| 80 |
+
const wasStreamingRef = useRef<boolean>(false);
|
| 81 |
+
const timerRef = useRef<ReturnType<typeof setInterval> | null>(null);
|
| 82 |
+
const inputRef = useRef<HTMLInputElement | null>(null);
|
| 83 |
+
|
| 84 |
+
const isTyping = isStreaming || isTypewriterActive;
|
| 85 |
+
|
| 86 |
+
// Sync typing status with parent if listener provided
|
| 87 |
+
useEffect(() => {
|
| 88 |
+
onTypingStatusChange?.(isTyping);
|
| 89 |
+
}, [isTyping, onTypingStatusChange]);
|
| 90 |
+
|
| 91 |
+
// Determine active choices (dynamic from AI suggestions or 3 standard mockup choices)
|
| 92 |
+
const activeChoices = useMemo(() => {
|
| 93 |
+
if (Array.isArray(choices) && choices.length > 0) {
|
| 94 |
+
return choices.slice(0, 4);
|
| 95 |
+
}
|
| 96 |
+
return DEFAULT_JRPG_CHOICES;
|
| 97 |
+
}, [choices]);
|
| 98 |
+
|
| 99 |
+
// Clamp highlighted index during render without an effect
|
| 100 |
+
const safeHighlightedIndex =
|
| 101 |
+
highlightedIndex < activeChoices.length ? highlightedIndex : 0;
|
| 102 |
+
|
| 103 |
+
// The actual text displayed: animated typewriter slice only for non-streamed active typing, else directly `text`
|
| 104 |
+
const displayedText = !isStreaming && isTypewriterActive ? typewriterSlice : text;
|
| 105 |
+
|
| 106 |
+
// Handle Typewriter Animation
|
| 107 |
+
useEffect(() => {
|
| 108 |
+
if (isStreaming) {
|
| 109 |
+
if (timerRef.current) {
|
| 110 |
+
clearInterval(timerRef.current);
|
| 111 |
+
timerRef.current = null;
|
| 112 |
+
}
|
| 113 |
+
wasStreamingRef.current = true;
|
| 114 |
+
prevTextRef.current = text;
|
| 115 |
+
return;
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
// Stream just ended: smoothly retain complete text without typewriter rewinding or flashing
|
| 119 |
+
if (wasStreamingRef.current) {
|
| 120 |
+
wasStreamingRef.current = false;
|
| 121 |
+
prevTextRef.current = text;
|
| 122 |
+
if (timerRef.current) {
|
| 123 |
+
clearInterval(timerRef.current);
|
| 124 |
+
timerRef.current = null;
|
| 125 |
+
}
|
| 126 |
+
return;
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
if (text !== prevTextRef.current && !isLoading) {
|
| 130 |
+
prevTextRef.current = text;
|
| 131 |
+
|
| 132 |
+
if (!text) {
|
| 133 |
+
if (timerRef.current) {
|
| 134 |
+
clearInterval(timerRef.current);
|
| 135 |
+
timerRef.current = null;
|
| 136 |
+
}
|
| 137 |
+
return;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
if (timerRef.current) {
|
| 141 |
+
clearInterval(timerRef.current);
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
let charIndex = 0;
|
| 145 |
+
const intervalId = setInterval(() => {
|
| 146 |
+
charIndex++;
|
| 147 |
+
setTypewriterSlice(text.slice(0, charIndex));
|
| 148 |
+
setIsTypewriterActive(true);
|
| 149 |
+
if (charIndex >= text.length) {
|
| 150 |
+
clearInterval(intervalId);
|
| 151 |
+
timerRef.current = null;
|
| 152 |
+
setIsTypewriterActive(false);
|
| 153 |
+
}
|
| 154 |
+
}, 20);
|
| 155 |
+
timerRef.current = intervalId;
|
| 156 |
+
|
| 157 |
+
return () => {
|
| 158 |
+
clearInterval(intervalId);
|
| 159 |
+
timerRef.current = null;
|
| 160 |
+
setIsTypewriterActive(false);
|
| 161 |
+
};
|
| 162 |
+
}
|
| 163 |
+
}, [text, isLoading, isStreaming]);
|
| 164 |
+
|
| 165 |
+
const handleSkipTyping = useCallback(() => {
|
| 166 |
+
if (timerRef.current) {
|
| 167 |
+
clearInterval(timerRef.current);
|
| 168 |
+
timerRef.current = null;
|
| 169 |
+
}
|
| 170 |
+
setIsTypewriterActive(false);
|
| 171 |
+
}, []);
|
| 172 |
+
|
| 173 |
+
const handleSendInput = () => {
|
| 174 |
+
const trimmed = inputText.trim();
|
| 175 |
+
if (!trimmed || isLoading || isStreaming) return;
|
| 176 |
+
onSendMessage(trimmed);
|
| 177 |
+
setInputText('');
|
| 178 |
+
};
|
| 179 |
+
|
| 180 |
+
const handleFormSubmit = (e: React.FormEvent) => {
|
| 181 |
+
e.preventDefault();
|
| 182 |
+
handleSendInput();
|
| 183 |
+
};
|
| 184 |
+
|
| 185 |
+
// Keyboard navigation for choices (1-4, ArrowUp, ArrowDown, Enter, Esc)
|
| 186 |
+
useEffect(() => {
|
| 187 |
+
const handleKeyDown = (e: KeyboardEvent) => {
|
| 188 |
+
if (e.key === 'Escape' && onClose) {
|
| 189 |
+
e.preventDefault();
|
| 190 |
+
onClose();
|
| 191 |
+
return;
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
// If typing inside the free-form text input, ignore selection hotkeys
|
| 195 |
+
if (isInputFocused) return;
|
| 196 |
+
|
| 197 |
+
if (e.key >= '1' && e.key <= String(activeChoices.length)) {
|
| 198 |
+
const idx = parseInt(e.key, 10) - 1;
|
| 199 |
+
if (activeChoices[idx] && !isLoading && !isStreaming) {
|
| 200 |
+
e.preventDefault();
|
| 201 |
+
onSelectChoice(activeChoices[idx]);
|
| 202 |
+
}
|
| 203 |
+
return;
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
if (e.key === 'ArrowUp') {
|
| 207 |
+
e.preventDefault();
|
| 208 |
+
setHighlightedIndex((prev) => (prev - 1 + activeChoices.length) % activeChoices.length);
|
| 209 |
+
return;
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
if (e.key === 'ArrowDown') {
|
| 213 |
+
e.preventDefault();
|
| 214 |
+
setHighlightedIndex((prev) => (prev + 1) % activeChoices.length);
|
| 215 |
+
return;
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
if (e.key === 'Enter') {
|
| 219 |
+
if (!isLoading && !isStreaming && activeChoices[safeHighlightedIndex]) {
|
| 220 |
+
e.preventDefault();
|
| 221 |
+
onSelectChoice(activeChoices[safeHighlightedIndex]);
|
| 222 |
+
}
|
| 223 |
+
return;
|
| 224 |
+
}
|
| 225 |
+
|
| 226 |
+
if (e.key === ' ' && isTyping) {
|
| 227 |
+
e.preventDefault();
|
| 228 |
+
handleSkipTyping();
|
| 229 |
+
}
|
| 230 |
+
};
|
| 231 |
+
|
| 232 |
+
window.addEventListener('keydown', handleKeyDown);
|
| 233 |
+
return () => window.removeEventListener('keydown', handleKeyDown);
|
| 234 |
+
}, [
|
| 235 |
+
isInputFocused,
|
| 236 |
+
activeChoices,
|
| 237 |
+
safeHighlightedIndex,
|
| 238 |
+
isLoading,
|
| 239 |
+
isStreaming,
|
| 240 |
+
isTyping,
|
| 241 |
+
onSelectChoice,
|
| 242 |
+
handleSkipTyping,
|
| 243 |
+
onClose,
|
| 244 |
+
]);
|
| 245 |
+
|
| 246 |
+
// Formatter for *actions*
|
| 247 |
+
const renderFormattedDialogue = (raw: string) => {
|
| 248 |
+
const parts = raw.split(/(\*[^*]+\*)/g);
|
| 249 |
+
return parts.map((part, index) => {
|
| 250 |
+
if (part.startsWith('*') && part.endsWith('*')) {
|
| 251 |
+
return (
|
| 252 |
+
<span key={index} className="text-[#f3cb65] italic font-semibold mr-1 inline-block">
|
| 253 |
+
{part}
|
| 254 |
+
</span>
|
| 255 |
+
);
|
| 256 |
+
}
|
| 257 |
+
return <span key={index}>{part}</span>;
|
| 258 |
+
});
|
| 259 |
+
};
|
| 260 |
+
|
| 261 |
+
return (
|
| 262 |
+
<div className={`relative flex flex-col gap-2 w-full ${className}`}>
|
| 263 |
+
{/* 1. TOP BOX: Main JRPG Dialogue Frame */}
|
| 264 |
+
<div
|
| 265 |
+
onClick={handleSkipTyping}
|
| 266 |
+
className="relative w-full rounded-md sm:rounded-lg text-white pt-3.5 pb-3.5 pr-3.5 pl-8 sm:pt-5 sm:pb-5 sm:pr-5 sm:pl-14 md:pl-16 lg:pl-18 flex flex-col gap-2.5 backdrop-blur-md transition-all select-none cursor-pointer"
|
| 267 |
+
style={JRPG_FRAME_STYLE}
|
| 268 |
+
>
|
| 269 |
+
{/* Floating Retro HUD Controls above dialogue box */}
|
| 270 |
+
<div
|
| 271 |
+
className="absolute -top-7 right-1 flex items-center gap-1 sm:gap-1.5 z-30"
|
| 272 |
+
onClick={(e) => e.stopPropagation()}
|
| 273 |
+
>
|
| 274 |
+
{/* Spire Journey Progress */}
|
| 275 |
+
{onOpenProgress && (
|
| 276 |
+
<button
|
| 277 |
+
type="button"
|
| 278 |
+
onClick={onOpenProgress}
|
| 279 |
+
className="px-2 py-0.5 bg-[#101e2e]/90 hover:bg-[#1f3750] border border-[#3e6080]/80 hover:border-[#67b1ec] rounded text-[10px] sm:text-[11px] font-mono font-bold text-[#8cb4db] hover:text-white transition-all cursor-pointer flex items-center gap-1 shadow-md"
|
| 280 |
+
title="Spire Tower Road (Floor Progress)"
|
| 281 |
+
>
|
| 282 |
+
<Castle className="w-3 h-3 text-amber-400" />
|
| 283 |
+
<span>{currentFloor}/150 LC</span>
|
| 284 |
+
</button>
|
| 285 |
+
)}
|
| 286 |
+
|
| 287 |
+
{/* Royal Satchel */}
|
| 288 |
+
{onOpenSatchel && (
|
| 289 |
+
<button
|
| 290 |
+
type="button"
|
| 291 |
+
onClick={onOpenSatchel}
|
| 292 |
+
className="px-2 py-0.5 bg-[#101e2e]/90 hover:bg-[#1f3750] border border-[#3e6080]/80 hover:border-[#67b1ec] rounded text-[10px] sm:text-[11px] font-mono font-bold text-[#8cb4db] hover:text-white transition-all cursor-pointer flex items-center gap-1 shadow-md"
|
| 293 |
+
title="Open Royal Satchel"
|
| 294 |
+
>
|
| 295 |
+
<Scroll className="w-3 h-3 text-amber-400" />
|
| 296 |
+
<span className="hidden sm:inline">Satchel</span>
|
| 297 |
+
{satchelCount > 0 && (
|
| 298 |
+
<span className="text-[9px] text-[#f3cb65]">({satchelCount})</span>
|
| 299 |
+
)}
|
| 300 |
+
</button>
|
| 301 |
+
)}
|
| 302 |
+
|
| 303 |
+
{/* Transcript History */}
|
| 304 |
+
{onOpenHistory && (
|
| 305 |
+
<button
|
| 306 |
+
type="button"
|
| 307 |
+
onClick={onOpenHistory}
|
| 308 |
+
className="px-2 py-0.5 bg-[#101e2e]/90 hover:bg-[#1f3750] border border-[#3e6080]/80 hover:border-[#67b1ec] rounded text-[10px] sm:text-[11px] font-mono font-bold text-[#8cb4db] hover:text-white transition-all cursor-pointer flex items-center gap-1 shadow-md"
|
| 309 |
+
title="Dialogue Transcript"
|
| 310 |
+
>
|
| 311 |
+
<History className="w-3 h-3 text-[#8cb4db]" />
|
| 312 |
+
<span className="hidden sm:inline">Log</span>
|
| 313 |
+
</button>
|
| 314 |
+
)}
|
| 315 |
+
|
| 316 |
+
{/* Audio Mute Toggle */}
|
| 317 |
+
{onToggleMute && (
|
| 318 |
+
<button
|
| 319 |
+
type="button"
|
| 320 |
+
onClick={onToggleMute}
|
| 321 |
+
className="p-1 bg-[#101e2e]/90 hover:bg-[#1f3750] border border-[#3e6080]/80 hover:border-[#67b1ec] rounded text-[#8cb4db] hover:text-white transition-all cursor-pointer shadow-md"
|
| 322 |
+
title={isMuted ? 'Unmute Audio' : 'Mute Audio'}
|
| 323 |
+
>
|
| 324 |
+
{isMuted ? <VolumeX className="w-3 h-3" /> : <Volume2 className="w-3 h-3" />}
|
| 325 |
+
</button>
|
| 326 |
+
)}
|
| 327 |
+
|
| 328 |
+
{/* Minimize Button */}
|
| 329 |
+
{onMinimize && (
|
| 330 |
+
<button
|
| 331 |
+
type="button"
|
| 332 |
+
onClick={onMinimize}
|
| 333 |
+
className="p-1 bg-[#101e2e]/90 hover:bg-[#1f3750] border border-[#3e6080]/80 hover:border-[#67b1ec] rounded text-[#8cb4db] hover:text-white transition-all cursor-pointer shadow-md"
|
| 334 |
+
title="Minimize to Taskbar"
|
| 335 |
+
>
|
| 336 |
+
<Minus className="w-3 h-3" />
|
| 337 |
+
</button>
|
| 338 |
+
)}
|
| 339 |
+
|
| 340 |
+
{/* Close Window */}
|
| 341 |
+
{onClose && (
|
| 342 |
+
<button
|
| 343 |
+
type="button"
|
| 344 |
+
onClick={onClose}
|
| 345 |
+
className="p-1 bg-[#101e2e]/90 hover:bg-rose-900/70 border border-[#3e6080]/80 hover:border-rose-400 rounded text-[#8cb4db] hover:text-rose-200 transition-all cursor-pointer shadow-md"
|
| 346 |
+
title="Leave Parlor (Esc)"
|
| 347 |
+
>
|
| 348 |
+
<X className="w-3 h-3" />
|
| 349 |
+
</button>
|
| 350 |
+
)}
|
| 351 |
+
</div>
|
| 352 |
+
|
| 353 |
+
{/* Nameplate: -Princess Aurelia- */}
|
| 354 |
+
<div className="flex items-center gap-2">
|
| 355 |
+
<span className="font-mono text-sm sm:text-base font-bold text-[#f3cb65] tracking-wide drop-shadow-[0_1px_2px_rgba(0,0,0,0.9)]">
|
| 356 |
+
-{characterName || 'Princess Aurelia'}-
|
| 357 |
+
</span>
|
| 358 |
+
{bondTier && (
|
| 359 |
+
<span className="hidden md:inline-block text-[9px] font-mono text-[#8cb4db] bg-[#101d2c]/80 border border-[#3e6080]/60 px-1.5 py-0.2 rounded uppercase tracking-wider">
|
| 360 |
+
{bondTier}
|
| 361 |
+
</span>
|
| 362 |
+
)}
|
| 363 |
+
</div>
|
| 364 |
+
|
| 365 |
+
{/* Dialogue Body Text */}
|
| 366 |
+
<div className="min-h-[48px] sm:min-h-[54px] flex flex-col justify-start">
|
| 367 |
+
{isLoading ? (
|
| 368 |
+
<div className="flex items-center gap-2 py-1 text-xs sm:text-sm font-mono text-[#8cb4db]">
|
| 369 |
+
<span className="inline-block w-2 h-2 bg-[#f3cb65] rounded-full animate-ping" />
|
| 370 |
+
<span>{characterName || 'Princess Aurelia'} is attuning the crystal relay...</span>
|
| 371 |
+
</div>
|
| 372 |
+
) : (
|
| 373 |
+
<div className="font-mono text-xs sm:text-sm md:text-[15px] leading-relaxed text-[#e6edf4] select-text">
|
| 374 |
+
{renderFormattedDialogue(displayedText)}
|
| 375 |
+
{isTyping && (
|
| 376 |
+
<span className="inline-block w-1.5 h-3.5 bg-[#f3cb65] ml-1 animate-pulse align-middle" />
|
| 377 |
+
)}
|
| 378 |
+
</div>
|
| 379 |
+
)}
|
| 380 |
+
|
| 381 |
+
{/* Tool Call Badges */}
|
| 382 |
+
{toolCalls && toolCalls.length > 0 && !isLoading && (
|
| 383 |
+
<div className="mt-2 flex flex-wrap gap-1.5 select-none">
|
| 384 |
+
{toolCalls.map((tc, idx) => (
|
| 385 |
+
<span
|
| 386 |
+
key={idx}
|
| 387 |
+
className="px-2 py-0.5 rounded bg-[#102438] border border-[#44729b] text-[10px] font-mono font-bold text-[#bfe1ff] flex items-center gap-1"
|
| 388 |
+
>
|
| 389 |
+
<Sparkles className="w-2.5 h-2.5 text-[#f3cb65]" />
|
| 390 |
+
<span>Enchantment: {tc.name}</span>
|
| 391 |
+
</span>
|
| 392 |
+
))}
|
| 393 |
+
</div>
|
| 394 |
+
)}
|
| 395 |
+
</div>
|
| 396 |
+
|
| 397 |
+
{/* Numbered Choices: 1. [I solved a tough task today!], 2., 3. */}
|
| 398 |
+
<div className="flex flex-col gap-1 pt-1" onClick={(e) => e.stopPropagation()}>
|
| 399 |
+
{activeChoices.map((choice, idx) => {
|
| 400 |
+
const num = idx + 1;
|
| 401 |
+
const isHighlighted = safeHighlightedIndex === idx;
|
| 402 |
+
|
| 403 |
+
return (
|
| 404 |
+
<button
|
| 405 |
+
key={idx}
|
| 406 |
+
type="button"
|
| 407 |
+
disabled={isLoading || isStreaming}
|
| 408 |
+
onClick={() => onSelectChoice(choice)}
|
| 409 |
+
onMouseEnter={() => setHighlightedIndex(idx)}
|
| 410 |
+
className={`w-full sm:max-w-[90%] md:max-w-[85%] text-left flex items-center gap-2 px-2.5 py-1 rounded-xs sm:rounded-sm transition-all select-none font-mono text-xs sm:text-sm disabled:opacity-40 disabled:cursor-not-allowed ${isHighlighted && !isLoading && !isStreaming
|
| 411 |
+
? 'bg-[#1c3e61]/80 border border-[#4883b6]/80 shadow-[0_0_12px_rgba(72,131,182,0.25)] cursor-pointer'
|
| 412 |
+
: 'border border-transparent hover:bg-[#1c3e61]/35 cursor-pointer'
|
| 413 |
+
}`}
|
| 414 |
+
>
|
| 415 |
+
<span
|
| 416 |
+
className={`font-bold shrink-0 ${isHighlighted ? 'text-[#e2ecf7]' : 'text-[#b4c8dc]'
|
| 417 |
+
}`}
|
| 418 |
+
>
|
| 419 |
+
{num}.
|
| 420 |
+
</span>
|
| 421 |
+
<span
|
| 422 |
+
className={`truncate font-medium ${isHighlighted ? 'text-[#f3cb65]' : 'text-[#dde7f2]'
|
| 423 |
+
}`}
|
| 424 |
+
>
|
| 425 |
+
[{choice}]
|
| 426 |
+
</span>
|
| 427 |
+
</button>
|
| 428 |
+
);
|
| 429 |
+
})}
|
| 430 |
+
</div>
|
| 431 |
+
</div>
|
| 432 |
+
|
| 433 |
+
{/* 2. BOTTOM BOX: Retro Command-Prompt Input Box */}
|
| 434 |
+
<form
|
| 435 |
+
onSubmit={handleFormSubmit}
|
| 436 |
+
onClick={(e) => e.stopPropagation()}
|
| 437 |
+
className="w-full rounded-md sm:rounded-lg text-white py-2 sm:py-2.5 pr-3 sm:pr-4 pl-8 sm:pl-14 md:pl-16 lg:pl-18 flex items-center gap-2 backdrop-blur-md transition-all select-none"
|
| 438 |
+
style={JRPG_FRAME_STYLE}
|
| 439 |
+
>
|
| 440 |
+
{/* Command Prompt Glyph > */}
|
| 441 |
+
<span className="font-mono text-sm sm:text-base font-bold text-[#e2ecf7] select-none pl-0.5 shrink-0">
|
| 442 |
+
>
|
| 443 |
+
</span>
|
| 444 |
+
|
| 445 |
+
{/* Bracketed Input Field [ Speak with Princess Aurelia... ] */}
|
| 446 |
+
<div className="flex-1 flex items-center bg-[#101e2e]/90 border border-[#3b5d7d] rounded px-2.5 py-1 focus-within:border-[#67b1ec] focus-within:ring-1 focus-within:ring-[#67b1ec]/40 shadow-inner">
|
| 447 |
+
<span className="text-[#f3cb65] font-mono text-xs sm:text-sm select-none mr-1.5 shrink-0">
|
| 448 |
+
[
|
| 449 |
+
</span>
|
| 450 |
+
<input
|
| 451 |
+
ref={inputRef}
|
| 452 |
+
type="text"
|
| 453 |
+
value={inputText}
|
| 454 |
+
onChange={(e) => setInputText(e.target.value)}
|
| 455 |
+
onFocus={() => setIsInputFocused(true)}
|
| 456 |
+
onBlur={() => setIsInputFocused(false)}
|
| 457 |
+
disabled={isLoading || isStreaming}
|
| 458 |
+
placeholder={`Speak with ${characterName || 'Princess Aurelia'}...`}
|
| 459 |
+
className="flex-1 bg-transparent border-none text-[#e2ecf7] placeholder-[#f3cb65]/70 font-mono text-xs sm:text-sm focus:outline-none disabled:opacity-50 disabled:cursor-not-allowed"
|
| 460 |
+
/>
|
| 461 |
+
<span className="text-[#f3cb65] font-mono text-xs sm:text-sm select-none ml-1.5 shrink-0">
|
| 462 |
+
]
|
| 463 |
+
</span>
|
| 464 |
+
</div>
|
| 465 |
+
|
| 466 |
+
{/* Distinct 3D Raised Retro Button [ Send ] */}
|
| 467 |
+
<button
|
| 468 |
+
type="submit"
|
| 469 |
+
disabled={isLoading || isStreaming || !inputText.trim()}
|
| 470 |
+
className="bg-[#34597b] hover:bg-[#3f6990] active:bg-[#2b4c6e] disabled:opacity-40 disabled:cursor-not-allowed border border-[#5c8cb5] hover:border-[#8db7dc] rounded px-3 sm:px-4 py-1 text-xs sm:text-sm font-mono font-bold text-white transition-all cursor-pointer shadow-md select-none shrink-0 flex items-center"
|
| 471 |
+
>
|
| 472 |
+
<span className="text-[#f3cb65]">[</span>
|
| 473 |
+
<span className="text-white px-1">Send</span>
|
| 474 |
+
<span className="text-[#f3cb65]">]</span>
|
| 475 |
+
</button>
|
| 476 |
+
</form>
|
| 477 |
+
</div>
|
| 478 |
+
);
|
| 479 |
+
}
|
algospaced-ui/src/features/companion/components/PrincessChamber.tsx
CHANGED
|
@@ -1,23 +1,33 @@
|
|
| 1 |
import { useState, useEffect, useMemo, useCallback } from 'react';
|
| 2 |
import { useCompanionStore, companionStore } from '../store/useCompanionStore';
|
| 3 |
import CharacterStage from './CharacterStage';
|
| 4 |
-
import
|
| 5 |
-
import ChoiceChips from './ChoiceChips';
|
| 6 |
import SpireProgressModal from './SpireProgressModal';
|
| 7 |
import RoyalSatchelModal from './RoyalSatchelModal';
|
|
|
|
| 8 |
import {
|
| 9 |
-
Sparkles,
|
| 10 |
-
Castle,
|
| 11 |
-
Scroll,
|
| 12 |
-
Volume2,
|
| 13 |
-
VolumeX,
|
| 14 |
-
RotateCcw,
|
| 15 |
History,
|
|
|
|
| 16 |
X,
|
| 17 |
} from 'lucide-react';
|
| 18 |
import { isAudioMuted, setAudioMuted } from '../../../utils/rpgAudio';
|
| 19 |
|
| 20 |
-
export
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
const store = useCompanionStore();
|
| 22 |
const [muted, setMuted] = useState(isAudioMuted());
|
| 23 |
const [showProgressModal, setShowProgressModal] = useState(false);
|
|
@@ -30,192 +40,205 @@ export default function PrincessChamber() {
|
|
| 30 |
companionStore.triggerProactiveGreeting();
|
| 31 |
}, []);
|
| 32 |
|
| 33 |
-
const
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
const newMuted = !muted;
|
| 35 |
setMuted(newMuted);
|
| 36 |
setAudioMuted(newMuted);
|
| 37 |
-
};
|
| 38 |
|
| 39 |
-
const
|
| 40 |
if (window.confirm('Clear conversation transcript with Princess Aurelia?')) {
|
| 41 |
companionStore.clearTranscript();
|
| 42 |
}
|
| 43 |
-
};
|
| 44 |
|
| 45 |
const handleTypingStatusChange = useCallback((isTyping: boolean) => {
|
| 46 |
companionStore.setIsTyping(isTyping);
|
| 47 |
}, []);
|
| 48 |
|
| 49 |
-
// Extract latest princess turn for
|
| 50 |
const latestPrincessTurn = useMemo(() => {
|
| 51 |
const turns = [...store.transcript].reverse();
|
| 52 |
return turns.find((t) => t.sender === 'princess') || store.transcript[0];
|
| 53 |
}, [store.transcript]);
|
| 54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
return (
|
| 57 |
-
<div
|
| 58 |
-
{
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
<h3 className="font-headline-md font-bold text-xs sm:text-sm text-ink-black m-0 truncate">
|
| 65 |
-
{store.companionSettings.name || 'Princess Aurelia'}
|
| 66 |
-
</h3>
|
| 67 |
-
</div>
|
| 68 |
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
-
{/*
|
| 75 |
-
<
|
| 76 |
-
|
| 77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
</div>
|
| 79 |
|
| 80 |
-
{/* Right
|
| 81 |
-
<div className="flex items-center gap-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
className="px-2.5 py-1 bg-amber-100 hover:bg-amber-200 border-[2px] border-ink-black rounded font-bold text-[11px] text-ink-black cursor-pointer shadow-[1.5px_1.5px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none transition-all flex items-center gap-1.5"
|
| 87 |
-
title="View Spire Journey Progress"
|
| 88 |
-
>
|
| 89 |
-
<Castle className="w-3.5 h-3.5 text-indigo-700" />
|
| 90 |
-
<span className="font-arcade text-[9px] text-indigo-950">
|
| 91 |
-
{store.currentFloor}/150 LC
|
| 92 |
-
</span>
|
| 93 |
-
</button>
|
| 94 |
-
|
| 95 |
-
{/* Royal Satchel (Letters & Spire Chronicles) */}
|
| 96 |
-
<button
|
| 97 |
-
type="button"
|
| 98 |
-
onClick={() => setShowSatchelModal(true)}
|
| 99 |
-
className="px-2.5 py-1 bg-white hover:bg-amber-50 border-[2px] border-ink-black rounded font-bold text-[11px] text-ink-black cursor-pointer shadow-[1.5px_1.5px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none transition-all flex items-center gap-1.5"
|
| 100 |
-
title="Open Royal Satchel (Missives & Diary)"
|
| 101 |
-
>
|
| 102 |
-
<Scroll className="w-3.5 h-3.5 text-amber-700" />
|
| 103 |
-
<span className="hidden md:inline">Satchel</span>
|
| 104 |
-
{store.unlockedLetters.length > 0 && (
|
| 105 |
-
<span className="w-4 h-4 rounded-full bg-amber-400 text-ink-black text-[9px] font-extrabold flex items-center justify-center border border-ink-black">
|
| 106 |
-
{store.unlockedLetters.length}
|
| 107 |
-
</span>
|
| 108 |
-
)}
|
| 109 |
-
</button>
|
| 110 |
-
|
| 111 |
-
{/* History Transcript Drawer */}
|
| 112 |
-
<button
|
| 113 |
-
type="button"
|
| 114 |
-
onClick={() => setShowHistoryModal(true)}
|
| 115 |
-
className="p-1.5 bg-white hover:bg-slate-100 border-[2px] border-ink-black rounded text-ink-black cursor-pointer shadow-[1.5px_1.5px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none transition-all"
|
| 116 |
-
title="View Transcript History"
|
| 117 |
-
>
|
| 118 |
-
<History className="w-3.5 h-3.5 text-slate-700" />
|
| 119 |
-
</button>
|
| 120 |
-
|
| 121 |
-
{/* Audio Mute Toggle */}
|
| 122 |
-
<button
|
| 123 |
-
type="button"
|
| 124 |
-
onClick={toggleMute}
|
| 125 |
-
className={`p-1.5 border-[2px] border-ink-black rounded text-ink-black cursor-pointer shadow-[1.5px_1.5px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none transition-all ${
|
| 126 |
-
muted ? 'bg-slate-200 opacity-80' : 'bg-[#FFE24C] hover:bg-yellow-300'
|
| 127 |
-
}`}
|
| 128 |
-
title={muted ? 'Unmute Audio' : 'Mute Audio'}
|
| 129 |
>
|
| 130 |
-
|
| 131 |
-
</
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
</div>
|
| 133 |
</div>
|
| 134 |
|
| 135 |
-
{/* Main Visual Novel Character Stage */}
|
| 136 |
-
<div className="flex-1 flex flex-col items-center justify-start gap-3 sm:gap-4 p-3 sm:p-5 overflow-y-auto custom-scrollbar min-h-0 relative">
|
| 137 |
-
<CharacterStage
|
| 138 |
-
emotion={store.activeEmotion}
|
| 139 |
-
floor={store.currentFloor}
|
| 140 |
-
rhythm={store.currentRhythm}
|
| 141 |
-
activity={store.currentActivity}
|
| 142 |
-
isLoading={store.isLoading}
|
| 143 |
-
/>
|
| 144 |
-
|
| 145 |
-
{/* Character Dialogue Bubble */}
|
| 146 |
-
<DialogueBubble
|
| 147 |
-
text={latestPrincessTurn?.text || 'I believe in you, champion!'}
|
| 148 |
-
characterName={store.companionSettings.name}
|
| 149 |
-
emotion={store.activeEmotion}
|
| 150 |
-
isLoading={store.isLoading}
|
| 151 |
-
isStreaming={latestPrincessTurn?.isStreaming}
|
| 152 |
-
toolCalls={latestPrincessTurn?.toolCalls}
|
| 153 |
-
onTypingStatusChange={handleTypingStatusChange}
|
| 154 |
-
/>
|
| 155 |
-
</div>
|
| 156 |
-
|
| 157 |
-
{/* Bottom Interactive Choice Chips & Free-Form Input */}
|
| 158 |
-
<ChoiceChips
|
| 159 |
-
suggestions={latestPrincessTurn?.choiceSuggestions}
|
| 160 |
-
isLoading={store.isLoading}
|
| 161 |
-
onSendMessage={(msg) => companionStore.sendMessage(msg)}
|
| 162 |
-
placeholder={`Speak with ${store.companionSettings.name || 'Princess Aurelia'}...`}
|
| 163 |
-
/>
|
| 164 |
-
|
| 165 |
{/* Popover 1: Spire Journey Progress Modal */}
|
| 166 |
{showProgressModal && (
|
| 167 |
-
<
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
|
|
|
|
|
|
| 172 |
)}
|
| 173 |
|
| 174 |
{/* Popover 2: Royal Satchel (Missives, Diary & Codex) */}
|
| 175 |
{showSatchelModal && (
|
| 176 |
-
<
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
|
|
|
|
|
|
| 186 |
)}
|
| 187 |
|
| 188 |
-
{/* Popover 3:
|
| 189 |
{showHistoryModal && (
|
| 190 |
<div
|
| 191 |
-
className="
|
| 192 |
onClick={() => setShowHistoryModal(false)}
|
| 193 |
>
|
| 194 |
<div
|
| 195 |
-
className="bg-[#
|
| 196 |
onClick={(e) => e.stopPropagation()}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 197 |
>
|
| 198 |
-
|
|
|
|
| 199 |
<div className="flex items-center gap-2">
|
| 200 |
-
<History className="w-4 h-4 text-
|
| 201 |
-
<h4 className="font-
|
| 202 |
Dialogue Transcript ({store.transcript.length} turns)
|
| 203 |
</h4>
|
| 204 |
</div>
|
| 205 |
<div className="flex items-center gap-1">
|
| 206 |
<button
|
| 207 |
type="button"
|
| 208 |
-
onClick={
|
| 209 |
-
className="
|
| 210 |
title="Clear Chat History"
|
| 211 |
>
|
| 212 |
-
<RotateCcw className="w-3
|
| 213 |
<span>Clear</span>
|
| 214 |
</button>
|
| 215 |
<button
|
| 216 |
type="button"
|
| 217 |
onClick={() => setShowHistoryModal(false)}
|
| 218 |
-
className="p-1 hover:bg-
|
| 219 |
title="Close"
|
| 220 |
>
|
| 221 |
<X className="w-4 h-4" />
|
|
@@ -223,20 +246,20 @@ export default function PrincessChamber() {
|
|
| 223 |
</div>
|
| 224 |
</div>
|
| 225 |
|
| 226 |
-
|
|
|
|
| 227 |
{store.transcript.map((t, idx) => (
|
| 228 |
<div
|
| 229 |
key={t.id || idx}
|
| 230 |
-
className={`p-2.5 rounded-lg border
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
}`}
|
| 235 |
>
|
| 236 |
-
<div className="text-[10px] font-bold
|
| 237 |
{t.sender === 'princess' ? store.companionSettings.name : 'Hero'}
|
| 238 |
</div>
|
| 239 |
-
<p className="
|
| 240 |
{t.text}
|
| 241 |
</p>
|
| 242 |
</div>
|
|
|
|
| 1 |
import { useState, useEffect, useMemo, useCallback } from 'react';
|
| 2 |
import { useCompanionStore, companionStore } from '../store/useCompanionStore';
|
| 3 |
import CharacterStage from './CharacterStage';
|
| 4 |
+
import JRPGDialogueBox from './JRPGDialogueBox';
|
|
|
|
| 5 |
import SpireProgressModal from './SpireProgressModal';
|
| 6 |
import RoyalSatchelModal from './RoyalSatchelModal';
|
| 7 |
+
import { useOSStore } from '../../../stores/useOSStore';
|
| 8 |
import {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
History,
|
| 10 |
+
RotateCcw,
|
| 11 |
X,
|
| 12 |
} from 'lucide-react';
|
| 13 |
import { isAudioMuted, setAudioMuted } from '../../../utils/rpgAudio';
|
| 14 |
|
| 15 |
+
export interface PrincessChamberProps {
|
| 16 |
+
onClose?: () => void;
|
| 17 |
+
onMinimize?: () => void;
|
| 18 |
+
isActive?: boolean;
|
| 19 |
+
onFocus?: () => void;
|
| 20 |
+
zIndex?: number;
|
| 21 |
+
isMobile?: boolean;
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
export default function PrincessChamber({
|
| 25 |
+
onClose,
|
| 26 |
+
onMinimize,
|
| 27 |
+
isActive = true,
|
| 28 |
+
onFocus,
|
| 29 |
+
zIndex,
|
| 30 |
+
}: PrincessChamberProps) {
|
| 31 |
const store = useCompanionStore();
|
| 32 |
const [muted, setMuted] = useState(isAudioMuted());
|
| 33 |
const [showProgressModal, setShowProgressModal] = useState(false);
|
|
|
|
| 40 |
companionStore.triggerProactiveGreeting();
|
| 41 |
}, []);
|
| 42 |
|
| 43 |
+
const handleClose = useCallback(() => {
|
| 44 |
+
if (onClose) {
|
| 45 |
+
onClose();
|
| 46 |
+
} else {
|
| 47 |
+
useOSStore.getState().closeWindow('companion');
|
| 48 |
+
}
|
| 49 |
+
}, [onClose]);
|
| 50 |
+
|
| 51 |
+
const handleMinimize = useCallback(() => {
|
| 52 |
+
if (onMinimize) {
|
| 53 |
+
onMinimize();
|
| 54 |
+
} else {
|
| 55 |
+
useOSStore.getState().minimizeWindow('companion');
|
| 56 |
+
}
|
| 57 |
+
}, [onMinimize]);
|
| 58 |
+
|
| 59 |
+
const handleFocus = useCallback(() => {
|
| 60 |
+
if (onFocus) {
|
| 61 |
+
onFocus();
|
| 62 |
+
} else {
|
| 63 |
+
useOSStore.getState().setActiveWindow('companion');
|
| 64 |
+
}
|
| 65 |
+
}, [onFocus]);
|
| 66 |
+
|
| 67 |
+
const toggleMute = useCallback(() => {
|
| 68 |
const newMuted = !muted;
|
| 69 |
setMuted(newMuted);
|
| 70 |
setAudioMuted(newMuted);
|
| 71 |
+
}, [muted]);
|
| 72 |
|
| 73 |
+
const handleClearTranscript = useCallback(() => {
|
| 74 |
if (window.confirm('Clear conversation transcript with Princess Aurelia?')) {
|
| 75 |
companionStore.clearTranscript();
|
| 76 |
}
|
| 77 |
+
}, []);
|
| 78 |
|
| 79 |
const handleTypingStatusChange = useCallback((isTyping: boolean) => {
|
| 80 |
companionStore.setIsTyping(isTyping);
|
| 81 |
}, []);
|
| 82 |
|
| 83 |
+
// Extract latest princess turn for dialogue display
|
| 84 |
const latestPrincessTurn = useMemo(() => {
|
| 85 |
const turns = [...store.transcript].reverse();
|
| 86 |
return turns.find((t) => t.sender === 'princess') || store.transcript[0];
|
| 87 |
}, [store.transcript]);
|
| 88 |
|
| 89 |
+
const defaultDialogue =
|
| 90 |
+
'Welcome back to the Spire Tower Parlor. How is your day going today? Are you making progress, or could you use a hand?';
|
| 91 |
+
|
| 92 |
+
const dialogueText = latestPrincessTurn
|
| 93 |
+
? latestPrincessTurn.isStreaming
|
| 94 |
+
? latestPrincessTurn.text
|
| 95 |
+
: (latestPrincessTurn.text || (store.isLoading ? '' : defaultDialogue))
|
| 96 |
+
: defaultDialogue;
|
| 97 |
+
|
| 98 |
+
// Preserve choices across in-flight streaming turns so options don't disappear or jump
|
| 99 |
+
const currentChoices = useMemo(() => {
|
| 100 |
+
if (latestPrincessTurn?.choiceSuggestions && latestPrincessTurn.choiceSuggestions.length > 0) {
|
| 101 |
+
return latestPrincessTurn.choiceSuggestions;
|
| 102 |
+
}
|
| 103 |
+
const previousWithChoices = [...store.transcript]
|
| 104 |
+
.reverse()
|
| 105 |
+
.find((t) => t.sender === 'princess' && t.choiceSuggestions && t.choiceSuggestions.length > 0);
|
| 106 |
+
return previousWithChoices?.choiceSuggestions;
|
| 107 |
+
}, [latestPrincessTurn, store.transcript]);
|
| 108 |
+
|
| 109 |
+
const currentZIndex = zIndex ?? (isActive ? 40 : 30);
|
| 110 |
|
| 111 |
return (
|
| 112 |
+
<div
|
| 113 |
+
onClick={handleFocus}
|
| 114 |
+
className="fixed inset-x-0 top-0 bottom-[40px] select-none pointer-events-none overflow-hidden font-sans"
|
| 115 |
+
style={{ zIndex: currentZIndex }}
|
| 116 |
+
>
|
| 117 |
+
{/* Subtle bottom vignette to frame the stage naturally over any desktop wallpaper */}
|
| 118 |
+
<div className="absolute inset-x-0 bottom-0 h-44 bg-gradient-to-t from-slate-950/35 via-slate-900/10 to-transparent pointer-events-none z-0" />
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
|
| 120 |
+
{/* Main JRPG Parlor Stage Container */}
|
| 121 |
+
<div className="relative w-full h-full flex flex-col justify-end pointer-events-none pb-2 sm:pb-3 px-2 sm:px-4 md:px-8">
|
| 122 |
+
{/* Invisible Parlor Stage Group (Princess Aurelia + Dialogue Box) */}
|
| 123 |
+
<div className="relative w-full max-w-5xl lg:max-w-6xl mx-auto flex items-end justify-start pointer-events-none">
|
| 124 |
+
{/* Left: Princess Aurelia (Overlaps the dialogue box slightly via negative margin) */}
|
| 125 |
+
<div className="relative z-30 shrink-0 pointer-events-auto -mr-6 sm:-mr-10 md:-mr-12 lg:-mr-14">
|
| 126 |
+
<CharacterStage
|
| 127 |
+
emotion={store.activeEmotion}
|
| 128 |
+
floor={store.currentFloor}
|
| 129 |
+
rhythm={store.currentRhythm}
|
| 130 |
+
activity={store.currentActivity}
|
| 131 |
+
isLoading={store.isLoading}
|
| 132 |
+
onClick={handleFocus}
|
| 133 |
+
/>
|
| 134 |
+
</div>
|
| 135 |
|
| 136 |
+
{/* Right: JRPG Dialogue Box Frame */}
|
| 137 |
+
<div className="relative z-20 flex-1 min-w-0 pointer-events-auto mb-1">
|
| 138 |
+
<JRPGDialogueBox
|
| 139 |
+
characterName={store.companionSettings.name || 'Princess Aurelia'}
|
| 140 |
+
emotion={store.activeEmotion}
|
| 141 |
+
text={dialogueText}
|
| 142 |
+
isStreaming={latestPrincessTurn?.isStreaming}
|
| 143 |
+
isLoading={store.isLoading}
|
| 144 |
+
choices={currentChoices}
|
| 145 |
+
toolCalls={latestPrincessTurn?.toolCalls}
|
| 146 |
+
onSelectChoice={(choice) => companionStore.sendMessage(choice)}
|
| 147 |
+
onSendMessage={(msg) => companionStore.sendMessage(msg)}
|
| 148 |
+
onTypingStatusChange={handleTypingStatusChange}
|
| 149 |
+
currentFloor={store.currentFloor}
|
| 150 |
+
bondTier={store.bondTier}
|
| 151 |
+
satchelCount={store.unlockedLetters.length}
|
| 152 |
+
isMuted={muted}
|
| 153 |
+
onToggleMute={toggleMute}
|
| 154 |
+
onOpenProgress={() => setShowProgressModal(true)}
|
| 155 |
+
onOpenSatchel={() => setShowSatchelModal(true)}
|
| 156 |
+
onOpenHistory={() => setShowHistoryModal(true)}
|
| 157 |
+
onMinimize={handleMinimize}
|
| 158 |
+
onClose={handleClose}
|
| 159 |
+
/>
|
| 160 |
+
</div>
|
| 161 |
</div>
|
| 162 |
|
| 163 |
+
{/* Bottom Right Corner Watermark */}
|
| 164 |
+
<div className="absolute bottom-1 right-3.5 pointer-events-none z-30 hidden md:flex flex-col items-center gap-0.5 opacity-65 select-none">
|
| 165 |
+
<svg
|
| 166 |
+
className="w-8 h-8 text-[#9cbcdb] drop-shadow-[0_0_6px_rgba(156,188,219,0.5)] rotate-6"
|
| 167 |
+
viewBox="0 0 24 24"
|
| 168 |
+
fill="currentColor"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
>
|
| 170 |
+
<path d="M12 2 C12 7.8 7.8 12 2 12 C7.8 12 12 16.2 12 22 C12 16.2 16.2 12 22 12 C16.2 12 12 7.8 12 2 Z" />
|
| 171 |
+
</svg>
|
| 172 |
+
<div className="font-mono text-[9px] text-[#7ba4c8] tracking-tight leading-tight text-center">
|
| 173 |
+
<div>AlgoSpaced (Beta)</div>
|
| 174 |
+
<div>Build Jun24 preview</div>
|
| 175 |
+
</div>
|
| 176 |
</div>
|
| 177 |
</div>
|
| 178 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 179 |
{/* Popover 1: Spire Journey Progress Modal */}
|
| 180 |
{showProgressModal && (
|
| 181 |
+
<div className="pointer-events-auto">
|
| 182 |
+
<SpireProgressModal
|
| 183 |
+
currentFloor={store.currentFloor}
|
| 184 |
+
totalSolved={store.totalSolved}
|
| 185 |
+
onClose={() => setShowProgressModal(false)}
|
| 186 |
+
/>
|
| 187 |
+
</div>
|
| 188 |
)}
|
| 189 |
|
| 190 |
{/* Popover 2: Royal Satchel (Missives, Diary & Codex) */}
|
| 191 |
{showSatchelModal && (
|
| 192 |
+
<div className="pointer-events-auto">
|
| 193 |
+
<RoyalSatchelModal
|
| 194 |
+
unlockedLetters={store.unlockedLetters}
|
| 195 |
+
spireChronicles={store.spireChronicles}
|
| 196 |
+
currentFloor={store.currentFloor}
|
| 197 |
+
heroCodex={store.heroCodex}
|
| 198 |
+
episodicEvents={store.episodicEvents}
|
| 199 |
+
recentToolTelemetry={store.recentToolTelemetry}
|
| 200 |
+
onRemoveCodexItem={companionStore.removeCodexItem}
|
| 201 |
+
onClose={() => setShowSatchelModal(false)}
|
| 202 |
+
/>
|
| 203 |
+
</div>
|
| 204 |
)}
|
| 205 |
|
| 206 |
+
{/* Popover 3: Retro Transcript History Drawer */}
|
| 207 |
{showHistoryModal && (
|
| 208 |
<div
|
| 209 |
+
className="fixed inset-0 z-50 bg-black/60 backdrop-blur-xs flex items-center justify-center p-3 sm:p-4 animate-in fade-in duration-200 pointer-events-auto"
|
| 210 |
onClick={() => setShowHistoryModal(false)}
|
| 211 |
>
|
| 212 |
<div
|
| 213 |
+
className="bg-[#142335] border-[3px] border-[#5a80a2] rounded-xl max-w-lg w-full h-[80%] max-h-[520px] shadow-[0_16px_40px_rgba(0,0,0,0.85)] flex flex-col overflow-hidden text-white"
|
| 214 |
onClick={(e) => e.stopPropagation()}
|
| 215 |
+
style={{
|
| 216 |
+
boxShadow:
|
| 217 |
+
'inset 0 0 0 1px #0a1420, inset 0 1px 0 rgba(255, 255, 255, 0.15), 0 16px 40px rgba(0, 0, 0, 0.85)',
|
| 218 |
+
}}
|
| 219 |
>
|
| 220 |
+
{/* Modal Header */}
|
| 221 |
+
<div className="bg-[#101b2a] border-b border-[#304f6f] px-4 py-2.5 flex items-center justify-between shrink-0">
|
| 222 |
<div className="flex items-center gap-2">
|
| 223 |
+
<History className="w-4 h-4 text-[#67b1ec]" />
|
| 224 |
+
<h4 className="font-mono font-bold text-xs sm:text-sm text-[#e6f0fa] m-0">
|
| 225 |
Dialogue Transcript ({store.transcript.length} turns)
|
| 226 |
</h4>
|
| 227 |
</div>
|
| 228 |
<div className="flex items-center gap-1">
|
| 229 |
<button
|
| 230 |
type="button"
|
| 231 |
+
onClick={handleClearTranscript}
|
| 232 |
+
className="px-2 py-0.5 bg-rose-950/60 hover:bg-rose-900 border border-rose-700/60 rounded text-[11px] font-mono font-bold text-rose-300 hover:text-white flex items-center gap-1 cursor-pointer mr-1 transition-colors"
|
| 233 |
title="Clear Chat History"
|
| 234 |
>
|
| 235 |
+
<RotateCcw className="w-3 h-3" />
|
| 236 |
<span>Clear</span>
|
| 237 |
</button>
|
| 238 |
<button
|
| 239 |
type="button"
|
| 240 |
onClick={() => setShowHistoryModal(false)}
|
| 241 |
+
className="p-1 hover:bg-[#203a55] rounded text-[#8cb4db] hover:text-white cursor-pointer transition-colors"
|
| 242 |
title="Close"
|
| 243 |
>
|
| 244 |
<X className="w-4 h-4" />
|
|
|
|
| 246 |
</div>
|
| 247 |
</div>
|
| 248 |
|
| 249 |
+
{/* Transcript Messages List */}
|
| 250 |
+
<div className="flex-1 p-3 sm:p-4 overflow-y-auto custom-scrollbar flex flex-col gap-2.5 bg-[#0e1824]/90">
|
| 251 |
{store.transcript.map((t, idx) => (
|
| 252 |
<div
|
| 253 |
key={t.id || idx}
|
| 254 |
+
className={`p-2.5 rounded-lg border font-mono text-xs max-w-[90%] shadow-md ${t.sender === 'princess'
|
| 255 |
+
? 'bg-[#182c42] border-[#3e6080] text-[#e6f0fa] self-start'
|
| 256 |
+
: 'bg-[#214365] border-[#5a8bb9] text-white self-end'
|
| 257 |
+
}`}
|
|
|
|
| 258 |
>
|
| 259 |
+
<div className="text-[10px] font-bold mb-1 text-[#f6d267]">
|
| 260 |
{t.sender === 'princess' ? store.companionSettings.name : 'Hero'}
|
| 261 |
</div>
|
| 262 |
+
<p className="font-medium m-0 leading-relaxed whitespace-pre-wrap select-text">
|
| 263 |
{t.text}
|
| 264 |
</p>
|
| 265 |
</div>
|
algospaced-ui/src/features/companion/components/PrincessToast.tsx
CHANGED
|
@@ -13,7 +13,6 @@ import {
|
|
| 13 |
} from 'lucide-react';
|
| 14 |
import {
|
| 15 |
playPopupChime,
|
| 16 |
-
playTypewriterBlip,
|
| 17 |
isAudioMuted,
|
| 18 |
setAudioMuted,
|
| 19 |
} from '../../../utils/rpgAudio';
|
|
@@ -55,9 +54,6 @@ export default function PrincessToast({ onOpenCompanionWindow }: PrincessToastPr
|
|
| 55 |
if (charIdx < lastTurn.text.length) {
|
| 56 |
charIdx++;
|
| 57 |
setDisplayedText(lastTurn.text.slice(0, charIdx));
|
| 58 |
-
if (charIdx % 2 === 0 && lastTurn.text[charIdx - 1] !== ' ') {
|
| 59 |
-
playTypewriterBlip(charIdx);
|
| 60 |
-
}
|
| 61 |
} else {
|
| 62 |
if (timerRef.current) clearInterval(timerRef.current);
|
| 63 |
setIsTyping(false);
|
|
|
|
| 13 |
} from 'lucide-react';
|
| 14 |
import {
|
| 15 |
playPopupChime,
|
|
|
|
| 16 |
isAudioMuted,
|
| 17 |
setAudioMuted,
|
| 18 |
} from '../../../utils/rpgAudio';
|
|
|
|
| 54 |
if (charIdx < lastTurn.text.length) {
|
| 55 |
charIdx++;
|
| 56 |
setDisplayedText(lastTurn.text.slice(0, charIdx));
|
|
|
|
|
|
|
|
|
|
| 57 |
} else {
|
| 58 |
if (timerRef.current) clearInterval(timerRef.current);
|
| 59 |
setIsTyping(false);
|
algospaced-ui/src/features/companion/index.ts
CHANGED
|
@@ -10,6 +10,7 @@ export { default as PrincessChamber } from './components/PrincessChamber';
|
|
| 10 |
export { default as PrincessToast } from './components/PrincessToast';
|
| 11 |
export { default as CharacterStage } from './components/CharacterStage';
|
| 12 |
export { default as DialogueBubble } from './components/DialogueBubble';
|
|
|
|
| 13 |
export { default as ChoiceChips } from './components/ChoiceChips';
|
| 14 |
export { default as SpireProgressModal } from './components/SpireProgressModal';
|
| 15 |
export { default as RoyalSatchelModal } from './components/RoyalSatchelModal';
|
|
|
|
| 10 |
export { default as PrincessToast } from './components/PrincessToast';
|
| 11 |
export { default as CharacterStage } from './components/CharacterStage';
|
| 12 |
export { default as DialogueBubble } from './components/DialogueBubble';
|
| 13 |
+
export { default as JRPGDialogueBox } from './components/JRPGDialogueBox';
|
| 14 |
export { default as ChoiceChips } from './components/ChoiceChips';
|
| 15 |
export { default as SpireProgressModal } from './components/SpireProgressModal';
|
| 16 |
export { default as RoyalSatchelModal } from './components/RoyalSatchelModal';
|
algospaced-ui/src/utils/rpgAudio.ts
CHANGED
|
@@ -2,10 +2,15 @@
|
|
| 2 |
|
| 3 |
let audioCtx: AudioContext | null = null;
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
function getAudioContext(): AudioContext | null {
|
| 6 |
if (typeof window === 'undefined') return null;
|
| 7 |
if (!audioCtx) {
|
| 8 |
-
const
|
|
|
|
| 9 |
if (AudioContextClass) {
|
| 10 |
audioCtx = new AudioContextClass();
|
| 11 |
}
|
|
@@ -28,38 +33,16 @@ export function isAudioMuted(): boolean {
|
|
| 28 |
export function setAudioMuted(muted: boolean): void {
|
| 29 |
try {
|
| 30 |
localStorage.setItem('companion_sound_enabled', muted ? 'false' : 'true');
|
| 31 |
-
} catch {
|
|
|
|
|
|
|
| 32 |
}
|
| 33 |
|
| 34 |
/**
|
| 35 |
-
*
|
| 36 |
*/
|
| 37 |
-
export function playTypewriterBlip(
|
| 38 |
-
|
| 39 |
-
const ctx = getAudioContext();
|
| 40 |
-
if (!ctx) return;
|
| 41 |
-
|
| 42 |
-
try {
|
| 43 |
-
const osc = ctx.createOscillator();
|
| 44 |
-
const gain = ctx.createGain();
|
| 45 |
-
|
| 46 |
-
osc.type = 'triangle';
|
| 47 |
-
// Base frequency around 520Hz with slight natural variation
|
| 48 |
-
const baseFreq = 520 + (pitchVariation % 5) * 20;
|
| 49 |
-
osc.frequency.setValueAtTime(baseFreq, ctx.currentTime);
|
| 50 |
-
osc.frequency.exponentialRampToValueAtTime(baseFreq * 1.2, ctx.currentTime + 0.025);
|
| 51 |
-
|
| 52 |
-
gain.gain.setValueAtTime(0.04, ctx.currentTime);
|
| 53 |
-
gain.gain.exponentialRampToValueAtTime(0.0001, ctx.currentTime + 0.035);
|
| 54 |
-
|
| 55 |
-
osc.connect(gain);
|
| 56 |
-
gain.connect(ctx.destination);
|
| 57 |
-
|
| 58 |
-
osc.start();
|
| 59 |
-
osc.stop(ctx.currentTime + 0.04);
|
| 60 |
-
} catch (err) {
|
| 61 |
-
// Ignore audio errors gracefully
|
| 62 |
-
}
|
| 63 |
}
|
| 64 |
|
| 65 |
/**
|
|
@@ -90,7 +73,9 @@ export function playPopupChime(): void {
|
|
| 90 |
osc.start(startTime + idx * 0.06);
|
| 91 |
osc.stop(startTime + idx * 0.06 + 0.2);
|
| 92 |
});
|
| 93 |
-
} catch
|
|
|
|
|
|
|
| 94 |
}
|
| 95 |
|
| 96 |
/**
|
|
@@ -121,7 +106,9 @@ export function playBreakReminderTone(): void {
|
|
| 121 |
osc.start(startTime + idx * 0.09);
|
| 122 |
osc.stop(startTime + idx * 0.09 + 0.4);
|
| 123 |
});
|
| 124 |
-
} catch
|
|
|
|
|
|
|
| 125 |
}
|
| 126 |
|
| 127 |
/**
|
|
@@ -160,5 +147,7 @@ export function playLevelUpFanfare(): void {
|
|
| 160 |
osc.start(startTime + item.time);
|
| 161 |
osc.stop(startTime + item.time + item.dur + 0.05);
|
| 162 |
});
|
| 163 |
-
} catch
|
|
|
|
|
|
|
| 164 |
}
|
|
|
|
| 2 |
|
| 3 |
let audioCtx: AudioContext | null = null;
|
| 4 |
|
| 5 |
+
type CustomWindow = Window & typeof globalThis & {
|
| 6 |
+
webkitAudioContext?: typeof AudioContext;
|
| 7 |
+
};
|
| 8 |
+
|
| 9 |
function getAudioContext(): AudioContext | null {
|
| 10 |
if (typeof window === 'undefined') return null;
|
| 11 |
if (!audioCtx) {
|
| 12 |
+
const customWin = window as CustomWindow;
|
| 13 |
+
const AudioContextClass = window.AudioContext || customWin.webkitAudioContext;
|
| 14 |
if (AudioContextClass) {
|
| 15 |
audioCtx = new AudioContextClass();
|
| 16 |
}
|
|
|
|
| 33 |
export function setAudioMuted(muted: boolean): void {
|
| 34 |
try {
|
| 35 |
localStorage.setItem('companion_sound_enabled', muted ? 'false' : 'true');
|
| 36 |
+
} catch {
|
| 37 |
+
// Graceful fallback if localStorage is disabled
|
| 38 |
+
}
|
| 39 |
}
|
| 40 |
|
| 41 |
/**
|
| 42 |
+
* Typewriter dialogue character blip (disabled)
|
| 43 |
*/
|
| 44 |
+
export function playTypewriterBlip(_pitchVariation: number = 0): void {
|
| 45 |
+
// Disabled: typewriter blip sound removed
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
}
|
| 47 |
|
| 48 |
/**
|
|
|
|
| 73 |
osc.start(startTime + idx * 0.06);
|
| 74 |
osc.stop(startTime + idx * 0.06 + 0.2);
|
| 75 |
});
|
| 76 |
+
} catch {
|
| 77 |
+
// Ignore audio errors gracefully
|
| 78 |
+
}
|
| 79 |
}
|
| 80 |
|
| 81 |
/**
|
|
|
|
| 106 |
osc.start(startTime + idx * 0.09);
|
| 107 |
osc.stop(startTime + idx * 0.09 + 0.4);
|
| 108 |
});
|
| 109 |
+
} catch {
|
| 110 |
+
// Ignore audio errors gracefully
|
| 111 |
+
}
|
| 112 |
}
|
| 113 |
|
| 114 |
/**
|
|
|
|
| 147 |
osc.start(startTime + item.time);
|
| 148 |
osc.stop(startTime + item.time + item.dur + 0.05);
|
| 149 |
});
|
| 150 |
+
} catch {
|
| 151 |
+
// Ignore audio errors gracefully
|
| 152 |
+
}
|
| 153 |
}
|
data/companion_telemetry.json
CHANGED
|
@@ -42,5 +42,381 @@
|
|
| 42 |
"hero_name": "Febin",
|
| 43 |
"source": "server_proposed",
|
| 44 |
"timestamp": 1788689138.6665707
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
}
|
| 46 |
]
|
|
|
|
| 42 |
"hero_name": "Febin",
|
| 43 |
"source": "server_proposed",
|
| 44 |
"timestamp": 1788689138.6665707
|
| 45 |
+
},
|
| 46 |
+
{
|
| 47 |
+
"tool_name": "record_episodic_event",
|
| 48 |
+
"args": {
|
| 49 |
+
"eventType": "personal_share",
|
| 50 |
+
"title": "Disturbed by a spider",
|
| 51 |
+
"description": "Champion expressed sadness, then mentioned seeing a spider, asking if it was big. This seemed to contribute to their discomfort.",
|
| 52 |
+
"relatedPattern": "environmental_distraction"
|
| 53 |
+
},
|
| 54 |
+
"success": true,
|
| 55 |
+
"hero_name": "Champion",
|
| 56 |
+
"source": "server_proposed",
|
| 57 |
+
"timestamp": 1791558769.2295122
|
| 58 |
+
},
|
| 59 |
+
{
|
| 60 |
+
"tool_name": "record_episodic_event",
|
| 61 |
+
"args": {
|
| 62 |
+
"eventType": "personal_share",
|
| 63 |
+
"title": "Disturbed by a spider",
|
| 64 |
+
"description": "Champion expressed sadness, then mentioned seeing a spider, asking if it was big. This seemed to contribute to their discomfort.",
|
| 65 |
+
"relatedPattern": "environmental_distraction"
|
| 66 |
+
},
|
| 67 |
+
"success": true,
|
| 68 |
+
"execution_time_ms": 0.0,
|
| 69 |
+
"hero_name": "Champion",
|
| 70 |
+
"source": "client",
|
| 71 |
+
"error": null,
|
| 72 |
+
"timestamp": 1791558769.233
|
| 73 |
+
},
|
| 74 |
+
{
|
| 75 |
+
"tool_name": "record_episodic_event",
|
| 76 |
+
"args": {
|
| 77 |
+
"eventType": "personal_share",
|
| 78 |
+
"title": "Disturbed by a spider",
|
| 79 |
+
"description": "Champion expressed sadness, then mentioned seeing a spider, asking if it was big. This seemed to contribute to their discomfort.",
|
| 80 |
+
"relatedPattern": "discomfort_from_environment"
|
| 81 |
+
},
|
| 82 |
+
"success": true,
|
| 83 |
+
"hero_name": "Champion",
|
| 84 |
+
"source": "server_proposed",
|
| 85 |
+
"timestamp": 1791558795.1189067
|
| 86 |
+
},
|
| 87 |
+
{
|
| 88 |
+
"tool_name": "record_episodic_event",
|
| 89 |
+
"args": {
|
| 90 |
+
"eventType": "personal_share",
|
| 91 |
+
"title": "Disturbed by a spider",
|
| 92 |
+
"description": "Champion expressed sadness, then mentioned seeing a spider, asking if it was big. This seemed to contribute to their discomfort.",
|
| 93 |
+
"relatedPattern": "discomfort_from_environment"
|
| 94 |
+
},
|
| 95 |
+
"success": true,
|
| 96 |
+
"execution_time_ms": 0.0,
|
| 97 |
+
"hero_name": "Champion",
|
| 98 |
+
"source": "client",
|
| 99 |
+
"error": null,
|
| 100 |
+
"timestamp": 1791558795.121
|
| 101 |
+
},
|
| 102 |
+
{
|
| 103 |
+
"tool_name": "record_episodic_event",
|
| 104 |
+
"args": {
|
| 105 |
+
"eventType": "personal_share",
|
| 106 |
+
"title": "Chose to chat over timed break",
|
| 107 |
+
"description": "Champion opted for a moment of free-form conversation instead of a structured 5-minute break."
|
| 108 |
+
},
|
| 109 |
+
"success": true,
|
| 110 |
+
"hero_name": "Champion",
|
| 111 |
+
"source": "server_proposed",
|
| 112 |
+
"timestamp": 1791558812.4477842
|
| 113 |
+
},
|
| 114 |
+
{
|
| 115 |
+
"tool_name": "record_episodic_event",
|
| 116 |
+
"args": {
|
| 117 |
+
"eventType": "personal_share",
|
| 118 |
+
"title": "Chose to chat over timed break",
|
| 119 |
+
"description": "Champion opted for a moment of free-form conversation instead of a structured 5-minute break."
|
| 120 |
+
},
|
| 121 |
+
"success": true,
|
| 122 |
+
"execution_time_ms": 0.0,
|
| 123 |
+
"hero_name": "Champion",
|
| 124 |
+
"source": "client",
|
| 125 |
+
"error": null,
|
| 126 |
+
"timestamp": 1791558812.45
|
| 127 |
+
},
|
| 128 |
+
{
|
| 129 |
+
"tool_name": "record_episodic_event",
|
| 130 |
+
"args": {
|
| 131 |
+
"eventType": "personal_share",
|
| 132 |
+
"title": "Champion expresses fear",
|
| 133 |
+
"description": "Champion directly stated 'be scared' after earlier mentioning a spider and sadness. Seems to be feeling generally uneasy or fearful.",
|
| 134 |
+
"relatedPattern": ""
|
| 135 |
+
},
|
| 136 |
+
"success": true,
|
| 137 |
+
"hero_name": "Champion",
|
| 138 |
+
"source": "server_proposed",
|
| 139 |
+
"timestamp": 1791558861.7550862
|
| 140 |
+
},
|
| 141 |
+
{
|
| 142 |
+
"tool_name": "write_spire_diary",
|
| 143 |
+
"args": {
|
| 144 |
+
"entry": "Champion confessed to feeling scared; need to offer comfort."
|
| 145 |
+
},
|
| 146 |
+
"success": true,
|
| 147 |
+
"hero_name": "Champion",
|
| 148 |
+
"source": "server_proposed",
|
| 149 |
+
"timestamp": 1791558861.755788
|
| 150 |
+
},
|
| 151 |
+
{
|
| 152 |
+
"tool_name": "record_episodic_event",
|
| 153 |
+
"args": {
|
| 154 |
+
"eventType": "personal_share",
|
| 155 |
+
"title": "Champion expresses fear",
|
| 156 |
+
"description": "Champion directly stated 'be scared' after earlier mentioning a spider and sadness. Seems to be feeling generally uneasy or fearful.",
|
| 157 |
+
"relatedPattern": ""
|
| 158 |
+
},
|
| 159 |
+
"success": true,
|
| 160 |
+
"execution_time_ms": 0.0,
|
| 161 |
+
"hero_name": "Champion",
|
| 162 |
+
"source": "client",
|
| 163 |
+
"error": null,
|
| 164 |
+
"timestamp": 1791558861.757
|
| 165 |
+
},
|
| 166 |
+
{
|
| 167 |
+
"tool_name": "write_spire_diary",
|
| 168 |
+
"args": {
|
| 169 |
+
"entry": "Champion confessed to feeling scared; need to offer comfort."
|
| 170 |
+
},
|
| 171 |
+
"success": true,
|
| 172 |
+
"execution_time_ms": 0.0,
|
| 173 |
+
"hero_name": "Champion",
|
| 174 |
+
"source": "client",
|
| 175 |
+
"error": null,
|
| 176 |
+
"timestamp": 1791558861.758
|
| 177 |
+
},
|
| 178 |
+
{
|
| 179 |
+
"tool_name": "record_episodic_event",
|
| 180 |
+
"args": {
|
| 181 |
+
"eventType": "breakthrough",
|
| 182 |
+
"title": "Conquered a tough task",
|
| 183 |
+
"description": "Champion successfully solved a challenging problem after expressing fear earlier.",
|
| 184 |
+
"relatedPattern": "overcame fear/difficulty"
|
| 185 |
+
},
|
| 186 |
+
"success": true,
|
| 187 |
+
"hero_name": "Champion",
|
| 188 |
+
"source": "server_proposed",
|
| 189 |
+
"timestamp": 1791563225.3743153
|
| 190 |
+
},
|
| 191 |
+
{
|
| 192 |
+
"tool_name": "record_episodic_event",
|
| 193 |
+
"args": {
|
| 194 |
+
"eventType": "breakthrough",
|
| 195 |
+
"title": "Conquered a tough task",
|
| 196 |
+
"description": "Champion successfully solved a challenging problem after expressing fear earlier.",
|
| 197 |
+
"relatedPattern": "overcame fear/difficulty"
|
| 198 |
+
},
|
| 199 |
+
"success": true,
|
| 200 |
+
"execution_time_ms": 1.0,
|
| 201 |
+
"hero_name": "Champion",
|
| 202 |
+
"source": "client",
|
| 203 |
+
"error": null,
|
| 204 |
+
"timestamp": 1791563225.377
|
| 205 |
+
},
|
| 206 |
+
{
|
| 207 |
+
"tool_name": "record_episodic_event",
|
| 208 |
+
"args": {
|
| 209 |
+
"eventType": "breakthrough",
|
| 210 |
+
"title": "Tackled a tough problem",
|
| 211 |
+
"description": "Champion successfully solved a challenging problem after expressing fear earlier.",
|
| 212 |
+
"relatedPattern": ""
|
| 213 |
+
},
|
| 214 |
+
"success": true,
|
| 215 |
+
"hero_name": "Champion",
|
| 216 |
+
"source": "server_proposed",
|
| 217 |
+
"timestamp": 1791563246.3450916
|
| 218 |
+
},
|
| 219 |
+
{
|
| 220 |
+
"tool_name": "record_episodic_event",
|
| 221 |
+
"args": {
|
| 222 |
+
"eventType": "breakthrough",
|
| 223 |
+
"title": "Tackled a tough problem",
|
| 224 |
+
"description": "Champion successfully solved a challenging problem after expressing fear earlier.",
|
| 225 |
+
"relatedPattern": ""
|
| 226 |
+
},
|
| 227 |
+
"success": true,
|
| 228 |
+
"execution_time_ms": 0.0,
|
| 229 |
+
"hero_name": "Champion",
|
| 230 |
+
"source": "client",
|
| 231 |
+
"error": null,
|
| 232 |
+
"timestamp": 1791563246.348
|
| 233 |
+
},
|
| 234 |
+
{
|
| 235 |
+
"tool_name": "open_app_window",
|
| 236 |
+
"args": {
|
| 237 |
+
"window_id": "reviewer"
|
| 238 |
+
},
|
| 239 |
+
"success": true,
|
| 240 |
+
"hero_name": "Champion",
|
| 241 |
+
"source": "server_proposed",
|
| 242 |
+
"timestamp": 1791563364.8702972
|
| 243 |
+
},
|
| 244 |
+
{
|
| 245 |
+
"tool_name": "record_episodic_event",
|
| 246 |
+
"args": {
|
| 247 |
+
"eventType": "breakthrough",
|
| 248 |
+
"title": "Problem Details Inquiry",
|
| 249 |
+
"description": "Champion asked for more details on a problem they solved, showing continued engagement even after solving it.",
|
| 250 |
+
"relatedPattern": "deep_dive_curiosity"
|
| 251 |
+
},
|
| 252 |
+
"success": true,
|
| 253 |
+
"hero_name": "Champion",
|
| 254 |
+
"source": "server_proposed",
|
| 255 |
+
"timestamp": 1791563364.8715653
|
| 256 |
+
},
|
| 257 |
+
{
|
| 258 |
+
"tool_name": "open_app_window",
|
| 259 |
+
"args": {
|
| 260 |
+
"window_id": "reviewer"
|
| 261 |
+
},
|
| 262 |
+
"success": true,
|
| 263 |
+
"execution_time_ms": 5.0,
|
| 264 |
+
"hero_name": "Champion",
|
| 265 |
+
"source": "client",
|
| 266 |
+
"error": null,
|
| 267 |
+
"timestamp": 1791563364.878
|
| 268 |
+
},
|
| 269 |
+
{
|
| 270 |
+
"tool_name": "record_episodic_event",
|
| 271 |
+
"args": {
|
| 272 |
+
"eventType": "breakthrough",
|
| 273 |
+
"title": "Problem Details Inquiry",
|
| 274 |
+
"description": "Champion asked for more details on a problem they solved, showing continued engagement even after solving it.",
|
| 275 |
+
"relatedPattern": "deep_dive_curiosity"
|
| 276 |
+
},
|
| 277 |
+
"success": true,
|
| 278 |
+
"execution_time_ms": 5.0,
|
| 279 |
+
"hero_name": "Champion",
|
| 280 |
+
"source": "client",
|
| 281 |
+
"error": null,
|
| 282 |
+
"timestamp": 1791563364.879
|
| 283 |
+
},
|
| 284 |
+
{
|
| 285 |
+
"tool_name": "record_episodic_event",
|
| 286 |
+
"args": {
|
| 287 |
+
"eventType": "personal_share",
|
| 288 |
+
"title": "Champion's concern for Aurelia's well-being",
|
| 289 |
+
"description": "Champion expressed concern that Aurelia must eat, showing care for her.",
|
| 290 |
+
"relatedPattern": ""
|
| 291 |
+
},
|
| 292 |
+
"success": true,
|
| 293 |
+
"hero_name": "Champion",
|
| 294 |
+
"source": "server_proposed",
|
| 295 |
+
"timestamp": 1791563442.1888142
|
| 296 |
+
},
|
| 297 |
+
{
|
| 298 |
+
"tool_name": "write_spire_diary",
|
| 299 |
+
"args": {
|
| 300 |
+
"entry": "Champion showed concern for my well-being today, a truly kind gesture."
|
| 301 |
+
},
|
| 302 |
+
"success": true,
|
| 303 |
+
"hero_name": "Champion",
|
| 304 |
+
"source": "server_proposed",
|
| 305 |
+
"timestamp": 1791563442.1897433
|
| 306 |
+
},
|
| 307 |
+
{
|
| 308 |
+
"tool_name": "record_episodic_event",
|
| 309 |
+
"args": {
|
| 310 |
+
"eventType": "personal_share",
|
| 311 |
+
"title": "Champion's concern for Aurelia's well-being",
|
| 312 |
+
"description": "Champion expressed concern that Aurelia must eat, showing care for her.",
|
| 313 |
+
"relatedPattern": ""
|
| 314 |
+
},
|
| 315 |
+
"success": true,
|
| 316 |
+
"execution_time_ms": 0.0,
|
| 317 |
+
"hero_name": "Champion",
|
| 318 |
+
"source": "client",
|
| 319 |
+
"error": null,
|
| 320 |
+
"timestamp": 1791563442.192
|
| 321 |
+
},
|
| 322 |
+
{
|
| 323 |
+
"tool_name": "write_spire_diary",
|
| 324 |
+
"args": {
|
| 325 |
+
"entry": "Champion showed concern for my well-being today, a truly kind gesture."
|
| 326 |
+
},
|
| 327 |
+
"success": true,
|
| 328 |
+
"execution_time_ms": 0.0,
|
| 329 |
+
"hero_name": "Champion",
|
| 330 |
+
"source": "client",
|
| 331 |
+
"error": null,
|
| 332 |
+
"timestamp": 1791563442.193
|
| 333 |
+
},
|
| 334 |
+
{
|
| 335 |
+
"tool_name": "record_episodic_event",
|
| 336 |
+
"args": {
|
| 337 |
+
"eventType": "personal_share",
|
| 338 |
+
"title": "Won a bet",
|
| 339 |
+
"description": "Champion shared that they won a bet today, indicating good personal fortune outside of their studies."
|
| 340 |
+
},
|
| 341 |
+
"success": true,
|
| 342 |
+
"hero_name": "Champion",
|
| 343 |
+
"source": "server_proposed",
|
| 344 |
+
"timestamp": 1791563475.6878104
|
| 345 |
+
},
|
| 346 |
+
{
|
| 347 |
+
"tool_name": "record_episodic_event",
|
| 348 |
+
"args": {
|
| 349 |
+
"eventType": "personal_share",
|
| 350 |
+
"title": "Won a bet",
|
| 351 |
+
"description": "Champion shared that they won a bet today, indicating good personal fortune outside of their studies."
|
| 352 |
+
},
|
| 353 |
+
"success": true,
|
| 354 |
+
"execution_time_ms": 0.0,
|
| 355 |
+
"hero_name": "Champion",
|
| 356 |
+
"source": "client",
|
| 357 |
+
"error": null,
|
| 358 |
+
"timestamp": 1791563475.69
|
| 359 |
+
},
|
| 360 |
+
{
|
| 361 |
+
"tool_name": "record_episodic_event",
|
| 362 |
+
"args": {
|
| 363 |
+
"eventType": "breakthrough",
|
| 364 |
+
"title": "Tough Task Conquered",
|
| 365 |
+
"description": "Champion conquered a tough problem and feels accomplished."
|
| 366 |
+
},
|
| 367 |
+
"success": true,
|
| 368 |
+
"hero_name": "Champion",
|
| 369 |
+
"source": "server_proposed",
|
| 370 |
+
"timestamp": 1791608213.0370414
|
| 371 |
+
},
|
| 372 |
+
{
|
| 373 |
+
"tool_name": "record_episodic_event",
|
| 374 |
+
"args": {
|
| 375 |
+
"eventType": "breakthrough",
|
| 376 |
+
"title": "Tough Task Conquered",
|
| 377 |
+
"description": "Champion conquered a tough problem and feels accomplished."
|
| 378 |
+
},
|
| 379 |
+
"success": true,
|
| 380 |
+
"execution_time_ms": 0.0,
|
| 381 |
+
"hero_name": "Champion",
|
| 382 |
+
"source": "client",
|
| 383 |
+
"error": null,
|
| 384 |
+
"timestamp": 1791608213.049
|
| 385 |
+
},
|
| 386 |
+
{
|
| 387 |
+
"tool_name": "hint_requested",
|
| 388 |
+
"args": {
|
| 389 |
+
"test": "async_val"
|
| 390 |
+
},
|
| 391 |
+
"success": true,
|
| 392 |
+
"execution_time_ms": null,
|
| 393 |
+
"hero_name": "Champion",
|
| 394 |
+
"source": "client",
|
| 395 |
+
"error": null,
|
| 396 |
+
"timestamp": 1791630917.0461233
|
| 397 |
+
},
|
| 398 |
+
{
|
| 399 |
+
"tool_name": "hint_requested",
|
| 400 |
+
"args": {
|
| 401 |
+
"test": "async_val"
|
| 402 |
+
},
|
| 403 |
+
"success": true,
|
| 404 |
+
"execution_time_ms": null,
|
| 405 |
+
"hero_name": "Champion",
|
| 406 |
+
"source": "client",
|
| 407 |
+
"error": null,
|
| 408 |
+
"timestamp": 1791638114.6923687
|
| 409 |
+
},
|
| 410 |
+
{
|
| 411 |
+
"tool_name": "hint_requested",
|
| 412 |
+
"args": {
|
| 413 |
+
"test": "async_val"
|
| 414 |
+
},
|
| 415 |
+
"success": true,
|
| 416 |
+
"execution_time_ms": null,
|
| 417 |
+
"hero_name": "Champion",
|
| 418 |
+
"source": "client",
|
| 419 |
+
"error": null,
|
| 420 |
+
"timestamp": 1791638560.2518651
|
| 421 |
}
|
| 422 |
]
|
llm_reviewer.py
CHANGED
|
@@ -6,6 +6,8 @@ import urllib.request
|
|
| 6 |
from datetime import UTC, datetime
|
| 7 |
from typing import Any
|
| 8 |
|
|
|
|
|
|
|
| 9 |
import ai_cache
|
| 10 |
import ai_provider
|
| 11 |
|
|
@@ -497,3 +499,481 @@ def format_code_with_emoji_comments(
|
|
| 497 |
except Exception as e:
|
| 498 |
logger.error(f"Error formatting code with emoji comments: {e}")
|
| 499 |
return {"error": str(e)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
from datetime import UTC, datetime
|
| 7 |
from typing import Any
|
| 8 |
|
| 9 |
+
import httpx
|
| 10 |
+
|
| 11 |
import ai_cache
|
| 12 |
import ai_provider
|
| 13 |
|
|
|
|
| 499 |
except Exception as e:
|
| 500 |
logger.error(f"Error formatting code with emoji comments: {e}")
|
| 501 |
return {"error": str(e)}
|
| 502 |
+
|
| 503 |
+
|
| 504 |
+
async def evaluate_code_async(
|
| 505 |
+
problem_name: str,
|
| 506 |
+
pattern_name: str,
|
| 507 |
+
expected_time: str,
|
| 508 |
+
expected_space: str,
|
| 509 |
+
candidate_code: str,
|
| 510 |
+
custom_api_key: str | None = None,
|
| 511 |
+
custom_provider: str | None = None,
|
| 512 |
+
) -> dict[str, Any]:
|
| 513 |
+
system_instruction = """
|
| 514 |
+
You are an expert technical interviewer evaluating a candidate's LeetCode code written from memory.
|
| 515 |
+
Your primary objective is to review code correctness, algorithmic efficiency, and potential edge-case failures.
|
| 516 |
+
Be highly forgiving of minor visual/syntax typos (e.g., off-by-one indentation, minor spelling mistakes in variables, or missing colons)
|
| 517 |
+
which would be caught in 1 second by a standard IDE. Focus on raw algorithmic correctness.
|
| 518 |
+
Return ONLY a JSON response matching the required schema. No markdown formatting blocks around the JSON.
|
| 519 |
+
"""
|
| 520 |
+
|
| 521 |
+
user_prompt = f"""
|
| 522 |
+
Problem Name: {problem_name}
|
| 523 |
+
Target Pattern: {pattern_name}
|
| 524 |
+
Expected Complexity: Time: {expected_time}, Space: {expected_space}
|
| 525 |
+
|
| 526 |
+
Candidate's Code Submission:
|
| 527 |
+
{candidate_code}
|
| 528 |
+
|
| 529 |
+
Evaluate the code logic and return the structured JSON output with the exact schema:
|
| 530 |
+
{{
|
| 531 |
+
"is_correct": boolean,
|
| 532 |
+
"detected_complexity": {{"time": string, "space": string}},
|
| 533 |
+
"bugs": [string, string, ...],
|
| 534 |
+
"key_suggestion": string
|
| 535 |
+
}}
|
| 536 |
+
"""
|
| 537 |
+
|
| 538 |
+
try:
|
| 539 |
+
raw_text, provider_used = await ai_provider.generate_ai_content_async(
|
| 540 |
+
system_instruction=system_instruction,
|
| 541 |
+
user_prompt=user_prompt,
|
| 542 |
+
is_json=True,
|
| 543 |
+
custom_provider=custom_provider,
|
| 544 |
+
custom_api_key=custom_api_key,
|
| 545 |
+
)
|
| 546 |
+
cleaned = ai_provider.clean_json_response(raw_text)
|
| 547 |
+
result = json.loads(cleaned)
|
| 548 |
+
result["_provider_used"] = provider_used
|
| 549 |
+
return result
|
| 550 |
+
except Exception as e:
|
| 551 |
+
logger.error(f"Error evaluating code async: {e}")
|
| 552 |
+
return {"error": str(e)}
|
| 553 |
+
|
| 554 |
+
|
| 555 |
+
async def explain_code_async(
|
| 556 |
+
problem_name: str,
|
| 557 |
+
code: str,
|
| 558 |
+
optimal_time: str,
|
| 559 |
+
optimal_space: str,
|
| 560 |
+
custom_api_key: str | None = None,
|
| 561 |
+
custom_provider: str | None = None,
|
| 562 |
+
) -> dict[str, Any]:
|
| 563 |
+
system_instruction = """
|
| 564 |
+
You are an expert technical interviewer and computer science educator.
|
| 565 |
+
Your objective is to provide a clean, comprehensive line-by-line explanation of a LeetCode reference solution.
|
| 566 |
+
|
| 567 |
+
Analyze only the provided code block text. Do NOT suggest or write an alternative code solution.
|
| 568 |
+
Break down the line-by-line logic, explain the state tracking variables, and explicitly match the code to the time and space complexities saved next to it.
|
| 569 |
+
|
| 570 |
+
Format your response in beautiful, clear Markdown.
|
| 571 |
+
"""
|
| 572 |
+
|
| 573 |
+
user_prompt = f"""
|
| 574 |
+
Problem Name: {problem_name}
|
| 575 |
+
Expected Complexity: Time: {optimal_time}, Space: {optimal_space}
|
| 576 |
+
|
| 577 |
+
Reference Code to Explain:
|
| 578 |
+
```python
|
| 579 |
+
{code}
|
| 580 |
+
```
|
| 581 |
+
|
| 582 |
+
Provide the explanation satisfying the constraints:
|
| 583 |
+
1. Break down the line-by-line logic of the code.
|
| 584 |
+
2. Explain any state tracking variables (what they hold and how they evolve).
|
| 585 |
+
3. Explicitly explain and match why the time complexity is {optimal_time} and the space complexity is {optimal_space}.
|
| 586 |
+
4. Do not write any alternative code solution.
|
| 587 |
+
"""
|
| 588 |
+
|
| 589 |
+
try:
|
| 590 |
+
raw_text, provider_used = await ai_provider.generate_ai_content_async(
|
| 591 |
+
system_instruction=system_instruction,
|
| 592 |
+
user_prompt=user_prompt,
|
| 593 |
+
is_json=False,
|
| 594 |
+
custom_provider=custom_provider,
|
| 595 |
+
custom_api_key=custom_api_key,
|
| 596 |
+
)
|
| 597 |
+
return {"explanation": raw_text.strip(), "_provider_used": provider_used}
|
| 598 |
+
except Exception as e:
|
| 599 |
+
logger.error(f"Error explaining code async: {e}")
|
| 600 |
+
return {"error": str(e)}
|
| 601 |
+
|
| 602 |
+
|
| 603 |
+
async def generate_daily_python_challenge_async(
|
| 604 |
+
custom_api_key: str | None = None,
|
| 605 |
+
custom_provider: str | None = None,
|
| 606 |
+
force_refresh: bool = False,
|
| 607 |
+
) -> dict[str, Any]:
|
| 608 |
+
today_str = datetime.now(UTC).strftime("%Y-%m-%d")
|
| 609 |
+
|
| 610 |
+
if not force_refresh:
|
| 611 |
+
cached = await ai_cache.get_daily_python_challenge_async(today_str)
|
| 612 |
+
if cached and isinstance(cached, dict) and "title" in cached:
|
| 613 |
+
return cached
|
| 614 |
+
|
| 615 |
+
system_instruction = """
|
| 616 |
+
You are an expert curriculum designer for a retro-arcade coding platform called AlgoSpaced.
|
| 617 |
+
Your task is to generate a new, daily python programming challenge.
|
| 618 |
+
The challenge should test standard core DSA concepts or standard coding tasks.
|
| 619 |
+
Provide test cases that check edge cases.
|
| 620 |
+
Return ONLY a JSON response matching the required schema. No markdown formatting blocks around the JSON.
|
| 621 |
+
"""
|
| 622 |
+
|
| 623 |
+
concepts = [
|
| 624 |
+
"arrays and hashing",
|
| 625 |
+
"two pointers",
|
| 626 |
+
"sliding window",
|
| 627 |
+
"stack",
|
| 628 |
+
"binary search",
|
| 629 |
+
"linked lists",
|
| 630 |
+
"trees and graphs",
|
| 631 |
+
"heap / priority queue",
|
| 632 |
+
"backtracking",
|
| 633 |
+
"dynamic programming",
|
| 634 |
+
"greedy algorithms",
|
| 635 |
+
"string manipulation",
|
| 636 |
+
"math & geometry",
|
| 637 |
+
"bit manipulation",
|
| 638 |
+
]
|
| 639 |
+
concept = random.choice(concepts)
|
| 640 |
+
|
| 641 |
+
user_prompt = f"""
|
| 642 |
+
Generate a daily coding challenge on the topic: "{concept}".
|
| 643 |
+
|
| 644 |
+
Return the structured JSON output with the exact schema:
|
| 645 |
+
{{
|
| 646 |
+
"title": "string (Short creative title, max 50 chars)",
|
| 647 |
+
"description": "string (Markdown description of the problem, input format, output format)",
|
| 648 |
+
"difficulty": "string (Easy, Medium, or Hard)",
|
| 649 |
+
"points": number (100 for Easy, 200 for Medium, 300 for Hard),
|
| 650 |
+
"starter_code": "string (Python starter code ending with 'pass')",
|
| 651 |
+
"test_cases": [
|
| 652 |
+
{{
|
| 653 |
+
"input": [any] (list of args to pass to the function),
|
| 654 |
+
"expected": any (expected return value)
|
| 655 |
+
}}
|
| 656 |
+
]
|
| 657 |
+
}}
|
| 658 |
+
|
| 659 |
+
Ensure the test cases are completely valid JSON and mathematically correct.
|
| 660 |
+
Ensure the starter_code defines a function (e.g., 'def solve(arr):\\n pass').
|
| 661 |
+
"""
|
| 662 |
+
|
| 663 |
+
try:
|
| 664 |
+
raw_text, _ = await ai_provider.generate_ai_content_async(
|
| 665 |
+
system_instruction=system_instruction,
|
| 666 |
+
user_prompt=user_prompt,
|
| 667 |
+
is_json=True,
|
| 668 |
+
custom_provider=custom_provider,
|
| 669 |
+
custom_api_key=custom_api_key,
|
| 670 |
+
)
|
| 671 |
+
cleaned = ai_provider.clean_json_response(raw_text)
|
| 672 |
+
result = json.loads(cleaned)
|
| 673 |
+
|
| 674 |
+
if "title" in result:
|
| 675 |
+
await ai_cache.set_daily_python_challenge_async(today_str, result)
|
| 676 |
+
|
| 677 |
+
return result
|
| 678 |
+
except Exception as e:
|
| 679 |
+
logger.error(f"Error generating daily python challenge async: {e}")
|
| 680 |
+
return {"error": str(e)}
|
| 681 |
+
|
| 682 |
+
|
| 683 |
+
async def generate_sql_challenge_async(
|
| 684 |
+
custom_api_key: str | None = None,
|
| 685 |
+
custom_provider: str | None = None,
|
| 686 |
+
force_refresh: bool = False,
|
| 687 |
+
) -> dict[str, Any]:
|
| 688 |
+
today_str = datetime.now(UTC).strftime("%Y-%m-%d")
|
| 689 |
+
|
| 690 |
+
if not force_refresh:
|
| 691 |
+
cached = await ai_cache.get_daily_sql_challenge_async(today_str)
|
| 692 |
+
if cached and isinstance(cached, dict) and "title" in cached:
|
| 693 |
+
return cached
|
| 694 |
+
|
| 695 |
+
system_instruction = """
|
| 696 |
+
You are an expert SQL instructor for a retro-arcade coding platform called AlgoSpaced.
|
| 697 |
+
Your task is to generate an interactive SQL challenge.
|
| 698 |
+
The challenge must test standard SQL capabilities (SELECT, JOIN, GROUP BY, Window Functions, or simple mutations like UPDATE/DELETE).
|
| 699 |
+
Return ONLY a JSON response matching the required schema. No markdown formatting blocks around the JSON.
|
| 700 |
+
"""
|
| 701 |
+
|
| 702 |
+
topics = [
|
| 703 |
+
"Window Functions (DENSE_RANK, ROW_NUMBER, PARTITION BY)",
|
| 704 |
+
"Aggregations & Grouping (SUM, AVG, HAVING)",
|
| 705 |
+
"Subqueries & CTEs (WITH clause)",
|
| 706 |
+
"Table Joins & Filtering (LEFT/INNER JOIN, NULL handling)",
|
| 707 |
+
"Data Mutations (UPDATE balances, DELETE inactive users)",
|
| 708 |
+
]
|
| 709 |
+
topic = random.choice(topics)
|
| 710 |
+
|
| 711 |
+
user_prompt = f"""
|
| 712 |
+
Generate an interactive SQL challenge on the topic: "{topic}".
|
| 713 |
+
|
| 714 |
+
Return the structured JSON output with the exact schema:
|
| 715 |
+
{{
|
| 716 |
+
"title": "string (Short creative title, max 50 chars)",
|
| 717 |
+
"objective": "string (Describe the SQL query the user needs to write. E.g., 'Write a query using DENSE_RANK() to rank employee salaries within each department.')",
|
| 718 |
+
"ddl": "string (DDL statements to create 2-3 tables. Use standard SQL types compatible with SQLite/MySQL. Ensure syntax is correct.)",
|
| 719 |
+
"inserts": "string (INSERT statements to populate the tables with 5-10 realistic mock rows.)",
|
| 720 |
+
"validation_query": "string (The correct reference SQL query that fulfills the objective.)",
|
| 721 |
+
"challenge_type": "string ('SELECT' or 'DML' (for UPDATE/DELETE challenges))",
|
| 722 |
+
"points": number (e.g., 150)
|
| 723 |
+
}}
|
| 724 |
+
|
| 725 |
+
Ensure that the DDL and INSERT statements are correct and run sequentially without errors.
|
| 726 |
+
Do not use complex MySQL-specific engines or custom functions. Keep it standard SQL.
|
| 727 |
+
"""
|
| 728 |
+
|
| 729 |
+
try:
|
| 730 |
+
raw_text, _ = await ai_provider.generate_ai_content_async(
|
| 731 |
+
system_instruction=system_instruction,
|
| 732 |
+
user_prompt=user_prompt,
|
| 733 |
+
is_json=True,
|
| 734 |
+
custom_provider=custom_provider,
|
| 735 |
+
custom_api_key=custom_api_key,
|
| 736 |
+
)
|
| 737 |
+
cleaned = ai_provider.clean_json_response(raw_text)
|
| 738 |
+
result = json.loads(cleaned)
|
| 739 |
+
|
| 740 |
+
if "title" in result:
|
| 741 |
+
await ai_cache.set_daily_sql_challenge_async(today_str, result)
|
| 742 |
+
|
| 743 |
+
return result
|
| 744 |
+
except Exception as e:
|
| 745 |
+
logger.error(f"Error generating daily SQL challenge async: {e}")
|
| 746 |
+
return {"error": str(e)}
|
| 747 |
+
|
| 748 |
+
|
| 749 |
+
async def prefill_problem_details_async(
|
| 750 |
+
name: str = "",
|
| 751 |
+
code: str = "",
|
| 752 |
+
custom_api_key: str | None = None,
|
| 753 |
+
custom_provider: str | None = None,
|
| 754 |
+
) -> dict[str, Any]:
|
| 755 |
+
system_instruction = """
|
| 756 |
+
You are an expert DSA assistant. Analyze the given problem name and/or reference code and return standard details about the problem.
|
| 757 |
+
Return ONLY a JSON response matching the required schema. No markdown formatting blocks around the JSON.
|
| 758 |
+
"""
|
| 759 |
+
|
| 760 |
+
user_prompt = f"""
|
| 761 |
+
Problem Name: {name}
|
| 762 |
+
Reference Code: {code}
|
| 763 |
+
|
| 764 |
+
Infer and fill in details about this programming problem.
|
| 765 |
+
Return the structured JSON output with the exact schema:
|
| 766 |
+
{{
|
| 767 |
+
"problem_number": number_or_null (the official LeetCode problem number if applicable, else null),
|
| 768 |
+
"pattern": "string (primary DSA pattern/category, e.g. Arrays & Hashing, Two Pointers, Sliding Window, Stack, Binary Search, Linked List, Trees, Graphs, Heap, Backtracking, Dynamic Programming, Greedy, Bit Manipulation, etc.)",
|
| 769 |
+
"difficulty": "string (Easy, Medium, or Hard)",
|
| 770 |
+
"optimal_time": "string (the optimal time complexity, e.g. O(N), O(N log N), O(1))",
|
| 771 |
+
"optimal_space": "string (the optimal auxiliary space complexity, e.g. O(N), O(1))",
|
| 772 |
+
"description": "string (a concise description of the problem's goal)",
|
| 773 |
+
"reference_code": "string (a clean, standard python solution for the optimal approach, formatted properly with indentation)"
|
| 774 |
+
}}
|
| 775 |
+
"""
|
| 776 |
+
|
| 777 |
+
try:
|
| 778 |
+
raw_text, _ = await ai_provider.generate_ai_content_async(
|
| 779 |
+
system_instruction=system_instruction,
|
| 780 |
+
user_prompt=user_prompt,
|
| 781 |
+
is_json=True,
|
| 782 |
+
custom_provider=custom_provider,
|
| 783 |
+
custom_api_key=custom_api_key,
|
| 784 |
+
)
|
| 785 |
+
cleaned = ai_provider.clean_json_response(raw_text)
|
| 786 |
+
result = json.loads(cleaned)
|
| 787 |
+
return result
|
| 788 |
+
except Exception as e:
|
| 789 |
+
logger.error(f"Error prefilling problem details async: {e}")
|
| 790 |
+
return {"error": str(e)}
|
| 791 |
+
|
| 792 |
+
|
| 793 |
+
async def fetch_leetcode_problem_async(
|
| 794 |
+
url_or_title: str, custom_api_key: str | None = None, custom_provider: str | None = None
|
| 795 |
+
) -> dict[str, Any]:
|
| 796 |
+
clean_input = url_or_title.strip()
|
| 797 |
+
|
| 798 |
+
cached = await ai_cache.get_leetcode_problem_async(clean_input)
|
| 799 |
+
if cached and isinstance(cached, dict) and "title" in cached:
|
| 800 |
+
return cached
|
| 801 |
+
|
| 802 |
+
slug_match = re.search(r"leetcode\.com/problems/([a-zA-Z0-9_\-]+)", clean_input)
|
| 803 |
+
slug = slug_match.group(1) if slug_match else clean_input.lower().replace(" ", "-")
|
| 804 |
+
slug = re.sub(r"^\d+[\.\-_]*", "", slug).strip("-")
|
| 805 |
+
|
| 806 |
+
raw_data = None
|
| 807 |
+
try:
|
| 808 |
+
gql_url = "https://leetcode.com/graphql"
|
| 809 |
+
query = {
|
| 810 |
+
"query": """
|
| 811 |
+
query getQuestionDetail($titleSlug: String!) {
|
| 812 |
+
question(titleSlug: $titleSlug) {
|
| 813 |
+
questionFrontendId
|
| 814 |
+
title
|
| 815 |
+
difficulty
|
| 816 |
+
content
|
| 817 |
+
topicTags { name }
|
| 818 |
+
}
|
| 819 |
+
}
|
| 820 |
+
""",
|
| 821 |
+
"variables": {"titleSlug": slug},
|
| 822 |
+
}
|
| 823 |
+
async with httpx.AsyncClient(timeout=10.0) as client:
|
| 824 |
+
resp = await client.post(
|
| 825 |
+
gql_url,
|
| 826 |
+
json=query,
|
| 827 |
+
headers={
|
| 828 |
+
"Content-Type": "application/json",
|
| 829 |
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)",
|
| 830 |
+
},
|
| 831 |
+
)
|
| 832 |
+
if resp.status_code == 200:
|
| 833 |
+
data = resp.json()
|
| 834 |
+
q = data.get("data", {}).get("question")
|
| 835 |
+
if q:
|
| 836 |
+
raw_data = q
|
| 837 |
+
except Exception:
|
| 838 |
+
raw_data = None
|
| 839 |
+
|
| 840 |
+
system_instruction = """
|
| 841 |
+
You are an expert LeetCode DSA parser and curriculum specialist.
|
| 842 |
+
Your task is to take LeetCode problem information (or title / slug) and output a clean, structured JSON format with complete details including clean text description, structured examples, constraints list, optimal complexities, pattern, and intuition.
|
| 843 |
+
Return ONLY a JSON response matching the required schema. No markdown formatting blocks around the JSON.
|
| 844 |
+
"""
|
| 845 |
+
|
| 846 |
+
user_prompt = f"""
|
| 847 |
+
Problem Identifier: {clean_input}
|
| 848 |
+
Raw LeetCode Metadata: {json.dumps(raw_data) if raw_data else "None"}
|
| 849 |
+
|
| 850 |
+
Structure this LeetCode problem into the following exact JSON schema:
|
| 851 |
+
{{
|
| 852 |
+
"problem_number": number_or_null (e.g. 2 for "Add Two Numbers"),
|
| 853 |
+
"title": "string (Official Problem Title, e.g. Add Two Numbers)",
|
| 854 |
+
"difficulty": "Easy" | "Medium" | "Hard",
|
| 855 |
+
"pattern": "string (e.g. Linked List, Dynamic Programming, Sliding Window, Trees, Graphs, Two Pointers, etc.)",
|
| 856 |
+
"optimal_time": "string (e.g. O(max(N, M)))",
|
| 857 |
+
"optimal_space": "string (e.g. O(max(N, M)))",
|
| 858 |
+
"description": "string (A clean, markdown-formatted problem description explaining the task. Do not include raw HTML.)",
|
| 859 |
+
"how_to_solve": "string (Clear, intuitive 2-4 sentence explanation of the optimal strategy and invariants)",
|
| 860 |
+
"examples": [
|
| 861 |
+
{{
|
| 862 |
+
"input": "string (e.g. l1 = [2,4,3], l2 = [5,6,4])",
|
| 863 |
+
"output": "string (e.g. [7,0,8])",
|
| 864 |
+
"explanation": "string or null"
|
| 865 |
+
}}
|
| 866 |
+
],
|
| 867 |
+
"constraints": [
|
| 868 |
+
"string (e.g. The number of nodes in each linked list is in the range [1, 100].)",
|
| 869 |
+
"string (e.g. 0 <= Node.val <= 9)"
|
| 870 |
+
],
|
| 871 |
+
"starter_code": "string (Standard Python 3 starter code template ending with 'pass', e.g. class Solution:\\n def addTwoNumbers(self, l1: Optional[ListNode], l2: Optional[ListNode]) -> Optional[ListNode]:\\n pass)",
|
| 872 |
+
"reference_code": "string (Clean, optimal, fully working Python 3 Solution class implementation with comments)"
|
| 873 |
+
}}
|
| 874 |
+
"""
|
| 875 |
+
|
| 876 |
+
try:
|
| 877 |
+
raw_text, _ = await ai_provider.generate_ai_content_async(
|
| 878 |
+
system_instruction=system_instruction,
|
| 879 |
+
user_prompt=user_prompt,
|
| 880 |
+
is_json=True,
|
| 881 |
+
custom_provider=custom_provider,
|
| 882 |
+
custom_api_key=custom_api_key,
|
| 883 |
+
)
|
| 884 |
+
cleaned = ai_provider.clean_json_response(raw_text)
|
| 885 |
+
result = json.loads(cleaned)
|
| 886 |
+
|
| 887 |
+
if "title" in result:
|
| 888 |
+
await ai_cache.set_leetcode_problem_async(clean_input, result)
|
| 889 |
+
if slug != clean_input:
|
| 890 |
+
await ai_cache.set_leetcode_problem_async(slug, result)
|
| 891 |
+
|
| 892 |
+
return result
|
| 893 |
+
except Exception as e:
|
| 894 |
+
logger.error(f"Error fetching LeetCode problem async: {e}")
|
| 895 |
+
return {"error": str(e)}
|
| 896 |
+
|
| 897 |
+
|
| 898 |
+
async def generate_how_to_solve_intuition_async(
|
| 899 |
+
title: str,
|
| 900 |
+
code: str,
|
| 901 |
+
description: str = "",
|
| 902 |
+
custom_api_key: str | None = None,
|
| 903 |
+
custom_provider: str | None = None,
|
| 904 |
+
) -> dict[str, Any]:
|
| 905 |
+
if title and not custom_api_key:
|
| 906 |
+
cached = await ai_cache.get_leetcode_intuition_async(title)
|
| 907 |
+
if cached and isinstance(cached, dict) and "how_to_solve" in cached:
|
| 908 |
+
return cached
|
| 909 |
+
|
| 910 |
+
system_instruction = """
|
| 911 |
+
You are an expert DSA educator. Write a clear, concise, step-by-step intuitive explanation ("How to solve?") for the provided algorithm.
|
| 912 |
+
Focus on the core concept, invariant, or technique used (e.g. dummy node, fast/slow pointers, sliding window bounds, hash map tracking).
|
| 913 |
+
Keep it engaging and accessible. Format in clean paragraphs.
|
| 914 |
+
"""
|
| 915 |
+
|
| 916 |
+
user_prompt = f"""
|
| 917 |
+
Problem: {title}
|
| 918 |
+
Description: {description}
|
| 919 |
+
Code:
|
| 920 |
+
```python
|
| 921 |
+
{code}
|
| 922 |
+
```
|
| 923 |
+
|
| 924 |
+
Provide the "How to solve?" intuition explanation.
|
| 925 |
+
"""
|
| 926 |
+
|
| 927 |
+
try:
|
| 928 |
+
raw_text, _ = await ai_provider.generate_ai_content_async(
|
| 929 |
+
system_instruction=system_instruction,
|
| 930 |
+
user_prompt=user_prompt,
|
| 931 |
+
is_json=False,
|
| 932 |
+
custom_provider=custom_provider,
|
| 933 |
+
custom_api_key=custom_api_key,
|
| 934 |
+
)
|
| 935 |
+
result = {"how_to_solve": raw_text.strip()}
|
| 936 |
+
if title and not custom_api_key:
|
| 937 |
+
await ai_cache.set_leetcode_intuition_async(title, result)
|
| 938 |
+
return result
|
| 939 |
+
except Exception as e:
|
| 940 |
+
logger.error(f"Error generating intuition async: {e}")
|
| 941 |
+
return {"error": str(e)}
|
| 942 |
+
|
| 943 |
+
|
| 944 |
+
async def format_code_with_emoji_comments_async(
|
| 945 |
+
code: str,
|
| 946 |
+
title: str = "",
|
| 947 |
+
custom_api_key: str | None = None,
|
| 948 |
+
custom_provider: str | None = None,
|
| 949 |
+
) -> dict[str, Any]:
|
| 950 |
+
system_instruction = """
|
| 951 |
+
You are an expert Python developer and educator.
|
| 952 |
+
Your task is to take Python solution code and format it cleanly with helpful step-by-step comments that include context-relevant emojis (e.g., 🗺️ for hash map, ➡️ for pointer advancement, 🔢 for computation, 🏷️ for node creation, 🎯 for target match).
|
| 953 |
+
Preserve the exact algorithmic logic and function signature.
|
| 954 |
+
Return ONLY the raw python code (or wrapped in ```python ... ``` which will be stripped).
|
| 955 |
+
"""
|
| 956 |
+
|
| 957 |
+
user_prompt = f"""
|
| 958 |
+
Problem: {title}
|
| 959 |
+
Original Code:
|
| 960 |
+
{code}
|
| 961 |
+
|
| 962 |
+
Add step-by-step numbered/descriptive comments with emojis to the code and ensure standard 4-space indentation.
|
| 963 |
+
"""
|
| 964 |
+
|
| 965 |
+
try:
|
| 966 |
+
raw_text, _ = await ai_provider.generate_ai_content_async(
|
| 967 |
+
system_instruction=system_instruction,
|
| 968 |
+
user_prompt=user_prompt,
|
| 969 |
+
is_json=False,
|
| 970 |
+
custom_provider=custom_provider,
|
| 971 |
+
custom_api_key=custom_api_key,
|
| 972 |
+
)
|
| 973 |
+
raw_text = raw_text.strip()
|
| 974 |
+
raw_text = re.sub(r"^```[a-zA-Z]*\n", "", raw_text)
|
| 975 |
+
raw_text = re.sub(r"\n```$", "", raw_text)
|
| 976 |
+
return {"formatted_code": raw_text.strip()}
|
| 977 |
+
except Exception as e:
|
| 978 |
+
logger.error(f"Error formatting code with emoji comments async: {e}")
|
| 979 |
+
return {"error": str(e)}
|
pyproject.toml
CHANGED
|
@@ -4,7 +4,7 @@ version = "0.1.0"
|
|
| 4 |
description = "Add your description here"
|
| 5 |
readme = "README.md"
|
| 6 |
authors = [
|
| 7 |
-
{ name = "
|
| 8 |
]
|
| 9 |
requires-python = ">=3.14"
|
| 10 |
dependencies = [
|
|
@@ -16,6 +16,7 @@ dependencies = [
|
|
| 16 |
"google-auth-oauthlib>=1.2.0",
|
| 17 |
"google-cloud-firestore>=2.16.0",
|
| 18 |
"google-genai>=0.1.0",
|
|
|
|
| 19 |
"pandas>=2.2.2",
|
| 20 |
"python-dotenv>=1.2.4",
|
| 21 |
"python-multipart>=0.0.9",
|
|
|
|
| 4 |
description = "Add your description here"
|
| 5 |
readme = "README.md"
|
| 6 |
authors = [
|
| 7 |
+
{ name = "iamfebin" }
|
| 8 |
]
|
| 9 |
requires-python = ">=3.14"
|
| 10 |
dependencies = [
|
|
|
|
| 16 |
"google-auth-oauthlib>=1.2.0",
|
| 17 |
"google-cloud-firestore>=2.16.0",
|
| 18 |
"google-genai>=0.1.0",
|
| 19 |
+
"httpx>=0.28.1",
|
| 20 |
"pandas>=2.2.2",
|
| 21 |
"python-dotenv>=1.2.4",
|
| 22 |
"python-multipart>=0.0.9",
|
routers/challenges.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
from datetime import UTC, datetime
|
| 2 |
|
| 3 |
from fastapi import APIRouter, Depends, Header, HTTPException, Request
|
|
@@ -22,7 +23,7 @@ class SubmitPythonRequest(BaseModel):
|
|
| 22 |
|
| 23 |
|
| 24 |
@router.get("/api/challenges/python/daily")
|
| 25 |
-
def get_daily_python_challenge(
|
| 26 |
request: Request,
|
| 27 |
client: Client = Depends(get_auth_session),
|
| 28 |
x_ai_provider: str = Header(None),
|
|
@@ -30,7 +31,8 @@ def get_daily_python_challenge(
|
|
| 30 |
x_gemini_api_key: str = Header(None),
|
| 31 |
):
|
| 32 |
api_key = x_custom_api_key or x_gemini_api_key
|
| 33 |
-
|
|
|
|
| 34 |
custom_api_key=api_key, custom_provider=x_ai_provider
|
| 35 |
)
|
| 36 |
if "error" in challenge:
|
|
@@ -38,15 +40,20 @@ def get_daily_python_challenge(
|
|
| 38 |
status_code=500, detail=f"Failed to generate challenge: {challenge['error']}"
|
| 39 |
)
|
| 40 |
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
| 42 |
completed = False
|
| 43 |
if user_id:
|
| 44 |
try:
|
| 45 |
-
completed =
|
|
|
|
|
|
|
| 46 |
except Exception:
|
| 47 |
pass
|
| 48 |
|
| 49 |
-
score_record = db.get_user_score
|
| 50 |
total_score = score_record["total_score"] if score_record else 0
|
| 51 |
|
| 52 |
return {
|
|
@@ -61,11 +68,13 @@ def get_daily_python_challenge(
|
|
| 61 |
|
| 62 |
|
| 63 |
@router.post("/api/challenges/python/submit")
|
| 64 |
-
def submit_python_challenge(
|
|
|
|
|
|
|
| 65 |
today_str = datetime.now(UTC).strftime("%Y-%m-%d")
|
| 66 |
|
| 67 |
if today_str not in DAILY_PYTHON_CHALLENGE_CACHE:
|
| 68 |
-
challenge = llm_reviewer.
|
| 69 |
if "error" in challenge:
|
| 70 |
raise HTTPException(
|
| 71 |
status_code=500, detail=f"No challenge available: {challenge['error']}"
|
|
@@ -75,7 +84,7 @@ def submit_python_challenge(req: SubmitPythonRequest, client: Client = Depends(g
|
|
| 75 |
challenge = DAILY_PYTHON_CHALLENGE_CACHE[today_str]
|
| 76 |
test_cases = challenge.get("test_cases", [])
|
| 77 |
|
| 78 |
-
run_res = sandbox.
|
| 79 |
|
| 80 |
if not run_res.get("success", False):
|
| 81 |
return {
|
|
@@ -91,22 +100,24 @@ def submit_python_challenge(req: SubmitPythonRequest, client: Client = Depends(g
|
|
| 91 |
completed_before = False
|
| 92 |
total_score = 0
|
| 93 |
|
| 94 |
-
user_id = db.get_current_user_id
|
| 95 |
if all_passed and user_id:
|
| 96 |
title = challenge.get("title", "Daily Python Challenge")
|
| 97 |
points = challenge.get("points", 100)
|
| 98 |
|
| 99 |
try:
|
| 100 |
-
completed_before =
|
|
|
|
|
|
|
| 101 |
except Exception:
|
| 102 |
pass
|
| 103 |
|
| 104 |
if not completed_before:
|
| 105 |
-
db.increment_user_score
|
| 106 |
-
db.add_challenge_history
|
| 107 |
points_awarded = points
|
| 108 |
|
| 109 |
-
score_record = db.get_user_score
|
| 110 |
if score_record:
|
| 111 |
total_score = score_record["total_score"]
|
| 112 |
|
|
@@ -127,7 +138,7 @@ class SQLQueryRequest(BaseModel):
|
|
| 127 |
|
| 128 |
|
| 129 |
@router.post("/api/challenges/mysql/init")
|
| 130 |
-
def init_mysql_challenge(
|
| 131 |
request: Request,
|
| 132 |
refresh: bool = False,
|
| 133 |
client: Client = Depends(get_auth_session),
|
|
@@ -135,13 +146,13 @@ def init_mysql_challenge(
|
|
| 135 |
x_custom_api_key: str = Header(None),
|
| 136 |
x_gemini_api_key: str = Header(None),
|
| 137 |
):
|
| 138 |
-
user_id = db.get_current_user_id
|
| 139 |
if not user_id:
|
| 140 |
raise HTTPException(status_code=401, detail="Authentication failed")
|
| 141 |
|
| 142 |
api_key = x_custom_api_key or x_gemini_api_key
|
| 143 |
check_burst_rate_limit(request, api_key)
|
| 144 |
-
challenge = llm_reviewer.
|
| 145 |
custom_api_key=api_key, custom_provider=x_ai_provider, force_refresh=refresh
|
| 146 |
)
|
| 147 |
if "error" in challenge:
|
|
@@ -149,7 +160,7 @@ def init_mysql_challenge(
|
|
| 149 |
status_code=500, detail=f"Failed to generate SQL challenge: {challenge['error']}"
|
| 150 |
)
|
| 151 |
|
| 152 |
-
init_res = sql_playground.init_user_db
|
| 153 |
if not init_res.get("success", False):
|
| 154 |
raise HTTPException(
|
| 155 |
status_code=500, detail=f"Failed to initialize database: {init_res.get('error')}"
|
|
@@ -157,7 +168,7 @@ def init_mysql_challenge(
|
|
| 157 |
|
| 158 |
ACTIVE_SQL_CHALLENGES[user_id] = challenge
|
| 159 |
|
| 160 |
-
score_record = db.get_user_score
|
| 161 |
total_score = score_record["total_score"] if score_record else 0
|
| 162 |
|
| 163 |
return {
|
|
@@ -172,27 +183,27 @@ def init_mysql_challenge(
|
|
| 172 |
|
| 173 |
|
| 174 |
@router.get("/api/challenges/mysql/status")
|
| 175 |
-
def get_mysql_status(
|
| 176 |
request: Request,
|
| 177 |
client: Client = Depends(get_auth_session),
|
| 178 |
x_ai_provider: str = Header(None),
|
| 179 |
x_custom_api_key: str = Header(None),
|
| 180 |
x_gemini_api_key: str = Header(None),
|
| 181 |
):
|
| 182 |
-
user_id = db.get_current_user_id
|
| 183 |
if not user_id:
|
| 184 |
raise HTTPException(status_code=401, detail="Authentication failed")
|
| 185 |
|
| 186 |
if user_id not in ACTIVE_SQL_CHALLENGES:
|
| 187 |
today_str = datetime.now(UTC).strftime("%Y-%m-%d")
|
| 188 |
-
challenge = ai_cache.
|
| 189 |
if not challenge or not isinstance(challenge, dict) or "title" not in challenge:
|
| 190 |
api_key = x_custom_api_key or x_gemini_api_key
|
| 191 |
-
challenge = llm_reviewer.
|
| 192 |
custom_api_key=api_key, custom_provider=x_ai_provider, force_refresh=False
|
| 193 |
)
|
| 194 |
if challenge and "title" in challenge:
|
| 195 |
-
init_res = sql_playground.init_user_db
|
| 196 |
if init_res.get("success", False):
|
| 197 |
ACTIVE_SQL_CHALLENGES[user_id] = challenge
|
| 198 |
else:
|
|
@@ -210,19 +221,26 @@ def get_mysql_status(
|
|
| 210 |
|
| 211 |
schema = {}
|
| 212 |
try:
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
except Exception:
|
| 217 |
pass
|
| 218 |
|
| 219 |
completed = False
|
| 220 |
try:
|
| 221 |
-
completed =
|
|
|
|
|
|
|
| 222 |
except Exception:
|
| 223 |
pass
|
| 224 |
|
| 225 |
-
score_record = db.get_user_score
|
| 226 |
total_score = score_record["total_score"] if score_record else 0
|
| 227 |
|
| 228 |
return {
|
|
@@ -238,17 +256,22 @@ def get_mysql_status(
|
|
| 238 |
|
| 239 |
|
| 240 |
@router.post("/api/challenges/mysql/query")
|
| 241 |
-
def run_mysql_query(req: SQLQueryRequest, client: Client = Depends(get_auth_session)):
|
| 242 |
-
user_id = db.get_current_user_id
|
| 243 |
if not user_id:
|
| 244 |
raise HTTPException(status_code=401, detail="Authentication failed")
|
| 245 |
|
| 246 |
if user_id not in ACTIVE_SQL_CHALLENGES:
|
| 247 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 248 |
|
| 249 |
challenge = ACTIVE_SQL_CHALLENGES[user_id]
|
| 250 |
|
| 251 |
-
run_res = sql_playground.run_user_query
|
| 252 |
|
| 253 |
if not run_res.get("success", False):
|
| 254 |
return {"success": False, "error": run_res.get("error", "Unknown database error")}
|
|
@@ -263,16 +286,18 @@ def run_mysql_query(req: SQLQueryRequest, client: Client = Depends(get_auth_sess
|
|
| 263 |
points = challenge.get("points", 150)
|
| 264 |
|
| 265 |
try:
|
| 266 |
-
completed_before =
|
|
|
|
|
|
|
| 267 |
except Exception:
|
| 268 |
pass
|
| 269 |
|
| 270 |
if not completed_before:
|
| 271 |
-
db.increment_user_score
|
| 272 |
-
db.add_challenge_history
|
| 273 |
points_awarded = points
|
| 274 |
|
| 275 |
-
score_record = db.get_user_score
|
| 276 |
if score_record:
|
| 277 |
total_score = score_record["total_score"]
|
| 278 |
|
|
@@ -290,17 +315,20 @@ def run_mysql_query(req: SQLQueryRequest, client: Client = Depends(get_auth_sess
|
|
| 290 |
|
| 291 |
|
| 292 |
@router.get("/api/scores")
|
| 293 |
-
def get_user_scores(client: Client = Depends(get_auth_session)):
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
|
|
|
|
|
|
|
|
|
| 302 |
|
| 303 |
|
| 304 |
@router.get("/api/scores/history")
|
| 305 |
-
def get_user_challenge_history(client: Client = Depends(get_auth_session)):
|
| 306 |
-
return db.get_challenge_history
|
|
|
|
| 1 |
+
import asyncio
|
| 2 |
from datetime import UTC, datetime
|
| 3 |
|
| 4 |
from fastapi import APIRouter, Depends, Header, HTTPException, Request
|
|
|
|
| 23 |
|
| 24 |
|
| 25 |
@router.get("/api/challenges/python/daily")
|
| 26 |
+
async def get_daily_python_challenge(
|
| 27 |
request: Request,
|
| 28 |
client: Client = Depends(get_auth_session),
|
| 29 |
x_ai_provider: str = Header(None),
|
|
|
|
| 31 |
x_gemini_api_key: str = Header(None),
|
| 32 |
):
|
| 33 |
api_key = x_custom_api_key or x_gemini_api_key
|
| 34 |
+
check_burst_rate_limit(request, api_key)
|
| 35 |
+
challenge = await llm_reviewer.generate_daily_python_challenge_async(
|
| 36 |
custom_api_key=api_key, custom_provider=x_ai_provider
|
| 37 |
)
|
| 38 |
if "error" in challenge:
|
|
|
|
| 40 |
status_code=500, detail=f"Failed to generate challenge: {challenge['error']}"
|
| 41 |
)
|
| 42 |
|
| 43 |
+
today_str = datetime.now(UTC).strftime("%Y-%m-%d")
|
| 44 |
+
DAILY_PYTHON_CHALLENGE_CACHE[today_str] = challenge
|
| 45 |
+
|
| 46 |
+
user_id = await asyncio.to_thread(db.get_current_user_id, client)
|
| 47 |
completed = False
|
| 48 |
if user_id:
|
| 49 |
try:
|
| 50 |
+
completed = await asyncio.to_thread(
|
| 51 |
+
db.has_completed_challenge, "python", challenge.get("title", ""), client
|
| 52 |
+
)
|
| 53 |
except Exception:
|
| 54 |
pass
|
| 55 |
|
| 56 |
+
score_record = await asyncio.to_thread(db.get_user_score, client)
|
| 57 |
total_score = score_record["total_score"] if score_record else 0
|
| 58 |
|
| 59 |
return {
|
|
|
|
| 68 |
|
| 69 |
|
| 70 |
@router.post("/api/challenges/python/submit")
|
| 71 |
+
async def submit_python_challenge(
|
| 72 |
+
req: SubmitPythonRequest, client: Client = Depends(get_auth_session)
|
| 73 |
+
):
|
| 74 |
today_str = datetime.now(UTC).strftime("%Y-%m-%d")
|
| 75 |
|
| 76 |
if today_str not in DAILY_PYTHON_CHALLENGE_CACHE:
|
| 77 |
+
challenge = await llm_reviewer.generate_daily_python_challenge_async()
|
| 78 |
if "error" in challenge:
|
| 79 |
raise HTTPException(
|
| 80 |
status_code=500, detail=f"No challenge available: {challenge['error']}"
|
|
|
|
| 84 |
challenge = DAILY_PYTHON_CHALLENGE_CACHE[today_str]
|
| 85 |
test_cases = challenge.get("test_cases", [])
|
| 86 |
|
| 87 |
+
run_res = await sandbox.run_python_sandbox_async(req.code, test_cases)
|
| 88 |
|
| 89 |
if not run_res.get("success", False):
|
| 90 |
return {
|
|
|
|
| 100 |
completed_before = False
|
| 101 |
total_score = 0
|
| 102 |
|
| 103 |
+
user_id = await asyncio.to_thread(db.get_current_user_id, client)
|
| 104 |
if all_passed and user_id:
|
| 105 |
title = challenge.get("title", "Daily Python Challenge")
|
| 106 |
points = challenge.get("points", 100)
|
| 107 |
|
| 108 |
try:
|
| 109 |
+
completed_before = await asyncio.to_thread(
|
| 110 |
+
db.has_completed_challenge, "python", title, client
|
| 111 |
+
)
|
| 112 |
except Exception:
|
| 113 |
pass
|
| 114 |
|
| 115 |
if not completed_before:
|
| 116 |
+
await asyncio.to_thread(db.increment_user_score, points, "python", client)
|
| 117 |
+
await asyncio.to_thread(db.add_challenge_history, "python", title, points, client)
|
| 118 |
points_awarded = points
|
| 119 |
|
| 120 |
+
score_record = await asyncio.to_thread(db.get_user_score, client)
|
| 121 |
if score_record:
|
| 122 |
total_score = score_record["total_score"]
|
| 123 |
|
|
|
|
| 138 |
|
| 139 |
|
| 140 |
@router.post("/api/challenges/mysql/init")
|
| 141 |
+
async def init_mysql_challenge(
|
| 142 |
request: Request,
|
| 143 |
refresh: bool = False,
|
| 144 |
client: Client = Depends(get_auth_session),
|
|
|
|
| 146 |
x_custom_api_key: str = Header(None),
|
| 147 |
x_gemini_api_key: str = Header(None),
|
| 148 |
):
|
| 149 |
+
user_id = await asyncio.to_thread(db.get_current_user_id, client)
|
| 150 |
if not user_id:
|
| 151 |
raise HTTPException(status_code=401, detail="Authentication failed")
|
| 152 |
|
| 153 |
api_key = x_custom_api_key or x_gemini_api_key
|
| 154 |
check_burst_rate_limit(request, api_key)
|
| 155 |
+
challenge = await llm_reviewer.generate_sql_challenge_async(
|
| 156 |
custom_api_key=api_key, custom_provider=x_ai_provider, force_refresh=refresh
|
| 157 |
)
|
| 158 |
if "error" in challenge:
|
|
|
|
| 160 |
status_code=500, detail=f"Failed to generate SQL challenge: {challenge['error']}"
|
| 161 |
)
|
| 162 |
|
| 163 |
+
init_res = await asyncio.to_thread(sql_playground.init_user_db, user_id, challenge)
|
| 164 |
if not init_res.get("success", False):
|
| 165 |
raise HTTPException(
|
| 166 |
status_code=500, detail=f"Failed to initialize database: {init_res.get('error')}"
|
|
|
|
| 168 |
|
| 169 |
ACTIVE_SQL_CHALLENGES[user_id] = challenge
|
| 170 |
|
| 171 |
+
score_record = await asyncio.to_thread(db.get_user_score, client)
|
| 172 |
total_score = score_record["total_score"] if score_record else 0
|
| 173 |
|
| 174 |
return {
|
|
|
|
| 183 |
|
| 184 |
|
| 185 |
@router.get("/api/challenges/mysql/status")
|
| 186 |
+
async def get_mysql_status(
|
| 187 |
request: Request,
|
| 188 |
client: Client = Depends(get_auth_session),
|
| 189 |
x_ai_provider: str = Header(None),
|
| 190 |
x_custom_api_key: str = Header(None),
|
| 191 |
x_gemini_api_key: str = Header(None),
|
| 192 |
):
|
| 193 |
+
user_id = await asyncio.to_thread(db.get_current_user_id, client)
|
| 194 |
if not user_id:
|
| 195 |
raise HTTPException(status_code=401, detail="Authentication failed")
|
| 196 |
|
| 197 |
if user_id not in ACTIVE_SQL_CHALLENGES:
|
| 198 |
today_str = datetime.now(UTC).strftime("%Y-%m-%d")
|
| 199 |
+
challenge = await ai_cache.get_daily_sql_challenge_async(today_str)
|
| 200 |
if not challenge or not isinstance(challenge, dict) or "title" not in challenge:
|
| 201 |
api_key = x_custom_api_key or x_gemini_api_key
|
| 202 |
+
challenge = await llm_reviewer.generate_sql_challenge_async(
|
| 203 |
custom_api_key=api_key, custom_provider=x_ai_provider, force_refresh=False
|
| 204 |
)
|
| 205 |
if challenge and "title" in challenge:
|
| 206 |
+
init_res = await asyncio.to_thread(sql_playground.init_user_db, user_id, challenge)
|
| 207 |
if init_res.get("success", False):
|
| 208 |
ACTIVE_SQL_CHALLENGES[user_id] = challenge
|
| 209 |
else:
|
|
|
|
| 221 |
|
| 222 |
schema = {}
|
| 223 |
try:
|
| 224 |
+
def _get_schema():
|
| 225 |
+
conn = sql_playground.get_connection(user_id)
|
| 226 |
+
try:
|
| 227 |
+
return sql_playground.get_db_schema(conn)
|
| 228 |
+
finally:
|
| 229 |
+
conn.close()
|
| 230 |
+
|
| 231 |
+
schema = await asyncio.to_thread(_get_schema)
|
| 232 |
except Exception:
|
| 233 |
pass
|
| 234 |
|
| 235 |
completed = False
|
| 236 |
try:
|
| 237 |
+
completed = await asyncio.to_thread(
|
| 238 |
+
db.has_completed_challenge, "mysql", challenge.get("title", ""), client
|
| 239 |
+
)
|
| 240 |
except Exception:
|
| 241 |
pass
|
| 242 |
|
| 243 |
+
score_record = await asyncio.to_thread(db.get_user_score, client)
|
| 244 |
total_score = score_record["total_score"] if score_record else 0
|
| 245 |
|
| 246 |
return {
|
|
|
|
| 256 |
|
| 257 |
|
| 258 |
@router.post("/api/challenges/mysql/query")
|
| 259 |
+
async def run_mysql_query(req: SQLQueryRequest, client: Client = Depends(get_auth_session)):
|
| 260 |
+
user_id = await asyncio.to_thread(db.get_current_user_id, client)
|
| 261 |
if not user_id:
|
| 262 |
raise HTTPException(status_code=401, detail="Authentication failed")
|
| 263 |
|
| 264 |
if user_id not in ACTIVE_SQL_CHALLENGES:
|
| 265 |
+
today_str = datetime.now(UTC).strftime("%Y-%m-%d")
|
| 266 |
+
cached_challenge = await ai_cache.get_daily_sql_challenge_async(today_str)
|
| 267 |
+
if cached_challenge and isinstance(cached_challenge, dict) and "title" in cached_challenge:
|
| 268 |
+
ACTIVE_SQL_CHALLENGES[user_id] = cached_challenge
|
| 269 |
+
else:
|
| 270 |
+
raise HTTPException(status_code=400, detail="No active SQL session. Type 'db init' first.")
|
| 271 |
|
| 272 |
challenge = ACTIVE_SQL_CHALLENGES[user_id]
|
| 273 |
|
| 274 |
+
run_res = await asyncio.to_thread(sql_playground.run_user_query, user_id, req.query, challenge)
|
| 275 |
|
| 276 |
if not run_res.get("success", False):
|
| 277 |
return {"success": False, "error": run_res.get("error", "Unknown database error")}
|
|
|
|
| 286 |
points = challenge.get("points", 150)
|
| 287 |
|
| 288 |
try:
|
| 289 |
+
completed_before = await asyncio.to_thread(
|
| 290 |
+
db.has_completed_challenge, "mysql", title, client
|
| 291 |
+
)
|
| 292 |
except Exception:
|
| 293 |
pass
|
| 294 |
|
| 295 |
if not completed_before:
|
| 296 |
+
await asyncio.to_thread(db.increment_user_score, points, "mysql", client)
|
| 297 |
+
await asyncio.to_thread(db.add_challenge_history, "mysql", title, points, client)
|
| 298 |
points_awarded = points
|
| 299 |
|
| 300 |
+
score_record = await asyncio.to_thread(db.get_user_score, client)
|
| 301 |
if score_record:
|
| 302 |
total_score = score_record["total_score"]
|
| 303 |
|
|
|
|
| 315 |
|
| 316 |
|
| 317 |
@router.get("/api/scores")
|
| 318 |
+
async def get_user_scores(client: Client = Depends(get_auth_session)):
|
| 319 |
+
def _fetch_scores():
|
| 320 |
+
user_id = db.get_current_user_id(client)
|
| 321 |
+
score_data = db.get_user_score(client)
|
| 322 |
+
return score_data or {
|
| 323 |
+
"user_id": user_id,
|
| 324 |
+
"total_score": 0,
|
| 325 |
+
"python_challenges_completed": 0,
|
| 326 |
+
"sql_challenges_completed": 0,
|
| 327 |
+
}
|
| 328 |
+
|
| 329 |
+
return await asyncio.to_thread(_fetch_scores)
|
| 330 |
|
| 331 |
|
| 332 |
@router.get("/api/scores/history")
|
| 333 |
+
async def get_user_challenge_history(client: Client = Depends(get_auth_session)):
|
| 334 |
+
return await asyncio.to_thread(db.get_challenge_history, client)
|
routers/companion.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import json
|
| 2 |
import logging
|
| 3 |
import os
|
|
@@ -85,13 +86,58 @@ def _load_telemetry():
|
|
| 85 |
_load_telemetry()
|
| 86 |
|
| 87 |
|
| 88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
try:
|
| 90 |
-
os.
|
| 91 |
-
|
| 92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
except Exception as e:
|
| 94 |
logger.warning(f"Failed to save telemetry logs: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
|
| 96 |
|
| 97 |
def record_tool_telemetry(event_dict: dict):
|
|
@@ -101,17 +147,17 @@ def record_tool_telemetry(event_dict: dict):
|
|
| 101 |
_telemetry_events.append(event_dict)
|
| 102 |
if len(_telemetry_events) > 500:
|
| 103 |
_telemetry_events.pop(0)
|
| 104 |
-
|
| 105 |
|
| 106 |
|
| 107 |
@router.post("/api/companion/telemetry")
|
| 108 |
-
def log_companion_telemetry(event: CompanionTelemetryEvent):
|
| 109 |
record_tool_telemetry(event.dict())
|
| 110 |
return {"status": "ok", "recorded": event.tool_name}
|
| 111 |
|
| 112 |
|
| 113 |
@router.get("/api/companion/telemetry")
|
| 114 |
-
def get_companion_telemetry():
|
| 115 |
with _telemetry_lock:
|
| 116 |
total = len(_telemetry_events)
|
| 117 |
tool_counts = defaultdict(int)
|
|
@@ -277,7 +323,7 @@ def build_companion_prompt(payload: CompanionChatRequest):
|
|
| 277 |
|
| 278 |
|
| 279 |
@router.post("/api/companion/chat")
|
| 280 |
-
def companion_chat(
|
| 281 |
payload: CompanionChatRequest,
|
| 282 |
request: Request,
|
| 283 |
user_session=Depends(get_auth_session),
|
|
@@ -291,7 +337,7 @@ def companion_chat(
|
|
| 291 |
system_instruction, user_prompt, hero_name, valid_emotions = build_companion_prompt(payload)
|
| 292 |
|
| 293 |
try:
|
| 294 |
-
raw_text, provider_used = ai_provider.
|
| 295 |
system_instruction=system_instruction,
|
| 296 |
user_prompt=user_prompt,
|
| 297 |
is_json=True,
|
|
@@ -345,7 +391,7 @@ def companion_chat(
|
|
| 345 |
|
| 346 |
|
| 347 |
@router.post("/api/companion/chat/stream")
|
| 348 |
-
def companion_chat_stream(
|
| 349 |
payload: CompanionChatRequest,
|
| 350 |
request: Request,
|
| 351 |
user_session=Depends(get_auth_session),
|
|
@@ -358,7 +404,7 @@ def companion_chat_stream(
|
|
| 358 |
|
| 359 |
system_instruction, user_prompt, hero_name, valid_emotions = build_companion_prompt(payload)
|
| 360 |
|
| 361 |
-
def event_generator():
|
| 362 |
full_text_acc = ""
|
| 363 |
yielded_text_len = 0
|
| 364 |
provider_used = "gemini (server)"
|
|
@@ -368,7 +414,7 @@ def companion_chat_stream(
|
|
| 368 |
text_regex = re.compile(r'"text"\s*:\s*"((?:[^"\\]|\\.)*)', re.DOTALL)
|
| 369 |
|
| 370 |
try:
|
| 371 |
-
for chunk, prov in ai_provider.
|
| 372 |
system_instruction=system_instruction,
|
| 373 |
user_prompt=user_prompt,
|
| 374 |
is_json=True,
|
|
|
|
| 1 |
+
import asyncio
|
| 2 |
import json
|
| 3 |
import logging
|
| 4 |
import os
|
|
|
|
| 86 |
_load_telemetry()
|
| 87 |
|
| 88 |
|
| 89 |
+
_disk_write_lock = threading.Lock()
|
| 90 |
+
_save_in_progress = False
|
| 91 |
+
_has_pending_save = False
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
def _write_telemetry_disk(events_snapshot: list[dict]):
|
| 95 |
+
temp_file = None
|
| 96 |
try:
|
| 97 |
+
dir_name = os.path.dirname(TELEMETRY_FILE)
|
| 98 |
+
os.makedirs(dir_name, exist_ok=True)
|
| 99 |
+
temp_file = os.path.join(
|
| 100 |
+
dir_name, f"companion_telemetry_{os.getpid()}_{threading.get_ident()}.tmp"
|
| 101 |
+
)
|
| 102 |
+
with open(temp_file, "w", encoding="utf-8") as f:
|
| 103 |
+
json.dump(events_snapshot, f, indent=2)
|
| 104 |
+
os.replace(temp_file, TELEMETRY_FILE)
|
| 105 |
except Exception as e:
|
| 106 |
logger.warning(f"Failed to save telemetry logs: {e}")
|
| 107 |
+
if temp_file and os.path.exists(temp_file):
|
| 108 |
+
try:
|
| 109 |
+
os.unlink(temp_file)
|
| 110 |
+
except Exception:
|
| 111 |
+
pass
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
def _run_disk_writer():
|
| 115 |
+
global _save_in_progress, _has_pending_save
|
| 116 |
+
with _disk_write_lock:
|
| 117 |
+
while True:
|
| 118 |
+
with _telemetry_lock:
|
| 119 |
+
snapshot = list(_telemetry_events[-500:])
|
| 120 |
+
_has_pending_save = False
|
| 121 |
+
_write_telemetry_disk(snapshot)
|
| 122 |
+
with _telemetry_lock:
|
| 123 |
+
if not _has_pending_save:
|
| 124 |
+
_save_in_progress = False
|
| 125 |
+
break
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
def _save_telemetry():
|
| 129 |
+
global _save_in_progress, _has_pending_save
|
| 130 |
+
with _telemetry_lock:
|
| 131 |
+
_has_pending_save = True
|
| 132 |
+
if _save_in_progress:
|
| 133 |
+
return
|
| 134 |
+
_save_in_progress = True
|
| 135 |
+
|
| 136 |
+
try:
|
| 137 |
+
loop = asyncio.get_running_loop()
|
| 138 |
+
loop.create_task(asyncio.to_thread(_run_disk_writer))
|
| 139 |
+
except RuntimeError:
|
| 140 |
+
threading.Thread(target=_run_disk_writer, daemon=True).start()
|
| 141 |
|
| 142 |
|
| 143 |
def record_tool_telemetry(event_dict: dict):
|
|
|
|
| 147 |
_telemetry_events.append(event_dict)
|
| 148 |
if len(_telemetry_events) > 500:
|
| 149 |
_telemetry_events.pop(0)
|
| 150 |
+
_save_telemetry()
|
| 151 |
|
| 152 |
|
| 153 |
@router.post("/api/companion/telemetry")
|
| 154 |
+
async def log_companion_telemetry(event: CompanionTelemetryEvent):
|
| 155 |
record_tool_telemetry(event.dict())
|
| 156 |
return {"status": "ok", "recorded": event.tool_name}
|
| 157 |
|
| 158 |
|
| 159 |
@router.get("/api/companion/telemetry")
|
| 160 |
+
async def get_companion_telemetry():
|
| 161 |
with _telemetry_lock:
|
| 162 |
total = len(_telemetry_events)
|
| 163 |
tool_counts = defaultdict(int)
|
|
|
|
| 323 |
|
| 324 |
|
| 325 |
@router.post("/api/companion/chat")
|
| 326 |
+
async def companion_chat(
|
| 327 |
payload: CompanionChatRequest,
|
| 328 |
request: Request,
|
| 329 |
user_session=Depends(get_auth_session),
|
|
|
|
| 337 |
system_instruction, user_prompt, hero_name, valid_emotions = build_companion_prompt(payload)
|
| 338 |
|
| 339 |
try:
|
| 340 |
+
raw_text, provider_used = await ai_provider.generate_ai_content_async(
|
| 341 |
system_instruction=system_instruction,
|
| 342 |
user_prompt=user_prompt,
|
| 343 |
is_json=True,
|
|
|
|
| 391 |
|
| 392 |
|
| 393 |
@router.post("/api/companion/chat/stream")
|
| 394 |
+
async def companion_chat_stream(
|
| 395 |
payload: CompanionChatRequest,
|
| 396 |
request: Request,
|
| 397 |
user_session=Depends(get_auth_session),
|
|
|
|
| 404 |
|
| 405 |
system_instruction, user_prompt, hero_name, valid_emotions = build_companion_prompt(payload)
|
| 406 |
|
| 407 |
+
async def event_generator():
|
| 408 |
full_text_acc = ""
|
| 409 |
yielded_text_len = 0
|
| 410 |
provider_used = "gemini (server)"
|
|
|
|
| 414 |
text_regex = re.compile(r'"text"\s*:\s*"((?:[^"\\]|\\.)*)', re.DOTALL)
|
| 415 |
|
| 416 |
try:
|
| 417 |
+
async for chunk, prov in ai_provider.stream_ai_content_async(
|
| 418 |
system_instruction=system_instruction,
|
| 419 |
user_prompt=user_prompt,
|
| 420 |
is_json=True,
|
routers/explorer.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import csv
|
| 2 |
import io
|
| 3 |
import os
|
|
@@ -71,7 +72,7 @@ class AssistFieldRequest(BaseModel):
|
|
| 71 |
|
| 72 |
|
| 73 |
@router.post("/api/explorer/problems/fetch-leetcode")
|
| 74 |
-
def fetch_leetcode_endpoint(
|
| 75 |
req: FetchLeetCodeRequest,
|
| 76 |
request: Request,
|
| 77 |
x_ai_provider: str = Header(None),
|
|
@@ -82,7 +83,7 @@ def fetch_leetcode_endpoint(
|
|
| 82 |
raise HTTPException(status_code=400, detail="Query cannot be empty")
|
| 83 |
api_key = x_custom_api_key or x_gemini_api_key
|
| 84 |
check_burst_rate_limit(request, api_key)
|
| 85 |
-
res = llm_reviewer.
|
| 86 |
req.query, custom_api_key=api_key, custom_provider=x_ai_provider
|
| 87 |
)
|
| 88 |
if "error" in res:
|
|
@@ -91,7 +92,7 @@ def fetch_leetcode_endpoint(
|
|
| 91 |
|
| 92 |
|
| 93 |
@router.post("/api/explorer/problems/prefill")
|
| 94 |
-
def prefill_problem_endpoint(
|
| 95 |
req: PrefillProblemRequest,
|
| 96 |
request: Request,
|
| 97 |
x_ai_provider: str = Header(None),
|
|
@@ -101,11 +102,11 @@ def prefill_problem_endpoint(
|
|
| 101 |
api_key = x_custom_api_key or x_gemini_api_key
|
| 102 |
check_burst_rate_limit(request, api_key)
|
| 103 |
if req.name.strip().startswith("http") or "leetcode.com" in req.name:
|
| 104 |
-
res = llm_reviewer.
|
| 105 |
req.name, custom_api_key=api_key, custom_provider=x_ai_provider
|
| 106 |
)
|
| 107 |
else:
|
| 108 |
-
res = llm_reviewer.
|
| 109 |
req.name, req.code, custom_api_key=api_key, custom_provider=x_ai_provider
|
| 110 |
)
|
| 111 |
if "error" in res:
|
|
@@ -114,7 +115,7 @@ def prefill_problem_endpoint(
|
|
| 114 |
|
| 115 |
|
| 116 |
@router.post("/api/explorer/problems/assist-field")
|
| 117 |
-
def assist_field_endpoint(
|
| 118 |
req: AssistFieldRequest,
|
| 119 |
request: Request,
|
| 120 |
x_ai_provider: str = Header(None),
|
|
@@ -124,7 +125,7 @@ def assist_field_endpoint(
|
|
| 124 |
api_key = x_custom_api_key or x_gemini_api_key
|
| 125 |
check_burst_rate_limit(request, api_key)
|
| 126 |
if req.field == "intuition":
|
| 127 |
-
res = llm_reviewer.
|
| 128 |
req.title,
|
| 129 |
req.code,
|
| 130 |
req.description,
|
|
@@ -132,7 +133,7 @@ def assist_field_endpoint(
|
|
| 132 |
custom_provider=x_ai_provider,
|
| 133 |
)
|
| 134 |
elif req.field == "comments":
|
| 135 |
-
res = llm_reviewer.
|
| 136 |
req.code, req.title, custom_api_key=api_key, custom_provider=x_ai_provider
|
| 137 |
)
|
| 138 |
else:
|
|
@@ -143,27 +144,29 @@ def assist_field_endpoint(
|
|
| 143 |
|
| 144 |
|
| 145 |
@router.get("/api/explorer/problems")
|
| 146 |
-
def get_explorer_problems(client: Client = Depends(get_auth_session)):
|
| 147 |
try:
|
| 148 |
-
return db.get_all_problems_with_reviews
|
| 149 |
except Exception as e:
|
| 150 |
raise HTTPException(status_code=500, detail=str(e))
|
| 151 |
|
| 152 |
|
| 153 |
@router.post("/api/explorer/problems/create")
|
| 154 |
-
def create_explorer_problem(
|
| 155 |
-
|
|
|
|
|
|
|
| 156 |
if not user_id:
|
| 157 |
raise HTTPException(status_code=401, detail="Authentication failed")
|
| 158 |
|
| 159 |
if not req.name.strip():
|
| 160 |
raise HTTPException(status_code=400, detail="Problem name cannot be empty")
|
| 161 |
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
|
|
|
| 165 |
|
| 166 |
-
try:
|
| 167 |
prob_data = {
|
| 168 |
"name": req.name.strip(),
|
| 169 |
"pattern": req.pattern.strip() or "General",
|
|
@@ -181,7 +184,7 @@ def create_explorer_problem(req: CreateProblemRequest, client: Client = Depends(
|
|
| 181 |
prob_data["solutions"] = req.solutions
|
| 182 |
res_prob = db.insert_problem(prob_data, client)
|
| 183 |
if not res_prob or not res_prob.data:
|
| 184 |
-
raise
|
| 185 |
|
| 186 |
new_prob_id = res_prob.data[0]["id"]
|
| 187 |
|
|
@@ -193,12 +196,19 @@ def create_explorer_problem(req: CreateProblemRequest, client: Client = Depends(
|
|
| 193 |
"total_attempts": 0,
|
| 194 |
}
|
| 195 |
db.insert_review(review_data, client)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 196 |
|
| 197 |
# Dual-Write: Append/Update to Google Doc if requested
|
| 198 |
gdoc_result = None
|
| 199 |
if req.sync_to_gdoc:
|
| 200 |
try:
|
| 201 |
-
gdoc_result =
|
|
|
|
| 202 |
doc_id=req.google_doc_id,
|
| 203 |
problem_number=req.problem_number,
|
| 204 |
problem_name=req.name,
|
|
@@ -214,7 +224,8 @@ def create_explorer_problem(req: CreateProblemRequest, client: Client = Depends(
|
|
| 214 |
method_name=req.pattern,
|
| 215 |
)
|
| 216 |
if gdoc_result and gdoc_result.get("doc_url"):
|
| 217 |
-
|
|
|
|
| 218 |
new_prob_id,
|
| 219 |
{
|
| 220 |
"google_doc_url": gdoc_result["doc_url"],
|
|
@@ -223,9 +234,13 @@ def create_explorer_problem(req: CreateProblemRequest, client: Client = Depends(
|
|
| 223 |
client,
|
| 224 |
)
|
| 225 |
except Exception as e:
|
| 226 |
-
db.log_trace
|
| 227 |
|
| 228 |
return {"success": True, "problem_id": new_prob_id, "gdoc_result": gdoc_result}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 229 |
except Exception as e:
|
| 230 |
raise HTTPException(status_code=500, detail=str(e))
|
| 231 |
|
|
@@ -334,39 +349,42 @@ def update_explorer_problem(
|
|
| 334 |
|
| 335 |
|
| 336 |
@router.get("/api/explorer/export")
|
| 337 |
-
def export_solutions_zip(client: Client = Depends(get_auth_session)):
|
| 338 |
-
user_id = db.get_current_user_id
|
| 339 |
if not user_id:
|
| 340 |
raise HTTPException(status_code=401, detail="Authentication failed")
|
| 341 |
|
| 342 |
try:
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
|
|
|
|
|
|
|
|
|
| 370 |
|
| 371 |
headers = {"Content-Disposition": "attachment; filename=algospaced_solutions.zip"}
|
| 372 |
return StreamingResponse(zip_buffer, media_type="application/zip", headers=headers)
|
|
@@ -375,225 +393,241 @@ def export_solutions_zip(client: Client = Depends(get_auth_session)):
|
|
| 375 |
|
| 376 |
|
| 377 |
@router.post("/api/explorer/import")
|
| 378 |
-
def import_problems(file: UploadFile = File(...), client: Client = Depends(get_auth_session)):
|
| 379 |
-
user_id = db.get_current_user_id
|
| 380 |
if not user_id:
|
| 381 |
raise HTTPException(status_code=401, detail="Authentication failed")
|
| 382 |
|
| 383 |
-
filename = file.filename
|
| 384 |
try:
|
| 385 |
-
contents = file.
|
| 386 |
if filename.lower().endswith(".csv"):
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
# Try to sniff delimiter, fallback to comma
|
| 390 |
-
try:
|
| 391 |
-
dialect = csv.Sniffer().sniff(decoded[:1024], delimiters=[",", ";", "\t"])
|
| 392 |
-
except Exception:
|
| 393 |
-
dialect = csv.excel
|
| 394 |
|
| 395 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 396 |
|
| 397 |
-
|
| 398 |
-
for col in reader.fieldnames or []:
|
| 399 |
-
col_lower = (
|
| 400 |
-
col.strip().lower().replace("_", " ").replace("&", "").replace(" ", " ")
|
| 401 |
-
)
|
| 402 |
-
if col_lower in ("name", "title", "problem name", "problem_name"):
|
| 403 |
-
field_mapping["name"] = col
|
| 404 |
-
elif col_lower in (
|
| 405 |
-
"problem_number",
|
| 406 |
-
"number",
|
| 407 |
-
"id",
|
| 408 |
-
"leetcode_number",
|
| 409 |
-
"problem number",
|
| 410 |
-
"leetcode id",
|
| 411 |
-
):
|
| 412 |
-
field_mapping["problem_number"] = col
|
| 413 |
-
elif col_lower in ("pattern", "category", "topic", "tag"):
|
| 414 |
-
field_mapping["pattern"] = col
|
| 415 |
-
elif col_lower in ("difficulty", "level"):
|
| 416 |
-
field_mapping["difficulty"] = col
|
| 417 |
-
elif col_lower in (
|
| 418 |
-
"optimal_time",
|
| 419 |
-
"time complexity",
|
| 420 |
-
"time_complexity",
|
| 421 |
-
"time",
|
| 422 |
-
"optimal time",
|
| 423 |
-
):
|
| 424 |
-
field_mapping["optimal_time"] = col
|
| 425 |
-
elif col_lower in (
|
| 426 |
-
"optimal_space",
|
| 427 |
-
"space complexity",
|
| 428 |
-
"space_complexity",
|
| 429 |
-
"space",
|
| 430 |
-
"optimal space",
|
| 431 |
-
):
|
| 432 |
-
field_mapping["optimal_space"] = col
|
| 433 |
-
elif col_lower in (
|
| 434 |
-
"reference_code",
|
| 435 |
-
"code",
|
| 436 |
-
"solution",
|
| 437 |
-
"reference code",
|
| 438 |
-
"python solution",
|
| 439 |
-
):
|
| 440 |
-
field_mapping["reference_code"] = col
|
| 441 |
-
elif col_lower in ("description", "notes", "doc description", "doc_description"):
|
| 442 |
-
field_mapping["description"] = col
|
| 443 |
-
|
| 444 |
-
imported_count = 0
|
| 445 |
-
for row in reader:
|
| 446 |
-
name = row.get(field_mapping.get("name", "name"), "").strip()
|
| 447 |
-
if not name:
|
| 448 |
-
name = row.get("name", row.get("title", "")).strip()
|
| 449 |
-
if not name:
|
| 450 |
-
continue
|
| 451 |
-
|
| 452 |
-
prob_num_str = row.get(
|
| 453 |
-
field_mapping.get("problem_number", "problem_number"), ""
|
| 454 |
-
).strip()
|
| 455 |
-
if not prob_num_str:
|
| 456 |
-
prob_num_str = row.get("problem_number", row.get("number", ""))
|
| 457 |
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 462 |
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
row.get(field_mapping.get("
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
|
| 470 |
-
|
| 471 |
-
row.get(
|
| 472 |
-
|
| 473 |
-
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
|
| 480 |
-
|
| 481 |
-
|
| 482 |
-
|
| 483 |
-
|
| 484 |
-
"
|
| 485 |
-
|
| 486 |
-
|
| 487 |
-
"
|
| 488 |
-
|
| 489 |
-
|
| 490 |
-
|
| 491 |
-
|
| 492 |
-
|
| 493 |
-
|
| 494 |
-
|
| 495 |
-
|
| 496 |
-
|
| 497 |
-
"
|
| 498 |
-
|
| 499 |
-
|
| 500 |
-
|
| 501 |
-
|
| 502 |
-
|
| 503 |
-
|
| 504 |
-
|
| 505 |
-
|
| 506 |
-
|
| 507 |
-
|
| 508 |
-
|
| 509 |
-
new_prob_id = res_p.data[0]["id"]
|
| 510 |
-
review_data = {
|
| 511 |
-
"problem_id": new_prob_id,
|
| 512 |
-
"box_level": 1,
|
| 513 |
-
"next_review": datetime.now(UTC).isoformat(),
|
| 514 |
-
"times_correct": 0,
|
| 515 |
-
"total_attempts": 0,
|
| 516 |
}
|
| 517 |
-
|
| 518 |
-
|
| 519 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 520 |
raise HTTPException(
|
| 521 |
status_code=400,
|
| 522 |
detail="No valid problems found in the CSV. Make sure it has a 'name' or 'title' column.",
|
| 523 |
)
|
| 524 |
-
|
|
|
|
|
|
|
| 525 |
|
| 526 |
elif filename.lower().endswith(".db"):
|
| 527 |
-
|
| 528 |
-
|
| 529 |
-
|
|
|
|
| 530 |
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
|
|
|
|
| 535 |
|
| 536 |
-
|
| 537 |
-
|
| 538 |
-
)
|
| 539 |
-
if not temp_cursor.fetchone():
|
| 540 |
-
raise HTTPException(
|
| 541 |
-
status_code=400, detail="Uploaded DB is missing the 'problems' table."
|
| 542 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 543 |
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
| 548 |
-
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
p_dict.pop("user_id", None)
|
| 552 |
-
|
| 553 |
-
existing = db.get_problem_by_name(p_dict["name"], client)
|
| 554 |
-
if existing:
|
| 555 |
-
db.update_problem(existing["id"], p_dict, client)
|
| 556 |
-
else:
|
| 557 |
-
res_p = db.insert_problem(p_dict, client)
|
| 558 |
-
if res_p and res_p.data:
|
| 559 |
-
new_prob_id = res_p.data[0]["id"]
|
| 560 |
-
|
| 561 |
-
review_copied = False
|
| 562 |
-
if old_id:
|
| 563 |
-
try:
|
| 564 |
-
temp_cursor.execute(
|
| 565 |
-
"SELECT * FROM user_reviews WHERE problem_id = ?", (old_id,)
|
| 566 |
-
)
|
| 567 |
-
rev_row = temp_cursor.fetchone()
|
| 568 |
-
if rev_row:
|
| 569 |
-
r_dict = dict(rev_row)
|
| 570 |
-
r_dict.pop("id", None)
|
| 571 |
-
r_dict.pop("user_id", None)
|
| 572 |
-
r_dict["problem_id"] = new_prob_id
|
| 573 |
-
db.insert_review(r_dict, client)
|
| 574 |
-
review_copied = True
|
| 575 |
-
except Exception:
|
| 576 |
-
pass
|
| 577 |
-
|
| 578 |
-
if not review_copied:
|
| 579 |
-
review_data = {
|
| 580 |
-
"problem_id": new_prob_id,
|
| 581 |
-
"box_level": 1,
|
| 582 |
-
"next_review": datetime.now(UTC).isoformat(),
|
| 583 |
-
"times_correct": 0,
|
| 584 |
-
"total_attempts": 0,
|
| 585 |
-
}
|
| 586 |
-
db.insert_review(review_data, client)
|
| 587 |
-
imported_count += 1
|
| 588 |
-
return {
|
| 589 |
-
"message": f"Successfully imported {imported_count} problems from database."
|
| 590 |
-
}
|
| 591 |
-
finally:
|
| 592 |
-
temp_conn.close()
|
| 593 |
-
try:
|
| 594 |
-
os.unlink(tmp_path)
|
| 595 |
-
except Exception:
|
| 596 |
-
pass
|
| 597 |
else:
|
| 598 |
raise HTTPException(
|
| 599 |
status_code=400, detail="Unsupported file format. Please upload .csv or .db files."
|
|
@@ -604,5 +638,6 @@ def import_problems(file: UploadFile = File(...), client: Client = Depends(get_a
|
|
| 604 |
except Exception as e:
|
| 605 |
import traceback
|
| 606 |
|
| 607 |
-
|
|
|
|
| 608 |
raise HTTPException(status_code=500, detail=f"Import failed: {str(e)}")
|
|
|
|
| 1 |
+
import asyncio
|
| 2 |
import csv
|
| 3 |
import io
|
| 4 |
import os
|
|
|
|
| 72 |
|
| 73 |
|
| 74 |
@router.post("/api/explorer/problems/fetch-leetcode")
|
| 75 |
+
async def fetch_leetcode_endpoint(
|
| 76 |
req: FetchLeetCodeRequest,
|
| 77 |
request: Request,
|
| 78 |
x_ai_provider: str = Header(None),
|
|
|
|
| 83 |
raise HTTPException(status_code=400, detail="Query cannot be empty")
|
| 84 |
api_key = x_custom_api_key or x_gemini_api_key
|
| 85 |
check_burst_rate_limit(request, api_key)
|
| 86 |
+
res = await llm_reviewer.fetch_leetcode_problem_async(
|
| 87 |
req.query, custom_api_key=api_key, custom_provider=x_ai_provider
|
| 88 |
)
|
| 89 |
if "error" in res:
|
|
|
|
| 92 |
|
| 93 |
|
| 94 |
@router.post("/api/explorer/problems/prefill")
|
| 95 |
+
async def prefill_problem_endpoint(
|
| 96 |
req: PrefillProblemRequest,
|
| 97 |
request: Request,
|
| 98 |
x_ai_provider: str = Header(None),
|
|
|
|
| 102 |
api_key = x_custom_api_key or x_gemini_api_key
|
| 103 |
check_burst_rate_limit(request, api_key)
|
| 104 |
if req.name.strip().startswith("http") or "leetcode.com" in req.name:
|
| 105 |
+
res = await llm_reviewer.fetch_leetcode_problem_async(
|
| 106 |
req.name, custom_api_key=api_key, custom_provider=x_ai_provider
|
| 107 |
)
|
| 108 |
else:
|
| 109 |
+
res = await llm_reviewer.prefill_problem_details_async(
|
| 110 |
req.name, req.code, custom_api_key=api_key, custom_provider=x_ai_provider
|
| 111 |
)
|
| 112 |
if "error" in res:
|
|
|
|
| 115 |
|
| 116 |
|
| 117 |
@router.post("/api/explorer/problems/assist-field")
|
| 118 |
+
async def assist_field_endpoint(
|
| 119 |
req: AssistFieldRequest,
|
| 120 |
request: Request,
|
| 121 |
x_ai_provider: str = Header(None),
|
|
|
|
| 125 |
api_key = x_custom_api_key or x_gemini_api_key
|
| 126 |
check_burst_rate_limit(request, api_key)
|
| 127 |
if req.field == "intuition":
|
| 128 |
+
res = await llm_reviewer.generate_how_to_solve_intuition_async(
|
| 129 |
req.title,
|
| 130 |
req.code,
|
| 131 |
req.description,
|
|
|
|
| 133 |
custom_provider=x_ai_provider,
|
| 134 |
)
|
| 135 |
elif req.field == "comments":
|
| 136 |
+
res = await llm_reviewer.format_code_with_emoji_comments_async(
|
| 137 |
req.code, req.title, custom_api_key=api_key, custom_provider=x_ai_provider
|
| 138 |
)
|
| 139 |
else:
|
|
|
|
| 144 |
|
| 145 |
|
| 146 |
@router.get("/api/explorer/problems")
|
| 147 |
+
async def get_explorer_problems(client: Client = Depends(get_auth_session)):
|
| 148 |
try:
|
| 149 |
+
return await asyncio.to_thread(db.get_all_problems_with_reviews, client)
|
| 150 |
except Exception as e:
|
| 151 |
raise HTTPException(status_code=500, detail=str(e))
|
| 152 |
|
| 153 |
|
| 154 |
@router.post("/api/explorer/problems/create")
|
| 155 |
+
async def create_explorer_problem(
|
| 156 |
+
req: CreateProblemRequest, client: Client = Depends(get_auth_session)
|
| 157 |
+
):
|
| 158 |
+
user_id = await asyncio.to_thread(db.get_current_user_id, client)
|
| 159 |
if not user_id:
|
| 160 |
raise HTTPException(status_code=401, detail="Authentication failed")
|
| 161 |
|
| 162 |
if not req.name.strip():
|
| 163 |
raise HTTPException(status_code=400, detail="Problem name cannot be empty")
|
| 164 |
|
| 165 |
+
def _create_problem_record():
|
| 166 |
+
existing = db.get_problem_by_name(req.name, client)
|
| 167 |
+
if existing:
|
| 168 |
+
raise ValueError(f"A problem named '{req.name}' already exists.")
|
| 169 |
|
|
|
|
| 170 |
prob_data = {
|
| 171 |
"name": req.name.strip(),
|
| 172 |
"pattern": req.pattern.strip() or "General",
|
|
|
|
| 184 |
prob_data["solutions"] = req.solutions
|
| 185 |
res_prob = db.insert_problem(prob_data, client)
|
| 186 |
if not res_prob or not res_prob.data:
|
| 187 |
+
raise RuntimeError("Failed to create problem record")
|
| 188 |
|
| 189 |
new_prob_id = res_prob.data[0]["id"]
|
| 190 |
|
|
|
|
| 196 |
"total_attempts": 0,
|
| 197 |
}
|
| 198 |
db.insert_review(review_data, client)
|
| 199 |
+
return new_prob_id
|
| 200 |
+
|
| 201 |
+
try:
|
| 202 |
+
new_prob_id = await asyncio.to_thread(_create_problem_record)
|
| 203 |
+
await asyncio.to_thread(cache.delete_cache, f"due_reviews:{user_id}")
|
| 204 |
+
await asyncio.to_thread(cache.delete_cache, f"all_problems_reviews:{user_id}")
|
| 205 |
|
| 206 |
# Dual-Write: Append/Update to Google Doc if requested
|
| 207 |
gdoc_result = None
|
| 208 |
if req.sync_to_gdoc:
|
| 209 |
try:
|
| 210 |
+
gdoc_result = await asyncio.to_thread(
|
| 211 |
+
gdoc_writer.append_or_update_problem_in_doc,
|
| 212 |
doc_id=req.google_doc_id,
|
| 213 |
problem_number=req.problem_number,
|
| 214 |
problem_name=req.name,
|
|
|
|
| 224 |
method_name=req.pattern,
|
| 225 |
)
|
| 226 |
if gdoc_result and gdoc_result.get("doc_url"):
|
| 227 |
+
await asyncio.to_thread(
|
| 228 |
+
db.update_problem,
|
| 229 |
new_prob_id,
|
| 230 |
{
|
| 231 |
"google_doc_url": gdoc_result["doc_url"],
|
|
|
|
| 234 |
client,
|
| 235 |
)
|
| 236 |
except Exception as e:
|
| 237 |
+
await asyncio.to_thread(db.log_trace, f"Dual-write Google Doc error: {str(e)}")
|
| 238 |
|
| 239 |
return {"success": True, "problem_id": new_prob_id, "gdoc_result": gdoc_result}
|
| 240 |
+
except ValueError as e:
|
| 241 |
+
raise HTTPException(status_code=400, detail=str(e))
|
| 242 |
+
except HTTPException:
|
| 243 |
+
raise
|
| 244 |
except Exception as e:
|
| 245 |
raise HTTPException(status_code=500, detail=str(e))
|
| 246 |
|
|
|
|
| 349 |
|
| 350 |
|
| 351 |
@router.get("/api/explorer/export")
|
| 352 |
+
async def export_solutions_zip(client: Client = Depends(get_auth_session)):
|
| 353 |
+
user_id = await asyncio.to_thread(db.get_current_user_id, client)
|
| 354 |
if not user_id:
|
| 355 |
raise HTTPException(status_code=401, detail="Authentication failed")
|
| 356 |
|
| 357 |
try:
|
| 358 |
+
def _generate_zip() -> io.BytesIO:
|
| 359 |
+
problems = db.get_all_problems(client)
|
| 360 |
+
zip_buffer = io.BytesIO()
|
| 361 |
+
with zipfile.ZipFile(zip_buffer, "w", zipfile.ZIP_DEFLATED) as zip_file:
|
| 362 |
+
for p in problems:
|
| 363 |
+
name = p.get("name", "Unnamed_Problem")
|
| 364 |
+
pattern = p.get("pattern", "General")
|
| 365 |
+
difficulty = p.get("difficulty", "Medium")
|
| 366 |
+
code = p.get("reference_code", "")
|
| 367 |
+
description = p.get("description", "")
|
| 368 |
+
|
| 369 |
+
safe_name = re.sub(r"[^\w\-]", "_", name)
|
| 370 |
+
filename = f"{safe_name}.py"
|
| 371 |
+
|
| 372 |
+
if not code or not code.strip():
|
| 373 |
+
desc_comment = f"\n# Description: {description}" if description else ""
|
| 374 |
+
code = f"# Problem: {name}\n# Pattern: {pattern}\n# Difficulty: {difficulty}{desc_comment}\n# Write your solution here!\n\ndef solve():\n pass\n"
|
| 375 |
+
else:
|
| 376 |
+
if description:
|
| 377 |
+
formatted_desc = "\n".join(
|
| 378 |
+
[f"# {line}" for line in description.splitlines()]
|
| 379 |
+
)
|
| 380 |
+
code = f"# Description:\n{formatted_desc}\n\n" + code
|
| 381 |
+
|
| 382 |
+
zip_file.writestr(filename, code)
|
| 383 |
+
|
| 384 |
+
zip_buffer.seek(0)
|
| 385 |
+
return zip_buffer
|
| 386 |
+
|
| 387 |
+
zip_buffer = await asyncio.to_thread(_generate_zip)
|
| 388 |
|
| 389 |
headers = {"Content-Disposition": "attachment; filename=algospaced_solutions.zip"}
|
| 390 |
return StreamingResponse(zip_buffer, media_type="application/zip", headers=headers)
|
|
|
|
| 393 |
|
| 394 |
|
| 395 |
@router.post("/api/explorer/import")
|
| 396 |
+
async def import_problems(file: UploadFile = File(...), client: Client = Depends(get_auth_session)):
|
| 397 |
+
user_id = await asyncio.to_thread(db.get_current_user_id, client)
|
| 398 |
if not user_id:
|
| 399 |
raise HTTPException(status_code=401, detail="Authentication failed")
|
| 400 |
|
| 401 |
+
filename = file.filename or ""
|
| 402 |
try:
|
| 403 |
+
contents = await file.read()
|
| 404 |
if filename.lower().endswith(".csv"):
|
| 405 |
+
def _import_csv() -> int:
|
| 406 |
+
decoded = contents.decode("utf-8-sig", errors="replace")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 407 |
|
| 408 |
+
# Try to sniff delimiter, fallback to comma
|
| 409 |
+
try:
|
| 410 |
+
dialect = csv.Sniffer().sniff(decoded[:1024], delimiters=[",", ";", "\t"])
|
| 411 |
+
except Exception:
|
| 412 |
+
dialect = csv.excel
|
| 413 |
|
| 414 |
+
reader = csv.DictReader(io.StringIO(decoded), dialect=dialect)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 415 |
|
| 416 |
+
field_mapping = {}
|
| 417 |
+
for col in reader.fieldnames or []:
|
| 418 |
+
col_lower = (
|
| 419 |
+
col.strip().lower().replace("_", " ").replace("&", "").replace(" ", " ")
|
| 420 |
+
)
|
| 421 |
+
if col_lower in ("name", "title", "problem name", "problem_name"):
|
| 422 |
+
field_mapping["name"] = col
|
| 423 |
+
elif col_lower in (
|
| 424 |
+
"problem_number",
|
| 425 |
+
"number",
|
| 426 |
+
"id",
|
| 427 |
+
"leetcode_number",
|
| 428 |
+
"problem number",
|
| 429 |
+
"leetcode id",
|
| 430 |
+
):
|
| 431 |
+
field_mapping["problem_number"] = col
|
| 432 |
+
elif col_lower in ("pattern", "category", "topic", "tag"):
|
| 433 |
+
field_mapping["pattern"] = col
|
| 434 |
+
elif col_lower in ("difficulty", "level"):
|
| 435 |
+
field_mapping["difficulty"] = col
|
| 436 |
+
elif col_lower in (
|
| 437 |
+
"optimal_time",
|
| 438 |
+
"time complexity",
|
| 439 |
+
"time_complexity",
|
| 440 |
+
"time",
|
| 441 |
+
"optimal time",
|
| 442 |
+
):
|
| 443 |
+
field_mapping["optimal_time"] = col
|
| 444 |
+
elif col_lower in (
|
| 445 |
+
"optimal_space",
|
| 446 |
+
"space complexity",
|
| 447 |
+
"space_complexity",
|
| 448 |
+
"space",
|
| 449 |
+
"optimal space",
|
| 450 |
+
):
|
| 451 |
+
field_mapping["optimal_space"] = col
|
| 452 |
+
elif col_lower in (
|
| 453 |
+
"reference_code",
|
| 454 |
+
"code",
|
| 455 |
+
"solution",
|
| 456 |
+
"reference code",
|
| 457 |
+
"python solution",
|
| 458 |
+
):
|
| 459 |
+
field_mapping["reference_code"] = col
|
| 460 |
+
elif col_lower in ("description", "notes", "doc description", "doc_description"):
|
| 461 |
+
field_mapping["description"] = col
|
| 462 |
|
| 463 |
+
imported_count = 0
|
| 464 |
+
for row in reader:
|
| 465 |
+
name = row.get(field_mapping.get("name", "name"), "").strip()
|
| 466 |
+
if not name:
|
| 467 |
+
name = row.get("name", row.get("title", "")).strip()
|
| 468 |
+
if not name:
|
| 469 |
+
continue
|
| 470 |
+
|
| 471 |
+
prob_num_str = row.get(
|
| 472 |
+
field_mapping.get("problem_number", "problem_number"), ""
|
| 473 |
+
).strip()
|
| 474 |
+
if not prob_num_str:
|
| 475 |
+
prob_num_str = row.get("problem_number", row.get("number", ""))
|
| 476 |
+
|
| 477 |
+
try:
|
| 478 |
+
problem_number = int(prob_num_str) if prob_num_str else None
|
| 479 |
+
except ValueError:
|
| 480 |
+
problem_number = None
|
| 481 |
+
|
| 482 |
+
pattern = row.get(field_mapping.get("pattern", "pattern"), "").strip() or "General"
|
| 483 |
+
difficulty = (
|
| 484 |
+
row.get(field_mapping.get("difficulty", "difficulty"), "").strip() or "Medium"
|
| 485 |
+
)
|
| 486 |
+
optimal_time = (
|
| 487 |
+
row.get(field_mapping.get("optimal_time", "optimal_time"), "").strip() or "O(N)"
|
| 488 |
+
)
|
| 489 |
+
optimal_space = (
|
| 490 |
+
row.get(field_mapping.get("optimal_space", "optimal_space"), "").strip()
|
| 491 |
+
or "O(N)"
|
| 492 |
+
)
|
| 493 |
+
reference_code = row.get(
|
| 494 |
+
field_mapping.get("reference_code", "reference_code"), ""
|
| 495 |
+
) or row.get("code", "")
|
| 496 |
+
description = row.get(
|
| 497 |
+
field_mapping.get("description", "description"), ""
|
| 498 |
+
) or row.get("notes", "")
|
| 499 |
+
|
| 500 |
+
existing = db.get_problem_by_name(name, client)
|
| 501 |
+
if existing:
|
| 502 |
+
prob_data = {
|
| 503 |
+
"pattern": pattern,
|
| 504 |
+
"difficulty": difficulty,
|
| 505 |
+
"optimal_time": optimal_time,
|
| 506 |
+
"optimal_space": optimal_space,
|
| 507 |
+
"reference_code": reference_code,
|
| 508 |
+
"description": description,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 509 |
}
|
| 510 |
+
if problem_number is not None:
|
| 511 |
+
prob_data["problem_number"] = problem_number
|
| 512 |
+
db.update_problem(existing["id"], prob_data, client)
|
| 513 |
+
else:
|
| 514 |
+
prob_data = {
|
| 515 |
+
"name": name,
|
| 516 |
+
"pattern": pattern,
|
| 517 |
+
"difficulty": difficulty,
|
| 518 |
+
"optimal_time": optimal_time,
|
| 519 |
+
"optimal_space": optimal_space,
|
| 520 |
+
"reference_code": reference_code,
|
| 521 |
+
"description": description,
|
| 522 |
+
}
|
| 523 |
+
if problem_number is not None:
|
| 524 |
+
prob_data["problem_number"] = problem_number
|
| 525 |
+
|
| 526 |
+
res_p = db.insert_problem(prob_data, client)
|
| 527 |
+
if res_p and res_p.data:
|
| 528 |
+
new_prob_id = res_p.data[0]["id"]
|
| 529 |
+
review_data = {
|
| 530 |
+
"problem_id": new_prob_id,
|
| 531 |
+
"box_level": 1,
|
| 532 |
+
"next_review": datetime.now(UTC).isoformat(),
|
| 533 |
+
"times_correct": 0,
|
| 534 |
+
"total_attempts": 0,
|
| 535 |
+
}
|
| 536 |
+
db.insert_review(review_data, client)
|
| 537 |
+
imported_count += 1
|
| 538 |
+
return imported_count
|
| 539 |
+
|
| 540 |
+
count = await asyncio.to_thread(_import_csv)
|
| 541 |
+
if count == 0:
|
| 542 |
raise HTTPException(
|
| 543 |
status_code=400,
|
| 544 |
detail="No valid problems found in the CSV. Make sure it has a 'name' or 'title' column.",
|
| 545 |
)
|
| 546 |
+
await asyncio.to_thread(cache.delete_cache, f"due_reviews:{user_id}")
|
| 547 |
+
await asyncio.to_thread(cache.delete_cache, f"all_problems_reviews:{user_id}")
|
| 548 |
+
return {"message": f"Successfully imported {count} problems from CSV."}
|
| 549 |
|
| 550 |
elif filename.lower().endswith(".db"):
|
| 551 |
+
def _import_sqlite() -> int:
|
| 552 |
+
with tempfile.NamedTemporaryFile(suffix=".db", delete=False) as tmp:
|
| 553 |
+
tmp.write(contents)
|
| 554 |
+
tmp_path = tmp.name
|
| 555 |
|
| 556 |
+
temp_conn = None
|
| 557 |
+
try:
|
| 558 |
+
temp_conn = sqlite3.connect(tmp_path)
|
| 559 |
+
temp_conn.row_factory = sqlite3.Row
|
| 560 |
+
temp_cursor = temp_conn.cursor()
|
| 561 |
|
| 562 |
+
temp_cursor.execute(
|
| 563 |
+
"SELECT name FROM sqlite_master WHERE type='table' AND name='problems'"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 564 |
)
|
| 565 |
+
if not temp_cursor.fetchone():
|
| 566 |
+
raise ValueError("Uploaded DB is missing the 'problems' table.")
|
| 567 |
+
|
| 568 |
+
temp_cursor.execute("SELECT * FROM problems")
|
| 569 |
+
rows = temp_cursor.fetchall()
|
| 570 |
+
|
| 571 |
+
imported_count = 0
|
| 572 |
+
for row in rows:
|
| 573 |
+
p_dict = dict(row)
|
| 574 |
+
old_id = p_dict.pop("id", None)
|
| 575 |
+
p_dict.pop("user_id", None)
|
| 576 |
+
|
| 577 |
+
existing = db.get_problem_by_name(p_dict["name"], client)
|
| 578 |
+
if existing:
|
| 579 |
+
db.update_problem(existing["id"], p_dict, client)
|
| 580 |
+
else:
|
| 581 |
+
res_p = db.insert_problem(p_dict, client)
|
| 582 |
+
if res_p and res_p.data:
|
| 583 |
+
new_prob_id = res_p.data[0]["id"]
|
| 584 |
+
|
| 585 |
+
review_copied = False
|
| 586 |
+
if old_id:
|
| 587 |
+
try:
|
| 588 |
+
temp_cursor.execute(
|
| 589 |
+
"SELECT * FROM user_reviews WHERE problem_id = ?", (old_id,)
|
| 590 |
+
)
|
| 591 |
+
rev_row = temp_cursor.fetchone()
|
| 592 |
+
if rev_row:
|
| 593 |
+
r_dict = dict(rev_row)
|
| 594 |
+
r_dict.pop("id", None)
|
| 595 |
+
r_dict.pop("user_id", None)
|
| 596 |
+
r_dict["problem_id"] = new_prob_id
|
| 597 |
+
db.insert_review(r_dict, client)
|
| 598 |
+
review_copied = True
|
| 599 |
+
except Exception:
|
| 600 |
+
pass
|
| 601 |
+
|
| 602 |
+
if not review_copied:
|
| 603 |
+
review_data = {
|
| 604 |
+
"problem_id": new_prob_id,
|
| 605 |
+
"box_level": 1,
|
| 606 |
+
"next_review": datetime.now(UTC).isoformat(),
|
| 607 |
+
"times_correct": 0,
|
| 608 |
+
"total_attempts": 0,
|
| 609 |
+
}
|
| 610 |
+
db.insert_review(review_data, client)
|
| 611 |
+
imported_count += 1
|
| 612 |
+
return imported_count
|
| 613 |
+
finally:
|
| 614 |
+
if temp_conn is not None:
|
| 615 |
+
try:
|
| 616 |
+
temp_conn.close()
|
| 617 |
+
except Exception:
|
| 618 |
+
pass
|
| 619 |
+
try:
|
| 620 |
+
os.unlink(tmp_path)
|
| 621 |
+
except Exception:
|
| 622 |
+
pass
|
| 623 |
|
| 624 |
+
try:
|
| 625 |
+
count = await asyncio.to_thread(_import_sqlite)
|
| 626 |
+
except ValueError as val_err:
|
| 627 |
+
raise HTTPException(status_code=400, detail=str(val_err))
|
| 628 |
+
await asyncio.to_thread(cache.delete_cache, f"due_reviews:{user_id}")
|
| 629 |
+
await asyncio.to_thread(cache.delete_cache, f"all_problems_reviews:{user_id}")
|
| 630 |
+
return {"message": f"Successfully imported {count} problems from database."}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 631 |
else:
|
| 632 |
raise HTTPException(
|
| 633 |
status_code=400, detail="Unsupported file format. Please upload .csv or .db files."
|
|
|
|
| 638 |
except Exception as e:
|
| 639 |
import traceback
|
| 640 |
|
| 641 |
+
err_trace = f"Import error: {str(e)}\n{traceback.format_exc()}"
|
| 642 |
+
await asyncio.to_thread(db.log_trace, err_trace)
|
| 643 |
raise HTTPException(status_code=500, detail=f"Import failed: {str(e)}")
|
routers/github_sync.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import base64
|
| 2 |
import json
|
| 3 |
import logging
|
|
@@ -9,6 +10,7 @@ import urllib.request
|
|
| 9 |
from datetime import UTC, datetime
|
| 10 |
from typing import Any
|
| 11 |
|
|
|
|
| 12 |
from fastapi import APIRouter, Depends, HTTPException
|
| 13 |
from fastapi.responses import HTMLResponse, RedirectResponse
|
| 14 |
from pydantic import BaseModel
|
|
@@ -74,6 +76,49 @@ def github_api_request(
|
|
| 74 |
return 500, {"message": f"GitHub API error: {str(e)}"}
|
| 75 |
|
| 76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
def slugify_problem(name: str, problem_number: int | None = None) -> str:
|
| 78 |
"""Generates clean repository folder name e.g. '0001-two-sum'."""
|
| 79 |
clean_name = re.sub(r"[^a-zA-Z0-9\s-]", "", name).strip().lower()
|
|
@@ -95,6 +140,18 @@ def get_file_sha(owner: str, repo: str, path: str, branch: str, token: str) -> s
|
|
| 95 |
return None
|
| 96 |
|
| 97 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
def commit_file_to_github(
|
| 99 |
owner: str,
|
| 100 |
repo: str,
|
|
@@ -138,6 +195,56 @@ def commit_file_to_github(
|
|
| 138 |
return False, err_msg, res
|
| 139 |
|
| 140 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
# ---------------------------------------------------------
|
| 142 |
# Markdown & Docstring Formatting Helpers
|
| 143 |
# ---------------------------------------------------------
|
|
@@ -474,7 +581,7 @@ def render_oauth_error_page(error: str) -> HTMLResponse:
|
|
| 474 |
|
| 475 |
|
| 476 |
@router.get("/oauth/status")
|
| 477 |
-
def get_github_oauth_status():
|
| 478 |
"""Returns whether direct backend GitHub OAuth is configured via environment variables."""
|
| 479 |
client_id = os.environ.get("GITHUB_CLIENT_ID", "").strip()
|
| 480 |
client_secret = os.environ.get("GITHUB_CLIENT_SECRET", "").strip()
|
|
@@ -485,7 +592,7 @@ def get_github_oauth_status():
|
|
| 485 |
|
| 486 |
|
| 487 |
@router.get("/oauth/login")
|
| 488 |
-
def github_oauth_login(redirect_uri: str | None = None):
|
| 489 |
"""Initiates GitHub OAuth flow by redirecting the browser to GitHub's authorization page."""
|
| 490 |
client_id = os.environ.get("GITHUB_CLIENT_ID", "").strip()
|
| 491 |
client_secret = os.environ.get("GITHUB_CLIENT_SECRET", "").strip()
|
|
@@ -508,7 +615,7 @@ def github_oauth_login(redirect_uri: str | None = None):
|
|
| 508 |
|
| 509 |
|
| 510 |
@router.get("/oauth/callback", response_class=HTMLResponse)
|
| 511 |
-
def github_oauth_callback(
|
| 512 |
code: str | None = None,
|
| 513 |
error: str | None = None,
|
| 514 |
error_description: str | None = None,
|
|
@@ -550,9 +657,12 @@ def github_oauth_callback(
|
|
| 550 |
method="POST",
|
| 551 |
)
|
| 552 |
|
| 553 |
-
|
| 554 |
with urllib.request.urlopen(req, timeout=15) as resp:
|
| 555 |
-
|
|
|
|
|
|
|
|
|
|
| 556 |
except Exception as exc:
|
| 557 |
logger.error("Failed exchanging code for GitHub token: %s", exc)
|
| 558 |
return render_oauth_error_page(f"Failed to communicate with GitHub token service: {exc}")
|
|
@@ -569,12 +679,12 @@ def github_oauth_callback(
|
|
| 569 |
|
| 570 |
|
| 571 |
@router.post("/verify")
|
| 572 |
-
def verify_github_token(req: VerifyTokenRequest):
|
| 573 |
"""Verifies a GitHub OAuth token or Personal Access Token and returns user profile."""
|
| 574 |
if not req.token or not req.token.strip():
|
| 575 |
raise HTTPException(status_code=400, detail="GitHub token is required.")
|
| 576 |
|
| 577 |
-
status, res =
|
| 578 |
if status == 200:
|
| 579 |
return {
|
| 580 |
"valid": True,
|
|
@@ -594,7 +704,7 @@ def verify_github_token(req: VerifyTokenRequest):
|
|
| 594 |
|
| 595 |
|
| 596 |
@router.post("/init-repo")
|
| 597 |
-
def init_github_repo(req: InitRepoRequest):
|
| 598 |
"""Checks if the target repository exists under the authenticated user's account;
|
| 599 |
|
| 600 |
if not, creates it with an initial README.
|
|
@@ -607,7 +717,7 @@ def init_github_repo(req: InitRepoRequest):
|
|
| 607 |
raise HTTPException(status_code=400, detail="Repository name is required.")
|
| 608 |
|
| 609 |
# 1. Fetch user login
|
| 610 |
-
status, user_res =
|
| 611 |
if status != 200:
|
| 612 |
raise HTTPException(
|
| 613 |
status_code=401,
|
|
@@ -616,7 +726,9 @@ def init_github_repo(req: InitRepoRequest):
|
|
| 616 |
owner = user_res.get("login")
|
| 617 |
|
| 618 |
# 2. Check if repository already exists
|
| 619 |
-
status, repo_res =
|
|
|
|
|
|
|
| 620 |
if status == 200:
|
| 621 |
return {
|
| 622 |
"success": True,
|
|
@@ -635,7 +747,7 @@ def init_github_repo(req: InitRepoRequest):
|
|
| 635 |
"private": req.private,
|
| 636 |
"auto_init": True,
|
| 637 |
}
|
| 638 |
-
status, create_res =
|
| 639 |
"/user/repos", token, method="POST", data=create_payload
|
| 640 |
)
|
| 641 |
if status in (200, 201):
|
|
@@ -656,7 +768,7 @@ def init_github_repo(req: InitRepoRequest):
|
|
| 656 |
|
| 657 |
|
| 658 |
@router.post("/push-solution")
|
| 659 |
-
def push_solution(req: PushSolutionRequest):
|
| 660 |
"""Pushes a single problem's solution code and README to the user's GitHub repository."""
|
| 661 |
token = req.token.strip()
|
| 662 |
repo_input = req.repo.strip()
|
|
@@ -669,7 +781,7 @@ def push_solution(req: PushSolutionRequest):
|
|
| 669 |
if "/" in repo_input:
|
| 670 |
owner, repo = repo_input.split("/", 1)
|
| 671 |
else:
|
| 672 |
-
status, user_res =
|
| 673 |
if status != 200:
|
| 674 |
raise HTTPException(status_code=401, detail="Invalid GitHub token")
|
| 675 |
owner = user_res.get("login")
|
|
@@ -692,8 +804,14 @@ def push_solution(req: PushSolutionRequest):
|
|
| 692 |
num_tag = f"#{req.problem_number} " if req.problem_number else ""
|
| 693 |
commit_msg = f"feat(solution): add {num_tag}{req.problem_name} solution [AlgoSpaced]"
|
| 694 |
|
| 695 |
-
success, msg, code_res =
|
| 696 |
-
owner,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 697 |
)
|
| 698 |
if not success:
|
| 699 |
raise HTTPException(status_code=500, detail=f"Failed to commit solution code: {msg}")
|
|
@@ -713,8 +831,14 @@ def push_solution(req: PushSolutionRequest):
|
|
| 713 |
readme_path = f"solutions/{slug}/README.md"
|
| 714 |
readme_commit_msg = f"docs(problem): add {num_tag}{req.problem_name} specification [AlgoSpaced]"
|
| 715 |
|
| 716 |
-
|
| 717 |
-
owner,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 718 |
)
|
| 719 |
|
| 720 |
return {
|
|
@@ -729,7 +853,7 @@ def push_solution(req: PushSolutionRequest):
|
|
| 729 |
|
| 730 |
|
| 731 |
@router.post("/sync-all")
|
| 732 |
-
def sync_all_solutions(req: SyncAllRequest, client: Client = Depends(get_auth_session)):
|
| 733 |
"""Batch-synchronizes all problems in the user's library with reference/submitted
|
| 734 |
|
| 735 |
solutions to their GitHub repository and updates the root README index.
|
|
@@ -749,14 +873,14 @@ def sync_all_solutions(req: SyncAllRequest, client: Client = Depends(get_auth_se
|
|
| 749 |
if "/" in repo_input:
|
| 750 |
owner, repo = repo_input.split("/", 1)
|
| 751 |
else:
|
| 752 |
-
status, user_res =
|
| 753 |
if status != 200:
|
| 754 |
raise HTTPException(status_code=401, detail="Invalid GitHub token")
|
| 755 |
owner = user_res.get("login")
|
| 756 |
repo = repo_input
|
| 757 |
|
| 758 |
# Retrieve all user problems from DB
|
| 759 |
-
all_problems = db.get_all_problems
|
| 760 |
user_problems = [
|
| 761 |
p for p in all_problems if p.get("user_id") == user_id or user_id == "sandbox-user-id"
|
| 762 |
]
|
|
@@ -797,8 +921,14 @@ def sync_all_solutions(req: SyncAllRequest, client: Client = Depends(get_auth_se
|
|
| 797 |
code_path = f"solutions/{slug}/solution.py"
|
| 798 |
commit_msg = f"sync: #{num or ''} {name} [AlgoSpaced]"
|
| 799 |
|
| 800 |
-
ok, _, _ =
|
| 801 |
-
owner,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 802 |
)
|
| 803 |
if ok:
|
| 804 |
synced_count += 1
|
|
@@ -815,7 +945,7 @@ def sync_all_solutions(req: SyncAllRequest, client: Client = Depends(get_auth_se
|
|
| 815 |
prob.get("constraints"),
|
| 816 |
)
|
| 817 |
readme_path = f"solutions/{slug}/README.md"
|
| 818 |
-
|
| 819 |
owner,
|
| 820 |
repo,
|
| 821 |
readme_path,
|
|
@@ -829,7 +959,7 @@ def sync_all_solutions(req: SyncAllRequest, client: Client = Depends(get_auth_se
|
|
| 829 |
|
| 830 |
# Update root README index table
|
| 831 |
root_readme = generate_root_readme(owner, repo, solved_problems)
|
| 832 |
-
|
| 833 |
owner,
|
| 834 |
repo,
|
| 835 |
"README.md",
|
|
|
|
| 1 |
+
import asyncio
|
| 2 |
import base64
|
| 3 |
import json
|
| 4 |
import logging
|
|
|
|
| 10 |
from datetime import UTC, datetime
|
| 11 |
from typing import Any
|
| 12 |
|
| 13 |
+
import httpx
|
| 14 |
from fastapi import APIRouter, Depends, HTTPException
|
| 15 |
from fastapi.responses import HTMLResponse, RedirectResponse
|
| 16 |
from pydantic import BaseModel
|
|
|
|
| 76 |
return 500, {"message": f"GitHub API error: {str(e)}"}
|
| 77 |
|
| 78 |
|
| 79 |
+
async def github_api_request_async(
|
| 80 |
+
endpoint: str,
|
| 81 |
+
token: str,
|
| 82 |
+
method: str = "GET",
|
| 83 |
+
data: dict[str, Any] | None = None,
|
| 84 |
+
) -> tuple[int, dict[str, Any]]:
|
| 85 |
+
"""Executes an authenticated asynchronous request against the GitHub REST API (v2022-11-28).
|
| 86 |
+
|
| 87 |
+
Returns (status_code, response_dict).
|
| 88 |
+
"""
|
| 89 |
+
from unittest.mock import Mock
|
| 90 |
+
|
| 91 |
+
# If github_api_request is patched in test suites, delegate to it
|
| 92 |
+
if isinstance(github_api_request, Mock) or hasattr(github_api_request, "assert_called"):
|
| 93 |
+
return await asyncio.to_thread(github_api_request, endpoint, token, method=method, data=data)
|
| 94 |
+
|
| 95 |
+
url = f"{GITHUB_API_BASE}{endpoint}" if endpoint.startswith("/") else endpoint
|
| 96 |
+
headers = {
|
| 97 |
+
"Authorization": f"Bearer {token.strip()}",
|
| 98 |
+
"Accept": "application/vnd.github+json",
|
| 99 |
+
"X-GitHub-Api-Version": "2022-11-28",
|
| 100 |
+
"User-Agent": "AlgoSpaced-DSA-Review",
|
| 101 |
+
}
|
| 102 |
+
try:
|
| 103 |
+
async with httpx.AsyncClient(timeout=15.0) as client:
|
| 104 |
+
resp = await client.request(
|
| 105 |
+
method=method,
|
| 106 |
+
url=url,
|
| 107 |
+
headers=headers,
|
| 108 |
+
json=data if data is not None else None,
|
| 109 |
+
)
|
| 110 |
+
status = resp.status_code
|
| 111 |
+
try:
|
| 112 |
+
res_json = resp.json()
|
| 113 |
+
except Exception:
|
| 114 |
+
res_json = {"raw": resp.text}
|
| 115 |
+
return status, res_json
|
| 116 |
+
except httpx.HTTPStatusError as e:
|
| 117 |
+
return e.response.status_code, {"message": str(e)}
|
| 118 |
+
except Exception as e:
|
| 119 |
+
return 500, {"message": f"GitHub API error: {str(e)}"}
|
| 120 |
+
|
| 121 |
+
|
| 122 |
def slugify_problem(name: str, problem_number: int | None = None) -> str:
|
| 123 |
"""Generates clean repository folder name e.g. '0001-two-sum'."""
|
| 124 |
clean_name = re.sub(r"[^a-zA-Z0-9\s-]", "", name).strip().lower()
|
|
|
|
| 140 |
return None
|
| 141 |
|
| 142 |
|
| 143 |
+
async def get_file_sha_async(owner: str, repo: str, path: str, branch: str, token: str) -> str | None:
|
| 144 |
+
"""Returns SHA of existing file in GitHub repository or None if 404 (async)."""
|
| 145 |
+
status, res = await github_api_request_async(
|
| 146 |
+
f"/repos/{owner}/{repo}/contents/{path}?ref={branch}",
|
| 147 |
+
token,
|
| 148 |
+
method="GET",
|
| 149 |
+
)
|
| 150 |
+
if status == 200 and "sha" in res:
|
| 151 |
+
return res["sha"]
|
| 152 |
+
return None
|
| 153 |
+
|
| 154 |
+
|
| 155 |
def commit_file_to_github(
|
| 156 |
owner: str,
|
| 157 |
repo: str,
|
|
|
|
| 195 |
return False, err_msg, res
|
| 196 |
|
| 197 |
|
| 198 |
+
async def commit_file_to_github_async(
|
| 199 |
+
owner: str,
|
| 200 |
+
repo: str,
|
| 201 |
+
path: str,
|
| 202 |
+
content_str: str,
|
| 203 |
+
commit_message: str,
|
| 204 |
+
branch: str,
|
| 205 |
+
token: str,
|
| 206 |
+
) -> tuple[bool, str, dict[str, Any]]:
|
| 207 |
+
"""Commits or updates a file in the user's GitHub repository asynchronously.
|
| 208 |
+
|
| 209 |
+
Returns (success, message, response_data).
|
| 210 |
+
"""
|
| 211 |
+
from unittest.mock import Mock
|
| 212 |
+
|
| 213 |
+
if isinstance(commit_file_to_github, Mock) or hasattr(commit_file_to_github, "assert_called"):
|
| 214 |
+
return await asyncio.to_thread(
|
| 215 |
+
commit_file_to_github, owner, repo, path, content_str, commit_message, branch, token
|
| 216 |
+
)
|
| 217 |
+
|
| 218 |
+
b64_content = base64.b64encode(content_str.encode("utf-8")).decode("utf-8")
|
| 219 |
+
existing_sha = await get_file_sha_async(owner, repo, path, branch, token)
|
| 220 |
+
|
| 221 |
+
payload: dict[str, Any] = {
|
| 222 |
+
"message": commit_message,
|
| 223 |
+
"content": b64_content,
|
| 224 |
+
"branch": branch,
|
| 225 |
+
}
|
| 226 |
+
if existing_sha:
|
| 227 |
+
payload["sha"] = existing_sha
|
| 228 |
+
|
| 229 |
+
status, res = await github_api_request_async(
|
| 230 |
+
f"/repos/{owner}/{repo}/contents/{path}",
|
| 231 |
+
token,
|
| 232 |
+
method="PUT",
|
| 233 |
+
data=payload,
|
| 234 |
+
)
|
| 235 |
+
|
| 236 |
+
if status in (200, 201):
|
| 237 |
+
html_url = res.get("content", {}).get("html_url", "")
|
| 238 |
+
return (
|
| 239 |
+
True,
|
| 240 |
+
"Committed successfully",
|
| 241 |
+
{"html_url": html_url, "sha": res.get("commit", {}).get("sha", "")},
|
| 242 |
+
)
|
| 243 |
+
|
| 244 |
+
err_msg = res.get("message", f"GitHub returned HTTP {status}")
|
| 245 |
+
return False, err_msg, res
|
| 246 |
+
|
| 247 |
+
|
| 248 |
# ---------------------------------------------------------
|
| 249 |
# Markdown & Docstring Formatting Helpers
|
| 250 |
# ---------------------------------------------------------
|
|
|
|
| 581 |
|
| 582 |
|
| 583 |
@router.get("/oauth/status")
|
| 584 |
+
async def get_github_oauth_status():
|
| 585 |
"""Returns whether direct backend GitHub OAuth is configured via environment variables."""
|
| 586 |
client_id = os.environ.get("GITHUB_CLIENT_ID", "").strip()
|
| 587 |
client_secret = os.environ.get("GITHUB_CLIENT_SECRET", "").strip()
|
|
|
|
| 592 |
|
| 593 |
|
| 594 |
@router.get("/oauth/login")
|
| 595 |
+
async def github_oauth_login(redirect_uri: str | None = None):
|
| 596 |
"""Initiates GitHub OAuth flow by redirecting the browser to GitHub's authorization page."""
|
| 597 |
client_id = os.environ.get("GITHUB_CLIENT_ID", "").strip()
|
| 598 |
client_secret = os.environ.get("GITHUB_CLIENT_SECRET", "").strip()
|
|
|
|
| 615 |
|
| 616 |
|
| 617 |
@router.get("/oauth/callback", response_class=HTMLResponse)
|
| 618 |
+
async def github_oauth_callback(
|
| 619 |
code: str | None = None,
|
| 620 |
error: str | None = None,
|
| 621 |
error_description: str | None = None,
|
|
|
|
| 657 |
method="POST",
|
| 658 |
)
|
| 659 |
|
| 660 |
+
def _exchange_token():
|
| 661 |
with urllib.request.urlopen(req, timeout=15) as resp:
|
| 662 |
+
return json.loads(resp.read().decode("utf-8"))
|
| 663 |
+
|
| 664 |
+
try:
|
| 665 |
+
resp_data = await asyncio.to_thread(_exchange_token)
|
| 666 |
except Exception as exc:
|
| 667 |
logger.error("Failed exchanging code for GitHub token: %s", exc)
|
| 668 |
return render_oauth_error_page(f"Failed to communicate with GitHub token service: {exc}")
|
|
|
|
| 679 |
|
| 680 |
|
| 681 |
@router.post("/verify")
|
| 682 |
+
async def verify_github_token(req: VerifyTokenRequest):
|
| 683 |
"""Verifies a GitHub OAuth token or Personal Access Token and returns user profile."""
|
| 684 |
if not req.token or not req.token.strip():
|
| 685 |
raise HTTPException(status_code=400, detail="GitHub token is required.")
|
| 686 |
|
| 687 |
+
status, res = await github_api_request_async("/user", req.token)
|
| 688 |
if status == 200:
|
| 689 |
return {
|
| 690 |
"valid": True,
|
|
|
|
| 704 |
|
| 705 |
|
| 706 |
@router.post("/init-repo")
|
| 707 |
+
async def init_github_repo(req: InitRepoRequest):
|
| 708 |
"""Checks if the target repository exists under the authenticated user's account;
|
| 709 |
|
| 710 |
if not, creates it with an initial README.
|
|
|
|
| 717 |
raise HTTPException(status_code=400, detail="Repository name is required.")
|
| 718 |
|
| 719 |
# 1. Fetch user login
|
| 720 |
+
status, user_res = await github_api_request_async("/user", token)
|
| 721 |
if status != 200:
|
| 722 |
raise HTTPException(
|
| 723 |
status_code=401,
|
|
|
|
| 726 |
owner = user_res.get("login")
|
| 727 |
|
| 728 |
# 2. Check if repository already exists
|
| 729 |
+
status, repo_res = await github_api_request_async(
|
| 730 |
+
f"/repos/{owner}/{repo_name}", token
|
| 731 |
+
)
|
| 732 |
if status == 200:
|
| 733 |
return {
|
| 734 |
"success": True,
|
|
|
|
| 747 |
"private": req.private,
|
| 748 |
"auto_init": True,
|
| 749 |
}
|
| 750 |
+
status, create_res = await github_api_request_async(
|
| 751 |
"/user/repos", token, method="POST", data=create_payload
|
| 752 |
)
|
| 753 |
if status in (200, 201):
|
|
|
|
| 768 |
|
| 769 |
|
| 770 |
@router.post("/push-solution")
|
| 771 |
+
async def push_solution(req: PushSolutionRequest):
|
| 772 |
"""Pushes a single problem's solution code and README to the user's GitHub repository."""
|
| 773 |
token = req.token.strip()
|
| 774 |
repo_input = req.repo.strip()
|
|
|
|
| 781 |
if "/" in repo_input:
|
| 782 |
owner, repo = repo_input.split("/", 1)
|
| 783 |
else:
|
| 784 |
+
status, user_res = await github_api_request_async("/user", token)
|
| 785 |
if status != 200:
|
| 786 |
raise HTTPException(status_code=401, detail="Invalid GitHub token")
|
| 787 |
owner = user_res.get("login")
|
|
|
|
| 804 |
num_tag = f"#{req.problem_number} " if req.problem_number else ""
|
| 805 |
commit_msg = f"feat(solution): add {num_tag}{req.problem_name} solution [AlgoSpaced]"
|
| 806 |
|
| 807 |
+
success, msg, code_res = await commit_file_to_github_async(
|
| 808 |
+
owner,
|
| 809 |
+
repo,
|
| 810 |
+
code_path,
|
| 811 |
+
formatted_code,
|
| 812 |
+
commit_msg,
|
| 813 |
+
branch,
|
| 814 |
+
token,
|
| 815 |
)
|
| 816 |
if not success:
|
| 817 |
raise HTTPException(status_code=500, detail=f"Failed to commit solution code: {msg}")
|
|
|
|
| 831 |
readme_path = f"solutions/{slug}/README.md"
|
| 832 |
readme_commit_msg = f"docs(problem): add {num_tag}{req.problem_name} specification [AlgoSpaced]"
|
| 833 |
|
| 834 |
+
await commit_file_to_github_async(
|
| 835 |
+
owner,
|
| 836 |
+
repo,
|
| 837 |
+
readme_path,
|
| 838 |
+
readme_content,
|
| 839 |
+
readme_commit_msg,
|
| 840 |
+
branch,
|
| 841 |
+
token,
|
| 842 |
)
|
| 843 |
|
| 844 |
return {
|
|
|
|
| 853 |
|
| 854 |
|
| 855 |
@router.post("/sync-all")
|
| 856 |
+
async def sync_all_solutions(req: SyncAllRequest, client: Client = Depends(get_auth_session)):
|
| 857 |
"""Batch-synchronizes all problems in the user's library with reference/submitted
|
| 858 |
|
| 859 |
solutions to their GitHub repository and updates the root README index.
|
|
|
|
| 873 |
if "/" in repo_input:
|
| 874 |
owner, repo = repo_input.split("/", 1)
|
| 875 |
else:
|
| 876 |
+
status, user_res = await github_api_request_async("/user", token)
|
| 877 |
if status != 200:
|
| 878 |
raise HTTPException(status_code=401, detail="Invalid GitHub token")
|
| 879 |
owner = user_res.get("login")
|
| 880 |
repo = repo_input
|
| 881 |
|
| 882 |
# Retrieve all user problems from DB
|
| 883 |
+
all_problems = await asyncio.to_thread(db.get_all_problems, client)
|
| 884 |
user_problems = [
|
| 885 |
p for p in all_problems if p.get("user_id") == user_id or user_id == "sandbox-user-id"
|
| 886 |
]
|
|
|
|
| 921 |
code_path = f"solutions/{slug}/solution.py"
|
| 922 |
commit_msg = f"sync: #{num or ''} {name} [AlgoSpaced]"
|
| 923 |
|
| 924 |
+
ok, _, _ = await commit_file_to_github_async(
|
| 925 |
+
owner,
|
| 926 |
+
repo,
|
| 927 |
+
code_path,
|
| 928 |
+
formatted_code,
|
| 929 |
+
commit_msg,
|
| 930 |
+
branch,
|
| 931 |
+
token,
|
| 932 |
)
|
| 933 |
if ok:
|
| 934 |
synced_count += 1
|
|
|
|
| 945 |
prob.get("constraints"),
|
| 946 |
)
|
| 947 |
readme_path = f"solutions/{slug}/README.md"
|
| 948 |
+
await commit_file_to_github_async(
|
| 949 |
owner,
|
| 950 |
repo,
|
| 951 |
readme_path,
|
|
|
|
| 959 |
|
| 960 |
# Update root README index table
|
| 961 |
root_readme = generate_root_readme(owner, repo, solved_problems)
|
| 962 |
+
await commit_file_to_github_async(
|
| 963 |
owner,
|
| 964 |
repo,
|
| 965 |
"README.md",
|
routers/journey.py
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
|
|
|
|
|
| 1 |
from fastapi import APIRouter, Depends, HTTPException
|
| 2 |
from pydantic import BaseModel
|
| 3 |
|
|
@@ -8,8 +10,8 @@ router = APIRouter(tags=["journey"])
|
|
| 8 |
|
| 9 |
|
| 10 |
@router.get("/api/journey-progress")
|
| 11 |
-
def get_journey_progress(client: Client = Depends(get_auth_session)):
|
| 12 |
-
return list(db.get_user_journey_progress(client))
|
| 13 |
|
| 14 |
|
| 15 |
class ToggleJourneyRequest(BaseModel):
|
|
@@ -17,18 +19,18 @@ class ToggleJourneyRequest(BaseModel):
|
|
| 17 |
|
| 18 |
|
| 19 |
@router.post("/api/journey-progress/toggle")
|
| 20 |
-
def toggle_journey(req: ToggleJourneyRequest, client: Client = Depends(get_auth_session)):
|
| 21 |
-
db.toggle_journey_progress
|
| 22 |
return {"success": True}
|
| 23 |
|
| 24 |
|
| 25 |
@router.get("/api/journey-progress/titles")
|
| 26 |
-
def get_journey_titles(client: Client = Depends(get_auth_session)):
|
| 27 |
-
return db.get_problem_titles_by_number
|
| 28 |
|
| 29 |
|
| 30 |
@router.get("/api/journey-progress/sequences")
|
| 31 |
-
def get_sequences(client: Client = Depends(get_auth_session)):
|
| 32 |
return [
|
| 33 |
{"id": "leetcode-150", "name": "LeetCode 150"},
|
| 34 |
{"id": "custom", "name": "My Custom Problems"},
|
|
@@ -36,7 +38,7 @@ def get_sequences(client: Client = Depends(get_auth_session)):
|
|
| 36 |
|
| 37 |
|
| 38 |
@router.get("/api/journey-progress/sequence/{set_id}")
|
| 39 |
-
def get_sequence_by_id(set_id: str, client: Client = Depends(get_auth_session)):
|
| 40 |
if set_id == "leetcode-150":
|
| 41 |
return [
|
| 42 |
217,
|
|
@@ -191,11 +193,11 @@ def get_sequence_by_id(set_id: str, client: Client = Depends(get_auth_session)):
|
|
| 191 |
7,
|
| 192 |
]
|
| 193 |
elif set_id == "custom":
|
| 194 |
-
user_id = db.get_current_user_id
|
| 195 |
if not user_id:
|
| 196 |
return []
|
| 197 |
|
| 198 |
-
problems = db.get_all_problems
|
| 199 |
|
| 200 |
sequence = []
|
| 201 |
for p in problems:
|
|
|
|
| 1 |
+
import asyncio
|
| 2 |
+
|
| 3 |
from fastapi import APIRouter, Depends, HTTPException
|
| 4 |
from pydantic import BaseModel
|
| 5 |
|
|
|
|
| 10 |
|
| 11 |
|
| 12 |
@router.get("/api/journey-progress")
|
| 13 |
+
async def get_journey_progress(client: Client = Depends(get_auth_session)):
|
| 14 |
+
return await asyncio.to_thread(lambda: list(db.get_user_journey_progress(client)))
|
| 15 |
|
| 16 |
|
| 17 |
class ToggleJourneyRequest(BaseModel):
|
|
|
|
| 19 |
|
| 20 |
|
| 21 |
@router.post("/api/journey-progress/toggle")
|
| 22 |
+
async def toggle_journey(req: ToggleJourneyRequest, client: Client = Depends(get_auth_session)):
|
| 23 |
+
await asyncio.to_thread(db.toggle_journey_progress, req.problem_number, client)
|
| 24 |
return {"success": True}
|
| 25 |
|
| 26 |
|
| 27 |
@router.get("/api/journey-progress/titles")
|
| 28 |
+
async def get_journey_titles(client: Client = Depends(get_auth_session)):
|
| 29 |
+
return await asyncio.to_thread(db.get_problem_titles_by_number, client)
|
| 30 |
|
| 31 |
|
| 32 |
@router.get("/api/journey-progress/sequences")
|
| 33 |
+
async def get_sequences(client: Client = Depends(get_auth_session)):
|
| 34 |
return [
|
| 35 |
{"id": "leetcode-150", "name": "LeetCode 150"},
|
| 36 |
{"id": "custom", "name": "My Custom Problems"},
|
|
|
|
| 38 |
|
| 39 |
|
| 40 |
@router.get("/api/journey-progress/sequence/{set_id}")
|
| 41 |
+
async def get_sequence_by_id(set_id: str, client: Client = Depends(get_auth_session)):
|
| 42 |
if set_id == "leetcode-150":
|
| 43 |
return [
|
| 44 |
217,
|
|
|
|
| 193 |
7,
|
| 194 |
]
|
| 195 |
elif set_id == "custom":
|
| 196 |
+
user_id = await asyncio.to_thread(db.get_current_user_id, client)
|
| 197 |
if not user_id:
|
| 198 |
return []
|
| 199 |
|
| 200 |
+
problems = await asyncio.to_thread(db.get_all_problems, client)
|
| 201 |
|
| 202 |
sequence = []
|
| 203 |
for p in problems:
|
routers/reviews.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import json
|
| 2 |
import re
|
| 3 |
import uuid
|
|
@@ -56,70 +57,82 @@ def ensure_problem_solutions(prob: dict[str, Any]) -> None:
|
|
| 56 |
|
| 57 |
|
| 58 |
@router.get("/api/streak")
|
| 59 |
-
def get_streak(client: Client = Depends(get_auth_session)):
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
|
| 67 |
@router.get("/api/reviews/due")
|
| 68 |
-
def get_due_reviews(client: Client = Depends(get_auth_session)):
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
prob.get("
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
|
| 81 |
@router.get("/api/reviews/problems/{problem_number}")
|
| 82 |
-
def get_problems_by_number(problem_number: int, client: Client = Depends(get_auth_session)):
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
if p.get("
|
| 92 |
-
if
|
| 93 |
-
|
| 94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
prob["starter_code"] = prob.get("starter_code") or extract_starter_code(
|
| 96 |
prob.get("reference_code", "")
|
| 97 |
)
|
| 98 |
enrich_problem_examples_and_constraints(prob, client)
|
| 99 |
-
|
|
|
|
| 100 |
|
| 101 |
-
|
| 102 |
-
for prob in problems:
|
| 103 |
-
prob["starter_code"] = prob.get("starter_code") or extract_starter_code(
|
| 104 |
-
prob.get("reference_code", "")
|
| 105 |
-
)
|
| 106 |
-
enrich_problem_examples_and_constraints(prob, client)
|
| 107 |
-
ensure_problem_solutions(prob)
|
| 108 |
-
return problems
|
| 109 |
|
| 110 |
|
| 111 |
@router.get("/api/reviews/problems/id/{problem_id}")
|
| 112 |
-
def get_reviews_by_problem_id(problem_id: str, client: Client = Depends(get_auth_session)):
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
prob.get("
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
|
| 125 |
class CompleteReviewRequest(BaseModel):
|
|
@@ -136,7 +149,7 @@ class CompleteReviewRequest(BaseModel):
|
|
| 136 |
|
| 137 |
|
| 138 |
@router.post("/api/reviews/complete")
|
| 139 |
-
def complete_review(req: CompleteReviewRequest, client: Client = Depends(get_auth_session)):
|
| 140 |
card_data = {
|
| 141 |
"fsrs_state": req.fsrs_state,
|
| 142 |
"fsrs_stability": req.fsrs_stability,
|
|
@@ -157,12 +170,14 @@ def complete_review(req: CompleteReviewRequest, client: Client = Depends(get_aut
|
|
| 157 |
"last_reviewed": datetime.now(UTC).isoformat(),
|
| 158 |
}
|
| 159 |
|
| 160 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
|
| 162 |
-
|
| 163 |
-
if streak_data:
|
| 164 |
-
new_streak = srs_logic.increment_streak(streak_data)
|
| 165 |
-
db.update_streak(new_streak, client)
|
| 166 |
|
| 167 |
return {"success": True, "updated_fields": updated_fields, "next_review": next_review_iso}
|
| 168 |
|
|
@@ -257,6 +272,9 @@ def activate_catalog_problem(
|
|
| 257 |
# 3. Ensure journey progress is marked
|
| 258 |
db.insert_journey_progress(req.problem_number, client)
|
| 259 |
|
|
|
|
|
|
|
|
|
|
| 260 |
return {
|
| 261 |
"success": True,
|
| 262 |
"problem_id": prob_id,
|
|
@@ -349,6 +367,9 @@ def activate_batch_problems(req: BatchActivateRequest, client: Client = Depends(
|
|
| 349 |
db.insert_journey_progress(prob_req.problem_number, client)
|
| 350 |
enrolled_count += 1
|
| 351 |
|
|
|
|
|
|
|
|
|
|
| 352 |
return {
|
| 353 |
"success": True,
|
| 354 |
"enrolled_count": enrolled_count,
|
|
@@ -559,7 +580,7 @@ class AISolutionRequest(BaseModel):
|
|
| 559 |
|
| 560 |
|
| 561 |
@router.post("/api/reviews/ai-solution")
|
| 562 |
-
def get_or_generate_solution(
|
| 563 |
req: AISolutionRequest,
|
| 564 |
request: Request,
|
| 565 |
client: Client = Depends(get_auth_session),
|
|
@@ -567,22 +588,32 @@ def get_or_generate_solution(
|
|
| 567 |
x_custom_api_key: str = Header(None),
|
| 568 |
x_gemini_api_key: str = Header(None),
|
| 569 |
):
|
| 570 |
-
user_id = db.get_current_user_id
|
| 571 |
if not user_id:
|
| 572 |
raise HTTPException(status_code=401, detail="Authentication failed")
|
| 573 |
|
| 574 |
prob_id = req.problem_id
|
| 575 |
prob = None
|
| 576 |
if prob_id:
|
| 577 |
-
|
| 578 |
-
|
| 579 |
-
|
| 580 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 581 |
elif req.problem_number is not None:
|
| 582 |
-
|
| 583 |
-
|
| 584 |
-
|
| 585 |
-
|
|
|
|
|
|
|
|
|
|
| 586 |
prob_id = prob["id"]
|
| 587 |
|
| 588 |
# 1. Zero-token: check stored reference_code
|
|
@@ -596,7 +627,7 @@ def get_or_generate_solution(
|
|
| 596 |
pattern = req.pattern or (prob.get("pattern") if prob else "General")
|
| 597 |
|
| 598 |
prompt = f"Provide a clean, optimal Python 3 solution with class Solution for '{prob_name}' ({pattern}). Return ONLY python code, no markdown formatting."
|
| 599 |
-
ai_res = ai_provider.
|
| 600 |
prompt, custom_api_key=api_key, custom_provider=x_ai_provider
|
| 601 |
)
|
| 602 |
code = ai_res.get("text", "")
|
|
@@ -605,7 +636,7 @@ def get_or_generate_solution(
|
|
| 605 |
|
| 606 |
if prob_id and code:
|
| 607 |
try:
|
| 608 |
-
db.update_problem
|
| 609 |
except Exception:
|
| 610 |
pass
|
| 611 |
|
|
@@ -621,8 +652,8 @@ class TestRunRequest(BaseModel):
|
|
| 621 |
|
| 622 |
|
| 623 |
@router.post("/api/reviews/test-run")
|
| 624 |
-
def run_test_cases(req: TestRunRequest, client: Client = Depends(get_auth_session)):
|
| 625 |
-
res = sandbox.
|
| 626 |
req.code, req.test_cases, timeout=req.timeout, starter_code=req.starter_code
|
| 627 |
)
|
| 628 |
if res.get("success") and "results" in res:
|
|
@@ -651,7 +682,7 @@ class EvaluateCodeRequest(BaseModel):
|
|
| 651 |
|
| 652 |
|
| 653 |
@router.post("/api/reviews/evaluate")
|
| 654 |
-
def evaluate_code(
|
| 655 |
req: EvaluateCodeRequest,
|
| 656 |
request: Request,
|
| 657 |
client: Client = Depends(get_auth_session),
|
|
@@ -661,7 +692,7 @@ def evaluate_code(
|
|
| 661 |
):
|
| 662 |
api_key = x_custom_api_key or x_gemini_api_key
|
| 663 |
check_burst_rate_limit(request, api_key)
|
| 664 |
-
eval_res = llm_reviewer.
|
| 665 |
req.problem_name,
|
| 666 |
req.pattern,
|
| 667 |
req.optimal_time,
|
|
@@ -685,7 +716,7 @@ class ExplainCodeRequest(BaseModel):
|
|
| 685 |
|
| 686 |
|
| 687 |
@router.post("/api/reviews/explain")
|
| 688 |
-
def explain_review_code(
|
| 689 |
req: ExplainCodeRequest,
|
| 690 |
request: Request,
|
| 691 |
client: Client = Depends(get_auth_session),
|
|
@@ -696,12 +727,12 @@ def explain_review_code(
|
|
| 696 |
try:
|
| 697 |
api_key = x_custom_api_key or x_gemini_api_key
|
| 698 |
check_burst_rate_limit(request, api_key)
|
| 699 |
-
user_id = db.get_current_user_id
|
| 700 |
if not user_id:
|
| 701 |
raise HTTPException(status_code=401, detail="Authentication failed")
|
| 702 |
|
| 703 |
if req.code is not None:
|
| 704 |
-
eval_res = llm_reviewer.
|
| 705 |
problem_name=req.problem_name or "Unknown Problem",
|
| 706 |
code=req.code,
|
| 707 |
optimal_time=req.optimal_time or "O(N)",
|
|
@@ -714,19 +745,21 @@ def explain_review_code(
|
|
| 714 |
return eval_res
|
| 715 |
|
| 716 |
# Fallback for old clients
|
| 717 |
-
|
| 718 |
-
|
| 719 |
-
|
| 720 |
-
|
| 721 |
-
|
| 722 |
-
if p.get("
|
| 723 |
-
if
|
| 724 |
-
|
| 725 |
-
|
| 726 |
-
|
| 727 |
-
|
| 728 |
-
|
| 729 |
-
|
|
|
|
|
|
|
| 730 |
|
| 731 |
if not res_data:
|
| 732 |
raise HTTPException(
|
|
@@ -754,7 +787,7 @@ def explain_review_code(
|
|
| 754 |
optimal_space = problem.get("optimal_space", "O(N)")
|
| 755 |
problem_name = problem.get("name", "")
|
| 756 |
|
| 757 |
-
eval_res = llm_reviewer.
|
| 758 |
problem_name=problem_name,
|
| 759 |
code=reference_code,
|
| 760 |
optimal_time=optimal_time,
|
|
@@ -772,5 +805,6 @@ def explain_review_code(
|
|
| 772 |
except Exception as e:
|
| 773 |
import traceback
|
| 774 |
|
| 775 |
-
|
|
|
|
| 776 |
raise HTTPException(status_code=500, detail=str(e))
|
|
|
|
| 1 |
+
import asyncio
|
| 2 |
import json
|
| 3 |
import re
|
| 4 |
import uuid
|
|
|
|
| 57 |
|
| 58 |
|
| 59 |
@router.get("/api/streak")
|
| 60 |
+
async def get_streak(client: Client = Depends(get_auth_session)):
|
| 61 |
+
def _fetch_and_update_streak():
|
| 62 |
+
streak_data = db.get_active_streak(client)
|
| 63 |
+
if streak_data:
|
| 64 |
+
streak_data = srs_logic.lazy_check_streak(streak_data)
|
| 65 |
+
db.update_streak(streak_data, client)
|
| 66 |
+
return streak_data
|
| 67 |
+
|
| 68 |
+
return await asyncio.to_thread(_fetch_and_update_streak)
|
| 69 |
|
| 70 |
|
| 71 |
@router.get("/api/reviews/due")
|
| 72 |
+
async def get_due_reviews(client: Client = Depends(get_auth_session)):
|
| 73 |
+
def _fetch_due_reviews():
|
| 74 |
+
reviews = db.get_due_reviews(client)
|
| 75 |
+
for i, review in enumerate(reviews):
|
| 76 |
+
if "problems" in review and review["problems"]:
|
| 77 |
+
prob = review["problems"]
|
| 78 |
+
prob["starter_code"] = prob.get("starter_code") or extract_starter_code(
|
| 79 |
+
prob.get("reference_code", "")
|
| 80 |
+
)
|
| 81 |
+
enrich_problem_examples_and_constraints(prob, client, check_remote_cache=(i < 3))
|
| 82 |
+
ensure_problem_solutions(prob)
|
| 83 |
+
return reviews
|
| 84 |
+
|
| 85 |
+
return await asyncio.to_thread(_fetch_due_reviews)
|
| 86 |
|
| 87 |
|
| 88 |
@router.get("/api/reviews/problems/{problem_number}")
|
| 89 |
+
async def get_problems_by_number(problem_number: int, client: Client = Depends(get_auth_session)):
|
| 90 |
+
def _fetch_by_number():
|
| 91 |
+
if problem_number < 0:
|
| 92 |
+
user_id = db.get_current_user_id(client)
|
| 93 |
+
if not user_id:
|
| 94 |
+
return []
|
| 95 |
+
problems = db.get_all_problems(client)
|
| 96 |
+
matched = []
|
| 97 |
+
for p in problems:
|
| 98 |
+
if p.get("user_id") == user_id:
|
| 99 |
+
if p.get("problem_number") is None:
|
| 100 |
+
if db.get_virtual_number(p["id"]) == problem_number:
|
| 101 |
+
matched.append(p)
|
| 102 |
+
for prob in matched:
|
| 103 |
+
prob["starter_code"] = prob.get("starter_code") or extract_starter_code(
|
| 104 |
+
prob.get("reference_code", "")
|
| 105 |
+
)
|
| 106 |
+
enrich_problem_examples_and_constraints(prob, client)
|
| 107 |
+
return matched
|
| 108 |
+
|
| 109 |
+
problems = db.get_problems_by_number(problem_number, client)
|
| 110 |
+
for prob in problems:
|
| 111 |
prob["starter_code"] = prob.get("starter_code") or extract_starter_code(
|
| 112 |
prob.get("reference_code", "")
|
| 113 |
)
|
| 114 |
enrich_problem_examples_and_constraints(prob, client)
|
| 115 |
+
ensure_problem_solutions(prob)
|
| 116 |
+
return problems
|
| 117 |
|
| 118 |
+
return await asyncio.to_thread(_fetch_by_number)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
|
| 120 |
|
| 121 |
@router.get("/api/reviews/problems/id/{problem_id}")
|
| 122 |
+
async def get_reviews_by_problem_id(problem_id: str, client: Client = Depends(get_auth_session)):
|
| 123 |
+
def _fetch_by_problem_id():
|
| 124 |
+
reviews = db.get_reviews_by_problem_id(problem_id, client)
|
| 125 |
+
for review in reviews:
|
| 126 |
+
if "problems" in review and review["problems"]:
|
| 127 |
+
prob = review["problems"]
|
| 128 |
+
prob["starter_code"] = prob.get("starter_code") or extract_starter_code(
|
| 129 |
+
prob.get("reference_code", "")
|
| 130 |
+
)
|
| 131 |
+
enrich_problem_examples_and_constraints(prob, client)
|
| 132 |
+
ensure_problem_solutions(prob)
|
| 133 |
+
return reviews
|
| 134 |
+
|
| 135 |
+
return await asyncio.to_thread(_fetch_by_problem_id)
|
| 136 |
|
| 137 |
|
| 138 |
class CompleteReviewRequest(BaseModel):
|
|
|
|
| 149 |
|
| 150 |
|
| 151 |
@router.post("/api/reviews/complete")
|
| 152 |
+
async def complete_review(req: CompleteReviewRequest, client: Client = Depends(get_auth_session)):
|
| 153 |
card_data = {
|
| 154 |
"fsrs_state": req.fsrs_state,
|
| 155 |
"fsrs_stability": req.fsrs_stability,
|
|
|
|
| 170 |
"last_reviewed": datetime.now(UTC).isoformat(),
|
| 171 |
}
|
| 172 |
|
| 173 |
+
def _update_review_and_streak():
|
| 174 |
+
db.update_review(req.review_id, db_update, client)
|
| 175 |
+
streak_data = db.get_active_streak(client)
|
| 176 |
+
if streak_data:
|
| 177 |
+
new_streak = srs_logic.increment_streak(streak_data)
|
| 178 |
+
db.update_streak(new_streak, client)
|
| 179 |
|
| 180 |
+
await asyncio.to_thread(_update_review_and_streak)
|
|
|
|
|
|
|
|
|
|
| 181 |
|
| 182 |
return {"success": True, "updated_fields": updated_fields, "next_review": next_review_iso}
|
| 183 |
|
|
|
|
| 272 |
# 3. Ensure journey progress is marked
|
| 273 |
db.insert_journey_progress(req.problem_number, client)
|
| 274 |
|
| 275 |
+
cache.delete_cache(f"due_reviews:{user_id}")
|
| 276 |
+
cache.delete_cache(f"all_problems_reviews:{user_id}")
|
| 277 |
+
|
| 278 |
return {
|
| 279 |
"success": True,
|
| 280 |
"problem_id": prob_id,
|
|
|
|
| 367 |
db.insert_journey_progress(prob_req.problem_number, client)
|
| 368 |
enrolled_count += 1
|
| 369 |
|
| 370 |
+
cache.delete_cache(f"due_reviews:{user_id}")
|
| 371 |
+
cache.delete_cache(f"all_problems_reviews:{user_id}")
|
| 372 |
+
|
| 373 |
return {
|
| 374 |
"success": True,
|
| 375 |
"enrolled_count": enrolled_count,
|
|
|
|
| 580 |
|
| 581 |
|
| 582 |
@router.post("/api/reviews/ai-solution")
|
| 583 |
+
async def get_or_generate_solution(
|
| 584 |
req: AISolutionRequest,
|
| 585 |
request: Request,
|
| 586 |
client: Client = Depends(get_auth_session),
|
|
|
|
| 588 |
x_custom_api_key: str = Header(None),
|
| 589 |
x_gemini_api_key: str = Header(None),
|
| 590 |
):
|
| 591 |
+
user_id = await asyncio.to_thread(db.get_current_user_id, client)
|
| 592 |
if not user_id:
|
| 593 |
raise HTTPException(status_code=401, detail="Authentication failed")
|
| 594 |
|
| 595 |
prob_id = req.problem_id
|
| 596 |
prob = None
|
| 597 |
if prob_id:
|
| 598 |
+
def _fetch_prob_by_id():
|
| 599 |
+
p = db.get_problem(prob_id, client)
|
| 600 |
+
if p and (
|
| 601 |
+
p.get("user_id") == user_id
|
| 602 |
+
or p.get("user_id") == "sandbox-user-id"
|
| 603 |
+
or not p.get("user_id")
|
| 604 |
+
):
|
| 605 |
+
return p
|
| 606 |
+
return None
|
| 607 |
+
|
| 608 |
+
prob = await asyncio.to_thread(_fetch_prob_by_id)
|
| 609 |
elif req.problem_number is not None:
|
| 610 |
+
def _fetch_prob_by_num():
|
| 611 |
+
probs = db.get_problems_by_number(req.problem_number, client)
|
| 612 |
+
user_probs = [p for p in probs if p.get("user_id") == user_id]
|
| 613 |
+
return user_probs[0] if user_probs else None
|
| 614 |
+
|
| 615 |
+
prob = await asyncio.to_thread(_fetch_prob_by_num)
|
| 616 |
+
if prob:
|
| 617 |
prob_id = prob["id"]
|
| 618 |
|
| 619 |
# 1. Zero-token: check stored reference_code
|
|
|
|
| 627 |
pattern = req.pattern or (prob.get("pattern") if prob else "General")
|
| 628 |
|
| 629 |
prompt = f"Provide a clean, optimal Python 3 solution with class Solution for '{prob_name}' ({pattern}). Return ONLY python code, no markdown formatting."
|
| 630 |
+
ai_res = await ai_provider.generate_text_async(
|
| 631 |
prompt, custom_api_key=api_key, custom_provider=x_ai_provider
|
| 632 |
)
|
| 633 |
code = ai_res.get("text", "")
|
|
|
|
| 636 |
|
| 637 |
if prob_id and code:
|
| 638 |
try:
|
| 639 |
+
await asyncio.to_thread(db.update_problem, prob_id, {"reference_code": code}, client)
|
| 640 |
except Exception:
|
| 641 |
pass
|
| 642 |
|
|
|
|
| 652 |
|
| 653 |
|
| 654 |
@router.post("/api/reviews/test-run")
|
| 655 |
+
async def run_test_cases(req: TestRunRequest, client: Client = Depends(get_auth_session)):
|
| 656 |
+
res = await sandbox.run_python_sandbox_async(
|
| 657 |
req.code, req.test_cases, timeout=req.timeout, starter_code=req.starter_code
|
| 658 |
)
|
| 659 |
if res.get("success") and "results" in res:
|
|
|
|
| 682 |
|
| 683 |
|
| 684 |
@router.post("/api/reviews/evaluate")
|
| 685 |
+
async def evaluate_code(
|
| 686 |
req: EvaluateCodeRequest,
|
| 687 |
request: Request,
|
| 688 |
client: Client = Depends(get_auth_session),
|
|
|
|
| 692 |
):
|
| 693 |
api_key = x_custom_api_key or x_gemini_api_key
|
| 694 |
check_burst_rate_limit(request, api_key)
|
| 695 |
+
eval_res = await llm_reviewer.evaluate_code_async(
|
| 696 |
req.problem_name,
|
| 697 |
req.pattern,
|
| 698 |
req.optimal_time,
|
|
|
|
| 716 |
|
| 717 |
|
| 718 |
@router.post("/api/reviews/explain")
|
| 719 |
+
async def explain_review_code(
|
| 720 |
req: ExplainCodeRequest,
|
| 721 |
request: Request,
|
| 722 |
client: Client = Depends(get_auth_session),
|
|
|
|
| 727 |
try:
|
| 728 |
api_key = x_custom_api_key or x_gemini_api_key
|
| 729 |
check_burst_rate_limit(request, api_key)
|
| 730 |
+
user_id = await asyncio.to_thread(db.get_current_user_id, client)
|
| 731 |
if not user_id:
|
| 732 |
raise HTTPException(status_code=401, detail="Authentication failed")
|
| 733 |
|
| 734 |
if req.code is not None:
|
| 735 |
+
eval_res = await llm_reviewer.explain_code_async(
|
| 736 |
problem_name=req.problem_name or "Unknown Problem",
|
| 737 |
code=req.code,
|
| 738 |
optimal_time=req.optimal_time or "O(N)",
|
|
|
|
| 745 |
return eval_res
|
| 746 |
|
| 747 |
# Fallback for old clients
|
| 748 |
+
def _fetch_fallback_problems():
|
| 749 |
+
if req.problem_number is not None and req.problem_number < 0:
|
| 750 |
+
problems = db.get_all_problems(client)
|
| 751 |
+
matched = []
|
| 752 |
+
for p in problems:
|
| 753 |
+
if p.get("user_id") == user_id:
|
| 754 |
+
if p.get("problem_number") is None:
|
| 755 |
+
if db.get_virtual_number(p["id"]) == req.problem_number:
|
| 756 |
+
matched.append(p)
|
| 757 |
+
return matched
|
| 758 |
+
elif req.problem_number is not None:
|
| 759 |
+
return db.get_problems_by_number(req.problem_number, client)
|
| 760 |
+
return []
|
| 761 |
+
|
| 762 |
+
res_data = await asyncio.to_thread(_fetch_fallback_problems)
|
| 763 |
|
| 764 |
if not res_data:
|
| 765 |
raise HTTPException(
|
|
|
|
| 787 |
optimal_space = problem.get("optimal_space", "O(N)")
|
| 788 |
problem_name = problem.get("name", "")
|
| 789 |
|
| 790 |
+
eval_res = await llm_reviewer.explain_code_async(
|
| 791 |
problem_name=problem_name,
|
| 792 |
code=reference_code,
|
| 793 |
optimal_time=optimal_time,
|
|
|
|
| 805 |
except Exception as e:
|
| 806 |
import traceback
|
| 807 |
|
| 808 |
+
err_msg = f"Explain endpoint error: {str(e)}\n{traceback.format_exc()}"
|
| 809 |
+
await asyncio.to_thread(db.log_trace, err_msg)
|
| 810 |
raise HTTPException(status_code=500, detail=str(e))
|
routers/sync.py
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
|
|
|
|
|
| 1 |
from fastapi import APIRouter, Depends, HTTPException
|
| 2 |
|
| 3 |
import db
|
|
@@ -8,18 +10,18 @@ router = APIRouter(tags=["sync"])
|
|
| 8 |
|
| 9 |
|
| 10 |
@router.post("/api/sync")
|
| 11 |
-
def trigger_sync(client: Client = Depends(get_auth_session)):
|
| 12 |
user_id = db.get_current_user_id(client)
|
| 13 |
if user_id == "sandbox-user-id":
|
| 14 |
return {
|
| 15 |
"message": "Google Drive Sync is not available in Sandbox Mode. Please log in to sync your notes."
|
| 16 |
}
|
| 17 |
try:
|
| 18 |
-
res = gdrive_sync.sync_gdrive
|
| 19 |
return {"message": res}
|
| 20 |
except Exception as e:
|
| 21 |
import traceback
|
| 22 |
|
| 23 |
err_msg = f"Sync endpoint exception: {str(e)}\n{traceback.format_exc()}"
|
| 24 |
-
db.log_trace
|
| 25 |
raise HTTPException(status_code=500, detail=err_msg)
|
|
|
|
| 1 |
+
import asyncio
|
| 2 |
+
|
| 3 |
from fastapi import APIRouter, Depends, HTTPException
|
| 4 |
|
| 5 |
import db
|
|
|
|
| 10 |
|
| 11 |
|
| 12 |
@router.post("/api/sync")
|
| 13 |
+
async def trigger_sync(client: Client = Depends(get_auth_session)):
|
| 14 |
user_id = db.get_current_user_id(client)
|
| 15 |
if user_id == "sandbox-user-id":
|
| 16 |
return {
|
| 17 |
"message": "Google Drive Sync is not available in Sandbox Mode. Please log in to sync your notes."
|
| 18 |
}
|
| 19 |
try:
|
| 20 |
+
res = await asyncio.to_thread(gdrive_sync.sync_gdrive, client)
|
| 21 |
return {"message": res}
|
| 22 |
except Exception as e:
|
| 23 |
import traceback
|
| 24 |
|
| 25 |
err_msg = f"Sync endpoint exception: {str(e)}\n{traceback.format_exc()}"
|
| 26 |
+
await asyncio.to_thread(db.log_trace, err_msg)
|
| 27 |
raise HTTPException(status_code=500, detail=err_msg)
|