@lunora/studio 1.0.0-alpha.122 → 1.0.0-alpha.124

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 (168) hide show
  1. package/dist/index.d.ts +46 -1
  2. package/dist/index.js +1 -1
  3. package/dist/mount.js +1 -1
  4. package/dist/packem_chunks/AdvisorHealthPanel.js +1 -1
  5. package/dist/packem_chunks/ApiTab.js +1 -1
  6. package/dist/packem_chunks/AuditPanel.js +1 -1
  7. package/dist/packem_chunks/DeploymentHealthPanel.js +1 -1
  8. package/dist/packem_chunks/ExportImportPanel.js +1 -1
  9. package/dist/packem_chunks/FileBrowser.js +1 -1
  10. package/dist/packem_chunks/FunctionRunner.js +1 -1
  11. package/dist/packem_chunks/FunctionStatsPanel.js +1 -1
  12. package/dist/packem_chunks/HealthPanel.js +1 -1
  13. package/dist/packem_chunks/InsightsPanel.js +1 -1
  14. package/dist/packem_chunks/LogsPanel.js +1 -1
  15. package/dist/packem_chunks/MailPanel.js +1 -1
  16. package/dist/packem_chunks/MetricsPanel.js +1 -1
  17. package/dist/packem_chunks/NotificationsPanel.js +1 -1
  18. package/dist/packem_chunks/PitrPanel.js +1 -1
  19. package/dist/packem_chunks/SchemaViewer.js +1 -1
  20. package/dist/packem_chunks/SecurityAdvisorPanel.js +1 -1
  21. package/dist/packem_chunks/SettingsPanel.js +1 -1
  22. package/dist/packem_chunks/SqlEditorPanel.js +1 -1
  23. package/dist/packem_chunks/TableEditor.js +1 -1
  24. package/dist/packem_chunks/agents-panel.js +1 -1
  25. package/dist/packem_chunks/analytics-panel.js +1 -1
  26. package/dist/packem_chunks/auth-audit-panel.js +1 -1
  27. package/dist/packem_chunks/auth-config-panel.js +1 -1
  28. package/dist/packem_chunks/auth-sessions-panel.js +1 -1
  29. package/dist/packem_chunks/containers-panel.js +1 -1
  30. package/dist/packem_chunks/dashboards-panel.js +1 -1
  31. package/dist/packem_chunks/evals-panel.js +1 -1
  32. package/dist/packem_chunks/fanout-panel.js +1 -1
  33. package/dist/packem_chunks/flags-panel.js +1 -1
  34. package/dist/packem_chunks/issues-panel.js +1 -1
  35. package/dist/packem_chunks/kv-browser.js +1 -1
  36. package/dist/packem_chunks/log-drains-panel.js +1 -1
  37. package/dist/packem_chunks/migrations-route.js +1 -1
  38. package/dist/packem_chunks/organizations-panel.js +1 -1
  39. package/dist/packem_chunks/payments-panel.js +1 -1
  40. package/dist/packem_chunks/permissions-panel.js +1 -1
  41. package/dist/packem_chunks/queues-panel.js +1 -1
  42. package/dist/packem_chunks/reactors-panel.js +1 -1
  43. package/dist/packem_chunks/rls-panel.js +1 -1
  44. package/dist/packem_chunks/schedule-panel.js +1 -1
  45. package/dist/packem_chunks/storage-rules-panel.js +1 -1
  46. package/dist/packem_chunks/subscriptions-panel.js +1 -1
  47. package/dist/packem_chunks/sync-client-panel.js +1 -1
  48. package/dist/packem_chunks/traces-panel.js +1 -1
  49. package/dist/packem_chunks/users-panel.js +1 -1
  50. package/dist/packem_chunks/vector-browser.js +1 -1
  51. package/dist/packem_chunks/workflows-panel.js +1 -1
  52. package/dist/packem_shared/{ApiDocsPanel-BMzLPgvv.js → ApiDocsPanel-Du1L7Ysj.js} +1 -1
  53. package/dist/packem_shared/{ApiReferencePanel-CZDVN7zg.js → ApiReferencePanel-uGgGOBYj.js} +1 -1
  54. package/dist/packem_shared/{CommandPalette-kQLn0xlS.js → CommandPalette-HqiXrWIm.js} +1 -1
  55. package/dist/packem_shared/DataBrowser-W5TxvLB8.js +4 -0
  56. package/dist/packem_shared/GlobalDataBrowser-LFznuyGe.js +1 -0
  57. package/dist/packem_shared/{HomePanel-B-tcMcTZ.js → HomePanel-DmB0EKjl.js} +1 -1
  58. package/dist/packem_shared/{MigrationsPanel-CLRWwPyL.js → MigrationsPanel-BDNt136v.js} +1 -1
  59. package/dist/packem_shared/{OpenRpcReferencePanel-XoYdKuMg.js → OpenRpcReferencePanel-DgrpASYD.js} +1 -1
  60. package/dist/packem_shared/{ScheduledJobs-DRmOKtDa.js → ScheduledJobs-CiO3eXgI.js} +1 -1
  61. package/dist/packem_shared/Studio-CkNE_tEy.js +1 -0
  62. package/dist/packem_shared/{StudioApp-Bxmtp-Fi.js → StudioApp-BZP_0E2n.js} +1 -1
  63. package/dist/packem_shared/{advisor-view-CqCG22DB.js → advisor-view-C1KFTXSH.js} +1 -1
  64. package/dist/packem_shared/control-button-BOZ5K-FC.js +1 -0
  65. package/dist/packem_shared/{data-grid-pjv4t5Yi.js → data-grid-BFTQnkXq.js} +1 -1
  66. package/dist/packem_shared/{error-alert-CKqB2CiN.js → error-alert-TYdKetJd.js} +1 -1
  67. package/dist/packem_shared/grid-features-jBzZGauv.js +6 -0
  68. package/dist/packem_shared/{home-panel-ecz6-nHV.js → home-panel-DHOa3sxt.js} +1 -1
  69. package/dist/packem_shared/{internal-7bgd8inO.js → internal-CwaF9YNk.js} +1 -1
  70. package/dist/packem_shared/{log-line-D0XBZaDn.js → log-line-UnE93Ovi.js} +1 -1
  71. package/dist/packem_shared/quote-identifier-CGiYFBvY.js +1 -0
  72. package/dist/packem_shared/{recording-client-BPY8sYUl.js → recording-client-CKn4-vUx.js} +1 -1
  73. package/dist/packem_shared/{reference-view-DY3CaRxH.js → reference-view-BU2dNK9Z.js} +1 -1
  74. package/dist/packem_shared/{schema-diagram-DLhppqVE.js → schema-diagram-DOaIh1y6.js} +1 -1
  75. package/dist/packem_shared/{sql-result-table-blxdNVJ0.js → sql-result-table-CqlZo2QN.js} +1 -1
  76. package/dist/packem_shared/{studio-Cvdwfzxm.js → studio-CXai1O2K.js} +1 -1
  77. package/dist/packem_shared/table-list-sidebar-BWq_-gtu.js +1 -0
  78. package/dist/packem_shared/{use-admin-query-DV9xmFl8.js → use-admin-query-P0RJrjsD.js} +1 -1
  79. package/dist/packem_shared/{use-async-submit-C9xXjXWX.js → use-async-submit-DdLd0MdK.js} +1 -1
  80. package/dist/packem_shared/{use-auth-config-DIAyVsa3.js → use-auth-config-z3KRWAqD.js} +1 -1
  81. package/dist/packem_shared/{use-open-trace-ClAdPkGD.js → use-open-trace-4mqqFWrn.js} +1 -1
  82. package/dist/packem_shared/{use-sql-assistant-CXgVX_PP.js → use-sql-assistant-D1K2LqpO.js} +1 -1
  83. package/dist/standalone/{chunk-5XMZP64Z.js → chunk-26VREVWU.js} +1 -1
  84. package/dist/standalone/{chunk-K3SXMDKL.js → chunk-2XWSDIDE.js} +1 -1
  85. package/dist/standalone/{chunk-R7EV3YND.js → chunk-3XH6Y5XR.js} +1 -1
  86. package/dist/standalone/chunk-443UDYWL.js +6 -0
  87. package/dist/standalone/{chunk-EIWXXEVA.js → chunk-4NIGWKLB.js} +1 -1
  88. package/dist/standalone/{chunk-TCAX32PK.js → chunk-52EGR2D7.js} +1 -1
  89. package/dist/standalone/{chunk-2HW5M4MK.js → chunk-52XAAEXT.js} +1 -1
  90. package/dist/standalone/{chunk-7MO56FXL.js → chunk-5AZRLELE.js} +1 -1
  91. package/dist/standalone/{chunk-DXXXNZ3P.js → chunk-5RC2J7EQ.js} +1 -1
  92. package/dist/standalone/{chunk-7EOXUWAI.js → chunk-6OP4OPZL.js} +1 -1
  93. package/dist/standalone/{chunk-BKM6PMSO.js → chunk-6ZPTNC34.js} +1 -1
  94. package/dist/standalone/{chunk-T7DJP5HM.js → chunk-76YLMHR3.js} +1 -1
  95. package/dist/standalone/{chunk-UBT2FIU5.js → chunk-BFCUKERU.js} +1 -1
  96. package/dist/standalone/{chunk-33TNFS73.js → chunk-C4KVCFWK.js} +1 -1
  97. package/dist/standalone/{chunk-5DEXJ766.js → chunk-CDSCHFAO.js} +1 -1
  98. package/dist/standalone/{chunk-GISVVEPU.js → chunk-CORGKNPG.js} +1 -1
  99. package/dist/standalone/{chunk-KNI5YDPT.js → chunk-CXCSFWBE.js} +1 -1
  100. package/dist/standalone/{chunk-SQSMHFA7.js → chunk-CXYGKZKS.js} +1 -1
  101. package/dist/standalone/{chunk-GDC3W3DZ.js → chunk-DPNKDUJC.js} +1 -1
  102. package/dist/standalone/{chunk-POD66K2Y.js → chunk-EKZA2SNK.js} +1 -1
  103. package/dist/standalone/{chunk-VYW2PAWC.js → chunk-FDLSPDIC.js} +4 -4
  104. package/dist/standalone/{chunk-XYWLXNTV.js → chunk-FJ57FLS4.js} +1 -1
  105. package/dist/standalone/{chunk-2EWSVBWG.js → chunk-FM2JJJO7.js} +1 -1
  106. package/dist/standalone/{chunk-UDCFI5NF.js → chunk-FW2XISZX.js} +1 -1
  107. package/dist/standalone/{chunk-THTL2KBP.js → chunk-FZQVGJMN.js} +1 -1
  108. package/dist/standalone/{chunk-FKXX3Y2J.js → chunk-GHYRLOMN.js} +1 -1
  109. package/dist/standalone/{chunk-6AJONHNM.js → chunk-GIQDEWC4.js} +1 -1
  110. package/dist/standalone/{chunk-TI5RJJRX.js → chunk-HBOCJUOG.js} +1 -1
  111. package/dist/standalone/chunk-HHVCAFE5.js +7 -0
  112. package/dist/standalone/{chunk-E4RVRJHD.js → chunk-HKEMILZM.js} +1 -1
  113. package/dist/standalone/{chunk-GNN5HJ56.js → chunk-ICIYR6A6.js} +1 -1
  114. package/dist/standalone/{chunk-JCSDJBBZ.js → chunk-JCSKFOWL.js} +1 -1
  115. package/dist/standalone/{chunk-UFUOW6UJ.js → chunk-JSRBQSJF.js} +1 -1
  116. package/dist/standalone/{chunk-E6P2ERQV.js → chunk-JURAVSE7.js} +1 -1
  117. package/dist/standalone/chunk-KIU56OEQ.js +11 -0
  118. package/dist/standalone/{chunk-B6YM5NAF.js → chunk-KN3HN3RR.js} +1 -1
  119. package/dist/standalone/chunk-LCQ5HHRP.js +1 -0
  120. package/dist/standalone/{chunk-MTGEDJQH.js → chunk-LY2DCTSE.js} +1 -1
  121. package/dist/standalone/{chunk-VJQAOU2U.js → chunk-MR7UZGEN.js} +1 -1
  122. package/dist/standalone/{chunk-4HWTEDVV.js → chunk-MV7VAZWZ.js} +1 -1
  123. package/dist/standalone/{chunk-AVBUV42G.js → chunk-N3BGHNUY.js} +1 -1
  124. package/dist/standalone/{chunk-MHB2TOAK.js → chunk-NF2SQSOU.js} +1 -1
  125. package/dist/standalone/{chunk-XL2OT5WB.js → chunk-NNLNQKT7.js} +1 -1
  126. package/dist/standalone/chunk-O5MAFDY2.js +1 -0
  127. package/dist/standalone/{chunk-2FFV3NB7.js → chunk-O7SUXUZM.js} +1 -1
  128. package/dist/standalone/{chunk-MLYZZD5C.js → chunk-OE4KGVJW.js} +1 -1
  129. package/dist/standalone/{chunk-2EJQ7SPV.js → chunk-OG57FC7W.js} +1 -1
  130. package/dist/standalone/{chunk-O4RQGUJ7.js → chunk-PC77ZYDR.js} +1 -1
  131. package/dist/standalone/{chunk-PAJQOSEU.js → chunk-QEF6JA57.js} +1 -1
  132. package/dist/standalone/chunk-QHQTOESO.js +1 -0
  133. package/dist/standalone/{chunk-PGTCEMBA.js → chunk-QQHMGTOT.js} +1 -1
  134. package/dist/standalone/{chunk-KTEVBZIV.js → chunk-QWARY4R4.js} +1 -1
  135. package/dist/standalone/{chunk-QBONDY5I.js → chunk-RBD64CEG.js} +1 -1
  136. package/dist/standalone/chunk-RCCQVHVD.js +1 -0
  137. package/dist/standalone/{chunk-VTFMI4DC.js → chunk-RO6ZQZVK.js} +1 -1
  138. package/dist/standalone/{chunk-KJNDUIZG.js → chunk-S7CPEVEC.js} +1 -1
  139. package/dist/standalone/{chunk-XOA5TTRA.js → chunk-SQMJUXBA.js} +1 -1
  140. package/dist/standalone/{chunk-YMVKAXBC.js → chunk-SRQP7SLQ.js} +1 -1
  141. package/dist/standalone/{chunk-TKKRBSUB.js → chunk-SXDZK4EN.js} +1 -1
  142. package/dist/standalone/{chunk-6UN4V2HB.js → chunk-TB5N24CM.js} +1 -1
  143. package/dist/standalone/{chunk-TDH7K7E7.js → chunk-USM7ZIHK.js} +1 -1
  144. package/dist/standalone/{chunk-MG7VPUFA.js → chunk-V6QPVFDL.js} +1 -1
  145. package/dist/standalone/{chunk-U2FRMJAN.js → chunk-VKJS3O3E.js} +1 -1
  146. package/dist/standalone/{chunk-OCZ2IP5A.js → chunk-VLIRSGFL.js} +1 -1
  147. package/dist/standalone/{chunk-3K4F3B56.js → chunk-W5WKMQFK.js} +1 -1
  148. package/dist/standalone/{chunk-U32MMDFO.js → chunk-WED7GO6G.js} +2 -2
  149. package/dist/standalone/{chunk-KR6SZXOI.js → chunk-WJOMJPWF.js} +1 -1
  150. package/dist/standalone/{chunk-RAFPVMXJ.js → chunk-X2CXZPPL.js} +1 -1
  151. package/dist/standalone/{chunk-N7PPYEHW.js → chunk-XT5DGCBY.js} +1 -1
  152. package/dist/standalone/{chunk-ZWATJNSU.js → chunk-YGGQHUKC.js} +1 -1
  153. package/dist/standalone/{chunk-2AJMY73I.js → chunk-YNIOJEFL.js} +1 -1
  154. package/dist/standalone/{chunk-3WFIPW6W.js → chunk-Z5HOZ3HK.js} +1 -1
  155. package/dist/standalone/{chunk-4O7MEQMU.js → chunk-ZQMNQ2EZ.js} +1 -1
  156. package/dist/standalone/studio.js +1 -1
  157. package/package.json +6 -6
  158. package/dist/packem_shared/DataBrowser-C68K5QHO.js +0 -4
  159. package/dist/packem_shared/GlobalDataBrowser-BHFgEqMl.js +0 -1
  160. package/dist/packem_shared/Studio-BYdUxnM5.js +0 -1
  161. package/dist/packem_shared/grid-features-AzpmpR3Q.js +0 -6
  162. package/dist/packem_shared/table-list-sidebar-BCxqrZ0s.js +0 -1
  163. package/dist/standalone/chunk-5QAT5NQ4.js +0 -1
  164. package/dist/standalone/chunk-5VKIJNHE.js +0 -1
  165. package/dist/standalone/chunk-7CVIN6KU.js +0 -6
  166. package/dist/standalone/chunk-FS7FGJOU.js +0 -1
  167. package/dist/standalone/chunk-ICQTVV6U.js +0 -7
  168. package/dist/standalone/chunk-NIUA7EHL.js +0 -11
@@ -1 +1 @@
1
- import{useLunora as X}from"@lunora/react";import{useState as i,useEffect as Y}from"react";import{ShardInput as G}from"../packem_shared/ShardInput-CdawpUiS.js";import{B as E}from"../packem_shared/badge-cAk9Di1Q.js";import{B as N}from"../packem_shared/button-BOPLD1un.js";import{I as Q}from"../packem_shared/input-CY5W3wzv.js";import{L as y}from"../packem_shared/label-BOUo-DP0.js";import{T as W}from"../packem_shared/textarea-DpO3i-Qo.js";import{useT as Z}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.js";import{ADMIN_FUNCTIONS as _}from"../packem_shared/ADMIN_FUNCTIONS-B6z7VLYt.js";import{b as ee,i as te,f as re,k as se,c as ae}from"../packem_shared/internal-7bgd8inO.js";import{r as ne}from"../packem_shared/shard-history-DU5b3QDI.js";import{jsxs as n,jsx as r}from"react/jsx-runtime";const oe=t=>t.kind==="id"?t.table===void 0?"id":`id<${t.table}>`:t.kind==="array"?t.element===void 0?"array":`${t.element}[]`:t.kind,ie=t=>t===void 0||t.length===0?"()":`(${t.map(o=>`${o.name}${o.optional?"?":""}: ${oe(o)}`).join(", ")})`,de=t=>{switch(t){case"array":return[];case"bigint":case"number":return 0;case"boolean":return!1;case"object":case"record":return{};default:return""}},le=t=>{const o={};for(const s of t??[])s.optional||(o[s.name]=de(s.kind));return JSON.stringify(o,void 0,2)},ce=ae(_.runAs),ue=10,me=t=>t===void 0?"undefined":JSON.stringify(t,null,2),Ae=({functions:t,runAsIdentity:o=!1}={})=>{const s=Z(),u=X(),[L,j]=i(null),[S,B]=i(null),p=t??L??[],[w,R]=i(""),[m,g]=i("{}"),[c,k]=i(""),[f,D]=i(""),[x,h]=i("idle"),[K,b]=i(void 0),[I,v]=i(null),[A,U]=i([]);Y(()=>{if(t!==void 0)return;let e=!1;return u.listFunctions().then(d=>(e||j(d),d)).catch(d=>{e||B(ee(d))}),()=>{e=!0}},[u,t]);const C=w===""?p[0]?.path??"":w,a=p.find(e=>e.path===C),J=async()=>{if(!a)return;let e;try{e=m.trim()===""?{}:JSON.parse(m)}catch(l){h("error"),b(void 0),v(s("Invalid JSON args: {message}",{message:l.message}));return}const d={__lunoraRef:a.path},T=c.trim()===""?{}:{shardKey:c.trim()},F=o?f.trim():"",$=l=>{U(O=>[{argsText:m,at:Date.now(),id:(O[0]?.id??0)+1,kind:a.kind,path:a.path,shardKey:c,status:l},...O].slice(0,ue))};h("running"),v(null);try{const l=F===""?await se(u,a.kind,d,e,T):await u.query(ce,{args:e,functionPath:a.path,userId:F},T);ne(c),b(l),h("success"),$("success")}catch(l){b(void 0),v(l.message),h("error"),$("error")}},M=e=>{R(e.path),g(e.argsText),k(e.shardKey)},P=e=>{R(e.target.value)},z=e=>{g(e.target.value)},q=e=>{D(e.target.value)},H=()=>{re(J())},V=()=>{g(le(a?.args))};return n("div",{className:"flex flex-col gap-4","data-testid":"lunora-function-runner",children:[S!==null&&r("p",{className:"text-sm text-destructive","data-testid":"function-discover-error",role:"alert",children:S}),n("div",{className:"flex flex-col gap-4 rounded-xl border border-border bg-card p-4",children:[n("div",{className:"flex flex-col gap-1.5",children:[r(y,{htmlFor:"function-select",children:s("Function")}),r("select",{"aria-label":s("Function"),className:"flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-xs transition-[color,box-shadow] outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50","data-testid":"function-select",id:"function-select",onChange:P,value:C,children:p.map(e=>n("option",{value:e.path,children:[e.path," (",e.kind,")"]},e.path))}),a!==void 0&&n("p",{className:"text-xs text-muted-foreground",children:[r("span",{className:"mr-1.5 font-medium",children:s("Signature")}),r("code",{className:"font-mono","data-testid":"function-signature",children:ie(a.args)})]})]}),n("div",{className:"flex flex-col gap-1.5",children:[n("div",{className:"flex items-center justify-between gap-2",children:[r(y,{htmlFor:"args-input",children:s("Arguments")}),r(N,{"data-testid":"prefill-button",disabled:a===void 0,onClick:V,size:"xs",type:"button",variant:"ghost",children:s("Prefill")})]}),r(W,{"aria-label":s("Arguments"),className:"font-mono text-xs","data-testid":"args-input",id:"args-input",onChange:z,value:m})]}),r(G,{onChange:k,testId:"shard-input",value:c}),o&&n("div",{className:"flex flex-col gap-1.5","data-testid":"run-as-field",children:[r(y,{htmlFor:"run-as-input",children:s("Run as identity (userId)")}),r(Q,{"aria-label":s("Run as identity (userId)"),className:"font-mono text-xs","data-testid":"run-as-input",id:"run-as-input",onChange:q,placeholder:s("Leave empty to run as admin"),value:f}),r("p",{className:"text-[11px] text-muted-foreground",children:s("Dev only: runs the function as this user so you can test auth and RLS. Forged over the admin gate.")})]}),n("div",{className:"flex flex-wrap items-center gap-2",children:[r(N,{"data-testid":"run-button",disabled:x==="running"||a===void 0,onClick:H,type:"button",children:s("Run")}),a!==void 0&&r(E,{variant:"outline",children:a.kind}),o&&f.trim()!==""&&r(E,{"data-testid":"run-as-badge",variant:"secondary",children:s("as {userId}",{userId:f.trim()})})]})]}),x==="error"&&I!==null&&r("pre",{className:"overflow-auto rounded-md border border-border bg-muted/50 p-3 font-mono text-xs text-destructive","data-testid":"error",role:"alert",children:I}),x==="success"&&r("pre",{className:"overflow-auto rounded-md border border-border bg-muted/50 p-3 font-mono text-xs","data-testid":"result",children:me(K)}),A.length>0&&r("ul",{className:"flex flex-col overflow-hidden rounded-xl border border-border","data-testid":"fn-history",children:A.map((e,d)=>n("li",{className:"flex flex-wrap items-center gap-2 border-b border-border px-3 py-2 text-sm last:border-b-0","data-testid":"fn-history-row",children:[r("span",{className:e.status==="success"?"text-success":"text-destructive","data-testid":`fn-history-status-${d.toString()}`,children:e.status==="success"?"✓":"✗"})," ",n("span",{className:"font-mono text-xs",children:[e.path," (",e.kind,")"]})," ",r("time",{className:"text-xs text-muted-foreground",children:te(e.at)})," ",r(N,{className:"ml-auto","data-testid":`fn-history-load-${d.toString()}`,onClick:()=>{M(e)},size:"xs",type:"button",variant:"ghost",children:s("Load")})]},e.id))})]})};export{Ae as FunctionRunner};
1
+ import{useLunora as X}from"@lunora/react";import{useState as i,useEffect as Y}from"react";import{ShardInput as G}from"../packem_shared/ShardInput-CdawpUiS.js";import{B as E}from"../packem_shared/badge-cAk9Di1Q.js";import{B as N}from"../packem_shared/button-BOPLD1un.js";import{I as Q}from"../packem_shared/input-CY5W3wzv.js";import{L as y}from"../packem_shared/label-BOUo-DP0.js";import{T as W}from"../packem_shared/textarea-DpO3i-Qo.js";import{useT as Z}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.js";import{ADMIN_FUNCTIONS as _}from"../packem_shared/ADMIN_FUNCTIONS-B6z7VLYt.js";import{b as ee,i as te,f as re,k as se,c as ae}from"../packem_shared/internal-CwaF9YNk.js";import{r as ne}from"../packem_shared/shard-history-DU5b3QDI.js";import{jsxs as n,jsx as r}from"react/jsx-runtime";const oe=t=>t.kind==="id"?t.table===void 0?"id":`id<${t.table}>`:t.kind==="array"?t.element===void 0?"array":`${t.element}[]`:t.kind,ie=t=>t===void 0||t.length===0?"()":`(${t.map(o=>`${o.name}${o.optional?"?":""}: ${oe(o)}`).join(", ")})`,de=t=>{switch(t){case"array":return[];case"bigint":case"number":return 0;case"boolean":return!1;case"object":case"record":return{};default:return""}},le=t=>{const o={};for(const s of t??[])s.optional||(o[s.name]=de(s.kind));return JSON.stringify(o,void 0,2)},ce=ae(_.runAs),ue=10,me=t=>t===void 0?"undefined":JSON.stringify(t,null,2),Ae=({functions:t,runAsIdentity:o=!1}={})=>{const s=Z(),u=X(),[L,j]=i(null),[S,B]=i(null),p=t??L??[],[w,R]=i(""),[m,g]=i("{}"),[c,k]=i(""),[f,D]=i(""),[x,h]=i("idle"),[K,b]=i(void 0),[I,v]=i(null),[A,U]=i([]);Y(()=>{if(t!==void 0)return;let e=!1;return u.listFunctions().then(d=>(e||j(d),d)).catch(d=>{e||B(ee(d))}),()=>{e=!0}},[u,t]);const C=w===""?p[0]?.path??"":w,a=p.find(e=>e.path===C),J=async()=>{if(!a)return;let e;try{e=m.trim()===""?{}:JSON.parse(m)}catch(l){h("error"),b(void 0),v(s("Invalid JSON args: {message}",{message:l.message}));return}const d={__lunoraRef:a.path},T=c.trim()===""?{}:{shardKey:c.trim()},F=o?f.trim():"",$=l=>{U(O=>[{argsText:m,at:Date.now(),id:(O[0]?.id??0)+1,kind:a.kind,path:a.path,shardKey:c,status:l},...O].slice(0,ue))};h("running"),v(null);try{const l=F===""?await se(u,a.kind,d,e,T):await u.query(ce,{args:e,functionPath:a.path,userId:F},T);ne(c),b(l),h("success"),$("success")}catch(l){b(void 0),v(l.message),h("error"),$("error")}},M=e=>{R(e.path),g(e.argsText),k(e.shardKey)},P=e=>{R(e.target.value)},z=e=>{g(e.target.value)},q=e=>{D(e.target.value)},H=()=>{re(J())},V=()=>{g(le(a?.args))};return n("div",{className:"flex flex-col gap-4","data-testid":"lunora-function-runner",children:[S!==null&&r("p",{className:"text-sm text-destructive","data-testid":"function-discover-error",role:"alert",children:S}),n("div",{className:"flex flex-col gap-4 rounded-xl border border-border bg-card p-4",children:[n("div",{className:"flex flex-col gap-1.5",children:[r(y,{htmlFor:"function-select",children:s("Function")}),r("select",{"aria-label":s("Function"),className:"flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-xs transition-[color,box-shadow] outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50","data-testid":"function-select",id:"function-select",onChange:P,value:C,children:p.map(e=>n("option",{value:e.path,children:[e.path," (",e.kind,")"]},e.path))}),a!==void 0&&n("p",{className:"text-xs text-muted-foreground",children:[r("span",{className:"mr-1.5 font-medium",children:s("Signature")}),r("code",{className:"font-mono","data-testid":"function-signature",children:ie(a.args)})]})]}),n("div",{className:"flex flex-col gap-1.5",children:[n("div",{className:"flex items-center justify-between gap-2",children:[r(y,{htmlFor:"args-input",children:s("Arguments")}),r(N,{"data-testid":"prefill-button",disabled:a===void 0,onClick:V,size:"xs",type:"button",variant:"ghost",children:s("Prefill")})]}),r(W,{"aria-label":s("Arguments"),className:"font-mono text-xs","data-testid":"args-input",id:"args-input",onChange:z,value:m})]}),r(G,{onChange:k,testId:"shard-input",value:c}),o&&n("div",{className:"flex flex-col gap-1.5","data-testid":"run-as-field",children:[r(y,{htmlFor:"run-as-input",children:s("Run as identity (userId)")}),r(Q,{"aria-label":s("Run as identity (userId)"),className:"font-mono text-xs","data-testid":"run-as-input",id:"run-as-input",onChange:q,placeholder:s("Leave empty to run as admin"),value:f}),r("p",{className:"text-[11px] text-muted-foreground",children:s("Dev only: runs the function as this user so you can test auth and RLS. Forged over the admin gate.")})]}),n("div",{className:"flex flex-wrap items-center gap-2",children:[r(N,{"data-testid":"run-button",disabled:x==="running"||a===void 0,onClick:H,type:"button",children:s("Run")}),a!==void 0&&r(E,{variant:"outline",children:a.kind}),o&&f.trim()!==""&&r(E,{"data-testid":"run-as-badge",variant:"secondary",children:s("as {userId}",{userId:f.trim()})})]})]}),x==="error"&&I!==null&&r("pre",{className:"overflow-auto rounded-md border border-border bg-muted/50 p-3 font-mono text-xs text-destructive","data-testid":"error",role:"alert",children:I}),x==="success"&&r("pre",{className:"overflow-auto rounded-md border border-border bg-muted/50 p-3 font-mono text-xs","data-testid":"result",children:me(K)}),A.length>0&&r("ul",{className:"flex flex-col overflow-hidden rounded-xl border border-border","data-testid":"fn-history",children:A.map((e,d)=>n("li",{className:"flex flex-wrap items-center gap-2 border-b border-border px-3 py-2 text-sm last:border-b-0","data-testid":"fn-history-row",children:[r("span",{className:e.status==="success"?"text-success":"text-destructive","data-testid":`fn-history-status-${d.toString()}`,children:e.status==="success"?"✓":"✗"})," ",n("span",{className:"font-mono text-xs",children:[e.path," (",e.kind,")"]})," ",r("time",{className:"text-xs text-muted-foreground",children:te(e.at)})," ",r(N,{className:"ml-auto","data-testid":`fn-history-load-${d.toString()}`,onClick:()=>{M(e)},size:"xs",type:"button",variant:"ghost",children:s("Load")})]},e.id))})]})};export{Ae as FunctionRunner};
@@ -1 +1 @@
1
- import{c as Q}from"react/compiler-runtime";import{useState as U}from"react";import{E as V}from"../packem_shared/error-alert-CKqB2CiN.js";import{L as W}from"../packem_shared/live-status-Bf7rR8o8.js";import{ShardInput as G}from"../packem_shared/ShardInput-CdawpUiS.js";import{B as J}from"../packem_shared/badge-cAk9Di1Q.js";import{B as X}from"../packem_shared/button-BOPLD1un.js";import{C as Y,a as Z}from"../packem_shared/card-BGlQzQY-.js";import{E as ee}from"../packem_shared/empty-state-B939z6K2.js";import{T as te,a as re,b as L,c as a,d as le,e as n}from"../packem_shared/table-BMsuYFhk.js";import{u as se}from"../packem_shared/use-admin-query-DV9xmFl8.js";import{u as ae}from"../packem_shared/use-shard-key-BsP3o5wT.js";import{useT as ne}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.js";import{ADMIN_FUNCTIONS as oe}from"../packem_shared/ADMIN_FUNCTIONS-B6z7VLYt.js";import{i as ie}from"../packem_shared/internal-7bgd8inO.js";import{c as j}from"../packem_shared/utils-bhneXptQ.js";import{jsx as t,jsxs as y}from"react/jsx-runtime";const ce={action:"outline",mutation:"default",query:"secondary"},q=r=>r<1e3?`${r<10?r.toFixed(1):Math.round(r).toString()}ms`:`${(r/1e3).toFixed(2)}s`,de=r=>r.calls===0?"—":r.errors===0?"0":`${r.errors.toString()} (${(r.errors/r.calls*100).toFixed(1)}%)`,me=r=>{const e=r.conflicts??0;return r.calls===0?"—":e===0?"0":`${e.toString()} (${(e/r.calls*100).toFixed(1)}%)`},ue={calls:(r,e)=>e.calls-r.calls,recent:(r,e)=>e.lastCalledAt-r.lastCalledAt,slowest:(r,e)=>e.maxDurationMs-r.maxDurationMs},Ae=r=>{const e=Q(47),{functions:I,initialShardKey:P}=r,s=ne(),{queryShardKey:F,setShardKey:N,shardKey:S}=ae(P),[o,H]=U("recent");let M;e[0]===Symbol.for("react.memo_cache_sentinel")?(M={},e[0]=M):M=e[0];let T;e[1]!==F?(T={live:!0,shardKey:F},e[1]=F,e[2]=T):T=e[2];const{data:O,error:i,errorSource:b,liveError:v}=se(oe.getFunctionStats,M,T),k=O?.functions??null;let w;e[3]!==I?(w=new Map((I??[]).map(fe)),e[3]=I,e[4]=w):w=e[4];const _=w;let E;e[5]===Symbol.for("react.memo_cache_sentinel")?(E=C=>{H(C.currentTarget.dataset.sort)},e[5]=E):E=e[5];const z=E;let K;if(e[6]!==i||e[7]!==b||e[8]!==_||e[9]!==v||e[10]!==N||e[11]!==S||e[12]!==o||e[13]!==k||e[14]!==s){const C=k===null?[]:k.toSorted(ue[o]);let c;e[16]!==s?(c=s("Recent"),e[16]=s,e[17]=c):c=e[17];let d;e[18]!==c?(d={key:"recent",label:c},e[18]=c,e[19]=d):d=e[19];let m;e[20]!==s?(m=s("Most called"),e[20]=s,e[21]=m):m=e[21];let u;e[22]!==m?(u={key:"calls",label:m},e[22]=m,e[23]=u):u=e[23];let f;e[24]!==s?(f=s("Slowest"),e[24]=s,e[25]=f):f=e[25];let h;e[26]!==f?(h={key:"slowest",label:f},e[26]=f,e[27]=h):h=e[27];let $;e[28]!==h||e[29]!==d||e[30]!==u?($=[d,u,h],e[28]=h,e[29]=d,e[30]=u,e[31]=$):$=e[31];const D=$;let p;e[32]!==N||e[33]!==S?(p=t(G,{onChange:N,testId:"fs-shard-input",value:S}),e[32]=N,e[33]=S,e[34]=p):p=e[34];let x;e[35]!==v?(x=t(W,{message:v,prefix:"fs"}),e[35]=v,e[36]=x):x=e[36];let g;e[37]!==D||e[38]!==o?(g=t("div",{className:"ml-auto flex items-center gap-1",role:"group",children:D.map(l=>t(X,{"data-sort":l.key,"data-testid":`fs-sort-${l.key}`,onClick:z,size:"sm",type:"button",variant:o===l.key?"secondary":"ghost",children:l.label},l.key))}),e[37]=D,e[38]=o,e[39]=g):g=e[39];let A;e[40]!==p||e[41]!==x||e[42]!==g?(A=y("div",{className:"flex flex-wrap items-center gap-2",children:[p,x,g]}),e[40]=p,e[41]=x,e[42]=g,e[43]=A):A=e[43];let B;e[44]!==i||e[45]!==b?(B=i!==null&&t(V,{error:b,testId:"fs-error"}),e[44]=i,e[45]=b,e[46]=B):B=e[46],K=y("div",{className:"flex flex-col gap-4","data-testid":"lunora-function-stats",children:[A,B,k!==null&&C.length===0&&i===null&&t(ee,{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:[t("path",{d:"M3 3v18h18"}),t("path",{d:"M7 14l4-4 3 3 5-6"})]}),testId:"fs-empty",title:s("No functions have run on this shard yet.")}),C.length>0&&t(Y,{className:"overflow-hidden py-0",children:t(Z,{className:"px-0",children:y(te,{"data-testid":"fs-table",children:[t(re,{children:y(L,{children:[t(a,{children:s("function")}),t(a,{children:s("kind")}),t(a,{className:"text-right",children:s("calls")}),t(a,{className:"text-right",children:s("errors")}),t(a,{className:"text-right",children:s("conflicts")}),t(a,{className:"text-right",children:s("avg")}),t(a,{className:"text-right",children:s("max")}),t(a,{children:s("last run")}),t(a,{children:s("last error")})]})}),t(le,{children:C.map(l=>{const R=_.get(l.path);return y(L,{"data-testid":`fs-row-${l.path}`,children:[t(n,{className:"font-medium",children:l.path}),t(n,{children:R===void 0?t("span",{className:"text-muted-foreground",children:"—"}):t(J,{variant:ce[R],children:R})}),t(n,{className:"text-right tabular-nums",children:l.calls}),t(n,{className:j("text-right tabular-nums",l.errors>0&&"text-destructive"),children:de(l)}),t(n,{className:j("text-right tabular-nums",(l.conflicts??0)>0&&"text-warning"),children:me(l)}),t(n,{className:"text-right tabular-nums",children:l.calls===0?"—":q(l.totalDurationMs/l.calls)}),t(n,{className:"text-right tabular-nums",children:l.calls===0?"—":q(l.maxDurationMs)}),t(n,{className:"text-muted-foreground",children:ie(l.lastCalledAt,"—")}),t(n,{className:"max-w-[24ch] truncate text-destructive",title:l.lastErrorMessage??void 0,children:l.lastErrorMessage??t("span",{className:"text-muted-foreground",children:"—"})})]},l.path)})})]})})})]}),e[6]=i,e[7]=b,e[8]=_,e[9]=v,e[10]=N,e[11]=S,e[12]=o,e[13]=k,e[14]=s,e[15]=K}else K=e[15];return K};function fe(r){return[r.path,r.kind]}export{Ae as FunctionStatsPanel};
1
+ import{c as Q}from"react/compiler-runtime";import{useState as U}from"react";import{E as V}from"../packem_shared/error-alert-TYdKetJd.js";import{L as W}from"../packem_shared/live-status-Bf7rR8o8.js";import{ShardInput as G}from"../packem_shared/ShardInput-CdawpUiS.js";import{B as J}from"../packem_shared/badge-cAk9Di1Q.js";import{B as X}from"../packem_shared/button-BOPLD1un.js";import{C as Y,a as Z}from"../packem_shared/card-BGlQzQY-.js";import{E as ee}from"../packem_shared/empty-state-B939z6K2.js";import{T as te,a as re,b as L,c as a,d as le,e as n}from"../packem_shared/table-BMsuYFhk.js";import{u as se}from"../packem_shared/use-admin-query-P0RJrjsD.js";import{u as ae}from"../packem_shared/use-shard-key-BsP3o5wT.js";import{useT as ne}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.js";import{ADMIN_FUNCTIONS as oe}from"../packem_shared/ADMIN_FUNCTIONS-B6z7VLYt.js";import{i as ie}from"../packem_shared/internal-CwaF9YNk.js";import{c as j}from"../packem_shared/utils-bhneXptQ.js";import{jsx as t,jsxs as y}from"react/jsx-runtime";const ce={action:"outline",mutation:"default",query:"secondary"},q=r=>r<1e3?`${r<10?r.toFixed(1):Math.round(r).toString()}ms`:`${(r/1e3).toFixed(2)}s`,de=r=>r.calls===0?"—":r.errors===0?"0":`${r.errors.toString()} (${(r.errors/r.calls*100).toFixed(1)}%)`,me=r=>{const e=r.conflicts??0;return r.calls===0?"—":e===0?"0":`${e.toString()} (${(e/r.calls*100).toFixed(1)}%)`},ue={calls:(r,e)=>e.calls-r.calls,recent:(r,e)=>e.lastCalledAt-r.lastCalledAt,slowest:(r,e)=>e.maxDurationMs-r.maxDurationMs},Ae=r=>{const e=Q(47),{functions:I,initialShardKey:P}=r,s=ne(),{queryShardKey:F,setShardKey:N,shardKey:S}=ae(P),[o,H]=U("recent");let M;e[0]===Symbol.for("react.memo_cache_sentinel")?(M={},e[0]=M):M=e[0];let T;e[1]!==F?(T={live:!0,shardKey:F},e[1]=F,e[2]=T):T=e[2];const{data:O,error:i,errorSource:b,liveError:v}=se(oe.getFunctionStats,M,T),k=O?.functions??null;let w;e[3]!==I?(w=new Map((I??[]).map(fe)),e[3]=I,e[4]=w):w=e[4];const _=w;let E;e[5]===Symbol.for("react.memo_cache_sentinel")?(E=C=>{H(C.currentTarget.dataset.sort)},e[5]=E):E=e[5];const z=E;let K;if(e[6]!==i||e[7]!==b||e[8]!==_||e[9]!==v||e[10]!==N||e[11]!==S||e[12]!==o||e[13]!==k||e[14]!==s){const C=k===null?[]:k.toSorted(ue[o]);let c;e[16]!==s?(c=s("Recent"),e[16]=s,e[17]=c):c=e[17];let d;e[18]!==c?(d={key:"recent",label:c},e[18]=c,e[19]=d):d=e[19];let m;e[20]!==s?(m=s("Most called"),e[20]=s,e[21]=m):m=e[21];let u;e[22]!==m?(u={key:"calls",label:m},e[22]=m,e[23]=u):u=e[23];let f;e[24]!==s?(f=s("Slowest"),e[24]=s,e[25]=f):f=e[25];let h;e[26]!==f?(h={key:"slowest",label:f},e[26]=f,e[27]=h):h=e[27];let $;e[28]!==h||e[29]!==d||e[30]!==u?($=[d,u,h],e[28]=h,e[29]=d,e[30]=u,e[31]=$):$=e[31];const D=$;let p;e[32]!==N||e[33]!==S?(p=t(G,{onChange:N,testId:"fs-shard-input",value:S}),e[32]=N,e[33]=S,e[34]=p):p=e[34];let x;e[35]!==v?(x=t(W,{message:v,prefix:"fs"}),e[35]=v,e[36]=x):x=e[36];let g;e[37]!==D||e[38]!==o?(g=t("div",{className:"ml-auto flex items-center gap-1",role:"group",children:D.map(l=>t(X,{"data-sort":l.key,"data-testid":`fs-sort-${l.key}`,onClick:z,size:"sm",type:"button",variant:o===l.key?"secondary":"ghost",children:l.label},l.key))}),e[37]=D,e[38]=o,e[39]=g):g=e[39];let A;e[40]!==p||e[41]!==x||e[42]!==g?(A=y("div",{className:"flex flex-wrap items-center gap-2",children:[p,x,g]}),e[40]=p,e[41]=x,e[42]=g,e[43]=A):A=e[43];let B;e[44]!==i||e[45]!==b?(B=i!==null&&t(V,{error:b,testId:"fs-error"}),e[44]=i,e[45]=b,e[46]=B):B=e[46],K=y("div",{className:"flex flex-col gap-4","data-testid":"lunora-function-stats",children:[A,B,k!==null&&C.length===0&&i===null&&t(ee,{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:[t("path",{d:"M3 3v18h18"}),t("path",{d:"M7 14l4-4 3 3 5-6"})]}),testId:"fs-empty",title:s("No functions have run on this shard yet.")}),C.length>0&&t(Y,{className:"overflow-hidden py-0",children:t(Z,{className:"px-0",children:y(te,{"data-testid":"fs-table",children:[t(re,{children:y(L,{children:[t(a,{children:s("function")}),t(a,{children:s("kind")}),t(a,{className:"text-right",children:s("calls")}),t(a,{className:"text-right",children:s("errors")}),t(a,{className:"text-right",children:s("conflicts")}),t(a,{className:"text-right",children:s("avg")}),t(a,{className:"text-right",children:s("max")}),t(a,{children:s("last run")}),t(a,{children:s("last error")})]})}),t(le,{children:C.map(l=>{const R=_.get(l.path);return y(L,{"data-testid":`fs-row-${l.path}`,children:[t(n,{className:"font-medium",children:l.path}),t(n,{children:R===void 0?t("span",{className:"text-muted-foreground",children:"—"}):t(J,{variant:ce[R],children:R})}),t(n,{className:"text-right tabular-nums",children:l.calls}),t(n,{className:j("text-right tabular-nums",l.errors>0&&"text-destructive"),children:de(l)}),t(n,{className:j("text-right tabular-nums",(l.conflicts??0)>0&&"text-warning"),children:me(l)}),t(n,{className:"text-right tabular-nums",children:l.calls===0?"—":q(l.totalDurationMs/l.calls)}),t(n,{className:"text-right tabular-nums",children:l.calls===0?"—":q(l.maxDurationMs)}),t(n,{className:"text-muted-foreground",children:ie(l.lastCalledAt,"—")}),t(n,{className:"max-w-[24ch] truncate text-destructive",title:l.lastErrorMessage??void 0,children:l.lastErrorMessage??t("span",{className:"text-muted-foreground",children:"—"})})]},l.path)})})]})})})]}),e[6]=i,e[7]=b,e[8]=_,e[9]=v,e[10]=N,e[11]=S,e[12]=o,e[13]=k,e[14]=s,e[15]=K}else K=e[15];return K};function fe(r){return[r.path,r.kind]}export{Ae as FunctionStatsPanel};
@@ -1 +1 @@
1
- import{c as ae}from"react/compiler-runtime";import{useLunora as pe}from"@lunora/react";import{useState as E,useRef as D,useEffect as j,useCallback as ge}from"react";import xe from"../packem_shared/ConnectionBadge-Bh16X9-u.js";import{L as ve}from"../packem_shared/live-status-Bf7rR8o8.js";import{B as G}from"../packem_shared/badge-cAk9Di1Q.js";import{C as M}from"../packem_shared/card-BGlQzQY-.js";import{u as Ne}from"../packem_shared/use-admin-query-DV9xmFl8.js";import{useT as le}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.js";import{ADMIN_FUNCTIONS as A}from"../packem_shared/ADMIN_FUNCTIONS-B6z7VLYt.js";import{i as be,f as $,d as ee,b as te,c as _}from"../packem_shared/internal-7bgd8inO.js";import{l as we}from"../packem_shared/shard-history-DU5b3QDI.js";import{c as R}from"../packem_shared/utils-bhneXptQ.js";import{jsx as l,jsxs as u}from"react/jsx-runtime";import{shardsToAggregate as Ee}from"../packem_shared/aggregateMetrics-A-Y7OH6R.js";import{S as z}from"../packem_shared/sparkline-CYbJzfA1.js";const Se={crit:"destructive",ok:"secondary",warn:"default"},P=(s,e)=>e===0?"—":`${(s/e*100).toFixed(1)}%`,Q=(s,e,r)=>Number.isNaN(s)?"ok":s>=r?"crit":s>=e?"warn":"ok",ne=.01,oe=.05,ye=s=>{const e=ae(36),{errorCount:r,logsError:t,topErrors:a,worstFunctions:f}=s,o=le();let n;e[0]!==o?(n=o("Functions by error rate"),e[0]=o,e[1]=n):n=e[1];let h;e[2]!==n?(h=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:n})}),e[2]=n,e[3]=h):h=e[3];let m;e[4]!==o||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:o("No function activity yet.")}):l("ul",{className:"divide-y divide-border",children:f.map(b=>u("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}),u("span",{className:"flex shrink-0 items-center gap-2",children:[l("span",{className:"tabular-nums text-muted-foreground",children:o("{count} calls",{count:b.calls.toString()})}),l(G,{variant:Se[Q(b.errors/b.calls,ne,oe)],children:P(b.errors,b.calls)})]})]},b.path))}),e[4]=o,e[5]=f,e[6]=m):m=e[6];let p;e[7]!==h||e[8]!==m?(p=u(M,{className:"gap-0 py-0","data-testid":"hl-functions",children:[h,m]}),e[7]=h,e[8]=m,e[9]=p):p=e[9];let v;e[10]!==o?(v=o("Recent errors"),e[10]=o,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(G,{"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=u("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 S;e[20]!==t?(S=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]=S):S=e[21];let y;e[22]!==t||e[23]!==o||e[24]!==a.length?(y=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:o("No recent errors.")}),e[22]=t,e[23]=o,e[24]=a.length,e[25]=y):y=e[25];let T;e[26]!==a?(T=a.length>0&&l("ul",{className:"divide-y divide-border",children:a.map(Te)}),e[26]=a,e[27]=T):T=e[27];let N;e[28]!==S||e[29]!==y||e[30]!==T||e[31]!==x?(N=u(M,{className:"gap-0 py-0",children:[x,S,y,T]}),e[28]=S,e[29]=y,e[30]=T,e[31]=x,e[32]=N):N=e[32];let w;return e[33]!==N||e[34]!==p?(w=u("div",{className:"grid gap-3 lg:grid-cols-2",children:[p,N]}),e[33]=N,e[34]=p,e[35]=w):w=e[35],w};function Te(s,e){return u("li",{className:"flex flex-col gap-0.5 px-4 py-2 text-xs","data-testid":"hl-error-row",children:[u("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},Ae=s=>{let e=0,r=0,t=0,a=0,f=!1;const o=[];for(const{metrics:n}of s){if(n===null){a+=1;continue}t+=1,e+=n.requests,r+=n.errors,o.push(...n.history??[]),f||=n.historyTruncated===!0}return{errors:r,failed:a,history:o,historyTruncated:f,reachable:t,requests:e}},ke=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()]},Re=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()]},Me=_(A.getAuthMetrics),_e=_(A.getFunctionStats),Le=_(A.getLogs),Ie=_(A.getMetrics),Ce=_(A.migrationStatus),qe=5,se=2e3,Oe=5,Fe=.1,De=.3,je=1,Ue=50,Pe=(s,e,r)=>s>=r?"crit":s>=e?"warn":"ok",Ge=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)}},Ve=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}},Be=(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"},He={crit:"bg-destructive/10 text-destructive",ok:"bg-success/10 text-success",warn:"bg-warning/10 text-warning"},Ke=s=>s.includes("crit")?"crit":s.includes("warn")?"warn":"ok",U=s=>{const e=ae(19),{chart:r,label:t,level:a,testId:f,value:o}=s,n=ie[a];let h;e[0]!==n?(h=R("size-1.5 shrink-0 rounded-full",n),e[0]=n,e[1]=h):h=e[1];let m;e[2]!==h?(m=l("span",{"aria-hidden":"true",className:h}),e[2]=h,e[3]=m):m=e[3];let p;e[4]!==t||e[5]!==m?(p=u("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]=p):p=e[6];const v=ce[a];let i;e[7]!==v?(i=R("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]!==o?(c=l("span",{className:i,"data-testid":f,children:o}),e[9]=i,e[10]=f,e[11]=o,e[12]=c):c=e[12];let g;e[13]!==r||e[14]!==c?(g=u("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]!==p||e[17]!==g?(x=l(M,{className:"gap-0 py-0",children:u("div",{className:"flex flex-col gap-2.5 p-4",children:[p,g]})}),e[16]=p,e[17]=g,e[18]=x):x=e[18],x},$e=async(s,e,r)=>{const t=await Promise.all(r.map(i=>{const c=ee(i);return Promise.allSettled([s.query(Ie,{},c),s.query(_e,{},c),s.query(Ce,{},c)])})),a=ee(e),f=typeof s.schedulerStatus=="function"?s.schedulerStatus():Promise.reject(new Error("scheduler status unavailable")),[o,n,h]=await Promise.allSettled([s.query(Le,{},a),s.query(Me,{},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:[]})),p=Ae(m),v=t[0]?.[0];return{auth:n.status==="fulfilled"?n.value:null,entries:o.status==="fulfilled"?o.value.entries:[],functions:ke(m.map(i=>i.functions)),logsError:o.status==="rejected"?te(o.reason):null,metricsError:p.reachable===0&&v?.status==="rejected"?te(v.reason):null,migrations:Re(m.map(i=>i.migrations)),scheduler:h.status==="fulfilled"?h.value:null,totals:p}},ze=s=>{const e=s?.history??[];return{attempts:e.map(r=>r.attempts),failures:e.map(r=>r.failures)}},ut=({initialShardKey:s})=>{const e=pe(),r=le(),[t,a]=E([]),[f,o]=E(null),[n,h]=E(null),[m,p]=E(null),[v,i]=E([]),[c,g]=E(null),[x,S]=E(null),[y,T]=E([]),[N]=E(we),w=D(!1),b=D(!0);j(()=>(b.current=!0,()=>{b.current=!1}),[]);const L=s??"",I=ge(async()=>{if(w.current)return;w.current=!0;const d=await $e(e,L,Ee(L,N));if(!b.current){w.current=!1;return}h(d.totals),p(d.metricsError),i(d.functions),T(d.migrations),a(d.entries),o(d.logsError),g(d.auth),S(d.scheduler),w.current=!1},[e,N,L]);j(()=>{$(I())},[I]);const V=D(0),k=D(null),ue=()=>{const d=Date.now()-V.current;if(d>=se){V.current=Date.now(),$(I());return}k.current===null&&(k.current=setTimeout(()=>{k.current=null,V.current=Date.now(),$(I())},se-d))};j(()=>()=>{k.current!==null&&clearTimeout(k.current)},[]);const{data:W,liveError:de}=Ne(A.getMetrics,{},{live:!0,shardKey:L});j(()=>{W!==void 0&&ue()},[W]);const X=t.filter(d=>d.level==="error"),me=X.slice(0,qe),C=Ge(n?.history),J=ze(c),fe=v.filter(d=>d.calls>0).toSorted((d,K)=>K.errors/K.calls-d.errors/d.calls||K.calls-d.calls).slice(0,Oe),B=Ve(y),he=n===null||n.requests===0?0:n.errors/n.requests,H=Q(he,ne,oe),Y=c===null?"ok":Q(c.failureRate,Fe,De),Z=x===null?"ok":Pe(x.backlog,je,Ue),q=Ke([H,Y,Z,B.level]);let O,F;return q==="crit"?(O=r("Critical"),F=r("One or more service levels are breached.")):q==="warn"?(O=r("Degraded"),F=r("Some service levels need attention.")):(O=r("All systems healthy"),F=r("All service levels are within target.")),u("div",{className:"flex flex-col gap-6","data-testid":"lunora-health",children:[u(M,{className:"gap-0 py-0",children:[u("div",{className:"flex flex-wrap items-center justify-between gap-4 p-4",children:[u("div",{className:"flex items-center gap-3",children:[l("span",{"aria-hidden":"true",className:R("flex size-10 shrink-0 items-center justify-center rounded-full",He[q]),children:l("span",{className:R("size-3 rounded-full",ie[q])})}),u("div",{className:"grid leading-tight",children:[l("span",{className:"text-sm font-semibold text-foreground","data-testid":"hl-status",children:O}),l("span",{className:"text-[13px] text-muted-foreground",children:F})]})]}),u("div",{className:"flex flex-wrap items-center gap-4",children:[u("div",{className:"text-end",children:[l("div",{className:"font-mono text-[10px] tracking-wide text-muted-foreground uppercase",children:r("Requests")}),u("div",{className:"flex items-center justify-end gap-2",children:[C.requests.length>=2&&l(z,{ariaLabel:r("Requests over time"),className:"h-6 w-20 text-foreground",series:C.requests,testId:"hl-spark-requests"}),l("span",{className:"text-lg font-semibold tabular-nums text-foreground","data-testid":"hl-requests",children:(n?.requests??0).toString()})]})]}),l("span",{"aria-hidden":"true",className:"h-9 w-px bg-border"}),u("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:R("text-lg font-semibold tabular-nums",ce[H]),"data-testid":"hl-error-rate",children:n===null?"—":P(n.errors,n.requests)})]}),l("span",{"aria-hidden":"true",className:"h-9 w-px bg-border"}),u("div",{className:"flex items-center gap-2",children:[l(xe,{}),l(ve,{message:de,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}),m===null&&n?.historyTruncated===!0&&l("div",{className:"border-t border-border bg-warning/5 px-4 py-2 text-sm text-muted-foreground","data-testid":"hl-history-truncated",children:r("Showing a partial request/error history — one or more shards have more data than the trend chart can display.")})]}),u("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4","data-testid":"hl-slo",children:[l(U,{chart:C.errors.length>=2?l(z,{ariaLabel:r("Errors over time"),className:"h-7 w-20 text-destructive",series:C.errors,testId:"hl-spark-errors"}):void 0,label:r("Error rate"),level:H,testId:"hl-slo-errorrate",value:n===null?"—":P(n.errors,n.requests)}),l(U,{chart:J.failures.length>=2?l(z,{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:Y,testId:"hl-slo-auth",value:c===null?"—":P(c.failures,c.attempts)}),l(U,{label:r("Scheduler backlog"),level:Z,testId:"hl-slo-backlog",value:x===null?"—":x.backlog.toString()}),l(U,{label:r("Migrations"),level:B.level,testId:"hl-slo-migrations",value:Be(B,r)})]}),l(ye,{errorCount:X.length,logsError:f,topErrors:me,worstFunctions:fe}),u(M,{className:"gap-0 py-0",children:[u("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(G,{"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(d=>l("li",{"data-testid":"hl-shard",children:l(G,{variant:"secondary",children:d})},d))})]})]})};export{ut as HealthPanel};
1
+ import{c as ae}from"react/compiler-runtime";import{useLunora as pe}from"@lunora/react";import{useState as E,useRef as D,useEffect as j,useCallback as ge}from"react";import xe from"../packem_shared/ConnectionBadge-Bh16X9-u.js";import{L as ve}from"../packem_shared/live-status-Bf7rR8o8.js";import{B as G}from"../packem_shared/badge-cAk9Di1Q.js";import{C as M}from"../packem_shared/card-BGlQzQY-.js";import{u as Ne}from"../packem_shared/use-admin-query-P0RJrjsD.js";import{useT as le}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.js";import{ADMIN_FUNCTIONS as A}from"../packem_shared/ADMIN_FUNCTIONS-B6z7VLYt.js";import{i as be,f as $,d as ee,b as te,c as _}from"../packem_shared/internal-CwaF9YNk.js";import{l as we}from"../packem_shared/shard-history-DU5b3QDI.js";import{c as R}from"../packem_shared/utils-bhneXptQ.js";import{jsx as l,jsxs as u}from"react/jsx-runtime";import{shardsToAggregate as Ee}from"../packem_shared/aggregateMetrics-A-Y7OH6R.js";import{S as z}from"../packem_shared/sparkline-CYbJzfA1.js";const Se={crit:"destructive",ok:"secondary",warn:"default"},P=(s,e)=>e===0?"—":`${(s/e*100).toFixed(1)}%`,Q=(s,e,r)=>Number.isNaN(s)?"ok":s>=r?"crit":s>=e?"warn":"ok",ne=.01,oe=.05,ye=s=>{const e=ae(36),{errorCount:r,logsError:t,topErrors:a,worstFunctions:f}=s,o=le();let n;e[0]!==o?(n=o("Functions by error rate"),e[0]=o,e[1]=n):n=e[1];let h;e[2]!==n?(h=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:n})}),e[2]=n,e[3]=h):h=e[3];let m;e[4]!==o||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:o("No function activity yet.")}):l("ul",{className:"divide-y divide-border",children:f.map(b=>u("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}),u("span",{className:"flex shrink-0 items-center gap-2",children:[l("span",{className:"tabular-nums text-muted-foreground",children:o("{count} calls",{count:b.calls.toString()})}),l(G,{variant:Se[Q(b.errors/b.calls,ne,oe)],children:P(b.errors,b.calls)})]})]},b.path))}),e[4]=o,e[5]=f,e[6]=m):m=e[6];let p;e[7]!==h||e[8]!==m?(p=u(M,{className:"gap-0 py-0","data-testid":"hl-functions",children:[h,m]}),e[7]=h,e[8]=m,e[9]=p):p=e[9];let v;e[10]!==o?(v=o("Recent errors"),e[10]=o,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(G,{"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=u("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 S;e[20]!==t?(S=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]=S):S=e[21];let y;e[22]!==t||e[23]!==o||e[24]!==a.length?(y=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:o("No recent errors.")}),e[22]=t,e[23]=o,e[24]=a.length,e[25]=y):y=e[25];let T;e[26]!==a?(T=a.length>0&&l("ul",{className:"divide-y divide-border",children:a.map(Te)}),e[26]=a,e[27]=T):T=e[27];let N;e[28]!==S||e[29]!==y||e[30]!==T||e[31]!==x?(N=u(M,{className:"gap-0 py-0",children:[x,S,y,T]}),e[28]=S,e[29]=y,e[30]=T,e[31]=x,e[32]=N):N=e[32];let w;return e[33]!==N||e[34]!==p?(w=u("div",{className:"grid gap-3 lg:grid-cols-2",children:[p,N]}),e[33]=N,e[34]=p,e[35]=w):w=e[35],w};function Te(s,e){return u("li",{className:"flex flex-col gap-0.5 px-4 py-2 text-xs","data-testid":"hl-error-row",children:[u("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},Ae=s=>{let e=0,r=0,t=0,a=0,f=!1;const o=[];for(const{metrics:n}of s){if(n===null){a+=1;continue}t+=1,e+=n.requests,r+=n.errors,o.push(...n.history??[]),f||=n.historyTruncated===!0}return{errors:r,failed:a,history:o,historyTruncated:f,reachable:t,requests:e}},ke=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()]},Re=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()]},Me=_(A.getAuthMetrics),_e=_(A.getFunctionStats),Le=_(A.getLogs),Ie=_(A.getMetrics),Ce=_(A.migrationStatus),qe=5,se=2e3,Oe=5,Fe=.1,De=.3,je=1,Ue=50,Pe=(s,e,r)=>s>=r?"crit":s>=e?"warn":"ok",Ge=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)}},Ve=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}},Be=(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"},He={crit:"bg-destructive/10 text-destructive",ok:"bg-success/10 text-success",warn:"bg-warning/10 text-warning"},Ke=s=>s.includes("crit")?"crit":s.includes("warn")?"warn":"ok",U=s=>{const e=ae(19),{chart:r,label:t,level:a,testId:f,value:o}=s,n=ie[a];let h;e[0]!==n?(h=R("size-1.5 shrink-0 rounded-full",n),e[0]=n,e[1]=h):h=e[1];let m;e[2]!==h?(m=l("span",{"aria-hidden":"true",className:h}),e[2]=h,e[3]=m):m=e[3];let p;e[4]!==t||e[5]!==m?(p=u("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]=p):p=e[6];const v=ce[a];let i;e[7]!==v?(i=R("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]!==o?(c=l("span",{className:i,"data-testid":f,children:o}),e[9]=i,e[10]=f,e[11]=o,e[12]=c):c=e[12];let g;e[13]!==r||e[14]!==c?(g=u("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]!==p||e[17]!==g?(x=l(M,{className:"gap-0 py-0",children:u("div",{className:"flex flex-col gap-2.5 p-4",children:[p,g]})}),e[16]=p,e[17]=g,e[18]=x):x=e[18],x},$e=async(s,e,r)=>{const t=await Promise.all(r.map(i=>{const c=ee(i);return Promise.allSettled([s.query(Ie,{},c),s.query(_e,{},c),s.query(Ce,{},c)])})),a=ee(e),f=typeof s.schedulerStatus=="function"?s.schedulerStatus():Promise.reject(new Error("scheduler status unavailable")),[o,n,h]=await Promise.allSettled([s.query(Le,{},a),s.query(Me,{},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:[]})),p=Ae(m),v=t[0]?.[0];return{auth:n.status==="fulfilled"?n.value:null,entries:o.status==="fulfilled"?o.value.entries:[],functions:ke(m.map(i=>i.functions)),logsError:o.status==="rejected"?te(o.reason):null,metricsError:p.reachable===0&&v?.status==="rejected"?te(v.reason):null,migrations:Re(m.map(i=>i.migrations)),scheduler:h.status==="fulfilled"?h.value:null,totals:p}},ze=s=>{const e=s?.history??[];return{attempts:e.map(r=>r.attempts),failures:e.map(r=>r.failures)}},ut=({initialShardKey:s})=>{const e=pe(),r=le(),[t,a]=E([]),[f,o]=E(null),[n,h]=E(null),[m,p]=E(null),[v,i]=E([]),[c,g]=E(null),[x,S]=E(null),[y,T]=E([]),[N]=E(we),w=D(!1),b=D(!0);j(()=>(b.current=!0,()=>{b.current=!1}),[]);const L=s??"",I=ge(async()=>{if(w.current)return;w.current=!0;const d=await $e(e,L,Ee(L,N));if(!b.current){w.current=!1;return}h(d.totals),p(d.metricsError),i(d.functions),T(d.migrations),a(d.entries),o(d.logsError),g(d.auth),S(d.scheduler),w.current=!1},[e,N,L]);j(()=>{$(I())},[I]);const V=D(0),k=D(null),ue=()=>{const d=Date.now()-V.current;if(d>=se){V.current=Date.now(),$(I());return}k.current===null&&(k.current=setTimeout(()=>{k.current=null,V.current=Date.now(),$(I())},se-d))};j(()=>()=>{k.current!==null&&clearTimeout(k.current)},[]);const{data:W,liveError:de}=Ne(A.getMetrics,{},{live:!0,shardKey:L});j(()=>{W!==void 0&&ue()},[W]);const X=t.filter(d=>d.level==="error"),me=X.slice(0,qe),C=Ge(n?.history),J=ze(c),fe=v.filter(d=>d.calls>0).toSorted((d,K)=>K.errors/K.calls-d.errors/d.calls||K.calls-d.calls).slice(0,Oe),B=Ve(y),he=n===null||n.requests===0?0:n.errors/n.requests,H=Q(he,ne,oe),Y=c===null?"ok":Q(c.failureRate,Fe,De),Z=x===null?"ok":Pe(x.backlog,je,Ue),q=Ke([H,Y,Z,B.level]);let O,F;return q==="crit"?(O=r("Critical"),F=r("One or more service levels are breached.")):q==="warn"?(O=r("Degraded"),F=r("Some service levels need attention.")):(O=r("All systems healthy"),F=r("All service levels are within target.")),u("div",{className:"flex flex-col gap-6","data-testid":"lunora-health",children:[u(M,{className:"gap-0 py-0",children:[u("div",{className:"flex flex-wrap items-center justify-between gap-4 p-4",children:[u("div",{className:"flex items-center gap-3",children:[l("span",{"aria-hidden":"true",className:R("flex size-10 shrink-0 items-center justify-center rounded-full",He[q]),children:l("span",{className:R("size-3 rounded-full",ie[q])})}),u("div",{className:"grid leading-tight",children:[l("span",{className:"text-sm font-semibold text-foreground","data-testid":"hl-status",children:O}),l("span",{className:"text-[13px] text-muted-foreground",children:F})]})]}),u("div",{className:"flex flex-wrap items-center gap-4",children:[u("div",{className:"text-end",children:[l("div",{className:"font-mono text-[10px] tracking-wide text-muted-foreground uppercase",children:r("Requests")}),u("div",{className:"flex items-center justify-end gap-2",children:[C.requests.length>=2&&l(z,{ariaLabel:r("Requests over time"),className:"h-6 w-20 text-foreground",series:C.requests,testId:"hl-spark-requests"}),l("span",{className:"text-lg font-semibold tabular-nums text-foreground","data-testid":"hl-requests",children:(n?.requests??0).toString()})]})]}),l("span",{"aria-hidden":"true",className:"h-9 w-px bg-border"}),u("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:R("text-lg font-semibold tabular-nums",ce[H]),"data-testid":"hl-error-rate",children:n===null?"—":P(n.errors,n.requests)})]}),l("span",{"aria-hidden":"true",className:"h-9 w-px bg-border"}),u("div",{className:"flex items-center gap-2",children:[l(xe,{}),l(ve,{message:de,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}),m===null&&n?.historyTruncated===!0&&l("div",{className:"border-t border-border bg-warning/5 px-4 py-2 text-sm text-muted-foreground","data-testid":"hl-history-truncated",children:r("Showing a partial request/error history — one or more shards have more data than the trend chart can display.")})]}),u("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4","data-testid":"hl-slo",children:[l(U,{chart:C.errors.length>=2?l(z,{ariaLabel:r("Errors over time"),className:"h-7 w-20 text-destructive",series:C.errors,testId:"hl-spark-errors"}):void 0,label:r("Error rate"),level:H,testId:"hl-slo-errorrate",value:n===null?"—":P(n.errors,n.requests)}),l(U,{chart:J.failures.length>=2?l(z,{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:Y,testId:"hl-slo-auth",value:c===null?"—":P(c.failures,c.attempts)}),l(U,{label:r("Scheduler backlog"),level:Z,testId:"hl-slo-backlog",value:x===null?"—":x.backlog.toString()}),l(U,{label:r("Migrations"),level:B.level,testId:"hl-slo-migrations",value:Be(B,r)})]}),l(ye,{errorCount:X.length,logsError:f,topErrors:me,worstFunctions:fe}),u(M,{className:"gap-0 py-0",children:[u("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(G,{"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(d=>l("li",{"data-testid":"hl-shard",children:l(G,{variant:"secondary",children:d})},d))})]})]})};export{ut as HealthPanel};
@@ -1 +1 @@
1
- import{c as J}from"react/compiler-runtime";import{useLunora as se}from"@lunora/react";import{useNavigate as re}from"@tanstack/react-router";import{useState as K,useRef as ae,useEffectEvent as O,useEffect as Q,useCallback as oe,useMemo as ie}from"react";import{ShardInput as ce}from"../packem_shared/ShardInput-CdawpUiS.js";import{B as le}from"../packem_shared/button-BOPLD1un.js";import{u as N}from"../packem_shared/use-admin-query-DV9xmFl8.js";import{u as de}from"../packem_shared/use-shard-key-BsP3o5wT.js";import{useT as R}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.js";import{ADMIN_FUNCTIONS as A}from"../packem_shared/ADMIN_FUNCTIONS-B6z7VLYt.js";import{s as L,f as E,d as k,c as q}from"../packem_shared/internal-7bgd8inO.js";import{r as ue}from"../packem_shared/shard-history-DU5b3QDI.js";import{a as U,A as fe}from"../packem_shared/advisor-view-CqCG22DB.js";import{ConfirmButton as me}from"../packem_shared/ConfirmButton-Cj2SOapE.js";import{jsx as g}from"react/jsx-runtime";import{deriveInsights as he}from"../packem_shared/DEFAULT_INSIGHT_THRESHOLDS-1Lrg55IV.js";import{runAdvisor as pe,RUNTIME_LINTS as be}from"@lunora/advisor";const xe=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)},ye=(t,e,r)=>{const n=L(t),s=L(e),i=r.map(c=>L(c)).join(", ");return`CREATE INDEX IF NOT EXISTS ${s} ON ${n} (${i});`},ve=t=>{const e=J(19),{fields:r,indexName:n,table:s,testId:i}=t,c=R(),[v,h]=K(!1);let u;e[0]!==r||e[1]!==n||e[2]!==s?(u=()=>{const y="navigator"in globalThis?globalThis.navigator.clipboard:void 0;if(y===void 0)return;const x=ye(s,n,r);E(y.writeText(x)),h(!0)},e[0]=r,e[1]=n,e[2]=s,e[3]=u):u=e[3];const I=u;if(v){const y=`${i}-applied`;let x;e[4]!==c?(x=c("CREATE INDEX SQL copied to clipboard."),e[4]=c,e[5]=x):x=e[5];let w;return e[6]!==y||e[7]!==x?(w=g("span",{className:"text-xs text-muted-foreground","data-testid":y,children:x}),e[6]=y,e[7]=x,e[8]=w):w=e[8],w}let d;e[9]!==c?(d=c("Apply?"),e[9]=c,e[10]=d):d=e[10];let f;e[11]!==c||e[12]!==s?(f=c("Apply index on {table}",{table:s}),e[11]=c,e[12]=s,e[13]=f):f=e[13];let b;return e[14]!==I||e[15]!==d||e[16]!==f||e[17]!==i?(b=g(me,{confirmLabel:d,onConfirm:I,testId:i,children:f}),e[14]=I,e[15]=d,e[16]=f,e[17]=i,e[18]=b):b=e[18],b},Se=(t,e)=>{const r=new Map;for(const n of e){const s=`${n.table} ${n.index}`;r.set(s,(r.get(s)??0)+n.reads)}return t.map(n=>({index:n.index,reads:r.get(`${n.table} ${n.index}`)??0,table:n.table}))},Te=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}))},X=(t,e)=>e.map(r=>({index:r.name,table:t})),ge=t=>{const e=Se(t.declaredIndexes??[],t.indexHits??[]),r=Te(t.functions??[]),n=t.shardTraffic??[],s=t.analyticsMetrics,i=s&&s.indexHits.length>0?s.indexHits:e,c=s&&s.tableScans.length>0?s.tableScans:r,v=s&&s.shardTraffic.length>0?s.shardTraffic:n,h=pe({indexHits:i,schema:{tables:[]},shardTraffic:v,tableScans:c},{lints:be,source:"runtime"}),u=t.suppressHotScanTables;return(u===void 0?h:h.filter(d=>!(d.metadata.kind==="hot_scan"&&typeof d.metadata.table=="string"&&u.has(d.metadata.table)))).map(d=>U(d))},Ie=q(A.listTables),we=q(A.listTableIndexes),Ae=q(A.listTablesIndexes),H=t=>`${(t*100).toFixed(1)}%`,P=t=>`${(t/1e3).toFixed(2)}s`,Ee=t=>{if(t.length<=1)return t[0]??"";const e=t[t.length-1]??"";return`${t.slice(0,-1).join(", ")} and ${e}`},$e=(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],V=(t,e)=>({"high-error-rate":t("{rate} of calls failed.",{rate:H(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:H(e.value)}),"low-cache-hit-rate":t("{rate} hit rate over recent traffic.",{rate:H(e.value)}),"missing-index":t("Slowest call took {duration} — it full-scanned {tables} with no index.",{duration:P(e.value),tables:Ee(e.tables??[])}),"slow-function":t("Slowest call took {duration}.",{duration:P(e.value)})})[e.kind],Ne=t=>{const e=J(10),{onJump:r,table:n}=t,s=R();let i;e[0]!==r||e[1]!==n?(i=()=>{r(n)},e[0]=r,e[1]=n,e[2]=i):i=e[2];const c=i,v=`in-add-index-${n}`;let h;e[3]!==s||e[4]!==n?(h=s("Add index on {table}",{table:n}),e[3]=s,e[4]=n,e[5]=h):h=e[5];let u;return e[6]!==c||e[7]!==v||e[8]!==h?(u=g(le,{"data-testid":v,onClick:c,size:"sm",type:"button",variant:"outline",children:h}),e[6]=c,e[7]=v,e[8]=h,e[9]=u):u=e[9],u},Je=({initialShardKey:t,loadShardTraffic:e})=>{const r=se(),n=re(),s=R(),{queryShardKey:i,setShardKey:c,shardKey:v}=de(t),[h,u]=K(null),[I,d]=K(null),f=ae(""),b=N(A.getMetrics,{},{live:!0,shardKey:i}),y=N(A.getFunctionStats,{},{live:!0,shardKey:i}),x=N(A.getAdvisories,{},{live:!0,shardKey:i}),w=b.data??null,B=y.data?.functions??null,D=x.data?.advisories??null,z=b.data?.indexHits??null,M=b.error!==null&&y.error!==null?b.error:null,G=e??(a=>r.shardTraffic(a)),W=async(a,p)=>{const S=a[0];if(S===void 0||S===""){f.current===p&&d(null);return}try{const o=await G(S);if(f.current!==p)return;const l=new Map;for(const m of o.shards)l.has(m.shardKey)||l.set(m.shardKey,{requests:m.requests,shardKey:m.shardKey});d([...l.values()])}catch{f.current===p&&d(null)}},Y=async(a,p)=>{const S=await Promise.allSettled(a.map(async l=>[l,await r.query(we,{table:l},k(p))])),o=[];for(const l of S)if(l.status==="fulfilled"){const[m,T]=l.value;o.push(...X(m,T.indexes))}return o},C=O(async a=>{f.current=a;let p=[];try{const S=await r.query(Ie,{},k(a));if(f.current!==a)return;ue(a),p=S.map(l=>l.name);let o=[];if(p.length>0)try{const l=await r.query(Ae,{tables:p},k(a));if(f.current!==a)return;for(const[m,T]of Object.entries(l.indexesByTable))o.push(...X(m,T))}catch{if(o=await Y(p,a),f.current!==a)return}u(o)}catch{f.current===a&&u(null)}await W(p,a)});Q(()=>{E(C(i))},[i]);const Z=O(()=>{b.refetch(),y.refetch(),x.refetch(),E(C(i))});Q(()=>{const a=()=>{document.visibilityState==="visible"&&Z()};return document.addEventListener("visibilitychange",a),()=>{document.removeEventListener("visibilitychange",a)}},[]);const F=oe(a=>{E(n({search:{table:a},to:"/schema"}))},[n]),$=he(w,B),_=new Set($.filter(a=>a.kind==="missing-index").flatMap(a=>a.tables??[])),j=ge({declaredIndexes:h??[],functions:B,indexHits:z,shardTraffic:I,suppressHotScanTables:_}),ee=ie(()=>{const a=$.map(o=>{const l=o.kind==="missing-index"?o.tables??[]:[];return{action:l.length>0?l.map(m=>g(Ne,{onJump:F,table:m},m)):void 0,description:o.message===void 0?V(s,o):`${V(s,o)} — ${o.message}`,entity:o.fn,issueType:$e(s,o),key:`${o.kind}:${o.fn??""}`,level:o.severity}}),p=new Set(["unindexed_foreign_key","unindexed_relation_target"]);return[...(D??[]).map(o=>{const l=U(o);if(p.has(o.name)&&xe(o.metadata)){const{table:m,suggestedIndex:T}=o.metadata,ne=`in-apply-index-${m}-${T.name}`;return{...l,action:g(ve,{fields:T.fields,indexName:T.name,table:m,testId:ne})}}return l}),...j,...a]},[D,$,F,j,s]),te=g(ce,{onChange:c,testId:"in-shard-input",value:v});return g(fe,{error:M,errorSource:M===null?void 0:b.errorSource,rows:ee,testId:"lunora-insights",toolbar:te})};export{Je as InsightsPanel};
1
+ import{c as J}from"react/compiler-runtime";import{useLunora as se}from"@lunora/react";import{useNavigate as re}from"@tanstack/react-router";import{useState as q,useRef as ae,useEffectEvent as O,useEffect as Q,useCallback as oe,useMemo as ie}from"react";import{ShardInput as ce}from"../packem_shared/ShardInput-CdawpUiS.js";import{B as le}from"../packem_shared/button-BOPLD1un.js";import{u as N}from"../packem_shared/use-admin-query-P0RJrjsD.js";import{u as de}from"../packem_shared/use-shard-key-BsP3o5wT.js";import{useT as K}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.js";import{ADMIN_FUNCTIONS as A}from"../packem_shared/ADMIN_FUNCTIONS-B6z7VLYt.js";import{f as E,d as L,c as R}from"../packem_shared/internal-CwaF9YNk.js";import{r as ue}from"../packem_shared/shard-history-DU5b3QDI.js";import{a as U,A as fe}from"../packem_shared/advisor-view-C1KFTXSH.js";import{ConfirmButton as me}from"../packem_shared/ConfirmButton-Cj2SOapE.js";import{q as k}from"../packem_shared/quote-identifier-CGiYFBvY.js";import{jsx as g}from"react/jsx-runtime";import{deriveInsights as he}from"../packem_shared/DEFAULT_INSIGHT_THRESHOLDS-1Lrg55IV.js";import{runAdvisor as pe,RUNTIME_LINTS as be}from"@lunora/advisor";const xe=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)},ye=(t,e,r)=>{const n=k(t),s=k(e),i=r.map(c=>k(c)).join(", ");return`CREATE INDEX IF NOT EXISTS ${s} ON ${n} (${i});`},ve=t=>{const e=J(19),{fields:r,indexName:n,table:s,testId:i}=t,c=K(),[v,h]=q(!1);let u;e[0]!==r||e[1]!==n||e[2]!==s?(u=()=>{const y="navigator"in globalThis?globalThis.navigator.clipboard:void 0;if(y===void 0)return;const x=ye(s,n,r);E(y.writeText(x)),h(!0)},e[0]=r,e[1]=n,e[2]=s,e[3]=u):u=e[3];const I=u;if(v){const y=`${i}-applied`;let x;e[4]!==c?(x=c("CREATE INDEX SQL copied to clipboard."),e[4]=c,e[5]=x):x=e[5];let w;return e[6]!==y||e[7]!==x?(w=g("span",{className:"text-xs text-muted-foreground","data-testid":y,children:x}),e[6]=y,e[7]=x,e[8]=w):w=e[8],w}let d;e[9]!==c?(d=c("Apply?"),e[9]=c,e[10]=d):d=e[10];let f;e[11]!==c||e[12]!==s?(f=c("Apply index on {table}",{table:s}),e[11]=c,e[12]=s,e[13]=f):f=e[13];let b;return e[14]!==I||e[15]!==d||e[16]!==f||e[17]!==i?(b=g(me,{confirmLabel:d,onConfirm:I,testId:i,children:f}),e[14]=I,e[15]=d,e[16]=f,e[17]=i,e[18]=b):b=e[18],b},Se=(t,e)=>{const r=new Map;for(const n of e){const s=`${n.table} ${n.index}`;r.set(s,(r.get(s)??0)+n.reads)}return t.map(n=>({index:n.index,reads:r.get(`${n.table} ${n.index}`)??0,table:n.table}))},Te=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}))},X=(t,e)=>e.map(r=>({index:r.name,table:t})),ge=t=>{const e=Se(t.declaredIndexes??[],t.indexHits??[]),r=Te(t.functions??[]),n=t.shardTraffic??[],s=t.analyticsMetrics,i=s&&s.indexHits.length>0?s.indexHits:e,c=s&&s.tableScans.length>0?s.tableScans:r,v=s&&s.shardTraffic.length>0?s.shardTraffic:n,h=pe({indexHits:i,schema:{tables:[]},shardTraffic:v,tableScans:c},{lints:be,source:"runtime"}),u=t.suppressHotScanTables;return(u===void 0?h:h.filter(d=>!(d.metadata.kind==="hot_scan"&&typeof d.metadata.table=="string"&&u.has(d.metadata.table)))).map(d=>U(d))},Ie=R(A.listTables),we=R(A.listTableIndexes),Ae=R(A.listTablesIndexes),H=t=>`${(t*100).toFixed(1)}%`,P=t=>`${(t/1e3).toFixed(2)}s`,Ee=t=>{if(t.length<=1)return t[0]??"";const e=t[t.length-1]??"";return`${t.slice(0,-1).join(", ")} and ${e}`},$e=(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],V=(t,e)=>({"high-error-rate":t("{rate} of calls failed.",{rate:H(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:H(e.value)}),"low-cache-hit-rate":t("{rate} hit rate over recent traffic.",{rate:H(e.value)}),"missing-index":t("Slowest call took {duration} — it full-scanned {tables} with no index.",{duration:P(e.value),tables:Ee(e.tables??[])}),"slow-function":t("Slowest call took {duration}.",{duration:P(e.value)})})[e.kind],Ne=t=>{const e=J(10),{onJump:r,table:n}=t,s=K();let i;e[0]!==r||e[1]!==n?(i=()=>{r(n)},e[0]=r,e[1]=n,e[2]=i):i=e[2];const c=i,v=`in-add-index-${n}`;let h;e[3]!==s||e[4]!==n?(h=s("Add index on {table}",{table:n}),e[3]=s,e[4]=n,e[5]=h):h=e[5];let u;return e[6]!==c||e[7]!==v||e[8]!==h?(u=g(le,{"data-testid":v,onClick:c,size:"sm",type:"button",variant:"outline",children:h}),e[6]=c,e[7]=v,e[8]=h,e[9]=u):u=e[9],u},Ue=({initialShardKey:t,loadShardTraffic:e})=>{const r=se(),n=re(),s=K(),{queryShardKey:i,setShardKey:c,shardKey:v}=de(t),[h,u]=q(null),[I,d]=q(null),f=ae(""),b=N(A.getMetrics,{},{live:!0,shardKey:i}),y=N(A.getFunctionStats,{},{live:!0,shardKey:i}),x=N(A.getAdvisories,{},{live:!0,shardKey:i}),w=b.data??null,B=y.data?.functions??null,D=x.data?.advisories??null,z=b.data?.indexHits??null,M=b.error!==null&&y.error!==null?b.error:null,G=e??(a=>r.shardTraffic(a)),W=async(a,p)=>{const S=a[0];if(S===void 0||S===""){f.current===p&&d(null);return}try{const o=await G(S);if(f.current!==p)return;const l=new Map;for(const m of o.shards)l.has(m.shardKey)||l.set(m.shardKey,{requests:m.requests,shardKey:m.shardKey});d([...l.values()])}catch{f.current===p&&d(null)}},Y=async(a,p)=>{const S=await Promise.allSettled(a.map(async l=>[l,await r.query(we,{table:l},L(p))])),o=[];for(const l of S)if(l.status==="fulfilled"){const[m,T]=l.value;o.push(...X(m,T.indexes))}return o},C=O(async a=>{f.current=a;let p=[];try{const S=await r.query(Ie,{},L(a));if(f.current!==a)return;ue(a),p=S.map(l=>l.name);let o=[];if(p.length>0)try{const l=await r.query(Ae,{tables:p},L(a));if(f.current!==a)return;for(const[m,T]of Object.entries(l.indexesByTable))o.push(...X(m,T))}catch{if(o=await Y(p,a),f.current!==a)return}u(o)}catch{f.current===a&&u(null)}await W(p,a)});Q(()=>{E(C(i))},[i]);const Z=O(()=>{b.refetch(),y.refetch(),x.refetch(),E(C(i))});Q(()=>{const a=()=>{document.visibilityState==="visible"&&Z()};return document.addEventListener("visibilitychange",a),()=>{document.removeEventListener("visibilitychange",a)}},[]);const F=oe(a=>{E(n({search:{table:a},to:"/schema"}))},[n]),$=he(w,B),_=new Set($.filter(a=>a.kind==="missing-index").flatMap(a=>a.tables??[])),j=ge({declaredIndexes:h??[],functions:B,indexHits:z,shardTraffic:I,suppressHotScanTables:_}),ee=ie(()=>{const a=$.map(o=>{const l=o.kind==="missing-index"?o.tables??[]:[];return{action:l.length>0?l.map(m=>g(Ne,{onJump:F,table:m},m)):void 0,description:o.message===void 0?V(s,o):`${V(s,o)} — ${o.message}`,entity:o.fn,issueType:$e(s,o),key:`${o.kind}:${o.fn??""}`,level:o.severity}}),p=new Set(["unindexed_foreign_key","unindexed_relation_target"]);return[...(D??[]).map(o=>{const l=U(o);if(p.has(o.name)&&xe(o.metadata)){const{table:m,suggestedIndex:T}=o.metadata,ne=`in-apply-index-${m}-${T.name}`;return{...l,action:g(ve,{fields:T.fields,indexName:T.name,table:m,testId:ne})}}return l}),...j,...a]},[D,$,F,j,s]),te=g(ce,{onChange:c,testId:"in-shard-input",value:v});return g(fe,{error:M,errorSource:M===null?void 0:b.errorSource,rows:ee,testId:"lunora-insights",toolbar:te})};export{Ue as InsightsPanel};
@@ -1 +1 @@
1
- import{c as q}from"react/compiler-runtime";import{useVirtualizer as Ce}from"@tanstack/react-virtual";import{useState as F,useReducer as Le,useRef as ue,useEffect as me,useMemo as Ne}from"react";import{f as fe}from"../packem_shared/log-fields-SBxKyBug.js";import{E as Se}from"../packem_shared/error-alert-CKqB2CiN.js";import{B as he}from"../packem_shared/badge-cAk9Di1Q.js";import{E as ee}from"../packem_shared/empty-state-B939z6K2.js";import{u as le}from"../packem_shared/use-admin-query-DV9xmFl8.js";import{u as Te}from"../packem_shared/use-open-trace-ClAdPkGD.js";import{u as Ie}from"../packem_shared/use-shard-key-BsP3o5wT.js";import{useT as Q}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.js";import{ADMIN_FUNCTIONS as oe}from"../packem_shared/ADMIN_FUNCTIONS-B6z7VLYt.js";import{r as Re}from"../packem_shared/shard-history-DU5b3QDI.js";import{f as ke}from"../packem_shared/virtual-rect-D_j7aLxX.js";import{useLunora as Pe}from"@lunora/react";import{B as Ee}from"../packem_shared/button-BOPLD1un.js";import{I as D}from"../packem_shared/input-CY5W3wzv.js";import{T as Oe,a as _e,b as ge,c as B,d as Fe,e as V}from"../packem_shared/table-BMsuYFhk.js";import ae from"../packem_shared/useDebounced-DVeQ5-oW.js";import{a as pe}from"../packem_shared/cf-links-CBJ5SywP.js";import{f as ne,m as qe,b as ie}from"../packem_shared/internal-7bgd8inO.js";import{a as Ae,L as Me}from"../packem_shared/log-line-D0XBZaDn.js";import{jsx as r,jsxs as E,Fragment as $e}from"react/jsx-runtime";import{c as H}from"../packem_shared/utils-bhneXptQ.js";import{L as Ue}from"../packem_shared/live-status-Bf7rR8o8.js";import{ShardInput as Ke}from"../packem_shared/ShardInput-CdawpUiS.js";const re=["trace","debug","log","info","warn","error","fatal"],Be="LOG_ARCHIVE_NOT_CONFIGURED",Ve={cursor:void 0,error:null,loading:!1,notConfigured:!1,rows:null},De=(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}},Qe=i=>{const e=q(33),{row:t}=i;let a;e[0]!==t.fields?(a=fe(t.fields),e[0]=t.fields,e[1]=a):a=e[1];const n=a,o=`lg-archive-row-${String(t.ts)}`;let d;e[2]!==t.ts?(d=new Date(t.ts).toLocaleString(),e[2]=t.ts,e[3]=d):d=e[3];let p;e[4]!==d?(p=r(V,{className:"tabular-nums whitespace-nowrap text-xs text-muted-foreground",children:d}),e[4]=d,e[5]=p):p=e[5];const m=Ae[t.level];let c;e[6]!==t.level||e[7]!==m?(c=r(V,{children:r(he,{variant:m,children:t.level})}),e[6]=t.level,e[7]=m,e[8]=c):c=e[8];let s;e[9]!==t.functionPath?(s=r(V,{className:"font-mono text-xs",children:t.functionPath}),e[9]=t.functionPath,e[10]=s):s=e[10];let f;e[11]!==t.message?(f=r("div",{className:"truncate",title:t.message,children:t.message}),e[11]=t.message,e[12]=f):f=e[12];let l;e[13]!==n?(l=n!==""&&r("div",{className:"truncate font-mono text-[11px] text-muted-foreground",title:n,children:n}),e[13]=n,e[14]=l):l=e[14];let u;e[15]!==f||e[16]!==l?(u=E(V,{className:"max-w-md",children:[f,l]}),e[15]=f,e[16]=l,e[17]=u):u=e[17];const h=t.traceId??"—";let v;e[18]!==h?(v=r(V,{className:"font-mono text-[11px] text-muted-foreground",children:h}),e[18]=h,e[19]=v):v=e[19];const b=t.shardKey??"—";let y;e[20]!==b?(y=r(V,{className:"font-mono text-[11px] text-muted-foreground",children:b}),e[20]=b,e[21]=y):y=e[21];const w=t.userId??"—";let x;e[22]!==w?(x=r(V,{className:"font-mono text-[11px] text-muted-foreground",children:w}),e[22]=w,e[23]=x):x=e[23];let T;return e[24]!==u||e[25]!==v||e[26]!==y||e[27]!==x||e[28]!==o||e[29]!==p||e[30]!==c||e[31]!==s?(T=E(ge,{"data-testid":o,children:[p,c,s,u,v,y,x]}),e[24]=u,e[25]=v,e[26]=y,e[27]=x,e[28]=o,e[29]=p,e[30]=c,e[31]=s,e[32]=T):T=e[32],T},ze=({shardKey:i})=>{const e=Pe(),t=Q(),[a,n]=F(""),[o,d]=F(""),[p,m]=F(""),[{cursor:c,error:s,loading:f,notConfigured:l,rows:u},h]=Le(De,Ve),v=ae(a.trim(),400),b=ae(o.trim(),400),y={...v===""?{}:{functionPathPrefix:v},...p===""?{}:{minLevel:p},...i===""?{}:{shardKey:i},...b===""?{}:{userId:b}},w=JSON.stringify(y),x=ue(w);me(()=>{const g={cancelled:!1};return x.current=w,ne((async()=>{h({type:"loading"});try{const C=await e.queryLogArchive(y);g.cancelled||h({cursor:C.nextCursor,rows:C.rows,type:"loaded"})}catch(C){g.cancelled||h(qe(C)===Be?{type:"notConfigured"}:{message:ie(C),type:"failed"})}})()),()=>{g.cancelled=!0}},[e,w]);const T=async()=>{if(c===void 0)return;const g=w;h({type:"loading"});try{const C=await e.queryLogArchive({...y,cursor:c});x.current===g&&h({cursor:C.nextCursor,rows:C.rows,type:"append"})}catch(C){x.current===g&&h({message:ie(C),type:"pageFailed"})}},R=g=>{n(g.target.value)},N=g=>{d(g.target.value)},L=g=>{m(g.target.value)},S=()=>{ne(T())};return l?r(ee,{action:r("a",{className:"text-sm text-primary underline-offset-4 hover:underline",href:pe,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")}):E("div",{className:"flex flex-col gap-4","data-testid":"lg-archive",children:[E("div",{className:"flex flex-wrap items-center gap-2",children:[r(D,{"aria-label":t("Function path prefix"),className:"h-8 w-48","data-testid":"lg-archive-path",onChange:R,placeholder:t("function path…"),value:a}),r(D,{"aria-label":t("User id"),className:"h-8 w-40","data-testid":"lg-archive-user",onChange:N,placeholder:t("user id…"),value:o}),E("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:L,value:p,children:[r("option",{value:"",children:t("min level")}),re.map(g=>r("option",{value:g,children:g},g))]})]}),s!==null&&r("p",{className:"text-sm text-destructive","data-testid":"lg-archive-error",role:"alert",children:s}),f&&u===null&&s===null&&r("p",{className:"text-sm text-muted-foreground","data-testid":"lg-archive-loading",children:t("Loading…")}),u!==null&&u.length===0&&r(ee,{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.")}),u!==null&&u.length>0&&r("div",{className:"overflow-hidden rounded-xl border border-border shadow-xs",children:E(Oe,{"data-testid":"lg-archive-table",children:[r(_e,{children:E(ge,{children:[r(B,{children:t("Time")}),r(B,{children:t("Level")}),r(B,{children:t("Function")}),r(B,{children:t("Message")}),r(B,{children:t("Trace")}),r(B,{children:t("Shard")}),r(B,{children:t("User")})]})}),r(Fe,{children:u.map((g,C)=>r(Qe,{row:g},`${String(g.ts)}-${String(C)}`))})]})}),c!==void 0&&r("div",{children:r(Ee,{"data-testid":"lg-archive-more",disabled:f,onClick:S,size:"sm",variant:"outline",children:t(f?"Loading…":"Load more")})})]})},Ge=i=>{const e=q(11),{level:t,onToggle:a,selected:n}=i;let o;e[0]!==t||e[1]!==a?(o=()=>{a(t)},e[0]=t,e[1]=a,e[2]=o):o=e[2];const d=o,p=n?"border-border bg-muted font-medium":"border-input text-muted-foreground";let m;e[3]!==p?(m=H("rounded-md border px-2 py-1 text-xs",p),e[3]=p,e[4]=m):m=e[4];const c=`logs-level-${t}`;let s;return e[5]!==t||e[6]!==d||e[7]!==n||e[8]!==m||e[9]!==c?(s=r("button",{"aria-pressed":n,className:m,"data-testid":c,onClick:d,type:"button",children:t}),e[5]=t,e[6]=d,e[7]=n,e[8]=m,e[9]=c,e[10]=s):s=e[10],s},He=i=>{const e=q(68),{levelFilter:t,onLogPathChange:a,onSearchChange:n,onTimeRangeChange:o,onToggleLevel:d,onToggleSummary:p,pathFilter:m,search:c,showSummary:s,timeRange:f}=i,l=Q();let u;e[0]!==l?(u=l("Search messages"),e[0]=l,e[1]=u):u=e[1];let h;e[2]!==l?(h=l("search message"),e[2]=l,e[3]=h):h=e[3];let v;e[4]!==n||e[5]!==c||e[6]!==u||e[7]!==h?(v=r(D,{"aria-label":u,className:"h-8 w-48","data-testid":"lg-search",onChange:n,placeholder:h,value:c}),e[4]=n,e[5]=c,e[6]=u,e[7]=h,e[8]=v):v=e[8];let b;e[9]!==l?(b=l("Function path"),e[9]=l,e[10]=b):b=e[10];let y;e[11]!==l?(y=l("filter path"),e[11]=l,e[12]=y):y=e[12];let w;e[13]!==a||e[14]!==m||e[15]!==b||e[16]!==y?(w=r(D,{"aria-label":b,className:"h-8 w-40","data-testid":"logs-path-filter",onChange:a,placeholder:y,value:m}),e[13]=a,e[14]=m,e[15]=b,e[16]=y,e[17]=w):w=e[17];let x;e[18]!==l?(x=l("Level filter"),e[18]=l,e[19]=x):x=e[19];let T;e[20]!==t||e[21]!==d?(T=re.map(G=>r(Ge,{level:G,onToggle:d,selected:t.has(G)},G)),e[20]=t,e[21]=d,e[22]=T):T=e[22];let R;e[23]!==x||e[24]!==T?(R=r("div",{"aria-label":x,className:"inline-flex items-center gap-1","data-testid":"logs-level-filter",role:"group",children:T}),e[23]=x,e[24]=T,e[25]=R):R=e[25];let N;e[26]!==l?(N=l("Time range"),e[26]=l,e[27]=N):N=e[27];let L;e[28]!==l?(L=l("All time"),e[28]=l,e[29]=L):L=e[29];let S;e[30]!==L?(S=r("option",{value:"all",children:L}),e[30]=L,e[31]=S):S=e[31];let g;e[32]!==l?(g=l("Last 5m"),e[32]=l,e[33]=g):g=e[33];let C;e[34]!==g?(C=r("option",{value:"5m",children:g}),e[34]=g,e[35]=C):C=e[35];let k;e[36]!==l?(k=l("Last 15m"),e[36]=l,e[37]=k):k=e[37];let P;e[38]!==k?(P=r("option",{value:"15m",children:k}),e[38]=k,e[39]=P):P=e[39];let O;e[40]!==l?(O=l("Last hour"),e[40]=l,e[41]=O):O=e[41];let _;e[42]!==O?(_=r("option",{value:"1h",children:O}),e[42]=O,e[43]=_):_=e[43];let A;e[44]!==o||e[45]!==N||e[46]!==S||e[47]!==C||e[48]!==P||e[49]!==_||e[50]!==f?(A=E("select",{"aria-label":N,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:f,children:[S,C,P,_]}),e[44]=o,e[45]=N,e[46]=S,e[47]=C,e[48]=P,e[49]=_,e[50]=f,e[51]=A):A=e[51];const z=s?"border-border bg-muted font-medium":"border-input text-muted-foreground";let M;e[52]!==z?(M=H("h-8 rounded-md border px-3 text-sm",z),e[52]=z,e[53]=M):M=e[53];let U;e[54]!==s||e[55]!==l?(U=l(s?"List":"Summary"),e[54]=s,e[55]=l,e[56]=U):U=e[56];let $;e[57]!==p||e[58]!==s||e[59]!==M||e[60]!==U?($=r("button",{"aria-pressed":s,className:M,"data-testid":"logs-summary-toggle",onClick:p,type:"button",children:U}),e[57]=p,e[58]=s,e[59]=M,e[60]=U,e[61]=$):$=e[61];let K;return e[62]!==A||e[63]!==$||e[64]!==v||e[65]!==w||e[66]!==R?(K=E("div",{className:"flex flex-wrap items-center gap-2",children:[v,w,R,A,$]}),e[62]=A,e[63]=$,e[64]=v,e[65]=w,e[66]=R,e[67]=K):K=e[67],K},We=i=>{const e=q(53),{onOutcomeChange:t,onPathChange:a,onTableChange:n,onUserChange:o,outcomeFilter:d,pathPrefix:p,tableFilter:m,userIdFilter:c}=i,s=Q();let f;e[0]!==s?(f=s("Function path"),e[0]=s,e[1]=f):f=e[1];let l;e[2]!==s?(l=s("file:function"),e[2]=s,e[3]=l):l=e[3];let u;e[4]!==a||e[5]!==p||e[6]!==f||e[7]!==l?(u=r(D,{"aria-label":f,className:"h-8 w-44","data-testid":"lg-req-path",onChange:a,placeholder:l,value:p}),e[4]=a,e[5]=p,e[6]=f,e[7]=l,e[8]=u):u=e[8];let h;e[9]!==s?(h=s("User id"),e[9]=s,e[10]=h):h=e[10];let v;e[11]!==s?(v=s("userId"),e[11]=s,e[12]=v):v=e[12];let b;e[13]!==o||e[14]!==h||e[15]!==v||e[16]!==c?(b=r(D,{"aria-label":h,className:"h-8 w-32","data-testid":"lg-req-user",onChange:o,placeholder:v,value:c}),e[13]=o,e[14]=h,e[15]=v,e[16]=c,e[17]=b):b=e[17];let y;e[18]!==s?(y=s("Table touched"),e[18]=s,e[19]=y):y=e[19];let w;e[20]!==s?(w=s("table"),e[20]=s,e[21]=w):w=e[21];let x;e[22]!==n||e[23]!==y||e[24]!==w||e[25]!==m?(x=r(D,{"aria-label":y,className:"h-8 w-32","data-testid":"lg-req-table",onChange:n,placeholder:w,value:m}),e[22]=n,e[23]=y,e[24]=w,e[25]=m,e[26]=x):x=e[26];let T;e[27]!==s?(T=s("Outcome filter"),e[27]=s,e[28]=T):T=e[28];let R;e[29]!==s?(R=s("all"),e[29]=s,e[30]=R):R=e[30];let N;e[31]!==R?(N=r("option",{value:"all",children:R}),e[31]=R,e[32]=N):N=e[32];let L;e[33]!==s?(L=s("ok"),e[33]=s,e[34]=L):L=e[34];let S;e[35]!==L?(S=r("option",{value:"ok",children:L}),e[35]=L,e[36]=S):S=e[36];let g;e[37]!==s?(g=s("error"),e[37]=s,e[38]=g):g=e[38];let C;e[39]!==g?(C=r("option",{value:"error",children:g}),e[39]=g,e[40]=C):C=e[40];let k;e[41]!==t||e[42]!==d||e[43]!==T||e[44]!==N||e[45]!==S||e[46]!==C?(k=E("select",{"aria-label":T,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:d,children:[N,S,C]}),e[41]=t,e[42]=d,e[43]=T,e[44]=N,e[45]=S,e[46]=C,e[47]=k):k=e[47];let P;return e[48]!==k||e[49]!==u||e[50]!==b||e[51]!==x?(P=E("div",{className:"flex flex-wrap items-center gap-2",children:[u,b,x,k]}),e[48]=k,e[49]=u,e[50]=b,e[51]=x,e[52]=P):P=e[52],P},ve=i=>{const e=q(7),{bucket:t}=i;let a;e[0]!==t.key?(a=r("span",{className:"truncate text-muted-foreground",role:"gridcell",children:t.key}),e[0]=t.key,e[1]=a):a=e[1];let n;e[2]!==t.count?(n=r("span",{className:"shrink-0 tabular-nums",role:"gridcell",children:t.count}),e[2]=t.count,e[3]=n):n=e[3];let o;return e[4]!==a||e[5]!==n?(o=E("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:[a,n]}),e[4]=a,e[5]=n,e[6]=o):o=e[6],o},Ye=i=>{const e=q(31),{summary:t}=i,a=Q();let n;e[0]!==t.total||e[1]!==a?(n=a("{count} entries",{count:t.total}),e[0]=t.total,e[1]=a,e[2]=n):n=e[2];let o;e[3]!==n?(o=r("p",{className:"text-xs text-muted-foreground","data-testid":"logs-summary-total",children:n}),e[3]=n,e[4]=o):o=e[4];let d;e[5]!==a?(d=a("By level"),e[5]=a,e[6]=d):d=e[6];let p;e[7]!==d?(p=r("h4",{className:"mb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:d}),e[7]=d,e[8]=p):p=e[8];let m;e[9]!==t.byLevel?(m=t.byLevel.map(je),e[9]=t.byLevel,e[10]=m):m=e[10];let c;e[11]!==m?(c=r("div",{className:"overflow-hidden rounded-lg border border-border","data-testid":"logs-summary-levels",role:"grid",children:m}),e[11]=m,e[12]=c):c=e[12];let s;e[13]!==p||e[14]!==c?(s=E("div",{children:[p,c]}),e[13]=p,e[14]=c,e[15]=s):s=e[15];let f;e[16]!==a?(f=a("By function"),e[16]=a,e[17]=f):f=e[17];let l;e[18]!==f?(l=r("h4",{className:"mb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:f}),e[18]=f,e[19]=l):l=e[19];let u;e[20]!==t.byPath?(u=t.byPath.map(Je),e[20]=t.byPath,e[21]=u):u=e[21];let h;e[22]!==u?(h=r("div",{className:"overflow-hidden rounded-lg border border-border","data-testid":"logs-summary-paths",role:"grid",children:u}),e[22]=u,e[23]=h):h=e[23];let v;e[24]!==h||e[25]!==l?(v=E("div",{children:[l,h]}),e[24]=h,e[25]=l,e[26]=v):v=e[26];let b;return e[27]!==v||e[28]!==o||e[29]!==s?(b=E("div",{className:"flex flex-col gap-4 rounded-xl border border-border bg-card p-4 shadow-xs","data-testid":"logs-summary",children:[o,s,v]}),e[27]=v,e[28]=o,e[29]=s,e[30]=b):b=e[30],b};function je(i){return r(ve,{bucket:i},i.key)}function Je(i){return r(ve,{bucket:i},i.key)}const Xe=i=>{const e=q(46),{liveError:t,onShardKeyChange:a,onShowArchive:n,onShowErrors:o,onShowRequests:d,shardKey:p,view:m}=i,c=Q(),s=m==="requests",f=m==="requests"?"bg-muted font-medium":"text-muted-foreground";let l;e[0]!==f?(l=H("px-3 py-1 text-sm",f),e[0]=f,e[1]=l):l=e[1];let u;e[2]!==c?(u=c("Requests"),e[2]=c,e[3]=u):u=e[3];let h;e[4]!==d||e[5]!==s||e[6]!==l||e[7]!==u?(h=r("button",{"aria-selected":s,className:l,"data-testid":"lg-view-requests",onClick:d,role:"tab",type:"button",children:u}),e[4]=d,e[5]=s,e[6]=l,e[7]=u,e[8]=h):h=e[8];const v=m==="errors",b=m==="errors"?"bg-muted font-medium":"text-muted-foreground";let y;e[9]!==b?(y=H("px-3 py-1 text-sm",b),e[9]=b,e[10]=y):y=e[10];let w;e[11]!==c?(w=c("Errors"),e[11]=c,e[12]=w):w=e[12];let x;e[13]!==o||e[14]!==v||e[15]!==y||e[16]!==w?(x=r("button",{"aria-selected":v,className:y,"data-testid":"lg-view-errors",onClick:o,role:"tab",type:"button",children:w}),e[13]=o,e[14]=v,e[15]=y,e[16]=w,e[17]=x):x=e[17];const T=m==="archive",R=m==="archive"?"bg-muted font-medium":"text-muted-foreground";let N;e[18]!==R?(N=H("px-3 py-1 text-sm",R),e[18]=R,e[19]=N):N=e[19];let L;e[20]!==c?(L=c("Archive"),e[20]=c,e[21]=L):L=e[21];let S;e[22]!==n||e[23]!==T||e[24]!==N||e[25]!==L?(S=r("button",{"aria-selected":T,className:N,"data-testid":"lg-view-archive",onClick:n,role:"tab",type:"button",children:L}),e[22]=n,e[23]=T,e[24]=N,e[25]=L,e[26]=S):S=e[26];let g;e[27]!==x||e[28]!==S||e[29]!==h?(g=E("div",{className:"inline-flex overflow-hidden rounded-lg border border-border",role:"tablist",children:[h,x,S]}),e[27]=x,e[28]=S,e[29]=h,e[30]=g):g=e[30];let C;e[31]!==a||e[32]!==p?(C=r(Ke,{onChange:a,testId:"lg-shard-input",value:p}),e[31]=a,e[32]=p,e[33]=C):C=e[33];let k;e[34]!==t||e[35]!==m?(k=m!=="archive"&&r(Ue,{message:t,prefix:"lg"}),e[34]=t,e[35]=m,e[36]=k):k=e[36];let P;e[37]!==c?(P=c("Open in Cloudflare"),e[37]=c,e[38]=P):P=e[38];let O;e[39]!==P?(O=r("a",{className:"text-sm text-primary underline-offset-4 hover:underline","data-testid":"lg-cf-link",href:pe,rel:"noreferrer",target:"_blank",children:P}),e[39]=P,e[40]=O):O=e[40];let _;return e[41]!==g||e[42]!==C||e[43]!==k||e[44]!==O?(_=E("div",{className:"flex flex-wrap items-center gap-2",children:[g,C,k,O]}),e[41]=g,e[42]=C,e[43]=k,e[44]=O,e[45]=_):_=e[45],_},te=400,Ze=36,et={height:te,overflow:"auto"},be={left:0,position:"absolute",top:0,width:"100%"},tt={error:"destructive",ok:"secondary"},xe=i=>{const e=q(6),{onOpenTrace:t,traceId:a}=i,n=Q();let o;e[0]!==t||e[1]!==n||e[2]!==a?(o=a===void 0?null:r("button",{className:"text-primary underline-offset-2 hover:underline","data-testid":"lg-trace-link",onClick:()=>{t(a)},type:"button",children:n("Trace")}),e[0]=t,e[1]=n,e[2]=a,e[3]=o):o=e[3];let d;return e[4]!==o?(d=r("span",{className:"w-16 shrink-0 text-right",role:"gridcell",children:o}),e[4]=o,e[5]=d):d=e[5],d},rt=i=>{const e=q(13),{entry:t,index:a,measureRef:n,onOpenTrace:o,start:d}=i,p=`translateY(${String(d)}px)`;let m;e[0]!==p?(m={...be,transform:p},e[0]=p,e[1]=m):m=e[1];const c=m;let s;e[2]!==t?(s=r(Me,{entry:t}),e[2]=t,e[3]=s):s=e[3];let f;e[4]!==t.traceId||e[5]!==o?(f=r(xe,{onOpenTrace:o,traceId:t.traceId}),e[4]=t.traceId,e[5]=o,e[6]=f):f=e[6];let l;return e[7]!==a||e[8]!==n||e[9]!==c||e[10]!==s||e[11]!==f?(l=E("div",{className:"flex items-center border-b border-border px-3 py-1.5 font-mono text-xs hover:bg-muted/50","data-index":a,"data-testid":"lg-row",ref:n,role:"row",style:c,children:[s,f]}),e[7]=a,e[8]=n,e[9]=c,e[10]=s,e[11]=f,e[12]=l):l=e[12],l},ce=i=>i.length===0?"—":i.join(", "),st=i=>{const e=q(41),{entry:t,index:a,measureRef:n,onOpenTrace:o,start:d}=i,p=`translateY(${String(d)}px)`;let m;e[0]!==p?(m={...be,transform:p},e[0]=p,e[1]=m):m=e[1];const c=m;let s;e[2]!==t.ts?(s=new Date(t.ts).toLocaleString(),e[2]=t.ts,e[3]=s):s=e[3];let f;e[4]!==s?(f=r("span",{className:"w-40 shrink-0 tabular-nums text-muted-foreground",role:"gridcell",children:s}),e[4]=s,e[5]=f):f=e[5];const l=tt[t.outcome];let u;e[6]!==t.outcome||e[7]!==l?(u=r("span",{className:"w-16 shrink-0",role:"gridcell",children:r(he,{variant:l,children:t.outcome})}),e[6]=t.outcome,e[7]=l,e[8]=u):u=e[8];let h;e[9]!==t.functionPath?(h=r("span",{className:"w-44 shrink-0 truncate",role:"gridcell",title:t.functionPath,children:t.functionPath}),e[9]=t.functionPath,e[10]=h):h=e[10];const v=t.shardKey??"—";let b;e[11]!==v?(b=r("span",{className:"w-24 shrink-0 truncate text-muted-foreground",role:"gridcell",children:v}),e[11]=v,e[12]=b):b=e[12];const y=t.userId??"—";let w;e[13]!==y?(w=r("span",{className:"w-24 shrink-0 truncate text-muted-foreground",role:"gridcell",children:y}),e[13]=y,e[14]=w):w=e[14];let x;e[15]!==t.durationMs?(x=Math.round(t.durationMs),e[15]=t.durationMs,e[16]=x):x=e[16];const T=`${String(x)}ms`;let R;e[17]!==T?(R=r("span",{className:"w-16 shrink-0 tabular-nums text-muted-foreground",role:"gridcell",children:T}),e[17]=T,e[18]=R):R=e[18];let N;e[19]!==t.errorMessage||e[20]!==t.outcome||e[21]!==t.tablesRead||e[22]!==t.tablesWritten?(N=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]=N):N=e[23];let L;e[24]!==N?(L=r("span",{className:"flex-1 truncate text-muted-foreground",role:"gridcell",children:N}),e[24]=N,e[25]=L):L=e[25];let S;e[26]!==t.traceId||e[27]!==o?(S=r(xe,{onOpenTrace:o,traceId:t.traceId}),e[26]=t.traceId,e[27]=o,e[28]=S):S=e[28];let g;return e[29]!==a||e[30]!==n||e[31]!==c||e[32]!==w||e[33]!==R||e[34]!==L||e[35]!==S||e[36]!==f||e[37]!==u||e[38]!==h||e[39]!==b?(g=E("div",{className:"flex items-center border-b border-border px-3 py-1.5 font-mono text-xs hover:bg-muted/50","data-index":a,"data-testid":"lg-req-row",ref:n,role:"row",style:c,children:[f,u,h,b,w,R,L,S]}),e[29]=a,e[30]=n,e[31]=c,e[32]=w,e[33]=R,e[34]=L,e[35]=S,e[36]=f,e[37]=u,e[38]=h,e[39]=b,e[40]=g):g=e[40],g},de=i=>{const{entries:e}=i??{};return Array.isArray(e)?e:[]},lt=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},ot={"5m":300*1e3,"15m":900*1e3,"1h":3600*1e3},at=(i,e)=>{const t=e.search.trim().toLowerCase(),a=e.path.trim().toLowerCase(),n=e.range==="all"?Number.NEGATIVE_INFINITY:e.now-ot[e.range];return i.filter(o=>e.levels.size>0&&!e.levels.has(o.level)||o.timestamp<n||a!==""&&!(o.functionPath??"").toLowerCase().includes(a)?!1:t===""||o.message.toLowerCase().includes(t)||fe(o.fields).toLowerCase().includes(t))},nt="—",it=i=>{const e=new Map,t=new Map;for(const o of i){e.set(o.level,(e.get(o.level)??0)+1);const d=o.functionPath??nt;t.set(d,(t.get(d)??0)+1)}const a=re.filter(o=>e.has(o)).map(o=>({count:e.get(o)??0,key:o})),n=[...t.entries()].map(([o,d])=>({count:d,key:o})).toSorted((o,d)=>d.count===o.count?o.key.localeCompare(d.key):d.count-o.count);return{byLevel:a,byPath:n,total:i.length}},Wt=({initialShardKey:i})=>{const e=Q(),[t,a]=F("requests"),{queryShardKey:n,setShardKey:o,shardKey:d}=Ie(i),[p,m]=F(""),[c,s]=F(()=>new Set),[f,l]=F(""),[u,h]=F("all"),[v,b]=F(!1),[y,w]=F(""),[x,T]=F(""),[R,N]=F(""),[L,S]=F("all"),g=lt({functionPathPrefix:y,outcome:L,tableTouched:R,userId:x}),C=le(oe.getRequestLog,g,{enabled:t==="requests",live:!0,shardKey:n}),k=le(oe.getLogs,{},{enabled:t==="errors",live:!0,shardKey:n}),P=t==="requests"?C:k,{error:O,errorSource:_,isLoading:A,liveError:z}=P,M=Te(n),U=de(k.data),$=de(C.data);me(()=>{P.data!==void 0&&Re(n)},[P.data,n]);const K=at(U,{levels:c,now:Date.now(),path:f,range:u,search:p}),G=it(K),J=t==="requests"?$.length:K.length,X=t==="errors"&&v,W=Ne(()=>O!==null?"error":J===0?A?X?"summary":"list":"empty":X?"summary":"list",[J,A,O,X]),se=ue(null),Y=Ce({count:J,estimateSize:()=>Ze,getScrollElement:()=>se.current,initialRect:{height:te,width:800},observeElementRect:(I,Z)=>ke(I,Z,te),overscan:8}),ye=Y.getVirtualItems(),we={height:Y.getTotalSize(),position:"relative",width:"100%"};return E("div",{className:"flex flex-col gap-4","data-testid":"lunora-logs",children:[r(Xe,{liveError:z,onShardKeyChange:o,onShowArchive:()=>{a("archive"),b(!1)},onShowErrors:()=>{a("errors"),b(!1)},onShowRequests:()=>{a("requests"),b(!1)},shardKey:d,view:t}),t==="errors"&&r(He,{levelFilter:c,onLogPathChange:I=>{l(I.target.value)},onSearchChange:I=>{m(I.target.value)},onTimeRangeChange:I=>{h(I.target.value)},onToggleLevel:I=>{s(Z=>{const j=new Set(Z);return j.has(I)?j.delete(I):j.add(I),j})},onToggleSummary:()=>{b(I=>!I)},pathFilter:f,search:p,showSummary:v,timeRange:u}),t==="requests"&&r(We,{onOutcomeChange:I=>{S(I.target.value)},onPathChange:I=>{w(I.target.value)},onTableChange:I=>{N(I.target.value)},onUserChange:I=>{T(I.target.value)},outcomeFilter:L,pathPrefix:y,tableFilter:R,userIdFilter:x}),t==="archive"?r(ze,{shardKey:n}):E($e,{children:[W==="error"&&r(Se,{error:_,testId:"lg-error"}),W==="empty"&&r(ee,{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.")}),W==="summary"&&r(Ye,{summary:G}),W==="list"&&r("div",{className:"rounded-xl border border-border shadow-xs","data-testid":"lg-scroll",ref:se,style:et,children:r("div",{"aria-label":e("Recent logs"),"data-testid":"lg-table",role:"grid",style:we,children:ye.map(I=>t==="requests"?r(st,{entry:$[I.index],index:I.index,measureRef:Y.measureElement,onOpenTrace:M,start:I.start},I.key):r(rt,{entry:K[I.index],index:I.index,measureRef:Y.measureElement,onOpenTrace:M,start:I.start},I.key))})})]})]})};export{Wt as LogsPanel,at as filterLogs,it as summarizeLogs};
1
+ import{c as q}from"react/compiler-runtime";import{useVirtualizer as Ce}from"@tanstack/react-virtual";import{useState as F,useReducer as Le,useRef as ue,useEffect as me,useMemo as Ne}from"react";import{f as fe}from"../packem_shared/log-fields-SBxKyBug.js";import{E as Se}from"../packem_shared/error-alert-TYdKetJd.js";import{B as he}from"../packem_shared/badge-cAk9Di1Q.js";import{E as ee}from"../packem_shared/empty-state-B939z6K2.js";import{u as le}from"../packem_shared/use-admin-query-P0RJrjsD.js";import{u as Te}from"../packem_shared/use-open-trace-4mqqFWrn.js";import{u as Ie}from"../packem_shared/use-shard-key-BsP3o5wT.js";import{useT as Q}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.js";import{ADMIN_FUNCTIONS as oe}from"../packem_shared/ADMIN_FUNCTIONS-B6z7VLYt.js";import{r as Re}from"../packem_shared/shard-history-DU5b3QDI.js";import{f as ke}from"../packem_shared/virtual-rect-D_j7aLxX.js";import{useLunora as Pe}from"@lunora/react";import{B as Ee}from"../packem_shared/button-BOPLD1un.js";import{I as D}from"../packem_shared/input-CY5W3wzv.js";import{T as Oe,a as _e,b as ge,c as B,d as Fe,e as V}from"../packem_shared/table-BMsuYFhk.js";import ae from"../packem_shared/useDebounced-DVeQ5-oW.js";import{a as pe}from"../packem_shared/cf-links-CBJ5SywP.js";import{f as ne,m as qe,b as ie}from"../packem_shared/internal-CwaF9YNk.js";import{a as Ae,L as Me}from"../packem_shared/log-line-UnE93Ovi.js";import{jsx as r,jsxs as E,Fragment as $e}from"react/jsx-runtime";import{c as H}from"../packem_shared/utils-bhneXptQ.js";import{L as Ue}from"../packem_shared/live-status-Bf7rR8o8.js";import{ShardInput as Ke}from"../packem_shared/ShardInput-CdawpUiS.js";const re=["trace","debug","log","info","warn","error","fatal"],Be="LOG_ARCHIVE_NOT_CONFIGURED",Ve={cursor:void 0,error:null,loading:!1,notConfigured:!1,rows:null},De=(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}},Qe=i=>{const e=q(33),{row:t}=i;let a;e[0]!==t.fields?(a=fe(t.fields),e[0]=t.fields,e[1]=a):a=e[1];const n=a,o=`lg-archive-row-${String(t.ts)}`;let d;e[2]!==t.ts?(d=new Date(t.ts).toLocaleString(),e[2]=t.ts,e[3]=d):d=e[3];let p;e[4]!==d?(p=r(V,{className:"tabular-nums whitespace-nowrap text-xs text-muted-foreground",children:d}),e[4]=d,e[5]=p):p=e[5];const m=Ae[t.level];let c;e[6]!==t.level||e[7]!==m?(c=r(V,{children:r(he,{variant:m,children:t.level})}),e[6]=t.level,e[7]=m,e[8]=c):c=e[8];let s;e[9]!==t.functionPath?(s=r(V,{className:"font-mono text-xs",children:t.functionPath}),e[9]=t.functionPath,e[10]=s):s=e[10];let f;e[11]!==t.message?(f=r("div",{className:"truncate",title:t.message,children:t.message}),e[11]=t.message,e[12]=f):f=e[12];let l;e[13]!==n?(l=n!==""&&r("div",{className:"truncate font-mono text-[11px] text-muted-foreground",title:n,children:n}),e[13]=n,e[14]=l):l=e[14];let u;e[15]!==f||e[16]!==l?(u=E(V,{className:"max-w-md",children:[f,l]}),e[15]=f,e[16]=l,e[17]=u):u=e[17];const h=t.traceId??"—";let v;e[18]!==h?(v=r(V,{className:"font-mono text-[11px] text-muted-foreground",children:h}),e[18]=h,e[19]=v):v=e[19];const b=t.shardKey??"—";let y;e[20]!==b?(y=r(V,{className:"font-mono text-[11px] text-muted-foreground",children:b}),e[20]=b,e[21]=y):y=e[21];const w=t.userId??"—";let x;e[22]!==w?(x=r(V,{className:"font-mono text-[11px] text-muted-foreground",children:w}),e[22]=w,e[23]=x):x=e[23];let T;return e[24]!==u||e[25]!==v||e[26]!==y||e[27]!==x||e[28]!==o||e[29]!==p||e[30]!==c||e[31]!==s?(T=E(ge,{"data-testid":o,children:[p,c,s,u,v,y,x]}),e[24]=u,e[25]=v,e[26]=y,e[27]=x,e[28]=o,e[29]=p,e[30]=c,e[31]=s,e[32]=T):T=e[32],T},ze=({shardKey:i})=>{const e=Pe(),t=Q(),[a,n]=F(""),[o,d]=F(""),[p,m]=F(""),[{cursor:c,error:s,loading:f,notConfigured:l,rows:u},h]=Le(De,Ve),v=ae(a.trim(),400),b=ae(o.trim(),400),y={...v===""?{}:{functionPathPrefix:v},...p===""?{}:{minLevel:p},...i===""?{}:{shardKey:i},...b===""?{}:{userId:b}},w=JSON.stringify(y),x=ue(w);me(()=>{const g={cancelled:!1};return x.current=w,ne((async()=>{h({type:"loading"});try{const C=await e.queryLogArchive(y);g.cancelled||h({cursor:C.nextCursor,rows:C.rows,type:"loaded"})}catch(C){g.cancelled||h(qe(C)===Be?{type:"notConfigured"}:{message:ie(C),type:"failed"})}})()),()=>{g.cancelled=!0}},[e,w]);const T=async()=>{if(c===void 0)return;const g=w;h({type:"loading"});try{const C=await e.queryLogArchive({...y,cursor:c});x.current===g&&h({cursor:C.nextCursor,rows:C.rows,type:"append"})}catch(C){x.current===g&&h({message:ie(C),type:"pageFailed"})}},R=g=>{n(g.target.value)},N=g=>{d(g.target.value)},L=g=>{m(g.target.value)},S=()=>{ne(T())};return l?r(ee,{action:r("a",{className:"text-sm text-primary underline-offset-4 hover:underline",href:pe,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")}):E("div",{className:"flex flex-col gap-4","data-testid":"lg-archive",children:[E("div",{className:"flex flex-wrap items-center gap-2",children:[r(D,{"aria-label":t("Function path prefix"),className:"h-8 w-48","data-testid":"lg-archive-path",onChange:R,placeholder:t("function path…"),value:a}),r(D,{"aria-label":t("User id"),className:"h-8 w-40","data-testid":"lg-archive-user",onChange:N,placeholder:t("user id…"),value:o}),E("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:L,value:p,children:[r("option",{value:"",children:t("min level")}),re.map(g=>r("option",{value:g,children:g},g))]})]}),s!==null&&r("p",{className:"text-sm text-destructive","data-testid":"lg-archive-error",role:"alert",children:s}),f&&u===null&&s===null&&r("p",{className:"text-sm text-muted-foreground","data-testid":"lg-archive-loading",children:t("Loading…")}),u!==null&&u.length===0&&r(ee,{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.")}),u!==null&&u.length>0&&r("div",{className:"overflow-hidden rounded-xl border border-border shadow-xs",children:E(Oe,{"data-testid":"lg-archive-table",children:[r(_e,{children:E(ge,{children:[r(B,{children:t("Time")}),r(B,{children:t("Level")}),r(B,{children:t("Function")}),r(B,{children:t("Message")}),r(B,{children:t("Trace")}),r(B,{children:t("Shard")}),r(B,{children:t("User")})]})}),r(Fe,{children:u.map((g,C)=>r(Qe,{row:g},`${String(g.ts)}-${String(C)}`))})]})}),c!==void 0&&r("div",{children:r(Ee,{"data-testid":"lg-archive-more",disabled:f,onClick:S,size:"sm",variant:"outline",children:t(f?"Loading…":"Load more")})})]})},Ge=i=>{const e=q(11),{level:t,onToggle:a,selected:n}=i;let o;e[0]!==t||e[1]!==a?(o=()=>{a(t)},e[0]=t,e[1]=a,e[2]=o):o=e[2];const d=o,p=n?"border-border bg-muted font-medium":"border-input text-muted-foreground";let m;e[3]!==p?(m=H("rounded-md border px-2 py-1 text-xs",p),e[3]=p,e[4]=m):m=e[4];const c=`logs-level-${t}`;let s;return e[5]!==t||e[6]!==d||e[7]!==n||e[8]!==m||e[9]!==c?(s=r("button",{"aria-pressed":n,className:m,"data-testid":c,onClick:d,type:"button",children:t}),e[5]=t,e[6]=d,e[7]=n,e[8]=m,e[9]=c,e[10]=s):s=e[10],s},He=i=>{const e=q(68),{levelFilter:t,onLogPathChange:a,onSearchChange:n,onTimeRangeChange:o,onToggleLevel:d,onToggleSummary:p,pathFilter:m,search:c,showSummary:s,timeRange:f}=i,l=Q();let u;e[0]!==l?(u=l("Search messages"),e[0]=l,e[1]=u):u=e[1];let h;e[2]!==l?(h=l("search message"),e[2]=l,e[3]=h):h=e[3];let v;e[4]!==n||e[5]!==c||e[6]!==u||e[7]!==h?(v=r(D,{"aria-label":u,className:"h-8 w-48","data-testid":"lg-search",onChange:n,placeholder:h,value:c}),e[4]=n,e[5]=c,e[6]=u,e[7]=h,e[8]=v):v=e[8];let b;e[9]!==l?(b=l("Function path"),e[9]=l,e[10]=b):b=e[10];let y;e[11]!==l?(y=l("filter path"),e[11]=l,e[12]=y):y=e[12];let w;e[13]!==a||e[14]!==m||e[15]!==b||e[16]!==y?(w=r(D,{"aria-label":b,className:"h-8 w-40","data-testid":"logs-path-filter",onChange:a,placeholder:y,value:m}),e[13]=a,e[14]=m,e[15]=b,e[16]=y,e[17]=w):w=e[17];let x;e[18]!==l?(x=l("Level filter"),e[18]=l,e[19]=x):x=e[19];let T;e[20]!==t||e[21]!==d?(T=re.map(G=>r(Ge,{level:G,onToggle:d,selected:t.has(G)},G)),e[20]=t,e[21]=d,e[22]=T):T=e[22];let R;e[23]!==x||e[24]!==T?(R=r("div",{"aria-label":x,className:"inline-flex items-center gap-1","data-testid":"logs-level-filter",role:"group",children:T}),e[23]=x,e[24]=T,e[25]=R):R=e[25];let N;e[26]!==l?(N=l("Time range"),e[26]=l,e[27]=N):N=e[27];let L;e[28]!==l?(L=l("All time"),e[28]=l,e[29]=L):L=e[29];let S;e[30]!==L?(S=r("option",{value:"all",children:L}),e[30]=L,e[31]=S):S=e[31];let g;e[32]!==l?(g=l("Last 5m"),e[32]=l,e[33]=g):g=e[33];let C;e[34]!==g?(C=r("option",{value:"5m",children:g}),e[34]=g,e[35]=C):C=e[35];let k;e[36]!==l?(k=l("Last 15m"),e[36]=l,e[37]=k):k=e[37];let P;e[38]!==k?(P=r("option",{value:"15m",children:k}),e[38]=k,e[39]=P):P=e[39];let O;e[40]!==l?(O=l("Last hour"),e[40]=l,e[41]=O):O=e[41];let _;e[42]!==O?(_=r("option",{value:"1h",children:O}),e[42]=O,e[43]=_):_=e[43];let A;e[44]!==o||e[45]!==N||e[46]!==S||e[47]!==C||e[48]!==P||e[49]!==_||e[50]!==f?(A=E("select",{"aria-label":N,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:f,children:[S,C,P,_]}),e[44]=o,e[45]=N,e[46]=S,e[47]=C,e[48]=P,e[49]=_,e[50]=f,e[51]=A):A=e[51];const z=s?"border-border bg-muted font-medium":"border-input text-muted-foreground";let M;e[52]!==z?(M=H("h-8 rounded-md border px-3 text-sm",z),e[52]=z,e[53]=M):M=e[53];let U;e[54]!==s||e[55]!==l?(U=l(s?"List":"Summary"),e[54]=s,e[55]=l,e[56]=U):U=e[56];let $;e[57]!==p||e[58]!==s||e[59]!==M||e[60]!==U?($=r("button",{"aria-pressed":s,className:M,"data-testid":"logs-summary-toggle",onClick:p,type:"button",children:U}),e[57]=p,e[58]=s,e[59]=M,e[60]=U,e[61]=$):$=e[61];let K;return e[62]!==A||e[63]!==$||e[64]!==v||e[65]!==w||e[66]!==R?(K=E("div",{className:"flex flex-wrap items-center gap-2",children:[v,w,R,A,$]}),e[62]=A,e[63]=$,e[64]=v,e[65]=w,e[66]=R,e[67]=K):K=e[67],K},We=i=>{const e=q(53),{onOutcomeChange:t,onPathChange:a,onTableChange:n,onUserChange:o,outcomeFilter:d,pathPrefix:p,tableFilter:m,userIdFilter:c}=i,s=Q();let f;e[0]!==s?(f=s("Function path"),e[0]=s,e[1]=f):f=e[1];let l;e[2]!==s?(l=s("file:function"),e[2]=s,e[3]=l):l=e[3];let u;e[4]!==a||e[5]!==p||e[6]!==f||e[7]!==l?(u=r(D,{"aria-label":f,className:"h-8 w-44","data-testid":"lg-req-path",onChange:a,placeholder:l,value:p}),e[4]=a,e[5]=p,e[6]=f,e[7]=l,e[8]=u):u=e[8];let h;e[9]!==s?(h=s("User id"),e[9]=s,e[10]=h):h=e[10];let v;e[11]!==s?(v=s("userId"),e[11]=s,e[12]=v):v=e[12];let b;e[13]!==o||e[14]!==h||e[15]!==v||e[16]!==c?(b=r(D,{"aria-label":h,className:"h-8 w-32","data-testid":"lg-req-user",onChange:o,placeholder:v,value:c}),e[13]=o,e[14]=h,e[15]=v,e[16]=c,e[17]=b):b=e[17];let y;e[18]!==s?(y=s("Table touched"),e[18]=s,e[19]=y):y=e[19];let w;e[20]!==s?(w=s("table"),e[20]=s,e[21]=w):w=e[21];let x;e[22]!==n||e[23]!==y||e[24]!==w||e[25]!==m?(x=r(D,{"aria-label":y,className:"h-8 w-32","data-testid":"lg-req-table",onChange:n,placeholder:w,value:m}),e[22]=n,e[23]=y,e[24]=w,e[25]=m,e[26]=x):x=e[26];let T;e[27]!==s?(T=s("Outcome filter"),e[27]=s,e[28]=T):T=e[28];let R;e[29]!==s?(R=s("all"),e[29]=s,e[30]=R):R=e[30];let N;e[31]!==R?(N=r("option",{value:"all",children:R}),e[31]=R,e[32]=N):N=e[32];let L;e[33]!==s?(L=s("ok"),e[33]=s,e[34]=L):L=e[34];let S;e[35]!==L?(S=r("option",{value:"ok",children:L}),e[35]=L,e[36]=S):S=e[36];let g;e[37]!==s?(g=s("error"),e[37]=s,e[38]=g):g=e[38];let C;e[39]!==g?(C=r("option",{value:"error",children:g}),e[39]=g,e[40]=C):C=e[40];let k;e[41]!==t||e[42]!==d||e[43]!==T||e[44]!==N||e[45]!==S||e[46]!==C?(k=E("select",{"aria-label":T,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:d,children:[N,S,C]}),e[41]=t,e[42]=d,e[43]=T,e[44]=N,e[45]=S,e[46]=C,e[47]=k):k=e[47];let P;return e[48]!==k||e[49]!==u||e[50]!==b||e[51]!==x?(P=E("div",{className:"flex flex-wrap items-center gap-2",children:[u,b,x,k]}),e[48]=k,e[49]=u,e[50]=b,e[51]=x,e[52]=P):P=e[52],P},ve=i=>{const e=q(7),{bucket:t}=i;let a;e[0]!==t.key?(a=r("span",{className:"truncate text-muted-foreground",role:"gridcell",children:t.key}),e[0]=t.key,e[1]=a):a=e[1];let n;e[2]!==t.count?(n=r("span",{className:"shrink-0 tabular-nums",role:"gridcell",children:t.count}),e[2]=t.count,e[3]=n):n=e[3];let o;return e[4]!==a||e[5]!==n?(o=E("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:[a,n]}),e[4]=a,e[5]=n,e[6]=o):o=e[6],o},Ye=i=>{const e=q(31),{summary:t}=i,a=Q();let n;e[0]!==t.total||e[1]!==a?(n=a("{count} entries",{count:t.total}),e[0]=t.total,e[1]=a,e[2]=n):n=e[2];let o;e[3]!==n?(o=r("p",{className:"text-xs text-muted-foreground","data-testid":"logs-summary-total",children:n}),e[3]=n,e[4]=o):o=e[4];let d;e[5]!==a?(d=a("By level"),e[5]=a,e[6]=d):d=e[6];let p;e[7]!==d?(p=r("h4",{className:"mb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:d}),e[7]=d,e[8]=p):p=e[8];let m;e[9]!==t.byLevel?(m=t.byLevel.map(je),e[9]=t.byLevel,e[10]=m):m=e[10];let c;e[11]!==m?(c=r("div",{className:"overflow-hidden rounded-lg border border-border","data-testid":"logs-summary-levels",role:"grid",children:m}),e[11]=m,e[12]=c):c=e[12];let s;e[13]!==p||e[14]!==c?(s=E("div",{children:[p,c]}),e[13]=p,e[14]=c,e[15]=s):s=e[15];let f;e[16]!==a?(f=a("By function"),e[16]=a,e[17]=f):f=e[17];let l;e[18]!==f?(l=r("h4",{className:"mb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:f}),e[18]=f,e[19]=l):l=e[19];let u;e[20]!==t.byPath?(u=t.byPath.map(Je),e[20]=t.byPath,e[21]=u):u=e[21];let h;e[22]!==u?(h=r("div",{className:"overflow-hidden rounded-lg border border-border","data-testid":"logs-summary-paths",role:"grid",children:u}),e[22]=u,e[23]=h):h=e[23];let v;e[24]!==h||e[25]!==l?(v=E("div",{children:[l,h]}),e[24]=h,e[25]=l,e[26]=v):v=e[26];let b;return e[27]!==v||e[28]!==o||e[29]!==s?(b=E("div",{className:"flex flex-col gap-4 rounded-xl border border-border bg-card p-4 shadow-xs","data-testid":"logs-summary",children:[o,s,v]}),e[27]=v,e[28]=o,e[29]=s,e[30]=b):b=e[30],b};function je(i){return r(ve,{bucket:i},i.key)}function Je(i){return r(ve,{bucket:i},i.key)}const Xe=i=>{const e=q(46),{liveError:t,onShardKeyChange:a,onShowArchive:n,onShowErrors:o,onShowRequests:d,shardKey:p,view:m}=i,c=Q(),s=m==="requests",f=m==="requests"?"bg-muted font-medium":"text-muted-foreground";let l;e[0]!==f?(l=H("px-3 py-1 text-sm",f),e[0]=f,e[1]=l):l=e[1];let u;e[2]!==c?(u=c("Requests"),e[2]=c,e[3]=u):u=e[3];let h;e[4]!==d||e[5]!==s||e[6]!==l||e[7]!==u?(h=r("button",{"aria-selected":s,className:l,"data-testid":"lg-view-requests",onClick:d,role:"tab",type:"button",children:u}),e[4]=d,e[5]=s,e[6]=l,e[7]=u,e[8]=h):h=e[8];const v=m==="errors",b=m==="errors"?"bg-muted font-medium":"text-muted-foreground";let y;e[9]!==b?(y=H("px-3 py-1 text-sm",b),e[9]=b,e[10]=y):y=e[10];let w;e[11]!==c?(w=c("Errors"),e[11]=c,e[12]=w):w=e[12];let x;e[13]!==o||e[14]!==v||e[15]!==y||e[16]!==w?(x=r("button",{"aria-selected":v,className:y,"data-testid":"lg-view-errors",onClick:o,role:"tab",type:"button",children:w}),e[13]=o,e[14]=v,e[15]=y,e[16]=w,e[17]=x):x=e[17];const T=m==="archive",R=m==="archive"?"bg-muted font-medium":"text-muted-foreground";let N;e[18]!==R?(N=H("px-3 py-1 text-sm",R),e[18]=R,e[19]=N):N=e[19];let L;e[20]!==c?(L=c("Archive"),e[20]=c,e[21]=L):L=e[21];let S;e[22]!==n||e[23]!==T||e[24]!==N||e[25]!==L?(S=r("button",{"aria-selected":T,className:N,"data-testid":"lg-view-archive",onClick:n,role:"tab",type:"button",children:L}),e[22]=n,e[23]=T,e[24]=N,e[25]=L,e[26]=S):S=e[26];let g;e[27]!==x||e[28]!==S||e[29]!==h?(g=E("div",{className:"inline-flex overflow-hidden rounded-lg border border-border",role:"tablist",children:[h,x,S]}),e[27]=x,e[28]=S,e[29]=h,e[30]=g):g=e[30];let C;e[31]!==a||e[32]!==p?(C=r(Ke,{onChange:a,testId:"lg-shard-input",value:p}),e[31]=a,e[32]=p,e[33]=C):C=e[33];let k;e[34]!==t||e[35]!==m?(k=m!=="archive"&&r(Ue,{message:t,prefix:"lg"}),e[34]=t,e[35]=m,e[36]=k):k=e[36];let P;e[37]!==c?(P=c("Open in Cloudflare"),e[37]=c,e[38]=P):P=e[38];let O;e[39]!==P?(O=r("a",{className:"text-sm text-primary underline-offset-4 hover:underline","data-testid":"lg-cf-link",href:pe,rel:"noreferrer",target:"_blank",children:P}),e[39]=P,e[40]=O):O=e[40];let _;return e[41]!==g||e[42]!==C||e[43]!==k||e[44]!==O?(_=E("div",{className:"flex flex-wrap items-center gap-2",children:[g,C,k,O]}),e[41]=g,e[42]=C,e[43]=k,e[44]=O,e[45]=_):_=e[45],_},te=400,Ze=36,et={height:te,overflow:"auto"},be={left:0,position:"absolute",top:0,width:"100%"},tt={error:"destructive",ok:"secondary"},xe=i=>{const e=q(6),{onOpenTrace:t,traceId:a}=i,n=Q();let o;e[0]!==t||e[1]!==n||e[2]!==a?(o=a===void 0?null:r("button",{className:"text-primary underline-offset-2 hover:underline","data-testid":"lg-trace-link",onClick:()=>{t(a)},type:"button",children:n("Trace")}),e[0]=t,e[1]=n,e[2]=a,e[3]=o):o=e[3];let d;return e[4]!==o?(d=r("span",{className:"w-16 shrink-0 text-right",role:"gridcell",children:o}),e[4]=o,e[5]=d):d=e[5],d},rt=i=>{const e=q(13),{entry:t,index:a,measureRef:n,onOpenTrace:o,start:d}=i,p=`translateY(${String(d)}px)`;let m;e[0]!==p?(m={...be,transform:p},e[0]=p,e[1]=m):m=e[1];const c=m;let s;e[2]!==t?(s=r(Me,{entry:t}),e[2]=t,e[3]=s):s=e[3];let f;e[4]!==t.traceId||e[5]!==o?(f=r(xe,{onOpenTrace:o,traceId:t.traceId}),e[4]=t.traceId,e[5]=o,e[6]=f):f=e[6];let l;return e[7]!==a||e[8]!==n||e[9]!==c||e[10]!==s||e[11]!==f?(l=E("div",{className:"flex items-center border-b border-border px-3 py-1.5 font-mono text-xs hover:bg-muted/50","data-index":a,"data-testid":"lg-row",ref:n,role:"row",style:c,children:[s,f]}),e[7]=a,e[8]=n,e[9]=c,e[10]=s,e[11]=f,e[12]=l):l=e[12],l},ce=i=>i.length===0?"—":i.join(", "),st=i=>{const e=q(41),{entry:t,index:a,measureRef:n,onOpenTrace:o,start:d}=i,p=`translateY(${String(d)}px)`;let m;e[0]!==p?(m={...be,transform:p},e[0]=p,e[1]=m):m=e[1];const c=m;let s;e[2]!==t.ts?(s=new Date(t.ts).toLocaleString(),e[2]=t.ts,e[3]=s):s=e[3];let f;e[4]!==s?(f=r("span",{className:"w-40 shrink-0 tabular-nums text-muted-foreground",role:"gridcell",children:s}),e[4]=s,e[5]=f):f=e[5];const l=tt[t.outcome];let u;e[6]!==t.outcome||e[7]!==l?(u=r("span",{className:"w-16 shrink-0",role:"gridcell",children:r(he,{variant:l,children:t.outcome})}),e[6]=t.outcome,e[7]=l,e[8]=u):u=e[8];let h;e[9]!==t.functionPath?(h=r("span",{className:"w-44 shrink-0 truncate",role:"gridcell",title:t.functionPath,children:t.functionPath}),e[9]=t.functionPath,e[10]=h):h=e[10];const v=t.shardKey??"—";let b;e[11]!==v?(b=r("span",{className:"w-24 shrink-0 truncate text-muted-foreground",role:"gridcell",children:v}),e[11]=v,e[12]=b):b=e[12];const y=t.userId??"—";let w;e[13]!==y?(w=r("span",{className:"w-24 shrink-0 truncate text-muted-foreground",role:"gridcell",children:y}),e[13]=y,e[14]=w):w=e[14];let x;e[15]!==t.durationMs?(x=Math.round(t.durationMs),e[15]=t.durationMs,e[16]=x):x=e[16];const T=`${String(x)}ms`;let R;e[17]!==T?(R=r("span",{className:"w-16 shrink-0 tabular-nums text-muted-foreground",role:"gridcell",children:T}),e[17]=T,e[18]=R):R=e[18];let N;e[19]!==t.errorMessage||e[20]!==t.outcome||e[21]!==t.tablesRead||e[22]!==t.tablesWritten?(N=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]=N):N=e[23];let L;e[24]!==N?(L=r("span",{className:"flex-1 truncate text-muted-foreground",role:"gridcell",children:N}),e[24]=N,e[25]=L):L=e[25];let S;e[26]!==t.traceId||e[27]!==o?(S=r(xe,{onOpenTrace:o,traceId:t.traceId}),e[26]=t.traceId,e[27]=o,e[28]=S):S=e[28];let g;return e[29]!==a||e[30]!==n||e[31]!==c||e[32]!==w||e[33]!==R||e[34]!==L||e[35]!==S||e[36]!==f||e[37]!==u||e[38]!==h||e[39]!==b?(g=E("div",{className:"flex items-center border-b border-border px-3 py-1.5 font-mono text-xs hover:bg-muted/50","data-index":a,"data-testid":"lg-req-row",ref:n,role:"row",style:c,children:[f,u,h,b,w,R,L,S]}),e[29]=a,e[30]=n,e[31]=c,e[32]=w,e[33]=R,e[34]=L,e[35]=S,e[36]=f,e[37]=u,e[38]=h,e[39]=b,e[40]=g):g=e[40],g},de=i=>{const{entries:e}=i??{};return Array.isArray(e)?e:[]},lt=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},ot={"5m":300*1e3,"15m":900*1e3,"1h":3600*1e3},at=(i,e)=>{const t=e.search.trim().toLowerCase(),a=e.path.trim().toLowerCase(),n=e.range==="all"?Number.NEGATIVE_INFINITY:e.now-ot[e.range];return i.filter(o=>e.levels.size>0&&!e.levels.has(o.level)||o.timestamp<n||a!==""&&!(o.functionPath??"").toLowerCase().includes(a)?!1:t===""||o.message.toLowerCase().includes(t)||fe(o.fields).toLowerCase().includes(t))},nt="—",it=i=>{const e=new Map,t=new Map;for(const o of i){e.set(o.level,(e.get(o.level)??0)+1);const d=o.functionPath??nt;t.set(d,(t.get(d)??0)+1)}const a=re.filter(o=>e.has(o)).map(o=>({count:e.get(o)??0,key:o})),n=[...t.entries()].map(([o,d])=>({count:d,key:o})).toSorted((o,d)=>d.count===o.count?o.key.localeCompare(d.key):d.count-o.count);return{byLevel:a,byPath:n,total:i.length}},Wt=({initialShardKey:i})=>{const e=Q(),[t,a]=F("requests"),{queryShardKey:n,setShardKey:o,shardKey:d}=Ie(i),[p,m]=F(""),[c,s]=F(()=>new Set),[f,l]=F(""),[u,h]=F("all"),[v,b]=F(!1),[y,w]=F(""),[x,T]=F(""),[R,N]=F(""),[L,S]=F("all"),g=lt({functionPathPrefix:y,outcome:L,tableTouched:R,userId:x}),C=le(oe.getRequestLog,g,{enabled:t==="requests",live:!0,shardKey:n}),k=le(oe.getLogs,{},{enabled:t==="errors",live:!0,shardKey:n}),P=t==="requests"?C:k,{error:O,errorSource:_,isLoading:A,liveError:z}=P,M=Te(n),U=de(k.data),$=de(C.data);me(()=>{P.data!==void 0&&Re(n)},[P.data,n]);const K=at(U,{levels:c,now:Date.now(),path:f,range:u,search:p}),G=it(K),J=t==="requests"?$.length:K.length,X=t==="errors"&&v,W=Ne(()=>O!==null?"error":J===0?A?X?"summary":"list":"empty":X?"summary":"list",[J,A,O,X]),se=ue(null),Y=Ce({count:J,estimateSize:()=>Ze,getScrollElement:()=>se.current,initialRect:{height:te,width:800},observeElementRect:(I,Z)=>ke(I,Z,te),overscan:8}),ye=Y.getVirtualItems(),we={height:Y.getTotalSize(),position:"relative",width:"100%"};return E("div",{className:"flex flex-col gap-4","data-testid":"lunora-logs",children:[r(Xe,{liveError:z,onShardKeyChange:o,onShowArchive:()=>{a("archive"),b(!1)},onShowErrors:()=>{a("errors"),b(!1)},onShowRequests:()=>{a("requests"),b(!1)},shardKey:d,view:t}),t==="errors"&&r(He,{levelFilter:c,onLogPathChange:I=>{l(I.target.value)},onSearchChange:I=>{m(I.target.value)},onTimeRangeChange:I=>{h(I.target.value)},onToggleLevel:I=>{s(Z=>{const j=new Set(Z);return j.has(I)?j.delete(I):j.add(I),j})},onToggleSummary:()=>{b(I=>!I)},pathFilter:f,search:p,showSummary:v,timeRange:u}),t==="requests"&&r(We,{onOutcomeChange:I=>{S(I.target.value)},onPathChange:I=>{w(I.target.value)},onTableChange:I=>{N(I.target.value)},onUserChange:I=>{T(I.target.value)},outcomeFilter:L,pathPrefix:y,tableFilter:R,userIdFilter:x}),t==="archive"?r(ze,{shardKey:n}):E($e,{children:[W==="error"&&r(Se,{error:_,testId:"lg-error"}),W==="empty"&&r(ee,{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.")}),W==="summary"&&r(Ye,{summary:G}),W==="list"&&r("div",{className:"rounded-xl border border-border shadow-xs","data-testid":"lg-scroll",ref:se,style:et,children:r("div",{"aria-label":e("Recent logs"),"data-testid":"lg-table",role:"grid",style:we,children:ye.map(I=>t==="requests"?r(st,{entry:$[I.index],index:I.index,measureRef:Y.measureElement,onOpenTrace:M,start:I.start},I.key):r(rt,{entry:K[I.index],index:I.index,measureRef:Y.measureElement,onOpenTrace:M,start:I.start},I.key))})})]})]})};export{Wt as LogsPanel,at as filterLogs,it as summarizeLogs};
@@ -1,2 +1,2 @@
1
- import{E as ie}from"../packem_shared/error-alert-CKqB2CiN.js";import{B as se}from"../packem_shared/badge-cAk9Di1Q.js";import{B as v}from"../packem_shared/button-BOPLD1un.js";import{E as oe}from"../packem_shared/empty-state-B939z6K2.js";import{I as ne}from"../packem_shared/input-CY5W3wzv.js";import{S as le}from"../packem_shared/scroll-area-DSJftwu_.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 n,Fragment as me}from"react/jsx-runtime";import{useT as ue}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.js";import{c as ae,d as Y,b as Z,f as ee,g as he,i as te}from"../packem_shared/internal-7bgd8inO.js";import{c as pe}from"react/compiler-runtime";import{useLunora as fe}from"@lunora/react";import{useState as O}from"react";import{u as be}from"../packem_shared/use-admin-query-DV9xmFl8.js";import{useAutoRefresh as xe}from"../packem_shared/DEFAULT_AUTO_REFRESH_MS-DuULO4XM.js";import{ADMIN_FUNCTIONS as X}from"../packem_shared/ADMIN_FUNCTIONS-B6z7VLYt.js";function ge({className:r,orientation:e="horizontal",...s}){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",r),...s})}const ve=/https?:\/\/[^\s"'<>)]+/i,re=r=>r===void 0?void 0:ve.exec(r)?.[0],N=r=>r===void 0?"":Array.isArray(r)?r.join(", "):r,Ne=r=>{if(r!==void 0)return re(r.html)??re(r.text)},we=(r,e)=>{const s=e.trim().toLowerCase();return s===""?r:r.filter(o=>`${o.subject} ${N(o.to)} ${N(o.cc)}`.toLowerCase().includes(s))},ye=(r,e)=>{if(r.length!==0)return r.find(s=>s.id===e)??r[0]},Ce=ae(X.clearCapturedMail),Se=ae(X.sendTestMail),Te=r=>{const e=pe(38),{limit:s}=r,o=fe();let p;e[0]!==s?(p={limit:s},e[0]=s,e[1]=p):p=e[1];const{data:R,error:w,errorSource:y,isLoading:x,refetch:l}=be(X.getCapturedMail,p),[C,f]=O(null),[B,S]=O(null),[g,i]=O("html"),[c,D]=O(""),b=R?.entries??[],a=w??C,h=w===null?C:y;let T;e[2]!==o||e[3]!==l?(T=async()=>{f(null);try{await o.query(Ce,{},Y("")),S(null),l()}catch(m){f(Z(m))}},e[2]=o,e[3]=l,e[4]=T):T=e[4];const H=T;let k;e[5]!==o||e[6]!==l?(k=async()=>{f(null);try{await o.query(Se,{},Y("")),l()}catch(m){f(Z(m))}},e[5]=o,e[6]=l,e[7]=k):k=e[7];const q=k;let L;e[8]!==l?(L=()=>{l()},e[8]=l,e[9]=L):L=e[9],xe(L,!0);let A;e[10]!==H?(A=()=>{ee(H())},e[10]=H,e[11]=A):A=e[11];const U=A;let E;e[12]!==q?(E=()=>{ee(q())},e[12]=q,e[13]=E):E=e[13];const W=E;let _;e[14]===Symbol.for("react.memo_cache_sentinel")?(_=m=>{D(m.currentTarget.value)},e[14]=_):_=e[14];const K=_;let M;e[15]===Symbol.for("react.memo_cache_sentinel")?(M=m=>{const{id:u}=m.currentTarget.dataset;u!==void 0&&S(u)},e[15]=M):M=e[15];const Q=M;let j;e[16]===Symbol.for("react.memo_cache_sentinel")?(j=m=>{const u=m.currentTarget.dataset.tab;(u==="headers"||u==="html"||u==="text")&&i(u)},e[16]=j):j=e[16];const V=j,I=we(b,c),$=ye(I,B),d=Ne($);let z;e[17]!==d?(z=()=>{d!==void 0&&he(d)},e[17]=d,e[18]=z):z=e[18];const G=z;let F;e[19]!==d?(F=()=>{d!==void 0&&"window"in globalThis&&globalThis.window.open(d,"_blank","noopener")},e[19]=d,e[20]=F):F=e[20];const J=F;let P;return e[21]!==b||e[22]!==a||e[23]!==h||e[24]!==c||e[25]!==x||e[26]!==d||e[27]!==U||e[28]!==G||e[29]!==K||e[30]!==J||e[31]!==Q||e[32]!==V||e[33]!==W||e[34]!==$||e[35]!==g||e[36]!==I?(P={entries:b,error:a,errorSource:h,filter:c,isLoading:x,link:d,onClear:U,onCopyLink:G,onFilterChange:K,onOpenLink:J,onSelectMessage:Q,onSelectTab:V,onSendTest:W,selected:$,tab:g,visible:I},e[21]=b,e[22]=a,e[23]=h,e[24]=c,e[25]=x,e[26]=d,e[27]=U,e[28]=G,e[29]=K,e[30]=J,e[31]=Q,e[32]=V,e[33]=W,e[34]=$,e[35]=g,e[36]=I,e[37]=P):P=e[37],P},ke=`<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src data:; style-src 'unsafe-inline'; font-src data:">`,Le=r=>`${ke}${r}`,We=({limit:r=100})=>{const e=ue(),{entries:s,error:o,errorSource:p,filter:R,isLoading:w,link:y,onClear:x,onCopyLink:l,onFilterChange:C,onOpenLink:f,onSelectMessage:B,onSelectTab:S,onSendTest:g,selected:i,tab:c,visible:D}=Te({limit:r}),b=a=>e(a==="html"?"HTML":a==="text"?"Plain text":"Headers");return n("div",{className:"flex flex-col gap-4","data-testid":"mail-panel",children:[n("div",{className:"flex flex-wrap items-center gap-2",children:[t(v,{"data-testid":"mail-send-test",onClick:g,size:"sm",type:"button",variant:"outline",children:e("Send test")}),t(v,{"data-testid":"mail-clear",disabled:s.length===0,onClick:x,size:"sm",type:"button",variant:"outline",children:e("Clear inbox")}),s.length>0&&t(se,{className:"ml-auto","data-testid":"mail-count",variant:"secondary",children:e("{count} messages",{count:s.length})})]}),o!==null&&t(ie,{error:p,testId:"mail-error"}),o===null&&!w&&s.length===0&&t(oe,{description:e("Email your app sends in dev is captured here — nothing is delivered."),icon:n("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.")}),s.length>0&&n("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-[minmax(0,22rem)_1fr]","data-testid":"mail-reader",children:[n("div",{className:"flex flex-col gap-2",children:[t(ne,{"aria-label":e("Search messages"),"data-testid":"mail-search",onChange:C,placeholder:e("Filter messages"),type:"search",value:R}),t(le,{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(a=>{const h=a.id===i?.id;return t("li",{children:n("button",{className:`flex w-full flex-col items-start gap-0.5 px-3 py-2 text-left text-sm hover:bg-muted/60 ${h?"bg-muted":""}`,"data-active":h,"data-id":a.id,"data-testid":"mail-list-item",onClick:B,type:"button",children:[t("span",{className:"w-full truncate font-medium",children:a.subject||e("(no subject)")}),t("span",{className:"w-full truncate text-xs text-muted-foreground",children:N(a.to)}),t("span",{className:"text-xs text-muted-foreground tabular-nums",children:te(a.capturedAt,"—")})]})},a.id)})})})]}),i!==void 0&&n("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:[n("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)")}),n("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&&n(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,"—")})]})]}),n("div",{className:"flex flex-wrap items-center gap-2","data-testid":"mail-actions",children:[t(v,{"data-testid":"mail-copy-link",disabled:y===void 0,onClick:l,size:"sm",type:"button",variant:"outline",children:e("Copy link")}),t(v,{"data-testid":"mail-open-link",disabled:y===void 0,onClick:f,size:"sm",type:"button",variant:"outline",children:e("Open in new tab")})]}),t(ge,{}),t("div",{className:"flex items-center gap-1","data-testid":"mail-tabs",role:"tablist",children:["html","text","headers"].map(a=>t(v,{"aria-selected":c===a,"data-tab":a,"data-testid":`mail-tab-${a}`,onClick:S,role:"tab",size:"sm",type:"button",variant:c===a?"secondary":"ghost",children:b(a)},a))}),n("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:Le(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(([a,h])=>`${a}: ${h}`).join(`
1
+ import{E as ie}from"../packem_shared/error-alert-TYdKetJd.js";import{B as se}from"../packem_shared/badge-cAk9Di1Q.js";import{B as v}from"../packem_shared/button-BOPLD1un.js";import{E as oe}from"../packem_shared/empty-state-B939z6K2.js";import{I as ne}from"../packem_shared/input-CY5W3wzv.js";import{S as le}from"../packem_shared/scroll-area-DSJftwu_.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 n,Fragment as me}from"react/jsx-runtime";import{useT as ue}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.js";import{c as ae,d as Y,b as Z,f as ee,g as he,i as te}from"../packem_shared/internal-CwaF9YNk.js";import{c as pe}from"react/compiler-runtime";import{useLunora as fe}from"@lunora/react";import{useState as O}from"react";import{u as be}from"../packem_shared/use-admin-query-P0RJrjsD.js";import{useAutoRefresh as xe}from"../packem_shared/DEFAULT_AUTO_REFRESH_MS-DuULO4XM.js";import{ADMIN_FUNCTIONS as X}from"../packem_shared/ADMIN_FUNCTIONS-B6z7VLYt.js";function ge({className:r,orientation:e="horizontal",...s}){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",r),...s})}const ve=/https?:\/\/[^\s"'<>)]+/i,re=r=>r===void 0?void 0:ve.exec(r)?.[0],N=r=>r===void 0?"":Array.isArray(r)?r.join(", "):r,Ne=r=>{if(r!==void 0)return re(r.html)??re(r.text)},we=(r,e)=>{const s=e.trim().toLowerCase();return s===""?r:r.filter(o=>`${o.subject} ${N(o.to)} ${N(o.cc)}`.toLowerCase().includes(s))},ye=(r,e)=>{if(r.length!==0)return r.find(s=>s.id===e)??r[0]},Ce=ae(X.clearCapturedMail),Se=ae(X.sendTestMail),Te=r=>{const e=pe(38),{limit:s}=r,o=fe();let p;e[0]!==s?(p={limit:s},e[0]=s,e[1]=p):p=e[1];const{data:R,error:w,errorSource:y,isLoading:x,refetch:l}=be(X.getCapturedMail,p),[C,f]=O(null),[B,S]=O(null),[g,i]=O("html"),[c,D]=O(""),b=R?.entries??[],a=w??C,h=w===null?C:y;let T;e[2]!==o||e[3]!==l?(T=async()=>{f(null);try{await o.query(Ce,{},Y("")),S(null),l()}catch(m){f(Z(m))}},e[2]=o,e[3]=l,e[4]=T):T=e[4];const H=T;let k;e[5]!==o||e[6]!==l?(k=async()=>{f(null);try{await o.query(Se,{},Y("")),l()}catch(m){f(Z(m))}},e[5]=o,e[6]=l,e[7]=k):k=e[7];const q=k;let L;e[8]!==l?(L=()=>{l()},e[8]=l,e[9]=L):L=e[9],xe(L,!0);let A;e[10]!==H?(A=()=>{ee(H())},e[10]=H,e[11]=A):A=e[11];const U=A;let E;e[12]!==q?(E=()=>{ee(q())},e[12]=q,e[13]=E):E=e[13];const W=E;let _;e[14]===Symbol.for("react.memo_cache_sentinel")?(_=m=>{D(m.currentTarget.value)},e[14]=_):_=e[14];const K=_;let M;e[15]===Symbol.for("react.memo_cache_sentinel")?(M=m=>{const{id:u}=m.currentTarget.dataset;u!==void 0&&S(u)},e[15]=M):M=e[15];const Q=M;let j;e[16]===Symbol.for("react.memo_cache_sentinel")?(j=m=>{const u=m.currentTarget.dataset.tab;(u==="headers"||u==="html"||u==="text")&&i(u)},e[16]=j):j=e[16];const V=j,I=we(b,c),$=ye(I,B),d=Ne($);let z;e[17]!==d?(z=()=>{d!==void 0&&he(d)},e[17]=d,e[18]=z):z=e[18];const G=z;let F;e[19]!==d?(F=()=>{d!==void 0&&"window"in globalThis&&globalThis.window.open(d,"_blank","noopener")},e[19]=d,e[20]=F):F=e[20];const J=F;let P;return e[21]!==b||e[22]!==a||e[23]!==h||e[24]!==c||e[25]!==x||e[26]!==d||e[27]!==U||e[28]!==G||e[29]!==K||e[30]!==J||e[31]!==Q||e[32]!==V||e[33]!==W||e[34]!==$||e[35]!==g||e[36]!==I?(P={entries:b,error:a,errorSource:h,filter:c,isLoading:x,link:d,onClear:U,onCopyLink:G,onFilterChange:K,onOpenLink:J,onSelectMessage:Q,onSelectTab:V,onSendTest:W,selected:$,tab:g,visible:I},e[21]=b,e[22]=a,e[23]=h,e[24]=c,e[25]=x,e[26]=d,e[27]=U,e[28]=G,e[29]=K,e[30]=J,e[31]=Q,e[32]=V,e[33]=W,e[34]=$,e[35]=g,e[36]=I,e[37]=P):P=e[37],P},ke=`<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src data:; style-src 'unsafe-inline'; font-src data:">`,Le=r=>`${ke}${r}`,We=({limit:r=100})=>{const e=ue(),{entries:s,error:o,errorSource:p,filter:R,isLoading:w,link:y,onClear:x,onCopyLink:l,onFilterChange:C,onOpenLink:f,onSelectMessage:B,onSelectTab:S,onSendTest:g,selected:i,tab:c,visible:D}=Te({limit:r}),b=a=>e(a==="html"?"HTML":a==="text"?"Plain text":"Headers");return n("div",{className:"flex flex-col gap-4","data-testid":"mail-panel",children:[n("div",{className:"flex flex-wrap items-center gap-2",children:[t(v,{"data-testid":"mail-send-test",onClick:g,size:"sm",type:"button",variant:"outline",children:e("Send test")}),t(v,{"data-testid":"mail-clear",disabled:s.length===0,onClick:x,size:"sm",type:"button",variant:"outline",children:e("Clear inbox")}),s.length>0&&t(se,{className:"ml-auto","data-testid":"mail-count",variant:"secondary",children:e("{count} messages",{count:s.length})})]}),o!==null&&t(ie,{error:p,testId:"mail-error"}),o===null&&!w&&s.length===0&&t(oe,{description:e("Email your app sends in dev is captured here — nothing is delivered."),icon:n("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.")}),s.length>0&&n("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-[minmax(0,22rem)_1fr]","data-testid":"mail-reader",children:[n("div",{className:"flex flex-col gap-2",children:[t(ne,{"aria-label":e("Search messages"),"data-testid":"mail-search",onChange:C,placeholder:e("Filter messages"),type:"search",value:R}),t(le,{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(a=>{const h=a.id===i?.id;return t("li",{children:n("button",{className:`flex w-full flex-col items-start gap-0.5 px-3 py-2 text-left text-sm hover:bg-muted/60 ${h?"bg-muted":""}`,"data-active":h,"data-id":a.id,"data-testid":"mail-list-item",onClick:B,type:"button",children:[t("span",{className:"w-full truncate font-medium",children:a.subject||e("(no subject)")}),t("span",{className:"w-full truncate text-xs text-muted-foreground",children:N(a.to)}),t("span",{className:"text-xs text-muted-foreground tabular-nums",children:te(a.capturedAt,"—")})]})},a.id)})})})]}),i!==void 0&&n("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:[n("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)")}),n("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&&n(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,"—")})]})]}),n("div",{className:"flex flex-wrap items-center gap-2","data-testid":"mail-actions",children:[t(v,{"data-testid":"mail-copy-link",disabled:y===void 0,onClick:l,size:"sm",type:"button",variant:"outline",children:e("Copy link")}),t(v,{"data-testid":"mail-open-link",disabled:y===void 0,onClick:f,size:"sm",type:"button",variant:"outline",children:e("Open in new tab")})]}),t(ge,{}),t("div",{className:"flex items-center gap-1","data-testid":"mail-tabs",role:"tablist",children:["html","text","headers"].map(a=>t(v,{"aria-selected":c===a,"data-tab":a,"data-testid":`mail-tab-${a}`,onClick:S,role:"tab",size:"sm",type:"button",variant:c===a?"secondary":"ghost",children:b(a)},a))}),n("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:Le(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(([a,h])=>`${a}: ${h}`).join(`
2
2
  `)}))]})]})]})]})};export{We as MailPanel};
@@ -1 +1 @@
1
- import{useLunora as gt}from"@lunora/react";import{useState as pe,useRef as Ge,useEffect as tt,useMemo as pt}from"react";import{L as xt}from"../packem_shared/live-status-Bf7rR8o8.js";import{ShardInput as bt}from"../packem_shared/ShardInput-CdawpUiS.js";import{B as rt}from"../packem_shared/button-BOPLD1un.js";import{u as Ue}from"../packem_shared/use-admin-query-DV9xmFl8.js";import{u as yt}from"../packem_shared/use-open-trace-ClAdPkGD.js";import{u as vt}from"../packem_shared/use-shard-key-BsP3o5wT.js";import{useT as xe}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.js";import{ADMIN_FUNCTIONS as Fe}from"../packem_shared/ADMIN_FUNCTIONS-B6z7VLYt.js";import{c as Nt}from"../packem_shared/cf-links-CBJ5SywP.js";import{m as St,l as Xe,f as wt,d as qt,b as Tt,c as _t}from"../packem_shared/internal-7bgd8inO.js";import{r as $t,l as Ct}from"../packem_shared/shard-history-DU5b3QDI.js";import{c as Oe}from"react/compiler-runtime";import{f as Rt}from"../packem_shared/log-fields-SBxKyBug.js";import{B as et}from"../packem_shared/badge-cAk9Di1Q.js";import{C as he,a as ge,c as Pe,d as kt,b as Be}from"../packem_shared/card-BGlQzQY-.js";import{b as Je,e as oe,T as ct,c as de,a as dt,d as mt}from"../packem_shared/table-BMsuYFhk.js";import{S as ut}from"../packem_shared/sparkline-CYbJzfA1.js";import{jsxs as n,jsx as t,Fragment as Ye}from"react/jsx-runtime";import{aggregateMetrics as Mt,computeLatencyPercentiles as It,enrichQueryStats as Dt,shardsToAggregate as At}from"../packem_shared/aggregateMetrics-A-Y7OH6R.js";import{S as me}from"../packem_shared/stat-card-B9uIvAHg.js";import{ResponsiveContainer as st,AreaChart as Ot,CartesianGrid as lt,XAxis as at,YAxis as it,Tooltip as nt,Area as Et,LineChart as Ft,Line as Lt}from"recharts";import{E as zt}from"../packem_shared/empty-state-B939z6K2.js";import{c as Kt}from"../packem_shared/utils-bhneXptQ.js";import{S as jt,a as Pt,c as Qe,b as Bt,d as Qt}from"../packem_shared/select-BPISLTcv.js";const Ht=(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(typeof l=="number"){if(Number.isNaN(l))return"nan";if(l===1/0)return"inf";if(l===-1/0)return"-inf";if(Object.is(l,-0))return"-0"}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 a=l,s=Object.keys(a).toSorted(Ht),r=[];for(const d of s){const o=a[d];o!==void 0&&r.push(`${JSON.stringify(d)}:${Ze(o)}`)}return`{${r.join(",")}}`},ft=(l,e,a)=>`${l}:${e}:${Ze(a??{})}`,ht=(l,e)=>l==="gauge"?e.last:l==="histogram"?e.sum/Math.max(1,e.count):e.sum,Ut=(l,e)=>ht(l,e),Jt=l=>ht(l.kind,l),We=l=>Number.isInteger(l)?l.toLocaleString():l.toLocaleString(void 0,{maximumFractionDigits:2}),Vt=l=>Array.isArray(l?.series)?l.series:[],Gt="FUNCTION_NOT_FOUND",Wt=l=>{const e=new Map;if(!Array.isArray(l?.series))return e;for(const a of l.series)e.set(ft(a.kind,a.name,a.attributes),a.points);return e},Xt={counter:"secondary",gauge:"default",histogram:"outline"},Yt=l=>{const e=Oe(18),{name:a,onOpenTrace:s,traceId:r}=l,d=xe();if(r===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 o;e[1]!==r?(o=r.slice(0,8),e[1]=r,e[2]=o):o=e[2];const i=o;if(s===void 0){const m=`mt-instrument-trace-${a}`;let h;return e[3]!==i||e[4]!==m||e[5]!==r?(h=t("span",{className:"text-muted-foreground","data-testid":m,title:r,children:i}),e[3]=i,e[4]=m,e[5]=r,e[6]=h):h=e[6],h}const S=`mt-instrument-trace-${a}`;let y;e[7]!==s||e[8]!==r?(y=()=>{s(r)},e[7]=s,e[8]=r,e[9]=y):y=e[9];let w;e[10]!==d||e[11]!==r?(w=d("Open the exemplar trace {trace}",{trace:r}),e[10]=d,e[11]=r,e[12]=w):w=e[12];let f;return e[13]!==i||e[14]!==S||e[15]!==y||e[16]!==w?(f=t("button",{className:"text-primary underline-offset-4 hover:underline","data-testid":S,onClick:y,title:w,type:"button",children:i}),e[13]=i,e[14]=S,e[15]=y,e[16]=w,e[17]=f):f=e[17],f},Zt=l=>{const e=Oe(105),{onOpenTrace:a,shardKey:s}=l,r=xe();let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d={},e[0]=d):d=e[0];let o;e[1]!==s?(o={live:!0,shardKey:s},e[1]=s,e[2]=o):o=e[2];const{data:i,error:S,errorSource:y}=Ue(Fe.getMetricSeries,d,o);let w;e[3]===Symbol.for("react.memo_cache_sentinel")?(w={},e[3]=w):w=e[3];let f;e[4]!==s?(f={live:!0,shardKey:s},e[4]=s,e[5]=f):f=e[5];const{data:m}=Ue(Fe.getMetricHistory,w,f);let h,v,q,$,c,p,g,x,T,C,N,k,R;if(e[6]!==i||e[7]!==S||e[8]!==y||e[9]!==m||e[10]!==a||e[11]!==r){x=Symbol.for("react.early_return_sentinel");e:{const E=Vt(i),L=St(y)===Gt;if(S!==null&&!L){let u;e[25]!==r?(u=r("Instruments"),e[25]=r,e[26]=u):u=e[26];let K;e[27]!==u?(K=t("h3",{className:"text-sm font-semibold text-foreground",children:u}),e[27]=u,e[28]=K):K=e[28];let P;e[29]!==S||e[30]!==r?(P=r("Instruments unavailable: {error}",{error:S}),e[29]=S,e[30]=r,e[31]=P):P=e[31];let B;e[32]!==P?(B=t("span",{className:"text-xs text-muted-foreground","data-testid":"mt-instruments-error",role:"status",children:P}),e[32]=P,e[33]=B):B=e[33];let Q;e[34]!==K||e[35]!==B?(Q=n("section",{className:"flex flex-col gap-2","data-testid":"mt-instruments",children:[K,B]}),e[34]=K,e[35]=B,e[36]=Q):Q=e[36],x=Q;break e}if(E.length===0){x=null;break e}const O=Wt(m);let z;e[37]!==r?(z=u=>r(u==="counter"?"Counter":u==="gauge"?"Gauge":"Histogram"),e[37]=r,e[38]=z):z=e[38];const j=z;c="flex flex-col gap-2",p="mt-instruments";let F;e[39]!==r?(F=r("Instruments"),e[39]=r,e[40]=F):F=e[40],e[41]!==F?(g=t("h3",{className:"text-sm font-semibold text-foreground",children:F}),e[41]=F,e[42]=g):g=e[42],$=he,R="overflow-hidden py-0",q=ge,k="px-0",v=ct,C="mt-instruments-table";let U;e[43]!==r?(U=r("name"),e[43]=r,e[44]=U):U=e[44];let J;e[45]!==U?(J=t(de,{children:U}),e[45]=U,e[46]=J):J=e[46];let V;e[47]!==r?(V=r("kind"),e[47]=r,e[48]=V):V=e[48];let G;e[49]!==V?(G=t(de,{children:V}),e[49]=V,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 Z;e[57]!==Y?(Z=t(de,{className:"text-right",children:Y}),e[57]=Y,e[58]=Z):Z=e[58];let ee;e[59]!==r?(ee=r("range"),e[59]=r,e[60]=ee):ee=e[60];let te;e[61]!==ee?(te=t(de,{className:"text-right",children:ee}),e[61]=ee,e[62]=te):te=e[62];let re;e[63]!==r?(re=r("trend"),e[63]=r,e[64]=re):re=e[64];let se;e[65]!==re?(se=t(de,{children:re}),e[65]=re,e[66]=se):se=e[66];let le;e[67]!==r?(le=r("trace"),e[67]=r,e[68]=le):le=e[68];let ae;e[69]!==le?(ae=t(de,{children:le}),e[69]=le,e[70]=ae):ae=e[70];let ie;e[71]!==r?(ie=r("dimensions"),e[71]=r,e[72]=ie):ie=e[72];let ne;e[73]!==ie?(ne=t(de,{children:ie}),e[73]=ie,e[74]=ne):ne=e[74],e[75]!==J||e[76]!==G||e[77]!==X||e[78]!==Z||e[79]!==te||e[80]!==se||e[81]!==ae||e[82]!==ne?(N=t(dt,{children:n(Je,{children:[J,G,X,Z,te,se,ae,ne]})}),e[75]=J,e[76]=G,e[77]=X,e[78]=Z,e[79]=te,e[80]=se,e[81]=ae,e[82]=ne,e[83]=N):N=e[83],h=mt,T=E.map(u=>{const K=Rt(u.attributes),P=ft(u.kind,u.name,u.attributes),Q=(O.get(P)??[]).map(ue=>Ut(u.kind,ue));return n(Je,{"data-testid":`mt-instrument-${u.name}`,children:[t(oe,{className:"font-mono text-xs",title:u.functionPath,children:u.name}),t(oe,{children:t(et,{variant:Xt[u.kind],children:j(u.kind)})}),t(oe,{className:"text-right font-mono tabular-nums","data-testid":`mt-instrument-value-${u.name}`,children:We(Jt(u))}),t(oe,{className:"text-right tabular-nums text-muted-foreground",children:u.count.toLocaleString()}),t(oe,{className:"text-right font-mono text-xs tabular-nums text-muted-foreground",children:u.min===u.max?"—":`${We(u.min)}–${We(u.max)}`}),t(oe,{children:Q.length>=2?t(ut,{ariaLabel:r("{name} trend",{name:u.name}),className:"h-6 w-24 text-foreground",series:Q,testId:`mt-instrument-trend-${u.name}`}):t("span",{className:"text-xs text-muted-foreground",children:"—"})}),t(oe,{className:"font-mono text-xs",children:t(Yt,{name:u.name,onOpenTrace:a,traceId:u.exemplarTraceId})}),t(oe,{className:"max-w-64 truncate font-mono text-xs text-muted-foreground",title:K,children:K===""?"—":K})]},P)})}e[6]=i,e[7]=S,e[8]=y,e[9]=m,e[10]=a,e[11]=r,e[12]=h,e[13]=v,e[14]=q,e[15]=$,e[16]=c,e[17]=p,e[18]=g,e[19]=x,e[20]=T,e[21]=C,e[22]=N,e[23]=k,e[24]=R}else h=e[12],v=e[13],q=e[14],$=e[15],c=e[16],p=e[17],g=e[18],x=e[19],T=e[20],C=e[21],N=e[22],k=e[23],R=e[24];if(x!==Symbol.for("react.early_return_sentinel"))return x;let M;e[84]!==h||e[85]!==T?(M=t(h,{children:T}),e[84]=h,e[85]=T,e[86]=M):M=e[86];let _;e[87]!==v||e[88]!==M||e[89]!==C||e[90]!==N?(_=n(v,{"data-testid":C,children:[N,M]}),e[87]=v,e[88]=M,e[89]=C,e[90]=N,e[91]=_):_=e[91];let b;e[92]!==q||e[93]!==_||e[94]!==k?(b=t(q,{className:k,children:_}),e[92]=q,e[93]=_,e[94]=k,e[95]=b):b=e[95];let I;e[96]!==$||e[97]!==b||e[98]!==R?(I=t($,{className:R,children:b}),e[96]=$,e[97]=b,e[98]=R,e[99]=I):I=e[99];let A;return e[100]!==c||e[101]!==p||e[102]!==g||e[103]!==I?(A=n("section",{className:c,"data-testid":p,children:[g,I]}),e[100]=c,e[101]=p,e[102]=g,e[103]=I,e[104]=A):A=e[104],A},er=l=>{const e=Oe(74),{aggregate:a,shardResults:s}=l,r=xe();let d;e[0]!==r?(d=r("Shards"),e[0]=r,e[1]=d):d=e[1];let o;e[2]!==a.failed||e[3]!==a.reachable||e[4]!==r?(o=a.failed>0?r("{reachable} reachable, {failed} unreachable",{failed:a.failed,reachable:a.reachable}):r("{reachable} reachable",{reachable:a.reachable}),e[2]=a.failed,e[3]=a.reachable,e[4]=r,e[5]=o):o=e[5];let i;e[6]!==d||e[7]!==o?(i=t(me,{label:d,testId:"mt-agg-shards",value:o}),e[6]=d,e[7]=o,e[8]=i):i=e[8];let S;e[9]!==r?(S=r("Total requests"),e[9]=r,e[10]=S):S=e[10];let y;e[11]!==a.totalRequests||e[12]!==S?(y=t(me,{label:S,testId:"mt-agg-requests",value:a.totalRequests}),e[11]=a.totalRequests,e[12]=S,e[13]=y):y=e[13];let w;e[14]!==r?(w=r("Total errors"),e[14]=r,e[15]=w):w=e[15];let f;e[16]!==a.totalErrors||e[17]!==w?(f=t(me,{label:w,testId:"mt-agg-errors",value:a.totalErrors}),e[16]=a.totalErrors,e[17]=w,e[18]=f):f=e[18];let m;e[19]!==r?(m=r("Total database size"),e[19]=r,e[20]=m):m=e[20];let h;e[21]!==a.totalDatabaseSize?(h=Xe(a.totalDatabaseSize),e[21]=a.totalDatabaseSize,e[22]=h):h=e[22];let v;e[23]!==m||e[24]!==h?(v=t(me,{label:m,testId:"mt-agg-db-size",value:h}),e[23]=m,e[24]=h,e[25]=v):v=e[25];let q;e[26]!==r?(q=r("Combined cache hit rate"),e[26]=r,e[27]=q):q=e[27];let $;e[28]!==a.hitRate||e[29]!==r?($=a.hitRate===null?r("no cache configured"):`${(a.hitRate*100).toFixed(1)}%`,e[28]=a.hitRate,e[29]=r,e[30]=$):$=e[30];let c;e[31]!==q||e[32]!==$?(c=t(me,{label:q,testId:"mt-agg-cache",value:$}),e[31]=q,e[32]=$,e[33]=c):c=e[33];let p;e[34]!==v||e[35]!==c||e[36]!==i||e[37]!==y||e[38]!==f?(p=n("dl",{className:"grid gap-3 sm:grid-cols-2 lg:grid-cols-3","data-testid":"mt-aggregate-stats",children:[i,y,f,v,c]}),e[34]=v,e[35]=c,e[36]=i,e[37]=y,e[38]=f,e[39]=p):p=e[39];let g;e[40]!==r?(g=r("shard"),e[40]=r,e[41]=g):g=e[41];let x;e[42]!==g?(x=t(de,{children:g}),e[42]=g,e[43]=x):x=e[43];let T;e[44]!==r?(T=r("requests"),e[44]=r,e[45]=T):T=e[45];let C;e[46]!==T?(C=t(de,{children:T}),e[46]=T,e[47]=C):C=e[47];let N;e[48]!==r?(N=r("errors"),e[48]=r,e[49]=N):N=e[49];let k;e[50]!==N?(k=t(de,{children:N}),e[50]=N,e[51]=k):k=e[51];let R;e[52]!==r?(R=r("db size"),e[52]=r,e[53]=R):R=e[53];let M;e[54]!==R?(M=t(de,{children:R}),e[54]=R,e[55]=M):M=e[55];let _;e[56]!==x||e[57]!==C||e[58]!==k||e[59]!==M?(_=t(dt,{children:n(Je,{children:[x,C,k,M]})}),e[56]=x,e[57]=C,e[58]=k,e[59]=M,e[60]=_):_=e[60];let b;if(e[61]!==s||e[62]!==r){let L;e[64]!==r?(L=O=>n(Je,{"data-testid":`mt-agg-row-${O.shard}`,children:[t(oe,{children:O.shard}),O.metrics===null?t(oe,{className:"text-destructive",colSpan:3,children:O.error??r("unreachable")}):n(Ye,{children:[t(oe,{className:"tabular-nums",children:O.metrics.requests}),t(oe,{className:"tabular-nums",children:O.metrics.errors}),t(oe,{className:"tabular-nums",children:Xe(O.metrics.databaseSize)})]})]},O.shard),e[64]=r,e[65]=L):L=e[65],b=s.map(L),e[61]=s,e[62]=r,e[63]=b}else b=e[63];let I;e[66]!==b?(I=t(mt,{children:b}),e[66]=b,e[67]=I):I=e[67];let A;e[68]!==_||e[69]!==I?(A=t(he,{className:"overflow-hidden py-0",children:t(ge,{className:"px-0",children:n(ct,{"data-testid":"mt-agg-table",children:[_,I]})})}),e[68]=_,e[69]=I,e[70]=A):A=e[70];let E;return e[71]!==p||e[72]!==A?(E=n("div",{className:"flex flex-col gap-4","data-testid":"mt-aggregate-view",children:[p,A]}),e[71]=p,e[72]=A,e[73]=E):E=e[73],E},tr=l=>{const e=Math.floor(l/1e3),a=Math.floor(e/3600),s=Math.floor(e%3600/60),r=e%60;return a>0?`${a.toString()}h ${s.toString()}m`:s>0?`${s.toString()}m ${r.toString()}s`:`${r.toString()}s`},rr=(l,e)=>{const a=l+e;return a===0?"—":`${(l/a*100).toFixed(1)}%`},ot=l=>l<=0?"—":l<1?`${(l*1e3).toFixed(0)}μs`:l<1e3?`${l.toFixed(1)}ms`:`${(l/1e3).toFixed(2)}s`,sr=l=>{const e=Oe(75),{currentDelta:a,errorRate:s,history:r,latencyPercentiles:d,metrics:o}=l,i=xe();let S;e[0]!==r||e[1]!==i?(S=r.length>=2?t(ut,{ariaLabel:i("Requests per interval over time"),className:"h-7 w-24 text-foreground",series:r,testId:"mt-sparkline"}):void 0,e[0]=r,e[1]=i,e[2]=S):S=e[2];let y;e[3]!==a||e[4]!==r.length||e[5]!==i?(y=r.length>=2?n(Ye,{children:[t("span",{className:"font-semibold text-foreground",children:`+${a.toLocaleString()}`})," ",i("last interval")]}):t("span",{"data-testid":"mt-sparkline-empty",children:i("collecting samples…")}),e[3]=a,e[4]=r.length,e[5]=i,e[6]=y):y=e[6];let w;e[7]!==i?(w=i("Requests"),e[7]=i,e[8]=w):w=e[8];let f;e[9]!==o.requests||e[10]!==S||e[11]!==y||e[12]!==w?(f=t(me,{chart:S,footer:y,label:w,testId:"mt-requests",value:o.requests}),e[9]=o.requests,e[10]=S,e[11]=y,e[12]=w,e[13]=f):f=e[13];let m;e[14]!==s||e[15]!==i?(m=i("{rate} error rate",{rate:s}),e[14]=s,e[15]=i,e[16]=m):m=e[16];let h;e[17]!==i?(h=i("Errors"),e[17]=i,e[18]=h):h=e[18];let v;e[19]!==s||e[20]!==o.errors?(v=n(Ye,{children:[o.errors," (",s,")"]}),e[19]=s,e[20]=o.errors,e[21]=v):v=e[21];let q;e[22]!==m||e[23]!==h||e[24]!==v?(q=t(me,{footer:m,label:h,testId:"mt-errors",value:v}),e[22]=m,e[23]=h,e[24]=v,e[25]=q):q=e[25];let $;e[26]!==d.p90?($=d.p90>0?`P90 ${ot(d.p90)}`:void 0,e[26]=d.p90,e[27]=$):$=e[27];let c;e[28]!==i?(c=i("P95 latency"),e[28]=i,e[29]=c):c=e[29];let p;e[30]!==d.p95?(p=d.p95>0?ot(d.p95):"—",e[30]=d.p95,e[31]=p):p=e[31];let g;e[32]!==c||e[33]!==p||e[34]!==$?(g=t(me,{footer:$,label:c,testId:"mt-p95",value:p}),e[32]=c,e[33]=p,e[34]=$,e[35]=g):g=e[35];let x;e[36]!==o.cache||e[37]!==i?(x=o.cache===null?void 0:`${o.cache.entries.toLocaleString()} ${i("cache entries")}`,e[36]=o.cache,e[37]=i,e[38]=x):x=e[38];let T;e[39]!==i?(T=i("Database size"),e[39]=i,e[40]=T):T=e[40];let C;e[41]!==o.databaseSize?(C=Xe(o.databaseSize),e[41]=o.databaseSize,e[42]=C):C=e[42];let N;e[43]!==x||e[44]!==T||e[45]!==C?(N=t(me,{footer:x,label:T,testId:"mt-db-size",value:C}),e[43]=x,e[44]=T,e[45]=C,e[46]=N):N=e[46];let k;e[47]!==i?(k=i("Shard"),e[47]=i,e[48]=k):k=e[48];let R;e[49]!==o.shard||e[50]!==k?(R=t(me,{label:k,testId:"mt-shard",value:o.shard}),e[49]=o.shard,e[50]=k,e[51]=R):R=e[51];let M;e[52]!==i?(M=i("Uptime"),e[52]=i,e[53]=M):M=e[53];let _;e[54]!==o.uptimeMs?(_=tr(o.uptimeMs),e[54]=o.uptimeMs,e[55]=_):_=e[55];let b;e[56]!==M||e[57]!==_?(b=t(me,{label:M,testId:"mt-uptime",value:_}),e[56]=M,e[57]=_,e[58]=b):b=e[58];let I;e[59]!==i?(I=i("Cache hit rate"),e[59]=i,e[60]=I):I=e[60];let A;e[61]!==o.cache||e[62]!==i?(A=o.cache===null?i("no cache configured"):i("{rate} ({count} entries)",{count:o.cache.entries,rate:rr(o.cache.hits,o.cache.misses)}),e[61]=o.cache,e[62]=i,e[63]=A):A=e[63];let E;e[64]!==I||e[65]!==A?(E=t(me,{label:I,testId:"mt-cache",value:A}),e[64]=I,e[65]=A,e[66]=E):E=e[66];let L;return e[67]!==g||e[68]!==N||e[69]!==R||e[70]!==b||e[71]!==E||e[72]!==f||e[73]!==q?(L=n("dl",{className:"grid gap-3 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4","data-testid":"mt-stats",children:[f,q,g,N,R,b,E]}),e[67]=g,e[68]=N,e[69]=R,e[70]=b,e[71]=E,e[72]=f,e[73]=q,e[74]=L):L=e[74],L},Ve=l=>l>=100?"critical":l>=50?"warning":"good",Ee=l=>l<1?`${(l*1e3).toFixed(0)}μs`:l<1e3?`${l.toFixed(1)}ms`:`${(l/1e3).toFixed(2)}s`,He=l=>l>=1e9?`${(l/1e9).toFixed(1)}B`:l>=1e6?`${(l/1e6).toFixed(1)}M`:l>=1e3?`${(l/1e3).toFixed(1)}K`:l.toLocaleString(),lr=l=>{const e=Oe(3),{level:a}=l;if(a==="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(a==="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 s;return e[2]===Symbol.for("react.memo_cache_sentinel")?(s=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]=s):s=e[2],s},ar=(l,e)=>{const a=[...l];return a.sort((s,r)=>{switch(e){case"avgTime":return r.avgDurationMs-s.avgDurationMs;case"execCount":return r.execCount-s.execCount;case"rowsRead":return r.rowsRead-s.rowsRead;default:return r.totalDurationMs-s.totalDurationMs}}),a},ir=l=>{const e=Oe(161),{queryStats:a}=l,s=xe(),[r,d]=pe("totalTime");let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o=new Set,e[0]=o):o=e[0];const[i,S]=pe(o);let y;e[1]===Symbol.for("react.memo_cache_sentinel")?(y=R=>{R!==null&&d(R)},e[1]=y):y=e[1];const w=y;let f,m,h,v,q,$,c,p,g,x;if(e[2]!==i||e[3]!==a||e[4]!==r||e[5]!==s){h=Symbol.for("react.early_return_sentinel");e:{const R=ar(a,r);let M;e[16]!==a?(M=a.filter(nr),e[16]=a,e[17]=M):M=e[17];const _=M.length;let b;e[18]!==a?(b=a.filter(or),e[18]=a,e[19]=b):b=e[19];const I=b.length;let A;e[20]!==a?(A=a.filter(cr),e[20]=a,e[21]=A):A=e[21];const E=A.length;let L;e[22]===Symbol.for("react.memo_cache_sentinel")?(L=D=>{S(ce=>{const H=new Set(ce);return H.has(D)?H.delete(D):H.add(D),H})},e[22]=L):L=e[22];const O=L;if(a.length===0){let D;e[23]!==s?(D=s("No query insights yet"),e[23]=s,e[24]=D):D=e[24];let ce;e[25]!==D?(ce=t("p",{className:"text-lg font-medium","data-testid":"qi-empty",children:D}),e[25]=D,e[26]=ce):ce=e[26];let H;e[27]!==s?(H=s("Query insights appear once statements are executed against this shard."),e[27]=s,e[28]=H):H=e[28];let fe;e[29]!==H?(fe=t("p",{className:"mt-1 text-sm",children:H}),e[29]=H,e[30]=fe):fe=e[30];let je;e[31]!==ce||e[32]!==fe?(je=t(he,{children:t(ge,{className:"py-12",children:n("div",{className:"text-center text-muted-foreground",children:[ce,fe]})})}),e[31]=ce,e[32]=fe,e[33]=je):je=e[33],h=je;break e}c="space-y-4",p="qi-root";let z;e[34]!==s?(z=s("Critical queries"),e[34]=s,e[35]=z):z=e[35];let j;e[36]!==z?(j=t(Pe,{className:"pb-2",children:t(Be,{className:"text-sm font-medium",children:z})}),e[36]=z,e[37]=j):j=e[37];let F;e[38]!==_?(F=t("div",{className:"text-2xl font-bold text-destructive","data-testid":"qi-critical",children:_}),e[38]=_,e[39]=F):F=e[39];let U;e[40]!==s?(U=s(">100ms avg execution"),e[40]=s,e[41]=U):U=e[41];let J;e[42]!==U?(J=t("p",{className:"text-xs text-muted-foreground",children:U}),e[42]=U,e[43]=J):J=e[43];let V;e[44]!==F||e[45]!==J?(V=n(ge,{children:[F,J]}),e[44]=F,e[45]=J,e[46]=V):V=e[46];let G;e[47]!==j||e[48]!==V?(G=n(he,{children:[j,V]}),e[47]=j,e[48]=V,e[49]=G):G=e[49];let W;e[50]!==s?(W=s("Moderate queries"),e[50]=s,e[51]=W):W=e[51];let X;e[52]!==W?(X=t(Pe,{className:"pb-2",children:t(Be,{className:"text-sm font-medium",children:W})}),e[52]=W,e[53]=X):X=e[53];let Y;e[54]!==I?(Y=t("div",{className:"text-2xl font-bold text-warning","data-testid":"qi-moderate",children:I}),e[54]=I,e[55]=Y):Y=e[55];let Z;e[56]!==s?(Z=s("50–100ms avg execution"),e[56]=s,e[57]=Z):Z=e[57];let ee;e[58]!==Z?(ee=t("p",{className:"text-xs text-muted-foreground",children:Z}),e[58]=Z,e[59]=ee):ee=e[59];let te;e[60]!==Y||e[61]!==ee?(te=n(ge,{children:[Y,ee]}),e[60]=Y,e[61]=ee,e[62]=te):te=e[62];let re;e[63]!==X||e[64]!==te?(re=n(he,{children:[X,te]}),e[63]=X,e[64]=te,e[65]=re):re=e[65];let se;e[66]!==s?(se=s("Fast queries"),e[66]=s,e[67]=se):se=e[67];let le;e[68]!==se?(le=t(Pe,{className:"pb-2",children:t(Be,{className:"text-sm font-medium",children:se})}),e[68]=se,e[69]=le):le=e[69];let ae;e[70]!==E?(ae=t("div",{className:"text-2xl font-bold text-success","data-testid":"qi-fast",children:E}),e[70]=E,e[71]=ae):ae=e[71];let ie;e[72]!==s?(ie=s("<50ms avg execution"),e[72]=s,e[73]=ie):ie=e[73];let ne;e[74]!==ie?(ne=t("p",{className:"text-xs text-muted-foreground",children:ie}),e[74]=ie,e[75]=ne):ne=e[75];let u;e[76]!==ae||e[77]!==ne?(u=n(ge,{children:[ae,ne]}),e[76]=ae,e[77]=ne,e[78]=u):u=e[78];let K;e[79]!==le||e[80]!==u?(K=n(he,{children:[le,u]}),e[79]=le,e[80]=u,e[81]=K):K=e[81],e[82]!==G||e[83]!==re||e[84]!==K?(g=n("div",{className:"grid gap-4 md:grid-cols-3",children:[G,re,K]}),e[82]=G,e[83]=re,e[84]=K,e[85]=g):g=e[85];let P;e[86]!==s?(P=s("Query leaderboard"),e[86]=s,e[87]=P):P=e[87];let B;e[88]!==P?(B=t("h3",{className:"text-lg font-semibold",children:P}),e[88]=P,e[89]=B):B=e[89];let Q;e[90]!==r||e[91]!==s?(Q=s("Slow queries sorted by {sortField}",{sortField:s(r)}),e[90]=r,e[91]=s,e[92]=Q):Q=e[92];let ue;e[93]!==Q?(ue=t("p",{className:"text-sm text-muted-foreground",children:Q}),e[93]=Q,e[94]=ue):ue=e[94];let be;e[95]!==B||e[96]!==ue?(be=n("div",{children:[B,ue]}),e[95]=B,e[96]=ue,e[97]=be):be=e[97];let ye;e[98]!==s?(ye=s("Sort by"),e[98]=s,e[99]=ye):ye=e[99];let ve;e[100]!==ye?(ve=t("span",{className:"text-sm text-muted-foreground",children:ye}),e[100]=ye,e[101]=ve):ve=e[101];let Ne;e[102]!==s?(Ne=s("Sort queries by"),e[102]=s,e[103]=Ne):Ne=e[103];let Le;e[104]===Symbol.for("react.memo_cache_sentinel")?(Le=t(jt,{}),e[104]=Le):Le=e[104];let Se;e[105]!==Ne?(Se=t(Pt,{"aria-label":Ne,className:"w-[140px]","data-testid":"qi-sort",children:Le}),e[105]=Ne,e[106]=Se):Se=e[106];let we;e[107]!==s?(we=s("Total time"),e[107]=s,e[108]=we):we=e[108];let qe;e[109]!==we?(qe=t(Qe,{value:"totalTime",children:we}),e[109]=we,e[110]=qe):qe=e[110];let Te;e[111]!==s?(Te=s("Avg time"),e[111]=s,e[112]=Te):Te=e[112];let _e;e[113]!==Te?(_e=t(Qe,{value:"avgTime",children:Te}),e[113]=Te,e[114]=_e):_e=e[114];let $e;e[115]!==s?($e=s("Execution count"),e[115]=s,e[116]=$e):$e=e[116];let Ce;e[117]!==$e?(Ce=t(Qe,{value:"execCount",children:$e}),e[117]=$e,e[118]=Ce):Ce=e[118];let Re;e[119]!==s?(Re=s("Rows read"),e[119]=s,e[120]=Re):Re=e[120];let ke;e[121]!==Re?(ke=t(Qe,{value:"rowsRead",children:Re}),e[121]=Re,e[122]=ke):ke=e[122];let Me;e[123]!==qe||e[124]!==_e||e[125]!==Ce||e[126]!==ke?(Me=n(Bt,{children:[qe,_e,Ce,ke]}),e[123]=qe,e[124]=_e,e[125]=Ce,e[126]=ke,e[127]=Me):Me=e[127];let Ie;e[128]!==r||e[129]!==Se||e[130]!==Me?(Ie=n(Qt,{onValueChange:w,value:r,children:[Se,Me]}),e[128]=r,e[129]=Se,e[130]=Me,e[131]=Ie):Ie=e[131];let De;e[132]!==ve||e[133]!==Ie?(De=n("div",{className:"flex items-center gap-2",children:[ve,Ie]}),e[132]=ve,e[133]=Ie,e[134]=De):De=e[134],e[135]!==be||e[136]!==De?(x=n("div",{className:"flex items-center justify-between",children:[be,De]}),e[135]=be,e[136]=De,e[137]=x):x=e[137],m=he;let Ae;e[138]!==s?(Ae=s("Statements"),e[138]=s,e[139]=Ae):Ae=e[139];let ze;e[140]!==Ae?(ze=t(Be,{children:Ae}),e[140]=Ae,e[141]=ze):ze=e[141],$=n(Pe,{children:[ze,t(kt,{children:s("{count} tracked statements",{count:R.length})})]}),f=ge,v="space-y-2";let Ke;e[142]!==i||e[143]!==s?(Ke=D=>{const ce=D.normalizedSql,H=i.has(ce),fe=Ve(D.avgDurationMs);return n("div",{className:"overflow-hidden rounded-lg border","data-testid":"qi-row",children:[n("button",{"aria-expanded":H,className:"flex w-full items-center justify-between p-3 text-left transition-colors hover:bg-muted/50",onClick:()=>{O(ce)},type:"button",children:[n("div",{className:"flex min-w-0 flex-1 items-center gap-3",children:[t(lr,{level:fe}),t("span",{className:"max-w-[300px] truncate font-mono text-sm lg:max-w-[500px]",children:D.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:Ee(D.totalDurationMs)}),t("div",{className:"text-xs text-muted-foreground",children:s("total")})]}),n("div",{className:"text-right",children:[t("div",{className:"text-sm font-medium",children:Ee(D.avgDurationMs)}),t("div",{className:"text-xs text-muted-foreground",children:s("avg")})]}),D.p95DurationMs!==void 0&&n("div",{className:"text-right",children:[t("div",{className:"text-sm font-medium",children:Ee(D.p95DurationMs)}),t("div",{className:"text-xs text-muted-foreground",children:s("p95")})]}),n("div",{className:"text-right",children:[t("div",{className:"text-sm font-medium",children:He(D.execCount)}),t("div",{className:"text-xs text-muted-foreground",children:s("calls")})]})]})]}),H&&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:s("Full statement")}),t("pre",{className:"overflow-x-auto rounded-md bg-muted p-3 font-mono text-sm whitespace-pre-wrap break-all",children:D.normalizedSql})]}),n("div",{className:"grid grid-cols-2 gap-4 text-sm md:grid-cols-4",children:[D.p50DurationMs!==void 0&&n("div",{children:[t("span",{className:"text-muted-foreground",children:s("p50")}),t("span",{className:"block font-medium tabular-nums",children:Ee(D.p50DurationMs)})]}),n("div",{children:[t("span",{className:"text-muted-foreground",children:s("Exec count")}),t("span",{className:"block font-medium tabular-nums",children:He(D.execCount)})]}),n("div",{children:[t("span",{className:"text-muted-foreground",children:s("Total time")}),t("span",{className:"block font-medium tabular-nums",children:Ee(D.totalDurationMs)})]}),n("div",{children:[t("span",{className:"text-muted-foreground",children:s("Rows read")}),t("span",{className:"block font-medium tabular-nums",children:He(D.rowsRead)})]}),n("div",{children:[t("span",{className:"text-muted-foreground",children:s("Rows written")}),t("span",{className:"block font-medium tabular-nums",children:He(D.rowsWritten)})]})]})]})]},ce)},e[142]=i,e[143]=s,e[144]=Ke):Ke=e[144],q=R.map(Ke)}e[2]=i,e[3]=a,e[4]=r,e[5]=s,e[6]=f,e[7]=m,e[8]=h,e[9]=v,e[10]=q,e[11]=$,e[12]=c,e[13]=p,e[14]=g,e[15]=x}else f=e[6],m=e[7],h=e[8],v=e[9],q=e[10],$=e[11],c=e[12],p=e[13],g=e[14],x=e[15];if(h!==Symbol.for("react.early_return_sentinel"))return h;let T;e[145]!==v||e[146]!==q?(T=t("div",{className:v,children:q}),e[145]=v,e[146]=q,e[147]=T):T=e[147];let C;e[148]!==f||e[149]!==T?(C=t(f,{children:T}),e[148]=f,e[149]=T,e[150]=C):C=e[150];let N;e[151]!==m||e[152]!==C||e[153]!==$?(N=n(m,{children:[$,C]}),e[151]=m,e[152]=C,e[153]=$,e[154]=N):N=e[154];let k;return e[155]!==N||e[156]!==c||e[157]!==p||e[158]!==g||e[159]!==x?(k=n("div",{className:c,"data-testid":p,children:[g,x,N]}),e[155]=N,e[156]=c,e[157]=p,e[158]=g,e[159]=x,e[160]=k):k=e[160],k};function nr(l){return Ve(l.avgDurationMs)==="critical"}function or(l){return Ve(l.avgDurationMs)==="warning"}function cr(l){return Ve(l.avgDurationMs)==="good"}const dr=["1m","5m","15m","1h"],mr=l=>new Date(l).toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"}),ur=l=>l.map(e=>({avg:Math.round(e.avgDurationMs*100)/100,execs:e.execCount,label:mr(e.bucketMs)})),fr=({shardKey:l=""})=>{const e=xe(),[a,s]=pe("15m"),d=Ue(Fe.getQueryInsights,{range:a},{live:!0,shardKey:l}).data,o=ur(d?.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:dr.map(i=>t("button",{"aria-pressed":i===a,className:Kt("rounded px-2 py-1 text-xs outline-none transition-colors hover:bg-accent focus-visible:bg-accent",i===a&&"bg-accent font-medium text-foreground"),"data-testid":`qi-range-${i}`,onClick:()=>{s(i)},type:"button",children:i},i))}),d?.capped===!0&&t(et,{"data-testid":"qi-capped",variant:"secondary",children:e("showing a capped set")})]}),o.length===0?t(zt,{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(Ot,{data:o,children:[t(lt,{strokeDasharray:"3 3",vertical:!1}),t(at,{dataKey:"label",fontSize:10,tickLine:!1}),t(it,{allowDecimals:!1,fontSize:10,tickLine:!1,width:32}),t(nt,{}),t(Et,{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(Ft,{data:o,children:[t(lt,{strokeDasharray:"3 3",vertical:!1}),t(at,{dataKey:"label",fontSize:10,tickLine:!1}),t(it,{fontSize:10,tickLine:!1,width:32}),t(nt,{}),t(Lt,{dataKey:"avg",dot:!1,stroke:"var(--color-destructive)",type:"monotone"})]})})]})]}),t(ir,{queryStats:d?.entries??[]})]})},hr=_t(Fe.getMetrics),gr=(l,e)=>l?e:"overview",Pr=({initialShardKey:l})=>{const e=gt(),a=xe(),{queryShardKey:s,setShardKey:r,shardKey:d}=vt(l),[o,i]=pe("overview"),[S,y]=pe([]),w=Ge(null),f=Ge(null),m=Ge(!0);tt(()=>(m.current=!0,()=>{m.current=!1}),[]);const h=yt(s),{data:v,error:q,liveError:$}=Ue(Fe.getMetrics,{},{live:!0,shardKey:s}),c=v??null;tt(()=>{if(v===void 0)return;$t(s);const O=v,z=w.current,j=f.current!==null&&f.current!==O.shard;if(f.current=O.shard,w.current=O.requests,j){y([]);return}z!==null&&O.requests>=z&&y(F=>[...F,O.requests-z].slice(-30))},[v,s]);const[p,g]=pe(null),[x,T]=pe(!1),C=async()=>{T(!0);const O=At(d,Ct());try{const z=await Promise.all(O.map(async j=>{try{const F=await e.query(hr,{},qt(j));return{error:null,metrics:F,shard:j===""?F.shard:j}}catch(F){return{error:Tt(F),metrics:null,shard:j===""?"__root__":j}}}));m.current&&g(z)}finally{m.current&&T(!1)}},N=p===null?null:Mt(p),k=c===null||c.requests===0?"—":`${(c.errors/c.requests*100).toFixed(1)}%`,R=S.length>0?S.at(-1):0,M=c?It(c):{p90:0,p95:0},_=pt(()=>{if(!c||!("queryStats"in c))return;const O=c.queryStats;if(!(!O||!Array.isArray(O)))return Dt(O)},[c]),b=gr(_!==void 0,o),I=()=>{wt(C())},A=()=>{g(null)},E=()=>{i("overview")},L=()=>{i("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(bt,{onChange:r,testId:"mt-shard-input",value:d}),t(xt,{message:$,prefix:"mt"}),t(rt,{"data-testid":"mt-aggregate",disabled:x,onClick:I,size:"sm",type:"button",variant:"secondary",children:a(x?"Aggregating…":"All shards")}),p!==null&&t(rt,{"data-testid":"mt-aggregate-clear",onClick:A,size:"sm",type:"button",variant:"ghost",children:a("Hide")}),t("a",{className:"text-sm text-primary underline-offset-4 hover:underline","data-testid":"mt-cf-link",href:Nt,rel:"noreferrer",target:"_blank",children:a("Open in Cloudflare")})]}),q!==null&&t("p",{className:"text-sm text-destructive","data-testid":"mt-error",role:"alert",children:q}),_!==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 ${b==="overview"?"border-b-2 border-primary text-foreground":"text-muted-foreground hover:text-foreground"}`,"data-testid":"mt-tab-overview",onClick:E,type:"button",children:a("Overview")}),n("button",{className:`pb-2 text-sm font-medium transition-colors ${b==="query-insights"?"border-b-2 border-primary text-foreground":"text-muted-foreground hover:text-foreground"}`,"data-testid":"mt-tab-query-insights",onClick:L,type:"button",children:[a("Query insights"),_.length>0&&t("span",{className:"ml-1.5 rounded-full bg-primary/10 px-1.5 py-0.5 text-xs text-primary",children:_.length})]})]}),b==="query-insights"&&_!==void 0&&t(fr,{shardKey:s}),b==="overview"&&c!==null&&t(sr,{currentDelta:R,errorRate:k,history:S,latencyPercentiles:M,metrics:c}),b==="overview"&&c===null&&null,b==="overview"&&t(Zt,{onOpenTrace:h,shardKey:s}),b==="overview"&&N!==null&&p!==null&&t(er,{aggregate:N,shardResults:p})]})};export{Pr as MetricsPanel};
1
+ import{useLunora as gt}from"@lunora/react";import{useState as pe,useRef as Ge,useEffect as tt,useMemo as pt}from"react";import{L as xt}from"../packem_shared/live-status-Bf7rR8o8.js";import{ShardInput as bt}from"../packem_shared/ShardInput-CdawpUiS.js";import{B as rt}from"../packem_shared/button-BOPLD1un.js";import{u as Ue}from"../packem_shared/use-admin-query-P0RJrjsD.js";import{u as yt}from"../packem_shared/use-open-trace-4mqqFWrn.js";import{u as vt}from"../packem_shared/use-shard-key-BsP3o5wT.js";import{useT as xe}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.js";import{ADMIN_FUNCTIONS as Fe}from"../packem_shared/ADMIN_FUNCTIONS-B6z7VLYt.js";import{c as Nt}from"../packem_shared/cf-links-CBJ5SywP.js";import{m as St,l as Xe,f as wt,d as qt,b as Tt,c as _t}from"../packem_shared/internal-CwaF9YNk.js";import{r as $t,l as Ct}from"../packem_shared/shard-history-DU5b3QDI.js";import{c as Oe}from"react/compiler-runtime";import{f as Rt}from"../packem_shared/log-fields-SBxKyBug.js";import{B as et}from"../packem_shared/badge-cAk9Di1Q.js";import{C as he,a as ge,c as Pe,d as kt,b as Be}from"../packem_shared/card-BGlQzQY-.js";import{b as Je,e as oe,T as ct,c as de,a as dt,d as mt}from"../packem_shared/table-BMsuYFhk.js";import{S as ut}from"../packem_shared/sparkline-CYbJzfA1.js";import{jsxs as n,jsx as t,Fragment as Ye}from"react/jsx-runtime";import{aggregateMetrics as Mt,computeLatencyPercentiles as It,enrichQueryStats as Dt,shardsToAggregate as At}from"../packem_shared/aggregateMetrics-A-Y7OH6R.js";import{S as me}from"../packem_shared/stat-card-B9uIvAHg.js";import{ResponsiveContainer as st,AreaChart as Ot,CartesianGrid as lt,XAxis as at,YAxis as it,Tooltip as nt,Area as Et,LineChart as Ft,Line as Lt}from"recharts";import{E as zt}from"../packem_shared/empty-state-B939z6K2.js";import{c as Kt}from"../packem_shared/utils-bhneXptQ.js";import{S as jt,a as Pt,c as Qe,b as Bt,d as Qt}from"../packem_shared/select-BPISLTcv.js";const Ht=(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(typeof l=="number"){if(Number.isNaN(l))return"nan";if(l===1/0)return"inf";if(l===-1/0)return"-inf";if(Object.is(l,-0))return"-0"}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 a=l,s=Object.keys(a).toSorted(Ht),r=[];for(const d of s){const o=a[d];o!==void 0&&r.push(`${JSON.stringify(d)}:${Ze(o)}`)}return`{${r.join(",")}}`},ft=(l,e,a)=>`${l}:${e}:${Ze(a??{})}`,ht=(l,e)=>l==="gauge"?e.last:l==="histogram"?e.sum/Math.max(1,e.count):e.sum,Ut=(l,e)=>ht(l,e),Jt=l=>ht(l.kind,l),We=l=>Number.isInteger(l)?l.toLocaleString():l.toLocaleString(void 0,{maximumFractionDigits:2}),Vt=l=>Array.isArray(l?.series)?l.series:[],Gt="FUNCTION_NOT_FOUND",Wt=l=>{const e=new Map;if(!Array.isArray(l?.series))return e;for(const a of l.series)e.set(ft(a.kind,a.name,a.attributes),a.points);return e},Xt={counter:"secondary",gauge:"default",histogram:"outline"},Yt=l=>{const e=Oe(18),{name:a,onOpenTrace:s,traceId:r}=l,d=xe();if(r===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 o;e[1]!==r?(o=r.slice(0,8),e[1]=r,e[2]=o):o=e[2];const i=o;if(s===void 0){const m=`mt-instrument-trace-${a}`;let h;return e[3]!==i||e[4]!==m||e[5]!==r?(h=t("span",{className:"text-muted-foreground","data-testid":m,title:r,children:i}),e[3]=i,e[4]=m,e[5]=r,e[6]=h):h=e[6],h}const S=`mt-instrument-trace-${a}`;let y;e[7]!==s||e[8]!==r?(y=()=>{s(r)},e[7]=s,e[8]=r,e[9]=y):y=e[9];let w;e[10]!==d||e[11]!==r?(w=d("Open the exemplar trace {trace}",{trace:r}),e[10]=d,e[11]=r,e[12]=w):w=e[12];let f;return e[13]!==i||e[14]!==S||e[15]!==y||e[16]!==w?(f=t("button",{className:"text-primary underline-offset-4 hover:underline","data-testid":S,onClick:y,title:w,type:"button",children:i}),e[13]=i,e[14]=S,e[15]=y,e[16]=w,e[17]=f):f=e[17],f},Zt=l=>{const e=Oe(105),{onOpenTrace:a,shardKey:s}=l,r=xe();let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d={},e[0]=d):d=e[0];let o;e[1]!==s?(o={live:!0,shardKey:s},e[1]=s,e[2]=o):o=e[2];const{data:i,error:S,errorSource:y}=Ue(Fe.getMetricSeries,d,o);let w;e[3]===Symbol.for("react.memo_cache_sentinel")?(w={},e[3]=w):w=e[3];let f;e[4]!==s?(f={live:!0,shardKey:s},e[4]=s,e[5]=f):f=e[5];const{data:m}=Ue(Fe.getMetricHistory,w,f);let h,v,q,$,c,p,g,x,T,C,N,k,R;if(e[6]!==i||e[7]!==S||e[8]!==y||e[9]!==m||e[10]!==a||e[11]!==r){x=Symbol.for("react.early_return_sentinel");e:{const E=Vt(i),L=St(y)===Gt;if(S!==null&&!L){let u;e[25]!==r?(u=r("Instruments"),e[25]=r,e[26]=u):u=e[26];let K;e[27]!==u?(K=t("h3",{className:"text-sm font-semibold text-foreground",children:u}),e[27]=u,e[28]=K):K=e[28];let P;e[29]!==S||e[30]!==r?(P=r("Instruments unavailable: {error}",{error:S}),e[29]=S,e[30]=r,e[31]=P):P=e[31];let B;e[32]!==P?(B=t("span",{className:"text-xs text-muted-foreground","data-testid":"mt-instruments-error",role:"status",children:P}),e[32]=P,e[33]=B):B=e[33];let Q;e[34]!==K||e[35]!==B?(Q=n("section",{className:"flex flex-col gap-2","data-testid":"mt-instruments",children:[K,B]}),e[34]=K,e[35]=B,e[36]=Q):Q=e[36],x=Q;break e}if(E.length===0){x=null;break e}const O=Wt(m);let z;e[37]!==r?(z=u=>r(u==="counter"?"Counter":u==="gauge"?"Gauge":"Histogram"),e[37]=r,e[38]=z):z=e[38];const j=z;c="flex flex-col gap-2",p="mt-instruments";let F;e[39]!==r?(F=r("Instruments"),e[39]=r,e[40]=F):F=e[40],e[41]!==F?(g=t("h3",{className:"text-sm font-semibold text-foreground",children:F}),e[41]=F,e[42]=g):g=e[42],$=he,R="overflow-hidden py-0",q=ge,k="px-0",v=ct,C="mt-instruments-table";let U;e[43]!==r?(U=r("name"),e[43]=r,e[44]=U):U=e[44];let J;e[45]!==U?(J=t(de,{children:U}),e[45]=U,e[46]=J):J=e[46];let V;e[47]!==r?(V=r("kind"),e[47]=r,e[48]=V):V=e[48];let G;e[49]!==V?(G=t(de,{children:V}),e[49]=V,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 Z;e[57]!==Y?(Z=t(de,{className:"text-right",children:Y}),e[57]=Y,e[58]=Z):Z=e[58];let ee;e[59]!==r?(ee=r("range"),e[59]=r,e[60]=ee):ee=e[60];let te;e[61]!==ee?(te=t(de,{className:"text-right",children:ee}),e[61]=ee,e[62]=te):te=e[62];let re;e[63]!==r?(re=r("trend"),e[63]=r,e[64]=re):re=e[64];let se;e[65]!==re?(se=t(de,{children:re}),e[65]=re,e[66]=se):se=e[66];let le;e[67]!==r?(le=r("trace"),e[67]=r,e[68]=le):le=e[68];let ae;e[69]!==le?(ae=t(de,{children:le}),e[69]=le,e[70]=ae):ae=e[70];let ie;e[71]!==r?(ie=r("dimensions"),e[71]=r,e[72]=ie):ie=e[72];let ne;e[73]!==ie?(ne=t(de,{children:ie}),e[73]=ie,e[74]=ne):ne=e[74],e[75]!==J||e[76]!==G||e[77]!==X||e[78]!==Z||e[79]!==te||e[80]!==se||e[81]!==ae||e[82]!==ne?(N=t(dt,{children:n(Je,{children:[J,G,X,Z,te,se,ae,ne]})}),e[75]=J,e[76]=G,e[77]=X,e[78]=Z,e[79]=te,e[80]=se,e[81]=ae,e[82]=ne,e[83]=N):N=e[83],h=mt,T=E.map(u=>{const K=Rt(u.attributes),P=ft(u.kind,u.name,u.attributes),Q=(O.get(P)??[]).map(ue=>Ut(u.kind,ue));return n(Je,{"data-testid":`mt-instrument-${u.name}`,children:[t(oe,{className:"font-mono text-xs",title:u.functionPath,children:u.name}),t(oe,{children:t(et,{variant:Xt[u.kind],children:j(u.kind)})}),t(oe,{className:"text-right font-mono tabular-nums","data-testid":`mt-instrument-value-${u.name}`,children:We(Jt(u))}),t(oe,{className:"text-right tabular-nums text-muted-foreground",children:u.count.toLocaleString()}),t(oe,{className:"text-right font-mono text-xs tabular-nums text-muted-foreground",children:u.min===u.max?"—":`${We(u.min)}–${We(u.max)}`}),t(oe,{children:Q.length>=2?t(ut,{ariaLabel:r("{name} trend",{name:u.name}),className:"h-6 w-24 text-foreground",series:Q,testId:`mt-instrument-trend-${u.name}`}):t("span",{className:"text-xs text-muted-foreground",children:"—"})}),t(oe,{className:"font-mono text-xs",children:t(Yt,{name:u.name,onOpenTrace:a,traceId:u.exemplarTraceId})}),t(oe,{className:"max-w-64 truncate font-mono text-xs text-muted-foreground",title:K,children:K===""?"—":K})]},P)})}e[6]=i,e[7]=S,e[8]=y,e[9]=m,e[10]=a,e[11]=r,e[12]=h,e[13]=v,e[14]=q,e[15]=$,e[16]=c,e[17]=p,e[18]=g,e[19]=x,e[20]=T,e[21]=C,e[22]=N,e[23]=k,e[24]=R}else h=e[12],v=e[13],q=e[14],$=e[15],c=e[16],p=e[17],g=e[18],x=e[19],T=e[20],C=e[21],N=e[22],k=e[23],R=e[24];if(x!==Symbol.for("react.early_return_sentinel"))return x;let M;e[84]!==h||e[85]!==T?(M=t(h,{children:T}),e[84]=h,e[85]=T,e[86]=M):M=e[86];let _;e[87]!==v||e[88]!==M||e[89]!==C||e[90]!==N?(_=n(v,{"data-testid":C,children:[N,M]}),e[87]=v,e[88]=M,e[89]=C,e[90]=N,e[91]=_):_=e[91];let b;e[92]!==q||e[93]!==_||e[94]!==k?(b=t(q,{className:k,children:_}),e[92]=q,e[93]=_,e[94]=k,e[95]=b):b=e[95];let I;e[96]!==$||e[97]!==b||e[98]!==R?(I=t($,{className:R,children:b}),e[96]=$,e[97]=b,e[98]=R,e[99]=I):I=e[99];let A;return e[100]!==c||e[101]!==p||e[102]!==g||e[103]!==I?(A=n("section",{className:c,"data-testid":p,children:[g,I]}),e[100]=c,e[101]=p,e[102]=g,e[103]=I,e[104]=A):A=e[104],A},er=l=>{const e=Oe(74),{aggregate:a,shardResults:s}=l,r=xe();let d;e[0]!==r?(d=r("Shards"),e[0]=r,e[1]=d):d=e[1];let o;e[2]!==a.failed||e[3]!==a.reachable||e[4]!==r?(o=a.failed>0?r("{reachable} reachable, {failed} unreachable",{failed:a.failed,reachable:a.reachable}):r("{reachable} reachable",{reachable:a.reachable}),e[2]=a.failed,e[3]=a.reachable,e[4]=r,e[5]=o):o=e[5];let i;e[6]!==d||e[7]!==o?(i=t(me,{label:d,testId:"mt-agg-shards",value:o}),e[6]=d,e[7]=o,e[8]=i):i=e[8];let S;e[9]!==r?(S=r("Total requests"),e[9]=r,e[10]=S):S=e[10];let y;e[11]!==a.totalRequests||e[12]!==S?(y=t(me,{label:S,testId:"mt-agg-requests",value:a.totalRequests}),e[11]=a.totalRequests,e[12]=S,e[13]=y):y=e[13];let w;e[14]!==r?(w=r("Total errors"),e[14]=r,e[15]=w):w=e[15];let f;e[16]!==a.totalErrors||e[17]!==w?(f=t(me,{label:w,testId:"mt-agg-errors",value:a.totalErrors}),e[16]=a.totalErrors,e[17]=w,e[18]=f):f=e[18];let m;e[19]!==r?(m=r("Total database size"),e[19]=r,e[20]=m):m=e[20];let h;e[21]!==a.totalDatabaseSize?(h=Xe(a.totalDatabaseSize),e[21]=a.totalDatabaseSize,e[22]=h):h=e[22];let v;e[23]!==m||e[24]!==h?(v=t(me,{label:m,testId:"mt-agg-db-size",value:h}),e[23]=m,e[24]=h,e[25]=v):v=e[25];let q;e[26]!==r?(q=r("Combined cache hit rate"),e[26]=r,e[27]=q):q=e[27];let $;e[28]!==a.hitRate||e[29]!==r?($=a.hitRate===null?r("no cache configured"):`${(a.hitRate*100).toFixed(1)}%`,e[28]=a.hitRate,e[29]=r,e[30]=$):$=e[30];let c;e[31]!==q||e[32]!==$?(c=t(me,{label:q,testId:"mt-agg-cache",value:$}),e[31]=q,e[32]=$,e[33]=c):c=e[33];let p;e[34]!==v||e[35]!==c||e[36]!==i||e[37]!==y||e[38]!==f?(p=n("dl",{className:"grid gap-3 sm:grid-cols-2 lg:grid-cols-3","data-testid":"mt-aggregate-stats",children:[i,y,f,v,c]}),e[34]=v,e[35]=c,e[36]=i,e[37]=y,e[38]=f,e[39]=p):p=e[39];let g;e[40]!==r?(g=r("shard"),e[40]=r,e[41]=g):g=e[41];let x;e[42]!==g?(x=t(de,{children:g}),e[42]=g,e[43]=x):x=e[43];let T;e[44]!==r?(T=r("requests"),e[44]=r,e[45]=T):T=e[45];let C;e[46]!==T?(C=t(de,{children:T}),e[46]=T,e[47]=C):C=e[47];let N;e[48]!==r?(N=r("errors"),e[48]=r,e[49]=N):N=e[49];let k;e[50]!==N?(k=t(de,{children:N}),e[50]=N,e[51]=k):k=e[51];let R;e[52]!==r?(R=r("db size"),e[52]=r,e[53]=R):R=e[53];let M;e[54]!==R?(M=t(de,{children:R}),e[54]=R,e[55]=M):M=e[55];let _;e[56]!==x||e[57]!==C||e[58]!==k||e[59]!==M?(_=t(dt,{children:n(Je,{children:[x,C,k,M]})}),e[56]=x,e[57]=C,e[58]=k,e[59]=M,e[60]=_):_=e[60];let b;if(e[61]!==s||e[62]!==r){let L;e[64]!==r?(L=O=>n(Je,{"data-testid":`mt-agg-row-${O.shard}`,children:[t(oe,{children:O.shard}),O.metrics===null?t(oe,{className:"text-destructive",colSpan:3,children:O.error??r("unreachable")}):n(Ye,{children:[t(oe,{className:"tabular-nums",children:O.metrics.requests}),t(oe,{className:"tabular-nums",children:O.metrics.errors}),t(oe,{className:"tabular-nums",children:Xe(O.metrics.databaseSize)})]})]},O.shard),e[64]=r,e[65]=L):L=e[65],b=s.map(L),e[61]=s,e[62]=r,e[63]=b}else b=e[63];let I;e[66]!==b?(I=t(mt,{children:b}),e[66]=b,e[67]=I):I=e[67];let A;e[68]!==_||e[69]!==I?(A=t(he,{className:"overflow-hidden py-0",children:t(ge,{className:"px-0",children:n(ct,{"data-testid":"mt-agg-table",children:[_,I]})})}),e[68]=_,e[69]=I,e[70]=A):A=e[70];let E;return e[71]!==p||e[72]!==A?(E=n("div",{className:"flex flex-col gap-4","data-testid":"mt-aggregate-view",children:[p,A]}),e[71]=p,e[72]=A,e[73]=E):E=e[73],E},tr=l=>{const e=Math.floor(l/1e3),a=Math.floor(e/3600),s=Math.floor(e%3600/60),r=e%60;return a>0?`${a.toString()}h ${s.toString()}m`:s>0?`${s.toString()}m ${r.toString()}s`:`${r.toString()}s`},rr=(l,e)=>{const a=l+e;return a===0?"—":`${(l/a*100).toFixed(1)}%`},ot=l=>l<=0?"—":l<1?`${(l*1e3).toFixed(0)}μs`:l<1e3?`${l.toFixed(1)}ms`:`${(l/1e3).toFixed(2)}s`,sr=l=>{const e=Oe(75),{currentDelta:a,errorRate:s,history:r,latencyPercentiles:d,metrics:o}=l,i=xe();let S;e[0]!==r||e[1]!==i?(S=r.length>=2?t(ut,{ariaLabel:i("Requests per interval over time"),className:"h-7 w-24 text-foreground",series:r,testId:"mt-sparkline"}):void 0,e[0]=r,e[1]=i,e[2]=S):S=e[2];let y;e[3]!==a||e[4]!==r.length||e[5]!==i?(y=r.length>=2?n(Ye,{children:[t("span",{className:"font-semibold text-foreground",children:`+${a.toLocaleString()}`})," ",i("last interval")]}):t("span",{"data-testid":"mt-sparkline-empty",children:i("collecting samples…")}),e[3]=a,e[4]=r.length,e[5]=i,e[6]=y):y=e[6];let w;e[7]!==i?(w=i("Requests"),e[7]=i,e[8]=w):w=e[8];let f;e[9]!==o.requests||e[10]!==S||e[11]!==y||e[12]!==w?(f=t(me,{chart:S,footer:y,label:w,testId:"mt-requests",value:o.requests}),e[9]=o.requests,e[10]=S,e[11]=y,e[12]=w,e[13]=f):f=e[13];let m;e[14]!==s||e[15]!==i?(m=i("{rate} error rate",{rate:s}),e[14]=s,e[15]=i,e[16]=m):m=e[16];let h;e[17]!==i?(h=i("Errors"),e[17]=i,e[18]=h):h=e[18];let v;e[19]!==s||e[20]!==o.errors?(v=n(Ye,{children:[o.errors," (",s,")"]}),e[19]=s,e[20]=o.errors,e[21]=v):v=e[21];let q;e[22]!==m||e[23]!==h||e[24]!==v?(q=t(me,{footer:m,label:h,testId:"mt-errors",value:v}),e[22]=m,e[23]=h,e[24]=v,e[25]=q):q=e[25];let $;e[26]!==d.p90?($=d.p90>0?`P90 ${ot(d.p90)}`:void 0,e[26]=d.p90,e[27]=$):$=e[27];let c;e[28]!==i?(c=i("P95 latency"),e[28]=i,e[29]=c):c=e[29];let p;e[30]!==d.p95?(p=d.p95>0?ot(d.p95):"—",e[30]=d.p95,e[31]=p):p=e[31];let g;e[32]!==c||e[33]!==p||e[34]!==$?(g=t(me,{footer:$,label:c,testId:"mt-p95",value:p}),e[32]=c,e[33]=p,e[34]=$,e[35]=g):g=e[35];let x;e[36]!==o.cache||e[37]!==i?(x=o.cache===null?void 0:`${o.cache.entries.toLocaleString()} ${i("cache entries")}`,e[36]=o.cache,e[37]=i,e[38]=x):x=e[38];let T;e[39]!==i?(T=i("Database size"),e[39]=i,e[40]=T):T=e[40];let C;e[41]!==o.databaseSize?(C=Xe(o.databaseSize),e[41]=o.databaseSize,e[42]=C):C=e[42];let N;e[43]!==x||e[44]!==T||e[45]!==C?(N=t(me,{footer:x,label:T,testId:"mt-db-size",value:C}),e[43]=x,e[44]=T,e[45]=C,e[46]=N):N=e[46];let k;e[47]!==i?(k=i("Shard"),e[47]=i,e[48]=k):k=e[48];let R;e[49]!==o.shard||e[50]!==k?(R=t(me,{label:k,testId:"mt-shard",value:o.shard}),e[49]=o.shard,e[50]=k,e[51]=R):R=e[51];let M;e[52]!==i?(M=i("Uptime"),e[52]=i,e[53]=M):M=e[53];let _;e[54]!==o.uptimeMs?(_=tr(o.uptimeMs),e[54]=o.uptimeMs,e[55]=_):_=e[55];let b;e[56]!==M||e[57]!==_?(b=t(me,{label:M,testId:"mt-uptime",value:_}),e[56]=M,e[57]=_,e[58]=b):b=e[58];let I;e[59]!==i?(I=i("Cache hit rate"),e[59]=i,e[60]=I):I=e[60];let A;e[61]!==o.cache||e[62]!==i?(A=o.cache===null?i("no cache configured"):i("{rate} ({count} entries)",{count:o.cache.entries,rate:rr(o.cache.hits,o.cache.misses)}),e[61]=o.cache,e[62]=i,e[63]=A):A=e[63];let E;e[64]!==I||e[65]!==A?(E=t(me,{label:I,testId:"mt-cache",value:A}),e[64]=I,e[65]=A,e[66]=E):E=e[66];let L;return e[67]!==g||e[68]!==N||e[69]!==R||e[70]!==b||e[71]!==E||e[72]!==f||e[73]!==q?(L=n("dl",{className:"grid gap-3 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4","data-testid":"mt-stats",children:[f,q,g,N,R,b,E]}),e[67]=g,e[68]=N,e[69]=R,e[70]=b,e[71]=E,e[72]=f,e[73]=q,e[74]=L):L=e[74],L},Ve=l=>l>=100?"critical":l>=50?"warning":"good",Ee=l=>l<1?`${(l*1e3).toFixed(0)}μs`:l<1e3?`${l.toFixed(1)}ms`:`${(l/1e3).toFixed(2)}s`,He=l=>l>=1e9?`${(l/1e9).toFixed(1)}B`:l>=1e6?`${(l/1e6).toFixed(1)}M`:l>=1e3?`${(l/1e3).toFixed(1)}K`:l.toLocaleString(),lr=l=>{const e=Oe(3),{level:a}=l;if(a==="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(a==="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 s;return e[2]===Symbol.for("react.memo_cache_sentinel")?(s=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]=s):s=e[2],s},ar=(l,e)=>{const a=[...l];return a.sort((s,r)=>{switch(e){case"avgTime":return r.avgDurationMs-s.avgDurationMs;case"execCount":return r.execCount-s.execCount;case"rowsRead":return r.rowsRead-s.rowsRead;default:return r.totalDurationMs-s.totalDurationMs}}),a},ir=l=>{const e=Oe(161),{queryStats:a}=l,s=xe(),[r,d]=pe("totalTime");let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o=new Set,e[0]=o):o=e[0];const[i,S]=pe(o);let y;e[1]===Symbol.for("react.memo_cache_sentinel")?(y=R=>{R!==null&&d(R)},e[1]=y):y=e[1];const w=y;let f,m,h,v,q,$,c,p,g,x;if(e[2]!==i||e[3]!==a||e[4]!==r||e[5]!==s){h=Symbol.for("react.early_return_sentinel");e:{const R=ar(a,r);let M;e[16]!==a?(M=a.filter(nr),e[16]=a,e[17]=M):M=e[17];const _=M.length;let b;e[18]!==a?(b=a.filter(or),e[18]=a,e[19]=b):b=e[19];const I=b.length;let A;e[20]!==a?(A=a.filter(cr),e[20]=a,e[21]=A):A=e[21];const E=A.length;let L;e[22]===Symbol.for("react.memo_cache_sentinel")?(L=D=>{S(ce=>{const H=new Set(ce);return H.has(D)?H.delete(D):H.add(D),H})},e[22]=L):L=e[22];const O=L;if(a.length===0){let D;e[23]!==s?(D=s("No query insights yet"),e[23]=s,e[24]=D):D=e[24];let ce;e[25]!==D?(ce=t("p",{className:"text-lg font-medium","data-testid":"qi-empty",children:D}),e[25]=D,e[26]=ce):ce=e[26];let H;e[27]!==s?(H=s("Query insights appear once statements are executed against this shard."),e[27]=s,e[28]=H):H=e[28];let fe;e[29]!==H?(fe=t("p",{className:"mt-1 text-sm",children:H}),e[29]=H,e[30]=fe):fe=e[30];let je;e[31]!==ce||e[32]!==fe?(je=t(he,{children:t(ge,{className:"py-12",children:n("div",{className:"text-center text-muted-foreground",children:[ce,fe]})})}),e[31]=ce,e[32]=fe,e[33]=je):je=e[33],h=je;break e}c="space-y-4",p="qi-root";let z;e[34]!==s?(z=s("Critical queries"),e[34]=s,e[35]=z):z=e[35];let j;e[36]!==z?(j=t(Pe,{className:"pb-2",children:t(Be,{className:"text-sm font-medium",children:z})}),e[36]=z,e[37]=j):j=e[37];let F;e[38]!==_?(F=t("div",{className:"text-2xl font-bold text-destructive","data-testid":"qi-critical",children:_}),e[38]=_,e[39]=F):F=e[39];let U;e[40]!==s?(U=s(">100ms avg execution"),e[40]=s,e[41]=U):U=e[41];let J;e[42]!==U?(J=t("p",{className:"text-xs text-muted-foreground",children:U}),e[42]=U,e[43]=J):J=e[43];let V;e[44]!==F||e[45]!==J?(V=n(ge,{children:[F,J]}),e[44]=F,e[45]=J,e[46]=V):V=e[46];let G;e[47]!==j||e[48]!==V?(G=n(he,{children:[j,V]}),e[47]=j,e[48]=V,e[49]=G):G=e[49];let W;e[50]!==s?(W=s("Moderate queries"),e[50]=s,e[51]=W):W=e[51];let X;e[52]!==W?(X=t(Pe,{className:"pb-2",children:t(Be,{className:"text-sm font-medium",children:W})}),e[52]=W,e[53]=X):X=e[53];let Y;e[54]!==I?(Y=t("div",{className:"text-2xl font-bold text-warning","data-testid":"qi-moderate",children:I}),e[54]=I,e[55]=Y):Y=e[55];let Z;e[56]!==s?(Z=s("50–100ms avg execution"),e[56]=s,e[57]=Z):Z=e[57];let ee;e[58]!==Z?(ee=t("p",{className:"text-xs text-muted-foreground",children:Z}),e[58]=Z,e[59]=ee):ee=e[59];let te;e[60]!==Y||e[61]!==ee?(te=n(ge,{children:[Y,ee]}),e[60]=Y,e[61]=ee,e[62]=te):te=e[62];let re;e[63]!==X||e[64]!==te?(re=n(he,{children:[X,te]}),e[63]=X,e[64]=te,e[65]=re):re=e[65];let se;e[66]!==s?(se=s("Fast queries"),e[66]=s,e[67]=se):se=e[67];let le;e[68]!==se?(le=t(Pe,{className:"pb-2",children:t(Be,{className:"text-sm font-medium",children:se})}),e[68]=se,e[69]=le):le=e[69];let ae;e[70]!==E?(ae=t("div",{className:"text-2xl font-bold text-success","data-testid":"qi-fast",children:E}),e[70]=E,e[71]=ae):ae=e[71];let ie;e[72]!==s?(ie=s("<50ms avg execution"),e[72]=s,e[73]=ie):ie=e[73];let ne;e[74]!==ie?(ne=t("p",{className:"text-xs text-muted-foreground",children:ie}),e[74]=ie,e[75]=ne):ne=e[75];let u;e[76]!==ae||e[77]!==ne?(u=n(ge,{children:[ae,ne]}),e[76]=ae,e[77]=ne,e[78]=u):u=e[78];let K;e[79]!==le||e[80]!==u?(K=n(he,{children:[le,u]}),e[79]=le,e[80]=u,e[81]=K):K=e[81],e[82]!==G||e[83]!==re||e[84]!==K?(g=n("div",{className:"grid gap-4 md:grid-cols-3",children:[G,re,K]}),e[82]=G,e[83]=re,e[84]=K,e[85]=g):g=e[85];let P;e[86]!==s?(P=s("Query leaderboard"),e[86]=s,e[87]=P):P=e[87];let B;e[88]!==P?(B=t("h3",{className:"text-lg font-semibold",children:P}),e[88]=P,e[89]=B):B=e[89];let Q;e[90]!==r||e[91]!==s?(Q=s("Slow queries sorted by {sortField}",{sortField:s(r)}),e[90]=r,e[91]=s,e[92]=Q):Q=e[92];let ue;e[93]!==Q?(ue=t("p",{className:"text-sm text-muted-foreground",children:Q}),e[93]=Q,e[94]=ue):ue=e[94];let be;e[95]!==B||e[96]!==ue?(be=n("div",{children:[B,ue]}),e[95]=B,e[96]=ue,e[97]=be):be=e[97];let ye;e[98]!==s?(ye=s("Sort by"),e[98]=s,e[99]=ye):ye=e[99];let ve;e[100]!==ye?(ve=t("span",{className:"text-sm text-muted-foreground",children:ye}),e[100]=ye,e[101]=ve):ve=e[101];let Ne;e[102]!==s?(Ne=s("Sort queries by"),e[102]=s,e[103]=Ne):Ne=e[103];let Le;e[104]===Symbol.for("react.memo_cache_sentinel")?(Le=t(jt,{}),e[104]=Le):Le=e[104];let Se;e[105]!==Ne?(Se=t(Pt,{"aria-label":Ne,className:"w-[140px]","data-testid":"qi-sort",children:Le}),e[105]=Ne,e[106]=Se):Se=e[106];let we;e[107]!==s?(we=s("Total time"),e[107]=s,e[108]=we):we=e[108];let qe;e[109]!==we?(qe=t(Qe,{value:"totalTime",children:we}),e[109]=we,e[110]=qe):qe=e[110];let Te;e[111]!==s?(Te=s("Avg time"),e[111]=s,e[112]=Te):Te=e[112];let _e;e[113]!==Te?(_e=t(Qe,{value:"avgTime",children:Te}),e[113]=Te,e[114]=_e):_e=e[114];let $e;e[115]!==s?($e=s("Execution count"),e[115]=s,e[116]=$e):$e=e[116];let Ce;e[117]!==$e?(Ce=t(Qe,{value:"execCount",children:$e}),e[117]=$e,e[118]=Ce):Ce=e[118];let Re;e[119]!==s?(Re=s("Rows read"),e[119]=s,e[120]=Re):Re=e[120];let ke;e[121]!==Re?(ke=t(Qe,{value:"rowsRead",children:Re}),e[121]=Re,e[122]=ke):ke=e[122];let Me;e[123]!==qe||e[124]!==_e||e[125]!==Ce||e[126]!==ke?(Me=n(Bt,{children:[qe,_e,Ce,ke]}),e[123]=qe,e[124]=_e,e[125]=Ce,e[126]=ke,e[127]=Me):Me=e[127];let Ie;e[128]!==r||e[129]!==Se||e[130]!==Me?(Ie=n(Qt,{onValueChange:w,value:r,children:[Se,Me]}),e[128]=r,e[129]=Se,e[130]=Me,e[131]=Ie):Ie=e[131];let De;e[132]!==ve||e[133]!==Ie?(De=n("div",{className:"flex items-center gap-2",children:[ve,Ie]}),e[132]=ve,e[133]=Ie,e[134]=De):De=e[134],e[135]!==be||e[136]!==De?(x=n("div",{className:"flex items-center justify-between",children:[be,De]}),e[135]=be,e[136]=De,e[137]=x):x=e[137],m=he;let Ae;e[138]!==s?(Ae=s("Statements"),e[138]=s,e[139]=Ae):Ae=e[139];let ze;e[140]!==Ae?(ze=t(Be,{children:Ae}),e[140]=Ae,e[141]=ze):ze=e[141],$=n(Pe,{children:[ze,t(kt,{children:s("{count} tracked statements",{count:R.length})})]}),f=ge,v="space-y-2";let Ke;e[142]!==i||e[143]!==s?(Ke=D=>{const ce=D.normalizedSql,H=i.has(ce),fe=Ve(D.avgDurationMs);return n("div",{className:"overflow-hidden rounded-lg border","data-testid":"qi-row",children:[n("button",{"aria-expanded":H,className:"flex w-full items-center justify-between p-3 text-left transition-colors hover:bg-muted/50",onClick:()=>{O(ce)},type:"button",children:[n("div",{className:"flex min-w-0 flex-1 items-center gap-3",children:[t(lr,{level:fe}),t("span",{className:"max-w-[300px] truncate font-mono text-sm lg:max-w-[500px]",children:D.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:Ee(D.totalDurationMs)}),t("div",{className:"text-xs text-muted-foreground",children:s("total")})]}),n("div",{className:"text-right",children:[t("div",{className:"text-sm font-medium",children:Ee(D.avgDurationMs)}),t("div",{className:"text-xs text-muted-foreground",children:s("avg")})]}),D.p95DurationMs!==void 0&&n("div",{className:"text-right",children:[t("div",{className:"text-sm font-medium",children:Ee(D.p95DurationMs)}),t("div",{className:"text-xs text-muted-foreground",children:s("p95")})]}),n("div",{className:"text-right",children:[t("div",{className:"text-sm font-medium",children:He(D.execCount)}),t("div",{className:"text-xs text-muted-foreground",children:s("calls")})]})]})]}),H&&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:s("Full statement")}),t("pre",{className:"overflow-x-auto rounded-md bg-muted p-3 font-mono text-sm whitespace-pre-wrap break-all",children:D.normalizedSql})]}),n("div",{className:"grid grid-cols-2 gap-4 text-sm md:grid-cols-4",children:[D.p50DurationMs!==void 0&&n("div",{children:[t("span",{className:"text-muted-foreground",children:s("p50")}),t("span",{className:"block font-medium tabular-nums",children:Ee(D.p50DurationMs)})]}),n("div",{children:[t("span",{className:"text-muted-foreground",children:s("Exec count")}),t("span",{className:"block font-medium tabular-nums",children:He(D.execCount)})]}),n("div",{children:[t("span",{className:"text-muted-foreground",children:s("Total time")}),t("span",{className:"block font-medium tabular-nums",children:Ee(D.totalDurationMs)})]}),n("div",{children:[t("span",{className:"text-muted-foreground",children:s("Rows read")}),t("span",{className:"block font-medium tabular-nums",children:He(D.rowsRead)})]}),n("div",{children:[t("span",{className:"text-muted-foreground",children:s("Rows written")}),t("span",{className:"block font-medium tabular-nums",children:He(D.rowsWritten)})]})]})]})]},ce)},e[142]=i,e[143]=s,e[144]=Ke):Ke=e[144],q=R.map(Ke)}e[2]=i,e[3]=a,e[4]=r,e[5]=s,e[6]=f,e[7]=m,e[8]=h,e[9]=v,e[10]=q,e[11]=$,e[12]=c,e[13]=p,e[14]=g,e[15]=x}else f=e[6],m=e[7],h=e[8],v=e[9],q=e[10],$=e[11],c=e[12],p=e[13],g=e[14],x=e[15];if(h!==Symbol.for("react.early_return_sentinel"))return h;let T;e[145]!==v||e[146]!==q?(T=t("div",{className:v,children:q}),e[145]=v,e[146]=q,e[147]=T):T=e[147];let C;e[148]!==f||e[149]!==T?(C=t(f,{children:T}),e[148]=f,e[149]=T,e[150]=C):C=e[150];let N;e[151]!==m||e[152]!==C||e[153]!==$?(N=n(m,{children:[$,C]}),e[151]=m,e[152]=C,e[153]=$,e[154]=N):N=e[154];let k;return e[155]!==N||e[156]!==c||e[157]!==p||e[158]!==g||e[159]!==x?(k=n("div",{className:c,"data-testid":p,children:[g,x,N]}),e[155]=N,e[156]=c,e[157]=p,e[158]=g,e[159]=x,e[160]=k):k=e[160],k};function nr(l){return Ve(l.avgDurationMs)==="critical"}function or(l){return Ve(l.avgDurationMs)==="warning"}function cr(l){return Ve(l.avgDurationMs)==="good"}const dr=["1m","5m","15m","1h"],mr=l=>new Date(l).toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"}),ur=l=>l.map(e=>({avg:Math.round(e.avgDurationMs*100)/100,execs:e.execCount,label:mr(e.bucketMs)})),fr=({shardKey:l=""})=>{const e=xe(),[a,s]=pe("15m"),d=Ue(Fe.getQueryInsights,{range:a},{live:!0,shardKey:l}).data,o=ur(d?.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:dr.map(i=>t("button",{"aria-pressed":i===a,className:Kt("rounded px-2 py-1 text-xs outline-none transition-colors hover:bg-accent focus-visible:bg-accent",i===a&&"bg-accent font-medium text-foreground"),"data-testid":`qi-range-${i}`,onClick:()=>{s(i)},type:"button",children:i},i))}),d?.capped===!0&&t(et,{"data-testid":"qi-capped",variant:"secondary",children:e("showing a capped set")})]}),o.length===0?t(zt,{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(Ot,{data:o,children:[t(lt,{strokeDasharray:"3 3",vertical:!1}),t(at,{dataKey:"label",fontSize:10,tickLine:!1}),t(it,{allowDecimals:!1,fontSize:10,tickLine:!1,width:32}),t(nt,{}),t(Et,{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(Ft,{data:o,children:[t(lt,{strokeDasharray:"3 3",vertical:!1}),t(at,{dataKey:"label",fontSize:10,tickLine:!1}),t(it,{fontSize:10,tickLine:!1,width:32}),t(nt,{}),t(Lt,{dataKey:"avg",dot:!1,stroke:"var(--color-destructive)",type:"monotone"})]})})]})]}),t(ir,{queryStats:d?.entries??[]})]})},hr=_t(Fe.getMetrics),gr=(l,e)=>l?e:"overview",Pr=({initialShardKey:l})=>{const e=gt(),a=xe(),{queryShardKey:s,setShardKey:r,shardKey:d}=vt(l),[o,i]=pe("overview"),[S,y]=pe([]),w=Ge(null),f=Ge(null),m=Ge(!0);tt(()=>(m.current=!0,()=>{m.current=!1}),[]);const h=yt(s),{data:v,error:q,liveError:$}=Ue(Fe.getMetrics,{},{live:!0,shardKey:s}),c=v??null;tt(()=>{if(v===void 0)return;$t(s);const O=v,z=w.current,j=f.current!==null&&f.current!==O.shard;if(f.current=O.shard,w.current=O.requests,j){y([]);return}z!==null&&O.requests>=z&&y(F=>[...F,O.requests-z].slice(-30))},[v,s]);const[p,g]=pe(null),[x,T]=pe(!1),C=async()=>{T(!0);const O=At(d,Ct());try{const z=await Promise.all(O.map(async j=>{try{const F=await e.query(hr,{},qt(j));return{error:null,metrics:F,shard:j===""?F.shard:j}}catch(F){return{error:Tt(F),metrics:null,shard:j===""?"__root__":j}}}));m.current&&g(z)}finally{m.current&&T(!1)}},N=p===null?null:Mt(p),k=c===null||c.requests===0?"—":`${(c.errors/c.requests*100).toFixed(1)}%`,R=S.length>0?S.at(-1):0,M=c?It(c):{p90:0,p95:0},_=pt(()=>{if(!c||!("queryStats"in c))return;const O=c.queryStats;if(!(!O||!Array.isArray(O)))return Dt(O)},[c]),b=gr(_!==void 0,o),I=()=>{wt(C())},A=()=>{g(null)},E=()=>{i("overview")},L=()=>{i("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(bt,{onChange:r,testId:"mt-shard-input",value:d}),t(xt,{message:$,prefix:"mt"}),t(rt,{"data-testid":"mt-aggregate",disabled:x,onClick:I,size:"sm",type:"button",variant:"secondary",children:a(x?"Aggregating…":"All shards")}),p!==null&&t(rt,{"data-testid":"mt-aggregate-clear",onClick:A,size:"sm",type:"button",variant:"ghost",children:a("Hide")}),t("a",{className:"text-sm text-primary underline-offset-4 hover:underline","data-testid":"mt-cf-link",href:Nt,rel:"noreferrer",target:"_blank",children:a("Open in Cloudflare")})]}),q!==null&&t("p",{className:"text-sm text-destructive","data-testid":"mt-error",role:"alert",children:q}),_!==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 ${b==="overview"?"border-b-2 border-primary text-foreground":"text-muted-foreground hover:text-foreground"}`,"data-testid":"mt-tab-overview",onClick:E,type:"button",children:a("Overview")}),n("button",{className:`pb-2 text-sm font-medium transition-colors ${b==="query-insights"?"border-b-2 border-primary text-foreground":"text-muted-foreground hover:text-foreground"}`,"data-testid":"mt-tab-query-insights",onClick:L,type:"button",children:[a("Query insights"),_.length>0&&t("span",{className:"ml-1.5 rounded-full bg-primary/10 px-1.5 py-0.5 text-xs text-primary",children:_.length})]})]}),b==="query-insights"&&_!==void 0&&t(fr,{shardKey:s}),b==="overview"&&c!==null&&t(sr,{currentDelta:R,errorRate:k,history:S,latencyPercentiles:M,metrics:c}),b==="overview"&&c===null&&null,b==="overview"&&t(Zt,{onOpenTrace:h,shardKey:s}),b==="overview"&&N!==null&&p!==null&&t(er,{aggregate:N,shardResults:p})]})};export{Pr as MetricsPanel};