Skip to content

feat(content): monthly quota for content brief generation - #224

Merged
gkhngyk merged 1 commit into
mainfrom
feat/brief-generation-quota
Jun 10, 2026
Merged

gkhngyk merged 1 commit into
mainfrom
feat/brief-generation-quota

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a plan-based monthly quota for AI content-brief generation (the "Generate Content Brief" action on /dashboard/content/[id]):

Plan Briefs / month
Starter 10
Growth 50
Enterprise unlimited by default — set per customer via organizations.plan_overrides.maxBriefGenerations
Self-Hosted unlimited (no cloud quota)

Quota resets on the 1st of each month (same convention as maxVolumeAnalyses).

Backend

  • New brief_usage table (migration 00015), mirroring the volume_usage pattern: one row per generated brief, counted per org per month. RLS enabled, service-role only.
  • maxBriefGenerations added to plan definitions (web + server, kept in sync).
  • Enforcement lives in the shared generateBriefForOpportunity core, so the dashboard route and the internal MCP route draw from the same monthly pool. Cached brief reads never charge quota.
  • Server plan resolution now applies enterprise plan_overrides — parity with the web getOrgPlan() behavior.
  • POST /api/content/:id/brief now does an org-ownership check (quota is charged to the opportunity's org) and returns the updated quota; quota exhaustion returns 403 quota_exceeded with a clear message.
  • New GET /api/content/briefs/quota returns { used, limit, remaining }.

Frontend

  • Content detail page shows X/Y briefs remaining this month under the generate button (hidden when unlimited).
  • When the quota is exhausted, the generate card switches to an Upgrade Plan CTA linking to Settings → Billing.

Setting an Enterprise customer limit

UPDATE organizations
SET plan_overrides = coalesce(plan_overrides, '{}'::jsonb) || '{"maxBriefGenerations": 200}'
WHERE id = '<org-id>';

Test plan

  • node --check on all edited server files
  • Server eslint + prettier --check pass
  • Web tsc --noEmit, eslint (0 errors), vitest (10/10) pass
  • Apply migration 00015_brief_usage.sql to the cloud DB before deploy
  • Manual: generate briefs until limit on a Starter org → counter decrements, 11th attempt shows upgrade CTA
  • Manual: self-hosted (IS_CLOUD != true) shows no counter and no limit

Made with Cursor

Cloud plans now cap AI content-brief generations per calendar month:
Starter 10, Growth 50, Enterprise unlimited by default with per-customer
overrides via organizations.plan_overrides.maxBriefGenerations.
Self-hosted stays unlimited.

- New brief_usage table (mirrors volume_usage) tracks generations per org
- Quota enforced in the shared generateBriefForOpportunity core so the
  dashboard route and internal MCP route draw from the same pool; cached
  brief reads never charge quota
- Server plan resolution now applies enterprise plan_overrides (parity
  with web getOrgPlan)
- Dashboard brief route gains an org-ownership check and returns the
  updated quota; new GET /api/content/briefs/quota endpoint
- Content detail page shows remaining briefs and swaps the generate
  button for an Upgrade Plan CTA when the quota is exhausted

Co-authored-by: Cursor <[email protected]>
@gkhngyk
gkhngyk merged commit 5fb12ab into main Jun 10, 2026
4 checks passed
@gkhngyk
gkhngyk deleted the feat/brief-generation-quota branch June 10, 2026 14:24

This branch was successfully deployed

1 active deployment
Preview — a24c47f7 Deployed Jun 10, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant