availsync 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.adal/skills/stripe-best-practices/SKILL.md +42 -0
- package/.adal/skills/stripe-best-practices/references/billing.md +36 -0
- package/.adal/skills/stripe-best-practices/references/connect.md +48 -0
- package/.adal/skills/stripe-best-practices/references/payments.md +79 -0
- package/.adal/skills/stripe-best-practices/references/security.md +109 -0
- package/.adal/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.adal/skills/stripe-projects/SKILL.md +139 -0
- package/.adal/skills/upgrade-stripe/SKILL.md +185 -0
- package/.agents/skills/stripe-best-practices/SKILL.md +42 -0
- package/.agents/skills/stripe-best-practices/references/billing.md +36 -0
- package/.agents/skills/stripe-best-practices/references/connect.md +48 -0
- package/.agents/skills/stripe-best-practices/references/payments.md +79 -0
- package/.agents/skills/stripe-best-practices/references/security.md +109 -0
- package/.agents/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.agents/skills/stripe-projects/SKILL.md +139 -0
- package/.agents/skills/upgrade-stripe/SKILL.md +185 -0
- package/.augment/skills/stripe-best-practices/SKILL.md +42 -0
- package/.augment/skills/stripe-best-practices/references/billing.md +36 -0
- package/.augment/skills/stripe-best-practices/references/connect.md +48 -0
- package/.augment/skills/stripe-best-practices/references/payments.md +79 -0
- package/.augment/skills/stripe-best-practices/references/security.md +109 -0
- package/.augment/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.augment/skills/stripe-projects/SKILL.md +139 -0
- package/.augment/skills/upgrade-stripe/SKILL.md +185 -0
- package/.bob/skills/stripe-best-practices/SKILL.md +42 -0
- package/.bob/skills/stripe-best-practices/references/billing.md +36 -0
- package/.bob/skills/stripe-best-practices/references/connect.md +48 -0
- package/.bob/skills/stripe-best-practices/references/payments.md +79 -0
- package/.bob/skills/stripe-best-practices/references/security.md +109 -0
- package/.bob/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.bob/skills/stripe-projects/SKILL.md +139 -0
- package/.bob/skills/upgrade-stripe/SKILL.md +185 -0
- package/.claude/settings.local.json +7 -0
- package/.claude/skills/stripe-best-practices/SKILL.md +42 -0
- package/.claude/skills/stripe-best-practices/references/billing.md +36 -0
- package/.claude/skills/stripe-best-practices/references/connect.md +48 -0
- package/.claude/skills/stripe-best-practices/references/payments.md +79 -0
- package/.claude/skills/stripe-best-practices/references/security.md +109 -0
- package/.claude/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.claude/skills/stripe-projects/SKILL.md +139 -0
- package/.claude/skills/upgrade-stripe/SKILL.md +185 -0
- package/.codebuddy/skills/stripe-best-practices/SKILL.md +42 -0
- package/.codebuddy/skills/stripe-best-practices/references/billing.md +36 -0
- package/.codebuddy/skills/stripe-best-practices/references/connect.md +48 -0
- package/.codebuddy/skills/stripe-best-practices/references/payments.md +79 -0
- package/.codebuddy/skills/stripe-best-practices/references/security.md +109 -0
- package/.codebuddy/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.codebuddy/skills/stripe-projects/SKILL.md +139 -0
- package/.codebuddy/skills/upgrade-stripe/SKILL.md +185 -0
- package/.commandcode/skills/stripe-best-practices/SKILL.md +42 -0
- package/.commandcode/skills/stripe-best-practices/references/billing.md +36 -0
- package/.commandcode/skills/stripe-best-practices/references/connect.md +48 -0
- package/.commandcode/skills/stripe-best-practices/references/payments.md +79 -0
- package/.commandcode/skills/stripe-best-practices/references/security.md +109 -0
- package/.commandcode/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.commandcode/skills/stripe-projects/SKILL.md +139 -0
- package/.commandcode/skills/upgrade-stripe/SKILL.md +185 -0
- package/.continue/skills/stripe-best-practices/SKILL.md +42 -0
- package/.continue/skills/stripe-best-practices/references/billing.md +36 -0
- package/.continue/skills/stripe-best-practices/references/connect.md +48 -0
- package/.continue/skills/stripe-best-practices/references/payments.md +79 -0
- package/.continue/skills/stripe-best-practices/references/security.md +109 -0
- package/.continue/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.continue/skills/stripe-projects/SKILL.md +139 -0
- package/.continue/skills/upgrade-stripe/SKILL.md +185 -0
- package/.cortex/skills/stripe-best-practices/SKILL.md +42 -0
- package/.cortex/skills/stripe-best-practices/references/billing.md +36 -0
- package/.cortex/skills/stripe-best-practices/references/connect.md +48 -0
- package/.cortex/skills/stripe-best-practices/references/payments.md +79 -0
- package/.cortex/skills/stripe-best-practices/references/security.md +109 -0
- package/.cortex/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.cortex/skills/stripe-projects/SKILL.md +139 -0
- package/.cortex/skills/upgrade-stripe/SKILL.md +185 -0
- package/.crush/skills/stripe-best-practices/SKILL.md +42 -0
- package/.crush/skills/stripe-best-practices/references/billing.md +36 -0
- package/.crush/skills/stripe-best-practices/references/connect.md +48 -0
- package/.crush/skills/stripe-best-practices/references/payments.md +79 -0
- package/.crush/skills/stripe-best-practices/references/security.md +109 -0
- package/.crush/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.crush/skills/stripe-projects/SKILL.md +139 -0
- package/.crush/skills/upgrade-stripe/SKILL.md +185 -0
- package/.env.example +20 -0
- package/.factory/skills/stripe-best-practices/SKILL.md +42 -0
- package/.factory/skills/stripe-best-practices/references/billing.md +36 -0
- package/.factory/skills/stripe-best-practices/references/connect.md +48 -0
- package/.factory/skills/stripe-best-practices/references/payments.md +79 -0
- package/.factory/skills/stripe-best-practices/references/security.md +109 -0
- package/.factory/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.factory/skills/stripe-projects/SKILL.md +139 -0
- package/.factory/skills/upgrade-stripe/SKILL.md +185 -0
- package/.goose/skills/stripe-best-practices/SKILL.md +42 -0
- package/.goose/skills/stripe-best-practices/references/billing.md +36 -0
- package/.goose/skills/stripe-best-practices/references/connect.md +48 -0
- package/.goose/skills/stripe-best-practices/references/payments.md +79 -0
- package/.goose/skills/stripe-best-practices/references/security.md +109 -0
- package/.goose/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.goose/skills/stripe-projects/SKILL.md +139 -0
- package/.goose/skills/upgrade-stripe/SKILL.md +185 -0
- package/.iflow/skills/stripe-best-practices/SKILL.md +42 -0
- package/.iflow/skills/stripe-best-practices/references/billing.md +36 -0
- package/.iflow/skills/stripe-best-practices/references/connect.md +48 -0
- package/.iflow/skills/stripe-best-practices/references/payments.md +79 -0
- package/.iflow/skills/stripe-best-practices/references/security.md +109 -0
- package/.iflow/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.iflow/skills/stripe-projects/SKILL.md +139 -0
- package/.iflow/skills/upgrade-stripe/SKILL.md +185 -0
- package/.junie/skills/stripe-best-practices/SKILL.md +42 -0
- package/.junie/skills/stripe-best-practices/references/billing.md +36 -0
- package/.junie/skills/stripe-best-practices/references/connect.md +48 -0
- package/.junie/skills/stripe-best-practices/references/payments.md +79 -0
- package/.junie/skills/stripe-best-practices/references/security.md +109 -0
- package/.junie/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.junie/skills/stripe-projects/SKILL.md +139 -0
- package/.junie/skills/upgrade-stripe/SKILL.md +185 -0
- package/.kilocode/skills/stripe-best-practices/SKILL.md +42 -0
- package/.kilocode/skills/stripe-best-practices/references/billing.md +36 -0
- package/.kilocode/skills/stripe-best-practices/references/connect.md +48 -0
- package/.kilocode/skills/stripe-best-practices/references/payments.md +79 -0
- package/.kilocode/skills/stripe-best-practices/references/security.md +109 -0
- package/.kilocode/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.kilocode/skills/stripe-projects/SKILL.md +139 -0
- package/.kilocode/skills/upgrade-stripe/SKILL.md +185 -0
- package/.kiro/skills/stripe-best-practices/SKILL.md +42 -0
- package/.kiro/skills/stripe-best-practices/references/billing.md +36 -0
- package/.kiro/skills/stripe-best-practices/references/connect.md +48 -0
- package/.kiro/skills/stripe-best-practices/references/payments.md +79 -0
- package/.kiro/skills/stripe-best-practices/references/security.md +109 -0
- package/.kiro/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.kiro/skills/stripe-projects/SKILL.md +139 -0
- package/.kiro/skills/upgrade-stripe/SKILL.md +185 -0
- package/.kode/skills/stripe-best-practices/SKILL.md +42 -0
- package/.kode/skills/stripe-best-practices/references/billing.md +36 -0
- package/.kode/skills/stripe-best-practices/references/connect.md +48 -0
- package/.kode/skills/stripe-best-practices/references/payments.md +79 -0
- package/.kode/skills/stripe-best-practices/references/security.md +109 -0
- package/.kode/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.kode/skills/stripe-projects/SKILL.md +139 -0
- package/.kode/skills/upgrade-stripe/SKILL.md +185 -0
- package/.mcpjam/skills/stripe-best-practices/SKILL.md +42 -0
- package/.mcpjam/skills/stripe-best-practices/references/billing.md +36 -0
- package/.mcpjam/skills/stripe-best-practices/references/connect.md +48 -0
- package/.mcpjam/skills/stripe-best-practices/references/payments.md +79 -0
- package/.mcpjam/skills/stripe-best-practices/references/security.md +109 -0
- package/.mcpjam/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.mcpjam/skills/stripe-projects/SKILL.md +139 -0
- package/.mcpjam/skills/upgrade-stripe/SKILL.md +185 -0
- package/.mux/skills/stripe-best-practices/SKILL.md +42 -0
- package/.mux/skills/stripe-best-practices/references/billing.md +36 -0
- package/.mux/skills/stripe-best-practices/references/connect.md +48 -0
- package/.mux/skills/stripe-best-practices/references/payments.md +79 -0
- package/.mux/skills/stripe-best-practices/references/security.md +109 -0
- package/.mux/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.mux/skills/stripe-projects/SKILL.md +139 -0
- package/.mux/skills/upgrade-stripe/SKILL.md +185 -0
- package/.neovate/skills/stripe-best-practices/SKILL.md +42 -0
- package/.neovate/skills/stripe-best-practices/references/billing.md +36 -0
- package/.neovate/skills/stripe-best-practices/references/connect.md +48 -0
- package/.neovate/skills/stripe-best-practices/references/payments.md +79 -0
- package/.neovate/skills/stripe-best-practices/references/security.md +109 -0
- package/.neovate/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.neovate/skills/stripe-projects/SKILL.md +139 -0
- package/.neovate/skills/upgrade-stripe/SKILL.md +185 -0
- package/.nixpacksignore +14 -0
- package/.openhands/skills/stripe-best-practices/SKILL.md +42 -0
- package/.openhands/skills/stripe-best-practices/references/billing.md +36 -0
- package/.openhands/skills/stripe-best-practices/references/connect.md +48 -0
- package/.openhands/skills/stripe-best-practices/references/payments.md +79 -0
- package/.openhands/skills/stripe-best-practices/references/security.md +109 -0
- package/.openhands/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.openhands/skills/stripe-projects/SKILL.md +139 -0
- package/.openhands/skills/upgrade-stripe/SKILL.md +185 -0
- package/.pi/skills/stripe-best-practices/SKILL.md +42 -0
- package/.pi/skills/stripe-best-practices/references/billing.md +36 -0
- package/.pi/skills/stripe-best-practices/references/connect.md +48 -0
- package/.pi/skills/stripe-best-practices/references/payments.md +79 -0
- package/.pi/skills/stripe-best-practices/references/security.md +109 -0
- package/.pi/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.pi/skills/stripe-projects/SKILL.md +139 -0
- package/.pi/skills/upgrade-stripe/SKILL.md +185 -0
- package/.pochi/skills/stripe-best-practices/SKILL.md +42 -0
- package/.pochi/skills/stripe-best-practices/references/billing.md +36 -0
- package/.pochi/skills/stripe-best-practices/references/connect.md +48 -0
- package/.pochi/skills/stripe-best-practices/references/payments.md +79 -0
- package/.pochi/skills/stripe-best-practices/references/security.md +109 -0
- package/.pochi/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.pochi/skills/stripe-projects/SKILL.md +139 -0
- package/.pochi/skills/upgrade-stripe/SKILL.md +185 -0
- package/.qoder/skills/stripe-best-practices/SKILL.md +42 -0
- package/.qoder/skills/stripe-best-practices/references/billing.md +36 -0
- package/.qoder/skills/stripe-best-practices/references/connect.md +48 -0
- package/.qoder/skills/stripe-best-practices/references/payments.md +79 -0
- package/.qoder/skills/stripe-best-practices/references/security.md +109 -0
- package/.qoder/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.qoder/skills/stripe-projects/SKILL.md +139 -0
- package/.qoder/skills/upgrade-stripe/SKILL.md +185 -0
- package/.qwen/skills/stripe-best-practices/SKILL.md +42 -0
- package/.qwen/skills/stripe-best-practices/references/billing.md +36 -0
- package/.qwen/skills/stripe-best-practices/references/connect.md +48 -0
- package/.qwen/skills/stripe-best-practices/references/payments.md +79 -0
- package/.qwen/skills/stripe-best-practices/references/security.md +109 -0
- package/.qwen/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.qwen/skills/stripe-projects/SKILL.md +139 -0
- package/.qwen/skills/upgrade-stripe/SKILL.md +185 -0
- package/.roo/skills/stripe-best-practices/SKILL.md +42 -0
- package/.roo/skills/stripe-best-practices/references/billing.md +36 -0
- package/.roo/skills/stripe-best-practices/references/connect.md +48 -0
- package/.roo/skills/stripe-best-practices/references/payments.md +79 -0
- package/.roo/skills/stripe-best-practices/references/security.md +109 -0
- package/.roo/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.roo/skills/stripe-projects/SKILL.md +139 -0
- package/.roo/skills/upgrade-stripe/SKILL.md +185 -0
- package/.trae/skills/stripe-best-practices/SKILL.md +42 -0
- package/.trae/skills/stripe-best-practices/references/billing.md +36 -0
- package/.trae/skills/stripe-best-practices/references/connect.md +48 -0
- package/.trae/skills/stripe-best-practices/references/payments.md +79 -0
- package/.trae/skills/stripe-best-practices/references/security.md +109 -0
- package/.trae/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.trae/skills/stripe-projects/SKILL.md +139 -0
- package/.trae/skills/upgrade-stripe/SKILL.md +185 -0
- package/.vibe/skills/stripe-best-practices/SKILL.md +42 -0
- package/.vibe/skills/stripe-best-practices/references/billing.md +36 -0
- package/.vibe/skills/stripe-best-practices/references/connect.md +48 -0
- package/.vibe/skills/stripe-best-practices/references/payments.md +79 -0
- package/.vibe/skills/stripe-best-practices/references/security.md +109 -0
- package/.vibe/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.vibe/skills/stripe-projects/SKILL.md +139 -0
- package/.vibe/skills/upgrade-stripe/SKILL.md +185 -0
- package/.windsurf/skills/stripe-best-practices/SKILL.md +42 -0
- package/.windsurf/skills/stripe-best-practices/references/billing.md +36 -0
- package/.windsurf/skills/stripe-best-practices/references/connect.md +48 -0
- package/.windsurf/skills/stripe-best-practices/references/payments.md +79 -0
- package/.windsurf/skills/stripe-best-practices/references/security.md +109 -0
- package/.windsurf/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.windsurf/skills/stripe-projects/SKILL.md +139 -0
- package/.windsurf/skills/upgrade-stripe/SKILL.md +185 -0
- package/.zencoder/skills/stripe-best-practices/SKILL.md +42 -0
- package/.zencoder/skills/stripe-best-practices/references/billing.md +36 -0
- package/.zencoder/skills/stripe-best-practices/references/connect.md +48 -0
- package/.zencoder/skills/stripe-best-practices/references/payments.md +79 -0
- package/.zencoder/skills/stripe-best-practices/references/security.md +109 -0
- package/.zencoder/skills/stripe-best-practices/references/treasury.md +16 -0
- package/.zencoder/skills/stripe-projects/SKILL.md +139 -0
- package/.zencoder/skills/upgrade-stripe/SKILL.md +185 -0
- package/AUDIT.md +95 -0
- package/BLOCKERS.md +0 -0
- package/COOLIFY.md +51 -0
- package/MCP_SETUP.md +23 -0
- package/PRODUCTION_CHECKLIST.md +246 -0
- package/README.md +47 -0
- package/ROADMAP.md +91 -0
- package/docs/superpowers/plans/2026-05-11-availsync-frontend-sales-flow.md +2445 -0
- package/frontend/.env.example +2 -0
- package/frontend/app/admin/layout.tsx +13 -0
- package/frontend/app/admin/page.tsx +747 -0
- package/frontend/app/app/activity/page.tsx +257 -0
- package/frontend/app/app/agents/[agentId]/page.tsx +21 -0
- package/frontend/app/app/agents/page.tsx +1155 -0
- package/frontend/app/app/audit/page.tsx +225 -0
- package/frontend/app/app/availability/page.tsx +840 -0
- package/frontend/app/app/holds/page.tsx +262 -0
- package/frontend/app/app/layout.tsx +19 -0
- package/frontend/app/app/onboarding/page.tsx +10 -0
- package/frontend/app/app/onboarding/verify/page.tsx +309 -0
- package/frontend/app/app/page.tsx +508 -0
- package/frontend/app/app/settings/page.tsx +399 -0
- package/frontend/app/app/work/page.tsx +426 -0
- package/frontend/app/changelog/page.tsx +93 -0
- package/frontend/app/checkout/page.tsx +25 -0
- package/frontend/app/docs/api/page.tsx +157 -0
- package/frontend/app/docs/page.tsx +296 -0
- package/frontend/app/docs/pilot/page.tsx +127 -0
- package/frontend/app/docs/quickstart/page.tsx +318 -0
- package/frontend/app/docs/reliability/page.tsx +78 -0
- package/frontend/app/docs/sdk/node/page.tsx +166 -0
- package/frontend/app/globals.css +57 -0
- package/frontend/app/icon.png +0 -0
- package/frontend/app/layout.tsx +87 -0
- package/frontend/app/login/page.tsx +14 -0
- package/frontend/app/page.tsx +47 -0
- package/frontend/app/pricing/page.tsx +66 -0
- package/frontend/app/privacy/page.tsx +52 -0
- package/frontend/app/robots.ts +26 -0
- package/frontend/app/security/page.tsx +74 -0
- package/frontend/app/signup/page.tsx +14 -0
- package/frontend/app/sitemap.ts +14 -0
- package/frontend/app/terms/page.tsx +51 -0
- package/frontend/components/brand/AvailsyncLogo.tsx +56 -0
- package/frontend/components/checkout/CheckoutClient.tsx +100 -0
- package/frontend/components/dashboard/AgentForm.tsx +59 -0
- package/frontend/components/dashboard/AppShell.tsx +291 -0
- package/frontend/components/dashboard/AvailabilityChecker.tsx +117 -0
- package/frontend/components/dashboard/AvailabilityWindowForm.tsx +40 -0
- package/frontend/components/dashboard/HoldForm.tsx +133 -0
- package/frontend/components/dashboard/MetricCard.tsx +10 -0
- package/frontend/components/login/LoginForm.tsx +95 -0
- package/frontend/components/marketing/AgentCoordinationStory.tsx +1530 -0
- package/frontend/components/marketing/Faq.tsx +41 -0
- package/frontend/components/marketing/Hero.tsx +73 -0
- package/frontend/components/marketing/HowItWorks.tsx +28 -0
- package/frontend/components/marketing/ObserveModeTeaser.tsx +41 -0
- package/frontend/components/marketing/PricingTeaser.tsx +23 -0
- package/frontend/components/marketing/ProblemSolution.tsx +36 -0
- package/frontend/components/marketing/SiteFooter.tsx +59 -0
- package/frontend/components/marketing/SiteHeader.tsx +45 -0
- package/frontend/components/marketing/UseCases.tsx +27 -0
- package/frontend/components/onboarding/OnboardingClient.tsx +278 -0
- package/frontend/components/pricing/PricingCards.tsx +65 -0
- package/frontend/components/privacy/CookieConsent.tsx +230 -0
- package/frontend/components/privacy/CookieSettingsButton.tsx +15 -0
- package/frontend/components/seo/JsonLd.tsx +10 -0
- package/frontend/components/signup/SignupForm.tsx +55 -0
- package/frontend/components/ui/Badge.tsx +23 -0
- package/frontend/components/ui/Button.tsx +37 -0
- package/frontend/components/ui/Card.tsx +11 -0
- package/frontend/components/ui/ConfirmDialog.tsx +77 -0
- package/frontend/components/ui/EmptyState.tsx +24 -0
- package/frontend/components/ui/Input.tsx +14 -0
- package/frontend/components/ui/KeyDisplay.tsx +49 -0
- package/frontend/components/ui/Select.tsx +14 -0
- package/frontend/components/ui/Skeleton.tsx +24 -0
- package/frontend/components/ui/Tabs.tsx +19 -0
- package/frontend/components/ui/Textarea.tsx +14 -0
- package/frontend/components/ui/Toast.tsx +78 -0
- package/frontend/components/waitlist/WaitlistDialog.tsx +128 -0
- package/frontend/lib/api.ts +1282 -0
- package/frontend/lib/billing.ts +6 -0
- package/frontend/lib/cookieConsent.ts +113 -0
- package/frontend/lib/format.ts +16 -0
- package/frontend/lib/plans.ts +62 -0
- package/frontend/lib/schemas.ts +108 -0
- package/frontend/lib/seo.ts +376 -0
- package/frontend/lib/setupGuides.ts +630 -0
- package/frontend/lib/storage.ts +30 -0
- package/frontend/next-env.d.ts +6 -0
- package/frontend/next.config.mjs +13 -0
- package/frontend/package-lock.json +14409 -0
- package/frontend/package.json +41 -0
- package/frontend/playwright.config.ts +20 -0
- package/frontend/postcss.config.mjs +8 -0
- package/frontend/public/.gitkeep +0 -0
- package/frontend/public/brand/availsync-logo-board.png +0 -0
- package/frontend/public/brand/availsync-logo-dark.png +0 -0
- package/frontend/public/brand/availsync-mark-dark.png +0 -0
- package/frontend/public/brand/availsync-wordmark-dark.png +0 -0
- package/frontend/public/marketing/hero-agent-coordination.png +0 -0
- package/frontend/tailwind.config.ts +53 -0
- package/frontend/tests/smoke.spec.ts +89 -0
- package/frontend/tsconfig.json +23 -0
- package/jest.config.js +7 -0
- package/nixpacks.toml +11 -0
- package/package.json +53 -0
- package/packages/mcp/LICENSE +21 -0
- package/packages/mcp/README.md +60 -0
- package/packages/mcp/jest.config.cjs +8 -0
- package/packages/mcp/package.json +54 -0
- package/packages/mcp/src/helpers.ts +38 -0
- package/packages/mcp/src/index.test.ts +60 -0
- package/packages/mcp/src/index.ts +387 -0
- package/packages/mcp/tsconfig.json +20 -0
- package/packages/mcp/tsconfig.test.json +12 -0
- package/packages/node/LICENSE +21 -0
- package/packages/node/README.md +120 -0
- package/packages/node/jest.config.cjs +8 -0
- package/packages/node/package.json +46 -0
- package/packages/node/src/index.test.ts +360 -0
- package/packages/node/src/index.ts +402 -0
- package/packages/node/tsconfig.json +20 -0
- package/packages/node/tsconfig.test.json +12 -0
- package/plan.md +923 -0
- package/skills/stripe-best-practices/SKILL.md +42 -0
- package/skills/stripe-best-practices/references/billing.md +36 -0
- package/skills/stripe-best-practices/references/connect.md +48 -0
- package/skills/stripe-best-practices/references/payments.md +79 -0
- package/skills/stripe-best-practices/references/security.md +109 -0
- package/skills/stripe-best-practices/references/treasury.md +16 -0
- package/skills/stripe-projects/SKILL.md +139 -0
- package/skills/upgrade-stripe/SKILL.md +185 -0
- package/skills-lock.json +20 -0
- package/src/core/availability.ts +178 -0
- package/src/core/conflict.ts +209 -0
- package/src/core/work.ts +490 -0
- package/src/db/client.ts +17 -0
- package/src/db/migrations/001_init.sql +88 -0
- package/src/db/migrations/002_stripe.sql +2 -0
- package/src/db/migrations/003_workspace_auth.sql +19 -0
- package/src/db/migrations/004_agent_mcp_status.sql +2 -0
- package/src/db/migrations/005_hold_event_actor.sql +4 -0
- package/src/db/migrations/006_agent_activity.sql +35 -0
- package/src/db/migrations/007_work_coordination.sql +60 -0
- package/src/db/migrations/008_work_claim_leases.sql +20 -0
- package/src/db/migrations/009_billing_subscription_state.sql +23 -0
- package/src/db/migrations/010_agent_api_key_prefix.sql +10 -0
- package/src/db/migrations/011_org_verified_and_work_event_retention.sql +11 -0
- package/src/db/migrations/012_agent_enforcement_mode.sql +12 -0
- package/src/db/migrations/013_support_tickets.sql +21 -0
- package/src/db/migrations/014_paid_plan_waitlist.sql +23 -0
- package/src/db/migrations/015_agent_last_seen.sql +2 -0
- package/src/db/migrations.ts +164 -0
- package/src/db/run-migrations.ts +13 -0
- package/src/index.ts +183 -0
- package/src/lib/activity.ts +137 -0
- package/src/lib/apiKeys.ts +32 -0
- package/src/lib/appInfo.ts +26 -0
- package/src/lib/billingConfig.ts +3 -0
- package/src/lib/env.ts +75 -0
- package/src/lib/logger.ts +8 -0
- package/src/lib/plans.ts +204 -0
- package/src/mcp/server.js +5 -0
- package/src/mcp/server.ts +350 -0
- package/src/middleware/auth.ts +342 -0
- package/src/middleware/requestId.ts +16 -0
- package/src/routes/account.ts +168 -0
- package/src/routes/activity.ts +126 -0
- package/src/routes/admin.ts +514 -0
- package/src/routes/audit.ts +68 -0
- package/src/routes/auth.ts +203 -0
- package/src/routes/availability.ts +325 -0
- package/src/routes/billing.ts +406 -0
- package/src/routes/conflicts.ts +131 -0
- package/src/routes/holds.ts +437 -0
- package/src/routes/mcp.ts +57 -0
- package/src/routes/metrics.ts +39 -0
- package/src/routes/onboarding.ts +273 -0
- package/src/routes/orgs.ts +981 -0
- package/src/routes/preferences.ts +132 -0
- package/src/routes/session.ts +16 -0
- package/src/routes/support.ts +77 -0
- package/src/routes/value.ts +186 -0
- package/src/routes/waitlist.ts +63 -0
- package/src/routes/work.ts +1578 -0
- package/src/server.ts +36 -0
- package/src/types/index.ts +109 -0
- package/tests/integration/activity.route.test.ts +103 -0
- package/tests/integration/admin.route.test.ts +143 -0
- package/tests/integration/agent-keys.route.test.ts +237 -0
- package/tests/integration/availability.route.test.ts +125 -0
- package/tests/integration/billing.route.test.ts +393 -0
- package/tests/integration/conflicts.route.test.ts +131 -0
- package/tests/integration/flows.test.ts +154 -0
- package/tests/integration/helpers.ts +134 -0
- package/tests/integration/holds.route.test.ts +185 -0
- package/tests/integration/metrics.route.test.ts +100 -0
- package/tests/integration/onboarding.verify.route.test.ts +163 -0
- package/tests/integration/preferences.route.test.ts +53 -0
- package/tests/integration/session.route.test.ts +97 -0
- package/tests/integration/system.route.test.ts +92 -0
- package/tests/integration/value.route.test.ts +235 -0
- package/tests/integration/work.route.test.ts +745 -0
- package/tests/setup.ts +4 -0
- package/tests/smoke.sh +62 -0
- package/tests/unit/auth.test.ts +114 -0
- package/tests/unit/availability.test.ts +149 -0
- package/tests/unit/conflict.test.ts +118 -0
- package/tests/unit/env.test.ts +69 -0
- package/tests/unit/migrations.test.ts +135 -0
- package/tests/unit/request-id.test.ts +37 -0
- package/tmp-mobile-agents.png +0 -0
- package/tmp-next-mobile.err.log +10 -0
- package/tmp-next-mobile.log +5 -0
- package/tsconfig.json +16 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import type { AgentAuthenticatedRequest, AnyAuthenticatedRequest, WorkspaceAuthenticatedRequest } from '../middleware/auth';
|
|
2
|
+
import { isAgentAuth } from '../middleware/auth';
|
|
3
|
+
import pool from '../db/client';
|
|
4
|
+
import { log } from './logger';
|
|
5
|
+
import { getPlanConfig, getOrgPlan } from './plans';
|
|
6
|
+
|
|
7
|
+
export type ActivityStatus = 'success' | 'error';
|
|
8
|
+
|
|
9
|
+
export type ActivityInput = {
|
|
10
|
+
org_id?: string | null;
|
|
11
|
+
agent_id?: string | null;
|
|
12
|
+
activity_type: string;
|
|
13
|
+
endpoint?: string | null;
|
|
14
|
+
method?: string | null;
|
|
15
|
+
status_code?: number | null;
|
|
16
|
+
status?: ActivityStatus;
|
|
17
|
+
actor_type?: string | null;
|
|
18
|
+
actor_id?: string | null;
|
|
19
|
+
actor_label?: string | null;
|
|
20
|
+
client_name?: string | null;
|
|
21
|
+
latency_ms?: number | null;
|
|
22
|
+
error_code?: string | null;
|
|
23
|
+
error_message?: string | null;
|
|
24
|
+
provider?: string | null;
|
|
25
|
+
model?: string | null;
|
|
26
|
+
input_tokens?: number | null;
|
|
27
|
+
output_tokens?: number | null;
|
|
28
|
+
total_tokens?: number | null;
|
|
29
|
+
estimated_cost_usd?: number | null;
|
|
30
|
+
metadata?: Record<string, unknown>;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export function actorFromAuth(req: AnyAuthenticatedRequest) {
|
|
34
|
+
if (isAgentAuth(req)) {
|
|
35
|
+
return {
|
|
36
|
+
actor_type: 'agent',
|
|
37
|
+
actor_id: req.agent.id,
|
|
38
|
+
actor_label: req.agent.name,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
actor_type: 'workspace',
|
|
44
|
+
actor_id: req.user.id,
|
|
45
|
+
actor_label: req.user.email,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function agentActor(req: AgentAuthenticatedRequest) {
|
|
50
|
+
return {
|
|
51
|
+
actor_type: 'agent',
|
|
52
|
+
actor_id: req.agent.id,
|
|
53
|
+
actor_label: req.agent.name,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function workspaceActor(req: WorkspaceAuthenticatedRequest) {
|
|
58
|
+
return {
|
|
59
|
+
actor_type: 'workspace',
|
|
60
|
+
actor_id: req.user.id,
|
|
61
|
+
actor_label: req.user.email,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export async function logActivity(input: ActivityInput): Promise<void> {
|
|
66
|
+
try {
|
|
67
|
+
await pool.query(
|
|
68
|
+
`INSERT INTO agent_activity_events (
|
|
69
|
+
org_id,
|
|
70
|
+
agent_id,
|
|
71
|
+
activity_type,
|
|
72
|
+
endpoint,
|
|
73
|
+
method,
|
|
74
|
+
status_code,
|
|
75
|
+
status,
|
|
76
|
+
actor_type,
|
|
77
|
+
actor_id,
|
|
78
|
+
actor_label,
|
|
79
|
+
client_name,
|
|
80
|
+
latency_ms,
|
|
81
|
+
error_code,
|
|
82
|
+
error_message,
|
|
83
|
+
provider,
|
|
84
|
+
model,
|
|
85
|
+
input_tokens,
|
|
86
|
+
output_tokens,
|
|
87
|
+
total_tokens,
|
|
88
|
+
estimated_cost_usd,
|
|
89
|
+
metadata
|
|
90
|
+
)
|
|
91
|
+
VALUES (
|
|
92
|
+
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10,
|
|
93
|
+
$11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21
|
|
94
|
+
)`,
|
|
95
|
+
[
|
|
96
|
+
input.org_id ?? null,
|
|
97
|
+
input.agent_id ?? null,
|
|
98
|
+
input.activity_type,
|
|
99
|
+
input.endpoint ?? null,
|
|
100
|
+
input.method ?? null,
|
|
101
|
+
input.status_code ?? null,
|
|
102
|
+
input.status ?? 'success',
|
|
103
|
+
input.actor_type ?? null,
|
|
104
|
+
input.actor_id ?? null,
|
|
105
|
+
input.actor_label ?? null,
|
|
106
|
+
input.client_name ?? null,
|
|
107
|
+
input.latency_ms ?? null,
|
|
108
|
+
input.error_code ?? null,
|
|
109
|
+
input.error_message ?? null,
|
|
110
|
+
input.provider ?? null,
|
|
111
|
+
input.model ?? null,
|
|
112
|
+
input.input_tokens ?? null,
|
|
113
|
+
input.output_tokens ?? null,
|
|
114
|
+
input.total_tokens ?? null,
|
|
115
|
+
input.estimated_cost_usd ?? null,
|
|
116
|
+
JSON.stringify(input.metadata ?? {}),
|
|
117
|
+
],
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
if (input.org_id) {
|
|
121
|
+
const plan = await getOrgPlan(input.org_id);
|
|
122
|
+
const retentionDays = getPlanConfig(plan).limits.activity_retention_days;
|
|
123
|
+
await pool.query(
|
|
124
|
+
`DELETE FROM agent_activity_events
|
|
125
|
+
WHERE org_id = $1
|
|
126
|
+
AND created_at < NOW() - ($2::text::interval)`,
|
|
127
|
+
[input.org_id, `${retentionDays} days`],
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
} catch (err) {
|
|
131
|
+
log.warn('[activity] failed to write activity event', { error: (err as Error).message });
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function durationSince(startedAt: number): number {
|
|
136
|
+
return Math.max(0, Date.now() - startedAt);
|
|
137
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { randomBytes } from 'crypto';
|
|
2
|
+
import bcrypt from 'bcrypt';
|
|
3
|
+
|
|
4
|
+
export const AGENT_API_KEY_PREFIX = 'avs_live';
|
|
5
|
+
|
|
6
|
+
const PREFIX_BYTES = 8;
|
|
7
|
+
const SECRET_BYTES = 32;
|
|
8
|
+
const AGENT_API_KEY_PATTERN = /^avs_live_([a-f0-9]{16})_[a-f0-9]{64}$/;
|
|
9
|
+
|
|
10
|
+
function urlSafeToken(bytes: number) {
|
|
11
|
+
return randomBytes(bytes).toString('hex');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function parseAgentApiKey(token: string): { prefix: string } | null {
|
|
15
|
+
const match = AGENT_API_KEY_PATTERN.exec(token);
|
|
16
|
+
if (!match) return null;
|
|
17
|
+
return { prefix: match[1] };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export async function createAgentApiKey() {
|
|
21
|
+
const prefix = urlSafeToken(PREFIX_BYTES);
|
|
22
|
+
const secret = urlSafeToken(SECRET_BYTES);
|
|
23
|
+
const apiKey = `${AGENT_API_KEY_PREFIX}_${prefix}_${secret}`;
|
|
24
|
+
const saltRounds = Number.parseInt(process.env.API_KEY_SALT_ROUNDS || '10', 10);
|
|
25
|
+
const apiKeyHash = await bcrypt.hash(apiKey, saltRounds);
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
apiKey,
|
|
29
|
+
apiKeyHash,
|
|
30
|
+
apiKeyPrefix: prefix,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
|
|
4
|
+
let cachedVersion: string | null = null;
|
|
5
|
+
|
|
6
|
+
export function appVersion() {
|
|
7
|
+
if (cachedVersion) return cachedVersion;
|
|
8
|
+
try {
|
|
9
|
+
const packagePath = path.resolve(process.cwd(), 'package.json');
|
|
10
|
+
const parsed = JSON.parse(fs.readFileSync(packagePath, 'utf8')) as { version?: string };
|
|
11
|
+
cachedVersion = parsed.version || '0.0.0';
|
|
12
|
+
} catch {
|
|
13
|
+
cachedVersion = '0.0.0';
|
|
14
|
+
}
|
|
15
|
+
return cachedVersion;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function gitCommit() {
|
|
19
|
+
return (
|
|
20
|
+
process.env.GIT_COMMIT ||
|
|
21
|
+
process.env.COOLIFY_COMMIT_SHA ||
|
|
22
|
+
process.env.COOLIFY_COMMIT ||
|
|
23
|
+
process.env.VERCEL_GIT_COMMIT_SHA ||
|
|
24
|
+
'unknown'
|
|
25
|
+
);
|
|
26
|
+
}
|
package/src/lib/env.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { billingUpgradesEnabled } from './billingConfig';
|
|
2
|
+
|
|
3
|
+
export type EnvCheck = {
|
|
4
|
+
name: string;
|
|
5
|
+
required: boolean;
|
|
6
|
+
configured: boolean;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const baseRequired = ['DATABASE_URL', 'API_KEY_SALT_ROUNDS', 'SESSION_SECRET'] as const;
|
|
10
|
+
const productionOnlyRequired = [
|
|
11
|
+
'APP_URL',
|
|
12
|
+
'CORS_ORIGINS',
|
|
13
|
+
'ADMIN_EMAILS',
|
|
14
|
+
] as const;
|
|
15
|
+
const billingRequired = [
|
|
16
|
+
'STRIPE_SECRET_KEY',
|
|
17
|
+
'STRIPE_WEBHOOK_SECRET',
|
|
18
|
+
'STRIPE_PRICE_INDIVIDUAL',
|
|
19
|
+
'STRIPE_PRICE_TEAM',
|
|
20
|
+
] as const;
|
|
21
|
+
|
|
22
|
+
export function requiredEnvNames(isProduction = process.env.NODE_ENV === 'production') {
|
|
23
|
+
if (!isProduction) return [...baseRequired];
|
|
24
|
+
return billingUpgradesEnabled()
|
|
25
|
+
? [...baseRequired, ...productionOnlyRequired, ...billingRequired]
|
|
26
|
+
: [...baseRequired, ...productionOnlyRequired];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function envReadiness(isProduction = process.env.NODE_ENV === 'production'): {
|
|
30
|
+
mode: string;
|
|
31
|
+
required: EnvCheck[];
|
|
32
|
+
optional: EnvCheck[];
|
|
33
|
+
missing: string[];
|
|
34
|
+
ok: boolean;
|
|
35
|
+
} {
|
|
36
|
+
const requiredNames = requiredEnvNames(isProduction);
|
|
37
|
+
const optionalNames = [
|
|
38
|
+
'PORT',
|
|
39
|
+
'BILLING_UPGRADES_ENABLED',
|
|
40
|
+
'NEXT_PUBLIC_BILLING_UPGRADES_ENABLED',
|
|
41
|
+
...billingRequired,
|
|
42
|
+
...(isProduction ? [] : productionOnlyRequired),
|
|
43
|
+
] as string[];
|
|
44
|
+
const required = requiredNames.map((name) => ({
|
|
45
|
+
name,
|
|
46
|
+
required: true,
|
|
47
|
+
configured: Boolean(process.env[name]),
|
|
48
|
+
}));
|
|
49
|
+
const optional = optionalNames
|
|
50
|
+
.filter((name, index, list) => list.indexOf(name) === index && !requiredNames.includes(name as never))
|
|
51
|
+
.map((name) => ({
|
|
52
|
+
name,
|
|
53
|
+
required: false,
|
|
54
|
+
configured: Boolean(process.env[name]),
|
|
55
|
+
}));
|
|
56
|
+
const missing = required.filter((item) => !item.configured).map((item) => item.name);
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
mode: isProduction ? 'production' : process.env.NODE_ENV || 'development',
|
|
60
|
+
required,
|
|
61
|
+
optional,
|
|
62
|
+
missing,
|
|
63
|
+
ok: missing.length === 0,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function stripeReadiness() {
|
|
68
|
+
return {
|
|
69
|
+
billing_upgrades_enabled: billingUpgradesEnabled(),
|
|
70
|
+
configured: Boolean(process.env.STRIPE_SECRET_KEY),
|
|
71
|
+
webhook_configured: Boolean(process.env.STRIPE_WEBHOOK_SECRET),
|
|
72
|
+
individual_price_configured: Boolean(process.env.STRIPE_PRICE_INDIVIDUAL),
|
|
73
|
+
team_price_configured: Boolean(process.env.STRIPE_PRICE_TEAM),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const log = {
|
|
2
|
+
info: (msg: string, meta?: object) =>
|
|
3
|
+
console.log(JSON.stringify({ level: 'info', msg, ...meta, ts: new Date().toISOString() })),
|
|
4
|
+
error: (msg: string, meta?: object) =>
|
|
5
|
+
console.error(JSON.stringify({ level: 'error', msg, ...meta, ts: new Date().toISOString() })),
|
|
6
|
+
warn: (msg: string, meta?: object) =>
|
|
7
|
+
console.warn(JSON.stringify({ level: 'warn', msg, ...meta, ts: new Date().toISOString() })),
|
|
8
|
+
};
|
package/src/lib/plans.ts
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import type { Response } from 'express';
|
|
2
|
+
import type { Pool, PoolClient } from 'pg';
|
|
3
|
+
import pool from '../db/client';
|
|
4
|
+
import { log } from './logger';
|
|
5
|
+
import { billingUpgradesEnabled } from './billingConfig';
|
|
6
|
+
import { requestIdFrom } from '../middleware/requestId';
|
|
7
|
+
|
|
8
|
+
export type PlanId = 'free' | 'individual' | 'team';
|
|
9
|
+
export type LimitType = 'agents' | 'protected_resources' | 'active_work_claims' | 'api_calls_month';
|
|
10
|
+
|
|
11
|
+
export type PlanLimits = {
|
|
12
|
+
agents: number | null;
|
|
13
|
+
protected_resources: number;
|
|
14
|
+
active_work_claims: number;
|
|
15
|
+
api_calls_month: number;
|
|
16
|
+
activity_retention_days: number;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const PLAN_CONFIG: Record<PlanId, {
|
|
20
|
+
id: PlanId;
|
|
21
|
+
name: string;
|
|
22
|
+
monthly_price_usd: number;
|
|
23
|
+
stripe_price_env?: string;
|
|
24
|
+
db_agent_limit: number;
|
|
25
|
+
limits: PlanLimits;
|
|
26
|
+
}> = {
|
|
27
|
+
free: {
|
|
28
|
+
id: 'free',
|
|
29
|
+
name: 'Free',
|
|
30
|
+
monthly_price_usd: 0,
|
|
31
|
+
db_agent_limit: 3,
|
|
32
|
+
limits: {
|
|
33
|
+
agents: 3,
|
|
34
|
+
protected_resources: 2,
|
|
35
|
+
active_work_claims: 1,
|
|
36
|
+
api_calls_month: 1000,
|
|
37
|
+
activity_retention_days: 7,
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
individual: {
|
|
41
|
+
id: 'individual',
|
|
42
|
+
name: 'Individual',
|
|
43
|
+
monthly_price_usd: 10,
|
|
44
|
+
stripe_price_env: 'STRIPE_PRICE_INDIVIDUAL',
|
|
45
|
+
db_agent_limit: 15,
|
|
46
|
+
limits: {
|
|
47
|
+
agents: 15,
|
|
48
|
+
protected_resources: 10,
|
|
49
|
+
active_work_claims: 5,
|
|
50
|
+
api_calls_month: 25000,
|
|
51
|
+
activity_retention_days: 30,
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
team: {
|
|
55
|
+
id: 'team',
|
|
56
|
+
name: 'Team',
|
|
57
|
+
monthly_price_usd: 25,
|
|
58
|
+
stripe_price_env: 'STRIPE_PRICE_TEAM',
|
|
59
|
+
db_agent_limit: 9999,
|
|
60
|
+
limits: {
|
|
61
|
+
agents: null,
|
|
62
|
+
protected_resources: 100,
|
|
63
|
+
active_work_claims: 25,
|
|
64
|
+
api_calls_month: 250000,
|
|
65
|
+
activity_retention_days: 90,
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export function parsePlan(plan: string | null | undefined): PlanId {
|
|
71
|
+
return plan === 'individual' || plan === 'team' ? plan : 'free';
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function getPlanConfig(plan: string | null | undefined) {
|
|
75
|
+
return PLAN_CONFIG[parsePlan(plan)];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function paidPlanIds(): Array<Exclude<PlanId, 'free'>> {
|
|
79
|
+
return ['individual', 'team'];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function upgradePlanFor(limitType: LimitType, currentPlan: PlanId): Exclude<PlanId, 'free'> | null {
|
|
83
|
+
if (currentPlan === 'free') return 'individual';
|
|
84
|
+
if (currentPlan === 'individual') return 'team';
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function serializableLimits(plan: string | null | undefined) {
|
|
89
|
+
return getPlanConfig(plan).limits;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export async function applyPlanToOrg(db: Pool | PoolClient, orgId: string, plan: PlanId) {
|
|
93
|
+
const config = PLAN_CONFIG[plan];
|
|
94
|
+
await db.query(
|
|
95
|
+
`UPDATE orgs
|
|
96
|
+
SET plan = $1,
|
|
97
|
+
agent_limit = $2
|
|
98
|
+
WHERE id = $3`,
|
|
99
|
+
[plan, config.db_agent_limit, orgId],
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export async function getOrgPlan(orgId: string, db: Pool | PoolClient = pool): Promise<PlanId> {
|
|
104
|
+
const result = await db.query('SELECT plan FROM orgs WHERE id = $1', [orgId]);
|
|
105
|
+
return parsePlan(result.rows[0]?.plan);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export async function getPlanUsage(orgId: string, db: Pool | PoolClient = pool) {
|
|
109
|
+
const result = await db.query(
|
|
110
|
+
`SELECT
|
|
111
|
+
(SELECT COUNT(*)::int FROM agents WHERE org_id = $1) AS agents,
|
|
112
|
+
(SELECT COUNT(*)::int FROM work_resources WHERE org_id = $1) AS protected_resources,
|
|
113
|
+
(SELECT COUNT(*)::int FROM work_claims WHERE org_id = $1 AND status = 'active' AND expires_at >= NOW()) AS active_work_claims,
|
|
114
|
+
(SELECT COUNT(*)::int FROM agent_activity_events WHERE org_id = $1 AND created_at >= date_trunc('month', NOW())) AS api_calls_month`,
|
|
115
|
+
[orgId],
|
|
116
|
+
);
|
|
117
|
+
return result.rows[0] as {
|
|
118
|
+
agents: number;
|
|
119
|
+
protected_resources: number;
|
|
120
|
+
active_work_claims: number;
|
|
121
|
+
api_calls_month: number;
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function planLimitPayload(input: {
|
|
126
|
+
plan: PlanId;
|
|
127
|
+
limit_type: LimitType;
|
|
128
|
+
limit: number | null;
|
|
129
|
+
usage: number;
|
|
130
|
+
}) {
|
|
131
|
+
const upgradePlan = upgradePlanFor(input.limit_type, input.plan);
|
|
132
|
+
const readable = input.limit_type.replaceAll('_', ' ');
|
|
133
|
+
const upgradesEnabled = billingUpgradesEnabled();
|
|
134
|
+
return {
|
|
135
|
+
error: 'plan_limit_reached',
|
|
136
|
+
limit_type: input.limit_type,
|
|
137
|
+
plan: input.plan,
|
|
138
|
+
limit: input.limit,
|
|
139
|
+
usage: input.usage,
|
|
140
|
+
upgrade_plan: upgradePlan,
|
|
141
|
+
message: upgradePlan
|
|
142
|
+
? upgradesEnabled
|
|
143
|
+
? `Your ${input.plan} plan has reached the ${readable} limit. Upgrade to ${upgradePlan} to continue.`
|
|
144
|
+
: `Your ${input.plan} plan has reached the ${readable} limit. Paid plans are currently waitlist-only.`
|
|
145
|
+
: `Your ${input.plan} plan has reached the ${readable} limit.`,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export async function enforcePlanLimit(input: {
|
|
150
|
+
org_id: string;
|
|
151
|
+
limit_type: LimitType;
|
|
152
|
+
increment?: number;
|
|
153
|
+
usage_override?: number;
|
|
154
|
+
db?: Pool | PoolClient;
|
|
155
|
+
res: Response;
|
|
156
|
+
}): Promise<boolean> {
|
|
157
|
+
const db = input.db ?? pool;
|
|
158
|
+
const plan = await getOrgPlan(input.org_id, db);
|
|
159
|
+
const config = PLAN_CONFIG[plan];
|
|
160
|
+
const limit = config.limits[input.limit_type];
|
|
161
|
+
if (limit === null) return true;
|
|
162
|
+
|
|
163
|
+
const usage =
|
|
164
|
+
input.usage_override ??
|
|
165
|
+
(await getPlanUsage(input.org_id, db))[input.limit_type === 'api_calls_month' ? 'api_calls_month' : input.limit_type];
|
|
166
|
+
const nextUsage = usage + (input.increment ?? 1);
|
|
167
|
+
if (nextUsage <= limit) return true;
|
|
168
|
+
|
|
169
|
+
const payload = planLimitPayload({
|
|
170
|
+
plan,
|
|
171
|
+
limit_type: input.limit_type,
|
|
172
|
+
limit,
|
|
173
|
+
usage,
|
|
174
|
+
});
|
|
175
|
+
log.warn('[plan] limit reached', {
|
|
176
|
+
request_id: requestIdFrom(input.res),
|
|
177
|
+
org_id: input.org_id,
|
|
178
|
+
limit_type: input.limit_type,
|
|
179
|
+
plan,
|
|
180
|
+
limit,
|
|
181
|
+
usage,
|
|
182
|
+
});
|
|
183
|
+
input.res.status(402).json({ ...payload, request_id: requestIdFrom(input.res) });
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export function upgradeReasons(plan: PlanId, usage: Awaited<ReturnType<typeof getPlanUsage>>) {
|
|
188
|
+
const limits = PLAN_CONFIG[plan].limits;
|
|
189
|
+
return (Object.keys(limits) as Array<keyof PlanLimits>)
|
|
190
|
+
.filter((key) => key !== 'activity_retention_days')
|
|
191
|
+
.flatMap((key) => {
|
|
192
|
+
const limit = limits[key];
|
|
193
|
+
const used = usage[key as keyof typeof usage];
|
|
194
|
+
if (typeof used !== 'number' || limit === null) return [];
|
|
195
|
+
if (used < Math.ceil(limit * 0.8)) return [];
|
|
196
|
+
return [{
|
|
197
|
+
limit_type: key,
|
|
198
|
+
usage: used,
|
|
199
|
+
limit,
|
|
200
|
+
state: used >= limit ? 'reached' : 'near',
|
|
201
|
+
upgrade_plan: upgradePlanFor(key as LimitType, plan),
|
|
202
|
+
}];
|
|
203
|
+
});
|
|
204
|
+
}
|