@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{Fa as n,Q as r,Ra as i,Ss as a,Xa as o,Xr as s,Z as c,_s as l,bs as u,cc as d,fo as f,ho as p,m,na as h,qi as g,sc as _,vs as v,wa as y,xs as b,ya as x,yo as S,ys as C}from"./command-bar-CaJygoez.js";import{j as w,n as T,r as E}from"./stack-oJ9iWdbl.js";import{t as D}from"./box-BsM8YLGl.js";import{n as O}from"./toaster-C_DYALhL.js";import{an as k,f as A}from"./dist-SwV3YZv3.js";import{t as j}from"./heading-D90dlSnH.js";import{t as M}from"./text-CwTrMF8x.js";import{n as N}from"./code-FF_ibTVI.js";import{a as ee,r as P,t as te}from"./field-CnUiixMS.js";import{t as F}from"./input-C7emsUCL.js";import{t as I}from"./h-stack-BKLDJ2vg.js";import{r as ne,t as re}from"./card-CMtKVPVl.js";import{Pt as L}from"./lu-Bf6j_N19.js";import{t as R}from"./link-CwZhwOLq.js";import{t as z}from"./spacer-2LJJGbo8.js";import{t as B}from"./v-stack-EOPQ57OZ.js";import{t as ie}from"./posthogErrorCapture-50j08Hs1.js";import{c as ae,m as V,s as H}from"./auth-client-D3UhxhQi.js";import{t as oe}from"./usePublicEnv-1QvVAhAk.js";import"./next-router-C6sliiV7.js";import{c as U,t as se}from"./useOrganizationTeamProject-DC0iozx2.js";import{r as ce}from"./useRequiredSession-DE4JSglk.js";import{l as W,o as le,s as ue,t as G}from"./index.esm-X7lxUoP1.js";import{t as de}from"./createLucideIcon-BJKFyRLS.js";import{t as K}from"./SettingsLayout-CLCGxMAe.js";import{t as fe}from"./WithPermissionGuard-DD8uo3UK.js";import{i as q,r as J,t as pe}from"./GroupBindingInputRow-DebZBCnD.js";var Y=de(`mail`,[[`path`,{d:`m22 7-8.991 5.727a2 2 0 0 1-2.009 0L2 7`,key:`132q7q`}],[`rect`,{x:`2`,y:`4`,width:`20`,height:`16`,rx:`2`,key:`izxlao`}]]),X=U(),Z=e(t()),Q=w();function me({teamOptions:e,organizationId:t,onSubmit:r,isLoading:i=!1,hasEmailProvider:o=!1,onClose:s,onCloseText:c=`Cancel`,isInviterAdmin:d=!0}){let{register:f,control:p,handleSubmit:m,setValue:h,formState:{errors:g}}=ue({defaultValues:{emailsRaw:``,orgRole:X.OrganizationUserRole.MEMBER,teams:e.length>0?[{teamId:e[0]?.value??``,role:X.TeamUserRole.MEMBER}]:[]}}),{fields:_,append:x,remove:w}=le({control:p,name:`teams`}),O=W({control:p,name:`teams`}),k=W({control:p,name:`orgRole`}),A=(0,Z.useRef)(k);(0,Z.useEffect)(()=>{A.current!==k&&O?.length>0&&O.forEach((e,t)=>{e&&(k===X.OrganizationUserRole.EXTERNAL?e.role!==X.TeamUserRole.VIEWER&&(h(`teams.${t}.role`,X.TeamUserRole.VIEWER),h(`teams.${t}.customRoleId`,void 0)):k===X.OrganizationUserRole.MEMBER&&e.role===X.TeamUserRole.VIEWER&&h(`teams.${t}.role`,X.TeamUserRole.MEMBER))}),A.current=k},[k,O,h]);let j=t=>{let n=O?.map((e,n)=>t!==void 0&&n===t?null:e?.teamId).filter(e=>!!e&&e!==``);return e.filter(e=>!n?.includes(e.value))},N=()=>{let e=j();e.length>0&&x({teamId:e[0]?.value??``,role:_e(k)})};return(0,Q.jsx)(`form`,{onSubmit:m(e=>{let t=e.emailsRaw.split(/[\s,;]+/).map(e=>e.trim()).filter(Boolean),n=e.teams.map(t=>e.orgRole===X.OrganizationUserRole.EXTERNAL?{teamId:t.teamId,role:X.TeamUserRole.VIEWER,customRoleId:void 0}:e.orgRole===X.OrganizationUserRole.MEMBER&&t.role===X.TeamUserRole.VIEWER?{...t,role:X.TeamUserRole.MEMBER,customRoleId:void 0}:t);return r({invites:t.map(t=>({email:t,orgRole:e.orgRole,teams:n}))})}),children:(0,Q.jsxs)(B,{align:`start`,gap:4,width:`100%`,children:[(0,Q.jsxs)(I,{gap:4,align:`start`,width:`full`,children:[(0,Q.jsxs)(ee,{flex:`2`,invalid:!!g.emailsRaw,children:[(0,Q.jsx)(P,{children:`Email addresses`}),(0,Q.jsx)(F,{placeholder:`alice@example.com, bob@example.com`,...f(`emailsRaw`,{required:`At least one email is required`,validate:e=>{let t=e.split(/[\s,;]+/).map(e=>e.trim()).filter(Boolean);if(t.length===0)return`At least one email is required`;let n=t.find(e=>!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e));return n?`Invalid email: ${n}`:!0}})}),(0,Q.jsx)(te,{children:g.emailsRaw?.message})]}),(0,Q.jsx)(D,{flex:`1`,pt:`28px`,children:(0,Q.jsx)(G,{control:p,name:`orgRole`,render:({field:e})=>(0,Q.jsx)(S,{checked:e.value===X.OrganizationUserRole.EXTERNAL,onChange:t=>e.onChange(t.target.checked?X.OrganizationUserRole.EXTERNAL:X.OrganizationUserRole.MEMBER),alignItems:`flex-start`,children:(0,Q.jsxs)(B,{align:`start`,gap:0,children:[(0,Q.jsx)(M,{fontSize:`sm`,fontWeight:`medium`,lineHeight:`short`,children:`Lite Member`}),(0,Q.jsx)(M,{fontSize:`xs`,color:`fg.muted`,children:`Can only view projects they are invited to, cannot see costs`})]})})})})]}),_.length>0&&(0,Q.jsxs)(B,{align:`start`,gap:2,width:`100%`,children:[(0,Q.jsxs)(I,{justify:`space-between`,width:`100%`,children:[(0,Q.jsx)(M,{fontSize:`sm`,fontWeight:`medium`,color:`fg`,children:`Team Assignments`}),(0,Q.jsxs)(T,{type:`button`,size:`sm`,variant:`ghost`,onClick:N,disabled:j().length===0,children:[(0,Q.jsx)(n,{size:14}),` Add team`]})]}),(0,Q.jsx)(D,{paddingX:4,paddingY:3,backgroundColor:`bg.muted`,borderRadius:`xl`,width:`100%`,children:(0,Q.jsxs)(b,{variant:`ghost`,width:`100%`,children:[(0,Q.jsx)(u,{children:(0,Q.jsxs)(a,{backgroundColor:`transparent`,children:[(0,Q.jsx)(C,{paddingLeft:0,paddingTop:0,children:`Team`}),(0,Q.jsx)(C,{paddingLeft:0,paddingTop:0,children:`Role`}),(0,Q.jsx)(C,{paddingLeft:0,paddingRight:0,paddingTop:0,width:`50px`})]})}),(0,Q.jsx)(l,{children:_.map((e,n)=>(0,Q.jsxs)(a,{backgroundColor:`transparent`,children:[(0,Q.jsx)(v,{paddingLeft:0,children:(0,Q.jsx)(he,{teamIndex:n,control:p,getAvailableTeamOptions:j})}),(0,Q.jsx)(v,{paddingLeft:0,children:(0,Q.jsx)(ve,{teamIndex:n,control:p,organizationId:t,orgRole:k,setValue:h,isInviterAdmin:d})}),(0,Q.jsx)(v,{paddingLeft:0,paddingRight:0,paddingY:2,children:(0,Q.jsx)(T,{type:`button`,size:`sm`,colorPalette:`red`,variant:`ghost`,"aria-label":`Remove team assignment`,onClick:()=>w(n),children:(0,Q.jsx)(y,{size:16})})})]},e.id))})]})})]}),_.length===0&&(0,Q.jsx)(I,{gap:2,children:(0,Q.jsxs)(T,{type:`button`,size:`sm`,variant:`outline`,onClick:N,disabled:j().length===0,children:[(0,Q.jsx)(n,{size:14}),` Add team`]})}),(0,Q.jsxs)(I,{justify:`end`,width:`100%`,marginTop:4,children:[(0,Q.jsx)(T,{type:`button`,variant:`outline`,onClick:s,disabled:i,children:c}),(0,Q.jsx)(T,{colorPalette:i?`gray`:`orange`,type:`submit`,disabled:i,children:(0,Q.jsxs)(I,{children:[i?(0,Q.jsx)(E,{size:`sm`}):(0,Q.jsx)(Y,{size:18}),(0,Q.jsx)(M,{children:o?`Send invites`:`Create invites`})]})})]})]})})}function he({teamIndex:e,control:t,getAvailableTeamOptions:n}){let r=n(e),i=(0,Z.useMemo)(()=>_({items:r}),[r]);return(0,Q.jsx)(G,{control:t,name:`teams.${e}.teamId`,rules:{required:`Team is required`},render:({field:e})=>(0,Q.jsxs)(h.Root,{collection:i,value:[e.value],onValueChange:t=>{let n=t.value[0];n&&e.onChange(n)},children:[(0,Q.jsx)(h.Trigger,{background:`bg`,width:`full`,children:(0,Q.jsx)(h.ValueText,{placeholder:`Select team`})}),(0,Q.jsx)(h.Content,{paddingY:2,children:r.map(e=>(0,Q.jsx)(h.Item,{item:e,children:e.label},e.value))})]})})}function ge(e,t,n){let i=Object.values(r),a=t.map(e=>({label:e.name,value:`custom:${e.id}`,description:e.description??`Custom role`,isCustom:!0,customRoleId:e.id}));return e===X.OrganizationUserRole.EXTERNAL?[r.VIEWER]:e===X.OrganizationUserRole.MEMBER?n?[...i.filter(e=>e.value!==X.TeamUserRole.VIEWER),...a]:[r.MEMBER]:[...i,...a]}function _e(e){return e===X.OrganizationUserRole.EXTERNAL?X.TeamUserRole.VIEWER:X.TeamUserRole.MEMBER}function ve({teamIndex:e,control:t,organizationId:n,orgRole:r,setValue:i,isInviterAdmin:a}){let o=H.role.getAll.useQuery({organizationId:n}),s=(0,Z.useMemo)(()=>ge(r,o.data??[],a),[r,o.data,a]),l=(0,Z.useMemo)(()=>_({items:s}),[s]);return(0,Q.jsx)(G,{control:t,name:`teams.${e}.role`,render:({field:t})=>(0,Q.jsxs)(h.Root,{collection:l,value:[t.value],onValueChange:n=>{let r=n.value[0];r&&(t.onChange(r),r.startsWith(`custom:`)?i(`teams.${e}.customRoleId`,r.replace(`custom:`,``)):i(`teams.${e}.customRoleId`,void 0))},disabled:o.isLoading,children:[(0,Q.jsx)(h.Trigger,{background:`bg`,width:`full`,children:(0,Q.jsx)(h.ValueText,{placeholder:`Select role`})}),(0,Q.jsx)(h.Content,{paddingY:2,width:`320px`,children:s.map(e=>(0,Q.jsx)(h.Item,{item:e,children:(0,Q.jsx)(c,{option:e})},e.value))})]})})}var $=[{label:`Admin`,value:X.OrganizationUserRole.ADMIN,description:`Can manage organization and add or remove members`},{label:`Member`,value:X.OrganizationUserRole.MEMBER,description:`Can manage their own projects and view other projects`},{label:`Lite Member`,value:X.OrganizationUserRole.EXTERNAL,description:`Can only view projects they are invited to, cannot see costs`}];function ye({value:e,onChange:t}){let n=(0,Z.useMemo)(()=>_({items:$}),[]);return(0,Q.jsx)(B,{align:`start`,children:(0,Q.jsx)(I,{gap:6,children:(0,Q.jsxs)(h.Root,{collection:n,value:[e],onValueChange:e=>{let n=e.value[0];n&&t(n)},children:[(0,Q.jsx)(h.Trigger,{width:`200px`,children:(0,Q.jsx)(h.ValueText,{placeholder:`Select role`})}),(0,Q.jsx)(h.Content,{width:`320px`,paddingY:2,children:$.map(e=>(0,Q.jsx)(h.Item,{item:e,children:(0,Q.jsxs)(B,{align:`start`,gap:0,flex:1,children:[(0,Q.jsx)(M,{children:e.label}),(0,Q.jsx)(M,{color:`fg.muted`,fontSize:`13px`,children:e.description})]})},e.value))})]})})})}function be({member:e,organizationId:t,canManage:n,isCurrentUser:r,open:i,onClose:a}){let o=H.useContext(),[s,c]=(0,Z.useState)(e.role),[l,u]=(0,Z.useState)(new Set),[d,f]=(0,Z.useState)([]),[p,m]=(0,Z.useState)(!1),h=(0,Z.useRef)(null),g=()=>{c(e.role),u(new Set),f([])};(0,Z.useEffect)(()=>{i&&g()},[i,e.userId]);let _=H.roleBinding.listForUser.useQuery({organizationId:t,userId:e.userId},{enabled:i&&n}),v=H.group.listForMember.useQuery({organizationId:t,userId:e.userId},{enabled:i}),y=H.organization.updateMemberRole.useMutation(),b=H.roleBinding.applyMemberBindings.useMutation(),S=l.size>0||d.length>0,C=s!==e.role,w=S||C,j=async()=>{let n=h.current?.flush()??null,r=n?[...d,n]:d,i=l.size>0||r.length>0;m(!0);try{C&&await y.mutateAsync({organizationId:t,userId:e.userId,role:s}),i&&await b.mutateAsync({organizationId:t,userId:e.userId,bindingIdsToDelete:[...l],bindingsToCreate:r.map(e=>({role:e.role,customRoleId:e.customRoleId,scopeType:e.scopeType,scopeId:e.scopeId}))}),await Promise.all([o.roleBinding.listForUser.invalidate(),o.roleBinding.listForOrg.invalidate(),o.organization.getOrganizationWithMembersAndTheirTeams.invalidate(),o.organization.getAll.invalidate()]),O.create({title:`Member updated`,type:`success`}),a()}catch(e){let t=e instanceof Error?e.message:`Failed to save`;O.create({title:t,type:`error`})}finally{m(!1)}},N=_.data??[];return(0,Q.jsx)(A.Root,{open:i,onOpenChange:e=>{e.open||(g(),a())},size:`lg`,children:(0,Q.jsxs)(A.Content,{maxHeight:`90vh`,overflowY:`auto`,children:[(0,Q.jsx)(A.Header,{children:(0,Q.jsx)(A.Title,{children:e.user.name??e.user.email})}),(0,Q.jsx)(A.CloseTrigger,{}),(0,Q.jsx)(A.Body,{pb:6,children:(0,Q.jsxs)(B,{gap:5,align:`stretch`,children:[n&&(0,Q.jsxs)(D,{children:[(0,Q.jsx)(M,{fontSize:`sm`,fontWeight:`semibold`,mb:3,children:`Organization role`}),r?(0,Q.jsx)(M,{fontSize:`sm`,color:`fg.muted`,fontStyle:`italic`,children:`You cannot change your own organization role.`}):(0,Q.jsx)(ye,{value:s,onChange:c})]}),n&&(0,Q.jsxs)(D,{children:[(0,Q.jsx)(M,{fontSize:`sm`,fontWeight:`semibold`,mb:3,children:`Access`}),_.isLoading?(0,Q.jsx)(E,{size:`sm`}):N.length===0&&d.length===0?(0,Q.jsx)(M,{fontSize:`sm`,color:`fg.muted`,fontStyle:`italic`,children:`No access configured.`}):(0,Q.jsxs)(B,{gap:2,align:`stretch`,children:[N.map(e=>{let t=l.has(e.id);return(0,Q.jsxs)(I,{px:3,py:2,bg:`bg.muted`,borderRadius:`md`,fontSize:`sm`,opacity:t?.4:1,transition:`opacity 0.15s`,children:[(0,Q.jsx)(k,{colorPalette:J(e.role),size:`sm`,textDecoration:t?`line-through`:void 0,children:e.customRoleName??e.role}),(0,Q.jsx)(M,{color:`fg.muted`,children:`on`}),(0,Q.jsxs)(k,{colorPalette:`purple`,size:`sm`,textDecoration:t?`line-through`:void 0,children:[q(e.scopeType),` `,e.scopeName??e.scopeId]}),(0,Q.jsx)(z,{}),e.scopeType!==X.RoleBindingScopeType.PROJECT&&(0,Q.jsx)(T,{size:`xs`,variant:`ghost`,color:t?`blue.500`:`fg.muted`,"aria-label":t?`Undo removal`:`Remove binding`,onClick:()=>u(t=>{let n=new Set(t);return n.has(e.id)?n.delete(e.id):n.add(e.id),n}),children:(0,Q.jsx)(x,{size:14})})]},e.id)}),d.map((e,t)=>(0,Q.jsxs)(I,{px:3,py:2,bg:`bg.muted`,borderRadius:`md`,fontSize:`sm`,opacity:.7,children:[(0,Q.jsx)(k,{colorPalette:J(e.role),size:`sm`,children:e.customRoleName??e.role}),(0,Q.jsx)(M,{color:`fg.muted`,children:`on`}),(0,Q.jsxs)(k,{colorPalette:`purple`,size:`sm`,children:[q(e.scopeType),` `,e.scopeName??e.scopeId]}),(0,Q.jsx)(z,{}),(0,Q.jsx)(T,{size:`xs`,variant:`ghost`,color:`fg.muted`,"aria-label":`Undo add`,onClick:()=>f(e=>e.filter((e,n)=>n!==t)),children:(0,Q.jsx)(x,{size:14})})]},t))]}),(0,Q.jsx)(pe,{ref:h,organizationId:t,onAdd:e=>f(t=>[...t,e])})]}),(0,Q.jsxs)(D,{children:[(0,Q.jsx)(M,{fontSize:`sm`,fontWeight:`semibold`,mb:3,children:`Group access`}),v.isLoading?(0,Q.jsx)(E,{size:`sm`}):v.data?.length?(0,Q.jsx)(B,{gap:2,align:`stretch`,children:v.data.map(e=>e.bindings.length===0?(0,Q.jsxs)(I,{px:3,py:2,bg:`bg.muted`,borderRadius:`md`,fontSize:`sm`,justifyContent:`space-between`,children:[(0,Q.jsx)(M,{fontSize:`sm`,color:`fg.muted`,children:e.name}),(0,Q.jsx)(R,{href:`/settings/groups`,fontSize:`xs`,color:`blue.400`,children:`No access configured`})]},e.id):e.bindings.map(t=>(0,Q.jsxs)(I,{px:3,py:2,bg:`bg.muted`,borderRadius:`md`,fontSize:`sm`,children:[(0,Q.jsx)(k,{colorPalette:J(t.role),size:`sm`,children:t.customRoleName??t.role}),(0,Q.jsx)(M,{color:`fg.muted`,children:`on`}),(0,Q.jsxs)(k,{colorPalette:`purple`,size:`sm`,children:[q(t.scopeType),` `,t.scopeName??`—`]}),(0,Q.jsx)(z,{}),(0,Q.jsxs)(M,{fontSize:`xs`,color:`fg.muted`,children:[`via `,e.name]})]},t.id)))}):(0,Q.jsx)(M,{fontSize:`sm`,color:`fg.muted`,fontStyle:`italic`,children:`Not a member of any groups.`})]})]})}),n&&(0,Q.jsxs)(A.Footer,{children:[(0,Q.jsx)(T,{variant:`outline`,onClick:()=>{g(),a()},children:`Cancel`}),(0,Q.jsx)(T,{colorPalette:`blue`,disabled:!w,loading:p,onClick:()=>void j(),children:`Save`})]})]})})}function xe({isAdmin:e,inviteId:t,onApprove:n,onReject:r}){return e?(0,Q.jsxs)(I,{gap:2,children:[(0,Q.jsx)(L,{"aria-label":`Approve`,variant:`ghost`,size:`sm`,color:`green.500`,onClick:()=>n(t),children:(0,Q.jsx)(N,{size:16})}),(0,Q.jsx)(L,{"aria-label":`Reject`,variant:`ghost`,size:`sm`,color:`red.500`,onClick:()=>r(t),children:(0,Q.jsx)(x,{size:16})})]}):null}function Se({waitingApprovalInvites:e,sentInvites:t,isAdmin:n,currentUserId:r,teams:i,onApprove:s,onReject:c,onViewInviteLink:d,onDeleteInvite:f}){let m=(0,Z.useMemo)(()=>n?e:e.filter(e=>e.requestedBy===r),[e,n,r]),h=(0,Z.useMemo)(()=>[...m,...t],[m,t]);return h.length===0?null:(0,Q.jsxs)(B,{align:`start`,gap:4,paddingTop:4,width:`full`,children:[(0,Q.jsx)(j,{children:`Invites`}),(0,Q.jsx)(ne,{width:`full`,overflow:`hidden`,children:(0,Q.jsx)(re,{paddingY:0,paddingX:0,children:(0,Q.jsxs)(b,{variant:`line`,size:`md`,width:`full`,children:[(0,Q.jsx)(u,{children:(0,Q.jsxs)(a,{children:[(0,Q.jsx)(C,{width:`56px`}),(0,Q.jsx)(C,{children:`Email`}),(0,Q.jsx)(C,{children:`Status`}),(0,Q.jsx)(C,{children:`Role`}),(0,Q.jsx)(C,{children:`Teams`}),(0,Q.jsx)(C,{width:`60px`})]})}),(0,Q.jsx)(l,{children:h.map(e=>{let t=e.status===`WAITING_APPROVAL`,r=$.find(t=>t.value===e.role)?.label??e.role;return(0,Q.jsxs)(a,{children:[(0,Q.jsx)(v,{children:(0,Q.jsx)(p,{size:`2xs`,name:e.email})}),(0,Q.jsx)(v,{children:e.email}),(0,Q.jsx)(v,{children:t?(0,Q.jsx)(k,{size:`sm`,variant:`surface`,colorPalette:`orange`,children:`Pending Approval`}):(0,Q.jsx)(k,{size:`sm`,variant:`surface`,children:`Invited`})}),(0,Q.jsx)(v,{children:r}),(0,Q.jsx)(v,{children:(0,Q.jsx)(Ce,{teamIds:e.teamIds,teams:i})}),(0,Q.jsx)(v,{children:(0,Q.jsx)(D,{width:`full`,height:`full`,display:`flex`,justifyContent:`end`,children:t?(0,Q.jsx)(xe,{isAdmin:n,inviteId:e.id,onApprove:s,onReject:c}):(0,Q.jsxs)(g.Root,{children:[(0,Q.jsx)(g.Trigger,{asChild:!0,children:(0,Q.jsx)(L,{"aria-label":`Invite actions`,variant:`ghost`,size:`sm`,children:(0,Q.jsx)(o,{size:16})})}),(0,Q.jsxs)(g.Content,{children:[(0,Q.jsxs)(g.Item,{value:`view-link`,onClick:()=>d(e.inviteCode,e.email),children:[(0,Q.jsx)(Y,{size:16}),`View invite link`]}),n&&(0,Q.jsxs)(g.Item,{value:`delete`,color:`red.500`,onClick:()=>f(e.id),children:[(0,Q.jsx)(y,{size:16}),`Delete`]})]})]})})})]},e.id)})})]})})})]})}var Ce=({teamIds:e,teams:t})=>{if(!e)return null;let n=e.split(`,`).map(e=>e.trim()).filter(Boolean);return n.length===0?null:(0,Q.jsx)(I,{gap:2,flexWrap:`wrap`,children:n.map(e=>{let n=t.find(t=>t.id===e);return n?(0,Q.jsx)(R,{href:`/settings/teams/${n.slug}`,children:(0,Q.jsx)(k,{size:`sm`,variant:`surface`,children:n.name})},e):null})})};function we({organizationId:e,isAdmin:t,hasEmailProvider:n,onInviteCreated:r,onClose:i,refetchInvites:a,pricingModel:o,activePlanFree:s,activePlanType:c,activePlanSource:l}){let u=f(`members`),d=f(`membersLite`),p=ae(e=>e.openSeats),m=H.useContext(),h=()=>{m.licenseEnforcement.checkLimit.invalidate()},g=H.subscription?.addTeamMemberOrEvents?.useMutation(),_=H.organization.createInvites.useMutation(),v=H.organization.createInviteRequest.useMutation(),y=H.organization.approveInvite.useMutation(),b=H.organization.deleteInvite.useMutation(),x=t=>{_.mutate({organizationId:e,invites:t.invites.map(e=>({email:e.email.toLowerCase(),role:e.orgRole,teams:e.teams.map(e=>({teamId:e.teamId,role:e.role,customRoleId:e.customRoleId}))}))},{onSuccess:e=>{r(e.reduce((e,t)=>(t?.invite&&t.emailNotSent&&e.push({inviteCode:t.invite.inviteCode,email:t.invite.email}),e),[]));let t=e.filter(Boolean).length,o=n?`All invites have been sent.`:`All invites have been created. View invite link under actions menu.`;O.create({title:`${t>1?`Invites`:`Invite`} created successfully`,description:o,type:`success`,duration:2e3,meta:{closable:!0}}),i(),a(),h()},onError:e=>{V(e)||O.create({title:`Sorry, something went wrong`,description:e.message??`Please try that again`,type:`error`,duration:5e3,meta:{closable:!0}})}})},S=t=>{v.mutate({organizationId:e,invites:t.invites.map(e=>({email:e.email.toLowerCase(),role:e.orgRole===X.OrganizationUserRole.EXTERNAL?`EXTERNAL`:`MEMBER`,teams:e.teams.map(e=>({teamId:e.teamId,role:e.role,customRoleId:e.customRoleId}))}))},{onSuccess:()=>{let e=t.invites.length;O.create({title:e>1?`Invitations sent for approval`:`Invitation sent for approval`,description:`An admin will review your invitation request.`,type:`success`,duration:2e3,meta:{closable:!0}}),i(),a(),h()},onError:e=>{V(e)||O.create({title:`Sorry, something went wrong`,description:e.message??`Please try that again`,type:`error`,duration:5e3,meta:{closable:!0}})}})};return{onSubmit:n=>{let r=n.invites.some(e=>e.orgRole!==X.OrganizationUserRole.EXTERNAL),i=n.invites.some(e=>e.orgRole===X.OrganizationUserRole.EXTERNAL),a=n.invites.filter(e=>e.orgRole!==X.OrganizationUserRole.EXTERNAL).length,s=t?x:S,f=()=>{i?d.checkAndProceed(()=>s(n)):s(n)};if(!r){f();return}let m=u.limitInfo;if(!m){f();return}if(m.current+a<=m.max){f();return}if(l===`subscription`&&o===`SEAT_EVENT`&&g){let t=m.current+a;p({organizationId:e,currentSeats:m.max,newSeats:t,onConfirm:async()=>{try{await g.mutateAsync({organizationId:e,plan:c,upgradeMembers:!0,upgradeTraces:!1,totalMembers:t,totalTraces:0}),s(n)}catch(e){O.create({title:`Failed to expand seats`,description:e instanceof Error?e.message:`Please try again`,type:`error`,duration:5e3,meta:{closable:!0}})}}})}else u.checkAndProceed(()=>{})},approveInvite:t=>{y.mutate({inviteId:t,organizationId:e},{onSuccess:()=>{O.create({title:`Invitation approved`,description:`The invitation has been approved and sent.`,type:`success`,duration:5e3,meta:{closable:!0}}),a(),h()},onError:()=>{O.create({title:`Sorry, something went wrong`,description:`Please try that again`,type:`error`,duration:5e3,meta:{closable:!0}})}})},rejectInvite:t=>{b.mutate({inviteId:t,organizationId:e},{onSuccess:()=>{O.create({title:`Invitation rejected`,description:`The invitation request has been rejected.`,type:`success`,duration:5e3,meta:{closable:!0}}),a(),h()},onError:()=>{O.create({title:`Sorry, something went wrong`,description:`Please try that again`,type:`error`,duration:5e3,meta:{closable:!0}})}})},deleteInvite:t=>{b.mutate({inviteId:t,organizationId:e},{onSuccess:()=>{O.create({title:`Invite deleted successfully`,description:`The invite has been deleted.`,type:`success`,duration:5e3,meta:{closable:!0}}),a(),h()},onError:e=>{V(e)||O.create({title:`Sorry, something went wrong`,description:e.message??`Please try that again`,type:`error`,duration:5e3,meta:{closable:!0}})}})},isSubmitting:_.isLoading||v.isLoading}}function Te(){let{organization:e}=se(),t=H.organization.getOrganizationWithMembersAndTheirTeams.useQuery({organizationId:e?.id??``,includeDeactivated:!0},{enabled:!!e}),n=H.plan.getActivePlan.useQuery({organizationId:e?.id??``},{enabled:!!e});return!e||!t.data||!n.data?(0,Q.jsx)(K,{}):(0,Q.jsx)(De,{teams:e.teams,organization:t.data,activePlan:n.data})}var Ee=fe(`organization:view`,{layoutComponent:K})(Te);function De({organization:e,teams:t,activePlan:r}){let{data:c}=ce(),{hasPermission:f}=se(),h=f(`organization:manage`),_=c?.user,x=t.map(e=>({label:e.name,value:e.id})),S=H.useContext(),[w,E]=(0,Z.useState)(null),{open:N,onOpen:ee,onClose:P}=d(),{open:te,onOpen:F,onClose:L}=d(),R=H.organization.getOrganizationPendingInvites.useQuery({organizationId:e?.id??``},{enabled:!!e}),ae=H.organization.deleteMember.useMutation(),[V,U]=(0,Z.useState)([]);(0,Z.useEffect)(()=>{V.length>0&&F()},[V,F]);let W=oe().data?.HAS_EMAIL_PROVIDER_KEY,{onSubmit:le,approveInvite:ue,rejectInvite:G,deleteInvite:de,isSubmitting:fe}=we({organizationId:e.id,isAdmin:h,hasEmailProvider:W??!1,onInviteCreated:U,onClose:P,refetchInvites:()=>void R.refetch(),pricingModel:e.pricingModel,activePlanFree:r.free,activePlanType:r.type,activePlanSource:r.planSource}),q=t=>{ae.mutate({organizationId:e.id,userId:t},{onSuccess:()=>{O.create({title:`Member removed successfully`,description:`The member has been removed from the organization.`,type:`success`,duration:5e3,meta:{closable:!0}}),S.organization.getOrganizationWithMembersAndTheirTeams.invalidate().catch(n=>{ie(n,{tags:{userId:t,organizationId:e.id}})}),S.licenseEnforcement.checkLimit.invalidate()},onError:()=>{O.create({title:`Sorry, something went wrong`,description:`Please try that again`,type:`error`,duration:5e3,meta:{closable:!0}})}})},J=(e,t)=>{U([{inviteCode:e,email:t}]),F()},pe=()=>{U([]),L()},{data:Y,isLoading:X,isError:he}=H.roleBinding.listForOrg.useQuery({organizationId:e.id},{enabled:!!e.id&&h}),ge=(0,Z.useMemo)(()=>{let e=new Map;for(let t of Y??[]){t.userId&&(e.has(t.userId)||e.set(t.userId,[]),e.get(t.userId).push(t));for(let n of t.memberUserIds)e.has(n)||e.set(n,[]),e.get(n).push(t)}return e},[Y]),_e=(0,Z.useMemo)(()=>[...e.members].sort((e,t)=>(e.user.name??e.user.email??``).localeCompare(t.user.name??t.user.email??``)),[e.members]),ve=t=>h&&e.members.length>1&&t!==_?.id,$=(0,Z.useMemo)(()=>(R.data??[]).filter(e=>e.status===`PENDING`),[R.data]),ye=(0,Z.useMemo)(()=>(R.data??[]).filter(e=>e.status===`WAITING_APPROVAL`),[R.data]);return(0,Q.jsxs)(K,{children:[(0,Q.jsxs)(B,{gap:6,width:`full`,align:`start`,children:[(0,Q.jsxs)(I,{width:`full`,children:[(0,Q.jsx)(j,{children:`Organization Members`}),(0,Q.jsx)(z,{}),h&&(0,Q.jsxs)(s.HeaderButton,{onClick:ee,children:[(0,Q.jsx)(n,{size:20}),`Add members`]})]}),(0,Q.jsx)(ne,{width:`full`,overflow:`hidden`,children:(0,Q.jsx)(re,{paddingY:0,paddingX:0,children:(0,Q.jsxs)(b,{variant:`line`,size:`md`,width:`full`,children:[(0,Q.jsx)(u,{children:(0,Q.jsxs)(a,{children:[(0,Q.jsx)(C,{width:`56px`}),(0,Q.jsx)(C,{children:`Name`}),(0,Q.jsx)(C,{children:`Email`}),h&&(0,Q.jsx)(C,{textAlign:`right`,children:`Access`}),(0,Q.jsx)(C,{width:`60px`})]})}),(0,Q.jsx)(l,{children:_e.map(e=>(0,Q.jsxs)(a,{children:[(0,Q.jsx)(v,{children:(0,Q.jsx)(p,{size:`2xs`,name:e.user.name??``})}),(0,Q.jsx)(v,{children:(0,Q.jsxs)(I,{children:[(0,Q.jsx)(T,{variant:`plain`,size:`sm`,padding:0,height:`auto`,fontWeight:`normal`,color:`colorPalette.fg`,colorPalette:`blue`,onClick:()=>{E({userId:e.userId,role:e.role,user:{name:e.user.name??null,email:e.user.email??null}})},children:e.user.name}),e.role===`EXTERNAL`&&(0,Q.jsx)(k,{colorPalette:`gray`,size:`sm`,children:`Lite Member`}),e.user.deactivatedAt&&(0,Q.jsx)(k,{colorPalette:`red`,size:`sm`,children:`Deactivated`})]})}),(0,Q.jsx)(v,{children:e.user.email}),h&&(0,Q.jsx)(v,{children:(0,Q.jsx)(Ae,{bindings:ge.get(e.userId)??[],isLoading:X||he})}),(0,Q.jsx)(v,{children:(0,Q.jsx)(D,{width:`full`,height:`full`,display:`flex`,justifyContent:`end`,children:(0,Q.jsxs)(g.Root,{children:[(0,Q.jsx)(g.Trigger,{children:(0,Q.jsx)(o,{size:16})}),(0,Q.jsxs)(g.Content,{children:[(0,Q.jsxs)(g.Item,{value:`edit`,onClick:()=>{E({userId:e.userId,role:e.role,user:{name:e.user.name??null,email:e.user.email??null}})},children:[(0,Q.jsx)(i,{size:16}),`Edit`]}),ve(e.userId)&&(0,Q.jsxs)(g.Item,{value:`delete`,color:`red.500`,onClick:()=>q(e.userId),children:[(0,Q.jsx)(y,{size:16}),`Delete`]})]})]})})})]},e.userId))})]})})}),(0,Q.jsx)(Se,{waitingApprovalInvites:ye,sentInvites:$,isAdmin:h,currentUserId:_?.id??``,teams:t,onApprove:ue,onReject:G,onViewInviteLink:J,onDeleteInvite:de})]}),w&&(0,Q.jsx)(be,{member:w,organizationId:e.id,canManage:h,isCurrentUser:w.userId===_?.id,open:!!w,onClose:()=>E(null)}),(0,Q.jsx)(A.Root,{open:te,onOpenChange:({open:e})=>e?void 0:pe(),children:(0,Q.jsxs)(A.Content,{children:[(0,Q.jsx)(A.Header,{children:(0,Q.jsx)(A.Title,{children:(0,Q.jsx)(j,{children:`Invite Link`})})}),(0,Q.jsx)(A.CloseTrigger,{}),(0,Q.jsx)(A.Body,{paddingBottom:6,children:(0,Q.jsxs)(B,{align:`start`,gap:4,children:[(0,Q.jsx)(M,{children:`Send the link below to the users you want to invite to join the organization.`}),(0,Q.jsx)(B,{align:`start`,gap:4,width:`full`,children:V.map(e=>(0,Q.jsxs)(B,{align:`start`,gap:6,width:`full`,children:[(0,Q.jsx)(M,{fontWeight:`600`,children:e.email}),(0,Q.jsx)(m,{value:`${window.location.origin}/invite/accept?inviteCode=${e.inviteCode}`,label:`Invite Link`,marginTop:0})]},e.inviteCode))})]})})]})}),(0,Q.jsx)(A.Root,{open:N,onOpenChange:({open:e})=>e?ee():P(),children:(0,Q.jsxs)(A.Content,{width:`100%`,maxWidth:`1024px`,children:[(0,Q.jsx)(A.Header,{children:(0,Q.jsx)(A.Title,{children:(0,Q.jsx)(j,{children:`Add members`})})}),(0,Q.jsx)(A.CloseTrigger,{}),(0,Q.jsx)(A.Body,{children:(0,Q.jsx)(me,{teamOptions:x,organizationId:e.id,onSubmit:le,isLoading:fe,hasEmailProvider:W??!1,onClose:P,isInviterAdmin:h})})]})})]})}function Oe(e){return e===X.RoleBindingScopeType.ORGANIZATION?`🏢`:e===X.RoleBindingScopeType.TEAM?`👥`:`📁`}function ke(e){return e===`ADMIN`?`red`:e===`MEMBER`?`blue`:`gray`}function Ae({bindings:e,isLoading:t}){return t?(0,Q.jsx)(M,{fontSize:`xs`,color:`fg.subtle`,textAlign:`right`,children:`—`}):e.length===0?(0,Q.jsx)(M,{fontSize:`xs`,color:`fg.subtle`,textAlign:`right`,children:`No access configured`}):(0,Q.jsx)(B,{gap:1,align:`end`,children:e.map(e=>(0,Q.jsxs)(I,{gap:1,fontSize:`xs`,children:[(0,Q.jsx)(k,{colorPalette:ke(e.role),size:`sm`,children:e.customRoleName??e.role}),(0,Q.jsx)(M,{color:`fg.muted`,children:`on`}),(0,Q.jsxs)(k,{colorPalette:`purple`,size:`sm`,children:[Oe(e.scopeType),` `,e.scopeName??e.scopeId.slice(0,8)+`…`]}),e.groupId&&(0,Q.jsxs)(M,{color:`fg.subtle`,fontSize:`xs`,title:`via group: ${e.groupName??e.groupId}`,children:[`via `,e.groupName??`group`]})]},e.id))})}export{Ee as default};
2
- //# sourceMappingURL=members-lIFLh-rh.js.map
1
+ import{s as e}from"./chunk-Bj-mKKzh.js";import{t}from"./react-C7JcuhbW.js";import{Fa as n,Q as r,Ra as i,Ss as a,Xa as o,Xr as s,Z as c,_s as l,bs as u,cc as d,fo as f,ho as p,m,na as h,qi as g,sc as _,vs as v,wa as y,xs as b,ya as x,yo as S,ys as C}from"./command-bar-DUK45yin.js";import{j as w,n as T,r as E}from"./stack-oJ9iWdbl.js";import{t as D}from"./box-BsM8YLGl.js";import{n as O}from"./toaster-C_DYALhL.js";import{an as k,f as A}from"./dist-Cds4Mqhj.js";import{t as j}from"./heading-D90dlSnH.js";import{t as M}from"./text-CwTrMF8x.js";import{n as N}from"./code-FF_ibTVI.js";import{a as ee,r as P,t as te}from"./field-CnUiixMS.js";import{t as F}from"./input-C7emsUCL.js";import{t as I}from"./h-stack-BKLDJ2vg.js";import{r as ne,t as re}from"./card-CMtKVPVl.js";import{Pt as L}from"./lu-Bf6j_N19.js";import{t as R}from"./link-CwZhwOLq.js";import{t as z}from"./spacer-2LJJGbo8.js";import{t as B}from"./v-stack-EOPQ57OZ.js";import{t as ie}from"./posthogErrorCapture-50j08Hs1.js";import{c as ae,m as V,s as H}from"./auth-client-D3UhxhQi.js";import{t as oe}from"./usePublicEnv-1QvVAhAk.js";import"./next-router-C6sliiV7.js";import{c as U,t as se}from"./useOrganizationTeamProject-DC0iozx2.js";import{r as ce}from"./useRequiredSession-DE4JSglk.js";import{l as W,o as le,s as ue,t as G}from"./index.esm-X7lxUoP1.js";import{t as de}from"./createLucideIcon-BJKFyRLS.js";import{t as K}from"./SettingsLayout--1gdEuhv.js";import{t as fe}from"./WithPermissionGuard-B4Jo8E5-.js";import{i as q,r as J,t as pe}from"./GroupBindingInputRow-CV-fBkX9.js";var Y=de(`mail`,[[`path`,{d:`m22 7-8.991 5.727a2 2 0 0 1-2.009 0L2 7`,key:`132q7q`}],[`rect`,{x:`2`,y:`4`,width:`20`,height:`16`,rx:`2`,key:`izxlao`}]]),X=U(),Z=e(t()),Q=w();function me({teamOptions:e,organizationId:t,onSubmit:r,isLoading:i=!1,hasEmailProvider:o=!1,onClose:s,onCloseText:c=`Cancel`,isInviterAdmin:d=!0}){let{register:f,control:p,handleSubmit:m,setValue:h,formState:{errors:g}}=ue({defaultValues:{emailsRaw:``,orgRole:X.OrganizationUserRole.MEMBER,teams:e.length>0?[{teamId:e[0]?.value??``,role:X.TeamUserRole.MEMBER}]:[]}}),{fields:_,append:x,remove:w}=le({control:p,name:`teams`}),O=W({control:p,name:`teams`}),k=W({control:p,name:`orgRole`}),A=(0,Z.useRef)(k);(0,Z.useEffect)(()=>{A.current!==k&&O?.length>0&&O.forEach((e,t)=>{e&&(k===X.OrganizationUserRole.EXTERNAL?e.role!==X.TeamUserRole.VIEWER&&(h(`teams.${t}.role`,X.TeamUserRole.VIEWER),h(`teams.${t}.customRoleId`,void 0)):k===X.OrganizationUserRole.MEMBER&&e.role===X.TeamUserRole.VIEWER&&h(`teams.${t}.role`,X.TeamUserRole.MEMBER))}),A.current=k},[k,O,h]);let j=t=>{let n=O?.map((e,n)=>t!==void 0&&n===t?null:e?.teamId).filter(e=>!!e&&e!==``);return e.filter(e=>!n?.includes(e.value))},N=()=>{let e=j();e.length>0&&x({teamId:e[0]?.value??``,role:_e(k)})};return(0,Q.jsx)(`form`,{onSubmit:m(e=>{let t=e.emailsRaw.split(/[\s,;]+/).map(e=>e.trim()).filter(Boolean),n=e.teams.map(t=>e.orgRole===X.OrganizationUserRole.EXTERNAL?{teamId:t.teamId,role:X.TeamUserRole.VIEWER,customRoleId:void 0}:e.orgRole===X.OrganizationUserRole.MEMBER&&t.role===X.TeamUserRole.VIEWER?{...t,role:X.TeamUserRole.MEMBER,customRoleId:void 0}:t);return r({invites:t.map(t=>({email:t,orgRole:e.orgRole,teams:n}))})}),children:(0,Q.jsxs)(B,{align:`start`,gap:4,width:`100%`,children:[(0,Q.jsxs)(I,{gap:4,align:`start`,width:`full`,children:[(0,Q.jsxs)(ee,{flex:`2`,invalid:!!g.emailsRaw,children:[(0,Q.jsx)(P,{children:`Email addresses`}),(0,Q.jsx)(F,{placeholder:`alice@example.com, bob@example.com`,...f(`emailsRaw`,{required:`At least one email is required`,validate:e=>{let t=e.split(/[\s,;]+/).map(e=>e.trim()).filter(Boolean);if(t.length===0)return`At least one email is required`;let n=t.find(e=>!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e));return n?`Invalid email: ${n}`:!0}})}),(0,Q.jsx)(te,{children:g.emailsRaw?.message})]}),(0,Q.jsx)(D,{flex:`1`,pt:`28px`,children:(0,Q.jsx)(G,{control:p,name:`orgRole`,render:({field:e})=>(0,Q.jsx)(S,{checked:e.value===X.OrganizationUserRole.EXTERNAL,onChange:t=>e.onChange(t.target.checked?X.OrganizationUserRole.EXTERNAL:X.OrganizationUserRole.MEMBER),alignItems:`flex-start`,children:(0,Q.jsxs)(B,{align:`start`,gap:0,children:[(0,Q.jsx)(M,{fontSize:`sm`,fontWeight:`medium`,lineHeight:`short`,children:`Lite Member`}),(0,Q.jsx)(M,{fontSize:`xs`,color:`fg.muted`,children:`Can only view projects they are invited to, cannot see costs`})]})})})})]}),_.length>0&&(0,Q.jsxs)(B,{align:`start`,gap:2,width:`100%`,children:[(0,Q.jsxs)(I,{justify:`space-between`,width:`100%`,children:[(0,Q.jsx)(M,{fontSize:`sm`,fontWeight:`medium`,color:`fg`,children:`Team Assignments`}),(0,Q.jsxs)(T,{type:`button`,size:`sm`,variant:`ghost`,onClick:N,disabled:j().length===0,children:[(0,Q.jsx)(n,{size:14}),` Add team`]})]}),(0,Q.jsx)(D,{paddingX:4,paddingY:3,backgroundColor:`bg.muted`,borderRadius:`xl`,width:`100%`,children:(0,Q.jsxs)(b,{variant:`ghost`,width:`100%`,children:[(0,Q.jsx)(u,{children:(0,Q.jsxs)(a,{backgroundColor:`transparent`,children:[(0,Q.jsx)(C,{paddingLeft:0,paddingTop:0,children:`Team`}),(0,Q.jsx)(C,{paddingLeft:0,paddingTop:0,children:`Role`}),(0,Q.jsx)(C,{paddingLeft:0,paddingRight:0,paddingTop:0,width:`50px`})]})}),(0,Q.jsx)(l,{children:_.map((e,n)=>(0,Q.jsxs)(a,{backgroundColor:`transparent`,children:[(0,Q.jsx)(v,{paddingLeft:0,children:(0,Q.jsx)(he,{teamIndex:n,control:p,getAvailableTeamOptions:j})}),(0,Q.jsx)(v,{paddingLeft:0,children:(0,Q.jsx)(ve,{teamIndex:n,control:p,organizationId:t,orgRole:k,setValue:h,isInviterAdmin:d})}),(0,Q.jsx)(v,{paddingLeft:0,paddingRight:0,paddingY:2,children:(0,Q.jsx)(T,{type:`button`,size:`sm`,colorPalette:`red`,variant:`ghost`,"aria-label":`Remove team assignment`,onClick:()=>w(n),children:(0,Q.jsx)(y,{size:16})})})]},e.id))})]})})]}),_.length===0&&(0,Q.jsx)(I,{gap:2,children:(0,Q.jsxs)(T,{type:`button`,size:`sm`,variant:`outline`,onClick:N,disabled:j().length===0,children:[(0,Q.jsx)(n,{size:14}),` Add team`]})}),(0,Q.jsxs)(I,{justify:`end`,width:`100%`,marginTop:4,children:[(0,Q.jsx)(T,{type:`button`,variant:`outline`,onClick:s,disabled:i,children:c}),(0,Q.jsx)(T,{colorPalette:i?`gray`:`orange`,type:`submit`,disabled:i,children:(0,Q.jsxs)(I,{children:[i?(0,Q.jsx)(E,{size:`sm`}):(0,Q.jsx)(Y,{size:18}),(0,Q.jsx)(M,{children:o?`Send invites`:`Create invites`})]})})]})]})})}function he({teamIndex:e,control:t,getAvailableTeamOptions:n}){let r=n(e),i=(0,Z.useMemo)(()=>_({items:r}),[r]);return(0,Q.jsx)(G,{control:t,name:`teams.${e}.teamId`,rules:{required:`Team is required`},render:({field:e})=>(0,Q.jsxs)(h.Root,{collection:i,value:[e.value],onValueChange:t=>{let n=t.value[0];n&&e.onChange(n)},children:[(0,Q.jsx)(h.Trigger,{background:`bg`,width:`full`,children:(0,Q.jsx)(h.ValueText,{placeholder:`Select team`})}),(0,Q.jsx)(h.Content,{paddingY:2,children:r.map(e=>(0,Q.jsx)(h.Item,{item:e,children:e.label},e.value))})]})})}function ge(e,t,n){let i=Object.values(r),a=t.map(e=>({label:e.name,value:`custom:${e.id}`,description:e.description??`Custom role`,isCustom:!0,customRoleId:e.id}));return e===X.OrganizationUserRole.EXTERNAL?[r.VIEWER]:e===X.OrganizationUserRole.MEMBER?n?[...i.filter(e=>e.value!==X.TeamUserRole.VIEWER),...a]:[r.MEMBER]:[...i,...a]}function _e(e){return e===X.OrganizationUserRole.EXTERNAL?X.TeamUserRole.VIEWER:X.TeamUserRole.MEMBER}function ve({teamIndex:e,control:t,organizationId:n,orgRole:r,setValue:i,isInviterAdmin:a}){let o=H.role.getAll.useQuery({organizationId:n}),s=(0,Z.useMemo)(()=>ge(r,o.data??[],a),[r,o.data,a]),l=(0,Z.useMemo)(()=>_({items:s}),[s]);return(0,Q.jsx)(G,{control:t,name:`teams.${e}.role`,render:({field:t})=>(0,Q.jsxs)(h.Root,{collection:l,value:[t.value],onValueChange:n=>{let r=n.value[0];r&&(t.onChange(r),r.startsWith(`custom:`)?i(`teams.${e}.customRoleId`,r.replace(`custom:`,``)):i(`teams.${e}.customRoleId`,void 0))},disabled:o.isLoading,children:[(0,Q.jsx)(h.Trigger,{background:`bg`,width:`full`,children:(0,Q.jsx)(h.ValueText,{placeholder:`Select role`})}),(0,Q.jsx)(h.Content,{paddingY:2,width:`320px`,children:s.map(e=>(0,Q.jsx)(h.Item,{item:e,children:(0,Q.jsx)(c,{option:e})},e.value))})]})})}var $=[{label:`Admin`,value:X.OrganizationUserRole.ADMIN,description:`Can manage organization and add or remove members`},{label:`Member`,value:X.OrganizationUserRole.MEMBER,description:`Can manage their own projects and view other projects`},{label:`Lite Member`,value:X.OrganizationUserRole.EXTERNAL,description:`Can only view projects they are invited to, cannot see costs`}];function ye({value:e,onChange:t}){let n=(0,Z.useMemo)(()=>_({items:$}),[]);return(0,Q.jsx)(B,{align:`start`,children:(0,Q.jsx)(I,{gap:6,children:(0,Q.jsxs)(h.Root,{collection:n,value:[e],onValueChange:e=>{let n=e.value[0];n&&t(n)},children:[(0,Q.jsx)(h.Trigger,{width:`200px`,children:(0,Q.jsx)(h.ValueText,{placeholder:`Select role`})}),(0,Q.jsx)(h.Content,{width:`320px`,paddingY:2,children:$.map(e=>(0,Q.jsx)(h.Item,{item:e,children:(0,Q.jsxs)(B,{align:`start`,gap:0,flex:1,children:[(0,Q.jsx)(M,{children:e.label}),(0,Q.jsx)(M,{color:`fg.muted`,fontSize:`13px`,children:e.description})]})},e.value))})]})})})}function be({member:e,organizationId:t,canManage:n,isCurrentUser:r,open:i,onClose:a}){let o=H.useContext(),[s,c]=(0,Z.useState)(e.role),[l,u]=(0,Z.useState)(new Set),[d,f]=(0,Z.useState)([]),[p,m]=(0,Z.useState)(!1),h=(0,Z.useRef)(null),g=()=>{c(e.role),u(new Set),f([])};(0,Z.useEffect)(()=>{i&&g()},[i,e.userId]);let _=H.roleBinding.listForUser.useQuery({organizationId:t,userId:e.userId},{enabled:i&&n}),v=H.group.listForMember.useQuery({organizationId:t,userId:e.userId},{enabled:i}),y=H.organization.updateMemberRole.useMutation(),b=H.roleBinding.applyMemberBindings.useMutation(),S=l.size>0||d.length>0,C=s!==e.role,w=S||C,j=async()=>{let n=h.current?.flush()??null,r=n?[...d,n]:d,i=l.size>0||r.length>0;m(!0);try{C&&await y.mutateAsync({organizationId:t,userId:e.userId,role:s}),i&&await b.mutateAsync({organizationId:t,userId:e.userId,bindingIdsToDelete:[...l],bindingsToCreate:r.map(e=>({role:e.role,customRoleId:e.customRoleId,scopeType:e.scopeType,scopeId:e.scopeId}))}),await Promise.all([o.roleBinding.listForUser.invalidate(),o.roleBinding.listForOrg.invalidate(),o.organization.getOrganizationWithMembersAndTheirTeams.invalidate(),o.organization.getAll.invalidate()]),O.create({title:`Member updated`,type:`success`}),a()}catch(e){let t=e instanceof Error?e.message:`Failed to save`;O.create({title:t,type:`error`})}finally{m(!1)}},N=_.data??[];return(0,Q.jsx)(A.Root,{open:i,onOpenChange:e=>{e.open||(g(),a())},size:`lg`,children:(0,Q.jsxs)(A.Content,{maxHeight:`90vh`,overflowY:`auto`,children:[(0,Q.jsx)(A.Header,{children:(0,Q.jsx)(A.Title,{children:e.user.name??e.user.email})}),(0,Q.jsx)(A.CloseTrigger,{}),(0,Q.jsx)(A.Body,{pb:6,children:(0,Q.jsxs)(B,{gap:5,align:`stretch`,children:[n&&(0,Q.jsxs)(D,{children:[(0,Q.jsx)(M,{fontSize:`sm`,fontWeight:`semibold`,mb:3,children:`Organization role`}),r?(0,Q.jsx)(M,{fontSize:`sm`,color:`fg.muted`,fontStyle:`italic`,children:`You cannot change your own organization role.`}):(0,Q.jsx)(ye,{value:s,onChange:c})]}),n&&(0,Q.jsxs)(D,{children:[(0,Q.jsx)(M,{fontSize:`sm`,fontWeight:`semibold`,mb:3,children:`Access`}),_.isLoading?(0,Q.jsx)(E,{size:`sm`}):N.length===0&&d.length===0?(0,Q.jsx)(M,{fontSize:`sm`,color:`fg.muted`,fontStyle:`italic`,children:`No access configured.`}):(0,Q.jsxs)(B,{gap:2,align:`stretch`,children:[N.map(e=>{let t=l.has(e.id);return(0,Q.jsxs)(I,{px:3,py:2,bg:`bg.muted`,borderRadius:`md`,fontSize:`sm`,opacity:t?.4:1,transition:`opacity 0.15s`,children:[(0,Q.jsx)(k,{colorPalette:J(e.role),size:`sm`,textDecoration:t?`line-through`:void 0,children:e.customRoleName??e.role}),(0,Q.jsx)(M,{color:`fg.muted`,children:`on`}),(0,Q.jsxs)(k,{colorPalette:`purple`,size:`sm`,textDecoration:t?`line-through`:void 0,children:[q(e.scopeType),` `,e.scopeName??e.scopeId]}),(0,Q.jsx)(z,{}),e.scopeType!==X.RoleBindingScopeType.PROJECT&&(0,Q.jsx)(T,{size:`xs`,variant:`ghost`,color:t?`blue.500`:`fg.muted`,"aria-label":t?`Undo removal`:`Remove binding`,onClick:()=>u(t=>{let n=new Set(t);return n.has(e.id)?n.delete(e.id):n.add(e.id),n}),children:(0,Q.jsx)(x,{size:14})})]},e.id)}),d.map((e,t)=>(0,Q.jsxs)(I,{px:3,py:2,bg:`bg.muted`,borderRadius:`md`,fontSize:`sm`,opacity:.7,children:[(0,Q.jsx)(k,{colorPalette:J(e.role),size:`sm`,children:e.customRoleName??e.role}),(0,Q.jsx)(M,{color:`fg.muted`,children:`on`}),(0,Q.jsxs)(k,{colorPalette:`purple`,size:`sm`,children:[q(e.scopeType),` `,e.scopeName??e.scopeId]}),(0,Q.jsx)(z,{}),(0,Q.jsx)(T,{size:`xs`,variant:`ghost`,color:`fg.muted`,"aria-label":`Undo add`,onClick:()=>f(e=>e.filter((e,n)=>n!==t)),children:(0,Q.jsx)(x,{size:14})})]},t))]}),(0,Q.jsx)(pe,{ref:h,organizationId:t,onAdd:e=>f(t=>[...t,e])})]}),(0,Q.jsxs)(D,{children:[(0,Q.jsx)(M,{fontSize:`sm`,fontWeight:`semibold`,mb:3,children:`Group access`}),v.isLoading?(0,Q.jsx)(E,{size:`sm`}):v.data?.length?(0,Q.jsx)(B,{gap:2,align:`stretch`,children:v.data.map(e=>e.bindings.length===0?(0,Q.jsxs)(I,{px:3,py:2,bg:`bg.muted`,borderRadius:`md`,fontSize:`sm`,justifyContent:`space-between`,children:[(0,Q.jsx)(M,{fontSize:`sm`,color:`fg.muted`,children:e.name}),(0,Q.jsx)(R,{href:`/settings/groups`,fontSize:`xs`,color:`blue.400`,children:`No access configured`})]},e.id):e.bindings.map(t=>(0,Q.jsxs)(I,{px:3,py:2,bg:`bg.muted`,borderRadius:`md`,fontSize:`sm`,children:[(0,Q.jsx)(k,{colorPalette:J(t.role),size:`sm`,children:t.customRoleName??t.role}),(0,Q.jsx)(M,{color:`fg.muted`,children:`on`}),(0,Q.jsxs)(k,{colorPalette:`purple`,size:`sm`,children:[q(t.scopeType),` `,t.scopeName??`—`]}),(0,Q.jsx)(z,{}),(0,Q.jsxs)(M,{fontSize:`xs`,color:`fg.muted`,children:[`via `,e.name]})]},t.id)))}):(0,Q.jsx)(M,{fontSize:`sm`,color:`fg.muted`,fontStyle:`italic`,children:`Not a member of any groups.`})]})]})}),n&&(0,Q.jsxs)(A.Footer,{children:[(0,Q.jsx)(T,{variant:`outline`,onClick:()=>{g(),a()},children:`Cancel`}),(0,Q.jsx)(T,{colorPalette:`blue`,disabled:!w,loading:p,onClick:()=>void j(),children:`Save`})]})]})})}function xe({isAdmin:e,inviteId:t,onApprove:n,onReject:r}){return e?(0,Q.jsxs)(I,{gap:2,children:[(0,Q.jsx)(L,{"aria-label":`Approve`,variant:`ghost`,size:`sm`,color:`green.500`,onClick:()=>n(t),children:(0,Q.jsx)(N,{size:16})}),(0,Q.jsx)(L,{"aria-label":`Reject`,variant:`ghost`,size:`sm`,color:`red.500`,onClick:()=>r(t),children:(0,Q.jsx)(x,{size:16})})]}):null}function Se({waitingApprovalInvites:e,sentInvites:t,isAdmin:n,currentUserId:r,teams:i,onApprove:s,onReject:c,onViewInviteLink:d,onDeleteInvite:f}){let m=(0,Z.useMemo)(()=>n?e:e.filter(e=>e.requestedBy===r),[e,n,r]),h=(0,Z.useMemo)(()=>[...m,...t],[m,t]);return h.length===0?null:(0,Q.jsxs)(B,{align:`start`,gap:4,paddingTop:4,width:`full`,children:[(0,Q.jsx)(j,{children:`Invites`}),(0,Q.jsx)(ne,{width:`full`,overflow:`hidden`,children:(0,Q.jsx)(re,{paddingY:0,paddingX:0,children:(0,Q.jsxs)(b,{variant:`line`,size:`md`,width:`full`,children:[(0,Q.jsx)(u,{children:(0,Q.jsxs)(a,{children:[(0,Q.jsx)(C,{width:`56px`}),(0,Q.jsx)(C,{children:`Email`}),(0,Q.jsx)(C,{children:`Status`}),(0,Q.jsx)(C,{children:`Role`}),(0,Q.jsx)(C,{children:`Teams`}),(0,Q.jsx)(C,{width:`60px`})]})}),(0,Q.jsx)(l,{children:h.map(e=>{let t=e.status===`WAITING_APPROVAL`,r=$.find(t=>t.value===e.role)?.label??e.role;return(0,Q.jsxs)(a,{children:[(0,Q.jsx)(v,{children:(0,Q.jsx)(p,{size:`2xs`,name:e.email})}),(0,Q.jsx)(v,{children:e.email}),(0,Q.jsx)(v,{children:t?(0,Q.jsx)(k,{size:`sm`,variant:`surface`,colorPalette:`orange`,children:`Pending Approval`}):(0,Q.jsx)(k,{size:`sm`,variant:`surface`,children:`Invited`})}),(0,Q.jsx)(v,{children:r}),(0,Q.jsx)(v,{children:(0,Q.jsx)(Ce,{teamIds:e.teamIds,teams:i})}),(0,Q.jsx)(v,{children:(0,Q.jsx)(D,{width:`full`,height:`full`,display:`flex`,justifyContent:`end`,children:t?(0,Q.jsx)(xe,{isAdmin:n,inviteId:e.id,onApprove:s,onReject:c}):(0,Q.jsxs)(g.Root,{children:[(0,Q.jsx)(g.Trigger,{asChild:!0,children:(0,Q.jsx)(L,{"aria-label":`Invite actions`,variant:`ghost`,size:`sm`,children:(0,Q.jsx)(o,{size:16})})}),(0,Q.jsxs)(g.Content,{children:[(0,Q.jsxs)(g.Item,{value:`view-link`,onClick:()=>d(e.inviteCode,e.email),children:[(0,Q.jsx)(Y,{size:16}),`View invite link`]}),n&&(0,Q.jsxs)(g.Item,{value:`delete`,color:`red.500`,onClick:()=>f(e.id),children:[(0,Q.jsx)(y,{size:16}),`Delete`]})]})]})})})]},e.id)})})]})})})]})}var Ce=({teamIds:e,teams:t})=>{if(!e)return null;let n=e.split(`,`).map(e=>e.trim()).filter(Boolean);return n.length===0?null:(0,Q.jsx)(I,{gap:2,flexWrap:`wrap`,children:n.map(e=>{let n=t.find(t=>t.id===e);return n?(0,Q.jsx)(R,{href:`/settings/teams/${n.slug}`,children:(0,Q.jsx)(k,{size:`sm`,variant:`surface`,children:n.name})},e):null})})};function we({organizationId:e,isAdmin:t,hasEmailProvider:n,onInviteCreated:r,onClose:i,refetchInvites:a,pricingModel:o,activePlanFree:s,activePlanType:c,activePlanSource:l}){let u=f(`members`),d=f(`membersLite`),p=ae(e=>e.openSeats),m=H.useContext(),h=()=>{m.licenseEnforcement.checkLimit.invalidate()},g=H.subscription?.addTeamMemberOrEvents?.useMutation(),_=H.organization.createInvites.useMutation(),v=H.organization.createInviteRequest.useMutation(),y=H.organization.approveInvite.useMutation(),b=H.organization.deleteInvite.useMutation(),x=t=>{_.mutate({organizationId:e,invites:t.invites.map(e=>({email:e.email.toLowerCase(),role:e.orgRole,teams:e.teams.map(e=>({teamId:e.teamId,role:e.role,customRoleId:e.customRoleId}))}))},{onSuccess:e=>{r(e.reduce((e,t)=>(t?.invite&&t.emailNotSent&&e.push({inviteCode:t.invite.inviteCode,email:t.invite.email}),e),[]));let t=e.filter(Boolean).length,o=n?`All invites have been sent.`:`All invites have been created. View invite link under actions menu.`;O.create({title:`${t>1?`Invites`:`Invite`} created successfully`,description:o,type:`success`,duration:2e3,meta:{closable:!0}}),i(),a(),h()},onError:e=>{V(e)||O.create({title:`Sorry, something went wrong`,description:e.message??`Please try that again`,type:`error`,duration:5e3,meta:{closable:!0}})}})},S=t=>{v.mutate({organizationId:e,invites:t.invites.map(e=>({email:e.email.toLowerCase(),role:e.orgRole===X.OrganizationUserRole.EXTERNAL?`EXTERNAL`:`MEMBER`,teams:e.teams.map(e=>({teamId:e.teamId,role:e.role,customRoleId:e.customRoleId}))}))},{onSuccess:()=>{let e=t.invites.length;O.create({title:e>1?`Invitations sent for approval`:`Invitation sent for approval`,description:`An admin will review your invitation request.`,type:`success`,duration:2e3,meta:{closable:!0}}),i(),a(),h()},onError:e=>{V(e)||O.create({title:`Sorry, something went wrong`,description:e.message??`Please try that again`,type:`error`,duration:5e3,meta:{closable:!0}})}})};return{onSubmit:n=>{let r=n.invites.some(e=>e.orgRole!==X.OrganizationUserRole.EXTERNAL),i=n.invites.some(e=>e.orgRole===X.OrganizationUserRole.EXTERNAL),a=n.invites.filter(e=>e.orgRole!==X.OrganizationUserRole.EXTERNAL).length,s=t?x:S,f=()=>{i?d.checkAndProceed(()=>s(n)):s(n)};if(!r){f();return}let m=u.limitInfo;if(!m){f();return}if(m.current+a<=m.max){f();return}if(l===`subscription`&&o===`SEAT_EVENT`&&g){let t=m.current+a;p({organizationId:e,currentSeats:m.max,newSeats:t,onConfirm:async()=>{try{await g.mutateAsync({organizationId:e,plan:c,upgradeMembers:!0,upgradeTraces:!1,totalMembers:t,totalTraces:0}),s(n)}catch(e){O.create({title:`Failed to expand seats`,description:e instanceof Error?e.message:`Please try again`,type:`error`,duration:5e3,meta:{closable:!0}})}}})}else u.checkAndProceed(()=>{})},approveInvite:t=>{y.mutate({inviteId:t,organizationId:e},{onSuccess:()=>{O.create({title:`Invitation approved`,description:`The invitation has been approved and sent.`,type:`success`,duration:5e3,meta:{closable:!0}}),a(),h()},onError:()=>{O.create({title:`Sorry, something went wrong`,description:`Please try that again`,type:`error`,duration:5e3,meta:{closable:!0}})}})},rejectInvite:t=>{b.mutate({inviteId:t,organizationId:e},{onSuccess:()=>{O.create({title:`Invitation rejected`,description:`The invitation request has been rejected.`,type:`success`,duration:5e3,meta:{closable:!0}}),a(),h()},onError:()=>{O.create({title:`Sorry, something went wrong`,description:`Please try that again`,type:`error`,duration:5e3,meta:{closable:!0}})}})},deleteInvite:t=>{b.mutate({inviteId:t,organizationId:e},{onSuccess:()=>{O.create({title:`Invite deleted successfully`,description:`The invite has been deleted.`,type:`success`,duration:5e3,meta:{closable:!0}}),a(),h()},onError:e=>{V(e)||O.create({title:`Sorry, something went wrong`,description:e.message??`Please try that again`,type:`error`,duration:5e3,meta:{closable:!0}})}})},isSubmitting:_.isLoading||v.isLoading}}function Te(){let{organization:e}=se(),t=H.organization.getOrganizationWithMembersAndTheirTeams.useQuery({organizationId:e?.id??``,includeDeactivated:!0},{enabled:!!e}),n=H.plan.getActivePlan.useQuery({organizationId:e?.id??``},{enabled:!!e});return!e||!t.data||!n.data?(0,Q.jsx)(K,{}):(0,Q.jsx)(De,{teams:e.teams,organization:t.data,activePlan:n.data})}var Ee=fe(`organization:view`,{layoutComponent:K})(Te);function De({organization:e,teams:t,activePlan:r}){let{data:c}=ce(),{hasPermission:f}=se(),h=f(`organization:manage`),_=c?.user,x=t.map(e=>({label:e.name,value:e.id})),S=H.useContext(),[w,E]=(0,Z.useState)(null),{open:N,onOpen:ee,onClose:P}=d(),{open:te,onOpen:F,onClose:L}=d(),R=H.organization.getOrganizationPendingInvites.useQuery({organizationId:e?.id??``},{enabled:!!e}),ae=H.organization.deleteMember.useMutation(),[V,U]=(0,Z.useState)([]);(0,Z.useEffect)(()=>{V.length>0&&F()},[V,F]);let W=oe().data?.HAS_EMAIL_PROVIDER_KEY,{onSubmit:le,approveInvite:ue,rejectInvite:G,deleteInvite:de,isSubmitting:fe}=we({organizationId:e.id,isAdmin:h,hasEmailProvider:W??!1,onInviteCreated:U,onClose:P,refetchInvites:()=>void R.refetch(),pricingModel:e.pricingModel,activePlanFree:r.free,activePlanType:r.type,activePlanSource:r.planSource}),q=t=>{ae.mutate({organizationId:e.id,userId:t},{onSuccess:()=>{O.create({title:`Member removed successfully`,description:`The member has been removed from the organization.`,type:`success`,duration:5e3,meta:{closable:!0}}),S.organization.getOrganizationWithMembersAndTheirTeams.invalidate().catch(n=>{ie(n,{tags:{userId:t,organizationId:e.id}})}),S.licenseEnforcement.checkLimit.invalidate()},onError:()=>{O.create({title:`Sorry, something went wrong`,description:`Please try that again`,type:`error`,duration:5e3,meta:{closable:!0}})}})},J=(e,t)=>{U([{inviteCode:e,email:t}]),F()},pe=()=>{U([]),L()},{data:Y,isLoading:X,isError:he}=H.roleBinding.listForOrg.useQuery({organizationId:e.id},{enabled:!!e.id&&h}),ge=(0,Z.useMemo)(()=>{let e=new Map;for(let t of Y??[]){t.userId&&(e.has(t.userId)||e.set(t.userId,[]),e.get(t.userId).push(t));for(let n of t.memberUserIds)e.has(n)||e.set(n,[]),e.get(n).push(t)}return e},[Y]),_e=(0,Z.useMemo)(()=>[...e.members].sort((e,t)=>(e.user.name??e.user.email??``).localeCompare(t.user.name??t.user.email??``)),[e.members]),ve=t=>h&&e.members.length>1&&t!==_?.id,$=(0,Z.useMemo)(()=>(R.data??[]).filter(e=>e.status===`PENDING`),[R.data]),ye=(0,Z.useMemo)(()=>(R.data??[]).filter(e=>e.status===`WAITING_APPROVAL`),[R.data]);return(0,Q.jsxs)(K,{children:[(0,Q.jsxs)(B,{gap:6,width:`full`,align:`start`,children:[(0,Q.jsxs)(I,{width:`full`,children:[(0,Q.jsx)(j,{children:`Organization Members`}),(0,Q.jsx)(z,{}),h&&(0,Q.jsxs)(s.HeaderButton,{onClick:ee,children:[(0,Q.jsx)(n,{size:20}),`Add members`]})]}),(0,Q.jsx)(ne,{width:`full`,overflow:`hidden`,children:(0,Q.jsx)(re,{paddingY:0,paddingX:0,children:(0,Q.jsxs)(b,{variant:`line`,size:`md`,width:`full`,children:[(0,Q.jsx)(u,{children:(0,Q.jsxs)(a,{children:[(0,Q.jsx)(C,{width:`56px`}),(0,Q.jsx)(C,{children:`Name`}),(0,Q.jsx)(C,{children:`Email`}),h&&(0,Q.jsx)(C,{textAlign:`right`,children:`Access`}),(0,Q.jsx)(C,{width:`60px`})]})}),(0,Q.jsx)(l,{children:_e.map(e=>(0,Q.jsxs)(a,{children:[(0,Q.jsx)(v,{children:(0,Q.jsx)(p,{size:`2xs`,name:e.user.name??``})}),(0,Q.jsx)(v,{children:(0,Q.jsxs)(I,{children:[(0,Q.jsx)(T,{variant:`plain`,size:`sm`,padding:0,height:`auto`,fontWeight:`normal`,color:`colorPalette.fg`,colorPalette:`blue`,onClick:()=>{E({userId:e.userId,role:e.role,user:{name:e.user.name??null,email:e.user.email??null}})},children:e.user.name}),e.role===`EXTERNAL`&&(0,Q.jsx)(k,{colorPalette:`gray`,size:`sm`,children:`Lite Member`}),e.user.deactivatedAt&&(0,Q.jsx)(k,{colorPalette:`red`,size:`sm`,children:`Deactivated`})]})}),(0,Q.jsx)(v,{children:e.user.email}),h&&(0,Q.jsx)(v,{children:(0,Q.jsx)(Ae,{bindings:ge.get(e.userId)??[],isLoading:X||he})}),(0,Q.jsx)(v,{children:(0,Q.jsx)(D,{width:`full`,height:`full`,display:`flex`,justifyContent:`end`,children:(0,Q.jsxs)(g.Root,{children:[(0,Q.jsx)(g.Trigger,{children:(0,Q.jsx)(o,{size:16})}),(0,Q.jsxs)(g.Content,{children:[(0,Q.jsxs)(g.Item,{value:`edit`,onClick:()=>{E({userId:e.userId,role:e.role,user:{name:e.user.name??null,email:e.user.email??null}})},children:[(0,Q.jsx)(i,{size:16}),`Edit`]}),ve(e.userId)&&(0,Q.jsxs)(g.Item,{value:`delete`,color:`red.500`,onClick:()=>q(e.userId),children:[(0,Q.jsx)(y,{size:16}),`Delete`]})]})]})})})]},e.userId))})]})})}),(0,Q.jsx)(Se,{waitingApprovalInvites:ye,sentInvites:$,isAdmin:h,currentUserId:_?.id??``,teams:t,onApprove:ue,onReject:G,onViewInviteLink:J,onDeleteInvite:de})]}),w&&(0,Q.jsx)(be,{member:w,organizationId:e.id,canManage:h,isCurrentUser:w.userId===_?.id,open:!!w,onClose:()=>E(null)}),(0,Q.jsx)(A.Root,{open:te,onOpenChange:({open:e})=>e?void 0:pe(),children:(0,Q.jsxs)(A.Content,{children:[(0,Q.jsx)(A.Header,{children:(0,Q.jsx)(A.Title,{children:(0,Q.jsx)(j,{children:`Invite Link`})})}),(0,Q.jsx)(A.CloseTrigger,{}),(0,Q.jsx)(A.Body,{paddingBottom:6,children:(0,Q.jsxs)(B,{align:`start`,gap:4,children:[(0,Q.jsx)(M,{children:`Send the link below to the users you want to invite to join the organization.`}),(0,Q.jsx)(B,{align:`start`,gap:4,width:`full`,children:V.map(e=>(0,Q.jsxs)(B,{align:`start`,gap:6,width:`full`,children:[(0,Q.jsx)(M,{fontWeight:`600`,children:e.email}),(0,Q.jsx)(m,{value:`${window.location.origin}/invite/accept?inviteCode=${e.inviteCode}`,label:`Invite Link`,marginTop:0})]},e.inviteCode))})]})})]})}),(0,Q.jsx)(A.Root,{open:N,onOpenChange:({open:e})=>e?ee():P(),children:(0,Q.jsxs)(A.Content,{width:`100%`,maxWidth:`1024px`,children:[(0,Q.jsx)(A.Header,{children:(0,Q.jsx)(A.Title,{children:(0,Q.jsx)(j,{children:`Add members`})})}),(0,Q.jsx)(A.CloseTrigger,{}),(0,Q.jsx)(A.Body,{children:(0,Q.jsx)(me,{teamOptions:x,organizationId:e.id,onSubmit:le,isLoading:fe,hasEmailProvider:W??!1,onClose:P,isInviterAdmin:h})})]})})]})}function Oe(e){return e===X.RoleBindingScopeType.ORGANIZATION?`🏢`:e===X.RoleBindingScopeType.TEAM?`👥`:`📁`}function ke(e){return e===`ADMIN`?`red`:e===`MEMBER`?`blue`:`gray`}function Ae({bindings:e,isLoading:t}){return t?(0,Q.jsx)(M,{fontSize:`xs`,color:`fg.subtle`,textAlign:`right`,children:`—`}):e.length===0?(0,Q.jsx)(M,{fontSize:`xs`,color:`fg.subtle`,textAlign:`right`,children:`No access configured`}):(0,Q.jsx)(B,{gap:1,align:`end`,children:e.map(e=>(0,Q.jsxs)(I,{gap:1,fontSize:`xs`,children:[(0,Q.jsx)(k,{colorPalette:ke(e.role),size:`sm`,children:e.customRoleName??e.role}),(0,Q.jsx)(M,{color:`fg.muted`,children:`on`}),(0,Q.jsxs)(k,{colorPalette:`purple`,size:`sm`,children:[Oe(e.scopeType),` `,e.scopeName??e.scopeId.slice(0,8)+`…`]}),e.groupId&&(0,Q.jsxs)(M,{color:`fg.subtle`,fontSize:`xs`,title:`via group: ${e.groupName??e.groupId}`,children:[`via `,e.groupName??`group`]})]},e.id))})}export{Ee as default};
2
+ //# sourceMappingURL=members-CUJANDtH.js.map
@@ -1,2 +1,2 @@
1
- import{s as e}from"./chunk-Bj-mKKzh.js";import{t}from"./react-C7JcuhbW.js";import{$i as n,Qi as r,Qo as i,Xn as a,Xr as o,_o as s,bn as c,cs as l,ea as u,fn as d,g as f,mn as p,p as m,qi as h,un as g,v as _,vn as v,vo as y,yn as ee}from"./command-bar-CaJygoez.js";import{j as b,p as x,y as S}from"./stack-oJ9iWdbl.js";import{t as C}from"./box-BsM8YLGl.js";import{f as w}from"./LoadingScreen--vgXk5-2.js";import{t as T}from"./tooltip-AEm0YeiF.js";import{h as E}from"./terminal-CfM0q99k.js";import{t as D}from"./text-CwTrMF8x.js";import{t as O}from"./h-stack-BKLDJ2vg.js";import{i as k,r as A,t as j}from"./alert-SnQmACl1.js";import{r as M,t as N}from"./card-CMtKVPVl.js";import{J as te,pt as P}from"./lu-Bf6j_N19.js";import{t as F}from"./container-Ccm3vB5X.js";import{t as I}from"./spacer-2LJJGbo8.js";import{t as L}from"./v-stack-EOPQ57OZ.js";import{s as R}from"./auth-client-D3UhxhQi.js";import{t as ne}from"./chevron-up-BC1rnYqD.js";import{r as z}from"./next-router-C6sliiV7.js";import{t as B}from"./useOrganizationTeamProject-DC0iozx2.js";import{t as V}from"./WithPermissionGuard-DD8uo3UK.js";import{n as H,t as U}from"./NavigationFooter-CiOVzDUh.js";import{t as W}from"./getSingleQueryParam-DjQoQARs.js";import{n as G,t as K}from"./MessagesTable-B6lYde-x.js";import{t as q}from"./WelcomeLayout-C-NpTCD2.js";var J=b(),Y=e(t(),1);(0,Y.forwardRef)(function(e,t){let{rel:n,className:r,...i}=e;return(0,J.jsx)(x.a,{...i,ref:t,className:S(`chakra-linkbox__overlay`,r),css:[{position:`static`,"&::before":{content:`''`,cursor:`inherit`,display:`block`,position:`absolute`,top:0,left:0,zIndex:0,width:`100%`,height:`100%`}},e.css]})});var X=(0,Y.forwardRef)(function(e,t){let{className:n,...r}=e;return(0,J.jsx)(x.div,{ref:t,position:`relative`,...r,className:S(`chakra-linkbox`,n),css:[{"& a[href]:not(.chakra-linkbox__overlay), abbr[title]":{position:`relative`,zIndex:1}},e.css]})});function re(){let{project:e}=B(),t=z(),[i,a]=(0,Y.useState)(),[s]=$(),{filterParams:c,queryOpts:l}=r(),f=H(),[p,h]=(0,Y.useState)(c.endDate);(0,Y.useEffect)(()=>{h(c.endDate)},[c.endDate]);let _=W(t.query.scrollId),y=R.traces.getAllForProject.useQuery({...c,endDate:p,query:W(t.query.query),groupBy:s,pageOffset:f.pageOffset,pageSize:f.pageSize,scrollId:_},l);f.useUpdateTotalHits(y);let b=G(y.isLoading||y.isRefetching),x=y.data?.groups.flatMap(e=>e.map(e=>e.trace_id))??[],S=R.traces.getEvaluationsMultiple.useQuery({projectId:e?.id??``,traceIds:x},{enabled:x.length>0,refetchInterval:i,refetchOnWindowFocus:!1}),{period:{startDate:w,endDate:E},setPeriod:D}=u();(0,Y.useEffect)(()=>{S.data&&(Object.values(S.data).flatMap(e=>e).filter(e=>(e.status==`scheduled`||e.status==`in_progress`)&&(e.timestamps.inserted_at??0)>new Date().getTime()-1e3*60*60*1).length>0?a(5e3):a(void 0))},[S.data]);let M=(0,Y.useRef)(y.data);return M.current=y.data,m({projectId:e?.id??``,onTraceSummaryUpdated:e=>{let t=new Set(M.current?.groups.flatMap(e=>e.map(e=>e.trace_id))??[]);(e.length===0||e.some(e=>t.has(e)))&&y.refetch()},enabled:!!e,pageOffset:f.pageOffset,cursorPageNumber:f.cursorPageNumber}),(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(o.Header,{children:[(0,J.jsx)(o.Heading,{children:`Traces`}),(0,J.jsx)(T,{content:`Refresh`,children:(0,J.jsx)(o.HeaderButton,{variant:`ghost`,onClick:()=>h(Date.now()),children:(0,J.jsx)(P,{className:b?`refresh-icon animation-spinning`:`refresh-icon`})})}),(0,J.jsx)(I,{}),(0,J.jsx)(ee,{}),(0,J.jsx)(ae,{}),(0,J.jsx)(n,{period:{startDate:w,endDate:E},setPeriod:D}),(0,J.jsx)(d,{defaultShowFilters:!0}),(0,J.jsx)(v,{})]}),(0,J.jsx)(F,{maxW:`calc(min(1440px, 100vw - 200px))`,padding:6,children:(0,J.jsxs)(O,{align:`start`,gap:8,children:[(0,J.jsxs)(L,{gap:6,width:`full`,children:[e&&y.data&&y.data.groups.length>0?(0,J.jsx)(ie,{project:e,traceGroups:y.data.groups,checksMap:S.data}):y.data?(0,J.jsxs)(k,{status:`info`,children:[(0,J.jsx)(A,{}),(0,J.jsx)(j,{children:`No messages found`})]}):y.isError?(0,J.jsxs)(k,{status:`error`,children:[(0,J.jsx)(A,{}),(0,J.jsx)(j,{children:`An error has occurred trying to load the messages`})]}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(Z,{}),(0,J.jsx)(Z,{}),(0,J.jsx)(Z,{})]}),(0,J.jsx)(U,{...f,scrollId:y.data?.scrollId}),(0,J.jsx)(C,{height:`32px`,flexShrink:0})]}),(0,J.jsx)(g,{defaultShowFilters:!0})]})})]})}var ie=Y.memo(function({project:e,traceGroups:t,checksMap:n}){let[r,o]=(0,Y.useState)({}),s=e=>{o(t=>({...t,[e]:!t[e]}))},[c,l]=(0,Y.useState)({}),u=(t??[]).map(()=>(0,Y.createRef)()),[d]=$(),[p,m]=(0,Y.useState)(!1);return(0,Y.useEffect)(()=>{let e={};u.forEach((t,n)=>{t.current&&(e[n]=t.current.clientHeight)}),l(e),setTimeout(()=>m(!0),100)},[t]),t.map((o,l)=>{let m=!!r[l],h=1e3+t.length-l;return(0,J.jsxs)(L,{gap:0,transition:`all .2s linear`,onClick:e=>{let t=e=>e?e.classList.contains(`card`)||e.classList.contains(`group-title`)?!0:t(e.parentElement):!1;m&&t(e.target)||o.length!==1&&s(l)},...m?{className:`card-stack-content expanded`,background:`bg.muted`,borderRadius:`10px`,padding:`40px`,width:`calc(100% + 80px)`,cursor:`n-resize`}:{background:`transparent`,className:`card-stack-content`,marginBottom:o.length>2?4:o.length>1?2:0,marginLeft:o.length>2?-4:o.length>1?-2:0,cursor:`pointer`,width:`full`,_hover:{transform:`scale(1.04)`,zIndex:h}},children:[m&&(0,J.jsx)(O,{width:`full`,cursor:`n-resize`,justify:`center`,marginTop:`-40px`,paddingY:3,children:(0,J.jsx)(ne,{})}),m&&d===`user_id`&&(0,J.jsx)(C,{className:`group-title`,position:`absolute`,left:`64px`,marginTop:`-22px`,fontSize:`13px`,fontWeight:600,color:`fg.muted`,cursor:`default`,children:(0,J.jsxs)(O,{gap:1,children:[(0,J.jsx)(D,{flexShrink:0,children:`User ID: `}),(0,J.jsx)(D,{children:o[0]?.metadata.user_id??`null`}),(0,J.jsx)(E,{orientation:`vertical`,height:`20px`})]})}),m&&d===`thread_id`&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(C,{className:`group-title`,position:`absolute`,left:`64px`,marginTop:`-22px`,fontSize:`13px`,fontWeight:600,color:`fg.muted`,cursor:`default`,children:(0,J.jsxs)(O,{gap:1,children:[(0,J.jsx)(D,{children:`Thread ID:`}),(0,J.jsx)(D,{children:o[0]?.metadata.thread_id??`null`})]})}),(0,J.jsx)(C,{className:`group-title`,position:`absolute`,right:`64px`,marginTop:`-22px`,fontSize:`13px`,fontWeight:600,color:`fg.muted`,cursor:`default`,children:(0,J.jsxs)(O,{gap:1,children:[(0,J.jsx)(D,{children:`Thread duration:`}),(0,J.jsx)(D,{children:(()=>{let e=o[0]?.timestamps.updated_at,t=o.at(-1)?.timestamps.updated_at;if(!e||!t)return`N/A`;let[n,r]=e<t?[e,t]:[t,e];return a(r-n)})()})]})})]}),(0,J.jsx)(L,{width:`full`,gap:6,children:o.slice(0,m?o.length:3).toReversed().map((t,r)=>{let a=m||o.length===1,s=m||r===0;return(0,J.jsx)(X,{asChild:!0,children:(0,J.jsxs)(M,{variant:`elevated`,className:`card`,ref:r===0?u[l]:null,height:s?`auto`:`${c[l]??0}px`,marginTop:s?`0`:`-${(c[l]??0)+24}px`,padding:0,cursor:`pointer`,width:`full`,transition:p?`all .2s linear`:void 0,_hover:a?{transform:`scale(1.04)`}:{},boxShadow:`lg`,borderRadius:`xl`,children:[!a&&(0,J.jsx)(C,{position:`absolute`,right:6,top:6,children:(0,J.jsx)(i,{})}),(0,J.jsx)(N,{padding:7,width:`fill`,children:s&&(0,J.jsx)(f,{linkActive:a,project:e,trace:t,checksMap:n})})]},t.trace_id)},t.trace_id)})})]},o[0]?.trace_id??l)})},(e,t)=>e.project===t.project&&e.traceGroups.flatMap(e=>e.map(e=>e.trace_id)).join()===t.traceGroups.flatMap(e=>e.map(e=>e.trace_id)).join()&&JSON.stringify(e.checksMap)===JSON.stringify(t.checksMap));function Z(){return(0,J.jsx)(M,{width:`full`,padding:0,variant:`elevated`,children:(0,J.jsx)(N,{padding:8,children:(0,J.jsxs)(L,{alignItems:`flex-start`,gap:4,children:[(0,J.jsx)(O,{gap:12,width:`full`,children:(0,J.jsx)(C,{fontSize:`24px`,fontWeight:`bold`,width:`full`,children:(0,J.jsx)(w,{width:`50%`,height:`20px`})})}),(0,J.jsxs)(L,{gap:4,width:`full`,children:[(0,J.jsx)(w,{width:`full`,height:`20px`}),(0,J.jsx)(w,{width:`full`,height:`20px`}),(0,J.jsx)(w,{width:`full`,height:`20px`})]})]})})})}var Q={thread_id:`Thread ID`,user_id:`User ID`,none:`None`},$=()=>{let e=z();return[e.query.group_by??`thread_id`,t=>{e.push({query:{...e.query,group_by:t}},void 0,{shallow:!0})}]};function ae(){let[e,t]=$();return(0,J.jsxs)(h.Root,{children:[(0,J.jsx)(h.Trigger,{asChild:!0,children:(0,J.jsx)(o.HeaderButton,{children:(0,J.jsxs)(O,{gap:2,children:[(0,J.jsx)(te,{}),(0,J.jsx)(C,{children:Q[e]}),(0,J.jsx)(C,{children:(0,J.jsx)(l,{})})]})})}),(0,J.jsxs)(h.Content,{children:[(0,J.jsx)(C,{paddingX:3,paddingY:2,fontWeight:`medium`,color:`fg.muted`,children:`Group by`}),(0,J.jsx)(y,{value:e,onChange:e=>t(e.target.value),children:Object.entries(Q).map(([e,n])=>(0,J.jsx)(h.Item,{value:e,onClick:()=>t(e),children:(0,J.jsxs)(O,{gap:2,children:[(0,J.jsx)(s,{value:e}),(0,J.jsx)(D,{children:n})]})},e))})]})]})}function oe(){let{project:e}=B(),t=R.project.getHasFirstMessage.useQuery({projectId:e?.id??``},{enabled:!!e?.id,staleTime:0}),n=!!t.data?.firstMessage,{isTableView:r}=c();return _(`input`),e&&t.isFetched&&!n?(0,J.jsx)(p,{children:(0,J.jsx)(q,{})}):(0,J.jsx)(p,{children:r?(0,J.jsx)(K,{}):(0,J.jsx)(re,{})})}var se=V(`traces:view`,{layoutComponent:p})(oe);export{se as default};
2
- //# sourceMappingURL=messages-CG9j8Dz8.js.map
1
+ import{s as e}from"./chunk-Bj-mKKzh.js";import{t}from"./react-C7JcuhbW.js";import{$i as n,Qi as r,Qo as i,Xn as a,Xr as o,_o as s,bn as c,cs as l,ea as u,fn as d,g as f,mn as p,p as m,qi as h,un as g,v as _,vn as v,vo as y,yn as ee}from"./command-bar-DUK45yin.js";import{j as b,p as x,y as S}from"./stack-oJ9iWdbl.js";import{t as C}from"./box-BsM8YLGl.js";import{f as w}from"./LoadingScreen--vgXk5-2.js";import{t as T}from"./tooltip-AEm0YeiF.js";import{h as E}from"./terminal-CfM0q99k.js";import{t as D}from"./text-CwTrMF8x.js";import{t as O}from"./h-stack-BKLDJ2vg.js";import{i as k,r as A,t as j}from"./alert-SnQmACl1.js";import{r as M,t as N}from"./card-CMtKVPVl.js";import{J as te,pt as P}from"./lu-Bf6j_N19.js";import{t as F}from"./container-Ccm3vB5X.js";import{t as I}from"./spacer-2LJJGbo8.js";import{t as L}from"./v-stack-EOPQ57OZ.js";import{s as R}from"./auth-client-D3UhxhQi.js";import{t as ne}from"./chevron-up-BC1rnYqD.js";import{r as z}from"./next-router-C6sliiV7.js";import{t as B}from"./useOrganizationTeamProject-DC0iozx2.js";import{t as V}from"./WithPermissionGuard-B4Jo8E5-.js";import{n as H,t as U}from"./NavigationFooter-Dzvauw3l.js";import{t as W}from"./getSingleQueryParam-DjQoQARs.js";import{n as G,t as K}from"./MessagesTable-9taaKCOZ.js";import{t as q}from"./WelcomeLayout-C-NpTCD2.js";var J=b(),Y=e(t(),1);(0,Y.forwardRef)(function(e,t){let{rel:n,className:r,...i}=e;return(0,J.jsx)(x.a,{...i,ref:t,className:S(`chakra-linkbox__overlay`,r),css:[{position:`static`,"&::before":{content:`''`,cursor:`inherit`,display:`block`,position:`absolute`,top:0,left:0,zIndex:0,width:`100%`,height:`100%`}},e.css]})});var X=(0,Y.forwardRef)(function(e,t){let{className:n,...r}=e;return(0,J.jsx)(x.div,{ref:t,position:`relative`,...r,className:S(`chakra-linkbox`,n),css:[{"& a[href]:not(.chakra-linkbox__overlay), abbr[title]":{position:`relative`,zIndex:1}},e.css]})});function re(){let{project:e}=B(),t=z(),[i,a]=(0,Y.useState)(),[s]=$(),{filterParams:c,queryOpts:l}=r(),f=H(),[p,h]=(0,Y.useState)(c.endDate);(0,Y.useEffect)(()=>{h(c.endDate)},[c.endDate]);let _=W(t.query.scrollId),y=R.traces.getAllForProject.useQuery({...c,endDate:p,query:W(t.query.query),groupBy:s,pageOffset:f.pageOffset,pageSize:f.pageSize,scrollId:_},l);f.useUpdateTotalHits(y);let b=G(y.isLoading||y.isRefetching),x=y.data?.groups.flatMap(e=>e.map(e=>e.trace_id))??[],S=R.traces.getEvaluationsMultiple.useQuery({projectId:e?.id??``,traceIds:x},{enabled:x.length>0,refetchInterval:i,refetchOnWindowFocus:!1}),{period:{startDate:w,endDate:E},setPeriod:D}=u();(0,Y.useEffect)(()=>{S.data&&(Object.values(S.data).flatMap(e=>e).filter(e=>(e.status==`scheduled`||e.status==`in_progress`)&&(e.timestamps.inserted_at??0)>new Date().getTime()-1e3*60*60*1).length>0?a(5e3):a(void 0))},[S.data]);let M=(0,Y.useRef)(y.data);return M.current=y.data,m({projectId:e?.id??``,onTraceSummaryUpdated:e=>{let t=new Set(M.current?.groups.flatMap(e=>e.map(e=>e.trace_id))??[]);(e.length===0||e.some(e=>t.has(e)))&&y.refetch()},enabled:!!e,pageOffset:f.pageOffset,cursorPageNumber:f.cursorPageNumber}),(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(o.Header,{children:[(0,J.jsx)(o.Heading,{children:`Traces`}),(0,J.jsx)(T,{content:`Refresh`,children:(0,J.jsx)(o.HeaderButton,{variant:`ghost`,onClick:()=>h(Date.now()),children:(0,J.jsx)(P,{className:b?`refresh-icon animation-spinning`:`refresh-icon`})})}),(0,J.jsx)(I,{}),(0,J.jsx)(ee,{}),(0,J.jsx)(ae,{}),(0,J.jsx)(n,{period:{startDate:w,endDate:E},setPeriod:D}),(0,J.jsx)(d,{defaultShowFilters:!0}),(0,J.jsx)(v,{})]}),(0,J.jsx)(F,{maxW:`calc(min(1440px, 100vw - 200px))`,padding:6,children:(0,J.jsxs)(O,{align:`start`,gap:8,children:[(0,J.jsxs)(L,{gap:6,width:`full`,children:[e&&y.data&&y.data.groups.length>0?(0,J.jsx)(ie,{project:e,traceGroups:y.data.groups,checksMap:S.data}):y.data?(0,J.jsxs)(k,{status:`info`,children:[(0,J.jsx)(A,{}),(0,J.jsx)(j,{children:`No messages found`})]}):y.isError?(0,J.jsxs)(k,{status:`error`,children:[(0,J.jsx)(A,{}),(0,J.jsx)(j,{children:`An error has occurred trying to load the messages`})]}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(Z,{}),(0,J.jsx)(Z,{}),(0,J.jsx)(Z,{})]}),(0,J.jsx)(U,{...f,scrollId:y.data?.scrollId}),(0,J.jsx)(C,{height:`32px`,flexShrink:0})]}),(0,J.jsx)(g,{defaultShowFilters:!0})]})})]})}var ie=Y.memo(function({project:e,traceGroups:t,checksMap:n}){let[r,o]=(0,Y.useState)({}),s=e=>{o(t=>({...t,[e]:!t[e]}))},[c,l]=(0,Y.useState)({}),u=(t??[]).map(()=>(0,Y.createRef)()),[d]=$(),[p,m]=(0,Y.useState)(!1);return(0,Y.useEffect)(()=>{let e={};u.forEach((t,n)=>{t.current&&(e[n]=t.current.clientHeight)}),l(e),setTimeout(()=>m(!0),100)},[t]),t.map((o,l)=>{let m=!!r[l],h=1e3+t.length-l;return(0,J.jsxs)(L,{gap:0,transition:`all .2s linear`,onClick:e=>{let t=e=>e?e.classList.contains(`card`)||e.classList.contains(`group-title`)?!0:t(e.parentElement):!1;m&&t(e.target)||o.length!==1&&s(l)},...m?{className:`card-stack-content expanded`,background:`bg.muted`,borderRadius:`10px`,padding:`40px`,width:`calc(100% + 80px)`,cursor:`n-resize`}:{background:`transparent`,className:`card-stack-content`,marginBottom:o.length>2?4:o.length>1?2:0,marginLeft:o.length>2?-4:o.length>1?-2:0,cursor:`pointer`,width:`full`,_hover:{transform:`scale(1.04)`,zIndex:h}},children:[m&&(0,J.jsx)(O,{width:`full`,cursor:`n-resize`,justify:`center`,marginTop:`-40px`,paddingY:3,children:(0,J.jsx)(ne,{})}),m&&d===`user_id`&&(0,J.jsx)(C,{className:`group-title`,position:`absolute`,left:`64px`,marginTop:`-22px`,fontSize:`13px`,fontWeight:600,color:`fg.muted`,cursor:`default`,children:(0,J.jsxs)(O,{gap:1,children:[(0,J.jsx)(D,{flexShrink:0,children:`User ID: `}),(0,J.jsx)(D,{children:o[0]?.metadata.user_id??`null`}),(0,J.jsx)(E,{orientation:`vertical`,height:`20px`})]})}),m&&d===`thread_id`&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(C,{className:`group-title`,position:`absolute`,left:`64px`,marginTop:`-22px`,fontSize:`13px`,fontWeight:600,color:`fg.muted`,cursor:`default`,children:(0,J.jsxs)(O,{gap:1,children:[(0,J.jsx)(D,{children:`Thread ID:`}),(0,J.jsx)(D,{children:o[0]?.metadata.thread_id??`null`})]})}),(0,J.jsx)(C,{className:`group-title`,position:`absolute`,right:`64px`,marginTop:`-22px`,fontSize:`13px`,fontWeight:600,color:`fg.muted`,cursor:`default`,children:(0,J.jsxs)(O,{gap:1,children:[(0,J.jsx)(D,{children:`Thread duration:`}),(0,J.jsx)(D,{children:(()=>{let e=o[0]?.timestamps.updated_at,t=o.at(-1)?.timestamps.updated_at;if(!e||!t)return`N/A`;let[n,r]=e<t?[e,t]:[t,e];return a(r-n)})()})]})})]}),(0,J.jsx)(L,{width:`full`,gap:6,children:o.slice(0,m?o.length:3).toReversed().map((t,r)=>{let a=m||o.length===1,s=m||r===0;return(0,J.jsx)(X,{asChild:!0,children:(0,J.jsxs)(M,{variant:`elevated`,className:`card`,ref:r===0?u[l]:null,height:s?`auto`:`${c[l]??0}px`,marginTop:s?`0`:`-${(c[l]??0)+24}px`,padding:0,cursor:`pointer`,width:`full`,transition:p?`all .2s linear`:void 0,_hover:a?{transform:`scale(1.04)`}:{},boxShadow:`lg`,borderRadius:`xl`,children:[!a&&(0,J.jsx)(C,{position:`absolute`,right:6,top:6,children:(0,J.jsx)(i,{})}),(0,J.jsx)(N,{padding:7,width:`fill`,children:s&&(0,J.jsx)(f,{linkActive:a,project:e,trace:t,checksMap:n})})]},t.trace_id)},t.trace_id)})})]},o[0]?.trace_id??l)})},(e,t)=>e.project===t.project&&e.traceGroups.flatMap(e=>e.map(e=>e.trace_id)).join()===t.traceGroups.flatMap(e=>e.map(e=>e.trace_id)).join()&&JSON.stringify(e.checksMap)===JSON.stringify(t.checksMap));function Z(){return(0,J.jsx)(M,{width:`full`,padding:0,variant:`elevated`,children:(0,J.jsx)(N,{padding:8,children:(0,J.jsxs)(L,{alignItems:`flex-start`,gap:4,children:[(0,J.jsx)(O,{gap:12,width:`full`,children:(0,J.jsx)(C,{fontSize:`24px`,fontWeight:`bold`,width:`full`,children:(0,J.jsx)(w,{width:`50%`,height:`20px`})})}),(0,J.jsxs)(L,{gap:4,width:`full`,children:[(0,J.jsx)(w,{width:`full`,height:`20px`}),(0,J.jsx)(w,{width:`full`,height:`20px`}),(0,J.jsx)(w,{width:`full`,height:`20px`})]})]})})})}var Q={thread_id:`Thread ID`,user_id:`User ID`,none:`None`},$=()=>{let e=z();return[e.query.group_by??`thread_id`,t=>{e.push({query:{...e.query,group_by:t}},void 0,{shallow:!0})}]};function ae(){let[e,t]=$();return(0,J.jsxs)(h.Root,{children:[(0,J.jsx)(h.Trigger,{asChild:!0,children:(0,J.jsx)(o.HeaderButton,{children:(0,J.jsxs)(O,{gap:2,children:[(0,J.jsx)(te,{}),(0,J.jsx)(C,{children:Q[e]}),(0,J.jsx)(C,{children:(0,J.jsx)(l,{})})]})})}),(0,J.jsxs)(h.Content,{children:[(0,J.jsx)(C,{paddingX:3,paddingY:2,fontWeight:`medium`,color:`fg.muted`,children:`Group by`}),(0,J.jsx)(y,{value:e,onChange:e=>t(e.target.value),children:Object.entries(Q).map(([e,n])=>(0,J.jsx)(h.Item,{value:e,onClick:()=>t(e),children:(0,J.jsxs)(O,{gap:2,children:[(0,J.jsx)(s,{value:e}),(0,J.jsx)(D,{children:n})]})},e))})]})]})}function oe(){let{project:e}=B(),t=R.project.getHasFirstMessage.useQuery({projectId:e?.id??``},{enabled:!!e?.id,staleTime:0}),n=!!t.data?.firstMessage,{isTableView:r}=c();return _(`input`),e&&t.isFetched&&!n?(0,J.jsx)(p,{children:(0,J.jsx)(q,{})}):(0,J.jsx)(p,{children:r?(0,J.jsx)(K,{}):(0,J.jsx)(re,{})})}var se=V(`traces:view`,{layoutComponent:p})(oe);export{se as default};
2
+ //# sourceMappingURL=messages-fQBfCjvp.js.map
@@ -1,2 +1,2 @@
1
- import{Gn as e,un as t}from"./command-bar-CaJygoez.js";import{j as n}from"./stack-oJ9iWdbl.js";import{t as r}from"./box-BsM8YLGl.js";import{t as i}from"./h-stack-BKLDJ2vg.js";import{t as a}from"./simple-grid-C3IW90zo.js";import{t as o}from"./useOrganizationTeamProject-DC0iozx2.js";import{t as s}from"./WithPermissionGuard-DD8uo3UK.js";import{t as c}from"./GraphsLayout-BJ68J9e-.js";import{t as l}from"./ChartCard-D14PUg_d.js";var u=n(),d=1440,f={graphId:`llmMetricsSummary`,graphType:`summary`,series:[{name:`LLM Calls`,metric:`metadata.trace_id`,aggregation:`cardinality`,colorSet:`colors`},{name:`Total cost`,colorSet:`greenTones`,metric:`performance.total_cost`,aggregation:`sum`},{name:`Total tokens`,colorSet:`purpleTones`,metric:`performance.total_tokens`,aggregation:`sum`}],includePrevious:!0,timeScale:d,height:300},p={graphId:`llmPerformanceSummary`,graphType:`summary`,series:[{name:`Average tokens per message`,colorSet:`colors`,metric:`performance.total_tokens`,aggregation:`avg`},{name:`Average cost per message`,colorSet:`greenTones`,metric:`performance.total_cost`,aggregation:`avg`},{name:`90th Percentile time to first token`,colorSet:`cyanTones`,metric:`performance.first_token`,aggregation:`p90`},{name:`90th Percentile completion time`,colorSet:`greenTones`,metric:`performance.completion_time`,aggregation:`p90`}],includePrevious:!0,timeScale:d,height:300},m={graphId:`llmCallsByModel`,graphType:`area`,series:[{name:`LLM Calls`,colorSet:`colors`,metric:`metadata.trace_id`,aggregation:`cardinality`}],groupBy:`metadata.model`,includePrevious:!1,timeScale:d,height:300},h={graphId:`llmSplitByModel`,graphType:`donnut`,series:[{name:`LLM Calls`,colorSet:`colors`,metric:`metadata.span_type`,aggregation:`cardinality`,key:`llm`}],groupBy:`metadata.model`,includePrevious:!1,timeScale:d,height:300},g={graphId:`avgCompletionTimeByModel`,graphType:`horizontal_bar`,series:[{name:`Completion time average`,colorSet:`colors`,metric:`performance.completion_time`,aggregation:`avg`}],groupBy:`metadata.model`,includePrevious:!1,timeScale:`full`,height:300},_={graphId:`avgCostPerModel`,graphType:`horizontal_bar`,series:[{name:`Average cost per message`,colorSet:`colors`,metric:`performance.total_cost`,aggregation:`avg`,pipeline:{field:`trace_id`,aggregation:`avg`}}],groupBy:`metadata.model`,includePrevious:!1,timeScale:`full`,height:300},v={graphId:`avgTokensPerModel`,graphType:`horizontal_bar`,series:[{name:`Average completion tokens per message`,colorSet:`colors`,metric:`performance.completion_tokens`,aggregation:`avg`,pipeline:{field:`trace_id`,aggregation:`avg`}}],groupBy:`metadata.model`,includePrevious:!1,timeScale:`full`,height:300},y={graphId:`latencyTrend`,graphType:`line`,series:[{name:`P90 Completion Time`,colorSet:`greenTones`,metric:`performance.completion_time`,aggregation:`p90`},{name:`P90 Time to First Token`,colorSet:`cyanTones`,metric:`performance.first_token`,aggregation:`p90`}],includePrevious:!1,timeScale:d,height:300},b={graphId:`tokensPerSecondByModel`,graphType:`horizontal_bar`,series:[{name:`Average tokens per second`,colorSet:`cyanTones`,metric:`performance.tokens_per_second`,aggregation:`avg`}],groupBy:`metadata.model`,includePrevious:!1,timeScale:`full`,height:300},x={graphId:`errorRateByModel`,graphType:`horizontal_bar`,series:[{name:`Traces with errors`,colorSet:`orangeTones`,metric:`metadata.trace_id`,aggregation:`cardinality`}],groupBy:`error.has_error`,includePrevious:!1,timeScale:`full`,height:300};function S(){let{hasPermission:n}=o(),s=n(`cost:view`),d={...f,series:f.series.filter(e=>s||!e.metric?.includes(`total_cost`))},S={...p,series:p.series.filter(e=>s||!e.metric?.includes(`total_cost`))};return(0,u.jsx)(c,{title:`LLM Metrics`,children:(0,u.jsxs)(i,{alignItems:`start`,gap:4,children:[(0,u.jsxs)(a,{templateColumns:`repeat(4, 1fr)`,gap:5,width:`100%`,children:[(0,u.jsx)(l,{title:`LLM Metrics`,colSpan:2,children:(0,u.jsx)(e,{input:d})}),(0,u.jsx)(l,{title:`Summary`,colSpan:2,children:(0,u.jsx)(e,{input:S})}),(0,u.jsx)(l,{title:`LLM Usage`,colSpan:4,children:(0,u.jsx)(e,{input:m})}),(0,u.jsx)(l,{title:`LLM Split`,colSpan:2,children:(0,u.jsx)(e,{input:h})}),(0,u.jsx)(l,{title:`Average Completion Time`,colSpan:2,children:(0,u.jsx)(e,{input:g})}),s&&(0,u.jsx)(l,{title:`Average Cost Per Message`,colSpan:2,children:(0,u.jsx)(e,{input:_})}),(0,u.jsx)(l,{title:`Average Tokens Per Message`,colSpan:2,children:(0,u.jsx)(e,{input:v})}),(0,u.jsx)(l,{title:`Latency Trend`,colSpan:4,children:(0,u.jsx)(e,{input:y})}),(0,u.jsx)(l,{title:`Tokens Per Second`,colSpan:2,children:(0,u.jsx)(e,{input:b})}),(0,u.jsx)(l,{title:`Error Distribution`,colSpan:2,children:(0,u.jsx)(e,{input:x})})]}),(0,u.jsx)(r,{padding:3,children:(0,u.jsx)(t,{hideTopics:!0})})]})})}var C=s(`analytics:view`)(S);export{C as default};
2
- //# sourceMappingURL=metrics-C9pzeaI6.js.map
1
+ import{Gn as e,un as t}from"./command-bar-DUK45yin.js";import{j as n}from"./stack-oJ9iWdbl.js";import{t as r}from"./box-BsM8YLGl.js";import{t as i}from"./h-stack-BKLDJ2vg.js";import{t as a}from"./simple-grid-C3IW90zo.js";import{t as o}from"./useOrganizationTeamProject-DC0iozx2.js";import{t as s}from"./WithPermissionGuard-B4Jo8E5-.js";import{t as c}from"./GraphsLayout-DJ-HI9N1.js";import{t as l}from"./ChartCard-s5fMPo7b.js";var u=n(),d=1440,f={graphId:`llmMetricsSummary`,graphType:`summary`,series:[{name:`LLM Calls`,metric:`metadata.trace_id`,aggregation:`cardinality`,colorSet:`colors`},{name:`Total cost`,colorSet:`greenTones`,metric:`performance.total_cost`,aggregation:`sum`},{name:`Total tokens`,colorSet:`purpleTones`,metric:`performance.total_tokens`,aggregation:`sum`}],includePrevious:!0,timeScale:d,height:300},p={graphId:`llmPerformanceSummary`,graphType:`summary`,series:[{name:`Average tokens per message`,colorSet:`colors`,metric:`performance.total_tokens`,aggregation:`avg`},{name:`Average cost per message`,colorSet:`greenTones`,metric:`performance.total_cost`,aggregation:`avg`},{name:`90th Percentile time to first token`,colorSet:`cyanTones`,metric:`performance.first_token`,aggregation:`p90`},{name:`90th Percentile completion time`,colorSet:`greenTones`,metric:`performance.completion_time`,aggregation:`p90`}],includePrevious:!0,timeScale:d,height:300},m={graphId:`llmCallsByModel`,graphType:`area`,series:[{name:`LLM Calls`,colorSet:`colors`,metric:`metadata.trace_id`,aggregation:`cardinality`}],groupBy:`metadata.model`,includePrevious:!1,timeScale:d,height:300},h={graphId:`llmSplitByModel`,graphType:`donnut`,series:[{name:`LLM Calls`,colorSet:`colors`,metric:`metadata.span_type`,aggregation:`cardinality`,key:`llm`}],groupBy:`metadata.model`,includePrevious:!1,timeScale:d,height:300},g={graphId:`avgCompletionTimeByModel`,graphType:`horizontal_bar`,series:[{name:`Completion time average`,colorSet:`colors`,metric:`performance.completion_time`,aggregation:`avg`}],groupBy:`metadata.model`,includePrevious:!1,timeScale:`full`,height:300},_={graphId:`avgCostPerModel`,graphType:`horizontal_bar`,series:[{name:`Average cost per message`,colorSet:`colors`,metric:`performance.total_cost`,aggregation:`avg`,pipeline:{field:`trace_id`,aggregation:`avg`}}],groupBy:`metadata.model`,includePrevious:!1,timeScale:`full`,height:300},v={graphId:`avgTokensPerModel`,graphType:`horizontal_bar`,series:[{name:`Average completion tokens per message`,colorSet:`colors`,metric:`performance.completion_tokens`,aggregation:`avg`,pipeline:{field:`trace_id`,aggregation:`avg`}}],groupBy:`metadata.model`,includePrevious:!1,timeScale:`full`,height:300},y={graphId:`latencyTrend`,graphType:`line`,series:[{name:`P90 Completion Time`,colorSet:`greenTones`,metric:`performance.completion_time`,aggregation:`p90`},{name:`P90 Time to First Token`,colorSet:`cyanTones`,metric:`performance.first_token`,aggregation:`p90`}],includePrevious:!1,timeScale:d,height:300},b={graphId:`tokensPerSecondByModel`,graphType:`horizontal_bar`,series:[{name:`Average tokens per second`,colorSet:`cyanTones`,metric:`performance.tokens_per_second`,aggregation:`avg`}],groupBy:`metadata.model`,includePrevious:!1,timeScale:`full`,height:300},x={graphId:`errorRateByModel`,graphType:`horizontal_bar`,series:[{name:`Traces with errors`,colorSet:`orangeTones`,metric:`metadata.trace_id`,aggregation:`cardinality`}],groupBy:`error.has_error`,includePrevious:!1,timeScale:`full`,height:300};function S(){let{hasPermission:n}=o(),s=n(`cost:view`),d={...f,series:f.series.filter(e=>s||!e.metric?.includes(`total_cost`))},S={...p,series:p.series.filter(e=>s||!e.metric?.includes(`total_cost`))};return(0,u.jsx)(c,{title:`LLM Metrics`,children:(0,u.jsxs)(i,{alignItems:`start`,gap:4,children:[(0,u.jsxs)(a,{templateColumns:`repeat(4, 1fr)`,gap:5,width:`100%`,children:[(0,u.jsx)(l,{title:`LLM Metrics`,colSpan:2,children:(0,u.jsx)(e,{input:d})}),(0,u.jsx)(l,{title:`Summary`,colSpan:2,children:(0,u.jsx)(e,{input:S})}),(0,u.jsx)(l,{title:`LLM Usage`,colSpan:4,children:(0,u.jsx)(e,{input:m})}),(0,u.jsx)(l,{title:`LLM Split`,colSpan:2,children:(0,u.jsx)(e,{input:h})}),(0,u.jsx)(l,{title:`Average Completion Time`,colSpan:2,children:(0,u.jsx)(e,{input:g})}),s&&(0,u.jsx)(l,{title:`Average Cost Per Message`,colSpan:2,children:(0,u.jsx)(e,{input:_})}),(0,u.jsx)(l,{title:`Average Tokens Per Message`,colSpan:2,children:(0,u.jsx)(e,{input:v})}),(0,u.jsx)(l,{title:`Latency Trend`,colSpan:4,children:(0,u.jsx)(e,{input:y})}),(0,u.jsx)(l,{title:`Tokens Per Second`,colSpan:2,children:(0,u.jsx)(e,{input:b})}),(0,u.jsx)(l,{title:`Error Distribution`,colSpan:2,children:(0,u.jsx)(e,{input:x})})]}),(0,u.jsx)(r,{padding:3,children:(0,u.jsx)(t,{hideTopics:!0})})]})})}var C=s(`analytics:view`)(S);export{C as default};
2
+ //# sourceMappingURL=metrics-DeIxebpD.js.map
@@ -1,2 +1,2 @@
1
- import{Ss as e,Xo as t,Xr as n,_s as r,bs as i,qi as a,r as o,rc as s,vs as c,xs as l,ys as u}from"./command-bar-CaJygoez.js";import{j as d,n as f}from"./stack-oJ9iWdbl.js";import{f as p}from"./LoadingScreen--vgXk5-2.js";import"./tooltip-AEm0YeiF.js";import{n as m}from"./toaster-C_DYALhL.js";import{Qt as h}from"./dist-SwV3YZv3.js";import{t as g}from"./heading-D90dlSnH.js";import{t as _}from"./text-CwTrMF8x.js";import{t as v}from"./h-stack-BKLDJ2vg.js";import{t as y}from"./spacer-2LJJGbo8.js";import{t as b}from"./v-stack-EOPQ57OZ.js";import{m as x,s as S}from"./auth-client-D3UhxhQi.js";import{t as C}from"./useOrganizationTeamProject-DC0iozx2.js";import{t as w}from"./SettingsLayout-CLCGxMAe.js";var T=d();function E(t){let{openDrawer:a}=o(),{hasPermission:d}=C(),f=S.llmModelCost.getAllForProject.useQuery({projectId:t.projectId??``},{enabled:!!t.projectId});return(0,T.jsxs)(b,{gap:0,paddingTop:2,width:`full`,align:`start`,children:[(0,T.jsxs)(n.Header,{withBorder:!1,children:[(0,T.jsxs)(v,{children:[(0,T.jsx)(g,{children:`LLM Model Costs`}),f.data&&(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(_,{fontSize:`md`,children:`·`}),(0,T.jsxs)(_,{fontSize:`md`,color:`fg.muted`,children:[f.data?.length,` models`]})]})]}),(0,T.jsx)(y,{}),(0,T.jsxs)(n.HeaderButton,{onClick:()=>a(`llmModelCost`,{}),disabled:!d(`project:manage`),children:[(0,T.jsx)(h,{size:20}),(0,T.jsx)(_,{children:`Add New Model`})]})]}),(0,T.jsx)(b,{width:`full`,gap:0,align:`start`,paddingY:4,paddingX:4,paddingBottom:12,children:(0,T.jsxs)(l,{variant:`line`,width:`full`,maxWidth:`100%`,wordBreak:`break-all`,style:{tableLayout:`fixed`},children:[(0,T.jsx)(i,{width:`full`,children:(0,T.jsxs)(e,{width:`full`,children:[(0,T.jsx)(u,{width:`30%`,children:`Model name`}),(0,T.jsx)(u,{width:`30%`,children:`Regex match rule`}),(0,T.jsx)(u,{children:`Input cost`}),(0,T.jsx)(u,{children:`Output cost`}),(0,T.jsx)(u,{width:`64px`,padding:1})]})}),(0,T.jsxs)(r,{width:`full`,children:[f.isLoading&&Array.from({length:3}).map((t,n)=>(0,T.jsxs)(e,{children:[Array.from({length:4}).map((e,t)=>(0,T.jsx)(c,{children:(0,T.jsx)(p,{height:`20px`})},t)),(0,T.jsx)(c,{padding:1})]},n)),f.data?.map(t=>(0,T.jsxs)(e,{width:`full`,children:[(0,T.jsx)(c,{children:(0,T.jsx)(_,{truncate:!0,color:t.updatedAt?`green.500`:void 0,children:t.model})}),(0,T.jsx)(c,{padding:0,children:(0,T.jsx)(v,{justifyContent:`space-between`,paddingX:4,marginX:2,maxWidth:`100%`,children:(0,T.jsx)(s,{truncate:!0,color:t.updatedAt?`green.500`:void 0,height:`32px`,lineHeight:`22px`,borderRadius:`6px`,border:`1px solid`,borderColor:`border`,bg:`bg.subtle`,paddingY:1,paddingX:2,children:t.regex})})}),(0,T.jsx)(c,{padding:0,children:(0,T.jsx)(_,{justifyContent:`space-between`,paddingX:4,marginX:2,color:t.id?`green.500`:void 0,children:t.inputCostPerToken?.toLocaleString(`fullwide`,{useGrouping:!1,maximumSignificantDigits:20})})}),(0,T.jsx)(c,{padding:0,children:(0,T.jsx)(_,{justifyContent:`space-between`,paddingX:4,marginX:2,color:t.id?`green.500`:void 0,children:t.outputCostPerToken?.toLocaleString(`fullwide`,{useGrouping:!1,maximumSignificantDigits:20})})}),(0,T.jsx)(c,{padding:1,children:(0,T.jsx)(D,{id:t.id,model:t.model,projectId:t.projectId})})]},t.model))]})]})})]})}function D({id:e,model:n,projectId:r}){let{openDrawer:i}=o(),s=S.llmModelCost.getAllForProject.useQuery({projectId:r??``},{enabled:!!r}),c=S.llmModelCost.delete.useMutation();return(0,T.jsxs)(a.Root,{children:[(0,T.jsx)(a.Trigger,{minWidth:0,asChild:!0,children:(0,T.jsx)(f,{variant:`ghost`,children:(0,T.jsx)(t,{})})}),(0,T.jsxs)(a.Content,{children:[!e&&(0,T.jsx)(a.Item,{value:`clone`,onClick:e=>{e.stopPropagation(),i(`llmModelCost`,{cloneModel:n})},children:`Clone`}),e&&(0,T.jsx)(a.Item,{value:`edit`,onClick:t=>{t.stopPropagation(),i(`llmModelCost`,{id:e})},children:`Edit`}),e&&(0,T.jsx)(a.Item,{value:`delete`,color:`red.600`,onClick:t=>{t.stopPropagation(),c.mutate({projectId:r??``,id:e},{onSuccess:()=>{m.create({title:`Success`,description:`LLM model cost deleted successfully`,type:`success`,meta:{closable:!0}}),s.refetch()},onError:e=>{x(e)||m.create({title:`Error`,description:`Error deleting LLM model cost`,type:`error`,meta:{closable:!0}})}})},children:`Delete`})]})]})}function O(){let{project:e}=C();return(0,T.jsx)(w,{children:(0,T.jsx)(E,{projectId:e?.id})})}export{O as default};
2
- //# sourceMappingURL=model-costs-Bc5uqjkl.js.map
1
+ import{Ss as e,Xo as t,Xr as n,_s as r,bs as i,qi as a,r as o,rc as s,vs as c,xs as l,ys as u}from"./command-bar-DUK45yin.js";import{j as d,n as f}from"./stack-oJ9iWdbl.js";import{f as p}from"./LoadingScreen--vgXk5-2.js";import"./tooltip-AEm0YeiF.js";import{n as m}from"./toaster-C_DYALhL.js";import{Qt as h}from"./dist-Cds4Mqhj.js";import{t as g}from"./heading-D90dlSnH.js";import{t as _}from"./text-CwTrMF8x.js";import{t as v}from"./h-stack-BKLDJ2vg.js";import{t as y}from"./spacer-2LJJGbo8.js";import{t as b}from"./v-stack-EOPQ57OZ.js";import{m as x,s as S}from"./auth-client-D3UhxhQi.js";import{t as C}from"./useOrganizationTeamProject-DC0iozx2.js";import{t as w}from"./SettingsLayout--1gdEuhv.js";var T=d();function E(t){let{openDrawer:a}=o(),{hasPermission:d}=C(),f=S.llmModelCost.getAllForProject.useQuery({projectId:t.projectId??``},{enabled:!!t.projectId});return(0,T.jsxs)(b,{gap:0,paddingTop:2,width:`full`,align:`start`,children:[(0,T.jsxs)(n.Header,{withBorder:!1,children:[(0,T.jsxs)(v,{children:[(0,T.jsx)(g,{children:`LLM Model Costs`}),f.data&&(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(_,{fontSize:`md`,children:`·`}),(0,T.jsxs)(_,{fontSize:`md`,color:`fg.muted`,children:[f.data?.length,` models`]})]})]}),(0,T.jsx)(y,{}),(0,T.jsxs)(n.HeaderButton,{onClick:()=>a(`llmModelCost`,{}),disabled:!d(`project:manage`),children:[(0,T.jsx)(h,{size:20}),(0,T.jsx)(_,{children:`Add New Model`})]})]}),(0,T.jsx)(b,{width:`full`,gap:0,align:`start`,paddingY:4,paddingX:4,paddingBottom:12,children:(0,T.jsxs)(l,{variant:`line`,width:`full`,maxWidth:`100%`,wordBreak:`break-all`,style:{tableLayout:`fixed`},children:[(0,T.jsx)(i,{width:`full`,children:(0,T.jsxs)(e,{width:`full`,children:[(0,T.jsx)(u,{width:`30%`,children:`Model name`}),(0,T.jsx)(u,{width:`30%`,children:`Regex match rule`}),(0,T.jsx)(u,{children:`Input cost`}),(0,T.jsx)(u,{children:`Output cost`}),(0,T.jsx)(u,{width:`64px`,padding:1})]})}),(0,T.jsxs)(r,{width:`full`,children:[f.isLoading&&Array.from({length:3}).map((t,n)=>(0,T.jsxs)(e,{children:[Array.from({length:4}).map((e,t)=>(0,T.jsx)(c,{children:(0,T.jsx)(p,{height:`20px`})},t)),(0,T.jsx)(c,{padding:1})]},n)),f.data?.map(t=>(0,T.jsxs)(e,{width:`full`,children:[(0,T.jsx)(c,{children:(0,T.jsx)(_,{truncate:!0,color:t.updatedAt?`green.500`:void 0,children:t.model})}),(0,T.jsx)(c,{padding:0,children:(0,T.jsx)(v,{justifyContent:`space-between`,paddingX:4,marginX:2,maxWidth:`100%`,children:(0,T.jsx)(s,{truncate:!0,color:t.updatedAt?`green.500`:void 0,height:`32px`,lineHeight:`22px`,borderRadius:`6px`,border:`1px solid`,borderColor:`border`,bg:`bg.subtle`,paddingY:1,paddingX:2,children:t.regex})})}),(0,T.jsx)(c,{padding:0,children:(0,T.jsx)(_,{justifyContent:`space-between`,paddingX:4,marginX:2,color:t.id?`green.500`:void 0,children:t.inputCostPerToken?.toLocaleString(`fullwide`,{useGrouping:!1,maximumSignificantDigits:20})})}),(0,T.jsx)(c,{padding:0,children:(0,T.jsx)(_,{justifyContent:`space-between`,paddingX:4,marginX:2,color:t.id?`green.500`:void 0,children:t.outputCostPerToken?.toLocaleString(`fullwide`,{useGrouping:!1,maximumSignificantDigits:20})})}),(0,T.jsx)(c,{padding:1,children:(0,T.jsx)(D,{id:t.id,model:t.model,projectId:t.projectId})})]},t.model))]})]})})]})}function D({id:e,model:n,projectId:r}){let{openDrawer:i}=o(),s=S.llmModelCost.getAllForProject.useQuery({projectId:r??``},{enabled:!!r}),c=S.llmModelCost.delete.useMutation();return(0,T.jsxs)(a.Root,{children:[(0,T.jsx)(a.Trigger,{minWidth:0,asChild:!0,children:(0,T.jsx)(f,{variant:`ghost`,children:(0,T.jsx)(t,{})})}),(0,T.jsxs)(a.Content,{children:[!e&&(0,T.jsx)(a.Item,{value:`clone`,onClick:e=>{e.stopPropagation(),i(`llmModelCost`,{cloneModel:n})},children:`Clone`}),e&&(0,T.jsx)(a.Item,{value:`edit`,onClick:t=>{t.stopPropagation(),i(`llmModelCost`,{id:e})},children:`Edit`}),e&&(0,T.jsx)(a.Item,{value:`delete`,color:`red.600`,onClick:t=>{t.stopPropagation(),c.mutate({projectId:r??``,id:e},{onSuccess:()=>{m.create({title:`Success`,description:`LLM model cost deleted successfully`,type:`success`,meta:{closable:!0}}),s.refetch()},onError:e=>{x(e)||m.create({title:`Error`,description:`Error deleting LLM model cost`,type:`error`,meta:{closable:!0}})}})},children:`Delete`})]})]})}function O(){let{project:e}=C();return(0,T.jsx)(w,{children:(0,T.jsx)(E,{projectId:e?.id})})}export{O as default};
2
+ //# sourceMappingURL=model-costs-C1RbgK--.js.map
@@ -1,2 +1,2 @@
1
- import{s as e}from"./chunk-Bj-mKKzh.js";import{t}from"./react-C7JcuhbW.js";import{$s as n,Da as r,Fa as i,Qs as a,Ss as o,Xa as s,Xr as c,Xs as l,Ys as ee,Zs as u,_s as d,an as f,bi as p,bs as te,gi as m,in as h,on as ne,qi as g,r as _,rn as v,vi as y,vs as b,wa as x,xi as S,xs as C,ys as w}from"./command-bar-CaJygoez.js";import{j as T,n as E,r as D}from"./stack-oJ9iWdbl.js";import{t as O}from"./box-BsM8YLGl.js";import{t as k}from"./tooltip-AEm0YeiF.js";import{n as A}from"./toaster-C_DYALhL.js";import{an as j,c as M,f as N}from"./dist-SwV3YZv3.js";import{t as P}from"./heading-D90dlSnH.js";import{t as F}from"./text-CwTrMF8x.js";import{t as I}from"./h-stack-BKLDJ2vg.js";import{r as L,t as re}from"./card-CMtKVPVl.js";import{t as ie}from"./spacer-2LJJGbo8.js";import{t as R}from"./v-stack-EOPQ57OZ.js";import{s as z}from"./auth-client-D3UhxhQi.js";import{t as B}from"./useOrganizationTeamProject-DC0iozx2.js";import{t as V}from"./HorizontalFormControl-BCD7-fcT.js";import{t as H}from"./brain-circuit-GfrhGCkg.js";import{t as U}from"./SettingsLayout-CLCGxMAe.js";var W=e(t());function G(e){let{projectId:t,initialValue:n,onSuccess:r,onError:i}=e,[a,o]=(0,W.useState)(n),[s,c]=(0,W.useState)(!1),l=z.project.updateEmbeddingsModel.useMutation();return{value:a,setValue:o,isSaving:s,update:(0,W.useCallback)(async e=>{c(!0);try{await l.mutateAsync({projectId:t??``,embeddingsModel:e}),A.create({title:`Embeddings Model Updated`,type:`success`,duration:3e3,meta:{closable:!0}}),r?.()}catch(e){i?.(e),A.create({title:`Failed to update embeddings model`,description:String(e),type:`error`,duration:4e3,meta:{closable:!0}})}finally{c(!1)}},[l,i,r,t])}}function K(e){let{projectId:t,initialValue:n,onSuccess:r,onError:i}=e,[a,o]=(0,W.useState)(n),[s,c]=(0,W.useState)(!1),l=z.project.updateTopicClusteringModel.useMutation();return{value:a,setValue:o,isSaving:s,update:(0,W.useCallback)(async e=>{c(!0);try{await l.mutateAsync({projectId:t??``,topicClusteringModel:e}),A.create({title:`Topic Clustering Model Updated`,type:`success`,duration:3e3,meta:{closable:!0}}),r?.()}catch(e){i?.(e),A.create({title:`Failed to update topic clustering model`,description:String(e),type:`error`,duration:4e3,meta:{closable:!0}})}finally{c(!1)}},[l,i,r,t])}}var q=T();function J(){let{project:e,organization:t,hasPermission:m}=B(),y=m(`project:manage`),{providers:T,isLoading:A,refetch:V}=S({projectId:e?.id}),{openDrawer:G,drawerOpen:K}=_(),J=K(`editModelProvider`),Y=z.modelProvider.update.useMutation(),[X,Z]=(0,W.useState)(null),Q=(0,W.useMemo)(()=>T?Object.values(T).filter(e=>e.enabled):[],[T]),ae=(0,W.useMemo)(()=>Object.keys(M).map(e=>({provider:e,name:M[e]?.name??e,icon:p[e]})),[]),oe=t=>ne({providerKey:t,project:e,enabledProvidersCount:Q.length}),$=t=>h(t,e),se=z.useContext();return(0,W.useEffect)(()=>{J||(V(),se.organization.getAll.invalidate())},[J]),(0,q.jsx)(U,{children:(0,q.jsxs)(R,{gap:6,width:`full`,align:`start`,children:[(0,q.jsxs)(I,{width:`full`,marginTop:2,children:[(0,q.jsx)(P,{as:`h2`,children:`Model Providers`}),(0,q.jsx)(ie,{}),(0,q.jsxs)(g.Root,{children:[(0,q.jsx)(k,{content:`You need model provider manage permissions to add new providers.`,disabled:y,children:(0,q.jsx)(g.Trigger,{asChild:!0,children:(0,q.jsxs)(c.HeaderButton,{disabled:!y,children:[(0,q.jsx)(i,{}),` Add Model Provider`]})})}),(0,q.jsx)(g.Content,{children:ae.map(n=>(0,q.jsx)(g.Item,{value:n.provider,onClick:()=>{e?.id&&G(`editModelProvider`,{projectId:e.id,organizationId:t?.id,providerKey:n.provider,modelProviderId:`new`})},children:(0,q.jsxs)(I,{gap:3,children:[(0,q.jsx)(O,{width:`20px`,height:`20px`,children:n.icon}),(0,q.jsx)(F,{children:n.name})]})},n.provider))})]})]}),A?(0,q.jsx)(D,{}):Q.length===0?(0,q.jsx)(a,{width:`full`,children:(0,q.jsxs)(ee,{children:[(0,q.jsx)(u,{children:(0,q.jsx)(H,{size:24})}),(0,q.jsxs)(R,{textAlign:`center`,children:[(0,q.jsx)(n,{children:`No model providers`}),(0,q.jsx)(l,{children:`Add a model provider to get started`})]})]})}):(0,q.jsx)(L,{width:`full`,overflow:`hidden`,children:(0,q.jsx)(re,{paddingY:0,paddingX:0,children:(0,q.jsxs)(C,{variant:`line`,size:`md`,width:`full`,children:[(0,q.jsx)(te,{children:(0,q.jsxs)(o,{children:[(0,q.jsx)(w,{children:`Provider`}),(0,q.jsx)(w,{children:`Scope`}),(0,q.jsx)(w,{})]})}),(0,q.jsx)(d,{children:Q.map(n=>{let i=p[n.provider],a=M[n.provider];return(0,q.jsxs)(o,{children:[(0,q.jsx)(b,{children:(0,q.jsxs)(I,{gap:3,align:`center`,children:[(0,q.jsx)(O,{width:`24px`,height:`24px`,children:i}),(0,q.jsx)(F,{children:n.name??a?.name??n.provider}),oe(n.provider)&&(0,q.jsx)(j,{colorPalette:`blue`,children:`Default Model`})]})}),(0,q.jsx)(b,{children:(0,q.jsx)(v,{scopes:n.scopes,fallbackScopeType:n.scopeType})}),(0,q.jsx)(b,{textAlign:`right`,children:(0,q.jsxs)(g.Root,{children:[(0,q.jsx)(k,{content:`You need model provider manage permissions to edit or delete providers.`,disabled:y,children:(0,q.jsx)(g.Trigger,{asChild:!0,children:(0,q.jsx)(E,{variant:`ghost`,disabled:!y,children:(0,q.jsx)(s,{})})})}),(0,q.jsxs)(g.Content,{children:[(0,q.jsx)(g.Item,{value:`edit`,onClick:r=>{r.stopPropagation(),G(`editModelProvider`,{projectId:e?.id,organizationId:t?.id,modelProviderId:n.id,providerKey:n.provider})},children:(0,q.jsxs)(O,{display:`flex`,alignItems:`center`,gap:2,children:[(0,q.jsx)(r,{size:14}),`Edit Provider`]})}),(0,q.jsx)(g.Item,{value:`disable`,color:`red`,onClick:e=>{e.stopPropagation(),Z({id:n.id??void 0,provider:n.provider,name:a?.name??n.provider})},children:(0,q.jsxs)(O,{display:`flex`,alignItems:`center`,gap:2,children:[(0,q.jsx)(x,{size:14}),`Delete Provider`]})})]})]})})]},n.id??n.provider)})})]})})}),(0,q.jsx)(N.Root,{open:!!X,onOpenChange:e=>{e.open||Z(null)},children:(0,q.jsxs)(N.Content,{children:[(0,q.jsx)(N.Header,{children:(0,q.jsxs)(N.Title,{children:[`Delete `,X?.name,`?`]})}),(0,q.jsx)(N.Body,{children:X&&$(X.provider)?(0,q.jsxs)(R,{gap:3,align:`start`,children:[(0,q.jsx)(F,{children:`This provider is currently being used for one or more default models and cannot be deleted.`}),(0,q.jsx)(F,{fontWeight:`medium`,children:`Please change the following before deleting:`}),(0,q.jsxs)(R,{gap:2,align:`start`,paddingLeft:4,children:[f(X.provider,e?.defaultModel??null,null,null)&&(0,q.jsx)(F,{children:`• Default Model`}),f(X.provider,null,null,e?.embeddingsModel??null)&&(0,q.jsx)(F,{children:`• Embeddings Model`}),f(X.provider,null,e?.topicClusteringModel??null,null)&&(0,q.jsx)(F,{children:`• Topic Clustering Model`})]})]}):(0,q.jsx)(F,{children:`This provider will no longer be available for use.`})}),(0,q.jsxs)(N.Footer,{children:[(0,q.jsx)(N.ActionTrigger,{asChild:!0,children:(0,q.jsx)(E,{variant:`outline`,children:`Cancel`})}),(0,q.jsx)(E,{colorPalette:`red`,loading:Y.isPending,disabled:X?$(X.provider):!1,onClick:async()=>{X&&e?.id&&(await Y.mutateAsync({id:X.id,projectId:e.id,provider:X.provider,enabled:!1}),Z(null),await V())},children:`Delete`})]}),(0,q.jsx)(N.CloseTrigger,{})]})})]})})}function Y(){let{project:e}=B(),t=K({projectId:e?.id,initialValue:e?.topicClusteringModel??`openai/gpt-5.2`});return(0,q.jsx)(V,{label:`Topic Clustering Model`,helper:`For generating topic names`,paddingY:4,borderBottomWidth:`1px`,children:(0,q.jsxs)(I,{children:[(0,q.jsx)(m,{model:t.value,options:y.filter(e=>e.mode===`chat`).map(e=>e.value),onChange:e=>{t.setValue(e),t.update(e)},mode:`chat`}),t.isSaving&&(0,q.jsx)(D,{size:`sm`,marginRight:2})]})})}function X(){let{project:e}=B(),t=G({projectId:e?.id,initialValue:e?.embeddingsModel??`openai/text-embedding-3-small`});return(0,q.jsx)(V,{label:`Embeddings Model`,helper:`For embeddings to be used in topic clustering and evaluations`,paddingY:4,children:(0,q.jsxs)(I,{children:[(0,q.jsx)(m,{model:t.value,options:y.filter(e=>e.mode===`embedding`).map(e=>e.value),onChange:e=>{t.setValue(e),t.update(e)},mode:`embedding`}),t.isSaving&&(0,q.jsx)(D,{size:`sm`,marginRight:2})]})})}export{X as EmbeddingsModel,Y as TopicClusteringModel,J as default};
2
- //# sourceMappingURL=model-providers-B5UjRgS_.js.map
1
+ import{s as e}from"./chunk-Bj-mKKzh.js";import{t}from"./react-C7JcuhbW.js";import{$s as n,Da as r,Fa as i,Qs as a,Ss as o,Xa as s,Xr as c,Xs as l,Ys as ee,Zs as u,_s as d,an as f,bi as p,bs as te,gi as m,in as h,on as ne,qi as g,r as _,rn as v,vi as y,vs as b,wa as x,xi as S,xs as C,ys as w}from"./command-bar-DUK45yin.js";import{j as T,n as E,r as D}from"./stack-oJ9iWdbl.js";import{t as O}from"./box-BsM8YLGl.js";import{t as k}from"./tooltip-AEm0YeiF.js";import{n as A}from"./toaster-C_DYALhL.js";import{an as j,c as M,f as N}from"./dist-Cds4Mqhj.js";import{t as P}from"./heading-D90dlSnH.js";import{t as F}from"./text-CwTrMF8x.js";import{t as I}from"./h-stack-BKLDJ2vg.js";import{r as L,t as re}from"./card-CMtKVPVl.js";import{t as ie}from"./spacer-2LJJGbo8.js";import{t as R}from"./v-stack-EOPQ57OZ.js";import{s as z}from"./auth-client-D3UhxhQi.js";import{t as B}from"./useOrganizationTeamProject-DC0iozx2.js";import{t as V}from"./HorizontalFormControl-BCD7-fcT.js";import{t as H}from"./brain-circuit-GfrhGCkg.js";import{t as U}from"./SettingsLayout--1gdEuhv.js";var W=e(t());function G(e){let{projectId:t,initialValue:n,onSuccess:r,onError:i}=e,[a,o]=(0,W.useState)(n),[s,c]=(0,W.useState)(!1),l=z.project.updateEmbeddingsModel.useMutation();return{value:a,setValue:o,isSaving:s,update:(0,W.useCallback)(async e=>{c(!0);try{await l.mutateAsync({projectId:t??``,embeddingsModel:e}),A.create({title:`Embeddings Model Updated`,type:`success`,duration:3e3,meta:{closable:!0}}),r?.()}catch(e){i?.(e),A.create({title:`Failed to update embeddings model`,description:String(e),type:`error`,duration:4e3,meta:{closable:!0}})}finally{c(!1)}},[l,i,r,t])}}function K(e){let{projectId:t,initialValue:n,onSuccess:r,onError:i}=e,[a,o]=(0,W.useState)(n),[s,c]=(0,W.useState)(!1),l=z.project.updateTopicClusteringModel.useMutation();return{value:a,setValue:o,isSaving:s,update:(0,W.useCallback)(async e=>{c(!0);try{await l.mutateAsync({projectId:t??``,topicClusteringModel:e}),A.create({title:`Topic Clustering Model Updated`,type:`success`,duration:3e3,meta:{closable:!0}}),r?.()}catch(e){i?.(e),A.create({title:`Failed to update topic clustering model`,description:String(e),type:`error`,duration:4e3,meta:{closable:!0}})}finally{c(!1)}},[l,i,r,t])}}var q=T();function J(){let{project:e,organization:t,hasPermission:m}=B(),y=m(`project:manage`),{providers:T,isLoading:A,refetch:V}=S({projectId:e?.id}),{openDrawer:G,drawerOpen:K}=_(),J=K(`editModelProvider`),Y=z.modelProvider.update.useMutation(),[X,Z]=(0,W.useState)(null),Q=(0,W.useMemo)(()=>T?Object.values(T).filter(e=>e.enabled):[],[T]),ae=(0,W.useMemo)(()=>Object.keys(M).map(e=>({provider:e,name:M[e]?.name??e,icon:p[e]})),[]),oe=t=>ne({providerKey:t,project:e,enabledProvidersCount:Q.length}),$=t=>h(t,e),se=z.useContext();return(0,W.useEffect)(()=>{J||(V(),se.organization.getAll.invalidate())},[J]),(0,q.jsx)(U,{children:(0,q.jsxs)(R,{gap:6,width:`full`,align:`start`,children:[(0,q.jsxs)(I,{width:`full`,marginTop:2,children:[(0,q.jsx)(P,{as:`h2`,children:`Model Providers`}),(0,q.jsx)(ie,{}),(0,q.jsxs)(g.Root,{children:[(0,q.jsx)(k,{content:`You need model provider manage permissions to add new providers.`,disabled:y,children:(0,q.jsx)(g.Trigger,{asChild:!0,children:(0,q.jsxs)(c.HeaderButton,{disabled:!y,children:[(0,q.jsx)(i,{}),` Add Model Provider`]})})}),(0,q.jsx)(g.Content,{children:ae.map(n=>(0,q.jsx)(g.Item,{value:n.provider,onClick:()=>{e?.id&&G(`editModelProvider`,{projectId:e.id,organizationId:t?.id,providerKey:n.provider,modelProviderId:`new`})},children:(0,q.jsxs)(I,{gap:3,children:[(0,q.jsx)(O,{width:`20px`,height:`20px`,children:n.icon}),(0,q.jsx)(F,{children:n.name})]})},n.provider))})]})]}),A?(0,q.jsx)(D,{}):Q.length===0?(0,q.jsx)(a,{width:`full`,children:(0,q.jsxs)(ee,{children:[(0,q.jsx)(u,{children:(0,q.jsx)(H,{size:24})}),(0,q.jsxs)(R,{textAlign:`center`,children:[(0,q.jsx)(n,{children:`No model providers`}),(0,q.jsx)(l,{children:`Add a model provider to get started`})]})]})}):(0,q.jsx)(L,{width:`full`,overflow:`hidden`,children:(0,q.jsx)(re,{paddingY:0,paddingX:0,children:(0,q.jsxs)(C,{variant:`line`,size:`md`,width:`full`,children:[(0,q.jsx)(te,{children:(0,q.jsxs)(o,{children:[(0,q.jsx)(w,{children:`Provider`}),(0,q.jsx)(w,{children:`Scope`}),(0,q.jsx)(w,{})]})}),(0,q.jsx)(d,{children:Q.map(n=>{let i=p[n.provider],a=M[n.provider];return(0,q.jsxs)(o,{children:[(0,q.jsx)(b,{children:(0,q.jsxs)(I,{gap:3,align:`center`,children:[(0,q.jsx)(O,{width:`24px`,height:`24px`,children:i}),(0,q.jsx)(F,{children:n.name??a?.name??n.provider}),oe(n.provider)&&(0,q.jsx)(j,{colorPalette:`blue`,children:`Default Model`})]})}),(0,q.jsx)(b,{children:(0,q.jsx)(v,{scopes:n.scopes,fallbackScopeType:n.scopeType})}),(0,q.jsx)(b,{textAlign:`right`,children:(0,q.jsxs)(g.Root,{children:[(0,q.jsx)(k,{content:`You need model provider manage permissions to edit or delete providers.`,disabled:y,children:(0,q.jsx)(g.Trigger,{asChild:!0,children:(0,q.jsx)(E,{variant:`ghost`,disabled:!y,children:(0,q.jsx)(s,{})})})}),(0,q.jsxs)(g.Content,{children:[(0,q.jsx)(g.Item,{value:`edit`,onClick:r=>{r.stopPropagation(),G(`editModelProvider`,{projectId:e?.id,organizationId:t?.id,modelProviderId:n.id,providerKey:n.provider})},children:(0,q.jsxs)(O,{display:`flex`,alignItems:`center`,gap:2,children:[(0,q.jsx)(r,{size:14}),`Edit Provider`]})}),(0,q.jsx)(g.Item,{value:`disable`,color:`red`,onClick:e=>{e.stopPropagation(),Z({id:n.id??void 0,provider:n.provider,name:a?.name??n.provider})},children:(0,q.jsxs)(O,{display:`flex`,alignItems:`center`,gap:2,children:[(0,q.jsx)(x,{size:14}),`Delete Provider`]})})]})]})})]},n.id??n.provider)})})]})})}),(0,q.jsx)(N.Root,{open:!!X,onOpenChange:e=>{e.open||Z(null)},children:(0,q.jsxs)(N.Content,{children:[(0,q.jsx)(N.Header,{children:(0,q.jsxs)(N.Title,{children:[`Delete `,X?.name,`?`]})}),(0,q.jsx)(N.Body,{children:X&&$(X.provider)?(0,q.jsxs)(R,{gap:3,align:`start`,children:[(0,q.jsx)(F,{children:`This provider is currently being used for one or more default models and cannot be deleted.`}),(0,q.jsx)(F,{fontWeight:`medium`,children:`Please change the following before deleting:`}),(0,q.jsxs)(R,{gap:2,align:`start`,paddingLeft:4,children:[f(X.provider,e?.defaultModel??null,null,null)&&(0,q.jsx)(F,{children:`• Default Model`}),f(X.provider,null,null,e?.embeddingsModel??null)&&(0,q.jsx)(F,{children:`• Embeddings Model`}),f(X.provider,null,e?.topicClusteringModel??null,null)&&(0,q.jsx)(F,{children:`• Topic Clustering Model`})]})]}):(0,q.jsx)(F,{children:`This provider will no longer be available for use.`})}),(0,q.jsxs)(N.Footer,{children:[(0,q.jsx)(N.ActionTrigger,{asChild:!0,children:(0,q.jsx)(E,{variant:`outline`,children:`Cancel`})}),(0,q.jsx)(E,{colorPalette:`red`,loading:Y.isPending,disabled:X?$(X.provider):!1,onClick:async()=>{X&&e?.id&&(await Y.mutateAsync({id:X.id,projectId:e.id,provider:X.provider,enabled:!1}),Z(null),await V())},children:`Delete`})]}),(0,q.jsx)(N.CloseTrigger,{})]})})]})})}function Y(){let{project:e}=B(),t=K({projectId:e?.id,initialValue:e?.topicClusteringModel??`openai/gpt-5.2`});return(0,q.jsx)(V,{label:`Topic Clustering Model`,helper:`For generating topic names`,paddingY:4,borderBottomWidth:`1px`,children:(0,q.jsxs)(I,{children:[(0,q.jsx)(m,{model:t.value,options:y.filter(e=>e.mode===`chat`).map(e=>e.value),onChange:e=>{t.setValue(e),t.update(e)},mode:`chat`}),t.isSaving&&(0,q.jsx)(D,{size:`sm`,marginRight:2})]})})}function X(){let{project:e}=B(),t=G({projectId:e?.id,initialValue:e?.embeddingsModel??`openai/text-embedding-3-small`});return(0,q.jsx)(V,{label:`Embeddings Model`,helper:`For embeddings to be used in topic clustering and evaluations`,paddingY:4,children:(0,q.jsxs)(I,{children:[(0,q.jsx)(m,{model:t.value,options:y.filter(e=>e.mode===`embedding`).map(e=>e.value),onChange:e=>{t.setValue(e),t.update(e)},mode:`embedding`}),t.isSaving&&(0,q.jsx)(D,{size:`sm`,marginRight:2})]})})}export{X as EmbeddingsModel,Y as TopicClusteringModel,J as default};
2
+ //# sourceMappingURL=model-providers-Pv3ML_-t.js.map
@@ -1,2 +1,2 @@
1
- import{s as e}from"./chunk-Bj-mKKzh.js";import{t}from"./react-C7JcuhbW.js";import{h as n,ls as r,mn as i,ss as a}from"./command-bar-CaJygoez.js";import{j as o,n as s,r as c}from"./stack-oJ9iWdbl.js";import{t as l}from"./box-BsM8YLGl.js";import{n as u}from"./LoadingScreen--vgXk5-2.js";import{t as d}from"./text-CwTrMF8x.js";import{t as f}from"./h-stack-BKLDJ2vg.js";import{t as p}from"./v-stack-EOPQ57OZ.js";import{s as m}from"./auth-client-D3UhxhQi.js";import{t as h}from"./chevron-left-D0kd9CrF.js";import{n as g,t as _}from"./useAnnotationQueues-2DKZTC7r.js";import{r as v}from"./next-router-C6sliiV7.js";import{t as y}from"./useOrganizationTeamProject-DC0iozx2.js";var b=e(t()),x=o();function S(e){return(0,x.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:e.width??564,height:e.height??424,fill:`none`,viewBox:`-40 0 630 424`,children:[(0,x.jsx)(`path`,{fill:`#ECC94B`,d:`M361.835 194.167c0 50.86-41.23 92.09-92.09 92.09-33.367 0-62.597-17.756-78.773-44.352-8.464-13.919-13.317-30.246-13.317-47.738 0-50.861 41.23-92.09 92.09-92.09 26.897 0 51.124 11.549 67.977 29.944 14.972 16.402 24.113 38.22 24.113 62.146`}),(0,x.jsx)(`path`,{fill:`#F6E05E`,d:`M351.039 179.797c0 50.86-41.23 92.09-92.09 92.09-26.935 0-51.124-11.549-67.977-29.944-8.464-13.919-13.317-30.246-13.317-47.738 0-50.86 41.23-92.09 92.09-92.09 26.897 0 51.124 11.549 67.977 29.944 8.464 13.919 13.317 30.245 13.317 47.738`}),(0,x.jsx)(`path`,{fill:`#3C2415`,d:`M272.718 216.024c-10.307 0-18.658-8.69-18.658-19.374 0-1.128.94-2.069 2.069-2.069 1.128 0 2.069.941 2.069 2.069 0 8.389 6.508 15.236 14.52 15.236s14.521-6.847 14.521-15.236c0-1.128.941-2.069 2.069-2.069s2.069.941 2.069 2.069c0 10.684-8.351 19.374-18.659 19.374M241.684 170.731c-6.132 0-11.135-5.192-11.135-11.549 0-.677.564-1.242 1.241-1.242s1.242.565 1.242 1.242c0 5.003 3.874 9.066 8.652 9.066s8.652-4.063 8.652-9.066c0-.677.564-1.242 1.242-1.242.677 0 1.241.565 1.241 1.242 0 6.395-5.003 11.549-11.135 11.549`}),(0,x.jsx)(`path`,{fill:`#3C2415`,stroke:`#3C2415`,strokeMiterlimit:`10`,strokeWidth:`0.295`,d:`M241.683 173.139c-7.448 0-13.542-6.245-13.542-13.957a3.65 3.65 0 0 1 3.649-3.649 3.653 3.653 0 0 1 3.649 3.649c0 3.687 2.783 6.659 6.244 6.659s6.245-3.01 6.245-6.659a3.653 3.653 0 0 1 3.649-3.649 3.653 3.653 0 0 1 3.649 3.649c-.038 7.712-6.094 13.957-13.543 13.957Z`}),(0,x.jsx)(`path`,{fill:`#3C2415`,d:`M307.779 174.831c-7.448 0-13.543-6.245-13.543-13.957a3.653 3.653 0 0 1 3.649-3.649 3.63 3.63 0 0 1 3.649 3.649c0 3.687 2.822 6.659 6.245 6.659 3.461 0 6.245-3.01 6.245-6.659a3.65 3.65 0 0 1 3.649-3.649 3.653 3.653 0 0 1 3.649 3.649c-.038 7.712-6.095 13.957-13.543 13.957`}),(0,x.jsx)(u.path,{id:`sun-flares`,fill:`#F6E05E`,animate:{rotate:360},transition:{duration:20,repeat:1/0,ease:`linear`},style:{transformOrigin:`center`},d:`M269.745 83.192c-2.294 0-4.138-.903-4.138-1.994v-37.58c0-1.092 1.844-1.995 4.138-1.995 2.295 0 4.138.903 4.138 1.994v37.581c.038 1.091-1.843 1.994-4.138 1.994M214.259 98.052c-1.994 1.128-4.026 1.316-4.59.338L190.86 65.85c-.564-.94.602-2.67 2.596-3.8 1.993-1.128 4.025-1.316 4.589-.338l18.809 32.54c.565.94-.602 2.633-2.595 3.8M173.63 138.679c-1.129 1.994-2.859 3.16-3.8 2.596l-32.54-18.809c-.94-.565-.79-2.596.339-4.59 1.128-1.994 2.859-3.16 3.799-2.596l32.54 18.81c.978.526.828 2.595-.338 4.589M158.772 194.166c0 2.295-.903 4.138-1.994 4.138h-37.581c-1.091 0-1.994-1.843-1.994-4.138s.903-4.138 1.994-4.138h37.581c1.091 0 1.994 1.844 1.994 4.138M173.632 249.654c1.128 1.994 1.316 4.025.338 4.589l-32.54 18.81c-.94.564-2.671-.602-3.799-2.596s-1.317-4.025-.339-4.59l32.54-18.809c.941-.527 2.671.64 3.8 2.596M214.259 290.282c1.993 1.128 3.16 2.859 2.595 3.799l-18.809 32.54c-.564.941-2.596.79-4.589-.338s-3.16-2.859-2.596-3.8l18.809-32.54c.564-.94 2.596-.79 4.59.339M269.745 305.179c2.295 0 4.138.903 4.138 1.993v37.581c0 1.091-1.843 1.994-4.138 1.994s-4.138-.903-4.138-1.994v-37.581c0-1.128 1.881-1.993 4.138-1.993M325.271 290.282c1.994-1.129 4.025-1.317 4.59-.339l18.809 32.54c.564.94-.602 2.671-2.596 3.799s-4.025 1.317-4.589.339l-18.81-32.54c-.564-.94.602-2.633 2.596-3.799M365.899 249.654c1.128-1.994 2.859-3.16 3.799-2.596l32.54 18.809c.941.565.79 2.596-.338 4.59s-2.859 3.16-3.8 2.596l-32.54-18.81c-.978-.526-.827-2.595.339-4.589M380.758 194.166c0-2.294.903-4.138 1.994-4.138h37.58c1.091 0 1.994 1.844 1.994 4.138 0 2.295-.903 4.138-1.994 4.138h-37.58c-1.091 0-1.994-1.843-1.994-4.138M365.898 138.679c-1.128-1.994-1.316-4.025-.338-4.589l32.54-18.81c.94-.564 2.671.602 3.799 2.596s1.317 4.025.339 4.59l-32.54 18.809c-.978.526-2.671-.602-3.8-2.596M325.271 98.051c-1.994-1.129-3.16-2.859-2.596-3.8l18.81-32.54c.564-.94 2.595-.79 4.589.34 1.994 1.128 3.16 2.858 2.596 3.799l-18.809 32.54c-.565.94-2.634.79-4.59-.339`}),(0,x.jsx)(u.path,{id:`clouds`,fill:`#BEE3F8`,animate:{x:[-30,30,-30],y:[0,20,0,20,0,20,0,20,0]},transition:{duration:40,repeat:1/0,ease:`easeInOut`},d:`M547.865 67.635c0-17.642-14.314-31.956-31.956-31.956s-31.956 14.314-31.956 31.956v.73c-1.505-.457-3.1-.73-4.741-.73-8.844 0-16.001 7.157-16.001 16s7.157 15.956 16.001 15.956h68.653c8.844 0 15.955-7.157 15.955-15.955 0-8.844-7.157-16.001-15.955-16.001M64.004 332.161c0-13.357-10.805-24.161-24.161-24.161s-24.161 10.804-24.161 24.161v.547a11.7 11.7 0 0 0-3.602-.547c-6.655 0-12.08 5.425-12.08 12.08s5.425 12.081 12.08 12.081h51.924c6.655 0 12.08-5.425 12.08-12.081s-5.38-12.08-12.08-12.08M544.538 361.896c-2.051 0-4.011.319-5.88.912-5.653-7.795-14.771-12.855-25.119-12.855a30.87 30.87 0 0 0-25.118 12.855 19.3 19.3 0 0 0-5.881-.912c-10.53 0-19.055 8.525-19.055 19.055 0 10.531 8.525 19.056 19.055 19.056a19.3 19.3 0 0 0 5.881-.912c5.653 7.795 14.77 12.855 25.118 12.855a30.87 30.87 0 0 0 25.119-12.855c1.869.593 3.829.912 5.88.912 10.531 0 19.055-8.525 19.055-19.056 0-10.53-8.524-19.055-19.055-19.055M55.029 8.087c-1.231 0-2.462.182-3.602.547C47.964 3.847 42.357.747 36.066.747c-6.337 0-11.944 3.1-15.363 7.887a11.7 11.7 0 0 0-3.601-.547c-6.428 0-11.67 5.242-11.67 11.67 0 6.427 5.242 11.67 11.67 11.67 1.23 0 2.462-.183 3.601-.547 3.465 4.786 9.072 7.886 15.363 7.886 6.336 0 11.944-3.1 15.363-7.886 1.14.364 2.324.547 3.6.547 6.429 0 11.671-5.243 11.671-11.67 0-6.428-5.242-11.67-11.67-11.67`})]})}function C(){let{"queue-item":e}=v().query,{assignedQueueItems:t,queuesLoading:r}=_({showQueueAndUser:!0,allQueueItems:!0}),{project:a}=y(),o=m.useContext(),s=(0,b.useMemo)(()=>[...t??[]].filter(e=>!e.doneAt),[t]),c=(0,b.useMemo)(()=>s.map(e=>`${e.id}-${e.doneAt}`).join(`,`),[s]),u=s.find(t=>t.id===e);u||=s[0];let f=async()=>{await o.annotation.getOptimizedAnnotationQueues.invalidate(),await o.annotation.getPendingItemsCount.invalidate(),await o.annotation.getAssignedItemsCount.invalidate(),await o.annotation.getQueueItemsCounts.invalidate()};console.log(`currentQueueItem`,u);let h=m.traces.getById.useQuery({projectId:a?.id??``,traceId:u?.trace?.trace_id??``},{enabled:!!a?.id&&!!u?.trace?.trace_id,refetchOnWindowFocus:!1}),[C,T]=(0,b.useState)(null);return(0,b.useEffect)(()=>{h.data?.metadata.thread_id?T(h.data?.metadata.thread_id):T(null)},[h.data?.metadata.thread_id,u?.id]),r?(0,x.jsx)(g,{}):s.length===0&&!r?(0,x.jsx)(g,{children:(0,x.jsxs)(p,{height:`100%`,width:`full`,justify:`center`,backgroundColor:`gray.100`,marginTop:`-48px`,children:[(0,x.jsx)(S,{}),(0,x.jsx)(d,{fontSize:`xl`,fontWeight:`500`,children:`All tasks complete`}),(0,x.jsx)(d,{children:`Nice work!`})]})}):(0,x.jsx)(i,{display:`flex`,flexDirection:`column`,children:(0,x.jsxs)(p,{height:`100%`,width:`full`,gap:0,alignItems:`stretch`,position:`relative`,flex:`1`,children:[(0,x.jsx)(l,{flex:`1`,overflowY:`auto`,padding:4,paddingBottom:u?.trace?`100px`:4,position:`relative`,children:(0,x.jsx)(n,{threadId:C??``,traceId:u?.trace?.trace_id??``},u?.trace?.trace_id??u?.id)}),u?.trace&&(0,x.jsx)(l,{position:`absolute`,bottom:0,left:0,right:0,width:`full`,backgroundColor:`white`,borderTop:`1px solid`,borderColor:`border`,zIndex:10,children:(0,x.jsx)(w,{queueItems:s,currentQueueItem:u,refetchQueueItems:f},c)})]})})}var w=({queueItems:e,currentQueueItem:t,refetchQueueItems:n})=>{let i=v(),{project:o}=y(),[u,g]=(0,b.useState)(!1),_=e.findIndex(e=>e.id===t.id),S=async(e,t)=>{g(!0);let n=t?`/${o?.slug}/annotations/my-queue?queue-item=${e}&trace=${t}`:`/${o?.slug}/annotations/my-queue?queue-item=${e}`;await i.push(n),setTimeout(()=>g(!1),100)},C=m.annotation.markQueueItemDone.useMutation(),w=async()=>{C.mutate({queueItemId:t.id,projectId:o?.id??``},{onSuccess:async()=>{await n();let t=e[_+1];t?await S(t.id):(g(!0),await i.replace(`/${o?.slug}/annotations/my-queue`),setTimeout(()=>g(!1),100))}})};return(0,x.jsxs)(l,{boxShadow:`0px -3px 10px rgba(0, 0, 0, 0.05)`,padding:5,width:`full`,position:`relative`,children:[u&&(0,x.jsx)(l,{position:`absolute`,top:0,left:0,right:0,bottom:0,backgroundColor:`whiteAlpha.800`,zIndex:20,display:`flex`,alignItems:`center`,justifyContent:`center`,children:(0,x.jsx)(c,{})}),(0,x.jsx)(p,{children:(0,x.jsxs)(f,{gap:8,children:[(0,x.jsxs)(f,{gap:2,children:[(0,x.jsx)(s,{variant:`outline`,disabled:_===0||u,onClick:()=>{let t=e[_-1];t&&S(t.id)},children:(0,x.jsx)(h,{})}),(0,x.jsx)(s,{variant:`outline`,disabled:_===e.length-1||u,onClick:()=>{let t=e[_+1];t&&S(t.id)},children:(0,x.jsx)(a,{})})]}),(0,x.jsxs)(d,{children:[_+1,` of `,e.length]}),(0,x.jsxs)(s,{colorPalette:`blue`,disabled:t.doneAt!==null||C.isLoading||u,onClick:()=>{w()},children:[(0,x.jsx)(r,{}),` Done`]})]})})]})};export{C as default};
2
- //# sourceMappingURL=my-queue-BkEfiWyR.js.map
1
+ import{s as e}from"./chunk-Bj-mKKzh.js";import{t}from"./react-C7JcuhbW.js";import{h as n,ls as r,mn as i,ss as a}from"./command-bar-DUK45yin.js";import{j as o,n as s,r as c}from"./stack-oJ9iWdbl.js";import{t as l}from"./box-BsM8YLGl.js";import{n as u}from"./LoadingScreen--vgXk5-2.js";import{t as d}from"./text-CwTrMF8x.js";import{t as f}from"./h-stack-BKLDJ2vg.js";import{t as p}from"./v-stack-EOPQ57OZ.js";import{s as m}from"./auth-client-D3UhxhQi.js";import{t as h}from"./chevron-left-D0kd9CrF.js";import{n as g,t as _}from"./useAnnotationQueues-CA6Vk--V.js";import{r as v}from"./next-router-C6sliiV7.js";import{t as y}from"./useOrganizationTeamProject-DC0iozx2.js";var b=e(t()),x=o();function S(e){return(0,x.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:e.width??564,height:e.height??424,fill:`none`,viewBox:`-40 0 630 424`,children:[(0,x.jsx)(`path`,{fill:`#ECC94B`,d:`M361.835 194.167c0 50.86-41.23 92.09-92.09 92.09-33.367 0-62.597-17.756-78.773-44.352-8.464-13.919-13.317-30.246-13.317-47.738 0-50.861 41.23-92.09 92.09-92.09 26.897 0 51.124 11.549 67.977 29.944 14.972 16.402 24.113 38.22 24.113 62.146`}),(0,x.jsx)(`path`,{fill:`#F6E05E`,d:`M351.039 179.797c0 50.86-41.23 92.09-92.09 92.09-26.935 0-51.124-11.549-67.977-29.944-8.464-13.919-13.317-30.246-13.317-47.738 0-50.86 41.23-92.09 92.09-92.09 26.897 0 51.124 11.549 67.977 29.944 8.464 13.919 13.317 30.245 13.317 47.738`}),(0,x.jsx)(`path`,{fill:`#3C2415`,d:`M272.718 216.024c-10.307 0-18.658-8.69-18.658-19.374 0-1.128.94-2.069 2.069-2.069 1.128 0 2.069.941 2.069 2.069 0 8.389 6.508 15.236 14.52 15.236s14.521-6.847 14.521-15.236c0-1.128.941-2.069 2.069-2.069s2.069.941 2.069 2.069c0 10.684-8.351 19.374-18.659 19.374M241.684 170.731c-6.132 0-11.135-5.192-11.135-11.549 0-.677.564-1.242 1.241-1.242s1.242.565 1.242 1.242c0 5.003 3.874 9.066 8.652 9.066s8.652-4.063 8.652-9.066c0-.677.564-1.242 1.242-1.242.677 0 1.241.565 1.241 1.242 0 6.395-5.003 11.549-11.135 11.549`}),(0,x.jsx)(`path`,{fill:`#3C2415`,stroke:`#3C2415`,strokeMiterlimit:`10`,strokeWidth:`0.295`,d:`M241.683 173.139c-7.448 0-13.542-6.245-13.542-13.957a3.65 3.65 0 0 1 3.649-3.649 3.653 3.653 0 0 1 3.649 3.649c0 3.687 2.783 6.659 6.244 6.659s6.245-3.01 6.245-6.659a3.653 3.653 0 0 1 3.649-3.649 3.653 3.653 0 0 1 3.649 3.649c-.038 7.712-6.094 13.957-13.543 13.957Z`}),(0,x.jsx)(`path`,{fill:`#3C2415`,d:`M307.779 174.831c-7.448 0-13.543-6.245-13.543-13.957a3.653 3.653 0 0 1 3.649-3.649 3.63 3.63 0 0 1 3.649 3.649c0 3.687 2.822 6.659 6.245 6.659 3.461 0 6.245-3.01 6.245-6.659a3.65 3.65 0 0 1 3.649-3.649 3.653 3.653 0 0 1 3.649 3.649c-.038 7.712-6.095 13.957-13.543 13.957`}),(0,x.jsx)(u.path,{id:`sun-flares`,fill:`#F6E05E`,animate:{rotate:360},transition:{duration:20,repeat:1/0,ease:`linear`},style:{transformOrigin:`center`},d:`M269.745 83.192c-2.294 0-4.138-.903-4.138-1.994v-37.58c0-1.092 1.844-1.995 4.138-1.995 2.295 0 4.138.903 4.138 1.994v37.581c.038 1.091-1.843 1.994-4.138 1.994M214.259 98.052c-1.994 1.128-4.026 1.316-4.59.338L190.86 65.85c-.564-.94.602-2.67 2.596-3.8 1.993-1.128 4.025-1.316 4.589-.338l18.809 32.54c.565.94-.602 2.633-2.595 3.8M173.63 138.679c-1.129 1.994-2.859 3.16-3.8 2.596l-32.54-18.809c-.94-.565-.79-2.596.339-4.59 1.128-1.994 2.859-3.16 3.799-2.596l32.54 18.81c.978.526.828 2.595-.338 4.589M158.772 194.166c0 2.295-.903 4.138-1.994 4.138h-37.581c-1.091 0-1.994-1.843-1.994-4.138s.903-4.138 1.994-4.138h37.581c1.091 0 1.994 1.844 1.994 4.138M173.632 249.654c1.128 1.994 1.316 4.025.338 4.589l-32.54 18.81c-.94.564-2.671-.602-3.799-2.596s-1.317-4.025-.339-4.59l32.54-18.809c.941-.527 2.671.64 3.8 2.596M214.259 290.282c1.993 1.128 3.16 2.859 2.595 3.799l-18.809 32.54c-.564.941-2.596.79-4.589-.338s-3.16-2.859-2.596-3.8l18.809-32.54c.564-.94 2.596-.79 4.59.339M269.745 305.179c2.295 0 4.138.903 4.138 1.993v37.581c0 1.091-1.843 1.994-4.138 1.994s-4.138-.903-4.138-1.994v-37.581c0-1.128 1.881-1.993 4.138-1.993M325.271 290.282c1.994-1.129 4.025-1.317 4.59-.339l18.809 32.54c.564.94-.602 2.671-2.596 3.799s-4.025 1.317-4.589.339l-18.81-32.54c-.564-.94.602-2.633 2.596-3.799M365.899 249.654c1.128-1.994 2.859-3.16 3.799-2.596l32.54 18.809c.941.565.79 2.596-.338 4.59s-2.859 3.16-3.8 2.596l-32.54-18.81c-.978-.526-.827-2.595.339-4.589M380.758 194.166c0-2.294.903-4.138 1.994-4.138h37.58c1.091 0 1.994 1.844 1.994 4.138 0 2.295-.903 4.138-1.994 4.138h-37.58c-1.091 0-1.994-1.843-1.994-4.138M365.898 138.679c-1.128-1.994-1.316-4.025-.338-4.589l32.54-18.81c.94-.564 2.671.602 3.799 2.596s1.317 4.025.339 4.59l-32.54 18.809c-.978.526-2.671-.602-3.8-2.596M325.271 98.051c-1.994-1.129-3.16-2.859-2.596-3.8l18.81-32.54c.564-.94 2.595-.79 4.589.34 1.994 1.128 3.16 2.858 2.596 3.799l-18.809 32.54c-.565.94-2.634.79-4.59-.339`}),(0,x.jsx)(u.path,{id:`clouds`,fill:`#BEE3F8`,animate:{x:[-30,30,-30],y:[0,20,0,20,0,20,0,20,0]},transition:{duration:40,repeat:1/0,ease:`easeInOut`},d:`M547.865 67.635c0-17.642-14.314-31.956-31.956-31.956s-31.956 14.314-31.956 31.956v.73c-1.505-.457-3.1-.73-4.741-.73-8.844 0-16.001 7.157-16.001 16s7.157 15.956 16.001 15.956h68.653c8.844 0 15.955-7.157 15.955-15.955 0-8.844-7.157-16.001-15.955-16.001M64.004 332.161c0-13.357-10.805-24.161-24.161-24.161s-24.161 10.804-24.161 24.161v.547a11.7 11.7 0 0 0-3.602-.547c-6.655 0-12.08 5.425-12.08 12.08s5.425 12.081 12.08 12.081h51.924c6.655 0 12.08-5.425 12.08-12.081s-5.38-12.08-12.08-12.08M544.538 361.896c-2.051 0-4.011.319-5.88.912-5.653-7.795-14.771-12.855-25.119-12.855a30.87 30.87 0 0 0-25.118 12.855 19.3 19.3 0 0 0-5.881-.912c-10.53 0-19.055 8.525-19.055 19.055 0 10.531 8.525 19.056 19.055 19.056a19.3 19.3 0 0 0 5.881-.912c5.653 7.795 14.77 12.855 25.118 12.855a30.87 30.87 0 0 0 25.119-12.855c1.869.593 3.829.912 5.88.912 10.531 0 19.055-8.525 19.055-19.056 0-10.53-8.524-19.055-19.055-19.055M55.029 8.087c-1.231 0-2.462.182-3.602.547C47.964 3.847 42.357.747 36.066.747c-6.337 0-11.944 3.1-15.363 7.887a11.7 11.7 0 0 0-3.601-.547c-6.428 0-11.67 5.242-11.67 11.67 0 6.427 5.242 11.67 11.67 11.67 1.23 0 2.462-.183 3.601-.547 3.465 4.786 9.072 7.886 15.363 7.886 6.336 0 11.944-3.1 15.363-7.886 1.14.364 2.324.547 3.6.547 6.429 0 11.671-5.243 11.671-11.67 0-6.428-5.242-11.67-11.67-11.67`})]})}function C(){let{"queue-item":e}=v().query,{assignedQueueItems:t,queuesLoading:r}=_({showQueueAndUser:!0,allQueueItems:!0}),{project:a}=y(),o=m.useContext(),s=(0,b.useMemo)(()=>[...t??[]].filter(e=>!e.doneAt),[t]),c=(0,b.useMemo)(()=>s.map(e=>`${e.id}-${e.doneAt}`).join(`,`),[s]),u=s.find(t=>t.id===e);u||=s[0];let f=async()=>{await o.annotation.getOptimizedAnnotationQueues.invalidate(),await o.annotation.getPendingItemsCount.invalidate(),await o.annotation.getAssignedItemsCount.invalidate(),await o.annotation.getQueueItemsCounts.invalidate()};console.log(`currentQueueItem`,u);let h=m.traces.getById.useQuery({projectId:a?.id??``,traceId:u?.trace?.trace_id??``},{enabled:!!a?.id&&!!u?.trace?.trace_id,refetchOnWindowFocus:!1}),[C,T]=(0,b.useState)(null);return(0,b.useEffect)(()=>{h.data?.metadata.thread_id?T(h.data?.metadata.thread_id):T(null)},[h.data?.metadata.thread_id,u?.id]),r?(0,x.jsx)(g,{}):s.length===0&&!r?(0,x.jsx)(g,{children:(0,x.jsxs)(p,{height:`100%`,width:`full`,justify:`center`,backgroundColor:`gray.100`,marginTop:`-48px`,children:[(0,x.jsx)(S,{}),(0,x.jsx)(d,{fontSize:`xl`,fontWeight:`500`,children:`All tasks complete`}),(0,x.jsx)(d,{children:`Nice work!`})]})}):(0,x.jsx)(i,{display:`flex`,flexDirection:`column`,children:(0,x.jsxs)(p,{height:`100%`,width:`full`,gap:0,alignItems:`stretch`,position:`relative`,flex:`1`,children:[(0,x.jsx)(l,{flex:`1`,overflowY:`auto`,padding:4,paddingBottom:u?.trace?`100px`:4,position:`relative`,children:(0,x.jsx)(n,{threadId:C??``,traceId:u?.trace?.trace_id??``},u?.trace?.trace_id??u?.id)}),u?.trace&&(0,x.jsx)(l,{position:`absolute`,bottom:0,left:0,right:0,width:`full`,backgroundColor:`white`,borderTop:`1px solid`,borderColor:`border`,zIndex:10,children:(0,x.jsx)(w,{queueItems:s,currentQueueItem:u,refetchQueueItems:f},c)})]})})}var w=({queueItems:e,currentQueueItem:t,refetchQueueItems:n})=>{let i=v(),{project:o}=y(),[u,g]=(0,b.useState)(!1),_=e.findIndex(e=>e.id===t.id),S=async(e,t)=>{g(!0);let n=t?`/${o?.slug}/annotations/my-queue?queue-item=${e}&trace=${t}`:`/${o?.slug}/annotations/my-queue?queue-item=${e}`;await i.push(n),setTimeout(()=>g(!1),100)},C=m.annotation.markQueueItemDone.useMutation(),w=async()=>{C.mutate({queueItemId:t.id,projectId:o?.id??``},{onSuccess:async()=>{await n();let t=e[_+1];t?await S(t.id):(g(!0),await i.replace(`/${o?.slug}/annotations/my-queue`),setTimeout(()=>g(!1),100))}})};return(0,x.jsxs)(l,{boxShadow:`0px -3px 10px rgba(0, 0, 0, 0.05)`,padding:5,width:`full`,position:`relative`,children:[u&&(0,x.jsx)(l,{position:`absolute`,top:0,left:0,right:0,bottom:0,backgroundColor:`whiteAlpha.800`,zIndex:20,display:`flex`,alignItems:`center`,justifyContent:`center`,children:(0,x.jsx)(c,{})}),(0,x.jsx)(p,{children:(0,x.jsxs)(f,{gap:8,children:[(0,x.jsxs)(f,{gap:2,children:[(0,x.jsx)(s,{variant:`outline`,disabled:_===0||u,onClick:()=>{let t=e[_-1];t&&S(t.id)},children:(0,x.jsx)(h,{})}),(0,x.jsx)(s,{variant:`outline`,disabled:_===e.length-1||u,onClick:()=>{let t=e[_+1];t&&S(t.id)},children:(0,x.jsx)(a,{})})]}),(0,x.jsxs)(d,{children:[_+1,` of `,e.length]}),(0,x.jsxs)(s,{colorPalette:`blue`,disabled:t.doneAt!==null||C.isLoading||u,onClick:()=>{w()},children:[(0,x.jsx)(r,{}),` Done`]})]})})]})};export{C as default};
2
+ //# sourceMappingURL=my-queue-BLre2NMr.js.map
@@ -1,2 +1,2 @@
1
- import{s as e}from"./chunk-Bj-mKKzh.js";import{t}from"./react-C7JcuhbW.js";import{$s as n,Aa as r,Cn as i,Cs as a,La as o,Qs as s,Ss as c,Xr as l,Xs as u,Ys as d,Zn as f,Zs as p,_s as m,ao as h,ar as g,bs as _,er as v,io as y,ir as b,mn as x,mr as S,rr as C,tr as w,vr as T,vs as E,xs as D,ys as O}from"./command-bar-CaJygoez.js";import{j as ee,n as k,r as A}from"./stack-oJ9iWdbl.js";import{t as j}from"./box-BsM8YLGl.js";import{n as M}from"./toaster-C_DYALhL.js";import{an as N,f as P}from"./dist-SwV3YZv3.js";import{t as F}from"./text-CwTrMF8x.js";import{i as I}from"./code-FF_ibTVI.js";import{t as L}from"./input-C7emsUCL.js";import{t as R}from"./h-stack-BKLDJ2vg.js";import{r as z,t as B}from"./card-CMtKVPVl.js";import{t as te}from"./simple-grid-C3IW90zo.js";import{t as V}from"./spacer-2LJJGbo8.js";import{n as ne,r as re,t as ie}from"./stat-CHoKZ9Rr.js";import{a as H,c as U,i as ae,l as oe,n as se,o as W,r as ce,s as G,t as le}from"./ReplayStateBadge-ChyX1KUG.js";import{t as K}from"./v-stack-EOPQ57OZ.js";import{s as q}from"./auth-client-D3UhxhQi.js";import{t as ue}from"./createLucideIcon-BJKFyRLS.js";import{t as de}from"./arrow-up-right-Cmmi1ap5.js";import{t as J}from"./next-link-DuYeiiEe.js";import{t as fe}from"./OpsPageShell-DJ1WlI6-.js";var pe=ue(`pause`,[[`rect`,{x:`14`,y:`3`,width:`5`,height:`18`,rx:`1`,key:`kaeet6`}],[`rect`,{x:`5`,y:`3`,width:`5`,height:`18`,rx:`1`,key:`1wsw3u`}]]),Y=e(t()),X=ee();function me({data:e}){let t=se().data,n=t?.state===`running`,r=e.pausedKeys,i=r.length>0;return!n&&!i?null:(0,X.jsxs)(z,{overflow:`hidden`,children:[(0,X.jsx)(F,{textStyle:`xs`,fontWeight:`medium`,color:`fg.muted`,paddingX:4,paddingTop:3,paddingBottom:2,children:`Active Operations`}),(0,X.jsxs)(K,{align:`stretch`,gap:0,paddingX:4,paddingBottom:3,children:[n&&t&&(0,X.jsxs)(R,{gap:2,paddingY:2,borderBottom:i?`1px solid`:void 0,borderBottomColor:`border`,children:[(0,X.jsx)(oe,{colorPalette:`blue`,size:`sm`,children:(0,X.jsx)(U,{})}),(0,X.jsx)(F,{textStyle:`sm`,fontWeight:`medium`,children:`Replay running`}),t.currentProjection&&(0,X.jsx)(N,{size:`sm`,variant:`subtle`,colorPalette:`blue`,children:t.currentProjection}),(0,X.jsx)(V,{}),t.runId&&(0,X.jsx)(J,{href:`/ops/projections/${t.runId}`,style:{textDecoration:`none`},children:(0,X.jsx)(F,{textStyle:`xs`,color:`blue.500`,cursor:`pointer`,children:`View progress`})})]}),i&&(0,X.jsxs)(K,{align:`stretch`,gap:1,paddingY:2,children:[(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,children:`Paused pipelines`}),(0,X.jsx)(R,{gap:2,flexWrap:`wrap`,children:r.map(e=>(0,X.jsx)(N,{size:`sm`,colorPalette:`orange`,variant:`subtle`,children:e},e))})]})]})]})}function Z({label:e,value:t,sublabel:n,href:r,color:i}){let a=(0,X.jsxs)(ne,{cursor:r?`pointer`:void 0,_hover:r?{bg:`bg.subtle`}:void 0,borderRadius:`md`,padding:2,transition:`background 0.1s`,children:[(0,X.jsx)(ie,{children:(0,X.jsxs)(R,{gap:1,children:[(0,X.jsx)(F,{children:e}),r&&(0,X.jsx)(de,{size:10})]})}),(0,X.jsxs)(R,{gap:1.5,alignItems:`baseline`,children:[(0,X.jsx)(re,{color:i,children:t}),n&&(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,fontWeight:`normal`,children:n})]})]});return r?(0,X.jsx)(J,{href:r,style:{textDecoration:`none`},children:a}):a}function he(){let e=q.ops.getReplayHistory.useQuery(void 0,{refetchInterval:1e4}).data?.[0];return(0,X.jsxs)(z,{overflow:`hidden`,children:[(0,X.jsx)(J,{href:`/ops/projections`,style:{textDecoration:`none`},children:(0,X.jsxs)(R,{paddingX:4,paddingTop:3,paddingBottom:2,cursor:`pointer`,_hover:{color:`orange.500`},transition:`color 0.1s`,children:[(0,X.jsx)(F,{textStyle:`xs`,fontWeight:`medium`,color:`fg.muted`,children:`Latest Replay`}),(0,X.jsx)(de,{size:10})]})}),(0,X.jsx)(j,{paddingX:4,paddingBottom:4,children:e?(0,X.jsx)(J,{href:`/ops/projections/${e.runId}`,style:{textDecoration:`none`},children:(0,X.jsxs)(R,{gap:3,cursor:`pointer`,_hover:{opacity:.8},transition:`opacity 0.1s`,children:[(0,X.jsx)(N,{size:`sm`,variant:`subtle`,colorPalette:le(e.state),children:e.state}),(0,X.jsx)(F,{textStyle:`xs`,truncate:!0,maxWidth:`240px`,children:e.description||`—`}),(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,children:ae(e.startedAt,e.completedAt)}),(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,whiteSpace:`nowrap`,children:e.completedAt?new Date(e.completedAt).toLocaleString([],{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`}):`—`})]})}):(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,children:`No replay history`})})]})}var Q={staged:{stroke:`#06b6d4`,fill:`#06b6d4`},completed:{stroke:`#22c55e`,fill:`#22c55e`},failed:{stroke:`#ef4444`,fill:`#ef4444`},pending:`#a78bfa`,blocked:`#f97316`},ge=[{label:`2s`,ms:0},{label:`5s`,ms:5e3},{label:`15s`,ms:15e3},{label:`30s`,ms:3e4},{label:`1m`,ms:6e4}];function _e(e,t){if(e.length===0)return[];if(t<=0)return e.map(e=>({timestamp:e.timestamp,staged:e.ingestedPerSec,completed:e.completedPerSec,failed:e.failedPerSec,pending:e.pendingCount,blocked:e.blockedCount}));let n=new Map;for(let r of e){let e=Math.floor(r.timestamp/t)*t,i=n.get(e);i?(i.sum.staged+=r.ingestedPerSec,i.sum.completed+=r.completedPerSec,i.sum.failed+=r.failedPerSec,i.sum.pending+=r.pendingCount,i.sum.blocked+=r.blockedCount,i.count++):n.set(e,{sum:{timestamp:e,staged:r.ingestedPerSec,completed:r.completedPerSec,failed:r.failedPerSec,pending:r.pendingCount,blocked:r.blockedCount},count:1})}let r=[];for(let[,{sum:e,count:t}]of n)r.push({timestamp:e.timestamp,staged:e.staged/t,completed:e.completed/t,failed:e.failed/t,pending:Math.round(e.pending/t),blocked:Math.round(e.blocked/t)});return r.sort((e,t)=>e.timestamp-t.timestamp),r}function ve(e){return new Date(e).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})}function ye(e){return new Date(e).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`,second:`2-digit`})}function be(e){return e>=1e3?`${(e/1e3).toFixed(1)}k`:e===0?`0`:Number.isInteger(e)?e.toString():e.toFixed(1)}function xe(e){if(e.length<2)return[];let t=e[0].timestamp,n=e[e.length-1].timestamp,r=n-t,i=6e4;r>20*6e4?i=5*6e4:r>10*6e4&&(i=2*6e4);let a=Math.ceil(t/i)*i,o=[];for(let e=a;e<=n;e+=i)o.push(e);return o}function Se(e){if(e<=0)return 1;let t=10**Math.floor(Math.log10(e)),n=e/t,r;return r=n<=1?1:n<=2?2:n<=5?5:10,r*t}function Ce({active:e,payload:t,label:n}){if(!e||!t?.length||n==null)return null;let r=t.filter(e=>e.name!==`Pending`&&e.name!==`Blocked`),i=t.filter(e=>e.name===`Pending`||e.name===`Blocked`);return(0,X.jsxs)(j,{bg:`bg.panel`,borderWidth:`1px`,borderColor:`border`,borderRadius:`md`,padding:2,shadow:`md`,minWidth:`140px`,children:[(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,marginBottom:1,children:ye(n)}),r.map(e=>(0,X.jsxs)(R,{justify:`space-between`,gap:3,children:[(0,X.jsxs)(R,{gap:1.5,children:[(0,X.jsx)(j,{width:`6px`,height:`6px`,borderRadius:`full`,bg:e.color}),(0,X.jsx)(F,{textStyle:`xs`,children:e.name})]}),(0,X.jsxs)(F,{textStyle:`xs`,fontFamily:`mono`,fontWeight:`medium`,children:[e.value.toFixed(1),`/s`]})]},e.name)),i.length>0&&i.some(e=>e.value>0)&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(j,{height:`1px`,bg:`border`,marginY:1}),i.map(e=>(0,X.jsxs)(R,{justify:`space-between`,gap:3,children:[(0,X.jsxs)(R,{gap:1.5,children:[(0,X.jsx)(j,{width:`6px`,height:`2px`,bg:e.color}),(0,X.jsx)(F,{textStyle:`xs`,children:e.name})]}),(0,X.jsx)(F,{textStyle:`xs`,fontFamily:`mono`,children:e.value.toLocaleString()})]},e.name))]})]})}function we({showCounts:e}){return(0,X.jsx)(R,{gap:3,justify:`center`,paddingTop:2,children:[{name:`Staged/s`,color:Q.staged.stroke,type:`area`},{name:`Completed/s`,color:Q.completed.stroke,type:`area`},{name:`Failed/s`,color:Q.failed.stroke,type:`area`},...e?[{name:`Pending`,color:Q.pending,type:`line`},{name:`Blocked`,color:Q.blocked,type:`line`}]:[]].map(e=>(0,X.jsxs)(R,{gap:1,children:[e.type===`area`?(0,X.jsx)(j,{width:`6px`,height:`6px`,borderRadius:`full`,bg:e.color}):(0,X.jsx)(j,{width:`10px`,height:`2px`,bg:e.color,borderRadius:`full`,opacity:.7}),(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,children:e.name})]},e.name))})}function Te({data:e}){let t=(0,Y.useRef)(1),[n,r]=(0,Y.useState)(5e3),i=(0,Y.useMemo)(()=>_e(e.throughputHistory,n),[e.throughputHistory,n]),a=(0,Y.useMemo)(()=>xe(i),[i]),o=(0,Y.useMemo)(()=>{if(i.length===0)return 1;let e=0;for(let t of i)e=Math.max(e,t.staged,t.completed,t.failed);let n=Se(e*1.3);return(n>t.current*1.2||n<t.current*.5)&&(t.current=n),t.current},[i]),s=(0,Y.useMemo)(()=>i.some(e=>e.pending>0||e.blocked>0),[i]),c=(0,Y.useMemo)(()=>{if(!s)return 10;let e=0;for(let t of i)e=Math.max(e,t.pending,t.blocked);return e<=0?10:Se(e*1.3)},[i,s]);return i.length<2?(0,X.jsx)(I,{height:`280px`,children:(0,X.jsxs)(K,{gap:2,children:[(0,X.jsx)(A,{size:`sm`}),(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,children:`Collecting data...`})]})}):(0,X.jsxs)(K,{align:`stretch`,gap:0,children:[(0,X.jsxs)(R,{justify:`space-between`,paddingX:1,paddingBottom:1,children:[(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,fontStyle:`italic`,children:`events/s`}),(0,X.jsx)(R,{gap:.5,children:ge.map(e=>(0,X.jsx)(k,{size:`2xs`,variant:n===e.ms?`subtle`:`ghost`,colorPalette:n===e.ms?`orange`:`gray`,onClick:()=>r(e.ms),fontFamily:`mono`,minWidth:`auto`,paddingX:1.5,children:e.label},e.ms))}),s&&(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,fontStyle:`italic`,children:`count`})]}),(0,X.jsx)(T,{width:`100%`,height:280,children:(0,X.jsxs)(f,{data:i,margin:{top:8,right:s?4:12,bottom:4,left:-8},children:[(0,X.jsxs)(`defs`,{children:[(0,X.jsxs)(`linearGradient`,{id:`gradStaged`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,X.jsx)(`stop`,{offset:`0%`,stopColor:Q.staged.fill,stopOpacity:.2}),(0,X.jsx)(`stop`,{offset:`100%`,stopColor:Q.staged.fill,stopOpacity:.02})]}),(0,X.jsxs)(`linearGradient`,{id:`gradCompleted`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,X.jsx)(`stop`,{offset:`0%`,stopColor:Q.completed.fill,stopOpacity:.2}),(0,X.jsx)(`stop`,{offset:`100%`,stopColor:Q.completed.fill,stopOpacity:.02})]}),(0,X.jsxs)(`linearGradient`,{id:`gradFailed`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,X.jsx)(`stop`,{offset:`0%`,stopColor:Q.failed.fill,stopOpacity:.25}),(0,X.jsx)(`stop`,{offset:`100%`,stopColor:Q.failed.fill,stopOpacity:.02})]})]}),(0,X.jsx)(g,{strokeDasharray:`3 3`,stroke:`var(--chakra-colors-border)`,strokeOpacity:.4,vertical:!1}),(0,X.jsx)(w,{dataKey:`timestamp`,type:`number`,domain:[`dataMin`,`dataMax`],scale:`time`,ticks:a,tickFormatter:ve,tick:{fontSize:10,fill:`var(--chakra-colors-fg-muted)`},axisLine:!1,tickLine:!1}),(0,X.jsx)(v,{yAxisId:`rate`,tick:{fontSize:10,fill:`var(--chakra-colors-fg-muted)`},axisLine:!1,tickLine:!1,width:40,domain:[0,o],allowDataOverflow:!0,tickFormatter:be}),s&&(0,X.jsx)(v,{yAxisId:`count`,orientation:`right`,tick:{fontSize:10,fill:`var(--chakra-colors-fg-muted)`},axisLine:!1,tickLine:!1,width:40,domain:[0,c],allowDataOverflow:!0,tickFormatter:be}),(0,X.jsx)(S,{content:(0,X.jsx)(Ce,{}),cursor:{stroke:`var(--chakra-colors-fg-muted)`,strokeWidth:1,strokeDasharray:`3 3`,strokeOpacity:.3}}),(0,X.jsx)(C,{yAxisId:`rate`,type:`monotone`,dataKey:`staged`,stroke:Q.staged.stroke,fill:`url(#gradStaged)`,strokeWidth:1.5,name:`Staged/s`,isAnimationActive:!1,dot:!1,activeDot:{r:3,strokeWidth:0}}),(0,X.jsx)(C,{yAxisId:`rate`,type:`monotone`,dataKey:`completed`,stroke:Q.completed.stroke,fill:`url(#gradCompleted)`,strokeWidth:1.5,name:`Completed/s`,isAnimationActive:!1,dot:!1,activeDot:{r:3,strokeWidth:0}}),(0,X.jsx)(C,{yAxisId:`rate`,type:`monotone`,dataKey:`failed`,stroke:Q.failed.stroke,fill:`url(#gradFailed)`,strokeWidth:1.5,name:`Failed/s`,isAnimationActive:!1,dot:!1,activeDot:{r:3,strokeWidth:0}}),(0,X.jsx)(b,{yAxisId:s?`count`:`rate`,type:`monotone`,dataKey:`pending`,stroke:Q.pending,strokeWidth:1,strokeOpacity:.6,strokeDasharray:`4 3`,dot:!1,activeDot:{r:2,strokeWidth:0},name:`Pending`,isAnimationActive:!1}),(0,X.jsx)(b,{yAxisId:s?`count`:`rate`,type:`monotone`,dataKey:`blocked`,stroke:Q.blocked,strokeWidth:1,strokeOpacity:.6,strokeDasharray:`4 3`,dot:!1,activeDot:{r:2,strokeWidth:0},name:`Blocked`,isAnimationActive:!1})]})}),(0,X.jsx)(we,{showCounts:s})]})}function Ee(e,t,n){let r=t?`${t}/${e.name}`:e.name;if(n.has(r))return!0;if(t){let e=t.split(`/`);for(let t=1;t<=e.length;t++){let r=e.slice(0,t).join(`/`);if(n.has(r))return!0}}return!1}function De(e,t){return t.has(e)}function Oe(e,t){if(!t.trim())return e;let n=t.toLowerCase();function r(e){if(e.name.toLowerCase().includes(n))return e;let t=e.children.map(r).filter(e=>e!==null);return t.length>0?{...e,children:t}:null}let i=e.map(r).filter(e=>e!==null);return i.length>0?i:null}function ke(e){return e===null?!1:Date.now()-e>300*1e3}function Ae(e,t){switch(t){case`all`:return!0;case`ok`:return!e.isBlocked&&!e.isStaleBlock;case`blocked`:return e.isBlocked&&!e.isStaleBlock;case`stale`:return e.isStaleBlock;case`active`:return e.hasActiveJob&&!e.isBlocked}}function je({node:e,parentPath:t,depth:n,pausedKeys:r,expandedPaths:i,onToggleExpand:a,onPause:s,onUnpause:c,hasAccess:l,queueNames:u}){let d=t?`${t}/${e.name}`:e.name,f=e.children.length>0,p=i.has(d),m=Ee(e,t,r),g=De(d,r),_=!f;return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(R,{paddingY:1,paddingX:3,paddingLeft:`${n*20+12}px`,cursor:f?`pointer`:`default`,_hover:{bg:`bg.subtle`},onClick:()=>f&&a(d),borderBottom:`1px solid`,borderBottomColor:`border`,gap:2,opacity:m?.6:1,children:[(0,X.jsx)(j,{width:`14px`,flexShrink:0,children:f?p?(0,X.jsx)(h,{size:12}):(0,X.jsx)(y,{size:12}):null}),(0,X.jsx)(F,{textStyle:`xs`,fontWeight:n===0?`semibold`:`medium`,fontFamily:_?`mono`:void 0,flex:1,color:m?`orange.500`:void 0,children:e.name}),m&&(0,X.jsx)(N,{size:`xs`,colorPalette:`orange`,variant:`subtle`,children:`Paused`}),(0,X.jsxs)(R,{gap:1,flexShrink:0,children:[e.pending>0&&(0,X.jsx)(N,{size:`xs`,colorPalette:`blue`,variant:`subtle`,children:e.pending}),e.active>0&&(0,X.jsx)(N,{size:`xs`,colorPalette:`green`,variant:`subtle`,children:e.active}),e.blocked>0&&(0,X.jsx)(N,{size:`xs`,colorPalette:`red`,variant:`subtle`,children:e.blocked})]}),l&&(0,X.jsx)(j,{flexShrink:0,onClick:e=>e.stopPropagation(),children:g?(0,X.jsx)(k,{variant:`ghost`,size:`2xs`,colorPalette:`green`,onClick:()=>c(d),children:(0,X.jsx)(o,{size:10})}):m?null:(0,X.jsx)(k,{variant:`ghost`,size:`2xs`,colorPalette:`orange`,onClick:()=>s(d),children:(0,X.jsx)(pe,{size:10})})})]}),f&&p&&e.children.map(e=>(0,X.jsx)(je,{node:e,parentPath:d,depth:n+1,pausedKeys:r,expandedPaths:i,onToggleExpand:a,onPause:s,onUnpause:c,hasAccess:l,queueNames:u},e.name))]})}function Me({pipelineTree:e,pausedKeys:t,queueNames:n}){let{hasAccess:a}=i(),o=q.useContext(),[s,c]=(0,Y.useState)(``),[l,u]=(0,Y.useState)(()=>new Set),d=(0,Y.useMemo)(()=>new Set(t),[t]),f=(0,Y.useMemo)(()=>Oe(e,s),[e,s]),p=q.ops.pausePipeline.useMutation({onSuccess:()=>{M.create({title:`Pipeline paused`,type:`success`}),o.ops.invalidate()},onError:e=>{M.create({title:`Failed to pause`,description:e.message,type:`error`})}}),m=q.ops.unpausePipeline.useMutation({onSuccess:()=>{M.create({title:`Pipeline unpaused`,type:`success`}),o.ops.invalidate()},onError:e=>{M.create({title:`Failed to unpause`,description:e.message,type:`error`})}});function h(e){u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function g(){let t=new Set;function n(e,r){for(let i of e){let e=r?`${r}/${i.name}`:i.name;t.add(e),n(i.children,e)}}n(e,``),u(t)}let _=n[0];function v(e){_&&p.mutate({queueName:_,key:e})}function y(e){_&&m.mutate({queueName:_,key:e})}return(0,X.jsx)(z,{children:(0,X.jsxs)(B,{padding:0,children:[(0,X.jsxs)(R,{paddingX:4,paddingY:2.5,borderBottom:`1px solid`,borderBottomColor:`border`,children:[(0,X.jsx)(F,{textStyle:`sm`,fontWeight:`medium`,children:`Pipeline Tree`}),(0,X.jsx)(V,{}),e.length>0&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(j,{position:`relative`,width:`200px`,children:[(0,X.jsx)(j,{position:`absolute`,left:2.5,top:`50%`,transform:`translateY(-50%)`,zIndex:1,children:(0,X.jsx)(r,{size:11,color:`var(--chakra-colors-fg-muted)`})}),(0,X.jsx)(L,{size:`xs`,placeholder:`Filter...`,value:s,onChange:e=>c(e.target.value),paddingLeft:7})]}),(0,X.jsx)(k,{variant:`ghost`,size:`2xs`,onClick:g,children:`Expand all`}),(0,X.jsx)(k,{variant:`ghost`,size:`2xs`,onClick:()=>u(new Set),children:`Collapse`})]})]}),e.length===0?(0,X.jsx)(j,{padding:4,children:(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,children:`No pipelines discovered yet.`})}):f===null?(0,X.jsx)(j,{padding:4,children:(0,X.jsxs)(F,{textStyle:`xs`,color:`fg.muted`,children:[`No pipelines match "`,s,`"`]})}):f.map(e=>(0,X.jsx)(je,{node:e,parentPath:``,depth:0,pausedKeys:d,expandedPaths:l,onToggleExpand:h,onPause:v,onUnpause:y,hasAccess:a,queueNames:n},e.name))]})})}function $({open:e,onClose:t,onConfirm:n,title:r,description:i,isLoading:a}){return(0,X.jsx)(P.Root,{open:e,onOpenChange:e=>!e.open&&t(),children:(0,X.jsxs)(P.Content,{children:[(0,X.jsx)(P.Header,{children:(0,X.jsx)(P.Title,{children:r})}),(0,X.jsx)(P.Body,{children:(0,X.jsx)(F,{textStyle:`sm`,children:i})}),(0,X.jsxs)(P.Footer,{children:[(0,X.jsx)(k,{variant:`outline`,size:`sm`,onClick:t,children:`Cancel`}),(0,X.jsx)(k,{colorPalette:`red`,size:`sm`,onClick:n,loading:a,children:`Confirm`})]}),(0,X.jsx)(P.CloseTrigger,{})]})})}function Ne({queueNames:e}){let{hasAccess:t}=i(),n=q.useContext(),r=q.ops.getBlockedSummary.useQuery(),o=q.ops.listQueues.useQuery(),[s,l]=(0,Y.useState)(null),[u,d]=(0,Y.useState)(null),[f,p]=(0,Y.useState)(null),[h,g]=(0,Y.useState)(null),[v,y]=(0,Y.useState)(5),b=q.ops.unblockAll.useMutation({onSuccess:e=>{M.create({title:`Unblocked ${e.unblockedCount} groups`,type:`success`}),l(null),n.ops.invalidate()},onError:e=>{M.create({title:`Unblock failed`,description:e.message,type:`error`})}}),x=q.ops.drainGroup.useMutation({onSuccess:e=>{M.create({title:`Drained, removed ${e.jobsRemoved} jobs`,type:`success`}),d(null),n.ops.invalidate()},onError:e=>{M.create({title:`Drain failed`,description:e.message,type:`error`})}}),S=q.ops.moveAllBlockedToDlq.useMutation({onSuccess:e=>{M.create({title:`Moved ${e.movedCount} groups to DLQ`,type:`success`}),p(null),n.ops.invalidate()},onError:e=>{M.create({title:`Move to DLQ failed`,description:e.message,type:`error`})}}),C=q.ops.canaryUnblock.useMutation({onSuccess:e=>{M.create({title:`Canary unblocked ${e.unblockedCount}`,type:`success`}),g(null),n.ops.invalidate()},onError:e=>{M.create({title:`Canary failed`,description:e.message,type:`error`})}}),w=(o.data??[]).filter(e=>e.blockedGroupCount>0);return r.isLoading||!r.data||r.data.clusters.length===0?null:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(z,{children:(0,X.jsxs)(B,{padding:0,children:[(0,X.jsxs)(R,{paddingX:4,paddingY:2.5,borderBottom:`1px solid`,borderBottomColor:`border`,gap:2,flexWrap:`wrap`,children:[(0,X.jsxs)(F,{textStyle:`sm`,fontWeight:`medium`,color:`red.500`,children:[`Blocked — `,r.data.totalBlocked,` groups, `,r.data.clusters.length,` error patterns`]}),(0,X.jsx)(V,{}),t&&(0,X.jsxs)(R,{gap:1.5,flexWrap:`wrap`,children:[w.map(e=>(0,X.jsxs)(k,{variant:`outline`,size:`2xs`,colorPalette:`orange`,onClick:()=>l(e.name),children:[`Unblock All (`,e.blockedGroupCount,`)`]},e.name)),w.map(e=>(0,X.jsx)(k,{variant:`outline`,size:`2xs`,colorPalette:`red`,onClick:()=>p(e.name),children:`→ DLQ`},`dlq-${e.name}`)),(0,X.jsxs)(R,{gap:1,children:[(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,children:`Canary:`}),(0,X.jsx)(L,{size:`xs`,type:`number`,value:v,onChange:e=>y(Math.max(1,Math.min(100,parseInt(e.target.value)||5))),width:`50px`}),w.map(e=>(0,X.jsx)(k,{variant:`ghost`,size:`2xs`,onClick:()=>g(e.name),children:`Go`},`c-${e.name}`))]})]})]}),(0,X.jsx)(a,{children:(0,X.jsxs)(D,{size:`sm`,variant:`line`,css:{"& tr:last-child td":{borderBottom:`none`}},children:[(0,X.jsx)(_,{children:(0,X.jsxs)(c,{children:[(0,X.jsx)(O,{width:`60px`,textAlign:`end`,children:`Count`}),(0,X.jsx)(O,{children:`Error`}),(0,X.jsx)(O,{children:`Pipeline`}),(0,X.jsx)(O,{children:`Sample Groups`}),(0,X.jsx)(O,{width:`60px`,children:`Actions`})]})}),(0,X.jsx)(m,{children:r.data.clusters.map((e,t)=>(0,X.jsxs)(c,{children:[(0,X.jsx)(E,{textAlign:`end`,children:(0,X.jsx)(F,{color:`red.500`,fontWeight:`medium`,textStyle:`xs`,children:e.count})}),(0,X.jsx)(E,{children:(0,X.jsx)(F,{textStyle:`xs`,truncate:!0,maxWidth:`300px`,title:e.sampleMessage,children:e.sampleMessage})}),(0,X.jsx)(E,{children:(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,children:e.pipelineName??`—`})}),(0,X.jsx)(E,{children:(0,X.jsxs)(F,{textStyle:`xs`,fontFamily:`mono`,truncate:!0,maxWidth:`160px`,children:[e.sampleGroupIds.slice(0,2).join(`, `),e.sampleGroupIds.length>2?` +${e.sampleGroupIds.length-2}`:``]})}),(0,X.jsx)(E,{children:e.sampleGroupIds[0]&&(0,X.jsx)(k,{variant:`outline`,size:`2xs`,colorPalette:`red`,onClick:()=>d({queueName:e.queueName,groupId:e.sampleGroupIds[0]}),children:`Drain`})})]},t))})]})})]})}),(0,X.jsx)($,{open:!!s,onClose:()=>l(null),onConfirm:()=>{s&&b.mutate({queueName:s})},title:`Unblock All`,description:`Unblock all blocked groups in "${s}". They will retry immediately.`,isLoading:b.isPending}),(0,X.jsx)($,{open:!!u,onClose:()=>d(null),onConfirm:()=>{u&&x.mutate(u)},title:`Drain Group`,description:`Permanently remove all jobs from "${u?.groupId}". Cannot be undone.`,isLoading:x.isPending}),(0,X.jsx)($,{open:!!f,onClose:()=>p(null),onConfirm:()=>{f&&S.mutate({queueName:f})},title:`Move All to DLQ`,description:`Move all blocked groups in "${f}" to DLQ. They can be replayed later.`,isLoading:S.isPending}),(0,X.jsx)($,{open:!!h,onClose:()=>g(null),onConfirm:()=>{h&&C.mutate({queueName:h,count:v})},title:`Canary Unblock`,description:`Unblock ${v} random groups in "${h}" as a canary test.`,isLoading:C.isPending})]})}function Pe({queueNames:e}){let{hasAccess:t}=i(),n=q.useContext(),r=q.ops.listAllDlqGroups.useQuery(void 0,{refetchInterval:1e4}),[o,s]=(0,Y.useState)(null),[l,u]=(0,Y.useState)(null),[d,f]=(0,Y.useState)(null),[p,h]=(0,Y.useState)(5),g=q.ops.replayFromDlq.useMutation({onSuccess:e=>{M.create({title:`Replayed ${e.jobsReplayed} jobs`,type:`success`}),s(null),n.ops.invalidate()},onError:e=>{M.create({title:`Replay failed`,description:e.message,type:`error`})}}),v=q.ops.replayAllFromDlq.useMutation({onSuccess:e=>{M.create({title:`Replayed ${e.replayedCount} groups`,type:`success`}),u(null),n.ops.invalidate()},onError:e=>{M.create({title:`Replay all failed`,description:e.message,type:`error`})}}),y=q.ops.canaryRedrive.useMutation({onSuccess:e=>{M.create({title:`Canary redrove ${e.redrivenCount}`,type:`success`}),f(null),n.ops.invalidate()},onError:e=>{M.create({title:`Canary failed`,description:e.message,type:`error`})}}),b=r.data??[],x=[...new Set(b.map(e=>e.queueName))];return r.isLoading||b.length===0?null:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(z,{children:(0,X.jsxs)(B,{padding:0,children:[(0,X.jsxs)(R,{paddingX:4,paddingY:2.5,borderBottom:`1px solid`,borderBottomColor:`border`,gap:2,flexWrap:`wrap`,children:[(0,X.jsxs)(F,{textStyle:`sm`,fontWeight:`medium`,color:`orange.500`,children:[`Dead Letter Queue — `,b.length,` group`,b.length===1?``:`s`]}),(0,X.jsx)(V,{}),t&&(0,X.jsxs)(R,{gap:1.5,flexWrap:`wrap`,children:[x.map(e=>{let t=b.filter(t=>t.queueName===e).length;return(0,X.jsxs)(k,{variant:`outline`,size:`2xs`,colorPalette:`green`,onClick:()=>u(e),children:[`Replay All `,b.find(t=>t.queueName===e)?.queueDisplayName??e,` (`,t,`)`]},e)}),(0,X.jsxs)(R,{gap:1,children:[(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,children:`Canary:`}),(0,X.jsx)(L,{size:`xs`,type:`number`,value:p,onChange:e=>h(Math.max(1,Math.min(100,parseInt(e.target.value)||5))),width:`50px`}),x.map(e=>(0,X.jsx)(k,{variant:`ghost`,size:`2xs`,onClick:()=>f(e),children:`Go`},`c-${e}`))]})]})]}),(0,X.jsx)(a,{children:(0,X.jsxs)(D,{size:`sm`,variant:`line`,css:{"& tr:last-child td":{borderBottom:`none`}},children:[(0,X.jsx)(_,{children:(0,X.jsxs)(c,{children:[(0,X.jsx)(O,{children:`Queue`}),(0,X.jsx)(O,{children:`Group ID`}),(0,X.jsx)(O,{children:`Pipeline`}),(0,X.jsx)(O,{children:`Error`}),(0,X.jsx)(O,{textAlign:`end`,width:`50px`,children:`Jobs`}),t&&(0,X.jsx)(O,{width:`70px`,children:`Actions`})]})}),(0,X.jsx)(m,{children:b.map(e=>(0,X.jsxs)(c,{children:[(0,X.jsx)(E,{children:(0,X.jsx)(N,{size:`xs`,variant:`subtle`,children:e.queueDisplayName})}),(0,X.jsx)(E,{children:(0,X.jsx)(F,{textStyle:`xs`,fontFamily:`mono`,truncate:!0,maxWidth:`160px`,children:e.groupId})}),(0,X.jsx)(E,{children:(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,children:e.pipelineName??`—`})}),(0,X.jsx)(E,{children:(0,X.jsx)(F,{textStyle:`xs`,color:`red.500`,truncate:!0,maxWidth:`220px`,title:e.error??void 0,children:e.error??``})}),(0,X.jsx)(E,{textAlign:`end`,children:(0,X.jsx)(F,{textStyle:`xs`,children:e.jobCount})}),t&&(0,X.jsx)(E,{children:(0,X.jsx)(k,{variant:`outline`,size:`2xs`,colorPalette:`green`,onClick:()=>s({queueName:e.queueName,groupId:e.groupId}),children:`Replay`})})]},`${e.queueName}:${e.groupId}`))})]})})]})}),(0,X.jsx)($,{open:!!o,onClose:()=>s(null),onConfirm:()=>{o&&g.mutate(o)},title:`Replay from DLQ`,description:`Move "${o?.groupId}" back to main queue for reprocessing.`,isLoading:g.isPending}),(0,X.jsx)($,{open:!!l,onClose:()=>u(null),onConfirm:()=>{l&&v.mutate({queueName:l})},title:`Replay All from DLQ`,description:`Move all DLQ groups in "${l}" back to main queue.`,isLoading:v.isPending}),(0,X.jsx)($,{open:!!d,onClose:()=>f(null),onConfirm:()=>{d&&y.mutate({queueName:d,count:p})},title:`Canary Redrive`,description:`Replay ${p} random DLQ groups from "${d}" as canary.`,isLoading:y.isPending})]})}function Fe({group:e,onClose:t}){let n=q.ops.getGroupDetail.useQuery({queueName:e?.queueName??``,groupId:e?.groupId??``},{enabled:!!e}),r=q.ops.getGroupJobs.useQuery({queueName:e?.queueName??``,groupId:e?.groupId??``,page:1,pageSize:20},{enabled:!!e}),i=n.data,a=r.data;return(0,X.jsx)(P.Root,{open:!!e,onOpenChange:e=>!e.open&&t(),size:`lg`,children:(0,X.jsxs)(P.Content,{children:[(0,X.jsx)(P.Header,{children:(0,X.jsx)(P.Title,{children:(0,X.jsx)(F,{textStyle:`sm`,fontFamily:`mono`,wordBreak:`break-all`,children:e?.groupId})})}),(0,X.jsx)(P.Body,{children:n.isLoading?(0,X.jsx)(I,{paddingY:6,children:(0,X.jsx)(A,{size:`sm`})}):i?(0,X.jsxs)(K,{align:`stretch`,gap:4,children:[(0,X.jsxs)(R,{gap:4,flexWrap:`wrap`,children:[(0,X.jsxs)(K,{align:`start`,gap:0,children:[(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,children:`Status`}),i.isStaleBlock?(0,X.jsx)(N,{size:`sm`,colorPalette:`orange`,variant:`subtle`,children:`Stale`}):i.isBlocked?(0,X.jsx)(N,{size:`sm`,colorPalette:`red`,variant:`subtle`,children:`Blocked`}):i.hasActiveJob?(0,X.jsx)(N,{size:`sm`,colorPalette:`green`,variant:`subtle`,children:`Active`}):(0,X.jsx)(N,{size:`sm`,colorPalette:`gray`,variant:`subtle`,children:`OK`})]}),(0,X.jsxs)(K,{align:`start`,gap:0,children:[(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,children:`Pipeline`}),(0,X.jsx)(F,{textStyle:`sm`,children:i.pipelineName??`—`})]}),(0,X.jsxs)(K,{align:`start`,gap:0,children:[(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,children:`Pending`}),(0,X.jsx)(F,{textStyle:`sm`,fontFamily:`mono`,children:i.pendingJobs})]}),(i.retryCount??0)>0&&(0,X.jsxs)(K,{align:`start`,gap:0,children:[(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,children:`Retries`}),(0,X.jsx)(F,{textStyle:`sm`,fontFamily:`mono`,color:`orange.500`,children:i.retryCount})]}),i.activeJobId&&(0,X.jsxs)(K,{align:`start`,gap:0,children:[(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,children:`Active Job`}),(0,X.jsx)(F,{textStyle:`xs`,fontFamily:`mono`,color:`green.500`,children:i.activeJobId})]})]}),(0,X.jsxs)(R,{gap:4,children:[(0,X.jsxs)(K,{align:`start`,gap:0,children:[(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,children:`Oldest Job`}),(0,X.jsx)(F,{textStyle:`sm`,children:G(i.oldestJobMs)})]}),(0,X.jsxs)(K,{align:`start`,gap:0,children:[(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,children:`Newest Job`}),(0,X.jsx)(F,{textStyle:`sm`,children:G(i.newestJobMs)})]}),i.processingDurationMs!=null&&(0,X.jsxs)(K,{align:`start`,gap:0,children:[(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,children:`Processing`}),(0,X.jsxs)(F,{textStyle:`sm`,children:[i.processingDurationMs,`ms`]})]})]}),i.errorMessage&&(0,X.jsxs)(K,{align:`stretch`,gap:1,children:[(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,children:`Error`}),(0,X.jsx)(z,{borderColor:`red.500/20`,children:(0,X.jsxs)(B,{padding:3,children:[(0,X.jsx)(F,{textStyle:`xs`,color:`red.500`,whiteSpace:`pre-wrap`,wordBreak:`break-word`,children:i.errorMessage}),i.errorStack&&(0,X.jsx)(j,{marginTop:2,maxHeight:`200px`,overflow:`auto`,bg:`bg.subtle`,borderRadius:`sm`,padding:2,children:(0,X.jsx)(F,{textStyle:`xs`,fontFamily:`mono`,color:`fg.muted`,whiteSpace:`pre`,fontSize:`10px`,children:i.errorStack})})]})})]}),(0,X.jsxs)(K,{align:`stretch`,gap:1,children:[(0,X.jsxs)(F,{textStyle:`xs`,color:`fg.muted`,children:[`Jobs `,a?`(${a.total})`:``]}),r.isLoading?(0,X.jsx)(A,{size:`xs`}):a&&a.jobs.length>0?(0,X.jsx)(K,{align:`stretch`,gap:2,children:a.jobs.map(e=>(0,X.jsx)(z,{variant:`outline`,children:(0,X.jsxs)(B,{padding:3,children:[(0,X.jsxs)(R,{gap:3,marginBottom:e.data?2:0,children:[(0,X.jsxs)(K,{align:`start`,gap:0,children:[(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,children:`Job ID`}),(0,X.jsx)(F,{textStyle:`xs`,fontFamily:`mono`,wordBreak:`break-all`,children:e.jobId})]}),(0,X.jsxs)(K,{align:`start`,gap:0,children:[(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,children:`Score`}),(0,X.jsx)(F,{textStyle:`xs`,fontFamily:`mono`,children:e.score})]})]}),e.data&&(0,X.jsx)(j,{bg:`bg.subtle`,borderRadius:`sm`,padding:2,maxHeight:`200px`,overflow:`auto`,children:(0,X.jsx)(F,{as:`pre`,textStyle:`xs`,fontFamily:`mono`,whiteSpace:`pre-wrap`,wordBreak:`break-word`,fontSize:`11px`,children:JSON.stringify(e.data,null,2)})})]})},e.jobId))}):(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,children:`No jobs in queue.`})]})]}):null}),(0,X.jsx)(P.CloseTrigger,{})]})})}function Ie({queueNames:e}){let{hasAccess:t}=i(),n=q.useContext(),[o,s]=(0,Y.useState)(`all`),[l,u]=(0,Y.useState)(``),d=e[0],f=q.ops.listGroups.useQuery({queueName:d??``,page:1,pageSize:200},{refetchInterval:1e4,enabled:!!d}),p=(0,Y.useMemo)(()=>{let e=[];if(f.data&&d)for(let t of f.data.groups)e.push({...t,queueName:d});return e},[f.data,d]),h=(0,Y.useMemo)(()=>{let e=p;if(o!==`all`&&(e=e.filter(e=>Ae(e,o))),l.trim()){let t=l.toLowerCase();e=e.filter(e=>e.groupId.toLowerCase().includes(t)||e.pipelineName?.toLowerCase().includes(t)||e.errorMessage?.toLowerCase().includes(t))}return e},[p,o,l]),g=(0,Y.useMemo)(()=>{let e=0,t=0,n=0,r=0;for(let i of p)i.isStaleBlock?n++:i.isBlocked?t++:e++,i.hasActiveJob&&!i.isBlocked&&r++;return{all:p.length,ok:e,blocked:t,stale:n,active:r}},[p]),v=!!d&&f.isLoading,[y,b]=(0,Y.useState)(null),[x,S]=(0,Y.useState)(null),C=q.ops.drainGroup.useMutation({onSuccess:e=>{M.create({title:`Drained, removed ${e.jobsRemoved} jobs`,type:`success`}),S(null),n.ops.invalidate()},onError:e=>{M.create({title:`Failed to drain`,description:e.message,type:`error`})}}),w=q.ops.unblockGroup.useMutation({onSuccess:()=>{M.create({title:`Group unblocked`,type:`success`}),n.ops.invalidate()},onError:e=>{M.create({title:`Failed to unblock`,description:e.message,type:`error`})}}),T=[{value:`all`,label:`All`,count:g.all,color:`gray`},{value:`ok`,label:`OK`,count:g.ok,color:`green`},{value:`blocked`,label:`Blocked`,count:g.blocked,color:`red`},{value:`stale`,label:`Stale`,count:g.stale,color:`orange`},{value:`active`,label:`Active`,count:g.active,color:`blue`}];return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(z,{children:(0,X.jsxs)(B,{padding:0,children:[(0,X.jsxs)(R,{paddingX:4,paddingY:2.5,borderBottom:`1px solid`,borderBottomColor:`border`,gap:2,flexWrap:`wrap`,children:[(0,X.jsx)(F,{textStyle:`sm`,fontWeight:`medium`,children:`Groups`}),(0,X.jsx)(V,{}),p.length>0&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(R,{gap:1,children:T.map(e=>(0,X.jsxs)(k,{size:`2xs`,variant:o===e.value?`solid`:`ghost`,colorPalette:e.color,onClick:()=>s(e.value),children:[e.label,` `,e.count>0?`(${e.count})`:``]},e.value))}),(0,X.jsxs)(j,{position:`relative`,width:`200px`,children:[(0,X.jsx)(j,{position:`absolute`,left:2.5,top:`50%`,transform:`translateY(-50%)`,zIndex:1,children:(0,X.jsx)(r,{size:11,color:`var(--chakra-colors-fg-muted)`})}),(0,X.jsx)(L,{size:`xs`,placeholder:`Search...`,value:l,onChange:e=>u(e.target.value),paddingLeft:7})]})]})]}),v?(0,X.jsx)(I,{paddingY:6,children:(0,X.jsx)(A,{size:`sm`})}):p.length===0?(0,X.jsx)(j,{padding:4,children:(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,children:`No groups — queues are idle.`})}):h.length===0?(0,X.jsx)(j,{padding:4,children:(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,children:`No groups match current filters.`})}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(a,{children:(0,X.jsxs)(D,{size:`sm`,variant:`line`,css:{"& tr:last-child td":{borderBottom:`none`}},children:[(0,X.jsx)(_,{children:(0,X.jsxs)(c,{children:[(0,X.jsx)(O,{children:`Group ID`}),(0,X.jsx)(O,{width:`140px`,children:`Pipeline`}),(0,X.jsx)(O,{textAlign:`end`,width:`50px`,children:`Pend.`}),(0,X.jsx)(O,{textAlign:`end`,width:`45px`,children:`Retry`}),(0,X.jsx)(O,{width:`75px`,children:`Oldest`}),(0,X.jsx)(O,{width:`65px`,children:`Status`}),t&&(0,X.jsx)(O,{width:`100px`,children:`Actions`})]})}),(0,X.jsx)(m,{children:h.slice(0,100).map(e=>{let n=!e.isBlocked&&ke(e.oldestJobMs);return(0,X.jsxs)(c,{cursor:`pointer`,_hover:{bg:`bg.subtle`},onClick:()=>b({queueName:e.queueName,groupId:e.groupId}),children:[(0,X.jsx)(E,{children:(0,X.jsx)(F,{textStyle:`xs`,fontFamily:`mono`,truncate:!0,title:e.groupId,children:e.groupId})}),(0,X.jsx)(E,{children:(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,truncate:!0,children:e.pipelineName??`—`})}),(0,X.jsx)(E,{textAlign:`end`,children:(0,X.jsx)(F,{textStyle:`xs`,fontFamily:`mono`,children:e.pendingJobs})}),(0,X.jsx)(E,{textAlign:`end`,children:(e.retryCount??0)>0?(0,X.jsx)(F,{textStyle:`xs`,fontFamily:`mono`,color:`orange.500`,children:e.retryCount}):(0,X.jsx)(F,{textStyle:`xs`,fontFamily:`mono`,color:`fg.muted`,children:`—`})}),(0,X.jsx)(E,{children:(0,X.jsxs)(F,{textStyle:`xs`,color:n?`orange.500`:`fg.muted`,fontWeight:n?`medium`:void 0,children:[G(e.oldestJobMs),n?` ⚠`:``]})}),(0,X.jsx)(E,{children:e.isStaleBlock?(0,X.jsx)(N,{size:`xs`,colorPalette:`orange`,variant:`subtle`,children:`Stale`}):e.isBlocked?(0,X.jsx)(N,{size:`xs`,colorPalette:`red`,variant:`subtle`,children:`Blocked`}):e.hasActiveJob?(0,X.jsx)(N,{size:`xs`,colorPalette:`green`,variant:`subtle`,children:`Active`}):(0,X.jsx)(N,{size:`xs`,colorPalette:`gray`,variant:`subtle`,children:`OK`})}),t&&(0,X.jsx)(E,{onClick:e=>e.stopPropagation(),children:(0,X.jsxs)(R,{gap:1,children:[e.isBlocked&&(0,X.jsx)(k,{variant:`outline`,size:`2xs`,colorPalette:`green`,onClick:()=>w.mutate({queueName:e.queueName,groupId:e.groupId}),loading:w.isPending,children:`Retry`}),(0,X.jsx)(k,{variant:`outline`,size:`2xs`,colorPalette:`red`,onClick:()=>S({queueName:e.queueName,groupId:e.groupId}),children:`Drain`})]})})]},`${e.queueName}:${e.groupId}`)})})]})}),h.length>100&&(0,X.jsx)(j,{padding:3,borderTop:`1px solid`,borderTopColor:`border`,children:(0,X.jsxs)(F,{textStyle:`xs`,color:`fg.muted`,textAlign:`center`,children:[`Showing 100 of `,h.length]})})]})]})}),(0,X.jsx)(Fe,{group:y,onClose:()=>b(null)}),(0,X.jsx)($,{open:!!x,onClose:()=>S(null),onConfirm:()=>{x&&C.mutate(x)},title:`Drain Group`,description:`Permanently remove all jobs from "${x?.groupId}". Cannot be undone.`,isLoading:C.isPending})]})}function Le({data:e}){let t=e.queues.reduce((e,t)=>e+t.blockedGroupCount,0),n=e.queues.reduce((e,t)=>e+t.dlqCount,0),r=q.ops.listQueues.useQuery(void 0,{refetchInterval:1e4}),i=(0,Y.useMemo)(()=>(r.data??[]).map(e=>e.name),[r.data]);return(0,X.jsxs)(K,{align:`stretch`,gap:5,width:`full`,children:[(0,X.jsx)(me,{data:e}),(0,X.jsxs)(te,{columns:{base:2,md:4,lg:7},gap:1,children:[(0,X.jsx)(Z,{label:`Staged/s`,value:W(e.throughputIngestedPerSec),sublabel:`peak ${W(e.peakIngestedPerSec)}`}),(0,X.jsx)(Z,{label:`Completed/s`,value:W(e.completedPerSec),sublabel:`${ce(e.totalCompleted)} total`}),(0,X.jsx)(Z,{label:`Failed/s`,value:W(e.failedPerSec),sublabel:e.totalFailed>0?`${ce(e.totalFailed)} total`:void 0,color:e.failedPerSec>0?`red.500`:void 0}),(0,X.jsx)(Z,{label:`Blocked`,value:t.toString(),sublabel:`${e.totalGroups} groups`,color:t>0?`red.500`:void 0}),(0,X.jsx)(Z,{label:`P50`,value:H(e.latencyP50Ms),sublabel:`peak ${H(e.peakLatencyP50Ms)}`}),(0,X.jsx)(Z,{label:`P99`,value:H(e.latencyP99Ms),sublabel:`peak ${H(e.peakLatencyP99Ms)}`}),(0,X.jsx)(Z,{label:`DLQ`,value:n.toString(),sublabel:e.redisMemoryUsed,color:n>0?`orange.500`:void 0})]}),(0,X.jsx)(z,{overflow:`hidden`,children:(0,X.jsxs)(B,{padding:4,children:[(0,X.jsx)(F,{textStyle:`xs`,fontWeight:`medium`,color:`fg.muted`,marginBottom:2,children:`Throughput`}),(0,X.jsx)(Te,{data:e})]})}),(0,X.jsx)(Me,{pipelineTree:e.pipelineTree,pausedKeys:e.pausedKeys,queueNames:i}),(0,X.jsxs)(z,{overflow:`hidden`,children:[(0,X.jsx)(R,{paddingX:4,paddingTop:3,paddingBottom:2,children:(0,X.jsx)(F,{textStyle:`xs`,fontWeight:`medium`,color:`fg.muted`,children:`Top Errors`})}),e.topErrors.length>0?(0,X.jsx)(a,{children:(0,X.jsxs)(D,{size:`sm`,variant:`line`,css:{"& tr:last-child td":{borderBottom:`none`}},children:[(0,X.jsx)(_,{children:(0,X.jsxs)(c,{children:[(0,X.jsx)(O,{width:`60px`,children:`Count`}),(0,X.jsx)(O,{children:`Error`}),(0,X.jsx)(O,{children:`Pipeline`})]})}),(0,X.jsx)(m,{children:e.topErrors.slice(0,5).map((e,t)=>(0,X.jsxs)(c,{children:[(0,X.jsx)(E,{children:(0,X.jsx)(F,{color:`red.500`,fontWeight:`medium`,children:e.count})}),(0,X.jsx)(E,{children:(0,X.jsx)(F,{truncate:!0,maxWidth:`400px`,children:e.sampleMessage})}),(0,X.jsx)(E,{color:`fg.muted`,children:e.pipelineName??`—`})]},t))})]})}):(0,X.jsx)(j,{paddingX:4,paddingBottom:4,children:(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,children:t>0?`0 errors`:`No errors`})})]}),(0,X.jsx)(Ne,{queueNames:i}),(0,X.jsx)(Pe,{queueNames:i}),(0,X.jsx)(Ie,{queueNames:i}),(0,X.jsx)(he,{})]})}var Re={connected:`green`,connecting:`orange`,disconnected:`red`},ze={connected:`Live`,connecting:`Connecting`,disconnected:`Disconnected`};function Be({status:e}){return(0,X.jsxs)(oe,{size:`sm`,colorPalette:Re[e],children:[(0,X.jsx)(U,{}),ze[e]]})}var Ve=300*1e3;function He(){let[e,t]=(0,Y.useState)(null),[n,r]=(0,Y.useState)(`connecting`),i=(0,Y.useRef)(1e3),a=(0,Y.useCallback)((e,n)=>{e===`dashboard`&&t(n)},[]),o=(0,Y.useRef)(a);return o.current=a,(0,Y.useEffect)(()=>{let e=null,t=!1,n=null;function a(){t||(r(`connecting`),e=new EventSource(`/api/ops/sse`),e.onopen=()=>{r(`connected`),i.current=1e3,n=setTimeout(()=>{!t&&e&&(e.close(),a())},Ve)},e.addEventListener(`dashboard`,e=>{try{o.current(`dashboard`,JSON.parse(e.data))}catch{}}),e.addEventListener(`heartbeat`,()=>{}),e.onerror=()=>{r(`disconnected`),e?.close(),n&&=(clearTimeout(n),null);let t=Math.min(i.current,3e4);i.current=t*2,setTimeout(a,t)})}return a(),()=>{t=!0,n&&clearTimeout(n),e?.close()}},[]),{data:e,status:n}}function Ue(){let{data:e,status:t}=He(),r=q.ops.getDashboardSnapshot.useQuery(void 0,{enabled:!e,refetchInterval:e?!1:5e3}),i=e??r.data??null;return(0,X.jsx)(fe,{children:(0,X.jsxs)(x,{children:[(0,X.jsxs)(l.Header,{children:[(0,X.jsx)(l.Heading,{children:`Ops Dashboard`}),(0,X.jsx)(V,{}),(0,X.jsx)(Be,{status:t})]}),(0,X.jsx)(l.Container,{children:i?(0,X.jsx)(Le,{data:i}):(0,X.jsx)(I,{paddingY:20,children:(0,X.jsx)(s,{children:(0,X.jsxs)(d,{children:[(0,X.jsx)(p,{children:(0,X.jsx)(A,{size:`lg`})}),(0,X.jsx)(n,{children:`Loading metrics`}),(0,X.jsx)(u,{children:`Waiting for the first collection cycle...`})]})})})})]})})}export{Ue as default};
2
- //# sourceMappingURL=ops-Cc-g-CMn.js.map
1
+ import{s as e}from"./chunk-Bj-mKKzh.js";import{t}from"./react-C7JcuhbW.js";import{$s as n,Aa as r,Cn as i,Cs as a,La as o,Qs as s,Ss as c,Xr as l,Xs as u,Ys as d,Zn as f,Zs as p,_s as m,ao as h,ar as g,bs as _,er as v,io as y,ir as b,mn as x,mr as S,rr as C,tr as w,vr as T,vs as E,xs as D,ys as O}from"./command-bar-DUK45yin.js";import{j as ee,n as k,r as A}from"./stack-oJ9iWdbl.js";import{t as j}from"./box-BsM8YLGl.js";import{n as M}from"./toaster-C_DYALhL.js";import{an as N,f as P}from"./dist-Cds4Mqhj.js";import{t as F}from"./text-CwTrMF8x.js";import{i as I}from"./code-FF_ibTVI.js";import{t as L}from"./input-C7emsUCL.js";import{t as R}from"./h-stack-BKLDJ2vg.js";import{r as z,t as B}from"./card-CMtKVPVl.js";import{t as te}from"./simple-grid-C3IW90zo.js";import{t as V}from"./spacer-2LJJGbo8.js";import{n as ne,r as re,t as ie}from"./stat-CHoKZ9Rr.js";import{a as H,c as U,i as ae,l as oe,n as se,o as W,r as ce,s as G,t as le}from"./ReplayStateBadge-ChyX1KUG.js";import{t as K}from"./v-stack-EOPQ57OZ.js";import{s as q}from"./auth-client-D3UhxhQi.js";import{t as ue}from"./createLucideIcon-BJKFyRLS.js";import{t as de}from"./arrow-up-right-Cmmi1ap5.js";import{t as J}from"./next-link-DuYeiiEe.js";import{t as fe}from"./OpsPageShell-C_mTziRS.js";var pe=ue(`pause`,[[`rect`,{x:`14`,y:`3`,width:`5`,height:`18`,rx:`1`,key:`kaeet6`}],[`rect`,{x:`5`,y:`3`,width:`5`,height:`18`,rx:`1`,key:`1wsw3u`}]]),Y=e(t()),X=ee();function me({data:e}){let t=se().data,n=t?.state===`running`,r=e.pausedKeys,i=r.length>0;return!n&&!i?null:(0,X.jsxs)(z,{overflow:`hidden`,children:[(0,X.jsx)(F,{textStyle:`xs`,fontWeight:`medium`,color:`fg.muted`,paddingX:4,paddingTop:3,paddingBottom:2,children:`Active Operations`}),(0,X.jsxs)(K,{align:`stretch`,gap:0,paddingX:4,paddingBottom:3,children:[n&&t&&(0,X.jsxs)(R,{gap:2,paddingY:2,borderBottom:i?`1px solid`:void 0,borderBottomColor:`border`,children:[(0,X.jsx)(oe,{colorPalette:`blue`,size:`sm`,children:(0,X.jsx)(U,{})}),(0,X.jsx)(F,{textStyle:`sm`,fontWeight:`medium`,children:`Replay running`}),t.currentProjection&&(0,X.jsx)(N,{size:`sm`,variant:`subtle`,colorPalette:`blue`,children:t.currentProjection}),(0,X.jsx)(V,{}),t.runId&&(0,X.jsx)(J,{href:`/ops/projections/${t.runId}`,style:{textDecoration:`none`},children:(0,X.jsx)(F,{textStyle:`xs`,color:`blue.500`,cursor:`pointer`,children:`View progress`})})]}),i&&(0,X.jsxs)(K,{align:`stretch`,gap:1,paddingY:2,children:[(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,children:`Paused pipelines`}),(0,X.jsx)(R,{gap:2,flexWrap:`wrap`,children:r.map(e=>(0,X.jsx)(N,{size:`sm`,colorPalette:`orange`,variant:`subtle`,children:e},e))})]})]})]})}function Z({label:e,value:t,sublabel:n,href:r,color:i}){let a=(0,X.jsxs)(ne,{cursor:r?`pointer`:void 0,_hover:r?{bg:`bg.subtle`}:void 0,borderRadius:`md`,padding:2,transition:`background 0.1s`,children:[(0,X.jsx)(ie,{children:(0,X.jsxs)(R,{gap:1,children:[(0,X.jsx)(F,{children:e}),r&&(0,X.jsx)(de,{size:10})]})}),(0,X.jsxs)(R,{gap:1.5,alignItems:`baseline`,children:[(0,X.jsx)(re,{color:i,children:t}),n&&(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,fontWeight:`normal`,children:n})]})]});return r?(0,X.jsx)(J,{href:r,style:{textDecoration:`none`},children:a}):a}function he(){let e=q.ops.getReplayHistory.useQuery(void 0,{refetchInterval:1e4}).data?.[0];return(0,X.jsxs)(z,{overflow:`hidden`,children:[(0,X.jsx)(J,{href:`/ops/projections`,style:{textDecoration:`none`},children:(0,X.jsxs)(R,{paddingX:4,paddingTop:3,paddingBottom:2,cursor:`pointer`,_hover:{color:`orange.500`},transition:`color 0.1s`,children:[(0,X.jsx)(F,{textStyle:`xs`,fontWeight:`medium`,color:`fg.muted`,children:`Latest Replay`}),(0,X.jsx)(de,{size:10})]})}),(0,X.jsx)(j,{paddingX:4,paddingBottom:4,children:e?(0,X.jsx)(J,{href:`/ops/projections/${e.runId}`,style:{textDecoration:`none`},children:(0,X.jsxs)(R,{gap:3,cursor:`pointer`,_hover:{opacity:.8},transition:`opacity 0.1s`,children:[(0,X.jsx)(N,{size:`sm`,variant:`subtle`,colorPalette:le(e.state),children:e.state}),(0,X.jsx)(F,{textStyle:`xs`,truncate:!0,maxWidth:`240px`,children:e.description||`—`}),(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,children:ae(e.startedAt,e.completedAt)}),(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,whiteSpace:`nowrap`,children:e.completedAt?new Date(e.completedAt).toLocaleString([],{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`}):`—`})]})}):(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,children:`No replay history`})})]})}var Q={staged:{stroke:`#06b6d4`,fill:`#06b6d4`},completed:{stroke:`#22c55e`,fill:`#22c55e`},failed:{stroke:`#ef4444`,fill:`#ef4444`},pending:`#a78bfa`,blocked:`#f97316`},ge=[{label:`2s`,ms:0},{label:`5s`,ms:5e3},{label:`15s`,ms:15e3},{label:`30s`,ms:3e4},{label:`1m`,ms:6e4}];function _e(e,t){if(e.length===0)return[];if(t<=0)return e.map(e=>({timestamp:e.timestamp,staged:e.ingestedPerSec,completed:e.completedPerSec,failed:e.failedPerSec,pending:e.pendingCount,blocked:e.blockedCount}));let n=new Map;for(let r of e){let e=Math.floor(r.timestamp/t)*t,i=n.get(e);i?(i.sum.staged+=r.ingestedPerSec,i.sum.completed+=r.completedPerSec,i.sum.failed+=r.failedPerSec,i.sum.pending+=r.pendingCount,i.sum.blocked+=r.blockedCount,i.count++):n.set(e,{sum:{timestamp:e,staged:r.ingestedPerSec,completed:r.completedPerSec,failed:r.failedPerSec,pending:r.pendingCount,blocked:r.blockedCount},count:1})}let r=[];for(let[,{sum:e,count:t}]of n)r.push({timestamp:e.timestamp,staged:e.staged/t,completed:e.completed/t,failed:e.failed/t,pending:Math.round(e.pending/t),blocked:Math.round(e.blocked/t)});return r.sort((e,t)=>e.timestamp-t.timestamp),r}function ve(e){return new Date(e).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})}function ye(e){return new Date(e).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`,second:`2-digit`})}function be(e){return e>=1e3?`${(e/1e3).toFixed(1)}k`:e===0?`0`:Number.isInteger(e)?e.toString():e.toFixed(1)}function xe(e){if(e.length<2)return[];let t=e[0].timestamp,n=e[e.length-1].timestamp,r=n-t,i=6e4;r>20*6e4?i=5*6e4:r>10*6e4&&(i=2*6e4);let a=Math.ceil(t/i)*i,o=[];for(let e=a;e<=n;e+=i)o.push(e);return o}function Se(e){if(e<=0)return 1;let t=10**Math.floor(Math.log10(e)),n=e/t,r;return r=n<=1?1:n<=2?2:n<=5?5:10,r*t}function Ce({active:e,payload:t,label:n}){if(!e||!t?.length||n==null)return null;let r=t.filter(e=>e.name!==`Pending`&&e.name!==`Blocked`),i=t.filter(e=>e.name===`Pending`||e.name===`Blocked`);return(0,X.jsxs)(j,{bg:`bg.panel`,borderWidth:`1px`,borderColor:`border`,borderRadius:`md`,padding:2,shadow:`md`,minWidth:`140px`,children:[(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,marginBottom:1,children:ye(n)}),r.map(e=>(0,X.jsxs)(R,{justify:`space-between`,gap:3,children:[(0,X.jsxs)(R,{gap:1.5,children:[(0,X.jsx)(j,{width:`6px`,height:`6px`,borderRadius:`full`,bg:e.color}),(0,X.jsx)(F,{textStyle:`xs`,children:e.name})]}),(0,X.jsxs)(F,{textStyle:`xs`,fontFamily:`mono`,fontWeight:`medium`,children:[e.value.toFixed(1),`/s`]})]},e.name)),i.length>0&&i.some(e=>e.value>0)&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(j,{height:`1px`,bg:`border`,marginY:1}),i.map(e=>(0,X.jsxs)(R,{justify:`space-between`,gap:3,children:[(0,X.jsxs)(R,{gap:1.5,children:[(0,X.jsx)(j,{width:`6px`,height:`2px`,bg:e.color}),(0,X.jsx)(F,{textStyle:`xs`,children:e.name})]}),(0,X.jsx)(F,{textStyle:`xs`,fontFamily:`mono`,children:e.value.toLocaleString()})]},e.name))]})]})}function we({showCounts:e}){return(0,X.jsx)(R,{gap:3,justify:`center`,paddingTop:2,children:[{name:`Staged/s`,color:Q.staged.stroke,type:`area`},{name:`Completed/s`,color:Q.completed.stroke,type:`area`},{name:`Failed/s`,color:Q.failed.stroke,type:`area`},...e?[{name:`Pending`,color:Q.pending,type:`line`},{name:`Blocked`,color:Q.blocked,type:`line`}]:[]].map(e=>(0,X.jsxs)(R,{gap:1,children:[e.type===`area`?(0,X.jsx)(j,{width:`6px`,height:`6px`,borderRadius:`full`,bg:e.color}):(0,X.jsx)(j,{width:`10px`,height:`2px`,bg:e.color,borderRadius:`full`,opacity:.7}),(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,children:e.name})]},e.name))})}function Te({data:e}){let t=(0,Y.useRef)(1),[n,r]=(0,Y.useState)(5e3),i=(0,Y.useMemo)(()=>_e(e.throughputHistory,n),[e.throughputHistory,n]),a=(0,Y.useMemo)(()=>xe(i),[i]),o=(0,Y.useMemo)(()=>{if(i.length===0)return 1;let e=0;for(let t of i)e=Math.max(e,t.staged,t.completed,t.failed);let n=Se(e*1.3);return(n>t.current*1.2||n<t.current*.5)&&(t.current=n),t.current},[i]),s=(0,Y.useMemo)(()=>i.some(e=>e.pending>0||e.blocked>0),[i]),c=(0,Y.useMemo)(()=>{if(!s)return 10;let e=0;for(let t of i)e=Math.max(e,t.pending,t.blocked);return e<=0?10:Se(e*1.3)},[i,s]);return i.length<2?(0,X.jsx)(I,{height:`280px`,children:(0,X.jsxs)(K,{gap:2,children:[(0,X.jsx)(A,{size:`sm`}),(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,children:`Collecting data...`})]})}):(0,X.jsxs)(K,{align:`stretch`,gap:0,children:[(0,X.jsxs)(R,{justify:`space-between`,paddingX:1,paddingBottom:1,children:[(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,fontStyle:`italic`,children:`events/s`}),(0,X.jsx)(R,{gap:.5,children:ge.map(e=>(0,X.jsx)(k,{size:`2xs`,variant:n===e.ms?`subtle`:`ghost`,colorPalette:n===e.ms?`orange`:`gray`,onClick:()=>r(e.ms),fontFamily:`mono`,minWidth:`auto`,paddingX:1.5,children:e.label},e.ms))}),s&&(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,fontStyle:`italic`,children:`count`})]}),(0,X.jsx)(T,{width:`100%`,height:280,children:(0,X.jsxs)(f,{data:i,margin:{top:8,right:s?4:12,bottom:4,left:-8},children:[(0,X.jsxs)(`defs`,{children:[(0,X.jsxs)(`linearGradient`,{id:`gradStaged`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,X.jsx)(`stop`,{offset:`0%`,stopColor:Q.staged.fill,stopOpacity:.2}),(0,X.jsx)(`stop`,{offset:`100%`,stopColor:Q.staged.fill,stopOpacity:.02})]}),(0,X.jsxs)(`linearGradient`,{id:`gradCompleted`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,X.jsx)(`stop`,{offset:`0%`,stopColor:Q.completed.fill,stopOpacity:.2}),(0,X.jsx)(`stop`,{offset:`100%`,stopColor:Q.completed.fill,stopOpacity:.02})]}),(0,X.jsxs)(`linearGradient`,{id:`gradFailed`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,X.jsx)(`stop`,{offset:`0%`,stopColor:Q.failed.fill,stopOpacity:.25}),(0,X.jsx)(`stop`,{offset:`100%`,stopColor:Q.failed.fill,stopOpacity:.02})]})]}),(0,X.jsx)(g,{strokeDasharray:`3 3`,stroke:`var(--chakra-colors-border)`,strokeOpacity:.4,vertical:!1}),(0,X.jsx)(w,{dataKey:`timestamp`,type:`number`,domain:[`dataMin`,`dataMax`],scale:`time`,ticks:a,tickFormatter:ve,tick:{fontSize:10,fill:`var(--chakra-colors-fg-muted)`},axisLine:!1,tickLine:!1}),(0,X.jsx)(v,{yAxisId:`rate`,tick:{fontSize:10,fill:`var(--chakra-colors-fg-muted)`},axisLine:!1,tickLine:!1,width:40,domain:[0,o],allowDataOverflow:!0,tickFormatter:be}),s&&(0,X.jsx)(v,{yAxisId:`count`,orientation:`right`,tick:{fontSize:10,fill:`var(--chakra-colors-fg-muted)`},axisLine:!1,tickLine:!1,width:40,domain:[0,c],allowDataOverflow:!0,tickFormatter:be}),(0,X.jsx)(S,{content:(0,X.jsx)(Ce,{}),cursor:{stroke:`var(--chakra-colors-fg-muted)`,strokeWidth:1,strokeDasharray:`3 3`,strokeOpacity:.3}}),(0,X.jsx)(C,{yAxisId:`rate`,type:`monotone`,dataKey:`staged`,stroke:Q.staged.stroke,fill:`url(#gradStaged)`,strokeWidth:1.5,name:`Staged/s`,isAnimationActive:!1,dot:!1,activeDot:{r:3,strokeWidth:0}}),(0,X.jsx)(C,{yAxisId:`rate`,type:`monotone`,dataKey:`completed`,stroke:Q.completed.stroke,fill:`url(#gradCompleted)`,strokeWidth:1.5,name:`Completed/s`,isAnimationActive:!1,dot:!1,activeDot:{r:3,strokeWidth:0}}),(0,X.jsx)(C,{yAxisId:`rate`,type:`monotone`,dataKey:`failed`,stroke:Q.failed.stroke,fill:`url(#gradFailed)`,strokeWidth:1.5,name:`Failed/s`,isAnimationActive:!1,dot:!1,activeDot:{r:3,strokeWidth:0}}),(0,X.jsx)(b,{yAxisId:s?`count`:`rate`,type:`monotone`,dataKey:`pending`,stroke:Q.pending,strokeWidth:1,strokeOpacity:.6,strokeDasharray:`4 3`,dot:!1,activeDot:{r:2,strokeWidth:0},name:`Pending`,isAnimationActive:!1}),(0,X.jsx)(b,{yAxisId:s?`count`:`rate`,type:`monotone`,dataKey:`blocked`,stroke:Q.blocked,strokeWidth:1,strokeOpacity:.6,strokeDasharray:`4 3`,dot:!1,activeDot:{r:2,strokeWidth:0},name:`Blocked`,isAnimationActive:!1})]})}),(0,X.jsx)(we,{showCounts:s})]})}function Ee(e,t,n){let r=t?`${t}/${e.name}`:e.name;if(n.has(r))return!0;if(t){let e=t.split(`/`);for(let t=1;t<=e.length;t++){let r=e.slice(0,t).join(`/`);if(n.has(r))return!0}}return!1}function De(e,t){return t.has(e)}function Oe(e,t){if(!t.trim())return e;let n=t.toLowerCase();function r(e){if(e.name.toLowerCase().includes(n))return e;let t=e.children.map(r).filter(e=>e!==null);return t.length>0?{...e,children:t}:null}let i=e.map(r).filter(e=>e!==null);return i.length>0?i:null}function ke(e){return e===null?!1:Date.now()-e>300*1e3}function Ae(e,t){switch(t){case`all`:return!0;case`ok`:return!e.isBlocked&&!e.isStaleBlock;case`blocked`:return e.isBlocked&&!e.isStaleBlock;case`stale`:return e.isStaleBlock;case`active`:return e.hasActiveJob&&!e.isBlocked}}function je({node:e,parentPath:t,depth:n,pausedKeys:r,expandedPaths:i,onToggleExpand:a,onPause:s,onUnpause:c,hasAccess:l,queueNames:u}){let d=t?`${t}/${e.name}`:e.name,f=e.children.length>0,p=i.has(d),m=Ee(e,t,r),g=De(d,r),_=!f;return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(R,{paddingY:1,paddingX:3,paddingLeft:`${n*20+12}px`,cursor:f?`pointer`:`default`,_hover:{bg:`bg.subtle`},onClick:()=>f&&a(d),borderBottom:`1px solid`,borderBottomColor:`border`,gap:2,opacity:m?.6:1,children:[(0,X.jsx)(j,{width:`14px`,flexShrink:0,children:f?p?(0,X.jsx)(h,{size:12}):(0,X.jsx)(y,{size:12}):null}),(0,X.jsx)(F,{textStyle:`xs`,fontWeight:n===0?`semibold`:`medium`,fontFamily:_?`mono`:void 0,flex:1,color:m?`orange.500`:void 0,children:e.name}),m&&(0,X.jsx)(N,{size:`xs`,colorPalette:`orange`,variant:`subtle`,children:`Paused`}),(0,X.jsxs)(R,{gap:1,flexShrink:0,children:[e.pending>0&&(0,X.jsx)(N,{size:`xs`,colorPalette:`blue`,variant:`subtle`,children:e.pending}),e.active>0&&(0,X.jsx)(N,{size:`xs`,colorPalette:`green`,variant:`subtle`,children:e.active}),e.blocked>0&&(0,X.jsx)(N,{size:`xs`,colorPalette:`red`,variant:`subtle`,children:e.blocked})]}),l&&(0,X.jsx)(j,{flexShrink:0,onClick:e=>e.stopPropagation(),children:g?(0,X.jsx)(k,{variant:`ghost`,size:`2xs`,colorPalette:`green`,onClick:()=>c(d),children:(0,X.jsx)(o,{size:10})}):m?null:(0,X.jsx)(k,{variant:`ghost`,size:`2xs`,colorPalette:`orange`,onClick:()=>s(d),children:(0,X.jsx)(pe,{size:10})})})]}),f&&p&&e.children.map(e=>(0,X.jsx)(je,{node:e,parentPath:d,depth:n+1,pausedKeys:r,expandedPaths:i,onToggleExpand:a,onPause:s,onUnpause:c,hasAccess:l,queueNames:u},e.name))]})}function Me({pipelineTree:e,pausedKeys:t,queueNames:n}){let{hasAccess:a}=i(),o=q.useContext(),[s,c]=(0,Y.useState)(``),[l,u]=(0,Y.useState)(()=>new Set),d=(0,Y.useMemo)(()=>new Set(t),[t]),f=(0,Y.useMemo)(()=>Oe(e,s),[e,s]),p=q.ops.pausePipeline.useMutation({onSuccess:()=>{M.create({title:`Pipeline paused`,type:`success`}),o.ops.invalidate()},onError:e=>{M.create({title:`Failed to pause`,description:e.message,type:`error`})}}),m=q.ops.unpausePipeline.useMutation({onSuccess:()=>{M.create({title:`Pipeline unpaused`,type:`success`}),o.ops.invalidate()},onError:e=>{M.create({title:`Failed to unpause`,description:e.message,type:`error`})}});function h(e){u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function g(){let t=new Set;function n(e,r){for(let i of e){let e=r?`${r}/${i.name}`:i.name;t.add(e),n(i.children,e)}}n(e,``),u(t)}let _=n[0];function v(e){_&&p.mutate({queueName:_,key:e})}function y(e){_&&m.mutate({queueName:_,key:e})}return(0,X.jsx)(z,{children:(0,X.jsxs)(B,{padding:0,children:[(0,X.jsxs)(R,{paddingX:4,paddingY:2.5,borderBottom:`1px solid`,borderBottomColor:`border`,children:[(0,X.jsx)(F,{textStyle:`sm`,fontWeight:`medium`,children:`Pipeline Tree`}),(0,X.jsx)(V,{}),e.length>0&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(j,{position:`relative`,width:`200px`,children:[(0,X.jsx)(j,{position:`absolute`,left:2.5,top:`50%`,transform:`translateY(-50%)`,zIndex:1,children:(0,X.jsx)(r,{size:11,color:`var(--chakra-colors-fg-muted)`})}),(0,X.jsx)(L,{size:`xs`,placeholder:`Filter...`,value:s,onChange:e=>c(e.target.value),paddingLeft:7})]}),(0,X.jsx)(k,{variant:`ghost`,size:`2xs`,onClick:g,children:`Expand all`}),(0,X.jsx)(k,{variant:`ghost`,size:`2xs`,onClick:()=>u(new Set),children:`Collapse`})]})]}),e.length===0?(0,X.jsx)(j,{padding:4,children:(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,children:`No pipelines discovered yet.`})}):f===null?(0,X.jsx)(j,{padding:4,children:(0,X.jsxs)(F,{textStyle:`xs`,color:`fg.muted`,children:[`No pipelines match "`,s,`"`]})}):f.map(e=>(0,X.jsx)(je,{node:e,parentPath:``,depth:0,pausedKeys:d,expandedPaths:l,onToggleExpand:h,onPause:v,onUnpause:y,hasAccess:a,queueNames:n},e.name))]})})}function $({open:e,onClose:t,onConfirm:n,title:r,description:i,isLoading:a}){return(0,X.jsx)(P.Root,{open:e,onOpenChange:e=>!e.open&&t(),children:(0,X.jsxs)(P.Content,{children:[(0,X.jsx)(P.Header,{children:(0,X.jsx)(P.Title,{children:r})}),(0,X.jsx)(P.Body,{children:(0,X.jsx)(F,{textStyle:`sm`,children:i})}),(0,X.jsxs)(P.Footer,{children:[(0,X.jsx)(k,{variant:`outline`,size:`sm`,onClick:t,children:`Cancel`}),(0,X.jsx)(k,{colorPalette:`red`,size:`sm`,onClick:n,loading:a,children:`Confirm`})]}),(0,X.jsx)(P.CloseTrigger,{})]})})}function Ne({queueNames:e}){let{hasAccess:t}=i(),n=q.useContext(),r=q.ops.getBlockedSummary.useQuery(),o=q.ops.listQueues.useQuery(),[s,l]=(0,Y.useState)(null),[u,d]=(0,Y.useState)(null),[f,p]=(0,Y.useState)(null),[h,g]=(0,Y.useState)(null),[v,y]=(0,Y.useState)(5),b=q.ops.unblockAll.useMutation({onSuccess:e=>{M.create({title:`Unblocked ${e.unblockedCount} groups`,type:`success`}),l(null),n.ops.invalidate()},onError:e=>{M.create({title:`Unblock failed`,description:e.message,type:`error`})}}),x=q.ops.drainGroup.useMutation({onSuccess:e=>{M.create({title:`Drained, removed ${e.jobsRemoved} jobs`,type:`success`}),d(null),n.ops.invalidate()},onError:e=>{M.create({title:`Drain failed`,description:e.message,type:`error`})}}),S=q.ops.moveAllBlockedToDlq.useMutation({onSuccess:e=>{M.create({title:`Moved ${e.movedCount} groups to DLQ`,type:`success`}),p(null),n.ops.invalidate()},onError:e=>{M.create({title:`Move to DLQ failed`,description:e.message,type:`error`})}}),C=q.ops.canaryUnblock.useMutation({onSuccess:e=>{M.create({title:`Canary unblocked ${e.unblockedCount}`,type:`success`}),g(null),n.ops.invalidate()},onError:e=>{M.create({title:`Canary failed`,description:e.message,type:`error`})}}),w=(o.data??[]).filter(e=>e.blockedGroupCount>0);return r.isLoading||!r.data||r.data.clusters.length===0?null:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(z,{children:(0,X.jsxs)(B,{padding:0,children:[(0,X.jsxs)(R,{paddingX:4,paddingY:2.5,borderBottom:`1px solid`,borderBottomColor:`border`,gap:2,flexWrap:`wrap`,children:[(0,X.jsxs)(F,{textStyle:`sm`,fontWeight:`medium`,color:`red.500`,children:[`Blocked — `,r.data.totalBlocked,` groups, `,r.data.clusters.length,` error patterns`]}),(0,X.jsx)(V,{}),t&&(0,X.jsxs)(R,{gap:1.5,flexWrap:`wrap`,children:[w.map(e=>(0,X.jsxs)(k,{variant:`outline`,size:`2xs`,colorPalette:`orange`,onClick:()=>l(e.name),children:[`Unblock All (`,e.blockedGroupCount,`)`]},e.name)),w.map(e=>(0,X.jsx)(k,{variant:`outline`,size:`2xs`,colorPalette:`red`,onClick:()=>p(e.name),children:`→ DLQ`},`dlq-${e.name}`)),(0,X.jsxs)(R,{gap:1,children:[(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,children:`Canary:`}),(0,X.jsx)(L,{size:`xs`,type:`number`,value:v,onChange:e=>y(Math.max(1,Math.min(100,parseInt(e.target.value)||5))),width:`50px`}),w.map(e=>(0,X.jsx)(k,{variant:`ghost`,size:`2xs`,onClick:()=>g(e.name),children:`Go`},`c-${e.name}`))]})]})]}),(0,X.jsx)(a,{children:(0,X.jsxs)(D,{size:`sm`,variant:`line`,css:{"& tr:last-child td":{borderBottom:`none`}},children:[(0,X.jsx)(_,{children:(0,X.jsxs)(c,{children:[(0,X.jsx)(O,{width:`60px`,textAlign:`end`,children:`Count`}),(0,X.jsx)(O,{children:`Error`}),(0,X.jsx)(O,{children:`Pipeline`}),(0,X.jsx)(O,{children:`Sample Groups`}),(0,X.jsx)(O,{width:`60px`,children:`Actions`})]})}),(0,X.jsx)(m,{children:r.data.clusters.map((e,t)=>(0,X.jsxs)(c,{children:[(0,X.jsx)(E,{textAlign:`end`,children:(0,X.jsx)(F,{color:`red.500`,fontWeight:`medium`,textStyle:`xs`,children:e.count})}),(0,X.jsx)(E,{children:(0,X.jsx)(F,{textStyle:`xs`,truncate:!0,maxWidth:`300px`,title:e.sampleMessage,children:e.sampleMessage})}),(0,X.jsx)(E,{children:(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,children:e.pipelineName??`—`})}),(0,X.jsx)(E,{children:(0,X.jsxs)(F,{textStyle:`xs`,fontFamily:`mono`,truncate:!0,maxWidth:`160px`,children:[e.sampleGroupIds.slice(0,2).join(`, `),e.sampleGroupIds.length>2?` +${e.sampleGroupIds.length-2}`:``]})}),(0,X.jsx)(E,{children:e.sampleGroupIds[0]&&(0,X.jsx)(k,{variant:`outline`,size:`2xs`,colorPalette:`red`,onClick:()=>d({queueName:e.queueName,groupId:e.sampleGroupIds[0]}),children:`Drain`})})]},t))})]})})]})}),(0,X.jsx)($,{open:!!s,onClose:()=>l(null),onConfirm:()=>{s&&b.mutate({queueName:s})},title:`Unblock All`,description:`Unblock all blocked groups in "${s}". They will retry immediately.`,isLoading:b.isPending}),(0,X.jsx)($,{open:!!u,onClose:()=>d(null),onConfirm:()=>{u&&x.mutate(u)},title:`Drain Group`,description:`Permanently remove all jobs from "${u?.groupId}". Cannot be undone.`,isLoading:x.isPending}),(0,X.jsx)($,{open:!!f,onClose:()=>p(null),onConfirm:()=>{f&&S.mutate({queueName:f})},title:`Move All to DLQ`,description:`Move all blocked groups in "${f}" to DLQ. They can be replayed later.`,isLoading:S.isPending}),(0,X.jsx)($,{open:!!h,onClose:()=>g(null),onConfirm:()=>{h&&C.mutate({queueName:h,count:v})},title:`Canary Unblock`,description:`Unblock ${v} random groups in "${h}" as a canary test.`,isLoading:C.isPending})]})}function Pe({queueNames:e}){let{hasAccess:t}=i(),n=q.useContext(),r=q.ops.listAllDlqGroups.useQuery(void 0,{refetchInterval:1e4}),[o,s]=(0,Y.useState)(null),[l,u]=(0,Y.useState)(null),[d,f]=(0,Y.useState)(null),[p,h]=(0,Y.useState)(5),g=q.ops.replayFromDlq.useMutation({onSuccess:e=>{M.create({title:`Replayed ${e.jobsReplayed} jobs`,type:`success`}),s(null),n.ops.invalidate()},onError:e=>{M.create({title:`Replay failed`,description:e.message,type:`error`})}}),v=q.ops.replayAllFromDlq.useMutation({onSuccess:e=>{M.create({title:`Replayed ${e.replayedCount} groups`,type:`success`}),u(null),n.ops.invalidate()},onError:e=>{M.create({title:`Replay all failed`,description:e.message,type:`error`})}}),y=q.ops.canaryRedrive.useMutation({onSuccess:e=>{M.create({title:`Canary redrove ${e.redrivenCount}`,type:`success`}),f(null),n.ops.invalidate()},onError:e=>{M.create({title:`Canary failed`,description:e.message,type:`error`})}}),b=r.data??[],x=[...new Set(b.map(e=>e.queueName))];return r.isLoading||b.length===0?null:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(z,{children:(0,X.jsxs)(B,{padding:0,children:[(0,X.jsxs)(R,{paddingX:4,paddingY:2.5,borderBottom:`1px solid`,borderBottomColor:`border`,gap:2,flexWrap:`wrap`,children:[(0,X.jsxs)(F,{textStyle:`sm`,fontWeight:`medium`,color:`orange.500`,children:[`Dead Letter Queue — `,b.length,` group`,b.length===1?``:`s`]}),(0,X.jsx)(V,{}),t&&(0,X.jsxs)(R,{gap:1.5,flexWrap:`wrap`,children:[x.map(e=>{let t=b.filter(t=>t.queueName===e).length;return(0,X.jsxs)(k,{variant:`outline`,size:`2xs`,colorPalette:`green`,onClick:()=>u(e),children:[`Replay All `,b.find(t=>t.queueName===e)?.queueDisplayName??e,` (`,t,`)`]},e)}),(0,X.jsxs)(R,{gap:1,children:[(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,children:`Canary:`}),(0,X.jsx)(L,{size:`xs`,type:`number`,value:p,onChange:e=>h(Math.max(1,Math.min(100,parseInt(e.target.value)||5))),width:`50px`}),x.map(e=>(0,X.jsx)(k,{variant:`ghost`,size:`2xs`,onClick:()=>f(e),children:`Go`},`c-${e}`))]})]})]}),(0,X.jsx)(a,{children:(0,X.jsxs)(D,{size:`sm`,variant:`line`,css:{"& tr:last-child td":{borderBottom:`none`}},children:[(0,X.jsx)(_,{children:(0,X.jsxs)(c,{children:[(0,X.jsx)(O,{children:`Queue`}),(0,X.jsx)(O,{children:`Group ID`}),(0,X.jsx)(O,{children:`Pipeline`}),(0,X.jsx)(O,{children:`Error`}),(0,X.jsx)(O,{textAlign:`end`,width:`50px`,children:`Jobs`}),t&&(0,X.jsx)(O,{width:`70px`,children:`Actions`})]})}),(0,X.jsx)(m,{children:b.map(e=>(0,X.jsxs)(c,{children:[(0,X.jsx)(E,{children:(0,X.jsx)(N,{size:`xs`,variant:`subtle`,children:e.queueDisplayName})}),(0,X.jsx)(E,{children:(0,X.jsx)(F,{textStyle:`xs`,fontFamily:`mono`,truncate:!0,maxWidth:`160px`,children:e.groupId})}),(0,X.jsx)(E,{children:(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,children:e.pipelineName??`—`})}),(0,X.jsx)(E,{children:(0,X.jsx)(F,{textStyle:`xs`,color:`red.500`,truncate:!0,maxWidth:`220px`,title:e.error??void 0,children:e.error??``})}),(0,X.jsx)(E,{textAlign:`end`,children:(0,X.jsx)(F,{textStyle:`xs`,children:e.jobCount})}),t&&(0,X.jsx)(E,{children:(0,X.jsx)(k,{variant:`outline`,size:`2xs`,colorPalette:`green`,onClick:()=>s({queueName:e.queueName,groupId:e.groupId}),children:`Replay`})})]},`${e.queueName}:${e.groupId}`))})]})})]})}),(0,X.jsx)($,{open:!!o,onClose:()=>s(null),onConfirm:()=>{o&&g.mutate(o)},title:`Replay from DLQ`,description:`Move "${o?.groupId}" back to main queue for reprocessing.`,isLoading:g.isPending}),(0,X.jsx)($,{open:!!l,onClose:()=>u(null),onConfirm:()=>{l&&v.mutate({queueName:l})},title:`Replay All from DLQ`,description:`Move all DLQ groups in "${l}" back to main queue.`,isLoading:v.isPending}),(0,X.jsx)($,{open:!!d,onClose:()=>f(null),onConfirm:()=>{d&&y.mutate({queueName:d,count:p})},title:`Canary Redrive`,description:`Replay ${p} random DLQ groups from "${d}" as canary.`,isLoading:y.isPending})]})}function Fe({group:e,onClose:t}){let n=q.ops.getGroupDetail.useQuery({queueName:e?.queueName??``,groupId:e?.groupId??``},{enabled:!!e}),r=q.ops.getGroupJobs.useQuery({queueName:e?.queueName??``,groupId:e?.groupId??``,page:1,pageSize:20},{enabled:!!e}),i=n.data,a=r.data;return(0,X.jsx)(P.Root,{open:!!e,onOpenChange:e=>!e.open&&t(),size:`lg`,children:(0,X.jsxs)(P.Content,{children:[(0,X.jsx)(P.Header,{children:(0,X.jsx)(P.Title,{children:(0,X.jsx)(F,{textStyle:`sm`,fontFamily:`mono`,wordBreak:`break-all`,children:e?.groupId})})}),(0,X.jsx)(P.Body,{children:n.isLoading?(0,X.jsx)(I,{paddingY:6,children:(0,X.jsx)(A,{size:`sm`})}):i?(0,X.jsxs)(K,{align:`stretch`,gap:4,children:[(0,X.jsxs)(R,{gap:4,flexWrap:`wrap`,children:[(0,X.jsxs)(K,{align:`start`,gap:0,children:[(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,children:`Status`}),i.isStaleBlock?(0,X.jsx)(N,{size:`sm`,colorPalette:`orange`,variant:`subtle`,children:`Stale`}):i.isBlocked?(0,X.jsx)(N,{size:`sm`,colorPalette:`red`,variant:`subtle`,children:`Blocked`}):i.hasActiveJob?(0,X.jsx)(N,{size:`sm`,colorPalette:`green`,variant:`subtle`,children:`Active`}):(0,X.jsx)(N,{size:`sm`,colorPalette:`gray`,variant:`subtle`,children:`OK`})]}),(0,X.jsxs)(K,{align:`start`,gap:0,children:[(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,children:`Pipeline`}),(0,X.jsx)(F,{textStyle:`sm`,children:i.pipelineName??`—`})]}),(0,X.jsxs)(K,{align:`start`,gap:0,children:[(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,children:`Pending`}),(0,X.jsx)(F,{textStyle:`sm`,fontFamily:`mono`,children:i.pendingJobs})]}),(i.retryCount??0)>0&&(0,X.jsxs)(K,{align:`start`,gap:0,children:[(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,children:`Retries`}),(0,X.jsx)(F,{textStyle:`sm`,fontFamily:`mono`,color:`orange.500`,children:i.retryCount})]}),i.activeJobId&&(0,X.jsxs)(K,{align:`start`,gap:0,children:[(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,children:`Active Job`}),(0,X.jsx)(F,{textStyle:`xs`,fontFamily:`mono`,color:`green.500`,children:i.activeJobId})]})]}),(0,X.jsxs)(R,{gap:4,children:[(0,X.jsxs)(K,{align:`start`,gap:0,children:[(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,children:`Oldest Job`}),(0,X.jsx)(F,{textStyle:`sm`,children:G(i.oldestJobMs)})]}),(0,X.jsxs)(K,{align:`start`,gap:0,children:[(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,children:`Newest Job`}),(0,X.jsx)(F,{textStyle:`sm`,children:G(i.newestJobMs)})]}),i.processingDurationMs!=null&&(0,X.jsxs)(K,{align:`start`,gap:0,children:[(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,children:`Processing`}),(0,X.jsxs)(F,{textStyle:`sm`,children:[i.processingDurationMs,`ms`]})]})]}),i.errorMessage&&(0,X.jsxs)(K,{align:`stretch`,gap:1,children:[(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,children:`Error`}),(0,X.jsx)(z,{borderColor:`red.500/20`,children:(0,X.jsxs)(B,{padding:3,children:[(0,X.jsx)(F,{textStyle:`xs`,color:`red.500`,whiteSpace:`pre-wrap`,wordBreak:`break-word`,children:i.errorMessage}),i.errorStack&&(0,X.jsx)(j,{marginTop:2,maxHeight:`200px`,overflow:`auto`,bg:`bg.subtle`,borderRadius:`sm`,padding:2,children:(0,X.jsx)(F,{textStyle:`xs`,fontFamily:`mono`,color:`fg.muted`,whiteSpace:`pre`,fontSize:`10px`,children:i.errorStack})})]})})]}),(0,X.jsxs)(K,{align:`stretch`,gap:1,children:[(0,X.jsxs)(F,{textStyle:`xs`,color:`fg.muted`,children:[`Jobs `,a?`(${a.total})`:``]}),r.isLoading?(0,X.jsx)(A,{size:`xs`}):a&&a.jobs.length>0?(0,X.jsx)(K,{align:`stretch`,gap:2,children:a.jobs.map(e=>(0,X.jsx)(z,{variant:`outline`,children:(0,X.jsxs)(B,{padding:3,children:[(0,X.jsxs)(R,{gap:3,marginBottom:e.data?2:0,children:[(0,X.jsxs)(K,{align:`start`,gap:0,children:[(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,children:`Job ID`}),(0,X.jsx)(F,{textStyle:`xs`,fontFamily:`mono`,wordBreak:`break-all`,children:e.jobId})]}),(0,X.jsxs)(K,{align:`start`,gap:0,children:[(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,children:`Score`}),(0,X.jsx)(F,{textStyle:`xs`,fontFamily:`mono`,children:e.score})]})]}),e.data&&(0,X.jsx)(j,{bg:`bg.subtle`,borderRadius:`sm`,padding:2,maxHeight:`200px`,overflow:`auto`,children:(0,X.jsx)(F,{as:`pre`,textStyle:`xs`,fontFamily:`mono`,whiteSpace:`pre-wrap`,wordBreak:`break-word`,fontSize:`11px`,children:JSON.stringify(e.data,null,2)})})]})},e.jobId))}):(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,children:`No jobs in queue.`})]})]}):null}),(0,X.jsx)(P.CloseTrigger,{})]})})}function Ie({queueNames:e}){let{hasAccess:t}=i(),n=q.useContext(),[o,s]=(0,Y.useState)(`all`),[l,u]=(0,Y.useState)(``),d=e[0],f=q.ops.listGroups.useQuery({queueName:d??``,page:1,pageSize:200},{refetchInterval:1e4,enabled:!!d}),p=(0,Y.useMemo)(()=>{let e=[];if(f.data&&d)for(let t of f.data.groups)e.push({...t,queueName:d});return e},[f.data,d]),h=(0,Y.useMemo)(()=>{let e=p;if(o!==`all`&&(e=e.filter(e=>Ae(e,o))),l.trim()){let t=l.toLowerCase();e=e.filter(e=>e.groupId.toLowerCase().includes(t)||e.pipelineName?.toLowerCase().includes(t)||e.errorMessage?.toLowerCase().includes(t))}return e},[p,o,l]),g=(0,Y.useMemo)(()=>{let e=0,t=0,n=0,r=0;for(let i of p)i.isStaleBlock?n++:i.isBlocked?t++:e++,i.hasActiveJob&&!i.isBlocked&&r++;return{all:p.length,ok:e,blocked:t,stale:n,active:r}},[p]),v=!!d&&f.isLoading,[y,b]=(0,Y.useState)(null),[x,S]=(0,Y.useState)(null),C=q.ops.drainGroup.useMutation({onSuccess:e=>{M.create({title:`Drained, removed ${e.jobsRemoved} jobs`,type:`success`}),S(null),n.ops.invalidate()},onError:e=>{M.create({title:`Failed to drain`,description:e.message,type:`error`})}}),w=q.ops.unblockGroup.useMutation({onSuccess:()=>{M.create({title:`Group unblocked`,type:`success`}),n.ops.invalidate()},onError:e=>{M.create({title:`Failed to unblock`,description:e.message,type:`error`})}}),T=[{value:`all`,label:`All`,count:g.all,color:`gray`},{value:`ok`,label:`OK`,count:g.ok,color:`green`},{value:`blocked`,label:`Blocked`,count:g.blocked,color:`red`},{value:`stale`,label:`Stale`,count:g.stale,color:`orange`},{value:`active`,label:`Active`,count:g.active,color:`blue`}];return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(z,{children:(0,X.jsxs)(B,{padding:0,children:[(0,X.jsxs)(R,{paddingX:4,paddingY:2.5,borderBottom:`1px solid`,borderBottomColor:`border`,gap:2,flexWrap:`wrap`,children:[(0,X.jsx)(F,{textStyle:`sm`,fontWeight:`medium`,children:`Groups`}),(0,X.jsx)(V,{}),p.length>0&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(R,{gap:1,children:T.map(e=>(0,X.jsxs)(k,{size:`2xs`,variant:o===e.value?`solid`:`ghost`,colorPalette:e.color,onClick:()=>s(e.value),children:[e.label,` `,e.count>0?`(${e.count})`:``]},e.value))}),(0,X.jsxs)(j,{position:`relative`,width:`200px`,children:[(0,X.jsx)(j,{position:`absolute`,left:2.5,top:`50%`,transform:`translateY(-50%)`,zIndex:1,children:(0,X.jsx)(r,{size:11,color:`var(--chakra-colors-fg-muted)`})}),(0,X.jsx)(L,{size:`xs`,placeholder:`Search...`,value:l,onChange:e=>u(e.target.value),paddingLeft:7})]})]})]}),v?(0,X.jsx)(I,{paddingY:6,children:(0,X.jsx)(A,{size:`sm`})}):p.length===0?(0,X.jsx)(j,{padding:4,children:(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,children:`No groups — queues are idle.`})}):h.length===0?(0,X.jsx)(j,{padding:4,children:(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,children:`No groups match current filters.`})}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(a,{children:(0,X.jsxs)(D,{size:`sm`,variant:`line`,css:{"& tr:last-child td":{borderBottom:`none`}},children:[(0,X.jsx)(_,{children:(0,X.jsxs)(c,{children:[(0,X.jsx)(O,{children:`Group ID`}),(0,X.jsx)(O,{width:`140px`,children:`Pipeline`}),(0,X.jsx)(O,{textAlign:`end`,width:`50px`,children:`Pend.`}),(0,X.jsx)(O,{textAlign:`end`,width:`45px`,children:`Retry`}),(0,X.jsx)(O,{width:`75px`,children:`Oldest`}),(0,X.jsx)(O,{width:`65px`,children:`Status`}),t&&(0,X.jsx)(O,{width:`100px`,children:`Actions`})]})}),(0,X.jsx)(m,{children:h.slice(0,100).map(e=>{let n=!e.isBlocked&&ke(e.oldestJobMs);return(0,X.jsxs)(c,{cursor:`pointer`,_hover:{bg:`bg.subtle`},onClick:()=>b({queueName:e.queueName,groupId:e.groupId}),children:[(0,X.jsx)(E,{children:(0,X.jsx)(F,{textStyle:`xs`,fontFamily:`mono`,truncate:!0,title:e.groupId,children:e.groupId})}),(0,X.jsx)(E,{children:(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,truncate:!0,children:e.pipelineName??`—`})}),(0,X.jsx)(E,{textAlign:`end`,children:(0,X.jsx)(F,{textStyle:`xs`,fontFamily:`mono`,children:e.pendingJobs})}),(0,X.jsx)(E,{textAlign:`end`,children:(e.retryCount??0)>0?(0,X.jsx)(F,{textStyle:`xs`,fontFamily:`mono`,color:`orange.500`,children:e.retryCount}):(0,X.jsx)(F,{textStyle:`xs`,fontFamily:`mono`,color:`fg.muted`,children:`—`})}),(0,X.jsx)(E,{children:(0,X.jsxs)(F,{textStyle:`xs`,color:n?`orange.500`:`fg.muted`,fontWeight:n?`medium`:void 0,children:[G(e.oldestJobMs),n?` ⚠`:``]})}),(0,X.jsx)(E,{children:e.isStaleBlock?(0,X.jsx)(N,{size:`xs`,colorPalette:`orange`,variant:`subtle`,children:`Stale`}):e.isBlocked?(0,X.jsx)(N,{size:`xs`,colorPalette:`red`,variant:`subtle`,children:`Blocked`}):e.hasActiveJob?(0,X.jsx)(N,{size:`xs`,colorPalette:`green`,variant:`subtle`,children:`Active`}):(0,X.jsx)(N,{size:`xs`,colorPalette:`gray`,variant:`subtle`,children:`OK`})}),t&&(0,X.jsx)(E,{onClick:e=>e.stopPropagation(),children:(0,X.jsxs)(R,{gap:1,children:[e.isBlocked&&(0,X.jsx)(k,{variant:`outline`,size:`2xs`,colorPalette:`green`,onClick:()=>w.mutate({queueName:e.queueName,groupId:e.groupId}),loading:w.isPending,children:`Retry`}),(0,X.jsx)(k,{variant:`outline`,size:`2xs`,colorPalette:`red`,onClick:()=>S({queueName:e.queueName,groupId:e.groupId}),children:`Drain`})]})})]},`${e.queueName}:${e.groupId}`)})})]})}),h.length>100&&(0,X.jsx)(j,{padding:3,borderTop:`1px solid`,borderTopColor:`border`,children:(0,X.jsxs)(F,{textStyle:`xs`,color:`fg.muted`,textAlign:`center`,children:[`Showing 100 of `,h.length]})})]})]})}),(0,X.jsx)(Fe,{group:y,onClose:()=>b(null)}),(0,X.jsx)($,{open:!!x,onClose:()=>S(null),onConfirm:()=>{x&&C.mutate(x)},title:`Drain Group`,description:`Permanently remove all jobs from "${x?.groupId}". Cannot be undone.`,isLoading:C.isPending})]})}function Le({data:e}){let t=e.queues.reduce((e,t)=>e+t.blockedGroupCount,0),n=e.queues.reduce((e,t)=>e+t.dlqCount,0),r=q.ops.listQueues.useQuery(void 0,{refetchInterval:1e4}),i=(0,Y.useMemo)(()=>(r.data??[]).map(e=>e.name),[r.data]);return(0,X.jsxs)(K,{align:`stretch`,gap:5,width:`full`,children:[(0,X.jsx)(me,{data:e}),(0,X.jsxs)(te,{columns:{base:2,md:4,lg:7},gap:1,children:[(0,X.jsx)(Z,{label:`Staged/s`,value:W(e.throughputIngestedPerSec),sublabel:`peak ${W(e.peakIngestedPerSec)}`}),(0,X.jsx)(Z,{label:`Completed/s`,value:W(e.completedPerSec),sublabel:`${ce(e.totalCompleted)} total`}),(0,X.jsx)(Z,{label:`Failed/s`,value:W(e.failedPerSec),sublabel:e.totalFailed>0?`${ce(e.totalFailed)} total`:void 0,color:e.failedPerSec>0?`red.500`:void 0}),(0,X.jsx)(Z,{label:`Blocked`,value:t.toString(),sublabel:`${e.totalGroups} groups`,color:t>0?`red.500`:void 0}),(0,X.jsx)(Z,{label:`P50`,value:H(e.latencyP50Ms),sublabel:`peak ${H(e.peakLatencyP50Ms)}`}),(0,X.jsx)(Z,{label:`P99`,value:H(e.latencyP99Ms),sublabel:`peak ${H(e.peakLatencyP99Ms)}`}),(0,X.jsx)(Z,{label:`DLQ`,value:n.toString(),sublabel:e.redisMemoryUsed,color:n>0?`orange.500`:void 0})]}),(0,X.jsx)(z,{overflow:`hidden`,children:(0,X.jsxs)(B,{padding:4,children:[(0,X.jsx)(F,{textStyle:`xs`,fontWeight:`medium`,color:`fg.muted`,marginBottom:2,children:`Throughput`}),(0,X.jsx)(Te,{data:e})]})}),(0,X.jsx)(Me,{pipelineTree:e.pipelineTree,pausedKeys:e.pausedKeys,queueNames:i}),(0,X.jsxs)(z,{overflow:`hidden`,children:[(0,X.jsx)(R,{paddingX:4,paddingTop:3,paddingBottom:2,children:(0,X.jsx)(F,{textStyle:`xs`,fontWeight:`medium`,color:`fg.muted`,children:`Top Errors`})}),e.topErrors.length>0?(0,X.jsx)(a,{children:(0,X.jsxs)(D,{size:`sm`,variant:`line`,css:{"& tr:last-child td":{borderBottom:`none`}},children:[(0,X.jsx)(_,{children:(0,X.jsxs)(c,{children:[(0,X.jsx)(O,{width:`60px`,children:`Count`}),(0,X.jsx)(O,{children:`Error`}),(0,X.jsx)(O,{children:`Pipeline`})]})}),(0,X.jsx)(m,{children:e.topErrors.slice(0,5).map((e,t)=>(0,X.jsxs)(c,{children:[(0,X.jsx)(E,{children:(0,X.jsx)(F,{color:`red.500`,fontWeight:`medium`,children:e.count})}),(0,X.jsx)(E,{children:(0,X.jsx)(F,{truncate:!0,maxWidth:`400px`,children:e.sampleMessage})}),(0,X.jsx)(E,{color:`fg.muted`,children:e.pipelineName??`—`})]},t))})]})}):(0,X.jsx)(j,{paddingX:4,paddingBottom:4,children:(0,X.jsx)(F,{textStyle:`xs`,color:`fg.muted`,children:t>0?`0 errors`:`No errors`})})]}),(0,X.jsx)(Ne,{queueNames:i}),(0,X.jsx)(Pe,{queueNames:i}),(0,X.jsx)(Ie,{queueNames:i}),(0,X.jsx)(he,{})]})}var Re={connected:`green`,connecting:`orange`,disconnected:`red`},ze={connected:`Live`,connecting:`Connecting`,disconnected:`Disconnected`};function Be({status:e}){return(0,X.jsxs)(oe,{size:`sm`,colorPalette:Re[e],children:[(0,X.jsx)(U,{}),ze[e]]})}var Ve=300*1e3;function He(){let[e,t]=(0,Y.useState)(null),[n,r]=(0,Y.useState)(`connecting`),i=(0,Y.useRef)(1e3),a=(0,Y.useCallback)((e,n)=>{e===`dashboard`&&t(n)},[]),o=(0,Y.useRef)(a);return o.current=a,(0,Y.useEffect)(()=>{let e=null,t=!1,n=null;function a(){t||(r(`connecting`),e=new EventSource(`/api/ops/sse`),e.onopen=()=>{r(`connected`),i.current=1e3,n=setTimeout(()=>{!t&&e&&(e.close(),a())},Ve)},e.addEventListener(`dashboard`,e=>{try{o.current(`dashboard`,JSON.parse(e.data))}catch{}}),e.addEventListener(`heartbeat`,()=>{}),e.onerror=()=>{r(`disconnected`),e?.close(),n&&=(clearTimeout(n),null);let t=Math.min(i.current,3e4);i.current=t*2,setTimeout(a,t)})}return a(),()=>{t=!0,n&&clearTimeout(n),e?.close()}},[]),{data:e,status:n}}function Ue(){let{data:e,status:t}=He(),r=q.ops.getDashboardSnapshot.useQuery(void 0,{enabled:!e,refetchInterval:e?!1:5e3}),i=e??r.data??null;return(0,X.jsx)(fe,{children:(0,X.jsxs)(x,{children:[(0,X.jsxs)(l.Header,{children:[(0,X.jsx)(l.Heading,{children:`Ops Dashboard`}),(0,X.jsx)(V,{}),(0,X.jsx)(Be,{status:t})]}),(0,X.jsx)(l.Container,{children:i?(0,X.jsx)(Le,{data:i}):(0,X.jsx)(I,{paddingY:20,children:(0,X.jsx)(s,{children:(0,X.jsxs)(d,{children:[(0,X.jsx)(p,{children:(0,X.jsx)(A,{size:`lg`})}),(0,X.jsx)(n,{children:`Loading metrics`}),(0,X.jsx)(u,{children:`Waiting for the first collection cycle...`})]})})})})]})})}export{Ue as default};
2
+ //# sourceMappingURL=ops-CCw-FJaT.js.map
@@ -1,2 +1,2 @@
1
- import{s as e}from"./chunk-Bj-mKKzh.js";import{t}from"./react-C7JcuhbW.js";import{Do as n,Ra as r,Ss as i,Xa as a,_s as o,bs as s,ga as c,qi as l,vs as u,xs as d,ys as f}from"./command-bar-CaJygoez.js";import{j as p,n as m}from"./stack-oJ9iWdbl.js";import{t as h}from"./box-BsM8YLGl.js";import{n as g}from"./toaster-C_DYALhL.js";import{n as _,r as v,t as y}from"./native-select-B51i56CE.js";import{t as b}from"./text-CwTrMF8x.js";import{a as x,n as S,r as C}from"./field-CnUiixMS.js";import{t as w}from"./input-C7emsUCL.js";import{t as T}from"./h-stack-BKLDJ2vg.js";import{t as E}from"./spacer-2LJJGbo8.js";import{t as D}from"./v-stack-EOPQ57OZ.js";import{a as O,c as k,n as A,o as j,r as M,s as N,t as P,u as F}from"./useAdminResource-SPC5iBHM.js";var I=e(t()),L=p(),R=25;function z(){let[e,t]=(0,I.useState)(1),[n,p]=(0,I.useState)(``),[m]=c(n,300),[g,_]=(0,I.useState)(null),[v,y]=(0,I.useState)(!1),x=A(`organizationFeature`,{pagination:{page:e,perPage:R},sort:{field:`createdAt`,order:`DESC`},filter:m?{query:m}:{}}),S=A(`organization`,{pagination:{page:1,perPage:200},sort:{field:`name`,order:`ASC`},filter:{}}),C=(0,I.useMemo)(()=>{let e=new Map;for(let t of S.data?.data??[])e.set(t.id,t.name);return e},[S.data]);return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(O,{title:`Organization Features`,searchValue:n,onSearchChange:e=>{p(e),t(1)},searchPlaceholder:`Search by ID, feature, or organization`,isLoading:x.isLoading,isFetching:x.isFetching,error:x.error,pagination:{page:e,perPage:R,total:x.data?.total??0,onPageChange:t},onCreate:()=>y(!0),createLabel:`Grant feature`,children:(0,L.jsxs)(d,{variant:`line`,size:`md`,width:`full`,children:[(0,L.jsx)(s,{children:(0,L.jsxs)(i,{children:[(0,L.jsx)(f,{children:`Feature`}),(0,L.jsx)(f,{children:`Organization`}),(0,L.jsx)(f,{children:`Trial ends`}),(0,L.jsx)(f,{children:`Created`}),(0,L.jsx)(f,{width:`60px`,textAlign:`right`})]})}),(0,L.jsxs)(o,{children:[x.data?.data.length===0&&(0,L.jsx)(i,{children:(0,L.jsx)(u,{colSpan:5,children:(0,L.jsx)(b,{color:`fg.muted`,textAlign:`center`,paddingY:6,children:`No organization features yet.`})})}),x.data?.data.map(e=>{let t=e.organization?.name??C.get(e.organizationId);return(0,L.jsxs)(i,{children:[(0,L.jsx)(u,{children:e.feature}),(0,L.jsx)(u,{children:t??(0,L.jsx)(b,{fontSize:`xs`,color:`fg.muted`,children:e.organizationId})}),(0,L.jsx)(u,{children:e.trialEndDate?k(e.trialEndDate):(0,L.jsx)(j,{children:`Permanent`})}),(0,L.jsx)(u,{children:k(e.createdAt)}),(0,L.jsx)(u,{textAlign:`right`,children:(0,L.jsx)(h,{width:`full`,height:`full`,display:`flex`,justifyContent:`end`,children:(0,L.jsxs)(l.Root,{children:[(0,L.jsx)(l.Trigger,{children:(0,L.jsx)(a,{size:16})}),(0,L.jsx)(l.Content,{children:(0,L.jsxs)(l.Item,{value:`edit`,onClick:()=>_(e),children:[(0,L.jsx)(r,{size:16}),`Edit`]})})]})})})]},e.id)})]})]})}),(0,L.jsx)(V,{mode:`edit`,item:g,onClose:()=>_(null)}),(0,L.jsx)(V,{mode:`create`,item:v?null:void 0,onClose:()=>y(!1)})]})}function B(e){if(!e)return``;let t=new Date(e);return Number.isNaN(t.getTime())?``:t.toISOString().slice(0,10)}function V({mode:e,item:t,onClose:r}){let i=M(`organizationFeature`),a=P(`organizationFeature`),o=e===`edit`?i:a,[s,l]=(0,I.useState)(``),[u,d]=(0,I.useState)(``),[f,p]=(0,I.useState)(``),[h,O]=(0,I.useState)(``),[k]=c(h,250),j=e===`edit`?!!t:t!==void 0;(0,I.useEffect)(()=>{j&&(e===`edit`&&t?(l(t.feature),d(t.organizationId),p(B(t.trialEndDate))):e===`create`&&(l(``),d(``),p(``),O(``)))},[j,e,t]);let F=A(`organization`,{pagination:{page:1,perPage:50},sort:{field:`name`,order:`ASC`},filter:k?{query:k}:{}},{enabled:j}),R=(0,I.useMemo)(()=>F.data?.data??[],[F.data]),z=()=>{if(!s.trim()){g.create({title:`Feature is required`,type:`error`,duration:3e3,meta:{closable:!0}});return}if(!u){g.create({title:`Organization is required`,type:`error`,duration:3e3,meta:{closable:!0}});return}let n={feature:s.trim(),organizationId:u,trialEndDate:N(f)},o=()=>{g.create({title:e===`edit`?`Feature updated`:`Feature granted`,type:`success`,duration:3e3,meta:{closable:!0}}),r()},c=t=>g.create({title:e===`edit`?`Update failed`:`Grant failed`,description:t.message,type:`error`,duration:5e3,meta:{closable:!0}});e===`edit`&&t?i.mutate({id:t.id,data:n},{onSuccess:o,onError:c}):a.mutate(n,{onSuccess:o,onError:c})},V=e===`edit`?`Edit Organization Feature`:`Grant Feature`;return(0,L.jsx)(n.Root,{open:j,onOpenChange:({open:e})=>{e||r()},size:`md`,children:(0,L.jsxs)(n.Content,{children:[(0,L.jsx)(n.Header,{children:(0,L.jsx)(n.Title,{children:V})}),(0,L.jsx)(n.CloseTrigger,{}),(0,L.jsx)(n.Body,{children:(0,L.jsxs)(D,{gap:4,align:`stretch`,children:[(0,L.jsxs)(x,{required:!0,children:[(0,L.jsx)(C,{children:`Feature`}),(0,L.jsx)(w,{value:s,onChange:e=>l(e.target.value),placeholder:`e.g. CUSTOM_EMBEDDINGS`}),(0,L.jsx)(S,{children:`Free-form feature key consumed by the entitlement checker.`})]}),(0,L.jsxs)(x,{required:!0,children:[(0,L.jsx)(C,{children:`Organization`}),e===`edit`&&t?.organization?.name&&!h&&(0,L.jsxs)(b,{fontSize:`xs`,color:`fg.muted`,children:[`Currently: `,t.organization.name]}),(0,L.jsx)(w,{placeholder:`Type to search organizations`,value:h,onChange:e=>O(e.target.value)}),(0,L.jsxs)(v,{size:`sm`,width:`full`,mt:1,children:[(0,L.jsxs)(y,{value:u,onChange:e=>d(e.target.value),children:[(0,L.jsx)(`option`,{value:``,children:`Select organization…`}),R.map(e=>(0,L.jsxs)(`option`,{value:e.id,children:[e.name,` (`,e.slug,`)`]},e.id))]}),(0,L.jsx)(_,{})]})]}),(0,L.jsxs)(x,{children:[(0,L.jsx)(C,{children:`Trial end date`}),(0,L.jsx)(w,{type:`date`,value:f,onChange:e=>p(e.target.value)}),(0,L.jsx)(S,{children:`Leave empty to grant the feature permanently.`})]})]})}),(0,L.jsx)(n.Footer,{children:(0,L.jsxs)(T,{width:`full`,children:[(0,L.jsx)(E,{}),(0,L.jsx)(m,{variant:`ghost`,onClick:r,children:`Cancel`}),(0,L.jsx)(m,{loading:o.isPending,onClick:z,children:e===`edit`?`Save`:`Grant`})]})})]})})}function H(){return(0,L.jsx)(F,{children:(0,L.jsx)(z,{})})}export{H as default};
2
- //# sourceMappingURL=organization-features-CoIKKHkQ.js.map
1
+ import{s as e}from"./chunk-Bj-mKKzh.js";import{t}from"./react-C7JcuhbW.js";import{Do as n,Ra as r,Ss as i,Xa as a,_s as o,bs as s,ga as c,qi as l,vs as u,xs as d,ys as f}from"./command-bar-DUK45yin.js";import{j as p,n as m}from"./stack-oJ9iWdbl.js";import{t as h}from"./box-BsM8YLGl.js";import{n as g}from"./toaster-C_DYALhL.js";import{n as _,r as v,t as y}from"./native-select-B51i56CE.js";import{t as b}from"./text-CwTrMF8x.js";import{a as x,n as S,r as C}from"./field-CnUiixMS.js";import{t as w}from"./input-C7emsUCL.js";import{t as T}from"./h-stack-BKLDJ2vg.js";import{t as E}from"./spacer-2LJJGbo8.js";import{t as D}from"./v-stack-EOPQ57OZ.js";import{a as O,c as k,n as A,o as j,r as M,s as N,t as P,u as F}from"./useAdminResource-SmnnHro6.js";var I=e(t()),L=p(),R=25;function z(){let[e,t]=(0,I.useState)(1),[n,p]=(0,I.useState)(``),[m]=c(n,300),[g,_]=(0,I.useState)(null),[v,y]=(0,I.useState)(!1),x=A(`organizationFeature`,{pagination:{page:e,perPage:R},sort:{field:`createdAt`,order:`DESC`},filter:m?{query:m}:{}}),S=A(`organization`,{pagination:{page:1,perPage:200},sort:{field:`name`,order:`ASC`},filter:{}}),C=(0,I.useMemo)(()=>{let e=new Map;for(let t of S.data?.data??[])e.set(t.id,t.name);return e},[S.data]);return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(O,{title:`Organization Features`,searchValue:n,onSearchChange:e=>{p(e),t(1)},searchPlaceholder:`Search by ID, feature, or organization`,isLoading:x.isLoading,isFetching:x.isFetching,error:x.error,pagination:{page:e,perPage:R,total:x.data?.total??0,onPageChange:t},onCreate:()=>y(!0),createLabel:`Grant feature`,children:(0,L.jsxs)(d,{variant:`line`,size:`md`,width:`full`,children:[(0,L.jsx)(s,{children:(0,L.jsxs)(i,{children:[(0,L.jsx)(f,{children:`Feature`}),(0,L.jsx)(f,{children:`Organization`}),(0,L.jsx)(f,{children:`Trial ends`}),(0,L.jsx)(f,{children:`Created`}),(0,L.jsx)(f,{width:`60px`,textAlign:`right`})]})}),(0,L.jsxs)(o,{children:[x.data?.data.length===0&&(0,L.jsx)(i,{children:(0,L.jsx)(u,{colSpan:5,children:(0,L.jsx)(b,{color:`fg.muted`,textAlign:`center`,paddingY:6,children:`No organization features yet.`})})}),x.data?.data.map(e=>{let t=e.organization?.name??C.get(e.organizationId);return(0,L.jsxs)(i,{children:[(0,L.jsx)(u,{children:e.feature}),(0,L.jsx)(u,{children:t??(0,L.jsx)(b,{fontSize:`xs`,color:`fg.muted`,children:e.organizationId})}),(0,L.jsx)(u,{children:e.trialEndDate?k(e.trialEndDate):(0,L.jsx)(j,{children:`Permanent`})}),(0,L.jsx)(u,{children:k(e.createdAt)}),(0,L.jsx)(u,{textAlign:`right`,children:(0,L.jsx)(h,{width:`full`,height:`full`,display:`flex`,justifyContent:`end`,children:(0,L.jsxs)(l.Root,{children:[(0,L.jsx)(l.Trigger,{children:(0,L.jsx)(a,{size:16})}),(0,L.jsx)(l.Content,{children:(0,L.jsxs)(l.Item,{value:`edit`,onClick:()=>_(e),children:[(0,L.jsx)(r,{size:16}),`Edit`]})})]})})})]},e.id)})]})]})}),(0,L.jsx)(V,{mode:`edit`,item:g,onClose:()=>_(null)}),(0,L.jsx)(V,{mode:`create`,item:v?null:void 0,onClose:()=>y(!1)})]})}function B(e){if(!e)return``;let t=new Date(e);return Number.isNaN(t.getTime())?``:t.toISOString().slice(0,10)}function V({mode:e,item:t,onClose:r}){let i=M(`organizationFeature`),a=P(`organizationFeature`),o=e===`edit`?i:a,[s,l]=(0,I.useState)(``),[u,d]=(0,I.useState)(``),[f,p]=(0,I.useState)(``),[h,O]=(0,I.useState)(``),[k]=c(h,250),j=e===`edit`?!!t:t!==void 0;(0,I.useEffect)(()=>{j&&(e===`edit`&&t?(l(t.feature),d(t.organizationId),p(B(t.trialEndDate))):e===`create`&&(l(``),d(``),p(``),O(``)))},[j,e,t]);let F=A(`organization`,{pagination:{page:1,perPage:50},sort:{field:`name`,order:`ASC`},filter:k?{query:k}:{}},{enabled:j}),R=(0,I.useMemo)(()=>F.data?.data??[],[F.data]),z=()=>{if(!s.trim()){g.create({title:`Feature is required`,type:`error`,duration:3e3,meta:{closable:!0}});return}if(!u){g.create({title:`Organization is required`,type:`error`,duration:3e3,meta:{closable:!0}});return}let n={feature:s.trim(),organizationId:u,trialEndDate:N(f)},o=()=>{g.create({title:e===`edit`?`Feature updated`:`Feature granted`,type:`success`,duration:3e3,meta:{closable:!0}}),r()},c=t=>g.create({title:e===`edit`?`Update failed`:`Grant failed`,description:t.message,type:`error`,duration:5e3,meta:{closable:!0}});e===`edit`&&t?i.mutate({id:t.id,data:n},{onSuccess:o,onError:c}):a.mutate(n,{onSuccess:o,onError:c})},V=e===`edit`?`Edit Organization Feature`:`Grant Feature`;return(0,L.jsx)(n.Root,{open:j,onOpenChange:({open:e})=>{e||r()},size:`md`,children:(0,L.jsxs)(n.Content,{children:[(0,L.jsx)(n.Header,{children:(0,L.jsx)(n.Title,{children:V})}),(0,L.jsx)(n.CloseTrigger,{}),(0,L.jsx)(n.Body,{children:(0,L.jsxs)(D,{gap:4,align:`stretch`,children:[(0,L.jsxs)(x,{required:!0,children:[(0,L.jsx)(C,{children:`Feature`}),(0,L.jsx)(w,{value:s,onChange:e=>l(e.target.value),placeholder:`e.g. CUSTOM_EMBEDDINGS`}),(0,L.jsx)(S,{children:`Free-form feature key consumed by the entitlement checker.`})]}),(0,L.jsxs)(x,{required:!0,children:[(0,L.jsx)(C,{children:`Organization`}),e===`edit`&&t?.organization?.name&&!h&&(0,L.jsxs)(b,{fontSize:`xs`,color:`fg.muted`,children:[`Currently: `,t.organization.name]}),(0,L.jsx)(w,{placeholder:`Type to search organizations`,value:h,onChange:e=>O(e.target.value)}),(0,L.jsxs)(v,{size:`sm`,width:`full`,mt:1,children:[(0,L.jsxs)(y,{value:u,onChange:e=>d(e.target.value),children:[(0,L.jsx)(`option`,{value:``,children:`Select organization…`}),R.map(e=>(0,L.jsxs)(`option`,{value:e.id,children:[e.name,` (`,e.slug,`)`]},e.id))]}),(0,L.jsx)(_,{})]})]}),(0,L.jsxs)(x,{children:[(0,L.jsx)(C,{children:`Trial end date`}),(0,L.jsx)(w,{type:`date`,value:f,onChange:e=>p(e.target.value)}),(0,L.jsx)(S,{children:`Leave empty to grant the feature permanently.`})]})]})}),(0,L.jsx)(n.Footer,{children:(0,L.jsxs)(T,{width:`full`,children:[(0,L.jsx)(E,{}),(0,L.jsx)(m,{variant:`ghost`,onClick:r,children:`Cancel`}),(0,L.jsx)(m,{loading:o.isPending,onClick:z,children:e===`edit`?`Save`:`Grant`})]})})]})})}function H(){return(0,L.jsx)(F,{children:(0,L.jsx)(z,{})})}export{H as default};
2
+ //# sourceMappingURL=organization-features-rqg-75mI.js.map