Skip to content

8 add client side entitlement layer and feature flag system#25

Merged
PAMulligan merged 2 commits into
mainfrom
8-add-client-side-entitlement-layer-and-feature-flag-system
Jul 21, 2026
Merged

8 add client side entitlement layer and feature flag system#25
PAMulligan merged 2 commits into
mainfrom
8-add-client-side-entitlement-layer-and-feature-flag-system

Conversation

@PAMulligan

Copy link
Copy Markdown
Contributor

No description provided.

Paul Mulligan and others added 2 commits July 21, 2026 13:24
Implements the free/Pro split (closes #9), stacked on the #8 entitlement
layer. AI provider migrated OpenAI -> Anthropic as part of the same change.

Free/Pro matrix (docs/free-vs-pro-gating.md):
- SEO scoring + score breakdown: fully free, never gated.
- AI recommendations: free via a capped, server-metered hosted proxy; Pro
  gets a higher proxy cap or unlimited with their own key.
- Advanced options, multi-language output, schema generation, and BYO key:
  Pro only. Every gate reads an entitlement-store flag (canUse*/isPro),
  never an ad-hoc apiKey check.

Three AI paths (app/src/lib/ai.ts + entitlement-store useAiStatus):
- byok: Pro + own Anthropic key -> browser->Anthropic directly, unlimited.
- pro:  Pro, no key -> hosted proxy authenticated by X-Optia-Entitlement.
- free: not Pro -> hosted proxy metered by install id.
A stored key only unlocks the direct path when isPro, so a free user can
never self-serve uncapped AI. The BYO key never transits Optia's backend.

Provider migration:
- openai.ts -> anthropic.ts using @anthropic-ai/sdk (claude-opus-4-8,
  dangerouslyAllowBrowser); new ai-proxy.ts for POST /ai/generate; ai.ts
  facade routes + records server-authoritative quota. Storage key
  openai_api_key -> anthropic_api_key; dev CORS proxy and all UI labels
  updated to Anthropic.

Quota is server-authoritative: /ai/generate returns quota {limit,remaining,
period} which the client caches; on a server quota_exceeded the client
drives remaining to 0 so the gate converges to a friendly upsell (no dead
ends). Free users generate on demand (auto-generate only runs on the
uncapped byok/pro paths) to conserve the monthly allowance.

Note: the shipped backend meters a MONTHLY free allowance (not the daily
cap the issue proposed); the client follows the backend.

Tests: 411 passing. New coverage for the proxy client, the Anthropic
direct client, the AI router (all three paths + locked + quota-exhaustion
lock + metered-subject), the quota model, and free/Pro rendering of every
gated surface (schema, multi-language, BYO-key, advanced options, and the
scoring-stays-free guarantee). tsc + vite build + eslint all green.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…e-vs-pro-feature-gating

feat(gating): free vs Pro feature gating + Anthropic migration
@PAMulligan
PAMulligan merged commit e7acd1f into main Jul 21, 2026
3 checks passed
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