Open-source agentic AI Search Execution Platform. Track AI visibility, find opportunities, and let agents turn signals into prioritized actions and drafted fixes across ChatGPT, Claude, Gemini, Google AI Overviews, Google AI Mode, Perplexity, Grok, and Microsoft Copilot.
TypeScript aeoai-agentai-searchanswer-engine-optimizationbrand-monitoringchatgptclaudecopilotdockergeminigeogoogle-ai-overviewsgrokmcpnextjsopen-sourceperplexityseosupabasetypescript
feat(plans): gate Claude tracking to Enterprise per-customer opt-in on cloud (#423)
Gökhan Geyik9485b04242e6
diff --git a/server/src/config/plans.js b/server/src/config/plans.jsindex 1710ceaa1..96c8d910f 100644--- a/server/src/config/plans.js+++ b/server/src/config/plans.js@@ -77,6 +77,9 @@ export const PLANS = {maxSiteAudits: 500,maxDailyOnDemand: 10,onDemandCooldownMinutes: 5,+ // API-model tracking (Claude) is not part of Growth — scraper engines+ // only. Enterprise can get it per customer via plan_overrides.+ allowedModels: [],features: ['basic_insights','prompt_suggestions',@@ -107,6 +110,10 @@ export const PLANS = {maxSiteAudits: -1,maxDailyOnDemand: -1,onDemandCooldownMinutes: 0,+ // API-model tracking (Claude) is a per-customer opt-in on Enterprise:+ // default off; enable via+ // organizations.plan_overrides = { "allowedModels": ["claude-sonnet-5"] }.+ allowedModels: [],features: ['basic_insights','prompt_suggestions',diff --git a/server/src/lib/plan-guard.js b/server/src/lib/plan-guard.jsindex 2525cb384..96c0ad6c6 100644--- a/server/src/lib/plan-guard.js+++ b/server/src/lib/plan-guard.js@@ -19,7 +19,7 @@ export class PlanLimitError extends Error {* Enterprise orgs can have per-customer limit overrides stored in* organizations.plan_overrides (jsonb) — mirrors web getOrgPlan().*/-function applyPlanOverrides(plan, org) {+export function applyPlanOverrides(plan, org) {if (org?.plan === 'enterprise' && org.plan_overrides && typeof org.plan_overrides === 'object') {return { ...plan, limits: { ...plan.limits, ...org.plan_overrides } };}diff --git a/server/src/workers/tracking-worker.js b/server/src/workers/tracking-worker.jsindex a071bc634..9660b46e6 100644--- a/server/src/workers/tracking-worker.js+++ b/server/src/workers/tracking-worker.js@@ -7,7 +7,8 @@ import { runPrompt, analyzeSentimentAI } from '../lib/ai-tracker.js';import { submitScraperTask, pollScraperResult } from '../lib/cloro-scraper.js';import { parseResponse, countBrandMentions } from '../lib/response-parser.js';import supabaseAdmin from '../config/supabase.js';-import { hasFeature, getPlan } from '../config/plans.js';+import { hasFeature, getPlan, isCloud } from '../config/plans.js';+import { applyPlanOverrides } from '../lib/plan-guard.js';import { generateContentOpportunities } from '../lib/opportunity-generator.js';import logger from '../lib/logger.js';@@ -84,10 +85,33 @@ export async function processTrackingJob({ brandId, promptId, promptIds, job })domain: c.domain || '',}));+ // 3b. Cloud: API-model tracking is plan-gated (Growth has no Claude;+ // Enterprise is per-customer via organizations.plan_overrides.allowedModels).+ // Prompts can still carry disallowed model ids from an earlier plan, so+ // filter at run time instead of trusting the stored arrays. `null` means+ // every model is allowed (self-host, or a plan without the restriction).+ let allowedModels = null;+ if (isCloud()) {+ const { data: org } = await supabaseAdmin+ .from('organizations')+ .select('plan, plan_overrides')+ .eq('id', brand.organization_id)+ .single();+ const plan = applyPlanOverrides(getPlan(org?.plan), org);+ allowedModels = plan.limits.allowedModels ?? null;+ if (allowedModels) {+ logger.info({ brandId, allowedModels }, 'api-model tracking plan-gated for this org');+ }+ }+ const allowedModelsFor = (prompt) => {+ const models = prompt.models && prompt.models.length > 0 ? prompt.models : [];+ return allowedModels ? models.filter((m) => allowedModels.includes(m)) : models;+ };+// 4. Count total tasks: prompt × (models + scrapers) × regionslet totalTasks = 0;for (const prompt of prompts) {- const mc = prompt.models && prompt.models.length > 0 ? prompt.models.length : 0;+ const mc = allowedModelsFor(prompt).length;const sc = prompt.platforms && prompt.platforms.length > 0 ? prompt.platforms.length : 0;const rc = prompt.regions && prompt.regions.length > 0 ? prompt.regions.length : 1;totalTasks += (mc + sc) * rc;@@ -337,7 +361,7 @@ export async function processTrackingJob({ brandId, promptId, promptIds, job })// 7. Phase 2: Run AI model tasks concurrentlyconst modelTasks = [];for (const prompt of prompts) {- const modelsToRun = prompt.models && prompt.models.length > 0 ? prompt.models : [];+ const modelsToRun = allowedModelsFor(prompt);const regionsToRun = prompt.regions && prompt.regions.length > 0 ? prompt.regions : [null];for (const modelName of modelsToRun) {diff --git a/web/src/app/[locale]/(dashboard)/dashboard/brands/[id]/prompts/page.tsx b/web/src/app/[locale]/(dashboard)/dashboard/brands/[id]/prompts/page.tsxindex d8454dd42..6490f39f0 100644--- a/web/src/app/[locale]/(dashboard)/dashboard/brands/[id]/prompts/page.tsx+++ b/web/src/app/[locale]/(dashboard)/dashboard/brands/[id]/prompts/page.tsx@@ -74,16 +74,18 @@ export default function PromptsPage() {const [manualText, setManualText] = useState('');const [manualCategory, setManualCategory] = useState('');const [generateTopics, setGenerateTopics] = useState<string[] | null>(null);- const { planId } = usePlanContext();+ const { planId, allowedModelIds: planAllowedModelIds } = usePlanContext();const { canManage } = useUserRole();const allowedScraperIds = useMemo(() => {const allowed = PLANS[planId].limits.allowedScrapers;return allowed ? [...allowed] : ALL_SCRAPERS.map((s) => s.id);}, [planId]);- const allowedModelIds = useMemo(() => {- const allowed = PLANS[planId].limits.allowedModels;- return allowed ? [...allowed] : ALL_MODELS.map((m) => m.id);- }, [planId]);+ // From context, not PLANS[planId]: Enterprise orgs can have Claude switched+ // on per customer via plan_overrides, which only the layout can see.+ const allowedModelIds = useMemo(+ () => planAllowedModelIds ?? ALL_MODELS.map((m) => m.id),+ [planAllowedModelIds],+ );const visibleScrapers = useMemo(() => ALL_SCRAPERS.filter((s) => allowedScraperIds.includes(s.id)),[allowedScraperIds],diff --git a/web/src/app/[locale]/(dashboard)/dashboard/brands/new/page.tsx b/web/src/app/[locale]/(dashboard)/dashboard/brands/new/page.tsxindex 569b4d7c5..739f384a6 100644--- a/web/src/app/[locale]/(dashboard)/dashboard/brands/new/page.tsx+++ b/web/src/app/[locale]/(dashboard)/dashboard/brands/new/page.tsx@@ -8,6 +8,7 @@ import { createTopics } from '@/lib/actions/topic';import { savePromptSet } from '@/lib/actions/prompt';import { addCompetitor } from '@/lib/actions/competitor';import { triggerTrackingCheck } from '@/lib/actions/tracking';+import { usePlanContext } from '@/components/providers/plan-provider';import { getFaviconUrl } from '@/lib/favicon';import { useBrandStore } from '@/stores/use-brand-store';import { REGIONS, LANGUAGES } from '@/config/prompt-options';@@ -279,7 +280,9 @@ export default function NewBrandPage() {const activeScrapers = allowedScraperIds? ALL_SCRAPERS.filter((s) => allowedScraperIds.includes(s.id)): ALL_SCRAPERS;- const allowedModelIds = currentPlan.limits.allowedModels;+ // From context, not the static plan config: Enterprise orgs can have Claude+ // switched on per customer via plan_overrides, which the layout merges in.+ const { allowedModelIds } = usePlanContext();const activeModels = allowedModelIds? ALL_MODELS.filter((m) => allowedModelIds.includes(m.id)): ALL_MODELS;diff --git a/web/src/app/[locale]/(dashboard)/layout.tsx b/web/src/app/[locale]/(dashboard)/layout.tsxindex 4fe105d77..298363557 100644--- a/web/src/app/[locale]/(dashboard)/layout.tsx+++ b/web/src/app/[locale]/(dashboard)/layout.tsx@@ -9,7 +9,7 @@ import { RoleProvider, type TeamRole } from '@/components/providers/role-provideimport { BrandLoader } from '@/components/providers/brand-loader';import { BrandGuard } from '@/components/providers/brand-guard';import { getBrands } from '@/lib/actions/brand';-import { isCloud, type PlanId } from '@/config/plans';+import { getPlan, isCloud, type PlanId } from '@/config/plans';import { evaluateSubscriptionAccess } from '@/lib/billing/subscription-access';import { SubscriptionExpiredNotice } from '@/components/billing/subscription-expired-notice';@@ -38,7 +38,7 @@ export default async function DashboardLayout({ children }: { children: React.Reconst [{ data: org }, brands] = await Promise.all([supabase.from('organizations')- .select('plan, subscription_status')+ .select('plan, subscription_status, plan_overrides').eq('id', profile.organization_id).single(),getBrands(profile.organization_id),@@ -66,11 +66,24 @@ export default async function DashboardLayout({ children }: { children: React.Reconst planId = (org?.plan ?? 'starter') as PlanId;+ // Effective API-model allowlist for the client (null = all allowed).+ // Enterprise orgs can be switched on per customer via+ // organizations.plan_overrides — same merge getOrgPlan applies.+ let allowedModelIds: string[] | null = null;+ if (isCloud()) {+ const overrides =+ planId === 'enterprise' && org?.plan_overrides+ ? (org.plan_overrides as { allowedModels?: string[] })+ : null;+ const effective = overrides?.allowedModels ?? getPlan(planId).limits.allowedModels;+ allowedModelIds = effective ? [...effective] : null;+ }+return (<><AuthProvider user={user} /><BrandLoader brands={brands} />- <PlanProvider planId={planId}>+ <PlanProvider planId={planId} allowedModelIds={allowedModelIds}><RoleProvider role={role}><div className="flex h-screen overflow-hidden">{/* Desktop sidebar */}diff --git a/web/src/components/providers/plan-provider.tsx b/web/src/components/providers/plan-provider.tsxindex 5cea25843..cf85818e0 100644--- a/web/src/components/providers/plan-provider.tsx+++ b/web/src/components/providers/plan-provider.tsx@@ -6,19 +6,43 @@ import type { PlanId } from '@/config/plans';interface PlanContextValue {planId: PlanId;isCloud: boolean;+ /**+ * Effective API-model allowlist for the org, with Enterprise+ * `plan_overrides` already merged server-side (dashboard layout).+ * `null` means every model is allowed (self-host, or a plan without an+ * `allowedModels` restriction). Consumers must read this instead of the+ * static `PLANS[planId].limits.allowedModels`, which can't see+ * per-customer overrides.+ */+ allowedModelIds: string[] | null;}const PlanContext = createContext<PlanContextValue>({planId: 'self_hosted',isCloud: false,+ allowedModelIds: null,});-export function PlanProvider({ planId, children }: { planId: PlanId; children: React.ReactNode }) {+export function PlanProvider({+ planId,+ allowedModelIds = null,+ children,+}: {+ planId: PlanId;+ allowedModelIds?: string[] | null;+ children: React.ReactNode;+}) {const isCloud = process.env.NEXT_PUBLIC_IS_CLOUD === 'true';const effectivePlan: PlanId = isCloud ? planId : 'self_hosted';return (- <PlanContext.Provider value={{ planId: effectivePlan, isCloud }}>+ <PlanContext.Provider+ value={{+ planId: effectivePlan,+ isCloud,+ allowedModelIds: isCloud ? allowedModelIds : null,+ }}+ >{children}</PlanContext.Provider>);diff --git a/web/src/config/plans.ts b/web/src/config/plans.tsindex 8a63b757f..c8c9ea36d 100644--- a/web/src/config/plans.ts+++ b/web/src/config/plans.ts@@ -153,6 +153,9 @@ export const PLANS: Record<PlanId, Plan> = {maxSiteAudits: 500,maxDailyOnDemand: 10,onDemandCooldownMinutes: 5,+ // API-model tracking (Claude) is not part of Growth — scraper engines+ // only. Enterprise can get it per customer via plan_overrides below.+ allowedModels: [],features: ['basic_insights','prompt_suggestions',@@ -185,6 +188,12 @@ export const PLANS: Record<PlanId, Plan> = {maxSiteAudits: -1,maxDailyOnDemand: -1,onDemandCooldownMinutes: 0,+ // API-model tracking (Claude) is a per-customer opt-in on Enterprise:+ // default off; enable by setting+ // organizations.plan_overrides = { "allowedModels": ["claude-sonnet-5"] }.+ // getOrgPlan / the server's applyPlanOverrides merge that over these+ // limits, so no code change is needed to switch a customer on.+ allowedModels: [],features: ['basic_insights','prompt_suggestions',diff --git a/web/src/lib/plan-engines.ts b/web/src/lib/plan-engines.tsindex 5f15e4796..3443a2fc8 100644--- a/web/src/lib/plan-engines.ts+++ b/web/src/lib/plan-engines.ts@@ -59,7 +59,23 @@ export async function alignPromptsToPlanForOrg(models: string[];promptCount: number;}> {- const { platforms, models } = getActiveEngineIdsForPlan(planId);+ const { platforms, models: baseModels } = getActiveEngineIdsForPlan(planId);++ // Enterprise: API-model tracking (Claude) is a per-customer opt-in via+ // organizations.plan_overrides.allowedModels — without this check, an+ // alignment run would strip Claude from a customer we've enabled it for.+ let models = baseModels;+ if (planId === 'enterprise') {+ const { data: org } = await supabaseAdmin+ .from('organizations')+ .select('plan_overrides')+ .eq('id', orgId)+ .maybeSingle();+ const overrides = org?.plan_overrides as { allowedModels?: string[] } | null;+ if (overrides?.allowedModels) {+ models = ALL_MODELS.filter((m) => overrides.allowedModels!.includes(m.id)).map((m) => m.id);+ }+ }const { data: brands, error: brandsErr } = await supabaseAdmin.from('brands')