@lunora/studio 1.0.0-alpha.78 → 1.0.0-alpha.79

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 (119) hide show
  1. package/dist/index.d.ts +2 -1
  2. package/dist/index.js +1 -1
  3. package/dist/mount.js +1 -1
  4. package/dist/packem_chunks/ApiTab.js +1 -1
  5. package/dist/packem_chunks/AuditPanel.js +1 -1
  6. package/dist/packem_chunks/ExportImportPanel.js +1 -1
  7. package/dist/packem_chunks/FileBrowser.js +1 -1
  8. package/dist/packem_chunks/FunctionRunner.js +1 -1
  9. package/dist/packem_chunks/FunctionStatsPanel.js +1 -1
  10. package/dist/packem_chunks/HealthPanel.js +1 -1
  11. package/dist/packem_chunks/InsightsPanel.js +1 -1
  12. package/dist/packem_chunks/LogsPanel.js +1 -1
  13. package/dist/packem_chunks/MailPanel.js +1 -1
  14. package/dist/packem_chunks/MetricsPanel.js +1 -1
  15. package/dist/packem_chunks/MigrationsPanel.js +1 -1
  16. package/dist/packem_chunks/NotificationsPanel.js +1 -1
  17. package/dist/packem_chunks/PitrPanel.js +1 -1
  18. package/dist/packem_chunks/SchemaViewer.js +1 -1
  19. package/dist/packem_chunks/SecurityAdvisorPanel.js +1 -1
  20. package/dist/packem_chunks/SettingsPanel.js +1 -1
  21. package/dist/packem_chunks/SqlEditorPanel.js +1 -1
  22. package/dist/packem_chunks/TableEditor.js +1 -1
  23. package/dist/packem_chunks/agents-panel.js +1 -1
  24. package/dist/packem_chunks/auth-audit-panel.js +1 -1
  25. package/dist/packem_chunks/containers-panel.js +1 -1
  26. package/dist/packem_chunks/dashboards-panel.js +1 -1
  27. package/dist/packem_chunks/fanout-panel.js +1 -1
  28. package/dist/packem_chunks/flags-panel.js +1 -1
  29. package/dist/packem_chunks/issues-panel.js +1 -1
  30. package/dist/packem_chunks/kv-browser.js +1 -1
  31. package/dist/packem_chunks/organizations-panel.js +1 -1
  32. package/dist/packem_chunks/payments-panel.js +1 -1
  33. package/dist/packem_chunks/permissions-panel.js +1 -1
  34. package/dist/packem_chunks/queues-panel.js +1 -1
  35. package/dist/packem_chunks/rls-panel.js +1 -1
  36. package/dist/packem_chunks/storage-rules-panel.js +1 -1
  37. package/dist/packem_chunks/subscriptions-panel.js +1 -1
  38. package/dist/packem_chunks/traces-panel.js +1 -1
  39. package/dist/packem_chunks/users-panel.js +1 -1
  40. package/dist/packem_chunks/workflows-panel.js +1 -1
  41. package/dist/packem_shared/ADMIN_FUNCTIONS-CpgIo9pj.js +1 -0
  42. package/dist/packem_shared/{ApiDocsPanel-eJYZlylw.js → ApiDocsPanel-CjdsxN1t.js} +1 -1
  43. package/dist/packem_shared/{DataBrowser-B8J5lHjP.js → DataBrowser-Bfstz_au.js} +1 -1
  44. package/dist/packem_shared/{HomePanel-DL1HupAN.js → HomePanel-B8EFM4u3.js} +1 -1
  45. package/dist/packem_shared/{Studio-BWBclm_C.js → Studio-BDtS9C5g.js} +1 -1
  46. package/dist/packem_shared/{StudioApp-BFm73yVr.js → StudioApp-DjLzIO9E.js} +1 -1
  47. package/dist/packem_shared/{home-panel-B-8BCffw.js → home-panel-Cm88Nvqh.js} +1 -1
  48. package/dist/packem_shared/{studio-BHA7hnI3.js → studio-BmWFd-Rz.js} +1 -1
  49. package/dist/packem_shared/use-async-submit-DLNCqLFq.js +1 -0
  50. package/dist/packem_shared/use-auth-config-9S_K_W-G.js +1 -0
  51. package/dist/standalone/{chunk-EVN46TVV.js → chunk-2SHUN7KF.js} +1 -1
  52. package/dist/standalone/{chunk-C43X4M5U.js → chunk-3EXLKL6V.js} +1 -1
  53. package/dist/standalone/{chunk-KDOC2DP5.js → chunk-3KAERFMC.js} +1 -1
  54. package/dist/standalone/{chunk-GSPTEMYN.js → chunk-4XDMVUS5.js} +1 -1
  55. package/dist/standalone/{chunk-YD5NF6UT.js → chunk-5YWJNF5X.js} +1 -1
  56. package/dist/standalone/chunk-66YJ3IOZ.js +1 -0
  57. package/dist/standalone/{chunk-2F7G7IWQ.js → chunk-6CULAILE.js} +1 -1
  58. package/dist/standalone/{chunk-D7XXWV4E.js → chunk-6KHEBRBB.js} +1 -1
  59. package/dist/standalone/{chunk-4WLYA3XE.js → chunk-6WCIFGDW.js} +1 -1
  60. package/dist/standalone/{chunk-OHKRN65U.js → chunk-7RG3AKPY.js} +1 -1
  61. package/dist/standalone/{chunk-65OTWFS3.js → chunk-A2FPLOMJ.js} +1 -1
  62. package/dist/standalone/chunk-AADILRJW.js +14 -0
  63. package/dist/standalone/chunk-AADXUXZO.js +1 -0
  64. package/dist/standalone/{chunk-L7N7F3DA.js → chunk-ARI4JTIH.js} +1 -1
  65. package/dist/standalone/chunk-AVZGVZZ7.js +1 -0
  66. package/dist/standalone/{chunk-5U2THBI7.js → chunk-BDO4J5AP.js} +1 -1
  67. package/dist/standalone/{chunk-XSD4Y6SQ.js → chunk-BMQJ4CAO.js} +1 -1
  68. package/dist/standalone/{chunk-5L2MD6F6.js → chunk-CMUP7HPS.js} +1 -1
  69. package/dist/standalone/{chunk-QGKAJTQQ.js → chunk-CP7AUUOU.js} +1 -1
  70. package/dist/standalone/{chunk-UIS34ZPB.js → chunk-DX3RMFQU.js} +1 -1
  71. package/dist/standalone/{chunk-5OWIOACV.js → chunk-E2CJUP53.js} +1 -1
  72. package/dist/standalone/{chunk-FGTK44LR.js → chunk-EIT7ERYE.js} +1 -1
  73. package/dist/standalone/{chunk-35II7U25.js → chunk-EN2QAEO4.js} +1 -1
  74. package/dist/standalone/{chunk-QVEHPYA5.js → chunk-FLYO3XY5.js} +1 -1
  75. package/dist/standalone/{chunk-DVOBKIUX.js → chunk-FWCKM2CU.js} +1 -1
  76. package/dist/standalone/{chunk-VPAXCQ2Y.js → chunk-GITJXQOS.js} +1 -1
  77. package/dist/standalone/{chunk-SA3MDZC3.js → chunk-GP6IRITM.js} +1 -1
  78. package/dist/standalone/{chunk-VGHSEUEX.js → chunk-GXU3ATKS.js} +1 -1
  79. package/dist/standalone/{chunk-FPLGBHY4.js → chunk-H5Y5NQPL.js} +1 -1
  80. package/dist/standalone/{chunk-34UVAASH.js → chunk-HALNNKTC.js} +1 -1
  81. package/dist/standalone/{chunk-UNUU7CJJ.js → chunk-HK4OVYG3.js} +1 -1
  82. package/dist/standalone/{chunk-ZNNAGR6N.js → chunk-HQEMYD2K.js} +1 -1
  83. package/dist/standalone/{chunk-F6GOKFMU.js → chunk-HYT2ZUNP.js} +2 -2
  84. package/dist/standalone/{chunk-7RXOPYR5.js → chunk-I4WGRDL2.js} +1 -1
  85. package/dist/standalone/{chunk-P24JBHEZ.js → chunk-ISZSYNTI.js} +1 -1
  86. package/dist/standalone/chunk-JWG3VRGB.js +1 -0
  87. package/dist/standalone/{chunk-RAA2RGG6.js → chunk-KDYNM3GV.js} +1 -1
  88. package/dist/standalone/{chunk-T2JIUFOD.js → chunk-KP6JQSH2.js} +1 -1
  89. package/dist/standalone/{chunk-IDNNI63H.js → chunk-LSEZN2ZL.js} +1 -1
  90. package/dist/standalone/{chunk-LJDP7NRB.js → chunk-LU3GW7HI.js} +1 -1
  91. package/dist/standalone/chunk-MVGE3JJN.js +1 -0
  92. package/dist/standalone/chunk-MXSHWB3M.js +1 -0
  93. package/dist/standalone/{chunk-BEH5N5ZA.js → chunk-NG6LYBPJ.js} +1 -1
  94. package/dist/standalone/{chunk-HP2UCWND.js → chunk-NL2DZKFI.js} +1 -1
  95. package/dist/standalone/{chunk-EXFBIISG.js → chunk-OGVCXKRL.js} +1 -1
  96. package/dist/standalone/{chunk-EKRN4ZQM.js → chunk-OPC233PZ.js} +1 -1
  97. package/dist/standalone/{chunk-TLHJRWNK.js → chunk-P4CWOYFL.js} +1 -1
  98. package/dist/standalone/{chunk-QLJJ5YYZ.js → chunk-PRJ4RJDU.js} +1 -1
  99. package/dist/standalone/{chunk-XEDU5FO4.js → chunk-PUY3YDXI.js} +1 -1
  100. package/dist/standalone/{chunk-FGTABSAK.js → chunk-QZMR6MUG.js} +1 -1
  101. package/dist/standalone/{chunk-F5QWLENA.js → chunk-W6TE2I2D.js} +1 -1
  102. package/dist/standalone/{chunk-PF7V3G2Z.js → chunk-WCWYSOCN.js} +1 -1
  103. package/dist/standalone/{chunk-BNUJ7QMG.js → chunk-WEO3YVP6.js} +1 -1
  104. package/dist/standalone/{chunk-6DWCIIHE.js → chunk-XIZNYKOD.js} +1 -1
  105. package/dist/standalone/{chunk-3FUFEZ65.js → chunk-XS6Q6GGV.js} +1 -1
  106. package/dist/standalone/{chunk-XQBTNJUQ.js → chunk-Y3CQDULJ.js} +1 -1
  107. package/dist/standalone/{chunk-7J5N6DGQ.js → chunk-YCRMVBPW.js} +1 -1
  108. package/dist/standalone/{chunk-H7NIIBHH.js → chunk-Z2JPEI2V.js} +1 -1
  109. package/dist/standalone/studio.js +1 -1
  110. package/dist/styles.css +1 -1
  111. package/package.json +6 -6
  112. package/dist/packem_shared/ADMIN_FUNCTIONS-BYNSbBVE.js +0 -1
  113. package/dist/packem_shared/use-async-submit-H68GHPz8.js +0 -1
  114. package/dist/standalone/chunk-3QRTYSSX.js +0 -1
  115. package/dist/standalone/chunk-B43FTQJ7.js +0 -1
  116. package/dist/standalone/chunk-GXZAXNZI.js +0 -1
  117. package/dist/standalone/chunk-LE56LPNH.js +0 -13
  118. package/dist/standalone/chunk-PWWHP76O.js +0 -1
  119. package/dist/standalone/chunk-YI3WYUXK.js +0 -1
@@ -1 +1 @@
1
- import{c as B}from"react/compiler-runtime";import{useLunora as Z}from"@lunora/react";import{useNavigate as ee}from"@tanstack/react-router";import{useState as A,useRef as te,useCallback as R,useEffect as j,useMemo as ne}from"react";import{ShardInput as ae}from"../packem_shared/ShardInput-BVn2iCU0.js";import{u as re}from"../packem_shared/button-BkCrNcAs.js";import{K as H}from"../packem_shared/use-admin-query-Di3fLE8H.js";import ie from"../packem_shared/useDebounced-Ihdiid_k.js";import{useT as M}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as T}from"../packem_shared/ADMIN_FUNCTIONS-BYNSbBVE.js";import{f as N,c as q,a as J}from"../packem_shared/internal-AtZ4bTal.js";import{r as se}from"../packem_shared/shard-history-DMEW5VBE.js";import{O as U,A as oe}from"../packem_shared/advisor-view-DaCX9Jy5.js";import{ConfirmButton as le}from"../packem_shared/ConfirmButton-CTL3f3kr.js";import{jsx as w}from"react/jsx-runtime";import{deriveInsights as ce}from"../packem_shared/DEFAULT_INSIGHT_THRESHOLDS-B-hcFVoi.js";import{runAdvisor as de,RUNTIME_LINTS as ue}from"@lunora/advisor";const fe=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)},me=(t,e,r)=>{const n=`"${t}"`,a=`"${e}"`,l=r.map(o=>`"${o}"`).join(", ");return`CREATE INDEX IF NOT EXISTS ${a} ON ${n} (${l});`},he=t=>{const e=B(19),{fields:r,indexName:n,table:a,testId:l}=t,o=M(),[x,d]=A(!1);let u;e[0]!==r||e[1]!==n||e[2]!==a?(u=()=>{const v="navigator"in globalThis?globalThis.navigator.clipboard:void 0;if(v===void 0)return;const g=me(a,n,r);N(v.writeText(g)),d(!0)},e[0]=r,e[1]=n,e[2]=a,e[3]=u):u=e[3];const h=u;if(x){const v=`${l}-applied`;let g;e[4]!==o?(g=o("CREATE INDEX SQL copied to clipboard."),e[4]=o,e[5]=g):g=e[5];let S;return e[6]!==v||e[7]!==g?(S=w("span",{className:"text-xs text-muted-foreground","data-testid":v,children:g}),e[6]=v,e[7]=g,e[8]=S):S=e[8],S}let f;e[9]!==o?(f=o("Apply?"),e[9]=o,e[10]=f):f=e[10];let m;e[11]!==o||e[12]!==a?(m=o("Apply index on {table}",{table:a}),e[11]=o,e[12]=a,e[13]=m):m=e[13];let p;return e[14]!==h||e[15]!==f||e[16]!==m||e[17]!==l?(p=w(le,{confirmLabel:f,onConfirm:h,testId:l,children:m}),e[14]=h,e[15]=f,e[16]=m,e[17]=l,e[18]=p):p=e[18],p},pe=(t,e)=>{const r=new Map;for(const n of e){const a=`${n.table} ${n.index}`;r.set(a,(r.get(a)??0)+n.reads)}return t.map(n=>({index:n.index,reads:r.get(`${n.table} ${n.index}`)??0,table:n.table}))},ge=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}))},be=(t,e)=>e.map(r=>({index:r.name,table:t})),ve=t=>{const e=pe(t.declaredIndexes??[],t.indexHits??[]),r=ge(t.functions??[]),n=t.shardTraffic??[],a=t.analyticsMetrics,l=a&&a.indexHits.length>0?a.indexHits:e,o=a&&a.tableScans.length>0?a.tableScans:r,x=a&&a.shardTraffic.length>0?a.shardTraffic:n,d=de({indexHits:l,schema:{tables:[]},shardTraffic:x,tableScans:o},{lints:ue,source:"runtime"}),u=t.suppressHotScanTables;return(u===void 0?d:d.filter(h=>!(h.metadata.kind==="hot_scan"&&typeof h.metadata.table=="string"&&u.has(h.metadata.table)))).map(h=>U(h))},xe=J(T.listTables),ye=J(T.listTableIndexes),K=t=>`${(t*100).toFixed(1)}%`,D=t=>`${(t/1e3).toFixed(2)}s`,$e=t=>{if(t.length<=1)return t[0]??"";const e=t[t.length-1]??"";return`${t.slice(0,-1).join(", ")} and ${e}`},we=(t,e)=>({"high-error-rate":t("High error rate"),"high-evictions":t("High cache eviction rate"),"high-write-contention":t("High write contention"),"low-cache-hit-rate":t("Low cache hit rate"),"missing-index":t("Missing index"),"slow-function":t("Slow function")})[e.kind],X=(t,e)=>({"high-error-rate":t("{rate} of calls failed.",{rate:K(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:K(e.value)}),"low-cache-hit-rate":t("{rate} hit rate over recent traffic.",{rate:K(e.value)}),"missing-index":t("Slowest call took {duration} — it full-scanned {tables} with no index.",{duration:D(e.value),tables:$e(e.tables??[])}),"slow-function":t("Slowest call took {duration}.",{duration:D(e.value)})})[e.kind],Se=t=>{const e=B(10),{onJump:r,table:n}=t,a=M();let l;e[0]!==r||e[1]!==n?(l=()=>{r(n)},e[0]=r,e[1]=n,e[2]=l):l=e[2];const o=l,x=`in-add-index-${n}`;let d;e[3]!==a||e[4]!==n?(d=a("Add index on {table}",{table:n}),e[3]=a,e[4]=n,e[5]=d):d=e[5];let u;return e[6]!==o||e[7]!==x||e[8]!==d?(u=w(re,{"data-testid":x,onClick:o,size:"sm",type:"button",variant:"outline",children:d}),e[6]=o,e[7]=x,e[8]=d,e[9]=u):u=e[9],u},De=({initialShardKey:t,loadShardTraffic:e})=>{const r=Z(),n=ee(),a=M(),[l,o]=A(t??""),[x,d]=A(null),[u,h]=A(null),f=ie(l.trim(),400),m=te(""),p=H(T.getMetrics,{},{live:!0,shardKey:f}),v=H(T.getFunctionStats,{},{live:!0,shardKey:f}),g=H(T.getAdvisories,{},{live:!0,shardKey:f}),S=p.data??null,C=v.data?.functions??null,F=g.data?.advisories??null,z=p.data?.indexHits??null,L=p.error!==null&&v.error!==null?p.error:null,P=e??(i=>r.shardTraffic(i)),V=async(i,$)=>{const s=i[0];if(s===void 0||s===""){m.current===$&&h(null);return}try{const y=await P(s);if(m.current!==$)return;const b=new Map;for(const c of y.shards)b.has(c.shardKey)||b.set(c.shardKey,{requests:c.requests,shardKey:c.shardKey});h([...b.values()])}catch{m.current===$&&h(null)}},I=R(async i=>{m.current=i;let $=[];try{const s=await r.query(xe,{},q(i));if(m.current!==i)return;se(i),$=s.map(c=>c.name);const y=await Promise.allSettled(s.map(async c=>[c.name,await r.query(ye,{table:c.name},q(i))]));if(m.current!==i)return;const b=[];for(const c of y)if(c.status==="fulfilled"){const[E,Y]=c.value;b.push(...be(E,Y.indexes))}d(b)}catch{m.current===i&&d(null)}await V($,i)},[r]);j(()=>{N(I(f))},[f,I]),j(()=>{const i=()=>{document.visibilityState==="visible"&&(p.refetch(),v.refetch(),g.refetch(),N(I(f)))};return document.addEventListener("visibilitychange",i),()=>{document.removeEventListener("visibilitychange",i)}},[g,f,I,v,p]);const _=R(i=>{N(n({search:{table:i},to:"/schema"}))},[n]),k=ce(S,C),G=new Set(k.filter(i=>i.kind==="missing-index").flatMap(i=>i.tables??[])),O=ve({declaredIndexes:x??[],functions:C,indexHits:z,shardTraffic:u,suppressHotScanTables:G}),Q=ne(()=>{const i=k.map(s=>{const y=s.kind==="missing-index"?s.tables??[]:[];return{action:y.length>0?y.map(b=>w(Se,{onJump:_,table:b},b)):void 0,description:s.message===void 0?X(a,s):`${X(a,s)} — ${s.message}`,entity:s.fn,issueType:we(a,s),key:`${s.kind}:${s.fn??""}`,level:s.severity}}),$=new Set(["unindexed_foreign_key","unindexed_relation_target"]);return[...(F??[]).map(s=>{const y=U(s);if($.has(s.name)&&fe(s.metadata)){const{table:b,suggestedIndex:c}=s.metadata,E=`in-apply-index-${b}-${c.name}`;return{...y,action:w(he,{fields:c.fields,indexName:c.name,table:b,testId:E})}}return y}),...O,...i]},[F,k,_,O,a]),W=w(ae,{onChange:o,testId:"in-shard-input",value:l});return w(oe,{error:L,errorSource:L===null?void 0:p.errorSource,rows:Q,testId:"lunora-insights",toolbar:W})};export{De as InsightsPanel};
1
+ import{c as B}from"react/compiler-runtime";import{useLunora as Z}from"@lunora/react";import{useNavigate as ee}from"@tanstack/react-router";import{useState as A,useRef as te,useCallback as R,useEffect as j,useMemo as ne}from"react";import{ShardInput as ae}from"../packem_shared/ShardInput-BVn2iCU0.js";import{u as re}from"../packem_shared/button-BkCrNcAs.js";import{K as H}from"../packem_shared/use-admin-query-Di3fLE8H.js";import ie from"../packem_shared/useDebounced-Ihdiid_k.js";import{useT as M}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as T}from"../packem_shared/ADMIN_FUNCTIONS-CpgIo9pj.js";import{f as N,c as q,a as J}from"../packem_shared/internal-AtZ4bTal.js";import{r as se}from"../packem_shared/shard-history-DMEW5VBE.js";import{O as U,A as oe}from"../packem_shared/advisor-view-DaCX9Jy5.js";import{ConfirmButton as le}from"../packem_shared/ConfirmButton-CTL3f3kr.js";import{jsx as w}from"react/jsx-runtime";import{deriveInsights as ce}from"../packem_shared/DEFAULT_INSIGHT_THRESHOLDS-B-hcFVoi.js";import{runAdvisor as de,RUNTIME_LINTS as ue}from"@lunora/advisor";const fe=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)},me=(t,e,r)=>{const n=`"${t}"`,a=`"${e}"`,l=r.map(o=>`"${o}"`).join(", ");return`CREATE INDEX IF NOT EXISTS ${a} ON ${n} (${l});`},he=t=>{const e=B(19),{fields:r,indexName:n,table:a,testId:l}=t,o=M(),[x,d]=A(!1);let u;e[0]!==r||e[1]!==n||e[2]!==a?(u=()=>{const v="navigator"in globalThis?globalThis.navigator.clipboard:void 0;if(v===void 0)return;const g=me(a,n,r);N(v.writeText(g)),d(!0)},e[0]=r,e[1]=n,e[2]=a,e[3]=u):u=e[3];const h=u;if(x){const v=`${l}-applied`;let g;e[4]!==o?(g=o("CREATE INDEX SQL copied to clipboard."),e[4]=o,e[5]=g):g=e[5];let S;return e[6]!==v||e[7]!==g?(S=w("span",{className:"text-xs text-muted-foreground","data-testid":v,children:g}),e[6]=v,e[7]=g,e[8]=S):S=e[8],S}let f;e[9]!==o?(f=o("Apply?"),e[9]=o,e[10]=f):f=e[10];let m;e[11]!==o||e[12]!==a?(m=o("Apply index on {table}",{table:a}),e[11]=o,e[12]=a,e[13]=m):m=e[13];let p;return e[14]!==h||e[15]!==f||e[16]!==m||e[17]!==l?(p=w(le,{confirmLabel:f,onConfirm:h,testId:l,children:m}),e[14]=h,e[15]=f,e[16]=m,e[17]=l,e[18]=p):p=e[18],p},pe=(t,e)=>{const r=new Map;for(const n of e){const a=`${n.table} ${n.index}`;r.set(a,(r.get(a)??0)+n.reads)}return t.map(n=>({index:n.index,reads:r.get(`${n.table} ${n.index}`)??0,table:n.table}))},ge=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}))},be=(t,e)=>e.map(r=>({index:r.name,table:t})),ve=t=>{const e=pe(t.declaredIndexes??[],t.indexHits??[]),r=ge(t.functions??[]),n=t.shardTraffic??[],a=t.analyticsMetrics,l=a&&a.indexHits.length>0?a.indexHits:e,o=a&&a.tableScans.length>0?a.tableScans:r,x=a&&a.shardTraffic.length>0?a.shardTraffic:n,d=de({indexHits:l,schema:{tables:[]},shardTraffic:x,tableScans:o},{lints:ue,source:"runtime"}),u=t.suppressHotScanTables;return(u===void 0?d:d.filter(h=>!(h.metadata.kind==="hot_scan"&&typeof h.metadata.table=="string"&&u.has(h.metadata.table)))).map(h=>U(h))},xe=J(T.listTables),ye=J(T.listTableIndexes),K=t=>`${(t*100).toFixed(1)}%`,D=t=>`${(t/1e3).toFixed(2)}s`,$e=t=>{if(t.length<=1)return t[0]??"";const e=t[t.length-1]??"";return`${t.slice(0,-1).join(", ")} and ${e}`},we=(t,e)=>({"high-error-rate":t("High error rate"),"high-evictions":t("High cache eviction rate"),"high-write-contention":t("High write contention"),"low-cache-hit-rate":t("Low cache hit rate"),"missing-index":t("Missing index"),"slow-function":t("Slow function")})[e.kind],X=(t,e)=>({"high-error-rate":t("{rate} of calls failed.",{rate:K(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:K(e.value)}),"low-cache-hit-rate":t("{rate} hit rate over recent traffic.",{rate:K(e.value)}),"missing-index":t("Slowest call took {duration} — it full-scanned {tables} with no index.",{duration:D(e.value),tables:$e(e.tables??[])}),"slow-function":t("Slowest call took {duration}.",{duration:D(e.value)})})[e.kind],Se=t=>{const e=B(10),{onJump:r,table:n}=t,a=M();let l;e[0]!==r||e[1]!==n?(l=()=>{r(n)},e[0]=r,e[1]=n,e[2]=l):l=e[2];const o=l,x=`in-add-index-${n}`;let d;e[3]!==a||e[4]!==n?(d=a("Add index on {table}",{table:n}),e[3]=a,e[4]=n,e[5]=d):d=e[5];let u;return e[6]!==o||e[7]!==x||e[8]!==d?(u=w(re,{"data-testid":x,onClick:o,size:"sm",type:"button",variant:"outline",children:d}),e[6]=o,e[7]=x,e[8]=d,e[9]=u):u=e[9],u},De=({initialShardKey:t,loadShardTraffic:e})=>{const r=Z(),n=ee(),a=M(),[l,o]=A(t??""),[x,d]=A(null),[u,h]=A(null),f=ie(l.trim(),400),m=te(""),p=H(T.getMetrics,{},{live:!0,shardKey:f}),v=H(T.getFunctionStats,{},{live:!0,shardKey:f}),g=H(T.getAdvisories,{},{live:!0,shardKey:f}),S=p.data??null,C=v.data?.functions??null,F=g.data?.advisories??null,z=p.data?.indexHits??null,L=p.error!==null&&v.error!==null?p.error:null,P=e??(i=>r.shardTraffic(i)),V=async(i,$)=>{const s=i[0];if(s===void 0||s===""){m.current===$&&h(null);return}try{const y=await P(s);if(m.current!==$)return;const b=new Map;for(const c of y.shards)b.has(c.shardKey)||b.set(c.shardKey,{requests:c.requests,shardKey:c.shardKey});h([...b.values()])}catch{m.current===$&&h(null)}},I=R(async i=>{m.current=i;let $=[];try{const s=await r.query(xe,{},q(i));if(m.current!==i)return;se(i),$=s.map(c=>c.name);const y=await Promise.allSettled(s.map(async c=>[c.name,await r.query(ye,{table:c.name},q(i))]));if(m.current!==i)return;const b=[];for(const c of y)if(c.status==="fulfilled"){const[E,Y]=c.value;b.push(...be(E,Y.indexes))}d(b)}catch{m.current===i&&d(null)}await V($,i)},[r]);j(()=>{N(I(f))},[f,I]),j(()=>{const i=()=>{document.visibilityState==="visible"&&(p.refetch(),v.refetch(),g.refetch(),N(I(f)))};return document.addEventListener("visibilitychange",i),()=>{document.removeEventListener("visibilitychange",i)}},[g,f,I,v,p]);const _=R(i=>{N(n({search:{table:i},to:"/schema"}))},[n]),k=ce(S,C),G=new Set(k.filter(i=>i.kind==="missing-index").flatMap(i=>i.tables??[])),O=ve({declaredIndexes:x??[],functions:C,indexHits:z,shardTraffic:u,suppressHotScanTables:G}),Q=ne(()=>{const i=k.map(s=>{const y=s.kind==="missing-index"?s.tables??[]:[];return{action:y.length>0?y.map(b=>w(Se,{onJump:_,table:b},b)):void 0,description:s.message===void 0?X(a,s):`${X(a,s)} — ${s.message}`,entity:s.fn,issueType:we(a,s),key:`${s.kind}:${s.fn??""}`,level:s.severity}}),$=new Set(["unindexed_foreign_key","unindexed_relation_target"]);return[...(F??[]).map(s=>{const y=U(s);if($.has(s.name)&&fe(s.metadata)){const{table:b,suggestedIndex:c}=s.metadata,E=`in-apply-index-${b}-${c.name}`;return{...y,action:w(he,{fields:c.fields,indexName:c.name,table:b,testId:E})}}return y}),...O,...i]},[F,k,_,O,a]),W=w(ae,{onChange:o,testId:"in-shard-input",value:l});return w(oe,{error:L,errorSource:L===null?void 0:p.errorSource,rows:Q,testId:"lunora-insights",toolbar:W})};export{De as InsightsPanel};
@@ -1 +1 @@
1
- import{c as M}from"react/compiler-runtime";import{useVirtualizer as qe}from"@tanstack/react-virtual";import{useState as $,useReducer as Me,useRef as ie,useEffect as de,useMemo as Ae}from"react";import{f as Q}from"../packem_shared/log-fields-CoL3hsIQ.js";import{E as Oe}from"../packem_shared/error-alert-B59DnrDI.js";import{L as Fe}from"../packem_shared/live-status-CGW2JHf_.js";import{ShardInput as De}from"../packem_shared/ShardInput-BVn2iCU0.js";import{g as Y}from"../packem_shared/badge-BbuuAio7.js";import{E as B}from"../packem_shared/empty-state-Cg7t_8qu.js";import{u as _}from"../packem_shared/input-JHu63lTv.js";import{K as re}from"../packem_shared/use-admin-query-Di3fLE8H.js";import G from"../packem_shared/useDebounced-Ihdiid_k.js";import{useT as ce}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as te}from"../packem_shared/ADMIN_FUNCTIONS-BYNSbBVE.js";import{b as ue}from"../packem_shared/cf-links-gbDy51nR.js";import{r as Ke}from"../packem_shared/shard-history-DMEW5VBE.js";import{c as q}from"../packem_shared/utils-bhneXptQ.js";import{l as Ue}from"../packem_shared/virtual-rect-1o1veP7R.js";import{useLunora as Ve}from"@lunora/react";import{u as ze}from"../packem_shared/button-BkCrNcAs.js";import{n as je,d as Be,m as me,p as P,f as Ge,u as T}from"../packem_shared/table-DdJBrClo.js";import{f as ae,l as We,e as le}from"../packem_shared/internal-AtZ4bTal.js";import{jsx as t,jsxs as w,Fragment as Qe}from"react/jsx-runtime";const he=["trace","debug","log","info","warn","error","fatal"],Ye="LOG_ARCHIVE_NOT_CONFIGURED",ge={debug:"secondary",error:"destructive",fatal:"destructive",info:"outline",log:"outline",trace:"outline",warn:"secondary"},He={cursor:void 0,error:null,loading:!1,notConfigured:!1,rows:null},Je=(l,e)=>{switch(e.type){case"append":return{...l,cursor:e.cursor,error:null,loading:!1,rows:[...l.rows??[],...e.rows]};case"failed":return{cursor:void 0,error:e.message,loading:!1,notConfigured:!1,rows:null};case"loaded":return{cursor:e.cursor,error:null,loading:!1,notConfigured:!1,rows:e.rows};case"loading":return{...l,error:null,loading:!0,notConfigured:!1};case"notConfigured":return{cursor:void 0,error:null,loading:!1,notConfigured:!0,rows:null};case"pageFailed":return{...l,error:e.message,loading:!1};default:return l}},Xe=l=>{const e=M(33),{row:r}=l;let s;e[0]!==r.fields?(s=Q(r.fields),e[0]=r.fields,e[1]=s):s=e[1];const n=s,a=`lg-archive-row-${String(r.ts)}`;let i;e[2]!==r.ts?(i=new Date(r.ts).toLocaleString(),e[2]=r.ts,e[3]=i):i=e[3];let u;e[4]!==i?(u=t(T,{className:"tabular-nums whitespace-nowrap text-xs text-muted-foreground",children:i}),e[4]=i,e[5]=u):u=e[5];const v=ge[r.level];let c;e[6]!==r.level||e[7]!==v?(c=t(T,{children:t(Y,{variant:v,children:r.level})}),e[6]=r.level,e[7]=v,e[8]=c):c=e[8];let d;e[9]!==r.functionPath?(d=t(T,{className:"font-mono text-xs",children:r.functionPath}),e[9]=r.functionPath,e[10]=d):d=e[10];let b;e[11]!==r.message?(b=t("div",{className:"truncate",title:r.message,children:r.message}),e[11]=r.message,e[12]=b):b=e[12];let f;e[13]!==n?(f=n!==""&&t("div",{className:"truncate font-mono text-[11px] text-muted-foreground",title:n,children:n}),e[13]=n,e[14]=f):f=e[14];let m;e[15]!==b||e[16]!==f?(m=w(T,{className:"max-w-md",children:[b,f]}),e[15]=b,e[16]=f,e[17]=m):m=e[17];const h=r.traceId??"—";let p;e[18]!==h?(p=t(T,{className:"font-mono text-[11px] text-muted-foreground",children:h}),e[18]=h,e[19]=p):p=e[19];const L=r.shardKey??"—";let g;e[20]!==L?(g=t(T,{className:"font-mono text-[11px] text-muted-foreground",children:L}),e[20]=L,e[21]=g):g=e[21];const x=r.userId??"—";let y;e[22]!==x?(y=t(T,{className:"font-mono text-[11px] text-muted-foreground",children:x}),e[22]=x,e[23]=y):y=e[23];let C;return e[24]!==m||e[25]!==p||e[26]!==g||e[27]!==y||e[28]!==a||e[29]!==u||e[30]!==c||e[31]!==d?(C=w(me,{"data-testid":a,children:[u,c,d,m,p,g,y]}),e[24]=m,e[25]=p,e[26]=g,e[27]=y,e[28]=a,e[29]=u,e[30]=c,e[31]=d,e[32]=C):C=e[32],C},Ze=({shardKey:l})=>{const e=Ve(),r=ce(),[s,n]=$(""),[a,i]=$(""),[u,v]=$(""),[{cursor:c,error:d,loading:b,notConfigured:f,rows:m},h]=Me(Je,He),p=G(s.trim(),400),L=G(a.trim(),400),g={...p===""?{}:{functionPathPrefix:p},...u===""?{}:{minLevel:u},...l===""?{}:{shardKey:l},...L===""?{}:{userId:L}},x=JSON.stringify(g),y=ie(x);de(()=>{const N={cancelled:!1};return y.current=x,ae((async()=>{h({type:"loading"});try{const k=await e.queryLogArchive(g);N.cancelled||h({cursor:k.nextCursor,rows:k.rows,type:"loaded"})}catch(k){N.cancelled||h(We(k)===Ye?{type:"notConfigured"}:{message:le(k),type:"failed"})}})()),()=>{N.cancelled=!0}},[e,x]);const C=async()=>{if(c===void 0)return;const N=x;h({type:"loading"});try{const k=await e.queryLogArchive({...g,cursor:c});y.current===N&&h({cursor:k.nextCursor,rows:k.rows,type:"append"})}catch(k){y.current===N&&h({message:le(k),type:"pageFailed"})}},R=N=>{n(N.target.value)},S=N=>{i(N.target.value)},I=N=>{v(N.target.value)},E=()=>{ae(C())};return f?t(B,{action:t("a",{className:"text-sm text-primary underline-offset-4 hover:underline",href:ue,rel:"noreferrer",target:"_blank",children:r("Open in Cloudflare")}),description:r("Wire pipelineLogSink to a Cloudflare Pipeline → R2 Data Catalog table and set R2_SQL_ACCOUNT_ID, R2_SQL_TOKEN, R2_SQL_BUCKET to browse the durable log archive here."),testId:"lg-archive-not-configured",title:r("Log archive not configured")}):w("div",{className:"flex flex-col gap-4","data-testid":"lg-archive",children:[w("div",{className:"flex flex-wrap items-center gap-2",children:[t(_,{"aria-label":r("Function path prefix"),className:"h-8 w-48","data-testid":"lg-archive-path",onChange:R,placeholder:r("function path…"),value:s}),t(_,{"aria-label":r("User id"),className:"h-8 w-40","data-testid":"lg-archive-user",onChange:S,placeholder:r("user id…"),value:a}),w("select",{"aria-label":r("Minimum level"),className:"h-8 rounded-md border border-border bg-background px-2 text-sm","data-testid":"lg-archive-min-level",onChange:I,value:u,children:[t("option",{value:"",children:r("min level")}),he.map(N=>t("option",{value:N,children:N},N))]})]}),d!==null&&t("p",{className:"text-sm text-destructive","data-testid":"lg-archive-error",role:"alert",children:d}),b&&m===null&&d===null&&t("p",{className:"text-sm text-muted-foreground","data-testid":"lg-archive-loading",children:r("Loading…")}),m!==null&&m.length===0&&t(B,{description:r("No archived logs match these filters. The durable archive fills as pipelineLogSink flushes records to R2."),testId:"lg-archive-empty",title:r("No archived logs.")}),m!==null&&m.length>0&&t("div",{className:"overflow-hidden rounded-xl border border-border shadow-xs",children:w(je,{"data-testid":"lg-archive-table",children:[t(Be,{children:w(me,{children:[t(P,{children:r("Time")}),t(P,{children:r("Level")}),t(P,{children:r("Function")}),t(P,{children:r("Message")}),t(P,{children:r("Trace")}),t(P,{children:r("Shard")}),t(P,{children:r("User")})]})}),t(Ge,{children:m.map((N,k)=>t(Xe,{row:N},`${String(N.ts)}-${String(k)}`))})]})}),c!==void 0&&t("div",{children:t(ze,{"data-testid":"lg-archive-more",disabled:b,onClick:E,size:"sm",variant:"outline",children:r(b?"Loading…":"Load more")})})]})},W=400,er=36,rr={height:W,overflow:"auto"},fe={left:0,position:"absolute",top:0,width:"100%"},tr={error:"destructive",ok:"secondary"},ar=l=>{const e=M(26),{entry:r,index:s,measureRef:n,start:a}=l,i=`translateY(${String(a)}px)`;let u;e[0]!==i?(u={...fe,transform:i},e[0]=i,e[1]=u):u=e[1];const v=u;let c;e[2]!==r.fields?(c=Q(r.fields),e[2]=r.fields,e[3]=c):c=e[3];const d=c;let b;e[4]!==r.timestamp?(b=new Date(r.timestamp).toLocaleString(),e[4]=r.timestamp,e[5]=b):b=e[5];let f;e[6]!==b?(f=t("span",{className:"w-44 shrink-0 tabular-nums text-muted-foreground",role:"gridcell",children:b}),e[6]=b,e[7]=f):f=e[7];const m=ge[r.level];let h;e[8]!==r.level||e[9]!==m?(h=t("span",{className:"w-20 shrink-0",role:"gridcell",children:t(Y,{variant:m,children:r.level})}),e[8]=r.level,e[9]=m,e[10]=h):h=e[10];const p=r.functionPath??"—";let L;e[11]!==p?(L=t("span",{className:"w-48 shrink-0 truncate text-muted-foreground",role:"gridcell",children:p}),e[11]=p,e[12]=L):L=e[12];let g;e[13]!==d?(g=d===""?null:t("span",{className:"ml-2 text-muted-foreground","data-testid":"lg-fields",children:d}),e[13]=d,e[14]=g):g=e[14];let x;e[15]!==r.message||e[16]!==g?(x=w("span",{className:"flex-1 truncate",role:"gridcell",children:[r.message,g]}),e[15]=r.message,e[16]=g,e[17]=x):x=e[17];let y;return e[18]!==s||e[19]!==n||e[20]!==v||e[21]!==x||e[22]!==f||e[23]!==h||e[24]!==L?(y=w("div",{className:"flex items-center border-b border-border px-3 py-1.5 font-mono text-xs hover:bg-muted/50","data-index":s,"data-testid":"lg-row",ref:n,role:"row",style:v,children:[f,h,L,x]}),e[18]=s,e[19]=n,e[20]=v,e[21]=x,e[22]=f,e[23]=h,e[24]=L,e[25]=y):y=e[25],y},oe=l=>l.length===0?"—":l.join(", "),lr=l=>{const e=M(37),{entry:r,index:s,measureRef:n,start:a}=l,i=`translateY(${String(a)}px)`;let u;e[0]!==i?(u={...fe,transform:i},e[0]=i,e[1]=u):u=e[1];const v=u;let c;e[2]!==r.ts?(c=new Date(r.ts).toLocaleString(),e[2]=r.ts,e[3]=c):c=e[3];let d;e[4]!==c?(d=t("span",{className:"w-40 shrink-0 tabular-nums text-muted-foreground",role:"gridcell",children:c}),e[4]=c,e[5]=d):d=e[5];const b=tr[r.outcome];let f;e[6]!==r.outcome||e[7]!==b?(f=t("span",{className:"w-16 shrink-0",role:"gridcell",children:t(Y,{variant:b,children:r.outcome})}),e[6]=r.outcome,e[7]=b,e[8]=f):f=e[8];let m;e[9]!==r.functionPath?(m=t("span",{className:"w-44 shrink-0 truncate",role:"gridcell",title:r.functionPath,children:r.functionPath}),e[9]=r.functionPath,e[10]=m):m=e[10];const h=r.shardKey??"—";let p;e[11]!==h?(p=t("span",{className:"w-24 shrink-0 truncate text-muted-foreground",role:"gridcell",children:h}),e[11]=h,e[12]=p):p=e[12];const L=r.userId??"—";let g;e[13]!==L?(g=t("span",{className:"w-24 shrink-0 truncate text-muted-foreground",role:"gridcell",children:L}),e[13]=L,e[14]=g):g=e[14];let x;e[15]!==r.durationMs?(x=Math.round(r.durationMs),e[15]=r.durationMs,e[16]=x):x=e[16];const y=`${String(x)}ms`;let C;e[17]!==y?(C=t("span",{className:"w-16 shrink-0 tabular-nums text-muted-foreground",role:"gridcell",children:y}),e[17]=y,e[18]=C):C=e[18];let R;e[19]!==r.errorMessage||e[20]!==r.outcome||e[21]!==r.tablesRead||e[22]!==r.tablesWritten?(R=r.outcome==="error"&&r.errorMessage!==void 0?r.errorMessage:`r:${oe(r.tablesRead)} · w:${oe(r.tablesWritten)}`,e[19]=r.errorMessage,e[20]=r.outcome,e[21]=r.tablesRead,e[22]=r.tablesWritten,e[23]=R):R=e[23];let S;e[24]!==R?(S=t("span",{className:"flex-1 truncate text-muted-foreground",role:"gridcell",children:R}),e[24]=R,e[25]=S):S=e[25];let I;return e[26]!==s||e[27]!==n||e[28]!==v||e[29]!==g||e[30]!==C||e[31]!==S||e[32]!==d||e[33]!==f||e[34]!==m||e[35]!==p?(I=w("div",{className:"flex items-center border-b border-border px-3 py-1.5 font-mono text-xs hover:bg-muted/50","data-index":s,"data-testid":"lg-req-row",ref:n,role:"row",style:v,children:[d,f,m,p,g,C,S]}),e[26]=s,e[27]=n,e[28]=v,e[29]=g,e[30]=C,e[31]=S,e[32]=d,e[33]=f,e[34]=m,e[35]=p,e[36]=I):I=e[36],I},se=l=>{const{entries:e}=l??{};return Array.isArray(e)?e:[]},or=l=>{const e={};return l.functionPathPrefix.trim()!==""&&(e.functionPathPrefix=l.functionPathPrefix.trim()),l.userId.trim()!==""&&(e.userId=l.userId.trim()),l.tableTouched.trim()!==""&&(e.tableTouched=l.tableTouched.trim()),(l.outcome==="ok"||l.outcome==="error")&&(e.outcome=l.outcome),e},pe=he,sr={"5m":300*1e3,"15m":900*1e3,"1h":3600*1e3},nr=(l,e)=>{const r=e.search.trim().toLowerCase(),s=e.path.trim().toLowerCase(),n=e.range==="all"?Number.NEGATIVE_INFINITY:e.now-sr[e.range];return l.filter(a=>e.levels.size>0&&!e.levels.has(a.level)||a.timestamp<n||s!==""&&!(a.functionPath??"").toLowerCase().includes(s)?!1:r===""||a.message.toLowerCase().includes(r)||Q(a.fields).toLowerCase().includes(r))},ir="—",dr=l=>{const e=new Map,r=new Map;for(const a of l){e.set(a.level,(e.get(a.level)??0)+1);const i=a.functionPath??ir;r.set(i,(r.get(i)??0)+1)}const s=pe.filter(a=>e.has(a)).map(a=>({count:e.get(a)??0,key:a})),n=[...r.entries()].map(([a,i])=>({count:i,key:a})).toSorted((a,i)=>i.count===a.count?a.key.localeCompare(i.key):i.count-a.count);return{byLevel:s,byPath:n,total:l.length}},cr=l=>{const e=M(11),{level:r,onToggle:s,selected:n}=l;let a;e[0]!==r||e[1]!==s?(a=()=>{s(r)},e[0]=r,e[1]=s,e[2]=a):a=e[2];const i=a,u=n?"border-border bg-muted font-medium":"border-input text-muted-foreground";let v;e[3]!==u?(v=q("rounded-md border px-2 py-1 text-xs",u),e[3]=u,e[4]=v):v=e[4];const c=`logs-level-${r}`;let d;return e[5]!==r||e[6]!==i||e[7]!==n||e[8]!==v||e[9]!==c?(d=t("button",{"aria-pressed":n,className:v,"data-testid":c,onClick:i,type:"button",children:r}),e[5]=r,e[6]=i,e[7]=n,e[8]=v,e[9]=c,e[10]=d):d=e[10],d},ne=l=>{const e=M(7),{bucket:r}=l;let s;e[0]!==r.key?(s=t("span",{className:"truncate text-muted-foreground",role:"gridcell",children:r.key}),e[0]=r.key,e[1]=s):s=e[1];let n;e[2]!==r.count?(n=t("span",{className:"shrink-0 tabular-nums",role:"gridcell",children:r.count}),e[2]=r.count,e[3]=n):n=e[3];let a;return e[4]!==s||e[5]!==n?(a=w("div",{className:"flex items-center justify-between gap-4 px-3 py-1 font-mono text-xs","data-testid":"logs-summary-row",role:"row",children:[s,n]}),e[4]=s,e[5]=n,e[6]=a):a=e[6],a},qr=({initialShardKey:l})=>{const e=ce(),[r,s]=$("requests"),[n,a]=$(l??""),[i,u]=$(""),[v,c]=$(()=>new Set),[d,b]=$(""),[f,m]=$("all"),[h,p]=$(!1),[L,g]=$(""),[x,y]=$(""),[C,R]=$(""),[S,I]=$("all"),E=G(n.trim(),400),N=or({functionPathPrefix:L,outcome:S,tableTouched:C,userId:x}),k=re(te.getRequestLog,N,{enabled:r==="requests",live:!0,shardKey:E}),H=re(te.getLogs,{},{enabled:r==="errors",live:!0,shardKey:E}),D=r==="requests"?k:H,{error:J,errorSource:ve,isLoading:X,liveError:be}=D,xe=se(H.data),Z=se(k.data);de(()=>{D.data!==void 0&&Ke(E)},[D.data,E]);const K=nr(xe,{levels:v,now:Date.now(),path:d,range:f,search:i}),U=dr(K),V=r==="requests"?Z.length:K.length,z=r==="errors"&&h,A=Ae(()=>J!==null?"error":V===0?X?z?"summary":"list":"empty":z?"summary":"list",[V,X,J,z]),ee=ie(null),O=qe({count:V,estimateSize:()=>er,getScrollElement:()=>ee.current,initialRect:{height:W,width:800},observeElementRect:(o,j)=>Ue(o,j,W),overscan:8}),we=O.getVirtualItems(),ye={height:O.getTotalSize(),position:"relative",width:"100%"},Ne=o=>{u(o.target.value)},Le=o=>{c(j=>{const F=new Set(j);return F.has(o)?F.delete(o):F.add(o),F})},Ce=o=>{b(o.target.value)},ke=o=>{m(o.target.value)},$e=()=>{p(o=>!o)},Se=o=>{g(o.target.value)},Re=o=>{y(o.target.value)},Ie=o=>{R(o.target.value)},Ee=o=>{I(o.target.value)},Pe=()=>{s("requests"),p(!1)},Te=()=>{s("errors"),p(!1)},_e=()=>{s("archive"),p(!1)};return w("div",{className:"flex flex-col gap-4","data-testid":"lunora-logs",children:[w("div",{className:"flex flex-wrap items-center gap-2",children:[w("div",{className:"inline-flex overflow-hidden rounded-lg border border-border",role:"tablist",children:[t("button",{"aria-selected":r==="requests",className:q("px-3 py-1 text-sm",r==="requests"?"bg-muted font-medium":"text-muted-foreground"),"data-testid":"lg-view-requests",onClick:Pe,role:"tab",type:"button",children:e("Requests")}),t("button",{"aria-selected":r==="errors",className:q("px-3 py-1 text-sm",r==="errors"?"bg-muted font-medium":"text-muted-foreground"),"data-testid":"lg-view-errors",onClick:Te,role:"tab",type:"button",children:e("Errors")}),t("button",{"aria-selected":r==="archive",className:q("px-3 py-1 text-sm",r==="archive"?"bg-muted font-medium":"text-muted-foreground"),"data-testid":"lg-view-archive",onClick:_e,role:"tab",type:"button",children:e("Archive")})]}),t(De,{onChange:a,testId:"lg-shard-input",value:n}),r!=="archive"&&t(Fe,{message:be,prefix:"lg"}),t("a",{className:"text-sm text-primary underline-offset-4 hover:underline","data-testid":"lg-cf-link",href:ue,rel:"noreferrer",target:"_blank",children:e("Open in Cloudflare")})]}),r==="errors"&&w("div",{className:"flex flex-wrap items-center gap-2",children:[t(_,{"aria-label":e("Search messages"),className:"h-8 w-48","data-testid":"lg-search",onChange:Ne,placeholder:e("search message"),value:i}),t(_,{"aria-label":e("Function path"),className:"h-8 w-40","data-testid":"logs-path-filter",onChange:Ce,placeholder:e("filter path"),value:d}),t("div",{"aria-label":e("Level filter"),className:"inline-flex items-center gap-1","data-testid":"logs-level-filter",role:"group",children:pe.map(o=>t(cr,{level:o,onToggle:Le,selected:v.has(o)},o))}),w("select",{"aria-label":e("Time range"),className:"h-8 rounded-md border border-input bg-transparent px-2 text-sm shadow-xs focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-none","data-testid":"logs-time-range",onChange:ke,value:f,children:[t("option",{value:"all",children:e("All time")}),t("option",{value:"5m",children:e("Last 5m")}),t("option",{value:"15m",children:e("Last 15m")}),t("option",{value:"1h",children:e("Last hour")})]}),t("button",{"aria-pressed":h,className:q("h-8 rounded-md border px-3 text-sm",h?"border-border bg-muted font-medium":"border-input text-muted-foreground"),"data-testid":"logs-summary-toggle",onClick:$e,type:"button",children:e(h?"List":"Summary")})]}),r==="requests"&&w("div",{className:"flex flex-wrap items-center gap-2",children:[t(_,{"aria-label":e("Function path"),className:"h-8 w-44","data-testid":"lg-req-path",onChange:Se,placeholder:e("file:function"),value:L}),t(_,{"aria-label":e("User id"),className:"h-8 w-32","data-testid":"lg-req-user",onChange:Re,placeholder:e("userId"),value:x}),t(_,{"aria-label":e("Table touched"),className:"h-8 w-32","data-testid":"lg-req-table",onChange:Ie,placeholder:e("table"),value:C}),w("select",{"aria-label":e("Outcome filter"),className:"h-8 rounded-md border border-input bg-transparent px-2 text-sm shadow-xs focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-none","data-testid":"lg-req-outcome",onChange:Ee,value:S,children:[t("option",{value:"all",children:e("all")}),t("option",{value:"ok",children:e("ok")}),t("option",{value:"error",children:e("error")})]})]}),r==="archive"?t(Ze,{shardKey:E}):w(Qe,{children:[A==="error"&&t(Oe,{error:ve,testId:"lg-error"}),A==="empty"&&t(B,{description:e("Function and request logs for this shard show up here as your app handles traffic."),icon:t("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:t("path",{d:"M4 5h16M4 12h16M4 19h10"})}),testId:"lg-empty",title:e("No logs.")}),A==="summary"&&w("div",{className:"flex flex-col gap-4 rounded-xl border border-border bg-card p-4 shadow-xs","data-testid":"logs-summary",children:[t("p",{className:"text-xs text-muted-foreground","data-testid":"logs-summary-total",children:e("{count} entries",{count:U.total})}),w("div",{children:[t("h4",{className:"mb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:e("By level")}),t("div",{className:"overflow-hidden rounded-lg border border-border","data-testid":"logs-summary-levels",role:"grid",children:U.byLevel.map(o=>t(ne,{bucket:o},o.key))})]}),w("div",{children:[t("h4",{className:"mb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:e("By function")}),t("div",{className:"overflow-hidden rounded-lg border border-border","data-testid":"logs-summary-paths",role:"grid",children:U.byPath.map(o=>t(ne,{bucket:o},o.key))})]})]}),A==="list"&&t("div",{className:"rounded-xl border border-border shadow-xs","data-testid":"lg-scroll",ref:ee,style:rr,children:t("div",{"aria-label":e("Recent logs"),"data-testid":"lg-table",role:"grid",style:ye,children:we.map(o=>r==="requests"?t(lr,{entry:Z[o.index],index:o.index,measureRef:O.measureElement,start:o.start},o.key):t(ar,{entry:K[o.index],index:o.index,measureRef:O.measureElement,start:o.start},o.key))})})]})]})};export{qr as LogsPanel,nr as filterLogs,dr as summarizeLogs};
1
+ import{c as M}from"react/compiler-runtime";import{useVirtualizer as qe}from"@tanstack/react-virtual";import{useState as $,useReducer as Me,useRef as ie,useEffect as de,useMemo as Ae}from"react";import{f as Q}from"../packem_shared/log-fields-CoL3hsIQ.js";import{E as Oe}from"../packem_shared/error-alert-B59DnrDI.js";import{L as Fe}from"../packem_shared/live-status-CGW2JHf_.js";import{ShardInput as De}from"../packem_shared/ShardInput-BVn2iCU0.js";import{g as Y}from"../packem_shared/badge-BbuuAio7.js";import{E as B}from"../packem_shared/empty-state-Cg7t_8qu.js";import{u as _}from"../packem_shared/input-JHu63lTv.js";import{K as re}from"../packem_shared/use-admin-query-Di3fLE8H.js";import G from"../packem_shared/useDebounced-Ihdiid_k.js";import{useT as ce}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as te}from"../packem_shared/ADMIN_FUNCTIONS-CpgIo9pj.js";import{b as ue}from"../packem_shared/cf-links-gbDy51nR.js";import{r as Ke}from"../packem_shared/shard-history-DMEW5VBE.js";import{c as q}from"../packem_shared/utils-bhneXptQ.js";import{l as Ue}from"../packem_shared/virtual-rect-1o1veP7R.js";import{useLunora as Ve}from"@lunora/react";import{u as ze}from"../packem_shared/button-BkCrNcAs.js";import{n as je,d as Be,m as me,p as P,f as Ge,u as T}from"../packem_shared/table-DdJBrClo.js";import{f as ae,l as We,e as le}from"../packem_shared/internal-AtZ4bTal.js";import{jsx as t,jsxs as w,Fragment as Qe}from"react/jsx-runtime";const he=["trace","debug","log","info","warn","error","fatal"],Ye="LOG_ARCHIVE_NOT_CONFIGURED",ge={debug:"secondary",error:"destructive",fatal:"destructive",info:"outline",log:"outline",trace:"outline",warn:"secondary"},He={cursor:void 0,error:null,loading:!1,notConfigured:!1,rows:null},Je=(l,e)=>{switch(e.type){case"append":return{...l,cursor:e.cursor,error:null,loading:!1,rows:[...l.rows??[],...e.rows]};case"failed":return{cursor:void 0,error:e.message,loading:!1,notConfigured:!1,rows:null};case"loaded":return{cursor:e.cursor,error:null,loading:!1,notConfigured:!1,rows:e.rows};case"loading":return{...l,error:null,loading:!0,notConfigured:!1};case"notConfigured":return{cursor:void 0,error:null,loading:!1,notConfigured:!0,rows:null};case"pageFailed":return{...l,error:e.message,loading:!1};default:return l}},Xe=l=>{const e=M(33),{row:r}=l;let s;e[0]!==r.fields?(s=Q(r.fields),e[0]=r.fields,e[1]=s):s=e[1];const n=s,a=`lg-archive-row-${String(r.ts)}`;let i;e[2]!==r.ts?(i=new Date(r.ts).toLocaleString(),e[2]=r.ts,e[3]=i):i=e[3];let u;e[4]!==i?(u=t(T,{className:"tabular-nums whitespace-nowrap text-xs text-muted-foreground",children:i}),e[4]=i,e[5]=u):u=e[5];const v=ge[r.level];let c;e[6]!==r.level||e[7]!==v?(c=t(T,{children:t(Y,{variant:v,children:r.level})}),e[6]=r.level,e[7]=v,e[8]=c):c=e[8];let d;e[9]!==r.functionPath?(d=t(T,{className:"font-mono text-xs",children:r.functionPath}),e[9]=r.functionPath,e[10]=d):d=e[10];let b;e[11]!==r.message?(b=t("div",{className:"truncate",title:r.message,children:r.message}),e[11]=r.message,e[12]=b):b=e[12];let f;e[13]!==n?(f=n!==""&&t("div",{className:"truncate font-mono text-[11px] text-muted-foreground",title:n,children:n}),e[13]=n,e[14]=f):f=e[14];let m;e[15]!==b||e[16]!==f?(m=w(T,{className:"max-w-md",children:[b,f]}),e[15]=b,e[16]=f,e[17]=m):m=e[17];const h=r.traceId??"—";let p;e[18]!==h?(p=t(T,{className:"font-mono text-[11px] text-muted-foreground",children:h}),e[18]=h,e[19]=p):p=e[19];const L=r.shardKey??"—";let g;e[20]!==L?(g=t(T,{className:"font-mono text-[11px] text-muted-foreground",children:L}),e[20]=L,e[21]=g):g=e[21];const x=r.userId??"—";let y;e[22]!==x?(y=t(T,{className:"font-mono text-[11px] text-muted-foreground",children:x}),e[22]=x,e[23]=y):y=e[23];let C;return e[24]!==m||e[25]!==p||e[26]!==g||e[27]!==y||e[28]!==a||e[29]!==u||e[30]!==c||e[31]!==d?(C=w(me,{"data-testid":a,children:[u,c,d,m,p,g,y]}),e[24]=m,e[25]=p,e[26]=g,e[27]=y,e[28]=a,e[29]=u,e[30]=c,e[31]=d,e[32]=C):C=e[32],C},Ze=({shardKey:l})=>{const e=Ve(),r=ce(),[s,n]=$(""),[a,i]=$(""),[u,v]=$(""),[{cursor:c,error:d,loading:b,notConfigured:f,rows:m},h]=Me(Je,He),p=G(s.trim(),400),L=G(a.trim(),400),g={...p===""?{}:{functionPathPrefix:p},...u===""?{}:{minLevel:u},...l===""?{}:{shardKey:l},...L===""?{}:{userId:L}},x=JSON.stringify(g),y=ie(x);de(()=>{const N={cancelled:!1};return y.current=x,ae((async()=>{h({type:"loading"});try{const k=await e.queryLogArchive(g);N.cancelled||h({cursor:k.nextCursor,rows:k.rows,type:"loaded"})}catch(k){N.cancelled||h(We(k)===Ye?{type:"notConfigured"}:{message:le(k),type:"failed"})}})()),()=>{N.cancelled=!0}},[e,x]);const C=async()=>{if(c===void 0)return;const N=x;h({type:"loading"});try{const k=await e.queryLogArchive({...g,cursor:c});y.current===N&&h({cursor:k.nextCursor,rows:k.rows,type:"append"})}catch(k){y.current===N&&h({message:le(k),type:"pageFailed"})}},R=N=>{n(N.target.value)},S=N=>{i(N.target.value)},I=N=>{v(N.target.value)},E=()=>{ae(C())};return f?t(B,{action:t("a",{className:"text-sm text-primary underline-offset-4 hover:underline",href:ue,rel:"noreferrer",target:"_blank",children:r("Open in Cloudflare")}),description:r("Wire pipelineLogSink to a Cloudflare Pipeline → R2 Data Catalog table and set R2_SQL_ACCOUNT_ID, R2_SQL_TOKEN, R2_SQL_BUCKET to browse the durable log archive here."),testId:"lg-archive-not-configured",title:r("Log archive not configured")}):w("div",{className:"flex flex-col gap-4","data-testid":"lg-archive",children:[w("div",{className:"flex flex-wrap items-center gap-2",children:[t(_,{"aria-label":r("Function path prefix"),className:"h-8 w-48","data-testid":"lg-archive-path",onChange:R,placeholder:r("function path…"),value:s}),t(_,{"aria-label":r("User id"),className:"h-8 w-40","data-testid":"lg-archive-user",onChange:S,placeholder:r("user id…"),value:a}),w("select",{"aria-label":r("Minimum level"),className:"h-8 rounded-md border border-border bg-background px-2 text-sm","data-testid":"lg-archive-min-level",onChange:I,value:u,children:[t("option",{value:"",children:r("min level")}),he.map(N=>t("option",{value:N,children:N},N))]})]}),d!==null&&t("p",{className:"text-sm text-destructive","data-testid":"lg-archive-error",role:"alert",children:d}),b&&m===null&&d===null&&t("p",{className:"text-sm text-muted-foreground","data-testid":"lg-archive-loading",children:r("Loading…")}),m!==null&&m.length===0&&t(B,{description:r("No archived logs match these filters. The durable archive fills as pipelineLogSink flushes records to R2."),testId:"lg-archive-empty",title:r("No archived logs.")}),m!==null&&m.length>0&&t("div",{className:"overflow-hidden rounded-xl border border-border shadow-xs",children:w(je,{"data-testid":"lg-archive-table",children:[t(Be,{children:w(me,{children:[t(P,{children:r("Time")}),t(P,{children:r("Level")}),t(P,{children:r("Function")}),t(P,{children:r("Message")}),t(P,{children:r("Trace")}),t(P,{children:r("Shard")}),t(P,{children:r("User")})]})}),t(Ge,{children:m.map((N,k)=>t(Xe,{row:N},`${String(N.ts)}-${String(k)}`))})]})}),c!==void 0&&t("div",{children:t(ze,{"data-testid":"lg-archive-more",disabled:b,onClick:E,size:"sm",variant:"outline",children:r(b?"Loading…":"Load more")})})]})},W=400,er=36,rr={height:W,overflow:"auto"},fe={left:0,position:"absolute",top:0,width:"100%"},tr={error:"destructive",ok:"secondary"},ar=l=>{const e=M(26),{entry:r,index:s,measureRef:n,start:a}=l,i=`translateY(${String(a)}px)`;let u;e[0]!==i?(u={...fe,transform:i},e[0]=i,e[1]=u):u=e[1];const v=u;let c;e[2]!==r.fields?(c=Q(r.fields),e[2]=r.fields,e[3]=c):c=e[3];const d=c;let b;e[4]!==r.timestamp?(b=new Date(r.timestamp).toLocaleString(),e[4]=r.timestamp,e[5]=b):b=e[5];let f;e[6]!==b?(f=t("span",{className:"w-44 shrink-0 tabular-nums text-muted-foreground",role:"gridcell",children:b}),e[6]=b,e[7]=f):f=e[7];const m=ge[r.level];let h;e[8]!==r.level||e[9]!==m?(h=t("span",{className:"w-20 shrink-0",role:"gridcell",children:t(Y,{variant:m,children:r.level})}),e[8]=r.level,e[9]=m,e[10]=h):h=e[10];const p=r.functionPath??"—";let L;e[11]!==p?(L=t("span",{className:"w-48 shrink-0 truncate text-muted-foreground",role:"gridcell",children:p}),e[11]=p,e[12]=L):L=e[12];let g;e[13]!==d?(g=d===""?null:t("span",{className:"ml-2 text-muted-foreground","data-testid":"lg-fields",children:d}),e[13]=d,e[14]=g):g=e[14];let x;e[15]!==r.message||e[16]!==g?(x=w("span",{className:"flex-1 truncate",role:"gridcell",children:[r.message,g]}),e[15]=r.message,e[16]=g,e[17]=x):x=e[17];let y;return e[18]!==s||e[19]!==n||e[20]!==v||e[21]!==x||e[22]!==f||e[23]!==h||e[24]!==L?(y=w("div",{className:"flex items-center border-b border-border px-3 py-1.5 font-mono text-xs hover:bg-muted/50","data-index":s,"data-testid":"lg-row",ref:n,role:"row",style:v,children:[f,h,L,x]}),e[18]=s,e[19]=n,e[20]=v,e[21]=x,e[22]=f,e[23]=h,e[24]=L,e[25]=y):y=e[25],y},oe=l=>l.length===0?"—":l.join(", "),lr=l=>{const e=M(37),{entry:r,index:s,measureRef:n,start:a}=l,i=`translateY(${String(a)}px)`;let u;e[0]!==i?(u={...fe,transform:i},e[0]=i,e[1]=u):u=e[1];const v=u;let c;e[2]!==r.ts?(c=new Date(r.ts).toLocaleString(),e[2]=r.ts,e[3]=c):c=e[3];let d;e[4]!==c?(d=t("span",{className:"w-40 shrink-0 tabular-nums text-muted-foreground",role:"gridcell",children:c}),e[4]=c,e[5]=d):d=e[5];const b=tr[r.outcome];let f;e[6]!==r.outcome||e[7]!==b?(f=t("span",{className:"w-16 shrink-0",role:"gridcell",children:t(Y,{variant:b,children:r.outcome})}),e[6]=r.outcome,e[7]=b,e[8]=f):f=e[8];let m;e[9]!==r.functionPath?(m=t("span",{className:"w-44 shrink-0 truncate",role:"gridcell",title:r.functionPath,children:r.functionPath}),e[9]=r.functionPath,e[10]=m):m=e[10];const h=r.shardKey??"—";let p;e[11]!==h?(p=t("span",{className:"w-24 shrink-0 truncate text-muted-foreground",role:"gridcell",children:h}),e[11]=h,e[12]=p):p=e[12];const L=r.userId??"—";let g;e[13]!==L?(g=t("span",{className:"w-24 shrink-0 truncate text-muted-foreground",role:"gridcell",children:L}),e[13]=L,e[14]=g):g=e[14];let x;e[15]!==r.durationMs?(x=Math.round(r.durationMs),e[15]=r.durationMs,e[16]=x):x=e[16];const y=`${String(x)}ms`;let C;e[17]!==y?(C=t("span",{className:"w-16 shrink-0 tabular-nums text-muted-foreground",role:"gridcell",children:y}),e[17]=y,e[18]=C):C=e[18];let R;e[19]!==r.errorMessage||e[20]!==r.outcome||e[21]!==r.tablesRead||e[22]!==r.tablesWritten?(R=r.outcome==="error"&&r.errorMessage!==void 0?r.errorMessage:`r:${oe(r.tablesRead)} · w:${oe(r.tablesWritten)}`,e[19]=r.errorMessage,e[20]=r.outcome,e[21]=r.tablesRead,e[22]=r.tablesWritten,e[23]=R):R=e[23];let S;e[24]!==R?(S=t("span",{className:"flex-1 truncate text-muted-foreground",role:"gridcell",children:R}),e[24]=R,e[25]=S):S=e[25];let I;return e[26]!==s||e[27]!==n||e[28]!==v||e[29]!==g||e[30]!==C||e[31]!==S||e[32]!==d||e[33]!==f||e[34]!==m||e[35]!==p?(I=w("div",{className:"flex items-center border-b border-border px-3 py-1.5 font-mono text-xs hover:bg-muted/50","data-index":s,"data-testid":"lg-req-row",ref:n,role:"row",style:v,children:[d,f,m,p,g,C,S]}),e[26]=s,e[27]=n,e[28]=v,e[29]=g,e[30]=C,e[31]=S,e[32]=d,e[33]=f,e[34]=m,e[35]=p,e[36]=I):I=e[36],I},se=l=>{const{entries:e}=l??{};return Array.isArray(e)?e:[]},or=l=>{const e={};return l.functionPathPrefix.trim()!==""&&(e.functionPathPrefix=l.functionPathPrefix.trim()),l.userId.trim()!==""&&(e.userId=l.userId.trim()),l.tableTouched.trim()!==""&&(e.tableTouched=l.tableTouched.trim()),(l.outcome==="ok"||l.outcome==="error")&&(e.outcome=l.outcome),e},pe=he,sr={"5m":300*1e3,"15m":900*1e3,"1h":3600*1e3},nr=(l,e)=>{const r=e.search.trim().toLowerCase(),s=e.path.trim().toLowerCase(),n=e.range==="all"?Number.NEGATIVE_INFINITY:e.now-sr[e.range];return l.filter(a=>e.levels.size>0&&!e.levels.has(a.level)||a.timestamp<n||s!==""&&!(a.functionPath??"").toLowerCase().includes(s)?!1:r===""||a.message.toLowerCase().includes(r)||Q(a.fields).toLowerCase().includes(r))},ir="—",dr=l=>{const e=new Map,r=new Map;for(const a of l){e.set(a.level,(e.get(a.level)??0)+1);const i=a.functionPath??ir;r.set(i,(r.get(i)??0)+1)}const s=pe.filter(a=>e.has(a)).map(a=>({count:e.get(a)??0,key:a})),n=[...r.entries()].map(([a,i])=>({count:i,key:a})).toSorted((a,i)=>i.count===a.count?a.key.localeCompare(i.key):i.count-a.count);return{byLevel:s,byPath:n,total:l.length}},cr=l=>{const e=M(11),{level:r,onToggle:s,selected:n}=l;let a;e[0]!==r||e[1]!==s?(a=()=>{s(r)},e[0]=r,e[1]=s,e[2]=a):a=e[2];const i=a,u=n?"border-border bg-muted font-medium":"border-input text-muted-foreground";let v;e[3]!==u?(v=q("rounded-md border px-2 py-1 text-xs",u),e[3]=u,e[4]=v):v=e[4];const c=`logs-level-${r}`;let d;return e[5]!==r||e[6]!==i||e[7]!==n||e[8]!==v||e[9]!==c?(d=t("button",{"aria-pressed":n,className:v,"data-testid":c,onClick:i,type:"button",children:r}),e[5]=r,e[6]=i,e[7]=n,e[8]=v,e[9]=c,e[10]=d):d=e[10],d},ne=l=>{const e=M(7),{bucket:r}=l;let s;e[0]!==r.key?(s=t("span",{className:"truncate text-muted-foreground",role:"gridcell",children:r.key}),e[0]=r.key,e[1]=s):s=e[1];let n;e[2]!==r.count?(n=t("span",{className:"shrink-0 tabular-nums",role:"gridcell",children:r.count}),e[2]=r.count,e[3]=n):n=e[3];let a;return e[4]!==s||e[5]!==n?(a=w("div",{className:"flex items-center justify-between gap-4 px-3 py-1 font-mono text-xs","data-testid":"logs-summary-row",role:"row",children:[s,n]}),e[4]=s,e[5]=n,e[6]=a):a=e[6],a},qr=({initialShardKey:l})=>{const e=ce(),[r,s]=$("requests"),[n,a]=$(l??""),[i,u]=$(""),[v,c]=$(()=>new Set),[d,b]=$(""),[f,m]=$("all"),[h,p]=$(!1),[L,g]=$(""),[x,y]=$(""),[C,R]=$(""),[S,I]=$("all"),E=G(n.trim(),400),N=or({functionPathPrefix:L,outcome:S,tableTouched:C,userId:x}),k=re(te.getRequestLog,N,{enabled:r==="requests",live:!0,shardKey:E}),H=re(te.getLogs,{},{enabled:r==="errors",live:!0,shardKey:E}),D=r==="requests"?k:H,{error:J,errorSource:ve,isLoading:X,liveError:be}=D,xe=se(H.data),Z=se(k.data);de(()=>{D.data!==void 0&&Ke(E)},[D.data,E]);const K=nr(xe,{levels:v,now:Date.now(),path:d,range:f,search:i}),U=dr(K),V=r==="requests"?Z.length:K.length,z=r==="errors"&&h,A=Ae(()=>J!==null?"error":V===0?X?z?"summary":"list":"empty":z?"summary":"list",[V,X,J,z]),ee=ie(null),O=qe({count:V,estimateSize:()=>er,getScrollElement:()=>ee.current,initialRect:{height:W,width:800},observeElementRect:(o,j)=>Ue(o,j,W),overscan:8}),we=O.getVirtualItems(),ye={height:O.getTotalSize(),position:"relative",width:"100%"},Ne=o=>{u(o.target.value)},Le=o=>{c(j=>{const F=new Set(j);return F.has(o)?F.delete(o):F.add(o),F})},Ce=o=>{b(o.target.value)},ke=o=>{m(o.target.value)},$e=()=>{p(o=>!o)},Se=o=>{g(o.target.value)},Re=o=>{y(o.target.value)},Ie=o=>{R(o.target.value)},Ee=o=>{I(o.target.value)},Pe=()=>{s("requests"),p(!1)},Te=()=>{s("errors"),p(!1)},_e=()=>{s("archive"),p(!1)};return w("div",{className:"flex flex-col gap-4","data-testid":"lunora-logs",children:[w("div",{className:"flex flex-wrap items-center gap-2",children:[w("div",{className:"inline-flex overflow-hidden rounded-lg border border-border",role:"tablist",children:[t("button",{"aria-selected":r==="requests",className:q("px-3 py-1 text-sm",r==="requests"?"bg-muted font-medium":"text-muted-foreground"),"data-testid":"lg-view-requests",onClick:Pe,role:"tab",type:"button",children:e("Requests")}),t("button",{"aria-selected":r==="errors",className:q("px-3 py-1 text-sm",r==="errors"?"bg-muted font-medium":"text-muted-foreground"),"data-testid":"lg-view-errors",onClick:Te,role:"tab",type:"button",children:e("Errors")}),t("button",{"aria-selected":r==="archive",className:q("px-3 py-1 text-sm",r==="archive"?"bg-muted font-medium":"text-muted-foreground"),"data-testid":"lg-view-archive",onClick:_e,role:"tab",type:"button",children:e("Archive")})]}),t(De,{onChange:a,testId:"lg-shard-input",value:n}),r!=="archive"&&t(Fe,{message:be,prefix:"lg"}),t("a",{className:"text-sm text-primary underline-offset-4 hover:underline","data-testid":"lg-cf-link",href:ue,rel:"noreferrer",target:"_blank",children:e("Open in Cloudflare")})]}),r==="errors"&&w("div",{className:"flex flex-wrap items-center gap-2",children:[t(_,{"aria-label":e("Search messages"),className:"h-8 w-48","data-testid":"lg-search",onChange:Ne,placeholder:e("search message"),value:i}),t(_,{"aria-label":e("Function path"),className:"h-8 w-40","data-testid":"logs-path-filter",onChange:Ce,placeholder:e("filter path"),value:d}),t("div",{"aria-label":e("Level filter"),className:"inline-flex items-center gap-1","data-testid":"logs-level-filter",role:"group",children:pe.map(o=>t(cr,{level:o,onToggle:Le,selected:v.has(o)},o))}),w("select",{"aria-label":e("Time range"),className:"h-8 rounded-md border border-input bg-transparent px-2 text-sm shadow-xs focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-none","data-testid":"logs-time-range",onChange:ke,value:f,children:[t("option",{value:"all",children:e("All time")}),t("option",{value:"5m",children:e("Last 5m")}),t("option",{value:"15m",children:e("Last 15m")}),t("option",{value:"1h",children:e("Last hour")})]}),t("button",{"aria-pressed":h,className:q("h-8 rounded-md border px-3 text-sm",h?"border-border bg-muted font-medium":"border-input text-muted-foreground"),"data-testid":"logs-summary-toggle",onClick:$e,type:"button",children:e(h?"List":"Summary")})]}),r==="requests"&&w("div",{className:"flex flex-wrap items-center gap-2",children:[t(_,{"aria-label":e("Function path"),className:"h-8 w-44","data-testid":"lg-req-path",onChange:Se,placeholder:e("file:function"),value:L}),t(_,{"aria-label":e("User id"),className:"h-8 w-32","data-testid":"lg-req-user",onChange:Re,placeholder:e("userId"),value:x}),t(_,{"aria-label":e("Table touched"),className:"h-8 w-32","data-testid":"lg-req-table",onChange:Ie,placeholder:e("table"),value:C}),w("select",{"aria-label":e("Outcome filter"),className:"h-8 rounded-md border border-input bg-transparent px-2 text-sm shadow-xs focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-none","data-testid":"lg-req-outcome",onChange:Ee,value:S,children:[t("option",{value:"all",children:e("all")}),t("option",{value:"ok",children:e("ok")}),t("option",{value:"error",children:e("error")})]})]}),r==="archive"?t(Ze,{shardKey:E}):w(Qe,{children:[A==="error"&&t(Oe,{error:ve,testId:"lg-error"}),A==="empty"&&t(B,{description:e("Function and request logs for this shard show up here as your app handles traffic."),icon:t("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:t("path",{d:"M4 5h16M4 12h16M4 19h10"})}),testId:"lg-empty",title:e("No logs.")}),A==="summary"&&w("div",{className:"flex flex-col gap-4 rounded-xl border border-border bg-card p-4 shadow-xs","data-testid":"logs-summary",children:[t("p",{className:"text-xs text-muted-foreground","data-testid":"logs-summary-total",children:e("{count} entries",{count:U.total})}),w("div",{children:[t("h4",{className:"mb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:e("By level")}),t("div",{className:"overflow-hidden rounded-lg border border-border","data-testid":"logs-summary-levels",role:"grid",children:U.byLevel.map(o=>t(ne,{bucket:o},o.key))})]}),w("div",{children:[t("h4",{className:"mb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:e("By function")}),t("div",{className:"overflow-hidden rounded-lg border border-border","data-testid":"logs-summary-paths",role:"grid",children:U.byPath.map(o=>t(ne,{bucket:o},o.key))})]})]}),A==="list"&&t("div",{className:"rounded-xl border border-border shadow-xs","data-testid":"lg-scroll",ref:ee,style:rr,children:t("div",{"aria-label":e("Recent logs"),"data-testid":"lg-table",role:"grid",style:ye,children:we.map(o=>r==="requests"?t(lr,{entry:Z[o.index],index:o.index,measureRef:O.measureElement,start:o.start},o.key):t(ar,{entry:K[o.index],index:o.index,measureRef:O.measureElement,start:o.start},o.key))})})]})]})};export{qr as LogsPanel,nr as filterLogs,dr as summarizeLogs};
@@ -1,2 +1,2 @@
1
- import{useLunora as G}from"@lunora/react";import{useState as p,useMemo as b}from"react";import{E as J}from"../packem_shared/error-alert-B59DnrDI.js";import{g as Q}from"../packem_shared/badge-BbuuAio7.js";import{u as m}from"../packem_shared/button-BkCrNcAs.js";import{E as V}from"../packem_shared/empty-state-Cg7t_8qu.js";import{u as X}from"../packem_shared/input-JHu63lTv.js";import{p as Y}from"../packem_shared/scroll-area-DTEq6Jec.js";import{Separator as Z}from"@base-ui/react/separator";import{c as ee}from"../packem_shared/utils-bhneXptQ.js";import{jsx as e,jsxs as d,Fragment as te}from"react/jsx-runtime";import{K as ae}from"../packem_shared/use-admin-query-Di3fLE8H.js";import{useAutoRefresh as re}from"../packem_shared/DEFAULT_AUTO_REFRESH_MS-BCC8_4BQ.js";import{useT as ie}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as v}from"../packem_shared/ADMIN_FUNCTIONS-BYNSbBVE.js";import{i as j,f as T,g as le,c as M,e as z,a as A}from"../packem_shared/internal-AtZ4bTal.js";function de({className:r,orientation:u="horizontal",...a}){return e(Z,{"data-slot":"separator",orientation:u,className:ee("shrink-0 bg-border data-horizontal:h-px data-horizontal:w-full data-vertical:w-px data-vertical:self-stretch",r),...a})}const se=A(v.clearCapturedMail),oe=A(v.sendTestMail),ne=/https?:\/\/[^\s"'<>)]+/i,S=r=>r===void 0?void 0:ne.exec(r)?.[0],ce=r=>{if(r!==void 0)return S(r.html)??S(r.text)},me=`<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src data:; style-src 'unsafe-inline'; font-src data:">`,ue=r=>`${me}${r}`,f=r=>r===void 0?"":Array.isArray(r)?r.join(", "):r,ze=({limit:r=100})=>{const u=G(),a=ie(),{data:N,error:w,errorSource:L,isLoading:E,refetch:x}=ae(v.getCapturedMail,{limit:r}),[y,h]=p(null),[C,k]=p(null),[n,F]=p("html"),[g,O]=p(""),s=b(()=>N?.entries??[],[N]),$=w??y,H=w===null?y:L,I=async()=>{h(null);try{await u.query(se,{},M("")),k(null),x()}catch(t){h(z(t))}},_=async()=>{h(null);try{await u.query(oe,{},M("")),x()}catch(t){h(z(t))}};re(()=>{x()},!0);const q=()=>{T(I())},P=()=>{T(_())},D=t=>{O(t.currentTarget.value)},R=t=>{const{id:l}=t.currentTarget.dataset;l!==void 0&&k(l)},B=t=>{const l=t.currentTarget.dataset.tab;(l==="headers"||l==="html"||l==="text")&&F(l)},K=t=>a(t==="html"?"HTML":t==="text"?"Plain text":"Headers"),c=b(()=>{const t=g.trim().toLowerCase();return t===""?s:s.filter(l=>`${l.subject} ${f(l.to)}`.toLowerCase().includes(t))},[s,g]),i=b(()=>{if(c.length!==0)return c.find(t=>t.id===C)??c[0]},[c,C]),o=ce(i),U=()=>{o!==void 0&&le(o)},W=()=>{o!==void 0&&"window"in globalThis&&globalThis.window.open(o,"_blank","noopener")};return d("div",{className:"flex flex-col gap-4","data-testid":"mail-panel",children:[d("div",{className:"flex flex-wrap items-center gap-2",children:[e(m,{"data-testid":"mail-send-test",onClick:P,size:"sm",type:"button",variant:"outline",children:a("Send test")}),e(m,{"data-testid":"mail-clear",disabled:s.length===0,onClick:q,size:"sm",type:"button",variant:"outline",children:a("Clear inbox")}),s.length>0&&e(Q,{className:"ml-auto","data-testid":"mail-count",variant:"secondary",children:a("{count} messages",{count:s.length})})]}),$!==null&&e(J,{error:H,testId:"mail-error"}),$===null&&!E&&s.length===0&&e(V,{description:a("Email your app sends in dev is captured here — nothing is delivered."),icon:d("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:[e("path",{d:"M4 5h16v14H4z"}),e("path",{d:"m4 6 8 6 8-6"})]}),testId:"mail-empty",title:a("No captured email.")}),s.length>0&&d("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-[minmax(0,22rem)_1fr]","data-testid":"mail-reader",children:[d("div",{className:"flex flex-col gap-2",children:[e(X,{"aria-label":a("Search messages"),"data-testid":"mail-search",onChange:D,placeholder:a("Filter messages"),type:"search",value:g}),e(Y,{className:"max-h-[32rem] rounded-xl border border-border bg-card shadow-xs","data-testid":"mail-list",children:e("ul",{className:"divide-y",children:c.map(t=>{const l=t.id===i?.id;return e("li",{children:d("button",{className:`flex w-full flex-col items-start gap-0.5 px-3 py-2 text-left text-sm hover:bg-muted/60 ${l?"bg-muted":""}`,"data-active":l,"data-id":t.id,"data-testid":"mail-list-item",onClick:R,type:"button",children:[e("span",{className:"w-full truncate font-medium",children:t.subject||a("(no subject)")}),e("span",{className:"w-full truncate text-xs text-muted-foreground",children:f(t.to)}),e("span",{className:"text-xs text-muted-foreground tabular-nums",children:j(t.capturedAt,"—")})]})},t.id)})})})]}),i!==void 0&&d("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:[d("div",{className:"flex flex-col gap-1",children:[e("h2",{className:"truncate text-base font-semibold","data-testid":"mail-subject",children:i.subject||a("(no subject)")}),d("dl",{className:"grid grid-cols-[auto_1fr] gap-x-3 gap-y-0.5 text-xs text-muted-foreground",children:[e("dt",{children:a("From")}),e("dd",{className:"truncate font-mono",children:i.from??"—"}),e("dt",{children:a("To")}),e("dd",{className:"truncate font-mono",children:f(i.to)}),i.cc!==void 0&&i.cc.length>0&&d(te,{children:[e("dt",{children:a("Cc")}),e("dd",{className:"truncate font-mono",children:f(i.cc)})]}),e("dt",{children:a("Sent")}),e("dd",{className:"tabular-nums",children:j(i.capturedAt,"—")})]})]}),d("div",{className:"flex flex-wrap items-center gap-2","data-testid":"mail-actions",children:[e(m,{"data-testid":"mail-copy-link",disabled:o===void 0,onClick:U,size:"sm",type:"button",variant:"outline",children:a("Copy link")}),e(m,{"data-testid":"mail-open-link",disabled:o===void 0,onClick:W,size:"sm",type:"button",variant:"outline",children:a("Open in new tab")})]}),e(de,{}),e("div",{className:"flex items-center gap-1","data-testid":"mail-tabs",role:"tablist",children:["html","text","headers"].map(t=>e(m,{"aria-selected":n===t,"data-tab":t,"data-testid":`mail-tab-${t}`,onClick:B,role:"tab",size:"sm",type:"button",variant:n===t?"secondary":"ghost",children:K(t)},t))}),d("div",{className:"min-h-[12rem]",children:[n==="html"&&(i.html===void 0?e("p",{className:"text-sm text-muted-foreground",children:a("No HTML body.")}):e("iframe",{className:"h-[24rem] w-full rounded-md border bg-white","data-testid":"mail-preview-html",sandbox:"",srcDoc:ue(i.html),title:a("Email preview")})),n==="text"&&(i.text===void 0?e("p",{className:"text-sm text-muted-foreground",children:a("No text body.")}):e("pre",{className:"overflow-auto whitespace-pre-wrap rounded-md border bg-muted/30 p-3 text-xs","data-testid":"mail-preview-text",children:i.text})),n==="headers"&&(i.headers===void 0||Object.keys(i.headers).length===0?e("p",{className:"text-sm text-muted-foreground",children:a("No headers.")}):e("pre",{className:"overflow-auto whitespace-pre-wrap rounded-md border bg-muted/30 p-3 text-xs","data-testid":"mail-preview-headers",children:Object.entries(i.headers).map(([t,l])=>`${t}: ${l}`).join(`
1
+ import{useLunora as G}from"@lunora/react";import{useState as p,useMemo as b}from"react";import{E as J}from"../packem_shared/error-alert-B59DnrDI.js";import{g as Q}from"../packem_shared/badge-BbuuAio7.js";import{u as m}from"../packem_shared/button-BkCrNcAs.js";import{E as V}from"../packem_shared/empty-state-Cg7t_8qu.js";import{u as X}from"../packem_shared/input-JHu63lTv.js";import{p as Y}from"../packem_shared/scroll-area-DTEq6Jec.js";import{Separator as Z}from"@base-ui/react/separator";import{c as ee}from"../packem_shared/utils-bhneXptQ.js";import{jsx as e,jsxs as d,Fragment as te}from"react/jsx-runtime";import{K as ae}from"../packem_shared/use-admin-query-Di3fLE8H.js";import{useAutoRefresh as re}from"../packem_shared/DEFAULT_AUTO_REFRESH_MS-BCC8_4BQ.js";import{useT as ie}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as v}from"../packem_shared/ADMIN_FUNCTIONS-CpgIo9pj.js";import{i as j,f as T,g as le,c as M,e as z,a as A}from"../packem_shared/internal-AtZ4bTal.js";function de({className:r,orientation:u="horizontal",...a}){return e(Z,{"data-slot":"separator",orientation:u,className:ee("shrink-0 bg-border data-horizontal:h-px data-horizontal:w-full data-vertical:w-px data-vertical:self-stretch",r),...a})}const se=A(v.clearCapturedMail),oe=A(v.sendTestMail),ne=/https?:\/\/[^\s"'<>)]+/i,S=r=>r===void 0?void 0:ne.exec(r)?.[0],ce=r=>{if(r!==void 0)return S(r.html)??S(r.text)},me=`<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src data:; style-src 'unsafe-inline'; font-src data:">`,ue=r=>`${me}${r}`,f=r=>r===void 0?"":Array.isArray(r)?r.join(", "):r,ze=({limit:r=100})=>{const u=G(),a=ie(),{data:N,error:w,errorSource:L,isLoading:E,refetch:x}=ae(v.getCapturedMail,{limit:r}),[y,h]=p(null),[C,k]=p(null),[n,F]=p("html"),[g,O]=p(""),s=b(()=>N?.entries??[],[N]),$=w??y,H=w===null?y:L,I=async()=>{h(null);try{await u.query(se,{},M("")),k(null),x()}catch(t){h(z(t))}},_=async()=>{h(null);try{await u.query(oe,{},M("")),x()}catch(t){h(z(t))}};re(()=>{x()},!0);const q=()=>{T(I())},P=()=>{T(_())},D=t=>{O(t.currentTarget.value)},R=t=>{const{id:l}=t.currentTarget.dataset;l!==void 0&&k(l)},B=t=>{const l=t.currentTarget.dataset.tab;(l==="headers"||l==="html"||l==="text")&&F(l)},K=t=>a(t==="html"?"HTML":t==="text"?"Plain text":"Headers"),c=b(()=>{const t=g.trim().toLowerCase();return t===""?s:s.filter(l=>`${l.subject} ${f(l.to)}`.toLowerCase().includes(t))},[s,g]),i=b(()=>{if(c.length!==0)return c.find(t=>t.id===C)??c[0]},[c,C]),o=ce(i),U=()=>{o!==void 0&&le(o)},W=()=>{o!==void 0&&"window"in globalThis&&globalThis.window.open(o,"_blank","noopener")};return d("div",{className:"flex flex-col gap-4","data-testid":"mail-panel",children:[d("div",{className:"flex flex-wrap items-center gap-2",children:[e(m,{"data-testid":"mail-send-test",onClick:P,size:"sm",type:"button",variant:"outline",children:a("Send test")}),e(m,{"data-testid":"mail-clear",disabled:s.length===0,onClick:q,size:"sm",type:"button",variant:"outline",children:a("Clear inbox")}),s.length>0&&e(Q,{className:"ml-auto","data-testid":"mail-count",variant:"secondary",children:a("{count} messages",{count:s.length})})]}),$!==null&&e(J,{error:H,testId:"mail-error"}),$===null&&!E&&s.length===0&&e(V,{description:a("Email your app sends in dev is captured here — nothing is delivered."),icon:d("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:[e("path",{d:"M4 5h16v14H4z"}),e("path",{d:"m4 6 8 6 8-6"})]}),testId:"mail-empty",title:a("No captured email.")}),s.length>0&&d("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-[minmax(0,22rem)_1fr]","data-testid":"mail-reader",children:[d("div",{className:"flex flex-col gap-2",children:[e(X,{"aria-label":a("Search messages"),"data-testid":"mail-search",onChange:D,placeholder:a("Filter messages"),type:"search",value:g}),e(Y,{className:"max-h-[32rem] rounded-xl border border-border bg-card shadow-xs","data-testid":"mail-list",children:e("ul",{className:"divide-y",children:c.map(t=>{const l=t.id===i?.id;return e("li",{children:d("button",{className:`flex w-full flex-col items-start gap-0.5 px-3 py-2 text-left text-sm hover:bg-muted/60 ${l?"bg-muted":""}`,"data-active":l,"data-id":t.id,"data-testid":"mail-list-item",onClick:R,type:"button",children:[e("span",{className:"w-full truncate font-medium",children:t.subject||a("(no subject)")}),e("span",{className:"w-full truncate text-xs text-muted-foreground",children:f(t.to)}),e("span",{className:"text-xs text-muted-foreground tabular-nums",children:j(t.capturedAt,"—")})]})},t.id)})})})]}),i!==void 0&&d("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:[d("div",{className:"flex flex-col gap-1",children:[e("h2",{className:"truncate text-base font-semibold","data-testid":"mail-subject",children:i.subject||a("(no subject)")}),d("dl",{className:"grid grid-cols-[auto_1fr] gap-x-3 gap-y-0.5 text-xs text-muted-foreground",children:[e("dt",{children:a("From")}),e("dd",{className:"truncate font-mono",children:i.from??"—"}),e("dt",{children:a("To")}),e("dd",{className:"truncate font-mono",children:f(i.to)}),i.cc!==void 0&&i.cc.length>0&&d(te,{children:[e("dt",{children:a("Cc")}),e("dd",{className:"truncate font-mono",children:f(i.cc)})]}),e("dt",{children:a("Sent")}),e("dd",{className:"tabular-nums",children:j(i.capturedAt,"—")})]})]}),d("div",{className:"flex flex-wrap items-center gap-2","data-testid":"mail-actions",children:[e(m,{"data-testid":"mail-copy-link",disabled:o===void 0,onClick:U,size:"sm",type:"button",variant:"outline",children:a("Copy link")}),e(m,{"data-testid":"mail-open-link",disabled:o===void 0,onClick:W,size:"sm",type:"button",variant:"outline",children:a("Open in new tab")})]}),e(de,{}),e("div",{className:"flex items-center gap-1","data-testid":"mail-tabs",role:"tablist",children:["html","text","headers"].map(t=>e(m,{"aria-selected":n===t,"data-tab":t,"data-testid":`mail-tab-${t}`,onClick:B,role:"tab",size:"sm",type:"button",variant:n===t?"secondary":"ghost",children:K(t)},t))}),d("div",{className:"min-h-[12rem]",children:[n==="html"&&(i.html===void 0?e("p",{className:"text-sm text-muted-foreground",children:a("No HTML body.")}):e("iframe",{className:"h-[24rem] w-full rounded-md border bg-white","data-testid":"mail-preview-html",sandbox:"",srcDoc:ue(i.html),title:a("Email preview")})),n==="text"&&(i.text===void 0?e("p",{className:"text-sm text-muted-foreground",children:a("No text body.")}):e("pre",{className:"overflow-auto whitespace-pre-wrap rounded-md border bg-muted/30 p-3 text-xs","data-testid":"mail-preview-text",children:i.text})),n==="headers"&&(i.headers===void 0||Object.keys(i.headers).length===0?e("p",{className:"text-sm text-muted-foreground",children:a("No headers.")}):e("pre",{className:"overflow-auto whitespace-pre-wrap rounded-md border bg-muted/30 p-3 text-xs","data-testid":"mail-preview-headers",children:Object.entries(i.headers).map(([t,l])=>`${t}: ${l}`).join(`
2
2
  `)}))]})]})]})]})};export{ze as MailPanel};
@@ -1 +1 @@
1
- import{c as Fe}from"react/compiler-runtime";import{useLunora as lt}from"@lunora/react";import{useNavigate as st}from"@tanstack/react-router";import{useState as ge,useRef as Ke,useEffect as Be,useMemo as nt}from"react";import{L as it}from"../packem_shared/live-status-CGW2JHf_.js";import{ShardInput as ot}from"../packem_shared/ShardInput-BVn2iCU0.js";import{u as Ve}from"../packem_shared/button-BkCrNcAs.js";import{c as he,u as fe,n as Te,f as Re,m as ct}from"../packem_shared/card-CIDGUN6K.js";import{p as ie,d as Xe,m as Ae,u as ae,n as Ye,f as Ze}from"../packem_shared/table-DdJBrClo.js";import{K as He}from"../packem_shared/use-admin-query-Di3fLE8H.js";import dt from"../packem_shared/useDebounced-Ihdiid_k.js";import{useT as Ee}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as ze}from"../packem_shared/ADMIN_FUNCTIONS-BYNSbBVE.js";import{c as mt}from"../packem_shared/cf-links-gbDy51nR.js";import{l as ut,k as Pe,f as Ge,c as ht,e as gt,a as ft}from"../packem_shared/internal-AtZ4bTal.js";import{r as xt,l as pt}from"../packem_shared/shard-history-DMEW5VBE.js";import{w as bt}from"../packem_shared/trace-handoff-Dw7mwjxu.js";import{f as vt}from"../packem_shared/log-fields-CoL3hsIQ.js";import{g as et}from"../packem_shared/badge-BbuuAio7.js";import{S as tt}from"../packem_shared/sparkline-DtcZoU48.js";import{jsx as t,jsxs as n,Fragment as Ue}from"react/jsx-runtime";import{aggregateMetrics as Nt,computeLatencyPercentiles as yt,enrichQueryStats as $t,shardsToAggregate as wt}from"../packem_shared/aggregateMetrics-BNfajLa2.js";import{N as St,y as qt,k as De,_ as kt,w as _t}from"../packem_shared/select-Bul-DeII.js";const Mt=(s,e)=>s<e?-1:s>e?1:0,We=s=>{if(s===void 0)return"null";if(typeof s=="bigint")throw new TypeError("stableStringify: cannot use a bigint in a stable JSON cache key — pass it as a string, or use stableWireKey");if(s===null||typeof s!="object")return JSON.stringify(s);if(Array.isArray(s))return`[${s.map(p=>We(p)).join(",")}]`;const e=Object.getPrototypeOf(s);if(e!==null&&e!==Object.prototype){const p=s.constructor?.name??"value";throw new TypeError(`stableStringify: cannot use a ${p} in a stable JSON cache key — only plain objects, arrays, and JSON primitives are supported (wire-typed values key via stableWireKey)`)}const l=s,r=Object.keys(l).toSorted(Mt),a=[];for(const p of r){const b=l[p];b!==void 0&&a.push(`${JSON.stringify(p)}:${We(b)}`)}return`{${a.join(",")}}`},rt=(s,e,l)=>`${s}:${e}:${We(l??{})}`,at=(s,e)=>s==="gauge"?e.last:s==="histogram"?e.sum/Math.max(1,e.count):e.sum,It=(s,e)=>at(s,e),Ft=s=>at(s.kind,s),Je=s=>Number.isInteger(s)?s.toLocaleString():s.toLocaleString(void 0,{maximumFractionDigits:2}),Ct=s=>Array.isArray(s?.series)?s.series:[],Ot="FUNCTION_NOT_FOUND",Tt=s=>{const e=new Map;if(!Array.isArray(s?.series))return e;for(const l of s.series)e.set(rt(l.kind,l.name,l.attributes),l.points);return e},Rt={counter:"secondary",gauge:"default",histogram:"outline"},Dt=s=>{const e=Fe(18),{name:l,onOpenTrace:r,traceId:a}=s,p=Ee();if(a===void 0){let m;return e[0]===Symbol.for("react.memo_cache_sentinel")?(m=t("span",{className:"text-muted-foreground",children:"—"}),e[0]=m):m=e[0],m}let b;e[1]!==a?(b=a.slice(0,8),e[1]=a,e[2]=b):b=e[2];const f=b;if(r===void 0){const m=`mt-instrument-trace-${l}`;let N;return e[3]!==f||e[4]!==m||e[5]!==a?(N=t("span",{className:"text-muted-foreground","data-testid":m,title:a,children:f}),e[3]=f,e[4]=m,e[5]=a,e[6]=N):N=e[6],N}const h=`mt-instrument-trace-${l}`;let g;e[7]!==r||e[8]!==a?(g=()=>{r(a)},e[7]=r,e[8]=a,e[9]=g):g=e[9];let v;e[10]!==p||e[11]!==a?(v=p("Open the exemplar trace {trace}",{trace:a}),e[10]=p,e[11]=a,e[12]=v):v=e[12];let u;return e[13]!==f||e[14]!==h||e[15]!==g||e[16]!==v?(u=t("button",{className:"text-primary underline-offset-4 hover:underline","data-testid":h,onClick:g,title:v,type:"button",children:f}),e[13]=f,e[14]=h,e[15]=g,e[16]=v,e[17]=u):u=e[17],u},Lt=s=>{const e=Fe(105),{onOpenTrace:l,shardKey:r}=s,a=Ee();let p;e[0]===Symbol.for("react.memo_cache_sentinel")?(p={},e[0]=p):p=e[0];let b;e[1]!==r?(b={live:!0,shardKey:r},e[1]=r,e[2]=b):b=e[2];const{data:f,error:h,errorSource:g}=He(ze.getMetricSeries,p,b);let v;e[3]===Symbol.for("react.memo_cache_sentinel")?(v={},e[3]=v):v=e[3];let u;e[4]!==r?(u={live:!0,shardKey:r},e[4]=r,e[5]=u):u=e[5];const{data:m}=He(ze.getMetricHistory,v,u);let N,le,O,j,K,c,S,se,T,R,I,x,D;if(e[6]!==f||e[7]!==h||e[8]!==g||e[9]!==m||e[10]!==l||e[11]!==a){se=Symbol.for("react.early_return_sentinel");e:{const oe=Ct(f),de=ut(g)===Ot;if(h!==null&&!de){let o;e[25]!==a?(o=a("Instruments"),e[25]=a,e[26]=o):o=e[26];let F;e[27]!==o?(F=t("h3",{className:"text-sm font-semibold text-foreground",children:o}),e[27]=o,e[28]=F):F=e[28];let A;e[29]!==h||e[30]!==a?(A=a("Instruments unavailable: {error}",{error:h}),e[29]=h,e[30]=a,e[31]=A):A=e[31];let z;e[32]!==A?(z=t("span",{className:"text-xs text-muted-foreground","data-testid":"mt-instruments-error",role:"status",children:A}),e[32]=A,e[33]=z):z=e[33];let re;e[34]!==F||e[35]!==z?(re=n("section",{className:"flex flex-col gap-2","data-testid":"mt-instruments",children:[F,z]}),e[34]=F,e[35]=z,e[36]=re):re=e[36],se=re;break e}if(oe.length===0){se=null;break e}const me=Tt(m);let P;e[37]!==a?(P=o=>a(o==="counter"?"Counter":o==="gauge"?"Gauge":"Histogram"),e[37]=a,e[38]=P):P=e[38];const i=P;K="flex flex-col gap-2",c="mt-instruments";let k;e[39]!==a?(k=a("Instruments"),e[39]=a,e[40]=k):k=e[40],e[41]!==k?(S=t("h3",{className:"text-sm font-semibold text-foreground",children:k}),e[41]=k,e[42]=S):S=e[42],j=he,D="overflow-hidden py-0",O=fe,x="px-0",le=Ye,R="mt-instruments-table";let y;e[43]!==a?(y=a("name"),e[43]=a,e[44]=y):y=e[44];let w;e[45]!==y?(w=t(ie,{children:y}),e[45]=y,e[46]=w):w=e[46];let U;e[47]!==a?(U=a("kind"),e[47]=a,e[48]=U):U=e[48];let J;e[49]!==U?(J=t(ie,{children:U}),e[49]=U,e[50]=J):J=e[50];let Q;e[51]!==a?(Q=a("value"),e[51]=a,e[52]=Q):Q=e[52];let H;e[53]!==Q?(H=t(ie,{className:"text-right",children:Q}),e[53]=Q,e[54]=H):H=e[54];let W;e[55]!==a?(W=a("count"),e[55]=a,e[56]=W):W=e[56];let B;e[57]!==W?(B=t(ie,{className:"text-right",children:W}),e[57]=W,e[58]=B):B=e[58];let V;e[59]!==a?(V=a("range"),e[59]=a,e[60]=V):V=e[60];let G;e[61]!==V?(G=t(ie,{className:"text-right",children:V}),e[61]=V,e[62]=G):G=e[62];let X;e[63]!==a?(X=a("trend"),e[63]=a,e[64]=X):X=e[64];let Y;e[65]!==X?(Y=t(ie,{children:X}),e[65]=X,e[66]=Y):Y=e[66];let Z;e[67]!==a?(Z=a("trace"),e[67]=a,e[68]=Z):Z=e[68];let ee;e[69]!==Z?(ee=t(ie,{children:Z}),e[69]=Z,e[70]=ee):ee=e[70];let ce;e[71]!==a?(ce=a("dimensions"),e[71]=a,e[72]=ce):ce=e[72];let te;e[73]!==ce?(te=t(ie,{children:ce}),e[73]=ce,e[74]=te):te=e[74],e[75]!==w||e[76]!==J||e[77]!==H||e[78]!==B||e[79]!==G||e[80]!==Y||e[81]!==ee||e[82]!==te?(I=t(Xe,{children:n(Ae,{children:[w,J,H,B,G,Y,ee,te]})}),e[75]=w,e[76]=J,e[77]=H,e[78]=B,e[79]=G,e[80]=Y,e[81]=ee,e[82]=te,e[83]=I):I=e[83],N=Ze,T=oe.map(o=>{const F=vt(o.attributes),A=rt(o.kind,o.name,o.attributes),z=(me.get(A)??[]).map(re=>It(o.kind,re));return n(Ae,{"data-testid":`mt-instrument-${o.name}`,children:[t(ae,{className:"font-mono text-xs",title:o.functionPath,children:o.name}),t(ae,{children:t(et,{variant:Rt[o.kind],children:i(o.kind)})}),t(ae,{className:"text-right font-mono tabular-nums","data-testid":`mt-instrument-value-${o.name}`,children:Je(Ft(o))}),t(ae,{className:"text-right tabular-nums text-muted-foreground",children:o.count.toLocaleString()}),t(ae,{className:"text-right font-mono text-xs tabular-nums text-muted-foreground",children:o.min===o.max?"—":`${Je(o.min)}–${Je(o.max)}`}),t(ae,{children:z.length>=2?t(tt,{ariaLabel:a("{name} trend",{name:o.name}),className:"h-6 w-24 text-foreground",series:z,testId:`mt-instrument-trend-${o.name}`}):t("span",{className:"text-xs text-muted-foreground",children:"—"})}),t(ae,{className:"font-mono text-xs",children:t(Dt,{name:o.name,onOpenTrace:l,traceId:o.exemplarTraceId})}),t(ae,{className:"max-w-64 truncate font-mono text-xs text-muted-foreground",title:F,children:F===""?"—":F})]},A)})}e[6]=f,e[7]=h,e[8]=g,e[9]=m,e[10]=l,e[11]=a,e[12]=N,e[13]=le,e[14]=O,e[15]=j,e[16]=K,e[17]=c,e[18]=S,e[19]=se,e[20]=T,e[21]=R,e[22]=I,e[23]=x,e[24]=D}else N=e[12],le=e[13],O=e[14],j=e[15],K=e[16],c=e[17],S=e[18],se=e[19],T=e[20],R=e[21],I=e[22],x=e[23],D=e[24];if(se!==Symbol.for("react.early_return_sentinel"))return se;let E;e[84]!==N||e[85]!==T?(E=t(N,{children:T}),e[84]=N,e[85]=T,e[86]=E):E=e[86];let M;e[87]!==le||e[88]!==E||e[89]!==R||e[90]!==I?(M=n(le,{"data-testid":R,children:[I,E]}),e[87]=le,e[88]=E,e[89]=R,e[90]=I,e[91]=M):M=e[91];let L;e[92]!==O||e[93]!==M||e[94]!==x?(L=t(O,{className:x,children:M}),e[92]=O,e[93]=M,e[94]=x,e[95]=L):L=e[95];let $;e[96]!==j||e[97]!==L||e[98]!==D?($=t(j,{className:D,children:L}),e[96]=j,e[97]=L,e[98]=D,e[99]=$):$=e[99];let q;return e[100]!==K||e[101]!==c||e[102]!==S||e[103]!==$?(q=n("section",{className:K,"data-testid":c,children:[S,$]}),e[100]=K,e[101]=c,e[102]=S,e[103]=$,e[104]=q):q=e[104],q},je=s=>s>=100?"critical":s>=50?"warning":"good",Qe=s=>s<1?`${(s*1e3).toFixed(0)}μs`:s<1e3?`${s.toFixed(1)}ms`:`${(s/1e3).toFixed(2)}s`,Le=s=>s>=1e9?`${(s/1e9).toFixed(1)}B`:s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString(),At=s=>{const e=Fe(3),{level:l}=s;if(l==="critical"){let a;return e[0]===Symbol.for("react.memo_cache_sentinel")?(a=t(et,{variant:"destructive",children:"Slow"}),e[0]=a):a=e[0],a}if(l==="warning"){let a;return e[1]===Symbol.for("react.memo_cache_sentinel")?(a=t("span",{className:"inline-flex items-center gap-1 rounded-md border border-transparent bg-warning/10 px-2 py-0.5 text-xs font-medium text-warning",children:"Moderate"}),e[1]=a):a=e[1],a}let r;return e[2]===Symbol.for("react.memo_cache_sentinel")?(r=t("span",{className:"inline-flex items-center gap-1 rounded-md border border-transparent bg-success/10 px-2 py-0.5 text-xs font-medium text-success",children:"Fast"}),e[2]=r):r=e[2],r},zt=s=>{const e=Fe(152),{queryStats:l}=s,r=Ee(),[a,p]=ge("totalTime");let b;e[0]===Symbol.for("react.memo_cache_sentinel")?(b=new Set,e[0]=b):b=e[0];const[f,h]=ge(b);let g;e[1]===Symbol.for("react.memo_cache_sentinel")?(g=d=>{d!==null&&p(d)},e[1]=g):g=e[1];const v=g;let u;if(e[2]!==l||e[3]!==a){u=[...l];let d;e[5]!==a?(d=(C,_)=>{switch(a){case"avgTime":return _.avgDurationMs-C.avgDurationMs;case"execCount":return _.execCount-C.execCount;case"rowsRead":return _.rowsRead-C.rowsRead;default:return _.totalDurationMs-C.totalDurationMs}},e[5]=a,e[6]=d):d=e[6],u.sort(d),e[2]=l,e[3]=a,e[4]=u}else u=e[4];const m=u;let N;e[7]!==l?(N=l.filter(Et),e[7]=l,e[8]=N):N=e[8];const le=N.length;let O;e[9]!==l?(O=l.filter(jt),e[9]=l,e[10]=O):O=e[10];const j=O.length;let K;e[11]!==l?(K=l.filter(Kt),e[11]=l,e[12]=K):K=e[12];const c=K.length;let S;e[13]===Symbol.for("react.memo_cache_sentinel")?(S=d=>{h(C=>{const _=new Set(C);return _.has(d)?_.delete(d):_.add(d),_})},e[13]=S):S=e[13];const se=S;if(l.length===0){let d;e[14]!==r?(d=r("No query insights yet"),e[14]=r,e[15]=d):d=e[15];let C;e[16]!==d?(C=t("p",{className:"text-lg font-medium","data-testid":"qi-empty",children:d}),e[16]=d,e[17]=C):C=e[17];let _;e[18]!==r?(_=r("Query insights appear once statements are executed against this shard."),e[18]=r,e[19]=_):_=e[19];let ue;e[20]!==_?(ue=t("p",{className:"mt-1 text-sm",children:_}),e[20]=_,e[21]=ue):ue=e[21];let Oe;return e[22]!==ue||e[23]!==C?(Oe=t(he,{children:t(fe,{className:"py-12",children:n("div",{className:"text-center text-muted-foreground",children:[C,ue]})})}),e[22]=ue,e[23]=C,e[24]=Oe):Oe=e[24],Oe}let T;e[25]!==r?(T=r("Critical queries"),e[25]=r,e[26]=T):T=e[26];let R;e[27]!==T?(R=t(Te,{className:"pb-2",children:t(Re,{className:"text-sm font-medium",children:T})}),e[27]=T,e[28]=R):R=e[28];let I;e[29]!==le?(I=t("div",{className:"text-2xl font-bold text-destructive","data-testid":"qi-critical",children:le}),e[29]=le,e[30]=I):I=e[30];let x;e[31]!==r?(x=r(">100ms avg execution"),e[31]=r,e[32]=x):x=e[32];let D;e[33]!==x?(D=t("p",{className:"text-xs text-muted-foreground",children:x}),e[33]=x,e[34]=D):D=e[34];let E;e[35]!==D||e[36]!==I?(E=n(fe,{children:[I,D]}),e[35]=D,e[36]=I,e[37]=E):E=e[37];let M;e[38]!==E||e[39]!==R?(M=n(he,{children:[R,E]}),e[38]=E,e[39]=R,e[40]=M):M=e[40];let L;e[41]!==r?(L=r("Moderate queries"),e[41]=r,e[42]=L):L=e[42];let $;e[43]!==L?($=t(Te,{className:"pb-2",children:t(Re,{className:"text-sm font-medium",children:L})}),e[43]=L,e[44]=$):$=e[44];let q;e[45]!==j?(q=t("div",{className:"text-2xl font-bold text-warning","data-testid":"qi-moderate",children:j}),e[45]=j,e[46]=q):q=e[46];let oe;e[47]!==r?(oe=r("50–100ms avg execution"),e[47]=r,e[48]=oe):oe=e[48];let de;e[49]!==oe?(de=t("p",{className:"text-xs text-muted-foreground",children:oe}),e[49]=oe,e[50]=de):de=e[50];let me;e[51]!==q||e[52]!==de?(me=n(fe,{children:[q,de]}),e[51]=q,e[52]=de,e[53]=me):me=e[53];let P;e[54]!==$||e[55]!==me?(P=n(he,{children:[$,me]}),e[54]=$,e[55]=me,e[56]=P):P=e[56];let i;e[57]!==r?(i=r("Fast queries"),e[57]=r,e[58]=i):i=e[58];let k;e[59]!==i?(k=t(Te,{className:"pb-2",children:t(Re,{className:"text-sm font-medium",children:i})}),e[59]=i,e[60]=k):k=e[60];let y;e[61]!==c?(y=t("div",{className:"text-2xl font-bold text-success","data-testid":"qi-fast",children:c}),e[61]=c,e[62]=y):y=e[62];let w;e[63]!==r?(w=r("<50ms avg execution"),e[63]=r,e[64]=w):w=e[64];let U;e[65]!==w?(U=t("p",{className:"text-xs text-muted-foreground",children:w}),e[65]=w,e[66]=U):U=e[66];let J;e[67]!==y||e[68]!==U?(J=n(fe,{children:[y,U]}),e[67]=y,e[68]=U,e[69]=J):J=e[69];let Q;e[70]!==k||e[71]!==J?(Q=n(he,{children:[k,J]}),e[70]=k,e[71]=J,e[72]=Q):Q=e[72];let H;e[73]!==M||e[74]!==P||e[75]!==Q?(H=n("div",{className:"grid gap-4 md:grid-cols-3",children:[M,P,Q]}),e[73]=M,e[74]=P,e[75]=Q,e[76]=H):H=e[76];let W;e[77]!==r?(W=r("Query leaderboard"),e[77]=r,e[78]=W):W=e[78];let B;e[79]!==W?(B=t("h3",{className:"text-lg font-semibold",children:W}),e[79]=W,e[80]=B):B=e[80];let V;e[81]!==a||e[82]!==r?(V=r("Slow queries sorted by {sortField}",{sortField:r(a)}),e[81]=a,e[82]=r,e[83]=V):V=e[83];let G;e[84]!==V?(G=t("p",{className:"text-sm text-muted-foreground",children:V}),e[84]=V,e[85]=G):G=e[85];let X;e[86]!==B||e[87]!==G?(X=n("div",{children:[B,G]}),e[86]=B,e[87]=G,e[88]=X):X=e[88];let Y;e[89]!==r?(Y=r("Sort by"),e[89]=r,e[90]=Y):Y=e[90];let Z;e[91]!==Y?(Z=t("span",{className:"text-sm text-muted-foreground",children:Y}),e[91]=Y,e[92]=Z):Z=e[92];let ee;e[93]!==r?(ee=r("Sort queries by"),e[93]=r,e[94]=ee):ee=e[94];let ce;e[95]===Symbol.for("react.memo_cache_sentinel")?(ce=t(St,{}),e[95]=ce):ce=e[95];let te;e[96]!==ee?(te=t(qt,{"aria-label":ee,className:"w-[140px]","data-testid":"qi-sort",children:ce}),e[96]=ee,e[97]=te):te=e[97];let o;e[98]!==r?(o=r("Total time"),e[98]=r,e[99]=o):o=e[99];let F;e[100]!==o?(F=t(De,{value:"totalTime",children:o}),e[100]=o,e[101]=F):F=e[101];let A;e[102]!==r?(A=r("Avg time"),e[102]=r,e[103]=A):A=e[103];let z;e[104]!==A?(z=t(De,{value:"avgTime",children:A}),e[104]=A,e[105]=z):z=e[105];let re;e[106]!==r?(re=r("Execution count"),e[106]=r,e[107]=re):re=e[107];let xe;e[108]!==re?(xe=t(De,{value:"execCount",children:re}),e[108]=re,e[109]=xe):xe=e[109];let pe;e[110]!==r?(pe=r("Rows read"),e[110]=r,e[111]=pe):pe=e[111];let be;e[112]!==pe?(be=t(De,{value:"rowsRead",children:pe}),e[112]=pe,e[113]=be):be=e[113];let ve;e[114]!==F||e[115]!==z||e[116]!==xe||e[117]!==be?(ve=n(kt,{children:[F,z,xe,be]}),e[114]=F,e[115]=z,e[116]=xe,e[117]=be,e[118]=ve):ve=e[118];let Ne;e[119]!==a||e[120]!==te||e[121]!==ve?(Ne=n(_t,{onValueChange:v,value:a,children:[te,ve]}),e[119]=a,e[120]=te,e[121]=ve,e[122]=Ne):Ne=e[122];let ye;e[123]!==Z||e[124]!==Ne?(ye=n("div",{className:"flex items-center gap-2",children:[Z,Ne]}),e[123]=Z,e[124]=Ne,e[125]=ye):ye=e[125];let $e;e[126]!==X||e[127]!==ye?($e=n("div",{className:"flex items-center justify-between",children:[X,ye]}),e[126]=X,e[127]=ye,e[128]=$e):$e=e[128];let we;e[129]!==r?(we=r("Statements"),e[129]=r,e[130]=we):we=e[130];let Se;e[131]!==we?(Se=t(Re,{children:we}),e[131]=we,e[132]=Se):Se=e[132];let qe;e[133]!==m.length||e[134]!==r?(qe=r("{count} tracked statements",{count:m.length}),e[133]=m.length,e[134]=r,e[135]=qe):qe=e[135];let ke;e[136]!==qe?(ke=t(ct,{children:qe}),e[136]=qe,e[137]=ke):ke=e[137];let _e;e[138]!==Se||e[139]!==ke?(_e=n(Te,{children:[Se,ke]}),e[138]=Se,e[139]=ke,e[140]=_e):_e=e[140];let Me;e[141]!==f||e[142]!==m||e[143]!==r?(Me=t(fe,{children:t("div",{className:"space-y-2",children:m.map(d=>{const C=d.normalizedSql,_=f.has(C),ue=je(d.avgDurationMs);return n("div",{className:"overflow-hidden rounded-lg border","data-testid":"qi-row",children:[n("button",{"aria-expanded":_,className:"flex w-full items-center justify-between p-3 text-left transition-colors hover:bg-muted/50",onClick:()=>{se(C)},type:"button",children:[n("div",{className:"flex min-w-0 flex-1 items-center gap-3",children:[t(At,{level:ue}),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:Qe(d.totalDurationMs)}),t("div",{className:"text-xs text-muted-foreground",children:r("total")})]}),n("div",{className:"text-right",children:[t("div",{className:"text-sm font-medium",children:Qe(d.avgDurationMs)}),t("div",{className:"text-xs text-muted-foreground",children:r("avg")})]}),n("div",{className:"text-right",children:[t("div",{className:"text-sm font-medium",children:Le(d.execCount)}),t("div",{className:"text-xs text-muted-foreground",children:r("calls")})]})]})]}),_&&n("div",{className:"space-y-3 border-t bg-muted/30 p-4",children:[n("div",{children:[t("p",{className:"mb-2 text-sm font-medium",children:r("Full statement")}),t("pre",{className:"overflow-x-auto rounded-md bg-muted p-3 font-mono text-sm whitespace-pre-wrap break-all",children:d.normalizedSql})]}),n("div",{className:"grid grid-cols-2 gap-4 text-sm md:grid-cols-4",children:[n("div",{children:[t("span",{className:"text-muted-foreground",children:r("Exec count")}),t("span",{className:"block font-medium tabular-nums",children:Le(d.execCount)})]}),n("div",{children:[t("span",{className:"text-muted-foreground",children:r("Total time")}),t("span",{className:"block font-medium tabular-nums",children:Qe(d.totalDurationMs)})]}),n("div",{children:[t("span",{className:"text-muted-foreground",children:r("Rows read")}),t("span",{className:"block font-medium tabular-nums",children:Le(d.rowsRead)})]}),n("div",{children:[t("span",{className:"text-muted-foreground",children:r("Rows written")}),t("span",{className:"block font-medium tabular-nums",children:Le(d.rowsWritten)})]})]})]})]},C)})})}),e[141]=f,e[142]=m,e[143]=r,e[144]=Me):Me=e[144];let Ie;e[145]!==_e||e[146]!==Me?(Ie=n(he,{children:[_e,Me]}),e[145]=_e,e[146]=Me,e[147]=Ie):Ie=e[147];let Ce;return e[148]!==H||e[149]!==$e||e[150]!==Ie?(Ce=n("div",{className:"space-y-4","data-testid":"qi-root",children:[H,$e,Ie]}),e[148]=H,e[149]=$e,e[150]=Ie,e[151]=Ce):Ce=e[151],Ce};function Et(s){return je(s.avgDurationMs)==="critical"}function jt(s){return je(s.avgDurationMs)==="warning"}function Kt(s){return je(s.avgDurationMs)==="good"}const Pt=ft(ze.getMetrics),Ut=s=>{const e=Math.floor(s/1e3),l=Math.floor(e/3600),r=Math.floor(e%3600/60),a=e%60;return l>0?`${l.toString()}h ${r.toString()}m`:r>0?`${r.toString()}m ${a.toString()}s`:`${a.toString()}s`},Jt=(s,e)=>s?e:"overview",Qt=(s,e)=>{const l=s+e;return l===0?"—":`${(s/l*100).toFixed(1)}%`},ne=s=>{const e=Fe(16),{chart:l,footer:r,label:a,testId:p,value:b}=s;let f;e[0]!==a?(f=t("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:a}),e[0]=a,e[1]=f):f=e[1];let h;e[2]!==p||e[3]!==b?(h=t("span",{className:"truncate text-2xl font-semibold tabular-nums text-foreground","data-testid":p,children:b}),e[2]=p,e[3]=b,e[4]=h):h=e[4];let g;e[5]!==l||e[6]!==h?(g=n("div",{className:"flex items-center justify-between gap-3",children:[h,l]}),e[5]=l,e[6]=h,e[7]=g):g=e[7];let v;e[8]!==f||e[9]!==g?(v=n("div",{className:"flex flex-col gap-2.5 p-4",children:[f,g]}),e[8]=f,e[9]=g,e[10]=v):v=e[10];let u;e[11]!==r?(u=r!=null&&t("div",{className:"border-t border-border bg-muted/50 px-4 py-2.5 text-[11px] text-muted-foreground",children:r}),e[11]=r,e[12]=u):u=e[12];let m;return e[13]!==v||e[14]!==u?(m=n(he,{className:"justify-between gap-0 py-0",children:[v,u]}),e[13]=v,e[14]=u,e[15]=m):m=e[15],m},fr=({initialShardKey:s})=>{const e=lt(),l=Ee(),r=st(),[a,p]=ge(s??""),[b,f]=ge("overview"),[h,g]=ge([]),v=Ke(null),u=Ke(null),m=Ke(!0);Be(()=>(m.current=!0,()=>{m.current=!1}),[]);const N=dt(a.trim(),400),le=i=>{bt({shardKey:N,traceId:i}),Ge(r({to:"/traces"}))},{data:O,error:j,liveError:K}=He(ze.getMetrics,{},{live:!0,shardKey:N}),c=O??null;Be(()=>{if(O===void 0)return;xt(N);const i=O,k=v.current,y=u.current!==null&&u.current!==i.shard;if(u.current=i.shard,v.current=i.requests,y){g([]);return}k!==null&&i.requests>=k&&g(w=>[...w,i.requests-k].slice(-30))},[O,N]);const[S,se]=ge(null),[T,R]=ge(!1),I=async()=>{R(!0);const i=wt(a,pt());try{const k=await Promise.all(i.map(async y=>{try{const w=await e.query(Pt,{},ht(y));return{error:null,metrics:w,shard:y===""?w.shard:y}}catch(w){return{error:gt(w),metrics:null,shard:y===""?"__root__":y}}}));m.current&&se(k)}finally{m.current&&R(!1)}},x=S===null?null:Nt(S),D=c===null||c.requests===0?"—":`${(c.errors/c.requests*100).toFixed(1)}%`,E=h.length>0?h.at(-1):0,M=c?yt(c):{p90:0,p95:0},L=i=>i<=0?"—":i<1?`${(i*1e3).toFixed(0)}μs`:i<1e3?`${i.toFixed(1)}ms`:`${(i/1e3).toFixed(2)}s`,$=nt(()=>{if(!c||!("queryStats"in c))return;const i=c.queryStats;if(!(!i||!Array.isArray(i)))return $t(i)},[c]),q=Jt($!==void 0,b),oe=()=>{Ge(I())},de=()=>{se(null)},me=()=>{f("overview")},P=()=>{f("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(ot,{onChange:p,testId:"mt-shard-input",value:a}),t(it,{message:K,prefix:"mt"}),t(Ve,{"data-testid":"mt-aggregate",disabled:T,onClick:oe,size:"sm",type:"button",variant:"secondary",children:l(T?"Aggregating…":"All shards")}),S!==null&&t(Ve,{"data-testid":"mt-aggregate-clear",onClick:de,size:"sm",type:"button",variant:"ghost",children:l("Hide")}),t("a",{className:"text-sm text-primary underline-offset-4 hover:underline","data-testid":"mt-cf-link",href:mt,rel:"noreferrer",target:"_blank",children:l("Open in Cloudflare")})]}),j!==null&&t("p",{className:"text-sm text-destructive","data-testid":"mt-error",role:"alert",children:j}),$!==void 0&&n("div",{className:"flex gap-2 border-b","data-testid":"mt-tabs",children:[t("button",{className:`pb-2 text-sm font-medium transition-colors ${q==="overview"?"border-b-2 border-primary text-foreground":"text-muted-foreground hover:text-foreground"}`,"data-testid":"mt-tab-overview",onClick:me,type:"button",children:l("Overview")}),n("button",{className:`pb-2 text-sm font-medium transition-colors ${q==="query-insights"?"border-b-2 border-primary text-foreground":"text-muted-foreground hover:text-foreground"}`,"data-testid":"mt-tab-query-insights",onClick:P,type:"button",children:[l("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})]})]}),q==="query-insights"&&$!==void 0&&t(zt,{queryStats:$}),q==="overview"&&c!==null&&n("dl",{className:"grid gap-3 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4","data-testid":"mt-stats",children:[t(ne,{chart:h.length>=2?t(tt,{ariaLabel:l("Requests per interval over time"),className:"h-7 w-24 text-foreground",series:h,testId:"mt-sparkline"}):void 0,footer:h.length>=2?n(Ue,{children:[t("span",{className:"font-semibold text-foreground",children:`+${E.toLocaleString()}`})," ",l("last interval")]}):t("span",{"data-testid":"mt-sparkline-empty",children:l("collecting samples…")}),label:l("Requests"),testId:"mt-requests",value:c.requests}),t(ne,{footer:l("{rate} error rate",{rate:D}),label:l("Errors"),testId:"mt-errors",value:n(Ue,{children:[c.errors," (",D,")"]})}),t(ne,{footer:M.p90>0?`P90 ${L(M.p90)}`:void 0,label:l("P95 latency"),testId:"mt-p95",value:M.p95>0?L(M.p95):"—"}),t(ne,{footer:c.cache===null?void 0:`${c.cache.entries.toLocaleString()} ${l("cache entries")}`,label:l("Database size"),testId:"mt-db-size",value:Pe(c.databaseSize)}),t(ne,{label:l("Shard"),testId:"mt-shard",value:c.shard}),t(ne,{label:l("Uptime"),testId:"mt-uptime",value:Ut(c.uptimeMs)}),t(ne,{label:l("Cache hit rate"),testId:"mt-cache",value:c.cache===null?l("no cache configured"):l("{rate} ({count} entries)",{count:c.cache.entries,rate:Qt(c.cache.hits,c.cache.misses)})})]}),q==="overview"&&c===null&&null,q==="overview"&&t(Lt,{onOpenTrace:le,shardKey:N}),q==="overview"&&x!==null&&S!==null&&n("div",{className:"flex flex-col gap-4","data-testid":"mt-aggregate-view",children:[n("dl",{className:"grid gap-3 sm:grid-cols-2 lg:grid-cols-3","data-testid":"mt-aggregate-stats",children:[t(ne,{label:l("Shards"),testId:"mt-agg-shards",value:x.failed>0?l("{reachable} reachable, {failed} unreachable",{failed:x.failed,reachable:x.reachable}):l("{reachable} reachable",{reachable:x.reachable})}),t(ne,{label:l("Total requests"),testId:"mt-agg-requests",value:x.totalRequests}),t(ne,{label:l("Total errors"),testId:"mt-agg-errors",value:x.totalErrors}),t(ne,{label:l("Total database size"),testId:"mt-agg-db-size",value:Pe(x.totalDatabaseSize)}),t(ne,{label:l("Combined cache hit rate"),testId:"mt-agg-cache",value:x.hitRate===null?l("no cache configured"):`${(x.hitRate*100).toFixed(1)}%`})]}),t(he,{className:"overflow-hidden py-0",children:t(fe,{className:"px-0",children:n(Ye,{"data-testid":"mt-agg-table",children:[t(Xe,{children:n(Ae,{children:[t(ie,{children:l("shard")}),t(ie,{children:l("requests")}),t(ie,{children:l("errors")}),t(ie,{children:l("db size")})]})}),t(Ze,{children:S.map(i=>n(Ae,{"data-testid":`mt-agg-row-${i.shard}`,children:[t(ae,{children:i.shard}),i.metrics===null?t(ae,{className:"text-destructive",colSpan:3,children:i.error??l("unreachable")}):n(Ue,{children:[t(ae,{className:"tabular-nums",children:i.metrics.requests}),t(ae,{className:"tabular-nums",children:i.metrics.errors}),t(ae,{className:"tabular-nums",children:Pe(i.metrics.databaseSize)})]})]},i.shard))})]})})})]})]})};export{fr as MetricsPanel};
1
+ import{c as Fe}from"react/compiler-runtime";import{useLunora as lt}from"@lunora/react";import{useNavigate as st}from"@tanstack/react-router";import{useState as ge,useRef as Ke,useEffect as Be,useMemo as nt}from"react";import{L as it}from"../packem_shared/live-status-CGW2JHf_.js";import{ShardInput as ot}from"../packem_shared/ShardInput-BVn2iCU0.js";import{u as Ve}from"../packem_shared/button-BkCrNcAs.js";import{c as he,u as fe,n as Te,f as Re,m as ct}from"../packem_shared/card-CIDGUN6K.js";import{p as ie,d as Xe,m as Ae,u as ae,n as Ye,f as Ze}from"../packem_shared/table-DdJBrClo.js";import{K as He}from"../packem_shared/use-admin-query-Di3fLE8H.js";import dt from"../packem_shared/useDebounced-Ihdiid_k.js";import{useT as Ee}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as ze}from"../packem_shared/ADMIN_FUNCTIONS-CpgIo9pj.js";import{c as mt}from"../packem_shared/cf-links-gbDy51nR.js";import{l as ut,k as Pe,f as Ge,c as ht,e as gt,a as ft}from"../packem_shared/internal-AtZ4bTal.js";import{r as xt,l as pt}from"../packem_shared/shard-history-DMEW5VBE.js";import{w as bt}from"../packem_shared/trace-handoff-Dw7mwjxu.js";import{f as vt}from"../packem_shared/log-fields-CoL3hsIQ.js";import{g as et}from"../packem_shared/badge-BbuuAio7.js";import{S as tt}from"../packem_shared/sparkline-DtcZoU48.js";import{jsx as t,jsxs as n,Fragment as Ue}from"react/jsx-runtime";import{aggregateMetrics as Nt,computeLatencyPercentiles as yt,enrichQueryStats as $t,shardsToAggregate as wt}from"../packem_shared/aggregateMetrics-BNfajLa2.js";import{N as St,y as qt,k as De,_ as kt,w as _t}from"../packem_shared/select-Bul-DeII.js";const Mt=(s,e)=>s<e?-1:s>e?1:0,We=s=>{if(s===void 0)return"null";if(typeof s=="bigint")throw new TypeError("stableStringify: cannot use a bigint in a stable JSON cache key — pass it as a string, or use stableWireKey");if(s===null||typeof s!="object")return JSON.stringify(s);if(Array.isArray(s))return`[${s.map(p=>We(p)).join(",")}]`;const e=Object.getPrototypeOf(s);if(e!==null&&e!==Object.prototype){const p=s.constructor?.name??"value";throw new TypeError(`stableStringify: cannot use a ${p} in a stable JSON cache key — only plain objects, arrays, and JSON primitives are supported (wire-typed values key via stableWireKey)`)}const l=s,r=Object.keys(l).toSorted(Mt),a=[];for(const p of r){const b=l[p];b!==void 0&&a.push(`${JSON.stringify(p)}:${We(b)}`)}return`{${a.join(",")}}`},rt=(s,e,l)=>`${s}:${e}:${We(l??{})}`,at=(s,e)=>s==="gauge"?e.last:s==="histogram"?e.sum/Math.max(1,e.count):e.sum,It=(s,e)=>at(s,e),Ft=s=>at(s.kind,s),Je=s=>Number.isInteger(s)?s.toLocaleString():s.toLocaleString(void 0,{maximumFractionDigits:2}),Ct=s=>Array.isArray(s?.series)?s.series:[],Ot="FUNCTION_NOT_FOUND",Tt=s=>{const e=new Map;if(!Array.isArray(s?.series))return e;for(const l of s.series)e.set(rt(l.kind,l.name,l.attributes),l.points);return e},Rt={counter:"secondary",gauge:"default",histogram:"outline"},Dt=s=>{const e=Fe(18),{name:l,onOpenTrace:r,traceId:a}=s,p=Ee();if(a===void 0){let m;return e[0]===Symbol.for("react.memo_cache_sentinel")?(m=t("span",{className:"text-muted-foreground",children:"—"}),e[0]=m):m=e[0],m}let b;e[1]!==a?(b=a.slice(0,8),e[1]=a,e[2]=b):b=e[2];const f=b;if(r===void 0){const m=`mt-instrument-trace-${l}`;let N;return e[3]!==f||e[4]!==m||e[5]!==a?(N=t("span",{className:"text-muted-foreground","data-testid":m,title:a,children:f}),e[3]=f,e[4]=m,e[5]=a,e[6]=N):N=e[6],N}const h=`mt-instrument-trace-${l}`;let g;e[7]!==r||e[8]!==a?(g=()=>{r(a)},e[7]=r,e[8]=a,e[9]=g):g=e[9];let v;e[10]!==p||e[11]!==a?(v=p("Open the exemplar trace {trace}",{trace:a}),e[10]=p,e[11]=a,e[12]=v):v=e[12];let u;return e[13]!==f||e[14]!==h||e[15]!==g||e[16]!==v?(u=t("button",{className:"text-primary underline-offset-4 hover:underline","data-testid":h,onClick:g,title:v,type:"button",children:f}),e[13]=f,e[14]=h,e[15]=g,e[16]=v,e[17]=u):u=e[17],u},Lt=s=>{const e=Fe(105),{onOpenTrace:l,shardKey:r}=s,a=Ee();let p;e[0]===Symbol.for("react.memo_cache_sentinel")?(p={},e[0]=p):p=e[0];let b;e[1]!==r?(b={live:!0,shardKey:r},e[1]=r,e[2]=b):b=e[2];const{data:f,error:h,errorSource:g}=He(ze.getMetricSeries,p,b);let v;e[3]===Symbol.for("react.memo_cache_sentinel")?(v={},e[3]=v):v=e[3];let u;e[4]!==r?(u={live:!0,shardKey:r},e[4]=r,e[5]=u):u=e[5];const{data:m}=He(ze.getMetricHistory,v,u);let N,le,O,j,K,c,S,se,T,R,I,x,D;if(e[6]!==f||e[7]!==h||e[8]!==g||e[9]!==m||e[10]!==l||e[11]!==a){se=Symbol.for("react.early_return_sentinel");e:{const oe=Ct(f),de=ut(g)===Ot;if(h!==null&&!de){let o;e[25]!==a?(o=a("Instruments"),e[25]=a,e[26]=o):o=e[26];let F;e[27]!==o?(F=t("h3",{className:"text-sm font-semibold text-foreground",children:o}),e[27]=o,e[28]=F):F=e[28];let A;e[29]!==h||e[30]!==a?(A=a("Instruments unavailable: {error}",{error:h}),e[29]=h,e[30]=a,e[31]=A):A=e[31];let z;e[32]!==A?(z=t("span",{className:"text-xs text-muted-foreground","data-testid":"mt-instruments-error",role:"status",children:A}),e[32]=A,e[33]=z):z=e[33];let re;e[34]!==F||e[35]!==z?(re=n("section",{className:"flex flex-col gap-2","data-testid":"mt-instruments",children:[F,z]}),e[34]=F,e[35]=z,e[36]=re):re=e[36],se=re;break e}if(oe.length===0){se=null;break e}const me=Tt(m);let P;e[37]!==a?(P=o=>a(o==="counter"?"Counter":o==="gauge"?"Gauge":"Histogram"),e[37]=a,e[38]=P):P=e[38];const i=P;K="flex flex-col gap-2",c="mt-instruments";let k;e[39]!==a?(k=a("Instruments"),e[39]=a,e[40]=k):k=e[40],e[41]!==k?(S=t("h3",{className:"text-sm font-semibold text-foreground",children:k}),e[41]=k,e[42]=S):S=e[42],j=he,D="overflow-hidden py-0",O=fe,x="px-0",le=Ye,R="mt-instruments-table";let y;e[43]!==a?(y=a("name"),e[43]=a,e[44]=y):y=e[44];let w;e[45]!==y?(w=t(ie,{children:y}),e[45]=y,e[46]=w):w=e[46];let U;e[47]!==a?(U=a("kind"),e[47]=a,e[48]=U):U=e[48];let J;e[49]!==U?(J=t(ie,{children:U}),e[49]=U,e[50]=J):J=e[50];let Q;e[51]!==a?(Q=a("value"),e[51]=a,e[52]=Q):Q=e[52];let H;e[53]!==Q?(H=t(ie,{className:"text-right",children:Q}),e[53]=Q,e[54]=H):H=e[54];let W;e[55]!==a?(W=a("count"),e[55]=a,e[56]=W):W=e[56];let B;e[57]!==W?(B=t(ie,{className:"text-right",children:W}),e[57]=W,e[58]=B):B=e[58];let V;e[59]!==a?(V=a("range"),e[59]=a,e[60]=V):V=e[60];let G;e[61]!==V?(G=t(ie,{className:"text-right",children:V}),e[61]=V,e[62]=G):G=e[62];let X;e[63]!==a?(X=a("trend"),e[63]=a,e[64]=X):X=e[64];let Y;e[65]!==X?(Y=t(ie,{children:X}),e[65]=X,e[66]=Y):Y=e[66];let Z;e[67]!==a?(Z=a("trace"),e[67]=a,e[68]=Z):Z=e[68];let ee;e[69]!==Z?(ee=t(ie,{children:Z}),e[69]=Z,e[70]=ee):ee=e[70];let ce;e[71]!==a?(ce=a("dimensions"),e[71]=a,e[72]=ce):ce=e[72];let te;e[73]!==ce?(te=t(ie,{children:ce}),e[73]=ce,e[74]=te):te=e[74],e[75]!==w||e[76]!==J||e[77]!==H||e[78]!==B||e[79]!==G||e[80]!==Y||e[81]!==ee||e[82]!==te?(I=t(Xe,{children:n(Ae,{children:[w,J,H,B,G,Y,ee,te]})}),e[75]=w,e[76]=J,e[77]=H,e[78]=B,e[79]=G,e[80]=Y,e[81]=ee,e[82]=te,e[83]=I):I=e[83],N=Ze,T=oe.map(o=>{const F=vt(o.attributes),A=rt(o.kind,o.name,o.attributes),z=(me.get(A)??[]).map(re=>It(o.kind,re));return n(Ae,{"data-testid":`mt-instrument-${o.name}`,children:[t(ae,{className:"font-mono text-xs",title:o.functionPath,children:o.name}),t(ae,{children:t(et,{variant:Rt[o.kind],children:i(o.kind)})}),t(ae,{className:"text-right font-mono tabular-nums","data-testid":`mt-instrument-value-${o.name}`,children:Je(Ft(o))}),t(ae,{className:"text-right tabular-nums text-muted-foreground",children:o.count.toLocaleString()}),t(ae,{className:"text-right font-mono text-xs tabular-nums text-muted-foreground",children:o.min===o.max?"—":`${Je(o.min)}–${Je(o.max)}`}),t(ae,{children:z.length>=2?t(tt,{ariaLabel:a("{name} trend",{name:o.name}),className:"h-6 w-24 text-foreground",series:z,testId:`mt-instrument-trend-${o.name}`}):t("span",{className:"text-xs text-muted-foreground",children:"—"})}),t(ae,{className:"font-mono text-xs",children:t(Dt,{name:o.name,onOpenTrace:l,traceId:o.exemplarTraceId})}),t(ae,{className:"max-w-64 truncate font-mono text-xs text-muted-foreground",title:F,children:F===""?"—":F})]},A)})}e[6]=f,e[7]=h,e[8]=g,e[9]=m,e[10]=l,e[11]=a,e[12]=N,e[13]=le,e[14]=O,e[15]=j,e[16]=K,e[17]=c,e[18]=S,e[19]=se,e[20]=T,e[21]=R,e[22]=I,e[23]=x,e[24]=D}else N=e[12],le=e[13],O=e[14],j=e[15],K=e[16],c=e[17],S=e[18],se=e[19],T=e[20],R=e[21],I=e[22],x=e[23],D=e[24];if(se!==Symbol.for("react.early_return_sentinel"))return se;let E;e[84]!==N||e[85]!==T?(E=t(N,{children:T}),e[84]=N,e[85]=T,e[86]=E):E=e[86];let M;e[87]!==le||e[88]!==E||e[89]!==R||e[90]!==I?(M=n(le,{"data-testid":R,children:[I,E]}),e[87]=le,e[88]=E,e[89]=R,e[90]=I,e[91]=M):M=e[91];let L;e[92]!==O||e[93]!==M||e[94]!==x?(L=t(O,{className:x,children:M}),e[92]=O,e[93]=M,e[94]=x,e[95]=L):L=e[95];let $;e[96]!==j||e[97]!==L||e[98]!==D?($=t(j,{className:D,children:L}),e[96]=j,e[97]=L,e[98]=D,e[99]=$):$=e[99];let q;return e[100]!==K||e[101]!==c||e[102]!==S||e[103]!==$?(q=n("section",{className:K,"data-testid":c,children:[S,$]}),e[100]=K,e[101]=c,e[102]=S,e[103]=$,e[104]=q):q=e[104],q},je=s=>s>=100?"critical":s>=50?"warning":"good",Qe=s=>s<1?`${(s*1e3).toFixed(0)}μs`:s<1e3?`${s.toFixed(1)}ms`:`${(s/1e3).toFixed(2)}s`,Le=s=>s>=1e9?`${(s/1e9).toFixed(1)}B`:s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString(),At=s=>{const e=Fe(3),{level:l}=s;if(l==="critical"){let a;return e[0]===Symbol.for("react.memo_cache_sentinel")?(a=t(et,{variant:"destructive",children:"Slow"}),e[0]=a):a=e[0],a}if(l==="warning"){let a;return e[1]===Symbol.for("react.memo_cache_sentinel")?(a=t("span",{className:"inline-flex items-center gap-1 rounded-md border border-transparent bg-warning/10 px-2 py-0.5 text-xs font-medium text-warning",children:"Moderate"}),e[1]=a):a=e[1],a}let r;return e[2]===Symbol.for("react.memo_cache_sentinel")?(r=t("span",{className:"inline-flex items-center gap-1 rounded-md border border-transparent bg-success/10 px-2 py-0.5 text-xs font-medium text-success",children:"Fast"}),e[2]=r):r=e[2],r},zt=s=>{const e=Fe(152),{queryStats:l}=s,r=Ee(),[a,p]=ge("totalTime");let b;e[0]===Symbol.for("react.memo_cache_sentinel")?(b=new Set,e[0]=b):b=e[0];const[f,h]=ge(b);let g;e[1]===Symbol.for("react.memo_cache_sentinel")?(g=d=>{d!==null&&p(d)},e[1]=g):g=e[1];const v=g;let u;if(e[2]!==l||e[3]!==a){u=[...l];let d;e[5]!==a?(d=(C,_)=>{switch(a){case"avgTime":return _.avgDurationMs-C.avgDurationMs;case"execCount":return _.execCount-C.execCount;case"rowsRead":return _.rowsRead-C.rowsRead;default:return _.totalDurationMs-C.totalDurationMs}},e[5]=a,e[6]=d):d=e[6],u.sort(d),e[2]=l,e[3]=a,e[4]=u}else u=e[4];const m=u;let N;e[7]!==l?(N=l.filter(Et),e[7]=l,e[8]=N):N=e[8];const le=N.length;let O;e[9]!==l?(O=l.filter(jt),e[9]=l,e[10]=O):O=e[10];const j=O.length;let K;e[11]!==l?(K=l.filter(Kt),e[11]=l,e[12]=K):K=e[12];const c=K.length;let S;e[13]===Symbol.for("react.memo_cache_sentinel")?(S=d=>{h(C=>{const _=new Set(C);return _.has(d)?_.delete(d):_.add(d),_})},e[13]=S):S=e[13];const se=S;if(l.length===0){let d;e[14]!==r?(d=r("No query insights yet"),e[14]=r,e[15]=d):d=e[15];let C;e[16]!==d?(C=t("p",{className:"text-lg font-medium","data-testid":"qi-empty",children:d}),e[16]=d,e[17]=C):C=e[17];let _;e[18]!==r?(_=r("Query insights appear once statements are executed against this shard."),e[18]=r,e[19]=_):_=e[19];let ue;e[20]!==_?(ue=t("p",{className:"mt-1 text-sm",children:_}),e[20]=_,e[21]=ue):ue=e[21];let Oe;return e[22]!==ue||e[23]!==C?(Oe=t(he,{children:t(fe,{className:"py-12",children:n("div",{className:"text-center text-muted-foreground",children:[C,ue]})})}),e[22]=ue,e[23]=C,e[24]=Oe):Oe=e[24],Oe}let T;e[25]!==r?(T=r("Critical queries"),e[25]=r,e[26]=T):T=e[26];let R;e[27]!==T?(R=t(Te,{className:"pb-2",children:t(Re,{className:"text-sm font-medium",children:T})}),e[27]=T,e[28]=R):R=e[28];let I;e[29]!==le?(I=t("div",{className:"text-2xl font-bold text-destructive","data-testid":"qi-critical",children:le}),e[29]=le,e[30]=I):I=e[30];let x;e[31]!==r?(x=r(">100ms avg execution"),e[31]=r,e[32]=x):x=e[32];let D;e[33]!==x?(D=t("p",{className:"text-xs text-muted-foreground",children:x}),e[33]=x,e[34]=D):D=e[34];let E;e[35]!==D||e[36]!==I?(E=n(fe,{children:[I,D]}),e[35]=D,e[36]=I,e[37]=E):E=e[37];let M;e[38]!==E||e[39]!==R?(M=n(he,{children:[R,E]}),e[38]=E,e[39]=R,e[40]=M):M=e[40];let L;e[41]!==r?(L=r("Moderate queries"),e[41]=r,e[42]=L):L=e[42];let $;e[43]!==L?($=t(Te,{className:"pb-2",children:t(Re,{className:"text-sm font-medium",children:L})}),e[43]=L,e[44]=$):$=e[44];let q;e[45]!==j?(q=t("div",{className:"text-2xl font-bold text-warning","data-testid":"qi-moderate",children:j}),e[45]=j,e[46]=q):q=e[46];let oe;e[47]!==r?(oe=r("50–100ms avg execution"),e[47]=r,e[48]=oe):oe=e[48];let de;e[49]!==oe?(de=t("p",{className:"text-xs text-muted-foreground",children:oe}),e[49]=oe,e[50]=de):de=e[50];let me;e[51]!==q||e[52]!==de?(me=n(fe,{children:[q,de]}),e[51]=q,e[52]=de,e[53]=me):me=e[53];let P;e[54]!==$||e[55]!==me?(P=n(he,{children:[$,me]}),e[54]=$,e[55]=me,e[56]=P):P=e[56];let i;e[57]!==r?(i=r("Fast queries"),e[57]=r,e[58]=i):i=e[58];let k;e[59]!==i?(k=t(Te,{className:"pb-2",children:t(Re,{className:"text-sm font-medium",children:i})}),e[59]=i,e[60]=k):k=e[60];let y;e[61]!==c?(y=t("div",{className:"text-2xl font-bold text-success","data-testid":"qi-fast",children:c}),e[61]=c,e[62]=y):y=e[62];let w;e[63]!==r?(w=r("<50ms avg execution"),e[63]=r,e[64]=w):w=e[64];let U;e[65]!==w?(U=t("p",{className:"text-xs text-muted-foreground",children:w}),e[65]=w,e[66]=U):U=e[66];let J;e[67]!==y||e[68]!==U?(J=n(fe,{children:[y,U]}),e[67]=y,e[68]=U,e[69]=J):J=e[69];let Q;e[70]!==k||e[71]!==J?(Q=n(he,{children:[k,J]}),e[70]=k,e[71]=J,e[72]=Q):Q=e[72];let H;e[73]!==M||e[74]!==P||e[75]!==Q?(H=n("div",{className:"grid gap-4 md:grid-cols-3",children:[M,P,Q]}),e[73]=M,e[74]=P,e[75]=Q,e[76]=H):H=e[76];let W;e[77]!==r?(W=r("Query leaderboard"),e[77]=r,e[78]=W):W=e[78];let B;e[79]!==W?(B=t("h3",{className:"text-lg font-semibold",children:W}),e[79]=W,e[80]=B):B=e[80];let V;e[81]!==a||e[82]!==r?(V=r("Slow queries sorted by {sortField}",{sortField:r(a)}),e[81]=a,e[82]=r,e[83]=V):V=e[83];let G;e[84]!==V?(G=t("p",{className:"text-sm text-muted-foreground",children:V}),e[84]=V,e[85]=G):G=e[85];let X;e[86]!==B||e[87]!==G?(X=n("div",{children:[B,G]}),e[86]=B,e[87]=G,e[88]=X):X=e[88];let Y;e[89]!==r?(Y=r("Sort by"),e[89]=r,e[90]=Y):Y=e[90];let Z;e[91]!==Y?(Z=t("span",{className:"text-sm text-muted-foreground",children:Y}),e[91]=Y,e[92]=Z):Z=e[92];let ee;e[93]!==r?(ee=r("Sort queries by"),e[93]=r,e[94]=ee):ee=e[94];let ce;e[95]===Symbol.for("react.memo_cache_sentinel")?(ce=t(St,{}),e[95]=ce):ce=e[95];let te;e[96]!==ee?(te=t(qt,{"aria-label":ee,className:"w-[140px]","data-testid":"qi-sort",children:ce}),e[96]=ee,e[97]=te):te=e[97];let o;e[98]!==r?(o=r("Total time"),e[98]=r,e[99]=o):o=e[99];let F;e[100]!==o?(F=t(De,{value:"totalTime",children:o}),e[100]=o,e[101]=F):F=e[101];let A;e[102]!==r?(A=r("Avg time"),e[102]=r,e[103]=A):A=e[103];let z;e[104]!==A?(z=t(De,{value:"avgTime",children:A}),e[104]=A,e[105]=z):z=e[105];let re;e[106]!==r?(re=r("Execution count"),e[106]=r,e[107]=re):re=e[107];let xe;e[108]!==re?(xe=t(De,{value:"execCount",children:re}),e[108]=re,e[109]=xe):xe=e[109];let pe;e[110]!==r?(pe=r("Rows read"),e[110]=r,e[111]=pe):pe=e[111];let be;e[112]!==pe?(be=t(De,{value:"rowsRead",children:pe}),e[112]=pe,e[113]=be):be=e[113];let ve;e[114]!==F||e[115]!==z||e[116]!==xe||e[117]!==be?(ve=n(kt,{children:[F,z,xe,be]}),e[114]=F,e[115]=z,e[116]=xe,e[117]=be,e[118]=ve):ve=e[118];let Ne;e[119]!==a||e[120]!==te||e[121]!==ve?(Ne=n(_t,{onValueChange:v,value:a,children:[te,ve]}),e[119]=a,e[120]=te,e[121]=ve,e[122]=Ne):Ne=e[122];let ye;e[123]!==Z||e[124]!==Ne?(ye=n("div",{className:"flex items-center gap-2",children:[Z,Ne]}),e[123]=Z,e[124]=Ne,e[125]=ye):ye=e[125];let $e;e[126]!==X||e[127]!==ye?($e=n("div",{className:"flex items-center justify-between",children:[X,ye]}),e[126]=X,e[127]=ye,e[128]=$e):$e=e[128];let we;e[129]!==r?(we=r("Statements"),e[129]=r,e[130]=we):we=e[130];let Se;e[131]!==we?(Se=t(Re,{children:we}),e[131]=we,e[132]=Se):Se=e[132];let qe;e[133]!==m.length||e[134]!==r?(qe=r("{count} tracked statements",{count:m.length}),e[133]=m.length,e[134]=r,e[135]=qe):qe=e[135];let ke;e[136]!==qe?(ke=t(ct,{children:qe}),e[136]=qe,e[137]=ke):ke=e[137];let _e;e[138]!==Se||e[139]!==ke?(_e=n(Te,{children:[Se,ke]}),e[138]=Se,e[139]=ke,e[140]=_e):_e=e[140];let Me;e[141]!==f||e[142]!==m||e[143]!==r?(Me=t(fe,{children:t("div",{className:"space-y-2",children:m.map(d=>{const C=d.normalizedSql,_=f.has(C),ue=je(d.avgDurationMs);return n("div",{className:"overflow-hidden rounded-lg border","data-testid":"qi-row",children:[n("button",{"aria-expanded":_,className:"flex w-full items-center justify-between p-3 text-left transition-colors hover:bg-muted/50",onClick:()=>{se(C)},type:"button",children:[n("div",{className:"flex min-w-0 flex-1 items-center gap-3",children:[t(At,{level:ue}),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:Qe(d.totalDurationMs)}),t("div",{className:"text-xs text-muted-foreground",children:r("total")})]}),n("div",{className:"text-right",children:[t("div",{className:"text-sm font-medium",children:Qe(d.avgDurationMs)}),t("div",{className:"text-xs text-muted-foreground",children:r("avg")})]}),n("div",{className:"text-right",children:[t("div",{className:"text-sm font-medium",children:Le(d.execCount)}),t("div",{className:"text-xs text-muted-foreground",children:r("calls")})]})]})]}),_&&n("div",{className:"space-y-3 border-t bg-muted/30 p-4",children:[n("div",{children:[t("p",{className:"mb-2 text-sm font-medium",children:r("Full statement")}),t("pre",{className:"overflow-x-auto rounded-md bg-muted p-3 font-mono text-sm whitespace-pre-wrap break-all",children:d.normalizedSql})]}),n("div",{className:"grid grid-cols-2 gap-4 text-sm md:grid-cols-4",children:[n("div",{children:[t("span",{className:"text-muted-foreground",children:r("Exec count")}),t("span",{className:"block font-medium tabular-nums",children:Le(d.execCount)})]}),n("div",{children:[t("span",{className:"text-muted-foreground",children:r("Total time")}),t("span",{className:"block font-medium tabular-nums",children:Qe(d.totalDurationMs)})]}),n("div",{children:[t("span",{className:"text-muted-foreground",children:r("Rows read")}),t("span",{className:"block font-medium tabular-nums",children:Le(d.rowsRead)})]}),n("div",{children:[t("span",{className:"text-muted-foreground",children:r("Rows written")}),t("span",{className:"block font-medium tabular-nums",children:Le(d.rowsWritten)})]})]})]})]},C)})})}),e[141]=f,e[142]=m,e[143]=r,e[144]=Me):Me=e[144];let Ie;e[145]!==_e||e[146]!==Me?(Ie=n(he,{children:[_e,Me]}),e[145]=_e,e[146]=Me,e[147]=Ie):Ie=e[147];let Ce;return e[148]!==H||e[149]!==$e||e[150]!==Ie?(Ce=n("div",{className:"space-y-4","data-testid":"qi-root",children:[H,$e,Ie]}),e[148]=H,e[149]=$e,e[150]=Ie,e[151]=Ce):Ce=e[151],Ce};function Et(s){return je(s.avgDurationMs)==="critical"}function jt(s){return je(s.avgDurationMs)==="warning"}function Kt(s){return je(s.avgDurationMs)==="good"}const Pt=ft(ze.getMetrics),Ut=s=>{const e=Math.floor(s/1e3),l=Math.floor(e/3600),r=Math.floor(e%3600/60),a=e%60;return l>0?`${l.toString()}h ${r.toString()}m`:r>0?`${r.toString()}m ${a.toString()}s`:`${a.toString()}s`},Jt=(s,e)=>s?e:"overview",Qt=(s,e)=>{const l=s+e;return l===0?"—":`${(s/l*100).toFixed(1)}%`},ne=s=>{const e=Fe(16),{chart:l,footer:r,label:a,testId:p,value:b}=s;let f;e[0]!==a?(f=t("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:a}),e[0]=a,e[1]=f):f=e[1];let h;e[2]!==p||e[3]!==b?(h=t("span",{className:"truncate text-2xl font-semibold tabular-nums text-foreground","data-testid":p,children:b}),e[2]=p,e[3]=b,e[4]=h):h=e[4];let g;e[5]!==l||e[6]!==h?(g=n("div",{className:"flex items-center justify-between gap-3",children:[h,l]}),e[5]=l,e[6]=h,e[7]=g):g=e[7];let v;e[8]!==f||e[9]!==g?(v=n("div",{className:"flex flex-col gap-2.5 p-4",children:[f,g]}),e[8]=f,e[9]=g,e[10]=v):v=e[10];let u;e[11]!==r?(u=r!=null&&t("div",{className:"border-t border-border bg-muted/50 px-4 py-2.5 text-[11px] text-muted-foreground",children:r}),e[11]=r,e[12]=u):u=e[12];let m;return e[13]!==v||e[14]!==u?(m=n(he,{className:"justify-between gap-0 py-0",children:[v,u]}),e[13]=v,e[14]=u,e[15]=m):m=e[15],m},fr=({initialShardKey:s})=>{const e=lt(),l=Ee(),r=st(),[a,p]=ge(s??""),[b,f]=ge("overview"),[h,g]=ge([]),v=Ke(null),u=Ke(null),m=Ke(!0);Be(()=>(m.current=!0,()=>{m.current=!1}),[]);const N=dt(a.trim(),400),le=i=>{bt({shardKey:N,traceId:i}),Ge(r({to:"/traces"}))},{data:O,error:j,liveError:K}=He(ze.getMetrics,{},{live:!0,shardKey:N}),c=O??null;Be(()=>{if(O===void 0)return;xt(N);const i=O,k=v.current,y=u.current!==null&&u.current!==i.shard;if(u.current=i.shard,v.current=i.requests,y){g([]);return}k!==null&&i.requests>=k&&g(w=>[...w,i.requests-k].slice(-30))},[O,N]);const[S,se]=ge(null),[T,R]=ge(!1),I=async()=>{R(!0);const i=wt(a,pt());try{const k=await Promise.all(i.map(async y=>{try{const w=await e.query(Pt,{},ht(y));return{error:null,metrics:w,shard:y===""?w.shard:y}}catch(w){return{error:gt(w),metrics:null,shard:y===""?"__root__":y}}}));m.current&&se(k)}finally{m.current&&R(!1)}},x=S===null?null:Nt(S),D=c===null||c.requests===0?"—":`${(c.errors/c.requests*100).toFixed(1)}%`,E=h.length>0?h.at(-1):0,M=c?yt(c):{p90:0,p95:0},L=i=>i<=0?"—":i<1?`${(i*1e3).toFixed(0)}μs`:i<1e3?`${i.toFixed(1)}ms`:`${(i/1e3).toFixed(2)}s`,$=nt(()=>{if(!c||!("queryStats"in c))return;const i=c.queryStats;if(!(!i||!Array.isArray(i)))return $t(i)},[c]),q=Jt($!==void 0,b),oe=()=>{Ge(I())},de=()=>{se(null)},me=()=>{f("overview")},P=()=>{f("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(ot,{onChange:p,testId:"mt-shard-input",value:a}),t(it,{message:K,prefix:"mt"}),t(Ve,{"data-testid":"mt-aggregate",disabled:T,onClick:oe,size:"sm",type:"button",variant:"secondary",children:l(T?"Aggregating…":"All shards")}),S!==null&&t(Ve,{"data-testid":"mt-aggregate-clear",onClick:de,size:"sm",type:"button",variant:"ghost",children:l("Hide")}),t("a",{className:"text-sm text-primary underline-offset-4 hover:underline","data-testid":"mt-cf-link",href:mt,rel:"noreferrer",target:"_blank",children:l("Open in Cloudflare")})]}),j!==null&&t("p",{className:"text-sm text-destructive","data-testid":"mt-error",role:"alert",children:j}),$!==void 0&&n("div",{className:"flex gap-2 border-b","data-testid":"mt-tabs",children:[t("button",{className:`pb-2 text-sm font-medium transition-colors ${q==="overview"?"border-b-2 border-primary text-foreground":"text-muted-foreground hover:text-foreground"}`,"data-testid":"mt-tab-overview",onClick:me,type:"button",children:l("Overview")}),n("button",{className:`pb-2 text-sm font-medium transition-colors ${q==="query-insights"?"border-b-2 border-primary text-foreground":"text-muted-foreground hover:text-foreground"}`,"data-testid":"mt-tab-query-insights",onClick:P,type:"button",children:[l("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})]})]}),q==="query-insights"&&$!==void 0&&t(zt,{queryStats:$}),q==="overview"&&c!==null&&n("dl",{className:"grid gap-3 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4","data-testid":"mt-stats",children:[t(ne,{chart:h.length>=2?t(tt,{ariaLabel:l("Requests per interval over time"),className:"h-7 w-24 text-foreground",series:h,testId:"mt-sparkline"}):void 0,footer:h.length>=2?n(Ue,{children:[t("span",{className:"font-semibold text-foreground",children:`+${E.toLocaleString()}`})," ",l("last interval")]}):t("span",{"data-testid":"mt-sparkline-empty",children:l("collecting samples…")}),label:l("Requests"),testId:"mt-requests",value:c.requests}),t(ne,{footer:l("{rate} error rate",{rate:D}),label:l("Errors"),testId:"mt-errors",value:n(Ue,{children:[c.errors," (",D,")"]})}),t(ne,{footer:M.p90>0?`P90 ${L(M.p90)}`:void 0,label:l("P95 latency"),testId:"mt-p95",value:M.p95>0?L(M.p95):"—"}),t(ne,{footer:c.cache===null?void 0:`${c.cache.entries.toLocaleString()} ${l("cache entries")}`,label:l("Database size"),testId:"mt-db-size",value:Pe(c.databaseSize)}),t(ne,{label:l("Shard"),testId:"mt-shard",value:c.shard}),t(ne,{label:l("Uptime"),testId:"mt-uptime",value:Ut(c.uptimeMs)}),t(ne,{label:l("Cache hit rate"),testId:"mt-cache",value:c.cache===null?l("no cache configured"):l("{rate} ({count} entries)",{count:c.cache.entries,rate:Qt(c.cache.hits,c.cache.misses)})})]}),q==="overview"&&c===null&&null,q==="overview"&&t(Lt,{onOpenTrace:le,shardKey:N}),q==="overview"&&x!==null&&S!==null&&n("div",{className:"flex flex-col gap-4","data-testid":"mt-aggregate-view",children:[n("dl",{className:"grid gap-3 sm:grid-cols-2 lg:grid-cols-3","data-testid":"mt-aggregate-stats",children:[t(ne,{label:l("Shards"),testId:"mt-agg-shards",value:x.failed>0?l("{reachable} reachable, {failed} unreachable",{failed:x.failed,reachable:x.reachable}):l("{reachable} reachable",{reachable:x.reachable})}),t(ne,{label:l("Total requests"),testId:"mt-agg-requests",value:x.totalRequests}),t(ne,{label:l("Total errors"),testId:"mt-agg-errors",value:x.totalErrors}),t(ne,{label:l("Total database size"),testId:"mt-agg-db-size",value:Pe(x.totalDatabaseSize)}),t(ne,{label:l("Combined cache hit rate"),testId:"mt-agg-cache",value:x.hitRate===null?l("no cache configured"):`${(x.hitRate*100).toFixed(1)}%`})]}),t(he,{className:"overflow-hidden py-0",children:t(fe,{className:"px-0",children:n(Ye,{"data-testid":"mt-agg-table",children:[t(Xe,{children:n(Ae,{children:[t(ie,{children:l("shard")}),t(ie,{children:l("requests")}),t(ie,{children:l("errors")}),t(ie,{children:l("db size")})]})}),t(Ze,{children:S.map(i=>n(Ae,{"data-testid":`mt-agg-row-${i.shard}`,children:[t(ae,{children:i.shard}),i.metrics===null?t(ae,{className:"text-destructive",colSpan:3,children:i.error??l("unreachable")}):n(Ue,{children:[t(ae,{className:"tabular-nums",children:i.metrics.requests}),t(ae,{className:"tabular-nums",children:i.metrics.errors}),t(ae,{className:"tabular-nums",children:Pe(i.metrics.databaseSize)})]})]},i.shard))})]})})})]})]})};export{fr as MetricsPanel};
@@ -1 +1 @@
1
- import{useLunora as z}from"@lunora/react";import{useState as a,useEffect as O}from"react";import{ConfirmButton as P}from"../packem_shared/ConfirmButton-CTL3f3kr.js";import{E as q}from"../packem_shared/error-alert-B59DnrDI.js";import{L as H}from"../packem_shared/live-status-CGW2JHf_.js";import{ShardInput as U}from"../packem_shared/ShardInput-BVn2iCU0.js";import{g as W}from"../packem_shared/badge-BbuuAio7.js";import{u as _}from"../packem_shared/button-BkCrNcAs.js";import{c as G,u as J}from"../packem_shared/card-CIDGUN6K.js";import{E as Q}from"../packem_shared/empty-state-Cg7t_8qu.js";import{u as V}from"../packem_shared/input-JHu63lTv.js";import{p as $}from"../packem_shared/label-6uP1obNF.js";import{n as X,d as Y,m as k,p as n,f as Z,u as o}from"../packem_shared/table-DdJBrClo.js";import{K as rr}from"../packem_shared/use-admin-query-Di3fLE8H.js";import er from"../packem_shared/useDebounced-Ihdiid_k.js";import{useT as tr}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as R}from"../packem_shared/ADMIN_FUNCTIONS-BYNSbBVE.js";import{i as ir,f as ar,c as nr,e as or,a as dr}from"../packem_shared/internal-AtZ4bTal.js";import{r as sr}from"../packem_shared/shard-history-DMEW5VBE.js";import{jsxs as i,jsx as r}from"react/jsx-runtime";const lr=dr(R.runMigration),Er=({initialShardKey:C})=>{const L=z(),e=tr(),[c,M]=a(C??""),[v,S]=a(""),[x,E]=a("up"),[h,I]=a(!0),[m,y]=a(!1),[s,p]=a(null),[b,g]=a(null),u=er(c.trim(),400),w=c.trim()===u,d=rr(R.migrationStatus,{},{live:!0,shardKey:u}),l=d.data?.migrations??null,D=d.error,{errorSource:A,liveError:j}=d;O(()=>{d.data!==void 0&&sr(u)},[d.data,u]);const K=async()=>{const t=v.trim();if(t===""){g(e("Enter a migration id")),p(null);return}y(!0),g(null);try{const f=await L.query(lr,{direction:x,dryRun:h,id:t},nr(c));p(f),d.refetch()}catch(f){p(null),g(or(f))}finally{y(!1)}},N=()=>{ar(K())},T=t=>{S(t.target.value)},B=t=>{E(t.target.value==="down"?"down":"up")},F=t=>{I(t.target.checked)};return i("div",{className:"flex flex-col gap-3","data-testid":"lunora-migrations",children:[i("div",{className:"flex flex-wrap items-center gap-2",children:[r(U,{onChange:M,testId:"mg-shard-input",value:c}),r(H,{message:j,prefix:"mg"})]}),D!==null&&r(q,{error:A,testId:"mg-status-error"}),l!==null&&l.length===0&&r(Q,{description:e("Data migrations you run against this shard will be tracked here."),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 12a8 8 0 0 1 13.7-5.6L20 8M20 4v4h-4M20 12a8 8 0 0 1-13.7 5.6L4 16m0 4v-4h4"})}),testId:"mg-empty",title:e("No migrations have run on this shard.")}),l!==null&&l.length>0&&r(G,{className:"overflow-hidden py-0",children:r(J,{className:"px-0",children:i(X,{"data-testid":"mg-table",children:[r(Y,{children:i(k,{children:[r(n,{children:e("id")}),r(n,{children:e("direction")}),r(n,{children:e("status")}),r(n,{children:e("processed")}),r(n,{children:e("changed")}),r(n,{children:e("updated")}),r(n,{children:e("error")})]})}),r(Z,{children:l.map(t=>i(k,{"data-testid":`mg-row-${t.id}`,children:[r(o,{children:t.id}),r(o,{children:t.direction}),r(o,{children:r(W,{variant:"secondary",children:t.status})}),r(o,{children:t.processed}),r(o,{children:t.changed}),r(o,{children:ir(t.updatedAt)}),r(o,{children:t.error??""})]},t.id))})]})})}),i("div",{className:"flex flex-col gap-2 rounded-xl border border-border bg-card p-3 shadow-xs",children:[r($,{children:e("Run migration")}),i("div",{className:"flex flex-wrap items-center gap-2",children:[r(V,{"aria-label":e("Migration id"),className:"w-auto","data-testid":"mg-id-input",onChange:T,placeholder:e("migration id"),value:v}),i("select",{"aria-label":e("Direction"),className:"flex h-9 rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring","data-testid":"mg-direction",onChange:B,value:x,children:[r("option",{value:"up",children:e("up")}),r("option",{value:"down",children:e("down")})]}),i($,{className:"flex items-center gap-1.5",htmlFor:"mg-dry-run",children:[r("input",{checked:h,className:"size-4 accent-primary","data-testid":"mg-dry-run",id:"mg-dry-run",onChange:F,type:"checkbox"}),e("Dry run")]}),h?r(_,{"data-testid":"mg-run",disabled:m||!w,onClick:N,size:"sm",type:"button",children:e(m?"Running…":"Run")}):r(P,{confirmLabel:e(m?"Running…":"Run migration?"),disabled:m||!w,onConfirm:N,testId:"mg-run",children:e("Run")})]})]}),b!==null&&r("pre",{className:"text-sm text-destructive whitespace-pre-wrap","data-testid":"mg-run-error",role:"alert",children:b}),s!==null&&i("p",{className:"text-sm text-muted-foreground","data-testid":"mg-run-result",children:[s.dryRun?e("Dry run: "):"",e("{status} — processed",{status:s.status}),s.processed,e(", changed"),s.changed]})]})};export{Er as MigrationsPanel};
1
+ import{useLunora as z}from"@lunora/react";import{useState as a,useEffect as O}from"react";import{ConfirmButton as P}from"../packem_shared/ConfirmButton-CTL3f3kr.js";import{E as q}from"../packem_shared/error-alert-B59DnrDI.js";import{L as H}from"../packem_shared/live-status-CGW2JHf_.js";import{ShardInput as U}from"../packem_shared/ShardInput-BVn2iCU0.js";import{g as W}from"../packem_shared/badge-BbuuAio7.js";import{u as _}from"../packem_shared/button-BkCrNcAs.js";import{c as G,u as J}from"../packem_shared/card-CIDGUN6K.js";import{E as Q}from"../packem_shared/empty-state-Cg7t_8qu.js";import{u as V}from"../packem_shared/input-JHu63lTv.js";import{p as $}from"../packem_shared/label-6uP1obNF.js";import{n as X,d as Y,m as k,p as n,f as Z,u as o}from"../packem_shared/table-DdJBrClo.js";import{K as rr}from"../packem_shared/use-admin-query-Di3fLE8H.js";import er from"../packem_shared/useDebounced-Ihdiid_k.js";import{useT as tr}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as R}from"../packem_shared/ADMIN_FUNCTIONS-CpgIo9pj.js";import{i as ir,f as ar,c as nr,e as or,a as dr}from"../packem_shared/internal-AtZ4bTal.js";import{r as sr}from"../packem_shared/shard-history-DMEW5VBE.js";import{jsxs as i,jsx as r}from"react/jsx-runtime";const lr=dr(R.runMigration),Er=({initialShardKey:C})=>{const L=z(),e=tr(),[c,M]=a(C??""),[v,S]=a(""),[x,E]=a("up"),[h,I]=a(!0),[m,y]=a(!1),[s,p]=a(null),[b,g]=a(null),u=er(c.trim(),400),w=c.trim()===u,d=rr(R.migrationStatus,{},{live:!0,shardKey:u}),l=d.data?.migrations??null,D=d.error,{errorSource:A,liveError:j}=d;O(()=>{d.data!==void 0&&sr(u)},[d.data,u]);const K=async()=>{const t=v.trim();if(t===""){g(e("Enter a migration id")),p(null);return}y(!0),g(null);try{const f=await L.query(lr,{direction:x,dryRun:h,id:t},nr(c));p(f),d.refetch()}catch(f){p(null),g(or(f))}finally{y(!1)}},N=()=>{ar(K())},T=t=>{S(t.target.value)},B=t=>{E(t.target.value==="down"?"down":"up")},F=t=>{I(t.target.checked)};return i("div",{className:"flex flex-col gap-3","data-testid":"lunora-migrations",children:[i("div",{className:"flex flex-wrap items-center gap-2",children:[r(U,{onChange:M,testId:"mg-shard-input",value:c}),r(H,{message:j,prefix:"mg"})]}),D!==null&&r(q,{error:A,testId:"mg-status-error"}),l!==null&&l.length===0&&r(Q,{description:e("Data migrations you run against this shard will be tracked here."),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 12a8 8 0 0 1 13.7-5.6L20 8M20 4v4h-4M20 12a8 8 0 0 1-13.7 5.6L4 16m0 4v-4h4"})}),testId:"mg-empty",title:e("No migrations have run on this shard.")}),l!==null&&l.length>0&&r(G,{className:"overflow-hidden py-0",children:r(J,{className:"px-0",children:i(X,{"data-testid":"mg-table",children:[r(Y,{children:i(k,{children:[r(n,{children:e("id")}),r(n,{children:e("direction")}),r(n,{children:e("status")}),r(n,{children:e("processed")}),r(n,{children:e("changed")}),r(n,{children:e("updated")}),r(n,{children:e("error")})]})}),r(Z,{children:l.map(t=>i(k,{"data-testid":`mg-row-${t.id}`,children:[r(o,{children:t.id}),r(o,{children:t.direction}),r(o,{children:r(W,{variant:"secondary",children:t.status})}),r(o,{children:t.processed}),r(o,{children:t.changed}),r(o,{children:ir(t.updatedAt)}),r(o,{children:t.error??""})]},t.id))})]})})}),i("div",{className:"flex flex-col gap-2 rounded-xl border border-border bg-card p-3 shadow-xs",children:[r($,{children:e("Run migration")}),i("div",{className:"flex flex-wrap items-center gap-2",children:[r(V,{"aria-label":e("Migration id"),className:"w-auto","data-testid":"mg-id-input",onChange:T,placeholder:e("migration id"),value:v}),i("select",{"aria-label":e("Direction"),className:"flex h-9 rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring","data-testid":"mg-direction",onChange:B,value:x,children:[r("option",{value:"up",children:e("up")}),r("option",{value:"down",children:e("down")})]}),i($,{className:"flex items-center gap-1.5",htmlFor:"mg-dry-run",children:[r("input",{checked:h,className:"size-4 accent-primary","data-testid":"mg-dry-run",id:"mg-dry-run",onChange:F,type:"checkbox"}),e("Dry run")]}),h?r(_,{"data-testid":"mg-run",disabled:m||!w,onClick:N,size:"sm",type:"button",children:e(m?"Running…":"Run")}):r(P,{confirmLabel:e(m?"Running…":"Run migration?"),disabled:m||!w,onConfirm:N,testId:"mg-run",children:e("Run")})]})]}),b!==null&&r("pre",{className:"text-sm text-destructive whitespace-pre-wrap","data-testid":"mg-run-error",role:"alert",children:b}),s!==null&&i("p",{className:"text-sm text-muted-foreground","data-testid":"mg-run-result",children:[s.dryRun?e("Dry run: "):"",e("{status} — processed",{status:s.status}),s.processed,e(", changed"),s.changed]})]})};export{Er as MigrationsPanel};
@@ -1 +1 @@
1
- import{c as W}from"react/compiler-runtime";import{useState as T}from"react";import{E as B}from"../packem_shared/error-alert-B59DnrDI.js";import{g as _}from"../packem_shared/badge-BbuuAio7.js";import{u as z}from"../packem_shared/button-BkCrNcAs.js";import{c as K,u as O}from"../packem_shared/card-CIDGUN6K.js";import{E as U}from"../packem_shared/empty-state-Cg7t_8qu.js";import{u as q}from"../packem_shared/input-JHu63lTv.js";import{n as G,d as J,m as F,p as h,f as Q,u as f}from"../packem_shared/table-DdJBrClo.js";import{K as X}from"../packem_shared/use-admin-query-Di3fLE8H.js";import{useT as Y}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as Z}from"../packem_shared/ADMIN_FUNCTIONS-BYNSbBVE.js";import{i as ee}from"../packem_shared/internal-AtZ4bTal.js";import{jsx as t,jsxs as x}from"react/jsx-runtime";const te=e=>e==="ok"?"success":e==="failed"?"destructive":e==="expired"?"warning":"secondary",P=e=>e.endpoint??e.id,ve=()=>{const e=W(38),r=Y(),[i,R]=T("all"),[s,V]=T("");let g;e[0]===Symbol.for("react.memo_cache_sentinel")?(g={},e[0]=g):g=e[0];const{data:S,error:o,errorSource:p,isLoading:C,refetch:v}=X(Z.listPushSubscriptions,g);let N;if(e[1]!==S?.subscriptions||e[2]!==o||e[3]!==p||e[4]!==C||e[5]!==i||e[6]!==v||e[7]!==s||e[8]!==r){const A=S?.subscriptions??[],j=s.trim().toLowerCase(),E=A.filter(a=>i!=="all"&&a.kind!==i?!1:j===""?!0:`${P(a)} ${a.userId??""}`.toLowerCase().includes(j));let b;e[10]===Symbol.for("react.memo_cache_sentinel")?(b=a=>{V(a.target.value)},e[10]=b):b=e[10];const D=b;let w;e[11]!==v?(w=()=>{v()},e[11]=v,e[12]=w):w=e[12];const I=w;let y;e[13]===Symbol.for("react.memo_cache_sentinel")?(y=["all","web-push","fcm"],e[13]=y):y=e[13];const H=y;let l;e[14]!==i||e[15]!==r?(l=t("div",{className:"flex items-center gap-1","data-testid":"nt-kind-filter",role:"tablist",children:H.map(a=>t(z,{"aria-selected":i===a,"data-testid":`nt-kind-${a}`,onClick:()=>{R(a)},role:"tab",size:"sm",type:"button",variant:i===a?"secondary":"ghost",children:a==="all"?r("All"):a},a))}),e[14]=i,e[15]=r,e[16]=l):l=e[16];let n;e[17]!==r?(n=r("Filter devices"),e[17]=r,e[18]=n):n=e[18];let c;e[19]!==r?(c=r("filter endpoint, user"),e[19]=r,e[20]=c):c=e[20];let d;e[21]!==s||e[22]!==n||e[23]!==c?(d=t(q,{"aria-label":n,className:"h-8 w-56","data-testid":"nt-search",onChange:D,placeholder:c,value:s}),e[21]=s,e[22]=n,e[23]=c,e[24]=d):d=e[24];let m;e[25]!==r?(m=r("Refresh"),e[25]=r,e[26]=m):m=e[26];let u;e[27]!==I||e[28]!==m?(u=t(z,{className:"ml-auto","data-testid":"nt-refresh",onClick:I,size:"sm",type:"button",variant:"outline",children:m}),e[27]=I,e[28]=m,e[29]=u):u=e[29];const L=A.length>0&&t(_,{"data-testid":"nt-count",variant:"secondary",children:r("{count} devices",{count:A.length})});let $;e[30]!==u||e[31]!==L||e[32]!==l||e[33]!==d?($=x("div",{className:"flex flex-wrap items-center gap-2",children:[l,d,u,L]}),e[30]=u,e[31]=L,e[32]=l,e[33]=d,e[34]=$):$=e[34];let k;e[35]!==o||e[36]!==p?(k=o!==null&&t(B,{error:p,testId:"nt-error"}),e[35]=o,e[36]=p,e[37]=k):k=e[37],N=x("div",{className:"flex flex-col gap-4","data-testid":"lunora-notifications",children:[$,k,o===null&&!C&&E.length===0&&t(U,{description:r("Registered Web Push / FCM devices appear here. Configure lunora/notify.ts with defineNotify({ store }) and register a device with ctx.push.register(...)."),icon:t("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:t("path",{d:"M15 17h5l-1.4-1.4A2 2 0 0 1 18 14.2V11a6 6 0 0 0-4-5.7V5a2 2 0 1 0-4 0v.3A6 6 0 0 0 6 11v3.2a2 2 0 0 1-.6 1.4L4 17h5m6 0v1a3 3 0 1 1-6 0v-1m6 0H9"})}),testId:"nt-empty",title:r("No registered devices.")}),E.length>0&&t(K,{className:"overflow-hidden py-0",children:t(O,{className:"max-h-[30rem] overflow-auto px-0",children:x(G,{"data-testid":"nt-table",children:[t(J,{children:x(F,{children:[t(h,{children:r("kind")}),t(h,{children:r("endpoint")}),t(h,{children:r("user")}),t(h,{children:r("last seen")}),t(h,{children:r("status")}),t(h,{children:r("error")})]})}),t(Q,{children:E.map(a=>{const M=P(a);return x(F,{"data-testid":"nt-row",children:[t(f,{children:t(_,{variant:"outline",children:a.kind})}),t(f,{className:"max-w-[28ch] truncate font-mono text-xs",title:M,children:M}),t(f,{className:"max-w-[16ch] truncate font-mono text-xs",children:a.userId??t("span",{className:"text-muted-foreground",children:"—"})}),t(f,{className:"text-muted-foreground tabular-nums",children:ee(a.lastSeenAt,"—")}),t(f,{children:t(_,{"data-testid":`nt-status-${a.id}`,variant:te(a.lastStatus),children:a.lastStatus??r("n/a")})}),t(f,{className:"max-w-[28ch] truncate font-mono text-xs text-muted-foreground",title:a.lastError??void 0,children:a.lastError??t("span",{className:"text-muted-foreground",children:"—"})})]},a.id)})})]})})})]}),e[1]=S?.subscriptions,e[2]=o,e[3]=p,e[4]=C,e[5]=i,e[6]=v,e[7]=s,e[8]=r,e[9]=N}else N=e[9];return N};export{ve as NotificationsPanel};
1
+ import{c as W}from"react/compiler-runtime";import{useState as T}from"react";import{E as B}from"../packem_shared/error-alert-B59DnrDI.js";import{g as _}from"../packem_shared/badge-BbuuAio7.js";import{u as z}from"../packem_shared/button-BkCrNcAs.js";import{c as K,u as O}from"../packem_shared/card-CIDGUN6K.js";import{E as U}from"../packem_shared/empty-state-Cg7t_8qu.js";import{u as q}from"../packem_shared/input-JHu63lTv.js";import{n as G,d as J,m as F,p as h,f as Q,u as f}from"../packem_shared/table-DdJBrClo.js";import{K as X}from"../packem_shared/use-admin-query-Di3fLE8H.js";import{useT as Y}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as Z}from"../packem_shared/ADMIN_FUNCTIONS-CpgIo9pj.js";import{i as ee}from"../packem_shared/internal-AtZ4bTal.js";import{jsx as t,jsxs as x}from"react/jsx-runtime";const te=e=>e==="ok"?"success":e==="failed"?"destructive":e==="expired"?"warning":"secondary",P=e=>e.endpoint??e.id,ve=()=>{const e=W(38),r=Y(),[i,R]=T("all"),[s,V]=T("");let g;e[0]===Symbol.for("react.memo_cache_sentinel")?(g={},e[0]=g):g=e[0];const{data:S,error:o,errorSource:p,isLoading:C,refetch:v}=X(Z.listPushSubscriptions,g);let N;if(e[1]!==S?.subscriptions||e[2]!==o||e[3]!==p||e[4]!==C||e[5]!==i||e[6]!==v||e[7]!==s||e[8]!==r){const A=S?.subscriptions??[],j=s.trim().toLowerCase(),E=A.filter(a=>i!=="all"&&a.kind!==i?!1:j===""?!0:`${P(a)} ${a.userId??""}`.toLowerCase().includes(j));let b;e[10]===Symbol.for("react.memo_cache_sentinel")?(b=a=>{V(a.target.value)},e[10]=b):b=e[10];const D=b;let w;e[11]!==v?(w=()=>{v()},e[11]=v,e[12]=w):w=e[12];const I=w;let y;e[13]===Symbol.for("react.memo_cache_sentinel")?(y=["all","web-push","fcm"],e[13]=y):y=e[13];const H=y;let l;e[14]!==i||e[15]!==r?(l=t("div",{className:"flex items-center gap-1","data-testid":"nt-kind-filter",role:"tablist",children:H.map(a=>t(z,{"aria-selected":i===a,"data-testid":`nt-kind-${a}`,onClick:()=>{R(a)},role:"tab",size:"sm",type:"button",variant:i===a?"secondary":"ghost",children:a==="all"?r("All"):a},a))}),e[14]=i,e[15]=r,e[16]=l):l=e[16];let n;e[17]!==r?(n=r("Filter devices"),e[17]=r,e[18]=n):n=e[18];let c;e[19]!==r?(c=r("filter endpoint, user"),e[19]=r,e[20]=c):c=e[20];let d;e[21]!==s||e[22]!==n||e[23]!==c?(d=t(q,{"aria-label":n,className:"h-8 w-56","data-testid":"nt-search",onChange:D,placeholder:c,value:s}),e[21]=s,e[22]=n,e[23]=c,e[24]=d):d=e[24];let m;e[25]!==r?(m=r("Refresh"),e[25]=r,e[26]=m):m=e[26];let u;e[27]!==I||e[28]!==m?(u=t(z,{className:"ml-auto","data-testid":"nt-refresh",onClick:I,size:"sm",type:"button",variant:"outline",children:m}),e[27]=I,e[28]=m,e[29]=u):u=e[29];const L=A.length>0&&t(_,{"data-testid":"nt-count",variant:"secondary",children:r("{count} devices",{count:A.length})});let $;e[30]!==u||e[31]!==L||e[32]!==l||e[33]!==d?($=x("div",{className:"flex flex-wrap items-center gap-2",children:[l,d,u,L]}),e[30]=u,e[31]=L,e[32]=l,e[33]=d,e[34]=$):$=e[34];let k;e[35]!==o||e[36]!==p?(k=o!==null&&t(B,{error:p,testId:"nt-error"}),e[35]=o,e[36]=p,e[37]=k):k=e[37],N=x("div",{className:"flex flex-col gap-4","data-testid":"lunora-notifications",children:[$,k,o===null&&!C&&E.length===0&&t(U,{description:r("Registered Web Push / FCM devices appear here. Configure lunora/notify.ts with defineNotify({ store }) and register a device with ctx.push.register(...)."),icon:t("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:t("path",{d:"M15 17h5l-1.4-1.4A2 2 0 0 1 18 14.2V11a6 6 0 0 0-4-5.7V5a2 2 0 1 0-4 0v.3A6 6 0 0 0 6 11v3.2a2 2 0 0 1-.6 1.4L4 17h5m6 0v1a3 3 0 1 1-6 0v-1m6 0H9"})}),testId:"nt-empty",title:r("No registered devices.")}),E.length>0&&t(K,{className:"overflow-hidden py-0",children:t(O,{className:"max-h-[30rem] overflow-auto px-0",children:x(G,{"data-testid":"nt-table",children:[t(J,{children:x(F,{children:[t(h,{children:r("kind")}),t(h,{children:r("endpoint")}),t(h,{children:r("user")}),t(h,{children:r("last seen")}),t(h,{children:r("status")}),t(h,{children:r("error")})]})}),t(Q,{children:E.map(a=>{const M=P(a);return x(F,{"data-testid":"nt-row",children:[t(f,{children:t(_,{variant:"outline",children:a.kind})}),t(f,{className:"max-w-[28ch] truncate font-mono text-xs",title:M,children:M}),t(f,{className:"max-w-[16ch] truncate font-mono text-xs",children:a.userId??t("span",{className:"text-muted-foreground",children:"—"})}),t(f,{className:"text-muted-foreground tabular-nums",children:ee(a.lastSeenAt,"—")}),t(f,{children:t(_,{"data-testid":`nt-status-${a.id}`,variant:te(a.lastStatus),children:a.lastStatus??r("n/a")})}),t(f,{className:"max-w-[28ch] truncate font-mono text-xs text-muted-foreground",title:a.lastError??void 0,children:a.lastError??t("span",{className:"text-muted-foreground",children:"—"})})]},a.id)})})]})})})]}),e[1]=S?.subscriptions,e[2]=o,e[3]=p,e[4]=C,e[5]=i,e[6]=v,e[7]=s,e[8]=r,e[9]=N}else N=e[9];return N};export{ve as NotificationsPanel};
@@ -1 +1 @@
1
- import{useLunora as E}from"@lunora/react";import{useState as s,useCallback as H,useEffect as W}from"react";import{ConfirmButton as F}from"../packem_shared/ConfirmButton-CTL3f3kr.js";import{g as Z}from"../packem_shared/badge-BbuuAio7.js";import{u as _}from"../packem_shared/button-BkCrNcAs.js";import{u as I}from"../packem_shared/input-JHu63lTv.js";import{p as g}from"../packem_shared/label-6uP1obNF.js";import{useAutoRefresh as G}from"../packem_shared/DEFAULT_AUTO_REFRESH_MS-BCC8_4BQ.js";import{useT as J}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as B}from"../packem_shared/ADMIN_FUNCTIONS-BYNSbBVE.js";import{c as u,e as y,f as p,a as S}from"../packem_shared/internal-AtZ4bTal.js";import{jsxs as a,jsx as r}from"react/jsx-runtime";const N=S(B.getPitrBookmark),Q=S(B.pitrRestore),de=({initialShardKey:T})=>{const m=E(),t=J(),l=T??"",[O,f]=s(null),[i,P]=s(""),[v,w]=s(null),[c,q]=s(""),[h,A]=s(!1),[o,L]=s(null),[C,n]=s(null),[x,d]=s(!1),k=H(async()=>{d(!0),n(null);try{const e=await m.query(N,{},u(l));f(e.current)}catch(e){n(y(e))}finally{d(!1)}},[m,l]);W(()=>{p(k())},[k]),G(()=>{p((async()=>{try{const e=await m.query(N,{},u(l));f(e.current)}catch{}})())},!0);const U=e=>{P(e.target.value)},j=e=>{q(e.target.value)},M=e=>{A(e.target.checked)},z=()=>{i.trim()!==""&&p((async()=>{d(!0),n(null);try{const e=await m.query(N,{time:i.trim()},u(l));w(e.forTime??null),f(e.current)}catch(e){w(null),n(y(e))}finally{d(!1)}})())},R=e=>{p((async()=>{d(!0),n(null);try{const b=await m.mutation(Q,e,u(l));L(b),await k()}catch(b){n(y(b))}finally{d(!1)}})())},K=c.trim()!==""||i.trim()!=="",$=()=>{const e=h?{restart:!0}:{};c.trim()===""?e.time=i.trim():e.bookmark=c.trim(),R(e)},D=()=>{o!==null&&R(h?{bookmark:o.undoBookmark,restart:!0}:{bookmark:o.undoBookmark})};return a("div",{className:"flex flex-col gap-4","data-testid":"lunora-pitr",children:[r("div",{className:"flex flex-wrap items-center gap-3",children:a("span",{className:"text-xs text-muted-foreground",children:[t("Shard"),": ",r("span",{className:"font-mono",children:l===""?t("root"):l})]})}),r("p",{className:"text-sm text-muted-foreground","data-testid":"pitr-note",children:t("In-place recovery to any moment in the last 30 days. For older or portable recovery, use the snapshot backup tier.")}),C!==null&&r("p",{className:"text-sm text-destructive","data-testid":"pitr-error",role:"alert",children:C}),a("section",{className:"rounded-xl border border-border bg-card p-3 shadow-xs",children:[r("h3",{className:"mb-2 text-sm font-semibold",children:t("Current bookmark")}),r("p",{className:"font-mono text-xs break-all text-muted-foreground","data-testid":"pitr-current",children:O??r("span",{className:"text-muted-foreground",children:"—"})})]}),a("section",{className:"flex flex-col gap-3 rounded-xl border border-border bg-card p-3 shadow-xs",children:[r("h3",{className:"text-sm font-semibold",children:t("Restore")}),a("div",{className:"flex flex-col gap-1",children:[r(g,{htmlFor:"pitr-time",children:t("Time (ISO or epoch-ms, last 30 days)")}),a("div",{className:"flex items-center gap-2",children:[r(I,{"data-testid":"pitr-time",id:"pitr-time",onChange:U,placeholder:"2026-06-01T00:00:00.000Z",value:i}),r(_,{"data-testid":"pitr-preview",disabled:x||i.trim()==="",onClick:z,size:"sm",type:"button",variant:"outline",children:t("Preview")})]}),v!==null&&a("p",{className:"font-mono text-xs break-all text-muted-foreground","data-testid":"pitr-preview-bookmark",children:[t("Bookmark for that time"),": ",v]})]}),a("div",{className:"flex flex-col gap-1",children:[r(g,{htmlFor:"pitr-bookmark",children:t("Or an explicit bookmark (wins over time)")}),r(I,{"data-testid":"pitr-bookmark",id:"pitr-bookmark",onChange:j,placeholder:t("bookmark string"),value:c})]}),a(g,{className:"flex items-center gap-2 text-xs font-normal text-muted-foreground",htmlFor:"pitr-restart",children:[r("input",{checked:h,className:"size-4 accent-primary","data-testid":"pitr-restart",id:"pitr-restart",onChange:M,type:"checkbox"}),t("Restart the shard now so recovery applies immediately")]}),r("div",{children:r(F,{confirmLabel:t("Confirm restore"),disabled:x||!K,onConfirm:$,testId:"pitr-restore",children:t("Restore")})})]}),o!==null&&a("section",{className:"flex flex-col gap-2 rounded-xl border border-border bg-card p-3 shadow-xs","data-testid":"pitr-result",children:[a("div",{className:"flex items-center gap-2",children:[r("h3",{className:"text-sm font-semibold",children:t("Restore armed")}),r(Z,{variant:o.restarted?"destructive":"secondary",children:o.restarted?t("restarted now"):t("on next restart")})]}),a("p",{className:"font-mono text-xs break-all text-muted-foreground",children:[t("Restored to"),": ",o.restoredTo]}),a("p",{className:"font-mono text-xs break-all text-muted-foreground","data-testid":"pitr-undo-bookmark",children:[t("Undo bookmark"),": ",o.undoBookmark]}),r("div",{children:r(F,{confirmLabel:t("Confirm undo"),disabled:x,onConfirm:D,testId:"pitr-undo",children:t("Undo restore")})})]})]})};export{de as PitrPanel};
1
+ import{useLunora as E}from"@lunora/react";import{useState as s,useCallback as H,useEffect as W}from"react";import{ConfirmButton as F}from"../packem_shared/ConfirmButton-CTL3f3kr.js";import{g as Z}from"../packem_shared/badge-BbuuAio7.js";import{u as _}from"../packem_shared/button-BkCrNcAs.js";import{u as I}from"../packem_shared/input-JHu63lTv.js";import{p as g}from"../packem_shared/label-6uP1obNF.js";import{useAutoRefresh as G}from"../packem_shared/DEFAULT_AUTO_REFRESH_MS-BCC8_4BQ.js";import{useT as J}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as B}from"../packem_shared/ADMIN_FUNCTIONS-CpgIo9pj.js";import{c as u,e as y,f as p,a as S}from"../packem_shared/internal-AtZ4bTal.js";import{jsxs as a,jsx as r}from"react/jsx-runtime";const N=S(B.getPitrBookmark),Q=S(B.pitrRestore),de=({initialShardKey:T})=>{const m=E(),t=J(),l=T??"",[O,f]=s(null),[i,P]=s(""),[v,w]=s(null),[c,q]=s(""),[h,A]=s(!1),[o,L]=s(null),[C,n]=s(null),[x,d]=s(!1),k=H(async()=>{d(!0),n(null);try{const e=await m.query(N,{},u(l));f(e.current)}catch(e){n(y(e))}finally{d(!1)}},[m,l]);W(()=>{p(k())},[k]),G(()=>{p((async()=>{try{const e=await m.query(N,{},u(l));f(e.current)}catch{}})())},!0);const U=e=>{P(e.target.value)},j=e=>{q(e.target.value)},M=e=>{A(e.target.checked)},z=()=>{i.trim()!==""&&p((async()=>{d(!0),n(null);try{const e=await m.query(N,{time:i.trim()},u(l));w(e.forTime??null),f(e.current)}catch(e){w(null),n(y(e))}finally{d(!1)}})())},R=e=>{p((async()=>{d(!0),n(null);try{const b=await m.mutation(Q,e,u(l));L(b),await k()}catch(b){n(y(b))}finally{d(!1)}})())},K=c.trim()!==""||i.trim()!=="",$=()=>{const e=h?{restart:!0}:{};c.trim()===""?e.time=i.trim():e.bookmark=c.trim(),R(e)},D=()=>{o!==null&&R(h?{bookmark:o.undoBookmark,restart:!0}:{bookmark:o.undoBookmark})};return a("div",{className:"flex flex-col gap-4","data-testid":"lunora-pitr",children:[r("div",{className:"flex flex-wrap items-center gap-3",children:a("span",{className:"text-xs text-muted-foreground",children:[t("Shard"),": ",r("span",{className:"font-mono",children:l===""?t("root"):l})]})}),r("p",{className:"text-sm text-muted-foreground","data-testid":"pitr-note",children:t("In-place recovery to any moment in the last 30 days. For older or portable recovery, use the snapshot backup tier.")}),C!==null&&r("p",{className:"text-sm text-destructive","data-testid":"pitr-error",role:"alert",children:C}),a("section",{className:"rounded-xl border border-border bg-card p-3 shadow-xs",children:[r("h3",{className:"mb-2 text-sm font-semibold",children:t("Current bookmark")}),r("p",{className:"font-mono text-xs break-all text-muted-foreground","data-testid":"pitr-current",children:O??r("span",{className:"text-muted-foreground",children:"—"})})]}),a("section",{className:"flex flex-col gap-3 rounded-xl border border-border bg-card p-3 shadow-xs",children:[r("h3",{className:"text-sm font-semibold",children:t("Restore")}),a("div",{className:"flex flex-col gap-1",children:[r(g,{htmlFor:"pitr-time",children:t("Time (ISO or epoch-ms, last 30 days)")}),a("div",{className:"flex items-center gap-2",children:[r(I,{"data-testid":"pitr-time",id:"pitr-time",onChange:U,placeholder:"2026-06-01T00:00:00.000Z",value:i}),r(_,{"data-testid":"pitr-preview",disabled:x||i.trim()==="",onClick:z,size:"sm",type:"button",variant:"outline",children:t("Preview")})]}),v!==null&&a("p",{className:"font-mono text-xs break-all text-muted-foreground","data-testid":"pitr-preview-bookmark",children:[t("Bookmark for that time"),": ",v]})]}),a("div",{className:"flex flex-col gap-1",children:[r(g,{htmlFor:"pitr-bookmark",children:t("Or an explicit bookmark (wins over time)")}),r(I,{"data-testid":"pitr-bookmark",id:"pitr-bookmark",onChange:j,placeholder:t("bookmark string"),value:c})]}),a(g,{className:"flex items-center gap-2 text-xs font-normal text-muted-foreground",htmlFor:"pitr-restart",children:[r("input",{checked:h,className:"size-4 accent-primary","data-testid":"pitr-restart",id:"pitr-restart",onChange:M,type:"checkbox"}),t("Restart the shard now so recovery applies immediately")]}),r("div",{children:r(F,{confirmLabel:t("Confirm restore"),disabled:x||!K,onConfirm:$,testId:"pitr-restore",children:t("Restore")})})]}),o!==null&&a("section",{className:"flex flex-col gap-2 rounded-xl border border-border bg-card p-3 shadow-xs","data-testid":"pitr-result",children:[a("div",{className:"flex items-center gap-2",children:[r("h3",{className:"text-sm font-semibold",children:t("Restore armed")}),r(Z,{variant:o.restarted?"destructive":"secondary",children:o.restarted?t("restarted now"):t("on next restart")})]}),a("p",{className:"font-mono text-xs break-all text-muted-foreground",children:[t("Restored to"),": ",o.restoredTo]}),a("p",{className:"font-mono text-xs break-all text-muted-foreground","data-testid":"pitr-undo-bookmark",children:[t("Undo bookmark"),": ",o.undoBookmark]}),r("div",{children:r(F,{confirmLabel:t("Confirm undo"),disabled:x,onConfirm:D,testId:"pitr-undo",children:t("Undo restore")})})]})]})};export{de as PitrPanel};