@lunora/studio 1.0.0-alpha.321 → 1.0.0-alpha.322

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 (67) hide show
  1. package/dist/standalone/{chunk-N2SJOHD6.js → chunk-2V47JHXK.js} +1 -1
  2. package/dist/standalone/{chunk-H6AITPPC.js → chunk-3NBWCIGD.js} +1 -1
  3. package/dist/standalone/{chunk-Q2KHDNYH.js → chunk-4DXGIJNQ.js} +1 -1
  4. package/dist/standalone/{chunk-MQCDUPD3.js → chunk-4SANMGOJ.js} +1 -1
  5. package/dist/standalone/{chunk-ROLSLIAL.js → chunk-4WONEGEO.js} +1 -1
  6. package/dist/standalone/{chunk-LR4Y6CQF.js → chunk-62EQDW2D.js} +1 -1
  7. package/dist/standalone/{chunk-6NTTNUVH.js → chunk-67WMIBQI.js} +1 -1
  8. package/dist/standalone/{chunk-7U2CDNFA.js → chunk-6ATAM7XD.js} +1 -1
  9. package/dist/standalone/{chunk-A43P35OS.js → chunk-7IN4NR3Q.js} +1 -1
  10. package/dist/standalone/{chunk-YDABMAXT.js → chunk-CKZGSVRG.js} +1 -1
  11. package/dist/standalone/{chunk-4OXIU2KT.js → chunk-CY25HYNM.js} +1 -1
  12. package/dist/standalone/{chunk-X2C3EX3E.js → chunk-D4GOAQJM.js} +1 -1
  13. package/dist/standalone/{chunk-TY5DCOTU.js → chunk-DBO2LRU7.js} +1 -1
  14. package/dist/standalone/{chunk-XGYH6FFM.js → chunk-DFSX67L5.js} +1 -1
  15. package/dist/standalone/{chunk-HCMDAFTX.js → chunk-DLVNLCCI.js} +1 -1
  16. package/dist/standalone/{chunk-UG2MMHTH.js → chunk-DLVUJBD6.js} +1 -1
  17. package/dist/standalone/{chunk-VY4D6ROH.js → chunk-DWHBAXWL.js} +1 -1
  18. package/dist/standalone/{chunk-NBFGB6LQ.js → chunk-E2AT2DLH.js} +1 -1
  19. package/dist/standalone/{chunk-R5P53FO2.js → chunk-EJ6CPRPX.js} +1 -1
  20. package/dist/standalone/{chunk-MXYGUIAL.js → chunk-EP35WNFQ.js} +1 -1
  21. package/dist/standalone/{chunk-JBWGM4O5.js → chunk-EY2JVIQL.js} +1 -1
  22. package/dist/standalone/{chunk-HPXC7ZFN.js → chunk-FQJMIMK6.js} +1 -1
  23. package/dist/standalone/{chunk-NNP5BWBX.js → chunk-FT66XZJF.js} +1 -1
  24. package/dist/standalone/{chunk-ZRJQQLAF.js → chunk-FUS6IIPK.js} +1 -1
  25. package/dist/standalone/{chunk-ASEMAFEH.js → chunk-GCAGUIGJ.js} +1 -1
  26. package/dist/standalone/{chunk-PNI5SACT.js → chunk-GKUCH3IT.js} +1 -1
  27. package/dist/standalone/{chunk-VQPCNZNW.js → chunk-HNWZRLZK.js} +1 -1
  28. package/dist/standalone/{chunk-AJV3ZKEY.js → chunk-HO7FAUZP.js} +2 -2
  29. package/dist/standalone/{chunk-KWTRRYMT.js → chunk-I54U4T6W.js} +1 -1
  30. package/dist/standalone/{chunk-VRWHCG2V.js → chunk-IPQ5KYVD.js} +1 -1
  31. package/dist/standalone/{chunk-HRVRCCML.js → chunk-J3BTWJEN.js} +1 -1
  32. package/dist/standalone/{chunk-MZNJ4SBH.js → chunk-JDIDVWA7.js} +1 -1
  33. package/dist/standalone/{chunk-ICDMV4MP.js → chunk-JSP7QF52.js} +2 -2
  34. package/dist/standalone/{chunk-QHXHYD2D.js → chunk-JWTNX66E.js} +1 -1
  35. package/dist/standalone/{chunk-CYVAA5G2.js → chunk-K55GCMUG.js} +1 -1
  36. package/dist/standalone/{chunk-TVCVRQUC.js → chunk-KMQTUDFK.js} +1 -1
  37. package/dist/standalone/{chunk-XZTOX6TC.js → chunk-L6AEV23T.js} +1 -1
  38. package/dist/standalone/{chunk-3PGRJ3V6.js → chunk-LIRPYTMM.js} +1 -1
  39. package/dist/standalone/{chunk-PFP4ELTQ.js → chunk-LWWPLBPR.js} +1 -1
  40. package/dist/standalone/{chunk-GS35QQEF.js → chunk-MP7FGHRS.js} +1 -1
  41. package/dist/standalone/{chunk-MYDSSTIL.js → chunk-MRMELMIL.js} +1 -1
  42. package/dist/standalone/{chunk-3V25YSWQ.js → chunk-N4SDDVZW.js} +1 -1
  43. package/dist/standalone/{chunk-3J42UGFU.js → chunk-N76L7Y6I.js} +1 -1
  44. package/dist/standalone/{chunk-BIF3IS4H.js → chunk-P3JRWNOG.js} +1 -1
  45. package/dist/standalone/{chunk-ODQ6AVXD.js → chunk-PL7TI67W.js} +1 -1
  46. package/dist/standalone/{chunk-JSKSPTUJ.js → chunk-QN5CM3OH.js} +1 -1
  47. package/dist/standalone/{chunk-GWOHQJIL.js → chunk-R2JJKTII.js} +1 -1
  48. package/dist/standalone/{chunk-TTZZ7DNO.js → chunk-RX3SOFXA.js} +1 -1
  49. package/dist/standalone/{chunk-SJUYCXDY.js → chunk-SEZ2IRFD.js} +1 -1
  50. package/dist/standalone/{chunk-DMPS3Z6Z.js → chunk-TQVDKDYK.js} +1 -1
  51. package/dist/standalone/{chunk-PODX443N.js → chunk-UJANVTRM.js} +1 -1
  52. package/dist/standalone/{chunk-HELZ4ROC.js → chunk-V77ZHGXW.js} +1 -1
  53. package/dist/standalone/{chunk-HXF32KMX.js → chunk-VDCF6PXM.js} +1 -1
  54. package/dist/standalone/{chunk-GTN6NHUL.js → chunk-VKR53NLO.js} +1 -1
  55. package/dist/standalone/{chunk-ODMIUMAO.js → chunk-VOWSZXG7.js} +1 -1
  56. package/dist/standalone/{chunk-6OHCSDVS.js → chunk-WJS62UEZ.js} +1 -1
  57. package/dist/standalone/{chunk-FQPBYMII.js → chunk-WVWG6LII.js} +1 -1
  58. package/dist/standalone/{chunk-BRE5MCZN.js → chunk-WZXQIVY4.js} +1 -1
  59. package/dist/standalone/{chunk-ZTPG3TFT.js → chunk-Y5IYXX5E.js} +1 -1
  60. package/dist/standalone/{chunk-AN5MJC2Z.js → chunk-YJFMMO37.js} +1 -1
  61. package/dist/standalone/{chunk-OWVKR6J4.js → chunk-YOJMTBDR.js} +1 -1
  62. package/dist/standalone/{chunk-JWOD73TN.js → chunk-ZG3DITNB.js} +1 -1
  63. package/dist/standalone/{chunk-P5QHD7XI.js → chunk-ZQU6EUUL.js} +1 -1
  64. package/dist/standalone/{chunk-SYMULPR4.js → chunk-ZZHEKODS.js} +1 -1
  65. package/dist/standalone/{chunk-PUEVXAMZ.js → chunk-ZZPTGL45.js} +1 -1
  66. package/dist/standalone/studio.js +1 -1
  67. package/package.json +5 -5
@@ -1 +1 @@
1
- import{a as Se}from"./chunk-FPI7AMQJ.js";import{a as $}from"./chunk-37WYCOQ2.js";import{a as Ce}from"./chunk-SV764LKQ.js";import{a as ve}from"./chunk-YVR4SEPU.js";import"./chunk-ZKJS6EBE.js";import"./chunk-RGMVGZV4.js";import{i as M}from"./chunk-E4PXACVL.js";import"./chunk-MVWZMWPD.js";import"./chunk-7Y3SY37W.js";import{a as E}from"./chunk-7G4Z6Q7X.js";import"./chunk-3YXASVTP.js";import"./chunk-AUAECCXB.js";import{b as F}from"./chunk-Q6ED4KUL.js";import"./chunk-BOMPSVRC.js";import{a as Ne}from"./chunk-SJUYCXDY.js";import"./chunk-NCPW7WHO.js";import"./chunk-3V25YSWQ.js";import"./chunk-55UGUCQ6.js";import{a as X}from"./chunk-4ZEL6BYL.js";import{c as ae}from"./chunk-VRWHCG2V.js";import{d as me,l as oe}from"./chunk-ICDMV4MP.js";import"./chunk-QAQDMS6R.js";import"./chunk-FQPBYMII.js";import{a as de}from"./chunk-RWVIV3U7.js";import{a as ke,b as we,c as Pe,d as ce,e as re,f as le}from"./chunk-HCTJKP5J.js";import{a as se,b as fe,c as ue,d as he,e as ne}from"./chunk-2IKDEUCX.js";import{d as V,f as xe,g as ye,h as ge,m as be,p as te}from"./chunk-HJHSQPHW.js";import{a as n,d as ie,e as Re,f as Te,g as Fe}from"./chunk-I26MS5PJ.js";var f=ie(Re(),1);var pe=ie(Te(),1);var t=ie(Fe(),1);var Ie=["read","insert","update","delete"],Ee=n((e,a)=>({delete:e("Delete"),insert:e("Insert"),read:e("Read"),update:e("Update")})[a],"Ie"),$e=n(e=>e.file===""?e.procedure:`${e.file}:${e.procedure}`,"Re"),ze=n(e=>{let a=new Set;for(let i of e?.advisories??[])if(i.name==="rls_uncovered_table"){let{table:d}=i.metadata;typeof d=="string"&&d!==""&&a.add(d)}return a},"Fe"),De=n((e,a,i)=>{let d=new Map,r=n(s=>{let o=d.get(s);if(o!==void 0)return o;let m={cells:{delete:{},insert:{},read:{},update:{}},maskedColumns:new Set,table:s,uncovered:i.has(s)};return d.set(s,m),m},"r");for(let s of e)r(s.table).cells[s.on]={path:$e(s),procedure:s.procedure};for(let s of a)r(s.table).maskedColumns.add(s.column);for(let s of i)r(s);return[...d.values()].toSorted((s,o)=>s.table.localeCompare(o.table))},"Oe"),Oe=n(e=>{let a=(0,pe.c)(17),i;a[0]!==e?(i=e===void 0?{}:e,a[0]=e,a[1]=i):i=a[1];let{onProbe:d}=i,r=V(),s,o;a[2]===Symbol.for("react.memo_cache_sentinel")?(s={},o={live:!0},a[2]=s,a[3]=o):(s=a[2],o=a[3]);let m=ae(X.rlsPolicies,s,o),l;a[4]===Symbol.for("react.memo_cache_sentinel")?(l={},a[4]=l):l=a[4];let g=ae(X.maskPolicies,l),h;a[5]===Symbol.for("react.memo_cache_sentinel")?(h={},a[5]=h):h=a[5];let b=ae(X.getAdvisories,h),v;if(a[6]!==b.data||a[7]!==g.data||a[8]!==d||a[9]!==m||a[10]!==r){let N=null;m.data!==void 0&&(N=Array.isArray(m.data.policies)?m.data.policies:[]);let z=Array.isArray(g.data?.columns)?g.data.columns:[],j=b.data??null,{error:C,errorSource:k,liveError:I}=m,R=N===null?[]:De(N,z,ze(j)),w;a[12]!==I?(w=(0,t.jsx)("div",{className:"flex items-center justify-end",children:(0,t.jsx)(Ce,{message:I,prefix:"pm"})}),a[12]=I,a[13]=w):w=a[13];let u;a[14]!==C||a[15]!==k?(u=C!==null&&(0,t.jsx)(Ne,{error:k,testId:"pm-error"}),a[14]=C,a[15]=k,a[16]=u):u=a[16],v=(0,t.jsxs)("div",{className:"flex flex-col gap-3","data-testid":"lunora-permissions-matrix",children:[w,u,N!==null&&R.length===0?(0,t.jsx)(de,{description:r("Add a `definePolicy` and wire it through `.use(rls(...))` to populate this matrix."),testId:"pm-empty",title:r("No policy")}):(0,t.jsxs)(ke,{"data-testid":"pm-table",children:[(0,t.jsx)(we,{children:(0,t.jsxs)(ce,{children:[(0,t.jsx)(re,{children:r("Table")}),Ie.map(p=>(0,t.jsx)(re,{children:Ee(r,p)},p)),(0,t.jsx)(re,{children:r("Masked columns")})]})}),(0,t.jsx)(Pe,{children:R.map(p=>(0,t.jsxs)(ce,{"data-testid":`pm-row-${p.table}`,children:[(0,t.jsx)(le,{className:"font-mono text-xs",children:(0,t.jsxs)("span",{className:"flex items-center gap-1.5",children:[p.table,p.uncovered&&(0,t.jsx)(F,{"data-testid":`pm-uncovered-${p.table}`,title:r("Uncovered \u2014 reachable without a policy"),variant:"destructive",children:r("Uncovered \u2014 reachable without a policy")})]})}),Ie.map(_=>{let x=p.cells[_];return(0,t.jsx)(le,{"data-testid":`pm-cell-${p.table}-${_}`,children:x.procedure===void 0?(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:r("No policy")}):(0,t.jsxs)("span",{className:"flex flex-col gap-1",children:[(0,t.jsx)(F,{variant:"secondary",children:r("Covered by {procedure}",{procedure:x.procedure})}),d!==void 0&&(0,t.jsx)(E,{className:"h-auto justify-start p-0 text-[11px]","data-testid":`pm-probe-${p.table}-${_}`,onClick:n(()=>{d(p.table,_,x.path??"")},"onClick"),size:"xs",type:"button",variant:"ghost",children:r("Probe this")})]})},_)}),(0,t.jsx)(le,{children:p.maskedColumns.size===0?(0,t.jsx)("span",{"aria-hidden":"true",className:"text-muted-foreground",children:"\u2014"}):(0,t.jsx)("span",{className:"flex flex-wrap gap-1",children:[...p.maskedColumns].map(Le)})})]},p.table))})]})]}),a[6]=b.data,a[7]=g.data,a[8]=d,a[9]=m,a[10]=r,a[11]=v}else v=a[11];return v},"De");function Le(e){return(0,t.jsx)(F,{variant:"outline",children:e},e)}n(Le,"Le");var je=xe(X.runAs),Me=new Set(["FORBIDDEN","RLS_REQUIRED","UNAUTHORIZED"]),Ue=n(e=>{let a=e?.code;return typeof a=="string"?a:void 0},"Me"),qe=n(()=>{let e=oe();return async({args:a,functionPath:i,shardKey:d="",userId:r})=>{if(r.trim()==="")return{kind:"invalid",message:"No identity to probe: enter the userId whose access you want to test."};let s=je;try{return{kind:"allowed",value:await e.query(s,{args:a,functionPath:i,userId:r},ye(d))}}catch(o){let m=o instanceof Error?o.message:String(o),l=Ue(o);return l!==void 0&&Me.has(l)?{kind:"denied",message:m}:{kind:"errored",message:m}}}},"ze"),We=n(e=>e===void 0?"undefined":JSON.stringify(e,be,2),"je"),Je=n(({functions:e,prefill:a,runAsIdentity:i=!1}={})=>{let d=oe(),r=V(),s=qe(),[o,m]=(0,f.useState)(null),[l,g]=(0,f.useState)(null),h=e??o??[],[b,v]=(0,f.useState)(""),[N,z]=(0,f.useState)("{}"),[j,C]=(0,f.useState)(""),[k,I]=(0,f.useState)(""),[R,w]=(0,f.useState)(!1),[u,p]=(0,f.useState)(null),[_,x]=(0,f.useState)(null),T=(0,f.useRef)(-1),P=(0,f.useRef)(0);(0,f.useEffect)(()=>{if(e!==void 0)return;let c=!1;return d.listFunctions().then(y=>(c||m(y),y)).catch(y=>{c||g(ge(y))}),()=>{c=!0}},[d,e]),(0,f.useEffect)(()=>{if(a===void 0||T.current===a.nonce)return;T.current=a.nonce,P.current+=1;let c=a.functionPath;queueMicrotask(()=>{v(c),p(null)})},[a]);let S=b===""?h[0]?.path??"":b,D=n(async()=>{if(S==="")return;let c;try{c=N.trim()===""?{}:me(JSON.parse(N))}catch(A){x(r("Invalid JSON args: {message}",{message:A.message})),p(null);return}P.current+=1;let y=P.current;x(null),w(!0);try{let A=await s({args:c,functionPath:S,shardKey:j.trim(),userId:k.trim()});y===P.current&&p(A)}finally{w(!1)}},"F"),Q=n(()=>{te(D())},"K"),O=n(c=>{v(c.target.value)},"O"),L=n(c=>{z(c.target.value)},"D"),G=n(c=>{I(c.target.value)},"Y");return(0,t.jsxs)("div",{className:"flex flex-col gap-3","data-testid":"lunora-permissions-playground",children:[l!==null&&(0,t.jsx)("p",{className:"text-sm text-destructive","data-testid":"pp-discover-error",role:"alert",children:l}),!i&&(0,t.jsx)(de,{description:r("Dev only: runs the selected function as this user over the admin gate so you can test auth and RLS."),testId:"pp-gate",title:r("Set `runAsIdentity` to forge an identity and probe access.")}),(0,t.jsxs)("div",{className:"flex flex-col gap-3 rounded-md border border-border p-3",children:[(0,t.jsxs)("div",{className:"flex flex-col gap-1.5",children:[(0,t.jsx)($,{htmlFor:"pp-function",children:r("Function")}),(0,t.jsx)("select",{"aria-label":r("Function"),className:"flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-xs outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50","data-testid":"pp-function",id:"pp-function",onChange:O,value:S,children:h.map(c=>(0,t.jsxs)("option",{value:c.path,children:[c.path," (",c.kind,")"]},c.path))})]}),(0,t.jsxs)("div",{className:"flex flex-col gap-1.5",children:[(0,t.jsx)($,{htmlFor:"pp-args",children:r("Arguments")}),(0,t.jsx)(Se,{"aria-label":r("Arguments"),className:"font-mono text-xs","data-testid":"pp-args",id:"pp-args",onChange:L,value:N})]}),(0,t.jsx)(ve,{onChange:C,testId:"pp-shard",value:j}),(0,t.jsxs)("div",{className:"flex flex-col gap-1.5",children:[(0,t.jsx)($,{htmlFor:"pp-user",children:r("Run as (userId)")}),(0,t.jsx)(M,{"aria-label":r("Identity (userId) to run as"),className:"font-mono text-xs","data-testid":"pp-user",id:"pp-user",onChange:G,placeholder:r("Required \u2014 the identity to probe as"),value:k})]}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(E,{"data-testid":"pp-run",disabled:!i||R||S==="",onClick:Q,type:"button",children:r(R?"Probing\u2026":"Run probe")}),k.trim()!==""&&(0,t.jsx)(F,{"data-testid":"pp-as-badge",variant:"secondary",children:r("as {userId}",{userId:k.trim()})})]})]}),_!==null&&(0,t.jsx)("p",{className:"text-sm text-destructive","data-testid":"pp-args-error",role:"alert",children:_}),u!==null&&u.kind==="allowed"&&(0,t.jsxs)("div",{className:"flex flex-col gap-2","data-testid":"pp-outcome-allowed",children:[(0,t.jsx)(F,{variant:"secondary",children:r("Allowed")}),(0,t.jsx)("pre",{className:"overflow-auto rounded-md border border-border bg-muted/50 p-3 font-mono text-xs","data-testid":"pp-result",children:We(u.value)})]}),u!==null&&u.kind==="invalid"&&(0,t.jsxs)("div",{className:"flex flex-col gap-2","data-testid":"pp-outcome-invalid",children:[(0,t.jsx)(F,{variant:"outline",children:r("Not run")}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground","data-testid":"pp-invalid",role:"status",children:u.message})]}),u!==null&&u.kind==="errored"&&(0,t.jsxs)("div",{className:"flex flex-col gap-2","data-testid":"pp-outcome-errored",children:[(0,t.jsx)(F,{variant:"outline",children:r("Errored")}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:r("The call failed for a reason that is not an access verdict, so it says nothing about the policy.")}),(0,t.jsx)("pre",{className:"overflow-auto rounded-md border border-border bg-muted/50 p-3 font-mono text-xs","data-testid":"pp-errored",role:"alert",children:u.message})]}),u!==null&&u.kind==="denied"&&(0,t.jsxs)("div",{className:"flex flex-col gap-2","data-testid":"pp-outcome-denied",children:[(0,t.jsx)(F,{variant:"destructive",children:r("Denied")}),(0,t.jsx)("pre",{className:"overflow-auto rounded-md border border-border bg-muted/50 p-3 font-mono text-xs text-destructive","data-testid":"pp-denied",role:"alert",children:u.message})]})]})},"qe"),Be="/__lunora/policy-scaffold",He={"already-wired":"That procedure already has an rls(...) policy wired in.","file-exists":"A policy file with that name already exists \u2014 pick another name or edit it by hand.","invalid-identifier":"Name, table, and policy-set must be plain identifiers (letters, digits, _ or $).","unknown-procedure":"No exported procedure was found at that file path.","unsupported-procedure-shape":"That procedure uses the bare query({\u2026}) form \u2014 convert it to the builder form (c.use(\u2026).query(\u2026)) before wiring RLS."},Ke=n(async e=>{let a=await fetch(Be,{body:JSON.stringify(e),headers:{"Content-Type":"application/json"},method:"POST"}),i=await a.json();if(i.needsManualEdit===!0)return{kind:"needs-manual-edit",message:i.message??"This change must be made by hand."};if(a.ok)return{diagnostics:i.diagnostics??[],kind:"ok",label:i.fileName??i.exportName??""};let d=i.error;return{kind:"error",message:d===void 0?`policy scaffold failed (${String(a.status)})`:He[d]??d}},"Qe"),_e={exportName:"",filePath:"",policyName:"",policies:"",tableName:""},Qe=n(()=>{let e=(0,pe.c)(69),a=V(),[i,d]=(0,f.useState)(null),[r,s]=(0,f.useState)(!1),[o,m]=(0,f.useState)(null),[l,g]=(0,f.useState)(_e),h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h=n(ee=>{let K=ee.target.name,{value:Y}=ee.target;g(Ae=>({...Ae,[K]:Y}))},"u"),e[0]=h):h=e[0];let b=h,v;e[1]===Symbol.for("react.memo_cache_sentinel")?(v=n(()=>{d(null),g(_e)},"v"),e[1]=v):v=e[1];let N=v,z;e[2]===Symbol.for("react.memo_cache_sentinel")?(z=n(async ee=>{s(!0),m(null);try{let K=await Ke(ee);m(K),K.kind==="ok"&&N()}catch(K){let Y=K;m({kind:"error",message:Y instanceof Error?Y.message:String(Y)})}s(!1)},"R"),e[2]=z):z=e[2];let j=z,C;e[3]!==l.policyName||e[4]!==l.tableName?(C=n(()=>{te(j({kind:"scaffoldPolicy",name:l.policyName.trim(),table:l.tableName.trim()}))},"P"),e[3]=l.policyName,e[4]=l.tableName,e[5]=C):C=e[5];let k=C,I;e[6]!==l.exportName||e[7]!==l.filePath||e[8]!==l.policies?(I=n(()=>{te(j({exportName:l.exportName.trim(),filePath:l.filePath.trim(),kind:"wireRls",policies:l.policies.trim()}))},"A"),e[6]=l.exportName,e[7]=l.filePath,e[8]=l.policies,e[9]=I):I=e[9];let R=I,w;e[10]===Symbol.for("react.memo_cache_sentinel")?(w=n(()=>{m(null),d("scaffold")},"S"),e[10]=w):w=e[10];let u=w,p;e[11]===Symbol.for("react.memo_cache_sentinel")?(p=n(()=>{m(null),d("wire")},"m"),e[11]=p):p=e[11];let _=p,x;e[12]!==a?(x=a("Scaffold access rules"),e[12]=a,e[13]=x):x=e[13];let T;e[14]!==x?(T=(0,t.jsx)(ue,{children:x}),e[14]=x,e[15]=T):T=e[15];let P;e[16]!==a?(P=a("Writes a new deny-by-default policy file under lunora/, or wires one into a procedure, then reruns codegen. Local dev only."),e[16]=a,e[17]=P):P=e[17];let S;e[18]!==P?(S=(0,t.jsx)(he,{children:P}),e[18]=P,e[19]=S):S=e[19];let D;e[20]!==S||e[21]!==T?(D=(0,t.jsxs)(fe,{children:[T,S]}),e[20]=S,e[21]=T,e[22]=D):D=e[22];let Q=i==="scaffold"?"default":"outline",O;e[23]!==a?(O=a("New policy file"),e[23]=a,e[24]=O):O=e[24];let L;e[25]!==Q||e[26]!==O?(L=(0,t.jsx)(E,{"data-testid":"policy-scaffolder-new",onClick:u,size:"xs",type:"button",variant:Q,children:O}),e[25]=Q,e[26]=O,e[27]=L):L=e[27];let G=i==="wire"?"default":"outline",c;e[28]!==a?(c=a("Wire into a procedure"),e[28]=a,e[29]=c):c=e[29];let y;e[30]!==G||e[31]!==c?(y=(0,t.jsx)(E,{"data-testid":"policy-scaffolder-wire",onClick:_,size:"xs",type:"button",variant:G,children:c}),e[30]=G,e[31]=c,e[32]=y):y=e[32];let A;e[33]!==L||e[34]!==y?(A=(0,t.jsxs)("div",{className:"flex flex-wrap gap-2",children:[L,y]}),e[33]=L,e[34]=y,e[35]=A):A=e[35];let U;e[36]!==r||e[37]!==l.policyName||e[38]!==l.tableName||e[39]!==i||e[40]!==k||e[41]!==a?(U=i==="scaffold"&&(0,t.jsxs)("div",{className:"mt-3 flex flex-wrap items-end gap-2","data-testid":"policy-scaffolder-new-form",children:[(0,t.jsxs)("div",{className:"flex flex-col gap-1 text-xs",children:[(0,t.jsx)($,{htmlFor:"policy-scaffolder-name",children:a("Policy name")}),(0,t.jsx)(M,{"data-testid":"policy-scaffolder-name",id:"policy-scaffolder-name",name:"policyName",onChange:b,value:l.policyName})]}),(0,t.jsxs)("div",{className:"flex flex-col gap-1 text-xs",children:[(0,t.jsx)($,{htmlFor:"policy-scaffolder-table",children:a("Table name")}),(0,t.jsx)(M,{"data-testid":"policy-scaffolder-table",id:"policy-scaffolder-table",name:"tableName",onChange:b,value:l.tableName})]}),(0,t.jsx)(E,{"data-testid":"policy-scaffolder-create",disabled:r||l.policyName.trim()===""||l.tableName.trim()==="",onClick:k,size:"xs",type:"button",children:a(r?"Creating\u2026":"Create policy file")}),(0,t.jsx)(E,{onClick:N,size:"xs",type:"button",variant:"ghost",children:a("Cancel")})]}),e[36]=r,e[37]=l.policyName,e[38]=l.tableName,e[39]=i,e[40]=k,e[41]=a,e[42]=U):U=e[42];let q;e[43]!==r||e[44]!==l.exportName||e[45]!==l.filePath||e[46]!==l.policies||e[47]!==i||e[48]!==R||e[49]!==a?(q=i==="wire"&&(0,t.jsxs)("div",{className:"mt-3 flex flex-wrap items-end gap-2","data-testid":"policy-scaffolder-wire-form",children:[(0,t.jsxs)("div",{className:"flex flex-col gap-1 text-xs",children:[(0,t.jsx)($,{htmlFor:"policy-scaffolder-file",children:a("Procedure file path")}),(0,t.jsx)(M,{"data-testid":"policy-scaffolder-file",id:"policy-scaffolder-file",name:"filePath",onChange:b,value:l.filePath})]}),(0,t.jsxs)("div",{className:"flex flex-col gap-1 text-xs",children:[(0,t.jsx)($,{htmlFor:"policy-scaffolder-export",children:a("Exported procedure")}),(0,t.jsx)(M,{"data-testid":"policy-scaffolder-export",id:"policy-scaffolder-export",name:"exportName",onChange:b,value:l.exportName})]}),(0,t.jsxs)("div",{className:"flex flex-col gap-1 text-xs",children:[(0,t.jsx)($,{htmlFor:"policy-scaffolder-policies",children:a("Policy set identifier")}),(0,t.jsx)(M,{"data-testid":"policy-scaffolder-policies",id:"policy-scaffolder-policies",name:"policies",onChange:b,value:l.policies})]}),(0,t.jsx)(E,{"data-testid":"policy-scaffolder-apply",disabled:r||l.filePath.trim()===""||l.exportName.trim()===""||l.policies.trim()==="",onClick:R,size:"xs",type:"button",children:a(r?"Wiring\u2026":"Wire RLS")}),(0,t.jsx)(E,{onClick:N,size:"xs",type:"button",variant:"ghost",children:a("Cancel")})]}),e[43]=r,e[44]=l.exportName,e[45]=l.filePath,e[46]=l.policies,e[47]=i,e[48]=R,e[49]=a,e[50]=q):q=e[50];let W;e[51]!==o?(W=o?.kind==="error"&&(0,t.jsx)("p",{className:"mt-3 text-sm text-destructive","data-testid":"policy-scaffolder-error",role:"alert",children:o.message}),e[51]=o,e[52]=W):W=e[52];let J;e[53]!==o?.kind||e[54]!==a?(J=o?.kind==="needs-manual-edit"&&(0,t.jsx)("p",{className:"mt-3 text-sm text-amber-600 dark:text-amber-500","data-testid":"policy-scaffolder-manual",role:"alert",children:a("This change must be made by hand \u2014 the scaffolder only adds new, deny-by-default rules.")}),e[53]=o?.kind,e[54]=a,e[55]=J):J=e[55];let B;e[56]!==o||e[57]!==a?(B=o?.kind==="ok"&&(0,t.jsxs)("div",{className:"mt-3 flex flex-col gap-1","data-testid":"policy-scaffolder-ok",children:[(0,t.jsx)("p",{className:"text-sm text-emerald-600 dark:text-emerald-500",children:a("Scaffolded {label} and reran codegen. Fill in the `when` predicates before relying on it.",{label:o.label})}),o.diagnostics.length>0&&(0,t.jsx)("ul",{className:"flex flex-col gap-0.5","data-testid":"policy-scaffolder-diagnostics",children:o.diagnostics.map(Ge)})]}),e[56]=o,e[57]=a,e[58]=B):B=e[58];let H;e[59]!==A||e[60]!==U||e[61]!==q||e[62]!==W||e[63]!==J||e[64]!==B?(H=(0,t.jsxs)(ne,{children:[A,U,q,W,J,B]}),e[59]=A,e[60]=U,e[61]=q,e[62]=W,e[63]=J,e[64]=B,e[65]=H):H=e[65];let Z;return e[66]!==D||e[67]!==H?(Z=(0,t.jsxs)(se,{"data-testid":"policy-scaffolder",size:"sm",children:[D,H]}),e[66]=D,e[67]=H,e[68]=Z):Z=e[68],Z},"He");function Ge(e){return(0,t.jsx)("li",{className:"font-mono text-[11px] text-destructive",children:e},e)}n(Ge,"Je");var ft=n(({functions:e,runAsIdentity:a=!1,schemaEditable:i=!1}={})=>{let d=V(),[r,s]=(0,f.useState)(void 0),o=n((m,l,g)=>{g!==""&&s(h=>({functionPath:g,nonce:(h?.nonce??0)+1}))},"o");return(0,t.jsxs)("div",{className:"flex flex-col gap-8","data-testid":"lunora-permissions",children:[(0,t.jsxs)("section",{className:"flex flex-col gap-3",children:[(0,t.jsx)("header",{className:"border-b border-border px-4 py-3",children:(0,t.jsx)("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:d("Permissions")})}),(0,t.jsx)(Oe,{onProbe:o})]}),(0,t.jsx)("section",{className:"flex flex-col gap-3",children:(0,t.jsxs)(se,{className:"gap-0 py-0",children:[(0,t.jsx)("header",{className:"border-b border-border px-4 py-3",children:(0,t.jsx)("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:d("Probe")})}),(0,t.jsxs)(ne,{className:"px-4 py-4",children:[(0,t.jsx)("p",{className:"mb-3 text-sm text-muted-foreground",children:d("Pick a function and an identity, then run it to see the access outcome.")}),(0,t.jsx)(Je,{functions:e,prefill:r,runAsIdentity:a})]})]})}),i&&(0,t.jsx)("section",{className:"flex flex-col gap-2",children:(0,t.jsx)(Qe,{})})]})},"ut");export{ft as PermissionsPanel};
1
+ import{a as Se}from"./chunk-FPI7AMQJ.js";import{a as $}from"./chunk-37WYCOQ2.js";import{a as Ce}from"./chunk-SV764LKQ.js";import{a as ve}from"./chunk-YVR4SEPU.js";import"./chunk-ZKJS6EBE.js";import"./chunk-RGMVGZV4.js";import{i as M}from"./chunk-E4PXACVL.js";import"./chunk-MVWZMWPD.js";import"./chunk-7Y3SY37W.js";import{a as E}from"./chunk-7G4Z6Q7X.js";import"./chunk-3YXASVTP.js";import"./chunk-AUAECCXB.js";import{b as F}from"./chunk-Q6ED4KUL.js";import"./chunk-BOMPSVRC.js";import{a as Ne}from"./chunk-SEZ2IRFD.js";import"./chunk-NCPW7WHO.js";import"./chunk-N4SDDVZW.js";import"./chunk-55UGUCQ6.js";import{a as X}from"./chunk-4ZEL6BYL.js";import{c as ae}from"./chunk-IPQ5KYVD.js";import{d as me,l as oe}from"./chunk-JSP7QF52.js";import"./chunk-QAQDMS6R.js";import"./chunk-WVWG6LII.js";import{a as de}from"./chunk-RWVIV3U7.js";import{a as ke,b as we,c as Pe,d as ce,e as re,f as le}from"./chunk-HCTJKP5J.js";import{a as se,b as fe,c as ue,d as he,e as ne}from"./chunk-2IKDEUCX.js";import{d as V,f as xe,g as ye,h as ge,m as be,p as te}from"./chunk-HJHSQPHW.js";import{a as n,d as ie,e as Re,f as Te,g as Fe}from"./chunk-I26MS5PJ.js";var f=ie(Re(),1);var pe=ie(Te(),1);var t=ie(Fe(),1);var Ie=["read","insert","update","delete"],Ee=n((e,a)=>({delete:e("Delete"),insert:e("Insert"),read:e("Read"),update:e("Update")})[a],"Ie"),$e=n(e=>e.file===""?e.procedure:`${e.file}:${e.procedure}`,"Re"),ze=n(e=>{let a=new Set;for(let i of e?.advisories??[])if(i.name==="rls_uncovered_table"){let{table:d}=i.metadata;typeof d=="string"&&d!==""&&a.add(d)}return a},"Fe"),De=n((e,a,i)=>{let d=new Map,r=n(s=>{let o=d.get(s);if(o!==void 0)return o;let m={cells:{delete:{},insert:{},read:{},update:{}},maskedColumns:new Set,table:s,uncovered:i.has(s)};return d.set(s,m),m},"r");for(let s of e)r(s.table).cells[s.on]={path:$e(s),procedure:s.procedure};for(let s of a)r(s.table).maskedColumns.add(s.column);for(let s of i)r(s);return[...d.values()].toSorted((s,o)=>s.table.localeCompare(o.table))},"Oe"),Oe=n(e=>{let a=(0,pe.c)(17),i;a[0]!==e?(i=e===void 0?{}:e,a[0]=e,a[1]=i):i=a[1];let{onProbe:d}=i,r=V(),s,o;a[2]===Symbol.for("react.memo_cache_sentinel")?(s={},o={live:!0},a[2]=s,a[3]=o):(s=a[2],o=a[3]);let m=ae(X.rlsPolicies,s,o),l;a[4]===Symbol.for("react.memo_cache_sentinel")?(l={},a[4]=l):l=a[4];let g=ae(X.maskPolicies,l),h;a[5]===Symbol.for("react.memo_cache_sentinel")?(h={},a[5]=h):h=a[5];let b=ae(X.getAdvisories,h),v;if(a[6]!==b.data||a[7]!==g.data||a[8]!==d||a[9]!==m||a[10]!==r){let N=null;m.data!==void 0&&(N=Array.isArray(m.data.policies)?m.data.policies:[]);let z=Array.isArray(g.data?.columns)?g.data.columns:[],j=b.data??null,{error:C,errorSource:k,liveError:I}=m,R=N===null?[]:De(N,z,ze(j)),w;a[12]!==I?(w=(0,t.jsx)("div",{className:"flex items-center justify-end",children:(0,t.jsx)(Ce,{message:I,prefix:"pm"})}),a[12]=I,a[13]=w):w=a[13];let u;a[14]!==C||a[15]!==k?(u=C!==null&&(0,t.jsx)(Ne,{error:k,testId:"pm-error"}),a[14]=C,a[15]=k,a[16]=u):u=a[16],v=(0,t.jsxs)("div",{className:"flex flex-col gap-3","data-testid":"lunora-permissions-matrix",children:[w,u,N!==null&&R.length===0?(0,t.jsx)(de,{description:r("Add a `definePolicy` and wire it through `.use(rls(...))` to populate this matrix."),testId:"pm-empty",title:r("No policy")}):(0,t.jsxs)(ke,{"data-testid":"pm-table",children:[(0,t.jsx)(we,{children:(0,t.jsxs)(ce,{children:[(0,t.jsx)(re,{children:r("Table")}),Ie.map(p=>(0,t.jsx)(re,{children:Ee(r,p)},p)),(0,t.jsx)(re,{children:r("Masked columns")})]})}),(0,t.jsx)(Pe,{children:R.map(p=>(0,t.jsxs)(ce,{"data-testid":`pm-row-${p.table}`,children:[(0,t.jsx)(le,{className:"font-mono text-xs",children:(0,t.jsxs)("span",{className:"flex items-center gap-1.5",children:[p.table,p.uncovered&&(0,t.jsx)(F,{"data-testid":`pm-uncovered-${p.table}`,title:r("Uncovered \u2014 reachable without a policy"),variant:"destructive",children:r("Uncovered \u2014 reachable without a policy")})]})}),Ie.map(_=>{let x=p.cells[_];return(0,t.jsx)(le,{"data-testid":`pm-cell-${p.table}-${_}`,children:x.procedure===void 0?(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:r("No policy")}):(0,t.jsxs)("span",{className:"flex flex-col gap-1",children:[(0,t.jsx)(F,{variant:"secondary",children:r("Covered by {procedure}",{procedure:x.procedure})}),d!==void 0&&(0,t.jsx)(E,{className:"h-auto justify-start p-0 text-[11px]","data-testid":`pm-probe-${p.table}-${_}`,onClick:n(()=>{d(p.table,_,x.path??"")},"onClick"),size:"xs",type:"button",variant:"ghost",children:r("Probe this")})]})},_)}),(0,t.jsx)(le,{children:p.maskedColumns.size===0?(0,t.jsx)("span",{"aria-hidden":"true",className:"text-muted-foreground",children:"\u2014"}):(0,t.jsx)("span",{className:"flex flex-wrap gap-1",children:[...p.maskedColumns].map(Le)})})]},p.table))})]})]}),a[6]=b.data,a[7]=g.data,a[8]=d,a[9]=m,a[10]=r,a[11]=v}else v=a[11];return v},"De");function Le(e){return(0,t.jsx)(F,{variant:"outline",children:e},e)}n(Le,"Le");var je=xe(X.runAs),Me=new Set(["FORBIDDEN","RLS_REQUIRED","UNAUTHORIZED"]),Ue=n(e=>{let a=e?.code;return typeof a=="string"?a:void 0},"Me"),qe=n(()=>{let e=oe();return async({args:a,functionPath:i,shardKey:d="",userId:r})=>{if(r.trim()==="")return{kind:"invalid",message:"No identity to probe: enter the userId whose access you want to test."};let s=je;try{return{kind:"allowed",value:await e.query(s,{args:a,functionPath:i,userId:r},ye(d))}}catch(o){let m=o instanceof Error?o.message:String(o),l=Ue(o);return l!==void 0&&Me.has(l)?{kind:"denied",message:m}:{kind:"errored",message:m}}}},"ze"),We=n(e=>e===void 0?"undefined":JSON.stringify(e,be,2),"je"),Je=n(({functions:e,prefill:a,runAsIdentity:i=!1}={})=>{let d=oe(),r=V(),s=qe(),[o,m]=(0,f.useState)(null),[l,g]=(0,f.useState)(null),h=e??o??[],[b,v]=(0,f.useState)(""),[N,z]=(0,f.useState)("{}"),[j,C]=(0,f.useState)(""),[k,I]=(0,f.useState)(""),[R,w]=(0,f.useState)(!1),[u,p]=(0,f.useState)(null),[_,x]=(0,f.useState)(null),T=(0,f.useRef)(-1),P=(0,f.useRef)(0);(0,f.useEffect)(()=>{if(e!==void 0)return;let c=!1;return d.listFunctions().then(y=>(c||m(y),y)).catch(y=>{c||g(ge(y))}),()=>{c=!0}},[d,e]),(0,f.useEffect)(()=>{if(a===void 0||T.current===a.nonce)return;T.current=a.nonce,P.current+=1;let c=a.functionPath;queueMicrotask(()=>{v(c),p(null)})},[a]);let S=b===""?h[0]?.path??"":b,D=n(async()=>{if(S==="")return;let c;try{c=N.trim()===""?{}:me(JSON.parse(N))}catch(A){x(r("Invalid JSON args: {message}",{message:A.message})),p(null);return}P.current+=1;let y=P.current;x(null),w(!0);try{let A=await s({args:c,functionPath:S,shardKey:j.trim(),userId:k.trim()});y===P.current&&p(A)}finally{w(!1)}},"F"),Q=n(()=>{te(D())},"K"),O=n(c=>{v(c.target.value)},"O"),L=n(c=>{z(c.target.value)},"D"),G=n(c=>{I(c.target.value)},"Y");return(0,t.jsxs)("div",{className:"flex flex-col gap-3","data-testid":"lunora-permissions-playground",children:[l!==null&&(0,t.jsx)("p",{className:"text-sm text-destructive","data-testid":"pp-discover-error",role:"alert",children:l}),!i&&(0,t.jsx)(de,{description:r("Dev only: runs the selected function as this user over the admin gate so you can test auth and RLS."),testId:"pp-gate",title:r("Set `runAsIdentity` to forge an identity and probe access.")}),(0,t.jsxs)("div",{className:"flex flex-col gap-3 rounded-md border border-border p-3",children:[(0,t.jsxs)("div",{className:"flex flex-col gap-1.5",children:[(0,t.jsx)($,{htmlFor:"pp-function",children:r("Function")}),(0,t.jsx)("select",{"aria-label":r("Function"),className:"flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-xs outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50","data-testid":"pp-function",id:"pp-function",onChange:O,value:S,children:h.map(c=>(0,t.jsxs)("option",{value:c.path,children:[c.path," (",c.kind,")"]},c.path))})]}),(0,t.jsxs)("div",{className:"flex flex-col gap-1.5",children:[(0,t.jsx)($,{htmlFor:"pp-args",children:r("Arguments")}),(0,t.jsx)(Se,{"aria-label":r("Arguments"),className:"font-mono text-xs","data-testid":"pp-args",id:"pp-args",onChange:L,value:N})]}),(0,t.jsx)(ve,{onChange:C,testId:"pp-shard",value:j}),(0,t.jsxs)("div",{className:"flex flex-col gap-1.5",children:[(0,t.jsx)($,{htmlFor:"pp-user",children:r("Run as (userId)")}),(0,t.jsx)(M,{"aria-label":r("Identity (userId) to run as"),className:"font-mono text-xs","data-testid":"pp-user",id:"pp-user",onChange:G,placeholder:r("Required \u2014 the identity to probe as"),value:k})]}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(E,{"data-testid":"pp-run",disabled:!i||R||S==="",onClick:Q,type:"button",children:r(R?"Probing\u2026":"Run probe")}),k.trim()!==""&&(0,t.jsx)(F,{"data-testid":"pp-as-badge",variant:"secondary",children:r("as {userId}",{userId:k.trim()})})]})]}),_!==null&&(0,t.jsx)("p",{className:"text-sm text-destructive","data-testid":"pp-args-error",role:"alert",children:_}),u!==null&&u.kind==="allowed"&&(0,t.jsxs)("div",{className:"flex flex-col gap-2","data-testid":"pp-outcome-allowed",children:[(0,t.jsx)(F,{variant:"secondary",children:r("Allowed")}),(0,t.jsx)("pre",{className:"overflow-auto rounded-md border border-border bg-muted/50 p-3 font-mono text-xs","data-testid":"pp-result",children:We(u.value)})]}),u!==null&&u.kind==="invalid"&&(0,t.jsxs)("div",{className:"flex flex-col gap-2","data-testid":"pp-outcome-invalid",children:[(0,t.jsx)(F,{variant:"outline",children:r("Not run")}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground","data-testid":"pp-invalid",role:"status",children:u.message})]}),u!==null&&u.kind==="errored"&&(0,t.jsxs)("div",{className:"flex flex-col gap-2","data-testid":"pp-outcome-errored",children:[(0,t.jsx)(F,{variant:"outline",children:r("Errored")}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:r("The call failed for a reason that is not an access verdict, so it says nothing about the policy.")}),(0,t.jsx)("pre",{className:"overflow-auto rounded-md border border-border bg-muted/50 p-3 font-mono text-xs","data-testid":"pp-errored",role:"alert",children:u.message})]}),u!==null&&u.kind==="denied"&&(0,t.jsxs)("div",{className:"flex flex-col gap-2","data-testid":"pp-outcome-denied",children:[(0,t.jsx)(F,{variant:"destructive",children:r("Denied")}),(0,t.jsx)("pre",{className:"overflow-auto rounded-md border border-border bg-muted/50 p-3 font-mono text-xs text-destructive","data-testid":"pp-denied",role:"alert",children:u.message})]})]})},"qe"),Be="/__lunora/policy-scaffold",He={"already-wired":"That procedure already has an rls(...) policy wired in.","file-exists":"A policy file with that name already exists \u2014 pick another name or edit it by hand.","invalid-identifier":"Name, table, and policy-set must be plain identifiers (letters, digits, _ or $).","unknown-procedure":"No exported procedure was found at that file path.","unsupported-procedure-shape":"That procedure uses the bare query({\u2026}) form \u2014 convert it to the builder form (c.use(\u2026).query(\u2026)) before wiring RLS."},Ke=n(async e=>{let a=await fetch(Be,{body:JSON.stringify(e),headers:{"Content-Type":"application/json"},method:"POST"}),i=await a.json();if(i.needsManualEdit===!0)return{kind:"needs-manual-edit",message:i.message??"This change must be made by hand."};if(a.ok)return{diagnostics:i.diagnostics??[],kind:"ok",label:i.fileName??i.exportName??""};let d=i.error;return{kind:"error",message:d===void 0?`policy scaffold failed (${String(a.status)})`:He[d]??d}},"Qe"),_e={exportName:"",filePath:"",policyName:"",policies:"",tableName:""},Qe=n(()=>{let e=(0,pe.c)(69),a=V(),[i,d]=(0,f.useState)(null),[r,s]=(0,f.useState)(!1),[o,m]=(0,f.useState)(null),[l,g]=(0,f.useState)(_e),h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h=n(ee=>{let K=ee.target.name,{value:Y}=ee.target;g(Ae=>({...Ae,[K]:Y}))},"u"),e[0]=h):h=e[0];let b=h,v;e[1]===Symbol.for("react.memo_cache_sentinel")?(v=n(()=>{d(null),g(_e)},"v"),e[1]=v):v=e[1];let N=v,z;e[2]===Symbol.for("react.memo_cache_sentinel")?(z=n(async ee=>{s(!0),m(null);try{let K=await Ke(ee);m(K),K.kind==="ok"&&N()}catch(K){let Y=K;m({kind:"error",message:Y instanceof Error?Y.message:String(Y)})}s(!1)},"R"),e[2]=z):z=e[2];let j=z,C;e[3]!==l.policyName||e[4]!==l.tableName?(C=n(()=>{te(j({kind:"scaffoldPolicy",name:l.policyName.trim(),table:l.tableName.trim()}))},"P"),e[3]=l.policyName,e[4]=l.tableName,e[5]=C):C=e[5];let k=C,I;e[6]!==l.exportName||e[7]!==l.filePath||e[8]!==l.policies?(I=n(()=>{te(j({exportName:l.exportName.trim(),filePath:l.filePath.trim(),kind:"wireRls",policies:l.policies.trim()}))},"A"),e[6]=l.exportName,e[7]=l.filePath,e[8]=l.policies,e[9]=I):I=e[9];let R=I,w;e[10]===Symbol.for("react.memo_cache_sentinel")?(w=n(()=>{m(null),d("scaffold")},"S"),e[10]=w):w=e[10];let u=w,p;e[11]===Symbol.for("react.memo_cache_sentinel")?(p=n(()=>{m(null),d("wire")},"m"),e[11]=p):p=e[11];let _=p,x;e[12]!==a?(x=a("Scaffold access rules"),e[12]=a,e[13]=x):x=e[13];let T;e[14]!==x?(T=(0,t.jsx)(ue,{children:x}),e[14]=x,e[15]=T):T=e[15];let P;e[16]!==a?(P=a("Writes a new deny-by-default policy file under lunora/, or wires one into a procedure, then reruns codegen. Local dev only."),e[16]=a,e[17]=P):P=e[17];let S;e[18]!==P?(S=(0,t.jsx)(he,{children:P}),e[18]=P,e[19]=S):S=e[19];let D;e[20]!==S||e[21]!==T?(D=(0,t.jsxs)(fe,{children:[T,S]}),e[20]=S,e[21]=T,e[22]=D):D=e[22];let Q=i==="scaffold"?"default":"outline",O;e[23]!==a?(O=a("New policy file"),e[23]=a,e[24]=O):O=e[24];let L;e[25]!==Q||e[26]!==O?(L=(0,t.jsx)(E,{"data-testid":"policy-scaffolder-new",onClick:u,size:"xs",type:"button",variant:Q,children:O}),e[25]=Q,e[26]=O,e[27]=L):L=e[27];let G=i==="wire"?"default":"outline",c;e[28]!==a?(c=a("Wire into a procedure"),e[28]=a,e[29]=c):c=e[29];let y;e[30]!==G||e[31]!==c?(y=(0,t.jsx)(E,{"data-testid":"policy-scaffolder-wire",onClick:_,size:"xs",type:"button",variant:G,children:c}),e[30]=G,e[31]=c,e[32]=y):y=e[32];let A;e[33]!==L||e[34]!==y?(A=(0,t.jsxs)("div",{className:"flex flex-wrap gap-2",children:[L,y]}),e[33]=L,e[34]=y,e[35]=A):A=e[35];let U;e[36]!==r||e[37]!==l.policyName||e[38]!==l.tableName||e[39]!==i||e[40]!==k||e[41]!==a?(U=i==="scaffold"&&(0,t.jsxs)("div",{className:"mt-3 flex flex-wrap items-end gap-2","data-testid":"policy-scaffolder-new-form",children:[(0,t.jsxs)("div",{className:"flex flex-col gap-1 text-xs",children:[(0,t.jsx)($,{htmlFor:"policy-scaffolder-name",children:a("Policy name")}),(0,t.jsx)(M,{"data-testid":"policy-scaffolder-name",id:"policy-scaffolder-name",name:"policyName",onChange:b,value:l.policyName})]}),(0,t.jsxs)("div",{className:"flex flex-col gap-1 text-xs",children:[(0,t.jsx)($,{htmlFor:"policy-scaffolder-table",children:a("Table name")}),(0,t.jsx)(M,{"data-testid":"policy-scaffolder-table",id:"policy-scaffolder-table",name:"tableName",onChange:b,value:l.tableName})]}),(0,t.jsx)(E,{"data-testid":"policy-scaffolder-create",disabled:r||l.policyName.trim()===""||l.tableName.trim()==="",onClick:k,size:"xs",type:"button",children:a(r?"Creating\u2026":"Create policy file")}),(0,t.jsx)(E,{onClick:N,size:"xs",type:"button",variant:"ghost",children:a("Cancel")})]}),e[36]=r,e[37]=l.policyName,e[38]=l.tableName,e[39]=i,e[40]=k,e[41]=a,e[42]=U):U=e[42];let q;e[43]!==r||e[44]!==l.exportName||e[45]!==l.filePath||e[46]!==l.policies||e[47]!==i||e[48]!==R||e[49]!==a?(q=i==="wire"&&(0,t.jsxs)("div",{className:"mt-3 flex flex-wrap items-end gap-2","data-testid":"policy-scaffolder-wire-form",children:[(0,t.jsxs)("div",{className:"flex flex-col gap-1 text-xs",children:[(0,t.jsx)($,{htmlFor:"policy-scaffolder-file",children:a("Procedure file path")}),(0,t.jsx)(M,{"data-testid":"policy-scaffolder-file",id:"policy-scaffolder-file",name:"filePath",onChange:b,value:l.filePath})]}),(0,t.jsxs)("div",{className:"flex flex-col gap-1 text-xs",children:[(0,t.jsx)($,{htmlFor:"policy-scaffolder-export",children:a("Exported procedure")}),(0,t.jsx)(M,{"data-testid":"policy-scaffolder-export",id:"policy-scaffolder-export",name:"exportName",onChange:b,value:l.exportName})]}),(0,t.jsxs)("div",{className:"flex flex-col gap-1 text-xs",children:[(0,t.jsx)($,{htmlFor:"policy-scaffolder-policies",children:a("Policy set identifier")}),(0,t.jsx)(M,{"data-testid":"policy-scaffolder-policies",id:"policy-scaffolder-policies",name:"policies",onChange:b,value:l.policies})]}),(0,t.jsx)(E,{"data-testid":"policy-scaffolder-apply",disabled:r||l.filePath.trim()===""||l.exportName.trim()===""||l.policies.trim()==="",onClick:R,size:"xs",type:"button",children:a(r?"Wiring\u2026":"Wire RLS")}),(0,t.jsx)(E,{onClick:N,size:"xs",type:"button",variant:"ghost",children:a("Cancel")})]}),e[43]=r,e[44]=l.exportName,e[45]=l.filePath,e[46]=l.policies,e[47]=i,e[48]=R,e[49]=a,e[50]=q):q=e[50];let W;e[51]!==o?(W=o?.kind==="error"&&(0,t.jsx)("p",{className:"mt-3 text-sm text-destructive","data-testid":"policy-scaffolder-error",role:"alert",children:o.message}),e[51]=o,e[52]=W):W=e[52];let J;e[53]!==o?.kind||e[54]!==a?(J=o?.kind==="needs-manual-edit"&&(0,t.jsx)("p",{className:"mt-3 text-sm text-amber-600 dark:text-amber-500","data-testid":"policy-scaffolder-manual",role:"alert",children:a("This change must be made by hand \u2014 the scaffolder only adds new, deny-by-default rules.")}),e[53]=o?.kind,e[54]=a,e[55]=J):J=e[55];let B;e[56]!==o||e[57]!==a?(B=o?.kind==="ok"&&(0,t.jsxs)("div",{className:"mt-3 flex flex-col gap-1","data-testid":"policy-scaffolder-ok",children:[(0,t.jsx)("p",{className:"text-sm text-emerald-600 dark:text-emerald-500",children:a("Scaffolded {label} and reran codegen. Fill in the `when` predicates before relying on it.",{label:o.label})}),o.diagnostics.length>0&&(0,t.jsx)("ul",{className:"flex flex-col gap-0.5","data-testid":"policy-scaffolder-diagnostics",children:o.diagnostics.map(Ge)})]}),e[56]=o,e[57]=a,e[58]=B):B=e[58];let H;e[59]!==A||e[60]!==U||e[61]!==q||e[62]!==W||e[63]!==J||e[64]!==B?(H=(0,t.jsxs)(ne,{children:[A,U,q,W,J,B]}),e[59]=A,e[60]=U,e[61]=q,e[62]=W,e[63]=J,e[64]=B,e[65]=H):H=e[65];let Z;return e[66]!==D||e[67]!==H?(Z=(0,t.jsxs)(se,{"data-testid":"policy-scaffolder",size:"sm",children:[D,H]}),e[66]=D,e[67]=H,e[68]=Z):Z=e[68],Z},"He");function Ge(e){return(0,t.jsx)("li",{className:"font-mono text-[11px] text-destructive",children:e},e)}n(Ge,"Je");var ft=n(({functions:e,runAsIdentity:a=!1,schemaEditable:i=!1}={})=>{let d=V(),[r,s]=(0,f.useState)(void 0),o=n((m,l,g)=>{g!==""&&s(h=>({functionPath:g,nonce:(h?.nonce??0)+1}))},"o");return(0,t.jsxs)("div",{className:"flex flex-col gap-8","data-testid":"lunora-permissions",children:[(0,t.jsxs)("section",{className:"flex flex-col gap-3",children:[(0,t.jsx)("header",{className:"border-b border-border px-4 py-3",children:(0,t.jsx)("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:d("Permissions")})}),(0,t.jsx)(Oe,{onProbe:o})]}),(0,t.jsx)("section",{className:"flex flex-col gap-3",children:(0,t.jsxs)(se,{className:"gap-0 py-0",children:[(0,t.jsx)("header",{className:"border-b border-border px-4 py-3",children:(0,t.jsx)("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:d("Probe")})}),(0,t.jsxs)(ne,{className:"px-4 py-4",children:[(0,t.jsx)("p",{className:"mb-3 text-sm text-muted-foreground",children:d("Pick a function and an identity, then run it to see the access outcome.")}),(0,t.jsx)(Je,{functions:e,prefill:r,runAsIdentity:a})]})]})}),i&&(0,t.jsx)("section",{className:"flex flex-col gap-2",children:(0,t.jsx)(Qe,{})})]})},"ut");export{ft as PermissionsPanel};
@@ -1 +1 @@
1
- import{a as be,b as fe,c as xe,d as Ne,e as Ce}from"./chunk-5QR2SQIS.js";import"./chunk-NRP22GKC.js";import"./chunk-OPM7ESDV.js";import{a as ce}from"./chunk-FPI7AMQJ.js";import{a as ue}from"./chunk-7RKB5KS7.js";import{a as q}from"./chunk-37WYCOQ2.js";import{g as me,h as ve,i as pe,j as ye}from"./chunk-NNP5BWBX.js";import"./chunk-XGCIDUJF.js";import"./chunk-AJV3ZKEY.js";import"./chunk-CCDX5RYT.js";import"./chunk-OYCUPD3Q.js";import"./chunk-NXQW5E6W.js";import"./chunk-UC7MNI2F.js";import"./chunk-SA2OGF3F.js";import"./chunk-NGVP66OH.js";import"./chunk-GHQ2VDI2.js";import"./chunk-WJRYEML4.js";import"./chunk-FUYEZFBP.js";import"./chunk-RGMVGZV4.js";import"./chunk-OQ6I6OXT.js";import{i as ae}from"./chunk-E4PXACVL.js";import"./chunk-MVWZMWPD.js";import"./chunk-SJQERRSZ.js";import"./chunk-7Y3SY37W.js";import{a as $}from"./chunk-7G4Z6Q7X.js";import"./chunk-3YXASVTP.js";import"./chunk-AUAECCXB.js";import{b as he}from"./chunk-Q6ED4KUL.js";import"./chunk-BOMPSVRC.js";import"./chunk-55UGUCQ6.js";import"./chunk-4ZEL6BYL.js";import"./chunk-VRWHCG2V.js";import{l as G}from"./chunk-ICDMV4MP.js";import"./chunk-QAQDMS6R.js";import"./chunk-FQPBYMII.js";import{a as ke}from"./chunk-RWVIV3U7.js";import{a as se,b as ie,c as oe,d as Q,e as X,f as Y}from"./chunk-HCTJKP5J.js";import{a as re,e as ne}from"./chunk-2IKDEUCX.js";import{d as R,h as Z,l as ge,p as z,s as de}from"./chunk-HJHSQPHW.js";import{a as i,d as le,e as Oe,f as _e,g as De}from"./chunk-I26MS5PJ.js";var P=le(Oe(),1);var ee=le(_e(),1);var a=le(De(),1);var Be=i(l=>{let e=l.trim();if(e==="")return;let n=Number(e);return Number.isFinite(n)&&n>0?Math.floor(n):void 0},"Be"),Le=i(l=>l===void 0?"\u2014":new Date(l*1e3).toISOString(),"Oe"),Je=i(l=>new TextEncoder().encode(l).length,"Ae"),Fe=i(l=>{if(l.trim()!=="")try{return JSON.stringify(JSON.parse(l),void 0,2)}catch{return}},"ge"),Ke=i(l=>{if(l.trim()==="")return!0;try{return JSON.parse(l),!0}catch{return!1}},"xe"),Ee=[{key:"seconds",seconds:1},{key:"minutes",seconds:60},{key:"hours",seconds:3600},{key:"days",seconds:86400}],we=i((l,e)=>{let n=l.trim();if(n==="")return"";let u=Number(n),s=Ee.find(p=>p.key===e)?.seconds??1;return Number.isFinite(u)&&u>0?String(Math.round(u*s)):n},"ue"),Ve=i(l=>{let e=l.trim();if(e==="")return!0;let n=Number(e);return Number.isInteger(n)&&n>=60},"Ce"),Te=i((l,e,n,u)=>{let s=Be(l.ttl);return{expiration:s===void 0?u:void 0,expirationTtl:s,key:e,metadata:l.metadata.trim()===""?void 0:JSON.parse(l.metadata),namespace:n,value:l.value}},"Se"),Me=i(l=>{let e=(0,ee.c)(60),{helper:n,id:u,invalid:s,onChange:p,testId:o}=l,t=R(),[r,y]=(0,P.useState)(""),[c,x]=(0,P.useState)("seconds"),b;e[0]!==p||e[1]!==c?(b=i(f=>{y(f.target.value),p(we(f.target.value,c))},"k"),e[0]=p,e[1]=c,e[2]=b):b=e[2];let _=b,V;e[3]!==r||e[4]!==p?(V=i(f=>{f!==null&&(x(f),p(we(r,f)))},"K"),e[3]=r,e[4]=p,e[5]=V):V=e[5];let T=V,h;e[6]!==t?(h=t("days"),e[6]=t,e[7]=h):h=e[7];let v;e[8]!==t?(v=t("hours"),e[8]=t,e[9]=v):v=e[9];let k;e[10]!==t?(k=t("minutes"),e[10]=t,e[11]=k):k=e[11];let N;e[12]!==t?(N=t("seconds"),e[12]=t,e[13]=N):N=e[13];let C;e[14]!==h||e[15]!==v||e[16]!==k||e[17]!==N?(C={days:h,hours:v,minutes:k,seconds:N},e[14]=h,e[15]=v,e[16]=k,e[17]=N,e[18]=C):C=e[18];let w=C,g;e[19]!==t?(g=t("Expires after"),e[19]=t,e[20]=g):g=e[20];let S;e[21]!==u||e[22]!==g?(S=(0,a.jsx)(q,{className:"text-xs",htmlFor:u,children:g}),e[21]=u,e[22]=g,e[23]=S):S=e[23];let E;e[24]!==t?(E=t("No expiration"),e[24]=t,e[25]=E):E=e[25];let B;e[26]!==r||e[27]!==u||e[28]!==s||e[29]!==_||e[30]!==E||e[31]!==o?(B=(0,a.jsx)(ae,{"aria-invalid":s,className:"flex-1","data-testid":o,id:u,inputMode:"numeric",onChange:_,placeholder:E,value:r}),e[26]=r,e[27]=u,e[28]=s,e[29]=_,e[30]=E,e[31]=o,e[32]=B):B=e[32];let M;e[33]!==t?(M=t("TTL unit"),e[33]=t,e[34]=M):M=e[34];let J=`${o}-unit`,L;e[35]===Symbol.for("react.memo_cache_sentinel")?(L=(0,a.jsx)(fe,{}),e[35]=L):L=e[35];let I;e[36]!==M||e[37]!==J?(I=(0,a.jsx)(xe,{"aria-label":M,className:"w-[7.5rem]","data-testid":J,children:L}),e[36]=M,e[37]=J,e[38]=I):I=e[38];let d;e[39]!==w?(d=Ee.map(f=>(0,a.jsx)(Ce,{value:f.key,children:w[f.key]},f.key)),e[39]=w,e[40]=d):d=e[40];let m;e[41]!==d?(m=(0,a.jsx)(Ne,{children:d}),e[41]=d,e[42]=m):m=e[42];let F;e[43]!==T||e[44]!==I||e[45]!==m||e[46]!==c?(F=(0,a.jsxs)(be,{onValueChange:T,value:c,children:[I,m]}),e[43]=T,e[44]=I,e[45]=m,e[46]=c,e[47]=F):F=e[47];let O;e[48]!==B||e[49]!==F?(O=(0,a.jsxs)("div",{className:"flex gap-2",children:[B,F]}),e[48]=B,e[49]=F,e[50]=O):O=e[50];let K;e[51]!==n||e[52]!==s||e[53]!==t||e[54]!==o?(K=s?(0,a.jsx)("p",{className:"text-xs text-destructive","data-testid":`${o}-invalid`,children:t("TTL must be at least 60 seconds.")}):n!==void 0&&(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:n}),e[51]=n,e[52]=s,e[53]=t,e[54]=o,e[55]=K):K=e[55];let D;return e[56]!==O||e[57]!==K||e[58]!==S?(D=(0,a.jsxs)("div",{className:"mb-3 grid gap-1",children:[S,O,K]}),e[56]=O,e[57]=K,e[58]=S,e[59]=D):D=e[59],D},"we"),Ie=i(l=>{let e=(0,ee.c)(36),{id:n,invalidTestId:u,onChange:s,testId:p,valid:o,value:t}=l,r=R(),y;e[0]!==t?(y=Fe(t),e[0]=t,e[1]=y):y=e[1];let c=y,x;e[2]!==r?(x=r("Metadata (JSON)"),e[2]=r,e[3]=x):x=e[3];let b;e[4]!==n||e[5]!==x?(b=(0,a.jsx)(q,{className:"text-xs",htmlFor:n,children:x}),e[4]=n,e[5]=x,e[6]=b):b=e[6];let _=`${p}-format`,V=c===void 0,T;e[7]!==c||e[8]!==s?(T=i(()=>{c!==void 0&&s(c)},"V"),e[7]=c,e[8]=s,e[9]=T):T=e[9];let h;e[10]!==r?(h=r("Format JSON"),e[10]=r,e[11]=h):h=e[11];let v;e[12]!==_||e[13]!==V||e[14]!==T||e[15]!==h?(v=(0,a.jsx)($,{"data-testid":_,disabled:V,onClick:T,size:"sm",variant:"outline",children:h}),e[12]=_,e[13]=V,e[14]=T,e[15]=h,e[16]=v):v=e[16];let k;e[17]!==b||e[18]!==v?(k=(0,a.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[b,v]}),e[17]=b,e[18]=v,e[19]=k):k=e[19];let N=!o,C;e[20]!==s?(C=i(E=>{s(E.target.value)},"N"),e[20]=s,e[21]=C):C=e[21];let w;e[22]!==n||e[23]!==N||e[24]!==C||e[25]!==p||e[26]!==t?(w=(0,a.jsx)(ce,{"aria-invalid":N,className:"min-h-[4rem] font-mono text-xs","data-testid":p,id:n,onChange:C,value:t}),e[22]=n,e[23]=N,e[24]=C,e[25]=p,e[26]=t,e[27]=w):w=e[27];let g;e[28]!==u||e[29]!==r||e[30]!==o?(g=!o&&(0,a.jsx)("p",{className:"text-xs text-destructive","data-testid":u,children:r("Metadata must be valid JSON.")}),e[28]=u,e[29]=r,e[30]=o,e[31]=g):g=e[31];let S;return e[32]!==w||e[33]!==g||e[34]!==k?(S=(0,a.jsxs)("div",{className:"mb-3 grid gap-1",children:[k,w,g]}),e[32]=w,e[33]=g,e[34]=k,e[35]=S):S=e[35],S},"Te"),Pe={busy:!1,error:null,metadata:"",name:"",ttl:"",value:""},$e=i((l,e)=>{switch(e.type){case"setField":return{...l,[e.field]:e.value};case"submitFailed":return{...l,busy:!1,error:e.error};case"submitStart":return{...l,busy:!0,error:null};default:return l}},"Je"),je=i(l=>{let e=(0,ee.c)(73),{namespace:n,onCancel:u,onCreated:s}=l,p=G(),o=R(),[t,r]=(0,P.useReducer)($e,Pe),y;e[0]!==t.metadata?(y=Ke(t.metadata),e[0]=t.metadata,e[1]=y):y=e[1];let c=y,x;e[2]!==t.ttl?(x=Ve(t.ttl),e[2]=t.ttl,e[3]=x):x=e[3];let b=x,_;e[4]!==c||e[5]!==t.busy||e[6]!==t.name||e[7]!==b?(_=t.name.trim()!==""&&c&&b&&!t.busy,e[4]=c,e[5]=t.busy,e[6]=t.name,e[7]=b,e[8]=_):_=e[8];let V=_,T;e[9]!==V||e[10]!==p||e[11]!==n||e[12]!==s||e[13]!==t.metadata||e[14]!==t.name||e[15]!==t.ttl||e[16]!==t.value?(T=i(()=>{V&&(r({type:"submitStart"}),z((async()=>{try{await p.putKvValue(Te({metadata:t.metadata,ttl:t.ttl,value:t.value},t.name,n)),s()}catch(A){r({error:Z(A),type:"submitFailed"})}})()))},"V"),e[9]=V,e[10]=p,e[11]=n,e[12]=s,e[13]=t.metadata,e[14]=t.name,e[15]=t.ttl,e[16]=t.value,e[17]=T):T=e[17];let h=T,v;e[18]!==o?(v=o("Key name"),e[18]=o,e[19]=v):v=e[19];let k;e[20]!==v?(k=(0,a.jsx)(q,{className:"text-xs",htmlFor:"kv-create-name",children:v}),e[20]=v,e[21]=k):k=e[21];let N;e[22]===Symbol.for("react.memo_cache_sentinel")?(N=i(A=>{r({field:"name",type:"setField",value:A.target.value})},"x"),e[22]=N):N=e[22];let C;e[23]!==o?(C=o("Key name"),e[23]=o,e[24]=C):C=e[24];let w;e[25]!==t.name||e[26]!==C?(w=(0,a.jsx)(ae,{autoFocus:!0,"data-testid":"kv-create-name",id:"kv-create-name",onChange:N,placeholder:C,value:t.name}),e[25]=t.name,e[26]=C,e[27]=w):w=e[27];let g;e[28]!==k||e[29]!==w?(g=(0,a.jsxs)("div",{className:"grid gap-1",children:[k,w]}),e[28]=k,e[29]=w,e[30]=g):g=e[30];let S;e[31]!==o?(S=o("Value"),e[31]=o,e[32]=S):S=e[32];let E;e[33]!==S?(E=(0,a.jsx)(q,{className:"text-xs",htmlFor:"kv-create-value",children:S}),e[33]=S,e[34]=E):E=e[34];let B;e[35]===Symbol.for("react.memo_cache_sentinel")?(B=i(A=>{r({field:"value",type:"setField",value:A.target.value})},"O"),e[35]=B):B=e[35];let M;e[36]!==t.value?(M=(0,a.jsx)(ce,{className:"min-h-[6rem] font-mono text-xs","data-testid":"kv-create-value",id:"kv-create-value",onChange:B,value:t.value}),e[36]=t.value,e[37]=M):M=e[37];let J;e[38]!==E||e[39]!==M?(J=(0,a.jsxs)("div",{className:"grid gap-1",children:[E,M]}),e[38]=E,e[39]=M,e[40]=J):J=e[40];let L=!b,I;e[41]===Symbol.for("react.memo_cache_sentinel")?(I=i(A=>{r({field:"ttl",type:"setField",value:A})},"_"),e[41]=I):I=e[41];let d;e[42]!==L?(d=(0,a.jsx)(Me,{id:"kv-create-ttl",invalid:L,onChange:I,testId:"kv-create-ttl"}),e[42]=L,e[43]=d):d=e[43];let m;e[44]===Symbol.for("react.memo_cache_sentinel")?(m=i(A=>{r({field:"metadata",type:"setField",value:A})},"u"),e[44]=m):m=e[44];let F;e[45]!==c||e[46]!==t.metadata?(F=(0,a.jsx)(Ie,{id:"kv-create-metadata",invalidTestId:"kv-create-metadata-invalid",onChange:m,testId:"kv-create-metadata",valid:c,value:t.metadata}),e[45]=c,e[46]=t.metadata,e[47]=F):F=e[47];let O=!V,K;e[48]!==t.busy||e[49]!==o?(K=t.busy?o("Creating\u2026"):o("Create key"),e[48]=t.busy,e[49]=o,e[50]=K):K=e[50];let D;e[51]!==h||e[52]!==O||e[53]!==K?(D=(0,a.jsx)($,{"data-testid":"kv-create-submit",disabled:O,onClick:h,children:K}),e[51]=h,e[52]=O,e[53]=K,e[54]=D):D=e[54];let f=t.busy,j;e[55]!==o?(j=o("Cancel"),e[55]=o,e[56]=j):j=e[56];let H;e[57]!==u||e[58]!==t.busy||e[59]!==j?(H=(0,a.jsx)($,{"data-testid":"kv-create-cancel",disabled:f,onClick:u,variant:"outline",children:j}),e[57]=u,e[58]=t.busy,e[59]=j,e[60]=H):H=e[60];let U;e[61]!==D||e[62]!==H?(U=(0,a.jsxs)("div",{className:"flex flex-wrap gap-2",children:[D,H]}),e[61]=D,e[62]=H,e[63]=U):U=e[63];let W;e[64]!==t.error?(W=t.error!==null&&(0,a.jsx)("p",{className:"text-sm text-destructive","data-testid":"kv-create-error",role:"alert",children:t.error}),e[64]=t.error,e[65]=W):W=e[65];let te;return e[66]!==g||e[67]!==J||e[68]!==d||e[69]!==F||e[70]!==U||e[71]!==W?(te=(0,a.jsxs)("div",{className:"grid gap-3 px-4 pb-4","data-testid":"kv-create-form",children:[g,J,d,F,U,W]}),e[66]=g,e[67]=J,e[68]=d,e[69]=F,e[70]=U,e[71]=W,e[72]=te):te=e[72],te},"Pe"),Ae={busy:"",editedMetadata:"",editedTtl:"",editedValue:"",loadError:null,loading:!0,value:null,writeError:null},ze=i((l,e)=>{switch(e.type){case"deleteStart":return{...l,busy:"deleting",writeError:null};case"editMetadata":return{...l,editedMetadata:e.value};case"editTtl":return{...l,editedTtl:e.value};case"editValue":return{...l,editedValue:e.value};case"loaded":return{...l,editedMetadata:e.metadata===null||e.metadata===void 0?"":JSON.stringify(e.metadata,null,2),editedValue:e.value??"",loading:!1,value:e.value};case"loadFailed":return{...l,loadError:e.error,loading:!1};case"saveOk":return{...l,busy:"",value:l.editedValue};case"saveStart":return{...l,busy:"saving",writeError:null};case"writeFailed":return{...l,busy:"",writeError:e.error};default:return l}},"je"),He=i(l=>{let e=(0,ee.c)(67),{expiration:n,keyName:u,namespace:s,onDeleted:p}=l,o=G(),t=R(),[r,y]=(0,P.useReducer)(ze,Ae),c,x;e[0]!==o||e[1]!==u||e[2]!==s?(c=i(()=>{let f={cancelled:!1};return z((async()=>{try{let j=await o.getKvValue({key:u,namespace:s});f.cancelled||y({metadata:j.metadata,type:"loaded",value:j.value})}catch(j){let H=j;f.cancelled||y({error:Z(H),type:"loadFailed"})}})()),()=>{f.cancelled=!0}},"o"),x=[o,s,u],e[0]=o,e[1]=u,e[2]=s,e[3]=c,e[4]=x):(c=e[3],x=e[4]),(0,P.useEffect)(c,x);let b;e[5]===Symbol.for("react.memo_cache_sentinel")?(b=i(f=>{y({type:"editValue",value:f.target.value})},"k"),e[5]=b):b=e[5];let _=b,V;e[6]===Symbol.for("react.memo_cache_sentinel")?(V=i(f=>{y({type:"editMetadata",value:f})},"K"),e[6]=V):V=e[6];let T=V,h;e[7]!==r.editedValue?(h=Fe(r.editedValue),e[7]=r.editedValue,e[8]=h):h=e[8];let v=h,k;e[9]!==r.editedMetadata?(k=Ke(r.editedMetadata),e[9]=r.editedMetadata,e[10]=k):k=e[10];let N=k,C;e[11]!==r.editedTtl?(C=Ve(r.editedTtl),e[11]=r.editedTtl,e[12]=C):C=e[12];let w=C,g;e[13]!==v?(g=i(()=>{v!==void 0&&y({type:"editValue",value:v})},"y"),e[13]=v,e[14]=g):g=e[14];let S=g,E;e[15]!==o||e[16]!==n||e[17]!==u||e[18]!==N||e[19]!==s||e[20]!==r.editedMetadata||e[21]!==r.editedTtl||e[22]!==r.editedValue||e[23]!==t?(E=i(()=>{if(!N){y({error:t("Metadata must be valid JSON."),type:"writeFailed"});return}y({type:"saveStart"}),z((async()=>{try{await o.putKvValue(Te({metadata:r.editedMetadata,ttl:r.editedTtl,value:r.editedValue},u,s,n)),y({type:"saveOk"})}catch(f){y({error:Z(f),type:"writeFailed"})}})())},"F"),e[15]=o,e[16]=n,e[17]=u,e[18]=N,e[19]=s,e[20]=r.editedMetadata,e[21]=r.editedTtl,e[22]=r.editedValue,e[23]=t,e[24]=E):E=e[24];let B=E,M;e[25]!==o||e[26]!==u||e[27]!==s||e[28]!==p?(M=i(()=>{y({type:"deleteStart"}),z((async()=>{try{await o.deleteKvKey({key:u,namespace:s}),p(u)}catch(f){y({error:Z(f),type:"writeFailed"})}})())},"I"),e[25]=o,e[26]=u,e[27]=s,e[28]=p,e[29]=M):M=e[29];let J=M,L;e[30]!==u?(L=i(()=>{de(u)},"A"),e[30]=u,e[31]=L):L=e[31];let I;e[32]!==t?(I=t("Copy key"),e[32]=t,e[33]=I):I=e[33];let d;e[34]!==L||e[35]!==I?(d=(0,a.jsx)("div",{className:"mb-2 flex justify-end",children:(0,a.jsx)($,{"data-testid":"kv-copy-key-btn",onClick:L,size:"sm",variant:"outline",children:I})}),e[34]=L,e[35]=I,e[36]=d):d=e[36];let m;e[37]!==r.loadError?(m=r.loadError!==null&&(0,a.jsx)("p",{className:"mb-2 text-sm text-destructive","data-testid":"kv-value-error",role:"alert",children:r.loadError}),e[37]=r.loadError,e[38]=m):m=e[38];let F;e[39]!==r.loading||e[40]!==t?(F=r.loading&&(0,a.jsx)("p",{className:"text-sm text-muted-foreground","data-testid":"kv-value-loading",children:t("Loading\u2026")}),e[39]=r.loading,e[40]=t,e[41]=F):F=e[41];let O;e[42]!==v||e[43]!==N||e[44]!==J||e[45]!==S||e[46]!==B||e[47]!==r.busy||e[48]!==r.editedMetadata||e[49]!==r.editedValue||e[50]!==r.loading||e[51]!==r.value||e[52]!==r.writeError||e[53]!==t||e[54]!==w?(O=!r.loading&&r.value!==null&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"mb-1 flex flex-wrap items-center gap-2",children:[(0,a.jsx)(q,{className:"text-xs",htmlFor:"kv-value-editor",children:t("Value")}),v!==void 0&&(0,a.jsx)(he,{variant:"secondary",children:t("JSON")}),(0,a.jsx)("span",{className:"ml-auto text-xs tabular-nums text-muted-foreground","data-testid":"kv-value-size",children:ge(Je(r.editedValue))})]}),(0,a.jsx)("textarea",{"aria-label":t("KV value"),className:"mb-2 min-h-[8rem] w-full rounded border border-border bg-muted/30 p-2 font-mono text-xs","data-testid":"kv-value-editor",id:"kv-value-editor",onChange:_,value:r.editedValue}),(0,a.jsxs)("div",{className:"mb-3 flex flex-wrap gap-2",children:[(0,a.jsx)($,{"data-testid":"kv-format-btn",disabled:v===void 0,onClick:S,size:"sm",variant:"outline",children:t("Format JSON")}),(0,a.jsx)($,{"data-testid":"kv-copy-value-btn",onClick:i(()=>{de(r.editedValue)},"onClick"),size:"sm",variant:"outline",children:t("Copy value")})]}),(0,a.jsx)(Me,{helper:t("Leave blank to keep the current expiration."),id:"kv-ttl-input",invalid:!w,onChange:i(f=>{y({type:"editTtl",value:f})},"onChange"),testId:"kv-ttl-input"}),(0,a.jsx)(Ie,{id:"kv-metadata-editor",invalidTestId:"kv-metadata-invalid",onChange:T,testId:"kv-metadata-editor",valid:N,value:r.editedMetadata}),(0,a.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,a.jsx)($,{"data-testid":"kv-save-btn",disabled:r.busy!==""||!N||!w,onClick:B,children:r.busy==="saving"?t("Saving\u2026"):t("Save")}),(0,a.jsx)($,{"data-testid":"kv-delete-btn",disabled:r.busy!=="",onClick:J,variant:"destructive",children:r.busy==="deleting"?t("Deleting\u2026"):t("Delete")})]}),r.writeError!==null&&(0,a.jsx)("p",{className:"mt-2 text-sm text-destructive","data-testid":"kv-save-error",role:"alert",children:r.writeError})]}),e[42]=v,e[43]=N,e[44]=J,e[45]=S,e[46]=B,e[47]=r.busy,e[48]=r.editedMetadata,e[49]=r.editedValue,e[50]=r.loading,e[51]=r.value,e[52]=r.writeError,e[53]=t,e[54]=w,e[55]=O):O=e[55];let K;e[56]!==r.loadError||e[57]!==r.loading||e[58]!==r.value||e[59]!==t?(K=!r.loading&&r.value===null&&r.loadError===null&&(0,a.jsx)("p",{className:"text-sm text-muted-foreground","data-testid":"kv-absent",children:t("Key is absent or has no value.")}),e[56]=r.loadError,e[57]=r.loading,e[58]=r.value,e[59]=t,e[60]=K):K=e[60];let D;return e[61]!==d||e[62]!==m||e[63]!==F||e[64]!==O||e[65]!==K?(D=(0,a.jsxs)("div",{className:"px-4 pb-4","data-testid":"kv-value-section",children:[d,m,F,O,K]}),e[61]=d,e[62]=m,e[63]=F,e[64]=O,e[65]=K,e[66]=D):D=e[66],D},"He"),Se=100,Ze={appliedPrefix:"",bulk:[],bulkBusy:!1,bulkError:null,cursor:null,keys:null,listComplete:!1,loadError:null,loading:!1,prefixInput:"",reloadNonce:0,selectedKey:null},Re=i((l,e)=>{switch(e.type){case"appendPage":return e.generation!==l.reloadNonce?l:{...l,cursor:e.cursor,keys:[...l.keys??[],...e.keys],listComplete:e.listComplete,loading:!1};case"applyFilter":return{...l,appliedPrefix:l.prefixInput,bulk:[],bulkError:null,cursor:null,keys:null,listComplete:!1,reloadNonce:l.reloadNonce+1,selectedKey:null};case"bulkDeleted":{let n=new Set(e.deleted);return{...l,bulk:l.bulk.filter(u=>!n.has(u)),bulkBusy:!1,bulkError:e.error,keys:l.keys===null?null:l.keys.filter(u=>!n.has(u.name)),selectedKey:l.selectedKey!==null&&n.has(l.selectedKey)?null:l.selectedKey}}case"bulkDeleteStart":return{...l,bulkBusy:!0,bulkError:null};case"firstPage":return{...l,cursor:e.cursor,keys:e.keys,listComplete:e.listComplete,loading:!1};case"keyDeleted":return{...l,bulk:l.bulk.filter(n=>n!==e.name),keys:l.keys===null?null:l.keys.filter(n=>n.name!==e.name),selectedKey:null};case"loadFailed":return e.generation!==void 0&&e.generation!==l.reloadNonce?l:{...l,loadError:e.error,loading:!1};case"loadStart":return{...l,loadError:null,loading:!0};case"prefixInput":return{...l,prefixInput:e.value};case"reload":return{...l,bulk:[],bulkError:null,reloadNonce:l.reloadNonce+1,selectedKey:null};case"selectKey":return{...l,selectedKey:e.name};case"toggleAllBulk":return{...l,bulk:e.names};case"toggleBulk":return{...l,bulk:l.bulk.includes(e.name)?l.bulk.filter(n=>n!==e.name):[...l.bulk,e.name]};default:return l}},"ze"),Ue=i(({namespace:l})=>{let e=G(),n=R(),[u,s]=(0,P.useReducer)(Re,Ze),{appliedPrefix:p,bulk:o,bulkBusy:t,bulkError:r,cursor:y,keys:c,listComplete:x,loadError:b,loading:_,prefixInput:V,reloadNonce:T,selectedKey:h}=u,[v,k]=(0,P.useState)(!1);(0,P.useEffect)(()=>{let d={cancelled:!1};return z((async()=>{s({type:"loadStart"});try{let m=await e.listKvKeys({limit:Se,namespace:l,prefix:p===""?void 0:p});d.cancelled||s({cursor:m.cursor??null,keys:m.keys,listComplete:m.listComplete,type:"firstPage"})}catch(m){d.cancelled||s({error:Z(m),type:"loadFailed"})}})()),()=>{d.cancelled=!0}},[e,l,p,T]);let N=i(d=>{s({type:"prefixInput",value:d.target.value})},"x"),C=i(()=>{s({type:"applyFilter"})},"N"),w=i(d=>{s({name:d.currentTarget.dataset.key??null,type:"selectKey"})},"C"),g=i(()=>{if(y===null)return;s({type:"loadStart"});let d=T;z((async()=>{try{let m=await e.listKvKeys({cursor:y,limit:Se,namespace:l,prefix:p===""?void 0:p});s({cursor:m.cursor??null,generation:d,keys:m.keys,listComplete:m.listComplete,type:"appendPage"})}catch(m){s({error:Z(m),generation:d,type:"loadFailed"})}})())},"y"),S=i(d=>{s({name:d,type:"keyDeleted"})},"S"),E=i(d=>{s({name:d,type:"toggleBulk"})},"F"),B=i(d=>{s({names:d&&c!==null?c.map(m=>m.name):[],type:"toggleAllBulk"})},"O"),M=i(()=>{if(o.length===0)return;let d=[...o];s({type:"bulkDeleteStart"}),z((async()=>{let m=await Promise.allSettled(d.map(K=>e.deleteKvKey({key:K,namespace:l}))),F=d.filter((K,D)=>m[D]?.status==="fulfilled"),O=d.length-F.length;s({deleted:F,error:O>0?n("Failed to delete {count} keys.",{count:O}):null,type:"bulkDeleted"})})())},"I"),J=i(()=>{k(!1),s({type:"reload"})},"D"),L=c!==null&&c.length>0&&o.length===c.length,I=new Set(o);return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("section",{className:"border border-border bg-card p-3","data-testid":"kv-keys-section",children:[(0,a.jsxs)("div",{className:"mb-3 flex flex-wrap items-center gap-2",children:[(0,a.jsx)(ae,{"aria-label":n("Filter keys by prefix"),className:"min-w-[16rem] flex-1","data-testid":"kv-prefix-input",onChange:N,placeholder:n("Filter by prefix\u2026"),value:V}),(0,a.jsx)($,{"data-testid":"kv-filter-btn",disabled:_,onClick:C,children:n("Filter")}),(0,a.jsx)($,{"data-testid":"kv-new-key-btn",onClick:i(()=>{k(d=>!d)},"onClick"),variant:"outline",children:n("New key")}),o.length>0&&(0,a.jsx)($,{"data-testid":"kv-bulk-delete-btn",disabled:t,onClick:M,variant:"destructive",children:t?n("Deleting\u2026"):n("Delete {count}",{count:o.length})})]}),r!==null&&(0,a.jsx)("p",{className:"mb-2 text-sm text-destructive","data-testid":"kv-bulk-error",role:"alert",children:r}),b!==null&&(0,a.jsx)("p",{className:"text-sm text-destructive","data-testid":"kv-keys-error",role:"alert",children:b}),c!==null&&c.length===0&&!_&&(0,a.jsx)("p",{className:"text-sm text-muted-foreground","data-testid":"kv-no-keys",children:n("No keys.")}),c!==null&&c.length>0&&(0,a.jsx)(re,{className:"overflow-hidden py-0",children:(0,a.jsx)(ne,{className:"px-0",children:(0,a.jsxs)(se,{"data-testid":"kv-key-table",children:[(0,a.jsx)(ie,{children:(0,a.jsxs)(Q,{children:[(0,a.jsx)(X,{className:"w-10",children:(0,a.jsx)(ue,{"aria-label":n("Select all"),checked:L,"data-testid":"kv-select-all",onCheckedChange:B})}),(0,a.jsx)(X,{children:n("Key")}),(0,a.jsx)(X,{children:n("Expiration")})]})}),(0,a.jsx)(oe,{children:c.map(d=>(0,a.jsxs)(Q,{className:d.name===h?"border-l-2 border-l-royal-amethyst bg-muted/50":"cursor-pointer","data-key":d.name,"data-testid":`kv-key-row-${d.name}`,onClick:w,children:[(0,a.jsx)(Y,{onClick:i(m=>{m.stopPropagation()},"onClick"),children:(0,a.jsx)(ue,{"aria-label":n("Select {name}",{name:d.name}),checked:I.has(d.name),"data-testid":`kv-select-${d.name}`,onCheckedChange:i(()=>{E(d.name)},"onCheckedChange")})}),(0,a.jsx)(Y,{className:"font-mono text-xs",children:d.name}),(0,a.jsx)(Y,{className:"tabular-nums text-xs",children:Le(d.expiration)})]},d.name))})]})})}),!x&&y!==null&&(0,a.jsx)("div",{className:"mt-2",children:(0,a.jsx)($,{"data-testid":"kv-load-more",disabled:_,onClick:g,variant:"outline",children:n(_?"Loading\u2026":"Load more")})})]}),(0,a.jsx)(me,{onOpenChange:i(d=>{d||k(!1)},"onOpenChange"),open:v,children:(0,a.jsxs)(ve,{className:"w-full gap-0 overflow-y-auto sm:max-w-md","data-testid":"kv-create-sheet",side:"right",children:[(0,a.jsx)(pe,{children:(0,a.jsx)(ye,{children:n("New key")})}),(0,a.jsx)(je,{namespace:l,onCancel:i(()=>{k(!1)},"onCancel"),onCreated:J})]})}),(0,a.jsx)(me,{onOpenChange:i(d=>{d||s({name:null,type:"selectKey"})},"onOpenChange"),open:h!==null,children:(0,a.jsxs)(ve,{className:"w-full gap-0 overflow-y-auto sm:max-w-md","data-testid":"kv-editor-sheet",side:"right",children:[(0,a.jsx)(pe,{children:(0,a.jsx)(ye,{className:"truncate font-mono text-xs",children:h})}),h!==null&&(0,a.jsx)(He,{expiration:c?.find(d=>d.name===h)?.expiration,keyName:h,namespace:l,onDeleted:S},`${l}:${h}`)]})})]})},"Ue"),it=i(({loadNamespaces:l}={})=>{let e=G(),n=R(),[u,s]=(0,P.useState)(null),[p,o]=(0,P.useState)(null),[t,r]=(0,P.useState)(null);(0,P.useEffect)(()=>{let c={cancelled:!1};return z((async()=>{try{let x=await(l??(()=>e.listKvNamespaces()))();c.cancelled||(s(x),o(null),r(b=>b??x[0]?.binding??null))}catch(x){c.cancelled||(s(null),o(Z(x)))}})()),()=>{c.cancelled=!0}},[e,l]);let y=i(c=>{r(c.currentTarget.dataset.ns??null)},"f");return(0,a.jsxs)("div",{className:"flex flex-col gap-4","data-testid":"lunora-kv-browser",children:[p!==null&&(0,a.jsx)("p",{className:"text-sm text-destructive","data-testid":"kv-ns-error",role:"alert",children:p}),u!==null&&u.length===0&&(0,a.jsx)(ke,{description:n("Add a kv_namespaces binding to wrangler.jsonc \u2014 it appears here automatically, no wiring needed."),icon:(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 5h14v4H5V5Zm0 5h14v4H5v-4Zm0 5h14v4H5v-4Z"})}),testId:"kv-empty",title:n("No KV namespaces.")}),u!==null&&u.length>0&&(0,a.jsx)(re,{className:"overflow-hidden py-0",children:(0,a.jsx)(ne,{className:"px-0",children:(0,a.jsxs)(se,{"data-testid":"kv-namespace-table",children:[(0,a.jsx)(ie,{children:(0,a.jsx)(Q,{children:(0,a.jsx)(X,{children:n("Namespace")})})}),(0,a.jsx)(oe,{children:u.map(c=>(0,a.jsx)(Q,{className:c.binding===t?"border-l-2 border-l-royal-amethyst bg-muted/50":"cursor-pointer","data-ns":c.binding,"data-testid":`kv-ns-row-${c.binding}`,onClick:y,children:(0,a.jsx)(Y,{className:"font-mono text-xs",children:c.binding})},c.binding))})]})})}),t!==null&&(0,a.jsx)(Ue,{namespace:t},t)]})},"ut");export{it as KvBrowser};
1
+ import{a as be,b as fe,c as xe,d as Ne,e as Ce}from"./chunk-5QR2SQIS.js";import"./chunk-NRP22GKC.js";import"./chunk-OPM7ESDV.js";import{a as ce}from"./chunk-FPI7AMQJ.js";import{a as ue}from"./chunk-7RKB5KS7.js";import{a as q}from"./chunk-37WYCOQ2.js";import{g as me,h as ve,i as pe,j as ye}from"./chunk-FT66XZJF.js";import"./chunk-XGCIDUJF.js";import"./chunk-HO7FAUZP.js";import"./chunk-CCDX5RYT.js";import"./chunk-OYCUPD3Q.js";import"./chunk-NXQW5E6W.js";import"./chunk-UC7MNI2F.js";import"./chunk-SA2OGF3F.js";import"./chunk-NGVP66OH.js";import"./chunk-GHQ2VDI2.js";import"./chunk-WJRYEML4.js";import"./chunk-FUYEZFBP.js";import"./chunk-RGMVGZV4.js";import"./chunk-OQ6I6OXT.js";import{i as ae}from"./chunk-E4PXACVL.js";import"./chunk-MVWZMWPD.js";import"./chunk-SJQERRSZ.js";import"./chunk-7Y3SY37W.js";import{a as $}from"./chunk-7G4Z6Q7X.js";import"./chunk-3YXASVTP.js";import"./chunk-AUAECCXB.js";import{b as he}from"./chunk-Q6ED4KUL.js";import"./chunk-BOMPSVRC.js";import"./chunk-55UGUCQ6.js";import"./chunk-4ZEL6BYL.js";import"./chunk-IPQ5KYVD.js";import{l as G}from"./chunk-JSP7QF52.js";import"./chunk-QAQDMS6R.js";import"./chunk-WVWG6LII.js";import{a as ke}from"./chunk-RWVIV3U7.js";import{a as se,b as ie,c as oe,d as Q,e as X,f as Y}from"./chunk-HCTJKP5J.js";import{a as re,e as ne}from"./chunk-2IKDEUCX.js";import{d as R,h as Z,l as ge,p as z,s as de}from"./chunk-HJHSQPHW.js";import{a as i,d as le,e as Oe,f as _e,g as De}from"./chunk-I26MS5PJ.js";var P=le(Oe(),1);var ee=le(_e(),1);var a=le(De(),1);var Be=i(l=>{let e=l.trim();if(e==="")return;let n=Number(e);return Number.isFinite(n)&&n>0?Math.floor(n):void 0},"Be"),Le=i(l=>l===void 0?"\u2014":new Date(l*1e3).toISOString(),"Oe"),Je=i(l=>new TextEncoder().encode(l).length,"Ae"),Fe=i(l=>{if(l.trim()!=="")try{return JSON.stringify(JSON.parse(l),void 0,2)}catch{return}},"ge"),Ke=i(l=>{if(l.trim()==="")return!0;try{return JSON.parse(l),!0}catch{return!1}},"xe"),Ee=[{key:"seconds",seconds:1},{key:"minutes",seconds:60},{key:"hours",seconds:3600},{key:"days",seconds:86400}],we=i((l,e)=>{let n=l.trim();if(n==="")return"";let u=Number(n),s=Ee.find(p=>p.key===e)?.seconds??1;return Number.isFinite(u)&&u>0?String(Math.round(u*s)):n},"ue"),Ve=i(l=>{let e=l.trim();if(e==="")return!0;let n=Number(e);return Number.isInteger(n)&&n>=60},"Ce"),Te=i((l,e,n,u)=>{let s=Be(l.ttl);return{expiration:s===void 0?u:void 0,expirationTtl:s,key:e,metadata:l.metadata.trim()===""?void 0:JSON.parse(l.metadata),namespace:n,value:l.value}},"Se"),Me=i(l=>{let e=(0,ee.c)(60),{helper:n,id:u,invalid:s,onChange:p,testId:o}=l,t=R(),[r,y]=(0,P.useState)(""),[c,x]=(0,P.useState)("seconds"),b;e[0]!==p||e[1]!==c?(b=i(f=>{y(f.target.value),p(we(f.target.value,c))},"k"),e[0]=p,e[1]=c,e[2]=b):b=e[2];let _=b,V;e[3]!==r||e[4]!==p?(V=i(f=>{f!==null&&(x(f),p(we(r,f)))},"K"),e[3]=r,e[4]=p,e[5]=V):V=e[5];let T=V,h;e[6]!==t?(h=t("days"),e[6]=t,e[7]=h):h=e[7];let v;e[8]!==t?(v=t("hours"),e[8]=t,e[9]=v):v=e[9];let k;e[10]!==t?(k=t("minutes"),e[10]=t,e[11]=k):k=e[11];let N;e[12]!==t?(N=t("seconds"),e[12]=t,e[13]=N):N=e[13];let C;e[14]!==h||e[15]!==v||e[16]!==k||e[17]!==N?(C={days:h,hours:v,minutes:k,seconds:N},e[14]=h,e[15]=v,e[16]=k,e[17]=N,e[18]=C):C=e[18];let w=C,g;e[19]!==t?(g=t("Expires after"),e[19]=t,e[20]=g):g=e[20];let S;e[21]!==u||e[22]!==g?(S=(0,a.jsx)(q,{className:"text-xs",htmlFor:u,children:g}),e[21]=u,e[22]=g,e[23]=S):S=e[23];let E;e[24]!==t?(E=t("No expiration"),e[24]=t,e[25]=E):E=e[25];let B;e[26]!==r||e[27]!==u||e[28]!==s||e[29]!==_||e[30]!==E||e[31]!==o?(B=(0,a.jsx)(ae,{"aria-invalid":s,className:"flex-1","data-testid":o,id:u,inputMode:"numeric",onChange:_,placeholder:E,value:r}),e[26]=r,e[27]=u,e[28]=s,e[29]=_,e[30]=E,e[31]=o,e[32]=B):B=e[32];let M;e[33]!==t?(M=t("TTL unit"),e[33]=t,e[34]=M):M=e[34];let J=`${o}-unit`,L;e[35]===Symbol.for("react.memo_cache_sentinel")?(L=(0,a.jsx)(fe,{}),e[35]=L):L=e[35];let I;e[36]!==M||e[37]!==J?(I=(0,a.jsx)(xe,{"aria-label":M,className:"w-[7.5rem]","data-testid":J,children:L}),e[36]=M,e[37]=J,e[38]=I):I=e[38];let d;e[39]!==w?(d=Ee.map(f=>(0,a.jsx)(Ce,{value:f.key,children:w[f.key]},f.key)),e[39]=w,e[40]=d):d=e[40];let m;e[41]!==d?(m=(0,a.jsx)(Ne,{children:d}),e[41]=d,e[42]=m):m=e[42];let F;e[43]!==T||e[44]!==I||e[45]!==m||e[46]!==c?(F=(0,a.jsxs)(be,{onValueChange:T,value:c,children:[I,m]}),e[43]=T,e[44]=I,e[45]=m,e[46]=c,e[47]=F):F=e[47];let O;e[48]!==B||e[49]!==F?(O=(0,a.jsxs)("div",{className:"flex gap-2",children:[B,F]}),e[48]=B,e[49]=F,e[50]=O):O=e[50];let K;e[51]!==n||e[52]!==s||e[53]!==t||e[54]!==o?(K=s?(0,a.jsx)("p",{className:"text-xs text-destructive","data-testid":`${o}-invalid`,children:t("TTL must be at least 60 seconds.")}):n!==void 0&&(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:n}),e[51]=n,e[52]=s,e[53]=t,e[54]=o,e[55]=K):K=e[55];let D;return e[56]!==O||e[57]!==K||e[58]!==S?(D=(0,a.jsxs)("div",{className:"mb-3 grid gap-1",children:[S,O,K]}),e[56]=O,e[57]=K,e[58]=S,e[59]=D):D=e[59],D},"we"),Ie=i(l=>{let e=(0,ee.c)(36),{id:n,invalidTestId:u,onChange:s,testId:p,valid:o,value:t}=l,r=R(),y;e[0]!==t?(y=Fe(t),e[0]=t,e[1]=y):y=e[1];let c=y,x;e[2]!==r?(x=r("Metadata (JSON)"),e[2]=r,e[3]=x):x=e[3];let b;e[4]!==n||e[5]!==x?(b=(0,a.jsx)(q,{className:"text-xs",htmlFor:n,children:x}),e[4]=n,e[5]=x,e[6]=b):b=e[6];let _=`${p}-format`,V=c===void 0,T;e[7]!==c||e[8]!==s?(T=i(()=>{c!==void 0&&s(c)},"V"),e[7]=c,e[8]=s,e[9]=T):T=e[9];let h;e[10]!==r?(h=r("Format JSON"),e[10]=r,e[11]=h):h=e[11];let v;e[12]!==_||e[13]!==V||e[14]!==T||e[15]!==h?(v=(0,a.jsx)($,{"data-testid":_,disabled:V,onClick:T,size:"sm",variant:"outline",children:h}),e[12]=_,e[13]=V,e[14]=T,e[15]=h,e[16]=v):v=e[16];let k;e[17]!==b||e[18]!==v?(k=(0,a.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[b,v]}),e[17]=b,e[18]=v,e[19]=k):k=e[19];let N=!o,C;e[20]!==s?(C=i(E=>{s(E.target.value)},"N"),e[20]=s,e[21]=C):C=e[21];let w;e[22]!==n||e[23]!==N||e[24]!==C||e[25]!==p||e[26]!==t?(w=(0,a.jsx)(ce,{"aria-invalid":N,className:"min-h-[4rem] font-mono text-xs","data-testid":p,id:n,onChange:C,value:t}),e[22]=n,e[23]=N,e[24]=C,e[25]=p,e[26]=t,e[27]=w):w=e[27];let g;e[28]!==u||e[29]!==r||e[30]!==o?(g=!o&&(0,a.jsx)("p",{className:"text-xs text-destructive","data-testid":u,children:r("Metadata must be valid JSON.")}),e[28]=u,e[29]=r,e[30]=o,e[31]=g):g=e[31];let S;return e[32]!==w||e[33]!==g||e[34]!==k?(S=(0,a.jsxs)("div",{className:"mb-3 grid gap-1",children:[k,w,g]}),e[32]=w,e[33]=g,e[34]=k,e[35]=S):S=e[35],S},"Te"),Pe={busy:!1,error:null,metadata:"",name:"",ttl:"",value:""},$e=i((l,e)=>{switch(e.type){case"setField":return{...l,[e.field]:e.value};case"submitFailed":return{...l,busy:!1,error:e.error};case"submitStart":return{...l,busy:!0,error:null};default:return l}},"Je"),je=i(l=>{let e=(0,ee.c)(73),{namespace:n,onCancel:u,onCreated:s}=l,p=G(),o=R(),[t,r]=(0,P.useReducer)($e,Pe),y;e[0]!==t.metadata?(y=Ke(t.metadata),e[0]=t.metadata,e[1]=y):y=e[1];let c=y,x;e[2]!==t.ttl?(x=Ve(t.ttl),e[2]=t.ttl,e[3]=x):x=e[3];let b=x,_;e[4]!==c||e[5]!==t.busy||e[6]!==t.name||e[7]!==b?(_=t.name.trim()!==""&&c&&b&&!t.busy,e[4]=c,e[5]=t.busy,e[6]=t.name,e[7]=b,e[8]=_):_=e[8];let V=_,T;e[9]!==V||e[10]!==p||e[11]!==n||e[12]!==s||e[13]!==t.metadata||e[14]!==t.name||e[15]!==t.ttl||e[16]!==t.value?(T=i(()=>{V&&(r({type:"submitStart"}),z((async()=>{try{await p.putKvValue(Te({metadata:t.metadata,ttl:t.ttl,value:t.value},t.name,n)),s()}catch(A){r({error:Z(A),type:"submitFailed"})}})()))},"V"),e[9]=V,e[10]=p,e[11]=n,e[12]=s,e[13]=t.metadata,e[14]=t.name,e[15]=t.ttl,e[16]=t.value,e[17]=T):T=e[17];let h=T,v;e[18]!==o?(v=o("Key name"),e[18]=o,e[19]=v):v=e[19];let k;e[20]!==v?(k=(0,a.jsx)(q,{className:"text-xs",htmlFor:"kv-create-name",children:v}),e[20]=v,e[21]=k):k=e[21];let N;e[22]===Symbol.for("react.memo_cache_sentinel")?(N=i(A=>{r({field:"name",type:"setField",value:A.target.value})},"x"),e[22]=N):N=e[22];let C;e[23]!==o?(C=o("Key name"),e[23]=o,e[24]=C):C=e[24];let w;e[25]!==t.name||e[26]!==C?(w=(0,a.jsx)(ae,{autoFocus:!0,"data-testid":"kv-create-name",id:"kv-create-name",onChange:N,placeholder:C,value:t.name}),e[25]=t.name,e[26]=C,e[27]=w):w=e[27];let g;e[28]!==k||e[29]!==w?(g=(0,a.jsxs)("div",{className:"grid gap-1",children:[k,w]}),e[28]=k,e[29]=w,e[30]=g):g=e[30];let S;e[31]!==o?(S=o("Value"),e[31]=o,e[32]=S):S=e[32];let E;e[33]!==S?(E=(0,a.jsx)(q,{className:"text-xs",htmlFor:"kv-create-value",children:S}),e[33]=S,e[34]=E):E=e[34];let B;e[35]===Symbol.for("react.memo_cache_sentinel")?(B=i(A=>{r({field:"value",type:"setField",value:A.target.value})},"O"),e[35]=B):B=e[35];let M;e[36]!==t.value?(M=(0,a.jsx)(ce,{className:"min-h-[6rem] font-mono text-xs","data-testid":"kv-create-value",id:"kv-create-value",onChange:B,value:t.value}),e[36]=t.value,e[37]=M):M=e[37];let J;e[38]!==E||e[39]!==M?(J=(0,a.jsxs)("div",{className:"grid gap-1",children:[E,M]}),e[38]=E,e[39]=M,e[40]=J):J=e[40];let L=!b,I;e[41]===Symbol.for("react.memo_cache_sentinel")?(I=i(A=>{r({field:"ttl",type:"setField",value:A})},"_"),e[41]=I):I=e[41];let d;e[42]!==L?(d=(0,a.jsx)(Me,{id:"kv-create-ttl",invalid:L,onChange:I,testId:"kv-create-ttl"}),e[42]=L,e[43]=d):d=e[43];let m;e[44]===Symbol.for("react.memo_cache_sentinel")?(m=i(A=>{r({field:"metadata",type:"setField",value:A})},"u"),e[44]=m):m=e[44];let F;e[45]!==c||e[46]!==t.metadata?(F=(0,a.jsx)(Ie,{id:"kv-create-metadata",invalidTestId:"kv-create-metadata-invalid",onChange:m,testId:"kv-create-metadata",valid:c,value:t.metadata}),e[45]=c,e[46]=t.metadata,e[47]=F):F=e[47];let O=!V,K;e[48]!==t.busy||e[49]!==o?(K=t.busy?o("Creating\u2026"):o("Create key"),e[48]=t.busy,e[49]=o,e[50]=K):K=e[50];let D;e[51]!==h||e[52]!==O||e[53]!==K?(D=(0,a.jsx)($,{"data-testid":"kv-create-submit",disabled:O,onClick:h,children:K}),e[51]=h,e[52]=O,e[53]=K,e[54]=D):D=e[54];let f=t.busy,j;e[55]!==o?(j=o("Cancel"),e[55]=o,e[56]=j):j=e[56];let H;e[57]!==u||e[58]!==t.busy||e[59]!==j?(H=(0,a.jsx)($,{"data-testid":"kv-create-cancel",disabled:f,onClick:u,variant:"outline",children:j}),e[57]=u,e[58]=t.busy,e[59]=j,e[60]=H):H=e[60];let U;e[61]!==D||e[62]!==H?(U=(0,a.jsxs)("div",{className:"flex flex-wrap gap-2",children:[D,H]}),e[61]=D,e[62]=H,e[63]=U):U=e[63];let W;e[64]!==t.error?(W=t.error!==null&&(0,a.jsx)("p",{className:"text-sm text-destructive","data-testid":"kv-create-error",role:"alert",children:t.error}),e[64]=t.error,e[65]=W):W=e[65];let te;return e[66]!==g||e[67]!==J||e[68]!==d||e[69]!==F||e[70]!==U||e[71]!==W?(te=(0,a.jsxs)("div",{className:"grid gap-3 px-4 pb-4","data-testid":"kv-create-form",children:[g,J,d,F,U,W]}),e[66]=g,e[67]=J,e[68]=d,e[69]=F,e[70]=U,e[71]=W,e[72]=te):te=e[72],te},"Pe"),Ae={busy:"",editedMetadata:"",editedTtl:"",editedValue:"",loadError:null,loading:!0,value:null,writeError:null},ze=i((l,e)=>{switch(e.type){case"deleteStart":return{...l,busy:"deleting",writeError:null};case"editMetadata":return{...l,editedMetadata:e.value};case"editTtl":return{...l,editedTtl:e.value};case"editValue":return{...l,editedValue:e.value};case"loaded":return{...l,editedMetadata:e.metadata===null||e.metadata===void 0?"":JSON.stringify(e.metadata,null,2),editedValue:e.value??"",loading:!1,value:e.value};case"loadFailed":return{...l,loadError:e.error,loading:!1};case"saveOk":return{...l,busy:"",value:l.editedValue};case"saveStart":return{...l,busy:"saving",writeError:null};case"writeFailed":return{...l,busy:"",writeError:e.error};default:return l}},"je"),He=i(l=>{let e=(0,ee.c)(67),{expiration:n,keyName:u,namespace:s,onDeleted:p}=l,o=G(),t=R(),[r,y]=(0,P.useReducer)(ze,Ae),c,x;e[0]!==o||e[1]!==u||e[2]!==s?(c=i(()=>{let f={cancelled:!1};return z((async()=>{try{let j=await o.getKvValue({key:u,namespace:s});f.cancelled||y({metadata:j.metadata,type:"loaded",value:j.value})}catch(j){let H=j;f.cancelled||y({error:Z(H),type:"loadFailed"})}})()),()=>{f.cancelled=!0}},"o"),x=[o,s,u],e[0]=o,e[1]=u,e[2]=s,e[3]=c,e[4]=x):(c=e[3],x=e[4]),(0,P.useEffect)(c,x);let b;e[5]===Symbol.for("react.memo_cache_sentinel")?(b=i(f=>{y({type:"editValue",value:f.target.value})},"k"),e[5]=b):b=e[5];let _=b,V;e[6]===Symbol.for("react.memo_cache_sentinel")?(V=i(f=>{y({type:"editMetadata",value:f})},"K"),e[6]=V):V=e[6];let T=V,h;e[7]!==r.editedValue?(h=Fe(r.editedValue),e[7]=r.editedValue,e[8]=h):h=e[8];let v=h,k;e[9]!==r.editedMetadata?(k=Ke(r.editedMetadata),e[9]=r.editedMetadata,e[10]=k):k=e[10];let N=k,C;e[11]!==r.editedTtl?(C=Ve(r.editedTtl),e[11]=r.editedTtl,e[12]=C):C=e[12];let w=C,g;e[13]!==v?(g=i(()=>{v!==void 0&&y({type:"editValue",value:v})},"y"),e[13]=v,e[14]=g):g=e[14];let S=g,E;e[15]!==o||e[16]!==n||e[17]!==u||e[18]!==N||e[19]!==s||e[20]!==r.editedMetadata||e[21]!==r.editedTtl||e[22]!==r.editedValue||e[23]!==t?(E=i(()=>{if(!N){y({error:t("Metadata must be valid JSON."),type:"writeFailed"});return}y({type:"saveStart"}),z((async()=>{try{await o.putKvValue(Te({metadata:r.editedMetadata,ttl:r.editedTtl,value:r.editedValue},u,s,n)),y({type:"saveOk"})}catch(f){y({error:Z(f),type:"writeFailed"})}})())},"F"),e[15]=o,e[16]=n,e[17]=u,e[18]=N,e[19]=s,e[20]=r.editedMetadata,e[21]=r.editedTtl,e[22]=r.editedValue,e[23]=t,e[24]=E):E=e[24];let B=E,M;e[25]!==o||e[26]!==u||e[27]!==s||e[28]!==p?(M=i(()=>{y({type:"deleteStart"}),z((async()=>{try{await o.deleteKvKey({key:u,namespace:s}),p(u)}catch(f){y({error:Z(f),type:"writeFailed"})}})())},"I"),e[25]=o,e[26]=u,e[27]=s,e[28]=p,e[29]=M):M=e[29];let J=M,L;e[30]!==u?(L=i(()=>{de(u)},"A"),e[30]=u,e[31]=L):L=e[31];let I;e[32]!==t?(I=t("Copy key"),e[32]=t,e[33]=I):I=e[33];let d;e[34]!==L||e[35]!==I?(d=(0,a.jsx)("div",{className:"mb-2 flex justify-end",children:(0,a.jsx)($,{"data-testid":"kv-copy-key-btn",onClick:L,size:"sm",variant:"outline",children:I})}),e[34]=L,e[35]=I,e[36]=d):d=e[36];let m;e[37]!==r.loadError?(m=r.loadError!==null&&(0,a.jsx)("p",{className:"mb-2 text-sm text-destructive","data-testid":"kv-value-error",role:"alert",children:r.loadError}),e[37]=r.loadError,e[38]=m):m=e[38];let F;e[39]!==r.loading||e[40]!==t?(F=r.loading&&(0,a.jsx)("p",{className:"text-sm text-muted-foreground","data-testid":"kv-value-loading",children:t("Loading\u2026")}),e[39]=r.loading,e[40]=t,e[41]=F):F=e[41];let O;e[42]!==v||e[43]!==N||e[44]!==J||e[45]!==S||e[46]!==B||e[47]!==r.busy||e[48]!==r.editedMetadata||e[49]!==r.editedValue||e[50]!==r.loading||e[51]!==r.value||e[52]!==r.writeError||e[53]!==t||e[54]!==w?(O=!r.loading&&r.value!==null&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"mb-1 flex flex-wrap items-center gap-2",children:[(0,a.jsx)(q,{className:"text-xs",htmlFor:"kv-value-editor",children:t("Value")}),v!==void 0&&(0,a.jsx)(he,{variant:"secondary",children:t("JSON")}),(0,a.jsx)("span",{className:"ml-auto text-xs tabular-nums text-muted-foreground","data-testid":"kv-value-size",children:ge(Je(r.editedValue))})]}),(0,a.jsx)("textarea",{"aria-label":t("KV value"),className:"mb-2 min-h-[8rem] w-full rounded border border-border bg-muted/30 p-2 font-mono text-xs","data-testid":"kv-value-editor",id:"kv-value-editor",onChange:_,value:r.editedValue}),(0,a.jsxs)("div",{className:"mb-3 flex flex-wrap gap-2",children:[(0,a.jsx)($,{"data-testid":"kv-format-btn",disabled:v===void 0,onClick:S,size:"sm",variant:"outline",children:t("Format JSON")}),(0,a.jsx)($,{"data-testid":"kv-copy-value-btn",onClick:i(()=>{de(r.editedValue)},"onClick"),size:"sm",variant:"outline",children:t("Copy value")})]}),(0,a.jsx)(Me,{helper:t("Leave blank to keep the current expiration."),id:"kv-ttl-input",invalid:!w,onChange:i(f=>{y({type:"editTtl",value:f})},"onChange"),testId:"kv-ttl-input"}),(0,a.jsx)(Ie,{id:"kv-metadata-editor",invalidTestId:"kv-metadata-invalid",onChange:T,testId:"kv-metadata-editor",valid:N,value:r.editedMetadata}),(0,a.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,a.jsx)($,{"data-testid":"kv-save-btn",disabled:r.busy!==""||!N||!w,onClick:B,children:r.busy==="saving"?t("Saving\u2026"):t("Save")}),(0,a.jsx)($,{"data-testid":"kv-delete-btn",disabled:r.busy!=="",onClick:J,variant:"destructive",children:r.busy==="deleting"?t("Deleting\u2026"):t("Delete")})]}),r.writeError!==null&&(0,a.jsx)("p",{className:"mt-2 text-sm text-destructive","data-testid":"kv-save-error",role:"alert",children:r.writeError})]}),e[42]=v,e[43]=N,e[44]=J,e[45]=S,e[46]=B,e[47]=r.busy,e[48]=r.editedMetadata,e[49]=r.editedValue,e[50]=r.loading,e[51]=r.value,e[52]=r.writeError,e[53]=t,e[54]=w,e[55]=O):O=e[55];let K;e[56]!==r.loadError||e[57]!==r.loading||e[58]!==r.value||e[59]!==t?(K=!r.loading&&r.value===null&&r.loadError===null&&(0,a.jsx)("p",{className:"text-sm text-muted-foreground","data-testid":"kv-absent",children:t("Key is absent or has no value.")}),e[56]=r.loadError,e[57]=r.loading,e[58]=r.value,e[59]=t,e[60]=K):K=e[60];let D;return e[61]!==d||e[62]!==m||e[63]!==F||e[64]!==O||e[65]!==K?(D=(0,a.jsxs)("div",{className:"px-4 pb-4","data-testid":"kv-value-section",children:[d,m,F,O,K]}),e[61]=d,e[62]=m,e[63]=F,e[64]=O,e[65]=K,e[66]=D):D=e[66],D},"He"),Se=100,Ze={appliedPrefix:"",bulk:[],bulkBusy:!1,bulkError:null,cursor:null,keys:null,listComplete:!1,loadError:null,loading:!1,prefixInput:"",reloadNonce:0,selectedKey:null},Re=i((l,e)=>{switch(e.type){case"appendPage":return e.generation!==l.reloadNonce?l:{...l,cursor:e.cursor,keys:[...l.keys??[],...e.keys],listComplete:e.listComplete,loading:!1};case"applyFilter":return{...l,appliedPrefix:l.prefixInput,bulk:[],bulkError:null,cursor:null,keys:null,listComplete:!1,reloadNonce:l.reloadNonce+1,selectedKey:null};case"bulkDeleted":{let n=new Set(e.deleted);return{...l,bulk:l.bulk.filter(u=>!n.has(u)),bulkBusy:!1,bulkError:e.error,keys:l.keys===null?null:l.keys.filter(u=>!n.has(u.name)),selectedKey:l.selectedKey!==null&&n.has(l.selectedKey)?null:l.selectedKey}}case"bulkDeleteStart":return{...l,bulkBusy:!0,bulkError:null};case"firstPage":return{...l,cursor:e.cursor,keys:e.keys,listComplete:e.listComplete,loading:!1};case"keyDeleted":return{...l,bulk:l.bulk.filter(n=>n!==e.name),keys:l.keys===null?null:l.keys.filter(n=>n.name!==e.name),selectedKey:null};case"loadFailed":return e.generation!==void 0&&e.generation!==l.reloadNonce?l:{...l,loadError:e.error,loading:!1};case"loadStart":return{...l,loadError:null,loading:!0};case"prefixInput":return{...l,prefixInput:e.value};case"reload":return{...l,bulk:[],bulkError:null,reloadNonce:l.reloadNonce+1,selectedKey:null};case"selectKey":return{...l,selectedKey:e.name};case"toggleAllBulk":return{...l,bulk:e.names};case"toggleBulk":return{...l,bulk:l.bulk.includes(e.name)?l.bulk.filter(n=>n!==e.name):[...l.bulk,e.name]};default:return l}},"ze"),Ue=i(({namespace:l})=>{let e=G(),n=R(),[u,s]=(0,P.useReducer)(Re,Ze),{appliedPrefix:p,bulk:o,bulkBusy:t,bulkError:r,cursor:y,keys:c,listComplete:x,loadError:b,loading:_,prefixInput:V,reloadNonce:T,selectedKey:h}=u,[v,k]=(0,P.useState)(!1);(0,P.useEffect)(()=>{let d={cancelled:!1};return z((async()=>{s({type:"loadStart"});try{let m=await e.listKvKeys({limit:Se,namespace:l,prefix:p===""?void 0:p});d.cancelled||s({cursor:m.cursor??null,keys:m.keys,listComplete:m.listComplete,type:"firstPage"})}catch(m){d.cancelled||s({error:Z(m),type:"loadFailed"})}})()),()=>{d.cancelled=!0}},[e,l,p,T]);let N=i(d=>{s({type:"prefixInput",value:d.target.value})},"x"),C=i(()=>{s({type:"applyFilter"})},"N"),w=i(d=>{s({name:d.currentTarget.dataset.key??null,type:"selectKey"})},"C"),g=i(()=>{if(y===null)return;s({type:"loadStart"});let d=T;z((async()=>{try{let m=await e.listKvKeys({cursor:y,limit:Se,namespace:l,prefix:p===""?void 0:p});s({cursor:m.cursor??null,generation:d,keys:m.keys,listComplete:m.listComplete,type:"appendPage"})}catch(m){s({error:Z(m),generation:d,type:"loadFailed"})}})())},"y"),S=i(d=>{s({name:d,type:"keyDeleted"})},"S"),E=i(d=>{s({name:d,type:"toggleBulk"})},"F"),B=i(d=>{s({names:d&&c!==null?c.map(m=>m.name):[],type:"toggleAllBulk"})},"O"),M=i(()=>{if(o.length===0)return;let d=[...o];s({type:"bulkDeleteStart"}),z((async()=>{let m=await Promise.allSettled(d.map(K=>e.deleteKvKey({key:K,namespace:l}))),F=d.filter((K,D)=>m[D]?.status==="fulfilled"),O=d.length-F.length;s({deleted:F,error:O>0?n("Failed to delete {count} keys.",{count:O}):null,type:"bulkDeleted"})})())},"I"),J=i(()=>{k(!1),s({type:"reload"})},"D"),L=c!==null&&c.length>0&&o.length===c.length,I=new Set(o);return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("section",{className:"border border-border bg-card p-3","data-testid":"kv-keys-section",children:[(0,a.jsxs)("div",{className:"mb-3 flex flex-wrap items-center gap-2",children:[(0,a.jsx)(ae,{"aria-label":n("Filter keys by prefix"),className:"min-w-[16rem] flex-1","data-testid":"kv-prefix-input",onChange:N,placeholder:n("Filter by prefix\u2026"),value:V}),(0,a.jsx)($,{"data-testid":"kv-filter-btn",disabled:_,onClick:C,children:n("Filter")}),(0,a.jsx)($,{"data-testid":"kv-new-key-btn",onClick:i(()=>{k(d=>!d)},"onClick"),variant:"outline",children:n("New key")}),o.length>0&&(0,a.jsx)($,{"data-testid":"kv-bulk-delete-btn",disabled:t,onClick:M,variant:"destructive",children:t?n("Deleting\u2026"):n("Delete {count}",{count:o.length})})]}),r!==null&&(0,a.jsx)("p",{className:"mb-2 text-sm text-destructive","data-testid":"kv-bulk-error",role:"alert",children:r}),b!==null&&(0,a.jsx)("p",{className:"text-sm text-destructive","data-testid":"kv-keys-error",role:"alert",children:b}),c!==null&&c.length===0&&!_&&(0,a.jsx)("p",{className:"text-sm text-muted-foreground","data-testid":"kv-no-keys",children:n("No keys.")}),c!==null&&c.length>0&&(0,a.jsx)(re,{className:"overflow-hidden py-0",children:(0,a.jsx)(ne,{className:"px-0",children:(0,a.jsxs)(se,{"data-testid":"kv-key-table",children:[(0,a.jsx)(ie,{children:(0,a.jsxs)(Q,{children:[(0,a.jsx)(X,{className:"w-10",children:(0,a.jsx)(ue,{"aria-label":n("Select all"),checked:L,"data-testid":"kv-select-all",onCheckedChange:B})}),(0,a.jsx)(X,{children:n("Key")}),(0,a.jsx)(X,{children:n("Expiration")})]})}),(0,a.jsx)(oe,{children:c.map(d=>(0,a.jsxs)(Q,{className:d.name===h?"border-l-2 border-l-royal-amethyst bg-muted/50":"cursor-pointer","data-key":d.name,"data-testid":`kv-key-row-${d.name}`,onClick:w,children:[(0,a.jsx)(Y,{onClick:i(m=>{m.stopPropagation()},"onClick"),children:(0,a.jsx)(ue,{"aria-label":n("Select {name}",{name:d.name}),checked:I.has(d.name),"data-testid":`kv-select-${d.name}`,onCheckedChange:i(()=>{E(d.name)},"onCheckedChange")})}),(0,a.jsx)(Y,{className:"font-mono text-xs",children:d.name}),(0,a.jsx)(Y,{className:"tabular-nums text-xs",children:Le(d.expiration)})]},d.name))})]})})}),!x&&y!==null&&(0,a.jsx)("div",{className:"mt-2",children:(0,a.jsx)($,{"data-testid":"kv-load-more",disabled:_,onClick:g,variant:"outline",children:n(_?"Loading\u2026":"Load more")})})]}),(0,a.jsx)(me,{onOpenChange:i(d=>{d||k(!1)},"onOpenChange"),open:v,children:(0,a.jsxs)(ve,{className:"w-full gap-0 overflow-y-auto sm:max-w-md","data-testid":"kv-create-sheet",side:"right",children:[(0,a.jsx)(pe,{children:(0,a.jsx)(ye,{children:n("New key")})}),(0,a.jsx)(je,{namespace:l,onCancel:i(()=>{k(!1)},"onCancel"),onCreated:J})]})}),(0,a.jsx)(me,{onOpenChange:i(d=>{d||s({name:null,type:"selectKey"})},"onOpenChange"),open:h!==null,children:(0,a.jsxs)(ve,{className:"w-full gap-0 overflow-y-auto sm:max-w-md","data-testid":"kv-editor-sheet",side:"right",children:[(0,a.jsx)(pe,{children:(0,a.jsx)(ye,{className:"truncate font-mono text-xs",children:h})}),h!==null&&(0,a.jsx)(He,{expiration:c?.find(d=>d.name===h)?.expiration,keyName:h,namespace:l,onDeleted:S},`${l}:${h}`)]})})]})},"Ue"),it=i(({loadNamespaces:l}={})=>{let e=G(),n=R(),[u,s]=(0,P.useState)(null),[p,o]=(0,P.useState)(null),[t,r]=(0,P.useState)(null);(0,P.useEffect)(()=>{let c={cancelled:!1};return z((async()=>{try{let x=await(l??(()=>e.listKvNamespaces()))();c.cancelled||(s(x),o(null),r(b=>b??x[0]?.binding??null))}catch(x){c.cancelled||(s(null),o(Z(x)))}})()),()=>{c.cancelled=!0}},[e,l]);let y=i(c=>{r(c.currentTarget.dataset.ns??null)},"f");return(0,a.jsxs)("div",{className:"flex flex-col gap-4","data-testid":"lunora-kv-browser",children:[p!==null&&(0,a.jsx)("p",{className:"text-sm text-destructive","data-testid":"kv-ns-error",role:"alert",children:p}),u!==null&&u.length===0&&(0,a.jsx)(ke,{description:n("Add a kv_namespaces binding to wrangler.jsonc \u2014 it appears here automatically, no wiring needed."),icon:(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 5h14v4H5V5Zm0 5h14v4H5v-4Zm0 5h14v4H5v-4Z"})}),testId:"kv-empty",title:n("No KV namespaces.")}),u!==null&&u.length>0&&(0,a.jsx)(re,{className:"overflow-hidden py-0",children:(0,a.jsx)(ne,{className:"px-0",children:(0,a.jsxs)(se,{"data-testid":"kv-namespace-table",children:[(0,a.jsx)(ie,{children:(0,a.jsx)(Q,{children:(0,a.jsx)(X,{children:n("Namespace")})})}),(0,a.jsx)(oe,{children:u.map(c=>(0,a.jsx)(Q,{className:c.binding===t?"border-l-2 border-l-royal-amethyst bg-muted/50":"cursor-pointer","data-ns":c.binding,"data-testid":`kv-ns-row-${c.binding}`,onClick:y,children:(0,a.jsx)(Y,{className:"font-mono text-xs",children:c.binding})},c.binding))})]})})}),t!==null&&(0,a.jsx)(Ue,{namespace:t},t)]})},"ut");export{it as KvBrowser};
@@ -1,4 +1,4 @@
1
- import{a as le}from"./chunk-6HLARDYO.js";import{a as je}from"./chunk-FPI7AMQJ.js";import{a as he}from"./chunk-37WYCOQ2.js";import{a as V}from"./chunk-SA2OGF3F.js";import{d as Ne,f as ke,g as we,k as oe}from"./chunk-GHQ2VDI2.js";import{a as Pe}from"./chunk-YVR4SEPU.js";import"./chunk-ZKJS6EBE.js";import"./chunk-RGMVGZV4.js";import{i as ve}from"./chunk-E4PXACVL.js";import"./chunk-MVWZMWPD.js";import"./chunk-7Y3SY37W.js";import{a as W}from"./chunk-7G4Z6Q7X.js";import"./chunk-3YXASVTP.js";import"./chunk-AUAECCXB.js";import{b as ye}from"./chunk-Q6ED4KUL.js";import"./chunk-BOMPSVRC.js";import{a as $e}from"./chunk-4ZEL6BYL.js";import{l as F}from"./chunk-ICDMV4MP.js";import"./chunk-QAQDMS6R.js";import{d as be}from"./chunk-FQPBYMII.js";import{a as U}from"./chunk-RWVIV3U7.js";import{d as J,e as Se,f as se,g as ie,h as fe,m as Ie,p as Oe,s as ae}from"./chunk-HJHSQPHW.js";import{a as u,d as K,e as me,f as te,g as re,i as ue}from"./chunk-I26MS5PJ.js";var Ge=K(te(),1),xe=K(me(),1);var Y=K(te(),1);var X=K(me(),1);var R=K(re(),1);var Ve=se($e.listTables),Xe=["react","client","cli"],Ye={action:"action",mutation:"mutation",query:"query"},Ce=u(t=>{let e=t.indexOf(":");return e===-1?{file:"",fn:t}:{file:t.slice(0,e),fn:t.slice(e+1)}},"Q"),Ze=u(({file:t,fn:e,kind:a})=>`await client.${Ye[a]}(api.${t}.${e}, { /* args */ });`,"ie"),et=u(t=>{let e=`api.${t.file}.${t.fn}`;switch(t.kind){case"action":return`const { call: ${t.fn} } = useAction(${e});`;case"mutation":return`const ${t.fn} = useMutation(${e});`;default:return`const data = useQuery(${e}, { /* args */ });`}},"se"),tt=u(({file:t,fn:e})=>`lunora run ${t}:${e} --args '{ }'`,"oe"),rt=u(t=>["// Read rows",`const rows = await ctx.db.query("${t}").collect();`,"","// Insert a row",`const id = await ctx.db.insert("${t}", { /* fields */ });`,"","// Generated types",`type Row = Doc<"${t}">;`,`type RowId = Id<"${t}">;`].join(`
1
+ import{a as le}from"./chunk-6HLARDYO.js";import{a as je}from"./chunk-FPI7AMQJ.js";import{a as he}from"./chunk-37WYCOQ2.js";import{a as V}from"./chunk-SA2OGF3F.js";import{d as Ne,f as ke,g as we,k as oe}from"./chunk-GHQ2VDI2.js";import{a as Pe}from"./chunk-YVR4SEPU.js";import"./chunk-ZKJS6EBE.js";import"./chunk-RGMVGZV4.js";import{i as ve}from"./chunk-E4PXACVL.js";import"./chunk-MVWZMWPD.js";import"./chunk-7Y3SY37W.js";import{a as W}from"./chunk-7G4Z6Q7X.js";import"./chunk-3YXASVTP.js";import"./chunk-AUAECCXB.js";import{b as ye}from"./chunk-Q6ED4KUL.js";import"./chunk-BOMPSVRC.js";import{a as $e}from"./chunk-4ZEL6BYL.js";import{l as F}from"./chunk-JSP7QF52.js";import"./chunk-QAQDMS6R.js";import{d as be}from"./chunk-WVWG6LII.js";import{a as U}from"./chunk-RWVIV3U7.js";import{d as J,e as Se,f as se,g as ie,h as fe,m as Ie,p as Oe,s as ae}from"./chunk-HJHSQPHW.js";import{a as u,d as K,e as me,f as te,g as re,i as ue}from"./chunk-I26MS5PJ.js";var Ge=K(te(),1),xe=K(me(),1);var Y=K(te(),1);var X=K(me(),1);var R=K(re(),1);var Ve=se($e.listTables),Xe=["react","client","cli"],Ye={action:"action",mutation:"mutation",query:"query"},Ce=u(t=>{let e=t.indexOf(":");return e===-1?{file:"",fn:t}:{file:t.slice(0,e),fn:t.slice(e+1)}},"Q"),Ze=u(({file:t,fn:e,kind:a})=>`await client.${Ye[a]}(api.${t}.${e}, { /* args */ });`,"ie"),et=u(t=>{let e=`api.${t.file}.${t.fn}`;switch(t.kind){case"action":return`const { call: ${t.fn} } = useAction(${e});`;case"mutation":return`const ${t.fn} = useMutation(${e});`;default:return`const data = useQuery(${e}, { /* args */ });`}},"se"),tt=u(({file:t,fn:e})=>`lunora run ${t}:${e} --args '{ }'`,"oe"),rt=u(t=>["// Read rows",`const rows = await ctx.db.query("${t}").collect();`,"","// Insert a row",`const id = await ctx.db.insert("${t}", { /* fields */ });`,"","// Generated types",`type Row = Doc<"${t}">;`,`type RowId = Id<"${t}">;`].join(`
2
2
  `),"ce"),at=u((t,e)=>{switch(t){case"cli":return tt(e);case"client":return Ze(e);default:return et(e)}},"re"),Re=u(t=>{let e=(0,Y.c)(19),{code:a,label:r,testId:n}=t,s=J(),o;e[0]!==a?(o=u(()=>{ae(a)},"c"),e[0]=a,e[1]=o):o=e[1];let i=o,c;e[2]!==r?(c=(0,R.jsx)("span",{className:"text-xs font-medium text-muted-foreground",children:r}),e[2]=r,e[3]=c):c=e[3];let m=`${n}-copy`,l;e[4]!==s?(l=s("Copy"),e[4]=s,e[5]=l):l=e[5];let p;e[6]!==i||e[7]!==m||e[8]!==l?(p=(0,R.jsx)(W,{"data-testid":m,onClick:i,size:"xs",type:"button",variant:"ghost",children:l}),e[6]=i,e[7]=m,e[8]=l,e[9]=p):p=e[9];let f;e[10]!==c||e[11]!==p?(f=(0,R.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[c,p]}),e[10]=c,e[11]=p,e[12]=f):f=e[12];let h;e[13]!==a||e[14]!==n?(h=(0,R.jsx)("pre",{className:"overflow-auto rounded-md border border-border bg-muted/50 p-3 font-mono text-xs","data-testid":n,children:a}),e[13]=a,e[14]=n,e[15]=h):h=e[15];let g;return e[16]!==f||e[17]!==h?(g=(0,R.jsxs)("div",{className:"flex flex-col gap-1.5",children:[f,h]}),e[16]=f,e[17]=h,e[18]=g):g=e[18],g},"U"),nt=u(t=>{let e=(0,Y.c)(46),{file:a,fn:r,kind:n}=t,s=J(),[o,i]=(0,X.useState)("react"),c,m,l;if(e[0]!==a||e[1]!==r||e[2]!==n||e[3]!==s||e[4]!==o){let w={file:a,fn:r,kind:n},j;e[8]!==s?(j=s("CLI"),e[8]=s,e[9]=j):j=e[9];let O;e[10]!==s?(O=s("Client"),e[10]=s,e[11]=O):O=e[11];let S;e[12]!==s?(S=s("React"),e[12]=s,e[13]=S):S=e[13];let C;e[14]!==j||e[15]!==O||e[16]!==S?(C={cli:j,client:O,react:S},e[14]=j,e[15]=O,e[16]=S,e[17]=C):C=e[17],l=C;let A;e[18]===Symbol.for("react.memo_cache_sentinel")?(A=u(_=>{i(_.currentTarget.dataset.tab)},"B"),e[18]=A):A=e[18],c=A,m=at(o,w),e[0]=a,e[1]=r,e[2]=n,e[3]=s,e[4]=o,e[5]=c,e[6]=m,e[7]=l}else c=e[5],m=e[6],l=e[7];let p=m,f=`api.${a}.${r}`,h;e[19]!==f?(h=(0,R.jsx)("h2",{className:"font-mono text-sm font-semibold text-foreground","data-testid":"api-fn-title",children:f}),e[19]=f,e[20]=h):h=e[20];let g;e[21]!==n||e[22]!==s?(g=s("Call this {kind} from your app.",{kind:n}),e[21]=n,e[22]=s,e[23]=g):g=e[23];let x;e[24]!==g?(x=(0,R.jsx)("p",{className:"text-xs text-muted-foreground",children:g}),e[24]=g,e[25]=x):x=e[25];let v;e[26]!==h||e[27]!==x?(v=(0,R.jsxs)("div",{children:[h,x]}),e[26]=h,e[27]=x,e[28]=v):v=e[28];let N;e[29]!==s?(N=s("Snippet flavour"),e[29]=s,e[30]=N):N=e[30];let y;e[31]!==c||e[32]!==o||e[33]!==l?(y=Xe.map(w=>(0,R.jsx)(W,{"aria-selected":o===w,"data-tab":w,"data-testid":`api-tab-${w}`,onClick:c,role:"tab",size:"xs",type:"button",variant:o===w?"default":"outline",children:l[w]},w)),e[31]=c,e[32]=o,e[33]=l,e[34]=y):y=e[34];let b;e[35]!==N||e[36]!==y?(b=(0,R.jsx)("div",{"aria-label":N,className:"flex gap-1.5","data-testid":"api-tabs",role:"tablist",children:y}),e[35]=N,e[36]=y,e[37]=b):b=e[37];let I=l[o],P=`api-snippet-${o}`,$;e[38]!==p||e[39]!==I||e[40]!==P?($=(0,R.jsx)(Re,{code:p,label:I,testId:P}),e[38]=p,e[39]=I,e[40]=P,e[41]=$):$=e[41];let k;return e[42]!==$||e[43]!==v||e[44]!==b?(k=(0,R.jsxs)("div",{className:"flex flex-col gap-3","data-testid":"api-fn-doc",children:[v,b,$]}),e[42]=$,e[43]=v,e[44]=b,e[45]=k):k=e[45],k},"de"),ot=u(t=>{let e=(0,Y.c)(19),{name:a}=t,r=J(),n;e[0]!==a?(n=rt(a),e[0]=a,e[1]=n):n=e[1];let s=n,o;e[2]!==a?(o=(0,R.jsx)("h2",{className:"font-mono text-sm font-semibold text-foreground","data-testid":"api-table-title",children:a}),e[2]=a,e[3]=o):o=e[3];let i;e[4]!==r?(i=r("Read and write this table through the typed data model."),e[4]=r,e[5]=i):i=e[5];let c;e[6]!==i?(c=(0,R.jsx)("p",{className:"text-xs text-muted-foreground",children:i}),e[6]=i,e[7]=c):c=e[7];let m;e[8]!==o||e[9]!==c?(m=(0,R.jsxs)("div",{children:[o,c]}),e[8]=o,e[9]=c,e[10]=m):m=e[10];let l;e[11]!==r?(l=r("Data model"),e[11]=r,e[12]=l):l=e[12];let p;e[13]!==s||e[14]!==l?(p=(0,R.jsx)(Re,{code:s,label:l,testId:"api-snippet-table"}),e[13]=s,e[14]=l,e[15]=p):p=e[15];let f;return e[16]!==m||e[17]!==p?(f=(0,R.jsxs)("div",{className:"flex flex-col gap-3","data-testid":"api-table-doc",children:[m,p]}),e[16]=m,e[17]=p,e[18]=f):f=e[18],f},"fe"),Te=u(t=>{let e=(0,Y.c)(8),{active:a,label:r,onSelect:n,testId:s,value:o}=t,i;e[0]!==n||e[1]!==o?(i=u(()=>{n(o)},"m"),e[0]=n,e[1]=o,e[2]=i):i=e[2];let c=i,m=a?"page":void 0,l;return e[3]!==r||e[4]!==c||e[5]!==m||e[6]!==s?(l=(0,R.jsx)("button",{"aria-current":m,className:"w-full truncate rounded-md px-2 py-1 text-start font-mono text-xs text-muted-foreground outline-none transition-colors hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:bg-sidebar-accent aria-[current=page]:bg-sidebar-accent aria-[current=page]:font-medium aria-[current=page]:text-foreground","data-testid":s,onClick:c,type:"button",children:r}),e[3]=r,e[4]=c,e[5]=m,e[6]=s,e[7]=l):l=e[7],l},"G"),st=u(t=>{let e=new Map;for(let a of t){let{file:r,fn:n}=Ce(a.path),s=e.get(r)??[];s.push({fn:n,kind:a.kind,path:a.path}),e.set(r,s)}return[...e.entries()].map(([a,r])=>({file:a,items:r.toSorted((n,s)=>n.fn.localeCompare(s.fn))})).toSorted((a,r)=>a.file.localeCompare(r.file))},"pe"),Ae=u(t=>{let e=(0,Y.c)(58),{functions:a,initialShardKey:r}=t,n=J(),s=F(),[o,i]=(0,X.useState)(null),[c,m]=(0,X.useState)(null),l,p;e[0]!==s||e[1]!==r?(l=u(()=>{let _=!1;return s.query(Ve,{},ie(r??"")).then(T=>(_||i(T),T)).catch(()=>{_||i([])}),()=>{_=!0}},"o"),p=[s,r],e[0]=s,e[1]=r,e[2]=l,e[3]=p):(l=e[2],p=e[3]),(0,X.useEffect)(l,p);let f,h,g,x,v,N,y,b,I,P;if(e[4]!==a||e[5]!==c||e[6]!==n||e[7]!==o){let _=a??[],T=st(_),L=(o??[]).map(it).toSorted(lt),E;e[18]===Symbol.for("react.memo_cache_sentinel")?(E=u(M=>{m({kind:"fn",path:M})},"P"),e[18]=E):E=e[18];let D=E,Q;e[19]===Symbol.for("react.memo_cache_sentinel")?(Q=u(M=>{m({kind:"table",name:M})},"j"),e[19]=Q):Q=e[19];let Qe=Q;h=c?.kind==="fn"?_.find(M=>M.path===c.path):void 0,f=_.length>0||L.length>0,g=h===void 0?void 0:Ce(h.path),I="grid min-h-0 gap-6 md:grid-cols-[16rem_minmax(0,1fr)]",P="lunora-api-docs",e[20]!==n?(x=n("API resources"),e[20]=n,e[21]=x):x=e[21],v="flex flex-col gap-4 overflow-y-auto",N="api-rail";let ne;e[22]!==c||e[23]!==n?(ne=u(M=>(0,R.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,R.jsx)("span",{className:"px-2 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:M.file||n("(root)")}),M.items.map(ee=>(0,R.jsx)(Te,{active:c?.kind==="fn"&&c.path===ee.path,label:ee.fn,onSelect:D,testId:`api-rail-fn-${ee.path}`,value:ee.path},ee.path))]},M.file),"q"),e[22]=c,e[23]=n,e[24]=ne):ne=e[24],y=T.map(ne),b=L.length>0&&(0,R.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,R.jsx)("span",{className:"px-2 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:n("Tables")}),L.map(M=>(0,R.jsx)(Te,{active:c?.kind==="table"&&c.name===M,label:M,onSelect:Qe,testId:`api-rail-table-${M}`,value:M},M))]}),e[4]=a,e[5]=c,e[6]=n,e[7]=o,e[8]=f,e[9]=h,e[10]=g,e[11]=x,e[12]=v,e[13]=N,e[14]=y,e[15]=b,e[16]=I,e[17]=P}else f=e[8],h=e[9],g=e[10],x=e[11],v=e[12],N=e[13],y=e[14],b=e[15],I=e[16],P=e[17];let $;e[25]!==f||e[26]!==n?($=!f&&(0,R.jsx)("p",{className:"px-2 text-xs text-muted-foreground","data-testid":"api-rail-empty",children:n("No functions or tables to document yet.")}),e[25]=f,e[26]=n,e[27]=$):$=e[27];let k;e[28]!==$||e[29]!==x||e[30]!==v||e[31]!==N||e[32]!==y||e[33]!==b?(k=(0,R.jsxs)("nav",{"aria-label":x,className:v,"data-testid":N,children:[y,b,$]}),e[28]=$,e[29]=x,e[30]=v,e[31]=N,e[32]=y,e[33]=b,e[34]=k):k=e[34];let w;e[35]!==c||e[36]!==n?(w=c===null&&(0,R.jsx)(U,{description:n("Select a function or table to see how to call it from your app."),testId:"api-empty",title:n("API usage snippets")}),e[35]=c,e[36]=n,e[37]=w):w=e[37];let j;e[38]!==c?.kind||e[39]!==h||e[40]!==g?(j=c?.kind==="fn"&&h!==void 0&&g!==void 0&&(0,R.jsx)(nt,{file:g.file,fn:g.fn,kind:h.kind},h.path),e[38]=c?.kind,e[39]=h,e[40]=g,e[41]=j):j=e[41];let O;e[42]!==c?.kind||e[43]!==h||e[44]!==n?(O=c?.kind==="fn"&&h===void 0&&(0,R.jsx)(U,{testId:"api-empty",title:n("API usage snippets")}),e[42]=c?.kind,e[43]=h,e[44]=n,e[45]=O):O=e[45];let S;e[46]!==c?(S=c?.kind==="table"&&(0,R.jsx)(ot,{name:c.name}),e[46]=c,e[47]=S):S=e[47];let C;e[48]!==w||e[49]!==j||e[50]!==O||e[51]!==S?(C=(0,R.jsxs)("div",{className:"min-w-0",children:[w,j,O,S]}),e[48]=w,e[49]=j,e[50]=O,e[51]=S,e[52]=C):C=e[52];let A;return e[53]!==k||e[54]!==C||e[55]!==I||e[56]!==P?(A=(0,R.jsxs)("div",{className:I,"data-testid":P,children:[k,C]}),e[53]=k,e[54]=C,e[55]=I,e[56]=P,e[57]=A):A=e[57],A},"ke");function it(t){return t.name}u(it,"ue");function lt(t,e){return t.localeCompare(e)}u(lt,"me");var De=K(te(),1);var z=K(te(),1);var q=K(me(),1);var d=K(re(),1);var dt=u(t=>typeof t=="number"?"number":typeof t=="boolean"?"boolean":"string","we"),Je=u(t=>{if(t.enum!==void 0&&t.enum.length>0)return t.enum;if(t.anyOf!==void 0&&t.anyOf.length>0&&t.anyOf.every(e=>e.const!==void 0))return t.anyOf.map(e=>e.const)},"Q"),ce=u(t=>t===void 0?"any":t.const!==void 0?JSON.stringify(t.const):t.enum!==void 0&&t.enum.length>0?t.enum.map(e=>JSON.stringify(e)).join(" | "):t.anyOf!==void 0&&t.anyOf.length>0?t.anyOf.map(e=>ce(e)).join(" | "):t.type==="array"?`array<${ce(t.items)}>`:t.type??"any","z"),ct=u(t=>{let e=Je(t);return e!==void 0?t.type??dt(e[0]):ce(t)},"ke"),pt=u(t=>{let e=Je(t);return e===void 0?void 0:e.map(a=>JSON.stringify(a)).join(" | ")},"Oe"),mt=u(t=>{let e=[];t.minimum!==void 0?e.push(`${String(t.minimum)} \u2264`):t.exclusiveMinimum!==void 0&&e.push(`${String(t.exclusiveMinimum)} <`);let a=e.length>0;e.push("value"),t.maximum!==void 0?e.push(`\u2264 ${String(t.maximum)}`):t.exclusiveMaximum!==void 0&&e.push(`< ${String(t.exclusiveMaximum)}`);let r=e.length>(a?2:1);return a||r?e.join(" "):void 0},"$e"),ut=u(t=>{if(t.type==="object"&&t.properties!==void 0)return t;if(t.type==="array"&&t.items?.type==="object"&&t.items.properties!==void 0)return t.items},"Te"),Z=u(t=>{if(t===void 0)return null;if(t.const!==void 0)return t.const;if(t.enum!==void 0&&t.enum.length>0)return t.enum[0];if(t.anyOf!==void 0&&t.anyOf.length>0)return Z(t.anyOf[0]);switch(t.type){case"array":return[];case"boolean":return!1;case"number":return 0;case"object":{let e={};for(let[a,r]of Object.entries(t.properties??{}))e[a]=Z(r);return e}case"string":return"";default:return null}},"D"),de=u(t=>{let e=(0,z.c)(7),{label:a,value:r}=t,n;e[0]!==a?(n=(0,d.jsx)("span",{className:"text-muted-foreground",children:a}),e[0]=a,e[1]=n):n=e[1];let s;e[2]!==r?(s=(0,d.jsx)("span",{className:"text-foreground",children:r}),e[2]=r,e[3]=s):s=e[3];let o;return e[4]!==n||e[5]!==s?(o=(0,d.jsxs)("span",{className:"inline-flex items-center gap-1 rounded border border-border px-1.5 py-0.5 font-mono text-[10px]",children:[n,s]}),e[4]=n,e[5]=s,e[6]=o):o=e[6],o},"K"),ft=u(t=>{let e=(0,z.c)(40),{name:a,required:r,schema:n}=t,s=J(),o;e[0]!==n?(o=mt(n),e[0]=n,e[1]=o):o=e[1];let i=o,c;e[2]!==n?(c=pt(n),e[2]=n,e[3]=c):c=e[3];let m=c,l=n["x-lunora-table"],p=n.format!==void 0||i!==void 0||m!==void 0||l!==void 0,f;e[4]!==n?(f=ut(n),e[4]=n,e[5]=f):f=e[5];let h=f,g=r?"*":"?",x;e[6]!==g?(x=(0,d.jsx)("span",{className:"text-muted-foreground",children:g}),e[6]=g,e[7]=x):x=e[7];let v;e[8]!==a||e[9]!==x?(v=(0,d.jsxs)("span",{className:"font-mono text-foreground",children:[a,x]}),e[8]=a,e[9]=x,e[10]=v):v=e[10];let N;e[11]!==n?(N=ct(n),e[11]=n,e[12]=N):N=e[12];let y;e[13]!==N?(y=(0,d.jsx)("span",{className:"font-mono text-muted-foreground",children:N}),e[13]=N,e[14]=y):y=e[14];let b;e[15]!==v||e[16]!==y?(b=(0,d.jsxs)("div",{className:"flex items-baseline gap-2",children:[v,y]}),e[15]=v,e[16]=y,e[17]=b):b=e[17];let I;e[18]!==n.description?(I=n.description!==void 0&&(0,d.jsx)("p",{className:"max-w-prose text-muted-foreground",children:n.description}),e[18]=n.description,e[19]=I):I=e[19];let P;e[20]!==p||e[21]!==i||e[22]!==l||e[23]!==n.format||e[24]!==s||e[25]!==m?(P=p&&(0,d.jsxs)("div",{className:"flex flex-wrap gap-1",children:[n.format!==void 0&&(0,d.jsx)(de,{label:s("Format"),value:n.format}),i!==void 0&&(0,d.jsx)(de,{label:s("Range"),value:i}),m!==void 0&&(0,d.jsx)(de,{label:s("Value in"),value:m}),l!==void 0&&(0,d.jsx)(de,{label:s("relation"),value:l})]}),e[20]=p,e[21]=i,e[22]=l,e[23]=n.format,e[24]=s,e[25]=m,e[26]=P):P=e[26];let $;e[27]!==I||e[28]!==P||e[29]!==b?($=(0,d.jsxs)("div",{className:"flex flex-col gap-1 py-2",children:[b,I,P]}),e[27]=I,e[28]=P,e[29]=b,e[30]=$):$=e[30];let k=$;if(h===void 0){let S;return e[31]!==k?(S=(0,d.jsx)("div",{className:"border-b border-border/50 last:border-b-0",children:k}),e[31]=k,e[32]=S):S=e[32],S}let w;e[33]!==k?(w=(0,d.jsx)("summary",{className:"cursor-pointer marker:text-muted-foreground",children:k}),e[33]=k,e[34]=w):w=e[34];let j;e[35]!==h?(j=(0,d.jsx)("div",{className:"mb-2 ml-2 border-l border-border pl-3",children:(0,d.jsx)(Le,{schema:h})}),e[35]=h,e[36]=j):j=e[36];let O;return e[37]!==w||e[38]!==j?(O=(0,d.jsxs)("details",{className:"border-b border-border/50 last:border-b-0",children:[w,j]}),e[37]=w,e[38]=j,e[39]=O):O=e[39],O},"Ee"),Le=u(t=>{let e=(0,z.c)(7),{schema:a}=t,r;e[0]!==a.required?(r=new Set(a.required),e[0]=a.required,e[1]=r):r=e[1];let n=r,s;e[2]!==a.properties?(s=Object.entries(a.properties??{}),e[2]=a.properties,e[3]=s):s=e[3];let o=s,i;return e[4]!==n||e[5]!==o?(i=(0,d.jsx)("div",{className:"flex flex-col",children:o.map(c=>{let[m,l]=c;return(0,d.jsx)(ft,{name:m,required:n.has(m),schema:l},m)})}),e[4]=n,e[5]=o,e[6]=i):i=e[6],i},"Z"),_e=u(t=>{let e=(0,z.c)(10),{schema:a,testId:r}=t;if(a?.type!=="object"||Object.keys(a.properties??{}).length===0){let o;e[0]!==a?(o=ce(a),e[0]=a,e[1]=o):o=e[1];let i;return e[2]!==o||e[3]!==r?(i=(0,d.jsx)("p",{className:"font-mono text-xs text-muted-foreground","data-testid":r,children:o}),e[2]=o,e[3]=r,e[4]=i):i=e[4],i}let n;e[5]!==a?(n=(0,d.jsx)(Le,{schema:a}),e[5]=a,e[6]=n):n=e[6];let s;return e[7]!==n||e[8]!==r?(s=(0,d.jsx)("div",{className:"text-xs","data-testid":r,children:n}),e[7]=n,e[8]=r,e[9]=s):s=e[9],s},"V"),ht=["curl","javascript","lunora"],gt={lunora:"Lunora",curl:"cURL",javascript:"JavaScript"},xt=u(t=>`api.${t.replaceAll(/[/:]/g,".")}`,"je"),bt=u(t=>{let e=Z(t.argsSchema)??{};return t.functionPath===void 0?e:{args:e,functionPath:t.functionPath}},"Ae"),yt=u((t,e,a)=>{let r=`${a}${e.httpPath}`,n=JSON.stringify(bt(e),void 0,2),s=JSON.stringify(Z(e.argsSchema)??{},void 0,2);switch(t){case"curl":{let o=e.method!=="GET"&&e.method!=="HEAD",i=[`curl -X ${e.method} ${JSON.stringify(r)}`];return o&&i.push(' -H "Content-Type: application/json"',` -d '${n}'`),i.join(` \\
3
3
  `)}case"lunora":return e.functionPath===void 0?`await fetch(${JSON.stringify(e.httpPath)}, { method: ${JSON.stringify(e.method)} });`:`import { useLunora } from "@lunora/react";
4
4
  import { api } from "./_generated/api";
@@ -1 +1 @@
1
- import{d as E,e as _}from"./chunk-CVXNHIQW.js";import{a as $}from"./chunk-253UHWDX.js";import{a as de}from"./chunk-ODMIUMAO.js";import{a as ce}from"./chunk-6QTAHSDD.js";import"./chunk-VESGIGMQ.js";import"./chunk-TVCVRQUC.js";import"./chunk-AUGKHAMQ.js";import"./chunk-WJRYEML4.js";import{a as le}from"./chunk-R6U22RSY.js";import{a as re}from"./chunk-YVR4SEPU.js";import"./chunk-ZKJS6EBE.js";import"./chunk-RGMVGZV4.js";import"./chunk-OQ6I6OXT.js";import"./chunk-E4PXACVL.js";import"./chunk-MVWZMWPD.js";import"./chunk-SJQERRSZ.js";import"./chunk-7Y3SY37W.js";import"./chunk-AUAECCXB.js";import{b as K}from"./chunk-Q6ED4KUL.js";import"./chunk-BOMPSVRC.js";import{a as ie}from"./chunk-SJUYCXDY.js";import"./chunk-NCPW7WHO.js";import"./chunk-3V25YSWQ.js";import"./chunk-55UGUCQ6.js";import{a as J}from"./chunk-4ZEL6BYL.js";import{c as H}from"./chunk-VRWHCG2V.js";import"./chunk-ICDMV4MP.js";import"./chunk-QAQDMS6R.js";import"./chunk-FQPBYMII.js";import{a as ne}from"./chunk-RWVIV3U7.js";import{a as R,b as W,c as Z,d as A,e as M,f as S}from"./chunk-HCTJKP5J.js";import{a as q,b as D,c as U,e as oe}from"./chunk-2IKDEUCX.js";import{d as F,t as ae}from"./chunk-HJHSQPHW.js";import{a as p,d as se,f as be,g as ge}from"./chunk-I26MS5PJ.js";var O=se(be(),1);var o=se(ge(),1);var G="gen_ai.usage.input_tokens",Q="gen_ai.usage.output_tokens",V="gen_ai.usage.cost",fe="gen_ai.request.model",Te="lunora.usage.cost.source",xe=new Set(["ai.embed","ai.generate","ai.stream"]),ue=6e4,Ce=1440,ve="unknown",X=p(()=>({calls:0,estimatedCost:0,inputTokens:0,outputTokens:0,providerCost:0}),"q"),Y=p((n,e)=>{let s=n?.[e];return typeof s=="string"&&s!==""?s:void 0},"J"),z=p((n,e)=>{let s=n?.[e];return typeof s=="number"&&Number.isFinite(s)?s:void 0},"L"),ee=p(n=>Y(n,Te)==="provider"?"provider":"estimated","Q"),me=p((n,e)=>n.reduce((s,a)=>s+e(a),0),"Y"),B=p(n=>n.providerCost+n.estimatedCost,"F"),ke=p(n=>n.estimatedCost>0?n.providerCost>0?"mixed":"estimated":n.providerCost>0?"provider":"none","ae"),ye=p((n,e)=>({calls:n.calls+e.calls,estimatedCost:n.estimatedCost+e.estimatedCost,inputTokens:n.inputTokens+e.inputTokens,outputTokens:n.outputTokens+e.outputTokens,providerCost:n.providerCost+e.providerCost}),"ce"),Ie=p(n=>{let e=X(),s=0,a=0,t=0;for(let c of n){let l=me(c.points,i=>i.sum),r=me(c.points,i=>i.count);c.name===G?(e.inputTokens+=l,s+=r):c.name===Q?(e.outputTokens+=l,a+=r):(t+=r,ee(c.attributes)==="provider"?e.providerCost+=l:e.estimatedCost+=l)}return e.calls=Math.max(s,a,t),e},"ge"),Ne=p((n,e)=>B(e)-B(n)||e.inputTokens+e.outputTokens-(n.inputTokens+n.outputTokens)||n.key.localeCompare(e.key),"Ne"),pe=p((n,e)=>{let s=new Map;for(let a of n){let t=e(a);s.set(t,{key:t,...ye(s.get(t)??X(),a)})}return[...s.values()].toSorted(Ne)},"Z"),we=p(n=>(n?.series??[]).filter(e=>e.name===G||e.name===Q||e.name===V),"xe"),Me=p(n=>Y(n.attributes,fe)??ve,"Se"),Se=p(n=>{let e=new Map;for(let s of n){let a=Me(s),t=JSON.stringify([s.functionPath,a]),c=e.get(t)??{functionPath:s.functionPath,model:a,series:[]};c.series.push(s),e.set(t,c)}return[...e.values()].map(({functionPath:s,model:a,series:t})=>({functionPath:s,model:a,...Ie(t)}))},"Ie"),_e=p(n=>{let e=new Map;for(let r of n){if(r.name!==V)continue;let i=ee(r.attributes)==="provider";for(let u of r.points){let m=e.get(u.bucketMs)??{bucketMs:u.bucketMs,estimatedCost:0,providerCost:0};i?m.providerCost+=u.sum:m.estimatedCost+=u.sum,e.set(u.bucketMs,m)}}let s=[...e.keys()].toSorted((r,i)=>r-i),a=s[0],t=s.at(-1);if(a===void 0||t===void 0)return[];let c=Math.max(a,t-(Ce-1)*ue),l=[];for(let r=c;r<=t;r+=ue)l.push(e.get(r)??{bucketMs:r,estimatedCost:0,providerCost:0});return l},"_e"),Pe=p(n=>{let e=[];for(let s of n)for(let a of s.spans){if(!xe.has(a.name))continue;let{attributes:t}=a,c=z(t,V),l=z(t,G),r=z(t,Q);e.push({...c===void 0?{}:{cost:c,costSource:ee(t)},functionPath:s.functionPath,...l===void 0?{}:{inputTokens:l},model:Y(t,fe)??ve,ok:a.ok,...r===void 0?{}:{outputTokens:r},startTs:s.startTs+a.offsetMs,streaming:a.name==="ai.stream",traceId:s.traceId})}return e.toSorted((s,a)=>a.startTs-s.startTs)},"Me"),Fe=p(n=>n.map(e=>{let s=e.cost??0;return{calls:1,estimatedCost:e.costSource==="provider"?0:s,functionPath:e.functionPath,inputTokens:e.inputTokens??0,model:e.model,outputTokens:e.outputTokens??0,providerCost:e.costSource==="provider"?s:0}}),"Oe"),Oe=p((n,e)=>{let s=we(n),a=Pe(e),t=s.length>0,c=t?Se(s):Fe(a),l=X(),r="none";for(let i of c)l=ye(l,i);return t?r="history":a.length>0&&(r="live"),{byFunction:pe(c,i=>i.functionPath),byModel:pe(c,i=>i.model),calls:a,source:r,totals:l,trend:t?_e(s):[]}},"Ae"),Ke=p(n=>Array.isArray(n?.traces)?n.traces:[],"Ee"),Ae=25,te=p(n=>{let e=(0,O.c)(16),{provenance:s,value:a}=n,t=F();if(s==="none"){let m;return e[0]===Symbol.for("react.memo_cache_sentinel")?(m=(0,o.jsx)("span",{className:"text-muted-foreground",children:"\u2014"}),e[0]=m):m=e[0],m}let c;e[1]!==s||e[2]!==a?(c=s==="provider"?E(a):`~${E(a)}`,e[1]=s,e[2]=a,e[3]=c):c=e[3];let l;e[4]!==c?(l=(0,o.jsx)("span",{className:"tabular-nums",children:c}),e[4]=c,e[5]=l):l=e[5];let r;e[6]!==s||e[7]!==t?(r=s==="estimated"?(0,o.jsx)(K,{title:t("Derived from a price table, not reported by the provider."),variant:"warning",children:t("Estimated")}):null,e[6]=s,e[7]=t,e[8]=r):r=e[8];let i;e[9]!==s||e[10]!==t?(i=s==="mixed"?(0,o.jsx)(K,{title:t("Includes cost derived from a price table, not reported by the provider."),variant:"warning",children:t("Partly estimated")}):null,e[9]=s,e[10]=t,e[11]=i):i=e[11];let u;return e[12]!==l||e[13]!==r||e[14]!==i?(u=(0,o.jsxs)("span",{className:"inline-flex items-center gap-2",children:[l,r,i]}),e[12]=l,e[13]=r,e[14]=i,e[15]=u):u=e[15],u},"V"),he=p(n=>{let e=(0,O.c)(40),{keyLabel:s,rows:a,testId:t,title:c}=n,l=F(),r;e[0]!==c?(r=(0,o.jsx)(D,{className:"px-4 py-3",children:(0,o.jsx)(U,{children:c})}),e[0]=c,e[1]=r):r=e[1];let i;e[2]!==s?(i=(0,o.jsx)(M,{children:s}),e[2]=s,e[3]=i):i=e[3];let u;e[4]!==l?(u=l("Calls"),e[4]=l,e[5]=u):u=e[5];let m;e[6]!==u?(m=(0,o.jsx)(M,{className:"text-end",children:u}),e[6]=u,e[7]=m):m=e[7];let k;e[8]!==l?(k=l("Input tokens"),e[8]=l,e[9]=k):k=e[9];let y;e[10]!==k?(y=(0,o.jsx)(M,{className:"text-end",children:k}),e[10]=k,e[11]=y):y=e[11];let b;e[12]!==l?(b=l("Output tokens"),e[12]=l,e[13]=b):b=e[13];let T;e[14]!==b?(T=(0,o.jsx)(M,{className:"text-end",children:b}),e[14]=b,e[15]=T):T=e[15];let g;e[16]!==l?(g=l("Cost"),e[16]=l,e[17]=g):g=e[17];let d;e[18]!==g?(d=(0,o.jsx)(M,{className:"text-end",children:g}),e[18]=g,e[19]=d):d=e[19];let x;e[20]!==d||e[21]!==i||e[22]!==m||e[23]!==y||e[24]!==T?(x=(0,o.jsx)(W,{children:(0,o.jsxs)(A,{children:[i,m,y,T,d]})}),e[20]=d,e[21]=i,e[22]=m,e[23]=y,e[24]=T,e[25]=x):x=e[25];let h;if(e[26]!==a||e[27]!==t){let N;e[29]!==t?(N=p(w=>(0,o.jsxs)(A,{"data-testid":`${t}-row`,children:[(0,o.jsx)(S,{className:"max-w-[280px] truncate font-mono",title:w.key,children:w.key}),(0,o.jsx)(S,{className:"text-end tabular-nums",children:_(w.calls)}),(0,o.jsx)(S,{className:"text-end tabular-nums",children:_(w.inputTokens)}),(0,o.jsx)(S,{className:"text-end tabular-nums",children:_(w.outputTokens)}),(0,o.jsx)(S,{className:"text-end",children:(0,o.jsx)(te,{provenance:ke(w),value:B(w)})})]},w.key),"x"),e[29]=t,e[30]=N):N=e[30],h=a.map(N),e[26]=a,e[27]=t,e[28]=h}else h=e[28];let f;e[31]!==h?(f=(0,o.jsx)(Z,{children:h}),e[31]=h,e[32]=f):f=e[32];let v;e[33]!==x||e[34]!==f?(v=(0,o.jsxs)(R,{children:[x,f]}),e[33]=x,e[34]=f,e[35]=v):v=e[35];let C;return e[36]!==r||e[37]!==v||e[38]!==t?(C=(0,o.jsxs)(q,{className:"gap-0 py-0","data-testid":t,children:[r,v]}),e[36]=r,e[37]=v,e[38]=t,e[39]=C):C=e[39],C},"ee"),$e=p(n=>{let e=(0,O.c)(55),{calls:s,onOpenTrace:a}=n,t=F(),c;e[0]!==t?(c=t("Recent calls"),e[0]=t,e[1]=c):c=e[1];let l;e[2]!==c?(l=(0,o.jsx)(D,{className:"px-4 py-3",children:(0,o.jsx)(U,{children:c})}),e[2]=c,e[3]=l):l=e[3];let r;e[4]!==t?(r=t("When"),e[4]=t,e[5]=r):r=e[5];let i;e[6]!==r?(i=(0,o.jsx)(M,{children:r}),e[6]=r,e[7]=i):i=e[7];let u;e[8]!==t?(u=t("Function"),e[8]=t,e[9]=u):u=e[9];let m;e[10]!==u?(m=(0,o.jsx)(M,{children:u}),e[10]=u,e[11]=m):m=e[11];let k;e[12]!==t?(k=t("Model"),e[12]=t,e[13]=k):k=e[13];let y;e[14]!==k?(y=(0,o.jsx)(M,{children:k}),e[14]=k,e[15]=y):y=e[15];let b;e[16]!==t?(b=t("Input tokens"),e[16]=t,e[17]=b):b=e[17];let T;e[18]!==b?(T=(0,o.jsx)(M,{className:"text-end",children:b}),e[18]=b,e[19]=T):T=e[19];let g;e[20]!==t?(g=t("Output tokens"),e[20]=t,e[21]=g):g=e[21];let d;e[22]!==g?(d=(0,o.jsx)(M,{className:"text-end",children:g}),e[22]=g,e[23]=d):d=e[23];let x;e[24]!==t?(x=t("Cost"),e[24]=t,e[25]=x):x=e[25];let h;e[26]!==x?(h=(0,o.jsx)(M,{className:"text-end",children:x}),e[26]=x,e[27]=h):h=e[27];let f;e[28]!==t?(f=t("Trace"),e[28]=t,e[29]=f):f=e[29];let v;e[30]!==f?(v=(0,o.jsx)(M,{children:f}),e[30]=f,e[31]=v):v=e[31];let C;e[32]!==T||e[33]!==d||e[34]!==h||e[35]!==v||e[36]!==i||e[37]!==m||e[38]!==y?(C=(0,o.jsx)(W,{children:(0,o.jsxs)(A,{children:[i,m,y,T,d,h,v]})}),e[32]=T,e[33]=d,e[34]=h,e[35]=v,e[36]=i,e[37]=m,e[38]=y,e[39]=C):C=e[39];let N;if(e[40]!==s||e[41]!==a||e[42]!==t){let j;e[44]!==a||e[45]!==t?(j=p(I=>(0,o.jsxs)(A,{"data-testid":"ai-call",children:[(0,o.jsx)(S,{className:"font-mono text-muted-foreground",children:ae(I.startTs)}),(0,o.jsx)(S,{className:"font-mono",children:(0,o.jsxs)("span",{className:"inline-flex items-center gap-2",children:[I.functionPath,I.streaming?(0,o.jsx)(K,{variant:"outline",children:t("stream")}):null,I.ok?null:(0,o.jsx)(K,{variant:"destructive",children:t("failed")})]})}),(0,o.jsx)(S,{className:"max-w-[240px] truncate font-mono",title:I.model,children:I.model}),(0,o.jsx)(S,{className:"text-end tabular-nums",children:I.inputTokens===void 0?"\u2014":_(I.inputTokens)}),(0,o.jsx)(S,{className:"text-end tabular-nums",children:I.outputTokens===void 0?"\u2014":_(I.outputTokens)}),(0,o.jsx)(S,{className:"text-end",children:(0,o.jsx)(te,{provenance:I.cost===void 0?"none":I.costSource??"estimated",value:I.cost??0})}),(0,o.jsx)(S,{children:(0,o.jsx)("button",{className:"font-mono text-muted-foreground underline-offset-2 hover:underline",onClick:p(()=>{a(I.traceId)},"onClick"),title:t("Open the trace {trace}",{trace:I.traceId}),type:"button",children:I.traceId.slice(0,8)})})]},`${I.traceId}:${I.startTs.toString()}:${I.model}`),"U"),e[44]=a,e[45]=t,e[46]=j):j=e[46],N=s.slice(0,Ae).map(j),e[40]=s,e[41]=a,e[42]=t,e[43]=N}else N=e[43];let w;e[47]!==N?(w=(0,o.jsx)(Z,{children:N}),e[47]=N,e[48]=w):w=e[48];let P;e[49]!==C||e[50]!==w?(P=(0,o.jsxs)(R,{children:[C,w]}),e[49]=C,e[50]=w,e[51]=P):P=e[51];let L;return e[52]!==l||e[53]!==P?(L=(0,o.jsxs)(q,{className:"gap-0 py-0","data-testid":"ai-calls",children:[l,P]}),e[52]=l,e[53]=P,e[54]=L):L=e[54],L},"Pe"),Ee=p(n=>{let e=(0,O.c)(48),{totals:s,trend:a}=n,t=F(),c;e[0]!==s?(c=ke(s),e[0]=s,e[1]=c):c=e[1];let l=c,r;e[2]!==t||e[3]!==a?(r=a.length>=2?(0,o.jsx)(de,{ariaLabel:t("Cost per minute"),className:"h-7 w-24",series:a,testId:"ai-trend"}):void 0,e[2]=t,e[3]=a,e[4]=r):r=e[4];let i;e[5]!==l||e[6]!==t||e[7]!==s.estimatedCost||e[8]!==s.providerCost?(i=l==="none"?t("No cost reported"):(0,o.jsx)("span",{"data-testid":"ai-cost-split",children:t("{provider} provider-reported \xB7 {estimated} estimated",{estimated:E(s.estimatedCost),provider:E(s.providerCost)})}),e[5]=l,e[6]=t,e[7]=s.estimatedCost,e[8]=s.providerCost,e[9]=i):i=e[9];let u;e[10]!==t?(u=t("Total cost"),e[10]=t,e[11]=u):u=e[11];let m;e[12]!==s?(m=B(s),e[12]=s,e[13]=m):m=e[13];let k;e[14]!==l||e[15]!==m?(k=(0,o.jsx)(te,{provenance:l,value:m}),e[14]=l,e[15]=m,e[16]=k):k=e[16];let y;e[17]!==r||e[18]!==i||e[19]!==u||e[20]!==k?(y=(0,o.jsx)($,{chart:r,footer:i,label:u,testId:"ai-total-cost",value:k}),e[17]=r,e[18]=i,e[19]=u,e[20]=k,e[21]=y):y=e[21];let b;e[22]!==t?(b=t("Input tokens"),e[22]=t,e[23]=b):b=e[23];let T;e[24]!==s.inputTokens?(T=_(s.inputTokens),e[24]=s.inputTokens,e[25]=T):T=e[25];let g;e[26]!==b||e[27]!==T?(g=(0,o.jsx)($,{label:b,testId:"ai-input-tokens",value:T}),e[26]=b,e[27]=T,e[28]=g):g=e[28];let d;e[29]!==t?(d=t("Output tokens"),e[29]=t,e[30]=d):d=e[30];let x;e[31]!==s.outputTokens?(x=_(s.outputTokens),e[31]=s.outputTokens,e[32]=x):x=e[32];let h;e[33]!==d||e[34]!==x?(h=(0,o.jsx)($,{label:d,testId:"ai-output-tokens",value:x}),e[33]=d,e[34]=x,e[35]=h):h=e[35];let f;e[36]!==t?(f=t("Calls"),e[36]=t,e[37]=f):f=e[37];let v;e[38]!==s.calls?(v=_(s.calls),e[38]=s.calls,e[39]=v):v=e[39];let C;e[40]!==f||e[41]!==v?(C=(0,o.jsx)($,{label:f,testId:"ai-calls-total",value:v}),e[40]=f,e[41]=v,e[42]=C):C=e[42];let N;return e[43]!==g||e[44]!==h||e[45]!==C||e[46]!==y?(N=(0,o.jsxs)("dl",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4","data-testid":"ai-totals",children:[y,g,h,C]}),e[43]=g,e[44]=h,e[45]=C,e[46]=y,e[47]=N):N=e[47],N},"Ue"),Ye=p(n=>{let e=(0,O.c)(28),{initialShardKey:s}=n,a=F(),{queryShardKey:t,setShardKey:c,shardKey:l}=le(s),r=ce(t),i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i={},e[0]=i):i=e[0];let u;e[1]!==t?(u={live:!0,shardKey:t},e[1]=t,e[2]=u):u=e[2];let{data:m,error:k}=H(J.getTraces,i,u),y;e[3]===Symbol.for("react.memo_cache_sentinel")?(y={},e[3]=y):y=e[3];let b;e[4]!==t?(b={live:!0,shardKey:t},e[4]=t,e[5]=b):b=e[5];let{data:T}=H(J.getMetricHistory,y,b),g,d;e[6]!==m||e[7]!==T?(d=Oe(T,Ke(m)),g=d.trend.map(Le),e[6]=m,e[7]=T,e[8]=g,e[9]=d):(g=e[8],d=e[9]);let x=g,h;e[10]!==c||e[11]!==l?(h=(0,o.jsx)(re,{onChange:c,testId:"ai-shard-input",value:l}),e[10]=c,e[11]=l,e[12]=h):h=e[12];let f;e[13]!==k?(f=k===null?null:(0,o.jsx)(ie,{error:k,testId:"ai-error"}),e[13]=k,e[14]=f):f=e[14];let v;e[15]!==r||e[16]!==a||e[17]!==x||e[18]!==d.byFunction||e[19]!==d.byModel||e[20]!==d.calls||e[21]!==d.source||e[22]!==d.totals?(v=d.source==="none"?(0,o.jsx)(ne,{description:a("Spend shows up here once an action calls ctx.ai.model(...) \u2014 tokens and cost per function and per model."),testId:"ai-empty",title:a("No AI usage recorded")}):(0,o.jsxs)(o.Fragment,{children:[d.source==="live"?(0,o.jsx)("p",{className:"text-xs text-muted-foreground","data-testid":"ai-live-only",children:a("No durable history yet \u2014 these totals come from the live trace ring and reset when the shard hibernates.")}):(0,o.jsx)("p",{className:"text-xs text-muted-foreground","data-testid":"ai-window",children:a("Totals cover the retained metric history (up to the last 24 hours).")}),(0,o.jsx)(Ee,{totals:d.totals,trend:x}),(0,o.jsxs)("div",{className:"grid gap-3 xl:grid-cols-2",children:[(0,o.jsx)(he,{keyLabel:a("Function"),rows:d.byFunction,testId:"ai-by-function",title:a("By function")}),(0,o.jsx)(he,{keyLabel:a("Model"),rows:d.byModel,testId:"ai-by-model",title:a("By model")})]}),d.calls.length===0?(0,o.jsx)(q,{children:(0,o.jsx)(oe,{className:"p-4 text-xs text-muted-foreground","data-testid":"ai-no-calls",children:a("No recent calls in the live trace ring \u2014 it empties when the shard hibernates.")})}):(0,o.jsx)($e,{calls:d.calls,onOpenTrace:r})]}),e[15]=r,e[16]=a,e[17]=x,e[18]=d.byFunction,e[19]=d.byModel,e[20]=d.calls,e[21]=d.source,e[22]=d.totals,e[23]=v):v=e[23];let C;return e[24]!==h||e[25]!==f||e[26]!==v?(C=(0,o.jsxs)("section",{className:"flex flex-col gap-4","data-testid":"ai-panel",children:[h,f,v]}),e[24]=h,e[25]=f,e[26]=v,e[27]=C):C=e[27],C},"Ze");function Le(n){return n.providerCost+n.estimatedCost}p(Le,"Ke");export{Ye as default};
1
+ import{d as E,e as _}from"./chunk-CVXNHIQW.js";import{a as $}from"./chunk-253UHWDX.js";import{a as de}from"./chunk-VOWSZXG7.js";import{a as ce}from"./chunk-6QTAHSDD.js";import"./chunk-VESGIGMQ.js";import"./chunk-KMQTUDFK.js";import"./chunk-AUGKHAMQ.js";import"./chunk-WJRYEML4.js";import{a as le}from"./chunk-R6U22RSY.js";import{a as re}from"./chunk-YVR4SEPU.js";import"./chunk-ZKJS6EBE.js";import"./chunk-RGMVGZV4.js";import"./chunk-OQ6I6OXT.js";import"./chunk-E4PXACVL.js";import"./chunk-MVWZMWPD.js";import"./chunk-SJQERRSZ.js";import"./chunk-7Y3SY37W.js";import"./chunk-AUAECCXB.js";import{b as K}from"./chunk-Q6ED4KUL.js";import"./chunk-BOMPSVRC.js";import{a as ie}from"./chunk-SEZ2IRFD.js";import"./chunk-NCPW7WHO.js";import"./chunk-N4SDDVZW.js";import"./chunk-55UGUCQ6.js";import{a as J}from"./chunk-4ZEL6BYL.js";import{c as H}from"./chunk-IPQ5KYVD.js";import"./chunk-JSP7QF52.js";import"./chunk-QAQDMS6R.js";import"./chunk-WVWG6LII.js";import{a as ne}from"./chunk-RWVIV3U7.js";import{a as R,b as W,c as Z,d as A,e as M,f as S}from"./chunk-HCTJKP5J.js";import{a as q,b as D,c as U,e as oe}from"./chunk-2IKDEUCX.js";import{d as F,t as ae}from"./chunk-HJHSQPHW.js";import{a as p,d as se,f as be,g as ge}from"./chunk-I26MS5PJ.js";var O=se(be(),1);var o=se(ge(),1);var G="gen_ai.usage.input_tokens",Q="gen_ai.usage.output_tokens",V="gen_ai.usage.cost",fe="gen_ai.request.model",Te="lunora.usage.cost.source",xe=new Set(["ai.embed","ai.generate","ai.stream"]),ue=6e4,Ce=1440,ve="unknown",X=p(()=>({calls:0,estimatedCost:0,inputTokens:0,outputTokens:0,providerCost:0}),"q"),Y=p((n,e)=>{let s=n?.[e];return typeof s=="string"&&s!==""?s:void 0},"J"),z=p((n,e)=>{let s=n?.[e];return typeof s=="number"&&Number.isFinite(s)?s:void 0},"L"),ee=p(n=>Y(n,Te)==="provider"?"provider":"estimated","Q"),me=p((n,e)=>n.reduce((s,a)=>s+e(a),0),"Y"),B=p(n=>n.providerCost+n.estimatedCost,"F"),ke=p(n=>n.estimatedCost>0?n.providerCost>0?"mixed":"estimated":n.providerCost>0?"provider":"none","ae"),ye=p((n,e)=>({calls:n.calls+e.calls,estimatedCost:n.estimatedCost+e.estimatedCost,inputTokens:n.inputTokens+e.inputTokens,outputTokens:n.outputTokens+e.outputTokens,providerCost:n.providerCost+e.providerCost}),"ce"),Ie=p(n=>{let e=X(),s=0,a=0,t=0;for(let c of n){let l=me(c.points,i=>i.sum),r=me(c.points,i=>i.count);c.name===G?(e.inputTokens+=l,s+=r):c.name===Q?(e.outputTokens+=l,a+=r):(t+=r,ee(c.attributes)==="provider"?e.providerCost+=l:e.estimatedCost+=l)}return e.calls=Math.max(s,a,t),e},"ge"),Ne=p((n,e)=>B(e)-B(n)||e.inputTokens+e.outputTokens-(n.inputTokens+n.outputTokens)||n.key.localeCompare(e.key),"Ne"),pe=p((n,e)=>{let s=new Map;for(let a of n){let t=e(a);s.set(t,{key:t,...ye(s.get(t)??X(),a)})}return[...s.values()].toSorted(Ne)},"Z"),we=p(n=>(n?.series??[]).filter(e=>e.name===G||e.name===Q||e.name===V),"xe"),Me=p(n=>Y(n.attributes,fe)??ve,"Se"),Se=p(n=>{let e=new Map;for(let s of n){let a=Me(s),t=JSON.stringify([s.functionPath,a]),c=e.get(t)??{functionPath:s.functionPath,model:a,series:[]};c.series.push(s),e.set(t,c)}return[...e.values()].map(({functionPath:s,model:a,series:t})=>({functionPath:s,model:a,...Ie(t)}))},"Ie"),_e=p(n=>{let e=new Map;for(let r of n){if(r.name!==V)continue;let i=ee(r.attributes)==="provider";for(let u of r.points){let m=e.get(u.bucketMs)??{bucketMs:u.bucketMs,estimatedCost:0,providerCost:0};i?m.providerCost+=u.sum:m.estimatedCost+=u.sum,e.set(u.bucketMs,m)}}let s=[...e.keys()].toSorted((r,i)=>r-i),a=s[0],t=s.at(-1);if(a===void 0||t===void 0)return[];let c=Math.max(a,t-(Ce-1)*ue),l=[];for(let r=c;r<=t;r+=ue)l.push(e.get(r)??{bucketMs:r,estimatedCost:0,providerCost:0});return l},"_e"),Pe=p(n=>{let e=[];for(let s of n)for(let a of s.spans){if(!xe.has(a.name))continue;let{attributes:t}=a,c=z(t,V),l=z(t,G),r=z(t,Q);e.push({...c===void 0?{}:{cost:c,costSource:ee(t)},functionPath:s.functionPath,...l===void 0?{}:{inputTokens:l},model:Y(t,fe)??ve,ok:a.ok,...r===void 0?{}:{outputTokens:r},startTs:s.startTs+a.offsetMs,streaming:a.name==="ai.stream",traceId:s.traceId})}return e.toSorted((s,a)=>a.startTs-s.startTs)},"Me"),Fe=p(n=>n.map(e=>{let s=e.cost??0;return{calls:1,estimatedCost:e.costSource==="provider"?0:s,functionPath:e.functionPath,inputTokens:e.inputTokens??0,model:e.model,outputTokens:e.outputTokens??0,providerCost:e.costSource==="provider"?s:0}}),"Oe"),Oe=p((n,e)=>{let s=we(n),a=Pe(e),t=s.length>0,c=t?Se(s):Fe(a),l=X(),r="none";for(let i of c)l=ye(l,i);return t?r="history":a.length>0&&(r="live"),{byFunction:pe(c,i=>i.functionPath),byModel:pe(c,i=>i.model),calls:a,source:r,totals:l,trend:t?_e(s):[]}},"Ae"),Ke=p(n=>Array.isArray(n?.traces)?n.traces:[],"Ee"),Ae=25,te=p(n=>{let e=(0,O.c)(16),{provenance:s,value:a}=n,t=F();if(s==="none"){let m;return e[0]===Symbol.for("react.memo_cache_sentinel")?(m=(0,o.jsx)("span",{className:"text-muted-foreground",children:"\u2014"}),e[0]=m):m=e[0],m}let c;e[1]!==s||e[2]!==a?(c=s==="provider"?E(a):`~${E(a)}`,e[1]=s,e[2]=a,e[3]=c):c=e[3];let l;e[4]!==c?(l=(0,o.jsx)("span",{className:"tabular-nums",children:c}),e[4]=c,e[5]=l):l=e[5];let r;e[6]!==s||e[7]!==t?(r=s==="estimated"?(0,o.jsx)(K,{title:t("Derived from a price table, not reported by the provider."),variant:"warning",children:t("Estimated")}):null,e[6]=s,e[7]=t,e[8]=r):r=e[8];let i;e[9]!==s||e[10]!==t?(i=s==="mixed"?(0,o.jsx)(K,{title:t("Includes cost derived from a price table, not reported by the provider."),variant:"warning",children:t("Partly estimated")}):null,e[9]=s,e[10]=t,e[11]=i):i=e[11];let u;return e[12]!==l||e[13]!==r||e[14]!==i?(u=(0,o.jsxs)("span",{className:"inline-flex items-center gap-2",children:[l,r,i]}),e[12]=l,e[13]=r,e[14]=i,e[15]=u):u=e[15],u},"V"),he=p(n=>{let e=(0,O.c)(40),{keyLabel:s,rows:a,testId:t,title:c}=n,l=F(),r;e[0]!==c?(r=(0,o.jsx)(D,{className:"px-4 py-3",children:(0,o.jsx)(U,{children:c})}),e[0]=c,e[1]=r):r=e[1];let i;e[2]!==s?(i=(0,o.jsx)(M,{children:s}),e[2]=s,e[3]=i):i=e[3];let u;e[4]!==l?(u=l("Calls"),e[4]=l,e[5]=u):u=e[5];let m;e[6]!==u?(m=(0,o.jsx)(M,{className:"text-end",children:u}),e[6]=u,e[7]=m):m=e[7];let k;e[8]!==l?(k=l("Input tokens"),e[8]=l,e[9]=k):k=e[9];let y;e[10]!==k?(y=(0,o.jsx)(M,{className:"text-end",children:k}),e[10]=k,e[11]=y):y=e[11];let b;e[12]!==l?(b=l("Output tokens"),e[12]=l,e[13]=b):b=e[13];let T;e[14]!==b?(T=(0,o.jsx)(M,{className:"text-end",children:b}),e[14]=b,e[15]=T):T=e[15];let g;e[16]!==l?(g=l("Cost"),e[16]=l,e[17]=g):g=e[17];let d;e[18]!==g?(d=(0,o.jsx)(M,{className:"text-end",children:g}),e[18]=g,e[19]=d):d=e[19];let x;e[20]!==d||e[21]!==i||e[22]!==m||e[23]!==y||e[24]!==T?(x=(0,o.jsx)(W,{children:(0,o.jsxs)(A,{children:[i,m,y,T,d]})}),e[20]=d,e[21]=i,e[22]=m,e[23]=y,e[24]=T,e[25]=x):x=e[25];let h;if(e[26]!==a||e[27]!==t){let N;e[29]!==t?(N=p(w=>(0,o.jsxs)(A,{"data-testid":`${t}-row`,children:[(0,o.jsx)(S,{className:"max-w-[280px] truncate font-mono",title:w.key,children:w.key}),(0,o.jsx)(S,{className:"text-end tabular-nums",children:_(w.calls)}),(0,o.jsx)(S,{className:"text-end tabular-nums",children:_(w.inputTokens)}),(0,o.jsx)(S,{className:"text-end tabular-nums",children:_(w.outputTokens)}),(0,o.jsx)(S,{className:"text-end",children:(0,o.jsx)(te,{provenance:ke(w),value:B(w)})})]},w.key),"x"),e[29]=t,e[30]=N):N=e[30],h=a.map(N),e[26]=a,e[27]=t,e[28]=h}else h=e[28];let f;e[31]!==h?(f=(0,o.jsx)(Z,{children:h}),e[31]=h,e[32]=f):f=e[32];let v;e[33]!==x||e[34]!==f?(v=(0,o.jsxs)(R,{children:[x,f]}),e[33]=x,e[34]=f,e[35]=v):v=e[35];let C;return e[36]!==r||e[37]!==v||e[38]!==t?(C=(0,o.jsxs)(q,{className:"gap-0 py-0","data-testid":t,children:[r,v]}),e[36]=r,e[37]=v,e[38]=t,e[39]=C):C=e[39],C},"ee"),$e=p(n=>{let e=(0,O.c)(55),{calls:s,onOpenTrace:a}=n,t=F(),c;e[0]!==t?(c=t("Recent calls"),e[0]=t,e[1]=c):c=e[1];let l;e[2]!==c?(l=(0,o.jsx)(D,{className:"px-4 py-3",children:(0,o.jsx)(U,{children:c})}),e[2]=c,e[3]=l):l=e[3];let r;e[4]!==t?(r=t("When"),e[4]=t,e[5]=r):r=e[5];let i;e[6]!==r?(i=(0,o.jsx)(M,{children:r}),e[6]=r,e[7]=i):i=e[7];let u;e[8]!==t?(u=t("Function"),e[8]=t,e[9]=u):u=e[9];let m;e[10]!==u?(m=(0,o.jsx)(M,{children:u}),e[10]=u,e[11]=m):m=e[11];let k;e[12]!==t?(k=t("Model"),e[12]=t,e[13]=k):k=e[13];let y;e[14]!==k?(y=(0,o.jsx)(M,{children:k}),e[14]=k,e[15]=y):y=e[15];let b;e[16]!==t?(b=t("Input tokens"),e[16]=t,e[17]=b):b=e[17];let T;e[18]!==b?(T=(0,o.jsx)(M,{className:"text-end",children:b}),e[18]=b,e[19]=T):T=e[19];let g;e[20]!==t?(g=t("Output tokens"),e[20]=t,e[21]=g):g=e[21];let d;e[22]!==g?(d=(0,o.jsx)(M,{className:"text-end",children:g}),e[22]=g,e[23]=d):d=e[23];let x;e[24]!==t?(x=t("Cost"),e[24]=t,e[25]=x):x=e[25];let h;e[26]!==x?(h=(0,o.jsx)(M,{className:"text-end",children:x}),e[26]=x,e[27]=h):h=e[27];let f;e[28]!==t?(f=t("Trace"),e[28]=t,e[29]=f):f=e[29];let v;e[30]!==f?(v=(0,o.jsx)(M,{children:f}),e[30]=f,e[31]=v):v=e[31];let C;e[32]!==T||e[33]!==d||e[34]!==h||e[35]!==v||e[36]!==i||e[37]!==m||e[38]!==y?(C=(0,o.jsx)(W,{children:(0,o.jsxs)(A,{children:[i,m,y,T,d,h,v]})}),e[32]=T,e[33]=d,e[34]=h,e[35]=v,e[36]=i,e[37]=m,e[38]=y,e[39]=C):C=e[39];let N;if(e[40]!==s||e[41]!==a||e[42]!==t){let j;e[44]!==a||e[45]!==t?(j=p(I=>(0,o.jsxs)(A,{"data-testid":"ai-call",children:[(0,o.jsx)(S,{className:"font-mono text-muted-foreground",children:ae(I.startTs)}),(0,o.jsx)(S,{className:"font-mono",children:(0,o.jsxs)("span",{className:"inline-flex items-center gap-2",children:[I.functionPath,I.streaming?(0,o.jsx)(K,{variant:"outline",children:t("stream")}):null,I.ok?null:(0,o.jsx)(K,{variant:"destructive",children:t("failed")})]})}),(0,o.jsx)(S,{className:"max-w-[240px] truncate font-mono",title:I.model,children:I.model}),(0,o.jsx)(S,{className:"text-end tabular-nums",children:I.inputTokens===void 0?"\u2014":_(I.inputTokens)}),(0,o.jsx)(S,{className:"text-end tabular-nums",children:I.outputTokens===void 0?"\u2014":_(I.outputTokens)}),(0,o.jsx)(S,{className:"text-end",children:(0,o.jsx)(te,{provenance:I.cost===void 0?"none":I.costSource??"estimated",value:I.cost??0})}),(0,o.jsx)(S,{children:(0,o.jsx)("button",{className:"font-mono text-muted-foreground underline-offset-2 hover:underline",onClick:p(()=>{a(I.traceId)},"onClick"),title:t("Open the trace {trace}",{trace:I.traceId}),type:"button",children:I.traceId.slice(0,8)})})]},`${I.traceId}:${I.startTs.toString()}:${I.model}`),"U"),e[44]=a,e[45]=t,e[46]=j):j=e[46],N=s.slice(0,Ae).map(j),e[40]=s,e[41]=a,e[42]=t,e[43]=N}else N=e[43];let w;e[47]!==N?(w=(0,o.jsx)(Z,{children:N}),e[47]=N,e[48]=w):w=e[48];let P;e[49]!==C||e[50]!==w?(P=(0,o.jsxs)(R,{children:[C,w]}),e[49]=C,e[50]=w,e[51]=P):P=e[51];let L;return e[52]!==l||e[53]!==P?(L=(0,o.jsxs)(q,{className:"gap-0 py-0","data-testid":"ai-calls",children:[l,P]}),e[52]=l,e[53]=P,e[54]=L):L=e[54],L},"Pe"),Ee=p(n=>{let e=(0,O.c)(48),{totals:s,trend:a}=n,t=F(),c;e[0]!==s?(c=ke(s),e[0]=s,e[1]=c):c=e[1];let l=c,r;e[2]!==t||e[3]!==a?(r=a.length>=2?(0,o.jsx)(de,{ariaLabel:t("Cost per minute"),className:"h-7 w-24",series:a,testId:"ai-trend"}):void 0,e[2]=t,e[3]=a,e[4]=r):r=e[4];let i;e[5]!==l||e[6]!==t||e[7]!==s.estimatedCost||e[8]!==s.providerCost?(i=l==="none"?t("No cost reported"):(0,o.jsx)("span",{"data-testid":"ai-cost-split",children:t("{provider} provider-reported \xB7 {estimated} estimated",{estimated:E(s.estimatedCost),provider:E(s.providerCost)})}),e[5]=l,e[6]=t,e[7]=s.estimatedCost,e[8]=s.providerCost,e[9]=i):i=e[9];let u;e[10]!==t?(u=t("Total cost"),e[10]=t,e[11]=u):u=e[11];let m;e[12]!==s?(m=B(s),e[12]=s,e[13]=m):m=e[13];let k;e[14]!==l||e[15]!==m?(k=(0,o.jsx)(te,{provenance:l,value:m}),e[14]=l,e[15]=m,e[16]=k):k=e[16];let y;e[17]!==r||e[18]!==i||e[19]!==u||e[20]!==k?(y=(0,o.jsx)($,{chart:r,footer:i,label:u,testId:"ai-total-cost",value:k}),e[17]=r,e[18]=i,e[19]=u,e[20]=k,e[21]=y):y=e[21];let b;e[22]!==t?(b=t("Input tokens"),e[22]=t,e[23]=b):b=e[23];let T;e[24]!==s.inputTokens?(T=_(s.inputTokens),e[24]=s.inputTokens,e[25]=T):T=e[25];let g;e[26]!==b||e[27]!==T?(g=(0,o.jsx)($,{label:b,testId:"ai-input-tokens",value:T}),e[26]=b,e[27]=T,e[28]=g):g=e[28];let d;e[29]!==t?(d=t("Output tokens"),e[29]=t,e[30]=d):d=e[30];let x;e[31]!==s.outputTokens?(x=_(s.outputTokens),e[31]=s.outputTokens,e[32]=x):x=e[32];let h;e[33]!==d||e[34]!==x?(h=(0,o.jsx)($,{label:d,testId:"ai-output-tokens",value:x}),e[33]=d,e[34]=x,e[35]=h):h=e[35];let f;e[36]!==t?(f=t("Calls"),e[36]=t,e[37]=f):f=e[37];let v;e[38]!==s.calls?(v=_(s.calls),e[38]=s.calls,e[39]=v):v=e[39];let C;e[40]!==f||e[41]!==v?(C=(0,o.jsx)($,{label:f,testId:"ai-calls-total",value:v}),e[40]=f,e[41]=v,e[42]=C):C=e[42];let N;return e[43]!==g||e[44]!==h||e[45]!==C||e[46]!==y?(N=(0,o.jsxs)("dl",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4","data-testid":"ai-totals",children:[y,g,h,C]}),e[43]=g,e[44]=h,e[45]=C,e[46]=y,e[47]=N):N=e[47],N},"Ue"),Ye=p(n=>{let e=(0,O.c)(28),{initialShardKey:s}=n,a=F(),{queryShardKey:t,setShardKey:c,shardKey:l}=le(s),r=ce(t),i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i={},e[0]=i):i=e[0];let u;e[1]!==t?(u={live:!0,shardKey:t},e[1]=t,e[2]=u):u=e[2];let{data:m,error:k}=H(J.getTraces,i,u),y;e[3]===Symbol.for("react.memo_cache_sentinel")?(y={},e[3]=y):y=e[3];let b;e[4]!==t?(b={live:!0,shardKey:t},e[4]=t,e[5]=b):b=e[5];let{data:T}=H(J.getMetricHistory,y,b),g,d;e[6]!==m||e[7]!==T?(d=Oe(T,Ke(m)),g=d.trend.map(Le),e[6]=m,e[7]=T,e[8]=g,e[9]=d):(g=e[8],d=e[9]);let x=g,h;e[10]!==c||e[11]!==l?(h=(0,o.jsx)(re,{onChange:c,testId:"ai-shard-input",value:l}),e[10]=c,e[11]=l,e[12]=h):h=e[12];let f;e[13]!==k?(f=k===null?null:(0,o.jsx)(ie,{error:k,testId:"ai-error"}),e[13]=k,e[14]=f):f=e[14];let v;e[15]!==r||e[16]!==a||e[17]!==x||e[18]!==d.byFunction||e[19]!==d.byModel||e[20]!==d.calls||e[21]!==d.source||e[22]!==d.totals?(v=d.source==="none"?(0,o.jsx)(ne,{description:a("Spend shows up here once an action calls ctx.ai.model(...) \u2014 tokens and cost per function and per model."),testId:"ai-empty",title:a("No AI usage recorded")}):(0,o.jsxs)(o.Fragment,{children:[d.source==="live"?(0,o.jsx)("p",{className:"text-xs text-muted-foreground","data-testid":"ai-live-only",children:a("No durable history yet \u2014 these totals come from the live trace ring and reset when the shard hibernates.")}):(0,o.jsx)("p",{className:"text-xs text-muted-foreground","data-testid":"ai-window",children:a("Totals cover the retained metric history (up to the last 24 hours).")}),(0,o.jsx)(Ee,{totals:d.totals,trend:x}),(0,o.jsxs)("div",{className:"grid gap-3 xl:grid-cols-2",children:[(0,o.jsx)(he,{keyLabel:a("Function"),rows:d.byFunction,testId:"ai-by-function",title:a("By function")}),(0,o.jsx)(he,{keyLabel:a("Model"),rows:d.byModel,testId:"ai-by-model",title:a("By model")})]}),d.calls.length===0?(0,o.jsx)(q,{children:(0,o.jsx)(oe,{className:"p-4 text-xs text-muted-foreground","data-testid":"ai-no-calls",children:a("No recent calls in the live trace ring \u2014 it empties when the shard hibernates.")})}):(0,o.jsx)($e,{calls:d.calls,onOpenTrace:r})]}),e[15]=r,e[16]=a,e[17]=x,e[18]=d.byFunction,e[19]=d.byModel,e[20]=d.calls,e[21]=d.source,e[22]=d.totals,e[23]=v):v=e[23];let C;return e[24]!==h||e[25]!==f||e[26]!==v?(C=(0,o.jsxs)("section",{className:"flex flex-col gap-4","data-testid":"ai-panel",children:[h,f,v]}),e[24]=h,e[25]=f,e[26]=v,e[27]=C):C=e[27],C},"Ze");function Le(n){return n.providerCost+n.estimatedCost}p(Le,"Ke");export{Ye as default};
@@ -1 +1 @@
1
- import{a as q}from"./chunk-ODMIUMAO.js";import{a as k}from"./chunk-6QTAHSDD.js";import"./chunk-VESGIGMQ.js";import"./chunk-TVCVRQUC.js";import"./chunk-AUGKHAMQ.js";import"./chunk-WJRYEML4.js";import{a as A}from"./chunk-R6U22RSY.js";import{a as $}from"./chunk-YVR4SEPU.js";import"./chunk-ZKJS6EBE.js";import"./chunk-RGMVGZV4.js";import"./chunk-OQ6I6OXT.js";import"./chunk-E4PXACVL.js";import"./chunk-MVWZMWPD.js";import"./chunk-SJQERRSZ.js";import"./chunk-7Y3SY37W.js";import"./chunk-AUAECCXB.js";import{b as K}from"./chunk-Q6ED4KUL.js";import"./chunk-BOMPSVRC.js";import{a as F}from"./chunk-SJUYCXDY.js";import"./chunk-NCPW7WHO.js";import"./chunk-3V25YSWQ.js";import"./chunk-55UGUCQ6.js";import{a as T}from"./chunk-4ZEL6BYL.js";import{c as S}from"./chunk-VRWHCG2V.js";import"./chunk-ICDMV4MP.js";import"./chunk-QAQDMS6R.js";import"./chunk-FQPBYMII.js";import{a as O}from"./chunk-RWVIV3U7.js";import{a as j,e as w}from"./chunk-2IKDEUCX.js";import{d as I,t as E}from"./chunk-HJHSQPHW.js";import{a as p,d as C,f as D,g as H}from"./chunk-I26MS5PJ.js";var M=C(D(),1);var m=C(H(),1);var L=p(s=>s.length===0?void 0:{max:Math.max(...s),mean:s.reduce((e,t)=>e+t,0)/s.length,min:Math.min(...s)},"F"),B=/^gen_ai\.evaluation\.(.+)\.score$/u,P=p(s=>{let e=[];for(let t of s)for(let n of t.spans)for(let[a,l]of Object.entries(n.attributes??{})){let o=B.exec(a);if(!o||typeof l!="number")continue;let i=o[1],c=n.attributes?.[`gen_ai.evaluation.${i}.label`];e.push({...typeof c=="string"?{label:c}:{},name:i,score:l,spanName:n.name,startTs:t.startTs+n.offsetMs,traceId:t.traceId})}return e.toSorted((t,n)=>n.startTs-t.startTs)},"q"),Q=p(s=>{let e=[];for(let t of s?.series??[]){let n=B.exec(t.name);n&&e.push({name:n[1],points:t.points})}return e},"D"),R=p((s,e)=>{let t=new Set([...s.map(a=>a.name),...e.map(a=>a.name)]),n=[];for(let a of t){let l=s.filter(r=>r.name===a),o=e.find(r=>r.name===a)?.points??[],i=o.at(-1)?.last??l[0]?.score,c=o.length>0?{max:Math.max(...o.map(r=>r.max)),mean:o.reduce((r,d)=>r+d.sum,0)/o.reduce((r,d)=>r+d.count,0),min:Math.min(...o.map(r=>r.min))}:L(l.map(r=>r.score));n.push({...i===void 0?{}:{latest:i},...c,name:a,points:o,runs:l})}return n.toSorted((a,l)=>a.name.localeCompare(l.name))},"H"),U=p(s=>Array.isArray(s?.traces)?s.traces:[],"L"),N=p(s=>s===void 0?"\u2014":s.toFixed(2),"y"),z=p(s=>{let e=(0,M.c)(34),{card:t,onOpenTrace:n}=s,a=I(),l;e[0]!==t.name?(l=(0,m.jsx)("h3",{className:"font-mono text-sm font-semibold text-foreground","data-testid":"ev-name",children:t.name}),e[0]=t.name,e[1]=l):l=e[1];let o;e[2]!==t.latest?(o=N(t.latest),e[2]=t.latest,e[3]=o):o=e[3];let i;e[4]!==o?(i=(0,m.jsx)("span",{className:"font-mono text-lg text-foreground","data-testid":"ev-latest",children:o}),e[4]=o,e[5]=i):i=e[5];let c;e[6]!==l||e[7]!==i?(c=(0,m.jsxs)("div",{className:"flex items-baseline justify-between gap-3",children:[l,i]}),e[6]=l,e[7]=i,e[8]=c):c=e[8];let r;e[9]!==t.max||e[10]!==t.mean||e[11]!==t.min||e[12]!==a?(r=a("min {min} \xB7 mean {mean} \xB7 max {max}",{max:N(t.max),mean:N(t.mean),min:N(t.min)}),e[9]=t.max,e[10]=t.mean,e[11]=t.min,e[12]=a,e[13]=r):r=e[13];let d;e[14]!==r?(d=(0,m.jsx)("p",{className:"font-mono text-xs text-muted-foreground","data-testid":"ev-summary",children:r}),e[14]=r,e[15]=d):d=e[15];let u;e[16]!==t.name||e[17]!==t.points||e[18]!==a?(u=t.points.length>1?(0,m.jsx)(q,{ariaLabel:a("Score trend for {name}",{name:t.name}),className:"h-10 w-full",series:t.points.map(G),testId:"ev-trend"}):(0,m.jsx)("p",{className:"text-xs text-muted-foreground","data-testid":"ev-no-trend",children:a("No durable history yet \u2014 pass ctx.metrics to recordEvaluation to chart a trend.")}),e[16]=t.name,e[17]=t.points,e[18]=a,e[19]=u):u=e[19];let h;if(e[20]!==t.runs||e[21]!==n||e[22]!==a){let v;e[24]!==n||e[25]!==a?(v=p(f=>(0,m.jsxs)("div",{className:"flex items-center justify-between gap-2 font-mono text-xs","data-testid":"ev-run",children:[(0,m.jsxs)("span",{className:"truncate text-muted-foreground",children:[E(f.startTs)," \xB7 ",f.spanName]}),(0,m.jsxs)("span",{className:"flex items-center gap-2",children:[f.label===void 0?null:(0,m.jsx)(K,{variant:"outline",children:f.label}),(0,m.jsx)("span",{className:"text-foreground",children:N(f.score)}),n===void 0?null:(0,m.jsx)("button",{className:"text-muted-foreground underline-offset-2 hover:underline",onClick:p(()=>{n(f.traceId)},"onClick"),title:a("Open the trace {trace}",{trace:f.traceId}),type:"button",children:f.traceId.slice(0,8)})]})]},`${f.traceId}:${f.spanName}`),"x"),e[24]=n,e[25]=a,e[26]=v):v=e[26],h=t.runs.slice(0,5).map(v),e[20]=t.runs,e[21]=n,e[22]=a,e[23]=h}else h=e[23];let x;e[27]!==h?(x=(0,m.jsx)("div",{className:"flex flex-col gap-1",children:h}),e[27]=h,e[28]=x):x=e[28];let g;return e[29]!==c||e[30]!==d||e[31]!==u||e[32]!==x?(g=(0,m.jsx)(j,{"data-testid":"ev-card",children:(0,m.jsxs)(w,{className:"flex flex-col gap-3 p-4",children:[c,d,u,x]})}),e[29]=c,e[30]=d,e[31]=u,e[32]=x,e[33]=g):g=e[33],g},"P"),oe=p(s=>{let e=(0,M.c)(19),{initialShardKey:t}=s,n=I(),{queryShardKey:a,setShardKey:l,shardKey:o}=A(t),i=k(a),c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c={},e[0]=c):c=e[0];let r;e[1]!==a?(r={live:!0,shardKey:a},e[1]=a,e[2]=r):r=e[2];let{data:d,error:u}=S(T.getTraces,c,r),h;e[3]===Symbol.for("react.memo_cache_sentinel")?(h={},e[3]=h):h=e[3];let x;e[4]!==a?(x={live:!0,shardKey:a},e[4]=a,e[5]=x):x=e[5];let{data:g}=S(T.getMetricHistory,h,x),v;if(e[6]!==d||e[7]!==u||e[8]!==g||e[9]!==i||e[10]!==l||e[11]!==o||e[12]!==n){let f=R(P(U(d)),Q(g)),y;e[14]!==l||e[15]!==o?(y=(0,m.jsx)($,{onChange:l,testId:"ev-shard-input",value:o}),e[14]=l,e[15]=o,e[16]=y):y=e[16];let b;e[17]!==u?(b=u===null?null:(0,m.jsx)(F,{error:u,testId:"ev-error"}),e[17]=u,e[18]=b):b=e[18],v=(0,m.jsxs)("section",{className:"flex flex-col gap-4","data-testid":"ev-panel",children:[y,b,f.length===0?(0,m.jsx)(O,{description:n("Call recordEvaluation from a graded run and its score shows up here."),testId:"ev-empty",title:n("No evals recorded")}):(0,m.jsx)("div",{className:"grid gap-3 md:grid-cols-2",children:f.map(_=>(0,m.jsx)(z,{card:_,onOpenTrace:i},_.name))})]}),e[6]=d,e[7]=u,e[8]=g,e[9]=i,e[10]=l,e[11]=o,e[12]=n,e[13]=v}else v=e[13];return v},"re");function G(s){return s.last}p(G,"Q");export{oe as default};
1
+ import{a as q}from"./chunk-VOWSZXG7.js";import{a as k}from"./chunk-6QTAHSDD.js";import"./chunk-VESGIGMQ.js";import"./chunk-KMQTUDFK.js";import"./chunk-AUGKHAMQ.js";import"./chunk-WJRYEML4.js";import{a as A}from"./chunk-R6U22RSY.js";import{a as $}from"./chunk-YVR4SEPU.js";import"./chunk-ZKJS6EBE.js";import"./chunk-RGMVGZV4.js";import"./chunk-OQ6I6OXT.js";import"./chunk-E4PXACVL.js";import"./chunk-MVWZMWPD.js";import"./chunk-SJQERRSZ.js";import"./chunk-7Y3SY37W.js";import"./chunk-AUAECCXB.js";import{b as K}from"./chunk-Q6ED4KUL.js";import"./chunk-BOMPSVRC.js";import{a as F}from"./chunk-SEZ2IRFD.js";import"./chunk-NCPW7WHO.js";import"./chunk-N4SDDVZW.js";import"./chunk-55UGUCQ6.js";import{a as T}from"./chunk-4ZEL6BYL.js";import{c as S}from"./chunk-IPQ5KYVD.js";import"./chunk-JSP7QF52.js";import"./chunk-QAQDMS6R.js";import"./chunk-WVWG6LII.js";import{a as O}from"./chunk-RWVIV3U7.js";import{a as j,e as w}from"./chunk-2IKDEUCX.js";import{d as I,t as E}from"./chunk-HJHSQPHW.js";import{a as p,d as C,f as D,g as H}from"./chunk-I26MS5PJ.js";var M=C(D(),1);var m=C(H(),1);var L=p(s=>s.length===0?void 0:{max:Math.max(...s),mean:s.reduce((e,t)=>e+t,0)/s.length,min:Math.min(...s)},"F"),B=/^gen_ai\.evaluation\.(.+)\.score$/u,P=p(s=>{let e=[];for(let t of s)for(let n of t.spans)for(let[a,l]of Object.entries(n.attributes??{})){let o=B.exec(a);if(!o||typeof l!="number")continue;let i=o[1],c=n.attributes?.[`gen_ai.evaluation.${i}.label`];e.push({...typeof c=="string"?{label:c}:{},name:i,score:l,spanName:n.name,startTs:t.startTs+n.offsetMs,traceId:t.traceId})}return e.toSorted((t,n)=>n.startTs-t.startTs)},"q"),Q=p(s=>{let e=[];for(let t of s?.series??[]){let n=B.exec(t.name);n&&e.push({name:n[1],points:t.points})}return e},"D"),R=p((s,e)=>{let t=new Set([...s.map(a=>a.name),...e.map(a=>a.name)]),n=[];for(let a of t){let l=s.filter(r=>r.name===a),o=e.find(r=>r.name===a)?.points??[],i=o.at(-1)?.last??l[0]?.score,c=o.length>0?{max:Math.max(...o.map(r=>r.max)),mean:o.reduce((r,d)=>r+d.sum,0)/o.reduce((r,d)=>r+d.count,0),min:Math.min(...o.map(r=>r.min))}:L(l.map(r=>r.score));n.push({...i===void 0?{}:{latest:i},...c,name:a,points:o,runs:l})}return n.toSorted((a,l)=>a.name.localeCompare(l.name))},"H"),U=p(s=>Array.isArray(s?.traces)?s.traces:[],"L"),N=p(s=>s===void 0?"\u2014":s.toFixed(2),"y"),z=p(s=>{let e=(0,M.c)(34),{card:t,onOpenTrace:n}=s,a=I(),l;e[0]!==t.name?(l=(0,m.jsx)("h3",{className:"font-mono text-sm font-semibold text-foreground","data-testid":"ev-name",children:t.name}),e[0]=t.name,e[1]=l):l=e[1];let o;e[2]!==t.latest?(o=N(t.latest),e[2]=t.latest,e[3]=o):o=e[3];let i;e[4]!==o?(i=(0,m.jsx)("span",{className:"font-mono text-lg text-foreground","data-testid":"ev-latest",children:o}),e[4]=o,e[5]=i):i=e[5];let c;e[6]!==l||e[7]!==i?(c=(0,m.jsxs)("div",{className:"flex items-baseline justify-between gap-3",children:[l,i]}),e[6]=l,e[7]=i,e[8]=c):c=e[8];let r;e[9]!==t.max||e[10]!==t.mean||e[11]!==t.min||e[12]!==a?(r=a("min {min} \xB7 mean {mean} \xB7 max {max}",{max:N(t.max),mean:N(t.mean),min:N(t.min)}),e[9]=t.max,e[10]=t.mean,e[11]=t.min,e[12]=a,e[13]=r):r=e[13];let d;e[14]!==r?(d=(0,m.jsx)("p",{className:"font-mono text-xs text-muted-foreground","data-testid":"ev-summary",children:r}),e[14]=r,e[15]=d):d=e[15];let u;e[16]!==t.name||e[17]!==t.points||e[18]!==a?(u=t.points.length>1?(0,m.jsx)(q,{ariaLabel:a("Score trend for {name}",{name:t.name}),className:"h-10 w-full",series:t.points.map(G),testId:"ev-trend"}):(0,m.jsx)("p",{className:"text-xs text-muted-foreground","data-testid":"ev-no-trend",children:a("No durable history yet \u2014 pass ctx.metrics to recordEvaluation to chart a trend.")}),e[16]=t.name,e[17]=t.points,e[18]=a,e[19]=u):u=e[19];let h;if(e[20]!==t.runs||e[21]!==n||e[22]!==a){let v;e[24]!==n||e[25]!==a?(v=p(f=>(0,m.jsxs)("div",{className:"flex items-center justify-between gap-2 font-mono text-xs","data-testid":"ev-run",children:[(0,m.jsxs)("span",{className:"truncate text-muted-foreground",children:[E(f.startTs)," \xB7 ",f.spanName]}),(0,m.jsxs)("span",{className:"flex items-center gap-2",children:[f.label===void 0?null:(0,m.jsx)(K,{variant:"outline",children:f.label}),(0,m.jsx)("span",{className:"text-foreground",children:N(f.score)}),n===void 0?null:(0,m.jsx)("button",{className:"text-muted-foreground underline-offset-2 hover:underline",onClick:p(()=>{n(f.traceId)},"onClick"),title:a("Open the trace {trace}",{trace:f.traceId}),type:"button",children:f.traceId.slice(0,8)})]})]},`${f.traceId}:${f.spanName}`),"x"),e[24]=n,e[25]=a,e[26]=v):v=e[26],h=t.runs.slice(0,5).map(v),e[20]=t.runs,e[21]=n,e[22]=a,e[23]=h}else h=e[23];let x;e[27]!==h?(x=(0,m.jsx)("div",{className:"flex flex-col gap-1",children:h}),e[27]=h,e[28]=x):x=e[28];let g;return e[29]!==c||e[30]!==d||e[31]!==u||e[32]!==x?(g=(0,m.jsx)(j,{"data-testid":"ev-card",children:(0,m.jsxs)(w,{className:"flex flex-col gap-3 p-4",children:[c,d,u,x]})}),e[29]=c,e[30]=d,e[31]=u,e[32]=x,e[33]=g):g=e[33],g},"P"),oe=p(s=>{let e=(0,M.c)(19),{initialShardKey:t}=s,n=I(),{queryShardKey:a,setShardKey:l,shardKey:o}=A(t),i=k(a),c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c={},e[0]=c):c=e[0];let r;e[1]!==a?(r={live:!0,shardKey:a},e[1]=a,e[2]=r):r=e[2];let{data:d,error:u}=S(T.getTraces,c,r),h;e[3]===Symbol.for("react.memo_cache_sentinel")?(h={},e[3]=h):h=e[3];let x;e[4]!==a?(x={live:!0,shardKey:a},e[4]=a,e[5]=x):x=e[5];let{data:g}=S(T.getMetricHistory,h,x),v;if(e[6]!==d||e[7]!==u||e[8]!==g||e[9]!==i||e[10]!==l||e[11]!==o||e[12]!==n){let f=R(P(U(d)),Q(g)),y;e[14]!==l||e[15]!==o?(y=(0,m.jsx)($,{onChange:l,testId:"ev-shard-input",value:o}),e[14]=l,e[15]=o,e[16]=y):y=e[16];let b;e[17]!==u?(b=u===null?null:(0,m.jsx)(F,{error:u,testId:"ev-error"}),e[17]=u,e[18]=b):b=e[18],v=(0,m.jsxs)("section",{className:"flex flex-col gap-4","data-testid":"ev-panel",children:[y,b,f.length===0?(0,m.jsx)(O,{description:n("Call recordEvaluation from a graded run and its score shows up here."),testId:"ev-empty",title:n("No evals recorded")}):(0,m.jsx)("div",{className:"grid gap-3 md:grid-cols-2",children:f.map(_=>(0,m.jsx)(z,{card:_,onOpenTrace:i},_.name))})]}),e[6]=d,e[7]=u,e[8]=g,e[9]=i,e[10]=l,e[11]=o,e[12]=n,e[13]=v}else v=e[13];return v},"re");function G(s){return s.last}p(G,"Q");export{oe as default};
@@ -1 +1 @@
1
- import{b as me}from"./chunk-2I4NHEKA.js";import{a as $}from"./chunk-ODMIUMAO.js";import{a as ue}from"./chunk-SV764LKQ.js";import"./chunk-TVCVRQUC.js";import"./chunk-AUGKHAMQ.js";import"./chunk-WJRYEML4.js";import{a as de}from"./chunk-ZKJS6EBE.js";import"./chunk-RGMVGZV4.js";import"./chunk-SJQERRSZ.js";import"./chunk-7Y3SY37W.js";import{b as P}from"./chunk-Q6ED4KUL.js";import"./chunk-BOMPSVRC.js";import"./chunk-55UGUCQ6.js";import{a as A}from"./chunk-4ZEL6BYL.js";import{c as ce}from"./chunk-VRWHCG2V.js";import{l as ne,m as oe}from"./chunk-ICDMV4MP.js";import"./chunk-QAQDMS6R.js";import"./chunk-FQPBYMII.js";import{a as C}from"./chunk-2IKDEUCX.js";import{d as D,f as I,g as Q,h as W,p as _,t as ie}from"./chunk-HJHSQPHW.js";import{a as f,d as T,e as qe,f as ae,g as le,i as M}from"./chunk-I26MS5PJ.js";var Y=T(ae(),1);var h=T(qe(),1);var fe=T(ae(),1);var B=T(le(),1);var Me={connected:"bg-success",connecting:"bg-warning",idle:"bg-muted-foreground",offline:"bg-destructive",polling:"bg-warning"},he=f(()=>{let t=(0,fe.c)(18),e=D(),a=oe(),s;e:switch(a){case"connected":{let n;t[0]!==e?(n=e("Connected"),t[0]=e,t[1]=n):n=t[1],s=n;break e}case"connecting":{let n;t[2]!==e?(n=e("Connecting\u2026"),t[2]=e,t[3]=n):n=t[3],s=n;break e}case"idle":{let n;t[4]!==e?(n=e("Idle"),t[4]=e,t[5]=n):n=t[5],s=n;break e}case"offline":{let n;t[6]!==e?(n=e("Offline"),t[6]=e,t[7]=n):n=t[7],s=n;break e}case"polling":{let n;t[8]!==e?(n=e("Polling"),t[8]=e,t[9]=n):n=t[9],s=n;break e}default:s=a}let l=Me[a],c;t[10]!==l?(c=M("size-2 rounded-full",l),t[10]=l,t[11]=c):c=t[11];let i;t[12]!==c?(i=(0,B.jsx)("span",{"aria-hidden":"true",className:c}),t[12]=c,t[13]=i):i=t[13];let o;return t[14]!==a||t[15]!==i||t[16]!==s?(o=(0,B.jsxs)("span",{"aria-live":"polite",className:"inline-flex items-center gap-1.5 text-xs text-muted-foreground","data-status":a,"data-testid":"dash-connection",role:"status",children:[i,s]}),t[14]=a,t[15]=i,t[16]=s,t[17]=o):o=t[17],o},"T");var r=T(le(),1);var Ae={crit:"destructive",ok:"secondary",warn:"default"},U=f((t,e)=>e===0?"\u2014":`${(t/e*100).toFixed(1)}%`,"P"),X=f((t,e,a)=>Number.isNaN(t)?"ok":t>=a?"crit":t>=e?"warn":"ok","z"),xe=.01,ve=.05,je=f(t=>{let e=(0,Y.c)(36),{errorCount:a,logsError:s,topErrors:l,worstFunctions:c}=t,i=D(),o;e[0]!==i?(o=i("Functions by error rate"),e[0]=i,e[1]=o):o=e[1];let n;e[2]!==o?(n=(0,r.jsx)("header",{className:"border-b border-border px-4 py-3",children:(0,r.jsx)("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:o})}),e[2]=o,e[3]=n):n=e[3];let m;e[4]!==i||e[5]!==c?(m=c.length===0?(0,r.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,r.jsx)("ul",{className:"divide-y divide-border",children:c.map(w=>(0,r.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,r.jsx)("span",{className:"truncate font-mono text-foreground",children:w.path}),(0,r.jsxs)("span",{className:"flex shrink-0 items-center gap-2",children:[(0,r.jsx)("span",{className:"tabular-nums text-muted-foreground",children:i("{count} calls",{count:w.calls.toString()})}),(0,r.jsx)(P,{variant:Ae[X(w.errors/w.calls,xe,ve)],children:U(w.errors,w.calls)})]})]},w.path))}),e[4]=i,e[5]=c,e[6]=m):m=e[6];let p;e[7]!==n||e[8]!==m?(p=(0,r.jsxs)(C,{className:"gap-0 py-0","data-testid":"hl-functions",children:[n,m]}),e[7]=n,e[8]=m,e[9]=p):p=e[9];let v;e[10]!==i?(v=i("Recent errors"),e[10]=i,e[11]=v):v=e[11];let d;e[12]!==v?(d=(0,r.jsx)("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:v}),e[12]=v,e[13]=d):d=e[13];let u=a>0?"destructive":"outline",g;e[14]!==a||e[15]!==u?(g=(0,r.jsx)(P,{"data-testid":"hl-error-count",variant:u,children:a}),e[14]=a,e[15]=u,e[16]=g):g=e[16];let x;e[17]!==d||e[18]!==g?(x=(0,r.jsxs)("header",{className:"flex items-center justify-between gap-2 border-b border-border px-4 py-3",children:[d,g]}),e[17]=d,e[18]=g,e[19]=x):x=e[19];let S;e[20]!==s?(S=s!==null&&(0,r.jsx)("p",{className:"px-4 py-8 text-center text-sm text-destructive","data-testid":"hl-logs-error",role:"alert",children:s}),e[20]=s,e[21]=S):S=e[21];let E;e[22]!==s||e[23]!==i||e[24]!==l.length?(E=s===null&&l.length===0&&(0,r.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]=s,e[23]=i,e[24]=l.length,e[25]=E):E=e[25];let q;e[26]!==l?(q=l.length>0&&(0,r.jsx)("ul",{className:"divide-y divide-border",children:l.map(Ce)}),e[26]=l,e[27]=q):q=e[27];let N;e[28]!==S||e[29]!==E||e[30]!==q||e[31]!==x?(N=(0,r.jsxs)(C,{className:"gap-0 py-0",children:[x,S,E,q]}),e[28]=S,e[29]=E,e[30]=q,e[31]=x,e[32]=N):N=e[32];let k;return e[33]!==N||e[34]!==p?(k=(0,r.jsxs)("div",{className:"grid gap-3 lg:grid-cols-2",children:[p,N]}),e[33]=N,e[34]=p,e[35]=k):k=e[35],k},"ye");function Ce(t,e){return(0,r.jsxs)("li",{className:"flex flex-col gap-0.5 px-4 py-2 text-xs","data-testid":"hl-error-row",children:[(0,r.jsxs)("span",{className:"flex items-center gap-2",children:[(0,r.jsx)("time",{className:"shrink-0 text-muted-foreground",children:ie(t.timestamp)}),t.functionPath!==void 0&&(0,r.jsx)("span",{className:"truncate font-mono text-foreground",children:t.functionPath})]}),(0,r.jsx)("span",{className:"text-destructive",children:t.message})]},`${t.timestamp.toString()}-${e.toString()}`)}f(Ce,"Te");var pe={completed:0,failed:2,in_progress:1},Ie=f(t=>{let e=0,a=0,s=0,l=0,c=!1,i=[];for(let{metrics:o}of t){if(o===null){l+=1;continue}s+=1,e+=o.requests,a+=o.errors,i.push(...o.history??[]),c||=o.historyTruncated===!0}return{errors:a,failed:l,history:i,historyTruncated:c,reachable:s,requests:e}},"Ae"),Te=f(t=>{let e=new Map;for(let a of t)for(let s of a){let l=e.get(s.path);if(l===void 0){e.set(s.path,{...s});continue}l.calls+=s.calls,l.errors+=s.errors,l.totalDurationMs+=s.totalDurationMs,l.scans=(l.scans??0)+(s.scans??0),l.maxDurationMs=Math.max(l.maxDurationMs,s.maxDurationMs),l.lastCalledAt=Math.max(l.lastCalledAt,s.lastCalledAt),(s.lastErrorAt??0)>(l.lastErrorAt??0)&&(l.lastErrorAt=s.lastErrorAt,l.lastErrorMessage=s.lastErrorMessage)}return[...e.values()]},"ke"),De=f(t=>{let e=new Map;for(let a of t)for(let s of a){let l=e.get(s.id);if(l===void 0){e.set(s.id,s);continue}let c=pe[s.status]-pe[l.status];(c>0||c===0&&(s.updatedAt??0)>(l.updatedAt??0))&&e.set(s.id,s)}return[...e.values()]},"Re"),Pe=I(A.getAuthMetrics),Fe=I(A.getFunctionStats),Le=I(A.getLogs),Re=I(A.getMetrics),ze=I(A.migrationStatus),Oe=5,ge=2e3,Ke=5,_e=.1,$e=.3,Be=1,He=50,Ue=f((t,e,a)=>t>=a?"crit":t>=e?"warn":"ok","Pe"),Ge=f(t=>{let e=new Map;for(let s of t??[]){let l=e.get(s.bucketMs)??{calls:0,errors:0};l.calls+=s.calls,l.errors+=s.errors,e.set(s.bucketMs,l)}let a=[...e.entries()].toSorted((s,l)=>s[0]-l[0]);return{errors:a.map(([,s])=>s.errors),requests:a.map(([,s])=>s.calls)}},"Ge"),Ve=f(t=>{let e=0,a=0;for(let l of t)l.status==="failed"?e+=1:l.status==="in_progress"&&(a+=1);let s="ok";return e>0?s="crit":a>0&&(s="warn"),{failed:e,level:s,running:a}},"Ve"),Je=f((t,e)=>t.failed>0?e("{count} failed",{count:t.failed.toString()}):t.running>0?e("{count} running",{count:t.running.toString()}):e("OK"),"Be"),be={crit:"bg-destructive",ok:"bg-success",warn:"bg-warning"},Ne={crit:"text-destructive",ok:"text-foreground",warn:"text-warning"},Qe={crit:"bg-destructive/10 text-destructive",ok:"bg-success/10 text-success",warn:"bg-warning/10 text-warning"},We=f(t=>t.includes("crit")?"crit":t.includes("warn")?"warn":"ok","Ke"),H=f(t=>{let e=(0,Y.c)(19),{chart:a,label:s,level:l,testId:c,value:i}=t,o=be[l],n;e[0]!==o?(n=M("size-1.5 shrink-0 rounded-full",o),e[0]=o,e[1]=n):n=e[1];let m;e[2]!==n?(m=(0,r.jsx)("span",{"aria-hidden":"true",className:n}),e[2]=n,e[3]=m):m=e[3];let p;e[4]!==s||e[5]!==m?(p=(0,r.jsxs)("span",{className:"flex items-center gap-1.5 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:[m,s]}),e[4]=s,e[5]=m,e[6]=p):p=e[6];let v=Ne[l],d;e[7]!==v?(d=M("truncate text-2xl font-semibold tabular-nums",v),e[7]=v,e[8]=d):d=e[8];let u;e[9]!==d||e[10]!==c||e[11]!==i?(u=(0,r.jsx)("span",{className:d,"data-testid":c,children:i}),e[9]=d,e[10]=c,e[11]=i,e[12]=u):u=e[12];let g;e[13]!==a||e[14]!==u?(g=(0,r.jsxs)("div",{className:"flex items-center justify-between gap-3",children:[u,a]}),e[13]=a,e[14]=u,e[15]=g):g=e[15];let x;return e[16]!==p||e[17]!==g?(x=(0,r.jsx)(C,{className:"gap-0 py-0",children:(0,r.jsxs)("div",{className:"flex flex-col gap-2.5 p-4",children:[p,g]})}),e[16]=p,e[17]=g,e[18]=x):x=e[18],x},"U"),Xe=f(async(t,e,a)=>{let s=await Promise.all(a.map(d=>{let u=Q(d);return Promise.allSettled([t.query(Re,{},u),t.query(Fe,{},u),t.query(ze,{},u)])})),l=Q(e),c=typeof t.schedulerStatus=="function"?t.schedulerStatus():Promise.reject(new Error("scheduler status unavailable")),[i,o,n]=await Promise.allSettled([t.query(Le,{},l),t.query(Pe,{},l),c]),m=s.map(([d,u,g])=>({functions:u.status==="fulfilled"?u.value.functions:[],metrics:d.status==="fulfilled"?d.value:null,migrations:g.status==="fulfilled"?g.value.migrations:[]})),p=Ie(m),v=s[0]?.[0];return{auth:o.status==="fulfilled"?o.value:null,entries:i.status==="fulfilled"?i.value.entries:[],functions:Te(m.map(d=>d.functions)),logsError:i.status==="rejected"?W(i.reason):null,metricsError:p.reachable===0&&v?.status==="rejected"?W(v.reason):null,migrations:De(m.map(d=>d.migrations)),scheduler:n.status==="fulfilled"?n.value:null,totals:p}},"$e"),Ye=f(t=>{let e=t?.history??[];return{attempts:e.map(a=>a.attempts),failures:e.map(a=>a.failures)}},"ze"),xt=f(({initialShardKey:t})=>{let e=ne(),a=D(),[s,l]=(0,h.useState)([]),[c,i]=(0,h.useState)(null),[o,n]=(0,h.useState)(null),[m,p]=(0,h.useState)(null),[v,d]=(0,h.useState)([]),[u,g]=(0,h.useState)(null),[x,S]=(0,h.useState)(null),[E,q]=(0,h.useState)([]),[N]=(0,h.useState)(de),k=(0,h.useRef)(!1),w=(0,h.useRef)(0),G=(0,h.useRef)(0),j=(0,h.useRef)(null),F=t??"",L=(0,h.useCallback)(async()=>{if(k.current)return;k.current=!0;let b=w.current,y=await Xe(e,F,me(F,N));b===w.current&&(n(y.totals),p(y.metricsError),d(y.functions),q(y.migrations),l(y.entries),i(y.logsError),g(y.auth),S(y.scheduler),k.current=!1)},[e,N,F]);(0,h.useEffect)(()=>(_(L()),()=>{w.current+=1,k.current=!1,j.current!==null&&(clearTimeout(j.current),j.current=null)}),[L]);let ye=f(()=>{let b=Date.now()-G.current;if(b>=ge){G.current=Date.now(),_(L());return}j.current===null&&(j.current=setTimeout(()=>{j.current=null,G.current=Date.now(),_(L())},ge-b))},"ue"),{data:Z,liveError:we}=ce(A.getMetrics,{},{live:!0,shardKey:F});(0,h.useEffect)(()=>{Z!==void 0&&ye()},[Z]);let ee=s.filter(b=>b.level==="error"),ke=ee.slice(0,Oe),R=Ge(o?.history),te=Ye(u),Se=v.filter(b=>b.calls>0).toSorted((b,y)=>y.errors/y.calls-b.errors/b.calls||y.calls-b.calls).slice(0,Ke),V=Ve(E),Ee=o===null||o.requests===0?0:o.errors/o.requests,J=X(Ee,xe,ve),re=u===null?"ok":X(u.failureRate,_e,$e),se=x===null?"ok":Ue(x.backlog,Be,He),z=We([J,re,se,V.level]),O,K;return z==="crit"?(O=a("Critical"),K=a("One or more service levels are breached.")):z==="warn"?(O=a("Degraded"),K=a("Some service levels need attention.")):(O=a("All systems healthy"),K=a("All service levels are within target.")),(0,r.jsxs)("div",{className:"flex flex-col gap-6","data-testid":"lunora-health",children:[(0,r.jsxs)(C,{className:"gap-0 py-0",children:[(0,r.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-4 p-4",children:[(0,r.jsxs)("div",{className:"flex items-center gap-3",children:[(0,r.jsx)("span",{"aria-hidden":"true",className:M("flex size-10 shrink-0 items-center justify-center rounded-full",Qe[z]),children:(0,r.jsx)("span",{className:M("size-3 rounded-full",be[z])})}),(0,r.jsxs)("div",{className:"grid leading-tight",children:[(0,r.jsx)("span",{className:"text-sm font-semibold text-foreground","data-testid":"hl-status",children:O}),(0,r.jsx)("span",{className:"text-[13px] text-muted-foreground",children:K})]})]}),(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-4",children:[(0,r.jsxs)("div",{className:"text-end",children:[(0,r.jsx)("div",{className:"font-mono text-[10px] tracking-wide text-muted-foreground uppercase",children:a("Requests")}),(0,r.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[R.requests.length>=2&&(0,r.jsx)($,{ariaLabel:a("Requests over time"),className:"h-6 w-20 text-foreground",series:R.requests,testId:"hl-spark-requests"}),(0,r.jsx)("span",{className:"text-lg font-semibold tabular-nums text-foreground","data-testid":"hl-requests",children:(o?.requests??0).toString()})]})]}),(0,r.jsx)("span",{"aria-hidden":"true",className:"h-9 w-px bg-border"}),(0,r.jsxs)("div",{className:"text-end",children:[(0,r.jsx)("div",{className:"font-mono text-[10px] tracking-wide text-muted-foreground uppercase",children:a("Error rate")}),(0,r.jsx)("div",{className:M("text-lg font-semibold tabular-nums",Ne[J]),"data-testid":"hl-error-rate",children:o===null?"\u2014":U(o.errors,o.requests)})]}),(0,r.jsx)("span",{"aria-hidden":"true",className:"h-9 w-px bg-border"}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)(he,{}),(0,r.jsx)(ue,{message:we,prefix:"hl"})]})]})]}),m!==null&&(0,r.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:m}),m===null&&o?.historyTruncated===!0&&(0,r.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:a("Showing a partial request/error history \u2014 one or more shards have more data than the trend chart can display.")})]}),(0,r.jsxs)("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4","data-testid":"hl-slo",children:[(0,r.jsx)(H,{chart:R.errors.length>=2?(0,r.jsx)($,{ariaLabel:a("Errors over time"),className:"h-7 w-20 text-destructive",series:R.errors,testId:"hl-spark-errors"}):void 0,label:a("Error rate"),level:J,testId:"hl-slo-errorrate",value:o===null?"\u2014":U(o.errors,o.requests)}),(0,r.jsx)(H,{chart:te.failures.length>=2?(0,r.jsx)($,{ariaLabel:a("Auth failures over time"),className:"h-7 w-20 text-destructive",series:te.failures,testId:"hl-spark-auth"}):void 0,label:a("Auth failures"),level:re,testId:"hl-slo-auth",value:u===null?"\u2014":U(u.failures,u.attempts)}),(0,r.jsx)(H,{label:a("Scheduler backlog"),level:se,testId:"hl-slo-backlog",value:x===null?"\u2014":x.backlog.toString()}),(0,r.jsx)(H,{label:a("Migrations"),level:V.level,testId:"hl-slo-migrations",value:Je(V,a)})]}),(0,r.jsx)(je,{errorCount:ee.length,logsError:c,topErrors:ke,worstFunctions:Se}),(0,r.jsxs)(C,{className:"gap-0 py-0",children:[(0,r.jsxs)("header",{className:"flex items-center justify-between gap-2 border-b border-border px-4 py-3",children:[(0,r.jsx)("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:a("Shards seen")}),(0,r.jsx)(P,{"data-testid":"hl-shard-count",variant:"outline",children:N.length})]}),N.length>0&&(0,r.jsx)("ul",{className:"flex flex-wrap gap-1.5 p-4",children:N.map(b=>(0,r.jsx)("li",{"data-testid":"hl-shard",children:(0,r.jsx)(P,{variant:"secondary",children:b})},b))})]})]})},"ut");export{xt as HealthPanel};
1
+ import{b as me}from"./chunk-2I4NHEKA.js";import{a as $}from"./chunk-VOWSZXG7.js";import{a as ue}from"./chunk-SV764LKQ.js";import"./chunk-KMQTUDFK.js";import"./chunk-AUGKHAMQ.js";import"./chunk-WJRYEML4.js";import{a as de}from"./chunk-ZKJS6EBE.js";import"./chunk-RGMVGZV4.js";import"./chunk-SJQERRSZ.js";import"./chunk-7Y3SY37W.js";import{b as P}from"./chunk-Q6ED4KUL.js";import"./chunk-BOMPSVRC.js";import"./chunk-55UGUCQ6.js";import{a as A}from"./chunk-4ZEL6BYL.js";import{c as ce}from"./chunk-IPQ5KYVD.js";import{l as ne,m as oe}from"./chunk-JSP7QF52.js";import"./chunk-QAQDMS6R.js";import"./chunk-WVWG6LII.js";import{a as C}from"./chunk-2IKDEUCX.js";import{d as D,f as I,g as Q,h as W,p as _,t as ie}from"./chunk-HJHSQPHW.js";import{a as f,d as T,e as qe,f as ae,g as le,i as M}from"./chunk-I26MS5PJ.js";var Y=T(ae(),1);var h=T(qe(),1);var fe=T(ae(),1);var B=T(le(),1);var Me={connected:"bg-success",connecting:"bg-warning",idle:"bg-muted-foreground",offline:"bg-destructive",polling:"bg-warning"},he=f(()=>{let t=(0,fe.c)(18),e=D(),a=oe(),s;e:switch(a){case"connected":{let n;t[0]!==e?(n=e("Connected"),t[0]=e,t[1]=n):n=t[1],s=n;break e}case"connecting":{let n;t[2]!==e?(n=e("Connecting\u2026"),t[2]=e,t[3]=n):n=t[3],s=n;break e}case"idle":{let n;t[4]!==e?(n=e("Idle"),t[4]=e,t[5]=n):n=t[5],s=n;break e}case"offline":{let n;t[6]!==e?(n=e("Offline"),t[6]=e,t[7]=n):n=t[7],s=n;break e}case"polling":{let n;t[8]!==e?(n=e("Polling"),t[8]=e,t[9]=n):n=t[9],s=n;break e}default:s=a}let l=Me[a],c;t[10]!==l?(c=M("size-2 rounded-full",l),t[10]=l,t[11]=c):c=t[11];let i;t[12]!==c?(i=(0,B.jsx)("span",{"aria-hidden":"true",className:c}),t[12]=c,t[13]=i):i=t[13];let o;return t[14]!==a||t[15]!==i||t[16]!==s?(o=(0,B.jsxs)("span",{"aria-live":"polite",className:"inline-flex items-center gap-1.5 text-xs text-muted-foreground","data-status":a,"data-testid":"dash-connection",role:"status",children:[i,s]}),t[14]=a,t[15]=i,t[16]=s,t[17]=o):o=t[17],o},"T");var r=T(le(),1);var Ae={crit:"destructive",ok:"secondary",warn:"default"},U=f((t,e)=>e===0?"\u2014":`${(t/e*100).toFixed(1)}%`,"P"),X=f((t,e,a)=>Number.isNaN(t)?"ok":t>=a?"crit":t>=e?"warn":"ok","z"),xe=.01,ve=.05,je=f(t=>{let e=(0,Y.c)(36),{errorCount:a,logsError:s,topErrors:l,worstFunctions:c}=t,i=D(),o;e[0]!==i?(o=i("Functions by error rate"),e[0]=i,e[1]=o):o=e[1];let n;e[2]!==o?(n=(0,r.jsx)("header",{className:"border-b border-border px-4 py-3",children:(0,r.jsx)("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:o})}),e[2]=o,e[3]=n):n=e[3];let m;e[4]!==i||e[5]!==c?(m=c.length===0?(0,r.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,r.jsx)("ul",{className:"divide-y divide-border",children:c.map(w=>(0,r.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,r.jsx)("span",{className:"truncate font-mono text-foreground",children:w.path}),(0,r.jsxs)("span",{className:"flex shrink-0 items-center gap-2",children:[(0,r.jsx)("span",{className:"tabular-nums text-muted-foreground",children:i("{count} calls",{count:w.calls.toString()})}),(0,r.jsx)(P,{variant:Ae[X(w.errors/w.calls,xe,ve)],children:U(w.errors,w.calls)})]})]},w.path))}),e[4]=i,e[5]=c,e[6]=m):m=e[6];let p;e[7]!==n||e[8]!==m?(p=(0,r.jsxs)(C,{className:"gap-0 py-0","data-testid":"hl-functions",children:[n,m]}),e[7]=n,e[8]=m,e[9]=p):p=e[9];let v;e[10]!==i?(v=i("Recent errors"),e[10]=i,e[11]=v):v=e[11];let d;e[12]!==v?(d=(0,r.jsx)("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:v}),e[12]=v,e[13]=d):d=e[13];let u=a>0?"destructive":"outline",g;e[14]!==a||e[15]!==u?(g=(0,r.jsx)(P,{"data-testid":"hl-error-count",variant:u,children:a}),e[14]=a,e[15]=u,e[16]=g):g=e[16];let x;e[17]!==d||e[18]!==g?(x=(0,r.jsxs)("header",{className:"flex items-center justify-between gap-2 border-b border-border px-4 py-3",children:[d,g]}),e[17]=d,e[18]=g,e[19]=x):x=e[19];let S;e[20]!==s?(S=s!==null&&(0,r.jsx)("p",{className:"px-4 py-8 text-center text-sm text-destructive","data-testid":"hl-logs-error",role:"alert",children:s}),e[20]=s,e[21]=S):S=e[21];let E;e[22]!==s||e[23]!==i||e[24]!==l.length?(E=s===null&&l.length===0&&(0,r.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]=s,e[23]=i,e[24]=l.length,e[25]=E):E=e[25];let q;e[26]!==l?(q=l.length>0&&(0,r.jsx)("ul",{className:"divide-y divide-border",children:l.map(Ce)}),e[26]=l,e[27]=q):q=e[27];let N;e[28]!==S||e[29]!==E||e[30]!==q||e[31]!==x?(N=(0,r.jsxs)(C,{className:"gap-0 py-0",children:[x,S,E,q]}),e[28]=S,e[29]=E,e[30]=q,e[31]=x,e[32]=N):N=e[32];let k;return e[33]!==N||e[34]!==p?(k=(0,r.jsxs)("div",{className:"grid gap-3 lg:grid-cols-2",children:[p,N]}),e[33]=N,e[34]=p,e[35]=k):k=e[35],k},"ye");function Ce(t,e){return(0,r.jsxs)("li",{className:"flex flex-col gap-0.5 px-4 py-2 text-xs","data-testid":"hl-error-row",children:[(0,r.jsxs)("span",{className:"flex items-center gap-2",children:[(0,r.jsx)("time",{className:"shrink-0 text-muted-foreground",children:ie(t.timestamp)}),t.functionPath!==void 0&&(0,r.jsx)("span",{className:"truncate font-mono text-foreground",children:t.functionPath})]}),(0,r.jsx)("span",{className:"text-destructive",children:t.message})]},`${t.timestamp.toString()}-${e.toString()}`)}f(Ce,"Te");var pe={completed:0,failed:2,in_progress:1},Ie=f(t=>{let e=0,a=0,s=0,l=0,c=!1,i=[];for(let{metrics:o}of t){if(o===null){l+=1;continue}s+=1,e+=o.requests,a+=o.errors,i.push(...o.history??[]),c||=o.historyTruncated===!0}return{errors:a,failed:l,history:i,historyTruncated:c,reachable:s,requests:e}},"Ae"),Te=f(t=>{let e=new Map;for(let a of t)for(let s of a){let l=e.get(s.path);if(l===void 0){e.set(s.path,{...s});continue}l.calls+=s.calls,l.errors+=s.errors,l.totalDurationMs+=s.totalDurationMs,l.scans=(l.scans??0)+(s.scans??0),l.maxDurationMs=Math.max(l.maxDurationMs,s.maxDurationMs),l.lastCalledAt=Math.max(l.lastCalledAt,s.lastCalledAt),(s.lastErrorAt??0)>(l.lastErrorAt??0)&&(l.lastErrorAt=s.lastErrorAt,l.lastErrorMessage=s.lastErrorMessage)}return[...e.values()]},"ke"),De=f(t=>{let e=new Map;for(let a of t)for(let s of a){let l=e.get(s.id);if(l===void 0){e.set(s.id,s);continue}let c=pe[s.status]-pe[l.status];(c>0||c===0&&(s.updatedAt??0)>(l.updatedAt??0))&&e.set(s.id,s)}return[...e.values()]},"Re"),Pe=I(A.getAuthMetrics),Fe=I(A.getFunctionStats),Le=I(A.getLogs),Re=I(A.getMetrics),ze=I(A.migrationStatus),Oe=5,ge=2e3,Ke=5,_e=.1,$e=.3,Be=1,He=50,Ue=f((t,e,a)=>t>=a?"crit":t>=e?"warn":"ok","Pe"),Ge=f(t=>{let e=new Map;for(let s of t??[]){let l=e.get(s.bucketMs)??{calls:0,errors:0};l.calls+=s.calls,l.errors+=s.errors,e.set(s.bucketMs,l)}let a=[...e.entries()].toSorted((s,l)=>s[0]-l[0]);return{errors:a.map(([,s])=>s.errors),requests:a.map(([,s])=>s.calls)}},"Ge"),Ve=f(t=>{let e=0,a=0;for(let l of t)l.status==="failed"?e+=1:l.status==="in_progress"&&(a+=1);let s="ok";return e>0?s="crit":a>0&&(s="warn"),{failed:e,level:s,running:a}},"Ve"),Je=f((t,e)=>t.failed>0?e("{count} failed",{count:t.failed.toString()}):t.running>0?e("{count} running",{count:t.running.toString()}):e("OK"),"Be"),be={crit:"bg-destructive",ok:"bg-success",warn:"bg-warning"},Ne={crit:"text-destructive",ok:"text-foreground",warn:"text-warning"},Qe={crit:"bg-destructive/10 text-destructive",ok:"bg-success/10 text-success",warn:"bg-warning/10 text-warning"},We=f(t=>t.includes("crit")?"crit":t.includes("warn")?"warn":"ok","Ke"),H=f(t=>{let e=(0,Y.c)(19),{chart:a,label:s,level:l,testId:c,value:i}=t,o=be[l],n;e[0]!==o?(n=M("size-1.5 shrink-0 rounded-full",o),e[0]=o,e[1]=n):n=e[1];let m;e[2]!==n?(m=(0,r.jsx)("span",{"aria-hidden":"true",className:n}),e[2]=n,e[3]=m):m=e[3];let p;e[4]!==s||e[5]!==m?(p=(0,r.jsxs)("span",{className:"flex items-center gap-1.5 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:[m,s]}),e[4]=s,e[5]=m,e[6]=p):p=e[6];let v=Ne[l],d;e[7]!==v?(d=M("truncate text-2xl font-semibold tabular-nums",v),e[7]=v,e[8]=d):d=e[8];let u;e[9]!==d||e[10]!==c||e[11]!==i?(u=(0,r.jsx)("span",{className:d,"data-testid":c,children:i}),e[9]=d,e[10]=c,e[11]=i,e[12]=u):u=e[12];let g;e[13]!==a||e[14]!==u?(g=(0,r.jsxs)("div",{className:"flex items-center justify-between gap-3",children:[u,a]}),e[13]=a,e[14]=u,e[15]=g):g=e[15];let x;return e[16]!==p||e[17]!==g?(x=(0,r.jsx)(C,{className:"gap-0 py-0",children:(0,r.jsxs)("div",{className:"flex flex-col gap-2.5 p-4",children:[p,g]})}),e[16]=p,e[17]=g,e[18]=x):x=e[18],x},"U"),Xe=f(async(t,e,a)=>{let s=await Promise.all(a.map(d=>{let u=Q(d);return Promise.allSettled([t.query(Re,{},u),t.query(Fe,{},u),t.query(ze,{},u)])})),l=Q(e),c=typeof t.schedulerStatus=="function"?t.schedulerStatus():Promise.reject(new Error("scheduler status unavailable")),[i,o,n]=await Promise.allSettled([t.query(Le,{},l),t.query(Pe,{},l),c]),m=s.map(([d,u,g])=>({functions:u.status==="fulfilled"?u.value.functions:[],metrics:d.status==="fulfilled"?d.value:null,migrations:g.status==="fulfilled"?g.value.migrations:[]})),p=Ie(m),v=s[0]?.[0];return{auth:o.status==="fulfilled"?o.value:null,entries:i.status==="fulfilled"?i.value.entries:[],functions:Te(m.map(d=>d.functions)),logsError:i.status==="rejected"?W(i.reason):null,metricsError:p.reachable===0&&v?.status==="rejected"?W(v.reason):null,migrations:De(m.map(d=>d.migrations)),scheduler:n.status==="fulfilled"?n.value:null,totals:p}},"$e"),Ye=f(t=>{let e=t?.history??[];return{attempts:e.map(a=>a.attempts),failures:e.map(a=>a.failures)}},"ze"),xt=f(({initialShardKey:t})=>{let e=ne(),a=D(),[s,l]=(0,h.useState)([]),[c,i]=(0,h.useState)(null),[o,n]=(0,h.useState)(null),[m,p]=(0,h.useState)(null),[v,d]=(0,h.useState)([]),[u,g]=(0,h.useState)(null),[x,S]=(0,h.useState)(null),[E,q]=(0,h.useState)([]),[N]=(0,h.useState)(de),k=(0,h.useRef)(!1),w=(0,h.useRef)(0),G=(0,h.useRef)(0),j=(0,h.useRef)(null),F=t??"",L=(0,h.useCallback)(async()=>{if(k.current)return;k.current=!0;let b=w.current,y=await Xe(e,F,me(F,N));b===w.current&&(n(y.totals),p(y.metricsError),d(y.functions),q(y.migrations),l(y.entries),i(y.logsError),g(y.auth),S(y.scheduler),k.current=!1)},[e,N,F]);(0,h.useEffect)(()=>(_(L()),()=>{w.current+=1,k.current=!1,j.current!==null&&(clearTimeout(j.current),j.current=null)}),[L]);let ye=f(()=>{let b=Date.now()-G.current;if(b>=ge){G.current=Date.now(),_(L());return}j.current===null&&(j.current=setTimeout(()=>{j.current=null,G.current=Date.now(),_(L())},ge-b))},"ue"),{data:Z,liveError:we}=ce(A.getMetrics,{},{live:!0,shardKey:F});(0,h.useEffect)(()=>{Z!==void 0&&ye()},[Z]);let ee=s.filter(b=>b.level==="error"),ke=ee.slice(0,Oe),R=Ge(o?.history),te=Ye(u),Se=v.filter(b=>b.calls>0).toSorted((b,y)=>y.errors/y.calls-b.errors/b.calls||y.calls-b.calls).slice(0,Ke),V=Ve(E),Ee=o===null||o.requests===0?0:o.errors/o.requests,J=X(Ee,xe,ve),re=u===null?"ok":X(u.failureRate,_e,$e),se=x===null?"ok":Ue(x.backlog,Be,He),z=We([J,re,se,V.level]),O,K;return z==="crit"?(O=a("Critical"),K=a("One or more service levels are breached.")):z==="warn"?(O=a("Degraded"),K=a("Some service levels need attention.")):(O=a("All systems healthy"),K=a("All service levels are within target.")),(0,r.jsxs)("div",{className:"flex flex-col gap-6","data-testid":"lunora-health",children:[(0,r.jsxs)(C,{className:"gap-0 py-0",children:[(0,r.jsxs)("div",{className:"flex flex-wrap items-center justify-between gap-4 p-4",children:[(0,r.jsxs)("div",{className:"flex items-center gap-3",children:[(0,r.jsx)("span",{"aria-hidden":"true",className:M("flex size-10 shrink-0 items-center justify-center rounded-full",Qe[z]),children:(0,r.jsx)("span",{className:M("size-3 rounded-full",be[z])})}),(0,r.jsxs)("div",{className:"grid leading-tight",children:[(0,r.jsx)("span",{className:"text-sm font-semibold text-foreground","data-testid":"hl-status",children:O}),(0,r.jsx)("span",{className:"text-[13px] text-muted-foreground",children:K})]})]}),(0,r.jsxs)("div",{className:"flex flex-wrap items-center gap-4",children:[(0,r.jsxs)("div",{className:"text-end",children:[(0,r.jsx)("div",{className:"font-mono text-[10px] tracking-wide text-muted-foreground uppercase",children:a("Requests")}),(0,r.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[R.requests.length>=2&&(0,r.jsx)($,{ariaLabel:a("Requests over time"),className:"h-6 w-20 text-foreground",series:R.requests,testId:"hl-spark-requests"}),(0,r.jsx)("span",{className:"text-lg font-semibold tabular-nums text-foreground","data-testid":"hl-requests",children:(o?.requests??0).toString()})]})]}),(0,r.jsx)("span",{"aria-hidden":"true",className:"h-9 w-px bg-border"}),(0,r.jsxs)("div",{className:"text-end",children:[(0,r.jsx)("div",{className:"font-mono text-[10px] tracking-wide text-muted-foreground uppercase",children:a("Error rate")}),(0,r.jsx)("div",{className:M("text-lg font-semibold tabular-nums",Ne[J]),"data-testid":"hl-error-rate",children:o===null?"\u2014":U(o.errors,o.requests)})]}),(0,r.jsx)("span",{"aria-hidden":"true",className:"h-9 w-px bg-border"}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)(he,{}),(0,r.jsx)(ue,{message:we,prefix:"hl"})]})]})]}),m!==null&&(0,r.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:m}),m===null&&o?.historyTruncated===!0&&(0,r.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:a("Showing a partial request/error history \u2014 one or more shards have more data than the trend chart can display.")})]}),(0,r.jsxs)("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4","data-testid":"hl-slo",children:[(0,r.jsx)(H,{chart:R.errors.length>=2?(0,r.jsx)($,{ariaLabel:a("Errors over time"),className:"h-7 w-20 text-destructive",series:R.errors,testId:"hl-spark-errors"}):void 0,label:a("Error rate"),level:J,testId:"hl-slo-errorrate",value:o===null?"\u2014":U(o.errors,o.requests)}),(0,r.jsx)(H,{chart:te.failures.length>=2?(0,r.jsx)($,{ariaLabel:a("Auth failures over time"),className:"h-7 w-20 text-destructive",series:te.failures,testId:"hl-spark-auth"}):void 0,label:a("Auth failures"),level:re,testId:"hl-slo-auth",value:u===null?"\u2014":U(u.failures,u.attempts)}),(0,r.jsx)(H,{label:a("Scheduler backlog"),level:se,testId:"hl-slo-backlog",value:x===null?"\u2014":x.backlog.toString()}),(0,r.jsx)(H,{label:a("Migrations"),level:V.level,testId:"hl-slo-migrations",value:Je(V,a)})]}),(0,r.jsx)(je,{errorCount:ee.length,logsError:c,topErrors:ke,worstFunctions:Se}),(0,r.jsxs)(C,{className:"gap-0 py-0",children:[(0,r.jsxs)("header",{className:"flex items-center justify-between gap-2 border-b border-border px-4 py-3",children:[(0,r.jsx)("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:a("Shards seen")}),(0,r.jsx)(P,{"data-testid":"hl-shard-count",variant:"outline",children:N.length})]}),N.length>0&&(0,r.jsx)("ul",{className:"flex flex-wrap gap-1.5 p-4",children:N.map(b=>(0,r.jsx)("li",{"data-testid":"hl-shard",children:(0,r.jsx)(P,{variant:"secondary",children:b})},b))})]})]})},"ut");export{xt as HealthPanel};
@@ -1 +1 @@
1
- import{a as Z}from"./chunk-R6U22RSY.js";import{a as te}from"./chunk-XHRKNCCI.js";import{a as Y}from"./chunk-YVR4SEPU.js";import{b as X}from"./chunk-ZKJS6EBE.js";import{a as W}from"./chunk-FUYEZFBP.js";import"./chunk-RGMVGZV4.js";import{i as G}from"./chunk-OQ6I6OXT.js";import"./chunk-E4PXACVL.js";import"./chunk-MVWZMWPD.js";import"./chunk-SJQERRSZ.js";import"./chunk-7Y3SY37W.js";import{b as ae,c as ne}from"./chunk-FSSQB6RQ.js";import{a as q,b as ee}from"./chunk-GWOHQJIL.js";import{a as Q}from"./chunk-7G4Z6Q7X.js";import"./chunk-3YXASVTP.js";import"./chunk-AUAECCXB.js";import"./chunk-BOMPSVRC.js";import"./chunk-SJUYCXDY.js";import"./chunk-NCPW7WHO.js";import"./chunk-3V25YSWQ.js";import"./chunk-55UGUCQ6.js";import{a as I}from"./chunk-4ZEL6BYL.js";import{c as _}from"./chunk-VRWHCG2V.js";import{l as D}from"./chunk-ICDMV4MP.js";import"./chunk-QAQDMS6R.js";import"./chunk-FQPBYMII.js";import"./chunk-HCTJKP5J.js";import"./chunk-2IKDEUCX.js";import{d as M,f as C,g as A,l as V,p as N}from"./chunk-HJHSQPHW.js";import{a as l,d as j,e as he,f as me,g as pe}from"./chunk-I26MS5PJ.js";var E=j(me(),1);var c=j(he(),1);var S=j(pe(),1);var ge=l(t=>{let{suggestedIndex:e,table:i}=t;if(typeof i!="string"||i.length===0||typeof e!="object"||e===null)return!1;let{fields:a,name:n}=e;return!Array.isArray(a)||a.length===0||a.some(s=>typeof s!="string"||s.length===0)?!1:typeof n=="string"&&n.length>0},"ye"),be=l((t,e)=>`.index(${JSON.stringify(t)}, [${e.map(i=>JSON.stringify(i)).join(", ")}])`,"ge"),ye=l(t=>{let e=(0,E.c)(19),{fields:i,indexName:a,table:n,testId:s}=t,u=M(),[h,f]=(0,c.useState)(null),m;e[0]!==i||e[1]!==a?(m=l(()=>{let b=be(a,i),$="navigator"in globalThis?globalThis.navigator.clipboard:void 0;if($===void 0){f({copied:!1,declaration:b});return}N($.writeText(b).then(()=>(f({copied:!0,declaration:b}),!0)),()=>{f({copied:!1,declaration:b})})},"m"),e[0]=i,e[1]=a,e[2]=m):m=e[2];let x=m;if(h!==null){let b;return e[3]!==h.copied||e[4]!==h.declaration||e[5]!==u||e[6]!==n||e[7]!==s?(b=h.copied?(0,S.jsx)("span",{className:"text-xs text-muted-foreground","data-testid":`${s}-applied`,children:u("Index declaration copied \u2014 add it to {table} in lunora/schema.ts.",{table:n})}):(0,S.jsxs)("span",{className:"flex flex-col gap-1 text-xs text-muted-foreground","data-testid":`${s}-manual`,children:[u("Could not reach the clipboard \u2014 add this to {table} in lunora/schema.ts:",{table:n}),(0,S.jsx)("code",{className:"font-mono break-all select-all",children:h.declaration})]}),e[3]=h.copied,e[4]=h.declaration,e[5]=u,e[6]=n,e[7]=s,e[8]=b):b=e[8],b}let T;e[9]!==u?(T=u("Copy?"),e[9]=u,e[10]=T):T=e[10];let p;e[11]!==u||e[12]!==n?(p=u("Copy index declaration for {table}",{table:n}),e[11]=u,e[12]=n,e[13]=p):p=e[13];let w;return e[14]!==x||e[15]!==T||e[16]!==p||e[17]!==s?(w=(0,S.jsx)(te,{confirmLabel:T,onConfirm:x,testId:s,children:p}),e[14]=x,e[15]=T,e[16]=p,e[17]=s,e[18]=w):w=e[18],w},"ve"),xe=l((t,e)=>{let i=new Map;for(let a of e){let n=`${a.table} ${a.index}`;i.set(n,(i.get(n)??0)+a.reads)}return t.map(a=>({index:a.index,reads:i.get(`${a.table} ${a.index}`)??0,table:a.table}))},"Se"),ve=l(t=>{let e=new Map;for(let i of t)for(let a of i.scannedTables??[])e.set(a.table,(e.get(a.table)??0)+a.scans);return[...e].map(([i,a])=>({scans:a,table:i}))},"Te"),ie=l((t,e)=>e.map(i=>({index:i.name,table:t})),"P"),we=l(t=>{let e=xe(t.declaredIndexes??[],t.indexHits??[]),i=ve(t.functions??[]),a=t.shardTraffic??[],n=t.analyticsMetrics,s=n&&n.indexHits.length>0?n.indexHits:e,u=n&&n.tableScans.length>0?n.tableScans:i,h=n&&n.shardTraffic.length>0?n.shardTraffic:a,f=ne({indexHits:s,schema:{tables:[]},shardTraffic:h,tableScans:u},{lints:ae,source:"runtime"}),m=t.suppressHotScanTables;return(m===void 0?f:f.filter(x=>!(x.metadata.kind==="hot_scan"&&typeof x.metadata.table=="string"&&m.has(x.metadata.table)))).map(x=>q(x))},"we"),Se=C(I.listTables),Te=C(I.listTableIndexes),Ie=C(I.listTablesIndexes),B=l(t=>`${(t*100).toFixed(1)}%`,"L"),re=l(t=>`${(t/1e3).toFixed(2)}s`,"V"),$e=l(t=>{if(t.length<=1)return t[0]??"";let e=t[t.length-1]??"";return`${t.slice(0,-1).join(", ")} and ${e}`},"Ne"),ke=l((t,e)=>({"high-error-rate":t("High error rate"),"high-evictions":t("High cache eviction rate"),"high-write-contention":t("High write contention"),"low-cache-hit-rate":t("Low cache hit rate"),"missing-index":t("Missing index"),"slow-function":t("Slow function"),"storage-headroom":t("Storage headroom")})[e.kind],"ke"),se=l((t,e)=>({"high-error-rate":t("{rate} of calls failed.",{rate:B(e.value)}),"high-evictions":t("{count} entries evicted recently.",{count:e.value}),"high-write-contention":t("{rate} of calls hit a write conflict \u2014 consider sharding to cut contention.",{rate:B(e.value)}),"low-cache-hit-rate":t("{rate} hit rate over recent traffic.",{rate:B(e.value)}),"missing-index":t("Slowest call took {duration} \u2014 it full-scanned {tables} with no index.",{duration:re(e.value),tables:$e(e.tables??[])}),"slow-function":t("Slowest call took {duration}.",{duration:re(e.value)}),"storage-headroom":t("{size} of the 10 GiB per-shard ceiling \u2014 plan a .shardBy() migration while it still has runway.",{size:V(e.value)})})[e.kind],"U"),Ne=l(t=>{let e=(0,E.c)(10),{onJump:i,table:a}=t,n=M(),s;e[0]!==i||e[1]!==a?(s=l(()=>{i(a)},"i"),e[0]=i,e[1]=a,e[2]=s):s=e[2];let u=s,h=`in-add-index-${a}`,f;e[3]!==n||e[4]!==a?(f=n("Add index on {table}",{table:a}),e[3]=n,e[4]=a,e[5]=f):f=e[5];let m;return e[6]!==u||e[7]!==h||e[8]!==f?(m=(0,S.jsx)(Q,{"data-testid":h,onClick:u,size:"sm",type:"button",variant:"outline",children:f}),e[6]=u,e[7]=h,e[8]=f,e[9]=m):m=e[9],m},"Be"),ze=l(({initialShardKey:t,loadShardTraffic:e})=>{let i=D(),a=G(),n=M(),{queryShardKey:s,setShardKey:u,shardKey:h}=Z(t),[f,m]=(0,c.useState)(null),[x,T]=(0,c.useState)(null),p=(0,c.useRef)(""),w=_(I.getMetrics,{},{live:!0,shardKey:s}),b=_(I.getFunctionStats,{},{live:!0,shardKey:s}),$=_(I.getAdvisories,{},{live:!0,shardKey:s}),L=w.data??null,H=b.data?.functions??null,F=$.data?.advisories??null,J=w.data?.indexHits??null,O=w.error!==null&&b.error!==null?w.error:null,oe=e??(r=>i.shardTraffic(r)),le=l(async(r,y)=>{let o=r[0];if(o===void 0||o===""){p.current===y&&T(null);return}try{let g=await oe(o);if(p.current!==y)return;let d=new Map;for(let v of g.shards)d.has(v.shardKey)||d.set(v.shardKey,{requests:v.requests,shardKey:v.shardKey});T([...d.values()])}catch{p.current===y&&T(null)}},"Y"),de=l(async(r,y)=>{let o=await Promise.allSettled(r.map(async d=>[d,await i.query(Te,{table:d},A(y))])),g=[];for(let d of o)if(d.status==="fulfilled"){let[v,k]=d.value;g.push(...ie(v,k.indexes))}return g},"Z"),z=(0,c.useEffectEvent)(async r=>{p.current=r;let y=[];try{let o=await i.query(Se,{},A(r));if(p.current!==r)return;X(r),y=o.map(d=>d.name);let g=[];if(y.length>0)try{let d=await i.query(Ie,{tables:y},A(r));if(p.current!==r)return;for(let[v,k]of Object.entries(d.indexesByTable))g.push(...ie(v,k))}catch{if(g=await de(y,r),p.current!==r)return}m(g)}catch{p.current===r&&m(null)}await le(y,r)});(0,c.useEffect)(()=>{N(z(s))},[s]);let ce=(0,c.useEffectEvent)(()=>{w.refetch(),b.refetch(),$.refetch(),N(z(s))});(0,c.useEffect)(()=>{let r=l(()=>{document.visibilityState==="visible"&&ce()},"r");return document.addEventListener("visibilitychange",r),()=>{document.removeEventListener("visibilitychange",r)}},[]);let U=(0,c.useCallback)(r=>{N(a({search:{table:r},to:"/schema"}))},[a]),K=(0,c.useMemo)(()=>W(L,H),[H,L]),P=(0,c.useMemo)(()=>new Set(K.filter(r=>r.kind==="missing-index").flatMap(r=>r.tables??[])),[K]),R=(0,c.useMemo)(()=>we({declaredIndexes:f??[],functions:H,indexHits:J,shardTraffic:x,suppressHotScanTables:P}),[f,H,J,P,x]),ue=(0,c.useMemo)(()=>{let r=K.map(o=>{let g=o.kind==="missing-index"?o.tables??[]:[];return{action:g.length>0?g.map(d=>(0,S.jsx)(Ne,{onJump:U,table:d},d)):void 0,description:o.message===void 0?se(n,o):`${se(n,o)} \u2014 ${o.message}`,entity:o.fn,issueType:ke(n,o),key:`${o.kind}:${o.fn??""}`,level:o.severity}}),y=new Set(["unindexed_foreign_key","unindexed_relation_target"]);return[...(F??[]).map(o=>{let g=q(o);if(y.has(o.name)&&ge(o.metadata)){let{table:d,suggestedIndex:v}=o.metadata,k=`in-apply-index-${d}-${v.name}`;return{...g,action:(0,S.jsx)(ye,{fields:v.fields,indexName:v.name,table:d,testId:k})}}return g}),...R,...r]},[F,K,U,R,n]),fe=(0,S.jsx)(Y,{onChange:u,testId:"in-shard-input",value:h});return(0,S.jsx)(ee,{error:O,errorSource:O===null?void 0:w.errorSource,rows:ue,testId:"lunora-insights",toolbar:fe})},"Ue");export{ze as InsightsPanel};
1
+ import{a as Z}from"./chunk-R6U22RSY.js";import{a as te}from"./chunk-XHRKNCCI.js";import{a as Y}from"./chunk-YVR4SEPU.js";import{b as X}from"./chunk-ZKJS6EBE.js";import{a as W}from"./chunk-FUYEZFBP.js";import"./chunk-RGMVGZV4.js";import{i as G}from"./chunk-OQ6I6OXT.js";import"./chunk-E4PXACVL.js";import"./chunk-MVWZMWPD.js";import"./chunk-SJQERRSZ.js";import"./chunk-7Y3SY37W.js";import{b as ae,c as ne}from"./chunk-FSSQB6RQ.js";import{a as q,b as ee}from"./chunk-R2JJKTII.js";import{a as Q}from"./chunk-7G4Z6Q7X.js";import"./chunk-3YXASVTP.js";import"./chunk-AUAECCXB.js";import"./chunk-BOMPSVRC.js";import"./chunk-SEZ2IRFD.js";import"./chunk-NCPW7WHO.js";import"./chunk-N4SDDVZW.js";import"./chunk-55UGUCQ6.js";import{a as I}from"./chunk-4ZEL6BYL.js";import{c as _}from"./chunk-IPQ5KYVD.js";import{l as D}from"./chunk-JSP7QF52.js";import"./chunk-QAQDMS6R.js";import"./chunk-WVWG6LII.js";import"./chunk-HCTJKP5J.js";import"./chunk-2IKDEUCX.js";import{d as M,f as C,g as A,l as V,p as N}from"./chunk-HJHSQPHW.js";import{a as l,d as j,e as he,f as me,g as pe}from"./chunk-I26MS5PJ.js";var E=j(me(),1);var c=j(he(),1);var S=j(pe(),1);var ge=l(t=>{let{suggestedIndex:e,table:i}=t;if(typeof i!="string"||i.length===0||typeof e!="object"||e===null)return!1;let{fields:a,name:n}=e;return!Array.isArray(a)||a.length===0||a.some(s=>typeof s!="string"||s.length===0)?!1:typeof n=="string"&&n.length>0},"ye"),be=l((t,e)=>`.index(${JSON.stringify(t)}, [${e.map(i=>JSON.stringify(i)).join(", ")}])`,"ge"),ye=l(t=>{let e=(0,E.c)(19),{fields:i,indexName:a,table:n,testId:s}=t,u=M(),[h,f]=(0,c.useState)(null),m;e[0]!==i||e[1]!==a?(m=l(()=>{let b=be(a,i),$="navigator"in globalThis?globalThis.navigator.clipboard:void 0;if($===void 0){f({copied:!1,declaration:b});return}N($.writeText(b).then(()=>(f({copied:!0,declaration:b}),!0)),()=>{f({copied:!1,declaration:b})})},"m"),e[0]=i,e[1]=a,e[2]=m):m=e[2];let x=m;if(h!==null){let b;return e[3]!==h.copied||e[4]!==h.declaration||e[5]!==u||e[6]!==n||e[7]!==s?(b=h.copied?(0,S.jsx)("span",{className:"text-xs text-muted-foreground","data-testid":`${s}-applied`,children:u("Index declaration copied \u2014 add it to {table} in lunora/schema.ts.",{table:n})}):(0,S.jsxs)("span",{className:"flex flex-col gap-1 text-xs text-muted-foreground","data-testid":`${s}-manual`,children:[u("Could not reach the clipboard \u2014 add this to {table} in lunora/schema.ts:",{table:n}),(0,S.jsx)("code",{className:"font-mono break-all select-all",children:h.declaration})]}),e[3]=h.copied,e[4]=h.declaration,e[5]=u,e[6]=n,e[7]=s,e[8]=b):b=e[8],b}let T;e[9]!==u?(T=u("Copy?"),e[9]=u,e[10]=T):T=e[10];let p;e[11]!==u||e[12]!==n?(p=u("Copy index declaration for {table}",{table:n}),e[11]=u,e[12]=n,e[13]=p):p=e[13];let w;return e[14]!==x||e[15]!==T||e[16]!==p||e[17]!==s?(w=(0,S.jsx)(te,{confirmLabel:T,onConfirm:x,testId:s,children:p}),e[14]=x,e[15]=T,e[16]=p,e[17]=s,e[18]=w):w=e[18],w},"ve"),xe=l((t,e)=>{let i=new Map;for(let a of e){let n=`${a.table} ${a.index}`;i.set(n,(i.get(n)??0)+a.reads)}return t.map(a=>({index:a.index,reads:i.get(`${a.table} ${a.index}`)??0,table:a.table}))},"Se"),ve=l(t=>{let e=new Map;for(let i of t)for(let a of i.scannedTables??[])e.set(a.table,(e.get(a.table)??0)+a.scans);return[...e].map(([i,a])=>({scans:a,table:i}))},"Te"),ie=l((t,e)=>e.map(i=>({index:i.name,table:t})),"P"),we=l(t=>{let e=xe(t.declaredIndexes??[],t.indexHits??[]),i=ve(t.functions??[]),a=t.shardTraffic??[],n=t.analyticsMetrics,s=n&&n.indexHits.length>0?n.indexHits:e,u=n&&n.tableScans.length>0?n.tableScans:i,h=n&&n.shardTraffic.length>0?n.shardTraffic:a,f=ne({indexHits:s,schema:{tables:[]},shardTraffic:h,tableScans:u},{lints:ae,source:"runtime"}),m=t.suppressHotScanTables;return(m===void 0?f:f.filter(x=>!(x.metadata.kind==="hot_scan"&&typeof x.metadata.table=="string"&&m.has(x.metadata.table)))).map(x=>q(x))},"we"),Se=C(I.listTables),Te=C(I.listTableIndexes),Ie=C(I.listTablesIndexes),B=l(t=>`${(t*100).toFixed(1)}%`,"L"),re=l(t=>`${(t/1e3).toFixed(2)}s`,"V"),$e=l(t=>{if(t.length<=1)return t[0]??"";let e=t[t.length-1]??"";return`${t.slice(0,-1).join(", ")} and ${e}`},"Ne"),ke=l((t,e)=>({"high-error-rate":t("High error rate"),"high-evictions":t("High cache eviction rate"),"high-write-contention":t("High write contention"),"low-cache-hit-rate":t("Low cache hit rate"),"missing-index":t("Missing index"),"slow-function":t("Slow function"),"storage-headroom":t("Storage headroom")})[e.kind],"ke"),se=l((t,e)=>({"high-error-rate":t("{rate} of calls failed.",{rate:B(e.value)}),"high-evictions":t("{count} entries evicted recently.",{count:e.value}),"high-write-contention":t("{rate} of calls hit a write conflict \u2014 consider sharding to cut contention.",{rate:B(e.value)}),"low-cache-hit-rate":t("{rate} hit rate over recent traffic.",{rate:B(e.value)}),"missing-index":t("Slowest call took {duration} \u2014 it full-scanned {tables} with no index.",{duration:re(e.value),tables:$e(e.tables??[])}),"slow-function":t("Slowest call took {duration}.",{duration:re(e.value)}),"storage-headroom":t("{size} of the 10 GiB per-shard ceiling \u2014 plan a .shardBy() migration while it still has runway.",{size:V(e.value)})})[e.kind],"U"),Ne=l(t=>{let e=(0,E.c)(10),{onJump:i,table:a}=t,n=M(),s;e[0]!==i||e[1]!==a?(s=l(()=>{i(a)},"i"),e[0]=i,e[1]=a,e[2]=s):s=e[2];let u=s,h=`in-add-index-${a}`,f;e[3]!==n||e[4]!==a?(f=n("Add index on {table}",{table:a}),e[3]=n,e[4]=a,e[5]=f):f=e[5];let m;return e[6]!==u||e[7]!==h||e[8]!==f?(m=(0,S.jsx)(Q,{"data-testid":h,onClick:u,size:"sm",type:"button",variant:"outline",children:f}),e[6]=u,e[7]=h,e[8]=f,e[9]=m):m=e[9],m},"Be"),ze=l(({initialShardKey:t,loadShardTraffic:e})=>{let i=D(),a=G(),n=M(),{queryShardKey:s,setShardKey:u,shardKey:h}=Z(t),[f,m]=(0,c.useState)(null),[x,T]=(0,c.useState)(null),p=(0,c.useRef)(""),w=_(I.getMetrics,{},{live:!0,shardKey:s}),b=_(I.getFunctionStats,{},{live:!0,shardKey:s}),$=_(I.getAdvisories,{},{live:!0,shardKey:s}),L=w.data??null,H=b.data?.functions??null,F=$.data?.advisories??null,J=w.data?.indexHits??null,O=w.error!==null&&b.error!==null?w.error:null,oe=e??(r=>i.shardTraffic(r)),le=l(async(r,y)=>{let o=r[0];if(o===void 0||o===""){p.current===y&&T(null);return}try{let g=await oe(o);if(p.current!==y)return;let d=new Map;for(let v of g.shards)d.has(v.shardKey)||d.set(v.shardKey,{requests:v.requests,shardKey:v.shardKey});T([...d.values()])}catch{p.current===y&&T(null)}},"Y"),de=l(async(r,y)=>{let o=await Promise.allSettled(r.map(async d=>[d,await i.query(Te,{table:d},A(y))])),g=[];for(let d of o)if(d.status==="fulfilled"){let[v,k]=d.value;g.push(...ie(v,k.indexes))}return g},"Z"),z=(0,c.useEffectEvent)(async r=>{p.current=r;let y=[];try{let o=await i.query(Se,{},A(r));if(p.current!==r)return;X(r),y=o.map(d=>d.name);let g=[];if(y.length>0)try{let d=await i.query(Ie,{tables:y},A(r));if(p.current!==r)return;for(let[v,k]of Object.entries(d.indexesByTable))g.push(...ie(v,k))}catch{if(g=await de(y,r),p.current!==r)return}m(g)}catch{p.current===r&&m(null)}await le(y,r)});(0,c.useEffect)(()=>{N(z(s))},[s]);let ce=(0,c.useEffectEvent)(()=>{w.refetch(),b.refetch(),$.refetch(),N(z(s))});(0,c.useEffect)(()=>{let r=l(()=>{document.visibilityState==="visible"&&ce()},"r");return document.addEventListener("visibilitychange",r),()=>{document.removeEventListener("visibilitychange",r)}},[]);let U=(0,c.useCallback)(r=>{N(a({search:{table:r},to:"/schema"}))},[a]),K=(0,c.useMemo)(()=>W(L,H),[H,L]),P=(0,c.useMemo)(()=>new Set(K.filter(r=>r.kind==="missing-index").flatMap(r=>r.tables??[])),[K]),R=(0,c.useMemo)(()=>we({declaredIndexes:f??[],functions:H,indexHits:J,shardTraffic:x,suppressHotScanTables:P}),[f,H,J,P,x]),ue=(0,c.useMemo)(()=>{let r=K.map(o=>{let g=o.kind==="missing-index"?o.tables??[]:[];return{action:g.length>0?g.map(d=>(0,S.jsx)(Ne,{onJump:U,table:d},d)):void 0,description:o.message===void 0?se(n,o):`${se(n,o)} \u2014 ${o.message}`,entity:o.fn,issueType:ke(n,o),key:`${o.kind}:${o.fn??""}`,level:o.severity}}),y=new Set(["unindexed_foreign_key","unindexed_relation_target"]);return[...(F??[]).map(o=>{let g=q(o);if(y.has(o.name)&&ge(o.metadata)){let{table:d,suggestedIndex:v}=o.metadata,k=`in-apply-index-${d}-${v.name}`;return{...g,action:(0,S.jsx)(ye,{fields:v.fields,indexName:v.name,table:d,testId:k})}}return g}),...R,...r]},[F,K,U,R,n]),fe=(0,S.jsx)(Y,{onChange:u,testId:"in-shard-input",value:h});return(0,S.jsx)(ee,{error:O,errorSource:O===null?void 0:w.errorSource,rows:ue,testId:"lunora-insights",toolbar:fe})},"Ue");export{ze as InsightsPanel};