@langwatch/server 3.1.0-beta.4 → 3.1.0-beta.6
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/langwatch/ee/admin/ImpersonationBanner.tsx +61 -0
- package/langwatch/ee/admin/ImpersonationSwitchBackMenuItem.tsx +30 -0
- package/langwatch/ee/admin/__tests__/ImpersonationBanner.integration.test.tsx +82 -0
- package/langwatch/ee/admin/__tests__/impersonation.service.unit.test.ts +231 -0
- package/langwatch/ee/admin/backoffice/BackofficeTable.tsx +200 -0
- package/langwatch/ee/admin/backoffice/__tests__/adminClient.unit.test.ts +147 -0
- package/langwatch/ee/admin/backoffice/__tests__/dateInputToISO.unit.test.ts +42 -0
- package/langwatch/ee/admin/backoffice/__tests__/userVisibility.unit.test.ts +174 -0
- package/langwatch/ee/admin/backoffice/adminClient.ts +114 -0
- package/langwatch/ee/admin/backoffice/resources/OrganizationFeaturesView.tsx +373 -0
- package/langwatch/ee/admin/backoffice/resources/OrganizationsView.tsx +677 -0
- package/langwatch/ee/admin/backoffice/resources/ProjectsView.tsx +647 -0
- package/langwatch/ee/admin/backoffice/resources/SubscriptionsView.tsx +628 -0
- package/langwatch/ee/admin/backoffice/resources/UsersView.tsx +556 -0
- package/langwatch/ee/admin/backoffice/useAdminResource.ts +104 -0
- package/langwatch/ee/admin/backoffice/userVisibility.ts +105 -0
- package/langwatch/ee/admin/impersonation.service.ts +170 -0
- package/langwatch/ee/admin/isAdmin.ts +9 -0
- package/langwatch/ee/admin/routes/admin.ts +531 -0
- package/langwatch/ee/admin/safeSelects.ts +64 -0
- package/langwatch/ee/billing/__tests__/customerService.unit.test.ts +183 -0
- package/langwatch/ee/billing/__tests__/growthSeatEvent.unit.test.ts +213 -0
- package/langwatch/ee/billing/__tests__/licensePurchaseHandler.unit.test.ts +250 -0
- package/langwatch/ee/billing/__tests__/notification.service.unit.test.ts +768 -0
- package/langwatch/ee/billing/__tests__/planLimits.unit.test.ts +19 -0
- package/langwatch/ee/billing/__tests__/planProvider.unit.test.ts +440 -0
- package/langwatch/ee/billing/__tests__/planTypes.unit.test.ts +32 -0
- package/langwatch/ee/billing/__tests__/pricing.unit.test.ts +54 -0
- package/langwatch/ee/billing/__tests__/seatEventSubscription.unit.test.ts +717 -0
- package/langwatch/ee/billing/__tests__/stripe.integration.test.ts +344 -0
- package/langwatch/ee/billing/__tests__/stripePrices.types.unit.test.ts +27 -0
- package/langwatch/ee/billing/__tests__/stripePricesLoader.unit.test.ts +72 -0
- package/langwatch/ee/billing/__tests__/subscription.service.unit.test.ts +730 -0
- package/langwatch/ee/billing/__tests__/subscriptionItemCalculator.unit.test.ts +176 -0
- package/langwatch/ee/billing/__tests__/usage-limit.service.unit.test.ts +706 -0
- package/langwatch/ee/billing/__tests__/usageReportingService.integration.test.ts +421 -0
- package/langwatch/ee/billing/__tests__/usageReportingService.unit.test.ts +515 -0
- package/langwatch/ee/billing/__tests__/webhookService.unit.test.ts +958 -0
- package/langwatch/ee/billing/currencyRouter.ts +18 -0
- package/langwatch/ee/billing/errors.ts +129 -0
- package/langwatch/ee/billing/index.ts +67 -0
- package/langwatch/ee/billing/middleware.ts +17 -0
- package/langwatch/ee/billing/notifications/notification.service.ts +651 -0
- package/langwatch/ee/billing/notifications/repositories/notification.repository.ts +51 -0
- package/langwatch/ee/billing/notifications/types.ts +9 -0
- package/langwatch/ee/billing/notifications/usage-limit.service.ts +622 -0
- package/langwatch/ee/billing/nurturing/hooks/activityTracking.ts +90 -0
- package/langwatch/ee/billing/nurturing/hooks/activityTracking.unit.test.ts +237 -0
- package/langwatch/ee/billing/nurturing/hooks/featureAdoption.ts +120 -0
- package/langwatch/ee/billing/nurturing/hooks/featureAdoption.unit.test.ts +324 -0
- package/langwatch/ee/billing/nurturing/hooks/index.ts +17 -0
- package/langwatch/ee/billing/nurturing/hooks/productInterest.ts +68 -0
- package/langwatch/ee/billing/nurturing/hooks/productInterest.unit.test.ts +138 -0
- package/langwatch/ee/billing/nurturing/hooks/promptCreation.integration.test.ts +288 -0
- package/langwatch/ee/billing/nurturing/hooks/promptCreation.ts +131 -0
- package/langwatch/ee/billing/nurturing/hooks/promptCreation.unit.test.ts +134 -0
- package/langwatch/ee/billing/nurturing/hooks/signupIdentification.ts +101 -0
- package/langwatch/ee/billing/nurturing/hooks/signupIdentification.unit.test.ts +317 -0
- package/langwatch/ee/billing/nurturing/hooks/subscriptionSync.ts +49 -0
- package/langwatch/ee/billing/nurturing/hooks/subscriptionSync.unit.test.ts +170 -0
- package/langwatch/ee/billing/nurturing/hooks/userSync.ts +143 -0
- package/langwatch/ee/billing/nurturing/hooks/userSync.unit.test.ts +307 -0
- package/langwatch/ee/billing/nurturing/nurturing.service.ts +179 -0
- package/langwatch/ee/billing/nurturing/nurturing.service.unit.test.ts +266 -0
- package/langwatch/ee/billing/nurturing/nurturing.service.wiring.unit.test.ts +109 -0
- package/langwatch/ee/billing/nurturing/types.ts +125 -0
- package/langwatch/ee/billing/planLimits.ts +190 -0
- package/langwatch/ee/billing/planProvider.ts +119 -0
- package/langwatch/ee/billing/planTypes.ts +53 -0
- package/langwatch/ee/billing/pricing.ts +57 -0
- package/langwatch/ee/billing/services/billableEventsQuery.ts +248 -0
- package/langwatch/ee/billing/services/customerService.ts +90 -0
- package/langwatch/ee/billing/services/licensePurchaseHandler.ts +73 -0
- package/langwatch/ee/billing/services/seatEventSubscription.ts +351 -0
- package/langwatch/ee/billing/services/seatSyncService.ts +34 -0
- package/langwatch/ee/billing/services/subscription.repository.ts +203 -0
- package/langwatch/ee/billing/services/subscription.service.ts +549 -0
- package/langwatch/ee/billing/services/subscriptionItemCalculator.ts +249 -0
- package/langwatch/ee/billing/services/usageReportingService.ts +301 -0
- package/langwatch/ee/billing/services/webhookService.ts +858 -0
- package/langwatch/ee/billing/stripe/stripeCatalog.json +1781 -0
- package/langwatch/ee/billing/stripe/stripeClient.ts +13 -0
- package/langwatch/ee/billing/stripe/stripePriceCatalog.ts +70 -0
- package/langwatch/ee/billing/stripe/stripePrices.types.ts +118 -0
- package/langwatch/ee/billing/subscriptionRouter.ts +202 -0
- package/langwatch/ee/billing/types.ts +102 -0
- package/langwatch/ee/billing/utils/currency.ts +99 -0
- package/langwatch/ee/billing/utils/growthSeatEvent.ts +137 -0
- package/langwatch/ee/licensing/__tests__/constants.unit.test.ts +56 -0
- package/langwatch/ee/licensing/__tests__/defaults.unit.test.ts +192 -0
- package/langwatch/ee/licensing/__tests__/fixtures/testKeys.ts +86 -0
- package/langwatch/ee/licensing/__tests__/fixtures/testLicenses.ts +92 -0
- package/langwatch/ee/licensing/__tests__/licenseGenerationService.unit.test.ts +232 -0
- package/langwatch/ee/licensing/__tests__/licenseHandler.integration.test.ts +419 -0
- package/langwatch/ee/licensing/__tests__/planMapping.unit.test.ts +195 -0
- package/langwatch/ee/licensing/__tests__/planTemplates.unit.test.ts +193 -0
- package/langwatch/ee/licensing/__tests__/signing.unit.test.ts +164 -0
- package/langwatch/ee/licensing/__tests__/validation.unit.test.ts +281 -0
- package/langwatch/ee/licensing/client.ts +29 -0
- package/langwatch/ee/licensing/constants.ts +195 -0
- package/langwatch/ee/licensing/defaults.ts +55 -0
- package/langwatch/ee/licensing/errors.ts +11 -0
- package/langwatch/ee/licensing/index.ts +52 -0
- package/langwatch/ee/licensing/licenseGenerationService.ts +87 -0
- package/langwatch/ee/licensing/licenseHandler.ts +308 -0
- package/langwatch/ee/licensing/planInfo.ts +46 -0
- package/langwatch/ee/licensing/planMapping.ts +37 -0
- package/langwatch/ee/licensing/planTemplates.ts +109 -0
- package/langwatch/ee/licensing/server.ts +43 -0
- package/langwatch/ee/licensing/signing.ts +43 -0
- package/langwatch/ee/licensing/types.ts +156 -0
- package/langwatch/ee/licensing/validation.ts +107 -0
- package/langwatch/ee/managed-providers/ManagedModelProviderAlert.tsx +29 -0
- package/langwatch/ee/managed-providers/managedBedrockConfig.ts +226 -0
- package/langwatch/ee/saas/ExtraFooterComponents.tsx +169 -0
- package/langwatch/package.json +1 -1
- package/langwatch/pnpm-workspace.yaml +0 -1
- package/mcp-server/.env.example +2 -0
- package/mcp-server/.eslintrc.cjs +36 -0
- package/mcp-server/CHANGELOG.md +165 -0
- package/mcp-server/CONTRIBUTING.md +96 -0
- package/mcp-server/README.md +172 -0
- package/mcp-server/dist/archive-scenario-WJ2A7ETN.js +19 -0
- package/mcp-server/dist/archive-suite-4JOM4SSL.js +15 -0
- package/mcp-server/dist/assign-prompt-tag-GL7EAAF3.js +19 -0
- package/mcp-server/dist/chunk-2GT7IFWK.js +40 -0
- package/mcp-server/dist/chunk-2WPLXEKF.js +127 -0
- package/mcp-server/dist/chunk-4AUB2BIA.js +71 -0
- package/mcp-server/dist/chunk-BWWY5KEF.js +71 -0
- package/mcp-server/dist/chunk-CCWCIJJ3.js +22 -0
- package/mcp-server/dist/chunk-EGH5RPXM.js +25 -0
- package/mcp-server/dist/chunk-EUQDVOSU.js +39 -0
- package/mcp-server/dist/chunk-HYMIWO3U.js +44 -0
- package/mcp-server/dist/chunk-IE4M5OGE.js +42 -0
- package/mcp-server/dist/chunk-LUMEZEHL.js +48 -0
- package/mcp-server/dist/chunk-NUFPTHKU.js +9 -0
- package/mcp-server/dist/chunk-UDHJYT6P.js +1567 -0
- package/mcp-server/dist/chunk-WQG2DFHX.js +86 -0
- package/mcp-server/dist/chunk-WVI5CJ6S.js +21 -0
- package/mcp-server/dist/chunk-ZVS4UKN2.js +35 -0
- package/mcp-server/dist/chunk-ZXKLPC2E.js +27 -0
- package/mcp-server/dist/config.d.ts +17 -0
- package/mcp-server/dist/config.js +13 -0
- package/mcp-server/dist/create-agent-MBOOT3XK.js +23 -0
- package/mcp-server/dist/create-annotation-XMV6A7ED.js +24 -0
- package/mcp-server/dist/create-dashboard-VRKLFVZJ.js +18 -0
- package/mcp-server/dist/create-dataset-7HQPZCRE.js +22 -0
- package/mcp-server/dist/create-dataset-records-2NIVFYTV.js +22 -0
- package/mcp-server/dist/create-evaluator-WYFRFLRC.js +27 -0
- package/mcp-server/dist/create-mcp-server.d.ts +8 -0
- package/mcp-server/dist/create-mcp-server.js +8 -0
- package/mcp-server/dist/create-prompt-IEN7O6JT.js +39 -0
- package/mcp-server/dist/create-prompt-tag-CAEZ45VO.js +17 -0
- package/mcp-server/dist/create-scenario-6YHSMGLP.js +26 -0
- package/mcp-server/dist/create-suite-H5XOFDE5.js +38 -0
- package/mcp-server/dist/delete-agent-JKTNBWAA.js +18 -0
- package/mcp-server/dist/delete-annotation-ACMDV6QO.js +17 -0
- package/mcp-server/dist/delete-dashboard-VJSR7CRU.js +18 -0
- package/mcp-server/dist/delete-dataset-RTTTWP4D.js +20 -0
- package/mcp-server/dist/delete-dataset-records-KNQTIPQK.js +21 -0
- package/mcp-server/dist/delete-evaluator-7FVC5WM4.js +15 -0
- package/mcp-server/dist/delete-prompt-tag-ZMZUAGFW.js +17 -0
- package/mcp-server/dist/delete-workflow-EYQ3T4RQ.js +17 -0
- package/mcp-server/dist/discover-evaluator-schema-H23XCLNE.js +1402 -0
- package/mcp-server/dist/discover-scenario-schema-MEEEVND7.js +65 -0
- package/mcp-server/dist/discover-schema-3T52ORPB.js +446 -0
- package/mcp-server/dist/get-agent-E3QSTVKG.js +28 -0
- package/mcp-server/dist/get-analytics-2OHV763I.js +72 -0
- package/mcp-server/dist/get-dashboard-PC7JDHH6.js +29 -0
- package/mcp-server/dist/get-dataset-H5IK5FVU.js +48 -0
- package/mcp-server/dist/get-evaluator-UWVUPYTM.js +47 -0
- package/mcp-server/dist/get-prompt-WZUOLLQC.js +45 -0
- package/mcp-server/dist/get-scenario-Q6LCNUYN.js +33 -0
- package/mcp-server/dist/get-simulation-run-Z2XKO256.js +56 -0
- package/mcp-server/dist/get-suite-BXK5TN7P.js +44 -0
- package/mcp-server/dist/get-trace-4EJAYVBG.js +50 -0
- package/mcp-server/dist/get-workflow-O34QJLHD.js +25 -0
- package/mcp-server/dist/http-server-RSTXN4CN.js +224 -0
- package/mcp-server/dist/index.d.ts +2 -0
- package/mcp-server/dist/index.js +67774 -0
- package/mcp-server/dist/langwatch-api-annotations-ERBG27RF.js +17 -0
- package/mcp-server/dist/langwatch-api-dashboards-G6TR7VVO.js +17 -0
- package/mcp-server/dist/langwatch-api-monitors-WSXZLS2B.js +52 -0
- package/mcp-server/dist/langwatch-api-secrets-RR5DKG2X.js +40 -0
- package/mcp-server/dist/langwatch-api-triggers-2RTNSWQY.js +30 -0
- package/mcp-server/dist/langwatch-api-workflows-VJRIIDZ7.js +15 -0
- package/mcp-server/dist/list-agents-AW3P6FJV.js +32 -0
- package/mcp-server/dist/list-annotations-QNCGWPQ3.js +33 -0
- package/mcp-server/dist/list-dashboards-R7RK2IXL.js +32 -0
- package/mcp-server/dist/list-dataset-records-WVCSQP7P.js +39 -0
- package/mcp-server/dist/list-datasets-KEXRLDEU.js +60 -0
- package/mcp-server/dist/list-evaluators-7R2LB4JH.js +34 -0
- package/mcp-server/dist/list-model-providers-OBYJCKBX.js +35 -0
- package/mcp-server/dist/list-prompt-tags-6LY3ZPYI.js +23 -0
- package/mcp-server/dist/list-prompts-VWEZ4CDE.js +32 -0
- package/mcp-server/dist/list-scenarios-TXD4W2ZJ.js +40 -0
- package/mcp-server/dist/list-simulation-runs-RHPOLMFI.js +43 -0
- package/mcp-server/dist/list-suites-FSGBX27Z.js +42 -0
- package/mcp-server/dist/list-workflows-VRGEZ3EN.js +35 -0
- package/mcp-server/dist/rename-prompt-tag-VOJJLX4M.js +18 -0
- package/mcp-server/dist/run-agent-KTCC7TB7.js +36 -0
- package/mcp-server/dist/run-evaluation-2X3V3Q6L.js +64 -0
- package/mcp-server/dist/run-suite-BTMHGI2D.js +29 -0
- package/mcp-server/dist/run-workflow-IGAYGKJL.js +36 -0
- package/mcp-server/dist/search-traces-VYFUIMXH.js +72 -0
- package/mcp-server/dist/set-model-provider-W5IUI326.js +33 -0
- package/mcp-server/dist/update-agent-4BB7EYLR.js +20 -0
- package/mcp-server/dist/update-dataset-CXBKZ4W3.js +22 -0
- package/mcp-server/dist/update-dataset-record-HOHAMHXG.js +19 -0
- package/mcp-server/dist/update-evaluator-IVOR6FTR.js +24 -0
- package/mcp-server/dist/update-prompt-OWQAKE7K.js +24 -0
- package/mcp-server/dist/update-scenario-GDFVILPN.js +27 -0
- package/mcp-server/dist/update-suite-BXYUYSPT.js +39 -0
- package/mcp-server/package.json +79 -0
- package/mcp-server/pnpm-lock.yaml +6103 -0
- package/mcp-server/pnpm-workspace.yaml +2 -0
- package/mcp-server/pyproject.toml +17 -0
- package/mcp-server/src/__tests__/all-tools.integration.test.ts +1681 -0
- package/mcp-server/src/__tests__/config.unit.test.ts +169 -0
- package/mcp-server/src/__tests__/datasets.integration.test.ts +603 -0
- package/mcp-server/src/__tests__/datasets.unit.test.ts +240 -0
- package/mcp-server/src/__tests__/date-parsing.unit.test.ts +78 -0
- package/mcp-server/src/__tests__/discover-evaluator-schema.unit.test.ts +89 -0
- package/mcp-server/src/__tests__/discover-schema.unit.test.ts +118 -0
- package/mcp-server/src/__tests__/docker.integration.test.ts +234 -0
- package/mcp-server/src/__tests__/evaluator-tools.unit.test.ts +262 -0
- package/mcp-server/src/__tests__/http-transport.integration.test.ts +397 -0
- package/mcp-server/src/__tests__/integration.integration.test.ts +288 -0
- package/mcp-server/src/__tests__/langwatch-api.unit.test.ts +455 -0
- package/mcp-server/src/__tests__/model-provider-tools.unit.test.ts +190 -0
- package/mcp-server/src/__tests__/scenario-tools.integration.test.ts +286 -0
- package/mcp-server/src/__tests__/scenario-tools.unit.test.ts +185 -0
- package/mcp-server/src/__tests__/schemas.unit.test.ts +85 -0
- package/mcp-server/src/__tests__/tools.unit.test.ts +900 -0
- package/mcp-server/src/config.d.ts +15 -0
- package/mcp-server/src/config.ts +107 -0
- package/mcp-server/src/create-mcp-server.d.ts +6 -0
- package/mcp-server/src/create-mcp-server.ts +1799 -0
- package/mcp-server/src/http-server.ts +329 -0
- package/mcp-server/src/index.ts +46 -0
- package/mcp-server/src/langwatch-api-agents.ts +108 -0
- package/mcp-server/src/langwatch-api-annotations.ts +49 -0
- package/mcp-server/src/langwatch-api-dashboards.ts +48 -0
- package/mcp-server/src/langwatch-api-datasets.ts +191 -0
- package/mcp-server/src/langwatch-api-evaluators.ts +80 -0
- package/mcp-server/src/langwatch-api-model-providers.ts +41 -0
- package/mcp-server/src/langwatch-api-monitors.ts +82 -0
- package/mcp-server/src/langwatch-api-scenarios.ts +67 -0
- package/mcp-server/src/langwatch-api-secrets.ts +48 -0
- package/mcp-server/src/langwatch-api-simulation-runs.ts +51 -0
- package/mcp-server/src/langwatch-api-suites.ts +118 -0
- package/mcp-server/src/langwatch-api-triggers.ts +48 -0
- package/mcp-server/src/langwatch-api-workflows.ts +41 -0
- package/mcp-server/src/langwatch-api.ts +299 -0
- package/mcp-server/src/schemas/analytics-groups.ts +78 -0
- package/mcp-server/src/schemas/analytics-metrics.ts +179 -0
- package/mcp-server/src/schemas/create-dataset.ts +48 -0
- package/mcp-server/src/schemas/filter-fields.ts +119 -0
- package/mcp-server/src/schemas/index.ts +4 -0
- package/mcp-server/src/tools/archive-scenario.ts +19 -0
- package/mcp-server/src/tools/archive-suite.ts +12 -0
- package/mcp-server/src/tools/assign-prompt-tag.ts +16 -0
- package/mcp-server/src/tools/create-agent.ts +15 -0
- package/mcp-server/src/tools/create-annotation.ts +18 -0
- package/mcp-server/src/tools/create-dashboard.ts +7 -0
- package/mcp-server/src/tools/create-dataset-records.ts +23 -0
- package/mcp-server/src/tools/create-dataset.ts +22 -0
- package/mcp-server/src/tools/create-evaluator.ts +33 -0
- package/mcp-server/src/tools/create-prompt-tag.ts +12 -0
- package/mcp-server/src/tools/create-prompt.ts +58 -0
- package/mcp-server/src/tools/create-scenario.ts +30 -0
- package/mcp-server/src/tools/create-suite.ts +42 -0
- package/mcp-server/src/tools/delete-agent.ts +7 -0
- package/mcp-server/src/tools/delete-annotation.ts +7 -0
- package/mcp-server/src/tools/delete-dashboard.ts +7 -0
- package/mcp-server/src/tools/delete-dataset-records.ts +22 -0
- package/mcp-server/src/tools/delete-dataset.ts +20 -0
- package/mcp-server/src/tools/delete-evaluator.ts +12 -0
- package/mcp-server/src/tools/delete-prompt-tag.ts +12 -0
- package/mcp-server/src/tools/delete-workflow.ts +7 -0
- package/mcp-server/src/tools/discover-evaluator-schema.ts +143 -0
- package/mcp-server/src/tools/discover-scenario-schema.ts +71 -0
- package/mcp-server/src/tools/discover-schema.ts +106 -0
- package/mcp-server/src/tools/format-dataset-mutation.ts +25 -0
- package/mcp-server/src/tools/get-agent.ts +21 -0
- package/mcp-server/src/tools/get-analytics.ts +98 -0
- package/mcp-server/src/tools/get-dashboard.ts +22 -0
- package/mcp-server/src/tools/get-dataset.ts +63 -0
- package/mcp-server/src/tools/get-evaluator.ts +53 -0
- package/mcp-server/src/tools/get-prompt.ts +54 -0
- package/mcp-server/src/tools/get-scenario.ts +36 -0
- package/mcp-server/src/tools/get-simulation-run.ts +60 -0
- package/mcp-server/src/tools/get-suite.ts +47 -0
- package/mcp-server/src/tools/get-trace.ts +61 -0
- package/mcp-server/src/tools/get-workflow.ts +17 -0
- package/mcp-server/src/tools/list-agents.ts +27 -0
- package/mcp-server/src/tools/list-annotations.ts +33 -0
- package/mcp-server/src/tools/list-dashboards.ts +27 -0
- package/mcp-server/src/tools/list-dataset-records.ts +46 -0
- package/mcp-server/src/tools/list-datasets.ts +80 -0
- package/mcp-server/src/tools/list-evaluators.ts +37 -0
- package/mcp-server/src/tools/list-model-providers.ts +40 -0
- package/mcp-server/src/tools/list-prompt-tags.ts +21 -0
- package/mcp-server/src/tools/list-prompts.ts +34 -0
- package/mcp-server/src/tools/list-scenarios.ts +47 -0
- package/mcp-server/src/tools/list-simulation-runs.ts +49 -0
- package/mcp-server/src/tools/list-suites.ts +43 -0
- package/mcp-server/src/tools/list-workflows.ts +31 -0
- package/mcp-server/src/tools/rename-prompt-tag.ts +14 -0
- package/mcp-server/src/tools/run-agent.ts +36 -0
- package/mcp-server/src/tools/run-evaluation.ts +87 -0
- package/mcp-server/src/tools/run-suite.ts +28 -0
- package/mcp-server/src/tools/run-workflow.ts +36 -0
- package/mcp-server/src/tools/search-traces.ts +91 -0
- package/mcp-server/src/tools/set-model-provider.ts +46 -0
- package/mcp-server/src/tools/update-agent.ts +13 -0
- package/mcp-server/src/tools/update-dataset-record.ts +21 -0
- package/mcp-server/src/tools/update-dataset.ts +23 -0
- package/mcp-server/src/tools/update-evaluator.ts +30 -0
- package/mcp-server/src/tools/update-prompt.ts +31 -0
- package/mcp-server/src/tools/update-scenario.ts +32 -0
- package/mcp-server/src/tools/update-suite.ts +44 -0
- package/mcp-server/src/utils/date-parsing.ts +31 -0
- package/mcp-server/src/utils/escape-markdown.ts +12 -0
- package/mcp-server/tsconfig.json +27 -0
- package/mcp-server/uv.lock +2731 -0
- package/package.json +2 -1
- package/packages/server/dist/cli.cjs +1 -1
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { HStack, Text, chakra } from "@chakra-ui/react";
|
|
2
|
+
import React from "react";
|
|
3
|
+
|
|
4
|
+
interface ImpersonationBannerProps {
|
|
5
|
+
user: {
|
|
6
|
+
name?: string | null;
|
|
7
|
+
email?: string | null;
|
|
8
|
+
impersonator?: {
|
|
9
|
+
id: string;
|
|
10
|
+
name?: string | null;
|
|
11
|
+
email?: string | null;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const ImpersonationBanner = ({ user }: ImpersonationBannerProps) => {
|
|
17
|
+
if (!user.impersonator) return null;
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<HStack
|
|
21
|
+
fontSize="12px"
|
|
22
|
+
fontWeight="bold"
|
|
23
|
+
color="white"
|
|
24
|
+
background="linear-gradient(135deg, #3182CE, #2B6CB0)"
|
|
25
|
+
border="1px solid"
|
|
26
|
+
borderColor="blue.400"
|
|
27
|
+
borderRadius="full"
|
|
28
|
+
height="32px"
|
|
29
|
+
paddingX={3}
|
|
30
|
+
gap={2}
|
|
31
|
+
flexShrink={0}
|
|
32
|
+
>
|
|
33
|
+
<Text fontSize="12px" lineClamp={1}>
|
|
34
|
+
Impersonating {user.name ?? user.email ?? "unknown user"}
|
|
35
|
+
</Text>
|
|
36
|
+
<chakra.a
|
|
37
|
+
href="#"
|
|
38
|
+
onClick={async (e: React.MouseEvent<HTMLAnchorElement>) => {
|
|
39
|
+
e.preventDefault();
|
|
40
|
+
const response = await fetch("/api/admin/impersonate", {
|
|
41
|
+
method: "DELETE",
|
|
42
|
+
});
|
|
43
|
+
if (response.ok) {
|
|
44
|
+
window.location.href = "/admin#/user";
|
|
45
|
+
}
|
|
46
|
+
}}
|
|
47
|
+
fontSize="11px"
|
|
48
|
+
fontWeight="bold"
|
|
49
|
+
color="white"
|
|
50
|
+
background="whiteAlpha.300"
|
|
51
|
+
borderRadius="full"
|
|
52
|
+
paddingX={2}
|
|
53
|
+
paddingY="2px"
|
|
54
|
+
cursor="pointer"
|
|
55
|
+
_hover={{ background: "whiteAlpha.400" }}
|
|
56
|
+
>
|
|
57
|
+
Stop
|
|
58
|
+
</chakra.a>
|
|
59
|
+
</HStack>
|
|
60
|
+
);
|
|
61
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Menu } from "~/components/ui/menu";
|
|
2
|
+
import { Separator } from "@chakra-ui/react";
|
|
3
|
+
import { useRequiredSession } from "~/hooks/useRequiredSession";
|
|
4
|
+
|
|
5
|
+
export const ImpersonationSwitchBackMenuItem = () => {
|
|
6
|
+
const { data: session } = useRequiredSession();
|
|
7
|
+
const user = session?.user;
|
|
8
|
+
|
|
9
|
+
return user?.impersonator ? (
|
|
10
|
+
<>
|
|
11
|
+
<Menu.ItemGroup title={`Impersonating ${user.name ?? user.email ?? ""}`}>
|
|
12
|
+
<Menu.Item
|
|
13
|
+
value="switch-back"
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
15
|
+
onClick={async () => {
|
|
16
|
+
const response = await fetch("/api/admin/impersonate", {
|
|
17
|
+
method: "DELETE",
|
|
18
|
+
});
|
|
19
|
+
if (response.ok) {
|
|
20
|
+
window.location.href = "/admin#/user";
|
|
21
|
+
}
|
|
22
|
+
}}
|
|
23
|
+
>
|
|
24
|
+
Switch back to {user.impersonator.name ?? user.impersonator.email}
|
|
25
|
+
</Menu.Item>
|
|
26
|
+
</Menu.ItemGroup>
|
|
27
|
+
<Separator />
|
|
28
|
+
</>
|
|
29
|
+
) : null;
|
|
30
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vitest-environment jsdom
|
|
3
|
+
*/
|
|
4
|
+
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
5
|
+
import { render, screen, fireEvent, waitFor } from "@testing-library/react";
|
|
6
|
+
import { ImpersonationBanner } from "../ImpersonationBanner";
|
|
7
|
+
import { ChakraProvider, defaultSystem } from "@chakra-ui/react";
|
|
8
|
+
|
|
9
|
+
const wrapper = ({ children }: { children: React.ReactNode }) => (
|
|
10
|
+
<ChakraProvider value={defaultSystem}>{children}</ChakraProvider>
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
describe("ImpersonationBanner", () => {
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
vi.restoreAllMocks();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
describe("when user is not being impersonated", () => {
|
|
19
|
+
it("renders nothing", () => {
|
|
20
|
+
const { container } = render(
|
|
21
|
+
<ImpersonationBanner
|
|
22
|
+
user={{ name: "Alice", email: "alice@test.com" }}
|
|
23
|
+
/>,
|
|
24
|
+
{ wrapper },
|
|
25
|
+
);
|
|
26
|
+
expect(container.innerHTML).toBe("");
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
describe("when user is being impersonated", () => {
|
|
31
|
+
const impersonatedUser = {
|
|
32
|
+
name: "Target User",
|
|
33
|
+
email: "target@test.com",
|
|
34
|
+
impersonator: {
|
|
35
|
+
id: "admin-id",
|
|
36
|
+
name: "Admin",
|
|
37
|
+
email: "admin@test.com",
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
it("displays the impersonation text and stop action", () => {
|
|
42
|
+
render(<ImpersonationBanner user={impersonatedUser} />, { wrapper });
|
|
43
|
+
expect(
|
|
44
|
+
screen.getByText("Impersonating Target User"),
|
|
45
|
+
).toBeInTheDocument();
|
|
46
|
+
// Chakra renders multiple copies for responsive breakpoints
|
|
47
|
+
const stopLinks = screen.getAllByRole("link", { name: "Stop" });
|
|
48
|
+
expect(stopLinks.length).toBeGreaterThan(0);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("falls back to email when name is null", () => {
|
|
52
|
+
render(
|
|
53
|
+
<ImpersonationBanner
|
|
54
|
+
user={{
|
|
55
|
+
...impersonatedUser,
|
|
56
|
+
name: null,
|
|
57
|
+
}}
|
|
58
|
+
/>,
|
|
59
|
+
{ wrapper },
|
|
60
|
+
);
|
|
61
|
+
expect(
|
|
62
|
+
screen.getByText("Impersonating target@test.com"),
|
|
63
|
+
).toBeInTheDocument();
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("sends DELETE request when Stop is clicked", async () => {
|
|
67
|
+
const fetchSpy = vi.spyOn(globalThis, "fetch").mockResolvedValue(
|
|
68
|
+
new Response(null, { status: 200 }),
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
render(<ImpersonationBanner user={impersonatedUser} />, { wrapper });
|
|
72
|
+
|
|
73
|
+
fireEvent.click(screen.getAllByRole("link", { name: "Stop" })[0]!);
|
|
74
|
+
|
|
75
|
+
await waitFor(() => {
|
|
76
|
+
expect(fetchSpy).toHaveBeenCalledWith("/api/admin/impersonate", {
|
|
77
|
+
method: "DELETE",
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
});
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import type { PrismaClient } from "@prisma/client";
|
|
2
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
import {
|
|
4
|
+
CannotImpersonateAdminError,
|
|
5
|
+
CannotImpersonateDeactivatedUserError,
|
|
6
|
+
ImpersonationService,
|
|
7
|
+
UserToImpersonateNotFoundError,
|
|
8
|
+
type AuditLogFn,
|
|
9
|
+
} from "../impersonation.service";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Unit tests for the Backoffice impersonation service. The service is DI'd
|
|
13
|
+
* so every dependency (PrismaClient, audit logger) is a stub here — no real
|
|
14
|
+
* DB, no real auth stack. Covers the four explicit outcomes the service
|
|
15
|
+
* contract promises:
|
|
16
|
+
*
|
|
17
|
+
* 1. Happy path: start writes an audit log + updates the session.
|
|
18
|
+
* 2. Rejects impersonating a deactivated user (400).
|
|
19
|
+
* 3. Rejects impersonating an admin (403).
|
|
20
|
+
* 4. Rejects an unknown target user (404).
|
|
21
|
+
*
|
|
22
|
+
* Also covers `stop()` clearing the impersonating column.
|
|
23
|
+
*
|
|
24
|
+
* Admin detection is driven by `isAdmin()` which reads ADMIN_EMAILS from the
|
|
25
|
+
* environment — we set it explicitly in the one test that needs it to keep
|
|
26
|
+
* the rest of the suite independent of the developer's local env.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
interface StubSession {
|
|
30
|
+
findUnique: ReturnType<typeof vi.fn>;
|
|
31
|
+
update: ReturnType<typeof vi.fn>;
|
|
32
|
+
}
|
|
33
|
+
interface StubUser {
|
|
34
|
+
findUnique: ReturnType<typeof vi.fn>;
|
|
35
|
+
}
|
|
36
|
+
interface StubPrisma {
|
|
37
|
+
user: StubUser;
|
|
38
|
+
session: StubSession;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function makePrisma(): StubPrisma {
|
|
42
|
+
return {
|
|
43
|
+
user: { findUnique: vi.fn() },
|
|
44
|
+
session: {
|
|
45
|
+
findUnique: vi.fn(),
|
|
46
|
+
update: vi.fn().mockResolvedValue({}),
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function makeAuditLog(): AuditLogFn & { calls: Parameters<AuditLogFn>[0][] } {
|
|
52
|
+
const calls: Parameters<AuditLogFn>[0][] = [];
|
|
53
|
+
const fn = (async (input) => {
|
|
54
|
+
calls.push(input);
|
|
55
|
+
}) as AuditLogFn & { calls: Parameters<AuditLogFn>[0][] };
|
|
56
|
+
fn.calls = calls;
|
|
57
|
+
return fn;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
describe("ImpersonationService", () => {
|
|
61
|
+
const originalAdminEmails = process.env.ADMIN_EMAILS;
|
|
62
|
+
|
|
63
|
+
beforeEach(() => {
|
|
64
|
+
// Keep every test's admin detection deterministic.
|
|
65
|
+
process.env.ADMIN_EMAILS = "root@langwatch.ai";
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
afterEach(() => {
|
|
69
|
+
process.env.ADMIN_EMAILS = originalAdminEmails;
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
describe("start", () => {
|
|
73
|
+
describe("given a healthy, non-admin, non-deactivated target", () => {
|
|
74
|
+
it("writes an audit log and stamps the session with the impersonating user", async () => {
|
|
75
|
+
const prisma = makePrisma();
|
|
76
|
+
prisma.user.findUnique.mockResolvedValue({
|
|
77
|
+
id: "user_target",
|
|
78
|
+
name: "Target",
|
|
79
|
+
email: "target@example.com",
|
|
80
|
+
image: null,
|
|
81
|
+
deactivatedAt: null,
|
|
82
|
+
});
|
|
83
|
+
const auditLog = makeAuditLog();
|
|
84
|
+
const service = ImpersonationService.create(
|
|
85
|
+
prisma as unknown as PrismaClient,
|
|
86
|
+
auditLog,
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
await service.start({
|
|
90
|
+
sessionId: "sess_1",
|
|
91
|
+
impersonatorUserId: "user_admin",
|
|
92
|
+
userIdToImpersonate: "user_target",
|
|
93
|
+
reason: "Debugging trace #42",
|
|
94
|
+
req: { foo: "bar" },
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
expect(auditLog.calls).toEqual([
|
|
98
|
+
{
|
|
99
|
+
userId: "user_admin",
|
|
100
|
+
action: "admin/impersonate",
|
|
101
|
+
args: {
|
|
102
|
+
userIdToImpersonate: "user_target",
|
|
103
|
+
reason: "Debugging trace #42",
|
|
104
|
+
},
|
|
105
|
+
req: { foo: "bar" },
|
|
106
|
+
},
|
|
107
|
+
]);
|
|
108
|
+
expect(prisma.session.update).toHaveBeenCalledTimes(1);
|
|
109
|
+
const call = prisma.session.update.mock.calls[0]!;
|
|
110
|
+
const [{ where, data }] = call;
|
|
111
|
+
expect(where).toEqual({ id: "sess_1" });
|
|
112
|
+
expect(data.impersonating.id).toBe("user_target");
|
|
113
|
+
expect(data.impersonating.email).toBe("target@example.com");
|
|
114
|
+
// Expiry is ~1h in the future; accept anything within a 5s window
|
|
115
|
+
// of "now + 1h" to avoid flaky timing assertions.
|
|
116
|
+
const expires = new Date(data.impersonating.expires).getTime();
|
|
117
|
+
const expected = Date.now() + 60 * 60 * 1000;
|
|
118
|
+
expect(Math.abs(expires - expected)).toBeLessThan(5_000);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
describe("given the target user does not exist", () => {
|
|
123
|
+
it("throws UserToImpersonateNotFoundError and leaves the session untouched", async () => {
|
|
124
|
+
const prisma = makePrisma();
|
|
125
|
+
prisma.user.findUnique.mockResolvedValue(null);
|
|
126
|
+
const auditLog = makeAuditLog();
|
|
127
|
+
const service = ImpersonationService.create(
|
|
128
|
+
prisma as unknown as PrismaClient,
|
|
129
|
+
auditLog,
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
await expect(
|
|
133
|
+
service.start({
|
|
134
|
+
sessionId: "sess_1",
|
|
135
|
+
impersonatorUserId: "user_admin",
|
|
136
|
+
userIdToImpersonate: "user_missing",
|
|
137
|
+
reason: "…",
|
|
138
|
+
req: null,
|
|
139
|
+
}),
|
|
140
|
+
).rejects.toBeInstanceOf(UserToImpersonateNotFoundError);
|
|
141
|
+
|
|
142
|
+
expect(prisma.session.update).not.toHaveBeenCalled();
|
|
143
|
+
expect(auditLog.calls).toHaveLength(0);
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
describe("given the target user is deactivated", () => {
|
|
148
|
+
it("throws CannotImpersonateDeactivatedUserError with 400 status", async () => {
|
|
149
|
+
const prisma = makePrisma();
|
|
150
|
+
prisma.user.findUnique.mockResolvedValue({
|
|
151
|
+
id: "user_deactivated",
|
|
152
|
+
name: null,
|
|
153
|
+
email: "shadow@example.com",
|
|
154
|
+
image: null,
|
|
155
|
+
deactivatedAt: new Date("2026-01-01"),
|
|
156
|
+
});
|
|
157
|
+
const service = ImpersonationService.create(
|
|
158
|
+
prisma as unknown as PrismaClient,
|
|
159
|
+
makeAuditLog(),
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
const err = await service
|
|
163
|
+
.start({
|
|
164
|
+
sessionId: "sess_1",
|
|
165
|
+
impersonatorUserId: "user_admin",
|
|
166
|
+
userIdToImpersonate: "user_deactivated",
|
|
167
|
+
reason: "…",
|
|
168
|
+
req: null,
|
|
169
|
+
})
|
|
170
|
+
.catch((e) => e);
|
|
171
|
+
|
|
172
|
+
expect(err).toBeInstanceOf(CannotImpersonateDeactivatedUserError);
|
|
173
|
+
expect((err as CannotImpersonateDeactivatedUserError).httpStatus).toBe(400);
|
|
174
|
+
expect(prisma.session.update).not.toHaveBeenCalled();
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
describe("given the target user is themselves an admin", () => {
|
|
179
|
+
it("throws CannotImpersonateAdminError with 403 status", async () => {
|
|
180
|
+
const prisma = makePrisma();
|
|
181
|
+
prisma.user.findUnique.mockResolvedValue({
|
|
182
|
+
id: "user_other_admin",
|
|
183
|
+
name: "Other Admin",
|
|
184
|
+
// Match ADMIN_EMAILS set in beforeEach — isAdmin is case-insensitive.
|
|
185
|
+
email: "Root@Langwatch.ai",
|
|
186
|
+
image: null,
|
|
187
|
+
deactivatedAt: null,
|
|
188
|
+
});
|
|
189
|
+
const service = ImpersonationService.create(
|
|
190
|
+
prisma as unknown as PrismaClient,
|
|
191
|
+
makeAuditLog(),
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
const err = await service
|
|
195
|
+
.start({
|
|
196
|
+
sessionId: "sess_1",
|
|
197
|
+
impersonatorUserId: "user_admin",
|
|
198
|
+
userIdToImpersonate: "user_other_admin",
|
|
199
|
+
reason: "…",
|
|
200
|
+
req: null,
|
|
201
|
+
})
|
|
202
|
+
.catch((e) => e);
|
|
203
|
+
|
|
204
|
+
expect(err).toBeInstanceOf(CannotImpersonateAdminError);
|
|
205
|
+
expect((err as CannotImpersonateAdminError).httpStatus).toBe(403);
|
|
206
|
+
expect(prisma.session.update).not.toHaveBeenCalled();
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
describe("stop", () => {
|
|
212
|
+
it("clears the impersonating column on the given session", async () => {
|
|
213
|
+
const prisma = makePrisma();
|
|
214
|
+
const service = ImpersonationService.create(
|
|
215
|
+
prisma as unknown as PrismaClient,
|
|
216
|
+
makeAuditLog(),
|
|
217
|
+
);
|
|
218
|
+
|
|
219
|
+
await service.stop({ sessionId: "sess_1" });
|
|
220
|
+
|
|
221
|
+
expect(prisma.session.update).toHaveBeenCalledTimes(1);
|
|
222
|
+
const call = prisma.session.update.mock.calls[0]!;
|
|
223
|
+
const [{ where, data }] = call;
|
|
224
|
+
expect(where).toEqual({ id: "sess_1" });
|
|
225
|
+
// Prisma.DbNull — vitest's deep equal compares by reference for
|
|
226
|
+
// unknown symbols, so just assert the property exists.
|
|
227
|
+
expect("impersonating" in data).toBe(true);
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Box,
|
|
3
|
+
Button,
|
|
4
|
+
Card,
|
|
5
|
+
HStack,
|
|
6
|
+
Heading,
|
|
7
|
+
Spacer,
|
|
8
|
+
Spinner,
|
|
9
|
+
Text,
|
|
10
|
+
VStack,
|
|
11
|
+
} from "@chakra-ui/react";
|
|
12
|
+
import { ChevronLeft, ChevronRight, Plus } from "lucide-react";
|
|
13
|
+
import type { PropsWithChildren, ReactNode } from "react";
|
|
14
|
+
import { SearchInput } from "~/components/ui/SearchInput";
|
|
15
|
+
import { PageLayout } from "~/components/ui/layouts/PageLayout";
|
|
16
|
+
|
|
17
|
+
export interface PaginationState {
|
|
18
|
+
page: number;
|
|
19
|
+
perPage: number;
|
|
20
|
+
total: number;
|
|
21
|
+
onPageChange: (page: number) => void;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface BackofficeTableProps {
|
|
25
|
+
title: string;
|
|
26
|
+
searchValue: string;
|
|
27
|
+
onSearchChange: (value: string) => void;
|
|
28
|
+
searchPlaceholder?: string;
|
|
29
|
+
pagination?: PaginationState;
|
|
30
|
+
isLoading?: boolean;
|
|
31
|
+
isFetching?: boolean;
|
|
32
|
+
error?: Error | null;
|
|
33
|
+
onCreate?: () => void;
|
|
34
|
+
createLabel?: string;
|
|
35
|
+
/** Slot for the <Table.Root>…</Table.Root> content. */
|
|
36
|
+
children: ReactNode;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Standard Backoffice list-view shell. Uses the same Heading + Card + Table
|
|
41
|
+
* rhythm as `/settings/members` so every admin resource page looks and feels
|
|
42
|
+
* like the rest of Settings — see `members.tsx` for the reference pattern.
|
|
43
|
+
*
|
|
44
|
+
* Intentionally thin: the view owns the table rows, this only handles the
|
|
45
|
+
* repeatable chrome (title, search, loading/empty/error, pagination).
|
|
46
|
+
*/
|
|
47
|
+
export function BackofficeTable({
|
|
48
|
+
title,
|
|
49
|
+
searchValue,
|
|
50
|
+
onSearchChange,
|
|
51
|
+
searchPlaceholder = "Search",
|
|
52
|
+
pagination,
|
|
53
|
+
isLoading,
|
|
54
|
+
isFetching,
|
|
55
|
+
error,
|
|
56
|
+
onCreate,
|
|
57
|
+
createLabel = "Create",
|
|
58
|
+
children,
|
|
59
|
+
}: BackofficeTableProps) {
|
|
60
|
+
return (
|
|
61
|
+
<VStack gap={6} width="full" align="start">
|
|
62
|
+
<HStack width="full">
|
|
63
|
+
<Heading>{title}</Heading>
|
|
64
|
+
<Spacer />
|
|
65
|
+
{onCreate && (
|
|
66
|
+
<PageLayout.HeaderButton onClick={onCreate}>
|
|
67
|
+
<Plus size={20} />
|
|
68
|
+
{createLabel}
|
|
69
|
+
</PageLayout.HeaderButton>
|
|
70
|
+
)}
|
|
71
|
+
</HStack>
|
|
72
|
+
|
|
73
|
+
<SearchInput
|
|
74
|
+
value={searchValue}
|
|
75
|
+
onChange={(e) => onSearchChange(e.target.value)}
|
|
76
|
+
placeholder={searchPlaceholder}
|
|
77
|
+
width="full"
|
|
78
|
+
maxWidth="480px"
|
|
79
|
+
/>
|
|
80
|
+
|
|
81
|
+
<Card.Root width="full" overflow="hidden">
|
|
82
|
+
<Card.Body paddingY={0} paddingX={0}>
|
|
83
|
+
{error ? (
|
|
84
|
+
<Box paddingY={10} paddingX={4}>
|
|
85
|
+
<Text color="red.500" fontSize="sm">
|
|
86
|
+
{error.message}
|
|
87
|
+
</Text>
|
|
88
|
+
</Box>
|
|
89
|
+
) : isLoading ? (
|
|
90
|
+
<Box paddingY={10} textAlign="center">
|
|
91
|
+
<Spinner size="md" />
|
|
92
|
+
</Box>
|
|
93
|
+
) : (
|
|
94
|
+
<Box position="relative" width="full" overflow="auto">
|
|
95
|
+
{isFetching && (
|
|
96
|
+
<Box
|
|
97
|
+
position="absolute"
|
|
98
|
+
top={2}
|
|
99
|
+
right={2}
|
|
100
|
+
zIndex={1}
|
|
101
|
+
color="fg.muted"
|
|
102
|
+
>
|
|
103
|
+
<Spinner size="xs" />
|
|
104
|
+
</Box>
|
|
105
|
+
)}
|
|
106
|
+
{children}
|
|
107
|
+
</Box>
|
|
108
|
+
)}
|
|
109
|
+
</Card.Body>
|
|
110
|
+
</Card.Root>
|
|
111
|
+
|
|
112
|
+
{pagination && pagination.total > 0 && (
|
|
113
|
+
<PaginationBar {...pagination} />
|
|
114
|
+
)}
|
|
115
|
+
</VStack>
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function PaginationBar({
|
|
120
|
+
page,
|
|
121
|
+
perPage,
|
|
122
|
+
total,
|
|
123
|
+
onPageChange,
|
|
124
|
+
}: PaginationState) {
|
|
125
|
+
const totalPages = Math.max(1, Math.ceil(total / perPage));
|
|
126
|
+
const canPrev = page > 1;
|
|
127
|
+
const canNext = page < totalPages;
|
|
128
|
+
const rangeStart = total === 0 ? 0 : (page - 1) * perPage + 1;
|
|
129
|
+
const rangeEnd = Math.min(total, page * perPage);
|
|
130
|
+
|
|
131
|
+
return (
|
|
132
|
+
<HStack width="full" justify="end" gap={4}>
|
|
133
|
+
<Text fontSize="sm" color="fg.muted">
|
|
134
|
+
{rangeStart}–{rangeEnd} of {total}
|
|
135
|
+
</Text>
|
|
136
|
+
<HStack gap={1}>
|
|
137
|
+
<Button
|
|
138
|
+
size="sm"
|
|
139
|
+
variant="outline"
|
|
140
|
+
disabled={!canPrev}
|
|
141
|
+
onClick={() => onPageChange(page - 1)}
|
|
142
|
+
>
|
|
143
|
+
<ChevronLeft size={14} />
|
|
144
|
+
</Button>
|
|
145
|
+
<Button
|
|
146
|
+
size="sm"
|
|
147
|
+
variant="outline"
|
|
148
|
+
disabled={!canNext}
|
|
149
|
+
onClick={() => onPageChange(page + 1)}
|
|
150
|
+
>
|
|
151
|
+
<ChevronRight size={14} />
|
|
152
|
+
</Button>
|
|
153
|
+
</HStack>
|
|
154
|
+
</HStack>
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** Dash placeholder for empty cell values — avoids `-` noise scattered across. */
|
|
159
|
+
export function EmptyCell({ children }: PropsWithChildren) {
|
|
160
|
+
return (
|
|
161
|
+
<Text color="fg.muted" fontSize="sm">
|
|
162
|
+
{children ?? "—"}
|
|
163
|
+
</Text>
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** Human-readable date (respects locale, uses user's TZ). */
|
|
168
|
+
export function formatDate(value: string | Date | null | undefined): string {
|
|
169
|
+
if (!value) return "—";
|
|
170
|
+
const d = typeof value === "string" ? new Date(value) : value;
|
|
171
|
+
if (Number.isNaN(d.getTime())) return "—";
|
|
172
|
+
return d.toLocaleDateString();
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export function formatDateTime(value: string | Date | null | undefined): string {
|
|
176
|
+
if (!value) return "—";
|
|
177
|
+
const d = typeof value === "string" ? new Date(value) : value;
|
|
178
|
+
if (Number.isNaN(d.getTime())) return "—";
|
|
179
|
+
return `${d.toLocaleDateString()} ${d.toLocaleTimeString()}`;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Turn a `<input type="date">` string (always `YYYY-MM-DD`, always the user's
|
|
184
|
+
* local calendar date) into an ISO string without drifting the day.
|
|
185
|
+
*
|
|
186
|
+
* Background: `new Date("2026-04-16").toISOString()` parses as UTC midnight.
|
|
187
|
+
* A user in PST typing "2026-04-16" and saving gets `2026-04-15T23:00:00Z`
|
|
188
|
+
* back on read — shifting the calendar day. Parsing as local noon keeps the
|
|
189
|
+
* date stable regardless of timezone.
|
|
190
|
+
*/
|
|
191
|
+
export function dateInputToISO(value: string): string | null {
|
|
192
|
+
if (!value) return null;
|
|
193
|
+
const parts = value.split("-").map(Number);
|
|
194
|
+
if (parts.length !== 3 || parts.some((n) => Number.isNaN(n))) return null;
|
|
195
|
+
const [year, month, day] = parts;
|
|
196
|
+
// Noon local time — gives a 12h buffer either side of UTC so the calendar
|
|
197
|
+
// day stays correct in every real-world timezone.
|
|
198
|
+
const d = new Date(year!, month! - 1, day!, 12, 0, 0, 0);
|
|
199
|
+
return d.toISOString();
|
|
200
|
+
}
|