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,203 @@
|
|
|
1
|
+
import { randomBytes } from 'crypto';
|
|
2
|
+
import bcrypt from 'bcrypt';
|
|
3
|
+
import express from 'express';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import pool from '../db/client';
|
|
6
|
+
import { log } from '../lib/logger';
|
|
7
|
+
import { createAgentApiKey } from '../lib/apiKeys';
|
|
8
|
+
import { PLAN_CONFIG } from '../lib/plans';
|
|
9
|
+
import {
|
|
10
|
+
WORKSPACE_SESSION_DAYS,
|
|
11
|
+
WORKSPACE_SESSION_COOKIE,
|
|
12
|
+
clearWorkspaceSessionCookie,
|
|
13
|
+
getCookie,
|
|
14
|
+
hashSessionToken,
|
|
15
|
+
requireAgentKey,
|
|
16
|
+
setWorkspaceSessionCookie,
|
|
17
|
+
type AgentAuthenticatedRequest,
|
|
18
|
+
} from '../middleware/auth';
|
|
19
|
+
|
|
20
|
+
const router = express.Router();
|
|
21
|
+
|
|
22
|
+
const AgentSchema = z.object({
|
|
23
|
+
name: z.string().min(1),
|
|
24
|
+
agent_type: z
|
|
25
|
+
.enum(['external_meeting', 'internal', 'focus', 'generic'])
|
|
26
|
+
.optional()
|
|
27
|
+
.default('generic'),
|
|
28
|
+
priority: z.number().int().optional().default(0),
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const SignupSchema = z.object({
|
|
32
|
+
workspace_name: z.string().min(1),
|
|
33
|
+
email: z.string().email(),
|
|
34
|
+
password: z.string().min(8),
|
|
35
|
+
agent: AgentSchema,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const LoginSchema = z.object({
|
|
39
|
+
email: z.string().email(),
|
|
40
|
+
password: z.string().min(1),
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const ClaimSchema = z.object({
|
|
44
|
+
email: z.string().email(),
|
|
45
|
+
password: z.string().min(8),
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
async function createAgent(
|
|
49
|
+
client: Pick<typeof pool, 'query'>,
|
|
50
|
+
orgId: string,
|
|
51
|
+
input: z.infer<typeof AgentSchema>,
|
|
52
|
+
) {
|
|
53
|
+
const { apiKey, apiKeyHash, apiKeyPrefix } = await createAgentApiKey();
|
|
54
|
+
|
|
55
|
+
const created = await client.query(
|
|
56
|
+
`INSERT INTO agents (org_id, name, api_key_hash, api_key_prefix, agent_type, priority)
|
|
57
|
+
VALUES ($1, $2, $3, $4, $5, $6)
|
|
58
|
+
RETURNING *`,
|
|
59
|
+
[orgId, input.name, apiKeyHash, apiKeyPrefix, input.agent_type, input.priority],
|
|
60
|
+
);
|
|
61
|
+
await client.query('INSERT INTO agent_preferences (agent_id) VALUES ($1)', [
|
|
62
|
+
created.rows[0].id,
|
|
63
|
+
]);
|
|
64
|
+
|
|
65
|
+
const { api_key_hash: _apiKeyHash, api_key_prefix: _apiKeyPrefix, ...agent } = created.rows[0];
|
|
66
|
+
return { agent, apiKey };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async function createWorkspaceSession(userId: string) {
|
|
70
|
+
const token = randomBytes(32).toString('hex');
|
|
71
|
+
const expiresAt = new Date(Date.now() + WORKSPACE_SESSION_DAYS * 24 * 60 * 60 * 1000);
|
|
72
|
+
|
|
73
|
+
await pool.query(
|
|
74
|
+
`INSERT INTO workspace_sessions (user_id, token_hash, expires_at)
|
|
75
|
+
VALUES ($1, $2, $3)`,
|
|
76
|
+
[userId, hashSessionToken(token), expiresAt],
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
return token;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
router.post('/auth/signup', async (req, res) => {
|
|
83
|
+
const parsed = SignupSchema.safeParse(req.body);
|
|
84
|
+
if (!parsed.success) {
|
|
85
|
+
return res.status(422).json({ error: 'validation_error', details: parsed.error.flatten() });
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const client = await pool.connect();
|
|
89
|
+
try {
|
|
90
|
+
const saltRounds = Number.parseInt(process.env.API_KEY_SALT_ROUNDS || '10', 10);
|
|
91
|
+
const passwordHash = await bcrypt.hash(parsed.data.password, saltRounds);
|
|
92
|
+
|
|
93
|
+
await client.query('BEGIN');
|
|
94
|
+
const org = await client.query(
|
|
95
|
+
"INSERT INTO orgs (name, plan, agent_limit, subscription_status) VALUES ($1, 'free', $2, 'free') RETURNING *",
|
|
96
|
+
[parsed.data.workspace_name, PLAN_CONFIG.free.db_agent_limit],
|
|
97
|
+
);
|
|
98
|
+
const user = await client.query(
|
|
99
|
+
`INSERT INTO workspace_users (org_id, email, password_hash, role)
|
|
100
|
+
VALUES ($1, $2, $3, 'owner')
|
|
101
|
+
RETURNING id, org_id, email, role, created_at`,
|
|
102
|
+
[org.rows[0].id, parsed.data.email.toLowerCase(), passwordHash],
|
|
103
|
+
);
|
|
104
|
+
const createdAgent = await createAgent(client, org.rows[0].id, parsed.data.agent);
|
|
105
|
+
await client.query('COMMIT');
|
|
106
|
+
|
|
107
|
+
const token = await createWorkspaceSession(user.rows[0].id);
|
|
108
|
+
setWorkspaceSessionCookie(res, token);
|
|
109
|
+
|
|
110
|
+
return res.status(201).json({
|
|
111
|
+
org: org.rows[0],
|
|
112
|
+
user: user.rows[0],
|
|
113
|
+
agent: createdAgent.agent,
|
|
114
|
+
api_key: createdAgent.apiKey,
|
|
115
|
+
});
|
|
116
|
+
} catch (err) {
|
|
117
|
+
await client.query('ROLLBACK').catch(() => {});
|
|
118
|
+
if ((err as { code?: string }).code === '23505') {
|
|
119
|
+
return res.status(409).json({ error: 'email_taken', message: 'Email already has a workspace' });
|
|
120
|
+
}
|
|
121
|
+
log.error('[auth] signup error', { error: (err as Error).message });
|
|
122
|
+
return res.status(500).json({ error: 'internal_error', message: 'An unexpected error occurred' });
|
|
123
|
+
} finally {
|
|
124
|
+
client.release();
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
router.post('/auth/login', async (req, res) => {
|
|
129
|
+
const parsed = LoginSchema.safeParse(req.body);
|
|
130
|
+
if (!parsed.success) {
|
|
131
|
+
return res.status(422).json({ error: 'validation_error', details: parsed.error.flatten() });
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
try {
|
|
135
|
+
const result = await pool.query(
|
|
136
|
+
`SELECT id, password_hash
|
|
137
|
+
FROM workspace_users
|
|
138
|
+
WHERE email = $1`,
|
|
139
|
+
[parsed.data.email.toLowerCase()],
|
|
140
|
+
);
|
|
141
|
+
const user = result.rows[0];
|
|
142
|
+
|
|
143
|
+
if (!user || !(await bcrypt.compare(parsed.data.password, user.password_hash))) {
|
|
144
|
+
return res.status(401).json({ error: 'invalid_credentials' });
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const token = await createWorkspaceSession(user.id);
|
|
148
|
+
setWorkspaceSessionCookie(res, token);
|
|
149
|
+
return res.json({ ok: true });
|
|
150
|
+
} catch (err) {
|
|
151
|
+
log.error('[auth] login error', { error: (err as Error).message });
|
|
152
|
+
return res.status(500).json({ error: 'internal_error', message: 'An unexpected error occurred' });
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
router.post('/auth/logout', async (req, res) => {
|
|
157
|
+
const token = getCookie(req, WORKSPACE_SESSION_COOKIE);
|
|
158
|
+
if (token) {
|
|
159
|
+
await pool
|
|
160
|
+
.query('DELETE FROM workspace_sessions WHERE token_hash = $1', [hashSessionToken(token)])
|
|
161
|
+
.catch((err) => log.warn('[auth] logout cleanup failed', { error: (err as Error).message }));
|
|
162
|
+
}
|
|
163
|
+
clearWorkspaceSessionCookie(res);
|
|
164
|
+
return res.json({ ok: true });
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
router.post('/auth/claim', requireAgentKey, async (req, res) => {
|
|
168
|
+
const parsed = ClaimSchema.safeParse(req.body);
|
|
169
|
+
if (!parsed.success) {
|
|
170
|
+
return res.status(422).json({ error: 'validation_error', details: parsed.error.flatten() });
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const authReq = req as AgentAuthenticatedRequest;
|
|
174
|
+
try {
|
|
175
|
+
const existing = await pool.query('SELECT 1 FROM workspace_users WHERE org_id = $1', [
|
|
176
|
+
authReq.org.id,
|
|
177
|
+
]);
|
|
178
|
+
if (existing.rows.length > 0) {
|
|
179
|
+
return res.status(409).json({ error: 'workspace_already_claimed' });
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const saltRounds = Number.parseInt(process.env.API_KEY_SALT_ROUNDS || '10', 10);
|
|
183
|
+
const passwordHash = await bcrypt.hash(parsed.data.password, saltRounds);
|
|
184
|
+
const user = await pool.query(
|
|
185
|
+
`INSERT INTO workspace_users (org_id, email, password_hash, role)
|
|
186
|
+
VALUES ($1, $2, $3, 'owner')
|
|
187
|
+
RETURNING id, org_id, email, role, created_at`,
|
|
188
|
+
[authReq.org.id, parsed.data.email.toLowerCase(), passwordHash],
|
|
189
|
+
);
|
|
190
|
+
const token = await createWorkspaceSession(user.rows[0].id);
|
|
191
|
+
setWorkspaceSessionCookie(res, token);
|
|
192
|
+
|
|
193
|
+
return res.status(201).json({ org: authReq.org, user: user.rows[0] });
|
|
194
|
+
} catch (err) {
|
|
195
|
+
if ((err as { code?: string }).code === '23505') {
|
|
196
|
+
return res.status(409).json({ error: 'email_taken', message: 'Email already has a workspace' });
|
|
197
|
+
}
|
|
198
|
+
log.error('[auth] claim error', { error: (err as Error).message });
|
|
199
|
+
return res.status(500).json({ error: 'internal_error', message: 'An unexpected error occurred' });
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
export default router;
|
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
import express from 'express';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import pool from '../db/client';
|
|
4
|
+
import { log } from '../lib/logger';
|
|
5
|
+
import { getAvailableSlots } from '../core/availability';
|
|
6
|
+
import { actorFromAuth, durationSince, logActivity } from '../lib/activity';
|
|
7
|
+
import { enforcePlanLimit } from '../lib/plans';
|
|
8
|
+
import {
|
|
9
|
+
canAccessAgent,
|
|
10
|
+
requireWorkspaceOrAgent,
|
|
11
|
+
type AnyAuthenticatedRequest,
|
|
12
|
+
} from '../middleware/auth';
|
|
13
|
+
|
|
14
|
+
const router = express.Router();
|
|
15
|
+
|
|
16
|
+
const AvailabilityQuerySchema = z
|
|
17
|
+
.object({
|
|
18
|
+
agent_id: z.string().uuid(),
|
|
19
|
+
from: z.string().datetime({ offset: true }),
|
|
20
|
+
to: z.string().datetime({ offset: true }),
|
|
21
|
+
duration_minutes: z.coerce.number().int().min(1).max(480),
|
|
22
|
+
include_competing_agents: z
|
|
23
|
+
.preprocess((value) => value === 'true' || value === true, z.boolean())
|
|
24
|
+
.optional()
|
|
25
|
+
.default(true),
|
|
26
|
+
})
|
|
27
|
+
.refine((data) => new Date(data.to) > new Date(data.from), {
|
|
28
|
+
path: ['to'],
|
|
29
|
+
message: 'to must be after from',
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const WindowSchema = z
|
|
33
|
+
.object({
|
|
34
|
+
agent_id: z.string().uuid(),
|
|
35
|
+
start_at: z.string().datetime({ offset: true }),
|
|
36
|
+
end_at: z.string().datetime({ offset: true }),
|
|
37
|
+
window_type: z.enum(['available', 'focus', 'blocked']),
|
|
38
|
+
recurrence: z.enum(['daily', 'weekly']).optional(),
|
|
39
|
+
})
|
|
40
|
+
.refine((data) => new Date(data.end_at) > new Date(data.start_at), {
|
|
41
|
+
path: ['end_at'],
|
|
42
|
+
message: 'end_at must be after start_at',
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const WindowUpdateSchema = z
|
|
46
|
+
.object({
|
|
47
|
+
start_at: z.string().datetime({ offset: true }),
|
|
48
|
+
end_at: z.string().datetime({ offset: true }),
|
|
49
|
+
window_type: z.enum(['available', 'focus', 'blocked']),
|
|
50
|
+
recurrence: z.enum(['daily', 'weekly']).nullable().optional(),
|
|
51
|
+
})
|
|
52
|
+
.refine((data) => new Date(data.end_at) > new Date(data.start_at), {
|
|
53
|
+
path: ['end_at'],
|
|
54
|
+
message: 'end_at must be after start_at',
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
async function agentBelongsToOrg(agentId: string, orgId: string): Promise<boolean> {
|
|
58
|
+
const result = await pool.query('SELECT 1 FROM agents WHERE id = $1 AND org_id = $2', [
|
|
59
|
+
agentId,
|
|
60
|
+
orgId,
|
|
61
|
+
]);
|
|
62
|
+
return result.rows.length > 0;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async function getWindowInOrg(windowId: string, orgId: string) {
|
|
66
|
+
const result = await pool.query(
|
|
67
|
+
`SELECT availability_windows.*
|
|
68
|
+
FROM availability_windows
|
|
69
|
+
JOIN agents ON agents.id = availability_windows.agent_id
|
|
70
|
+
WHERE availability_windows.id = $1
|
|
71
|
+
AND agents.org_id = $2`,
|
|
72
|
+
[windowId, orgId],
|
|
73
|
+
);
|
|
74
|
+
return result.rows[0];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
router.get('/availability', requireWorkspaceOrAgent, async (req, res) => {
|
|
78
|
+
const startedAt = Date.now();
|
|
79
|
+
const parsed = AvailabilityQuerySchema.safeParse(req.query);
|
|
80
|
+
if (!parsed.success) {
|
|
81
|
+
return res.status(400).json({ error: 'validation_error', details: parsed.error.flatten() });
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const authReq = req as AnyAuthenticatedRequest;
|
|
85
|
+
const from = new Date(parsed.data.from);
|
|
86
|
+
const to = new Date(parsed.data.to);
|
|
87
|
+
|
|
88
|
+
if (from < new Date()) {
|
|
89
|
+
return res.status(400).json({ error: 'past_datetime' });
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
try {
|
|
93
|
+
if (!(await agentBelongsToOrg(parsed.data.agent_id, authReq.org.id))) {
|
|
94
|
+
return res.status(403).json({ error: 'forbidden', message: 'Agent is outside your org' });
|
|
95
|
+
}
|
|
96
|
+
if (!canAccessAgent(authReq, parsed.data.agent_id)) {
|
|
97
|
+
return res.status(403).json({ error: 'forbidden', message: 'Agent key cannot act for another agent' });
|
|
98
|
+
}
|
|
99
|
+
if (!(await enforcePlanLimit({
|
|
100
|
+
org_id: authReq.org.id,
|
|
101
|
+
limit_type: 'api_calls_month',
|
|
102
|
+
res,
|
|
103
|
+
}))) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const prefs = await pool.query(
|
|
108
|
+
'SELECT booking_window_days, buffer_minutes_after, focus_blocks FROM agent_preferences WHERE agent_id = $1',
|
|
109
|
+
[parsed.data.agent_id],
|
|
110
|
+
);
|
|
111
|
+
const preference = prefs.rows[0];
|
|
112
|
+
const bookingWindowDays = preference?.booking_window_days ?? 30;
|
|
113
|
+
const maxTo = new Date(Date.now() + bookingWindowDays * 24 * 60 * 60 * 1000);
|
|
114
|
+
|
|
115
|
+
if (to > maxTo) {
|
|
116
|
+
return res.status(400).json({ error: 'outside_booking_window' });
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const slots = await getAvailableSlots({
|
|
120
|
+
agent_id: parsed.data.agent_id,
|
|
121
|
+
org_id: authReq.org.id,
|
|
122
|
+
from,
|
|
123
|
+
to,
|
|
124
|
+
duration_minutes: parsed.data.duration_minutes,
|
|
125
|
+
include_competing_agents: parsed.data.include_competing_agents,
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
await logActivity({
|
|
129
|
+
org_id: authReq.org.id,
|
|
130
|
+
agent_id: parsed.data.agent_id,
|
|
131
|
+
activity_type: 'availability_check',
|
|
132
|
+
endpoint: '/v1/availability',
|
|
133
|
+
method: 'GET',
|
|
134
|
+
status_code: 200,
|
|
135
|
+
status: 'success',
|
|
136
|
+
...actorFromAuth(authReq),
|
|
137
|
+
latency_ms: durationSince(startedAt),
|
|
138
|
+
metadata: {
|
|
139
|
+
from: from.toISOString(),
|
|
140
|
+
to: to.toISOString(),
|
|
141
|
+
duration_minutes: parsed.data.duration_minutes,
|
|
142
|
+
total_slots: slots.length,
|
|
143
|
+
include_competing_agents: parsed.data.include_competing_agents,
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
const rulesApplied = [
|
|
148
|
+
`buffer_${preference?.buffer_minutes_after ?? 15}min`,
|
|
149
|
+
...(Array.isArray(preference?.focus_blocks) && preference.focus_blocks.length > 0
|
|
150
|
+
? ['focus_block_mornings']
|
|
151
|
+
: []),
|
|
152
|
+
];
|
|
153
|
+
|
|
154
|
+
return res.json({
|
|
155
|
+
slots: slots.map((slot) => ({
|
|
156
|
+
start: slot.start.toISOString(),
|
|
157
|
+
end: slot.end.toISOString(),
|
|
158
|
+
confidence: slot.confidence,
|
|
159
|
+
competing_holds_count: slot.competing_holds_count,
|
|
160
|
+
})),
|
|
161
|
+
rules_applied: rulesApplied,
|
|
162
|
+
generated_at: new Date().toISOString(),
|
|
163
|
+
total_slots: slots.length,
|
|
164
|
+
});
|
|
165
|
+
} catch (err) {
|
|
166
|
+
log.error('[availability] unexpected error', { error: (err as Error).message });
|
|
167
|
+
return res.status(500).json({ error: 'internal_error', message: 'An unexpected error occurred' });
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
router.post('/availability-windows', requireWorkspaceOrAgent, async (req, res) => {
|
|
172
|
+
const parsed = WindowSchema.safeParse(req.body);
|
|
173
|
+
if (!parsed.success) {
|
|
174
|
+
return res.status(422).json({ error: 'validation_error', details: parsed.error.flatten() });
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const authReq = req as AnyAuthenticatedRequest;
|
|
178
|
+
|
|
179
|
+
try {
|
|
180
|
+
if (!(await agentBelongsToOrg(parsed.data.agent_id, authReq.org.id))) {
|
|
181
|
+
return res.status(403).json({ error: 'forbidden', message: 'Agent is outside your org' });
|
|
182
|
+
}
|
|
183
|
+
if (!canAccessAgent(authReq, parsed.data.agent_id)) {
|
|
184
|
+
return res.status(403).json({ error: 'forbidden', message: 'Agent key cannot act for another agent' });
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const created = await pool.query(
|
|
188
|
+
`INSERT INTO availability_windows (agent_id, start_at, end_at, window_type, recurrence)
|
|
189
|
+
VALUES ($1, $2, $3, $4, $5)
|
|
190
|
+
RETURNING *`,
|
|
191
|
+
[
|
|
192
|
+
parsed.data.agent_id,
|
|
193
|
+
new Date(parsed.data.start_at),
|
|
194
|
+
new Date(parsed.data.end_at),
|
|
195
|
+
parsed.data.window_type,
|
|
196
|
+
parsed.data.recurrence ?? null,
|
|
197
|
+
],
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
return res.status(201).json({ window: created.rows[0] });
|
|
201
|
+
} catch (err) {
|
|
202
|
+
log.error('[availability] unexpected error', { error: (err as Error).message });
|
|
203
|
+
return res.status(500).json({ error: 'internal_error', message: 'An unexpected error occurred' });
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
router.get('/availability-windows', requireWorkspaceOrAgent, async (req, res) => {
|
|
208
|
+
const query = z
|
|
209
|
+
.object({
|
|
210
|
+
agent_id: z.string().uuid(),
|
|
211
|
+
from: z.string().datetime({ offset: true }).optional(),
|
|
212
|
+
to: z.string().datetime({ offset: true }).optional(),
|
|
213
|
+
})
|
|
214
|
+
.safeParse(req.query);
|
|
215
|
+
|
|
216
|
+
if (!query.success) {
|
|
217
|
+
return res.status(400).json({ error: 'validation_error', details: query.error.flatten() });
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const authReq = req as AnyAuthenticatedRequest;
|
|
221
|
+
|
|
222
|
+
try {
|
|
223
|
+
if (!(await agentBelongsToOrg(query.data.agent_id, authReq.org.id))) {
|
|
224
|
+
return res.status(403).json({ error: 'forbidden', message: 'Agent is outside your org' });
|
|
225
|
+
}
|
|
226
|
+
if (!canAccessAgent(authReq, query.data.agent_id)) {
|
|
227
|
+
return res.status(403).json({ error: 'forbidden', message: 'Agent key cannot act for another agent' });
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const windows = await pool.query(
|
|
231
|
+
`SELECT *
|
|
232
|
+
FROM availability_windows
|
|
233
|
+
WHERE agent_id = $1
|
|
234
|
+
AND ($2::timestamptz IS NULL OR end_at > $2)
|
|
235
|
+
AND ($3::timestamptz IS NULL OR start_at < $3)
|
|
236
|
+
ORDER BY start_at ASC`,
|
|
237
|
+
[
|
|
238
|
+
query.data.agent_id,
|
|
239
|
+
query.data.from ? new Date(query.data.from) : null,
|
|
240
|
+
query.data.to ? new Date(query.data.to) : null,
|
|
241
|
+
],
|
|
242
|
+
);
|
|
243
|
+
return res.json({ windows: windows.rows });
|
|
244
|
+
} catch (err) {
|
|
245
|
+
log.error('[availability] unexpected error', { error: (err as Error).message });
|
|
246
|
+
return res.status(500).json({ error: 'internal_error', message: 'An unexpected error occurred' });
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
router.put('/availability-windows/:window_id', requireWorkspaceOrAgent, async (req, res) => {
|
|
251
|
+
const windowId = z.string().uuid().safeParse(req.params.window_id);
|
|
252
|
+
if (!windowId.success) {
|
|
253
|
+
return res.status(400).json({ error: 'validation_error', details: windowId.error.flatten() });
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
const parsed = WindowUpdateSchema.safeParse(req.body);
|
|
257
|
+
if (!parsed.success) {
|
|
258
|
+
return res.status(422).json({ error: 'validation_error', details: parsed.error.flatten() });
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
const authReq = req as AnyAuthenticatedRequest;
|
|
262
|
+
|
|
263
|
+
try {
|
|
264
|
+
const existing = await getWindowInOrg(windowId.data, authReq.org.id);
|
|
265
|
+
if (!existing) {
|
|
266
|
+
return res.status(404).json({ error: 'window_not_found', message: 'Availability window not found' });
|
|
267
|
+
}
|
|
268
|
+
if (!canAccessAgent(authReq, existing.agent_id)) {
|
|
269
|
+
return res.status(403).json({ error: 'forbidden', message: 'Agent key cannot act for another agent' });
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
const updated = await pool.query(
|
|
273
|
+
`UPDATE availability_windows
|
|
274
|
+
SET start_at = $1,
|
|
275
|
+
end_at = $2,
|
|
276
|
+
window_type = $3,
|
|
277
|
+
recurrence = $4
|
|
278
|
+
WHERE id = $5
|
|
279
|
+
RETURNING *`,
|
|
280
|
+
[
|
|
281
|
+
new Date(parsed.data.start_at),
|
|
282
|
+
new Date(parsed.data.end_at),
|
|
283
|
+
parsed.data.window_type,
|
|
284
|
+
parsed.data.recurrence ?? null,
|
|
285
|
+
windowId.data,
|
|
286
|
+
],
|
|
287
|
+
);
|
|
288
|
+
|
|
289
|
+
return res.json({ window: updated.rows[0] });
|
|
290
|
+
} catch (err) {
|
|
291
|
+
log.error('[availability] unexpected error', { error: (err as Error).message });
|
|
292
|
+
return res.status(500).json({ error: 'internal_error', message: 'An unexpected error occurred' });
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
router.delete('/availability-windows/:window_id', requireWorkspaceOrAgent, async (req, res) => {
|
|
297
|
+
const windowId = z.string().uuid().safeParse(req.params.window_id);
|
|
298
|
+
if (!windowId.success) {
|
|
299
|
+
return res.status(400).json({ error: 'validation_error', details: windowId.error.flatten() });
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
const authReq = req as AnyAuthenticatedRequest;
|
|
303
|
+
|
|
304
|
+
try {
|
|
305
|
+
const existing = await getWindowInOrg(windowId.data, authReq.org.id);
|
|
306
|
+
if (!existing) {
|
|
307
|
+
return res.status(404).json({ error: 'window_not_found', message: 'Availability window not found' });
|
|
308
|
+
}
|
|
309
|
+
if (!canAccessAgent(authReq, existing.agent_id)) {
|
|
310
|
+
return res.status(403).json({ error: 'forbidden', message: 'Agent key cannot act for another agent' });
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
const deleted = await pool.query(
|
|
314
|
+
'DELETE FROM availability_windows WHERE id = $1 RETURNING *',
|
|
315
|
+
[windowId.data],
|
|
316
|
+
);
|
|
317
|
+
|
|
318
|
+
return res.json({ window: deleted.rows[0] });
|
|
319
|
+
} catch (err) {
|
|
320
|
+
log.error('[availability] unexpected error', { error: (err as Error).message });
|
|
321
|
+
return res.status(500).json({ error: 'internal_error', message: 'An unexpected error occurred' });
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
export default router;
|