@langwatch/server 3.1.0-beta.1 → 3.1.0-beta.11
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/langwatch_nlp/uv.lock +179 -5
- 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 -6
- package/packages/server/dist/cli.cjs +453 -186
- package/cmd/service/main.go +0 -68
- package/go.mod +0 -117
- package/go.sum +0 -299
- package/pkg/breaker/breaker.go +0 -157
- package/pkg/breaker/breaker_test.go +0 -131
- package/pkg/clog/LICENSE +0 -26
- package/pkg/clog/clog.go +0 -90
- package/pkg/clog/clog_test.go +0 -56
- package/pkg/clog/panic.go +0 -39
- package/pkg/config/LICENSE +0 -26
- package/pkg/config/config.go +0 -86
- package/pkg/config/config_test.go +0 -70
- package/pkg/config/otel.go +0 -50
- package/pkg/config/server.go +0 -61
- package/pkg/config/validate.go +0 -80
- package/pkg/config/validate_test.go +0 -74
- package/pkg/contexts/contexts_test.go +0 -34
- package/pkg/contexts/request_id.go +0 -1
- package/pkg/contexts/service_info.go +0 -33
- package/pkg/errfuncs/errfuncs.go +0 -9
- package/pkg/errfuncs/errfuncs_test.go +0 -28
- package/pkg/forkedcontext/forkedcontext.go +0 -57
- package/pkg/health/health.go +0 -123
- package/pkg/health/health_test.go +0 -84
- package/pkg/herr/LICENSE +0 -26
- package/pkg/herr/code.go +0 -14
- package/pkg/herr/herr.go +0 -112
- package/pkg/herr/herr_test.go +0 -78
- package/pkg/herr/http.go +0 -133
- package/pkg/herr/http_test.go +0 -103
- package/pkg/herr/validate.go +0 -72
- package/pkg/herr/validate_test.go +0 -75
- package/pkg/httpmiddleware/bearer.go +0 -47
- package/pkg/httpmiddleware/httputil_test.go +0 -167
- package/pkg/httpmiddleware/inflight.go +0 -23
- package/pkg/httpmiddleware/maxbody.go +0 -30
- package/pkg/httpmiddleware/recover.go +0 -38
- package/pkg/httpmiddleware/requestid.go +0 -40
- package/pkg/httpmiddleware/telemetry.go +0 -96
- package/pkg/httpmiddleware/version.go +0 -16
- package/pkg/jwtverify/verifier.go +0 -72
- package/pkg/jwtverify/verifier_test.go +0 -134
- package/pkg/ksuid/LICENSE +0 -26
- package/pkg/ksuid/ksuid.go +0 -157
- package/pkg/ksuid/ksuid_test.go +0 -107
- package/pkg/ksuid/resources.go +0 -13
- package/pkg/lifecycle/group.go +0 -175
- package/pkg/lifecycle/group_test.go +0 -236
- package/pkg/lifecycle/service.go +0 -112
- package/pkg/netprobe/netprobe.go +0 -89
- package/pkg/netprobe/netprobe_test.go +0 -55
- package/pkg/otelsetup/otelsetup.go +0 -226
- package/pkg/otelsetup/otelsetup_test.go +0 -130
- package/pkg/ptr/LICENSE +0 -26
- package/pkg/ptr/ptr.go +0 -34
- package/pkg/ptr/ptr_test.go +0 -66
- package/pkg/retry/bench_test.go +0 -67
- package/pkg/retry/retry.go +0 -188
- package/pkg/retry/retry_test.go +0 -222
- package/pkg/slicefuncs/LICENSE +0 -26
- package/pkg/slicefuncs/slicefuncs.go +0 -10
- package/pkg/slicefuncs/slicefuncs_test.go +0 -29
- package/pkg/stacktrace/LICENSE +0 -26
- package/pkg/stacktrace/frames.go +0 -77
- package/pkg/stacktrace/frames_test.go +0 -73
- package/services/aigateway/BENCHMARKS.md +0 -110
- package/services/aigateway/README.md +0 -156
- package/services/aigateway/adapters/authresolver/bench_test.go +0 -13
- package/services/aigateway/adapters/authresolver/redis.go +0 -61
- package/services/aigateway/adapters/authresolver/service.go +0 -442
- package/services/aigateway/adapters/authresolver/service_test.go +0 -435
- package/services/aigateway/adapters/budget/bench_test.go +0 -50
- package/services/aigateway/adapters/budget/budget.go +0 -59
- package/services/aigateway/adapters/cacherules/evaluator.go +0 -134
- package/services/aigateway/adapters/cacherules/evaluator_test.go +0 -207
- package/services/aigateway/adapters/controlplane/bench_test.go +0 -40
- package/services/aigateway/adapters/controlplane/client.go +0 -213
- package/services/aigateway/adapters/controlplane/client_test.go +0 -73
- package/services/aigateway/adapters/controlplane/config_wire.go +0 -310
- package/services/aigateway/adapters/controlplane/guardrails.go +0 -88
- package/services/aigateway/adapters/controlplane/signer.go +0 -95
- package/services/aigateway/adapters/controlplane/signer_test.go +0 -64
- package/services/aigateway/adapters/customertracebridge/context.go +0 -48
- package/services/aigateway/adapters/customertracebridge/context_test.go +0 -24
- package/services/aigateway/adapters/customertracebridge/emitter.go +0 -329
- package/services/aigateway/adapters/customertracebridge/emitter_test.go +0 -93
- package/services/aigateway/adapters/customertracebridge/registry.go +0 -82
- package/services/aigateway/adapters/customertracebridge/transport.go +0 -122
- package/services/aigateway/adapters/gatewaytracer/attrs.go +0 -28
- package/services/aigateway/adapters/gatewaytracer/attrs_genai.go +0 -24
- package/services/aigateway/adapters/gatewaytracer/headers.go +0 -8
- package/services/aigateway/adapters/gatewaytracer/tracer.go +0 -101
- package/services/aigateway/adapters/httpapi/bench_test.go +0 -83
- package/services/aigateway/adapters/httpapi/middleware.go +0 -123
- package/services/aigateway/adapters/httpapi/router.go +0 -635
- package/services/aigateway/adapters/httpapi/router_test.go +0 -633
- package/services/aigateway/adapters/modelresolver/resolver.go +0 -107
- package/services/aigateway/adapters/modelresolver/resolver_test.go +0 -140
- package/services/aigateway/adapters/policy/matcher.go +0 -250
- package/services/aigateway/adapters/policy/matcher_test.go +0 -124
- package/services/aigateway/adapters/providers/bifrost.go +0 -798
- package/services/aigateway/adapters/providers/bifrost_parser.go +0 -201
- package/services/aigateway/adapters/providers/bifrost_test.go +0 -181
- package/services/aigateway/adapters/ratelimit/limiter.go +0 -122
- package/services/aigateway/adapters/ratelimit/limiter_test.go +0 -81
- package/services/aigateway/app/app.go +0 -104
- package/services/aigateway/app/dispatch.go +0 -89
- package/services/aigateway/app/dispatch_test.go +0 -475
- package/services/aigateway/app/handlers.go +0 -79
- package/services/aigateway/app/peek_bench_test.go +0 -21
- package/services/aigateway/app/pipeline/bench_test.go +0 -34
- package/services/aigateway/app/pipeline/budget.go +0 -55
- package/services/aigateway/app/pipeline/cache.go +0 -34
- package/services/aigateway/app/pipeline/cachecontrol.go +0 -86
- package/services/aigateway/app/pipeline/cachecontrol_test.go +0 -110
- package/services/aigateway/app/pipeline/guardrail.go +0 -121
- package/services/aigateway/app/pipeline/pipeline.go +0 -159
- package/services/aigateway/app/pipeline/policy.go +0 -23
- package/services/aigateway/app/pipeline/ratelimit.go +0 -21
- package/services/aigateway/app/pipeline/rawframing_test.go +0 -67
- package/services/aigateway/app/pipeline/resolve.go +0 -44
- package/services/aigateway/app/pipeline/trace.go +0 -129
- package/services/aigateway/app/ports.go +0 -61
- package/services/aigateway/cmd/root.go +0 -42
- package/services/aigateway/config.go +0 -86
- package/services/aigateway/deps.go +0 -177
- package/services/aigateway/domain/bundle.go +0 -203
- package/services/aigateway/domain/errors.go +0 -23
- package/services/aigateway/domain/model.go +0 -24
- package/services/aigateway/domain/provider.go +0 -38
- package/services/aigateway/domain/request.go +0 -65
- package/services/aigateway/domain/response.go +0 -56
- package/services/aigateway/domain/verdict.go +0 -55
- package/services/aigateway/serve.go +0 -45
- package/services/aigateway/tests/matrix/README.md +0 -71
- package/services/aigateway/tests/matrix/anthropic_test.go +0 -61
- package/services/aigateway/tests/matrix/azure_test.go +0 -52
- package/services/aigateway/tests/matrix/bedrock_test.go +0 -69
- package/services/aigateway/tests/matrix/gemini_test.go +0 -117
- package/services/aigateway/tests/matrix/matrix_test.go +0 -601
- package/services/aigateway/tests/matrix/openai_test.go +0 -66
- package/services/aigateway/tests/matrix/vertex_test.go +0 -160
|
@@ -0,0 +1,900 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
+
|
|
3
|
+
vi.mock("../langwatch-api.js", () => ({
|
|
4
|
+
searchTraces: vi.fn(),
|
|
5
|
+
getTraceById: vi.fn(),
|
|
6
|
+
getAnalyticsTimeseries: vi.fn(),
|
|
7
|
+
listPrompts: vi.fn(),
|
|
8
|
+
getPrompt: vi.fn(),
|
|
9
|
+
createPrompt: vi.fn(),
|
|
10
|
+
updatePrompt: vi.fn(),
|
|
11
|
+
assignPromptTag: vi.fn(),
|
|
12
|
+
listPromptTags: vi.fn(),
|
|
13
|
+
createPromptTag: vi.fn(),
|
|
14
|
+
renamePromptTag: vi.fn(),
|
|
15
|
+
deletePromptTag: vi.fn(),
|
|
16
|
+
}));
|
|
17
|
+
|
|
18
|
+
import {
|
|
19
|
+
searchTraces,
|
|
20
|
+
getTraceById,
|
|
21
|
+
getAnalyticsTimeseries,
|
|
22
|
+
listPrompts,
|
|
23
|
+
getPrompt,
|
|
24
|
+
createPrompt,
|
|
25
|
+
updatePrompt,
|
|
26
|
+
assignPromptTag,
|
|
27
|
+
listPromptTags,
|
|
28
|
+
createPromptTag,
|
|
29
|
+
renamePromptTag,
|
|
30
|
+
deletePromptTag,
|
|
31
|
+
type PromptSummary,
|
|
32
|
+
} from "../langwatch-api.js";
|
|
33
|
+
|
|
34
|
+
import { handleSearchTraces } from "../tools/search-traces.js";
|
|
35
|
+
import { handleGetTrace } from "../tools/get-trace.js";
|
|
36
|
+
import { handleGetAnalytics } from "../tools/get-analytics.js";
|
|
37
|
+
import { handleListPrompts } from "../tools/list-prompts.js";
|
|
38
|
+
import { handleGetPrompt } from "../tools/get-prompt.js";
|
|
39
|
+
import { handleCreatePrompt } from "../tools/create-prompt.js";
|
|
40
|
+
import { handleUpdatePrompt } from "../tools/update-prompt.js";
|
|
41
|
+
import { handleAssignPromptTag } from "../tools/assign-prompt-tag.js";
|
|
42
|
+
import { handleListPromptTags } from "../tools/list-prompt-tags.js";
|
|
43
|
+
import { handleCreatePromptTag } from "../tools/create-prompt-tag.js";
|
|
44
|
+
import { handleRenamePromptTag } from "../tools/rename-prompt-tag.js";
|
|
45
|
+
import { handleDeletePromptTag } from "../tools/delete-prompt-tag.js";
|
|
46
|
+
|
|
47
|
+
const mockSearchTraces = vi.mocked(searchTraces);
|
|
48
|
+
const mockGetTraceById = vi.mocked(getTraceById);
|
|
49
|
+
const mockGetAnalytics = vi.mocked(getAnalyticsTimeseries);
|
|
50
|
+
const mockListPrompts = vi.mocked(listPrompts);
|
|
51
|
+
const mockGetPrompt = vi.mocked(getPrompt);
|
|
52
|
+
const mockCreatePrompt = vi.mocked(createPrompt);
|
|
53
|
+
const mockUpdatePrompt = vi.mocked(updatePrompt);
|
|
54
|
+
const mockAssignPromptTag = vi.mocked(assignPromptTag);
|
|
55
|
+
const mockListPromptTags = vi.mocked(listPromptTags);
|
|
56
|
+
const mockCreatePromptTag = vi.mocked(createPromptTag);
|
|
57
|
+
const mockRenamePromptTag = vi.mocked(renamePromptTag);
|
|
58
|
+
const mockDeletePromptTag = vi.mocked(deletePromptTag);
|
|
59
|
+
|
|
60
|
+
beforeEach(() => {
|
|
61
|
+
vi.clearAllMocks();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe("handleSearchTraces()", () => {
|
|
65
|
+
describe("when traces are found with formatted_trace (digest mode)", () => {
|
|
66
|
+
it("shows formatted digest per trace", async () => {
|
|
67
|
+
mockSearchTraces.mockResolvedValue({
|
|
68
|
+
traces: [
|
|
69
|
+
{
|
|
70
|
+
trace_id: "trace-1",
|
|
71
|
+
formatted_trace: "LLM Call [llm] 500ms\n Input: Hello\n Output: Hi",
|
|
72
|
+
input: { value: "Hello world" },
|
|
73
|
+
output: { value: "Hi there" },
|
|
74
|
+
timestamps: { started_at: "2024-01-01T00:00:00Z" },
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
pagination: { totalHits: 1 },
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
const result = await handleSearchTraces({});
|
|
81
|
+
|
|
82
|
+
expect(result).toContain("Found 1 traces:");
|
|
83
|
+
expect(result).toContain("### Trace: trace-1");
|
|
84
|
+
expect(result).toContain("LLM Call [llm] 500ms");
|
|
85
|
+
expect(result).toContain("**Time**: 2024-01-01T00:00:00Z");
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
describe("when traces have no formatted_trace", () => {
|
|
90
|
+
it("falls back to input/output truncation", async () => {
|
|
91
|
+
mockSearchTraces.mockResolvedValue({
|
|
92
|
+
traces: [
|
|
93
|
+
{
|
|
94
|
+
trace_id: "trace-2",
|
|
95
|
+
input: { value: "Hello world" },
|
|
96
|
+
output: { value: "Hi there" },
|
|
97
|
+
},
|
|
98
|
+
],
|
|
99
|
+
pagination: { totalHits: 1 },
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
const result = await handleSearchTraces({});
|
|
103
|
+
|
|
104
|
+
expect(result).toContain("**Input**: Hello world");
|
|
105
|
+
expect(result).toContain("**Output**: Hi there");
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("truncates long input/output to 100 characters", async () => {
|
|
109
|
+
const longText = "x".repeat(150);
|
|
110
|
+
mockSearchTraces.mockResolvedValue({
|
|
111
|
+
traces: [
|
|
112
|
+
{
|
|
113
|
+
trace_id: "trace-2",
|
|
114
|
+
input: { value: longText },
|
|
115
|
+
output: { value: longText },
|
|
116
|
+
},
|
|
117
|
+
],
|
|
118
|
+
pagination: { totalHits: 1 },
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
const result = await handleSearchTraces({});
|
|
122
|
+
|
|
123
|
+
expect(result).toContain("x".repeat(100) + "...");
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
describe("when format is json", () => {
|
|
128
|
+
it("returns raw JSON string", async () => {
|
|
129
|
+
const responseData = {
|
|
130
|
+
traces: [{ trace_id: "trace-1", input: { value: "Hello" } }],
|
|
131
|
+
pagination: { totalHits: 1 },
|
|
132
|
+
};
|
|
133
|
+
mockSearchTraces.mockResolvedValue(responseData);
|
|
134
|
+
|
|
135
|
+
const result = await handleSearchTraces({ format: "json" });
|
|
136
|
+
|
|
137
|
+
expect(JSON.parse(result)).toEqual(responseData);
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it("includes scroll ID when more results are available", async () => {
|
|
142
|
+
mockSearchTraces.mockResolvedValue({
|
|
143
|
+
traces: [{ trace_id: "trace-1", input: { value: "" }, output: { value: "" } }],
|
|
144
|
+
pagination: { totalHits: 100, scrollId: "scroll-abc" },
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
const result = await handleSearchTraces({});
|
|
148
|
+
|
|
149
|
+
expect(result).toContain('scrollId: "scroll-abc"');
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it("shows error information when trace has errors", async () => {
|
|
153
|
+
mockSearchTraces.mockResolvedValue({
|
|
154
|
+
traces: [
|
|
155
|
+
{
|
|
156
|
+
trace_id: "trace-err",
|
|
157
|
+
input: { value: "" },
|
|
158
|
+
output: { value: "" },
|
|
159
|
+
error: { message: "timeout" },
|
|
160
|
+
},
|
|
161
|
+
],
|
|
162
|
+
pagination: { totalHits: 1 },
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
const result = await handleSearchTraces({});
|
|
166
|
+
|
|
167
|
+
expect(result).toContain("**Error**");
|
|
168
|
+
expect(result).toContain("timeout");
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
describe("when no traces are found", () => {
|
|
172
|
+
it("returns a no-results message", async () => {
|
|
173
|
+
mockSearchTraces.mockResolvedValue({ traces: [] });
|
|
174
|
+
|
|
175
|
+
const result = await handleSearchTraces({});
|
|
176
|
+
|
|
177
|
+
expect(result).toBe("No traces found matching your query.");
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
describe("when relative dates are provided", () => {
|
|
182
|
+
it("passes parsed timestamps to the API", async () => {
|
|
183
|
+
mockSearchTraces.mockResolvedValue({ traces: [] });
|
|
184
|
+
|
|
185
|
+
await handleSearchTraces({ startDate: "7d", endDate: "1d" });
|
|
186
|
+
|
|
187
|
+
const call = mockSearchTraces.mock.calls[0]![0] as any;
|
|
188
|
+
expect(call.startDate).toBeTypeOf("number");
|
|
189
|
+
expect(call.endDate).toBeTypeOf("number");
|
|
190
|
+
expect(call.startDate).toBeLessThan(call.endDate);
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
describe("when pageSize is specified", () => {
|
|
195
|
+
it("passes pageSize to the API", async () => {
|
|
196
|
+
mockSearchTraces.mockResolvedValue({ traces: [] });
|
|
197
|
+
|
|
198
|
+
await handleSearchTraces({ pageSize: 50 });
|
|
199
|
+
|
|
200
|
+
const call = mockSearchTraces.mock.calls[0]![0] as any;
|
|
201
|
+
expect(call.pageSize).toBe(50);
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
describe("when pageSize is not specified", () => {
|
|
206
|
+
it("defaults to 25", async () => {
|
|
207
|
+
mockSearchTraces.mockResolvedValue({ traces: [] });
|
|
208
|
+
|
|
209
|
+
await handleSearchTraces({});
|
|
210
|
+
|
|
211
|
+
const call = mockSearchTraces.mock.calls[0]![0] as any;
|
|
212
|
+
expect(call.pageSize).toBe(25);
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it("passes format to the API", async () => {
|
|
217
|
+
mockSearchTraces.mockResolvedValue({ traces: [] });
|
|
218
|
+
|
|
219
|
+
await handleSearchTraces({ format: "json" });
|
|
220
|
+
|
|
221
|
+
const call = mockSearchTraces.mock.calls[0]![0] as any;
|
|
222
|
+
expect(call.format).toBe("json");
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
it("defaults format to digest", async () => {
|
|
226
|
+
mockSearchTraces.mockResolvedValue({ traces: [] });
|
|
227
|
+
|
|
228
|
+
await handleSearchTraces({});
|
|
229
|
+
|
|
230
|
+
const call = mockSearchTraces.mock.calls[0]![0] as any;
|
|
231
|
+
expect(call.format).toBe("digest");
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it("includes usage tip about get_trace, format, and discover_schema", async () => {
|
|
235
|
+
mockSearchTraces.mockResolvedValue({
|
|
236
|
+
traces: [{ trace_id: "t1", input: { value: "" }, output: { value: "" } }],
|
|
237
|
+
pagination: { totalHits: 1 },
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
const result = await handleSearchTraces({});
|
|
241
|
+
|
|
242
|
+
expect(result).toContain("get_trace");
|
|
243
|
+
expect(result).toContain("discover_schema");
|
|
244
|
+
expect(result).toContain('"json"');
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
describe("handleGetTrace()", () => {
|
|
249
|
+
describe("when trace has formatted_trace (digest mode)", () => {
|
|
250
|
+
it("shows the formatted digest", async () => {
|
|
251
|
+
mockGetTraceById.mockResolvedValue({
|
|
252
|
+
trace_id: "trace-abc",
|
|
253
|
+
formatted_trace: "Root [server] 1200ms\n LLM Call [llm] 800ms\n Input: Hello\n Output: Hi there",
|
|
254
|
+
timestamps: {
|
|
255
|
+
started_at: "2024-01-01T00:00:00Z",
|
|
256
|
+
updated_at: "2024-01-01T00:01:00Z",
|
|
257
|
+
},
|
|
258
|
+
metadata: { user_id: "user-123" },
|
|
259
|
+
evaluations: [
|
|
260
|
+
{ name: "Toxicity", passed: true, score: 0.95 },
|
|
261
|
+
],
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
const result = await handleGetTrace({ traceId: "trace-abc" });
|
|
265
|
+
|
|
266
|
+
expect(result).toContain("# Trace: trace-abc");
|
|
267
|
+
expect(result).toContain("**Started**: 2024-01-01T00:00:00Z");
|
|
268
|
+
expect(result).toContain("**User**: user-123");
|
|
269
|
+
expect(result).toContain("## Evaluations");
|
|
270
|
+
expect(result).toContain("**Toxicity**: PASSED (score: 0.95)");
|
|
271
|
+
expect(result).toContain("## Trace Details");
|
|
272
|
+
expect(result).toContain("Root [server] 1200ms");
|
|
273
|
+
expect(result).toContain("LLM Call [llm] 800ms");
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
it("includes tip about json format", async () => {
|
|
277
|
+
mockGetTraceById.mockResolvedValue({
|
|
278
|
+
trace_id: "trace-abc",
|
|
279
|
+
formatted_trace: "some digest",
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
const result = await handleGetTrace({ traceId: "trace-abc" });
|
|
283
|
+
|
|
284
|
+
expect(result).toContain('"json"');
|
|
285
|
+
expect(result).toContain("get_trace");
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
describe("when format is json", () => {
|
|
290
|
+
it("returns raw JSON string", async () => {
|
|
291
|
+
const responseData = {
|
|
292
|
+
trace_id: "trace-abc",
|
|
293
|
+
spans: [{ span_id: "s1", name: "LLM Call" }],
|
|
294
|
+
evaluations: [],
|
|
295
|
+
metadata: {},
|
|
296
|
+
};
|
|
297
|
+
mockGetTraceById.mockResolvedValue(responseData);
|
|
298
|
+
|
|
299
|
+
const result = await handleGetTrace({ traceId: "trace-abc", format: "json" });
|
|
300
|
+
|
|
301
|
+
expect(JSON.parse(result)).toEqual(responseData);
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
it("passes json format to the API", async () => {
|
|
305
|
+
mockGetTraceById.mockResolvedValue({ trace_id: "trace-abc" });
|
|
306
|
+
|
|
307
|
+
await handleGetTrace({ traceId: "trace-abc", format: "json" });
|
|
308
|
+
|
|
309
|
+
expect(mockGetTraceById).toHaveBeenCalledWith("trace-abc", "json");
|
|
310
|
+
});
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
describe("when trace has metadata fields", () => {
|
|
314
|
+
it("formats metadata fields", async () => {
|
|
315
|
+
mockGetTraceById.mockResolvedValue({
|
|
316
|
+
trace_id: "trace-abc",
|
|
317
|
+
metadata: {
|
|
318
|
+
user_id: "user-123",
|
|
319
|
+
thread_id: "thread-456",
|
|
320
|
+
customer_id: "cust-789",
|
|
321
|
+
labels: ["production", "important"],
|
|
322
|
+
},
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
const result = await handleGetTrace({ traceId: "trace-abc" });
|
|
326
|
+
|
|
327
|
+
expect(result).toContain("**User**: user-123");
|
|
328
|
+
expect(result).toContain("**Thread**: thread-456");
|
|
329
|
+
expect(result).toContain("**Customer**: cust-789");
|
|
330
|
+
expect(result).toContain("**Labels**: production, important");
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
describe("when trace has evaluations", () => {
|
|
335
|
+
it("formats evaluations", async () => {
|
|
336
|
+
mockGetTraceById.mockResolvedValue({
|
|
337
|
+
trace_id: "trace-abc",
|
|
338
|
+
evaluations: [
|
|
339
|
+
{ name: "Toxicity", passed: true, score: 0.95 },
|
|
340
|
+
{ evaluator_id: "eval-2", passed: false, label: "bad" },
|
|
341
|
+
],
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
const result = await handleGetTrace({ traceId: "trace-abc" });
|
|
345
|
+
|
|
346
|
+
expect(result).toContain("## Evaluations");
|
|
347
|
+
expect(result).toContain("**Toxicity**: PASSED (score: 0.95)");
|
|
348
|
+
expect(result).toContain("**eval-2**: FAILED");
|
|
349
|
+
expect(result).toContain("[bad]");
|
|
350
|
+
});
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
describe("when trace has no formatted_trace", () => {
|
|
354
|
+
it("still renders header and metadata", async () => {
|
|
355
|
+
mockGetTraceById.mockResolvedValue({
|
|
356
|
+
trace_id: "trace-abc",
|
|
357
|
+
timestamps: { started_at: "2024-01-01" },
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
const result = await handleGetTrace({ traceId: "trace-abc" });
|
|
361
|
+
|
|
362
|
+
expect(result).toContain("# Trace: trace-abc");
|
|
363
|
+
expect(result).toContain("**Started**: 2024-01-01");
|
|
364
|
+
expect(result).not.toContain("## Trace Details");
|
|
365
|
+
});
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
describe("when digest format is used (default)", () => {
|
|
369
|
+
it("passes digest format to the API", async () => {
|
|
370
|
+
mockGetTraceById.mockResolvedValue({ trace_id: "trace-abc" });
|
|
371
|
+
|
|
372
|
+
await handleGetTrace({ traceId: "trace-abc" });
|
|
373
|
+
|
|
374
|
+
expect(mockGetTraceById).toHaveBeenCalledWith("trace-abc", "digest");
|
|
375
|
+
});
|
|
376
|
+
});
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
describe("handleGetAnalytics()", () => {
|
|
380
|
+
describe("when data is available", () => {
|
|
381
|
+
it("formats a markdown table with date and value", async () => {
|
|
382
|
+
mockGetAnalytics.mockResolvedValue({
|
|
383
|
+
currentPeriod: [
|
|
384
|
+
{ date: "2024-01-01", metric_0: 42 },
|
|
385
|
+
{ date: "2024-01-02", metric_0: 55 },
|
|
386
|
+
],
|
|
387
|
+
previousPeriod: [],
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
const result = await handleGetAnalytics({
|
|
391
|
+
metric: "performance.completion_time",
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
expect(result).toContain(
|
|
395
|
+
"# Analytics: performance.completion_time (avg)"
|
|
396
|
+
);
|
|
397
|
+
expect(result).toContain("| Date | Value |");
|
|
398
|
+
expect(result).toContain("| 2024-01-01 | 42 |");
|
|
399
|
+
expect(result).toContain("| 2024-01-02 | 55 |");
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
it("shows groupBy when provided", async () => {
|
|
403
|
+
mockGetAnalytics.mockResolvedValue({ currentPeriod: [], previousPeriod: [] });
|
|
404
|
+
|
|
405
|
+
const result = await handleGetAnalytics({
|
|
406
|
+
metric: "metadata.trace_id",
|
|
407
|
+
groupBy: "metadata.model",
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
expect(result).toContain("Grouped by: metadata.model");
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
it("formats grouped data with group column", async () => {
|
|
414
|
+
mockGetAnalytics.mockResolvedValue({
|
|
415
|
+
currentPeriod: [
|
|
416
|
+
{
|
|
417
|
+
date: "2024-01-01",
|
|
418
|
+
"sentiment.thumbs_up_down": {
|
|
419
|
+
"Thumbs Up": { "0/metadata.trace_id/cardinality": 10 },
|
|
420
|
+
"Thumbs Down": { "0/metadata.trace_id/cardinality": 5 },
|
|
421
|
+
},
|
|
422
|
+
},
|
|
423
|
+
],
|
|
424
|
+
previousPeriod: [],
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
const result = await handleGetAnalytics({
|
|
428
|
+
metric: "metadata.trace_id",
|
|
429
|
+
aggregation: "cardinality",
|
|
430
|
+
groupBy: "sentiment.thumbs_up_down",
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
expect(result).toContain("| Date | Group | Value |");
|
|
434
|
+
expect(result).toContain("| 2024-01-01 | Thumbs Up | 10 |");
|
|
435
|
+
expect(result).toContain("| 2024-01-01 | Thumbs Down | 5 |");
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
it("uses the specified aggregation", async () => {
|
|
439
|
+
mockGetAnalytics.mockResolvedValue({ currentPeriod: [], previousPeriod: [] });
|
|
440
|
+
|
|
441
|
+
const result = await handleGetAnalytics({
|
|
442
|
+
metric: "performance.total_cost",
|
|
443
|
+
aggregation: "sum",
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
expect(result).toContain("(sum)");
|
|
447
|
+
const call = mockGetAnalytics.mock.calls[0]![0] as any;
|
|
448
|
+
expect(call.series[0].aggregation).toBe("sum");
|
|
449
|
+
});
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
describe("when no data is available", () => {
|
|
453
|
+
it("returns a no-data message", async () => {
|
|
454
|
+
mockGetAnalytics.mockResolvedValue({ currentPeriod: [], previousPeriod: [] });
|
|
455
|
+
|
|
456
|
+
const result = await handleGetAnalytics({
|
|
457
|
+
metric: "performance.completion_time",
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
expect(result).toContain("No data available for this period.");
|
|
461
|
+
});
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
describe("when metric has no dot", () => {
|
|
465
|
+
it("defaults category to metadata", async () => {
|
|
466
|
+
mockGetAnalytics.mockResolvedValue({ currentPeriod: [], previousPeriod: [] });
|
|
467
|
+
|
|
468
|
+
await handleGetAnalytics({ metric: "trace_id" });
|
|
469
|
+
|
|
470
|
+
const call = mockGetAnalytics.mock.calls[0]![0] as any;
|
|
471
|
+
expect(call.series[0].metric).toBe("metadata.trace_id");
|
|
472
|
+
});
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
it("includes discover_schema tip", async () => {
|
|
476
|
+
mockGetAnalytics.mockResolvedValue({ currentPeriod: [], previousPeriod: [] });
|
|
477
|
+
|
|
478
|
+
const result = await handleGetAnalytics({
|
|
479
|
+
metric: "performance.completion_time",
|
|
480
|
+
});
|
|
481
|
+
|
|
482
|
+
expect(result).toContain("discover_schema");
|
|
483
|
+
});
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
describe("handleListPrompts()", () => {
|
|
487
|
+
describe("when prompts exist", () => {
|
|
488
|
+
it("formats a markdown table with prompt details", async () => {
|
|
489
|
+
mockListPrompts.mockResolvedValue([
|
|
490
|
+
{
|
|
491
|
+
handle: "greeting",
|
|
492
|
+
name: "Greeting Prompt",
|
|
493
|
+
latestVersionNumber: 3,
|
|
494
|
+
},
|
|
495
|
+
{
|
|
496
|
+
id: "p2",
|
|
497
|
+
name: "Summary",
|
|
498
|
+
version: 1,
|
|
499
|
+
},
|
|
500
|
+
]);
|
|
501
|
+
|
|
502
|
+
const result = await handleListPrompts();
|
|
503
|
+
|
|
504
|
+
expect(result).toContain("# Prompts (2 total)");
|
|
505
|
+
expect(result).toContain("| Handle | Name | Latest Version |");
|
|
506
|
+
expect(result).toContain("| greeting | Greeting Prompt | v3 |");
|
|
507
|
+
expect(result).toContain("| p2 | Summary | v1 |");
|
|
508
|
+
});
|
|
509
|
+
});
|
|
510
|
+
|
|
511
|
+
describe("when no prompts exist", () => {
|
|
512
|
+
it("returns a no-prompts message", async () => {
|
|
513
|
+
mockListPrompts.mockResolvedValue([]);
|
|
514
|
+
|
|
515
|
+
const result = await handleListPrompts();
|
|
516
|
+
|
|
517
|
+
expect(result).toBe("No prompts found in this project.");
|
|
518
|
+
});
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
describe("when API returns non-array", () => {
|
|
522
|
+
it("returns a no-prompts message", async () => {
|
|
523
|
+
mockListPrompts.mockResolvedValue(null as unknown as PromptSummary[]);
|
|
524
|
+
|
|
525
|
+
const result = await handleListPrompts();
|
|
526
|
+
|
|
527
|
+
expect(result).toBe("No prompts found in this project.");
|
|
528
|
+
});
|
|
529
|
+
});
|
|
530
|
+
|
|
531
|
+
it("includes usage tip about platform_get_prompt", async () => {
|
|
532
|
+
mockListPrompts.mockResolvedValue([
|
|
533
|
+
{ handle: "test", name: "Test", latestVersionNumber: 1 },
|
|
534
|
+
]);
|
|
535
|
+
|
|
536
|
+
const result = await handleListPrompts();
|
|
537
|
+
|
|
538
|
+
expect(result).toContain("platform_get_prompt");
|
|
539
|
+
});
|
|
540
|
+
});
|
|
541
|
+
|
|
542
|
+
describe("handleGetPrompt()", () => {
|
|
543
|
+
describe("when prompt has full details", () => {
|
|
544
|
+
it("formats the prompt header and metadata", async () => {
|
|
545
|
+
mockGetPrompt.mockResolvedValue({
|
|
546
|
+
id: "p1",
|
|
547
|
+
handle: "greeting",
|
|
548
|
+
name: "Greeting Prompt",
|
|
549
|
+
latestVersionNumber: 2,
|
|
550
|
+
versions: [
|
|
551
|
+
{
|
|
552
|
+
version: 2,
|
|
553
|
+
model: "openai/gpt-4o",
|
|
554
|
+
messages: [
|
|
555
|
+
{ role: "system", content: "You are a greeter." },
|
|
556
|
+
{ role: "user", content: "Hello!" },
|
|
557
|
+
],
|
|
558
|
+
commitMessage: "Updated greeting",
|
|
559
|
+
},
|
|
560
|
+
{
|
|
561
|
+
version: 1,
|
|
562
|
+
commitMessage: "Initial version",
|
|
563
|
+
},
|
|
564
|
+
],
|
|
565
|
+
});
|
|
566
|
+
|
|
567
|
+
const result = await handleGetPrompt({ idOrHandle: "greeting" });
|
|
568
|
+
|
|
569
|
+
expect(result).toContain("# Prompt: Greeting Prompt");
|
|
570
|
+
expect(result).toContain("**Handle**: greeting");
|
|
571
|
+
expect(result).toContain("**ID**: p1");
|
|
572
|
+
expect(result).toContain("**Latest Version**: v2");
|
|
573
|
+
expect(result).toContain("**Model**: openai/gpt-4o");
|
|
574
|
+
expect(result).not.toContain("**Provider**");
|
|
575
|
+
});
|
|
576
|
+
|
|
577
|
+
it("formats messages", async () => {
|
|
578
|
+
mockGetPrompt.mockResolvedValue({
|
|
579
|
+
name: "Test",
|
|
580
|
+
versions: [
|
|
581
|
+
{
|
|
582
|
+
messages: [
|
|
583
|
+
{ role: "system", content: "You are helpful." },
|
|
584
|
+
{ role: "user", content: "Hi there" },
|
|
585
|
+
],
|
|
586
|
+
},
|
|
587
|
+
],
|
|
588
|
+
});
|
|
589
|
+
|
|
590
|
+
const result = await handleGetPrompt({ idOrHandle: "test" });
|
|
591
|
+
|
|
592
|
+
expect(result).toContain("## Messages");
|
|
593
|
+
expect(result).toContain("### system\nYou are helpful.");
|
|
594
|
+
expect(result).toContain("### user\nHi there");
|
|
595
|
+
});
|
|
596
|
+
|
|
597
|
+
it("formats version history", async () => {
|
|
598
|
+
mockGetPrompt.mockResolvedValue({
|
|
599
|
+
name: "Test",
|
|
600
|
+
versions: [
|
|
601
|
+
{ version: 3, commitMessage: "Third update" },
|
|
602
|
+
{ version: 2, commitMessage: "Second update" },
|
|
603
|
+
{ version: 1, commitMessage: "Initial" },
|
|
604
|
+
],
|
|
605
|
+
});
|
|
606
|
+
|
|
607
|
+
const result = await handleGetPrompt({ idOrHandle: "test" });
|
|
608
|
+
|
|
609
|
+
expect(result).toContain("## Version History");
|
|
610
|
+
expect(result).toContain("- **v3**: Third update");
|
|
611
|
+
expect(result).toContain("- **v2**: Second update");
|
|
612
|
+
expect(result).toContain("- **v1**: Initial");
|
|
613
|
+
});
|
|
614
|
+
});
|
|
615
|
+
|
|
616
|
+
describe("when prompt has more than 10 versions", () => {
|
|
617
|
+
it("truncates version history with a count", async () => {
|
|
618
|
+
const versions = Array.from({ length: 12 }, (_, i) => ({
|
|
619
|
+
version: 12 - i,
|
|
620
|
+
commitMessage: `Version ${12 - i}`,
|
|
621
|
+
}));
|
|
622
|
+
|
|
623
|
+
mockGetPrompt.mockResolvedValue({
|
|
624
|
+
name: "Test",
|
|
625
|
+
versions,
|
|
626
|
+
});
|
|
627
|
+
|
|
628
|
+
const result = await handleGetPrompt({ idOrHandle: "test" });
|
|
629
|
+
|
|
630
|
+
expect(result).toContain("... and 2 more versions");
|
|
631
|
+
});
|
|
632
|
+
});
|
|
633
|
+
|
|
634
|
+
describe("when prompt has no versions", () => {
|
|
635
|
+
it("uses prompt-level model config", async () => {
|
|
636
|
+
mockGetPrompt.mockResolvedValue({
|
|
637
|
+
name: "Simple",
|
|
638
|
+
model: "openai/gpt-3.5-turbo",
|
|
639
|
+
messages: [{ role: "system", content: "Be brief." }],
|
|
640
|
+
});
|
|
641
|
+
|
|
642
|
+
const result = await handleGetPrompt({ idOrHandle: "simple" });
|
|
643
|
+
|
|
644
|
+
expect(result).toContain("**Model**: openai/gpt-3.5-turbo");
|
|
645
|
+
expect(result).not.toContain("**Provider**");
|
|
646
|
+
expect(result).toContain("### system\nBe brief.");
|
|
647
|
+
});
|
|
648
|
+
});
|
|
649
|
+
});
|
|
650
|
+
|
|
651
|
+
describe("handleCreatePrompt()", () => {
|
|
652
|
+
describe("when prompt is created successfully", () => {
|
|
653
|
+
it("formats a success message with details", async () => {
|
|
654
|
+
mockCreatePrompt.mockResolvedValue({
|
|
655
|
+
id: "new-id-123",
|
|
656
|
+
handle: "my-prompt",
|
|
657
|
+
name: "My Prompt",
|
|
658
|
+
latestVersionNumber: 1,
|
|
659
|
+
});
|
|
660
|
+
|
|
661
|
+
const result = await handleCreatePrompt({
|
|
662
|
+
name: "My Prompt",
|
|
663
|
+
handle: "my-prompt",
|
|
664
|
+
messages: [{ role: "system", content: "You are helpful." }],
|
|
665
|
+
model: "openai/gpt-4o",
|
|
666
|
+
});
|
|
667
|
+
|
|
668
|
+
expect(result).toContain("Prompt created successfully!");
|
|
669
|
+
expect(result).toContain("**ID**: new-id-123");
|
|
670
|
+
expect(result).toContain("**Handle**: my-prompt");
|
|
671
|
+
expect(result).toContain("**Name**: My Prompt");
|
|
672
|
+
expect(result).toContain("**Model**: openai/gpt-4o");
|
|
673
|
+
expect(result).toContain("**Version**: v1");
|
|
674
|
+
});
|
|
675
|
+
|
|
676
|
+
it("generates handle from name when handle is not provided", async () => {
|
|
677
|
+
mockCreatePrompt.mockResolvedValue({
|
|
678
|
+
id: "new-id",
|
|
679
|
+
handle: "my-prompt",
|
|
680
|
+
});
|
|
681
|
+
|
|
682
|
+
await handleCreatePrompt({
|
|
683
|
+
name: "My Prompt!",
|
|
684
|
+
messages: [{ role: "system", content: "test" }],
|
|
685
|
+
model: "openai/gpt-4o",
|
|
686
|
+
});
|
|
687
|
+
|
|
688
|
+
expect(mockCreatePrompt).toHaveBeenCalledWith({
|
|
689
|
+
handle: "my-prompt",
|
|
690
|
+
messages: [{ role: "system", content: "test" }],
|
|
691
|
+
model: "openai/gpt-4o",
|
|
692
|
+
});
|
|
693
|
+
});
|
|
694
|
+
|
|
695
|
+
it("uses provided handle instead of generating one", async () => {
|
|
696
|
+
mockCreatePrompt.mockResolvedValue({
|
|
697
|
+
id: "new-id",
|
|
698
|
+
handle: "custom-handle",
|
|
699
|
+
});
|
|
700
|
+
|
|
701
|
+
await handleCreatePrompt({
|
|
702
|
+
name: "My Prompt",
|
|
703
|
+
handle: "custom-handle",
|
|
704
|
+
messages: [{ role: "system", content: "test" }],
|
|
705
|
+
model: "openai/gpt-4o",
|
|
706
|
+
});
|
|
707
|
+
|
|
708
|
+
expect(mockCreatePrompt).toHaveBeenCalledWith({
|
|
709
|
+
handle: "custom-handle",
|
|
710
|
+
messages: [{ role: "system", content: "test" }],
|
|
711
|
+
model: "openai/gpt-4o",
|
|
712
|
+
});
|
|
713
|
+
});
|
|
714
|
+
});
|
|
715
|
+
|
|
716
|
+
describe("when API returns no name", () => {
|
|
717
|
+
it("uses the input name as fallback", async () => {
|
|
718
|
+
mockCreatePrompt.mockResolvedValue({ id: "p1" });
|
|
719
|
+
|
|
720
|
+
const result = await handleCreatePrompt({
|
|
721
|
+
name: "Fallback Name",
|
|
722
|
+
messages: [{ role: "system", content: "test" }],
|
|
723
|
+
model: "openai/gpt-4o",
|
|
724
|
+
});
|
|
725
|
+
|
|
726
|
+
expect(result).toContain("**Name**: Fallback Name");
|
|
727
|
+
});
|
|
728
|
+
});
|
|
729
|
+
});
|
|
730
|
+
|
|
731
|
+
describe("handleUpdatePrompt()", () => {
|
|
732
|
+
describe("when updating a prompt", () => {
|
|
733
|
+
it("formats an update success message", async () => {
|
|
734
|
+
mockUpdatePrompt.mockResolvedValue({
|
|
735
|
+
id: "p1",
|
|
736
|
+
handle: "greeting",
|
|
737
|
+
latestVersionNumber: 2,
|
|
738
|
+
});
|
|
739
|
+
|
|
740
|
+
const result = await handleUpdatePrompt({
|
|
741
|
+
idOrHandle: "greeting",
|
|
742
|
+
messages: [{ role: "system", content: "Updated content" }],
|
|
743
|
+
commitMessage: "Update system prompt",
|
|
744
|
+
});
|
|
745
|
+
|
|
746
|
+
expect(result).toContain("Prompt updated successfully!");
|
|
747
|
+
expect(result).toContain("**ID**: p1");
|
|
748
|
+
expect(result).toContain("**Handle**: greeting");
|
|
749
|
+
expect(result).toContain("**Version**: v2");
|
|
750
|
+
expect(result).toContain("**Commit**: Update system prompt");
|
|
751
|
+
});
|
|
752
|
+
|
|
753
|
+
it("calls updatePrompt API with correct params", async () => {
|
|
754
|
+
mockUpdatePrompt.mockResolvedValue({});
|
|
755
|
+
|
|
756
|
+
await handleUpdatePrompt({
|
|
757
|
+
idOrHandle: "greeting",
|
|
758
|
+
model: "openai/gpt-4o",
|
|
759
|
+
commitMessage: "Switch model",
|
|
760
|
+
});
|
|
761
|
+
|
|
762
|
+
expect(mockUpdatePrompt).toHaveBeenCalledWith("greeting", {
|
|
763
|
+
model: "openai/gpt-4o",
|
|
764
|
+
commitMessage: "Switch model",
|
|
765
|
+
});
|
|
766
|
+
});
|
|
767
|
+
});
|
|
768
|
+
});
|
|
769
|
+
|
|
770
|
+
describe("handleGetPrompt() with tag options", () => {
|
|
771
|
+
describe("when called with a tag", () => {
|
|
772
|
+
it("passes tag option to the API", async () => {
|
|
773
|
+
mockGetPrompt.mockResolvedValue({ name: "Test" });
|
|
774
|
+
|
|
775
|
+
await handleGetPrompt({ idOrHandle: "pizza-prompt", tag: "production" });
|
|
776
|
+
|
|
777
|
+
expect(mockGetPrompt).toHaveBeenCalledWith("pizza-prompt", { version: undefined, tag: "production" });
|
|
778
|
+
});
|
|
779
|
+
});
|
|
780
|
+
});
|
|
781
|
+
|
|
782
|
+
describe("handleCreatePrompt() with tags", () => {
|
|
783
|
+
describe("when called with tags", () => {
|
|
784
|
+
it("includes tags in the output", async () => {
|
|
785
|
+
mockCreatePrompt.mockResolvedValue({ id: "p1", handle: "test" });
|
|
786
|
+
|
|
787
|
+
const result = await handleCreatePrompt({
|
|
788
|
+
name: "Test",
|
|
789
|
+
messages: [{ role: "system", content: "hi" }],
|
|
790
|
+
model: "openai/gpt-5-mini",
|
|
791
|
+
tags: ["production"],
|
|
792
|
+
});
|
|
793
|
+
|
|
794
|
+
expect(result).toContain("**Tags**: production");
|
|
795
|
+
});
|
|
796
|
+
});
|
|
797
|
+
});
|
|
798
|
+
|
|
799
|
+
describe("handleUpdatePrompt() with tags", () => {
|
|
800
|
+
describe("when called with tags", () => {
|
|
801
|
+
it("includes tags in the output", async () => {
|
|
802
|
+
mockUpdatePrompt.mockResolvedValue({ id: "p1", handle: "test", latestVersionNumber: 2 });
|
|
803
|
+
|
|
804
|
+
const result = await handleUpdatePrompt({
|
|
805
|
+
idOrHandle: "test",
|
|
806
|
+
commitMessage: "add tags",
|
|
807
|
+
tags: ["staging"],
|
|
808
|
+
});
|
|
809
|
+
|
|
810
|
+
expect(result).toContain("**Tags**: staging");
|
|
811
|
+
});
|
|
812
|
+
});
|
|
813
|
+
});
|
|
814
|
+
|
|
815
|
+
describe("handleAssignPromptTag()", () => {
|
|
816
|
+
describe("when tag is assigned successfully", () => {
|
|
817
|
+
it("returns a confirmation with prompt, tag, and version", async () => {
|
|
818
|
+
mockAssignPromptTag.mockResolvedValue({ success: true });
|
|
819
|
+
|
|
820
|
+
const result = await handleAssignPromptTag({
|
|
821
|
+
idOrHandle: "pizza-prompt",
|
|
822
|
+
tag: "production",
|
|
823
|
+
versionId: "v123",
|
|
824
|
+
});
|
|
825
|
+
|
|
826
|
+
expect(result).toContain("Tag assigned successfully!");
|
|
827
|
+
expect(result).toContain("**Prompt**: pizza-prompt");
|
|
828
|
+
expect(result).toContain("**Tag**: production");
|
|
829
|
+
expect(result).toContain("**Version ID**: v123");
|
|
830
|
+
});
|
|
831
|
+
});
|
|
832
|
+
});
|
|
833
|
+
|
|
834
|
+
describe("handleListPromptTags()", () => {
|
|
835
|
+
describe("when tags exist", () => {
|
|
836
|
+
it("formats tags as a markdown list", async () => {
|
|
837
|
+
mockListPromptTags.mockResolvedValue([
|
|
838
|
+
{ id: "1", name: "production", createdAt: "2024-01-01" },
|
|
839
|
+
{ id: "2", name: "staging" },
|
|
840
|
+
]);
|
|
841
|
+
|
|
842
|
+
const result = await handleListPromptTags();
|
|
843
|
+
|
|
844
|
+
expect(result).toContain("# Prompt Tags");
|
|
845
|
+
expect(result).toContain("**production**");
|
|
846
|
+
expect(result).toContain("**staging**");
|
|
847
|
+
});
|
|
848
|
+
});
|
|
849
|
+
|
|
850
|
+
describe("when no tags exist", () => {
|
|
851
|
+
it("returns an empty-state message mentioning latest", async () => {
|
|
852
|
+
mockListPromptTags.mockResolvedValue([]);
|
|
853
|
+
|
|
854
|
+
const result = await handleListPromptTags();
|
|
855
|
+
|
|
856
|
+
expect(result).toContain("No prompt tags found");
|
|
857
|
+
expect(result).toContain("`latest`");
|
|
858
|
+
});
|
|
859
|
+
});
|
|
860
|
+
});
|
|
861
|
+
|
|
862
|
+
describe("handleCreatePromptTag()", () => {
|
|
863
|
+
describe("when tag is created successfully", () => {
|
|
864
|
+
it("returns a confirmation with the tag name", async () => {
|
|
865
|
+
mockCreatePromptTag.mockResolvedValue({ id: "t1", name: "canary" });
|
|
866
|
+
|
|
867
|
+
const result = await handleCreatePromptTag({ name: "canary" });
|
|
868
|
+
|
|
869
|
+
expect(result).toContain("Tag created successfully!");
|
|
870
|
+
expect(result).toContain("**Name**: canary");
|
|
871
|
+
});
|
|
872
|
+
});
|
|
873
|
+
});
|
|
874
|
+
|
|
875
|
+
describe("handleRenamePromptTag()", () => {
|
|
876
|
+
describe("when tag is renamed successfully", () => {
|
|
877
|
+
it("returns a confirmation with old and new names", async () => {
|
|
878
|
+
mockRenamePromptTag.mockResolvedValue({ id: "t1", name: "preview" });
|
|
879
|
+
|
|
880
|
+
const result = await handleRenamePromptTag({ tag: "canary", name: "preview" });
|
|
881
|
+
|
|
882
|
+
expect(result).toContain("Tag renamed successfully!");
|
|
883
|
+
expect(result).toContain("**Old name**: canary");
|
|
884
|
+
expect(result).toContain("**New name**: preview");
|
|
885
|
+
});
|
|
886
|
+
});
|
|
887
|
+
});
|
|
888
|
+
|
|
889
|
+
describe("handleDeletePromptTag()", () => {
|
|
890
|
+
describe("when tag is deleted successfully", () => {
|
|
891
|
+
it("returns a confirmation with the tag name", async () => {
|
|
892
|
+
mockDeletePromptTag.mockResolvedValue(null);
|
|
893
|
+
|
|
894
|
+
const result = await handleDeletePromptTag({ tag: "canary" });
|
|
895
|
+
|
|
896
|
+
expect(result).toContain("Tag deleted successfully!");
|
|
897
|
+
expect(result).toContain("**Tag**: canary");
|
|
898
|
+
});
|
|
899
|
+
});
|
|
900
|
+
});
|