@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,266 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Conversations REST routes — list, get, and delete conversations.
|
|
3
|
+
*
|
|
4
|
+
* Middleware stack follows the same auth → rate limit → withRequestContext
|
|
5
|
+
* pattern as chat.ts and query.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
|
+
listConversations,
|
|
20
|
+
getConversation,
|
|
21
|
+
deleteConversation,
|
|
22
|
+
starConversation,
|
|
23
|
+
type CrudFailReason,
|
|
24
|
+
} from "@atlas/api/lib/conversations";
|
|
25
|
+
|
|
26
|
+
const log = createLogger("conversations");
|
|
27
|
+
|
|
28
|
+
// ---------------------------------------------------------------------------
|
|
29
|
+
// Zod schemas — exported for OpenAPI spec generation
|
|
30
|
+
// ---------------------------------------------------------------------------
|
|
31
|
+
|
|
32
|
+
export const ConversationSchema = z.object({
|
|
33
|
+
id: z.string().uuid(),
|
|
34
|
+
userId: z.string().nullable(),
|
|
35
|
+
title: z.string().nullable(),
|
|
36
|
+
surface: z.enum(["web", "api", "mcp", "slack"]),
|
|
37
|
+
connectionId: z.string().nullable(),
|
|
38
|
+
starred: z.boolean(),
|
|
39
|
+
createdAt: z.string().datetime(),
|
|
40
|
+
updatedAt: z.string().datetime(),
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
export const StarConversationBodySchema = z.object({
|
|
44
|
+
starred: z.boolean(),
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
export const MessageSchema = z.object({
|
|
48
|
+
id: z.string().uuid(),
|
|
49
|
+
conversationId: z.string().uuid(),
|
|
50
|
+
role: z.enum(["user", "assistant", "system", "tool"]),
|
|
51
|
+
content: z.unknown(),
|
|
52
|
+
createdAt: z.string().datetime(),
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
export const ConversationWithMessagesSchema = ConversationSchema.extend({
|
|
56
|
+
messages: z.array(MessageSchema),
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
export const ListConversationsResponseSchema = z.object({
|
|
60
|
+
conversations: z.array(ConversationSchema),
|
|
61
|
+
total: z.number().int().nonnegative(),
|
|
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
|
+
/** Map a CrudFailReason to { body, status } for JSON responses. */
|
|
67
|
+
function crudFailResponse(reason: CrudFailReason) {
|
|
68
|
+
switch (reason) {
|
|
69
|
+
case "no_db":
|
|
70
|
+
return { body: { error: "not_available", message: "Conversation history is not available (no internal database configured)." }, status: 404 as const };
|
|
71
|
+
case "not_found":
|
|
72
|
+
return { body: { error: "not_found", message: "Conversation not found." }, status: 404 as const };
|
|
73
|
+
case "error":
|
|
74
|
+
return { body: { error: "internal_error", message: "A database error occurred. Please try again." }, status: 500 as const };
|
|
75
|
+
default: {
|
|
76
|
+
const _exhaustive: never = reason;
|
|
77
|
+
return { body: { error: "internal_error", message: `Unexpected failure: ${_exhaustive}` }, status: 500 as const };
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const conversations = new Hono();
|
|
83
|
+
|
|
84
|
+
// ---------------------------------------------------------------------------
|
|
85
|
+
// Shared auth + rate-limit preamble
|
|
86
|
+
// ---------------------------------------------------------------------------
|
|
87
|
+
|
|
88
|
+
async function authPreamble(req: Request, requestId: string) {
|
|
89
|
+
let authResult: AuthResult;
|
|
90
|
+
try {
|
|
91
|
+
authResult = await authenticateRequest(req);
|
|
92
|
+
} catch (err) {
|
|
93
|
+
log.error(
|
|
94
|
+
{ err: err instanceof Error ? err : new Error(String(err)), requestId },
|
|
95
|
+
"Auth dispatch failed",
|
|
96
|
+
);
|
|
97
|
+
return { error: { error: "auth_error", message: "Authentication system error" }, status: 500 as const };
|
|
98
|
+
}
|
|
99
|
+
if (!authResult.authenticated) {
|
|
100
|
+
log.warn({ requestId, status: authResult.status }, "Authentication failed");
|
|
101
|
+
return { error: { error: "auth_error", message: authResult.error }, status: authResult.status as 401 | 403 | 500 };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const ip = getClientIP(req);
|
|
105
|
+
const rateLimitKey = authResult.user?.id ?? (ip ? `ip:${ip}` : "anon");
|
|
106
|
+
const rateCheck = checkRateLimit(rateLimitKey);
|
|
107
|
+
if (!rateCheck.allowed) {
|
|
108
|
+
const retryAfterSeconds = Math.ceil((rateCheck.retryAfterMs ?? 60000) / 1000);
|
|
109
|
+
return {
|
|
110
|
+
error: { error: "rate_limited", message: "Too many requests. Please wait before trying again.", retryAfterSeconds },
|
|
111
|
+
status: 429 as const,
|
|
112
|
+
headers: { "Retry-After": String(retryAfterSeconds) },
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return { authResult };
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// ---------------------------------------------------------------------------
|
|
120
|
+
// GET / — list conversations
|
|
121
|
+
// ---------------------------------------------------------------------------
|
|
122
|
+
|
|
123
|
+
conversations.get("/", async (c) => {
|
|
124
|
+
const req = c.req.raw;
|
|
125
|
+
const requestId = crypto.randomUUID();
|
|
126
|
+
|
|
127
|
+
if (!hasInternalDB()) {
|
|
128
|
+
return c.json({ error: "not_available", message: "Conversation history is not available (no internal database configured)." }, 404);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const preamble = await authPreamble(req, requestId);
|
|
132
|
+
if ("error" in preamble) {
|
|
133
|
+
return c.json(preamble.error, { status: preamble.status, headers: preamble.headers });
|
|
134
|
+
}
|
|
135
|
+
const { authResult } = preamble;
|
|
136
|
+
|
|
137
|
+
return withRequestContext({ requestId, user: authResult.user }, async () => {
|
|
138
|
+
const rawLimit = parseInt(c.req.query("limit") ?? "20", 10);
|
|
139
|
+
const rawOffset = parseInt(c.req.query("offset") ?? "0", 10);
|
|
140
|
+
const limit = Number.isFinite(rawLimit) && rawLimit > 0 ? Math.min(rawLimit, 100) : 20;
|
|
141
|
+
const offset = Number.isFinite(rawOffset) && rawOffset >= 0 ? rawOffset : 0;
|
|
142
|
+
const starredParam = c.req.query("starred");
|
|
143
|
+
const starred = starredParam === "true" ? true : starredParam === "false" ? false : undefined;
|
|
144
|
+
const result = await listConversations({
|
|
145
|
+
userId: authResult.user?.id,
|
|
146
|
+
starred,
|
|
147
|
+
limit,
|
|
148
|
+
offset,
|
|
149
|
+
});
|
|
150
|
+
return c.json(result);
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
// ---------------------------------------------------------------------------
|
|
155
|
+
// GET /:id — get conversation with messages
|
|
156
|
+
// ---------------------------------------------------------------------------
|
|
157
|
+
|
|
158
|
+
conversations.get("/:id", 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: "Conversation history is not available (no internal database configured)." }, 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
|
+
const id = c.req.param("id");
|
|
173
|
+
if (!UUID_RE.test(id)) {
|
|
174
|
+
return c.json({ error: "invalid_request", message: "Invalid conversation ID format." }, 400);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return withRequestContext({ requestId, user: authResult.user }, async () => {
|
|
178
|
+
const result = await getConversation(id, authResult.user?.id);
|
|
179
|
+
if (!result.ok) {
|
|
180
|
+
const fail = crudFailResponse(result.reason);
|
|
181
|
+
return c.json(fail.body, fail.status);
|
|
182
|
+
}
|
|
183
|
+
return c.json(result.data);
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
// ---------------------------------------------------------------------------
|
|
188
|
+
// PATCH /:id/star — star or unstar a conversation
|
|
189
|
+
// ---------------------------------------------------------------------------
|
|
190
|
+
|
|
191
|
+
conversations.patch("/:id/star", async (c) => {
|
|
192
|
+
const req = c.req.raw;
|
|
193
|
+
const requestId = crypto.randomUUID();
|
|
194
|
+
|
|
195
|
+
if (!hasInternalDB()) {
|
|
196
|
+
return c.json({ error: "not_available", message: "Conversation history is not available (no internal database configured)." }, 404);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const preamble = await authPreamble(req, requestId);
|
|
200
|
+
if ("error" in preamble) {
|
|
201
|
+
return c.json(preamble.error, { status: preamble.status, headers: preamble.headers });
|
|
202
|
+
}
|
|
203
|
+
const { authResult } = preamble;
|
|
204
|
+
|
|
205
|
+
const id = c.req.param("id");
|
|
206
|
+
if (!UUID_RE.test(id)) {
|
|
207
|
+
return c.json({ error: "invalid_request", message: "Invalid conversation ID format." }, 400);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return withRequestContext({ requestId, user: authResult.user }, async () => {
|
|
211
|
+
let body: unknown;
|
|
212
|
+
try {
|
|
213
|
+
body = await req.json();
|
|
214
|
+
} catch (err) {
|
|
215
|
+
log.debug({ err: err instanceof Error ? err.message : String(err) }, "Invalid JSON body in PATCH star");
|
|
216
|
+
return c.json({ error: "invalid_request", message: "Invalid JSON body." }, 400);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const parsed = StarConversationBodySchema.safeParse(body);
|
|
220
|
+
if (!parsed.success) {
|
|
221
|
+
return c.json({ error: "invalid_request", message: "Body must contain { starred: boolean }." }, 400);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const result = await starConversation(id, parsed.data.starred, authResult.user?.id);
|
|
225
|
+
if (!result.ok) {
|
|
226
|
+
const fail = crudFailResponse(result.reason);
|
|
227
|
+
return c.json(fail.body, fail.status);
|
|
228
|
+
}
|
|
229
|
+
return c.json({ id, starred: parsed.data.starred });
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
// ---------------------------------------------------------------------------
|
|
234
|
+
// DELETE /:id — delete conversation
|
|
235
|
+
// ---------------------------------------------------------------------------
|
|
236
|
+
|
|
237
|
+
conversations.delete("/:id", async (c) => {
|
|
238
|
+
const req = c.req.raw;
|
|
239
|
+
const requestId = crypto.randomUUID();
|
|
240
|
+
|
|
241
|
+
if (!hasInternalDB()) {
|
|
242
|
+
return c.json({ error: "not_available", message: "Conversation history is not available (no internal database configured)." }, 404);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const preamble = await authPreamble(req, requestId);
|
|
246
|
+
if ("error" in preamble) {
|
|
247
|
+
return c.json(preamble.error, { status: preamble.status, headers: preamble.headers });
|
|
248
|
+
}
|
|
249
|
+
const { authResult } = preamble;
|
|
250
|
+
|
|
251
|
+
const id = c.req.param("id");
|
|
252
|
+
if (!UUID_RE.test(id)) {
|
|
253
|
+
return c.json({ error: "invalid_request", message: "Invalid conversation ID format." }, 400);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
return withRequestContext({ requestId, user: authResult.user }, async () => {
|
|
257
|
+
const result = await deleteConversation(id, authResult.user?.id);
|
|
258
|
+
if (!result.ok) {
|
|
259
|
+
const fail = crudFailResponse(result.reason);
|
|
260
|
+
return c.json(fail.body, fail.status);
|
|
261
|
+
}
|
|
262
|
+
return c.body(null, 204);
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
export { conversations };
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Health check route — public, no auth.
|
|
3
|
+
*
|
|
4
|
+
* Probes datasource, internal DB, semantic layer, explore backend,
|
|
5
|
+
* and auth mode.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { Hono } from "hono";
|
|
9
|
+
import { z } from "zod";
|
|
10
|
+
import {
|
|
11
|
+
validateEnvironment,
|
|
12
|
+
getStartupWarnings,
|
|
13
|
+
type DiagnosticError,
|
|
14
|
+
} from "@atlas/api/lib/startup";
|
|
15
|
+
import { getWhitelistedTables } from "@atlas/api/lib/semantic";
|
|
16
|
+
import { createLogger } from "@atlas/api/lib/logger";
|
|
17
|
+
import { getExploreBackendType, getActiveSandboxPluginId } from "@atlas/api/lib/tools/explore";
|
|
18
|
+
import { detectAuthMode } from "@atlas/api/lib/auth/detect";
|
|
19
|
+
import { SENSITIVE_PATTERNS } from "@atlas/api/lib/security";
|
|
20
|
+
|
|
21
|
+
const log = createLogger("health");
|
|
22
|
+
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
// Zod schemas — exported for OpenAPI spec generation
|
|
25
|
+
// ---------------------------------------------------------------------------
|
|
26
|
+
|
|
27
|
+
const CheckStatusSchema = z.enum(["ok", "error", "not_configured"]);
|
|
28
|
+
|
|
29
|
+
export const HealthResponseSchema = z.object({
|
|
30
|
+
status: z.enum(["ok", "degraded", "error"]),
|
|
31
|
+
warnings: z.array(z.string()).optional(),
|
|
32
|
+
checks: z.object({
|
|
33
|
+
datasource: z.object({
|
|
34
|
+
status: CheckStatusSchema,
|
|
35
|
+
latencyMs: z.number().int().nonnegative().optional(),
|
|
36
|
+
error: z.string().optional(),
|
|
37
|
+
}),
|
|
38
|
+
provider: z.object({
|
|
39
|
+
status: z.enum(["ok", "error"]),
|
|
40
|
+
provider: z.string(),
|
|
41
|
+
model: z.string(),
|
|
42
|
+
error: z.string().optional(),
|
|
43
|
+
}),
|
|
44
|
+
semanticLayer: z.object({
|
|
45
|
+
status: z.enum(["ok", "error"]),
|
|
46
|
+
entityCount: z.number().int().nonnegative(),
|
|
47
|
+
error: z.string().optional(),
|
|
48
|
+
}),
|
|
49
|
+
internalDb: z.object({
|
|
50
|
+
status: CheckStatusSchema,
|
|
51
|
+
latencyMs: z.number().int().nonnegative().optional(),
|
|
52
|
+
error: z.string().optional(),
|
|
53
|
+
}),
|
|
54
|
+
explore: z.object({
|
|
55
|
+
backend: z.enum(["nsjail", "sidecar", "vercel-sandbox", "just-bash", "plugin"]),
|
|
56
|
+
isolated: z.boolean(),
|
|
57
|
+
isolationVerified: z.boolean().optional(),
|
|
58
|
+
pluginId: z.string().optional(),
|
|
59
|
+
}),
|
|
60
|
+
auth: z.object({
|
|
61
|
+
mode: z.enum(["none", "simple-key", "managed", "byot"]),
|
|
62
|
+
enabled: z.boolean(),
|
|
63
|
+
error: z.string().optional(),
|
|
64
|
+
}),
|
|
65
|
+
slack: z.object({
|
|
66
|
+
enabled: z.boolean(),
|
|
67
|
+
mode: z.enum(["disabled", "single-workspace", "oauth"]),
|
|
68
|
+
}),
|
|
69
|
+
}),
|
|
70
|
+
sources: z.record(z.string(), z.object({
|
|
71
|
+
status: z.enum(["healthy", "degraded", "unhealthy", "unknown"]),
|
|
72
|
+
latencyMs: z.number().int().nonnegative().optional(),
|
|
73
|
+
message: z.string().optional(),
|
|
74
|
+
checkedAt: z.string().optional(),
|
|
75
|
+
dbType: z.string(),
|
|
76
|
+
})).optional(),
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
function findDiagnostic(
|
|
80
|
+
diagnostics: DiagnosticError[],
|
|
81
|
+
...codes: DiagnosticError["code"][]
|
|
82
|
+
): DiagnosticError | undefined {
|
|
83
|
+
return diagnostics.find((d) => codes.includes(d.code));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const health = new Hono();
|
|
87
|
+
|
|
88
|
+
health.get("/", async (c) => {
|
|
89
|
+
try {
|
|
90
|
+
const diagnostics = await validateEnvironment();
|
|
91
|
+
|
|
92
|
+
// Probe datasource with SELECT 1 — this is the authoritative real-time check.
|
|
93
|
+
// Check both the env var and the ConnectionRegistry (a default datasource may
|
|
94
|
+
// be configured via atlas.config.ts without ATLAS_DATASOURCE_URL).
|
|
95
|
+
let dsLatencyMs: number | undefined;
|
|
96
|
+
let dsProbeError: string | undefined;
|
|
97
|
+
const { connections: connRegistry2, detectDBType, getDB } = await import("@atlas/api/lib/db/connection");
|
|
98
|
+
const hasDatasource = !!process.env.ATLAS_DATASOURCE_URL || connRegistry2.list().includes("default");
|
|
99
|
+
if (hasDatasource) {
|
|
100
|
+
try {
|
|
101
|
+
const dbType = detectDBType();
|
|
102
|
+
|
|
103
|
+
if (dbType === "salesforce") {
|
|
104
|
+
const { getSalesforceSource, listSalesforceSources } = await import("@atlas/api/lib/db/salesforce");
|
|
105
|
+
const sourceId = listSalesforceSources()[0] ?? "default";
|
|
106
|
+
const start = performance.now();
|
|
107
|
+
await getSalesforceSource(sourceId).listObjects();
|
|
108
|
+
dsLatencyMs = Math.round(performance.now() - start);
|
|
109
|
+
} else {
|
|
110
|
+
const start = performance.now();
|
|
111
|
+
await getDB().query("SELECT 1", 5000);
|
|
112
|
+
dsLatencyMs = Math.round(performance.now() - start);
|
|
113
|
+
}
|
|
114
|
+
} catch (err) {
|
|
115
|
+
log.error(
|
|
116
|
+
{ err: err instanceof Error ? err : new Error(String(err)) },
|
|
117
|
+
"Health check datasource probe failed",
|
|
118
|
+
);
|
|
119
|
+
dsProbeError = "Datasource query failed";
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Probe internal DB with SELECT 1
|
|
124
|
+
let internalLatencyMs: number | undefined;
|
|
125
|
+
let internalProbeError: string | undefined;
|
|
126
|
+
if (process.env.DATABASE_URL) {
|
|
127
|
+
try {
|
|
128
|
+
const { getInternalDB } = await import("@atlas/api/lib/db/internal");
|
|
129
|
+
const pool = getInternalDB();
|
|
130
|
+
const start = performance.now();
|
|
131
|
+
await pool.query("SELECT 1");
|
|
132
|
+
internalLatencyMs = Math.round(performance.now() - start);
|
|
133
|
+
} catch (err) {
|
|
134
|
+
log.error(
|
|
135
|
+
{ err: err instanceof Error ? err : new Error(String(err)) },
|
|
136
|
+
"Health check internal DB probe failed",
|
|
137
|
+
);
|
|
138
|
+
internalProbeError = "Internal DB query failed";
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const provider = process.env.ATLAS_PROVIDER ?? "anthropic";
|
|
143
|
+
const entityCount = getWhitelistedTables().size;
|
|
144
|
+
const exploreBackend = getExploreBackendType();
|
|
145
|
+
const authMode = detectAuthMode();
|
|
146
|
+
|
|
147
|
+
// Datasource is unhealthy if: no URL, diagnostics flagged it, OR the live probe failed
|
|
148
|
+
const dsDiagnostic = findDiagnostic(
|
|
149
|
+
diagnostics,
|
|
150
|
+
"MISSING_DATASOURCE_URL",
|
|
151
|
+
"DB_UNREACHABLE",
|
|
152
|
+
);
|
|
153
|
+
const hasDsError = !!dsDiagnostic || !!dsProbeError;
|
|
154
|
+
const dsNotConfigured = !hasDatasource;
|
|
155
|
+
const hasKeyError = !!findDiagnostic(diagnostics, "MISSING_API_KEY");
|
|
156
|
+
const hasSemanticError = !!findDiagnostic(
|
|
157
|
+
diagnostics,
|
|
158
|
+
"MISSING_SEMANTIC_LAYER",
|
|
159
|
+
);
|
|
160
|
+
const hasInternalDbError =
|
|
161
|
+
!!findDiagnostic(diagnostics, "INTERNAL_DB_UNREACHABLE") ||
|
|
162
|
+
!!internalProbeError;
|
|
163
|
+
const authDiagnostic = findDiagnostic(
|
|
164
|
+
diagnostics,
|
|
165
|
+
"WEAK_AUTH_SECRET",
|
|
166
|
+
"INVALID_JWKS_URL",
|
|
167
|
+
"MISSING_AUTH_ISSUER",
|
|
168
|
+
);
|
|
169
|
+
const hasAuthError = !!authDiagnostic;
|
|
170
|
+
|
|
171
|
+
let status: "ok" | "degraded" | "error";
|
|
172
|
+
if (hasDsError && !dsNotConfigured) status = "error";
|
|
173
|
+
else if (
|
|
174
|
+
dsNotConfigured ||
|
|
175
|
+
hasKeyError ||
|
|
176
|
+
hasSemanticError ||
|
|
177
|
+
hasInternalDbError ||
|
|
178
|
+
hasAuthError
|
|
179
|
+
)
|
|
180
|
+
status = "degraded";
|
|
181
|
+
else status = "ok";
|
|
182
|
+
|
|
183
|
+
const warnings = getStartupWarnings();
|
|
184
|
+
|
|
185
|
+
// Per-source health from ConnectionRegistry
|
|
186
|
+
let sourcesSection: Record<string, { status: string; latencyMs?: number; message?: string; checkedAt?: string; dbType: string }> | undefined;
|
|
187
|
+
try {
|
|
188
|
+
const connMeta = connRegistry2.describe();
|
|
189
|
+
if (connMeta.length > 0) {
|
|
190
|
+
sourcesSection = {};
|
|
191
|
+
for (const meta of connMeta) {
|
|
192
|
+
const h = meta.health;
|
|
193
|
+
// Scrub health messages that might contain connection credentials or internal state
|
|
194
|
+
const safeMessage = h?.message && !SENSITIVE_PATTERNS.test(h.message)
|
|
195
|
+
? h.message
|
|
196
|
+
: h?.message ? "Health check failed — check server logs for details." : undefined;
|
|
197
|
+
sourcesSection[meta.id] = {
|
|
198
|
+
status: h?.status ?? "unknown",
|
|
199
|
+
...(h?.latencyMs !== undefined ? { latencyMs: h.latencyMs } : {}),
|
|
200
|
+
...(safeMessage ? { message: safeMessage } : {}),
|
|
201
|
+
...(h?.checkedAt ? { checkedAt: h.checkedAt.toISOString() } : {}),
|
|
202
|
+
dbType: meta.dbType,
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// Promote overall status based on source health
|
|
207
|
+
const hasUnhealthy = connMeta.some((m) => m.health?.status === "unhealthy");
|
|
208
|
+
const hasDegraded = connMeta.some((m) => m.health?.status === "degraded");
|
|
209
|
+
if (hasUnhealthy && status !== "error") status = "error";
|
|
210
|
+
else if (hasDegraded && status === "ok") status = "degraded";
|
|
211
|
+
}
|
|
212
|
+
} catch (err) {
|
|
213
|
+
log.warn(
|
|
214
|
+
{ err: err instanceof Error ? err.message : String(err) },
|
|
215
|
+
"Failed to collect per-source health — sources section omitted",
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const response = {
|
|
220
|
+
status,
|
|
221
|
+
...(warnings.length > 0 && { warnings }),
|
|
222
|
+
checks: {
|
|
223
|
+
datasource: dsNotConfigured
|
|
224
|
+
? { status: "not_configured" as const }
|
|
225
|
+
: {
|
|
226
|
+
status: hasDsError ? "error" : "ok",
|
|
227
|
+
...(dsLatencyMs !== undefined && { latencyMs: dsLatencyMs }),
|
|
228
|
+
...(hasDsError && {
|
|
229
|
+
error: dsProbeError ?? dsDiagnostic?.code ?? "DB_UNREACHABLE",
|
|
230
|
+
}),
|
|
231
|
+
},
|
|
232
|
+
provider: {
|
|
233
|
+
status: hasKeyError ? "error" : "ok",
|
|
234
|
+
provider,
|
|
235
|
+
model: process.env.ATLAS_MODEL ?? "(default)",
|
|
236
|
+
...(hasKeyError && { error: "MISSING_API_KEY" }),
|
|
237
|
+
},
|
|
238
|
+
semanticLayer: {
|
|
239
|
+
status: hasSemanticError ? "error" : "ok",
|
|
240
|
+
entityCount,
|
|
241
|
+
...(hasSemanticError && { error: "MISSING_SEMANTIC_LAYER" }),
|
|
242
|
+
},
|
|
243
|
+
internalDb: !process.env.DATABASE_URL
|
|
244
|
+
? { status: "not_configured" as const }
|
|
245
|
+
: {
|
|
246
|
+
status: hasInternalDbError ? "error" : "ok",
|
|
247
|
+
...(internalLatencyMs !== undefined && {
|
|
248
|
+
latencyMs: internalLatencyMs,
|
|
249
|
+
}),
|
|
250
|
+
...(hasInternalDbError && {
|
|
251
|
+
error: internalProbeError ?? "INTERNAL_DB_UNREACHABLE",
|
|
252
|
+
}),
|
|
253
|
+
},
|
|
254
|
+
explore: {
|
|
255
|
+
backend: exploreBackend,
|
|
256
|
+
isolated: exploreBackend !== "just-bash",
|
|
257
|
+
...(exploreBackend === "plugin" && { isolationVerified: false }),
|
|
258
|
+
...(exploreBackend === "plugin" && getActiveSandboxPluginId() ? { pluginId: getActiveSandboxPluginId() } : {}),
|
|
259
|
+
},
|
|
260
|
+
auth: {
|
|
261
|
+
mode: authMode,
|
|
262
|
+
enabled: authMode !== "none",
|
|
263
|
+
...(hasAuthError && { error: authDiagnostic!.code }),
|
|
264
|
+
},
|
|
265
|
+
slack: {
|
|
266
|
+
enabled: !!process.env.SLACK_SIGNING_SECRET,
|
|
267
|
+
mode: !process.env.SLACK_SIGNING_SECRET
|
|
268
|
+
? ("disabled" as const)
|
|
269
|
+
: process.env.SLACK_CLIENT_ID
|
|
270
|
+
? ("oauth" as const)
|
|
271
|
+
: ("single-workspace" as const),
|
|
272
|
+
},
|
|
273
|
+
},
|
|
274
|
+
...(sourcesSection ? { sources: sourcesSection } : {}),
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
return c.json(response, response.status === "error" ? 503 : 200);
|
|
278
|
+
} catch (err) {
|
|
279
|
+
log.error(
|
|
280
|
+
{ err: err instanceof Error ? err : new Error(String(err)) },
|
|
281
|
+
"Health endpoint unexpected error",
|
|
282
|
+
);
|
|
283
|
+
return c.json({ status: "error", error: "health_check_failed" }, 503);
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
export { health };
|