@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.
Files changed (471) hide show
  1. package/langwatch/ee/admin/ImpersonationBanner.tsx +61 -0
  2. package/langwatch/ee/admin/ImpersonationSwitchBackMenuItem.tsx +30 -0
  3. package/langwatch/ee/admin/__tests__/ImpersonationBanner.integration.test.tsx +82 -0
  4. package/langwatch/ee/admin/__tests__/impersonation.service.unit.test.ts +231 -0
  5. package/langwatch/ee/admin/backoffice/BackofficeTable.tsx +200 -0
  6. package/langwatch/ee/admin/backoffice/__tests__/adminClient.unit.test.ts +147 -0
  7. package/langwatch/ee/admin/backoffice/__tests__/dateInputToISO.unit.test.ts +42 -0
  8. package/langwatch/ee/admin/backoffice/__tests__/userVisibility.unit.test.ts +174 -0
  9. package/langwatch/ee/admin/backoffice/adminClient.ts +114 -0
  10. package/langwatch/ee/admin/backoffice/resources/OrganizationFeaturesView.tsx +373 -0
  11. package/langwatch/ee/admin/backoffice/resources/OrganizationsView.tsx +677 -0
  12. package/langwatch/ee/admin/backoffice/resources/ProjectsView.tsx +647 -0
  13. package/langwatch/ee/admin/backoffice/resources/SubscriptionsView.tsx +628 -0
  14. package/langwatch/ee/admin/backoffice/resources/UsersView.tsx +556 -0
  15. package/langwatch/ee/admin/backoffice/useAdminResource.ts +104 -0
  16. package/langwatch/ee/admin/backoffice/userVisibility.ts +105 -0
  17. package/langwatch/ee/admin/impersonation.service.ts +170 -0
  18. package/langwatch/ee/admin/isAdmin.ts +9 -0
  19. package/langwatch/ee/admin/routes/admin.ts +531 -0
  20. package/langwatch/ee/admin/safeSelects.ts +64 -0
  21. package/langwatch/ee/billing/__tests__/customerService.unit.test.ts +183 -0
  22. package/langwatch/ee/billing/__tests__/growthSeatEvent.unit.test.ts +213 -0
  23. package/langwatch/ee/billing/__tests__/licensePurchaseHandler.unit.test.ts +250 -0
  24. package/langwatch/ee/billing/__tests__/notification.service.unit.test.ts +768 -0
  25. package/langwatch/ee/billing/__tests__/planLimits.unit.test.ts +19 -0
  26. package/langwatch/ee/billing/__tests__/planProvider.unit.test.ts +440 -0
  27. package/langwatch/ee/billing/__tests__/planTypes.unit.test.ts +32 -0
  28. package/langwatch/ee/billing/__tests__/pricing.unit.test.ts +54 -0
  29. package/langwatch/ee/billing/__tests__/seatEventSubscription.unit.test.ts +717 -0
  30. package/langwatch/ee/billing/__tests__/stripe.integration.test.ts +344 -0
  31. package/langwatch/ee/billing/__tests__/stripePrices.types.unit.test.ts +27 -0
  32. package/langwatch/ee/billing/__tests__/stripePricesLoader.unit.test.ts +72 -0
  33. package/langwatch/ee/billing/__tests__/subscription.service.unit.test.ts +730 -0
  34. package/langwatch/ee/billing/__tests__/subscriptionItemCalculator.unit.test.ts +176 -0
  35. package/langwatch/ee/billing/__tests__/usage-limit.service.unit.test.ts +706 -0
  36. package/langwatch/ee/billing/__tests__/usageReportingService.integration.test.ts +421 -0
  37. package/langwatch/ee/billing/__tests__/usageReportingService.unit.test.ts +515 -0
  38. package/langwatch/ee/billing/__tests__/webhookService.unit.test.ts +958 -0
  39. package/langwatch/ee/billing/currencyRouter.ts +18 -0
  40. package/langwatch/ee/billing/errors.ts +129 -0
  41. package/langwatch/ee/billing/index.ts +67 -0
  42. package/langwatch/ee/billing/middleware.ts +17 -0
  43. package/langwatch/ee/billing/notifications/notification.service.ts +651 -0
  44. package/langwatch/ee/billing/notifications/repositories/notification.repository.ts +51 -0
  45. package/langwatch/ee/billing/notifications/types.ts +9 -0
  46. package/langwatch/ee/billing/notifications/usage-limit.service.ts +622 -0
  47. package/langwatch/ee/billing/nurturing/hooks/activityTracking.ts +90 -0
  48. package/langwatch/ee/billing/nurturing/hooks/activityTracking.unit.test.ts +237 -0
  49. package/langwatch/ee/billing/nurturing/hooks/featureAdoption.ts +120 -0
  50. package/langwatch/ee/billing/nurturing/hooks/featureAdoption.unit.test.ts +324 -0
  51. package/langwatch/ee/billing/nurturing/hooks/index.ts +17 -0
  52. package/langwatch/ee/billing/nurturing/hooks/productInterest.ts +68 -0
  53. package/langwatch/ee/billing/nurturing/hooks/productInterest.unit.test.ts +138 -0
  54. package/langwatch/ee/billing/nurturing/hooks/promptCreation.integration.test.ts +288 -0
  55. package/langwatch/ee/billing/nurturing/hooks/promptCreation.ts +131 -0
  56. package/langwatch/ee/billing/nurturing/hooks/promptCreation.unit.test.ts +134 -0
  57. package/langwatch/ee/billing/nurturing/hooks/signupIdentification.ts +101 -0
  58. package/langwatch/ee/billing/nurturing/hooks/signupIdentification.unit.test.ts +317 -0
  59. package/langwatch/ee/billing/nurturing/hooks/subscriptionSync.ts +49 -0
  60. package/langwatch/ee/billing/nurturing/hooks/subscriptionSync.unit.test.ts +170 -0
  61. package/langwatch/ee/billing/nurturing/hooks/userSync.ts +143 -0
  62. package/langwatch/ee/billing/nurturing/hooks/userSync.unit.test.ts +307 -0
  63. package/langwatch/ee/billing/nurturing/nurturing.service.ts +179 -0
  64. package/langwatch/ee/billing/nurturing/nurturing.service.unit.test.ts +266 -0
  65. package/langwatch/ee/billing/nurturing/nurturing.service.wiring.unit.test.ts +109 -0
  66. package/langwatch/ee/billing/nurturing/types.ts +125 -0
  67. package/langwatch/ee/billing/planLimits.ts +190 -0
  68. package/langwatch/ee/billing/planProvider.ts +119 -0
  69. package/langwatch/ee/billing/planTypes.ts +53 -0
  70. package/langwatch/ee/billing/pricing.ts +57 -0
  71. package/langwatch/ee/billing/services/billableEventsQuery.ts +248 -0
  72. package/langwatch/ee/billing/services/customerService.ts +90 -0
  73. package/langwatch/ee/billing/services/licensePurchaseHandler.ts +73 -0
  74. package/langwatch/ee/billing/services/seatEventSubscription.ts +351 -0
  75. package/langwatch/ee/billing/services/seatSyncService.ts +34 -0
  76. package/langwatch/ee/billing/services/subscription.repository.ts +203 -0
  77. package/langwatch/ee/billing/services/subscription.service.ts +549 -0
  78. package/langwatch/ee/billing/services/subscriptionItemCalculator.ts +249 -0
  79. package/langwatch/ee/billing/services/usageReportingService.ts +301 -0
  80. package/langwatch/ee/billing/services/webhookService.ts +858 -0
  81. package/langwatch/ee/billing/stripe/stripeCatalog.json +1781 -0
  82. package/langwatch/ee/billing/stripe/stripeClient.ts +13 -0
  83. package/langwatch/ee/billing/stripe/stripePriceCatalog.ts +70 -0
  84. package/langwatch/ee/billing/stripe/stripePrices.types.ts +118 -0
  85. package/langwatch/ee/billing/subscriptionRouter.ts +202 -0
  86. package/langwatch/ee/billing/types.ts +102 -0
  87. package/langwatch/ee/billing/utils/currency.ts +99 -0
  88. package/langwatch/ee/billing/utils/growthSeatEvent.ts +137 -0
  89. package/langwatch/ee/licensing/__tests__/constants.unit.test.ts +56 -0
  90. package/langwatch/ee/licensing/__tests__/defaults.unit.test.ts +192 -0
  91. package/langwatch/ee/licensing/__tests__/fixtures/testKeys.ts +86 -0
  92. package/langwatch/ee/licensing/__tests__/fixtures/testLicenses.ts +92 -0
  93. package/langwatch/ee/licensing/__tests__/licenseGenerationService.unit.test.ts +232 -0
  94. package/langwatch/ee/licensing/__tests__/licenseHandler.integration.test.ts +419 -0
  95. package/langwatch/ee/licensing/__tests__/planMapping.unit.test.ts +195 -0
  96. package/langwatch/ee/licensing/__tests__/planTemplates.unit.test.ts +193 -0
  97. package/langwatch/ee/licensing/__tests__/signing.unit.test.ts +164 -0
  98. package/langwatch/ee/licensing/__tests__/validation.unit.test.ts +281 -0
  99. package/langwatch/ee/licensing/client.ts +29 -0
  100. package/langwatch/ee/licensing/constants.ts +195 -0
  101. package/langwatch/ee/licensing/defaults.ts +55 -0
  102. package/langwatch/ee/licensing/errors.ts +11 -0
  103. package/langwatch/ee/licensing/index.ts +52 -0
  104. package/langwatch/ee/licensing/licenseGenerationService.ts +87 -0
  105. package/langwatch/ee/licensing/licenseHandler.ts +308 -0
  106. package/langwatch/ee/licensing/planInfo.ts +46 -0
  107. package/langwatch/ee/licensing/planMapping.ts +37 -0
  108. package/langwatch/ee/licensing/planTemplates.ts +109 -0
  109. package/langwatch/ee/licensing/server.ts +43 -0
  110. package/langwatch/ee/licensing/signing.ts +43 -0
  111. package/langwatch/ee/licensing/types.ts +156 -0
  112. package/langwatch/ee/licensing/validation.ts +107 -0
  113. package/langwatch/ee/managed-providers/ManagedModelProviderAlert.tsx +29 -0
  114. package/langwatch/ee/managed-providers/managedBedrockConfig.ts +226 -0
  115. package/langwatch/ee/saas/ExtraFooterComponents.tsx +169 -0
  116. package/langwatch/package.json +1 -1
  117. package/langwatch/pnpm-workspace.yaml +0 -1
  118. package/langwatch_nlp/uv.lock +179 -5
  119. package/mcp-server/.env.example +2 -0
  120. package/mcp-server/.eslintrc.cjs +36 -0
  121. package/mcp-server/CHANGELOG.md +165 -0
  122. package/mcp-server/CONTRIBUTING.md +96 -0
  123. package/mcp-server/README.md +172 -0
  124. package/mcp-server/dist/archive-scenario-WJ2A7ETN.js +19 -0
  125. package/mcp-server/dist/archive-suite-4JOM4SSL.js +15 -0
  126. package/mcp-server/dist/assign-prompt-tag-GL7EAAF3.js +19 -0
  127. package/mcp-server/dist/chunk-2GT7IFWK.js +40 -0
  128. package/mcp-server/dist/chunk-2WPLXEKF.js +127 -0
  129. package/mcp-server/dist/chunk-4AUB2BIA.js +71 -0
  130. package/mcp-server/dist/chunk-BWWY5KEF.js +71 -0
  131. package/mcp-server/dist/chunk-CCWCIJJ3.js +22 -0
  132. package/mcp-server/dist/chunk-EGH5RPXM.js +25 -0
  133. package/mcp-server/dist/chunk-EUQDVOSU.js +39 -0
  134. package/mcp-server/dist/chunk-HYMIWO3U.js +44 -0
  135. package/mcp-server/dist/chunk-IE4M5OGE.js +42 -0
  136. package/mcp-server/dist/chunk-LUMEZEHL.js +48 -0
  137. package/mcp-server/dist/chunk-NUFPTHKU.js +9 -0
  138. package/mcp-server/dist/chunk-UDHJYT6P.js +1567 -0
  139. package/mcp-server/dist/chunk-WQG2DFHX.js +86 -0
  140. package/mcp-server/dist/chunk-WVI5CJ6S.js +21 -0
  141. package/mcp-server/dist/chunk-ZVS4UKN2.js +35 -0
  142. package/mcp-server/dist/chunk-ZXKLPC2E.js +27 -0
  143. package/mcp-server/dist/config.d.ts +17 -0
  144. package/mcp-server/dist/config.js +13 -0
  145. package/mcp-server/dist/create-agent-MBOOT3XK.js +23 -0
  146. package/mcp-server/dist/create-annotation-XMV6A7ED.js +24 -0
  147. package/mcp-server/dist/create-dashboard-VRKLFVZJ.js +18 -0
  148. package/mcp-server/dist/create-dataset-7HQPZCRE.js +22 -0
  149. package/mcp-server/dist/create-dataset-records-2NIVFYTV.js +22 -0
  150. package/mcp-server/dist/create-evaluator-WYFRFLRC.js +27 -0
  151. package/mcp-server/dist/create-mcp-server.d.ts +8 -0
  152. package/mcp-server/dist/create-mcp-server.js +8 -0
  153. package/mcp-server/dist/create-prompt-IEN7O6JT.js +39 -0
  154. package/mcp-server/dist/create-prompt-tag-CAEZ45VO.js +17 -0
  155. package/mcp-server/dist/create-scenario-6YHSMGLP.js +26 -0
  156. package/mcp-server/dist/create-suite-H5XOFDE5.js +38 -0
  157. package/mcp-server/dist/delete-agent-JKTNBWAA.js +18 -0
  158. package/mcp-server/dist/delete-annotation-ACMDV6QO.js +17 -0
  159. package/mcp-server/dist/delete-dashboard-VJSR7CRU.js +18 -0
  160. package/mcp-server/dist/delete-dataset-RTTTWP4D.js +20 -0
  161. package/mcp-server/dist/delete-dataset-records-KNQTIPQK.js +21 -0
  162. package/mcp-server/dist/delete-evaluator-7FVC5WM4.js +15 -0
  163. package/mcp-server/dist/delete-prompt-tag-ZMZUAGFW.js +17 -0
  164. package/mcp-server/dist/delete-workflow-EYQ3T4RQ.js +17 -0
  165. package/mcp-server/dist/discover-evaluator-schema-H23XCLNE.js +1402 -0
  166. package/mcp-server/dist/discover-scenario-schema-MEEEVND7.js +65 -0
  167. package/mcp-server/dist/discover-schema-3T52ORPB.js +446 -0
  168. package/mcp-server/dist/get-agent-E3QSTVKG.js +28 -0
  169. package/mcp-server/dist/get-analytics-2OHV763I.js +72 -0
  170. package/mcp-server/dist/get-dashboard-PC7JDHH6.js +29 -0
  171. package/mcp-server/dist/get-dataset-H5IK5FVU.js +48 -0
  172. package/mcp-server/dist/get-evaluator-UWVUPYTM.js +47 -0
  173. package/mcp-server/dist/get-prompt-WZUOLLQC.js +45 -0
  174. package/mcp-server/dist/get-scenario-Q6LCNUYN.js +33 -0
  175. package/mcp-server/dist/get-simulation-run-Z2XKO256.js +56 -0
  176. package/mcp-server/dist/get-suite-BXK5TN7P.js +44 -0
  177. package/mcp-server/dist/get-trace-4EJAYVBG.js +50 -0
  178. package/mcp-server/dist/get-workflow-O34QJLHD.js +25 -0
  179. package/mcp-server/dist/http-server-RSTXN4CN.js +224 -0
  180. package/mcp-server/dist/index.d.ts +2 -0
  181. package/mcp-server/dist/index.js +67774 -0
  182. package/mcp-server/dist/langwatch-api-annotations-ERBG27RF.js +17 -0
  183. package/mcp-server/dist/langwatch-api-dashboards-G6TR7VVO.js +17 -0
  184. package/mcp-server/dist/langwatch-api-monitors-WSXZLS2B.js +52 -0
  185. package/mcp-server/dist/langwatch-api-secrets-RR5DKG2X.js +40 -0
  186. package/mcp-server/dist/langwatch-api-triggers-2RTNSWQY.js +30 -0
  187. package/mcp-server/dist/langwatch-api-workflows-VJRIIDZ7.js +15 -0
  188. package/mcp-server/dist/list-agents-AW3P6FJV.js +32 -0
  189. package/mcp-server/dist/list-annotations-QNCGWPQ3.js +33 -0
  190. package/mcp-server/dist/list-dashboards-R7RK2IXL.js +32 -0
  191. package/mcp-server/dist/list-dataset-records-WVCSQP7P.js +39 -0
  192. package/mcp-server/dist/list-datasets-KEXRLDEU.js +60 -0
  193. package/mcp-server/dist/list-evaluators-7R2LB4JH.js +34 -0
  194. package/mcp-server/dist/list-model-providers-OBYJCKBX.js +35 -0
  195. package/mcp-server/dist/list-prompt-tags-6LY3ZPYI.js +23 -0
  196. package/mcp-server/dist/list-prompts-VWEZ4CDE.js +32 -0
  197. package/mcp-server/dist/list-scenarios-TXD4W2ZJ.js +40 -0
  198. package/mcp-server/dist/list-simulation-runs-RHPOLMFI.js +43 -0
  199. package/mcp-server/dist/list-suites-FSGBX27Z.js +42 -0
  200. package/mcp-server/dist/list-workflows-VRGEZ3EN.js +35 -0
  201. package/mcp-server/dist/rename-prompt-tag-VOJJLX4M.js +18 -0
  202. package/mcp-server/dist/run-agent-KTCC7TB7.js +36 -0
  203. package/mcp-server/dist/run-evaluation-2X3V3Q6L.js +64 -0
  204. package/mcp-server/dist/run-suite-BTMHGI2D.js +29 -0
  205. package/mcp-server/dist/run-workflow-IGAYGKJL.js +36 -0
  206. package/mcp-server/dist/search-traces-VYFUIMXH.js +72 -0
  207. package/mcp-server/dist/set-model-provider-W5IUI326.js +33 -0
  208. package/mcp-server/dist/update-agent-4BB7EYLR.js +20 -0
  209. package/mcp-server/dist/update-dataset-CXBKZ4W3.js +22 -0
  210. package/mcp-server/dist/update-dataset-record-HOHAMHXG.js +19 -0
  211. package/mcp-server/dist/update-evaluator-IVOR6FTR.js +24 -0
  212. package/mcp-server/dist/update-prompt-OWQAKE7K.js +24 -0
  213. package/mcp-server/dist/update-scenario-GDFVILPN.js +27 -0
  214. package/mcp-server/dist/update-suite-BXYUYSPT.js +39 -0
  215. package/mcp-server/package.json +79 -0
  216. package/mcp-server/pnpm-lock.yaml +6103 -0
  217. package/mcp-server/pnpm-workspace.yaml +2 -0
  218. package/mcp-server/pyproject.toml +17 -0
  219. package/mcp-server/src/__tests__/all-tools.integration.test.ts +1681 -0
  220. package/mcp-server/src/__tests__/config.unit.test.ts +169 -0
  221. package/mcp-server/src/__tests__/datasets.integration.test.ts +603 -0
  222. package/mcp-server/src/__tests__/datasets.unit.test.ts +240 -0
  223. package/mcp-server/src/__tests__/date-parsing.unit.test.ts +78 -0
  224. package/mcp-server/src/__tests__/discover-evaluator-schema.unit.test.ts +89 -0
  225. package/mcp-server/src/__tests__/discover-schema.unit.test.ts +118 -0
  226. package/mcp-server/src/__tests__/docker.integration.test.ts +234 -0
  227. package/mcp-server/src/__tests__/evaluator-tools.unit.test.ts +262 -0
  228. package/mcp-server/src/__tests__/http-transport.integration.test.ts +397 -0
  229. package/mcp-server/src/__tests__/integration.integration.test.ts +288 -0
  230. package/mcp-server/src/__tests__/langwatch-api.unit.test.ts +455 -0
  231. package/mcp-server/src/__tests__/model-provider-tools.unit.test.ts +190 -0
  232. package/mcp-server/src/__tests__/scenario-tools.integration.test.ts +286 -0
  233. package/mcp-server/src/__tests__/scenario-tools.unit.test.ts +185 -0
  234. package/mcp-server/src/__tests__/schemas.unit.test.ts +85 -0
  235. package/mcp-server/src/__tests__/tools.unit.test.ts +900 -0
  236. package/mcp-server/src/config.d.ts +15 -0
  237. package/mcp-server/src/config.ts +107 -0
  238. package/mcp-server/src/create-mcp-server.d.ts +6 -0
  239. package/mcp-server/src/create-mcp-server.ts +1799 -0
  240. package/mcp-server/src/http-server.ts +329 -0
  241. package/mcp-server/src/index.ts +46 -0
  242. package/mcp-server/src/langwatch-api-agents.ts +108 -0
  243. package/mcp-server/src/langwatch-api-annotations.ts +49 -0
  244. package/mcp-server/src/langwatch-api-dashboards.ts +48 -0
  245. package/mcp-server/src/langwatch-api-datasets.ts +191 -0
  246. package/mcp-server/src/langwatch-api-evaluators.ts +80 -0
  247. package/mcp-server/src/langwatch-api-model-providers.ts +41 -0
  248. package/mcp-server/src/langwatch-api-monitors.ts +82 -0
  249. package/mcp-server/src/langwatch-api-scenarios.ts +67 -0
  250. package/mcp-server/src/langwatch-api-secrets.ts +48 -0
  251. package/mcp-server/src/langwatch-api-simulation-runs.ts +51 -0
  252. package/mcp-server/src/langwatch-api-suites.ts +118 -0
  253. package/mcp-server/src/langwatch-api-triggers.ts +48 -0
  254. package/mcp-server/src/langwatch-api-workflows.ts +41 -0
  255. package/mcp-server/src/langwatch-api.ts +299 -0
  256. package/mcp-server/src/schemas/analytics-groups.ts +78 -0
  257. package/mcp-server/src/schemas/analytics-metrics.ts +179 -0
  258. package/mcp-server/src/schemas/create-dataset.ts +48 -0
  259. package/mcp-server/src/schemas/filter-fields.ts +119 -0
  260. package/mcp-server/src/schemas/index.ts +4 -0
  261. package/mcp-server/src/tools/archive-scenario.ts +19 -0
  262. package/mcp-server/src/tools/archive-suite.ts +12 -0
  263. package/mcp-server/src/tools/assign-prompt-tag.ts +16 -0
  264. package/mcp-server/src/tools/create-agent.ts +15 -0
  265. package/mcp-server/src/tools/create-annotation.ts +18 -0
  266. package/mcp-server/src/tools/create-dashboard.ts +7 -0
  267. package/mcp-server/src/tools/create-dataset-records.ts +23 -0
  268. package/mcp-server/src/tools/create-dataset.ts +22 -0
  269. package/mcp-server/src/tools/create-evaluator.ts +33 -0
  270. package/mcp-server/src/tools/create-prompt-tag.ts +12 -0
  271. package/mcp-server/src/tools/create-prompt.ts +58 -0
  272. package/mcp-server/src/tools/create-scenario.ts +30 -0
  273. package/mcp-server/src/tools/create-suite.ts +42 -0
  274. package/mcp-server/src/tools/delete-agent.ts +7 -0
  275. package/mcp-server/src/tools/delete-annotation.ts +7 -0
  276. package/mcp-server/src/tools/delete-dashboard.ts +7 -0
  277. package/mcp-server/src/tools/delete-dataset-records.ts +22 -0
  278. package/mcp-server/src/tools/delete-dataset.ts +20 -0
  279. package/mcp-server/src/tools/delete-evaluator.ts +12 -0
  280. package/mcp-server/src/tools/delete-prompt-tag.ts +12 -0
  281. package/mcp-server/src/tools/delete-workflow.ts +7 -0
  282. package/mcp-server/src/tools/discover-evaluator-schema.ts +143 -0
  283. package/mcp-server/src/tools/discover-scenario-schema.ts +71 -0
  284. package/mcp-server/src/tools/discover-schema.ts +106 -0
  285. package/mcp-server/src/tools/format-dataset-mutation.ts +25 -0
  286. package/mcp-server/src/tools/get-agent.ts +21 -0
  287. package/mcp-server/src/tools/get-analytics.ts +98 -0
  288. package/mcp-server/src/tools/get-dashboard.ts +22 -0
  289. package/mcp-server/src/tools/get-dataset.ts +63 -0
  290. package/mcp-server/src/tools/get-evaluator.ts +53 -0
  291. package/mcp-server/src/tools/get-prompt.ts +54 -0
  292. package/mcp-server/src/tools/get-scenario.ts +36 -0
  293. package/mcp-server/src/tools/get-simulation-run.ts +60 -0
  294. package/mcp-server/src/tools/get-suite.ts +47 -0
  295. package/mcp-server/src/tools/get-trace.ts +61 -0
  296. package/mcp-server/src/tools/get-workflow.ts +17 -0
  297. package/mcp-server/src/tools/list-agents.ts +27 -0
  298. package/mcp-server/src/tools/list-annotations.ts +33 -0
  299. package/mcp-server/src/tools/list-dashboards.ts +27 -0
  300. package/mcp-server/src/tools/list-dataset-records.ts +46 -0
  301. package/mcp-server/src/tools/list-datasets.ts +80 -0
  302. package/mcp-server/src/tools/list-evaluators.ts +37 -0
  303. package/mcp-server/src/tools/list-model-providers.ts +40 -0
  304. package/mcp-server/src/tools/list-prompt-tags.ts +21 -0
  305. package/mcp-server/src/tools/list-prompts.ts +34 -0
  306. package/mcp-server/src/tools/list-scenarios.ts +47 -0
  307. package/mcp-server/src/tools/list-simulation-runs.ts +49 -0
  308. package/mcp-server/src/tools/list-suites.ts +43 -0
  309. package/mcp-server/src/tools/list-workflows.ts +31 -0
  310. package/mcp-server/src/tools/rename-prompt-tag.ts +14 -0
  311. package/mcp-server/src/tools/run-agent.ts +36 -0
  312. package/mcp-server/src/tools/run-evaluation.ts +87 -0
  313. package/mcp-server/src/tools/run-suite.ts +28 -0
  314. package/mcp-server/src/tools/run-workflow.ts +36 -0
  315. package/mcp-server/src/tools/search-traces.ts +91 -0
  316. package/mcp-server/src/tools/set-model-provider.ts +46 -0
  317. package/mcp-server/src/tools/update-agent.ts +13 -0
  318. package/mcp-server/src/tools/update-dataset-record.ts +21 -0
  319. package/mcp-server/src/tools/update-dataset.ts +23 -0
  320. package/mcp-server/src/tools/update-evaluator.ts +30 -0
  321. package/mcp-server/src/tools/update-prompt.ts +31 -0
  322. package/mcp-server/src/tools/update-scenario.ts +32 -0
  323. package/mcp-server/src/tools/update-suite.ts +44 -0
  324. package/mcp-server/src/utils/date-parsing.ts +31 -0
  325. package/mcp-server/src/utils/escape-markdown.ts +12 -0
  326. package/mcp-server/tsconfig.json +27 -0
  327. package/mcp-server/uv.lock +2731 -0
  328. package/package.json +2 -6
  329. package/packages/server/dist/cli.cjs +453 -186
  330. package/cmd/service/main.go +0 -68
  331. package/go.mod +0 -117
  332. package/go.sum +0 -299
  333. package/pkg/breaker/breaker.go +0 -157
  334. package/pkg/breaker/breaker_test.go +0 -131
  335. package/pkg/clog/LICENSE +0 -26
  336. package/pkg/clog/clog.go +0 -90
  337. package/pkg/clog/clog_test.go +0 -56
  338. package/pkg/clog/panic.go +0 -39
  339. package/pkg/config/LICENSE +0 -26
  340. package/pkg/config/config.go +0 -86
  341. package/pkg/config/config_test.go +0 -70
  342. package/pkg/config/otel.go +0 -50
  343. package/pkg/config/server.go +0 -61
  344. package/pkg/config/validate.go +0 -80
  345. package/pkg/config/validate_test.go +0 -74
  346. package/pkg/contexts/contexts_test.go +0 -34
  347. package/pkg/contexts/request_id.go +0 -1
  348. package/pkg/contexts/service_info.go +0 -33
  349. package/pkg/errfuncs/errfuncs.go +0 -9
  350. package/pkg/errfuncs/errfuncs_test.go +0 -28
  351. package/pkg/forkedcontext/forkedcontext.go +0 -57
  352. package/pkg/health/health.go +0 -123
  353. package/pkg/health/health_test.go +0 -84
  354. package/pkg/herr/LICENSE +0 -26
  355. package/pkg/herr/code.go +0 -14
  356. package/pkg/herr/herr.go +0 -112
  357. package/pkg/herr/herr_test.go +0 -78
  358. package/pkg/herr/http.go +0 -133
  359. package/pkg/herr/http_test.go +0 -103
  360. package/pkg/herr/validate.go +0 -72
  361. package/pkg/herr/validate_test.go +0 -75
  362. package/pkg/httpmiddleware/bearer.go +0 -47
  363. package/pkg/httpmiddleware/httputil_test.go +0 -167
  364. package/pkg/httpmiddleware/inflight.go +0 -23
  365. package/pkg/httpmiddleware/maxbody.go +0 -30
  366. package/pkg/httpmiddleware/recover.go +0 -38
  367. package/pkg/httpmiddleware/requestid.go +0 -40
  368. package/pkg/httpmiddleware/telemetry.go +0 -96
  369. package/pkg/httpmiddleware/version.go +0 -16
  370. package/pkg/jwtverify/verifier.go +0 -72
  371. package/pkg/jwtverify/verifier_test.go +0 -134
  372. package/pkg/ksuid/LICENSE +0 -26
  373. package/pkg/ksuid/ksuid.go +0 -157
  374. package/pkg/ksuid/ksuid_test.go +0 -107
  375. package/pkg/ksuid/resources.go +0 -13
  376. package/pkg/lifecycle/group.go +0 -175
  377. package/pkg/lifecycle/group_test.go +0 -236
  378. package/pkg/lifecycle/service.go +0 -112
  379. package/pkg/netprobe/netprobe.go +0 -89
  380. package/pkg/netprobe/netprobe_test.go +0 -55
  381. package/pkg/otelsetup/otelsetup.go +0 -226
  382. package/pkg/otelsetup/otelsetup_test.go +0 -130
  383. package/pkg/ptr/LICENSE +0 -26
  384. package/pkg/ptr/ptr.go +0 -34
  385. package/pkg/ptr/ptr_test.go +0 -66
  386. package/pkg/retry/bench_test.go +0 -67
  387. package/pkg/retry/retry.go +0 -188
  388. package/pkg/retry/retry_test.go +0 -222
  389. package/pkg/slicefuncs/LICENSE +0 -26
  390. package/pkg/slicefuncs/slicefuncs.go +0 -10
  391. package/pkg/slicefuncs/slicefuncs_test.go +0 -29
  392. package/pkg/stacktrace/LICENSE +0 -26
  393. package/pkg/stacktrace/frames.go +0 -77
  394. package/pkg/stacktrace/frames_test.go +0 -73
  395. package/services/aigateway/BENCHMARKS.md +0 -110
  396. package/services/aigateway/README.md +0 -156
  397. package/services/aigateway/adapters/authresolver/bench_test.go +0 -13
  398. package/services/aigateway/adapters/authresolver/redis.go +0 -61
  399. package/services/aigateway/adapters/authresolver/service.go +0 -442
  400. package/services/aigateway/adapters/authresolver/service_test.go +0 -435
  401. package/services/aigateway/adapters/budget/bench_test.go +0 -50
  402. package/services/aigateway/adapters/budget/budget.go +0 -59
  403. package/services/aigateway/adapters/cacherules/evaluator.go +0 -134
  404. package/services/aigateway/adapters/cacherules/evaluator_test.go +0 -207
  405. package/services/aigateway/adapters/controlplane/bench_test.go +0 -40
  406. package/services/aigateway/adapters/controlplane/client.go +0 -213
  407. package/services/aigateway/adapters/controlplane/client_test.go +0 -73
  408. package/services/aigateway/adapters/controlplane/config_wire.go +0 -310
  409. package/services/aigateway/adapters/controlplane/guardrails.go +0 -88
  410. package/services/aigateway/adapters/controlplane/signer.go +0 -95
  411. package/services/aigateway/adapters/controlplane/signer_test.go +0 -64
  412. package/services/aigateway/adapters/customertracebridge/context.go +0 -48
  413. package/services/aigateway/adapters/customertracebridge/context_test.go +0 -24
  414. package/services/aigateway/adapters/customertracebridge/emitter.go +0 -329
  415. package/services/aigateway/adapters/customertracebridge/emitter_test.go +0 -93
  416. package/services/aigateway/adapters/customertracebridge/registry.go +0 -82
  417. package/services/aigateway/adapters/customertracebridge/transport.go +0 -122
  418. package/services/aigateway/adapters/gatewaytracer/attrs.go +0 -28
  419. package/services/aigateway/adapters/gatewaytracer/attrs_genai.go +0 -24
  420. package/services/aigateway/adapters/gatewaytracer/headers.go +0 -8
  421. package/services/aigateway/adapters/gatewaytracer/tracer.go +0 -101
  422. package/services/aigateway/adapters/httpapi/bench_test.go +0 -83
  423. package/services/aigateway/adapters/httpapi/middleware.go +0 -123
  424. package/services/aigateway/adapters/httpapi/router.go +0 -635
  425. package/services/aigateway/adapters/httpapi/router_test.go +0 -633
  426. package/services/aigateway/adapters/modelresolver/resolver.go +0 -107
  427. package/services/aigateway/adapters/modelresolver/resolver_test.go +0 -140
  428. package/services/aigateway/adapters/policy/matcher.go +0 -250
  429. package/services/aigateway/adapters/policy/matcher_test.go +0 -124
  430. package/services/aigateway/adapters/providers/bifrost.go +0 -798
  431. package/services/aigateway/adapters/providers/bifrost_parser.go +0 -201
  432. package/services/aigateway/adapters/providers/bifrost_test.go +0 -181
  433. package/services/aigateway/adapters/ratelimit/limiter.go +0 -122
  434. package/services/aigateway/adapters/ratelimit/limiter_test.go +0 -81
  435. package/services/aigateway/app/app.go +0 -104
  436. package/services/aigateway/app/dispatch.go +0 -89
  437. package/services/aigateway/app/dispatch_test.go +0 -475
  438. package/services/aigateway/app/handlers.go +0 -79
  439. package/services/aigateway/app/peek_bench_test.go +0 -21
  440. package/services/aigateway/app/pipeline/bench_test.go +0 -34
  441. package/services/aigateway/app/pipeline/budget.go +0 -55
  442. package/services/aigateway/app/pipeline/cache.go +0 -34
  443. package/services/aigateway/app/pipeline/cachecontrol.go +0 -86
  444. package/services/aigateway/app/pipeline/cachecontrol_test.go +0 -110
  445. package/services/aigateway/app/pipeline/guardrail.go +0 -121
  446. package/services/aigateway/app/pipeline/pipeline.go +0 -159
  447. package/services/aigateway/app/pipeline/policy.go +0 -23
  448. package/services/aigateway/app/pipeline/ratelimit.go +0 -21
  449. package/services/aigateway/app/pipeline/rawframing_test.go +0 -67
  450. package/services/aigateway/app/pipeline/resolve.go +0 -44
  451. package/services/aigateway/app/pipeline/trace.go +0 -129
  452. package/services/aigateway/app/ports.go +0 -61
  453. package/services/aigateway/cmd/root.go +0 -42
  454. package/services/aigateway/config.go +0 -86
  455. package/services/aigateway/deps.go +0 -177
  456. package/services/aigateway/domain/bundle.go +0 -203
  457. package/services/aigateway/domain/errors.go +0 -23
  458. package/services/aigateway/domain/model.go +0 -24
  459. package/services/aigateway/domain/provider.go +0 -38
  460. package/services/aigateway/domain/request.go +0 -65
  461. package/services/aigateway/domain/response.go +0 -56
  462. package/services/aigateway/domain/verdict.go +0 -55
  463. package/services/aigateway/serve.go +0 -45
  464. package/services/aigateway/tests/matrix/README.md +0 -71
  465. package/services/aigateway/tests/matrix/anthropic_test.go +0 -61
  466. package/services/aigateway/tests/matrix/azure_test.go +0 -52
  467. package/services/aigateway/tests/matrix/bedrock_test.go +0 -69
  468. package/services/aigateway/tests/matrix/gemini_test.go +0 -117
  469. package/services/aigateway/tests/matrix/matrix_test.go +0 -601
  470. package/services/aigateway/tests/matrix/openai_test.go +0 -66
  471. package/services/aigateway/tests/matrix/vertex_test.go +0 -160
@@ -0,0 +1,1681 @@
1
+ import { createServer, type Server } from "http";
2
+ import { afterAll, beforeAll, describe, expect, it, vi, beforeEach } from "vitest";
3
+ import { initConfig } from "../config.js";
4
+
5
+ // --- Canned responses for every API endpoint ---
6
+
7
+ const CANNED_TRACES_SEARCH = {
8
+ traces: [
9
+ {
10
+ trace_id: "trace-001",
11
+ formatted_trace:
12
+ "Root [server] 1200ms\n LLM Call [llm] 500ms\n Input: Hello, how are you?\n Output: I am fine, thank you!",
13
+ input: { value: "Hello, how are you?" },
14
+ output: { value: "I am fine, thank you!" },
15
+ timestamps: { started_at: 1700000000000 },
16
+ metadata: { user_id: "user-42", thread_id: "thread-1" },
17
+ },
18
+ ],
19
+ pagination: { totalHits: 1 },
20
+ };
21
+
22
+ const CANNED_TRACES_SEARCH_WITH_SCROLL = {
23
+ traces: [
24
+ {
25
+ trace_id: "trace-page-1",
26
+ input: { value: "Page 1 input" },
27
+ output: { value: "Page 1 output" },
28
+ },
29
+ ],
30
+ pagination: { totalHits: 50, scrollId: "scroll-token-abc" },
31
+ };
32
+
33
+ const CANNED_TRACES_EMPTY = {
34
+ traces: [],
35
+ pagination: { totalHits: 0 },
36
+ };
37
+
38
+ const CANNED_TRACE_DETAIL = {
39
+ trace_id: "trace-001",
40
+ formatted_trace:
41
+ "Root [server] 1200ms\n LLM Call [llm] 500ms\n Input: Hello\n Output: Hi there",
42
+ timestamps: {
43
+ started_at: 1700000000000,
44
+ updated_at: 1700000001000,
45
+ inserted_at: 1700000001000,
46
+ },
47
+ metadata: {
48
+ user_id: "user-42",
49
+ thread_id: "thread-1",
50
+ customer_id: "cust-100",
51
+ labels: ["production"],
52
+ },
53
+ evaluations: [
54
+ {
55
+ evaluator_id: "eval-1",
56
+ name: "Faithfulness",
57
+ score: 0.95,
58
+ passed: true,
59
+ },
60
+ ],
61
+ };
62
+
63
+ const CANNED_ANALYTICS = {
64
+ currentPeriod: [
65
+ { date: "2024-01-01", "0__trace_id_cardinality": 42 },
66
+ { date: "2024-01-02", "0__trace_id_cardinality": 58 },
67
+ ],
68
+ previousPeriod: [],
69
+ };
70
+
71
+ const CANNED_PROMPTS_LIST = [
72
+ {
73
+ id: "p1",
74
+ handle: "greeting-bot",
75
+ name: "Greeting Bot",
76
+ latestVersionNumber: 3,
77
+ },
78
+ {
79
+ id: "p2",
80
+ handle: "qa-assistant",
81
+ name: "QA Assistant",
82
+ latestVersionNumber: 1,
83
+ },
84
+ ];
85
+
86
+ const CANNED_PROMPT_DETAIL = {
87
+ id: "p1",
88
+ handle: "greeting-bot",
89
+ name: "Greeting Bot",
90
+ latestVersionNumber: 3,
91
+ versions: [
92
+ {
93
+ version: 3,
94
+ commitMessage: "Updated tone",
95
+ model: "openai/gpt-4o",
96
+ messages: [{ role: "system", content: "You are a friendly bot." }],
97
+ },
98
+ { version: 2, commitMessage: "Added greeting" },
99
+ { version: 1, commitMessage: "Initial version" },
100
+ ],
101
+ };
102
+
103
+ const CANNED_PROMPT_CREATED = {
104
+ id: "p-new",
105
+ handle: "new-prompt",
106
+ name: "New Prompt",
107
+ latestVersionNumber: 1,
108
+ };
109
+
110
+ const CANNED_PROMPT_UPDATED = {
111
+ id: "p1",
112
+ handle: "greeting-bot",
113
+ latestVersionNumber: 4,
114
+ };
115
+
116
+ const CANNED_SCENARIOS_LIST = [
117
+ {
118
+ id: "scen_abc123",
119
+ name: "Login Flow Happy Path",
120
+ situation: "User attempts to log in with valid credentials",
121
+ criteria: [
122
+ "Responds with a welcome message",
123
+ "Includes user name in greeting",
124
+ ],
125
+ labels: ["auth", "happy-path"],
126
+ },
127
+ {
128
+ id: "scen_def456",
129
+ name: "Password Reset",
130
+ situation: "User requests a password reset link",
131
+ criteria: ["Sends reset email"],
132
+ labels: ["auth"],
133
+ },
134
+ ];
135
+
136
+ const CANNED_SCENARIO_DETAIL = {
137
+ id: "scen_abc123",
138
+ name: "Login Flow Happy Path",
139
+ situation: "User attempts to log in with valid credentials",
140
+ criteria: [
141
+ "Responds with a welcome message",
142
+ "Includes user name in greeting",
143
+ ],
144
+ labels: ["auth", "happy-path"],
145
+ };
146
+
147
+ const CANNED_SCENARIO_CREATED = {
148
+ id: "scen_new789",
149
+ name: "New Scenario",
150
+ situation: "User does something",
151
+ criteria: ["Agent responds correctly"],
152
+ labels: ["test"],
153
+ };
154
+
155
+ const CANNED_SCENARIO_UPDATED = {
156
+ id: "scen_abc123",
157
+ name: "Login Flow - Updated",
158
+ situation: "User logs in with correct email and pass",
159
+ criteria: [
160
+ "Responds with welcome message",
161
+ "Sets session cookie",
162
+ "Redirects to dashboard",
163
+ ],
164
+ labels: ["auth", "happy-path"],
165
+ };
166
+
167
+ const CANNED_SCENARIO_ARCHIVED = {
168
+ id: "scen_abc123",
169
+ archived: true,
170
+ };
171
+
172
+ const CANNED_EVALUATORS_LIST = [
173
+ {
174
+ id: "evaluator_abc123",
175
+ projectId: "proj_1",
176
+ name: "Toxicity Check",
177
+ slug: "toxicity-check",
178
+ type: "evaluator",
179
+ config: { evaluatorType: "openai/moderation" },
180
+ workflowId: null,
181
+ copiedFromEvaluatorId: null,
182
+ createdAt: "2024-01-01T00:00:00.000Z",
183
+ updatedAt: "2024-01-01T00:00:00.000Z",
184
+ fields: [{ identifier: "input", type: "str" }],
185
+ outputFields: [{ identifier: "passed", type: "bool" }],
186
+ },
187
+ {
188
+ id: "evaluator_def456",
189
+ projectId: "proj_1",
190
+ name: "Exact Match",
191
+ slug: "exact-match",
192
+ type: "evaluator",
193
+ config: { evaluatorType: "langevals/exact_match" },
194
+ workflowId: null,
195
+ copiedFromEvaluatorId: null,
196
+ createdAt: "2024-01-02T00:00:00.000Z",
197
+ updatedAt: "2024-01-02T00:00:00.000Z",
198
+ fields: [
199
+ { identifier: "output", type: "str" },
200
+ { identifier: "expected_output", type: "str" },
201
+ ],
202
+ outputFields: [{ identifier: "passed", type: "bool" }],
203
+ },
204
+ ];
205
+
206
+ const CANNED_EVALUATOR_DETAIL = {
207
+ id: "evaluator_abc123",
208
+ projectId: "proj_1",
209
+ name: "Toxicity Check",
210
+ slug: "toxicity-check",
211
+ type: "evaluator",
212
+ config: {
213
+ evaluatorType: "openai/moderation",
214
+ settings: { model: "text-moderation-stable" },
215
+ },
216
+ workflowId: null,
217
+ copiedFromEvaluatorId: null,
218
+ createdAt: "2024-01-01T00:00:00.000Z",
219
+ updatedAt: "2024-01-01T00:00:00.000Z",
220
+ fields: [
221
+ { identifier: "input", type: "str" },
222
+ { identifier: "output", type: "str", optional: true },
223
+ ],
224
+ outputFields: [
225
+ { identifier: "passed", type: "bool" },
226
+ { identifier: "score", type: "float" },
227
+ ],
228
+ };
229
+
230
+ const CANNED_EVALUATOR_CREATED = {
231
+ id: "evaluator_new123",
232
+ projectId: "proj_1",
233
+ name: "My LLM Judge",
234
+ slug: "my-llm-judge",
235
+ type: "evaluator",
236
+ config: { evaluatorType: "langevals/llm_boolean" },
237
+ workflowId: null,
238
+ copiedFromEvaluatorId: null,
239
+ createdAt: "2024-01-01T00:00:00.000Z",
240
+ updatedAt: "2024-01-01T00:00:00.000Z",
241
+ fields: [{ identifier: "input", type: "str" }],
242
+ outputFields: [{ identifier: "passed", type: "bool" }],
243
+ };
244
+
245
+ const CANNED_EVALUATOR_UPDATED = {
246
+ id: "evaluator_abc123",
247
+ projectId: "proj_1",
248
+ name: "Updated Toxicity",
249
+ slug: "toxicity-check",
250
+ type: "evaluator",
251
+ config: { evaluatorType: "openai/moderation" },
252
+ workflowId: null,
253
+ copiedFromEvaluatorId: null,
254
+ createdAt: "2024-01-01T00:00:00.000Z",
255
+ updatedAt: "2024-01-02T00:00:00.000Z",
256
+ fields: [],
257
+ outputFields: [],
258
+ };
259
+
260
+ const CANNED_MODEL_PROVIDERS_LIST = {
261
+ openai: {
262
+ provider: "openai",
263
+ enabled: true,
264
+ customKeys: { OPENAI_API_KEY: "HAS_KEY" },
265
+ models: ["gpt-4o", "gpt-4o-mini"],
266
+ embeddingsModels: ["text-embedding-3-small"],
267
+ deploymentMapping: null,
268
+ extraHeaders: [],
269
+ },
270
+ anthropic: {
271
+ provider: "anthropic",
272
+ enabled: false,
273
+ customKeys: null,
274
+ models: ["claude-sonnet-4-5-20250929"],
275
+ embeddingsModels: null,
276
+ deploymentMapping: null,
277
+ extraHeaders: [],
278
+ },
279
+ };
280
+
281
+ const CANNED_AGENTS_LIST = {
282
+ data: [
283
+ { id: "agent_abc", name: "Test Agent", type: "http", config: { url: "http://example.com" }, createdAt: "2024-01-01T00:00:00Z", updatedAt: "2024-01-01T00:00:00Z" },
284
+ ],
285
+ pagination: { page: 1, limit: 50, total: 1, totalPages: 1 },
286
+ };
287
+
288
+ const CANNED_AGENT_DETAIL = {
289
+ id: "agent_abc", name: "Test Agent", type: "http", config: { url: "http://example.com" }, createdAt: "2024-01-01T00:00:00Z", updatedAt: "2024-01-01T00:00:00Z",
290
+ };
291
+
292
+ const CANNED_SUITES_LIST = [
293
+ { id: "suite_abc", name: "Regression Suite", slug: "regression-suite", description: null, scenarioIds: ["scen_abc123"], targets: [{ type: "http", referenceId: "agent_abc" }], repeatCount: 1, labels: [], createdAt: "2024-01-01T00:00:00Z", updatedAt: "2024-01-01T00:00:00Z" },
294
+ ];
295
+
296
+ const CANNED_SUITE_DETAIL = {
297
+ id: "suite_abc", name: "Regression Suite", slug: "regression-suite", description: "A test suite", scenarioIds: ["scen_abc123"], targets: [{ type: "http", referenceId: "agent_abc" }], repeatCount: 1, labels: [], createdAt: "2024-01-01T00:00:00Z", updatedAt: "2024-01-01T00:00:00Z",
298
+ };
299
+
300
+ const CANNED_SUITE_CREATED = {
301
+ id: "suite_new", name: "New Suite", slug: "new-suite", description: null, scenarioIds: ["scen_abc123"], targets: [{ type: "http", referenceId: "agent_abc" }], repeatCount: 1, labels: [], createdAt: "2024-01-01T00:00:00Z", updatedAt: "2024-01-01T00:00:00Z",
302
+ };
303
+
304
+ const CANNED_SUITE_RUN = {
305
+ scheduled: true, batchRunId: "batch_123", setId: "set_456", jobCount: 1, skippedArchived: { scenarios: [], targets: [] }, items: [{ scenarioRunId: "run_1", scenarioId: "scen_abc123", target: { type: "http", referenceId: "agent_abc" }, name: "Test" }],
306
+ };
307
+
308
+ const CANNED_SIMULATION_RUNS = {
309
+ runs: [{ scenarioRunId: "run_abc", scenarioId: "scen_abc123", batchRunId: "batch_xyz", name: "Login Flow", status: "SUCCESS", durationInMs: 5200, totalCost: 0.0042, timestamp: 1700000000000, updatedAt: 1700000001000 }],
310
+ hasMore: false,
311
+ };
312
+
313
+ const CANNED_SIMULATION_RUN_DETAIL = {
314
+ scenarioRunId: "run_abc", scenarioId: "scen_abc123", batchRunId: "batch_xyz", name: "Login Flow", status: "SUCCESS", durationInMs: 5200, totalCost: 0.0042, results: { verdict: "passed", reasoning: "All criteria met", metCriteria: ["Greets user"], unmetCriteria: [], error: null }, messages: [{ role: "user", content: "Hello" }, { role: "assistant", content: "Hi there!" }], timestamp: 1700000000000, updatedAt: 1700000001000,
315
+ };
316
+
317
+ const CANNED_DASHBOARDS_LIST = {
318
+ data: [{ id: "dash_abc", name: "Main Dashboard", order: 0, graphCount: 3, createdAt: "2024-01-01T00:00:00Z", updatedAt: "2024-01-01T00:00:00Z" }],
319
+ };
320
+
321
+ const CANNED_WORKFLOWS_LIST = [
322
+ { id: "wf_abc", name: "Test Workflow", icon: null, description: "A workflow", isEvaluator: false, isComponent: false, createdAt: "2024-01-01T00:00:00Z", updatedAt: "2024-01-01T00:00:00Z" },
323
+ ];
324
+
325
+ const CANNED_MODEL_PROVIDER_SET = {
326
+ openai: {
327
+ provider: "openai",
328
+ enabled: true,
329
+ customKeys: { OPENAI_API_KEY: "HAS_KEY" },
330
+ models: ["gpt-4o"],
331
+ embeddingsModels: null,
332
+ deploymentMapping: null,
333
+ extraHeaders: [],
334
+ },
335
+ };
336
+
337
+ // --- Mock HTTP Server that handles ALL MCP API endpoints ---
338
+
339
+ /** Track last request for each route so tests can assert on request body/params. */
340
+ const lastRequests: Record<string, { method: string; url: string; body: string }> = {};
341
+
342
+ function createMockServer(): Server {
343
+ return createServer((req, res) => {
344
+ const authToken = req.headers["x-auth-token"];
345
+ if (authToken !== "test-integration-key") {
346
+ res.writeHead(401, { "Content-Type": "application/json" });
347
+ res.end(JSON.stringify({ message: "Invalid auth token." }));
348
+ return;
349
+ }
350
+
351
+ let body = "";
352
+ req.on("data", (chunk: string) => (body += chunk));
353
+ req.on("end", () => {
354
+ const url = req.url ?? "";
355
+ const method = req.method ?? "GET";
356
+ res.setHeader("Content-Type", "application/json");
357
+
358
+ // Store last request for assertions
359
+ const routeKey = `${method} ${url.split("?")[0]}`;
360
+ lastRequests[routeKey] = { method, url, body };
361
+
362
+ // --- Trace endpoints ---
363
+ if (url === "/api/traces/search" && method === "POST") {
364
+ const parsed = JSON.parse(body);
365
+ // Return empty results when a special query is used
366
+ if (parsed.query === "__empty__") {
367
+ res.writeHead(200);
368
+ res.end(JSON.stringify(CANNED_TRACES_EMPTY));
369
+ } else if (parsed.pageSize === 5) {
370
+ res.writeHead(200);
371
+ res.end(JSON.stringify(CANNED_TRACES_SEARCH_WITH_SCROLL));
372
+ } else {
373
+ res.writeHead(200);
374
+ res.end(JSON.stringify(CANNED_TRACES_SEARCH));
375
+ }
376
+ } else if (
377
+ url.match(/^\/api\/traces\/trace-nonexistent(\?|$)/) &&
378
+ method === "GET"
379
+ ) {
380
+ res.writeHead(404);
381
+ res.end(JSON.stringify({ message: "Trace not found" }));
382
+ } else if (
383
+ url.match(/^\/api\/traces\/[^/]+(\?|$)/) &&
384
+ method === "GET"
385
+ ) {
386
+ res.writeHead(200);
387
+ res.end(JSON.stringify(CANNED_TRACE_DETAIL));
388
+ }
389
+ // --- Analytics endpoint ---
390
+ else if (url === "/api/analytics/timeseries" && method === "POST") {
391
+ res.writeHead(200);
392
+ res.end(JSON.stringify(CANNED_ANALYTICS));
393
+ }
394
+ // --- Prompt endpoints ---
395
+ else if (url === "/api/prompts" && method === "GET") {
396
+ res.writeHead(200);
397
+ res.end(JSON.stringify(CANNED_PROMPTS_LIST));
398
+ } else if (url === "/api/prompts" && method === "POST") {
399
+ res.writeHead(200);
400
+ res.end(JSON.stringify(CANNED_PROMPT_CREATED));
401
+ } else if (
402
+ url.match(/^\/api\/prompts\/[^/]+$/) &&
403
+ method === "GET"
404
+ ) {
405
+ res.writeHead(200);
406
+ res.end(JSON.stringify(CANNED_PROMPT_DETAIL));
407
+ } else if (
408
+ url.match(/^\/api\/prompts\/[^/]+$/) &&
409
+ method === "PUT"
410
+ ) {
411
+ res.writeHead(200);
412
+ res.end(JSON.stringify(CANNED_PROMPT_UPDATED));
413
+ }
414
+ // --- Scenario endpoints ---
415
+ else if (url === "/api/scenarios" && method === "GET") {
416
+ res.writeHead(200);
417
+ res.end(JSON.stringify(CANNED_SCENARIOS_LIST));
418
+ } else if (url === "/api/scenarios" && method === "POST") {
419
+ res.writeHead(200);
420
+ res.end(JSON.stringify(CANNED_SCENARIO_CREATED));
421
+ } else if (
422
+ url.match(/^\/api\/scenarios\/scen_nonexistent(\?|$)/) &&
423
+ method === "GET"
424
+ ) {
425
+ res.writeHead(404);
426
+ res.end(JSON.stringify({ message: "Scenario not found" }));
427
+ } else if (
428
+ url.match(/^\/api\/scenarios\/[^/]+$/) &&
429
+ method === "GET"
430
+ ) {
431
+ res.writeHead(200);
432
+ res.end(JSON.stringify(CANNED_SCENARIO_DETAIL));
433
+ } else if (
434
+ url.match(/^\/api\/scenarios\/[^/]+$/) &&
435
+ method === "PUT"
436
+ ) {
437
+ res.writeHead(200);
438
+ res.end(JSON.stringify(CANNED_SCENARIO_UPDATED));
439
+ } else if (
440
+ url.match(/^\/api\/scenarios\/[^/]+$/) &&
441
+ method === "DELETE"
442
+ ) {
443
+ res.writeHead(200);
444
+ res.end(JSON.stringify(CANNED_SCENARIO_ARCHIVED));
445
+ }
446
+ // --- Evaluator endpoints ---
447
+ else if (url === "/api/evaluators" && method === "GET") {
448
+ res.writeHead(200);
449
+ res.end(JSON.stringify(CANNED_EVALUATORS_LIST));
450
+ } else if (url === "/api/evaluators" && method === "POST") {
451
+ res.writeHead(200);
452
+ res.end(JSON.stringify(CANNED_EVALUATOR_CREATED));
453
+ } else if (
454
+ url.match(/^\/api\/evaluators\/evaluator_nonexistent(\?|$)/) &&
455
+ method === "GET"
456
+ ) {
457
+ res.writeHead(404);
458
+ res.end(JSON.stringify({ message: "Evaluator not found" }));
459
+ } else if (
460
+ url.match(/^\/api\/evaluators\/[^/]+$/) &&
461
+ method === "GET"
462
+ ) {
463
+ res.writeHead(200);
464
+ res.end(JSON.stringify(CANNED_EVALUATOR_DETAIL));
465
+ } else if (
466
+ url.match(/^\/api\/evaluators\/[^/]+$/) &&
467
+ method === "PUT"
468
+ ) {
469
+ res.writeHead(200);
470
+ res.end(JSON.stringify(CANNED_EVALUATOR_UPDATED));
471
+ }
472
+ // --- Model Provider endpoints ---
473
+ else if (url === "/api/model-providers" && method === "GET") {
474
+ res.writeHead(200);
475
+ res.end(JSON.stringify(CANNED_MODEL_PROVIDERS_LIST));
476
+ } else if (
477
+ url.match(/^\/api\/model-providers\/[^/]+$/) &&
478
+ method === "PUT"
479
+ ) {
480
+ res.writeHead(200);
481
+ res.end(JSON.stringify(CANNED_MODEL_PROVIDER_SET));
482
+ }
483
+ // --- Agent endpoints ---
484
+ else if (url === "/api/agents" && method === "GET") {
485
+ res.writeHead(200);
486
+ res.end(JSON.stringify(CANNED_AGENTS_LIST));
487
+ } else if (url === "/api/agents" && method === "POST") {
488
+ res.writeHead(201);
489
+ res.end(JSON.stringify(CANNED_AGENT_DETAIL));
490
+ } else if (url?.match(/^\/api\/agents\/[^/]+$/) && method === "GET") {
491
+ res.writeHead(200);
492
+ res.end(JSON.stringify(CANNED_AGENT_DETAIL));
493
+ } else if (url?.match(/^\/api\/agents\/[^/]+$/) && method === "PATCH") {
494
+ res.writeHead(200);
495
+ res.end(JSON.stringify(CANNED_AGENT_DETAIL));
496
+ } else if (url?.match(/^\/api\/agents\/[^/]+$/) && method === "DELETE") {
497
+ res.writeHead(200);
498
+ res.end(JSON.stringify({ id: "agent_abc", name: "Test Agent" }));
499
+ }
500
+ // --- Suite endpoints ---
501
+ else if (url === "/api/suites" && method === "GET") {
502
+ res.writeHead(200);
503
+ res.end(JSON.stringify(CANNED_SUITES_LIST));
504
+ } else if (url === "/api/suites" && method === "POST") {
505
+ res.writeHead(201);
506
+ res.end(JSON.stringify(CANNED_SUITE_CREATED));
507
+ } else if (url?.match(/^\/api\/suites\/[^/]+\/run$/) && method === "POST") {
508
+ res.writeHead(200);
509
+ res.end(JSON.stringify(CANNED_SUITE_RUN));
510
+ } else if (url?.match(/^\/api\/suites\/[^/]+\/duplicate$/) && method === "POST") {
511
+ res.writeHead(201);
512
+ res.end(JSON.stringify(CANNED_SUITE_CREATED));
513
+ } else if (url?.match(/^\/api\/suites\/[^/]+$/) && method === "GET") {
514
+ res.writeHead(200);
515
+ res.end(JSON.stringify(CANNED_SUITE_DETAIL));
516
+ } else if (url?.match(/^\/api\/suites\/[^/]+$/) && method === "PATCH") {
517
+ res.writeHead(200);
518
+ res.end(JSON.stringify(CANNED_SUITE_DETAIL));
519
+ } else if (url?.match(/^\/api\/suites\/[^/]+$/) && method === "DELETE") {
520
+ res.writeHead(200);
521
+ res.end(JSON.stringify({ id: "suite_abc", archived: true }));
522
+ }
523
+ // --- Simulation Run endpoints ---
524
+ else if (url?.match(/^\/api\/simulation-runs\/[^/]+$/) && method === "GET") {
525
+ res.writeHead(200);
526
+ res.end(JSON.stringify(CANNED_SIMULATION_RUN_DETAIL));
527
+ } else if (url?.match(/^\/api\/simulation-runs/) && method === "GET") {
528
+ res.writeHead(200);
529
+ res.end(JSON.stringify(CANNED_SIMULATION_RUNS));
530
+ }
531
+ // --- Dashboard endpoints ---
532
+ else if (url === "/api/dashboards" && method === "GET") {
533
+ res.writeHead(200);
534
+ res.end(JSON.stringify(CANNED_DASHBOARDS_LIST));
535
+ } else if (url === "/api/dashboards" && method === "POST") {
536
+ res.writeHead(201);
537
+ res.end(JSON.stringify({ id: "dash_new", name: "New Dashboard" }));
538
+ } else if (url?.match(/^\/api\/dashboards\/[^/]+$/) && method === "GET") {
539
+ res.writeHead(200);
540
+ res.end(JSON.stringify(CANNED_DASHBOARDS_LIST.data[0]));
541
+ } else if (url?.match(/^\/api\/dashboards\/[^/]+$/) && method === "DELETE") {
542
+ res.writeHead(200);
543
+ res.end(JSON.stringify({ id: "dash_abc", name: "Main Dashboard" }));
544
+ }
545
+ // --- Workflow endpoints ---
546
+ else if (url === "/api/workflows" && method === "GET") {
547
+ res.writeHead(200);
548
+ res.end(JSON.stringify(CANNED_WORKFLOWS_LIST));
549
+ } else if (url?.match(/^\/api\/workflows\/[^/]+\/run$/) && method === "POST") {
550
+ res.writeHead(200);
551
+ res.end(JSON.stringify({ output: "workflow result" }));
552
+ } else if (url?.match(/^\/api\/workflows\/[^/]+$/) && method === "GET") {
553
+ res.writeHead(200);
554
+ res.end(JSON.stringify(CANNED_WORKFLOWS_LIST[0]));
555
+ } else if (url?.match(/^\/api\/workflows\/[^/]+$/) && method === "DELETE") {
556
+ res.writeHead(200);
557
+ res.end(JSON.stringify({ id: "wf_abc", archived: true }));
558
+ }
559
+ // --- Monitor endpoints ---
560
+ else if (url === "/api/monitors" && method === "GET") {
561
+ res.writeHead(200);
562
+ res.end(JSON.stringify([
563
+ { id: "mon_abc", name: "Toxicity Check", slug: "toxicity-check-x1y2z", checkType: "ragas/toxicity", enabled: true, executionMode: "ON_MESSAGE", sample: 1.0, level: "trace", evaluatorId: null, preconditions: [], parameters: {}, mappings: {}, threadIdleTimeout: null, createdAt: "2026-01-01T00:00:00Z", updatedAt: "2026-01-01T00:00:00Z" },
564
+ ]));
565
+ } else if (url === "/api/monitors" && method === "POST") {
566
+ res.writeHead(201);
567
+ res.end(JSON.stringify({ id: "mon_new", name: "New Monitor", slug: "new-monitor-abc12", checkType: "ragas/toxicity", enabled: true, executionMode: "ON_MESSAGE", sample: 1.0, level: "trace", evaluatorId: null, preconditions: [], parameters: {}, mappings: {}, threadIdleTimeout: null, createdAt: "2026-01-01T00:00:00Z", updatedAt: "2026-01-01T00:00:00Z" }));
568
+ } else if (url?.match(/^\/api\/monitors\/[^/]+\/toggle$/) && method === "POST") {
569
+ const monitorId = url?.split("/")[3];
570
+ res.writeHead(200);
571
+ res.end(JSON.stringify({ id: monitorId, enabled: true }));
572
+ } else if (url?.match(/^\/api\/monitors\/[^/]+$/) && method === "GET") {
573
+ res.writeHead(200);
574
+ res.end(JSON.stringify({ id: "mon_abc", name: "Toxicity Check", slug: "toxicity-check-x1y2z", checkType: "ragas/toxicity", enabled: true, executionMode: "ON_MESSAGE", sample: 1.0, level: "trace", evaluatorId: null, preconditions: [], parameters: {}, mappings: {}, threadIdleTimeout: null, createdAt: "2026-01-01T00:00:00Z", updatedAt: "2026-01-01T00:00:00Z" }));
575
+ } else if (url?.match(/^\/api\/monitors\/[^/]+$/) && method === "PATCH") {
576
+ res.writeHead(200);
577
+ res.end(JSON.stringify({ id: "mon_abc", name: "Updated Monitor", slug: "toxicity-check-x1y2z", checkType: "ragas/toxicity", enabled: false, executionMode: "ON_MESSAGE", sample: 0.5, level: "trace", evaluatorId: null, preconditions: [], parameters: {}, mappings: {}, threadIdleTimeout: null, createdAt: "2026-01-01T00:00:00Z", updatedAt: "2026-01-02T00:00:00Z" }));
578
+ } else if (url?.match(/^\/api\/monitors\/[^/]+$/) && method === "DELETE") {
579
+ const monitorId = url?.split("/").pop();
580
+ res.writeHead(200);
581
+ res.end(JSON.stringify({ id: monitorId, deleted: true }));
582
+ }
583
+ // --- Secret endpoints ---
584
+ else if (url === "/api/secrets" && method === "GET") {
585
+ res.writeHead(200);
586
+ res.end(JSON.stringify([
587
+ { id: "secret_abc", projectId: "proj_123", name: "MY_API_KEY", createdAt: "2026-01-01T00:00:00Z", updatedAt: "2026-01-01T00:00:00Z" },
588
+ { id: "secret_def", projectId: "proj_123", name: "DB_PASSWORD", createdAt: "2026-01-02T00:00:00Z", updatedAt: "2026-01-02T00:00:00Z" },
589
+ ]));
590
+ } else if (url === "/api/secrets" && method === "POST") {
591
+ res.writeHead(201);
592
+ res.end(JSON.stringify({ id: "secret_new", projectId: "proj_123", name: "NEW_SECRET", createdAt: "2026-01-03T00:00:00Z", updatedAt: "2026-01-03T00:00:00Z" }));
593
+ } else if (url?.match(/^\/api\/secrets\/[^/]+$/) && method === "PUT") {
594
+ res.writeHead(200);
595
+ res.end(JSON.stringify({ id: "secret_abc", projectId: "proj_123", name: "MY_API_KEY", createdAt: "2026-01-01T00:00:00Z", updatedAt: "2026-01-03T00:00:00Z" }));
596
+ } else if (url?.match(/^\/api\/secrets\/[^/]+$/) && method === "DELETE") {
597
+ const secretId = url?.split("/").pop();
598
+ res.writeHead(200);
599
+ res.end(JSON.stringify({ id: secretId, deleted: true }));
600
+ }
601
+ // --- Fallback ---
602
+ else {
603
+ res.writeHead(404);
604
+ res.end(
605
+ JSON.stringify({ message: `Not found: ${method} ${url}` }),
606
+ );
607
+ }
608
+ });
609
+ });
610
+ }
611
+
612
+ // --- Integration Tests ---
613
+ // These verify that every MCP tool handler correctly communicates with the REST API
614
+ // through a real HTTP server. Formatting/digest assertions ensure the full chain works.
615
+
616
+ describe("All MCP tools integration", () => {
617
+ let server: Server;
618
+ let port: number;
619
+ let originalFetch: typeof globalThis.fetch;
620
+
621
+ beforeAll(async () => {
622
+ server = createMockServer();
623
+ await new Promise<void>((resolve) => {
624
+ server.listen(0, () => {
625
+ const addr = server.address();
626
+ port = typeof addr === "object" && addr ? addr.port : 0;
627
+ initConfig({
628
+ apiKey: "test-integration-key",
629
+ endpoint: `http://localhost:${port}`,
630
+ });
631
+ resolve();
632
+ });
633
+ });
634
+ originalFetch = globalThis.fetch;
635
+ });
636
+
637
+ afterAll(async () => {
638
+ await new Promise<void>((resolve) => server.close(() => resolve()));
639
+ globalThis.fetch = originalFetch;
640
+ });
641
+
642
+ // =====================
643
+ // 1. fetch_langwatch_docs
644
+ // =====================
645
+ describe("fetch_langwatch_docs", () => {
646
+ describe("when fetching the docs index", () => {
647
+ it("returns content from the langwatch docs URL", async () => {
648
+ // Intercept fetch to avoid hitting the real network
649
+ const mockFetch = vi.fn().mockResolvedValue({
650
+ text: () =>
651
+ Promise.resolve(
652
+ "# LangWatch Docs\nWelcome to LangWatch documentation.",
653
+ ),
654
+ });
655
+ globalThis.fetch = mockFetch;
656
+
657
+ // The tool is inlined in index.ts; call the same logic directly
658
+ const url = "https://langwatch.ai/docs/llms.txt";
659
+ const response = await fetch(url);
660
+ const text = await response.text();
661
+
662
+ expect(text).toContain("LangWatch");
663
+ expect(mockFetch).toHaveBeenCalledWith(url);
664
+
665
+ globalThis.fetch = originalFetch;
666
+ });
667
+ });
668
+
669
+ describe("when fetching a specific doc page", () => {
670
+ it("appends .md extension when missing", async () => {
671
+ const mockFetch = vi.fn().mockResolvedValue({
672
+ text: () => Promise.resolve("# Integration Guide"),
673
+ });
674
+ globalThis.fetch = mockFetch;
675
+
676
+ let urlToFetch = "https://langwatch.ai/docs/integration";
677
+ if (
678
+ !urlToFetch.endsWith(".md") &&
679
+ !urlToFetch.endsWith(".txt")
680
+ ) {
681
+ urlToFetch += ".md";
682
+ }
683
+
684
+ const response = await fetch(urlToFetch);
685
+ const text = await response.text();
686
+
687
+ expect(text).toContain("Integration Guide");
688
+ expect(mockFetch).toHaveBeenCalledWith(
689
+ "https://langwatch.ai/docs/integration.md",
690
+ );
691
+
692
+ globalThis.fetch = originalFetch;
693
+ });
694
+ });
695
+
696
+ describe("when a relative path is provided", () => {
697
+ it("prepends the docs base URL", async () => {
698
+ const mockFetch = vi.fn().mockResolvedValue({
699
+ text: () => Promise.resolve("# Getting Started"),
700
+ });
701
+ globalThis.fetch = mockFetch;
702
+
703
+ let urlToFetch: string | undefined = "/getting-started";
704
+ if (urlToFetch && !urlToFetch.endsWith(".md") && !urlToFetch.endsWith(".txt")) {
705
+ urlToFetch += ".md";
706
+ }
707
+ if (!urlToFetch!.startsWith("http")) {
708
+ if (!urlToFetch!.startsWith("/")) {
709
+ urlToFetch = "/" + urlToFetch;
710
+ }
711
+ urlToFetch = "https://langwatch.ai/docs" + urlToFetch;
712
+ }
713
+
714
+ await fetch(urlToFetch);
715
+
716
+ expect(mockFetch).toHaveBeenCalledWith(
717
+ "https://langwatch.ai/docs/getting-started.md",
718
+ );
719
+
720
+ globalThis.fetch = originalFetch;
721
+ });
722
+ });
723
+ });
724
+
725
+ // =====================
726
+ // 2. fetch_scenario_docs
727
+ // =====================
728
+ describe("fetch_scenario_docs", () => {
729
+ describe("when fetching the scenario docs index", () => {
730
+ it("returns content from the scenario docs URL", async () => {
731
+ const mockFetch = vi.fn().mockResolvedValue({
732
+ text: () =>
733
+ Promise.resolve(
734
+ "# Scenario Testing\nLearn how to test agents.",
735
+ ),
736
+ });
737
+ globalThis.fetch = mockFetch;
738
+
739
+ const url = "https://langwatch.ai/scenario/llms.txt";
740
+ const response = await fetch(url);
741
+ const text = await response.text();
742
+
743
+ expect(text).toContain("Scenario Testing");
744
+ expect(mockFetch).toHaveBeenCalledWith(url);
745
+
746
+ globalThis.fetch = originalFetch;
747
+ });
748
+ });
749
+
750
+ describe("when fetching a specific scenario doc page", () => {
751
+ it("appends .md extension and prepends base URL for relative paths", async () => {
752
+ const mockFetch = vi.fn().mockResolvedValue({
753
+ text: () => Promise.resolve("# Setup Guide"),
754
+ });
755
+ globalThis.fetch = mockFetch;
756
+
757
+ let urlToFetch: string | undefined = "setup";
758
+ if (urlToFetch && !urlToFetch.endsWith(".md") && !urlToFetch.endsWith(".txt")) {
759
+ urlToFetch += ".md";
760
+ }
761
+ if (!urlToFetch!.startsWith("http")) {
762
+ if (!urlToFetch!.startsWith("/")) {
763
+ urlToFetch = "/" + urlToFetch;
764
+ }
765
+ urlToFetch = "https://langwatch.ai/scenario" + urlToFetch;
766
+ }
767
+
768
+ await fetch(urlToFetch);
769
+
770
+ expect(mockFetch).toHaveBeenCalledWith(
771
+ "https://langwatch.ai/scenario/setup.md",
772
+ );
773
+
774
+ globalThis.fetch = originalFetch;
775
+ });
776
+ });
777
+ });
778
+
779
+ // =====================
780
+ // 3. discover_schema
781
+ // =====================
782
+ describe("discover_schema", () => {
783
+ describe("when category is filters", () => {
784
+ it("returns filter field documentation", async () => {
785
+ const { formatSchema } = await import(
786
+ "../tools/discover-schema.js"
787
+ );
788
+ const result = formatSchema("filters");
789
+
790
+ expect(result).toContain("## Available Filter Fields");
791
+ expect(result).toContain("filters");
792
+ });
793
+ });
794
+
795
+ describe("when category is metrics", () => {
796
+ it("returns metric documentation", async () => {
797
+ const { formatSchema } = await import(
798
+ "../tools/discover-schema.js"
799
+ );
800
+ const result = formatSchema("metrics");
801
+
802
+ expect(result).toContain("## Available Metrics");
803
+ });
804
+ });
805
+
806
+ describe("when category is aggregations", () => {
807
+ it("returns aggregation types", async () => {
808
+ const { formatSchema } = await import(
809
+ "../tools/discover-schema.js"
810
+ );
811
+ const result = formatSchema("aggregations");
812
+
813
+ expect(result).toContain("## Available Aggregation Types");
814
+ expect(result).toContain("cardinality");
815
+ expect(result).toContain("avg");
816
+ expect(result).toContain("sum");
817
+ });
818
+ });
819
+
820
+ describe("when category is groups", () => {
821
+ it("returns group-by options", async () => {
822
+ const { formatSchema } = await import(
823
+ "../tools/discover-schema.js"
824
+ );
825
+ const result = formatSchema("groups");
826
+
827
+ expect(result).toContain("## Available Group-By Options");
828
+ });
829
+ });
830
+
831
+ describe("when category is scenarios", () => {
832
+ it("returns scenario schema documentation", async () => {
833
+ const { formatScenarioSchema } = await import(
834
+ "../tools/discover-scenario-schema.js"
835
+ );
836
+ const result = formatScenarioSchema();
837
+
838
+ expect(result).toContain("# Scenario Schema");
839
+ expect(result).toContain("**name** (required)");
840
+ expect(result).toContain("**situation** (required)");
841
+ });
842
+ });
843
+
844
+ describe("when category is evaluators", () => {
845
+ it("returns evaluator type overview", async () => {
846
+ const { formatEvaluatorSchema } = await import(
847
+ "../tools/discover-evaluator-schema.js"
848
+ );
849
+ const result = formatEvaluatorSchema();
850
+
851
+ expect(result).toContain("# Available Evaluator Types");
852
+ });
853
+ });
854
+
855
+ describe("when category is evaluators with specific type", () => {
856
+ it("returns detailed evaluator schema", async () => {
857
+ const { formatEvaluatorSchema } = await import(
858
+ "../tools/discover-evaluator-schema.js"
859
+ );
860
+ const result = formatEvaluatorSchema("langevals/llm_boolean");
861
+
862
+ expect(result).toContain("langevals/llm_boolean");
863
+ expect(result).toContain("## Settings");
864
+ });
865
+ });
866
+
867
+ describe("when evaluator type is unknown", () => {
868
+ it("returns an error message", async () => {
869
+ const { formatEvaluatorSchema } = await import(
870
+ "../tools/discover-evaluator-schema.js"
871
+ );
872
+ const result = formatEvaluatorSchema("nonexistent/type");
873
+
874
+ expect(result).toContain('Unknown evaluator type');
875
+ });
876
+ });
877
+
878
+ describe("when category is all", () => {
879
+ it("returns all schema categories", async () => {
880
+ const { formatSchema } = await import(
881
+ "../tools/discover-schema.js"
882
+ );
883
+ const result = formatSchema("all");
884
+
885
+ expect(result).toContain("## Available Filter Fields");
886
+ expect(result).toContain("## Available Metrics");
887
+ expect(result).toContain("## Available Aggregation Types");
888
+ expect(result).toContain("## Available Group-By Options");
889
+ });
890
+ });
891
+ });
892
+
893
+ // =====================
894
+ // 4. search_traces
895
+ // =====================
896
+ describe("search_traces", () => {
897
+ describe("when traces are found", () => {
898
+ it("returns formatted trace digests", async () => {
899
+ const { handleSearchTraces } = await import(
900
+ "../tools/search-traces.js"
901
+ );
902
+ const result = await handleSearchTraces({
903
+ startDate: "24h",
904
+ endDate: "now",
905
+ });
906
+
907
+ expect(result).toContain("trace-001");
908
+ expect(result).toContain("LLM Call [llm] 500ms");
909
+ expect(result).toContain("1 trace");
910
+ });
911
+ });
912
+
913
+ describe("when no traces match", () => {
914
+ it("returns a no-results message", async () => {
915
+ const { handleSearchTraces } = await import(
916
+ "../tools/search-traces.js"
917
+ );
918
+ const result = await handleSearchTraces({
919
+ query: "__empty__",
920
+ });
921
+
922
+ expect(result).toBe("No traces found matching your query.");
923
+ });
924
+ });
925
+
926
+ describe("when pagination token is present", () => {
927
+ it("includes scroll ID for next page", async () => {
928
+ const { handleSearchTraces } = await import(
929
+ "../tools/search-traces.js"
930
+ );
931
+ const result = await handleSearchTraces({
932
+ pageSize: 5,
933
+ });
934
+
935
+ expect(result).toContain("scroll-token-abc");
936
+ });
937
+ });
938
+
939
+ describe("when format is json", () => {
940
+ it("returns parseable JSON", async () => {
941
+ const { handleSearchTraces } = await import(
942
+ "../tools/search-traces.js"
943
+ );
944
+ const result = await handleSearchTraces({
945
+ format: "json",
946
+ });
947
+
948
+ const parsed = JSON.parse(result);
949
+ expect(parsed.traces).toBeDefined();
950
+ expect(parsed.traces.length).toBeGreaterThan(0);
951
+ expect(parsed.traces[0].trace_id).toBe("trace-001");
952
+ });
953
+ });
954
+
955
+ describe("when filters are applied", () => {
956
+ it("passes filters to the API", async () => {
957
+ const { handleSearchTraces } = await import(
958
+ "../tools/search-traces.js"
959
+ );
960
+ await handleSearchTraces({
961
+ filters: { "metadata.user_id": ["user-42"] },
962
+ });
963
+
964
+ const req = lastRequests["POST /api/traces/search"];
965
+ expect(req).toBeDefined();
966
+ const parsed = JSON.parse(req!.body);
967
+ expect(parsed.filters).toEqual({
968
+ "metadata.user_id": ["user-42"],
969
+ });
970
+ });
971
+ });
972
+ });
973
+
974
+ // =====================
975
+ // 5. get_trace
976
+ // =====================
977
+ describe("get_trace", () => {
978
+ describe("when trace exists", () => {
979
+ it("returns formatted trace with metadata and evaluations", async () => {
980
+ const { handleGetTrace } = await import(
981
+ "../tools/get-trace.js"
982
+ );
983
+ const result = await handleGetTrace({ traceId: "trace-001" });
984
+
985
+ expect(result).toContain("# Trace: trace-001");
986
+ expect(result).toContain("LLM Call [llm] 500ms");
987
+ expect(result).toContain("Faithfulness");
988
+ expect(result).toContain("PASSED");
989
+ expect(result).toContain("**User**: user-42");
990
+ expect(result).toContain("**Thread**: thread-1");
991
+ expect(result).toContain("**Customer**: cust-100");
992
+ });
993
+ });
994
+
995
+ describe("when trace does not exist", () => {
996
+ it("propagates the 404 error", async () => {
997
+ const { handleGetTrace } = await import(
998
+ "../tools/get-trace.js"
999
+ );
1000
+
1001
+ await expect(
1002
+ handleGetTrace({ traceId: "trace-nonexistent" }),
1003
+ ).rejects.toThrow("404");
1004
+ });
1005
+ });
1006
+
1007
+ describe("when format is json", () => {
1008
+ it("returns parseable JSON with full trace data", async () => {
1009
+ const { handleGetTrace } = await import(
1010
+ "../tools/get-trace.js"
1011
+ );
1012
+ const result = await handleGetTrace({
1013
+ traceId: "trace-001",
1014
+ format: "json",
1015
+ });
1016
+
1017
+ const parsed = JSON.parse(result);
1018
+ expect(parsed.trace_id).toBe("trace-001");
1019
+ expect(parsed.evaluations).toBeDefined();
1020
+ expect(parsed.metadata).toBeDefined();
1021
+ });
1022
+ });
1023
+ });
1024
+
1025
+ // =====================
1026
+ // 6. get_analytics
1027
+ // =====================
1028
+ describe("get_analytics", () => {
1029
+ describe("when data is available", () => {
1030
+ it("returns formatted analytics with markdown table", async () => {
1031
+ const { handleGetAnalytics } = await import(
1032
+ "../tools/get-analytics.js"
1033
+ );
1034
+ const result = await handleGetAnalytics({
1035
+ metric: "metadata.trace_id",
1036
+ aggregation: "cardinality",
1037
+ startDate: "7d",
1038
+ });
1039
+
1040
+ expect(result).toContain("42");
1041
+ expect(result).toContain("58");
1042
+ expect(result).toContain("| Date | Value |");
1043
+ });
1044
+ });
1045
+
1046
+ describe("when metric and aggregation are specified", () => {
1047
+ it("passes them through to the API", async () => {
1048
+ const { handleGetAnalytics } = await import(
1049
+ "../tools/get-analytics.js"
1050
+ );
1051
+ await handleGetAnalytics({
1052
+ metric: "performance.total_cost",
1053
+ aggregation: "sum",
1054
+ });
1055
+
1056
+ const req = lastRequests["POST /api/analytics/timeseries"];
1057
+ expect(req).toBeDefined();
1058
+ const parsed = JSON.parse(req!.body);
1059
+ expect(parsed.series[0].metric).toBe("performance.total_cost");
1060
+ expect(parsed.series[0].aggregation).toBe("sum");
1061
+ });
1062
+ });
1063
+ });
1064
+
1065
+ // =====================
1066
+ // 7. platform_create_prompt
1067
+ // =====================
1068
+ describe("platform_create_prompt", () => {
1069
+ describe("when valid data is provided", () => {
1070
+ it("returns success confirmation with prompt details", async () => {
1071
+ const { handleCreatePrompt } = await import(
1072
+ "../tools/create-prompt.js"
1073
+ );
1074
+ const result = await handleCreatePrompt({
1075
+ name: "New Prompt",
1076
+ messages: [{ role: "system", content: "You are helpful." }],
1077
+ model: "openai/gpt-4o",
1078
+ });
1079
+
1080
+ expect(result).toContain("created successfully");
1081
+ expect(result).toContain("p-new");
1082
+ expect(result).toContain("**Name**: New Prompt");
1083
+ expect(result).toContain("**Model**: openai/gpt-4o");
1084
+ });
1085
+ });
1086
+ });
1087
+
1088
+ // =====================
1089
+ // 8. platform_list_prompts
1090
+ // =====================
1091
+ describe("platform_list_prompts", () => {
1092
+ describe("when prompts exist", () => {
1093
+ it("returns formatted prompt list", async () => {
1094
+ const { handleListPrompts } = await import(
1095
+ "../tools/list-prompts.js"
1096
+ );
1097
+ const result = await handleListPrompts();
1098
+
1099
+ expect(result).toContain("greeting-bot");
1100
+ expect(result).toContain("Greeting Bot");
1101
+ expect(result).toContain("qa-assistant");
1102
+ expect(result).toContain("QA Assistant");
1103
+ expect(result).toContain("# Prompts (2 total)");
1104
+ });
1105
+ });
1106
+ });
1107
+
1108
+ // =====================
1109
+ // 9. platform_get_prompt
1110
+ // =====================
1111
+ describe("platform_get_prompt", () => {
1112
+ describe("when prompt exists", () => {
1113
+ it("returns formatted prompt details with messages and versions", async () => {
1114
+ const { handleGetPrompt } = await import(
1115
+ "../tools/get-prompt.js"
1116
+ );
1117
+ const result = await handleGetPrompt({
1118
+ idOrHandle: "greeting-bot",
1119
+ });
1120
+
1121
+ expect(result).toContain("# Prompt: Greeting Bot");
1122
+ expect(result).toContain("gpt-4o");
1123
+ expect(result).toContain("You are a friendly bot.");
1124
+ expect(result).toContain("v3");
1125
+ expect(result).toContain("## Version History");
1126
+ expect(result).toContain("Updated tone");
1127
+ });
1128
+ });
1129
+ });
1130
+
1131
+ // =====================
1132
+ // 10. platform_update_prompt
1133
+ // =====================
1134
+ describe("platform_update_prompt", () => {
1135
+ describe("when updating a prompt", () => {
1136
+ it("returns success message", async () => {
1137
+ const { handleUpdatePrompt } = await import(
1138
+ "../tools/update-prompt.js"
1139
+ );
1140
+ const result = await handleUpdatePrompt({
1141
+ idOrHandle: "greeting-bot",
1142
+ model: "openai/gpt-4o-mini",
1143
+ commitMessage: "Switch to mini",
1144
+ });
1145
+
1146
+ expect(result).toContain("updated successfully");
1147
+ expect(result).toContain("Switch to mini");
1148
+ });
1149
+ });
1150
+ });
1151
+
1152
+ // =====================
1153
+ // 11. platform_create_scenario
1154
+ // =====================
1155
+ describe("platform_create_scenario", () => {
1156
+ describe("when valid data is provided", () => {
1157
+ it("returns confirmation with new scenario ID", async () => {
1158
+ const { handleCreateScenario } = await import(
1159
+ "../tools/create-scenario.js"
1160
+ );
1161
+ const result = await handleCreateScenario({
1162
+ name: "New Scenario",
1163
+ situation: "User does something",
1164
+ criteria: ["Agent responds correctly"],
1165
+ labels: ["test"],
1166
+ });
1167
+
1168
+ expect(result).toContain("created successfully");
1169
+ expect(result).toContain("scen_new789");
1170
+ });
1171
+ });
1172
+ });
1173
+
1174
+ // =====================
1175
+ // 12. platform_list_scenarios
1176
+ // =====================
1177
+ describe("platform_list_scenarios", () => {
1178
+ describe("when scenarios exist", () => {
1179
+ it("returns formatted scenario list", async () => {
1180
+ const { handleListScenarios } = await import(
1181
+ "../tools/list-scenarios.js"
1182
+ );
1183
+ const result = await handleListScenarios({});
1184
+
1185
+ expect(result).toContain("# Scenarios (2 total)");
1186
+ expect(result).toContain("Login Flow Happy Path");
1187
+ expect(result).toContain("Password Reset");
1188
+ });
1189
+ });
1190
+
1191
+ describe("when format is json", () => {
1192
+ it("returns parseable JSON matching API response", async () => {
1193
+ const { handleListScenarios } = await import(
1194
+ "../tools/list-scenarios.js"
1195
+ );
1196
+ const result = await handleListScenarios({ format: "json" });
1197
+
1198
+ expect(JSON.parse(result)).toEqual(CANNED_SCENARIOS_LIST);
1199
+ });
1200
+ });
1201
+ });
1202
+
1203
+ // =====================
1204
+ // 13. platform_get_scenario
1205
+ // =====================
1206
+ describe("platform_get_scenario", () => {
1207
+ describe("when the scenario exists", () => {
1208
+ it("returns formatted scenario details", async () => {
1209
+ const { handleGetScenario } = await import(
1210
+ "../tools/get-scenario.js"
1211
+ );
1212
+ const result = await handleGetScenario({
1213
+ scenarioId: "scen_abc123",
1214
+ });
1215
+
1216
+ expect(result).toContain("# Scenario: Login Flow Happy Path");
1217
+ expect(result).toContain("User attempts to log in");
1218
+ expect(result).toContain("Responds with a welcome message");
1219
+ });
1220
+ });
1221
+
1222
+ describe("when the scenario does not exist", () => {
1223
+ it("propagates the 404 error", async () => {
1224
+ const { handleGetScenario } = await import(
1225
+ "../tools/get-scenario.js"
1226
+ );
1227
+
1228
+ await expect(
1229
+ handleGetScenario({ scenarioId: "scen_nonexistent" }),
1230
+ ).rejects.toThrow("404");
1231
+ });
1232
+ });
1233
+
1234
+ describe("when format is json", () => {
1235
+ it("returns parseable JSON", async () => {
1236
+ const { handleGetScenario } = await import(
1237
+ "../tools/get-scenario.js"
1238
+ );
1239
+ const result = await handleGetScenario({
1240
+ scenarioId: "scen_abc123",
1241
+ format: "json",
1242
+ });
1243
+
1244
+ expect(JSON.parse(result)).toEqual(CANNED_SCENARIO_DETAIL);
1245
+ });
1246
+ });
1247
+ });
1248
+
1249
+ // =====================
1250
+ // 14. platform_update_scenario
1251
+ // =====================
1252
+ describe("platform_update_scenario", () => {
1253
+ describe("when the scenario exists", () => {
1254
+ it("returns update confirmation with updated details", async () => {
1255
+ const { handleUpdateScenario } = await import(
1256
+ "../tools/update-scenario.js"
1257
+ );
1258
+ const result = await handleUpdateScenario({
1259
+ scenarioId: "scen_abc123",
1260
+ name: "Login Flow - Updated",
1261
+ });
1262
+
1263
+ expect(result).toContain("updated successfully");
1264
+ expect(result).toContain("scen_abc123");
1265
+ });
1266
+ });
1267
+ });
1268
+
1269
+ // =====================
1270
+ // 15. platform_archive_scenario
1271
+ // =====================
1272
+ describe("platform_archive_scenario", () => {
1273
+ describe("when the scenario exists", () => {
1274
+ it("returns confirmation that scenario was archived", async () => {
1275
+ const { handleArchiveScenario } = await import(
1276
+ "../tools/archive-scenario.js"
1277
+ );
1278
+ const result = await handleArchiveScenario({
1279
+ scenarioId: "scen_abc123",
1280
+ });
1281
+
1282
+ expect(result).toContain("archived successfully");
1283
+ expect(result).toContain("scen_abc123");
1284
+ expect(result).toContain("archived");
1285
+ });
1286
+ });
1287
+ });
1288
+
1289
+ // =====================
1290
+ // 16. platform_create_evaluator
1291
+ // =====================
1292
+ describe("platform_create_evaluator", () => {
1293
+ describe("when valid data is provided", () => {
1294
+ it("returns success confirmation with evaluator details", async () => {
1295
+ const { handleCreateEvaluator } = await import(
1296
+ "../tools/create-evaluator.js"
1297
+ );
1298
+ const result = await handleCreateEvaluator({
1299
+ name: "My LLM Judge",
1300
+ config: { evaluatorType: "langevals/llm_boolean" },
1301
+ });
1302
+
1303
+ expect(result).toContain("Evaluator created successfully!");
1304
+ expect(result).toContain("evaluator_new123");
1305
+ expect(result).toContain("my-llm-judge");
1306
+ expect(result).toContain("langevals/llm_boolean");
1307
+ });
1308
+ });
1309
+ });
1310
+
1311
+ // =====================
1312
+ // 17. platform_list_evaluators
1313
+ // =====================
1314
+ describe("platform_list_evaluators", () => {
1315
+ describe("when evaluators exist", () => {
1316
+ it("returns formatted evaluator list", async () => {
1317
+ const { handleListEvaluators } = await import(
1318
+ "../tools/list-evaluators.js"
1319
+ );
1320
+ const result = await handleListEvaluators();
1321
+
1322
+ expect(result).toContain("# Evaluators (2 total)");
1323
+ expect(result).toContain("Toxicity Check");
1324
+ expect(result).toContain("toxicity-check");
1325
+ expect(result).toContain("openai/moderation");
1326
+ expect(result).toContain("Exact Match");
1327
+ expect(result).toContain("exact-match");
1328
+ });
1329
+ });
1330
+ });
1331
+
1332
+ // =====================
1333
+ // 18. platform_get_evaluator
1334
+ // =====================
1335
+ describe("platform_get_evaluator", () => {
1336
+ describe("when the evaluator exists", () => {
1337
+ it("returns formatted evaluator details with config and fields", async () => {
1338
+ const { handleGetEvaluator } = await import(
1339
+ "../tools/get-evaluator.js"
1340
+ );
1341
+ const result = await handleGetEvaluator({
1342
+ idOrSlug: "evaluator_abc123",
1343
+ });
1344
+
1345
+ expect(result).toContain("# Evaluator: Toxicity Check");
1346
+ expect(result).toContain("openai/moderation");
1347
+ expect(result).toContain("text-moderation-stable");
1348
+ expect(result).toContain("## Input Fields");
1349
+ expect(result).toContain("**input** (str)");
1350
+ expect(result).toContain("## Output Fields");
1351
+ expect(result).toContain("**passed** (bool)");
1352
+ expect(result).toContain("**score** (float)");
1353
+ });
1354
+ });
1355
+
1356
+ describe("when the evaluator does not exist", () => {
1357
+ it("propagates the 404 error", async () => {
1358
+ const { handleGetEvaluator } = await import(
1359
+ "../tools/get-evaluator.js"
1360
+ );
1361
+
1362
+ await expect(
1363
+ handleGetEvaluator({ idOrSlug: "evaluator_nonexistent" }),
1364
+ ).rejects.toThrow("404");
1365
+ });
1366
+ });
1367
+ });
1368
+
1369
+ // =====================
1370
+ // 19. platform_update_evaluator
1371
+ // =====================
1372
+ describe("platform_update_evaluator", () => {
1373
+ describe("when the evaluator exists", () => {
1374
+ it("returns update confirmation", async () => {
1375
+ const { handleUpdateEvaluator } = await import(
1376
+ "../tools/update-evaluator.js"
1377
+ );
1378
+ const result = await handleUpdateEvaluator({
1379
+ evaluatorId: "evaluator_abc123",
1380
+ name: "Updated Toxicity",
1381
+ });
1382
+
1383
+ expect(result).toContain("Evaluator updated successfully!");
1384
+ expect(result).toContain("evaluator_abc123");
1385
+ expect(result).toContain("Updated Toxicity");
1386
+ });
1387
+ });
1388
+ });
1389
+
1390
+ // =====================
1391
+ // 20. platform_set_model_provider
1392
+ // =====================
1393
+ describe("platform_set_model_provider", () => {
1394
+ describe("when setting a provider with API key", () => {
1395
+ it("returns success confirmation with provider details", async () => {
1396
+ const { handleSetModelProvider } = await import(
1397
+ "../tools/set-model-provider.js"
1398
+ );
1399
+ const result = await handleSetModelProvider({
1400
+ provider: "openai",
1401
+ enabled: true,
1402
+ customKeys: { OPENAI_API_KEY: "sk-test123" },
1403
+ });
1404
+
1405
+ expect(result).toContain("Model provider updated successfully!");
1406
+ expect(result).toContain("**Provider**: openai");
1407
+ expect(result).toContain("**Status**: enabled");
1408
+ expect(result).toContain("OPENAI_API_KEY: set");
1409
+ });
1410
+ });
1411
+
1412
+ describe("when setting a default model", () => {
1413
+ it("shows the normalized model name with provider prefix", async () => {
1414
+ const { handleSetModelProvider } = await import(
1415
+ "../tools/set-model-provider.js"
1416
+ );
1417
+ const result = await handleSetModelProvider({
1418
+ provider: "openai",
1419
+ enabled: true,
1420
+ defaultModel: "gpt-4o",
1421
+ });
1422
+
1423
+ expect(result).toContain("**Default Model**: openai/gpt-4o");
1424
+ });
1425
+ });
1426
+ });
1427
+
1428
+ // =====================
1429
+ // 21. platform_list_model_providers
1430
+ // =====================
1431
+ describe("platform_list_model_providers", () => {
1432
+ describe("when providers exist", () => {
1433
+ it("returns formatted provider list with status and key info", async () => {
1434
+ const { handleListModelProviders } = await import(
1435
+ "../tools/list-model-providers.js"
1436
+ );
1437
+ const result = await handleListModelProviders();
1438
+
1439
+ expect(result).toContain("# Model Providers (2 total)");
1440
+ expect(result).toContain("## openai");
1441
+ expect(result).toContain("**Status**: enabled");
1442
+ expect(result).toContain("## anthropic");
1443
+ expect(result).toContain("**Status**: disabled");
1444
+ expect(result).toContain("OPENAI_API_KEY: set");
1445
+ expect(result).toContain("2 available");
1446
+ });
1447
+ });
1448
+ });
1449
+
1450
+ // =====================
1451
+ // Cross-cutting: authentication
1452
+ // =====================
1453
+ describe("when API key is invalid", () => {
1454
+ afterAll(() => {
1455
+ initConfig({
1456
+ apiKey: "test-integration-key",
1457
+ endpoint: `http://localhost:${port}`,
1458
+ });
1459
+ });
1460
+
1461
+ it("throws an error with 401 status for trace search", async () => {
1462
+ initConfig({
1463
+ apiKey: "bad-key",
1464
+ endpoint: `http://localhost:${port}`,
1465
+ });
1466
+
1467
+ const { handleSearchTraces } = await import(
1468
+ "../tools/search-traces.js"
1469
+ );
1470
+ await expect(
1471
+ handleSearchTraces({ startDate: "24h" }),
1472
+ ).rejects.toThrow("401");
1473
+ });
1474
+
1475
+ it("throws an error with 401 status for evaluator list", async () => {
1476
+ initConfig({
1477
+ apiKey: "bad-key",
1478
+ endpoint: `http://localhost:${port}`,
1479
+ });
1480
+
1481
+ const { handleListEvaluators } = await import(
1482
+ "../tools/list-evaluators.js"
1483
+ );
1484
+ await expect(handleListEvaluators()).rejects.toThrow("401");
1485
+ });
1486
+
1487
+ it("throws an error with 401 status for model providers list", async () => {
1488
+ initConfig({
1489
+ apiKey: "bad-key",
1490
+ endpoint: `http://localhost:${port}`,
1491
+ });
1492
+
1493
+ const { handleListModelProviders } = await import(
1494
+ "../tools/list-model-providers.js"
1495
+ );
1496
+ await expect(handleListModelProviders()).rejects.toThrow("401");
1497
+ });
1498
+ });
1499
+
1500
+ // =====================
1501
+ // Suite Tools
1502
+ // =====================
1503
+ describe("platform_list_suites", () => {
1504
+ it("returns formatted suite list", async () => {
1505
+ const { handleListSuites } = await import("../tools/list-suites.js");
1506
+ const result = await handleListSuites({});
1507
+
1508
+ expect(result).toContain("Suites / Run Plans (1 total)");
1509
+ expect(result).toContain("Regression Suite");
1510
+ });
1511
+ });
1512
+
1513
+ describe("platform_get_suite", () => {
1514
+ it("returns suite details", async () => {
1515
+ const { handleGetSuite } = await import("../tools/get-suite.js");
1516
+ const result = await handleGetSuite({ id: "suite_abc" });
1517
+
1518
+ expect(result).toContain("Regression Suite");
1519
+ expect(result).toContain("suite_abc");
1520
+ });
1521
+ });
1522
+
1523
+ describe("platform_create_suite", () => {
1524
+ it("creates a suite and returns confirmation", async () => {
1525
+ const { handleCreateSuite } = await import("../tools/create-suite.js");
1526
+ const result = await handleCreateSuite({
1527
+ name: "New Suite",
1528
+ scenarioIds: ["scen_abc123"],
1529
+ targets: JSON.stringify([{ type: "http", referenceId: "agent_abc" }]),
1530
+ });
1531
+
1532
+ expect(result).toContain("created successfully");
1533
+ expect(result).toContain("New Suite");
1534
+ });
1535
+ });
1536
+
1537
+ describe("platform_run_suite", () => {
1538
+ it("triggers a suite run and returns batch info", async () => {
1539
+ const { handleRunSuite } = await import("../tools/run-suite.js");
1540
+ const result = await handleRunSuite({ id: "suite_abc" });
1541
+
1542
+ expect(result).toContain("scheduled successfully");
1543
+ expect(result).toContain("batch_123");
1544
+ });
1545
+ });
1546
+
1547
+ describe("platform_archive_suite", () => {
1548
+ it("archives the suite", async () => {
1549
+ const { handleArchiveSuite } = await import("../tools/archive-suite.js");
1550
+ const result = await handleArchiveSuite({ id: "suite_abc" });
1551
+
1552
+ expect(result).toContain("archived");
1553
+ });
1554
+ });
1555
+
1556
+ // =====================
1557
+ // Simulation Run Tools
1558
+ // =====================
1559
+ describe("platform_list_simulation_runs", () => {
1560
+ it("returns formatted run list", async () => {
1561
+ const { handleListSimulationRuns } = await import("../tools/list-simulation-runs.js");
1562
+ const result = await handleListSimulationRuns({});
1563
+
1564
+ expect(result).toContain("Simulation Runs");
1565
+ expect(result).toContain("Login Flow");
1566
+ });
1567
+ });
1568
+
1569
+ describe("platform_get_simulation_run", () => {
1570
+ it("returns run details with conversation", async () => {
1571
+ const { handleGetSimulationRun } = await import("../tools/get-simulation-run.js");
1572
+ const result = await handleGetSimulationRun({ scenarioRunId: "run_abc" });
1573
+
1574
+ expect(result).toContain("Login Flow");
1575
+ expect(result).toContain("passed");
1576
+ expect(result).toContain("Hello");
1577
+ });
1578
+ });
1579
+
1580
+ // =====================
1581
+ // Monitor Tools
1582
+ // =====================
1583
+ describe("platform_list_monitors", () => {
1584
+ it("returns formatted monitor list", async () => {
1585
+ const { listMonitors } = await import("../langwatch-api-monitors.js");
1586
+ const monitors = await listMonitors();
1587
+ expect(monitors).toHaveLength(1);
1588
+ expect(monitors[0]!.name).toBe("Toxicity Check");
1589
+ expect(monitors[0]!.checkType).toBe("ragas/toxicity");
1590
+ });
1591
+ });
1592
+
1593
+ describe("platform_get_monitor", () => {
1594
+ it("returns monitor details", async () => {
1595
+ const { getMonitor } = await import("../langwatch-api-monitors.js");
1596
+ const monitor = await getMonitor("mon_abc");
1597
+ expect(monitor.id).toBe("mon_abc");
1598
+ expect(monitor.name).toBe("Toxicity Check");
1599
+ expect(monitor.enabled).toBe(true);
1600
+ });
1601
+ });
1602
+
1603
+ describe("platform_create_monitor", () => {
1604
+ it("creates a monitor and returns metadata", async () => {
1605
+ const { createMonitor } = await import("../langwatch-api-monitors.js");
1606
+ const monitor = await createMonitor({ name: "New Monitor", checkType: "ragas/toxicity" });
1607
+ expect(monitor.id).toBe("mon_new");
1608
+ expect(monitor.name).toBe("New Monitor");
1609
+ });
1610
+ });
1611
+
1612
+ describe("platform_update_monitor", () => {
1613
+ it("updates a monitor", async () => {
1614
+ const { updateMonitor } = await import("../langwatch-api-monitors.js");
1615
+ const monitor = await updateMonitor({ id: "mon_abc", enabled: false });
1616
+ expect(monitor.id).toBe("mon_abc");
1617
+ expect(monitor.enabled).toBe(false);
1618
+ });
1619
+ });
1620
+
1621
+ describe("platform_delete_monitor", () => {
1622
+ it("deletes a monitor", async () => {
1623
+ const { deleteMonitor } = await import("../langwatch-api-monitors.js");
1624
+ const result = await deleteMonitor("mon_abc");
1625
+ expect(result.id).toBe("mon_abc");
1626
+ expect(result.deleted).toBe(true);
1627
+ });
1628
+ });
1629
+
1630
+ // =====================
1631
+ // Secret Tools
1632
+ // =====================
1633
+ describe("platform_list_secrets", () => {
1634
+ it("returns formatted secret list", async () => {
1635
+ const { listSecrets } = await import("../langwatch-api-secrets.js");
1636
+ const secrets = await listSecrets();
1637
+ expect(secrets).toHaveLength(2);
1638
+ expect(secrets[0]!.name).toBe("MY_API_KEY");
1639
+ });
1640
+ });
1641
+
1642
+ describe("platform_create_secret", () => {
1643
+ it("creates a secret and returns metadata", async () => {
1644
+ const { createSecret } = await import("../langwatch-api-secrets.js");
1645
+ const secret = await createSecret({ name: "NEW_SECRET", value: "sk-123" });
1646
+ expect(secret.id).toBe("secret_new");
1647
+ expect(secret.name).toBe("NEW_SECRET");
1648
+ });
1649
+ });
1650
+
1651
+ describe("platform_update_secret", () => {
1652
+ it("updates a secret value", async () => {
1653
+ const { updateSecret } = await import("../langwatch-api-secrets.js");
1654
+ const secret = await updateSecret({ id: "secret_abc", value: "new-val" });
1655
+ expect(secret.id).toBe("secret_abc");
1656
+ expect(secret.name).toBe("MY_API_KEY");
1657
+ });
1658
+ });
1659
+
1660
+ describe("platform_delete_secret", () => {
1661
+ it("deletes a secret", async () => {
1662
+ const { deleteSecret } = await import("../langwatch-api-secrets.js");
1663
+ const result = await deleteSecret("secret_abc");
1664
+ expect(result.id).toBe("secret_abc");
1665
+ expect(result.deleted).toBe(true);
1666
+ });
1667
+ });
1668
+
1669
+ // =====================
1670
+ // Agent Run Tool
1671
+ // =====================
1672
+ describe("platform_run_workflow", () => {
1673
+ it("executes a workflow and returns result", async () => {
1674
+ const { handleRunWorkflow } = await import("../tools/run-workflow.js");
1675
+ const result = await handleRunWorkflow({ id: "wf_abc" });
1676
+
1677
+ expect(result).toContain("executed successfully");
1678
+ expect(result).toContain("workflow result");
1679
+ });
1680
+ });
1681
+ });