@langwatch/server 3.1.0-beta.21 → 3.1.0-beta.22

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 (171) hide show
  1. package/langevals/evaluators/topic_clustering/langevals_topic_clustering/__init__.py +36 -0
  2. package/langevals/evaluators/topic_clustering/langevals_topic_clustering/_logger.py +165 -0
  3. package/langevals/evaluators/topic_clustering/langevals_topic_clustering/batch_clustering.py +153 -0
  4. package/langevals/evaluators/topic_clustering/langevals_topic_clustering/build_response.py +77 -0
  5. package/langevals/evaluators/topic_clustering/langevals_topic_clustering/constants.py +7 -0
  6. package/langevals/evaluators/topic_clustering/langevals_topic_clustering/incremental_clustering.py +325 -0
  7. package/langevals/evaluators/topic_clustering/langevals_topic_clustering/topic_naming.py +432 -0
  8. package/langevals/evaluators/topic_clustering/langevals_topic_clustering/types.py +42 -0
  9. package/langevals/evaluators/topic_clustering/langevals_topic_clustering/utils.py +191 -0
  10. package/langevals/evaluators/topic_clustering/pyproject.toml +52 -0
  11. package/langevals/evaluators/topic_clustering/tests/test_topic_clustering.py +239 -0
  12. package/langevals/evaluators/topic_clustering/tests/test_topic_clustering_integration.py +97 -0
  13. package/langevals/evaluators/topic_clustering/tests/test_topic_naming.py +72 -0
  14. package/langevals/langevals/pytest_plugins/pass_rate_plugin.py +7 -1
  15. package/langevals/langevals/server.py +28 -0
  16. package/langevals/pyproject.toml +3 -0
  17. package/langevals/uv.lock +119 -20
  18. package/langwatch/dist/client/assets/{AnnotationsTable-BDAkYaz6.js → AnnotationsTable-uS_9SQ-g.js} +2 -2
  19. package/langwatch/dist/client/assets/{BatchEvaluationSummary-DMaQM_VB.js → BatchEvaluationSummary-DtFd8yKJ.js} +2 -2
  20. package/langwatch/dist/client/assets/{BudgetEditDrawer-CHaqmdIl.js → BudgetEditDrawer-CHEPz0hH.js} +2 -2
  21. package/langwatch/dist/client/assets/{ChartCard-D14PUg_d.js → ChartCard-s5fMPo7b.js} +2 -2
  22. package/langwatch/dist/client/assets/{ChatWindow-CRDnlP-Q.js → ChatWindow-C0XSteVJ.js} +2 -2
  23. package/langwatch/dist/client/assets/ChatWindow-DFEmNXQL.js +1 -0
  24. package/langwatch/dist/client/assets/{ConfirmDialog-CXIhncvW.js → ConfirmDialog-M94yLNvP.js} +2 -2
  25. package/langwatch/dist/client/assets/{ContactSalesBlock-CijLBwRC.js → ContactSalesBlock-CnnuZ8iI.js} +2 -2
  26. package/langwatch/dist/client/assets/{DSPyExperiment-B1YOL2m8.js → DSPyExperiment-CMA6lrlx.js} +2 -2
  27. package/langwatch/dist/client/assets/{FilterDisplay-BB0xWrLn.js → FilterDisplay-0S3NqCkq.js} +2 -2
  28. package/langwatch/dist/client/assets/{FormatMoney-w9vr_h0X.js → FormatMoney-CCygtAHg.js} +2 -2
  29. package/langwatch/dist/client/assets/{FoundryDrawer-CdJDXtpz.js → FoundryDrawer-B35xZ26C.js} +2 -2
  30. package/langwatch/dist/client/assets/{GatewayErrorPanel-DvE9U2dS.js → GatewayErrorPanel-BsaYQEie.js} +2 -2
  31. package/langwatch/dist/client/assets/{GatewayLayout-lv1p_6B5.js → GatewayLayout-LvwwrwMf.js} +2 -2
  32. package/langwatch/dist/client/assets/{GraphsLayout-BJ68J9e-.js → GraphsLayout-DJ-HI9N1.js} +2 -2
  33. package/langwatch/dist/client/assets/{GroupBindingInputRow-DebZBCnD.js → GroupBindingInputRow-CV-fBkX9.js} +2 -2
  34. package/langwatch/dist/client/assets/{MessagesTable-B6lYde-x.js → MessagesTable-9taaKCOZ.js} +2 -2
  35. package/langwatch/dist/client/assets/{NavigationFooter-CiOVzDUh.js → NavigationFooter-Dzvauw3l.js} +2 -2
  36. package/langwatch/dist/client/assets/{NoDataInfoBlock-quSW_MRm.js → NoDataInfoBlock-CLKl_wlX.js} +2 -2
  37. package/langwatch/dist/client/assets/{OpsPageShell-DJ1WlI6-.js → OpsPageShell-C_mTziRS.js} +2 -2
  38. package/langwatch/dist/client/assets/{OptimizationStudio-BlozXjcN.js → OptimizationStudio-D2zpsmJj.js} +8 -12
  39. package/langwatch/dist/client/assets/{PreconditionsField-BOfcWvmZ.js → PreconditionsField-WXB8kcTK.js} +2 -2
  40. package/langwatch/dist/client/assets/{SettingsLayout-CLCGxMAe.js → SettingsLayout--1gdEuhv.js} +2 -2
  41. package/langwatch/dist/client/assets/{SubscriptionPage-J8b2Zaj6.js → SubscriptionPage-B0ox_4kM.js} +2 -2
  42. package/langwatch/dist/client/assets/{VirtualKeySecretReveal-DR1VDLy7.js → VirtualKeySecretReveal-CRbI1dKQ.js} +2 -2
  43. package/langwatch/dist/client/assets/{WithPermissionGuard-DD8uo3UK.js → WithPermissionGuard-B4Jo8E5-.js} +2 -2
  44. package/langwatch/dist/client/assets/{__...path__-BZVaIayJ.js → __...path__-BF2zkD84.js} +2 -2
  45. package/langwatch/dist/client/assets/{_experiment_-B1aT-wS3.js → _experiment_-D02aoVQk.js} +2 -2
  46. package/langwatch/dist/client/assets/{_id_-oI_eq-I_.js → _id_-Ch8YmTiM.js} +2 -2
  47. package/langwatch/dist/client/assets/{_id_-DAqPuO73.js → _id_-D6ZvwHpH.js} +2 -2
  48. package/langwatch/dist/client/assets/{_id_-DUngklVb.js → _id_-DOC1ZkBm.js} +2 -2
  49. package/langwatch/dist/client/assets/{_id_-jFDAfbob.js → _id_-DfWwW6_N.js} +2 -2
  50. package/langwatch/dist/client/assets/{_id_-BKBrWGG0.js → _id_-DxUo4W7J.js} +2 -2
  51. package/langwatch/dist/client/assets/_not-found-DDh108-i.js +1 -0
  52. package/langwatch/dist/client/assets/{_project_-Bt1tayHB.js → _project_-_UUt5Ar9.js} +2 -2
  53. package/langwatch/dist/client/assets/{_runId_-CfvnDt5H.js → _runId_-Dimwzp48.js} +2 -2
  54. package/langwatch/dist/client/assets/_slug_-BMvKBwS_.js +2 -0
  55. package/langwatch/dist/client/assets/{_slug_-DZAdl0QS.js → _slug_-CE6VoDSC.js} +2 -2
  56. package/langwatch/dist/client/assets/{_slug_-DmoWXjKT.js → _slug_-OiOLG1Mv.js} +2 -2
  57. package/langwatch/dist/client/assets/{_team_-DL_wKSWK.js → _team_-DKvmwO_5.js} +2 -2
  58. package/langwatch/dist/client/assets/{_workflow_-DcMXLPUe.js → _workflow_-FkilKiB-.js} +3 -3
  59. package/langwatch/dist/client/assets/{_workflow_-NI9bac7d.js → _workflow_-gJZppg3h.js} +2 -2
  60. package/langwatch/dist/client/assets/{access-audit-CFwNwusI.js → access-audit-xcUVYMMT.js} +2 -2
  61. package/langwatch/dist/client/assets/{agents-Di4XRwcn.js → agents-D32g91cu.js} +2 -2
  62. package/langwatch/dist/client/assets/{all-C273mlDB.js → all-vnREzDZj.js} +2 -2
  63. package/langwatch/dist/client/assets/{analytics-CEAcSf6B.js → analytics-DP6Y4Feh.js} +2 -2
  64. package/langwatch/dist/client/assets/{annotation-scores-CHfn4LQp.js → annotation-scores-CjD4CEB6.js} +2 -2
  65. package/langwatch/dist/client/assets/{annotations-CHZQrha6.js → annotations-1rVXiDRQ.js} +2 -2
  66. package/langwatch/dist/client/assets/{api-keys-BT7HExHM.js → api-keys-BJpKyuaz.js} +2 -2
  67. package/langwatch/dist/client/assets/{audit-log-BGk-51Dt.js → audit-log-BdUdZjxp.js} +2 -2
  68. package/langwatch/dist/client/assets/{authentication-DvwXfkp-.js → authentication-8mQB00CC.js} +2 -2
  69. package/langwatch/dist/client/assets/{authorize-tXpHrWyw.js → authorize-BpUueMNW.js} +2 -2
  70. package/langwatch/dist/client/assets/{authorize-CRu9xlpU.js → authorize-CbNBtmxW.js} +2 -2
  71. package/langwatch/dist/client/assets/{automations-CjDvz9Ak.js → automations-34KMkRxd.js} +2 -2
  72. package/langwatch/dist/client/assets/{billing-plans-FUqEPN62.js → billing-plans-BUQp08MI.js} +2 -2
  73. package/langwatch/dist/client/assets/{budgets-BV6_RHrs.js → budgets-CdelE8Hv.js} +2 -2
  74. package/langwatch/dist/client/assets/{cache-rules-CtYA79E_.js → cache-rules-D2m1QlNJ.js} +2 -2
  75. package/langwatch/dist/client/assets/choose-C0LdeUiH.js +2 -0
  76. package/langwatch/dist/client/assets/{command-bar-CaJygoez.js → command-bar-DUK45yin.js} +7 -9
  77. package/langwatch/dist/client/assets/custom-hBq2K4FJ.js +1 -0
  78. package/langwatch/dist/client/assets/{datasets-vLWpH84_.js → datasets-ErNNhmjg.js} +2 -2
  79. package/langwatch/dist/client/assets/{dejaview-DwVR3RGg.js → dejaview-BaD4_v90.js} +2 -2
  80. package/langwatch/dist/client/assets/{dist-SwV3YZv3.js → dist-Cds4Mqhj.js} +4 -6
  81. package/langwatch/dist/client/assets/{edit-CyxsmQmW.js → edit-DpT8ejBV.js} +2 -2
  82. package/langwatch/dist/client/assets/{evaluations-BfgeZMph.js → evaluations-BdQ2Dm2r.js} +2 -2
  83. package/langwatch/dist/client/assets/{evaluations-HSQIMvbX.js → evaluations-C90I4VAr.js} +2 -2
  84. package/langwatch/dist/client/assets/{evaluators-DLHVvnrh.js → evaluators-ig_ugRLt.js} +2 -2
  85. package/langwatch/dist/client/assets/{foundry-Ckq0WjPU.js → foundry-B-X_80pD.js} +2 -2
  86. package/langwatch/dist/client/assets/{gateway-CDSYPZ6w.js → gateway-CS_mtJx-.js} +2 -2
  87. package/langwatch/dist/client/assets/{groups-CCCRUqPj.js → groups-Bp90ChP3.js} +2 -2
  88. package/langwatch/dist/client/assets/{index-Bm6z2fM9.js → index-TNQ6uyis.js} +4 -4
  89. package/langwatch/dist/client/assets/{license-CHOarGWr.js → license-CgnlvyuI.js} +2 -2
  90. package/langwatch/dist/client/assets/{me-CBya_vXs.js → me-DEqhm_KC.js} +2 -2
  91. package/langwatch/dist/client/assets/{members-lIFLh-rh.js → members-CUJANDtH.js} +2 -2
  92. package/langwatch/dist/client/assets/{messages-CG9j8Dz8.js → messages-fQBfCjvp.js} +2 -2
  93. package/langwatch/dist/client/assets/{metrics-C9pzeaI6.js → metrics-DeIxebpD.js} +2 -2
  94. package/langwatch/dist/client/assets/{model-costs-Bc5uqjkl.js → model-costs-C1RbgK--.js} +2 -2
  95. package/langwatch/dist/client/assets/{model-providers-B5UjRgS_.js → model-providers-Pv3ML_-t.js} +2 -2
  96. package/langwatch/dist/client/assets/{my-queue-BkEfiWyR.js → my-queue-BLre2NMr.js} +2 -2
  97. package/langwatch/dist/client/assets/{ops-Cc-g-CMn.js → ops-CCw-FJaT.js} +2 -2
  98. package/langwatch/dist/client/assets/{organization-features-CoIKKHkQ.js → organization-features-rqg-75mI.js} +2 -2
  99. package/langwatch/dist/client/assets/{organizations-DWcQUTzi.js → organizations-DjCzIHVx.js} +2 -2
  100. package/langwatch/dist/client/assets/{persistence-CTQ44vGL.js → persistence-BPvHS0F6.js} +2 -2
  101. package/langwatch/dist/client/assets/{plans-Dq3eFg5K.js → plans-Ch2Ol-Fd.js} +2 -2
  102. package/langwatch/dist/client/assets/{projections-CTNj1QBM.js → projections-it4FOVjm.js} +2 -2
  103. package/langwatch/dist/client/assets/{projects-BxM7C87h.js → projects-CjWZFLfn.js} +2 -2
  104. package/langwatch/dist/client/assets/{prompts-DhXnJT6e.js → prompts-DilmFH_s.js} +2 -2
  105. package/langwatch/dist/client/assets/{providers-DW7VWdqq.js → providers-tlLT_lTF.js} +2 -2
  106. package/langwatch/dist/client/assets/{reports-D3QFKhNP.js → reports-vlrcTrLs.js} +2 -2
  107. package/langwatch/dist/client/assets/{roles-B_0t5DWA.js → roles-DNgi-NQ9.js} +2 -2
  108. package/langwatch/dist/client/assets/{scenarios-BX3XslU0.js → scenarios-BmG_wDkR.js} +2 -2
  109. package/langwatch/dist/client/assets/{scim-DDsLO39r.js → scim-BKr1_FHt.js} +2 -2
  110. package/langwatch/dist/client/assets/{secrets-BvEGwDCy.js → secrets-CU8ocTGv.js} +2 -2
  111. package/langwatch/dist/client/assets/{settings-9giNiAQQ.js → settings-CDzdoYVK.js} +2 -2
  112. package/langwatch/dist/client/assets/{setup-HxXKoVKG.js → setup-nEvn2rjN.js} +2 -2
  113. package/langwatch/dist/client/assets/{subscription-DhyswDze.js → subscription-BPNl_6jF.js} +3 -3
  114. package/langwatch/dist/client/assets/{subscriptions-Dyyau22a.js → subscriptions-D0G-OE5C.js} +2 -2
  115. package/langwatch/dist/client/assets/{teams-DRmeAxzf.js → teams-DThgDQvB.js} +2 -2
  116. package/langwatch/dist/client/assets/{textOverflowHeuristic-JibhpzDV.js → textOverflowHeuristic-DTC8-Ffx.js} +2 -2
  117. package/langwatch/dist/client/assets/{topic-clustering-Bllfw5rZ.js → topic-clustering-BR2Mbpao.js} +2 -2
  118. package/langwatch/dist/client/assets/{topics-CpiGYxqb.js → topics-CI8GoNqp.js} +2 -2
  119. package/langwatch/dist/client/assets/{traceExecutor-CiHXJB0V.js → traceExecutor-CDUGyUaw.js} +2 -2
  120. package/langwatch/dist/client/assets/{usage-BnsstwBY.js → usage-B4mR7ut_.js} +2 -2
  121. package/langwatch/dist/client/assets/{usage-CoyGtJoI.js → usage-C8fbffYi.js} +2 -2
  122. package/langwatch/dist/client/assets/{useAdminResource-SPC5iBHM.js → useAdminResource-SmnnHro6.js} +2 -2
  123. package/langwatch/dist/client/assets/{useAnnotationQueues-2DKZTC7r.js → useAnnotationQueues-CA6Vk--V.js} +2 -2
  124. package/langwatch/dist/client/assets/{useAvailableEvaluators-HndTl2LV.js → useAvailableEvaluators-hmbmcRQr.js} +2 -2
  125. package/langwatch/dist/client/assets/{useDeleteDatasetConfirmation-BgWN6Qqb.js → useDeleteDatasetConfirmation-BCK_zUUe.js} +2 -2
  126. package/langwatch/dist/client/assets/{useWorkflowStore-e1wFCvo2.js → useWorkflowStore-QUJ3J8X9.js} +2 -2
  127. package/langwatch/dist/client/assets/{users-C6wjliCC.js → users-CfhanCfR.js} +2 -2
  128. package/langwatch/dist/client/assets/{users-tF6ZKeV1.js → users-HjuN3o6k.js} +2 -2
  129. package/langwatch/dist/client/assets/{virtual-keys-BL-65S0B.js → virtual-keys-Bj-MhW66.js} +2 -2
  130. package/langwatch/dist/client/assets/{wizard-faGkpZDT.js → wizard-dRWCVVx6.js} +2 -2
  131. package/langwatch/dist/client/assets/{workbench-Oj0s_YR-.js → workbench-CuixH3G1.js} +2 -2
  132. package/langwatch/dist/client/assets/{workflows-Cu9k-Twu.js → workflows-BT6m4Yu9.js} +2 -2
  133. package/langwatch/dist/client/index.html +3 -3
  134. package/langwatch/scripts/seed-dogfood-password.ts +163 -0
  135. package/langwatch/src/app/api/workflows/post_event/__tests__/post-event-evaluator.integration.test.ts +458 -0
  136. package/langwatch/src/app/api/workflows/post_event/__tests__/post-event-routing.test.ts +180 -0
  137. package/langwatch/src/app/api/workflows/post_event/__tests__/post-event.integration.test.ts +274 -0
  138. package/langwatch/src/app/api/workflows/post_event/post-event.ts +29 -1
  139. package/langwatch/src/components/agents/AgentCodeEditorDrawer.tsx +4 -5
  140. package/langwatch/src/components/agents/__tests__/AgentCodeEditorDrawer.integration.test.tsx +40 -0
  141. package/langwatch/src/components/evaluations/wizard/hooks/evaluation-wizard-store/slices/factories/__tests__/code-execution-node.factory.unit.test.ts +47 -0
  142. package/langwatch/src/components/evaluations/wizard/hooks/evaluation-wizard-store/slices/factories/code-execution-node.factory.ts +2 -4
  143. package/langwatch/src/components/experiments/BatchEvaluationV2/BatchEvaluationV2EvaluationResults.tsx +6 -1
  144. package/langwatch/src/optimization_studio/__tests__/registry.test.ts +29 -1
  145. package/langwatch/src/optimization_studio/components/Optimize.tsx +17 -3
  146. package/langwatch/src/optimization_studio/components/properties/AgentPropertiesPanel.tsx +4 -5
  147. package/langwatch/src/optimization_studio/hooks/workflowStoreCore.ts +17 -6
  148. package/langwatch/src/optimization_studio/hooks/workflowStoreCore.unit.test.ts +42 -0
  149. package/langwatch/src/optimization_studio/registry.ts +2 -4
  150. package/langwatch/src/optimization_studio/server/lambda/index.ts +12 -2
  151. package/langwatch/src/server/api/routers/workflows.ts +18 -0
  152. package/langwatch/src/server/evaluations-v3/execution/workflowBuilder.ts +3 -2
  153. package/langwatch/src/server/evaluations-v3/services/__tests__/experiment-run.service.getRun-null.unit.test.ts +71 -0
  154. package/langwatch/src/server/evaluations-v3/services/experiment-run.service.ts +18 -9
  155. package/langwatch/src/server/modelProviders/utils.ts +11 -1
  156. package/langwatch/src/server/nlpgo/__tests__/nlpgoFetch.integration.test.ts +248 -0
  157. package/langwatch/src/server/nlpgo/nlpgoFetch.ts +142 -0
  158. package/langwatch/src/server/routes/__tests__/playground-proxy.integration.test.ts +242 -0
  159. package/langwatch/src/server/routes/playground.ts +11 -1
  160. package/langwatch/src/server/routes/workflows.ts +17 -0
  161. package/langwatch/src/server/topicClustering/topicClustering.ts +33 -8
  162. package/langwatch/src/server/workflows/runWorkflow.ts +10 -13
  163. package/langwatch_nlp/langwatch_nlp/topic_clustering/topic_naming.py +39 -32
  164. package/langwatch_nlp/scripts/entrypoint.sh +67 -0
  165. package/package.json +1 -1
  166. package/packages/server/dist/cli.cjs +67 -94
  167. package/langwatch/dist/client/assets/ChatWindow-DzB-tNlQ.js +0 -1
  168. package/langwatch/dist/client/assets/_not-found-PEUaWdF3.js +0 -1
  169. package/langwatch/dist/client/assets/_slug_-C-8AjsjC.js +0 -2
  170. package/langwatch/dist/client/assets/choose--PBky27o.js +0 -2
  171. package/langwatch/dist/client/assets/custom-CSiS1liN.js +0 -1
@@ -1,2 +1,2 @@
1
- import{s as e}from"./chunk-Bj-mKKzh.js";import{t}from"./react-C7JcuhbW.js";import{t as n}from"./prop-types-DifpXm68.js";import{$i as r,Dr as i,Fo as a,Jo as o,Jt as s,Mt as c,Nt as l,Ot as u,Qi as ee,S as te,Ss as d,Xo as f,Y as ne,Yn as p,Yo as re,Yt as m,_ as h,_s as ie,aa as g,bs as _,cs as ae,ea as v,es as oe,fn as y,jt as b,kt as x,mn as S,qi as C,r as se,rs as ce,un as le,vs as w,x as ue,xs as T,ys as E}from"./command-bar-CaJygoez.js";import{j as D,n as O,r as de}from"./stack-oJ9iWdbl.js";import{f as k,u as fe}from"./LoadingScreen--vgXk5-2.js";import{t as A}from"./tooltip-AEm0YeiF.js";import{n as j}from"./toaster-C_DYALhL.js";import{$t as pe,At as M,O as N,Ot as me,i as he,j as P,jt as F,k as I}from"./dist-SwV3YZv3.js";import{A as L,D as R,E as z,O as ge,k as _e}from"./terminal-CfM0q99k.js";import{n as ve,r as ye,t as be}from"./native-select-B51i56CE.js";import{t as xe}from"./heading-D90dlSnH.js";import{t as B}from"./text-CwTrMF8x.js";import{a as Se,n as Ce,r as we}from"./field-CnUiixMS.js";import{t as Te}from"./input-C7emsUCL.js";import{t as V}from"./h-stack-BKLDJ2vg.js";import{i as Ee,r as De,t as Oe}from"./alert-SnQmACl1.js";import{n as ke,r as H,t as U}from"./card-CMtKVPVl.js";import{t as Ae}from"./container-Ccm3vB5X.js";import{t as W}from"./spacer-2LJJGbo8.js";import{t as G}from"./v-stack-EOPQ57OZ.js";import{g as je,s as K}from"./auth-client-D3UhxhQi.js";import{r as Me}from"./next-router-C6sliiV7.js";import{c as Ne,t as Pe,u as Fe}from"./useOrganizationTeamProject-DC0iozx2.js";import{D as Ie,E as Le,b as Re,j as ze}from"./types-B5pOLKPA.js";import{n as Be,o as Ve,s as He,t as Ue}from"./index.esm-X7lxUoP1.js";import{n as We,t as q}from"./HorizontalFormControl-BCD7-fcT.js";import{t as Ge}from"./useAvailableEvaluators-HndTl2LV.js";import{n as Ke,r as qe,t as Je}from"./PreconditionsField-BOfcWvmZ.js";var J=e(t()),Y=e(n());function Ye(){return Ye=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},Ye.apply(this,arguments)}function Xe(e,t){if(e==null)return{};var n=Ze(e,t),r,i;if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(i=0;i<a.length;i++)r=a[i],!(t.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=e[r])}return n}function Ze(e,t){if(e==null)return{};var n={},r=Object.keys(e),i,a;for(a=0;a<r.length;a++)i=r[a],!(t.indexOf(i)>=0)&&(n[i]=e[i]);return n}var X=(0,J.forwardRef)(function(e,t){var n=e.color,r=n===void 0?`currentColor`:n,i=e.size,a=i===void 0?24:i,o=Xe(e,[`color`,`size`]);return J.createElement(`svg`,Ye({ref:t,xmlns:`http://www.w3.org/2000/svg`,width:a,height:a,viewBox:`0 0 24 24`,fill:`none`,stroke:r,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},o),J.createElement(`rect`,{x:`6`,y:`4`,width:`4`,height:`16`}),J.createElement(`rect`,{x:`14`,y:`4`,width:`4`,height:`16`}))});X.propTypes={color:Y.default.string,size:Y.default.oneOfType([Y.default.string,Y.default.number])},X.displayName=`Pause`;var Z=Ne(),Qe={mapping:{spans:{source:`spans`},input:{source:`input`},output:{source:`output`},contexts:{source:`contexts`},expected_output:{source:`metadata`,key:`expected_output`}},expansions:[]},$e=e=>{if(e.mapping)return e;let t={spans:{source:`spans`},"trace.input":{source:`input`},"trace.output":{source:`output`},"trace.first_rag_context":{source:`contexts`},"metadata.expected_output":{source:`metadata`,key:`expected_output`},"metadata.expected_contexts":{source:`metadata`,key:`expected_contexts`}};return{mapping:Object.fromEntries(Object.entries(e).map(([e,n])=>[e,t[n]])),expansions:[]}},et=e(i());je(`langwatch:elasticsearch:transformers`);var tt=(e,t)=>n=>{let{input:r,output:i,metrics:a,...o}=n,s={...o,params:o.params??{}},c=null,l=null,u=null;if(r&&(c=e.canSeeCapturedInput===!0?M(r):{type:`text`,value:`[REDACTED]`}),i&&(l=e.canSeeCapturedOutput===!0?M(i):{type:`text`,value:`[REDACTED]`}),c&&(c.value=Q(c.value,t)),l&&(l.value=Q(l.value,t)),a){let{cost:t,...n}=a;u=n,e.canSeeCosts===!0&&(u.cost=t)}return{...s,input:c,output:l,metrics:u}},Q=(e,t)=>{if(t.size===0)return e;if(typeof e==`string`)try{let n=JSON.parse(e);return JSON.stringify(Q(n,t))}catch{let n=g(e);return typeof n==`object`?JSON.stringify(Q(n,t)):Array.from(t).filter(t=>e.includes(t)).length>0?`[REDACTED]`:e}return Array.isArray(e)?e.map(e=>Q(e,t)):typeof e==`object`&&e?Object.fromEntries(Object.entries(e).map(([e,n])=>[e,Q(n,t)])):e},nt=e(ne()),rt=je(`langwatch:evaluations:preconditions`);function it({field:e,data:t,key:n,subkey:r,value:i}){let a=s[e];return a==null?null:a(t,i,n,r)}function at({rule:e,fieldValue:t,conditionValue:n}){switch(e){case`is`:return ot({fieldValue:t,conditionValue:n});case`contains`:return st({fieldValue:t,conditionValue:n});case`not_contains`:return ct({fieldValue:t,conditionValue:n});case`matches_regex`:return lt({fieldValue:t,conditionValue:n});default:return!1}}function ot({fieldValue:e,conditionValue:t}){return e==null?!1:Array.isArray(e)?e.some(e=>e.toLowerCase()===t.toLowerCase()):e.toLowerCase()===t.toLowerCase()}function st({fieldValue:e,conditionValue:t}){return e==null?!1:Array.isArray(e)?e.some(e=>e.toLowerCase().includes(t.toLowerCase())):e.toLowerCase().includes(t.toLowerCase())}function ct({fieldValue:e,conditionValue:t}){return e==null?!0:Array.isArray(e)?!e.some(e=>e.toLowerCase().includes(t.toLowerCase())):!e.toLowerCase().includes(t.toLowerCase())}function lt({fieldValue:e,conditionValue:t}){if(e==null)return!1;try{if(!(0,nt.default)(t))throw Error(`Invalid regex`);let n=Array.isArray(e)?JSON.stringify(e):e;return new RegExp(t,`gi`).test(n)}catch(e){return rt.error({error:e,precondition:t},`Invalid regex in preconditions`),!1}}function ut({evaluatorType:e,spans:t,expectedOutput:n}){let r=l(e);return!(r?.requiredFields.includes(`contexts`)&&!t.some(e=>e.type===`rag`&&F(e.contexts).length>0)||r?.requiredFields.includes(`expected_output`)&&!n)}function dt({traceData:e,preconditions:t}){let n=m(e);for(let e of t){let t=it({field:e.field,data:n,key:e.key,subkey:e.subkey,value:e.value});if(!at({rule:e.rule,fieldValue:t,conditionValue:e.value}))return!1}return!0}function ft({trace:e,spans:t,events:n}){let r={};if(e.metadata?.custom)for(let[t,n]of Object.entries(e.metadata.custom))r[t]=n==null?null:String(n);return{input:e.input?.value??null,output:e.output?.value??null,origin:e.origin??null,hasError:!!e.error,userId:e.metadata?.user_id??null,threadId:e.metadata?.thread_id??null,customerId:e.metadata?.customer_id??null,labels:e.metadata?.labels??null,promptIds:e.metadata?.prompt_ids??null,topicId:e.metadata?.topic_id??null,subTopicId:e.metadata?.subtopic_id??null,spanTypes:t.map(e=>e.type),spanModels:t.map(e=>e.model).filter(e=>typeof e==`string`&&e!==``),customMetadata:Object.keys(r).length>0?r:null,annotationIds:[],events:n?.map(e=>({event_type:e.event_type,metrics:e.metrics??[],event_details:e.event_details??[]}))??null}}var $=D();function pt({form:e}){let{project:t}=Pe(),{watch:n}=e,i=fe(`gray.400`),a=n(`checkType`),s=n(`preconditions`),c=n(`settings`),u=n(`mappings`),f=a&&l(a),[ne,m]=Fe(``,300),{period:{startDate:g,endDate:ae},setPeriod:oe}=v(),{filterParams:b}=ee(),{openDrawer:S}=se(),[C,ce]=(0,J.useState)(Math.random()*1e3),[D,M]=(0,J.useState)(void 0),N=K.traces.getSampleTraces.useQuery({...b,...D,query:ne,expectedResults:10,sortBy:`random.${C}`},{enabled:!!b.projectId&&!!D,refetchOnMount:!1,refetchOnWindowFocus:!1});(0,J.useEffect)(()=>{M({preconditions:s,evaluatorType:a})},[]);let me=N.data?.every(e=>e.passesPreconditions)??!1,P=N.data?.map(e=>(()=>{if(!a)return!1;let t=(e.spans??[]).map(e=>tt({canSeeCapturedInput:!1,canSeeCapturedOutput:!1,canSeeCosts:!1},new Set)(e));return ut({evaluatorType:a,spans:t,expectedOutput:e.expected_output})?dt({traceData:ft({trace:e,spans:t}),preconditions:s}):!1})())??[],F=P.findIndex(e=>e),[I,L]=(0,J.useState)({}),[R,z]=(0,J.useState)({state:`idle`}),ge=K.evaluations.runEvaluation.useMutation();(0,J.useEffect)(()=>{L({}),z({state:`idle`})},[N.data]),(0,J.useEffect)(()=>{if(!t||!a||R.state!==`running`)return;L(e=>({...e,[R.nextTraceId]:{status:`loading`}}));let e=()=>{let e=[...Object.keys(I),R.nextTraceId],t=P.findIndex((t,n)=>t&&!e.includes(N.data?.[n]?.trace_id??``)),n=N.data?.[t]?.trace_id;if(!n){z({state:`idle`});return}z(e=>({...e,nextTraceId:n}))},n;try{n=x.shape[a].shape.settings.parse(c)}catch(e){if(Object.keys(f?.settings??{}).length===0)n={};else{j.create({title:`Invalid evaluator settings`,description:`Please check your settings and try again.`,type:`error`,meta:{closable:!0}}),console.error(e);return}}ge.mutate({projectId:t.id,evaluatorType:a,traceId:R.nextTraceId,settings:n,mappings:u},{onSuccess:t=>{L(e=>({...e,[R.nextTraceId]:t})),e()},onError:t=>{L(e=>({...e,[R.nextTraceId]:{status:`error`,error_type:typeof t,details:t.message,traceback:[]}})),e()}})},[R.state,R.nextTraceId]);let _e=Object.values(I).reduce((e,t)=>e+(t.status===`processed`?t.cost?.amount??0:0),0),ve=f?.result.label;return(0,$.jsxs)(G,{width:`full`,gap:6,marginTop:6,children:[(0,$.jsxs)(V,{width:`full`,align:`end`,children:[(0,$.jsx)(xe,{as:`h2`,size:`lg`,textAlign:`center`,paddingTop:4,children:`Try it out`}),(0,$.jsx)(W,{}),(0,$.jsx)(he,{maxWidth:`350px`,borderColor:`border.emphasized`,startElement:(0,$.jsx)(o,{color:i,width:16}),children:(0,$.jsx)(Te,{name:`query`,type:`search`,placeholder:`Search`,_placeholder:{color:`gray.800`},fontSize:`14px`,paddingY:1.5,height:`auto`,onChange:e=>m(e.target.value)})}),(0,$.jsx)(r,{period:{startDate:g,endDate:ae},setPeriod:oe}),(0,$.jsx)(y,{})]}),a===`presidio/pii_detection`&&(0,$.jsxs)(Ee,{children:[(0,$.jsx)(De,{}),(0,$.jsx)(Oe,{children:(0,$.jsxs)(B,{children:[`Heads up! Since LangWatch already redacts PII, you won`,`'`,`t see any bad examples here. You can still try it though.`]})})]}),(0,$.jsxs)(V,{width:`full`,align:`start`,gap:6,paddingBottom:6,children:[(0,$.jsxs)(H,{width:`full`,minHeight:`400px`,children:[(0,$.jsx)(ke,{children:(0,$.jsxs)(V,{gap:4,children:[(0,$.jsx)(B,{fontWeight:`500`,children:N.isLoading?`Fetching samples...`:`Fetched ${(N.data??[]).length} random sample messages${s.length>0&&me?` passing preconditions`:``}`}),(0,$.jsx)(W,{}),(0,$.jsxs)(O,{onClick:()=>{M({preconditions:s,evaluatorType:a}),ce(Math.random()*1e3)},size:`sm`,children:[(0,$.jsx)(re,{size:16,className:N.isLoading?`refresh-icon animation-spinning`:`refresh-icon`}),`Shuffle`]}),(0,$.jsxs)(O,{colorPalette:`orange`,size:`sm`,disabled:F===-1,onClick:()=>{if(R.state===`idle`){let e=N.data?.[F]?.trace_id;if(!e)return;L({}),z({state:`running`,nextTraceId:e})}else R.state===`paused`?z({state:`running`,nextTraceId:R.nextTraceId}):z({state:`paused`,nextTraceId:``})},children:[R.state===`running`?(0,$.jsx)(de,{size:`sm`}):R.state===`paused`?(0,$.jsx)(X,{size:16}):(0,$.jsx)(pe,{size:16}),R.state===`running`?`Running...`:R.state===`paused`?`Paused`:`Run on samples`]})]})}),(0,$.jsx)(U,{paddingX:2,paddingTop:0,children:(0,$.jsx)(G,{width:`full`,align:`start`,gap:6,children:(0,$.jsxs)(T,{variant:`line`,children:[(0,$.jsx)(_,{children:(0,$.jsxs)(d,{children:[(0,$.jsx)(E,{width:`180px`,children:`Timestamp`}),(0,$.jsx)(E,{width:`225px`,children:`Input`}),(0,$.jsx)(E,{width:`225px`,children:`Output`}),f?.isGuardrail?(0,$.jsx)(E,{width:`120px`,children:`Passed`}):f?.result.score?(0,$.jsx)(E,{width:`120px`,children:`Score`}):null,a?.startsWith(`custom/`)?(0,$.jsx)(E,{width:`120px`,children:`Passed`}):null,a?.startsWith(`custom/`)?(0,$.jsx)(E,{width:`120px`,children:`Score`}):null,ve&&(0,$.jsx)(E,{width:`120px`,children:`Label`}),(0,$.jsx)(E,{width:`250px`,children:`Details`}),(0,$.jsx)(E,{width:`120px`,children:`Cost`})]})}),(0,$.jsxs)(ie,{children:[N.data?.map((e,t)=>{let n=P[t],r=I[e.trace_id],i=r&&r.status!==`loading`?te(r):void 0,o=r&&`details`in r?r.details:``;return(0,$.jsx)(A,{showArrow:!0,positioning:{placement:`top`},content:n?void 0:`Entry does not match the pre-conditions`,children:(0,$.jsxs)(d,{role:`button`,cursor:`pointer`,background:n?void 0:`gray.100`,color:n?void 0:`gray.400`,children:[(0,$.jsx)(w,{maxWidth:`180px`,onClick:()=>S(`traceDetails`,{traceId:e.trace_id}),children:new Date(e.timestamps.started_at).toLocaleDateString(void 0,{month:`numeric`,day:`numeric`})+`, `+new Date(e.timestamps.started_at).toLocaleTimeString(void 0,{hour:`numeric`,minute:`numeric`})}),(0,$.jsx)(w,{maxWidth:`225px`,onClick:()=>S(`traceDetails`,{traceId:e.trace_id}),children:(0,$.jsx)(A,{content:n?e.input?.value??``:void 0,children:(0,$.jsx)(h,{field:`input`,children:(0,$.jsx)(B,{lineClamp:1,wordBreak:`break-all`,display:`block`,children:e.input?.value??`<empty>`})})})}),e.error?(0,$.jsx)(w,{maxWidth:`225px`,onClick:()=>S(`traceDetails`,{traceId:e.trace_id}),children:(0,$.jsxs)(B,{lineClamp:1,maxWidth:`250px`,display:`block`,color:`red.400`,children:[`Error`,e.error.message?`: `:``,e.error.message]})}):(0,$.jsx)(w,{maxWidth:`225px`,onClick:()=>S(`traceDetails`,{traceId:e.trace_id}),children:(0,$.jsx)(A,{content:n?e.output?.value:void 0,children:(0,$.jsx)(h,{field:`output`,children:(0,$.jsx)(B,{lineClamp:1,display:`block`,maxWidth:`250px`,children:(e.output?.value??``).trim()===``?`<empty>`:e.output?.value})})})}),r?(0,$.jsxs)($.Fragment,{children:[r.status===`loading`?(0,$.jsx)(w,{maxWidth:`120`,children:(0,$.jsx)(de,{size:`sm`})}):r.status===`skipped`?(0,$.jsx)(w,{maxWidth:`120`,color:i,children:`Skipped`}):r.status===`error`?(0,$.jsx)(w,{maxWidth:`120`,color:i,children:`Error`}):a?.startsWith(`custom/`)?(0,$.jsx)(w,{maxWidth:`120`,color:i,children:`passed`in r?r.passed?`Pass`:`Fail`:`-`}):f?.isGuardrail?(0,$.jsx)(w,{maxWidth:`120`,color:i,children:r.passed?`Pass`:`Fail`}):f?.result.score?(0,$.jsx)(w,{maxWidth:`120`,color:i,children:(0,et.default)(r.score).format(`0.[00]`)}):null,a?.startsWith(`custom/`)?(0,$.jsx)(w,{maxWidth:`120`,color:i,children:`score`in r?(0,et.default)(r.score).format(`0.[00]`):`-`}):null,ve&&(f?.isGuardrail||!!f?.result.score||r.status===`processed`)&&(0,$.jsx)(w,{maxWidth:`120`,color:i,children:`label`in r?r.label:`-`}),a?.startsWith(`custom/`)?(0,$.jsx)(w,{maxWidth:`120`,color:i,children:`score`in r?(0,et.default)(r.score).format(`0.[00]`):`-`}):null]}):t==F?(0,$.jsx)(w,{maxWidth:`120`,children:`Waiting to run`}):(0,$.jsx)(w,{maxWidth:`120`}),(0,$.jsx)(w,{color:i,maxWidth:`250px`,children:r&&(o?(0,$.jsx)(ue,{lineClamp:3,children:o}):r.status===`loading`?``:`-`)}),(0,$.jsx)(w,{maxWidth:`120px`,children:r&&(r.status===`processed`?p(r.cost??{amount:0,currency:`USD`}):r.status===`loading`?``:`-`)})]})},e.trace_id)}),N.isLoading&&Array.from({length:10}).map((e,t)=>(0,$.jsx)(d,{children:Array.from({length:6}).map((e,t)=>(0,$.jsx)(w,{children:(0,$.jsx)(k,{height:`20px`})},t))},t)),N.isFetched&&N.data?.length===0&&(0,$.jsx)(d,{children:(0,$.jsx)(w,{colSpan:5,children:`No messages found, try selecting different filters and dates`})}),(0,$.jsxs)(d,{children:[(0,$.jsx)(w,{colSpan:5,textAlign:`right`,fontWeight:500,children:`Total Cost:`}),(0,$.jsx)(w,{children:Object.values(I).filter(e=>e.status!==`loading`).length>0?p({amount:_e,currency:Object.values(I).filter(e=>e.status===`processed`&&e.cost)[0]?.cost.currency??`USD`}):`-`})]})]})]})})})]}),(0,$.jsx)(le,{})]})]})}function mt({checkId:e,defaultValues:t,onSubmit:n,loading:r}){let{project:i}=Pe(),o=K.monitors.isNameAvailable.useMutation(),[s,ee]=(0,J.useState)(!1),te=async t=>{let n=await o.mutateAsync({projectId:i?.id??``,name:t,checkId:e});return ee(!n.available),n.available},d=He({defaultValues:t,resolver:(e,t,n)=>We(Ie({name:ze().min(1).max(255).refine(te),checkType:u,sample:Le().min(.01).max(1),preconditions:P,settings:e.checkType?.startsWith(`custom/`)?Ie({}).optional():x.shape[e.checkType??`langevals/basic`].shape.settings,executionMode:Re([Z.EvaluationExecutionMode.ON_MESSAGE,Z.EvaluationExecutionMode.AS_GUARDRAIL,Z.EvaluationExecutionMode.MANUALLY]).optional(),mappings:me}))({...e,settings:e.settings||{}},t,n)}),{register:f,handleSubmit:ne,watch:p,control:re,formState:{errors:m}}=d,h=p(`checkType`),ie=p(`preconditions`),g=p(`name`),_=p(`sample`),v=p(`executionMode`),y=p(`storeSettingsOnCode`),S=p(`mappings`)??Qe,C=p(`settings`);(0,J.useEffect)(()=>{S&&!S.mapping&&d.setValue(`mappings`,$e(S))},[d,S]);let{fields:se,append:le,remove:w}=Ve({control:re,name:`preconditions`}),ue=a(g||``,{lower:!0,strict:!0}),T=Me(),E=T.pathname.endsWith(`/choose`),D=Ge();(0,J.useEffect)(()=>{!h&&!E&&T.replace({pathname:T.pathname+`/choose`,query:T.query})},[h,E,T]),(0,J.useEffect)(()=>{if(!D||t?.settings&&t.checkType===h||!h)return;let e=l(h)?.name;e=I[e??``]??e;let n=Object.values(D).map(e=>I[e.name]??e.name);(!g||n.includes(g))&&d.setValue(`name`,h.includes(`custom`)?``:e??``);let r=(e,t)=>{e&&Object.entries(e).forEach(([e,n])=>{typeof n==`object`&&!Array.isArray(n)&&n!==null?r(n,`${t}.${e}`):d.setValue(`${t}.${e}`,n)})};r(c(D[h],void 0),`settings`)},[h,t?.checkType,t?.settings]);let[de,k]=(0,J.useState)((h?.startsWith(`custom/`),[])),fe=(0,$.jsxs)(B,{color:`fg.muted`,fontStyle:`italic`,children:[`This check will run on`,` `,_>=1?`every message`:`${+(_*100).toFixed(2)}% of messages`,ie?.length>0&&` matching the preconditions`]}),j=(0,J.useMemo)(()=>h&&D?.[h],[h,D]),pe=(0,J.useMemo)(()=>[...j?.requiredFields??[],...j?.optionalFields??[]],[j]);return(0,$.jsx)(Be,{...d,children:(0,$.jsx)(`form`,{onSubmit:ne(e=>n(e)),style:{width:`100%`},children:!h||E||!D?(0,$.jsx)(N,{form:d}):(0,$.jsxs)(G,{gap:6,align:`start`,width:`full`,children:[(0,$.jsx)(H,{width:`full`,children:(0,$.jsx)(U,{children:(0,$.jsxs)(G,{gap:0,children:[(0,$.jsx)(q,{label:`Evaluation Type`,helper:`Select the evaluation to run`,invalid:!!m.checkType,children:(0,$.jsxs)(G,{align:`start`,width:`full`,children:[(0,$.jsxs)(V,{gap:0,width:`full`,children:[(0,$.jsx)(B,{children:I[D[h].name]??D[h].name}),(0,$.jsx)(O,{variant:`ghost`,size:`xs`,onClick:()=>{T.push({pathname:T.pathname+`/choose`,query:T.query})},marginLeft:4,fontWeight:`normal`,color:`fg.muted`,children:(0,$.jsx)(ce,{size:14})})]}),(0,$.jsx)(B,{fontSize:`12px`,color:`fg.muted`,children:D[h].description}),h.startsWith(`legacy/`)&&(0,$.jsxs)(Ee,{status:`warning`,children:[(0,$.jsx)(De,{}),(0,$.jsx)(Oe,{children:(0,$.jsxs)(B,{fontSize:`13px`,children:[`You are using a legacy evaluator version, please click the `,(0,$.jsx)(`b`,{children:`change`}),` button above to select a newer version or a replacement for this evaluator.`]})})]})]})}),(0,$.jsx)(q,{label:`Name`,helper:`Used to identify the check and call it from the API`,invalid:!!m.name,align:`start`,children:(0,$.jsxs)(G,{gap:2,align:`start`,children:[(0,$.jsx)(Te,{id:`name`,...f(`name`,{required:!0})}),s&&(0,$.jsx)(B,{color:`red.500`,fontSize:`13px`,children:`An evaluation with the same name already exists, please choose a different name to have a different slug identifier as well`}),(0,$.jsxs)(B,{fontSize:`12px`,paddingLeft:4,children:[g&&`slug: `,ue]})]})}),h&&x.shape[h]&&(0,$.jsx)(b,{schema:x.shape[h].shape.settings,evaluatorType:h,prefix:`settings`,errors:m.settings,skipFields:[`max_tokens`]})]})})}),(0,$.jsx)(H,{width:`full`,padding:0,children:(0,$.jsxs)(U,{padding:0,children:[(0,$.jsxs)(G,{paddingX:4,gap:0,children:[(0,$.jsx)(q,{label:`Execution Mode`,helper:`Configure when this evaluation is executed`,invalid:!!m.executionMode,align:`start`,_last:{borderBottomWidth:`1px`},children:(0,$.jsxs)(ye,{children:[(0,$.jsxs)(be,{...f(`executionMode`),children:[(0,$.jsx)(`option`,{value:Z.EvaluationExecutionMode.ON_MESSAGE,children:`When message arrives`}),j?.isGuardrail&&(0,$.jsx)(`option`,{value:Z.EvaluationExecutionMode.AS_GUARDRAIL,children:`As a Guardrail`}),(0,$.jsx)(`option`,{value:Z.EvaluationExecutionMode.MANUALLY,children:`Manually`})]}),(0,$.jsx)(ve,{})]})}),v!==Z.EvaluationExecutionMode.ON_MESSAGE&&(0,$.jsx)(Ke,{slug:ue,evaluatorDefinition:D[h],form:d,checkType:h,name:g,executionMode:v,settings:C,storeSettingsOnCode:y})]}),v===Z.EvaluationExecutionMode.ON_MESSAGE&&(0,$.jsx)(L,{value:de,onValueChange:({value:e})=>{k(e)},multiple:!0,children:(0,$.jsxs)(z,{value:`0`,children:[(0,$.jsxs)(_e,{padding:4,paddingBottom:6,children:[(0,$.jsx)(Se,{children:(0,$.jsxs)(G,{align:`start`,gap:1,children:[(0,$.jsx)(we,{margin:0,children:`Execution Settings`}),(0,$.jsx)(Ce,{margin:0,fontSize:`13px`,children:`Configure how and when this evaluation is executed when a new message arrives`})]})}),(0,$.jsx)(ge,{children:(0,$.jsx)(ae,{})})]}),(0,$.jsxs)(R,{paddingX:4,children:[(0,$.jsx)(q,{label:`Mappings`,helper:`Map which fields from the trace will be used to run the evaluation`,children:(0,$.jsx)(qe,{targetFields:pe,traceMapping:S,setTraceMapping:e=>{d.setValue(`mappings`,e)}})}),(0,$.jsx)(Je,{runOn:ie?.length===0&&!j?.requiredFields.includes(`contexts`)?_==1?fe:(0,$.jsx)(B,{color:`fg.muted`,fontStyle:`italic`,children:`No preconditions defined`}):null,append:le,remove:w,fields:se}),h&&x.shape[h]&&(0,$.jsx)(b,{schema:x.shape[h].shape.settings,evaluatorType:h,prefix:`settings`,errors:m.settings,onlyFields:[`max_tokens`]}),(0,$.jsx)(q,{label:`Sampling`,helper:`Run this check only on a sample of messages (min 0.01, max 1.0)`,invalid:!!m.sample,align:`start`,children:(0,$.jsx)(Ue,{control:re,name:`sample`,render:({field:e})=>(0,$.jsxs)(G,{align:`start`,children:[(0,$.jsxs)(V,{children:[(0,$.jsx)(Te,{width:`110px`,type:`number`,min:`0`,max:`1`,step:`0.1`,placeholder:`0.0`,...e,onChange:t=>e.onChange(+t.target.value)}),(0,$.jsx)(A,{content:`You can use this to save costs on expensive checks if you have too many messages incomming. From 0.01 to run on 1% of the messages to 1.0 to run on 100% of the messages`,children:(0,$.jsx)(oe,{width:`14px`})})]}),fe]})})})]})]})})]})}),(0,$.jsxs)(V,{width:`full`,children:[(0,$.jsx)(W,{}),(0,$.jsx)(A,{content:y?`You checked the "Store the settings on code" option, so the evaluation is configured directly on your codebase, saving is disabled`:void 0,children:(0,$.jsx)(O,{colorPalette:`orange`,type:`submit`,minWidth:`92px`,loading:r,disabled:y,children:`Save`})})]}),(0,$.jsx)(pt,{form:d})]})})})}function ht(){let{project:e}=Pe(),t=Me(),n=typeof t.query.id==`string`?t.query.id:``,r=K.monitors.getById.useQuery({id:n,projectId:e?.id??``},{enabled:!!e}),i=K.monitors.update.useMutation(),a=K.monitors.delete.useMutation(),o=async a=>{if(!(!e||!a.checkType))try{await i.mutateAsync({...a,checkType:a.checkType,id:n,projectId:e.id}),j.create({title:`Check updated successfully`,type:`success`,meta:{closable:!0}}),t.push(`/${e.slug}/evaluations`),r.remove()}catch{j.create({title:`Failed to update check`,description:`Please try again`,type:`error`,meta:{closable:!0}})}},s=()=>{e&&window.confirm(`Are you sure you want to delete this check?`)&&a.mutate({id:n,projectId:e.id},{onSuccess:()=>{j.create({title:`Check deleted successfully`,type:`success`,meta:{closable:!0}}),t.push(`/${e.slug}/evaluations`)},onError:()=>{j.create({title:`Failed to delete check`,description:`Please try again`,type:`error`,meta:{closable:!0}})}})},c=r.data?{...r.data,checkType:r.data.checkType,preconditions:r.data.preconditions,settings:r.data.parameters,mappings:r.data.mappings}:void 0;return(0,$.jsx)(S,{children:(0,$.jsx)(Ae,{maxWidth:`1200`,padding:6,children:(0,$.jsxs)(G,{align:`start`,gap:4,children:[(0,$.jsxs)(V,{align:`end`,width:`full`,children:[(0,$.jsx)(xe,{as:`h1`,size:`xl`,textAlign:`center`,paddingTop:4,children:`Editing Evaluation`}),(0,$.jsx)(W,{}),(0,$.jsxs)(C.Root,{children:[(0,$.jsx)(C.Trigger,{asChild:!0,children:(0,$.jsx)(O,{children:(0,$.jsx)(f,{})})}),(0,$.jsx)(C.Content,{children:(0,$.jsx)(C.Item,{value:`delete`,color:`red.fg`,onClick:s,children:`Delete Check`})})]})]}),r.isLoading?(0,$.jsx)(H,{width:`full`,children:(0,$.jsx)(U,{children:(0,$.jsxs)(G,{gap:4,width:`full`,children:[(0,$.jsx)(k,{width:`full`,height:`20px`}),(0,$.jsx)(k,{width:`full`,height:`20px`}),(0,$.jsx)(k,{width:`full`,height:`20px`})]})})}):r.isError?(0,$.jsxs)(Ee,{status:`error`,children:[(0,$.jsx)(De,{}),(0,$.jsx)(Oe,{children:`An error has occurred trying to load the check configs`})]}):(0,$.jsx)(mt,{checkId:n,defaultValues:c,onSubmit:o,loading:i.isLoading})]})})})}export{ht as default};
2
- //# sourceMappingURL=edit-CyxsmQmW.js.map
1
+ import{s as e}from"./chunk-Bj-mKKzh.js";import{t}from"./react-C7JcuhbW.js";import{t as n}from"./prop-types-DifpXm68.js";import{$i as r,Dr as i,Fo as a,Jo as o,Jt as s,Mt as c,Nt as l,Ot as u,Qi as ee,S as te,Ss as d,Xo as f,Y as ne,Yn as p,Yo as re,Yt as m,_ as h,_s as ie,aa as g,bs as _,cs as ae,ea as v,es as oe,fn as y,jt as b,kt as x,mn as S,qi as C,r as se,rs as ce,un as le,vs as w,x as ue,xs as T,ys as E}from"./command-bar-DUK45yin.js";import{j as D,n as O,r as de}from"./stack-oJ9iWdbl.js";import{f as k,u as fe}from"./LoadingScreen--vgXk5-2.js";import{t as A}from"./tooltip-AEm0YeiF.js";import{n as j}from"./toaster-C_DYALhL.js";import{$t as pe,At as M,O as N,Ot as me,i as he,j as P,jt as F,k as I}from"./dist-Cds4Mqhj.js";import{A as L,D as R,E as z,O as ge,k as _e}from"./terminal-CfM0q99k.js";import{n as ve,r as ye,t as be}from"./native-select-B51i56CE.js";import{t as xe}from"./heading-D90dlSnH.js";import{t as B}from"./text-CwTrMF8x.js";import{a as Se,n as Ce,r as we}from"./field-CnUiixMS.js";import{t as Te}from"./input-C7emsUCL.js";import{t as V}from"./h-stack-BKLDJ2vg.js";import{i as Ee,r as De,t as Oe}from"./alert-SnQmACl1.js";import{n as ke,r as H,t as U}from"./card-CMtKVPVl.js";import{t as Ae}from"./container-Ccm3vB5X.js";import{t as W}from"./spacer-2LJJGbo8.js";import{t as G}from"./v-stack-EOPQ57OZ.js";import{g as je,s as K}from"./auth-client-D3UhxhQi.js";import{r as Me}from"./next-router-C6sliiV7.js";import{c as Ne,t as Pe,u as Fe}from"./useOrganizationTeamProject-DC0iozx2.js";import{D as Ie,E as Le,b as Re,j as ze}from"./types-B5pOLKPA.js";import{n as Be,o as Ve,s as He,t as Ue}from"./index.esm-X7lxUoP1.js";import{n as We,t as q}from"./HorizontalFormControl-BCD7-fcT.js";import{t as Ge}from"./useAvailableEvaluators-hmbmcRQr.js";import{n as Ke,r as qe,t as Je}from"./PreconditionsField-WXB8kcTK.js";var J=e(t()),Y=e(n());function Ye(){return Ye=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},Ye.apply(this,arguments)}function Xe(e,t){if(e==null)return{};var n=Ze(e,t),r,i;if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(i=0;i<a.length;i++)r=a[i],!(t.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=e[r])}return n}function Ze(e,t){if(e==null)return{};var n={},r=Object.keys(e),i,a;for(a=0;a<r.length;a++)i=r[a],!(t.indexOf(i)>=0)&&(n[i]=e[i]);return n}var X=(0,J.forwardRef)(function(e,t){var n=e.color,r=n===void 0?`currentColor`:n,i=e.size,a=i===void 0?24:i,o=Xe(e,[`color`,`size`]);return J.createElement(`svg`,Ye({ref:t,xmlns:`http://www.w3.org/2000/svg`,width:a,height:a,viewBox:`0 0 24 24`,fill:`none`,stroke:r,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},o),J.createElement(`rect`,{x:`6`,y:`4`,width:`4`,height:`16`}),J.createElement(`rect`,{x:`14`,y:`4`,width:`4`,height:`16`}))});X.propTypes={color:Y.default.string,size:Y.default.oneOfType([Y.default.string,Y.default.number])},X.displayName=`Pause`;var Z=Ne(),Qe={mapping:{spans:{source:`spans`},input:{source:`input`},output:{source:`output`},contexts:{source:`contexts`},expected_output:{source:`metadata`,key:`expected_output`}},expansions:[]},$e=e=>{if(e.mapping)return e;let t={spans:{source:`spans`},"trace.input":{source:`input`},"trace.output":{source:`output`},"trace.first_rag_context":{source:`contexts`},"metadata.expected_output":{source:`metadata`,key:`expected_output`},"metadata.expected_contexts":{source:`metadata`,key:`expected_contexts`}};return{mapping:Object.fromEntries(Object.entries(e).map(([e,n])=>[e,t[n]])),expansions:[]}},et=e(i());je(`langwatch:elasticsearch:transformers`);var tt=(e,t)=>n=>{let{input:r,output:i,metrics:a,...o}=n,s={...o,params:o.params??{}},c=null,l=null,u=null;if(r&&(c=e.canSeeCapturedInput===!0?M(r):{type:`text`,value:`[REDACTED]`}),i&&(l=e.canSeeCapturedOutput===!0?M(i):{type:`text`,value:`[REDACTED]`}),c&&(c.value=Q(c.value,t)),l&&(l.value=Q(l.value,t)),a){let{cost:t,...n}=a;u=n,e.canSeeCosts===!0&&(u.cost=t)}return{...s,input:c,output:l,metrics:u}},Q=(e,t)=>{if(t.size===0)return e;if(typeof e==`string`)try{let n=JSON.parse(e);return JSON.stringify(Q(n,t))}catch{let n=g(e);return typeof n==`object`?JSON.stringify(Q(n,t)):Array.from(t).filter(t=>e.includes(t)).length>0?`[REDACTED]`:e}return Array.isArray(e)?e.map(e=>Q(e,t)):typeof e==`object`&&e?Object.fromEntries(Object.entries(e).map(([e,n])=>[e,Q(n,t)])):e},nt=e(ne()),rt=je(`langwatch:evaluations:preconditions`);function it({field:e,data:t,key:n,subkey:r,value:i}){let a=s[e];return a==null?null:a(t,i,n,r)}function at({rule:e,fieldValue:t,conditionValue:n}){switch(e){case`is`:return ot({fieldValue:t,conditionValue:n});case`contains`:return st({fieldValue:t,conditionValue:n});case`not_contains`:return ct({fieldValue:t,conditionValue:n});case`matches_regex`:return lt({fieldValue:t,conditionValue:n});default:return!1}}function ot({fieldValue:e,conditionValue:t}){return e==null?!1:Array.isArray(e)?e.some(e=>e.toLowerCase()===t.toLowerCase()):e.toLowerCase()===t.toLowerCase()}function st({fieldValue:e,conditionValue:t}){return e==null?!1:Array.isArray(e)?e.some(e=>e.toLowerCase().includes(t.toLowerCase())):e.toLowerCase().includes(t.toLowerCase())}function ct({fieldValue:e,conditionValue:t}){return e==null?!0:Array.isArray(e)?!e.some(e=>e.toLowerCase().includes(t.toLowerCase())):!e.toLowerCase().includes(t.toLowerCase())}function lt({fieldValue:e,conditionValue:t}){if(e==null)return!1;try{if(!(0,nt.default)(t))throw Error(`Invalid regex`);let n=Array.isArray(e)?JSON.stringify(e):e;return new RegExp(t,`gi`).test(n)}catch(e){return rt.error({error:e,precondition:t},`Invalid regex in preconditions`),!1}}function ut({evaluatorType:e,spans:t,expectedOutput:n}){let r=l(e);return!(r?.requiredFields.includes(`contexts`)&&!t.some(e=>e.type===`rag`&&F(e.contexts).length>0)||r?.requiredFields.includes(`expected_output`)&&!n)}function dt({traceData:e,preconditions:t}){let n=m(e);for(let e of t){let t=it({field:e.field,data:n,key:e.key,subkey:e.subkey,value:e.value});if(!at({rule:e.rule,fieldValue:t,conditionValue:e.value}))return!1}return!0}function ft({trace:e,spans:t,events:n}){let r={};if(e.metadata?.custom)for(let[t,n]of Object.entries(e.metadata.custom))r[t]=n==null?null:String(n);return{input:e.input?.value??null,output:e.output?.value??null,origin:e.origin??null,hasError:!!e.error,userId:e.metadata?.user_id??null,threadId:e.metadata?.thread_id??null,customerId:e.metadata?.customer_id??null,labels:e.metadata?.labels??null,promptIds:e.metadata?.prompt_ids??null,topicId:e.metadata?.topic_id??null,subTopicId:e.metadata?.subtopic_id??null,spanTypes:t.map(e=>e.type),spanModels:t.map(e=>e.model).filter(e=>typeof e==`string`&&e!==``),customMetadata:Object.keys(r).length>0?r:null,annotationIds:[],events:n?.map(e=>({event_type:e.event_type,metrics:e.metrics??[],event_details:e.event_details??[]}))??null}}var $=D();function pt({form:e}){let{project:t}=Pe(),{watch:n}=e,i=fe(`gray.400`),a=n(`checkType`),s=n(`preconditions`),c=n(`settings`),u=n(`mappings`),f=a&&l(a),[ne,m]=Fe(``,300),{period:{startDate:g,endDate:ae},setPeriod:oe}=v(),{filterParams:b}=ee(),{openDrawer:S}=se(),[C,ce]=(0,J.useState)(Math.random()*1e3),[D,M]=(0,J.useState)(void 0),N=K.traces.getSampleTraces.useQuery({...b,...D,query:ne,expectedResults:10,sortBy:`random.${C}`},{enabled:!!b.projectId&&!!D,refetchOnMount:!1,refetchOnWindowFocus:!1});(0,J.useEffect)(()=>{M({preconditions:s,evaluatorType:a})},[]);let me=N.data?.every(e=>e.passesPreconditions)??!1,P=N.data?.map(e=>(()=>{if(!a)return!1;let t=(e.spans??[]).map(e=>tt({canSeeCapturedInput:!1,canSeeCapturedOutput:!1,canSeeCosts:!1},new Set)(e));return ut({evaluatorType:a,spans:t,expectedOutput:e.expected_output})?dt({traceData:ft({trace:e,spans:t}),preconditions:s}):!1})())??[],F=P.findIndex(e=>e),[I,L]=(0,J.useState)({}),[R,z]=(0,J.useState)({state:`idle`}),ge=K.evaluations.runEvaluation.useMutation();(0,J.useEffect)(()=>{L({}),z({state:`idle`})},[N.data]),(0,J.useEffect)(()=>{if(!t||!a||R.state!==`running`)return;L(e=>({...e,[R.nextTraceId]:{status:`loading`}}));let e=()=>{let e=[...Object.keys(I),R.nextTraceId],t=P.findIndex((t,n)=>t&&!e.includes(N.data?.[n]?.trace_id??``)),n=N.data?.[t]?.trace_id;if(!n){z({state:`idle`});return}z(e=>({...e,nextTraceId:n}))},n;try{n=x.shape[a].shape.settings.parse(c)}catch(e){if(Object.keys(f?.settings??{}).length===0)n={};else{j.create({title:`Invalid evaluator settings`,description:`Please check your settings and try again.`,type:`error`,meta:{closable:!0}}),console.error(e);return}}ge.mutate({projectId:t.id,evaluatorType:a,traceId:R.nextTraceId,settings:n,mappings:u},{onSuccess:t=>{L(e=>({...e,[R.nextTraceId]:t})),e()},onError:t=>{L(e=>({...e,[R.nextTraceId]:{status:`error`,error_type:typeof t,details:t.message,traceback:[]}})),e()}})},[R.state,R.nextTraceId]);let _e=Object.values(I).reduce((e,t)=>e+(t.status===`processed`?t.cost?.amount??0:0),0),ve=f?.result.label;return(0,$.jsxs)(G,{width:`full`,gap:6,marginTop:6,children:[(0,$.jsxs)(V,{width:`full`,align:`end`,children:[(0,$.jsx)(xe,{as:`h2`,size:`lg`,textAlign:`center`,paddingTop:4,children:`Try it out`}),(0,$.jsx)(W,{}),(0,$.jsx)(he,{maxWidth:`350px`,borderColor:`border.emphasized`,startElement:(0,$.jsx)(o,{color:i,width:16}),children:(0,$.jsx)(Te,{name:`query`,type:`search`,placeholder:`Search`,_placeholder:{color:`gray.800`},fontSize:`14px`,paddingY:1.5,height:`auto`,onChange:e=>m(e.target.value)})}),(0,$.jsx)(r,{period:{startDate:g,endDate:ae},setPeriod:oe}),(0,$.jsx)(y,{})]}),a===`presidio/pii_detection`&&(0,$.jsxs)(Ee,{children:[(0,$.jsx)(De,{}),(0,$.jsx)(Oe,{children:(0,$.jsxs)(B,{children:[`Heads up! Since LangWatch already redacts PII, you won`,`'`,`t see any bad examples here. You can still try it though.`]})})]}),(0,$.jsxs)(V,{width:`full`,align:`start`,gap:6,paddingBottom:6,children:[(0,$.jsxs)(H,{width:`full`,minHeight:`400px`,children:[(0,$.jsx)(ke,{children:(0,$.jsxs)(V,{gap:4,children:[(0,$.jsx)(B,{fontWeight:`500`,children:N.isLoading?`Fetching samples...`:`Fetched ${(N.data??[]).length} random sample messages${s.length>0&&me?` passing preconditions`:``}`}),(0,$.jsx)(W,{}),(0,$.jsxs)(O,{onClick:()=>{M({preconditions:s,evaluatorType:a}),ce(Math.random()*1e3)},size:`sm`,children:[(0,$.jsx)(re,{size:16,className:N.isLoading?`refresh-icon animation-spinning`:`refresh-icon`}),`Shuffle`]}),(0,$.jsxs)(O,{colorPalette:`orange`,size:`sm`,disabled:F===-1,onClick:()=>{if(R.state===`idle`){let e=N.data?.[F]?.trace_id;if(!e)return;L({}),z({state:`running`,nextTraceId:e})}else R.state===`paused`?z({state:`running`,nextTraceId:R.nextTraceId}):z({state:`paused`,nextTraceId:``})},children:[R.state===`running`?(0,$.jsx)(de,{size:`sm`}):R.state===`paused`?(0,$.jsx)(X,{size:16}):(0,$.jsx)(pe,{size:16}),R.state===`running`?`Running...`:R.state===`paused`?`Paused`:`Run on samples`]})]})}),(0,$.jsx)(U,{paddingX:2,paddingTop:0,children:(0,$.jsx)(G,{width:`full`,align:`start`,gap:6,children:(0,$.jsxs)(T,{variant:`line`,children:[(0,$.jsx)(_,{children:(0,$.jsxs)(d,{children:[(0,$.jsx)(E,{width:`180px`,children:`Timestamp`}),(0,$.jsx)(E,{width:`225px`,children:`Input`}),(0,$.jsx)(E,{width:`225px`,children:`Output`}),f?.isGuardrail?(0,$.jsx)(E,{width:`120px`,children:`Passed`}):f?.result.score?(0,$.jsx)(E,{width:`120px`,children:`Score`}):null,a?.startsWith(`custom/`)?(0,$.jsx)(E,{width:`120px`,children:`Passed`}):null,a?.startsWith(`custom/`)?(0,$.jsx)(E,{width:`120px`,children:`Score`}):null,ve&&(0,$.jsx)(E,{width:`120px`,children:`Label`}),(0,$.jsx)(E,{width:`250px`,children:`Details`}),(0,$.jsx)(E,{width:`120px`,children:`Cost`})]})}),(0,$.jsxs)(ie,{children:[N.data?.map((e,t)=>{let n=P[t],r=I[e.trace_id],i=r&&r.status!==`loading`?te(r):void 0,o=r&&`details`in r?r.details:``;return(0,$.jsx)(A,{showArrow:!0,positioning:{placement:`top`},content:n?void 0:`Entry does not match the pre-conditions`,children:(0,$.jsxs)(d,{role:`button`,cursor:`pointer`,background:n?void 0:`gray.100`,color:n?void 0:`gray.400`,children:[(0,$.jsx)(w,{maxWidth:`180px`,onClick:()=>S(`traceDetails`,{traceId:e.trace_id}),children:new Date(e.timestamps.started_at).toLocaleDateString(void 0,{month:`numeric`,day:`numeric`})+`, `+new Date(e.timestamps.started_at).toLocaleTimeString(void 0,{hour:`numeric`,minute:`numeric`})}),(0,$.jsx)(w,{maxWidth:`225px`,onClick:()=>S(`traceDetails`,{traceId:e.trace_id}),children:(0,$.jsx)(A,{content:n?e.input?.value??``:void 0,children:(0,$.jsx)(h,{field:`input`,children:(0,$.jsx)(B,{lineClamp:1,wordBreak:`break-all`,display:`block`,children:e.input?.value??`<empty>`})})})}),e.error?(0,$.jsx)(w,{maxWidth:`225px`,onClick:()=>S(`traceDetails`,{traceId:e.trace_id}),children:(0,$.jsxs)(B,{lineClamp:1,maxWidth:`250px`,display:`block`,color:`red.400`,children:[`Error`,e.error.message?`: `:``,e.error.message]})}):(0,$.jsx)(w,{maxWidth:`225px`,onClick:()=>S(`traceDetails`,{traceId:e.trace_id}),children:(0,$.jsx)(A,{content:n?e.output?.value:void 0,children:(0,$.jsx)(h,{field:`output`,children:(0,$.jsx)(B,{lineClamp:1,display:`block`,maxWidth:`250px`,children:(e.output?.value??``).trim()===``?`<empty>`:e.output?.value})})})}),r?(0,$.jsxs)($.Fragment,{children:[r.status===`loading`?(0,$.jsx)(w,{maxWidth:`120`,children:(0,$.jsx)(de,{size:`sm`})}):r.status===`skipped`?(0,$.jsx)(w,{maxWidth:`120`,color:i,children:`Skipped`}):r.status===`error`?(0,$.jsx)(w,{maxWidth:`120`,color:i,children:`Error`}):a?.startsWith(`custom/`)?(0,$.jsx)(w,{maxWidth:`120`,color:i,children:`passed`in r?r.passed?`Pass`:`Fail`:`-`}):f?.isGuardrail?(0,$.jsx)(w,{maxWidth:`120`,color:i,children:r.passed?`Pass`:`Fail`}):f?.result.score?(0,$.jsx)(w,{maxWidth:`120`,color:i,children:(0,et.default)(r.score).format(`0.[00]`)}):null,a?.startsWith(`custom/`)?(0,$.jsx)(w,{maxWidth:`120`,color:i,children:`score`in r?(0,et.default)(r.score).format(`0.[00]`):`-`}):null,ve&&(f?.isGuardrail||!!f?.result.score||r.status===`processed`)&&(0,$.jsx)(w,{maxWidth:`120`,color:i,children:`label`in r?r.label:`-`}),a?.startsWith(`custom/`)?(0,$.jsx)(w,{maxWidth:`120`,color:i,children:`score`in r?(0,et.default)(r.score).format(`0.[00]`):`-`}):null]}):t==F?(0,$.jsx)(w,{maxWidth:`120`,children:`Waiting to run`}):(0,$.jsx)(w,{maxWidth:`120`}),(0,$.jsx)(w,{color:i,maxWidth:`250px`,children:r&&(o?(0,$.jsx)(ue,{lineClamp:3,children:o}):r.status===`loading`?``:`-`)}),(0,$.jsx)(w,{maxWidth:`120px`,children:r&&(r.status===`processed`?p(r.cost??{amount:0,currency:`USD`}):r.status===`loading`?``:`-`)})]})},e.trace_id)}),N.isLoading&&Array.from({length:10}).map((e,t)=>(0,$.jsx)(d,{children:Array.from({length:6}).map((e,t)=>(0,$.jsx)(w,{children:(0,$.jsx)(k,{height:`20px`})},t))},t)),N.isFetched&&N.data?.length===0&&(0,$.jsx)(d,{children:(0,$.jsx)(w,{colSpan:5,children:`No messages found, try selecting different filters and dates`})}),(0,$.jsxs)(d,{children:[(0,$.jsx)(w,{colSpan:5,textAlign:`right`,fontWeight:500,children:`Total Cost:`}),(0,$.jsx)(w,{children:Object.values(I).filter(e=>e.status!==`loading`).length>0?p({amount:_e,currency:Object.values(I).filter(e=>e.status===`processed`&&e.cost)[0]?.cost.currency??`USD`}):`-`})]})]})]})})})]}),(0,$.jsx)(le,{})]})]})}function mt({checkId:e,defaultValues:t,onSubmit:n,loading:r}){let{project:i}=Pe(),o=K.monitors.isNameAvailable.useMutation(),[s,ee]=(0,J.useState)(!1),te=async t=>{let n=await o.mutateAsync({projectId:i?.id??``,name:t,checkId:e});return ee(!n.available),n.available},d=He({defaultValues:t,resolver:(e,t,n)=>We(Ie({name:ze().min(1).max(255).refine(te),checkType:u,sample:Le().min(.01).max(1),preconditions:P,settings:e.checkType?.startsWith(`custom/`)?Ie({}).optional():x.shape[e.checkType??`langevals/basic`].shape.settings,executionMode:Re([Z.EvaluationExecutionMode.ON_MESSAGE,Z.EvaluationExecutionMode.AS_GUARDRAIL,Z.EvaluationExecutionMode.MANUALLY]).optional(),mappings:me}))({...e,settings:e.settings||{}},t,n)}),{register:f,handleSubmit:ne,watch:p,control:re,formState:{errors:m}}=d,h=p(`checkType`),ie=p(`preconditions`),g=p(`name`),_=p(`sample`),v=p(`executionMode`),y=p(`storeSettingsOnCode`),S=p(`mappings`)??Qe,C=p(`settings`);(0,J.useEffect)(()=>{S&&!S.mapping&&d.setValue(`mappings`,$e(S))},[d,S]);let{fields:se,append:le,remove:w}=Ve({control:re,name:`preconditions`}),ue=a(g||``,{lower:!0,strict:!0}),T=Me(),E=T.pathname.endsWith(`/choose`),D=Ge();(0,J.useEffect)(()=>{!h&&!E&&T.replace({pathname:T.pathname+`/choose`,query:T.query})},[h,E,T]),(0,J.useEffect)(()=>{if(!D||t?.settings&&t.checkType===h||!h)return;let e=l(h)?.name;e=I[e??``]??e;let n=Object.values(D).map(e=>I[e.name]??e.name);(!g||n.includes(g))&&d.setValue(`name`,h.includes(`custom`)?``:e??``);let r=(e,t)=>{e&&Object.entries(e).forEach(([e,n])=>{typeof n==`object`&&!Array.isArray(n)&&n!==null?r(n,`${t}.${e}`):d.setValue(`${t}.${e}`,n)})};r(c(D[h],void 0),`settings`)},[h,t?.checkType,t?.settings]);let[de,k]=(0,J.useState)((h?.startsWith(`custom/`),[])),fe=(0,$.jsxs)(B,{color:`fg.muted`,fontStyle:`italic`,children:[`This check will run on`,` `,_>=1?`every message`:`${+(_*100).toFixed(2)}% of messages`,ie?.length>0&&` matching the preconditions`]}),j=(0,J.useMemo)(()=>h&&D?.[h],[h,D]),pe=(0,J.useMemo)(()=>[...j?.requiredFields??[],...j?.optionalFields??[]],[j]);return(0,$.jsx)(Be,{...d,children:(0,$.jsx)(`form`,{onSubmit:ne(e=>n(e)),style:{width:`100%`},children:!h||E||!D?(0,$.jsx)(N,{form:d}):(0,$.jsxs)(G,{gap:6,align:`start`,width:`full`,children:[(0,$.jsx)(H,{width:`full`,children:(0,$.jsx)(U,{children:(0,$.jsxs)(G,{gap:0,children:[(0,$.jsx)(q,{label:`Evaluation Type`,helper:`Select the evaluation to run`,invalid:!!m.checkType,children:(0,$.jsxs)(G,{align:`start`,width:`full`,children:[(0,$.jsxs)(V,{gap:0,width:`full`,children:[(0,$.jsx)(B,{children:I[D[h].name]??D[h].name}),(0,$.jsx)(O,{variant:`ghost`,size:`xs`,onClick:()=>{T.push({pathname:T.pathname+`/choose`,query:T.query})},marginLeft:4,fontWeight:`normal`,color:`fg.muted`,children:(0,$.jsx)(ce,{size:14})})]}),(0,$.jsx)(B,{fontSize:`12px`,color:`fg.muted`,children:D[h].description}),h.startsWith(`legacy/`)&&(0,$.jsxs)(Ee,{status:`warning`,children:[(0,$.jsx)(De,{}),(0,$.jsx)(Oe,{children:(0,$.jsxs)(B,{fontSize:`13px`,children:[`You are using a legacy evaluator version, please click the `,(0,$.jsx)(`b`,{children:`change`}),` button above to select a newer version or a replacement for this evaluator.`]})})]})]})}),(0,$.jsx)(q,{label:`Name`,helper:`Used to identify the check and call it from the API`,invalid:!!m.name,align:`start`,children:(0,$.jsxs)(G,{gap:2,align:`start`,children:[(0,$.jsx)(Te,{id:`name`,...f(`name`,{required:!0})}),s&&(0,$.jsx)(B,{color:`red.500`,fontSize:`13px`,children:`An evaluation with the same name already exists, please choose a different name to have a different slug identifier as well`}),(0,$.jsxs)(B,{fontSize:`12px`,paddingLeft:4,children:[g&&`slug: `,ue]})]})}),h&&x.shape[h]&&(0,$.jsx)(b,{schema:x.shape[h].shape.settings,evaluatorType:h,prefix:`settings`,errors:m.settings,skipFields:[`max_tokens`]})]})})}),(0,$.jsx)(H,{width:`full`,padding:0,children:(0,$.jsxs)(U,{padding:0,children:[(0,$.jsxs)(G,{paddingX:4,gap:0,children:[(0,$.jsx)(q,{label:`Execution Mode`,helper:`Configure when this evaluation is executed`,invalid:!!m.executionMode,align:`start`,_last:{borderBottomWidth:`1px`},children:(0,$.jsxs)(ye,{children:[(0,$.jsxs)(be,{...f(`executionMode`),children:[(0,$.jsx)(`option`,{value:Z.EvaluationExecutionMode.ON_MESSAGE,children:`When message arrives`}),j?.isGuardrail&&(0,$.jsx)(`option`,{value:Z.EvaluationExecutionMode.AS_GUARDRAIL,children:`As a Guardrail`}),(0,$.jsx)(`option`,{value:Z.EvaluationExecutionMode.MANUALLY,children:`Manually`})]}),(0,$.jsx)(ve,{})]})}),v!==Z.EvaluationExecutionMode.ON_MESSAGE&&(0,$.jsx)(Ke,{slug:ue,evaluatorDefinition:D[h],form:d,checkType:h,name:g,executionMode:v,settings:C,storeSettingsOnCode:y})]}),v===Z.EvaluationExecutionMode.ON_MESSAGE&&(0,$.jsx)(L,{value:de,onValueChange:({value:e})=>{k(e)},multiple:!0,children:(0,$.jsxs)(z,{value:`0`,children:[(0,$.jsxs)(_e,{padding:4,paddingBottom:6,children:[(0,$.jsx)(Se,{children:(0,$.jsxs)(G,{align:`start`,gap:1,children:[(0,$.jsx)(we,{margin:0,children:`Execution Settings`}),(0,$.jsx)(Ce,{margin:0,fontSize:`13px`,children:`Configure how and when this evaluation is executed when a new message arrives`})]})}),(0,$.jsx)(ge,{children:(0,$.jsx)(ae,{})})]}),(0,$.jsxs)(R,{paddingX:4,children:[(0,$.jsx)(q,{label:`Mappings`,helper:`Map which fields from the trace will be used to run the evaluation`,children:(0,$.jsx)(qe,{targetFields:pe,traceMapping:S,setTraceMapping:e=>{d.setValue(`mappings`,e)}})}),(0,$.jsx)(Je,{runOn:ie?.length===0&&!j?.requiredFields.includes(`contexts`)?_==1?fe:(0,$.jsx)(B,{color:`fg.muted`,fontStyle:`italic`,children:`No preconditions defined`}):null,append:le,remove:w,fields:se}),h&&x.shape[h]&&(0,$.jsx)(b,{schema:x.shape[h].shape.settings,evaluatorType:h,prefix:`settings`,errors:m.settings,onlyFields:[`max_tokens`]}),(0,$.jsx)(q,{label:`Sampling`,helper:`Run this check only on a sample of messages (min 0.01, max 1.0)`,invalid:!!m.sample,align:`start`,children:(0,$.jsx)(Ue,{control:re,name:`sample`,render:({field:e})=>(0,$.jsxs)(G,{align:`start`,children:[(0,$.jsxs)(V,{children:[(0,$.jsx)(Te,{width:`110px`,type:`number`,min:`0`,max:`1`,step:`0.1`,placeholder:`0.0`,...e,onChange:t=>e.onChange(+t.target.value)}),(0,$.jsx)(A,{content:`You can use this to save costs on expensive checks if you have too many messages incomming. From 0.01 to run on 1% of the messages to 1.0 to run on 100% of the messages`,children:(0,$.jsx)(oe,{width:`14px`})})]}),fe]})})})]})]})})]})}),(0,$.jsxs)(V,{width:`full`,children:[(0,$.jsx)(W,{}),(0,$.jsx)(A,{content:y?`You checked the "Store the settings on code" option, so the evaluation is configured directly on your codebase, saving is disabled`:void 0,children:(0,$.jsx)(O,{colorPalette:`orange`,type:`submit`,minWidth:`92px`,loading:r,disabled:y,children:`Save`})})]}),(0,$.jsx)(pt,{form:d})]})})})}function ht(){let{project:e}=Pe(),t=Me(),n=typeof t.query.id==`string`?t.query.id:``,r=K.monitors.getById.useQuery({id:n,projectId:e?.id??``},{enabled:!!e}),i=K.monitors.update.useMutation(),a=K.monitors.delete.useMutation(),o=async a=>{if(!(!e||!a.checkType))try{await i.mutateAsync({...a,checkType:a.checkType,id:n,projectId:e.id}),j.create({title:`Check updated successfully`,type:`success`,meta:{closable:!0}}),t.push(`/${e.slug}/evaluations`),r.remove()}catch{j.create({title:`Failed to update check`,description:`Please try again`,type:`error`,meta:{closable:!0}})}},s=()=>{e&&window.confirm(`Are you sure you want to delete this check?`)&&a.mutate({id:n,projectId:e.id},{onSuccess:()=>{j.create({title:`Check deleted successfully`,type:`success`,meta:{closable:!0}}),t.push(`/${e.slug}/evaluations`)},onError:()=>{j.create({title:`Failed to delete check`,description:`Please try again`,type:`error`,meta:{closable:!0}})}})},c=r.data?{...r.data,checkType:r.data.checkType,preconditions:r.data.preconditions,settings:r.data.parameters,mappings:r.data.mappings}:void 0;return(0,$.jsx)(S,{children:(0,$.jsx)(Ae,{maxWidth:`1200`,padding:6,children:(0,$.jsxs)(G,{align:`start`,gap:4,children:[(0,$.jsxs)(V,{align:`end`,width:`full`,children:[(0,$.jsx)(xe,{as:`h1`,size:`xl`,textAlign:`center`,paddingTop:4,children:`Editing Evaluation`}),(0,$.jsx)(W,{}),(0,$.jsxs)(C.Root,{children:[(0,$.jsx)(C.Trigger,{asChild:!0,children:(0,$.jsx)(O,{children:(0,$.jsx)(f,{})})}),(0,$.jsx)(C.Content,{children:(0,$.jsx)(C.Item,{value:`delete`,color:`red.fg`,onClick:s,children:`Delete Check`})})]})]}),r.isLoading?(0,$.jsx)(H,{width:`full`,children:(0,$.jsx)(U,{children:(0,$.jsxs)(G,{gap:4,width:`full`,children:[(0,$.jsx)(k,{width:`full`,height:`20px`}),(0,$.jsx)(k,{width:`full`,height:`20px`}),(0,$.jsx)(k,{width:`full`,height:`20px`})]})})}):r.isError?(0,$.jsxs)(Ee,{status:`error`,children:[(0,$.jsx)(De,{}),(0,$.jsx)(Oe,{children:`An error has occurred trying to load the check configs`})]}):(0,$.jsx)(mt,{checkId:n,defaultValues:c,onSubmit:o,loading:i.isLoading})]})})})}export{ht as default};
2
+ //# sourceMappingURL=edit-DpT8ejBV.js.map
@@ -1,2 +1,2 @@
1
- import{s as e}from"./chunk-Bj-mKKzh.js";import{t}from"./react-C7JcuhbW.js";import{$a as n,$s as r,Fa as i,Gn as a,Nt as o,Qs as s,Ss as c,Xo as l,Xr as u,Xs as d,Ys as f,Zs as p,_s as m,ao as h,bs as g,fi as _,fo as v,mn as y,mt as b,na as x,os as ee,qi as S,r as C,sc as w,vs as T,xs as te,yo as E,ys as D}from"./command-bar-CaJygoez.js";import{j as ne,n as O,r as k}from"./stack-oJ9iWdbl.js";import{t as A}from"./box-BsM8YLGl.js";import{f as j}from"./LoadingScreen--vgXk5-2.js";import"./tooltip-AEm0YeiF.js";import{n as M}from"./toaster-C_DYALhL.js";import{an as N,f as P}from"./dist-SwV3YZv3.js";import{i as re}from"./tracking-DbhAKeey.js";import{t as ie}from"./heading-D90dlSnH.js";import{t as F}from"./text-CwTrMF8x.js";import{a as ae,r as oe}from"./field-CnUiixMS.js";import{t as I}from"./h-stack-BKLDJ2vg.js";import{r as L,t as R}from"./card-CMtKVPVl.js";import{D as se,Dt as ce,L as le,N as ue,Pt as z,T as B,Tt as V,dt as de,lt as fe,ut as H,v as pe,x as me,xt as U}from"./lu-Bf6j_N19.js";import{t as he}from"./container-Ccm3vB5X.js";import{n as ge,t as W}from"./link-CwZhwOLq.js";import{t as _e}from"./simple-grid-C3IW90zo.js";import{t as ve}from"./spacer-2LJJGbo8.js";import{t as G}from"./v-stack-EOPQ57OZ.js";import{m as K,s as q}from"./auth-client-D3UhxhQi.js";import{r as J}from"./next-router-C6sliiV7.js";import{a as ye,o as Y,t as X}from"./useOrganizationTeamProject-DC0iozx2.js";import{r as be}from"./useRequiredSession-DE4JSglk.js";import{t as xe}from"./WithPermissionGuard-DD8uo3UK.js";import{n as Se,t as Ce}from"./NavigationFooter-CiOVzDUh.js";import{t as we}from"./NoDataInfoBlock-quSW_MRm.js";import{t as Te}from"./persistence-CTQ44vGL.js";import{t as Ee}from"./humanReadableId-BiX-kWLL.js";import{t as De}from"./BatchEvaluationSummary-DMaQM_VB.js";var Z=e(t()),Q=ne();function Oe({open:e,onOpenChange:t}){let{project:n,hasPermission:r}=X(),a=!!n&&r(`evaluations:manage`),{openDrawer:o}=C(),s=J(),[c,l]=(0,Z.useState)(!1),d=q.useContext(),{checkAndProceed:f}=v(`experiments`),p=q.experiments.saveEvaluationsV3.useMutation({onSuccess:e=>{d.experiments.getAllForEvaluationsList.invalidate(),s.push(`/${n?.slug}/experiments/workbench/${e.slug}`),l(!1)},onError:()=>{l(!1)}});return a?(0,Q.jsx)(Q.Fragment,{children:(0,Q.jsxs)(S.Root,{open:e,onOpenChange:e=>t?.(e.open),children:[(0,Q.jsx)(S.Trigger,{asChild:!0,children:(0,Q.jsxs)(u.HeaderButton,{children:[(0,Q.jsx)(i,{size:16}),`New Evaluation`,(0,Q.jsx)(h,{size:14})]})}),(0,Q.jsxs)(S.Content,{minWidth:`320px`,children:[(0,Q.jsx)(S.Item,{value:`experiment`,onClick:()=>{f(()=>{if(!n?.id||c)return;l(!0);let e=Ee(),t=b();t.name=e;let r=Te(t);p.mutate({projectId:n.id,experimentId:void 0,state:{...r,experimentSlug:e}})})},disabled:c,children:(0,Q.jsxs)(A,{width:`100%`,children:[(0,Q.jsxs)(F,{fontWeight:`medium`,children:[c&&(0,Q.jsx)(k,{size:`xs`,marginRight:2}),`Create Experiment`]}),(0,Q.jsx)(F,{fontSize:`xs`,color:`gray.500`,children:`Compare prompts and agents performance side by side`})]})}),(0,Q.jsx)(S.Item,{value:`onlineEvaluation`,onClick:()=>{o(`onlineEvaluation`,{})},children:(0,Q.jsxs)(A,{width:`100%`,children:[(0,Q.jsx)(F,{fontWeight:`medium`,children:`Add Online Evaluation`}),(0,Q.jsx)(F,{fontSize:`xs`,color:`gray.500`,children:`Monitor live traces and capture performance signals`})]})}),(0,Q.jsx)(S.Item,{value:`guardrail`,onClick:()=>{o(`guardrails`,{})},children:(0,Q.jsxs)(A,{width:`100%`,children:[(0,Q.jsx)(F,{fontWeight:`medium`,children:`Setup Guardrail`}),(0,Q.jsx)(F,{fontSize:`xs`,color:`gray.500`,children:`Block dangerous requests and harmful outputs`})]})}),(0,Q.jsx)(S.Item,{value:`monitor`,asChild:!0,children:(0,Q.jsx)(ge,{href:`https://langwatch.ai/docs/evaluations/experiments/sdk`,target:`_blank`,children:(0,Q.jsxs)(A,{width:`100%`,children:[(0,Q.jsxs)(I,{children:[(0,Q.jsx)(F,{fontWeight:`medium`,children:`Evaluate via SDK`}),(0,Q.jsx)(re,{size:14,style:{marginTop:`-2px`}})]}),(0,Q.jsx)(F,{fontSize:`xs`,color:`gray.500`,children:`Run evaluations programmatically from notebooks or scripts`})]})})})]})]})}):null}var $=({open:e,onClose:t,experimentId:n,evaluationName:r})=>{let{organizations:i,project:a}=X(),o=be(),s=q.useContext(),c=q.experiments.copy.useMutation(),[l,u]=(0,Z.useState)([]),[d,f]=(0,Z.useState)(!1),p=o.data?.user?.id,m=i?.flatMap(e=>e.teams.flatMap(t=>{let n=t.members.find(e=>e.userId===p);if(!n)return[];let r=!1;if(n.assignedRole){let e=n.assignedRole.permissions??[];r=e.length>0?ye(e,`evaluations:manage`):Y(n.role,`evaluations:manage`)}else r=Y(n.role,`evaluations:manage`);return t.projects.map(n=>({label:`${e.name} / ${t.name} / ${n.name}`,value:n.id,hasManagePermission:r}))}))??[],h=w({items:m}),g=async()=>{let e=l[0];if(!e||!a)return;let i=m.find(t=>t.value===e)?.label??`selected project`;try{await c.mutateAsync({experimentId:n,projectId:e,sourceProjectId:a.id,copyDatasets:d}),await s.experiments.getAllForEvaluationsList.invalidate(),M.create({title:`Evaluation replicated`,description:`Evaluation "${r}" replicated successfully to ${i}.`,type:`success`}),t()}catch(e){if(K(e))return;M.create({title:`Error replicating evaluation`,description:e instanceof Error?e.message:`Unknown error`,type:`error`})}};return(0,Q.jsx)(P.Root,{open:e,onOpenChange:e=>!e.open&&t(),children:(0,Q.jsxs)(P.Content,{onClick:e=>e.stopPropagation(),children:[(0,Q.jsx)(P.Header,{children:(0,Q.jsx)(P.Title,{children:`Replicate Evaluation`})}),(0,Q.jsx)(P.Body,{children:(0,Q.jsxs)(G,{gap:4,align:`start`,children:[(0,Q.jsxs)(ae,{children:[(0,Q.jsx)(oe,{children:`Target Project`}),(0,Q.jsxs)(x.Root,{collection:h,value:l,onValueChange:e=>{m.find(t=>t.value===e.value[0])?.hasManagePermission&&u(e.value)},children:[(0,Q.jsx)(x.Trigger,{children:(0,Q.jsx)(x.ValueText,{placeholder:`Select project`})}),(0,Q.jsx)(x.Content,{children:h.items.map(e=>{let t=e.hasManagePermission;return(0,Q.jsxs)(x.Item,{item:e,opacity:t?1:.5,cursor:t?`pointer`:`not-allowed`,children:[e.label,!t&&(0,Q.jsx)(F,{display:`inline-block`,fontSize:`sm`,color:`fg.subtle`,ml:2,children:`(no permission)`})]},e.value)})})]})]}),(0,Q.jsx)(E,{checked:d,onCheckedChange:e=>f(!!e.checked),children:`Replicate associated dataset`})]})}),(0,Q.jsxs)(P.Footer,{children:[(0,Q.jsx)(O,{variant:`ghost`,onClick:t,children:`Cancel`}),(0,Q.jsx)(O,{colorPalette:`blue`,onClick:()=>{g()},loading:c.isLoading,disabled:!l.length||!m.find(e=>e.value===l[0])?.hasManagePermission,children:`Replicate`})]})]})})},ke=({title:e,monitors:t})=>{let[r,i]=(0,Z.useState)(!1),[s,c]=(0,Z.useState)(null),{project:l,hasPermission:u}=X(),d=J(),{openDrawer:f}=C(),p=q.experiments.getAllForEvaluationsList.useQuery({projectId:l?.id??``},{enabled:!!l}),m=(0,Z.useMemo)(()=>Object.fromEntries(p.data?.experiments?.map(e=>[e.id,e.slug])??[]),[p.data]),h=q.monitors.delete.useMutation({onSuccess:()=>{t.refetch(),p.refetch(),M.create({title:`Successfully deleted online evaluation`,type:`success`,meta:{closable:!0}})},onError:()=>{M.create({title:`Error deleting monitor`,description:`Please try again`,type:`error`,meta:{closable:!0}})}}),g=q.monitors.toggle.useMutation();return(0,Q.jsxs)(L,{mb:8,children:[(0,Q.jsxs)(R,{children:[(0,Q.jsxs)(I,{justify:`space-between`,mb:4,children:[(0,Q.jsxs)(I,{gap:2,children:[(0,Q.jsx)(ie,{size:`md`,children:e}),(0,Q.jsxs)(N,{variant:`outline`,px:2,py:1,children:[t.data?.length,` Active`]})]}),(0,Q.jsxs)(I,{gap:2,children:[(0,Q.jsx)(W,{href:`/${l?.slug}/analytics/evaluations`,children:(0,Q.jsxs)(O,{size:`sm`,variant:`outline`,textDecoration:`none`,children:[(0,Q.jsx)(ce,{}),` View analytics`]})}),(0,Q.jsx)(z,{"aria-label":r?`Expand section`:`Collapse section`,variant:`ghost`,size:`sm`,onClick:()=>i(!r),children:r?(0,Q.jsx)(pe,{size:16}):(0,Q.jsx)(me,{size:16})})]})]}),!r&&(0,Q.jsx)(Q.Fragment,{children:(0,Q.jsx)(_e,{columns:{base:1,md:2,lg:3},gap:4,children:t.data?.map(e=>{let r=o(e.checkType);return(0,Q.jsxs)(A,{position:`relative`,children:[(0,Q.jsxs)(S.Root,{children:[(0,Q.jsx)(S.Trigger,{asChild:!0,position:`absolute`,top:4,right:4,zIndex:2,children:(0,Q.jsx)(z,{variant:`ghost`,size:`sm`,"aria-label":`More options`,_hover:{backgroundColor:`bg.panel`},children:(0,Q.jsx)(ue,{size:16})})}),(0,Q.jsxs)(S.Content,{children:[(0,Q.jsxs)(S.Item,{value:`edit`,onClick:()=>{l&&(e.experimentId&&m[e.experimentId]?d.push(`/${l.slug}/evaluations/wizard/${m[e.experimentId]}`):f(`onlineEvaluation`,{monitorId:e.id}))},children:[(0,Q.jsx)(H,{size:16}),`Edit`]}),e.experimentId&&(0,Q.jsxs)(S.Item,{value:`copy`,onClick:()=>{if(!l||!e.experimentId)return;let t=p.data?.experiments?.find(t=>t.id===e.experimentId);t&&c({open:!0,experimentId:t.id,evaluationName:t.name??t.slug})},children:[(0,Q.jsx)(n,{size:16}),` Replicate to another project`]}),(0,Q.jsx)(S.Item,{value:`toggle`,onClick:()=>{l&&g.mutate({id:e.id,projectId:l.id,enabled:!e.enabled},{onSuccess:()=>{t.refetch(),M.create({title:`Monitor ${e.enabled?`disabled`:`enabled`}`,type:`info`,meta:{closable:!0}})}})},children:e.enabled?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(fe,{size:16}),`Disable`]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(de,{size:16}),`Enable`]})}),(0,Q.jsxs)(S.Item,{value:`delete`,color:`red.fg`,onClick:()=>{l&&confirm(`Are you sure you want to delete this monitor?`)&&h.mutate({id:e.id,projectId:l.id})},children:[(0,Q.jsx)(V,{size:16}),`Delete`]})]})]}),(0,Q.jsx)(a,{input:{graphId:e.id,graphType:`monitor_graph`,series:[{aggregation:`avg`,colorSet:`tealTones`,key:e.id,metric:r?.isGuardrail?`evaluations.evaluation_pass_rate`:`evaluations.evaluation_score`,name:e.name}],includePrevious:!1,timeScale:1,height:140,monitorGraph:{disabled:!e.enabled,isGuardrail:e.executionMode===`AS_GUARDRAIL`}}})]},e.id)})})})]}),s&&(0,Q.jsx)($,{open:s.open,onClose:()=>c(null),experimentId:s.experimentId,evaluationName:s.evaluationName})]})};function Ae(){let{project:e,hasPermission:t}=X(),n=J(),[a,o]=(0,Z.useState)(null),[h,v]=(0,Z.useState)(!1),b=Se(),x=q.monitors.getAllForProject.useQuery({projectId:e?.id??``},{enabled:!!e}),C=q.experiments.getAllForEvaluationsList.useQuery({projectId:e?.id??``,pageOffset:b.pageOffset,pageSize:b.pageSize},{enabled:!!e&&n.isReady,keepPreviousData:!0,refetchOnMount:!1,refetchOnWindowFocus:!1});b.useUpdateTotalHits(C);let w=q.experiments.deleteExperiment.useMutation({onSuccess:()=>{C.refetch(),x.refetch(),M.create({title:`Experiment deleted`,type:`success`,meta:{closable:!0}})},onError:e=>{K(e)||M.create({title:`Error deleting experiment`,description:`Please try again. If the problem persists, contact support.`,type:`error`,meta:{closable:!0}})}}),E=(t,n)=>{confirm(`Are you sure you want to delete the evaluation "${n}"? This will also delete the workflow, monitor, and prompts associated with it. Datasets will be kept.`)&&w.mutate({projectId:e?.id??``,experimentId:t})};if(!e)return null;let ne={real_time:`Real-Time Evaluation`,llm_app:`LLM App Evaluation`,prompt_creation:`Prompt Creation`,custom_evaluator:`Custom Evaluator`,scan:`Scan for Vulnerabilities`},O={BATCH_EVALUATION_V2:`Experiment (SDK)`,BATCH_EVALUATION:`Batch Evaluation`,DSPY:`DSPy Optimization`,EVALUATIONS_V3:`Experiment (UI)`};return(0,Q.jsxs)(y,{children:[(0,Q.jsxs)(u.Header,{children:[(0,Q.jsx)(u.Heading,{children:`Experiments`}),(0,Q.jsx)(ve,{}),(0,Q.jsx)(I,{gap:2,children:(0,Q.jsx)(Oe,{open:h,onOpenChange:v})})]}),x.isLoading||C.isLoading?(0,Q.jsx)(A,{display:`flex`,justifyContent:`center`,py:8,children:(0,Q.jsx)(k,{})}):x.isError?(0,Q.jsx)(A,{padding:6,children:(0,Q.jsx)(F,{color:`red.500`,children:`Error loading evaluations`})}):x.data?.length===0&&C.data?.experiments.length===0?(0,Q.jsx)(u.Container,{children:(0,Q.jsx)(u.Content,{children:(0,Q.jsx)(we,{title:`No experiments yet`,description:`Run experiments to evaluate your LLM outputs with automated checks and custom metrics.`,icon:(0,Q.jsx)(U,{size:24}),color:`green.500`,docsInfo:(0,Q.jsxs)(F,{children:[`To learn more about evaluations, please visit our`,` `,(0,Q.jsx)(W,{color:`green.500`,href:`https://langwatch.ai/docs/evaluations/overview`,isExternal:!0,children:`documentation`}),`.`]}),children:t(`evaluations:manage`)&&(0,Q.jsxs)(u.HeaderButton,{onClick:()=>v(!0),marginTop:4,children:[(0,Q.jsx)(i,{size:16}),` Create your first evaluation`]})})})}):(0,Q.jsx)(he,{maxW:`calc(min(1440px, 100vw - 200px))`,paddingX:6,paddingTop:4,children:(0,Q.jsxs)(G,{width:`fill`,gap:4,align:`stretch`,children:[x.data&&x.data.length>0&&(0,Q.jsx)(ke,{title:`Online Evaluations`,monitors:x}),(0,Q.jsxs)(G,{align:`start`,gap:1,children:[(0,Q.jsx)(ie,{as:`h1`,children:`Experiments`}),(0,Q.jsx)(F,{color:`fg.muted`,children:`View and analyze your experiment results`})]}),(0,Q.jsxs)(L,{overflow:`hidden`,children:[(0,Q.jsx)(R,{padding:0,overflowX:`auto`,children:C.data&&C.data.experiments.length==0?(0,Q.jsx)(s,{children:(0,Q.jsxs)(f,{children:[(0,Q.jsx)(p,{children:(0,Q.jsx)(U,{size:32})}),(0,Q.jsx)(r,{children:`No experiments yet`}),(0,Q.jsx)(d,{children:e&&t(`evaluations:manage`)&&(0,Q.jsxs)(Q.Fragment,{children:[` `,`Click on`,` `,(0,Q.jsx)(F,{as:`span`,textDecoration:`underline`,cursor:`pointer`,onClick:()=>v(!0),children:`New Evaluation`}),` `,`to get started.`]})})]})}):(0,Q.jsxs)(te,{variant:`line`,width:`full`,children:[(0,Q.jsx)(g,{children:(0,Q.jsxs)(c,{children:[(0,Q.jsx)(D,{width:`20%`,children:`Evaluation`}),(0,Q.jsx)(D,{width:`15%`,children:`Type`}),(0,Q.jsx)(D,{width:`10%`,children:`Dataset`}),(0,Q.jsx)(D,{width:`20%`,children:`Primary Metric`}),(0,Q.jsx)(D,{width:`10%`,children:`Runs`}),(0,Q.jsx)(D,{width:`10%`,children:`Status`}),(0,Q.jsx)(D,{width:`10%`,children:`Last Updated`}),(0,Q.jsx)(D,{width:`5%`})]})}),(0,Q.jsx)(m,{children:C.isLoading||C.isFetching?Array.from({length:3}).map((e,t)=>(0,Q.jsxs)(c,{children:[(0,Q.jsx)(T,{children:(0,Q.jsx)(j,{height:`20px`})}),(0,Q.jsx)(T,{children:(0,Q.jsx)(j,{height:`20px`})}),(0,Q.jsx)(T,{children:(0,Q.jsx)(j,{height:`20px`})}),(0,Q.jsx)(T,{children:(0,Q.jsx)(j,{height:`20px`})}),(0,Q.jsx)(T,{children:(0,Q.jsx)(j,{height:`20px`})}),(0,Q.jsx)(T,{children:(0,Q.jsx)(j,{height:`20px`})}),(0,Q.jsx)(T,{children:(0,Q.jsx)(j,{height:`20px`})}),(0,Q.jsx)(T,{children:(0,Q.jsx)(j,{height:`20px`})})]},t)):C.data?C.data.experiments.map((r,i)=>(0,Q.jsxs)(c,{cursor:`pointer`,onClick:()=>{r.type===`EVALUATIONS_V3`?n.push({pathname:`/${e?.slug}/experiments/workbench/${r.slug}`}):r.workbenchState?n.push({pathname:`/${e?.slug}/evaluations/wizard/${r.slug}`}):n.push({pathname:`/${e?.slug}/experiments/${r.slug}`})},children:[(0,Q.jsx)(T,{children:(0,Q.jsx)(_,{lineClamp:1,wordBreak:`break-word`,children:r.name??r.slug})}),(0,Q.jsx)(T,{whiteSpace:`nowrap`,children:(0,Q.jsx)(N,{colorPalette:`gray`,variant:`outline`,children:r.workbenchState?.task?ne[r.workbenchState.task]:O[r.type]})}),(0,Q.jsx)(T,{children:(0,Q.jsx)(_,{lineClamp:1,wordBreak:`break-word`,children:r.dataset?.name??`-`})}),(0,Q.jsx)(T,{children:r.runsSummary.primaryMetric?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(F,{as:`span`,fontSize:`xs`,color:`fg.muted`,children:[r.runsSummary.primaryMetric.name,`: \xA0`]}),(0,Q.jsx)(F,{as:`span`,fontWeight:`semibold`,children:De(r.runsSummary.primaryMetric,!0)})]}):`-`}),(0,Q.jsx)(T,{children:r.runsSummary.count??`-`}),(0,Q.jsx)(T,{children:(0,Q.jsx)(I,{gap:1,children:r.runsSummary.latestRun?.timestamps?.finishedAt?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(B,{size:14,color:`var(--chakra-colors-green-500)`}),(0,Q.jsx)(F,{fontSize:`sm`,children:`Completed`})]}):r.runsSummary.latestRun?.timestamps?.stoppedAt?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(se,{size:14,color:`var(--chakra-colors-red-500)`}),(0,Q.jsx)(F,{fontSize:`sm`,children:`Stopped`})]}):r.runsSummary.latestRun?.timestamps?.updatedAt&&Date.now()-r.runsSummary.latestRun.timestamps.updatedAt<300*1e3?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(k,{size:`xs`}),(0,Q.jsx)(F,{fontSize:`sm`,children:`Running`})]}):r.runsSummary.count>0?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(B,{size:14,color:`var(--chakra-colors-green-500)`}),(0,Q.jsx)(F,{fontSize:`sm`,children:`Completed`})]}):(0,Q.jsx)(F,{fontSize:`sm`,color:`fg.muted`,children:`-`})})}),(0,Q.jsx)(T,{whiteSpace:`nowrap`,children:new Date(r.updatedAt).toLocaleString()}),(0,Q.jsx)(T,{children:(0,Q.jsx)(A,{width:`full`,height:`full`,display:`flex`,justifyContent:`end`,children:(0,Q.jsxs)(S.Root,{children:[(0,Q.jsx)(S.Trigger,{onClick:e=>{e.stopPropagation()},children:(0,Q.jsx)(l,{size:16})}),(0,Q.jsxs)(S.Content,{children:[r.type===`EVALUATIONS_V3`&&(0,Q.jsxs)(S.Item,{value:`edit`,onClick:t=>{t.stopPropagation(),n.push(`/${e?.slug}/experiments/workbench/${r.slug}`)},children:[(0,Q.jsx)(H,{size:16}),`Edit`]}),r.type!==`EVALUATIONS_V3`&&r.type!==`BATCH_EVALUATION_V2`&&r.workbenchState&&(0,Q.jsxs)(S.Item,{value:`edit`,onClick:t=>{t.stopPropagation(),n.push(`/${e?.slug}/evaluations/wizard/${r.slug}`)},children:[(0,Q.jsx)(H,{size:16}),`Edit`]}),(0,Q.jsxs)(S.Item,{value:`view-results`,onClick:t=>{t.stopPropagation(),n.push(`/${e?.slug}/experiments/${r.slug}`)},children:[(0,Q.jsx)(le,{size:16}),`View Results`]}),t(`evaluations:manage`)&&(0,Q.jsxs)(S.Item,{value:`replicate`,onClick:e=>{e.stopPropagation(),o({open:!0,experimentId:r.id,evaluationName:r.name??r.slug})},children:[(0,Q.jsx)(ee,{size:16}),`Replicate to another project`]}),t(`evaluations:manage`)&&(0,Q.jsxs)(S.Item,{value:`delete`,color:`red.500`,onClick:e=>{e.stopPropagation(),E(r.id,r.name??r.slug)},children:[(0,Q.jsx)(V,{size:16}),`Delete`]})]})]})})})]},i)):null})]})}),C.data&&C.data.experiments.length>0&&(0,Q.jsx)(Ce,{...b})]})]})}),a&&(0,Q.jsx)($,{open:a.open,onClose:()=>o(null),experimentId:a.experimentId,evaluationName:a.evaluationName})]})}var je=xe(`evaluations:view`,{layoutComponent:y})(Ae);export{je as default};
2
- //# sourceMappingURL=evaluations-BfgeZMph.js.map
1
+ import{s as e}from"./chunk-Bj-mKKzh.js";import{t}from"./react-C7JcuhbW.js";import{$a as n,$s as r,Fa as i,Gn as a,Nt as o,Qs as s,Ss as c,Xo as l,Xr as u,Xs as d,Ys as f,Zs as p,_s as m,ao as h,bs as g,fi as _,fo as v,mn as y,mt as b,na as x,os as ee,qi as S,r as C,sc as w,vs as T,xs as te,yo as E,ys as D}from"./command-bar-DUK45yin.js";import{j as ne,n as O,r as k}from"./stack-oJ9iWdbl.js";import{t as A}from"./box-BsM8YLGl.js";import{f as j}from"./LoadingScreen--vgXk5-2.js";import"./tooltip-AEm0YeiF.js";import{n as M}from"./toaster-C_DYALhL.js";import{an as N,f as P}from"./dist-Cds4Mqhj.js";import{i as re}from"./tracking-DbhAKeey.js";import{t as ie}from"./heading-D90dlSnH.js";import{t as F}from"./text-CwTrMF8x.js";import{a as ae,r as oe}from"./field-CnUiixMS.js";import{t as I}from"./h-stack-BKLDJ2vg.js";import{r as L,t as R}from"./card-CMtKVPVl.js";import{D as se,Dt as ce,L as le,N as ue,Pt as z,T as B,Tt as V,dt as de,lt as fe,ut as H,v as pe,x as me,xt as U}from"./lu-Bf6j_N19.js";import{t as he}from"./container-Ccm3vB5X.js";import{n as ge,t as W}from"./link-CwZhwOLq.js";import{t as _e}from"./simple-grid-C3IW90zo.js";import{t as ve}from"./spacer-2LJJGbo8.js";import{t as G}from"./v-stack-EOPQ57OZ.js";import{m as K,s as q}from"./auth-client-D3UhxhQi.js";import{r as J}from"./next-router-C6sliiV7.js";import{a as ye,o as Y,t as X}from"./useOrganizationTeamProject-DC0iozx2.js";import{r as be}from"./useRequiredSession-DE4JSglk.js";import{t as xe}from"./WithPermissionGuard-B4Jo8E5-.js";import{n as Se,t as Ce}from"./NavigationFooter-Dzvauw3l.js";import{t as we}from"./NoDataInfoBlock-CLKl_wlX.js";import{t as Te}from"./persistence-BPvHS0F6.js";import{t as Ee}from"./humanReadableId-BiX-kWLL.js";import{t as De}from"./BatchEvaluationSummary-DtFd8yKJ.js";var Z=e(t()),Q=ne();function Oe({open:e,onOpenChange:t}){let{project:n,hasPermission:r}=X(),a=!!n&&r(`evaluations:manage`),{openDrawer:o}=C(),s=J(),[c,l]=(0,Z.useState)(!1),d=q.useContext(),{checkAndProceed:f}=v(`experiments`),p=q.experiments.saveEvaluationsV3.useMutation({onSuccess:e=>{d.experiments.getAllForEvaluationsList.invalidate(),s.push(`/${n?.slug}/experiments/workbench/${e.slug}`),l(!1)},onError:()=>{l(!1)}});return a?(0,Q.jsx)(Q.Fragment,{children:(0,Q.jsxs)(S.Root,{open:e,onOpenChange:e=>t?.(e.open),children:[(0,Q.jsx)(S.Trigger,{asChild:!0,children:(0,Q.jsxs)(u.HeaderButton,{children:[(0,Q.jsx)(i,{size:16}),`New Evaluation`,(0,Q.jsx)(h,{size:14})]})}),(0,Q.jsxs)(S.Content,{minWidth:`320px`,children:[(0,Q.jsx)(S.Item,{value:`experiment`,onClick:()=>{f(()=>{if(!n?.id||c)return;l(!0);let e=Ee(),t=b();t.name=e;let r=Te(t);p.mutate({projectId:n.id,experimentId:void 0,state:{...r,experimentSlug:e}})})},disabled:c,children:(0,Q.jsxs)(A,{width:`100%`,children:[(0,Q.jsxs)(F,{fontWeight:`medium`,children:[c&&(0,Q.jsx)(k,{size:`xs`,marginRight:2}),`Create Experiment`]}),(0,Q.jsx)(F,{fontSize:`xs`,color:`gray.500`,children:`Compare prompts and agents performance side by side`})]})}),(0,Q.jsx)(S.Item,{value:`onlineEvaluation`,onClick:()=>{o(`onlineEvaluation`,{})},children:(0,Q.jsxs)(A,{width:`100%`,children:[(0,Q.jsx)(F,{fontWeight:`medium`,children:`Add Online Evaluation`}),(0,Q.jsx)(F,{fontSize:`xs`,color:`gray.500`,children:`Monitor live traces and capture performance signals`})]})}),(0,Q.jsx)(S.Item,{value:`guardrail`,onClick:()=>{o(`guardrails`,{})},children:(0,Q.jsxs)(A,{width:`100%`,children:[(0,Q.jsx)(F,{fontWeight:`medium`,children:`Setup Guardrail`}),(0,Q.jsx)(F,{fontSize:`xs`,color:`gray.500`,children:`Block dangerous requests and harmful outputs`})]})}),(0,Q.jsx)(S.Item,{value:`monitor`,asChild:!0,children:(0,Q.jsx)(ge,{href:`https://langwatch.ai/docs/evaluations/experiments/sdk`,target:`_blank`,children:(0,Q.jsxs)(A,{width:`100%`,children:[(0,Q.jsxs)(I,{children:[(0,Q.jsx)(F,{fontWeight:`medium`,children:`Evaluate via SDK`}),(0,Q.jsx)(re,{size:14,style:{marginTop:`-2px`}})]}),(0,Q.jsx)(F,{fontSize:`xs`,color:`gray.500`,children:`Run evaluations programmatically from notebooks or scripts`})]})})})]})]})}):null}var $=({open:e,onClose:t,experimentId:n,evaluationName:r})=>{let{organizations:i,project:a}=X(),o=be(),s=q.useContext(),c=q.experiments.copy.useMutation(),[l,u]=(0,Z.useState)([]),[d,f]=(0,Z.useState)(!1),p=o.data?.user?.id,m=i?.flatMap(e=>e.teams.flatMap(t=>{let n=t.members.find(e=>e.userId===p);if(!n)return[];let r=!1;if(n.assignedRole){let e=n.assignedRole.permissions??[];r=e.length>0?ye(e,`evaluations:manage`):Y(n.role,`evaluations:manage`)}else r=Y(n.role,`evaluations:manage`);return t.projects.map(n=>({label:`${e.name} / ${t.name} / ${n.name}`,value:n.id,hasManagePermission:r}))}))??[],h=w({items:m}),g=async()=>{let e=l[0];if(!e||!a)return;let i=m.find(t=>t.value===e)?.label??`selected project`;try{await c.mutateAsync({experimentId:n,projectId:e,sourceProjectId:a.id,copyDatasets:d}),await s.experiments.getAllForEvaluationsList.invalidate(),M.create({title:`Evaluation replicated`,description:`Evaluation "${r}" replicated successfully to ${i}.`,type:`success`}),t()}catch(e){if(K(e))return;M.create({title:`Error replicating evaluation`,description:e instanceof Error?e.message:`Unknown error`,type:`error`})}};return(0,Q.jsx)(P.Root,{open:e,onOpenChange:e=>!e.open&&t(),children:(0,Q.jsxs)(P.Content,{onClick:e=>e.stopPropagation(),children:[(0,Q.jsx)(P.Header,{children:(0,Q.jsx)(P.Title,{children:`Replicate Evaluation`})}),(0,Q.jsx)(P.Body,{children:(0,Q.jsxs)(G,{gap:4,align:`start`,children:[(0,Q.jsxs)(ae,{children:[(0,Q.jsx)(oe,{children:`Target Project`}),(0,Q.jsxs)(x.Root,{collection:h,value:l,onValueChange:e=>{m.find(t=>t.value===e.value[0])?.hasManagePermission&&u(e.value)},children:[(0,Q.jsx)(x.Trigger,{children:(0,Q.jsx)(x.ValueText,{placeholder:`Select project`})}),(0,Q.jsx)(x.Content,{children:h.items.map(e=>{let t=e.hasManagePermission;return(0,Q.jsxs)(x.Item,{item:e,opacity:t?1:.5,cursor:t?`pointer`:`not-allowed`,children:[e.label,!t&&(0,Q.jsx)(F,{display:`inline-block`,fontSize:`sm`,color:`fg.subtle`,ml:2,children:`(no permission)`})]},e.value)})})]})]}),(0,Q.jsx)(E,{checked:d,onCheckedChange:e=>f(!!e.checked),children:`Replicate associated dataset`})]})}),(0,Q.jsxs)(P.Footer,{children:[(0,Q.jsx)(O,{variant:`ghost`,onClick:t,children:`Cancel`}),(0,Q.jsx)(O,{colorPalette:`blue`,onClick:()=>{g()},loading:c.isLoading,disabled:!l.length||!m.find(e=>e.value===l[0])?.hasManagePermission,children:`Replicate`})]})]})})},ke=({title:e,monitors:t})=>{let[r,i]=(0,Z.useState)(!1),[s,c]=(0,Z.useState)(null),{project:l,hasPermission:u}=X(),d=J(),{openDrawer:f}=C(),p=q.experiments.getAllForEvaluationsList.useQuery({projectId:l?.id??``},{enabled:!!l}),m=(0,Z.useMemo)(()=>Object.fromEntries(p.data?.experiments?.map(e=>[e.id,e.slug])??[]),[p.data]),h=q.monitors.delete.useMutation({onSuccess:()=>{t.refetch(),p.refetch(),M.create({title:`Successfully deleted online evaluation`,type:`success`,meta:{closable:!0}})},onError:()=>{M.create({title:`Error deleting monitor`,description:`Please try again`,type:`error`,meta:{closable:!0}})}}),g=q.monitors.toggle.useMutation();return(0,Q.jsxs)(L,{mb:8,children:[(0,Q.jsxs)(R,{children:[(0,Q.jsxs)(I,{justify:`space-between`,mb:4,children:[(0,Q.jsxs)(I,{gap:2,children:[(0,Q.jsx)(ie,{size:`md`,children:e}),(0,Q.jsxs)(N,{variant:`outline`,px:2,py:1,children:[t.data?.length,` Active`]})]}),(0,Q.jsxs)(I,{gap:2,children:[(0,Q.jsx)(W,{href:`/${l?.slug}/analytics/evaluations`,children:(0,Q.jsxs)(O,{size:`sm`,variant:`outline`,textDecoration:`none`,children:[(0,Q.jsx)(ce,{}),` View analytics`]})}),(0,Q.jsx)(z,{"aria-label":r?`Expand section`:`Collapse section`,variant:`ghost`,size:`sm`,onClick:()=>i(!r),children:r?(0,Q.jsx)(pe,{size:16}):(0,Q.jsx)(me,{size:16})})]})]}),!r&&(0,Q.jsx)(Q.Fragment,{children:(0,Q.jsx)(_e,{columns:{base:1,md:2,lg:3},gap:4,children:t.data?.map(e=>{let r=o(e.checkType);return(0,Q.jsxs)(A,{position:`relative`,children:[(0,Q.jsxs)(S.Root,{children:[(0,Q.jsx)(S.Trigger,{asChild:!0,position:`absolute`,top:4,right:4,zIndex:2,children:(0,Q.jsx)(z,{variant:`ghost`,size:`sm`,"aria-label":`More options`,_hover:{backgroundColor:`bg.panel`},children:(0,Q.jsx)(ue,{size:16})})}),(0,Q.jsxs)(S.Content,{children:[(0,Q.jsxs)(S.Item,{value:`edit`,onClick:()=>{l&&(e.experimentId&&m[e.experimentId]?d.push(`/${l.slug}/evaluations/wizard/${m[e.experimentId]}`):f(`onlineEvaluation`,{monitorId:e.id}))},children:[(0,Q.jsx)(H,{size:16}),`Edit`]}),e.experimentId&&(0,Q.jsxs)(S.Item,{value:`copy`,onClick:()=>{if(!l||!e.experimentId)return;let t=p.data?.experiments?.find(t=>t.id===e.experimentId);t&&c({open:!0,experimentId:t.id,evaluationName:t.name??t.slug})},children:[(0,Q.jsx)(n,{size:16}),` Replicate to another project`]}),(0,Q.jsx)(S.Item,{value:`toggle`,onClick:()=>{l&&g.mutate({id:e.id,projectId:l.id,enabled:!e.enabled},{onSuccess:()=>{t.refetch(),M.create({title:`Monitor ${e.enabled?`disabled`:`enabled`}`,type:`info`,meta:{closable:!0}})}})},children:e.enabled?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(fe,{size:16}),`Disable`]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(de,{size:16}),`Enable`]})}),(0,Q.jsxs)(S.Item,{value:`delete`,color:`red.fg`,onClick:()=>{l&&confirm(`Are you sure you want to delete this monitor?`)&&h.mutate({id:e.id,projectId:l.id})},children:[(0,Q.jsx)(V,{size:16}),`Delete`]})]})]}),(0,Q.jsx)(a,{input:{graphId:e.id,graphType:`monitor_graph`,series:[{aggregation:`avg`,colorSet:`tealTones`,key:e.id,metric:r?.isGuardrail?`evaluations.evaluation_pass_rate`:`evaluations.evaluation_score`,name:e.name}],includePrevious:!1,timeScale:1,height:140,monitorGraph:{disabled:!e.enabled,isGuardrail:e.executionMode===`AS_GUARDRAIL`}}})]},e.id)})})})]}),s&&(0,Q.jsx)($,{open:s.open,onClose:()=>c(null),experimentId:s.experimentId,evaluationName:s.evaluationName})]})};function Ae(){let{project:e,hasPermission:t}=X(),n=J(),[a,o]=(0,Z.useState)(null),[h,v]=(0,Z.useState)(!1),b=Se(),x=q.monitors.getAllForProject.useQuery({projectId:e?.id??``},{enabled:!!e}),C=q.experiments.getAllForEvaluationsList.useQuery({projectId:e?.id??``,pageOffset:b.pageOffset,pageSize:b.pageSize},{enabled:!!e&&n.isReady,keepPreviousData:!0,refetchOnMount:!1,refetchOnWindowFocus:!1});b.useUpdateTotalHits(C);let w=q.experiments.deleteExperiment.useMutation({onSuccess:()=>{C.refetch(),x.refetch(),M.create({title:`Experiment deleted`,type:`success`,meta:{closable:!0}})},onError:e=>{K(e)||M.create({title:`Error deleting experiment`,description:`Please try again. If the problem persists, contact support.`,type:`error`,meta:{closable:!0}})}}),E=(t,n)=>{confirm(`Are you sure you want to delete the evaluation "${n}"? This will also delete the workflow, monitor, and prompts associated with it. Datasets will be kept.`)&&w.mutate({projectId:e?.id??``,experimentId:t})};if(!e)return null;let ne={real_time:`Real-Time Evaluation`,llm_app:`LLM App Evaluation`,prompt_creation:`Prompt Creation`,custom_evaluator:`Custom Evaluator`,scan:`Scan for Vulnerabilities`},O={BATCH_EVALUATION_V2:`Experiment (SDK)`,BATCH_EVALUATION:`Batch Evaluation`,DSPY:`DSPy Optimization`,EVALUATIONS_V3:`Experiment (UI)`};return(0,Q.jsxs)(y,{children:[(0,Q.jsxs)(u.Header,{children:[(0,Q.jsx)(u.Heading,{children:`Experiments`}),(0,Q.jsx)(ve,{}),(0,Q.jsx)(I,{gap:2,children:(0,Q.jsx)(Oe,{open:h,onOpenChange:v})})]}),x.isLoading||C.isLoading?(0,Q.jsx)(A,{display:`flex`,justifyContent:`center`,py:8,children:(0,Q.jsx)(k,{})}):x.isError?(0,Q.jsx)(A,{padding:6,children:(0,Q.jsx)(F,{color:`red.500`,children:`Error loading evaluations`})}):x.data?.length===0&&C.data?.experiments.length===0?(0,Q.jsx)(u.Container,{children:(0,Q.jsx)(u.Content,{children:(0,Q.jsx)(we,{title:`No experiments yet`,description:`Run experiments to evaluate your LLM outputs with automated checks and custom metrics.`,icon:(0,Q.jsx)(U,{size:24}),color:`green.500`,docsInfo:(0,Q.jsxs)(F,{children:[`To learn more about evaluations, please visit our`,` `,(0,Q.jsx)(W,{color:`green.500`,href:`https://langwatch.ai/docs/evaluations/overview`,isExternal:!0,children:`documentation`}),`.`]}),children:t(`evaluations:manage`)&&(0,Q.jsxs)(u.HeaderButton,{onClick:()=>v(!0),marginTop:4,children:[(0,Q.jsx)(i,{size:16}),` Create your first evaluation`]})})})}):(0,Q.jsx)(he,{maxW:`calc(min(1440px, 100vw - 200px))`,paddingX:6,paddingTop:4,children:(0,Q.jsxs)(G,{width:`fill`,gap:4,align:`stretch`,children:[x.data&&x.data.length>0&&(0,Q.jsx)(ke,{title:`Online Evaluations`,monitors:x}),(0,Q.jsxs)(G,{align:`start`,gap:1,children:[(0,Q.jsx)(ie,{as:`h1`,children:`Experiments`}),(0,Q.jsx)(F,{color:`fg.muted`,children:`View and analyze your experiment results`})]}),(0,Q.jsxs)(L,{overflow:`hidden`,children:[(0,Q.jsx)(R,{padding:0,overflowX:`auto`,children:C.data&&C.data.experiments.length==0?(0,Q.jsx)(s,{children:(0,Q.jsxs)(f,{children:[(0,Q.jsx)(p,{children:(0,Q.jsx)(U,{size:32})}),(0,Q.jsx)(r,{children:`No experiments yet`}),(0,Q.jsx)(d,{children:e&&t(`evaluations:manage`)&&(0,Q.jsxs)(Q.Fragment,{children:[` `,`Click on`,` `,(0,Q.jsx)(F,{as:`span`,textDecoration:`underline`,cursor:`pointer`,onClick:()=>v(!0),children:`New Evaluation`}),` `,`to get started.`]})})]})}):(0,Q.jsxs)(te,{variant:`line`,width:`full`,children:[(0,Q.jsx)(g,{children:(0,Q.jsxs)(c,{children:[(0,Q.jsx)(D,{width:`20%`,children:`Evaluation`}),(0,Q.jsx)(D,{width:`15%`,children:`Type`}),(0,Q.jsx)(D,{width:`10%`,children:`Dataset`}),(0,Q.jsx)(D,{width:`20%`,children:`Primary Metric`}),(0,Q.jsx)(D,{width:`10%`,children:`Runs`}),(0,Q.jsx)(D,{width:`10%`,children:`Status`}),(0,Q.jsx)(D,{width:`10%`,children:`Last Updated`}),(0,Q.jsx)(D,{width:`5%`})]})}),(0,Q.jsx)(m,{children:C.isLoading||C.isFetching?Array.from({length:3}).map((e,t)=>(0,Q.jsxs)(c,{children:[(0,Q.jsx)(T,{children:(0,Q.jsx)(j,{height:`20px`})}),(0,Q.jsx)(T,{children:(0,Q.jsx)(j,{height:`20px`})}),(0,Q.jsx)(T,{children:(0,Q.jsx)(j,{height:`20px`})}),(0,Q.jsx)(T,{children:(0,Q.jsx)(j,{height:`20px`})}),(0,Q.jsx)(T,{children:(0,Q.jsx)(j,{height:`20px`})}),(0,Q.jsx)(T,{children:(0,Q.jsx)(j,{height:`20px`})}),(0,Q.jsx)(T,{children:(0,Q.jsx)(j,{height:`20px`})}),(0,Q.jsx)(T,{children:(0,Q.jsx)(j,{height:`20px`})})]},t)):C.data?C.data.experiments.map((r,i)=>(0,Q.jsxs)(c,{cursor:`pointer`,onClick:()=>{r.type===`EVALUATIONS_V3`?n.push({pathname:`/${e?.slug}/experiments/workbench/${r.slug}`}):r.workbenchState?n.push({pathname:`/${e?.slug}/evaluations/wizard/${r.slug}`}):n.push({pathname:`/${e?.slug}/experiments/${r.slug}`})},children:[(0,Q.jsx)(T,{children:(0,Q.jsx)(_,{lineClamp:1,wordBreak:`break-word`,children:r.name??r.slug})}),(0,Q.jsx)(T,{whiteSpace:`nowrap`,children:(0,Q.jsx)(N,{colorPalette:`gray`,variant:`outline`,children:r.workbenchState?.task?ne[r.workbenchState.task]:O[r.type]})}),(0,Q.jsx)(T,{children:(0,Q.jsx)(_,{lineClamp:1,wordBreak:`break-word`,children:r.dataset?.name??`-`})}),(0,Q.jsx)(T,{children:r.runsSummary.primaryMetric?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(F,{as:`span`,fontSize:`xs`,color:`fg.muted`,children:[r.runsSummary.primaryMetric.name,`: \xA0`]}),(0,Q.jsx)(F,{as:`span`,fontWeight:`semibold`,children:De(r.runsSummary.primaryMetric,!0)})]}):`-`}),(0,Q.jsx)(T,{children:r.runsSummary.count??`-`}),(0,Q.jsx)(T,{children:(0,Q.jsx)(I,{gap:1,children:r.runsSummary.latestRun?.timestamps?.finishedAt?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(B,{size:14,color:`var(--chakra-colors-green-500)`}),(0,Q.jsx)(F,{fontSize:`sm`,children:`Completed`})]}):r.runsSummary.latestRun?.timestamps?.stoppedAt?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(se,{size:14,color:`var(--chakra-colors-red-500)`}),(0,Q.jsx)(F,{fontSize:`sm`,children:`Stopped`})]}):r.runsSummary.latestRun?.timestamps?.updatedAt&&Date.now()-r.runsSummary.latestRun.timestamps.updatedAt<300*1e3?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(k,{size:`xs`}),(0,Q.jsx)(F,{fontSize:`sm`,children:`Running`})]}):r.runsSummary.count>0?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(B,{size:14,color:`var(--chakra-colors-green-500)`}),(0,Q.jsx)(F,{fontSize:`sm`,children:`Completed`})]}):(0,Q.jsx)(F,{fontSize:`sm`,color:`fg.muted`,children:`-`})})}),(0,Q.jsx)(T,{whiteSpace:`nowrap`,children:new Date(r.updatedAt).toLocaleString()}),(0,Q.jsx)(T,{children:(0,Q.jsx)(A,{width:`full`,height:`full`,display:`flex`,justifyContent:`end`,children:(0,Q.jsxs)(S.Root,{children:[(0,Q.jsx)(S.Trigger,{onClick:e=>{e.stopPropagation()},children:(0,Q.jsx)(l,{size:16})}),(0,Q.jsxs)(S.Content,{children:[r.type===`EVALUATIONS_V3`&&(0,Q.jsxs)(S.Item,{value:`edit`,onClick:t=>{t.stopPropagation(),n.push(`/${e?.slug}/experiments/workbench/${r.slug}`)},children:[(0,Q.jsx)(H,{size:16}),`Edit`]}),r.type!==`EVALUATIONS_V3`&&r.type!==`BATCH_EVALUATION_V2`&&r.workbenchState&&(0,Q.jsxs)(S.Item,{value:`edit`,onClick:t=>{t.stopPropagation(),n.push(`/${e?.slug}/evaluations/wizard/${r.slug}`)},children:[(0,Q.jsx)(H,{size:16}),`Edit`]}),(0,Q.jsxs)(S.Item,{value:`view-results`,onClick:t=>{t.stopPropagation(),n.push(`/${e?.slug}/experiments/${r.slug}`)},children:[(0,Q.jsx)(le,{size:16}),`View Results`]}),t(`evaluations:manage`)&&(0,Q.jsxs)(S.Item,{value:`replicate`,onClick:e=>{e.stopPropagation(),o({open:!0,experimentId:r.id,evaluationName:r.name??r.slug})},children:[(0,Q.jsx)(ee,{size:16}),`Replicate to another project`]}),t(`evaluations:manage`)&&(0,Q.jsxs)(S.Item,{value:`delete`,color:`red.500`,onClick:e=>{e.stopPropagation(),E(r.id,r.name??r.slug)},children:[(0,Q.jsx)(V,{size:16}),`Delete`]})]})]})})})]},i)):null})]})}),C.data&&C.data.experiments.length>0&&(0,Q.jsx)(Ce,{...b})]})]})}),a&&(0,Q.jsx)($,{open:a.open,onClose:()=>o(null),experimentId:a.experimentId,evaluationName:a.evaluationName})]})}var je=xe(`evaluations:view`,{layoutComponent:y})(Ae);export{je as default};
2
+ //# sourceMappingURL=evaluations-BdQ2Dm2r.js.map
@@ -1,2 +1,2 @@
1
- import{s as e}from"./chunk-Bj-mKKzh.js";import{t}from"./react-C7JcuhbW.js";import{Gn as n,Nt as r,un as i}from"./command-bar-CaJygoez.js";import{j as a}from"./stack-oJ9iWdbl.js";import{t as o}from"./box-BsM8YLGl.js";import{s}from"./tabs-DwV1cIZB.js";import{t as c}from"./heading-D90dlSnH.js";import{t as l}from"./text-CwTrMF8x.js";import{t as u}from"./h-stack-BKLDJ2vg.js";import{a as d,i as f,n as p,r as m,t as h}from"./alert-SnQmACl1.js";import{n as g,r as _,t as v}from"./card-CMtKVPVl.js";import{t as y}from"./link-CwZhwOLq.js";import{t as b}from"./simple-grid-C3IW90zo.js";import{s as x}from"./auth-client-D3UhxhQi.js";import{r as S}from"./next-router-C6sliiV7.js";import{t as C}from"./useOrganizationTeamProject-DC0iozx2.js";import{t as w}from"./chart-no-axes-column-BMqNR285.js";import{t as T}from"./WithPermissionGuard-DD8uo3UK.js";import{t as E}from"./GraphsLayout-BJ68J9e-.js";var D=e(t()),O=a(),k=1440,A={graphId:`evaluationsHealthSummary`,graphType:`summary`,series:[{name:`Total evaluation runs`,metric:`evaluations.evaluation_runs`,aggregation:`cardinality`,key:``,colorSet:`tealTones`}],includePrevious:!0,timeScale:k,height:200},j={graphId:`evaluationsPassFailTrend`,graphType:`stacked_bar`,series:[{name:`Evaluations`,metric:`evaluations.evaluation_runs`,aggregation:`cardinality`,key:``,colorSet:`positiveNegativeNeutral`}],groupBy:`evaluations.evaluation_passed`,includePrevious:!1,timeScale:k,height:200},M=(e,t)=>e.map(e=>{let i={},a={},o=null,d=r(e.checkType),f=e.checkType===`langevals/llm_category`;return d?.isGuardrail?(a={graphId:`evalSummary_${e.id}`,graphType:`donnut`,series:[{name:`Checks count`,colorSet:`positiveNegativeNeutral`,metric:`evaluations.evaluation_runs`,aggregation:`cardinality`,key:e.id,filters:{"evaluations.state":{[e.id]:[`processed`]}}}],groupBy:`evaluations.evaluation_passed`,groupByKey:e.id,includePrevious:!1,timeScale:k,height:300},i={graphId:`evalTimeline_${e.id}`,graphType:`stacked_bar`,series:[{name:``,colorSet:`positiveNegativeNeutral`,metric:`evaluations.evaluation_runs`,aggregation:`cardinality`,pipeline:{field:`trace_id`,aggregation:`sum`},key:e.id,filters:{"evaluations.state":{[e.id]:[`processed`]}}}],groupBy:`evaluations.evaluation_passed`,groupByKey:e.id,includePrevious:!1,timeScale:k,height:300},o={graphId:`evalPassRate_${e.id}`,graphType:`line`,series:[{name:`Pass rate`,colorSet:`tealTones`,metric:`evaluations.evaluation_pass_rate`,aggregation:`avg`,key:e.id,filters:{"evaluations.state":{[e.id]:[`processed`]}}}],includePrevious:!1,timeScale:k,height:200}):f?(a={graphId:`evalSummary_${e.id}`,graphType:`donnut`,series:[{name:`Traces count`,colorSet:`colors`,metric:`metadata.trace_id`,aggregation:`cardinality`,filters:{"evaluations.state":{[e.id]:[`processed`]}}}],groupBy:`evaluations.evaluation_label`,groupByKey:e.id,includePrevious:!1,timeScale:k,height:400},i={graphId:`evalTimeline_${e.id}`,graphType:`horizontal_bar`,series:[{name:``,colorSet:`colors`,metric:`metadata.trace_id`,aggregation:`cardinality`,filters:{"evaluations.state":{[e.id]:[`processed`]}}}],groupBy:`evaluations.evaluation_label`,groupByKey:e.id,includePrevious:!1,timeScale:`full`,height:400}):(a={graphId:`evalSummary_${e.id}`,graphType:`summary`,series:[{name:`Evaluation score average`,colorSet:`tealTones`,metric:`evaluations.evaluation_score`,aggregation:`avg`,key:e.id,filters:{"evaluations.state":{[e.id]:[`processed`]}}}],includePrevious:!1,timeScale:k,height:200},i={graphId:`evalTimeline_${e.id}`,graphType:`line`,series:[{name:`Average score`,colorSet:`colors`,metric:`evaluations.evaluation_score`,aggregation:`avg`,key:e.id,filters:{"evaluations.state":{[e.id]:[`processed`]}}}],includePrevious:!1,timeScale:k,height:200}),(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(s,{colSpan:1,display:`inline-grid`,children:(0,O.jsxs)(_,{children:[(0,O.jsxs)(g,{children:[(0,O.jsxs)(u,{gap:2,children:[(0,O.jsx)(w,{color:`orange`}),(0,O.jsx)(c,{size:`sm`,children:e.name})]}),!e.enabled&&(0,O.jsx)(l,{color:`gray`,fontSize:`sm`,children:`(disabled)`})]}),(0,O.jsx)(v,{children:(0,O.jsx)(n,{input:a,onDataPointClick:n=>{t({evaluatorId:e.id,groupKey:n.groupKey,checkType:e.checkType,isGuardrail:d?.isGuardrail??!1})}})})]})}),(0,O.jsx)(s,{colSpan:3,display:`inline-grid`,children:(0,O.jsxs)(_,{children:[(0,O.jsxs)(g,{children:[(0,O.jsxs)(u,{gap:2,children:[(0,O.jsx)(w,{color:`orange`}),(0,O.jsx)(c,{size:`sm`,children:e.name}),d&&(0,O.jsxs)(l,{fontWeight:300,children:[`- `,d.name]})]}),!e.enabled&&(0,O.jsx)(l,{color:`gray`,fontSize:`sm`,children:`(disabled)`})]}),(0,O.jsx)(v,{children:(0,O.jsx)(n,{input:i,onDataPointClick:n=>{t({evaluatorId:e.id,groupKey:n.groupKey,date:n.date,startDate:n.startDate,endDate:n.endDate,checkType:e.checkType,isGuardrail:d?.isGuardrail??!1})}})})]})}),o&&(0,O.jsx)(s,{colSpan:4,display:`inline-grid`,children:(0,O.jsxs)(_,{children:[(0,O.jsx)(g,{children:(0,O.jsxs)(u,{gap:2,children:[(0,O.jsx)(w,{color:`orange`}),(0,O.jsxs)(c,{size:`sm`,children:[e.name,` - Pass Rate Trend`]})]})}),(0,O.jsx)(v,{children:(0,O.jsx)(n,{input:o})})]})})]})});function N(){let{project:e}=C(),t=S(),r=x.monitors.getAllForProject.useQuery({projectId:e?.id??``},{enabled:!!e}),a=(0,D.useCallback)(n=>{if(!e||!n.evaluatorId)return;let r=n.checkType===`langevals/llm_category`,i={[`evaluation_run.${n.evaluatorId}`]:[`processed`]};if(n.isGuardrail&&n.groupKey){let e=n.groupKey===`passed`||n.groupKey===`true`||n.groupKey===`positive`||n.groupKey===`1`,t=n.groupKey===`failed`||n.groupKey===`false`||n.groupKey===`negative`||n.groupKey===`0`;e?i[`evaluation_passed.${n.evaluatorId}`]=`1`:t&&(i[`evaluation_passed.${n.evaluatorId}`]=`0`)}else r&&n.groupKey&&(i[`evaluation_label.${n.evaluatorId}`]=n.groupKey);n.startDate&&n.endDate&&(i.startDate=n.startDate,i.endDate=n.endDate),t.push({pathname:`/${e.slug}/messages`,query:i},void 0,{shallow:!1})},[e,t]);return(0,O.jsxs)(E,{title:`Online Evaluations`,children:[r.data&&r.data?.length===0&&(0,O.jsxs)(f,{colorPalette:`warning`,borderStartWidth:`4px`,borderStartColor:`colorPalette.solid`,marginBottom:6,children:[(0,O.jsx)(m,{}),(0,O.jsxs)(h,{children:[(0,O.jsx)(d,{children:`No online evaluations yet`}),(0,O.jsxs)(p,{children:[(0,O.jsxs)(l,{as:`span`,children:[`The evaluation results will be displayed here. Setup evaluations for your project to see the results. Click`,` `]}),(0,O.jsx)(y,{href:`/${e?.slug}/evaluations`,children:`here`}),(0,O.jsx)(l,{as:`span`,children:` to get started.`})]})]})]}),(0,O.jsxs)(u,{alignItems:`start`,gap:4,children:[(0,O.jsxs)(b,{templateColumns:`repeat(4, 1fr)`,gap:5,width:`100%`,children:[r.data&&r.data.length>0&&(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(s,{colSpan:1,display:`inline-grid`,children:(0,O.jsxs)(_,{children:[(0,O.jsx)(g,{children:(0,O.jsx)(c,{size:`sm`,children:`Overall Health`})}),(0,O.jsx)(v,{children:(0,O.jsx)(n,{input:A})})]})}),(0,O.jsx)(s,{colSpan:3,display:`inline-grid`,children:(0,O.jsxs)(_,{children:[(0,O.jsx)(g,{children:(0,O.jsx)(c,{size:`sm`,children:`Pass / Fail Trend`})}),(0,O.jsx)(v,{children:(0,O.jsx)(n,{input:j})})]})})]}),r.data?M([...r.data].sort((e,t)=>e.enabled===t.enabled?0:e.enabled?-1:1),a):null]}),(0,O.jsx)(o,{padding:3,children:(0,O.jsx)(i,{hideTopics:!0})})]})]})}var P=T(`analytics:view`)(N);export{P as default};
2
- //# sourceMappingURL=evaluations-HSQIMvbX.js.map
1
+ import{s as e}from"./chunk-Bj-mKKzh.js";import{t}from"./react-C7JcuhbW.js";import{Gn as n,Nt as r,un as i}from"./command-bar-DUK45yin.js";import{j as a}from"./stack-oJ9iWdbl.js";import{t as o}from"./box-BsM8YLGl.js";import{s}from"./tabs-DwV1cIZB.js";import{t as c}from"./heading-D90dlSnH.js";import{t as l}from"./text-CwTrMF8x.js";import{t as u}from"./h-stack-BKLDJ2vg.js";import{a as d,i as f,n as p,r as m,t as h}from"./alert-SnQmACl1.js";import{n as g,r as _,t as v}from"./card-CMtKVPVl.js";import{t as y}from"./link-CwZhwOLq.js";import{t as b}from"./simple-grid-C3IW90zo.js";import{s as x}from"./auth-client-D3UhxhQi.js";import{r as S}from"./next-router-C6sliiV7.js";import{t as C}from"./useOrganizationTeamProject-DC0iozx2.js";import{t as w}from"./chart-no-axes-column-BMqNR285.js";import{t as T}from"./WithPermissionGuard-B4Jo8E5-.js";import{t as E}from"./GraphsLayout-DJ-HI9N1.js";var D=e(t()),O=a(),k=1440,A={graphId:`evaluationsHealthSummary`,graphType:`summary`,series:[{name:`Total evaluation runs`,metric:`evaluations.evaluation_runs`,aggregation:`cardinality`,key:``,colorSet:`tealTones`}],includePrevious:!0,timeScale:k,height:200},j={graphId:`evaluationsPassFailTrend`,graphType:`stacked_bar`,series:[{name:`Evaluations`,metric:`evaluations.evaluation_runs`,aggregation:`cardinality`,key:``,colorSet:`positiveNegativeNeutral`}],groupBy:`evaluations.evaluation_passed`,includePrevious:!1,timeScale:k,height:200},M=(e,t)=>e.map(e=>{let i={},a={},o=null,d=r(e.checkType),f=e.checkType===`langevals/llm_category`;return d?.isGuardrail?(a={graphId:`evalSummary_${e.id}`,graphType:`donnut`,series:[{name:`Checks count`,colorSet:`positiveNegativeNeutral`,metric:`evaluations.evaluation_runs`,aggregation:`cardinality`,key:e.id,filters:{"evaluations.state":{[e.id]:[`processed`]}}}],groupBy:`evaluations.evaluation_passed`,groupByKey:e.id,includePrevious:!1,timeScale:k,height:300},i={graphId:`evalTimeline_${e.id}`,graphType:`stacked_bar`,series:[{name:``,colorSet:`positiveNegativeNeutral`,metric:`evaluations.evaluation_runs`,aggregation:`cardinality`,pipeline:{field:`trace_id`,aggregation:`sum`},key:e.id,filters:{"evaluations.state":{[e.id]:[`processed`]}}}],groupBy:`evaluations.evaluation_passed`,groupByKey:e.id,includePrevious:!1,timeScale:k,height:300},o={graphId:`evalPassRate_${e.id}`,graphType:`line`,series:[{name:`Pass rate`,colorSet:`tealTones`,metric:`evaluations.evaluation_pass_rate`,aggregation:`avg`,key:e.id,filters:{"evaluations.state":{[e.id]:[`processed`]}}}],includePrevious:!1,timeScale:k,height:200}):f?(a={graphId:`evalSummary_${e.id}`,graphType:`donnut`,series:[{name:`Traces count`,colorSet:`colors`,metric:`metadata.trace_id`,aggregation:`cardinality`,filters:{"evaluations.state":{[e.id]:[`processed`]}}}],groupBy:`evaluations.evaluation_label`,groupByKey:e.id,includePrevious:!1,timeScale:k,height:400},i={graphId:`evalTimeline_${e.id}`,graphType:`horizontal_bar`,series:[{name:``,colorSet:`colors`,metric:`metadata.trace_id`,aggregation:`cardinality`,filters:{"evaluations.state":{[e.id]:[`processed`]}}}],groupBy:`evaluations.evaluation_label`,groupByKey:e.id,includePrevious:!1,timeScale:`full`,height:400}):(a={graphId:`evalSummary_${e.id}`,graphType:`summary`,series:[{name:`Evaluation score average`,colorSet:`tealTones`,metric:`evaluations.evaluation_score`,aggregation:`avg`,key:e.id,filters:{"evaluations.state":{[e.id]:[`processed`]}}}],includePrevious:!1,timeScale:k,height:200},i={graphId:`evalTimeline_${e.id}`,graphType:`line`,series:[{name:`Average score`,colorSet:`colors`,metric:`evaluations.evaluation_score`,aggregation:`avg`,key:e.id,filters:{"evaluations.state":{[e.id]:[`processed`]}}}],includePrevious:!1,timeScale:k,height:200}),(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(s,{colSpan:1,display:`inline-grid`,children:(0,O.jsxs)(_,{children:[(0,O.jsxs)(g,{children:[(0,O.jsxs)(u,{gap:2,children:[(0,O.jsx)(w,{color:`orange`}),(0,O.jsx)(c,{size:`sm`,children:e.name})]}),!e.enabled&&(0,O.jsx)(l,{color:`gray`,fontSize:`sm`,children:`(disabled)`})]}),(0,O.jsx)(v,{children:(0,O.jsx)(n,{input:a,onDataPointClick:n=>{t({evaluatorId:e.id,groupKey:n.groupKey,checkType:e.checkType,isGuardrail:d?.isGuardrail??!1})}})})]})}),(0,O.jsx)(s,{colSpan:3,display:`inline-grid`,children:(0,O.jsxs)(_,{children:[(0,O.jsxs)(g,{children:[(0,O.jsxs)(u,{gap:2,children:[(0,O.jsx)(w,{color:`orange`}),(0,O.jsx)(c,{size:`sm`,children:e.name}),d&&(0,O.jsxs)(l,{fontWeight:300,children:[`- `,d.name]})]}),!e.enabled&&(0,O.jsx)(l,{color:`gray`,fontSize:`sm`,children:`(disabled)`})]}),(0,O.jsx)(v,{children:(0,O.jsx)(n,{input:i,onDataPointClick:n=>{t({evaluatorId:e.id,groupKey:n.groupKey,date:n.date,startDate:n.startDate,endDate:n.endDate,checkType:e.checkType,isGuardrail:d?.isGuardrail??!1})}})})]})}),o&&(0,O.jsx)(s,{colSpan:4,display:`inline-grid`,children:(0,O.jsxs)(_,{children:[(0,O.jsx)(g,{children:(0,O.jsxs)(u,{gap:2,children:[(0,O.jsx)(w,{color:`orange`}),(0,O.jsxs)(c,{size:`sm`,children:[e.name,` - Pass Rate Trend`]})]})}),(0,O.jsx)(v,{children:(0,O.jsx)(n,{input:o})})]})})]})});function N(){let{project:e}=C(),t=S(),r=x.monitors.getAllForProject.useQuery({projectId:e?.id??``},{enabled:!!e}),a=(0,D.useCallback)(n=>{if(!e||!n.evaluatorId)return;let r=n.checkType===`langevals/llm_category`,i={[`evaluation_run.${n.evaluatorId}`]:[`processed`]};if(n.isGuardrail&&n.groupKey){let e=n.groupKey===`passed`||n.groupKey===`true`||n.groupKey===`positive`||n.groupKey===`1`,t=n.groupKey===`failed`||n.groupKey===`false`||n.groupKey===`negative`||n.groupKey===`0`;e?i[`evaluation_passed.${n.evaluatorId}`]=`1`:t&&(i[`evaluation_passed.${n.evaluatorId}`]=`0`)}else r&&n.groupKey&&(i[`evaluation_label.${n.evaluatorId}`]=n.groupKey);n.startDate&&n.endDate&&(i.startDate=n.startDate,i.endDate=n.endDate),t.push({pathname:`/${e.slug}/messages`,query:i},void 0,{shallow:!1})},[e,t]);return(0,O.jsxs)(E,{title:`Online Evaluations`,children:[r.data&&r.data?.length===0&&(0,O.jsxs)(f,{colorPalette:`warning`,borderStartWidth:`4px`,borderStartColor:`colorPalette.solid`,marginBottom:6,children:[(0,O.jsx)(m,{}),(0,O.jsxs)(h,{children:[(0,O.jsx)(d,{children:`No online evaluations yet`}),(0,O.jsxs)(p,{children:[(0,O.jsxs)(l,{as:`span`,children:[`The evaluation results will be displayed here. Setup evaluations for your project to see the results. Click`,` `]}),(0,O.jsx)(y,{href:`/${e?.slug}/evaluations`,children:`here`}),(0,O.jsx)(l,{as:`span`,children:` to get started.`})]})]})]}),(0,O.jsxs)(u,{alignItems:`start`,gap:4,children:[(0,O.jsxs)(b,{templateColumns:`repeat(4, 1fr)`,gap:5,width:`100%`,children:[r.data&&r.data.length>0&&(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(s,{colSpan:1,display:`inline-grid`,children:(0,O.jsxs)(_,{children:[(0,O.jsx)(g,{children:(0,O.jsx)(c,{size:`sm`,children:`Overall Health`})}),(0,O.jsx)(v,{children:(0,O.jsx)(n,{input:A})})]})}),(0,O.jsx)(s,{colSpan:3,display:`inline-grid`,children:(0,O.jsxs)(_,{children:[(0,O.jsx)(g,{children:(0,O.jsx)(c,{size:`sm`,children:`Pass / Fail Trend`})}),(0,O.jsx)(v,{children:(0,O.jsx)(n,{input:j})})]})})]}),r.data?M([...r.data].sort((e,t)=>e.enabled===t.enabled?0:e.enabled?-1:1),a):null]}),(0,O.jsx)(o,{padding:3,children:(0,O.jsx)(i,{hideTopics:!0})})]})]})}var P=T(`analytics:view`)(N);export{P as default};
2
+ //# sourceMappingURL=evaluations-C90I4VAr.js.map
@@ -1,2 +1,2 @@
1
- import{s as e}from"./chunk-Bj-mKKzh.js";import{t}from"./react-C7JcuhbW.js";import{$a as n,$s as r,Et as i,Fa as a,Lt as o,Oa as s,Pa as c,Pr as l,Qs as u,Rt as d,Xa as f,Xr as p,Xs as m,Ys as h,Zs as g,ba as _,eo as v,jr as y,mn as b,n as x,nn as S,qi as C,r as w,uo as T,zt as E}from"./command-bar-CaJygoez.js";import{j as D}from"./stack-oJ9iWdbl.js";import{t as O}from"./box-BsM8YLGl.js";import{f as k}from"./LoadingScreen--vgXk5-2.js";import{r as A}from"./dialog.anatomy-hrluUh9u.js";import{n as j}from"./toaster-C_DYALhL.js";import{t as M}from"./text-CwTrMF8x.js";import{i as N,t as P}from"./code-FF_ibTVI.js";import{t as F}from"./h-stack-BKLDJ2vg.js";import{r as I,t as L}from"./card-CMtKVPVl.js";import{Et as R,ut as z}from"./lu-Bf6j_N19.js";import{t as B}from"./spacer-2LJJGbo8.js";import{t as V}from"./v-stack-EOPQ57OZ.js";import{g as H,m as U,s as W}from"./auth-client-D3UhxhQi.js";import{t as G}from"./useOrganizationTeamProject-DC0iozx2.js";import{t as K}from"./WithPermissionGuard-DD8uo3UK.js";var q=e(t()),J=D(),Y=H(`CopyEvaluatorDialog`),X=({open:e,onClose:t,onSuccess:n,evaluatorId:r,evaluatorName:i})=>{let{project:a}=G(),o=W.evaluators.copy.useMutation(),s=d(`evaluations:manage`);return a?(0,J.jsx)(E,{open:e,onClose:t,onSuccess:n,title:`Replicate Evaluator`,entityLabel:`Evaluator`,sourceName:i,sourceId:r,sourceProjectId:a.id,projects:s,onCopy:async({projectId:e,sourceProjectId:t})=>{await o.mutateAsync({evaluatorId:r,projectId:e,sourceProjectId:t})},isLoading:o.isLoading,logError:Y.error.bind(Y)}):null},Z={evaluator:s,workflow:_},Q={evaluator:`Built-in`,workflow:`Workflow`};function $({evaluator:e,onClick:t,onEdit:r,onDelete:a,onUseFromApi:o,onReplicate:u,onPushToCopies:d,onSyncFromSource:p,onViewHistory:m}){let h=Z[e.type]??s,g=Q[e.type]??e.type,[_,y]=(0,q.useState)(!1),b=e.config?.evaluatorType,x=!!e.copiedFromEvaluatorId,S=(e._count?.copiedEvaluators??0)>0,w=()=>{o?o():y(!0)};return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(I,{variant:`elevated`,onClick:t,cursor:`pointer`,height:`142px`,transition:`all 0.2s ease-in-out`,"data-testid":`evaluator-card-${e.id}`,children:(0,J.jsx)(L,{padding:4,children:(0,J.jsxs)(V,{align:`start`,gap:2,height:`full`,children:[(0,J.jsxs)(F,{width:`full`,children:[(0,J.jsx)(O,{bg:`green.subtle`,padding:1,borderRadius:`md`,children:(0,J.jsx)(h,{size:18,color:`var(--chakra-colors-green-fg)`})}),(0,J.jsx)(B,{}),(0,J.jsxs)(C.Root,{children:[(0,J.jsx)(C.Trigger,{className:`js-inner-menu`,onClick:e=>e.stopPropagation(),children:(0,J.jsx)(f,{size:16})}),(0,J.jsxs)(C.Content,{className:`js-inner-menu`,children:[r&&(0,J.jsxs)(C.Item,{value:`edit`,onClick:e=>{e.stopPropagation(),r()},children:[(0,J.jsx)(z,{size:14}),`Edit`]}),(0,J.jsxs)(C.Item,{value:`use-from-api`,onClick:e=>{e.stopPropagation(),w()},"data-testid":`evaluator-use-api-${e.id}`,children:[(0,J.jsx)(P,{size:14}),`Use via API`]}),x&&p&&(0,J.jsxs)(C.Item,{value:`sync`,onClick:e=>{e.stopPropagation(),p()},children:[(0,J.jsx)(c,{size:16}),` Update from source`]}),S&&d&&(0,J.jsxs)(C.Item,{value:`push`,onClick:e=>{e.stopPropagation(),d()},children:[(0,J.jsx)(T,{size:16}),` Push to replicas`]}),u&&(0,J.jsxs)(C.Item,{value:`replicate`,onClick:e=>{e.stopPropagation(),u()},children:[(0,J.jsx)(n,{size:16}),` Replicate to another project`]}),m&&(0,J.jsxs)(C.Item,{value:`history`,onClick:e=>{e.stopPropagation(),m()},children:[(0,J.jsx)(v,{size:14}),`View history`]}),a&&(0,J.jsxs)(C.Item,{value:`delete`,color:`red.500`,onClick:e=>{e.stopPropagation(),a()},children:[(0,J.jsx)(R,{size:14}),`Delete`]})]})]})]}),(0,J.jsx)(B,{}),(0,J.jsx)(M,{color:`fg`,fontSize:`sm`,fontWeight:500,children:e.name}),(0,J.jsxs)(M,{color:`fg.subtle`,fontSize:`12px`,children:[g,b&&` • ${b}`,` •`,` `,l(new Date(e.updatedAt).getTime())]})]})})}),(0,J.jsx)(i,{evaluator:e,open:_,onClose:()=>y(!1)})]})}function ee(){let e=W.useContext();return W.evaluators.pushToCopies.useMutation({onSuccess:(t,n)=>{e.evaluators.getAll.invalidate({projectId:n.projectId})}})}var te=({open:e,onClose:t,evaluatorId:n,evaluatorName:r})=>{let{project:i}=G(),a=ee(),[s,c]=(0,q.useState)(new Set),{data:l,isLoading:u,error:d}=W.evaluators.getCopies.useQuery({projectId:i?.id??``,evaluatorId:n},{enabled:e&&!!i?.id&&!!n}),[f,p]=(0,q.useState)([]);return(0,q.useEffect)(()=>{l&&(p(l),c(new Set(l.map(e=>e.id))))},[l]),(0,J.jsx)(o,{open:e,onClose:t,entityLabel:`Evaluator`,sourceName:r,copies:f,isLoading:u,error:d?{message:d.message}:null,selectedCopyIds:s,onToggleCopy:e=>{let t=new Set(s);t.has(e)?t.delete(e):t.add(e),c(t)},onPush:async()=>{if(!i)throw Error(`No project available for push`);return a.mutateAsync({evaluatorId:n,projectId:i.id,copyIds:Array.from(s)})},pushLoading:a.isLoading,onSuccess:()=>c(new Set)})};function ne(){let{project:e,hasPermission:t}=G(),{openDrawer:n,closeDrawer:i}=w(),o=W.useContext(),[c,l]=(0,q.useState)(null),[d,f]=(0,q.useState)(null),[_,v]=(0,q.useState)(null),C=W.evaluators.syncFromSource.useMutation({onSuccess:(e,t)=>{o.evaluators.getAll.invalidate({projectId:t.projectId}),j.create({title:`Evaluator updated`,description:`Evaluator has been updated from source.`,type:`success`,meta:{closable:!0}})},onError:e=>{U(e)||j.create({title:`Error updating evaluator`,description:e.message??`Please try again later.`,type:`error`})}}),T=(0,q.useCallback)(t=>{e?.id&&C.mutate({projectId:e.id,evaluatorId:t})},[e?.id,C]),E=W.evaluators.getAll.useQuery({projectId:e?.id??``},{enabled:!!e}),D=W.evaluators.getRelatedEntities.useQuery({id:c?.id??``,projectId:e?.id??``},{enabled:!!c&&!!e?.id}),O=W.evaluators.delete.useMutation({onSuccess:()=>{o.evaluators.getAll.invalidate({projectId:e?.id??``}),o.licenseEnforcement.checkLimit.invalidate()}}),M=W.evaluators.cascadeArchive.useMutation({onSuccess:t=>{l(null),o.evaluators.getAll.invalidate({projectId:e?.id??``}),o.licenseEnforcement.checkLimit.invalidate();let n=[];t.archivedWorkflow&&n.push(`1 workflow`),t.deletedMonitorsCount>0&&n.push(`${t.deletedMonitorsCount} online evaluation${t.deletedMonitorsCount>1?`s`:``}`),j.create({title:`Evaluator deleted`,description:n.length>0?`Also deleted: ${n.join(`, `)}`:void 0,type:`success`,meta:{closable:!0}})},onError:()=>{j.create({title:`Error deleting evaluator`,description:`Please try again later.`,type:`error`})}}),P=e=>{let t=e.config;n(`evaluatorEditor`,{evaluatorId:e.id,evaluatorType:t?.evaluatorType})},F=()=>{x(`evaluatorEditor`,S({onSave:()=>(i(),!0)})),n(`evaluatorCategorySelector`)},I=e=>{l(e)},L=()=>{!c||!e||(D.data?.workflow||(D.data?.monitors.length??0)>0?M.mutate({id:c.id,projectId:e.id}):O.mutate({id:c.id,projectId:e.id},{onSuccess:()=>{l(null),j.create({title:`Evaluator deleted`,type:`success`,meta:{closable:!0}})},onError:()=>{j.create({title:`Error deleting evaluator`,description:`Please try again later.`,type:`error`})}}))},R=E.data&&E.data.length>0,z=!E.isLoading&&!R;return(0,J.jsxs)(b,{children:[(0,J.jsxs)(p.Header,{children:[(0,J.jsx)(p.Heading,{children:`Evaluators`}),(0,J.jsx)(B,{}),(0,J.jsxs)(p.HeaderButton,{onClick:F,children:[(0,J.jsx)(a,{size:16}),` New Evaluator`]})]}),z?(0,J.jsx)(N,{flex:1,padding:6,children:(0,J.jsx)(u,{children:(0,J.jsxs)(h,{children:[(0,J.jsx)(g,{children:(0,J.jsx)(s,{size:32})}),(0,J.jsx)(r,{children:`No evaluators yet`}),(0,J.jsx)(m,{children:`Create reusable evaluators for your evaluations.`}),(0,J.jsxs)(p.HeaderButton,{onClick:F,children:[(0,J.jsx)(a,{size:16}),` Create your first evaluator`]})]})})}):(0,J.jsx)(V,{gap:6,width:`full`,align:`start`,padding:6,children:(0,J.jsxs)(A,{templateColumns:`repeat(auto-fill, minmax(300px, 1fr))`,gap:4,width:`full`,children:[E.isLoading&&Array.from({length:3}).map((e,t)=>(0,J.jsx)(k,{height:`100px`,borderRadius:`md`},t)),E.data?.map(e=>(0,J.jsx)($,{evaluator:e,onClick:()=>P(e),onEdit:()=>P(e),onDelete:()=>I(e),onReplicate:()=>f({id:e.id,name:e.name}),onPushToCopies:()=>v({id:e.id,name:e.name}),onSyncFromSource:()=>T(e.id),onViewHistory:()=>n(`evaluatorHistory`,{urlParams:{evaluatorId:e.id,evaluatorName:e.name}})},e.id))]})}),(0,J.jsx)(y,{open:!!c,onClose:()=>l(null),onConfirm:L,isLoading:M.isPending||O.isPending,isLoadingRelated:D.isLoading,entityType:`evaluator`,entityName:c?.name??``,relatedEntities:{workflows:D.data?.workflow?[D.data.workflow]:[],monitors:D.data?.monitors}}),(0,J.jsx)(X,{open:!!d,onClose:()=>f(null),onSuccess:()=>void o.evaluators.getAll.invalidate({projectId:e?.id??``}),evaluatorId:d?.id??``,evaluatorName:d?.name??``}),(0,J.jsx)(te,{open:!!_,onClose:()=>v(null),evaluatorId:_?.id??``,evaluatorName:_?.name??``})]})}var re=K(`evaluations:view`,{layoutComponent:b})(ne);export{re as default};
2
- //# sourceMappingURL=evaluators-DLHVvnrh.js.map
1
+ import{s as e}from"./chunk-Bj-mKKzh.js";import{t}from"./react-C7JcuhbW.js";import{$a as n,$s as r,Et as i,Fa as a,Lt as o,Oa as s,Pa as c,Pr as l,Qs as u,Rt as d,Xa as f,Xr as p,Xs as m,Ys as h,Zs as g,ba as _,eo as v,jr as y,mn as b,n as x,nn as S,qi as C,r as w,uo as T,zt as E}from"./command-bar-DUK45yin.js";import{j as D}from"./stack-oJ9iWdbl.js";import{t as O}from"./box-BsM8YLGl.js";import{f as k}from"./LoadingScreen--vgXk5-2.js";import{r as A}from"./dialog.anatomy-hrluUh9u.js";import{n as j}from"./toaster-C_DYALhL.js";import{t as M}from"./text-CwTrMF8x.js";import{i as N,t as P}from"./code-FF_ibTVI.js";import{t as F}from"./h-stack-BKLDJ2vg.js";import{r as I,t as L}from"./card-CMtKVPVl.js";import{Et as R,ut as z}from"./lu-Bf6j_N19.js";import{t as B}from"./spacer-2LJJGbo8.js";import{t as V}from"./v-stack-EOPQ57OZ.js";import{g as H,m as U,s as W}from"./auth-client-D3UhxhQi.js";import{t as G}from"./useOrganizationTeamProject-DC0iozx2.js";import{t as K}from"./WithPermissionGuard-B4Jo8E5-.js";var q=e(t()),J=D(),Y=H(`CopyEvaluatorDialog`),X=({open:e,onClose:t,onSuccess:n,evaluatorId:r,evaluatorName:i})=>{let{project:a}=G(),o=W.evaluators.copy.useMutation(),s=d(`evaluations:manage`);return a?(0,J.jsx)(E,{open:e,onClose:t,onSuccess:n,title:`Replicate Evaluator`,entityLabel:`Evaluator`,sourceName:i,sourceId:r,sourceProjectId:a.id,projects:s,onCopy:async({projectId:e,sourceProjectId:t})=>{await o.mutateAsync({evaluatorId:r,projectId:e,sourceProjectId:t})},isLoading:o.isLoading,logError:Y.error.bind(Y)}):null},Z={evaluator:s,workflow:_},Q={evaluator:`Built-in`,workflow:`Workflow`};function $({evaluator:e,onClick:t,onEdit:r,onDelete:a,onUseFromApi:o,onReplicate:u,onPushToCopies:d,onSyncFromSource:p,onViewHistory:m}){let h=Z[e.type]??s,g=Q[e.type]??e.type,[_,y]=(0,q.useState)(!1),b=e.config?.evaluatorType,x=!!e.copiedFromEvaluatorId,S=(e._count?.copiedEvaluators??0)>0,w=()=>{o?o():y(!0)};return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(I,{variant:`elevated`,onClick:t,cursor:`pointer`,height:`142px`,transition:`all 0.2s ease-in-out`,"data-testid":`evaluator-card-${e.id}`,children:(0,J.jsx)(L,{padding:4,children:(0,J.jsxs)(V,{align:`start`,gap:2,height:`full`,children:[(0,J.jsxs)(F,{width:`full`,children:[(0,J.jsx)(O,{bg:`green.subtle`,padding:1,borderRadius:`md`,children:(0,J.jsx)(h,{size:18,color:`var(--chakra-colors-green-fg)`})}),(0,J.jsx)(B,{}),(0,J.jsxs)(C.Root,{children:[(0,J.jsx)(C.Trigger,{className:`js-inner-menu`,onClick:e=>e.stopPropagation(),children:(0,J.jsx)(f,{size:16})}),(0,J.jsxs)(C.Content,{className:`js-inner-menu`,children:[r&&(0,J.jsxs)(C.Item,{value:`edit`,onClick:e=>{e.stopPropagation(),r()},children:[(0,J.jsx)(z,{size:14}),`Edit`]}),(0,J.jsxs)(C.Item,{value:`use-from-api`,onClick:e=>{e.stopPropagation(),w()},"data-testid":`evaluator-use-api-${e.id}`,children:[(0,J.jsx)(P,{size:14}),`Use via API`]}),x&&p&&(0,J.jsxs)(C.Item,{value:`sync`,onClick:e=>{e.stopPropagation(),p()},children:[(0,J.jsx)(c,{size:16}),` Update from source`]}),S&&d&&(0,J.jsxs)(C.Item,{value:`push`,onClick:e=>{e.stopPropagation(),d()},children:[(0,J.jsx)(T,{size:16}),` Push to replicas`]}),u&&(0,J.jsxs)(C.Item,{value:`replicate`,onClick:e=>{e.stopPropagation(),u()},children:[(0,J.jsx)(n,{size:16}),` Replicate to another project`]}),m&&(0,J.jsxs)(C.Item,{value:`history`,onClick:e=>{e.stopPropagation(),m()},children:[(0,J.jsx)(v,{size:14}),`View history`]}),a&&(0,J.jsxs)(C.Item,{value:`delete`,color:`red.500`,onClick:e=>{e.stopPropagation(),a()},children:[(0,J.jsx)(R,{size:14}),`Delete`]})]})]})]}),(0,J.jsx)(B,{}),(0,J.jsx)(M,{color:`fg`,fontSize:`sm`,fontWeight:500,children:e.name}),(0,J.jsxs)(M,{color:`fg.subtle`,fontSize:`12px`,children:[g,b&&` • ${b}`,` •`,` `,l(new Date(e.updatedAt).getTime())]})]})})}),(0,J.jsx)(i,{evaluator:e,open:_,onClose:()=>y(!1)})]})}function ee(){let e=W.useContext();return W.evaluators.pushToCopies.useMutation({onSuccess:(t,n)=>{e.evaluators.getAll.invalidate({projectId:n.projectId})}})}var te=({open:e,onClose:t,evaluatorId:n,evaluatorName:r})=>{let{project:i}=G(),a=ee(),[s,c]=(0,q.useState)(new Set),{data:l,isLoading:u,error:d}=W.evaluators.getCopies.useQuery({projectId:i?.id??``,evaluatorId:n},{enabled:e&&!!i?.id&&!!n}),[f,p]=(0,q.useState)([]);return(0,q.useEffect)(()=>{l&&(p(l),c(new Set(l.map(e=>e.id))))},[l]),(0,J.jsx)(o,{open:e,onClose:t,entityLabel:`Evaluator`,sourceName:r,copies:f,isLoading:u,error:d?{message:d.message}:null,selectedCopyIds:s,onToggleCopy:e=>{let t=new Set(s);t.has(e)?t.delete(e):t.add(e),c(t)},onPush:async()=>{if(!i)throw Error(`No project available for push`);return a.mutateAsync({evaluatorId:n,projectId:i.id,copyIds:Array.from(s)})},pushLoading:a.isLoading,onSuccess:()=>c(new Set)})};function ne(){let{project:e,hasPermission:t}=G(),{openDrawer:n,closeDrawer:i}=w(),o=W.useContext(),[c,l]=(0,q.useState)(null),[d,f]=(0,q.useState)(null),[_,v]=(0,q.useState)(null),C=W.evaluators.syncFromSource.useMutation({onSuccess:(e,t)=>{o.evaluators.getAll.invalidate({projectId:t.projectId}),j.create({title:`Evaluator updated`,description:`Evaluator has been updated from source.`,type:`success`,meta:{closable:!0}})},onError:e=>{U(e)||j.create({title:`Error updating evaluator`,description:e.message??`Please try again later.`,type:`error`})}}),T=(0,q.useCallback)(t=>{e?.id&&C.mutate({projectId:e.id,evaluatorId:t})},[e?.id,C]),E=W.evaluators.getAll.useQuery({projectId:e?.id??``},{enabled:!!e}),D=W.evaluators.getRelatedEntities.useQuery({id:c?.id??``,projectId:e?.id??``},{enabled:!!c&&!!e?.id}),O=W.evaluators.delete.useMutation({onSuccess:()=>{o.evaluators.getAll.invalidate({projectId:e?.id??``}),o.licenseEnforcement.checkLimit.invalidate()}}),M=W.evaluators.cascadeArchive.useMutation({onSuccess:t=>{l(null),o.evaluators.getAll.invalidate({projectId:e?.id??``}),o.licenseEnforcement.checkLimit.invalidate();let n=[];t.archivedWorkflow&&n.push(`1 workflow`),t.deletedMonitorsCount>0&&n.push(`${t.deletedMonitorsCount} online evaluation${t.deletedMonitorsCount>1?`s`:``}`),j.create({title:`Evaluator deleted`,description:n.length>0?`Also deleted: ${n.join(`, `)}`:void 0,type:`success`,meta:{closable:!0}})},onError:()=>{j.create({title:`Error deleting evaluator`,description:`Please try again later.`,type:`error`})}}),P=e=>{let t=e.config;n(`evaluatorEditor`,{evaluatorId:e.id,evaluatorType:t?.evaluatorType})},F=()=>{x(`evaluatorEditor`,S({onSave:()=>(i(),!0)})),n(`evaluatorCategorySelector`)},I=e=>{l(e)},L=()=>{!c||!e||(D.data?.workflow||(D.data?.monitors.length??0)>0?M.mutate({id:c.id,projectId:e.id}):O.mutate({id:c.id,projectId:e.id},{onSuccess:()=>{l(null),j.create({title:`Evaluator deleted`,type:`success`,meta:{closable:!0}})},onError:()=>{j.create({title:`Error deleting evaluator`,description:`Please try again later.`,type:`error`})}}))},R=E.data&&E.data.length>0,z=!E.isLoading&&!R;return(0,J.jsxs)(b,{children:[(0,J.jsxs)(p.Header,{children:[(0,J.jsx)(p.Heading,{children:`Evaluators`}),(0,J.jsx)(B,{}),(0,J.jsxs)(p.HeaderButton,{onClick:F,children:[(0,J.jsx)(a,{size:16}),` New Evaluator`]})]}),z?(0,J.jsx)(N,{flex:1,padding:6,children:(0,J.jsx)(u,{children:(0,J.jsxs)(h,{children:[(0,J.jsx)(g,{children:(0,J.jsx)(s,{size:32})}),(0,J.jsx)(r,{children:`No evaluators yet`}),(0,J.jsx)(m,{children:`Create reusable evaluators for your evaluations.`}),(0,J.jsxs)(p.HeaderButton,{onClick:F,children:[(0,J.jsx)(a,{size:16}),` Create your first evaluator`]})]})})}):(0,J.jsx)(V,{gap:6,width:`full`,align:`start`,padding:6,children:(0,J.jsxs)(A,{templateColumns:`repeat(auto-fill, minmax(300px, 1fr))`,gap:4,width:`full`,children:[E.isLoading&&Array.from({length:3}).map((e,t)=>(0,J.jsx)(k,{height:`100px`,borderRadius:`md`},t)),E.data?.map(e=>(0,J.jsx)($,{evaluator:e,onClick:()=>P(e),onEdit:()=>P(e),onDelete:()=>I(e),onReplicate:()=>f({id:e.id,name:e.name}),onPushToCopies:()=>v({id:e.id,name:e.name}),onSyncFromSource:()=>T(e.id),onViewHistory:()=>n(`evaluatorHistory`,{urlParams:{evaluatorId:e.id,evaluatorName:e.name}})},e.id))]})}),(0,J.jsx)(y,{open:!!c,onClose:()=>l(null),onConfirm:L,isLoading:M.isPending||O.isPending,isLoadingRelated:D.isLoading,entityType:`evaluator`,entityName:c?.name??``,relatedEntities:{workflows:D.data?.workflow?[D.data.workflow]:[],monitors:D.data?.monitors}}),(0,J.jsx)(X,{open:!!d,onClose:()=>f(null),onSuccess:()=>void o.evaluators.getAll.invalidate({projectId:e?.id??``}),evaluatorId:d?.id??``,evaluatorName:d?.name??``}),(0,J.jsx)(te,{open:!!_,onClose:()=>v(null),evaluatorId:_?.id??``,evaluatorName:_?.name??``})]})}var re=K(`evaluations:view`,{layoutComponent:b})(ne);export{re as default};
2
+ //# sourceMappingURL=evaluators-ig_ugRLt.js.map
@@ -1,4 +1,4 @@
1
1
  const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/dist-B1d0YXwd.js","assets/chunk-Bj-mKKzh.js","assets/react-C7JcuhbW.js"])))=>i.map(i=>d[i]);
2
- import{s as e}from"./chunk-Bj-mKKzh.js";import{t}from"./react-C7JcuhbW.js";import{t as n}from"./preload-helper-rov5CBGT.js";import{$a as r,As as i,Ds as a,Fa as o,La as s,Ma as c,Ms as l,Os as u,Xr as d,ao as f,gs as p,js as m,ks as h,mn as g,sc as _,wa as v}from"./command-bar-CaJygoez.js";import{j as ee,n as y}from"./stack-oJ9iWdbl.js";import{t as b}from"./box-BsM8YLGl.js";import{c as x}from"./LoadingScreen--vgXk5-2.js";import{r as S}from"./dialog.anatomy-hrluUh9u.js";import{i as te,o as C,r as ne,s as w,t as T}from"./tabs-DwV1cIZB.js";import{i as E}from"./toaster-C_DYALhL.js";import{an as D,at as re,ct as ie,gt as O,in as k,lt as A,pt as ae}from"./dist-SwV3YZv3.js";import{t as j}from"./text-CwTrMF8x.js";import{i as oe,n as M,r as se}from"./code-FF_ibTVI.js";import{t as N}from"./input-C7emsUCL.js";import{t as P}from"./h-stack-BKLDJ2vg.js";import{Pt as F}from"./lu-Bf6j_N19.js";import{t as I}from"./v-stack-EOPQ57OZ.js";import{s as ce}from"./auth-client-D3UhxhQi.js";import{t as L}from"./useOrganizationTeamProject-DC0iozx2.js";import{a as R,c as z,i as B,l as V,n as H,o as le,r as ue,s as U,t as de}from"./traceExecutor-CiHXJB0V.js";import{t as fe}from"./createLucideIcon-BJKFyRLS.js";import{t as pe}from"./arrow-right-B3ZN8yal.js";import{t as me}from"./chevron-up-BvG6wkCS.js";import{t as he}from"./next-dynamic-CldmZdeI.js";/* empty css */import{t as ge}from"./OpsPageShell-DJ1WlI6-.js";var _e=fe(`text-wrap`,[[`path`,{d:`m16 16-3 3 3 3`,key:`117b85`}],[`path`,{d:`M3 12h14.5a1 1 0 0 1 0 7H13`,key:`18xa6z`}],[`path`,{d:`M3 19h6`,key:`1ygdsz`}],[`path`,{d:`M3 5h18`,key:`1u36vt`}]]),W=e(t()),G=ee();function K({span:e,depth:t}){let n=R(e=>e.selectedSpanId),i=R(e=>e.selectSpan),a=R(e=>e.removeSpan),o=R(e=>e.duplicateSpan),s=R(e=>e.moveSpan),c=n===e.id;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(k,{align:`center`,gap:1.5,px:2,py:1,pl:`${t*16+8}px`,rounded:`md`,cursor:`pointer`,fontSize:`xs`,bg:c?`orange.500/10`:`transparent`,color:c?`orange.400`:`fg.default`,_hover:{bg:c?`orange.500/10`:`bg.subtle`},onClick:()=>i(e.id),role:`group`,children:[(0,G.jsx)(j,{as:`span`,flexShrink:0,fontSize:`sm`,children:V[e.type]}),(0,G.jsx)(j,{flex:1,truncate:!0,fontWeight:`medium`,children:e.name}),(0,G.jsx)(j,{flexShrink:0,fontSize:`10px`,textTransform:`uppercase`,color:z[e.type],children:e.type}),e.status===`error`&&(0,G.jsx)(j,{color:`red.400`,fontWeight:`bold`,children:`!`}),(0,G.jsxs)(k,{gap:0,display:`none`,_groupHover:{display:`flex`},children:[(0,G.jsx)(F,{"aria-label":`Up`,size:`2xs`,variant:`ghost`,color:`fg.muted`,onClick:t=>{t.stopPropagation(),s(e.id,`up`)},children:(0,G.jsx)(me,{size:12})}),(0,G.jsx)(F,{"aria-label":`Down`,size:`2xs`,variant:`ghost`,color:`fg.muted`,onClick:t=>{t.stopPropagation(),s(e.id,`down`)},children:(0,G.jsx)(f,{size:12})}),(0,G.jsx)(F,{"aria-label":`Copy`,size:`2xs`,variant:`ghost`,color:`fg.muted`,onClick:t=>{t.stopPropagation(),o(e.id)},children:(0,G.jsx)(r,{size:12})}),(0,G.jsx)(F,{"aria-label":`Delete`,size:`2xs`,variant:`ghost`,color:`fg.muted`,_hover:{color:`red.400`},onClick:t=>{t.stopPropagation(),a(e.id)},children:(0,G.jsx)(v,{size:12})})]})]}),e.children.map(e=>(0,G.jsx)(K,{span:e,depth:t+1},e.id))]})}var ve=[`llm`,`agent`,`tool`,`rag`,`chain`,`prompt`,`guardrail`,`span`];function ye({parentId:e}){let[t,n]=(0,W.useState)(!1),r=R(e=>e.addSpan);return(0,G.jsxs)(b,{position:`relative`,mt:1,children:[(0,G.jsxs)(k,{as:`button`,w:`full`,align:`center`,justify:`center`,gap:1,rounded:`md`,border:`1px dashed`,borderColor:`border`,px:2,py:1.5,fontSize:`xs`,color:`fg.muted`,_hover:{borderColor:`border.emphasized`,color:`fg.default`},onClick:()=>n(!t),children:[(0,G.jsx)(o,{size:12}),` Add Span`]}),t&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(b,{position:`fixed`,inset:0,zIndex:10,onClick:()=>n(!1)}),(0,G.jsx)(b,{position:`absolute`,left:0,zIndex:20,mt:1,w:`full`,rounded:`lg`,border:`1px solid`,borderColor:`border`,bg:`bg.panel`,p:1,shadow:`xl`,children:ve.map(t=>(0,G.jsxs)(k,{as:`button`,w:`full`,align:`center`,gap:2,rounded:`md`,px:2,py:1.5,fontSize:`xs`,color:`fg.default`,_hover:{bg:`bg.subtle`},onClick:()=>{r(e,t),n(!1)},children:[(0,G.jsx)(j,{as:`span`,children:V[t]}),(0,G.jsx)(j,{textTransform:`capitalize`,children:t})]},t))})]})]})}function be(){let e=R(e=>e.trace.spans);return(0,G.jsxs)(b,{p:3,children:[(0,G.jsx)(j,{fontSize:`xs`,fontWeight:`medium`,textTransform:`uppercase`,letterSpacing:`wider`,color:`fg.muted`,mb:2,children:`Spans`}),(0,G.jsx)(k,{direction:`column`,gap:.5,children:e.map(e=>(0,G.jsx)(K,{span:e,depth:0},e.id))}),(0,G.jsx)(ye,{parentId:null})]})}var xe=[{label:`GPT-4o`,value:`gpt-4o`},{label:`GPT-4o Mini`,value:`gpt-4o-mini`},{label:`GPT-4.1`,value:`gpt-4.1`},{label:`GPT-4.1 Mini`,value:`gpt-4.1-mini`},{label:`GPT-5 Mini`,value:`gpt-5-mini`},{label:`o3`,value:`o3`},{label:`o4-mini`,value:`o4-mini`},{label:`Claude Opus 4`,value:`claude-opus-4-20250514`},{label:`Claude Sonnet 4`,value:`claude-sonnet-4-20250514`},{label:`Claude Haiku 3.5`,value:`claude-3-5-haiku-20241022`},{label:`Gemini 2.5 Pro`,value:`gemini-2.5-pro`},{label:`Gemini 2.5 Flash`,value:`gemini-2.5-flash`},{label:`Grok 3`,value:`grok-3`},{label:`Grok 3 Mini`,value:`grok-3-mini`},{label:`Llama 4 Scout`,value:`meta-llama/llama-4-scout`},{label:`DeepSeek V3`,value:`deepseek-chat`},{label:`DeepSeek R1`,value:`deepseek-reasoner`},{label:`Mistral Large`,value:`mistral-large-latest`}],Se={system:`purple.500`,user:`green.400`,assistant:`blue.400`,tool:`yellow.400`};function Ce({span:e}){let t=R(e=>e.updateSpan),n=e.llm??{};function r(r){t(e.id,{llm:{...n,...r}})}let i=n.messages??[];function a(e,t){r({messages:i.map((n,r)=>r===e?{...n,...t}:n)})}return(0,G.jsxs)(b,{rounded:`lg`,border:`1px solid`,borderColor:`blue.500/20`,bg:`blue.500/5`,p:4,children:[(0,G.jsx)(j,{fontSize:`sm`,fontWeight:`semibold`,color:`blue.400`,mb:3,children:`LLM Configuration`}),(0,G.jsxs)(k,{gap:3,wrap:`wrap`,mb:3,children:[(0,G.jsxs)(b,{flex:1,minW:`140px`,children:[(0,G.jsx)(j,{fontSize:`xs`,color:`fg.subtle`,mb:1,children:`Model`}),(0,G.jsx)(N,{size:`sm`,value:n.requestModel??``,onChange:e=>r({requestModel:e.target.value}),placeholder:`gpt-4o`,list:`llm-models`}),(0,G.jsx)(`datalist`,{id:`llm-models`,children:xe.map(e=>(0,G.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),(0,G.jsxs)(b,{w:`80px`,children:[(0,G.jsx)(j,{fontSize:`xs`,color:`fg.subtle`,mb:1,children:`Temp`}),(0,G.jsx)(N,{size:`sm`,type:`number`,value:n.temperature??.7,onChange:e=>r({temperature:parseFloat(e.target.value)}),step:.1,min:0,max:2})]})]}),(0,G.jsx)(j,{fontSize:`xs`,fontWeight:`medium`,color:`fg.subtle`,mb:1,children:`Messages`}),(0,G.jsxs)(k,{direction:`column`,gap:2,mb:2,children:[i.map((e,t)=>(0,G.jsxs)(k,{gap:2,rounded:`md`,border:`1px solid`,borderColor:`border`,borderLeftWidth:`2px`,borderLeftColor:Se[e.role]??`gray.500`,bg:`bg.subtle`,p:2,children:[(0,G.jsxs)(`select`,{value:e.role,onChange:e=>a(t,{role:e.target.value}),style:{width:`90px`,flexShrink:0,background:`var(--chakra-colors-bg-subtle)`,color:`var(--chakra-colors-fg-default)`,border:`1px solid var(--chakra-colors-border)`,borderRadius:`4px`,padding:`2px 6px`,fontSize:`12px`},children:[(0,G.jsx)(`option`,{value:`system`,children:`system`}),(0,G.jsx)(`option`,{value:`user`,children:`user`}),(0,G.jsx)(`option`,{value:`assistant`,children:`assistant`}),(0,G.jsx)(`option`,{value:`tool`,children:`tool`})]}),(0,G.jsx)(p,{flex:1,size:`sm`,fontSize:`xs`,value:e.content,onChange:e=>a(t,{content:e.target.value}),rows:2,resize:`vertical`,placeholder:`Message content...`}),(0,G.jsx)(y,{size:`xs`,variant:`ghost`,color:`fg.muted`,_hover:{color:`red.400`},onClick:()=>r({messages:i.filter((e,n)=>n!==t)}),alignSelf:`flex-start`,children:(0,G.jsx)(v,{size:12})})]},t)),(0,G.jsxs)(y,{size:`xs`,variant:`outline`,onClick:()=>r({messages:[...i,{role:`user`,content:``}]}),children:[(0,G.jsx)(o,{size:12}),` Add Message`]})]}),(0,G.jsx)(j,{fontSize:`xs`,fontWeight:`medium`,color:`fg.subtle`,mb:1,children:`Metrics`}),(0,G.jsxs)(k,{gap:3,children:[(0,G.jsxs)(b,{flex:1,children:[(0,G.jsx)(j,{fontSize:`xs`,color:`fg.muted`,mb:1,children:`Prompt Tokens`}),(0,G.jsx)(N,{size:`sm`,type:`number`,value:n.metrics?.promptTokens??``,onChange:e=>r({metrics:{...n.metrics,promptTokens:parseInt(e.target.value)||void 0}}),placeholder:`0`})]}),(0,G.jsxs)(b,{flex:1,children:[(0,G.jsx)(j,{fontSize:`xs`,color:`fg.muted`,mb:1,children:`Completion Tokens`}),(0,G.jsx)(N,{size:`sm`,type:`number`,value:n.metrics?.completionTokens??``,onChange:e=>r({metrics:{...n.metrics,completionTokens:parseInt(e.target.value)||void 0}}),placeholder:`0`})]}),(0,G.jsxs)(b,{flex:1,children:[(0,G.jsx)(j,{fontSize:`xs`,color:`fg.muted`,mb:1,children:`Cost ($)`}),(0,G.jsx)(N,{size:`sm`,type:`number`,value:n.metrics?.cost??``,onChange:e=>r({metrics:{...n.metrics,cost:parseFloat(e.target.value)||void 0}}),step:1e-4,placeholder:`0.00`})]})]})]})}function we({span:e}){let t=R(e=>e.updateSpan),n=e.rag?.contexts??[];function r(r,i){let a=n.map((e,t)=>t===r?{...e,...i}:e);t(e.id,{rag:{contexts:a}})}return(0,G.jsxs)(b,{rounded:`lg`,border:`1px solid`,borderColor:`teal.500/20`,bg:`teal.500/5`,p:4,children:[(0,G.jsx)(j,{fontSize:`sm`,fontWeight:`semibold`,color:`teal.400`,mb:3,children:`RAG Contexts`}),(0,G.jsxs)(k,{direction:`column`,gap:3,children:[n.map((i,a)=>(0,G.jsxs)(b,{rounded:`md`,border:`1px solid`,borderColor:`border`,bg:`bg.subtle`,p:3,children:[(0,G.jsxs)(k,{justify:`space-between`,mb:2,children:[(0,G.jsxs)(j,{fontSize:`xs`,fontWeight:`medium`,color:`fg.subtle`,children:[`Context `,a+1]}),(0,G.jsx)(y,{size:`xs`,variant:`ghost`,color:`fg.muted`,_hover:{color:`red.400`},onClick:()=>t(e.id,{rag:{contexts:n.filter((e,t)=>t!==a)}}),children:(0,G.jsx)(v,{size:12})})]}),(0,G.jsxs)(k,{gap:2,mb:2,children:[(0,G.jsx)(N,{size:`sm`,flex:1,value:i.document_id,onChange:e=>r(a,{document_id:e.target.value}),placeholder:`Document ID`}),(0,G.jsx)(N,{size:`sm`,flex:1,value:i.chunk_id,onChange:e=>r(a,{chunk_id:e.target.value}),placeholder:`Chunk ID`})]}),(0,G.jsx)(p,{size:`sm`,fontSize:`xs`,value:i.content,onChange:e=>r(a,{content:e.target.value}),placeholder:`Retrieved content...`,rows:3})]},a)),(0,G.jsxs)(y,{size:`xs`,variant:`outline`,onClick:()=>t(e.id,{rag:{contexts:[...n,{document_id:``,chunk_id:``,content:``}]}}),children:[(0,G.jsx)(o,{size:12}),` Add Context`]})]})]})}function Te({span:e}){let t=R(e=>e.updateSpan),n=e.prompt??{};function r(r){t(e.id,{prompt:{...n,...r}})}let i=n.variables??{},a=Object.entries(i);return(0,G.jsxs)(b,{rounded:`lg`,border:`1px solid`,borderColor:`yellow.500/20`,bg:`yellow.500/5`,p:4,children:[(0,G.jsx)(j,{fontSize:`sm`,fontWeight:`semibold`,color:`yellow.400`,mb:3,children:`Prompt Configuration`}),(0,G.jsxs)(k,{gap:3,mb:3,children:[(0,G.jsxs)(b,{flex:1,children:[(0,G.jsx)(j,{fontSize:`xs`,color:`fg.subtle`,mb:1,children:`Prompt ID`}),(0,G.jsx)(N,{size:`sm`,value:n.promptId??``,onChange:e=>r({promptId:e.target.value}),placeholder:`e.g. customer-support-v2`})]}),(0,G.jsxs)(b,{flex:1,children:[(0,G.jsx)(j,{fontSize:`xs`,color:`fg.subtle`,mb:1,children:`Version ID`}),(0,G.jsx)(N,{size:`sm`,value:n.versionId??``,onChange:e=>r({versionId:e.target.value}),placeholder:`e.g. ver-abc123`})]})]}),(0,G.jsx)(j,{fontSize:`xs`,fontWeight:`medium`,color:`fg.subtle`,mb:1,children:`Template Variables`}),(0,G.jsxs)(k,{direction:`column`,gap:1,children:[a.map(([e,t])=>(0,G.jsxs)(k,{align:`center`,gap:2,children:[(0,G.jsx)(N,{size:`sm`,w:`120px`,flexShrink:0,value:e,onChange:n=>{let a={...i};delete a[e],a[n.target.value]=t,r({variables:a})},placeholder:`key`}),(0,G.jsx)(N,{size:`sm`,flex:1,value:t,onChange:t=>r({variables:{...i,[e]:t.target.value}}),placeholder:`value`}),(0,G.jsx)(y,{size:`xs`,variant:`ghost`,color:`fg.muted`,_hover:{color:`red.400`},onClick:()=>{let t={...i};delete t[e],r({variables:t})},children:(0,G.jsx)(v,{size:12})})]},e)),(0,G.jsxs)(y,{size:`xs`,variant:`outline`,onClick:()=>r({variables:{...i,[`var_${a.length+1}`]:``}}),children:[(0,G.jsx)(o,{size:12}),` Add Variable`]})]})]})}function Ee({attributes:e,onChange:t}){let n=Object.entries(e),[r,i]=(0,W.useState)(``);function a(){!r||r in e||(t({...e,[r]:``}),i(``))}function s(n,r){let i=r;r===`true`?i=!0:r===`false`?i=!1:/^\d+(\.\d+)?$/.test(r)&&(i=parseFloat(r)),t({...e,[n]:i})}return(0,G.jsxs)(k,{direction:`column`,gap:1,mt:1,children:[n.map(([n,r])=>(0,G.jsxs)(k,{align:`center`,gap:2,children:[(0,G.jsx)(j,{fontSize:`xs`,color:`fg.subtle`,w:`140px`,flexShrink:0,truncate:!0,children:n}),(0,G.jsx)(N,{size:`sm`,flex:1,fontSize:`xs`,value:String(r),onChange:e=>s(n,e.target.value)}),(0,G.jsx)(y,{size:`xs`,variant:`ghost`,color:`fg.muted`,_hover:{color:`red.400`},onClick:()=>{let r={...e};delete r[n],t(r)},children:(0,G.jsx)(v,{size:12})})]},n)),(0,G.jsxs)(k,{align:`center`,gap:2,children:[(0,G.jsx)(N,{size:`sm`,w:`140px`,flexShrink:0,fontSize:`xs`,value:r,onChange:e=>i(e.target.value),onKeyDown:e=>e.key===`Enter`&&a(),placeholder:`attribute.key`}),(0,G.jsxs)(y,{size:`xs`,variant:`outline`,onClick:a,disabled:!r,children:[(0,G.jsx)(o,{size:12}),` Add`]})]})]})}function q(e,t){for(let n of e){if(n.id===t)return n;let e=q(n.children,t);if(e)return e}}var De=_({items:U.map(e=>({label:`${V[e]} ${e}`,value:e}))}),Oe=_({items:[{label:`OK`,value:`ok`},{label:`Error`,value:`error`},{label:`Unset`,value:`unset`}]});function ke(){let e=R(e=>e.selectedSpanId),t=R(e=>e.trace.spans),n=R(e=>e.updateSpan),r=R(e=>e.indentSpan),o=R(e=>e.outdentSpan);if(!e)return null;let s=q(t,e);return s?(0,G.jsxs)(I,{align:`stretch`,gap:4,p:5,minW:0,overflow:`hidden`,children:[(0,G.jsxs)(k,{align:`center`,justify:`space-between`,children:[(0,G.jsx)(j,{fontSize:`lg`,fontWeight:`semibold`,children:s.name}),(0,G.jsxs)(P,{gap:1,children:[(0,G.jsx)(y,{size:`xs`,variant:`outline`,onClick:()=>r(s.id),children:(0,G.jsx)(pe,{size:14})}),(0,G.jsx)(y,{size:`xs`,variant:`outline`,onClick:()=>o(s.id),children:(0,G.jsx)(se,{size:14})})]})]}),(0,G.jsxs)(k,{gap:3,wrap:`wrap`,children:[(0,G.jsxs)(b,{flex:`1`,minW:`140px`,children:[(0,G.jsx)(j,{fontSize:`xs`,color:`fg.subtle`,mb:1,children:`Name`}),(0,G.jsx)(N,{size:`sm`,value:s.name,onChange:e=>n(s.id,{name:e.target.value})})]}),(0,G.jsxs)(b,{flex:`1`,minW:`140px`,children:[(0,G.jsx)(j,{fontSize:`xs`,color:`fg.subtle`,mb:1,children:`Type`}),(0,G.jsxs)(i,{size:`sm`,collection:De,value:[s.type],onValueChange:e=>n(s.id,{type:e.value[0]}),children:[(0,G.jsx)(m,{children:(0,G.jsx)(l,{})}),(0,G.jsx)(E,{children:(0,G.jsx)(h,{children:(0,G.jsx)(a,{children:U.map(e=>(0,G.jsxs)(u,{item:e,children:[V[e],` `,e]},e))})})})]})]})]}),(0,G.jsxs)(k,{gap:3,wrap:`wrap`,children:[(0,G.jsxs)(b,{flex:`1`,minW:`100px`,children:[(0,G.jsx)(j,{fontSize:`xs`,color:`fg.subtle`,mb:1,children:`Duration (ms)`}),(0,G.jsx)(N,{size:`sm`,type:`number`,value:s.durationMs,onChange:e=>n(s.id,{durationMs:parseInt(e.target.value)||0}),min:0})]}),(0,G.jsxs)(b,{flex:`1`,minW:`100px`,children:[(0,G.jsx)(j,{fontSize:`xs`,color:`fg.subtle`,mb:1,children:`Offset (ms)`}),(0,G.jsx)(N,{size:`sm`,type:`number`,value:s.offsetMs,onChange:e=>n(s.id,{offsetMs:parseInt(e.target.value)||0}),min:0})]}),(0,G.jsxs)(b,{flex:`1`,minW:`100px`,children:[(0,G.jsx)(j,{fontSize:`xs`,color:`fg.subtle`,mb:1,children:`Status`}),(0,G.jsxs)(i,{size:`sm`,collection:Oe,value:[s.status],onValueChange:e=>n(s.id,{status:e.value[0]}),children:[(0,G.jsx)(m,{children:(0,G.jsx)(l,{})}),(0,G.jsx)(E,{children:(0,G.jsx)(h,{children:(0,G.jsxs)(a,{children:[(0,G.jsx)(u,{item:`ok`,children:`OK`}),(0,G.jsx)(u,{item:`error`,children:`Error`}),(0,G.jsx)(u,{item:`unset`,children:`Unset`})]})})})]})]})]}),s.status===`error`&&(0,G.jsxs)(b,{rounded:`lg`,border:`1px solid`,borderColor:`red.500/30`,bg:`red.500/5`,p:3,children:[(0,G.jsx)(j,{fontSize:`xs`,fontWeight:`medium`,color:`red.400`,mb:1,children:`Exception`}),(0,G.jsx)(N,{size:`sm`,value:s.exception?.message??``,onChange:e=>n(s.id,{exception:{...s.exception,message:e.target.value}}),placeholder:`Error message`,mb:2}),(0,G.jsx)(p,{size:`sm`,value:s.exception?.stackTrace??``,onChange:e=>n(s.id,{exception:{message:s.exception?.message??``,stackTrace:e.target.value||void 0}}),placeholder:`Stack trace`,rows:3,fontFamily:`mono`,fontSize:`xs`})]}),(0,G.jsxs)(k,{gap:3,children:[(0,G.jsxs)(b,{flex:1,children:[(0,G.jsx)(j,{fontSize:`xs`,color:`fg.subtle`,mb:1,children:`Input`}),(0,G.jsx)(p,{size:`sm`,fontSize:`xs`,rows:3,placeholder:`Span input...`,value:s.input?.type===`text`?s.input.value:s.input?JSON.stringify(s.input.value,null,2):``,onChange:e=>n(s.id,{input:e.target.value?{type:`text`,value:e.target.value}:void 0})})]}),(0,G.jsxs)(b,{flex:1,children:[(0,G.jsx)(j,{fontSize:`xs`,color:`fg.subtle`,mb:1,children:`Output`}),(0,G.jsx)(p,{size:`sm`,fontSize:`xs`,rows:3,placeholder:`Span output...`,value:s.output?.type===`text`?s.output.value:s.output?JSON.stringify(s.output.value,null,2):``,onChange:e=>n(s.id,{output:e.target.value?{type:`text`,value:e.target.value}:void 0})})]})]}),s.type===`llm`&&(0,G.jsx)(Ce,{span:s}),s.type===`rag`&&(0,G.jsx)(we,{span:s}),s.type===`prompt`&&(0,G.jsx)(Te,{span:s}),(0,G.jsxs)(b,{children:[(0,G.jsx)(j,{fontSize:`xs`,fontWeight:`medium`,textTransform:`uppercase`,letterSpacing:`wider`,color:`fg.muted`,mb:1,children:`Custom Attributes`}),(0,G.jsx)(Ee,{attributes:s.attributes,onChange:e=>n(s.id,{attributes:e})})]})]}):null}function Ae({compact:e=!1}){let{project:t}=L(),n=ce.organization.getAll.useQuery({isDemo:!1},{staleTime:6e4}),[r,i]=(0,W.useState)(!1),{selectedProjectId:a,setSelectedProject:o}=H(),s=(0,W.useMemo)(()=>n.data?n.data.flatMap(e=>e.teams.flatMap(t=>t.projects.map(n=>({id:n.id,name:n.name,slug:n.slug,apiKey:n.apiKey,orgName:e.name,teamName:t.name})))):[],[n.data]),c=a?s.find(e=>e.id===a):s.find(e=>e.id===t?.id)??s[0];return(0,G.jsxs)(b,{p:3,children:[(0,G.jsx)(j,{fontSize:`xs`,fontWeight:`medium`,textTransform:`uppercase`,letterSpacing:`wider`,color:`fg.muted`,mb:2,children:`Target Project`}),(0,G.jsxs)(b,{position:`relative`,children:[(0,G.jsxs)(k,{as:`button`,w:`full`,align:`center`,gap:2,rounded:`md`,border:`1px solid`,borderColor:`border`,px:2,py:1.5,cursor:`pointer`,_hover:{bg:`bg.subtle`},onClick:()=>i(!r),children:[(0,G.jsx)(b,{w:2,h:2,rounded:`full`,bg:c?`green.400`:`gray.500`,flexShrink:0}),(0,G.jsxs)(I,{align:`start`,gap:0,flex:1,minW:0,children:[(0,G.jsx)(j,{fontSize:`xs`,color:`fg.default`,truncate:!0,w:`full`,textAlign:`left`,children:c?.name??`Select a project`}),c&&!e&&(0,G.jsx)(j,{fontSize:`10px`,color:`fg.muted`,truncate:!0,w:`full`,textAlign:`left`,children:c.orgName})]}),(0,G.jsx)(f,{size:12,color:`var(--chakra-colors-fg-muted)`})]}),r&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(b,{position:`fixed`,inset:0,zIndex:40,onClick:()=>i(!1)}),(0,G.jsx)(b,{position:`absolute`,left:0,right:0,zIndex:50,mt:1,maxH:`300px`,overflow:`auto`,rounded:`lg`,border:`1px solid`,borderColor:`border`,bg:`bg.panel`,shadow:`lg`,children:s.length===0?(0,G.jsx)(b,{px:3,py:2,children:(0,G.jsx)(j,{fontSize:`xs`,color:`fg.muted`,children:`No projects found`})}):(0,G.jsx)(je,{projects:s,selectedId:c?.id,onSelect:e=>{o(e.id,e.apiKey),i(!1)}})})]})]})]})}function je({projects:e,selectedId:t,onSelect:n}){return(0,G.jsx)(I,{align:`stretch`,gap:0,py:1,children:[...(0,W.useMemo)(()=>{let t=new Map;for(let n of e){let e=t.get(n.orgName)??[];e.push(n),t.set(n.orgName,e)}return t},[e]).entries()].map(([e,r])=>(0,G.jsxs)(b,{children:[(0,G.jsx)(j,{fontSize:`10px`,fontWeight:`medium`,color:`fg.muted`,textTransform:`uppercase`,letterSpacing:`wider`,px:3,py:1,children:e}),r.map(e=>(0,G.jsxs)(k,{as:`button`,w:`full`,align:`center`,gap:2,px:3,py:1.5,_hover:{bg:`bg.subtle`},onClick:()=>n(e),children:[t===e.id?(0,G.jsx)(M,{size:12,color:`var(--chakra-colors-green-400)`}):(0,G.jsx)(b,{w:3}),(0,G.jsx)(j,{fontSize:`xs`,color:`fg.default`,flex:1,textAlign:`left`,truncate:!0,children:e.name}),(0,G.jsx)(j,{fontSize:`10px`,color:`fg.muted`,fontFamily:`mono`,children:e.slug})]},e.id))]},e))})}function Me({compact:e=!1}){let{batchCount:t,staggerMs:n,running:r,setBatchCount:i,setStaggerMs:a,setRunning:o,addLogEntry:c,updateLogEntry:l}=B(),u=R(e=>e.trace),{project:d}=L(),f=H(e=>e.selectedApiKey)??d?.apiKey;async function p(){if(!(r||!f)){o(!0);for(let e=0;e<t;e++){let r=`log-${Date.now()}-${e}`;c({id:r,traceId:r,timestamp:Date.now(),status:`pending`});try{l(r,{status:`success`,traceId:await de({trace:u,apiKey:f,endpoint:window.location.origin})})}catch(e){l(r,{status:`error`,error:e instanceof Error?e.message:`Send failed`})}n>0&&e<t-1&&await new Promise(e=>setTimeout(e,n))}o(!1)}}return(0,G.jsxs)(b,{p:3,children:[(0,G.jsx)(j,{fontSize:`xs`,fontWeight:`medium`,textTransform:`uppercase`,letterSpacing:`wider`,color:`fg.muted`,mb:2,children:`Execution`}),(0,G.jsxs)(k,{gap:2,mb:2,children:[(0,G.jsxs)(b,{flex:1,children:[(0,G.jsx)(j,{fontSize:`xs`,color:`fg.subtle`,mb:1,children:`Run N times`}),(0,G.jsx)(N,{size:`sm`,type:`number`,value:t,onChange:e=>i(parseInt(e.target.value)||1),min:1,max:100})]}),!e&&(0,G.jsxs)(b,{flex:1,children:[(0,G.jsx)(j,{fontSize:`xs`,color:`fg.subtle`,mb:1,children:`Stagger (ms)`}),(0,G.jsx)(N,{size:`sm`,type:`number`,value:n,onChange:e=>a(parseInt(e.target.value)||0),min:0,step:100})]})]}),(0,G.jsxs)(y,{w:`full`,size:`sm`,colorPalette:`orange`,onClick:p,disabled:r||!f,loading:r,loadingText:`Sending...`,children:[(0,G.jsx)(s,{size:14}),` Send Traces`]}),!f&&(0,G.jsx)(j,{fontSize:`xs`,color:`fg.muted`,mt:1,children:`Navigate to a project first`}),(0,G.jsx)(Ne,{})]})}function Ne(){let e=B(e=>e.log),t=B(e=>e.clearLog);return e.length===0?null:(0,G.jsxs)(b,{mt:2,children:[(0,G.jsxs)(k,{justify:`space-between`,align:`center`,mb:1,children:[(0,G.jsx)(j,{fontSize:`xs`,color:`fg.muted`,children:`Log`}),(0,G.jsx)(j,{as:`button`,fontSize:`xs`,color:`fg.muted`,_hover:{color:`fg.default`},onClick:t,children:`Clear`})]}),(0,G.jsx)(I,{maxH:`120px`,overflow:`auto`,gap:.5,align:`stretch`,children:e.map(e=>(0,G.jsx)(Pe,{entry:e},e.id))})]})}function Pe({entry:e}){let[t,n]=(0,W.useState)(!1),r=e.status===`success`;return(0,G.jsxs)(k,{align:`center`,gap:2,px:2,py:1,fontSize:`xs`,rounded:`sm`,cursor:r?`pointer`:`default`,bg:t?`green.500/10`:`transparent`,_hover:r?{bg:t?`green.500/10`:`bg.subtle`}:void 0,transition:`background 0.15s`,onClick:()=>{r&&(navigator.clipboard.writeText(e.traceId),n(!0),setTimeout(()=>n(!1),2e3))},children:[(0,G.jsx)(j,{flexShrink:0,children:e.status===`pending`?`⏳`:e.status===`success`?`✅`:`❌`}),(0,G.jsx)(j,{flex:1,truncate:!0,fontFamily:`mono`,color:`fg.muted`,children:e.traceId}),r&&(0,G.jsx)(j,{fontSize:`10px`,color:t?`green.400`:`fg.muted`,flexShrink:0,children:t?`Copied!`:`Copy ID`}),e.error&&(0,G.jsx)(j,{color:`red.400`,title:e.error,flexShrink:0,children:`Failed`})]})}function Fe({compact:e=!1}){let t=R(e=>e.trace),n=R(e=>e.updateTrace);return(0,G.jsxs)(b,{p:3,children:[(0,G.jsx)(j,{fontSize:`xs`,fontWeight:`medium`,textTransform:`uppercase`,letterSpacing:`wider`,color:`fg.muted`,mb:2,children:`Trace Settings`}),(0,G.jsxs)(I,{gap:2,align:`stretch`,children:[(0,G.jsxs)(b,{children:[(0,G.jsx)(j,{fontSize:`xs`,color:`fg.subtle`,mb:1,children:`service.name`}),(0,G.jsx)(N,{size:`sm`,value:t.resourceAttributes[`service.name`]??``,onChange:e=>n({resourceAttributes:{...t.resourceAttributes,"service.name":e.target.value}})})]}),(0,G.jsxs)(b,{children:[(0,G.jsx)(j,{fontSize:`xs`,color:`fg.subtle`,mb:1,children:`user_id`}),(0,G.jsx)(N,{size:`sm`,value:t.metadata.userId??``,onChange:e=>n({metadata:{...t.metadata,userId:e.target.value||void 0}}),placeholder:`optional`})]}),!e&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(b,{children:[(0,G.jsx)(j,{fontSize:`xs`,color:`fg.subtle`,mb:1,children:`thread_id`}),(0,G.jsx)(N,{size:`sm`,value:t.metadata.threadId??``,onChange:e=>n({metadata:{...t.metadata,threadId:e.target.value||void 0}}),placeholder:`optional`})]}),(0,G.jsxs)(b,{children:[(0,G.jsx)(j,{fontSize:`xs`,color:`fg.subtle`,mb:1,children:`labels`}),(0,G.jsx)(N,{size:`sm`,value:t.metadata.labels?.join(`, `)??``,onChange:e=>n({metadata:{...t.metadata,labels:e.target.value?e.target.value.split(`,`).map(e=>e.trim()):void 0}}),placeholder:`e.g. production, v2`})]})]})]})]})}function J(e,t,n){let r=[];for(let i of e){let e=n+i.offsetMs;r.push({span:i,depth:t,absoluteStartMs:e,absoluteEndMs:e+i.durationMs}),r.push(...J(i.children,t+1,e))}return r}var Ie={llm:`blue.500`,agent:`purple.500`,tool:`green.500`,rag:`teal.500`,chain:`orange.500`,prompt:`yellow.500`,guardrail:`red.500`,workflow:`blue.600`,span:`gray.500`};function Le(){let e=R(e=>e.trace.spans),t=R(e=>e.selectedSpanId),n=R(e=>e.selectSpan),r=J(e,0,0);if(r.length===0)return(0,G.jsx)(k,{h:`200px`,align:`center`,justify:`center`,color:`fg.muted`,children:(0,G.jsx)(j,{children:`No spans`})});let i=Math.min(...r.map(e=>e.absoluteStartMs)),a=Math.max(...r.map(e=>e.absoluteEndMs))-i||1;return(0,G.jsxs)(b,{p:4,children:[(0,G.jsx)(k,{pl:`180px`,mb:2,children:(0,G.jsx)(b,{position:`relative`,flex:1,h:`16px`,children:Array.from({length:6},(e,t)=>Math.round(i+a*t/5)).map((e,t)=>(0,G.jsxs)(j,{position:`absolute`,fontSize:`10px`,color:`fg.muted`,transform:`translateX(-50%)`,left:`${(e-i)/a*100}%`,children:[e,`ms`]},t))})}),(0,G.jsx)(k,{direction:`column`,gap:.5,children:r.map(e=>{let r=(e.absoluteStartMs-i)/a*100,o=Math.max(e.span.durationMs/a*100,.5),s=t===e.span.id,c=e.span.status===`error`?`red.500`:Ie[e.span.type]??`gray.500`;return(0,G.jsxs)(k,{align:`center`,cursor:`pointer`,rounded:`sm`,bg:s?`orange.500/10`:`transparent`,_hover:{bg:s?`orange.500/10`:`bg.subtle`},onClick:()=>n(e.span.id),children:[(0,G.jsxs)(k,{w:`180px`,flexShrink:0,align:`center`,gap:1,pr:2,pl:`${e.depth*16+8}px`,truncate:!0,children:[(0,G.jsx)(j,{fontSize:`xs`,flexShrink:0,children:V[e.span.type]}),(0,G.jsx)(j,{fontSize:`xs`,color:`fg.default`,truncate:!0,children:e.span.name})]}),(0,G.jsx)(b,{flex:1,position:`relative`,h:`20px`,children:(0,G.jsx)(b,{position:`absolute`,top:`3px`,h:`14px`,rounded:`sm`,bg:c,left:`${r}%`,w:`${o}%`,minW:`4px`,opacity:s?1:.8,ring:s?`1px`:void 0,ringColor:s?`orange.400`:void 0})}),(0,G.jsxs)(j,{w:`50px`,flexShrink:0,textAlign:`right`,fontSize:`10px`,color:`fg.muted`,pr:2,children:[e.span.durationMs,`ms`]})]},e.span.id)})})]})}function Re({data:e}){let t=z[e.type]??`gray.400`;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(A,{type:`target`,position:O.Top,style:{background:`var(--chakra-colors-border)`,width:8,height:8,border:`1px solid var(--chakra-colors-border)`}}),(0,G.jsxs)(b,{borderRadius:`lg`,borderWidth:`1px`,borderColor:e.isSelected?`orange.400`:e.status===`error`?`red.600`:`border`,bg:e.isSelected?`orange.subtle`:e.status===`error`?`red.subtle`:`bg.panel`,paddingX:3,paddingY:2,minWidth:`140px`,boxShadow:`sm`,children:[(0,G.jsxs)(P,{gap:1.5,children:[(0,G.jsx)(j,{textStyle:`sm`,children:V[e.type]??`·`}),(0,G.jsx)(j,{textStyle:`xs`,fontWeight:`medium`,truncate:!0,maxWidth:`120px`,children:e.label})]}),(0,G.jsxs)(P,{gap:2,marginTop:1,children:[(0,G.jsx)(j,{textStyle:`xs`,color:t,textTransform:`uppercase`,children:e.type}),(0,G.jsxs)(j,{textStyle:`xs`,color:`fg.muted`,children:[e.durationMs,`ms`]})]})]}),(0,G.jsx)(A,{type:`source`,position:O.Bottom,style:{background:`var(--chakra-colors-border)`,width:8,height:8,border:`1px solid var(--chakra-colors-border)`}})]})}var ze={spanNode:Re};function Y(e,t,n=null,r=0,i=0){let a=[],o=[],s=r;for(let r of e){let e=Y(r.children,t,r.id,s,i+100),c=Math.max(e.width,180),l=s+c/2-180/2;a.push({id:r.id,type:`spanNode`,position:{x:l,y:i},data:{label:r.name,type:r.type,durationMs:r.durationMs,status:r.status,spanId:r.id,isSelected:t===r.id}}),n&&o.push({id:`${n}-${r.id}`,source:n,target:r.id,style:{stroke:`var(--chakra-colors-border)`}}),a.push(...e.nodes),o.push(...e.edges),s+=c}return{nodes:a,edges:o,width:Math.max(s-r,0)}}function Be(){let e=R(e=>e.trace.spans),t=R(e=>e.selectedSpanId),n=R(e=>e.selectSpan),r=x(),{nodes:i,edges:a}=(0,W.useMemo)(()=>Y(e,t),[e,t]),o=(0,W.useCallback)((e,t)=>{n(t.data.spanId)},[n]);return(0,G.jsx)(b,{height:`full`,width:`full`,className:r.colorMode===`dark`?`dark`:``,css:{"& .react-flow__controls":{background:`var(--chakra-colors-bg-panel)`,border:`1px solid var(--chakra-colors-border)`,borderRadius:`8px`,boxShadow:`none`},"& .react-flow__controls-button":{background:`var(--chakra-colors-bg-panel)`,borderColor:`var(--chakra-colors-border)`,fill:`var(--chakra-colors-fg-muted)`,"&:hover":{background:`var(--chakra-colors-bg-muted)`}},"& .react-flow__edge-path":{stroke:`var(--chakra-colors-border)`},"& .react-flow__background pattern line":{stroke:`var(--chakra-colors-border)`}},children:(0,G.jsxs)(ae,{nodes:i,edges:a,nodeTypes:ze,onNodeClick:o,fitView:!0,fitViewOptions:{padding:.3},proOptions:{hideAttribution:!0},colorMode:r.colorMode===`dark`?`dark`:`light`,style:{background:`var(--chakra-colors-bg-subtle)`},children:[(0,G.jsx)(re,{color:`var(--chakra-colors-border)`,gap:20}),(0,G.jsx)(ie,{})]})})}var X={$schema:`http://json-schema.org/draft-07/schema#`,type:`object`,required:[`id`,`name`,`resourceAttributes`,`metadata`,`spans`],properties:{id:{type:`string`,description:`Unique trace identifier`},name:{type:`string`,description:`Human-readable trace name`},description:{type:`string`,description:`Optional trace description`},resourceAttributes:{type:`object`,additionalProperties:{type:`string`},description:`OTel resource attributes (e.g. service.name)`},metadata:{type:`object`,properties:{userId:{type:`string`,description:`User ID for the trace`},threadId:{type:`string`,description:`Conversation thread ID`},customerId:{type:`string`,description:`Customer/tenant ID`},labels:{type:`array`,items:{type:`string`},description:`Trace labels`}},additionalProperties:!1},spans:{type:`array`,items:{$ref:`#/definitions/SpanConfig`},description:`Root-level spans in the trace`}},additionalProperties:!1,definitions:{SpanConfig:{type:`object`,required:[`id`,`name`,`type`,`durationMs`,`offsetMs`,`status`,`children`,`attributes`],properties:{id:{type:`string`},name:{type:`string`,description:`Span display name`},type:{type:`string`,enum:[...U],description:`Span type (llm, agent, tool, rag, etc.)`},durationMs:{type:`number`,minimum:0,description:`Span duration in ms`},offsetMs:{type:`number`,minimum:0,description:`Offset from parent start in ms`},status:{type:`string`,enum:[`ok`,`error`,`unset`]},children:{type:`array`,items:{$ref:`#/definitions/SpanConfig`},description:`Child spans`},input:{$ref:`#/definitions/SpanInputOutput`},output:{$ref:`#/definitions/SpanInputOutput`},attributes:{type:`object`,additionalProperties:{oneOf:[{type:`string`},{type:`number`},{type:`boolean`}]},description:`Custom span attributes`},exception:{type:`object`,properties:{message:{type:`string`},stackTrace:{type:`string`}},required:[`message`]},llm:{$ref:`#/definitions/LLMConfig`},rag:{$ref:`#/definitions/RAGConfig`},prompt:{$ref:`#/definitions/PromptConfig`}},additionalProperties:!1},SpanInputOutput:{type:`object`,required:[`type`,`value`],properties:{type:{type:`string`,enum:[...le]},value:{description:`The input/output value`}}},LLMConfig:{type:`object`,properties:{requestModel:{type:`string`,description:`Model requested (e.g. gpt-4o)`},responseModel:{type:`string`,description:`Model that responded`},messages:{type:`array`,items:{type:`object`,required:[`role`,`content`],properties:{role:{type:`string`,enum:[`system`,`user`,`assistant`,`tool`]},content:{type:`string`}}}},temperature:{type:`number`,minimum:0,maximum:2},stream:{type:`boolean`},metrics:{type:`object`,properties:{promptTokens:{type:`number`},completionTokens:{type:`number`},cost:{type:`number`}}}},additionalProperties:!1},RAGConfig:{type:`object`,required:[`contexts`],properties:{contexts:{type:`array`,items:{type:`object`,required:[`document_id`,`chunk_id`,`content`],properties:{document_id:{type:`string`},chunk_id:{type:`string`},content:{type:`string`}}}}},additionalProperties:!1},PromptConfig:{type:`object`,properties:{promptId:{type:`string`},versionId:{type:`string`},variables:{type:`object`,additionalProperties:{type:`string`}}},additionalProperties:!1}}},Ve=he(()=>n(()=>import(`./dist-B1d0YXwd.js`),__vite__mapDeps([0,1,2])),{ssr:!1,loading:()=>(0,G.jsx)(b,{padding:4,color:`fg.muted`,children:`Loading editor...`})});function Z(e){return e.reduce((e,t)=>e+1+Z(t.children),0)}function He(){let e=R(e=>e.trace),t=R(e=>e.setTrace),n=R(e=>e.resetTrace),{colorMode:i}=x(),[a,o]=(0,W.useState)(!1),[s,l]=(0,W.useState)(null),u=(0,W.useRef)(null),d=(0,W.useMemo)(()=>JSON.stringify(e,null,2),[e]),f=(0,W.useMemo)(()=>Z(e.spans),[e.spans]),p=d.split(`
2
+ import{s as e}from"./chunk-Bj-mKKzh.js";import{t}from"./react-C7JcuhbW.js";import{t as n}from"./preload-helper-rov5CBGT.js";import{$a as r,As as i,Ds as a,Fa as o,La as s,Ma as c,Ms as l,Os as u,Xr as d,ao as f,gs as p,js as m,ks as h,mn as g,sc as _,wa as v}from"./command-bar-DUK45yin.js";import{j as ee,n as y}from"./stack-oJ9iWdbl.js";import{t as b}from"./box-BsM8YLGl.js";import{c as x}from"./LoadingScreen--vgXk5-2.js";import{r as S}from"./dialog.anatomy-hrluUh9u.js";import{i as te,o as C,r as ne,s as w,t as T}from"./tabs-DwV1cIZB.js";import{i as E}from"./toaster-C_DYALhL.js";import{an as D,at as re,ct as ie,gt as O,in as k,lt as A,pt as ae}from"./dist-Cds4Mqhj.js";import{t as j}from"./text-CwTrMF8x.js";import{i as oe,n as M,r as se}from"./code-FF_ibTVI.js";import{t as N}from"./input-C7emsUCL.js";import{t as P}from"./h-stack-BKLDJ2vg.js";import{Pt as F}from"./lu-Bf6j_N19.js";import{t as I}from"./v-stack-EOPQ57OZ.js";import{s as ce}from"./auth-client-D3UhxhQi.js";import{t as L}from"./useOrganizationTeamProject-DC0iozx2.js";import{a as R,c as z,i as B,l as V,n as H,o as le,r as ue,s as U,t as de}from"./traceExecutor-CDUGyUaw.js";import{t as fe}from"./createLucideIcon-BJKFyRLS.js";import{t as pe}from"./arrow-right-B3ZN8yal.js";import{t as me}from"./chevron-up-BvG6wkCS.js";import{t as he}from"./next-dynamic-CldmZdeI.js";/* empty css */import{t as ge}from"./OpsPageShell-C_mTziRS.js";var _e=fe(`text-wrap`,[[`path`,{d:`m16 16-3 3 3 3`,key:`117b85`}],[`path`,{d:`M3 12h14.5a1 1 0 0 1 0 7H13`,key:`18xa6z`}],[`path`,{d:`M3 19h6`,key:`1ygdsz`}],[`path`,{d:`M3 5h18`,key:`1u36vt`}]]),W=e(t()),G=ee();function K({span:e,depth:t}){let n=R(e=>e.selectedSpanId),i=R(e=>e.selectSpan),a=R(e=>e.removeSpan),o=R(e=>e.duplicateSpan),s=R(e=>e.moveSpan),c=n===e.id;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(k,{align:`center`,gap:1.5,px:2,py:1,pl:`${t*16+8}px`,rounded:`md`,cursor:`pointer`,fontSize:`xs`,bg:c?`orange.500/10`:`transparent`,color:c?`orange.400`:`fg.default`,_hover:{bg:c?`orange.500/10`:`bg.subtle`},onClick:()=>i(e.id),role:`group`,children:[(0,G.jsx)(j,{as:`span`,flexShrink:0,fontSize:`sm`,children:V[e.type]}),(0,G.jsx)(j,{flex:1,truncate:!0,fontWeight:`medium`,children:e.name}),(0,G.jsx)(j,{flexShrink:0,fontSize:`10px`,textTransform:`uppercase`,color:z[e.type],children:e.type}),e.status===`error`&&(0,G.jsx)(j,{color:`red.400`,fontWeight:`bold`,children:`!`}),(0,G.jsxs)(k,{gap:0,display:`none`,_groupHover:{display:`flex`},children:[(0,G.jsx)(F,{"aria-label":`Up`,size:`2xs`,variant:`ghost`,color:`fg.muted`,onClick:t=>{t.stopPropagation(),s(e.id,`up`)},children:(0,G.jsx)(me,{size:12})}),(0,G.jsx)(F,{"aria-label":`Down`,size:`2xs`,variant:`ghost`,color:`fg.muted`,onClick:t=>{t.stopPropagation(),s(e.id,`down`)},children:(0,G.jsx)(f,{size:12})}),(0,G.jsx)(F,{"aria-label":`Copy`,size:`2xs`,variant:`ghost`,color:`fg.muted`,onClick:t=>{t.stopPropagation(),o(e.id)},children:(0,G.jsx)(r,{size:12})}),(0,G.jsx)(F,{"aria-label":`Delete`,size:`2xs`,variant:`ghost`,color:`fg.muted`,_hover:{color:`red.400`},onClick:t=>{t.stopPropagation(),a(e.id)},children:(0,G.jsx)(v,{size:12})})]})]}),e.children.map(e=>(0,G.jsx)(K,{span:e,depth:t+1},e.id))]})}var ve=[`llm`,`agent`,`tool`,`rag`,`chain`,`prompt`,`guardrail`,`span`];function ye({parentId:e}){let[t,n]=(0,W.useState)(!1),r=R(e=>e.addSpan);return(0,G.jsxs)(b,{position:`relative`,mt:1,children:[(0,G.jsxs)(k,{as:`button`,w:`full`,align:`center`,justify:`center`,gap:1,rounded:`md`,border:`1px dashed`,borderColor:`border`,px:2,py:1.5,fontSize:`xs`,color:`fg.muted`,_hover:{borderColor:`border.emphasized`,color:`fg.default`},onClick:()=>n(!t),children:[(0,G.jsx)(o,{size:12}),` Add Span`]}),t&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(b,{position:`fixed`,inset:0,zIndex:10,onClick:()=>n(!1)}),(0,G.jsx)(b,{position:`absolute`,left:0,zIndex:20,mt:1,w:`full`,rounded:`lg`,border:`1px solid`,borderColor:`border`,bg:`bg.panel`,p:1,shadow:`xl`,children:ve.map(t=>(0,G.jsxs)(k,{as:`button`,w:`full`,align:`center`,gap:2,rounded:`md`,px:2,py:1.5,fontSize:`xs`,color:`fg.default`,_hover:{bg:`bg.subtle`},onClick:()=>{r(e,t),n(!1)},children:[(0,G.jsx)(j,{as:`span`,children:V[t]}),(0,G.jsx)(j,{textTransform:`capitalize`,children:t})]},t))})]})]})}function be(){let e=R(e=>e.trace.spans);return(0,G.jsxs)(b,{p:3,children:[(0,G.jsx)(j,{fontSize:`xs`,fontWeight:`medium`,textTransform:`uppercase`,letterSpacing:`wider`,color:`fg.muted`,mb:2,children:`Spans`}),(0,G.jsx)(k,{direction:`column`,gap:.5,children:e.map(e=>(0,G.jsx)(K,{span:e,depth:0},e.id))}),(0,G.jsx)(ye,{parentId:null})]})}var xe=[{label:`GPT-4o`,value:`gpt-4o`},{label:`GPT-4o Mini`,value:`gpt-4o-mini`},{label:`GPT-4.1`,value:`gpt-4.1`},{label:`GPT-4.1 Mini`,value:`gpt-4.1-mini`},{label:`GPT-5 Mini`,value:`gpt-5-mini`},{label:`o3`,value:`o3`},{label:`o4-mini`,value:`o4-mini`},{label:`Claude Opus 4`,value:`claude-opus-4-20250514`},{label:`Claude Sonnet 4`,value:`claude-sonnet-4-20250514`},{label:`Claude Haiku 3.5`,value:`claude-3-5-haiku-20241022`},{label:`Gemini 2.5 Pro`,value:`gemini-2.5-pro`},{label:`Gemini 2.5 Flash`,value:`gemini-2.5-flash`},{label:`Grok 3`,value:`grok-3`},{label:`Grok 3 Mini`,value:`grok-3-mini`},{label:`Llama 4 Scout`,value:`meta-llama/llama-4-scout`},{label:`DeepSeek V3`,value:`deepseek-chat`},{label:`DeepSeek R1`,value:`deepseek-reasoner`},{label:`Mistral Large`,value:`mistral-large-latest`}],Se={system:`purple.500`,user:`green.400`,assistant:`blue.400`,tool:`yellow.400`};function Ce({span:e}){let t=R(e=>e.updateSpan),n=e.llm??{};function r(r){t(e.id,{llm:{...n,...r}})}let i=n.messages??[];function a(e,t){r({messages:i.map((n,r)=>r===e?{...n,...t}:n)})}return(0,G.jsxs)(b,{rounded:`lg`,border:`1px solid`,borderColor:`blue.500/20`,bg:`blue.500/5`,p:4,children:[(0,G.jsx)(j,{fontSize:`sm`,fontWeight:`semibold`,color:`blue.400`,mb:3,children:`LLM Configuration`}),(0,G.jsxs)(k,{gap:3,wrap:`wrap`,mb:3,children:[(0,G.jsxs)(b,{flex:1,minW:`140px`,children:[(0,G.jsx)(j,{fontSize:`xs`,color:`fg.subtle`,mb:1,children:`Model`}),(0,G.jsx)(N,{size:`sm`,value:n.requestModel??``,onChange:e=>r({requestModel:e.target.value}),placeholder:`gpt-4o`,list:`llm-models`}),(0,G.jsx)(`datalist`,{id:`llm-models`,children:xe.map(e=>(0,G.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),(0,G.jsxs)(b,{w:`80px`,children:[(0,G.jsx)(j,{fontSize:`xs`,color:`fg.subtle`,mb:1,children:`Temp`}),(0,G.jsx)(N,{size:`sm`,type:`number`,value:n.temperature??.7,onChange:e=>r({temperature:parseFloat(e.target.value)}),step:.1,min:0,max:2})]})]}),(0,G.jsx)(j,{fontSize:`xs`,fontWeight:`medium`,color:`fg.subtle`,mb:1,children:`Messages`}),(0,G.jsxs)(k,{direction:`column`,gap:2,mb:2,children:[i.map((e,t)=>(0,G.jsxs)(k,{gap:2,rounded:`md`,border:`1px solid`,borderColor:`border`,borderLeftWidth:`2px`,borderLeftColor:Se[e.role]??`gray.500`,bg:`bg.subtle`,p:2,children:[(0,G.jsxs)(`select`,{value:e.role,onChange:e=>a(t,{role:e.target.value}),style:{width:`90px`,flexShrink:0,background:`var(--chakra-colors-bg-subtle)`,color:`var(--chakra-colors-fg-default)`,border:`1px solid var(--chakra-colors-border)`,borderRadius:`4px`,padding:`2px 6px`,fontSize:`12px`},children:[(0,G.jsx)(`option`,{value:`system`,children:`system`}),(0,G.jsx)(`option`,{value:`user`,children:`user`}),(0,G.jsx)(`option`,{value:`assistant`,children:`assistant`}),(0,G.jsx)(`option`,{value:`tool`,children:`tool`})]}),(0,G.jsx)(p,{flex:1,size:`sm`,fontSize:`xs`,value:e.content,onChange:e=>a(t,{content:e.target.value}),rows:2,resize:`vertical`,placeholder:`Message content...`}),(0,G.jsx)(y,{size:`xs`,variant:`ghost`,color:`fg.muted`,_hover:{color:`red.400`},onClick:()=>r({messages:i.filter((e,n)=>n!==t)}),alignSelf:`flex-start`,children:(0,G.jsx)(v,{size:12})})]},t)),(0,G.jsxs)(y,{size:`xs`,variant:`outline`,onClick:()=>r({messages:[...i,{role:`user`,content:``}]}),children:[(0,G.jsx)(o,{size:12}),` Add Message`]})]}),(0,G.jsx)(j,{fontSize:`xs`,fontWeight:`medium`,color:`fg.subtle`,mb:1,children:`Metrics`}),(0,G.jsxs)(k,{gap:3,children:[(0,G.jsxs)(b,{flex:1,children:[(0,G.jsx)(j,{fontSize:`xs`,color:`fg.muted`,mb:1,children:`Prompt Tokens`}),(0,G.jsx)(N,{size:`sm`,type:`number`,value:n.metrics?.promptTokens??``,onChange:e=>r({metrics:{...n.metrics,promptTokens:parseInt(e.target.value)||void 0}}),placeholder:`0`})]}),(0,G.jsxs)(b,{flex:1,children:[(0,G.jsx)(j,{fontSize:`xs`,color:`fg.muted`,mb:1,children:`Completion Tokens`}),(0,G.jsx)(N,{size:`sm`,type:`number`,value:n.metrics?.completionTokens??``,onChange:e=>r({metrics:{...n.metrics,completionTokens:parseInt(e.target.value)||void 0}}),placeholder:`0`})]}),(0,G.jsxs)(b,{flex:1,children:[(0,G.jsx)(j,{fontSize:`xs`,color:`fg.muted`,mb:1,children:`Cost ($)`}),(0,G.jsx)(N,{size:`sm`,type:`number`,value:n.metrics?.cost??``,onChange:e=>r({metrics:{...n.metrics,cost:parseFloat(e.target.value)||void 0}}),step:1e-4,placeholder:`0.00`})]})]})]})}function we({span:e}){let t=R(e=>e.updateSpan),n=e.rag?.contexts??[];function r(r,i){let a=n.map((e,t)=>t===r?{...e,...i}:e);t(e.id,{rag:{contexts:a}})}return(0,G.jsxs)(b,{rounded:`lg`,border:`1px solid`,borderColor:`teal.500/20`,bg:`teal.500/5`,p:4,children:[(0,G.jsx)(j,{fontSize:`sm`,fontWeight:`semibold`,color:`teal.400`,mb:3,children:`RAG Contexts`}),(0,G.jsxs)(k,{direction:`column`,gap:3,children:[n.map((i,a)=>(0,G.jsxs)(b,{rounded:`md`,border:`1px solid`,borderColor:`border`,bg:`bg.subtle`,p:3,children:[(0,G.jsxs)(k,{justify:`space-between`,mb:2,children:[(0,G.jsxs)(j,{fontSize:`xs`,fontWeight:`medium`,color:`fg.subtle`,children:[`Context `,a+1]}),(0,G.jsx)(y,{size:`xs`,variant:`ghost`,color:`fg.muted`,_hover:{color:`red.400`},onClick:()=>t(e.id,{rag:{contexts:n.filter((e,t)=>t!==a)}}),children:(0,G.jsx)(v,{size:12})})]}),(0,G.jsxs)(k,{gap:2,mb:2,children:[(0,G.jsx)(N,{size:`sm`,flex:1,value:i.document_id,onChange:e=>r(a,{document_id:e.target.value}),placeholder:`Document ID`}),(0,G.jsx)(N,{size:`sm`,flex:1,value:i.chunk_id,onChange:e=>r(a,{chunk_id:e.target.value}),placeholder:`Chunk ID`})]}),(0,G.jsx)(p,{size:`sm`,fontSize:`xs`,value:i.content,onChange:e=>r(a,{content:e.target.value}),placeholder:`Retrieved content...`,rows:3})]},a)),(0,G.jsxs)(y,{size:`xs`,variant:`outline`,onClick:()=>t(e.id,{rag:{contexts:[...n,{document_id:``,chunk_id:``,content:``}]}}),children:[(0,G.jsx)(o,{size:12}),` Add Context`]})]})]})}function Te({span:e}){let t=R(e=>e.updateSpan),n=e.prompt??{};function r(r){t(e.id,{prompt:{...n,...r}})}let i=n.variables??{},a=Object.entries(i);return(0,G.jsxs)(b,{rounded:`lg`,border:`1px solid`,borderColor:`yellow.500/20`,bg:`yellow.500/5`,p:4,children:[(0,G.jsx)(j,{fontSize:`sm`,fontWeight:`semibold`,color:`yellow.400`,mb:3,children:`Prompt Configuration`}),(0,G.jsxs)(k,{gap:3,mb:3,children:[(0,G.jsxs)(b,{flex:1,children:[(0,G.jsx)(j,{fontSize:`xs`,color:`fg.subtle`,mb:1,children:`Prompt ID`}),(0,G.jsx)(N,{size:`sm`,value:n.promptId??``,onChange:e=>r({promptId:e.target.value}),placeholder:`e.g. customer-support-v2`})]}),(0,G.jsxs)(b,{flex:1,children:[(0,G.jsx)(j,{fontSize:`xs`,color:`fg.subtle`,mb:1,children:`Version ID`}),(0,G.jsx)(N,{size:`sm`,value:n.versionId??``,onChange:e=>r({versionId:e.target.value}),placeholder:`e.g. ver-abc123`})]})]}),(0,G.jsx)(j,{fontSize:`xs`,fontWeight:`medium`,color:`fg.subtle`,mb:1,children:`Template Variables`}),(0,G.jsxs)(k,{direction:`column`,gap:1,children:[a.map(([e,t])=>(0,G.jsxs)(k,{align:`center`,gap:2,children:[(0,G.jsx)(N,{size:`sm`,w:`120px`,flexShrink:0,value:e,onChange:n=>{let a={...i};delete a[e],a[n.target.value]=t,r({variables:a})},placeholder:`key`}),(0,G.jsx)(N,{size:`sm`,flex:1,value:t,onChange:t=>r({variables:{...i,[e]:t.target.value}}),placeholder:`value`}),(0,G.jsx)(y,{size:`xs`,variant:`ghost`,color:`fg.muted`,_hover:{color:`red.400`},onClick:()=>{let t={...i};delete t[e],r({variables:t})},children:(0,G.jsx)(v,{size:12})})]},e)),(0,G.jsxs)(y,{size:`xs`,variant:`outline`,onClick:()=>r({variables:{...i,[`var_${a.length+1}`]:``}}),children:[(0,G.jsx)(o,{size:12}),` Add Variable`]})]})]})}function Ee({attributes:e,onChange:t}){let n=Object.entries(e),[r,i]=(0,W.useState)(``);function a(){!r||r in e||(t({...e,[r]:``}),i(``))}function s(n,r){let i=r;r===`true`?i=!0:r===`false`?i=!1:/^\d+(\.\d+)?$/.test(r)&&(i=parseFloat(r)),t({...e,[n]:i})}return(0,G.jsxs)(k,{direction:`column`,gap:1,mt:1,children:[n.map(([n,r])=>(0,G.jsxs)(k,{align:`center`,gap:2,children:[(0,G.jsx)(j,{fontSize:`xs`,color:`fg.subtle`,w:`140px`,flexShrink:0,truncate:!0,children:n}),(0,G.jsx)(N,{size:`sm`,flex:1,fontSize:`xs`,value:String(r),onChange:e=>s(n,e.target.value)}),(0,G.jsx)(y,{size:`xs`,variant:`ghost`,color:`fg.muted`,_hover:{color:`red.400`},onClick:()=>{let r={...e};delete r[n],t(r)},children:(0,G.jsx)(v,{size:12})})]},n)),(0,G.jsxs)(k,{align:`center`,gap:2,children:[(0,G.jsx)(N,{size:`sm`,w:`140px`,flexShrink:0,fontSize:`xs`,value:r,onChange:e=>i(e.target.value),onKeyDown:e=>e.key===`Enter`&&a(),placeholder:`attribute.key`}),(0,G.jsxs)(y,{size:`xs`,variant:`outline`,onClick:a,disabled:!r,children:[(0,G.jsx)(o,{size:12}),` Add`]})]})]})}function q(e,t){for(let n of e){if(n.id===t)return n;let e=q(n.children,t);if(e)return e}}var De=_({items:U.map(e=>({label:`${V[e]} ${e}`,value:e}))}),Oe=_({items:[{label:`OK`,value:`ok`},{label:`Error`,value:`error`},{label:`Unset`,value:`unset`}]});function ke(){let e=R(e=>e.selectedSpanId),t=R(e=>e.trace.spans),n=R(e=>e.updateSpan),r=R(e=>e.indentSpan),o=R(e=>e.outdentSpan);if(!e)return null;let s=q(t,e);return s?(0,G.jsxs)(I,{align:`stretch`,gap:4,p:5,minW:0,overflow:`hidden`,children:[(0,G.jsxs)(k,{align:`center`,justify:`space-between`,children:[(0,G.jsx)(j,{fontSize:`lg`,fontWeight:`semibold`,children:s.name}),(0,G.jsxs)(P,{gap:1,children:[(0,G.jsx)(y,{size:`xs`,variant:`outline`,onClick:()=>r(s.id),children:(0,G.jsx)(pe,{size:14})}),(0,G.jsx)(y,{size:`xs`,variant:`outline`,onClick:()=>o(s.id),children:(0,G.jsx)(se,{size:14})})]})]}),(0,G.jsxs)(k,{gap:3,wrap:`wrap`,children:[(0,G.jsxs)(b,{flex:`1`,minW:`140px`,children:[(0,G.jsx)(j,{fontSize:`xs`,color:`fg.subtle`,mb:1,children:`Name`}),(0,G.jsx)(N,{size:`sm`,value:s.name,onChange:e=>n(s.id,{name:e.target.value})})]}),(0,G.jsxs)(b,{flex:`1`,minW:`140px`,children:[(0,G.jsx)(j,{fontSize:`xs`,color:`fg.subtle`,mb:1,children:`Type`}),(0,G.jsxs)(i,{size:`sm`,collection:De,value:[s.type],onValueChange:e=>n(s.id,{type:e.value[0]}),children:[(0,G.jsx)(m,{children:(0,G.jsx)(l,{})}),(0,G.jsx)(E,{children:(0,G.jsx)(h,{children:(0,G.jsx)(a,{children:U.map(e=>(0,G.jsxs)(u,{item:e,children:[V[e],` `,e]},e))})})})]})]})]}),(0,G.jsxs)(k,{gap:3,wrap:`wrap`,children:[(0,G.jsxs)(b,{flex:`1`,minW:`100px`,children:[(0,G.jsx)(j,{fontSize:`xs`,color:`fg.subtle`,mb:1,children:`Duration (ms)`}),(0,G.jsx)(N,{size:`sm`,type:`number`,value:s.durationMs,onChange:e=>n(s.id,{durationMs:parseInt(e.target.value)||0}),min:0})]}),(0,G.jsxs)(b,{flex:`1`,minW:`100px`,children:[(0,G.jsx)(j,{fontSize:`xs`,color:`fg.subtle`,mb:1,children:`Offset (ms)`}),(0,G.jsx)(N,{size:`sm`,type:`number`,value:s.offsetMs,onChange:e=>n(s.id,{offsetMs:parseInt(e.target.value)||0}),min:0})]}),(0,G.jsxs)(b,{flex:`1`,minW:`100px`,children:[(0,G.jsx)(j,{fontSize:`xs`,color:`fg.subtle`,mb:1,children:`Status`}),(0,G.jsxs)(i,{size:`sm`,collection:Oe,value:[s.status],onValueChange:e=>n(s.id,{status:e.value[0]}),children:[(0,G.jsx)(m,{children:(0,G.jsx)(l,{})}),(0,G.jsx)(E,{children:(0,G.jsx)(h,{children:(0,G.jsxs)(a,{children:[(0,G.jsx)(u,{item:`ok`,children:`OK`}),(0,G.jsx)(u,{item:`error`,children:`Error`}),(0,G.jsx)(u,{item:`unset`,children:`Unset`})]})})})]})]})]}),s.status===`error`&&(0,G.jsxs)(b,{rounded:`lg`,border:`1px solid`,borderColor:`red.500/30`,bg:`red.500/5`,p:3,children:[(0,G.jsx)(j,{fontSize:`xs`,fontWeight:`medium`,color:`red.400`,mb:1,children:`Exception`}),(0,G.jsx)(N,{size:`sm`,value:s.exception?.message??``,onChange:e=>n(s.id,{exception:{...s.exception,message:e.target.value}}),placeholder:`Error message`,mb:2}),(0,G.jsx)(p,{size:`sm`,value:s.exception?.stackTrace??``,onChange:e=>n(s.id,{exception:{message:s.exception?.message??``,stackTrace:e.target.value||void 0}}),placeholder:`Stack trace`,rows:3,fontFamily:`mono`,fontSize:`xs`})]}),(0,G.jsxs)(k,{gap:3,children:[(0,G.jsxs)(b,{flex:1,children:[(0,G.jsx)(j,{fontSize:`xs`,color:`fg.subtle`,mb:1,children:`Input`}),(0,G.jsx)(p,{size:`sm`,fontSize:`xs`,rows:3,placeholder:`Span input...`,value:s.input?.type===`text`?s.input.value:s.input?JSON.stringify(s.input.value,null,2):``,onChange:e=>n(s.id,{input:e.target.value?{type:`text`,value:e.target.value}:void 0})})]}),(0,G.jsxs)(b,{flex:1,children:[(0,G.jsx)(j,{fontSize:`xs`,color:`fg.subtle`,mb:1,children:`Output`}),(0,G.jsx)(p,{size:`sm`,fontSize:`xs`,rows:3,placeholder:`Span output...`,value:s.output?.type===`text`?s.output.value:s.output?JSON.stringify(s.output.value,null,2):``,onChange:e=>n(s.id,{output:e.target.value?{type:`text`,value:e.target.value}:void 0})})]})]}),s.type===`llm`&&(0,G.jsx)(Ce,{span:s}),s.type===`rag`&&(0,G.jsx)(we,{span:s}),s.type===`prompt`&&(0,G.jsx)(Te,{span:s}),(0,G.jsxs)(b,{children:[(0,G.jsx)(j,{fontSize:`xs`,fontWeight:`medium`,textTransform:`uppercase`,letterSpacing:`wider`,color:`fg.muted`,mb:1,children:`Custom Attributes`}),(0,G.jsx)(Ee,{attributes:s.attributes,onChange:e=>n(s.id,{attributes:e})})]})]}):null}function Ae({compact:e=!1}){let{project:t}=L(),n=ce.organization.getAll.useQuery({isDemo:!1},{staleTime:6e4}),[r,i]=(0,W.useState)(!1),{selectedProjectId:a,setSelectedProject:o}=H(),s=(0,W.useMemo)(()=>n.data?n.data.flatMap(e=>e.teams.flatMap(t=>t.projects.map(n=>({id:n.id,name:n.name,slug:n.slug,apiKey:n.apiKey,orgName:e.name,teamName:t.name})))):[],[n.data]),c=a?s.find(e=>e.id===a):s.find(e=>e.id===t?.id)??s[0];return(0,G.jsxs)(b,{p:3,children:[(0,G.jsx)(j,{fontSize:`xs`,fontWeight:`medium`,textTransform:`uppercase`,letterSpacing:`wider`,color:`fg.muted`,mb:2,children:`Target Project`}),(0,G.jsxs)(b,{position:`relative`,children:[(0,G.jsxs)(k,{as:`button`,w:`full`,align:`center`,gap:2,rounded:`md`,border:`1px solid`,borderColor:`border`,px:2,py:1.5,cursor:`pointer`,_hover:{bg:`bg.subtle`},onClick:()=>i(!r),children:[(0,G.jsx)(b,{w:2,h:2,rounded:`full`,bg:c?`green.400`:`gray.500`,flexShrink:0}),(0,G.jsxs)(I,{align:`start`,gap:0,flex:1,minW:0,children:[(0,G.jsx)(j,{fontSize:`xs`,color:`fg.default`,truncate:!0,w:`full`,textAlign:`left`,children:c?.name??`Select a project`}),c&&!e&&(0,G.jsx)(j,{fontSize:`10px`,color:`fg.muted`,truncate:!0,w:`full`,textAlign:`left`,children:c.orgName})]}),(0,G.jsx)(f,{size:12,color:`var(--chakra-colors-fg-muted)`})]}),r&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(b,{position:`fixed`,inset:0,zIndex:40,onClick:()=>i(!1)}),(0,G.jsx)(b,{position:`absolute`,left:0,right:0,zIndex:50,mt:1,maxH:`300px`,overflow:`auto`,rounded:`lg`,border:`1px solid`,borderColor:`border`,bg:`bg.panel`,shadow:`lg`,children:s.length===0?(0,G.jsx)(b,{px:3,py:2,children:(0,G.jsx)(j,{fontSize:`xs`,color:`fg.muted`,children:`No projects found`})}):(0,G.jsx)(je,{projects:s,selectedId:c?.id,onSelect:e=>{o(e.id,e.apiKey),i(!1)}})})]})]})]})}function je({projects:e,selectedId:t,onSelect:n}){return(0,G.jsx)(I,{align:`stretch`,gap:0,py:1,children:[...(0,W.useMemo)(()=>{let t=new Map;for(let n of e){let e=t.get(n.orgName)??[];e.push(n),t.set(n.orgName,e)}return t},[e]).entries()].map(([e,r])=>(0,G.jsxs)(b,{children:[(0,G.jsx)(j,{fontSize:`10px`,fontWeight:`medium`,color:`fg.muted`,textTransform:`uppercase`,letterSpacing:`wider`,px:3,py:1,children:e}),r.map(e=>(0,G.jsxs)(k,{as:`button`,w:`full`,align:`center`,gap:2,px:3,py:1.5,_hover:{bg:`bg.subtle`},onClick:()=>n(e),children:[t===e.id?(0,G.jsx)(M,{size:12,color:`var(--chakra-colors-green-400)`}):(0,G.jsx)(b,{w:3}),(0,G.jsx)(j,{fontSize:`xs`,color:`fg.default`,flex:1,textAlign:`left`,truncate:!0,children:e.name}),(0,G.jsx)(j,{fontSize:`10px`,color:`fg.muted`,fontFamily:`mono`,children:e.slug})]},e.id))]},e))})}function Me({compact:e=!1}){let{batchCount:t,staggerMs:n,running:r,setBatchCount:i,setStaggerMs:a,setRunning:o,addLogEntry:c,updateLogEntry:l}=B(),u=R(e=>e.trace),{project:d}=L(),f=H(e=>e.selectedApiKey)??d?.apiKey;async function p(){if(!(r||!f)){o(!0);for(let e=0;e<t;e++){let r=`log-${Date.now()}-${e}`;c({id:r,traceId:r,timestamp:Date.now(),status:`pending`});try{l(r,{status:`success`,traceId:await de({trace:u,apiKey:f,endpoint:window.location.origin})})}catch(e){l(r,{status:`error`,error:e instanceof Error?e.message:`Send failed`})}n>0&&e<t-1&&await new Promise(e=>setTimeout(e,n))}o(!1)}}return(0,G.jsxs)(b,{p:3,children:[(0,G.jsx)(j,{fontSize:`xs`,fontWeight:`medium`,textTransform:`uppercase`,letterSpacing:`wider`,color:`fg.muted`,mb:2,children:`Execution`}),(0,G.jsxs)(k,{gap:2,mb:2,children:[(0,G.jsxs)(b,{flex:1,children:[(0,G.jsx)(j,{fontSize:`xs`,color:`fg.subtle`,mb:1,children:`Run N times`}),(0,G.jsx)(N,{size:`sm`,type:`number`,value:t,onChange:e=>i(parseInt(e.target.value)||1),min:1,max:100})]}),!e&&(0,G.jsxs)(b,{flex:1,children:[(0,G.jsx)(j,{fontSize:`xs`,color:`fg.subtle`,mb:1,children:`Stagger (ms)`}),(0,G.jsx)(N,{size:`sm`,type:`number`,value:n,onChange:e=>a(parseInt(e.target.value)||0),min:0,step:100})]})]}),(0,G.jsxs)(y,{w:`full`,size:`sm`,colorPalette:`orange`,onClick:p,disabled:r||!f,loading:r,loadingText:`Sending...`,children:[(0,G.jsx)(s,{size:14}),` Send Traces`]}),!f&&(0,G.jsx)(j,{fontSize:`xs`,color:`fg.muted`,mt:1,children:`Navigate to a project first`}),(0,G.jsx)(Ne,{})]})}function Ne(){let e=B(e=>e.log),t=B(e=>e.clearLog);return e.length===0?null:(0,G.jsxs)(b,{mt:2,children:[(0,G.jsxs)(k,{justify:`space-between`,align:`center`,mb:1,children:[(0,G.jsx)(j,{fontSize:`xs`,color:`fg.muted`,children:`Log`}),(0,G.jsx)(j,{as:`button`,fontSize:`xs`,color:`fg.muted`,_hover:{color:`fg.default`},onClick:t,children:`Clear`})]}),(0,G.jsx)(I,{maxH:`120px`,overflow:`auto`,gap:.5,align:`stretch`,children:e.map(e=>(0,G.jsx)(Pe,{entry:e},e.id))})]})}function Pe({entry:e}){let[t,n]=(0,W.useState)(!1),r=e.status===`success`;return(0,G.jsxs)(k,{align:`center`,gap:2,px:2,py:1,fontSize:`xs`,rounded:`sm`,cursor:r?`pointer`:`default`,bg:t?`green.500/10`:`transparent`,_hover:r?{bg:t?`green.500/10`:`bg.subtle`}:void 0,transition:`background 0.15s`,onClick:()=>{r&&(navigator.clipboard.writeText(e.traceId),n(!0),setTimeout(()=>n(!1),2e3))},children:[(0,G.jsx)(j,{flexShrink:0,children:e.status===`pending`?`⏳`:e.status===`success`?`✅`:`❌`}),(0,G.jsx)(j,{flex:1,truncate:!0,fontFamily:`mono`,color:`fg.muted`,children:e.traceId}),r&&(0,G.jsx)(j,{fontSize:`10px`,color:t?`green.400`:`fg.muted`,flexShrink:0,children:t?`Copied!`:`Copy ID`}),e.error&&(0,G.jsx)(j,{color:`red.400`,title:e.error,flexShrink:0,children:`Failed`})]})}function Fe({compact:e=!1}){let t=R(e=>e.trace),n=R(e=>e.updateTrace);return(0,G.jsxs)(b,{p:3,children:[(0,G.jsx)(j,{fontSize:`xs`,fontWeight:`medium`,textTransform:`uppercase`,letterSpacing:`wider`,color:`fg.muted`,mb:2,children:`Trace Settings`}),(0,G.jsxs)(I,{gap:2,align:`stretch`,children:[(0,G.jsxs)(b,{children:[(0,G.jsx)(j,{fontSize:`xs`,color:`fg.subtle`,mb:1,children:`service.name`}),(0,G.jsx)(N,{size:`sm`,value:t.resourceAttributes[`service.name`]??``,onChange:e=>n({resourceAttributes:{...t.resourceAttributes,"service.name":e.target.value}})})]}),(0,G.jsxs)(b,{children:[(0,G.jsx)(j,{fontSize:`xs`,color:`fg.subtle`,mb:1,children:`user_id`}),(0,G.jsx)(N,{size:`sm`,value:t.metadata.userId??``,onChange:e=>n({metadata:{...t.metadata,userId:e.target.value||void 0}}),placeholder:`optional`})]}),!e&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(b,{children:[(0,G.jsx)(j,{fontSize:`xs`,color:`fg.subtle`,mb:1,children:`thread_id`}),(0,G.jsx)(N,{size:`sm`,value:t.metadata.threadId??``,onChange:e=>n({metadata:{...t.metadata,threadId:e.target.value||void 0}}),placeholder:`optional`})]}),(0,G.jsxs)(b,{children:[(0,G.jsx)(j,{fontSize:`xs`,color:`fg.subtle`,mb:1,children:`labels`}),(0,G.jsx)(N,{size:`sm`,value:t.metadata.labels?.join(`, `)??``,onChange:e=>n({metadata:{...t.metadata,labels:e.target.value?e.target.value.split(`,`).map(e=>e.trim()):void 0}}),placeholder:`e.g. production, v2`})]})]})]})]})}function J(e,t,n){let r=[];for(let i of e){let e=n+i.offsetMs;r.push({span:i,depth:t,absoluteStartMs:e,absoluteEndMs:e+i.durationMs}),r.push(...J(i.children,t+1,e))}return r}var Ie={llm:`blue.500`,agent:`purple.500`,tool:`green.500`,rag:`teal.500`,chain:`orange.500`,prompt:`yellow.500`,guardrail:`red.500`,workflow:`blue.600`,span:`gray.500`};function Le(){let e=R(e=>e.trace.spans),t=R(e=>e.selectedSpanId),n=R(e=>e.selectSpan),r=J(e,0,0);if(r.length===0)return(0,G.jsx)(k,{h:`200px`,align:`center`,justify:`center`,color:`fg.muted`,children:(0,G.jsx)(j,{children:`No spans`})});let i=Math.min(...r.map(e=>e.absoluteStartMs)),a=Math.max(...r.map(e=>e.absoluteEndMs))-i||1;return(0,G.jsxs)(b,{p:4,children:[(0,G.jsx)(k,{pl:`180px`,mb:2,children:(0,G.jsx)(b,{position:`relative`,flex:1,h:`16px`,children:Array.from({length:6},(e,t)=>Math.round(i+a*t/5)).map((e,t)=>(0,G.jsxs)(j,{position:`absolute`,fontSize:`10px`,color:`fg.muted`,transform:`translateX(-50%)`,left:`${(e-i)/a*100}%`,children:[e,`ms`]},t))})}),(0,G.jsx)(k,{direction:`column`,gap:.5,children:r.map(e=>{let r=(e.absoluteStartMs-i)/a*100,o=Math.max(e.span.durationMs/a*100,.5),s=t===e.span.id,c=e.span.status===`error`?`red.500`:Ie[e.span.type]??`gray.500`;return(0,G.jsxs)(k,{align:`center`,cursor:`pointer`,rounded:`sm`,bg:s?`orange.500/10`:`transparent`,_hover:{bg:s?`orange.500/10`:`bg.subtle`},onClick:()=>n(e.span.id),children:[(0,G.jsxs)(k,{w:`180px`,flexShrink:0,align:`center`,gap:1,pr:2,pl:`${e.depth*16+8}px`,truncate:!0,children:[(0,G.jsx)(j,{fontSize:`xs`,flexShrink:0,children:V[e.span.type]}),(0,G.jsx)(j,{fontSize:`xs`,color:`fg.default`,truncate:!0,children:e.span.name})]}),(0,G.jsx)(b,{flex:1,position:`relative`,h:`20px`,children:(0,G.jsx)(b,{position:`absolute`,top:`3px`,h:`14px`,rounded:`sm`,bg:c,left:`${r}%`,w:`${o}%`,minW:`4px`,opacity:s?1:.8,ring:s?`1px`:void 0,ringColor:s?`orange.400`:void 0})}),(0,G.jsxs)(j,{w:`50px`,flexShrink:0,textAlign:`right`,fontSize:`10px`,color:`fg.muted`,pr:2,children:[e.span.durationMs,`ms`]})]},e.span.id)})})]})}function Re({data:e}){let t=z[e.type]??`gray.400`;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(A,{type:`target`,position:O.Top,style:{background:`var(--chakra-colors-border)`,width:8,height:8,border:`1px solid var(--chakra-colors-border)`}}),(0,G.jsxs)(b,{borderRadius:`lg`,borderWidth:`1px`,borderColor:e.isSelected?`orange.400`:e.status===`error`?`red.600`:`border`,bg:e.isSelected?`orange.subtle`:e.status===`error`?`red.subtle`:`bg.panel`,paddingX:3,paddingY:2,minWidth:`140px`,boxShadow:`sm`,children:[(0,G.jsxs)(P,{gap:1.5,children:[(0,G.jsx)(j,{textStyle:`sm`,children:V[e.type]??`·`}),(0,G.jsx)(j,{textStyle:`xs`,fontWeight:`medium`,truncate:!0,maxWidth:`120px`,children:e.label})]}),(0,G.jsxs)(P,{gap:2,marginTop:1,children:[(0,G.jsx)(j,{textStyle:`xs`,color:t,textTransform:`uppercase`,children:e.type}),(0,G.jsxs)(j,{textStyle:`xs`,color:`fg.muted`,children:[e.durationMs,`ms`]})]})]}),(0,G.jsx)(A,{type:`source`,position:O.Bottom,style:{background:`var(--chakra-colors-border)`,width:8,height:8,border:`1px solid var(--chakra-colors-border)`}})]})}var ze={spanNode:Re};function Y(e,t,n=null,r=0,i=0){let a=[],o=[],s=r;for(let r of e){let e=Y(r.children,t,r.id,s,i+100),c=Math.max(e.width,180),l=s+c/2-180/2;a.push({id:r.id,type:`spanNode`,position:{x:l,y:i},data:{label:r.name,type:r.type,durationMs:r.durationMs,status:r.status,spanId:r.id,isSelected:t===r.id}}),n&&o.push({id:`${n}-${r.id}`,source:n,target:r.id,style:{stroke:`var(--chakra-colors-border)`}}),a.push(...e.nodes),o.push(...e.edges),s+=c}return{nodes:a,edges:o,width:Math.max(s-r,0)}}function Be(){let e=R(e=>e.trace.spans),t=R(e=>e.selectedSpanId),n=R(e=>e.selectSpan),r=x(),{nodes:i,edges:a}=(0,W.useMemo)(()=>Y(e,t),[e,t]),o=(0,W.useCallback)((e,t)=>{n(t.data.spanId)},[n]);return(0,G.jsx)(b,{height:`full`,width:`full`,className:r.colorMode===`dark`?`dark`:``,css:{"& .react-flow__controls":{background:`var(--chakra-colors-bg-panel)`,border:`1px solid var(--chakra-colors-border)`,borderRadius:`8px`,boxShadow:`none`},"& .react-flow__controls-button":{background:`var(--chakra-colors-bg-panel)`,borderColor:`var(--chakra-colors-border)`,fill:`var(--chakra-colors-fg-muted)`,"&:hover":{background:`var(--chakra-colors-bg-muted)`}},"& .react-flow__edge-path":{stroke:`var(--chakra-colors-border)`},"& .react-flow__background pattern line":{stroke:`var(--chakra-colors-border)`}},children:(0,G.jsxs)(ae,{nodes:i,edges:a,nodeTypes:ze,onNodeClick:o,fitView:!0,fitViewOptions:{padding:.3},proOptions:{hideAttribution:!0},colorMode:r.colorMode===`dark`?`dark`:`light`,style:{background:`var(--chakra-colors-bg-subtle)`},children:[(0,G.jsx)(re,{color:`var(--chakra-colors-border)`,gap:20}),(0,G.jsx)(ie,{})]})})}var X={$schema:`http://json-schema.org/draft-07/schema#`,type:`object`,required:[`id`,`name`,`resourceAttributes`,`metadata`,`spans`],properties:{id:{type:`string`,description:`Unique trace identifier`},name:{type:`string`,description:`Human-readable trace name`},description:{type:`string`,description:`Optional trace description`},resourceAttributes:{type:`object`,additionalProperties:{type:`string`},description:`OTel resource attributes (e.g. service.name)`},metadata:{type:`object`,properties:{userId:{type:`string`,description:`User ID for the trace`},threadId:{type:`string`,description:`Conversation thread ID`},customerId:{type:`string`,description:`Customer/tenant ID`},labels:{type:`array`,items:{type:`string`},description:`Trace labels`}},additionalProperties:!1},spans:{type:`array`,items:{$ref:`#/definitions/SpanConfig`},description:`Root-level spans in the trace`}},additionalProperties:!1,definitions:{SpanConfig:{type:`object`,required:[`id`,`name`,`type`,`durationMs`,`offsetMs`,`status`,`children`,`attributes`],properties:{id:{type:`string`},name:{type:`string`,description:`Span display name`},type:{type:`string`,enum:[...U],description:`Span type (llm, agent, tool, rag, etc.)`},durationMs:{type:`number`,minimum:0,description:`Span duration in ms`},offsetMs:{type:`number`,minimum:0,description:`Offset from parent start in ms`},status:{type:`string`,enum:[`ok`,`error`,`unset`]},children:{type:`array`,items:{$ref:`#/definitions/SpanConfig`},description:`Child spans`},input:{$ref:`#/definitions/SpanInputOutput`},output:{$ref:`#/definitions/SpanInputOutput`},attributes:{type:`object`,additionalProperties:{oneOf:[{type:`string`},{type:`number`},{type:`boolean`}]},description:`Custom span attributes`},exception:{type:`object`,properties:{message:{type:`string`},stackTrace:{type:`string`}},required:[`message`]},llm:{$ref:`#/definitions/LLMConfig`},rag:{$ref:`#/definitions/RAGConfig`},prompt:{$ref:`#/definitions/PromptConfig`}},additionalProperties:!1},SpanInputOutput:{type:`object`,required:[`type`,`value`],properties:{type:{type:`string`,enum:[...le]},value:{description:`The input/output value`}}},LLMConfig:{type:`object`,properties:{requestModel:{type:`string`,description:`Model requested (e.g. gpt-4o)`},responseModel:{type:`string`,description:`Model that responded`},messages:{type:`array`,items:{type:`object`,required:[`role`,`content`],properties:{role:{type:`string`,enum:[`system`,`user`,`assistant`,`tool`]},content:{type:`string`}}}},temperature:{type:`number`,minimum:0,maximum:2},stream:{type:`boolean`},metrics:{type:`object`,properties:{promptTokens:{type:`number`},completionTokens:{type:`number`},cost:{type:`number`}}}},additionalProperties:!1},RAGConfig:{type:`object`,required:[`contexts`],properties:{contexts:{type:`array`,items:{type:`object`,required:[`document_id`,`chunk_id`,`content`],properties:{document_id:{type:`string`},chunk_id:{type:`string`},content:{type:`string`}}}}},additionalProperties:!1},PromptConfig:{type:`object`,properties:{promptId:{type:`string`},versionId:{type:`string`},variables:{type:`object`,additionalProperties:{type:`string`}}},additionalProperties:!1}}},Ve=he(()=>n(()=>import(`./dist-B1d0YXwd.js`),__vite__mapDeps([0,1,2])),{ssr:!1,loading:()=>(0,G.jsx)(b,{padding:4,color:`fg.muted`,children:`Loading editor...`})});function Z(e){return e.reduce((e,t)=>e+1+Z(t.children),0)}function He(){let e=R(e=>e.trace),t=R(e=>e.setTrace),n=R(e=>e.resetTrace),{colorMode:i}=x(),[a,o]=(0,W.useState)(!1),[s,l]=(0,W.useState)(null),u=(0,W.useRef)(null),d=(0,W.useMemo)(()=>JSON.stringify(e,null,2),[e]),f=(0,W.useMemo)(()=>Z(e.spans),[e.spans]),p=d.split(`
3
3
  `).length;function m(e){if(e)try{t(JSON.parse(e)),l(null)}catch(e){l(e instanceof Error?e.message:`Invalid JSON`)}}function h(){let e=u.current?.getValue()??d;navigator.clipboard.writeText(e),o(!0),setTimeout(()=>o(!1),2e3)}function g(){let e=u.current?.getValue();if(e)try{t(JSON.parse(e)),l(null)}catch{}}return(0,G.jsxs)(b,{h:`full`,w:`full`,minH:0,display:`flex`,flexDirection:`column`,children:[(0,G.jsxs)(P,{px:3,py:1.5,borderBottom:`1px solid`,borderColor:`border`,bg:`bg.subtle`,flexShrink:0,gap:2,justify:`space-between`,children:[(0,G.jsxs)(P,{gap:2,children:[(0,G.jsxs)(D,{size:`sm`,variant:`outline`,children:[f,` `,f===1?`span`:`spans`]}),(0,G.jsxs)(D,{size:`sm`,variant:`outline`,children:[p,` lines`]}),s?(0,G.jsx)(j,{fontSize:`xs`,color:`red.400`,truncate:!0,maxW:`300px`,children:s}):(0,G.jsx)(j,{fontSize:`xs`,color:`green.500`,children:`Valid`})]}),(0,G.jsxs)(P,{gap:1,children:[(0,G.jsx)(y,{size:`2xs`,variant:`ghost`,onClick:g,title:`Format`,children:(0,G.jsx)(_e,{size:12})}),(0,G.jsx)(y,{size:`2xs`,variant:`ghost`,onClick:h,title:`Copy`,children:a?(0,G.jsx)(M,{size:12}):(0,G.jsx)(r,{size:12})}),(0,G.jsx)(y,{size:`2xs`,variant:`ghost`,onClick:n,title:`Reset to default`,children:(0,G.jsx)(c,{size:12})})]})]}),(0,G.jsx)(b,{flex:1,minH:0,children:(0,G.jsx)(Ve,{height:`100%`,language:`json`,value:d,onChange:m,theme:i===`dark`?`vs-dark`:`light`,onMount:e=>{u.current=e},beforeMount:e=>{e.languages.json.jsonDefaults.setDiagnosticsOptions({validate:!0,allowComments:!1,trailingCommas:`error`,schemas:[{uri:`https://langwatch.ai/schemas/trace-config.json`,fileMatch:[`*`],schema:X}]})},options:{minimap:{enabled:!1},fontSize:12,lineNumbers:`on`,scrollBeyondLastLine:!1,automaticLayout:!0,tabSize:2,wordWrap:`on`,formatOnPaste:!0}})})]})}function Ue({compact:e=!1}){let t=R(e=>e.selectedSpanId);return(0,G.jsxs)(S,{h:`full`,w:`full`,templateColumns:`${e?`260px`:`300px`} minmax(0, 1fr)`,overflow:`hidden`,children:[(0,G.jsx)(w,{overflow:`auto`,borderRight:`1px solid`,borderColor:`border`,children:(0,G.jsxs)(k,{direction:`column`,minH:`full`,children:[(0,G.jsx)(Ae,{compact:e}),(0,G.jsx)(b,{borderTop:`1px solid`,borderColor:`border`,children:(0,G.jsx)(Fe,{compact:e})}),(0,G.jsx)(b,{borderTop:`1px solid`,borderColor:`border`,flex:1,children:(0,G.jsx)(be,{})}),(0,G.jsx)(b,{borderTop:`1px solid`,borderColor:`border`,children:(0,G.jsx)(Me,{compact:e})})]})}),(0,G.jsx)(w,{overflow:`hidden`,display:`flex`,flexDirection:`column`,children:(0,G.jsxs)(te,{defaultValue:`editor`,variant:`line`,size:`sm`,display:`flex`,flexDirection:`column`,flex:1,overflow:`hidden`,children:[(0,G.jsxs)(ne,{borderBottom:`1px solid`,borderColor:`border`,px:3,gap:0,flexShrink:0,children:[(0,G.jsx)(C,{value:`editor`,fontSize:`xs`,px:3,py:1.5,color:`fg.muted`,_selected:{color:`fg.default`,borderColor:`orange.500`},children:`Editor`}),(0,G.jsx)(C,{value:`waterfall`,fontSize:`xs`,px:3,py:1.5,color:`fg.muted`,_selected:{color:`fg.default`,borderColor:`orange.500`},children:`Waterfall`}),(0,G.jsx)(C,{value:`graph`,fontSize:`xs`,px:3,py:1.5,color:`fg.muted`,_selected:{color:`fg.default`,borderColor:`orange.500`},children:`Graph`}),(0,G.jsx)(C,{value:`json`,fontSize:`xs`,px:3,py:1.5,color:`fg.muted`,_selected:{color:`fg.default`,borderColor:`orange.500`},children:`JSON`})]}),(0,G.jsxs)(b,{flex:1,overflow:`auto`,minH:0,children:[(0,G.jsx)(T,{value:`editor`,p:0,children:t?(0,G.jsx)(ke,{}):(0,G.jsx)(k,{h:`300px`,align:`center`,justify:`center`,color:`fg.muted`,children:(0,G.jsxs)(b,{textAlign:`center`,children:[(0,G.jsx)(j,{fontSize:`md`,children:`Select a span to edit`}),(0,G.jsx)(j,{fontSize:`sm`,mt:1,children:`Or add a new span from the tree`})]})})}),(0,G.jsx)(T,{value:`waterfall`,p:0,children:(0,G.jsx)(Le,{})}),(0,G.jsx)(T,{value:`graph`,p:0,h:`full`,children:(0,G.jsx)(Be,{})}),(0,G.jsx)(T,{value:`json`,p:0,h:`full`,children:(0,G.jsx)(He,{})})]})]})})]})}function Q(e){return e.reduce((e,t)=>e+1+Q(t.children),0)}function We(){let[e,t]=(0,W.useState)(!1),n=R(e=>e.setTrace),{builtIn:r,userPresets:i}=ue(),a=[...r,...i];function o(e){let r=a.find(t=>t.id===e);r&&(n(structuredClone(r.config)),t(!1))}return(0,G.jsxs)(b,{position:`relative`,children:[(0,G.jsxs)(y,{size:`xs`,variant:`outline`,onClick:()=>t(!e),children:[`Load Preset `,(0,G.jsx)(f,{size:12})]}),e&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(b,{position:`fixed`,inset:0,zIndex:40,onClick:()=>t(!1)}),(0,G.jsxs)(b,{position:`absolute`,right:0,zIndex:50,mt:1,w:`360px`,maxH:`400px`,overflow:`auto`,rounded:`lg`,border:`1px solid`,borderColor:`border`,bg:`bg.panel`,shadow:`xl`,p:1,children:[(0,G.jsx)(j,{fontSize:`xs`,fontWeight:`medium`,color:`fg.muted`,px:2,py:1,children:`Built-in Presets`}),r.map(e=>(0,G.jsxs)(k,{as:`button`,w:`full`,align:`flex-start`,direction:`column`,gap:.5,rounded:`md`,px:3,py:2,textAlign:`left`,_hover:{bg:`bg.subtle`},onClick:()=>o(e.id),children:[(0,G.jsxs)(k,{w:`full`,justify:`space-between`,align:`center`,children:[(0,G.jsx)(j,{fontSize:`sm`,fontWeight:`medium`,color:`fg.default`,children:e.name}),(0,G.jsxs)(j,{fontSize:`10px`,color:`fg.muted`,children:[Q(e.config.spans),` spans`]})]}),(0,G.jsx)(j,{fontSize:`xs`,color:`fg.muted`,lineClamp:1,children:e.description})]},e.id)),i.length>0&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(j,{fontSize:`xs`,fontWeight:`medium`,color:`fg.muted`,px:2,py:1,mt:1,children:`Your Presets`}),i.map(e=>(0,G.jsxs)(k,{as:`button`,w:`full`,align:`flex-start`,direction:`column`,gap:.5,rounded:`md`,px:3,py:2,textAlign:`left`,_hover:{bg:`bg.subtle`},onClick:()=>o(e.id),children:[(0,G.jsxs)(k,{w:`full`,justify:`space-between`,align:`center`,children:[(0,G.jsx)(j,{fontSize:`sm`,fontWeight:`medium`,color:`fg.default`,children:e.name}),(0,G.jsx)(D,{colorPalette:`purple`,size:`sm`,children:`Custom`})]}),(0,G.jsx)(j,{fontSize:`xs`,color:`fg.muted`,lineClamp:1,children:e.description})]},e.id))]})]})]})]})}var $=[`Warming up the flux capacitor...`,`Calibrating span generators...`,`Untangling distributed traces...`,`Teaching spans about their parents...`,`Inflating token counts for drama...`,`Reticulating splines (the OTel ones)...`,`Asking the LLM to be patient...`];function Ge(){let[e]=(0,W.useState)(()=>$[Math.floor(Math.random()*$.length)]);return(0,G.jsx)(oe,{h:`full`,children:(0,G.jsxs)(I,{gap:3,children:[(0,G.jsx)(j,{fontSize:`lg`,fontWeight:`semibold`,color:`fg.default`,children:`The Foundry`}),(0,G.jsx)(j,{fontSize:`sm`,color:`fg.muted`,fontStyle:`italic`,children:e})]})})}function Ke(){let e=R(e=>e.resetTrace),[t,n]=(0,W.useState)(!1);return(0,W.useEffect)(()=>{n(!0)},[]),(0,G.jsx)(ge,{children:(0,G.jsxs)(g,{children:[(0,G.jsx)(d.Header,{children:(0,G.jsxs)(k,{align:`center`,justify:`space-between`,w:`full`,children:[(0,G.jsx)(d.Heading,{children:`The Foundry`}),(0,G.jsxs)(P,{gap:2,children:[(0,G.jsx)(We,{}),(0,G.jsxs)(y,{size:`xs`,variant:`outline`,onClick:e,children:[(0,G.jsx)(c,{size:14}),`Reset`]})]})]})}),(0,G.jsx)(b,{height:`calc(100vh - 56px - 48px)`,w:`full`,overflow:`hidden`,borderTopLeftRadius:`inherit`,children:t?(0,G.jsx)(Ue,{}):(0,G.jsx)(Ge,{})})]})})}export{Ke as default};
4
- //# sourceMappingURL=foundry-Ckq0WjPU.js.map
4
+ //# sourceMappingURL=foundry-B-X_80pD.js.map
@@ -1,2 +1,2 @@
1
- import{s as e}from"./chunk-Bj-mKKzh.js";import{t}from"./react-C7JcuhbW.js";import{mn as n}from"./command-bar-CaJygoez.js";import{r}from"./next-router-C6sliiV7.js";import{t as i}from"./useOrganizationTeamProject-DC0iozx2.js";import{t as a}from"./WithPermissionGuard-DD8uo3UK.js";var o=e(t());function s(){let e=r(),{project:t}=i();return(0,o.useEffect)(()=>{t?.slug&&e.replace(`/${t.slug}/gateway/virtual-keys`)},[t?.slug,e]),null}var c=a(`virtualKeys:view`,{layoutComponent:n})(s);export{c as default};
2
- //# sourceMappingURL=gateway-CDSYPZ6w.js.map
1
+ import{s as e}from"./chunk-Bj-mKKzh.js";import{t}from"./react-C7JcuhbW.js";import{mn as n}from"./command-bar-DUK45yin.js";import{r}from"./next-router-C6sliiV7.js";import{t as i}from"./useOrganizationTeamProject-DC0iozx2.js";import{t as a}from"./WithPermissionGuard-B4Jo8E5-.js";var o=e(t());function s(){let e=r(),{project:t}=i();return(0,o.useEffect)(()=>{t?.slug&&e.replace(`/${t.slug}/gateway/virtual-keys`)},[t?.slug,e]),null}var c=a(`virtualKeys:view`,{layoutComponent:n})(s);export{c as default};
2
+ //# sourceMappingURL=gateway-CS_mtJx-.js.map
@@ -1,2 +1,2 @@
1
- import{s as e}from"./chunk-Bj-mKKzh.js";import{t}from"./react-C7JcuhbW.js";import{Aa as n,Fa as r,Ss as i,Xa as a,_s as o,bs as s,ho as c,na as l,qi as u,sc as d,vs as f,wa as p,xs as m,ya as h,ys as g,za as _}from"./command-bar-CaJygoez.js";import{j as v,n as y,r as b}from"./stack-oJ9iWdbl.js";import{t as x}from"./box-BsM8YLGl.js";import{n as S}from"./toaster-C_DYALhL.js";import{an as C,f as w,i as T}from"./dist-SwV3YZv3.js";import{h as E}from"./terminal-CfM0q99k.js";import{t as D}from"./heading-D90dlSnH.js";import{t as O}from"./text-CwTrMF8x.js";import{t as k}from"./input-C7emsUCL.js";import{t as A}from"./h-stack-BKLDJ2vg.js";import{a as j,i as M,n as N,r as P,t as F}from"./alert-SnQmACl1.js";import{r as I,t as L}from"./card-CMtKVPVl.js";import{t as R}from"./spacer-2LJJGbo8.js";import{t as z}from"./v-stack-EOPQ57OZ.js";import{s as B}from"./auth-client-D3UhxhQi.js";import{t as V}from"./useOrganizationTeamProject-DC0iozx2.js";import{n as H,t as U}from"./SettingsLayout-CLCGxMAe.js";import{t as W}from"./ContactSalesBlock-CijLBwRC.js";import{t as G}from"./WithPermissionGuard-DD8uo3UK.js";import{i as K,n as q,r as J,t as Y}from"./GroupBindingInputRow-DebZBCnD.js";var X=e(t()),Z=v();function Q({organizationId:e,open:t,onClose:r}){let i=B.useContext(),[a,o]=(0,X.useState)(``),[s,u]=(0,X.useState)([]),[f,p]=(0,X.useState)([]),[m,g]=(0,X.useState)(``),[_,v]=(0,X.useState)(``),b=B.organization.getOrganizationWithMembersAndTheirTeams.useQuery({organizationId:e},{enabled:t}),E=B.group.create.useMutation();function D(){o(``),u([]),p([]),g(``),v(``)}async function j(){if(a.trim())try{await E.mutateAsync({organizationId:e,name:a.trim(),bindings:s.map(e=>({role:e.role,customRoleId:e.customRoleId,scopeType:e.scopeType,scopeId:e.scopeId})),memberIds:f}),i.group.listAll.invalidate(),D(),r()}catch(e){S.create({title:e.message??`Failed to create group`,type:`error`})}}let M=(b.data?.members??[]).filter(e=>!f.includes(e.userId)).map(e=>({label:`${e.user.name??e.user.email} (${e.user.email})`,value:e.userId})).sort((e,t)=>e.label.localeCompare(t.label)),N=_?M.filter(e=>e.label.toLowerCase().includes(_.toLowerCase())):M,P=d({items:N});return(0,Z.jsx)(w.Root,{open:t,onOpenChange:e=>{e.open||(D(),r())},size:`lg`,children:(0,Z.jsxs)(w.Content,{maxHeight:`90vh`,overflowY:`auto`,children:[(0,Z.jsx)(w.Header,{children:(0,Z.jsx)(w.Title,{children:`Create group`})}),(0,Z.jsx)(w.CloseTrigger,{}),(0,Z.jsx)(w.Body,{pb:6,children:(0,Z.jsxs)(z,{gap:5,align:`stretch`,children:[(0,Z.jsx)(k,{autoFocus:!0,placeholder:`Group name`,value:a,onChange:e=>o(e.target.value)}),(0,Z.jsxs)(x,{children:[(0,Z.jsx)(O,{fontSize:`sm`,fontWeight:`semibold`,mb:3,children:`Access`}),s.length>0&&(0,Z.jsx)(z,{gap:2,align:`stretch`,mb:2,children:s.map((e,t)=>(0,Z.jsxs)(A,{px:3,py:2,bg:`bg.muted`,borderRadius:`md`,fontSize:`sm`,children:[(0,Z.jsx)(C,{colorPalette:J(e.role),size:`sm`,children:e.customRoleName??e.role}),(0,Z.jsx)(O,{color:`fg.muted`,children:`on`}),(0,Z.jsxs)(C,{colorPalette:`purple`,size:`sm`,children:[K(e.scopeType),` `,e.scopeName??e.scopeId]}),(0,Z.jsx)(R,{}),(0,Z.jsx)(y,{size:`xs`,variant:`ghost`,color:`fg.muted`,"aria-label":`Remove ${e.customRoleName??e.role} binding on ${e.scopeName??e.scopeId}`,onClick:()=>u(e=>e.filter((e,n)=>n!==t)),children:(0,Z.jsx)(h,{size:14})})]},t))}),(0,Z.jsx)(Y,{organizationId:e,onAdd:e=>u(t=>[...t,e])})]}),(0,Z.jsxs)(x,{children:[(0,Z.jsx)(O,{fontSize:`sm`,fontWeight:`semibold`,mb:3,children:`Members`}),f.length>0&&(0,Z.jsx)(z,{gap:1,align:`stretch`,mb:2,children:f.map(e=>{let t=b.data?.members.find(t=>t.userId===e);return(0,Z.jsxs)(A,{py:1,fontSize:`sm`,children:[(0,Z.jsx)(c,{name:t?.user.name??t?.user.email??`?`,size:`xs`}),(0,Z.jsx)(O,{flex:1,children:t?.user.name??t?.user.email??e}),(0,Z.jsx)(y,{size:`xs`,variant:`ghost`,color:`fg.muted`,"aria-label":`Remove ${t?.user.name??t?.user.email??e} from group`,onClick:()=>p(t=>t.filter(t=>t!==e)),children:(0,Z.jsx)(h,{size:14})})]},e)})}),(0,Z.jsx)(A,{gap:2,mt:2,children:(0,Z.jsxs)(l.Root,{collection:P,value:m?[m]:[],onValueChange:e=>{let t=e.value[0];t&&(p(e=>[...e,t]),g(``))},size:`sm`,flex:1,children:[(0,Z.jsx)(l.Trigger,{children:(0,Z.jsx)(l.ValueText,{placeholder:`Add member...`})}),(0,Z.jsxs)(l.Content,{children:[(0,Z.jsx)(x,{position:`sticky`,top:0,zIndex:1,bg:`bg`,pb:1,children:(0,Z.jsx)(T,{startElement:(0,Z.jsx)(n,{size:14}),startOffset:`2px`,width:`full`,children:(0,Z.jsx)(k,{size:`sm`,placeholder:`Search members...`,value:_,onChange:e=>v(e.target.value),onKeyDown:e=>e.stopPropagation()})})}),N.map(e=>(0,Z.jsx)(l.Item,{item:e,children:e.label},e.value))]})]})})]})]})}),(0,Z.jsxs)(w.Footer,{children:[(0,Z.jsx)(y,{variant:`outline`,onClick:()=>{D(),r()},children:`Cancel`}),(0,Z.jsx)(y,{colorPalette:`blue`,disabled:!a.trim(),loading:E.isPending,onClick:()=>void j(),children:`Create group`})]})]})})}function ee({group:e,organizationId:t,canManage:r,open:i,onClose:a}){let o=B.useContext(),[s,u]=(0,X.useState)(e.name),[f,p]=(0,X.useState)(e.name),[m,g]=(0,X.useState)(new Set),[_,v]=(0,X.useState)([]),[E,D]=(0,X.useState)(new Set),[j,M]=(0,X.useState)([]),[N,P]=(0,X.useState)(``),[F,I]=(0,X.useState)(``),[L,V]=(0,X.useState)(!1),H=(0,X.useRef)(null),U=()=>{u(e.name),p(e.name),g(new Set),v([]),D(new Set),M([]),P(``),I(``)};(0,X.useEffect)(()=>{i&&U()},[i,e.id]);let W=s.trim()!==f&&s.trim()!==``,G=W||m.size>0||_.length>0||E.size>0||j.length>0,Q=B.group.getById.useQuery({organizationId:t,groupId:e.id},{enabled:i}),ee=B.organization.getOrganizationWithMembersAndTheirTeams.useQuery({organizationId:t},{enabled:i&&r}),te=B.group.applyEdits.useMutation(),ne=async()=>{let n=H.current?.flush()??null,r=n?[..._,n]:_;V(!0);try{await te.mutateAsync({organizationId:t,groupId:e.id,rename:W?{name:s.trim()}:null,bindingIdsToDelete:[...m],bindingsToCreate:r.map(e=>({role:e.role,customRoleId:e.customRoleId,scopeType:e.scopeType,scopeId:e.scopeId})),memberUserIdsToAdd:j.map(e=>e.userId),memberUserIdsToRemove:[...E]}),o.group.getById.invalidate(),o.group.listAll.invalidate(),S.create({title:`Group updated`,type:`success`}),a()}catch(e){let t=e instanceof Error?e.message:`Failed to save`;S.create({title:t,type:`error`})}finally{V(!1)}},re=e=>g(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),ie=e=>D(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),ae=(e,t)=>{M(n=>[...n,{userId:e,label:t}]),P(``),I(``)},$=Q.data,oe=new Set([...$?.members.map(e=>e.userId)??[],...j.map(e=>e.userId)]);return(0,Z.jsx)(w.Root,{open:i,onOpenChange:e=>{e.open||(U(),a())},size:`lg`,children:(0,Z.jsxs)(w.Content,{maxHeight:`90vh`,overflowY:`auto`,children:[(0,Z.jsx)(w.Header,{children:(0,Z.jsx)(w.Title,{children:e.name})}),(0,Z.jsx)(w.CloseTrigger,{}),(0,Z.jsx)(w.Body,{pb:6,children:Q.isLoading?(0,Z.jsx)(b,{}):$?(0,Z.jsxs)(z,{gap:5,align:`stretch`,children:[r&&!$.scimSource&&(0,Z.jsx)(k,{value:s,onChange:e=>u(e.target.value),placeholder:`Group name`,size:`md`}),(0,Z.jsxs)(A,{children:[(0,Z.jsx)(q,{scimSource:$.scimSource}),(0,Z.jsxs)(O,{fontSize:`sm`,color:`fg.muted`,children:[Math.max(0,$.members.length-E.size+j.length),` `,`members`]})]}),(0,Z.jsxs)(x,{children:[(0,Z.jsx)(O,{fontSize:`sm`,fontWeight:`semibold`,mb:3,children:`Access granted`}),$.bindings.length===0&&_.length===0?(0,Z.jsx)(O,{fontSize:`sm`,color:`fg.muted`,fontStyle:`italic`,children:`No access configured yet.`}):(0,Z.jsxs)(z,{gap:2,align:`stretch`,children:[$.bindings.map(e=>{let t=m.has(e.id);return(0,Z.jsxs)(A,{px:3,py:2,bg:`bg.muted`,borderRadius:`md`,fontSize:`sm`,opacity:t?.4:1,transition:`opacity 0.15s`,children:[(0,Z.jsx)(C,{colorPalette:J(e.role),size:`sm`,textDecoration:t?`line-through`:void 0,children:e.customRoleName??e.role}),(0,Z.jsx)(O,{color:`fg.muted`,children:`on`}),(0,Z.jsxs)(C,{colorPalette:`purple`,size:`sm`,textDecoration:t?`line-through`:void 0,children:[K(e.scopeType),` `,e.scopeName??e.scopeId]}),(0,Z.jsx)(R,{}),r&&(0,Z.jsx)(y,{size:`xs`,variant:`ghost`,color:t?`blue.500`:`fg.muted`,"aria-label":t?`Undo removal`:`Remove binding`,onClick:()=>re(e.id),children:(0,Z.jsx)(h,{size:14})})]},e.id)}),_.map((e,t)=>(0,Z.jsxs)(A,{px:3,py:2,bg:`bg.muted`,borderRadius:`md`,fontSize:`sm`,opacity:.7,children:[(0,Z.jsx)(C,{colorPalette:J(e.role),size:`sm`,children:e.customRoleName??e.role}),(0,Z.jsx)(O,{color:`fg.muted`,children:`on`}),(0,Z.jsxs)(C,{colorPalette:`purple`,size:`sm`,children:[K(e.scopeType),` `,e.scopeName??e.scopeId]}),(0,Z.jsx)(R,{}),(0,Z.jsx)(y,{size:`xs`,variant:`ghost`,color:`fg.muted`,"aria-label":`Undo add`,onClick:()=>v(e=>e.filter((e,n)=>n!==t)),children:(0,Z.jsx)(h,{size:14})})]},t))]}),r&&(0,Z.jsx)(Y,{ref:H,organizationId:t,onAdd:e=>v(t=>[...t,e])})]}),(0,Z.jsxs)(x,{children:[(0,Z.jsx)(O,{fontSize:`sm`,fontWeight:`semibold`,mb:3,children:`Members`}),$.scimSource&&(0,Z.jsxs)(x,{px:3,py:2,bg:`bg.muted`,borderRadius:`md`,mb:3,fontSize:`sm`,color:`fg.muted`,children:[`Membership managed by `,$.scimSource.toUpperCase(),` via SCIM.`]}),$.members.length===0&&j.length===0?(0,Z.jsx)(O,{fontSize:`sm`,color:`fg.muted`,fontStyle:`italic`,children:`No members yet.`}):(0,Z.jsxs)(Z.Fragment,{children:[$.members.map(e=>{let t=E.has(e.userId);return(0,Z.jsxs)(A,{py:1,fontSize:`sm`,opacity:t?.4:1,transition:`opacity 0.15s`,children:[(0,Z.jsx)(c,{name:e.name??e.email??`?`,size:`xs`}),(0,Z.jsx)(O,{flex:1,textDecoration:t?`line-through`:void 0,children:e.name??e.email}),r&&!$.scimSource&&(0,Z.jsx)(y,{size:`xs`,variant:`ghost`,color:t?`blue.500`:`fg.muted`,"aria-label":t?`Undo removal of ${e.name??e.email}`:`Mark ${e.name??e.email} for removal`,onClick:()=>ie(e.userId),children:(0,Z.jsx)(h,{size:14})})]},e.userId)}),j.map(e=>(0,Z.jsxs)(A,{py:1,fontSize:`sm`,opacity:.7,children:[(0,Z.jsx)(c,{name:e.label,size:`xs`}),(0,Z.jsx)(O,{flex:1,color:`green.600`,children:e.label}),(0,Z.jsx)(y,{size:`xs`,variant:`ghost`,color:`fg.muted`,"aria-label":`Undo adding ${e.label}`,onClick:()=>M(t=>t.filter(t=>t.userId!==e.userId)),children:(0,Z.jsx)(h,{size:14})})]},e.userId))]}),r&&!$.scimSource&&(()=>{let e=(ee.data?.members??[]).filter(e=>!oe.has(e.userId)).map(e=>({label:`${e.user.name??e.user.email} (${e.user.email})`,value:e.userId})).sort((e,t)=>e.label.localeCompare(t.label)),t=F?e.filter(e=>e.label.toLowerCase().includes(F.toLowerCase())):e,r=d({items:t});return(0,Z.jsxs)(A,{gap:2,mt:2,children:[(0,Z.jsxs)(l.Root,{collection:r,value:N?[N]:[],onValueChange:e=>P(e.value[0]??``),size:`sm`,flex:1,children:[(0,Z.jsx)(l.Trigger,{children:(0,Z.jsx)(l.ValueText,{placeholder:`Add member...`})}),(0,Z.jsxs)(l.Content,{children:[(0,Z.jsx)(x,{position:`sticky`,top:0,zIndex:1,bg:`bg`,pb:1,children:(0,Z.jsx)(T,{startElement:(0,Z.jsx)(n,{size:14}),startOffset:`2px`,width:`full`,children:(0,Z.jsx)(k,{size:`sm`,placeholder:`Search members...`,value:F,onChange:e=>I(e.target.value),onKeyDown:e=>e.stopPropagation()})})}),t.map(e=>(0,Z.jsx)(l.Item,{item:e,children:e.label},e.value))]})]}),(0,Z.jsx)(y,{size:`sm`,colorPalette:N?`blue`:void 0,disabled:!N,onClick:()=>{let t=e.find(e=>e.value===N);t&&ae(t.value,t.label)},children:`Add`})]})})()]})]}):null}),r&&(0,Z.jsxs)(w.Footer,{children:[(0,Z.jsx)(y,{variant:`outline`,onClick:()=>{U(),a()},children:`Cancel`}),(0,Z.jsx)(y,{colorPalette:`blue`,disabled:!G,loading:L,onClick:()=>void ne(),children:`Save`})]})]})})}function te(){let{organization:e,hasPermission:t}=V(),{isEnterprise:n}=H(),[c,l]=(0,X.useState)(null),[d,h]=(0,X.useState)(!1),[v,T]=(0,X.useState)(null),k=B.useContext(),R=B.group.delete.useMutation({onSuccess:()=>{S.create({title:`Group deleted`,type:`success`}),k.group.listAll.invalidate(),T(null)},onError:e=>S.create({title:e.message,type:`error`})}),G=B.group.listAll.useQuery({organizationId:e?.id??``},{enabled:!!e&&n}),Y=t(`organization:manage`);return e?n?(0,Z.jsxs)(U,{children:[(0,Z.jsxs)(z,{gap:6,width:`full`,align:`start`,children:[(0,Z.jsx)(A,{justify:`space-between`,width:`full`,children:(0,Z.jsxs)(z,{align:`start`,gap:1,children:[(0,Z.jsx)(D,{as:`h2`,children:`Groups`}),(0,Z.jsx)(O,{color:`fg.muted`,fontSize:`sm`,children:`Assign access to many people at once. SCIM-synced groups are managed by your identity provider.`})]})}),(0,Z.jsx)(E,{}),G.isLoading&&(0,Z.jsx)(b,{}),!G.isLoading&&(0,Z.jsx)(I,{width:`full`,overflow:`hidden`,children:(0,Z.jsx)(L,{paddingY:0,paddingX:0,children:(0,Z.jsxs)(m,{variant:`line`,size:`md`,width:`full`,children:[(0,Z.jsx)(s,{children:(0,Z.jsxs)(i,{children:[(0,Z.jsx)(g,{children:`Group`}),(0,Z.jsx)(g,{width:`120px`,children:`Source`}),(0,Z.jsx)(g,{textAlign:`right`,children:`Access`}),(0,Z.jsx)(g,{width:`80px`,textAlign:`right`,children:`Members`}),Y&&(0,Z.jsx)(g,{width:`48px`})]})}),(0,Z.jsxs)(o,{children:[(G.data??[]).map(e=>(0,Z.jsxs)(i,{cursor:`pointer`,onClick:()=>l(e),onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),l(e))},tabIndex:0,role:`button`,_hover:{bg:`bg.muted`},children:[(0,Z.jsx)(f,{fontWeight:`medium`,children:e.name}),(0,Z.jsx)(f,{children:(0,Z.jsx)(q,{scimSource:e.scimSource})}),(0,Z.jsx)(f,{children:(0,Z.jsxs)(z,{gap:1,align:`end`,children:[e.bindings.map((e,t)=>(0,Z.jsxs)(A,{gap:1,fontSize:`xs`,children:[(0,Z.jsx)(C,{colorPalette:J(e.role),size:`sm`,children:e.customRoleName??e.role}),(0,Z.jsx)(O,{color:`fg.muted`,children:`on`}),(0,Z.jsxs)(C,{colorPalette:`purple`,size:`sm`,children:[K(e.scopeType),` `,e.scopeName??e.scopeId]})]},t)),e.bindings.length===0&&(0,Z.jsx)(O,{fontSize:`xs`,color:`fg.subtle`,textAlign:`right`,children:`No access configured`})]})}),(0,Z.jsx)(f,{textAlign:`right`,children:(0,Z.jsx)(O,{fontSize:`sm`,color:`fg.muted`,children:e.memberCount})}),Y&&(0,Z.jsx)(f,{children:(0,Z.jsxs)(u.Root,{children:[(0,Z.jsx)(u.Trigger,{asChild:!0,children:(0,Z.jsx)(y,{variant:`ghost`,size:`xs`,"aria-label":`Actions for ${e.name}`,onClick:e=>e.stopPropagation(),children:(0,Z.jsx)(a,{size:16})})}),(0,Z.jsxs)(u.Content,{children:[(0,Z.jsx)(u.Item,{value:`edit`,onClick:t=>{t.stopPropagation(),l(e)},children:(0,Z.jsxs)(x,{display:`flex`,alignItems:`center`,gap:2,children:[(0,Z.jsx)(_,{size:14}),`Edit`]})}),(0,Z.jsx)(u.Item,{value:`delete`,color:`red.500`,onClick:t=>{t.stopPropagation(),T(e)},children:(0,Z.jsxs)(x,{display:`flex`,alignItems:`center`,gap:2,children:[(0,Z.jsx)(p,{size:14}),`Delete`]})})]})]})})]},e.id)),Y&&(0,Z.jsx)(i,{cursor:`pointer`,onClick:()=>h(!0),onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),h(!0))},tabIndex:0,role:`button`,_hover:{bg:`bg.muted`},color:`fg.muted`,children:(0,Z.jsx)(f,{colSpan:5,children:(0,Z.jsxs)(A,{gap:2,children:[(0,Z.jsx)(r,{size:14}),(0,Z.jsx)(O,{fontSize:`sm`,children:`Add manual group`})]})})})]})]})})})]}),c&&(0,Z.jsx)(ee,{group:c,organizationId:e.id,canManage:Y,open:!!c,onClose:()=>l(null)}),(0,Z.jsx)(Q,{organizationId:e.id,open:d,onClose:()=>h(!1)}),(0,Z.jsx)(w.Root,{open:!!v,onOpenChange:e=>{e.open||T(null)},children:(0,Z.jsxs)(w.Content,{maxWidth:`440px`,children:[(0,Z.jsx)(w.Header,{children:(0,Z.jsx)(w.Title,{children:`Delete group`})}),(0,Z.jsx)(w.CloseTrigger,{}),(0,Z.jsx)(w.Body,{children:(0,Z.jsx)(O,{fontSize:`sm`,children:v?.scimSource?`This SCIM group will be re-created by your IdP on next sync. Delete anyway?`:`Delete "${v?.name}" and all its access rules?`})}),(0,Z.jsxs)(w.Footer,{children:[(0,Z.jsx)(y,{variant:`outline`,onClick:()=>T(null),children:`Cancel`}),(0,Z.jsx)(y,{colorPalette:`red`,loading:R.isPending,onClick:()=>v&&R.mutate({organizationId:e.id,groupId:v.id}),children:`Delete`})]})]})})]}):(0,Z.jsx)(U,{children:(0,Z.jsxs)(z,{gap:6,align:`start`,width:`full`,children:[(0,Z.jsxs)(M,{status:`info`,children:[(0,Z.jsx)(P,{}),(0,Z.jsxs)(F,{children:[(0,Z.jsx)(j,{children:`Enterprise Feature`}),(0,Z.jsx)(N,{children:`Groups are available on Enterprise plans. Contact sales to upgrade.`})]})]}),(0,Z.jsx)(x,{width:`full`,children:(0,Z.jsx)(W,{})})]})}):(0,Z.jsx)(U,{})}var ne=G(`organization:view`,{layoutComponent:U})(te);export{ne as default};
2
- //# sourceMappingURL=groups-CCCRUqPj.js.map
1
+ import{s as e}from"./chunk-Bj-mKKzh.js";import{t}from"./react-C7JcuhbW.js";import{Aa as n,Fa as r,Ss as i,Xa as a,_s as o,bs as s,ho as c,na as l,qi as u,sc as d,vs as f,wa as p,xs as m,ya as h,ys as g,za as _}from"./command-bar-DUK45yin.js";import{j as v,n as y,r as b}from"./stack-oJ9iWdbl.js";import{t as x}from"./box-BsM8YLGl.js";import{n as S}from"./toaster-C_DYALhL.js";import{an as C,f as w,i as T}from"./dist-Cds4Mqhj.js";import{h as E}from"./terminal-CfM0q99k.js";import{t as D}from"./heading-D90dlSnH.js";import{t as O}from"./text-CwTrMF8x.js";import{t as k}from"./input-C7emsUCL.js";import{t as A}from"./h-stack-BKLDJ2vg.js";import{a as j,i as M,n as N,r as P,t as F}from"./alert-SnQmACl1.js";import{r as I,t as L}from"./card-CMtKVPVl.js";import{t as R}from"./spacer-2LJJGbo8.js";import{t as z}from"./v-stack-EOPQ57OZ.js";import{s as B}from"./auth-client-D3UhxhQi.js";import{t as V}from"./useOrganizationTeamProject-DC0iozx2.js";import{n as H,t as U}from"./SettingsLayout--1gdEuhv.js";import{t as W}from"./ContactSalesBlock-CnnuZ8iI.js";import{t as G}from"./WithPermissionGuard-B4Jo8E5-.js";import{i as K,n as q,r as J,t as Y}from"./GroupBindingInputRow-CV-fBkX9.js";var X=e(t()),Z=v();function Q({organizationId:e,open:t,onClose:r}){let i=B.useContext(),[a,o]=(0,X.useState)(``),[s,u]=(0,X.useState)([]),[f,p]=(0,X.useState)([]),[m,g]=(0,X.useState)(``),[_,v]=(0,X.useState)(``),b=B.organization.getOrganizationWithMembersAndTheirTeams.useQuery({organizationId:e},{enabled:t}),E=B.group.create.useMutation();function D(){o(``),u([]),p([]),g(``),v(``)}async function j(){if(a.trim())try{await E.mutateAsync({organizationId:e,name:a.trim(),bindings:s.map(e=>({role:e.role,customRoleId:e.customRoleId,scopeType:e.scopeType,scopeId:e.scopeId})),memberIds:f}),i.group.listAll.invalidate(),D(),r()}catch(e){S.create({title:e.message??`Failed to create group`,type:`error`})}}let M=(b.data?.members??[]).filter(e=>!f.includes(e.userId)).map(e=>({label:`${e.user.name??e.user.email} (${e.user.email})`,value:e.userId})).sort((e,t)=>e.label.localeCompare(t.label)),N=_?M.filter(e=>e.label.toLowerCase().includes(_.toLowerCase())):M,P=d({items:N});return(0,Z.jsx)(w.Root,{open:t,onOpenChange:e=>{e.open||(D(),r())},size:`lg`,children:(0,Z.jsxs)(w.Content,{maxHeight:`90vh`,overflowY:`auto`,children:[(0,Z.jsx)(w.Header,{children:(0,Z.jsx)(w.Title,{children:`Create group`})}),(0,Z.jsx)(w.CloseTrigger,{}),(0,Z.jsx)(w.Body,{pb:6,children:(0,Z.jsxs)(z,{gap:5,align:`stretch`,children:[(0,Z.jsx)(k,{autoFocus:!0,placeholder:`Group name`,value:a,onChange:e=>o(e.target.value)}),(0,Z.jsxs)(x,{children:[(0,Z.jsx)(O,{fontSize:`sm`,fontWeight:`semibold`,mb:3,children:`Access`}),s.length>0&&(0,Z.jsx)(z,{gap:2,align:`stretch`,mb:2,children:s.map((e,t)=>(0,Z.jsxs)(A,{px:3,py:2,bg:`bg.muted`,borderRadius:`md`,fontSize:`sm`,children:[(0,Z.jsx)(C,{colorPalette:J(e.role),size:`sm`,children:e.customRoleName??e.role}),(0,Z.jsx)(O,{color:`fg.muted`,children:`on`}),(0,Z.jsxs)(C,{colorPalette:`purple`,size:`sm`,children:[K(e.scopeType),` `,e.scopeName??e.scopeId]}),(0,Z.jsx)(R,{}),(0,Z.jsx)(y,{size:`xs`,variant:`ghost`,color:`fg.muted`,"aria-label":`Remove ${e.customRoleName??e.role} binding on ${e.scopeName??e.scopeId}`,onClick:()=>u(e=>e.filter((e,n)=>n!==t)),children:(0,Z.jsx)(h,{size:14})})]},t))}),(0,Z.jsx)(Y,{organizationId:e,onAdd:e=>u(t=>[...t,e])})]}),(0,Z.jsxs)(x,{children:[(0,Z.jsx)(O,{fontSize:`sm`,fontWeight:`semibold`,mb:3,children:`Members`}),f.length>0&&(0,Z.jsx)(z,{gap:1,align:`stretch`,mb:2,children:f.map(e=>{let t=b.data?.members.find(t=>t.userId===e);return(0,Z.jsxs)(A,{py:1,fontSize:`sm`,children:[(0,Z.jsx)(c,{name:t?.user.name??t?.user.email??`?`,size:`xs`}),(0,Z.jsx)(O,{flex:1,children:t?.user.name??t?.user.email??e}),(0,Z.jsx)(y,{size:`xs`,variant:`ghost`,color:`fg.muted`,"aria-label":`Remove ${t?.user.name??t?.user.email??e} from group`,onClick:()=>p(t=>t.filter(t=>t!==e)),children:(0,Z.jsx)(h,{size:14})})]},e)})}),(0,Z.jsx)(A,{gap:2,mt:2,children:(0,Z.jsxs)(l.Root,{collection:P,value:m?[m]:[],onValueChange:e=>{let t=e.value[0];t&&(p(e=>[...e,t]),g(``))},size:`sm`,flex:1,children:[(0,Z.jsx)(l.Trigger,{children:(0,Z.jsx)(l.ValueText,{placeholder:`Add member...`})}),(0,Z.jsxs)(l.Content,{children:[(0,Z.jsx)(x,{position:`sticky`,top:0,zIndex:1,bg:`bg`,pb:1,children:(0,Z.jsx)(T,{startElement:(0,Z.jsx)(n,{size:14}),startOffset:`2px`,width:`full`,children:(0,Z.jsx)(k,{size:`sm`,placeholder:`Search members...`,value:_,onChange:e=>v(e.target.value),onKeyDown:e=>e.stopPropagation()})})}),N.map(e=>(0,Z.jsx)(l.Item,{item:e,children:e.label},e.value))]})]})})]})]})}),(0,Z.jsxs)(w.Footer,{children:[(0,Z.jsx)(y,{variant:`outline`,onClick:()=>{D(),r()},children:`Cancel`}),(0,Z.jsx)(y,{colorPalette:`blue`,disabled:!a.trim(),loading:E.isPending,onClick:()=>void j(),children:`Create group`})]})]})})}function ee({group:e,organizationId:t,canManage:r,open:i,onClose:a}){let o=B.useContext(),[s,u]=(0,X.useState)(e.name),[f,p]=(0,X.useState)(e.name),[m,g]=(0,X.useState)(new Set),[_,v]=(0,X.useState)([]),[E,D]=(0,X.useState)(new Set),[j,M]=(0,X.useState)([]),[N,P]=(0,X.useState)(``),[F,I]=(0,X.useState)(``),[L,V]=(0,X.useState)(!1),H=(0,X.useRef)(null),U=()=>{u(e.name),p(e.name),g(new Set),v([]),D(new Set),M([]),P(``),I(``)};(0,X.useEffect)(()=>{i&&U()},[i,e.id]);let W=s.trim()!==f&&s.trim()!==``,G=W||m.size>0||_.length>0||E.size>0||j.length>0,Q=B.group.getById.useQuery({organizationId:t,groupId:e.id},{enabled:i}),ee=B.organization.getOrganizationWithMembersAndTheirTeams.useQuery({organizationId:t},{enabled:i&&r}),te=B.group.applyEdits.useMutation(),ne=async()=>{let n=H.current?.flush()??null,r=n?[..._,n]:_;V(!0);try{await te.mutateAsync({organizationId:t,groupId:e.id,rename:W?{name:s.trim()}:null,bindingIdsToDelete:[...m],bindingsToCreate:r.map(e=>({role:e.role,customRoleId:e.customRoleId,scopeType:e.scopeType,scopeId:e.scopeId})),memberUserIdsToAdd:j.map(e=>e.userId),memberUserIdsToRemove:[...E]}),o.group.getById.invalidate(),o.group.listAll.invalidate(),S.create({title:`Group updated`,type:`success`}),a()}catch(e){let t=e instanceof Error?e.message:`Failed to save`;S.create({title:t,type:`error`})}finally{V(!1)}},re=e=>g(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),ie=e=>D(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),ae=(e,t)=>{M(n=>[...n,{userId:e,label:t}]),P(``),I(``)},$=Q.data,oe=new Set([...$?.members.map(e=>e.userId)??[],...j.map(e=>e.userId)]);return(0,Z.jsx)(w.Root,{open:i,onOpenChange:e=>{e.open||(U(),a())},size:`lg`,children:(0,Z.jsxs)(w.Content,{maxHeight:`90vh`,overflowY:`auto`,children:[(0,Z.jsx)(w.Header,{children:(0,Z.jsx)(w.Title,{children:e.name})}),(0,Z.jsx)(w.CloseTrigger,{}),(0,Z.jsx)(w.Body,{pb:6,children:Q.isLoading?(0,Z.jsx)(b,{}):$?(0,Z.jsxs)(z,{gap:5,align:`stretch`,children:[r&&!$.scimSource&&(0,Z.jsx)(k,{value:s,onChange:e=>u(e.target.value),placeholder:`Group name`,size:`md`}),(0,Z.jsxs)(A,{children:[(0,Z.jsx)(q,{scimSource:$.scimSource}),(0,Z.jsxs)(O,{fontSize:`sm`,color:`fg.muted`,children:[Math.max(0,$.members.length-E.size+j.length),` `,`members`]})]}),(0,Z.jsxs)(x,{children:[(0,Z.jsx)(O,{fontSize:`sm`,fontWeight:`semibold`,mb:3,children:`Access granted`}),$.bindings.length===0&&_.length===0?(0,Z.jsx)(O,{fontSize:`sm`,color:`fg.muted`,fontStyle:`italic`,children:`No access configured yet.`}):(0,Z.jsxs)(z,{gap:2,align:`stretch`,children:[$.bindings.map(e=>{let t=m.has(e.id);return(0,Z.jsxs)(A,{px:3,py:2,bg:`bg.muted`,borderRadius:`md`,fontSize:`sm`,opacity:t?.4:1,transition:`opacity 0.15s`,children:[(0,Z.jsx)(C,{colorPalette:J(e.role),size:`sm`,textDecoration:t?`line-through`:void 0,children:e.customRoleName??e.role}),(0,Z.jsx)(O,{color:`fg.muted`,children:`on`}),(0,Z.jsxs)(C,{colorPalette:`purple`,size:`sm`,textDecoration:t?`line-through`:void 0,children:[K(e.scopeType),` `,e.scopeName??e.scopeId]}),(0,Z.jsx)(R,{}),r&&(0,Z.jsx)(y,{size:`xs`,variant:`ghost`,color:t?`blue.500`:`fg.muted`,"aria-label":t?`Undo removal`:`Remove binding`,onClick:()=>re(e.id),children:(0,Z.jsx)(h,{size:14})})]},e.id)}),_.map((e,t)=>(0,Z.jsxs)(A,{px:3,py:2,bg:`bg.muted`,borderRadius:`md`,fontSize:`sm`,opacity:.7,children:[(0,Z.jsx)(C,{colorPalette:J(e.role),size:`sm`,children:e.customRoleName??e.role}),(0,Z.jsx)(O,{color:`fg.muted`,children:`on`}),(0,Z.jsxs)(C,{colorPalette:`purple`,size:`sm`,children:[K(e.scopeType),` `,e.scopeName??e.scopeId]}),(0,Z.jsx)(R,{}),(0,Z.jsx)(y,{size:`xs`,variant:`ghost`,color:`fg.muted`,"aria-label":`Undo add`,onClick:()=>v(e=>e.filter((e,n)=>n!==t)),children:(0,Z.jsx)(h,{size:14})})]},t))]}),r&&(0,Z.jsx)(Y,{ref:H,organizationId:t,onAdd:e=>v(t=>[...t,e])})]}),(0,Z.jsxs)(x,{children:[(0,Z.jsx)(O,{fontSize:`sm`,fontWeight:`semibold`,mb:3,children:`Members`}),$.scimSource&&(0,Z.jsxs)(x,{px:3,py:2,bg:`bg.muted`,borderRadius:`md`,mb:3,fontSize:`sm`,color:`fg.muted`,children:[`Membership managed by `,$.scimSource.toUpperCase(),` via SCIM.`]}),$.members.length===0&&j.length===0?(0,Z.jsx)(O,{fontSize:`sm`,color:`fg.muted`,fontStyle:`italic`,children:`No members yet.`}):(0,Z.jsxs)(Z.Fragment,{children:[$.members.map(e=>{let t=E.has(e.userId);return(0,Z.jsxs)(A,{py:1,fontSize:`sm`,opacity:t?.4:1,transition:`opacity 0.15s`,children:[(0,Z.jsx)(c,{name:e.name??e.email??`?`,size:`xs`}),(0,Z.jsx)(O,{flex:1,textDecoration:t?`line-through`:void 0,children:e.name??e.email}),r&&!$.scimSource&&(0,Z.jsx)(y,{size:`xs`,variant:`ghost`,color:t?`blue.500`:`fg.muted`,"aria-label":t?`Undo removal of ${e.name??e.email}`:`Mark ${e.name??e.email} for removal`,onClick:()=>ie(e.userId),children:(0,Z.jsx)(h,{size:14})})]},e.userId)}),j.map(e=>(0,Z.jsxs)(A,{py:1,fontSize:`sm`,opacity:.7,children:[(0,Z.jsx)(c,{name:e.label,size:`xs`}),(0,Z.jsx)(O,{flex:1,color:`green.600`,children:e.label}),(0,Z.jsx)(y,{size:`xs`,variant:`ghost`,color:`fg.muted`,"aria-label":`Undo adding ${e.label}`,onClick:()=>M(t=>t.filter(t=>t.userId!==e.userId)),children:(0,Z.jsx)(h,{size:14})})]},e.userId))]}),r&&!$.scimSource&&(()=>{let e=(ee.data?.members??[]).filter(e=>!oe.has(e.userId)).map(e=>({label:`${e.user.name??e.user.email} (${e.user.email})`,value:e.userId})).sort((e,t)=>e.label.localeCompare(t.label)),t=F?e.filter(e=>e.label.toLowerCase().includes(F.toLowerCase())):e,r=d({items:t});return(0,Z.jsxs)(A,{gap:2,mt:2,children:[(0,Z.jsxs)(l.Root,{collection:r,value:N?[N]:[],onValueChange:e=>P(e.value[0]??``),size:`sm`,flex:1,children:[(0,Z.jsx)(l.Trigger,{children:(0,Z.jsx)(l.ValueText,{placeholder:`Add member...`})}),(0,Z.jsxs)(l.Content,{children:[(0,Z.jsx)(x,{position:`sticky`,top:0,zIndex:1,bg:`bg`,pb:1,children:(0,Z.jsx)(T,{startElement:(0,Z.jsx)(n,{size:14}),startOffset:`2px`,width:`full`,children:(0,Z.jsx)(k,{size:`sm`,placeholder:`Search members...`,value:F,onChange:e=>I(e.target.value),onKeyDown:e=>e.stopPropagation()})})}),t.map(e=>(0,Z.jsx)(l.Item,{item:e,children:e.label},e.value))]})]}),(0,Z.jsx)(y,{size:`sm`,colorPalette:N?`blue`:void 0,disabled:!N,onClick:()=>{let t=e.find(e=>e.value===N);t&&ae(t.value,t.label)},children:`Add`})]})})()]})]}):null}),r&&(0,Z.jsxs)(w.Footer,{children:[(0,Z.jsx)(y,{variant:`outline`,onClick:()=>{U(),a()},children:`Cancel`}),(0,Z.jsx)(y,{colorPalette:`blue`,disabled:!G,loading:L,onClick:()=>void ne(),children:`Save`})]})]})})}function te(){let{organization:e,hasPermission:t}=V(),{isEnterprise:n}=H(),[c,l]=(0,X.useState)(null),[d,h]=(0,X.useState)(!1),[v,T]=(0,X.useState)(null),k=B.useContext(),R=B.group.delete.useMutation({onSuccess:()=>{S.create({title:`Group deleted`,type:`success`}),k.group.listAll.invalidate(),T(null)},onError:e=>S.create({title:e.message,type:`error`})}),G=B.group.listAll.useQuery({organizationId:e?.id??``},{enabled:!!e&&n}),Y=t(`organization:manage`);return e?n?(0,Z.jsxs)(U,{children:[(0,Z.jsxs)(z,{gap:6,width:`full`,align:`start`,children:[(0,Z.jsx)(A,{justify:`space-between`,width:`full`,children:(0,Z.jsxs)(z,{align:`start`,gap:1,children:[(0,Z.jsx)(D,{as:`h2`,children:`Groups`}),(0,Z.jsx)(O,{color:`fg.muted`,fontSize:`sm`,children:`Assign access to many people at once. SCIM-synced groups are managed by your identity provider.`})]})}),(0,Z.jsx)(E,{}),G.isLoading&&(0,Z.jsx)(b,{}),!G.isLoading&&(0,Z.jsx)(I,{width:`full`,overflow:`hidden`,children:(0,Z.jsx)(L,{paddingY:0,paddingX:0,children:(0,Z.jsxs)(m,{variant:`line`,size:`md`,width:`full`,children:[(0,Z.jsx)(s,{children:(0,Z.jsxs)(i,{children:[(0,Z.jsx)(g,{children:`Group`}),(0,Z.jsx)(g,{width:`120px`,children:`Source`}),(0,Z.jsx)(g,{textAlign:`right`,children:`Access`}),(0,Z.jsx)(g,{width:`80px`,textAlign:`right`,children:`Members`}),Y&&(0,Z.jsx)(g,{width:`48px`})]})}),(0,Z.jsxs)(o,{children:[(G.data??[]).map(e=>(0,Z.jsxs)(i,{cursor:`pointer`,onClick:()=>l(e),onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),l(e))},tabIndex:0,role:`button`,_hover:{bg:`bg.muted`},children:[(0,Z.jsx)(f,{fontWeight:`medium`,children:e.name}),(0,Z.jsx)(f,{children:(0,Z.jsx)(q,{scimSource:e.scimSource})}),(0,Z.jsx)(f,{children:(0,Z.jsxs)(z,{gap:1,align:`end`,children:[e.bindings.map((e,t)=>(0,Z.jsxs)(A,{gap:1,fontSize:`xs`,children:[(0,Z.jsx)(C,{colorPalette:J(e.role),size:`sm`,children:e.customRoleName??e.role}),(0,Z.jsx)(O,{color:`fg.muted`,children:`on`}),(0,Z.jsxs)(C,{colorPalette:`purple`,size:`sm`,children:[K(e.scopeType),` `,e.scopeName??e.scopeId]})]},t)),e.bindings.length===0&&(0,Z.jsx)(O,{fontSize:`xs`,color:`fg.subtle`,textAlign:`right`,children:`No access configured`})]})}),(0,Z.jsx)(f,{textAlign:`right`,children:(0,Z.jsx)(O,{fontSize:`sm`,color:`fg.muted`,children:e.memberCount})}),Y&&(0,Z.jsx)(f,{children:(0,Z.jsxs)(u.Root,{children:[(0,Z.jsx)(u.Trigger,{asChild:!0,children:(0,Z.jsx)(y,{variant:`ghost`,size:`xs`,"aria-label":`Actions for ${e.name}`,onClick:e=>e.stopPropagation(),children:(0,Z.jsx)(a,{size:16})})}),(0,Z.jsxs)(u.Content,{children:[(0,Z.jsx)(u.Item,{value:`edit`,onClick:t=>{t.stopPropagation(),l(e)},children:(0,Z.jsxs)(x,{display:`flex`,alignItems:`center`,gap:2,children:[(0,Z.jsx)(_,{size:14}),`Edit`]})}),(0,Z.jsx)(u.Item,{value:`delete`,color:`red.500`,onClick:t=>{t.stopPropagation(),T(e)},children:(0,Z.jsxs)(x,{display:`flex`,alignItems:`center`,gap:2,children:[(0,Z.jsx)(p,{size:14}),`Delete`]})})]})]})})]},e.id)),Y&&(0,Z.jsx)(i,{cursor:`pointer`,onClick:()=>h(!0),onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),h(!0))},tabIndex:0,role:`button`,_hover:{bg:`bg.muted`},color:`fg.muted`,children:(0,Z.jsx)(f,{colSpan:5,children:(0,Z.jsxs)(A,{gap:2,children:[(0,Z.jsx)(r,{size:14}),(0,Z.jsx)(O,{fontSize:`sm`,children:`Add manual group`})]})})})]})]})})})]}),c&&(0,Z.jsx)(ee,{group:c,organizationId:e.id,canManage:Y,open:!!c,onClose:()=>l(null)}),(0,Z.jsx)(Q,{organizationId:e.id,open:d,onClose:()=>h(!1)}),(0,Z.jsx)(w.Root,{open:!!v,onOpenChange:e=>{e.open||T(null)},children:(0,Z.jsxs)(w.Content,{maxWidth:`440px`,children:[(0,Z.jsx)(w.Header,{children:(0,Z.jsx)(w.Title,{children:`Delete group`})}),(0,Z.jsx)(w.CloseTrigger,{}),(0,Z.jsx)(w.Body,{children:(0,Z.jsx)(O,{fontSize:`sm`,children:v?.scimSource?`This SCIM group will be re-created by your IdP on next sync. Delete anyway?`:`Delete "${v?.name}" and all its access rules?`})}),(0,Z.jsxs)(w.Footer,{children:[(0,Z.jsx)(y,{variant:`outline`,onClick:()=>T(null),children:`Cancel`}),(0,Z.jsx)(y,{colorPalette:`red`,loading:R.isPending,onClick:()=>v&&R.mutate({organizationId:e.id,groupId:v.id}),children:`Delete`})]})]})})]}):(0,Z.jsx)(U,{children:(0,Z.jsxs)(z,{gap:6,align:`start`,width:`full`,children:[(0,Z.jsxs)(M,{status:`info`,children:[(0,Z.jsx)(P,{}),(0,Z.jsxs)(F,{children:[(0,Z.jsx)(j,{children:`Enterprise Feature`}),(0,Z.jsx)(N,{children:`Groups are available on Enterprise plans. Contact sales to upgrade.`})]})]}),(0,Z.jsx)(x,{width:`full`,children:(0,Z.jsx)(W,{})})]})}):(0,Z.jsx)(U,{})}var ne=G(`organization:view`,{layoutComponent:U})(te);export{ne as default};
2
+ //# sourceMappingURL=groups-Bp90ChP3.js.map