feat: enhance environment variable management and refactor API route handling: - #294
Conversation
…handling: - Added global environment variables to turbo.json for better configuration management. - Refactored API route handlers to simplify parameter resolution, improving code readability and maintainability. - Updated AI gateway integration to support dual provider functionality, enhancing the review generation process with fallback options.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
|
Warning Review limit reachedNext included review available in 16 minutes. View limit detailsLimit details: You’ve used all 2 included reviews currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (4)
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (8)
Included review availability: Your plan provides up to 2 included reviews per hour; 0 remain after this review. WalkthroughThe change standardizes promise-based marketplace route parameters, adds Vercel and Merge AI gateway fallback support, updates review and embedding model selection, documents gateway variables, and declares required Turbo build environment variables. ChangesMarketplace route context
AI gateway provider fallback
Build environment configuration
Estimated code review effort: 3 (Moderate) | ~25 minutes Merge Risk: ⚪ Minimal · up to The reviewed environment, route-context, and gateway fallback changes have no identified merge-blocking risk. Sequence Diagram(s)sequenceDiagram
participant runGeneratePrReview
participant generateReviewText
participant GatewayProvider
participant ModelProvider
runGeneratePrReview->>generateReviewText: submit prompt
generateReviewText->>GatewayProvider: get ordered providers
generateReviewText->>ModelProvider: request configured model
ModelProvider-->>generateReviewText: return text or retryable error
generateReviewText-->>runGeneratePrReview: return review text or aggregated error
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 6 files. (2 skipped: 2 unsupported.) ✨ Finishing Touches 💡 2📝 Generate docstrings 💡
🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Greptile SummaryThe PR updates Marketplace route contexts for promise-based Next.js parameters and introduces provider-aware AI gateway selection with model fallback for reviews and embeddings.
Confidence Score: 4/5The PR appears safe to merge, though its fallback loop should be bounded to avoid excessive calls and latency on terminal gateway errors. Route and provider-selection changes have no established blocking failure, but the new catch logic retries every remaining model/provider combination even when the error is classified as non-retryable. Files Needing Attention: apps/web/modules/ai/lib/generate-pr-review.ts Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Generate PR review] --> B[Resolve preferred gateway]
B --> C[Resolve ordered model list]
C --> D[Call provider and model]
D -->|Success| E[Return generated review]
D -->|Failure and combinations remain| F[Advance to next combination]
F --> D
D -->|Final failure| G[Throw gateway error]
G --> H[Background-job retry or failure handling]
Reviews (1): Last reviewed commit: "feat: enhance environment variable manag..." | Re-trigger Greptile |
| if (!isLast && isRetryableGatewayModelError(error)) { | ||
| console.warn( | ||
| `[generate-pr-review] ${label} rejected; trying next:`, | ||
| message, | ||
| ) | ||
| continue | ||
| } | ||
|
|
||
| if (!isLast) { | ||
| // Non-policy errors: still try next provider/model once (network blips). | ||
| console.warn( | ||
| `[generate-pr-review] ${label} failed; trying next:`, | ||
| message, | ||
| ) | ||
| continue |
There was a problem hiding this comment.
Non-retryable errors exhaust fallbacks
The catch logic continues for both retryable and non-retryable failures whenever another combination remains, so an invalid credential, malformed request, or content-policy rejection can trigger every remaining provider/model call. This adds unnecessary latency and potential usage charges, and the enclosing job retries can repeat the entire sequence.
🤖 Supercode AI ReviewSummaryThis PR modernizes route param handling in the marketplace app by removing an unnecessary Walkthrough
Changes table
Findings
Risk assessmentMedium — AI gateway behavior changes are central to user-visible PR review generation; if model/provider selection or retry classification is off, review generation could fail more often or take longer due to additional retries. Marketplace route typing changes are lower risk but still affect request routing. Test plan
Suggested PR descriptionWhat
Why
How tested
Automated review by Supercode · leave a 👍/👎 reaction to rate this review |
…ent: - Updated .env.example to reflect new AI gateway provider order and added direct API key options for OPENAI, ANTHROPIC, and GOOGLE. - Added @ai-sdk/anthropic dependency to package.json for improved model support. - Refactored gateway.ts to support multi-provider routing, including direct API access for enhanced review generation. - Improved error handling in generate-pr-review.ts to manage provider-specific errors and optimize model selection based on availability.
Description
Type of change
How Has This Been Tested?
Please describe the tests that you ran to verify your changes.
bun testpassesbun run typecheckpassesbun run lintpasses (if applicable)Checklist:
Summary by CodeRabbit
New Features
Documentation
Reliability