@lunora/studio 1.0.0-alpha.357 → 1.0.0-alpha.358

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 (66) hide show
  1. package/dist/standalone/{chunk-Q5GY7D5H.js → chunk-2CPBNLFU.js} +1 -1
  2. package/dist/standalone/{chunk-YHK5UBXI.js → chunk-3HX723U6.js} +1 -1
  3. package/dist/standalone/{chunk-GNVWTK4S.js → chunk-4FZYH76L.js} +1 -1
  4. package/dist/standalone/{chunk-FIJVZCBO.js → chunk-5IGDDSST.js} +1 -1
  5. package/dist/standalone/{chunk-SL7LF2SO.js → chunk-5SYMAYUA.js} +1 -1
  6. package/dist/standalone/{chunk-SPPJFTWE.js → chunk-7KPRMBD6.js} +1 -1
  7. package/dist/standalone/{chunk-SOVH524I.js → chunk-AKGGWCWW.js} +1 -1
  8. package/dist/standalone/{chunk-Z3NZJ4C2.js → chunk-AN2L3XHC.js} +1 -1
  9. package/dist/standalone/{chunk-MQ3FFFP4.js → chunk-B4BK5Q5O.js} +1 -1
  10. package/dist/standalone/{chunk-TIQ3NI77.js → chunk-B6OTKSMY.js} +1 -1
  11. package/dist/standalone/{chunk-DN3HPAOA.js → chunk-BCP3MEB3.js} +1 -1
  12. package/dist/standalone/{chunk-F7GMBSJP.js → chunk-CVUNFP54.js} +1 -1
  13. package/dist/standalone/{chunk-S6OBDEAQ.js → chunk-CZACJYDC.js} +1 -1
  14. package/dist/standalone/{chunk-VO6GV6F2.js → chunk-DPESH5MT.js} +1 -1
  15. package/dist/standalone/{chunk-N5FOHLIG.js → chunk-EAZXULX6.js} +1 -1
  16. package/dist/standalone/{chunk-CDV6T5KM.js → chunk-F4VO76XV.js} +1 -1
  17. package/dist/standalone/{chunk-ILLDX6LU.js → chunk-FACE2CFY.js} +1 -1
  18. package/dist/standalone/{chunk-64S3IDR2.js → chunk-FCRSF54M.js} +1 -1
  19. package/dist/standalone/{chunk-XFTWGZKD.js → chunk-FHGTI6PR.js} +1 -1
  20. package/dist/standalone/{chunk-CHGMDVEQ.js → chunk-FMQ72AKG.js} +1 -1
  21. package/dist/standalone/{chunk-NQX6SAC6.js → chunk-FNUPPZKJ.js} +1 -1
  22. package/dist/standalone/{chunk-ESUUPILO.js → chunk-FRN6D6MP.js} +1 -1
  23. package/dist/standalone/{chunk-D5LY65EX.js → chunk-FSWWDMW2.js} +1 -1
  24. package/dist/standalone/{chunk-VPG46PCA.js → chunk-FYWZRJCT.js} +1 -1
  25. package/dist/standalone/{chunk-IMF6DJKL.js → chunk-GMO7IUXO.js} +1 -1
  26. package/dist/standalone/{chunk-OGKRWT6I.js → chunk-HGT4YHTI.js} +1 -1
  27. package/dist/standalone/{chunk-EEPCLLGE.js → chunk-HONLEKH5.js} +1 -1
  28. package/dist/standalone/{chunk-SV34MAIK.js → chunk-HSLO46OW.js} +1 -1
  29. package/dist/standalone/{chunk-UWAVY3IF.js → chunk-IIJXS3KP.js} +1 -1
  30. package/dist/standalone/{chunk-UHGLZ5RV.js → chunk-IWG2D7QS.js} +1 -1
  31. package/dist/standalone/{chunk-R66XCM3J.js → chunk-JYCRY3LM.js} +1 -1
  32. package/dist/standalone/{chunk-7DMOBHYC.js → chunk-KRDWV6YM.js} +1 -1
  33. package/dist/standalone/{chunk-RNHTOEL7.js → chunk-KRH6UDVU.js} +1 -1
  34. package/dist/standalone/{chunk-M3KSCNKR.js → chunk-LVNPLZDL.js} +1 -1
  35. package/dist/standalone/{chunk-ZXUEBA56.js → chunk-MC577GI5.js} +1 -1
  36. package/dist/standalone/{chunk-U2YFL6EA.js → chunk-MHJNM7VT.js} +1 -1
  37. package/dist/standalone/{chunk-3QGR4DC7.js → chunk-MI7DM536.js} +1 -1
  38. package/dist/standalone/{chunk-I2PP6Q6F.js → chunk-MY7ZGJOD.js} +1 -1
  39. package/dist/standalone/{chunk-E423VRTC.js → chunk-N4AWDORA.js} +1 -1
  40. package/dist/standalone/{chunk-O6XMGPGY.js → chunk-NEZRBBPI.js} +1 -1
  41. package/dist/standalone/{chunk-YJYXN3WQ.js → chunk-NSUOMZWM.js} +1 -1
  42. package/dist/standalone/{chunk-NXNUGQHB.js → chunk-OIBN6KMM.js} +1 -1
  43. package/dist/standalone/{chunk-R5ACA3OC.js → chunk-OSQYIZAV.js} +1 -1
  44. package/dist/standalone/{chunk-AZRUSOAH.js → chunk-OX7I5YHU.js} +1 -1
  45. package/dist/standalone/{chunk-QSNQXPIX.js → chunk-PBKTGB7B.js} +1 -1
  46. package/dist/standalone/{chunk-GZX5XABE.js → chunk-PCMV6S7K.js} +1 -1
  47. package/dist/standalone/{chunk-OT4KZ6Y6.js → chunk-PMGNJZYE.js} +1 -1
  48. package/dist/standalone/{chunk-BCIFRJ3Q.js → chunk-PTCC45P7.js} +1 -1
  49. package/dist/standalone/{chunk-AMLIZFTD.js → chunk-QXHMVPS3.js} +1 -1
  50. package/dist/standalone/{chunk-TNII7Q2L.js → chunk-SUOVLXY6.js} +1 -1
  51. package/dist/standalone/{chunk-DUQ7KXNS.js → chunk-TA3DCQUA.js} +1 -1
  52. package/dist/standalone/{chunk-5KD75VXP.js → chunk-UFPN44MP.js} +1 -1
  53. package/dist/standalone/{chunk-7W6WESSS.js → chunk-V6SVNLUM.js} +1 -1
  54. package/dist/standalone/{chunk-4SJDWMH3.js → chunk-W37HRJGQ.js} +1 -1
  55. package/dist/standalone/{chunk-ZZ5564FZ.js → chunk-WC5QFZYZ.js} +1 -1
  56. package/dist/standalone/{chunk-FXTT2XP3.js → chunk-WCWSMX3N.js} +1 -1
  57. package/dist/standalone/{chunk-OKSZWLJX.js → chunk-WOGVVXGF.js} +1 -1
  58. package/dist/standalone/{chunk-4BNWYVLP.js → chunk-XIVWJUD3.js} +1 -1
  59. package/dist/standalone/{chunk-2CWGRQ5L.js → chunk-XZ6B5XNN.js} +1 -1
  60. package/dist/standalone/{chunk-AQJXOPBW.js → chunk-XZKWGTLI.js} +1 -1
  61. package/dist/standalone/{chunk-TAGWTOFD.js → chunk-ZD53YB3L.js} +1 -1
  62. package/dist/standalone/{chunk-5IIX2STA.js → chunk-ZFFZWSDJ.js} +1 -1
  63. package/dist/standalone/{chunk-2PHY5V5E.js → chunk-ZQOPXQIT.js} +1 -1
  64. package/dist/standalone/studio.js +1 -1
  65. package/package.json +5 -5
  66. /package/dist/standalone/{chunk-FKM35PXF.js → chunk-SDSQIQJG.js} +0 -0
@@ -1 +1 @@
1
- import{d as E,e as _}from"./chunk-VEWQWS3J.js";import{a as $}from"./chunk-AOHKAKKL.js";import{a as de}from"./chunk-EEPCLLGE.js";import"./chunk-5IIX2STA.js";import{a as ce}from"./chunk-TRZTGE4R.js";import"./chunk-IH2CJZF2.js";import"./chunk-SYGCASPT.js";import"./chunk-ZGSL4DPP.js";import{a as le}from"./chunk-5DNGK3NT.js";import{a as re}from"./chunk-KYONGQQ4.js";import"./chunk-SLIDAWNX.js";import"./chunk-6M7FLLMT.js";import"./chunk-LUHXNZI4.js";import"./chunk-ZTOREMGH.js";import"./chunk-SDQH4HR6.js";import"./chunk-W7MRISE3.js";import"./chunk-IBJVVHV5.js";import"./chunk-ZBON5T5A.js";import{b as K}from"./chunk-6I42AM75.js";import"./chunk-4C4THJUD.js";import{a as ie}from"./chunk-IMF6DJKL.js";import"./chunk-OSJ7HV7B.js";import"./chunk-SL7LF2SO.js";import"./chunk-E26OT26O.js";import{a as J}from"./chunk-6UTZXEW3.js";import{c as H}from"./chunk-4SJDWMH3.js";import"./chunk-FKM35PXF.js";import"./chunk-WZTY3ZYI.js";import{a as ne}from"./chunk-3Y5K3IQO.js";import{a as R,b as W,c as Z,d as A,e as M,f as S}from"./chunk-CW57Q264.js";import{a as q,b as D,c as U,e as oe}from"./chunk-MD67S53Z.js";import{f as F,w as ae}from"./chunk-LPINY2IJ.js";import{a as p,d as se,f as be,g as ge}from"./chunk-OXFKZ4BM.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-VEWQWS3J.js";import{a as $}from"./chunk-AOHKAKKL.js";import{a as de}from"./chunk-HONLEKH5.js";import"./chunk-ZFFZWSDJ.js";import{a as ce}from"./chunk-TRZTGE4R.js";import"./chunk-IH2CJZF2.js";import"./chunk-SYGCASPT.js";import"./chunk-ZGSL4DPP.js";import{a as le}from"./chunk-5DNGK3NT.js";import{a as re}from"./chunk-KYONGQQ4.js";import"./chunk-SLIDAWNX.js";import"./chunk-6M7FLLMT.js";import"./chunk-LUHXNZI4.js";import"./chunk-ZTOREMGH.js";import"./chunk-SDQH4HR6.js";import"./chunk-W7MRISE3.js";import"./chunk-IBJVVHV5.js";import"./chunk-ZBON5T5A.js";import{b as K}from"./chunk-6I42AM75.js";import"./chunk-4C4THJUD.js";import{a as ie}from"./chunk-GMO7IUXO.js";import"./chunk-OSJ7HV7B.js";import"./chunk-5SYMAYUA.js";import"./chunk-E26OT26O.js";import{a as J}from"./chunk-6UTZXEW3.js";import{c as H}from"./chunk-W37HRJGQ.js";import"./chunk-SDSQIQJG.js";import"./chunk-WZTY3ZYI.js";import{a as ne}from"./chunk-3Y5K3IQO.js";import{a as R,b as W,c as Z,d as A,e as M,f as S}from"./chunk-CW57Q264.js";import{a as q,b as D,c as U,e as oe}from"./chunk-MD67S53Z.js";import{f as F,w as ae}from"./chunk-LPINY2IJ.js";import{a as p,d as se,f as be,g as ge}from"./chunk-OXFKZ4BM.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{a as Z}from"./chunk-5DNGK3NT.js";import{a as te}from"./chunk-ZWDORIZY.js";import{a as Y}from"./chunk-KYONGQQ4.js";import{b as X}from"./chunk-SLIDAWNX.js";import{a as W}from"./chunk-DBVJ5VLI.js";import"./chunk-6M7FLLMT.js";import{i as D}from"./chunk-LUHXNZI4.js";import"./chunk-ZTOREMGH.js";import"./chunk-SDQH4HR6.js";import"./chunk-W7MRISE3.js";import"./chunk-IBJVVHV5.js";import{b as ae,c as ne}from"./chunk-WS36BO4R.js";import{a as q,b as ee}from"./chunk-NXNUGQHB.js";import{a as G}from"./chunk-2O6KKVH2.js";import"./chunk-JTGGWF7R.js";import"./chunk-ZBON5T5A.js";import"./chunk-4C4THJUD.js";import"./chunk-IMF6DJKL.js";import"./chunk-OSJ7HV7B.js";import"./chunk-SL7LF2SO.js";import"./chunk-E26OT26O.js";import{a as I}from"./chunk-6UTZXEW3.js";import{c as _}from"./chunk-4SJDWMH3.js";import{p as V}from"./chunk-FKM35PXF.js";import"./chunk-WZTY3ZYI.js";import"./chunk-CW57Q264.js";import"./chunk-MD67S53Z.js";import{f as M,h as C,i as A,o as Q,s as N}from"./chunk-LPINY2IJ.js";import{a as l,d as j,e as he,f as me,g as pe}from"./chunk-OXFKZ4BM.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)}%`,"H"),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:Q(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)(G,{"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=V(),a=D(),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-5DNGK3NT.js";import{a as te}from"./chunk-ZWDORIZY.js";import{a as Y}from"./chunk-KYONGQQ4.js";import{b as X}from"./chunk-SLIDAWNX.js";import{a as W}from"./chunk-DBVJ5VLI.js";import"./chunk-6M7FLLMT.js";import{i as D}from"./chunk-LUHXNZI4.js";import"./chunk-ZTOREMGH.js";import"./chunk-SDQH4HR6.js";import"./chunk-W7MRISE3.js";import"./chunk-IBJVVHV5.js";import{b as ae,c as ne}from"./chunk-WS36BO4R.js";import{a as q,b as ee}from"./chunk-OIBN6KMM.js";import{a as G}from"./chunk-2O6KKVH2.js";import"./chunk-JTGGWF7R.js";import"./chunk-ZBON5T5A.js";import"./chunk-4C4THJUD.js";import"./chunk-GMO7IUXO.js";import"./chunk-OSJ7HV7B.js";import"./chunk-5SYMAYUA.js";import"./chunk-E26OT26O.js";import{a as I}from"./chunk-6UTZXEW3.js";import{c as _}from"./chunk-W37HRJGQ.js";import{p as V}from"./chunk-SDSQIQJG.js";import"./chunk-WZTY3ZYI.js";import"./chunk-CW57Q264.js";import"./chunk-MD67S53Z.js";import{f as M,h as C,i as A,o as Q,s as N}from"./chunk-LPINY2IJ.js";import{a as l,d as j,e as he,f as me,g as pe}from"./chunk-OXFKZ4BM.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)}%`,"H"),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:Q(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)(G,{"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=V(),a=D(),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 +1 @@
1
- import{i as R}from"./chunk-SDQH4HR6.js";import"./chunk-W7MRISE3.js";import"./chunk-IBJVVHV5.js";import{a as B}from"./chunk-2O6KKVH2.js";import"./chunk-JTGGWF7R.js";import"./chunk-ZBON5T5A.js";import{b as S}from"./chunk-6I42AM75.js";import"./chunk-4C4THJUD.js";import{a as q}from"./chunk-IMF6DJKL.js";import"./chunk-OSJ7HV7B.js";import"./chunk-SL7LF2SO.js";import"./chunk-E26OT26O.js";import{a as U}from"./chunk-6UTZXEW3.js";import{c as O}from"./chunk-4SJDWMH3.js";import"./chunk-FKM35PXF.js";import"./chunk-WZTY3ZYI.js";import{a as D}from"./chunk-3Y5K3IQO.js";import{a as G,b as J,c as K,d as F,e as s,f as o}from"./chunk-CW57Q264.js";import{a as V,e as W}from"./chunk-MD67S53Z.js";import{f as P,w as H}from"./chunk-LPINY2IJ.js";import{a as n,d as j,e as re,f as ae,g as ie}from"./chunk-OXFKZ4BM.js";var X=j(ae(),1),M=j(re(),1);var t=j(ie(),1);var ne=n(e=>e==="ok"?"success":e==="failed"?"destructive":e==="expired"?"warning":"secondary","te"),Q=n(e=>e.endpoint??e.id,"M"),ve=n(()=>{let e=(0,X.c)(38),r=P(),[i,Y]=(0,M.useState)("all"),[l,Z]=(0,M.useState)(""),g;e[0]===Symbol.for("react.memo_cache_sentinel")?(g={},e[0]=g):g=e[0];let{data:I,error:d,errorSource:x,isLoading:_,refetch:v}=O(U.listPushSubscriptions,g),N;if(e[1]!==I?.subscriptions||e[2]!==d||e[3]!==x||e[4]!==_||e[5]!==i||e[6]!==v||e[7]!==l||e[8]!==r){let L=I?.subscriptions??[],T=l.trim().toLowerCase(),A=L.filter(a=>i!=="all"&&a.kind!==i?!1:T===""?!0:`${Q(a)} ${a.userId??""}`.toLowerCase().includes(T)),b;e[10]===Symbol.for("react.memo_cache_sentinel")?(b=n(a=>{Z(a.target.value)},"w"),e[10]=b):b=e[10];let ee=b,w;e[11]!==v?(w=n(()=>{v()},"y"),e[11]=v,e[12]=w):w=e[12];let E=w,k;e[13]===Symbol.for("react.memo_cache_sentinel")?(k=["all","web-push","fcm"],e[13]=k):k=e[13];let te=k,c;e[14]!==i||e[15]!==r?(c=(0,t.jsx)("div",{className:"flex items-center gap-1","data-testid":"nt-kind-filter",role:"tablist",children:te.map(a=>(0,t.jsx)(B,{"aria-selected":i===a,"data-testid":`nt-kind-${a}`,onClick:n(()=>{Y(a)},"onClick"),role:"tab",size:"sm",type:"button",variant:i===a?"secondary":"ghost",children:a==="all"?r("All"):a},a))}),e[14]=i,e[15]=r,e[16]=c):c=e[16];let m;e[17]!==r?(m=r("Filter devices"),e[17]=r,e[18]=m):m=e[18];let h;e[19]!==r?(h=r("filter endpoint, user"),e[19]=r,e[20]=h):h=e[20];let u;e[21]!==l||e[22]!==m||e[23]!==h?(u=(0,t.jsx)(R,{"aria-label":m,className:"h-8 w-56","data-testid":"nt-search",onChange:ee,placeholder:h,value:l}),e[21]=l,e[22]=m,e[23]=h,e[24]=u):u=e[24];let f;e[25]!==r?(f=r("Refresh"),e[25]=r,e[26]=f):f=e[26];let p;e[27]!==E||e[28]!==f?(p=(0,t.jsx)(B,{className:"ml-auto","data-testid":"nt-refresh",onClick:E,size:"sm",type:"button",variant:"outline",children:f}),e[27]=E,e[28]=f,e[29]=p):p=e[29];let $=L.length>0&&(0,t.jsx)(S,{"data-testid":"nt-count",variant:"secondary",children:r("{count} devices",{count:L.length})}),y;e[30]!==p||e[31]!==$||e[32]!==c||e[33]!==u?(y=(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[c,u,p,$]}),e[30]=p,e[31]=$,e[32]=c,e[33]=u,e[34]=y):y=e[34];let C;e[35]!==d||e[36]!==x?(C=d!==null&&(0,t.jsx)(q,{error:x,testId:"nt-error"}),e[35]=d,e[36]=x,e[37]=C):C=e[37],N=(0,t.jsxs)("div",{className:"flex flex-col gap-4","data-testid":"lunora-notifications",children:[y,C,d===null&&!_&&A.length===0&&(0,t.jsx)(D,{description:r("Registered Web Push / FCM devices appear here. Configure lunora/notify.ts with defineNotify({ store }) and register a device with ctx.push.register(...)."),icon:(0,t.jsx)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,t.jsx)("path",{d:"M15 17h5l-1.4-1.4A2 2 0 0 1 18 14.2V11a6 6 0 0 0-4-5.7V5a2 2 0 1 0-4 0v.3A6 6 0 0 0 6 11v3.2a2 2 0 0 1-.6 1.4L4 17h5m6 0v1a3 3 0 1 1-6 0v-1m6 0H9"})}),testId:"nt-empty",title:r("No registered devices.")}),A.length>0&&(0,t.jsx)(V,{className:"overflow-hidden py-0",children:(0,t.jsx)(W,{className:"max-h-[30rem] overflow-auto px-0",children:(0,t.jsxs)(G,{"data-testid":"nt-table",children:[(0,t.jsx)(J,{children:(0,t.jsxs)(F,{children:[(0,t.jsx)(s,{children:r("kind")}),(0,t.jsx)(s,{children:r("endpoint")}),(0,t.jsx)(s,{children:r("user")}),(0,t.jsx)(s,{children:r("last seen")}),(0,t.jsx)(s,{children:r("status")}),(0,t.jsx)(s,{children:r("error")})]})}),(0,t.jsx)(K,{children:A.map(a=>{let z=Q(a);return(0,t.jsxs)(F,{"data-testid":"nt-row",children:[(0,t.jsx)(o,{children:(0,t.jsx)(S,{variant:"outline",children:a.kind})}),(0,t.jsx)(o,{className:"max-w-[28ch] truncate font-mono text-xs",title:z,children:z}),(0,t.jsx)(o,{className:"max-w-[16ch] truncate font-mono text-xs",children:a.userId??(0,t.jsx)("span",{className:"text-muted-foreground",children:"\u2014"})}),(0,t.jsx)(o,{className:"text-muted-foreground tabular-nums",children:H(a.lastSeenAt,"\u2014")}),(0,t.jsx)(o,{children:(0,t.jsx)(S,{"data-testid":`nt-status-${a.id}`,variant:ne(a.lastStatus),children:a.lastStatus??r("n/a")})}),(0,t.jsx)(o,{className:"max-w-[28ch] truncate font-mono text-xs text-muted-foreground",title:a.lastError??void 0,children:a.lastError??(0,t.jsx)("span",{className:"text-muted-foreground",children:"\u2014"})})]},a.id)})})]})})})]}),e[1]=I?.subscriptions,e[2]=d,e[3]=x,e[4]=_,e[5]=i,e[6]=v,e[7]=l,e[8]=r,e[9]=N}else N=e[9];return N},"ge");export{ve as default};
1
+ import{i as R}from"./chunk-SDQH4HR6.js";import"./chunk-W7MRISE3.js";import"./chunk-IBJVVHV5.js";import{a as B}from"./chunk-2O6KKVH2.js";import"./chunk-JTGGWF7R.js";import"./chunk-ZBON5T5A.js";import{b as S}from"./chunk-6I42AM75.js";import"./chunk-4C4THJUD.js";import{a as q}from"./chunk-GMO7IUXO.js";import"./chunk-OSJ7HV7B.js";import"./chunk-5SYMAYUA.js";import"./chunk-E26OT26O.js";import{a as U}from"./chunk-6UTZXEW3.js";import{c as O}from"./chunk-W37HRJGQ.js";import"./chunk-SDSQIQJG.js";import"./chunk-WZTY3ZYI.js";import{a as D}from"./chunk-3Y5K3IQO.js";import{a as G,b as J,c as K,d as F,e as s,f as o}from"./chunk-CW57Q264.js";import{a as V,e as W}from"./chunk-MD67S53Z.js";import{f as P,w as H}from"./chunk-LPINY2IJ.js";import{a as n,d as j,e as re,f as ae,g as ie}from"./chunk-OXFKZ4BM.js";var X=j(ae(),1),M=j(re(),1);var t=j(ie(),1);var ne=n(e=>e==="ok"?"success":e==="failed"?"destructive":e==="expired"?"warning":"secondary","te"),Q=n(e=>e.endpoint??e.id,"M"),ve=n(()=>{let e=(0,X.c)(38),r=P(),[i,Y]=(0,M.useState)("all"),[l,Z]=(0,M.useState)(""),g;e[0]===Symbol.for("react.memo_cache_sentinel")?(g={},e[0]=g):g=e[0];let{data:I,error:d,errorSource:x,isLoading:_,refetch:v}=O(U.listPushSubscriptions,g),N;if(e[1]!==I?.subscriptions||e[2]!==d||e[3]!==x||e[4]!==_||e[5]!==i||e[6]!==v||e[7]!==l||e[8]!==r){let L=I?.subscriptions??[],T=l.trim().toLowerCase(),A=L.filter(a=>i!=="all"&&a.kind!==i?!1:T===""?!0:`${Q(a)} ${a.userId??""}`.toLowerCase().includes(T)),b;e[10]===Symbol.for("react.memo_cache_sentinel")?(b=n(a=>{Z(a.target.value)},"w"),e[10]=b):b=e[10];let ee=b,w;e[11]!==v?(w=n(()=>{v()},"y"),e[11]=v,e[12]=w):w=e[12];let E=w,k;e[13]===Symbol.for("react.memo_cache_sentinel")?(k=["all","web-push","fcm"],e[13]=k):k=e[13];let te=k,c;e[14]!==i||e[15]!==r?(c=(0,t.jsx)("div",{className:"flex items-center gap-1","data-testid":"nt-kind-filter",role:"tablist",children:te.map(a=>(0,t.jsx)(B,{"aria-selected":i===a,"data-testid":`nt-kind-${a}`,onClick:n(()=>{Y(a)},"onClick"),role:"tab",size:"sm",type:"button",variant:i===a?"secondary":"ghost",children:a==="all"?r("All"):a},a))}),e[14]=i,e[15]=r,e[16]=c):c=e[16];let m;e[17]!==r?(m=r("Filter devices"),e[17]=r,e[18]=m):m=e[18];let h;e[19]!==r?(h=r("filter endpoint, user"),e[19]=r,e[20]=h):h=e[20];let u;e[21]!==l||e[22]!==m||e[23]!==h?(u=(0,t.jsx)(R,{"aria-label":m,className:"h-8 w-56","data-testid":"nt-search",onChange:ee,placeholder:h,value:l}),e[21]=l,e[22]=m,e[23]=h,e[24]=u):u=e[24];let f;e[25]!==r?(f=r("Refresh"),e[25]=r,e[26]=f):f=e[26];let p;e[27]!==E||e[28]!==f?(p=(0,t.jsx)(B,{className:"ml-auto","data-testid":"nt-refresh",onClick:E,size:"sm",type:"button",variant:"outline",children:f}),e[27]=E,e[28]=f,e[29]=p):p=e[29];let $=L.length>0&&(0,t.jsx)(S,{"data-testid":"nt-count",variant:"secondary",children:r("{count} devices",{count:L.length})}),y;e[30]!==p||e[31]!==$||e[32]!==c||e[33]!==u?(y=(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[c,u,p,$]}),e[30]=p,e[31]=$,e[32]=c,e[33]=u,e[34]=y):y=e[34];let C;e[35]!==d||e[36]!==x?(C=d!==null&&(0,t.jsx)(q,{error:x,testId:"nt-error"}),e[35]=d,e[36]=x,e[37]=C):C=e[37],N=(0,t.jsxs)("div",{className:"flex flex-col gap-4","data-testid":"lunora-notifications",children:[y,C,d===null&&!_&&A.length===0&&(0,t.jsx)(D,{description:r("Registered Web Push / FCM devices appear here. Configure lunora/notify.ts with defineNotify({ store }) and register a device with ctx.push.register(...)."),icon:(0,t.jsx)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,t.jsx)("path",{d:"M15 17h5l-1.4-1.4A2 2 0 0 1 18 14.2V11a6 6 0 0 0-4-5.7V5a2 2 0 1 0-4 0v.3A6 6 0 0 0 6 11v3.2a2 2 0 0 1-.6 1.4L4 17h5m6 0v1a3 3 0 1 1-6 0v-1m6 0H9"})}),testId:"nt-empty",title:r("No registered devices.")}),A.length>0&&(0,t.jsx)(V,{className:"overflow-hidden py-0",children:(0,t.jsx)(W,{className:"max-h-[30rem] overflow-auto px-0",children:(0,t.jsxs)(G,{"data-testid":"nt-table",children:[(0,t.jsx)(J,{children:(0,t.jsxs)(F,{children:[(0,t.jsx)(s,{children:r("kind")}),(0,t.jsx)(s,{children:r("endpoint")}),(0,t.jsx)(s,{children:r("user")}),(0,t.jsx)(s,{children:r("last seen")}),(0,t.jsx)(s,{children:r("status")}),(0,t.jsx)(s,{children:r("error")})]})}),(0,t.jsx)(K,{children:A.map(a=>{let z=Q(a);return(0,t.jsxs)(F,{"data-testid":"nt-row",children:[(0,t.jsx)(o,{children:(0,t.jsx)(S,{variant:"outline",children:a.kind})}),(0,t.jsx)(o,{className:"max-w-[28ch] truncate font-mono text-xs",title:z,children:z}),(0,t.jsx)(o,{className:"max-w-[16ch] truncate font-mono text-xs",children:a.userId??(0,t.jsx)("span",{className:"text-muted-foreground",children:"\u2014"})}),(0,t.jsx)(o,{className:"text-muted-foreground tabular-nums",children:H(a.lastSeenAt,"\u2014")}),(0,t.jsx)(o,{children:(0,t.jsx)(S,{"data-testid":`nt-status-${a.id}`,variant:ne(a.lastStatus),children:a.lastStatus??r("n/a")})}),(0,t.jsx)(o,{className:"max-w-[28ch] truncate font-mono text-xs text-muted-foreground",title:a.lastError??void 0,children:a.lastError??(0,t.jsx)("span",{className:"text-muted-foreground",children:"\u2014"})})]},a.id)})})]})})})]}),e[1]=I?.subscriptions,e[2]=d,e[3]=x,e[4]=_,e[5]=i,e[6]=v,e[7]=l,e[8]=r,e[9]=N}else N=e[9];return N},"ge");export{ve as default};
@@ -1,3 +1,3 @@
1
- import{a as at}from"./chunk-DBVJ5VLI.js";import{i as Ee}from"./chunk-LUHXNZI4.js";import{a as Fe}from"./chunk-2O6KKVH2.js";import{b as We}from"./chunk-6I42AM75.js";import{a as D}from"./chunk-6UTZXEW3.js";import{c as _e}from"./chunk-4SJDWMH3.js";import{p as Te}from"./chunk-FKM35PXF.js";import{a as Ze}from"./chunk-3Y5K3IQO.js";import{a as j,e as Ue}from"./chunk-MD67S53Z.js";import{b as Ve,f as $,h as Qe,i as Xe,o as et,s as Ne,u as tt,v as nt}from"./chunk-LPINY2IJ.js";import{a as c,d as ze,e as dt,f as mt,g as ut}from"./chunk-OXFKZ4BM.js";var _=ze(mt(),1);var B=ze(dt(),1);var a=ze(ut(),1);var pt=Qe(D.studioFeatures),Ge={analytics:!0,auth:!0,containers:!0,flags:!0,kv:!0,mail:!0,notifications:!0,payments:!0,privacy:!0,queues:!0,scheduler:!0,storage:!0,vectors:!0,workflows:!0},ft=c(t=>{if(t===null||typeof t!="object")return;let{id:e,name:r,unsupported:n}=t;if(!(typeof e!="string"||typeof r!="string"||!Array.isArray(n)))return{id:e,name:r,unsupported:n.filter(s=>typeof s=="string")}},"ut"),ht=c(t=>{if(t===null||typeof t!="object")return Ge;let e=t,r=c(n=>typeof e[n]=="boolean"?e[n]:!0,"n");return{analytics:r("analytics"),auth:r("auth"),containers:r("containers"),flags:r("flags"),kv:r("kv"),mail:r("mail"),notifications:r("notifications"),payments:r("payments"),privacy:r("privacy"),platform:ft(e.platform),queues:r("queues"),scheduler:r("scheduler"),storage:r("storage"),vectors:r("vectors"),workflows:r("workflows")}},"mt"),gt={...Ge,settled:!1},xt=c(()=>{let t=(0,_.c)(3),e=Te(),[r,n]=(0,B.useState)(void 0),s,l;return t[0]!==e?(s=c(()=>{let i=new AbortController;return Ne((async()=>{let o;try{o={...ht(await e.query(pt,{},Xe(""))),settled:!0}}catch{o={...Ge,settled:!0}}i.signal.aborted||n({client:e,features:o})})()),()=>{i.abort()}},"l"),l=[e],t[0]=e,t[1]=s,t[2]=l):(s=t[1],l=t[2]),(0,B.useEffect)(s,l),r?.client===e?r.features:gt},"pt"),bt=c(()=>{let t=(0,_.c)(1),e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=(0,a.jsx)("svg",{"aria-hidden":"true",className:"size-4 text-muted-foreground",fill:"none",stroke:"currentColor",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,a.jsx)("path",{d:"m9 6 6 6-6 6",strokeLinecap:"round",strokeLinejoin:"round"})}),t[0]=e):e=t[0],e},"ht"),yt=c(t=>{let e=(0,_.c)(24),{group:r}=t,n=$(),s=Ee(),l;e[0]!==r.tab||e[1]!==s?(l=c(()=>{Ne(s({to:`/${r.tab}`}))},"r"),e[0]=r.tab,e[1]=s,e[2]=l):l=e[2];let i=l,o=r.bindings.length,d;e[3]!==r.label?(d=(0,a.jsx)("span",{className:"text-sm font-medium text-foreground",children:r.label}),e[3]=r.label,e[4]=d):d=e[4];let u;e[5]===Symbol.for("react.memo_cache_sentinel")?(u=(0,a.jsx)(bt,{}),e[5]=u):u=e[5];let p;e[6]!==d?(p=(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[d,u]}),e[6]=d,e[7]=p):p=e[7];let m;e[8]!==o||e[9]!==n?(m=o===1?n("1 binding"):n("{count} bindings",{count:o}),e[8]=o,e[9]=n,e[10]=m):m=e[10];let f;e[11]!==m?(f=(0,a.jsx)("span",{className:"text-xs text-muted-foreground",children:m}),e[11]=m,e[12]=f):f=e[12];let h;e[13]!==o||e[14]!==r.bindings?(h=o>0&&(0,a.jsx)("div",{className:"flex flex-wrap gap-1.5",children:r.bindings.map(_t)}),e[13]=o,e[14]=r.bindings,e[15]=h):h=e[15];let g;e[16]!==p||e[17]!==f||e[18]!==h?(g=(0,a.jsxs)(Ue,{className:"flex flex-col gap-2 py-4",children:[p,f,h]}),e[16]=p,e[17]=f,e[18]=h,e[19]=g):g=e[19];let x;return e[20]!==r.testId||e[21]!==i||e[22]!==g?(x=(0,a.jsx)(j,{className:"cursor-pointer gap-0 py-0 transition-colors hover:bg-muted/40","data-testid":r.testId,onClick:i,children:g}),e[20]=r.testId,e[21]=i,e[22]=g,e[23]=x):x=e[23],x},"gt"),rt=["kv","files","vectors"],vt=c((t,e)=>[...t.filter(r=>r.tab!==e.tab),e].toSorted((r,n)=>rt.indexOf(r.tab)-rt.indexOf(n.tab)),"xt"),Nt=c(()=>{let t=(0,_.c)(19),e=Te(),r=xt(),n=$(),s;t[0]===Symbol.for("react.memo_cache_sentinel")?(s=[],t[0]=s):s=t[0];let[l,i]=(0,B.useState)(s),o,d;if(t[1]!==e||t[2]!==r.kv||t[3]!==r.storage||t[4]!==r.vectors||t[5]!==n?(o=c(()=>{let g={cancelled:!1},x=[{enabled:r.kv,label:n("KV Namespaces"),load:c(async()=>(await e.listKvNamespaces()).map(wt),"load"),tab:"kv",testId:"home-binding-kv"},{enabled:r.storage,label:n("R2 Buckets"),load:c(()=>e.listStorageBuckets(),"load"),tab:"files",testId:"home-binding-r2"},{enabled:r.vectors,label:n("Vectorize Indexes"),load:c(async()=>(await e.listVectorIndexes()).map(kt),"load"),tab:"vectors",testId:"home-binding-vectors"}];for(let b of x)b.enabled&&Ne((async()=>{try{let v=await b.load();if(!g.cancelled){let w={bindings:v,label:b.label,tab:b.tab,testId:b.testId};i(k=>vt(k,w))}}catch{}})());return()=>{g.cancelled=!0}},"o"),d=[e,r.kv,r.storage,r.vectors,n],t[1]=e,t[2]=r.kv,t[3]=r.storage,t[4]=r.vectors,t[5]=n,t[6]=o,t[7]=d):(o=t[6],d=t[7]),(0,B.useEffect)(o,d),l.length===0)return null;let u;t[8]!==n?(u=n("Bindings"),t[8]=n,t[9]=u):u=t[9];let p;t[10]!==u?(p=(0,a.jsx)("h2",{className:"text-sm font-semibold tracking-tight text-foreground",children:u}),t[10]=u,t[11]=p):p=t[11];let m;t[12]!==l?(m=l.map(St),t[12]=l,t[13]=m):m=t[13];let f;t[14]!==m?(f=(0,a.jsx)("div",{className:"grid gap-3 sm:grid-cols-2 lg:grid-cols-3",children:m}),t[14]=m,t[15]=f):f=t[15];let h;return t[16]!==p||t[17]!==f?(h=(0,a.jsxs)("section",{className:"flex flex-col gap-3","data-testid":"home-bindings",children:[p,f]}),t[16]=p,t[17]=f,t[18]=h):h=t[18],h},"bt");function _t(t){return(0,a.jsx)(We,{variant:"secondary",children:t},t)}c(_t,"yt");function wt(t){return t.binding}c(wt,"vt");function kt(t){return t.name}c(kt,"Nt");function St(t){return(0,a.jsx)(yt,{group:t},t.tab)}c(St,"_t");var Mt=[{name:"lunora_list_functions",summary:"list every query, mutation, and action with its path"},{name:"lunora_list_tables",summary:"list the schema's tables"},{name:"lunora_get_function_schema",summary:"read a function's argument JSON Schema before calling it"},{name:"lunora_run_query",summary:"run a read-only query"},{name:"lunora_run_mutation",summary:"run a mutation \u2014 writes; only when LUNORA_MCP_ALLOW_WRITES is set"},{name:"lunora_run_action",summary:"run an action \u2014 writes/effects; only when LUNORA_MCP_ALLOW_WRITES is set"}],At=c(t=>JSON.stringify({mcpServers:{lunora:{args:["-y","@lunora/mcp"],command:"npx",env:{LUNORA_ADMIN_TOKEN:"<your-admin-token>",LUNORA_URL:t}}}},null,2),"wt"),Ct=c(t=>{let e=Mt.map(r=>`- ${r.name} \u2014 ${r.summary}`).join(`
1
+ import{a as at}from"./chunk-DBVJ5VLI.js";import{i as Ee}from"./chunk-LUHXNZI4.js";import{a as Fe}from"./chunk-2O6KKVH2.js";import{b as We}from"./chunk-6I42AM75.js";import{a as D}from"./chunk-6UTZXEW3.js";import{c as _e}from"./chunk-W37HRJGQ.js";import{p as Te}from"./chunk-SDSQIQJG.js";import{a as Ze}from"./chunk-3Y5K3IQO.js";import{a as j,e as Ue}from"./chunk-MD67S53Z.js";import{b as Ve,f as $,h as Qe,i as Xe,o as et,s as Ne,u as tt,v as nt}from"./chunk-LPINY2IJ.js";import{a as c,d as ze,e as dt,f as mt,g as ut}from"./chunk-OXFKZ4BM.js";var _=ze(mt(),1);var B=ze(dt(),1);var a=ze(ut(),1);var pt=Qe(D.studioFeatures),Ge={analytics:!0,auth:!0,containers:!0,flags:!0,kv:!0,mail:!0,notifications:!0,payments:!0,privacy:!0,queues:!0,scheduler:!0,storage:!0,vectors:!0,workflows:!0},ft=c(t=>{if(t===null||typeof t!="object")return;let{id:e,name:r,unsupported:n}=t;if(!(typeof e!="string"||typeof r!="string"||!Array.isArray(n)))return{id:e,name:r,unsupported:n.filter(s=>typeof s=="string")}},"ut"),ht=c(t=>{if(t===null||typeof t!="object")return Ge;let e=t,r=c(n=>typeof e[n]=="boolean"?e[n]:!0,"n");return{analytics:r("analytics"),auth:r("auth"),containers:r("containers"),flags:r("flags"),kv:r("kv"),mail:r("mail"),notifications:r("notifications"),payments:r("payments"),privacy:r("privacy"),platform:ft(e.platform),queues:r("queues"),scheduler:r("scheduler"),storage:r("storage"),vectors:r("vectors"),workflows:r("workflows")}},"mt"),gt={...Ge,settled:!1},xt=c(()=>{let t=(0,_.c)(3),e=Te(),[r,n]=(0,B.useState)(void 0),s,l;return t[0]!==e?(s=c(()=>{let i=new AbortController;return Ne((async()=>{let o;try{o={...ht(await e.query(pt,{},Xe(""))),settled:!0}}catch{o={...Ge,settled:!0}}i.signal.aborted||n({client:e,features:o})})()),()=>{i.abort()}},"l"),l=[e],t[0]=e,t[1]=s,t[2]=l):(s=t[1],l=t[2]),(0,B.useEffect)(s,l),r?.client===e?r.features:gt},"pt"),bt=c(()=>{let t=(0,_.c)(1),e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=(0,a.jsx)("svg",{"aria-hidden":"true",className:"size-4 text-muted-foreground",fill:"none",stroke:"currentColor",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,a.jsx)("path",{d:"m9 6 6 6-6 6",strokeLinecap:"round",strokeLinejoin:"round"})}),t[0]=e):e=t[0],e},"ht"),yt=c(t=>{let e=(0,_.c)(24),{group:r}=t,n=$(),s=Ee(),l;e[0]!==r.tab||e[1]!==s?(l=c(()=>{Ne(s({to:`/${r.tab}`}))},"r"),e[0]=r.tab,e[1]=s,e[2]=l):l=e[2];let i=l,o=r.bindings.length,d;e[3]!==r.label?(d=(0,a.jsx)("span",{className:"text-sm font-medium text-foreground",children:r.label}),e[3]=r.label,e[4]=d):d=e[4];let u;e[5]===Symbol.for("react.memo_cache_sentinel")?(u=(0,a.jsx)(bt,{}),e[5]=u):u=e[5];let p;e[6]!==d?(p=(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[d,u]}),e[6]=d,e[7]=p):p=e[7];let m;e[8]!==o||e[9]!==n?(m=o===1?n("1 binding"):n("{count} bindings",{count:o}),e[8]=o,e[9]=n,e[10]=m):m=e[10];let f;e[11]!==m?(f=(0,a.jsx)("span",{className:"text-xs text-muted-foreground",children:m}),e[11]=m,e[12]=f):f=e[12];let h;e[13]!==o||e[14]!==r.bindings?(h=o>0&&(0,a.jsx)("div",{className:"flex flex-wrap gap-1.5",children:r.bindings.map(_t)}),e[13]=o,e[14]=r.bindings,e[15]=h):h=e[15];let g;e[16]!==p||e[17]!==f||e[18]!==h?(g=(0,a.jsxs)(Ue,{className:"flex flex-col gap-2 py-4",children:[p,f,h]}),e[16]=p,e[17]=f,e[18]=h,e[19]=g):g=e[19];let x;return e[20]!==r.testId||e[21]!==i||e[22]!==g?(x=(0,a.jsx)(j,{className:"cursor-pointer gap-0 py-0 transition-colors hover:bg-muted/40","data-testid":r.testId,onClick:i,children:g}),e[20]=r.testId,e[21]=i,e[22]=g,e[23]=x):x=e[23],x},"gt"),rt=["kv","files","vectors"],vt=c((t,e)=>[...t.filter(r=>r.tab!==e.tab),e].toSorted((r,n)=>rt.indexOf(r.tab)-rt.indexOf(n.tab)),"xt"),Nt=c(()=>{let t=(0,_.c)(19),e=Te(),r=xt(),n=$(),s;t[0]===Symbol.for("react.memo_cache_sentinel")?(s=[],t[0]=s):s=t[0];let[l,i]=(0,B.useState)(s),o,d;if(t[1]!==e||t[2]!==r.kv||t[3]!==r.storage||t[4]!==r.vectors||t[5]!==n?(o=c(()=>{let g={cancelled:!1},x=[{enabled:r.kv,label:n("KV Namespaces"),load:c(async()=>(await e.listKvNamespaces()).map(wt),"load"),tab:"kv",testId:"home-binding-kv"},{enabled:r.storage,label:n("R2 Buckets"),load:c(()=>e.listStorageBuckets(),"load"),tab:"files",testId:"home-binding-r2"},{enabled:r.vectors,label:n("Vectorize Indexes"),load:c(async()=>(await e.listVectorIndexes()).map(kt),"load"),tab:"vectors",testId:"home-binding-vectors"}];for(let b of x)b.enabled&&Ne((async()=>{try{let v=await b.load();if(!g.cancelled){let w={bindings:v,label:b.label,tab:b.tab,testId:b.testId};i(k=>vt(k,w))}}catch{}})());return()=>{g.cancelled=!0}},"o"),d=[e,r.kv,r.storage,r.vectors,n],t[1]=e,t[2]=r.kv,t[3]=r.storage,t[4]=r.vectors,t[5]=n,t[6]=o,t[7]=d):(o=t[6],d=t[7]),(0,B.useEffect)(o,d),l.length===0)return null;let u;t[8]!==n?(u=n("Bindings"),t[8]=n,t[9]=u):u=t[9];let p;t[10]!==u?(p=(0,a.jsx)("h2",{className:"text-sm font-semibold tracking-tight text-foreground",children:u}),t[10]=u,t[11]=p):p=t[11];let m;t[12]!==l?(m=l.map(St),t[12]=l,t[13]=m):m=t[13];let f;t[14]!==m?(f=(0,a.jsx)("div",{className:"grid gap-3 sm:grid-cols-2 lg:grid-cols-3",children:m}),t[14]=m,t[15]=f):f=t[15];let h;return t[16]!==p||t[17]!==f?(h=(0,a.jsxs)("section",{className:"flex flex-col gap-3","data-testid":"home-bindings",children:[p,f]}),t[16]=p,t[17]=f,t[18]=h):h=t[18],h},"bt");function _t(t){return(0,a.jsx)(We,{variant:"secondary",children:t},t)}c(_t,"yt");function wt(t){return t.binding}c(wt,"vt");function kt(t){return t.name}c(kt,"Nt");function St(t){return(0,a.jsx)(yt,{group:t},t.tab)}c(St,"_t");var Mt=[{name:"lunora_list_functions",summary:"list every query, mutation, and action with its path"},{name:"lunora_list_tables",summary:"list the schema's tables"},{name:"lunora_get_function_schema",summary:"read a function's argument JSON Schema before calling it"},{name:"lunora_run_query",summary:"run a read-only query"},{name:"lunora_run_mutation",summary:"run a mutation \u2014 writes; only when LUNORA_MCP_ALLOW_WRITES is set"},{name:"lunora_run_action",summary:"run an action \u2014 writes/effects; only when LUNORA_MCP_ALLOW_WRITES is set"}],At=c(t=>JSON.stringify({mcpServers:{lunora:{args:["-y","@lunora/mcp"],command:"npx",env:{LUNORA_ADMIN_TOKEN:"<your-admin-token>",LUNORA_URL:t}}}},null,2),"wt"),Ct=c(t=>{let e=Mt.map(r=>`- ${r.name} \u2014 ${r.summary}`).join(`
2
2
  `);return[`You have a Lunora MCP server connected to the deployment at ${t}.`,"It exposes this backend's functions and schema so you can inspect and operate it:",e,"",`Start by calling lunora_list_functions and lunora_list_tables to learn what exists, then lunora_get_function_schema before any run call. The full HTTP API is also documented at ${t}/_lunora/admin/openapi (that endpoint needs the same admin token the MCP server is configured with).`].join(`
3
3
  `)},"kt"),It=1500,Lt=c(()=>{let t=(0,_.c)(40),e=$(),{url:r}=Te(),n;t[0]!==r?(n=tt(r),t[0]=r,t[1]=n):n=t[1];let s=n,[l,i]=(0,B.useState)(null),o,d;t[2]!==l?(o=c(()=>{if(l===null)return;let L=globalThis.setTimeout(()=>{i(null)},It);return()=>{globalThis.clearTimeout(L)}},"o"),d=[l],t[2]=l,t[3]=o,t[4]=d):(o=t[3],d=t[4]),(0,B.useEffect)(o,d);let u;t[5]===Symbol.for("react.memo_cache_sentinel")?(u=c((L,T)=>{nt(T)&&i(L)},"u"),t[5]=u):u=t[5];let p=u,m;t[6]!==s?(m=c(()=>{p("config",At(s))},"d"),t[6]=s,t[7]=m):m=t[7];let f=m,h;t[8]!==s?(h=c(()=>{p("prompt",Ct(s))},"p"),t[8]=s,t[9]=h):h=t[9];let g=h,x;t[10]!==e?(x=e("Connect an AI agent"),t[10]=e,t[11]=x):x=t[11];let b;t[12]!==x?(b=(0,a.jsx)("span",{className:"text-sm font-medium text-foreground",children:x}),t[12]=x,t[13]=b):b=t[13];let v;t[14]!==e?(v=e("Drive this deployment from an AI agent over the Model Context Protocol \u2014 it can list functions and tables, read schemas, and run read-only queries. Writes stay off unless you opt in."),t[14]=e,t[15]=v):v=t[15];let w;t[16]!==v?(w=(0,a.jsx)("span",{className:"text-xs text-muted-foreground",children:v}),t[16]=v,t[17]=w):w=t[17];let k;t[18]!==b||t[19]!==w?(k=(0,a.jsxs)("div",{className:"flex flex-col gap-1.5 p-4",children:[b,w]}),t[18]=b,t[19]=w,t[20]=k):k=t[20];let I;t[21]===Symbol.for("react.memo_cache_sentinel")?(I=(0,a.jsx)("code",{className:"font-mono text-xs text-muted-foreground","data-testid":"home-connect-agent-command",children:"npx -y @lunora/mcp"}),t[21]=I):I=t[21];let y;t[22]!==l||t[23]!==e?(y=e(l==="config"?"Copied":"Copy MCP config"),t[22]=l,t[23]=e,t[24]=y):y=t[24];let S;t[25]!==f||t[26]!==y?(S=(0,a.jsx)(Fe,{"data-testid":"home-connect-agent-copy-config",onClick:f,size:"xs",variant:"outline",children:y}),t[25]=f,t[26]=y,t[27]=S):S=t[27];let M;t[28]!==l||t[29]!==e?(M=e(l==="prompt"?"Copied":"Copy agent prompt"),t[28]=l,t[29]=e,t[30]=M):M=t[30];let A;t[31]!==g||t[32]!==M?(A=(0,a.jsx)(Fe,{"data-testid":"home-connect-agent-copy-prompt",onClick:g,size:"xs",variant:"outline",children:M}),t[31]=g,t[32]=M,t[33]=A):A=t[33];let N;t[34]!==S||t[35]!==A?(N=(0,a.jsxs)("div",{className:"flex flex-col gap-3 border-t border-border bg-muted/50 px-4 py-3",children:[I,(0,a.jsxs)("div",{className:"flex flex-wrap gap-2",children:[S,A]})]}),t[34]=S,t[35]=A,t[36]=N):N=t[36];let C;return t[37]!==k||t[38]!==N?(C=(0,a.jsxs)(j,{className:"gap-0 py-0","data-testid":"home-connect-agent",children:[k,N]}),t[37]=k,t[38]=N,t[39]=C):C=t[39],C},"At"),$t=112,st=32,Oe=5,lt=1,jt=3,Tt=c(t=>{let e=t.slice(-16),r=Math.max(0,...e),n=st-Oe*2,s=($t-Oe*2)/e.length;return e.map((l,i)=>{let o=r>0?Math.max(0,l)/r*n:0;return{height:Math.max(0,o-jt),width:Math.max(0,s-lt*2),x:Oe+i*s+lt,y:st-Oe-o}})},"It"),Ot=c(t=>{let e=(0,_.c)(4),{data:r}=t,n;e[0]!==r?(n=Tt(r).map(qt),e[0]=r,e[1]=n):n=e[1];let s;return e[2]!==n?(s=(0,a.jsx)("svg",{"aria-hidden":"true",className:"h-8 w-28 fill-foreground","data-testid":"home-sparkline",viewBox:"0 0 112 32",children:n}),e[2]=n,e[3]=s):s=e[3],s},"Tt");function qt(t){return(0,a.jsx)("rect",{height:t.height,rx:2,width:t.width,x:t.x,y:t.y},t.x)}c(qt,"Lt");var Rt=3,Kt=c((t,e)=>{if(e==null)return t("cache not enabled");let r=e.hits+e.misses;return r===0?t("no cache traffic yet"):`${Math.round(e.hits/r*100).toString()}% ${t("cache hit")}`},"Rt"),Je=c(t=>{if(t<1e3)return`${String(Math.round(t))}ms`;let e=t>=1e4?0:1;return`${(t/1e3).toFixed(e)}s`},"Fe"),Bt=c((t,e)=>{let r=Math.max(0,Math.round((e-t)/1e3));if(r<60)return`${String(r)}s ago`;let n=Math.round(r/60);if(n<60)return`${String(n)}m ago`;let s=Math.round(n/60);return s<24?`${String(s)}h ago`:`${String(Math.round(s/24))}d ago`},"Et"),ot=c((t,e)=>{if(t===void 0||t.length===0)return[];let r=new Map;for(let n of t)r.set(n.bucketMs,(r.get(n.bucketMs)??0)+n[e]);return[...r.entries()].toSorted(([n],[s])=>n-s).map(([,n])=>n)},"Je"),it=c((t,e=!0)=>{if(t.length<4)return null;let r=Math.floor(t.length/2),n=t.slice(0,r).reduce((i,o)=>i+o,0),s=t.slice(r).reduce((i,o)=>i+o,0);if(n===0)return null;let l=(s-n)/n*100;return{positive:e?l>=0:l<=0,text:`${l>=0?"+":""}${l.toFixed(1)}%`}},"Ye"),qe=c(t=>{let e=(0,_.c)(24),{delta:r,footer:n,label:s,trend:l,unit:i,value:o}=t,d=$(),u;e[0]!==s?(u=(0,a.jsx)("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:s}),e[0]=s,e[1]=u):u=e[1];let p;e[2]!==o?(p=(0,a.jsx)("span",{className:"text-2xl font-semibold tabular-nums text-foreground",children:o}),e[2]=o,e[3]=p):p=e[3];let m;e[4]!==i?(m=i!==void 0&&(0,a.jsx)("span",{className:"text-xs text-muted-foreground",children:i}),e[4]=i,e[5]=m):m=e[5];let f;e[6]!==p||e[7]!==m?(f=(0,a.jsxs)("span",{className:"flex items-baseline gap-1.5",children:[p,m]}),e[6]=p,e[7]=m,e[8]=f):f=e[8];let h;e[9]!==l?(h=l!==void 0&&l.length>=Rt&&(0,a.jsx)(Ot,{data:l}),e[9]=l,e[10]=h):h=e[10];let g;e[11]!==f||e[12]!==h?(g=(0,a.jsxs)("div",{className:"flex items-center justify-between gap-3",children:[f,h]}),e[11]=f,e[12]=h,e[13]=g):g=e[13];let x;e[14]!==u||e[15]!==g?(x=(0,a.jsxs)("div",{className:"flex flex-col gap-2.5 p-4",children:[u,g]}),e[14]=u,e[15]=g,e[16]=x):x=e[16];let b;e[17]!==r||e[18]!==n||e[19]!==d?(b=r==null?n!=null&&(0,a.jsx)("div",{className:"border-t border-border bg-muted/50 px-4 py-2.5 text-[11px] text-muted-foreground",children:n}):(0,a.jsxs)("div",{className:"border-t border-border bg-muted/50 px-4 py-2.5 text-[11px]",children:[(0,a.jsx)("span",{className:Ve("font-semibold",r.positive?"text-success":"text-destructive"),children:r.text})," ",(0,a.jsx)("span",{className:"text-muted-foreground",children:d("vs. prev.")})]}),e[17]=r,e[18]=n,e[19]=d,e[20]=b):b=e[20];let v;return e[21]!==x||e[22]!==b?(v=(0,a.jsxs)(j,{className:"justify-between gap-0 py-0",children:[x,b]}),e[21]=x,e[22]=b,e[23]=v):v=e[23],v},"Oe"),Dt=c(()=>{let t=(0,_.c)(1),e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=(0,a.jsx)("svg",{"aria-hidden":"true",className:"size-3.5",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.8,viewBox:"0 0 24 24",children:(0,a.jsx)("path",{d:"m9 6 6 6-6 6"})}),t[0]=e):e=t[0],e},"Bt"),He=c(t=>{let e=(0,_.c)(7),{command:r,label:n}=t,s;e[0]!==n?(s=(0,a.jsx)("div",{className:"p-4",children:(0,a.jsx)("span",{className:"text-sm font-medium text-foreground",children:n})}),e[0]=n,e[1]=s):s=e[1];let l;e[2]!==r?(l=(0,a.jsx)("div",{className:"border-t border-border bg-muted/50 px-4 py-2.5",children:(0,a.jsx)("code",{className:"font-mono text-xs text-muted-foreground",children:r})}),e[2]=r,e[3]=l):l=e[3];let i;return e[4]!==s||e[5]!==l?(i=(0,a.jsxs)(j,{className:"justify-between gap-0 py-0",children:[s,l]}),e[4]=s,e[5]=l,e[6]=i):i=e[6],i},"je"),ct=c(t=>{let e=(0,_.c)(18),{count:r,onView:n,testId:s,title:l}=t,i=$(),o;e[0]!==l?(o=(0,a.jsx)("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:l}),e[0]=l,e[1]=o):o=e[1];let d;e[2]!==r||e[3]!==i?(d=r===null?(0,a.jsx)("span",{className:"text-xs text-muted-foreground",children:i("No data yet")}):(0,a.jsx)(We,{variant:r>0?"destructive":"success",children:r>0?r:i("All clear")}),e[2]=r,e[3]=i,e[4]=d):d=e[4];let u;e[5]!==o||e[6]!==d?(u=(0,a.jsxs)("div",{className:"flex items-start justify-between gap-2 p-4",children:[o,d]}),e[5]=o,e[6]=d,e[7]=u):u=e[7];let p;e[8]!==i?(p=i("View"),e[8]=i,e[9]=p):p=e[9];let m;e[10]===Symbol.for("react.memo_cache_sentinel")?(m=(0,a.jsx)(Dt,{}),e[10]=m):m=e[10];let f;e[11]!==n||e[12]!==p?(f=(0,a.jsxs)("button",{className:"flex items-center gap-1 border-t border-border bg-muted/50 px-4 py-2.5 text-[12px] font-medium text-foreground outline-none transition-colors hover:bg-muted focus-visible:bg-muted",onClick:n,type:"button",children:[p,m]}),e[11]=n,e[12]=p,e[13]=f):f=e[13];let h;return e[14]!==u||e[15]!==f||e[16]!==s?(h=(0,a.jsxs)(j,{className:"justify-between gap-0 py-0","data-testid":s,children:[u,f]}),e[14]=u,e[15]=f,e[16]=s,e[17]=h):h=e[17],h},"Ze"),Pt=c(t=>{let e=(0,_.c)(7),{functions:r}=t,n=$(),s;if(e[0]!==r||e[1]!==n){let l=[...r].toSorted(Wt).slice(0,5),i;e[3]!==n?(i=n("Top functions"),e[3]=n,e[4]=i):i=e[4];let o;e[5]!==i?(o=(0,a.jsx)("div",{className:"border-b border-border px-4 py-3",children:(0,a.jsx)("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:i})}),e[5]=i,e[6]=o):o=e[6],s=(0,a.jsxs)(j,{className:"gap-0 py-0","data-testid":"home-top-functions",children:[o,l.length===0?(0,a.jsx)("p",{className:"px-4 py-8 text-center text-xs text-muted-foreground",children:n("No functions called yet.")}):(0,a.jsxs)("div",{className:"divide-y divide-border",children:[(0,a.jsxs)("div",{className:"grid grid-cols-[1fr_auto_auto_auto] gap-4 px-4 py-1.5 font-mono text-[10px] tracking-wide text-muted-foreground uppercase",children:[(0,a.jsx)("span",{children:n("Function")}),(0,a.jsx)("span",{className:"text-end",children:n("Calls")}),(0,a.jsx)("span",{className:"w-12 text-end",children:n("Avg")}),(0,a.jsx)("span",{className:"w-8 text-end",children:n("Err")})]}),l.map(Ft)]})]}),e[0]=r,e[1]=n,e[2]=s}else s=e[2];return s},"Pt"),zt=c(t=>{let e=(0,_.c)(26),{subs:r}=t,n=$(),s;e[0]!==n?(s=n("Live connections"),e[0]=n,e[1]=s):s=e[1];let l;e[2]!==s?(l=(0,a.jsx)("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:s}),e[2]=s,e[3]=l):l=e[3];let i=r?.totalConnections??0,o;e[4]!==i?(o=i.toLocaleString(),e[4]=i,e[5]=o):o=e[5];let d;e[6]!==o?(d=(0,a.jsx)("span",{className:"text-2xl font-semibold tabular-nums text-foreground",children:o}),e[6]=o,e[7]=d):d=e[7];let u;e[8]!==n?(u=n("sockets"),e[8]=n,e[9]=u):u=e[9];let p;e[10]!==u?(p=(0,a.jsx)("span",{className:"text-xs text-muted-foreground",children:u}),e[10]=u,e[11]=p):p=e[11];let m;e[12]!==d||e[13]!==p?(m=(0,a.jsxs)("span",{className:"flex items-baseline gap-1.5",children:[d,p]}),e[12]=d,e[13]=p,e[14]=m):m=e[14];let f=r?.totalSubscriptions??0,h;e[15]!==f?(h=f.toLocaleString(),e[15]=f,e[16]=h):h=e[16];let g;e[17]!==n?(g=n("active subscriptions"),e[17]=n,e[18]=g):g=e[18];let x;e[19]!==h||e[20]!==g?(x=(0,a.jsxs)("span",{className:"text-[11px] text-muted-foreground",children:[h," ",g]}),e[19]=h,e[20]=g,e[21]=x):x=e[21];let b;return e[22]!==x||e[23]!==l||e[24]!==m?(b=(0,a.jsx)(j,{"data-testid":"home-live-connections",children:(0,a.jsxs)(Ue,{className:"flex flex-col gap-2.5 py-4",children:[l,m,x]})}),e[22]=x,e[23]=l,e[24]=m,e[25]=b):b=e[25],b},"Dt"),Et=c(t=>{let e=(0,_.c)(7),{entries:r}=t,n=$(),s;if(e[0]!==r||e[1]!==n){let l=Date.now(),i;e[3]!==n?(i=n("Recent activity"),e[3]=n,e[4]=i):i=e[4];let o;e[5]!==i?(o=(0,a.jsx)("div",{className:"border-b border-border px-4 py-3",children:(0,a.jsx)("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:i})}),e[5]=i,e[6]=o):o=e[6],s=(0,a.jsxs)(j,{className:"gap-0 py-0","data-testid":"home-recent-activity",children:[o,r.length===0?(0,a.jsx)("p",{className:"px-4 py-8 text-center text-xs text-muted-foreground",children:n("No recent activity.")}):(0,a.jsx)("ul",{className:"divide-y divide-border",children:r.slice(0,5).map(d=>(0,a.jsxs)("li",{className:"flex items-center justify-between gap-3 px-4 py-2 text-[13px]",children:[(0,a.jsxs)("span",{className:"flex min-w-0 items-center gap-2",children:[(0,a.jsx)("span",{"aria-hidden":"true",className:"size-1.5 shrink-0 rounded-full bg-muted-foreground/40"}),(0,a.jsxs)("span",{className:"truncate text-foreground",children:[d.op,d.table!==void 0&&(0,a.jsxs)("span",{className:"text-muted-foreground",children:[" \xB7 ",d.table,d.id===void 0?"":`#${d.id}`]})]})]}),(0,a.jsx)("span",{className:"shrink-0 text-xs tabular-nums text-muted-foreground",children:Bt(d.ts,l)})]},d.seq))})]}),e[0]=r,e[1]=n,e[2]=s}else s=e[2];return s},"jt"),Vt=c(t=>{let e=t.reduce((r,n)=>r+n.calls,0);return e===0?null:t.reduce((r,n)=>r+n.totalDurationMs,0)/e},"Ft"),sn=c(t=>{let e=(0,_.c)(149),{initialShardKey:r}=t,n=$(),s=Ee(),l=r??"",i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i={},e[0]=i):i=e[0];let o;e[1]!==l?(o={shardKey:l},e[1]=l,e[2]=o):o=e[2];let d=_e(D.getMetrics,i,o),u;e[3]===Symbol.for("react.memo_cache_sentinel")?(u={},e[3]=u):u=e[3];let p;e[4]!==l?(p={shardKey:l},e[4]=l,e[5]=p):p=e[5];let m=_e(D.getFunctionStats,u,p),f,h;e[6]===Symbol.for("react.memo_cache_sentinel")?(f={},h={shardKey:""},e[6]=f,e[7]=h):(f=e[6],h=e[7]);let g=_e(D.getSecurityAudit,f,h),x;e[8]===Symbol.for("react.memo_cache_sentinel")?(x={},e[8]=x):x=e[8];let b;e[9]!==l?(b={shardKey:l},e[9]=l,e[10]=b):b=e[10];let v=_e(D.listSubscriptions,x,b),w;e[11]===Symbol.for("react.memo_cache_sentinel")?(w={},e[11]=w):w=e[11];let k;e[12]!==l?(k={shardKey:l},e[12]=l,e[13]=k):k=e[13];let I=_e(D.getAuditLog,w,k),y=d.data??null,S,M,A,N,C,L,T,O,q,P,z,E,R,K,V,W,F,U;if(e[14]!==I.data||e[15]!==g.data||e[16]!==y||e[17]!==d.data||e[18]!==s||e[19]!==m.data||e[20]!==v.data||e[21]!==n){N=Array.isArray(m.data?.functions)?m.data.functions:[],T=v.data??null;let Me;e[40]!==I.data?(Me=Array.isArray(I.data?.entries)?I.data.entries:[],e[40]=I.data,e[41]=Me):Me=e[41],M=Me,C=d.data===void 0||m.data===void 0?null:at(y,N).length,L=Array.isArray(g.data?.findings)?g.data.findings.length:null;let Ae;e[42]!==s?(Ae=c(()=>{Ne(s({to:"/security"}))},"Ce"),e[42]=s,e[43]=Ae):Ae=e[43],U=Ae;let Ce;e[44]!==s?(Ce=c(()=>{Ne(s({to:"/insights"}))},"Ae"),e[44]=s,e[45]=Ce):Ce=e[45],F=Ce;let Ie=ot(y?.history,"calls"),Le=ot(y?.history,"errors"),Ye=Vt(N),$e=Math.max(0,...N.map(Ut)),je;e[46]!==y||e[47]!==n?(je=y===null?void 0:Kt(n,y.cache),e[46]=y,e[47]=n,e[48]=je):je=e[48],A=je,V="flex flex-col gap-6",W="lunora-home",z="grid gap-3 sm:grid-cols-2 xl:grid-cols-4",E="home-health";let Ke=it(Ie),xe;e[49]!==n?(xe=n("Requests"),e[49]=n,e[50]=xe):xe=e[50];let Be=y?.requests??0,be;e[51]!==Be?(be=Be.toLocaleString(),e[51]=Be,e[52]=be):be=e[52],e[53]!==Ie||e[54]!==Ke||e[55]!==xe||e[56]!==be?(R=(0,a.jsx)(qe,{delta:Ke,label:xe,trend:Ie,value:be}),e[53]=Ie,e[54]=Ke,e[55]=xe,e[56]=be,e[57]=R):R=e[57];let De=it(Le,!1),ye;e[58]!==n?(ye=n("Errors"),e[58]=n,e[59]=ye):ye=e[59];let Pe=y?.errors??0,ve;e[60]!==Pe?(ve=Pe.toLocaleString(),e[60]=Pe,e[61]=ve):ve=e[61],e[62]!==Le||e[63]!==De||e[64]!==ye||e[65]!==ve?(K=(0,a.jsx)(qe,{delta:De,label:ye,trend:Le,value:ve}),e[62]=Le,e[63]=De,e[64]=ye,e[65]=ve,e[66]=K):K=e[66],S=qe,e[67]!==$e||e[68]!==n?(O=$e>0?`${n("max")} ${Je($e)}`:void 0,e[67]=$e,e[68]=n,e[69]=O):O=e[69],e[70]!==n?(q=n("Avg latency"),e[70]=n,e[71]=q):q=e[71],P=Ye===null?"\u2014":Je(Ye),e[14]=I.data,e[15]=g.data,e[16]=y,e[17]=d.data,e[18]=s,e[19]=m.data,e[20]=v.data,e[21]=n,e[22]=S,e[23]=M,e[24]=A,e[25]=N,e[26]=C,e[27]=L,e[28]=T,e[29]=O,e[30]=q,e[31]=P,e[32]=z,e[33]=E,e[34]=R,e[35]=K,e[36]=V,e[37]=W,e[38]=F,e[39]=U}else S=e[22],M=e[23],A=e[24],N=e[25],C=e[26],L=e[27],T=e[28],O=e[29],q=e[30],P=e[31],z=e[32],E=e[33],R=e[34],K=e[35],V=e[36],W=e[37],F=e[38],U=e[39];let H;e[72]!==S||e[73]!==O||e[74]!==q||e[75]!==P?(H=(0,a.jsx)(S,{footer:O,label:q,value:P}),e[72]=S,e[73]=O,e[74]=q,e[75]=P,e[76]=H):H=e[76];let J;e[77]!==n?(J=n("Database size"),e[77]=n,e[78]=J):J=e[78];let Re=y?.databaseSize??null,G;e[79]!==Re?(G=et(Re),e[79]=Re,e[80]=G):G=e[80];let Y;e[81]!==A||e[82]!==J||e[83]!==G?(Y=(0,a.jsx)(qe,{footer:A,label:J,value:G}),e[81]=A,e[82]=J,e[83]=G,e[84]=Y):Y=e[84];let Z;e[85]!==z||e[86]!==E||e[87]!==R||e[88]!==K||e[89]!==H||e[90]!==Y?(Z=(0,a.jsxs)("div",{className:z,"data-testid":E,children:[R,K,H,Y]}),e[85]=z,e[86]=E,e[87]=R,e[88]=K,e[89]=H,e[90]=Y,e[91]=Z):Z=e[91];let we;e[92]===Symbol.for("react.memo_cache_sentinel")?(we=(0,a.jsx)(Nt,{}),e[92]=we):we=e[92];let Q;e[93]!==N?(Q=(0,a.jsx)("div",{className:"lg:col-span-2",children:(0,a.jsx)(Pt,{functions:N})}),e[93]=N,e[94]=Q):Q=e[94];let X;e[95]!==T?(X=(0,a.jsx)(zt,{subs:T}),e[95]=T,e[96]=X):X=e[96];let ee;e[97]!==M?(ee=(0,a.jsx)(Et,{entries:M}),e[97]=M,e[98]=ee):ee=e[98];let te;e[99]!==X||e[100]!==ee?(te=(0,a.jsxs)("div",{className:"flex flex-col gap-3",children:[X,ee]}),e[99]=X,e[100]=ee,e[101]=te):te=e[101];let ne;e[102]!==Q||e[103]!==te?(ne=(0,a.jsxs)("div",{className:"grid gap-3 lg:grid-cols-3",children:[Q,te]}),e[102]=Q,e[103]=te,e[104]=ne):ne=e[104];let ae;e[105]!==n?(ae=n("Advisors"),e[105]=n,e[106]=ae):ae=e[106];let re;e[107]!==ae?(re=(0,a.jsx)("h2",{className:"text-sm font-semibold tracking-tight text-foreground",children:ae}),e[107]=ae,e[108]=re):re=e[108];let se;e[109]!==C||e[110]!==L||e[111]!==n||e[112]!==F||e[113]!==U?(se=L===0&&C===0?(0,a.jsx)(Ze,{description:n("No security or performance issues detected."),icon:(0,a.jsxs)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:[(0,a.jsx)("path",{d:"M12 3 4 6v5c0 5 3.4 8.5 8 10 4.6-1.5 8-5 8-10V6l-8-3Z"}),(0,a.jsx)("path",{d:"m9 12 2 2 4-4"})]}),testId:"home-advisors-clear",title:n("No issues found")}):(0,a.jsxs)("div",{className:"grid gap-3 sm:grid-cols-2",children:[(0,a.jsx)(ct,{count:L,onView:U,testId:"home-security",title:n("Security findings")}),(0,a.jsx)(ct,{count:C,onView:F,testId:"home-performance",title:n("Performance issues")})]}),e[109]=C,e[110]=L,e[111]=n,e[112]=F,e[113]=U,e[114]=se):se=e[114];let le;e[115]!==re||e[116]!==se?(le=(0,a.jsxs)("section",{className:"flex flex-col gap-3","data-testid":"home-advisors",children:[re,se]}),e[115]=re,e[116]=se,e[117]=le):le=e[117];let oe;e[118]!==n?(oe=n("Get connected"),e[118]=n,e[119]=oe):oe=e[119];let ie;e[120]!==oe?(ie=(0,a.jsx)("h2",{className:"text-sm font-semibold tracking-tight text-foreground",children:oe}),e[120]=oe,e[121]=ie):ie=e[121];let ce;e[122]!==n?(ce=n("Client SDK"),e[122]=n,e[123]=ce):ce=e[123];let de;e[124]!==ce?(de=(0,a.jsx)(He,{command:"npm i @lunora/client",label:ce}),e[124]=ce,e[125]=de):de=e[125];let me;e[126]!==n?(me=n("React"),e[126]=n,e[127]=me):me=e[127];let ue;e[128]!==me?(ue=(0,a.jsx)(He,{command:"npm i @lunora/react",label:me}),e[128]=me,e[129]=ue):ue=e[129];let pe;e[130]!==n?(pe=n("CLI"),e[130]=n,e[131]=pe):pe=e[131];let fe;e[132]!==pe?(fe=(0,a.jsx)(He,{command:"lunora dev",label:pe}),e[132]=pe,e[133]=fe):fe=e[133];let he;e[134]!==de||e[135]!==ue||e[136]!==fe?(he=(0,a.jsxs)("div",{className:"grid gap-3 sm:grid-cols-3",children:[de,ue,fe]}),e[134]=de,e[135]=ue,e[136]=fe,e[137]=he):he=e[137];let ke;e[138]===Symbol.for("react.memo_cache_sentinel")?(ke=(0,a.jsx)(Lt,{}),e[138]=ke):ke=e[138];let ge;e[139]!==ie||e[140]!==he?(ge=(0,a.jsxs)("section",{className:"flex flex-col gap-3","data-testid":"home-get-connected",children:[ie,he,ke]}),e[139]=ie,e[140]=he,e[141]=ge):ge=e[141];let Se;return e[142]!==V||e[143]!==W||e[144]!==Z||e[145]!==ne||e[146]!==le||e[147]!==ge?(Se=(0,a.jsxs)("div",{className:V,"data-testid":W,children:[Z,we,ne,le,ge]}),e[142]=V,e[143]=W,e[144]=Z,e[145]=ne,e[146]=le,e[147]=ge,e[148]=Se):Se=e[148],Se},"as");function Wt(t,e){return e.calls-t.calls}c(Wt,"Ut");function Ft(t){return(0,a.jsxs)("div",{className:"grid grid-cols-[1fr_auto_auto_auto] items-center gap-4 px-4 py-2 text-[13px]",children:[(0,a.jsx)("span",{className:"truncate font-mono text-xs text-foreground",children:t.path}),(0,a.jsx)("span",{className:"text-end tabular-nums",children:t.calls.toLocaleString()}),(0,a.jsx)("span",{className:"w-12 text-end tabular-nums text-muted-foreground",children:Je(t.calls>0?t.totalDurationMs/t.calls:0)}),(0,a.jsx)("span",{className:Ve("w-8 text-end tabular-nums",t.errors>0?"text-destructive":"text-muted-foreground"),children:t.errors})]},t.path)}c(Ft,"qt");function Ut(t){return t.maxDurationMs}c(Ut,"Kt");export{xt as a,sn as b};
@@ -1 +1 @@
1
- import{a as s}from"./chunk-4SJDWMH3.js";import{a as n}from"./chunk-OXFKZ4BM.js";var b="__lunora_admin__:",g=new Set(["action","mutation","query"]),c=Symbol("lunora.operationSeq"),_=n(t=>{if(typeof t!="object"||t===null)return;let e=t[c];return typeof e=="number"?e:void 0},"g"),d=n((t,e)=>{if(!(typeof t!="object"||t===null||!Object.isExtensible(t)))try{Object.defineProperty(t,c,{configurable:!0,enumerable:!1,value:e,writable:!0})}catch{}},"h"),m=n(t=>{if(typeof t!="object"||t===null)return;let e=t.__lunoraRef;return typeof e=="string"&&e.startsWith(b)?e:void 0},"p"),h=n(t=>{if(typeof t!="object"||t===null)return"";let{shardKey:e}=t;return typeof e=="string"?e:""},"O"),w=n(t=>new Proxy(t,{get(e,u,y){let i=Reflect.get(e,u,y);if(typeof i!="function"||typeof u!="string"||!g.has(u))return typeof i=="function"?i.bind(e):i;let f=i;return async(...o)=>{let l=m(o[0]);if(l===void 0)return f.apply(e,o);let p=typeof o[1]=="object"&&o[1]!==null?o[1]:{},a=s.start(l,p,h(o[2]));try{let r=await f.apply(e,o);return s.settle(a,{result:r}),r}catch(r){throw s.settle(a,{error:r instanceof Error?r.message:String(r)}),d(r,a),r}}}}),"E");export{_ as a,w as b};
1
+ import{a as s}from"./chunk-W37HRJGQ.js";import{a as n}from"./chunk-OXFKZ4BM.js";var b="__lunora_admin__:",g=new Set(["action","mutation","query"]),c=Symbol("lunora.operationSeq"),_=n(t=>{if(typeof t!="object"||t===null)return;let e=t[c];return typeof e=="number"?e:void 0},"g"),d=n((t,e)=>{if(!(typeof t!="object"||t===null||!Object.isExtensible(t)))try{Object.defineProperty(t,c,{configurable:!0,enumerable:!1,value:e,writable:!0})}catch{}},"h"),m=n(t=>{if(typeof t!="object"||t===null)return;let e=t.__lunoraRef;return typeof e=="string"&&e.startsWith(b)?e:void 0},"p"),h=n(t=>{if(typeof t!="object"||t===null)return"";let{shardKey:e}=t;return typeof e=="string"?e:""},"O"),w=n(t=>new Proxy(t,{get(e,u,y){let i=Reflect.get(e,u,y);if(typeof i!="function"||typeof u!="string"||!g.has(u))return typeof i=="function"?i.bind(e):i;let f=i;return async(...o)=>{let l=m(o[0]);if(l===void 0)return f.apply(e,o);let p=typeof o[1]=="object"&&o[1]!==null?o[1]:{},a=s.start(l,p,h(o[2]));try{let r=await f.apply(e,o);return s.settle(a,{result:r}),r}catch(r){throw s.settle(a,{error:r instanceof Error?r.message:String(r)}),d(r,a),r}}}}),"E");export{_ as a,w as b};
@@ -1 +1 @@
1
- import{i as A}from"./chunk-SDQH4HR6.js";import"./chunk-W7MRISE3.js";import"./chunk-IBJVVHV5.js";import{a as D}from"./chunk-2O6KKVH2.js";import"./chunk-JTGGWF7R.js";import"./chunk-ZBON5T5A.js";import"./chunk-4C4THJUD.js";import{p as J}from"./chunk-FKM35PXF.js";import"./chunk-WZTY3ZYI.js";import{a as G}from"./chunk-3Y5K3IQO.js";import{a as Q,b as W,c as Z,d as V,e as C,f as S}from"./chunk-CW57Q264.js";import{a as $,e as z}from"./chunk-MD67S53Z.js";import{f as B,j as F,r as H,s as K}from"./chunk-LPINY2IJ.js";import{a as I,d as M,e as U,f as X,g as Y}from"./chunk-OXFKZ4BM.js";var L=M(X(),1),g=M(U(),1);var t=M(Y(),1);var _=10,E=I(h=>{let e=(0,L.c)(7),{label:i,value:l}=h,r;e[0]!==i?(r=(0,t.jsx)("span",{className:"font-mono text-[11px] uppercase tracking-wide text-muted-foreground",children:i}),e[0]=i,e[1]=r):r=e[1];let a=l??"\u2014",n;e[2]!==a?(n=(0,t.jsx)("span",{className:"font-mono text-sm",children:a}),e[2]=a,e[3]=n):n=e[3];let s;return e[4]!==r||e[5]!==n?(s=(0,t.jsxs)("div",{className:"flex flex-col gap-0.5",children:[r,n]}),e[4]=r,e[5]=n,e[6]=s):s=e[6],s},"_"),ee=I(h=>{let e=(0,L.c)(38),{indexes:i,onSelect:l,selected:r}=h,a=B(),n;e[0]!==a?(n=a("name"),e[0]=a,e[1]=n):n=e[1];let s;e[2]!==n?(s=(0,t.jsx)(C,{children:n}),e[2]=n,e[3]=s):s=e[3];let c;e[4]!==a?(c=a("table"),e[4]=a,e[5]=c):c=e[5];let o;e[6]!==c?(o=(0,t.jsx)(C,{children:c}),e[6]=c,e[7]=o):o=e[7];let d;e[8]!==a?(d=a("dimensions"),e[8]=a,e[9]=d):d=e[9];let x;e[10]!==d?(x=(0,t.jsx)(C,{children:d}),e[10]=d,e[11]=x):x=e[11];let m;e[12]!==a?(m=a("metric"),e[12]=a,e[13]=m):m=e[13];let p;e[14]!==m?(p=(0,t.jsx)(C,{children:m}),e[14]=m,e[15]=p):p=e[15];let u;e[16]!==a?(u=a("vectors"),e[16]=a,e[17]=u):u=e[17];let v;e[18]!==u?(v=(0,t.jsx)(C,{children:u}),e[18]=u,e[19]=v):v=e[19];let y;e[20]!==v||e[21]!==s||e[22]!==o||e[23]!==x||e[24]!==p?(y=(0,t.jsx)(W,{children:(0,t.jsxs)(V,{children:[s,o,x,p,v]})}),e[20]=v,e[21]=s,e[22]=o,e[23]=x,e[24]=p,e[25]=y):y=e[25];let k;if(e[26]!==i||e[27]!==l||e[28]!==r){let q;e[30]!==l||e[31]!==r?(q=I(w=>(0,t.jsxs)(V,{className:w.name===r?"border-l-2 border-l-royal-amethyst bg-muted/50":"cursor-pointer","data-index":w.name,"data-testid":`vector-row-${w.name}`,onClick:l,children:[(0,t.jsx)(S,{className:"font-mono text-xs",children:w.name}),(0,t.jsx)(S,{className:"font-mono text-xs",children:w.table}),(0,t.jsx)(S,{className:"tabular-nums",children:w.dimensions??"\u2014"}),(0,t.jsx)(S,{children:w.metric??"\u2014"}),(0,t.jsx)(S,{className:"tabular-nums",children:w.vectorsCount??"\u2014"})]},w.name),"q"),e[30]=l,e[31]=r,e[32]=q):q=e[32],k=i.map(q),e[26]=i,e[27]=l,e[28]=r,e[29]=k}else k=e[29];let N;e[33]!==k?(N=(0,t.jsx)(Z,{children:k}),e[33]=k,e[34]=N):N=e[34];let f;return e[35]!==y||e[36]!==N?(f=(0,t.jsx)($,{className:"overflow-hidden py-0",children:(0,t.jsx)(z,{className:"px-0",children:(0,t.jsxs)(Q,{"data-testid":"vector-table",children:[y,N]})})}),e[35]=y,e[36]=N,e[37]=f):f=e[37],f},"X"),te=I(h=>{let e=(0,L.c)(27),{matches:i}=h,l=B();if(i.length===0){let u;e[0]!==l?(u=l("No matches."),e[0]=l,e[1]=u):u=e[1];let v;return e[2]!==u?(v=(0,t.jsx)("p",{className:"mt-2 text-sm text-muted-foreground","data-testid":"vector-no-matches",children:u}),e[2]=u,e[3]=v):v=e[3],v}let r;e[4]!==l?(r=l("id"),e[4]=l,e[5]=r):r=e[5];let a;e[6]!==r?(a=(0,t.jsx)(C,{children:r}),e[6]=r,e[7]=a):a=e[7];let n;e[8]!==l?(n=l("score"),e[8]=l,e[9]=n):n=e[9];let s;e[10]!==n?(s=(0,t.jsx)(C,{children:n}),e[10]=n,e[11]=s):s=e[11];let c;e[12]!==l?(c=l("metadata"),e[12]=l,e[13]=c):c=e[13];let o;e[14]!==c?(o=(0,t.jsx)(C,{children:c}),e[14]=c,e[15]=o):o=e[15];let d;e[16]!==a||e[17]!==s||e[18]!==o?(d=(0,t.jsx)(W,{children:(0,t.jsxs)(V,{children:[a,s,o]})}),e[16]=a,e[17]=s,e[18]=o,e[19]=d):d=e[19];let x;e[20]!==i?(x=i.map(le),e[20]=i,e[21]=x):x=e[21];let m;e[22]!==x?(m=(0,t.jsx)(Z,{children:x}),e[22]=x,e[23]=m):m=e[23];let p;return e[24]!==d||e[25]!==m?(p=(0,t.jsx)($,{className:"mt-3 overflow-hidden py-0",children:(0,t.jsx)(z,{className:"px-0",children:(0,t.jsxs)(Q,{"data-testid":"vector-matches",children:[d,m]})})}),e[24]=d,e[25]=m,e[26]=p):p=e[26],p},"Y"),me=I(({loadIndexes:h,runQuery:e}={})=>{let i=J(),l=B(),[r,a]=(0,g.useState)(null),[n,s]=(0,g.useState)(null),[c,o]=(0,g.useState)(null),[d,x]=(0,g.useState)(""),[m,p]=(0,g.useState)(null),[u,v]=(0,g.useState)(null),[y,k]=(0,g.useState)(!1),N=(0,g.useRef)(0);(0,g.useEffect)(()=>{let b={cancelled:!1};return K((async()=>{try{let j=await(h??(()=>i.listVectorIndexes()))();b.cancelled||(a(j),s(null),o(T=>T??j[0]?.name??null))}catch(j){b.cancelled||(a(null),s(F(j)))}})()),()=>{b.cancelled=!0}},[i,h]);let f=r?.find(b=>b.name===c)??null,q=I(b=>{N.current+=1,o(b.currentTarget.dataset.index??null),p(null),v(null),k(!1)},"q"),w=I(b=>{x(b.target.value)},"y"),O=I(async()=>{let b=d.trim();if(c===null||b==="")return;N.current+=1;let j=N.current;k(!0),v(null);try{let T=await(e??(R=>i.queryVectorIndex(R)))({name:c,text:b,topK:_});if(j!==N.current)return;p(T)}catch(T){if(j!==N.current)return;p(null),v(F(T))}k(!1)},"H"),P=I(()=>{K(O())},"K");return(0,t.jsxs)("div",{className:"flex flex-col gap-4","data-testid":"lunora-vector-browser",children:[n!==null&&(0,t.jsx)("p",{className:"text-sm text-destructive","data-testid":"vector-error",role:"alert",children:n}),r!==null&&r.length===0&&(0,t.jsx)(G,{description:l("Indexes declared with .vectorize() or defineVectorIndex() appear here."),icon:(0,t.jsx)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,t.jsx)("path",{d:"M4 7l8-4 8 4-8 4-8-4Zm0 5 8 4 8-4M4 17l8 4 8-4"})}),testId:"vector-empty",title:l("No vector indexes.")}),r!==null&&r.length>0&&(0,t.jsx)(ee,{indexes:r,onSelect:q,selected:c}),f!==null&&(0,t.jsxs)("section",{className:"border border-border bg-card p-3","data-testid":"vector-detail",children:[(0,t.jsxs)("div",{className:"grid grid-cols-2 gap-3 sm:grid-cols-4",children:[(0,t.jsx)(E,{label:l("field"),value:f.field}),(0,t.jsx)(E,{label:l("dimensions"),value:f.dimensions}),(0,t.jsx)(E,{label:l("metric"),value:f.metric}),(0,t.jsx)(E,{label:l("vectors"),value:f.vectorsCount})]}),f.metadata!==void 0&&f.metadata.length>0&&(0,t.jsxs)("p",{className:"mt-3 text-xs text-muted-foreground","data-testid":"vector-metadata",children:[l("metadata"),": ",(0,t.jsx)("span",{className:"font-mono",children:f.metadata.join(", ")})]}),(0,t.jsxs)("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[(0,t.jsx)(A,{className:"min-w-[18rem] flex-1","data-testid":"vector-query-input",onChange:w,placeholder:l("Search by similarity\u2026"),value:d}),(0,t.jsx)(D,{"data-testid":"vector-search",disabled:y||d.trim()==="",onClick:P,children:l(y?"Searching\u2026":"Search")})]}),u!==null&&(0,t.jsx)("p",{className:"mt-2 text-sm text-destructive","data-testid":"vector-query-error",role:"alert",children:u}),m!==null&&(0,t.jsx)(te,{matches:m})]})]})},"ue");function le(h){return(0,t.jsxs)(V,{"data-testid":`vector-match-${h.id}`,children:[(0,t.jsx)(S,{className:"font-mono text-xs",children:h.id}),(0,t.jsx)(S,{className:"tabular-nums",children:h.score.toFixed(4)}),(0,t.jsx)(S,{className:"max-w-md truncate font-mono text-xs",children:h.metadata===void 0?"\u2014":H(h.metadata)})]},h.id)}I(le,"ee");export{me as VectorBrowser};
1
+ import{i as A}from"./chunk-SDQH4HR6.js";import"./chunk-W7MRISE3.js";import"./chunk-IBJVVHV5.js";import{a as D}from"./chunk-2O6KKVH2.js";import"./chunk-JTGGWF7R.js";import"./chunk-ZBON5T5A.js";import"./chunk-4C4THJUD.js";import{p as J}from"./chunk-SDSQIQJG.js";import"./chunk-WZTY3ZYI.js";import{a as G}from"./chunk-3Y5K3IQO.js";import{a as Q,b as W,c as Z,d as V,e as C,f as S}from"./chunk-CW57Q264.js";import{a as $,e as z}from"./chunk-MD67S53Z.js";import{f as B,j as F,r as H,s as K}from"./chunk-LPINY2IJ.js";import{a as I,d as M,e as U,f as X,g as Y}from"./chunk-OXFKZ4BM.js";var L=M(X(),1),g=M(U(),1);var t=M(Y(),1);var _=10,E=I(h=>{let e=(0,L.c)(7),{label:i,value:l}=h,r;e[0]!==i?(r=(0,t.jsx)("span",{className:"font-mono text-[11px] uppercase tracking-wide text-muted-foreground",children:i}),e[0]=i,e[1]=r):r=e[1];let a=l??"\u2014",n;e[2]!==a?(n=(0,t.jsx)("span",{className:"font-mono text-sm",children:a}),e[2]=a,e[3]=n):n=e[3];let s;return e[4]!==r||e[5]!==n?(s=(0,t.jsxs)("div",{className:"flex flex-col gap-0.5",children:[r,n]}),e[4]=r,e[5]=n,e[6]=s):s=e[6],s},"_"),ee=I(h=>{let e=(0,L.c)(38),{indexes:i,onSelect:l,selected:r}=h,a=B(),n;e[0]!==a?(n=a("name"),e[0]=a,e[1]=n):n=e[1];let s;e[2]!==n?(s=(0,t.jsx)(C,{children:n}),e[2]=n,e[3]=s):s=e[3];let c;e[4]!==a?(c=a("table"),e[4]=a,e[5]=c):c=e[5];let o;e[6]!==c?(o=(0,t.jsx)(C,{children:c}),e[6]=c,e[7]=o):o=e[7];let d;e[8]!==a?(d=a("dimensions"),e[8]=a,e[9]=d):d=e[9];let x;e[10]!==d?(x=(0,t.jsx)(C,{children:d}),e[10]=d,e[11]=x):x=e[11];let m;e[12]!==a?(m=a("metric"),e[12]=a,e[13]=m):m=e[13];let p;e[14]!==m?(p=(0,t.jsx)(C,{children:m}),e[14]=m,e[15]=p):p=e[15];let u;e[16]!==a?(u=a("vectors"),e[16]=a,e[17]=u):u=e[17];let v;e[18]!==u?(v=(0,t.jsx)(C,{children:u}),e[18]=u,e[19]=v):v=e[19];let y;e[20]!==v||e[21]!==s||e[22]!==o||e[23]!==x||e[24]!==p?(y=(0,t.jsx)(W,{children:(0,t.jsxs)(V,{children:[s,o,x,p,v]})}),e[20]=v,e[21]=s,e[22]=o,e[23]=x,e[24]=p,e[25]=y):y=e[25];let k;if(e[26]!==i||e[27]!==l||e[28]!==r){let q;e[30]!==l||e[31]!==r?(q=I(w=>(0,t.jsxs)(V,{className:w.name===r?"border-l-2 border-l-royal-amethyst bg-muted/50":"cursor-pointer","data-index":w.name,"data-testid":`vector-row-${w.name}`,onClick:l,children:[(0,t.jsx)(S,{className:"font-mono text-xs",children:w.name}),(0,t.jsx)(S,{className:"font-mono text-xs",children:w.table}),(0,t.jsx)(S,{className:"tabular-nums",children:w.dimensions??"\u2014"}),(0,t.jsx)(S,{children:w.metric??"\u2014"}),(0,t.jsx)(S,{className:"tabular-nums",children:w.vectorsCount??"\u2014"})]},w.name),"q"),e[30]=l,e[31]=r,e[32]=q):q=e[32],k=i.map(q),e[26]=i,e[27]=l,e[28]=r,e[29]=k}else k=e[29];let N;e[33]!==k?(N=(0,t.jsx)(Z,{children:k}),e[33]=k,e[34]=N):N=e[34];let f;return e[35]!==y||e[36]!==N?(f=(0,t.jsx)($,{className:"overflow-hidden py-0",children:(0,t.jsx)(z,{className:"px-0",children:(0,t.jsxs)(Q,{"data-testid":"vector-table",children:[y,N]})})}),e[35]=y,e[36]=N,e[37]=f):f=e[37],f},"X"),te=I(h=>{let e=(0,L.c)(27),{matches:i}=h,l=B();if(i.length===0){let u;e[0]!==l?(u=l("No matches."),e[0]=l,e[1]=u):u=e[1];let v;return e[2]!==u?(v=(0,t.jsx)("p",{className:"mt-2 text-sm text-muted-foreground","data-testid":"vector-no-matches",children:u}),e[2]=u,e[3]=v):v=e[3],v}let r;e[4]!==l?(r=l("id"),e[4]=l,e[5]=r):r=e[5];let a;e[6]!==r?(a=(0,t.jsx)(C,{children:r}),e[6]=r,e[7]=a):a=e[7];let n;e[8]!==l?(n=l("score"),e[8]=l,e[9]=n):n=e[9];let s;e[10]!==n?(s=(0,t.jsx)(C,{children:n}),e[10]=n,e[11]=s):s=e[11];let c;e[12]!==l?(c=l("metadata"),e[12]=l,e[13]=c):c=e[13];let o;e[14]!==c?(o=(0,t.jsx)(C,{children:c}),e[14]=c,e[15]=o):o=e[15];let d;e[16]!==a||e[17]!==s||e[18]!==o?(d=(0,t.jsx)(W,{children:(0,t.jsxs)(V,{children:[a,s,o]})}),e[16]=a,e[17]=s,e[18]=o,e[19]=d):d=e[19];let x;e[20]!==i?(x=i.map(le),e[20]=i,e[21]=x):x=e[21];let m;e[22]!==x?(m=(0,t.jsx)(Z,{children:x}),e[22]=x,e[23]=m):m=e[23];let p;return e[24]!==d||e[25]!==m?(p=(0,t.jsx)($,{className:"mt-3 overflow-hidden py-0",children:(0,t.jsx)(z,{className:"px-0",children:(0,t.jsxs)(Q,{"data-testid":"vector-matches",children:[d,m]})})}),e[24]=d,e[25]=m,e[26]=p):p=e[26],p},"Y"),me=I(({loadIndexes:h,runQuery:e}={})=>{let i=J(),l=B(),[r,a]=(0,g.useState)(null),[n,s]=(0,g.useState)(null),[c,o]=(0,g.useState)(null),[d,x]=(0,g.useState)(""),[m,p]=(0,g.useState)(null),[u,v]=(0,g.useState)(null),[y,k]=(0,g.useState)(!1),N=(0,g.useRef)(0);(0,g.useEffect)(()=>{let b={cancelled:!1};return K((async()=>{try{let j=await(h??(()=>i.listVectorIndexes()))();b.cancelled||(a(j),s(null),o(T=>T??j[0]?.name??null))}catch(j){b.cancelled||(a(null),s(F(j)))}})()),()=>{b.cancelled=!0}},[i,h]);let f=r?.find(b=>b.name===c)??null,q=I(b=>{N.current+=1,o(b.currentTarget.dataset.index??null),p(null),v(null),k(!1)},"q"),w=I(b=>{x(b.target.value)},"y"),O=I(async()=>{let b=d.trim();if(c===null||b==="")return;N.current+=1;let j=N.current;k(!0),v(null);try{let T=await(e??(R=>i.queryVectorIndex(R)))({name:c,text:b,topK:_});if(j!==N.current)return;p(T)}catch(T){if(j!==N.current)return;p(null),v(F(T))}k(!1)},"H"),P=I(()=>{K(O())},"K");return(0,t.jsxs)("div",{className:"flex flex-col gap-4","data-testid":"lunora-vector-browser",children:[n!==null&&(0,t.jsx)("p",{className:"text-sm text-destructive","data-testid":"vector-error",role:"alert",children:n}),r!==null&&r.length===0&&(0,t.jsx)(G,{description:l("Indexes declared with .vectorize() or defineVectorIndex() appear here."),icon:(0,t.jsx)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,t.jsx)("path",{d:"M4 7l8-4 8 4-8 4-8-4Zm0 5 8 4 8-4M4 17l8 4 8-4"})}),testId:"vector-empty",title:l("No vector indexes.")}),r!==null&&r.length>0&&(0,t.jsx)(ee,{indexes:r,onSelect:q,selected:c}),f!==null&&(0,t.jsxs)("section",{className:"border border-border bg-card p-3","data-testid":"vector-detail",children:[(0,t.jsxs)("div",{className:"grid grid-cols-2 gap-3 sm:grid-cols-4",children:[(0,t.jsx)(E,{label:l("field"),value:f.field}),(0,t.jsx)(E,{label:l("dimensions"),value:f.dimensions}),(0,t.jsx)(E,{label:l("metric"),value:f.metric}),(0,t.jsx)(E,{label:l("vectors"),value:f.vectorsCount})]}),f.metadata!==void 0&&f.metadata.length>0&&(0,t.jsxs)("p",{className:"mt-3 text-xs text-muted-foreground","data-testid":"vector-metadata",children:[l("metadata"),": ",(0,t.jsx)("span",{className:"font-mono",children:f.metadata.join(", ")})]}),(0,t.jsxs)("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[(0,t.jsx)(A,{className:"min-w-[18rem] flex-1","data-testid":"vector-query-input",onChange:w,placeholder:l("Search by similarity\u2026"),value:d}),(0,t.jsx)(D,{"data-testid":"vector-search",disabled:y||d.trim()==="",onClick:P,children:l(y?"Searching\u2026":"Search")})]}),u!==null&&(0,t.jsx)("p",{className:"mt-2 text-sm text-destructive","data-testid":"vector-query-error",role:"alert",children:u}),m!==null&&(0,t.jsx)(te,{matches:m})]})]})},"ue");function le(h){return(0,t.jsxs)(V,{"data-testid":`vector-match-${h.id}`,children:[(0,t.jsx)(S,{className:"font-mono text-xs",children:h.id}),(0,t.jsx)(S,{className:"tabular-nums",children:h.score.toFixed(4)}),(0,t.jsx)(S,{className:"max-w-md truncate font-mono text-xs",children:h.metadata===void 0?"\u2014":H(h.metadata)})]},h.id)}I(le,"ee");export{me as VectorBrowser};
@@ -1 +1 @@
1
- import{b as be}from"./chunk-TDVDZ7XQ.js";import{a as le}from"./chunk-EEPCLLGE.js";import"./chunk-5IIX2STA.js";import"./chunk-SYGCASPT.js";import{a as ve}from"./chunk-XBZUJDHD.js";import"./chunk-ZGSL4DPP.js";import{a as xe}from"./chunk-SLIDAWNX.js";import"./chunk-6M7FLLMT.js";import"./chunk-ZTOREMGH.js";import"./chunk-IBJVVHV5.js";import{b as ee}from"./chunk-6I42AM75.js";import"./chunk-4C4THJUD.js";import"./chunk-E26OT26O.js";import{a as U}from"./chunk-6UTZXEW3.js";import{c as ge}from"./chunk-4SJDWMH3.js";import{o as he,p as fe}from"./chunk-FKM35PXF.js";import"./chunk-WZTY3ZYI.js";import{a as W}from"./chunk-MD67S53Z.js";import{b as $,f as B,h as X,i as ie,j as ce,s as se,w as pe}from"./chunk-LPINY2IJ.js";import{a as h,d as Z,e as Ae,f as ue,g as me}from"./chunk-OXFKZ4BM.js";var te=Z(ue(),1),x=Z(Ae(),1);var Ne=Z(ue(),1);var ae=Z(me(),1);var je={connected:"bg-success",connecting:"bg-warning",idle:"bg-muted-foreground",offline:"bg-destructive",polling:"bg-warning"},ye=h(()=>{let t=(0,Ne.c)(18),e=B(),n=he(),r;e:switch(n){case"connected":{let l;t[0]!==e?(l=e("Connected"),t[0]=e,t[1]=l):l=t[1],r=l;break e}case"connecting":{let l;t[2]!==e?(l=e("Connecting\u2026"),t[2]=e,t[3]=l):l=t[3],r=l;break e}case"idle":{let l;t[4]!==e?(l=e("Idle"),t[4]=e,t[5]=l):l=t[5],r=l;break e}case"offline":{let l;t[6]!==e?(l=e("Offline"),t[6]=e,t[7]=l):l=t[7],r=l;break e}case"polling":{let l;t[8]!==e?(l=e("Polling"),t[8]=e,t[9]=l):l=t[9],r=l;break e}default:r=n}let a=je[n],c;t[10]!==a?(c=$("size-2 rounded-full",a),t[10]=a,t[11]=c):c=t[11];let i;t[12]!==c?(i=(0,ae.jsx)("span",{"aria-hidden":"true",className:c}),t[12]=c,t[13]=i):i=t[13];let o;return t[14]!==n||t[15]!==i||t[16]!==r?(o=(0,ae.jsxs)("span",{"aria-live":"polite",className:"inline-flex items-center gap-1.5 text-xs text-muted-foreground","data-status":n,"data-testid":"dash-connection",role:"status",children:[i,r]}),t[14]=n,t[15]=i,t[16]=r,t[17]=o):o=t[17],o},"T");var s=Z(me(),1);var Te={crit:"destructive",ok:"secondary",warn:"default"},oe=h((t,e)=>e===0?"\u2014":`${(t/e*100).toFixed(1)}%`,"re"),de=h((t,e,n)=>Number.isNaN(t)?"ok":t>=n?"crit":t>=e?"warn":"ok","oe"),Se=.01,Ee=.05,Ce=h(t=>{let e=(0,te.c)(36),{errorCount:n,logsError:r,topErrors:a,worstFunctions:c}=t,i=B(),o;e[0]!==i?(o=i("Functions by error rate"),e[0]=i,e[1]=o):o=e[1];let l;e[2]!==o?(l=(0,s.jsx)("header",{className:"border-b border-border px-4 py-3",children:(0,s.jsx)("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:o})}),e[2]=o,e[3]=l):l=e[3];let u;e[4]!==i||e[5]!==c?(u=c.length===0?(0,s.jsx)("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground","data-testid":"hl-functions-empty",children:i("No function activity yet.")}):(0,s.jsx)("ul",{className:"divide-y divide-border",children:c.map(y=>(0,s.jsxs)("li",{className:"flex flex-wrap items-center justify-between gap-2 px-4 py-2 text-xs","data-testid":"hl-fn-row",children:[(0,s.jsx)("span",{className:"truncate font-mono text-foreground",children:y.path}),(0,s.jsxs)("span",{className:"flex shrink-0 items-center gap-2",children:[(0,s.jsx)("span",{className:"tabular-nums text-muted-foreground",children:i("{count} calls",{count:y.calls.toString()})}),(0,s.jsx)(ee,{variant:Te[de(y.errors/y.calls,Se,Ee)],children:oe(y.errors,y.calls)})]})]},y.path))}),e[4]=i,e[5]=c,e[6]=u):u=e[6];let f;e[7]!==l||e[8]!==u?(f=(0,s.jsxs)(W,{className:"gap-0 py-0","data-testid":"hl-functions",children:[l,u]}),e[7]=l,e[8]=u,e[9]=f):f=e[9];let v;e[10]!==i?(v=i("Recent errors"),e[10]=i,e[11]=v):v=e[11];let m;e[12]!==v?(m=(0,s.jsx)("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:v}),e[12]=v,e[13]=m):m=e[13];let d=n>0?"destructive":"outline",g;e[14]!==n||e[15]!==d?(g=(0,s.jsx)(ee,{"data-testid":"hl-error-count",variant:d,children:n}),e[14]=n,e[15]=d,e[16]=g):g=e[16];let p;e[17]!==m||e[18]!==g?(p=(0,s.jsxs)("header",{className:"flex items-center justify-between gap-2 border-b border-border px-4 py-3",children:[m,g]}),e[17]=m,e[18]=g,e[19]=p):p=e[19];let S;e[20]!==r?(S=r!==null&&(0,s.jsx)("p",{className:"px-4 py-8 text-center text-sm text-destructive","data-testid":"hl-logs-error",role:"alert",children:r}),e[20]=r,e[21]=S):S=e[21];let E;e[22]!==r||e[23]!==i||e[24]!==a.length?(E=r===null&&a.length===0&&(0,s.jsx)("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground","data-testid":"hl-errors-empty",children:i("No recent errors.")}),e[22]=r,e[23]=i,e[24]=a.length,e[25]=E):E=e[25];let q;e[26]!==a?(q=a.length>0&&(0,s.jsx)("ul",{className:"divide-y divide-border",children:a.map(Ie)}),e[26]=a,e[27]=q):q=e[27];let w;e[28]!==S||e[29]!==E||e[30]!==q||e[31]!==p?(w=(0,s.jsxs)(W,{className:"gap-0 py-0",children:[p,S,E,q]}),e[28]=S,e[29]=E,e[30]=q,e[31]=p,e[32]=w):w=e[32];let k;return e[33]!==w||e[34]!==f?(k=(0,s.jsxs)("div",{className:"grid gap-3 lg:grid-cols-2",children:[f,w]}),e[33]=w,e[34]=f,e[35]=k):k=e[35],k},"_e");function Ie(t,e){return(0,s.jsxs)("li",{className:"flex flex-col gap-0.5 px-4 py-2 text-xs","data-testid":"hl-error-row",children:[(0,s.jsxs)("span",{className:"flex items-center gap-2",children:[(0,s.jsx)("time",{className:"shrink-0 text-muted-foreground",children:pe(t.timestamp)}),t.functionPath!==void 0&&(0,s.jsx)("span",{className:"truncate font-mono text-foreground",children:t.functionPath})]}),(0,s.jsx)("span",{className:"text-destructive",children:t.message})]},`${t.timestamp.toString()}-${e.toString()}`)}h(Ie,"Ae");var we={completed:0,failed:2,in_progress:1},De=h(t=>{let e=0,n=0,r=0,a=0,c=!1,i=[];for(let{metrics:o}of t){if(o===null){a+=1;continue}r+=1,e+=o.requests,n+=o.errors,i.push(...o.history??[]),c||=o.historyTruncated===!0}return{errors:n,failed:a,history:i,historyTruncated:c,reachable:r,requests:e}},"ke"),_e=h(t=>{let e=new Map;for(let n of t)for(let r of n){let a=e.get(r.path);if(a===void 0){e.set(r.path,{...r});continue}a.calls+=r.calls,a.errors+=r.errors,a.totalDurationMs+=r.totalDurationMs,a.scans=(a.scans??0)+(r.scans??0),a.maxDurationMs=Math.max(a.maxDurationMs,r.maxDurationMs),a.lastCalledAt=Math.max(a.lastCalledAt,r.lastCalledAt),(r.lastErrorAt??0)>(a.lastErrorAt??0)&&(a.lastErrorAt=r.lastErrorAt,a.lastErrorMessage=r.lastErrorMessage)}return[...e.values()]},"Re"),Pe=h(t=>{let e=new Map;for(let n of t)for(let r of n){let a=e.get(r.id);if(a===void 0){e.set(r.id,r);continue}let c=we[r.status]-we[a.status];(c>0||c===0&&(r.updatedAt??0)>(a.updatedAt??0))&&e.set(r.id,r)}return[...e.values()]},"Me"),Le=X(U.getAuthMetrics),Fe=X(U.getFunctionStats),Re=X(U.getLogs),Oe=X(U.getMetrics),ze=X(U.migrationStatus),$e=5,ke=2e3,Ke=5,Be=.1,Ue=.3,Ge=1,He=50,Qe=h((t,e,n)=>t>=n?"crit":t>=e?"warn":"ok","$e"),Je=h(t=>{let e=new Map;for(let r of t??[]){let a=e.get(r.bucketMs)??{calls:0,errors:0};a.calls+=r.calls,a.errors+=r.errors,e.set(r.bucketMs,a)}let n=[...e.entries()].toSorted((r,a)=>r[0]-a[0]);return{errors:n.map(([,r])=>r.errors),requests:n.map(([,r])=>r.calls)}},"Be"),Ve=h(t=>{let e=0,n=0;for(let a of t)a.status==="failed"?e+=1:a.status==="in_progress"&&(n+=1);let r="ok";return e>0?r="crit":n>0&&(r="warn"),{failed:e,level:r,running:n}},"Ve"),We=h((t,e)=>t.failed>0?e("{count} failed",{count:t.failed.toString()}):t.running>0?e("{count} running",{count:t.running.toString()}):e("OK"),"He"),qe={crit:"bg-destructive",ok:"bg-success",warn:"bg-warning"},Me={crit:"text-destructive",ok:"text-foreground",warn:"text-warning"},Xe={crit:"bg-destructive/10 text-destructive",ok:"bg-success/10 text-success",warn:"bg-warning/10 text-warning"},Ye=h(t=>t.includes("crit")?"crit":t.includes("warn")?"warn":"ok","ze"),ne=h(t=>{let e=(0,te.c)(19),{chart:n,label:r,level:a,testId:c,value:i}=t,o=qe[a],l;e[0]!==o?(l=$("size-1.5 shrink-0 rounded-full",o),e[0]=o,e[1]=l):l=e[1];let u;e[2]!==l?(u=(0,s.jsx)("span",{"aria-hidden":"true",className:l}),e[2]=l,e[3]=u):u=e[3];let f;e[4]!==r||e[5]!==u?(f=(0,s.jsxs)("span",{className:"flex items-center gap-1.5 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:[u,r]}),e[4]=r,e[5]=u,e[6]=f):f=e[6];let v=Me[a],m;e[7]!==v?(m=$("truncate text-2xl font-semibold tabular-nums",v),e[7]=v,e[8]=m):m=e[8];let d;e[9]!==m||e[10]!==c||e[11]!==i?(d=(0,s.jsx)("span",{className:m,"data-testid":c,children:i}),e[9]=m,e[10]=c,e[11]=i,e[12]=d):d=e[12];let g;e[13]!==n||e[14]!==d?(g=(0,s.jsxs)("div",{className:"flex items-center justify-between gap-3",children:[d,n]}),e[13]=n,e[14]=d,e[15]=g):g=e[15];let p;return e[16]!==f||e[17]!==g?(p=(0,s.jsx)(W,{className:"gap-0 py-0",children:(0,s.jsxs)("div",{className:"flex flex-col gap-2.5 p-4",children:[f,g]})}),e[16]=f,e[17]=g,e[18]=p):p=e[18],p},"ee"),Ze=h(async(t,e,n)=>{let r=await Promise.all(n.map(m=>{let d=ie(m);return Promise.allSettled([t.query(Oe,{},d),t.query(Fe,{},d),t.query(ze,{},d)])})),a=ie(e),c=typeof t.schedulerStatus=="function"?t.schedulerStatus():Promise.reject(new Error("scheduler status unavailable")),[i,o,l]=await Promise.allSettled([t.query(Re,{},a),t.query(Le,{},a),c]),u=r.map(([m,d,g])=>({functions:d.status==="fulfilled"?d.value.functions:[],metrics:m.status==="fulfilled"?m.value:null,migrations:g.status==="fulfilled"?g.value.migrations:[]})),f=De(u),v=r[0]?.[0];return{auth:o.status==="fulfilled"?o.value:null,entries:i.status==="fulfilled"?i.value.entries:[],functions:_e(u.map(m=>m.functions)),logsError:i.status==="rejected"?ce(i.reason):null,metricsError:f.reachable===0&&v?.status==="rejected"?ce(v.reason):null,migrations:Pe(u.map(m=>m.migrations)),scheduler:l.status==="fulfilled"?l.value:null,totals:f}},"Qe"),et=h(t=>{let e=t?.history??[];return{attempts:e.map(n=>n.attempts),failures:e.map(n=>n.failures)}},"We"),tt=h((t,e)=>t==="crit"?{description:e("One or more service levels are breached."),label:e("Critical")}:t==="warn"?{description:e("Some service levels need attention."),label:e("Degraded")}:{description:e("All service levels are within target."),label:e("All systems healthy")},"Xe"),rt=h(t=>{let e=(0,te.c)(75),{errorLevel:n,liveError:r,metricsError:a,overall:c,requestSeries:i,totals:o}=t,l=B(),u;e[0]!==c||e[1]!==l?(u=tt(c,l),e[0]=c,e[1]=l,e[2]=u):u=e[2];let{description:f,label:v}=u,m=Xe[c],d;e[3]!==m?(d=$("flex size-10 shrink-0 items-center justify-center rounded-full",m),e[3]=m,e[4]=d):d=e[4];let g=qe[c],p;e[5]!==g?(p=$("size-3 rounded-full",g),e[5]=g,e[6]=p):p=e[6];let S;e[7]!==p?(S=(0,s.jsx)("span",{className:p}),e[7]=p,e[8]=S):S=e[8];let E;e[9]!==d||e[10]!==S?(E=(0,s.jsx)("span",{"aria-hidden":"true",className:d,children:S}),e[9]=d,e[10]=S,e[11]=E):E=e[11];let q;e[12]!==v?(q=(0,s.jsx)("span",{className:"text-sm font-semibold text-foreground","data-testid":"hl-status",children:v}),e[12]=v,e[13]=q):q=e[13];let w;e[14]!==f?(w=(0,s.jsx)("span",{className:"text-[13px] text-muted-foreground",children:f}),e[14]=f,e[15]=w):w=e[15];let k;e[16]!==q||e[17]!==w?(k=(0,s.jsxs)("div",{className:"grid leading-tight",children:[q,w]}),e[16]=q,e[17]=w,e[18]=k):k=e[18];let y;e[19]!==k||e[20]!==E?(y=(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[E,k]}),e[19]=k,e[20]=E,e[21]=y):y=e[21];let j;e[22]!==l?(j=l("Requests"),e[22]=l,e[23]=j):j=e[23];let M;e[24]!==j?(M=(0,s.jsx)("div",{className:"font-mono text-[10px] tracking-wide text-muted-foreground uppercase",children:j}),e[24]=j,e[25]=M):M=e[25];let A;e[26]!==i||e[27]!==l?(A=i.length>=2&&(0,s.jsx)(le,{ariaLabel:l("Requests over time"),className:"h-6 w-20 text-foreground",series:i,testId:"hl-spark-requests"}),e[26]=i,e[27]=l,e[28]=A):A=e[28];let F=o?.requests??0,R;e[29]!==F?(R=F.toString(),e[29]=F,e[30]=R):R=e[30];let D;e[31]!==R?(D=(0,s.jsx)("span",{className:"text-lg font-semibold tabular-nums text-foreground","data-testid":"hl-requests",children:R}),e[31]=R,e[32]=D):D=e[32];let O;e[33]!==A||e[34]!==D?(O=(0,s.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[A,D]}),e[33]=A,e[34]=D,e[35]=O):O=e[35];let _;e[36]!==M||e[37]!==O?(_=(0,s.jsxs)("div",{className:"text-end",children:[M,O]}),e[36]=M,e[37]=O,e[38]=_):_=e[38];let G;e[39]===Symbol.for("react.memo_cache_sentinel")?(G=(0,s.jsx)("span",{"aria-hidden":"true",className:"h-9 w-px bg-border"}),e[39]=G):G=e[39];let T;e[40]!==l?(T=l("Error rate"),e[40]=l,e[41]=T):T=e[41];let P;e[42]!==T?(P=(0,s.jsx)("div",{className:"font-mono text-[10px] tracking-wide text-muted-foreground uppercase",children:T}),e[42]=T,e[43]=P):P=e[43];let Y=Me[n],C;e[44]!==Y?(C=$("text-lg font-semibold tabular-nums",Y),e[44]=Y,e[45]=C):C=e[45];let z;e[46]!==o?(z=o===null?"\u2014":oe(o.errors,o.requests),e[46]=o,e[47]=z):z=e[47];let I;e[48]!==C||e[49]!==z?(I=(0,s.jsx)("div",{className:C,"data-testid":"hl-error-rate",children:z}),e[48]=C,e[49]=z,e[50]=I):I=e[50];let L;e[51]!==P||e[52]!==I?(L=(0,s.jsxs)("div",{className:"text-end",children:[P,I]}),e[51]=P,e[52]=I,e[53]=L):L=e[53];let K;e[54]===Symbol.for("react.memo_cache_sentinel")?(K=(0,s.jsx)("span",{"aria-hidden":"true",className:"h-9 w-px bg-border"}),e[54]=K):K=e[54];let H;e[55]===Symbol.for("react.memo_cache_sentinel")?(H=(0,s.jsx)(ye,{}),e[55]=H):H=e[55];let b;e[56]!==r?(b=(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[H,(0,s.jsx)(ve,{message:r,prefix:"hl"})]}),e[56]=r,e[57]=b):b=e[57];let N;e[58]!==_||e[59]!==L||e[60]!==b?(N=(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-4",children:[_,G,L,K,b]}),e[58]=_,e[59]=L,e[60]=b,e[61]=N):N=e[61];let Q;e[62]!==y||e[63]!==N?(Q=(0,s.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-4 p-4",children:[y,N]}),e[62]=y,e[63]=N,e[64]=Q):Q=e[64];let J;e[65]!==a?(J=a!==null&&(0,s.jsx)("div",{className:"border-t border-border bg-destructive/5 px-4 py-2 text-sm text-destructive","data-testid":"hl-metrics-error",role:"alert",children:a}),e[65]=a,e[66]=J):J=e[66];let V;e[67]!==a||e[68]!==l||e[69]!==o?.historyTruncated?(V=a===null&&o?.historyTruncated===!0&&(0,s.jsx)("div",{className:"border-t border-border bg-warning/5 px-4 py-2 text-sm text-muted-foreground","data-testid":"hl-history-truncated",children:l("Showing a partial request/error history \u2014 one or more shards have more data than the trend chart can display.")}),e[67]=a,e[68]=l,e[69]=o?.historyTruncated,e[70]=V):V=e[70];let re;return e[71]!==Q||e[72]!==J||e[73]!==V?(re=(0,s.jsxs)(W,{className:"gap-0 py-0",children:[Q,J,V]}),e[71]=Q,e[72]=J,e[73]=V,e[74]=re):re=e[74],re},"Je"),st=h(t=>{let e=(0,te.c)(14),{shards:n}=t,r=B(),a;e[0]!==r?(a=r("Shards seen"),e[0]=r,e[1]=a):a=e[1];let c;e[2]!==a?(c=(0,s.jsx)("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:a}),e[2]=a,e[3]=c):c=e[3];let i;e[4]!==n.length?(i=(0,s.jsx)(ee,{"data-testid":"hl-shard-count",variant:"outline",children:n.length}),e[4]=n.length,e[5]=i):i=e[5];let o;e[6]!==c||e[7]!==i?(o=(0,s.jsxs)("header",{className:"flex items-center justify-between gap-2 border-b border-border px-4 py-3",children:[c,i]}),e[6]=c,e[7]=i,e[8]=o):o=e[8];let l;e[9]!==n?(l=n.length>0&&(0,s.jsx)("ul",{className:"flex flex-wrap gap-1.5 p-4",children:n.map(lt)}),e[9]=n,e[10]=l):l=e[10];let u;return e[11]!==o||e[12]!==l?(u=(0,s.jsxs)(W,{className:"gap-0 py-0",children:[o,l]}),e[11]=o,e[12]=l,e[13]=u):u=e[13],u},"Ye"),kt=h(({initialShardKey:t})=>{let e=fe(),n=B(),[r,a]=(0,x.useState)([]),[c,i]=(0,x.useState)(null),[o,l]=(0,x.useState)(null),[u,f]=(0,x.useState)(null),[v,m]=(0,x.useState)([]),[d,g]=(0,x.useState)(null),[p,S]=(0,x.useState)(null),[E,q]=(0,x.useState)([]),[w]=(0,x.useState)(xe),k=(0,x.useRef)(!1),y=(0,x.useRef)(0),j=(0,x.useRef)(0),M=(0,x.useRef)(null),A=t??"",F=(0,x.useCallback)(async()=>{if(k.current)return;k.current=!0;let b=y.current,N=await Ze(e,A,be(A,w));b===y.current&&(l(N.totals),f(N.metricsError),m(N.functions),q(N.migrations),a(N.entries),i(N.logsError),g(N.auth),S(N.scheduler),k.current=!1)},[e,w,A]);(0,x.useEffect)(()=>(se(F()),()=>{y.current+=1,k.current=!1,M.current!==null&&(clearTimeout(M.current),M.current=null)}),[F]);let R=h(()=>{let b=Date.now()-j.current;if(b>=ke){j.current=Date.now(),se(F());return}M.current===null&&(M.current=setTimeout(()=>{M.current=null,j.current=Date.now(),se(F())},ke-b))},"j"),{data:D,liveError:O}=ge(U.getMetrics,{},{live:!0,shardKey:A});(0,x.useEffect)(()=>{D!==void 0&&R()},[D]);let _=r.filter(b=>b.level==="error"),G=_.slice(0,$e),T=Je(o?.history),P=et(d),Y=v.filter(b=>b.calls>0).toSorted((b,N)=>N.errors/N.calls-b.errors/b.calls||N.calls-b.calls).slice(0,Ke),C=Ve(E),z=o===null||o.requests===0?0:o.errors/o.requests,I=de(z,Se,Ee),L=d===null?"ok":de(d.failureRate,Be,Ue),K=p===null?"ok":Qe(p.backlog,Ge,He),H=Ye([I,L,K,C.level]);return(0,s.jsxs)("div",{className:"flex flex-col gap-6","data-testid":"lunora-health",children:[(0,s.jsx)(rt,{errorLevel:I,liveError:O,metricsError:u,overall:H,requestSeries:T.requests,totals:o}),(0,s.jsxs)("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4","data-testid":"hl-slo",children:[(0,s.jsx)(ne,{chart:T.errors.length>=2?(0,s.jsx)(le,{ariaLabel:n("Errors over time"),className:"h-7 w-20 text-destructive",series:T.errors,testId:"hl-spark-errors"}):void 0,label:n("Error rate"),level:I,testId:"hl-slo-errorrate",value:o===null?"\u2014":oe(o.errors,o.requests)}),(0,s.jsx)(ne,{chart:P.failures.length>=2?(0,s.jsx)(le,{ariaLabel:n("Auth failures over time"),className:"h-7 w-20 text-destructive",series:P.failures,testId:"hl-spark-auth"}):void 0,label:n("Auth failures"),level:L,testId:"hl-slo-auth",value:d===null?"\u2014":oe(d.failures,d.attempts)}),(0,s.jsx)(ne,{label:n("Scheduler backlog"),level:K,testId:"hl-slo-backlog",value:p===null?"\u2014":p.backlog.toString()}),(0,s.jsx)(ne,{label:n("Migrations"),level:C.level,testId:"hl-slo-migrations",value:We(C,n)})]}),(0,s.jsx)(Ce,{errorCount:_.length,logsError:c,topErrors:G,worstFunctions:Y}),(0,s.jsx)(st,{shards:w})]})},"gt");function lt(t){return(0,s.jsx)("li",{"data-testid":"hl-shard",children:(0,s.jsx)(ee,{variant:"secondary",children:t})},t)}h(lt,"Ze");export{kt as HealthPanel};
1
+ import{b as be}from"./chunk-TDVDZ7XQ.js";import{a as le}from"./chunk-HONLEKH5.js";import"./chunk-ZFFZWSDJ.js";import"./chunk-SYGCASPT.js";import{a as ve}from"./chunk-XBZUJDHD.js";import"./chunk-ZGSL4DPP.js";import{a as xe}from"./chunk-SLIDAWNX.js";import"./chunk-6M7FLLMT.js";import"./chunk-ZTOREMGH.js";import"./chunk-IBJVVHV5.js";import{b as ee}from"./chunk-6I42AM75.js";import"./chunk-4C4THJUD.js";import"./chunk-E26OT26O.js";import{a as U}from"./chunk-6UTZXEW3.js";import{c as ge}from"./chunk-W37HRJGQ.js";import{o as he,p as fe}from"./chunk-SDSQIQJG.js";import"./chunk-WZTY3ZYI.js";import{a as W}from"./chunk-MD67S53Z.js";import{b as $,f as B,h as X,i as ie,j as ce,s as se,w as pe}from"./chunk-LPINY2IJ.js";import{a as h,d as Z,e as Ae,f as ue,g as me}from"./chunk-OXFKZ4BM.js";var te=Z(ue(),1),x=Z(Ae(),1);var Ne=Z(ue(),1);var ae=Z(me(),1);var je={connected:"bg-success",connecting:"bg-warning",idle:"bg-muted-foreground",offline:"bg-destructive",polling:"bg-warning"},ye=h(()=>{let t=(0,Ne.c)(18),e=B(),n=he(),r;e:switch(n){case"connected":{let l;t[0]!==e?(l=e("Connected"),t[0]=e,t[1]=l):l=t[1],r=l;break e}case"connecting":{let l;t[2]!==e?(l=e("Connecting\u2026"),t[2]=e,t[3]=l):l=t[3],r=l;break e}case"idle":{let l;t[4]!==e?(l=e("Idle"),t[4]=e,t[5]=l):l=t[5],r=l;break e}case"offline":{let l;t[6]!==e?(l=e("Offline"),t[6]=e,t[7]=l):l=t[7],r=l;break e}case"polling":{let l;t[8]!==e?(l=e("Polling"),t[8]=e,t[9]=l):l=t[9],r=l;break e}default:r=n}let a=je[n],c;t[10]!==a?(c=$("size-2 rounded-full",a),t[10]=a,t[11]=c):c=t[11];let i;t[12]!==c?(i=(0,ae.jsx)("span",{"aria-hidden":"true",className:c}),t[12]=c,t[13]=i):i=t[13];let o;return t[14]!==n||t[15]!==i||t[16]!==r?(o=(0,ae.jsxs)("span",{"aria-live":"polite",className:"inline-flex items-center gap-1.5 text-xs text-muted-foreground","data-status":n,"data-testid":"dash-connection",role:"status",children:[i,r]}),t[14]=n,t[15]=i,t[16]=r,t[17]=o):o=t[17],o},"T");var s=Z(me(),1);var Te={crit:"destructive",ok:"secondary",warn:"default"},oe=h((t,e)=>e===0?"\u2014":`${(t/e*100).toFixed(1)}%`,"re"),de=h((t,e,n)=>Number.isNaN(t)?"ok":t>=n?"crit":t>=e?"warn":"ok","oe"),Se=.01,Ee=.05,Ce=h(t=>{let e=(0,te.c)(36),{errorCount:n,logsError:r,topErrors:a,worstFunctions:c}=t,i=B(),o;e[0]!==i?(o=i("Functions by error rate"),e[0]=i,e[1]=o):o=e[1];let l;e[2]!==o?(l=(0,s.jsx)("header",{className:"border-b border-border px-4 py-3",children:(0,s.jsx)("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:o})}),e[2]=o,e[3]=l):l=e[3];let u;e[4]!==i||e[5]!==c?(u=c.length===0?(0,s.jsx)("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground","data-testid":"hl-functions-empty",children:i("No function activity yet.")}):(0,s.jsx)("ul",{className:"divide-y divide-border",children:c.map(y=>(0,s.jsxs)("li",{className:"flex flex-wrap items-center justify-between gap-2 px-4 py-2 text-xs","data-testid":"hl-fn-row",children:[(0,s.jsx)("span",{className:"truncate font-mono text-foreground",children:y.path}),(0,s.jsxs)("span",{className:"flex shrink-0 items-center gap-2",children:[(0,s.jsx)("span",{className:"tabular-nums text-muted-foreground",children:i("{count} calls",{count:y.calls.toString()})}),(0,s.jsx)(ee,{variant:Te[de(y.errors/y.calls,Se,Ee)],children:oe(y.errors,y.calls)})]})]},y.path))}),e[4]=i,e[5]=c,e[6]=u):u=e[6];let f;e[7]!==l||e[8]!==u?(f=(0,s.jsxs)(W,{className:"gap-0 py-0","data-testid":"hl-functions",children:[l,u]}),e[7]=l,e[8]=u,e[9]=f):f=e[9];let v;e[10]!==i?(v=i("Recent errors"),e[10]=i,e[11]=v):v=e[11];let m;e[12]!==v?(m=(0,s.jsx)("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:v}),e[12]=v,e[13]=m):m=e[13];let d=n>0?"destructive":"outline",g;e[14]!==n||e[15]!==d?(g=(0,s.jsx)(ee,{"data-testid":"hl-error-count",variant:d,children:n}),e[14]=n,e[15]=d,e[16]=g):g=e[16];let p;e[17]!==m||e[18]!==g?(p=(0,s.jsxs)("header",{className:"flex items-center justify-between gap-2 border-b border-border px-4 py-3",children:[m,g]}),e[17]=m,e[18]=g,e[19]=p):p=e[19];let S;e[20]!==r?(S=r!==null&&(0,s.jsx)("p",{className:"px-4 py-8 text-center text-sm text-destructive","data-testid":"hl-logs-error",role:"alert",children:r}),e[20]=r,e[21]=S):S=e[21];let E;e[22]!==r||e[23]!==i||e[24]!==a.length?(E=r===null&&a.length===0&&(0,s.jsx)("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground","data-testid":"hl-errors-empty",children:i("No recent errors.")}),e[22]=r,e[23]=i,e[24]=a.length,e[25]=E):E=e[25];let q;e[26]!==a?(q=a.length>0&&(0,s.jsx)("ul",{className:"divide-y divide-border",children:a.map(Ie)}),e[26]=a,e[27]=q):q=e[27];let w;e[28]!==S||e[29]!==E||e[30]!==q||e[31]!==p?(w=(0,s.jsxs)(W,{className:"gap-0 py-0",children:[p,S,E,q]}),e[28]=S,e[29]=E,e[30]=q,e[31]=p,e[32]=w):w=e[32];let k;return e[33]!==w||e[34]!==f?(k=(0,s.jsxs)("div",{className:"grid gap-3 lg:grid-cols-2",children:[f,w]}),e[33]=w,e[34]=f,e[35]=k):k=e[35],k},"_e");function Ie(t,e){return(0,s.jsxs)("li",{className:"flex flex-col gap-0.5 px-4 py-2 text-xs","data-testid":"hl-error-row",children:[(0,s.jsxs)("span",{className:"flex items-center gap-2",children:[(0,s.jsx)("time",{className:"shrink-0 text-muted-foreground",children:pe(t.timestamp)}),t.functionPath!==void 0&&(0,s.jsx)("span",{className:"truncate font-mono text-foreground",children:t.functionPath})]}),(0,s.jsx)("span",{className:"text-destructive",children:t.message})]},`${t.timestamp.toString()}-${e.toString()}`)}h(Ie,"Ae");var we={completed:0,failed:2,in_progress:1},De=h(t=>{let e=0,n=0,r=0,a=0,c=!1,i=[];for(let{metrics:o}of t){if(o===null){a+=1;continue}r+=1,e+=o.requests,n+=o.errors,i.push(...o.history??[]),c||=o.historyTruncated===!0}return{errors:n,failed:a,history:i,historyTruncated:c,reachable:r,requests:e}},"ke"),_e=h(t=>{let e=new Map;for(let n of t)for(let r of n){let a=e.get(r.path);if(a===void 0){e.set(r.path,{...r});continue}a.calls+=r.calls,a.errors+=r.errors,a.totalDurationMs+=r.totalDurationMs,a.scans=(a.scans??0)+(r.scans??0),a.maxDurationMs=Math.max(a.maxDurationMs,r.maxDurationMs),a.lastCalledAt=Math.max(a.lastCalledAt,r.lastCalledAt),(r.lastErrorAt??0)>(a.lastErrorAt??0)&&(a.lastErrorAt=r.lastErrorAt,a.lastErrorMessage=r.lastErrorMessage)}return[...e.values()]},"Re"),Pe=h(t=>{let e=new Map;for(let n of t)for(let r of n){let a=e.get(r.id);if(a===void 0){e.set(r.id,r);continue}let c=we[r.status]-we[a.status];(c>0||c===0&&(r.updatedAt??0)>(a.updatedAt??0))&&e.set(r.id,r)}return[...e.values()]},"Me"),Le=X(U.getAuthMetrics),Fe=X(U.getFunctionStats),Re=X(U.getLogs),Oe=X(U.getMetrics),ze=X(U.migrationStatus),$e=5,ke=2e3,Ke=5,Be=.1,Ue=.3,Ge=1,He=50,Qe=h((t,e,n)=>t>=n?"crit":t>=e?"warn":"ok","$e"),Je=h(t=>{let e=new Map;for(let r of t??[]){let a=e.get(r.bucketMs)??{calls:0,errors:0};a.calls+=r.calls,a.errors+=r.errors,e.set(r.bucketMs,a)}let n=[...e.entries()].toSorted((r,a)=>r[0]-a[0]);return{errors:n.map(([,r])=>r.errors),requests:n.map(([,r])=>r.calls)}},"Be"),Ve=h(t=>{let e=0,n=0;for(let a of t)a.status==="failed"?e+=1:a.status==="in_progress"&&(n+=1);let r="ok";return e>0?r="crit":n>0&&(r="warn"),{failed:e,level:r,running:n}},"Ve"),We=h((t,e)=>t.failed>0?e("{count} failed",{count:t.failed.toString()}):t.running>0?e("{count} running",{count:t.running.toString()}):e("OK"),"He"),qe={crit:"bg-destructive",ok:"bg-success",warn:"bg-warning"},Me={crit:"text-destructive",ok:"text-foreground",warn:"text-warning"},Xe={crit:"bg-destructive/10 text-destructive",ok:"bg-success/10 text-success",warn:"bg-warning/10 text-warning"},Ye=h(t=>t.includes("crit")?"crit":t.includes("warn")?"warn":"ok","ze"),ne=h(t=>{let e=(0,te.c)(19),{chart:n,label:r,level:a,testId:c,value:i}=t,o=qe[a],l;e[0]!==o?(l=$("size-1.5 shrink-0 rounded-full",o),e[0]=o,e[1]=l):l=e[1];let u;e[2]!==l?(u=(0,s.jsx)("span",{"aria-hidden":"true",className:l}),e[2]=l,e[3]=u):u=e[3];let f;e[4]!==r||e[5]!==u?(f=(0,s.jsxs)("span",{className:"flex items-center gap-1.5 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:[u,r]}),e[4]=r,e[5]=u,e[6]=f):f=e[6];let v=Me[a],m;e[7]!==v?(m=$("truncate text-2xl font-semibold tabular-nums",v),e[7]=v,e[8]=m):m=e[8];let d;e[9]!==m||e[10]!==c||e[11]!==i?(d=(0,s.jsx)("span",{className:m,"data-testid":c,children:i}),e[9]=m,e[10]=c,e[11]=i,e[12]=d):d=e[12];let g;e[13]!==n||e[14]!==d?(g=(0,s.jsxs)("div",{className:"flex items-center justify-between gap-3",children:[d,n]}),e[13]=n,e[14]=d,e[15]=g):g=e[15];let p;return e[16]!==f||e[17]!==g?(p=(0,s.jsx)(W,{className:"gap-0 py-0",children:(0,s.jsxs)("div",{className:"flex flex-col gap-2.5 p-4",children:[f,g]})}),e[16]=f,e[17]=g,e[18]=p):p=e[18],p},"ee"),Ze=h(async(t,e,n)=>{let r=await Promise.all(n.map(m=>{let d=ie(m);return Promise.allSettled([t.query(Oe,{},d),t.query(Fe,{},d),t.query(ze,{},d)])})),a=ie(e),c=typeof t.schedulerStatus=="function"?t.schedulerStatus():Promise.reject(new Error("scheduler status unavailable")),[i,o,l]=await Promise.allSettled([t.query(Re,{},a),t.query(Le,{},a),c]),u=r.map(([m,d,g])=>({functions:d.status==="fulfilled"?d.value.functions:[],metrics:m.status==="fulfilled"?m.value:null,migrations:g.status==="fulfilled"?g.value.migrations:[]})),f=De(u),v=r[0]?.[0];return{auth:o.status==="fulfilled"?o.value:null,entries:i.status==="fulfilled"?i.value.entries:[],functions:_e(u.map(m=>m.functions)),logsError:i.status==="rejected"?ce(i.reason):null,metricsError:f.reachable===0&&v?.status==="rejected"?ce(v.reason):null,migrations:Pe(u.map(m=>m.migrations)),scheduler:l.status==="fulfilled"?l.value:null,totals:f}},"Qe"),et=h(t=>{let e=t?.history??[];return{attempts:e.map(n=>n.attempts),failures:e.map(n=>n.failures)}},"We"),tt=h((t,e)=>t==="crit"?{description:e("One or more service levels are breached."),label:e("Critical")}:t==="warn"?{description:e("Some service levels need attention."),label:e("Degraded")}:{description:e("All service levels are within target."),label:e("All systems healthy")},"Xe"),rt=h(t=>{let e=(0,te.c)(75),{errorLevel:n,liveError:r,metricsError:a,overall:c,requestSeries:i,totals:o}=t,l=B(),u;e[0]!==c||e[1]!==l?(u=tt(c,l),e[0]=c,e[1]=l,e[2]=u):u=e[2];let{description:f,label:v}=u,m=Xe[c],d;e[3]!==m?(d=$("flex size-10 shrink-0 items-center justify-center rounded-full",m),e[3]=m,e[4]=d):d=e[4];let g=qe[c],p;e[5]!==g?(p=$("size-3 rounded-full",g),e[5]=g,e[6]=p):p=e[6];let S;e[7]!==p?(S=(0,s.jsx)("span",{className:p}),e[7]=p,e[8]=S):S=e[8];let E;e[9]!==d||e[10]!==S?(E=(0,s.jsx)("span",{"aria-hidden":"true",className:d,children:S}),e[9]=d,e[10]=S,e[11]=E):E=e[11];let q;e[12]!==v?(q=(0,s.jsx)("span",{className:"text-sm font-semibold text-foreground","data-testid":"hl-status",children:v}),e[12]=v,e[13]=q):q=e[13];let w;e[14]!==f?(w=(0,s.jsx)("span",{className:"text-[13px] text-muted-foreground",children:f}),e[14]=f,e[15]=w):w=e[15];let k;e[16]!==q||e[17]!==w?(k=(0,s.jsxs)("div",{className:"grid leading-tight",children:[q,w]}),e[16]=q,e[17]=w,e[18]=k):k=e[18];let y;e[19]!==k||e[20]!==E?(y=(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[E,k]}),e[19]=k,e[20]=E,e[21]=y):y=e[21];let j;e[22]!==l?(j=l("Requests"),e[22]=l,e[23]=j):j=e[23];let M;e[24]!==j?(M=(0,s.jsx)("div",{className:"font-mono text-[10px] tracking-wide text-muted-foreground uppercase",children:j}),e[24]=j,e[25]=M):M=e[25];let A;e[26]!==i||e[27]!==l?(A=i.length>=2&&(0,s.jsx)(le,{ariaLabel:l("Requests over time"),className:"h-6 w-20 text-foreground",series:i,testId:"hl-spark-requests"}),e[26]=i,e[27]=l,e[28]=A):A=e[28];let F=o?.requests??0,R;e[29]!==F?(R=F.toString(),e[29]=F,e[30]=R):R=e[30];let D;e[31]!==R?(D=(0,s.jsx)("span",{className:"text-lg font-semibold tabular-nums text-foreground","data-testid":"hl-requests",children:R}),e[31]=R,e[32]=D):D=e[32];let O;e[33]!==A||e[34]!==D?(O=(0,s.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[A,D]}),e[33]=A,e[34]=D,e[35]=O):O=e[35];let _;e[36]!==M||e[37]!==O?(_=(0,s.jsxs)("div",{className:"text-end",children:[M,O]}),e[36]=M,e[37]=O,e[38]=_):_=e[38];let G;e[39]===Symbol.for("react.memo_cache_sentinel")?(G=(0,s.jsx)("span",{"aria-hidden":"true",className:"h-9 w-px bg-border"}),e[39]=G):G=e[39];let T;e[40]!==l?(T=l("Error rate"),e[40]=l,e[41]=T):T=e[41];let P;e[42]!==T?(P=(0,s.jsx)("div",{className:"font-mono text-[10px] tracking-wide text-muted-foreground uppercase",children:T}),e[42]=T,e[43]=P):P=e[43];let Y=Me[n],C;e[44]!==Y?(C=$("text-lg font-semibold tabular-nums",Y),e[44]=Y,e[45]=C):C=e[45];let z;e[46]!==o?(z=o===null?"\u2014":oe(o.errors,o.requests),e[46]=o,e[47]=z):z=e[47];let I;e[48]!==C||e[49]!==z?(I=(0,s.jsx)("div",{className:C,"data-testid":"hl-error-rate",children:z}),e[48]=C,e[49]=z,e[50]=I):I=e[50];let L;e[51]!==P||e[52]!==I?(L=(0,s.jsxs)("div",{className:"text-end",children:[P,I]}),e[51]=P,e[52]=I,e[53]=L):L=e[53];let K;e[54]===Symbol.for("react.memo_cache_sentinel")?(K=(0,s.jsx)("span",{"aria-hidden":"true",className:"h-9 w-px bg-border"}),e[54]=K):K=e[54];let H;e[55]===Symbol.for("react.memo_cache_sentinel")?(H=(0,s.jsx)(ye,{}),e[55]=H):H=e[55];let b;e[56]!==r?(b=(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[H,(0,s.jsx)(ve,{message:r,prefix:"hl"})]}),e[56]=r,e[57]=b):b=e[57];let N;e[58]!==_||e[59]!==L||e[60]!==b?(N=(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-4",children:[_,G,L,K,b]}),e[58]=_,e[59]=L,e[60]=b,e[61]=N):N=e[61];let Q;e[62]!==y||e[63]!==N?(Q=(0,s.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-4 p-4",children:[y,N]}),e[62]=y,e[63]=N,e[64]=Q):Q=e[64];let J;e[65]!==a?(J=a!==null&&(0,s.jsx)("div",{className:"border-t border-border bg-destructive/5 px-4 py-2 text-sm text-destructive","data-testid":"hl-metrics-error",role:"alert",children:a}),e[65]=a,e[66]=J):J=e[66];let V;e[67]!==a||e[68]!==l||e[69]!==o?.historyTruncated?(V=a===null&&o?.historyTruncated===!0&&(0,s.jsx)("div",{className:"border-t border-border bg-warning/5 px-4 py-2 text-sm text-muted-foreground","data-testid":"hl-history-truncated",children:l("Showing a partial request/error history \u2014 one or more shards have more data than the trend chart can display.")}),e[67]=a,e[68]=l,e[69]=o?.historyTruncated,e[70]=V):V=e[70];let re;return e[71]!==Q||e[72]!==J||e[73]!==V?(re=(0,s.jsxs)(W,{className:"gap-0 py-0",children:[Q,J,V]}),e[71]=Q,e[72]=J,e[73]=V,e[74]=re):re=e[74],re},"Je"),st=h(t=>{let e=(0,te.c)(14),{shards:n}=t,r=B(),a;e[0]!==r?(a=r("Shards seen"),e[0]=r,e[1]=a):a=e[1];let c;e[2]!==a?(c=(0,s.jsx)("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:a}),e[2]=a,e[3]=c):c=e[3];let i;e[4]!==n.length?(i=(0,s.jsx)(ee,{"data-testid":"hl-shard-count",variant:"outline",children:n.length}),e[4]=n.length,e[5]=i):i=e[5];let o;e[6]!==c||e[7]!==i?(o=(0,s.jsxs)("header",{className:"flex items-center justify-between gap-2 border-b border-border px-4 py-3",children:[c,i]}),e[6]=c,e[7]=i,e[8]=o):o=e[8];let l;e[9]!==n?(l=n.length>0&&(0,s.jsx)("ul",{className:"flex flex-wrap gap-1.5 p-4",children:n.map(lt)}),e[9]=n,e[10]=l):l=e[10];let u;return e[11]!==o||e[12]!==l?(u=(0,s.jsxs)(W,{className:"gap-0 py-0",children:[o,l]}),e[11]=o,e[12]=l,e[13]=u):u=e[13],u},"Ye"),kt=h(({initialShardKey:t})=>{let e=fe(),n=B(),[r,a]=(0,x.useState)([]),[c,i]=(0,x.useState)(null),[o,l]=(0,x.useState)(null),[u,f]=(0,x.useState)(null),[v,m]=(0,x.useState)([]),[d,g]=(0,x.useState)(null),[p,S]=(0,x.useState)(null),[E,q]=(0,x.useState)([]),[w]=(0,x.useState)(xe),k=(0,x.useRef)(!1),y=(0,x.useRef)(0),j=(0,x.useRef)(0),M=(0,x.useRef)(null),A=t??"",F=(0,x.useCallback)(async()=>{if(k.current)return;k.current=!0;let b=y.current,N=await Ze(e,A,be(A,w));b===y.current&&(l(N.totals),f(N.metricsError),m(N.functions),q(N.migrations),a(N.entries),i(N.logsError),g(N.auth),S(N.scheduler),k.current=!1)},[e,w,A]);(0,x.useEffect)(()=>(se(F()),()=>{y.current+=1,k.current=!1,M.current!==null&&(clearTimeout(M.current),M.current=null)}),[F]);let R=h(()=>{let b=Date.now()-j.current;if(b>=ke){j.current=Date.now(),se(F());return}M.current===null&&(M.current=setTimeout(()=>{M.current=null,j.current=Date.now(),se(F())},ke-b))},"j"),{data:D,liveError:O}=ge(U.getMetrics,{},{live:!0,shardKey:A});(0,x.useEffect)(()=>{D!==void 0&&R()},[D]);let _=r.filter(b=>b.level==="error"),G=_.slice(0,$e),T=Je(o?.history),P=et(d),Y=v.filter(b=>b.calls>0).toSorted((b,N)=>N.errors/N.calls-b.errors/b.calls||N.calls-b.calls).slice(0,Ke),C=Ve(E),z=o===null||o.requests===0?0:o.errors/o.requests,I=de(z,Se,Ee),L=d===null?"ok":de(d.failureRate,Be,Ue),K=p===null?"ok":Qe(p.backlog,Ge,He),H=Ye([I,L,K,C.level]);return(0,s.jsxs)("div",{className:"flex flex-col gap-6","data-testid":"lunora-health",children:[(0,s.jsx)(rt,{errorLevel:I,liveError:O,metricsError:u,overall:H,requestSeries:T.requests,totals:o}),(0,s.jsxs)("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4","data-testid":"hl-slo",children:[(0,s.jsx)(ne,{chart:T.errors.length>=2?(0,s.jsx)(le,{ariaLabel:n("Errors over time"),className:"h-7 w-20 text-destructive",series:T.errors,testId:"hl-spark-errors"}):void 0,label:n("Error rate"),level:I,testId:"hl-slo-errorrate",value:o===null?"\u2014":oe(o.errors,o.requests)}),(0,s.jsx)(ne,{chart:P.failures.length>=2?(0,s.jsx)(le,{ariaLabel:n("Auth failures over time"),className:"h-7 w-20 text-destructive",series:P.failures,testId:"hl-spark-auth"}):void 0,label:n("Auth failures"),level:L,testId:"hl-slo-auth",value:d===null?"\u2014":oe(d.failures,d.attempts)}),(0,s.jsx)(ne,{label:n("Scheduler backlog"),level:K,testId:"hl-slo-backlog",value:p===null?"\u2014":p.backlog.toString()}),(0,s.jsx)(ne,{label:n("Migrations"),level:C.level,testId:"hl-slo-migrations",value:We(C,n)})]}),(0,s.jsx)(Ce,{errorCount:_.length,logsError:c,topErrors:G,worstFunctions:Y}),(0,s.jsx)(st,{shards:w})]})},"gt");function lt(t){return(0,s.jsx)("li",{"data-testid":"hl-shard",children:(0,s.jsx)(ee,{variant:"secondary",children:t})},t)}h(lt,"Ze");export{kt as HealthPanel};
@@ -1 +1 @@
1
- import{a as Ce,b as Ne}from"./chunk-DN3HPAOA.js";import"./chunk-5IIX2STA.js";import{a as ye}from"./chunk-N5FOHLIG.js";import"./chunk-SYGCASPT.js";import"./chunk-ZGSL4DPP.js";import{e as ke,g as we}from"./chunk-6M7FLLMT.js";import"./chunk-ZTOREMGH.js";import"./chunk-IBJVVHV5.js";import{a as X}from"./chunk-2O6KKVH2.js";import"./chunk-JTGGWF7R.js";import"./chunk-ZBON5T5A.js";import"./chunk-4C4THJUD.js";import{a as le}from"./chunk-OSJ7HV7B.js";import{a as pe}from"./chunk-6UTZXEW3.js";import"./chunk-4SJDWMH3.js";import{p as xe}from"./chunk-FKM35PXF.js";import"./chunk-WZTY3ZYI.js";import{a as ge}from"./chunk-3Y5K3IQO.js";import"./chunk-CW57Q264.js";import{a as oe,b as he,c as ue,e as ae}from"./chunk-MD67S53Z.js";import{f as te,h as me,i as ve,j as be,r as fe,s as ne}from"./chunk-LPINY2IJ.js";import{a as g,d as ie,e as Se,f as Ke,g as Me}from"./chunk-OXFKZ4BM.js";var Y=ie(Ke(),1),G=ie(Se(),1);var a=ie(Me(),1);var Le=me(pe.runSql),qe=g((f,e)=>{let t=(0,Y.c)(11),n=xe(),[l,d]=(0,G.useState)(void 0),[s,i]=(0,G.useState)(void 0),[h,x]=(0,G.useState)(!0),m;t[0]!==n||t[1]!==e||t[2]!==f?(m=g(async u=>{x(!0);try{let C=await n.query(Le,{sql:f},ve(e));u.cancelled||(d(C),i(void 0))}catch(C){let k=C;u.cancelled||(d(void 0),i(be(k)))}u.cancelled||x(!1)},"h"),t[0]=n,t[1]=e,t[2]=f,t[3]=m):m=t[3];let r=m,o,v;t[4]!==r?(o=g(()=>{let u={cancelled:!1};return ne(r(u)),()=>{u.cancelled=!0}},"l"),v=[r],t[4]=r,t[5]=o,t[6]=v):(o=t[5],v=t[6]),(0,G.useEffect)(o,v);let S;return t[7]!==s||t[8]!==h||t[9]!==l?(S={error:s,loading:h,result:l},t[7]=s,t[8]=h,t[9]=l,t[10]=S):S=t[10],S},"Le"),Ee=g(f=>{f.preventDefault()},"Me"),ce=g(f=>f.kind??"chart","le"),Re=g(f=>{let e=(0,Y.c)(80),{actions:t,children:n,draggedRef:l,first:d,last:s,onEdit:i,onMove:h,onRemove:x,onReorder:m,widget:r}=f,o=te(),v;e[0]!==h||e[1]!==r.id?(v=g(()=>{h(r.id,-1)},"g"),e[0]=h,e[1]=r.id,e[2]=v):v=e[2];let S=v,u;e[3]!==h||e[4]!==r.id?(u=g(()=>{h(r.id,1)},"f"),e[3]=h,e[4]=r.id,e[5]=u):u=e[5];let C=u,k;e[6]!==i||e[7]!==r.id?(k=g(()=>{i(r.id)},"x"),e[6]=i,e[7]=r.id,e[8]=k):k=e[8];let E=k,O;e[9]!==x||e[10]!==r.id?(O=g(()=>{x(r.id)},"O"),e[9]=x,e[10]=r.id,e[11]=O):O=e[11];let j=O,T;e[12]!==l||e[13]!==r.id?(T=g(()=>{l.current=r.id},"z"),e[12]=l,e[13]=r.id,e[14]=T):T=e[14];let w=T,K;e[15]!==l||e[16]!==m||e[17]!==r.id?(K=g(()=>{let de=l.current;l.current=null,de!==null&&de!==r.id&&m(de,r.id)},"K"),e[15]=l,e[16]=m,e[17]=r.id,e[18]=K):K=e[18];let _=K,R=`dashboards-widget-${r.id}`,y;e[19]!==r.title?(y=(0,a.jsx)(ue,{className:"min-w-0 cursor-grab truncate",title:r.title,children:r.title}),e[19]=r.title,e[20]=y):y=e[20];let N;e[21]!==o?(N=o("Move widget up"),e[21]=o,e[22]=N):N=e[22];let F=`dashboards-move-up-${r.id}`,H;e[23]!==o?(H=o("Move widget up"),e[23]=o,e[24]=H):H=e[24];let D;e[25]===Symbol.for("react.memo_cache_sentinel")?(D=(0,a.jsx)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,a.jsx)("path",{d:"m6 15 6-6 6 6"})}),e[25]=D):D=e[25];let W;e[26]!==d||e[27]!==S||e[28]!==F||e[29]!==H||e[30]!==N?(W=(0,a.jsx)(X,{"aria-label":N,"data-testid":F,disabled:d,onClick:S,size:"icon-xs",title:H,type:"button",variant:"ghost",children:D}),e[26]=d,e[27]=S,e[28]=F,e[29]=H,e[30]=N,e[31]=W):W=e[31];let M;e[32]!==o?(M=o("Move widget down"),e[32]=o,e[33]=M):M=e[33];let $=`dashboards-move-down-${r.id}`,L;e[34]!==o?(L=o("Move widget down"),e[34]=o,e[35]=L):L=e[35];let z;e[36]===Symbol.for("react.memo_cache_sentinel")?(z=(0,a.jsx)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,a.jsx)("path",{d:"m6 9 6 6 6-6"})}),e[36]=z):z=e[36];let q;e[37]!==s||e[38]!==C||e[39]!==M||e[40]!==$||e[41]!==L?(q=(0,a.jsx)(X,{"aria-label":M,"data-testid":$,disabled:s,onClick:C,size:"icon-xs",title:L,type:"button",variant:"ghost",children:z}),e[37]=s,e[38]=C,e[39]=M,e[40]=$,e[41]=L,e[42]=q):q=e[42];let B;e[43]!==o?(B=o("Edit widget"),e[43]=o,e[44]=B):B=e[44];let I=`dashboards-widget-edit-${r.id}`,A;e[45]!==o?(A=o("Edit widget"),e[45]=o,e[46]=A):A=e[46];let p;e[47]===Symbol.for("react.memo_cache_sentinel")?(p=(0,a.jsx)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,a.jsx)("path",{d:"M4 20h4L18 10l-4-4L4 16v4ZM14 6l4 4"})}),e[47]=p):p=e[47];let b;e[48]!==E||e[49]!==B||e[50]!==I||e[51]!==A?(b=(0,a.jsx)(X,{"aria-label":B,"data-testid":I,onClick:E,size:"icon-xs",title:A,type:"button",variant:"ghost",children:p}),e[48]=E,e[49]=B,e[50]=I,e[51]=A,e[52]=b):b=e[52];let c;e[53]!==o?(c=o("Remove widget"),e[53]=o,e[54]=c):c=e[54];let J=`dashboards-widget-remove-${r.id}`,V;e[55]!==o?(V=o("Remove widget"),e[55]=o,e[56]=V):V=e[56];let U;e[57]===Symbol.for("react.memo_cache_sentinel")?(U=(0,a.jsx)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,a.jsx)("path",{d:"M5 7h14M9 7V5h6v2m-1 0v12H10V7M7 7v13h10V7"})}),e[57]=U):U=e[57];let Q;e[58]!==j||e[59]!==c||e[60]!==J||e[61]!==V?(Q=(0,a.jsx)(X,{"aria-label":c,"data-testid":J,onClick:j,size:"icon-xs",title:V,type:"button",variant:"ghost",children:U}),e[58]=j,e[59]=c,e[60]=J,e[61]=V,e[62]=Q):Q=e[62];let Z;e[63]!==t||e[64]!==W||e[65]!==q||e[66]!==b||e[67]!==Q?(Z=(0,a.jsxs)("div",{className:"flex shrink-0 items-center gap-1",children:[t,W,q,b,Q]}),e[63]=t,e[64]=W,e[65]=q,e[66]=b,e[67]=Q,e[68]=Z):Z=e[68];let P;e[69]!==Z||e[70]!==y?(P=(0,a.jsxs)(he,{className:"flex flex-row items-start justify-between gap-2 border-b pb-3",children:[y,Z]}),e[69]=Z,e[70]=y,e[71]=P):P=e[71];let ee;e[72]!==n?(ee=(0,a.jsx)(ae,{className:"min-h-32 py-2",children:n}),e[72]=n,e[73]=ee):ee=e[73];let re;return e[74]!==w||e[75]!==_||e[76]!==P||e[77]!==ee||e[78]!==R?(re=(0,a.jsxs)(oe,{"data-testid":R,draggable:!0,onDragOver:Ee,onDragStart:w,onDrop:_,children:[P,ee]}),e[74]=w,e[75]=_,e[76]=P,e[77]=ee,e[78]=R,e[79]=re):re=e[79],re},"ce"),je=g(f=>{let e=(0,Y.c)(10),{result:t}=f,n=te(),l=t.columns[0],d=l===void 0?void 0:t.rows[0]?.[l],s;e[0]!==d||e[1]!==n?(s=d===void 0?n("\u2014"):fe(d),e[0]=d,e[1]=n,e[2]=s):s=e[2];let i;e[3]!==s?(i=(0,a.jsx)("p",{className:"truncate font-mono text-3xl font-semibold text-foreground",children:s}),e[3]=s,e[4]=i):i=e[4];let h;e[5]!==l?(h=l!==void 0&&(0,a.jsx)("p",{className:"truncate text-xs text-muted-foreground",children:l}),e[5]=l,e[6]=h):h=e[6];let x;return e[7]!==i||e[8]!==h?(x=(0,a.jsxs)("div",{className:"flex h-full flex-col justify-center gap-1 p-4","data-testid":"dashboards-kpi",children:[i,h]}),e[7]=i,e[8]=h,e[9]=x):x=e[9],x},"qe"),ze=g(f=>{let e=(0,Y.c)(12),{draggedRef:t,first:n,last:l,onEdit:d,onMove:s,onRemove:i,onReorder:h,widget:x}=f,m=x.text??"",r;e[0]!==m?(r=(0,a.jsx)("p",{className:"p-2 text-sm whitespace-pre-wrap text-muted-foreground","data-testid":"dashboards-text",children:m}),e[0]=m,e[1]=r):r=e[1];let o;return e[2]!==t||e[3]!==n||e[4]!==l||e[5]!==d||e[6]!==s||e[7]!==i||e[8]!==h||e[9]!==r||e[10]!==x?(o=(0,a.jsx)(Re,{draggedRef:t,first:n,last:l,onEdit:d,onMove:s,onRemove:i,onReorder:h,widget:x,children:r}),e[2]=t,e[3]=n,e[4]=l,e[5]=d,e[6]=s,e[7]=i,e[8]=h,e[9]=r,e[10]=x,e[11]=o):o=e[11],o},"Ee"),Ae=g(f=>{let e=(0,Y.c)(52),{draggedRef:t,first:n,inferring:l,last:d,onEdit:s,onMove:i,onRemove:h,onReorder:x,onSuggest:m,widget:r}=f,o=te(),{error:v,loading:S,result:u}=qe(r.sql,r.shardKey??""),C;e[0]!==r?(C=ce(r),e[0]=r,e[1]=C):C=e[1];let k=C,E;e[2]!==m||e[3]!==u||e[4]!==r.id?(E=g(()=>{u!==void 0&&m?.(r.id,u)},"q"),e[2]=m,e[3]=u,e[4]=r.id,e[5]=E):E=e[5];let O=E,j;e[6]!==l||e[7]!==k||e[8]!==m||e[9]!==O||e[10]!==u||e[11]!==o||e[12]!==r.id?(j=k==="chart"&&m!==void 0&&u!==void 0?(0,a.jsx)(X,{"aria-label":o("Suggest chart"),"data-testid":`dashboards-widget-suggest-${r.id}`,disabled:l,onClick:O,size:"icon-xs",title:o(l?"Suggesting\u2026":"Suggest chart"),type:"button",variant:"ghost",children:(0,a.jsx)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,a.jsx)("path",{d:"m12 3 1.9 4.6L18.5 9.5 13.9 11.4 12 16l-1.9-4.6L5.5 9.5l4.6-1.9L12 3ZM18 15l.9 2.1 2.1.9-2.1.9L18 21l-.9-2.1-2.1-.9 2.1-.9L18 15Z"})})}):void 0,e[6]=l,e[7]=k,e[8]=m,e[9]=O,e[10]=u,e[11]=o,e[12]=r.id,e[13]=j):j=e[13];let T=j,w;e[14]!==v||e[15]!==r.id?(w=v!==void 0&&(0,a.jsx)(le,{className:"font-mono text-xs",testId:`dashboards-widget-error-${r.id}`,variant:"destructive",children:v}),e[14]=v,e[15]=r.id,e[16]=w):w=e[16];let K;e[17]!==v||e[18]!==S||e[19]!==u||e[20]!==o||e[21]!==r.id?(K=v===void 0&&S&&u===void 0&&(0,a.jsx)("p",{className:"p-4 text-sm text-muted-foreground","data-testid":`dashboards-widget-loading-${r.id}`,children:o("Running\u2026")}),e[17]=v,e[18]=S,e[19]=u,e[20]=o,e[21]=r.id,e[22]=K):K=e[22];let _;e[23]!==v||e[24]!==k||e[25]!==u||e[26]!==r.chartAxes||e[27]!==r.chartKind?(_=v===void 0&&u!==void 0&&k==="chart"&&(0,a.jsx)(Ce,{axes:r.chartAxes,kind:r.chartKind,result:u}),e[23]=v,e[24]=k,e[25]=u,e[26]=r.chartAxes,e[27]=r.chartKind,e[28]=_):_=e[28];let R;e[29]!==v||e[30]!==k||e[31]!==u?(R=v===void 0&&u!==void 0&&k==="kpi"&&(0,a.jsx)(je,{result:u}),e[29]=v,e[30]=k,e[31]=u,e[32]=R):R=e[32];let y;e[33]!==v||e[34]!==k||e[35]!==u?(y=v===void 0&&u!==void 0&&k==="table"&&(0,a.jsx)("div",{className:"max-h-72 overflow-auto",children:(0,a.jsx)(Ne,{result:u})}),e[33]=v,e[34]=k,e[35]=u,e[36]=y):y=e[36];let N;return e[37]!==t||e[38]!==n||e[39]!==d||e[40]!==s||e[41]!==i||e[42]!==h||e[43]!==x||e[44]!==T||e[45]!==w||e[46]!==K||e[47]!==_||e[48]!==R||e[49]!==y||e[50]!==r?(N=(0,a.jsxs)(Re,{actions:T,draggedRef:t,first:n,last:d,onEdit:s,onMove:i,onRemove:h,onReorder:x,widget:r,children:[w,K,_,R,y]}),e[37]=t,e[38]=n,e[39]=d,e[40]=s,e[41]=i,e[42]=h,e[43]=x,e[44]=T,e[45]=w,e[46]=K,e[47]=_,e[48]=R,e[49]=y,e[50]=r,e[51]=N):N=e[51],N},"Ae"),_e=g(f=>{let e=(0,Y.c)(11),{draggedRef:t,first:n,inferring:l,last:d,onEdit:s,onMove:i,onRemove:h,onReorder:x,onSuggest:m,widget:r}=f,o;return e[0]!==t||e[1]!==n||e[2]!==l||e[3]!==d||e[4]!==s||e[5]!==i||e[6]!==h||e[7]!==x||e[8]!==m||e[9]!==r?(o=ce(r)==="text"?(0,a.jsx)(ze,{draggedRef:t,first:n,last:d,onEdit:s,onMove:i,onRemove:h,onReorder:x,widget:r}):(0,a.jsx)(Ae,{draggedRef:t,first:n,inferring:l,last:d,onEdit:s,onMove:i,onRemove:h,onReorder:x,onSuggest:m,widget:r}),e[0]=t,e[1]=n,e[2]=l,e[3]=d,e[4]=s,e[5]=i,e[6]=h,e[7]=x,e[8]=m,e[9]=r,e[10]=o):o=e[10],o},"Te"),We=["bar","line","area"],$e=["chart","kpi","table","text"],Be="lunora-studio-dashboards",se={chartKind:"bar",kind:"chart",shardKey:"",sql:"",text:"",title:""},Ie=g((f,e)=>t=>t.map(n=>n.id===f?{...n,chartAxes:e,chartKind:e.kind}:n),"De"),Te=g((f,e)=>t=>{let n=t.find(s=>s.id===f),l=t.filter(s=>s.id!==f),d=l.findIndex(s=>s.id===e);return n===void 0||d===-1?t:[...l.slice(0,d),n,...l.slice(d)]},"je"),De=g((f,e)=>e(f==="line"?"Line":f==="area"?"Area":"Bar"),"ze"),Oe=g((f,e)=>e(f==="kpi"?"Single value":f==="table"?"Table":f==="text"?"Text":"Chart"),"Be"),Fe=g(f=>{let e=(0,Y.c)(82),{draft:t,editing:n,onCancel:l,onChange:d,onSubmit:s}=f,i=te(),h;e[0]!==t||e[1]!==d?(h=g(c=>{d({...t,title:c.target.value})},"c"),e[0]=t,e[1]=d,e[2]=h):h=e[2];let x=h,m;e[3]!==t||e[4]!==d?(m=g(c=>{d({...t,sql:c.target.value})},"h"),e[3]=t,e[4]=d,e[5]=m):m=e[5];let r=m,o;e[6]!==t||e[7]!==d?(o=g(c=>{d({...t,text:c.target.value})},"l"),e[6]=t,e[7]=d,e[8]=o):o=e[8];let v=o,S;e[9]!==t||e[10]!==d?(S=g(c=>{d({...t,shardKey:c.target.value})},"N"),e[9]=t,e[10]=d,e[11]=S):S=e[11];let u=S,C;e[12]!==t||e[13]!==d?(C=g(c=>{d({...t,chartKind:c.target.value})},"y"),e[12]=t,e[13]=d,e[14]=C):C=e[14];let k=C,E;e[15]!==t||e[16]!==d?(E=g(c=>{d({...t,kind:c.target.value})},"q"),e[15]=t,e[16]=d,e[17]=E):E=e[17];let O=E,j;e[18]!==s?(j=g(()=>{s()},"E"),e[18]=s,e[19]=j):j=e[19];let T=j,w=t.kind==="text",K;e[20]!==t.sql||e[21]!==t.text||e[22]!==t.title||e[23]!==w?(K=t.title.trim()!==""&&(w?t.text.trim()!=="":t.sql.trim()!==""),e[20]=t.sql,e[21]=t.text,e[22]=t.title,e[23]=w,e[24]=K):K=e[24];let _=K,R;e[25]!==i?(R=i("Widget title"),e[25]=i,e[26]=R):R=e[26];let y;e[27]!==i?(y=i("Widget title"),e[27]=i,e[28]=y):y=e[28];let N;e[29]!==t.title||e[30]!==x||e[31]!==y||e[32]!==R?(N=(0,a.jsx)("input",{"aria-label":R,className:"h-8 rounded-md border border-border bg-background px-2 text-xs outline-none focus-visible:border-ring","data-testid":"dashboards-form-title",onChange:x,placeholder:y,type:"text",value:t.title}),e[29]=t.title,e[30]=x,e[31]=y,e[32]=R,e[33]=N):N=e[33];let F;e[34]!==i?(F=i("Widget type"),e[34]=i,e[35]=F):F=e[35];let H=t.kind,D;e[36]!==i?(D=$e.map(c=>(0,a.jsx)("option",{value:c,children:Oe(c,i)},c)),e[36]=i,e[37]=D):D=e[37];let W;e[38]!==t.kind||e[39]!==O||e[40]!==F||e[41]!==D?(W=(0,a.jsx)("select",{"aria-label":F,className:"h-8 rounded-md border border-border bg-background px-2 text-xs outline-none focus-visible:border-ring","data-testid":"dashboards-form-widget-kind",onChange:O,value:H,children:D}),e[38]=t.kind,e[39]=O,e[40]=F,e[41]=D,e[42]=W):W=e[42];let M;e[43]!==t.sql||e[44]!==t.text||e[45]!==w||e[46]!==r||e[47]!==v||e[48]!==i?(M=w?(0,a.jsx)("textarea",{"aria-label":i("Text"),className:"min-h-24 resize-y rounded-md border border-border bg-background p-2 text-xs leading-5 outline-none focus-visible:border-ring","data-testid":"dashboards-form-text",onChange:v,placeholder:i("Notes for whoever reads this dashboard."),value:t.text}):(0,a.jsx)("textarea",{"aria-label":i("SQL query"),className:"min-h-24 resize-y rounded-md border border-border bg-background p-2 font-mono text-xs leading-5 outline-none focus-visible:border-ring","data-testid":"dashboards-form-sql",onChange:r,placeholder:"SELECT author, COUNT(*) AS messages FROM \u2026",spellCheck:!1,value:t.sql}),e[43]=t.sql,e[44]=t.text,e[45]=w,e[46]=r,e[47]=v,e[48]=i,e[49]=M):M=e[49];let $;e[50]!==t.chartKind||e[51]!==t.kind||e[52]!==k||e[53]!==i?($=t.kind==="chart"&&(0,a.jsx)("select",{"aria-label":i("Chart type"),className:"h-8 rounded-md border border-border bg-background px-2 text-xs outline-none focus-visible:border-ring","data-testid":"dashboards-form-kind",onChange:k,value:t.chartKind,children:We.map(c=>(0,a.jsx)("option",{value:c,children:De(c,i)},c))}),e[50]=t.chartKind,e[51]=t.kind,e[52]=k,e[53]=i,e[54]=$):$=e[54];let L;e[55]!==t.shardKey||e[56]!==w||e[57]!==u||e[58]!==i?(L=!w&&(0,a.jsx)("input",{"aria-label":i("Shard key (optional)"),className:"h-8 rounded-md border border-border bg-background px-2 font-mono text-xs outline-none focus-visible:border-ring","data-testid":"dashboards-form-shard",onChange:u,placeholder:i("Shard key (optional)"),type:"text",value:t.shardKey}),e[55]=t.shardKey,e[56]=w,e[57]=u,e[58]=i,e[59]=L):L=e[59];let z;e[60]!==i?(z=i("Cancel"),e[60]=i,e[61]=z):z=e[61];let q;e[62]!==l||e[63]!==z?(q=(0,a.jsx)(X,{"data-testid":"dashboards-form-cancel",onClick:l,size:"sm",type:"button",variant:"outline",children:z}),e[62]=l,e[63]=z,e[64]=q):q=e[64];let B=!_,I;e[65]!==n||e[66]!==i?(I=i(n?"Save widget":"Add widget"),e[65]=n,e[66]=i,e[67]=I):I=e[67];let A;e[68]!==T||e[69]!==B||e[70]!==I?(A=(0,a.jsx)(X,{"data-testid":"dashboards-form-save",disabled:B,onClick:T,size:"sm",type:"button",children:I}),e[68]=T,e[69]=B,e[70]=I,e[71]=A):A=e[71];let p;e[72]!==q||e[73]!==A?(p=(0,a.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[q,A]}),e[72]=q,e[73]=A,e[74]=p):p=e[74];let b;return e[75]!==N||e[76]!==W||e[77]!==M||e[78]!==$||e[79]!==L||e[80]!==p?(b=(0,a.jsx)(oe,{"data-testid":"dashboards-form",children:(0,a.jsxs)(ae,{className:"flex flex-col gap-3 py-4",children:[N,W,M,$,L,p]})}),e[75]=N,e[76]=W,e[77]=M,e[78]=$,e[79]=L,e[80]=p,e[81]=b):b=e[81],b},"Fe"),tt=g(f=>{let e=(0,Y.c)(53),{initialShardKey:t}=f,n=te(),[l,d]=ke(Be),[s,i]=(0,G.useState)(se),[h,x]=(0,G.useState)(null),[m,r]=(0,G.useState)(!1),o=ye(t??""),[v,S]=(0,G.useState)(null),u=(0,G.useRef)(null),C;e[0]!==t?(C=g(()=>{x(null),i({...se,shardKey:t??""}),r(!0)},"y"),e[0]=t,e[1]=C):C=e[1];let k=C,E;e[2]===Symbol.for("react.memo_cache_sentinel")?(E=g(()=>{r(!1),x(null),i(se)},"q"),e[2]=E):E=e[2];let O=E,j;e[3]!==l?(j=g(p=>{let b=l.find(c=>c.id===p);b!==void 0&&(x(p),i({chartKind:b.chartKind??"bar",kind:ce(b),shardKey:b.shardKey??"",sql:b.sql,text:b.text??"",title:b.title}),r(!0))},"E"),e[3]=l,e[4]=j):j=e[4];let T=j,w;e[5]!==o||e[6]!==d?(w=g((p,b)=>{S(p),ne((async()=>{let c=await o.inferChart({columns:b.columns,rowCount:b.rowCount});c!==void 0&&d(Ie(p,c))})().finally(()=>{S(c=>c===p?null:c)}))},"C"),e[5]=o,e[6]=d,e[7]=w):w=e[7];let K=w,_;e[8]!==d?(_=g(p=>{d(b=>b.filter(c=>c.id!==p))},"W"),e[8]=d,e[9]=_):_=e[9];let R=_,y;e[10]!==d?(y=g((p,b)=>{d(Te(p,b))},"k"),e[10]=d,e[11]=y):y=e[11];let N=y,F;e[12]!==d?(F=g((p,b)=>{d(c=>{let J=c.findIndex(P=>P.id===p),V=J+b;if(J===-1||V<0||V>=c.length)return c;let U=[...c],Q=U[J],Z=U[V];return Q===void 0||Z===void 0?c:(U[J]=Z,U[V]=Q,U)})},"_"),e[12]=d,e[13]=F):F=e[13];let H=F,D;e[14]!==s||e[15]!==h||e[16]!==d?(D=g(()=>{let p=s.title.trim(),b=s.sql.trim(),c=s.text.trim(),{chartKind:J,kind:V}=s;if(p===""||(V==="text"?c==="":b===""))return;let U={chartKind:J,kind:V,shardKey:s.shardKey.trim(),sql:b,text:c,title:p};d(h===null?Q=>[...Q,{...U,id:we("w")}]:Q=>Q.map(Z=>Z.id===h?{...Z,...U}:Z)),O()},"B"),e[14]=s,e[15]=h,e[16]=d,e[17]=D):D=e[17];let W=D,M;e[18]!==n?(M=n("Charts, values, tables, and notes. Drag a tile to reorder."),e[18]=n,e[19]=M):M=e[19];let $;e[20]!==M?($=(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:M}),e[20]=M,e[21]=$):$=e[21];let L;e[22]!==m||e[23]!==k||e[24]!==n?(L=!m&&(0,a.jsx)(X,{"data-testid":"dashboards-add",onClick:k,size:"sm",type:"button",children:n("Add widget")}),e[22]=m,e[23]=k,e[24]=n,e[25]=L):L=e[25];let z;e[26]!==$||e[27]!==L?(z=(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[$,L]}),e[26]=$,e[27]=L,e[28]=z):z=e[28];let q;e[29]!==o||e[30]!==n?(q=o.reason("chart")!==void 0&&(0,a.jsx)(le,{className:"text-xs",testId:"dashboards-suggest-error",variant:"destructive",children:n("Could not suggest a chart for that result.")}),e[29]=o,e[30]=n,e[31]=q):q=e[31];let B;e[32]!==s||e[33]!==h||e[34]!==m||e[35]!==W?(B=m&&(0,a.jsx)(Fe,{draft:s,editing:h!==null,onCancel:O,onChange:i,onSubmit:W}),e[32]=s,e[33]=h,e[34]=m,e[35]=W,e[36]=B):B=e[36];let I;e[37]!==o.unavailable||e[38]!==m||e[39]!==v||e[40]!==T||e[41]!==H||e[42]!==R||e[43]!==N||e[44]!==K||e[45]!==n||e[46]!==l?(I=l.length===0&&!m?(0,a.jsx)(ge,{description:n("Add a chart, a single value, a table, or a note. Everything is saved on this browser."),testId:"dashboards-empty",title:n("No widgets yet")}):(0,a.jsx)("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-2 xl:grid-cols-3","data-testid":"dashboards-grid",children:l.map((p,b)=>(0,a.jsx)(_e,{draggedRef:u,first:b===0,inferring:v===p.id,last:b===l.length-1,onEdit:T,onMove:H,onRemove:R,onReorder:N,onSuggest:o.unavailable?void 0:K,widget:p},p.id))}),e[37]=o.unavailable,e[38]=m,e[39]=v,e[40]=T,e[41]=H,e[42]=R,e[43]=N,e[44]=K,e[45]=n,e[46]=l,e[47]=I):I=e[47];let A;return e[48]!==z||e[49]!==q||e[50]!==B||e[51]!==I?(A=(0,a.jsxs)("div",{className:"flex flex-col gap-4","data-testid":"lunora-dashboards",children:[z,q,B,I]}),e[48]=z,e[49]=q,e[50]=B,e[51]=I,e[52]=A):A=e[52],A},"it");export{tt as default};
1
+ import{a as Ce,b as Ne}from"./chunk-BCP3MEB3.js";import"./chunk-ZFFZWSDJ.js";import{a as ye}from"./chunk-EAZXULX6.js";import"./chunk-SYGCASPT.js";import"./chunk-ZGSL4DPP.js";import{e as ke,g as we}from"./chunk-6M7FLLMT.js";import"./chunk-ZTOREMGH.js";import"./chunk-IBJVVHV5.js";import{a as X}from"./chunk-2O6KKVH2.js";import"./chunk-JTGGWF7R.js";import"./chunk-ZBON5T5A.js";import"./chunk-4C4THJUD.js";import{a as le}from"./chunk-OSJ7HV7B.js";import{a as pe}from"./chunk-6UTZXEW3.js";import"./chunk-W37HRJGQ.js";import{p as xe}from"./chunk-SDSQIQJG.js";import"./chunk-WZTY3ZYI.js";import{a as ge}from"./chunk-3Y5K3IQO.js";import"./chunk-CW57Q264.js";import{a as oe,b as he,c as ue,e as ae}from"./chunk-MD67S53Z.js";import{f as te,h as me,i as ve,j as be,r as fe,s as ne}from"./chunk-LPINY2IJ.js";import{a as g,d as ie,e as Se,f as Ke,g as Me}from"./chunk-OXFKZ4BM.js";var Y=ie(Ke(),1),G=ie(Se(),1);var a=ie(Me(),1);var Le=me(pe.runSql),qe=g((f,e)=>{let t=(0,Y.c)(11),n=xe(),[l,d]=(0,G.useState)(void 0),[s,i]=(0,G.useState)(void 0),[h,x]=(0,G.useState)(!0),m;t[0]!==n||t[1]!==e||t[2]!==f?(m=g(async u=>{x(!0);try{let C=await n.query(Le,{sql:f},ve(e));u.cancelled||(d(C),i(void 0))}catch(C){let k=C;u.cancelled||(d(void 0),i(be(k)))}u.cancelled||x(!1)},"h"),t[0]=n,t[1]=e,t[2]=f,t[3]=m):m=t[3];let r=m,o,v;t[4]!==r?(o=g(()=>{let u={cancelled:!1};return ne(r(u)),()=>{u.cancelled=!0}},"l"),v=[r],t[4]=r,t[5]=o,t[6]=v):(o=t[5],v=t[6]),(0,G.useEffect)(o,v);let S;return t[7]!==s||t[8]!==h||t[9]!==l?(S={error:s,loading:h,result:l},t[7]=s,t[8]=h,t[9]=l,t[10]=S):S=t[10],S},"Le"),Ee=g(f=>{f.preventDefault()},"Me"),ce=g(f=>f.kind??"chart","le"),Re=g(f=>{let e=(0,Y.c)(80),{actions:t,children:n,draggedRef:l,first:d,last:s,onEdit:i,onMove:h,onRemove:x,onReorder:m,widget:r}=f,o=te(),v;e[0]!==h||e[1]!==r.id?(v=g(()=>{h(r.id,-1)},"g"),e[0]=h,e[1]=r.id,e[2]=v):v=e[2];let S=v,u;e[3]!==h||e[4]!==r.id?(u=g(()=>{h(r.id,1)},"f"),e[3]=h,e[4]=r.id,e[5]=u):u=e[5];let C=u,k;e[6]!==i||e[7]!==r.id?(k=g(()=>{i(r.id)},"x"),e[6]=i,e[7]=r.id,e[8]=k):k=e[8];let E=k,O;e[9]!==x||e[10]!==r.id?(O=g(()=>{x(r.id)},"O"),e[9]=x,e[10]=r.id,e[11]=O):O=e[11];let j=O,T;e[12]!==l||e[13]!==r.id?(T=g(()=>{l.current=r.id},"z"),e[12]=l,e[13]=r.id,e[14]=T):T=e[14];let w=T,K;e[15]!==l||e[16]!==m||e[17]!==r.id?(K=g(()=>{let de=l.current;l.current=null,de!==null&&de!==r.id&&m(de,r.id)},"K"),e[15]=l,e[16]=m,e[17]=r.id,e[18]=K):K=e[18];let _=K,R=`dashboards-widget-${r.id}`,y;e[19]!==r.title?(y=(0,a.jsx)(ue,{className:"min-w-0 cursor-grab truncate",title:r.title,children:r.title}),e[19]=r.title,e[20]=y):y=e[20];let N;e[21]!==o?(N=o("Move widget up"),e[21]=o,e[22]=N):N=e[22];let F=`dashboards-move-up-${r.id}`,H;e[23]!==o?(H=o("Move widget up"),e[23]=o,e[24]=H):H=e[24];let D;e[25]===Symbol.for("react.memo_cache_sentinel")?(D=(0,a.jsx)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,a.jsx)("path",{d:"m6 15 6-6 6 6"})}),e[25]=D):D=e[25];let W;e[26]!==d||e[27]!==S||e[28]!==F||e[29]!==H||e[30]!==N?(W=(0,a.jsx)(X,{"aria-label":N,"data-testid":F,disabled:d,onClick:S,size:"icon-xs",title:H,type:"button",variant:"ghost",children:D}),e[26]=d,e[27]=S,e[28]=F,e[29]=H,e[30]=N,e[31]=W):W=e[31];let M;e[32]!==o?(M=o("Move widget down"),e[32]=o,e[33]=M):M=e[33];let $=`dashboards-move-down-${r.id}`,L;e[34]!==o?(L=o("Move widget down"),e[34]=o,e[35]=L):L=e[35];let z;e[36]===Symbol.for("react.memo_cache_sentinel")?(z=(0,a.jsx)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,a.jsx)("path",{d:"m6 9 6 6 6-6"})}),e[36]=z):z=e[36];let q;e[37]!==s||e[38]!==C||e[39]!==M||e[40]!==$||e[41]!==L?(q=(0,a.jsx)(X,{"aria-label":M,"data-testid":$,disabled:s,onClick:C,size:"icon-xs",title:L,type:"button",variant:"ghost",children:z}),e[37]=s,e[38]=C,e[39]=M,e[40]=$,e[41]=L,e[42]=q):q=e[42];let B;e[43]!==o?(B=o("Edit widget"),e[43]=o,e[44]=B):B=e[44];let I=`dashboards-widget-edit-${r.id}`,A;e[45]!==o?(A=o("Edit widget"),e[45]=o,e[46]=A):A=e[46];let p;e[47]===Symbol.for("react.memo_cache_sentinel")?(p=(0,a.jsx)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,a.jsx)("path",{d:"M4 20h4L18 10l-4-4L4 16v4ZM14 6l4 4"})}),e[47]=p):p=e[47];let b;e[48]!==E||e[49]!==B||e[50]!==I||e[51]!==A?(b=(0,a.jsx)(X,{"aria-label":B,"data-testid":I,onClick:E,size:"icon-xs",title:A,type:"button",variant:"ghost",children:p}),e[48]=E,e[49]=B,e[50]=I,e[51]=A,e[52]=b):b=e[52];let c;e[53]!==o?(c=o("Remove widget"),e[53]=o,e[54]=c):c=e[54];let J=`dashboards-widget-remove-${r.id}`,V;e[55]!==o?(V=o("Remove widget"),e[55]=o,e[56]=V):V=e[56];let U;e[57]===Symbol.for("react.memo_cache_sentinel")?(U=(0,a.jsx)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,a.jsx)("path",{d:"M5 7h14M9 7V5h6v2m-1 0v12H10V7M7 7v13h10V7"})}),e[57]=U):U=e[57];let Q;e[58]!==j||e[59]!==c||e[60]!==J||e[61]!==V?(Q=(0,a.jsx)(X,{"aria-label":c,"data-testid":J,onClick:j,size:"icon-xs",title:V,type:"button",variant:"ghost",children:U}),e[58]=j,e[59]=c,e[60]=J,e[61]=V,e[62]=Q):Q=e[62];let Z;e[63]!==t||e[64]!==W||e[65]!==q||e[66]!==b||e[67]!==Q?(Z=(0,a.jsxs)("div",{className:"flex shrink-0 items-center gap-1",children:[t,W,q,b,Q]}),e[63]=t,e[64]=W,e[65]=q,e[66]=b,e[67]=Q,e[68]=Z):Z=e[68];let P;e[69]!==Z||e[70]!==y?(P=(0,a.jsxs)(he,{className:"flex flex-row items-start justify-between gap-2 border-b pb-3",children:[y,Z]}),e[69]=Z,e[70]=y,e[71]=P):P=e[71];let ee;e[72]!==n?(ee=(0,a.jsx)(ae,{className:"min-h-32 py-2",children:n}),e[72]=n,e[73]=ee):ee=e[73];let re;return e[74]!==w||e[75]!==_||e[76]!==P||e[77]!==ee||e[78]!==R?(re=(0,a.jsxs)(oe,{"data-testid":R,draggable:!0,onDragOver:Ee,onDragStart:w,onDrop:_,children:[P,ee]}),e[74]=w,e[75]=_,e[76]=P,e[77]=ee,e[78]=R,e[79]=re):re=e[79],re},"ce"),je=g(f=>{let e=(0,Y.c)(10),{result:t}=f,n=te(),l=t.columns[0],d=l===void 0?void 0:t.rows[0]?.[l],s;e[0]!==d||e[1]!==n?(s=d===void 0?n("\u2014"):fe(d),e[0]=d,e[1]=n,e[2]=s):s=e[2];let i;e[3]!==s?(i=(0,a.jsx)("p",{className:"truncate font-mono text-3xl font-semibold text-foreground",children:s}),e[3]=s,e[4]=i):i=e[4];let h;e[5]!==l?(h=l!==void 0&&(0,a.jsx)("p",{className:"truncate text-xs text-muted-foreground",children:l}),e[5]=l,e[6]=h):h=e[6];let x;return e[7]!==i||e[8]!==h?(x=(0,a.jsxs)("div",{className:"flex h-full flex-col justify-center gap-1 p-4","data-testid":"dashboards-kpi",children:[i,h]}),e[7]=i,e[8]=h,e[9]=x):x=e[9],x},"qe"),ze=g(f=>{let e=(0,Y.c)(12),{draggedRef:t,first:n,last:l,onEdit:d,onMove:s,onRemove:i,onReorder:h,widget:x}=f,m=x.text??"",r;e[0]!==m?(r=(0,a.jsx)("p",{className:"p-2 text-sm whitespace-pre-wrap text-muted-foreground","data-testid":"dashboards-text",children:m}),e[0]=m,e[1]=r):r=e[1];let o;return e[2]!==t||e[3]!==n||e[4]!==l||e[5]!==d||e[6]!==s||e[7]!==i||e[8]!==h||e[9]!==r||e[10]!==x?(o=(0,a.jsx)(Re,{draggedRef:t,first:n,last:l,onEdit:d,onMove:s,onRemove:i,onReorder:h,widget:x,children:r}),e[2]=t,e[3]=n,e[4]=l,e[5]=d,e[6]=s,e[7]=i,e[8]=h,e[9]=r,e[10]=x,e[11]=o):o=e[11],o},"Ee"),Ae=g(f=>{let e=(0,Y.c)(52),{draggedRef:t,first:n,inferring:l,last:d,onEdit:s,onMove:i,onRemove:h,onReorder:x,onSuggest:m,widget:r}=f,o=te(),{error:v,loading:S,result:u}=qe(r.sql,r.shardKey??""),C;e[0]!==r?(C=ce(r),e[0]=r,e[1]=C):C=e[1];let k=C,E;e[2]!==m||e[3]!==u||e[4]!==r.id?(E=g(()=>{u!==void 0&&m?.(r.id,u)},"q"),e[2]=m,e[3]=u,e[4]=r.id,e[5]=E):E=e[5];let O=E,j;e[6]!==l||e[7]!==k||e[8]!==m||e[9]!==O||e[10]!==u||e[11]!==o||e[12]!==r.id?(j=k==="chart"&&m!==void 0&&u!==void 0?(0,a.jsx)(X,{"aria-label":o("Suggest chart"),"data-testid":`dashboards-widget-suggest-${r.id}`,disabled:l,onClick:O,size:"icon-xs",title:o(l?"Suggesting\u2026":"Suggest chart"),type:"button",variant:"ghost",children:(0,a.jsx)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,a.jsx)("path",{d:"m12 3 1.9 4.6L18.5 9.5 13.9 11.4 12 16l-1.9-4.6L5.5 9.5l4.6-1.9L12 3ZM18 15l.9 2.1 2.1.9-2.1.9L18 21l-.9-2.1-2.1-.9 2.1-.9L18 15Z"})})}):void 0,e[6]=l,e[7]=k,e[8]=m,e[9]=O,e[10]=u,e[11]=o,e[12]=r.id,e[13]=j):j=e[13];let T=j,w;e[14]!==v||e[15]!==r.id?(w=v!==void 0&&(0,a.jsx)(le,{className:"font-mono text-xs",testId:`dashboards-widget-error-${r.id}`,variant:"destructive",children:v}),e[14]=v,e[15]=r.id,e[16]=w):w=e[16];let K;e[17]!==v||e[18]!==S||e[19]!==u||e[20]!==o||e[21]!==r.id?(K=v===void 0&&S&&u===void 0&&(0,a.jsx)("p",{className:"p-4 text-sm text-muted-foreground","data-testid":`dashboards-widget-loading-${r.id}`,children:o("Running\u2026")}),e[17]=v,e[18]=S,e[19]=u,e[20]=o,e[21]=r.id,e[22]=K):K=e[22];let _;e[23]!==v||e[24]!==k||e[25]!==u||e[26]!==r.chartAxes||e[27]!==r.chartKind?(_=v===void 0&&u!==void 0&&k==="chart"&&(0,a.jsx)(Ce,{axes:r.chartAxes,kind:r.chartKind,result:u}),e[23]=v,e[24]=k,e[25]=u,e[26]=r.chartAxes,e[27]=r.chartKind,e[28]=_):_=e[28];let R;e[29]!==v||e[30]!==k||e[31]!==u?(R=v===void 0&&u!==void 0&&k==="kpi"&&(0,a.jsx)(je,{result:u}),e[29]=v,e[30]=k,e[31]=u,e[32]=R):R=e[32];let y;e[33]!==v||e[34]!==k||e[35]!==u?(y=v===void 0&&u!==void 0&&k==="table"&&(0,a.jsx)("div",{className:"max-h-72 overflow-auto",children:(0,a.jsx)(Ne,{result:u})}),e[33]=v,e[34]=k,e[35]=u,e[36]=y):y=e[36];let N;return e[37]!==t||e[38]!==n||e[39]!==d||e[40]!==s||e[41]!==i||e[42]!==h||e[43]!==x||e[44]!==T||e[45]!==w||e[46]!==K||e[47]!==_||e[48]!==R||e[49]!==y||e[50]!==r?(N=(0,a.jsxs)(Re,{actions:T,draggedRef:t,first:n,last:d,onEdit:s,onMove:i,onRemove:h,onReorder:x,widget:r,children:[w,K,_,R,y]}),e[37]=t,e[38]=n,e[39]=d,e[40]=s,e[41]=i,e[42]=h,e[43]=x,e[44]=T,e[45]=w,e[46]=K,e[47]=_,e[48]=R,e[49]=y,e[50]=r,e[51]=N):N=e[51],N},"Ae"),_e=g(f=>{let e=(0,Y.c)(11),{draggedRef:t,first:n,inferring:l,last:d,onEdit:s,onMove:i,onRemove:h,onReorder:x,onSuggest:m,widget:r}=f,o;return e[0]!==t||e[1]!==n||e[2]!==l||e[3]!==d||e[4]!==s||e[5]!==i||e[6]!==h||e[7]!==x||e[8]!==m||e[9]!==r?(o=ce(r)==="text"?(0,a.jsx)(ze,{draggedRef:t,first:n,last:d,onEdit:s,onMove:i,onRemove:h,onReorder:x,widget:r}):(0,a.jsx)(Ae,{draggedRef:t,first:n,inferring:l,last:d,onEdit:s,onMove:i,onRemove:h,onReorder:x,onSuggest:m,widget:r}),e[0]=t,e[1]=n,e[2]=l,e[3]=d,e[4]=s,e[5]=i,e[6]=h,e[7]=x,e[8]=m,e[9]=r,e[10]=o):o=e[10],o},"Te"),We=["bar","line","area"],$e=["chart","kpi","table","text"],Be="lunora-studio-dashboards",se={chartKind:"bar",kind:"chart",shardKey:"",sql:"",text:"",title:""},Ie=g((f,e)=>t=>t.map(n=>n.id===f?{...n,chartAxes:e,chartKind:e.kind}:n),"De"),Te=g((f,e)=>t=>{let n=t.find(s=>s.id===f),l=t.filter(s=>s.id!==f),d=l.findIndex(s=>s.id===e);return n===void 0||d===-1?t:[...l.slice(0,d),n,...l.slice(d)]},"je"),De=g((f,e)=>e(f==="line"?"Line":f==="area"?"Area":"Bar"),"ze"),Oe=g((f,e)=>e(f==="kpi"?"Single value":f==="table"?"Table":f==="text"?"Text":"Chart"),"Be"),Fe=g(f=>{let e=(0,Y.c)(82),{draft:t,editing:n,onCancel:l,onChange:d,onSubmit:s}=f,i=te(),h;e[0]!==t||e[1]!==d?(h=g(c=>{d({...t,title:c.target.value})},"c"),e[0]=t,e[1]=d,e[2]=h):h=e[2];let x=h,m;e[3]!==t||e[4]!==d?(m=g(c=>{d({...t,sql:c.target.value})},"h"),e[3]=t,e[4]=d,e[5]=m):m=e[5];let r=m,o;e[6]!==t||e[7]!==d?(o=g(c=>{d({...t,text:c.target.value})},"l"),e[6]=t,e[7]=d,e[8]=o):o=e[8];let v=o,S;e[9]!==t||e[10]!==d?(S=g(c=>{d({...t,shardKey:c.target.value})},"N"),e[9]=t,e[10]=d,e[11]=S):S=e[11];let u=S,C;e[12]!==t||e[13]!==d?(C=g(c=>{d({...t,chartKind:c.target.value})},"y"),e[12]=t,e[13]=d,e[14]=C):C=e[14];let k=C,E;e[15]!==t||e[16]!==d?(E=g(c=>{d({...t,kind:c.target.value})},"q"),e[15]=t,e[16]=d,e[17]=E):E=e[17];let O=E,j;e[18]!==s?(j=g(()=>{s()},"E"),e[18]=s,e[19]=j):j=e[19];let T=j,w=t.kind==="text",K;e[20]!==t.sql||e[21]!==t.text||e[22]!==t.title||e[23]!==w?(K=t.title.trim()!==""&&(w?t.text.trim()!=="":t.sql.trim()!==""),e[20]=t.sql,e[21]=t.text,e[22]=t.title,e[23]=w,e[24]=K):K=e[24];let _=K,R;e[25]!==i?(R=i("Widget title"),e[25]=i,e[26]=R):R=e[26];let y;e[27]!==i?(y=i("Widget title"),e[27]=i,e[28]=y):y=e[28];let N;e[29]!==t.title||e[30]!==x||e[31]!==y||e[32]!==R?(N=(0,a.jsx)("input",{"aria-label":R,className:"h-8 rounded-md border border-border bg-background px-2 text-xs outline-none focus-visible:border-ring","data-testid":"dashboards-form-title",onChange:x,placeholder:y,type:"text",value:t.title}),e[29]=t.title,e[30]=x,e[31]=y,e[32]=R,e[33]=N):N=e[33];let F;e[34]!==i?(F=i("Widget type"),e[34]=i,e[35]=F):F=e[35];let H=t.kind,D;e[36]!==i?(D=$e.map(c=>(0,a.jsx)("option",{value:c,children:Oe(c,i)},c)),e[36]=i,e[37]=D):D=e[37];let W;e[38]!==t.kind||e[39]!==O||e[40]!==F||e[41]!==D?(W=(0,a.jsx)("select",{"aria-label":F,className:"h-8 rounded-md border border-border bg-background px-2 text-xs outline-none focus-visible:border-ring","data-testid":"dashboards-form-widget-kind",onChange:O,value:H,children:D}),e[38]=t.kind,e[39]=O,e[40]=F,e[41]=D,e[42]=W):W=e[42];let M;e[43]!==t.sql||e[44]!==t.text||e[45]!==w||e[46]!==r||e[47]!==v||e[48]!==i?(M=w?(0,a.jsx)("textarea",{"aria-label":i("Text"),className:"min-h-24 resize-y rounded-md border border-border bg-background p-2 text-xs leading-5 outline-none focus-visible:border-ring","data-testid":"dashboards-form-text",onChange:v,placeholder:i("Notes for whoever reads this dashboard."),value:t.text}):(0,a.jsx)("textarea",{"aria-label":i("SQL query"),className:"min-h-24 resize-y rounded-md border border-border bg-background p-2 font-mono text-xs leading-5 outline-none focus-visible:border-ring","data-testid":"dashboards-form-sql",onChange:r,placeholder:"SELECT author, COUNT(*) AS messages FROM \u2026",spellCheck:!1,value:t.sql}),e[43]=t.sql,e[44]=t.text,e[45]=w,e[46]=r,e[47]=v,e[48]=i,e[49]=M):M=e[49];let $;e[50]!==t.chartKind||e[51]!==t.kind||e[52]!==k||e[53]!==i?($=t.kind==="chart"&&(0,a.jsx)("select",{"aria-label":i("Chart type"),className:"h-8 rounded-md border border-border bg-background px-2 text-xs outline-none focus-visible:border-ring","data-testid":"dashboards-form-kind",onChange:k,value:t.chartKind,children:We.map(c=>(0,a.jsx)("option",{value:c,children:De(c,i)},c))}),e[50]=t.chartKind,e[51]=t.kind,e[52]=k,e[53]=i,e[54]=$):$=e[54];let L;e[55]!==t.shardKey||e[56]!==w||e[57]!==u||e[58]!==i?(L=!w&&(0,a.jsx)("input",{"aria-label":i("Shard key (optional)"),className:"h-8 rounded-md border border-border bg-background px-2 font-mono text-xs outline-none focus-visible:border-ring","data-testid":"dashboards-form-shard",onChange:u,placeholder:i("Shard key (optional)"),type:"text",value:t.shardKey}),e[55]=t.shardKey,e[56]=w,e[57]=u,e[58]=i,e[59]=L):L=e[59];let z;e[60]!==i?(z=i("Cancel"),e[60]=i,e[61]=z):z=e[61];let q;e[62]!==l||e[63]!==z?(q=(0,a.jsx)(X,{"data-testid":"dashboards-form-cancel",onClick:l,size:"sm",type:"button",variant:"outline",children:z}),e[62]=l,e[63]=z,e[64]=q):q=e[64];let B=!_,I;e[65]!==n||e[66]!==i?(I=i(n?"Save widget":"Add widget"),e[65]=n,e[66]=i,e[67]=I):I=e[67];let A;e[68]!==T||e[69]!==B||e[70]!==I?(A=(0,a.jsx)(X,{"data-testid":"dashboards-form-save",disabled:B,onClick:T,size:"sm",type:"button",children:I}),e[68]=T,e[69]=B,e[70]=I,e[71]=A):A=e[71];let p;e[72]!==q||e[73]!==A?(p=(0,a.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[q,A]}),e[72]=q,e[73]=A,e[74]=p):p=e[74];let b;return e[75]!==N||e[76]!==W||e[77]!==M||e[78]!==$||e[79]!==L||e[80]!==p?(b=(0,a.jsx)(oe,{"data-testid":"dashboards-form",children:(0,a.jsxs)(ae,{className:"flex flex-col gap-3 py-4",children:[N,W,M,$,L,p]})}),e[75]=N,e[76]=W,e[77]=M,e[78]=$,e[79]=L,e[80]=p,e[81]=b):b=e[81],b},"Fe"),tt=g(f=>{let e=(0,Y.c)(53),{initialShardKey:t}=f,n=te(),[l,d]=ke(Be),[s,i]=(0,G.useState)(se),[h,x]=(0,G.useState)(null),[m,r]=(0,G.useState)(!1),o=ye(t??""),[v,S]=(0,G.useState)(null),u=(0,G.useRef)(null),C;e[0]!==t?(C=g(()=>{x(null),i({...se,shardKey:t??""}),r(!0)},"y"),e[0]=t,e[1]=C):C=e[1];let k=C,E;e[2]===Symbol.for("react.memo_cache_sentinel")?(E=g(()=>{r(!1),x(null),i(se)},"q"),e[2]=E):E=e[2];let O=E,j;e[3]!==l?(j=g(p=>{let b=l.find(c=>c.id===p);b!==void 0&&(x(p),i({chartKind:b.chartKind??"bar",kind:ce(b),shardKey:b.shardKey??"",sql:b.sql,text:b.text??"",title:b.title}),r(!0))},"E"),e[3]=l,e[4]=j):j=e[4];let T=j,w;e[5]!==o||e[6]!==d?(w=g((p,b)=>{S(p),ne((async()=>{let c=await o.inferChart({columns:b.columns,rowCount:b.rowCount});c!==void 0&&d(Ie(p,c))})().finally(()=>{S(c=>c===p?null:c)}))},"C"),e[5]=o,e[6]=d,e[7]=w):w=e[7];let K=w,_;e[8]!==d?(_=g(p=>{d(b=>b.filter(c=>c.id!==p))},"W"),e[8]=d,e[9]=_):_=e[9];let R=_,y;e[10]!==d?(y=g((p,b)=>{d(Te(p,b))},"k"),e[10]=d,e[11]=y):y=e[11];let N=y,F;e[12]!==d?(F=g((p,b)=>{d(c=>{let J=c.findIndex(P=>P.id===p),V=J+b;if(J===-1||V<0||V>=c.length)return c;let U=[...c],Q=U[J],Z=U[V];return Q===void 0||Z===void 0?c:(U[J]=Z,U[V]=Q,U)})},"_"),e[12]=d,e[13]=F):F=e[13];let H=F,D;e[14]!==s||e[15]!==h||e[16]!==d?(D=g(()=>{let p=s.title.trim(),b=s.sql.trim(),c=s.text.trim(),{chartKind:J,kind:V}=s;if(p===""||(V==="text"?c==="":b===""))return;let U={chartKind:J,kind:V,shardKey:s.shardKey.trim(),sql:b,text:c,title:p};d(h===null?Q=>[...Q,{...U,id:we("w")}]:Q=>Q.map(Z=>Z.id===h?{...Z,...U}:Z)),O()},"B"),e[14]=s,e[15]=h,e[16]=d,e[17]=D):D=e[17];let W=D,M;e[18]!==n?(M=n("Charts, values, tables, and notes. Drag a tile to reorder."),e[18]=n,e[19]=M):M=e[19];let $;e[20]!==M?($=(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:M}),e[20]=M,e[21]=$):$=e[21];let L;e[22]!==m||e[23]!==k||e[24]!==n?(L=!m&&(0,a.jsx)(X,{"data-testid":"dashboards-add",onClick:k,size:"sm",type:"button",children:n("Add widget")}),e[22]=m,e[23]=k,e[24]=n,e[25]=L):L=e[25];let z;e[26]!==$||e[27]!==L?(z=(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[$,L]}),e[26]=$,e[27]=L,e[28]=z):z=e[28];let q;e[29]!==o||e[30]!==n?(q=o.reason("chart")!==void 0&&(0,a.jsx)(le,{className:"text-xs",testId:"dashboards-suggest-error",variant:"destructive",children:n("Could not suggest a chart for that result.")}),e[29]=o,e[30]=n,e[31]=q):q=e[31];let B;e[32]!==s||e[33]!==h||e[34]!==m||e[35]!==W?(B=m&&(0,a.jsx)(Fe,{draft:s,editing:h!==null,onCancel:O,onChange:i,onSubmit:W}),e[32]=s,e[33]=h,e[34]=m,e[35]=W,e[36]=B):B=e[36];let I;e[37]!==o.unavailable||e[38]!==m||e[39]!==v||e[40]!==T||e[41]!==H||e[42]!==R||e[43]!==N||e[44]!==K||e[45]!==n||e[46]!==l?(I=l.length===0&&!m?(0,a.jsx)(ge,{description:n("Add a chart, a single value, a table, or a note. Everything is saved on this browser."),testId:"dashboards-empty",title:n("No widgets yet")}):(0,a.jsx)("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-2 xl:grid-cols-3","data-testid":"dashboards-grid",children:l.map((p,b)=>(0,a.jsx)(_e,{draggedRef:u,first:b===0,inferring:v===p.id,last:b===l.length-1,onEdit:T,onMove:H,onRemove:R,onReorder:N,onSuggest:o.unavailable?void 0:K,widget:p},p.id))}),e[37]=o.unavailable,e[38]=m,e[39]=v,e[40]=T,e[41]=H,e[42]=R,e[43]=N,e[44]=K,e[45]=n,e[46]=l,e[47]=I):I=e[47];let A;return e[48]!==z||e[49]!==q||e[50]!==B||e[51]!==I?(A=(0,a.jsxs)("div",{className:"flex flex-col gap-4","data-testid":"lunora-dashboards",children:[z,q,B,I]}),e[48]=z,e[49]=q,e[50]=B,e[51]=I,e[52]=A):A=e[52],A},"it");export{tt as default};
@@ -1 +1 @@
1
- import{b as y}from"./chunk-6I42AM75.js";import"./chunk-4C4THJUD.js";import{a as R}from"./chunk-IMF6DJKL.js";import"./chunk-OSJ7HV7B.js";import"./chunk-SL7LF2SO.js";import"./chunk-E26OT26O.js";import{a as v}from"./chunk-6UTZXEW3.js";import{c as $}from"./chunk-4SJDWMH3.js";import"./chunk-FKM35PXF.js";import"./chunk-WZTY3ZYI.js";import{a as S}from"./chunk-3Y5K3IQO.js";import{a as A,b as C,c as I,d as x,e as c,f as n}from"./chunk-CW57Q264.js";import{a as k,e as w}from"./chunk-MD67S53Z.js";import{f as N}from"./chunk-LPINY2IJ.js";import{a as f,d as b,f as E,g as O}from"./chunk-OXFKZ4BM.js";var j=b(E(),1);var r=b(O(),1);var _=f((e,t)=>({delete:e("Delete"),list:e("List"),read:e("Read"),write:e("Write")})[t],"I"),T={delete:2,list:3,read:0,write:1},B=f(e=>[...e].toSorted((t,a)=>t.bucket.localeCompare(a.bucket)||T[t.on]-T[a.on]||(t.prefix??"").localeCompare(a.prefix??"")),"O"),q=f(()=>{let e=(0,j.c)(14),t=N(),a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a={},e[0]=a):a=e[0];let{data:l,error:i,errorSource:d}=$(v.storageRules,a),h=l!==void 0,m;if(e[1]!==l||e[2]!==i||e[3]!==d||e[4]!==h||e[5]!==t){let g=B(Array.isArray(l?.rules)?l.rules:[]),u;e[7]!==i||e[8]!==d?(u=i!==null&&(0,r.jsx)(R,{error:d,testId:"storage-rules-error"}),e[7]=i,e[8]=d,e[9]=u):u=e[9];let o;e[10]!==t?(o=t("Storage rules are declared in code with defineStorageRule and gate ctx.storage access per bucket. This view is read-only."),e[10]=t,e[11]=o):o=e[11];let p;e[12]!==o?(p=(0,r.jsx)("p",{className:"text-sm text-muted-foreground","data-testid":"storage-rules-note",children:o}),e[12]=o,e[13]=p):p=e[13],m=(0,r.jsxs)("div",{className:"flex flex-col gap-4","data-testid":"lunora-storage-rules-panel",children:[u,p,h&&g.length===0?(0,r.jsx)(S,{description:t("No defineStorageRule is wired through .use(storageRules(...)) in this deployment. Add one to gate object access by key prefix."),testId:"storage-rules-empty",title:t("No storage rules defined")}):(0,r.jsx)(k,{className:"overflow-hidden py-0",children:(0,r.jsx)(w,{className:"px-0",children:(0,r.jsxs)(A,{"data-testid":"storage-rules-table",children:[(0,r.jsx)(C,{children:(0,r.jsxs)(x,{children:[(0,r.jsx)(c,{children:t("Bucket")}),(0,r.jsx)(c,{children:t("Operation")}),(0,r.jsx)(c,{children:t("Key prefix")}),(0,r.jsx)(c,{children:t("Guarded by")})]})}),(0,r.jsx)(I,{children:g.map(s=>(0,r.jsxs)(x,{"data-testid":`storage-rule-${s.bucket}-${s.on}-${s.prefix??""}`,children:[(0,r.jsx)(n,{className:"font-mono text-xs",children:s.bucket}),(0,r.jsx)(n,{children:(0,r.jsx)(y,{variant:"secondary",children:_(t,s.on)})}),(0,r.jsx)(n,{className:"font-mono text-xs",children:s.prefix??(0,r.jsx)("span",{className:"text-muted-foreground",children:t("(whole bucket)")})}),(0,r.jsx)(n,{className:"font-mono text-xs text-muted-foreground",children:s.procedure})]},`${s.bucket}:${s.on}:${s.prefix??""}:${s.procedure}`))})]})})})]}),e[1]=l,e[2]=i,e[3]=d,e[4]=h,e[5]=t,e[6]=m}else m=e[6];return m},"M");export{q as default};
1
+ import{b as y}from"./chunk-6I42AM75.js";import"./chunk-4C4THJUD.js";import{a as R}from"./chunk-GMO7IUXO.js";import"./chunk-OSJ7HV7B.js";import"./chunk-5SYMAYUA.js";import"./chunk-E26OT26O.js";import{a as v}from"./chunk-6UTZXEW3.js";import{c as $}from"./chunk-W37HRJGQ.js";import"./chunk-SDSQIQJG.js";import"./chunk-WZTY3ZYI.js";import{a as S}from"./chunk-3Y5K3IQO.js";import{a as A,b as C,c as I,d as x,e as c,f as n}from"./chunk-CW57Q264.js";import{a as k,e as w}from"./chunk-MD67S53Z.js";import{f as N}from"./chunk-LPINY2IJ.js";import{a as f,d as b,f as E,g as O}from"./chunk-OXFKZ4BM.js";var j=b(E(),1);var r=b(O(),1);var _=f((e,t)=>({delete:e("Delete"),list:e("List"),read:e("Read"),write:e("Write")})[t],"I"),T={delete:2,list:3,read:0,write:1},B=f(e=>[...e].toSorted((t,a)=>t.bucket.localeCompare(a.bucket)||T[t.on]-T[a.on]||(t.prefix??"").localeCompare(a.prefix??"")),"O"),q=f(()=>{let e=(0,j.c)(14),t=N(),a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a={},e[0]=a):a=e[0];let{data:l,error:i,errorSource:d}=$(v.storageRules,a),h=l!==void 0,m;if(e[1]!==l||e[2]!==i||e[3]!==d||e[4]!==h||e[5]!==t){let g=B(Array.isArray(l?.rules)?l.rules:[]),u;e[7]!==i||e[8]!==d?(u=i!==null&&(0,r.jsx)(R,{error:d,testId:"storage-rules-error"}),e[7]=i,e[8]=d,e[9]=u):u=e[9];let o;e[10]!==t?(o=t("Storage rules are declared in code with defineStorageRule and gate ctx.storage access per bucket. This view is read-only."),e[10]=t,e[11]=o):o=e[11];let p;e[12]!==o?(p=(0,r.jsx)("p",{className:"text-sm text-muted-foreground","data-testid":"storage-rules-note",children:o}),e[12]=o,e[13]=p):p=e[13],m=(0,r.jsxs)("div",{className:"flex flex-col gap-4","data-testid":"lunora-storage-rules-panel",children:[u,p,h&&g.length===0?(0,r.jsx)(S,{description:t("No defineStorageRule is wired through .use(storageRules(...)) in this deployment. Add one to gate object access by key prefix."),testId:"storage-rules-empty",title:t("No storage rules defined")}):(0,r.jsx)(k,{className:"overflow-hidden py-0",children:(0,r.jsx)(w,{className:"px-0",children:(0,r.jsxs)(A,{"data-testid":"storage-rules-table",children:[(0,r.jsx)(C,{children:(0,r.jsxs)(x,{children:[(0,r.jsx)(c,{children:t("Bucket")}),(0,r.jsx)(c,{children:t("Operation")}),(0,r.jsx)(c,{children:t("Key prefix")}),(0,r.jsx)(c,{children:t("Guarded by")})]})}),(0,r.jsx)(I,{children:g.map(s=>(0,r.jsxs)(x,{"data-testid":`storage-rule-${s.bucket}-${s.on}-${s.prefix??""}`,children:[(0,r.jsx)(n,{className:"font-mono text-xs",children:s.bucket}),(0,r.jsx)(n,{children:(0,r.jsx)(y,{variant:"secondary",children:_(t,s.on)})}),(0,r.jsx)(n,{className:"font-mono text-xs",children:s.prefix??(0,r.jsx)("span",{className:"text-muted-foreground",children:t("(whole bucket)")})}),(0,r.jsx)(n,{className:"font-mono text-xs text-muted-foreground",children:s.procedure})]},`${s.bucket}:${s.on}:${s.prefix??""}:${s.procedure}`))})]})})})]}),e[1]=l,e[2]=i,e[3]=d,e[4]=h,e[5]=t,e[6]=m}else m=e[6];return m},"M");export{q as default};