Skip to content

feat(ai): wire DifficultyEstimator to real backend AI endpoint (#1574) - #1669

Open
saidai-bhuvanesh wants to merge 1 commit into
Canopus-Labs:mainfrom
saidai-bhuvanesh:fix/issue-1574-difficulty-estimator-ai-endpoint
Open

feat(ai): wire DifficultyEstimator to real backend AI endpoint (#1574)#1669
saidai-bhuvanesh wants to merge 1 commit into
Canopus-Labs:mainfrom
saidai-bhuvanesh:fix/issue-1574-difficulty-estimator-ai-endpoint

Conversation

@saidai-bhuvanesh

Copy link
Copy Markdown
Contributor

The DifficultyEstimator page returned hardcoded results (Hard/94%/35 Minutes/same 4 prerequisites) for every question, and no backend endpoint existed to produce a genuine estimate.

Backend

  • Add difficultyEstimatePrompt() to utils/prompts.js
  • Add estimateDifficulty controller in aiController.js that calls generateWithFallback and validates the Gemini JSON response with Zod (difficulty enum, confidence 0-100, estimatedTime, prerequisites, analysis)
  • Add validateEstimateDifficulty Zod middleware in ValidateAi.js
  • Mount POST /api/ai/estimate-difficulty (protect + aiLimiter + sensitiveRouteHeaders) in server.js

Frontend

  • Add ESTIMATE_DIFFICULTY to apiPaths.js
  • Rewrite DifficultyEstimator.jsx to POST to the endpoint with loading and error states (react-hot-toast), rendering dynamic results (difficulty-colored badge, confidence, estimated time, analysis text, prerequisite chips). All hardcoded values removed.

Frontend build verified: vite build passes cleanly.

Closes #1574
Closes #1648

This PR was created by an AI agent (OpenHands) on behalf of saidai-bhuvanesh.

…us-Labs#1574)

The DifficultyEstimator page returned hardcoded results (Hard/94%/35
Minutes/same 4 prerequisites) for every question, and no backend
endpoint existed to produce a genuine estimate.

Backend:
- Add difficultyEstimatePrompt() to utils/prompts.js
- Add estimateDifficulty controller to aiController.js that calls
  generateWithFallback and validates the Gemini JSON response with
  Zod (difficulty enum, confidence 0-100, estimatedTime,
  prerequisites, analysis)
- Add validateEstimateDifficulty Zod middleware in ValidateAi.js
- Mount POST /api/ai/estimate-difficulty (protect + aiLimiter +
  sensitiveRouteHeaders) in server.js

Frontend:
- Add ESTIMATE_DIFFICULTY to apiPaths.js
- Rewrite DifficultyEstimator.jsx to POST to the endpoint with
  loading and error states (react-hot-toast), and render dynamic
  results (difficulty-colored badge, confidence, estimated time,
  analysis text, prerequisite chips). Removed all hardcoded values.

Closes Canopus-Labs#1574
Closes Canopus-Labs#1648

Co-authored-by: openhands <openhands@all-hands.dev>
@coderabbitai

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@saidai-bhuvanesh, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 38 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b05e3bb6-9f64-400e-be13-823c6d0061af

📥 Commits

Reviewing files that changed from the base of the PR and between 33a3c81 and f48e908.

📒 Files selected for processing (6)
  • backend/Input_validators/ValidateAi.js
  • backend/controllers/aiController.js
  • backend/server.js
  • backend/utils/prompts.js
  • frontend/src/pages/DifficultyEstimator/DifficultyEstimator.jsx
  • frontend/src/utils/apiPaths.js

Comment @coderabbitai help to get the list of available commands.

const rawText = await result.response.text();
let cleanedText = rawText
.replace(/^(\s*```json\s*|\s*```\s*)+/i, "")
.replace(/(\s*```\s*)+$/i, "")
@github-actions github-actions Bot added the merge ready PR is mergeable and has no conflicts label Aug 8, 2026
@KaranUnique

Copy link
Copy Markdown
Contributor

@saidai-bhuvanesh Take a look on github bot suggestion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge ready PR is mergeable and has no conflicts

Projects

None yet

4 participants