@lunora/studio 1.0.0-alpha.346 → 1.0.0-alpha.348

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 (63) hide show
  1. package/dist/standalone/{chunk-JVGG53MB.js → chunk-2PMCHTCC.js} +1 -1
  2. package/dist/standalone/{chunk-WTV4RQSJ.js → chunk-34OJ2OXP.js} +1 -1
  3. package/dist/standalone/{chunk-YXP64PAM.js → chunk-3FWAGIOT.js} +1 -1
  4. package/dist/standalone/{chunk-QBHBARC7.js → chunk-4GHCKQLY.js} +1 -1
  5. package/dist/standalone/{chunk-ZGAGB7A3.js → chunk-4HYPC5NN.js} +1 -1
  6. package/dist/standalone/{chunk-TJRANF5R.js → chunk-4TYCTORB.js} +1 -1
  7. package/dist/standalone/{chunk-XWTIKXCE.js → chunk-5TQHZVNN.js} +1 -1
  8. package/dist/standalone/{chunk-TCINSNB6.js → chunk-5YLFS5NU.js} +1 -1
  9. package/dist/standalone/{chunk-3HLLOLQA.js → chunk-6BELLPMP.js} +1 -1
  10. package/dist/standalone/{chunk-PE7PZDTO.js → chunk-6FZLAL4W.js} +1 -1
  11. package/dist/standalone/{chunk-B6MQIRHD.js → chunk-6TJHYXQW.js} +1 -1
  12. package/dist/standalone/{chunk-5GUYGF6M.js → chunk-6XPDVZVB.js} +1 -1
  13. package/dist/standalone/{chunk-AF5MBRCX.js → chunk-ATVMUIBN.js} +1 -1
  14. package/dist/standalone/{chunk-PFAXMXYQ.js → chunk-AVSMQPR3.js} +3 -3
  15. package/dist/standalone/{chunk-3JMBYPK4.js → chunk-B57UZJ6W.js} +1 -1
  16. package/dist/standalone/{chunk-4U54WFRN.js → chunk-BOMFGCKX.js} +1 -1
  17. package/dist/standalone/{chunk-N2KGAFCZ.js → chunk-C7SAXSO3.js} +1 -1
  18. package/dist/standalone/{chunk-N3UPEA6I.js → chunk-E4Y6TF6C.js} +1 -1
  19. package/dist/standalone/{chunk-MK4JCUYB.js → chunk-EFGDGZHN.js} +1 -1
  20. package/dist/standalone/{chunk-Y5HDOWSF.js → chunk-EGYPW6UY.js} +1 -1
  21. package/dist/standalone/{chunk-OIKMDNJQ.js → chunk-EPI4SHLN.js} +1 -1
  22. package/dist/standalone/{chunk-QVUGGQ7V.js → chunk-FTN4XJOQ.js} +1 -1
  23. package/dist/standalone/{chunk-RGGZK22L.js → chunk-GDP3S4GQ.js} +1 -1
  24. package/dist/standalone/{chunk-KZJ5IOS2.js → chunk-GZEWLX7U.js} +1 -1
  25. package/dist/standalone/{chunk-ZBTIU4HD.js → chunk-IIU4TZRG.js} +1 -1
  26. package/dist/standalone/{chunk-URHYIB3N.js → chunk-IQ3SMVFW.js} +1 -1
  27. package/dist/standalone/{chunk-LLSYLN5P.js → chunk-JD6SCY7V.js} +1 -1
  28. package/dist/standalone/{chunk-57EABO5S.js → chunk-JGUKFZ3R.js} +1 -1
  29. package/dist/standalone/{chunk-YPPGH4NA.js → chunk-JLQPIE3Z.js} +1 -1
  30. package/dist/standalone/{chunk-2CMEIEJR.js → chunk-KCPZ4P6C.js} +1 -1
  31. package/dist/standalone/{chunk-Y6XR3J3F.js → chunk-KEHDC5BQ.js} +1 -1
  32. package/dist/standalone/{chunk-6RDZ3RY2.js → chunk-L4BDA4VZ.js} +1 -1
  33. package/dist/standalone/{chunk-XV6RRMU4.js → chunk-LI2GRPOB.js} +1 -1
  34. package/dist/standalone/{chunk-3HVIUFSK.js → chunk-M7HCYBJJ.js} +1 -1
  35. package/dist/standalone/{chunk-VB43XZB7.js → chunk-MFZF7GEM.js} +1 -1
  36. package/dist/standalone/{chunk-XF3J4GW4.js → chunk-MT4E42PB.js} +1 -1
  37. package/dist/standalone/{chunk-SPGCHADE.js → chunk-N45O7D5G.js} +1 -1
  38. package/dist/standalone/{chunk-YKICSMGF.js → chunk-NARRSYMQ.js} +1 -1
  39. package/dist/standalone/{chunk-YGBF5K76.js → chunk-PQ6DUCKC.js} +1 -1
  40. package/dist/standalone/{chunk-A5CPAQN4.js → chunk-PTIKIQY6.js} +1 -1
  41. package/dist/standalone/{chunk-A6FR5AGG.js → chunk-QDHFLZ3N.js} +1 -1
  42. package/dist/standalone/{chunk-QJ5XNVMG.js → chunk-R37RA67H.js} +1 -1
  43. package/dist/standalone/{chunk-UFHZX7TT.js → chunk-R457VG7L.js} +1 -1
  44. package/dist/standalone/{chunk-EXYGAGPA.js → chunk-R75AFV7G.js} +1 -1
  45. package/dist/standalone/{chunk-J2GDX4FP.js → chunk-RLVR5BRF.js} +1 -1
  46. package/dist/standalone/{chunk-ZC5UIV3L.js → chunk-RTWSDGPV.js} +1 -1
  47. package/dist/standalone/{chunk-DYVZYYYT.js → chunk-SQYX2Z5H.js} +1 -1
  48. package/dist/standalone/{chunk-NM6ZWVHT.js → chunk-T2JHVL34.js} +1 -1
  49. package/dist/standalone/{chunk-XCIF2IN3.js → chunk-TNPF3XGI.js} +1 -1
  50. package/dist/standalone/{chunk-TOZJLFTE.js → chunk-TVSU6RYZ.js} +1 -1
  51. package/dist/standalone/{chunk-4IVPXVFO.js → chunk-U7KUGVBB.js} +1 -1
  52. package/dist/standalone/{chunk-QUMSA7YN.js → chunk-UD7BKB4T.js} +1 -1
  53. package/dist/standalone/{chunk-IBWKMX3K.js → chunk-UJFT3C53.js} +1 -1
  54. package/dist/standalone/{chunk-ZUG3TS2J.js → chunk-V7IFSDTT.js} +1 -1
  55. package/dist/standalone/{chunk-6NIZKJVH.js → chunk-WQW4IPHB.js} +1 -1
  56. package/dist/standalone/{chunk-OHYRDHPE.js → chunk-XCVO3IAH.js} +1 -1
  57. package/dist/standalone/{chunk-VLMI4DES.js → chunk-XCWVO6DI.js} +1 -1
  58. package/dist/standalone/{chunk-VMGUS3ZD.js → chunk-XEGAP64U.js} +1 -1
  59. package/dist/standalone/{chunk-GTQ5GYU3.js → chunk-XJPJSZ4W.js} +1 -1
  60. package/dist/standalone/{chunk-OEZ5JUSS.js → chunk-XR2JH2A7.js} +1 -1
  61. package/dist/standalone/{chunk-WO5ULVRR.js → chunk-XT6GSN64.js} +1 -1
  62. package/dist/standalone/studio.js +1 -1
  63. package/package.json +4 -4
@@ -1 +1 @@
1
- import{d as E,e as _}from"./chunk-CVXNHIQW.js";import{a as $}from"./chunk-253UHWDX.js";import{a as de}from"./chunk-WW7D5RFR.js";import{a as ce}from"./chunk-K2EHRNYW.js";import"./chunk-VESGIGMQ.js";import"./chunk-TET2ESOI.js";import"./chunk-AUGKHAMQ.js";import"./chunk-WJRYEML4.js";import{a as le}from"./chunk-R6U22RSY.js";import{a as re}from"./chunk-7Q256NLI.js";import"./chunk-ZKJS6EBE.js";import"./chunk-RGMVGZV4.js";import"./chunk-OQ6I6OXT.js";import"./chunk-E4PXACVL.js";import"./chunk-MVWZMWPD.js";import"./chunk-SJQERRSZ.js";import"./chunk-7Y3SY37W.js";import"./chunk-AUAECCXB.js";import{b as K}from"./chunk-Q6ED4KUL.js";import"./chunk-BOMPSVRC.js";import{a as ie}from"./chunk-EXYGAGPA.js";import"./chunk-NCPW7WHO.js";import"./chunk-URHYIB3N.js";import"./chunk-55UGUCQ6.js";import{a as J}from"./chunk-4ZEL6BYL.js";import{c as H}from"./chunk-NM6ZWVHT.js";import"./chunk-PFAXMXYQ.js";import"./chunk-QAQDMS6R.js";import"./chunk-3I25WO3P.js";import{a as ne}from"./chunk-RWVIV3U7.js";import{a as R,b as W,c as Z,d as A,e as M,f as S}from"./chunk-HCTJKP5J.js";import{a as q,b as D,c as U,e as oe}from"./chunk-2IKDEUCX.js";import{d as F,u as ae}from"./chunk-74IYYDDI.js";import{a as p,d as se,f as be,g as ge}from"./chunk-I26MS5PJ.js";var O=se(be(),1);var o=se(ge(),1);var G="gen_ai.usage.input_tokens",Q="gen_ai.usage.output_tokens",V="gen_ai.usage.cost",fe="gen_ai.request.model",Te="lunora.usage.cost.source",xe=new Set(["ai.embed","ai.generate","ai.stream"]),ue=6e4,Ce=1440,ve="unknown",X=p(()=>({calls:0,estimatedCost:0,inputTokens:0,outputTokens:0,providerCost:0}),"q"),Y=p((n,e)=>{let s=n?.[e];return typeof s=="string"&&s!==""?s:void 0},"J"),z=p((n,e)=>{let s=n?.[e];return typeof s=="number"&&Number.isFinite(s)?s:void 0},"L"),ee=p(n=>Y(n,Te)==="provider"?"provider":"estimated","Q"),me=p((n,e)=>n.reduce((s,a)=>s+e(a),0),"Y"),B=p(n=>n.providerCost+n.estimatedCost,"F"),ke=p(n=>n.estimatedCost>0?n.providerCost>0?"mixed":"estimated":n.providerCost>0?"provider":"none","ae"),ye=p((n,e)=>({calls:n.calls+e.calls,estimatedCost:n.estimatedCost+e.estimatedCost,inputTokens:n.inputTokens+e.inputTokens,outputTokens:n.outputTokens+e.outputTokens,providerCost:n.providerCost+e.providerCost}),"ce"),Ie=p(n=>{let e=X(),s=0,a=0,t=0;for(let c of n){let l=me(c.points,i=>i.sum),r=me(c.points,i=>i.count);c.name===G?(e.inputTokens+=l,s+=r):c.name===Q?(e.outputTokens+=l,a+=r):(t+=r,ee(c.attributes)==="provider"?e.providerCost+=l:e.estimatedCost+=l)}return e.calls=Math.max(s,a,t),e},"ge"),Ne=p((n,e)=>B(e)-B(n)||e.inputTokens+e.outputTokens-(n.inputTokens+n.outputTokens)||n.key.localeCompare(e.key),"Ne"),pe=p((n,e)=>{let s=new Map;for(let a of n){let t=e(a);s.set(t,{key:t,...ye(s.get(t)??X(),a)})}return[...s.values()].toSorted(Ne)},"Z"),we=p(n=>(n?.series??[]).filter(e=>e.name===G||e.name===Q||e.name===V),"xe"),Me=p(n=>Y(n.attributes,fe)??ve,"Se"),Se=p(n=>{let e=new Map;for(let s of n){let a=Me(s),t=JSON.stringify([s.functionPath,a]),c=e.get(t)??{functionPath:s.functionPath,model:a,series:[]};c.series.push(s),e.set(t,c)}return[...e.values()].map(({functionPath:s,model:a,series:t})=>({functionPath:s,model:a,...Ie(t)}))},"Ie"),_e=p(n=>{let e=new Map;for(let r of n){if(r.name!==V)continue;let i=ee(r.attributes)==="provider";for(let u of r.points){let m=e.get(u.bucketMs)??{bucketMs:u.bucketMs,estimatedCost:0,providerCost:0};i?m.providerCost+=u.sum:m.estimatedCost+=u.sum,e.set(u.bucketMs,m)}}let s=[...e.keys()].toSorted((r,i)=>r-i),a=s[0],t=s.at(-1);if(a===void 0||t===void 0)return[];let c=Math.max(a,t-(Ce-1)*ue),l=[];for(let r=c;r<=t;r+=ue)l.push(e.get(r)??{bucketMs:r,estimatedCost:0,providerCost:0});return l},"_e"),Pe=p(n=>{let e=[];for(let s of n)for(let a of s.spans){if(!xe.has(a.name))continue;let{attributes:t}=a,c=z(t,V),l=z(t,G),r=z(t,Q);e.push({...c===void 0?{}:{cost:c,costSource:ee(t)},functionPath:s.functionPath,...l===void 0?{}:{inputTokens:l},model:Y(t,fe)??ve,ok:a.ok,...r===void 0?{}:{outputTokens:r},startTs:s.startTs+a.offsetMs,streaming:a.name==="ai.stream",traceId:s.traceId})}return e.toSorted((s,a)=>a.startTs-s.startTs)},"Me"),Fe=p(n=>n.map(e=>{let s=e.cost??0;return{calls:1,estimatedCost:e.costSource==="provider"?0:s,functionPath:e.functionPath,inputTokens:e.inputTokens??0,model:e.model,outputTokens:e.outputTokens??0,providerCost:e.costSource==="provider"?s:0}}),"Oe"),Oe=p((n,e)=>{let s=we(n),a=Pe(e),t=s.length>0,c=t?Se(s):Fe(a),l=X(),r="none";for(let i of c)l=ye(l,i);return t?r="history":a.length>0&&(r="live"),{byFunction:pe(c,i=>i.functionPath),byModel:pe(c,i=>i.model),calls:a,source:r,totals:l,trend:t?_e(s):[]}},"Ae"),Ke=p(n=>Array.isArray(n?.traces)?n.traces:[],"Ee"),Ae=25,te=p(n=>{let e=(0,O.c)(16),{provenance:s,value:a}=n,t=F();if(s==="none"){let m;return e[0]===Symbol.for("react.memo_cache_sentinel")?(m=(0,o.jsx)("span",{className:"text-muted-foreground",children:"\u2014"}),e[0]=m):m=e[0],m}let c;e[1]!==s||e[2]!==a?(c=s==="provider"?E(a):`~${E(a)}`,e[1]=s,e[2]=a,e[3]=c):c=e[3];let l;e[4]!==c?(l=(0,o.jsx)("span",{className:"tabular-nums",children:c}),e[4]=c,e[5]=l):l=e[5];let r;e[6]!==s||e[7]!==t?(r=s==="estimated"?(0,o.jsx)(K,{title:t("Derived from a price table, not reported by the provider."),variant:"warning",children:t("Estimated")}):null,e[6]=s,e[7]=t,e[8]=r):r=e[8];let i;e[9]!==s||e[10]!==t?(i=s==="mixed"?(0,o.jsx)(K,{title:t("Includes cost derived from a price table, not reported by the provider."),variant:"warning",children:t("Partly estimated")}):null,e[9]=s,e[10]=t,e[11]=i):i=e[11];let u;return e[12]!==l||e[13]!==r||e[14]!==i?(u=(0,o.jsxs)("span",{className:"inline-flex items-center gap-2",children:[l,r,i]}),e[12]=l,e[13]=r,e[14]=i,e[15]=u):u=e[15],u},"V"),he=p(n=>{let e=(0,O.c)(40),{keyLabel:s,rows:a,testId:t,title:c}=n,l=F(),r;e[0]!==c?(r=(0,o.jsx)(D,{className:"px-4 py-3",children:(0,o.jsx)(U,{children:c})}),e[0]=c,e[1]=r):r=e[1];let i;e[2]!==s?(i=(0,o.jsx)(M,{children:s}),e[2]=s,e[3]=i):i=e[3];let u;e[4]!==l?(u=l("Calls"),e[4]=l,e[5]=u):u=e[5];let m;e[6]!==u?(m=(0,o.jsx)(M,{className:"text-end",children:u}),e[6]=u,e[7]=m):m=e[7];let k;e[8]!==l?(k=l("Input tokens"),e[8]=l,e[9]=k):k=e[9];let y;e[10]!==k?(y=(0,o.jsx)(M,{className:"text-end",children:k}),e[10]=k,e[11]=y):y=e[11];let b;e[12]!==l?(b=l("Output tokens"),e[12]=l,e[13]=b):b=e[13];let T;e[14]!==b?(T=(0,o.jsx)(M,{className:"text-end",children:b}),e[14]=b,e[15]=T):T=e[15];let g;e[16]!==l?(g=l("Cost"),e[16]=l,e[17]=g):g=e[17];let d;e[18]!==g?(d=(0,o.jsx)(M,{className:"text-end",children:g}),e[18]=g,e[19]=d):d=e[19];let x;e[20]!==d||e[21]!==i||e[22]!==m||e[23]!==y||e[24]!==T?(x=(0,o.jsx)(W,{children:(0,o.jsxs)(A,{children:[i,m,y,T,d]})}),e[20]=d,e[21]=i,e[22]=m,e[23]=y,e[24]=T,e[25]=x):x=e[25];let h;if(e[26]!==a||e[27]!==t){let N;e[29]!==t?(N=p(w=>(0,o.jsxs)(A,{"data-testid":`${t}-row`,children:[(0,o.jsx)(S,{className:"max-w-[280px] truncate font-mono",title:w.key,children:w.key}),(0,o.jsx)(S,{className:"text-end tabular-nums",children:_(w.calls)}),(0,o.jsx)(S,{className:"text-end tabular-nums",children:_(w.inputTokens)}),(0,o.jsx)(S,{className:"text-end tabular-nums",children:_(w.outputTokens)}),(0,o.jsx)(S,{className:"text-end",children:(0,o.jsx)(te,{provenance:ke(w),value:B(w)})})]},w.key),"x"),e[29]=t,e[30]=N):N=e[30],h=a.map(N),e[26]=a,e[27]=t,e[28]=h}else h=e[28];let f;e[31]!==h?(f=(0,o.jsx)(Z,{children:h}),e[31]=h,e[32]=f):f=e[32];let v;e[33]!==x||e[34]!==f?(v=(0,o.jsxs)(R,{children:[x,f]}),e[33]=x,e[34]=f,e[35]=v):v=e[35];let C;return e[36]!==r||e[37]!==v||e[38]!==t?(C=(0,o.jsxs)(q,{className:"gap-0 py-0","data-testid":t,children:[r,v]}),e[36]=r,e[37]=v,e[38]=t,e[39]=C):C=e[39],C},"ee"),$e=p(n=>{let e=(0,O.c)(55),{calls:s,onOpenTrace:a}=n,t=F(),c;e[0]!==t?(c=t("Recent calls"),e[0]=t,e[1]=c):c=e[1];let l;e[2]!==c?(l=(0,o.jsx)(D,{className:"px-4 py-3",children:(0,o.jsx)(U,{children:c})}),e[2]=c,e[3]=l):l=e[3];let r;e[4]!==t?(r=t("When"),e[4]=t,e[5]=r):r=e[5];let i;e[6]!==r?(i=(0,o.jsx)(M,{children:r}),e[6]=r,e[7]=i):i=e[7];let u;e[8]!==t?(u=t("Function"),e[8]=t,e[9]=u):u=e[9];let m;e[10]!==u?(m=(0,o.jsx)(M,{children:u}),e[10]=u,e[11]=m):m=e[11];let k;e[12]!==t?(k=t("Model"),e[12]=t,e[13]=k):k=e[13];let y;e[14]!==k?(y=(0,o.jsx)(M,{children:k}),e[14]=k,e[15]=y):y=e[15];let b;e[16]!==t?(b=t("Input tokens"),e[16]=t,e[17]=b):b=e[17];let T;e[18]!==b?(T=(0,o.jsx)(M,{className:"text-end",children:b}),e[18]=b,e[19]=T):T=e[19];let g;e[20]!==t?(g=t("Output tokens"),e[20]=t,e[21]=g):g=e[21];let d;e[22]!==g?(d=(0,o.jsx)(M,{className:"text-end",children:g}),e[22]=g,e[23]=d):d=e[23];let x;e[24]!==t?(x=t("Cost"),e[24]=t,e[25]=x):x=e[25];let h;e[26]!==x?(h=(0,o.jsx)(M,{className:"text-end",children:x}),e[26]=x,e[27]=h):h=e[27];let f;e[28]!==t?(f=t("Trace"),e[28]=t,e[29]=f):f=e[29];let v;e[30]!==f?(v=(0,o.jsx)(M,{children:f}),e[30]=f,e[31]=v):v=e[31];let C;e[32]!==T||e[33]!==d||e[34]!==h||e[35]!==v||e[36]!==i||e[37]!==m||e[38]!==y?(C=(0,o.jsx)(W,{children:(0,o.jsxs)(A,{children:[i,m,y,T,d,h,v]})}),e[32]=T,e[33]=d,e[34]=h,e[35]=v,e[36]=i,e[37]=m,e[38]=y,e[39]=C):C=e[39];let N;if(e[40]!==s||e[41]!==a||e[42]!==t){let j;e[44]!==a||e[45]!==t?(j=p(I=>(0,o.jsxs)(A,{"data-testid":"ai-call",children:[(0,o.jsx)(S,{className:"font-mono text-muted-foreground",children:ae(I.startTs)}),(0,o.jsx)(S,{className:"font-mono",children:(0,o.jsxs)("span",{className:"inline-flex items-center gap-2",children:[I.functionPath,I.streaming?(0,o.jsx)(K,{variant:"outline",children:t("stream")}):null,I.ok?null:(0,o.jsx)(K,{variant:"destructive",children:t("failed")})]})}),(0,o.jsx)(S,{className:"max-w-[240px] truncate font-mono",title:I.model,children:I.model}),(0,o.jsx)(S,{className:"text-end tabular-nums",children:I.inputTokens===void 0?"\u2014":_(I.inputTokens)}),(0,o.jsx)(S,{className:"text-end tabular-nums",children:I.outputTokens===void 0?"\u2014":_(I.outputTokens)}),(0,o.jsx)(S,{className:"text-end",children:(0,o.jsx)(te,{provenance:I.cost===void 0?"none":I.costSource??"estimated",value:I.cost??0})}),(0,o.jsx)(S,{children:(0,o.jsx)("button",{className:"font-mono text-muted-foreground underline-offset-2 hover:underline",onClick:p(()=>{a(I.traceId)},"onClick"),title:t("Open the trace {trace}",{trace:I.traceId}),type:"button",children:I.traceId.slice(0,8)})})]},`${I.traceId}:${I.startTs.toString()}:${I.model}`),"U"),e[44]=a,e[45]=t,e[46]=j):j=e[46],N=s.slice(0,Ae).map(j),e[40]=s,e[41]=a,e[42]=t,e[43]=N}else N=e[43];let w;e[47]!==N?(w=(0,o.jsx)(Z,{children:N}),e[47]=N,e[48]=w):w=e[48];let P;e[49]!==C||e[50]!==w?(P=(0,o.jsxs)(R,{children:[C,w]}),e[49]=C,e[50]=w,e[51]=P):P=e[51];let L;return e[52]!==l||e[53]!==P?(L=(0,o.jsxs)(q,{className:"gap-0 py-0","data-testid":"ai-calls",children:[l,P]}),e[52]=l,e[53]=P,e[54]=L):L=e[54],L},"Pe"),Ee=p(n=>{let e=(0,O.c)(48),{totals:s,trend:a}=n,t=F(),c;e[0]!==s?(c=ke(s),e[0]=s,e[1]=c):c=e[1];let l=c,r;e[2]!==t||e[3]!==a?(r=a.length>=2?(0,o.jsx)(de,{ariaLabel:t("Cost per minute"),className:"h-7 w-24",series:a,testId:"ai-trend"}):void 0,e[2]=t,e[3]=a,e[4]=r):r=e[4];let i;e[5]!==l||e[6]!==t||e[7]!==s.estimatedCost||e[8]!==s.providerCost?(i=l==="none"?t("No cost reported"):(0,o.jsx)("span",{"data-testid":"ai-cost-split",children:t("{provider} provider-reported \xB7 {estimated} estimated",{estimated:E(s.estimatedCost),provider:E(s.providerCost)})}),e[5]=l,e[6]=t,e[7]=s.estimatedCost,e[8]=s.providerCost,e[9]=i):i=e[9];let u;e[10]!==t?(u=t("Total cost"),e[10]=t,e[11]=u):u=e[11];let m;e[12]!==s?(m=B(s),e[12]=s,e[13]=m):m=e[13];let k;e[14]!==l||e[15]!==m?(k=(0,o.jsx)(te,{provenance:l,value:m}),e[14]=l,e[15]=m,e[16]=k):k=e[16];let y;e[17]!==r||e[18]!==i||e[19]!==u||e[20]!==k?(y=(0,o.jsx)($,{chart:r,footer:i,label:u,testId:"ai-total-cost",value:k}),e[17]=r,e[18]=i,e[19]=u,e[20]=k,e[21]=y):y=e[21];let b;e[22]!==t?(b=t("Input tokens"),e[22]=t,e[23]=b):b=e[23];let T;e[24]!==s.inputTokens?(T=_(s.inputTokens),e[24]=s.inputTokens,e[25]=T):T=e[25];let g;e[26]!==b||e[27]!==T?(g=(0,o.jsx)($,{label:b,testId:"ai-input-tokens",value:T}),e[26]=b,e[27]=T,e[28]=g):g=e[28];let d;e[29]!==t?(d=t("Output tokens"),e[29]=t,e[30]=d):d=e[30];let x;e[31]!==s.outputTokens?(x=_(s.outputTokens),e[31]=s.outputTokens,e[32]=x):x=e[32];let h;e[33]!==d||e[34]!==x?(h=(0,o.jsx)($,{label:d,testId:"ai-output-tokens",value:x}),e[33]=d,e[34]=x,e[35]=h):h=e[35];let f;e[36]!==t?(f=t("Calls"),e[36]=t,e[37]=f):f=e[37];let v;e[38]!==s.calls?(v=_(s.calls),e[38]=s.calls,e[39]=v):v=e[39];let C;e[40]!==f||e[41]!==v?(C=(0,o.jsx)($,{label:f,testId:"ai-calls-total",value:v}),e[40]=f,e[41]=v,e[42]=C):C=e[42];let N;return e[43]!==g||e[44]!==h||e[45]!==C||e[46]!==y?(N=(0,o.jsxs)("dl",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4","data-testid":"ai-totals",children:[y,g,h,C]}),e[43]=g,e[44]=h,e[45]=C,e[46]=y,e[47]=N):N=e[47],N},"Ue"),Ye=p(n=>{let e=(0,O.c)(28),{initialShardKey:s}=n,a=F(),{queryShardKey:t,setShardKey:c,shardKey:l}=le(s),r=ce(t),i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i={},e[0]=i):i=e[0];let u;e[1]!==t?(u={live:!0,shardKey:t},e[1]=t,e[2]=u):u=e[2];let{data:m,error:k}=H(J.getTraces,i,u),y;e[3]===Symbol.for("react.memo_cache_sentinel")?(y={},e[3]=y):y=e[3];let b;e[4]!==t?(b={live:!0,shardKey:t},e[4]=t,e[5]=b):b=e[5];let{data:T}=H(J.getMetricHistory,y,b),g,d;e[6]!==m||e[7]!==T?(d=Oe(T,Ke(m)),g=d.trend.map(Le),e[6]=m,e[7]=T,e[8]=g,e[9]=d):(g=e[8],d=e[9]);let x=g,h;e[10]!==c||e[11]!==l?(h=(0,o.jsx)(re,{onChange:c,testId:"ai-shard-input",value:l}),e[10]=c,e[11]=l,e[12]=h):h=e[12];let f;e[13]!==k?(f=k===null?null:(0,o.jsx)(ie,{error:k,testId:"ai-error"}),e[13]=k,e[14]=f):f=e[14];let v;e[15]!==r||e[16]!==a||e[17]!==x||e[18]!==d.byFunction||e[19]!==d.byModel||e[20]!==d.calls||e[21]!==d.source||e[22]!==d.totals?(v=d.source==="none"?(0,o.jsx)(ne,{description:a("Spend shows up here once an action calls ctx.ai.model(...) \u2014 tokens and cost per function and per model."),testId:"ai-empty",title:a("No AI usage recorded")}):(0,o.jsxs)(o.Fragment,{children:[d.source==="live"?(0,o.jsx)("p",{className:"text-xs text-muted-foreground","data-testid":"ai-live-only",children:a("No durable history yet \u2014 these totals come from the live trace ring and reset when the shard hibernates.")}):(0,o.jsx)("p",{className:"text-xs text-muted-foreground","data-testid":"ai-window",children:a("Totals cover the retained metric history (up to the last 24 hours).")}),(0,o.jsx)(Ee,{totals:d.totals,trend:x}),(0,o.jsxs)("div",{className:"grid gap-3 xl:grid-cols-2",children:[(0,o.jsx)(he,{keyLabel:a("Function"),rows:d.byFunction,testId:"ai-by-function",title:a("By function")}),(0,o.jsx)(he,{keyLabel:a("Model"),rows:d.byModel,testId:"ai-by-model",title:a("By model")})]}),d.calls.length===0?(0,o.jsx)(q,{children:(0,o.jsx)(oe,{className:"p-4 text-xs text-muted-foreground","data-testid":"ai-no-calls",children:a("No recent calls in the live trace ring \u2014 it empties when the shard hibernates.")})}):(0,o.jsx)($e,{calls:d.calls,onOpenTrace:r})]}),e[15]=r,e[16]=a,e[17]=x,e[18]=d.byFunction,e[19]=d.byModel,e[20]=d.calls,e[21]=d.source,e[22]=d.totals,e[23]=v):v=e[23];let C;return e[24]!==h||e[25]!==f||e[26]!==v?(C=(0,o.jsxs)("section",{className:"flex flex-col gap-4","data-testid":"ai-panel",children:[h,f,v]}),e[24]=h,e[25]=f,e[26]=v,e[27]=C):C=e[27],C},"Ze");function Le(n){return n.providerCost+n.estimatedCost}p(Le,"Ke");export{Ye as default};
1
+ import{d as E,e as _}from"./chunk-CVXNHIQW.js";import{a as $}from"./chunk-253UHWDX.js";import{a as de}from"./chunk-WW7D5RFR.js";import{a as ce}from"./chunk-K2EHRNYW.js";import"./chunk-VESGIGMQ.js";import"./chunk-TET2ESOI.js";import"./chunk-AUGKHAMQ.js";import"./chunk-WJRYEML4.js";import{a as le}from"./chunk-R6U22RSY.js";import{a as re}from"./chunk-7Q256NLI.js";import"./chunk-ZKJS6EBE.js";import"./chunk-RGMVGZV4.js";import"./chunk-OQ6I6OXT.js";import"./chunk-E4PXACVL.js";import"./chunk-MVWZMWPD.js";import"./chunk-SJQERRSZ.js";import"./chunk-7Y3SY37W.js";import"./chunk-AUAECCXB.js";import{b as K}from"./chunk-Q6ED4KUL.js";import"./chunk-BOMPSVRC.js";import{a as ie}from"./chunk-R75AFV7G.js";import"./chunk-NCPW7WHO.js";import"./chunk-IQ3SMVFW.js";import"./chunk-55UGUCQ6.js";import{a as J}from"./chunk-4ZEL6BYL.js";import{c as H}from"./chunk-T2JHVL34.js";import"./chunk-AVSMQPR3.js";import"./chunk-QAQDMS6R.js";import"./chunk-3I25WO3P.js";import{a as ne}from"./chunk-RWVIV3U7.js";import{a as R,b as W,c as Z,d as A,e as M,f as S}from"./chunk-HCTJKP5J.js";import{a as q,b as D,c as U,e as oe}from"./chunk-2IKDEUCX.js";import{d as F,u as ae}from"./chunk-74IYYDDI.js";import{a as p,d as se,f as be,g as ge}from"./chunk-I26MS5PJ.js";var O=se(be(),1);var o=se(ge(),1);var G="gen_ai.usage.input_tokens",Q="gen_ai.usage.output_tokens",V="gen_ai.usage.cost",fe="gen_ai.request.model",Te="lunora.usage.cost.source",xe=new Set(["ai.embed","ai.generate","ai.stream"]),ue=6e4,Ce=1440,ve="unknown",X=p(()=>({calls:0,estimatedCost:0,inputTokens:0,outputTokens:0,providerCost:0}),"q"),Y=p((n,e)=>{let s=n?.[e];return typeof s=="string"&&s!==""?s:void 0},"J"),z=p((n,e)=>{let s=n?.[e];return typeof s=="number"&&Number.isFinite(s)?s:void 0},"L"),ee=p(n=>Y(n,Te)==="provider"?"provider":"estimated","Q"),me=p((n,e)=>n.reduce((s,a)=>s+e(a),0),"Y"),B=p(n=>n.providerCost+n.estimatedCost,"F"),ke=p(n=>n.estimatedCost>0?n.providerCost>0?"mixed":"estimated":n.providerCost>0?"provider":"none","ae"),ye=p((n,e)=>({calls:n.calls+e.calls,estimatedCost:n.estimatedCost+e.estimatedCost,inputTokens:n.inputTokens+e.inputTokens,outputTokens:n.outputTokens+e.outputTokens,providerCost:n.providerCost+e.providerCost}),"ce"),Ie=p(n=>{let e=X(),s=0,a=0,t=0;for(let c of n){let l=me(c.points,i=>i.sum),r=me(c.points,i=>i.count);c.name===G?(e.inputTokens+=l,s+=r):c.name===Q?(e.outputTokens+=l,a+=r):(t+=r,ee(c.attributes)==="provider"?e.providerCost+=l:e.estimatedCost+=l)}return e.calls=Math.max(s,a,t),e},"ge"),Ne=p((n,e)=>B(e)-B(n)||e.inputTokens+e.outputTokens-(n.inputTokens+n.outputTokens)||n.key.localeCompare(e.key),"Ne"),pe=p((n,e)=>{let s=new Map;for(let a of n){let t=e(a);s.set(t,{key:t,...ye(s.get(t)??X(),a)})}return[...s.values()].toSorted(Ne)},"Z"),we=p(n=>(n?.series??[]).filter(e=>e.name===G||e.name===Q||e.name===V),"xe"),Me=p(n=>Y(n.attributes,fe)??ve,"Se"),Se=p(n=>{let e=new Map;for(let s of n){let a=Me(s),t=JSON.stringify([s.functionPath,a]),c=e.get(t)??{functionPath:s.functionPath,model:a,series:[]};c.series.push(s),e.set(t,c)}return[...e.values()].map(({functionPath:s,model:a,series:t})=>({functionPath:s,model:a,...Ie(t)}))},"Ie"),_e=p(n=>{let e=new Map;for(let r of n){if(r.name!==V)continue;let i=ee(r.attributes)==="provider";for(let u of r.points){let m=e.get(u.bucketMs)??{bucketMs:u.bucketMs,estimatedCost:0,providerCost:0};i?m.providerCost+=u.sum:m.estimatedCost+=u.sum,e.set(u.bucketMs,m)}}let s=[...e.keys()].toSorted((r,i)=>r-i),a=s[0],t=s.at(-1);if(a===void 0||t===void 0)return[];let c=Math.max(a,t-(Ce-1)*ue),l=[];for(let r=c;r<=t;r+=ue)l.push(e.get(r)??{bucketMs:r,estimatedCost:0,providerCost:0});return l},"_e"),Pe=p(n=>{let e=[];for(let s of n)for(let a of s.spans){if(!xe.has(a.name))continue;let{attributes:t}=a,c=z(t,V),l=z(t,G),r=z(t,Q);e.push({...c===void 0?{}:{cost:c,costSource:ee(t)},functionPath:s.functionPath,...l===void 0?{}:{inputTokens:l},model:Y(t,fe)??ve,ok:a.ok,...r===void 0?{}:{outputTokens:r},startTs:s.startTs+a.offsetMs,streaming:a.name==="ai.stream",traceId:s.traceId})}return e.toSorted((s,a)=>a.startTs-s.startTs)},"Me"),Fe=p(n=>n.map(e=>{let s=e.cost??0;return{calls:1,estimatedCost:e.costSource==="provider"?0:s,functionPath:e.functionPath,inputTokens:e.inputTokens??0,model:e.model,outputTokens:e.outputTokens??0,providerCost:e.costSource==="provider"?s:0}}),"Oe"),Oe=p((n,e)=>{let s=we(n),a=Pe(e),t=s.length>0,c=t?Se(s):Fe(a),l=X(),r="none";for(let i of c)l=ye(l,i);return t?r="history":a.length>0&&(r="live"),{byFunction:pe(c,i=>i.functionPath),byModel:pe(c,i=>i.model),calls:a,source:r,totals:l,trend:t?_e(s):[]}},"Ae"),Ke=p(n=>Array.isArray(n?.traces)?n.traces:[],"Ee"),Ae=25,te=p(n=>{let e=(0,O.c)(16),{provenance:s,value:a}=n,t=F();if(s==="none"){let m;return e[0]===Symbol.for("react.memo_cache_sentinel")?(m=(0,o.jsx)("span",{className:"text-muted-foreground",children:"\u2014"}),e[0]=m):m=e[0],m}let c;e[1]!==s||e[2]!==a?(c=s==="provider"?E(a):`~${E(a)}`,e[1]=s,e[2]=a,e[3]=c):c=e[3];let l;e[4]!==c?(l=(0,o.jsx)("span",{className:"tabular-nums",children:c}),e[4]=c,e[5]=l):l=e[5];let r;e[6]!==s||e[7]!==t?(r=s==="estimated"?(0,o.jsx)(K,{title:t("Derived from a price table, not reported by the provider."),variant:"warning",children:t("Estimated")}):null,e[6]=s,e[7]=t,e[8]=r):r=e[8];let i;e[9]!==s||e[10]!==t?(i=s==="mixed"?(0,o.jsx)(K,{title:t("Includes cost derived from a price table, not reported by the provider."),variant:"warning",children:t("Partly estimated")}):null,e[9]=s,e[10]=t,e[11]=i):i=e[11];let u;return e[12]!==l||e[13]!==r||e[14]!==i?(u=(0,o.jsxs)("span",{className:"inline-flex items-center gap-2",children:[l,r,i]}),e[12]=l,e[13]=r,e[14]=i,e[15]=u):u=e[15],u},"V"),he=p(n=>{let e=(0,O.c)(40),{keyLabel:s,rows:a,testId:t,title:c}=n,l=F(),r;e[0]!==c?(r=(0,o.jsx)(D,{className:"px-4 py-3",children:(0,o.jsx)(U,{children:c})}),e[0]=c,e[1]=r):r=e[1];let i;e[2]!==s?(i=(0,o.jsx)(M,{children:s}),e[2]=s,e[3]=i):i=e[3];let u;e[4]!==l?(u=l("Calls"),e[4]=l,e[5]=u):u=e[5];let m;e[6]!==u?(m=(0,o.jsx)(M,{className:"text-end",children:u}),e[6]=u,e[7]=m):m=e[7];let k;e[8]!==l?(k=l("Input tokens"),e[8]=l,e[9]=k):k=e[9];let y;e[10]!==k?(y=(0,o.jsx)(M,{className:"text-end",children:k}),e[10]=k,e[11]=y):y=e[11];let b;e[12]!==l?(b=l("Output tokens"),e[12]=l,e[13]=b):b=e[13];let T;e[14]!==b?(T=(0,o.jsx)(M,{className:"text-end",children:b}),e[14]=b,e[15]=T):T=e[15];let g;e[16]!==l?(g=l("Cost"),e[16]=l,e[17]=g):g=e[17];let d;e[18]!==g?(d=(0,o.jsx)(M,{className:"text-end",children:g}),e[18]=g,e[19]=d):d=e[19];let x;e[20]!==d||e[21]!==i||e[22]!==m||e[23]!==y||e[24]!==T?(x=(0,o.jsx)(W,{children:(0,o.jsxs)(A,{children:[i,m,y,T,d]})}),e[20]=d,e[21]=i,e[22]=m,e[23]=y,e[24]=T,e[25]=x):x=e[25];let h;if(e[26]!==a||e[27]!==t){let N;e[29]!==t?(N=p(w=>(0,o.jsxs)(A,{"data-testid":`${t}-row`,children:[(0,o.jsx)(S,{className:"max-w-[280px] truncate font-mono",title:w.key,children:w.key}),(0,o.jsx)(S,{className:"text-end tabular-nums",children:_(w.calls)}),(0,o.jsx)(S,{className:"text-end tabular-nums",children:_(w.inputTokens)}),(0,o.jsx)(S,{className:"text-end tabular-nums",children:_(w.outputTokens)}),(0,o.jsx)(S,{className:"text-end",children:(0,o.jsx)(te,{provenance:ke(w),value:B(w)})})]},w.key),"x"),e[29]=t,e[30]=N):N=e[30],h=a.map(N),e[26]=a,e[27]=t,e[28]=h}else h=e[28];let f;e[31]!==h?(f=(0,o.jsx)(Z,{children:h}),e[31]=h,e[32]=f):f=e[32];let v;e[33]!==x||e[34]!==f?(v=(0,o.jsxs)(R,{children:[x,f]}),e[33]=x,e[34]=f,e[35]=v):v=e[35];let C;return e[36]!==r||e[37]!==v||e[38]!==t?(C=(0,o.jsxs)(q,{className:"gap-0 py-0","data-testid":t,children:[r,v]}),e[36]=r,e[37]=v,e[38]=t,e[39]=C):C=e[39],C},"ee"),$e=p(n=>{let e=(0,O.c)(55),{calls:s,onOpenTrace:a}=n,t=F(),c;e[0]!==t?(c=t("Recent calls"),e[0]=t,e[1]=c):c=e[1];let l;e[2]!==c?(l=(0,o.jsx)(D,{className:"px-4 py-3",children:(0,o.jsx)(U,{children:c})}),e[2]=c,e[3]=l):l=e[3];let r;e[4]!==t?(r=t("When"),e[4]=t,e[5]=r):r=e[5];let i;e[6]!==r?(i=(0,o.jsx)(M,{children:r}),e[6]=r,e[7]=i):i=e[7];let u;e[8]!==t?(u=t("Function"),e[8]=t,e[9]=u):u=e[9];let m;e[10]!==u?(m=(0,o.jsx)(M,{children:u}),e[10]=u,e[11]=m):m=e[11];let k;e[12]!==t?(k=t("Model"),e[12]=t,e[13]=k):k=e[13];let y;e[14]!==k?(y=(0,o.jsx)(M,{children:k}),e[14]=k,e[15]=y):y=e[15];let b;e[16]!==t?(b=t("Input tokens"),e[16]=t,e[17]=b):b=e[17];let T;e[18]!==b?(T=(0,o.jsx)(M,{className:"text-end",children:b}),e[18]=b,e[19]=T):T=e[19];let g;e[20]!==t?(g=t("Output tokens"),e[20]=t,e[21]=g):g=e[21];let d;e[22]!==g?(d=(0,o.jsx)(M,{className:"text-end",children:g}),e[22]=g,e[23]=d):d=e[23];let x;e[24]!==t?(x=t("Cost"),e[24]=t,e[25]=x):x=e[25];let h;e[26]!==x?(h=(0,o.jsx)(M,{className:"text-end",children:x}),e[26]=x,e[27]=h):h=e[27];let f;e[28]!==t?(f=t("Trace"),e[28]=t,e[29]=f):f=e[29];let v;e[30]!==f?(v=(0,o.jsx)(M,{children:f}),e[30]=f,e[31]=v):v=e[31];let C;e[32]!==T||e[33]!==d||e[34]!==h||e[35]!==v||e[36]!==i||e[37]!==m||e[38]!==y?(C=(0,o.jsx)(W,{children:(0,o.jsxs)(A,{children:[i,m,y,T,d,h,v]})}),e[32]=T,e[33]=d,e[34]=h,e[35]=v,e[36]=i,e[37]=m,e[38]=y,e[39]=C):C=e[39];let N;if(e[40]!==s||e[41]!==a||e[42]!==t){let j;e[44]!==a||e[45]!==t?(j=p(I=>(0,o.jsxs)(A,{"data-testid":"ai-call",children:[(0,o.jsx)(S,{className:"font-mono text-muted-foreground",children:ae(I.startTs)}),(0,o.jsx)(S,{className:"font-mono",children:(0,o.jsxs)("span",{className:"inline-flex items-center gap-2",children:[I.functionPath,I.streaming?(0,o.jsx)(K,{variant:"outline",children:t("stream")}):null,I.ok?null:(0,o.jsx)(K,{variant:"destructive",children:t("failed")})]})}),(0,o.jsx)(S,{className:"max-w-[240px] truncate font-mono",title:I.model,children:I.model}),(0,o.jsx)(S,{className:"text-end tabular-nums",children:I.inputTokens===void 0?"\u2014":_(I.inputTokens)}),(0,o.jsx)(S,{className:"text-end tabular-nums",children:I.outputTokens===void 0?"\u2014":_(I.outputTokens)}),(0,o.jsx)(S,{className:"text-end",children:(0,o.jsx)(te,{provenance:I.cost===void 0?"none":I.costSource??"estimated",value:I.cost??0})}),(0,o.jsx)(S,{children:(0,o.jsx)("button",{className:"font-mono text-muted-foreground underline-offset-2 hover:underline",onClick:p(()=>{a(I.traceId)},"onClick"),title:t("Open the trace {trace}",{trace:I.traceId}),type:"button",children:I.traceId.slice(0,8)})})]},`${I.traceId}:${I.startTs.toString()}:${I.model}`),"U"),e[44]=a,e[45]=t,e[46]=j):j=e[46],N=s.slice(0,Ae).map(j),e[40]=s,e[41]=a,e[42]=t,e[43]=N}else N=e[43];let w;e[47]!==N?(w=(0,o.jsx)(Z,{children:N}),e[47]=N,e[48]=w):w=e[48];let P;e[49]!==C||e[50]!==w?(P=(0,o.jsxs)(R,{children:[C,w]}),e[49]=C,e[50]=w,e[51]=P):P=e[51];let L;return e[52]!==l||e[53]!==P?(L=(0,o.jsxs)(q,{className:"gap-0 py-0","data-testid":"ai-calls",children:[l,P]}),e[52]=l,e[53]=P,e[54]=L):L=e[54],L},"Pe"),Ee=p(n=>{let e=(0,O.c)(48),{totals:s,trend:a}=n,t=F(),c;e[0]!==s?(c=ke(s),e[0]=s,e[1]=c):c=e[1];let l=c,r;e[2]!==t||e[3]!==a?(r=a.length>=2?(0,o.jsx)(de,{ariaLabel:t("Cost per minute"),className:"h-7 w-24",series:a,testId:"ai-trend"}):void 0,e[2]=t,e[3]=a,e[4]=r):r=e[4];let i;e[5]!==l||e[6]!==t||e[7]!==s.estimatedCost||e[8]!==s.providerCost?(i=l==="none"?t("No cost reported"):(0,o.jsx)("span",{"data-testid":"ai-cost-split",children:t("{provider} provider-reported \xB7 {estimated} estimated",{estimated:E(s.estimatedCost),provider:E(s.providerCost)})}),e[5]=l,e[6]=t,e[7]=s.estimatedCost,e[8]=s.providerCost,e[9]=i):i=e[9];let u;e[10]!==t?(u=t("Total cost"),e[10]=t,e[11]=u):u=e[11];let m;e[12]!==s?(m=B(s),e[12]=s,e[13]=m):m=e[13];let k;e[14]!==l||e[15]!==m?(k=(0,o.jsx)(te,{provenance:l,value:m}),e[14]=l,e[15]=m,e[16]=k):k=e[16];let y;e[17]!==r||e[18]!==i||e[19]!==u||e[20]!==k?(y=(0,o.jsx)($,{chart:r,footer:i,label:u,testId:"ai-total-cost",value:k}),e[17]=r,e[18]=i,e[19]=u,e[20]=k,e[21]=y):y=e[21];let b;e[22]!==t?(b=t("Input tokens"),e[22]=t,e[23]=b):b=e[23];let T;e[24]!==s.inputTokens?(T=_(s.inputTokens),e[24]=s.inputTokens,e[25]=T):T=e[25];let g;e[26]!==b||e[27]!==T?(g=(0,o.jsx)($,{label:b,testId:"ai-input-tokens",value:T}),e[26]=b,e[27]=T,e[28]=g):g=e[28];let d;e[29]!==t?(d=t("Output tokens"),e[29]=t,e[30]=d):d=e[30];let x;e[31]!==s.outputTokens?(x=_(s.outputTokens),e[31]=s.outputTokens,e[32]=x):x=e[32];let h;e[33]!==d||e[34]!==x?(h=(0,o.jsx)($,{label:d,testId:"ai-output-tokens",value:x}),e[33]=d,e[34]=x,e[35]=h):h=e[35];let f;e[36]!==t?(f=t("Calls"),e[36]=t,e[37]=f):f=e[37];let v;e[38]!==s.calls?(v=_(s.calls),e[38]=s.calls,e[39]=v):v=e[39];let C;e[40]!==f||e[41]!==v?(C=(0,o.jsx)($,{label:f,testId:"ai-calls-total",value:v}),e[40]=f,e[41]=v,e[42]=C):C=e[42];let N;return e[43]!==g||e[44]!==h||e[45]!==C||e[46]!==y?(N=(0,o.jsxs)("dl",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4","data-testid":"ai-totals",children:[y,g,h,C]}),e[43]=g,e[44]=h,e[45]=C,e[46]=y,e[47]=N):N=e[47],N},"Ue"),Ye=p(n=>{let e=(0,O.c)(28),{initialShardKey:s}=n,a=F(),{queryShardKey:t,setShardKey:c,shardKey:l}=le(s),r=ce(t),i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i={},e[0]=i):i=e[0];let u;e[1]!==t?(u={live:!0,shardKey:t},e[1]=t,e[2]=u):u=e[2];let{data:m,error:k}=H(J.getTraces,i,u),y;e[3]===Symbol.for("react.memo_cache_sentinel")?(y={},e[3]=y):y=e[3];let b;e[4]!==t?(b={live:!0,shardKey:t},e[4]=t,e[5]=b):b=e[5];let{data:T}=H(J.getMetricHistory,y,b),g,d;e[6]!==m||e[7]!==T?(d=Oe(T,Ke(m)),g=d.trend.map(Le),e[6]=m,e[7]=T,e[8]=g,e[9]=d):(g=e[8],d=e[9]);let x=g,h;e[10]!==c||e[11]!==l?(h=(0,o.jsx)(re,{onChange:c,testId:"ai-shard-input",value:l}),e[10]=c,e[11]=l,e[12]=h):h=e[12];let f;e[13]!==k?(f=k===null?null:(0,o.jsx)(ie,{error:k,testId:"ai-error"}),e[13]=k,e[14]=f):f=e[14];let v;e[15]!==r||e[16]!==a||e[17]!==x||e[18]!==d.byFunction||e[19]!==d.byModel||e[20]!==d.calls||e[21]!==d.source||e[22]!==d.totals?(v=d.source==="none"?(0,o.jsx)(ne,{description:a("Spend shows up here once an action calls ctx.ai.model(...) \u2014 tokens and cost per function and per model."),testId:"ai-empty",title:a("No AI usage recorded")}):(0,o.jsxs)(o.Fragment,{children:[d.source==="live"?(0,o.jsx)("p",{className:"text-xs text-muted-foreground","data-testid":"ai-live-only",children:a("No durable history yet \u2014 these totals come from the live trace ring and reset when the shard hibernates.")}):(0,o.jsx)("p",{className:"text-xs text-muted-foreground","data-testid":"ai-window",children:a("Totals cover the retained metric history (up to the last 24 hours).")}),(0,o.jsx)(Ee,{totals:d.totals,trend:x}),(0,o.jsxs)("div",{className:"grid gap-3 xl:grid-cols-2",children:[(0,o.jsx)(he,{keyLabel:a("Function"),rows:d.byFunction,testId:"ai-by-function",title:a("By function")}),(0,o.jsx)(he,{keyLabel:a("Model"),rows:d.byModel,testId:"ai-by-model",title:a("By model")})]}),d.calls.length===0?(0,o.jsx)(q,{children:(0,o.jsx)(oe,{className:"p-4 text-xs text-muted-foreground","data-testid":"ai-no-calls",children:a("No recent calls in the live trace ring \u2014 it empties when the shard hibernates.")})}):(0,o.jsx)($e,{calls:d.calls,onOpenTrace:r})]}),e[15]=r,e[16]=a,e[17]=x,e[18]=d.byFunction,e[19]=d.byModel,e[20]=d.calls,e[21]=d.source,e[22]=d.totals,e[23]=v):v=e[23];let C;return e[24]!==h||e[25]!==f||e[26]!==v?(C=(0,o.jsxs)("section",{className:"flex flex-col gap-4","data-testid":"ai-panel",children:[h,f,v]}),e[24]=h,e[25]=f,e[26]=v,e[27]=C):C=e[27],C},"Ze");function Le(n){return n.providerCost+n.estimatedCost}p(Le,"Ke");export{Ye as default};
@@ -1 +1 @@
1
- import{g as j,h as v,i as D,l as g}from"./chunk-PFAXMXYQ.js";import{f as S,g as w,h as P,q}from"./chunk-74IYYDDI.js";import{a as i,d as A,e as x,f as M}from"./chunk-I26MS5PJ.js";var E=A(M(),1);var p=A(x(),1);var I=300,l=i(t=>typeof t=="string"?t===""?void 0:t:typeof t=="number"||typeof t=="boolean"?String(t):void 0,"c"),u=i(t=>t.filter(r=>r!==void 0).join(" "),"u"),T=i(t=>{let r=Array.isArray(t.filters)?t.filters.length:0,e=typeof t.search=="string"&&t.search!=="";return r===0&&!e?"no predicate":u([r===0?void 0:`${String(r)} filters`,e?"search":void 0])},"q"),N={clearTable:i(t=>u([l(t.table),"whole table"]),"clearTable"),deleteRows:i(t=>u([l(t.table),T(t)]),"deleteRows"),facetColumn:i(t=>u([l(t.table),l(t.column)]),"facetColumn"),importShard:i(t=>{if(!Array.isArray(t.rows))return"";let r=[...new Set(t.rows.filter(e=>typeof e=="object"&&e!==null).map(e=>e.table).filter(e=>typeof e=="string"))].toSorted((e,s)=>e.localeCompare(s));return u([`${String(t.rows.length)} rows`,r.length===0?void 0:`into ${r.join(", ")}`])},"importShard"),lintSql:i(()=>"sql","lintSql"),patchRows:i(t=>u([l(t.table),typeof t.doc=="object"&&t.doc!==null?`set ${Object.keys(t.doc).join(", ")}`:void 0,T(t)]),"patchRows"),pitrRestore:i(t=>u([l(t.time)===void 0?void 0:`to ${String(t.time)}`,typeof t.bookmark=="string"&&t.bookmark!==""?"from bookmark":void 0,t.restart===!0?"restart now":void 0]),"pitrRestore"),readTablePage:i(t=>u([l(t.table),Array.isArray(t.filters)&&t.filters.length>0?`${String(t.filters.length)} filters`:void 0,typeof t.search=="string"&&t.search!==""?"search":void 0,typeof t.limit=="number"?`limit ${String(t.limit)}`:void 0]),"readTablePage"),runMigration:i(t=>u([l(t.id),l(t.direction),t.dryRun===!0?"dry-run":void 0]),"runMigration"),runSql:i(t=>typeof t.sql=="string"?`${String(t.sql.length)} chars`:"","runSql"),schemaVersion:i(t=>typeof t.hash=="string"?t.hash.slice(0,8):"","schemaVersion"),writeRow:i(t=>u([l(t.table),"1 row"]),"writeRow")},$="__lunora_admin__:",F=i((t,r)=>{let e=t.startsWith($)?t.slice($.length):t,s=N[e];if(s!==void 0)return s(r);let n=Object.keys(r);return n.length===0?"":n.join(", ")},"M"),V=i(t=>{if(Array.isArray(t))return t.length;if(!(typeof t!="object"||t===null)){for(let r of Object.values(t))if(Array.isArray(r))return r.length}},"K"),k=class{static{i(this,"x")}entries=[];listeners=new Set;nextSeq=1;getSnapshot=i(()=>this.entries,"getSnapshot");subscribe=i(r=>(this.listeners.add(r),()=>{this.listeners.delete(r)}),"subscribe");start(r,e,s){return this.append(r,e,s,"call","pending")}startSubscription(r,e,s){return this.append(r,e,s,"subscription","live")}recordPush(r){if(this.listeners.size===0){let e=this.entries.find(s=>s.seq===r);e!==void 0&&(e.pushes=(e.pushes??0)+1);return}this.patch(r,e=>({...e,pushes:(e.pushes??0)+1}))}failSubscription(r,e){this.patch(r,s=>({...s,error:e,status:"error"}))}endSubscription(r){this.patch(r,e=>e.status==="error"?e:{...e,durationMs:Date.now()-e.startedAt,status:"closed"})}lastErrorSeq(){return this.entries.findLast(r=>r.status==="error")?.seq}settle(r,e){this.patch(r,s=>({...s,durationMs:Date.now()-s.startedAt,...e.error===void 0?{resultCount:V(e.result),status:"ok"}:{error:e.error,status:"error"}}))}clear(){this.entries=[],this.emit()}append(r,e,s,n,a){let c=this.nextSeq;this.nextSeq+=1;let d={functionPath:r,kind:n,seq:c,shardKey:s,startedAt:Date.now(),status:a,summary:F(r,e),...n==="subscription"?{pushes:0}:{}},o=[...this.entries,d];return this.entries=o.length>I?o.slice(o.length-I):o,this.emit(),c}patch(r,e){let s=this.entries.findIndex(n=>n.seq===r);s!==-1&&(this.entries=this.entries.with(s,e(this.entries[s])),this.emit())}emit(){for(let r of this.listeners)r()}},f=new k,O=i((t,r,e)=>["lunora-admin",t,r,e.trim()],"E"),_=i((t,r)=>[...t,r],"j");function W(t,r,e={}){let s=g(),{enabled:n=!0,keepPreviousData:a=!1,staleTime:c=0}=e,d=_(t,s.clientIdentifier()),o=D({enabled:n,queryFn:r,placeholderData:a?j:void 0,queryKey:d,staleTime:c});return{data:o.data,error:o.error?P(o.error):o.error,errorSource:o.error??void 0,isLoading:o.isLoading,liveError:void 0,refetch:i(()=>{q(o.refetch())},"refetch"),poll:i(async()=>{await o.refetch({throwOnError:!0})},"poll")}}i(W,"F");function Y(t,r,e={}){let s=g(),n=v(),{enabled:a=!0,keepPreviousData:c=!1,live:d=!1,shardKey:o="",staleTime:R}=e,m=O(t,r,o),C=W(m,()=>s.query(S(t),r,w(o)),{enabled:a,keepPreviousData:c,staleTime:R??(d?Number.POSITIVE_INFINITY:0)}),[K,b]=(0,p.useState)(void 0),L=JSON.stringify(m);return(0,p.useEffect)(()=>{if(!a||!d)return;b(void 0);let y=f.startSubscription(t,r,o),Q=s.subscribe(S(t),r,h=>{f.recordPush(y),b(void 0),n.setQueryData(_(m,s.clientIdentifier()),h)},{...w(o),onError:i(h=>{f.failSubscription(y,h.message),b(h.message)},"onError")});return()=>{f.endSubscription(y),Q()}},[s,L,a,d]),{...C,liveError:a&&d?K:void 0}}i(Y,"U");var B=i(()=>{let t=(0,E.c)(2),r=v(),e;return t[0]!==r?(e=i((s,n,a)=>{let c=n===void 0?["lunora-admin",s]:O(s,n,a??"");q(r.invalidateQueries({queryKey:c}))},"r"),t[0]=r,t[1]=e):e=t[1],e},"W");export{f as a,W as b,Y as c,B as d};
1
+ import{g as j,h as v,i as D,l as g}from"./chunk-AVSMQPR3.js";import{f as S,g as w,h as P,q}from"./chunk-74IYYDDI.js";import{a as i,d as A,e as x,f as M}from"./chunk-I26MS5PJ.js";var E=A(M(),1);var p=A(x(),1);var I=300,l=i(t=>typeof t=="string"?t===""?void 0:t:typeof t=="number"||typeof t=="boolean"?String(t):void 0,"c"),u=i(t=>t.filter(r=>r!==void 0).join(" "),"u"),T=i(t=>{let r=Array.isArray(t.filters)?t.filters.length:0,e=typeof t.search=="string"&&t.search!=="";return r===0&&!e?"no predicate":u([r===0?void 0:`${String(r)} filters`,e?"search":void 0])},"q"),N={clearTable:i(t=>u([l(t.table),"whole table"]),"clearTable"),deleteRows:i(t=>u([l(t.table),T(t)]),"deleteRows"),facetColumn:i(t=>u([l(t.table),l(t.column)]),"facetColumn"),importShard:i(t=>{if(!Array.isArray(t.rows))return"";let r=[...new Set(t.rows.filter(e=>typeof e=="object"&&e!==null).map(e=>e.table).filter(e=>typeof e=="string"))].toSorted((e,s)=>e.localeCompare(s));return u([`${String(t.rows.length)} rows`,r.length===0?void 0:`into ${r.join(", ")}`])},"importShard"),lintSql:i(()=>"sql","lintSql"),patchRows:i(t=>u([l(t.table),typeof t.doc=="object"&&t.doc!==null?`set ${Object.keys(t.doc).join(", ")}`:void 0,T(t)]),"patchRows"),pitrRestore:i(t=>u([l(t.time)===void 0?void 0:`to ${String(t.time)}`,typeof t.bookmark=="string"&&t.bookmark!==""?"from bookmark":void 0,t.restart===!0?"restart now":void 0]),"pitrRestore"),readTablePage:i(t=>u([l(t.table),Array.isArray(t.filters)&&t.filters.length>0?`${String(t.filters.length)} filters`:void 0,typeof t.search=="string"&&t.search!==""?"search":void 0,typeof t.limit=="number"?`limit ${String(t.limit)}`:void 0]),"readTablePage"),runMigration:i(t=>u([l(t.id),l(t.direction),t.dryRun===!0?"dry-run":void 0]),"runMigration"),runSql:i(t=>typeof t.sql=="string"?`${String(t.sql.length)} chars`:"","runSql"),schemaVersion:i(t=>typeof t.hash=="string"?t.hash.slice(0,8):"","schemaVersion"),writeRow:i(t=>u([l(t.table),"1 row"]),"writeRow")},$="__lunora_admin__:",F=i((t,r)=>{let e=t.startsWith($)?t.slice($.length):t,s=N[e];if(s!==void 0)return s(r);let n=Object.keys(r);return n.length===0?"":n.join(", ")},"M"),V=i(t=>{if(Array.isArray(t))return t.length;if(!(typeof t!="object"||t===null)){for(let r of Object.values(t))if(Array.isArray(r))return r.length}},"K"),k=class{static{i(this,"x")}entries=[];listeners=new Set;nextSeq=1;getSnapshot=i(()=>this.entries,"getSnapshot");subscribe=i(r=>(this.listeners.add(r),()=>{this.listeners.delete(r)}),"subscribe");start(r,e,s){return this.append(r,e,s,"call","pending")}startSubscription(r,e,s){return this.append(r,e,s,"subscription","live")}recordPush(r){if(this.listeners.size===0){let e=this.entries.find(s=>s.seq===r);e!==void 0&&(e.pushes=(e.pushes??0)+1);return}this.patch(r,e=>({...e,pushes:(e.pushes??0)+1}))}failSubscription(r,e){this.patch(r,s=>({...s,error:e,status:"error"}))}endSubscription(r){this.patch(r,e=>e.status==="error"?e:{...e,durationMs:Date.now()-e.startedAt,status:"closed"})}lastErrorSeq(){return this.entries.findLast(r=>r.status==="error")?.seq}settle(r,e){this.patch(r,s=>({...s,durationMs:Date.now()-s.startedAt,...e.error===void 0?{resultCount:V(e.result),status:"ok"}:{error:e.error,status:"error"}}))}clear(){this.entries=[],this.emit()}append(r,e,s,n,a){let c=this.nextSeq;this.nextSeq+=1;let d={functionPath:r,kind:n,seq:c,shardKey:s,startedAt:Date.now(),status:a,summary:F(r,e),...n==="subscription"?{pushes:0}:{}},o=[...this.entries,d];return this.entries=o.length>I?o.slice(o.length-I):o,this.emit(),c}patch(r,e){let s=this.entries.findIndex(n=>n.seq===r);s!==-1&&(this.entries=this.entries.with(s,e(this.entries[s])),this.emit())}emit(){for(let r of this.listeners)r()}},f=new k,O=i((t,r,e)=>["lunora-admin",t,r,e.trim()],"E"),_=i((t,r)=>[...t,r],"j");function W(t,r,e={}){let s=g(),{enabled:n=!0,keepPreviousData:a=!1,staleTime:c=0}=e,d=_(t,s.clientIdentifier()),o=D({enabled:n,queryFn:r,placeholderData:a?j:void 0,queryKey:d,staleTime:c});return{data:o.data,error:o.error?P(o.error):o.error,errorSource:o.error??void 0,isLoading:o.isLoading,liveError:void 0,refetch:i(()=>{q(o.refetch())},"refetch"),poll:i(async()=>{await o.refetch({throwOnError:!0})},"poll")}}i(W,"F");function Y(t,r,e={}){let s=g(),n=v(),{enabled:a=!0,keepPreviousData:c=!1,live:d=!1,shardKey:o="",staleTime:R}=e,m=O(t,r,o),C=W(m,()=>s.query(S(t),r,w(o)),{enabled:a,keepPreviousData:c,staleTime:R??(d?Number.POSITIVE_INFINITY:0)}),[K,b]=(0,p.useState)(void 0),L=JSON.stringify(m);return(0,p.useEffect)(()=>{if(!a||!d)return;b(void 0);let y=f.startSubscription(t,r,o),Q=s.subscribe(S(t),r,h=>{f.recordPush(y),b(void 0),n.setQueryData(_(m,s.clientIdentifier()),h)},{...w(o),onError:i(h=>{f.failSubscription(y,h.message),b(h.message)},"onError")});return()=>{f.endSubscription(y),Q()}},[s,L,a,d]),{...C,liveError:a&&d?K:void 0}}i(Y,"U");var B=i(()=>{let t=(0,E.c)(2),r=v(),e;return t[0]!==r?(e=i((s,n,a)=>{let c=n===void 0?["lunora-admin",s]:O(s,n,a??"");q(r.invalidateQueries({queryKey:c}))},"r"),t[0]=r,t[1]=e):e=t[1],e},"W");export{f as a,W as b,Y as c,B as d};
@@ -1 +1 @@
1
- import{a as O,b as D}from"./chunk-5B2RTXBS.js";import{a as F}from"./chunk-EWMBX5N2.js";import{a as j}from"./chunk-R6U22RSY.js";import{a as V}from"./chunk-7Q256NLI.js";import"./chunk-ZKJS6EBE.js";import"./chunk-RGMVGZV4.js";import{i as L}from"./chunk-E4PXACVL.js";import"./chunk-MVWZMWPD.js";import"./chunk-7Y3SY37W.js";import"./chunk-AUAECCXB.js";import{b as C}from"./chunk-Q6ED4KUL.js";import"./chunk-BOMPSVRC.js";import{a as z}from"./chunk-EXYGAGPA.js";import"./chunk-NCPW7WHO.js";import"./chunk-URHYIB3N.js";import"./chunk-55UGUCQ6.js";import{a as T}from"./chunk-4ZEL6BYL.js";import{c as R}from"./chunk-NM6ZWVHT.js";import"./chunk-PFAXMXYQ.js";import"./chunk-QAQDMS6R.js";import"./chunk-3I25WO3P.js";import{a as k}from"./chunk-RWVIV3U7.js";import{a as A,b as q,c as B,d as p,e as d,f as n}from"./chunk-HCTJKP5J.js";import{a as I,e as E}from"./chunk-2IKDEUCX.js";import{d as b,n as K,u as M}from"./chunk-74IYYDDI.js";import{a as i,d as y,e as ee,g as te}from"./chunk-I26MS5PJ.js";var s=y(ee(),1);var e=y(te(),1);var re=i(o=>o===void 0?"":JSON.stringify(o,K),"te"),ae=41,J=480,H=5,ie=i((o,t)=>O(o,l=>{t(l.height>0?l:{height:J,width:l.width})}),"ae"),Ne=i(({initialShardKey:o})=>{let t=b(),{queryShardKey:l,setShardKey:P,shardKey:U}=j(o),[h,W]=(0,s.useState)(""),{data:f,error:g,errorSource:Z,isLoading:_,liveError:G}=R(T.getAuditLog,{},{live:!0,shardKey:l}),c=(0,s.useMemo)(()=>f?.entries??[],[f]),m=(0,s.useMemo)(()=>{let a=h.trim().toLowerCase();return a===""?c:c.filter(r=>r.op.toLowerCase().includes(a)||(r.table??"").toLowerCase().includes(a)||(r.id??"").toLowerCase().includes(a))},[c,h]),x=(0,s.useRef)(null),v=D({count:m.length,estimateSize:i(()=>ae,"estimateSize"),getScrollElement:i(()=>x.current,"getScrollElement"),initialRect:{height:J,width:800},observeElementRect:ie,overscan:8}),u=v.getVirtualItems(),Q=v.getTotalSize(),N=u[0]?.start??0,w=Q-(u.at(-1)?.end??0),X={height:N},Y={height:w},$=i(a=>{W(a.target.value)},"z");return(0,e.jsxs)("div",{className:"flex flex-col gap-4","data-testid":"lunora-audit",children:[(0,e.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,e.jsx)(V,{onChange:P,testId:"au-shard-input",value:U}),(0,e.jsx)(F,{message:G,prefix:"au"}),(0,e.jsx)(L,{"aria-label":t("Filter audit log"),className:"h-8 w-48","data-testid":"au-search",onChange:$,placeholder:t("filter op, table, id"),value:h})]}),g!==null&&(0,e.jsx)(z,{error:Z,testId:"au-error"}),g===null&&!_&&m.length===0&&(0,e.jsx)(k,{description:t("State-changing admin operations are recorded here."),icon:(0,e.jsx)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,e.jsx)("path",{d:"M8 3H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2h-2M9 3a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v1a1 1 0 0 1-1 1h-4a1 1 0 0 1-1-1V3Zm-1 9h8m-8 4h5"})}),testId:"au-empty",title:t("No audit entries.")}),m.length>0&&(0,e.jsx)(I,{className:"overflow-hidden py-0",children:(0,e.jsx)(E,{className:"max-h-[30rem] overflow-auto px-0",ref:x,children:(0,e.jsxs)(A,{"data-testid":"au-table",children:[(0,e.jsx)(q,{children:(0,e.jsxs)(p,{children:[(0,e.jsx)(d,{children:t("time")}),(0,e.jsx)(d,{children:t("op")}),(0,e.jsx)(d,{children:t("table")}),(0,e.jsx)(d,{children:t("id")}),(0,e.jsx)(d,{children:t("detail")})]})}),(0,e.jsxs)(B,{children:[N>0&&(0,e.jsx)("tr",{"aria-hidden":"true",children:(0,e.jsx)("td",{colSpan:H,style:X})}),u.map(a=>{let r=m[a.index],S=re(r.detail);return(0,e.jsxs)(p,{"data-testid":"au-row",children:[(0,e.jsx)(n,{className:"text-muted-foreground tabular-nums",children:M(r.ts,"\u2014")}),(0,e.jsx)(n,{children:(0,e.jsx)(C,{variant:"secondary",children:r.op})}),(0,e.jsx)(n,{className:"font-medium",children:r.table??(0,e.jsx)("span",{className:"text-muted-foreground",children:"\u2014"})}),(0,e.jsx)(n,{className:"max-w-[20ch] truncate font-mono text-xs",children:r.id??(0,e.jsx)("span",{className:"text-muted-foreground",children:"\u2014"})}),(0,e.jsx)(n,{className:"max-w-[32ch] truncate font-mono text-xs text-muted-foreground",title:S||void 0,children:S||(0,e.jsx)("span",{className:"text-muted-foreground",children:"\u2014"})})]},r.seq)}),w>0&&(0,e.jsx)("tr",{"aria-hidden":"true",children:(0,e.jsx)("td",{colSpan:H,style:Y})})]})]})})})]})},"we");export{Ne as AuditPanel};
1
+ import{a as O,b as D}from"./chunk-5B2RTXBS.js";import{a as F}from"./chunk-EWMBX5N2.js";import{a as j}from"./chunk-R6U22RSY.js";import{a as V}from"./chunk-7Q256NLI.js";import"./chunk-ZKJS6EBE.js";import"./chunk-RGMVGZV4.js";import{i as L}from"./chunk-E4PXACVL.js";import"./chunk-MVWZMWPD.js";import"./chunk-7Y3SY37W.js";import"./chunk-AUAECCXB.js";import{b as C}from"./chunk-Q6ED4KUL.js";import"./chunk-BOMPSVRC.js";import{a as z}from"./chunk-R75AFV7G.js";import"./chunk-NCPW7WHO.js";import"./chunk-IQ3SMVFW.js";import"./chunk-55UGUCQ6.js";import{a as T}from"./chunk-4ZEL6BYL.js";import{c as R}from"./chunk-T2JHVL34.js";import"./chunk-AVSMQPR3.js";import"./chunk-QAQDMS6R.js";import"./chunk-3I25WO3P.js";import{a as k}from"./chunk-RWVIV3U7.js";import{a as A,b as q,c as B,d as p,e as d,f as n}from"./chunk-HCTJKP5J.js";import{a as I,e as E}from"./chunk-2IKDEUCX.js";import{d as b,n as K,u as M}from"./chunk-74IYYDDI.js";import{a as i,d as y,e as ee,g as te}from"./chunk-I26MS5PJ.js";var s=y(ee(),1);var e=y(te(),1);var re=i(o=>o===void 0?"":JSON.stringify(o,K),"te"),ae=41,J=480,H=5,ie=i((o,t)=>O(o,l=>{t(l.height>0?l:{height:J,width:l.width})}),"ae"),Ne=i(({initialShardKey:o})=>{let t=b(),{queryShardKey:l,setShardKey:P,shardKey:U}=j(o),[h,W]=(0,s.useState)(""),{data:f,error:g,errorSource:Z,isLoading:_,liveError:G}=R(T.getAuditLog,{},{live:!0,shardKey:l}),c=(0,s.useMemo)(()=>f?.entries??[],[f]),m=(0,s.useMemo)(()=>{let a=h.trim().toLowerCase();return a===""?c:c.filter(r=>r.op.toLowerCase().includes(a)||(r.table??"").toLowerCase().includes(a)||(r.id??"").toLowerCase().includes(a))},[c,h]),x=(0,s.useRef)(null),v=D({count:m.length,estimateSize:i(()=>ae,"estimateSize"),getScrollElement:i(()=>x.current,"getScrollElement"),initialRect:{height:J,width:800},observeElementRect:ie,overscan:8}),u=v.getVirtualItems(),Q=v.getTotalSize(),N=u[0]?.start??0,w=Q-(u.at(-1)?.end??0),X={height:N},Y={height:w},$=i(a=>{W(a.target.value)},"z");return(0,e.jsxs)("div",{className:"flex flex-col gap-4","data-testid":"lunora-audit",children:[(0,e.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,e.jsx)(V,{onChange:P,testId:"au-shard-input",value:U}),(0,e.jsx)(F,{message:G,prefix:"au"}),(0,e.jsx)(L,{"aria-label":t("Filter audit log"),className:"h-8 w-48","data-testid":"au-search",onChange:$,placeholder:t("filter op, table, id"),value:h})]}),g!==null&&(0,e.jsx)(z,{error:Z,testId:"au-error"}),g===null&&!_&&m.length===0&&(0,e.jsx)(k,{description:t("State-changing admin operations are recorded here."),icon:(0,e.jsx)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,e.jsx)("path",{d:"M8 3H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2h-2M9 3a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v1a1 1 0 0 1-1 1h-4a1 1 0 0 1-1-1V3Zm-1 9h8m-8 4h5"})}),testId:"au-empty",title:t("No audit entries.")}),m.length>0&&(0,e.jsx)(I,{className:"overflow-hidden py-0",children:(0,e.jsx)(E,{className:"max-h-[30rem] overflow-auto px-0",ref:x,children:(0,e.jsxs)(A,{"data-testid":"au-table",children:[(0,e.jsx)(q,{children:(0,e.jsxs)(p,{children:[(0,e.jsx)(d,{children:t("time")}),(0,e.jsx)(d,{children:t("op")}),(0,e.jsx)(d,{children:t("table")}),(0,e.jsx)(d,{children:t("id")}),(0,e.jsx)(d,{children:t("detail")})]})}),(0,e.jsxs)(B,{children:[N>0&&(0,e.jsx)("tr",{"aria-hidden":"true",children:(0,e.jsx)("td",{colSpan:H,style:X})}),u.map(a=>{let r=m[a.index],S=re(r.detail);return(0,e.jsxs)(p,{"data-testid":"au-row",children:[(0,e.jsx)(n,{className:"text-muted-foreground tabular-nums",children:M(r.ts,"\u2014")}),(0,e.jsx)(n,{children:(0,e.jsx)(C,{variant:"secondary",children:r.op})}),(0,e.jsx)(n,{className:"font-medium",children:r.table??(0,e.jsx)("span",{className:"text-muted-foreground",children:"\u2014"})}),(0,e.jsx)(n,{className:"max-w-[20ch] truncate font-mono text-xs",children:r.id??(0,e.jsx)("span",{className:"text-muted-foreground",children:"\u2014"})}),(0,e.jsx)(n,{className:"max-w-[32ch] truncate font-mono text-xs text-muted-foreground",title:S||void 0,children:S||(0,e.jsx)("span",{className:"text-muted-foreground",children:"\u2014"})})]},r.seq)}),w>0&&(0,e.jsx)("tr",{"aria-hidden":"true",children:(0,e.jsx)("td",{colSpan:H,style:Y})})]})]})})})]})},"we");export{Ne as AuditPanel};
@@ -1,4 +1,4 @@
1
- import{a as le}from"./chunk-VDC6JP4A.js";import{a as je}from"./chunk-FPI7AMQJ.js";import{a as he}from"./chunk-37WYCOQ2.js";import{a as V}from"./chunk-SA2OGF3F.js";import{d as Ne,f as ke,g as we,k as oe}from"./chunk-GHQ2VDI2.js";import{a as Pe}from"./chunk-7Q256NLI.js";import"./chunk-ZKJS6EBE.js";import"./chunk-RGMVGZV4.js";import{i as ve}from"./chunk-E4PXACVL.js";import"./chunk-MVWZMWPD.js";import"./chunk-7Y3SY37W.js";import{a as W}from"./chunk-7G4Z6Q7X.js";import"./chunk-3YXASVTP.js";import"./chunk-AUAECCXB.js";import{b as ye}from"./chunk-Q6ED4KUL.js";import"./chunk-BOMPSVRC.js";import{a as $e}from"./chunk-4ZEL6BYL.js";import{l as F}from"./chunk-PFAXMXYQ.js";import"./chunk-QAQDMS6R.js";import{d as be}from"./chunk-3I25WO3P.js";import{a as U}from"./chunk-RWVIV3U7.js";import{d as J,e as Se,f as se,g as ie,h as fe,n as Ie,q as Oe,t as ae}from"./chunk-74IYYDDI.js";import{a as u,d as K,e as me,f as te,g as re,i as ue}from"./chunk-I26MS5PJ.js";var Qe=K(te(),1),xe=K(me(),1);var Y=K(te(),1);var X=K(me(),1);var R=K(re(),1);var Xe=se($e.listTables),Ye=["react","client","cli"],Ze={action:"action",mutation:"mutation",query:"query"},Ce=u(t=>{let e=t.indexOf(":");return e===-1?{file:"",fn:t}:{file:t.slice(0,e),fn:t.slice(e+1)}},"Q"),et=u(({file:t,fn:e,kind:a})=>`await client.${Ze[a]}(api.${t}.${e}, { /* args */ });`,"ie"),tt=u(t=>{let e=`api.${t.file}.${t.fn}`;switch(t.kind){case"action":return`const { call: ${t.fn} } = useAction(${e});`;case"mutation":return`const ${t.fn} = useMutation(${e});`;default:return`const data = useQuery(${e}, { /* args */ });`}},"se"),rt=u(({file:t,fn:e})=>`lunora run ${t}:${e} --args '{ }'`,"oe"),at=u(t=>["// Read rows",`const rows = await ctx.db.query("${t}").collect();`,"","// Insert a row",`const id = await ctx.db.insert("${t}", { /* fields */ });`,"","// Generated types",`type Row = Doc<"${t}">;`,`type RowId = Id<"${t}">;`].join(`
1
+ import{a as le}from"./chunk-VDC6JP4A.js";import{a as je}from"./chunk-FPI7AMQJ.js";import{a as he}from"./chunk-37WYCOQ2.js";import{a as V}from"./chunk-SA2OGF3F.js";import{d as Ne,f as ke,g as we,k as oe}from"./chunk-GHQ2VDI2.js";import{a as Pe}from"./chunk-7Q256NLI.js";import"./chunk-ZKJS6EBE.js";import"./chunk-RGMVGZV4.js";import{i as ve}from"./chunk-E4PXACVL.js";import"./chunk-MVWZMWPD.js";import"./chunk-7Y3SY37W.js";import{a as W}from"./chunk-7G4Z6Q7X.js";import"./chunk-3YXASVTP.js";import"./chunk-AUAECCXB.js";import{b as ye}from"./chunk-Q6ED4KUL.js";import"./chunk-BOMPSVRC.js";import{a as $e}from"./chunk-4ZEL6BYL.js";import{l as F}from"./chunk-AVSMQPR3.js";import"./chunk-QAQDMS6R.js";import{d as be}from"./chunk-3I25WO3P.js";import{a as U}from"./chunk-RWVIV3U7.js";import{d as J,e as Se,f as se,g as ie,h as fe,n as Ie,q as Oe,t as ae}from"./chunk-74IYYDDI.js";import{a as u,d as K,e as me,f as te,g as re,i as ue}from"./chunk-I26MS5PJ.js";var Qe=K(te(),1),xe=K(me(),1);var Y=K(te(),1);var X=K(me(),1);var R=K(re(),1);var Xe=se($e.listTables),Ye=["react","client","cli"],Ze={action:"action",mutation:"mutation",query:"query"},Ce=u(t=>{let e=t.indexOf(":");return e===-1?{file:"",fn:t}:{file:t.slice(0,e),fn:t.slice(e+1)}},"Q"),et=u(({file:t,fn:e,kind:a})=>`await client.${Ze[a]}(api.${t}.${e}, { /* args */ });`,"ie"),tt=u(t=>{let e=`api.${t.file}.${t.fn}`;switch(t.kind){case"action":return`const { call: ${t.fn} } = useAction(${e});`;case"mutation":return`const ${t.fn} = useMutation(${e});`;default:return`const data = useQuery(${e}, { /* args */ });`}},"se"),rt=u(({file:t,fn:e})=>`lunora run ${t}:${e} --args '{ }'`,"oe"),at=u(t=>["// Read rows",`const rows = await ctx.db.query("${t}").collect();`,"","// Insert a row",`const id = await ctx.db.insert("${t}", { /* fields */ });`,"","// Generated types",`type Row = Doc<"${t}">;`,`type RowId = Id<"${t}">;`].join(`
2
2
  `),"ce"),nt=u((t,e)=>{switch(t){case"cli":return rt(e);case"client":return et(e);default:return tt(e)}},"re"),Re=u(t=>{let e=(0,Y.c)(19),{code:a,label:r,testId:n}=t,s=J(),o;e[0]!==a?(o=u(()=>{ae(a)},"c"),e[0]=a,e[1]=o):o=e[1];let i=o,c;e[2]!==r?(c=(0,R.jsx)("span",{className:"text-xs font-medium text-muted-foreground",children:r}),e[2]=r,e[3]=c):c=e[3];let m=`${n}-copy`,l;e[4]!==s?(l=s("Copy"),e[4]=s,e[5]=l):l=e[5];let p;e[6]!==i||e[7]!==m||e[8]!==l?(p=(0,R.jsx)(W,{"data-testid":m,onClick:i,size:"xs",type:"button",variant:"ghost",children:l}),e[6]=i,e[7]=m,e[8]=l,e[9]=p):p=e[9];let f;e[10]!==c||e[11]!==p?(f=(0,R.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[c,p]}),e[10]=c,e[11]=p,e[12]=f):f=e[12];let h;e[13]!==a||e[14]!==n?(h=(0,R.jsx)("pre",{className:"overflow-auto rounded-md border border-border bg-muted/50 p-3 font-mono text-xs","data-testid":n,children:a}),e[13]=a,e[14]=n,e[15]=h):h=e[15];let g;return e[16]!==f||e[17]!==h?(g=(0,R.jsxs)("div",{className:"flex flex-col gap-1.5",children:[f,h]}),e[16]=f,e[17]=h,e[18]=g):g=e[18],g},"U"),ot=u(t=>{let e=(0,Y.c)(46),{file:a,fn:r,kind:n}=t,s=J(),[o,i]=(0,X.useState)("react"),c,m,l;if(e[0]!==a||e[1]!==r||e[2]!==n||e[3]!==s||e[4]!==o){let w={file:a,fn:r,kind:n},j;e[8]!==s?(j=s("CLI"),e[8]=s,e[9]=j):j=e[9];let O;e[10]!==s?(O=s("Client"),e[10]=s,e[11]=O):O=e[11];let S;e[12]!==s?(S=s("React"),e[12]=s,e[13]=S):S=e[13];let C;e[14]!==j||e[15]!==O||e[16]!==S?(C={cli:j,client:O,react:S},e[14]=j,e[15]=O,e[16]=S,e[17]=C):C=e[17],l=C;let A;e[18]===Symbol.for("react.memo_cache_sentinel")?(A=u(_=>{i(_.currentTarget.dataset.tab)},"B"),e[18]=A):A=e[18],c=A,m=nt(o,w),e[0]=a,e[1]=r,e[2]=n,e[3]=s,e[4]=o,e[5]=c,e[6]=m,e[7]=l}else c=e[5],m=e[6],l=e[7];let p=m,f=`api.${a}.${r}`,h;e[19]!==f?(h=(0,R.jsx)("h2",{className:"font-mono text-sm font-semibold text-foreground","data-testid":"api-fn-title",children:f}),e[19]=f,e[20]=h):h=e[20];let g;e[21]!==n||e[22]!==s?(g=s("Call this {kind} from your app.",{kind:n}),e[21]=n,e[22]=s,e[23]=g):g=e[23];let x;e[24]!==g?(x=(0,R.jsx)("p",{className:"text-xs text-muted-foreground",children:g}),e[24]=g,e[25]=x):x=e[25];let v;e[26]!==h||e[27]!==x?(v=(0,R.jsxs)("div",{children:[h,x]}),e[26]=h,e[27]=x,e[28]=v):v=e[28];let N;e[29]!==s?(N=s("Snippet flavour"),e[29]=s,e[30]=N):N=e[30];let y;e[31]!==c||e[32]!==o||e[33]!==l?(y=Ye.map(w=>(0,R.jsx)(W,{"aria-selected":o===w,"data-tab":w,"data-testid":`api-tab-${w}`,onClick:c,role:"tab",size:"xs",type:"button",variant:o===w?"default":"outline",children:l[w]},w)),e[31]=c,e[32]=o,e[33]=l,e[34]=y):y=e[34];let b;e[35]!==N||e[36]!==y?(b=(0,R.jsx)("div",{"aria-label":N,className:"flex gap-1.5","data-testid":"api-tabs",role:"tablist",children:y}),e[35]=N,e[36]=y,e[37]=b):b=e[37];let I=l[o],P=`api-snippet-${o}`,$;e[38]!==p||e[39]!==I||e[40]!==P?($=(0,R.jsx)(Re,{code:p,label:I,testId:P}),e[38]=p,e[39]=I,e[40]=P,e[41]=$):$=e[41];let k;return e[42]!==$||e[43]!==v||e[44]!==b?(k=(0,R.jsxs)("div",{className:"flex flex-col gap-3","data-testid":"api-fn-doc",children:[v,b,$]}),e[42]=$,e[43]=v,e[44]=b,e[45]=k):k=e[45],k},"de"),st=u(t=>{let e=(0,Y.c)(19),{name:a}=t,r=J(),n;e[0]!==a?(n=at(a),e[0]=a,e[1]=n):n=e[1];let s=n,o;e[2]!==a?(o=(0,R.jsx)("h2",{className:"font-mono text-sm font-semibold text-foreground","data-testid":"api-table-title",children:a}),e[2]=a,e[3]=o):o=e[3];let i;e[4]!==r?(i=r("Read and write this table through the typed data model."),e[4]=r,e[5]=i):i=e[5];let c;e[6]!==i?(c=(0,R.jsx)("p",{className:"text-xs text-muted-foreground",children:i}),e[6]=i,e[7]=c):c=e[7];let m;e[8]!==o||e[9]!==c?(m=(0,R.jsxs)("div",{children:[o,c]}),e[8]=o,e[9]=c,e[10]=m):m=e[10];let l;e[11]!==r?(l=r("Data model"),e[11]=r,e[12]=l):l=e[12];let p;e[13]!==s||e[14]!==l?(p=(0,R.jsx)(Re,{code:s,label:l,testId:"api-snippet-table"}),e[13]=s,e[14]=l,e[15]=p):p=e[15];let f;return e[16]!==m||e[17]!==p?(f=(0,R.jsxs)("div",{className:"flex flex-col gap-3","data-testid":"api-table-doc",children:[m,p]}),e[16]=m,e[17]=p,e[18]=f):f=e[18],f},"fe"),Te=u(t=>{let e=(0,Y.c)(8),{active:a,label:r,onSelect:n,testId:s,value:o}=t,i;e[0]!==n||e[1]!==o?(i=u(()=>{n(o)},"m"),e[0]=n,e[1]=o,e[2]=i):i=e[2];let c=i,m=a?"page":void 0,l;return e[3]!==r||e[4]!==c||e[5]!==m||e[6]!==s?(l=(0,R.jsx)("button",{"aria-current":m,className:"w-full truncate rounded-md px-2 py-1 text-start font-mono text-xs text-muted-foreground outline-none transition-colors hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:bg-sidebar-accent aria-[current=page]:bg-sidebar-accent aria-[current=page]:font-medium aria-[current=page]:text-foreground","data-testid":s,onClick:c,type:"button",children:r}),e[3]=r,e[4]=c,e[5]=m,e[6]=s,e[7]=l):l=e[7],l},"G"),it=u(t=>{let e=new Map;for(let a of t){let{file:r,fn:n}=Ce(a.path),s=e.get(r)??[];s.push({fn:n,kind:a.kind,path:a.path}),e.set(r,s)}return[...e.entries()].map(([a,r])=>({file:a,items:r.toSorted((n,s)=>n.fn.localeCompare(s.fn))})).toSorted((a,r)=>a.file.localeCompare(r.file))},"pe"),Ae=u(t=>{let e=(0,Y.c)(58),{functions:a,initialShardKey:r}=t,n=J(),s=F(),[o,i]=(0,X.useState)(null),[c,m]=(0,X.useState)(null),l,p;e[0]!==s||e[1]!==r?(l=u(()=>{let _=!1;return s.query(Xe,{},ie(r??"")).then(T=>(_||i(T),T)).catch(()=>{_||i([])}),()=>{_=!0}},"o"),p=[s,r],e[0]=s,e[1]=r,e[2]=l,e[3]=p):(l=e[2],p=e[3]),(0,X.useEffect)(l,p);let f,h,g,x,v,N,y,b,I,P;if(e[4]!==a||e[5]!==c||e[6]!==n||e[7]!==o){let _=a??[],T=it(_),L=(o??[]).map(lt).toSorted(dt),E;e[18]===Symbol.for("react.memo_cache_sentinel")?(E=u(M=>{m({kind:"fn",path:M})},"P"),e[18]=E):E=e[18];let D=E,Q;e[19]===Symbol.for("react.memo_cache_sentinel")?(Q=u(M=>{m({kind:"table",name:M})},"j"),e[19]=Q):Q=e[19];let Ve=Q;h=c?.kind==="fn"?_.find(M=>M.path===c.path):void 0,f=_.length>0||L.length>0,g=h===void 0?void 0:Ce(h.path),I="grid min-h-0 gap-6 md:grid-cols-[16rem_minmax(0,1fr)]",P="lunora-api-docs",e[20]!==n?(x=n("API resources"),e[20]=n,e[21]=x):x=e[21],v="flex flex-col gap-4 overflow-y-auto",N="api-rail";let ne;e[22]!==c||e[23]!==n?(ne=u(M=>(0,R.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,R.jsx)("span",{className:"px-2 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:M.file||n("(root)")}),M.items.map(ee=>(0,R.jsx)(Te,{active:c?.kind==="fn"&&c.path===ee.path,label:ee.fn,onSelect:D,testId:`api-rail-fn-${ee.path}`,value:ee.path},ee.path))]},M.file),"q"),e[22]=c,e[23]=n,e[24]=ne):ne=e[24],y=T.map(ne),b=L.length>0&&(0,R.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,R.jsx)("span",{className:"px-2 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:n("Tables")}),L.map(M=>(0,R.jsx)(Te,{active:c?.kind==="table"&&c.name===M,label:M,onSelect:Ve,testId:`api-rail-table-${M}`,value:M},M))]}),e[4]=a,e[5]=c,e[6]=n,e[7]=o,e[8]=f,e[9]=h,e[10]=g,e[11]=x,e[12]=v,e[13]=N,e[14]=y,e[15]=b,e[16]=I,e[17]=P}else f=e[8],h=e[9],g=e[10],x=e[11],v=e[12],N=e[13],y=e[14],b=e[15],I=e[16],P=e[17];let $;e[25]!==f||e[26]!==n?($=!f&&(0,R.jsx)("p",{className:"px-2 text-xs text-muted-foreground","data-testid":"api-rail-empty",children:n("No functions or tables to document yet.")}),e[25]=f,e[26]=n,e[27]=$):$=e[27];let k;e[28]!==$||e[29]!==x||e[30]!==v||e[31]!==N||e[32]!==y||e[33]!==b?(k=(0,R.jsxs)("nav",{"aria-label":x,className:v,"data-testid":N,children:[y,b,$]}),e[28]=$,e[29]=x,e[30]=v,e[31]=N,e[32]=y,e[33]=b,e[34]=k):k=e[34];let w;e[35]!==c||e[36]!==n?(w=c===null&&(0,R.jsx)(U,{description:n("Select a function or table to see how to call it from your app."),testId:"api-empty",title:n("API usage snippets")}),e[35]=c,e[36]=n,e[37]=w):w=e[37];let j;e[38]!==c?.kind||e[39]!==h||e[40]!==g?(j=c?.kind==="fn"&&h!==void 0&&g!==void 0&&(0,R.jsx)(ot,{file:g.file,fn:g.fn,kind:h.kind},h.path),e[38]=c?.kind,e[39]=h,e[40]=g,e[41]=j):j=e[41];let O;e[42]!==c?.kind||e[43]!==h||e[44]!==n?(O=c?.kind==="fn"&&h===void 0&&(0,R.jsx)(U,{testId:"api-empty",title:n("API usage snippets")}),e[42]=c?.kind,e[43]=h,e[44]=n,e[45]=O):O=e[45];let S;e[46]!==c?(S=c?.kind==="table"&&(0,R.jsx)(st,{name:c.name}),e[46]=c,e[47]=S):S=e[47];let C;e[48]!==w||e[49]!==j||e[50]!==O||e[51]!==S?(C=(0,R.jsxs)("div",{className:"min-w-0",children:[w,j,O,S]}),e[48]=w,e[49]=j,e[50]=O,e[51]=S,e[52]=C):C=e[52];let A;return e[53]!==k||e[54]!==C||e[55]!==I||e[56]!==P?(A=(0,R.jsxs)("div",{className:I,"data-testid":P,children:[k,C]}),e[53]=k,e[54]=C,e[55]=I,e[56]=P,e[57]=A):A=e[57],A},"ke");function lt(t){return t.name}u(lt,"ue");function dt(t,e){return t.localeCompare(e)}u(dt,"me");var De=K(te(),1);var z=K(te(),1);var q=K(me(),1);var d=K(re(),1);var ct=u(t=>typeof t=="number"?"number":typeof t=="boolean"?"boolean":"string","we"),Je=u(t=>{if(t.enum!==void 0&&t.enum.length>0)return t.enum;if(t.anyOf!==void 0&&t.anyOf.length>0&&t.anyOf.every(e=>e.const!==void 0))return t.anyOf.map(e=>e.const)},"Q"),ce=u(t=>t===void 0?"any":t.const!==void 0?JSON.stringify(t.const):t.enum!==void 0&&t.enum.length>0?t.enum.map(e=>JSON.stringify(e)).join(" | "):t.anyOf!==void 0&&t.anyOf.length>0?t.anyOf.map(e=>ce(e)).join(" | "):t.type==="array"?`array<${ce(t.items)}>`:t.type??"any","z"),pt=u(t=>{let e=Je(t);return e!==void 0?t.type??ct(e[0]):ce(t)},"ke"),mt=u(t=>{let e=Je(t);return e===void 0?void 0:e.map(a=>JSON.stringify(a)).join(" | ")},"Oe"),ut=u(t=>{let e=[];t.minimum!==void 0?e.push(`${String(t.minimum)} \u2264`):t.exclusiveMinimum!==void 0&&e.push(`${String(t.exclusiveMinimum)} <`);let a=e.length>0;e.push("value"),t.maximum!==void 0?e.push(`\u2264 ${String(t.maximum)}`):t.exclusiveMaximum!==void 0&&e.push(`< ${String(t.exclusiveMaximum)}`);let r=e.length>(a?2:1);return a||r?e.join(" "):void 0},"$e"),ft=u(t=>{if(t.type==="object"&&t.properties!==void 0)return t;if(t.type==="array"&&t.items?.type==="object"&&t.items.properties!==void 0)return t.items},"Te"),Z=u(t=>{if(t===void 0)return null;if(t.const!==void 0)return t.const;if(t.enum!==void 0&&t.enum.length>0)return t.enum[0];if(t.anyOf!==void 0&&t.anyOf.length>0)return Z(t.anyOf[0]);switch(t.type){case"array":return[];case"boolean":return!1;case"number":return 0;case"object":{let e={};for(let[a,r]of Object.entries(t.properties??{}))e[a]=Z(r);return e}case"string":return"";default:return null}},"D"),de=u(t=>{let e=(0,z.c)(7),{label:a,value:r}=t,n;e[0]!==a?(n=(0,d.jsx)("span",{className:"text-muted-foreground",children:a}),e[0]=a,e[1]=n):n=e[1];let s;e[2]!==r?(s=(0,d.jsx)("span",{className:"text-foreground",children:r}),e[2]=r,e[3]=s):s=e[3];let o;return e[4]!==n||e[5]!==s?(o=(0,d.jsxs)("span",{className:"inline-flex items-center gap-1 rounded border border-border px-1.5 py-0.5 font-mono text-[10px]",children:[n,s]}),e[4]=n,e[5]=s,e[6]=o):o=e[6],o},"K"),ht=u(t=>{let e=(0,z.c)(40),{name:a,required:r,schema:n}=t,s=J(),o;e[0]!==n?(o=ut(n),e[0]=n,e[1]=o):o=e[1];let i=o,c;e[2]!==n?(c=mt(n),e[2]=n,e[3]=c):c=e[3];let m=c,l=n["x-lunora-table"],p=n.format!==void 0||i!==void 0||m!==void 0||l!==void 0,f;e[4]!==n?(f=ft(n),e[4]=n,e[5]=f):f=e[5];let h=f,g=r?"*":"?",x;e[6]!==g?(x=(0,d.jsx)("span",{className:"text-muted-foreground",children:g}),e[6]=g,e[7]=x):x=e[7];let v;e[8]!==a||e[9]!==x?(v=(0,d.jsxs)("span",{className:"font-mono text-foreground",children:[a,x]}),e[8]=a,e[9]=x,e[10]=v):v=e[10];let N;e[11]!==n?(N=pt(n),e[11]=n,e[12]=N):N=e[12];let y;e[13]!==N?(y=(0,d.jsx)("span",{className:"font-mono text-muted-foreground",children:N}),e[13]=N,e[14]=y):y=e[14];let b;e[15]!==v||e[16]!==y?(b=(0,d.jsxs)("div",{className:"flex items-baseline gap-2",children:[v,y]}),e[15]=v,e[16]=y,e[17]=b):b=e[17];let I;e[18]!==n.description?(I=n.description!==void 0&&(0,d.jsx)("p",{className:"max-w-prose text-muted-foreground",children:n.description}),e[18]=n.description,e[19]=I):I=e[19];let P;e[20]!==p||e[21]!==i||e[22]!==l||e[23]!==n.format||e[24]!==s||e[25]!==m?(P=p&&(0,d.jsxs)("div",{className:"flex flex-wrap gap-1",children:[n.format!==void 0&&(0,d.jsx)(de,{label:s("Format"),value:n.format}),i!==void 0&&(0,d.jsx)(de,{label:s("Range"),value:i}),m!==void 0&&(0,d.jsx)(de,{label:s("Value in"),value:m}),l!==void 0&&(0,d.jsx)(de,{label:s("relation"),value:l})]}),e[20]=p,e[21]=i,e[22]=l,e[23]=n.format,e[24]=s,e[25]=m,e[26]=P):P=e[26];let $;e[27]!==I||e[28]!==P||e[29]!==b?($=(0,d.jsxs)("div",{className:"flex flex-col gap-1 py-2",children:[b,I,P]}),e[27]=I,e[28]=P,e[29]=b,e[30]=$):$=e[30];let k=$;if(h===void 0){let S;return e[31]!==k?(S=(0,d.jsx)("div",{className:"border-b border-border/50 last:border-b-0",children:k}),e[31]=k,e[32]=S):S=e[32],S}let w;e[33]!==k?(w=(0,d.jsx)("summary",{className:"cursor-pointer marker:text-muted-foreground",children:k}),e[33]=k,e[34]=w):w=e[34];let j;e[35]!==h?(j=(0,d.jsx)("div",{className:"mb-2 ml-2 border-l border-border pl-3",children:(0,d.jsx)(Le,{schema:h})}),e[35]=h,e[36]=j):j=e[36];let O;return e[37]!==w||e[38]!==j?(O=(0,d.jsxs)("details",{className:"border-b border-border/50 last:border-b-0",children:[w,j]}),e[37]=w,e[38]=j,e[39]=O):O=e[39],O},"Ee"),Le=u(t=>{let e=(0,z.c)(7),{schema:a}=t,r;e[0]!==a.required?(r=new Set(a.required),e[0]=a.required,e[1]=r):r=e[1];let n=r,s;e[2]!==a.properties?(s=Object.entries(a.properties??{}),e[2]=a.properties,e[3]=s):s=e[3];let o=s,i;return e[4]!==n||e[5]!==o?(i=(0,d.jsx)("div",{className:"flex flex-col",children:o.map(c=>{let[m,l]=c;return(0,d.jsx)(ht,{name:m,required:n.has(m),schema:l},m)})}),e[4]=n,e[5]=o,e[6]=i):i=e[6],i},"Z"),_e=u(t=>{let e=(0,z.c)(10),{schema:a,testId:r}=t;if(a?.type!=="object"||Object.keys(a.properties??{}).length===0){let o;e[0]!==a?(o=ce(a),e[0]=a,e[1]=o):o=e[1];let i;return e[2]!==o||e[3]!==r?(i=(0,d.jsx)("p",{className:"font-mono text-xs text-muted-foreground","data-testid":r,children:o}),e[2]=o,e[3]=r,e[4]=i):i=e[4],i}let n;e[5]!==a?(n=(0,d.jsx)(Le,{schema:a}),e[5]=a,e[6]=n):n=e[6];let s;return e[7]!==n||e[8]!==r?(s=(0,d.jsx)("div",{className:"text-xs","data-testid":r,children:n}),e[7]=n,e[8]=r,e[9]=s):s=e[9],s},"V"),gt=["curl","javascript","lunora"],xt={lunora:"Lunora",curl:"cURL",javascript:"JavaScript"},bt=u(t=>`api.${t.replaceAll(/[/:]/g,".")}`,"Ae"),yt=u(t=>{let e=Z(t.argsSchema)??{};return t.functionPath===void 0?e:{args:e,functionPath:t.functionPath}},"je"),vt=u((t,e,a)=>{let r=`${a}${e.httpPath}`,n=JSON.stringify(yt(e),void 0,2),s=JSON.stringify(Z(e.argsSchema)??{},void 0,2);switch(t){case"curl":{let o=e.method!=="GET"&&e.method!=="HEAD",i=[`curl -X ${e.method} ${JSON.stringify(r)}`];return o&&i.push(' -H "Content-Type: application/json"',` -d '${n}'`),i.join(` \\
3
3
  `)}case"lunora":return e.functionPath===void 0?`await fetch(${JSON.stringify(e.httpPath)}, { method: ${JSON.stringify(e.method)} });`:`import { useLunora } from "@lunora/react";
4
4
  import { api } from "./_generated/api";
@@ -1 +1 @@
1
- import{a as Ot,b as Qt,c as ot}from"./chunk-CVXNHIQW.js";import{a as me}from"./chunk-253UHWDX.js";import{a as Kt,b as At,c as Pt,d as $t}from"./chunk-2I4NHEKA.js";import{a as it}from"./chunk-WW7D5RFR.js";import{a as Ft}from"./chunk-VCFEO3RI.js";import{a as Lt}from"./chunk-K2EHRNYW.js";import"./chunk-VESGIGMQ.js";import{e as Ct}from"./chunk-UYEZR3BI.js";import{a as It,b as Rt,c as Tt,d as zt,e as Qe}from"./chunk-5QR2SQIS.js";import"./chunk-NRP22GKC.js";import"./chunk-OPM7ESDV.js";import{a as Dt}from"./chunk-EWMBX5N2.js";import"./chunk-NXQW5E6W.js";import"./chunk-UC7MNI2F.js";import"./chunk-NGVP66OH.js";import"./chunk-GHQ2VDI2.js";import{a as Ze,b as et,c as tt,d as Nt,e as yt,f as rt,g as at,h as wt,i as St}from"./chunk-TET2ESOI.js";import"./chunk-AUGKHAMQ.js";import"./chunk-WJRYEML4.js";import{a as Mt}from"./chunk-R6U22RSY.js";import{a as _t}from"./chunk-7Q256NLI.js";import{a as qt,b as kt}from"./chunk-ZKJS6EBE.js";import"./chunk-RGMVGZV4.js";import"./chunk-OQ6I6OXT.js";import"./chunk-E4PXACVL.js";import"./chunk-MVWZMWPD.js";import"./chunk-SJQERRSZ.js";import"./chunk-7Y3SY37W.js";import{a as Je}from"./chunk-7G4Z6Q7X.js";import"./chunk-3YXASVTP.js";import"./chunk-AUAECCXB.js";import{b as Ge}from"./chunk-Q6ED4KUL.js";import"./chunk-BOMPSVRC.js";import"./chunk-55UGUCQ6.js";import{a as Ke}from"./chunk-4ZEL6BYL.js";import{c as $e}from"./chunk-NM6ZWVHT.js";import{a as ct,l as mt}from"./chunk-PFAXMXYQ.js";import"./chunk-QAQDMS6R.js";import"./chunk-3I25WO3P.js";import{a as gt}from"./chunk-RWVIV3U7.js";import{a as st,b as lt,c as nt,d as Oe,e as ce,f as V}from"./chunk-HCTJKP5J.js";import{a as fe,b as Ae,c as Pe,d as ht,e as pe}from"./chunk-2IKDEUCX.js";import{d as ge,f as ft,g as pt,h as xt,i as bt,m as Ve,q as vt}from"./chunk-74IYYDDI.js";import{a as d,d as Ye,e as Et,f as Ht,g as Ut,i as ut}from"./chunk-I26MS5PJ.js";var B=Ye(Et(),1);var xe=Ye(Ht(),1);var t=Ye(Ut(),1);var jt=d((l,e,s)=>`${l}:${e}:${ct(s??{})}`,"ut"),Bt=d((l,e)=>l==="gauge"?e.last:l==="histogram"?e.sum/Math.max(1,e.count):e.sum,"ft"),Gt=d((l,e)=>Bt(l,e),"Vt"),Vt=d(l=>Bt(l.kind,l),"Gt"),dt=d(l=>Number.isInteger(l)?l.toLocaleString():l.toLocaleString(void 0,{maximumFractionDigits:2}),"We"),Wt=d(l=>Array.isArray(l?.series)?l.series:[],"Jt"),Xt="FUNCTION_NOT_FOUND",Yt=d(l=>{let e=new Map;if(!Array.isArray(l?.series))return e;for(let s of l.series)e.set(jt(s.kind,s.name,s.attributes),s.points);return e},"Xt"),Jt={counter:"secondary",gauge:"default",histogram:"outline"},Zt=d(l=>{let e=(0,xe.c)(18),{name:s,onOpenTrace:a,traceId:r}=l,h=ge();if(r===void 0){let c;return e[0]===Symbol.for("react.memo_cache_sentinel")?(c=(0,t.jsx)("span",{className:"text-muted-foreground",children:"\u2014"}),e[0]=c):c=e[0],c}let i;e[1]!==r?(i=r.slice(0,8),e[1]=r,e[2]=i):i=e[2];let n=i;if(a===void 0){let c=`mt-instrument-trace-${s}`,p;return e[3]!==n||e[4]!==c||e[5]!==r?(p=(0,t.jsx)("span",{className:"text-muted-foreground","data-testid":c,title:r,children:n}),e[3]=n,e[4]=c,e[5]=r,e[6]=p):p=e[6],p}let g=`mt-instrument-trace-${s}`,v;e[7]!==a||e[8]!==r?(v=d(()=>{a(r)},"v"),e[7]=a,e[8]=r,e[9]=v):v=e[9];let S;e[10]!==h||e[11]!==r?(S=h("Open the exemplar trace {trace}",{trace:r}),e[10]=h,e[11]=r,e[12]=S):S=e[12];let f;return e[13]!==n||e[14]!==g||e[15]!==v||e[16]!==S?(f=(0,t.jsx)("button",{className:"text-primary underline-offset-4 hover:underline","data-testid":g,onClick:v,title:S,type:"button",children:n}),e[13]=n,e[14]=g,e[15]=v,e[16]=S,e[17]=f):f=e[17],f},"Zt"),er=d(l=>{let e=(0,xe.c)(105),{onOpenTrace:s,shardKey:a}=l,r=ge(),h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h={},e[0]=h):h=e[0];let i;e[1]!==a?(i={live:!0,shardKey:a},e[1]=a,e[2]=i):i=e[2];let{data:n,error:g,errorSource:v}=$e(Ke.getMetricSeries,h,i),S;e[3]===Symbol.for("react.memo_cache_sentinel")?(S={},e[3]=S):S=e[3];let f;e[4]!==a?(f={live:!0,shardKey:a},e[4]=a,e[5]=f):f=e[5];let{data:c}=$e(Ke.getMetricHistory,S,f),p,N,q,M,o,k,x,b,_,D,u,C,I;if(e[6]!==n||e[7]!==g||e[8]!==v||e[9]!==c||e[10]!==s||e[11]!==r){b=Symbol.for("react.early_return_sentinel");e:{let A=Wt(n),P=bt(v)===Xt;if(g!==null&&!P){let m;e[25]!==r?(m=r("Instruments"),e[25]=r,e[26]=m):m=e[26];let j;e[27]!==m?(j=(0,t.jsx)("h3",{className:"text-sm font-semibold text-foreground",children:m}),e[27]=m,e[28]=j):j=e[28];let E;e[29]!==g||e[30]!==r?(E=r("Instruments unavailable: {error}",{error:g}),e[29]=g,e[30]=r,e[31]=E):E=e[31];let H;e[32]!==E?(H=(0,t.jsx)("span",{className:"text-xs text-muted-foreground","data-testid":"mt-instruments-error",role:"status",children:E}),e[32]=E,e[33]=H):H=e[33];let de;e[34]!==j||e[35]!==H?(de=(0,t.jsxs)("section",{className:"flex flex-col gap-2","data-testid":"mt-instruments",children:[j,H]}),e[34]=j,e[35]=H,e[36]=de):de=e[36],b=de;break e}if(A.length===0){b=null;break e}let $=Yt(c),L;e[37]!==r?(L=d(m=>r(m==="counter"?"Counter":m==="gauge"?"Gauge":"Histogram"),"L"),e[37]=r,e[38]=L):L=e[38];let U=L;o="flex flex-col gap-2",k="mt-instruments";let Q;e[39]!==r?(Q=r("Instruments"),e[39]=r,e[40]=Q):Q=e[40],e[41]!==Q?(x=(0,t.jsx)("h3",{className:"text-sm font-semibold text-foreground",children:Q}),e[41]=Q,e[42]=x):x=e[42],M=fe,I="overflow-hidden py-0",q=pe,C="px-0",N=st,D="mt-instruments-table";let K;e[43]!==r?(K=r("name"),e[43]=r,e[44]=K):K=e[44];let O;e[45]!==K?(O=(0,t.jsx)(ce,{children:K}),e[45]=K,e[46]=O):O=e[46];let W;e[47]!==r?(W=r("kind"),e[47]=r,e[48]=W):W=e[48];let X;e[49]!==W?(X=(0,t.jsx)(ce,{children:W}),e[49]=W,e[50]=X):X=e[50];let Y;e[51]!==r?(Y=r("value"),e[51]=r,e[52]=Y):Y=e[52];let J;e[53]!==Y?(J=(0,t.jsx)(ce,{className:"text-right",children:Y}),e[53]=Y,e[54]=J):J=e[54];let Z;e[55]!==r?(Z=r("count"),e[55]=r,e[56]=Z):Z=e[56];let ee;e[57]!==Z?(ee=(0,t.jsx)(ce,{className:"text-right",children:Z}),e[57]=Z,e[58]=ee):ee=e[58];let te;e[59]!==r?(te=r("range"),e[59]=r,e[60]=te):te=e[60];let re;e[61]!==te?(re=(0,t.jsx)(ce,{className:"text-right",children:te}),e[61]=te,e[62]=re):re=e[62];let ae;e[63]!==r?(ae=r("trend"),e[63]=r,e[64]=ae):ae=e[64];let se;e[65]!==ae?(se=(0,t.jsx)(ce,{children:ae}),e[65]=ae,e[66]=se):se=e[66];let le;e[67]!==r?(le=r("trace"),e[67]=r,e[68]=le):le=e[68];let ne;e[69]!==le?(ne=(0,t.jsx)(ce,{children:le}),e[69]=le,e[70]=ne):ne=e[70];let ie;e[71]!==r?(ie=r("dimensions"),e[71]=r,e[72]=ie):ie=e[72];let oe;e[73]!==ie?(oe=(0,t.jsx)(ce,{children:ie}),e[73]=ie,e[74]=oe):oe=e[74],e[75]!==O||e[76]!==X||e[77]!==J||e[78]!==ee||e[79]!==re||e[80]!==se||e[81]!==ne||e[82]!==oe?(u=(0,t.jsx)(lt,{children:(0,t.jsxs)(Oe,{children:[O,X,J,ee,re,se,ne,oe]})}),e[75]=O,e[76]=X,e[77]=J,e[78]=ee,e[79]=re,e[80]=se,e[81]=ne,e[82]=oe,e[83]=u):u=e[83],p=nt,_=A.map(m=>{let j=Ft(m.attributes),E=jt(m.kind,m.name,m.attributes),H=($.get(E)??[]).map(de=>Gt(m.kind,de));return(0,t.jsxs)(Oe,{"data-testid":`mt-instrument-${m.name}`,children:[(0,t.jsx)(V,{className:"font-mono text-xs",title:m.functionPath,children:m.name}),(0,t.jsx)(V,{children:(0,t.jsx)(Ge,{variant:Jt[m.kind],children:U(m.kind)})}),(0,t.jsx)(V,{className:"text-right font-mono tabular-nums","data-testid":`mt-instrument-value-${m.name}`,children:dt(Vt(m))}),(0,t.jsx)(V,{className:"text-right tabular-nums text-muted-foreground",children:m.count.toLocaleString()}),(0,t.jsx)(V,{className:"text-right font-mono text-xs tabular-nums text-muted-foreground",children:m.min===m.max?"\u2014":`${dt(m.min)}\u2013${dt(m.max)}`}),(0,t.jsx)(V,{children:H.length>=2?(0,t.jsx)(it,{ariaLabel:r("{name} trend",{name:m.name}),className:"h-6 w-24 text-foreground",series:H,testId:`mt-instrument-trend-${m.name}`}):(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:"\u2014"})}),(0,t.jsx)(V,{className:"font-mono text-xs",children:(0,t.jsx)(Zt,{name:m.name,onOpenTrace:s,traceId:m.exemplarTraceId})}),(0,t.jsx)(V,{className:"max-w-64 truncate font-mono text-xs text-muted-foreground",title:j,children:j===""?"\u2014":j})]},E)})}e[6]=n,e[7]=g,e[8]=v,e[9]=c,e[10]=s,e[11]=r,e[12]=p,e[13]=N,e[14]=q,e[15]=M,e[16]=o,e[17]=k,e[18]=x,e[19]=b,e[20]=_,e[21]=D,e[22]=u,e[23]=C,e[24]=I}else p=e[12],N=e[13],q=e[14],M=e[15],o=e[16],k=e[17],x=e[18],b=e[19],_=e[20],D=e[21],u=e[22],C=e[23],I=e[24];if(b!==Symbol.for("react.early_return_sentinel"))return b;let R;e[84]!==p||e[85]!==_?(R=(0,t.jsx)(p,{children:_}),e[84]=p,e[85]=_,e[86]=R):R=e[86];let T;e[87]!==N||e[88]!==R||e[89]!==D||e[90]!==u?(T=(0,t.jsxs)(N,{"data-testid":D,children:[u,R]}),e[87]=N,e[88]=R,e[89]=D,e[90]=u,e[91]=T):T=e[91];let w;e[92]!==q||e[93]!==T||e[94]!==C?(w=(0,t.jsx)(q,{className:C,children:T}),e[92]=q,e[93]=T,e[94]=C,e[95]=w):w=e[95];let y;e[96]!==M||e[97]!==w||e[98]!==I?(y=(0,t.jsx)(M,{className:I,children:w}),e[96]=M,e[97]=w,e[98]=I,e[99]=y):y=e[99];let F;return e[100]!==o||e[101]!==k||e[102]!==x||e[103]!==y?(F=(0,t.jsxs)("section",{className:o,"data-testid":k,children:[x,y]}),e[100]=o,e[101]=k,e[102]=x,e[103]=y,e[104]=F):F=e[104],F},"er"),tr=d(l=>{let e=(0,xe.c)(74),{aggregate:s,shardResults:a}=l,r=ge(),h;e[0]!==r?(h=r("Shards"),e[0]=r,e[1]=h):h=e[1];let i;e[2]!==s.failed||e[3]!==s.reachable||e[4]!==r?(i=s.failed>0?r("{reachable} reachable, {failed} unreachable",{failed:s.failed,reachable:s.reachable}):r("{reachable} reachable",{reachable:s.reachable}),e[2]=s.failed,e[3]=s.reachable,e[4]=r,e[5]=i):i=e[5];let n;e[6]!==h||e[7]!==i?(n=(0,t.jsx)(me,{label:h,testId:"mt-agg-shards",value:i}),e[6]=h,e[7]=i,e[8]=n):n=e[8];let g;e[9]!==r?(g=r("Total requests"),e[9]=r,e[10]=g):g=e[10];let v;e[11]!==s.totalRequests||e[12]!==g?(v=(0,t.jsx)(me,{label:g,testId:"mt-agg-requests",value:s.totalRequests}),e[11]=s.totalRequests,e[12]=g,e[13]=v):v=e[13];let S;e[14]!==r?(S=r("Total errors"),e[14]=r,e[15]=S):S=e[15];let f;e[16]!==s.totalErrors||e[17]!==S?(f=(0,t.jsx)(me,{label:S,testId:"mt-agg-errors",value:s.totalErrors}),e[16]=s.totalErrors,e[17]=S,e[18]=f):f=e[18];let c;e[19]!==r?(c=r("Total database size"),e[19]=r,e[20]=c):c=e[20];let p;e[21]!==s.totalDatabaseSize?(p=Ve(s.totalDatabaseSize),e[21]=s.totalDatabaseSize,e[22]=p):p=e[22];let N;e[23]!==c||e[24]!==p?(N=(0,t.jsx)(me,{label:c,testId:"mt-agg-db-size",value:p}),e[23]=c,e[24]=p,e[25]=N):N=e[25];let q;e[26]!==r?(q=r("Combined cache hit rate"),e[26]=r,e[27]=q):q=e[27];let M;e[28]!==s.hitRate||e[29]!==r?(M=s.hitRate===null?r("no cache configured"):`${(s.hitRate*100).toFixed(1)}%`,e[28]=s.hitRate,e[29]=r,e[30]=M):M=e[30];let o;e[31]!==q||e[32]!==M?(o=(0,t.jsx)(me,{label:q,testId:"mt-agg-cache",value:M}),e[31]=q,e[32]=M,e[33]=o):o=e[33];let k;e[34]!==N||e[35]!==o||e[36]!==n||e[37]!==v||e[38]!==f?(k=(0,t.jsxs)("dl",{className:"grid gap-3 sm:grid-cols-2 lg:grid-cols-3","data-testid":"mt-aggregate-stats",children:[n,v,f,N,o]}),e[34]=N,e[35]=o,e[36]=n,e[37]=v,e[38]=f,e[39]=k):k=e[39];let x;e[40]!==r?(x=r("shard"),e[40]=r,e[41]=x):x=e[41];let b;e[42]!==x?(b=(0,t.jsx)(ce,{children:x}),e[42]=x,e[43]=b):b=e[43];let _;e[44]!==r?(_=r("requests"),e[44]=r,e[45]=_):_=e[45];let D;e[46]!==_?(D=(0,t.jsx)(ce,{children:_}),e[46]=_,e[47]=D):D=e[47];let u;e[48]!==r?(u=r("errors"),e[48]=r,e[49]=u):u=e[49];let C;e[50]!==u?(C=(0,t.jsx)(ce,{children:u}),e[50]=u,e[51]=C):C=e[51];let I;e[52]!==r?(I=r("db size"),e[52]=r,e[53]=I):I=e[53];let R;e[54]!==I?(R=(0,t.jsx)(ce,{children:I}),e[54]=I,e[55]=R):R=e[55];let T;e[56]!==b||e[57]!==D||e[58]!==C||e[59]!==R?(T=(0,t.jsx)(lt,{children:(0,t.jsxs)(Oe,{children:[b,D,C,R]})}),e[56]=b,e[57]=D,e[58]=C,e[59]=R,e[60]=T):T=e[60];let w;if(e[61]!==a||e[62]!==r){let P;e[64]!==r?(P=d($=>(0,t.jsxs)(Oe,{"data-testid":`mt-agg-row-${$.shard}`,children:[(0,t.jsx)(V,{children:$.shard}),$.metrics===null?(0,t.jsx)(V,{className:"text-destructive",colSpan:3,children:$.error??r("unreachable")}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(V,{className:"tabular-nums",children:$.metrics.requests}),(0,t.jsx)(V,{className:"tabular-nums",children:$.metrics.errors}),(0,t.jsx)(V,{className:"tabular-nums",children:Ve($.metrics.databaseSize)})]})]},$.shard),"z"),e[64]=r,e[65]=P):P=e[65],w=a.map(P),e[61]=a,e[62]=r,e[63]=w}else w=e[63];let y;e[66]!==w?(y=(0,t.jsx)(nt,{children:w}),e[66]=w,e[67]=y):y=e[67];let F;e[68]!==T||e[69]!==y?(F=(0,t.jsx)(fe,{className:"overflow-hidden py-0",children:(0,t.jsx)(pe,{className:"px-0",children:(0,t.jsxs)(st,{"data-testid":"mt-agg-table",children:[T,y]})})}),e[68]=T,e[69]=y,e[70]=F):F=e[70];let A;return e[71]!==k||e[72]!==F?(A=(0,t.jsxs)("div",{className:"flex flex-col gap-4","data-testid":"mt-aggregate-view",children:[k,F]}),e[71]=k,e[72]=F,e[73]=A):A=e[73],A},"tr"),rr=d(l=>{let e=(0,xe.c)(75),{currentDelta:s,errorRate:a,history:r,latencyPercentiles:h,metrics:i}=l,n=ge(),{cache:g}=i,v;e[0]!==r||e[1]!==n?(v=r.length>=2?(0,t.jsx)(it,{ariaLabel:n("Requests per interval over time"),className:"h-7 w-24 text-foreground",series:r,testId:"mt-sparkline"}):void 0,e[0]=r,e[1]=n,e[2]=v):v=e[2];let S;e[3]!==s||e[4]!==r.length||e[5]!==n?(S=r.length>=2?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("span",{className:"font-semibold text-foreground",children:`+${s.toLocaleString()}`})," ",n("last interval")]}):(0,t.jsx)("span",{"data-testid":"mt-sparkline-empty",children:n("collecting samples\u2026")}),e[3]=s,e[4]=r.length,e[5]=n,e[6]=S):S=e[6];let f;e[7]!==n?(f=n("Requests"),e[7]=n,e[8]=f):f=e[8];let c;e[9]!==i.requests||e[10]!==v||e[11]!==S||e[12]!==f?(c=(0,t.jsx)(me,{chart:v,footer:S,label:f,testId:"mt-requests",value:i.requests}),e[9]=i.requests,e[10]=v,e[11]=S,e[12]=f,e[13]=c):c=e[13];let p;e[14]!==a||e[15]!==n?(p=n("{rate} error rate",{rate:a}),e[14]=a,e[15]=n,e[16]=p):p=e[16];let N;e[17]!==n?(N=n("Errors"),e[17]=n,e[18]=N):N=e[18];let q;e[19]!==a||e[20]!==i.errors?(q=(0,t.jsxs)(t.Fragment,{children:[i.errors," (",a,")"]}),e[19]=a,e[20]=i.errors,e[21]=q):q=e[21];let M;e[22]!==p||e[23]!==N||e[24]!==q?(M=(0,t.jsx)(me,{footer:p,label:N,testId:"mt-errors",value:q}),e[22]=p,e[23]=N,e[24]=q,e[25]=M):M=e[25];let o;e[26]!==h.p90?(o=h.p90>0?`P90 ${ot(h.p90)}`:void 0,e[26]=h.p90,e[27]=o):o=e[27];let k;e[28]!==n?(k=n("P95 latency"),e[28]=n,e[29]=k):k=e[29];let x;e[30]!==h.p95?(x=h.p95>0?ot(h.p95):"\u2014",e[30]=h.p95,e[31]=x):x=e[31];let b;e[32]!==k||e[33]!==x||e[34]!==o?(b=(0,t.jsx)(me,{footer:o,label:k,testId:"mt-p95",value:x}),e[32]=k,e[33]=x,e[34]=o,e[35]=b):b=e[35];let _;e[36]!==g||e[37]!==n?(_=g?`${g.entries.toLocaleString()} ${n("cache entries")}`:void 0,e[36]=g,e[37]=n,e[38]=_):_=e[38];let D;e[39]!==n?(D=n("Database size"),e[39]=n,e[40]=D):D=e[40];let u;e[41]!==i.databaseSize?(u=Ve(i.databaseSize),e[41]=i.databaseSize,e[42]=u):u=e[42];let C;e[43]!==_||e[44]!==D||e[45]!==u?(C=(0,t.jsx)(me,{footer:_,label:D,testId:"mt-db-size",value:u}),e[43]=_,e[44]=D,e[45]=u,e[46]=C):C=e[46];let I;e[47]!==n?(I=n("Shard"),e[47]=n,e[48]=I):I=e[48];let R;e[49]!==i.shard||e[50]!==I?(R=(0,t.jsx)(me,{label:I,testId:"mt-shard",value:i.shard}),e[49]=i.shard,e[50]=I,e[51]=R):R=e[51];let T;e[52]!==n?(T=n("Uptime"),e[52]=n,e[53]=T):T=e[53];let w;e[54]!==i.uptimeMs?(w=Ot(i.uptimeMs),e[54]=i.uptimeMs,e[55]=w):w=e[55];let y;e[56]!==T||e[57]!==w?(y=(0,t.jsx)(me,{label:T,testId:"mt-uptime",value:w}),e[56]=T,e[57]=w,e[58]=y):y=e[58];let F;e[59]!==n?(F=n("Cache hit rate"),e[59]=n,e[60]=F):F=e[60];let A;e[61]!==g||e[62]!==n?(A=g?n("{rate} ({count} entries)",{count:g.entries,rate:Qt(g.hits,g.misses)}):n("no cache configured"),e[61]=g,e[62]=n,e[63]=A):A=e[63];let P;e[64]!==F||e[65]!==A?(P=(0,t.jsx)(me,{label:F,testId:"mt-cache",value:A}),e[64]=F,e[65]=A,e[66]=P):P=e[66];let $;return e[67]!==b||e[68]!==C||e[69]!==R||e[70]!==y||e[71]!==P||e[72]!==c||e[73]!==M?($=(0,t.jsxs)("dl",{className:"grid gap-3 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4","data-testid":"mt-stats",children:[c,M,b,C,R,y,P]}),e[67]=b,e[68]=C,e[69]=R,e[70]=y,e[71]=P,e[72]=c,e[73]=M,e[74]=$):$=e[74],$},"rr"),Xe=d(l=>l>=100?"critical":l>=50?"warning":"good","Ge"),je=d(l=>l<1?`${(l*1e3).toFixed(0)}\u03BCs`:l<1e3?`${l.toFixed(1)}ms`:`${(l/1e3).toFixed(2)}s`,"Ee"),We=d(l=>l>=1e9?`${(l/1e9).toFixed(1)}B`:l>=1e6?`${(l/1e6).toFixed(1)}M`:l>=1e3?`${(l/1e3).toFixed(1)}K`:l.toLocaleString(),"Ue"),ar=d(l=>{let e=(0,xe.c)(3),{level:s}=l;if(s==="critical"){let r;return e[0]===Symbol.for("react.memo_cache_sentinel")?(r=(0,t.jsx)(Ge,{variant:"destructive",children:"Slow"}),e[0]=r):r=e[0],r}if(s==="warning"){let r;return e[1]===Symbol.for("react.memo_cache_sentinel")?(r=(0,t.jsx)("span",{className:"inline-flex items-center gap-1 rounded-md border border-transparent bg-warning/10 px-2 py-0.5 text-xs font-medium text-warning",children:"Moderate"}),e[1]=r):r=e[1],r}let a;return e[2]===Symbol.for("react.memo_cache_sentinel")?(a=(0,t.jsx)("span",{className:"inline-flex items-center gap-1 rounded-md border border-transparent bg-success/10 px-2 py-0.5 text-xs font-medium text-success",children:"Fast"}),e[2]=a):a=e[2],a},"sr"),sr=d((l,e)=>{let s=[...l];return s.sort((a,r)=>{switch(e){case"avgTime":return r.avgDurationMs-a.avgDurationMs;case"execCount":return r.execCount-a.execCount;case"rowsRead":return r.rowsRead-a.rowsRead;default:return r.totalDurationMs-a.totalDurationMs}}),s},"lr"),lr=d(l=>{let e=(0,xe.c)(161),{queryStats:s}=l,a=ge(),[r,h]=(0,B.useState)("totalTime"),i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=new Set,e[0]=i):i=e[0];let[n,g]=(0,B.useState)(i),v;e[1]===Symbol.for("react.memo_cache_sentinel")?(v=d(I=>{I!==null&&h(I)},"v"),e[1]=v):v=e[1];let S=v,f,c,p,N,q,M,o,k,x,b;if(e[2]!==n||e[3]!==s||e[4]!==r||e[5]!==a){p=Symbol.for("react.early_return_sentinel");e:{let I=sr(s,r),R;e[16]!==s?(R=s.filter(nr),e[16]=s,e[17]=R):R=e[17];let T=R.length,w;e[18]!==s?(w=s.filter(ir),e[18]=s,e[19]=w):w=e[19];let y=w.length,F;e[20]!==s?(F=s.filter(or),e[20]=s,e[21]=F):F=e[21];let A=F.length,P;e[22]===Symbol.for("react.memo_cache_sentinel")?(P=d(z=>{g(ue=>{let G=new Set(ue);return G.has(z)?G.delete(z):G.add(z),G})},"z"),e[22]=P):P=e[22];let $=P;if(s.length===0){let z;e[23]!==a?(z=a("No query insights yet"),e[23]=a,e[24]=z):z=e[24];let ue;e[25]!==z?(ue=(0,t.jsx)("p",{className:"text-lg font-medium","data-testid":"qi-empty",children:z}),e[25]=z,e[26]=ue):ue=e[26];let G;e[27]!==a?(G=a("Query insights appear once statements are executed against this shard."),e[27]=a,e[28]=G):G=e[28];let he;e[29]!==G?(he=(0,t.jsx)("p",{className:"mt-1 text-sm",children:G}),e[29]=G,e[30]=he):he=e[30];let Ue;e[31]!==ue||e[32]!==he?(Ue=(0,t.jsx)(fe,{children:(0,t.jsx)(pe,{className:"py-12",children:(0,t.jsxs)("div",{className:"text-center text-muted-foreground",children:[ue,he]})})}),e[31]=ue,e[32]=he,e[33]=Ue):Ue=e[33],p=Ue;break e}o="space-y-4",k="qi-root";let L;e[34]!==a?(L=a("Critical queries"),e[34]=a,e[35]=L):L=e[35];let U;e[36]!==L?(U=(0,t.jsx)(Ae,{className:"pb-2",children:(0,t.jsx)(Pe,{className:"text-sm font-medium",children:L})}),e[36]=L,e[37]=U):U=e[37];let Q;e[38]!==T?(Q=(0,t.jsx)("div",{className:"text-2xl font-bold text-destructive","data-testid":"qi-critical",children:T}),e[38]=T,e[39]=Q):Q=e[39];let K;e[40]!==a?(K=a(">100ms avg execution"),e[40]=a,e[41]=K):K=e[41];let O;e[42]!==K?(O=(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:K}),e[42]=K,e[43]=O):O=e[43];let W;e[44]!==Q||e[45]!==O?(W=(0,t.jsxs)(pe,{children:[Q,O]}),e[44]=Q,e[45]=O,e[46]=W):W=e[46];let X;e[47]!==U||e[48]!==W?(X=(0,t.jsxs)(fe,{children:[U,W]}),e[47]=U,e[48]=W,e[49]=X):X=e[49];let Y;e[50]!==a?(Y=a("Moderate queries"),e[50]=a,e[51]=Y):Y=e[51];let J;e[52]!==Y?(J=(0,t.jsx)(Ae,{className:"pb-2",children:(0,t.jsx)(Pe,{className:"text-sm font-medium",children:Y})}),e[52]=Y,e[53]=J):J=e[53];let Z;e[54]!==y?(Z=(0,t.jsx)("div",{className:"text-2xl font-bold text-warning","data-testid":"qi-moderate",children:y}),e[54]=y,e[55]=Z):Z=e[55];let ee;e[56]!==a?(ee=a("50\u2013100ms avg execution"),e[56]=a,e[57]=ee):ee=e[57];let te;e[58]!==ee?(te=(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:ee}),e[58]=ee,e[59]=te):te=e[59];let re;e[60]!==Z||e[61]!==te?(re=(0,t.jsxs)(pe,{children:[Z,te]}),e[60]=Z,e[61]=te,e[62]=re):re=e[62];let ae;e[63]!==J||e[64]!==re?(ae=(0,t.jsxs)(fe,{children:[J,re]}),e[63]=J,e[64]=re,e[65]=ae):ae=e[65];let se;e[66]!==a?(se=a("Fast queries"),e[66]=a,e[67]=se):se=e[67];let le;e[68]!==se?(le=(0,t.jsx)(Ae,{className:"pb-2",children:(0,t.jsx)(Pe,{className:"text-sm font-medium",children:se})}),e[68]=se,e[69]=le):le=e[69];let ne;e[70]!==A?(ne=(0,t.jsx)("div",{className:"text-2xl font-bold text-success","data-testid":"qi-fast",children:A}),e[70]=A,e[71]=ne):ne=e[71];let ie;e[72]!==a?(ie=a("<50ms avg execution"),e[72]=a,e[73]=ie):ie=e[73];let oe;e[74]!==ie?(oe=(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:ie}),e[74]=ie,e[75]=oe):oe=e[75];let m;e[76]!==ne||e[77]!==oe?(m=(0,t.jsxs)(pe,{children:[ne,oe]}),e[76]=ne,e[77]=oe,e[78]=m):m=e[78];let j;e[79]!==le||e[80]!==m?(j=(0,t.jsxs)(fe,{children:[le,m]}),e[79]=le,e[80]=m,e[81]=j):j=e[81],e[82]!==X||e[83]!==ae||e[84]!==j?(x=(0,t.jsxs)("div",{className:"grid gap-4 md:grid-cols-3",children:[X,ae,j]}),e[82]=X,e[83]=ae,e[84]=j,e[85]=x):x=e[85];let E;e[86]!==a?(E=a("Query leaderboard"),e[86]=a,e[87]=E):E=e[87];let H;e[88]!==E?(H=(0,t.jsx)("h3",{className:"text-lg font-semibold",children:E}),e[88]=E,e[89]=H):H=e[89];let de;e[90]!==r||e[91]!==a?(de=a("Slow queries sorted by {sortField}",{sortField:a(r)}),e[90]=r,e[91]=a,e[92]=de):de=e[92];let be;e[93]!==de?(be=(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:de}),e[93]=de,e[94]=be):be=e[94];let ve;e[95]!==H||e[96]!==be?(ve=(0,t.jsxs)("div",{children:[H,be]}),e[95]=H,e[96]=be,e[97]=ve):ve=e[97];let Ne;e[98]!==a?(Ne=a("Sort by"),e[98]=a,e[99]=Ne):Ne=e[99];let ye;e[100]!==Ne?(ye=(0,t.jsx)("span",{className:"text-sm text-muted-foreground",children:Ne}),e[100]=Ne,e[101]=ye):ye=e[101];let we;e[102]!==a?(we=a("Sort queries by"),e[102]=a,e[103]=we):we=e[103];let Be;e[104]===Symbol.for("react.memo_cache_sentinel")?(Be=(0,t.jsx)(Rt,{}),e[104]=Be):Be=e[104];let Se;e[105]!==we?(Se=(0,t.jsx)(Tt,{"aria-label":we,className:"w-[140px]","data-testid":"qi-sort",children:Be}),e[105]=we,e[106]=Se):Se=e[106];let qe;e[107]!==a?(qe=a("Total time"),e[107]=a,e[108]=qe):qe=e[108];let ke;e[109]!==qe?(ke=(0,t.jsx)(Qe,{value:"totalTime",children:qe}),e[109]=qe,e[110]=ke):ke=e[110];let _e;e[111]!==a?(_e=a("Avg time"),e[111]=a,e[112]=_e):_e=e[112];let Me;e[113]!==_e?(Me=(0,t.jsx)(Qe,{value:"avgTime",children:_e}),e[113]=_e,e[114]=Me):Me=e[114];let De;e[115]!==a?(De=a("Execution count"),e[115]=a,e[116]=De):De=e[116];let Ce;e[117]!==De?(Ce=(0,t.jsx)(Qe,{value:"execCount",children:De}),e[117]=De,e[118]=Ce):Ce=e[118];let Ie;e[119]!==a?(Ie=a("Rows read"),e[119]=a,e[120]=Ie):Ie=e[120];let Re;e[121]!==Ie?(Re=(0,t.jsx)(Qe,{value:"rowsRead",children:Ie}),e[121]=Ie,e[122]=Re):Re=e[122];let Te;e[123]!==ke||e[124]!==Me||e[125]!==Ce||e[126]!==Re?(Te=(0,t.jsxs)(zt,{children:[ke,Me,Ce,Re]}),e[123]=ke,e[124]=Me,e[125]=Ce,e[126]=Re,e[127]=Te):Te=e[127];let ze;e[128]!==r||e[129]!==Se||e[130]!==Te?(ze=(0,t.jsxs)(It,{onValueChange:S,value:r,children:[Se,Te]}),e[128]=r,e[129]=Se,e[130]=Te,e[131]=ze):ze=e[131];let Fe;e[132]!==ye||e[133]!==ze?(Fe=(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[ye,ze]}),e[132]=ye,e[133]=ze,e[134]=Fe):Fe=e[134],e[135]!==ve||e[136]!==Fe?(b=(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[ve,Fe]}),e[135]=ve,e[136]=Fe,e[137]=b):b=e[137],c=fe;let Le;e[138]!==a?(Le=a("Statements"),e[138]=a,e[139]=Le):Le=e[139];let Ee;e[140]!==Le?(Ee=(0,t.jsx)(Pe,{children:Le}),e[140]=Le,e[141]=Ee):Ee=e[141],M=(0,t.jsxs)(Ae,{children:[Ee,(0,t.jsx)(ht,{children:a("{count} tracked statements",{count:I.length})})]}),f=pe,N="space-y-2";let He;e[142]!==n||e[143]!==a?(He=d(z=>{let ue=z.normalizedSql,G=n.has(ue),he=Xe(z.avgDurationMs);return(0,t.jsxs)("div",{className:"overflow-hidden rounded-lg border","data-testid":"qi-row",children:[(0,t.jsxs)("button",{"aria-expanded":G,className:"flex w-full items-center justify-between p-3 text-left transition-colors hover:bg-muted/50",onClick:d(()=>{$(ue)},"onClick"),type:"button",children:[(0,t.jsxs)("div",{className:"flex min-w-0 flex-1 items-center gap-3",children:[(0,t.jsx)(ar,{level:he}),(0,t.jsx)("span",{className:"max-w-[300px] truncate font-mono text-sm lg:max-w-[500px]",children:z.normalizedSql})]}),(0,t.jsxs)("div",{className:"flex shrink-0 items-center gap-4",children:[(0,t.jsxs)("div",{className:"text-right",children:[(0,t.jsx)("div",{className:"text-sm font-medium",children:je(z.totalDurationMs)}),(0,t.jsx)("div",{className:"text-xs text-muted-foreground",children:a("total")})]}),(0,t.jsxs)("div",{className:"text-right",children:[(0,t.jsx)("div",{className:"text-sm font-medium",children:je(z.avgDurationMs)}),(0,t.jsx)("div",{className:"text-xs text-muted-foreground",children:a("avg")})]}),z.p95DurationMs!==void 0&&(0,t.jsxs)("div",{className:"text-right",children:[(0,t.jsx)("div",{className:"text-sm font-medium",children:je(z.p95DurationMs)}),(0,t.jsx)("div",{className:"text-xs text-muted-foreground",children:a("p95")})]}),(0,t.jsxs)("div",{className:"text-right",children:[(0,t.jsx)("div",{className:"text-sm font-medium",children:We(z.execCount)}),(0,t.jsx)("div",{className:"text-xs text-muted-foreground",children:a("calls")})]})]})]}),G&&(0,t.jsxs)("div",{className:"space-y-3 border-t bg-muted/30 p-4",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"mb-2 text-sm font-medium",children:a("Full statement")}),(0,t.jsx)("pre",{className:"overflow-x-auto rounded-md bg-muted p-3 font-mono text-sm whitespace-pre-wrap break-all",children:z.normalizedSql})]}),(0,t.jsxs)("div",{className:"grid grid-cols-2 gap-4 text-sm md:grid-cols-4",children:[z.p50DurationMs!==void 0&&(0,t.jsxs)("div",{children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:a("p50")}),(0,t.jsx)("span",{className:"block font-medium tabular-nums",children:je(z.p50DurationMs)})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:a("Exec count")}),(0,t.jsx)("span",{className:"block font-medium tabular-nums",children:We(z.execCount)})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:a("Total time")}),(0,t.jsx)("span",{className:"block font-medium tabular-nums",children:je(z.totalDurationMs)})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:a("Rows read")}),(0,t.jsx)("span",{className:"block font-medium tabular-nums",children:We(z.rowsRead)})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:a("Rows written")}),(0,t.jsx)("span",{className:"block font-medium tabular-nums",children:We(z.rowsWritten)})]})]})]})]},ue)},"Ke"),e[142]=n,e[143]=a,e[144]=He):He=e[144],q=I.map(He)}e[2]=n,e[3]=s,e[4]=r,e[5]=a,e[6]=f,e[7]=c,e[8]=p,e[9]=N,e[10]=q,e[11]=M,e[12]=o,e[13]=k,e[14]=x,e[15]=b}else f=e[6],c=e[7],p=e[8],N=e[9],q=e[10],M=e[11],o=e[12],k=e[13],x=e[14],b=e[15];if(p!==Symbol.for("react.early_return_sentinel"))return p;let _;e[145]!==N||e[146]!==q?(_=(0,t.jsx)("div",{className:N,children:q}),e[145]=N,e[146]=q,e[147]=_):_=e[147];let D;e[148]!==f||e[149]!==_?(D=(0,t.jsx)(f,{children:_}),e[148]=f,e[149]=_,e[150]=D):D=e[150];let u;e[151]!==c||e[152]!==D||e[153]!==M?(u=(0,t.jsxs)(c,{children:[M,D]}),e[151]=c,e[152]=D,e[153]=M,e[154]=u):u=e[154];let C;return e[155]!==u||e[156]!==o||e[157]!==k||e[158]!==x||e[159]!==b?(C=(0,t.jsxs)("div",{className:o,"data-testid":k,children:[x,b,u]}),e[155]=u,e[156]=o,e[157]=k,e[158]=x,e[159]=b,e[160]=C):C=e[160],C},"ar");function nr(l){return Xe(l.avgDurationMs)==="critical"}d(nr,"ir");function ir(l){return Xe(l.avgDurationMs)==="warning"}d(ir,"nr");function or(l){return Xe(l.avgDurationMs)==="good"}d(or,"or");var dr=["1m","5m","15m","1h"],cr=d(l=>new Date(l).toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"}),"dr"),mr=d(l=>l.map(e=>({avg:Math.round(e.avgDurationMs*100)/100,execs:e.execCount,label:cr(e.bucketMs)})),"mr"),ur=d(({shardKey:l=""})=>{let e=ge(),[s,a]=(0,B.useState)("15m"),r=$e(Ke.getQueryInsights,{range:s},{live:!0,shardKey:l}).data,h=mr(r?.buckets??[]);return(0,t.jsxs)("div",{className:"flex flex-col gap-4","data-testid":"qi-range",children:[(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,t.jsx)("div",{className:"flex gap-1 rounded-lg border border-border p-0.5","data-testid":"qi-ranges",role:"group",children:dr.map(i=>(0,t.jsx)("button",{"aria-pressed":i===s,className:ut("rounded px-2 py-1 text-xs outline-none transition-colors hover:bg-accent focus-visible:bg-accent",i===s&&"bg-accent font-medium text-foreground"),"data-testid":`qi-range-${i}`,onClick:d(()=>{a(i)},"onClick"),type:"button",children:i},i))}),r?.capped===!0&&(0,t.jsx)(Ge,{"data-testid":"qi-capped",variant:"secondary",children:e("showing a capped set")})]}),h.length===0?(0,t.jsx)(gt,{description:e("Statements executed in the selected window appear here, with throughput and latency over time."),testId:"qi-empty",title:e("No queries in this window.")}):(0,t.jsxs)("div",{className:"grid gap-4 lg:grid-cols-2",children:[(0,t.jsxs)("figure",{className:"rounded-xl border border-border p-3","data-testid":"qi-throughput",children:[(0,t.jsx)("figcaption",{className:"mb-2 text-xs font-medium text-muted-foreground",children:e("Throughput")}),(0,t.jsx)(Ze,{height:140,width:"100%",children:(0,t.jsxs)(St,{data:h,children:[(0,t.jsx)(tt,{strokeDasharray:"3 3",vertical:!1}),(0,t.jsx)(rt,{dataKey:"label",fontSize:10,tickLine:!1}),(0,t.jsx)(at,{allowDecimals:!1,fontSize:10,tickLine:!1,width:32}),(0,t.jsx)(et,{}),(0,t.jsx)(yt,{dataKey:"execs",fill:"var(--color-primary)",fillOpacity:.15,stroke:"var(--color-primary)",type:"monotone"})]})})]}),(0,t.jsxs)("figure",{className:"rounded-xl border border-border p-3","data-testid":"qi-latency",children:[(0,t.jsx)("figcaption",{className:"mb-2 text-xs font-medium text-muted-foreground",children:e("Mean latency (ms)")}),(0,t.jsx)(Ze,{height:140,width:"100%",children:(0,t.jsxs)(wt,{data:h,children:[(0,t.jsx)(tt,{strokeDasharray:"3 3",vertical:!1}),(0,t.jsx)(rt,{dataKey:"label",fontSize:10,tickLine:!1}),(0,t.jsx)(at,{fontSize:10,tickLine:!1,width:32}),(0,t.jsx)(et,{}),(0,t.jsx)(Nt,{dataKey:"avg",dot:!1,stroke:"var(--color-destructive)",type:"monotone"})]})})]})]}),(0,t.jsx)(lr,{queryStats:r?.entries??[]})]})},"ur"),hr=ft(Ke.getMetrics),gr=d((l,e)=>l?e:"overview","hr"),Or=d(({initialShardKey:l})=>{let e=mt(),s=ge(),{queryShardKey:a,setShardKey:r,shardKey:h}=Mt(l),[i,n]=(0,B.useState)("overview"),[g,v]=(0,B.useState)([]),S=(0,B.useRef)(null),f=(0,B.useRef)(null),c=(0,B.useRef)(!0);(0,B.useEffect)(()=>(c.current=!0,()=>{c.current=!1}),[]);let p=Lt(a),{data:N,error:q,liveError:M}=$e(Ke.getMetrics,{},{live:!0,shardKey:a}),o=N??null;(0,B.useEffect)(()=>{if(N===void 0)return;kt(a);let L=N,U=S.current,Q=f.current!==null&&f.current!==L.shard;if(f.current=L.shard,S.current=L.requests,Q){v([]);return}U!==null&&L.requests>=U&&v(K=>[...K,L.requests-U].slice(-30))},[N,a]);let[k,x]=(0,B.useState)(null),[b,_]=(0,B.useState)(!1),D=d(async()=>{_(!0);let L=h,U=At(L,qt());try{let Q=await Promise.all(U.map(async K=>{try{let O=await e.query(hr,{},pt(K));return{error:null,metrics:O,shard:K===""?O.shard:K}}catch(O){return{error:xt(O),metrics:null,shard:K===""?"__root__":K}}}));c.current&&x({results:Q,shard:L})}finally{c.current&&_(!1)}},"R"),u=k?.shard===h?k.results:null,C=u===null?null:Kt(u),I=o===null||o.requests===0?"\u2014":`${(o.errors/o.requests*100).toFixed(1)}%`,R=g.length>0?g.at(-1):0,T=o?Pt(o):{p90:0,p95:0},w=(0,B.useMemo)(()=>{if(!o||!("queryStats"in o))return;let L=o.queryStats;if(!(!L||!Array.isArray(L)))return $t(L)},[o]),y=gr(w!==void 0,i),F=d(()=>{vt(D())},"A"),A=d(()=>{x(null)},"F"),P=d(()=>{n("overview")},"z"),$=d(()=>{n("query-insights")},"O");return(0,t.jsxs)("div",{className:"flex flex-col gap-4","data-testid":"lunora-metrics",children:[(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,t.jsx)(_t,{onChange:r,testId:"mt-shard-input",value:h}),(0,t.jsx)(Dt,{message:M,prefix:"mt"}),(0,t.jsx)(Je,{"data-testid":"mt-aggregate",disabled:b,onClick:F,size:"sm",type:"button",variant:"secondary",children:s(b?"Aggregating\u2026":"All shards")}),u!==null&&(0,t.jsx)(Je,{"data-testid":"mt-aggregate-clear",onClick:A,size:"sm",type:"button",variant:"ghost",children:s("Hide")}),(0,t.jsx)("a",{className:"text-sm text-primary underline-offset-4 hover:underline","data-testid":"mt-cf-link",href:Ct,rel:"noreferrer",target:"_blank",children:s("Open in Cloudflare")})]}),q!==null&&(0,t.jsx)("p",{className:"text-sm text-destructive","data-testid":"mt-error",role:"alert",children:q}),w!==void 0&&(0,t.jsxs)("div",{className:"flex gap-2 border-b","data-testid":"mt-tabs",children:[(0,t.jsx)("button",{className:`pb-2 text-sm font-medium transition-colors ${y==="overview"?"border-b-2 border-primary text-foreground":"text-muted-foreground hover:text-foreground"}`,"data-testid":"mt-tab-overview",onClick:P,type:"button",children:s("Overview")}),(0,t.jsxs)("button",{className:`pb-2 text-sm font-medium transition-colors ${y==="query-insights"?"border-b-2 border-primary text-foreground":"text-muted-foreground hover:text-foreground"}`,"data-testid":"mt-tab-query-insights",onClick:$,type:"button",children:[s("Query insights"),w.length>0&&(0,t.jsx)("span",{className:"ml-1.5 rounded-full bg-primary/10 px-1.5 py-0.5 text-xs text-primary",children:w.length})]})]}),y==="query-insights"&&w!==void 0&&(0,t.jsx)(ur,{shardKey:a}),y==="overview"&&o!==null&&(0,t.jsx)(rr,{currentDelta:R,errorRate:I,history:g,latencyPercentiles:T,metrics:o}),y==="overview"&&o===null&&null,y==="overview"&&(0,t.jsx)(er,{onOpenTrace:p,shardKey:a}),y==="overview"&&C!==null&&u!==null&&(0,t.jsx)(tr,{aggregate:C,shardResults:u})]})},"Qr");export{Or as MetricsPanel};
1
+ import{a as Ot,b as Qt,c as ot}from"./chunk-CVXNHIQW.js";import{a as me}from"./chunk-253UHWDX.js";import{a as Kt,b as At,c as Pt,d as $t}from"./chunk-2I4NHEKA.js";import{a as it}from"./chunk-WW7D5RFR.js";import{a as Ft}from"./chunk-VCFEO3RI.js";import{a as Lt}from"./chunk-K2EHRNYW.js";import"./chunk-VESGIGMQ.js";import{e as Ct}from"./chunk-UYEZR3BI.js";import{a as It,b as Rt,c as Tt,d as zt,e as Qe}from"./chunk-5QR2SQIS.js";import"./chunk-NRP22GKC.js";import"./chunk-OPM7ESDV.js";import{a as Dt}from"./chunk-EWMBX5N2.js";import"./chunk-NXQW5E6W.js";import"./chunk-UC7MNI2F.js";import"./chunk-NGVP66OH.js";import"./chunk-GHQ2VDI2.js";import{a as Ze,b as et,c as tt,d as Nt,e as yt,f as rt,g as at,h as wt,i as St}from"./chunk-TET2ESOI.js";import"./chunk-AUGKHAMQ.js";import"./chunk-WJRYEML4.js";import{a as Mt}from"./chunk-R6U22RSY.js";import{a as _t}from"./chunk-7Q256NLI.js";import{a as qt,b as kt}from"./chunk-ZKJS6EBE.js";import"./chunk-RGMVGZV4.js";import"./chunk-OQ6I6OXT.js";import"./chunk-E4PXACVL.js";import"./chunk-MVWZMWPD.js";import"./chunk-SJQERRSZ.js";import"./chunk-7Y3SY37W.js";import{a as Je}from"./chunk-7G4Z6Q7X.js";import"./chunk-3YXASVTP.js";import"./chunk-AUAECCXB.js";import{b as Ge}from"./chunk-Q6ED4KUL.js";import"./chunk-BOMPSVRC.js";import"./chunk-55UGUCQ6.js";import{a as Ke}from"./chunk-4ZEL6BYL.js";import{c as $e}from"./chunk-T2JHVL34.js";import{a as ct,l as mt}from"./chunk-AVSMQPR3.js";import"./chunk-QAQDMS6R.js";import"./chunk-3I25WO3P.js";import{a as gt}from"./chunk-RWVIV3U7.js";import{a as st,b as lt,c as nt,d as Oe,e as ce,f as V}from"./chunk-HCTJKP5J.js";import{a as fe,b as Ae,c as Pe,d as ht,e as pe}from"./chunk-2IKDEUCX.js";import{d as ge,f as ft,g as pt,h as xt,i as bt,m as Ve,q as vt}from"./chunk-74IYYDDI.js";import{a as d,d as Ye,e as Et,f as Ht,g as Ut,i as ut}from"./chunk-I26MS5PJ.js";var B=Ye(Et(),1);var xe=Ye(Ht(),1);var t=Ye(Ut(),1);var jt=d((l,e,s)=>`${l}:${e}:${ct(s??{})}`,"ut"),Bt=d((l,e)=>l==="gauge"?e.last:l==="histogram"?e.sum/Math.max(1,e.count):e.sum,"ft"),Gt=d((l,e)=>Bt(l,e),"Vt"),Vt=d(l=>Bt(l.kind,l),"Gt"),dt=d(l=>Number.isInteger(l)?l.toLocaleString():l.toLocaleString(void 0,{maximumFractionDigits:2}),"We"),Wt=d(l=>Array.isArray(l?.series)?l.series:[],"Jt"),Xt="FUNCTION_NOT_FOUND",Yt=d(l=>{let e=new Map;if(!Array.isArray(l?.series))return e;for(let s of l.series)e.set(jt(s.kind,s.name,s.attributes),s.points);return e},"Xt"),Jt={counter:"secondary",gauge:"default",histogram:"outline"},Zt=d(l=>{let e=(0,xe.c)(18),{name:s,onOpenTrace:a,traceId:r}=l,h=ge();if(r===void 0){let c;return e[0]===Symbol.for("react.memo_cache_sentinel")?(c=(0,t.jsx)("span",{className:"text-muted-foreground",children:"\u2014"}),e[0]=c):c=e[0],c}let i;e[1]!==r?(i=r.slice(0,8),e[1]=r,e[2]=i):i=e[2];let n=i;if(a===void 0){let c=`mt-instrument-trace-${s}`,p;return e[3]!==n||e[4]!==c||e[5]!==r?(p=(0,t.jsx)("span",{className:"text-muted-foreground","data-testid":c,title:r,children:n}),e[3]=n,e[4]=c,e[5]=r,e[6]=p):p=e[6],p}let g=`mt-instrument-trace-${s}`,v;e[7]!==a||e[8]!==r?(v=d(()=>{a(r)},"v"),e[7]=a,e[8]=r,e[9]=v):v=e[9];let S;e[10]!==h||e[11]!==r?(S=h("Open the exemplar trace {trace}",{trace:r}),e[10]=h,e[11]=r,e[12]=S):S=e[12];let f;return e[13]!==n||e[14]!==g||e[15]!==v||e[16]!==S?(f=(0,t.jsx)("button",{className:"text-primary underline-offset-4 hover:underline","data-testid":g,onClick:v,title:S,type:"button",children:n}),e[13]=n,e[14]=g,e[15]=v,e[16]=S,e[17]=f):f=e[17],f},"Zt"),er=d(l=>{let e=(0,xe.c)(105),{onOpenTrace:s,shardKey:a}=l,r=ge(),h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h={},e[0]=h):h=e[0];let i;e[1]!==a?(i={live:!0,shardKey:a},e[1]=a,e[2]=i):i=e[2];let{data:n,error:g,errorSource:v}=$e(Ke.getMetricSeries,h,i),S;e[3]===Symbol.for("react.memo_cache_sentinel")?(S={},e[3]=S):S=e[3];let f;e[4]!==a?(f={live:!0,shardKey:a},e[4]=a,e[5]=f):f=e[5];let{data:c}=$e(Ke.getMetricHistory,S,f),p,N,q,M,o,k,x,b,_,D,u,C,I;if(e[6]!==n||e[7]!==g||e[8]!==v||e[9]!==c||e[10]!==s||e[11]!==r){b=Symbol.for("react.early_return_sentinel");e:{let A=Wt(n),P=bt(v)===Xt;if(g!==null&&!P){let m;e[25]!==r?(m=r("Instruments"),e[25]=r,e[26]=m):m=e[26];let j;e[27]!==m?(j=(0,t.jsx)("h3",{className:"text-sm font-semibold text-foreground",children:m}),e[27]=m,e[28]=j):j=e[28];let E;e[29]!==g||e[30]!==r?(E=r("Instruments unavailable: {error}",{error:g}),e[29]=g,e[30]=r,e[31]=E):E=e[31];let H;e[32]!==E?(H=(0,t.jsx)("span",{className:"text-xs text-muted-foreground","data-testid":"mt-instruments-error",role:"status",children:E}),e[32]=E,e[33]=H):H=e[33];let de;e[34]!==j||e[35]!==H?(de=(0,t.jsxs)("section",{className:"flex flex-col gap-2","data-testid":"mt-instruments",children:[j,H]}),e[34]=j,e[35]=H,e[36]=de):de=e[36],b=de;break e}if(A.length===0){b=null;break e}let $=Yt(c),L;e[37]!==r?(L=d(m=>r(m==="counter"?"Counter":m==="gauge"?"Gauge":"Histogram"),"L"),e[37]=r,e[38]=L):L=e[38];let U=L;o="flex flex-col gap-2",k="mt-instruments";let Q;e[39]!==r?(Q=r("Instruments"),e[39]=r,e[40]=Q):Q=e[40],e[41]!==Q?(x=(0,t.jsx)("h3",{className:"text-sm font-semibold text-foreground",children:Q}),e[41]=Q,e[42]=x):x=e[42],M=fe,I="overflow-hidden py-0",q=pe,C="px-0",N=st,D="mt-instruments-table";let K;e[43]!==r?(K=r("name"),e[43]=r,e[44]=K):K=e[44];let O;e[45]!==K?(O=(0,t.jsx)(ce,{children:K}),e[45]=K,e[46]=O):O=e[46];let W;e[47]!==r?(W=r("kind"),e[47]=r,e[48]=W):W=e[48];let X;e[49]!==W?(X=(0,t.jsx)(ce,{children:W}),e[49]=W,e[50]=X):X=e[50];let Y;e[51]!==r?(Y=r("value"),e[51]=r,e[52]=Y):Y=e[52];let J;e[53]!==Y?(J=(0,t.jsx)(ce,{className:"text-right",children:Y}),e[53]=Y,e[54]=J):J=e[54];let Z;e[55]!==r?(Z=r("count"),e[55]=r,e[56]=Z):Z=e[56];let ee;e[57]!==Z?(ee=(0,t.jsx)(ce,{className:"text-right",children:Z}),e[57]=Z,e[58]=ee):ee=e[58];let te;e[59]!==r?(te=r("range"),e[59]=r,e[60]=te):te=e[60];let re;e[61]!==te?(re=(0,t.jsx)(ce,{className:"text-right",children:te}),e[61]=te,e[62]=re):re=e[62];let ae;e[63]!==r?(ae=r("trend"),e[63]=r,e[64]=ae):ae=e[64];let se;e[65]!==ae?(se=(0,t.jsx)(ce,{children:ae}),e[65]=ae,e[66]=se):se=e[66];let le;e[67]!==r?(le=r("trace"),e[67]=r,e[68]=le):le=e[68];let ne;e[69]!==le?(ne=(0,t.jsx)(ce,{children:le}),e[69]=le,e[70]=ne):ne=e[70];let ie;e[71]!==r?(ie=r("dimensions"),e[71]=r,e[72]=ie):ie=e[72];let oe;e[73]!==ie?(oe=(0,t.jsx)(ce,{children:ie}),e[73]=ie,e[74]=oe):oe=e[74],e[75]!==O||e[76]!==X||e[77]!==J||e[78]!==ee||e[79]!==re||e[80]!==se||e[81]!==ne||e[82]!==oe?(u=(0,t.jsx)(lt,{children:(0,t.jsxs)(Oe,{children:[O,X,J,ee,re,se,ne,oe]})}),e[75]=O,e[76]=X,e[77]=J,e[78]=ee,e[79]=re,e[80]=se,e[81]=ne,e[82]=oe,e[83]=u):u=e[83],p=nt,_=A.map(m=>{let j=Ft(m.attributes),E=jt(m.kind,m.name,m.attributes),H=($.get(E)??[]).map(de=>Gt(m.kind,de));return(0,t.jsxs)(Oe,{"data-testid":`mt-instrument-${m.name}`,children:[(0,t.jsx)(V,{className:"font-mono text-xs",title:m.functionPath,children:m.name}),(0,t.jsx)(V,{children:(0,t.jsx)(Ge,{variant:Jt[m.kind],children:U(m.kind)})}),(0,t.jsx)(V,{className:"text-right font-mono tabular-nums","data-testid":`mt-instrument-value-${m.name}`,children:dt(Vt(m))}),(0,t.jsx)(V,{className:"text-right tabular-nums text-muted-foreground",children:m.count.toLocaleString()}),(0,t.jsx)(V,{className:"text-right font-mono text-xs tabular-nums text-muted-foreground",children:m.min===m.max?"\u2014":`${dt(m.min)}\u2013${dt(m.max)}`}),(0,t.jsx)(V,{children:H.length>=2?(0,t.jsx)(it,{ariaLabel:r("{name} trend",{name:m.name}),className:"h-6 w-24 text-foreground",series:H,testId:`mt-instrument-trend-${m.name}`}):(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:"\u2014"})}),(0,t.jsx)(V,{className:"font-mono text-xs",children:(0,t.jsx)(Zt,{name:m.name,onOpenTrace:s,traceId:m.exemplarTraceId})}),(0,t.jsx)(V,{className:"max-w-64 truncate font-mono text-xs text-muted-foreground",title:j,children:j===""?"\u2014":j})]},E)})}e[6]=n,e[7]=g,e[8]=v,e[9]=c,e[10]=s,e[11]=r,e[12]=p,e[13]=N,e[14]=q,e[15]=M,e[16]=o,e[17]=k,e[18]=x,e[19]=b,e[20]=_,e[21]=D,e[22]=u,e[23]=C,e[24]=I}else p=e[12],N=e[13],q=e[14],M=e[15],o=e[16],k=e[17],x=e[18],b=e[19],_=e[20],D=e[21],u=e[22],C=e[23],I=e[24];if(b!==Symbol.for("react.early_return_sentinel"))return b;let R;e[84]!==p||e[85]!==_?(R=(0,t.jsx)(p,{children:_}),e[84]=p,e[85]=_,e[86]=R):R=e[86];let T;e[87]!==N||e[88]!==R||e[89]!==D||e[90]!==u?(T=(0,t.jsxs)(N,{"data-testid":D,children:[u,R]}),e[87]=N,e[88]=R,e[89]=D,e[90]=u,e[91]=T):T=e[91];let w;e[92]!==q||e[93]!==T||e[94]!==C?(w=(0,t.jsx)(q,{className:C,children:T}),e[92]=q,e[93]=T,e[94]=C,e[95]=w):w=e[95];let y;e[96]!==M||e[97]!==w||e[98]!==I?(y=(0,t.jsx)(M,{className:I,children:w}),e[96]=M,e[97]=w,e[98]=I,e[99]=y):y=e[99];let F;return e[100]!==o||e[101]!==k||e[102]!==x||e[103]!==y?(F=(0,t.jsxs)("section",{className:o,"data-testid":k,children:[x,y]}),e[100]=o,e[101]=k,e[102]=x,e[103]=y,e[104]=F):F=e[104],F},"er"),tr=d(l=>{let e=(0,xe.c)(74),{aggregate:s,shardResults:a}=l,r=ge(),h;e[0]!==r?(h=r("Shards"),e[0]=r,e[1]=h):h=e[1];let i;e[2]!==s.failed||e[3]!==s.reachable||e[4]!==r?(i=s.failed>0?r("{reachable} reachable, {failed} unreachable",{failed:s.failed,reachable:s.reachable}):r("{reachable} reachable",{reachable:s.reachable}),e[2]=s.failed,e[3]=s.reachable,e[4]=r,e[5]=i):i=e[5];let n;e[6]!==h||e[7]!==i?(n=(0,t.jsx)(me,{label:h,testId:"mt-agg-shards",value:i}),e[6]=h,e[7]=i,e[8]=n):n=e[8];let g;e[9]!==r?(g=r("Total requests"),e[9]=r,e[10]=g):g=e[10];let v;e[11]!==s.totalRequests||e[12]!==g?(v=(0,t.jsx)(me,{label:g,testId:"mt-agg-requests",value:s.totalRequests}),e[11]=s.totalRequests,e[12]=g,e[13]=v):v=e[13];let S;e[14]!==r?(S=r("Total errors"),e[14]=r,e[15]=S):S=e[15];let f;e[16]!==s.totalErrors||e[17]!==S?(f=(0,t.jsx)(me,{label:S,testId:"mt-agg-errors",value:s.totalErrors}),e[16]=s.totalErrors,e[17]=S,e[18]=f):f=e[18];let c;e[19]!==r?(c=r("Total database size"),e[19]=r,e[20]=c):c=e[20];let p;e[21]!==s.totalDatabaseSize?(p=Ve(s.totalDatabaseSize),e[21]=s.totalDatabaseSize,e[22]=p):p=e[22];let N;e[23]!==c||e[24]!==p?(N=(0,t.jsx)(me,{label:c,testId:"mt-agg-db-size",value:p}),e[23]=c,e[24]=p,e[25]=N):N=e[25];let q;e[26]!==r?(q=r("Combined cache hit rate"),e[26]=r,e[27]=q):q=e[27];let M;e[28]!==s.hitRate||e[29]!==r?(M=s.hitRate===null?r("no cache configured"):`${(s.hitRate*100).toFixed(1)}%`,e[28]=s.hitRate,e[29]=r,e[30]=M):M=e[30];let o;e[31]!==q||e[32]!==M?(o=(0,t.jsx)(me,{label:q,testId:"mt-agg-cache",value:M}),e[31]=q,e[32]=M,e[33]=o):o=e[33];let k;e[34]!==N||e[35]!==o||e[36]!==n||e[37]!==v||e[38]!==f?(k=(0,t.jsxs)("dl",{className:"grid gap-3 sm:grid-cols-2 lg:grid-cols-3","data-testid":"mt-aggregate-stats",children:[n,v,f,N,o]}),e[34]=N,e[35]=o,e[36]=n,e[37]=v,e[38]=f,e[39]=k):k=e[39];let x;e[40]!==r?(x=r("shard"),e[40]=r,e[41]=x):x=e[41];let b;e[42]!==x?(b=(0,t.jsx)(ce,{children:x}),e[42]=x,e[43]=b):b=e[43];let _;e[44]!==r?(_=r("requests"),e[44]=r,e[45]=_):_=e[45];let D;e[46]!==_?(D=(0,t.jsx)(ce,{children:_}),e[46]=_,e[47]=D):D=e[47];let u;e[48]!==r?(u=r("errors"),e[48]=r,e[49]=u):u=e[49];let C;e[50]!==u?(C=(0,t.jsx)(ce,{children:u}),e[50]=u,e[51]=C):C=e[51];let I;e[52]!==r?(I=r("db size"),e[52]=r,e[53]=I):I=e[53];let R;e[54]!==I?(R=(0,t.jsx)(ce,{children:I}),e[54]=I,e[55]=R):R=e[55];let T;e[56]!==b||e[57]!==D||e[58]!==C||e[59]!==R?(T=(0,t.jsx)(lt,{children:(0,t.jsxs)(Oe,{children:[b,D,C,R]})}),e[56]=b,e[57]=D,e[58]=C,e[59]=R,e[60]=T):T=e[60];let w;if(e[61]!==a||e[62]!==r){let P;e[64]!==r?(P=d($=>(0,t.jsxs)(Oe,{"data-testid":`mt-agg-row-${$.shard}`,children:[(0,t.jsx)(V,{children:$.shard}),$.metrics===null?(0,t.jsx)(V,{className:"text-destructive",colSpan:3,children:$.error??r("unreachable")}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(V,{className:"tabular-nums",children:$.metrics.requests}),(0,t.jsx)(V,{className:"tabular-nums",children:$.metrics.errors}),(0,t.jsx)(V,{className:"tabular-nums",children:Ve($.metrics.databaseSize)})]})]},$.shard),"z"),e[64]=r,e[65]=P):P=e[65],w=a.map(P),e[61]=a,e[62]=r,e[63]=w}else w=e[63];let y;e[66]!==w?(y=(0,t.jsx)(nt,{children:w}),e[66]=w,e[67]=y):y=e[67];let F;e[68]!==T||e[69]!==y?(F=(0,t.jsx)(fe,{className:"overflow-hidden py-0",children:(0,t.jsx)(pe,{className:"px-0",children:(0,t.jsxs)(st,{"data-testid":"mt-agg-table",children:[T,y]})})}),e[68]=T,e[69]=y,e[70]=F):F=e[70];let A;return e[71]!==k||e[72]!==F?(A=(0,t.jsxs)("div",{className:"flex flex-col gap-4","data-testid":"mt-aggregate-view",children:[k,F]}),e[71]=k,e[72]=F,e[73]=A):A=e[73],A},"tr"),rr=d(l=>{let e=(0,xe.c)(75),{currentDelta:s,errorRate:a,history:r,latencyPercentiles:h,metrics:i}=l,n=ge(),{cache:g}=i,v;e[0]!==r||e[1]!==n?(v=r.length>=2?(0,t.jsx)(it,{ariaLabel:n("Requests per interval over time"),className:"h-7 w-24 text-foreground",series:r,testId:"mt-sparkline"}):void 0,e[0]=r,e[1]=n,e[2]=v):v=e[2];let S;e[3]!==s||e[4]!==r.length||e[5]!==n?(S=r.length>=2?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("span",{className:"font-semibold text-foreground",children:`+${s.toLocaleString()}`})," ",n("last interval")]}):(0,t.jsx)("span",{"data-testid":"mt-sparkline-empty",children:n("collecting samples\u2026")}),e[3]=s,e[4]=r.length,e[5]=n,e[6]=S):S=e[6];let f;e[7]!==n?(f=n("Requests"),e[7]=n,e[8]=f):f=e[8];let c;e[9]!==i.requests||e[10]!==v||e[11]!==S||e[12]!==f?(c=(0,t.jsx)(me,{chart:v,footer:S,label:f,testId:"mt-requests",value:i.requests}),e[9]=i.requests,e[10]=v,e[11]=S,e[12]=f,e[13]=c):c=e[13];let p;e[14]!==a||e[15]!==n?(p=n("{rate} error rate",{rate:a}),e[14]=a,e[15]=n,e[16]=p):p=e[16];let N;e[17]!==n?(N=n("Errors"),e[17]=n,e[18]=N):N=e[18];let q;e[19]!==a||e[20]!==i.errors?(q=(0,t.jsxs)(t.Fragment,{children:[i.errors," (",a,")"]}),e[19]=a,e[20]=i.errors,e[21]=q):q=e[21];let M;e[22]!==p||e[23]!==N||e[24]!==q?(M=(0,t.jsx)(me,{footer:p,label:N,testId:"mt-errors",value:q}),e[22]=p,e[23]=N,e[24]=q,e[25]=M):M=e[25];let o;e[26]!==h.p90?(o=h.p90>0?`P90 ${ot(h.p90)}`:void 0,e[26]=h.p90,e[27]=o):o=e[27];let k;e[28]!==n?(k=n("P95 latency"),e[28]=n,e[29]=k):k=e[29];let x;e[30]!==h.p95?(x=h.p95>0?ot(h.p95):"\u2014",e[30]=h.p95,e[31]=x):x=e[31];let b;e[32]!==k||e[33]!==x||e[34]!==o?(b=(0,t.jsx)(me,{footer:o,label:k,testId:"mt-p95",value:x}),e[32]=k,e[33]=x,e[34]=o,e[35]=b):b=e[35];let _;e[36]!==g||e[37]!==n?(_=g?`${g.entries.toLocaleString()} ${n("cache entries")}`:void 0,e[36]=g,e[37]=n,e[38]=_):_=e[38];let D;e[39]!==n?(D=n("Database size"),e[39]=n,e[40]=D):D=e[40];let u;e[41]!==i.databaseSize?(u=Ve(i.databaseSize),e[41]=i.databaseSize,e[42]=u):u=e[42];let C;e[43]!==_||e[44]!==D||e[45]!==u?(C=(0,t.jsx)(me,{footer:_,label:D,testId:"mt-db-size",value:u}),e[43]=_,e[44]=D,e[45]=u,e[46]=C):C=e[46];let I;e[47]!==n?(I=n("Shard"),e[47]=n,e[48]=I):I=e[48];let R;e[49]!==i.shard||e[50]!==I?(R=(0,t.jsx)(me,{label:I,testId:"mt-shard",value:i.shard}),e[49]=i.shard,e[50]=I,e[51]=R):R=e[51];let T;e[52]!==n?(T=n("Uptime"),e[52]=n,e[53]=T):T=e[53];let w;e[54]!==i.uptimeMs?(w=Ot(i.uptimeMs),e[54]=i.uptimeMs,e[55]=w):w=e[55];let y;e[56]!==T||e[57]!==w?(y=(0,t.jsx)(me,{label:T,testId:"mt-uptime",value:w}),e[56]=T,e[57]=w,e[58]=y):y=e[58];let F;e[59]!==n?(F=n("Cache hit rate"),e[59]=n,e[60]=F):F=e[60];let A;e[61]!==g||e[62]!==n?(A=g?n("{rate} ({count} entries)",{count:g.entries,rate:Qt(g.hits,g.misses)}):n("no cache configured"),e[61]=g,e[62]=n,e[63]=A):A=e[63];let P;e[64]!==F||e[65]!==A?(P=(0,t.jsx)(me,{label:F,testId:"mt-cache",value:A}),e[64]=F,e[65]=A,e[66]=P):P=e[66];let $;return e[67]!==b||e[68]!==C||e[69]!==R||e[70]!==y||e[71]!==P||e[72]!==c||e[73]!==M?($=(0,t.jsxs)("dl",{className:"grid gap-3 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4","data-testid":"mt-stats",children:[c,M,b,C,R,y,P]}),e[67]=b,e[68]=C,e[69]=R,e[70]=y,e[71]=P,e[72]=c,e[73]=M,e[74]=$):$=e[74],$},"rr"),Xe=d(l=>l>=100?"critical":l>=50?"warning":"good","Ge"),je=d(l=>l<1?`${(l*1e3).toFixed(0)}\u03BCs`:l<1e3?`${l.toFixed(1)}ms`:`${(l/1e3).toFixed(2)}s`,"Ee"),We=d(l=>l>=1e9?`${(l/1e9).toFixed(1)}B`:l>=1e6?`${(l/1e6).toFixed(1)}M`:l>=1e3?`${(l/1e3).toFixed(1)}K`:l.toLocaleString(),"Ue"),ar=d(l=>{let e=(0,xe.c)(3),{level:s}=l;if(s==="critical"){let r;return e[0]===Symbol.for("react.memo_cache_sentinel")?(r=(0,t.jsx)(Ge,{variant:"destructive",children:"Slow"}),e[0]=r):r=e[0],r}if(s==="warning"){let r;return e[1]===Symbol.for("react.memo_cache_sentinel")?(r=(0,t.jsx)("span",{className:"inline-flex items-center gap-1 rounded-md border border-transparent bg-warning/10 px-2 py-0.5 text-xs font-medium text-warning",children:"Moderate"}),e[1]=r):r=e[1],r}let a;return e[2]===Symbol.for("react.memo_cache_sentinel")?(a=(0,t.jsx)("span",{className:"inline-flex items-center gap-1 rounded-md border border-transparent bg-success/10 px-2 py-0.5 text-xs font-medium text-success",children:"Fast"}),e[2]=a):a=e[2],a},"sr"),sr=d((l,e)=>{let s=[...l];return s.sort((a,r)=>{switch(e){case"avgTime":return r.avgDurationMs-a.avgDurationMs;case"execCount":return r.execCount-a.execCount;case"rowsRead":return r.rowsRead-a.rowsRead;default:return r.totalDurationMs-a.totalDurationMs}}),s},"lr"),lr=d(l=>{let e=(0,xe.c)(161),{queryStats:s}=l,a=ge(),[r,h]=(0,B.useState)("totalTime"),i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=new Set,e[0]=i):i=e[0];let[n,g]=(0,B.useState)(i),v;e[1]===Symbol.for("react.memo_cache_sentinel")?(v=d(I=>{I!==null&&h(I)},"v"),e[1]=v):v=e[1];let S=v,f,c,p,N,q,M,o,k,x,b;if(e[2]!==n||e[3]!==s||e[4]!==r||e[5]!==a){p=Symbol.for("react.early_return_sentinel");e:{let I=sr(s,r),R;e[16]!==s?(R=s.filter(nr),e[16]=s,e[17]=R):R=e[17];let T=R.length,w;e[18]!==s?(w=s.filter(ir),e[18]=s,e[19]=w):w=e[19];let y=w.length,F;e[20]!==s?(F=s.filter(or),e[20]=s,e[21]=F):F=e[21];let A=F.length,P;e[22]===Symbol.for("react.memo_cache_sentinel")?(P=d(z=>{g(ue=>{let G=new Set(ue);return G.has(z)?G.delete(z):G.add(z),G})},"z"),e[22]=P):P=e[22];let $=P;if(s.length===0){let z;e[23]!==a?(z=a("No query insights yet"),e[23]=a,e[24]=z):z=e[24];let ue;e[25]!==z?(ue=(0,t.jsx)("p",{className:"text-lg font-medium","data-testid":"qi-empty",children:z}),e[25]=z,e[26]=ue):ue=e[26];let G;e[27]!==a?(G=a("Query insights appear once statements are executed against this shard."),e[27]=a,e[28]=G):G=e[28];let he;e[29]!==G?(he=(0,t.jsx)("p",{className:"mt-1 text-sm",children:G}),e[29]=G,e[30]=he):he=e[30];let Ue;e[31]!==ue||e[32]!==he?(Ue=(0,t.jsx)(fe,{children:(0,t.jsx)(pe,{className:"py-12",children:(0,t.jsxs)("div",{className:"text-center text-muted-foreground",children:[ue,he]})})}),e[31]=ue,e[32]=he,e[33]=Ue):Ue=e[33],p=Ue;break e}o="space-y-4",k="qi-root";let L;e[34]!==a?(L=a("Critical queries"),e[34]=a,e[35]=L):L=e[35];let U;e[36]!==L?(U=(0,t.jsx)(Ae,{className:"pb-2",children:(0,t.jsx)(Pe,{className:"text-sm font-medium",children:L})}),e[36]=L,e[37]=U):U=e[37];let Q;e[38]!==T?(Q=(0,t.jsx)("div",{className:"text-2xl font-bold text-destructive","data-testid":"qi-critical",children:T}),e[38]=T,e[39]=Q):Q=e[39];let K;e[40]!==a?(K=a(">100ms avg execution"),e[40]=a,e[41]=K):K=e[41];let O;e[42]!==K?(O=(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:K}),e[42]=K,e[43]=O):O=e[43];let W;e[44]!==Q||e[45]!==O?(W=(0,t.jsxs)(pe,{children:[Q,O]}),e[44]=Q,e[45]=O,e[46]=W):W=e[46];let X;e[47]!==U||e[48]!==W?(X=(0,t.jsxs)(fe,{children:[U,W]}),e[47]=U,e[48]=W,e[49]=X):X=e[49];let Y;e[50]!==a?(Y=a("Moderate queries"),e[50]=a,e[51]=Y):Y=e[51];let J;e[52]!==Y?(J=(0,t.jsx)(Ae,{className:"pb-2",children:(0,t.jsx)(Pe,{className:"text-sm font-medium",children:Y})}),e[52]=Y,e[53]=J):J=e[53];let Z;e[54]!==y?(Z=(0,t.jsx)("div",{className:"text-2xl font-bold text-warning","data-testid":"qi-moderate",children:y}),e[54]=y,e[55]=Z):Z=e[55];let ee;e[56]!==a?(ee=a("50\u2013100ms avg execution"),e[56]=a,e[57]=ee):ee=e[57];let te;e[58]!==ee?(te=(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:ee}),e[58]=ee,e[59]=te):te=e[59];let re;e[60]!==Z||e[61]!==te?(re=(0,t.jsxs)(pe,{children:[Z,te]}),e[60]=Z,e[61]=te,e[62]=re):re=e[62];let ae;e[63]!==J||e[64]!==re?(ae=(0,t.jsxs)(fe,{children:[J,re]}),e[63]=J,e[64]=re,e[65]=ae):ae=e[65];let se;e[66]!==a?(se=a("Fast queries"),e[66]=a,e[67]=se):se=e[67];let le;e[68]!==se?(le=(0,t.jsx)(Ae,{className:"pb-2",children:(0,t.jsx)(Pe,{className:"text-sm font-medium",children:se})}),e[68]=se,e[69]=le):le=e[69];let ne;e[70]!==A?(ne=(0,t.jsx)("div",{className:"text-2xl font-bold text-success","data-testid":"qi-fast",children:A}),e[70]=A,e[71]=ne):ne=e[71];let ie;e[72]!==a?(ie=a("<50ms avg execution"),e[72]=a,e[73]=ie):ie=e[73];let oe;e[74]!==ie?(oe=(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:ie}),e[74]=ie,e[75]=oe):oe=e[75];let m;e[76]!==ne||e[77]!==oe?(m=(0,t.jsxs)(pe,{children:[ne,oe]}),e[76]=ne,e[77]=oe,e[78]=m):m=e[78];let j;e[79]!==le||e[80]!==m?(j=(0,t.jsxs)(fe,{children:[le,m]}),e[79]=le,e[80]=m,e[81]=j):j=e[81],e[82]!==X||e[83]!==ae||e[84]!==j?(x=(0,t.jsxs)("div",{className:"grid gap-4 md:grid-cols-3",children:[X,ae,j]}),e[82]=X,e[83]=ae,e[84]=j,e[85]=x):x=e[85];let E;e[86]!==a?(E=a("Query leaderboard"),e[86]=a,e[87]=E):E=e[87];let H;e[88]!==E?(H=(0,t.jsx)("h3",{className:"text-lg font-semibold",children:E}),e[88]=E,e[89]=H):H=e[89];let de;e[90]!==r||e[91]!==a?(de=a("Slow queries sorted by {sortField}",{sortField:a(r)}),e[90]=r,e[91]=a,e[92]=de):de=e[92];let be;e[93]!==de?(be=(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:de}),e[93]=de,e[94]=be):be=e[94];let ve;e[95]!==H||e[96]!==be?(ve=(0,t.jsxs)("div",{children:[H,be]}),e[95]=H,e[96]=be,e[97]=ve):ve=e[97];let Ne;e[98]!==a?(Ne=a("Sort by"),e[98]=a,e[99]=Ne):Ne=e[99];let ye;e[100]!==Ne?(ye=(0,t.jsx)("span",{className:"text-sm text-muted-foreground",children:Ne}),e[100]=Ne,e[101]=ye):ye=e[101];let we;e[102]!==a?(we=a("Sort queries by"),e[102]=a,e[103]=we):we=e[103];let Be;e[104]===Symbol.for("react.memo_cache_sentinel")?(Be=(0,t.jsx)(Rt,{}),e[104]=Be):Be=e[104];let Se;e[105]!==we?(Se=(0,t.jsx)(Tt,{"aria-label":we,className:"w-[140px]","data-testid":"qi-sort",children:Be}),e[105]=we,e[106]=Se):Se=e[106];let qe;e[107]!==a?(qe=a("Total time"),e[107]=a,e[108]=qe):qe=e[108];let ke;e[109]!==qe?(ke=(0,t.jsx)(Qe,{value:"totalTime",children:qe}),e[109]=qe,e[110]=ke):ke=e[110];let _e;e[111]!==a?(_e=a("Avg time"),e[111]=a,e[112]=_e):_e=e[112];let Me;e[113]!==_e?(Me=(0,t.jsx)(Qe,{value:"avgTime",children:_e}),e[113]=_e,e[114]=Me):Me=e[114];let De;e[115]!==a?(De=a("Execution count"),e[115]=a,e[116]=De):De=e[116];let Ce;e[117]!==De?(Ce=(0,t.jsx)(Qe,{value:"execCount",children:De}),e[117]=De,e[118]=Ce):Ce=e[118];let Ie;e[119]!==a?(Ie=a("Rows read"),e[119]=a,e[120]=Ie):Ie=e[120];let Re;e[121]!==Ie?(Re=(0,t.jsx)(Qe,{value:"rowsRead",children:Ie}),e[121]=Ie,e[122]=Re):Re=e[122];let Te;e[123]!==ke||e[124]!==Me||e[125]!==Ce||e[126]!==Re?(Te=(0,t.jsxs)(zt,{children:[ke,Me,Ce,Re]}),e[123]=ke,e[124]=Me,e[125]=Ce,e[126]=Re,e[127]=Te):Te=e[127];let ze;e[128]!==r||e[129]!==Se||e[130]!==Te?(ze=(0,t.jsxs)(It,{onValueChange:S,value:r,children:[Se,Te]}),e[128]=r,e[129]=Se,e[130]=Te,e[131]=ze):ze=e[131];let Fe;e[132]!==ye||e[133]!==ze?(Fe=(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[ye,ze]}),e[132]=ye,e[133]=ze,e[134]=Fe):Fe=e[134],e[135]!==ve||e[136]!==Fe?(b=(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[ve,Fe]}),e[135]=ve,e[136]=Fe,e[137]=b):b=e[137],c=fe;let Le;e[138]!==a?(Le=a("Statements"),e[138]=a,e[139]=Le):Le=e[139];let Ee;e[140]!==Le?(Ee=(0,t.jsx)(Pe,{children:Le}),e[140]=Le,e[141]=Ee):Ee=e[141],M=(0,t.jsxs)(Ae,{children:[Ee,(0,t.jsx)(ht,{children:a("{count} tracked statements",{count:I.length})})]}),f=pe,N="space-y-2";let He;e[142]!==n||e[143]!==a?(He=d(z=>{let ue=z.normalizedSql,G=n.has(ue),he=Xe(z.avgDurationMs);return(0,t.jsxs)("div",{className:"overflow-hidden rounded-lg border","data-testid":"qi-row",children:[(0,t.jsxs)("button",{"aria-expanded":G,className:"flex w-full items-center justify-between p-3 text-left transition-colors hover:bg-muted/50",onClick:d(()=>{$(ue)},"onClick"),type:"button",children:[(0,t.jsxs)("div",{className:"flex min-w-0 flex-1 items-center gap-3",children:[(0,t.jsx)(ar,{level:he}),(0,t.jsx)("span",{className:"max-w-[300px] truncate font-mono text-sm lg:max-w-[500px]",children:z.normalizedSql})]}),(0,t.jsxs)("div",{className:"flex shrink-0 items-center gap-4",children:[(0,t.jsxs)("div",{className:"text-right",children:[(0,t.jsx)("div",{className:"text-sm font-medium",children:je(z.totalDurationMs)}),(0,t.jsx)("div",{className:"text-xs text-muted-foreground",children:a("total")})]}),(0,t.jsxs)("div",{className:"text-right",children:[(0,t.jsx)("div",{className:"text-sm font-medium",children:je(z.avgDurationMs)}),(0,t.jsx)("div",{className:"text-xs text-muted-foreground",children:a("avg")})]}),z.p95DurationMs!==void 0&&(0,t.jsxs)("div",{className:"text-right",children:[(0,t.jsx)("div",{className:"text-sm font-medium",children:je(z.p95DurationMs)}),(0,t.jsx)("div",{className:"text-xs text-muted-foreground",children:a("p95")})]}),(0,t.jsxs)("div",{className:"text-right",children:[(0,t.jsx)("div",{className:"text-sm font-medium",children:We(z.execCount)}),(0,t.jsx)("div",{className:"text-xs text-muted-foreground",children:a("calls")})]})]})]}),G&&(0,t.jsxs)("div",{className:"space-y-3 border-t bg-muted/30 p-4",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"mb-2 text-sm font-medium",children:a("Full statement")}),(0,t.jsx)("pre",{className:"overflow-x-auto rounded-md bg-muted p-3 font-mono text-sm whitespace-pre-wrap break-all",children:z.normalizedSql})]}),(0,t.jsxs)("div",{className:"grid grid-cols-2 gap-4 text-sm md:grid-cols-4",children:[z.p50DurationMs!==void 0&&(0,t.jsxs)("div",{children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:a("p50")}),(0,t.jsx)("span",{className:"block font-medium tabular-nums",children:je(z.p50DurationMs)})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:a("Exec count")}),(0,t.jsx)("span",{className:"block font-medium tabular-nums",children:We(z.execCount)})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:a("Total time")}),(0,t.jsx)("span",{className:"block font-medium tabular-nums",children:je(z.totalDurationMs)})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:a("Rows read")}),(0,t.jsx)("span",{className:"block font-medium tabular-nums",children:We(z.rowsRead)})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:a("Rows written")}),(0,t.jsx)("span",{className:"block font-medium tabular-nums",children:We(z.rowsWritten)})]})]})]})]},ue)},"Ke"),e[142]=n,e[143]=a,e[144]=He):He=e[144],q=I.map(He)}e[2]=n,e[3]=s,e[4]=r,e[5]=a,e[6]=f,e[7]=c,e[8]=p,e[9]=N,e[10]=q,e[11]=M,e[12]=o,e[13]=k,e[14]=x,e[15]=b}else f=e[6],c=e[7],p=e[8],N=e[9],q=e[10],M=e[11],o=e[12],k=e[13],x=e[14],b=e[15];if(p!==Symbol.for("react.early_return_sentinel"))return p;let _;e[145]!==N||e[146]!==q?(_=(0,t.jsx)("div",{className:N,children:q}),e[145]=N,e[146]=q,e[147]=_):_=e[147];let D;e[148]!==f||e[149]!==_?(D=(0,t.jsx)(f,{children:_}),e[148]=f,e[149]=_,e[150]=D):D=e[150];let u;e[151]!==c||e[152]!==D||e[153]!==M?(u=(0,t.jsxs)(c,{children:[M,D]}),e[151]=c,e[152]=D,e[153]=M,e[154]=u):u=e[154];let C;return e[155]!==u||e[156]!==o||e[157]!==k||e[158]!==x||e[159]!==b?(C=(0,t.jsxs)("div",{className:o,"data-testid":k,children:[x,b,u]}),e[155]=u,e[156]=o,e[157]=k,e[158]=x,e[159]=b,e[160]=C):C=e[160],C},"ar");function nr(l){return Xe(l.avgDurationMs)==="critical"}d(nr,"ir");function ir(l){return Xe(l.avgDurationMs)==="warning"}d(ir,"nr");function or(l){return Xe(l.avgDurationMs)==="good"}d(or,"or");var dr=["1m","5m","15m","1h"],cr=d(l=>new Date(l).toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"}),"dr"),mr=d(l=>l.map(e=>({avg:Math.round(e.avgDurationMs*100)/100,execs:e.execCount,label:cr(e.bucketMs)})),"mr"),ur=d(({shardKey:l=""})=>{let e=ge(),[s,a]=(0,B.useState)("15m"),r=$e(Ke.getQueryInsights,{range:s},{live:!0,shardKey:l}).data,h=mr(r?.buckets??[]);return(0,t.jsxs)("div",{className:"flex flex-col gap-4","data-testid":"qi-range",children:[(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,t.jsx)("div",{className:"flex gap-1 rounded-lg border border-border p-0.5","data-testid":"qi-ranges",role:"group",children:dr.map(i=>(0,t.jsx)("button",{"aria-pressed":i===s,className:ut("rounded px-2 py-1 text-xs outline-none transition-colors hover:bg-accent focus-visible:bg-accent",i===s&&"bg-accent font-medium text-foreground"),"data-testid":`qi-range-${i}`,onClick:d(()=>{a(i)},"onClick"),type:"button",children:i},i))}),r?.capped===!0&&(0,t.jsx)(Ge,{"data-testid":"qi-capped",variant:"secondary",children:e("showing a capped set")})]}),h.length===0?(0,t.jsx)(gt,{description:e("Statements executed in the selected window appear here, with throughput and latency over time."),testId:"qi-empty",title:e("No queries in this window.")}):(0,t.jsxs)("div",{className:"grid gap-4 lg:grid-cols-2",children:[(0,t.jsxs)("figure",{className:"rounded-xl border border-border p-3","data-testid":"qi-throughput",children:[(0,t.jsx)("figcaption",{className:"mb-2 text-xs font-medium text-muted-foreground",children:e("Throughput")}),(0,t.jsx)(Ze,{height:140,width:"100%",children:(0,t.jsxs)(St,{data:h,children:[(0,t.jsx)(tt,{strokeDasharray:"3 3",vertical:!1}),(0,t.jsx)(rt,{dataKey:"label",fontSize:10,tickLine:!1}),(0,t.jsx)(at,{allowDecimals:!1,fontSize:10,tickLine:!1,width:32}),(0,t.jsx)(et,{}),(0,t.jsx)(yt,{dataKey:"execs",fill:"var(--color-primary)",fillOpacity:.15,stroke:"var(--color-primary)",type:"monotone"})]})})]}),(0,t.jsxs)("figure",{className:"rounded-xl border border-border p-3","data-testid":"qi-latency",children:[(0,t.jsx)("figcaption",{className:"mb-2 text-xs font-medium text-muted-foreground",children:e("Mean latency (ms)")}),(0,t.jsx)(Ze,{height:140,width:"100%",children:(0,t.jsxs)(wt,{data:h,children:[(0,t.jsx)(tt,{strokeDasharray:"3 3",vertical:!1}),(0,t.jsx)(rt,{dataKey:"label",fontSize:10,tickLine:!1}),(0,t.jsx)(at,{fontSize:10,tickLine:!1,width:32}),(0,t.jsx)(et,{}),(0,t.jsx)(Nt,{dataKey:"avg",dot:!1,stroke:"var(--color-destructive)",type:"monotone"})]})})]})]}),(0,t.jsx)(lr,{queryStats:r?.entries??[]})]})},"ur"),hr=ft(Ke.getMetrics),gr=d((l,e)=>l?e:"overview","hr"),Or=d(({initialShardKey:l})=>{let e=mt(),s=ge(),{queryShardKey:a,setShardKey:r,shardKey:h}=Mt(l),[i,n]=(0,B.useState)("overview"),[g,v]=(0,B.useState)([]),S=(0,B.useRef)(null),f=(0,B.useRef)(null),c=(0,B.useRef)(!0);(0,B.useEffect)(()=>(c.current=!0,()=>{c.current=!1}),[]);let p=Lt(a),{data:N,error:q,liveError:M}=$e(Ke.getMetrics,{},{live:!0,shardKey:a}),o=N??null;(0,B.useEffect)(()=>{if(N===void 0)return;kt(a);let L=N,U=S.current,Q=f.current!==null&&f.current!==L.shard;if(f.current=L.shard,S.current=L.requests,Q){v([]);return}U!==null&&L.requests>=U&&v(K=>[...K,L.requests-U].slice(-30))},[N,a]);let[k,x]=(0,B.useState)(null),[b,_]=(0,B.useState)(!1),D=d(async()=>{_(!0);let L=h,U=At(L,qt());try{let Q=await Promise.all(U.map(async K=>{try{let O=await e.query(hr,{},pt(K));return{error:null,metrics:O,shard:K===""?O.shard:K}}catch(O){return{error:xt(O),metrics:null,shard:K===""?"__root__":K}}}));c.current&&x({results:Q,shard:L})}finally{c.current&&_(!1)}},"R"),u=k?.shard===h?k.results:null,C=u===null?null:Kt(u),I=o===null||o.requests===0?"\u2014":`${(o.errors/o.requests*100).toFixed(1)}%`,R=g.length>0?g.at(-1):0,T=o?Pt(o):{p90:0,p95:0},w=(0,B.useMemo)(()=>{if(!o||!("queryStats"in o))return;let L=o.queryStats;if(!(!L||!Array.isArray(L)))return $t(L)},[o]),y=gr(w!==void 0,i),F=d(()=>{vt(D())},"A"),A=d(()=>{x(null)},"F"),P=d(()=>{n("overview")},"z"),$=d(()=>{n("query-insights")},"O");return(0,t.jsxs)("div",{className:"flex flex-col gap-4","data-testid":"lunora-metrics",children:[(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,t.jsx)(_t,{onChange:r,testId:"mt-shard-input",value:h}),(0,t.jsx)(Dt,{message:M,prefix:"mt"}),(0,t.jsx)(Je,{"data-testid":"mt-aggregate",disabled:b,onClick:F,size:"sm",type:"button",variant:"secondary",children:s(b?"Aggregating\u2026":"All shards")}),u!==null&&(0,t.jsx)(Je,{"data-testid":"mt-aggregate-clear",onClick:A,size:"sm",type:"button",variant:"ghost",children:s("Hide")}),(0,t.jsx)("a",{className:"text-sm text-primary underline-offset-4 hover:underline","data-testid":"mt-cf-link",href:Ct,rel:"noreferrer",target:"_blank",children:s("Open in Cloudflare")})]}),q!==null&&(0,t.jsx)("p",{className:"text-sm text-destructive","data-testid":"mt-error",role:"alert",children:q}),w!==void 0&&(0,t.jsxs)("div",{className:"flex gap-2 border-b","data-testid":"mt-tabs",children:[(0,t.jsx)("button",{className:`pb-2 text-sm font-medium transition-colors ${y==="overview"?"border-b-2 border-primary text-foreground":"text-muted-foreground hover:text-foreground"}`,"data-testid":"mt-tab-overview",onClick:P,type:"button",children:s("Overview")}),(0,t.jsxs)("button",{className:`pb-2 text-sm font-medium transition-colors ${y==="query-insights"?"border-b-2 border-primary text-foreground":"text-muted-foreground hover:text-foreground"}`,"data-testid":"mt-tab-query-insights",onClick:$,type:"button",children:[s("Query insights"),w.length>0&&(0,t.jsx)("span",{className:"ml-1.5 rounded-full bg-primary/10 px-1.5 py-0.5 text-xs text-primary",children:w.length})]})]}),y==="query-insights"&&w!==void 0&&(0,t.jsx)(ur,{shardKey:a}),y==="overview"&&o!==null&&(0,t.jsx)(rr,{currentDelta:R,errorRate:I,history:g,latencyPercentiles:T,metrics:o}),y==="overview"&&o===null&&null,y==="overview"&&(0,t.jsx)(er,{onOpenTrace:p,shardKey:a}),y==="overview"&&C!==null&&u!==null&&(0,t.jsx)(tr,{aggregate:C,shardResults:u})]})},"Qr");export{Or as MetricsPanel};
@@ -1 +1 @@
1
- import{a as Z}from"./chunk-R6U22RSY.js";import{a as te}from"./chunk-LXCVA5SP.js";import{a as Y}from"./chunk-7Q256NLI.js";import{b as X}from"./chunk-ZKJS6EBE.js";import{a as W}from"./chunk-FUYEZFBP.js";import"./chunk-RGMVGZV4.js";import{i as G}from"./chunk-OQ6I6OXT.js";import"./chunk-E4PXACVL.js";import"./chunk-MVWZMWPD.js";import"./chunk-SJQERRSZ.js";import"./chunk-7Y3SY37W.js";import{b as ae,c as ne}from"./chunk-KZJ5IOS2.js";import{a as q,b as ee}from"./chunk-N3UPEA6I.js";import{a as Q}from"./chunk-7G4Z6Q7X.js";import"./chunk-3YXASVTP.js";import"./chunk-AUAECCXB.js";import"./chunk-BOMPSVRC.js";import"./chunk-EXYGAGPA.js";import"./chunk-NCPW7WHO.js";import"./chunk-URHYIB3N.js";import"./chunk-55UGUCQ6.js";import{a as I}from"./chunk-4ZEL6BYL.js";import{c as _}from"./chunk-NM6ZWVHT.js";import{l as D}from"./chunk-PFAXMXYQ.js";import"./chunk-QAQDMS6R.js";import"./chunk-3I25WO3P.js";import"./chunk-HCTJKP5J.js";import"./chunk-2IKDEUCX.js";import{d as M,f as C,g as A,m as V,q as N}from"./chunk-74IYYDDI.js";import{a as l,d as j,e as he,f as me,g as pe}from"./chunk-I26MS5PJ.js";var E=j(me(),1);var c=j(he(),1);var S=j(pe(),1);var ge=l(t=>{let{suggestedIndex:e,table:i}=t;if(typeof i!="string"||i.length===0||typeof e!="object"||e===null)return!1;let{fields:a,name:n}=e;return!Array.isArray(a)||a.length===0||a.some(s=>typeof s!="string"||s.length===0)?!1:typeof n=="string"&&n.length>0},"ye"),be=l((t,e)=>`.index(${JSON.stringify(t)}, [${e.map(i=>JSON.stringify(i)).join(", ")}])`,"ge"),ye=l(t=>{let e=(0,E.c)(19),{fields:i,indexName:a,table:n,testId:s}=t,u=M(),[h,f]=(0,c.useState)(null),m;e[0]!==i||e[1]!==a?(m=l(()=>{let b=be(a,i),$="navigator"in globalThis?globalThis.navigator.clipboard:void 0;if($===void 0){f({copied:!1,declaration:b});return}N($.writeText(b).then(()=>(f({copied:!0,declaration:b}),!0)),()=>{f({copied:!1,declaration:b})})},"m"),e[0]=i,e[1]=a,e[2]=m):m=e[2];let x=m;if(h!==null){let b;return e[3]!==h.copied||e[4]!==h.declaration||e[5]!==u||e[6]!==n||e[7]!==s?(b=h.copied?(0,S.jsx)("span",{className:"text-xs text-muted-foreground","data-testid":`${s}-applied`,children:u("Index declaration copied \u2014 add it to {table} in lunora/schema.ts.",{table:n})}):(0,S.jsxs)("span",{className:"flex flex-col gap-1 text-xs text-muted-foreground","data-testid":`${s}-manual`,children:[u("Could not reach the clipboard \u2014 add this to {table} in lunora/schema.ts:",{table:n}),(0,S.jsx)("code",{className:"font-mono break-all select-all",children:h.declaration})]}),e[3]=h.copied,e[4]=h.declaration,e[5]=u,e[6]=n,e[7]=s,e[8]=b):b=e[8],b}let T;e[9]!==u?(T=u("Copy?"),e[9]=u,e[10]=T):T=e[10];let p;e[11]!==u||e[12]!==n?(p=u("Copy index declaration for {table}",{table:n}),e[11]=u,e[12]=n,e[13]=p):p=e[13];let w;return e[14]!==x||e[15]!==T||e[16]!==p||e[17]!==s?(w=(0,S.jsx)(te,{confirmLabel:T,onConfirm:x,testId:s,children:p}),e[14]=x,e[15]=T,e[16]=p,e[17]=s,e[18]=w):w=e[18],w},"ve"),xe=l((t,e)=>{let i=new Map;for(let a of e){let n=`${a.table} ${a.index}`;i.set(n,(i.get(n)??0)+a.reads)}return t.map(a=>({index:a.index,reads:i.get(`${a.table} ${a.index}`)??0,table:a.table}))},"Se"),ve=l(t=>{let e=new Map;for(let i of t)for(let a of i.scannedTables??[])e.set(a.table,(e.get(a.table)??0)+a.scans);return[...e].map(([i,a])=>({scans:a,table:i}))},"Te"),ie=l((t,e)=>e.map(i=>({index:i.name,table:t})),"P"),we=l(t=>{let e=xe(t.declaredIndexes??[],t.indexHits??[]),i=ve(t.functions??[]),a=t.shardTraffic??[],n=t.analyticsMetrics,s=n&&n.indexHits.length>0?n.indexHits:e,u=n&&n.tableScans.length>0?n.tableScans:i,h=n&&n.shardTraffic.length>0?n.shardTraffic:a,f=ne({indexHits:s,schema:{tables:[]},shardTraffic:h,tableScans:u},{lints:ae,source:"runtime"}),m=t.suppressHotScanTables;return(m===void 0?f:f.filter(x=>!(x.metadata.kind==="hot_scan"&&typeof x.metadata.table=="string"&&m.has(x.metadata.table)))).map(x=>q(x))},"we"),Se=C(I.listTables),Te=C(I.listTableIndexes),Ie=C(I.listTablesIndexes),B=l(t=>`${(t*100).toFixed(1)}%`,"L"),re=l(t=>`${(t/1e3).toFixed(2)}s`,"V"),$e=l(t=>{if(t.length<=1)return t[0]??"";let e=t[t.length-1]??"";return`${t.slice(0,-1).join(", ")} and ${e}`},"Ne"),ke=l((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"),"storage-headroom":t("Storage headroom")})[e.kind],"ke"),se=l((t,e)=>({"high-error-rate":t("{rate} of calls failed.",{rate:B(e.value)}),"high-evictions":t("{count} entries evicted recently.",{count:e.value}),"high-write-contention":t("{rate} of calls hit a write conflict \u2014 consider sharding to cut contention.",{rate:B(e.value)}),"low-cache-hit-rate":t("{rate} hit rate over recent traffic.",{rate:B(e.value)}),"missing-index":t("Slowest call took {duration} \u2014 it full-scanned {tables} with no index.",{duration:re(e.value),tables:$e(e.tables??[])}),"slow-function":t("Slowest call took {duration}.",{duration:re(e.value)}),"storage-headroom":t("{size} of the 10 GiB per-shard ceiling \u2014 plan a .shardBy() migration while it still has runway.",{size:V(e.value)})})[e.kind],"U"),Ne=l(t=>{let e=(0,E.c)(10),{onJump:i,table:a}=t,n=M(),s;e[0]!==i||e[1]!==a?(s=l(()=>{i(a)},"i"),e[0]=i,e[1]=a,e[2]=s):s=e[2];let u=s,h=`in-add-index-${a}`,f;e[3]!==n||e[4]!==a?(f=n("Add index on {table}",{table:a}),e[3]=n,e[4]=a,e[5]=f):f=e[5];let m;return e[6]!==u||e[7]!==h||e[8]!==f?(m=(0,S.jsx)(Q,{"data-testid":h,onClick:u,size:"sm",type:"button",variant:"outline",children:f}),e[6]=u,e[7]=h,e[8]=f,e[9]=m):m=e[9],m},"Be"),ze=l(({initialShardKey:t,loadShardTraffic:e})=>{let i=D(),a=G(),n=M(),{queryShardKey:s,setShardKey:u,shardKey:h}=Z(t),[f,m]=(0,c.useState)(null),[x,T]=(0,c.useState)(null),p=(0,c.useRef)(""),w=_(I.getMetrics,{},{live:!0,shardKey:s}),b=_(I.getFunctionStats,{},{live:!0,shardKey:s}),$=_(I.getAdvisories,{},{live:!0,shardKey:s}),L=w.data??null,H=b.data?.functions??null,F=$.data?.advisories??null,J=w.data?.indexHits??null,O=w.error!==null&&b.error!==null?w.error:null,oe=e??(r=>i.shardTraffic(r)),le=l(async(r,y)=>{let o=r[0];if(o===void 0||o===""){p.current===y&&T(null);return}try{let g=await oe(o);if(p.current!==y)return;let d=new Map;for(let v of g.shards)d.has(v.shardKey)||d.set(v.shardKey,{requests:v.requests,shardKey:v.shardKey});T([...d.values()])}catch{p.current===y&&T(null)}},"Y"),de=l(async(r,y)=>{let o=await Promise.allSettled(r.map(async d=>[d,await i.query(Te,{table:d},A(y))])),g=[];for(let d of o)if(d.status==="fulfilled"){let[v,k]=d.value;g.push(...ie(v,k.indexes))}return g},"Z"),z=(0,c.useEffectEvent)(async r=>{p.current=r;let y=[];try{let o=await i.query(Se,{},A(r));if(p.current!==r)return;X(r),y=o.map(d=>d.name);let g=[];if(y.length>0)try{let d=await i.query(Ie,{tables:y},A(r));if(p.current!==r)return;for(let[v,k]of Object.entries(d.indexesByTable))g.push(...ie(v,k))}catch{if(g=await de(y,r),p.current!==r)return}m(g)}catch{p.current===r&&m(null)}await le(y,r)});(0,c.useEffect)(()=>{N(z(s))},[s]);let ce=(0,c.useEffectEvent)(()=>{w.refetch(),b.refetch(),$.refetch(),N(z(s))});(0,c.useEffect)(()=>{let r=l(()=>{document.visibilityState==="visible"&&ce()},"r");return document.addEventListener("visibilitychange",r),()=>{document.removeEventListener("visibilitychange",r)}},[]);let U=(0,c.useCallback)(r=>{N(a({search:{table:r},to:"/schema"}))},[a]),K=(0,c.useMemo)(()=>W(L,H),[H,L]),P=(0,c.useMemo)(()=>new Set(K.filter(r=>r.kind==="missing-index").flatMap(r=>r.tables??[])),[K]),R=(0,c.useMemo)(()=>we({declaredIndexes:f??[],functions:H,indexHits:J,shardTraffic:x,suppressHotScanTables:P}),[f,H,J,P,x]),ue=(0,c.useMemo)(()=>{let r=K.map(o=>{let g=o.kind==="missing-index"?o.tables??[]:[];return{action:g.length>0?g.map(d=>(0,S.jsx)(Ne,{onJump:U,table:d},d)):void 0,description:o.message===void 0?se(n,o):`${se(n,o)} \u2014 ${o.message}`,entity:o.fn,issueType:ke(n,o),key:`${o.kind}:${o.fn??""}`,level:o.severity}}),y=new Set(["unindexed_foreign_key","unindexed_relation_target"]);return[...(F??[]).map(o=>{let g=q(o);if(y.has(o.name)&&ge(o.metadata)){let{table:d,suggestedIndex:v}=o.metadata,k=`in-apply-index-${d}-${v.name}`;return{...g,action:(0,S.jsx)(ye,{fields:v.fields,indexName:v.name,table:d,testId:k})}}return g}),...R,...r]},[F,K,U,R,n]),fe=(0,S.jsx)(Y,{onChange:u,testId:"in-shard-input",value:h});return(0,S.jsx)(ee,{error:O,errorSource:O===null?void 0:w.errorSource,rows:ue,testId:"lunora-insights",toolbar:fe})},"Ue");export{ze as InsightsPanel};
1
+ import{a as Z}from"./chunk-R6U22RSY.js";import{a as te}from"./chunk-LXCVA5SP.js";import{a as Y}from"./chunk-7Q256NLI.js";import{b as X}from"./chunk-ZKJS6EBE.js";import{a as W}from"./chunk-FUYEZFBP.js";import"./chunk-RGMVGZV4.js";import{i as G}from"./chunk-OQ6I6OXT.js";import"./chunk-E4PXACVL.js";import"./chunk-MVWZMWPD.js";import"./chunk-SJQERRSZ.js";import"./chunk-7Y3SY37W.js";import{b as ae,c as ne}from"./chunk-GZEWLX7U.js";import{a as q,b as ee}from"./chunk-E4Y6TF6C.js";import{a as Q}from"./chunk-7G4Z6Q7X.js";import"./chunk-3YXASVTP.js";import"./chunk-AUAECCXB.js";import"./chunk-BOMPSVRC.js";import"./chunk-R75AFV7G.js";import"./chunk-NCPW7WHO.js";import"./chunk-IQ3SMVFW.js";import"./chunk-55UGUCQ6.js";import{a as I}from"./chunk-4ZEL6BYL.js";import{c as _}from"./chunk-T2JHVL34.js";import{l as D}from"./chunk-AVSMQPR3.js";import"./chunk-QAQDMS6R.js";import"./chunk-3I25WO3P.js";import"./chunk-HCTJKP5J.js";import"./chunk-2IKDEUCX.js";import{d as M,f as C,g as A,m as V,q as N}from"./chunk-74IYYDDI.js";import{a as l,d as j,e as he,f as me,g as pe}from"./chunk-I26MS5PJ.js";var E=j(me(),1);var c=j(he(),1);var S=j(pe(),1);var ge=l(t=>{let{suggestedIndex:e,table:i}=t;if(typeof i!="string"||i.length===0||typeof e!="object"||e===null)return!1;let{fields:a,name:n}=e;return!Array.isArray(a)||a.length===0||a.some(s=>typeof s!="string"||s.length===0)?!1:typeof n=="string"&&n.length>0},"ye"),be=l((t,e)=>`.index(${JSON.stringify(t)}, [${e.map(i=>JSON.stringify(i)).join(", ")}])`,"ge"),ye=l(t=>{let e=(0,E.c)(19),{fields:i,indexName:a,table:n,testId:s}=t,u=M(),[h,f]=(0,c.useState)(null),m;e[0]!==i||e[1]!==a?(m=l(()=>{let b=be(a,i),$="navigator"in globalThis?globalThis.navigator.clipboard:void 0;if($===void 0){f({copied:!1,declaration:b});return}N($.writeText(b).then(()=>(f({copied:!0,declaration:b}),!0)),()=>{f({copied:!1,declaration:b})})},"m"),e[0]=i,e[1]=a,e[2]=m):m=e[2];let x=m;if(h!==null){let b;return e[3]!==h.copied||e[4]!==h.declaration||e[5]!==u||e[6]!==n||e[7]!==s?(b=h.copied?(0,S.jsx)("span",{className:"text-xs text-muted-foreground","data-testid":`${s}-applied`,children:u("Index declaration copied \u2014 add it to {table} in lunora/schema.ts.",{table:n})}):(0,S.jsxs)("span",{className:"flex flex-col gap-1 text-xs text-muted-foreground","data-testid":`${s}-manual`,children:[u("Could not reach the clipboard \u2014 add this to {table} in lunora/schema.ts:",{table:n}),(0,S.jsx)("code",{className:"font-mono break-all select-all",children:h.declaration})]}),e[3]=h.copied,e[4]=h.declaration,e[5]=u,e[6]=n,e[7]=s,e[8]=b):b=e[8],b}let T;e[9]!==u?(T=u("Copy?"),e[9]=u,e[10]=T):T=e[10];let p;e[11]!==u||e[12]!==n?(p=u("Copy index declaration for {table}",{table:n}),e[11]=u,e[12]=n,e[13]=p):p=e[13];let w;return e[14]!==x||e[15]!==T||e[16]!==p||e[17]!==s?(w=(0,S.jsx)(te,{confirmLabel:T,onConfirm:x,testId:s,children:p}),e[14]=x,e[15]=T,e[16]=p,e[17]=s,e[18]=w):w=e[18],w},"ve"),xe=l((t,e)=>{let i=new Map;for(let a of e){let n=`${a.table} ${a.index}`;i.set(n,(i.get(n)??0)+a.reads)}return t.map(a=>({index:a.index,reads:i.get(`${a.table} ${a.index}`)??0,table:a.table}))},"Se"),ve=l(t=>{let e=new Map;for(let i of t)for(let a of i.scannedTables??[])e.set(a.table,(e.get(a.table)??0)+a.scans);return[...e].map(([i,a])=>({scans:a,table:i}))},"Te"),ie=l((t,e)=>e.map(i=>({index:i.name,table:t})),"P"),we=l(t=>{let e=xe(t.declaredIndexes??[],t.indexHits??[]),i=ve(t.functions??[]),a=t.shardTraffic??[],n=t.analyticsMetrics,s=n&&n.indexHits.length>0?n.indexHits:e,u=n&&n.tableScans.length>0?n.tableScans:i,h=n&&n.shardTraffic.length>0?n.shardTraffic:a,f=ne({indexHits:s,schema:{tables:[]},shardTraffic:h,tableScans:u},{lints:ae,source:"runtime"}),m=t.suppressHotScanTables;return(m===void 0?f:f.filter(x=>!(x.metadata.kind==="hot_scan"&&typeof x.metadata.table=="string"&&m.has(x.metadata.table)))).map(x=>q(x))},"we"),Se=C(I.listTables),Te=C(I.listTableIndexes),Ie=C(I.listTablesIndexes),B=l(t=>`${(t*100).toFixed(1)}%`,"L"),re=l(t=>`${(t/1e3).toFixed(2)}s`,"V"),$e=l(t=>{if(t.length<=1)return t[0]??"";let e=t[t.length-1]??"";return`${t.slice(0,-1).join(", ")} and ${e}`},"Ne"),ke=l((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"),"storage-headroom":t("Storage headroom")})[e.kind],"ke"),se=l((t,e)=>({"high-error-rate":t("{rate} of calls failed.",{rate:B(e.value)}),"high-evictions":t("{count} entries evicted recently.",{count:e.value}),"high-write-contention":t("{rate} of calls hit a write conflict \u2014 consider sharding to cut contention.",{rate:B(e.value)}),"low-cache-hit-rate":t("{rate} hit rate over recent traffic.",{rate:B(e.value)}),"missing-index":t("Slowest call took {duration} \u2014 it full-scanned {tables} with no index.",{duration:re(e.value),tables:$e(e.tables??[])}),"slow-function":t("Slowest call took {duration}.",{duration:re(e.value)}),"storage-headroom":t("{size} of the 10 GiB per-shard ceiling \u2014 plan a .shardBy() migration while it still has runway.",{size:V(e.value)})})[e.kind],"U"),Ne=l(t=>{let e=(0,E.c)(10),{onJump:i,table:a}=t,n=M(),s;e[0]!==i||e[1]!==a?(s=l(()=>{i(a)},"i"),e[0]=i,e[1]=a,e[2]=s):s=e[2];let u=s,h=`in-add-index-${a}`,f;e[3]!==n||e[4]!==a?(f=n("Add index on {table}",{table:a}),e[3]=n,e[4]=a,e[5]=f):f=e[5];let m;return e[6]!==u||e[7]!==h||e[8]!==f?(m=(0,S.jsx)(Q,{"data-testid":h,onClick:u,size:"sm",type:"button",variant:"outline",children:f}),e[6]=u,e[7]=h,e[8]=f,e[9]=m):m=e[9],m},"Be"),ze=l(({initialShardKey:t,loadShardTraffic:e})=>{let i=D(),a=G(),n=M(),{queryShardKey:s,setShardKey:u,shardKey:h}=Z(t),[f,m]=(0,c.useState)(null),[x,T]=(0,c.useState)(null),p=(0,c.useRef)(""),w=_(I.getMetrics,{},{live:!0,shardKey:s}),b=_(I.getFunctionStats,{},{live:!0,shardKey:s}),$=_(I.getAdvisories,{},{live:!0,shardKey:s}),L=w.data??null,H=b.data?.functions??null,F=$.data?.advisories??null,J=w.data?.indexHits??null,O=w.error!==null&&b.error!==null?w.error:null,oe=e??(r=>i.shardTraffic(r)),le=l(async(r,y)=>{let o=r[0];if(o===void 0||o===""){p.current===y&&T(null);return}try{let g=await oe(o);if(p.current!==y)return;let d=new Map;for(let v of g.shards)d.has(v.shardKey)||d.set(v.shardKey,{requests:v.requests,shardKey:v.shardKey});T([...d.values()])}catch{p.current===y&&T(null)}},"Y"),de=l(async(r,y)=>{let o=await Promise.allSettled(r.map(async d=>[d,await i.query(Te,{table:d},A(y))])),g=[];for(let d of o)if(d.status==="fulfilled"){let[v,k]=d.value;g.push(...ie(v,k.indexes))}return g},"Z"),z=(0,c.useEffectEvent)(async r=>{p.current=r;let y=[];try{let o=await i.query(Se,{},A(r));if(p.current!==r)return;X(r),y=o.map(d=>d.name);let g=[];if(y.length>0)try{let d=await i.query(Ie,{tables:y},A(r));if(p.current!==r)return;for(let[v,k]of Object.entries(d.indexesByTable))g.push(...ie(v,k))}catch{if(g=await de(y,r),p.current!==r)return}m(g)}catch{p.current===r&&m(null)}await le(y,r)});(0,c.useEffect)(()=>{N(z(s))},[s]);let ce=(0,c.useEffectEvent)(()=>{w.refetch(),b.refetch(),$.refetch(),N(z(s))});(0,c.useEffect)(()=>{let r=l(()=>{document.visibilityState==="visible"&&ce()},"r");return document.addEventListener("visibilitychange",r),()=>{document.removeEventListener("visibilitychange",r)}},[]);let U=(0,c.useCallback)(r=>{N(a({search:{table:r},to:"/schema"}))},[a]),K=(0,c.useMemo)(()=>W(L,H),[H,L]),P=(0,c.useMemo)(()=>new Set(K.filter(r=>r.kind==="missing-index").flatMap(r=>r.tables??[])),[K]),R=(0,c.useMemo)(()=>we({declaredIndexes:f??[],functions:H,indexHits:J,shardTraffic:x,suppressHotScanTables:P}),[f,H,J,P,x]),ue=(0,c.useMemo)(()=>{let r=K.map(o=>{let g=o.kind==="missing-index"?o.tables??[]:[];return{action:g.length>0?g.map(d=>(0,S.jsx)(Ne,{onJump:U,table:d},d)):void 0,description:o.message===void 0?se(n,o):`${se(n,o)} \u2014 ${o.message}`,entity:o.fn,issueType:ke(n,o),key:`${o.kind}:${o.fn??""}`,level:o.severity}}),y=new Set(["unindexed_foreign_key","unindexed_relation_target"]);return[...(F??[]).map(o=>{let g=q(o);if(y.has(o.name)&&ge(o.metadata)){let{table:d,suggestedIndex:v}=o.metadata,k=`in-apply-index-${d}-${v.name}`;return{...g,action:(0,S.jsx)(ye,{fields:v.fields,indexName:v.name,table:d,testId:k})}}return g}),...R,...r]},[F,K,U,R,n]),fe=(0,S.jsx)(Y,{onChange:u,testId:"in-shard-input",value:h});return(0,S.jsx)(ee,{error:O,errorSource:O===null?void 0:w.errorSource,rows:ue,testId:"lunora-insights",toolbar:fe})},"Ue");export{ze as InsightsPanel};