@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,427 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach, mock } from "bun:test";
|
|
2
|
+
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
// Mock handler module so we don't hit real DB / auth
|
|
5
|
+
// ---------------------------------------------------------------------------
|
|
6
|
+
|
|
7
|
+
let lastHandleActionCall: { request: unknown; executeFn: unknown } | null = null;
|
|
8
|
+
|
|
9
|
+
mock.module("@atlas/api/lib/tools/actions/handler", () => ({
|
|
10
|
+
buildActionRequest: (params: Record<string, unknown>) => ({
|
|
11
|
+
id: "test-action-id",
|
|
12
|
+
...params,
|
|
13
|
+
}),
|
|
14
|
+
handleAction: async (request: unknown, executeFn: unknown) => {
|
|
15
|
+
lastHandleActionCall = { request, executeFn };
|
|
16
|
+
return { status: "pending_approval", actionId: "test-action-id", summary: "test" };
|
|
17
|
+
},
|
|
18
|
+
}));
|
|
19
|
+
|
|
20
|
+
mock.module("@atlas/api/lib/logger", () => ({
|
|
21
|
+
createLogger: () => ({
|
|
22
|
+
info: () => {},
|
|
23
|
+
warn: () => {},
|
|
24
|
+
error: () => {},
|
|
25
|
+
debug: () => {},
|
|
26
|
+
}),
|
|
27
|
+
}));
|
|
28
|
+
|
|
29
|
+
const { executeJiraCreate, createJiraTicket, textToADF } = await import(
|
|
30
|
+
"@atlas/api/lib/tools/actions/jira"
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
// ---------------------------------------------------------------------------
|
|
34
|
+
// Env snapshot + fetch mock
|
|
35
|
+
// ---------------------------------------------------------------------------
|
|
36
|
+
|
|
37
|
+
const ENV_KEYS = [
|
|
38
|
+
"JIRA_BASE_URL",
|
|
39
|
+
"JIRA_EMAIL",
|
|
40
|
+
"JIRA_API_TOKEN",
|
|
41
|
+
"JIRA_DEFAULT_PROJECT",
|
|
42
|
+
] as const;
|
|
43
|
+
|
|
44
|
+
const saved: Record<string, string | undefined> = {};
|
|
45
|
+
const originalFetch = globalThis.fetch;
|
|
46
|
+
|
|
47
|
+
let capturedFetchUrl = "";
|
|
48
|
+
let capturedFetchInit: RequestInit | undefined;
|
|
49
|
+
|
|
50
|
+
function installFetchMock(
|
|
51
|
+
response: { status: number; body: unknown },
|
|
52
|
+
) {
|
|
53
|
+
globalThis.fetch = (async (input: string | URL | Request, init?: RequestInit) => {
|
|
54
|
+
capturedFetchUrl = typeof input === "string" ? input : (input as Request).url;
|
|
55
|
+
capturedFetchInit = init;
|
|
56
|
+
return new Response(JSON.stringify(response.body), {
|
|
57
|
+
status: response.status,
|
|
58
|
+
headers: { "Content-Type": "application/json" },
|
|
59
|
+
});
|
|
60
|
+
}) as typeof globalThis.fetch;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function installFetchMockRaw(
|
|
64
|
+
response: { status: number; text: string },
|
|
65
|
+
) {
|
|
66
|
+
globalThis.fetch = (async (input: string | URL | Request) => {
|
|
67
|
+
capturedFetchUrl = typeof input === "string" ? input : (input as Request).url;
|
|
68
|
+
return new Response(response.text, { status: response.status });
|
|
69
|
+
}) as typeof globalThis.fetch;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
beforeEach(() => {
|
|
73
|
+
for (const key of ENV_KEYS) saved[key] = process.env[key];
|
|
74
|
+
lastHandleActionCall = null;
|
|
75
|
+
capturedFetchUrl = "";
|
|
76
|
+
capturedFetchInit = undefined;
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
afterEach(() => {
|
|
80
|
+
globalThis.fetch = originalFetch;
|
|
81
|
+
for (const key of ENV_KEYS) {
|
|
82
|
+
if (saved[key] !== undefined) process.env[key] = saved[key];
|
|
83
|
+
else delete process.env[key];
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// ---------------------------------------------------------------------------
|
|
88
|
+
// AtlasAction metadata
|
|
89
|
+
// ---------------------------------------------------------------------------
|
|
90
|
+
|
|
91
|
+
describe("createJiraTicket — metadata", () => {
|
|
92
|
+
it("has the correct actionType", () => {
|
|
93
|
+
expect(createJiraTicket.actionType).toBe("jira:create");
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("is reversible", () => {
|
|
97
|
+
expect(createJiraTicket.reversible).toBe(true);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("defaults to manual approval", () => {
|
|
101
|
+
expect(createJiraTicket.defaultApproval).toBe("manual");
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it("requires JIRA credentials", () => {
|
|
105
|
+
expect(createJiraTicket.requiredCredentials).toEqual([
|
|
106
|
+
"JIRA_BASE_URL",
|
|
107
|
+
"JIRA_EMAIL",
|
|
108
|
+
"JIRA_API_TOKEN",
|
|
109
|
+
]);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it("has a name", () => {
|
|
113
|
+
expect(createJiraTicket.name).toBe("createJiraTicket");
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it("has a description", () => {
|
|
117
|
+
expect(createJiraTicket.description).toBeTruthy();
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
// ---------------------------------------------------------------------------
|
|
122
|
+
// textToADF — Atlassian Document Format helper
|
|
123
|
+
// ---------------------------------------------------------------------------
|
|
124
|
+
|
|
125
|
+
describe("textToADF", () => {
|
|
126
|
+
it("splits multi-paragraph text into separate paragraph nodes", () => {
|
|
127
|
+
const doc = textToADF("Para1\n\nPara2\n\nPara3");
|
|
128
|
+
expect(doc.type).toBe("doc");
|
|
129
|
+
expect(doc.version).toBe(1);
|
|
130
|
+
expect(doc.content).toHaveLength(3);
|
|
131
|
+
expect(doc.content[0].content[0].text).toBe("Para1");
|
|
132
|
+
expect(doc.content[1].content[0].text).toBe("Para2");
|
|
133
|
+
expect(doc.content[2].content[0].text).toBe("Para3");
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it("returns fallback for empty text", () => {
|
|
137
|
+
const doc = textToADF("");
|
|
138
|
+
expect(doc.content).toHaveLength(1);
|
|
139
|
+
expect(doc.content[0].content[0].text).toBe("(no description)");
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it("returns fallback for whitespace-only text", () => {
|
|
143
|
+
const doc = textToADF(" \n\n ");
|
|
144
|
+
expect(doc.content).toHaveLength(1);
|
|
145
|
+
expect(doc.content[0].content[0].text).toBe("(no description)");
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it("produces no empty paragraph nodes from trailing newlines", () => {
|
|
149
|
+
const doc = textToADF("Hello\n\n\n\n");
|
|
150
|
+
for (const node of doc.content) {
|
|
151
|
+
expect(node.content[0].text.trim().length).toBeGreaterThan(0);
|
|
152
|
+
}
|
|
153
|
+
expect(doc.content).toHaveLength(1);
|
|
154
|
+
expect(doc.content[0].content[0].text).toBe("Hello");
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it("does not split on single newlines", () => {
|
|
158
|
+
const doc = textToADF("Line1\nLine2");
|
|
159
|
+
expect(doc.content).toHaveLength(1);
|
|
160
|
+
expect(doc.content[0].content[0].text).toBe("Line1\nLine2");
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
// ---------------------------------------------------------------------------
|
|
165
|
+
// executeJiraCreate — raw API call
|
|
166
|
+
// ---------------------------------------------------------------------------
|
|
167
|
+
|
|
168
|
+
describe("executeJiraCreate", () => {
|
|
169
|
+
it("throws when JIRA credentials are missing", async () => {
|
|
170
|
+
delete process.env.JIRA_BASE_URL;
|
|
171
|
+
delete process.env.JIRA_EMAIL;
|
|
172
|
+
delete process.env.JIRA_API_TOKEN;
|
|
173
|
+
|
|
174
|
+
await expect(
|
|
175
|
+
executeJiraCreate({
|
|
176
|
+
summary: "Test",
|
|
177
|
+
description: "Test desc",
|
|
178
|
+
project: "PROJ",
|
|
179
|
+
}),
|
|
180
|
+
).rejects.toThrow("Missing JIRA credentials");
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it("throws when no project is specified and no default", async () => {
|
|
184
|
+
process.env.JIRA_BASE_URL = "https://test.atlassian.net";
|
|
185
|
+
process.env.JIRA_EMAIL = "test@example.com";
|
|
186
|
+
process.env.JIRA_API_TOKEN = "tok-123";
|
|
187
|
+
delete process.env.JIRA_DEFAULT_PROJECT;
|
|
188
|
+
|
|
189
|
+
await expect(
|
|
190
|
+
executeJiraCreate({
|
|
191
|
+
summary: "Test",
|
|
192
|
+
description: "Test desc",
|
|
193
|
+
}),
|
|
194
|
+
).rejects.toThrow("No JIRA project specified");
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it("calls the correct JIRA API endpoint with Basic auth", async () => {
|
|
198
|
+
process.env.JIRA_BASE_URL = "https://test.atlassian.net";
|
|
199
|
+
process.env.JIRA_EMAIL = "test@example.com";
|
|
200
|
+
process.env.JIRA_API_TOKEN = "tok-123";
|
|
201
|
+
|
|
202
|
+
installFetchMock({
|
|
203
|
+
status: 201,
|
|
204
|
+
body: { key: "PROJ-42", self: "https://test.atlassian.net/rest/api/3/issue/12345" },
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
const result = await executeJiraCreate({
|
|
208
|
+
summary: "Bug report",
|
|
209
|
+
description: "Something is broken",
|
|
210
|
+
project: "PROJ",
|
|
211
|
+
labels: ["bug", "urgent"],
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
expect(capturedFetchUrl).toBe("https://test.atlassian.net/rest/api/3/issue");
|
|
215
|
+
expect(capturedFetchInit?.method).toBe("POST");
|
|
216
|
+
|
|
217
|
+
// Check Basic auth header
|
|
218
|
+
const expectedAuth = Buffer.from("test@example.com:tok-123").toString("base64");
|
|
219
|
+
expect((capturedFetchInit?.headers as Record<string, string>)?.Authorization).toBe(
|
|
220
|
+
`Basic ${expectedAuth}`,
|
|
221
|
+
);
|
|
222
|
+
|
|
223
|
+
// Check body includes project, summary, labels
|
|
224
|
+
const body = JSON.parse(capturedFetchInit?.body as string);
|
|
225
|
+
expect(body.fields.project.key).toBe("PROJ");
|
|
226
|
+
expect(body.fields.summary).toBe("Bug report");
|
|
227
|
+
expect(body.fields.labels).toEqual(["bug", "urgent"]);
|
|
228
|
+
|
|
229
|
+
// Check description is ADF format
|
|
230
|
+
expect(body.fields.description.type).toBe("doc");
|
|
231
|
+
expect(body.fields.description.version).toBe(1);
|
|
232
|
+
|
|
233
|
+
// Check result
|
|
234
|
+
expect(result.key).toBe("PROJ-42");
|
|
235
|
+
expect(result.url).toBe("https://test.atlassian.net/browse/PROJ-42");
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
it("falls back to JIRA_DEFAULT_PROJECT when project not provided", async () => {
|
|
239
|
+
process.env.JIRA_BASE_URL = "https://test.atlassian.net";
|
|
240
|
+
process.env.JIRA_EMAIL = "test@example.com";
|
|
241
|
+
process.env.JIRA_API_TOKEN = "tok-123";
|
|
242
|
+
process.env.JIRA_DEFAULT_PROJECT = "DEFAULT";
|
|
243
|
+
|
|
244
|
+
installFetchMock({
|
|
245
|
+
status: 201,
|
|
246
|
+
body: { key: "DEFAULT-1", self: "..." },
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
await executeJiraCreate({
|
|
250
|
+
summary: "Test",
|
|
251
|
+
description: "Desc",
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
const body = JSON.parse(capturedFetchInit?.body as string);
|
|
255
|
+
expect(body.fields.project.key).toBe("DEFAULT");
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
it("throws on API error without exposing secrets", async () => {
|
|
259
|
+
process.env.JIRA_BASE_URL = "https://test.atlassian.net";
|
|
260
|
+
process.env.JIRA_EMAIL = "test@example.com";
|
|
261
|
+
process.env.JIRA_API_TOKEN = "tok-123";
|
|
262
|
+
|
|
263
|
+
installFetchMock({
|
|
264
|
+
status: 400,
|
|
265
|
+
body: { errorMessages: ["Project 'BAD' does not exist."], errors: {} },
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
try {
|
|
269
|
+
await executeJiraCreate({
|
|
270
|
+
summary: "Test",
|
|
271
|
+
description: "Desc",
|
|
272
|
+
project: "BAD",
|
|
273
|
+
});
|
|
274
|
+
expect(true).toBe(false); // should not reach here
|
|
275
|
+
} catch (err) {
|
|
276
|
+
const message = (err as Error).message;
|
|
277
|
+
expect(message).toContain("JIRA API error");
|
|
278
|
+
expect(message).toContain("does not exist");
|
|
279
|
+
// Must not contain secrets
|
|
280
|
+
expect(message).not.toContain("tok-123");
|
|
281
|
+
expect(message).not.toContain("test@example.com");
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
it("handles non-JSON error responses", async () => {
|
|
286
|
+
process.env.JIRA_BASE_URL = "https://test.atlassian.net";
|
|
287
|
+
process.env.JIRA_EMAIL = "test@example.com";
|
|
288
|
+
process.env.JIRA_API_TOKEN = "tok-123";
|
|
289
|
+
|
|
290
|
+
installFetchMockRaw({ status: 500, text: "Internal Server Error" });
|
|
291
|
+
|
|
292
|
+
await expect(
|
|
293
|
+
executeJiraCreate({ summary: "Test", description: "Desc", project: "PROJ" }),
|
|
294
|
+
).rejects.toThrow("HTTP 500");
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
it("omits labels field when no labels provided", async () => {
|
|
298
|
+
process.env.JIRA_BASE_URL = "https://test.atlassian.net";
|
|
299
|
+
process.env.JIRA_EMAIL = "test@example.com";
|
|
300
|
+
process.env.JIRA_API_TOKEN = "tok-123";
|
|
301
|
+
|
|
302
|
+
installFetchMock({
|
|
303
|
+
status: 201,
|
|
304
|
+
body: { key: "PROJ-1", self: "..." },
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
await executeJiraCreate({
|
|
308
|
+
summary: "Test",
|
|
309
|
+
description: "Desc",
|
|
310
|
+
project: "PROJ",
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
const body = JSON.parse(capturedFetchInit?.body as string);
|
|
314
|
+
expect(body.fields.labels).toBeUndefined();
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
it("throws when only JIRA_BASE_URL is set (partial credentials)", async () => {
|
|
318
|
+
process.env.JIRA_BASE_URL = "https://test.atlassian.net";
|
|
319
|
+
delete process.env.JIRA_EMAIL;
|
|
320
|
+
delete process.env.JIRA_API_TOKEN;
|
|
321
|
+
|
|
322
|
+
await expect(
|
|
323
|
+
executeJiraCreate({
|
|
324
|
+
summary: "Test",
|
|
325
|
+
description: "Desc",
|
|
326
|
+
project: "PROJ",
|
|
327
|
+
}),
|
|
328
|
+
).rejects.toThrow("Missing JIRA credentials");
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
it("throws when success response is not valid JSON", async () => {
|
|
332
|
+
process.env.JIRA_BASE_URL = "https://test.atlassian.net";
|
|
333
|
+
process.env.JIRA_EMAIL = "test@example.com";
|
|
334
|
+
process.env.JIRA_API_TOKEN = "tok-123";
|
|
335
|
+
|
|
336
|
+
// Return 201 but with invalid JSON body
|
|
337
|
+
globalThis.fetch = (async () => {
|
|
338
|
+
return new Response("not json", {
|
|
339
|
+
status: 201,
|
|
340
|
+
headers: { "Content-Type": "text/plain" },
|
|
341
|
+
});
|
|
342
|
+
}) as unknown as typeof globalThis.fetch;
|
|
343
|
+
|
|
344
|
+
await expect(
|
|
345
|
+
executeJiraCreate({ summary: "Test", description: "Desc", project: "PROJ" }),
|
|
346
|
+
).rejects.toThrow("response could not be parsed");
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
it("throws when success response is missing key field", async () => {
|
|
350
|
+
process.env.JIRA_BASE_URL = "https://test.atlassian.net";
|
|
351
|
+
process.env.JIRA_EMAIL = "test@example.com";
|
|
352
|
+
process.env.JIRA_API_TOKEN = "tok-123";
|
|
353
|
+
|
|
354
|
+
installFetchMock({
|
|
355
|
+
status: 201,
|
|
356
|
+
body: { id: "12345", self: "https://test.atlassian.net/rest/api/3/issue/12345" },
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
await expect(
|
|
360
|
+
executeJiraCreate({ summary: "Test", description: "Desc", project: "PROJ" }),
|
|
361
|
+
).rejects.toThrow("response could not be parsed");
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
it("strips trailing slash from base URL", async () => {
|
|
365
|
+
process.env.JIRA_BASE_URL = "https://test.atlassian.net/";
|
|
366
|
+
process.env.JIRA_EMAIL = "test@example.com";
|
|
367
|
+
process.env.JIRA_API_TOKEN = "tok-123";
|
|
368
|
+
|
|
369
|
+
installFetchMock({
|
|
370
|
+
status: 201,
|
|
371
|
+
body: { key: "PROJ-1", self: "..." },
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
const result = await executeJiraCreate({
|
|
375
|
+
summary: "Test",
|
|
376
|
+
description: "Desc",
|
|
377
|
+
project: "PROJ",
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
expect(capturedFetchUrl).toBe("https://test.atlassian.net/rest/api/3/issue");
|
|
381
|
+
expect(result.url).toBe("https://test.atlassian.net/browse/PROJ-1");
|
|
382
|
+
});
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
// ---------------------------------------------------------------------------
|
|
386
|
+
// Tool execute — integration with handleAction
|
|
387
|
+
// ---------------------------------------------------------------------------
|
|
388
|
+
|
|
389
|
+
describe("createJiraTicket — tool execute", () => {
|
|
390
|
+
it("calls handleAction with correct actionType and payload", async () => {
|
|
391
|
+
process.env.JIRA_DEFAULT_PROJECT = "FALLBACK";
|
|
392
|
+
|
|
393
|
+
const aiTool = createJiraTicket.tool as unknown as {
|
|
394
|
+
execute: (args: unknown, options: unknown) => Promise<unknown>;
|
|
395
|
+
};
|
|
396
|
+
|
|
397
|
+
await aiTool.execute(
|
|
398
|
+
{ summary: "Test issue", description: "Details here" },
|
|
399
|
+
{ toolCallId: "test-call", messages: [], abortSignal: undefined as unknown as AbortSignal },
|
|
400
|
+
);
|
|
401
|
+
|
|
402
|
+
expect(lastHandleActionCall).not.toBeNull();
|
|
403
|
+
const request = lastHandleActionCall!.request as Record<string, unknown>;
|
|
404
|
+
expect(request.actionType).toBe("jira:create");
|
|
405
|
+
expect(request.target).toBe("FALLBACK");
|
|
406
|
+
expect(request.reversible).toBe(true);
|
|
407
|
+
expect((request.payload as Record<string, unknown>).summary).toBe("Test issue");
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
it("uses explicit project when provided instead of JIRA_DEFAULT_PROJECT", async () => {
|
|
411
|
+
process.env.JIRA_DEFAULT_PROJECT = "FALLBACK";
|
|
412
|
+
|
|
413
|
+
const aiTool = createJiraTicket.tool as unknown as {
|
|
414
|
+
execute: (args: unknown, options: unknown) => Promise<unknown>;
|
|
415
|
+
};
|
|
416
|
+
|
|
417
|
+
await aiTool.execute(
|
|
418
|
+
{ summary: "Explicit project", description: "Details", project: "EXPLICIT" },
|
|
419
|
+
{ toolCallId: "test-call-2", messages: [], abortSignal: undefined as unknown as AbortSignal },
|
|
420
|
+
);
|
|
421
|
+
|
|
422
|
+
expect(lastHandleActionCall).not.toBeNull();
|
|
423
|
+
const request = lastHandleActionCall!.request as Record<string, unknown>;
|
|
424
|
+
expect(request.target).toBe("EXPLICIT");
|
|
425
|
+
expect((request.payload as Record<string, unknown>).project).toBe("EXPLICIT");
|
|
426
|
+
});
|
|
427
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Action lifecycle logger.
|
|
3
|
+
*
|
|
4
|
+
* Structured pino logs for every action state transition.
|
|
5
|
+
*
|
|
6
|
+
* State transitions:
|
|
7
|
+
* - pending -> approved -> executed | failed
|
|
8
|
+
* - pending -> denied
|
|
9
|
+
* - pending -> auto_approved (executed inline) | failed
|
|
10
|
+
* - pending -> timed_out (reserved, not yet implemented)
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { createLogger } from "@atlas/api/lib/logger";
|
|
14
|
+
import type { ActionStatus } from "@atlas/api/lib/action-types";
|
|
15
|
+
|
|
16
|
+
const log = createLogger("action-audit");
|
|
17
|
+
|
|
18
|
+
export interface ActionAuditEntry {
|
|
19
|
+
actionId: string;
|
|
20
|
+
actionType: string;
|
|
21
|
+
status: ActionStatus;
|
|
22
|
+
latencyMs?: number;
|
|
23
|
+
userId?: string;
|
|
24
|
+
approverId?: string;
|
|
25
|
+
error?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function logActionAudit(entry: ActionAuditEntry): void {
|
|
29
|
+
const { actionId, actionType, status, latencyMs, userId, approverId, error } = entry;
|
|
30
|
+
const fields = {
|
|
31
|
+
actionId,
|
|
32
|
+
actionType,
|
|
33
|
+
status,
|
|
34
|
+
...(latencyMs !== undefined && { latencyMs }),
|
|
35
|
+
...(userId && { userId }),
|
|
36
|
+
...(approverId && { approverId }),
|
|
37
|
+
...(error && { error }),
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
if (status === "failed") {
|
|
41
|
+
log.error(fields, `action_${status}`);
|
|
42
|
+
} else if (status === "denied") {
|
|
43
|
+
log.warn(fields, `action_${status}`);
|
|
44
|
+
} else {
|
|
45
|
+
log.info(fields, `action_${status}`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Email action — send reports via Resend.
|
|
3
|
+
*
|
|
4
|
+
* Exports:
|
|
5
|
+
* - executeEmailSend(params) — raw Resend SDK call
|
|
6
|
+
* - sendEmailReport — AtlasAction for the agent tool registry
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { tool } from "ai";
|
|
10
|
+
import { z } from "zod";
|
|
11
|
+
import type { AtlasAction } from "@atlas/api/lib/action-types";
|
|
12
|
+
import { buildActionRequest, handleAction } from "./handler";
|
|
13
|
+
import { createLogger } from "@atlas/api/lib/logger";
|
|
14
|
+
|
|
15
|
+
const log = createLogger("action:email");
|
|
16
|
+
|
|
17
|
+
// ---------------------------------------------------------------------------
|
|
18
|
+
// Domain allowlist validation
|
|
19
|
+
// ---------------------------------------------------------------------------
|
|
20
|
+
|
|
21
|
+
/** Extract the domain from an email address, handling display-name format. */
|
|
22
|
+
function extractEmailDomain(addr: string): string | undefined {
|
|
23
|
+
// Handle display-name format: "User <user@company.com>"
|
|
24
|
+
const angleMatch = addr.match(/<([^>]+)>/);
|
|
25
|
+
const email = angleMatch ? angleMatch[1] : addr;
|
|
26
|
+
return email.split("@")[1]?.toLowerCase();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function validateAllowedDomains(
|
|
30
|
+
recipients: string[],
|
|
31
|
+
): { valid: boolean; blocked: string[] } {
|
|
32
|
+
const raw = process.env.ATLAS_EMAIL_ALLOWED_DOMAINS;
|
|
33
|
+
if (!raw) return { valid: true, blocked: [] };
|
|
34
|
+
|
|
35
|
+
const allowed = raw
|
|
36
|
+
.split(",")
|
|
37
|
+
.map((d) => d.trim().toLowerCase())
|
|
38
|
+
.filter(Boolean);
|
|
39
|
+
|
|
40
|
+
if (allowed.length === 0) return { valid: true, blocked: [] };
|
|
41
|
+
|
|
42
|
+
const blocked: string[] = [];
|
|
43
|
+
for (const addr of recipients) {
|
|
44
|
+
const domain = extractEmailDomain(addr);
|
|
45
|
+
if (!domain || !allowed.includes(domain)) {
|
|
46
|
+
blocked.push(addr);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (blocked.length > 0) {
|
|
51
|
+
log.warn({ blocked, allowed }, "Domain allowlist rejected recipients");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return { valid: blocked.length === 0, blocked };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// ---------------------------------------------------------------------------
|
|
58
|
+
// Raw Resend API call
|
|
59
|
+
// ---------------------------------------------------------------------------
|
|
60
|
+
|
|
61
|
+
export interface EmailSendParams {
|
|
62
|
+
to: string | string[];
|
|
63
|
+
subject: string;
|
|
64
|
+
body: string;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface EmailSendResult {
|
|
68
|
+
id: string;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export async function executeEmailSend(
|
|
72
|
+
params: EmailSendParams,
|
|
73
|
+
): Promise<EmailSendResult> {
|
|
74
|
+
const apiKey = process.env.RESEND_API_KEY;
|
|
75
|
+
if (!apiKey) {
|
|
76
|
+
log.error("Missing RESEND_API_KEY");
|
|
77
|
+
throw new Error("Missing RESEND_API_KEY. Set it to send emails via Resend.");
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const fromAddress =
|
|
81
|
+
process.env.ATLAS_EMAIL_FROM ?? "Atlas <atlas@notifications.useatlas.dev>";
|
|
82
|
+
const recipients = Array.isArray(params.to) ? params.to : [params.to];
|
|
83
|
+
|
|
84
|
+
const response = await fetch("https://api.resend.com/emails", {
|
|
85
|
+
method: "POST",
|
|
86
|
+
headers: {
|
|
87
|
+
Authorization: `Bearer ${apiKey}`,
|
|
88
|
+
"Content-Type": "application/json",
|
|
89
|
+
},
|
|
90
|
+
body: JSON.stringify({
|
|
91
|
+
from: fromAddress,
|
|
92
|
+
to: recipients,
|
|
93
|
+
subject: params.subject,
|
|
94
|
+
html: params.body,
|
|
95
|
+
}),
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
if (!response.ok) {
|
|
99
|
+
let detail: string;
|
|
100
|
+
try {
|
|
101
|
+
const errorBody = (await response.json()) as { message?: string };
|
|
102
|
+
detail = errorBody.message ?? `HTTP ${response.status}`;
|
|
103
|
+
} catch {
|
|
104
|
+
try {
|
|
105
|
+
const text = await response.text();
|
|
106
|
+
detail = text ? `HTTP ${response.status}: ${text.slice(0, 200)}` : `HTTP ${response.status}`;
|
|
107
|
+
} catch {
|
|
108
|
+
detail = `HTTP ${response.status}`;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
log.error({ status: response.status, detail }, "Resend API request failed");
|
|
112
|
+
throw new Error(`Resend API error: ${detail}`);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
let data: { id?: string };
|
|
116
|
+
try {
|
|
117
|
+
data = (await response.json()) as { id?: string };
|
|
118
|
+
} catch (err) {
|
|
119
|
+
log.error({ err }, "Failed to parse Resend API success response");
|
|
120
|
+
throw new Error("Resend API returned unparseable response after success status", { cause: err });
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (!data.id) {
|
|
124
|
+
log.warn("Resend API returned success but no email ID — email may have been sent");
|
|
125
|
+
}
|
|
126
|
+
return { id: data.id ?? "unknown" };
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// ---------------------------------------------------------------------------
|
|
130
|
+
// Agent tool (AtlasAction)
|
|
131
|
+
// ---------------------------------------------------------------------------
|
|
132
|
+
|
|
133
|
+
const SEND_EMAIL_DESCRIPTION = `### Send Email Report
|
|
134
|
+
Use sendEmailReport to email analysis results to stakeholders:
|
|
135
|
+
- Provide recipient email addresses
|
|
136
|
+
- Include a clear subject line
|
|
137
|
+
- Format the body as HTML for rich formatting
|
|
138
|
+
- Domain restrictions may apply (ATLAS_EMAIL_ALLOWED_DOMAINS)
|
|
139
|
+
- Emails require admin approval before sending`;
|
|
140
|
+
|
|
141
|
+
export const sendEmailReport: AtlasAction = {
|
|
142
|
+
name: "sendEmailReport",
|
|
143
|
+
description: SEND_EMAIL_DESCRIPTION,
|
|
144
|
+
actionType: "email:send",
|
|
145
|
+
reversible: false,
|
|
146
|
+
defaultApproval: "admin-only",
|
|
147
|
+
requiredCredentials: ["RESEND_API_KEY"],
|
|
148
|
+
|
|
149
|
+
tool: tool({
|
|
150
|
+
description:
|
|
151
|
+
"Send an email report. Requires admin approval before the email is sent.",
|
|
152
|
+
inputSchema: z.object({
|
|
153
|
+
to: z
|
|
154
|
+
.union([z.string(), z.array(z.string()).min(1)])
|
|
155
|
+
.describe("Recipient email address(es)"),
|
|
156
|
+
subject: z.string().describe("Email subject line"),
|
|
157
|
+
body: z.string().describe("Email body (HTML)"),
|
|
158
|
+
}),
|
|
159
|
+
execute: async ({ to, subject, body }) => {
|
|
160
|
+
const recipients = Array.isArray(to) ? to : [to];
|
|
161
|
+
log.info(
|
|
162
|
+
{ to: recipients, subject },
|
|
163
|
+
"sendEmailReport invoked",
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
// Domain allowlist check — runs pre-approval
|
|
167
|
+
const domainCheck = validateAllowedDomains(recipients);
|
|
168
|
+
if (!domainCheck.valid) {
|
|
169
|
+
return {
|
|
170
|
+
status: "error" as const,
|
|
171
|
+
error: `Recipient domain not allowed: ${domainCheck.blocked.join(", ")}. Allowed domains: ${process.env.ATLAS_EMAIL_ALLOWED_DOMAINS}`,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const request = buildActionRequest({
|
|
176
|
+
actionType: "email:send",
|
|
177
|
+
target: recipients.join(", "),
|
|
178
|
+
summary: `Send email: "${subject}" to ${recipients.join(", ")}`,
|
|
179
|
+
payload: { to: recipients, subject, body },
|
|
180
|
+
reversible: false,
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
return handleAction(request, async (payload) => {
|
|
184
|
+
const result = await executeEmailSend(
|
|
185
|
+
payload as unknown as EmailSendParams,
|
|
186
|
+
);
|
|
187
|
+
return result;
|
|
188
|
+
});
|
|
189
|
+
},
|
|
190
|
+
}),
|
|
191
|
+
};
|