@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,78 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import type { Conversation } from "../../lib/types";
|
|
4
|
+
import { ConversationList } from "./conversation-list";
|
|
5
|
+
|
|
6
|
+
export function ConversationSidebar({
|
|
7
|
+
conversations,
|
|
8
|
+
selectedId,
|
|
9
|
+
loading,
|
|
10
|
+
onSelect,
|
|
11
|
+
onDelete,
|
|
12
|
+
onStar,
|
|
13
|
+
onNewChat,
|
|
14
|
+
mobileOpen,
|
|
15
|
+
onMobileClose,
|
|
16
|
+
}: {
|
|
17
|
+
conversations: Conversation[];
|
|
18
|
+
selectedId: string | null;
|
|
19
|
+
loading: boolean;
|
|
20
|
+
onSelect: (id: string) => void;
|
|
21
|
+
onDelete: (id: string) => Promise<boolean>;
|
|
22
|
+
onStar: (id: string, starred: boolean) => Promise<boolean>;
|
|
23
|
+
onNewChat: () => void;
|
|
24
|
+
mobileOpen: boolean;
|
|
25
|
+
onMobileClose: () => void;
|
|
26
|
+
}) {
|
|
27
|
+
const sidebar = (
|
|
28
|
+
<div className="flex h-full flex-col border-r border-zinc-200 bg-zinc-50/50 dark:border-zinc-800 dark:bg-zinc-950/50">
|
|
29
|
+
<div className="flex items-center justify-between border-b border-zinc-200 px-3 py-3 dark:border-zinc-800">
|
|
30
|
+
<span className="text-sm font-medium text-zinc-700 dark:text-zinc-300">History</span>
|
|
31
|
+
<button
|
|
32
|
+
onClick={onNewChat}
|
|
33
|
+
className="rounded-lg border border-zinc-200 px-2.5 py-1 text-xs font-medium text-zinc-600 transition-colors hover:border-zinc-400 hover:text-zinc-900 dark:border-zinc-700 dark:text-zinc-400 dark:hover:border-zinc-500 dark:hover:text-zinc-200"
|
|
34
|
+
>
|
|
35
|
+
+ New
|
|
36
|
+
</button>
|
|
37
|
+
</div>
|
|
38
|
+
|
|
39
|
+
<div className="flex-1 overflow-y-auto p-2">
|
|
40
|
+
{loading && conversations.length === 0 ? (
|
|
41
|
+
<div className="flex items-center justify-center py-8">
|
|
42
|
+
<span className="inline-block h-4 w-4 animate-spin rounded-full border-2 border-zinc-300 border-t-zinc-600 dark:border-zinc-600 dark:border-t-zinc-300" />
|
|
43
|
+
</div>
|
|
44
|
+
) : (
|
|
45
|
+
<ConversationList
|
|
46
|
+
conversations={conversations}
|
|
47
|
+
selectedId={selectedId}
|
|
48
|
+
onSelect={onSelect}
|
|
49
|
+
onDelete={onDelete}
|
|
50
|
+
onStar={onStar}
|
|
51
|
+
/>
|
|
52
|
+
)}
|
|
53
|
+
</div>
|
|
54
|
+
</div>
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<>
|
|
59
|
+
{/* Desktop sidebar */}
|
|
60
|
+
<div className="hidden w-[280px] shrink-0 md:block">
|
|
61
|
+
{sidebar}
|
|
62
|
+
</div>
|
|
63
|
+
|
|
64
|
+
{/* Mobile overlay */}
|
|
65
|
+
{mobileOpen && (
|
|
66
|
+
<>
|
|
67
|
+
<div
|
|
68
|
+
className="fixed inset-0 z-40 bg-black/30 md:hidden"
|
|
69
|
+
onClick={onMobileClose}
|
|
70
|
+
/>
|
|
71
|
+
<div className="fixed inset-y-0 left-0 z-50 w-[280px] md:hidden">
|
|
72
|
+
{sidebar}
|
|
73
|
+
</div>
|
|
74
|
+
</>
|
|
75
|
+
)}
|
|
76
|
+
</>
|
|
77
|
+
);
|
|
78
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
export function DeleteConfirmation({
|
|
4
|
+
onConfirm,
|
|
5
|
+
onCancel,
|
|
6
|
+
}: {
|
|
7
|
+
onConfirm: () => void;
|
|
8
|
+
onCancel: () => void;
|
|
9
|
+
}) {
|
|
10
|
+
return (
|
|
11
|
+
<div className="flex items-center gap-2 px-3 py-2 text-xs">
|
|
12
|
+
<span className="text-zinc-500 dark:text-zinc-400">Delete?</span>
|
|
13
|
+
<button
|
|
14
|
+
onClick={onCancel}
|
|
15
|
+
className="rounded px-2 py-0.5 text-zinc-500 transition-colors hover:text-zinc-800 dark:text-zinc-400 dark:hover:text-zinc-200"
|
|
16
|
+
>
|
|
17
|
+
Cancel
|
|
18
|
+
</button>
|
|
19
|
+
<button
|
|
20
|
+
onClick={onConfirm}
|
|
21
|
+
className="rounded bg-red-600 px-2 py-0.5 text-white transition-colors hover:bg-red-500"
|
|
22
|
+
>
|
|
23
|
+
Delete
|
|
24
|
+
</button>
|
|
25
|
+
</div>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { createContext, useContext, useMemo, type ReactNode } from "react";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Duck-typed interface that matches better-auth's client shape.
|
|
7
|
+
* Components like ManagedAuthCard call signIn/signUp/signOut and useSession().
|
|
8
|
+
*/
|
|
9
|
+
export interface AtlasAuthClient {
|
|
10
|
+
signIn: {
|
|
11
|
+
email: (opts: { email: string; password: string }) => Promise<{ error?: { message?: string } | null }>;
|
|
12
|
+
};
|
|
13
|
+
signUp: {
|
|
14
|
+
email: (opts: { email: string; password: string; name: string }) => Promise<{ error?: { message?: string } | null }>;
|
|
15
|
+
};
|
|
16
|
+
signOut: () => Promise<unknown>;
|
|
17
|
+
useSession: () => { data?: { user?: { email?: string } } | null };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface AtlasUIConfig {
|
|
21
|
+
apiUrl: string;
|
|
22
|
+
isCrossOrigin: boolean;
|
|
23
|
+
authClient: AtlasAuthClient;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const AtlasUIContext = createContext<AtlasUIConfig | null>(null);
|
|
27
|
+
|
|
28
|
+
export function useAtlasConfig(): AtlasUIConfig {
|
|
29
|
+
const ctx = useContext(AtlasUIContext);
|
|
30
|
+
if (!ctx) throw new Error("useAtlasConfig must be used within <AtlasUIProvider>");
|
|
31
|
+
return ctx;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function AtlasUIProvider({
|
|
35
|
+
config,
|
|
36
|
+
children,
|
|
37
|
+
}: {
|
|
38
|
+
config: AtlasUIConfig;
|
|
39
|
+
children: ReactNode;
|
|
40
|
+
}) {
|
|
41
|
+
return (
|
|
42
|
+
<AtlasUIContext.Provider value={config}>
|
|
43
|
+
{children}
|
|
44
|
+
</AtlasUIContext.Provider>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/* ------------------------------------------------------------------ */
|
|
49
|
+
/* ActionAuth — internal context for passing auth to action cards */
|
|
50
|
+
/* ------------------------------------------------------------------ */
|
|
51
|
+
|
|
52
|
+
export interface ActionAuthValue {
|
|
53
|
+
getHeaders: () => Record<string, string>;
|
|
54
|
+
getCredentials: () => RequestCredentials;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const ActionAuthContext = createContext<ActionAuthValue | null>(null);
|
|
58
|
+
|
|
59
|
+
/** Returns auth helpers for action API calls, or null when no provider is present. */
|
|
60
|
+
export function useActionAuth(): ActionAuthValue | null {
|
|
61
|
+
return useContext(ActionAuthContext);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function ActionAuthProvider({
|
|
65
|
+
getHeaders,
|
|
66
|
+
getCredentials,
|
|
67
|
+
children,
|
|
68
|
+
}: ActionAuthValue & { children: ReactNode }) {
|
|
69
|
+
const value = useMemo(
|
|
70
|
+
() => ({ getHeaders, getCredentials }),
|
|
71
|
+
[getHeaders, getCredentials],
|
|
72
|
+
);
|
|
73
|
+
return (
|
|
74
|
+
<ActionAuthContext.Provider value={value}>
|
|
75
|
+
{children}
|
|
76
|
+
</ActionAuthContext.Provider>
|
|
77
|
+
);
|
|
78
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useEffect, useState, useCallback, useRef } from "react";
|
|
4
|
+
import { useAtlasConfig } from "@/ui/context";
|
|
5
|
+
|
|
6
|
+
export interface FetchError {
|
|
7
|
+
message: string;
|
|
8
|
+
status?: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** Map HTTP status codes to user-friendly messages for admin pages. */
|
|
12
|
+
export function friendlyError(err: FetchError): string {
|
|
13
|
+
if (err.status === 401) return "Not authenticated. Please sign in.";
|
|
14
|
+
if (err.status === 403)
|
|
15
|
+
return "Access denied. Admin role required to view this page.";
|
|
16
|
+
if (err.status === 404) return "This feature is not enabled on this server.";
|
|
17
|
+
return err.message;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Shared fetch hook for admin pages.
|
|
22
|
+
* Handles loading/error state, cancellation on unmount, and credentials.
|
|
23
|
+
*/
|
|
24
|
+
export function useAdminFetch<T>(
|
|
25
|
+
path: string,
|
|
26
|
+
opts?: {
|
|
27
|
+
deps?: unknown[];
|
|
28
|
+
transform?: (json: unknown) => T;
|
|
29
|
+
},
|
|
30
|
+
) {
|
|
31
|
+
const { apiUrl, isCrossOrigin } = useAtlasConfig();
|
|
32
|
+
const [data, setData] = useState<T | null>(null);
|
|
33
|
+
const [loading, setLoading] = useState(true);
|
|
34
|
+
const [error, setError] = useState<FetchError | null>(null);
|
|
35
|
+
const credentials: RequestCredentials = isCrossOrigin ? "include" : "same-origin";
|
|
36
|
+
const credentialsRef = useRef(credentials);
|
|
37
|
+
credentialsRef.current = credentials;
|
|
38
|
+
|
|
39
|
+
const fetchData = useCallback(async (signal?: AbortSignal) => {
|
|
40
|
+
setLoading(true);
|
|
41
|
+
setError(null);
|
|
42
|
+
try {
|
|
43
|
+
const res = await fetch(`${apiUrl}${path}`, {
|
|
44
|
+
credentials: credentialsRef.current,
|
|
45
|
+
signal,
|
|
46
|
+
});
|
|
47
|
+
if (!res.ok) {
|
|
48
|
+
const e: FetchError = { message: `HTTP ${res.status}`, status: res.status };
|
|
49
|
+
if (!signal?.aborted) setError(e);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const json = await res.json();
|
|
53
|
+
const result = opts?.transform ? opts.transform(json) : (json as T);
|
|
54
|
+
if (!signal?.aborted) setData(result);
|
|
55
|
+
} catch (err) {
|
|
56
|
+
if (err instanceof DOMException && err.name === "AbortError") return;
|
|
57
|
+
if (!signal?.aborted) {
|
|
58
|
+
setError({
|
|
59
|
+
message: err instanceof Error ? err.message : "Request failed",
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
} finally {
|
|
63
|
+
if (!signal?.aborted) setLoading(false);
|
|
64
|
+
}
|
|
65
|
+
}, [apiUrl, path, ...(opts?.deps ?? [])]);
|
|
66
|
+
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
const controller = new AbortController();
|
|
69
|
+
fetchData(controller.signal);
|
|
70
|
+
return () => controller.abort();
|
|
71
|
+
}, [fetchData]);
|
|
72
|
+
|
|
73
|
+
const refetch = useCallback(() => {
|
|
74
|
+
fetchData();
|
|
75
|
+
}, [fetchData]);
|
|
76
|
+
|
|
77
|
+
return { data, loading, error, setError, refetch };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Returns `{ has, start, stop }` for tracking in-progress mutations by ID.
|
|
82
|
+
*/
|
|
83
|
+
export function useInProgressSet() {
|
|
84
|
+
const [set, setSet] = useState<Set<string>>(new Set());
|
|
85
|
+
return {
|
|
86
|
+
has: (id: string) => set.has(id),
|
|
87
|
+
start: (id: string) => setSet((prev) => new Set(prev).add(id)),
|
|
88
|
+
stop: (id: string) =>
|
|
89
|
+
setSet((prev) => {
|
|
90
|
+
const next = new Set(prev);
|
|
91
|
+
next.delete(id);
|
|
92
|
+
return next;
|
|
93
|
+
}),
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Returns fetch options with correct credentials for admin API calls.
|
|
99
|
+
*/
|
|
100
|
+
export function useAdminFetchOpts() {
|
|
101
|
+
const { apiUrl, isCrossOrigin } = useAtlasConfig();
|
|
102
|
+
const credentials: RequestCredentials = isCrossOrigin ? "include" : "same-origin";
|
|
103
|
+
return { apiUrl, fetchOpts: { credentials } as RequestInit };
|
|
104
|
+
}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useState, useCallback, useRef } from "react";
|
|
4
|
+
import type { Conversation, ConversationWithMessages, Message } from "../lib/types";
|
|
5
|
+
import type { UIMessage } from "@ai-sdk/react";
|
|
6
|
+
|
|
7
|
+
export interface UseConversationsOptions {
|
|
8
|
+
apiUrl: string;
|
|
9
|
+
enabled: boolean;
|
|
10
|
+
getHeaders: () => Record<string, string>;
|
|
11
|
+
getCredentials: () => RequestCredentials;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface UseConversationsReturn {
|
|
15
|
+
conversations: Conversation[];
|
|
16
|
+
total: number;
|
|
17
|
+
loading: boolean;
|
|
18
|
+
available: boolean;
|
|
19
|
+
selectedId: string | null;
|
|
20
|
+
setSelectedId: (id: string | null) => void;
|
|
21
|
+
fetchList: () => Promise<void>;
|
|
22
|
+
loadConversation: (id: string) => Promise<UIMessage[] | null>;
|
|
23
|
+
deleteConversation: (id: string) => Promise<boolean>;
|
|
24
|
+
starConversation: (id: string, starred: boolean) => Promise<boolean>;
|
|
25
|
+
refresh: () => Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function transformMessages(messages: Message[]): UIMessage[] {
|
|
29
|
+
return messages
|
|
30
|
+
.filter((m) => m.role === "user" || m.role === "assistant")
|
|
31
|
+
.map((m) => {
|
|
32
|
+
const content = typeof m.content === "string"
|
|
33
|
+
? m.content
|
|
34
|
+
: JSON.stringify(m.content);
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
id: m.id,
|
|
38
|
+
role: m.role as "user" | "assistant",
|
|
39
|
+
parts: [{ type: "text" as const, text: content }],
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function useConversations(opts: UseConversationsOptions): UseConversationsReturn {
|
|
45
|
+
const [conversations, setConversations] = useState<Conversation[]>([]);
|
|
46
|
+
const [total, setTotal] = useState(0);
|
|
47
|
+
const [loading, setLoading] = useState(false);
|
|
48
|
+
const [available, setAvailable] = useState(true);
|
|
49
|
+
const [selectedId, setSelectedId] = useState<string | null>(null);
|
|
50
|
+
const fetchedRef = useRef(false);
|
|
51
|
+
|
|
52
|
+
const fetchList = useCallback(async () => {
|
|
53
|
+
if (!opts.enabled || !available) return;
|
|
54
|
+
setLoading(true);
|
|
55
|
+
try {
|
|
56
|
+
const res = await fetch(`${opts.apiUrl}/api/v1/conversations?limit=50`, {
|
|
57
|
+
headers: opts.getHeaders(),
|
|
58
|
+
credentials: opts.getCredentials(),
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
if (res.status === 404) {
|
|
62
|
+
setAvailable(false);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (!res.ok) {
|
|
67
|
+
const body = await res.json().catch(() => null);
|
|
68
|
+
if (body?.code === "not_available") {
|
|
69
|
+
setAvailable(false);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
console.warn(`fetchList: HTTP ${res.status}`, body);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const data = await res.json();
|
|
77
|
+
setConversations(data.conversations ?? []);
|
|
78
|
+
setTotal(data.total ?? 0);
|
|
79
|
+
fetchedRef.current = true;
|
|
80
|
+
} catch (err) {
|
|
81
|
+
console.warn("fetchList error:", err);
|
|
82
|
+
// Network error on first attempt — permanently disable conversations for this session. A page reload resets this.
|
|
83
|
+
if (!fetchedRef.current) setAvailable(false);
|
|
84
|
+
} finally {
|
|
85
|
+
setLoading(false);
|
|
86
|
+
}
|
|
87
|
+
}, [opts.apiUrl, opts.enabled, opts.getHeaders, opts.getCredentials, available]);
|
|
88
|
+
|
|
89
|
+
const loadConversation = useCallback(async (id: string): Promise<UIMessage[] | null> => {
|
|
90
|
+
try {
|
|
91
|
+
const res = await fetch(`${opts.apiUrl}/api/v1/conversations/${id}`, {
|
|
92
|
+
headers: opts.getHeaders(),
|
|
93
|
+
credentials: opts.getCredentials(),
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
if (!res.ok) {
|
|
97
|
+
console.warn(`loadConversation: HTTP ${res.status} for ${id}`);
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const data: ConversationWithMessages = await res.json();
|
|
102
|
+
return transformMessages(data.messages);
|
|
103
|
+
} catch (err) {
|
|
104
|
+
console.warn("loadConversation error:", err);
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
}, [opts.apiUrl, opts.getHeaders, opts.getCredentials]);
|
|
108
|
+
|
|
109
|
+
const deleteConversation = useCallback(async (id: string): Promise<boolean> => {
|
|
110
|
+
try {
|
|
111
|
+
const res = await fetch(`${opts.apiUrl}/api/v1/conversations/${id}`, {
|
|
112
|
+
method: "DELETE",
|
|
113
|
+
headers: opts.getHeaders(),
|
|
114
|
+
credentials: opts.getCredentials(),
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
if (!res.ok) {
|
|
118
|
+
console.warn(`deleteConversation: HTTP ${res.status} for ${id}`);
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
setConversations((prev) => prev.filter((c) => c.id !== id));
|
|
123
|
+
setTotal((prev) => Math.max(0, prev - 1));
|
|
124
|
+
|
|
125
|
+
if (selectedId === id) setSelectedId(null);
|
|
126
|
+
|
|
127
|
+
return true;
|
|
128
|
+
} catch (err) {
|
|
129
|
+
console.warn("deleteConversation error:", err);
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
}, [opts.apiUrl, opts.getHeaders, opts.getCredentials, selectedId]);
|
|
133
|
+
|
|
134
|
+
const starConversation = useCallback(async (id: string, starred: boolean): Promise<boolean> => {
|
|
135
|
+
// Optimistic update
|
|
136
|
+
setConversations((prev) =>
|
|
137
|
+
prev.map((c) => (c.id === id ? { ...c, starred } : c)),
|
|
138
|
+
);
|
|
139
|
+
try {
|
|
140
|
+
const res = await fetch(`${opts.apiUrl}/api/v1/conversations/${id}/star`, {
|
|
141
|
+
method: "PATCH",
|
|
142
|
+
headers: { ...opts.getHeaders(), "Content-Type": "application/json" },
|
|
143
|
+
credentials: opts.getCredentials(),
|
|
144
|
+
body: JSON.stringify({ starred }),
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
if (!res.ok) {
|
|
148
|
+
console.warn(`starConversation: HTTP ${res.status} for ${id}`);
|
|
149
|
+
// Rollback
|
|
150
|
+
setConversations((prev) =>
|
|
151
|
+
prev.map((c) => (c.id === id ? { ...c, starred: !starred } : c)),
|
|
152
|
+
);
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return true;
|
|
157
|
+
} catch (err) {
|
|
158
|
+
console.warn("starConversation error:", err);
|
|
159
|
+
// Rollback
|
|
160
|
+
setConversations((prev) =>
|
|
161
|
+
prev.map((c) => (c.id === id ? { ...c, starred: !starred } : c)),
|
|
162
|
+
);
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
}, [opts.apiUrl, opts.getHeaders, opts.getCredentials]);
|
|
166
|
+
|
|
167
|
+
const refresh = useCallback(async () => {
|
|
168
|
+
await fetchList();
|
|
169
|
+
}, [fetchList]);
|
|
170
|
+
|
|
171
|
+
return {
|
|
172
|
+
conversations,
|
|
173
|
+
total,
|
|
174
|
+
loading,
|
|
175
|
+
available,
|
|
176
|
+
selectedId,
|
|
177
|
+
setSelectedId,
|
|
178
|
+
fetchList,
|
|
179
|
+
loadConversation,
|
|
180
|
+
deleteConversation,
|
|
181
|
+
starConversation,
|
|
182
|
+
refresh,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { createContext, useState, useEffect } from "react";
|
|
4
|
+
|
|
5
|
+
export const DarkModeContext = createContext(false);
|
|
6
|
+
|
|
7
|
+
export function useDarkMode() {
|
|
8
|
+
const [dark, setDark] = useState(false);
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
const mq = window.matchMedia("(prefers-color-scheme: dark)");
|
|
11
|
+
setDark(mq.matches);
|
|
12
|
+
const handler = (e: MediaQueryListEvent) => setDark(e.matches);
|
|
13
|
+
mq.addEventListener("change", handler);
|
|
14
|
+
return () => mq.removeEventListener("change", handler);
|
|
15
|
+
}, []);
|
|
16
|
+
return dark;
|
|
17
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/** Status lifecycle for action tools that require user approval. */
|
|
2
|
+
export type ActionStatus =
|
|
3
|
+
| "pending_approval"
|
|
4
|
+
| "approved"
|
|
5
|
+
| "executed"
|
|
6
|
+
| "auto_approved"
|
|
7
|
+
| "denied"
|
|
8
|
+
| "failed"
|
|
9
|
+
| "rolled_back"
|
|
10
|
+
| "timed_out";
|
|
11
|
+
|
|
12
|
+
/** A status that is terminal (no longer pending). */
|
|
13
|
+
export type ResolvedStatus = Exclude<ActionStatus, "pending_approval">;
|
|
14
|
+
|
|
15
|
+
/** Single source of truth for every ActionStatus value. */
|
|
16
|
+
export const ALL_STATUSES = [
|
|
17
|
+
"pending_approval",
|
|
18
|
+
"approved",
|
|
19
|
+
"executed",
|
|
20
|
+
"auto_approved",
|
|
21
|
+
"denied",
|
|
22
|
+
"failed",
|
|
23
|
+
"rolled_back",
|
|
24
|
+
"timed_out",
|
|
25
|
+
] as const satisfies readonly ActionStatus[];
|
|
26
|
+
|
|
27
|
+
/** All statuses that are terminal (no longer pending). */
|
|
28
|
+
export const RESOLVED_STATUSES: ReadonlySet<ActionStatus> = new Set<ActionStatus>(
|
|
29
|
+
ALL_STATUSES.filter((s): s is ResolvedStatus => s !== "pending_approval"),
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
/** Shape returned by action tools in the tool result. */
|
|
33
|
+
export interface ActionToolResultShape {
|
|
34
|
+
status: ActionStatus;
|
|
35
|
+
actionId: string;
|
|
36
|
+
summary?: string;
|
|
37
|
+
details?: Record<string, unknown>;
|
|
38
|
+
result?: unknown;
|
|
39
|
+
reason?: string;
|
|
40
|
+
error?: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** API response when approving or denying an action. */
|
|
44
|
+
export interface ActionApprovalResponse {
|
|
45
|
+
actionId: string;
|
|
46
|
+
status: ActionStatus;
|
|
47
|
+
result?: unknown;
|
|
48
|
+
error?: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** All valid ActionStatus values (derived from ALL_STATUSES). */
|
|
52
|
+
const VALID_STATUSES: ReadonlySet<ActionStatus> = new Set<ActionStatus>(ALL_STATUSES);
|
|
53
|
+
|
|
54
|
+
/** Type guard: returns true if `result` looks like an action tool result. */
|
|
55
|
+
export function isActionToolResult(result: unknown): result is ActionToolResultShape {
|
|
56
|
+
if (result == null || typeof result !== "object") return false;
|
|
57
|
+
const r = result as Record<string, unknown>;
|
|
58
|
+
return (
|
|
59
|
+
typeof r.actionId === "string" &&
|
|
60
|
+
typeof r.status === "string" &&
|
|
61
|
+
VALID_STATUSES.has(r.status as ActionStatus)
|
|
62
|
+
);
|
|
63
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/** Extract tool invocation input from a ToolUIPart. Returns empty object if unavailable. */
|
|
2
|
+
export function getToolArgs(part: unknown): Record<string, unknown> {
|
|
3
|
+
if (part == null || typeof part !== "object") return {};
|
|
4
|
+
const input = (part as Record<string, unknown>).input;
|
|
5
|
+
if (input == null || typeof input !== "object") return {};
|
|
6
|
+
return input as Record<string, unknown>;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** Extract tool output from a ToolUIPart. Returns null if not yet available. */
|
|
10
|
+
export function getToolResult(part: unknown): unknown {
|
|
11
|
+
if (part == null || typeof part !== "object") return null;
|
|
12
|
+
return (part as Record<string, unknown>).output ?? null;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** True when the tool invocation has finished successfully (state is "output-available"). */
|
|
16
|
+
export function isToolComplete(part: unknown): boolean {
|
|
17
|
+
if (part == null || typeof part !== "object") return false;
|
|
18
|
+
return (part as Record<string, unknown>).state === "output-available";
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Parse a CSV string into headers + rows. Handles basic quoting and escaped quotes (""). */
|
|
22
|
+
export function parseCSV(csv: string): { headers: string[]; rows: string[][] } {
|
|
23
|
+
if (!csv || !csv.trim()) return { headers: [], rows: [] };
|
|
24
|
+
|
|
25
|
+
const lines = csv.trim().split("\n");
|
|
26
|
+
if (lines.length === 0) return { headers: [], rows: [] };
|
|
27
|
+
|
|
28
|
+
function parseLine(line: string): string[] {
|
|
29
|
+
const result: string[] = [];
|
|
30
|
+
let current = "";
|
|
31
|
+
let inQuotes = false;
|
|
32
|
+
for (let k = 0; k < line.length; k++) {
|
|
33
|
+
const char = line[k];
|
|
34
|
+
if (char === '"') {
|
|
35
|
+
if (inQuotes && line[k + 1] === '"') {
|
|
36
|
+
current += '"';
|
|
37
|
+
k++;
|
|
38
|
+
} else {
|
|
39
|
+
inQuotes = !inQuotes;
|
|
40
|
+
}
|
|
41
|
+
} else if (char === "," && !inQuotes) {
|
|
42
|
+
result.push(current.trim());
|
|
43
|
+
current = "";
|
|
44
|
+
} else {
|
|
45
|
+
current += char;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
result.push(current.trim());
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
headers: parseLine(lines[0]),
|
|
54
|
+
rows: lines
|
|
55
|
+
.slice(1)
|
|
56
|
+
.filter((l) => l.trim())
|
|
57
|
+
.map(parseLine),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Serialize columns + rows to a CSV string. Handles commas, quotes, and newlines in values. */
|
|
62
|
+
export function toCsvString(columns: string[], rows: Record<string, unknown>[]): string {
|
|
63
|
+
const escape = (v: unknown) => {
|
|
64
|
+
const s = v == null ? "" : String(v);
|
|
65
|
+
return s.includes(",") || s.includes('"') || s.includes("\n")
|
|
66
|
+
? `"${s.replace(/"/g, '""')}"`
|
|
67
|
+
: s;
|
|
68
|
+
};
|
|
69
|
+
const header = columns.map(escape).join(",");
|
|
70
|
+
const body = rows.map((row) => columns.map((col) => escape(row[col])).join(","));
|
|
71
|
+
return [header, ...body].join("\n");
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Trigger a CSV download in the browser. */
|
|
75
|
+
export function downloadCSV(csv: string, filename = "atlas-results.csv") {
|
|
76
|
+
let url: string | null = null;
|
|
77
|
+
try {
|
|
78
|
+
const blob = new Blob([csv], { type: "text/csv" });
|
|
79
|
+
url = URL.createObjectURL(blob);
|
|
80
|
+
const a = document.createElement("a");
|
|
81
|
+
a.href = url;
|
|
82
|
+
a.download = filename;
|
|
83
|
+
a.click();
|
|
84
|
+
} catch (err) {
|
|
85
|
+
console.error("CSV download failed:", err);
|
|
86
|
+
window.alert("CSV download failed");
|
|
87
|
+
} finally {
|
|
88
|
+
if (url) {
|
|
89
|
+
const blobUrl = url;
|
|
90
|
+
setTimeout(() => URL.revokeObjectURL(blobUrl), 10_000);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Format a cell value: null as em-dash, numbers with locale formatting, else stringified. */
|
|
96
|
+
export function formatCell(value: unknown): string {
|
|
97
|
+
if (value == null) return "\u2014";
|
|
98
|
+
if (typeof value === "number") {
|
|
99
|
+
return Number.isInteger(value)
|
|
100
|
+
? value.toLocaleString()
|
|
101
|
+
: value.toLocaleString(undefined, { maximumFractionDigits: 2 });
|
|
102
|
+
}
|
|
103
|
+
return String(value);
|
|
104
|
+
}
|