@useatlas/create 0.0.1
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/README.md +231 -0
- package/index.ts +829 -0
- package/package.json +38 -0
- package/templates/docker/.env.example +67 -0
- package/templates/docker/Dockerfile +52 -0
- package/templates/docker/bin/__tests__/benchmark.test.ts +598 -0
- package/templates/docker/bin/__tests__/duckdb-ingest.test.ts +171 -0
- package/templates/docker/bin/__tests__/eval.test.ts +434 -0
- package/templates/docker/bin/__tests__/matview-partition.test.ts +615 -0
- package/templates/docker/bin/__tests__/multi-source.test.ts +113 -0
- package/templates/docker/bin/__tests__/plugin-cli.test.ts +322 -0
- package/templates/docker/bin/__tests__/profiler-heuristics.test.ts +608 -0
- package/templates/docker/bin/__tests__/query.test.ts +240 -0
- package/templates/docker/bin/__tests__/schema-drift.test.ts +542 -0
- package/templates/docker/bin/__tests__/view-yaml-generation.test.ts +146 -0
- package/templates/docker/bin/atlas.ts +5044 -0
- package/templates/docker/bin/benchmark.ts +695 -0
- package/templates/docker/bin/enrich.ts +559 -0
- package/templates/docker/bin/eval.ts +770 -0
- package/templates/docker/bin/smoke.ts +438 -0
- package/templates/docker/data/.gitkeep +0 -0
- package/templates/docker/data/cybersec.sql +1961 -0
- package/templates/docker/data/demo-semantic/catalog.yml +40 -0
- package/templates/docker/data/demo-semantic/entities/accounts.yml +170 -0
- package/templates/docker/data/demo-semantic/entities/companies.yml +207 -0
- package/templates/docker/data/demo-semantic/entities/people.yml +145 -0
- package/templates/docker/data/demo-semantic/glossary.yml +22 -0
- package/templates/docker/data/demo-semantic/metrics/accounts.yml +38 -0
- package/templates/docker/data/demo-semantic/metrics/companies.yml +89 -0
- package/templates/docker/data/demo.sql +373 -0
- package/templates/docker/data/ecommerce.sql +1690 -0
- package/templates/docker/data/init-demo-db.sql +8 -0
- package/templates/docker/docker-compose.yml +34 -0
- package/templates/docker/docs/deploy.md +390 -0
- package/templates/docker/eslint.config.mjs +18 -0
- package/templates/docker/gitignore +5 -0
- package/templates/docker/next.config.ts +9 -0
- package/templates/docker/package.json +59 -0
- package/templates/docker/postcss.config.mjs +8 -0
- package/templates/docker/public/.gitkeep +0 -0
- package/templates/docker/public/favicon.svg +4 -0
- package/templates/docker/railway.json +13 -0
- package/templates/docker/render.yaml +34 -0
- package/templates/docker/semantic/catalog.yml +5 -0
- package/templates/docker/semantic/entities/.gitkeep +0 -0
- package/templates/docker/semantic/glossary.yml +6 -0
- package/templates/docker/semantic/metrics/.gitkeep +0 -0
- package/templates/docker/sidecar/Dockerfile +28 -0
- package/templates/docker/sidecar/railway.json +14 -0
- package/templates/docker/sidecar/server.ts +188 -0
- package/templates/docker/src/api/__tests__/actions.test.ts +683 -0
- package/templates/docker/src/api/__tests__/admin.test.ts +820 -0
- package/templates/docker/src/api/__tests__/auth.test.ts +165 -0
- package/templates/docker/src/api/__tests__/chat.test.ts +376 -0
- package/templates/docker/src/api/__tests__/conversations.test.ts +555 -0
- package/templates/docker/src/api/__tests__/cors.test.ts +135 -0
- package/templates/docker/src/api/__tests__/health-plugin.test.ts +169 -0
- package/templates/docker/src/api/__tests__/health.test.ts +261 -0
- package/templates/docker/src/api/__tests__/query.test.ts +891 -0
- package/templates/docker/src/api/__tests__/scheduled-tasks.test.ts +601 -0
- package/templates/docker/src/api/__tests__/slack.test.ts +847 -0
- package/templates/docker/src/api/index.ts +117 -0
- package/templates/docker/src/api/routes/actions.ts +274 -0
- package/templates/docker/src/api/routes/admin.ts +757 -0
- package/templates/docker/src/api/routes/auth.ts +48 -0
- package/templates/docker/src/api/routes/chat.ts +465 -0
- package/templates/docker/src/api/routes/conversations.ts +266 -0
- package/templates/docker/src/api/routes/health.ts +287 -0
- package/templates/docker/src/api/routes/openapi.ts +390 -0
- package/templates/docker/src/api/routes/query.ts +318 -0
- package/templates/docker/src/api/routes/scheduled-tasks.ts +467 -0
- package/templates/docker/src/api/routes/slack.ts +611 -0
- package/templates/docker/src/api/server.ts +226 -0
- package/templates/docker/src/app/api/[...route]/route.ts +33 -0
- package/templates/docker/src/app/error.tsx +24 -0
- package/templates/docker/src/app/globals.css +126 -0
- package/templates/docker/src/app/layout.tsx +19 -0
- package/templates/docker/src/app/page.tsx +14 -0
- package/templates/docker/src/global.d.ts +1 -0
- package/templates/docker/src/lib/__tests__/agent-cache.test.ts +437 -0
- package/templates/docker/src/lib/__tests__/agent-dialect.test.ts +114 -0
- package/templates/docker/src/lib/__tests__/agent-health-annotations.test.ts +164 -0
- package/templates/docker/src/lib/__tests__/agent-integration.test.ts +514 -0
- package/templates/docker/src/lib/__tests__/config-actions.test.ts +166 -0
- package/templates/docker/src/lib/__tests__/config.test.ts +1063 -0
- package/templates/docker/src/lib/__tests__/conversations.test.ts +589 -0
- package/templates/docker/src/lib/__tests__/errors.test.ts +256 -0
- package/templates/docker/src/lib/__tests__/logger.test.ts +200 -0
- package/templates/docker/src/lib/__tests__/providers.test.ts +99 -0
- package/templates/docker/src/lib/__tests__/rls.test.ts +435 -0
- package/templates/docker/src/lib/__tests__/scheduled-task-types.test.ts +124 -0
- package/templates/docker/src/lib/__tests__/scheduled-tasks.test.ts +550 -0
- package/templates/docker/src/lib/__tests__/semantic-index.test.ts +547 -0
- package/templates/docker/src/lib/__tests__/semantic-multisource.test.ts +544 -0
- package/templates/docker/src/lib/__tests__/semantic.test.ts +363 -0
- package/templates/docker/src/lib/__tests__/startup-actions.test.ts +452 -0
- package/templates/docker/src/lib/__tests__/startup.test.ts +465 -0
- package/templates/docker/src/lib/__tests__/tracing.test.ts +28 -0
- package/templates/docker/src/lib/action-types.ts +95 -0
- package/templates/docker/src/lib/agent-query.ts +178 -0
- package/templates/docker/src/lib/agent.ts +505 -0
- package/templates/docker/src/lib/api-url.ts +2 -0
- package/templates/docker/src/lib/auth/__tests__/audit.test.ts +418 -0
- package/templates/docker/src/lib/auth/__tests__/byot-integration.test.ts +222 -0
- package/templates/docker/src/lib/auth/__tests__/byot.test.ts +366 -0
- package/templates/docker/src/lib/auth/__tests__/detect.test.ts +190 -0
- package/templates/docker/src/lib/auth/__tests__/managed.test.ts +173 -0
- package/templates/docker/src/lib/auth/__tests__/middleware.test.ts +456 -0
- package/templates/docker/src/lib/auth/__tests__/migrate.test.ts +201 -0
- package/templates/docker/src/lib/auth/__tests__/permissions.test.ts +225 -0
- package/templates/docker/src/lib/auth/__tests__/server.test.ts +34 -0
- package/templates/docker/src/lib/auth/__tests__/simple-key.test.ts +176 -0
- package/templates/docker/src/lib/auth/__tests__/types.test.ts +44 -0
- package/templates/docker/src/lib/auth/audit.ts +89 -0
- package/templates/docker/src/lib/auth/byot.ts +158 -0
- package/templates/docker/src/lib/auth/client.ts +35 -0
- package/templates/docker/src/lib/auth/detect.ts +83 -0
- package/templates/docker/src/lib/auth/managed.ts +73 -0
- package/templates/docker/src/lib/auth/middleware.ts +208 -0
- package/templates/docker/src/lib/auth/migrate.ts +111 -0
- package/templates/docker/src/lib/auth/permissions.ts +156 -0
- package/templates/docker/src/lib/auth/server.ts +142 -0
- package/templates/docker/src/lib/auth/simple-key.ts +92 -0
- package/templates/docker/src/lib/auth/types.ts +49 -0
- package/templates/docker/src/lib/config.ts +704 -0
- package/templates/docker/src/lib/conversation-types.ts +29 -0
- package/templates/docker/src/lib/conversations.ts +270 -0
- package/templates/docker/src/lib/db/__tests__/connection.test.ts +69 -0
- package/templates/docker/src/lib/db/__tests__/duckdb.test.ts +141 -0
- package/templates/docker/src/lib/db/__tests__/internal.test.ts +387 -0
- package/templates/docker/src/lib/db/__tests__/registry-health.test.ts +207 -0
- package/templates/docker/src/lib/db/__tests__/registry-pool-limits.test.ts +156 -0
- package/templates/docker/src/lib/db/__tests__/registry.test.ts +595 -0
- package/templates/docker/src/lib/db/__tests__/salesforce.test.ts +339 -0
- package/templates/docker/src/lib/db/__tests__/snowflake.test.ts +217 -0
- package/templates/docker/src/lib/db/__tests__/source-rate-limit.test.ts +130 -0
- package/templates/docker/src/lib/db/connection.ts +753 -0
- package/templates/docker/src/lib/db/duckdb.ts +122 -0
- package/templates/docker/src/lib/db/internal.ts +273 -0
- package/templates/docker/src/lib/db/salesforce.ts +342 -0
- package/templates/docker/src/lib/db/source-rate-limit.ts +191 -0
- package/templates/docker/src/lib/errors.ts +154 -0
- package/templates/docker/src/lib/logger.ts +98 -0
- package/templates/docker/src/lib/plugins/__tests__/hooks-integration.test.ts +202 -0
- package/templates/docker/src/lib/plugins/__tests__/hooks.test.ts +529 -0
- package/templates/docker/src/lib/plugins/__tests__/migrate.test.ts +521 -0
- package/templates/docker/src/lib/plugins/__tests__/registry.test.ts +346 -0
- package/templates/docker/src/lib/plugins/__tests__/tools.test.ts +49 -0
- package/templates/docker/src/lib/plugins/__tests__/wiring.test.ts +585 -0
- package/templates/docker/src/lib/plugins/hooks.ts +162 -0
- package/templates/docker/src/lib/plugins/index.ts +9 -0
- package/templates/docker/src/lib/plugins/migrate.ts +309 -0
- package/templates/docker/src/lib/plugins/registry.ts +231 -0
- package/templates/docker/src/lib/plugins/tools.ts +39 -0
- package/templates/docker/src/lib/plugins/wiring.ts +291 -0
- package/templates/docker/src/lib/providers.ts +102 -0
- package/templates/docker/src/lib/rls.ts +321 -0
- package/templates/docker/src/lib/scheduled-task-types.ts +132 -0
- package/templates/docker/src/lib/scheduled-tasks.ts +475 -0
- package/templates/docker/src/lib/scheduler/__tests__/delivery.test.ts +192 -0
- package/templates/docker/src/lib/scheduler/__tests__/engine.test.ts +248 -0
- package/templates/docker/src/lib/scheduler/__tests__/format-email.test.ts +96 -0
- package/templates/docker/src/lib/scheduler/__tests__/format-slack.test.ts +78 -0
- package/templates/docker/src/lib/scheduler/__tests__/format-webhook.test.ts +78 -0
- package/templates/docker/src/lib/scheduler/delivery.ts +248 -0
- package/templates/docker/src/lib/scheduler/engine.ts +317 -0
- package/templates/docker/src/lib/scheduler/executor.ts +73 -0
- package/templates/docker/src/lib/scheduler/format-email.ts +109 -0
- package/templates/docker/src/lib/scheduler/format-slack.ts +35 -0
- package/templates/docker/src/lib/scheduler/format-webhook.ts +37 -0
- package/templates/docker/src/lib/scheduler/index.ts +7 -0
- package/templates/docker/src/lib/security.ts +11 -0
- package/templates/docker/src/lib/semantic-index.ts +503 -0
- package/templates/docker/src/lib/semantic.ts +387 -0
- package/templates/docker/src/lib/sidecar-types.ts +16 -0
- package/templates/docker/src/lib/slack/__tests__/api.test.ts +160 -0
- package/templates/docker/src/lib/slack/__tests__/format.test.ts +237 -0
- package/templates/docker/src/lib/slack/__tests__/store.test.ts +188 -0
- package/templates/docker/src/lib/slack/__tests__/threads.test.ts +112 -0
- package/templates/docker/src/lib/slack/__tests__/verify.test.ts +111 -0
- package/templates/docker/src/lib/slack/api.ts +102 -0
- package/templates/docker/src/lib/slack/format.ts +209 -0
- package/templates/docker/src/lib/slack/store.ts +107 -0
- package/templates/docker/src/lib/slack/threads.ts +64 -0
- package/templates/docker/src/lib/slack/verify.ts +71 -0
- package/templates/docker/src/lib/startup.ts +730 -0
- package/templates/docker/src/lib/tools/__tests__/action-permissions.test.ts +594 -0
- package/templates/docker/src/lib/tools/__tests__/custom-validation.test.ts +238 -0
- package/templates/docker/src/lib/tools/__tests__/explore-backend.test.ts +267 -0
- package/templates/docker/src/lib/tools/__tests__/explore-nsjail.test.ts +492 -0
- package/templates/docker/src/lib/tools/__tests__/explore-plugin.test.ts +374 -0
- package/templates/docker/src/lib/tools/__tests__/explore-sdk-compat.test.ts +82 -0
- package/templates/docker/src/lib/tools/__tests__/explore-sidecar.test.ts +208 -0
- package/templates/docker/src/lib/tools/__tests__/registry-actions.test.ts +144 -0
- package/templates/docker/src/lib/tools/__tests__/registry.test.ts +235 -0
- package/templates/docker/src/lib/tools/__tests__/salesforce-tool.test.ts +154 -0
- package/templates/docker/src/lib/tools/__tests__/soql-validation.test.ts +303 -0
- package/templates/docker/src/lib/tools/__tests__/sql-audit.test.ts +225 -0
- package/templates/docker/src/lib/tools/__tests__/sql-connection-whitelist.test.ts +98 -0
- package/templates/docker/src/lib/tools/__tests__/sql-duckdb.test.ts +233 -0
- package/templates/docker/src/lib/tools/__tests__/sql-ratelimit.test.ts +225 -0
- package/templates/docker/src/lib/tools/__tests__/sql.test.ts +1012 -0
- package/templates/docker/src/lib/tools/actions/__tests__/audit.test.ts +211 -0
- package/templates/docker/src/lib/tools/actions/__tests__/email.test.ts +378 -0
- package/templates/docker/src/lib/tools/actions/__tests__/handler.test.ts +681 -0
- package/templates/docker/src/lib/tools/actions/__tests__/jira.test.ts +427 -0
- package/templates/docker/src/lib/tools/actions/audit.ts +47 -0
- package/templates/docker/src/lib/tools/actions/email.ts +191 -0
- package/templates/docker/src/lib/tools/actions/handler.ts +591 -0
- package/templates/docker/src/lib/tools/actions/index.ts +23 -0
- package/templates/docker/src/lib/tools/actions/jira.ts +220 -0
- package/templates/docker/src/lib/tools/explore-nsjail.ts +343 -0
- package/templates/docker/src/lib/tools/explore-sandbox.ts +264 -0
- package/templates/docker/src/lib/tools/explore-sidecar.ts +163 -0
- package/templates/docker/src/lib/tools/explore.ts +379 -0
- package/templates/docker/src/lib/tools/registry.ts +221 -0
- package/templates/docker/src/lib/tools/salesforce.ts +138 -0
- package/templates/docker/src/lib/tools/soql-validation.ts +172 -0
- package/templates/docker/src/lib/tools/sql.ts +680 -0
- package/templates/docker/src/lib/tracing.ts +40 -0
- package/templates/docker/src/lib/utils.ts +6 -0
- package/templates/docker/src/test-setup.ts +38 -0
- package/templates/docker/src/types/vercel-sandbox.d.ts +54 -0
- package/templates/docker/src/ui/components/actions/action-approval-card.tsx +295 -0
- package/templates/docker/src/ui/components/actions/action-status-badge.tsx +50 -0
- package/templates/docker/src/ui/components/admin/admin-layout.tsx +26 -0
- package/templates/docker/src/ui/components/admin/admin-sidebar.tsx +96 -0
- package/templates/docker/src/ui/components/admin/empty-state.tsx +24 -0
- package/templates/docker/src/ui/components/admin/entity-detail.tsx +233 -0
- package/templates/docker/src/ui/components/admin/entity-list.tsx +96 -0
- package/templates/docker/src/ui/components/admin/error-banner.tsx +22 -0
- package/templates/docker/src/ui/components/admin/feature-disabled.tsx +44 -0
- package/templates/docker/src/ui/components/admin/health-badge.tsx +30 -0
- package/templates/docker/src/ui/components/admin/loading-state.tsx +14 -0
- package/templates/docker/src/ui/components/admin/stat-card.tsx +32 -0
- package/templates/docker/src/ui/components/atlas-chat.tsx +370 -0
- package/templates/docker/src/ui/components/chart/chart-detection.ts +261 -0
- package/templates/docker/src/ui/components/chart/result-chart.tsx +375 -0
- package/templates/docker/src/ui/components/chat/api-key-bar.tsx +66 -0
- package/templates/docker/src/ui/components/chat/copy-button.tsx +25 -0
- package/templates/docker/src/ui/components/chat/data-table.tsx +102 -0
- package/templates/docker/src/ui/components/chat/error-banner.tsx +32 -0
- package/templates/docker/src/ui/components/chat/explore-card.tsx +41 -0
- package/templates/docker/src/ui/components/chat/loading-card.tsx +10 -0
- package/templates/docker/src/ui/components/chat/managed-auth-card.tsx +116 -0
- package/templates/docker/src/ui/components/chat/markdown.tsx +72 -0
- package/templates/docker/src/ui/components/chat/sql-block.tsx +30 -0
- package/templates/docker/src/ui/components/chat/sql-result-card.tsx +144 -0
- package/templates/docker/src/ui/components/chat/starter-prompts.ts +6 -0
- package/templates/docker/src/ui/components/chat/tool-part.tsx +40 -0
- package/templates/docker/src/ui/components/chat/typing-indicator.tsx +19 -0
- package/templates/docker/src/ui/components/conversations/conversation-item.tsx +120 -0
- package/templates/docker/src/ui/components/conversations/conversation-list.tsx +66 -0
- package/templates/docker/src/ui/components/conversations/conversation-sidebar.tsx +78 -0
- package/templates/docker/src/ui/components/conversations/delete-confirmation.tsx +27 -0
- package/templates/docker/src/ui/context.tsx +78 -0
- package/templates/docker/src/ui/hooks/use-admin-fetch.ts +104 -0
- package/templates/docker/src/ui/hooks/use-conversations.ts +184 -0
- package/templates/docker/src/ui/hooks/use-dark-mode.ts +17 -0
- package/templates/docker/src/ui/lib/action-types.ts +63 -0
- package/templates/docker/src/ui/lib/helpers.ts +104 -0
- package/templates/docker/src/ui/lib/types.ts +145 -0
- package/templates/docker/tsconfig.json +41 -0
- package/templates/docker/vercel.json +3 -0
- package/templates/nextjs-standalone/.env.example +68 -0
- package/templates/nextjs-standalone/bin/__tests__/benchmark.test.ts +598 -0
- package/templates/nextjs-standalone/bin/__tests__/duckdb-ingest.test.ts +171 -0
- package/templates/nextjs-standalone/bin/__tests__/eval.test.ts +434 -0
- package/templates/nextjs-standalone/bin/__tests__/matview-partition.test.ts +615 -0
- package/templates/nextjs-standalone/bin/__tests__/multi-source.test.ts +113 -0
- package/templates/nextjs-standalone/bin/__tests__/plugin-cli.test.ts +322 -0
- package/templates/nextjs-standalone/bin/__tests__/profiler-heuristics.test.ts +608 -0
- package/templates/nextjs-standalone/bin/__tests__/query.test.ts +240 -0
- package/templates/nextjs-standalone/bin/__tests__/schema-drift.test.ts +542 -0
- package/templates/nextjs-standalone/bin/__tests__/view-yaml-generation.test.ts +146 -0
- package/templates/nextjs-standalone/bin/atlas.ts +5044 -0
- package/templates/nextjs-standalone/bin/benchmark.ts +695 -0
- package/templates/nextjs-standalone/bin/enrich.ts +559 -0
- package/templates/nextjs-standalone/bin/eval.ts +770 -0
- package/templates/nextjs-standalone/bin/smoke.ts +438 -0
- package/templates/nextjs-standalone/data/.gitkeep +0 -0
- package/templates/nextjs-standalone/data/cybersec.sql +1961 -0
- package/templates/nextjs-standalone/data/demo-semantic/catalog.yml +40 -0
- package/templates/nextjs-standalone/data/demo-semantic/entities/accounts.yml +170 -0
- package/templates/nextjs-standalone/data/demo-semantic/entities/companies.yml +207 -0
- package/templates/nextjs-standalone/data/demo-semantic/entities/people.yml +145 -0
- package/templates/nextjs-standalone/data/demo-semantic/glossary.yml +22 -0
- package/templates/nextjs-standalone/data/demo-semantic/metrics/accounts.yml +38 -0
- package/templates/nextjs-standalone/data/demo-semantic/metrics/companies.yml +89 -0
- package/templates/nextjs-standalone/data/demo.sql +373 -0
- package/templates/nextjs-standalone/data/ecommerce.sql +1690 -0
- package/templates/nextjs-standalone/data/init-demo-db.sql +8 -0
- package/templates/nextjs-standalone/docs/deploy.md +390 -0
- package/templates/nextjs-standalone/eslint.config.mjs +18 -0
- package/templates/nextjs-standalone/gitignore +5 -0
- package/templates/nextjs-standalone/next.config.ts +10 -0
- package/templates/nextjs-standalone/package.json +63 -0
- package/templates/nextjs-standalone/postcss.config.mjs +8 -0
- package/templates/nextjs-standalone/semantic/catalog.yml +5 -0
- package/templates/nextjs-standalone/semantic/entities/.gitkeep +0 -0
- package/templates/nextjs-standalone/semantic/glossary.yml +6 -0
- package/templates/nextjs-standalone/semantic/metrics/.gitkeep +0 -0
- package/templates/nextjs-standalone/src/api/__tests__/actions.test.ts +683 -0
- package/templates/nextjs-standalone/src/api/__tests__/admin.test.ts +820 -0
- package/templates/nextjs-standalone/src/api/__tests__/auth.test.ts +165 -0
- package/templates/nextjs-standalone/src/api/__tests__/chat.test.ts +376 -0
- package/templates/nextjs-standalone/src/api/__tests__/conversations.test.ts +555 -0
- package/templates/nextjs-standalone/src/api/__tests__/cors.test.ts +135 -0
- package/templates/nextjs-standalone/src/api/__tests__/health-plugin.test.ts +169 -0
- package/templates/nextjs-standalone/src/api/__tests__/health.test.ts +261 -0
- package/templates/nextjs-standalone/src/api/__tests__/query.test.ts +891 -0
- package/templates/nextjs-standalone/src/api/__tests__/scheduled-tasks.test.ts +601 -0
- package/templates/nextjs-standalone/src/api/__tests__/slack.test.ts +847 -0
- package/templates/nextjs-standalone/src/api/index.ts +117 -0
- package/templates/nextjs-standalone/src/api/routes/actions.ts +274 -0
- package/templates/nextjs-standalone/src/api/routes/admin.ts +757 -0
- package/templates/nextjs-standalone/src/api/routes/auth.ts +48 -0
- package/templates/nextjs-standalone/src/api/routes/chat.ts +465 -0
- package/templates/nextjs-standalone/src/api/routes/conversations.ts +266 -0
- package/templates/nextjs-standalone/src/api/routes/health.ts +287 -0
- package/templates/nextjs-standalone/src/api/routes/openapi.ts +390 -0
- package/templates/nextjs-standalone/src/api/routes/query.ts +318 -0
- package/templates/nextjs-standalone/src/api/routes/scheduled-tasks.ts +467 -0
- package/templates/nextjs-standalone/src/api/routes/slack.ts +611 -0
- package/templates/nextjs-standalone/src/api/server.ts +226 -0
- package/templates/nextjs-standalone/src/app/api/[...route]/route.ts +33 -0
- package/templates/nextjs-standalone/src/app/error.tsx +24 -0
- package/templates/nextjs-standalone/src/app/global-error.tsx +68 -0
- package/templates/nextjs-standalone/src/app/globals.css +126 -0
- package/templates/nextjs-standalone/src/app/layout.tsx +19 -0
- package/templates/nextjs-standalone/src/app/page.tsx +14 -0
- package/templates/nextjs-standalone/src/lib/__tests__/agent-cache.test.ts +437 -0
- package/templates/nextjs-standalone/src/lib/__tests__/agent-dialect.test.ts +114 -0
- package/templates/nextjs-standalone/src/lib/__tests__/agent-health-annotations.test.ts +164 -0
- package/templates/nextjs-standalone/src/lib/__tests__/agent-integration.test.ts +514 -0
- package/templates/nextjs-standalone/src/lib/__tests__/config-actions.test.ts +166 -0
- package/templates/nextjs-standalone/src/lib/__tests__/config.test.ts +1063 -0
- package/templates/nextjs-standalone/src/lib/__tests__/conversations.test.ts +589 -0
- package/templates/nextjs-standalone/src/lib/__tests__/errors.test.ts +256 -0
- package/templates/nextjs-standalone/src/lib/__tests__/logger.test.ts +200 -0
- package/templates/nextjs-standalone/src/lib/__tests__/providers.test.ts +99 -0
- package/templates/nextjs-standalone/src/lib/__tests__/rls.test.ts +435 -0
- package/templates/nextjs-standalone/src/lib/__tests__/scheduled-task-types.test.ts +124 -0
- package/templates/nextjs-standalone/src/lib/__tests__/scheduled-tasks.test.ts +550 -0
- package/templates/nextjs-standalone/src/lib/__tests__/semantic-index.test.ts +547 -0
- package/templates/nextjs-standalone/src/lib/__tests__/semantic-multisource.test.ts +544 -0
- package/templates/nextjs-standalone/src/lib/__tests__/semantic.test.ts +363 -0
- package/templates/nextjs-standalone/src/lib/__tests__/startup-actions.test.ts +452 -0
- package/templates/nextjs-standalone/src/lib/__tests__/startup.test.ts +465 -0
- package/templates/nextjs-standalone/src/lib/__tests__/tracing.test.ts +28 -0
- package/templates/nextjs-standalone/src/lib/action-types.ts +95 -0
- package/templates/nextjs-standalone/src/lib/agent-query.ts +178 -0
- package/templates/nextjs-standalone/src/lib/agent.ts +505 -0
- package/templates/nextjs-standalone/src/lib/api-url.ts +3 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/audit.test.ts +418 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/byot-integration.test.ts +222 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/byot.test.ts +366 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/detect.test.ts +190 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/managed.test.ts +173 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/middleware.test.ts +456 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/migrate.test.ts +201 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/permissions.test.ts +225 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/server.test.ts +34 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/simple-key.test.ts +176 -0
- package/templates/nextjs-standalone/src/lib/auth/__tests__/types.test.ts +44 -0
- package/templates/nextjs-standalone/src/lib/auth/audit.ts +89 -0
- package/templates/nextjs-standalone/src/lib/auth/byot.ts +158 -0
- package/templates/nextjs-standalone/src/lib/auth/client.ts +23 -0
- package/templates/nextjs-standalone/src/lib/auth/detect.ts +83 -0
- package/templates/nextjs-standalone/src/lib/auth/managed.ts +73 -0
- package/templates/nextjs-standalone/src/lib/auth/middleware.ts +208 -0
- package/templates/nextjs-standalone/src/lib/auth/migrate.ts +111 -0
- package/templates/nextjs-standalone/src/lib/auth/permissions.ts +156 -0
- package/templates/nextjs-standalone/src/lib/auth/server.ts +142 -0
- package/templates/nextjs-standalone/src/lib/auth/simple-key.ts +92 -0
- package/templates/nextjs-standalone/src/lib/auth/types.ts +49 -0
- package/templates/nextjs-standalone/src/lib/config.ts +704 -0
- package/templates/nextjs-standalone/src/lib/conversation-types.ts +29 -0
- package/templates/nextjs-standalone/src/lib/conversations.ts +270 -0
- package/templates/nextjs-standalone/src/lib/db/__tests__/connection.test.ts +69 -0
- package/templates/nextjs-standalone/src/lib/db/__tests__/duckdb.test.ts +141 -0
- package/templates/nextjs-standalone/src/lib/db/__tests__/internal.test.ts +387 -0
- package/templates/nextjs-standalone/src/lib/db/__tests__/registry-health.test.ts +207 -0
- package/templates/nextjs-standalone/src/lib/db/__tests__/registry-pool-limits.test.ts +156 -0
- package/templates/nextjs-standalone/src/lib/db/__tests__/registry.test.ts +595 -0
- package/templates/nextjs-standalone/src/lib/db/__tests__/salesforce.test.ts +339 -0
- package/templates/nextjs-standalone/src/lib/db/__tests__/snowflake.test.ts +217 -0
- package/templates/nextjs-standalone/src/lib/db/__tests__/source-rate-limit.test.ts +130 -0
- package/templates/nextjs-standalone/src/lib/db/connection.ts +753 -0
- package/templates/nextjs-standalone/src/lib/db/duckdb.ts +122 -0
- package/templates/nextjs-standalone/src/lib/db/internal.ts +273 -0
- package/templates/nextjs-standalone/src/lib/db/salesforce.ts +342 -0
- package/templates/nextjs-standalone/src/lib/db/source-rate-limit.ts +191 -0
- package/templates/nextjs-standalone/src/lib/errors.ts +154 -0
- package/templates/nextjs-standalone/src/lib/logger.ts +98 -0
- package/templates/nextjs-standalone/src/lib/plugins/__tests__/hooks-integration.test.ts +202 -0
- package/templates/nextjs-standalone/src/lib/plugins/__tests__/hooks.test.ts +529 -0
- package/templates/nextjs-standalone/src/lib/plugins/__tests__/migrate.test.ts +521 -0
- package/templates/nextjs-standalone/src/lib/plugins/__tests__/registry.test.ts +346 -0
- package/templates/nextjs-standalone/src/lib/plugins/__tests__/tools.test.ts +49 -0
- package/templates/nextjs-standalone/src/lib/plugins/__tests__/wiring.test.ts +585 -0
- package/templates/nextjs-standalone/src/lib/plugins/hooks.ts +162 -0
- package/templates/nextjs-standalone/src/lib/plugins/index.ts +9 -0
- package/templates/nextjs-standalone/src/lib/plugins/migrate.ts +309 -0
- package/templates/nextjs-standalone/src/lib/plugins/registry.ts +231 -0
- package/templates/nextjs-standalone/src/lib/plugins/tools.ts +39 -0
- package/templates/nextjs-standalone/src/lib/plugins/wiring.ts +291 -0
- package/templates/nextjs-standalone/src/lib/providers.ts +102 -0
- package/templates/nextjs-standalone/src/lib/rls.ts +321 -0
- package/templates/nextjs-standalone/src/lib/scheduled-task-types.ts +132 -0
- package/templates/nextjs-standalone/src/lib/scheduled-tasks.ts +475 -0
- package/templates/nextjs-standalone/src/lib/scheduler/__tests__/delivery.test.ts +192 -0
- package/templates/nextjs-standalone/src/lib/scheduler/__tests__/engine.test.ts +248 -0
- package/templates/nextjs-standalone/src/lib/scheduler/__tests__/format-email.test.ts +96 -0
- package/templates/nextjs-standalone/src/lib/scheduler/__tests__/format-slack.test.ts +78 -0
- package/templates/nextjs-standalone/src/lib/scheduler/__tests__/format-webhook.test.ts +78 -0
- package/templates/nextjs-standalone/src/lib/scheduler/delivery.ts +248 -0
- package/templates/nextjs-standalone/src/lib/scheduler/engine.ts +317 -0
- package/templates/nextjs-standalone/src/lib/scheduler/executor.ts +73 -0
- package/templates/nextjs-standalone/src/lib/scheduler/format-email.ts +109 -0
- package/templates/nextjs-standalone/src/lib/scheduler/format-slack.ts +35 -0
- package/templates/nextjs-standalone/src/lib/scheduler/format-webhook.ts +37 -0
- package/templates/nextjs-standalone/src/lib/scheduler/index.ts +7 -0
- package/templates/nextjs-standalone/src/lib/security.ts +11 -0
- package/templates/nextjs-standalone/src/lib/semantic-index.ts +503 -0
- package/templates/nextjs-standalone/src/lib/semantic.ts +387 -0
- package/templates/nextjs-standalone/src/lib/sidecar-types.ts +16 -0
- package/templates/nextjs-standalone/src/lib/slack/__tests__/api.test.ts +160 -0
- package/templates/nextjs-standalone/src/lib/slack/__tests__/format.test.ts +237 -0
- package/templates/nextjs-standalone/src/lib/slack/__tests__/store.test.ts +188 -0
- package/templates/nextjs-standalone/src/lib/slack/__tests__/threads.test.ts +112 -0
- package/templates/nextjs-standalone/src/lib/slack/__tests__/verify.test.ts +111 -0
- package/templates/nextjs-standalone/src/lib/slack/api.ts +102 -0
- package/templates/nextjs-standalone/src/lib/slack/format.ts +209 -0
- package/templates/nextjs-standalone/src/lib/slack/store.ts +107 -0
- package/templates/nextjs-standalone/src/lib/slack/threads.ts +64 -0
- package/templates/nextjs-standalone/src/lib/slack/verify.ts +71 -0
- package/templates/nextjs-standalone/src/lib/startup.ts +730 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/action-permissions.test.ts +594 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/custom-validation.test.ts +238 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/explore-backend.test.ts +267 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/explore-nsjail.test.ts +492 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/explore-plugin.test.ts +374 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/explore-sdk-compat.test.ts +82 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/explore-sidecar.test.ts +208 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/registry-actions.test.ts +144 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/registry.test.ts +235 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/salesforce-tool.test.ts +154 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/soql-validation.test.ts +303 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/sql-audit.test.ts +225 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/sql-connection-whitelist.test.ts +98 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/sql-duckdb.test.ts +233 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/sql-ratelimit.test.ts +225 -0
- package/templates/nextjs-standalone/src/lib/tools/__tests__/sql.test.ts +1012 -0
- package/templates/nextjs-standalone/src/lib/tools/actions/__tests__/audit.test.ts +211 -0
- package/templates/nextjs-standalone/src/lib/tools/actions/__tests__/email.test.ts +378 -0
- package/templates/nextjs-standalone/src/lib/tools/actions/__tests__/handler.test.ts +681 -0
- package/templates/nextjs-standalone/src/lib/tools/actions/__tests__/jira.test.ts +427 -0
- package/templates/nextjs-standalone/src/lib/tools/actions/audit.ts +47 -0
- package/templates/nextjs-standalone/src/lib/tools/actions/email.ts +191 -0
- package/templates/nextjs-standalone/src/lib/tools/actions/handler.ts +591 -0
- package/templates/nextjs-standalone/src/lib/tools/actions/index.ts +23 -0
- package/templates/nextjs-standalone/src/lib/tools/actions/jira.ts +220 -0
- package/templates/nextjs-standalone/src/lib/tools/explore-nsjail.ts +343 -0
- package/templates/nextjs-standalone/src/lib/tools/explore-sandbox.ts +264 -0
- package/templates/nextjs-standalone/src/lib/tools/explore-sidecar.ts +163 -0
- package/templates/nextjs-standalone/src/lib/tools/explore.ts +379 -0
- package/templates/nextjs-standalone/src/lib/tools/registry.ts +221 -0
- package/templates/nextjs-standalone/src/lib/tools/salesforce.ts +138 -0
- package/templates/nextjs-standalone/src/lib/tools/soql-validation.ts +172 -0
- package/templates/nextjs-standalone/src/lib/tools/sql.ts +680 -0
- package/templates/nextjs-standalone/src/lib/tracing.ts +40 -0
- package/templates/nextjs-standalone/src/lib/utils.ts +6 -0
- package/templates/nextjs-standalone/src/test-setup.ts +38 -0
- package/templates/nextjs-standalone/src/ui/components/actions/action-approval-card.tsx +295 -0
- package/templates/nextjs-standalone/src/ui/components/actions/action-status-badge.tsx +50 -0
- package/templates/nextjs-standalone/src/ui/components/admin/admin-layout.tsx +26 -0
- package/templates/nextjs-standalone/src/ui/components/admin/admin-sidebar.tsx +96 -0
- package/templates/nextjs-standalone/src/ui/components/admin/empty-state.tsx +24 -0
- package/templates/nextjs-standalone/src/ui/components/admin/entity-detail.tsx +233 -0
- package/templates/nextjs-standalone/src/ui/components/admin/entity-list.tsx +96 -0
- package/templates/nextjs-standalone/src/ui/components/admin/error-banner.tsx +22 -0
- package/templates/nextjs-standalone/src/ui/components/admin/feature-disabled.tsx +44 -0
- package/templates/nextjs-standalone/src/ui/components/admin/health-badge.tsx +30 -0
- package/templates/nextjs-standalone/src/ui/components/admin/loading-state.tsx +14 -0
- package/templates/nextjs-standalone/src/ui/components/admin/stat-card.tsx +32 -0
- package/templates/nextjs-standalone/src/ui/components/atlas-chat.tsx +370 -0
- package/templates/nextjs-standalone/src/ui/components/chart/chart-detection.ts +261 -0
- package/templates/nextjs-standalone/src/ui/components/chart/result-chart.tsx +375 -0
- package/templates/nextjs-standalone/src/ui/components/chat/api-key-bar.tsx +66 -0
- package/templates/nextjs-standalone/src/ui/components/chat/copy-button.tsx +25 -0
- package/templates/nextjs-standalone/src/ui/components/chat/data-table.tsx +102 -0
- package/templates/nextjs-standalone/src/ui/components/chat/error-banner.tsx +32 -0
- package/templates/nextjs-standalone/src/ui/components/chat/explore-card.tsx +41 -0
- package/templates/nextjs-standalone/src/ui/components/chat/loading-card.tsx +10 -0
- package/templates/nextjs-standalone/src/ui/components/chat/managed-auth-card.tsx +116 -0
- package/templates/nextjs-standalone/src/ui/components/chat/markdown.tsx +72 -0
- package/templates/nextjs-standalone/src/ui/components/chat/sql-block.tsx +30 -0
- package/templates/nextjs-standalone/src/ui/components/chat/sql-result-card.tsx +144 -0
- package/templates/nextjs-standalone/src/ui/components/chat/starter-prompts.ts +6 -0
- package/templates/nextjs-standalone/src/ui/components/chat/tool-part.tsx +40 -0
- package/templates/nextjs-standalone/src/ui/components/chat/typing-indicator.tsx +19 -0
- package/templates/nextjs-standalone/src/ui/components/conversations/conversation-item.tsx +120 -0
- package/templates/nextjs-standalone/src/ui/components/conversations/conversation-list.tsx +66 -0
- package/templates/nextjs-standalone/src/ui/components/conversations/conversation-sidebar.tsx +78 -0
- package/templates/nextjs-standalone/src/ui/components/conversations/delete-confirmation.tsx +27 -0
- package/templates/nextjs-standalone/src/ui/context.tsx +78 -0
- package/templates/nextjs-standalone/src/ui/hooks/use-admin-fetch.ts +104 -0
- package/templates/nextjs-standalone/src/ui/hooks/use-conversations.ts +184 -0
- package/templates/nextjs-standalone/src/ui/hooks/use-dark-mode.ts +17 -0
- package/templates/nextjs-standalone/src/ui/lib/action-types.ts +63 -0
- package/templates/nextjs-standalone/src/ui/lib/helpers.ts +104 -0
- package/templates/nextjs-standalone/src/ui/lib/types.ts +145 -0
- package/templates/nextjs-standalone/tsconfig.json +32 -0
- package/templates/nextjs-standalone/vercel.json +4 -0
|
@@ -0,0 +1,467 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scheduled tasks REST routes — CRUD + trigger + run history.
|
|
3
|
+
*
|
|
4
|
+
* Gated behind ATLAS_SCHEDULER_ENABLED=true (conditional mount in index.ts).
|
|
5
|
+
* Follows the same auth → rate limit → withRequestContext pattern as conversations.ts.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { Hono } from "hono";
|
|
9
|
+
import { z } from "zod";
|
|
10
|
+
import { createLogger, withRequestContext } from "@atlas/api/lib/logger";
|
|
11
|
+
import type { AuthResult } from "@atlas/api/lib/auth/types";
|
|
12
|
+
import {
|
|
13
|
+
authenticateRequest,
|
|
14
|
+
checkRateLimit,
|
|
15
|
+
getClientIP,
|
|
16
|
+
} from "@atlas/api/lib/auth/middleware";
|
|
17
|
+
import { hasInternalDB } from "@atlas/api/lib/db/internal";
|
|
18
|
+
import {
|
|
19
|
+
createScheduledTask,
|
|
20
|
+
getScheduledTask,
|
|
21
|
+
listScheduledTasks,
|
|
22
|
+
updateScheduledTask,
|
|
23
|
+
deleteScheduledTask,
|
|
24
|
+
listTaskRuns,
|
|
25
|
+
validateCronExpression,
|
|
26
|
+
type CrudFailReason,
|
|
27
|
+
} from "@atlas/api/lib/scheduled-tasks";
|
|
28
|
+
import { DELIVERY_CHANNELS } from "@atlas/api/lib/scheduled-task-types";
|
|
29
|
+
import { ACTION_APPROVAL_MODES } from "@atlas/api/lib/action-types";
|
|
30
|
+
|
|
31
|
+
const log = createLogger("scheduled-tasks-routes");
|
|
32
|
+
|
|
33
|
+
// ---------------------------------------------------------------------------
|
|
34
|
+
// Zod schemas
|
|
35
|
+
// ---------------------------------------------------------------------------
|
|
36
|
+
|
|
37
|
+
const RecipientSchema = z.discriminatedUnion("type", [
|
|
38
|
+
z.object({ type: z.literal("email"), address: z.string().email() }),
|
|
39
|
+
z.object({ type: z.literal("slack"), channel: z.string().min(1), teamId: z.string().optional() }),
|
|
40
|
+
z.object({ type: z.literal("webhook"), url: z.string().url(), headers: z.record(z.string(), z.string()).optional() }),
|
|
41
|
+
]);
|
|
42
|
+
|
|
43
|
+
export const CreateScheduledTaskSchema = z.object({
|
|
44
|
+
name: z.string().min(1).max(200),
|
|
45
|
+
question: z.string().min(1).max(2000),
|
|
46
|
+
cronExpression: z.string().min(1),
|
|
47
|
+
deliveryChannel: z.enum(DELIVERY_CHANNELS).default("webhook"),
|
|
48
|
+
recipients: z.array(RecipientSchema).default([]),
|
|
49
|
+
connectionId: z.string().nullable().optional(),
|
|
50
|
+
approvalMode: z.enum(ACTION_APPROVAL_MODES).default("auto"),
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
export const UpdateScheduledTaskSchema = z.object({
|
|
54
|
+
name: z.string().min(1).max(200).optional(),
|
|
55
|
+
question: z.string().min(1).max(2000).optional(),
|
|
56
|
+
cronExpression: z.string().min(1).optional(),
|
|
57
|
+
deliveryChannel: z.enum(DELIVERY_CHANNELS).optional(),
|
|
58
|
+
recipients: z.array(RecipientSchema).optional(),
|
|
59
|
+
connectionId: z.string().nullable().optional(),
|
|
60
|
+
approvalMode: z.enum(ACTION_APPROVAL_MODES).optional(),
|
|
61
|
+
enabled: z.boolean().optional(),
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
65
|
+
|
|
66
|
+
function crudFailResponse(reason: CrudFailReason) {
|
|
67
|
+
switch (reason) {
|
|
68
|
+
case "no_db":
|
|
69
|
+
return { body: { error: "not_available", message: "Scheduled tasks require an internal database." }, status: 404 as const };
|
|
70
|
+
case "not_found":
|
|
71
|
+
return { body: { error: "not_found", message: "Scheduled task not found." }, status: 404 as const };
|
|
72
|
+
case "error":
|
|
73
|
+
return { body: { error: "internal_error", message: "A database error occurred. Please try again." }, status: 500 as const };
|
|
74
|
+
default: {
|
|
75
|
+
const _exhaustive: never = reason;
|
|
76
|
+
return { body: { error: "internal_error", message: `Unexpected failure: ${_exhaustive}` }, status: 500 as const };
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const scheduledTasks = new Hono();
|
|
82
|
+
|
|
83
|
+
// ---------------------------------------------------------------------------
|
|
84
|
+
// Shared auth preamble
|
|
85
|
+
// ---------------------------------------------------------------------------
|
|
86
|
+
|
|
87
|
+
async function authPreamble(req: Request, requestId: string) {
|
|
88
|
+
let authResult: AuthResult;
|
|
89
|
+
try {
|
|
90
|
+
authResult = await authenticateRequest(req);
|
|
91
|
+
} catch (err) {
|
|
92
|
+
log.error(
|
|
93
|
+
{ err: err instanceof Error ? err : new Error(String(err)), requestId },
|
|
94
|
+
"Auth dispatch failed",
|
|
95
|
+
);
|
|
96
|
+
return { error: { error: "auth_error", message: "Authentication system error" }, status: 500 as const };
|
|
97
|
+
}
|
|
98
|
+
if (!authResult.authenticated) {
|
|
99
|
+
log.warn({ requestId, status: authResult.status }, "Authentication failed");
|
|
100
|
+
return { error: { error: "auth_error", message: authResult.error }, status: authResult.status as 401 | 403 | 500 };
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const ip = getClientIP(req);
|
|
104
|
+
const rateLimitKey = authResult.user?.id ?? (ip ? `ip:${ip}` : "anon");
|
|
105
|
+
const rateCheck = checkRateLimit(rateLimitKey);
|
|
106
|
+
if (!rateCheck.allowed) {
|
|
107
|
+
const retryAfterSeconds = Math.ceil((rateCheck.retryAfterMs ?? 60000) / 1000);
|
|
108
|
+
return {
|
|
109
|
+
error: { error: "rate_limited", message: "Too many requests. Please wait before trying again.", retryAfterSeconds },
|
|
110
|
+
status: 429 as const,
|
|
111
|
+
headers: { "Retry-After": String(retryAfterSeconds) },
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return { authResult };
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// ---------------------------------------------------------------------------
|
|
119
|
+
// GET / — list scheduled tasks
|
|
120
|
+
// ---------------------------------------------------------------------------
|
|
121
|
+
|
|
122
|
+
scheduledTasks.get("/", async (c) => {
|
|
123
|
+
const req = c.req.raw;
|
|
124
|
+
const requestId = crypto.randomUUID();
|
|
125
|
+
|
|
126
|
+
if (!hasInternalDB()) {
|
|
127
|
+
return c.json({ error: "not_available", message: "Scheduled tasks require an internal database." }, 404);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const preamble = await authPreamble(req, requestId);
|
|
131
|
+
if ("error" in preamble) {
|
|
132
|
+
return c.json(preamble.error, { status: preamble.status, headers: preamble.headers });
|
|
133
|
+
}
|
|
134
|
+
const { authResult } = preamble;
|
|
135
|
+
|
|
136
|
+
return withRequestContext({ requestId, user: authResult.user }, async () => {
|
|
137
|
+
const rawLimit = parseInt(c.req.query("limit") ?? "20", 10);
|
|
138
|
+
const rawOffset = parseInt(c.req.query("offset") ?? "0", 10);
|
|
139
|
+
const limit = Number.isFinite(rawLimit) && rawLimit > 0 ? Math.min(rawLimit, 100) : 20;
|
|
140
|
+
const offset = Number.isFinite(rawOffset) && rawOffset >= 0 ? rawOffset : 0;
|
|
141
|
+
const enabledParam = c.req.query("enabled");
|
|
142
|
+
const enabled = enabledParam === "true" ? true : enabledParam === "false" ? false : undefined;
|
|
143
|
+
|
|
144
|
+
const result = await listScheduledTasks({
|
|
145
|
+
ownerId: authResult.user?.id,
|
|
146
|
+
enabled,
|
|
147
|
+
limit,
|
|
148
|
+
offset,
|
|
149
|
+
});
|
|
150
|
+
return c.json(result);
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
// ---------------------------------------------------------------------------
|
|
155
|
+
// POST / — create scheduled task
|
|
156
|
+
// ---------------------------------------------------------------------------
|
|
157
|
+
|
|
158
|
+
scheduledTasks.post("/", async (c) => {
|
|
159
|
+
const req = c.req.raw;
|
|
160
|
+
const requestId = crypto.randomUUID();
|
|
161
|
+
|
|
162
|
+
if (!hasInternalDB()) {
|
|
163
|
+
return c.json({ error: "not_available", message: "Scheduled tasks require an internal database." }, 404);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const preamble = await authPreamble(req, requestId);
|
|
167
|
+
if ("error" in preamble) {
|
|
168
|
+
return c.json(preamble.error, { status: preamble.status, headers: preamble.headers });
|
|
169
|
+
}
|
|
170
|
+
const { authResult } = preamble;
|
|
171
|
+
|
|
172
|
+
return withRequestContext({ requestId, user: authResult.user }, async () => {
|
|
173
|
+
let body: unknown;
|
|
174
|
+
try {
|
|
175
|
+
body = await req.json();
|
|
176
|
+
} catch {
|
|
177
|
+
return c.json({ error: "invalid_request", message: "Invalid JSON body." }, 400);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const parsed = CreateScheduledTaskSchema.safeParse(body);
|
|
181
|
+
if (!parsed.success) {
|
|
182
|
+
const issues = parsed.error.issues.map((i) => `${i.path.join(".")}: ${i.message}`).join("; ");
|
|
183
|
+
return c.json({ error: "invalid_request", message: issues }, 400);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Validate cron expression
|
|
187
|
+
const cronCheck = validateCronExpression(parsed.data.cronExpression);
|
|
188
|
+
if (!cronCheck.valid) {
|
|
189
|
+
return c.json({ error: "invalid_request", message: `Invalid cron expression: ${cronCheck.error}` }, 400);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const result = await createScheduledTask({
|
|
193
|
+
ownerId: authResult.user?.id ?? "anonymous",
|
|
194
|
+
name: parsed.data.name,
|
|
195
|
+
question: parsed.data.question,
|
|
196
|
+
cronExpression: parsed.data.cronExpression,
|
|
197
|
+
deliveryChannel: parsed.data.deliveryChannel,
|
|
198
|
+
recipients: parsed.data.recipients,
|
|
199
|
+
connectionId: parsed.data.connectionId ?? null,
|
|
200
|
+
approvalMode: parsed.data.approvalMode,
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
if (!result.ok) {
|
|
204
|
+
const fail = crudFailResponse(result.reason);
|
|
205
|
+
return c.json(fail.body, fail.status);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
return c.json(result.data, 201);
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
// ---------------------------------------------------------------------------
|
|
213
|
+
// POST /tick — serverless scheduler tick (Vercel Cron)
|
|
214
|
+
// ---------------------------------------------------------------------------
|
|
215
|
+
|
|
216
|
+
scheduledTasks.post("/tick", async (c) => {
|
|
217
|
+
const req = c.req.raw;
|
|
218
|
+
|
|
219
|
+
if (!hasInternalDB()) {
|
|
220
|
+
return c.json({ error: "not_available", message: "Scheduled tasks require an internal database." }, 404);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// Auth: check CRON_SECRET (Vercel-native) or ATLAS_SCHEDULER_SECRET (generic)
|
|
224
|
+
const secret = process.env.CRON_SECRET ?? process.env.ATLAS_SCHEDULER_SECRET;
|
|
225
|
+
const { getConfig } = await import("@atlas/api/lib/config");
|
|
226
|
+
const config = getConfig();
|
|
227
|
+
|
|
228
|
+
if (secret) {
|
|
229
|
+
const authHeader = req.headers.get("authorization");
|
|
230
|
+
if (authHeader !== `Bearer ${secret}`) {
|
|
231
|
+
return c.json({ error: "unauthorized", message: "Invalid or missing cron secret." }, 401);
|
|
232
|
+
}
|
|
233
|
+
} else if (config?.scheduler?.backend === "vercel") {
|
|
234
|
+
return c.json(
|
|
235
|
+
{ error: "misconfigured", message: "Vercel backend requires CRON_SECRET or ATLAS_SCHEDULER_SECRET to be set." },
|
|
236
|
+
500,
|
|
237
|
+
);
|
|
238
|
+
} else if (process.env.NODE_ENV === "production") {
|
|
239
|
+
return c.json(
|
|
240
|
+
{ error: "misconfigured", message: "CRON_SECRET or ATLAS_SCHEDULER_SECRET must be set in production." },
|
|
241
|
+
500,
|
|
242
|
+
);
|
|
243
|
+
} else {
|
|
244
|
+
log.warn("POST /tick called without secret — allowing because NODE_ENV is not 'production'");
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
try {
|
|
248
|
+
const { runTick } = await import("@atlas/api/lib/scheduler/engine");
|
|
249
|
+
const result = await runTick();
|
|
250
|
+
if (result.error) {
|
|
251
|
+
return c.json(result, 500);
|
|
252
|
+
}
|
|
253
|
+
return c.json(result);
|
|
254
|
+
} catch (err) {
|
|
255
|
+
log.error({ err: err instanceof Error ? err : new Error(String(err)) }, "Tick execution failed");
|
|
256
|
+
return c.json({ error: "internal_error", message: "Tick execution failed." }, 500);
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
// ---------------------------------------------------------------------------
|
|
261
|
+
// GET /:id — get scheduled task with recent runs
|
|
262
|
+
// ---------------------------------------------------------------------------
|
|
263
|
+
|
|
264
|
+
scheduledTasks.get("/:id", async (c) => {
|
|
265
|
+
const req = c.req.raw;
|
|
266
|
+
const requestId = crypto.randomUUID();
|
|
267
|
+
|
|
268
|
+
if (!hasInternalDB()) {
|
|
269
|
+
return c.json({ error: "not_available", message: "Scheduled tasks require an internal database." }, 404);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
const preamble = await authPreamble(req, requestId);
|
|
273
|
+
if ("error" in preamble) {
|
|
274
|
+
return c.json(preamble.error, { status: preamble.status, headers: preamble.headers });
|
|
275
|
+
}
|
|
276
|
+
const { authResult } = preamble;
|
|
277
|
+
|
|
278
|
+
const id = c.req.param("id");
|
|
279
|
+
if (!UUID_RE.test(id)) {
|
|
280
|
+
return c.json({ error: "invalid_request", message: "Invalid task ID format." }, 400);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
return withRequestContext({ requestId, user: authResult.user }, async () => {
|
|
284
|
+
const result = await getScheduledTask(id, authResult.user?.id);
|
|
285
|
+
if (!result.ok) {
|
|
286
|
+
const fail = crudFailResponse(result.reason);
|
|
287
|
+
return c.json(fail.body, fail.status);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
const runs = await listTaskRuns(id, { limit: 10 });
|
|
291
|
+
return c.json({ ...result.data, recentRuns: runs });
|
|
292
|
+
});
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
// ---------------------------------------------------------------------------
|
|
296
|
+
// PUT /:id — update scheduled task
|
|
297
|
+
// ---------------------------------------------------------------------------
|
|
298
|
+
|
|
299
|
+
scheduledTasks.put("/:id", async (c) => {
|
|
300
|
+
const req = c.req.raw;
|
|
301
|
+
const requestId = crypto.randomUUID();
|
|
302
|
+
|
|
303
|
+
if (!hasInternalDB()) {
|
|
304
|
+
return c.json({ error: "not_available", message: "Scheduled tasks require an internal database." }, 404);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
const preamble = await authPreamble(req, requestId);
|
|
308
|
+
if ("error" in preamble) {
|
|
309
|
+
return c.json(preamble.error, { status: preamble.status, headers: preamble.headers });
|
|
310
|
+
}
|
|
311
|
+
const { authResult } = preamble;
|
|
312
|
+
|
|
313
|
+
const id = c.req.param("id");
|
|
314
|
+
if (!UUID_RE.test(id)) {
|
|
315
|
+
return c.json({ error: "invalid_request", message: "Invalid task ID format." }, 400);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
return withRequestContext({ requestId, user: authResult.user }, async () => {
|
|
319
|
+
let body: unknown;
|
|
320
|
+
try {
|
|
321
|
+
body = await req.json();
|
|
322
|
+
} catch {
|
|
323
|
+
return c.json({ error: "invalid_request", message: "Invalid JSON body." }, 400);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
const parsed = UpdateScheduledTaskSchema.safeParse(body);
|
|
327
|
+
if (!parsed.success) {
|
|
328
|
+
const issues = parsed.error.issues.map((i) => `${i.path.join(".")}: ${i.message}`).join("; ");
|
|
329
|
+
return c.json({ error: "invalid_request", message: issues }, 400);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// Validate cron if provided
|
|
333
|
+
if (parsed.data.cronExpression) {
|
|
334
|
+
const cronCheck = validateCronExpression(parsed.data.cronExpression);
|
|
335
|
+
if (!cronCheck.valid) {
|
|
336
|
+
return c.json({ error: "invalid_request", message: `Invalid cron expression: ${cronCheck.error}` }, 400);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
const result = await updateScheduledTask(id, authResult.user?.id ?? "anonymous", parsed.data);
|
|
341
|
+
if (!result.ok) {
|
|
342
|
+
const fail = crudFailResponse(result.reason);
|
|
343
|
+
return c.json(fail.body, fail.status);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// Fetch updated task to return
|
|
347
|
+
const updated = await getScheduledTask(id, authResult.user?.id);
|
|
348
|
+
if (!updated.ok) {
|
|
349
|
+
return c.json({ ok: true });
|
|
350
|
+
}
|
|
351
|
+
return c.json(updated.data);
|
|
352
|
+
});
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
// ---------------------------------------------------------------------------
|
|
356
|
+
// DELETE /:id — soft delete (disable)
|
|
357
|
+
// ---------------------------------------------------------------------------
|
|
358
|
+
|
|
359
|
+
scheduledTasks.delete("/:id", async (c) => {
|
|
360
|
+
const req = c.req.raw;
|
|
361
|
+
const requestId = crypto.randomUUID();
|
|
362
|
+
|
|
363
|
+
if (!hasInternalDB()) {
|
|
364
|
+
return c.json({ error: "not_available", message: "Scheduled tasks require an internal database." }, 404);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
const preamble = await authPreamble(req, requestId);
|
|
368
|
+
if ("error" in preamble) {
|
|
369
|
+
return c.json(preamble.error, { status: preamble.status, headers: preamble.headers });
|
|
370
|
+
}
|
|
371
|
+
const { authResult } = preamble;
|
|
372
|
+
|
|
373
|
+
const id = c.req.param("id");
|
|
374
|
+
if (!UUID_RE.test(id)) {
|
|
375
|
+
return c.json({ error: "invalid_request", message: "Invalid task ID format." }, 400);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
return withRequestContext({ requestId, user: authResult.user }, async () => {
|
|
379
|
+
const result = await deleteScheduledTask(id, authResult.user?.id);
|
|
380
|
+
if (!result.ok) {
|
|
381
|
+
const fail = crudFailResponse(result.reason);
|
|
382
|
+
return c.json(fail.body, fail.status);
|
|
383
|
+
}
|
|
384
|
+
return c.body(null, 204);
|
|
385
|
+
});
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
// ---------------------------------------------------------------------------
|
|
389
|
+
// POST /:id/run — trigger immediate execution
|
|
390
|
+
// ---------------------------------------------------------------------------
|
|
391
|
+
|
|
392
|
+
scheduledTasks.post("/:id/run", async (c) => {
|
|
393
|
+
const req = c.req.raw;
|
|
394
|
+
const requestId = crypto.randomUUID();
|
|
395
|
+
|
|
396
|
+
if (!hasInternalDB()) {
|
|
397
|
+
return c.json({ error: "not_available", message: "Scheduled tasks require an internal database." }, 404);
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
const preamble = await authPreamble(req, requestId);
|
|
401
|
+
if ("error" in preamble) {
|
|
402
|
+
return c.json(preamble.error, { status: preamble.status, headers: preamble.headers });
|
|
403
|
+
}
|
|
404
|
+
const { authResult } = preamble;
|
|
405
|
+
|
|
406
|
+
const id = c.req.param("id");
|
|
407
|
+
if (!UUID_RE.test(id)) {
|
|
408
|
+
return c.json({ error: "invalid_request", message: "Invalid task ID format." }, 400);
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
return withRequestContext({ requestId, user: authResult.user }, async () => {
|
|
412
|
+
const task = await getScheduledTask(id, authResult.user?.id);
|
|
413
|
+
if (!task.ok) {
|
|
414
|
+
const fail = crudFailResponse(task.reason);
|
|
415
|
+
return c.json(fail.body, fail.status);
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
try {
|
|
419
|
+
const { triggerTask } = await import("@atlas/api/lib/scheduler/engine");
|
|
420
|
+
await triggerTask(id);
|
|
421
|
+
return c.json({ message: "Task triggered successfully.", taskId: id });
|
|
422
|
+
} catch (err) {
|
|
423
|
+
log.error({ err: err instanceof Error ? err.message : String(err), taskId: id }, "Trigger failed");
|
|
424
|
+
return c.json({ error: "internal_error", message: "Failed to trigger task execution." }, 500);
|
|
425
|
+
}
|
|
426
|
+
});
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
// ---------------------------------------------------------------------------
|
|
430
|
+
// GET /:id/runs — list past runs
|
|
431
|
+
// ---------------------------------------------------------------------------
|
|
432
|
+
|
|
433
|
+
scheduledTasks.get("/:id/runs", async (c) => {
|
|
434
|
+
const req = c.req.raw;
|
|
435
|
+
const requestId = crypto.randomUUID();
|
|
436
|
+
|
|
437
|
+
if (!hasInternalDB()) {
|
|
438
|
+
return c.json({ error: "not_available", message: "Scheduled tasks require an internal database." }, 404);
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
const preamble = await authPreamble(req, requestId);
|
|
442
|
+
if ("error" in preamble) {
|
|
443
|
+
return c.json(preamble.error, { status: preamble.status, headers: preamble.headers });
|
|
444
|
+
}
|
|
445
|
+
const { authResult } = preamble;
|
|
446
|
+
|
|
447
|
+
const id = c.req.param("id");
|
|
448
|
+
if (!UUID_RE.test(id)) {
|
|
449
|
+
return c.json({ error: "invalid_request", message: "Invalid task ID format." }, 400);
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
return withRequestContext({ requestId, user: authResult.user }, async () => {
|
|
453
|
+
// Verify task ownership
|
|
454
|
+
const task = await getScheduledTask(id, authResult.user?.id);
|
|
455
|
+
if (!task.ok) {
|
|
456
|
+
const fail = crudFailResponse(task.reason);
|
|
457
|
+
return c.json(fail.body, fail.status);
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
const rawLimit = parseInt(c.req.query("limit") ?? "20", 10);
|
|
461
|
+
const limit = Number.isFinite(rawLimit) && rawLimit > 0 ? Math.min(rawLimit, 100) : 20;
|
|
462
|
+
const runs = await listTaskRuns(id, { limit });
|
|
463
|
+
return c.json({ runs });
|
|
464
|
+
});
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
export { scheduledTasks };
|