@useatlas/create 0.0.5 → 0.0.7
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/LICENSE +21 -0
- package/README.md +1 -1
- package/index.ts +253 -36
- package/package.json +4 -4
- package/templates/docker/Dockerfile +1 -1
- package/templates/docker/Dockerfile.sidecar +1 -1
- package/templates/docker/bin/__tests__/duckdb-ingest.test.ts +17 -14
- package/templates/docker/bin/__tests__/failure-threshold.test.ts +148 -0
- package/templates/docker/bin/__tests__/fatal-error-propagation.test.ts +267 -0
- package/templates/docker/bin/__tests__/profiler-heuristics.test.ts +5 -5
- package/templates/docker/bin/__tests__/schema-drift.test.ts +39 -0
- package/templates/docker/bin/atlas.ts +981 -1819
- package/templates/docker/bin/benchmark.ts +14 -16
- package/templates/docker/bin/enrich.ts +7 -2
- package/templates/docker/brand.css +13 -0
- package/templates/docker/data/cybersec-semantic/catalog.yml +222 -0
- package/templates/docker/data/cybersec-semantic/entities/alerts.yml +195 -0
- package/templates/docker/data/cybersec-semantic/entities/assets.yml +191 -0
- package/templates/docker/data/cybersec-semantic/entities/compliance_assessments.yml +170 -0
- package/templates/docker/data/cybersec-semantic/entities/incidents.yml +219 -0
- package/templates/docker/data/cybersec-semantic/entities/organizations.yml +136 -0
- package/templates/docker/data/cybersec-semantic/entities/plans.yml +114 -0
- package/templates/docker/data/cybersec-semantic/entities/remediation_actions.yml +212 -0
- package/templates/docker/data/cybersec-semantic/entities/scan_results.yml +215 -0
- package/templates/docker/data/cybersec-semantic/entities/scans.yml +180 -0
- package/templates/docker/data/cybersec-semantic/entities/subscriptions.yml +184 -0
- package/templates/docker/data/cybersec-semantic/entities/users.yml +140 -0
- package/templates/docker/data/cybersec-semantic/entities/vulnerabilities.yml +154 -0
- package/templates/docker/data/cybersec-semantic/glossary.yml +207 -0
- package/templates/docker/data/cybersec-semantic/metrics/business.yml +148 -0
- package/templates/docker/data/cybersec-semantic/metrics/compliance.yml +138 -0
- package/templates/docker/data/cybersec-semantic/metrics/security.yml +181 -0
- package/templates/docker/data/cybersec.sql +8 -8
- package/templates/docker/data/demo.sql +3 -0
- package/templates/docker/data/ecommerce-semantic/catalog.yml +221 -0
- package/templates/docker/data/ecommerce-semantic/entities/categories.yml +91 -0
- package/templates/docker/data/ecommerce-semantic/entities/customers.yml +133 -0
- package/templates/docker/data/ecommerce-semantic/entities/email_campaigns.yml +119 -0
- package/templates/docker/data/ecommerce-semantic/entities/inventory_levels.yml +153 -0
- package/templates/docker/data/ecommerce-semantic/entities/order_items.yml +159 -0
- package/templates/docker/data/ecommerce-semantic/entities/orders.yml +199 -0
- package/templates/docker/data/ecommerce-semantic/entities/payments.yml +140 -0
- package/templates/docker/data/ecommerce-semantic/entities/product_reviews.yml +155 -0
- package/templates/docker/data/ecommerce-semantic/entities/products.yml +178 -0
- package/templates/docker/data/ecommerce-semantic/entities/promotions.yml +171 -0
- package/templates/docker/data/ecommerce-semantic/entities/returns.yml +144 -0
- package/templates/docker/data/ecommerce-semantic/entities/sellers.yml +124 -0
- package/templates/docker/data/ecommerce-semantic/entities/shipments.yml +159 -0
- package/templates/docker/data/ecommerce-semantic/glossary.yml +193 -0
- package/templates/docker/data/ecommerce-semantic/metrics/customers.yml +116 -0
- package/templates/docker/data/ecommerce-semantic/metrics/operations.yml +131 -0
- package/templates/docker/data/ecommerce-semantic/metrics/revenue.yml +120 -0
- package/templates/docker/docs/deploy.md +2 -1
- package/templates/docker/ee/src/__mocks__/internal.ts +170 -0
- package/templates/docker/ee/src/audit/purge-scheduler.ts +113 -0
- package/templates/docker/ee/src/audit/retention.ts +467 -0
- package/templates/docker/ee/src/auth/ip-allowlist.ts +367 -0
- package/templates/docker/ee/src/auth/roles.ts +562 -0
- package/templates/docker/ee/src/auth/scim.ts +343 -0
- package/templates/docker/ee/src/auth/sso.ts +538 -0
- package/templates/docker/ee/src/backups/engine.ts +355 -0
- package/templates/docker/ee/src/backups/index.ts +26 -0
- package/templates/docker/ee/src/backups/restore.ts +169 -0
- package/templates/docker/ee/src/backups/scheduler.ts +153 -0
- package/templates/docker/ee/src/backups/verify.ts +124 -0
- package/templates/docker/ee/src/branding/white-label.ts +228 -0
- package/templates/docker/ee/src/compliance/masking.ts +477 -0
- package/templates/docker/ee/src/compliance/patterns.ts +16 -0
- package/templates/docker/ee/src/compliance/pii-detection.ts +217 -0
- package/templates/docker/ee/src/compliance/reports.ts +402 -0
- package/templates/docker/ee/src/deploy-mode.ts +37 -0
- package/templates/docker/ee/src/governance/approval.ts +699 -0
- package/templates/docker/ee/src/index.ts +74 -0
- package/templates/docker/ee/src/platform/domains.ts +562 -0
- package/templates/docker/ee/src/platform/model-routing.ts +382 -0
- package/templates/docker/ee/src/platform/residency.ts +265 -0
- package/templates/docker/ee/src/sla/alerting.ts +382 -0
- package/templates/docker/ee/src/sla/index.ts +12 -0
- package/templates/docker/ee/src/sla/metrics.ts +275 -0
- package/templates/docker/ee/src/test-setup.ts +1 -0
- package/templates/docker/next.config.ts +4 -1
- package/templates/docker/package.json +49 -29
- package/templates/docker/sidecar/Dockerfile +1 -1
- package/templates/docker/src/api/index.ts +336 -24
- package/templates/docker/src/api/routes/actions.ts +443 -176
- package/templates/docker/src/api/routes/admin-abuse.ts +219 -0
- package/templates/docker/src/api/routes/admin-approval.ts +418 -0
- package/templates/docker/src/api/routes/admin-audit-retention.ts +405 -0
- package/templates/docker/src/api/routes/admin-auth.ts +122 -0
- package/templates/docker/src/api/routes/admin-branding.ts +252 -0
- package/templates/docker/src/api/routes/admin-compliance.ts +352 -0
- package/templates/docker/src/api/routes/admin-domains.ts +334 -0
- package/templates/docker/src/api/routes/admin-integrations.ts +2667 -0
- package/templates/docker/src/api/routes/admin-ip-allowlist.ts +261 -0
- package/templates/docker/src/api/routes/admin-learned-patterns.ts +525 -0
- package/templates/docker/src/api/routes/admin-model-config.ts +252 -0
- package/templates/docker/src/api/routes/admin-onboarding-emails.ts +145 -0
- package/templates/docker/src/api/routes/admin-orgs.ts +710 -0
- package/templates/docker/src/api/routes/admin-prompts.ts +694 -0
- package/templates/docker/src/api/routes/admin-residency.ts +570 -0
- package/templates/docker/src/api/routes/admin-roles.ts +296 -0
- package/templates/docker/src/api/routes/admin-router.ts +120 -0
- package/templates/docker/src/api/routes/admin-sandbox.ts +417 -0
- package/templates/docker/src/api/routes/admin-scim.ts +262 -0
- package/templates/docker/src/api/routes/admin-sso.ts +545 -0
- package/templates/docker/src/api/routes/admin-suggestions.ts +176 -0
- package/templates/docker/src/api/routes/admin-usage.ts +310 -0
- package/templates/docker/src/api/routes/admin.ts +4156 -898
- package/templates/docker/src/api/routes/auth-preamble.ts +105 -0
- package/templates/docker/src/api/routes/billing.ts +397 -0
- package/templates/docker/src/api/routes/chat.ts +597 -334
- package/templates/docker/src/api/routes/conversations.ts +987 -132
- package/templates/docker/src/api/routes/demo.ts +673 -0
- package/templates/docker/src/api/routes/discord.ts +274 -0
- package/templates/docker/src/api/routes/ee-error-handler.ts +32 -0
- package/templates/docker/src/api/routes/health.ts +129 -14
- package/templates/docker/src/api/routes/middleware.ts +244 -0
- package/templates/docker/src/api/routes/onboarding-emails.ts +134 -0
- package/templates/docker/src/api/routes/onboarding.ts +1109 -0
- package/templates/docker/src/api/routes/openapi.ts +184 -1597
- package/templates/docker/src/api/routes/platform-admin.ts +760 -0
- package/templates/docker/src/api/routes/platform-backups.ts +436 -0
- package/templates/docker/src/api/routes/platform-domains.ts +235 -0
- package/templates/docker/src/api/routes/platform-residency.ts +257 -0
- package/templates/docker/src/api/routes/platform-sla.ts +379 -0
- package/templates/docker/src/api/routes/prompts.ts +221 -0
- package/templates/docker/src/api/routes/public-branding.ts +106 -0
- package/templates/docker/src/api/routes/query.ts +330 -219
- package/templates/docker/src/api/routes/scheduled-tasks.ts +393 -297
- package/templates/docker/src/api/routes/semantic.ts +179 -0
- package/templates/docker/src/api/routes/sessions.ts +210 -0
- package/templates/docker/src/api/routes/shared-domains.ts +98 -0
- package/templates/docker/src/api/routes/shared-schemas.ts +139 -0
- package/templates/docker/src/api/routes/slack.ts +209 -52
- package/templates/docker/src/api/routes/suggestions.ts +233 -0
- package/templates/docker/src/api/routes/tables.ts +67 -0
- package/templates/docker/src/api/routes/teams.ts +222 -0
- package/templates/docker/src/api/routes/validate-sql.ts +188 -0
- package/templates/docker/src/api/routes/validation-hook.ts +62 -0
- package/templates/docker/src/api/routes/widget-loader.ts +356 -0
- package/templates/docker/src/api/routes/widget.ts +428 -0
- package/templates/docker/src/api/routes/wizard.ts +852 -0
- package/templates/docker/src/api/server.ts +187 -69
- package/templates/docker/src/app/error.tsx +5 -2
- package/templates/docker/src/app/globals.css +1 -1
- package/templates/docker/src/app/layout.tsx +7 -2
- package/templates/docker/src/app/page.tsx +39 -5
- package/templates/docker/src/components/data-table/data-table-column-header.tsx +99 -0
- package/templates/docker/src/components/data-table/data-table-date-filter.tsx +225 -0
- package/templates/docker/src/components/data-table/data-table-expandable.tsx +125 -0
- package/templates/docker/src/components/data-table/data-table-faceted-filter.tsx +189 -0
- package/templates/docker/src/components/data-table/data-table-pagination.tsx +112 -0
- package/templates/docker/src/components/data-table/data-table-range-filter.tsx +122 -0
- package/templates/docker/src/components/data-table/data-table-slider-filter.tsx +256 -0
- package/templates/docker/src/components/data-table/data-table-sort-list.tsx +407 -0
- package/templates/docker/src/components/data-table/data-table-toolbar.tsx +149 -0
- package/templates/docker/src/components/data-table/data-table-view-options.tsx +89 -0
- package/templates/docker/src/components/data-table/data-table.tsx +105 -0
- package/templates/docker/src/components/form-dialog.tsx +135 -0
- package/templates/docker/src/components/ui/accordion.tsx +66 -0
- package/templates/docker/src/components/ui/calendar.tsx +220 -0
- package/templates/docker/src/components/ui/checkbox.tsx +32 -0
- package/templates/docker/src/components/ui/faceted.tsx +283 -0
- package/templates/docker/src/components/ui/form.tsx +167 -0
- package/templates/docker/src/components/ui/label.tsx +24 -0
- package/templates/docker/src/components/ui/popover.tsx +89 -0
- package/templates/docker/src/components/ui/progress.tsx +31 -0
- package/templates/docker/src/components/ui/scroll-area.tsx +6 -2
- package/templates/docker/src/components/ui/slider.tsx +63 -0
- package/templates/docker/src/components/ui/sortable.tsx +581 -0
- package/templates/docker/src/components/ui/switch.tsx +35 -0
- package/templates/docker/src/components/ui/textarea.tsx +18 -0
- package/templates/docker/src/config/data-table.ts +82 -0
- package/templates/docker/src/env-check.ts +74 -0
- package/templates/docker/src/hooks/use-callback-ref.ts +27 -0
- package/templates/docker/src/hooks/use-data-table.ts +316 -0
- package/templates/docker/src/hooks/use-debounced-callback.ts +28 -0
- package/templates/docker/src/lib/action-types.ts +7 -41
- package/templates/docker/src/lib/agent-query.ts +4 -2
- package/templates/docker/src/lib/agent.ts +363 -31
- package/templates/docker/src/lib/auth/admin-permissions.ts +38 -0
- package/templates/docker/src/lib/auth/audit.ts +19 -4
- package/templates/docker/src/lib/auth/byot.ts +3 -3
- package/templates/docker/src/lib/auth/client.ts +33 -3
- package/templates/docker/src/lib/auth/detect.ts +29 -8
- package/templates/docker/src/lib/auth/managed.ts +104 -14
- package/templates/docker/src/lib/auth/middleware.ts +53 -6
- package/templates/docker/src/lib/auth/migrate.ts +140 -15
- package/templates/docker/src/lib/auth/oauth-state.ts +123 -0
- package/templates/docker/src/lib/auth/org-permissions.ts +55 -0
- package/templates/docker/src/lib/auth/permissions.ts +26 -19
- package/templates/docker/src/lib/auth/server.ts +355 -9
- package/templates/docker/src/lib/auth/simple-key.ts +3 -3
- package/templates/docker/src/lib/auth/types.ts +15 -21
- package/templates/docker/src/lib/billing/enforcement.ts +368 -0
- package/templates/docker/src/lib/billing/plans.ts +155 -0
- package/templates/docker/src/lib/cache/index.ts +92 -0
- package/templates/docker/src/lib/cache/keys.ts +30 -0
- package/templates/docker/src/lib/cache/lru.ts +79 -0
- package/templates/docker/src/lib/cache/types.ts +31 -0
- package/templates/docker/src/lib/compose-refs.ts +62 -0
- package/templates/docker/src/lib/config.ts +563 -11
- package/templates/docker/src/lib/connection-types.ts +9 -0
- package/templates/docker/src/lib/conversation-types.ts +1 -25
- package/templates/docker/src/lib/conversations.ts +345 -14
- package/templates/docker/src/lib/data-table.ts +61 -0
- package/templates/docker/src/lib/db/connection.ts +793 -39
- package/templates/docker/src/lib/db/internal.ts +985 -139
- package/templates/docker/src/lib/db/migrate.ts +295 -0
- package/templates/docker/src/lib/db/migrations/0000_baseline.sql +703 -0
- package/templates/docker/src/lib/db/migrations/0001_teams_installations.sql +14 -0
- package/templates/docker/src/lib/db/migrations/0002_discord_installations.sql +14 -0
- package/templates/docker/src/lib/db/migrations/0003_telegram_installations.sql +15 -0
- package/templates/docker/src/lib/db/migrations/0004_sandbox_credentials.sql +18 -0
- package/templates/docker/src/lib/db/migrations/0005_oauth_state.sql +16 -0
- package/templates/docker/src/lib/db/migrations/0006_byot_credentials.sql +14 -0
- package/templates/docker/src/lib/db/migrations/0007_gchat_installations.sql +15 -0
- package/templates/docker/src/lib/db/migrations/0008_github_installations.sql +14 -0
- package/templates/docker/src/lib/db/migrations/0009_linear_installations.sql +15 -0
- package/templates/docker/src/lib/db/migrations/0010_whatsapp_installations.sql +14 -0
- package/templates/docker/src/lib/db/migrations/0011_email_installations.sql +16 -0
- package/templates/docker/src/lib/db/migrations/0012_region_migrations.sql +25 -0
- package/templates/docker/src/lib/db/schema.ts +1120 -0
- package/templates/docker/src/lib/db/source-rate-limit.ts +89 -139
- package/templates/docker/src/lib/demo.ts +308 -0
- package/templates/docker/src/lib/discord/store.ts +225 -0
- package/templates/docker/src/lib/effect/ai.ts +243 -0
- package/templates/docker/src/lib/effect/errors.ts +234 -0
- package/templates/docker/src/lib/effect/hono.ts +454 -0
- package/templates/docker/src/lib/effect/index.ts +137 -0
- package/templates/docker/src/lib/effect/layers.ts +496 -0
- package/templates/docker/src/lib/effect/services.ts +776 -0
- package/templates/docker/src/lib/effect/sql.ts +178 -0
- package/templates/docker/src/lib/effect/toolkit.ts +123 -0
- package/templates/docker/src/lib/email/delivery.ts +232 -0
- package/templates/docker/src/lib/email/engine.ts +349 -0
- package/templates/docker/src/lib/email/hooks.ts +107 -0
- package/templates/docker/src/lib/email/index.ts +16 -0
- package/templates/docker/src/lib/email/scheduler.ts +72 -0
- package/templates/docker/src/lib/email/sequence.ts +73 -0
- package/templates/docker/src/lib/email/store.ts +163 -0
- package/templates/docker/src/lib/email/templates.ts +215 -0
- package/templates/docker/src/lib/format.ts +67 -0
- package/templates/docker/src/lib/gchat/store.ts +202 -0
- package/templates/docker/src/lib/github/store.ts +197 -0
- package/templates/docker/src/lib/id.ts +29 -0
- package/templates/docker/src/lib/integrations/types.ts +166 -0
- package/templates/docker/src/lib/learn/pattern-analyzer.ts +224 -0
- package/templates/docker/src/lib/learn/pattern-cache.ts +229 -0
- package/templates/docker/src/lib/learn/pattern-proposer.ts +87 -0
- package/templates/docker/src/lib/learn/suggestion-helpers.ts +34 -0
- package/templates/docker/src/lib/learn/suggestions.ts +139 -0
- package/templates/docker/src/lib/linear/store.ts +200 -0
- package/templates/docker/src/lib/logger.ts +35 -3
- package/templates/docker/src/lib/metering.ts +272 -0
- package/templates/docker/src/lib/parsers.ts +99 -0
- package/templates/docker/src/lib/plugins/hooks.ts +13 -11
- package/templates/docker/src/lib/plugins/index.ts +3 -1
- package/templates/docker/src/lib/plugins/registry.ts +58 -6
- package/templates/docker/src/lib/plugins/settings.ts +147 -0
- package/templates/docker/src/lib/plugins/wiring.ts +6 -9
- package/templates/docker/src/lib/profiler.ts +1665 -0
- package/templates/docker/src/lib/providers.ts +188 -13
- package/templates/docker/src/lib/rls.ts +172 -60
- package/templates/docker/src/lib/sandbox/credentials.ts +206 -0
- package/templates/docker/src/lib/sandbox/validate.ts +179 -0
- package/templates/docker/src/lib/scheduled-task-types.ts +26 -94
- package/templates/docker/src/lib/scheduled-tasks.ts +174 -34
- package/templates/docker/src/lib/scheduler/delivery.ts +248 -150
- package/templates/docker/src/lib/scheduler/engine.ts +190 -154
- package/templates/docker/src/lib/scheduler/executor.ts +74 -23
- package/templates/docker/src/lib/scheduler/preview.ts +72 -0
- package/templates/docker/src/lib/security/abuse.ts +463 -0
- package/templates/docker/src/lib/semantic/diff.ts +267 -0
- package/templates/docker/src/lib/semantic/entities.ts +167 -0
- package/templates/docker/src/lib/semantic/files.ts +283 -0
- package/templates/docker/src/lib/semantic/index.ts +27 -0
- package/templates/docker/src/lib/{semantic-index.ts → semantic/search.ts} +80 -9
- package/templates/docker/src/lib/semantic/sync.ts +581 -0
- package/templates/docker/src/lib/{semantic.ts → semantic/whitelist.ts} +189 -3
- package/templates/docker/src/lib/settings.ts +817 -0
- package/templates/docker/src/lib/sidecar-types.ts +13 -0
- package/templates/docker/src/lib/slack/store.ts +134 -25
- package/templates/docker/src/lib/startup.ts +528 -362
- package/templates/docker/src/lib/teams/store.ts +216 -0
- package/templates/docker/src/lib/telegram/store.ts +202 -0
- package/templates/docker/src/lib/telemetry.ts +40 -0
- package/templates/docker/src/lib/tools/actions/audit.ts +8 -5
- package/templates/docker/src/lib/tools/actions/email.ts +3 -1
- package/templates/docker/src/lib/tools/actions/handler.ts +276 -93
- package/templates/docker/src/lib/tools/actions/jira.ts +2 -2
- package/templates/docker/src/lib/tools/backends/detect.ts +16 -0
- package/templates/docker/src/lib/tools/backends/index.ts +11 -0
- package/templates/docker/src/lib/tools/backends/nsjail.ts +213 -0
- package/templates/docker/src/lib/tools/backends/shared.ts +103 -0
- package/templates/docker/src/lib/tools/backends/types.ts +26 -0
- package/templates/docker/src/lib/tools/explore-nsjail.ts +7 -228
- package/templates/docker/src/lib/tools/explore-sandbox.ts +4 -29
- package/templates/docker/src/lib/tools/explore-sidecar.ts +18 -2
- package/templates/docker/src/lib/tools/explore.ts +246 -54
- package/templates/docker/src/lib/tools/index.ts +17 -0
- package/templates/docker/src/lib/tools/python-nsjail.ts +11 -139
- package/templates/docker/src/lib/tools/python-sandbox.ts +9 -132
- package/templates/docker/src/lib/tools/python-sidecar.ts +184 -3
- package/templates/docker/src/lib/tools/python-stream.ts +33 -0
- package/templates/docker/src/lib/tools/python-wrapper.ts +129 -0
- package/templates/docker/src/lib/tools/python.ts +115 -15
- package/templates/docker/src/lib/tools/registry.ts +14 -2
- package/templates/docker/src/lib/tools/sql.ts +778 -362
- package/templates/docker/src/lib/tracing.ts +16 -0
- package/templates/docker/src/lib/whatsapp/store.ts +198 -0
- package/templates/docker/src/lib/workspace.ts +89 -0
- package/templates/docker/src/progress.ts +121 -0
- package/templates/docker/src/types/data-table.ts +48 -0
- package/templates/docker/src/ui/atlas-chat-reexport.ts +3 -0
- package/templates/docker/src/ui/components/actions/action-approval-card.tsx +26 -19
- package/templates/docker/src/ui/components/actions/action-status-badge.tsx +3 -3
- package/templates/docker/src/ui/components/admin/admin-layout.tsx +57 -39
- package/templates/docker/src/ui/components/admin/admin-sidebar.tsx +213 -35
- package/templates/docker/src/ui/components/admin/delivery-status-badge.tsx +53 -0
- package/templates/docker/src/ui/components/admin/empty-state.tsx +27 -6
- package/templates/docker/src/ui/components/admin/entity-detail.tsx +3 -52
- package/templates/docker/src/ui/components/admin/error-banner.tsx +2 -2
- package/templates/docker/src/ui/components/admin/feature-disabled.tsx +28 -5
- package/templates/docker/src/ui/components/admin-content-wrapper.tsx +87 -0
- package/templates/docker/src/ui/components/atlas-chat.tsx +449 -166
- package/templates/docker/src/ui/components/branding-head.tsx +41 -0
- package/templates/docker/src/ui/components/chart/chart-detection.ts +62 -5
- package/templates/docker/src/ui/components/chart/result-chart.tsx +316 -125
- package/templates/docker/src/ui/components/chat/api-key-bar.tsx +4 -4
- package/templates/docker/src/ui/components/chat/data-table.tsx +45 -4
- package/templates/docker/src/ui/components/chat/error-banner.tsx +86 -5
- package/templates/docker/src/ui/components/chat/follow-up-chips.tsx +29 -0
- package/templates/docker/src/ui/components/chat/markdown.tsx +24 -0
- package/templates/docker/src/ui/components/chat/prompt-library.tsx +206 -0
- package/templates/docker/src/ui/components/chat/python-result-card.tsx +106 -78
- package/templates/docker/src/ui/components/chat/result-card-base.tsx +101 -0
- package/templates/docker/src/ui/components/chat/share-dialog.tsx +377 -0
- package/templates/docker/src/ui/components/chat/sql-result-card.tsx +94 -73
- package/templates/docker/src/ui/components/chat/suggestion-chips.tsx +46 -0
- package/templates/docker/src/ui/components/chat/tool-part.tsx +16 -4
- package/templates/docker/src/ui/components/conversations/conversation-item.tsx +48 -17
- package/templates/docker/src/ui/components/conversations/conversation-list.tsx +38 -24
- package/templates/docker/src/ui/components/conversations/conversation-sidebar.tsx +66 -7
- package/templates/docker/src/ui/components/conversations/delete-confirmation.tsx +9 -2
- package/templates/docker/src/ui/components/error-boundary.tsx +66 -0
- package/templates/docker/src/ui/components/notebook/delete-cell-dialog.tsx +48 -0
- package/templates/docker/src/ui/components/notebook/fork-branch-selector.tsx +68 -0
- package/templates/docker/src/ui/components/notebook/notebook-cell-input.tsx +76 -0
- package/templates/docker/src/ui/components/notebook/notebook-cell-output.tsx +58 -0
- package/templates/docker/src/ui/components/notebook/notebook-cell-toolbar.tsx +91 -0
- package/templates/docker/src/ui/components/notebook/notebook-cell.tsx +119 -0
- package/templates/docker/src/ui/components/notebook/notebook-empty-state.tsx +19 -0
- package/templates/docker/src/ui/components/notebook/notebook-export.ts +287 -0
- package/templates/docker/src/ui/components/notebook/notebook-input-bar.tsx +49 -0
- package/templates/docker/src/ui/components/notebook/notebook-shell.tsx +266 -0
- package/templates/docker/src/ui/components/notebook/notebook-text-cell.tsx +152 -0
- package/templates/docker/src/ui/components/notebook/types.ts +39 -0
- package/templates/docker/src/ui/components/notebook/use-keyboard-nav.ts +109 -0
- package/templates/docker/src/ui/components/notebook/use-notebook.ts +684 -0
- package/templates/docker/src/ui/components/org-switcher.tsx +111 -0
- package/templates/docker/src/ui/components/region-picker.tsx +103 -0
- package/templates/docker/src/ui/components/schema-explorer/schema-explorer.tsx +522 -0
- package/templates/docker/src/ui/components/social-icons.tsx +26 -0
- package/templates/docker/src/ui/components/tour/guided-tour.tsx +81 -0
- package/templates/docker/src/ui/components/tour/index.ts +5 -0
- package/templates/docker/src/ui/components/tour/nav-bar.tsx +100 -0
- package/templates/docker/src/ui/components/tour/tour-overlay.tsx +298 -0
- package/templates/docker/src/ui/components/tour/tour-steps.ts +43 -0
- package/templates/docker/src/ui/components/tour/types.ts +21 -0
- package/templates/docker/src/ui/components/tour/use-tour.ts +193 -0
- package/templates/docker/src/ui/context-reexport.ts +3 -0
- package/templates/docker/src/ui/hooks/theme-init-script.ts +17 -0
- package/templates/docker/src/ui/hooks/use-admin-fetch.ts +38 -30
- package/templates/docker/src/ui/hooks/use-admin-mutation.ts +188 -0
- package/templates/docker/src/ui/hooks/use-atlas-transport.ts +225 -0
- package/templates/docker/src/ui/hooks/use-branding.ts +68 -0
- package/templates/docker/src/ui/hooks/use-conversations.ts +106 -83
- package/templates/docker/src/ui/hooks/use-dark-mode.ts +134 -10
- package/templates/docker/src/ui/hooks/use-deploy-mode.ts +36 -0
- package/templates/docker/src/ui/hooks/use-platform-admin-guard.ts +49 -0
- package/templates/docker/src/ui/lib/action-types.ts +11 -63
- package/templates/docker/src/ui/lib/admin-schemas.ts +744 -0
- package/templates/docker/src/ui/lib/fetch-client.ts +84 -0
- package/templates/docker/src/ui/lib/fetch-error.ts +54 -0
- package/templates/docker/src/ui/lib/helpers.ts +94 -1
- package/templates/docker/src/ui/lib/types.ts +149 -140
- package/templates/docker/tsconfig.json +4 -2
- package/templates/nextjs-standalone/bin/__tests__/duckdb-ingest.test.ts +17 -14
- package/templates/nextjs-standalone/bin/__tests__/failure-threshold.test.ts +148 -0
- package/templates/nextjs-standalone/bin/__tests__/fatal-error-propagation.test.ts +267 -0
- package/templates/nextjs-standalone/bin/__tests__/profiler-heuristics.test.ts +5 -5
- package/templates/nextjs-standalone/bin/__tests__/schema-drift.test.ts +39 -0
- package/templates/nextjs-standalone/bin/atlas.ts +981 -1819
- package/templates/nextjs-standalone/bin/benchmark.ts +14 -16
- package/templates/nextjs-standalone/bin/enrich.ts +7 -2
- package/templates/nextjs-standalone/brand.css +13 -0
- package/templates/nextjs-standalone/data/cybersec-semantic/catalog.yml +222 -0
- package/templates/nextjs-standalone/data/cybersec-semantic/entities/alerts.yml +195 -0
- package/templates/nextjs-standalone/data/cybersec-semantic/entities/assets.yml +191 -0
- package/templates/nextjs-standalone/data/cybersec-semantic/entities/compliance_assessments.yml +170 -0
- package/templates/nextjs-standalone/data/cybersec-semantic/entities/incidents.yml +219 -0
- package/templates/nextjs-standalone/data/cybersec-semantic/entities/organizations.yml +136 -0
- package/templates/nextjs-standalone/data/cybersec-semantic/entities/plans.yml +114 -0
- package/templates/nextjs-standalone/data/cybersec-semantic/entities/remediation_actions.yml +212 -0
- package/templates/nextjs-standalone/data/cybersec-semantic/entities/scan_results.yml +215 -0
- package/templates/nextjs-standalone/data/cybersec-semantic/entities/scans.yml +180 -0
- package/templates/nextjs-standalone/data/cybersec-semantic/entities/subscriptions.yml +184 -0
- package/templates/nextjs-standalone/data/cybersec-semantic/entities/users.yml +140 -0
- package/templates/nextjs-standalone/data/cybersec-semantic/entities/vulnerabilities.yml +154 -0
- package/templates/nextjs-standalone/data/cybersec-semantic/glossary.yml +207 -0
- package/templates/nextjs-standalone/data/cybersec-semantic/metrics/business.yml +148 -0
- package/templates/nextjs-standalone/data/cybersec-semantic/metrics/compliance.yml +138 -0
- package/templates/nextjs-standalone/data/cybersec-semantic/metrics/security.yml +181 -0
- package/templates/nextjs-standalone/data/cybersec.sql +8 -8
- package/templates/nextjs-standalone/data/demo.sql +3 -0
- package/templates/nextjs-standalone/data/ecommerce-semantic/catalog.yml +221 -0
- package/templates/nextjs-standalone/data/ecommerce-semantic/entities/categories.yml +91 -0
- package/templates/nextjs-standalone/data/ecommerce-semantic/entities/customers.yml +133 -0
- package/templates/nextjs-standalone/data/ecommerce-semantic/entities/email_campaigns.yml +119 -0
- package/templates/nextjs-standalone/data/ecommerce-semantic/entities/inventory_levels.yml +153 -0
- package/templates/nextjs-standalone/data/ecommerce-semantic/entities/order_items.yml +159 -0
- package/templates/nextjs-standalone/data/ecommerce-semantic/entities/orders.yml +199 -0
- package/templates/nextjs-standalone/data/ecommerce-semantic/entities/payments.yml +140 -0
- package/templates/nextjs-standalone/data/ecommerce-semantic/entities/product_reviews.yml +155 -0
- package/templates/nextjs-standalone/data/ecommerce-semantic/entities/products.yml +178 -0
- package/templates/nextjs-standalone/data/ecommerce-semantic/entities/promotions.yml +171 -0
- package/templates/nextjs-standalone/data/ecommerce-semantic/entities/returns.yml +144 -0
- package/templates/nextjs-standalone/data/ecommerce-semantic/entities/sellers.yml +124 -0
- package/templates/nextjs-standalone/data/ecommerce-semantic/entities/shipments.yml +159 -0
- package/templates/nextjs-standalone/data/ecommerce-semantic/glossary.yml +193 -0
- package/templates/nextjs-standalone/data/ecommerce-semantic/metrics/customers.yml +116 -0
- package/templates/nextjs-standalone/data/ecommerce-semantic/metrics/operations.yml +131 -0
- package/templates/nextjs-standalone/data/ecommerce-semantic/metrics/revenue.yml +120 -0
- package/templates/nextjs-standalone/docs/deploy.md +2 -1
- package/templates/nextjs-standalone/ee/src/__mocks__/internal.ts +170 -0
- package/templates/nextjs-standalone/ee/src/audit/purge-scheduler.ts +113 -0
- package/templates/nextjs-standalone/ee/src/audit/retention.ts +467 -0
- package/templates/nextjs-standalone/ee/src/auth/ip-allowlist.ts +367 -0
- package/templates/nextjs-standalone/ee/src/auth/roles.ts +562 -0
- package/templates/nextjs-standalone/ee/src/auth/scim.ts +343 -0
- package/templates/nextjs-standalone/ee/src/auth/sso.ts +538 -0
- package/templates/nextjs-standalone/ee/src/backups/engine.ts +355 -0
- package/templates/nextjs-standalone/ee/src/backups/index.ts +26 -0
- package/templates/nextjs-standalone/ee/src/backups/restore.ts +169 -0
- package/templates/nextjs-standalone/ee/src/backups/scheduler.ts +153 -0
- package/templates/nextjs-standalone/ee/src/backups/verify.ts +124 -0
- package/templates/nextjs-standalone/ee/src/branding/white-label.ts +228 -0
- package/templates/nextjs-standalone/ee/src/compliance/masking.ts +477 -0
- package/templates/nextjs-standalone/ee/src/compliance/patterns.ts +16 -0
- package/templates/nextjs-standalone/ee/src/compliance/pii-detection.ts +217 -0
- package/templates/nextjs-standalone/ee/src/compliance/reports.ts +402 -0
- package/templates/nextjs-standalone/ee/src/deploy-mode.ts +37 -0
- package/templates/nextjs-standalone/ee/src/governance/approval.ts +699 -0
- package/templates/nextjs-standalone/ee/src/index.ts +74 -0
- package/templates/nextjs-standalone/ee/src/platform/domains.ts +562 -0
- package/templates/nextjs-standalone/ee/src/platform/model-routing.ts +382 -0
- package/templates/nextjs-standalone/ee/src/platform/residency.ts +265 -0
- package/templates/nextjs-standalone/ee/src/sla/alerting.ts +382 -0
- package/templates/nextjs-standalone/ee/src/sla/index.ts +12 -0
- package/templates/nextjs-standalone/ee/src/sla/metrics.ts +275 -0
- package/templates/nextjs-standalone/ee/src/test-setup.ts +1 -0
- package/templates/nextjs-standalone/next.config.ts +1 -1
- package/templates/nextjs-standalone/package.json +50 -30
- package/templates/nextjs-standalone/src/api/index.ts +336 -24
- package/templates/nextjs-standalone/src/api/routes/actions.ts +443 -176
- package/templates/nextjs-standalone/src/api/routes/admin-abuse.ts +219 -0
- package/templates/nextjs-standalone/src/api/routes/admin-approval.ts +418 -0
- package/templates/nextjs-standalone/src/api/routes/admin-audit-retention.ts +405 -0
- package/templates/nextjs-standalone/src/api/routes/admin-auth.ts +122 -0
- package/templates/nextjs-standalone/src/api/routes/admin-branding.ts +252 -0
- package/templates/nextjs-standalone/src/api/routes/admin-compliance.ts +352 -0
- package/templates/nextjs-standalone/src/api/routes/admin-domains.ts +334 -0
- package/templates/nextjs-standalone/src/api/routes/admin-integrations.ts +2667 -0
- package/templates/nextjs-standalone/src/api/routes/admin-ip-allowlist.ts +261 -0
- package/templates/nextjs-standalone/src/api/routes/admin-learned-patterns.ts +525 -0
- package/templates/nextjs-standalone/src/api/routes/admin-model-config.ts +252 -0
- package/templates/nextjs-standalone/src/api/routes/admin-onboarding-emails.ts +145 -0
- package/templates/nextjs-standalone/src/api/routes/admin-orgs.ts +710 -0
- package/templates/nextjs-standalone/src/api/routes/admin-prompts.ts +694 -0
- package/templates/nextjs-standalone/src/api/routes/admin-residency.ts +570 -0
- package/templates/nextjs-standalone/src/api/routes/admin-roles.ts +296 -0
- package/templates/nextjs-standalone/src/api/routes/admin-router.ts +120 -0
- package/templates/nextjs-standalone/src/api/routes/admin-sandbox.ts +417 -0
- package/templates/nextjs-standalone/src/api/routes/admin-scim.ts +262 -0
- package/templates/nextjs-standalone/src/api/routes/admin-sso.ts +545 -0
- package/templates/nextjs-standalone/src/api/routes/admin-suggestions.ts +176 -0
- package/templates/nextjs-standalone/src/api/routes/admin-usage.ts +310 -0
- package/templates/nextjs-standalone/src/api/routes/admin.ts +4156 -898
- package/templates/nextjs-standalone/src/api/routes/auth-preamble.ts +105 -0
- package/templates/nextjs-standalone/src/api/routes/billing.ts +397 -0
- package/templates/nextjs-standalone/src/api/routes/chat.ts +597 -334
- package/templates/nextjs-standalone/src/api/routes/conversations.ts +987 -132
- package/templates/nextjs-standalone/src/api/routes/demo.ts +673 -0
- package/templates/nextjs-standalone/src/api/routes/discord.ts +274 -0
- package/templates/nextjs-standalone/src/api/routes/ee-error-handler.ts +32 -0
- package/templates/nextjs-standalone/src/api/routes/health.ts +129 -14
- package/templates/nextjs-standalone/src/api/routes/middleware.ts +244 -0
- package/templates/nextjs-standalone/src/api/routes/onboarding-emails.ts +134 -0
- package/templates/nextjs-standalone/src/api/routes/onboarding.ts +1109 -0
- package/templates/nextjs-standalone/src/api/routes/openapi.ts +184 -1597
- package/templates/nextjs-standalone/src/api/routes/platform-admin.ts +760 -0
- package/templates/nextjs-standalone/src/api/routes/platform-backups.ts +436 -0
- package/templates/nextjs-standalone/src/api/routes/platform-domains.ts +235 -0
- package/templates/nextjs-standalone/src/api/routes/platform-residency.ts +257 -0
- package/templates/nextjs-standalone/src/api/routes/platform-sla.ts +379 -0
- package/templates/nextjs-standalone/src/api/routes/prompts.ts +221 -0
- package/templates/nextjs-standalone/src/api/routes/public-branding.ts +106 -0
- package/templates/nextjs-standalone/src/api/routes/query.ts +330 -219
- package/templates/nextjs-standalone/src/api/routes/scheduled-tasks.ts +393 -297
- package/templates/nextjs-standalone/src/api/routes/semantic.ts +179 -0
- package/templates/nextjs-standalone/src/api/routes/sessions.ts +210 -0
- package/templates/nextjs-standalone/src/api/routes/shared-domains.ts +98 -0
- package/templates/nextjs-standalone/src/api/routes/shared-schemas.ts +139 -0
- package/templates/nextjs-standalone/src/api/routes/slack.ts +209 -52
- package/templates/nextjs-standalone/src/api/routes/suggestions.ts +233 -0
- package/templates/nextjs-standalone/src/api/routes/tables.ts +67 -0
- package/templates/nextjs-standalone/src/api/routes/teams.ts +222 -0
- package/templates/nextjs-standalone/src/api/routes/validate-sql.ts +188 -0
- package/templates/nextjs-standalone/src/api/routes/validation-hook.ts +62 -0
- package/templates/nextjs-standalone/src/api/routes/widget-loader.ts +356 -0
- package/templates/nextjs-standalone/src/api/routes/widget.ts +428 -0
- package/templates/nextjs-standalone/src/api/routes/wizard.ts +852 -0
- package/templates/nextjs-standalone/src/api/server.ts +187 -69
- package/templates/nextjs-standalone/src/app/error.tsx +5 -2
- package/templates/nextjs-standalone/src/app/globals.css +1 -1
- package/templates/nextjs-standalone/src/app/layout.tsx +7 -2
- package/templates/nextjs-standalone/src/app/page.tsx +39 -5
- package/templates/nextjs-standalone/src/components/data-table/data-table-column-header.tsx +99 -0
- package/templates/nextjs-standalone/src/components/data-table/data-table-date-filter.tsx +225 -0
- package/templates/nextjs-standalone/src/components/data-table/data-table-expandable.tsx +125 -0
- package/templates/nextjs-standalone/src/components/data-table/data-table-faceted-filter.tsx +189 -0
- package/templates/nextjs-standalone/src/components/data-table/data-table-pagination.tsx +112 -0
- package/templates/nextjs-standalone/src/components/data-table/data-table-range-filter.tsx +122 -0
- package/templates/nextjs-standalone/src/components/data-table/data-table-slider-filter.tsx +256 -0
- package/templates/nextjs-standalone/src/components/data-table/data-table-sort-list.tsx +407 -0
- package/templates/nextjs-standalone/src/components/data-table/data-table-toolbar.tsx +149 -0
- package/templates/nextjs-standalone/src/components/data-table/data-table-view-options.tsx +89 -0
- package/templates/nextjs-standalone/src/components/data-table/data-table.tsx +105 -0
- package/templates/nextjs-standalone/src/components/form-dialog.tsx +135 -0
- package/templates/nextjs-standalone/src/components/ui/accordion.tsx +66 -0
- package/templates/nextjs-standalone/src/components/ui/calendar.tsx +220 -0
- package/templates/nextjs-standalone/src/components/ui/checkbox.tsx +32 -0
- package/templates/nextjs-standalone/src/components/ui/faceted.tsx +283 -0
- package/templates/nextjs-standalone/src/components/ui/form.tsx +167 -0
- package/templates/nextjs-standalone/src/components/ui/label.tsx +24 -0
- package/templates/nextjs-standalone/src/components/ui/popover.tsx +89 -0
- package/templates/nextjs-standalone/src/components/ui/progress.tsx +31 -0
- package/templates/nextjs-standalone/src/components/ui/scroll-area.tsx +6 -2
- package/templates/nextjs-standalone/src/components/ui/slider.tsx +63 -0
- package/templates/nextjs-standalone/src/components/ui/sortable.tsx +581 -0
- package/templates/nextjs-standalone/src/components/ui/switch.tsx +35 -0
- package/templates/nextjs-standalone/src/components/ui/textarea.tsx +18 -0
- package/templates/nextjs-standalone/src/config/data-table.ts +82 -0
- package/templates/nextjs-standalone/src/env-check.ts +74 -0
- package/templates/nextjs-standalone/src/hooks/use-callback-ref.ts +27 -0
- package/templates/nextjs-standalone/src/hooks/use-data-table.ts +316 -0
- package/templates/nextjs-standalone/src/hooks/use-debounced-callback.ts +28 -0
- package/templates/nextjs-standalone/src/lib/action-types.ts +7 -41
- package/templates/nextjs-standalone/src/lib/agent-query.ts +4 -2
- package/templates/nextjs-standalone/src/lib/agent.ts +363 -31
- package/templates/nextjs-standalone/src/lib/api-url.ts +2 -3
- package/templates/nextjs-standalone/src/lib/auth/admin-permissions.ts +38 -0
- package/templates/nextjs-standalone/src/lib/auth/audit.ts +19 -4
- package/templates/nextjs-standalone/src/lib/auth/byot.ts +3 -3
- package/templates/nextjs-standalone/src/lib/auth/detect.ts +29 -8
- package/templates/nextjs-standalone/src/lib/auth/managed.ts +104 -14
- package/templates/nextjs-standalone/src/lib/auth/middleware.ts +53 -6
- package/templates/nextjs-standalone/src/lib/auth/migrate.ts +140 -15
- package/templates/nextjs-standalone/src/lib/auth/oauth-state.ts +123 -0
- package/templates/nextjs-standalone/src/lib/auth/org-permissions.ts +55 -0
- package/templates/nextjs-standalone/src/lib/auth/permissions.ts +26 -19
- package/templates/nextjs-standalone/src/lib/auth/server.ts +355 -9
- package/templates/nextjs-standalone/src/lib/auth/simple-key.ts +3 -3
- package/templates/nextjs-standalone/src/lib/auth/types.ts +15 -21
- package/templates/nextjs-standalone/src/lib/billing/enforcement.ts +368 -0
- package/templates/nextjs-standalone/src/lib/billing/plans.ts +155 -0
- package/templates/nextjs-standalone/src/lib/cache/index.ts +92 -0
- package/templates/nextjs-standalone/src/lib/cache/keys.ts +30 -0
- package/templates/nextjs-standalone/src/lib/cache/lru.ts +79 -0
- package/templates/nextjs-standalone/src/lib/cache/types.ts +31 -0
- package/templates/nextjs-standalone/src/lib/compose-refs.ts +62 -0
- package/templates/nextjs-standalone/src/lib/config.ts +563 -11
- package/templates/nextjs-standalone/src/lib/connection-types.ts +9 -0
- package/templates/nextjs-standalone/src/lib/conversation-types.ts +1 -25
- package/templates/nextjs-standalone/src/lib/conversations.ts +345 -14
- package/templates/nextjs-standalone/src/lib/data-table.ts +61 -0
- package/templates/nextjs-standalone/src/lib/db/connection.ts +793 -39
- package/templates/nextjs-standalone/src/lib/db/internal.ts +985 -139
- package/templates/nextjs-standalone/src/lib/db/migrate.ts +295 -0
- package/templates/nextjs-standalone/src/lib/db/migrations/0000_baseline.sql +703 -0
- package/templates/nextjs-standalone/src/lib/db/migrations/0001_teams_installations.sql +14 -0
- package/templates/nextjs-standalone/src/lib/db/migrations/0002_discord_installations.sql +14 -0
- package/templates/nextjs-standalone/src/lib/db/migrations/0003_telegram_installations.sql +15 -0
- package/templates/nextjs-standalone/src/lib/db/migrations/0004_sandbox_credentials.sql +18 -0
- package/templates/nextjs-standalone/src/lib/db/migrations/0005_oauth_state.sql +16 -0
- package/templates/nextjs-standalone/src/lib/db/migrations/0006_byot_credentials.sql +14 -0
- package/templates/nextjs-standalone/src/lib/db/migrations/0007_gchat_installations.sql +15 -0
- package/templates/nextjs-standalone/src/lib/db/migrations/0008_github_installations.sql +14 -0
- package/templates/nextjs-standalone/src/lib/db/migrations/0009_linear_installations.sql +15 -0
- package/templates/nextjs-standalone/src/lib/db/migrations/0010_whatsapp_installations.sql +14 -0
- package/templates/nextjs-standalone/src/lib/db/migrations/0011_email_installations.sql +16 -0
- package/templates/nextjs-standalone/src/lib/db/migrations/0012_region_migrations.sql +25 -0
- package/templates/nextjs-standalone/src/lib/db/schema.ts +1120 -0
- package/templates/nextjs-standalone/src/lib/db/source-rate-limit.ts +89 -139
- package/templates/nextjs-standalone/src/lib/demo.ts +308 -0
- package/templates/nextjs-standalone/src/lib/discord/store.ts +225 -0
- package/templates/nextjs-standalone/src/lib/effect/ai.ts +243 -0
- package/templates/nextjs-standalone/src/lib/effect/errors.ts +234 -0
- package/templates/nextjs-standalone/src/lib/effect/hono.ts +454 -0
- package/templates/nextjs-standalone/src/lib/effect/index.ts +137 -0
- package/templates/nextjs-standalone/src/lib/effect/layers.ts +496 -0
- package/templates/nextjs-standalone/src/lib/effect/services.ts +776 -0
- package/templates/nextjs-standalone/src/lib/effect/sql.ts +178 -0
- package/templates/nextjs-standalone/src/lib/effect/toolkit.ts +123 -0
- package/templates/nextjs-standalone/src/lib/email/delivery.ts +232 -0
- package/templates/nextjs-standalone/src/lib/email/engine.ts +349 -0
- package/templates/nextjs-standalone/src/lib/email/hooks.ts +107 -0
- package/templates/nextjs-standalone/src/lib/email/index.ts +16 -0
- package/templates/nextjs-standalone/src/lib/email/scheduler.ts +72 -0
- package/templates/nextjs-standalone/src/lib/email/sequence.ts +73 -0
- package/templates/nextjs-standalone/src/lib/email/store.ts +163 -0
- package/templates/nextjs-standalone/src/lib/email/templates.ts +215 -0
- package/templates/nextjs-standalone/src/lib/format.test.ts +117 -0
- package/templates/nextjs-standalone/src/lib/format.ts +67 -0
- package/templates/nextjs-standalone/src/lib/gchat/store.ts +202 -0
- package/templates/nextjs-standalone/src/lib/github/store.ts +197 -0
- package/templates/nextjs-standalone/src/lib/id.ts +29 -0
- package/templates/nextjs-standalone/src/lib/integrations/types.ts +166 -0
- package/templates/nextjs-standalone/src/lib/learn/pattern-analyzer.ts +224 -0
- package/templates/nextjs-standalone/src/lib/learn/pattern-cache.ts +229 -0
- package/templates/nextjs-standalone/src/lib/learn/pattern-proposer.ts +87 -0
- package/templates/nextjs-standalone/src/lib/learn/suggestion-helpers.ts +34 -0
- package/templates/nextjs-standalone/src/lib/learn/suggestions.ts +139 -0
- package/templates/nextjs-standalone/src/lib/linear/store.ts +200 -0
- package/templates/nextjs-standalone/src/lib/logger.ts +35 -3
- package/templates/nextjs-standalone/src/lib/metering.ts +272 -0
- package/templates/nextjs-standalone/src/lib/parsers.ts +99 -0
- package/templates/nextjs-standalone/src/lib/plugins/hooks.ts +13 -11
- package/templates/nextjs-standalone/src/lib/plugins/index.ts +3 -1
- package/templates/nextjs-standalone/src/lib/plugins/registry.ts +58 -6
- package/templates/nextjs-standalone/src/lib/plugins/settings.ts +147 -0
- package/templates/nextjs-standalone/src/lib/plugins/wiring.ts +6 -9
- package/templates/nextjs-standalone/src/lib/profiler.ts +1665 -0
- package/templates/nextjs-standalone/src/lib/providers.ts +188 -13
- package/templates/nextjs-standalone/src/lib/rls.ts +172 -60
- package/templates/nextjs-standalone/src/lib/sandbox/credentials.ts +206 -0
- package/templates/nextjs-standalone/src/lib/sandbox/validate.ts +179 -0
- package/templates/nextjs-standalone/src/lib/scheduled-task-types.ts +26 -94
- package/templates/nextjs-standalone/src/lib/scheduled-tasks.ts +174 -34
- package/templates/nextjs-standalone/src/lib/scheduler/delivery.ts +248 -150
- package/templates/nextjs-standalone/src/lib/scheduler/engine.ts +190 -154
- package/templates/nextjs-standalone/src/lib/scheduler/executor.ts +74 -23
- package/templates/nextjs-standalone/src/lib/scheduler/preview.ts +72 -0
- package/templates/nextjs-standalone/src/lib/security/abuse.ts +463 -0
- package/templates/nextjs-standalone/src/lib/semantic/diff.ts +267 -0
- package/templates/nextjs-standalone/src/lib/semantic/entities.ts +167 -0
- package/templates/nextjs-standalone/src/lib/semantic/files.ts +283 -0
- package/templates/nextjs-standalone/src/lib/semantic/index.ts +27 -0
- package/templates/nextjs-standalone/src/lib/{semantic-index.ts → semantic/search.ts} +80 -9
- package/templates/nextjs-standalone/src/lib/semantic/sync.ts +581 -0
- package/templates/nextjs-standalone/src/lib/{semantic.ts → semantic/whitelist.ts} +189 -3
- package/templates/nextjs-standalone/src/lib/settings.ts +817 -0
- package/templates/nextjs-standalone/src/lib/sidecar-types.ts +13 -0
- package/templates/nextjs-standalone/src/lib/slack/store.ts +134 -25
- package/templates/nextjs-standalone/src/lib/startup.ts +528 -362
- package/templates/nextjs-standalone/src/lib/teams/store.ts +216 -0
- package/templates/nextjs-standalone/src/lib/telegram/store.ts +202 -0
- package/templates/nextjs-standalone/src/lib/telemetry.ts +40 -0
- package/templates/nextjs-standalone/src/lib/tools/actions/audit.ts +8 -5
- package/templates/nextjs-standalone/src/lib/tools/actions/email.ts +3 -1
- package/templates/nextjs-standalone/src/lib/tools/actions/handler.ts +276 -93
- package/templates/nextjs-standalone/src/lib/tools/actions/jira.ts +2 -2
- package/templates/nextjs-standalone/src/lib/tools/backends/detect.ts +16 -0
- package/templates/nextjs-standalone/src/lib/tools/backends/index.ts +11 -0
- package/templates/nextjs-standalone/src/lib/tools/backends/nsjail.ts +213 -0
- package/templates/nextjs-standalone/src/lib/tools/backends/shared.ts +103 -0
- package/templates/nextjs-standalone/src/lib/tools/backends/types.ts +26 -0
- package/templates/nextjs-standalone/src/lib/tools/explore-nsjail.ts +7 -228
- package/templates/nextjs-standalone/src/lib/tools/explore-sandbox.ts +4 -29
- package/templates/nextjs-standalone/src/lib/tools/explore-sidecar.ts +18 -2
- package/templates/nextjs-standalone/src/lib/tools/explore.ts +246 -54
- package/templates/nextjs-standalone/src/lib/tools/index.ts +17 -0
- package/templates/nextjs-standalone/src/lib/tools/python-nsjail.ts +11 -139
- package/templates/nextjs-standalone/src/lib/tools/python-sandbox.ts +9 -132
- package/templates/nextjs-standalone/src/lib/tools/python-sidecar.ts +184 -3
- package/templates/nextjs-standalone/src/lib/tools/python-stream.ts +33 -0
- package/templates/nextjs-standalone/src/lib/tools/python-wrapper.ts +129 -0
- package/templates/nextjs-standalone/src/lib/tools/python.ts +115 -15
- package/templates/nextjs-standalone/src/lib/tools/registry.ts +14 -2
- package/templates/nextjs-standalone/src/lib/tools/sql.ts +778 -362
- package/templates/nextjs-standalone/src/lib/tracing.ts +16 -0
- package/templates/nextjs-standalone/src/lib/whatsapp/store.ts +198 -0
- package/templates/nextjs-standalone/src/lib/workspace.ts +89 -0
- package/templates/nextjs-standalone/src/progress.ts +121 -0
- package/templates/nextjs-standalone/src/types/data-table.ts +48 -0
- package/templates/nextjs-standalone/src/ui/atlas-chat-reexport.ts +3 -0
- package/templates/nextjs-standalone/src/ui/components/actions/action-approval-card.tsx +26 -19
- package/templates/nextjs-standalone/src/ui/components/actions/action-status-badge.tsx +3 -3
- package/templates/nextjs-standalone/src/ui/components/admin/admin-layout.tsx +57 -39
- package/templates/nextjs-standalone/src/ui/components/admin/admin-sidebar.tsx +213 -35
- package/templates/nextjs-standalone/src/ui/components/admin/delivery-status-badge.tsx +53 -0
- package/templates/nextjs-standalone/src/ui/components/admin/empty-state.tsx +27 -6
- package/templates/nextjs-standalone/src/ui/components/admin/entity-detail.tsx +3 -52
- package/templates/nextjs-standalone/src/ui/components/admin/error-banner.tsx +2 -2
- package/templates/nextjs-standalone/src/ui/components/admin/feature-disabled.tsx +28 -5
- package/templates/nextjs-standalone/src/ui/components/admin-content-wrapper.tsx +87 -0
- package/templates/nextjs-standalone/src/ui/components/atlas-chat.tsx +449 -166
- package/templates/nextjs-standalone/src/ui/components/branding-head.tsx +41 -0
- package/templates/nextjs-standalone/src/ui/components/chart/chart-detection.ts +62 -5
- package/templates/nextjs-standalone/src/ui/components/chart/result-chart.tsx +316 -125
- package/templates/nextjs-standalone/src/ui/components/chat/api-key-bar.tsx +4 -4
- package/templates/nextjs-standalone/src/ui/components/chat/data-table.tsx +45 -4
- package/templates/nextjs-standalone/src/ui/components/chat/error-banner.tsx +86 -5
- package/templates/nextjs-standalone/src/ui/components/chat/follow-up-chips.tsx +29 -0
- package/templates/nextjs-standalone/src/ui/components/chat/markdown.tsx +24 -0
- package/templates/nextjs-standalone/src/ui/components/chat/prompt-library.tsx +206 -0
- package/templates/nextjs-standalone/src/ui/components/chat/python-result-card.tsx +106 -78
- package/templates/nextjs-standalone/src/ui/components/chat/result-card-base.tsx +101 -0
- package/templates/nextjs-standalone/src/ui/components/chat/share-dialog.tsx +377 -0
- package/templates/nextjs-standalone/src/ui/components/chat/sql-result-card.tsx +94 -73
- package/templates/nextjs-standalone/src/ui/components/chat/suggestion-chips.tsx +46 -0
- package/templates/nextjs-standalone/src/ui/components/chat/tool-part.tsx +16 -4
- package/templates/nextjs-standalone/src/ui/components/conversations/conversation-item.tsx +48 -17
- package/templates/nextjs-standalone/src/ui/components/conversations/conversation-list.tsx +38 -24
- package/templates/nextjs-standalone/src/ui/components/conversations/conversation-sidebar.tsx +66 -7
- package/templates/nextjs-standalone/src/ui/components/conversations/delete-confirmation.tsx +9 -2
- package/templates/nextjs-standalone/src/ui/components/error-boundary.tsx +66 -0
- package/templates/nextjs-standalone/src/ui/components/notebook/delete-cell-dialog.tsx +48 -0
- package/templates/nextjs-standalone/src/ui/components/notebook/fork-branch-selector.tsx +68 -0
- package/templates/nextjs-standalone/src/ui/components/notebook/notebook-cell-input.tsx +76 -0
- package/templates/nextjs-standalone/src/ui/components/notebook/notebook-cell-output.tsx +58 -0
- package/templates/nextjs-standalone/src/ui/components/notebook/notebook-cell-toolbar.tsx +91 -0
- package/templates/nextjs-standalone/src/ui/components/notebook/notebook-cell.tsx +119 -0
- package/templates/nextjs-standalone/src/ui/components/notebook/notebook-empty-state.tsx +19 -0
- package/templates/nextjs-standalone/src/ui/components/notebook/notebook-export.ts +287 -0
- package/templates/nextjs-standalone/src/ui/components/notebook/notebook-input-bar.tsx +49 -0
- package/templates/nextjs-standalone/src/ui/components/notebook/notebook-shell.tsx +266 -0
- package/templates/nextjs-standalone/src/ui/components/notebook/notebook-text-cell.tsx +152 -0
- package/templates/nextjs-standalone/src/ui/components/notebook/types.ts +39 -0
- package/templates/nextjs-standalone/src/ui/components/notebook/use-keyboard-nav.ts +109 -0
- package/templates/nextjs-standalone/src/ui/components/notebook/use-notebook.ts +684 -0
- package/templates/nextjs-standalone/src/ui/components/org-switcher.tsx +111 -0
- package/templates/nextjs-standalone/src/ui/components/region-picker.tsx +103 -0
- package/templates/nextjs-standalone/src/ui/components/schema-explorer/schema-explorer.tsx +522 -0
- package/templates/nextjs-standalone/src/ui/components/social-icons.tsx +26 -0
- package/templates/nextjs-standalone/src/ui/components/tour/guided-tour.tsx +81 -0
- package/templates/nextjs-standalone/src/ui/components/tour/index.ts +5 -0
- package/templates/nextjs-standalone/src/ui/components/tour/nav-bar.tsx +100 -0
- package/templates/nextjs-standalone/src/ui/components/tour/tour-overlay.tsx +298 -0
- package/templates/nextjs-standalone/src/ui/components/tour/tour-steps.ts +43 -0
- package/templates/nextjs-standalone/src/ui/components/tour/types.ts +21 -0
- package/templates/nextjs-standalone/src/ui/components/tour/use-tour.ts +193 -0
- package/templates/nextjs-standalone/src/ui/context-reexport.ts +3 -0
- package/templates/nextjs-standalone/src/ui/hooks/theme-init-script.ts +17 -0
- package/templates/nextjs-standalone/src/ui/hooks/use-admin-fetch.ts +38 -30
- package/templates/nextjs-standalone/src/ui/hooks/use-admin-mutation.ts +188 -0
- package/templates/nextjs-standalone/src/ui/hooks/use-atlas-transport.ts +225 -0
- package/templates/nextjs-standalone/src/ui/hooks/use-branding.ts +68 -0
- package/templates/nextjs-standalone/src/ui/hooks/use-conversations.ts +106 -83
- package/templates/nextjs-standalone/src/ui/hooks/use-dark-mode.ts +134 -10
- package/templates/nextjs-standalone/src/ui/hooks/use-deploy-mode.ts +36 -0
- package/templates/nextjs-standalone/src/ui/hooks/use-platform-admin-guard.ts +49 -0
- package/templates/nextjs-standalone/src/ui/lib/action-types.ts +11 -63
- package/templates/nextjs-standalone/src/ui/lib/admin-schemas.ts +744 -0
- package/templates/nextjs-standalone/src/ui/lib/fetch-client.ts +84 -0
- package/templates/nextjs-standalone/src/ui/lib/fetch-error.ts +54 -0
- package/templates/nextjs-standalone/src/ui/lib/helpers.ts +94 -1
- package/templates/nextjs-standalone/src/ui/lib/types.ts +149 -140
- package/templates/nextjs-standalone/tsconfig.json +3 -2
- package/templates/docker/src/api/__tests__/actions.test.ts +0 -683
- package/templates/docker/src/api/__tests__/admin.test.ts +0 -820
- package/templates/docker/src/api/__tests__/auth.test.ts +0 -165
- package/templates/docker/src/api/__tests__/chat.test.ts +0 -376
- package/templates/docker/src/api/__tests__/conversations.test.ts +0 -555
- package/templates/docker/src/api/__tests__/cors.test.ts +0 -135
- package/templates/docker/src/api/__tests__/health-plugin.test.ts +0 -176
- package/templates/docker/src/api/__tests__/health.test.ts +0 -283
- package/templates/docker/src/api/__tests__/query.test.ts +0 -891
- package/templates/docker/src/api/__tests__/scheduled-tasks.test.ts +0 -601
- package/templates/docker/src/api/__tests__/slack.test.ts +0 -847
- package/templates/docker/src/lib/__tests__/agent-cache.test.ts +0 -439
- package/templates/docker/src/lib/__tests__/agent-dialect.test.ts +0 -131
- package/templates/docker/src/lib/__tests__/agent-health-annotations.test.ts +0 -166
- package/templates/docker/src/lib/__tests__/agent-integration.test.ts +0 -516
- package/templates/docker/src/lib/__tests__/config-actions.test.ts +0 -166
- package/templates/docker/src/lib/__tests__/config.test.ts +0 -1113
- package/templates/docker/src/lib/__tests__/conversations.test.ts +0 -589
- package/templates/docker/src/lib/__tests__/errors.test.ts +0 -256
- package/templates/docker/src/lib/__tests__/logger.test.ts +0 -200
- package/templates/docker/src/lib/__tests__/plugin-aware-validation.test.ts +0 -321
- package/templates/docker/src/lib/__tests__/providers.test.ts +0 -130
- package/templates/docker/src/lib/__tests__/rls.test.ts +0 -435
- package/templates/docker/src/lib/__tests__/scheduled-task-types.test.ts +0 -124
- package/templates/docker/src/lib/__tests__/scheduled-tasks.test.ts +0 -550
- package/templates/docker/src/lib/__tests__/semantic-index.test.ts +0 -547
- package/templates/docker/src/lib/__tests__/semantic-multisource.test.ts +0 -544
- package/templates/docker/src/lib/__tests__/semantic.test.ts +0 -363
- package/templates/docker/src/lib/__tests__/startup-actions.test.ts +0 -461
- package/templates/docker/src/lib/__tests__/startup-first-run.test.ts +0 -429
- package/templates/docker/src/lib/__tests__/startup.test.ts +0 -470
- package/templates/docker/src/lib/__tests__/tracing.test.ts +0 -28
- package/templates/docker/src/lib/auth/__tests__/audit.test.ts +0 -418
- package/templates/docker/src/lib/auth/__tests__/byot-integration.test.ts +0 -222
- package/templates/docker/src/lib/auth/__tests__/byot.test.ts +0 -366
- package/templates/docker/src/lib/auth/__tests__/detect.test.ts +0 -190
- package/templates/docker/src/lib/auth/__tests__/managed.test.ts +0 -173
- package/templates/docker/src/lib/auth/__tests__/middleware.test.ts +0 -456
- package/templates/docker/src/lib/auth/__tests__/migrate.test.ts +0 -203
- package/templates/docker/src/lib/auth/__tests__/permissions.test.ts +0 -225
- package/templates/docker/src/lib/auth/__tests__/server.test.ts +0 -34
- package/templates/docker/src/lib/auth/__tests__/simple-key.test.ts +0 -176
- package/templates/docker/src/lib/auth/__tests__/types.test.ts +0 -44
- package/templates/docker/src/lib/db/__tests__/connection.test.ts +0 -144
- package/templates/docker/src/lib/db/__tests__/internal.test.ts +0 -387
- package/templates/docker/src/lib/db/__tests__/registry-health.test.ts +0 -190
- package/templates/docker/src/lib/db/__tests__/registry-pool-limits.test.ts +0 -137
- package/templates/docker/src/lib/db/__tests__/registry.test.ts +0 -398
- package/templates/docker/src/lib/db/__tests__/source-rate-limit.test.ts +0 -130
- package/templates/docker/src/lib/errors.ts +0 -154
- package/templates/docker/src/lib/plugins/__tests__/hooks-integration.test.ts +0 -204
- package/templates/docker/src/lib/plugins/__tests__/hooks.test.ts +0 -529
- package/templates/docker/src/lib/plugins/__tests__/migrate.test.ts +0 -875
- package/templates/docker/src/lib/plugins/__tests__/registry.test.ts +0 -373
- package/templates/docker/src/lib/plugins/__tests__/tools.test.ts +0 -49
- package/templates/docker/src/lib/plugins/__tests__/wiring.test.ts +0 -799
- package/templates/docker/src/lib/scheduler/__tests__/delivery.test.ts +0 -192
- package/templates/docker/src/lib/scheduler/__tests__/engine.test.ts +0 -248
- package/templates/docker/src/lib/scheduler/__tests__/format-email.test.ts +0 -96
- package/templates/docker/src/lib/scheduler/__tests__/format-slack.test.ts +0 -78
- package/templates/docker/src/lib/scheduler/__tests__/format-webhook.test.ts +0 -78
- package/templates/docker/src/lib/scheduler/index.ts +0 -7
- package/templates/docker/src/lib/slack/__tests__/api.test.ts +0 -160
- package/templates/docker/src/lib/slack/__tests__/format.test.ts +0 -237
- package/templates/docker/src/lib/slack/__tests__/store.test.ts +0 -188
- package/templates/docker/src/lib/slack/__tests__/threads.test.ts +0 -112
- package/templates/docker/src/lib/slack/__tests__/verify.test.ts +0 -111
- package/templates/docker/src/lib/tools/__tests__/action-permissions.test.ts +0 -594
- package/templates/docker/src/lib/tools/__tests__/custom-validation.test.ts +0 -240
- package/templates/docker/src/lib/tools/__tests__/explore-backend.test.ts +0 -267
- package/templates/docker/src/lib/tools/__tests__/explore-nsjail.test.ts +0 -506
- package/templates/docker/src/lib/tools/__tests__/explore-plugin.test.ts +0 -374
- package/templates/docker/src/lib/tools/__tests__/explore-sdk-compat.test.ts +0 -82
- package/templates/docker/src/lib/tools/__tests__/explore-sidecar.test.ts +0 -210
- package/templates/docker/src/lib/tools/__tests__/python-nsjail.test.ts +0 -515
- package/templates/docker/src/lib/tools/__tests__/python-sandbox.test.ts +0 -397
- package/templates/docker/src/lib/tools/__tests__/python-sidecar.test.ts +0 -365
- package/templates/docker/src/lib/tools/__tests__/python.test.ts +0 -331
- package/templates/docker/src/lib/tools/__tests__/registry-actions.test.ts +0 -132
- package/templates/docker/src/lib/tools/__tests__/registry.test.ts +0 -242
- package/templates/docker/src/lib/tools/__tests__/sql-audit.test.ts +0 -227
- package/templates/docker/src/lib/tools/__tests__/sql-connection-whitelist.test.ts +0 -100
- package/templates/docker/src/lib/tools/__tests__/sql-ratelimit.test.ts +0 -227
- package/templates/docker/src/lib/tools/__tests__/sql.test.ts +0 -709
- package/templates/docker/src/lib/tools/actions/__tests__/audit.test.ts +0 -211
- package/templates/docker/src/lib/tools/actions/__tests__/email.test.ts +0 -378
- package/templates/docker/src/lib/tools/actions/__tests__/handler.test.ts +0 -681
- package/templates/docker/src/lib/tools/actions/__tests__/jira.test.ts +0 -427
- package/templates/docker/src/test-setup.ts +0 -38
- package/templates/docker/src/types/vercel-sandbox.d.ts +0 -61
- package/templates/docker/src/ui/components/chat/managed-auth-card.tsx +0 -116
- package/templates/nextjs-standalone/src/api/__tests__/actions.test.ts +0 -683
- package/templates/nextjs-standalone/src/api/__tests__/admin.test.ts +0 -820
- package/templates/nextjs-standalone/src/api/__tests__/auth.test.ts +0 -165
- package/templates/nextjs-standalone/src/api/__tests__/chat.test.ts +0 -376
- package/templates/nextjs-standalone/src/api/__tests__/conversations.test.ts +0 -555
- package/templates/nextjs-standalone/src/api/__tests__/cors.test.ts +0 -135
- package/templates/nextjs-standalone/src/api/__tests__/health-plugin.test.ts +0 -176
- package/templates/nextjs-standalone/src/api/__tests__/health.test.ts +0 -283
- package/templates/nextjs-standalone/src/api/__tests__/query.test.ts +0 -891
- package/templates/nextjs-standalone/src/api/__tests__/scheduled-tasks.test.ts +0 -601
- package/templates/nextjs-standalone/src/api/__tests__/slack.test.ts +0 -847
- package/templates/nextjs-standalone/src/app/global-error.tsx +0 -68
- package/templates/nextjs-standalone/src/lib/__tests__/agent-cache.test.ts +0 -439
- package/templates/nextjs-standalone/src/lib/__tests__/agent-dialect.test.ts +0 -131
- package/templates/nextjs-standalone/src/lib/__tests__/agent-health-annotations.test.ts +0 -166
- package/templates/nextjs-standalone/src/lib/__tests__/agent-integration.test.ts +0 -516
- package/templates/nextjs-standalone/src/lib/__tests__/config-actions.test.ts +0 -166
- package/templates/nextjs-standalone/src/lib/__tests__/config.test.ts +0 -1113
- package/templates/nextjs-standalone/src/lib/__tests__/conversations.test.ts +0 -589
- package/templates/nextjs-standalone/src/lib/__tests__/errors.test.ts +0 -256
- package/templates/nextjs-standalone/src/lib/__tests__/logger.test.ts +0 -200
- package/templates/nextjs-standalone/src/lib/__tests__/plugin-aware-validation.test.ts +0 -321
- package/templates/nextjs-standalone/src/lib/__tests__/providers.test.ts +0 -130
- package/templates/nextjs-standalone/src/lib/__tests__/rls.test.ts +0 -435
- package/templates/nextjs-standalone/src/lib/__tests__/scheduled-task-types.test.ts +0 -124
- package/templates/nextjs-standalone/src/lib/__tests__/scheduled-tasks.test.ts +0 -550
- package/templates/nextjs-standalone/src/lib/__tests__/semantic-index.test.ts +0 -547
- package/templates/nextjs-standalone/src/lib/__tests__/semantic-multisource.test.ts +0 -544
- package/templates/nextjs-standalone/src/lib/__tests__/semantic.test.ts +0 -363
- package/templates/nextjs-standalone/src/lib/__tests__/startup-actions.test.ts +0 -461
- package/templates/nextjs-standalone/src/lib/__tests__/startup-first-run.test.ts +0 -429
- package/templates/nextjs-standalone/src/lib/__tests__/startup.test.ts +0 -470
- package/templates/nextjs-standalone/src/lib/__tests__/tracing.test.ts +0 -28
- package/templates/nextjs-standalone/src/lib/auth/__tests__/audit.test.ts +0 -418
- package/templates/nextjs-standalone/src/lib/auth/__tests__/byot-integration.test.ts +0 -222
- package/templates/nextjs-standalone/src/lib/auth/__tests__/byot.test.ts +0 -366
- package/templates/nextjs-standalone/src/lib/auth/__tests__/detect.test.ts +0 -190
- package/templates/nextjs-standalone/src/lib/auth/__tests__/managed.test.ts +0 -173
- package/templates/nextjs-standalone/src/lib/auth/__tests__/middleware.test.ts +0 -456
- package/templates/nextjs-standalone/src/lib/auth/__tests__/migrate.test.ts +0 -203
- package/templates/nextjs-standalone/src/lib/auth/__tests__/permissions.test.ts +0 -225
- package/templates/nextjs-standalone/src/lib/auth/__tests__/server.test.ts +0 -34
- package/templates/nextjs-standalone/src/lib/auth/__tests__/simple-key.test.ts +0 -176
- package/templates/nextjs-standalone/src/lib/auth/__tests__/types.test.ts +0 -44
- package/templates/nextjs-standalone/src/lib/db/__tests__/connection.test.ts +0 -144
- package/templates/nextjs-standalone/src/lib/db/__tests__/internal.test.ts +0 -387
- package/templates/nextjs-standalone/src/lib/db/__tests__/registry-health.test.ts +0 -190
- package/templates/nextjs-standalone/src/lib/db/__tests__/registry-pool-limits.test.ts +0 -137
- package/templates/nextjs-standalone/src/lib/db/__tests__/registry.test.ts +0 -398
- package/templates/nextjs-standalone/src/lib/db/__tests__/source-rate-limit.test.ts +0 -130
- package/templates/nextjs-standalone/src/lib/errors.ts +0 -154
- package/templates/nextjs-standalone/src/lib/plugins/__tests__/hooks-integration.test.ts +0 -204
- package/templates/nextjs-standalone/src/lib/plugins/__tests__/hooks.test.ts +0 -529
- package/templates/nextjs-standalone/src/lib/plugins/__tests__/migrate.test.ts +0 -875
- package/templates/nextjs-standalone/src/lib/plugins/__tests__/registry.test.ts +0 -373
- package/templates/nextjs-standalone/src/lib/plugins/__tests__/tools.test.ts +0 -49
- package/templates/nextjs-standalone/src/lib/plugins/__tests__/wiring.test.ts +0 -799
- package/templates/nextjs-standalone/src/lib/scheduler/__tests__/delivery.test.ts +0 -192
- package/templates/nextjs-standalone/src/lib/scheduler/__tests__/engine.test.ts +0 -248
- package/templates/nextjs-standalone/src/lib/scheduler/__tests__/format-email.test.ts +0 -96
- package/templates/nextjs-standalone/src/lib/scheduler/__tests__/format-slack.test.ts +0 -78
- package/templates/nextjs-standalone/src/lib/scheduler/__tests__/format-webhook.test.ts +0 -78
- package/templates/nextjs-standalone/src/lib/scheduler/index.ts +0 -7
- package/templates/nextjs-standalone/src/lib/slack/__tests__/api.test.ts +0 -160
- package/templates/nextjs-standalone/src/lib/slack/__tests__/format.test.ts +0 -237
- package/templates/nextjs-standalone/src/lib/slack/__tests__/store.test.ts +0 -188
- package/templates/nextjs-standalone/src/lib/slack/__tests__/threads.test.ts +0 -112
- package/templates/nextjs-standalone/src/lib/slack/__tests__/verify.test.ts +0 -111
- package/templates/nextjs-standalone/src/lib/tools/__tests__/action-permissions.test.ts +0 -594
- package/templates/nextjs-standalone/src/lib/tools/__tests__/custom-validation.test.ts +0 -240
- package/templates/nextjs-standalone/src/lib/tools/__tests__/explore-backend.test.ts +0 -267
- package/templates/nextjs-standalone/src/lib/tools/__tests__/explore-nsjail.test.ts +0 -506
- package/templates/nextjs-standalone/src/lib/tools/__tests__/explore-plugin.test.ts +0 -374
- package/templates/nextjs-standalone/src/lib/tools/__tests__/explore-sdk-compat.test.ts +0 -82
- package/templates/nextjs-standalone/src/lib/tools/__tests__/explore-sidecar.test.ts +0 -210
- package/templates/nextjs-standalone/src/lib/tools/__tests__/python-nsjail.test.ts +0 -515
- package/templates/nextjs-standalone/src/lib/tools/__tests__/python-sandbox.test.ts +0 -397
- package/templates/nextjs-standalone/src/lib/tools/__tests__/python-sidecar.test.ts +0 -365
- package/templates/nextjs-standalone/src/lib/tools/__tests__/python.test.ts +0 -331
- package/templates/nextjs-standalone/src/lib/tools/__tests__/registry-actions.test.ts +0 -132
- package/templates/nextjs-standalone/src/lib/tools/__tests__/registry.test.ts +0 -242
- package/templates/nextjs-standalone/src/lib/tools/__tests__/sql-audit.test.ts +0 -227
- package/templates/nextjs-standalone/src/lib/tools/__tests__/sql-connection-whitelist.test.ts +0 -100
- package/templates/nextjs-standalone/src/lib/tools/__tests__/sql-ratelimit.test.ts +0 -227
- package/templates/nextjs-standalone/src/lib/tools/__tests__/sql.test.ts +0 -709
- package/templates/nextjs-standalone/src/lib/tools/actions/__tests__/audit.test.ts +0 -211
- package/templates/nextjs-standalone/src/lib/tools/actions/__tests__/email.test.ts +0 -378
- package/templates/nextjs-standalone/src/lib/tools/actions/__tests__/handler.test.ts +0 -681
- package/templates/nextjs-standalone/src/lib/tools/actions/__tests__/jira.test.ts +0 -427
- package/templates/nextjs-standalone/src/test-setup.ts +0 -38
- package/templates/nextjs-standalone/src/ui/components/chat/managed-auth-card.tsx +0 -116
|
@@ -0,0 +1,760 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Platform admin routes — cross-tenant management for operators.
|
|
3
|
+
*
|
|
4
|
+
* Mounted at /api/v1/platform. All routes require `platform_admin` user role
|
|
5
|
+
* (via Better Auth's admin plugin). This is separate from workspace-scoped
|
|
6
|
+
* admin routes in admin.ts.
|
|
7
|
+
*
|
|
8
|
+
* Provides:
|
|
9
|
+
* - GET /workspaces — list all workspaces with health/usage
|
|
10
|
+
* - GET /workspaces/:id — detailed workspace view
|
|
11
|
+
* - POST /workspaces/:id/suspend — suspend a workspace
|
|
12
|
+
* - POST /workspaces/:id/unsuspend — reactivate a workspace
|
|
13
|
+
* - DELETE /workspaces/:id — delete with cascading cleanup
|
|
14
|
+
* - PATCH /workspaces/:id/plan — change plan tier
|
|
15
|
+
* - GET /stats — aggregate platform stats
|
|
16
|
+
* - GET /noisy-neighbors — workspaces consuming disproportionate resources
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { createRoute, z } from "@hono/zod-openapi";
|
|
20
|
+
import { createPlatformRouter } from "./admin-router";
|
|
21
|
+
import { Effect } from "effect";
|
|
22
|
+
import { createLogger } from "@atlas/api/lib/logger";
|
|
23
|
+
import { runEffect } from "@atlas/api/lib/effect/hono";
|
|
24
|
+
import {
|
|
25
|
+
RequestContext,
|
|
26
|
+
} from "@atlas/api/lib/effect/services";
|
|
27
|
+
import {
|
|
28
|
+
hasInternalDB,
|
|
29
|
+
internalQuery,
|
|
30
|
+
getWorkspaceDetails,
|
|
31
|
+
updateWorkspaceStatus,
|
|
32
|
+
updateWorkspacePlanTier,
|
|
33
|
+
cascadeWorkspaceDelete,
|
|
34
|
+
type WorkspaceRow,
|
|
35
|
+
type PlanTier,
|
|
36
|
+
type WorkspaceStatus,
|
|
37
|
+
} from "@atlas/api/lib/db/internal";
|
|
38
|
+
import {
|
|
39
|
+
WORKSPACE_STATUSES,
|
|
40
|
+
PLAN_TIERS,
|
|
41
|
+
NOISY_NEIGHBOR_METRICS,
|
|
42
|
+
type PlatformWorkspace,
|
|
43
|
+
} from "@useatlas/types";
|
|
44
|
+
import { ATLAS_ROLES, type AtlasRole } from "@atlas/api/lib/auth/types";
|
|
45
|
+
import { ErrorSchema, AuthErrorSchema } from "./shared-schemas";
|
|
46
|
+
|
|
47
|
+
const log = createLogger("platform-admin");
|
|
48
|
+
|
|
49
|
+
const VALID_PLAN_TIERS = new Set<string>(PLAN_TIERS);
|
|
50
|
+
|
|
51
|
+
// ---------------------------------------------------------------------------
|
|
52
|
+
// Schemas
|
|
53
|
+
// ---------------------------------------------------------------------------
|
|
54
|
+
|
|
55
|
+
const PlatformWorkspaceSchema = z.object({
|
|
56
|
+
id: z.string(),
|
|
57
|
+
name: z.string(),
|
|
58
|
+
slug: z.string(),
|
|
59
|
+
status: z.enum(WORKSPACE_STATUSES),
|
|
60
|
+
planTier: z.enum(PLAN_TIERS),
|
|
61
|
+
byot: z.boolean(),
|
|
62
|
+
members: z.number(),
|
|
63
|
+
conversations: z.number(),
|
|
64
|
+
queriesLast24h: z.number(),
|
|
65
|
+
connections: z.number(),
|
|
66
|
+
scheduledTasks: z.number(),
|
|
67
|
+
stripeCustomerId: z.string().nullable(),
|
|
68
|
+
trialEndsAt: z.string().nullable(),
|
|
69
|
+
suspendedAt: z.string().nullable(),
|
|
70
|
+
deletedAt: z.string().nullable(),
|
|
71
|
+
region: z.string().nullable(),
|
|
72
|
+
regionAssignedAt: z.string().nullable(),
|
|
73
|
+
createdAt: z.string(),
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const PlatformWorkspaceUserSchema = z.object({
|
|
77
|
+
id: z.string(),
|
|
78
|
+
name: z.string(),
|
|
79
|
+
email: z.string(),
|
|
80
|
+
role: z.enum(ATLAS_ROLES),
|
|
81
|
+
createdAt: z.string(),
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
const PlatformStatsSchema = z.object({
|
|
85
|
+
totalWorkspaces: z.number(),
|
|
86
|
+
activeWorkspaces: z.number(),
|
|
87
|
+
suspendedWorkspaces: z.number(),
|
|
88
|
+
totalUsers: z.number(),
|
|
89
|
+
totalQueries24h: z.number(),
|
|
90
|
+
mrr: z.number(),
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const NoisyNeighborSchema = z.object({
|
|
94
|
+
workspaceId: z.string(),
|
|
95
|
+
workspaceName: z.string(),
|
|
96
|
+
planTier: z.enum(PLAN_TIERS),
|
|
97
|
+
metric: z.enum(NOISY_NEIGHBOR_METRICS),
|
|
98
|
+
value: z.number(),
|
|
99
|
+
median: z.number(),
|
|
100
|
+
ratio: z.number(),
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
const ChangePlanBodySchema = z.object({
|
|
104
|
+
planTier: z.enum(PLAN_TIERS).openapi({
|
|
105
|
+
description: "The new plan tier for the workspace.",
|
|
106
|
+
example: "team",
|
|
107
|
+
}),
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
// ---------------------------------------------------------------------------
|
|
111
|
+
// Route definitions
|
|
112
|
+
// ---------------------------------------------------------------------------
|
|
113
|
+
|
|
114
|
+
const listWorkspacesRoute = createRoute({
|
|
115
|
+
method: "get",
|
|
116
|
+
path: "/workspaces",
|
|
117
|
+
tags: ["Platform Admin"],
|
|
118
|
+
summary: "List all workspaces",
|
|
119
|
+
description: "SaaS only. Returns all workspaces across the platform with health metrics, usage data, plan info, and status.",
|
|
120
|
+
responses: {
|
|
121
|
+
200: {
|
|
122
|
+
description: "Workspaces list",
|
|
123
|
+
content: { "application/json": { schema: z.object({ workspaces: z.array(PlatformWorkspaceSchema) }) } },
|
|
124
|
+
},
|
|
125
|
+
401: { description: "Authentication required", content: { "application/json": { schema: AuthErrorSchema } } },
|
|
126
|
+
403: { description: "Platform admin role required", content: { "application/json": { schema: AuthErrorSchema } } },
|
|
127
|
+
404: { description: "Internal database not configured", content: { "application/json": { schema: ErrorSchema } } },
|
|
128
|
+
500: { description: "Internal server error", content: { "application/json": { schema: ErrorSchema } } },
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
const getWorkspaceRoute = createRoute({
|
|
133
|
+
method: "get",
|
|
134
|
+
path: "/workspaces/:id",
|
|
135
|
+
tags: ["Platform Admin"],
|
|
136
|
+
summary: "Get workspace details",
|
|
137
|
+
description: "SaaS only. Returns detailed workspace information including resource breakdown and user list.",
|
|
138
|
+
responses: {
|
|
139
|
+
200: {
|
|
140
|
+
description: "Workspace detail",
|
|
141
|
+
content: {
|
|
142
|
+
"application/json": {
|
|
143
|
+
schema: z.object({
|
|
144
|
+
workspace: PlatformWorkspaceSchema,
|
|
145
|
+
users: z.array(PlatformWorkspaceUserSchema),
|
|
146
|
+
}),
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
401: { description: "Authentication required", content: { "application/json": { schema: AuthErrorSchema } } },
|
|
151
|
+
403: { description: "Platform admin role required", content: { "application/json": { schema: AuthErrorSchema } } },
|
|
152
|
+
404: { description: "Workspace not found", content: { "application/json": { schema: ErrorSchema } } },
|
|
153
|
+
500: { description: "Internal server error", content: { "application/json": { schema: ErrorSchema } } },
|
|
154
|
+
},
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
const suspendWorkspaceRoute = createRoute({
|
|
158
|
+
method: "post",
|
|
159
|
+
path: "/workspaces/:id/suspend",
|
|
160
|
+
tags: ["Platform Admin"],
|
|
161
|
+
summary: "Suspend a workspace",
|
|
162
|
+
description: "SaaS only. Suspends a workspace, preventing all user access until reactivated.",
|
|
163
|
+
responses: {
|
|
164
|
+
200: {
|
|
165
|
+
description: "Workspace suspended",
|
|
166
|
+
content: { "application/json": { schema: z.object({ message: z.string(), workspaceId: z.string() }) } },
|
|
167
|
+
},
|
|
168
|
+
401: { description: "Authentication required", content: { "application/json": { schema: AuthErrorSchema } } },
|
|
169
|
+
403: { description: "Platform admin role required", content: { "application/json": { schema: AuthErrorSchema } } },
|
|
170
|
+
404: { description: "Workspace not found", content: { "application/json": { schema: ErrorSchema } } },
|
|
171
|
+
409: { description: "Workspace already suspended", content: { "application/json": { schema: ErrorSchema } } },
|
|
172
|
+
500: { description: "Internal server error", content: { "application/json": { schema: ErrorSchema } } },
|
|
173
|
+
},
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
const unsuspendWorkspaceRoute = createRoute({
|
|
177
|
+
method: "post",
|
|
178
|
+
path: "/workspaces/:id/unsuspend",
|
|
179
|
+
tags: ["Platform Admin"],
|
|
180
|
+
summary: "Unsuspend a workspace",
|
|
181
|
+
description: "SaaS only. Reactivates a suspended workspace, restoring user access.",
|
|
182
|
+
responses: {
|
|
183
|
+
200: {
|
|
184
|
+
description: "Workspace reactivated",
|
|
185
|
+
content: { "application/json": { schema: z.object({ message: z.string(), workspaceId: z.string() }) } },
|
|
186
|
+
},
|
|
187
|
+
401: { description: "Authentication required", content: { "application/json": { schema: AuthErrorSchema } } },
|
|
188
|
+
403: { description: "Platform admin role required", content: { "application/json": { schema: AuthErrorSchema } } },
|
|
189
|
+
404: { description: "Workspace not found", content: { "application/json": { schema: ErrorSchema } } },
|
|
190
|
+
409: { description: "Workspace not suspended", content: { "application/json": { schema: ErrorSchema } } },
|
|
191
|
+
500: { description: "Internal server error", content: { "application/json": { schema: ErrorSchema } } },
|
|
192
|
+
},
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
const deleteWorkspaceRoute = createRoute({
|
|
196
|
+
method: "delete",
|
|
197
|
+
path: "/workspaces/:id",
|
|
198
|
+
tags: ["Platform Admin"],
|
|
199
|
+
summary: "Delete a workspace",
|
|
200
|
+
description: "SaaS only. Soft-deletes a workspace with cascading cleanup (conversations, semantic entities, learned patterns, suggestions, scheduled tasks).",
|
|
201
|
+
responses: {
|
|
202
|
+
200: {
|
|
203
|
+
description: "Workspace deleted",
|
|
204
|
+
content: {
|
|
205
|
+
"application/json": {
|
|
206
|
+
schema: z.object({
|
|
207
|
+
message: z.string(),
|
|
208
|
+
workspaceId: z.string(),
|
|
209
|
+
cleanup: z.object({
|
|
210
|
+
conversations: z.number(),
|
|
211
|
+
semanticEntities: z.number(),
|
|
212
|
+
learnedPatterns: z.number(),
|
|
213
|
+
suggestions: z.number(),
|
|
214
|
+
scheduledTasks: z.number(),
|
|
215
|
+
}),
|
|
216
|
+
}),
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
},
|
|
220
|
+
401: { description: "Authentication required", content: { "application/json": { schema: AuthErrorSchema } } },
|
|
221
|
+
403: { description: "Platform admin role required", content: { "application/json": { schema: AuthErrorSchema } } },
|
|
222
|
+
404: { description: "Workspace not found", content: { "application/json": { schema: ErrorSchema } } },
|
|
223
|
+
409: { description: "Workspace already deleted", content: { "application/json": { schema: ErrorSchema } } },
|
|
224
|
+
500: { description: "Internal server error", content: { "application/json": { schema: ErrorSchema } } },
|
|
225
|
+
},
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
const changePlanRoute = createRoute({
|
|
229
|
+
method: "patch",
|
|
230
|
+
path: "/workspaces/:id/plan",
|
|
231
|
+
tags: ["Platform Admin"],
|
|
232
|
+
summary: "Change workspace plan tier",
|
|
233
|
+
description: "SaaS only. Updates the plan tier for a workspace (free, trial, team, enterprise).",
|
|
234
|
+
request: { body: { required: true, content: { "application/json": { schema: ChangePlanBodySchema } } } },
|
|
235
|
+
responses: {
|
|
236
|
+
200: {
|
|
237
|
+
description: "Plan updated",
|
|
238
|
+
content: { "application/json": { schema: z.object({ message: z.string(), workspaceId: z.string(), planTier: z.string() }) } },
|
|
239
|
+
},
|
|
240
|
+
400: { description: "Invalid plan tier", content: { "application/json": { schema: ErrorSchema } } },
|
|
241
|
+
401: { description: "Authentication required", content: { "application/json": { schema: AuthErrorSchema } } },
|
|
242
|
+
403: { description: "Platform admin role required", content: { "application/json": { schema: AuthErrorSchema } } },
|
|
243
|
+
404: { description: "Workspace not found", content: { "application/json": { schema: ErrorSchema } } },
|
|
244
|
+
500: { description: "Internal server error", content: { "application/json": { schema: ErrorSchema } } },
|
|
245
|
+
},
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
const platformStatsRoute = createRoute({
|
|
249
|
+
method: "get",
|
|
250
|
+
path: "/stats",
|
|
251
|
+
tags: ["Platform Admin"],
|
|
252
|
+
summary: "Aggregate platform stats",
|
|
253
|
+
description: "SaaS only. Returns aggregate platform statistics: total workspaces, active users, total queries, MRR.",
|
|
254
|
+
responses: {
|
|
255
|
+
200: {
|
|
256
|
+
description: "Platform statistics",
|
|
257
|
+
content: { "application/json": { schema: PlatformStatsSchema } },
|
|
258
|
+
},
|
|
259
|
+
401: { description: "Authentication required", content: { "application/json": { schema: AuthErrorSchema } } },
|
|
260
|
+
403: { description: "Platform admin role required", content: { "application/json": { schema: AuthErrorSchema } } },
|
|
261
|
+
404: { description: "Internal database not configured", content: { "application/json": { schema: ErrorSchema } } },
|
|
262
|
+
500: { description: "Internal server error", content: { "application/json": { schema: ErrorSchema } } },
|
|
263
|
+
},
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
const noisyNeighborsRoute = createRoute({
|
|
267
|
+
method: "get",
|
|
268
|
+
path: "/noisy-neighbors",
|
|
269
|
+
tags: ["Platform Admin"],
|
|
270
|
+
summary: "Detect noisy neighbors",
|
|
271
|
+
description: "SaaS only. Identifies workspaces consuming disproportionate resources (>3x median queries, tokens, or storage).",
|
|
272
|
+
responses: {
|
|
273
|
+
200: {
|
|
274
|
+
description: "Noisy neighbors list",
|
|
275
|
+
content: { "application/json": { schema: z.object({ neighbors: z.array(NoisyNeighborSchema), medians: z.object({ queries: z.number(), tokens: z.number(), storage: z.number() }) }) } },
|
|
276
|
+
},
|
|
277
|
+
401: { description: "Authentication required", content: { "application/json": { schema: AuthErrorSchema } } },
|
|
278
|
+
403: { description: "Platform admin role required", content: { "application/json": { schema: AuthErrorSchema } } },
|
|
279
|
+
404: { description: "Internal database not configured", content: { "application/json": { schema: ErrorSchema } } },
|
|
280
|
+
500: { description: "Internal server error", content: { "application/json": { schema: ErrorSchema } } },
|
|
281
|
+
},
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
// ---------------------------------------------------------------------------
|
|
285
|
+
// Helpers
|
|
286
|
+
// ---------------------------------------------------------------------------
|
|
287
|
+
|
|
288
|
+
/** Build a PlatformWorkspace from a WorkspaceRow + health counts. */
|
|
289
|
+
function toWorkspaceResponse(
|
|
290
|
+
row: WorkspaceRow,
|
|
291
|
+
health: { members: number; conversations: number; queriesLast24h: number; connections: number; scheduledTasks: number },
|
|
292
|
+
): PlatformWorkspace {
|
|
293
|
+
return {
|
|
294
|
+
id: row.id,
|
|
295
|
+
name: row.name,
|
|
296
|
+
slug: row.slug,
|
|
297
|
+
status: row.workspace_status,
|
|
298
|
+
planTier: row.plan_tier,
|
|
299
|
+
byot: row.byot,
|
|
300
|
+
members: health.members,
|
|
301
|
+
conversations: health.conversations,
|
|
302
|
+
queriesLast24h: health.queriesLast24h,
|
|
303
|
+
connections: health.connections,
|
|
304
|
+
scheduledTasks: health.scheduledTasks,
|
|
305
|
+
stripeCustomerId: row.stripe_customer_id,
|
|
306
|
+
trialEndsAt: row.trial_ends_at,
|
|
307
|
+
suspendedAt: row.suspended_at,
|
|
308
|
+
deletedAt: row.deleted_at,
|
|
309
|
+
region: row.region,
|
|
310
|
+
regionAssignedAt: row.region_assigned_at,
|
|
311
|
+
createdAt: row.createdAt,
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Compute median from a sorted array of numbers.
|
|
317
|
+
*/
|
|
318
|
+
function median(values: number[]): number {
|
|
319
|
+
if (values.length === 0) return 0;
|
|
320
|
+
const sorted = values.toSorted((a, b) => a - b);
|
|
321
|
+
const mid = Math.floor(sorted.length / 2);
|
|
322
|
+
return sorted.length % 2 !== 0
|
|
323
|
+
? sorted[mid]
|
|
324
|
+
: (sorted[mid - 1] + sorted[mid]) / 2;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// MRR estimates per plan tier (monthly recurring revenue)
|
|
328
|
+
const PLAN_MRR: Record<string, number> = {
|
|
329
|
+
free: 0,
|
|
330
|
+
trial: 0,
|
|
331
|
+
team: 99,
|
|
332
|
+
enterprise: 499,
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
// ---------------------------------------------------------------------------
|
|
336
|
+
// Router
|
|
337
|
+
// ---------------------------------------------------------------------------
|
|
338
|
+
|
|
339
|
+
const platformAdmin = createPlatformRouter();
|
|
340
|
+
|
|
341
|
+
// ── List workspaces ──────────────────────────────────────────────────
|
|
342
|
+
|
|
343
|
+
platformAdmin.openapi(listWorkspacesRoute, async (c) => {
|
|
344
|
+
return runEffect(c, Effect.gen(function* () {
|
|
345
|
+
const { requestId } = yield* RequestContext;
|
|
346
|
+
|
|
347
|
+
if (!hasInternalDB()) {
|
|
348
|
+
return c.json({ error: "not_configured", message: "Internal database not configured.", requestId }, 404);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
const rows = yield* Effect.promise(() => internalQuery<{
|
|
352
|
+
id: string;
|
|
353
|
+
name: string;
|
|
354
|
+
slug: string;
|
|
355
|
+
workspace_status: WorkspaceStatus;
|
|
356
|
+
plan_tier: PlanTier;
|
|
357
|
+
byot: boolean;
|
|
358
|
+
stripe_customer_id: string | null;
|
|
359
|
+
trial_ends_at: string | null;
|
|
360
|
+
suspended_at: string | null;
|
|
361
|
+
deleted_at: string | null;
|
|
362
|
+
region: string | null;
|
|
363
|
+
region_assigned_at: string | null;
|
|
364
|
+
createdAt: string;
|
|
365
|
+
members: number;
|
|
366
|
+
conversations: number;
|
|
367
|
+
queries_last_24h: number;
|
|
368
|
+
connections: number;
|
|
369
|
+
scheduled_tasks: number;
|
|
370
|
+
}>(
|
|
371
|
+
`SELECT
|
|
372
|
+
o.id, o.name, o.slug, o.workspace_status, o.plan_tier, o.byot,
|
|
373
|
+
o.stripe_customer_id, o.trial_ends_at, o.suspended_at, o.deleted_at,
|
|
374
|
+
o.region, o.region_assigned_at, o."createdAt",
|
|
375
|
+
COALESCE(m.cnt, 0)::int AS members,
|
|
376
|
+
COALESCE(cv.cnt, 0)::int AS conversations,
|
|
377
|
+
COALESCE(al.cnt, 0)::int AS queries_last_24h,
|
|
378
|
+
COALESCE(cn.cnt, 0)::int AS connections,
|
|
379
|
+
COALESCE(st.cnt, 0)::int AS scheduled_tasks
|
|
380
|
+
FROM organization o
|
|
381
|
+
LEFT JOIN (SELECT "organizationId", COUNT(*)::int AS cnt FROM member GROUP BY "organizationId") m ON m."organizationId" = o.id
|
|
382
|
+
LEFT JOIN (SELECT org_id, COUNT(*)::int AS cnt FROM conversations GROUP BY org_id) cv ON cv.org_id = o.id
|
|
383
|
+
LEFT JOIN (SELECT org_id, COUNT(*)::int AS cnt FROM audit_log WHERE timestamp > now() - interval '24 hours' GROUP BY org_id) al ON al.org_id = o.id
|
|
384
|
+
LEFT JOIN (SELECT org_id, COUNT(*)::int AS cnt FROM connections GROUP BY org_id) cn ON cn.org_id = o.id
|
|
385
|
+
LEFT JOIN (SELECT org_id, COUNT(*)::int AS cnt FROM scheduled_tasks WHERE enabled = true GROUP BY org_id) st ON st.org_id = o.id
|
|
386
|
+
ORDER BY o."createdAt" DESC`,
|
|
387
|
+
));
|
|
388
|
+
|
|
389
|
+
const workspaces = rows.map((row) => ({
|
|
390
|
+
id: row.id,
|
|
391
|
+
name: row.name,
|
|
392
|
+
slug: row.slug,
|
|
393
|
+
status: row.workspace_status,
|
|
394
|
+
planTier: row.plan_tier,
|
|
395
|
+
byot: row.byot,
|
|
396
|
+
members: row.members,
|
|
397
|
+
conversations: row.conversations,
|
|
398
|
+
queriesLast24h: row.queries_last_24h,
|
|
399
|
+
connections: row.connections,
|
|
400
|
+
scheduledTasks: row.scheduled_tasks,
|
|
401
|
+
stripeCustomerId: row.stripe_customer_id,
|
|
402
|
+
trialEndsAt: row.trial_ends_at,
|
|
403
|
+
suspendedAt: row.suspended_at,
|
|
404
|
+
deletedAt: row.deleted_at,
|
|
405
|
+
region: row.region,
|
|
406
|
+
regionAssignedAt: row.region_assigned_at,
|
|
407
|
+
createdAt: row.createdAt,
|
|
408
|
+
}));
|
|
409
|
+
|
|
410
|
+
return c.json({ workspaces }, 200);
|
|
411
|
+
}), { label: "list workspaces" });
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
// ── Get workspace detail ─────────────────────────────────────────────
|
|
415
|
+
|
|
416
|
+
platformAdmin.openapi(getWorkspaceRoute, async (c) => {
|
|
417
|
+
return runEffect(c, Effect.gen(function* () {
|
|
418
|
+
const { requestId } = yield* RequestContext;
|
|
419
|
+
|
|
420
|
+
if (!hasInternalDB()) {
|
|
421
|
+
return c.json({ error: "not_configured", message: "Internal database not configured.", requestId }, 404);
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
const workspaceId = c.req.param("id");
|
|
425
|
+
|
|
426
|
+
const workspace = yield* Effect.promise(() => getWorkspaceDetails(workspaceId));
|
|
427
|
+
if (!workspace) {
|
|
428
|
+
return c.json({ error: "not_found", message: "Workspace not found.", requestId }, 404);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
const [memberRows, convRows, queryRows, connRows, taskRows, userRows] = yield* Effect.promise(() => Promise.all([
|
|
432
|
+
internalQuery<{ count: number }>(
|
|
433
|
+
`SELECT COUNT(*)::int as count FROM member WHERE "organizationId" = $1`,
|
|
434
|
+
[workspaceId],
|
|
435
|
+
),
|
|
436
|
+
internalQuery<{ count: number }>(
|
|
437
|
+
`SELECT COUNT(*)::int as count FROM conversations WHERE org_id = $1`,
|
|
438
|
+
[workspaceId],
|
|
439
|
+
),
|
|
440
|
+
internalQuery<{ count: number }>(
|
|
441
|
+
`SELECT COUNT(*)::int as count FROM audit_log WHERE org_id = $1 AND timestamp > now() - interval '24 hours'`,
|
|
442
|
+
[workspaceId],
|
|
443
|
+
),
|
|
444
|
+
internalQuery<{ count: number }>(
|
|
445
|
+
`SELECT COUNT(*)::int as count FROM connections WHERE org_id = $1`,
|
|
446
|
+
[workspaceId],
|
|
447
|
+
),
|
|
448
|
+
internalQuery<{ count: number }>(
|
|
449
|
+
`SELECT COUNT(*)::int as count FROM scheduled_tasks WHERE org_id = $1 AND enabled = true`,
|
|
450
|
+
[workspaceId],
|
|
451
|
+
),
|
|
452
|
+
internalQuery<{ id: string; name: string; email: string; role: AtlasRole; createdAt: string }>(
|
|
453
|
+
`SELECT u.id, u.name, u.email, m.role, u."createdAt"
|
|
454
|
+
FROM "user" u
|
|
455
|
+
JOIN member m ON m."userId" = u.id
|
|
456
|
+
WHERE m."organizationId" = $1
|
|
457
|
+
ORDER BY u."createdAt" ASC`,
|
|
458
|
+
[workspaceId],
|
|
459
|
+
),
|
|
460
|
+
]));
|
|
461
|
+
|
|
462
|
+
const ws = toWorkspaceResponse(workspace, {
|
|
463
|
+
members: memberRows[0]?.count ?? 0,
|
|
464
|
+
conversations: convRows[0]?.count ?? 0,
|
|
465
|
+
queriesLast24h: queryRows[0]?.count ?? 0,
|
|
466
|
+
connections: connRows[0]?.count ?? 0,
|
|
467
|
+
scheduledTasks: taskRows[0]?.count ?? 0,
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
const users = userRows.map((u) => ({
|
|
471
|
+
id: u.id,
|
|
472
|
+
name: u.name,
|
|
473
|
+
email: u.email,
|
|
474
|
+
role: u.role,
|
|
475
|
+
createdAt: u.createdAt,
|
|
476
|
+
}));
|
|
477
|
+
|
|
478
|
+
return c.json({ workspace: ws, users }, 200);
|
|
479
|
+
}), { label: "get workspace details" });
|
|
480
|
+
});
|
|
481
|
+
|
|
482
|
+
// ── Suspend workspace ────────────────────────────────────────────────
|
|
483
|
+
|
|
484
|
+
platformAdmin.openapi(suspendWorkspaceRoute, async (c) => {
|
|
485
|
+
return runEffect(c, Effect.gen(function* () {
|
|
486
|
+
const { requestId } = yield* RequestContext;
|
|
487
|
+
|
|
488
|
+
if (!hasInternalDB()) {
|
|
489
|
+
return c.json({ error: "not_configured", message: "Internal database not configured.", requestId }, 404);
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
const workspaceId = c.req.param("id");
|
|
493
|
+
|
|
494
|
+
const workspace = yield* Effect.promise(() => getWorkspaceDetails(workspaceId));
|
|
495
|
+
if (!workspace) {
|
|
496
|
+
return c.json({ error: "not_found", message: "Workspace not found.", requestId }, 404);
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
if (workspace.workspace_status === "suspended") {
|
|
500
|
+
return c.json({ error: "conflict", message: "Workspace is already suspended.", requestId }, 409);
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
if (workspace.workspace_status === "deleted") {
|
|
504
|
+
return c.json({ error: "conflict", message: "Cannot suspend a deleted workspace.", requestId }, 409);
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
yield* Effect.promise(() => updateWorkspaceStatus(workspaceId, "suspended"));
|
|
508
|
+
log.info({ workspaceId, requestId }, "Workspace suspended by platform admin");
|
|
509
|
+
|
|
510
|
+
return c.json({ message: "Workspace suspended.", workspaceId }, 200);
|
|
511
|
+
}), { label: "suspend workspace" });
|
|
512
|
+
});
|
|
513
|
+
|
|
514
|
+
// ── Unsuspend workspace ──────────────────────────────────────────────
|
|
515
|
+
|
|
516
|
+
platformAdmin.openapi(unsuspendWorkspaceRoute, async (c) => {
|
|
517
|
+
return runEffect(c, Effect.gen(function* () {
|
|
518
|
+
const { requestId } = yield* RequestContext;
|
|
519
|
+
|
|
520
|
+
if (!hasInternalDB()) {
|
|
521
|
+
return c.json({ error: "not_configured", message: "Internal database not configured.", requestId }, 404);
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
const workspaceId = c.req.param("id");
|
|
525
|
+
|
|
526
|
+
const workspace = yield* Effect.promise(() => getWorkspaceDetails(workspaceId));
|
|
527
|
+
if (!workspace) {
|
|
528
|
+
return c.json({ error: "not_found", message: "Workspace not found.", requestId }, 404);
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
if (workspace.workspace_status !== "suspended") {
|
|
532
|
+
return c.json({ error: "conflict", message: "Workspace is not suspended.", requestId }, 409);
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
yield* Effect.promise(() => updateWorkspaceStatus(workspaceId, "active"));
|
|
536
|
+
log.info({ workspaceId, requestId }, "Workspace unsuspended by platform admin");
|
|
537
|
+
|
|
538
|
+
return c.json({ message: "Workspace reactivated.", workspaceId }, 200);
|
|
539
|
+
}), { label: "unsuspend workspace" });
|
|
540
|
+
});
|
|
541
|
+
|
|
542
|
+
// ── Delete workspace ─────────────────────────────────────────────────
|
|
543
|
+
|
|
544
|
+
platformAdmin.openapi(deleteWorkspaceRoute, async (c) => {
|
|
545
|
+
return runEffect(c, Effect.gen(function* () {
|
|
546
|
+
const { requestId } = yield* RequestContext;
|
|
547
|
+
|
|
548
|
+
if (!hasInternalDB()) {
|
|
549
|
+
return c.json({ error: "not_configured", message: "Internal database not configured.", requestId }, 404);
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
const workspaceId = c.req.param("id");
|
|
553
|
+
|
|
554
|
+
const workspace = yield* Effect.promise(() => getWorkspaceDetails(workspaceId));
|
|
555
|
+
if (!workspace) {
|
|
556
|
+
return c.json({ error: "not_found", message: "Workspace not found.", requestId }, 404);
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
if (workspace.workspace_status === "deleted") {
|
|
560
|
+
return c.json({ error: "conflict", message: "Workspace is already deleted.", requestId }, 409);
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
// Cascade cleanup first, then mark as deleted — if cleanup fails,
|
|
564
|
+
// the workspace remains in its current state and can be retried.
|
|
565
|
+
const cleanup = yield* Effect.tryPromise({
|
|
566
|
+
try: () => cascadeWorkspaceDelete(workspaceId),
|
|
567
|
+
catch: (err) => err instanceof Error ? err : new Error(String(err)),
|
|
568
|
+
});
|
|
569
|
+
yield* Effect.tryPromise({
|
|
570
|
+
try: () => updateWorkspaceStatus(workspaceId, "deleted"),
|
|
571
|
+
catch: (err) => err instanceof Error ? err : new Error(String(err)),
|
|
572
|
+
});
|
|
573
|
+
|
|
574
|
+
log.info({ workspaceId, cleanup, requestId }, "Workspace deleted by platform admin");
|
|
575
|
+
|
|
576
|
+
return c.json({
|
|
577
|
+
message: "Workspace deleted.",
|
|
578
|
+
workspaceId,
|
|
579
|
+
cleanup,
|
|
580
|
+
}, 200);
|
|
581
|
+
}), { label: "delete workspace" });
|
|
582
|
+
});
|
|
583
|
+
|
|
584
|
+
// ── Change plan ──────────────────────────────────────────────────────
|
|
585
|
+
|
|
586
|
+
platformAdmin.openapi(changePlanRoute, async (c) => {
|
|
587
|
+
return runEffect(c, Effect.gen(function* () {
|
|
588
|
+
const { requestId } = yield* RequestContext;
|
|
589
|
+
|
|
590
|
+
if (!hasInternalDB()) {
|
|
591
|
+
return c.json({ error: "not_configured", message: "Internal database not configured.", requestId }, 404);
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
const workspaceId = c.req.param("id");
|
|
595
|
+
const body = c.req.valid("json");
|
|
596
|
+
const { planTier } = body;
|
|
597
|
+
|
|
598
|
+
if (!VALID_PLAN_TIERS.has(planTier)) {
|
|
599
|
+
return c.json({ error: "validation_error", message: `Invalid plan tier: ${planTier}`, requestId }, 400);
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
const workspace = yield* Effect.promise(() => getWorkspaceDetails(workspaceId));
|
|
603
|
+
if (!workspace) {
|
|
604
|
+
return c.json({ error: "not_found", message: "Workspace not found.", requestId }, 404);
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
const updated = yield* Effect.promise(() => updateWorkspacePlanTier(workspaceId, planTier as PlanTier));
|
|
608
|
+
if (!updated) {
|
|
609
|
+
return c.json({ error: "not_found", message: "Workspace not found.", requestId }, 404);
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
// Invalidate the billing enforcement cache for this org
|
|
613
|
+
yield* Effect.tryPromise({
|
|
614
|
+
try: async () => {
|
|
615
|
+
const { invalidatePlanCache } = await import("@atlas/api/lib/billing/enforcement");
|
|
616
|
+
invalidatePlanCache(workspaceId);
|
|
617
|
+
},
|
|
618
|
+
catch: (err) => err instanceof Error ? err : new Error(String(err)),
|
|
619
|
+
}).pipe(Effect.catchAll((err) => {
|
|
620
|
+
log.warn(
|
|
621
|
+
{ err: err.message, workspaceId, requestId },
|
|
622
|
+
"Failed to invalidate plan cache after tier change — stale limits may persist until cache expires",
|
|
623
|
+
);
|
|
624
|
+
return Effect.void;
|
|
625
|
+
}));
|
|
626
|
+
|
|
627
|
+
log.info({ workspaceId, planTier, previousTier: workspace.plan_tier, requestId }, "Workspace plan changed by platform admin");
|
|
628
|
+
|
|
629
|
+
return c.json({ message: "Plan updated.", workspaceId, planTier }, 200);
|
|
630
|
+
}), { label: "change workspace plan" });
|
|
631
|
+
});
|
|
632
|
+
|
|
633
|
+
// ── Platform stats ───────────────────────────────────────────────────
|
|
634
|
+
|
|
635
|
+
platformAdmin.openapi(platformStatsRoute, async (c) => {
|
|
636
|
+
return runEffect(c, Effect.gen(function* () {
|
|
637
|
+
const { requestId } = yield* RequestContext;
|
|
638
|
+
|
|
639
|
+
if (!hasInternalDB()) {
|
|
640
|
+
return c.json({ error: "not_configured", message: "Internal database not configured.", requestId }, 404);
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
const [wsRows, userRows, queryRows] = yield* Effect.promise(() => Promise.all([
|
|
644
|
+
internalQuery<{ total: number; active: number; suspended: number }>(
|
|
645
|
+
`SELECT
|
|
646
|
+
COUNT(*)::int AS total,
|
|
647
|
+
COUNT(*) FILTER (WHERE workspace_status = 'active')::int AS active,
|
|
648
|
+
COUNT(*) FILTER (WHERE workspace_status = 'suspended')::int AS suspended
|
|
649
|
+
FROM organization`,
|
|
650
|
+
),
|
|
651
|
+
internalQuery<{ count: number }>(
|
|
652
|
+
`SELECT COUNT(*)::int AS count FROM "user"`,
|
|
653
|
+
),
|
|
654
|
+
internalQuery<{ count: number }>(
|
|
655
|
+
`SELECT COUNT(*)::int AS count FROM audit_log WHERE timestamp > now() - interval '24 hours'`,
|
|
656
|
+
),
|
|
657
|
+
]));
|
|
658
|
+
|
|
659
|
+
// MRR: sum of PLAN_MRR for each active workspace's plan tier
|
|
660
|
+
const mrrRows = yield* Effect.promise(() => internalQuery<{ plan_tier: string; cnt: number }>(
|
|
661
|
+
`SELECT plan_tier, COUNT(*)::int AS cnt FROM organization WHERE workspace_status = 'active' GROUP BY plan_tier`,
|
|
662
|
+
));
|
|
663
|
+
const mrr = mrrRows.reduce((sum, row) => sum + (PLAN_MRR[row.plan_tier] ?? 0) * row.cnt, 0);
|
|
664
|
+
|
|
665
|
+
return c.json({
|
|
666
|
+
totalWorkspaces: wsRows[0]?.total ?? 0,
|
|
667
|
+
activeWorkspaces: wsRows[0]?.active ?? 0,
|
|
668
|
+
suspendedWorkspaces: wsRows[0]?.suspended ?? 0,
|
|
669
|
+
totalUsers: userRows[0]?.count ?? 0,
|
|
670
|
+
totalQueries24h: queryRows[0]?.count ?? 0,
|
|
671
|
+
mrr,
|
|
672
|
+
}, 200);
|
|
673
|
+
}), { label: "compute platform stats" });
|
|
674
|
+
});
|
|
675
|
+
|
|
676
|
+
// ── Noisy neighbors ──────────────────────────────────────────────────
|
|
677
|
+
|
|
678
|
+
platformAdmin.openapi(noisyNeighborsRoute, async (c) => {
|
|
679
|
+
return runEffect(c, Effect.gen(function* () {
|
|
680
|
+
const { requestId } = yield* RequestContext;
|
|
681
|
+
|
|
682
|
+
if (!hasInternalDB()) {
|
|
683
|
+
return c.json({ error: "not_configured", message: "Internal database not configured.", requestId }, 404);
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
// Get current period usage for each active workspace
|
|
687
|
+
const rows = yield* Effect.promise(() => internalQuery<{
|
|
688
|
+
id: string;
|
|
689
|
+
name: string;
|
|
690
|
+
plan_tier: PlanTier;
|
|
691
|
+
query_count: number;
|
|
692
|
+
token_count: number;
|
|
693
|
+
storage_bytes: number;
|
|
694
|
+
}>(
|
|
695
|
+
`SELECT
|
|
696
|
+
o.id, o.name, o.plan_tier,
|
|
697
|
+
COALESCE(us.query_count, 0)::int AS query_count,
|
|
698
|
+
COALESCE(us.token_count, 0)::int AS token_count,
|
|
699
|
+
COALESCE(us.storage_bytes, 0)::int AS storage_bytes
|
|
700
|
+
FROM organization o
|
|
701
|
+
LEFT JOIN usage_summaries us
|
|
702
|
+
ON us.workspace_id = o.id
|
|
703
|
+
AND us.period = 'monthly'
|
|
704
|
+
AND us.period_start = date_trunc('month', now())
|
|
705
|
+
WHERE o.workspace_status = 'active'`,
|
|
706
|
+
));
|
|
707
|
+
|
|
708
|
+
if (rows.length === 0) {
|
|
709
|
+
return c.json({ neighbors: [], medians: { queries: 0, tokens: 0, storage: 0 } }, 200);
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
const queryValues = rows.map((r) => r.query_count);
|
|
713
|
+
const tokenValues = rows.map((r) => r.token_count);
|
|
714
|
+
const storageValues = rows.map((r) => r.storage_bytes);
|
|
715
|
+
|
|
716
|
+
const medians = {
|
|
717
|
+
queries: median(queryValues),
|
|
718
|
+
tokens: median(tokenValues),
|
|
719
|
+
storage: median(storageValues),
|
|
720
|
+
};
|
|
721
|
+
|
|
722
|
+
const THRESHOLD = 3;
|
|
723
|
+
type NoisyMetric = "queries" | "tokens" | "storage";
|
|
724
|
+
const neighbors: Array<{
|
|
725
|
+
workspaceId: string;
|
|
726
|
+
workspaceName: string;
|
|
727
|
+
planTier: PlanTier;
|
|
728
|
+
metric: NoisyMetric;
|
|
729
|
+
value: number;
|
|
730
|
+
median: number;
|
|
731
|
+
ratio: number;
|
|
732
|
+
}> = [];
|
|
733
|
+
|
|
734
|
+
for (const row of rows) {
|
|
735
|
+
const checks: Array<{ metric: NoisyMetric; value: number; med: number }> = [
|
|
736
|
+
{ metric: "queries", value: row.query_count, med: medians.queries },
|
|
737
|
+
{ metric: "tokens", value: row.token_count, med: medians.tokens },
|
|
738
|
+
{ metric: "storage", value: row.storage_bytes, med: medians.storage },
|
|
739
|
+
];
|
|
740
|
+
|
|
741
|
+
for (const check of checks) {
|
|
742
|
+
if (check.med > 0 && check.value > check.med * THRESHOLD) {
|
|
743
|
+
neighbors.push({
|
|
744
|
+
workspaceId: row.id,
|
|
745
|
+
workspaceName: row.name,
|
|
746
|
+
planTier: row.plan_tier,
|
|
747
|
+
metric: check.metric,
|
|
748
|
+
value: check.value,
|
|
749
|
+
median: check.med,
|
|
750
|
+
ratio: Math.round((check.value / check.med) * 100) / 100,
|
|
751
|
+
});
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
return c.json({ neighbors, medians }, 200);
|
|
757
|
+
}), { label: "detect noisy neighbors" });
|
|
758
|
+
});
|
|
759
|
+
|
|
760
|
+
export { platformAdmin };
|