chatbot-template/lib/subscription/config.ts
dmitry.galkin 22a172e92d Add Umami analytics, subscription tiers, tool-call metering
- Analytics: <Analytics /> in root layout loads umami when NEXT_PUBLIC_UMAMI_* env are set
- Subscription: free/pro tiers in Postgres, daily quotas (10msg/5tool free, 1000/500 pro)
- Chat route: checkAndConsume(chat_message) gate before streamText, 429 when exhausted
- Tool metering: getWeather wrapped with withLimit decorator that deducts tool_call quota
- Pricing page at /pricing with upgrade button
- /api/billing/checkout posts to EGBE payment gateway, /api/billing/webhook verifies HMAC and upgrades user on checkout.session.completed
- UsageBadge in chat header polls /api/usage every 15s
- Dropped now-unused entitlements.ts
2026-05-25 17:27:08 +04:00

27 lines
630 B
TypeScript

export type Tier = "free" | "pro";
export type LimitKey = "chat_message" | "tool_call";
export type TierLimits = Record<LimitKey, number>;
export const LIMITS: Record<Tier, TierLimits> = {
free: {
chat_message: 10,
tool_call: 5,
},
pro: {
chat_message: 1000,
tool_call: 500,
},
};
export const TIER_LABELS: Record<Tier, string> = {
free: "Free",
pro: "Pro",
};
export function todayPeriodKey(now = new Date()): string {
const y = now.getUTCFullYear();
const m = String(now.getUTCMonth() + 1).padStart(2, "0");
const d = String(now.getUTCDate()).padStart(2, "0");
return `${y}-${m}-${d}`;
}