refactor(credits): consume the api credits endpoint; delete chat's duplicated stack#1842
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Review limit reached
Next review available in: 59 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the 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 configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (3)
📒 Files selected for processing (15)
✨ Finishing Touches🧪 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 |
There was a problem hiding this comment.
1 issue found across 8 files
Confidence score: 3/5
- In
lib/credits/checkAndResetCredits.ts, usingPromise.allmeans an enterprise-email lookup error can reject the whole refill path, so otherwise eligible paid users may not get credits reset/refilled as expected. This creates a concrete user-facing billing/entitlement regression risk—handle lookup failures by degrading enterprise detection tofalse(or otherwise isolating that failure) before merging.
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
…plicated credits stack Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
7bca1cb to
b8cb180
Compare
Preview verification — 2026-07-03 (rescoped consolidation)Preview
Not exercised live: the rendered sidebar number (needs a logged-in Privy session on the preview domain). The data path it renders is #4, verified; Once merged, the sidebar tier-mismatch window closes retroactively — chat displays whatever the api computes, including the enterprise-pro 9,999 already live on prod. |
Full-flow browser verification — 2026-07-03Follow-up to the earlier table: drove the complete user flow on the preview via browser automation (Chrome DevTools MCP) — Privy email login as sweetmantech@gmail.com (OTP), workspace load, user menu open.
Environment finding (process, not a PR defect): chat previews point at |
Rescope decision (owner, 2026-07-03)
This PR originally mirrored the api repo's enterprise-pro credits change into chat's own duplicated credits stack. The owner decided to replace that with a consolidation: chat stops computing credits itself and consumes the api's credits endpoint. Credits logic (monthly reset, pro and enterprise tiers, totals) now lives only in the api repo. The old mirror commit (7bca1cb) was discarded and the branch force-pushed.
Related: #1841 (tracking) and recoupable/api#747 (merged api side: enterprise-domain accounts resolve pro, PRO_CREDITS 9999).
Rewired
lib/recoup/getAccountCredits.ts(new): callsGET {API_BASE}/api/accounts/{accountId}/creditswith the user's Privy bearer token, following thelib/recoup/fetchPosts.tsanduseProStatuspatterns. Returns the api's flat shape:account_id,remaining_credits,total_credits,used_credits,is_pro,timestamp.hooks/useCredits.ts: now acquires the Privy access token (likeuseProStatus) and calls the new helper. Query key, staleTime, and enabled gating unchanged; the data type changed from thecredits_usageDB row to the api response (fieldremaining_creditsis common to both).hooks/usePayment.tsx:totalCreditsnow comes from the api response (total_credits) instead of the localPRO_CREDITS/DEFAULT_CREDITSconstants (which were stale: chat said 1000, the api grants 9999 for pro). External contract ofusePayment(credits,totalCredits,isSubscribed,isLoading,refetchCredits) is unchanged, so no component changes.Deleted (dead after consolidation, zero remaining callers)
app/api/credits/get/route.ts(chat's own credits endpoint)lib/credits/checkAndResetCredits.ts(reset/refill logic, now api-side)lib/supabase/getCredits.tsx(replaced bylib/recoup/getAccountCredits.ts)lib/supabase/credits_usage/:initializeAccountCredits.ts,selectCreditsUsage.ts,updateCreditsUsage.tslib/stripe/:getOrgSubscription.ts,getActiveSubscriptionDetails.ts,getActiveSubscriptions.ts,isActiveSubscription.ts,client.tsx(the Stripe SDK client; the surviving stripe helpers call the api over HTTP)DEFAULT_CREDITS/PRO_CREDITSfromlib/consts.tsstripenpm dependency (all importers deleted; chat no longer needsSTRIPE_SK)Kept:
useProStatus(still theisSubscribedsource inusePayment),getAccountOrganizations(used bylib/organizations/formatAccountOrganizations.ts),createClientCheckoutSession/createClientPortalSession(used byuseSubscribeClick).Verification
lib/recoup/__tests__/getAccountCredits.test.ts, written red-first)pnpm exec tsc --noEmit: 7 errors, all pre-existing inlib/emails/__tests__/extractSendEmailResults.test.ts— zero newnext lintis broken repo-wide, pre-existing)pnpm buildfails locally on missing env (pre-existing)🤖 Generated with Claude Code