@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,256 @@
|
|
|
1
|
+
import { describe, it, expect } from "bun:test";
|
|
2
|
+
import {
|
|
3
|
+
parseChatError,
|
|
4
|
+
authErrorMessage,
|
|
5
|
+
} from "@atlas/api/lib/errors";
|
|
6
|
+
|
|
7
|
+
/* ------------------------------------------------------------------ */
|
|
8
|
+
/* Helpers */
|
|
9
|
+
/* ------------------------------------------------------------------ */
|
|
10
|
+
|
|
11
|
+
/** Build an Error whose .message is a JSON string (mimics AI SDK chat errors). */
|
|
12
|
+
function jsonError(body: Record<string, unknown>): Error {
|
|
13
|
+
return new Error(JSON.stringify(body));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/* ------------------------------------------------------------------ */
|
|
17
|
+
/* parseChatError */
|
|
18
|
+
/* ------------------------------------------------------------------ */
|
|
19
|
+
|
|
20
|
+
describe("parseChatError", () => {
|
|
21
|
+
// 1. Non-JSON fallback
|
|
22
|
+
it("returns generic fallback when error.message is not JSON", () => {
|
|
23
|
+
const info = parseChatError(new Error("network timeout"), "none");
|
|
24
|
+
expect(info.title).toBe("Something went wrong. Please try again.");
|
|
25
|
+
expect(info.code).toBeUndefined();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
// 2–5. auth_error × each auth mode
|
|
29
|
+
it("auth_error + simple-key → API key message", () => {
|
|
30
|
+
const info = parseChatError(jsonError({ error: "auth_error" }), "simple-key");
|
|
31
|
+
expect(info.title).toContain("API key");
|
|
32
|
+
expect(info.code).toBe("auth_error");
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("auth_error + managed → session expired message", () => {
|
|
36
|
+
const info = parseChatError(jsonError({ error: "auth_error" }), "managed");
|
|
37
|
+
expect(info.title).toContain("sign in");
|
|
38
|
+
expect(info.code).toBe("auth_error");
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("auth_error + byot → token expired message", () => {
|
|
42
|
+
const info = parseChatError(jsonError({ error: "auth_error" }), "byot");
|
|
43
|
+
expect(info.title).toContain("token");
|
|
44
|
+
expect(info.code).toBe("auth_error");
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("auth_error + none → unexpected auth error message", () => {
|
|
48
|
+
const info = parseChatError(jsonError({ error: "auth_error" }), "none");
|
|
49
|
+
expect(info.title).toContain("unexpected");
|
|
50
|
+
expect(info.code).toBe("auth_error");
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// 6. rate_limited WITH retryAfterSeconds
|
|
54
|
+
it("rate_limited with retryAfterSeconds → includes countdown", () => {
|
|
55
|
+
const info = parseChatError(
|
|
56
|
+
jsonError({ error: "rate_limited", retryAfterSeconds: 30 }),
|
|
57
|
+
"none",
|
|
58
|
+
);
|
|
59
|
+
expect(info.title).toBe("Too many requests.");
|
|
60
|
+
expect(info.detail).toContain("30 seconds");
|
|
61
|
+
expect(info.retryAfterSeconds).toBe(30);
|
|
62
|
+
expect(info.code).toBe("rate_limited");
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// 7. rate_limited WITHOUT retryAfterSeconds
|
|
66
|
+
it("rate_limited without retryAfterSeconds → generic wait message", () => {
|
|
67
|
+
const info = parseChatError(
|
|
68
|
+
jsonError({ error: "rate_limited" }),
|
|
69
|
+
"none",
|
|
70
|
+
);
|
|
71
|
+
expect(info.title).toBe("Too many requests.");
|
|
72
|
+
expect(info.detail).toBe("Please wait before trying again.");
|
|
73
|
+
expect(info.retryAfterSeconds).toBeUndefined();
|
|
74
|
+
expect(info.code).toBe("rate_limited");
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// 8. rate_limited with negative retryAfterSeconds → clamped to 0
|
|
78
|
+
it("rate_limited with negative retryAfterSeconds → clamped to 0", () => {
|
|
79
|
+
const info = parseChatError(
|
|
80
|
+
jsonError({ error: "rate_limited", retryAfterSeconds: -5 }),
|
|
81
|
+
"none",
|
|
82
|
+
);
|
|
83
|
+
expect(info.retryAfterSeconds).toBe(0);
|
|
84
|
+
expect(info.detail).toContain("0 seconds");
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// 9. rate_limited with very large retryAfterSeconds → clamped to 300
|
|
88
|
+
it("rate_limited with huge retryAfterSeconds → clamped to 300", () => {
|
|
89
|
+
const info = parseChatError(
|
|
90
|
+
jsonError({ error: "rate_limited", retryAfterSeconds: 9999 }),
|
|
91
|
+
"none",
|
|
92
|
+
);
|
|
93
|
+
expect(info.retryAfterSeconds).toBe(300);
|
|
94
|
+
expect(info.detail).toContain("300 seconds");
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// 10. configuration_error
|
|
98
|
+
it("configuration_error → includes server message as detail", () => {
|
|
99
|
+
const info = parseChatError(
|
|
100
|
+
jsonError({ error: "configuration_error", message: "Missing API key" }),
|
|
101
|
+
"none",
|
|
102
|
+
);
|
|
103
|
+
expect(info.title).toBe("Atlas is not fully configured.");
|
|
104
|
+
expect(info.detail).toBe("Missing API key");
|
|
105
|
+
expect(info.code).toBe("configuration_error");
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
// 11. no_datasource
|
|
109
|
+
it("no_datasource → correct title", () => {
|
|
110
|
+
const info = parseChatError(
|
|
111
|
+
jsonError({ error: "no_datasource" }),
|
|
112
|
+
"none",
|
|
113
|
+
);
|
|
114
|
+
expect(info.title).toBe("No data source configured.");
|
|
115
|
+
expect(info.code).toBe("no_datasource");
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
// 12. invalid_request
|
|
119
|
+
it("invalid_request → correct title", () => {
|
|
120
|
+
const info = parseChatError(
|
|
121
|
+
jsonError({ error: "invalid_request" }),
|
|
122
|
+
"none",
|
|
123
|
+
);
|
|
124
|
+
expect(info.title).toBe("Invalid request.");
|
|
125
|
+
expect(info.code).toBe("invalid_request");
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
// 13. provider_model_not_found
|
|
129
|
+
it("provider_model_not_found → correct title", () => {
|
|
130
|
+
const info = parseChatError(
|
|
131
|
+
jsonError({ error: "provider_model_not_found" }),
|
|
132
|
+
"none",
|
|
133
|
+
);
|
|
134
|
+
expect(info.title).toBe("The configured AI model was not found.");
|
|
135
|
+
expect(info.code).toBe("provider_model_not_found");
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
// 14. provider_auth_error
|
|
139
|
+
it("provider_auth_error → correct title", () => {
|
|
140
|
+
const info = parseChatError(
|
|
141
|
+
jsonError({ error: "provider_auth_error", message: "Bad credentials" }),
|
|
142
|
+
"none",
|
|
143
|
+
);
|
|
144
|
+
expect(info.title).toBe("The AI provider could not authenticate.");
|
|
145
|
+
expect(info.detail).toBe("Bad credentials");
|
|
146
|
+
expect(info.code).toBe("provider_auth_error");
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
// 15. provider_rate_limit
|
|
150
|
+
it("provider_rate_limit → correct title", () => {
|
|
151
|
+
const info = parseChatError(
|
|
152
|
+
jsonError({ error: "provider_rate_limit" }),
|
|
153
|
+
"none",
|
|
154
|
+
);
|
|
155
|
+
expect(info.title).toBe("The AI provider is rate limiting requests.");
|
|
156
|
+
expect(info.code).toBe("provider_rate_limit");
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
// 16. provider_timeout
|
|
160
|
+
it("provider_timeout → correct title", () => {
|
|
161
|
+
const info = parseChatError(
|
|
162
|
+
jsonError({ error: "provider_timeout" }),
|
|
163
|
+
"none",
|
|
164
|
+
);
|
|
165
|
+
expect(info.title).toBe("The AI provider timed out.");
|
|
166
|
+
expect(info.code).toBe("provider_timeout");
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
// 17. provider_unreachable
|
|
170
|
+
it("provider_unreachable → correct title", () => {
|
|
171
|
+
const info = parseChatError(
|
|
172
|
+
jsonError({ error: "provider_unreachable" }),
|
|
173
|
+
"none",
|
|
174
|
+
);
|
|
175
|
+
expect(info.title).toBe("Could not reach the AI provider.");
|
|
176
|
+
expect(info.code).toBe("provider_unreachable");
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
// 18. internal_error with message
|
|
180
|
+
it("internal_error with message → passes through server message", () => {
|
|
181
|
+
const info = parseChatError(
|
|
182
|
+
jsonError({ error: "internal_error", message: "DB pool exhausted" }),
|
|
183
|
+
"none",
|
|
184
|
+
);
|
|
185
|
+
expect(info.title).toBe("DB pool exhausted");
|
|
186
|
+
expect(info.code).toBe("internal_error");
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
// 19. internal_error without message
|
|
190
|
+
it("internal_error without message → generic fallback", () => {
|
|
191
|
+
const info = parseChatError(
|
|
192
|
+
jsonError({ error: "internal_error" }),
|
|
193
|
+
"none",
|
|
194
|
+
);
|
|
195
|
+
expect(info.title).toBe("An unexpected error occurred.");
|
|
196
|
+
expect(info.code).toBe("internal_error");
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
// 20. Unknown code with message
|
|
200
|
+
it("unknown code with message → passes through server message", () => {
|
|
201
|
+
const info = parseChatError(
|
|
202
|
+
jsonError({ error: "something_new", message: "New error type" }),
|
|
203
|
+
"none",
|
|
204
|
+
);
|
|
205
|
+
expect(info.title).toBe("New error type");
|
|
206
|
+
expect(info.code).toBeUndefined();
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
// 21. Unknown code without message
|
|
210
|
+
it("unknown code without message → generic fallback", () => {
|
|
211
|
+
const info = parseChatError(
|
|
212
|
+
jsonError({ error: "something_new" }),
|
|
213
|
+
"none",
|
|
214
|
+
);
|
|
215
|
+
expect(info.title).toBe("Something went wrong. Please try again.");
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
// 22. Valid JSON but error field is not a string
|
|
219
|
+
it("error field is a number → default case", () => {
|
|
220
|
+
const info = parseChatError(
|
|
221
|
+
jsonError({ error: 42, message: "Unexpected" }),
|
|
222
|
+
"none",
|
|
223
|
+
);
|
|
224
|
+
expect(info.title).toBe("Unexpected");
|
|
225
|
+
expect(info.code).toBeUndefined();
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
// 23. Valid JSON but empty object
|
|
229
|
+
it("empty JSON object → default case", () => {
|
|
230
|
+
const info = parseChatError(jsonError({}), "none");
|
|
231
|
+
expect(info.title).toBe("Something went wrong. Please try again.");
|
|
232
|
+
expect(info.code).toBeUndefined();
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
/* ------------------------------------------------------------------ */
|
|
237
|
+
/* authErrorMessage */
|
|
238
|
+
/* ------------------------------------------------------------------ */
|
|
239
|
+
|
|
240
|
+
describe("authErrorMessage", () => {
|
|
241
|
+
it("simple-key → mentions API key", () => {
|
|
242
|
+
expect(authErrorMessage("simple-key")).toContain("API key");
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
it("managed → mentions sign in", () => {
|
|
246
|
+
expect(authErrorMessage("managed")).toContain("sign in");
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
it("byot → mentions token", () => {
|
|
250
|
+
expect(authErrorMessage("byot")).toContain("token");
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
it("none → mentions unexpected", () => {
|
|
254
|
+
expect(authErrorMessage("none")).toContain("unexpected");
|
|
255
|
+
});
|
|
256
|
+
});
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { Writable } from "stream";
|
|
3
|
+
import pino from "pino";
|
|
4
|
+
import {
|
|
5
|
+
getLogger,
|
|
6
|
+
createLogger,
|
|
7
|
+
withRequestContext,
|
|
8
|
+
getRequestContext,
|
|
9
|
+
redactPaths,
|
|
10
|
+
} from "../logger";
|
|
11
|
+
|
|
12
|
+
describe("logger", () => {
|
|
13
|
+
test("getLogger returns a pino logger with expected methods", () => {
|
|
14
|
+
const log = getLogger();
|
|
15
|
+
expect(typeof log.info).toBe("function");
|
|
16
|
+
expect(typeof log.error).toBe("function");
|
|
17
|
+
expect(typeof log.warn).toBe("function");
|
|
18
|
+
expect(typeof log.debug).toBe("function");
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test("createLogger returns a child logger with component binding", () => {
|
|
22
|
+
const log = createLogger("test-component");
|
|
23
|
+
expect(typeof log.info).toBe("function");
|
|
24
|
+
const bindings = log.bindings();
|
|
25
|
+
expect(bindings.component).toBe("test-component");
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test("withRequestContext makes requestId available via getRequestContext", () => {
|
|
29
|
+
const requestId = "test-request-123";
|
|
30
|
+
|
|
31
|
+
withRequestContext({ requestId }, () => {
|
|
32
|
+
const ctx = getRequestContext();
|
|
33
|
+
expect(ctx).toBeDefined();
|
|
34
|
+
expect(ctx!.requestId).toBe(requestId);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test("getLogger outside request context returns root logger", () => {
|
|
39
|
+
const log = getLogger();
|
|
40
|
+
const bindings = log.bindings();
|
|
41
|
+
expect(bindings.requestId).toBeUndefined();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test("getRequestContext returns undefined outside context", () => {
|
|
45
|
+
const ctx = getRequestContext();
|
|
46
|
+
expect(ctx).toBeUndefined();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test("mixin injects requestId into log output within withRequestContext", () => {
|
|
50
|
+
const requestId = "mixin-test-456";
|
|
51
|
+
|
|
52
|
+
// Create a pino logger that mimics the module's mixin, writing to a stream
|
|
53
|
+
const chunks: Buffer[] = [];
|
|
54
|
+
const stream = new Writable({
|
|
55
|
+
write(chunk: Buffer, _encoding: string, cb: () => void) {
|
|
56
|
+
chunks.push(chunk);
|
|
57
|
+
cb();
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const testLogger = pino(
|
|
62
|
+
{
|
|
63
|
+
level: "info",
|
|
64
|
+
mixin() {
|
|
65
|
+
const ctx = getRequestContext();
|
|
66
|
+
return ctx ? { requestId: ctx.requestId } : {};
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
stream,
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
// Outside context — no requestId
|
|
73
|
+
testLogger.info({ msg: "no-context" });
|
|
74
|
+
const outsideParsed = JSON.parse(Buffer.concat(chunks).toString());
|
|
75
|
+
expect(outsideParsed.requestId).toBeUndefined();
|
|
76
|
+
|
|
77
|
+
// Inside context — requestId injected by mixin
|
|
78
|
+
chunks.length = 0;
|
|
79
|
+
withRequestContext({ requestId }, () => {
|
|
80
|
+
testLogger.info({ msg: "with-context" });
|
|
81
|
+
});
|
|
82
|
+
const insideParsed = JSON.parse(Buffer.concat(chunks).toString());
|
|
83
|
+
expect(insideParsed.requestId).toBe(requestId);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test("withRequestContext propagates user to getRequestContext", () => {
|
|
87
|
+
const user = { id: "test-user-id", mode: "simple-key" as const, label: "api-key-test" };
|
|
88
|
+
withRequestContext({ requestId: "req-123", user }, () => {
|
|
89
|
+
const ctx = getRequestContext();
|
|
90
|
+
expect(ctx).toBeDefined();
|
|
91
|
+
expect(ctx!.user).toEqual(user);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test("mixin injects userId and authMode when user is present in context", () => {
|
|
96
|
+
const chunks: Buffer[] = [];
|
|
97
|
+
const stream = new Writable({
|
|
98
|
+
write(chunk: Buffer, _encoding: string, cb: () => void) {
|
|
99
|
+
chunks.push(chunk);
|
|
100
|
+
cb();
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
const testLogger = pino(
|
|
105
|
+
{
|
|
106
|
+
level: "info",
|
|
107
|
+
mixin() {
|
|
108
|
+
const ctx = getRequestContext();
|
|
109
|
+
if (!ctx) return {};
|
|
110
|
+
const base: Record<string, unknown> = { requestId: ctx.requestId };
|
|
111
|
+
if (ctx.user) {
|
|
112
|
+
base.userId = ctx.user.id;
|
|
113
|
+
base.authMode = ctx.user.mode;
|
|
114
|
+
}
|
|
115
|
+
return base;
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
stream,
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
const user = { id: "api-key-abc12345", mode: "simple-key" as const, label: "api-key-sk-t" };
|
|
122
|
+
withRequestContext({ requestId: "req-with-user", user }, () => {
|
|
123
|
+
testLogger.info("authenticated request");
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
const parsed = JSON.parse(Buffer.concat(chunks).toString());
|
|
127
|
+
expect(parsed.requestId).toBe("req-with-user");
|
|
128
|
+
expect(parsed.userId).toBe("api-key-abc12345");
|
|
129
|
+
expect(parsed.authMode).toBe("simple-key");
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test("redaction replaces sensitive fields with [Redacted]", () => {
|
|
133
|
+
// Create a test logger with equivalent redact paths (object form for explicit censor assertion)
|
|
134
|
+
const chunks: Buffer[] = [];
|
|
135
|
+
const stream = new Writable({
|
|
136
|
+
write(chunk: Buffer, _encoding: string, cb: () => void) {
|
|
137
|
+
chunks.push(chunk);
|
|
138
|
+
cb();
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
const testLogger = pino(
|
|
143
|
+
{
|
|
144
|
+
level: "info",
|
|
145
|
+
redact: { paths: redactPaths, censor: "[Redacted]" },
|
|
146
|
+
},
|
|
147
|
+
stream,
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
testLogger.info({
|
|
151
|
+
msg: "connection attempt",
|
|
152
|
+
password: "super-secret-pw",
|
|
153
|
+
apiKey: "sk-ant-key-12345",
|
|
154
|
+
connectionString: "postgresql://user:pass@host/db",
|
|
155
|
+
safe: "this-should-remain",
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
const output = Buffer.concat(chunks).toString();
|
|
159
|
+
const parsed = JSON.parse(output);
|
|
160
|
+
|
|
161
|
+
expect(parsed.password).toBe("[Redacted]");
|
|
162
|
+
expect(parsed.apiKey).toBe("[Redacted]");
|
|
163
|
+
expect(parsed.connectionString).toBe("[Redacted]");
|
|
164
|
+
expect(parsed.safe).toBe("this-should-remain");
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
test("redaction works for nested fields", () => {
|
|
168
|
+
const chunks: Buffer[] = [];
|
|
169
|
+
const stream = new Writable({
|
|
170
|
+
write(chunk: Buffer, _encoding: string, cb: () => void) {
|
|
171
|
+
chunks.push(chunk);
|
|
172
|
+
cb();
|
|
173
|
+
},
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
const testLogger = pino(
|
|
177
|
+
{
|
|
178
|
+
level: "info",
|
|
179
|
+
redact: { paths: redactPaths, censor: "[Redacted]" },
|
|
180
|
+
},
|
|
181
|
+
stream,
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
testLogger.info({
|
|
185
|
+
msg: "nested secret test",
|
|
186
|
+
config: {
|
|
187
|
+
password: "nested-secret",
|
|
188
|
+
apiKey: "nested-key",
|
|
189
|
+
safe: "visible",
|
|
190
|
+
},
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
const output = Buffer.concat(chunks).toString();
|
|
194
|
+
const parsed = JSON.parse(output);
|
|
195
|
+
|
|
196
|
+
expect(parsed.config.password).toBe("[Redacted]");
|
|
197
|
+
expect(parsed.config.apiKey).toBe("[Redacted]");
|
|
198
|
+
expect(parsed.config.safe).toBe("visible");
|
|
199
|
+
});
|
|
200
|
+
});
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { describe, expect, test, afterEach } from "bun:test";
|
|
2
|
+
|
|
3
|
+
// Import after mocks — getProviderType reads process.env at call time, so no
|
|
4
|
+
// module-level mocking is needed.
|
|
5
|
+
const { getProviderType } = await import("@atlas/api/lib/providers");
|
|
6
|
+
|
|
7
|
+
// ---------------------------------------------------------------------------
|
|
8
|
+
// Env snapshot — capture/restore only the vars this test touches
|
|
9
|
+
// ---------------------------------------------------------------------------
|
|
10
|
+
|
|
11
|
+
const origProvider = process.env.ATLAS_PROVIDER;
|
|
12
|
+
const origModel = process.env.ATLAS_MODEL;
|
|
13
|
+
|
|
14
|
+
afterEach(() => {
|
|
15
|
+
if (origProvider !== undefined) process.env.ATLAS_PROVIDER = origProvider;
|
|
16
|
+
else delete process.env.ATLAS_PROVIDER;
|
|
17
|
+
|
|
18
|
+
if (origModel !== undefined) process.env.ATLAS_MODEL = origModel;
|
|
19
|
+
else delete process.env.ATLAS_MODEL;
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// ---------------------------------------------------------------------------
|
|
23
|
+
// Tests
|
|
24
|
+
// ---------------------------------------------------------------------------
|
|
25
|
+
|
|
26
|
+
describe("getProviderType", () => {
|
|
27
|
+
test("defaults to 'anthropic' when no env vars are set", () => {
|
|
28
|
+
delete process.env.ATLAS_PROVIDER;
|
|
29
|
+
delete process.env.ATLAS_MODEL;
|
|
30
|
+
expect(getProviderType()).toBe("anthropic");
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test("returns 'anthropic' when ATLAS_PROVIDER=anthropic", () => {
|
|
34
|
+
process.env.ATLAS_PROVIDER = "anthropic";
|
|
35
|
+
delete process.env.ATLAS_MODEL;
|
|
36
|
+
expect(getProviderType()).toBe("anthropic");
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test("returns 'openai' when ATLAS_PROVIDER=openai", () => {
|
|
40
|
+
process.env.ATLAS_PROVIDER = "openai";
|
|
41
|
+
expect(getProviderType()).toBe("openai");
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test("returns 'ollama' when ATLAS_PROVIDER=ollama", () => {
|
|
45
|
+
process.env.ATLAS_PROVIDER = "ollama";
|
|
46
|
+
expect(getProviderType()).toBe("ollama");
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test("returns 'gateway' when ATLAS_PROVIDER=gateway", () => {
|
|
50
|
+
process.env.ATLAS_PROVIDER = "gateway";
|
|
51
|
+
expect(getProviderType()).toBe("gateway");
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// --- Bedrock variants ---------------------------------------------------
|
|
55
|
+
|
|
56
|
+
test("returns 'bedrock-anthropic' for bedrock with anthropic.claude model", () => {
|
|
57
|
+
process.env.ATLAS_PROVIDER = "bedrock";
|
|
58
|
+
process.env.ATLAS_MODEL = "anthropic.claude-opus-4-6-v1:0";
|
|
59
|
+
expect(getProviderType()).toBe("bedrock-anthropic");
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test("returns 'bedrock-anthropic' for bedrock with cross-region anthropic model", () => {
|
|
63
|
+
process.env.ATLAS_PROVIDER = "bedrock";
|
|
64
|
+
process.env.ATLAS_MODEL = "us.anthropic.claude-3-7-sonnet-20250219-v1:0";
|
|
65
|
+
expect(getProviderType()).toBe("bedrock-anthropic");
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test("returns 'bedrock' for bedrock with non-anthropic model", () => {
|
|
69
|
+
process.env.ATLAS_PROVIDER = "bedrock";
|
|
70
|
+
process.env.ATLAS_MODEL = "amazon.nova-pro-v1:0";
|
|
71
|
+
expect(getProviderType()).toBe("bedrock");
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test("returns 'bedrock-anthropic' for bedrock with default model (no ATLAS_MODEL)", () => {
|
|
75
|
+
process.env.ATLAS_PROVIDER = "bedrock";
|
|
76
|
+
delete process.env.ATLAS_MODEL;
|
|
77
|
+
// Default bedrock model is anthropic.claude-opus-4-6-v1:0, which contains "anthropic"
|
|
78
|
+
expect(getProviderType()).toBe("bedrock-anthropic");
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test("returns 'bedrock-anthropic' for bedrock with claude model (no 'anthropic' in ID)", () => {
|
|
82
|
+
process.env.ATLAS_PROVIDER = "bedrock";
|
|
83
|
+
process.env.ATLAS_MODEL = "claude-3-opus-20240229";
|
|
84
|
+
expect(getProviderType()).toBe("bedrock-anthropic");
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test("returns 'bedrock' for bedrock with meta llama model", () => {
|
|
88
|
+
process.env.ATLAS_PROVIDER = "bedrock";
|
|
89
|
+
process.env.ATLAS_MODEL = "meta.llama3-1-70b-instruct-v1:0";
|
|
90
|
+
expect(getProviderType()).toBe("bedrock");
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
// --- Invalid provider ----------------------------------------------------
|
|
94
|
+
|
|
95
|
+
test("throws for an invalid provider string", () => {
|
|
96
|
+
process.env.ATLAS_PROVIDER = "typo-provider";
|
|
97
|
+
expect(() => getProviderType()).toThrow(Error);
|
|
98
|
+
});
|
|
99
|
+
});
|