@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,695 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BIRD Benchmark harness for Atlas text-to-SQL accuracy measurement.
|
|
3
|
+
*
|
|
4
|
+
* Runs the BIRD dev set (~1500 questions across 11 SQLite databases),
|
|
5
|
+
* using DuckDB + sqlite_scanner to load each database, the Atlas agent
|
|
6
|
+
* to generate SQL, and bun:sqlite to execute gold SQL. Result sets are
|
|
7
|
+
* compared order-insensitive with type coercion.
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* bun run atlas -- benchmark --bird-path ./bird-dev
|
|
11
|
+
* bun run atlas -- benchmark --bird-path ./bird-dev --limit 10
|
|
12
|
+
* bun run atlas -- benchmark --bird-path ./bird-dev --db california_schools
|
|
13
|
+
* bun run atlas -- benchmark --bird-path ./bird-dev --csv
|
|
14
|
+
* bun run atlas -- benchmark --bird-path ./bird-dev --resume results.jsonl
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import * as fs from "fs";
|
|
18
|
+
import * as path from "path";
|
|
19
|
+
import {
|
|
20
|
+
getFlag,
|
|
21
|
+
generateEntityYAML,
|
|
22
|
+
generateCatalogYAML,
|
|
23
|
+
generateGlossaryYAML,
|
|
24
|
+
type TableProfile,
|
|
25
|
+
type ColumnProfile,
|
|
26
|
+
} from "./atlas";
|
|
27
|
+
import { connections, type DBConnection, type QueryResult } from "@atlas/api/lib/db/connection";
|
|
28
|
+
import { _resetWhitelists } from "@atlas/api/lib/semantic";
|
|
29
|
+
import { invalidateExploreBackend } from "@atlas/api/lib/tools/explore";
|
|
30
|
+
|
|
31
|
+
// --- Types ---
|
|
32
|
+
|
|
33
|
+
interface BIRDQuestion {
|
|
34
|
+
question_id: number;
|
|
35
|
+
db_id: string;
|
|
36
|
+
question: string;
|
|
37
|
+
evidence: string;
|
|
38
|
+
SQL: string;
|
|
39
|
+
difficulty: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface QuestionResult {
|
|
43
|
+
question_id: number;
|
|
44
|
+
db_id: string;
|
|
45
|
+
question: string;
|
|
46
|
+
difficulty: string;
|
|
47
|
+
gold_sql: string;
|
|
48
|
+
predicted_sql: string | null;
|
|
49
|
+
match: boolean;
|
|
50
|
+
error: string | null;
|
|
51
|
+
latency_ms: number;
|
|
52
|
+
tokens: number;
|
|
53
|
+
steps: number;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// --- Result set comparison (re-exported from shared module) ---
|
|
57
|
+
|
|
58
|
+
import { escapeIdent, compareResultSets } from "../lib/compare";
|
|
59
|
+
export { escapeIdent, normalizeValue, sortRows, valuesMatch, compareResultSets, explainMismatch } from "../lib/compare";
|
|
60
|
+
|
|
61
|
+
// --- Gold SQL execution (bun:sqlite) ---
|
|
62
|
+
|
|
63
|
+
export function executeGoldSQL(
|
|
64
|
+
sqlitePath: string,
|
|
65
|
+
sql: string,
|
|
66
|
+
): { columns: string[]; rows: Record<string, unknown>[] } {
|
|
67
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
68
|
+
const { Database } = require("bun:sqlite");
|
|
69
|
+
const db = new Database(sqlitePath, { readonly: true });
|
|
70
|
+
try {
|
|
71
|
+
const stmt = db.prepare(sql);
|
|
72
|
+
const rows = stmt.all() as Record<string, unknown>[];
|
|
73
|
+
const columns = rows.length > 0 ? Object.keys(rows[0]) : stmt.columnNames ?? [];
|
|
74
|
+
return { columns, rows };
|
|
75
|
+
} finally {
|
|
76
|
+
db.close();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// --- DuckDB helpers ---
|
|
81
|
+
|
|
82
|
+
async function loadDuckDB() {
|
|
83
|
+
const { DuckDBInstance } = await import("@duckdb/node-api");
|
|
84
|
+
return DuckDBInstance;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async function duckdbQuery<T = Record<string, unknown>>(
|
|
88
|
+
conn: unknown,
|
|
89
|
+
sql: string,
|
|
90
|
+
): Promise<T[]> {
|
|
91
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
92
|
+
const reader = await (conn as any).runAndReadAll(sql);
|
|
93
|
+
return reader.getRowObjects() as T[];
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Build a DBConnection wrapper around a DuckDB connection.
|
|
98
|
+
*/
|
|
99
|
+
function wrapDuckDBConnection(conn: unknown): DBConnection {
|
|
100
|
+
return {
|
|
101
|
+
async query(sql: string): Promise<QueryResult> {
|
|
102
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
103
|
+
const reader = await (conn as any).runAndReadAll(sql);
|
|
104
|
+
const columns: string[] = reader.columnNames();
|
|
105
|
+
const rows: Record<string, unknown>[] = reader.getRowObjects();
|
|
106
|
+
return { columns, rows };
|
|
107
|
+
},
|
|
108
|
+
async close(): Promise<void> {
|
|
109
|
+
// DuckDB lifecycle managed externally by closeDuckDB() — intentional no-op.
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// --- Lightweight profiler for DuckDB tables ---
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Profile tables in an already-connected DuckDB instance.
|
|
118
|
+
* Uses information_schema queries — no external DB connection needed.
|
|
119
|
+
*/
|
|
120
|
+
async function profileFromConnection(
|
|
121
|
+
conn: unknown,
|
|
122
|
+
tableNames: string[],
|
|
123
|
+
): Promise<TableProfile[]> {
|
|
124
|
+
const profiles: TableProfile[] = [];
|
|
125
|
+
|
|
126
|
+
for (const tableName of tableNames) {
|
|
127
|
+
const countRows = await duckdbQuery<{ c: number | bigint }>(
|
|
128
|
+
conn,
|
|
129
|
+
`SELECT COUNT(*) as c FROM ${escapeIdent(tableName)}`,
|
|
130
|
+
);
|
|
131
|
+
const rowCount = Number(countRows[0].c);
|
|
132
|
+
|
|
133
|
+
const colRows = await duckdbQuery<{
|
|
134
|
+
column_name: string;
|
|
135
|
+
data_type: string;
|
|
136
|
+
is_nullable: string;
|
|
137
|
+
}>(
|
|
138
|
+
conn,
|
|
139
|
+
`SELECT column_name, data_type, is_nullable
|
|
140
|
+
FROM information_schema.columns
|
|
141
|
+
WHERE table_name = '${tableName.replace(/'/g, "''")}' AND table_schema = 'main'
|
|
142
|
+
ORDER BY ordinal_position`,
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
const columns: ColumnProfile[] = [];
|
|
146
|
+
for (const col of colRows) {
|
|
147
|
+
let uniqueCount: number | null = null;
|
|
148
|
+
let nullCount: number | null = null;
|
|
149
|
+
let sampleValues: string[] = [];
|
|
150
|
+
let isEnumLike = false;
|
|
151
|
+
|
|
152
|
+
try {
|
|
153
|
+
const stats = await duckdbQuery<{ u: number | bigint; n: number | bigint }>(
|
|
154
|
+
conn,
|
|
155
|
+
`SELECT COUNT(DISTINCT ${escapeIdent(col.column_name)}) as u, COUNT(*) - COUNT(${escapeIdent(col.column_name)}) as n FROM ${escapeIdent(tableName)}`,
|
|
156
|
+
);
|
|
157
|
+
uniqueCount = Number(stats[0].u);
|
|
158
|
+
nullCount = Number(stats[0].n);
|
|
159
|
+
|
|
160
|
+
// Enum-like: text columns with <=20 unique values and low cardinality
|
|
161
|
+
const mappedType = mapDuckDBType(col.data_type);
|
|
162
|
+
if (
|
|
163
|
+
mappedType === "string" &&
|
|
164
|
+
uniqueCount > 0 &&
|
|
165
|
+
uniqueCount <= 20 &&
|
|
166
|
+
rowCount > 0
|
|
167
|
+
) {
|
|
168
|
+
const cardinality = uniqueCount / rowCount;
|
|
169
|
+
if (cardinality < 0.05 || uniqueCount <= 10) {
|
|
170
|
+
isEnumLike = true;
|
|
171
|
+
const enumRows = await duckdbQuery<{ v: string }>(
|
|
172
|
+
conn,
|
|
173
|
+
`SELECT DISTINCT CAST(${escapeIdent(col.column_name)} AS VARCHAR) as v FROM ${escapeIdent(tableName)} WHERE ${escapeIdent(col.column_name)} IS NOT NULL ORDER BY v LIMIT 20`,
|
|
174
|
+
);
|
|
175
|
+
sampleValues = enumRows.map((r) => String(r.v));
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (!isEnumLike) {
|
|
180
|
+
const sampleRows = await duckdbQuery<{ v: string }>(
|
|
181
|
+
conn,
|
|
182
|
+
`SELECT DISTINCT CAST(${escapeIdent(col.column_name)} AS VARCHAR) as v FROM ${escapeIdent(tableName)} WHERE ${escapeIdent(col.column_name)} IS NOT NULL LIMIT 5`,
|
|
183
|
+
);
|
|
184
|
+
sampleValues = sampleRows.map((r) => String(r.v));
|
|
185
|
+
}
|
|
186
|
+
} catch (err) {
|
|
187
|
+
process.stderr.write(` WARNING: Failed to profile column "${col.column_name}" in "${tableName}": ${err instanceof Error ? err.message : String(err)}\n`);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
columns.push({
|
|
191
|
+
name: col.column_name,
|
|
192
|
+
type: col.data_type,
|
|
193
|
+
nullable: col.is_nullable === "YES",
|
|
194
|
+
unique_count: uniqueCount,
|
|
195
|
+
null_count: nullCount,
|
|
196
|
+
sample_values: sampleValues,
|
|
197
|
+
is_primary_key: false,
|
|
198
|
+
is_foreign_key: false,
|
|
199
|
+
fk_target_table: null,
|
|
200
|
+
fk_target_column: null,
|
|
201
|
+
is_enum_like: isEnumLike,
|
|
202
|
+
profiler_notes: [],
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
profiles.push({
|
|
207
|
+
table_name: tableName,
|
|
208
|
+
object_type: "table",
|
|
209
|
+
row_count: rowCount,
|
|
210
|
+
columns,
|
|
211
|
+
primary_key_columns: [],
|
|
212
|
+
foreign_keys: [],
|
|
213
|
+
inferred_foreign_keys: [],
|
|
214
|
+
profiler_notes: [],
|
|
215
|
+
table_flags: {
|
|
216
|
+
possibly_abandoned: false,
|
|
217
|
+
possibly_denormalized: false,
|
|
218
|
+
},
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
return profiles;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export function mapDuckDBType(duckType: string): string {
|
|
226
|
+
const t = duckType.toLowerCase();
|
|
227
|
+
if (
|
|
228
|
+
t.includes("int") || t.includes("float") || t.includes("double") ||
|
|
229
|
+
t.includes("decimal") || t.includes("numeric") || t.includes("real") ||
|
|
230
|
+
t === "hugeint" || t === "uhugeint"
|
|
231
|
+
) return "number";
|
|
232
|
+
if (t.startsWith("bool")) return "boolean";
|
|
233
|
+
if (t.includes("date") || t.includes("time") || t.includes("timestamp")) return "date";
|
|
234
|
+
return "string";
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// --- Semantic layer backup/restore ---
|
|
238
|
+
|
|
239
|
+
const SEMANTIC_DIR = path.resolve("semantic");
|
|
240
|
+
const BACKUP_DIR = path.resolve(".semantic-backup-benchmark");
|
|
241
|
+
|
|
242
|
+
function backupSemanticLayer(): void {
|
|
243
|
+
if (fs.existsSync(BACKUP_DIR)) {
|
|
244
|
+
fs.rmSync(BACKUP_DIR, { recursive: true });
|
|
245
|
+
}
|
|
246
|
+
if (fs.existsSync(SEMANTIC_DIR)) {
|
|
247
|
+
fs.cpSync(SEMANTIC_DIR, BACKUP_DIR, { recursive: true });
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function restoreSemanticLayer(): void {
|
|
252
|
+
if (fs.existsSync(BACKUP_DIR)) {
|
|
253
|
+
if (fs.existsSync(SEMANTIC_DIR)) {
|
|
254
|
+
fs.rmSync(SEMANTIC_DIR, { recursive: true });
|
|
255
|
+
}
|
|
256
|
+
fs.cpSync(BACKUP_DIR, SEMANTIC_DIR, { recursive: true });
|
|
257
|
+
fs.rmSync(BACKUP_DIR, { recursive: true });
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function clearSemanticDir(): void {
|
|
262
|
+
const entitiesDir = path.join(SEMANTIC_DIR, "entities");
|
|
263
|
+
const metricsDir = path.join(SEMANTIC_DIR, "metrics");
|
|
264
|
+
for (const dir of [entitiesDir, metricsDir]) {
|
|
265
|
+
if (fs.existsSync(dir)) {
|
|
266
|
+
for (const f of fs.readdirSync(dir)) {
|
|
267
|
+
if (f.endsWith(".yml")) fs.unlinkSync(path.join(dir, f));
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// --- Per-database setup ---
|
|
274
|
+
|
|
275
|
+
interface DatabaseSetupResult {
|
|
276
|
+
instance: unknown;
|
|
277
|
+
conn: unknown;
|
|
278
|
+
dbConnection: DBConnection;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
async function setupDatabase(
|
|
282
|
+
dbId: string,
|
|
283
|
+
devDbDir: string,
|
|
284
|
+
): Promise<DatabaseSetupResult> {
|
|
285
|
+
const sqlitePath = path.join(devDbDir, dbId, `${dbId}.sqlite`);
|
|
286
|
+
if (!fs.existsSync(sqlitePath)) {
|
|
287
|
+
throw new Error(`SQLite file not found: ${sqlitePath}`);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
const DuckDBInstance = await loadDuckDB();
|
|
291
|
+
const instance = await DuckDBInstance.create(":memory:");
|
|
292
|
+
const conn = await instance.connect();
|
|
293
|
+
|
|
294
|
+
// Install and load sqlite_scanner
|
|
295
|
+
await duckdbQuery(conn, "INSTALL sqlite_scanner");
|
|
296
|
+
await duckdbQuery(conn, "LOAD sqlite_scanner");
|
|
297
|
+
|
|
298
|
+
// Attach SQLite file read-only
|
|
299
|
+
await duckdbQuery(
|
|
300
|
+
conn,
|
|
301
|
+
`ATTACH '${sqlitePath.replace(/'/g, "''")}' AS bird_src (TYPE sqlite, READ_ONLY)`,
|
|
302
|
+
);
|
|
303
|
+
|
|
304
|
+
// Discover tables in the attached SQLite database via sqlite_master
|
|
305
|
+
// (information_schema uses table_catalog for attached DBs in DuckDB,
|
|
306
|
+
// but sqlite_master is simpler and always works for attached SQLite files)
|
|
307
|
+
const sqliteTables = await duckdbQuery<{ name: string }>(
|
|
308
|
+
conn,
|
|
309
|
+
`SELECT name FROM bird_src.sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%'`,
|
|
310
|
+
);
|
|
311
|
+
const tableNames = sqliteTables.map((t) => t.name);
|
|
312
|
+
|
|
313
|
+
if (tableNames.length === 0) {
|
|
314
|
+
throw new Error(`No tables found in SQLite database: ${sqlitePath}`);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// Copy tables into DuckDB main schema
|
|
318
|
+
for (const table of tableNames) {
|
|
319
|
+
await duckdbQuery(
|
|
320
|
+
conn,
|
|
321
|
+
`CREATE TABLE main.${escapeIdent(table)} AS SELECT * FROM bird_src.${escapeIdent(table)}`,
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// Detach SQLite source
|
|
326
|
+
await duckdbQuery(conn, "DETACH bird_src");
|
|
327
|
+
|
|
328
|
+
// Build DBConnection wrapper
|
|
329
|
+
const dbConnection = wrapDuckDBConnection(conn);
|
|
330
|
+
|
|
331
|
+
// Register in ConnectionRegistry
|
|
332
|
+
connections._reset();
|
|
333
|
+
connections.registerDirect("default", dbConnection, "duckdb");
|
|
334
|
+
|
|
335
|
+
// Profile tables and generate semantic layer
|
|
336
|
+
const profiles = await profileFromConnection(conn, tableNames);
|
|
337
|
+
|
|
338
|
+
// Write YAMLs
|
|
339
|
+
clearSemanticDir();
|
|
340
|
+
const entitiesDir = path.join(SEMANTIC_DIR, "entities");
|
|
341
|
+
const metricsDir = path.join(SEMANTIC_DIR, "metrics");
|
|
342
|
+
fs.mkdirSync(entitiesDir, { recursive: true });
|
|
343
|
+
fs.mkdirSync(metricsDir, { recursive: true });
|
|
344
|
+
|
|
345
|
+
for (const profile of profiles) {
|
|
346
|
+
const entityYaml = generateEntityYAML(profile, profiles, "duckdb", "main");
|
|
347
|
+
fs.writeFileSync(path.join(entitiesDir, `${profile.table_name}.yml`), entityYaml);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
fs.writeFileSync(path.join(SEMANTIC_DIR, "catalog.yml"), generateCatalogYAML(profiles));
|
|
351
|
+
fs.writeFileSync(path.join(SEMANTIC_DIR, "glossary.yml"), generateGlossaryYAML(profiles));
|
|
352
|
+
|
|
353
|
+
// Refresh caches
|
|
354
|
+
_resetWhitelists();
|
|
355
|
+
invalidateExploreBackend();
|
|
356
|
+
|
|
357
|
+
return { instance, conn, dbConnection };
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
function closeDuckDB(instance: unknown, conn: unknown): void {
|
|
361
|
+
try {
|
|
362
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
363
|
+
(conn as any).disconnectSync();
|
|
364
|
+
} catch (err) {
|
|
365
|
+
process.stderr.write(`WARNING: DuckDB disconnect failed: ${err instanceof Error ? err.message : String(err)}\n`);
|
|
366
|
+
}
|
|
367
|
+
try {
|
|
368
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
369
|
+
(instance as any).closeSync();
|
|
370
|
+
} catch (err) {
|
|
371
|
+
process.stderr.write(`WARNING: DuckDB close failed: ${err instanceof Error ? err.message : String(err)}\n`);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// --- Question evaluation ---
|
|
376
|
+
|
|
377
|
+
async function evaluateQuestion(
|
|
378
|
+
q: BIRDQuestion,
|
|
379
|
+
devDbDir: string,
|
|
380
|
+
): Promise<QuestionResult> {
|
|
381
|
+
const start = Date.now();
|
|
382
|
+
|
|
383
|
+
try {
|
|
384
|
+
// Build question text with evidence hint
|
|
385
|
+
let questionText = q.question;
|
|
386
|
+
if (q.evidence && q.evidence.trim()) {
|
|
387
|
+
questionText += `\n\nHint: ${q.evidence}`;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// Run agent
|
|
391
|
+
const { executeAgentQuery } = await import("@atlas/api/lib/agent-query");
|
|
392
|
+
const result = await executeAgentQuery(questionText);
|
|
393
|
+
|
|
394
|
+
const latencyMs = Date.now() - start;
|
|
395
|
+
const predictedSql = result.sql.length > 0 ? result.sql[result.sql.length - 1] : null;
|
|
396
|
+
|
|
397
|
+
// Execute gold SQL via bun:sqlite
|
|
398
|
+
const sqlitePath = path.join(devDbDir, q.db_id, `${q.db_id}.sqlite`);
|
|
399
|
+
const goldResult = executeGoldSQL(sqlitePath, q.SQL);
|
|
400
|
+
|
|
401
|
+
// Get predicted result (agent already executed it)
|
|
402
|
+
const predictedResult = result.data.length > 0 ? result.data[result.data.length - 1] : null;
|
|
403
|
+
|
|
404
|
+
let match = false;
|
|
405
|
+
if (predictedResult) {
|
|
406
|
+
match = compareResultSets(goldResult, predictedResult);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
return {
|
|
410
|
+
question_id: q.question_id,
|
|
411
|
+
db_id: q.db_id,
|
|
412
|
+
question: q.question,
|
|
413
|
+
difficulty: q.difficulty,
|
|
414
|
+
gold_sql: q.SQL,
|
|
415
|
+
predicted_sql: predictedSql,
|
|
416
|
+
match,
|
|
417
|
+
error: null,
|
|
418
|
+
latency_ms: latencyMs,
|
|
419
|
+
tokens: result.usage.totalTokens,
|
|
420
|
+
steps: result.steps,
|
|
421
|
+
};
|
|
422
|
+
} catch (err) {
|
|
423
|
+
process.stderr.write(`\n ERROR evaluating Q${q.question_id}: ${err instanceof Error && err.stack ? err.stack : String(err)}\n`);
|
|
424
|
+
return {
|
|
425
|
+
question_id: q.question_id,
|
|
426
|
+
db_id: q.db_id,
|
|
427
|
+
question: q.question,
|
|
428
|
+
difficulty: q.difficulty,
|
|
429
|
+
gold_sql: q.SQL,
|
|
430
|
+
predicted_sql: null,
|
|
431
|
+
match: false,
|
|
432
|
+
error: err instanceof Error ? err.message : String(err),
|
|
433
|
+
latency_ms: Date.now() - start,
|
|
434
|
+
tokens: 0,
|
|
435
|
+
steps: 0,
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
// --- Summary printing ---
|
|
441
|
+
|
|
442
|
+
function printSummary(results: QuestionResult[], csvOutput: boolean): void {
|
|
443
|
+
if (csvOutput) {
|
|
444
|
+
console.log("question_id,db_id,difficulty,match,predicted_sql,gold_sql,error,latency_ms,tokens,steps");
|
|
445
|
+
for (const r of results) {
|
|
446
|
+
const csvSafe = (s: string | null) =>
|
|
447
|
+
s ? `"${s.replace(/"/g, '""').replace(/\n/g, " ")}"` : "";
|
|
448
|
+
console.log(
|
|
449
|
+
[
|
|
450
|
+
r.question_id,
|
|
451
|
+
r.db_id,
|
|
452
|
+
r.difficulty,
|
|
453
|
+
r.match,
|
|
454
|
+
csvSafe(r.predicted_sql),
|
|
455
|
+
csvSafe(r.gold_sql),
|
|
456
|
+
csvSafe(r.error),
|
|
457
|
+
r.latency_ms,
|
|
458
|
+
r.tokens,
|
|
459
|
+
r.steps,
|
|
460
|
+
].join(","),
|
|
461
|
+
);
|
|
462
|
+
}
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
const total = results.length;
|
|
467
|
+
const correct = results.filter((r) => r.match).length;
|
|
468
|
+
const errors = results.filter((r) => r.error).length;
|
|
469
|
+
const accuracy = total > 0 ? ((correct / total) * 100).toFixed(1) : "0.0";
|
|
470
|
+
|
|
471
|
+
console.log("\n" + "=".repeat(60));
|
|
472
|
+
console.log("BIRD Benchmark Results");
|
|
473
|
+
console.log("=".repeat(60));
|
|
474
|
+
console.log(`Total: ${total}`);
|
|
475
|
+
console.log(`Correct: ${correct}`);
|
|
476
|
+
console.log(`Errors: ${errors}`);
|
|
477
|
+
console.log(`Accuracy: ${accuracy}%`);
|
|
478
|
+
|
|
479
|
+
// Per-database breakdown
|
|
480
|
+
const byDb = new Map<string, QuestionResult[]>();
|
|
481
|
+
for (const r of results) {
|
|
482
|
+
const arr = byDb.get(r.db_id) ?? [];
|
|
483
|
+
arr.push(r);
|
|
484
|
+
byDb.set(r.db_id, arr);
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
if (byDb.size > 1) {
|
|
488
|
+
console.log("\nPer-database:");
|
|
489
|
+
for (const [dbId, dbResults] of [...byDb.entries()].sort((a, b) => a[0].localeCompare(b[0]))) {
|
|
490
|
+
const dbCorrect = dbResults.filter((r) => r.match).length;
|
|
491
|
+
const dbAcc = ((dbCorrect / dbResults.length) * 100).toFixed(1);
|
|
492
|
+
console.log(` ${dbId.padEnd(30)} ${dbCorrect}/${dbResults.length} (${dbAcc}%)`);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
// Per-difficulty breakdown
|
|
497
|
+
const byDiff = new Map<string, QuestionResult[]>();
|
|
498
|
+
for (const r of results) {
|
|
499
|
+
const arr = byDiff.get(r.difficulty) ?? [];
|
|
500
|
+
arr.push(r);
|
|
501
|
+
byDiff.set(r.difficulty, arr);
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
if (byDiff.size > 1) {
|
|
505
|
+
console.log("\nPer-difficulty:");
|
|
506
|
+
for (const [diff, diffResults] of [...byDiff.entries()].sort((a, b) => a[0].localeCompare(b[0]))) {
|
|
507
|
+
const diffCorrect = diffResults.filter((r) => r.match).length;
|
|
508
|
+
const diffAcc = ((diffCorrect / diffResults.length) * 100).toFixed(1);
|
|
509
|
+
console.log(` ${diff.padEnd(15)} ${diffCorrect}/${diffResults.length} (${diffAcc}%)`);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
// Token and latency stats
|
|
514
|
+
const totalTokens = results.reduce((s, r) => s + r.tokens, 0);
|
|
515
|
+
const totalLatency = results.reduce((s, r) => s + r.latency_ms, 0);
|
|
516
|
+
const avgLatency = total > 0 ? Math.round(totalLatency / total) : 0;
|
|
517
|
+
console.log(`\nTotal tokens: ${totalTokens.toLocaleString()}`);
|
|
518
|
+
console.log(`Avg latency: ${avgLatency.toLocaleString()}ms`);
|
|
519
|
+
console.log("=".repeat(60));
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
// --- Main entry point ---
|
|
523
|
+
|
|
524
|
+
export async function handleBenchmark(args: string[]): Promise<void> {
|
|
525
|
+
const birdPath = getFlag(args, "--bird-path");
|
|
526
|
+
if (!birdPath) {
|
|
527
|
+
console.error(
|
|
528
|
+
"Usage: atlas benchmark --bird-path <path> [options]\n\n" +
|
|
529
|
+
"Options:\n" +
|
|
530
|
+
" --bird-path <path> Path to BIRD dev directory (required)\n" +
|
|
531
|
+
" --limit <n> Max questions to evaluate\n" +
|
|
532
|
+
" --db <name> Filter to a single database\n" +
|
|
533
|
+
" --csv CSV output\n" +
|
|
534
|
+
" --resume <file> Resume from existing JSONL results file",
|
|
535
|
+
);
|
|
536
|
+
process.exit(1);
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
const limitArg = getFlag(args, "--limit");
|
|
540
|
+
const limit = limitArg ? parseInt(limitArg, 10) : undefined;
|
|
541
|
+
const dbFilter = getFlag(args, "--db");
|
|
542
|
+
const csvOutput = args.includes("--csv");
|
|
543
|
+
const resumeFile = getFlag(args, "--resume");
|
|
544
|
+
|
|
545
|
+
// Locate BIRD files
|
|
546
|
+
const devJsonPath = path.resolve(birdPath, "dev.json");
|
|
547
|
+
const devDbDir = path.resolve(birdPath, "dev_databases");
|
|
548
|
+
|
|
549
|
+
if (!fs.existsSync(devJsonPath)) {
|
|
550
|
+
console.error(`Error: dev.json not found at ${devJsonPath}`);
|
|
551
|
+
console.error(" Expected BIRD directory structure:");
|
|
552
|
+
console.error(" <bird-path>/dev.json");
|
|
553
|
+
console.error(" <bird-path>/dev_databases/<db_id>/<db_id>.sqlite");
|
|
554
|
+
process.exit(1);
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
if (!fs.existsSync(devDbDir)) {
|
|
558
|
+
console.error(`Error: dev_databases directory not found at ${devDbDir}`);
|
|
559
|
+
process.exit(1);
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
// Load questions
|
|
563
|
+
const allQuestions: BIRDQuestion[] = JSON.parse(
|
|
564
|
+
fs.readFileSync(devJsonPath, "utf-8"),
|
|
565
|
+
);
|
|
566
|
+
|
|
567
|
+
// Filter by database
|
|
568
|
+
let questions = dbFilter
|
|
569
|
+
? allQuestions.filter((q) => q.db_id === dbFilter)
|
|
570
|
+
: allQuestions;
|
|
571
|
+
|
|
572
|
+
if (questions.length === 0) {
|
|
573
|
+
console.error(`Error: No questions found${dbFilter ? ` for database "${dbFilter}"` : ""}.`);
|
|
574
|
+
if (dbFilter) {
|
|
575
|
+
const dbIds = [...new Set(allQuestions.map((q) => q.db_id))].sort();
|
|
576
|
+
console.error(` Available databases: ${dbIds.join(", ")}`);
|
|
577
|
+
}
|
|
578
|
+
process.exit(1);
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
// Apply limit
|
|
582
|
+
if (limit && limit > 0) {
|
|
583
|
+
questions = questions.slice(0, limit);
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
// Load completed results for resume
|
|
587
|
+
const completedIds = new Set<number>();
|
|
588
|
+
const allResults: QuestionResult[] = [];
|
|
589
|
+
const resultsFile = resumeFile ?? `benchmark-results-${Date.now()}.jsonl`;
|
|
590
|
+
|
|
591
|
+
if (resumeFile && fs.existsSync(resumeFile)) {
|
|
592
|
+
const lines = fs.readFileSync(resumeFile, "utf-8").split("\n").filter(Boolean);
|
|
593
|
+
let skippedLines = 0;
|
|
594
|
+
for (const line of lines) {
|
|
595
|
+
try {
|
|
596
|
+
const r = JSON.parse(line) as QuestionResult;
|
|
597
|
+
if (typeof r.question_id !== "number" || Number.isNaN(r.question_id)) {
|
|
598
|
+
skippedLines++;
|
|
599
|
+
continue;
|
|
600
|
+
}
|
|
601
|
+
completedIds.add(r.question_id);
|
|
602
|
+
allResults.push(r);
|
|
603
|
+
} catch {
|
|
604
|
+
skippedLines++;
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
if (skippedLines > 0) {
|
|
608
|
+
process.stderr.write(`WARNING: ${skippedLines} malformed line(s) skipped in resume file\n`);
|
|
609
|
+
}
|
|
610
|
+
console.log(`Resuming: ${completedIds.size} questions already completed`);
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
// Group questions by db_id
|
|
614
|
+
const byDb = new Map<string, BIRDQuestion[]>();
|
|
615
|
+
for (const q of questions) {
|
|
616
|
+
if (completedIds.has(q.question_id)) continue;
|
|
617
|
+
const arr = byDb.get(q.db_id) ?? [];
|
|
618
|
+
arr.push(q);
|
|
619
|
+
byDb.set(q.db_id, arr);
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
const completedInScope = questions.filter(q => completedIds.has(q.question_id)).length;
|
|
623
|
+
const remainingCount = questions.length - completedInScope;
|
|
624
|
+
const dbCount = byDb.size;
|
|
625
|
+
console.log(
|
|
626
|
+
`BIRD Benchmark: ${questions.length} questions across ${dbCount} database(s)` +
|
|
627
|
+
(completedIds.size > 0 ? ` (${remainingCount} remaining)` : ""),
|
|
628
|
+
);
|
|
629
|
+
|
|
630
|
+
// Backup semantic layer
|
|
631
|
+
backupSemanticLayer();
|
|
632
|
+
|
|
633
|
+
try {
|
|
634
|
+
let questionIdx = 0;
|
|
635
|
+
|
|
636
|
+
for (const [dbId, dbQuestions] of byDb) {
|
|
637
|
+
console.log(`\n--- Database: ${dbId} (${dbQuestions.length} questions) ---`);
|
|
638
|
+
|
|
639
|
+
let setup: DatabaseSetupResult | null = null;
|
|
640
|
+
try {
|
|
641
|
+
setup = await setupDatabase(dbId, devDbDir);
|
|
642
|
+
|
|
643
|
+
for (const q of dbQuestions) {
|
|
644
|
+
questionIdx++;
|
|
645
|
+
const progress = `[${questionIdx}/${remainingCount}]`;
|
|
646
|
+
process.stderr.write(`${progress} Q${q.question_id} (${q.difficulty}): ${q.question.slice(0, 60)}...`);
|
|
647
|
+
|
|
648
|
+
const result = await evaluateQuestion(q, devDbDir);
|
|
649
|
+
allResults.push(result);
|
|
650
|
+
|
|
651
|
+
// Append to JSONL
|
|
652
|
+
fs.appendFileSync(resultsFile, JSON.stringify(result) + "\n");
|
|
653
|
+
|
|
654
|
+
const status = result.match ? "PASS" : result.error ? "ERROR" : "FAIL";
|
|
655
|
+
process.stderr.write(` ${status} (${result.latency_ms}ms)\n`);
|
|
656
|
+
}
|
|
657
|
+
} catch (dbErr) {
|
|
658
|
+
console.error(
|
|
659
|
+
` Error setting up database ${dbId}: ${dbErr instanceof Error ? dbErr.message : String(dbErr)}`,
|
|
660
|
+
);
|
|
661
|
+
// Mark all questions for this DB as errored
|
|
662
|
+
for (const q of dbQuestions) {
|
|
663
|
+
const errResult: QuestionResult = {
|
|
664
|
+
question_id: q.question_id,
|
|
665
|
+
db_id: q.db_id,
|
|
666
|
+
question: q.question,
|
|
667
|
+
difficulty: q.difficulty,
|
|
668
|
+
gold_sql: q.SQL,
|
|
669
|
+
predicted_sql: null,
|
|
670
|
+
match: false,
|
|
671
|
+
error: `Database setup failed: ${dbErr instanceof Error ? dbErr.message : String(dbErr)}`,
|
|
672
|
+
latency_ms: 0,
|
|
673
|
+
tokens: 0,
|
|
674
|
+
steps: 0,
|
|
675
|
+
};
|
|
676
|
+
allResults.push(errResult);
|
|
677
|
+
fs.appendFileSync(resultsFile, JSON.stringify(errResult) + "\n");
|
|
678
|
+
}
|
|
679
|
+
} finally {
|
|
680
|
+
if (setup) {
|
|
681
|
+
closeDuckDB(setup.instance, setup.conn);
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
} finally {
|
|
686
|
+
restoreSemanticLayer();
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
// Print summary
|
|
690
|
+
printSummary(allResults, csvOutput);
|
|
691
|
+
|
|
692
|
+
if (!csvOutput) {
|
|
693
|
+
console.log(`\nResults saved to: ${resultsFile}`);
|
|
694
|
+
}
|
|
695
|
+
}
|