@lunora/studio 1.0.0-alpha.80 → 1.0.0-alpha.82

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 (134) hide show
  1. package/dist/index.d.ts +35 -6
  2. package/dist/index.js +1 -1
  3. package/dist/mount.js +1 -1
  4. package/dist/packem_chunks/AdvisorHealthPanel.js +1 -0
  5. package/dist/packem_chunks/ApiTab.js +1 -1
  6. package/dist/packem_chunks/AuditPanel.js +1 -1
  7. package/dist/packem_chunks/ExportImportPanel.js +1 -1
  8. package/dist/packem_chunks/FileBrowser.js +1 -1
  9. package/dist/packem_chunks/FunctionRunner.js +1 -1
  10. package/dist/packem_chunks/FunctionStatsPanel.js +1 -1
  11. package/dist/packem_chunks/HealthPanel.js +1 -1
  12. package/dist/packem_chunks/InsightsPanel.js +1 -1
  13. package/dist/packem_chunks/LogsPanel.js +1 -1
  14. package/dist/packem_chunks/MailPanel.js +2 -2
  15. package/dist/packem_chunks/MetricsPanel.js +1 -1
  16. package/dist/packem_chunks/NotificationsPanel.js +1 -1
  17. package/dist/packem_chunks/PitrPanel.js +1 -1
  18. package/dist/packem_chunks/SchemaViewer.js +1 -1
  19. package/dist/packem_chunks/SecurityAdvisorPanel.js +1 -1
  20. package/dist/packem_chunks/SettingsPanel.js +1 -1
  21. package/dist/packem_chunks/SqlEditorPanel.js +6 -6
  22. package/dist/packem_chunks/TableEditor.js +1 -1
  23. package/dist/packem_chunks/agents-panel.js +1 -1
  24. package/dist/packem_chunks/auth-audit-panel.js +1 -1
  25. package/dist/packem_chunks/containers-panel.js +1 -1
  26. package/dist/packem_chunks/dashboards-panel.js +1 -1
  27. package/dist/packem_chunks/fanout-panel.js +1 -1
  28. package/dist/packem_chunks/flags-panel.js +1 -1
  29. package/dist/packem_chunks/issues-panel.js +1 -1
  30. package/dist/packem_chunks/kv-browser.js +1 -1
  31. package/dist/packem_chunks/log-drains-panel.js +1 -1
  32. package/dist/packem_chunks/migrations-route.js +1 -1
  33. package/dist/packem_chunks/organizations-panel.js +1 -1
  34. package/dist/packem_chunks/payments-panel.js +1 -1
  35. package/dist/packem_chunks/permissions-panel.js +1 -1
  36. package/dist/packem_chunks/queues-panel.js +1 -1
  37. package/dist/packem_chunks/rls-panel.js +1 -1
  38. package/dist/packem_chunks/storage-rules-panel.js +1 -1
  39. package/dist/packem_chunks/subscriptions-panel.js +1 -1
  40. package/dist/packem_chunks/traces-panel.js +1 -1
  41. package/dist/packem_chunks/workflows-panel.js +1 -1
  42. package/dist/packem_shared/ADMIN_FUNCTIONS-CZESgd10.js +1 -0
  43. package/dist/packem_shared/{ApiDocsPanel-DfUQ1ZAF.js → ApiDocsPanel-fYS9NiLg.js} +1 -1
  44. package/dist/packem_shared/DataBrowser-C4J4gVUu.js +1 -0
  45. package/dist/packem_shared/GlobalDataBrowser-CSttudUx.js +1 -0
  46. package/dist/packem_shared/{HomePanel-Dcs4a3Ax.js → HomePanel-BYsfMhKh.js} +1 -1
  47. package/dist/packem_shared/{MigrationsPanel-C2OnsqRb.js → MigrationsPanel-2JbQ2HwG.js} +1 -1
  48. package/dist/packem_shared/{Studio-B26_pT8J.js → Studio-Ba9x0dG_.js} +1 -1
  49. package/dist/packem_shared/{StudioApp-bXhJeLlZ.js → StudioApp-B_PRdg4h.js} +1 -1
  50. package/dist/packem_shared/{cf-links-gbDy51nR.js → cf-links-Dmg86v1D.js} +1 -1
  51. package/dist/packem_shared/{home-panel-CU6MWLHG.js → home-panel-B60-5YfI.js} +1 -1
  52. package/dist/packem_shared/stat-card-fm_TF1mo.js +1 -0
  53. package/dist/packem_shared/studio-CPuoAmjh.js +2 -0
  54. package/dist/packem_shared/table-list-sidebar-BRv3hTLX.js +1 -0
  55. package/dist/packem_shared/{use-sql-assistant-CHEu2-Rk.js → use-sql-assistant-BLG9unQN.js} +1 -1
  56. package/dist/standalone/{chunk-RQ7AFLIV.js → chunk-2QSHLBCO.js} +1 -1
  57. package/dist/standalone/{chunk-33CL6OHR.js → chunk-5SQRE3VR.js} +1 -1
  58. package/dist/standalone/{chunk-5CVJS7ON.js → chunk-6QP5N57V.js} +1 -1
  59. package/dist/standalone/chunk-73GRNONE.js +1 -0
  60. package/dist/standalone/{chunk-JRMMYIAF.js → chunk-74DN6HIE.js} +1 -1
  61. package/dist/standalone/{chunk-KZ3ALMMP.js → chunk-7H7LZRLP.js} +1 -1
  62. package/dist/standalone/{chunk-FOBRNWBG.js → chunk-7YKWP4QK.js} +1 -1
  63. package/dist/standalone/{chunk-T7IUZIF4.js → chunk-7ZUQE3KU.js} +1 -1
  64. package/dist/standalone/{chunk-P4YLIBCN.js → chunk-A3KUNMU6.js} +1 -1
  65. package/dist/standalone/{chunk-S2VVR7HI.js → chunk-B2H5DK55.js} +1 -1
  66. package/dist/standalone/{chunk-FNPJ7GJZ.js → chunk-BDJCCVB6.js} +1 -1
  67. package/dist/standalone/{chunk-KJB7YAKB.js → chunk-C7EOC2WS.js} +1 -1
  68. package/dist/standalone/{chunk-KLQYC6CC.js → chunk-CGLS2ILT.js} +1 -1
  69. package/dist/standalone/chunk-CPSGJSHY.js +1 -0
  70. package/dist/standalone/{chunk-RJP3WBZ4.js → chunk-CU6SCYQ7.js} +1 -1
  71. package/dist/standalone/chunk-DGBJE7YF.js +4 -0
  72. package/dist/standalone/{chunk-G6PSMGLD.js → chunk-DOZAODYC.js} +1 -1
  73. package/dist/standalone/chunk-EQZTSISX.js +1 -0
  74. package/dist/standalone/chunk-ERMTJYQF.js +1 -0
  75. package/dist/standalone/{chunk-QZGTH6WH.js → chunk-GB6LP6UJ.js} +1 -1
  76. package/dist/standalone/{chunk-GYKVBKT5.js → chunk-GM67EQJU.js} +1 -1
  77. package/dist/standalone/chunk-GN567L2T.js +1 -0
  78. package/dist/standalone/{chunk-L7R74G63.js → chunk-GWHM4C4N.js} +1 -1
  79. package/dist/standalone/{chunk-JLOWAJRR.js → chunk-GWQIPIYA.js} +1 -1
  80. package/dist/standalone/{chunk-6YTSSIEJ.js → chunk-HEB6GQQ6.js} +1 -1
  81. package/dist/standalone/chunk-HOR3JLUY.js +6 -0
  82. package/dist/standalone/{chunk-7LWMHTJ3.js → chunk-I6A5C46N.js} +1 -1
  83. package/dist/standalone/{chunk-H6YOWRFB.js → chunk-KAPSM6AI.js} +1 -1
  84. package/dist/standalone/{chunk-6NY7SPDL.js → chunk-KSRP7GZV.js} +1 -1
  85. package/dist/standalone/chunk-LLF5KWDZ.js +2 -0
  86. package/dist/standalone/chunk-NRCXRCJX.js +1 -0
  87. package/dist/standalone/chunk-OE465DVY.js +1 -0
  88. package/dist/standalone/{chunk-HJ3E4YF5.js → chunk-PXYWCZ7T.js} +1 -1
  89. package/dist/standalone/{chunk-PZVU2QMX.js → chunk-Q7QTRX2E.js} +1 -1
  90. package/dist/standalone/{chunk-E3NMX2VU.js → chunk-S4ILMYP5.js} +1 -1
  91. package/dist/standalone/{chunk-KC44QCN6.js → chunk-SDQBPFLO.js} +1 -1
  92. package/dist/standalone/chunk-SV52HB7D.js +1 -0
  93. package/dist/standalone/{chunk-WBYSSCV2.js → chunk-T242WITF.js} +1 -1
  94. package/dist/standalone/{chunk-VHWOCPRK.js → chunk-TBRZQICB.js} +1 -1
  95. package/dist/standalone/{chunk-6LNCYDZO.js → chunk-TQXZ7LG4.js} +1 -1
  96. package/dist/standalone/chunk-U457LHCO.js +1 -0
  97. package/dist/standalone/chunk-UBPYN4DU.js +1 -0
  98. package/dist/standalone/{chunk-34D36UCW.js → chunk-UDVB4URN.js} +1 -1
  99. package/dist/standalone/{chunk-6IKEW5LG.js → chunk-UETNCBWU.js} +1 -1
  100. package/dist/standalone/{chunk-OY2RVUZL.js → chunk-UU2QJMGJ.js} +1 -1
  101. package/dist/standalone/chunk-VC5SSRUP.js +1 -0
  102. package/dist/standalone/{chunk-GXSZH7VJ.js → chunk-VCXH5V3Z.js} +1 -1
  103. package/dist/standalone/{chunk-RNRJKBY3.js → chunk-VTLYN3CX.js} +1 -1
  104. package/dist/standalone/{chunk-3O3HAXW7.js → chunk-WDG4WFUV.js} +1 -1
  105. package/dist/standalone/{chunk-3STOIE7Q.js → chunk-WJGOI3FZ.js} +1 -1
  106. package/dist/standalone/{chunk-W6SAOXGH.js → chunk-WLZ7YPBH.js} +1 -1
  107. package/dist/standalone/{chunk-2VDFV5TD.js → chunk-WQVVA5NB.js} +1 -1
  108. package/dist/standalone/{chunk-TTGOOYLF.js → chunk-WZ3B3MEV.js} +1 -1
  109. package/dist/standalone/{chunk-SKW6J4VW.js → chunk-Y7A5NCXT.js} +1 -1
  110. package/dist/standalone/{chunk-IHQC7J35.js → chunk-YSRW5RNU.js} +1 -1
  111. package/dist/standalone/{chunk-GAX5IZYG.js → chunk-YTA2HGRD.js} +1 -1
  112. package/dist/standalone/chunk-ZHBIKP5G.js +1 -0
  113. package/dist/standalone/{chunk-CCVXYYPJ.js → chunk-ZK3XKFCI.js} +1 -1
  114. package/dist/standalone/studio.js +1 -1
  115. package/dist/styles.css +1 -1
  116. package/package.json +5 -5
  117. package/dist/packem_shared/ADMIN_FUNCTIONS-BnD4aovm.js +0 -1
  118. package/dist/packem_shared/DataBrowser-CuRlztBz.js +0 -1
  119. package/dist/packem_shared/GlobalDataBrowser-DB-vQ2_H.js +0 -1
  120. package/dist/packem_shared/studio-q-C-acL7.js +0 -2
  121. package/dist/packem_shared/table-list-sidebar-BFkSQwlB.js +0 -1
  122. package/dist/standalone/chunk-2GA4SHO7.js +0 -1
  123. package/dist/standalone/chunk-2WOIRKEI.js +0 -1
  124. package/dist/standalone/chunk-6PNPIW6I.js +0 -2
  125. package/dist/standalone/chunk-6YI4WJO4.js +0 -1
  126. package/dist/standalone/chunk-A74VSSA2.js +0 -4
  127. package/dist/standalone/chunk-CT5MMH4O.js +0 -1
  128. package/dist/standalone/chunk-GB6U2BPU.js +0 -1
  129. package/dist/standalone/chunk-GEDMLM4A.js +0 -6
  130. package/dist/standalone/chunk-S252DAFP.js +0 -1
  131. package/dist/standalone/chunk-XS5LDR52.js +0 -1
  132. package/dist/standalone/chunk-YJYTMQJI.js +0 -1
  133. package/dist/standalone/chunk-Z2V42P7J.js +0 -1
  134. /package/dist/standalone/{chunk-SKHEGARW.js → chunk-XF2B7P5A.js} +0 -0
@@ -1 +1 @@
1
- import{c as W}from"react/compiler-runtime";import{useState as K}from"react";import{E as G}from"../packem_shared/error-alert-t6cpEi0z.js";import{L as J}from"../packem_shared/live-status-CmuRLFKf.js";import{ShardInput as V}from"../packem_shared/ShardInput-BVn2iCU0.js";import{g as X}from"../packem_shared/badge-BbuuAio7.js";import{u as Y}from"../packem_shared/button-BkCrNcAs.js";import{c as Z,u as tt}from"../packem_shared/card-CIDGUN6K.js";import{E as et}from"../packem_shared/empty-state-Cg7t_8qu.js";import{n as rt,d as at,m as P,p as l,f as st,u as n}from"../packem_shared/table-DdJBrClo.js";import{N as lt}from"../packem_shared/use-admin-query-QJ-ibl5u.js";import nt from"../packem_shared/useDebounced-Ihdiid_k.js";import{useT as ot}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as it}from"../packem_shared/ADMIN_FUNCTIONS-BnD4aovm.js";import{i as ct}from"../packem_shared/internal-BSIsQVC6.js";import{c as z}from"../packem_shared/utils-bhneXptQ.js";import{jsx as e,jsxs as y}from"react/jsx-runtime";const dt={action:"outline",mutation:"default",query:"secondary"},O=r=>r<1e3?`${r<10?r.toFixed(1):Math.round(r).toString()}ms`:`${(r/1e3).toFixed(2)}s`,mt=r=>r.calls===0?"—":r.errors===0?"0":`${r.errors.toString()} (${(r.errors/r.calls*100).toFixed(1)}%)`,ut=r=>{const t=r.conflicts??0;return r.calls===0?"—":t===0?"0":`${t.toString()} (${(t/r.calls*100).toFixed(1)}%)`},ht={calls:(r,t)=>t.calls-r.calls,recent:(r,t)=>t.lastCalledAt-r.lastCalledAt,slowest:(r,t)=>t.maxDurationMs-r.maxDurationMs},Dt=r=>{const t=W(47),{functions:_,initialShardKey:R}=r,s=ot(),[o,U]=K(R??""),[i,B]=K("recent");let S;t[0]!==o?(S=o.trim(),t[0]=o,t[1]=S):S=t[1];const T=nt(S,400);let M;t[2]===Symbol.for("react.memo_cache_sentinel")?(M={},t[2]=M):M=t[2];let w;t[3]!==T?(w={live:!0,shardKey:T},t[3]=T,t[4]=w):w=t[4];const{data:H,error:c,errorSource:$,liveError:v}=lt(it.getFunctionStats,M,w),b=H?.functions??null;let E;t[5]!==_?(E=new Map((_??[]).map(ft)),t[5]=_,t[6]=E):E=t[6];const L=E;let C;t[7]===Symbol.for("react.memo_cache_sentinel")?(C=k=>{B(k.currentTarget.dataset.sort)},t[7]=C):C=t[7];const Q=C;let F;if(t[8]!==c||t[9]!==$||t[10]!==L||t[11]!==v||t[12]!==o||t[13]!==i||t[14]!==b||t[15]!==s){const k=b===null?[]:b.toSorted(ht[i]);let d;t[17]!==s?(d=s("Recent"),t[17]=s,t[18]=d):d=t[18];let m;t[19]!==d?(m={key:"recent",label:d},t[19]=d,t[20]=m):m=t[20];let u;t[21]!==s?(u=s("Most called"),t[21]=s,t[22]=u):u=t[22];let h;t[23]!==u?(h={key:"calls",label:u},t[23]=u,t[24]=h):h=t[24];let f;t[25]!==s?(f=s("Slowest"),t[25]=s,t[26]=f):f=t[26];let p;t[27]!==f?(p={key:"slowest",label:f},t[27]=f,t[28]=p):p=t[28];let I;t[29]!==h||t[30]!==p||t[31]!==m?(I=[m,h,p],t[29]=h,t[30]=p,t[31]=m,t[32]=I):I=t[32];const j=I;let x;t[33]!==o?(x=e(V,{onChange:U,testId:"fs-shard-input",value:o}),t[33]=o,t[34]=x):x=t[34];let g;t[35]!==v?(g=e(J,{message:v,prefix:"fs"}),t[35]=v,t[36]=g):g=t[36];let N;t[37]!==j||t[38]!==i?(N=e("div",{className:"ml-auto flex items-center gap-1",role:"group",children:j.map(a=>e(Y,{"data-sort":a.key,"data-testid":`fs-sort-${a.key}`,onClick:Q,size:"sm",type:"button",variant:i===a.key?"secondary":"ghost",children:a.label},a.key))}),t[37]=j,t[38]=i,t[39]=N):N=t[39];let A;t[40]!==x||t[41]!==g||t[42]!==N?(A=y("div",{className:"flex flex-wrap items-center gap-2",children:[x,g,N]}),t[40]=x,t[41]=g,t[42]=N,t[43]=A):A=t[43];let D;t[44]!==c||t[45]!==$?(D=c!==null&&e(G,{error:$,testId:"fs-error"}),t[44]=c,t[45]=$,t[46]=D):D=t[46],F=y("div",{className:"flex flex-col gap-4","data-testid":"lunora-function-stats",children:[A,D,b!==null&&k.length===0&&c===null&&e(et,{description:s("Per-function call counts, error rates, and latency land here after your first request."),icon:y("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:[e("path",{d:"M3 3v18h18"}),e("path",{d:"M7 14l4-4 3 3 5-6"})]}),testId:"fs-empty",title:s("No functions have run on this shard yet.")}),k.length>0&&e(Z,{className:"overflow-hidden py-0",children:e(tt,{className:"px-0",children:y(rt,{"data-testid":"fs-table",children:[e(at,{children:y(P,{children:[e(l,{children:s("function")}),e(l,{children:s("kind")}),e(l,{className:"text-right",children:s("calls")}),e(l,{className:"text-right",children:s("errors")}),e(l,{className:"text-right",children:s("conflicts")}),e(l,{className:"text-right",children:s("avg")}),e(l,{className:"text-right",children:s("max")}),e(l,{children:s("last run")}),e(l,{children:s("last error")})]})}),e(st,{children:k.map(a=>{const q=L.get(a.path);return y(P,{"data-testid":`fs-row-${a.path}`,children:[e(n,{className:"font-medium",children:a.path}),e(n,{children:q===void 0?e("span",{className:"text-muted-foreground",children:"—"}):e(X,{variant:dt[q],children:q})}),e(n,{className:"text-right tabular-nums",children:a.calls}),e(n,{className:z("text-right tabular-nums",a.errors>0&&"text-destructive"),children:mt(a)}),e(n,{className:z("text-right tabular-nums",(a.conflicts??0)>0&&"text-warning"),children:ut(a)}),e(n,{className:"text-right tabular-nums",children:a.calls===0?"—":O(a.totalDurationMs/a.calls)}),e(n,{className:"text-right tabular-nums",children:a.calls===0?"—":O(a.maxDurationMs)}),e(n,{className:"text-muted-foreground",children:ct(a.lastCalledAt,"—")}),e(n,{className:"max-w-[24ch] truncate text-destructive",title:a.lastErrorMessage??void 0,children:a.lastErrorMessage??e("span",{className:"text-muted-foreground",children:"—"})})]},a.path)})})]})})})]}),t[8]=c,t[9]=$,t[10]=L,t[11]=v,t[12]=o,t[13]=i,t[14]=b,t[15]=s,t[16]=F}else F=t[16];return F};function ft(r){return[r.path,r.kind]}export{Dt as FunctionStatsPanel};
1
+ import{c as W}from"react/compiler-runtime";import{useState as K}from"react";import{E as G}from"../packem_shared/error-alert-t6cpEi0z.js";import{L as J}from"../packem_shared/live-status-CmuRLFKf.js";import{ShardInput as V}from"../packem_shared/ShardInput-BVn2iCU0.js";import{g as X}from"../packem_shared/badge-BbuuAio7.js";import{u as Y}from"../packem_shared/button-BkCrNcAs.js";import{c as Z,u as tt}from"../packem_shared/card-CIDGUN6K.js";import{E as et}from"../packem_shared/empty-state-Cg7t_8qu.js";import{n as rt,d as at,m as P,p as l,f as st,u as n}from"../packem_shared/table-DdJBrClo.js";import{N as lt}from"../packem_shared/use-admin-query-QJ-ibl5u.js";import nt from"../packem_shared/useDebounced-Ihdiid_k.js";import{useT as ot}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as it}from"../packem_shared/ADMIN_FUNCTIONS-CZESgd10.js";import{i as ct}from"../packem_shared/internal-BSIsQVC6.js";import{c as z}from"../packem_shared/utils-bhneXptQ.js";import{jsx as e,jsxs as y}from"react/jsx-runtime";const dt={action:"outline",mutation:"default",query:"secondary"},O=r=>r<1e3?`${r<10?r.toFixed(1):Math.round(r).toString()}ms`:`${(r/1e3).toFixed(2)}s`,mt=r=>r.calls===0?"—":r.errors===0?"0":`${r.errors.toString()} (${(r.errors/r.calls*100).toFixed(1)}%)`,ut=r=>{const t=r.conflicts??0;return r.calls===0?"—":t===0?"0":`${t.toString()} (${(t/r.calls*100).toFixed(1)}%)`},ht={calls:(r,t)=>t.calls-r.calls,recent:(r,t)=>t.lastCalledAt-r.lastCalledAt,slowest:(r,t)=>t.maxDurationMs-r.maxDurationMs},Dt=r=>{const t=W(47),{functions:_,initialShardKey:R}=r,s=ot(),[o,U]=K(R??""),[i,B]=K("recent");let S;t[0]!==o?(S=o.trim(),t[0]=o,t[1]=S):S=t[1];const T=nt(S,400);let M;t[2]===Symbol.for("react.memo_cache_sentinel")?(M={},t[2]=M):M=t[2];let w;t[3]!==T?(w={live:!0,shardKey:T},t[3]=T,t[4]=w):w=t[4];const{data:H,error:c,errorSource:$,liveError:v}=lt(it.getFunctionStats,M,w),b=H?.functions??null;let E;t[5]!==_?(E=new Map((_??[]).map(ft)),t[5]=_,t[6]=E):E=t[6];const L=E;let C;t[7]===Symbol.for("react.memo_cache_sentinel")?(C=k=>{B(k.currentTarget.dataset.sort)},t[7]=C):C=t[7];const Q=C;let F;if(t[8]!==c||t[9]!==$||t[10]!==L||t[11]!==v||t[12]!==o||t[13]!==i||t[14]!==b||t[15]!==s){const k=b===null?[]:b.toSorted(ht[i]);let d;t[17]!==s?(d=s("Recent"),t[17]=s,t[18]=d):d=t[18];let m;t[19]!==d?(m={key:"recent",label:d},t[19]=d,t[20]=m):m=t[20];let u;t[21]!==s?(u=s("Most called"),t[21]=s,t[22]=u):u=t[22];let h;t[23]!==u?(h={key:"calls",label:u},t[23]=u,t[24]=h):h=t[24];let f;t[25]!==s?(f=s("Slowest"),t[25]=s,t[26]=f):f=t[26];let p;t[27]!==f?(p={key:"slowest",label:f},t[27]=f,t[28]=p):p=t[28];let I;t[29]!==h||t[30]!==p||t[31]!==m?(I=[m,h,p],t[29]=h,t[30]=p,t[31]=m,t[32]=I):I=t[32];const j=I;let x;t[33]!==o?(x=e(V,{onChange:U,testId:"fs-shard-input",value:o}),t[33]=o,t[34]=x):x=t[34];let g;t[35]!==v?(g=e(J,{message:v,prefix:"fs"}),t[35]=v,t[36]=g):g=t[36];let N;t[37]!==j||t[38]!==i?(N=e("div",{className:"ml-auto flex items-center gap-1",role:"group",children:j.map(a=>e(Y,{"data-sort":a.key,"data-testid":`fs-sort-${a.key}`,onClick:Q,size:"sm",type:"button",variant:i===a.key?"secondary":"ghost",children:a.label},a.key))}),t[37]=j,t[38]=i,t[39]=N):N=t[39];let A;t[40]!==x||t[41]!==g||t[42]!==N?(A=y("div",{className:"flex flex-wrap items-center gap-2",children:[x,g,N]}),t[40]=x,t[41]=g,t[42]=N,t[43]=A):A=t[43];let D;t[44]!==c||t[45]!==$?(D=c!==null&&e(G,{error:$,testId:"fs-error"}),t[44]=c,t[45]=$,t[46]=D):D=t[46],F=y("div",{className:"flex flex-col gap-4","data-testid":"lunora-function-stats",children:[A,D,b!==null&&k.length===0&&c===null&&e(et,{description:s("Per-function call counts, error rates, and latency land here after your first request."),icon:y("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:[e("path",{d:"M3 3v18h18"}),e("path",{d:"M7 14l4-4 3 3 5-6"})]}),testId:"fs-empty",title:s("No functions have run on this shard yet.")}),k.length>0&&e(Z,{className:"overflow-hidden py-0",children:e(tt,{className:"px-0",children:y(rt,{"data-testid":"fs-table",children:[e(at,{children:y(P,{children:[e(l,{children:s("function")}),e(l,{children:s("kind")}),e(l,{className:"text-right",children:s("calls")}),e(l,{className:"text-right",children:s("errors")}),e(l,{className:"text-right",children:s("conflicts")}),e(l,{className:"text-right",children:s("avg")}),e(l,{className:"text-right",children:s("max")}),e(l,{children:s("last run")}),e(l,{children:s("last error")})]})}),e(st,{children:k.map(a=>{const q=L.get(a.path);return y(P,{"data-testid":`fs-row-${a.path}`,children:[e(n,{className:"font-medium",children:a.path}),e(n,{children:q===void 0?e("span",{className:"text-muted-foreground",children:"—"}):e(X,{variant:dt[q],children:q})}),e(n,{className:"text-right tabular-nums",children:a.calls}),e(n,{className:z("text-right tabular-nums",a.errors>0&&"text-destructive"),children:mt(a)}),e(n,{className:z("text-right tabular-nums",(a.conflicts??0)>0&&"text-warning"),children:ut(a)}),e(n,{className:"text-right tabular-nums",children:a.calls===0?"—":O(a.totalDurationMs/a.calls)}),e(n,{className:"text-right tabular-nums",children:a.calls===0?"—":O(a.maxDurationMs)}),e(n,{className:"text-muted-foreground",children:ct(a.lastCalledAt,"—")}),e(n,{className:"max-w-[24ch] truncate text-destructive",title:a.lastErrorMessage??void 0,children:a.lastErrorMessage??e("span",{className:"text-muted-foreground",children:"—"})})]},a.path)})})]})})})]}),t[8]=c,t[9]=$,t[10]=L,t[11]=v,t[12]=o,t[13]=i,t[14]=b,t[15]=s,t[16]=F}else F=t[16];return F};function ft(r){return[r.path,r.kind]}export{Dt as FunctionStatsPanel};
@@ -1 +1 @@
1
- import{c as fe}from"react/compiler-runtime";import{useLunora as pe}from"@lunora/react";import{useState as v,useRef as P,useEffect as C,useCallback as he}from"react";import ge from"../packem_shared/ConnectionBadge-DOk0CQWo.js";import{L as xe}from"../packem_shared/live-status-CmuRLFKf.js";import{g as F}from"../packem_shared/badge-BbuuAio7.js";import{c as S}from"../packem_shared/card-CIDGUN6K.js";import{N as ve}from"../packem_shared/use-admin-query-QJ-ibl5u.js";import{useT as Ne}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as b}from"../packem_shared/ADMIN_FUNCTIONS-BnD4aovm.js";import{f as B,i as be,d as Z,b as ee,g as q}from"../packem_shared/internal-BSIsQVC6.js";import{l as we}from"../packem_shared/shard-history-DMEW5VBE.js";import{c as M}from"../packem_shared/utils-bhneXptQ.js";import{shardsToAggregate as ye}from"../packem_shared/aggregateMetrics-BNfajLa2.js";import{S as G}from"../packem_shared/sparkline-CgjeUU2I.js";import{jsxs as i,jsx as s}from"react/jsx-runtime";const te={completed:0,failed:2,in_progress:1},ke=a=>{let e=0,t=0,r=0,l=0;const u=[];for(const{metrics:m}of a){if(m===null){l+=1;continue}r+=1,e+=m.requests,t+=m.errors,u.push(...m.history??[])}return{errors:t,failed:l,history:u,reachable:r,requests:e}},Se=a=>{const e=new Map;for(const t of a)for(const r of t){const l=e.get(r.path);if(l===void 0){e.set(r.path,{...r});continue}l.calls+=r.calls,l.errors+=r.errors,l.totalDurationMs+=r.totalDurationMs,l.scans=(l.scans??0)+(r.scans??0),l.maxDurationMs=Math.max(l.maxDurationMs,r.maxDurationMs),l.lastCalledAt=Math.max(l.lastCalledAt,r.lastCalledAt),(r.lastErrorAt??0)>(l.lastErrorAt??0)&&(l.lastErrorAt=r.lastErrorAt,l.lastErrorMessage=r.lastErrorMessage)}return[...e.values()]},Me=a=>{const e=new Map;for(const t of a)for(const r of t){const l=e.get(r.id);if(l===void 0){e.set(r.id,r);continue}const u=te[r.status]-te[l.status];(u>0||u===0&&(r.updatedAt??0)>(l.updatedAt??0))&&e.set(r.id,r)}return[...e.values()]},qe=q(b.getAuthMetrics),Ae=q(b.getFunctionStats),Ee=q(b.getLogs),je=q(b.getMetrics),De=q(b.migrationStatus),Ie=5,re=2e3,$e=5,se=.01,ae=.05,Le=.1,Pe=.3,Ce=1,Fe=50,V=(a,e,t)=>a>=t?"crit":a>=e?"warn":"ok",Te=(a,e,t)=>a>=t?"crit":a>=e?"warn":"ok",Oe={crit:"destructive",ok:"secondary",warn:"default"},T=(a,e)=>e===0?"—":`${(a/e*100).toFixed(1)}%`,Re=a=>{const e=new Map;for(const r of a??[]){const l=e.get(r.bucketMs)??{calls:0,errors:0};l.calls+=r.calls,l.errors+=r.errors,e.set(r.bucketMs,l)}const t=[...e.entries()].toSorted((r,l)=>r[0]-l[0]);return{errors:t.map(([,r])=>r.errors),requests:t.map(([,r])=>r.calls)}},_e=a=>{let e=0,t=0;for(const l of a)l.status==="failed"?e+=1:l.status==="in_progress"&&(t+=1);let r="ok";return e>0?r="crit":t>0&&(r="warn"),{failed:e,level:r,running:t}},ze=(a,e)=>a.failed>0?e("{count} failed",{count:a.failed.toString()}):a.running>0?e("{count} running",{count:a.running.toString()}):e("OK"),le={crit:"bg-destructive",ok:"bg-success",warn:"bg-warning"},ne={crit:"text-destructive",ok:"text-foreground",warn:"text-warning"},He={crit:"bg-destructive/10 text-destructive",ok:"bg-success/10 text-success",warn:"bg-warning/10 text-warning"},Ke=a=>a.includes("crit")?"crit":a.includes("warn")?"warn":"ok",O=a=>{const e=fe(19),{chart:t,label:r,level:l,testId:u,value:m}=a,c=le[l];let p;e[0]!==c?(p=M("size-1.5 shrink-0 rounded-full",c),e[0]=c,e[1]=p):p=e[1];let f;e[2]!==p?(f=s("span",{"aria-hidden":"true",className:p}),e[2]=p,e[3]=f):f=e[3];let h;e[4]!==r||e[5]!==f?(h=i("span",{className:"flex items-center gap-1.5 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:[f,r]}),e[4]=r,e[5]=f,e[6]=h):h=e[6];const N=ne[l];let d;e[7]!==N?(d=M("truncate text-2xl font-semibold tabular-nums",N),e[7]=N,e[8]=d):d=e[8];let o;e[9]!==d||e[10]!==u||e[11]!==m?(o=s("span",{className:d,"data-testid":u,children:m}),e[9]=d,e[10]=u,e[11]=m,e[12]=o):o=e[12];let g;e[13]!==t||e[14]!==o?(g=i("div",{className:"flex items-center justify-between gap-3",children:[o,t]}),e[13]=t,e[14]=o,e[15]=g):g=e[15];let x;return e[16]!==h||e[17]!==g?(x=s(S,{className:"gap-0 py-0",children:i("div",{className:"flex flex-col gap-2.5 p-4",children:[h,g]})}),e[16]=h,e[17]=g,e[18]=x):x=e[18],x},Ue=async(a,e,t)=>{const r=await Promise.all(t.map(d=>{const o=Z(d);return Promise.allSettled([a.query(je,{},o),a.query(Ae,{},o),a.query(De,{},o)])})),l=Z(e),u=typeof a.schedulerStatus=="function"?a.schedulerStatus():Promise.reject(new Error("scheduler status unavailable")),[m,c,p]=await Promise.allSettled([a.query(Ee,{},l),a.query(qe,{},l),u]),f=r.map(([d,o,g])=>({functions:o.status==="fulfilled"?o.value.functions:[],metrics:d.status==="fulfilled"?d.value:null,migrations:g.status==="fulfilled"?g.value.migrations:[]})),h=ke(f),N=r[0]?.[0];return{auth:c.status==="fulfilled"?c.value:null,entries:m.status==="fulfilled"?m.value.entries:[],functions:Se(f.map(d=>d.functions)),logsError:m.status==="rejected"?ee(m.reason):null,metricsError:h.reachable===0&&N?.status==="rejected"?ee(N.reason):null,migrations:Me(f.map(d=>d.migrations)),scheduler:p.status==="fulfilled"?p.value:null,totals:h}},Be=a=>{const e=a?.history??[];return{attempts:e.map(t=>t.attempts),failures:e.map(t=>t.failures)}},ot=({initialShardKey:a})=>{const e=pe(),t=Ne(),[r,l]=v([]),[u,m]=v(null),[c,p]=v(null),[f,h]=v(null),[N,d]=v([]),[o,g]=v(null),[x,ie]=v(null),[oe,ce]=v([]),[w]=v(we),A=P(!1),R=P(!0);C(()=>(R.current=!0,()=>{R.current=!1}),[]);const E=a??"",j=he(async()=>{if(A.current)return;A.current=!0;const n=await Ue(e,E,ye(E,w));if(!R.current){A.current=!1;return}p(n.totals),h(n.metricsError),d(n.functions),ce(n.migrations),l(n.entries),m(n.logsError),g(n.auth),ie(n.scheduler),A.current=!1},[e,w,E]);C(()=>{B(j())},[j]);const _=P(0),y=P(null),de=()=>{const n=Date.now()-_.current;if(n>=re){_.current=Date.now(),B(j());return}y.current===null&&(y.current=setTimeout(()=>{y.current=null,_.current=Date.now(),B(j())},re-n))};C(()=>()=>{y.current!==null&&clearTimeout(y.current)},[]);const{data:J,liveError:ue}=ve(b.getMetrics,{},{live:!0,shardKey:E});C(()=>{J!==void 0&&de()},[J]);const z=r.filter(n=>n.level==="error"),H=z.slice(0,Ie),D=Re(c?.history),Q=Be(o),W=N.filter(n=>n.calls>0).toSorted((n,k)=>k.errors/k.calls-n.errors/n.calls||k.calls-n.calls).slice(0,$e),K=_e(oe),me=c===null||c.requests===0?0:c.errors/c.requests,U=V(me,se,ae),X=o===null?"ok":V(o.failureRate,Le,Pe),Y=x===null?"ok":Te(x.backlog,Ce,Fe),I=Ke([U,X,Y,K.level]);let $,L;return I==="crit"?($=t("Critical"),L=t("One or more service levels are breached.")):I==="warn"?($=t("Degraded"),L=t("Some service levels need attention.")):($=t("All systems healthy"),L=t("All service levels are within target.")),i("div",{className:"flex flex-col gap-6","data-testid":"lunora-health",children:[i(S,{className:"gap-0 py-0",children:[i("div",{className:"flex flex-wrap items-center justify-between gap-4 p-4",children:[i("div",{className:"flex items-center gap-3",children:[s("span",{"aria-hidden":"true",className:M("flex size-10 shrink-0 items-center justify-center rounded-full",He[I]),children:s("span",{className:M("size-3 rounded-full",le[I])})}),i("div",{className:"grid leading-tight",children:[s("span",{className:"text-sm font-semibold text-foreground","data-testid":"hl-status",children:$}),s("span",{className:"text-[13px] text-muted-foreground",children:L})]})]}),i("div",{className:"flex flex-wrap items-center gap-4",children:[i("div",{className:"text-end",children:[s("div",{className:"font-mono text-[10px] tracking-wide text-muted-foreground uppercase",children:t("Requests")}),i("div",{className:"flex items-center justify-end gap-2",children:[D.requests.length>=2&&s(G,{ariaLabel:t("Requests over time"),className:"h-6 w-20 text-foreground",series:D.requests,testId:"hl-spark-requests"}),s("span",{className:"text-lg font-semibold tabular-nums text-foreground","data-testid":"hl-requests",children:(c?.requests??0).toString()})]})]}),s("span",{"aria-hidden":"true",className:"h-9 w-px bg-border"}),i("div",{className:"text-end",children:[s("div",{className:"font-mono text-[10px] tracking-wide text-muted-foreground uppercase",children:t("Error rate")}),s("div",{className:M("text-lg font-semibold tabular-nums",ne[U]),"data-testid":"hl-error-rate",children:c===null?"—":T(c.errors,c.requests)})]}),s("span",{"aria-hidden":"true",className:"h-9 w-px bg-border"}),i("div",{className:"flex items-center gap-2",children:[s(ge,{}),s(xe,{message:ue,prefix:"hl"})]})]})]}),f!==null&&s("div",{className:"border-t border-border bg-destructive/5 px-4 py-2 text-sm text-destructive","data-testid":"hl-metrics-error",role:"alert",children:f})]}),i("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4","data-testid":"hl-slo",children:[s(O,{chart:D.errors.length>=2?s(G,{ariaLabel:t("Errors over time"),className:"h-7 w-20 text-destructive",series:D.errors,testId:"hl-spark-errors"}):void 0,label:t("Error rate"),level:U,testId:"hl-slo-errorrate",value:c===null?"—":T(c.errors,c.requests)}),s(O,{chart:Q.failures.length>=2?s(G,{ariaLabel:t("Auth failures over time"),className:"h-7 w-20 text-destructive",series:Q.failures,testId:"hl-spark-auth"}):void 0,label:t("Auth failures"),level:X,testId:"hl-slo-auth",value:o===null?"—":T(o.failures,o.attempts)}),s(O,{label:t("Scheduler backlog"),level:Y,testId:"hl-slo-backlog",value:x===null?"—":x.backlog.toString()}),s(O,{label:t("Migrations"),level:K.level,testId:"hl-slo-migrations",value:ze(K,t)})]}),i("div",{className:"grid gap-3 lg:grid-cols-2",children:[i(S,{className:"gap-0 py-0","data-testid":"hl-functions",children:[s("header",{className:"border-b border-border px-4 py-3",children:s("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:t("Functions by error rate")})}),W.length===0?s("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground","data-testid":"hl-functions-empty",children:t("No function activity yet.")}):s("ul",{className:"divide-y divide-border",children:W.map(n=>i("li",{className:"flex flex-wrap items-center justify-between gap-2 px-4 py-2 text-xs","data-testid":"hl-fn-row",children:[s("span",{className:"truncate font-mono text-foreground",children:n.path}),i("span",{className:"flex shrink-0 items-center gap-2",children:[s("span",{className:"tabular-nums text-muted-foreground",children:t("{count} calls",{count:n.calls.toString()})}),s(F,{variant:Oe[V(n.errors/n.calls,se,ae)],children:T(n.errors,n.calls)})]})]},n.path))})]}),i(S,{className:"gap-0 py-0",children:[i("header",{className:"flex items-center justify-between gap-2 border-b border-border px-4 py-3",children:[s("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:t("Recent errors")}),s(F,{"data-testid":"hl-error-count",variant:z.length>0?"destructive":"outline",children:z.length})]}),u!==null&&s("p",{className:"px-4 py-8 text-center text-sm text-destructive","data-testid":"hl-logs-error",role:"alert",children:u}),u===null&&H.length===0&&s("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground","data-testid":"hl-errors-empty",children:t("No recent errors.")}),H.length>0&&s("ul",{className:"divide-y divide-border",children:H.map((n,k)=>i("li",{className:"flex flex-col gap-0.5 px-4 py-2 text-xs","data-testid":"hl-error-row",children:[i("span",{className:"flex items-center gap-2",children:[s("time",{className:"shrink-0 text-muted-foreground",children:be(n.timestamp)}),n.functionPath!==void 0&&s("span",{className:"truncate font-mono text-foreground",children:n.functionPath})]}),s("span",{className:"text-destructive",children:n.message})]},`${n.timestamp.toString()}-${k.toString()}`))})]})]}),i(S,{className:"gap-0 py-0",children:[i("header",{className:"flex items-center justify-between gap-2 border-b border-border px-4 py-3",children:[s("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:t("Shards seen")}),s(F,{"data-testid":"hl-shard-count",variant:"outline",children:w.length})]}),w.length>0&&s("ul",{className:"flex flex-wrap gap-1.5 p-4",children:w.map(n=>s("li",{"data-testid":"hl-shard",children:s(F,{variant:"secondary",children:n})},n))})]})]})};export{ot as HealthPanel};
1
+ import{c as ae}from"react/compiler-runtime";import{useLunora as he}from"@lunora/react";import{useState as y,useRef as L,useEffect as O,useCallback as ge}from"react";import xe from"../packem_shared/ConnectionBadge-DOk0CQWo.js";import{L as ve}from"../packem_shared/live-status-CmuRLFKf.js";import{g as z}from"../packem_shared/badge-BbuuAio7.js";import{c as A}from"../packem_shared/card-CIDGUN6K.js";import{N as Ne}from"../packem_shared/use-admin-query-QJ-ibl5u.js";import{useT as le}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as M}from"../packem_shared/ADMIN_FUNCTIONS-CZESgd10.js";import{i as be,f as G,d as ee,b as te,g as j}from"../packem_shared/internal-BSIsQVC6.js";import{l as we}from"../packem_shared/shard-history-DMEW5VBE.js";import{c as $}from"../packem_shared/utils-bhneXptQ.js";import{jsx as l,jsxs as d}from"react/jsx-runtime";import{shardsToAggregate as ye}from"../packem_shared/aggregateMetrics-BNfajLa2.js";import{S as Q}from"../packem_shared/sparkline-CgjeUU2I.js";const ke={crit:"destructive",ok:"secondary",warn:"default"},_=(s,e)=>e===0?"—":`${(s/e*100).toFixed(1)}%`,V=(s,e,r)=>Number.isNaN(s)?"ok":s>=r?"crit":s>=e?"warn":"ok",ne=.01,oe=.05,Se=s=>{const e=ae(36),{errorCount:r,logsError:t,topErrors:a,worstFunctions:f}=s,n=le();let o;e[0]!==n?(o=n("Functions by error rate"),e[0]=n,e[1]=o):o=e[1];let p;e[2]!==o?(p=l("header",{className:"border-b border-border px-4 py-3",children:l("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:o})}),e[2]=o,e[3]=p):p=e[3];let m;e[4]!==n||e[5]!==f?(m=f.length===0?l("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground","data-testid":"hl-functions-empty",children:n("No function activity yet.")}):l("ul",{className:"divide-y divide-border",children:f.map(b=>d("li",{className:"flex flex-wrap items-center justify-between gap-2 px-4 py-2 text-xs","data-testid":"hl-fn-row",children:[l("span",{className:"truncate font-mono text-foreground",children:b.path}),d("span",{className:"flex shrink-0 items-center gap-2",children:[l("span",{className:"tabular-nums text-muted-foreground",children:n("{count} calls",{count:b.calls.toString()})}),l(z,{variant:ke[V(b.errors/b.calls,ne,oe)],children:_(b.errors,b.calls)})]})]},b.path))}),e[4]=n,e[5]=f,e[6]=m):m=e[6];let h;e[7]!==p||e[8]!==m?(h=d(A,{className:"gap-0 py-0","data-testid":"hl-functions",children:[p,m]}),e[7]=p,e[8]=m,e[9]=h):h=e[9];let v;e[10]!==n?(v=n("Recent errors"),e[10]=n,e[11]=v):v=e[11];let i;e[12]!==v?(i=l("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:v}),e[12]=v,e[13]=i):i=e[13];const c=r>0?"destructive":"outline";let g;e[14]!==r||e[15]!==c?(g=l(z,{"data-testid":"hl-error-count",variant:c,children:r}),e[14]=r,e[15]=c,e[16]=g):g=e[16];let x;e[17]!==i||e[18]!==g?(x=d("header",{className:"flex items-center justify-between gap-2 border-b border-border px-4 py-3",children:[i,g]}),e[17]=i,e[18]=g,e[19]=x):x=e[19];let k;e[20]!==t?(k=t!==null&&l("p",{className:"px-4 py-8 text-center text-sm text-destructive","data-testid":"hl-logs-error",role:"alert",children:t}),e[20]=t,e[21]=k):k=e[21];let S;e[22]!==t||e[23]!==n||e[24]!==a.length?(S=t===null&&a.length===0&&l("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground","data-testid":"hl-errors-empty",children:n("No recent errors.")}),e[22]=t,e[23]=n,e[24]=a.length,e[25]=S):S=e[25];let E;e[26]!==a?(E=a.length>0&&l("ul",{className:"divide-y divide-border",children:a.map(Ee)}),e[26]=a,e[27]=E):E=e[27];let N;e[28]!==k||e[29]!==S||e[30]!==E||e[31]!==x?(N=d(A,{className:"gap-0 py-0",children:[x,k,S,E]}),e[28]=k,e[29]=S,e[30]=E,e[31]=x,e[32]=N):N=e[32];let w;return e[33]!==N||e[34]!==h?(w=d("div",{className:"grid gap-3 lg:grid-cols-2",children:[h,N]}),e[33]=N,e[34]=h,e[35]=w):w=e[35],w};function Ee(s,e){return d("li",{className:"flex flex-col gap-0.5 px-4 py-2 text-xs","data-testid":"hl-error-row",children:[d("span",{className:"flex items-center gap-2",children:[l("time",{className:"shrink-0 text-muted-foreground",children:be(s.timestamp)}),s.functionPath!==void 0&&l("span",{className:"truncate font-mono text-foreground",children:s.functionPath})]}),l("span",{className:"text-destructive",children:s.message})]},`${s.timestamp.toString()}-${e.toString()}`)}const re={completed:0,failed:2,in_progress:1},Me=s=>{let e=0,r=0,t=0,a=0;const f=[];for(const{metrics:n}of s){if(n===null){a+=1;continue}t+=1,e+=n.requests,r+=n.errors,f.push(...n.history??[])}return{errors:r,failed:a,history:f,reachable:t,requests:e}},qe=s=>{const e=new Map;for(const r of s)for(const t of r){const a=e.get(t.path);if(a===void 0){e.set(t.path,{...t});continue}a.calls+=t.calls,a.errors+=t.errors,a.totalDurationMs+=t.totalDurationMs,a.scans=(a.scans??0)+(t.scans??0),a.maxDurationMs=Math.max(a.maxDurationMs,t.maxDurationMs),a.lastCalledAt=Math.max(a.lastCalledAt,t.lastCalledAt),(t.lastErrorAt??0)>(a.lastErrorAt??0)&&(a.lastErrorAt=t.lastErrorAt,a.lastErrorMessage=t.lastErrorMessage)}return[...e.values()]},$e=s=>{const e=new Map;for(const r of s)for(const t of r){const a=e.get(t.id);if(a===void 0){e.set(t.id,t);continue}const f=re[t.status]-re[a.status];(f>0||f===0&&(t.updatedAt??0)>(a.updatedAt??0))&&e.set(t.id,t)}return[...e.values()]},Ae=j(M.getAuthMetrics),je=j(M.getFunctionStats),Ie=j(M.getLogs),Pe=j(M.getMetrics),Re=j(M.migrationStatus),Ce=5,se=2e3,De=5,Fe=.1,Le=.3,Oe=1,Te=50,_e=(s,e,r)=>s>=r?"crit":s>=e?"warn":"ok",ze=s=>{const e=new Map;for(const t of s??[]){const a=e.get(t.bucketMs)??{calls:0,errors:0};a.calls+=t.calls,a.errors+=t.errors,e.set(t.bucketMs,a)}const r=[...e.entries()].toSorted((t,a)=>t[0]-a[0]);return{errors:r.map(([,t])=>t.errors),requests:r.map(([,t])=>t.calls)}},Ke=s=>{let e=0,r=0;for(const a of s)a.status==="failed"?e+=1:a.status==="in_progress"&&(r+=1);let t="ok";return e>0?t="crit":r>0&&(t="warn"),{failed:e,level:t,running:r}},He=(s,e)=>s.failed>0?e("{count} failed",{count:s.failed.toString()}):s.running>0?e("{count} running",{count:s.running.toString()}):e("OK"),ie={crit:"bg-destructive",ok:"bg-success",warn:"bg-warning"},ce={crit:"text-destructive",ok:"text-foreground",warn:"text-warning"},Ue={crit:"bg-destructive/10 text-destructive",ok:"bg-success/10 text-success",warn:"bg-warning/10 text-warning"},Be=s=>s.includes("crit")?"crit":s.includes("warn")?"warn":"ok",T=s=>{const e=ae(19),{chart:r,label:t,level:a,testId:f,value:n}=s,o=ie[a];let p;e[0]!==o?(p=$("size-1.5 shrink-0 rounded-full",o),e[0]=o,e[1]=p):p=e[1];let m;e[2]!==p?(m=l("span",{"aria-hidden":"true",className:p}),e[2]=p,e[3]=m):m=e[3];let h;e[4]!==t||e[5]!==m?(h=d("span",{className:"flex items-center gap-1.5 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:[m,t]}),e[4]=t,e[5]=m,e[6]=h):h=e[6];const v=ce[a];let i;e[7]!==v?(i=$("truncate text-2xl font-semibold tabular-nums",v),e[7]=v,e[8]=i):i=e[8];let c;e[9]!==i||e[10]!==f||e[11]!==n?(c=l("span",{className:i,"data-testid":f,children:n}),e[9]=i,e[10]=f,e[11]=n,e[12]=c):c=e[12];let g;e[13]!==r||e[14]!==c?(g=d("div",{className:"flex items-center justify-between gap-3",children:[c,r]}),e[13]=r,e[14]=c,e[15]=g):g=e[15];let x;return e[16]!==h||e[17]!==g?(x=l(A,{className:"gap-0 py-0",children:d("div",{className:"flex flex-col gap-2.5 p-4",children:[h,g]})}),e[16]=h,e[17]=g,e[18]=x):x=e[18],x},Ge=async(s,e,r)=>{const t=await Promise.all(r.map(i=>{const c=ee(i);return Promise.allSettled([s.query(Pe,{},c),s.query(je,{},c),s.query(Re,{},c)])})),a=ee(e),f=typeof s.schedulerStatus=="function"?s.schedulerStatus():Promise.reject(new Error("scheduler status unavailable")),[n,o,p]=await Promise.allSettled([s.query(Ie,{},a),s.query(Ae,{},a),f]),m=t.map(([i,c,g])=>({functions:c.status==="fulfilled"?c.value.functions:[],metrics:i.status==="fulfilled"?i.value:null,migrations:g.status==="fulfilled"?g.value.migrations:[]})),h=Me(m),v=t[0]?.[0];return{auth:o.status==="fulfilled"?o.value:null,entries:n.status==="fulfilled"?n.value.entries:[],functions:qe(m.map(i=>i.functions)),logsError:n.status==="rejected"?te(n.reason):null,metricsError:h.reachable===0&&v?.status==="rejected"?te(v.reason):null,migrations:$e(m.map(i=>i.migrations)),scheduler:p.status==="fulfilled"?p.value:null,totals:h}},Qe=s=>{const e=s?.history??[];return{attempts:e.map(r=>r.attempts),failures:e.map(r=>r.failures)}},dt=({initialShardKey:s})=>{const e=he(),r=le(),[t,a]=y([]),[f,n]=y(null),[o,p]=y(null),[m,h]=y(null),[v,i]=y([]),[c,g]=y(null),[x,k]=y(null),[S,E]=y([]),[N]=y(we),w=L(!1),b=L(!0);O(()=>(b.current=!0,()=>{b.current=!1}),[]);const I=s??"",P=ge(async()=>{if(w.current)return;w.current=!0;const u=await Ge(e,I,ye(I,N));if(!b.current){w.current=!1;return}p(u.totals),h(u.metricsError),i(u.functions),E(u.migrations),a(u.entries),n(u.logsError),g(u.auth),k(u.scheduler),w.current=!1},[e,N,I]);O(()=>{G(P())},[P]);const K=L(0),q=L(null),de=()=>{const u=Date.now()-K.current;if(u>=se){K.current=Date.now(),G(P());return}q.current===null&&(q.current=setTimeout(()=>{q.current=null,K.current=Date.now(),G(P())},se-u))};O(()=>()=>{q.current!==null&&clearTimeout(q.current)},[]);const{data:W,liveError:ue}=Ne(M.getMetrics,{},{live:!0,shardKey:I});O(()=>{W!==void 0&&de()},[W]);const Z=t.filter(u=>u.level==="error"),me=Z.slice(0,Ce),R=ze(o?.history),J=Qe(c),fe=v.filter(u=>u.calls>0).toSorted((u,B)=>B.errors/B.calls-u.errors/u.calls||B.calls-u.calls).slice(0,De),H=Ke(S),pe=o===null||o.requests===0?0:o.errors/o.requests,U=V(pe,ne,oe),X=c===null?"ok":V(c.failureRate,Fe,Le),Y=x===null?"ok":_e(x.backlog,Oe,Te),C=Be([U,X,Y,H.level]);let D,F;return C==="crit"?(D=r("Critical"),F=r("One or more service levels are breached.")):C==="warn"?(D=r("Degraded"),F=r("Some service levels need attention.")):(D=r("All systems healthy"),F=r("All service levels are within target.")),d("div",{className:"flex flex-col gap-6","data-testid":"lunora-health",children:[d(A,{className:"gap-0 py-0",children:[d("div",{className:"flex flex-wrap items-center justify-between gap-4 p-4",children:[d("div",{className:"flex items-center gap-3",children:[l("span",{"aria-hidden":"true",className:$("flex size-10 shrink-0 items-center justify-center rounded-full",Ue[C]),children:l("span",{className:$("size-3 rounded-full",ie[C])})}),d("div",{className:"grid leading-tight",children:[l("span",{className:"text-sm font-semibold text-foreground","data-testid":"hl-status",children:D}),l("span",{className:"text-[13px] text-muted-foreground",children:F})]})]}),d("div",{className:"flex flex-wrap items-center gap-4",children:[d("div",{className:"text-end",children:[l("div",{className:"font-mono text-[10px] tracking-wide text-muted-foreground uppercase",children:r("Requests")}),d("div",{className:"flex items-center justify-end gap-2",children:[R.requests.length>=2&&l(Q,{ariaLabel:r("Requests over time"),className:"h-6 w-20 text-foreground",series:R.requests,testId:"hl-spark-requests"}),l("span",{className:"text-lg font-semibold tabular-nums text-foreground","data-testid":"hl-requests",children:(o?.requests??0).toString()})]})]}),l("span",{"aria-hidden":"true",className:"h-9 w-px bg-border"}),d("div",{className:"text-end",children:[l("div",{className:"font-mono text-[10px] tracking-wide text-muted-foreground uppercase",children:r("Error rate")}),l("div",{className:$("text-lg font-semibold tabular-nums",ce[U]),"data-testid":"hl-error-rate",children:o===null?"—":_(o.errors,o.requests)})]}),l("span",{"aria-hidden":"true",className:"h-9 w-px bg-border"}),d("div",{className:"flex items-center gap-2",children:[l(xe,{}),l(ve,{message:ue,prefix:"hl"})]})]})]}),m!==null&&l("div",{className:"border-t border-border bg-destructive/5 px-4 py-2 text-sm text-destructive","data-testid":"hl-metrics-error",role:"alert",children:m})]}),d("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4","data-testid":"hl-slo",children:[l(T,{chart:R.errors.length>=2?l(Q,{ariaLabel:r("Errors over time"),className:"h-7 w-20 text-destructive",series:R.errors,testId:"hl-spark-errors"}):void 0,label:r("Error rate"),level:U,testId:"hl-slo-errorrate",value:o===null?"—":_(o.errors,o.requests)}),l(T,{chart:J.failures.length>=2?l(Q,{ariaLabel:r("Auth failures over time"),className:"h-7 w-20 text-destructive",series:J.failures,testId:"hl-spark-auth"}):void 0,label:r("Auth failures"),level:X,testId:"hl-slo-auth",value:c===null?"—":_(c.failures,c.attempts)}),l(T,{label:r("Scheduler backlog"),level:Y,testId:"hl-slo-backlog",value:x===null?"—":x.backlog.toString()}),l(T,{label:r("Migrations"),level:H.level,testId:"hl-slo-migrations",value:He(H,r)})]}),l(Se,{errorCount:Z.length,logsError:f,topErrors:me,worstFunctions:fe}),d(A,{className:"gap-0 py-0",children:[d("header",{className:"flex items-center justify-between gap-2 border-b border-border px-4 py-3",children:[l("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:r("Shards seen")}),l(z,{"data-testid":"hl-shard-count",variant:"outline",children:N.length})]}),N.length>0&&l("ul",{className:"flex flex-wrap gap-1.5 p-4",children:N.map(u=>l("li",{"data-testid":"hl-shard",children:l(z,{variant:"secondary",children:u})},u))})]})]})};export{dt as HealthPanel};
@@ -1 +1 @@
1
- import{c as B}from"react/compiler-runtime";import{useLunora as ee}from"@lunora/react";import{useNavigate as te}from"@tanstack/react-router";import{useState as I,useRef as ne,useCallback as j,useEffect as O,useEffectEvent as ae,useMemo as re}from"react";import{ShardInput as ie}from"../packem_shared/ShardInput-BVn2iCU0.js";import{u as se}from"../packem_shared/button-BkCrNcAs.js";import{N as H}from"../packem_shared/use-admin-query-QJ-ibl5u.js";import oe from"../packem_shared/useDebounced-Ihdiid_k.js";import{useT as K}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as T}from"../packem_shared/ADMIN_FUNCTIONS-BnD4aovm.js";import{f as E,d as q,g as J}from"../packem_shared/internal-BSIsQVC6.js";import{r as le}from"../packem_shared/shard-history-DMEW5VBE.js";import{E as U,A as ce}from"../packem_shared/advisor-view-Pa8HLtBv.js";import{ConfirmButton as de}from"../packem_shared/ConfirmButton-CTL3f3kr.js";import{jsx as w}from"react/jsx-runtime";import{deriveInsights as ue}from"../packem_shared/DEFAULT_INSIGHT_THRESHOLDS-B-hcFVoi.js";import{runAdvisor as fe,RUNTIME_LINTS as me}from"@lunora/advisor";const he=t=>{const{suggestedIndex:e,table:r}=t;return!(typeof r!="string"||r.length===0||typeof e!="object"||e===null||!Array.isArray(e.fields)||e.fields.length===0)},pe=(t,e,r)=>{const n=`"${t}"`,a=`"${e}"`,l=r.map(o=>`"${o}"`).join(", ");return`CREATE INDEX IF NOT EXISTS ${a} ON ${n} (${l});`},ge=t=>{const e=B(19),{fields:r,indexName:n,table:a,testId:l}=t,o=K(),[x,d]=I(!1);let u;e[0]!==r||e[1]!==n||e[2]!==a?(u=()=>{const v="navigator"in globalThis?globalThis.navigator.clipboard:void 0;if(v===void 0)return;const b=pe(a,n,r);E(v.writeText(b)),d(!0)},e[0]=r,e[1]=n,e[2]=a,e[3]=u):u=e[3];const m=u;if(x){const v=`${l}-applied`;let b;e[4]!==o?(b=o("CREATE INDEX SQL copied to clipboard."),e[4]=o,e[5]=b):b=e[5];let S;return e[6]!==v||e[7]!==b?(S=w("span",{className:"text-xs text-muted-foreground","data-testid":v,children:b}),e[6]=v,e[7]=b,e[8]=S):S=e[8],S}let h;e[9]!==o?(h=o("Apply?"),e[9]=o,e[10]=h):h=e[10];let f;e[11]!==o||e[12]!==a?(f=o("Apply index on {table}",{table:a}),e[11]=o,e[12]=a,e[13]=f):f=e[13];let g;return e[14]!==m||e[15]!==h||e[16]!==f||e[17]!==l?(g=w(de,{confirmLabel:h,onConfirm:m,testId:l,children:f}),e[14]=m,e[15]=h,e[16]=f,e[17]=l,e[18]=g):g=e[18],g},be=(t,e)=>{const r=new Map;for(const n of e){const a=`${n.table} ${n.index}`;r.set(a,(r.get(a)??0)+n.reads)}return t.map(n=>({index:n.index,reads:r.get(`${n.table} ${n.index}`)??0,table:n.table}))},ve=t=>{const e=new Map;for(const r of t)for(const n of r.scannedTables??[])e.set(n.table,(e.get(n.table)??0)+n.scans);return[...e].map(([r,n])=>({scans:n,table:r}))},xe=(t,e)=>e.map(r=>({index:r.name,table:t})),ye=t=>{const e=be(t.declaredIndexes??[],t.indexHits??[]),r=ve(t.functions??[]),n=t.shardTraffic??[],a=t.analyticsMetrics,l=a&&a.indexHits.length>0?a.indexHits:e,o=a&&a.tableScans.length>0?a.tableScans:r,x=a&&a.shardTraffic.length>0?a.shardTraffic:n,d=fe({indexHits:l,schema:{tables:[]},shardTraffic:x,tableScans:o},{lints:me,source:"runtime"}),u=t.suppressHotScanTables;return(u===void 0?d:d.filter(m=>!(m.metadata.kind==="hot_scan"&&typeof m.metadata.table=="string"&&u.has(m.metadata.table)))).map(m=>U(m))},$e=J(T.listTables),we=J(T.listTableIndexes),M=t=>`${(t*100).toFixed(1)}%`,D=t=>`${(t/1e3).toFixed(2)}s`,Se=t=>{if(t.length<=1)return t[0]??"";const e=t[t.length-1]??"";return`${t.slice(0,-1).join(", ")} and ${e}`},Te=(t,e)=>({"high-error-rate":t("High error rate"),"high-evictions":t("High cache eviction rate"),"high-write-contention":t("High write contention"),"low-cache-hit-rate":t("Low cache hit rate"),"missing-index":t("Missing index"),"slow-function":t("Slow function")})[e.kind],X=(t,e)=>({"high-error-rate":t("{rate} of calls failed.",{rate:M(e.value)}),"high-evictions":t("{count} entries evicted recently.",{count:e.value}),"high-write-contention":t("{rate} of calls hit a write conflict — consider sharding to cut contention.",{rate:M(e.value)}),"low-cache-hit-rate":t("{rate} hit rate over recent traffic.",{rate:M(e.value)}),"missing-index":t("Slowest call took {duration} — it full-scanned {tables} with no index.",{duration:D(e.value),tables:Se(e.tables??[])}),"slow-function":t("Slowest call took {duration}.",{duration:D(e.value)})})[e.kind],Ie=t=>{const e=B(10),{onJump:r,table:n}=t,a=K();let l;e[0]!==r||e[1]!==n?(l=()=>{r(n)},e[0]=r,e[1]=n,e[2]=l):l=e[2];const o=l,x=`in-add-index-${n}`;let d;e[3]!==a||e[4]!==n?(d=a("Add index on {table}",{table:n}),e[3]=a,e[4]=n,e[5]=d):d=e[5];let u;return e[6]!==o||e[7]!==x||e[8]!==d?(u=w(se,{"data-testid":x,onClick:o,size:"sm",type:"button",variant:"outline",children:d}),e[6]=o,e[7]=x,e[8]=d,e[9]=u):u=e[9],u},Be=({initialShardKey:t,loadShardTraffic:e})=>{const r=ee(),n=te(),a=K(),[l,o]=I(t??""),[x,d]=I(null),[u,m]=I(null),h=oe(l.trim(),400),f=ne(""),g=H(T.getMetrics,{},{live:!0,shardKey:h}),v=H(T.getFunctionStats,{},{live:!0,shardKey:h}),b=H(T.getAdvisories,{},{live:!0,shardKey:h}),S=g.data??null,C=v.data?.functions??null,L=b.data?.advisories??null,z=g.data?.indexHits??null,_=g.error!==null&&v.error!==null?g.error:null,P=e??(i=>r.shardTraffic(i)),V=async(i,$)=>{const s=i[0];if(s===void 0||s===""){f.current===$&&m(null);return}try{const y=await P(s);if(f.current!==$)return;const p=new Map;for(const c of y.shards)p.has(c.shardKey)||p.set(c.shardKey,{requests:c.requests,shardKey:c.shardKey});m([...p.values()])}catch{f.current===$&&m(null)}},A=j(async i=>{f.current=i;let $=[];try{const s=await r.query($e,{},q(i));if(f.current!==i)return;le(i),$=s.map(c=>c.name);const y=await Promise.allSettled(s.map(async c=>[c.name,await r.query(we,{table:c.name},q(i))]));if(f.current!==i)return;const p=[];for(const c of y)if(c.status==="fulfilled"){const[k,Z]=c.value;p.push(...xe(k,Z.indexes))}d(p)}catch{f.current===i&&d(null)}await V($,i)},[r]);O(()=>{E(A(h))},[h,A]);const G=ae(()=>{g.refetch(),v.refetch(),b.refetch(),E(A(h))});O(()=>{const i=()=>{document.visibilityState==="visible"&&G()};return document.addEventListener("visibilitychange",i),()=>{document.removeEventListener("visibilitychange",i)}},[]);const R=j(i=>{E(n({search:{table:i},to:"/schema"}))},[n]),N=ue(S,C),Q=new Set(N.filter(i=>i.kind==="missing-index").flatMap(i=>i.tables??[])),F=ye({declaredIndexes:x??[],functions:C,indexHits:z,shardTraffic:u,suppressHotScanTables:Q}),W=re(()=>{const i=N.map(s=>{const y=s.kind==="missing-index"?s.tables??[]:[];return{action:y.length>0?y.map(p=>w(Ie,{onJump:R,table:p},p)):void 0,description:s.message===void 0?X(a,s):`${X(a,s)} — ${s.message}`,entity:s.fn,issueType:Te(a,s),key:`${s.kind}:${s.fn??""}`,level:s.severity}}),$=new Set(["unindexed_foreign_key","unindexed_relation_target"]);return[...(L??[]).map(s=>{const y=U(s);if($.has(s.name)&&he(s.metadata)){const{table:p,suggestedIndex:c}=s.metadata,k=`in-apply-index-${p}-${c.name}`;return{...y,action:w(ge,{fields:c.fields,indexName:c.name,table:p,testId:k})}}return y}),...F,...i]},[L,N,R,F,a]),Y=w(ie,{onChange:o,testId:"in-shard-input",value:l});return w(ce,{error:_,errorSource:_===null?void 0:g.errorSource,rows:W,testId:"lunora-insights",toolbar:Y})};export{Be as InsightsPanel};
1
+ import{c as B}from"react/compiler-runtime";import{useLunora as ee}from"@lunora/react";import{useNavigate as te}from"@tanstack/react-router";import{useState as I,useRef as ne,useCallback as j,useEffect as O,useEffectEvent as ae,useMemo as re}from"react";import{ShardInput as ie}from"../packem_shared/ShardInput-BVn2iCU0.js";import{u as se}from"../packem_shared/button-BkCrNcAs.js";import{N as H}from"../packem_shared/use-admin-query-QJ-ibl5u.js";import oe from"../packem_shared/useDebounced-Ihdiid_k.js";import{useT as K}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as T}from"../packem_shared/ADMIN_FUNCTIONS-CZESgd10.js";import{f as E,d as q,g as J}from"../packem_shared/internal-BSIsQVC6.js";import{r as le}from"../packem_shared/shard-history-DMEW5VBE.js";import{E as U,A as ce}from"../packem_shared/advisor-view-Pa8HLtBv.js";import{ConfirmButton as de}from"../packem_shared/ConfirmButton-CTL3f3kr.js";import{jsx as w}from"react/jsx-runtime";import{deriveInsights as ue}from"../packem_shared/DEFAULT_INSIGHT_THRESHOLDS-B-hcFVoi.js";import{runAdvisor as fe,RUNTIME_LINTS as me}from"@lunora/advisor";const he=t=>{const{suggestedIndex:e,table:r}=t;return!(typeof r!="string"||r.length===0||typeof e!="object"||e===null||!Array.isArray(e.fields)||e.fields.length===0)},pe=(t,e,r)=>{const n=`"${t}"`,a=`"${e}"`,l=r.map(o=>`"${o}"`).join(", ");return`CREATE INDEX IF NOT EXISTS ${a} ON ${n} (${l});`},ge=t=>{const e=B(19),{fields:r,indexName:n,table:a,testId:l}=t,o=K(),[x,d]=I(!1);let u;e[0]!==r||e[1]!==n||e[2]!==a?(u=()=>{const v="navigator"in globalThis?globalThis.navigator.clipboard:void 0;if(v===void 0)return;const b=pe(a,n,r);E(v.writeText(b)),d(!0)},e[0]=r,e[1]=n,e[2]=a,e[3]=u):u=e[3];const m=u;if(x){const v=`${l}-applied`;let b;e[4]!==o?(b=o("CREATE INDEX SQL copied to clipboard."),e[4]=o,e[5]=b):b=e[5];let S;return e[6]!==v||e[7]!==b?(S=w("span",{className:"text-xs text-muted-foreground","data-testid":v,children:b}),e[6]=v,e[7]=b,e[8]=S):S=e[8],S}let h;e[9]!==o?(h=o("Apply?"),e[9]=o,e[10]=h):h=e[10];let f;e[11]!==o||e[12]!==a?(f=o("Apply index on {table}",{table:a}),e[11]=o,e[12]=a,e[13]=f):f=e[13];let g;return e[14]!==m||e[15]!==h||e[16]!==f||e[17]!==l?(g=w(de,{confirmLabel:h,onConfirm:m,testId:l,children:f}),e[14]=m,e[15]=h,e[16]=f,e[17]=l,e[18]=g):g=e[18],g},be=(t,e)=>{const r=new Map;for(const n of e){const a=`${n.table} ${n.index}`;r.set(a,(r.get(a)??0)+n.reads)}return t.map(n=>({index:n.index,reads:r.get(`${n.table} ${n.index}`)??0,table:n.table}))},ve=t=>{const e=new Map;for(const r of t)for(const n of r.scannedTables??[])e.set(n.table,(e.get(n.table)??0)+n.scans);return[...e].map(([r,n])=>({scans:n,table:r}))},xe=(t,e)=>e.map(r=>({index:r.name,table:t})),ye=t=>{const e=be(t.declaredIndexes??[],t.indexHits??[]),r=ve(t.functions??[]),n=t.shardTraffic??[],a=t.analyticsMetrics,l=a&&a.indexHits.length>0?a.indexHits:e,o=a&&a.tableScans.length>0?a.tableScans:r,x=a&&a.shardTraffic.length>0?a.shardTraffic:n,d=fe({indexHits:l,schema:{tables:[]},shardTraffic:x,tableScans:o},{lints:me,source:"runtime"}),u=t.suppressHotScanTables;return(u===void 0?d:d.filter(m=>!(m.metadata.kind==="hot_scan"&&typeof m.metadata.table=="string"&&u.has(m.metadata.table)))).map(m=>U(m))},$e=J(T.listTables),we=J(T.listTableIndexes),M=t=>`${(t*100).toFixed(1)}%`,D=t=>`${(t/1e3).toFixed(2)}s`,Se=t=>{if(t.length<=1)return t[0]??"";const e=t[t.length-1]??"";return`${t.slice(0,-1).join(", ")} and ${e}`},Te=(t,e)=>({"high-error-rate":t("High error rate"),"high-evictions":t("High cache eviction rate"),"high-write-contention":t("High write contention"),"low-cache-hit-rate":t("Low cache hit rate"),"missing-index":t("Missing index"),"slow-function":t("Slow function")})[e.kind],X=(t,e)=>({"high-error-rate":t("{rate} of calls failed.",{rate:M(e.value)}),"high-evictions":t("{count} entries evicted recently.",{count:e.value}),"high-write-contention":t("{rate} of calls hit a write conflict — consider sharding to cut contention.",{rate:M(e.value)}),"low-cache-hit-rate":t("{rate} hit rate over recent traffic.",{rate:M(e.value)}),"missing-index":t("Slowest call took {duration} — it full-scanned {tables} with no index.",{duration:D(e.value),tables:Se(e.tables??[])}),"slow-function":t("Slowest call took {duration}.",{duration:D(e.value)})})[e.kind],Ie=t=>{const e=B(10),{onJump:r,table:n}=t,a=K();let l;e[0]!==r||e[1]!==n?(l=()=>{r(n)},e[0]=r,e[1]=n,e[2]=l):l=e[2];const o=l,x=`in-add-index-${n}`;let d;e[3]!==a||e[4]!==n?(d=a("Add index on {table}",{table:n}),e[3]=a,e[4]=n,e[5]=d):d=e[5];let u;return e[6]!==o||e[7]!==x||e[8]!==d?(u=w(se,{"data-testid":x,onClick:o,size:"sm",type:"button",variant:"outline",children:d}),e[6]=o,e[7]=x,e[8]=d,e[9]=u):u=e[9],u},Be=({initialShardKey:t,loadShardTraffic:e})=>{const r=ee(),n=te(),a=K(),[l,o]=I(t??""),[x,d]=I(null),[u,m]=I(null),h=oe(l.trim(),400),f=ne(""),g=H(T.getMetrics,{},{live:!0,shardKey:h}),v=H(T.getFunctionStats,{},{live:!0,shardKey:h}),b=H(T.getAdvisories,{},{live:!0,shardKey:h}),S=g.data??null,C=v.data?.functions??null,L=b.data?.advisories??null,z=g.data?.indexHits??null,_=g.error!==null&&v.error!==null?g.error:null,P=e??(i=>r.shardTraffic(i)),V=async(i,$)=>{const s=i[0];if(s===void 0||s===""){f.current===$&&m(null);return}try{const y=await P(s);if(f.current!==$)return;const p=new Map;for(const c of y.shards)p.has(c.shardKey)||p.set(c.shardKey,{requests:c.requests,shardKey:c.shardKey});m([...p.values()])}catch{f.current===$&&m(null)}},A=j(async i=>{f.current=i;let $=[];try{const s=await r.query($e,{},q(i));if(f.current!==i)return;le(i),$=s.map(c=>c.name);const y=await Promise.allSettled(s.map(async c=>[c.name,await r.query(we,{table:c.name},q(i))]));if(f.current!==i)return;const p=[];for(const c of y)if(c.status==="fulfilled"){const[k,Z]=c.value;p.push(...xe(k,Z.indexes))}d(p)}catch{f.current===i&&d(null)}await V($,i)},[r]);O(()=>{E(A(h))},[h,A]);const G=ae(()=>{g.refetch(),v.refetch(),b.refetch(),E(A(h))});O(()=>{const i=()=>{document.visibilityState==="visible"&&G()};return document.addEventListener("visibilitychange",i),()=>{document.removeEventListener("visibilitychange",i)}},[]);const R=j(i=>{E(n({search:{table:i},to:"/schema"}))},[n]),N=ue(S,C),Q=new Set(N.filter(i=>i.kind==="missing-index").flatMap(i=>i.tables??[])),F=ye({declaredIndexes:x??[],functions:C,indexHits:z,shardTraffic:u,suppressHotScanTables:Q}),W=re(()=>{const i=N.map(s=>{const y=s.kind==="missing-index"?s.tables??[]:[];return{action:y.length>0?y.map(p=>w(Ie,{onJump:R,table:p},p)):void 0,description:s.message===void 0?X(a,s):`${X(a,s)} — ${s.message}`,entity:s.fn,issueType:Te(a,s),key:`${s.kind}:${s.fn??""}`,level:s.severity}}),$=new Set(["unindexed_foreign_key","unindexed_relation_target"]);return[...(L??[]).map(s=>{const y=U(s);if($.has(s.name)&&he(s.metadata)){const{table:p,suggestedIndex:c}=s.metadata,k=`in-apply-index-${p}-${c.name}`;return{...y,action:w(ge,{fields:c.fields,indexName:c.name,table:p,testId:k})}}return y}),...F,...i]},[L,N,R,F,a]),Y=w(ie,{onChange:o,testId:"in-shard-input",value:l});return w(ce,{error:_,errorSource:_===null?void 0:g.errorSource,rows:W,testId:"lunora-insights",toolbar:Y})};export{Be as InsightsPanel};
@@ -1 +1 @@
1
- import{c as M}from"react/compiler-runtime";import{useVirtualizer as qe}from"@tanstack/react-virtual";import{useState as $,useReducer as Me,useRef as ie,useEffect as de,useMemo as Ae}from"react";import{f as Q}from"../packem_shared/log-fields-CoL3hsIQ.js";import{E as Oe}from"../packem_shared/error-alert-t6cpEi0z.js";import{L as Fe}from"../packem_shared/live-status-CmuRLFKf.js";import{ShardInput as De}from"../packem_shared/ShardInput-BVn2iCU0.js";import{g as Y}from"../packem_shared/badge-BbuuAio7.js";import{E as B}from"../packem_shared/empty-state-Cg7t_8qu.js";import{u as _}from"../packem_shared/input-JHu63lTv.js";import{N as re}from"../packem_shared/use-admin-query-QJ-ibl5u.js";import G from"../packem_shared/useDebounced-Ihdiid_k.js";import{useT as ce}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as te}from"../packem_shared/ADMIN_FUNCTIONS-BnD4aovm.js";import{b as ue}from"../packem_shared/cf-links-gbDy51nR.js";import{r as Ue}from"../packem_shared/shard-history-DMEW5VBE.js";import{c as q}from"../packem_shared/utils-bhneXptQ.js";import{l as Ke}from"../packem_shared/virtual-rect-1o1veP7R.js";import{useLunora as Ve}from"@lunora/react";import{u as ze}from"../packem_shared/button-BkCrNcAs.js";import{n as je,d as Be,m as me,p as P,f as Ge,u as T}from"../packem_shared/table-DdJBrClo.js";import{f as ae,l as We,b as le}from"../packem_shared/internal-BSIsQVC6.js";import{jsx as t,jsxs as w,Fragment as Qe}from"react/jsx-runtime";const he=["trace","debug","log","info","warn","error","fatal"],Ye="LOG_ARCHIVE_NOT_CONFIGURED",ge={debug:"secondary",error:"destructive",fatal:"destructive",info:"outline",log:"outline",trace:"outline",warn:"secondary"},He={cursor:void 0,error:null,loading:!1,notConfigured:!1,rows:null},Je=(l,e)=>{switch(e.type){case"append":return{...l,cursor:e.cursor,error:null,loading:!1,rows:[...l.rows??[],...e.rows]};case"failed":return{cursor:void 0,error:e.message,loading:!1,notConfigured:!1,rows:null};case"loaded":return{cursor:e.cursor,error:null,loading:!1,notConfigured:!1,rows:e.rows};case"loading":return{...l,error:null,loading:!0,notConfigured:!1};case"notConfigured":return{cursor:void 0,error:null,loading:!1,notConfigured:!0,rows:null};case"pageFailed":return{...l,error:e.message,loading:!1};default:return l}},Xe=l=>{const e=M(33),{row:r}=l;let s;e[0]!==r.fields?(s=Q(r.fields),e[0]=r.fields,e[1]=s):s=e[1];const n=s,a=`lg-archive-row-${String(r.ts)}`;let i;e[2]!==r.ts?(i=new Date(r.ts).toLocaleString(),e[2]=r.ts,e[3]=i):i=e[3];let u;e[4]!==i?(u=t(T,{className:"tabular-nums whitespace-nowrap text-xs text-muted-foreground",children:i}),e[4]=i,e[5]=u):u=e[5];const v=ge[r.level];let c;e[6]!==r.level||e[7]!==v?(c=t(T,{children:t(Y,{variant:v,children:r.level})}),e[6]=r.level,e[7]=v,e[8]=c):c=e[8];let d;e[9]!==r.functionPath?(d=t(T,{className:"font-mono text-xs",children:r.functionPath}),e[9]=r.functionPath,e[10]=d):d=e[10];let b;e[11]!==r.message?(b=t("div",{className:"truncate",title:r.message,children:r.message}),e[11]=r.message,e[12]=b):b=e[12];let f;e[13]!==n?(f=n!==""&&t("div",{className:"truncate font-mono text-[11px] text-muted-foreground",title:n,children:n}),e[13]=n,e[14]=f):f=e[14];let m;e[15]!==b||e[16]!==f?(m=w(T,{className:"max-w-md",children:[b,f]}),e[15]=b,e[16]=f,e[17]=m):m=e[17];const h=r.traceId??"—";let p;e[18]!==h?(p=t(T,{className:"font-mono text-[11px] text-muted-foreground",children:h}),e[18]=h,e[19]=p):p=e[19];const L=r.shardKey??"—";let g;e[20]!==L?(g=t(T,{className:"font-mono text-[11px] text-muted-foreground",children:L}),e[20]=L,e[21]=g):g=e[21];const x=r.userId??"—";let y;e[22]!==x?(y=t(T,{className:"font-mono text-[11px] text-muted-foreground",children:x}),e[22]=x,e[23]=y):y=e[23];let C;return e[24]!==m||e[25]!==p||e[26]!==g||e[27]!==y||e[28]!==a||e[29]!==u||e[30]!==c||e[31]!==d?(C=w(me,{"data-testid":a,children:[u,c,d,m,p,g,y]}),e[24]=m,e[25]=p,e[26]=g,e[27]=y,e[28]=a,e[29]=u,e[30]=c,e[31]=d,e[32]=C):C=e[32],C},Ze=({shardKey:l})=>{const e=Ve(),r=ce(),[s,n]=$(""),[a,i]=$(""),[u,v]=$(""),[{cursor:c,error:d,loading:b,notConfigured:f,rows:m},h]=Me(Je,He),p=G(s.trim(),400),L=G(a.trim(),400),g={...p===""?{}:{functionPathPrefix:p},...u===""?{}:{minLevel:u},...l===""?{}:{shardKey:l},...L===""?{}:{userId:L}},x=JSON.stringify(g),y=ie(x);de(()=>{const N={cancelled:!1};return y.current=x,ae((async()=>{h({type:"loading"});try{const k=await e.queryLogArchive(g);N.cancelled||h({cursor:k.nextCursor,rows:k.rows,type:"loaded"})}catch(k){N.cancelled||h(We(k)===Ye?{type:"notConfigured"}:{message:le(k),type:"failed"})}})()),()=>{N.cancelled=!0}},[e,x]);const C=async()=>{if(c===void 0)return;const N=x;h({type:"loading"});try{const k=await e.queryLogArchive({...g,cursor:c});y.current===N&&h({cursor:k.nextCursor,rows:k.rows,type:"append"})}catch(k){y.current===N&&h({message:le(k),type:"pageFailed"})}},R=N=>{n(N.target.value)},S=N=>{i(N.target.value)},I=N=>{v(N.target.value)},E=()=>{ae(C())};return f?t(B,{action:t("a",{className:"text-sm text-primary underline-offset-4 hover:underline",href:ue,rel:"noreferrer",target:"_blank",children:r("Open in Cloudflare")}),description:r("Wire pipelineLogSink to a Cloudflare Pipeline → R2 Data Catalog table and set R2_SQL_ACCOUNT_ID, R2_SQL_TOKEN, R2_SQL_BUCKET to browse the durable log archive here."),testId:"lg-archive-not-configured",title:r("Log archive not configured")}):w("div",{className:"flex flex-col gap-4","data-testid":"lg-archive",children:[w("div",{className:"flex flex-wrap items-center gap-2",children:[t(_,{"aria-label":r("Function path prefix"),className:"h-8 w-48","data-testid":"lg-archive-path",onChange:R,placeholder:r("function path…"),value:s}),t(_,{"aria-label":r("User id"),className:"h-8 w-40","data-testid":"lg-archive-user",onChange:S,placeholder:r("user id…"),value:a}),w("select",{"aria-label":r("Minimum level"),className:"h-8 rounded-md border border-border bg-background px-2 text-sm","data-testid":"lg-archive-min-level",onChange:I,value:u,children:[t("option",{value:"",children:r("min level")}),he.map(N=>t("option",{value:N,children:N},N))]})]}),d!==null&&t("p",{className:"text-sm text-destructive","data-testid":"lg-archive-error",role:"alert",children:d}),b&&m===null&&d===null&&t("p",{className:"text-sm text-muted-foreground","data-testid":"lg-archive-loading",children:r("Loading…")}),m!==null&&m.length===0&&t(B,{description:r("No archived logs match these filters. The durable archive fills as pipelineLogSink flushes records to R2."),testId:"lg-archive-empty",title:r("No archived logs.")}),m!==null&&m.length>0&&t("div",{className:"overflow-hidden rounded-xl border border-border shadow-xs",children:w(je,{"data-testid":"lg-archive-table",children:[t(Be,{children:w(me,{children:[t(P,{children:r("Time")}),t(P,{children:r("Level")}),t(P,{children:r("Function")}),t(P,{children:r("Message")}),t(P,{children:r("Trace")}),t(P,{children:r("Shard")}),t(P,{children:r("User")})]})}),t(Ge,{children:m.map((N,k)=>t(Xe,{row:N},`${String(N.ts)}-${String(k)}`))})]})}),c!==void 0&&t("div",{children:t(ze,{"data-testid":"lg-archive-more",disabled:b,onClick:E,size:"sm",variant:"outline",children:r(b?"Loading…":"Load more")})})]})},W=400,er=36,rr={height:W,overflow:"auto"},fe={left:0,position:"absolute",top:0,width:"100%"},tr={error:"destructive",ok:"secondary"},ar=l=>{const e=M(26),{entry:r,index:s,measureRef:n,start:a}=l,i=`translateY(${String(a)}px)`;let u;e[0]!==i?(u={...fe,transform:i},e[0]=i,e[1]=u):u=e[1];const v=u;let c;e[2]!==r.fields?(c=Q(r.fields),e[2]=r.fields,e[3]=c):c=e[3];const d=c;let b;e[4]!==r.timestamp?(b=new Date(r.timestamp).toLocaleString(),e[4]=r.timestamp,e[5]=b):b=e[5];let f;e[6]!==b?(f=t("span",{className:"w-44 shrink-0 tabular-nums text-muted-foreground",role:"gridcell",children:b}),e[6]=b,e[7]=f):f=e[7];const m=ge[r.level];let h;e[8]!==r.level||e[9]!==m?(h=t("span",{className:"w-20 shrink-0",role:"gridcell",children:t(Y,{variant:m,children:r.level})}),e[8]=r.level,e[9]=m,e[10]=h):h=e[10];const p=r.functionPath??"—";let L;e[11]!==p?(L=t("span",{className:"w-48 shrink-0 truncate text-muted-foreground",role:"gridcell",children:p}),e[11]=p,e[12]=L):L=e[12];let g;e[13]!==d?(g=d===""?null:t("span",{className:"ml-2 text-muted-foreground","data-testid":"lg-fields",children:d}),e[13]=d,e[14]=g):g=e[14];let x;e[15]!==r.message||e[16]!==g?(x=w("span",{className:"flex-1 truncate",role:"gridcell",children:[r.message,g]}),e[15]=r.message,e[16]=g,e[17]=x):x=e[17];let y;return e[18]!==s||e[19]!==n||e[20]!==v||e[21]!==x||e[22]!==f||e[23]!==h||e[24]!==L?(y=w("div",{className:"flex items-center border-b border-border px-3 py-1.5 font-mono text-xs hover:bg-muted/50","data-index":s,"data-testid":"lg-row",ref:n,role:"row",style:v,children:[f,h,L,x]}),e[18]=s,e[19]=n,e[20]=v,e[21]=x,e[22]=f,e[23]=h,e[24]=L,e[25]=y):y=e[25],y},oe=l=>l.length===0?"—":l.join(", "),lr=l=>{const e=M(37),{entry:r,index:s,measureRef:n,start:a}=l,i=`translateY(${String(a)}px)`;let u;e[0]!==i?(u={...fe,transform:i},e[0]=i,e[1]=u):u=e[1];const v=u;let c;e[2]!==r.ts?(c=new Date(r.ts).toLocaleString(),e[2]=r.ts,e[3]=c):c=e[3];let d;e[4]!==c?(d=t("span",{className:"w-40 shrink-0 tabular-nums text-muted-foreground",role:"gridcell",children:c}),e[4]=c,e[5]=d):d=e[5];const b=tr[r.outcome];let f;e[6]!==r.outcome||e[7]!==b?(f=t("span",{className:"w-16 shrink-0",role:"gridcell",children:t(Y,{variant:b,children:r.outcome})}),e[6]=r.outcome,e[7]=b,e[8]=f):f=e[8];let m;e[9]!==r.functionPath?(m=t("span",{className:"w-44 shrink-0 truncate",role:"gridcell",title:r.functionPath,children:r.functionPath}),e[9]=r.functionPath,e[10]=m):m=e[10];const h=r.shardKey??"—";let p;e[11]!==h?(p=t("span",{className:"w-24 shrink-0 truncate text-muted-foreground",role:"gridcell",children:h}),e[11]=h,e[12]=p):p=e[12];const L=r.userId??"—";let g;e[13]!==L?(g=t("span",{className:"w-24 shrink-0 truncate text-muted-foreground",role:"gridcell",children:L}),e[13]=L,e[14]=g):g=e[14];let x;e[15]!==r.durationMs?(x=Math.round(r.durationMs),e[15]=r.durationMs,e[16]=x):x=e[16];const y=`${String(x)}ms`;let C;e[17]!==y?(C=t("span",{className:"w-16 shrink-0 tabular-nums text-muted-foreground",role:"gridcell",children:y}),e[17]=y,e[18]=C):C=e[18];let R;e[19]!==r.errorMessage||e[20]!==r.outcome||e[21]!==r.tablesRead||e[22]!==r.tablesWritten?(R=r.outcome==="error"&&r.errorMessage!==void 0?r.errorMessage:`r:${oe(r.tablesRead)} · w:${oe(r.tablesWritten)}`,e[19]=r.errorMessage,e[20]=r.outcome,e[21]=r.tablesRead,e[22]=r.tablesWritten,e[23]=R):R=e[23];let S;e[24]!==R?(S=t("span",{className:"flex-1 truncate text-muted-foreground",role:"gridcell",children:R}),e[24]=R,e[25]=S):S=e[25];let I;return e[26]!==s||e[27]!==n||e[28]!==v||e[29]!==g||e[30]!==C||e[31]!==S||e[32]!==d||e[33]!==f||e[34]!==m||e[35]!==p?(I=w("div",{className:"flex items-center border-b border-border px-3 py-1.5 font-mono text-xs hover:bg-muted/50","data-index":s,"data-testid":"lg-req-row",ref:n,role:"row",style:v,children:[d,f,m,p,g,C,S]}),e[26]=s,e[27]=n,e[28]=v,e[29]=g,e[30]=C,e[31]=S,e[32]=d,e[33]=f,e[34]=m,e[35]=p,e[36]=I):I=e[36],I},se=l=>{const{entries:e}=l??{};return Array.isArray(e)?e:[]},or=l=>{const e={};return l.functionPathPrefix.trim()!==""&&(e.functionPathPrefix=l.functionPathPrefix.trim()),l.userId.trim()!==""&&(e.userId=l.userId.trim()),l.tableTouched.trim()!==""&&(e.tableTouched=l.tableTouched.trim()),(l.outcome==="ok"||l.outcome==="error")&&(e.outcome=l.outcome),e},pe=he,sr={"5m":300*1e3,"15m":900*1e3,"1h":3600*1e3},nr=(l,e)=>{const r=e.search.trim().toLowerCase(),s=e.path.trim().toLowerCase(),n=e.range==="all"?Number.NEGATIVE_INFINITY:e.now-sr[e.range];return l.filter(a=>e.levels.size>0&&!e.levels.has(a.level)||a.timestamp<n||s!==""&&!(a.functionPath??"").toLowerCase().includes(s)?!1:r===""||a.message.toLowerCase().includes(r)||Q(a.fields).toLowerCase().includes(r))},ir="—",dr=l=>{const e=new Map,r=new Map;for(const a of l){e.set(a.level,(e.get(a.level)??0)+1);const i=a.functionPath??ir;r.set(i,(r.get(i)??0)+1)}const s=pe.filter(a=>e.has(a)).map(a=>({count:e.get(a)??0,key:a})),n=[...r.entries()].map(([a,i])=>({count:i,key:a})).toSorted((a,i)=>i.count===a.count?a.key.localeCompare(i.key):i.count-a.count);return{byLevel:s,byPath:n,total:l.length}},cr=l=>{const e=M(11),{level:r,onToggle:s,selected:n}=l;let a;e[0]!==r||e[1]!==s?(a=()=>{s(r)},e[0]=r,e[1]=s,e[2]=a):a=e[2];const i=a,u=n?"border-border bg-muted font-medium":"border-input text-muted-foreground";let v;e[3]!==u?(v=q("rounded-md border px-2 py-1 text-xs",u),e[3]=u,e[4]=v):v=e[4];const c=`logs-level-${r}`;let d;return e[5]!==r||e[6]!==i||e[7]!==n||e[8]!==v||e[9]!==c?(d=t("button",{"aria-pressed":n,className:v,"data-testid":c,onClick:i,type:"button",children:r}),e[5]=r,e[6]=i,e[7]=n,e[8]=v,e[9]=c,e[10]=d):d=e[10],d},ne=l=>{const e=M(7),{bucket:r}=l;let s;e[0]!==r.key?(s=t("span",{className:"truncate text-muted-foreground",role:"gridcell",children:r.key}),e[0]=r.key,e[1]=s):s=e[1];let n;e[2]!==r.count?(n=t("span",{className:"shrink-0 tabular-nums",role:"gridcell",children:r.count}),e[2]=r.count,e[3]=n):n=e[3];let a;return e[4]!==s||e[5]!==n?(a=w("div",{className:"flex items-center justify-between gap-4 px-3 py-1 font-mono text-xs","data-testid":"logs-summary-row",role:"row",children:[s,n]}),e[4]=s,e[5]=n,e[6]=a):a=e[6],a},qr=({initialShardKey:l})=>{const e=ce(),[r,s]=$("requests"),[n,a]=$(l??""),[i,u]=$(""),[v,c]=$(()=>new Set),[d,b]=$(""),[f,m]=$("all"),[h,p]=$(!1),[L,g]=$(""),[x,y]=$(""),[C,R]=$(""),[S,I]=$("all"),E=G(n.trim(),400),N=or({functionPathPrefix:L,outcome:S,tableTouched:C,userId:x}),k=re(te.getRequestLog,N,{enabled:r==="requests",live:!0,shardKey:E}),H=re(te.getLogs,{},{enabled:r==="errors",live:!0,shardKey:E}),D=r==="requests"?k:H,{error:J,errorSource:ve,isLoading:X,liveError:be}=D,xe=se(H.data),Z=se(k.data);de(()=>{D.data!==void 0&&Ue(E)},[D.data,E]);const U=nr(xe,{levels:v,now:Date.now(),path:d,range:f,search:i}),K=dr(U),V=r==="requests"?Z.length:U.length,z=r==="errors"&&h,A=Ae(()=>J!==null?"error":V===0?X?z?"summary":"list":"empty":z?"summary":"list",[V,X,J,z]),ee=ie(null),O=qe({count:V,estimateSize:()=>er,getScrollElement:()=>ee.current,initialRect:{height:W,width:800},observeElementRect:(o,j)=>Ke(o,j,W),overscan:8}),we=O.getVirtualItems(),ye={height:O.getTotalSize(),position:"relative",width:"100%"},Ne=o=>{u(o.target.value)},Le=o=>{c(j=>{const F=new Set(j);return F.has(o)?F.delete(o):F.add(o),F})},Ce=o=>{b(o.target.value)},ke=o=>{m(o.target.value)},$e=()=>{p(o=>!o)},Se=o=>{g(o.target.value)},Re=o=>{y(o.target.value)},Ie=o=>{R(o.target.value)},Ee=o=>{I(o.target.value)},Pe=()=>{s("requests"),p(!1)},Te=()=>{s("errors"),p(!1)},_e=()=>{s("archive"),p(!1)};return w("div",{className:"flex flex-col gap-4","data-testid":"lunora-logs",children:[w("div",{className:"flex flex-wrap items-center gap-2",children:[w("div",{className:"inline-flex overflow-hidden rounded-lg border border-border",role:"tablist",children:[t("button",{"aria-selected":r==="requests",className:q("px-3 py-1 text-sm",r==="requests"?"bg-muted font-medium":"text-muted-foreground"),"data-testid":"lg-view-requests",onClick:Pe,role:"tab",type:"button",children:e("Requests")}),t("button",{"aria-selected":r==="errors",className:q("px-3 py-1 text-sm",r==="errors"?"bg-muted font-medium":"text-muted-foreground"),"data-testid":"lg-view-errors",onClick:Te,role:"tab",type:"button",children:e("Errors")}),t("button",{"aria-selected":r==="archive",className:q("px-3 py-1 text-sm",r==="archive"?"bg-muted font-medium":"text-muted-foreground"),"data-testid":"lg-view-archive",onClick:_e,role:"tab",type:"button",children:e("Archive")})]}),t(De,{onChange:a,testId:"lg-shard-input",value:n}),r!=="archive"&&t(Fe,{message:be,prefix:"lg"}),t("a",{className:"text-sm text-primary underline-offset-4 hover:underline","data-testid":"lg-cf-link",href:ue,rel:"noreferrer",target:"_blank",children:e("Open in Cloudflare")})]}),r==="errors"&&w("div",{className:"flex flex-wrap items-center gap-2",children:[t(_,{"aria-label":e("Search messages"),className:"h-8 w-48","data-testid":"lg-search",onChange:Ne,placeholder:e("search message"),value:i}),t(_,{"aria-label":e("Function path"),className:"h-8 w-40","data-testid":"logs-path-filter",onChange:Ce,placeholder:e("filter path"),value:d}),t("div",{"aria-label":e("Level filter"),className:"inline-flex items-center gap-1","data-testid":"logs-level-filter",role:"group",children:pe.map(o=>t(cr,{level:o,onToggle:Le,selected:v.has(o)},o))}),w("select",{"aria-label":e("Time range"),className:"h-8 rounded-md border border-input bg-transparent px-2 text-sm shadow-xs focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-none","data-testid":"logs-time-range",onChange:ke,value:f,children:[t("option",{value:"all",children:e("All time")}),t("option",{value:"5m",children:e("Last 5m")}),t("option",{value:"15m",children:e("Last 15m")}),t("option",{value:"1h",children:e("Last hour")})]}),t("button",{"aria-pressed":h,className:q("h-8 rounded-md border px-3 text-sm",h?"border-border bg-muted font-medium":"border-input text-muted-foreground"),"data-testid":"logs-summary-toggle",onClick:$e,type:"button",children:e(h?"List":"Summary")})]}),r==="requests"&&w("div",{className:"flex flex-wrap items-center gap-2",children:[t(_,{"aria-label":e("Function path"),className:"h-8 w-44","data-testid":"lg-req-path",onChange:Se,placeholder:e("file:function"),value:L}),t(_,{"aria-label":e("User id"),className:"h-8 w-32","data-testid":"lg-req-user",onChange:Re,placeholder:e("userId"),value:x}),t(_,{"aria-label":e("Table touched"),className:"h-8 w-32","data-testid":"lg-req-table",onChange:Ie,placeholder:e("table"),value:C}),w("select",{"aria-label":e("Outcome filter"),className:"h-8 rounded-md border border-input bg-transparent px-2 text-sm shadow-xs focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-none","data-testid":"lg-req-outcome",onChange:Ee,value:S,children:[t("option",{value:"all",children:e("all")}),t("option",{value:"ok",children:e("ok")}),t("option",{value:"error",children:e("error")})]})]}),r==="archive"?t(Ze,{shardKey:E}):w(Qe,{children:[A==="error"&&t(Oe,{error:ve,testId:"lg-error"}),A==="empty"&&t(B,{description:e("Function and request logs for this shard show up here as your app handles traffic."),icon:t("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:t("path",{d:"M4 5h16M4 12h16M4 19h10"})}),testId:"lg-empty",title:e("No logs.")}),A==="summary"&&w("div",{className:"flex flex-col gap-4 rounded-xl border border-border bg-card p-4 shadow-xs","data-testid":"logs-summary",children:[t("p",{className:"text-xs text-muted-foreground","data-testid":"logs-summary-total",children:e("{count} entries",{count:K.total})}),w("div",{children:[t("h4",{className:"mb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:e("By level")}),t("div",{className:"overflow-hidden rounded-lg border border-border","data-testid":"logs-summary-levels",role:"grid",children:K.byLevel.map(o=>t(ne,{bucket:o},o.key))})]}),w("div",{children:[t("h4",{className:"mb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:e("By function")}),t("div",{className:"overflow-hidden rounded-lg border border-border","data-testid":"logs-summary-paths",role:"grid",children:K.byPath.map(o=>t(ne,{bucket:o},o.key))})]})]}),A==="list"&&t("div",{className:"rounded-xl border border-border shadow-xs","data-testid":"lg-scroll",ref:ee,style:rr,children:t("div",{"aria-label":e("Recent logs"),"data-testid":"lg-table",role:"grid",style:ye,children:we.map(o=>r==="requests"?t(lr,{entry:Z[o.index],index:o.index,measureRef:O.measureElement,start:o.start},o.key):t(ar,{entry:U[o.index],index:o.index,measureRef:O.measureElement,start:o.start},o.key))})})]})]})};export{qr as LogsPanel,nr as filterLogs,dr as summarizeLogs};
1
+ import{c as M}from"react/compiler-runtime";import{useVirtualizer as we}from"@tanstack/react-virtual";import{useState as F,useReducer as Ne,useRef as me,useEffect as he,useMemo as Ce}from"react";import{f as re}from"../packem_shared/log-fields-CoL3hsIQ.js";import{E as Le}from"../packem_shared/error-alert-t6cpEi0z.js";import{g as le}from"../packem_shared/badge-BbuuAio7.js";import{E as Z}from"../packem_shared/empty-state-Cg7t_8qu.js";import{N as ne}from"../packem_shared/use-admin-query-QJ-ibl5u.js";import ee from"../packem_shared/useDebounced-Ihdiid_k.js";import{useT as z}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as se}from"../packem_shared/ADMIN_FUNCTIONS-CZESgd10.js";import{r as Se}from"../packem_shared/shard-history-DMEW5VBE.js";import{l as ke}from"../packem_shared/virtual-rect-1o1veP7R.js";import{useLunora as $e}from"@lunora/react";import{u as Re}from"../packem_shared/button-BkCrNcAs.js";import{u as j}from"../packem_shared/input-JHu63lTv.js";import{n as Ie,d as Pe,m as ge,p as D,f as Te,u as V}from"../packem_shared/table-DdJBrClo.js";import{a as fe}from"../packem_shared/cf-links-Dmg86v1D.js";import{f as ie,l as Ee,b as de}from"../packem_shared/internal-BSIsQVC6.js";import{jsx as r,jsxs as T,Fragment as Fe}from"react/jsx-runtime";import{c as G}from"../packem_shared/utils-bhneXptQ.js";import{L as qe}from"../packem_shared/live-status-CmuRLFKf.js";import{ShardInput as _e}from"../packem_shared/ShardInput-BVn2iCU0.js";const ae=["trace","debug","log","info","warn","error","fatal"],Ae="LOG_ARCHIVE_NOT_CONFIGURED",pe={debug:"secondary",error:"destructive",fatal:"destructive",info:"outline",log:"outline",trace:"outline",warn:"secondary"},Oe={cursor:void 0,error:null,loading:!1,notConfigured:!1,rows:null},Me=(i,e)=>{switch(e.type){case"append":return{...i,cursor:e.cursor,error:null,loading:!1,rows:[...i.rows??[],...e.rows]};case"failed":return{cursor:void 0,error:e.message,loading:!1,notConfigured:!1,rows:null};case"loaded":return{cursor:e.cursor,error:null,loading:!1,notConfigured:!1,rows:e.rows};case"loading":return{...i,error:null,loading:!0,notConfigured:!1};case"notConfigured":return{cursor:void 0,error:null,loading:!1,notConfigured:!0,rows:null};case"pageFailed":return{...i,error:e.message,loading:!1};default:return i}},Ke=i=>{const e=M(33),{row:t}=i;let n;e[0]!==t.fields?(n=re(t.fields),e[0]=t.fields,e[1]=n):n=e[1];const c=n,o=`lg-archive-row-${String(t.ts)}`;let m;e[2]!==t.ts?(m=new Date(t.ts).toLocaleString(),e[2]=t.ts,e[3]=m):m=e[3];let p;e[4]!==m?(p=r(V,{className:"tabular-nums whitespace-nowrap text-xs text-muted-foreground",children:m}),e[4]=m,e[5]=p):p=e[5];const g=pe[t.level];let s;e[6]!==t.level||e[7]!==g?(s=r(V,{children:r(le,{variant:g,children:t.level})}),e[6]=t.level,e[7]=g,e[8]=s):s=e[8];let l;e[9]!==t.functionPath?(l=r(V,{className:"font-mono text-xs",children:t.functionPath}),e[9]=t.functionPath,e[10]=l):l=e[10];let v;e[11]!==t.message?(v=r("div",{className:"truncate",title:t.message,children:t.message}),e[11]=t.message,e[12]=v):v=e[12];let a;e[13]!==c?(a=c!==""&&r("div",{className:"truncate font-mono text-[11px] text-muted-foreground",title:c,children:c}),e[13]=c,e[14]=a):a=e[14];let d;e[15]!==v||e[16]!==a?(d=T(V,{className:"max-w-md",children:[v,a]}),e[15]=v,e[16]=a,e[17]=d):d=e[17];const u=t.traceId??"—";let h;e[18]!==u?(h=r(V,{className:"font-mono text-[11px] text-muted-foreground",children:u}),e[18]=u,e[19]=h):h=e[19];const x=t.shardKey??"—";let f;e[20]!==x?(f=r(V,{className:"font-mono text-[11px] text-muted-foreground",children:x}),e[20]=x,e[21]=f):f=e[21];const b=t.userId??"—";let y;e[22]!==b?(y=r(V,{className:"font-mono text-[11px] text-muted-foreground",children:b}),e[22]=b,e[23]=y):y=e[23];let C;return e[24]!==d||e[25]!==h||e[26]!==f||e[27]!==y||e[28]!==o||e[29]!==p||e[30]!==s||e[31]!==l?(C=T(ge,{"data-testid":o,children:[p,s,l,d,h,f,y]}),e[24]=d,e[25]=h,e[26]=f,e[27]=y,e[28]=o,e[29]=p,e[30]=s,e[31]=l,e[32]=C):C=e[32],C},Ue=({shardKey:i})=>{const e=$e(),t=z(),[n,c]=F(""),[o,m]=F(""),[p,g]=F(""),[{cursor:s,error:l,loading:v,notConfigured:a,rows:d},u]=Ne(Me,Oe),h=ee(n.trim(),400),x=ee(o.trim(),400),f={...h===""?{}:{functionPathPrefix:h},...p===""?{}:{minLevel:p},...i===""?{}:{shardKey:i},...x===""?{}:{userId:x}},b=JSON.stringify(f),y=me(b);he(()=>{const w={cancelled:!1};return y.current=b,ie((async()=>{u({type:"loading"});try{const N=await e.queryLogArchive(f);w.cancelled||u({cursor:N.nextCursor,rows:N.rows,type:"loaded"})}catch(N){w.cancelled||u(Ee(N)===Ae?{type:"notConfigured"}:{message:de(N),type:"failed"})}})()),()=>{w.cancelled=!0}},[e,b]);const C=async()=>{if(s===void 0)return;const w=b;u({type:"loading"});try{const N=await e.queryLogArchive({...f,cursor:s});y.current===w&&u({cursor:N.nextCursor,rows:N.rows,type:"append"})}catch(N){y.current===w&&u({message:de(N),type:"pageFailed"})}},$=w=>{c(w.target.value)},L=w=>{m(w.target.value)},k=w=>{g(w.target.value)},R=()=>{ie(C())};return a?r(Z,{action:r("a",{className:"text-sm text-primary underline-offset-4 hover:underline",href:fe,rel:"noreferrer",target:"_blank",children:t("Open in Cloudflare")}),description:t("Wire pipelineLogSink to a Cloudflare Pipeline → R2 Data Catalog table and set R2_SQL_ACCOUNT_ID, R2_SQL_TOKEN, R2_SQL_BUCKET to browse the durable log archive here."),testId:"lg-archive-not-configured",title:t("Log archive not configured")}):T("div",{className:"flex flex-col gap-4","data-testid":"lg-archive",children:[T("div",{className:"flex flex-wrap items-center gap-2",children:[r(j,{"aria-label":t("Function path prefix"),className:"h-8 w-48","data-testid":"lg-archive-path",onChange:$,placeholder:t("function path…"),value:n}),r(j,{"aria-label":t("User id"),className:"h-8 w-40","data-testid":"lg-archive-user",onChange:L,placeholder:t("user id…"),value:o}),T("select",{"aria-label":t("Minimum level"),className:"h-8 rounded-md border border-border bg-background px-2 text-sm","data-testid":"lg-archive-min-level",onChange:k,value:p,children:[r("option",{value:"",children:t("min level")}),ae.map(w=>r("option",{value:w,children:w},w))]})]}),l!==null&&r("p",{className:"text-sm text-destructive","data-testid":"lg-archive-error",role:"alert",children:l}),v&&d===null&&l===null&&r("p",{className:"text-sm text-muted-foreground","data-testid":"lg-archive-loading",children:t("Loading…")}),d!==null&&d.length===0&&r(Z,{description:t("No archived logs match these filters. The durable archive fills as pipelineLogSink flushes records to R2."),testId:"lg-archive-empty",title:t("No archived logs.")}),d!==null&&d.length>0&&r("div",{className:"overflow-hidden rounded-xl border border-border shadow-xs",children:T(Ie,{"data-testid":"lg-archive-table",children:[r(Pe,{children:T(ge,{children:[r(D,{children:t("Time")}),r(D,{children:t("Level")}),r(D,{children:t("Function")}),r(D,{children:t("Message")}),r(D,{children:t("Trace")}),r(D,{children:t("Shard")}),r(D,{children:t("User")})]})}),r(Te,{children:d.map((w,N)=>r(Ke,{row:w},`${String(w.ts)}-${String(N)}`))})]})}),s!==void 0&&r("div",{children:r(Re,{"data-testid":"lg-archive-more",disabled:v,onClick:R,size:"sm",variant:"outline",children:t(v?"Loading…":"Load more")})})]})},De=i=>{const e=M(11),{level:t,onToggle:n,selected:c}=i;let o;e[0]!==t||e[1]!==n?(o=()=>{n(t)},e[0]=t,e[1]=n,e[2]=o):o=e[2];const m=o,p=c?"border-border bg-muted font-medium":"border-input text-muted-foreground";let g;e[3]!==p?(g=G("rounded-md border px-2 py-1 text-xs",p),e[3]=p,e[4]=g):g=e[4];const s=`logs-level-${t}`;let l;return e[5]!==t||e[6]!==m||e[7]!==c||e[8]!==g||e[9]!==s?(l=r("button",{"aria-pressed":c,className:g,"data-testid":s,onClick:m,type:"button",children:t}),e[5]=t,e[6]=m,e[7]=c,e[8]=g,e[9]=s,e[10]=l):l=e[10],l},Ve=i=>{const e=M(68),{levelFilter:t,onLogPathChange:n,onSearchChange:c,onTimeRangeChange:o,onToggleLevel:m,onToggleSummary:p,pathFilter:g,search:s,showSummary:l,timeRange:v}=i,a=z();let d;e[0]!==a?(d=a("Search messages"),e[0]=a,e[1]=d):d=e[1];let u;e[2]!==a?(u=a("search message"),e[2]=a,e[3]=u):u=e[3];let h;e[4]!==c||e[5]!==s||e[6]!==d||e[7]!==u?(h=r(j,{"aria-label":d,className:"h-8 w-48","data-testid":"lg-search",onChange:c,placeholder:u,value:s}),e[4]=c,e[5]=s,e[6]=d,e[7]=u,e[8]=h):h=e[8];let x;e[9]!==a?(x=a("Function path"),e[9]=a,e[10]=x):x=e[10];let f;e[11]!==a?(f=a("filter path"),e[11]=a,e[12]=f):f=e[12];let b;e[13]!==n||e[14]!==g||e[15]!==x||e[16]!==f?(b=r(j,{"aria-label":x,className:"h-8 w-40","data-testid":"logs-path-filter",onChange:n,placeholder:f,value:g}),e[13]=n,e[14]=g,e[15]=x,e[16]=f,e[17]=b):b=e[17];let y;e[18]!==a?(y=a("Level filter"),e[18]=a,e[19]=y):y=e[19];let C;e[20]!==t||e[21]!==m?(C=ae.map(U=>r(De,{level:U,onToggle:m,selected:t.has(U)},U)),e[20]=t,e[21]=m,e[22]=C):C=e[22];let $;e[23]!==y||e[24]!==C?($=r("div",{"aria-label":y,className:"inline-flex items-center gap-1","data-testid":"logs-level-filter",role:"group",children:C}),e[23]=y,e[24]=C,e[25]=$):$=e[25];let L;e[26]!==a?(L=a("Time range"),e[26]=a,e[27]=L):L=e[27];let k;e[28]!==a?(k=a("All time"),e[28]=a,e[29]=k):k=e[29];let R;e[30]!==k?(R=r("option",{value:"all",children:k}),e[30]=k,e[31]=R):R=e[31];let w;e[32]!==a?(w=a("Last 5m"),e[32]=a,e[33]=w):w=e[33];let N;e[34]!==w?(N=r("option",{value:"5m",children:w}),e[34]=w,e[35]=N):N=e[35];let I;e[36]!==a?(I=a("Last 15m"),e[36]=a,e[37]=I):I=e[37];let P;e[38]!==I?(P=r("option",{value:"15m",children:I}),e[38]=I,e[39]=P):P=e[39];let E;e[40]!==a?(E=a("Last hour"),e[40]=a,e[41]=E):E=e[41];let q;e[42]!==E?(q=r("option",{value:"1h",children:E}),e[42]=E,e[43]=q):q=e[43];let A;e[44]!==o||e[45]!==L||e[46]!==R||e[47]!==N||e[48]!==P||e[49]!==q||e[50]!==v?(A=T("select",{"aria-label":L,className:"h-8 rounded-md border border-input bg-transparent px-2 text-sm shadow-xs focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-none","data-testid":"logs-time-range",onChange:o,value:v,children:[R,N,P,q]}),e[44]=o,e[45]=L,e[46]=R,e[47]=N,e[48]=P,e[49]=q,e[50]=v,e[51]=A):A=e[51];const W=l?"border-border bg-muted font-medium":"border-input text-muted-foreground";let K;e[52]!==W?(K=G("h-8 rounded-md border px-3 text-sm",W),e[52]=W,e[53]=K):K=e[53];let O;e[54]!==l||e[55]!==a?(O=a(l?"List":"Summary"),e[54]=l,e[55]=a,e[56]=O):O=e[56];let _;e[57]!==p||e[58]!==l||e[59]!==K||e[60]!==O?(_=r("button",{"aria-pressed":l,className:K,"data-testid":"logs-summary-toggle",onClick:p,type:"button",children:O}),e[57]=p,e[58]=l,e[59]=K,e[60]=O,e[61]=_):_=e[61];let B;return e[62]!==A||e[63]!==_||e[64]!==h||e[65]!==b||e[66]!==$?(B=T("div",{className:"flex flex-wrap items-center gap-2",children:[h,b,$,A,_]}),e[62]=A,e[63]=_,e[64]=h,e[65]=b,e[66]=$,e[67]=B):B=e[67],B},je=i=>{const e=M(53),{onOutcomeChange:t,onPathChange:n,onTableChange:c,onUserChange:o,outcomeFilter:m,pathPrefix:p,tableFilter:g,userIdFilter:s}=i,l=z();let v;e[0]!==l?(v=l("Function path"),e[0]=l,e[1]=v):v=e[1];let a;e[2]!==l?(a=l("file:function"),e[2]=l,e[3]=a):a=e[3];let d;e[4]!==n||e[5]!==p||e[6]!==v||e[7]!==a?(d=r(j,{"aria-label":v,className:"h-8 w-44","data-testid":"lg-req-path",onChange:n,placeholder:a,value:p}),e[4]=n,e[5]=p,e[6]=v,e[7]=a,e[8]=d):d=e[8];let u;e[9]!==l?(u=l("User id"),e[9]=l,e[10]=u):u=e[10];let h;e[11]!==l?(h=l("userId"),e[11]=l,e[12]=h):h=e[12];let x;e[13]!==o||e[14]!==u||e[15]!==h||e[16]!==s?(x=r(j,{"aria-label":u,className:"h-8 w-32","data-testid":"lg-req-user",onChange:o,placeholder:h,value:s}),e[13]=o,e[14]=u,e[15]=h,e[16]=s,e[17]=x):x=e[17];let f;e[18]!==l?(f=l("Table touched"),e[18]=l,e[19]=f):f=e[19];let b;e[20]!==l?(b=l("table"),e[20]=l,e[21]=b):b=e[21];let y;e[22]!==c||e[23]!==f||e[24]!==b||e[25]!==g?(y=r(j,{"aria-label":f,className:"h-8 w-32","data-testid":"lg-req-table",onChange:c,placeholder:b,value:g}),e[22]=c,e[23]=f,e[24]=b,e[25]=g,e[26]=y):y=e[26];let C;e[27]!==l?(C=l("Outcome filter"),e[27]=l,e[28]=C):C=e[28];let $;e[29]!==l?($=l("all"),e[29]=l,e[30]=$):$=e[30];let L;e[31]!==$?(L=r("option",{value:"all",children:$}),e[31]=$,e[32]=L):L=e[32];let k;e[33]!==l?(k=l("ok"),e[33]=l,e[34]=k):k=e[34];let R;e[35]!==k?(R=r("option",{value:"ok",children:k}),e[35]=k,e[36]=R):R=e[36];let w;e[37]!==l?(w=l("error"),e[37]=l,e[38]=w):w=e[38];let N;e[39]!==w?(N=r("option",{value:"error",children:w}),e[39]=w,e[40]=N):N=e[40];let I;e[41]!==t||e[42]!==m||e[43]!==C||e[44]!==L||e[45]!==R||e[46]!==N?(I=T("select",{"aria-label":C,className:"h-8 rounded-md border border-input bg-transparent px-2 text-sm shadow-xs focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-none","data-testid":"lg-req-outcome",onChange:t,value:m,children:[L,R,N]}),e[41]=t,e[42]=m,e[43]=C,e[44]=L,e[45]=R,e[46]=N,e[47]=I):I=e[47];let P;return e[48]!==I||e[49]!==d||e[50]!==x||e[51]!==y?(P=T("div",{className:"flex flex-wrap items-center gap-2",children:[d,x,y,I]}),e[48]=I,e[49]=d,e[50]=x,e[51]=y,e[52]=P):P=e[52],P},ve=i=>{const e=M(7),{bucket:t}=i;let n;e[0]!==t.key?(n=r("span",{className:"truncate text-muted-foreground",role:"gridcell",children:t.key}),e[0]=t.key,e[1]=n):n=e[1];let c;e[2]!==t.count?(c=r("span",{className:"shrink-0 tabular-nums",role:"gridcell",children:t.count}),e[2]=t.count,e[3]=c):c=e[3];let o;return e[4]!==n||e[5]!==c?(o=T("div",{className:"flex items-center justify-between gap-4 px-3 py-1 font-mono text-xs","data-testid":"logs-summary-row",role:"row",children:[n,c]}),e[4]=n,e[5]=c,e[6]=o):o=e[6],o},Be=i=>{const e=M(31),{summary:t}=i,n=z();let c;e[0]!==t.total||e[1]!==n?(c=n("{count} entries",{count:t.total}),e[0]=t.total,e[1]=n,e[2]=c):c=e[2];let o;e[3]!==c?(o=r("p",{className:"text-xs text-muted-foreground","data-testid":"logs-summary-total",children:c}),e[3]=c,e[4]=o):o=e[4];let m;e[5]!==n?(m=n("By level"),e[5]=n,e[6]=m):m=e[6];let p;e[7]!==m?(p=r("h4",{className:"mb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:m}),e[7]=m,e[8]=p):p=e[8];let g;e[9]!==t.byLevel?(g=t.byLevel.map(ze),e[9]=t.byLevel,e[10]=g):g=e[10];let s;e[11]!==g?(s=r("div",{className:"overflow-hidden rounded-lg border border-border","data-testid":"logs-summary-levels",role:"grid",children:g}),e[11]=g,e[12]=s):s=e[12];let l;e[13]!==p||e[14]!==s?(l=T("div",{children:[p,s]}),e[13]=p,e[14]=s,e[15]=l):l=e[15];let v;e[16]!==n?(v=n("By function"),e[16]=n,e[17]=v):v=e[17];let a;e[18]!==v?(a=r("h4",{className:"mb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:v}),e[18]=v,e[19]=a):a=e[19];let d;e[20]!==t.byPath?(d=t.byPath.map(We),e[20]=t.byPath,e[21]=d):d=e[21];let u;e[22]!==d?(u=r("div",{className:"overflow-hidden rounded-lg border border-border","data-testid":"logs-summary-paths",role:"grid",children:d}),e[22]=d,e[23]=u):u=e[23];let h;e[24]!==u||e[25]!==a?(h=T("div",{children:[a,u]}),e[24]=u,e[25]=a,e[26]=h):h=e[26];let x;return e[27]!==h||e[28]!==o||e[29]!==l?(x=T("div",{className:"flex flex-col gap-4 rounded-xl border border-border bg-card p-4 shadow-xs","data-testid":"logs-summary",children:[o,l,h]}),e[27]=h,e[28]=o,e[29]=l,e[30]=x):x=e[30],x};function ze(i){return r(ve,{bucket:i},i.key)}function We(i){return r(ve,{bucket:i},i.key)}const Ge=i=>{const e=M(46),{liveError:t,onShardKeyChange:n,onShowArchive:c,onShowErrors:o,onShowRequests:m,shardKey:p,view:g}=i,s=z(),l=g==="requests",v=g==="requests"?"bg-muted font-medium":"text-muted-foreground";let a;e[0]!==v?(a=G("px-3 py-1 text-sm",v),e[0]=v,e[1]=a):a=e[1];let d;e[2]!==s?(d=s("Requests"),e[2]=s,e[3]=d):d=e[3];let u;e[4]!==m||e[5]!==l||e[6]!==a||e[7]!==d?(u=r("button",{"aria-selected":l,className:a,"data-testid":"lg-view-requests",onClick:m,role:"tab",type:"button",children:d}),e[4]=m,e[5]=l,e[6]=a,e[7]=d,e[8]=u):u=e[8];const h=g==="errors",x=g==="errors"?"bg-muted font-medium":"text-muted-foreground";let f;e[9]!==x?(f=G("px-3 py-1 text-sm",x),e[9]=x,e[10]=f):f=e[10];let b;e[11]!==s?(b=s("Errors"),e[11]=s,e[12]=b):b=e[12];let y;e[13]!==o||e[14]!==h||e[15]!==f||e[16]!==b?(y=r("button",{"aria-selected":h,className:f,"data-testid":"lg-view-errors",onClick:o,role:"tab",type:"button",children:b}),e[13]=o,e[14]=h,e[15]=f,e[16]=b,e[17]=y):y=e[17];const C=g==="archive",$=g==="archive"?"bg-muted font-medium":"text-muted-foreground";let L;e[18]!==$?(L=G("px-3 py-1 text-sm",$),e[18]=$,e[19]=L):L=e[19];let k;e[20]!==s?(k=s("Archive"),e[20]=s,e[21]=k):k=e[21];let R;e[22]!==c||e[23]!==C||e[24]!==L||e[25]!==k?(R=r("button",{"aria-selected":C,className:L,"data-testid":"lg-view-archive",onClick:c,role:"tab",type:"button",children:k}),e[22]=c,e[23]=C,e[24]=L,e[25]=k,e[26]=R):R=e[26];let w;e[27]!==y||e[28]!==R||e[29]!==u?(w=T("div",{className:"inline-flex overflow-hidden rounded-lg border border-border",role:"tablist",children:[u,y,R]}),e[27]=y,e[28]=R,e[29]=u,e[30]=w):w=e[30];let N;e[31]!==n||e[32]!==p?(N=r(_e,{onChange:n,testId:"lg-shard-input",value:p}),e[31]=n,e[32]=p,e[33]=N):N=e[33];let I;e[34]!==t||e[35]!==g?(I=g!=="archive"&&r(qe,{message:t,prefix:"lg"}),e[34]=t,e[35]=g,e[36]=I):I=e[36];let P;e[37]!==s?(P=s("Open in Cloudflare"),e[37]=s,e[38]=P):P=e[38];let E;e[39]!==P?(E=r("a",{className:"text-sm text-primary underline-offset-4 hover:underline","data-testid":"lg-cf-link",href:fe,rel:"noreferrer",target:"_blank",children:P}),e[39]=P,e[40]=E):E=e[40];let q;return e[41]!==w||e[42]!==N||e[43]!==I||e[44]!==E?(q=T("div",{className:"flex flex-wrap items-center gap-2",children:[w,N,I,E]}),e[41]=w,e[42]=N,e[43]=I,e[44]=E,e[45]=q):q=e[45],q},te=400,Qe=36,Ye={height:te,overflow:"auto"},be={left:0,position:"absolute",top:0,width:"100%"},He={error:"destructive",ok:"secondary"},Je=i=>{const e=M(26),{entry:t,index:n,measureRef:c,start:o}=i,m=`translateY(${String(o)}px)`;let p;e[0]!==m?(p={...be,transform:m},e[0]=m,e[1]=p):p=e[1];const g=p;let s;e[2]!==t.fields?(s=re(t.fields),e[2]=t.fields,e[3]=s):s=e[3];const l=s;let v;e[4]!==t.timestamp?(v=new Date(t.timestamp).toLocaleString(),e[4]=t.timestamp,e[5]=v):v=e[5];let a;e[6]!==v?(a=r("span",{className:"w-44 shrink-0 tabular-nums text-muted-foreground",role:"gridcell",children:v}),e[6]=v,e[7]=a):a=e[7];const d=pe[t.level];let u;e[8]!==t.level||e[9]!==d?(u=r("span",{className:"w-20 shrink-0",role:"gridcell",children:r(le,{variant:d,children:t.level})}),e[8]=t.level,e[9]=d,e[10]=u):u=e[10];const h=t.functionPath??"—";let x;e[11]!==h?(x=r("span",{className:"w-48 shrink-0 truncate text-muted-foreground",role:"gridcell",children:h}),e[11]=h,e[12]=x):x=e[12];let f;e[13]!==l?(f=l===""?null:r("span",{className:"ml-2 text-muted-foreground","data-testid":"lg-fields",children:l}),e[13]=l,e[14]=f):f=e[14];let b;e[15]!==t.message||e[16]!==f?(b=T("span",{className:"flex-1 truncate",role:"gridcell",children:[t.message,f]}),e[15]=t.message,e[16]=f,e[17]=b):b=e[17];let y;return e[18]!==n||e[19]!==c||e[20]!==g||e[21]!==b||e[22]!==a||e[23]!==u||e[24]!==x?(y=T("div",{className:"flex items-center border-b border-border px-3 py-1.5 font-mono text-xs hover:bg-muted/50","data-index":n,"data-testid":"lg-row",ref:c,role:"row",style:g,children:[a,u,x,b]}),e[18]=n,e[19]=c,e[20]=g,e[21]=b,e[22]=a,e[23]=u,e[24]=x,e[25]=y):y=e[25],y},ce=i=>i.length===0?"—":i.join(", "),Xe=i=>{const e=M(37),{entry:t,index:n,measureRef:c,start:o}=i,m=`translateY(${String(o)}px)`;let p;e[0]!==m?(p={...be,transform:m},e[0]=m,e[1]=p):p=e[1];const g=p;let s;e[2]!==t.ts?(s=new Date(t.ts).toLocaleString(),e[2]=t.ts,e[3]=s):s=e[3];let l;e[4]!==s?(l=r("span",{className:"w-40 shrink-0 tabular-nums text-muted-foreground",role:"gridcell",children:s}),e[4]=s,e[5]=l):l=e[5];const v=He[t.outcome];let a;e[6]!==t.outcome||e[7]!==v?(a=r("span",{className:"w-16 shrink-0",role:"gridcell",children:r(le,{variant:v,children:t.outcome})}),e[6]=t.outcome,e[7]=v,e[8]=a):a=e[8];let d;e[9]!==t.functionPath?(d=r("span",{className:"w-44 shrink-0 truncate",role:"gridcell",title:t.functionPath,children:t.functionPath}),e[9]=t.functionPath,e[10]=d):d=e[10];const u=t.shardKey??"—";let h;e[11]!==u?(h=r("span",{className:"w-24 shrink-0 truncate text-muted-foreground",role:"gridcell",children:u}),e[11]=u,e[12]=h):h=e[12];const x=t.userId??"—";let f;e[13]!==x?(f=r("span",{className:"w-24 shrink-0 truncate text-muted-foreground",role:"gridcell",children:x}),e[13]=x,e[14]=f):f=e[14];let b;e[15]!==t.durationMs?(b=Math.round(t.durationMs),e[15]=t.durationMs,e[16]=b):b=e[16];const y=`${String(b)}ms`;let C;e[17]!==y?(C=r("span",{className:"w-16 shrink-0 tabular-nums text-muted-foreground",role:"gridcell",children:y}),e[17]=y,e[18]=C):C=e[18];let $;e[19]!==t.errorMessage||e[20]!==t.outcome||e[21]!==t.tablesRead||e[22]!==t.tablesWritten?($=t.outcome==="error"&&t.errorMessage!==void 0?t.errorMessage:`r:${ce(t.tablesRead)} · w:${ce(t.tablesWritten)}`,e[19]=t.errorMessage,e[20]=t.outcome,e[21]=t.tablesRead,e[22]=t.tablesWritten,e[23]=$):$=e[23];let L;e[24]!==$?(L=r("span",{className:"flex-1 truncate text-muted-foreground",role:"gridcell",children:$}),e[24]=$,e[25]=L):L=e[25];let k;return e[26]!==n||e[27]!==c||e[28]!==g||e[29]!==f||e[30]!==C||e[31]!==L||e[32]!==l||e[33]!==a||e[34]!==d||e[35]!==h?(k=T("div",{className:"flex items-center border-b border-border px-3 py-1.5 font-mono text-xs hover:bg-muted/50","data-index":n,"data-testid":"lg-req-row",ref:c,role:"row",style:g,children:[l,a,d,h,f,C,L]}),e[26]=n,e[27]=c,e[28]=g,e[29]=f,e[30]=C,e[31]=L,e[32]=l,e[33]=a,e[34]=d,e[35]=h,e[36]=k):k=e[36],k},ue=i=>{const{entries:e}=i??{};return Array.isArray(e)?e:[]},Ze=i=>{const e={};return i.functionPathPrefix.trim()!==""&&(e.functionPathPrefix=i.functionPathPrefix.trim()),i.userId.trim()!==""&&(e.userId=i.userId.trim()),i.tableTouched.trim()!==""&&(e.tableTouched=i.tableTouched.trim()),(i.outcome==="ok"||i.outcome==="error")&&(e.outcome=i.outcome),e},et={"5m":300*1e3,"15m":900*1e3,"1h":3600*1e3},tt=(i,e)=>{const t=e.search.trim().toLowerCase(),n=e.path.trim().toLowerCase(),c=e.range==="all"?Number.NEGATIVE_INFINITY:e.now-et[e.range];return i.filter(o=>e.levels.size>0&&!e.levels.has(o.level)||o.timestamp<c||n!==""&&!(o.functionPath??"").toLowerCase().includes(n)?!1:t===""||o.message.toLowerCase().includes(t)||re(o.fields).toLowerCase().includes(t))},rt="—",lt=i=>{const e=new Map,t=new Map;for(const o of i){e.set(o.level,(e.get(o.level)??0)+1);const m=o.functionPath??rt;t.set(m,(t.get(m)??0)+1)}const n=ae.filter(o=>e.has(o)).map(o=>({count:e.get(o)??0,key:o})),c=[...t.entries()].map(([o,m])=>({count:m,key:o})).toSorted((o,m)=>m.count===o.count?o.key.localeCompare(m.key):m.count-o.count);return{byLevel:n,byPath:c,total:i.length}},$t=({initialShardKey:i})=>{const e=z(),[t,n]=F("requests"),[c,o]=F(i??""),[m,p]=F(""),[g,s]=F(()=>new Set),[l,v]=F(""),[a,d]=F("all"),[u,h]=F(!1),[x,f]=F(""),[b,y]=F(""),[C,$]=F(""),[L,k]=F("all"),R=ee(c.trim(),400),w=Ze({functionPathPrefix:x,outcome:L,tableTouched:C,userId:b}),N=ne(se.getRequestLog,w,{enabled:t==="requests",live:!0,shardKey:R}),I=ne(se.getLogs,{},{enabled:t==="errors",live:!0,shardKey:R}),P=t==="requests"?N:I,{error:E,errorSource:q,isLoading:A,liveError:W}=P,K=ue(I.data),O=ue(N.data);he(()=>{P.data!==void 0&&Se(R)},[P.data,R]);const _=tt(K,{levels:g,now:Date.now(),path:l,range:a,search:m}),B=lt(_),U=t==="requests"?O.length:_.length,J=t==="errors"&&u,Q=Ce(()=>E!==null?"error":U===0?A?J?"summary":"list":"empty":J?"summary":"list",[U,A,E,J]),oe=me(null),Y=we({count:U,estimateSize:()=>Qe,getScrollElement:()=>oe.current,initialRect:{height:te,width:800},observeElementRect:(S,X)=>ke(S,X,te),overscan:8}),xe=Y.getVirtualItems(),ye={height:Y.getTotalSize(),position:"relative",width:"100%"};return T("div",{className:"flex flex-col gap-4","data-testid":"lunora-logs",children:[r(Ge,{liveError:W,onShardKeyChange:o,onShowArchive:()=>{n("archive"),h(!1)},onShowErrors:()=>{n("errors"),h(!1)},onShowRequests:()=>{n("requests"),h(!1)},shardKey:c,view:t}),t==="errors"&&r(Ve,{levelFilter:g,onLogPathChange:S=>{v(S.target.value)},onSearchChange:S=>{p(S.target.value)},onTimeRangeChange:S=>{d(S.target.value)},onToggleLevel:S=>{s(X=>{const H=new Set(X);return H.has(S)?H.delete(S):H.add(S),H})},onToggleSummary:()=>{h(S=>!S)},pathFilter:l,search:m,showSummary:u,timeRange:a}),t==="requests"&&r(je,{onOutcomeChange:S=>{k(S.target.value)},onPathChange:S=>{f(S.target.value)},onTableChange:S=>{$(S.target.value)},onUserChange:S=>{y(S.target.value)},outcomeFilter:L,pathPrefix:x,tableFilter:C,userIdFilter:b}),t==="archive"?r(Ue,{shardKey:R}):T(Fe,{children:[Q==="error"&&r(Le,{error:q,testId:"lg-error"}),Q==="empty"&&r(Z,{description:e("Function and request logs for this shard show up here as your app handles traffic."),icon:r("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:r("path",{d:"M4 5h16M4 12h16M4 19h10"})}),testId:"lg-empty",title:e("No logs.")}),Q==="summary"&&r(Be,{summary:B}),Q==="list"&&r("div",{className:"rounded-xl border border-border shadow-xs","data-testid":"lg-scroll",ref:oe,style:Ye,children:r("div",{"aria-label":e("Recent logs"),"data-testid":"lg-table",role:"grid",style:ye,children:xe.map(S=>t==="requests"?r(Xe,{entry:O[S.index],index:S.index,measureRef:Y.measureElement,start:S.start},S.key):r(Je,{entry:_[S.index],index:S.index,measureRef:Y.measureElement,start:S.start},S.key))})})]})]})};export{$t as LogsPanel,tt as filterLogs,lt as summarizeLogs};
@@ -1,2 +1,2 @@
1
- import{useLunora as G}from"@lunora/react";import{useState as p}from"react";import{E as J}from"../packem_shared/error-alert-t6cpEi0z.js";import{g as K}from"../packem_shared/badge-BbuuAio7.js";import{u as m}from"../packem_shared/button-BkCrNcAs.js";import{E as Q}from"../packem_shared/empty-state-Cg7t_8qu.js";import{u as V}from"../packem_shared/input-JHu63lTv.js";import{p as X}from"../packem_shared/scroll-area-DTEq6Jec.js";import{Separator as Y}from"@base-ui/react/separator";import{c as Z}from"../packem_shared/utils-bhneXptQ.js";import{jsx as e,jsxs as l,Fragment as ee}from"react/jsx-runtime";import{N as te}from"../packem_shared/use-admin-query-QJ-ibl5u.js";import{useAutoRefresh as ae}from"../packem_shared/DEFAULT_AUTO_REFRESH_MS-BCC8_4BQ.js";import{useT as re}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as g}from"../packem_shared/ADMIN_FUNCTIONS-BnD4aovm.js";import{i as k,f as $,c as ie,d as j,b as T,g as L}from"../packem_shared/internal-BSIsQVC6.js";function de({className:r,orientation:s="horizontal",...a}){return e(Y,{"data-slot":"separator",orientation:s,className:Z("shrink-0 bg-border data-horizontal:h-px data-horizontal:w-full data-vertical:w-px data-vertical:self-stretch",r),...a})}const le=L(g.clearCapturedMail),se=L(g.sendTestMail),oe=/https?:\/\/[^\s"'<>)]+/i,z=r=>r===void 0?void 0:oe.exec(r)?.[0],ne=r=>{if(r!==void 0)return z(r.html)??z(r.text)},ce=`<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src data:; style-src 'unsafe-inline'; font-src data:">`,me=r=>`${ce}${r}`,f=r=>r===void 0?"":Array.isArray(r)?r.join(", "):r,ue=(r,s)=>{const a=s.trim().toLowerCase();return a===""?r:r.filter(u=>`${u.subject} ${f(u.to)}`.toLowerCase().includes(a))},he=(r,s)=>{if(r.length!==0)return r.find(a=>a.id===s)??r[0]},Me=({limit:r=100})=>{const s=G(),a=re(),{data:u,error:b,errorSource:M,isLoading:S,refetch:x}=te(g.getCapturedMail,{limit:r}),[v,h]=p(null),[A,N]=p(null),[c,E]=p("html"),[w,F]=p(""),o=u?.entries??[],y=b??v,O=b===null?v:M,H=async()=>{h(null);try{await s.query(le,{},j("")),N(null),x()}catch(t){h(T(t))}},I=async()=>{h(null);try{await s.query(se,{},j("")),x()}catch(t){h(T(t))}};ae(()=>{x()},!0);const _=()=>{$(H())},q=()=>{$(I())},P=t=>{F(t.currentTarget.value)},D=t=>{const{id:d}=t.currentTarget.dataset;d!==void 0&&N(d)},R=t=>{const d=t.currentTarget.dataset.tab;(d==="headers"||d==="html"||d==="text")&&E(d)},B=t=>a(t==="html"?"HTML":t==="text"?"Plain text":"Headers"),C=ue(o,w),i=he(C,A),n=ne(i),U=()=>{n!==void 0&&ie(n)},W=()=>{n!==void 0&&"window"in globalThis&&globalThis.window.open(n,"_blank","noopener")};return l("div",{className:"flex flex-col gap-4","data-testid":"mail-panel",children:[l("div",{className:"flex flex-wrap items-center gap-2",children:[e(m,{"data-testid":"mail-send-test",onClick:q,size:"sm",type:"button",variant:"outline",children:a("Send test")}),e(m,{"data-testid":"mail-clear",disabled:o.length===0,onClick:_,size:"sm",type:"button",variant:"outline",children:a("Clear inbox")}),o.length>0&&e(K,{className:"ml-auto","data-testid":"mail-count",variant:"secondary",children:a("{count} messages",{count:o.length})})]}),y!==null&&e(J,{error:O,testId:"mail-error"}),y===null&&!S&&o.length===0&&e(Q,{description:a("Email your app sends in dev is captured here — nothing is delivered."),icon:l("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:[e("path",{d:"M4 5h16v14H4z"}),e("path",{d:"m4 6 8 6 8-6"})]}),testId:"mail-empty",title:a("No captured email.")}),o.length>0&&l("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-[minmax(0,22rem)_1fr]","data-testid":"mail-reader",children:[l("div",{className:"flex flex-col gap-2",children:[e(V,{"aria-label":a("Search messages"),"data-testid":"mail-search",onChange:P,placeholder:a("Filter messages"),type:"search",value:w}),e(X,{className:"max-h-[32rem] rounded-xl border border-border bg-card shadow-xs","data-testid":"mail-list",children:e("ul",{className:"divide-y",children:C.map(t=>{const d=t.id===i?.id;return e("li",{children:l("button",{className:`flex w-full flex-col items-start gap-0.5 px-3 py-2 text-left text-sm hover:bg-muted/60 ${d?"bg-muted":""}`,"data-active":d,"data-id":t.id,"data-testid":"mail-list-item",onClick:D,type:"button",children:[e("span",{className:"w-full truncate font-medium",children:t.subject||a("(no subject)")}),e("span",{className:"w-full truncate text-xs text-muted-foreground",children:f(t.to)}),e("span",{className:"text-xs text-muted-foreground tabular-nums",children:k(t.capturedAt,"—")})]})},t.id)})})})]}),i!==void 0&&l("div",{className:"flex min-w-0 flex-col gap-3 rounded-xl border border-border bg-card p-4 shadow-xs","data-testid":"mail-detail",children:[l("div",{className:"flex flex-col gap-1",children:[e("h2",{className:"truncate text-base font-semibold","data-testid":"mail-subject",children:i.subject||a("(no subject)")}),l("dl",{className:"grid grid-cols-[auto_1fr] gap-x-3 gap-y-0.5 text-xs text-muted-foreground",children:[e("dt",{children:a("From")}),e("dd",{className:"truncate font-mono",children:i.from??"—"}),e("dt",{children:a("To")}),e("dd",{className:"truncate font-mono",children:f(i.to)}),i.cc!==void 0&&i.cc.length>0&&l(ee,{children:[e("dt",{children:a("Cc")}),e("dd",{className:"truncate font-mono",children:f(i.cc)})]}),e("dt",{children:a("Sent")}),e("dd",{className:"tabular-nums",children:k(i.capturedAt,"—")})]})]}),l("div",{className:"flex flex-wrap items-center gap-2","data-testid":"mail-actions",children:[e(m,{"data-testid":"mail-copy-link",disabled:n===void 0,onClick:U,size:"sm",type:"button",variant:"outline",children:a("Copy link")}),e(m,{"data-testid":"mail-open-link",disabled:n===void 0,onClick:W,size:"sm",type:"button",variant:"outline",children:a("Open in new tab")})]}),e(de,{}),e("div",{className:"flex items-center gap-1","data-testid":"mail-tabs",role:"tablist",children:["html","text","headers"].map(t=>e(m,{"aria-selected":c===t,"data-tab":t,"data-testid":`mail-tab-${t}`,onClick:R,role:"tab",size:"sm",type:"button",variant:c===t?"secondary":"ghost",children:B(t)},t))}),l("div",{className:"min-h-[12rem]",children:[c==="html"&&(i.html===void 0?e("p",{className:"text-sm text-muted-foreground",children:a("No HTML body.")}):e("iframe",{className:"h-[24rem] w-full rounded-md border bg-white","data-testid":"mail-preview-html",sandbox:"",srcDoc:me(i.html),title:a("Email preview")})),c==="text"&&(i.text===void 0?e("p",{className:"text-sm text-muted-foreground",children:a("No text body.")}):e("pre",{className:"overflow-auto whitespace-pre-wrap rounded-md border bg-muted/30 p-3 text-xs","data-testid":"mail-preview-text",children:i.text})),c==="headers"&&(i.headers===void 0||Object.keys(i.headers).length===0?e("p",{className:"text-sm text-muted-foreground",children:a("No headers.")}):e("pre",{className:"overflow-auto whitespace-pre-wrap rounded-md border bg-muted/30 p-3 text-xs","data-testid":"mail-preview-headers",children:Object.entries(i.headers).map(([t,d])=>`${t}: ${d}`).join(`
2
- `)}))]})]})]})]})};export{Me as MailPanel};
1
+ import{E as ie}from"../packem_shared/error-alert-t6cpEi0z.js";import{g as le}from"../packem_shared/badge-BbuuAio7.js";import{u as v}from"../packem_shared/button-BkCrNcAs.js";import{E as oe}from"../packem_shared/empty-state-Cg7t_8qu.js";import{u as se}from"../packem_shared/input-JHu63lTv.js";import{p as ne}from"../packem_shared/scroll-area-DTEq6Jec.js";import{Separator as de}from"@base-ui/react/separator";import{c as ce}from"../packem_shared/utils-bhneXptQ.js";import{jsx as t,jsxs as s,Fragment as me}from"react/jsx-runtime";import{useT as ue}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{d as Y,b as Z,f as ee,c as he,g as re,i as te}from"../packem_shared/internal-BSIsQVC6.js";import{c as pe}from"react/compiler-runtime";import{useLunora as fe}from"@lunora/react";import{useState as H}from"react";import{N as be}from"../packem_shared/use-admin-query-QJ-ibl5u.js";import{useAutoRefresh as ge}from"../packem_shared/DEFAULT_AUTO_REFRESH_MS-BCC8_4BQ.js";import{ADMIN_FUNCTIONS as Q}from"../packem_shared/ADMIN_FUNCTIONS-CZESgd10.js";function xe({className:a,orientation:e="horizontal",...l}){return t(de,{"data-slot":"separator",orientation:e,className:ce("shrink-0 bg-border data-horizontal:h-px data-horizontal:w-full data-vertical:w-px data-vertical:self-stretch",a),...l})}const ve=/https?:\/\/[^\s"'<>)]+/i,ae=a=>a===void 0?void 0:ve.exec(a)?.[0],N=a=>a===void 0?"":Array.isArray(a)?a.join(", "):a,Ne=a=>{if(a!==void 0)return ae(a.html)??ae(a.text)},ye=(a,e)=>{const l=e.trim().toLowerCase();return l===""?a:a.filter(o=>`${o.subject} ${N(o.to)} ${N(o.cc)}`.toLowerCase().includes(l))},we=(a,e)=>{if(a.length!==0)return a.find(l=>l.id===e)??a[0]},Ce=re(Q.clearCapturedMail),ke=re(Q.sendTestMail),Se=a=>{const e=pe(38),{limit:l}=a,o=fe();let p;e[0]!==l?(p={limit:l},e[0]=l,e[1]=p):p=e[1];const{data:P,error:y,errorSource:w,isLoading:g,refetch:n}=be(Q.getCapturedMail,p),[C,f]=H(null),[q,k]=H(null),[x,i]=H("html"),[c,D]=H(""),b=P?.entries??[],r=y??C,u=y===null?C:w;let S;e[2]!==o||e[3]!==n?(S=async()=>{f(null);try{await o.query(Ce,{},Y("")),k(null),n()}catch(m){f(Z(m))}},e[2]=o,e[3]=n,e[4]=S):S=e[4];const R=S;let $;e[5]!==o||e[6]!==n?($=async()=>{f(null);try{await o.query(ke,{},Y("")),n()}catch(m){f(Z(m))}},e[5]=o,e[6]=n,e[7]=$):$=e[7];const B=$;let T;e[8]!==n?(T=()=>{n()},e[8]=n,e[9]=T):T=e[9],ge(T,!0);let L;e[10]!==R?(L=()=>{ee(R())},e[10]=R,e[11]=L):L=e[11];const U=L;let j;e[12]!==B?(j=()=>{ee(B())},e[12]=B,e[13]=j):j=e[13];const W=j;let M;e[14]===Symbol.for("react.memo_cache_sentinel")?(M=m=>{D(m.currentTarget.value)},e[14]=M):M=e[14];const J=M;let _;e[15]===Symbol.for("react.memo_cache_sentinel")?(_=m=>{const{id:h}=m.currentTarget.dataset;h!==void 0&&k(h)},e[15]=_):_=e[15];const K=_;let z;e[16]===Symbol.for("react.memo_cache_sentinel")?(z=m=>{const h=m.currentTarget.dataset.tab;(h==="headers"||h==="html"||h==="text")&&i(h)},e[16]=z):z=e[16];const V=z,A=ye(b,c),F=we(A,q),d=Ne(F);let O;e[17]!==d?(O=()=>{d!==void 0&&he(d)},e[17]=d,e[18]=O):O=e[18];const X=O;let E;e[19]!==d?(E=()=>{d!==void 0&&"window"in globalThis&&globalThis.window.open(d,"_blank","noopener")},e[19]=d,e[20]=E):E=e[20];const G=E;let I;return e[21]!==b||e[22]!==r||e[23]!==u||e[24]!==c||e[25]!==g||e[26]!==d||e[27]!==U||e[28]!==X||e[29]!==J||e[30]!==G||e[31]!==K||e[32]!==V||e[33]!==W||e[34]!==F||e[35]!==x||e[36]!==A?(I={entries:b,error:r,errorSource:u,filter:c,isLoading:g,link:d,onClear:U,onCopyLink:X,onFilterChange:J,onOpenLink:G,onSelectMessage:K,onSelectTab:V,onSendTest:W,selected:F,tab:x,visible:A},e[21]=b,e[22]=r,e[23]=u,e[24]=c,e[25]=g,e[26]=d,e[27]=U,e[28]=X,e[29]=J,e[30]=G,e[31]=K,e[32]=V,e[33]=W,e[34]=F,e[35]=x,e[36]=A,e[37]=I):I=e[37],I},$e=`<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src data:; style-src 'unsafe-inline'; font-src data:">`,Te=a=>`${$e}${a}`,We=({limit:a=100})=>{const e=ue(),{entries:l,error:o,errorSource:p,filter:P,isLoading:y,link:w,onClear:g,onCopyLink:n,onFilterChange:C,onOpenLink:f,onSelectMessage:q,onSelectTab:k,onSendTest:x,selected:i,tab:c,visible:D}=Se({limit:a}),b=r=>e(r==="html"?"HTML":r==="text"?"Plain text":"Headers");return s("div",{className:"flex flex-col gap-4","data-testid":"mail-panel",children:[s("div",{className:"flex flex-wrap items-center gap-2",children:[t(v,{"data-testid":"mail-send-test",onClick:x,size:"sm",type:"button",variant:"outline",children:e("Send test")}),t(v,{"data-testid":"mail-clear",disabled:l.length===0,onClick:g,size:"sm",type:"button",variant:"outline",children:e("Clear inbox")}),l.length>0&&t(le,{className:"ml-auto","data-testid":"mail-count",variant:"secondary",children:e("{count} messages",{count:l.length})})]}),o!==null&&t(ie,{error:p,testId:"mail-error"}),o===null&&!y&&l.length===0&&t(oe,{description:e("Email your app sends in dev is captured here — nothing is delivered."),icon:s("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:[t("path",{d:"M4 5h16v14H4z"}),t("path",{d:"m4 6 8 6 8-6"})]}),testId:"mail-empty",title:e("No captured email.")}),l.length>0&&s("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-[minmax(0,22rem)_1fr]","data-testid":"mail-reader",children:[s("div",{className:"flex flex-col gap-2",children:[t(se,{"aria-label":e("Search messages"),"data-testid":"mail-search",onChange:C,placeholder:e("Filter messages"),type:"search",value:P}),t(ne,{className:"max-h-[32rem] rounded-xl border border-border bg-card shadow-xs","data-testid":"mail-list",children:t("ul",{className:"divide-y",children:D.map(r=>{const u=r.id===i?.id;return t("li",{children:s("button",{className:`flex w-full flex-col items-start gap-0.5 px-3 py-2 text-left text-sm hover:bg-muted/60 ${u?"bg-muted":""}`,"data-active":u,"data-id":r.id,"data-testid":"mail-list-item",onClick:q,type:"button",children:[t("span",{className:"w-full truncate font-medium",children:r.subject||e("(no subject)")}),t("span",{className:"w-full truncate text-xs text-muted-foreground",children:N(r.to)}),t("span",{className:"text-xs text-muted-foreground tabular-nums",children:te(r.capturedAt,"—")})]})},r.id)})})})]}),i!==void 0&&s("div",{className:"flex min-w-0 flex-col gap-3 rounded-xl border border-border bg-card p-4 shadow-xs","data-testid":"mail-detail",children:[s("div",{className:"flex flex-col gap-1",children:[t("h2",{className:"truncate text-base font-semibold","data-testid":"mail-subject",children:i.subject||e("(no subject)")}),s("dl",{className:"grid grid-cols-[auto_1fr] gap-x-3 gap-y-0.5 text-xs text-muted-foreground",children:[t("dt",{children:e("From")}),t("dd",{className:"truncate font-mono",children:i.from??"—"}),t("dt",{children:e("To")}),t("dd",{className:"truncate font-mono",children:N(i.to)}),i.cc!==void 0&&i.cc.length>0&&s(me,{children:[t("dt",{children:e("Cc")}),t("dd",{className:"truncate font-mono",children:N(i.cc)})]}),t("dt",{children:e("Sent")}),t("dd",{className:"tabular-nums",children:te(i.capturedAt,"—")})]})]}),s("div",{className:"flex flex-wrap items-center gap-2","data-testid":"mail-actions",children:[t(v,{"data-testid":"mail-copy-link",disabled:w===void 0,onClick:n,size:"sm",type:"button",variant:"outline",children:e("Copy link")}),t(v,{"data-testid":"mail-open-link",disabled:w===void 0,onClick:f,size:"sm",type:"button",variant:"outline",children:e("Open in new tab")})]}),t(xe,{}),t("div",{className:"flex items-center gap-1","data-testid":"mail-tabs",role:"tablist",children:["html","text","headers"].map(r=>t(v,{"aria-selected":c===r,"data-tab":r,"data-testid":`mail-tab-${r}`,onClick:k,role:"tab",size:"sm",type:"button",variant:c===r?"secondary":"ghost",children:b(r)},r))}),s("div",{className:"min-h-[12rem]",children:[c==="html"&&(i.html===void 0?t("p",{className:"text-sm text-muted-foreground",children:e("No HTML body.")}):t("iframe",{className:"h-[24rem] w-full rounded-md border bg-white","data-testid":"mail-preview-html",sandbox:"",srcDoc:Te(i.html),title:e("Email preview")})),c==="text"&&(i.text===void 0?t("p",{className:"text-sm text-muted-foreground",children:e("No text body.")}):t("pre",{className:"overflow-auto whitespace-pre-wrap rounded-md border bg-muted/30 p-3 text-xs","data-testid":"mail-preview-text",children:i.text})),c==="headers"&&(i.headers===void 0||Object.keys(i.headers).length===0?t("p",{className:"text-sm text-muted-foreground",children:e("No headers.")}):t("pre",{className:"overflow-auto whitespace-pre-wrap rounded-md border bg-muted/30 p-3 text-xs","data-testid":"mail-preview-headers",children:Object.entries(i.headers).map(([r,u])=>`${r}: ${u}`).join(`
2
+ `)}))]})]})]})]})};export{We as MailPanel};
@@ -1 +1 @@
1
- import{c as Re}from"react/compiler-runtime";import{useLunora as pt}from"@lunora/react";import{useNavigate as xt}from"@tanstack/react-router";import{useState as ue,useRef as Ge,useEffect as tt,useMemo as bt}from"react";import{L as vt}from"../packem_shared/live-status-CmuRLFKf.js";import{ShardInput as yt}from"../packem_shared/ShardInput-BVn2iCU0.js";import{u as rt}from"../packem_shared/button-BkCrNcAs.js";import{c as he,u as ge,n as Qe,f as Ue,m as Nt}from"../packem_shared/card-CIDGUN6K.js";import{p as ie,d as ct,m as Be,u as se,n as mt,f as ut}from"../packem_shared/table-DdJBrClo.js";import{N as He}from"../packem_shared/use-admin-query-QJ-ibl5u.js";import wt from"../packem_shared/useDebounced-Ihdiid_k.js";import{useT as Ae}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as Oe}from"../packem_shared/ADMIN_FUNCTIONS-BnD4aovm.js";import{c as St}from"../packem_shared/cf-links-gbDy51nR.js";import{l as $t,k as Xe,f as at,d as kt,b as qt,g as _t}from"../packem_shared/internal-BSIsQVC6.js";import{r as Mt,l as It}from"../packem_shared/shard-history-DMEW5VBE.js";import{w as Ct}from"../packem_shared/trace-handoff-Dw7mwjxu.js";import{f as Tt}from"../packem_shared/log-fields-CoL3hsIQ.js";import{g as et}from"../packem_shared/badge-BbuuAio7.js";import{S as ht}from"../packem_shared/sparkline-CgjeUU2I.js";import{jsx as t,jsxs as n,Fragment as Ye}from"react/jsx-runtime";import{aggregateMetrics as Dt,computeLatencyPercentiles as Ft,enrichQueryStats as Lt,shardsToAggregate as Ot}from"../packem_shared/aggregateMetrics-BNfajLa2.js";import{ResponsiveContainer as st,AreaChart as Rt,CartesianGrid as lt,XAxis as nt,YAxis as it,Tooltip as ot,Area as At,LineChart as zt,Line as Kt}from"recharts";import{E as Et}from"../packem_shared/empty-state-Cg7t_8qu.js";import{c as jt}from"../packem_shared/utils-bhneXptQ.js";import{N as Qt,y as Ut,k as Pe,_ as Pt,w as Jt}from"../packem_shared/select-Bul-DeII.js";const Bt=(s,e)=>s<e?-1:s>e?1:0,Ze=s=>{if(s===void 0)return"null";if(typeof s=="bigint")throw new TypeError("stableStringify: cannot use a bigint in a stable JSON cache key — pass it as a string, or use stableWireKey");if(s===null||typeof s!="object")return JSON.stringify(s);if(Array.isArray(s))return`[${s.map(u=>Ze(u)).join(",")}]`;const e=Object.getPrototypeOf(s);if(e!==null&&e!==Object.prototype){const u=s.constructor?.name??"value";throw new TypeError(`stableStringify: cannot use a ${u} in a stable JSON cache key — only plain objects, arrays, and JSON primitives are supported (wire-typed values key via stableWireKey)`)}const l=s,r=Object.keys(l).toSorted(Bt),a=[];for(const u of r){const c=l[u];c!==void 0&&a.push(`${JSON.stringify(u)}:${Ze(c)}`)}return`{${a.join(",")}}`},gt=(s,e,l)=>`${s}:${e}:${Ze(l??{})}`,ft=(s,e)=>s==="gauge"?e.last:s==="histogram"?e.sum/Math.max(1,e.count):e.sum,Ht=(s,e)=>ft(s,e),Wt=s=>ft(s.kind,s),Ve=s=>Number.isInteger(s)?s.toLocaleString():s.toLocaleString(void 0,{maximumFractionDigits:2}),Gt=s=>Array.isArray(s?.series)?s.series:[],Xt="FUNCTION_NOT_FOUND",Yt=s=>{const e=new Map;if(!Array.isArray(s?.series))return e;for(const l of s.series)e.set(gt(l.kind,l.name,l.attributes),l.points);return e},Vt={counter:"secondary",gauge:"default",histogram:"outline"},Zt=s=>{const e=Re(18),{name:l,onOpenTrace:r,traceId:a}=s,u=Ae();if(a===void 0){let m;return e[0]===Symbol.for("react.memo_cache_sentinel")?(m=t("span",{className:"text-muted-foreground",children:"—"}),e[0]=m):m=e[0],m}let c;e[1]!==a?(c=a.slice(0,8),e[1]=a,e[2]=c):c=e[2];const g=c;if(r===void 0){const m=`mt-instrument-trace-${l}`;let b;return e[3]!==g||e[4]!==m||e[5]!==a?(b=t("span",{className:"text-muted-foreground","data-testid":m,title:a,children:g}),e[3]=g,e[4]=m,e[5]=a,e[6]=b):b=e[6],b}const p=`mt-instrument-trace-${l}`;let x;e[7]!==r||e[8]!==a?(x=()=>{r(a)},e[7]=r,e[8]=a,e[9]=x):x=e[9];let v;e[10]!==u||e[11]!==a?(v=u("Open the exemplar trace {trace}",{trace:a}),e[10]=u,e[11]=a,e[12]=v):v=e[12];let h;return e[13]!==g||e[14]!==p||e[15]!==x||e[16]!==v?(h=t("button",{className:"text-primary underline-offset-4 hover:underline","data-testid":p,onClick:x,title:v,type:"button",children:g}),e[13]=g,e[14]=p,e[15]=x,e[16]=v,e[17]=h):h=e[17],h},er=s=>{const e=Re(105),{onOpenTrace:l,shardKey:r}=s,a=Ae();let u;e[0]===Symbol.for("react.memo_cache_sentinel")?(u={},e[0]=u):u=e[0];let c;e[1]!==r?(c={live:!0,shardKey:r},e[1]=r,e[2]=c):c=e[2];const{data:g,error:p,errorSource:x}=He(Oe.getMetricSeries,u,c);let v;e[3]===Symbol.for("react.memo_cache_sentinel")?(v={},e[3]=v):v=e[3];let h;e[4]!==r?(h={live:!0,shardKey:r},e[4]=r,e[5]=h):h=e[5];const{data:m}=He(Oe.getMetricHistory,v,h);let b,O,k,C,R,o,y,$,T,D,_,N,A;if(e[6]!==g||e[7]!==p||e[8]!==x||e[9]!==m||e[10]!==l||e[11]!==a){$=Symbol.for("react.early_return_sentinel");e:{const de=Gt(g),ce=$t(x)===Xt;if(p!==null&&!ce){let i;e[25]!==a?(i=a("Instruments"),e[25]=a,e[26]=i):i=e[26];let I;e[27]!==i?(I=t("h3",{className:"text-sm font-semibold text-foreground",children:i}),e[27]=i,e[28]=I):I=e[28];let F;e[29]!==p||e[30]!==a?(F=a("Instruments unavailable: {error}",{error:p}),e[29]=p,e[30]=a,e[31]=F):F=e[31];let L;e[32]!==F?(L=t("span",{className:"text-xs text-muted-foreground","data-testid":"mt-instruments-error",role:"status",children:F}),e[32]=F,e[33]=L):L=e[33];let ae;e[34]!==I||e[35]!==L?(ae=n("section",{className:"flex flex-col gap-2","data-testid":"mt-instruments",children:[I,L]}),e[34]=I,e[35]=L,e[36]=ae):ae=e[36],$=ae;break e}if(de.length===0){$=null;break e}const Fe=Yt(m);let d;e[37]!==a?(d=i=>a(i==="counter"?"Counter":i==="gauge"?"Gauge":"Histogram"),e[37]=a,e[38]=d):d=e[38];const K=d;R="flex flex-col gap-2",o="mt-instruments";let w;e[39]!==a?(w=a("Instruments"),e[39]=a,e[40]=w):w=e[40],e[41]!==w?(y=t("h3",{className:"text-sm font-semibold text-foreground",children:w}),e[41]=w,e[42]=y):y=e[42],C=he,A="overflow-hidden py-0",k=ge,N="px-0",O=mt,D="mt-instruments-table";let S;e[43]!==a?(S=a("name"),e[43]=a,e[44]=S):S=e[44];let Q;e[45]!==S?(Q=t(ie,{children:S}),e[45]=S,e[46]=Q):Q=e[46];let U;e[47]!==a?(U=a("kind"),e[47]=a,e[48]=U):U=e[48];let P;e[49]!==U?(P=t(ie,{children:U}),e[49]=U,e[50]=P):P=e[50];let J;e[51]!==a?(J=a("value"),e[51]=a,e[52]=J):J=e[52];let B;e[53]!==J?(B=t(ie,{className:"text-right",children:J}),e[53]=J,e[54]=B):B=e[54];let H;e[55]!==a?(H=a("count"),e[55]=a,e[56]=H):H=e[56];let W;e[57]!==H?(W=t(ie,{className:"text-right",children:H}),e[57]=H,e[58]=W):W=e[58];let G;e[59]!==a?(G=a("range"),e[59]=a,e[60]=G):G=e[60];let X;e[61]!==G?(X=t(ie,{className:"text-right",children:G}),e[61]=G,e[62]=X):X=e[62];let Y;e[63]!==a?(Y=a("trend"),e[63]=a,e[64]=Y):Y=e[64];let V;e[65]!==Y?(V=t(ie,{children:Y}),e[65]=Y,e[66]=V):V=e[66];let Z;e[67]!==a?(Z=a("trace"),e[67]=a,e[68]=Z):Z=e[68];let ee;e[69]!==Z?(ee=t(ie,{children:Z}),e[69]=Z,e[70]=ee):ee=e[70];let te;e[71]!==a?(te=a("dimensions"),e[71]=a,e[72]=te):te=e[72];let re;e[73]!==te?(re=t(ie,{children:te}),e[73]=te,e[74]=re):re=e[74],e[75]!==Q||e[76]!==P||e[77]!==B||e[78]!==W||e[79]!==X||e[80]!==V||e[81]!==ee||e[82]!==re?(_=t(ct,{children:n(Be,{children:[Q,P,B,W,X,V,ee,re]})}),e[75]=Q,e[76]=P,e[77]=B,e[78]=W,e[79]=X,e[80]=V,e[81]=ee,e[82]=re,e[83]=_):_=e[83],b=ut,T=de.map(i=>{const I=Tt(i.attributes),F=gt(i.kind,i.name,i.attributes),L=(Fe.get(F)??[]).map(ae=>Ht(i.kind,ae));return n(Be,{"data-testid":`mt-instrument-${i.name}`,children:[t(se,{className:"font-mono text-xs",title:i.functionPath,children:i.name}),t(se,{children:t(et,{variant:Vt[i.kind],children:K(i.kind)})}),t(se,{className:"text-right font-mono tabular-nums","data-testid":`mt-instrument-value-${i.name}`,children:Ve(Wt(i))}),t(se,{className:"text-right tabular-nums text-muted-foreground",children:i.count.toLocaleString()}),t(se,{className:"text-right font-mono text-xs tabular-nums text-muted-foreground",children:i.min===i.max?"—":`${Ve(i.min)}–${Ve(i.max)}`}),t(se,{children:L.length>=2?t(ht,{ariaLabel:a("{name} trend",{name:i.name}),className:"h-6 w-24 text-foreground",series:L,testId:`mt-instrument-trend-${i.name}`}):t("span",{className:"text-xs text-muted-foreground",children:"—"})}),t(se,{className:"font-mono text-xs",children:t(Zt,{name:i.name,onOpenTrace:l,traceId:i.exemplarTraceId})}),t(se,{className:"max-w-64 truncate font-mono text-xs text-muted-foreground",title:I,children:I===""?"—":I})]},F)})}e[6]=g,e[7]=p,e[8]=x,e[9]=m,e[10]=l,e[11]=a,e[12]=b,e[13]=O,e[14]=k,e[15]=C,e[16]=R,e[17]=o,e[18]=y,e[19]=$,e[20]=T,e[21]=D,e[22]=_,e[23]=N,e[24]=A}else b=e[12],O=e[13],k=e[14],C=e[15],R=e[16],o=e[17],y=e[18],$=e[19],T=e[20],D=e[21],_=e[22],N=e[23],A=e[24];if($!==Symbol.for("react.early_return_sentinel"))return $;let j;e[84]!==b||e[85]!==T?(j=t(b,{children:T}),e[84]=b,e[85]=T,e[86]=j):j=e[86];let z;e[87]!==O||e[88]!==j||e[89]!==D||e[90]!==_?(z=n(O,{"data-testid":D,children:[_,j]}),e[87]=O,e[88]=j,e[89]=D,e[90]=_,e[91]=z):z=e[91];let M;e[92]!==k||e[93]!==z||e[94]!==N?(M=t(k,{className:N,children:z}),e[92]=k,e[93]=z,e[94]=N,e[95]=M):M=e[95];let q;e[96]!==C||e[97]!==M||e[98]!==A?(q=t(C,{className:A,children:M}),e[96]=C,e[97]=M,e[98]=A,e[99]=q):q=e[99];let oe;return e[100]!==R||e[101]!==o||e[102]!==y||e[103]!==q?(oe=n("section",{className:R,"data-testid":o,children:[y,q]}),e[100]=R,e[101]=o,e[102]=y,e[103]=q,e[104]=oe):oe=e[104],oe},We=s=>s>=100?"critical":s>=50?"warning":"good",Le=s=>s<1?`${(s*1e3).toFixed(0)}μs`:s<1e3?`${s.toFixed(1)}ms`:`${(s/1e3).toFixed(2)}s`,Je=s=>s>=1e9?`${(s/1e9).toFixed(1)}B`:s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString(),tr=s=>{const e=Re(3),{level:l}=s;if(l==="critical"){let a;return e[0]===Symbol.for("react.memo_cache_sentinel")?(a=t(et,{variant:"destructive",children:"Slow"}),e[0]=a):a=e[0],a}if(l==="warning"){let a;return e[1]===Symbol.for("react.memo_cache_sentinel")?(a=t("span",{className:"inline-flex items-center gap-1 rounded-md border border-transparent bg-warning/10 px-2 py-0.5 text-xs font-medium text-warning",children:"Moderate"}),e[1]=a):a=e[1],a}let r;return e[2]===Symbol.for("react.memo_cache_sentinel")?(r=t("span",{className:"inline-flex items-center gap-1 rounded-md border border-transparent bg-success/10 px-2 py-0.5 text-xs font-medium text-success",children:"Fast"}),e[2]=r):r=e[2],r},rr=(s,e)=>{const l=[...s];return l.sort((r,a)=>{switch(e){case"avgTime":return a.avgDurationMs-r.avgDurationMs;case"execCount":return a.execCount-r.execCount;case"rowsRead":return a.rowsRead-r.rowsRead;default:return a.totalDurationMs-r.totalDurationMs}}),l},ar=s=>{const e=Re(161),{queryStats:l}=s,r=Ae(),[a,u]=ue("totalTime");let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c=new Set,e[0]=c):c=e[0];const[g,p]=ue(c);let x;e[1]===Symbol.for("react.memo_cache_sentinel")?(x=A=>{A!==null&&u(A)},e[1]=x):x=e[1];const v=x;let h,m,b,O,k,C,R,o,y,$;if(e[2]!==g||e[3]!==l||e[4]!==a||e[5]!==r){b=Symbol.for("react.early_return_sentinel");e:{const A=rr(l,a);let j;e[16]!==l?(j=l.filter(sr),e[16]=l,e[17]=j):j=e[17];const z=j.length;let M;e[18]!==l?(M=l.filter(lr),e[18]=l,e[19]=M):M=e[19];const q=M.length;let oe;e[20]!==l?(oe=l.filter(nr),e[20]=l,e[21]=oe):oe=e[21];const de=oe.length;let ce;e[22]===Symbol.for("react.memo_cache_sentinel")?(ce=f=>{p(le=>{const E=new Set(le);return E.has(f)?E.delete(f):E.add(f),E})},e[22]=ce):ce=e[22];const Fe=ce;if(l.length===0){let f;e[23]!==r?(f=r("No query insights yet"),e[23]=r,e[24]=f):f=e[24];let le;e[25]!==f?(le=t("p",{className:"text-lg font-medium","data-testid":"qi-empty",children:f}),e[25]=f,e[26]=le):le=e[26];let E;e[27]!==r?(E=r("Query insights appear once statements are executed against this shard."),e[27]=r,e[28]=E):E=e[28];let me;e[29]!==E?(me=t("p",{className:"mt-1 text-sm",children:E}),e[29]=E,e[30]=me):me=e[30];let je;e[31]!==le||e[32]!==me?(je=t(he,{children:t(ge,{className:"py-12",children:n("div",{className:"text-center text-muted-foreground",children:[le,me]})})}),e[31]=le,e[32]=me,e[33]=je):je=e[33],b=je;break e}R="space-y-4",o="qi-root";let d;e[34]!==r?(d=r("Critical queries"),e[34]=r,e[35]=d):d=e[35];let K;e[36]!==d?(K=t(Qe,{className:"pb-2",children:t(Ue,{className:"text-sm font-medium",children:d})}),e[36]=d,e[37]=K):K=e[37];let w;e[38]!==z?(w=t("div",{className:"text-2xl font-bold text-destructive","data-testid":"qi-critical",children:z}),e[38]=z,e[39]=w):w=e[39];let S;e[40]!==r?(S=r(">100ms avg execution"),e[40]=r,e[41]=S):S=e[41];let Q;e[42]!==S?(Q=t("p",{className:"text-xs text-muted-foreground",children:S}),e[42]=S,e[43]=Q):Q=e[43];let U;e[44]!==w||e[45]!==Q?(U=n(ge,{children:[w,Q]}),e[44]=w,e[45]=Q,e[46]=U):U=e[46];let P;e[47]!==K||e[48]!==U?(P=n(he,{children:[K,U]}),e[47]=K,e[48]=U,e[49]=P):P=e[49];let J;e[50]!==r?(J=r("Moderate queries"),e[50]=r,e[51]=J):J=e[51];let B;e[52]!==J?(B=t(Qe,{className:"pb-2",children:t(Ue,{className:"text-sm font-medium",children:J})}),e[52]=J,e[53]=B):B=e[53];let H;e[54]!==q?(H=t("div",{className:"text-2xl font-bold text-warning","data-testid":"qi-moderate",children:q}),e[54]=q,e[55]=H):H=e[55];let W;e[56]!==r?(W=r("50–100ms avg execution"),e[56]=r,e[57]=W):W=e[57];let G;e[58]!==W?(G=t("p",{className:"text-xs text-muted-foreground",children:W}),e[58]=W,e[59]=G):G=e[59];let X;e[60]!==H||e[61]!==G?(X=n(ge,{children:[H,G]}),e[60]=H,e[61]=G,e[62]=X):X=e[62];let Y;e[63]!==B||e[64]!==X?(Y=n(he,{children:[B,X]}),e[63]=B,e[64]=X,e[65]=Y):Y=e[65];let V;e[66]!==r?(V=r("Fast queries"),e[66]=r,e[67]=V):V=e[67];let Z;e[68]!==V?(Z=t(Qe,{className:"pb-2",children:t(Ue,{className:"text-sm font-medium",children:V})}),e[68]=V,e[69]=Z):Z=e[69];let ee;e[70]!==de?(ee=t("div",{className:"text-2xl font-bold text-success","data-testid":"qi-fast",children:de}),e[70]=de,e[71]=ee):ee=e[71];let te;e[72]!==r?(te=r("<50ms avg execution"),e[72]=r,e[73]=te):te=e[73];let re;e[74]!==te?(re=t("p",{className:"text-xs text-muted-foreground",children:te}),e[74]=te,e[75]=re):re=e[75];let i;e[76]!==ee||e[77]!==re?(i=n(ge,{children:[ee,re]}),e[76]=ee,e[77]=re,e[78]=i):i=e[78];let I;e[79]!==Z||e[80]!==i?(I=n(he,{children:[Z,i]}),e[79]=Z,e[80]=i,e[81]=I):I=e[81],e[82]!==P||e[83]!==Y||e[84]!==I?(y=n("div",{className:"grid gap-4 md:grid-cols-3",children:[P,Y,I]}),e[82]=P,e[83]=Y,e[84]=I,e[85]=y):y=e[85];let F;e[86]!==r?(F=r("Query leaderboard"),e[86]=r,e[87]=F):F=e[87];let L;e[88]!==F?(L=t("h3",{className:"text-lg font-semibold",children:F}),e[88]=F,e[89]=L):L=e[89];let ae;e[90]!==a||e[91]!==r?(ae=r("Slow queries sorted by {sortField}",{sortField:r(a)}),e[90]=a,e[91]=r,e[92]=ae):ae=e[92];let fe;e[93]!==ae?(fe=t("p",{className:"text-sm text-muted-foreground",children:ae}),e[93]=ae,e[94]=fe):fe=e[94];let pe;e[95]!==L||e[96]!==fe?(pe=n("div",{children:[L,fe]}),e[95]=L,e[96]=fe,e[97]=pe):pe=e[97];let xe;e[98]!==r?(xe=r("Sort by"),e[98]=r,e[99]=xe):xe=e[99];let be;e[100]!==xe?(be=t("span",{className:"text-sm text-muted-foreground",children:xe}),e[100]=xe,e[101]=be):be=e[101];let ve;e[102]!==r?(ve=r("Sort queries by"),e[102]=r,e[103]=ve):ve=e[103];let ze;e[104]===Symbol.for("react.memo_cache_sentinel")?(ze=t(Qt,{}),e[104]=ze):ze=e[104];let ye;e[105]!==ve?(ye=t(Ut,{"aria-label":ve,className:"w-[140px]","data-testid":"qi-sort",children:ze}),e[105]=ve,e[106]=ye):ye=e[106];let Ne;e[107]!==r?(Ne=r("Total time"),e[107]=r,e[108]=Ne):Ne=e[108];let we;e[109]!==Ne?(we=t(Pe,{value:"totalTime",children:Ne}),e[109]=Ne,e[110]=we):we=e[110];let Se;e[111]!==r?(Se=r("Avg time"),e[111]=r,e[112]=Se):Se=e[112];let $e;e[113]!==Se?($e=t(Pe,{value:"avgTime",children:Se}),e[113]=Se,e[114]=$e):$e=e[114];let ke;e[115]!==r?(ke=r("Execution count"),e[115]=r,e[116]=ke):ke=e[116];let qe;e[117]!==ke?(qe=t(Pe,{value:"execCount",children:ke}),e[117]=ke,e[118]=qe):qe=e[118];let _e;e[119]!==r?(_e=r("Rows read"),e[119]=r,e[120]=_e):_e=e[120];let Me;e[121]!==_e?(Me=t(Pe,{value:"rowsRead",children:_e}),e[121]=_e,e[122]=Me):Me=e[122];let Ie;e[123]!==we||e[124]!==$e||e[125]!==qe||e[126]!==Me?(Ie=n(Pt,{children:[we,$e,qe,Me]}),e[123]=we,e[124]=$e,e[125]=qe,e[126]=Me,e[127]=Ie):Ie=e[127];let Ce;e[128]!==a||e[129]!==ye||e[130]!==Ie?(Ce=n(Jt,{onValueChange:v,value:a,children:[ye,Ie]}),e[128]=a,e[129]=ye,e[130]=Ie,e[131]=Ce):Ce=e[131];let Te;e[132]!==be||e[133]!==Ce?(Te=n("div",{className:"flex items-center gap-2",children:[be,Ce]}),e[132]=be,e[133]=Ce,e[134]=Te):Te=e[134],e[135]!==pe||e[136]!==Te?($=n("div",{className:"flex items-center justify-between",children:[pe,Te]}),e[135]=pe,e[136]=Te,e[137]=$):$=e[137],m=he;let De;e[138]!==r?(De=r("Statements"),e[138]=r,e[139]=De):De=e[139];let Ke;e[140]!==De?(Ke=t(Ue,{children:De}),e[140]=De,e[141]=Ke):Ke=e[141],C=n(Qe,{children:[Ke,t(Nt,{children:r("{count} tracked statements",{count:A.length})})]}),h=ge,O="space-y-2";let Ee;e[142]!==g||e[143]!==r?(Ee=f=>{const le=f.normalizedSql,E=g.has(le),me=We(f.avgDurationMs);return n("div",{className:"overflow-hidden rounded-lg border","data-testid":"qi-row",children:[n("button",{"aria-expanded":E,className:"flex w-full items-center justify-between p-3 text-left transition-colors hover:bg-muted/50",onClick:()=>{Fe(le)},type:"button",children:[n("div",{className:"flex min-w-0 flex-1 items-center gap-3",children:[t(tr,{level:me}),t("span",{className:"max-w-[300px] truncate font-mono text-sm lg:max-w-[500px]",children:f.normalizedSql})]}),n("div",{className:"flex shrink-0 items-center gap-4",children:[n("div",{className:"text-right",children:[t("div",{className:"text-sm font-medium",children:Le(f.totalDurationMs)}),t("div",{className:"text-xs text-muted-foreground",children:r("total")})]}),n("div",{className:"text-right",children:[t("div",{className:"text-sm font-medium",children:Le(f.avgDurationMs)}),t("div",{className:"text-xs text-muted-foreground",children:r("avg")})]}),f.p95DurationMs!==void 0&&n("div",{className:"text-right",children:[t("div",{className:"text-sm font-medium",children:Le(f.p95DurationMs)}),t("div",{className:"text-xs text-muted-foreground",children:r("p95")})]}),n("div",{className:"text-right",children:[t("div",{className:"text-sm font-medium",children:Je(f.execCount)}),t("div",{className:"text-xs text-muted-foreground",children:r("calls")})]})]})]}),E&&n("div",{className:"space-y-3 border-t bg-muted/30 p-4",children:[n("div",{children:[t("p",{className:"mb-2 text-sm font-medium",children:r("Full statement")}),t("pre",{className:"overflow-x-auto rounded-md bg-muted p-3 font-mono text-sm whitespace-pre-wrap break-all",children:f.normalizedSql})]}),n("div",{className:"grid grid-cols-2 gap-4 text-sm md:grid-cols-4",children:[f.p50DurationMs!==void 0&&n("div",{children:[t("span",{className:"text-muted-foreground",children:r("p50")}),t("span",{className:"block font-medium tabular-nums",children:Le(f.p50DurationMs)})]}),n("div",{children:[t("span",{className:"text-muted-foreground",children:r("Exec count")}),t("span",{className:"block font-medium tabular-nums",children:Je(f.execCount)})]}),n("div",{children:[t("span",{className:"text-muted-foreground",children:r("Total time")}),t("span",{className:"block font-medium tabular-nums",children:Le(f.totalDurationMs)})]}),n("div",{children:[t("span",{className:"text-muted-foreground",children:r("Rows read")}),t("span",{className:"block font-medium tabular-nums",children:Je(f.rowsRead)})]}),n("div",{children:[t("span",{className:"text-muted-foreground",children:r("Rows written")}),t("span",{className:"block font-medium tabular-nums",children:Je(f.rowsWritten)})]})]})]})]},le)},e[142]=g,e[143]=r,e[144]=Ee):Ee=e[144],k=A.map(Ee)}e[2]=g,e[3]=l,e[4]=a,e[5]=r,e[6]=h,e[7]=m,e[8]=b,e[9]=O,e[10]=k,e[11]=C,e[12]=R,e[13]=o,e[14]=y,e[15]=$}else h=e[6],m=e[7],b=e[8],O=e[9],k=e[10],C=e[11],R=e[12],o=e[13],y=e[14],$=e[15];if(b!==Symbol.for("react.early_return_sentinel"))return b;let T;e[145]!==O||e[146]!==k?(T=t("div",{className:O,children:k}),e[145]=O,e[146]=k,e[147]=T):T=e[147];let D;e[148]!==h||e[149]!==T?(D=t(h,{children:T}),e[148]=h,e[149]=T,e[150]=D):D=e[150];let _;e[151]!==m||e[152]!==D||e[153]!==C?(_=n(m,{children:[C,D]}),e[151]=m,e[152]=D,e[153]=C,e[154]=_):_=e[154];let N;return e[155]!==_||e[156]!==R||e[157]!==o||e[158]!==y||e[159]!==$?(N=n("div",{className:R,"data-testid":o,children:[y,$,_]}),e[155]=_,e[156]=R,e[157]=o,e[158]=y,e[159]=$,e[160]=N):N=e[160],N};function sr(s){return We(s.avgDurationMs)==="critical"}function lr(s){return We(s.avgDurationMs)==="warning"}function nr(s){return We(s.avgDurationMs)==="good"}const ir=["1m","5m","15m","1h"],or=s=>new Date(s).toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"}),dr=s=>s.map(e=>({avg:Math.round(e.avgDurationMs*100)/100,execs:e.execCount,label:or(e.bucketMs)})),cr=({shardKey:s=""})=>{const e=Ae(),[l,r]=ue("15m"),a=He(Oe.getQueryInsights,{range:l},{live:!0,shardKey:s}).data,u=dr(a?.buckets??[]);return n("div",{className:"flex flex-col gap-4","data-testid":"qi-range",children:[n("div",{className:"flex flex-wrap items-center gap-2",children:[t("div",{className:"flex gap-1 rounded-lg border border-border p-0.5","data-testid":"qi-ranges",role:"group",children:ir.map(c=>t("button",{"aria-pressed":c===l,className:jt("rounded px-2 py-1 text-xs outline-none transition-colors hover:bg-accent focus-visible:bg-accent",c===l&&"bg-accent font-medium text-foreground"),"data-testid":`qi-range-${c}`,onClick:()=>{r(c)},type:"button",children:c},c))}),a?.capped===!0&&t(et,{"data-testid":"qi-capped",variant:"secondary",children:e("showing a capped set")})]}),u.length===0?t(Et,{description:e("Statements executed in the selected window appear here, with throughput and latency over time."),testId:"qi-empty",title:e("No queries in this window.")}):n("div",{className:"grid gap-4 lg:grid-cols-2",children:[n("figure",{className:"rounded-xl border border-border p-3","data-testid":"qi-throughput",children:[t("figcaption",{className:"mb-2 text-xs font-medium text-muted-foreground",children:e("Throughput")}),t(st,{height:140,width:"100%",children:n(Rt,{data:u,children:[t(lt,{strokeDasharray:"3 3",vertical:!1}),t(nt,{dataKey:"label",fontSize:10,tickLine:!1}),t(it,{allowDecimals:!1,fontSize:10,tickLine:!1,width:32}),t(ot,{}),t(At,{dataKey:"execs",fill:"var(--color-primary)",fillOpacity:.15,stroke:"var(--color-primary)",type:"monotone"})]})})]}),n("figure",{className:"rounded-xl border border-border p-3","data-testid":"qi-latency",children:[t("figcaption",{className:"mb-2 text-xs font-medium text-muted-foreground",children:e("Mean latency (ms)")}),t(st,{height:140,width:"100%",children:n(zt,{data:u,children:[t(lt,{strokeDasharray:"3 3",vertical:!1}),t(nt,{dataKey:"label",fontSize:10,tickLine:!1}),t(it,{fontSize:10,tickLine:!1,width:32}),t(ot,{}),t(Kt,{dataKey:"avg",dot:!1,stroke:"var(--color-destructive)",type:"monotone"})]})})]})]}),t(ar,{queryStats:a?.entries??[]})]})},mr=_t(Oe.getMetrics),ur=s=>{const e=Math.floor(s/1e3),l=Math.floor(e/3600),r=Math.floor(e%3600/60),a=e%60;return l>0?`${l.toString()}h ${r.toString()}m`:r>0?`${r.toString()}m ${a.toString()}s`:`${a.toString()}s`},hr=(s,e)=>s?e:"overview",gr=(s,e)=>{const l=s+e;return l===0?"—":`${(s/l*100).toFixed(1)}%`},ne=s=>{const e=Re(16),{chart:l,footer:r,label:a,testId:u,value:c}=s;let g;e[0]!==a?(g=t("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:a}),e[0]=a,e[1]=g):g=e[1];let p;e[2]!==u||e[3]!==c?(p=t("span",{className:"truncate text-2xl font-semibold tabular-nums text-foreground","data-testid":u,children:c}),e[2]=u,e[3]=c,e[4]=p):p=e[4];let x;e[5]!==l||e[6]!==p?(x=n("div",{className:"flex items-center justify-between gap-3",children:[p,l]}),e[5]=l,e[6]=p,e[7]=x):x=e[7];let v;e[8]!==g||e[9]!==x?(v=n("div",{className:"flex flex-col gap-2.5 p-4",children:[g,x]}),e[8]=g,e[9]=x,e[10]=v):v=e[10];let h;e[11]!==r?(h=r!=null&&t("div",{className:"border-t border-border bg-muted/50 px-4 py-2.5 text-[11px] text-muted-foreground",children:r}),e[11]=r,e[12]=h):h=e[12];let m;return e[13]!==v||e[14]!==h?(m=n(he,{className:"justify-between gap-0 py-0",children:[v,h]}),e[13]=v,e[14]=h,e[15]=m):m=e[15],m},dt=s=>s<=0?"—":s<1?`${(s*1e3).toFixed(0)}μs`:s<1e3?`${s.toFixed(1)}ms`:`${(s/1e3).toFixed(2)}s`,jr=({initialShardKey:s})=>{const e=pt(),l=Ae(),r=xt(),[a,u]=ue(s??""),[c,g]=ue("overview"),[p,x]=ue([]),v=Ge(null),h=Ge(null),m=Ge(!0);tt(()=>(m.current=!0,()=>{m.current=!1}),[]);const b=wt(a.trim(),400),O=d=>{Ct({shardKey:b,traceId:d}),at(r({to:"/traces"}))},{data:k,error:C,liveError:R}=He(Oe.getMetrics,{},{live:!0,shardKey:b}),o=k??null;tt(()=>{if(k===void 0)return;Mt(b);const d=k,K=v.current,w=h.current!==null&&h.current!==d.shard;if(h.current=d.shard,v.current=d.requests,w){x([]);return}K!==null&&d.requests>=K&&x(S=>[...S,d.requests-K].slice(-30))},[k,b]);const[y,$]=ue(null),[T,D]=ue(!1),_=async()=>{D(!0);const d=Ot(a,It());try{const K=await Promise.all(d.map(async w=>{try{const S=await e.query(mr,{},kt(w));return{error:null,metrics:S,shard:w===""?S.shard:w}}catch(S){return{error:qt(S),metrics:null,shard:w===""?"__root__":w}}}));m.current&&$(K)}finally{m.current&&D(!1)}},N=y===null?null:Dt(y),A=o===null||o.requests===0?"—":`${(o.errors/o.requests*100).toFixed(1)}%`,j=p.length>0?p.at(-1):0,z=o?Ft(o):{p90:0,p95:0},M=bt(()=>{if(!o||!("queryStats"in o))return;const d=o.queryStats;if(!(!d||!Array.isArray(d)))return Lt(d)},[o]),q=hr(M!==void 0,c),oe=()=>{at(_())},de=()=>{$(null)},ce=()=>{g("overview")},Fe=()=>{g("query-insights")};return n("div",{className:"flex flex-col gap-4","data-testid":"lunora-metrics",children:[n("div",{className:"flex flex-wrap items-center gap-2",children:[t(yt,{onChange:u,testId:"mt-shard-input",value:a}),t(vt,{message:R,prefix:"mt"}),t(rt,{"data-testid":"mt-aggregate",disabled:T,onClick:oe,size:"sm",type:"button",variant:"secondary",children:l(T?"Aggregating…":"All shards")}),y!==null&&t(rt,{"data-testid":"mt-aggregate-clear",onClick:de,size:"sm",type:"button",variant:"ghost",children:l("Hide")}),t("a",{className:"text-sm text-primary underline-offset-4 hover:underline","data-testid":"mt-cf-link",href:St,rel:"noreferrer",target:"_blank",children:l("Open in Cloudflare")})]}),C!==null&&t("p",{className:"text-sm text-destructive","data-testid":"mt-error",role:"alert",children:C}),M!==void 0&&n("div",{className:"flex gap-2 border-b","data-testid":"mt-tabs",children:[t("button",{className:`pb-2 text-sm font-medium transition-colors ${q==="overview"?"border-b-2 border-primary text-foreground":"text-muted-foreground hover:text-foreground"}`,"data-testid":"mt-tab-overview",onClick:ce,type:"button",children:l("Overview")}),n("button",{className:`pb-2 text-sm font-medium transition-colors ${q==="query-insights"?"border-b-2 border-primary text-foreground":"text-muted-foreground hover:text-foreground"}`,"data-testid":"mt-tab-query-insights",onClick:Fe,type:"button",children:[l("Query insights"),M.length>0&&t("span",{className:"ml-1.5 rounded-full bg-primary/10 px-1.5 py-0.5 text-xs text-primary",children:M.length})]})]}),q==="query-insights"&&M!==void 0&&t(cr,{shardKey:b}),q==="overview"&&o!==null&&n("dl",{className:"grid gap-3 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4","data-testid":"mt-stats",children:[t(ne,{chart:p.length>=2?t(ht,{ariaLabel:l("Requests per interval over time"),className:"h-7 w-24 text-foreground",series:p,testId:"mt-sparkline"}):void 0,footer:p.length>=2?n(Ye,{children:[t("span",{className:"font-semibold text-foreground",children:`+${j.toLocaleString()}`})," ",l("last interval")]}):t("span",{"data-testid":"mt-sparkline-empty",children:l("collecting samples…")}),label:l("Requests"),testId:"mt-requests",value:o.requests}),t(ne,{footer:l("{rate} error rate",{rate:A}),label:l("Errors"),testId:"mt-errors",value:n(Ye,{children:[o.errors," (",A,")"]})}),t(ne,{footer:z.p90>0?`P90 ${dt(z.p90)}`:void 0,label:l("P95 latency"),testId:"mt-p95",value:z.p95>0?dt(z.p95):"—"}),t(ne,{footer:o.cache===null?void 0:`${o.cache.entries.toLocaleString()} ${l("cache entries")}`,label:l("Database size"),testId:"mt-db-size",value:Xe(o.databaseSize)}),t(ne,{label:l("Shard"),testId:"mt-shard",value:o.shard}),t(ne,{label:l("Uptime"),testId:"mt-uptime",value:ur(o.uptimeMs)}),t(ne,{label:l("Cache hit rate"),testId:"mt-cache",value:o.cache===null?l("no cache configured"):l("{rate} ({count} entries)",{count:o.cache.entries,rate:gr(o.cache.hits,o.cache.misses)})})]}),q==="overview"&&o===null&&null,q==="overview"&&t(er,{onOpenTrace:O,shardKey:b}),q==="overview"&&N!==null&&y!==null&&n("div",{className:"flex flex-col gap-4","data-testid":"mt-aggregate-view",children:[n("dl",{className:"grid gap-3 sm:grid-cols-2 lg:grid-cols-3","data-testid":"mt-aggregate-stats",children:[t(ne,{label:l("Shards"),testId:"mt-agg-shards",value:N.failed>0?l("{reachable} reachable, {failed} unreachable",{failed:N.failed,reachable:N.reachable}):l("{reachable} reachable",{reachable:N.reachable})}),t(ne,{label:l("Total requests"),testId:"mt-agg-requests",value:N.totalRequests}),t(ne,{label:l("Total errors"),testId:"mt-agg-errors",value:N.totalErrors}),t(ne,{label:l("Total database size"),testId:"mt-agg-db-size",value:Xe(N.totalDatabaseSize)}),t(ne,{label:l("Combined cache hit rate"),testId:"mt-agg-cache",value:N.hitRate===null?l("no cache configured"):`${(N.hitRate*100).toFixed(1)}%`})]}),t(he,{className:"overflow-hidden py-0",children:t(ge,{className:"px-0",children:n(mt,{"data-testid":"mt-agg-table",children:[t(ct,{children:n(Be,{children:[t(ie,{children:l("shard")}),t(ie,{children:l("requests")}),t(ie,{children:l("errors")}),t(ie,{children:l("db size")})]})}),t(ut,{children:y.map(d=>n(Be,{"data-testid":`mt-agg-row-${d.shard}`,children:[t(se,{children:d.shard}),d.metrics===null?t(se,{className:"text-destructive",colSpan:3,children:d.error??l("unreachable")}):n(Ye,{children:[t(se,{className:"tabular-nums",children:d.metrics.requests}),t(se,{className:"tabular-nums",children:d.metrics.errors}),t(se,{className:"tabular-nums",children:Xe(d.metrics.databaseSize)})]})]},d.shard))})]})})})]})]})};export{jr as MetricsPanel};
1
+ import{useLunora as pt}from"@lunora/react";import{useNavigate as xt}from"@tanstack/react-router";import{useState as he,useRef as We,useEffect as tt,useMemo as bt}from"react";import{L as vt}from"../packem_shared/live-status-CmuRLFKf.js";import{ShardInput as yt}from"../packem_shared/ShardInput-BVn2iCU0.js";import{u as rt}from"../packem_shared/button-BkCrNcAs.js";import{N as Je}from"../packem_shared/use-admin-query-QJ-ibl5u.js";import Nt from"../packem_shared/useDebounced-Ihdiid_k.js";import{useT as pe}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as ze}from"../packem_shared/ADMIN_FUNCTIONS-CZESgd10.js";import{c as St}from"../packem_shared/cf-links-Dmg86v1D.js";import{l as $t,k as Ye,f as at,d as wt,b as qt,g as kt}from"../packem_shared/internal-BSIsQVC6.js";import{r as Mt,l as _t}from"../packem_shared/shard-history-DMEW5VBE.js";import{w as It}from"../packem_shared/trace-handoff-Dw7mwjxu.js";import{c as Le}from"react/compiler-runtime";import{f as Ct}from"../packem_shared/log-fields-CoL3hsIQ.js";import{g as et}from"../packem_shared/badge-BbuuAio7.js";import{c as ge,u as fe,n as Pe,f as Qe,m as Rt}from"../packem_shared/card-CIDGUN6K.js";import{p as de,d as dt,m as He,u as oe,n as mt,f as ut}from"../packem_shared/table-DdJBrClo.js";import{S as ht}from"../packem_shared/sparkline-CgjeUU2I.js";import{jsx as t,jsxs as o,Fragment as Ve}from"react/jsx-runtime";import{aggregateMetrics as Dt,computeLatencyPercentiles as Ft,enrichQueryStats as Tt,shardsToAggregate as Lt}from"../packem_shared/aggregateMetrics-BNfajLa2.js";import{g as me}from"../packem_shared/stat-card-fm_TF1mo.js";import{ResponsiveContainer as lt,AreaChart as Ot,CartesianGrid as st,XAxis as nt,YAxis as it,Tooltip as ot,Area as zt,LineChart as At,Line as Et}from"recharts";import{E as Kt}from"../packem_shared/empty-state-Cg7t_8qu.js";import{c as jt}from"../packem_shared/utils-bhneXptQ.js";import{N as Pt,y as Qt,k as Ue,_ as Ut,w as Bt}from"../packem_shared/select-Bul-DeII.js";const Jt=(l,e)=>l<e?-1:l>e?1:0,Ze=l=>{if(l===void 0)return"null";if(typeof l=="bigint")throw new TypeError("stableStringify: cannot use a bigint in a stable JSON cache key — pass it as a string, or use stableWireKey");if(l===null||typeof l!="object")return JSON.stringify(l);if(Array.isArray(l))return`[${l.map(d=>Ze(d)).join(",")}]`;const e=Object.getPrototypeOf(l);if(e!==null&&e!==Object.prototype){const d=l.constructor?.name??"value";throw new TypeError(`stableStringify: cannot use a ${d} in a stable JSON cache key — only plain objects, arrays, and JSON primitives are supported (wire-typed values key via stableWireKey)`)}const s=l,a=Object.keys(s).toSorted(Jt),r=[];for(const d of a){const i=s[d];i!==void 0&&r.push(`${JSON.stringify(d)}:${Ze(i)}`)}return`{${r.join(",")}}`},gt=(l,e,s)=>`${l}:${e}:${Ze(s??{})}`,ft=(l,e)=>l==="gauge"?e.last:l==="histogram"?e.sum/Math.max(1,e.count):e.sum,Ht=(l,e)=>ft(l,e),Gt=l=>ft(l.kind,l),Xe=l=>Number.isInteger(l)?l.toLocaleString():l.toLocaleString(void 0,{maximumFractionDigits:2}),Wt=l=>Array.isArray(l?.series)?l.series:[],Xt="FUNCTION_NOT_FOUND",Yt=l=>{const e=new Map;if(!Array.isArray(l?.series))return e;for(const s of l.series)e.set(gt(s.kind,s.name,s.attributes),s.points);return e},Vt={counter:"secondary",gauge:"default",histogram:"outline"},Zt=l=>{const e=Le(18),{name:s,onOpenTrace:a,traceId:r}=l,d=pe();if(r===void 0){let u;return e[0]===Symbol.for("react.memo_cache_sentinel")?(u=t("span",{className:"text-muted-foreground",children:"—"}),e[0]=u):u=e[0],u}let i;e[1]!==r?(i=r.slice(0,8),e[1]=r,e[2]=i):i=e[2];const n=i;if(a===void 0){const u=`mt-instrument-trace-${s}`;let m;return e[3]!==n||e[4]!==u||e[5]!==r?(m=t("span",{className:"text-muted-foreground","data-testid":u,title:r,children:n}),e[3]=n,e[4]=u,e[5]=r,e[6]=m):m=e[6],m}const S=`mt-instrument-trace-${s}`;let x;e[7]!==a||e[8]!==r?(x=()=>{a(r)},e[7]=a,e[8]=r,e[9]=x):x=e[9];let $;e[10]!==d||e[11]!==r?($=d("Open the exemplar trace {trace}",{trace:r}),e[10]=d,e[11]=r,e[12]=$):$=e[12];let f;return e[13]!==n||e[14]!==S||e[15]!==x||e[16]!==$?(f=t("button",{className:"text-primary underline-offset-4 hover:underline","data-testid":S,onClick:x,title:$,type:"button",children:n}),e[13]=n,e[14]=S,e[15]=x,e[16]=$,e[17]=f):f=e[17],f},er=l=>{const e=Le(105),{onOpenTrace:s,shardKey:a}=l,r=pe();let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d={},e[0]=d):d=e[0];let i;e[1]!==a?(i={live:!0,shardKey:a},e[1]=a,e[2]=i):i=e[2];const{data:n,error:S,errorSource:x}=Je(ze.getMetricSeries,d,i);let $;e[3]===Symbol.for("react.memo_cache_sentinel")?($={},e[3]=$):$=e[3];let f;e[4]!==a?(f={live:!0,shardKey:a},e[4]=a,e[5]=f):f=e[5];const{data:u}=Je(ze.getMetricHistory,$,f);let m,M,b,w,_,c,g,p,q,k,y,I,C;if(e[6]!==n||e[7]!==S||e[8]!==x||e[9]!==u||e[10]!==s||e[11]!==r){p=Symbol.for("react.early_return_sentinel");e:{const z=Wt(n),E=$t(x)===Xt;if(S!==null&&!E){let h;e[25]!==r?(h=r("Instruments"),e[25]=r,e[26]=h):h=e[26];let K;e[27]!==h?(K=t("h3",{className:"text-sm font-semibold text-foreground",children:h}),e[27]=h,e[28]=K):K=e[28];let j;e[29]!==S||e[30]!==r?(j=r("Instruments unavailable: {error}",{error:S}),e[29]=S,e[30]=r,e[31]=j):j=e[31];let P;e[32]!==j?(P=t("span",{className:"text-xs text-muted-foreground","data-testid":"mt-instruments-error",role:"status",children:j}),e[32]=j,e[33]=P):P=e[33];let ie;e[34]!==K||e[35]!==P?(ie=o("section",{className:"flex flex-col gap-2","data-testid":"mt-instruments",children:[K,P]}),e[34]=K,e[35]=P,e[36]=ie):ie=e[36],p=ie;break e}if(z.length===0){p=null;break e}const Q=Yt(u);let L;e[37]!==r?(L=h=>r(h==="counter"?"Counter":h==="gauge"?"Gauge":"Histogram"),e[37]=r,e[38]=L):L=e[38];const U=L;_="flex flex-col gap-2",c="mt-instruments";let O;e[39]!==r?(O=r("Instruments"),e[39]=r,e[40]=O):O=e[40],e[41]!==O?(g=t("h3",{className:"text-sm font-semibold text-foreground",children:O}),e[41]=O,e[42]=g):g=e[42],w=ge,C="overflow-hidden py-0",b=fe,I="px-0",M=mt,k="mt-instruments-table";let A;e[43]!==r?(A=r("name"),e[43]=r,e[44]=A):A=e[44];let J;e[45]!==A?(J=t(de,{children:A}),e[45]=A,e[46]=J):J=e[46];let H;e[47]!==r?(H=r("kind"),e[47]=r,e[48]=H):H=e[48];let G;e[49]!==H?(G=t(de,{children:H}),e[49]=H,e[50]=G):G=e[50];let W;e[51]!==r?(W=r("value"),e[51]=r,e[52]=W):W=e[52];let X;e[53]!==W?(X=t(de,{className:"text-right",children:W}),e[53]=W,e[54]=X):X=e[54];let Y;e[55]!==r?(Y=r("count"),e[55]=r,e[56]=Y):Y=e[56];let V;e[57]!==Y?(V=t(de,{className:"text-right",children:Y}),e[57]=Y,e[58]=V):V=e[58];let Z;e[59]!==r?(Z=r("range"),e[59]=r,e[60]=Z):Z=e[60];let ee;e[61]!==Z?(ee=t(de,{className:"text-right",children:Z}),e[61]=Z,e[62]=ee):ee=e[62];let te;e[63]!==r?(te=r("trend"),e[63]=r,e[64]=te):te=e[64];let re;e[65]!==te?(re=t(de,{children:te}),e[65]=te,e[66]=re):re=e[66];let ae;e[67]!==r?(ae=r("trace"),e[67]=r,e[68]=ae):ae=e[68];let le;e[69]!==ae?(le=t(de,{children:ae}),e[69]=ae,e[70]=le):le=e[70];let se;e[71]!==r?(se=r("dimensions"),e[71]=r,e[72]=se):se=e[72];let ne;e[73]!==se?(ne=t(de,{children:se}),e[73]=se,e[74]=ne):ne=e[74],e[75]!==J||e[76]!==G||e[77]!==X||e[78]!==V||e[79]!==ee||e[80]!==re||e[81]!==le||e[82]!==ne?(y=t(dt,{children:o(He,{children:[J,G,X,V,ee,re,le,ne]})}),e[75]=J,e[76]=G,e[77]=X,e[78]=V,e[79]=ee,e[80]=re,e[81]=le,e[82]=ne,e[83]=y):y=e[83],m=ut,q=z.map(h=>{const K=Ct(h.attributes),j=gt(h.kind,h.name,h.attributes),P=(Q.get(j)??[]).map(ie=>Ht(h.kind,ie));return o(He,{"data-testid":`mt-instrument-${h.name}`,children:[t(oe,{className:"font-mono text-xs",title:h.functionPath,children:h.name}),t(oe,{children:t(et,{variant:Vt[h.kind],children:U(h.kind)})}),t(oe,{className:"text-right font-mono tabular-nums","data-testid":`mt-instrument-value-${h.name}`,children:Xe(Gt(h))}),t(oe,{className:"text-right tabular-nums text-muted-foreground",children:h.count.toLocaleString()}),t(oe,{className:"text-right font-mono text-xs tabular-nums text-muted-foreground",children:h.min===h.max?"—":`${Xe(h.min)}–${Xe(h.max)}`}),t(oe,{children:P.length>=2?t(ht,{ariaLabel:r("{name} trend",{name:h.name}),className:"h-6 w-24 text-foreground",series:P,testId:`mt-instrument-trend-${h.name}`}):t("span",{className:"text-xs text-muted-foreground",children:"—"})}),t(oe,{className:"font-mono text-xs",children:t(Zt,{name:h.name,onOpenTrace:s,traceId:h.exemplarTraceId})}),t(oe,{className:"max-w-64 truncate font-mono text-xs text-muted-foreground",title:K,children:K===""?"—":K})]},j)})}e[6]=n,e[7]=S,e[8]=x,e[9]=u,e[10]=s,e[11]=r,e[12]=m,e[13]=M,e[14]=b,e[15]=w,e[16]=_,e[17]=c,e[18]=g,e[19]=p,e[20]=q,e[21]=k,e[22]=y,e[23]=I,e[24]=C}else m=e[12],M=e[13],b=e[14],w=e[15],_=e[16],c=e[17],g=e[18],p=e[19],q=e[20],k=e[21],y=e[22],I=e[23],C=e[24];if(p!==Symbol.for("react.early_return_sentinel"))return p;let R;e[84]!==m||e[85]!==q?(R=t(m,{children:q}),e[84]=m,e[85]=q,e[86]=R):R=e[86];let D;e[87]!==M||e[88]!==R||e[89]!==k||e[90]!==y?(D=o(M,{"data-testid":k,children:[y,R]}),e[87]=M,e[88]=R,e[89]=k,e[90]=y,e[91]=D):D=e[91];let N;e[92]!==b||e[93]!==D||e[94]!==I?(N=t(b,{className:I,children:D}),e[92]=b,e[93]=D,e[94]=I,e[95]=N):N=e[95];let v;e[96]!==w||e[97]!==N||e[98]!==C?(v=t(w,{className:C,children:N}),e[96]=w,e[97]=N,e[98]=C,e[99]=v):v=e[99];let T;return e[100]!==_||e[101]!==c||e[102]!==g||e[103]!==v?(T=o("section",{className:_,"data-testid":c,children:[g,v]}),e[100]=_,e[101]=c,e[102]=g,e[103]=v,e[104]=T):T=e[104],T},tr=l=>{const e=Le(74),{aggregate:s,shardResults:a}=l,r=pe();let d;e[0]!==r?(d=r("Shards"),e[0]=r,e[1]=d):d=e[1];let i;e[2]!==s.failed||e[3]!==s.reachable||e[4]!==r?(i=s.failed>0?r("{reachable} reachable, {failed} unreachable",{failed:s.failed,reachable:s.reachable}):r("{reachable} reachable",{reachable:s.reachable}),e[2]=s.failed,e[3]=s.reachable,e[4]=r,e[5]=i):i=e[5];let n;e[6]!==d||e[7]!==i?(n=t(me,{label:d,testId:"mt-agg-shards",value:i}),e[6]=d,e[7]=i,e[8]=n):n=e[8];let S;e[9]!==r?(S=r("Total requests"),e[9]=r,e[10]=S):S=e[10];let x;e[11]!==s.totalRequests||e[12]!==S?(x=t(me,{label:S,testId:"mt-agg-requests",value:s.totalRequests}),e[11]=s.totalRequests,e[12]=S,e[13]=x):x=e[13];let $;e[14]!==r?($=r("Total errors"),e[14]=r,e[15]=$):$=e[15];let f;e[16]!==s.totalErrors||e[17]!==$?(f=t(me,{label:$,testId:"mt-agg-errors",value:s.totalErrors}),e[16]=s.totalErrors,e[17]=$,e[18]=f):f=e[18];let u;e[19]!==r?(u=r("Total database size"),e[19]=r,e[20]=u):u=e[20];let m;e[21]!==s.totalDatabaseSize?(m=Ye(s.totalDatabaseSize),e[21]=s.totalDatabaseSize,e[22]=m):m=e[22];let M;e[23]!==u||e[24]!==m?(M=t(me,{label:u,testId:"mt-agg-db-size",value:m}),e[23]=u,e[24]=m,e[25]=M):M=e[25];let b;e[26]!==r?(b=r("Combined cache hit rate"),e[26]=r,e[27]=b):b=e[27];let w;e[28]!==s.hitRate||e[29]!==r?(w=s.hitRate===null?r("no cache configured"):`${(s.hitRate*100).toFixed(1)}%`,e[28]=s.hitRate,e[29]=r,e[30]=w):w=e[30];let _;e[31]!==b||e[32]!==w?(_=t(me,{label:b,testId:"mt-agg-cache",value:w}),e[31]=b,e[32]=w,e[33]=_):_=e[33];let c;e[34]!==M||e[35]!==_||e[36]!==n||e[37]!==x||e[38]!==f?(c=o("dl",{className:"grid gap-3 sm:grid-cols-2 lg:grid-cols-3","data-testid":"mt-aggregate-stats",children:[n,x,f,M,_]}),e[34]=M,e[35]=_,e[36]=n,e[37]=x,e[38]=f,e[39]=c):c=e[39];let g;e[40]!==r?(g=r("shard"),e[40]=r,e[41]=g):g=e[41];let p;e[42]!==g?(p=t(de,{children:g}),e[42]=g,e[43]=p):p=e[43];let q;e[44]!==r?(q=r("requests"),e[44]=r,e[45]=q):q=e[45];let k;e[46]!==q?(k=t(de,{children:q}),e[46]=q,e[47]=k):k=e[47];let y;e[48]!==r?(y=r("errors"),e[48]=r,e[49]=y):y=e[49];let I;e[50]!==y?(I=t(de,{children:y}),e[50]=y,e[51]=I):I=e[51];let C;e[52]!==r?(C=r("db size"),e[52]=r,e[53]=C):C=e[53];let R;e[54]!==C?(R=t(de,{children:C}),e[54]=C,e[55]=R):R=e[55];let D;e[56]!==p||e[57]!==k||e[58]!==I||e[59]!==R?(D=t(dt,{children:o(He,{children:[p,k,I,R]})}),e[56]=p,e[57]=k,e[58]=I,e[59]=R,e[60]=D):D=e[60];let N;if(e[61]!==a||e[62]!==r){let E;e[64]!==r?(E=Q=>o(He,{"data-testid":`mt-agg-row-${Q.shard}`,children:[t(oe,{children:Q.shard}),Q.metrics===null?t(oe,{className:"text-destructive",colSpan:3,children:Q.error??r("unreachable")}):o(Ve,{children:[t(oe,{className:"tabular-nums",children:Q.metrics.requests}),t(oe,{className:"tabular-nums",children:Q.metrics.errors}),t(oe,{className:"tabular-nums",children:Ye(Q.metrics.databaseSize)})]})]},Q.shard),e[64]=r,e[65]=E):E=e[65],N=a.map(E),e[61]=a,e[62]=r,e[63]=N}else N=e[63];let v;e[66]!==N?(v=t(ut,{children:N}),e[66]=N,e[67]=v):v=e[67];let T;e[68]!==D||e[69]!==v?(T=t(ge,{className:"overflow-hidden py-0",children:t(fe,{className:"px-0",children:o(mt,{"data-testid":"mt-agg-table",children:[D,v]})})}),e[68]=D,e[69]=v,e[70]=T):T=e[70];let z;return e[71]!==c||e[72]!==T?(z=o("div",{className:"flex flex-col gap-4","data-testid":"mt-aggregate-view",children:[c,T]}),e[71]=c,e[72]=T,e[73]=z):z=e[73],z},rr=l=>{const e=Math.floor(l/1e3),s=Math.floor(e/3600),a=Math.floor(e%3600/60),r=e%60;return s>0?`${s.toString()}h ${a.toString()}m`:a>0?`${a.toString()}m ${r.toString()}s`:`${r.toString()}s`},ar=(l,e)=>{const s=l+e;return s===0?"—":`${(l/s*100).toFixed(1)}%`},ct=l=>l<=0?"—":l<1?`${(l*1e3).toFixed(0)}μs`:l<1e3?`${l.toFixed(1)}ms`:`${(l/1e3).toFixed(2)}s`,lr=l=>{const e=Le(75),{currentDelta:s,errorRate:a,history:r,latencyPercentiles:d,metrics:i}=l,n=pe();let S;e[0]!==r||e[1]!==n?(S=r.length>=2?t(ht,{ariaLabel:n("Requests per interval over time"),className:"h-7 w-24 text-foreground",series:r,testId:"mt-sparkline"}):void 0,e[0]=r,e[1]=n,e[2]=S):S=e[2];let x;e[3]!==s||e[4]!==r.length||e[5]!==n?(x=r.length>=2?o(Ve,{children:[t("span",{className:"font-semibold text-foreground",children:`+${s.toLocaleString()}`})," ",n("last interval")]}):t("span",{"data-testid":"mt-sparkline-empty",children:n("collecting samples…")}),e[3]=s,e[4]=r.length,e[5]=n,e[6]=x):x=e[6];let $;e[7]!==n?($=n("Requests"),e[7]=n,e[8]=$):$=e[8];let f;e[9]!==i.requests||e[10]!==S||e[11]!==x||e[12]!==$?(f=t(me,{chart:S,footer:x,label:$,testId:"mt-requests",value:i.requests}),e[9]=i.requests,e[10]=S,e[11]=x,e[12]=$,e[13]=f):f=e[13];let u;e[14]!==a||e[15]!==n?(u=n("{rate} error rate",{rate:a}),e[14]=a,e[15]=n,e[16]=u):u=e[16];let m;e[17]!==n?(m=n("Errors"),e[17]=n,e[18]=m):m=e[18];let M;e[19]!==a||e[20]!==i.errors?(M=o(Ve,{children:[i.errors," (",a,")"]}),e[19]=a,e[20]=i.errors,e[21]=M):M=e[21];let b;e[22]!==u||e[23]!==m||e[24]!==M?(b=t(me,{footer:u,label:m,testId:"mt-errors",value:M}),e[22]=u,e[23]=m,e[24]=M,e[25]=b):b=e[25];let w;e[26]!==d.p90?(w=d.p90>0?`P90 ${ct(d.p90)}`:void 0,e[26]=d.p90,e[27]=w):w=e[27];let _;e[28]!==n?(_=n("P95 latency"),e[28]=n,e[29]=_):_=e[29];let c;e[30]!==d.p95?(c=d.p95>0?ct(d.p95):"—",e[30]=d.p95,e[31]=c):c=e[31];let g;e[32]!==_||e[33]!==c||e[34]!==w?(g=t(me,{footer:w,label:_,testId:"mt-p95",value:c}),e[32]=_,e[33]=c,e[34]=w,e[35]=g):g=e[35];let p;e[36]!==i.cache||e[37]!==n?(p=i.cache===null?void 0:`${i.cache.entries.toLocaleString()} ${n("cache entries")}`,e[36]=i.cache,e[37]=n,e[38]=p):p=e[38];let q;e[39]!==n?(q=n("Database size"),e[39]=n,e[40]=q):q=e[40];let k;e[41]!==i.databaseSize?(k=Ye(i.databaseSize),e[41]=i.databaseSize,e[42]=k):k=e[42];let y;e[43]!==p||e[44]!==q||e[45]!==k?(y=t(me,{footer:p,label:q,testId:"mt-db-size",value:k}),e[43]=p,e[44]=q,e[45]=k,e[46]=y):y=e[46];let I;e[47]!==n?(I=n("Shard"),e[47]=n,e[48]=I):I=e[48];let C;e[49]!==i.shard||e[50]!==I?(C=t(me,{label:I,testId:"mt-shard",value:i.shard}),e[49]=i.shard,e[50]=I,e[51]=C):C=e[51];let R;e[52]!==n?(R=n("Uptime"),e[52]=n,e[53]=R):R=e[53];let D;e[54]!==i.uptimeMs?(D=rr(i.uptimeMs),e[54]=i.uptimeMs,e[55]=D):D=e[55];let N;e[56]!==R||e[57]!==D?(N=t(me,{label:R,testId:"mt-uptime",value:D}),e[56]=R,e[57]=D,e[58]=N):N=e[58];let v;e[59]!==n?(v=n("Cache hit rate"),e[59]=n,e[60]=v):v=e[60];let T;e[61]!==i.cache||e[62]!==n?(T=i.cache===null?n("no cache configured"):n("{rate} ({count} entries)",{count:i.cache.entries,rate:ar(i.cache.hits,i.cache.misses)}),e[61]=i.cache,e[62]=n,e[63]=T):T=e[63];let z;e[64]!==v||e[65]!==T?(z=t(me,{label:v,testId:"mt-cache",value:T}),e[64]=v,e[65]=T,e[66]=z):z=e[66];let E;return e[67]!==g||e[68]!==y||e[69]!==C||e[70]!==N||e[71]!==z||e[72]!==f||e[73]!==b?(E=o("dl",{className:"grid gap-3 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4","data-testid":"mt-stats",children:[f,b,g,y,C,N,z]}),e[67]=g,e[68]=y,e[69]=C,e[70]=N,e[71]=z,e[72]=f,e[73]=b,e[74]=E):E=e[74],E},Ge=l=>l>=100?"critical":l>=50?"warning":"good",Oe=l=>l<1?`${(l*1e3).toFixed(0)}μs`:l<1e3?`${l.toFixed(1)}ms`:`${(l/1e3).toFixed(2)}s`,Be=l=>l>=1e9?`${(l/1e9).toFixed(1)}B`:l>=1e6?`${(l/1e6).toFixed(1)}M`:l>=1e3?`${(l/1e3).toFixed(1)}K`:l.toLocaleString(),sr=l=>{const e=Le(3),{level:s}=l;if(s==="critical"){let r;return e[0]===Symbol.for("react.memo_cache_sentinel")?(r=t(et,{variant:"destructive",children:"Slow"}),e[0]=r):r=e[0],r}if(s==="warning"){let r;return e[1]===Symbol.for("react.memo_cache_sentinel")?(r=t("span",{className:"inline-flex items-center gap-1 rounded-md border border-transparent bg-warning/10 px-2 py-0.5 text-xs font-medium text-warning",children:"Moderate"}),e[1]=r):r=e[1],r}let a;return e[2]===Symbol.for("react.memo_cache_sentinel")?(a=t("span",{className:"inline-flex items-center gap-1 rounded-md border border-transparent bg-success/10 px-2 py-0.5 text-xs font-medium text-success",children:"Fast"}),e[2]=a):a=e[2],a},nr=(l,e)=>{const s=[...l];return s.sort((a,r)=>{switch(e){case"avgTime":return r.avgDurationMs-a.avgDurationMs;case"execCount":return r.execCount-a.execCount;case"rowsRead":return r.rowsRead-a.rowsRead;default:return r.totalDurationMs-a.totalDurationMs}}),s},ir=l=>{const e=Le(161),{queryStats:s}=l,a=pe(),[r,d]=he("totalTime");let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=new Set,e[0]=i):i=e[0];const[n,S]=he(i);let x;e[1]===Symbol.for("react.memo_cache_sentinel")?(x=C=>{C!==null&&d(C)},e[1]=x):x=e[1];const $=x;let f,u,m,M,b,w,_,c,g,p;if(e[2]!==n||e[3]!==s||e[4]!==r||e[5]!==a){m=Symbol.for("react.early_return_sentinel");e:{const C=nr(s,r);let R;e[16]!==s?(R=s.filter(or),e[16]=s,e[17]=R):R=e[17];const D=R.length;let N;e[18]!==s?(N=s.filter(cr),e[18]=s,e[19]=N):N=e[19];const v=N.length;let T;e[20]!==s?(T=s.filter(dr),e[20]=s,e[21]=T):T=e[21];const z=T.length;let E;e[22]===Symbol.for("react.memo_cache_sentinel")?(E=F=>{S(ce=>{const B=new Set(ce);return B.has(F)?B.delete(F):B.add(F),B})},e[22]=E):E=e[22];const Q=E;if(s.length===0){let F;e[23]!==a?(F=a("No query insights yet"),e[23]=a,e[24]=F):F=e[24];let ce;e[25]!==F?(ce=t("p",{className:"text-lg font-medium","data-testid":"qi-empty",children:F}),e[25]=F,e[26]=ce):ce=e[26];let B;e[27]!==a?(B=a("Query insights appear once statements are executed against this shard."),e[27]=a,e[28]=B):B=e[28];let ue;e[29]!==B?(ue=t("p",{className:"mt-1 text-sm",children:B}),e[29]=B,e[30]=ue):ue=e[30];let je;e[31]!==ce||e[32]!==ue?(je=t(ge,{children:t(fe,{className:"py-12",children:o("div",{className:"text-center text-muted-foreground",children:[ce,ue]})})}),e[31]=ce,e[32]=ue,e[33]=je):je=e[33],m=je;break e}_="space-y-4",c="qi-root";let L;e[34]!==a?(L=a("Critical queries"),e[34]=a,e[35]=L):L=e[35];let U;e[36]!==L?(U=t(Pe,{className:"pb-2",children:t(Qe,{className:"text-sm font-medium",children:L})}),e[36]=L,e[37]=U):U=e[37];let O;e[38]!==D?(O=t("div",{className:"text-2xl font-bold text-destructive","data-testid":"qi-critical",children:D}),e[38]=D,e[39]=O):O=e[39];let A;e[40]!==a?(A=a(">100ms avg execution"),e[40]=a,e[41]=A):A=e[41];let J;e[42]!==A?(J=t("p",{className:"text-xs text-muted-foreground",children:A}),e[42]=A,e[43]=J):J=e[43];let H;e[44]!==O||e[45]!==J?(H=o(fe,{children:[O,J]}),e[44]=O,e[45]=J,e[46]=H):H=e[46];let G;e[47]!==U||e[48]!==H?(G=o(ge,{children:[U,H]}),e[47]=U,e[48]=H,e[49]=G):G=e[49];let W;e[50]!==a?(W=a("Moderate queries"),e[50]=a,e[51]=W):W=e[51];let X;e[52]!==W?(X=t(Pe,{className:"pb-2",children:t(Qe,{className:"text-sm font-medium",children:W})}),e[52]=W,e[53]=X):X=e[53];let Y;e[54]!==v?(Y=t("div",{className:"text-2xl font-bold text-warning","data-testid":"qi-moderate",children:v}),e[54]=v,e[55]=Y):Y=e[55];let V;e[56]!==a?(V=a("50–100ms avg execution"),e[56]=a,e[57]=V):V=e[57];let Z;e[58]!==V?(Z=t("p",{className:"text-xs text-muted-foreground",children:V}),e[58]=V,e[59]=Z):Z=e[59];let ee;e[60]!==Y||e[61]!==Z?(ee=o(fe,{children:[Y,Z]}),e[60]=Y,e[61]=Z,e[62]=ee):ee=e[62];let te;e[63]!==X||e[64]!==ee?(te=o(ge,{children:[X,ee]}),e[63]=X,e[64]=ee,e[65]=te):te=e[65];let re;e[66]!==a?(re=a("Fast queries"),e[66]=a,e[67]=re):re=e[67];let ae;e[68]!==re?(ae=t(Pe,{className:"pb-2",children:t(Qe,{className:"text-sm font-medium",children:re})}),e[68]=re,e[69]=ae):ae=e[69];let le;e[70]!==z?(le=t("div",{className:"text-2xl font-bold text-success","data-testid":"qi-fast",children:z}),e[70]=z,e[71]=le):le=e[71];let se;e[72]!==a?(se=a("<50ms avg execution"),e[72]=a,e[73]=se):se=e[73];let ne;e[74]!==se?(ne=t("p",{className:"text-xs text-muted-foreground",children:se}),e[74]=se,e[75]=ne):ne=e[75];let h;e[76]!==le||e[77]!==ne?(h=o(fe,{children:[le,ne]}),e[76]=le,e[77]=ne,e[78]=h):h=e[78];let K;e[79]!==ae||e[80]!==h?(K=o(ge,{children:[ae,h]}),e[79]=ae,e[80]=h,e[81]=K):K=e[81],e[82]!==G||e[83]!==te||e[84]!==K?(g=o("div",{className:"grid gap-4 md:grid-cols-3",children:[G,te,K]}),e[82]=G,e[83]=te,e[84]=K,e[85]=g):g=e[85];let j;e[86]!==a?(j=a("Query leaderboard"),e[86]=a,e[87]=j):j=e[87];let P;e[88]!==j?(P=t("h3",{className:"text-lg font-semibold",children:j}),e[88]=j,e[89]=P):P=e[89];let ie;e[90]!==r||e[91]!==a?(ie=a("Slow queries sorted by {sortField}",{sortField:a(r)}),e[90]=r,e[91]=a,e[92]=ie):ie=e[92];let xe;e[93]!==ie?(xe=t("p",{className:"text-sm text-muted-foreground",children:ie}),e[93]=ie,e[94]=xe):xe=e[94];let be;e[95]!==P||e[96]!==xe?(be=o("div",{children:[P,xe]}),e[95]=P,e[96]=xe,e[97]=be):be=e[97];let ve;e[98]!==a?(ve=a("Sort by"),e[98]=a,e[99]=ve):ve=e[99];let ye;e[100]!==ve?(ye=t("span",{className:"text-sm text-muted-foreground",children:ve}),e[100]=ve,e[101]=ye):ye=e[101];let Ne;e[102]!==a?(Ne=a("Sort queries by"),e[102]=a,e[103]=Ne):Ne=e[103];let Ae;e[104]===Symbol.for("react.memo_cache_sentinel")?(Ae=t(Pt,{}),e[104]=Ae):Ae=e[104];let Se;e[105]!==Ne?(Se=t(Qt,{"aria-label":Ne,className:"w-[140px]","data-testid":"qi-sort",children:Ae}),e[105]=Ne,e[106]=Se):Se=e[106];let $e;e[107]!==a?($e=a("Total time"),e[107]=a,e[108]=$e):$e=e[108];let we;e[109]!==$e?(we=t(Ue,{value:"totalTime",children:$e}),e[109]=$e,e[110]=we):we=e[110];let qe;e[111]!==a?(qe=a("Avg time"),e[111]=a,e[112]=qe):qe=e[112];let ke;e[113]!==qe?(ke=t(Ue,{value:"avgTime",children:qe}),e[113]=qe,e[114]=ke):ke=e[114];let Me;e[115]!==a?(Me=a("Execution count"),e[115]=a,e[116]=Me):Me=e[116];let _e;e[117]!==Me?(_e=t(Ue,{value:"execCount",children:Me}),e[117]=Me,e[118]=_e):_e=e[118];let Ie;e[119]!==a?(Ie=a("Rows read"),e[119]=a,e[120]=Ie):Ie=e[120];let Ce;e[121]!==Ie?(Ce=t(Ue,{value:"rowsRead",children:Ie}),e[121]=Ie,e[122]=Ce):Ce=e[122];let Re;e[123]!==we||e[124]!==ke||e[125]!==_e||e[126]!==Ce?(Re=o(Ut,{children:[we,ke,_e,Ce]}),e[123]=we,e[124]=ke,e[125]=_e,e[126]=Ce,e[127]=Re):Re=e[127];let De;e[128]!==r||e[129]!==Se||e[130]!==Re?(De=o(Bt,{onValueChange:$,value:r,children:[Se,Re]}),e[128]=r,e[129]=Se,e[130]=Re,e[131]=De):De=e[131];let Fe;e[132]!==ye||e[133]!==De?(Fe=o("div",{className:"flex items-center gap-2",children:[ye,De]}),e[132]=ye,e[133]=De,e[134]=Fe):Fe=e[134],e[135]!==be||e[136]!==Fe?(p=o("div",{className:"flex items-center justify-between",children:[be,Fe]}),e[135]=be,e[136]=Fe,e[137]=p):p=e[137],u=ge;let Te;e[138]!==a?(Te=a("Statements"),e[138]=a,e[139]=Te):Te=e[139];let Ee;e[140]!==Te?(Ee=t(Qe,{children:Te}),e[140]=Te,e[141]=Ee):Ee=e[141],w=o(Pe,{children:[Ee,t(Rt,{children:a("{count} tracked statements",{count:C.length})})]}),f=fe,M="space-y-2";let Ke;e[142]!==n||e[143]!==a?(Ke=F=>{const ce=F.normalizedSql,B=n.has(ce),ue=Ge(F.avgDurationMs);return o("div",{className:"overflow-hidden rounded-lg border","data-testid":"qi-row",children:[o("button",{"aria-expanded":B,className:"flex w-full items-center justify-between p-3 text-left transition-colors hover:bg-muted/50",onClick:()=>{Q(ce)},type:"button",children:[o("div",{className:"flex min-w-0 flex-1 items-center gap-3",children:[t(sr,{level:ue}),t("span",{className:"max-w-[300px] truncate font-mono text-sm lg:max-w-[500px]",children:F.normalizedSql})]}),o("div",{className:"flex shrink-0 items-center gap-4",children:[o("div",{className:"text-right",children:[t("div",{className:"text-sm font-medium",children:Oe(F.totalDurationMs)}),t("div",{className:"text-xs text-muted-foreground",children:a("total")})]}),o("div",{className:"text-right",children:[t("div",{className:"text-sm font-medium",children:Oe(F.avgDurationMs)}),t("div",{className:"text-xs text-muted-foreground",children:a("avg")})]}),F.p95DurationMs!==void 0&&o("div",{className:"text-right",children:[t("div",{className:"text-sm font-medium",children:Oe(F.p95DurationMs)}),t("div",{className:"text-xs text-muted-foreground",children:a("p95")})]}),o("div",{className:"text-right",children:[t("div",{className:"text-sm font-medium",children:Be(F.execCount)}),t("div",{className:"text-xs text-muted-foreground",children:a("calls")})]})]})]}),B&&o("div",{className:"space-y-3 border-t bg-muted/30 p-4",children:[o("div",{children:[t("p",{className:"mb-2 text-sm font-medium",children:a("Full statement")}),t("pre",{className:"overflow-x-auto rounded-md bg-muted p-3 font-mono text-sm whitespace-pre-wrap break-all",children:F.normalizedSql})]}),o("div",{className:"grid grid-cols-2 gap-4 text-sm md:grid-cols-4",children:[F.p50DurationMs!==void 0&&o("div",{children:[t("span",{className:"text-muted-foreground",children:a("p50")}),t("span",{className:"block font-medium tabular-nums",children:Oe(F.p50DurationMs)})]}),o("div",{children:[t("span",{className:"text-muted-foreground",children:a("Exec count")}),t("span",{className:"block font-medium tabular-nums",children:Be(F.execCount)})]}),o("div",{children:[t("span",{className:"text-muted-foreground",children:a("Total time")}),t("span",{className:"block font-medium tabular-nums",children:Oe(F.totalDurationMs)})]}),o("div",{children:[t("span",{className:"text-muted-foreground",children:a("Rows read")}),t("span",{className:"block font-medium tabular-nums",children:Be(F.rowsRead)})]}),o("div",{children:[t("span",{className:"text-muted-foreground",children:a("Rows written")}),t("span",{className:"block font-medium tabular-nums",children:Be(F.rowsWritten)})]})]})]})]},ce)},e[142]=n,e[143]=a,e[144]=Ke):Ke=e[144],b=C.map(Ke)}e[2]=n,e[3]=s,e[4]=r,e[5]=a,e[6]=f,e[7]=u,e[8]=m,e[9]=M,e[10]=b,e[11]=w,e[12]=_,e[13]=c,e[14]=g,e[15]=p}else f=e[6],u=e[7],m=e[8],M=e[9],b=e[10],w=e[11],_=e[12],c=e[13],g=e[14],p=e[15];if(m!==Symbol.for("react.early_return_sentinel"))return m;let q;e[145]!==M||e[146]!==b?(q=t("div",{className:M,children:b}),e[145]=M,e[146]=b,e[147]=q):q=e[147];let k;e[148]!==f||e[149]!==q?(k=t(f,{children:q}),e[148]=f,e[149]=q,e[150]=k):k=e[150];let y;e[151]!==u||e[152]!==k||e[153]!==w?(y=o(u,{children:[w,k]}),e[151]=u,e[152]=k,e[153]=w,e[154]=y):y=e[154];let I;return e[155]!==y||e[156]!==_||e[157]!==c||e[158]!==g||e[159]!==p?(I=o("div",{className:_,"data-testid":c,children:[g,p,y]}),e[155]=y,e[156]=_,e[157]=c,e[158]=g,e[159]=p,e[160]=I):I=e[160],I};function or(l){return Ge(l.avgDurationMs)==="critical"}function cr(l){return Ge(l.avgDurationMs)==="warning"}function dr(l){return Ge(l.avgDurationMs)==="good"}const mr=["1m","5m","15m","1h"],ur=l=>new Date(l).toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"}),hr=l=>l.map(e=>({avg:Math.round(e.avgDurationMs*100)/100,execs:e.execCount,label:ur(e.bucketMs)})),gr=({shardKey:l=""})=>{const e=pe(),[s,a]=he("15m"),r=Je(ze.getQueryInsights,{range:s},{live:!0,shardKey:l}).data,d=hr(r?.buckets??[]);return o("div",{className:"flex flex-col gap-4","data-testid":"qi-range",children:[o("div",{className:"flex flex-wrap items-center gap-2",children:[t("div",{className:"flex gap-1 rounded-lg border border-border p-0.5","data-testid":"qi-ranges",role:"group",children:mr.map(i=>t("button",{"aria-pressed":i===s,className:jt("rounded px-2 py-1 text-xs outline-none transition-colors hover:bg-accent focus-visible:bg-accent",i===s&&"bg-accent font-medium text-foreground"),"data-testid":`qi-range-${i}`,onClick:()=>{a(i)},type:"button",children:i},i))}),r?.capped===!0&&t(et,{"data-testid":"qi-capped",variant:"secondary",children:e("showing a capped set")})]}),d.length===0?t(Kt,{description:e("Statements executed in the selected window appear here, with throughput and latency over time."),testId:"qi-empty",title:e("No queries in this window.")}):o("div",{className:"grid gap-4 lg:grid-cols-2",children:[o("figure",{className:"rounded-xl border border-border p-3","data-testid":"qi-throughput",children:[t("figcaption",{className:"mb-2 text-xs font-medium text-muted-foreground",children:e("Throughput")}),t(lt,{height:140,width:"100%",children:o(Ot,{data:d,children:[t(st,{strokeDasharray:"3 3",vertical:!1}),t(nt,{dataKey:"label",fontSize:10,tickLine:!1}),t(it,{allowDecimals:!1,fontSize:10,tickLine:!1,width:32}),t(ot,{}),t(zt,{dataKey:"execs",fill:"var(--color-primary)",fillOpacity:.15,stroke:"var(--color-primary)",type:"monotone"})]})})]}),o("figure",{className:"rounded-xl border border-border p-3","data-testid":"qi-latency",children:[t("figcaption",{className:"mb-2 text-xs font-medium text-muted-foreground",children:e("Mean latency (ms)")}),t(lt,{height:140,width:"100%",children:o(At,{data:d,children:[t(st,{strokeDasharray:"3 3",vertical:!1}),t(nt,{dataKey:"label",fontSize:10,tickLine:!1}),t(it,{fontSize:10,tickLine:!1,width:32}),t(ot,{}),t(Et,{dataKey:"avg",dot:!1,stroke:"var(--color-destructive)",type:"monotone"})]})})]})]}),t(ir,{queryStats:r?.entries??[]})]})},fr=kt(ze.getMetrics),pr=(l,e)=>l?e:"overview",Ur=({initialShardKey:l})=>{const e=pt(),s=pe(),a=xt(),[r,d]=he(l??""),[i,n]=he("overview"),[S,x]=he([]),$=We(null),f=We(null),u=We(!0);tt(()=>(u.current=!0,()=>{u.current=!1}),[]);const m=Nt(r.trim(),400),M=L=>{It({shardKey:m,traceId:L}),at(a({to:"/traces"}))},{data:b,error:w,liveError:_}=Je(ze.getMetrics,{},{live:!0,shardKey:m}),c=b??null;tt(()=>{if(b===void 0)return;Mt(m);const L=b,U=$.current,O=f.current!==null&&f.current!==L.shard;if(f.current=L.shard,$.current=L.requests,O){x([]);return}U!==null&&L.requests>=U&&x(A=>[...A,L.requests-U].slice(-30))},[b,m]);const[g,p]=he(null),[q,k]=he(!1),y=async()=>{k(!0);const L=Lt(r,_t());try{const U=await Promise.all(L.map(async O=>{try{const A=await e.query(fr,{},wt(O));return{error:null,metrics:A,shard:O===""?A.shard:O}}catch(A){return{error:qt(A),metrics:null,shard:O===""?"__root__":O}}}));u.current&&p(U)}finally{u.current&&k(!1)}},I=g===null?null:Dt(g),C=c===null||c.requests===0?"—":`${(c.errors/c.requests*100).toFixed(1)}%`,R=S.length>0?S.at(-1):0,D=c?Ft(c):{p90:0,p95:0},N=bt(()=>{if(!c||!("queryStats"in c))return;const L=c.queryStats;if(!(!L||!Array.isArray(L)))return Tt(L)},[c]),v=pr(N!==void 0,i),T=()=>{at(y())},z=()=>{p(null)},E=()=>{n("overview")},Q=()=>{n("query-insights")};return o("div",{className:"flex flex-col gap-4","data-testid":"lunora-metrics",children:[o("div",{className:"flex flex-wrap items-center gap-2",children:[t(yt,{onChange:d,testId:"mt-shard-input",value:r}),t(vt,{message:_,prefix:"mt"}),t(rt,{"data-testid":"mt-aggregate",disabled:q,onClick:T,size:"sm",type:"button",variant:"secondary",children:s(q?"Aggregating…":"All shards")}),g!==null&&t(rt,{"data-testid":"mt-aggregate-clear",onClick:z,size:"sm",type:"button",variant:"ghost",children:s("Hide")}),t("a",{className:"text-sm text-primary underline-offset-4 hover:underline","data-testid":"mt-cf-link",href:St,rel:"noreferrer",target:"_blank",children:s("Open in Cloudflare")})]}),w!==null&&t("p",{className:"text-sm text-destructive","data-testid":"mt-error",role:"alert",children:w}),N!==void 0&&o("div",{className:"flex gap-2 border-b","data-testid":"mt-tabs",children:[t("button",{className:`pb-2 text-sm font-medium transition-colors ${v==="overview"?"border-b-2 border-primary text-foreground":"text-muted-foreground hover:text-foreground"}`,"data-testid":"mt-tab-overview",onClick:E,type:"button",children:s("Overview")}),o("button",{className:`pb-2 text-sm font-medium transition-colors ${v==="query-insights"?"border-b-2 border-primary text-foreground":"text-muted-foreground hover:text-foreground"}`,"data-testid":"mt-tab-query-insights",onClick:Q,type:"button",children:[s("Query insights"),N.length>0&&t("span",{className:"ml-1.5 rounded-full bg-primary/10 px-1.5 py-0.5 text-xs text-primary",children:N.length})]})]}),v==="query-insights"&&N!==void 0&&t(gr,{shardKey:m}),v==="overview"&&c!==null&&t(lr,{currentDelta:R,errorRate:C,history:S,latencyPercentiles:D,metrics:c}),v==="overview"&&c===null&&null,v==="overview"&&t(er,{onOpenTrace:M,shardKey:m}),v==="overview"&&I!==null&&g!==null&&t(tr,{aggregate:I,shardResults:g})]})};export{Ur as MetricsPanel};
@@ -1 +1 @@
1
- import{c as W}from"react/compiler-runtime";import{useState as T}from"react";import{E as B}from"../packem_shared/error-alert-t6cpEi0z.js";import{g as _}from"../packem_shared/badge-BbuuAio7.js";import{u as z}from"../packem_shared/button-BkCrNcAs.js";import{c as O,u as U}from"../packem_shared/card-CIDGUN6K.js";import{E as q}from"../packem_shared/empty-state-Cg7t_8qu.js";import{u as G}from"../packem_shared/input-JHu63lTv.js";import{n as J,d as K,m as F,p as h,f as Q,u as f}from"../packem_shared/table-DdJBrClo.js";import{N as X}from"../packem_shared/use-admin-query-QJ-ibl5u.js";import{useT as Y}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as Z}from"../packem_shared/ADMIN_FUNCTIONS-BnD4aovm.js";import{i as ee}from"../packem_shared/internal-BSIsQVC6.js";import{jsx as t,jsxs as x}from"react/jsx-runtime";const te=e=>e==="ok"?"success":e==="failed"?"destructive":e==="expired"?"warning":"secondary",P=e=>e.endpoint??e.id,ve=()=>{const e=W(38),r=Y(),[i,R]=T("all"),[s,V]=T("");let g;e[0]===Symbol.for("react.memo_cache_sentinel")?(g={},e[0]=g):g=e[0];const{data:S,error:o,errorSource:p,isLoading:C,refetch:v}=X(Z.listPushSubscriptions,g);let N;if(e[1]!==S?.subscriptions||e[2]!==o||e[3]!==p||e[4]!==C||e[5]!==i||e[6]!==v||e[7]!==s||e[8]!==r){const A=S?.subscriptions??[],j=s.trim().toLowerCase(),E=A.filter(a=>i!=="all"&&a.kind!==i?!1:j===""?!0:`${P(a)} ${a.userId??""}`.toLowerCase().includes(j));let b;e[10]===Symbol.for("react.memo_cache_sentinel")?(b=a=>{V(a.target.value)},e[10]=b):b=e[10];const D=b;let w;e[11]!==v?(w=()=>{v()},e[11]=v,e[12]=w):w=e[12];const I=w;let y;e[13]===Symbol.for("react.memo_cache_sentinel")?(y=["all","web-push","fcm"],e[13]=y):y=e[13];const H=y;let l;e[14]!==i||e[15]!==r?(l=t("div",{className:"flex items-center gap-1","data-testid":"nt-kind-filter",role:"tablist",children:H.map(a=>t(z,{"aria-selected":i===a,"data-testid":`nt-kind-${a}`,onClick:()=>{R(a)},role:"tab",size:"sm",type:"button",variant:i===a?"secondary":"ghost",children:a==="all"?r("All"):a},a))}),e[14]=i,e[15]=r,e[16]=l):l=e[16];let n;e[17]!==r?(n=r("Filter devices"),e[17]=r,e[18]=n):n=e[18];let c;e[19]!==r?(c=r("filter endpoint, user"),e[19]=r,e[20]=c):c=e[20];let d;e[21]!==s||e[22]!==n||e[23]!==c?(d=t(G,{"aria-label":n,className:"h-8 w-56","data-testid":"nt-search",onChange:D,placeholder:c,value:s}),e[21]=s,e[22]=n,e[23]=c,e[24]=d):d=e[24];let m;e[25]!==r?(m=r("Refresh"),e[25]=r,e[26]=m):m=e[26];let u;e[27]!==I||e[28]!==m?(u=t(z,{className:"ml-auto","data-testid":"nt-refresh",onClick:I,size:"sm",type:"button",variant:"outline",children:m}),e[27]=I,e[28]=m,e[29]=u):u=e[29];const L=A.length>0&&t(_,{"data-testid":"nt-count",variant:"secondary",children:r("{count} devices",{count:A.length})});let $;e[30]!==u||e[31]!==L||e[32]!==l||e[33]!==d?($=x("div",{className:"flex flex-wrap items-center gap-2",children:[l,d,u,L]}),e[30]=u,e[31]=L,e[32]=l,e[33]=d,e[34]=$):$=e[34];let k;e[35]!==o||e[36]!==p?(k=o!==null&&t(B,{error:p,testId:"nt-error"}),e[35]=o,e[36]=p,e[37]=k):k=e[37],N=x("div",{className:"flex flex-col gap-4","data-testid":"lunora-notifications",children:[$,k,o===null&&!C&&E.length===0&&t(q,{description:r("Registered Web Push / FCM devices appear here. Configure lunora/notify.ts with defineNotify({ store }) and register a device with ctx.push.register(...)."),icon:t("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:t("path",{d:"M15 17h5l-1.4-1.4A2 2 0 0 1 18 14.2V11a6 6 0 0 0-4-5.7V5a2 2 0 1 0-4 0v.3A6 6 0 0 0 6 11v3.2a2 2 0 0 1-.6 1.4L4 17h5m6 0v1a3 3 0 1 1-6 0v-1m6 0H9"})}),testId:"nt-empty",title:r("No registered devices.")}),E.length>0&&t(O,{className:"overflow-hidden py-0",children:t(U,{className:"max-h-[30rem] overflow-auto px-0",children:x(J,{"data-testid":"nt-table",children:[t(K,{children:x(F,{children:[t(h,{children:r("kind")}),t(h,{children:r("endpoint")}),t(h,{children:r("user")}),t(h,{children:r("last seen")}),t(h,{children:r("status")}),t(h,{children:r("error")})]})}),t(Q,{children:E.map(a=>{const M=P(a);return x(F,{"data-testid":"nt-row",children:[t(f,{children:t(_,{variant:"outline",children:a.kind})}),t(f,{className:"max-w-[28ch] truncate font-mono text-xs",title:M,children:M}),t(f,{className:"max-w-[16ch] truncate font-mono text-xs",children:a.userId??t("span",{className:"text-muted-foreground",children:"—"})}),t(f,{className:"text-muted-foreground tabular-nums",children:ee(a.lastSeenAt,"—")}),t(f,{children:t(_,{"data-testid":`nt-status-${a.id}`,variant:te(a.lastStatus),children:a.lastStatus??r("n/a")})}),t(f,{className:"max-w-[28ch] truncate font-mono text-xs text-muted-foreground",title:a.lastError??void 0,children:a.lastError??t("span",{className:"text-muted-foreground",children:"—"})})]},a.id)})})]})})})]}),e[1]=S?.subscriptions,e[2]=o,e[3]=p,e[4]=C,e[5]=i,e[6]=v,e[7]=s,e[8]=r,e[9]=N}else N=e[9];return N};export{ve as NotificationsPanel};
1
+ import{c as W}from"react/compiler-runtime";import{useState as T}from"react";import{E as B}from"../packem_shared/error-alert-t6cpEi0z.js";import{g as _}from"../packem_shared/badge-BbuuAio7.js";import{u as z}from"../packem_shared/button-BkCrNcAs.js";import{c as O,u as U}from"../packem_shared/card-CIDGUN6K.js";import{E as q}from"../packem_shared/empty-state-Cg7t_8qu.js";import{u as G}from"../packem_shared/input-JHu63lTv.js";import{n as J,d as K,m as F,p as h,f as Q,u as f}from"../packem_shared/table-DdJBrClo.js";import{N as X}from"../packem_shared/use-admin-query-QJ-ibl5u.js";import{useT as Y}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as Z}from"../packem_shared/ADMIN_FUNCTIONS-CZESgd10.js";import{i as ee}from"../packem_shared/internal-BSIsQVC6.js";import{jsx as t,jsxs as x}from"react/jsx-runtime";const te=e=>e==="ok"?"success":e==="failed"?"destructive":e==="expired"?"warning":"secondary",P=e=>e.endpoint??e.id,ve=()=>{const e=W(38),r=Y(),[i,R]=T("all"),[s,V]=T("");let g;e[0]===Symbol.for("react.memo_cache_sentinel")?(g={},e[0]=g):g=e[0];const{data:S,error:o,errorSource:p,isLoading:C,refetch:v}=X(Z.listPushSubscriptions,g);let N;if(e[1]!==S?.subscriptions||e[2]!==o||e[3]!==p||e[4]!==C||e[5]!==i||e[6]!==v||e[7]!==s||e[8]!==r){const A=S?.subscriptions??[],j=s.trim().toLowerCase(),E=A.filter(a=>i!=="all"&&a.kind!==i?!1:j===""?!0:`${P(a)} ${a.userId??""}`.toLowerCase().includes(j));let b;e[10]===Symbol.for("react.memo_cache_sentinel")?(b=a=>{V(a.target.value)},e[10]=b):b=e[10];const D=b;let w;e[11]!==v?(w=()=>{v()},e[11]=v,e[12]=w):w=e[12];const I=w;let y;e[13]===Symbol.for("react.memo_cache_sentinel")?(y=["all","web-push","fcm"],e[13]=y):y=e[13];const H=y;let l;e[14]!==i||e[15]!==r?(l=t("div",{className:"flex items-center gap-1","data-testid":"nt-kind-filter",role:"tablist",children:H.map(a=>t(z,{"aria-selected":i===a,"data-testid":`nt-kind-${a}`,onClick:()=>{R(a)},role:"tab",size:"sm",type:"button",variant:i===a?"secondary":"ghost",children:a==="all"?r("All"):a},a))}),e[14]=i,e[15]=r,e[16]=l):l=e[16];let n;e[17]!==r?(n=r("Filter devices"),e[17]=r,e[18]=n):n=e[18];let c;e[19]!==r?(c=r("filter endpoint, user"),e[19]=r,e[20]=c):c=e[20];let d;e[21]!==s||e[22]!==n||e[23]!==c?(d=t(G,{"aria-label":n,className:"h-8 w-56","data-testid":"nt-search",onChange:D,placeholder:c,value:s}),e[21]=s,e[22]=n,e[23]=c,e[24]=d):d=e[24];let m;e[25]!==r?(m=r("Refresh"),e[25]=r,e[26]=m):m=e[26];let u;e[27]!==I||e[28]!==m?(u=t(z,{className:"ml-auto","data-testid":"nt-refresh",onClick:I,size:"sm",type:"button",variant:"outline",children:m}),e[27]=I,e[28]=m,e[29]=u):u=e[29];const L=A.length>0&&t(_,{"data-testid":"nt-count",variant:"secondary",children:r("{count} devices",{count:A.length})});let $;e[30]!==u||e[31]!==L||e[32]!==l||e[33]!==d?($=x("div",{className:"flex flex-wrap items-center gap-2",children:[l,d,u,L]}),e[30]=u,e[31]=L,e[32]=l,e[33]=d,e[34]=$):$=e[34];let k;e[35]!==o||e[36]!==p?(k=o!==null&&t(B,{error:p,testId:"nt-error"}),e[35]=o,e[36]=p,e[37]=k):k=e[37],N=x("div",{className:"flex flex-col gap-4","data-testid":"lunora-notifications",children:[$,k,o===null&&!C&&E.length===0&&t(q,{description:r("Registered Web Push / FCM devices appear here. Configure lunora/notify.ts with defineNotify({ store }) and register a device with ctx.push.register(...)."),icon:t("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:t("path",{d:"M15 17h5l-1.4-1.4A2 2 0 0 1 18 14.2V11a6 6 0 0 0-4-5.7V5a2 2 0 1 0-4 0v.3A6 6 0 0 0 6 11v3.2a2 2 0 0 1-.6 1.4L4 17h5m6 0v1a3 3 0 1 1-6 0v-1m6 0H9"})}),testId:"nt-empty",title:r("No registered devices.")}),E.length>0&&t(O,{className:"overflow-hidden py-0",children:t(U,{className:"max-h-[30rem] overflow-auto px-0",children:x(J,{"data-testid":"nt-table",children:[t(K,{children:x(F,{children:[t(h,{children:r("kind")}),t(h,{children:r("endpoint")}),t(h,{children:r("user")}),t(h,{children:r("last seen")}),t(h,{children:r("status")}),t(h,{children:r("error")})]})}),t(Q,{children:E.map(a=>{const M=P(a);return x(F,{"data-testid":"nt-row",children:[t(f,{children:t(_,{variant:"outline",children:a.kind})}),t(f,{className:"max-w-[28ch] truncate font-mono text-xs",title:M,children:M}),t(f,{className:"max-w-[16ch] truncate font-mono text-xs",children:a.userId??t("span",{className:"text-muted-foreground",children:"—"})}),t(f,{className:"text-muted-foreground tabular-nums",children:ee(a.lastSeenAt,"—")}),t(f,{children:t(_,{"data-testid":`nt-status-${a.id}`,variant:te(a.lastStatus),children:a.lastStatus??r("n/a")})}),t(f,{className:"max-w-[28ch] truncate font-mono text-xs text-muted-foreground",title:a.lastError??void 0,children:a.lastError??t("span",{className:"text-muted-foreground",children:"—"})})]},a.id)})})]})})})]}),e[1]=S?.subscriptions,e[2]=o,e[3]=p,e[4]=C,e[5]=i,e[6]=v,e[7]=s,e[8]=r,e[9]=N}else N=e[9];return N};export{ve as NotificationsPanel};
@@ -1 +1 @@
1
- import{useLunora as E}from"@lunora/react";import{useState as s,useCallback as H,useEffect as W}from"react";import{ConfirmButton as F}from"../packem_shared/ConfirmButton-CTL3f3kr.js";import{g as Z}from"../packem_shared/badge-BbuuAio7.js";import{u as _}from"../packem_shared/button-BkCrNcAs.js";import{u as I}from"../packem_shared/input-JHu63lTv.js";import{p as g}from"../packem_shared/label-6uP1obNF.js";import{useAutoRefresh as G}from"../packem_shared/DEFAULT_AUTO_REFRESH_MS-BCC8_4BQ.js";import{useT as J}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as B}from"../packem_shared/ADMIN_FUNCTIONS-BnD4aovm.js";import{d as u,b as N,f as p,g as S}from"../packem_shared/internal-BSIsQVC6.js";import{jsxs as a,jsx as r}from"react/jsx-runtime";const y=S(B.getPitrBookmark),Q=S(B.pitrRestore),de=({initialShardKey:T})=>{const m=E(),t=J(),i=T??"",[O,f]=s(null),[l,P]=s(""),[v,w]=s(null),[c,q]=s(""),[h,A]=s(!1),[o,L]=s(null),[C,n]=s(null),[x,d]=s(!1),b=H(async()=>{d(!0),n(null);try{const e=await m.query(y,{},u(i));f(e.current)}catch(e){n(N(e))}d(!1)},[m,i]);W(()=>{p(b())},[b]),G(()=>{p((async()=>{try{const e=await m.query(y,{},u(i));f(e.current)}catch{}})())},!0);const U=e=>{P(e.target.value)},j=e=>{q(e.target.value)},M=e=>{A(e.target.checked)},z=()=>{l.trim()!==""&&p((async()=>{d(!0),n(null);try{const e=await m.query(y,{time:l.trim()},u(i));w(e.forTime??null),f(e.current)}catch(e){w(null),n(N(e))}d(!1)})())},R=e=>{p((async()=>{d(!0),n(null);try{const k=await m.mutation(Q,e,u(i));L(k),await b()}catch(k){n(N(k))}d(!1)})())},K=c.trim()!==""||l.trim()!=="",$=()=>{const e=h?{restart:!0}:{};c.trim()===""?e.time=l.trim():e.bookmark=c.trim(),R(e)},D=()=>{o!==null&&R(h?{bookmark:o.undoBookmark,restart:!0}:{bookmark:o.undoBookmark})};return a("div",{className:"flex flex-col gap-4","data-testid":"lunora-pitr",children:[r("div",{className:"flex flex-wrap items-center gap-3",children:a("span",{className:"text-xs text-muted-foreground",children:[t("Shard"),": ",r("span",{className:"font-mono",children:i===""?t("root"):i})]})}),r("p",{className:"text-sm text-muted-foreground","data-testid":"pitr-note",children:t("In-place recovery to any moment in the last 30 days. For older or portable recovery, use the snapshot backup tier.")}),C!==null&&r("p",{className:"text-sm text-destructive","data-testid":"pitr-error",role:"alert",children:C}),a("section",{className:"rounded-xl border border-border bg-card p-3 shadow-xs",children:[r("h3",{className:"mb-2 text-sm font-semibold",children:t("Current bookmark")}),r("p",{className:"font-mono text-xs break-all text-muted-foreground","data-testid":"pitr-current",children:O??r("span",{className:"text-muted-foreground",children:"—"})})]}),a("section",{className:"flex flex-col gap-3 rounded-xl border border-border bg-card p-3 shadow-xs",children:[r("h3",{className:"text-sm font-semibold",children:t("Restore")}),a("div",{className:"flex flex-col gap-1",children:[r(g,{htmlFor:"pitr-time",children:t("Time (ISO or epoch-ms, last 30 days)")}),a("div",{className:"flex items-center gap-2",children:[r(I,{"data-testid":"pitr-time",id:"pitr-time",onChange:U,placeholder:"2026-06-01T00:00:00.000Z",value:l}),r(_,{"data-testid":"pitr-preview",disabled:x||l.trim()==="",onClick:z,size:"sm",type:"button",variant:"outline",children:t("Preview")})]}),v!==null&&a("p",{className:"font-mono text-xs break-all text-muted-foreground","data-testid":"pitr-preview-bookmark",children:[t("Bookmark for that time"),": ",v]})]}),a("div",{className:"flex flex-col gap-1",children:[r(g,{htmlFor:"pitr-bookmark",children:t("Or an explicit bookmark (wins over time)")}),r(I,{"data-testid":"pitr-bookmark",id:"pitr-bookmark",onChange:j,placeholder:t("bookmark string"),value:c})]}),a(g,{className:"flex items-center gap-2 text-xs font-normal text-muted-foreground",htmlFor:"pitr-restart",children:[r("input",{checked:h,className:"size-4 accent-primary","data-testid":"pitr-restart",id:"pitr-restart",onChange:M,type:"checkbox"}),t("Restart the shard now so recovery applies immediately")]}),r("div",{children:r(F,{confirmLabel:t("Confirm restore"),disabled:x||!K,onConfirm:$,testId:"pitr-restore",children:t("Restore")})})]}),o!==null&&a("section",{className:"flex flex-col gap-2 rounded-xl border border-border bg-card p-3 shadow-xs","data-testid":"pitr-result",children:[a("div",{className:"flex items-center gap-2",children:[r("h3",{className:"text-sm font-semibold",children:t("Restore armed")}),r(Z,{variant:o.restarted?"destructive":"secondary",children:o.restarted?t("restarted now"):t("on next restart")})]}),a("p",{className:"font-mono text-xs break-all text-muted-foreground",children:[t("Restored to"),": ",o.restoredTo]}),a("p",{className:"font-mono text-xs break-all text-muted-foreground","data-testid":"pitr-undo-bookmark",children:[t("Undo bookmark"),": ",o.undoBookmark]}),r("div",{children:r(F,{confirmLabel:t("Confirm undo"),disabled:x,onConfirm:D,testId:"pitr-undo",children:t("Undo restore")})})]})]})};export{de as PitrPanel};
1
+ import{useLunora as E}from"@lunora/react";import{useState as s,useCallback as H,useEffect as W}from"react";import{ConfirmButton as F}from"../packem_shared/ConfirmButton-CTL3f3kr.js";import{g as Z}from"../packem_shared/badge-BbuuAio7.js";import{u as _}from"../packem_shared/button-BkCrNcAs.js";import{u as I}from"../packem_shared/input-JHu63lTv.js";import{p as g}from"../packem_shared/label-6uP1obNF.js";import{useAutoRefresh as G}from"../packem_shared/DEFAULT_AUTO_REFRESH_MS-BCC8_4BQ.js";import{useT as J}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as B}from"../packem_shared/ADMIN_FUNCTIONS-CZESgd10.js";import{d as u,b as N,f as p,g as S}from"../packem_shared/internal-BSIsQVC6.js";import{jsxs as a,jsx as r}from"react/jsx-runtime";const y=S(B.getPitrBookmark),Q=S(B.pitrRestore),de=({initialShardKey:T})=>{const m=E(),t=J(),i=T??"",[O,f]=s(null),[l,P]=s(""),[v,w]=s(null),[c,q]=s(""),[h,A]=s(!1),[o,L]=s(null),[C,n]=s(null),[x,d]=s(!1),b=H(async()=>{d(!0),n(null);try{const e=await m.query(y,{},u(i));f(e.current)}catch(e){n(N(e))}d(!1)},[m,i]);W(()=>{p(b())},[b]),G(()=>{p((async()=>{try{const e=await m.query(y,{},u(i));f(e.current)}catch{}})())},!0);const U=e=>{P(e.target.value)},j=e=>{q(e.target.value)},M=e=>{A(e.target.checked)},z=()=>{l.trim()!==""&&p((async()=>{d(!0),n(null);try{const e=await m.query(y,{time:l.trim()},u(i));w(e.forTime??null),f(e.current)}catch(e){w(null),n(N(e))}d(!1)})())},R=e=>{p((async()=>{d(!0),n(null);try{const k=await m.mutation(Q,e,u(i));L(k),await b()}catch(k){n(N(k))}d(!1)})())},K=c.trim()!==""||l.trim()!=="",$=()=>{const e=h?{restart:!0}:{};c.trim()===""?e.time=l.trim():e.bookmark=c.trim(),R(e)},D=()=>{o!==null&&R(h?{bookmark:o.undoBookmark,restart:!0}:{bookmark:o.undoBookmark})};return a("div",{className:"flex flex-col gap-4","data-testid":"lunora-pitr",children:[r("div",{className:"flex flex-wrap items-center gap-3",children:a("span",{className:"text-xs text-muted-foreground",children:[t("Shard"),": ",r("span",{className:"font-mono",children:i===""?t("root"):i})]})}),r("p",{className:"text-sm text-muted-foreground","data-testid":"pitr-note",children:t("In-place recovery to any moment in the last 30 days. For older or portable recovery, use the snapshot backup tier.")}),C!==null&&r("p",{className:"text-sm text-destructive","data-testid":"pitr-error",role:"alert",children:C}),a("section",{className:"rounded-xl border border-border bg-card p-3 shadow-xs",children:[r("h3",{className:"mb-2 text-sm font-semibold",children:t("Current bookmark")}),r("p",{className:"font-mono text-xs break-all text-muted-foreground","data-testid":"pitr-current",children:O??r("span",{className:"text-muted-foreground",children:"—"})})]}),a("section",{className:"flex flex-col gap-3 rounded-xl border border-border bg-card p-3 shadow-xs",children:[r("h3",{className:"text-sm font-semibold",children:t("Restore")}),a("div",{className:"flex flex-col gap-1",children:[r(g,{htmlFor:"pitr-time",children:t("Time (ISO or epoch-ms, last 30 days)")}),a("div",{className:"flex items-center gap-2",children:[r(I,{"data-testid":"pitr-time",id:"pitr-time",onChange:U,placeholder:"2026-06-01T00:00:00.000Z",value:l}),r(_,{"data-testid":"pitr-preview",disabled:x||l.trim()==="",onClick:z,size:"sm",type:"button",variant:"outline",children:t("Preview")})]}),v!==null&&a("p",{className:"font-mono text-xs break-all text-muted-foreground","data-testid":"pitr-preview-bookmark",children:[t("Bookmark for that time"),": ",v]})]}),a("div",{className:"flex flex-col gap-1",children:[r(g,{htmlFor:"pitr-bookmark",children:t("Or an explicit bookmark (wins over time)")}),r(I,{"data-testid":"pitr-bookmark",id:"pitr-bookmark",onChange:j,placeholder:t("bookmark string"),value:c})]}),a(g,{className:"flex items-center gap-2 text-xs font-normal text-muted-foreground",htmlFor:"pitr-restart",children:[r("input",{checked:h,className:"size-4 accent-primary","data-testid":"pitr-restart",id:"pitr-restart",onChange:M,type:"checkbox"}),t("Restart the shard now so recovery applies immediately")]}),r("div",{children:r(F,{confirmLabel:t("Confirm restore"),disabled:x||!K,onConfirm:$,testId:"pitr-restore",children:t("Restore")})})]}),o!==null&&a("section",{className:"flex flex-col gap-2 rounded-xl border border-border bg-card p-3 shadow-xs","data-testid":"pitr-result",children:[a("div",{className:"flex items-center gap-2",children:[r("h3",{className:"text-sm font-semibold",children:t("Restore armed")}),r(Z,{variant:o.restarted?"destructive":"secondary",children:o.restarted?t("restarted now"):t("on next restart")})]}),a("p",{className:"font-mono text-xs break-all text-muted-foreground",children:[t("Restored to"),": ",o.restoredTo]}),a("p",{className:"font-mono text-xs break-all text-muted-foreground","data-testid":"pitr-undo-bookmark",children:[t("Undo bookmark"),": ",o.undoBookmark]}),r("div",{children:r(F,{confirmLabel:t("Confirm undo"),disabled:x,onConfirm:D,testId:"pitr-undo",children:t("Undo restore")})})]})]})};export{de as PitrPanel};