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
package/skills-lock.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 1,
|
|
3
|
+
"skills": {
|
|
4
|
+
"stripe-best-practices": {
|
|
5
|
+
"source": "docs.stripe.com",
|
|
6
|
+
"sourceType": "well-known",
|
|
7
|
+
"computedHash": "1d32ab705b1801928f68b8f0b839e5f43e8e83405bf14e72978ac4422ca4f052"
|
|
8
|
+
},
|
|
9
|
+
"stripe-projects": {
|
|
10
|
+
"source": "docs.stripe.com",
|
|
11
|
+
"sourceType": "well-known",
|
|
12
|
+
"computedHash": "5f82f044d22f5d23b5ddd8cf0370d173e05d9d82345176e388eb49deeac3af0e"
|
|
13
|
+
},
|
|
14
|
+
"upgrade-stripe": {
|
|
15
|
+
"source": "docs.stripe.com",
|
|
16
|
+
"sourceType": "well-known",
|
|
17
|
+
"computedHash": "df1c52c17aff54490e81e98979f302564988fbddaaf59e74c2d1bd4b103a7d2e"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { addMinutes, isBefore, max, min } from 'date-fns';
|
|
2
|
+
import type { PoolClient } from 'pg';
|
|
3
|
+
import pool from '../db/client';
|
|
4
|
+
import type { AgentPreferences, AvailabilityWindow, AvailableSlot, Hold } from '../types';
|
|
5
|
+
|
|
6
|
+
export interface GetSlotsParams {
|
|
7
|
+
agent_id: string;
|
|
8
|
+
org_id: string;
|
|
9
|
+
from: Date;
|
|
10
|
+
to: Date;
|
|
11
|
+
duration_minutes: number;
|
|
12
|
+
include_competing_agents?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
type HoldLike = Pick<Hold, 'agent_id' | 'start_at' | 'end_at'>;
|
|
16
|
+
|
|
17
|
+
const DEFAULT_PREFERENCES: Omit<AgentPreferences, 'agent_id'> = {
|
|
18
|
+
buffer_minutes_after: 15,
|
|
19
|
+
buffer_minutes_before: 0,
|
|
20
|
+
focus_blocks: [],
|
|
21
|
+
priority_over_agents: [],
|
|
22
|
+
booking_window_days: 30,
|
|
23
|
+
allow_back_to_back: false,
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
function overlaps(
|
|
27
|
+
startA: Date,
|
|
28
|
+
endA: Date,
|
|
29
|
+
startB: Date,
|
|
30
|
+
endB: Date,
|
|
31
|
+
allowTouching = true,
|
|
32
|
+
): boolean {
|
|
33
|
+
if (allowTouching) {
|
|
34
|
+
return startA < endB && endA > startB;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return startA <= endB && endA >= startB;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function parseTimeOnDate(date: Date, time: string): Date {
|
|
41
|
+
const [hours, minutes] = time.split(':').map(Number);
|
|
42
|
+
const result = new Date(date);
|
|
43
|
+
result.setUTCHours(hours, minutes, 0, 0);
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function getFocusIntervals(
|
|
48
|
+
preferences: AgentPreferences,
|
|
49
|
+
from: Date,
|
|
50
|
+
to: Date,
|
|
51
|
+
): Array<{ start: Date; end: Date }> {
|
|
52
|
+
if (preferences.focus_blocks.length === 0) {
|
|
53
|
+
return [];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const days: Date[] = [];
|
|
57
|
+
const cursor = new Date(
|
|
58
|
+
Date.UTC(from.getUTCFullYear(), from.getUTCMonth(), from.getUTCDate()),
|
|
59
|
+
);
|
|
60
|
+
const finalDay = new Date(Date.UTC(to.getUTCFullYear(), to.getUTCMonth(), to.getUTCDate()));
|
|
61
|
+
|
|
62
|
+
while (cursor <= finalDay) {
|
|
63
|
+
days.push(new Date(cursor));
|
|
64
|
+
cursor.setUTCDate(cursor.getUTCDate() + 1);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return days.flatMap((day) => {
|
|
68
|
+
return preferences.focus_blocks
|
|
69
|
+
.filter((block) => block.weekday === day.getUTCDay())
|
|
70
|
+
.map((block) => ({
|
|
71
|
+
start: parseTimeOnDate(day, block.start_time),
|
|
72
|
+
end: parseTimeOnDate(day, block.end_time),
|
|
73
|
+
}));
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function applyHoldBuffer(
|
|
78
|
+
hold: HoldLike,
|
|
79
|
+
preferences: AgentPreferences,
|
|
80
|
+
): { start: Date; end: Date } {
|
|
81
|
+
return {
|
|
82
|
+
start: addMinutes(hold.start_at, -preferences.buffer_minutes_before),
|
|
83
|
+
end: addMinutes(hold.end_at, preferences.buffer_minutes_after),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function countCompetingHolds(slotStart: Date, slotEnd: Date, holds: HoldLike[], agentId: string): number {
|
|
88
|
+
const nearStart = addMinutes(slotStart, -30);
|
|
89
|
+
const nearEnd = addMinutes(slotEnd, 30);
|
|
90
|
+
|
|
91
|
+
return holds.filter((hold) => {
|
|
92
|
+
return hold.agent_id !== agentId && overlaps(nearStart, nearEnd, hold.start_at, hold.end_at);
|
|
93
|
+
}).length;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export async function getAvailableSlots(
|
|
97
|
+
params: GetSlotsParams,
|
|
98
|
+
client: PoolClient = pool as unknown as PoolClient,
|
|
99
|
+
): Promise<AvailableSlot[]> {
|
|
100
|
+
const windowsResult = await client.query<AvailabilityWindow>(
|
|
101
|
+
`SELECT *
|
|
102
|
+
FROM availability_windows
|
|
103
|
+
WHERE agent_id = $1
|
|
104
|
+
AND window_type = 'available'
|
|
105
|
+
AND start_at < $3
|
|
106
|
+
AND end_at > $2
|
|
107
|
+
ORDER BY start_at ASC`,
|
|
108
|
+
[params.agent_id, params.from, params.to],
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
const preferencesResult = await client.query<AgentPreferences>(
|
|
112
|
+
'SELECT * FROM agent_preferences WHERE agent_id = $1',
|
|
113
|
+
[params.agent_id],
|
|
114
|
+
);
|
|
115
|
+
const preferences: AgentPreferences = {
|
|
116
|
+
...DEFAULT_PREFERENCES,
|
|
117
|
+
...preferencesResult.rows[0],
|
|
118
|
+
agent_id: preferencesResult.rows[0]?.agent_id ?? params.agent_id,
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const holdsQuery = params.include_competing_agents
|
|
122
|
+
? `SELECT agent_id, start_at, end_at
|
|
123
|
+
FROM holds
|
|
124
|
+
WHERE org_id = $1
|
|
125
|
+
AND status = 'confirmed'
|
|
126
|
+
AND start_at < $3
|
|
127
|
+
AND end_at > $2`
|
|
128
|
+
: `SELECT agent_id, start_at, end_at
|
|
129
|
+
FROM holds
|
|
130
|
+
WHERE org_id = $1
|
|
131
|
+
AND agent_id = $4
|
|
132
|
+
AND status = 'confirmed'
|
|
133
|
+
AND start_at < $3
|
|
134
|
+
AND end_at > $2`;
|
|
135
|
+
const holdsParams = params.include_competing_agents
|
|
136
|
+
? [params.org_id, params.from, params.to]
|
|
137
|
+
: [params.org_id, params.from, params.to, params.agent_id];
|
|
138
|
+
const holdsResult = await client.query<HoldLike>(holdsQuery, holdsParams);
|
|
139
|
+
|
|
140
|
+
const focusIntervals = getFocusIntervals(preferences, params.from, params.to);
|
|
141
|
+
const slots: AvailableSlot[] = [];
|
|
142
|
+
|
|
143
|
+
for (const window of windowsResult.rows) {
|
|
144
|
+
let slotStart = max([window.start_at, params.from]);
|
|
145
|
+
const windowEnd = min([window.end_at, params.to]);
|
|
146
|
+
|
|
147
|
+
while (!isBefore(windowEnd, addMinutes(slotStart, params.duration_minutes))) {
|
|
148
|
+
const slotEnd = addMinutes(slotStart, params.duration_minutes);
|
|
149
|
+
|
|
150
|
+
const overlapsHold = holdsResult.rows.some((hold) => {
|
|
151
|
+
const buffered = applyHoldBuffer(hold, preferences);
|
|
152
|
+
return overlaps(slotStart, slotEnd, buffered.start, buffered.end);
|
|
153
|
+
});
|
|
154
|
+
const overlapsFocus = focusIntervals.some((focus) =>
|
|
155
|
+
overlaps(slotStart, slotEnd, focus.start, focus.end),
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
if (!overlapsHold && !overlapsFocus) {
|
|
159
|
+
const competingHoldsCount = countCompetingHolds(
|
|
160
|
+
slotStart,
|
|
161
|
+
slotEnd,
|
|
162
|
+
holdsResult.rows,
|
|
163
|
+
params.agent_id,
|
|
164
|
+
);
|
|
165
|
+
slots.push({
|
|
166
|
+
start: slotStart,
|
|
167
|
+
end: slotEnd,
|
|
168
|
+
confidence: Math.max(0.1, 1 - competingHoldsCount * 0.15),
|
|
169
|
+
competing_holds_count: competingHoldsCount,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
slotStart = addMinutes(slotStart, params.duration_minutes);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return slots.sort((a, b) => a.start.getTime() - b.start.getTime());
|
|
178
|
+
}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import type { PoolClient } from 'pg';
|
|
2
|
+
import type { Agent, AgentPreferences, Hold } from '../types';
|
|
3
|
+
|
|
4
|
+
const AGENT_TYPE_RANK: Record<Agent['agent_type'], number> = {
|
|
5
|
+
external_meeting: 4,
|
|
6
|
+
internal: 3,
|
|
7
|
+
focus: 2,
|
|
8
|
+
generic: 1,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type ConflictRuleApplied = 'none' | 'priority_over_agents' | 'agent_type' | 'priority' | 'first_created';
|
|
12
|
+
|
|
13
|
+
export function determineWinnerWithReason(
|
|
14
|
+
holdA: Hold,
|
|
15
|
+
agentA: Agent,
|
|
16
|
+
holdB: Hold,
|
|
17
|
+
agentB: Agent,
|
|
18
|
+
prefs: AgentPreferences[],
|
|
19
|
+
): { winner: Hold; rule_applied: ConflictRuleApplied } {
|
|
20
|
+
const prefsA = prefs.find((preference) => preference.agent_id === agentA.id);
|
|
21
|
+
const prefsB = prefs.find((preference) => preference.agent_id === agentB.id);
|
|
22
|
+
|
|
23
|
+
const agentAOverrides = prefsA?.priority_over_agents.includes(agentB.id) ?? false;
|
|
24
|
+
const agentBOverrides = prefsB?.priority_over_agents.includes(agentA.id) ?? false;
|
|
25
|
+
|
|
26
|
+
if (agentAOverrides && !agentBOverrides) {
|
|
27
|
+
return { winner: holdA, rule_applied: 'priority_over_agents' };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (agentBOverrides && !agentAOverrides) {
|
|
31
|
+
return { winner: holdB, rule_applied: 'priority_over_agents' };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const typeRankA = AGENT_TYPE_RANK[agentA.agent_type];
|
|
35
|
+
const typeRankB = AGENT_TYPE_RANK[agentB.agent_type];
|
|
36
|
+
|
|
37
|
+
if (typeRankA !== typeRankB) {
|
|
38
|
+
return { winner: typeRankA > typeRankB ? holdA : holdB, rule_applied: 'agent_type' };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (agentA.priority !== agentB.priority) {
|
|
42
|
+
return { winner: agentA.priority > agentB.priority ? holdA : holdB, rule_applied: 'priority' };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return { winner: holdA.created_at <= holdB.created_at ? holdA : holdB, rule_applied: 'first_created' };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function determineWinner(
|
|
49
|
+
holdA: Hold,
|
|
50
|
+
agentA: Agent,
|
|
51
|
+
holdB: Hold,
|
|
52
|
+
agentB: Agent,
|
|
53
|
+
prefs: AgentPreferences[],
|
|
54
|
+
): Hold {
|
|
55
|
+
return determineWinnerWithReason(holdA, agentA, holdB, agentB, prefs).winner;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export async function checkAndResolveConflict(
|
|
59
|
+
newHold: Omit<Hold, 'id' | 'created_at'>,
|
|
60
|
+
client: PoolClient,
|
|
61
|
+
): Promise<{ winner: 'new' | 'existing'; conflictingHold?: Hold }> {
|
|
62
|
+
const conflicts = await client.query<Hold>(
|
|
63
|
+
`SELECT *
|
|
64
|
+
FROM holds
|
|
65
|
+
WHERE org_id = $1
|
|
66
|
+
AND status = 'confirmed'
|
|
67
|
+
AND start_at < $3
|
|
68
|
+
AND end_at > $2
|
|
69
|
+
FOR UPDATE SKIP LOCKED`,
|
|
70
|
+
[newHold.org_id, newHold.start_at, newHold.end_at],
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
if (conflicts.rows.length === 0) {
|
|
74
|
+
return { winner: 'new' };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const newAgentResult = await client.query<Agent>('SELECT * FROM agents WHERE id = $1', [
|
|
78
|
+
newHold.agent_id,
|
|
79
|
+
]);
|
|
80
|
+
const newAgent = newAgentResult.rows[0];
|
|
81
|
+
|
|
82
|
+
if (!newAgent) {
|
|
83
|
+
throw new Error(`Agent not found: ${newHold.agent_id}`);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const losingConflicts: Hold[] = [];
|
|
87
|
+
const syntheticNewHold: Hold = {
|
|
88
|
+
...newHold,
|
|
89
|
+
id: 'new',
|
|
90
|
+
created_at: new Date(8640000000000000),
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
for (const existingHold of conflicts.rows) {
|
|
94
|
+
const existingAgentResult = await client.query<Agent>(
|
|
95
|
+
'SELECT * FROM agents WHERE id = $1',
|
|
96
|
+
[existingHold.agent_id],
|
|
97
|
+
);
|
|
98
|
+
const existingAgent = existingAgentResult.rows[0];
|
|
99
|
+
|
|
100
|
+
if (!existingAgent) {
|
|
101
|
+
throw new Error(`Agent not found: ${existingHold.agent_id}`);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const preferencesResult = await client.query<AgentPreferences>(
|
|
105
|
+
'SELECT * FROM agent_preferences WHERE agent_id = ANY($1::uuid[])',
|
|
106
|
+
[[newAgent.id, existingAgent.id]],
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
const result = determineWinnerWithReason(
|
|
110
|
+
syntheticNewHold,
|
|
111
|
+
newAgent,
|
|
112
|
+
existingHold,
|
|
113
|
+
existingAgent,
|
|
114
|
+
preferencesResult.rows,
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
if (result.winner.id === existingHold.id) {
|
|
118
|
+
return { winner: 'existing', conflictingHold: existingHold };
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
losingConflicts.push(existingHold);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return { winner: 'new', conflictingHold: losingConflicts[0] };
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export async function previewConflict(
|
|
128
|
+
newHold: Omit<Hold, 'id' | 'created_at'>,
|
|
129
|
+
client: PoolClient,
|
|
130
|
+
): Promise<{
|
|
131
|
+
status: 'available' | 'would_win' | 'would_lose';
|
|
132
|
+
winning_hold_id: string | null;
|
|
133
|
+
losing_hold_ids: string[];
|
|
134
|
+
rule_applied: ConflictRuleApplied;
|
|
135
|
+
}> {
|
|
136
|
+
const conflicts = await client.query<Hold>(
|
|
137
|
+
`SELECT *
|
|
138
|
+
FROM holds
|
|
139
|
+
WHERE org_id = $1
|
|
140
|
+
AND status = 'confirmed'
|
|
141
|
+
AND start_at < $3
|
|
142
|
+
AND end_at > $2
|
|
143
|
+
ORDER BY created_at ASC`,
|
|
144
|
+
[newHold.org_id, newHold.start_at, newHold.end_at],
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
if (conflicts.rows.length === 0) {
|
|
148
|
+
return {
|
|
149
|
+
status: 'available',
|
|
150
|
+
winning_hold_id: null,
|
|
151
|
+
losing_hold_ids: [],
|
|
152
|
+
rule_applied: 'none',
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const agentIds = Array.from(new Set([newHold.agent_id, ...conflicts.rows.map((hold) => hold.agent_id)]));
|
|
157
|
+
const agents = await client.query<Agent>('SELECT * FROM agents WHERE id = ANY($1::uuid[])', [agentIds]);
|
|
158
|
+
const preferences = await client.query<AgentPreferences>(
|
|
159
|
+
'SELECT * FROM agent_preferences WHERE agent_id = ANY($1::uuid[])',
|
|
160
|
+
[agentIds],
|
|
161
|
+
);
|
|
162
|
+
const newAgent = agents.rows.find((agent) => agent.id === newHold.agent_id);
|
|
163
|
+
|
|
164
|
+
if (!newAgent) {
|
|
165
|
+
throw new Error(`Agent not found: ${newHold.agent_id}`);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const syntheticNewHold: Hold = {
|
|
169
|
+
...newHold,
|
|
170
|
+
id: 'new',
|
|
171
|
+
created_at: new Date(8640000000000000),
|
|
172
|
+
};
|
|
173
|
+
const losingHoldIds: string[] = [];
|
|
174
|
+
let lastRule: ConflictRuleApplied = 'none';
|
|
175
|
+
|
|
176
|
+
for (const existingHold of conflicts.rows) {
|
|
177
|
+
const existingAgent = agents.rows.find((agent) => agent.id === existingHold.agent_id);
|
|
178
|
+
if (!existingAgent) {
|
|
179
|
+
throw new Error(`Agent not found: ${existingHold.agent_id}`);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const result = determineWinnerWithReason(
|
|
183
|
+
syntheticNewHold,
|
|
184
|
+
newAgent,
|
|
185
|
+
existingHold,
|
|
186
|
+
existingAgent,
|
|
187
|
+
preferences.rows,
|
|
188
|
+
);
|
|
189
|
+
lastRule = result.rule_applied;
|
|
190
|
+
|
|
191
|
+
if (result.winner.id === existingHold.id) {
|
|
192
|
+
return {
|
|
193
|
+
status: 'would_lose',
|
|
194
|
+
winning_hold_id: existingHold.id,
|
|
195
|
+
losing_hold_ids: [],
|
|
196
|
+
rule_applied: lastRule,
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
losingHoldIds.push(existingHold.id);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return {
|
|
204
|
+
status: 'would_win',
|
|
205
|
+
winning_hold_id: null,
|
|
206
|
+
losing_hold_ids: losingHoldIds,
|
|
207
|
+
rule_applied: lastRule,
|
|
208
|
+
};
|
|
209
|
+
}
|