@useatlas/create 0.0.6 → 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
|
@@ -2,13 +2,20 @@
|
|
|
2
2
|
* Chat route — accepts a conversation and streams agent responses.
|
|
3
3
|
*
|
|
4
4
|
* Middleware stack:
|
|
5
|
-
* auth → rate limit → withRequestContext → validateEnvironment → conversation persistence → runAgent → stream.
|
|
5
|
+
* withRequestId → auth → rate limit → withRequestContext(user) → validateEnvironment → conversation persistence → runAgent → stream.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { OpenAPIHono, createRoute } from "@hono/zod-openapi";
|
|
9
|
+
import { Effect } from "effect";
|
|
10
|
+
import { runEffect } from "@atlas/api/lib/effect/hono";
|
|
11
|
+
import { RequestContext } from "@atlas/api/lib/effect/services";
|
|
12
|
+
import { HTTPException } from "hono/http-exception";
|
|
13
|
+
import { validationHook } from "./validation-hook";
|
|
14
|
+
import { withRequestId, type AuthEnv } from "./middleware";
|
|
9
15
|
import { z } from "zod";
|
|
10
|
-
import { type UIMessage } from "ai";
|
|
16
|
+
import { type UIMessage, createUIMessageStream, createUIMessageStreamResponse } from "ai";
|
|
11
17
|
import { APICallError, LoadAPIKeyError, NoSuchModelError } from "ai";
|
|
18
|
+
import { matchError, isRetryableError, isChatErrorCode } from "@useatlas/types";
|
|
12
19
|
import { runAgent } from "@atlas/api/lib/agent";
|
|
13
20
|
import { validateEnvironment } from "@atlas/api/lib/startup";
|
|
14
21
|
import { GatewayModelNotFoundError } from "@ai-sdk/gateway";
|
|
@@ -20,12 +27,17 @@ import {
|
|
|
20
27
|
getClientIP,
|
|
21
28
|
} from "@atlas/api/lib/auth/middleware";
|
|
22
29
|
import { hasInternalDB } from "@atlas/api/lib/db/internal";
|
|
30
|
+
import { checkWorkspaceStatus } from "@atlas/api/lib/workspace";
|
|
31
|
+
import { checkAbuseStatus } from "@atlas/api/lib/security/abuse";
|
|
32
|
+
import { checkPlanLimits } from "@atlas/api/lib/billing/enforcement";
|
|
23
33
|
import {
|
|
24
34
|
createConversation,
|
|
25
35
|
addMessage,
|
|
26
36
|
getConversation,
|
|
27
37
|
generateTitle,
|
|
28
38
|
} from "@atlas/api/lib/conversations";
|
|
39
|
+
import { setStreamWriter, clearStreamWriter } from "@atlas/api/lib/tools/python-stream";
|
|
40
|
+
import { ErrorSchema } from "./shared-schemas";
|
|
29
41
|
|
|
30
42
|
const log = createLogger("chat");
|
|
31
43
|
|
|
@@ -46,405 +58,656 @@ export const ChatRequestSchema = z.object({
|
|
|
46
58
|
conversationId: z.string().uuid().optional(),
|
|
47
59
|
});
|
|
48
60
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const req = c.req.raw;
|
|
53
|
-
const requestId = crypto.randomUUID();
|
|
54
|
-
|
|
55
|
-
// Auth check — before context so user identity is available to all downstream logs
|
|
56
|
-
let authResult: AuthResult;
|
|
57
|
-
try {
|
|
58
|
-
authResult = await authenticateRequest(req);
|
|
59
|
-
} catch (err) {
|
|
60
|
-
log.error(
|
|
61
|
-
{
|
|
62
|
-
err: err instanceof Error ? err : new Error(String(err)),
|
|
63
|
-
requestId,
|
|
64
|
-
},
|
|
65
|
-
"Auth dispatch failed",
|
|
66
|
-
);
|
|
67
|
-
return c.json(
|
|
68
|
-
{ error: "auth_error", message: "Authentication system error" },
|
|
69
|
-
500,
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
if (!authResult.authenticated) {
|
|
73
|
-
log.warn({ requestId, status: authResult.status }, "Authentication failed");
|
|
74
|
-
return c.json(
|
|
75
|
-
{ error: "auth_error", message: authResult.error },
|
|
76
|
-
authResult.status as 401 | 403 | 500,
|
|
77
|
-
);
|
|
78
|
-
}
|
|
61
|
+
// ---------------------------------------------------------------------------
|
|
62
|
+
// Route definition
|
|
63
|
+
// ---------------------------------------------------------------------------
|
|
79
64
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
65
|
+
const chatRoute = createRoute({
|
|
66
|
+
method: "post",
|
|
67
|
+
path: "/",
|
|
68
|
+
tags: ["Chat"],
|
|
69
|
+
summary: "Chat with the agent (streaming)",
|
|
70
|
+
description:
|
|
71
|
+
"Sends a conversation to the Atlas agent and streams the response as Server-Sent Events using the Vercel AI SDK UI message stream protocol. " +
|
|
72
|
+
"Each SSE event is a JSON object with a 'type' field: 'text-delta' for incremental text, 'tool-call' for tool invocations, " +
|
|
73
|
+
"'tool-result' for tool outputs, 'step-start' for new agent steps, and 'finish' for completion. " +
|
|
74
|
+
"The response includes an `x-conversation-id` header when conversation persistence is enabled.",
|
|
75
|
+
request: {
|
|
76
|
+
body: {
|
|
77
|
+
content: { "application/json": { schema: ChatRequestSchema } },
|
|
78
|
+
required: true,
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
responses: {
|
|
82
|
+
200: {
|
|
83
|
+
description:
|
|
84
|
+
"SSE stream using the Vercel AI SDK UI message stream protocol. Each event is a JSON object with a 'type' field (text-delta, tool-call, tool-result, step-start, finish).",
|
|
85
|
+
content: {
|
|
86
|
+
"text/event-stream": { schema: z.string() },
|
|
97
87
|
},
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
88
|
+
},
|
|
89
|
+
400: {
|
|
90
|
+
description: "Bad request (malformed JSON, missing datasource, or invalid configuration)",
|
|
91
|
+
content: { "application/json": { schema: ErrorSchema } },
|
|
92
|
+
},
|
|
93
|
+
401: {
|
|
94
|
+
description: "Authentication required",
|
|
95
|
+
content: { "application/json": { schema: ErrorSchema } },
|
|
96
|
+
},
|
|
97
|
+
403: {
|
|
98
|
+
description: "Forbidden — insufficient permissions",
|
|
99
|
+
content: { "application/json": { schema: ErrorSchema } },
|
|
100
|
+
},
|
|
101
|
+
404: {
|
|
102
|
+
description: "Conversation not found (invalid conversationId)",
|
|
103
|
+
content: { "application/json": { schema: ErrorSchema } },
|
|
104
|
+
},
|
|
105
|
+
422: {
|
|
106
|
+
description: "Validation error (invalid request body)",
|
|
107
|
+
content: { "application/json": { schema: ErrorSchema } },
|
|
108
|
+
},
|
|
109
|
+
429: {
|
|
110
|
+
description: "Rate limit exceeded",
|
|
111
|
+
content: { "application/json": { schema: ErrorSchema } },
|
|
112
|
+
},
|
|
113
|
+
500: {
|
|
114
|
+
description: "Internal server error",
|
|
115
|
+
content: { "application/json": { schema: ErrorSchema } },
|
|
116
|
+
},
|
|
117
|
+
502: {
|
|
118
|
+
description: "LLM provider error",
|
|
119
|
+
content: { "application/json": { schema: ErrorSchema } },
|
|
120
|
+
},
|
|
121
|
+
503: {
|
|
122
|
+
description: "Provider unreachable, auth error, or rate limited",
|
|
123
|
+
content: { "application/json": { schema: ErrorSchema } },
|
|
124
|
+
},
|
|
125
|
+
504: {
|
|
126
|
+
description: "Request timed out",
|
|
127
|
+
content: { "application/json": { schema: ErrorSchema } },
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
});
|
|
101
131
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
132
|
+
const chat = new OpenAPIHono<AuthEnv>({ defaultHook: validationHook });
|
|
133
|
+
|
|
134
|
+
chat.use(withRequestId);
|
|
135
|
+
|
|
136
|
+
chat.openapi(chatRoute, async (c) => {
|
|
137
|
+
return runEffect(c, Effect.gen(function* () {
|
|
138
|
+
const req = c.req.raw;
|
|
139
|
+
const { requestId } = yield* RequestContext;
|
|
140
|
+
|
|
141
|
+
// Auth check — before context so user identity is available to all downstream logs
|
|
142
|
+
const authAttempt = yield* Effect.tryPromise({
|
|
143
|
+
try: () => authenticateRequest(req),
|
|
144
|
+
catch: (err) => err instanceof Error ? err : new Error(String(err)),
|
|
145
|
+
}).pipe(Effect.either);
|
|
146
|
+
if (authAttempt._tag === "Left") {
|
|
147
|
+
log.error(
|
|
148
|
+
{
|
|
149
|
+
err: authAttempt.left,
|
|
150
|
+
requestId,
|
|
151
|
+
},
|
|
152
|
+
"Auth dispatch failed",
|
|
153
|
+
);
|
|
154
|
+
return c.json(
|
|
155
|
+
{ error: "auth_error", message: "Authentication system error", retryable: false, requestId },
|
|
156
|
+
500,
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
const authResult: AuthResult = authAttempt.right;
|
|
160
|
+
if (!authResult.authenticated) {
|
|
161
|
+
log.warn({ requestId, status: authResult.status }, "Authentication failed");
|
|
162
|
+
const errorBody: Record<string, unknown> = { error: "auth_error", message: authResult.error, retryable: false, requestId };
|
|
163
|
+
if (authResult.ssoRedirectUrl) {
|
|
164
|
+
errorBody.ssoRedirectUrl = authResult.ssoRedirectUrl;
|
|
118
165
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
166
|
+
return c.json(
|
|
167
|
+
errorBody,
|
|
168
|
+
authResult.status as 401 | 403 | 500,
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Rate limit check — after auth so we have user identity
|
|
173
|
+
const ip = getClientIP(req);
|
|
174
|
+
const rateLimitKey = authResult.user?.id ?? (ip ? `ip:${ip}` : "anon");
|
|
175
|
+
const rateCheck = checkRateLimit(rateLimitKey);
|
|
176
|
+
if (!rateCheck.allowed) {
|
|
177
|
+
log.warn(
|
|
178
|
+
{ requestId, rateLimitKey, retryAfterMs: rateCheck.retryAfterMs },
|
|
179
|
+
"Rate limit exceeded",
|
|
180
|
+
);
|
|
181
|
+
const retryAfterSeconds = Math.ceil(
|
|
182
|
+
(rateCheck.retryAfterMs ?? 60000) / 1000,
|
|
183
|
+
);
|
|
184
|
+
return c.json(
|
|
185
|
+
{
|
|
186
|
+
error: "rate_limited",
|
|
187
|
+
message: "Too many requests. Please wait before trying again.",
|
|
188
|
+
retryAfterSeconds,
|
|
189
|
+
retryable: true,
|
|
190
|
+
requestId,
|
|
191
|
+
},
|
|
192
|
+
{ status: 429, headers: { "Retry-After": String(retryAfterSeconds) } },
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// IP allowlist check — enterprise feature, after auth so we have org context
|
|
197
|
+
let checkIPAllowlist: ((orgId: string, clientIP: string | null) => Promise<{ allowed: boolean }>) | undefined;
|
|
198
|
+
const eeModule = yield* Effect.tryPromise({
|
|
199
|
+
try: () => import("@atlas/ee/auth/ip-allowlist"),
|
|
200
|
+
catch: (err) => err instanceof Error ? err : new Error(String(err)),
|
|
201
|
+
}).pipe(Effect.option);
|
|
202
|
+
if (eeModule._tag === "Some") {
|
|
203
|
+
checkIPAllowlist = eeModule.value.checkIPAllowlist;
|
|
204
|
+
}
|
|
205
|
+
// ee module not installed — IP allowlist feature unavailable, skip
|
|
206
|
+
if (checkIPAllowlist) {
|
|
207
|
+
const orgId = authResult.user?.activeOrganizationId;
|
|
208
|
+
if (orgId) {
|
|
209
|
+
const ipCheck = yield* Effect.promise(() => checkIPAllowlist!(orgId, ip));
|
|
210
|
+
if (!ipCheck.allowed) {
|
|
211
|
+
log.warn({ requestId, orgId, ip }, "IP not in workspace allowlist");
|
|
212
|
+
return c.json(
|
|
213
|
+
{ error: "ip_not_allowed", message: "Your IP address is not in the workspace's allowlist.", retryable: false, requestId },
|
|
214
|
+
403,
|
|
215
|
+
);
|
|
216
|
+
}
|
|
131
217
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// Workspace status check — block suspended/deleted workspaces
|
|
221
|
+
const wsCheck = yield* Effect.promise(() => checkWorkspaceStatus(authResult.user?.activeOrganizationId));
|
|
222
|
+
if (!wsCheck.allowed) {
|
|
223
|
+
return c.json(
|
|
224
|
+
{ error: wsCheck.errorCode, message: wsCheck.errorMessage, retryable: wsCheck.errorCode && isChatErrorCode(wsCheck.errorCode) ? isRetryableError(wsCheck.errorCode) : false, requestId },
|
|
225
|
+
wsCheck.httpStatus ?? 403,
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// Abuse check — block suspended workspaces, reject throttled ones with 429
|
|
230
|
+
const abuseOrgId = authResult.user?.activeOrganizationId;
|
|
231
|
+
if (abuseOrgId) {
|
|
232
|
+
const abuse = checkAbuseStatus(abuseOrgId);
|
|
233
|
+
if (abuse.level === "suspended") {
|
|
234
|
+
log.warn({ requestId, orgId: abuseOrgId }, "Workspace suspended due to abuse");
|
|
142
235
|
return c.json(
|
|
143
|
-
{
|
|
144
|
-
|
|
145
|
-
message: "Invalid JSON body.",
|
|
146
|
-
},
|
|
147
|
-
400,
|
|
236
|
+
{ error: "workspace_suspended", message: "Workspace suspended due to unusual activity. Contact your administrator.", retryable: false, requestId },
|
|
237
|
+
403,
|
|
148
238
|
);
|
|
149
239
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
240
|
+
if (abuse.level === "throttled" && abuse.throttleDelayMs) {
|
|
241
|
+
const retryAfterSeconds = Math.ceil(abuse.throttleDelayMs / 1000);
|
|
242
|
+
log.warn({ requestId, orgId: abuseOrgId, delayMs: abuse.throttleDelayMs }, "Workspace throttled due to abuse");
|
|
153
243
|
return c.json(
|
|
154
244
|
{
|
|
155
|
-
error: "
|
|
156
|
-
message: "
|
|
157
|
-
|
|
245
|
+
error: "workspace_throttled",
|
|
246
|
+
message: "Workspace is temporarily throttled due to high usage. Please retry shortly.",
|
|
247
|
+
retryable: true,
|
|
248
|
+
retryAfterSeconds,
|
|
249
|
+
requestId,
|
|
158
250
|
},
|
|
159
|
-
|
|
251
|
+
{ status: 429, headers: { "Retry-After": String(retryAfterSeconds) } },
|
|
160
252
|
);
|
|
161
253
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
.join(" ") ?? "",
|
|
193
|
-
)
|
|
194
|
-
: "New conversation";
|
|
195
|
-
const created = await createConversation({
|
|
196
|
-
userId: authResult.user?.id,
|
|
197
|
-
title,
|
|
198
|
-
surface: "web",
|
|
199
|
-
});
|
|
200
|
-
if (created) conversationId = created.id;
|
|
201
|
-
} catch (err) {
|
|
202
|
-
log.warn({ err: err instanceof Error ? err.message : String(err) }, "Failed to create conversation");
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
try {
|
|
208
|
-
// Build a dynamic registry when actions are enabled
|
|
209
|
-
let toolRegistry;
|
|
210
|
-
const includeActions = process.env.ATLAS_ACTIONS_ENABLED === "true";
|
|
211
|
-
if (includeActions) {
|
|
212
|
-
try {
|
|
213
|
-
const { buildRegistry } = await import("@atlas/api/lib/tools/registry");
|
|
214
|
-
toolRegistry = await buildRegistry({ includeActions });
|
|
215
|
-
} catch (err) {
|
|
216
|
-
log.error(
|
|
217
|
-
{ err: err instanceof Error ? err : new Error(String(err)) },
|
|
218
|
-
"Failed to build tool registry — falling back to default tools",
|
|
219
|
-
);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
// Merge plugin tools (if any) on top of the current registry
|
|
224
|
-
const { getPluginTools } = await import("@atlas/api/lib/plugins/tools");
|
|
225
|
-
const pluginTools = getPluginTools();
|
|
226
|
-
if (pluginTools) {
|
|
227
|
-
const { ToolRegistry, defaultRegistry } = await import("@atlas/api/lib/tools/registry");
|
|
228
|
-
const base = toolRegistry ?? defaultRegistry;
|
|
229
|
-
toolRegistry = ToolRegistry.merge(base, pluginTools);
|
|
230
|
-
toolRegistry.freeze();
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
const result = await runAgent({ messages, ...(toolRegistry && { tools: toolRegistry }) });
|
|
234
|
-
const streamResponse = result.toUIMessageStreamResponse();
|
|
235
|
-
|
|
236
|
-
// Set conversation ID header so the client can track continuity
|
|
237
|
-
if (conversationId) {
|
|
238
|
-
streamResponse.headers.set("x-conversation-id", conversationId);
|
|
239
|
-
|
|
240
|
-
// Fire-and-forget: persist assistant response after stream completes
|
|
241
|
-
const cid = conversationId;
|
|
242
|
-
void Promise.resolve(result.text)
|
|
243
|
-
.then((text) => {
|
|
244
|
-
addMessage({ conversationId: cid, role: "assistant", content: [{ type: "text", text }] });
|
|
245
|
-
})
|
|
246
|
-
.catch((err: unknown) => {
|
|
247
|
-
log.warn({ err: err instanceof Error ? err.message : String(err) }, "Failed to persist assistant message");
|
|
248
|
-
});
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
return streamResponse;
|
|
252
|
-
} catch (err) {
|
|
253
|
-
const message = err instanceof Error ? err.message : "";
|
|
254
|
-
|
|
255
|
-
// --- Structured AI SDK error types (checked first) ---
|
|
256
|
-
|
|
257
|
-
if (GatewayModelNotFoundError.isInstance(err)) {
|
|
258
|
-
log.error(
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// Plan limit check — block or warn when usage approaches/exceeds plan limits
|
|
257
|
+
const planCheck = yield* Effect.promise(() => checkPlanLimits(authResult.user?.activeOrganizationId));
|
|
258
|
+
if (!planCheck.allowed) {
|
|
259
|
+
return c.json(
|
|
260
|
+
{
|
|
261
|
+
error: planCheck.errorCode,
|
|
262
|
+
message: planCheck.errorMessage,
|
|
263
|
+
retryable: isChatErrorCode(planCheck.errorCode) ? isRetryableError(planCheck.errorCode) : false,
|
|
264
|
+
requestId,
|
|
265
|
+
...(planCheck.errorCode === "plan_limit_exceeded" && { usage: planCheck.usage }),
|
|
266
|
+
},
|
|
267
|
+
planCheck.httpStatus,
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// Capture plan warning for response headers (set after stream is created)
|
|
272
|
+
const planWarning = planCheck.allowed ? planCheck.warning : undefined;
|
|
273
|
+
|
|
274
|
+
// Bind user to AsyncLocalStorage so downstream code (logQueryAudit, etc.)
|
|
275
|
+
// has access to user identity. The middleware already set up requestId context;
|
|
276
|
+
// this nested call adds the user after inline auth completes.
|
|
277
|
+
return withRequestContext(
|
|
278
|
+
{ requestId, user: authResult.user },
|
|
279
|
+
async () => {
|
|
280
|
+
// Startup diagnostics — fast-fail with actionable errors
|
|
281
|
+
const diagnostics = await validateEnvironment();
|
|
282
|
+
if (diagnostics.length > 0) {
|
|
283
|
+
return c.json(
|
|
259
284
|
{
|
|
260
|
-
|
|
261
|
-
|
|
285
|
+
error: "configuration_error",
|
|
286
|
+
message: diagnostics.map((d) => d.message).join("\n\n"),
|
|
287
|
+
diagnostics,
|
|
288
|
+
retryable: false,
|
|
289
|
+
requestId,
|
|
262
290
|
},
|
|
263
|
-
|
|
291
|
+
400,
|
|
264
292
|
);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// Datasource guard — diagnostics pass (it's a warning) but chat requires a datasource
|
|
296
|
+
const { resolveDatasourceUrl } = await import("@atlas/api/lib/db/connection");
|
|
297
|
+
if (!resolveDatasourceUrl()) {
|
|
265
298
|
return c.json(
|
|
266
299
|
{
|
|
267
|
-
error: "
|
|
300
|
+
error: "no_datasource",
|
|
268
301
|
message:
|
|
269
|
-
"
|
|
302
|
+
"No analytics datasource configured. Set ATLAS_DATASOURCE_URL to query your data.",
|
|
303
|
+
retryable: false,
|
|
304
|
+
requestId,
|
|
270
305
|
},
|
|
271
306
|
400,
|
|
272
307
|
);
|
|
273
308
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
309
|
+
|
|
310
|
+
// Parse request body separately so malformed JSON gets a 400, not 500
|
|
311
|
+
let body: unknown;
|
|
312
|
+
try {
|
|
313
|
+
body = await c.req.json();
|
|
314
|
+
} catch (err) {
|
|
315
|
+
log.warn(
|
|
316
|
+
{ err: err instanceof Error ? err : new Error(String(err)) },
|
|
317
|
+
"Failed to parse request body",
|
|
282
318
|
);
|
|
283
319
|
return c.json(
|
|
284
320
|
{
|
|
285
|
-
error: "
|
|
286
|
-
message:
|
|
287
|
-
|
|
321
|
+
error: "invalid_request",
|
|
322
|
+
message: "Invalid JSON body.",
|
|
323
|
+
retryable: false,
|
|
324
|
+
requestId,
|
|
288
325
|
},
|
|
289
326
|
400,
|
|
290
327
|
);
|
|
291
328
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
{
|
|
296
|
-
err: err instanceof Error ? err : new Error(String(err)),
|
|
297
|
-
category: "provider_auth_error",
|
|
298
|
-
},
|
|
299
|
-
"API key not loaded",
|
|
300
|
-
);
|
|
329
|
+
|
|
330
|
+
const parsed = ChatRequestSchema.safeParse(body);
|
|
331
|
+
if (!parsed.success) {
|
|
301
332
|
return c.json(
|
|
302
333
|
{
|
|
303
|
-
error: "
|
|
304
|
-
message:
|
|
305
|
-
|
|
334
|
+
error: "validation_error",
|
|
335
|
+
message: "Invalid request body.",
|
|
336
|
+
details: parsed.error.issues,
|
|
337
|
+
retryable: false,
|
|
338
|
+
requestId,
|
|
306
339
|
},
|
|
307
|
-
|
|
340
|
+
422,
|
|
308
341
|
);
|
|
309
342
|
}
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
343
|
+
|
|
344
|
+
const messages = parsed.data.messages as UIMessage[];
|
|
345
|
+
let conversationId = parsed.data.conversationId;
|
|
346
|
+
|
|
347
|
+
// Conversation persistence — Ownership verification blocks here (can 404); message writes are fire-and-forget via internalExecute.
|
|
348
|
+
if (hasInternalDB()) {
|
|
349
|
+
if (conversationId) {
|
|
350
|
+
// Ownership verification — NOT best-effort, this is a security check
|
|
351
|
+
const existing = await getConversation(conversationId, authResult.user?.id);
|
|
352
|
+
if (!existing.ok) {
|
|
353
|
+
return c.json({ error: "not_found", message: "Conversation not found.", retryable: false, requestId }, 404);
|
|
354
|
+
}
|
|
355
|
+
// Persist the latest user message
|
|
356
|
+
try {
|
|
357
|
+
const lastUserMsg = [...messages].reverse().find((m) => m.role === "user");
|
|
358
|
+
if (lastUserMsg) {
|
|
359
|
+
addMessage({ conversationId, role: "user", content: lastUserMsg.parts });
|
|
360
|
+
}
|
|
361
|
+
} catch (err) {
|
|
362
|
+
log.warn({ err: err instanceof Error ? err.message : String(err) }, "Failed to persist user message");
|
|
363
|
+
}
|
|
364
|
+
} else {
|
|
365
|
+
try {
|
|
366
|
+
// Create new conversation — best-effort
|
|
367
|
+
const firstUserMsg = messages.find((m) => m.role === "user");
|
|
368
|
+
const title = firstUserMsg
|
|
369
|
+
? generateTitle(
|
|
370
|
+
firstUserMsg.parts
|
|
371
|
+
?.filter((p): p is { type: "text"; text: string } => p.type === "text")
|
|
372
|
+
.map((p) => p.text)
|
|
373
|
+
.join(" ") ?? "",
|
|
374
|
+
)
|
|
375
|
+
: "New conversation";
|
|
376
|
+
const created = await createConversation({
|
|
377
|
+
userId: authResult.user?.id,
|
|
378
|
+
title,
|
|
379
|
+
surface: "web",
|
|
380
|
+
orgId: authResult.user?.activeOrganizationId,
|
|
381
|
+
});
|
|
382
|
+
if (created) {
|
|
383
|
+
conversationId = created.id;
|
|
384
|
+
// Persist the user message that triggered conversation creation
|
|
385
|
+
if (firstUserMsg) {
|
|
386
|
+
addMessage({ conversationId, role: "user", content: firstUserMsg.parts });
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
} catch (err) {
|
|
390
|
+
log.warn({ err: err instanceof Error ? err.message : String(err) }, "Failed to create conversation");
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
try {
|
|
396
|
+
// Build a dynamic registry when actions are enabled
|
|
397
|
+
let toolRegistry: import("@atlas/api/lib/tools/registry").ToolRegistry | undefined;
|
|
398
|
+
const warnings: string[] = [];
|
|
399
|
+
const includeActions = process.env.ATLAS_ACTIONS_ENABLED === "true";
|
|
400
|
+
if (includeActions) {
|
|
401
|
+
try {
|
|
402
|
+
const { buildRegistry } = await import("@atlas/api/lib/tools/registry");
|
|
403
|
+
const result = await buildRegistry({ includeActions });
|
|
404
|
+
toolRegistry = result.registry;
|
|
405
|
+
warnings.push(...result.warnings);
|
|
406
|
+
} catch (err) {
|
|
407
|
+
const errObj = err instanceof Error ? err : new Error(String(err));
|
|
408
|
+
log.error(
|
|
409
|
+
{ err: errObj },
|
|
410
|
+
"Failed to build tool registry — falling back to default tools",
|
|
411
|
+
);
|
|
412
|
+
warnings.push(
|
|
413
|
+
"Actions were requested but the tool registry failed to build. Action tools are unavailable for this session. Inform the user that actions are currently unavailable and suggest they check server logs or retry later.",
|
|
414
|
+
);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
// Merge plugin tools (if any) on top of the current registry
|
|
419
|
+
const prePluginRegistry = toolRegistry;
|
|
420
|
+
try {
|
|
421
|
+
const { getPluginTools } = await import("@atlas/api/lib/plugins/tools");
|
|
422
|
+
const pluginTools = getPluginTools();
|
|
423
|
+
if (pluginTools) {
|
|
424
|
+
const { ToolRegistry, defaultRegistry } = await import("@atlas/api/lib/tools/registry");
|
|
425
|
+
const base = toolRegistry ?? defaultRegistry;
|
|
426
|
+
toolRegistry = ToolRegistry.merge(base, pluginTools);
|
|
427
|
+
toolRegistry.freeze();
|
|
428
|
+
}
|
|
429
|
+
} catch (err) {
|
|
430
|
+
toolRegistry = prePluginRegistry;
|
|
431
|
+
const errObj = err instanceof Error ? err : new Error(String(err));
|
|
316
432
|
log.error(
|
|
317
|
-
{
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
}
|
|
322
|
-
|
|
433
|
+
{ err: errObj },
|
|
434
|
+
"Failed to merge plugin tools — continuing without plugin tools",
|
|
435
|
+
);
|
|
436
|
+
warnings.push(
|
|
437
|
+
`Plugin tools failed to load: ${errObj.message}. Chat will continue without plugin tools. Inform the user that plugin-provided tools are unavailable for this session.`,
|
|
438
|
+
);
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
// Call runAgent first so errors (provider auth, config, etc.) are
|
|
442
|
+
// caught by the outer try-catch and returned as proper JSON errors.
|
|
443
|
+
// The agent stream is then merged into a UIMessageStream that supports
|
|
444
|
+
// writing custom data parts (Python progress events).
|
|
445
|
+
const agentResult = await runAgent({
|
|
446
|
+
messages,
|
|
447
|
+
...(toolRegistry && { tools: toolRegistry }),
|
|
448
|
+
conversationId,
|
|
449
|
+
...(warnings.length > 0 && { warnings }),
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
// Register stream writer so Python tool can send progress events.
|
|
453
|
+
// The writer is set before merge() triggers tool execution reads.
|
|
454
|
+
const stream = createUIMessageStream({
|
|
455
|
+
execute: ({ writer }) => {
|
|
456
|
+
// Surface plan warning as a data annotation so clients can display it
|
|
457
|
+
if (planWarning) {
|
|
458
|
+
writer.write({ type: "data-plan-warning", data: planWarning });
|
|
459
|
+
}
|
|
460
|
+
setStreamWriter(requestId, writer);
|
|
461
|
+
writer.merge(agentResult.toUIMessageStream());
|
|
462
|
+
},
|
|
463
|
+
onFinish: () => {
|
|
464
|
+
clearStreamWriter(requestId);
|
|
465
|
+
},
|
|
466
|
+
onError: (error) => {
|
|
467
|
+
clearStreamWriter(requestId);
|
|
468
|
+
log.error(
|
|
469
|
+
{ err: error instanceof Error ? error : new Error(String(error)), requestId },
|
|
470
|
+
"Stream error",
|
|
471
|
+
);
|
|
472
|
+
return `An error occurred while generating a response (ref: ${requestId.slice(0, 8)}). Try sending your message again.`;
|
|
473
|
+
},
|
|
474
|
+
});
|
|
475
|
+
|
|
476
|
+
const streamResponse = createUIMessageStreamResponse({
|
|
477
|
+
stream,
|
|
478
|
+
headers: {
|
|
479
|
+
"X-Accel-Buffering": "no",
|
|
480
|
+
"Cache-Control": "no-cache, no-transform",
|
|
481
|
+
...(conversationId ? { "x-conversation-id": conversationId } : {}),
|
|
482
|
+
...(planWarning ? { "x-plan-limit-warning": JSON.stringify(planWarning) } : {}),
|
|
483
|
+
},
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
// Fire-and-forget: trigger onboarding "first query" milestone.
|
|
487
|
+
// AtlasUser.label is the user's email in managed auth mode.
|
|
488
|
+
if (authResult.user?.id && authResult.user.label?.includes("@")) {
|
|
489
|
+
const uid = authResult.user.id;
|
|
490
|
+
const uemail = authResult.user.label;
|
|
491
|
+
const uorg = authResult.user.activeOrganizationId ?? "default";
|
|
492
|
+
void import("@atlas/api/lib/email/hooks")
|
|
493
|
+
.then(({ onFirstQueryExecuted }) => {
|
|
494
|
+
onFirstQueryExecuted({ userId: uid, email: uemail, orgId: uorg });
|
|
495
|
+
})
|
|
496
|
+
.catch((err: unknown) => {
|
|
497
|
+
log.debug({ err: err instanceof Error ? err.message : String(err) }, "Onboarding email hook not available — non-blocking");
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
// Fire-and-forget: persist assistant response after stream completes.
|
|
502
|
+
if (conversationId) {
|
|
503
|
+
const cid = conversationId;
|
|
504
|
+
void Promise.resolve(agentResult.text)
|
|
505
|
+
.then((text) => {
|
|
506
|
+
try {
|
|
507
|
+
addMessage({ conversationId: cid, role: "assistant", content: [{ type: "text", text }] });
|
|
508
|
+
} catch (persistErr) {
|
|
509
|
+
log.warn({ err: persistErr instanceof Error ? persistErr.message : String(persistErr), conversationId: cid }, "Failed to persist assistant message");
|
|
510
|
+
}
|
|
511
|
+
})
|
|
512
|
+
.catch((err: unknown) => {
|
|
513
|
+
log.error({ err: err instanceof Error ? err.message : String(err), conversationId: cid }, "Agent stream failed — assistant response not available");
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
// The streaming response is a raw Response from createUIMessageStreamResponse.
|
|
518
|
+
// OpenAPIHono expects typed c.json() returns, but SSE streams bypass that.
|
|
519
|
+
// Throw as HTTPException so the global onError handler returns the raw response
|
|
520
|
+
// via getResponse(), bypassing the OpenAPI typed return requirement.
|
|
521
|
+
throw new HTTPException(200, { res: streamResponse });
|
|
522
|
+
} catch (err) {
|
|
523
|
+
// Re-throw HTTPException (stream response) — handled by global onError
|
|
524
|
+
if (err instanceof HTTPException) throw err;
|
|
525
|
+
|
|
526
|
+
const errObj = err instanceof Error ? err : new Error(String(err));
|
|
527
|
+
const message = errObj.message;
|
|
528
|
+
|
|
529
|
+
// --- Structured AI SDK error types (checked first) ---
|
|
530
|
+
|
|
531
|
+
if (GatewayModelNotFoundError.isInstance(err)) {
|
|
532
|
+
log.error(
|
|
533
|
+
{ err: errObj, category: "provider_model_not_found" },
|
|
534
|
+
"Gateway model not found",
|
|
323
535
|
);
|
|
324
536
|
return c.json(
|
|
325
537
|
{
|
|
326
|
-
error: "
|
|
538
|
+
error: "provider_model_not_found",
|
|
327
539
|
message:
|
|
328
|
-
"
|
|
540
|
+
"Model not found on the AI Gateway. Check that your ATLAS_MODEL uses the correct provider/model format (e.g., anthropic/claude-sonnet-4.6).",
|
|
541
|
+
retryable: isRetryableError("provider_model_not_found"),
|
|
542
|
+
requestId,
|
|
329
543
|
},
|
|
330
|
-
|
|
544
|
+
400,
|
|
331
545
|
);
|
|
332
546
|
}
|
|
333
|
-
|
|
334
|
-
if (
|
|
547
|
+
|
|
548
|
+
if (NoSuchModelError.isInstance(err)) {
|
|
335
549
|
log.error(
|
|
550
|
+
{ err: errObj, category: "provider_model_not_found" },
|
|
551
|
+
"Model not found",
|
|
552
|
+
);
|
|
553
|
+
return c.json(
|
|
336
554
|
{
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
555
|
+
error: "provider_model_not_found",
|
|
556
|
+
message:
|
|
557
|
+
"The configured model was not found. Check ATLAS_MODEL and ATLAS_PROVIDER settings.",
|
|
558
|
+
retryable: isRetryableError("provider_model_not_found"),
|
|
559
|
+
requestId,
|
|
340
560
|
},
|
|
341
|
-
|
|
561
|
+
400,
|
|
562
|
+
);
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
if (LoadAPIKeyError.isInstance(err)) {
|
|
566
|
+
log.error(
|
|
567
|
+
{ err: errObj, category: "provider_auth_error" },
|
|
568
|
+
"API key not loaded",
|
|
342
569
|
);
|
|
343
570
|
return c.json(
|
|
344
571
|
{
|
|
345
|
-
error: "
|
|
572
|
+
error: "provider_auth_error",
|
|
346
573
|
message:
|
|
347
|
-
"LLM provider
|
|
574
|
+
"LLM provider API key could not be loaded. Check that the required API key environment variable is set.",
|
|
575
|
+
retryable: isRetryableError("provider_auth_error"),
|
|
576
|
+
requestId,
|
|
348
577
|
},
|
|
349
578
|
503,
|
|
350
579
|
);
|
|
351
580
|
}
|
|
352
|
-
|
|
353
|
-
|
|
581
|
+
|
|
582
|
+
// APICallError carries the HTTP status code from the provider response
|
|
583
|
+
if (APICallError.isInstance(err)) {
|
|
584
|
+
const status = err.statusCode;
|
|
585
|
+
|
|
586
|
+
if (status === 401 || status === 403) {
|
|
587
|
+
log.error(
|
|
588
|
+
{ err: errObj, category: "provider_auth_error", statusCode: status },
|
|
589
|
+
"Provider auth error",
|
|
590
|
+
);
|
|
591
|
+
return c.json(
|
|
592
|
+
{
|
|
593
|
+
error: "provider_auth_error",
|
|
594
|
+
message:
|
|
595
|
+
"LLM provider authentication failed. Check that your API key is valid and has not expired.",
|
|
596
|
+
retryable: isRetryableError("provider_auth_error"),
|
|
597
|
+
requestId,
|
|
598
|
+
},
|
|
599
|
+
503,
|
|
600
|
+
);
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
if (status === 429) {
|
|
604
|
+
log.error(
|
|
605
|
+
{ err: errObj, category: "provider_rate_limit", statusCode: status },
|
|
606
|
+
"Provider rate limit",
|
|
607
|
+
);
|
|
608
|
+
return c.json(
|
|
609
|
+
{
|
|
610
|
+
error: "provider_rate_limit",
|
|
611
|
+
message:
|
|
612
|
+
"LLM provider rate limit reached. Wait a moment and try again.",
|
|
613
|
+
retryable: isRetryableError("provider_rate_limit"),
|
|
614
|
+
requestId,
|
|
615
|
+
},
|
|
616
|
+
503,
|
|
617
|
+
);
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
if (status === 408 || /timeout/i.test(message)) {
|
|
621
|
+
log.error(
|
|
622
|
+
{ err: errObj, category: "provider_timeout", statusCode: status },
|
|
623
|
+
"Request timed out",
|
|
624
|
+
);
|
|
625
|
+
return c.json(
|
|
626
|
+
{
|
|
627
|
+
error: "provider_timeout",
|
|
628
|
+
message:
|
|
629
|
+
"The request timed out. The LLM provider took too long to respond. " +
|
|
630
|
+
"Try again, or if using a local model, ensure it has sufficient resources.",
|
|
631
|
+
retryable: isRetryableError("provider_timeout"),
|
|
632
|
+
requestId,
|
|
633
|
+
},
|
|
634
|
+
504,
|
|
635
|
+
);
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
// Catch-all for any other APICallError status codes (5xx, etc.)
|
|
354
639
|
log.error(
|
|
355
|
-
{
|
|
356
|
-
|
|
357
|
-
category: "provider_timeout",
|
|
358
|
-
statusCode: status,
|
|
359
|
-
},
|
|
360
|
-
"Request timed out",
|
|
640
|
+
{ err: errObj, category: "provider_error", statusCode: status },
|
|
641
|
+
"Provider error",
|
|
361
642
|
);
|
|
362
643
|
return c.json(
|
|
363
644
|
{
|
|
364
|
-
error: "
|
|
365
|
-
message:
|
|
366
|
-
|
|
367
|
-
|
|
645
|
+
error: "provider_error",
|
|
646
|
+
message: `The LLM provider returned an error (HTTP ${status}). This is usually a temporary issue. Try again in a moment.`,
|
|
647
|
+
retryable: isRetryableError("provider_error"),
|
|
648
|
+
requestId,
|
|
368
649
|
},
|
|
369
|
-
|
|
650
|
+
502,
|
|
370
651
|
);
|
|
371
652
|
}
|
|
372
|
-
|
|
373
|
-
//
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
"
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
err:
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
{
|
|
403
|
-
|
|
404
|
-
message:
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
653
|
+
|
|
654
|
+
// --- Pattern-matched errors (non-APICallError exceptions) ---
|
|
655
|
+
// In the chat route, errors from runAgent are typically provider-related,
|
|
656
|
+
// so we override matchError's generic messages with provider-appropriate ones.
|
|
657
|
+
|
|
658
|
+
const matched = matchError(err);
|
|
659
|
+
if (matched) {
|
|
660
|
+
const isConnectionError = /ECONNREFUSED|ENOTFOUND|fetch failed/i.test(message);
|
|
661
|
+
const code = (matched.code === "internal_error" && isConnectionError)
|
|
662
|
+
? "provider_unreachable" as const
|
|
663
|
+
: matched.code === "provider_unreachable" ? "provider_unreachable" as const
|
|
664
|
+
: matched.code;
|
|
665
|
+
const httpStatus = code === "rate_limited" ? 429
|
|
666
|
+
: code === "provider_unreachable" ? 503
|
|
667
|
+
: code === "provider_timeout" ? 504
|
|
668
|
+
: 500;
|
|
669
|
+
// Use provider-appropriate messages instead of database-oriented matchError defaults
|
|
670
|
+
const userMessage = code === "provider_unreachable"
|
|
671
|
+
? "Could not reach the LLM provider. Check your network connection and provider status."
|
|
672
|
+
: code === "provider_timeout"
|
|
673
|
+
? "The request timed out. The LLM provider took too long to respond. Try again, or if using a local model, ensure it has sufficient resources."
|
|
674
|
+
: matched.message;
|
|
675
|
+
if (code === "rate_limited") {
|
|
676
|
+
// Pool exhaustion is transient — warn, don't error
|
|
677
|
+
log.warn({ err: errObj, category: code }, "Matched error: %s", code);
|
|
678
|
+
return c.json(
|
|
679
|
+
{ error: code, message: userMessage, retryable: true, retryAfterSeconds: 5, requestId },
|
|
680
|
+
{ status: 429, headers: { "Retry-After": "5" } },
|
|
681
|
+
);
|
|
682
|
+
}
|
|
683
|
+
log.error({ err: errObj, category: code }, "Matched error: %s", code);
|
|
684
|
+
return c.json(
|
|
685
|
+
{ error: code, message: userMessage, retryable: isRetryableError(code), requestId },
|
|
686
|
+
httpStatus as 429 | 500 | 503 | 504,
|
|
687
|
+
);
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
// Fallback — safe 500 with requestId for log correlation.
|
|
691
|
+
// Full error details (stack trace, original message) are serialized
|
|
692
|
+
// server-side via pino's err serializer; only a generic message +
|
|
693
|
+
// request ID reach the client.
|
|
413
694
|
log.error(
|
|
414
|
-
{
|
|
415
|
-
|
|
416
|
-
category: "provider_unreachable",
|
|
417
|
-
},
|
|
418
|
-
"Provider unreachable",
|
|
695
|
+
{ err: errObj, category: "internal_error" },
|
|
696
|
+
"Unclassified error",
|
|
419
697
|
);
|
|
420
698
|
return c.json(
|
|
421
699
|
{
|
|
422
|
-
error: "
|
|
423
|
-
message:
|
|
424
|
-
|
|
700
|
+
error: "internal_error",
|
|
701
|
+
message: `An unexpected error occurred. Quote ref ${requestId.slice(0, 8)} when reporting this issue.`,
|
|
702
|
+
retryable: isRetryableError("internal_error"),
|
|
703
|
+
requestId,
|
|
425
704
|
},
|
|
426
|
-
|
|
705
|
+
500,
|
|
427
706
|
);
|
|
428
707
|
}
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
{
|
|
433
|
-
err: err instanceof Error ? err : new Error(String(err)),
|
|
434
|
-
category: "internal_error",
|
|
435
|
-
},
|
|
436
|
-
"Unexpected error",
|
|
437
|
-
);
|
|
438
|
-
return c.json(
|
|
439
|
-
{
|
|
440
|
-
error: "internal_error",
|
|
441
|
-
message: `An unexpected error occurred (ref: ${requestId.slice(0, 8)}). If this persists, check the server logs.`,
|
|
442
|
-
},
|
|
443
|
-
500,
|
|
444
|
-
);
|
|
445
|
-
}
|
|
446
|
-
},
|
|
447
|
-
);
|
|
708
|
+
},
|
|
709
|
+
);
|
|
710
|
+
}), { label: "chat" });
|
|
448
711
|
});
|
|
449
712
|
|
|
450
713
|
export { chat };
|