@lunora/studio 1.0.0-alpha.324 → 1.0.0-alpha.325

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 (68) hide show
  1. package/dist/standalone/{chunk-WP2AS7SZ.js → chunk-3S4PZ7KQ.js} +1 -1
  2. package/dist/standalone/{chunk-ESSG4L6C.js → chunk-3T4K7XUT.js} +1 -1
  3. package/dist/standalone/{chunk-EXYBVVHU.js → chunk-4HBHTD3A.js} +1 -1
  4. package/dist/standalone/{chunk-NDGHCEE3.js → chunk-4UKHYUNB.js} +1 -1
  5. package/dist/standalone/{chunk-6YQ3RTCB.js → chunk-5BLNLZXF.js} +1 -1
  6. package/dist/standalone/{chunk-2QLSWJDL.js → chunk-5LBBEWDQ.js} +1 -1
  7. package/dist/standalone/{chunk-WFNUMMDF.js → chunk-5QYM3MYE.js} +2 -2
  8. package/dist/standalone/{chunk-SB4443ME.js → chunk-7PER26LF.js} +1 -1
  9. package/dist/standalone/{chunk-U4YBJ4OW.js → chunk-7Q6GOHAD.js} +1 -1
  10. package/dist/standalone/{chunk-NYHYH5Z5.js → chunk-7UQC3B6P.js} +1 -1
  11. package/dist/standalone/{chunk-3YH5TM3G.js → chunk-7VJPXCOU.js} +1 -1
  12. package/dist/standalone/{chunk-DL6TTBE6.js → chunk-A5U37V2S.js} +1 -1
  13. package/dist/standalone/{chunk-R4ILI46D.js → chunk-ASA7UJIH.js} +1 -1
  14. package/dist/standalone/chunk-BWKZ6FFW.js +9 -0
  15. package/dist/standalone/{chunk-QZRKA2E4.js → chunk-CDB3QQA6.js} +1 -1
  16. package/dist/standalone/{chunk-2JH7ZYVY.js → chunk-CGYVHQAD.js} +1 -1
  17. package/dist/standalone/{chunk-4Y5AFETG.js → chunk-CQ23LQGY.js} +1 -1
  18. package/dist/standalone/{chunk-4K6CXILB.js → chunk-CVBWPFHY.js} +1 -1
  19. package/dist/standalone/{chunk-MTGFTTXO.js → chunk-CY7FSXYX.js} +1 -1
  20. package/dist/standalone/{chunk-Z6THFOLU.js → chunk-CZKN2SRN.js} +1 -1
  21. package/dist/standalone/{chunk-N7LJO732.js → chunk-DYR23C3V.js} +2 -2
  22. package/dist/standalone/{chunk-HER5A45F.js → chunk-EOE2E73Q.js} +1 -1
  23. package/dist/standalone/{chunk-QSUWAGXH.js → chunk-FSXPV7YQ.js} +1 -1
  24. package/dist/standalone/{chunk-SQ2LCZBH.js → chunk-HXR3HVAR.js} +1 -1
  25. package/dist/standalone/{chunk-JNBWPXNV.js → chunk-HY7DUJVI.js} +1 -1
  26. package/dist/standalone/{chunk-SNJ5HRZO.js → chunk-IZ3OOKZL.js} +1 -1
  27. package/dist/standalone/{chunk-XTQR2C6N.js → chunk-JN2DUGT5.js} +1 -1
  28. package/dist/standalone/{chunk-JL6LEVHQ.js → chunk-JSGD6M6E.js} +1 -1
  29. package/dist/standalone/{chunk-MB5JGSN6.js → chunk-KHCM76LG.js} +1 -1
  30. package/dist/standalone/{chunk-7AF3FZCB.js → chunk-LJIMLABC.js} +1 -1
  31. package/dist/standalone/{chunk-ICU56FBP.js → chunk-LLN6LEHZ.js} +1 -1
  32. package/dist/standalone/{chunk-NW6FNJ4L.js → chunk-LU6UOZWK.js} +1 -1
  33. package/dist/standalone/{chunk-3OHVDOV5.js → chunk-MK4H5D3L.js} +1 -1
  34. package/dist/standalone/{chunk-POKVFO6Q.js → chunk-NTZX6RJQ.js} +1 -1
  35. package/dist/standalone/{chunk-OM3B3V47.js → chunk-P2OIRN2O.js} +1 -1
  36. package/dist/standalone/{chunk-5WOMOENH.js → chunk-PLPA2F6L.js} +1 -1
  37. package/dist/standalone/{chunk-MJ3SSK6L.js → chunk-QLKZIBWQ.js} +1 -1
  38. package/dist/standalone/{chunk-OK35SLOW.js → chunk-QPZG3NV6.js} +1 -1
  39. package/dist/standalone/{chunk-DSIY2CMT.js → chunk-QUXXMJPZ.js} +1 -1
  40. package/dist/standalone/{chunk-UDMY3BMT.js → chunk-QZRACAES.js} +1 -1
  41. package/dist/standalone/{chunk-ZJQI4C3A.js → chunk-R2GYDPPC.js} +1 -1
  42. package/dist/standalone/{chunk-7RAYXTNN.js → chunk-R73OPTTE.js} +1 -1
  43. package/dist/standalone/{chunk-KU3IXE36.js → chunk-RI6LCPJQ.js} +1 -1
  44. package/dist/standalone/{chunk-RBAD4SMG.js → chunk-SMCCFWX3.js} +1 -1
  45. package/dist/standalone/{chunk-RDJCY5PQ.js → chunk-SR2FQOVJ.js} +1 -1
  46. package/dist/standalone/{chunk-22TUDRBR.js → chunk-SUTA66KR.js} +1 -1
  47. package/dist/standalone/{chunk-6MFVEI7C.js → chunk-SYPUVLW6.js} +1 -1
  48. package/dist/standalone/{chunk-F3UUFO2C.js → chunk-U6IDPJGC.js} +1 -1
  49. package/dist/standalone/{chunk-HM57YJY5.js → chunk-UMHLRQOR.js} +1 -1
  50. package/dist/standalone/{chunk-VFL7VJWF.js → chunk-UPO3FC7D.js} +1 -1
  51. package/dist/standalone/{chunk-HOGQLP3J.js → chunk-VBUNOAPR.js} +1 -1
  52. package/dist/standalone/{chunk-VKURTWDH.js → chunk-VNHJSWBS.js} +1 -1
  53. package/dist/standalone/{chunk-KLTGKTSL.js → chunk-VRG5BACA.js} +1 -1
  54. package/dist/standalone/{chunk-TIQ7OBZJ.js → chunk-WHDFMKYB.js} +1 -1
  55. package/dist/standalone/{chunk-MRJB4FPI.js → chunk-WHJDJ4OD.js} +1 -1
  56. package/dist/standalone/{chunk-MGEACGEE.js → chunk-WTNHJS56.js} +1 -1
  57. package/dist/standalone/{chunk-CUJGTNYR.js → chunk-WY5WGFM3.js} +1 -1
  58. package/dist/standalone/{chunk-WAX5WY6F.js → chunk-X4JXFRIZ.js} +1 -1
  59. package/dist/standalone/{chunk-WJHMDTV2.js → chunk-XEKXUZWX.js} +1 -1
  60. package/dist/standalone/{chunk-OX6JWCPF.js → chunk-XXMXVSAN.js} +1 -1
  61. package/dist/standalone/{chunk-W3LXMSGC.js → chunk-Y2DTPEO4.js} +1 -1
  62. package/dist/standalone/{chunk-2H5IXFGR.js → chunk-Y2O72Z46.js} +1 -1
  63. package/dist/standalone/{chunk-OH7DVC7S.js → chunk-ZCQJFVF2.js} +1 -1
  64. package/dist/standalone/{chunk-R6PJYMJT.js → chunk-ZNVNSNDU.js} +1 -1
  65. package/dist/standalone/{chunk-EEDIMNRC.js → chunk-ZRB4HPDU.js} +1 -1
  66. package/dist/standalone/studio.js +1 -1
  67. package/package.json +5 -5
  68. package/dist/standalone/chunk-BOYS4DOC.js +0 -9
@@ -1 +1 @@
1
- import{g as j,h as v,i as D,l as g}from"./chunk-BOYS4DOC.js";import{f as S,g as w,h as P,p as q}from"./chunk-HJHSQPHW.js";import{a as i,d as A,e as x,f as M}from"./chunk-I26MS5PJ.js";var E=A(M(),1);var p=A(x(),1);var I=300,l=i(t=>typeof t=="string"?t===""?void 0:t:typeof t=="number"||typeof t=="boolean"?String(t):void 0,"a"),u=i(t=>t.filter(r=>r!==void 0).join(" "),"c"),T=i(t=>{let r=Array.isArray(t.filters)?t.filters.length:0,e=typeof t.search=="string"&&t.search!=="";return r===0&&!e?"no predicate":u([r===0?void 0:`${String(r)} filters`,e?"search":void 0])},"q"),N={clearTable:i(t=>u([l(t.table),"whole table"]),"clearTable"),deleteRows:i(t=>u([l(t.table),T(t)]),"deleteRows"),facetColumn:i(t=>u([l(t.table),l(t.column)]),"facetColumn"),importShard:i(t=>{if(!Array.isArray(t.rows))return"";let r=[...new Set(t.rows.filter(e=>typeof e=="object"&&e!==null).map(e=>e.table).filter(e=>typeof e=="string"))].toSorted((e,s)=>e.localeCompare(s));return u([`${String(t.rows.length)} rows`,r.length===0?void 0:`into ${r.join(", ")}`])},"importShard"),lintSql:i(()=>"sql","lintSql"),patchRows:i(t=>u([l(t.table),typeof t.doc=="object"&&t.doc!==null?`set ${Object.keys(t.doc).join(", ")}`:void 0,T(t)]),"patchRows"),pitrRestore:i(t=>u([l(t.time)===void 0?void 0:`to ${String(t.time)}`,typeof t.bookmark=="string"&&t.bookmark!==""?"from bookmark":void 0,t.restart===!0?"restart now":void 0]),"pitrRestore"),readTablePage:i(t=>u([l(t.table),Array.isArray(t.filters)&&t.filters.length>0?`${String(t.filters.length)} filters`:void 0,typeof t.search=="string"&&t.search!==""?"search":void 0,typeof t.limit=="number"?`limit ${String(t.limit)}`:void 0]),"readTablePage"),runMigration:i(t=>u([l(t.id),l(t.direction),t.dryRun===!0?"dry-run":void 0]),"runMigration"),runSql:i(t=>typeof t.sql=="string"?`${String(t.sql.length)} chars`:"","runSql"),schemaVersion:i(t=>typeof t.hash=="string"?t.hash.slice(0,8):"","schemaVersion"),writeRow:i(t=>u([l(t.table),"1 row"]),"writeRow")},$="__lunora_admin__:",F=i((t,r)=>{let e=t.startsWith($)?t.slice($.length):t,s=N[e];if(s!==void 0)return s(r);let n=Object.keys(r);return n.length===0?"":n.join(", ")},"M"),V=i(t=>{if(Array.isArray(t))return t.length;if(!(typeof t!="object"||t===null)){for(let r of Object.values(t))if(Array.isArray(r))return r.length}},"K"),k=class{static{i(this,"x")}entries=[];listeners=new Set;nextSeq=1;getSnapshot=i(()=>this.entries,"getSnapshot");subscribe=i(r=>(this.listeners.add(r),()=>{this.listeners.delete(r)}),"subscribe");start(r,e,s){return this.append(r,e,s,"call","pending")}startSubscription(r,e,s){return this.append(r,e,s,"subscription","live")}recordPush(r){if(this.listeners.size===0){let e=this.entries.find(s=>s.seq===r);e!==void 0&&(e.pushes=(e.pushes??0)+1);return}this.patch(r,e=>({...e,pushes:(e.pushes??0)+1}))}failSubscription(r,e){this.patch(r,s=>({...s,error:e,status:"error"}))}endSubscription(r){this.patch(r,e=>e.status==="error"?e:{...e,durationMs:Date.now()-e.startedAt,status:"closed"})}lastErrorSeq(){return this.entries.findLast(r=>r.status==="error")?.seq}settle(r,e){this.patch(r,s=>({...s,durationMs:Date.now()-s.startedAt,...e.error===void 0?{resultCount:V(e.result),status:"ok"}:{error:e.error,status:"error"}}))}clear(){this.entries=[],this.emit()}append(r,e,s,n,a){let d=this.nextSeq;this.nextSeq+=1;let c={functionPath:r,kind:n,seq:d,shardKey:s,startedAt:Date.now(),status:a,summary:F(r,e),...n==="subscription"?{pushes:0}:{}},o=[...this.entries,c];return this.entries=o.length>I?o.slice(o.length-I):o,this.emit(),d}patch(r,e){let s=this.entries.findIndex(n=>n.seq===r);s!==-1&&(this.entries=this.entries.with(s,e(this.entries[s])),this.emit())}emit(){for(let r of this.listeners)r()}},f=new k,_=i((t,r,e)=>["lunora-admin",t,r,e.trim()],"j"),O=i((t,r)=>[...t,r],"E");function W(t,r,e={}){let s=g(),{enabled:n=!0,keepPreviousData:a=!1,staleTime:d=0}=e,c=O(t,s.clientIdentifier()),o=D({enabled:n,queryFn:r,placeholderData:a?j:void 0,queryKey:c,staleTime:d});return{data:o.data,error:o.error?P(o.error):o.error,errorSource:o.error??void 0,isLoading:o.isLoading,liveError:void 0,refetch:i(()=>{q(o.refetch())},"refetch")}}i(W,"F");function Y(t,r,e={}){let s=g(),n=v(),{enabled:a=!0,keepPreviousData:d=!1,live:c=!1,shardKey:o="",staleTime:R}=e,m=_(t,r,o),C=W(m,()=>s.query(S(t),r,w(o)),{enabled:a,keepPreviousData:d,staleTime:R??(c?Number.POSITIVE_INFINITY:0)}),[K,b]=(0,p.useState)(void 0),L=JSON.stringify(m);return(0,p.useEffect)(()=>{if(!a||!c)return;b(void 0);let y=f.startSubscription(t,r,o),Q=s.subscribe(S(t),r,h=>{f.recordPush(y),b(void 0),n.setQueryData(O(m,s.clientIdentifier()),h)},{...w(o),onError:i(h=>{f.failSubscription(y,h.message),b(h.message)},"onError")});return()=>{f.endSubscription(y),Q()}},[s,L,a,c]),{...C,liveError:a&&c?K:void 0}}i(Y,"U");var B=i(()=>{let t=(0,E.c)(2),r=v(),e;return t[0]!==r?(e=i((s,n,a)=>{let d=n===void 0?["lunora-admin",s]:_(s,n,a??"");q(r.invalidateQueries({queryKey:d}))},"r"),t[0]=r,t[1]=e):e=t[1],e},"W");export{f as a,W as b,Y as c,B as d};
1
+ import{g as j,h as v,i as D,l as g}from"./chunk-BWKZ6FFW.js";import{f as S,g as w,h as P,p as q}from"./chunk-HJHSQPHW.js";import{a as i,d as A,e as x,f as M}from"./chunk-I26MS5PJ.js";var E=A(M(),1);var p=A(x(),1);var I=300,l=i(t=>typeof t=="string"?t===""?void 0:t:typeof t=="number"||typeof t=="boolean"?String(t):void 0,"a"),u=i(t=>t.filter(r=>r!==void 0).join(" "),"c"),T=i(t=>{let r=Array.isArray(t.filters)?t.filters.length:0,e=typeof t.search=="string"&&t.search!=="";return r===0&&!e?"no predicate":u([r===0?void 0:`${String(r)} filters`,e?"search":void 0])},"q"),N={clearTable:i(t=>u([l(t.table),"whole table"]),"clearTable"),deleteRows:i(t=>u([l(t.table),T(t)]),"deleteRows"),facetColumn:i(t=>u([l(t.table),l(t.column)]),"facetColumn"),importShard:i(t=>{if(!Array.isArray(t.rows))return"";let r=[...new Set(t.rows.filter(e=>typeof e=="object"&&e!==null).map(e=>e.table).filter(e=>typeof e=="string"))].toSorted((e,s)=>e.localeCompare(s));return u([`${String(t.rows.length)} rows`,r.length===0?void 0:`into ${r.join(", ")}`])},"importShard"),lintSql:i(()=>"sql","lintSql"),patchRows:i(t=>u([l(t.table),typeof t.doc=="object"&&t.doc!==null?`set ${Object.keys(t.doc).join(", ")}`:void 0,T(t)]),"patchRows"),pitrRestore:i(t=>u([l(t.time)===void 0?void 0:`to ${String(t.time)}`,typeof t.bookmark=="string"&&t.bookmark!==""?"from bookmark":void 0,t.restart===!0?"restart now":void 0]),"pitrRestore"),readTablePage:i(t=>u([l(t.table),Array.isArray(t.filters)&&t.filters.length>0?`${String(t.filters.length)} filters`:void 0,typeof t.search=="string"&&t.search!==""?"search":void 0,typeof t.limit=="number"?`limit ${String(t.limit)}`:void 0]),"readTablePage"),runMigration:i(t=>u([l(t.id),l(t.direction),t.dryRun===!0?"dry-run":void 0]),"runMigration"),runSql:i(t=>typeof t.sql=="string"?`${String(t.sql.length)} chars`:"","runSql"),schemaVersion:i(t=>typeof t.hash=="string"?t.hash.slice(0,8):"","schemaVersion"),writeRow:i(t=>u([l(t.table),"1 row"]),"writeRow")},$="__lunora_admin__:",F=i((t,r)=>{let e=t.startsWith($)?t.slice($.length):t,s=N[e];if(s!==void 0)return s(r);let n=Object.keys(r);return n.length===0?"":n.join(", ")},"M"),V=i(t=>{if(Array.isArray(t))return t.length;if(!(typeof t!="object"||t===null)){for(let r of Object.values(t))if(Array.isArray(r))return r.length}},"K"),k=class{static{i(this,"x")}entries=[];listeners=new Set;nextSeq=1;getSnapshot=i(()=>this.entries,"getSnapshot");subscribe=i(r=>(this.listeners.add(r),()=>{this.listeners.delete(r)}),"subscribe");start(r,e,s){return this.append(r,e,s,"call","pending")}startSubscription(r,e,s){return this.append(r,e,s,"subscription","live")}recordPush(r){if(this.listeners.size===0){let e=this.entries.find(s=>s.seq===r);e!==void 0&&(e.pushes=(e.pushes??0)+1);return}this.patch(r,e=>({...e,pushes:(e.pushes??0)+1}))}failSubscription(r,e){this.patch(r,s=>({...s,error:e,status:"error"}))}endSubscription(r){this.patch(r,e=>e.status==="error"?e:{...e,durationMs:Date.now()-e.startedAt,status:"closed"})}lastErrorSeq(){return this.entries.findLast(r=>r.status==="error")?.seq}settle(r,e){this.patch(r,s=>({...s,durationMs:Date.now()-s.startedAt,...e.error===void 0?{resultCount:V(e.result),status:"ok"}:{error:e.error,status:"error"}}))}clear(){this.entries=[],this.emit()}append(r,e,s,n,a){let d=this.nextSeq;this.nextSeq+=1;let c={functionPath:r,kind:n,seq:d,shardKey:s,startedAt:Date.now(),status:a,summary:F(r,e),...n==="subscription"?{pushes:0}:{}},o=[...this.entries,c];return this.entries=o.length>I?o.slice(o.length-I):o,this.emit(),d}patch(r,e){let s=this.entries.findIndex(n=>n.seq===r);s!==-1&&(this.entries=this.entries.with(s,e(this.entries[s])),this.emit())}emit(){for(let r of this.listeners)r()}},f=new k,_=i((t,r,e)=>["lunora-admin",t,r,e.trim()],"j"),O=i((t,r)=>[...t,r],"E");function W(t,r,e={}){let s=g(),{enabled:n=!0,keepPreviousData:a=!1,staleTime:d=0}=e,c=O(t,s.clientIdentifier()),o=D({enabled:n,queryFn:r,placeholderData:a?j:void 0,queryKey:c,staleTime:d});return{data:o.data,error:o.error?P(o.error):o.error,errorSource:o.error??void 0,isLoading:o.isLoading,liveError:void 0,refetch:i(()=>{q(o.refetch())},"refetch")}}i(W,"F");function Y(t,r,e={}){let s=g(),n=v(),{enabled:a=!0,keepPreviousData:d=!1,live:c=!1,shardKey:o="",staleTime:R}=e,m=_(t,r,o),C=W(m,()=>s.query(S(t),r,w(o)),{enabled:a,keepPreviousData:d,staleTime:R??(c?Number.POSITIVE_INFINITY:0)}),[K,b]=(0,p.useState)(void 0),L=JSON.stringify(m);return(0,p.useEffect)(()=>{if(!a||!c)return;b(void 0);let y=f.startSubscription(t,r,o),Q=s.subscribe(S(t),r,h=>{f.recordPush(y),b(void 0),n.setQueryData(O(m,s.clientIdentifier()),h)},{...w(o),onError:i(h=>{f.failSubscription(y,h.message),b(h.message)},"onError")});return()=>{f.endSubscription(y),Q()}},[s,L,a,c]),{...C,liveError:a&&c?K:void 0}}i(Y,"U");var B=i(()=>{let t=(0,E.c)(2),r=v(),e;return t[0]!==r?(e=i((s,n,a)=>{let d=n===void 0?["lunora-admin",s]:_(s,n,a??"");q(r.invalidateQueries({queryKey:d}))},"r"),t[0]=r,t[1]=e):e=t[1],e},"W");export{f as a,W as b,Y as c,B as d};
@@ -1 +1 @@
1
- import{d as E,e as _}from"./chunk-CVXNHIQW.js";import{a as $}from"./chunk-253UHWDX.js";import{a as de}from"./chunk-HOGQLP3J.js";import{a as ce}from"./chunk-6QTAHSDD.js";import"./chunk-VESGIGMQ.js";import"./chunk-TIQ7OBZJ.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-3YH5TM3G.js";import"./chunk-NCPW7WHO.js";import"./chunk-WP2AS7SZ.js";import"./chunk-55UGUCQ6.js";import{a as J}from"./chunk-4ZEL6BYL.js";import{c as H}from"./chunk-DSIY2CMT.js";import"./chunk-BOYS4DOC.js";import"./chunk-QAQDMS6R.js";import"./chunk-N7LJO732.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-VBUNOAPR.js";import{a as ce}from"./chunk-6QTAHSDD.js";import"./chunk-VESGIGMQ.js";import"./chunk-WHDFMKYB.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-7VJPXCOU.js";import"./chunk-NCPW7WHO.js";import"./chunk-3S4PZ7KQ.js";import"./chunk-55UGUCQ6.js";import{a as J}from"./chunk-4ZEL6BYL.js";import{c as H}from"./chunk-QUXXMJPZ.js";import"./chunk-BWKZ6FFW.js";import"./chunk-QAQDMS6R.js";import"./chunk-DYR23C3V.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 Ze}from"./chunk-7RKB5KS7.js";import{a as qe}from"./chunk-4K6CXILB.js";import{a as Ke}from"./chunk-OSGXNEFA.js";import{a as He}from"./chunk-QJLHH3ET.js";import{a as O}from"./chunk-37WYCOQ2.js";import{a as Je}from"./chunk-4WD4XGC3.js";import"./chunk-Z22BDS6N.js";import{a as We}from"./chunk-JQXA2OYK.js";import{a as Xe}from"./chunk-IWZ7GVQO.js";import"./chunk-NGVP66OH.js";import"./chunk-GHQ2VDI2.js";import{i as T}from"./chunk-E4PXACVL.js";import"./chunk-MVWZMWPD.js";import"./chunk-7Y3SY37W.js";import{a as _}from"./chunk-7G4Z6Q7X.js";import"./chunk-3YXASVTP.js";import"./chunk-AUAECCXB.js";import{b as D}from"./chunk-Q6ED4KUL.js";import"./chunk-BOMPSVRC.js";import{b as De}from"./chunk-DSIY2CMT.js";import{l as J}from"./chunk-BOYS4DOC.js";import"./chunk-QAQDMS6R.js";import"./chunk-N7LJO732.js";import{a as Ve}from"./chunk-RWVIV3U7.js";import{a as ze,b as _e,c as Pe,d as q,e as U,f as z}from"./chunk-HCTJKP5J.js";import{a as K,e as X}from"./chunk-2IKDEUCX.js";import{d as Q,h as Ee,o as Ue,p as Z,r as Qe,t as te}from"./chunk-HJHSQPHW.js";import{a as s,d as Me,e as at,f as lt,g as nt}from"./chunk-I26MS5PJ.js";var C=Me(at(),1);var W=Me(lt(),1);var t=Me(nt(),1);var it=s(()=>{let h=(0,W.c)(3),{config:e,ready:n}=qe(),l;return h[0]!==e.capabilities||h[1]!==n?(l={capabilities:e.capabilities,ready:n},h[0]=e.capabilities,h[1]=n,h[2]=l):l=h[2],l},"nt"),st=s((h,e)=>typeof h.acceptedAt=="number"?"spent":typeof h.expiresAt=="number"&&h.expiresAt<=e?"expired":"pending","lt"),et=500,rt=s((h,e)=>{if(!URL.canParse(h.trim()))return null;let n=new URL(h.trim());return n.searchParams.set("email",e.email),n.searchParams.set("invite",e.token),n.toString()},"at"),dt=s(h=>{let e=(0,W.c)(34),{issued:n,onSignUpPageChange:l,signUpPage:o}=h,a=Q(),[p,i]=(0,C.useState)(null),u;e[0]!==n||e[1]!==o?(u=rt(o,n),e[0]=n,e[1]=o,e[2]=u):u=e[2];let c=u,y;e[3]!==c?(y=s(()=>{let $="navigator"in globalThis?globalThis.navigator.clipboard:void 0;c===null||$===void 0||Z($.writeText(c).then(()=>(i(c),!0)))},"y"),e[3]=c,e[4]=y):y=e[4];let w=y,g;e[5]!==a?(g=a("Send this link to the invitee. It is shown once and cannot be recovered."),e[5]=a,e[6]=g):g=e[6];let I;e[7]!==g?(I=(0,t.jsx)("p",{className:"text-sm",children:g}),e[7]=g,e[8]=I):I=e[8];let k=c===null,v;e[9]!==a?(v=a("Your app's sign-up page"),e[9]=a,e[10]=v):v=e[10];let d;e[11]!==l?(d=s($=>{l($.target.value)},"r"),e[11]=l,e[12]=d):d=e[12];let m;e[13]!==o||e[14]!==k||e[15]!==v||e[16]!==d?(m=(0,t.jsx)(T,{"aria-invalid":k,"aria-label":v,"data-testid":"sign-up-invitation-page",onChange:d,value:o}),e[13]=o,e[14]=k,e[15]=v,e[16]=d,e[17]=m):m=e[17];let b=c??"",x;e[18]!==b?(x=(0,t.jsx)(T,{"data-testid":"sign-up-invitation-link",readOnly:!0,value:b}),e[18]=b,e[19]=x):x=e[19];let N;e[20]!==p||e[21]!==c||e[22]!==a?(N=a(p!==null&&p===c?"Copied":"Copy"),e[20]=p,e[21]=c,e[22]=a,e[23]=N):N=e[23];let f;e[24]!==w||e[25]!==N?(f=(0,t.jsx)(_,{"data-testid":"sign-up-invitation-copy",onClick:w,type:"button",children:N}),e[24]=w,e[25]=N,e[26]=f):f=e[26];let r;e[27]!==x||e[28]!==f?(r=(0,t.jsxs)("div",{className:"flex gap-2",children:[x,f]}),e[27]=x,e[28]=f,e[29]=r):r=e[29];let S;return e[30]!==r||e[31]!==I||e[32]!==m?(S=(0,t.jsx)(K,{children:(0,t.jsxs)(X,{className:"flex flex-col gap-2 p-4",children:[I,m,r]})}),e[30]=r,e[31]=I,e[32]=m,e[33]=S):S=e[33],S},"it"),ot=s(()=>{let h=J(),e=Q(),[n,l]=(0,C.useState)(""),[o,a]=(0,C.useState)(null),[p,i]=(0,C.useState)(null),[u,c]=(0,C.useState)(()=>`${Qe(h.url)}/sign-up`),y=De(["lunora-auth-sign-up-invitations",et],()=>h.listAuthSignUpInvitations({limit:et})),w=y.data?.rows??null,g=y.data?.total??0,I=s(()=>{let v=n.trim();v!==""&&(a(null),Z((async()=>{try{let d=await h.createAuthSignUpInvitation({email:v}),m=typeof d.token=="string"?d.token:void 0;i(m===void 0?null:{email:v,token:m}),l(""),y.refetch()}catch(d){a(d instanceof Error?d.message:String(d))}})()))},"w"),k=s(v=>{a(null),Z((async()=>{try{await h.revokeAuthSignUpInvitation({email:v}),y.refetch()}catch(d){a(d instanceof Error?d.message:String(d))}})())},"k");return(0,t.jsxs)("div",{className:"flex flex-col gap-4","data-testid":"sign-up-invitations",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("h2",{className:"text-base font-medium",children:e("Sign-up invitations")}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:e("Only invited addresses can create an account. Nothing is emailed \u2014 send the invitee the one-time link yourself.")})]}),(0,t.jsxs)("div",{className:"flex gap-2",children:[(0,t.jsx)(T,{"aria-label":e("Email address to invite"),"data-testid":"sign-up-invitation-email",onChange:s(v=>{l(v.target.value)},"onChange"),placeholder:e("ada@example.com"),type:"email",value:n}),(0,t.jsx)(_,{"data-testid":"sign-up-invitation-submit",onClick:I,type:"button",children:e("Invite")})]}),p!==null&&(0,t.jsx)(dt,{issued:p,onSignUpPageChange:c,signUpPage:u},p.token),(o??y.error)!==null&&(0,t.jsx)("p",{className:"text-sm text-destructive","data-testid":"sign-up-invitations-error",role:"alert",children:o??y.error}),w!==null&&w.length===0&&(0,t.jsx)(Ve,{testId:"sign-up-invitations-empty",title:e("Nobody has been invited yet.")}),w!==null&&g>w.length&&(0,t.jsx)("p",{className:"text-sm text-muted-foreground","data-testid":"sign-up-invitations-truncated",children:e("Showing the most recent invitations. Query the signUpInvitation table directly to see the rest.")}),w!==null&&w.length>0&&(0,t.jsx)(K,{children:(0,t.jsx)(X,{className:"p-0",children:(0,t.jsxs)(ze,{children:[(0,t.jsx)(_e,{children:(0,t.jsxs)(q,{children:[(0,t.jsx)(U,{children:e("Email")}),(0,t.jsx)(U,{children:e("Status")}),(0,t.jsx)(U,{children:e("Expires")}),(0,t.jsx)(U,{children:e("Invited by")}),(0,t.jsx)(U,{})]})}),(0,t.jsx)(Pe,{children:w.map(v=>{let d=st(v,Date.now()),m=v.email??"";return(0,t.jsxs)(q,{"data-testid":`sign-up-invitation-${m}`,children:[(0,t.jsx)(z,{children:m}),(0,t.jsxs)(z,{"data-testid":`sign-up-invitation-status-${m}`,children:[d==="spent"&&e("Accepted"),d==="expired"&&e("Expired"),d==="pending"&&e("Pending")]}),(0,t.jsx)(z,{children:typeof v.expiresAt=="number"?te(v.expiresAt):"\u2014"}),(0,t.jsx)(z,{children:v.invitedBy??"\u2014"}),(0,t.jsx)(z,{className:"text-right",children:(0,t.jsx)(_,{onClick:s(()=>{k(m)},"onClick"),type:"button",variant:"ghost",children:e("Revoke")})})]},v.id)})})]})})})]})},"rt"),ct={boolean:"checkbox",date:"datetime-local",number:"number",string:"text"},ut=s((h,e)=>h.type==="boolean"?!0:typeof e!="string"||e.trim()===""?!1:h.type!=="number"||!Number.isNaN(Number(e.trim())),"dt"),mt=s((h,e)=>{if(h.type==="boolean")return e===!0?{value:!0}:h.required?{value:!1}:void 0;let n=typeof e=="string"?e.trim():"";if(n!==""){if(h.type==="number"){let l=Number(n);return Number.isNaN(l)?void 0:{value:l}}return{value:n}}},"ct"),ht=s(h=>{let e=(0,W.c)(105),{onClose:n,onCreated:l}=h,o=J(),a=Q(),{config:p}=qe(),{busy:i,error:u,run:c}=Ke(),[y,w]=(0,C.useState)(""),[g,I]=(0,C.useState)(""),[k,v]=(0,C.useState)(""),[d,m]=(0,C.useState)(""),b;e[0]===Symbol.for("react.memo_cache_sentinel")?(b={},e[0]=b):b=e[0];let[x,N]=(0,C.useState)(b),f;e[1]===Symbol.for("react.memo_cache_sentinel")?(f=s(A=>{w(A.target.value)},"p"),e[1]=f):f=e[1];let r=f,S;e[2]===Symbol.for("react.memo_cache_sentinel")?(S=s(A=>{I(A.target.value)},"I"),e[2]=S):S=e[2];let $=S,j;e[3]===Symbol.for("react.memo_cache_sentinel")?(j=s(A=>{v(A.target.value)},"z"),e[3]=j):j=e[3];let H=j,M;e[4]===Symbol.for("react.memo_cache_sentinel")?(M=s(A=>{m(A.target.value)},"M"),e[4]=M):M=e[4];let Y=M,B;e[5]===Symbol.for("react.memo_cache_sentinel")?(B=s((A,R)=>{N(ee=>({...ee,[A]:R}))},"L"),e[5]=B):B=e[5];let V=B,G;e[6]!==x?(G=s(A=>x[A.name]??(A.type==="boolean"?!1:""),"Y"),e[6]=x,e[7]=G):G=e[7];let P=G,L;if(e[8]!==p.userFields||e[9]!==P){let A;e[11]!==P?(A=s(R=>!R.required||ut(R,P(R)),"A"),e[11]=P,e[12]=A):A=e[12],L=p.userFields.every(A),e[8]=p.userFields,e[9]=P,e[10]=L}else L=e[10];let F=L,E;e[13]!==i||e[14]!==y||e[15]!==g||e[16]!==F?(E=!i&&y.trim()!==""&&g.trim()!==""&&F,e[13]=i,e[14]=y,e[15]=g,e[16]=F,e[17]=E):E=e[17];let $e=E,ae;e[18]!==p.userFields||e[19]!==P?(ae=s(()=>{let A={};for(let R of p.userFields){let ee=mt(R,P(R));ee!==void 0&&(A[R.name]=ee.value)}return Object.keys(A).length===0?void 0:A},"te"),e[18]=p.userFields,e[19]=P,e[20]=ae):ae=e[20];let je=ae,Re;e[21]!==je||e[22]!==o||e[23]!==y||e[24]!==g||e[25]!==n||e[26]!==l||e[27]!==k||e[28]!==d||e[29]!==c?(Re=s(()=>{c(async()=>{await o.createAuthUser({data:je(),email:y.trim(),name:g.trim(),password:k===""?void 0:k,role:d.trim()===""?void 0:d.trim()}),l(),n()})},"De"),e[21]=je,e[22]=o,e[23]=y,e[24]=g,e[25]=n,e[26]=l,e[27]=k,e[28]=d,e[29]=c,e[30]=Re):Re=e[30];let Be=Re,le;e[31]!==a?(le=a("Create user"),e[31]=a,e[32]=le):le=e[32];let ne;e[33]!==a?(ne=a("Create user"),e[33]=a,e[34]=ne):ne=e[34];let ie;e[35]!==ne?(ie=(0,t.jsx)("h2",{className:"text-sm font-semibold text-foreground",children:ne}),e[35]=ne,e[36]=ie):ie=e[36];let se;e[37]!==a?(se=a("email"),e[37]=a,e[38]=se):se=e[38];let re;e[39]!==se?(re=(0,t.jsx)(O,{htmlFor:"uc-email",children:se}),e[39]=se,e[40]=re):re=e[40];let de;e[41]!==y?(de=(0,t.jsx)(T,{"data-testid":"uc-email",id:"uc-email",onChange:r,type:"email",value:y}),e[41]=y,e[42]=de):de=e[42];let oe;e[43]!==re||e[44]!==de?(oe=(0,t.jsxs)("div",{className:"flex flex-col gap-1",children:[re,de]}),e[43]=re,e[44]=de,e[45]=oe):oe=e[45];let ce;e[46]!==a?(ce=a("name"),e[46]=a,e[47]=ce):ce=e[47];let ue;e[48]!==ce?(ue=(0,t.jsx)(O,{htmlFor:"uc-name",children:ce}),e[48]=ce,e[49]=ue):ue=e[49];let me;e[50]!==g?(me=(0,t.jsx)(T,{"data-testid":"uc-name",id:"uc-name",onChange:$,value:g}),e[50]=g,e[51]=me):me=e[51];let he;e[52]!==ue||e[53]!==me?(he=(0,t.jsxs)("div",{className:"flex flex-col gap-1",children:[ue,me]}),e[52]=ue,e[53]=me,e[54]=he):he=e[54];let pe;e[55]!==a?(pe=a("Password (optional)"),e[55]=a,e[56]=pe):pe=e[56];let fe;e[57]!==pe?(fe=(0,t.jsx)(O,{htmlFor:"uc-password",children:pe}),e[57]=pe,e[58]=fe):fe=e[58];let ve;e[59]!==k?(ve=(0,t.jsx)(T,{"data-testid":"uc-password",id:"uc-password",onChange:H,type:"password",value:k}),e[59]=k,e[60]=ve):ve=e[60];let ge;e[61]!==fe||e[62]!==ve?(ge=(0,t.jsxs)("div",{className:"flex flex-col gap-1",children:[fe,ve]}),e[61]=fe,e[62]=ve,e[63]=ge):ge=e[63];let be;e[64]!==a?(be=a("Role (optional)"),e[64]=a,e[65]=be):be=e[65];let xe;e[66]!==be?(xe=(0,t.jsx)(O,{htmlFor:"uc-role",children:be}),e[66]=be,e[67]=xe):xe=e[67];let ye;e[68]!==d?(ye=(0,t.jsx)(T,{"data-testid":"uc-role",id:"uc-role",onChange:Y,value:d}),e[68]=d,e[69]=ye):ye=e[69];let Ne;e[70]!==xe||e[71]!==ye?(Ne=(0,t.jsxs)("div",{className:"flex flex-col gap-1",children:[xe,ye]}),e[70]=xe,e[71]=ye,e[72]=Ne):Ne=e[72];let ke;e[73]!==p.userFields||e[74]!==P||e[75]!==a?(ke=p.userFields.length>0&&(0,t.jsxs)("div",{className:"flex flex-col gap-3 border-t border-border pt-3","data-testid":"uc-plugin-fields",children:[(0,t.jsx)("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:a("Plugin fields")}),p.userFields.map(A=>{let R=`uc-field-${A.name}`,ee=A.required?"":` (${a("optional")})`;if(A.type==="boolean"){let Oe=P(A)===!0;return(0,t.jsxs)("label",{className:"flex items-center gap-2",htmlFor:R,children:[(0,t.jsx)(Ze,{checked:Oe,"data-testid":R,id:R,onCheckedChange:s(tt=>{V(A.name,tt)},"onCheckedChange")}),(0,t.jsxs)("span",{className:"text-sm",children:[A.name,ee]})]},A.name)}let Ge=P(A);return(0,t.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,t.jsxs)(O,{htmlFor:R,children:[A.name,ee]}),(0,t.jsx)(T,{"data-testid":R,id:R,onChange:s(Oe=>{V(A.name,Oe.target.value)},"onChange"),type:ct[A.type],value:typeof Ge=="string"?Ge:""})]},A.name)})]}),e[73]=p.userFields,e[74]=P,e[75]=a,e[76]=ke):ke=e[76];let we;e[77]!==u?(we=u!==null&&(0,t.jsx)("p",{className:"text-sm text-destructive","data-testid":"uc-error",role:"alert",children:u}),e[77]=u,e[78]=we):we=e[78];let Ce;e[79]!==a?(Ce=a("Cancel"),e[79]=a,e[80]=Ce):Ce=e[80];let Ie;e[81]!==n||e[82]!==Ce?(Ie=(0,t.jsx)(_,{"data-testid":"uc-cancel",onClick:n,size:"sm",type:"button",variant:"outline",children:Ce}),e[81]=n,e[82]=Ce,e[83]=Ie):Ie=e[83];let Le=!$e,Ae;e[84]!==i||e[85]!==a?(Ae=a(i?"Creating\u2026":"Create"),e[84]=i,e[85]=a,e[86]=Ae):Ae=e[86];let Se;e[87]!==Be||e[88]!==Le||e[89]!==Ae?(Se=(0,t.jsx)(_,{"data-testid":"uc-submit",disabled:Le,onClick:Be,size:"sm",type:"button",children:Ae}),e[87]=Be,e[88]=Le,e[89]=Ae,e[90]=Se):Se=e[90];let Fe;e[91]!==Ie||e[92]!==Se?(Fe=(0,t.jsxs)("div",{className:"flex justify-end gap-2 pt-1",children:[Ie,Se]}),e[91]=Ie,e[92]=Se,e[93]=Fe):Fe=e[93];let Te;return e[94]!==n||e[95]!==le||e[96]!==ie||e[97]!==oe||e[98]!==he||e[99]!==ge||e[100]!==Ne||e[101]!==ke||e[102]!==we||e[103]!==Fe?(Te=(0,t.jsxs)(He,{label:le,onClose:n,panelTestId:"uc-dialog",testId:"uc-overlay",variant:"dialog",children:[ie,oe,he,ge,Ne,ke,we,Fe]}),e[94]=n,e[95]=le,e[96]=ie,e[97]=oe,e[98]=he,e[99]=ge,e[100]=Ne,e[101]=ke,e[102]=we,e[103]=Fe,e[104]=Te):Te=e[104],Te},"ut"),Ye=s(h=>{let e=(0,W.c)(2),{children:n}=h,l;return e[0]!==n?(l=(0,t.jsx)("h3",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:n}),e[0]=n,e[1]=l):l=e[1],l},"_e"),pt=s(h=>{let e=(0,W.c)(29),{busy:n,runAction:l,userId:o,version:a}=h,p=J(),i=Q(),[u,c]=(0,C.useState)(null),[y,w]=(0,C.useState)(null),g;e[0]!==p||e[1]!==o?(g=s(()=>{Z((async()=>{w(null);try{let r=await p.listAuthSessions({limit:50,userId:o});c(r.rows)}catch(r){let S=r;c(null),w(Ee(S))}})())},"g"),e[0]=p,e[1]=o,e[2]=g):g=e[2];let I;e[3]!==p||e[4]!==o||e[5]!==a?(I=[p,o,a],e[3]=p,e[4]=o,e[5]=a,e[6]=I):I=e[6],(0,C.useEffect)(g,I);let k;e[7]!==p||e[8]!==l?(k=s(r=>{l(()=>p.revokeAuthSession({sessionId:r}))},"k"),e[7]=p,e[8]=l,e[9]=k):k=e[9];let v=k,d;e[10]!==i?(d=i("Sessions"),e[10]=i,e[11]=d):d=e[11];let m;e[12]!==d?(m=(0,t.jsx)(Ye,{children:d}),e[12]=d,e[13]=m):m=e[13];let b;e[14]!==y?(b=y!==null&&(0,t.jsx)("p",{className:"text-sm text-destructive","data-testid":"ud-sessions-error",role:"alert",children:y}),e[14]=y,e[15]=b):b=e[15];let x;e[16]!==u||e[17]!==i?(x=u!==null&&u.length===0&&(0,t.jsx)("p",{className:"text-sm text-muted-foreground","data-testid":"ud-sessions-empty",children:i("No active sessions.")}),e[16]=u,e[17]=i,e[18]=x):x=e[18];let N;e[19]!==n||e[20]!==v||e[21]!==u||e[22]!==i?(N=u!==null&&u.length>0&&(0,t.jsx)(K,{className:"overflow-hidden py-0",children:(0,t.jsx)(X,{className:"px-0",children:(0,t.jsxs)(ze,{"data-testid":"ud-sessions-table",children:[(0,t.jsx)(_e,{children:(0,t.jsxs)(q,{children:[(0,t.jsx)(U,{children:i("expires")}),(0,t.jsx)(U,{children:i("ip")}),(0,t.jsx)(U,{children:i("user agent")}),(0,t.jsx)(U,{"aria-label":i("Actions")})]})}),(0,t.jsx)(Pe,{children:u.map(r=>(0,t.jsxs)(q,{"data-testid":`ud-session-${r.id}`,children:[(0,t.jsx)(z,{className:"text-muted-foreground tabular-nums",children:te(r.expiresAt)}),(0,t.jsx)(z,{children:r.ipAddress??""}),(0,t.jsx)(z,{className:"max-w-40 truncate",children:r.userAgent??""}),(0,t.jsx)(z,{children:(0,t.jsx)(_,{"data-testid":`ud-revoke-${r.id}`,disabled:n,onClick:s(()=>{v(r.id)},"onClick"),size:"xs",type:"button",variant:"ghost",children:i("Revoke")})})]},r.id))})]})})}),e[19]=n,e[20]=v,e[21]=u,e[22]=i,e[23]=N):N=e[23];let f;return e[24]!==m||e[25]!==b||e[26]!==x||e[27]!==N?(f=(0,t.jsxs)("div",{className:"flex flex-col gap-2","data-testid":"ud-sessions",children:[m,b,x,N]}),e[24]=m,e[25]=b,e[26]=x,e[27]=N,e[28]=f):f=e[28],f},"mt"),ft=s(h=>{let e=(0,W.c)(30),{busy:n,runAction:l,userId:o,version:a}=h,p=J(),i=Q(),[u,c]=(0,C.useState)(null),[y,w]=(0,C.useState)(null),g;e[0]!==p||e[1]!==o?(g=s(()=>{Z((async()=>{w(null);try{c(await p.listAuthAccounts({userId:o}))}catch(r){let S=r;c(null),w(Ee(S))}})())},"g"),e[0]=p,e[1]=o,e[2]=g):g=e[2];let I;e[3]!==p||e[4]!==o||e[5]!==a?(I=[p,o,a],e[3]=p,e[4]=o,e[5]=a,e[6]=I):I=e[6],(0,C.useEffect)(g,I);let k;e[7]!==p||e[8]!==l||e[9]!==o?(k=s(r=>{l(()=>p.unlinkAuthAccount({accountId:r,userId:o}))},"k"),e[7]=p,e[8]=l,e[9]=o,e[10]=k):k=e[10];let v=k,d;e[11]!==i?(d=i("Linked accounts"),e[11]=i,e[12]=d):d=e[12];let m;e[13]!==d?(m=(0,t.jsx)(Ye,{children:d}),e[13]=d,e[14]=m):m=e[14];let b;e[15]!==y?(b=y!==null&&(0,t.jsx)("p",{className:"text-sm text-destructive",role:"alert",children:y}),e[15]=y,e[16]=b):b=e[16];let x;e[17]!==u||e[18]!==i?(x=u!==null&&u.length===0&&(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:i("No linked accounts.")}),e[17]=u,e[18]=i,e[19]=x):x=e[19];let N;e[20]!==u||e[21]!==n||e[22]!==v||e[23]!==i?(N=u!==null&&u.length>0&&(0,t.jsx)(K,{className:"overflow-hidden py-0",children:(0,t.jsx)(X,{className:"px-0",children:(0,t.jsxs)(ze,{"data-testid":"ud-accounts-table",children:[(0,t.jsx)(_e,{children:(0,t.jsxs)(q,{children:[(0,t.jsx)(U,{children:i("provider")}),(0,t.jsx)(U,{children:i("created")}),(0,t.jsx)(U,{"aria-label":i("Actions")})]})}),(0,t.jsx)(Pe,{children:u.map(r=>{let S=Ue(r.id);return(0,t.jsxs)(q,{"data-testid":`ud-account-${S}`,children:[(0,t.jsx)(z,{children:Ue(r.providerId)}),(0,t.jsx)(z,{className:"text-muted-foreground tabular-nums",children:te(r.createdAt)}),(0,t.jsx)(z,{children:(0,t.jsx)(_,{"data-testid":`ud-unlink-${S}`,disabled:n,onClick:s(()=>{v(S)},"onClick"),size:"xs",type:"button",variant:"ghost",children:i("Unlink")})})]},S)})})]})})}),e[20]=u,e[21]=n,e[22]=v,e[23]=i,e[24]=N):N=e[24];let f;return e[25]!==m||e[26]!==b||e[27]!==x||e[28]!==N?(f=(0,t.jsxs)("div",{className:"flex flex-col gap-2","data-testid":"ud-accounts",children:[m,b,x,N]}),e[25]=m,e[26]=b,e[27]=x,e[28]=N,e[29]=f):f=e[29],f},"ht"),vt=s(h=>{let e=(0,W.c)(40),{busy:n,capabilities:l,runAction:o,userId:a,version:p}=h,i=J(),u=Q(),[c,y]=(0,C.useState)(null),w;e[0]!==l.passkey||e[1]!==i||e[2]!==a?(w=s(()=>{l.passkey&&Z((async()=>{try{y(await i.listAuthPasskeys({userId:a}))}catch{y(null)}})())},"C"),e[0]=l.passkey,e[1]=i,e[2]=a,e[3]=w):w=e[3];let g;e[4]!==l.passkey||e[5]!==i||e[6]!==a||e[7]!==p?(g=[l.passkey,i,a,p],e[4]=l.passkey,e[5]=i,e[6]=a,e[7]=p,e[8]=g):g=e[8],(0,C.useEffect)(w,g);let I;e[9]!==i||e[10]!==o||e[11]!==a?(I=s(()=>{o(()=>i.disableAuthTwoFactor({userId:a}))},"w"),e[9]=i,e[10]=o,e[11]=a,e[12]=I):I=e[12];let k=I,v;e[13]!==i||e[14]!==o?(v=s(S=>{o(()=>i.deleteAuthPasskey({passkeyId:S}))},"v"),e[13]=i,e[14]=o,e[15]=v):v=e[15];let d=v,m;e[16]!==u?(m=u("Security"),e[16]=u,e[17]=m):m=e[17];let b;e[18]!==m?(b=(0,t.jsx)(Ye,{children:m}),e[18]=m,e[19]=b):b=e[19];let x;e[20]!==n||e[21]!==l.twoFactor||e[22]!==k||e[23]!==u?(x=l.twoFactor&&(0,t.jsx)(_,{"data-testid":"ud-disable-2fa",disabled:n,onClick:k,size:"sm",type:"button",variant:"outline",children:u("Disable two-factor")}),e[20]=n,e[21]=l.twoFactor,e[22]=k,e[23]=u,e[24]=x):x=e[24];let N;e[25]!==l.passkey||e[26]!==c||e[27]!==u?(N=l.passkey&&c!==null&&c.length===0&&(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:u("No passkeys.")}),e[25]=l.passkey,e[26]=c,e[27]=u,e[28]=N):N=e[28];let f;e[29]!==n||e[30]!==l.passkey||e[31]!==d||e[32]!==c||e[33]!==u?(f=l.passkey&&c!==null&&c.length>0&&(0,t.jsx)(K,{className:"overflow-hidden py-0",children:(0,t.jsx)(X,{className:"px-0",children:(0,t.jsxs)(ze,{"data-testid":"ud-passkeys-table",children:[(0,t.jsx)(_e,{children:(0,t.jsxs)(q,{children:[(0,t.jsx)(U,{children:u("name")}),(0,t.jsx)(U,{children:u("created")}),(0,t.jsx)(U,{"aria-label":u("Actions")})]})}),(0,t.jsx)(Pe,{children:c.map(S=>{let $=Ue(S.id);return(0,t.jsxs)(q,{"data-testid":`ud-passkey-${$}`,children:[(0,t.jsx)(z,{children:Ue(S.name)||$}),(0,t.jsx)(z,{className:"text-muted-foreground tabular-nums",children:te(S.createdAt)}),(0,t.jsx)(z,{children:(0,t.jsx)(_,{"data-testid":`ud-delete-passkey-${$}`,disabled:n,onClick:s(()=>{d($)},"onClick"),size:"xs",type:"button",variant:"ghost",children:u("Delete")})})]},$)})})]})})}),e[29]=n,e[30]=l.passkey,e[31]=d,e[32]=c,e[33]=u,e[34]=f):f=e[34];let r;return e[35]!==b||e[36]!==x||e[37]!==N||e[38]!==f?(r=(0,t.jsxs)("div",{className:"flex flex-col gap-2","data-testid":"ud-security",children:[b,x,N,f]}),e[35]=b,e[36]=x,e[37]=N,e[38]=f,e[39]=r):r=e[39],r},"ft"),gt=/(?:at|expires)$/iu,bt=/^[1-9]\d*$/u,xt=new Set(["banExpires","banned","banReason","email","emailVerified","id","name","role"]),yt=s(h=>{let e=(0,W.c)(51),{busy:n,onBan:l}=h,o=Q(),[a,p]=(0,C.useState)(""),[i,u]=(0,C.useState)(""),[c,y]=(0,C.useState)(!1),w;e[0]!==i?(w=bt.test(i.trim())&&Number.isSafeInteger(Number(i.trim())*86400)?Number(i.trim()):void 0,e[0]=i,e[1]=w):w=e[1];let g=w,I=c||g!==void 0,k;e[2]!==l||e[3]!==c||e[4]!==a||e[5]!==g?(k=s(()=>{l({expiresInSeconds:c||g===void 0?void 0:g*86400,reason:a.trim()===""?void 0:a.trim()})},"k"),e[2]=l,e[3]=c,e[4]=a,e[5]=g,e[6]=k):k=e[6];let v=k,d;e[7]!==o?(d=o("Ban reason (optional)"),e[7]=o,e[8]=d):d=e[8];let m;e[9]!==d?(m=(0,t.jsx)(O,{htmlFor:"ud-ban-reason",children:d}),e[9]=d,e[10]=m):m=e[10];let b;e[11]===Symbol.for("react.memo_cache_sentinel")?(b=s(E=>{p(E.target.value)},"b"),e[11]=b):b=e[11];let x;e[12]!==a?(x=(0,t.jsx)(T,{"data-testid":"ud-ban-reason",id:"ud-ban-reason",onChange:b,value:a}),e[12]=a,e[13]=x):x=e[13];let N;e[14]!==m||e[15]!==x?(N=(0,t.jsxs)("div",{className:"flex flex-1 flex-col gap-1",children:[m,x]}),e[14]=m,e[15]=x,e[16]=N):N=e[16];let f;e[17]!==o?(f=o("Days"),e[17]=o,e[18]=f):f=e[18];let r;e[19]!==f?(r=(0,t.jsx)(O,{htmlFor:"ud-ban-days",children:f}),e[19]=f,e[20]=r):r=e[20];let S;e[21]!==i||e[22]!==g?(S=i.trim()!==""&&g===void 0,e[21]=i,e[22]=g,e[23]=S):S=e[23];let $;e[24]===Symbol.for("react.memo_cache_sentinel")?($=s(E=>{u(E.target.value)},"T"),e[24]=$):$=e[24];let j;e[25]!==i||e[26]!==c||e[27]!==S?(j=(0,t.jsx)(T,{"aria-invalid":S,"data-testid":"ud-ban-days",disabled:c,id:"ud-ban-days",min:1,onChange:$,step:1,type:"number",value:i}),e[25]=i,e[26]=c,e[27]=S,e[28]=j):j=e[28];let H;e[29]!==j||e[30]!==r?(H=(0,t.jsxs)("div",{className:"flex w-24 flex-col gap-1",children:[r,j]}),e[29]=j,e[30]=r,e[31]=H):H=e[31];let M;e[32]===Symbol.for("react.memo_cache_sentinel")?(M=s(E=>{y(E.target.checked)},"M"),e[32]=M):M=e[32];let Y;e[33]!==c?(Y=(0,t.jsx)("input",{checked:c,className:"size-4 accent-destructive","data-testid":"ud-ban-permanent",id:"ud-ban-permanent",onChange:M,type:"checkbox"}),e[33]=c,e[34]=Y):Y=e[34];let B;e[35]!==o?(B=o("Permanent"),e[35]=o,e[36]=B):B=e[36];let V;e[37]!==Y||e[38]!==B?(V=(0,t.jsxs)(O,{className:"flex items-center gap-1.5 pb-2 text-xs font-normal",htmlFor:"ud-ban-permanent",children:[Y,B]}),e[37]=Y,e[38]=B,e[39]=V):V=e[39];let G=n||!I,P;e[40]!==o?(P=o("Ban user"),e[40]=o,e[41]=P):P=e[41];let L;e[42]!==v||e[43]!==G||e[44]!==P?(L=(0,t.jsx)(_,{"data-testid":"ud-ban",disabled:G,onClick:v,size:"sm",type:"button",variant:"destructive",children:P}),e[42]=v,e[43]=G,e[44]=P,e[45]=L):L=e[45];let F;return e[46]!==H||e[47]!==V||e[48]!==L||e[49]!==N?(F=(0,t.jsxs)("div",{className:"flex items-end gap-2",children:[N,H,V,L]}),e[46]=H,e[47]=V,e[48]=L,e[49]=N,e[50]=F):F=e[50],F},"bt"),Nt=s((h,e)=>typeof e=="number"&&gt.test(h)?te(e):Ue(e),"xt"),kt=s(({capabilities:h,onChanged:e,onClose:n,user:l})=>{let o=J(),a=Q(),p=l.banned===!0,[i,u]=(0,C.useState)(null),[c,y]=(0,C.useState)(!1),[w,g]=(0,C.useState)(0),[I,k]=(0,C.useState)(typeof l.role=="string"?l.role:""),[v,d]=(0,C.useState)(""),[m,b]=(0,C.useState)(null),[x,N]=(0,C.useState)(!1),f=s((F,E)=>{Z((async()=>{y(!0),u(null);try{let $e=await F();E?.refresh!==!1&&(g(ae=>ae+1),e()),E?.onResult?.($e)}catch($e){u(Ee($e))}y(!1)})())},"p"),r=s(F=>{k(F.target.value)},"i"),S=s(F=>{d(F.target.value)},"I"),$=s(()=>{let F=I.trim();F!==""&&f(async()=>{await o.setAuthUserRole({role:F,userId:l.id})})},"T"),j=s(F=>{f(async()=>{await o.banAuthUser({...F,userId:l.id})})},"z"),H=s(()=>{f(async()=>{await o.unbanAuthUser({userId:l.id})})},"j"),M=s(()=>{f(async()=>{await o.setAuthUserPassword({newPassword:v,userId:l.id}),d("")})},"M"),Y=s(()=>{f(()=>o.impersonateAuthUser({userId:l.id}),{onResult:s(F=>{b(F.token)},"onResult"),refresh:!1})},"H"),B=s(()=>{f(async()=>{await o.revokeAuthUserSessions({userId:l.id})})},"L"),V=s(()=>{f(async()=>{await o.removeAuthUser({userId:l.id}),n()})},"V"),G=s(()=>{N(!0)},"Y"),P=s(()=>{N(!1)},"E"),L=Object.entries(l).filter(([F])=>!xt.has(F));return(0,t.jsxs)(He,{label:a("User details"),onClose:n,panelTestId:"ud-panel",testId:"ud-overlay",variant:"drawer",children:[(0,t.jsxs)("div",{className:"flex items-start justify-between gap-2",children:[(0,t.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,t.jsx)("h2",{className:"text-sm font-semibold text-foreground",children:l.name??l.email??l.id}),(0,t.jsx)("p",{className:"font-mono text-xs text-muted-foreground",children:l.id}),(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-1.5 pt-1",children:[typeof l.role=="string"&&l.role!==""&&(0,t.jsx)(D,{variant:"secondary",children:l.role}),p?(0,t.jsx)(D,{variant:"destructive",children:a("Banned")}):(0,t.jsx)(D,{variant:"outline",children:a("Active")}),l.emailVerified===!0?(0,t.jsx)(D,{variant:"secondary",children:a("verified")}):(0,t.jsx)(D,{variant:"outline",children:a("unverified")})]})]}),(0,t.jsx)(_,{"data-testid":"ud-close",onClick:n,size:"sm",type:"button",variant:"ghost",children:a("Close")})]}),i!==null&&(0,t.jsx)("p",{className:"text-sm text-destructive","data-testid":"ud-action-error",role:"alert",children:i}),h.admin&&(0,t.jsxs)(K,{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:a("Actions")})}),(0,t.jsxs)(X,{className:"flex flex-col gap-3 p-3",children:[(0,t.jsxs)("div",{className:"flex items-end gap-2",children:[(0,t.jsxs)("div",{className:"flex flex-1 flex-col gap-1",children:[(0,t.jsx)(O,{htmlFor:"ud-role",children:a("Role")}),(0,t.jsx)(T,{"data-testid":"ud-role-input",id:"ud-role",onChange:r,value:I})]}),(0,t.jsx)(_,{"data-testid":"ud-set-role",disabled:c||I.trim()==="",onClick:$,size:"sm",type:"button",variant:"outline",children:a("Set role")})]}),p?(0,t.jsx)(_,{"data-testid":"ud-unban",disabled:c,onClick:H,size:"sm",type:"button",variant:"outline",children:a("Unban")}):(0,t.jsx)(yt,{busy:c,onBan:j}),(0,t.jsxs)("div",{className:"flex items-end gap-2",children:[(0,t.jsxs)("div",{className:"flex flex-1 flex-col gap-1",children:[(0,t.jsx)(O,{htmlFor:"ud-password",children:a("New password")}),(0,t.jsx)(T,{"data-testid":"ud-password",id:"ud-password",onChange:S,type:"password",value:v})]}),(0,t.jsx)(_,{"data-testid":"ud-set-password",disabled:c||v==="",onClick:M,size:"sm",type:"button",variant:"outline",children:a("Set password")})]}),(0,t.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,t.jsx)(_,{"data-testid":"ud-impersonate",disabled:c,onClick:Y,size:"sm",type:"button",variant:"outline",children:a("Impersonate")}),(0,t.jsx)(_,{"data-testid":"ud-revoke-all",disabled:c,onClick:B,size:"sm",type:"button",variant:"outline",children:a("Revoke all sessions")}),x?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(_,{"data-testid":"ud-delete-confirm",disabled:c,onClick:V,size:"sm",type:"button",variant:"destructive",children:a("Confirm delete")}),(0,t.jsx)(_,{"data-testid":"ud-delete-cancel",onClick:P,size:"sm",type:"button",variant:"ghost",children:a("Cancel")})]}):(0,t.jsx)(_,{"data-testid":"ud-delete",disabled:c,onClick:G,size:"sm",type:"button",variant:"destructive",children:a("Delete user")})]}),m!==null&&(0,t.jsxs)("div",{className:"flex flex-col gap-1","data-testid":"ud-impersonation",children:[(0,t.jsx)(O,{htmlFor:"ud-token",children:a("Impersonation token")}),(0,t.jsx)(T,{"data-testid":"ud-token",id:"ud-token",readOnly:!0,value:m})]})]})]}),(0,t.jsx)(pt,{busy:c,runAction:f,userId:l.id,version:w}),h.accounts&&(0,t.jsx)(ft,{busy:c,runAction:f,userId:l.id,version:w}),(h.twoFactor||h.passkey)&&(0,t.jsx)(vt,{busy:c,capabilities:h,runAction:f,userId:l.id,version:w}),(0,t.jsxs)("div",{className:"flex flex-col gap-1","data-testid":"ud-fields",children:[(0,t.jsx)("h3",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:a("Fields")}),(0,t.jsx)("dl",{className:"flex flex-col",children:L.map(([F,E])=>(0,t.jsxs)("div",{className:"flex flex-col border-t border-border py-1.5",children:[(0,t.jsx)("dt",{className:"text-xs font-semibold text-muted-foreground",children:F}),(0,t.jsx)("dd",{className:"m-0 font-mono text-xs break-words",children:Nt(F,E)})]},F))})]})]})},"yt"),wt=50,Vt=s(({pageSize:h=wt}={})=>{let e=J(),n=Q(),[l,o]=(0,C.useState)(""),[a,p]=(0,C.useState)(""),[i,u]=(0,C.useState)(0),c=Xe(l),[y,w]=(0,C.useState)(null),[g,I]=(0,C.useState)(!1),{capabilities:k}=it(),v=c.trim(),d=a.trim(),m=De(["lunora-auth-users",v,d,h,i],()=>e.listAuthUsers({filterField:d===""?void 0:"role",filterValue:d===""?void 0:d,limit:h,offset:i,search:v===""?void 0:v}).then(r=>({...r,offset:i})),{keepPreviousData:!0}),b=m.data?.rows??null,x=m.error,N=s(()=>{m.refetch()},"N");We(()=>{m.refetch()},!0);let f=y===null?null:b?.find(r=>r.id===y)??null;return(0,t.jsxs)("div",{className:"flex flex-col gap-4","data-testid":"lunora-users",children:[(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,t.jsx)(T,{"aria-label":n("Search users"),className:"w-56","data-testid":"us-search",onChange:s(r=>{o(r.target.value),u(0)},"onChange"),placeholder:n("Search by email or name\u2026"),value:l}),(0,t.jsx)(T,{"aria-label":n("Filter by role"),className:"w-40","data-testid":"us-role-filter",onChange:s(r=>{p(r.target.value),u(0)},"onChange"),placeholder:n("Filter by role"),value:a}),(0,t.jsx)(_,{"data-testid":"us-new",onClick:s(()=>{I(!0)},"onClick"),size:"sm",type:"button",children:n("New user")})]}),x!==null&&(0,t.jsx)("p",{className:"text-sm text-destructive","data-testid":"us-users-error",role:"alert",children:x}),b!==null&&b.length===0&&(0,t.jsx)(Ve,{description:n("Users who sign up to your app will appear here."),icon:(0,t.jsx)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,t.jsx)("path",{d:"M16 20v-2a4 4 0 0 0-4-4H7a4 4 0 0 0-4 4v2M9.5 10a3.5 3.5 0 1 0 0-7 3.5 3.5 0 0 0 0 7Zm11.5 10v-2a4 4 0 0 0-3-3.85"})}),testId:"us-empty",title:n("No users.")}),b!==null&&b.length>0&&(0,t.jsx)(K,{className:"overflow-hidden py-0",children:(0,t.jsx)(X,{className:"px-0",children:(0,t.jsxs)(ze,{"data-testid":"us-table",children:[(0,t.jsx)(_e,{children:(0,t.jsxs)(q,{children:[(0,t.jsx)(U,{children:n("id")}),(0,t.jsx)(U,{children:n("email")}),(0,t.jsx)(U,{children:n("name")}),(0,t.jsx)(U,{children:n("role")}),(0,t.jsx)(U,{children:n("status")}),(0,t.jsx)(U,{children:n("verified")}),(0,t.jsx)(U,{children:n("created")}),(0,t.jsx)(U,{"aria-label":n("Actions")})]})}),(0,t.jsx)(Pe,{children:b.map(r=>(0,t.jsxs)(q,{"data-testid":`us-row-${r.id}`,children:[(0,t.jsx)(z,{className:"font-mono text-xs",children:r.id}),(0,t.jsx)(z,{children:r.email??""}),(0,t.jsx)(z,{children:r.name??""}),(0,t.jsx)(z,{children:typeof r.role=="string"&&r.role!==""?(0,t.jsx)(D,{variant:"secondary",children:r.role}):""}),(0,t.jsx)(z,{children:r.banned===!0?(0,t.jsx)(D,{variant:"destructive",children:n("Banned")}):(0,t.jsx)(D,{variant:"success",children:n("Active")})}),(0,t.jsx)(z,{children:r.emailVerified===!0?(0,t.jsx)(D,{variant:"success",children:n("yes")}):(0,t.jsx)(D,{variant:"outline",children:n("no")})}),(0,t.jsx)(z,{className:"text-muted-foreground tabular-nums",children:te(r.createdAt)}),(0,t.jsx)(z,{children:(0,t.jsx)(_,{"data-testid":`us-manage-${r.id}`,onClick:s(()=>{w(r.id)},"onClick"),size:"xs",type:"button",variant:"ghost",children:n("Manage")})})]},r.id))})]})})}),b!==null&&(0,t.jsx)(Je,{count:b.length,offset:m.data?.offset??0,onOffsetChange:u,pageSize:h,prefix:"us",total:m.data?.total}),f!==null&&(0,t.jsx)(kt,{capabilities:k,onChanged:N,onClose:s(()=>{w(null)},"onClose"),user:f}),g&&(0,t.jsx)(ht,{onClose:s(()=>{I(!1)},"onClose"),onCreated:N}),k.inviteOnly&&(0,t.jsx)(ot,{})]})},"jt");export{Vt as UsersPanel};
1
+ import{a as Ze}from"./chunk-7RKB5KS7.js";import{a as qe}from"./chunk-CVBWPFHY.js";import{a as Ke}from"./chunk-OSGXNEFA.js";import{a as He}from"./chunk-QJLHH3ET.js";import{a as O}from"./chunk-37WYCOQ2.js";import{a as Je}from"./chunk-4WD4XGC3.js";import"./chunk-Z22BDS6N.js";import{a as We}from"./chunk-JQXA2OYK.js";import{a as Xe}from"./chunk-IWZ7GVQO.js";import"./chunk-NGVP66OH.js";import"./chunk-GHQ2VDI2.js";import{i as T}from"./chunk-E4PXACVL.js";import"./chunk-MVWZMWPD.js";import"./chunk-7Y3SY37W.js";import{a as _}from"./chunk-7G4Z6Q7X.js";import"./chunk-3YXASVTP.js";import"./chunk-AUAECCXB.js";import{b as D}from"./chunk-Q6ED4KUL.js";import"./chunk-BOMPSVRC.js";import{b as De}from"./chunk-QUXXMJPZ.js";import{l as J}from"./chunk-BWKZ6FFW.js";import"./chunk-QAQDMS6R.js";import"./chunk-DYR23C3V.js";import{a as Ve}from"./chunk-RWVIV3U7.js";import{a as ze,b as _e,c as Pe,d as q,e as U,f as z}from"./chunk-HCTJKP5J.js";import{a as K,e as X}from"./chunk-2IKDEUCX.js";import{d as Q,h as Ee,o as Ue,p as Z,r as Qe,t as te}from"./chunk-HJHSQPHW.js";import{a as s,d as Me,e as at,f as lt,g as nt}from"./chunk-I26MS5PJ.js";var C=Me(at(),1);var W=Me(lt(),1);var t=Me(nt(),1);var it=s(()=>{let h=(0,W.c)(3),{config:e,ready:n}=qe(),l;return h[0]!==e.capabilities||h[1]!==n?(l={capabilities:e.capabilities,ready:n},h[0]=e.capabilities,h[1]=n,h[2]=l):l=h[2],l},"nt"),st=s((h,e)=>typeof h.acceptedAt=="number"?"spent":typeof h.expiresAt=="number"&&h.expiresAt<=e?"expired":"pending","lt"),et=500,rt=s((h,e)=>{if(!URL.canParse(h.trim()))return null;let n=new URL(h.trim());return n.searchParams.set("email",e.email),n.searchParams.set("invite",e.token),n.toString()},"at"),dt=s(h=>{let e=(0,W.c)(34),{issued:n,onSignUpPageChange:l,signUpPage:o}=h,a=Q(),[p,i]=(0,C.useState)(null),u;e[0]!==n||e[1]!==o?(u=rt(o,n),e[0]=n,e[1]=o,e[2]=u):u=e[2];let c=u,y;e[3]!==c?(y=s(()=>{let $="navigator"in globalThis?globalThis.navigator.clipboard:void 0;c===null||$===void 0||Z($.writeText(c).then(()=>(i(c),!0)))},"y"),e[3]=c,e[4]=y):y=e[4];let w=y,g;e[5]!==a?(g=a("Send this link to the invitee. It is shown once and cannot be recovered."),e[5]=a,e[6]=g):g=e[6];let I;e[7]!==g?(I=(0,t.jsx)("p",{className:"text-sm",children:g}),e[7]=g,e[8]=I):I=e[8];let k=c===null,v;e[9]!==a?(v=a("Your app's sign-up page"),e[9]=a,e[10]=v):v=e[10];let d;e[11]!==l?(d=s($=>{l($.target.value)},"r"),e[11]=l,e[12]=d):d=e[12];let m;e[13]!==o||e[14]!==k||e[15]!==v||e[16]!==d?(m=(0,t.jsx)(T,{"aria-invalid":k,"aria-label":v,"data-testid":"sign-up-invitation-page",onChange:d,value:o}),e[13]=o,e[14]=k,e[15]=v,e[16]=d,e[17]=m):m=e[17];let b=c??"",x;e[18]!==b?(x=(0,t.jsx)(T,{"data-testid":"sign-up-invitation-link",readOnly:!0,value:b}),e[18]=b,e[19]=x):x=e[19];let N;e[20]!==p||e[21]!==c||e[22]!==a?(N=a(p!==null&&p===c?"Copied":"Copy"),e[20]=p,e[21]=c,e[22]=a,e[23]=N):N=e[23];let f;e[24]!==w||e[25]!==N?(f=(0,t.jsx)(_,{"data-testid":"sign-up-invitation-copy",onClick:w,type:"button",children:N}),e[24]=w,e[25]=N,e[26]=f):f=e[26];let r;e[27]!==x||e[28]!==f?(r=(0,t.jsxs)("div",{className:"flex gap-2",children:[x,f]}),e[27]=x,e[28]=f,e[29]=r):r=e[29];let S;return e[30]!==r||e[31]!==I||e[32]!==m?(S=(0,t.jsx)(K,{children:(0,t.jsxs)(X,{className:"flex flex-col gap-2 p-4",children:[I,m,r]})}),e[30]=r,e[31]=I,e[32]=m,e[33]=S):S=e[33],S},"it"),ot=s(()=>{let h=J(),e=Q(),[n,l]=(0,C.useState)(""),[o,a]=(0,C.useState)(null),[p,i]=(0,C.useState)(null),[u,c]=(0,C.useState)(()=>`${Qe(h.url)}/sign-up`),y=De(["lunora-auth-sign-up-invitations",et],()=>h.listAuthSignUpInvitations({limit:et})),w=y.data?.rows??null,g=y.data?.total??0,I=s(()=>{let v=n.trim();v!==""&&(a(null),Z((async()=>{try{let d=await h.createAuthSignUpInvitation({email:v}),m=typeof d.token=="string"?d.token:void 0;i(m===void 0?null:{email:v,token:m}),l(""),y.refetch()}catch(d){a(d instanceof Error?d.message:String(d))}})()))},"w"),k=s(v=>{a(null),Z((async()=>{try{await h.revokeAuthSignUpInvitation({email:v}),y.refetch()}catch(d){a(d instanceof Error?d.message:String(d))}})())},"k");return(0,t.jsxs)("div",{className:"flex flex-col gap-4","data-testid":"sign-up-invitations",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("h2",{className:"text-base font-medium",children:e("Sign-up invitations")}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:e("Only invited addresses can create an account. Nothing is emailed \u2014 send the invitee the one-time link yourself.")})]}),(0,t.jsxs)("div",{className:"flex gap-2",children:[(0,t.jsx)(T,{"aria-label":e("Email address to invite"),"data-testid":"sign-up-invitation-email",onChange:s(v=>{l(v.target.value)},"onChange"),placeholder:e("ada@example.com"),type:"email",value:n}),(0,t.jsx)(_,{"data-testid":"sign-up-invitation-submit",onClick:I,type:"button",children:e("Invite")})]}),p!==null&&(0,t.jsx)(dt,{issued:p,onSignUpPageChange:c,signUpPage:u},p.token),(o??y.error)!==null&&(0,t.jsx)("p",{className:"text-sm text-destructive","data-testid":"sign-up-invitations-error",role:"alert",children:o??y.error}),w!==null&&w.length===0&&(0,t.jsx)(Ve,{testId:"sign-up-invitations-empty",title:e("Nobody has been invited yet.")}),w!==null&&g>w.length&&(0,t.jsx)("p",{className:"text-sm text-muted-foreground","data-testid":"sign-up-invitations-truncated",children:e("Showing the most recent invitations. Query the signUpInvitation table directly to see the rest.")}),w!==null&&w.length>0&&(0,t.jsx)(K,{children:(0,t.jsx)(X,{className:"p-0",children:(0,t.jsxs)(ze,{children:[(0,t.jsx)(_e,{children:(0,t.jsxs)(q,{children:[(0,t.jsx)(U,{children:e("Email")}),(0,t.jsx)(U,{children:e("Status")}),(0,t.jsx)(U,{children:e("Expires")}),(0,t.jsx)(U,{children:e("Invited by")}),(0,t.jsx)(U,{})]})}),(0,t.jsx)(Pe,{children:w.map(v=>{let d=st(v,Date.now()),m=v.email??"";return(0,t.jsxs)(q,{"data-testid":`sign-up-invitation-${m}`,children:[(0,t.jsx)(z,{children:m}),(0,t.jsxs)(z,{"data-testid":`sign-up-invitation-status-${m}`,children:[d==="spent"&&e("Accepted"),d==="expired"&&e("Expired"),d==="pending"&&e("Pending")]}),(0,t.jsx)(z,{children:typeof v.expiresAt=="number"?te(v.expiresAt):"\u2014"}),(0,t.jsx)(z,{children:v.invitedBy??"\u2014"}),(0,t.jsx)(z,{className:"text-right",children:(0,t.jsx)(_,{onClick:s(()=>{k(m)},"onClick"),type:"button",variant:"ghost",children:e("Revoke")})})]},v.id)})})]})})})]})},"rt"),ct={boolean:"checkbox",date:"datetime-local",number:"number",string:"text"},ut=s((h,e)=>h.type==="boolean"?!0:typeof e!="string"||e.trim()===""?!1:h.type!=="number"||!Number.isNaN(Number(e.trim())),"dt"),mt=s((h,e)=>{if(h.type==="boolean")return e===!0?{value:!0}:h.required?{value:!1}:void 0;let n=typeof e=="string"?e.trim():"";if(n!==""){if(h.type==="number"){let l=Number(n);return Number.isNaN(l)?void 0:{value:l}}return{value:n}}},"ct"),ht=s(h=>{let e=(0,W.c)(105),{onClose:n,onCreated:l}=h,o=J(),a=Q(),{config:p}=qe(),{busy:i,error:u,run:c}=Ke(),[y,w]=(0,C.useState)(""),[g,I]=(0,C.useState)(""),[k,v]=(0,C.useState)(""),[d,m]=(0,C.useState)(""),b;e[0]===Symbol.for("react.memo_cache_sentinel")?(b={},e[0]=b):b=e[0];let[x,N]=(0,C.useState)(b),f;e[1]===Symbol.for("react.memo_cache_sentinel")?(f=s(A=>{w(A.target.value)},"p"),e[1]=f):f=e[1];let r=f,S;e[2]===Symbol.for("react.memo_cache_sentinel")?(S=s(A=>{I(A.target.value)},"I"),e[2]=S):S=e[2];let $=S,j;e[3]===Symbol.for("react.memo_cache_sentinel")?(j=s(A=>{v(A.target.value)},"z"),e[3]=j):j=e[3];let H=j,M;e[4]===Symbol.for("react.memo_cache_sentinel")?(M=s(A=>{m(A.target.value)},"M"),e[4]=M):M=e[4];let Y=M,B;e[5]===Symbol.for("react.memo_cache_sentinel")?(B=s((A,R)=>{N(ee=>({...ee,[A]:R}))},"L"),e[5]=B):B=e[5];let V=B,G;e[6]!==x?(G=s(A=>x[A.name]??(A.type==="boolean"?!1:""),"Y"),e[6]=x,e[7]=G):G=e[7];let P=G,L;if(e[8]!==p.userFields||e[9]!==P){let A;e[11]!==P?(A=s(R=>!R.required||ut(R,P(R)),"A"),e[11]=P,e[12]=A):A=e[12],L=p.userFields.every(A),e[8]=p.userFields,e[9]=P,e[10]=L}else L=e[10];let F=L,E;e[13]!==i||e[14]!==y||e[15]!==g||e[16]!==F?(E=!i&&y.trim()!==""&&g.trim()!==""&&F,e[13]=i,e[14]=y,e[15]=g,e[16]=F,e[17]=E):E=e[17];let $e=E,ae;e[18]!==p.userFields||e[19]!==P?(ae=s(()=>{let A={};for(let R of p.userFields){let ee=mt(R,P(R));ee!==void 0&&(A[R.name]=ee.value)}return Object.keys(A).length===0?void 0:A},"te"),e[18]=p.userFields,e[19]=P,e[20]=ae):ae=e[20];let je=ae,Re;e[21]!==je||e[22]!==o||e[23]!==y||e[24]!==g||e[25]!==n||e[26]!==l||e[27]!==k||e[28]!==d||e[29]!==c?(Re=s(()=>{c(async()=>{await o.createAuthUser({data:je(),email:y.trim(),name:g.trim(),password:k===""?void 0:k,role:d.trim()===""?void 0:d.trim()}),l(),n()})},"De"),e[21]=je,e[22]=o,e[23]=y,e[24]=g,e[25]=n,e[26]=l,e[27]=k,e[28]=d,e[29]=c,e[30]=Re):Re=e[30];let Be=Re,le;e[31]!==a?(le=a("Create user"),e[31]=a,e[32]=le):le=e[32];let ne;e[33]!==a?(ne=a("Create user"),e[33]=a,e[34]=ne):ne=e[34];let ie;e[35]!==ne?(ie=(0,t.jsx)("h2",{className:"text-sm font-semibold text-foreground",children:ne}),e[35]=ne,e[36]=ie):ie=e[36];let se;e[37]!==a?(se=a("email"),e[37]=a,e[38]=se):se=e[38];let re;e[39]!==se?(re=(0,t.jsx)(O,{htmlFor:"uc-email",children:se}),e[39]=se,e[40]=re):re=e[40];let de;e[41]!==y?(de=(0,t.jsx)(T,{"data-testid":"uc-email",id:"uc-email",onChange:r,type:"email",value:y}),e[41]=y,e[42]=de):de=e[42];let oe;e[43]!==re||e[44]!==de?(oe=(0,t.jsxs)("div",{className:"flex flex-col gap-1",children:[re,de]}),e[43]=re,e[44]=de,e[45]=oe):oe=e[45];let ce;e[46]!==a?(ce=a("name"),e[46]=a,e[47]=ce):ce=e[47];let ue;e[48]!==ce?(ue=(0,t.jsx)(O,{htmlFor:"uc-name",children:ce}),e[48]=ce,e[49]=ue):ue=e[49];let me;e[50]!==g?(me=(0,t.jsx)(T,{"data-testid":"uc-name",id:"uc-name",onChange:$,value:g}),e[50]=g,e[51]=me):me=e[51];let he;e[52]!==ue||e[53]!==me?(he=(0,t.jsxs)("div",{className:"flex flex-col gap-1",children:[ue,me]}),e[52]=ue,e[53]=me,e[54]=he):he=e[54];let pe;e[55]!==a?(pe=a("Password (optional)"),e[55]=a,e[56]=pe):pe=e[56];let fe;e[57]!==pe?(fe=(0,t.jsx)(O,{htmlFor:"uc-password",children:pe}),e[57]=pe,e[58]=fe):fe=e[58];let ve;e[59]!==k?(ve=(0,t.jsx)(T,{"data-testid":"uc-password",id:"uc-password",onChange:H,type:"password",value:k}),e[59]=k,e[60]=ve):ve=e[60];let ge;e[61]!==fe||e[62]!==ve?(ge=(0,t.jsxs)("div",{className:"flex flex-col gap-1",children:[fe,ve]}),e[61]=fe,e[62]=ve,e[63]=ge):ge=e[63];let be;e[64]!==a?(be=a("Role (optional)"),e[64]=a,e[65]=be):be=e[65];let xe;e[66]!==be?(xe=(0,t.jsx)(O,{htmlFor:"uc-role",children:be}),e[66]=be,e[67]=xe):xe=e[67];let ye;e[68]!==d?(ye=(0,t.jsx)(T,{"data-testid":"uc-role",id:"uc-role",onChange:Y,value:d}),e[68]=d,e[69]=ye):ye=e[69];let Ne;e[70]!==xe||e[71]!==ye?(Ne=(0,t.jsxs)("div",{className:"flex flex-col gap-1",children:[xe,ye]}),e[70]=xe,e[71]=ye,e[72]=Ne):Ne=e[72];let ke;e[73]!==p.userFields||e[74]!==P||e[75]!==a?(ke=p.userFields.length>0&&(0,t.jsxs)("div",{className:"flex flex-col gap-3 border-t border-border pt-3","data-testid":"uc-plugin-fields",children:[(0,t.jsx)("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:a("Plugin fields")}),p.userFields.map(A=>{let R=`uc-field-${A.name}`,ee=A.required?"":` (${a("optional")})`;if(A.type==="boolean"){let Oe=P(A)===!0;return(0,t.jsxs)("label",{className:"flex items-center gap-2",htmlFor:R,children:[(0,t.jsx)(Ze,{checked:Oe,"data-testid":R,id:R,onCheckedChange:s(tt=>{V(A.name,tt)},"onCheckedChange")}),(0,t.jsxs)("span",{className:"text-sm",children:[A.name,ee]})]},A.name)}let Ge=P(A);return(0,t.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,t.jsxs)(O,{htmlFor:R,children:[A.name,ee]}),(0,t.jsx)(T,{"data-testid":R,id:R,onChange:s(Oe=>{V(A.name,Oe.target.value)},"onChange"),type:ct[A.type],value:typeof Ge=="string"?Ge:""})]},A.name)})]}),e[73]=p.userFields,e[74]=P,e[75]=a,e[76]=ke):ke=e[76];let we;e[77]!==u?(we=u!==null&&(0,t.jsx)("p",{className:"text-sm text-destructive","data-testid":"uc-error",role:"alert",children:u}),e[77]=u,e[78]=we):we=e[78];let Ce;e[79]!==a?(Ce=a("Cancel"),e[79]=a,e[80]=Ce):Ce=e[80];let Ie;e[81]!==n||e[82]!==Ce?(Ie=(0,t.jsx)(_,{"data-testid":"uc-cancel",onClick:n,size:"sm",type:"button",variant:"outline",children:Ce}),e[81]=n,e[82]=Ce,e[83]=Ie):Ie=e[83];let Le=!$e,Ae;e[84]!==i||e[85]!==a?(Ae=a(i?"Creating\u2026":"Create"),e[84]=i,e[85]=a,e[86]=Ae):Ae=e[86];let Se;e[87]!==Be||e[88]!==Le||e[89]!==Ae?(Se=(0,t.jsx)(_,{"data-testid":"uc-submit",disabled:Le,onClick:Be,size:"sm",type:"button",children:Ae}),e[87]=Be,e[88]=Le,e[89]=Ae,e[90]=Se):Se=e[90];let Fe;e[91]!==Ie||e[92]!==Se?(Fe=(0,t.jsxs)("div",{className:"flex justify-end gap-2 pt-1",children:[Ie,Se]}),e[91]=Ie,e[92]=Se,e[93]=Fe):Fe=e[93];let Te;return e[94]!==n||e[95]!==le||e[96]!==ie||e[97]!==oe||e[98]!==he||e[99]!==ge||e[100]!==Ne||e[101]!==ke||e[102]!==we||e[103]!==Fe?(Te=(0,t.jsxs)(He,{label:le,onClose:n,panelTestId:"uc-dialog",testId:"uc-overlay",variant:"dialog",children:[ie,oe,he,ge,Ne,ke,we,Fe]}),e[94]=n,e[95]=le,e[96]=ie,e[97]=oe,e[98]=he,e[99]=ge,e[100]=Ne,e[101]=ke,e[102]=we,e[103]=Fe,e[104]=Te):Te=e[104],Te},"ut"),Ye=s(h=>{let e=(0,W.c)(2),{children:n}=h,l;return e[0]!==n?(l=(0,t.jsx)("h3",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:n}),e[0]=n,e[1]=l):l=e[1],l},"_e"),pt=s(h=>{let e=(0,W.c)(29),{busy:n,runAction:l,userId:o,version:a}=h,p=J(),i=Q(),[u,c]=(0,C.useState)(null),[y,w]=(0,C.useState)(null),g;e[0]!==p||e[1]!==o?(g=s(()=>{Z((async()=>{w(null);try{let r=await p.listAuthSessions({limit:50,userId:o});c(r.rows)}catch(r){let S=r;c(null),w(Ee(S))}})())},"g"),e[0]=p,e[1]=o,e[2]=g):g=e[2];let I;e[3]!==p||e[4]!==o||e[5]!==a?(I=[p,o,a],e[3]=p,e[4]=o,e[5]=a,e[6]=I):I=e[6],(0,C.useEffect)(g,I);let k;e[7]!==p||e[8]!==l?(k=s(r=>{l(()=>p.revokeAuthSession({sessionId:r}))},"k"),e[7]=p,e[8]=l,e[9]=k):k=e[9];let v=k,d;e[10]!==i?(d=i("Sessions"),e[10]=i,e[11]=d):d=e[11];let m;e[12]!==d?(m=(0,t.jsx)(Ye,{children:d}),e[12]=d,e[13]=m):m=e[13];let b;e[14]!==y?(b=y!==null&&(0,t.jsx)("p",{className:"text-sm text-destructive","data-testid":"ud-sessions-error",role:"alert",children:y}),e[14]=y,e[15]=b):b=e[15];let x;e[16]!==u||e[17]!==i?(x=u!==null&&u.length===0&&(0,t.jsx)("p",{className:"text-sm text-muted-foreground","data-testid":"ud-sessions-empty",children:i("No active sessions.")}),e[16]=u,e[17]=i,e[18]=x):x=e[18];let N;e[19]!==n||e[20]!==v||e[21]!==u||e[22]!==i?(N=u!==null&&u.length>0&&(0,t.jsx)(K,{className:"overflow-hidden py-0",children:(0,t.jsx)(X,{className:"px-0",children:(0,t.jsxs)(ze,{"data-testid":"ud-sessions-table",children:[(0,t.jsx)(_e,{children:(0,t.jsxs)(q,{children:[(0,t.jsx)(U,{children:i("expires")}),(0,t.jsx)(U,{children:i("ip")}),(0,t.jsx)(U,{children:i("user agent")}),(0,t.jsx)(U,{"aria-label":i("Actions")})]})}),(0,t.jsx)(Pe,{children:u.map(r=>(0,t.jsxs)(q,{"data-testid":`ud-session-${r.id}`,children:[(0,t.jsx)(z,{className:"text-muted-foreground tabular-nums",children:te(r.expiresAt)}),(0,t.jsx)(z,{children:r.ipAddress??""}),(0,t.jsx)(z,{className:"max-w-40 truncate",children:r.userAgent??""}),(0,t.jsx)(z,{children:(0,t.jsx)(_,{"data-testid":`ud-revoke-${r.id}`,disabled:n,onClick:s(()=>{v(r.id)},"onClick"),size:"xs",type:"button",variant:"ghost",children:i("Revoke")})})]},r.id))})]})})}),e[19]=n,e[20]=v,e[21]=u,e[22]=i,e[23]=N):N=e[23];let f;return e[24]!==m||e[25]!==b||e[26]!==x||e[27]!==N?(f=(0,t.jsxs)("div",{className:"flex flex-col gap-2","data-testid":"ud-sessions",children:[m,b,x,N]}),e[24]=m,e[25]=b,e[26]=x,e[27]=N,e[28]=f):f=e[28],f},"mt"),ft=s(h=>{let e=(0,W.c)(30),{busy:n,runAction:l,userId:o,version:a}=h,p=J(),i=Q(),[u,c]=(0,C.useState)(null),[y,w]=(0,C.useState)(null),g;e[0]!==p||e[1]!==o?(g=s(()=>{Z((async()=>{w(null);try{c(await p.listAuthAccounts({userId:o}))}catch(r){let S=r;c(null),w(Ee(S))}})())},"g"),e[0]=p,e[1]=o,e[2]=g):g=e[2];let I;e[3]!==p||e[4]!==o||e[5]!==a?(I=[p,o,a],e[3]=p,e[4]=o,e[5]=a,e[6]=I):I=e[6],(0,C.useEffect)(g,I);let k;e[7]!==p||e[8]!==l||e[9]!==o?(k=s(r=>{l(()=>p.unlinkAuthAccount({accountId:r,userId:o}))},"k"),e[7]=p,e[8]=l,e[9]=o,e[10]=k):k=e[10];let v=k,d;e[11]!==i?(d=i("Linked accounts"),e[11]=i,e[12]=d):d=e[12];let m;e[13]!==d?(m=(0,t.jsx)(Ye,{children:d}),e[13]=d,e[14]=m):m=e[14];let b;e[15]!==y?(b=y!==null&&(0,t.jsx)("p",{className:"text-sm text-destructive",role:"alert",children:y}),e[15]=y,e[16]=b):b=e[16];let x;e[17]!==u||e[18]!==i?(x=u!==null&&u.length===0&&(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:i("No linked accounts.")}),e[17]=u,e[18]=i,e[19]=x):x=e[19];let N;e[20]!==u||e[21]!==n||e[22]!==v||e[23]!==i?(N=u!==null&&u.length>0&&(0,t.jsx)(K,{className:"overflow-hidden py-0",children:(0,t.jsx)(X,{className:"px-0",children:(0,t.jsxs)(ze,{"data-testid":"ud-accounts-table",children:[(0,t.jsx)(_e,{children:(0,t.jsxs)(q,{children:[(0,t.jsx)(U,{children:i("provider")}),(0,t.jsx)(U,{children:i("created")}),(0,t.jsx)(U,{"aria-label":i("Actions")})]})}),(0,t.jsx)(Pe,{children:u.map(r=>{let S=Ue(r.id);return(0,t.jsxs)(q,{"data-testid":`ud-account-${S}`,children:[(0,t.jsx)(z,{children:Ue(r.providerId)}),(0,t.jsx)(z,{className:"text-muted-foreground tabular-nums",children:te(r.createdAt)}),(0,t.jsx)(z,{children:(0,t.jsx)(_,{"data-testid":`ud-unlink-${S}`,disabled:n,onClick:s(()=>{v(S)},"onClick"),size:"xs",type:"button",variant:"ghost",children:i("Unlink")})})]},S)})})]})})}),e[20]=u,e[21]=n,e[22]=v,e[23]=i,e[24]=N):N=e[24];let f;return e[25]!==m||e[26]!==b||e[27]!==x||e[28]!==N?(f=(0,t.jsxs)("div",{className:"flex flex-col gap-2","data-testid":"ud-accounts",children:[m,b,x,N]}),e[25]=m,e[26]=b,e[27]=x,e[28]=N,e[29]=f):f=e[29],f},"ht"),vt=s(h=>{let e=(0,W.c)(40),{busy:n,capabilities:l,runAction:o,userId:a,version:p}=h,i=J(),u=Q(),[c,y]=(0,C.useState)(null),w;e[0]!==l.passkey||e[1]!==i||e[2]!==a?(w=s(()=>{l.passkey&&Z((async()=>{try{y(await i.listAuthPasskeys({userId:a}))}catch{y(null)}})())},"C"),e[0]=l.passkey,e[1]=i,e[2]=a,e[3]=w):w=e[3];let g;e[4]!==l.passkey||e[5]!==i||e[6]!==a||e[7]!==p?(g=[l.passkey,i,a,p],e[4]=l.passkey,e[5]=i,e[6]=a,e[7]=p,e[8]=g):g=e[8],(0,C.useEffect)(w,g);let I;e[9]!==i||e[10]!==o||e[11]!==a?(I=s(()=>{o(()=>i.disableAuthTwoFactor({userId:a}))},"w"),e[9]=i,e[10]=o,e[11]=a,e[12]=I):I=e[12];let k=I,v;e[13]!==i||e[14]!==o?(v=s(S=>{o(()=>i.deleteAuthPasskey({passkeyId:S}))},"v"),e[13]=i,e[14]=o,e[15]=v):v=e[15];let d=v,m;e[16]!==u?(m=u("Security"),e[16]=u,e[17]=m):m=e[17];let b;e[18]!==m?(b=(0,t.jsx)(Ye,{children:m}),e[18]=m,e[19]=b):b=e[19];let x;e[20]!==n||e[21]!==l.twoFactor||e[22]!==k||e[23]!==u?(x=l.twoFactor&&(0,t.jsx)(_,{"data-testid":"ud-disable-2fa",disabled:n,onClick:k,size:"sm",type:"button",variant:"outline",children:u("Disable two-factor")}),e[20]=n,e[21]=l.twoFactor,e[22]=k,e[23]=u,e[24]=x):x=e[24];let N;e[25]!==l.passkey||e[26]!==c||e[27]!==u?(N=l.passkey&&c!==null&&c.length===0&&(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:u("No passkeys.")}),e[25]=l.passkey,e[26]=c,e[27]=u,e[28]=N):N=e[28];let f;e[29]!==n||e[30]!==l.passkey||e[31]!==d||e[32]!==c||e[33]!==u?(f=l.passkey&&c!==null&&c.length>0&&(0,t.jsx)(K,{className:"overflow-hidden py-0",children:(0,t.jsx)(X,{className:"px-0",children:(0,t.jsxs)(ze,{"data-testid":"ud-passkeys-table",children:[(0,t.jsx)(_e,{children:(0,t.jsxs)(q,{children:[(0,t.jsx)(U,{children:u("name")}),(0,t.jsx)(U,{children:u("created")}),(0,t.jsx)(U,{"aria-label":u("Actions")})]})}),(0,t.jsx)(Pe,{children:c.map(S=>{let $=Ue(S.id);return(0,t.jsxs)(q,{"data-testid":`ud-passkey-${$}`,children:[(0,t.jsx)(z,{children:Ue(S.name)||$}),(0,t.jsx)(z,{className:"text-muted-foreground tabular-nums",children:te(S.createdAt)}),(0,t.jsx)(z,{children:(0,t.jsx)(_,{"data-testid":`ud-delete-passkey-${$}`,disabled:n,onClick:s(()=>{d($)},"onClick"),size:"xs",type:"button",variant:"ghost",children:u("Delete")})})]},$)})})]})})}),e[29]=n,e[30]=l.passkey,e[31]=d,e[32]=c,e[33]=u,e[34]=f):f=e[34];let r;return e[35]!==b||e[36]!==x||e[37]!==N||e[38]!==f?(r=(0,t.jsxs)("div",{className:"flex flex-col gap-2","data-testid":"ud-security",children:[b,x,N,f]}),e[35]=b,e[36]=x,e[37]=N,e[38]=f,e[39]=r):r=e[39],r},"ft"),gt=/(?:at|expires)$/iu,bt=/^[1-9]\d*$/u,xt=new Set(["banExpires","banned","banReason","email","emailVerified","id","name","role"]),yt=s(h=>{let e=(0,W.c)(51),{busy:n,onBan:l}=h,o=Q(),[a,p]=(0,C.useState)(""),[i,u]=(0,C.useState)(""),[c,y]=(0,C.useState)(!1),w;e[0]!==i?(w=bt.test(i.trim())&&Number.isSafeInteger(Number(i.trim())*86400)?Number(i.trim()):void 0,e[0]=i,e[1]=w):w=e[1];let g=w,I=c||g!==void 0,k;e[2]!==l||e[3]!==c||e[4]!==a||e[5]!==g?(k=s(()=>{l({expiresInSeconds:c||g===void 0?void 0:g*86400,reason:a.trim()===""?void 0:a.trim()})},"k"),e[2]=l,e[3]=c,e[4]=a,e[5]=g,e[6]=k):k=e[6];let v=k,d;e[7]!==o?(d=o("Ban reason (optional)"),e[7]=o,e[8]=d):d=e[8];let m;e[9]!==d?(m=(0,t.jsx)(O,{htmlFor:"ud-ban-reason",children:d}),e[9]=d,e[10]=m):m=e[10];let b;e[11]===Symbol.for("react.memo_cache_sentinel")?(b=s(E=>{p(E.target.value)},"b"),e[11]=b):b=e[11];let x;e[12]!==a?(x=(0,t.jsx)(T,{"data-testid":"ud-ban-reason",id:"ud-ban-reason",onChange:b,value:a}),e[12]=a,e[13]=x):x=e[13];let N;e[14]!==m||e[15]!==x?(N=(0,t.jsxs)("div",{className:"flex flex-1 flex-col gap-1",children:[m,x]}),e[14]=m,e[15]=x,e[16]=N):N=e[16];let f;e[17]!==o?(f=o("Days"),e[17]=o,e[18]=f):f=e[18];let r;e[19]!==f?(r=(0,t.jsx)(O,{htmlFor:"ud-ban-days",children:f}),e[19]=f,e[20]=r):r=e[20];let S;e[21]!==i||e[22]!==g?(S=i.trim()!==""&&g===void 0,e[21]=i,e[22]=g,e[23]=S):S=e[23];let $;e[24]===Symbol.for("react.memo_cache_sentinel")?($=s(E=>{u(E.target.value)},"T"),e[24]=$):$=e[24];let j;e[25]!==i||e[26]!==c||e[27]!==S?(j=(0,t.jsx)(T,{"aria-invalid":S,"data-testid":"ud-ban-days",disabled:c,id:"ud-ban-days",min:1,onChange:$,step:1,type:"number",value:i}),e[25]=i,e[26]=c,e[27]=S,e[28]=j):j=e[28];let H;e[29]!==j||e[30]!==r?(H=(0,t.jsxs)("div",{className:"flex w-24 flex-col gap-1",children:[r,j]}),e[29]=j,e[30]=r,e[31]=H):H=e[31];let M;e[32]===Symbol.for("react.memo_cache_sentinel")?(M=s(E=>{y(E.target.checked)},"M"),e[32]=M):M=e[32];let Y;e[33]!==c?(Y=(0,t.jsx)("input",{checked:c,className:"size-4 accent-destructive","data-testid":"ud-ban-permanent",id:"ud-ban-permanent",onChange:M,type:"checkbox"}),e[33]=c,e[34]=Y):Y=e[34];let B;e[35]!==o?(B=o("Permanent"),e[35]=o,e[36]=B):B=e[36];let V;e[37]!==Y||e[38]!==B?(V=(0,t.jsxs)(O,{className:"flex items-center gap-1.5 pb-2 text-xs font-normal",htmlFor:"ud-ban-permanent",children:[Y,B]}),e[37]=Y,e[38]=B,e[39]=V):V=e[39];let G=n||!I,P;e[40]!==o?(P=o("Ban user"),e[40]=o,e[41]=P):P=e[41];let L;e[42]!==v||e[43]!==G||e[44]!==P?(L=(0,t.jsx)(_,{"data-testid":"ud-ban",disabled:G,onClick:v,size:"sm",type:"button",variant:"destructive",children:P}),e[42]=v,e[43]=G,e[44]=P,e[45]=L):L=e[45];let F;return e[46]!==H||e[47]!==V||e[48]!==L||e[49]!==N?(F=(0,t.jsxs)("div",{className:"flex items-end gap-2",children:[N,H,V,L]}),e[46]=H,e[47]=V,e[48]=L,e[49]=N,e[50]=F):F=e[50],F},"bt"),Nt=s((h,e)=>typeof e=="number"&&gt.test(h)?te(e):Ue(e),"xt"),kt=s(({capabilities:h,onChanged:e,onClose:n,user:l})=>{let o=J(),a=Q(),p=l.banned===!0,[i,u]=(0,C.useState)(null),[c,y]=(0,C.useState)(!1),[w,g]=(0,C.useState)(0),[I,k]=(0,C.useState)(typeof l.role=="string"?l.role:""),[v,d]=(0,C.useState)(""),[m,b]=(0,C.useState)(null),[x,N]=(0,C.useState)(!1),f=s((F,E)=>{Z((async()=>{y(!0),u(null);try{let $e=await F();E?.refresh!==!1&&(g(ae=>ae+1),e()),E?.onResult?.($e)}catch($e){u(Ee($e))}y(!1)})())},"p"),r=s(F=>{k(F.target.value)},"i"),S=s(F=>{d(F.target.value)},"I"),$=s(()=>{let F=I.trim();F!==""&&f(async()=>{await o.setAuthUserRole({role:F,userId:l.id})})},"T"),j=s(F=>{f(async()=>{await o.banAuthUser({...F,userId:l.id})})},"z"),H=s(()=>{f(async()=>{await o.unbanAuthUser({userId:l.id})})},"j"),M=s(()=>{f(async()=>{await o.setAuthUserPassword({newPassword:v,userId:l.id}),d("")})},"M"),Y=s(()=>{f(()=>o.impersonateAuthUser({userId:l.id}),{onResult:s(F=>{b(F.token)},"onResult"),refresh:!1})},"H"),B=s(()=>{f(async()=>{await o.revokeAuthUserSessions({userId:l.id})})},"L"),V=s(()=>{f(async()=>{await o.removeAuthUser({userId:l.id}),n()})},"V"),G=s(()=>{N(!0)},"Y"),P=s(()=>{N(!1)},"E"),L=Object.entries(l).filter(([F])=>!xt.has(F));return(0,t.jsxs)(He,{label:a("User details"),onClose:n,panelTestId:"ud-panel",testId:"ud-overlay",variant:"drawer",children:[(0,t.jsxs)("div",{className:"flex items-start justify-between gap-2",children:[(0,t.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,t.jsx)("h2",{className:"text-sm font-semibold text-foreground",children:l.name??l.email??l.id}),(0,t.jsx)("p",{className:"font-mono text-xs text-muted-foreground",children:l.id}),(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-1.5 pt-1",children:[typeof l.role=="string"&&l.role!==""&&(0,t.jsx)(D,{variant:"secondary",children:l.role}),p?(0,t.jsx)(D,{variant:"destructive",children:a("Banned")}):(0,t.jsx)(D,{variant:"outline",children:a("Active")}),l.emailVerified===!0?(0,t.jsx)(D,{variant:"secondary",children:a("verified")}):(0,t.jsx)(D,{variant:"outline",children:a("unverified")})]})]}),(0,t.jsx)(_,{"data-testid":"ud-close",onClick:n,size:"sm",type:"button",variant:"ghost",children:a("Close")})]}),i!==null&&(0,t.jsx)("p",{className:"text-sm text-destructive","data-testid":"ud-action-error",role:"alert",children:i}),h.admin&&(0,t.jsxs)(K,{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:a("Actions")})}),(0,t.jsxs)(X,{className:"flex flex-col gap-3 p-3",children:[(0,t.jsxs)("div",{className:"flex items-end gap-2",children:[(0,t.jsxs)("div",{className:"flex flex-1 flex-col gap-1",children:[(0,t.jsx)(O,{htmlFor:"ud-role",children:a("Role")}),(0,t.jsx)(T,{"data-testid":"ud-role-input",id:"ud-role",onChange:r,value:I})]}),(0,t.jsx)(_,{"data-testid":"ud-set-role",disabled:c||I.trim()==="",onClick:$,size:"sm",type:"button",variant:"outline",children:a("Set role")})]}),p?(0,t.jsx)(_,{"data-testid":"ud-unban",disabled:c,onClick:H,size:"sm",type:"button",variant:"outline",children:a("Unban")}):(0,t.jsx)(yt,{busy:c,onBan:j}),(0,t.jsxs)("div",{className:"flex items-end gap-2",children:[(0,t.jsxs)("div",{className:"flex flex-1 flex-col gap-1",children:[(0,t.jsx)(O,{htmlFor:"ud-password",children:a("New password")}),(0,t.jsx)(T,{"data-testid":"ud-password",id:"ud-password",onChange:S,type:"password",value:v})]}),(0,t.jsx)(_,{"data-testid":"ud-set-password",disabled:c||v==="",onClick:M,size:"sm",type:"button",variant:"outline",children:a("Set password")})]}),(0,t.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,t.jsx)(_,{"data-testid":"ud-impersonate",disabled:c,onClick:Y,size:"sm",type:"button",variant:"outline",children:a("Impersonate")}),(0,t.jsx)(_,{"data-testid":"ud-revoke-all",disabled:c,onClick:B,size:"sm",type:"button",variant:"outline",children:a("Revoke all sessions")}),x?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(_,{"data-testid":"ud-delete-confirm",disabled:c,onClick:V,size:"sm",type:"button",variant:"destructive",children:a("Confirm delete")}),(0,t.jsx)(_,{"data-testid":"ud-delete-cancel",onClick:P,size:"sm",type:"button",variant:"ghost",children:a("Cancel")})]}):(0,t.jsx)(_,{"data-testid":"ud-delete",disabled:c,onClick:G,size:"sm",type:"button",variant:"destructive",children:a("Delete user")})]}),m!==null&&(0,t.jsxs)("div",{className:"flex flex-col gap-1","data-testid":"ud-impersonation",children:[(0,t.jsx)(O,{htmlFor:"ud-token",children:a("Impersonation token")}),(0,t.jsx)(T,{"data-testid":"ud-token",id:"ud-token",readOnly:!0,value:m})]})]})]}),(0,t.jsx)(pt,{busy:c,runAction:f,userId:l.id,version:w}),h.accounts&&(0,t.jsx)(ft,{busy:c,runAction:f,userId:l.id,version:w}),(h.twoFactor||h.passkey)&&(0,t.jsx)(vt,{busy:c,capabilities:h,runAction:f,userId:l.id,version:w}),(0,t.jsxs)("div",{className:"flex flex-col gap-1","data-testid":"ud-fields",children:[(0,t.jsx)("h3",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:a("Fields")}),(0,t.jsx)("dl",{className:"flex flex-col",children:L.map(([F,E])=>(0,t.jsxs)("div",{className:"flex flex-col border-t border-border py-1.5",children:[(0,t.jsx)("dt",{className:"text-xs font-semibold text-muted-foreground",children:F}),(0,t.jsx)("dd",{className:"m-0 font-mono text-xs break-words",children:Nt(F,E)})]},F))})]})]})},"yt"),wt=50,Vt=s(({pageSize:h=wt}={})=>{let e=J(),n=Q(),[l,o]=(0,C.useState)(""),[a,p]=(0,C.useState)(""),[i,u]=(0,C.useState)(0),c=Xe(l),[y,w]=(0,C.useState)(null),[g,I]=(0,C.useState)(!1),{capabilities:k}=it(),v=c.trim(),d=a.trim(),m=De(["lunora-auth-users",v,d,h,i],()=>e.listAuthUsers({filterField:d===""?void 0:"role",filterValue:d===""?void 0:d,limit:h,offset:i,search:v===""?void 0:v}).then(r=>({...r,offset:i})),{keepPreviousData:!0}),b=m.data?.rows??null,x=m.error,N=s(()=>{m.refetch()},"N");We(()=>{m.refetch()},!0);let f=y===null?null:b?.find(r=>r.id===y)??null;return(0,t.jsxs)("div",{className:"flex flex-col gap-4","data-testid":"lunora-users",children:[(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,t.jsx)(T,{"aria-label":n("Search users"),className:"w-56","data-testid":"us-search",onChange:s(r=>{o(r.target.value),u(0)},"onChange"),placeholder:n("Search by email or name\u2026"),value:l}),(0,t.jsx)(T,{"aria-label":n("Filter by role"),className:"w-40","data-testid":"us-role-filter",onChange:s(r=>{p(r.target.value),u(0)},"onChange"),placeholder:n("Filter by role"),value:a}),(0,t.jsx)(_,{"data-testid":"us-new",onClick:s(()=>{I(!0)},"onClick"),size:"sm",type:"button",children:n("New user")})]}),x!==null&&(0,t.jsx)("p",{className:"text-sm text-destructive","data-testid":"us-users-error",role:"alert",children:x}),b!==null&&b.length===0&&(0,t.jsx)(Ve,{description:n("Users who sign up to your app will appear here."),icon:(0,t.jsx)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,t.jsx)("path",{d:"M16 20v-2a4 4 0 0 0-4-4H7a4 4 0 0 0-4 4v2M9.5 10a3.5 3.5 0 1 0 0-7 3.5 3.5 0 0 0 0 7Zm11.5 10v-2a4 4 0 0 0-3-3.85"})}),testId:"us-empty",title:n("No users.")}),b!==null&&b.length>0&&(0,t.jsx)(K,{className:"overflow-hidden py-0",children:(0,t.jsx)(X,{className:"px-0",children:(0,t.jsxs)(ze,{"data-testid":"us-table",children:[(0,t.jsx)(_e,{children:(0,t.jsxs)(q,{children:[(0,t.jsx)(U,{children:n("id")}),(0,t.jsx)(U,{children:n("email")}),(0,t.jsx)(U,{children:n("name")}),(0,t.jsx)(U,{children:n("role")}),(0,t.jsx)(U,{children:n("status")}),(0,t.jsx)(U,{children:n("verified")}),(0,t.jsx)(U,{children:n("created")}),(0,t.jsx)(U,{"aria-label":n("Actions")})]})}),(0,t.jsx)(Pe,{children:b.map(r=>(0,t.jsxs)(q,{"data-testid":`us-row-${r.id}`,children:[(0,t.jsx)(z,{className:"font-mono text-xs",children:r.id}),(0,t.jsx)(z,{children:r.email??""}),(0,t.jsx)(z,{children:r.name??""}),(0,t.jsx)(z,{children:typeof r.role=="string"&&r.role!==""?(0,t.jsx)(D,{variant:"secondary",children:r.role}):""}),(0,t.jsx)(z,{children:r.banned===!0?(0,t.jsx)(D,{variant:"destructive",children:n("Banned")}):(0,t.jsx)(D,{variant:"success",children:n("Active")})}),(0,t.jsx)(z,{children:r.emailVerified===!0?(0,t.jsx)(D,{variant:"success",children:n("yes")}):(0,t.jsx)(D,{variant:"outline",children:n("no")})}),(0,t.jsx)(z,{className:"text-muted-foreground tabular-nums",children:te(r.createdAt)}),(0,t.jsx)(z,{children:(0,t.jsx)(_,{"data-testid":`us-manage-${r.id}`,onClick:s(()=>{w(r.id)},"onClick"),size:"xs",type:"button",variant:"ghost",children:n("Manage")})})]},r.id))})]})})}),b!==null&&(0,t.jsx)(Je,{count:b.length,offset:m.data?.offset??0,onOffsetChange:u,pageSize:h,prefix:"us",total:m.data?.total}),f!==null&&(0,t.jsx)(kt,{capabilities:k,onChanged:N,onClose:s(()=>{w(null)},"onClose"),user:f}),g&&(0,t.jsx)(ht,{onClose:s(()=>{I(!1)},"onClose"),onCreated:N}),k.inviteOnly&&(0,t.jsx)(ot,{})]})},"jt");export{Vt as UsersPanel};
@@ -1 +1 @@
1
- import{b as me}from"./chunk-2I4NHEKA.js";import{a as $}from"./chunk-HOGQLP3J.js";import{a as ue}from"./chunk-SV764LKQ.js";import"./chunk-TIQ7OBZJ.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-DSIY2CMT.js";import{l as ne,m as oe}from"./chunk-BOYS4DOC.js";import"./chunk-QAQDMS6R.js";import"./chunk-N7LJO732.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-VBUNOAPR.js";import{a as ue}from"./chunk-SV764LKQ.js";import"./chunk-WHDFMKYB.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-QUXXMJPZ.js";import{l as ne,m as oe}from"./chunk-BWKZ6FFW.js";import"./chunk-QAQDMS6R.js";import"./chunk-DYR23C3V.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 Be,b as Ue,c as We,d as De,e as we}from"./chunk-5QR2SQIS.js";import"./chunk-NRP22GKC.js";import"./chunk-OPM7ESDV.js";import{a as Ve}from"./chunk-OSGXNEFA.js";import{a as qe}from"./chunk-SV764LKQ.js";import"./chunk-NXQW5E6W.js";import"./chunk-UC7MNI2F.js";import"./chunk-NGVP66OH.js";import"./chunk-GHQ2VDI2.js";import{a as Le}from"./chunk-R6U22RSY.js";import{a as _e}from"./chunk-YVR4SEPU.js";import"./chunk-ZKJS6EBE.js";import"./chunk-RGMVGZV4.js";import{i as ke}from"./chunk-E4PXACVL.js";import"./chunk-MVWZMWPD.js";import"./chunk-SJQERRSZ.js";import"./chunk-7Y3SY37W.js";import{a as ie}from"./chunk-7G4Z6Q7X.js";import"./chunk-3YXASVTP.js";import"./chunk-AUAECCXB.js";import{b as me}from"./chunk-Q6ED4KUL.js";import"./chunk-BOMPSVRC.js";import"./chunk-55UGUCQ6.js";import{a as U}from"./chunk-4ZEL6BYL.js";import{c as Ee}from"./chunk-DSIY2CMT.js";import{l as Ne}from"./chunk-BOYS4DOC.js";import"./chunk-QAQDMS6R.js";import{b as Ie,c as $e}from"./chunk-N7LJO732.js";import{a as Ae}from"./chunk-RWVIV3U7.js";import{a as ze,b as Re,c as je,d as pe,e as B,f as z}from"./chunk-HCTJKP5J.js";import{a as Me,e as Ce}from"./chunk-2IKDEUCX.js";import{d as ue,f as re,g as be,h as Ke,p as le,t as Te}from"./chunk-HJHSQPHW.js";import{a as d,d as ye,e as Oe,f as Ge,g as He}from"./chunk-I26MS5PJ.js";var ge=ye(Ge(),1);var ne=ye(Oe(),1);var t=ye(He(),1);var Se="none",Je=["all","open","resolved","ignored"],Pe=["critical","high","medium","low"],Qe=re(U.resolveIssue),Xe=re(U.ignoreIssue),Fe=re(U.assignIssue),Ye=re(U.setIssueSeverity),Ze=re(U.explainIssue),es=d(n=>Array.isArray(n?.issues)?n.issues:[],"Xe"),ss=d(n=>n==="resolved"?"success":n==="ignored"?"secondary":"warning","Je"),ts=d(n=>n==="critical"?"destructive":n==="high"?"warning":n==="medium"?"info":"secondary","Ze"),as=d(n=>{let e=(0,ge.c)(44),{expanded:u,issue:s,shardKey:$}=n,i=Ne(),l=ue(),[a,o]=(0,ne.useState)(void 0),{busy:_,error:A,run:R}=Ve(),K;e[0]!==i||e[1]!==s||e[2]!==R||e[3]!==$?(K=d(()=>{o(void 0),R(async()=>{let g={culprit:s.culprit,sampleMessage:s.sampleMessage,title:s.title},I=await i.query(Ze,g,be($));o(I)})},"C"),e[0]=i,e[1]=s,e[2]=R,e[3]=$,e[4]=K):K=e[4];let L=K;if(!u)return null;let k;if(e[5]!==s.sampleMessage){let g=$e(s.sampleMessage);k=g===void 0?void 0:Ie(g.body),e[5]=s.sampleMessage,e[6]=k}else k=e[6];let T=k,E=`issues-detail-${s.hash}`,h;e[7]!==s.sampleMessage?(h=(0,t.jsx)("p",{className:"whitespace-pre-wrap font-mono text-xs text-muted-foreground",children:s.sampleMessage}),e[7]=s.sampleMessage,e[8]=h):h=e[8];let x;e[9]!==l?(x=l("Suggested fix"),e[9]=l,e[10]=x):x=e[10];let M;e[11]!==x?(M=(0,t.jsx)("div",{className:"text-xs font-medium text-muted-foreground",children:x}),e[11]=x,e[12]=M):M=e[12];let v;e[13]!==T||e[14]!==s.hash||e[15]!==l?(v=T===void 0?(0,t.jsx)("p",{className:"mt-1 text-sm text-muted-foreground","data-testid":`issues-hint-empty-${s.hash}`,children:l("No known fix for this error yet.")}):(0,t.jsx)("p",{className:"mt-1 whitespace-pre-wrap text-sm","data-testid":`issues-hint-${s.hash}`,children:T}),e[13]=T,e[14]=s.hash,e[15]=l,e[16]=v):v=e[16];let y;e[17]!==M||e[18]!==v?(y=(0,t.jsxs)("div",{children:[M,v]}),e[17]=M,e[18]=v,e[19]=y):y=e[19];let b=`issues-explain-${s.hash}`,w;e[20]!==_||e[21]!==l?(w=l(_?"Explaining\u2026":"Explain in plain language"),e[20]=_,e[21]=l,e[22]=w):w=e[22];let m;e[23]!==_||e[24]!==L||e[25]!==w||e[26]!==b?(m=(0,t.jsx)("div",{children:(0,t.jsx)(ie,{"data-testid":b,disabled:_,onClick:L,size:"sm",type:"button",variant:"outline",children:w})}),e[23]=_,e[24]=L,e[25]=w,e[26]=b,e[27]=m):m=e[27];let f;e[28]!==A||e[29]!==s.hash?(f=A!==null&&(0,t.jsx)("p",{className:"text-xs text-destructive","data-testid":`issues-explain-error-${s.hash}`,role:"alert",children:A}),e[28]=A,e[29]=s.hash,e[30]=f):f=e[30];let p;e[31]!==a||e[32]!==s.hash||e[33]!==l?(p=a!==void 0&&(a.degraded?(0,t.jsx)("p",{className:"text-xs text-muted-foreground","data-testid":`issues-degraded-${s.hash}`,children:a.reason==="no-ai-binding"?l("No AI binding is configured. Wire an AI binding to enable plain-language explanations \u2014 the suggested fix above is always available."):l("The AI model could not explain this error right now. The suggested fix above still applies.")}):(0,t.jsxs)("div",{"data-testid":`issues-explanation-${s.hash}`,children:[(0,t.jsx)("div",{className:"text-xs font-medium text-muted-foreground",children:l("AI explanation")}),(0,t.jsx)("p",{className:"mt-1 whitespace-pre-wrap text-sm",children:a.explanation}),a.groundedId===void 0&&(0,t.jsx)("p",{className:"mt-1 text-xs text-muted-foreground","data-testid":`issues-ungrounded-${s.hash}`,children:l("No catalog fix matched this error, so this explanation is the model's own reading of the message. Verify before acting on it.")}),(0,t.jsx)("p",{className:"mt-1 text-[0.7rem] text-muted-foreground",children:l("Generated by {model}",{model:a.model})})]})),e[31]=a,e[32]=s.hash,e[33]=l,e[34]=p):p=e[34];let c;e[35]!==m||e[36]!==f||e[37]!==p||e[38]!==h||e[39]!==y?(c=(0,t.jsx)(z,{className:"bg-muted/30",colSpan:7,children:(0,t.jsxs)("div",{className:"flex flex-col gap-3 py-1",children:[h,y,m,f,p]})}),e[35]=m,e[36]=f,e[37]=p,e[38]=h,e[39]=y,e[40]=c):c=e[40];let S;return e[41]!==c||e[42]!==E?(S=(0,t.jsx)(pe,{"data-testid":E,children:c}),e[41]=c,e[42]=E,e[43]=S):S=e[43],S},"et"),is=d(n=>{let e=(0,ge.c)(119),{busy:u,issue:s,rowError:$,runTriage:i,shardKey:l}=n,a=ue(),[o,_]=(0,ne.useState)(!1),A;e[0]===Symbol.for("react.memo_cache_sentinel")?(A=d(()=>{_(rs)},"A"),e[0]=A):A=e[0];let R=A,K;e[1]!==s.hash||e[2]!==i?(K=d(ae=>{let ce=ae===null||ae===Se?null:ae;le(i(s.hash,Ye,{severity:ce}))},"C"),e[1]=s.hash,e[2]=i,e[3]=K):K=e[3];let L=K,k;e[4]!==s.hash||e[5]!==i?(k=d(ae=>{if(ae.key!=="Enter")return;let ce=ae.currentTarget.value.trim();le(i(s.hash,Fe,{assignee:ce===""?null:ce}))},"T"),e[4]=s.hash,e[5]=i,e[6]=k):k=e[6];let T=k,E=`issues-row-${s.hash}`,h;e[7]!==a?(h=a("Toggle issue details"),e[7]=a,e[8]=h):h=e[8];let x=`issues-toggle-${s.hash}`,M=`mt-1 size-3 shrink-0 text-muted-foreground transition-transform ${o?"rotate-90":""}`,v;e[9]===Symbol.for("react.memo_cache_sentinel")?(v=(0,t.jsx)("path",{d:"m9 6 6 6-6 6"}),e[9]=v):v=e[9];let y;e[10]!==M?(y=(0,t.jsx)("svg",{"aria-hidden":"true",className:M,fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,viewBox:"0 0 24 24",children:v}),e[10]=M,e[11]=y):y=e[11];let b;e[12]!==s.title?(b=(0,t.jsx)("span",{className:"block truncate font-medium",title:s.title,children:s.title}),e[12]=s.title,e[13]=b):b=e[13];let w;e[14]!==s.culprit?(w=(0,t.jsx)("span",{className:"block truncate font-mono text-xs text-muted-foreground",title:s.culprit,children:s.culprit}),e[14]=s.culprit,e[15]=w):w=e[15];let m;e[16]!==b||e[17]!==w?(m=(0,t.jsxs)("span",{className:"min-w-0",children:[b,w]}),e[16]=b,e[17]=w,e[18]=m):m=e[18];let f;e[19]!==o||e[20]!==m||e[21]!==h||e[22]!==x||e[23]!==y?(f=(0,t.jsxs)("button",{"aria-expanded":o,"aria-label":h,className:"flex w-full items-start gap-2 text-left","data-testid":x,onClick:R,type:"button",children:[y,m]}),e[19]=o,e[20]=m,e[21]=h,e[22]=x,e[23]=y,e[24]=f):f=e[24];let p;e[25]!==s.hash||e[26]!==$?(p=$!==void 0&&(0,t.jsx)("p",{className:"mt-1 text-xs text-destructive","data-testid":`issues-action-error-${s.hash}`,role:"alert",children:$}),e[25]=s.hash,e[26]=$,e[27]=p):p=e[27];let c;e[28]!==f||e[29]!==p?(c=(0,t.jsxs)(z,{className:"max-w-80",children:[f,p]}),e[28]=f,e[29]=p,e[30]=c):c=e[30];let S=`issues-status-${s.hash}`,g;e[31]!==s.status?(g=ss(s.status),e[31]=s.status,e[32]=g):g=e[32];let I;e[33]!==s.status||e[34]!==S||e[35]!==g?(I=(0,t.jsx)(z,{children:(0,t.jsx)(me,{"data-testid":S,variant:g,children:s.status})}),e[33]=s.status,e[34]=S,e[35]=g,e[36]=I):I=e[36];let j=s.severity??Se,r;e[37]!==a?(r=a("Set severity"),e[37]=a,e[38]=r):r=e[38];let oe=`issues-severity-${s.hash}`,V;e[39]!==a?(V=a("\u2014"),e[39]=a,e[40]=V):V=e[40];let N;e[41]!==s.severity||e[42]!==a?(N=s.severity===void 0?(0,t.jsx)("span",{className:"text-muted-foreground",children:a("\u2014")}):(0,t.jsx)(me,{variant:ts(s.severity),children:s.severity}),e[41]=s.severity,e[42]=a,e[43]=N):N=e[43];let C;e[44]!==V||e[45]!==N?(C=(0,t.jsx)(Ue,{placeholder:V,children:N}),e[44]=V,e[45]=N,e[46]=C):C=e[46];let q;e[47]!==r||e[48]!==oe||e[49]!==C?(q=(0,t.jsx)(We,{"aria-label":r,className:"h-7 w-[110px]","data-testid":oe,children:C}),e[47]=r,e[48]=oe,e[49]=C,e[50]=q):q=e[50];let de;e[51]===Symbol.for("react.memo_cache_sentinel")?(de=Pe.map(ls),e[51]=de):de=e[51];let W;e[52]!==a?(W=a("Clear"),e[52]=a,e[53]=W):W=e[53];let D;e[54]!==W?(D=(0,t.jsxs)(De,{children:[de,(0,t.jsx)(we,{value:Se,children:W})]}),e[54]=W,e[55]=D):D=e[55];let F;e[56]!==u||e[57]!==L||e[58]!==j||e[59]!==q||e[60]!==D?(F=(0,t.jsx)(z,{children:(0,t.jsxs)(Be,{disabled:u,onValueChange:L,value:j,children:[q,D]})}),e[56]=u,e[57]=L,e[58]=j,e[59]=q,e[60]=D,e[61]=F):F=e[61];let O;e[62]!==a?(O=a("Assignee"),e[62]=a,e[63]=O):O=e[63];let fe=`issues-assignee-${s.hash}`,xe=s.assignee??"",ve=s.assignee??"",G;e[64]!==a?(G=a("Unassigned"),e[64]=a,e[65]=G):G=e[65];let H;e[66]!==u||e[67]!==T||e[68]!==O||e[69]!==fe||e[70]!==xe||e[71]!==ve||e[72]!==G?(H=(0,t.jsx)(z,{children:(0,t.jsx)(ke,{"aria-label":O,className:"h-7 w-32","data-testid":fe,defaultValue:xe,disabled:u,onKeyDown:T,placeholder:G},ve)}),e[66]=u,e[67]=T,e[68]=O,e[69]=fe,e[70]=xe,e[71]=ve,e[72]=G,e[73]=H):H=e[73];let J;e[74]!==s.count?(J=(0,t.jsx)(z,{className:"text-right",children:(0,t.jsx)(me,{variant:"secondary",children:s.count})}),e[74]=s.count,e[75]=J):J=e[75];let P;e[76]!==s.lastSeen?(P=Te(s.lastSeen),e[76]=s.lastSeen,e[77]=P):P=e[77];let Q;e[78]!==P?(Q=(0,t.jsx)(z,{className:"text-xs tabular-nums text-muted-foreground",children:P}),e[78]=P,e[79]=Q):Q=e[79];let X;e[80]!==u||e[81]!==s.hash||e[82]!==s.status||e[83]!==i||e[84]!==a?(X=s.status!=="resolved"&&(0,t.jsx)(ie,{"data-testid":`issues-resolve-${s.hash}`,disabled:u,onClick:d(()=>{le(i(s.hash,Qe,{}))},"onClick"),size:"xs",variant:"outline",children:a("Resolve")}),e[80]=u,e[81]=s.hash,e[82]=s.status,e[83]=i,e[84]=a,e[85]=X):X=e[85];let Y;e[86]!==u||e[87]!==s.hash||e[88]!==s.status||e[89]!==i||e[90]!==a?(Y=s.status!=="ignored"&&(0,t.jsx)(ie,{"data-testid":`issues-ignore-${s.hash}`,disabled:u,onClick:d(()=>{le(i(s.hash,Xe,{}))},"onClick"),size:"xs",variant:"ghost",children:a("Ignore")}),e[86]=u,e[87]=s.hash,e[88]=s.status,e[89]=i,e[90]=a,e[91]=Y):Y=e[91];let Z;e[92]!==u||e[93]!==s.assignee||e[94]!==s.hash||e[95]!==s.status||e[96]!==i||e[97]!==a?(Z=s.status!=="open"&&(0,t.jsx)(ie,{"data-testid":`issues-reopen-${s.hash}`,disabled:u,onClick:d(()=>{le(i(s.hash,Fe,{assignee:s.assignee??null}))},"onClick"),size:"xs",variant:"ghost",children:a("Reopen")}),e[92]=u,e[93]=s.assignee,e[94]=s.hash,e[95]=s.status,e[96]=i,e[97]=a,e[98]=Z):Z=e[98];let ee;e[99]!==X||e[100]!==Y||e[101]!==Z?(ee=(0,t.jsx)(z,{className:"text-right",children:(0,t.jsxs)("div",{className:"flex justify-end gap-1",children:[X,Y,Z]})}),e[99]=X,e[100]=Y,e[101]=Z,e[102]=ee):ee=e[102];let se;e[103]!==c||e[104]!==I||e[105]!==F||e[106]!==H||e[107]!==J||e[108]!==Q||e[109]!==E||e[110]!==ee?(se=(0,t.jsxs)(pe,{"data-testid":E,children:[c,I,F,H,J,Q,ee]}),e[103]=c,e[104]=I,e[105]=F,e[106]=H,e[107]=J,e[108]=Q,e[109]=E,e[110]=ee,e[111]=se):se=e[111];let te;e[112]!==o||e[113]!==s||e[114]!==l?(te=(0,t.jsx)(as,{expanded:o,issue:s,shardKey:l},s.sampleMessage),e[112]=o,e[113]=s,e[114]=l,e[115]=te):te=e[115];let he;return e[116]!==se||e[117]!==te?(he=(0,t.jsxs)(t.Fragment,{children:[se,te]}),e[116]=se,e[117]=te,e[118]=he):he=e[118],he},"tt"),ks=d(n=>{let e=(0,ge.c)(38),{initialShardKey:u}=n,s=ue(),$=Ne(),{queryShardKey:i,setShardKey:l,shardKey:a}=Le(u),[o,_]=(0,ne.useState)("all"),[A,R]=(0,ne.useState)(ns),[K,L]=(0,ne.useState)(os),k;e[0]!==o?(k=o==="all"?{}:{status:o},e[0]=o,e[1]=k):k=e[1];let T;e[2]!==i?(T={live:!0,shardKey:i},e[2]=i,e[3]=T):T=e[3];let{data:E,error:h,liveError:x}=Ee(U.getIssues,k,T),M=E!==void 0,v;if(e[4]!==K||e[5]!==A||e[6]!==$||e[7]!==E||e[8]!==h||e[9]!==x||e[10]!==M||e[11]!==i||e[12]!==l||e[13]!==a||e[14]!==o||e[15]!==s){let y=es(E),b;e[17]!==$||e[18]!==i?(b=d(async(r,oe,V)=>{L(N=>{if(!N.has(r))return N;let C=new Map(N);return C.delete(r),C}),R(N=>new Set(N).add(r));try{await $.query(oe,{...V,hash:r},be(i))}catch(N){let C=Ke(N);L(q=>new Map(q).set(r,C))}R(N=>{let C=new Set(N);return C.delete(r),C})},"S"),e[17]=$,e[18]=i,e[19]=b):b=e[19];let w=b,m;e[20]!==s?(m=d(r=>s(r==="all"?"All":r==="open"?"Open":r==="resolved"?"Resolved":"Ignored"),"u"),e[20]=s,e[21]=m):m=e[21];let f=m,p;e[22]!==h?(p=h!==null&&(0,t.jsx)("p",{className:"text-sm text-destructive","data-testid":"issues-error",role:"alert",children:h}),e[22]=h,e[23]=p):p=e[23];let c;e[24]!==l||e[25]!==a?(c=(0,t.jsx)(_e,{onChange:l,testId:"issues-shard-input",value:a}),e[24]=l,e[25]=a,e[26]=c):c=e[26];let S;e[27]!==x?(S=(0,t.jsx)(qe,{message:x,prefix:"issues"}),e[27]=x,e[28]=S):S=e[28];let g;e[29]!==o||e[30]!==f?(g=Je.map(r=>(0,t.jsx)(ie,{"data-active":o===r?"":void 0,"data-testid":`issues-filter-${r}`,onClick:d(()=>{_(r)},"onClick"),size:"xs",variant:o===r?"default":"outline",children:f(r)},r)),e[29]=o,e[30]=f,e[31]=g):g=e[31];let I;e[32]!==g?(I=(0,t.jsx)("div",{className:"ms-auto flex items-center gap-1","data-testid":"issues-status-filter",role:"group",children:g}),e[32]=g,e[33]=I):I=e[33];let j;e[34]!==I||e[35]!==c||e[36]!==S?(j=(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[c,S,I]}),e[34]=I,e[35]=c,e[36]=S,e[37]=j):j=e[37],v=(0,t.jsxs)("div",{className:"flex flex-col gap-6","data-testid":"lunora-issues-panel",children:[p,j,M&&y.length===0?(0,t.jsx)(Ae,{description:s("No grouped errors yet. When a function throws or a container crashes, matching errors fold into a single issue here."),testId:"issues-empty",title:s("No issues")}):(0,t.jsx)(Me,{className:"overflow-hidden py-0",children:(0,t.jsx)(Ce,{className:"px-0",children:(0,t.jsxs)(ze,{"data-testid":"issues-table",children:[(0,t.jsx)(Re,{children:(0,t.jsxs)(pe,{children:[(0,t.jsx)(B,{children:s("Issue")}),(0,t.jsx)(B,{children:s("Status")}),(0,t.jsx)(B,{children:s("Severity")}),(0,t.jsx)(B,{children:s("Assignee")}),(0,t.jsx)(B,{className:"text-right",children:s("Events")}),(0,t.jsx)(B,{children:s("Last seen")}),(0,t.jsx)(B,{className:"text-right",children:s("Actions")})]})}),(0,t.jsx)(je,{children:y.map(r=>(0,t.jsx)(is,{busy:A.has(r.hash),issue:r,rowError:K.get(r.hash),runTriage:w,shardKey:i},r.hash))})]})})})]}),e[4]=K,e[5]=A,e[6]=$,e[7]=E,e[8]=h,e[9]=x,e[10]=M,e[11]=i,e[12]=l,e[13]=a,e[14]=o,e[15]=s,e[16]=v}else v=e[16];return v},"Tt");function rs(n){return!n}d(rs,"st");function ls(n){return(0,t.jsx)(we,{value:n,children:n},n)}d(ls,"at");function ns(){return new Set}d(ns,"it");function os(){return new Map}d(os,"lt");export{ks as default};
1
+ import{a as Be,b as Ue,c as We,d as De,e as we}from"./chunk-5QR2SQIS.js";import"./chunk-NRP22GKC.js";import"./chunk-OPM7ESDV.js";import{a as Ve}from"./chunk-OSGXNEFA.js";import{a as qe}from"./chunk-SV764LKQ.js";import"./chunk-NXQW5E6W.js";import"./chunk-UC7MNI2F.js";import"./chunk-NGVP66OH.js";import"./chunk-GHQ2VDI2.js";import{a as Le}from"./chunk-R6U22RSY.js";import{a as _e}from"./chunk-YVR4SEPU.js";import"./chunk-ZKJS6EBE.js";import"./chunk-RGMVGZV4.js";import{i as ke}from"./chunk-E4PXACVL.js";import"./chunk-MVWZMWPD.js";import"./chunk-SJQERRSZ.js";import"./chunk-7Y3SY37W.js";import{a as ie}from"./chunk-7G4Z6Q7X.js";import"./chunk-3YXASVTP.js";import"./chunk-AUAECCXB.js";import{b as me}from"./chunk-Q6ED4KUL.js";import"./chunk-BOMPSVRC.js";import"./chunk-55UGUCQ6.js";import{a as U}from"./chunk-4ZEL6BYL.js";import{c as Ee}from"./chunk-QUXXMJPZ.js";import{l as Ne}from"./chunk-BWKZ6FFW.js";import"./chunk-QAQDMS6R.js";import{b as Ie,c as $e}from"./chunk-DYR23C3V.js";import{a as Ae}from"./chunk-RWVIV3U7.js";import{a as ze,b as Re,c as je,d as pe,e as B,f as z}from"./chunk-HCTJKP5J.js";import{a as Me,e as Ce}from"./chunk-2IKDEUCX.js";import{d as ue,f as re,g as be,h as Ke,p as le,t as Te}from"./chunk-HJHSQPHW.js";import{a as d,d as ye,e as Oe,f as Ge,g as He}from"./chunk-I26MS5PJ.js";var ge=ye(Ge(),1);var ne=ye(Oe(),1);var t=ye(He(),1);var Se="none",Je=["all","open","resolved","ignored"],Pe=["critical","high","medium","low"],Qe=re(U.resolveIssue),Xe=re(U.ignoreIssue),Fe=re(U.assignIssue),Ye=re(U.setIssueSeverity),Ze=re(U.explainIssue),es=d(n=>Array.isArray(n?.issues)?n.issues:[],"Xe"),ss=d(n=>n==="resolved"?"success":n==="ignored"?"secondary":"warning","Je"),ts=d(n=>n==="critical"?"destructive":n==="high"?"warning":n==="medium"?"info":"secondary","Ze"),as=d(n=>{let e=(0,ge.c)(44),{expanded:u,issue:s,shardKey:$}=n,i=Ne(),l=ue(),[a,o]=(0,ne.useState)(void 0),{busy:_,error:A,run:R}=Ve(),K;e[0]!==i||e[1]!==s||e[2]!==R||e[3]!==$?(K=d(()=>{o(void 0),R(async()=>{let g={culprit:s.culprit,sampleMessage:s.sampleMessage,title:s.title},I=await i.query(Ze,g,be($));o(I)})},"C"),e[0]=i,e[1]=s,e[2]=R,e[3]=$,e[4]=K):K=e[4];let L=K;if(!u)return null;let k;if(e[5]!==s.sampleMessage){let g=$e(s.sampleMessage);k=g===void 0?void 0:Ie(g.body),e[5]=s.sampleMessage,e[6]=k}else k=e[6];let T=k,E=`issues-detail-${s.hash}`,h;e[7]!==s.sampleMessage?(h=(0,t.jsx)("p",{className:"whitespace-pre-wrap font-mono text-xs text-muted-foreground",children:s.sampleMessage}),e[7]=s.sampleMessage,e[8]=h):h=e[8];let x;e[9]!==l?(x=l("Suggested fix"),e[9]=l,e[10]=x):x=e[10];let M;e[11]!==x?(M=(0,t.jsx)("div",{className:"text-xs font-medium text-muted-foreground",children:x}),e[11]=x,e[12]=M):M=e[12];let v;e[13]!==T||e[14]!==s.hash||e[15]!==l?(v=T===void 0?(0,t.jsx)("p",{className:"mt-1 text-sm text-muted-foreground","data-testid":`issues-hint-empty-${s.hash}`,children:l("No known fix for this error yet.")}):(0,t.jsx)("p",{className:"mt-1 whitespace-pre-wrap text-sm","data-testid":`issues-hint-${s.hash}`,children:T}),e[13]=T,e[14]=s.hash,e[15]=l,e[16]=v):v=e[16];let y;e[17]!==M||e[18]!==v?(y=(0,t.jsxs)("div",{children:[M,v]}),e[17]=M,e[18]=v,e[19]=y):y=e[19];let b=`issues-explain-${s.hash}`,w;e[20]!==_||e[21]!==l?(w=l(_?"Explaining\u2026":"Explain in plain language"),e[20]=_,e[21]=l,e[22]=w):w=e[22];let m;e[23]!==_||e[24]!==L||e[25]!==w||e[26]!==b?(m=(0,t.jsx)("div",{children:(0,t.jsx)(ie,{"data-testid":b,disabled:_,onClick:L,size:"sm",type:"button",variant:"outline",children:w})}),e[23]=_,e[24]=L,e[25]=w,e[26]=b,e[27]=m):m=e[27];let f;e[28]!==A||e[29]!==s.hash?(f=A!==null&&(0,t.jsx)("p",{className:"text-xs text-destructive","data-testid":`issues-explain-error-${s.hash}`,role:"alert",children:A}),e[28]=A,e[29]=s.hash,e[30]=f):f=e[30];let p;e[31]!==a||e[32]!==s.hash||e[33]!==l?(p=a!==void 0&&(a.degraded?(0,t.jsx)("p",{className:"text-xs text-muted-foreground","data-testid":`issues-degraded-${s.hash}`,children:a.reason==="no-ai-binding"?l("No AI binding is configured. Wire an AI binding to enable plain-language explanations \u2014 the suggested fix above is always available."):l("The AI model could not explain this error right now. The suggested fix above still applies.")}):(0,t.jsxs)("div",{"data-testid":`issues-explanation-${s.hash}`,children:[(0,t.jsx)("div",{className:"text-xs font-medium text-muted-foreground",children:l("AI explanation")}),(0,t.jsx)("p",{className:"mt-1 whitespace-pre-wrap text-sm",children:a.explanation}),a.groundedId===void 0&&(0,t.jsx)("p",{className:"mt-1 text-xs text-muted-foreground","data-testid":`issues-ungrounded-${s.hash}`,children:l("No catalog fix matched this error, so this explanation is the model's own reading of the message. Verify before acting on it.")}),(0,t.jsx)("p",{className:"mt-1 text-[0.7rem] text-muted-foreground",children:l("Generated by {model}",{model:a.model})})]})),e[31]=a,e[32]=s.hash,e[33]=l,e[34]=p):p=e[34];let c;e[35]!==m||e[36]!==f||e[37]!==p||e[38]!==h||e[39]!==y?(c=(0,t.jsx)(z,{className:"bg-muted/30",colSpan:7,children:(0,t.jsxs)("div",{className:"flex flex-col gap-3 py-1",children:[h,y,m,f,p]})}),e[35]=m,e[36]=f,e[37]=p,e[38]=h,e[39]=y,e[40]=c):c=e[40];let S;return e[41]!==c||e[42]!==E?(S=(0,t.jsx)(pe,{"data-testid":E,children:c}),e[41]=c,e[42]=E,e[43]=S):S=e[43],S},"et"),is=d(n=>{let e=(0,ge.c)(119),{busy:u,issue:s,rowError:$,runTriage:i,shardKey:l}=n,a=ue(),[o,_]=(0,ne.useState)(!1),A;e[0]===Symbol.for("react.memo_cache_sentinel")?(A=d(()=>{_(rs)},"A"),e[0]=A):A=e[0];let R=A,K;e[1]!==s.hash||e[2]!==i?(K=d(ae=>{let ce=ae===null||ae===Se?null:ae;le(i(s.hash,Ye,{severity:ce}))},"C"),e[1]=s.hash,e[2]=i,e[3]=K):K=e[3];let L=K,k;e[4]!==s.hash||e[5]!==i?(k=d(ae=>{if(ae.key!=="Enter")return;let ce=ae.currentTarget.value.trim();le(i(s.hash,Fe,{assignee:ce===""?null:ce}))},"T"),e[4]=s.hash,e[5]=i,e[6]=k):k=e[6];let T=k,E=`issues-row-${s.hash}`,h;e[7]!==a?(h=a("Toggle issue details"),e[7]=a,e[8]=h):h=e[8];let x=`issues-toggle-${s.hash}`,M=`mt-1 size-3 shrink-0 text-muted-foreground transition-transform ${o?"rotate-90":""}`,v;e[9]===Symbol.for("react.memo_cache_sentinel")?(v=(0,t.jsx)("path",{d:"m9 6 6 6-6 6"}),e[9]=v):v=e[9];let y;e[10]!==M?(y=(0,t.jsx)("svg",{"aria-hidden":"true",className:M,fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,viewBox:"0 0 24 24",children:v}),e[10]=M,e[11]=y):y=e[11];let b;e[12]!==s.title?(b=(0,t.jsx)("span",{className:"block truncate font-medium",title:s.title,children:s.title}),e[12]=s.title,e[13]=b):b=e[13];let w;e[14]!==s.culprit?(w=(0,t.jsx)("span",{className:"block truncate font-mono text-xs text-muted-foreground",title:s.culprit,children:s.culprit}),e[14]=s.culprit,e[15]=w):w=e[15];let m;e[16]!==b||e[17]!==w?(m=(0,t.jsxs)("span",{className:"min-w-0",children:[b,w]}),e[16]=b,e[17]=w,e[18]=m):m=e[18];let f;e[19]!==o||e[20]!==m||e[21]!==h||e[22]!==x||e[23]!==y?(f=(0,t.jsxs)("button",{"aria-expanded":o,"aria-label":h,className:"flex w-full items-start gap-2 text-left","data-testid":x,onClick:R,type:"button",children:[y,m]}),e[19]=o,e[20]=m,e[21]=h,e[22]=x,e[23]=y,e[24]=f):f=e[24];let p;e[25]!==s.hash||e[26]!==$?(p=$!==void 0&&(0,t.jsx)("p",{className:"mt-1 text-xs text-destructive","data-testid":`issues-action-error-${s.hash}`,role:"alert",children:$}),e[25]=s.hash,e[26]=$,e[27]=p):p=e[27];let c;e[28]!==f||e[29]!==p?(c=(0,t.jsxs)(z,{className:"max-w-80",children:[f,p]}),e[28]=f,e[29]=p,e[30]=c):c=e[30];let S=`issues-status-${s.hash}`,g;e[31]!==s.status?(g=ss(s.status),e[31]=s.status,e[32]=g):g=e[32];let I;e[33]!==s.status||e[34]!==S||e[35]!==g?(I=(0,t.jsx)(z,{children:(0,t.jsx)(me,{"data-testid":S,variant:g,children:s.status})}),e[33]=s.status,e[34]=S,e[35]=g,e[36]=I):I=e[36];let j=s.severity??Se,r;e[37]!==a?(r=a("Set severity"),e[37]=a,e[38]=r):r=e[38];let oe=`issues-severity-${s.hash}`,V;e[39]!==a?(V=a("\u2014"),e[39]=a,e[40]=V):V=e[40];let N;e[41]!==s.severity||e[42]!==a?(N=s.severity===void 0?(0,t.jsx)("span",{className:"text-muted-foreground",children:a("\u2014")}):(0,t.jsx)(me,{variant:ts(s.severity),children:s.severity}),e[41]=s.severity,e[42]=a,e[43]=N):N=e[43];let C;e[44]!==V||e[45]!==N?(C=(0,t.jsx)(Ue,{placeholder:V,children:N}),e[44]=V,e[45]=N,e[46]=C):C=e[46];let q;e[47]!==r||e[48]!==oe||e[49]!==C?(q=(0,t.jsx)(We,{"aria-label":r,className:"h-7 w-[110px]","data-testid":oe,children:C}),e[47]=r,e[48]=oe,e[49]=C,e[50]=q):q=e[50];let de;e[51]===Symbol.for("react.memo_cache_sentinel")?(de=Pe.map(ls),e[51]=de):de=e[51];let W;e[52]!==a?(W=a("Clear"),e[52]=a,e[53]=W):W=e[53];let D;e[54]!==W?(D=(0,t.jsxs)(De,{children:[de,(0,t.jsx)(we,{value:Se,children:W})]}),e[54]=W,e[55]=D):D=e[55];let F;e[56]!==u||e[57]!==L||e[58]!==j||e[59]!==q||e[60]!==D?(F=(0,t.jsx)(z,{children:(0,t.jsxs)(Be,{disabled:u,onValueChange:L,value:j,children:[q,D]})}),e[56]=u,e[57]=L,e[58]=j,e[59]=q,e[60]=D,e[61]=F):F=e[61];let O;e[62]!==a?(O=a("Assignee"),e[62]=a,e[63]=O):O=e[63];let fe=`issues-assignee-${s.hash}`,xe=s.assignee??"",ve=s.assignee??"",G;e[64]!==a?(G=a("Unassigned"),e[64]=a,e[65]=G):G=e[65];let H;e[66]!==u||e[67]!==T||e[68]!==O||e[69]!==fe||e[70]!==xe||e[71]!==ve||e[72]!==G?(H=(0,t.jsx)(z,{children:(0,t.jsx)(ke,{"aria-label":O,className:"h-7 w-32","data-testid":fe,defaultValue:xe,disabled:u,onKeyDown:T,placeholder:G},ve)}),e[66]=u,e[67]=T,e[68]=O,e[69]=fe,e[70]=xe,e[71]=ve,e[72]=G,e[73]=H):H=e[73];let J;e[74]!==s.count?(J=(0,t.jsx)(z,{className:"text-right",children:(0,t.jsx)(me,{variant:"secondary",children:s.count})}),e[74]=s.count,e[75]=J):J=e[75];let P;e[76]!==s.lastSeen?(P=Te(s.lastSeen),e[76]=s.lastSeen,e[77]=P):P=e[77];let Q;e[78]!==P?(Q=(0,t.jsx)(z,{className:"text-xs tabular-nums text-muted-foreground",children:P}),e[78]=P,e[79]=Q):Q=e[79];let X;e[80]!==u||e[81]!==s.hash||e[82]!==s.status||e[83]!==i||e[84]!==a?(X=s.status!=="resolved"&&(0,t.jsx)(ie,{"data-testid":`issues-resolve-${s.hash}`,disabled:u,onClick:d(()=>{le(i(s.hash,Qe,{}))},"onClick"),size:"xs",variant:"outline",children:a("Resolve")}),e[80]=u,e[81]=s.hash,e[82]=s.status,e[83]=i,e[84]=a,e[85]=X):X=e[85];let Y;e[86]!==u||e[87]!==s.hash||e[88]!==s.status||e[89]!==i||e[90]!==a?(Y=s.status!=="ignored"&&(0,t.jsx)(ie,{"data-testid":`issues-ignore-${s.hash}`,disabled:u,onClick:d(()=>{le(i(s.hash,Xe,{}))},"onClick"),size:"xs",variant:"ghost",children:a("Ignore")}),e[86]=u,e[87]=s.hash,e[88]=s.status,e[89]=i,e[90]=a,e[91]=Y):Y=e[91];let Z;e[92]!==u||e[93]!==s.assignee||e[94]!==s.hash||e[95]!==s.status||e[96]!==i||e[97]!==a?(Z=s.status!=="open"&&(0,t.jsx)(ie,{"data-testid":`issues-reopen-${s.hash}`,disabled:u,onClick:d(()=>{le(i(s.hash,Fe,{assignee:s.assignee??null}))},"onClick"),size:"xs",variant:"ghost",children:a("Reopen")}),e[92]=u,e[93]=s.assignee,e[94]=s.hash,e[95]=s.status,e[96]=i,e[97]=a,e[98]=Z):Z=e[98];let ee;e[99]!==X||e[100]!==Y||e[101]!==Z?(ee=(0,t.jsx)(z,{className:"text-right",children:(0,t.jsxs)("div",{className:"flex justify-end gap-1",children:[X,Y,Z]})}),e[99]=X,e[100]=Y,e[101]=Z,e[102]=ee):ee=e[102];let se;e[103]!==c||e[104]!==I||e[105]!==F||e[106]!==H||e[107]!==J||e[108]!==Q||e[109]!==E||e[110]!==ee?(se=(0,t.jsxs)(pe,{"data-testid":E,children:[c,I,F,H,J,Q,ee]}),e[103]=c,e[104]=I,e[105]=F,e[106]=H,e[107]=J,e[108]=Q,e[109]=E,e[110]=ee,e[111]=se):se=e[111];let te;e[112]!==o||e[113]!==s||e[114]!==l?(te=(0,t.jsx)(as,{expanded:o,issue:s,shardKey:l},s.sampleMessage),e[112]=o,e[113]=s,e[114]=l,e[115]=te):te=e[115];let he;return e[116]!==se||e[117]!==te?(he=(0,t.jsxs)(t.Fragment,{children:[se,te]}),e[116]=se,e[117]=te,e[118]=he):he=e[118],he},"tt"),ks=d(n=>{let e=(0,ge.c)(38),{initialShardKey:u}=n,s=ue(),$=Ne(),{queryShardKey:i,setShardKey:l,shardKey:a}=Le(u),[o,_]=(0,ne.useState)("all"),[A,R]=(0,ne.useState)(ns),[K,L]=(0,ne.useState)(os),k;e[0]!==o?(k=o==="all"?{}:{status:o},e[0]=o,e[1]=k):k=e[1];let T;e[2]!==i?(T={live:!0,shardKey:i},e[2]=i,e[3]=T):T=e[3];let{data:E,error:h,liveError:x}=Ee(U.getIssues,k,T),M=E!==void 0,v;if(e[4]!==K||e[5]!==A||e[6]!==$||e[7]!==E||e[8]!==h||e[9]!==x||e[10]!==M||e[11]!==i||e[12]!==l||e[13]!==a||e[14]!==o||e[15]!==s){let y=es(E),b;e[17]!==$||e[18]!==i?(b=d(async(r,oe,V)=>{L(N=>{if(!N.has(r))return N;let C=new Map(N);return C.delete(r),C}),R(N=>new Set(N).add(r));try{await $.query(oe,{...V,hash:r},be(i))}catch(N){let C=Ke(N);L(q=>new Map(q).set(r,C))}R(N=>{let C=new Set(N);return C.delete(r),C})},"S"),e[17]=$,e[18]=i,e[19]=b):b=e[19];let w=b,m;e[20]!==s?(m=d(r=>s(r==="all"?"All":r==="open"?"Open":r==="resolved"?"Resolved":"Ignored"),"u"),e[20]=s,e[21]=m):m=e[21];let f=m,p;e[22]!==h?(p=h!==null&&(0,t.jsx)("p",{className:"text-sm text-destructive","data-testid":"issues-error",role:"alert",children:h}),e[22]=h,e[23]=p):p=e[23];let c;e[24]!==l||e[25]!==a?(c=(0,t.jsx)(_e,{onChange:l,testId:"issues-shard-input",value:a}),e[24]=l,e[25]=a,e[26]=c):c=e[26];let S;e[27]!==x?(S=(0,t.jsx)(qe,{message:x,prefix:"issues"}),e[27]=x,e[28]=S):S=e[28];let g;e[29]!==o||e[30]!==f?(g=Je.map(r=>(0,t.jsx)(ie,{"data-active":o===r?"":void 0,"data-testid":`issues-filter-${r}`,onClick:d(()=>{_(r)},"onClick"),size:"xs",variant:o===r?"default":"outline",children:f(r)},r)),e[29]=o,e[30]=f,e[31]=g):g=e[31];let I;e[32]!==g?(I=(0,t.jsx)("div",{className:"ms-auto flex items-center gap-1","data-testid":"issues-status-filter",role:"group",children:g}),e[32]=g,e[33]=I):I=e[33];let j;e[34]!==I||e[35]!==c||e[36]!==S?(j=(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[c,S,I]}),e[34]=I,e[35]=c,e[36]=S,e[37]=j):j=e[37],v=(0,t.jsxs)("div",{className:"flex flex-col gap-6","data-testid":"lunora-issues-panel",children:[p,j,M&&y.length===0?(0,t.jsx)(Ae,{description:s("No grouped errors yet. When a function throws or a container crashes, matching errors fold into a single issue here."),testId:"issues-empty",title:s("No issues")}):(0,t.jsx)(Me,{className:"overflow-hidden py-0",children:(0,t.jsx)(Ce,{className:"px-0",children:(0,t.jsxs)(ze,{"data-testid":"issues-table",children:[(0,t.jsx)(Re,{children:(0,t.jsxs)(pe,{children:[(0,t.jsx)(B,{children:s("Issue")}),(0,t.jsx)(B,{children:s("Status")}),(0,t.jsx)(B,{children:s("Severity")}),(0,t.jsx)(B,{children:s("Assignee")}),(0,t.jsx)(B,{className:"text-right",children:s("Events")}),(0,t.jsx)(B,{children:s("Last seen")}),(0,t.jsx)(B,{className:"text-right",children:s("Actions")})]})}),(0,t.jsx)(je,{children:y.map(r=>(0,t.jsx)(is,{busy:A.has(r.hash),issue:r,rowError:K.get(r.hash),runTriage:w,shardKey:i},r.hash))})]})})})]}),e[4]=K,e[5]=A,e[6]=$,e[7]=E,e[8]=h,e[9]=x,e[10]=M,e[11]=i,e[12]=l,e[13]=a,e[14]=o,e[15]=s,e[16]=v}else v=e[16];return v},"Tt");function rs(n){return!n}d(rs,"st");function ls(n){return(0,t.jsx)(we,{value:n,children:n},n)}d(ls,"at");function ns(){return new Set}d(ns,"it");function os(){return new Map}d(os,"lt");export{ks as default};
@@ -1 +1 @@
1
- import{a as Ce,b as Ne}from"./chunk-EEDIMNRC.js";import{a as ye}from"./chunk-R6PJYMJT.js";import"./chunk-TIQ7OBZJ.js";import"./chunk-AUGKHAMQ.js";import"./chunk-WJRYEML4.js";import{e as ke,g as we}from"./chunk-RGMVGZV4.js";import"./chunk-SJQERRSZ.js";import"./chunk-7Y3SY37W.js";import{a as X}from"./chunk-7G4Z6Q7X.js";import"./chunk-3YXASVTP.js";import"./chunk-AUAECCXB.js";import"./chunk-BOMPSVRC.js";import{a as le}from"./chunk-NCPW7WHO.js";import{a as pe}from"./chunk-4ZEL6BYL.js";import"./chunk-DSIY2CMT.js";import{l as he}from"./chunk-BOYS4DOC.js";import"./chunk-QAQDMS6R.js";import"./chunk-N7LJO732.js";import{a as me}from"./chunk-RWVIV3U7.js";import"./chunk-HCTJKP5J.js";import{a as oe,b as ue,c as ge,e as ae}from"./chunk-2IKDEUCX.js";import{d as te,f as ve,g as be,h as fe,o as xe,p as ne}from"./chunk-HJHSQPHW.js";import{a as g,d as ie,e as Se,f as Ke,g as Le}from"./chunk-I26MS5PJ.js";var Y=ie(Ke(),1),G=ie(Se(),1);var a=ie(Le(),1);var Me=ve(pe.runSql),qe=g((f,e)=>{let t=(0,Y.c)(11),n=he(),[l,d]=(0,G.useState)(void 0),[s,i]=(0,G.useState)(void 0),[h,x]=(0,G.useState)(!0),m;t[0]!==n||t[1]!==e||t[2]!==f?(m=g(async u=>{x(!0);try{let C=await n.query(Me,{sql:f},be(e));u.cancelled||(d(C),i(void 0))}catch(C){let k=C;u.cancelled||(d(void 0),i(fe(k)))}u.cancelled||x(!1)},"h"),t[0]=n,t[1]=e,t[2]=f,t[3]=m):m=t[3];let r=m,o,v;t[4]!==r?(o=g(()=>{let u={cancelled:!1};return ne(r(u)),()=>{u.cancelled=!0}},"l"),v=[r],t[4]=r,t[5]=o,t[6]=v):(o=t[5],v=t[6]),(0,G.useEffect)(o,v);let S;return t[7]!==s||t[8]!==h||t[9]!==l?(S={error:s,loading:h,result:l},t[7]=s,t[8]=h,t[9]=l,t[10]=S):S=t[10],S},"Le"),Ee=g(f=>{f.preventDefault()},"Me"),ce=g(f=>f.kind??"chart","le"),Re=g(f=>{let e=(0,Y.c)(80),{actions:t,children:n,draggedRef:l,first:d,last:s,onEdit:i,onMove:h,onRemove:x,onReorder:m,widget:r}=f,o=te(),v;e[0]!==h||e[1]!==r.id?(v=g(()=>{h(r.id,-1)},"g"),e[0]=h,e[1]=r.id,e[2]=v):v=e[2];let S=v,u;e[3]!==h||e[4]!==r.id?(u=g(()=>{h(r.id,1)},"f"),e[3]=h,e[4]=r.id,e[5]=u):u=e[5];let C=u,k;e[6]!==i||e[7]!==r.id?(k=g(()=>{i(r.id)},"x"),e[6]=i,e[7]=r.id,e[8]=k):k=e[8];let E=k,O;e[9]!==x||e[10]!==r.id?(O=g(()=>{x(r.id)},"O"),e[9]=x,e[10]=r.id,e[11]=O):O=e[11];let j=O,T;e[12]!==l||e[13]!==r.id?(T=g(()=>{l.current=r.id},"z"),e[12]=l,e[13]=r.id,e[14]=T):T=e[14];let w=T,K;e[15]!==l||e[16]!==m||e[17]!==r.id?(K=g(()=>{let de=l.current;l.current=null,de!==null&&de!==r.id&&m(de,r.id)},"K"),e[15]=l,e[16]=m,e[17]=r.id,e[18]=K):K=e[18];let _=K,R=`dashboards-widget-${r.id}`,y;e[19]!==r.title?(y=(0,a.jsx)(ge,{className:"min-w-0 cursor-grab truncate",title:r.title,children:r.title}),e[19]=r.title,e[20]=y):y=e[20];let N;e[21]!==o?(N=o("Move widget up"),e[21]=o,e[22]=N):N=e[22];let F=`dashboards-move-up-${r.id}`,H;e[23]!==o?(H=o("Move widget up"),e[23]=o,e[24]=H):H=e[24];let D;e[25]===Symbol.for("react.memo_cache_sentinel")?(D=(0,a.jsx)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,a.jsx)("path",{d:"m6 15 6-6 6 6"})}),e[25]=D):D=e[25];let W;e[26]!==d||e[27]!==S||e[28]!==F||e[29]!==H||e[30]!==N?(W=(0,a.jsx)(X,{"aria-label":N,"data-testid":F,disabled:d,onClick:S,size:"icon-xs",title:H,type:"button",variant:"ghost",children:D}),e[26]=d,e[27]=S,e[28]=F,e[29]=H,e[30]=N,e[31]=W):W=e[31];let L;e[32]!==o?(L=o("Move widget down"),e[32]=o,e[33]=L):L=e[33];let $=`dashboards-move-down-${r.id}`,M;e[34]!==o?(M=o("Move widget down"),e[34]=o,e[35]=M):M=e[35];let z;e[36]===Symbol.for("react.memo_cache_sentinel")?(z=(0,a.jsx)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,a.jsx)("path",{d:"m6 9 6 6 6-6"})}),e[36]=z):z=e[36];let q;e[37]!==s||e[38]!==C||e[39]!==L||e[40]!==$||e[41]!==M?(q=(0,a.jsx)(X,{"aria-label":L,"data-testid":$,disabled:s,onClick:C,size:"icon-xs",title:M,type:"button",variant:"ghost",children:z}),e[37]=s,e[38]=C,e[39]=L,e[40]=$,e[41]=M,e[42]=q):q=e[42];let B;e[43]!==o?(B=o("Edit widget"),e[43]=o,e[44]=B):B=e[44];let I=`dashboards-widget-edit-${r.id}`,A;e[45]!==o?(A=o("Edit widget"),e[45]=o,e[46]=A):A=e[46];let p;e[47]===Symbol.for("react.memo_cache_sentinel")?(p=(0,a.jsx)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,a.jsx)("path",{d:"M4 20h4L18 10l-4-4L4 16v4ZM14 6l4 4"})}),e[47]=p):p=e[47];let b;e[48]!==E||e[49]!==B||e[50]!==I||e[51]!==A?(b=(0,a.jsx)(X,{"aria-label":B,"data-testid":I,onClick:E,size:"icon-xs",title:A,type:"button",variant:"ghost",children:p}),e[48]=E,e[49]=B,e[50]=I,e[51]=A,e[52]=b):b=e[52];let c;e[53]!==o?(c=o("Remove widget"),e[53]=o,e[54]=c):c=e[54];let J=`dashboards-widget-remove-${r.id}`,V;e[55]!==o?(V=o("Remove widget"),e[55]=o,e[56]=V):V=e[56];let U;e[57]===Symbol.for("react.memo_cache_sentinel")?(U=(0,a.jsx)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,a.jsx)("path",{d:"M5 7h14M9 7V5h6v2m-1 0v12H10V7M7 7v13h10V7"})}),e[57]=U):U=e[57];let Q;e[58]!==j||e[59]!==c||e[60]!==J||e[61]!==V?(Q=(0,a.jsx)(X,{"aria-label":c,"data-testid":J,onClick:j,size:"icon-xs",title:V,type:"button",variant:"ghost",children:U}),e[58]=j,e[59]=c,e[60]=J,e[61]=V,e[62]=Q):Q=e[62];let Z;e[63]!==t||e[64]!==W||e[65]!==q||e[66]!==b||e[67]!==Q?(Z=(0,a.jsxs)("div",{className:"flex shrink-0 items-center gap-1",children:[t,W,q,b,Q]}),e[63]=t,e[64]=W,e[65]=q,e[66]=b,e[67]=Q,e[68]=Z):Z=e[68];let P;e[69]!==Z||e[70]!==y?(P=(0,a.jsxs)(ue,{className:"flex flex-row items-start justify-between gap-2 border-b pb-3",children:[y,Z]}),e[69]=Z,e[70]=y,e[71]=P):P=e[71];let ee;e[72]!==n?(ee=(0,a.jsx)(ae,{className:"min-h-32 py-2",children:n}),e[72]=n,e[73]=ee):ee=e[73];let re;return e[74]!==w||e[75]!==_||e[76]!==P||e[77]!==ee||e[78]!==R?(re=(0,a.jsxs)(oe,{"data-testid":R,draggable:!0,onDragOver:Ee,onDragStart:w,onDrop:_,children:[P,ee]}),e[74]=w,e[75]=_,e[76]=P,e[77]=ee,e[78]=R,e[79]=re):re=e[79],re},"ce"),je=g(f=>{let e=(0,Y.c)(10),{result:t}=f,n=te(),l=t.columns[0],d=l===void 0?void 0:t.rows[0]?.[l],s;e[0]!==d||e[1]!==n?(s=d===void 0?n("\u2014"):xe(d),e[0]=d,e[1]=n,e[2]=s):s=e[2];let i;e[3]!==s?(i=(0,a.jsx)("p",{className:"truncate font-mono text-3xl font-semibold text-foreground",children:s}),e[3]=s,e[4]=i):i=e[4];let h;e[5]!==l?(h=l!==void 0&&(0,a.jsx)("p",{className:"truncate text-xs text-muted-foreground",children:l}),e[5]=l,e[6]=h):h=e[6];let x;return e[7]!==i||e[8]!==h?(x=(0,a.jsxs)("div",{className:"flex h-full flex-col justify-center gap-1 p-4","data-testid":"dashboards-kpi",children:[i,h]}),e[7]=i,e[8]=h,e[9]=x):x=e[9],x},"qe"),ze=g(f=>{let e=(0,Y.c)(12),{draggedRef:t,first:n,last:l,onEdit:d,onMove:s,onRemove:i,onReorder:h,widget:x}=f,m=x.text??"",r;e[0]!==m?(r=(0,a.jsx)("p",{className:"p-2 text-sm whitespace-pre-wrap text-muted-foreground","data-testid":"dashboards-text",children:m}),e[0]=m,e[1]=r):r=e[1];let o;return e[2]!==t||e[3]!==n||e[4]!==l||e[5]!==d||e[6]!==s||e[7]!==i||e[8]!==h||e[9]!==r||e[10]!==x?(o=(0,a.jsx)(Re,{draggedRef:t,first:n,last:l,onEdit:d,onMove:s,onRemove:i,onReorder:h,widget:x,children:r}),e[2]=t,e[3]=n,e[4]=l,e[5]=d,e[6]=s,e[7]=i,e[8]=h,e[9]=r,e[10]=x,e[11]=o):o=e[11],o},"Ee"),Ae=g(f=>{let e=(0,Y.c)(52),{draggedRef:t,first:n,inferring:l,last:d,onEdit:s,onMove:i,onRemove:h,onReorder:x,onSuggest:m,widget:r}=f,o=te(),{error:v,loading:S,result:u}=qe(r.sql,r.shardKey??""),C;e[0]!==r?(C=ce(r),e[0]=r,e[1]=C):C=e[1];let k=C,E;e[2]!==m||e[3]!==u||e[4]!==r.id?(E=g(()=>{u!==void 0&&m?.(r.id,u)},"q"),e[2]=m,e[3]=u,e[4]=r.id,e[5]=E):E=e[5];let O=E,j;e[6]!==l||e[7]!==k||e[8]!==m||e[9]!==O||e[10]!==u||e[11]!==o||e[12]!==r.id?(j=k==="chart"&&m!==void 0&&u!==void 0?(0,a.jsx)(X,{"aria-label":o("Suggest chart"),"data-testid":`dashboards-widget-suggest-${r.id}`,disabled:l,onClick:O,size:"icon-xs",title:o(l?"Suggesting\u2026":"Suggest chart"),type:"button",variant:"ghost",children:(0,a.jsx)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,a.jsx)("path",{d:"m12 3 1.9 4.6L18.5 9.5 13.9 11.4 12 16l-1.9-4.6L5.5 9.5l4.6-1.9L12 3ZM18 15l.9 2.1 2.1.9-2.1.9L18 21l-.9-2.1-2.1-.9 2.1-.9L18 15Z"})})}):void 0,e[6]=l,e[7]=k,e[8]=m,e[9]=O,e[10]=u,e[11]=o,e[12]=r.id,e[13]=j):j=e[13];let T=j,w;e[14]!==v||e[15]!==r.id?(w=v!==void 0&&(0,a.jsx)(le,{className:"font-mono text-xs",testId:`dashboards-widget-error-${r.id}`,variant:"destructive",children:v}),e[14]=v,e[15]=r.id,e[16]=w):w=e[16];let K;e[17]!==v||e[18]!==S||e[19]!==u||e[20]!==o||e[21]!==r.id?(K=v===void 0&&S&&u===void 0&&(0,a.jsx)("p",{className:"p-4 text-sm text-muted-foreground","data-testid":`dashboards-widget-loading-${r.id}`,children:o("Running\u2026")}),e[17]=v,e[18]=S,e[19]=u,e[20]=o,e[21]=r.id,e[22]=K):K=e[22];let _;e[23]!==v||e[24]!==k||e[25]!==u||e[26]!==r.chartAxes||e[27]!==r.chartKind?(_=v===void 0&&u!==void 0&&k==="chart"&&(0,a.jsx)(Ce,{axes:r.chartAxes,kind:r.chartKind,result:u}),e[23]=v,e[24]=k,e[25]=u,e[26]=r.chartAxes,e[27]=r.chartKind,e[28]=_):_=e[28];let R;e[29]!==v||e[30]!==k||e[31]!==u?(R=v===void 0&&u!==void 0&&k==="kpi"&&(0,a.jsx)(je,{result:u}),e[29]=v,e[30]=k,e[31]=u,e[32]=R):R=e[32];let y;e[33]!==v||e[34]!==k||e[35]!==u?(y=v===void 0&&u!==void 0&&k==="table"&&(0,a.jsx)("div",{className:"max-h-72 overflow-auto",children:(0,a.jsx)(Ne,{result:u})}),e[33]=v,e[34]=k,e[35]=u,e[36]=y):y=e[36];let N;return e[37]!==t||e[38]!==n||e[39]!==d||e[40]!==s||e[41]!==i||e[42]!==h||e[43]!==x||e[44]!==T||e[45]!==w||e[46]!==K||e[47]!==_||e[48]!==R||e[49]!==y||e[50]!==r?(N=(0,a.jsxs)(Re,{actions:T,draggedRef:t,first:n,last:d,onEdit:s,onMove:i,onRemove:h,onReorder:x,widget:r,children:[w,K,_,R,y]}),e[37]=t,e[38]=n,e[39]=d,e[40]=s,e[41]=i,e[42]=h,e[43]=x,e[44]=T,e[45]=w,e[46]=K,e[47]=_,e[48]=R,e[49]=y,e[50]=r,e[51]=N):N=e[51],N},"Ae"),_e=g(f=>{let e=(0,Y.c)(11),{draggedRef:t,first:n,inferring:l,last:d,onEdit:s,onMove:i,onRemove:h,onReorder:x,onSuggest:m,widget:r}=f,o;return e[0]!==t||e[1]!==n||e[2]!==l||e[3]!==d||e[4]!==s||e[5]!==i||e[6]!==h||e[7]!==x||e[8]!==m||e[9]!==r?(o=ce(r)==="text"?(0,a.jsx)(ze,{draggedRef:t,first:n,last:d,onEdit:s,onMove:i,onRemove:h,onReorder:x,widget:r}):(0,a.jsx)(Ae,{draggedRef:t,first:n,inferring:l,last:d,onEdit:s,onMove:i,onRemove:h,onReorder:x,onSuggest:m,widget:r}),e[0]=t,e[1]=n,e[2]=l,e[3]=d,e[4]=s,e[5]=i,e[6]=h,e[7]=x,e[8]=m,e[9]=r,e[10]=o):o=e[10],o},"Te"),We=["bar","line","area"],$e=["chart","kpi","table","text"],Be="lunora-studio-dashboards",se={chartKind:"bar",kind:"chart",shardKey:"",sql:"",text:"",title:""},Ie=g((f,e)=>t=>t.map(n=>n.id===f?{...n,chartAxes:e,chartKind:e.kind}:n),"De"),Te=g((f,e)=>t=>{let n=t.find(s=>s.id===f),l=t.filter(s=>s.id!==f),d=l.findIndex(s=>s.id===e);return n===void 0||d===-1?t:[...l.slice(0,d),n,...l.slice(d)]},"je"),De=g((f,e)=>e(f==="line"?"Line":f==="area"?"Area":"Bar"),"ze"),Oe=g((f,e)=>e(f==="kpi"?"Single value":f==="table"?"Table":f==="text"?"Text":"Chart"),"Be"),Fe=g(f=>{let e=(0,Y.c)(82),{draft:t,editing:n,onCancel:l,onChange:d,onSubmit:s}=f,i=te(),h;e[0]!==t||e[1]!==d?(h=g(c=>{d({...t,title:c.target.value})},"c"),e[0]=t,e[1]=d,e[2]=h):h=e[2];let x=h,m;e[3]!==t||e[4]!==d?(m=g(c=>{d({...t,sql:c.target.value})},"h"),e[3]=t,e[4]=d,e[5]=m):m=e[5];let r=m,o;e[6]!==t||e[7]!==d?(o=g(c=>{d({...t,text:c.target.value})},"l"),e[6]=t,e[7]=d,e[8]=o):o=e[8];let v=o,S;e[9]!==t||e[10]!==d?(S=g(c=>{d({...t,shardKey:c.target.value})},"N"),e[9]=t,e[10]=d,e[11]=S):S=e[11];let u=S,C;e[12]!==t||e[13]!==d?(C=g(c=>{d({...t,chartKind:c.target.value})},"y"),e[12]=t,e[13]=d,e[14]=C):C=e[14];let k=C,E;e[15]!==t||e[16]!==d?(E=g(c=>{d({...t,kind:c.target.value})},"q"),e[15]=t,e[16]=d,e[17]=E):E=e[17];let O=E,j;e[18]!==s?(j=g(()=>{s()},"E"),e[18]=s,e[19]=j):j=e[19];let T=j,w=t.kind==="text",K;e[20]!==t.sql||e[21]!==t.text||e[22]!==t.title||e[23]!==w?(K=t.title.trim()!==""&&(w?t.text.trim()!=="":t.sql.trim()!==""),e[20]=t.sql,e[21]=t.text,e[22]=t.title,e[23]=w,e[24]=K):K=e[24];let _=K,R;e[25]!==i?(R=i("Widget title"),e[25]=i,e[26]=R):R=e[26];let y;e[27]!==i?(y=i("Widget title"),e[27]=i,e[28]=y):y=e[28];let N;e[29]!==t.title||e[30]!==x||e[31]!==y||e[32]!==R?(N=(0,a.jsx)("input",{"aria-label":R,className:"h-8 rounded-md border border-border bg-background px-2 text-xs outline-none focus-visible:border-ring","data-testid":"dashboards-form-title",onChange:x,placeholder:y,type:"text",value:t.title}),e[29]=t.title,e[30]=x,e[31]=y,e[32]=R,e[33]=N):N=e[33];let F;e[34]!==i?(F=i("Widget type"),e[34]=i,e[35]=F):F=e[35];let H=t.kind,D;e[36]!==i?(D=$e.map(c=>(0,a.jsx)("option",{value:c,children:Oe(c,i)},c)),e[36]=i,e[37]=D):D=e[37];let W;e[38]!==t.kind||e[39]!==O||e[40]!==F||e[41]!==D?(W=(0,a.jsx)("select",{"aria-label":F,className:"h-8 rounded-md border border-border bg-background px-2 text-xs outline-none focus-visible:border-ring","data-testid":"dashboards-form-widget-kind",onChange:O,value:H,children:D}),e[38]=t.kind,e[39]=O,e[40]=F,e[41]=D,e[42]=W):W=e[42];let L;e[43]!==t.sql||e[44]!==t.text||e[45]!==w||e[46]!==r||e[47]!==v||e[48]!==i?(L=w?(0,a.jsx)("textarea",{"aria-label":i("Text"),className:"min-h-24 resize-y rounded-md border border-border bg-background p-2 text-xs leading-5 outline-none focus-visible:border-ring","data-testid":"dashboards-form-text",onChange:v,placeholder:i("Notes for whoever reads this dashboard."),value:t.text}):(0,a.jsx)("textarea",{"aria-label":i("SQL query"),className:"min-h-24 resize-y rounded-md border border-border bg-background p-2 font-mono text-xs leading-5 outline-none focus-visible:border-ring","data-testid":"dashboards-form-sql",onChange:r,placeholder:"SELECT author, COUNT(*) AS messages FROM \u2026",spellCheck:!1,value:t.sql}),e[43]=t.sql,e[44]=t.text,e[45]=w,e[46]=r,e[47]=v,e[48]=i,e[49]=L):L=e[49];let $;e[50]!==t.chartKind||e[51]!==t.kind||e[52]!==k||e[53]!==i?($=t.kind==="chart"&&(0,a.jsx)("select",{"aria-label":i("Chart type"),className:"h-8 rounded-md border border-border bg-background px-2 text-xs outline-none focus-visible:border-ring","data-testid":"dashboards-form-kind",onChange:k,value:t.chartKind,children:We.map(c=>(0,a.jsx)("option",{value:c,children:De(c,i)},c))}),e[50]=t.chartKind,e[51]=t.kind,e[52]=k,e[53]=i,e[54]=$):$=e[54];let M;e[55]!==t.shardKey||e[56]!==w||e[57]!==u||e[58]!==i?(M=!w&&(0,a.jsx)("input",{"aria-label":i("Shard key (optional)"),className:"h-8 rounded-md border border-border bg-background px-2 font-mono text-xs outline-none focus-visible:border-ring","data-testid":"dashboards-form-shard",onChange:u,placeholder:i("Shard key (optional)"),type:"text",value:t.shardKey}),e[55]=t.shardKey,e[56]=w,e[57]=u,e[58]=i,e[59]=M):M=e[59];let z;e[60]!==i?(z=i("Cancel"),e[60]=i,e[61]=z):z=e[61];let q;e[62]!==l||e[63]!==z?(q=(0,a.jsx)(X,{"data-testid":"dashboards-form-cancel",onClick:l,size:"sm",type:"button",variant:"outline",children:z}),e[62]=l,e[63]=z,e[64]=q):q=e[64];let B=!_,I;e[65]!==n||e[66]!==i?(I=i(n?"Save widget":"Add widget"),e[65]=n,e[66]=i,e[67]=I):I=e[67];let A;e[68]!==T||e[69]!==B||e[70]!==I?(A=(0,a.jsx)(X,{"data-testid":"dashboards-form-save",disabled:B,onClick:T,size:"sm",type:"button",children:I}),e[68]=T,e[69]=B,e[70]=I,e[71]=A):A=e[71];let p;e[72]!==q||e[73]!==A?(p=(0,a.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[q,A]}),e[72]=q,e[73]=A,e[74]=p):p=e[74];let b;return e[75]!==N||e[76]!==W||e[77]!==L||e[78]!==$||e[79]!==M||e[80]!==p?(b=(0,a.jsx)(oe,{"data-testid":"dashboards-form",children:(0,a.jsxs)(ae,{className:"flex flex-col gap-3 py-4",children:[N,W,L,$,M,p]})}),e[75]=N,e[76]=W,e[77]=L,e[78]=$,e[79]=M,e[80]=p,e[81]=b):b=e[81],b},"Fe"),tt=g(f=>{let e=(0,Y.c)(53),{initialShardKey:t}=f,n=te(),[l,d]=ke(Be),[s,i]=(0,G.useState)(se),[h,x]=(0,G.useState)(null),[m,r]=(0,G.useState)(!1),o=ye(t??""),[v,S]=(0,G.useState)(null),u=(0,G.useRef)(null),C;e[0]!==t?(C=g(()=>{x(null),i({...se,shardKey:t??""}),r(!0)},"y"),e[0]=t,e[1]=C):C=e[1];let k=C,E;e[2]===Symbol.for("react.memo_cache_sentinel")?(E=g(()=>{r(!1),x(null),i(se)},"q"),e[2]=E):E=e[2];let O=E,j;e[3]!==l?(j=g(p=>{let b=l.find(c=>c.id===p);b!==void 0&&(x(p),i({chartKind:b.chartKind??"bar",kind:ce(b),shardKey:b.shardKey??"",sql:b.sql,text:b.text??"",title:b.title}),r(!0))},"E"),e[3]=l,e[4]=j):j=e[4];let T=j,w;e[5]!==o||e[6]!==d?(w=g((p,b)=>{S(p),ne((async()=>{let c=await o.inferChart({columns:b.columns,rowCount:b.rowCount});c!==void 0&&d(Ie(p,c))})().finally(()=>{S(c=>c===p?null:c)}))},"C"),e[5]=o,e[6]=d,e[7]=w):w=e[7];let K=w,_;e[8]!==d?(_=g(p=>{d(b=>b.filter(c=>c.id!==p))},"W"),e[8]=d,e[9]=_):_=e[9];let R=_,y;e[10]!==d?(y=g((p,b)=>{d(Te(p,b))},"k"),e[10]=d,e[11]=y):y=e[11];let N=y,F;e[12]!==d?(F=g((p,b)=>{d(c=>{let J=c.findIndex(P=>P.id===p),V=J+b;if(J===-1||V<0||V>=c.length)return c;let U=[...c],Q=U[J],Z=U[V];return Q===void 0||Z===void 0?c:(U[J]=Z,U[V]=Q,U)})},"_"),e[12]=d,e[13]=F):F=e[13];let H=F,D;e[14]!==s||e[15]!==h||e[16]!==d?(D=g(()=>{let p=s.title.trim(),b=s.sql.trim(),c=s.text.trim(),{chartKind:J,kind:V}=s;if(p===""||(V==="text"?c==="":b===""))return;let U={chartKind:J,kind:V,shardKey:s.shardKey.trim(),sql:b,text:c,title:p};d(h===null?Q=>[...Q,{...U,id:we("w")}]:Q=>Q.map(Z=>Z.id===h?{...Z,...U}:Z)),O()},"B"),e[14]=s,e[15]=h,e[16]=d,e[17]=D):D=e[17];let W=D,L;e[18]!==n?(L=n("Charts, values, tables, and notes. Drag a tile to reorder."),e[18]=n,e[19]=L):L=e[19];let $;e[20]!==L?($=(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:L}),e[20]=L,e[21]=$):$=e[21];let M;e[22]!==m||e[23]!==k||e[24]!==n?(M=!m&&(0,a.jsx)(X,{"data-testid":"dashboards-add",onClick:k,size:"sm",type:"button",children:n("Add widget")}),e[22]=m,e[23]=k,e[24]=n,e[25]=M):M=e[25];let z;e[26]!==$||e[27]!==M?(z=(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[$,M]}),e[26]=$,e[27]=M,e[28]=z):z=e[28];let q;e[29]!==o||e[30]!==n?(q=o.reason("chart")!==void 0&&(0,a.jsx)(le,{className:"text-xs",testId:"dashboards-suggest-error",variant:"destructive",children:n("Could not suggest a chart for that result.")}),e[29]=o,e[30]=n,e[31]=q):q=e[31];let B;e[32]!==s||e[33]!==h||e[34]!==m||e[35]!==W?(B=m&&(0,a.jsx)(Fe,{draft:s,editing:h!==null,onCancel:O,onChange:i,onSubmit:W}),e[32]=s,e[33]=h,e[34]=m,e[35]=W,e[36]=B):B=e[36];let I;e[37]!==o.unavailable||e[38]!==m||e[39]!==v||e[40]!==T||e[41]!==H||e[42]!==R||e[43]!==N||e[44]!==K||e[45]!==n||e[46]!==l?(I=l.length===0&&!m?(0,a.jsx)(me,{description:n("Add a chart, a single value, a table, or a note. Everything is saved on this browser."),testId:"dashboards-empty",title:n("No widgets yet")}):(0,a.jsx)("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-2 xl:grid-cols-3","data-testid":"dashboards-grid",children:l.map((p,b)=>(0,a.jsx)(_e,{draggedRef:u,first:b===0,inferring:v===p.id,last:b===l.length-1,onEdit:T,onMove:H,onRemove:R,onReorder:N,onSuggest:o.unavailable?void 0:K,widget:p},p.id))}),e[37]=o.unavailable,e[38]=m,e[39]=v,e[40]=T,e[41]=H,e[42]=R,e[43]=N,e[44]=K,e[45]=n,e[46]=l,e[47]=I):I=e[47];let A;return e[48]!==z||e[49]!==q||e[50]!==B||e[51]!==I?(A=(0,a.jsxs)("div",{className:"flex flex-col gap-4","data-testid":"lunora-dashboards",children:[z,q,B,I]}),e[48]=z,e[49]=q,e[50]=B,e[51]=I,e[52]=A):A=e[52],A},"it");export{tt as default};
1
+ import{a as Ce,b as Ne}from"./chunk-ZRB4HPDU.js";import{a as ye}from"./chunk-ZNVNSNDU.js";import"./chunk-WHDFMKYB.js";import"./chunk-AUGKHAMQ.js";import"./chunk-WJRYEML4.js";import{e as ke,g as we}from"./chunk-RGMVGZV4.js";import"./chunk-SJQERRSZ.js";import"./chunk-7Y3SY37W.js";import{a as X}from"./chunk-7G4Z6Q7X.js";import"./chunk-3YXASVTP.js";import"./chunk-AUAECCXB.js";import"./chunk-BOMPSVRC.js";import{a as le}from"./chunk-NCPW7WHO.js";import{a as pe}from"./chunk-4ZEL6BYL.js";import"./chunk-QUXXMJPZ.js";import{l as he}from"./chunk-BWKZ6FFW.js";import"./chunk-QAQDMS6R.js";import"./chunk-DYR23C3V.js";import{a as me}from"./chunk-RWVIV3U7.js";import"./chunk-HCTJKP5J.js";import{a as oe,b as ue,c as ge,e as ae}from"./chunk-2IKDEUCX.js";import{d as te,f as ve,g as be,h as fe,o as xe,p as ne}from"./chunk-HJHSQPHW.js";import{a as g,d as ie,e as Se,f as Ke,g as Le}from"./chunk-I26MS5PJ.js";var Y=ie(Ke(),1),G=ie(Se(),1);var a=ie(Le(),1);var Me=ve(pe.runSql),qe=g((f,e)=>{let t=(0,Y.c)(11),n=he(),[l,d]=(0,G.useState)(void 0),[s,i]=(0,G.useState)(void 0),[h,x]=(0,G.useState)(!0),m;t[0]!==n||t[1]!==e||t[2]!==f?(m=g(async u=>{x(!0);try{let C=await n.query(Me,{sql:f},be(e));u.cancelled||(d(C),i(void 0))}catch(C){let k=C;u.cancelled||(d(void 0),i(fe(k)))}u.cancelled||x(!1)},"h"),t[0]=n,t[1]=e,t[2]=f,t[3]=m):m=t[3];let r=m,o,v;t[4]!==r?(o=g(()=>{let u={cancelled:!1};return ne(r(u)),()=>{u.cancelled=!0}},"l"),v=[r],t[4]=r,t[5]=o,t[6]=v):(o=t[5],v=t[6]),(0,G.useEffect)(o,v);let S;return t[7]!==s||t[8]!==h||t[9]!==l?(S={error:s,loading:h,result:l},t[7]=s,t[8]=h,t[9]=l,t[10]=S):S=t[10],S},"Le"),Ee=g(f=>{f.preventDefault()},"Me"),ce=g(f=>f.kind??"chart","le"),Re=g(f=>{let e=(0,Y.c)(80),{actions:t,children:n,draggedRef:l,first:d,last:s,onEdit:i,onMove:h,onRemove:x,onReorder:m,widget:r}=f,o=te(),v;e[0]!==h||e[1]!==r.id?(v=g(()=>{h(r.id,-1)},"g"),e[0]=h,e[1]=r.id,e[2]=v):v=e[2];let S=v,u;e[3]!==h||e[4]!==r.id?(u=g(()=>{h(r.id,1)},"f"),e[3]=h,e[4]=r.id,e[5]=u):u=e[5];let C=u,k;e[6]!==i||e[7]!==r.id?(k=g(()=>{i(r.id)},"x"),e[6]=i,e[7]=r.id,e[8]=k):k=e[8];let E=k,O;e[9]!==x||e[10]!==r.id?(O=g(()=>{x(r.id)},"O"),e[9]=x,e[10]=r.id,e[11]=O):O=e[11];let j=O,T;e[12]!==l||e[13]!==r.id?(T=g(()=>{l.current=r.id},"z"),e[12]=l,e[13]=r.id,e[14]=T):T=e[14];let w=T,K;e[15]!==l||e[16]!==m||e[17]!==r.id?(K=g(()=>{let de=l.current;l.current=null,de!==null&&de!==r.id&&m(de,r.id)},"K"),e[15]=l,e[16]=m,e[17]=r.id,e[18]=K):K=e[18];let _=K,R=`dashboards-widget-${r.id}`,y;e[19]!==r.title?(y=(0,a.jsx)(ge,{className:"min-w-0 cursor-grab truncate",title:r.title,children:r.title}),e[19]=r.title,e[20]=y):y=e[20];let N;e[21]!==o?(N=o("Move widget up"),e[21]=o,e[22]=N):N=e[22];let F=`dashboards-move-up-${r.id}`,H;e[23]!==o?(H=o("Move widget up"),e[23]=o,e[24]=H):H=e[24];let D;e[25]===Symbol.for("react.memo_cache_sentinel")?(D=(0,a.jsx)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,a.jsx)("path",{d:"m6 15 6-6 6 6"})}),e[25]=D):D=e[25];let W;e[26]!==d||e[27]!==S||e[28]!==F||e[29]!==H||e[30]!==N?(W=(0,a.jsx)(X,{"aria-label":N,"data-testid":F,disabled:d,onClick:S,size:"icon-xs",title:H,type:"button",variant:"ghost",children:D}),e[26]=d,e[27]=S,e[28]=F,e[29]=H,e[30]=N,e[31]=W):W=e[31];let L;e[32]!==o?(L=o("Move widget down"),e[32]=o,e[33]=L):L=e[33];let $=`dashboards-move-down-${r.id}`,M;e[34]!==o?(M=o("Move widget down"),e[34]=o,e[35]=M):M=e[35];let z;e[36]===Symbol.for("react.memo_cache_sentinel")?(z=(0,a.jsx)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,a.jsx)("path",{d:"m6 9 6 6 6-6"})}),e[36]=z):z=e[36];let q;e[37]!==s||e[38]!==C||e[39]!==L||e[40]!==$||e[41]!==M?(q=(0,a.jsx)(X,{"aria-label":L,"data-testid":$,disabled:s,onClick:C,size:"icon-xs",title:M,type:"button",variant:"ghost",children:z}),e[37]=s,e[38]=C,e[39]=L,e[40]=$,e[41]=M,e[42]=q):q=e[42];let B;e[43]!==o?(B=o("Edit widget"),e[43]=o,e[44]=B):B=e[44];let I=`dashboards-widget-edit-${r.id}`,A;e[45]!==o?(A=o("Edit widget"),e[45]=o,e[46]=A):A=e[46];let p;e[47]===Symbol.for("react.memo_cache_sentinel")?(p=(0,a.jsx)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,a.jsx)("path",{d:"M4 20h4L18 10l-4-4L4 16v4ZM14 6l4 4"})}),e[47]=p):p=e[47];let b;e[48]!==E||e[49]!==B||e[50]!==I||e[51]!==A?(b=(0,a.jsx)(X,{"aria-label":B,"data-testid":I,onClick:E,size:"icon-xs",title:A,type:"button",variant:"ghost",children:p}),e[48]=E,e[49]=B,e[50]=I,e[51]=A,e[52]=b):b=e[52];let c;e[53]!==o?(c=o("Remove widget"),e[53]=o,e[54]=c):c=e[54];let J=`dashboards-widget-remove-${r.id}`,V;e[55]!==o?(V=o("Remove widget"),e[55]=o,e[56]=V):V=e[56];let U;e[57]===Symbol.for("react.memo_cache_sentinel")?(U=(0,a.jsx)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,a.jsx)("path",{d:"M5 7h14M9 7V5h6v2m-1 0v12H10V7M7 7v13h10V7"})}),e[57]=U):U=e[57];let Q;e[58]!==j||e[59]!==c||e[60]!==J||e[61]!==V?(Q=(0,a.jsx)(X,{"aria-label":c,"data-testid":J,onClick:j,size:"icon-xs",title:V,type:"button",variant:"ghost",children:U}),e[58]=j,e[59]=c,e[60]=J,e[61]=V,e[62]=Q):Q=e[62];let Z;e[63]!==t||e[64]!==W||e[65]!==q||e[66]!==b||e[67]!==Q?(Z=(0,a.jsxs)("div",{className:"flex shrink-0 items-center gap-1",children:[t,W,q,b,Q]}),e[63]=t,e[64]=W,e[65]=q,e[66]=b,e[67]=Q,e[68]=Z):Z=e[68];let P;e[69]!==Z||e[70]!==y?(P=(0,a.jsxs)(ue,{className:"flex flex-row items-start justify-between gap-2 border-b pb-3",children:[y,Z]}),e[69]=Z,e[70]=y,e[71]=P):P=e[71];let ee;e[72]!==n?(ee=(0,a.jsx)(ae,{className:"min-h-32 py-2",children:n}),e[72]=n,e[73]=ee):ee=e[73];let re;return e[74]!==w||e[75]!==_||e[76]!==P||e[77]!==ee||e[78]!==R?(re=(0,a.jsxs)(oe,{"data-testid":R,draggable:!0,onDragOver:Ee,onDragStart:w,onDrop:_,children:[P,ee]}),e[74]=w,e[75]=_,e[76]=P,e[77]=ee,e[78]=R,e[79]=re):re=e[79],re},"ce"),je=g(f=>{let e=(0,Y.c)(10),{result:t}=f,n=te(),l=t.columns[0],d=l===void 0?void 0:t.rows[0]?.[l],s;e[0]!==d||e[1]!==n?(s=d===void 0?n("\u2014"):xe(d),e[0]=d,e[1]=n,e[2]=s):s=e[2];let i;e[3]!==s?(i=(0,a.jsx)("p",{className:"truncate font-mono text-3xl font-semibold text-foreground",children:s}),e[3]=s,e[4]=i):i=e[4];let h;e[5]!==l?(h=l!==void 0&&(0,a.jsx)("p",{className:"truncate text-xs text-muted-foreground",children:l}),e[5]=l,e[6]=h):h=e[6];let x;return e[7]!==i||e[8]!==h?(x=(0,a.jsxs)("div",{className:"flex h-full flex-col justify-center gap-1 p-4","data-testid":"dashboards-kpi",children:[i,h]}),e[7]=i,e[8]=h,e[9]=x):x=e[9],x},"qe"),ze=g(f=>{let e=(0,Y.c)(12),{draggedRef:t,first:n,last:l,onEdit:d,onMove:s,onRemove:i,onReorder:h,widget:x}=f,m=x.text??"",r;e[0]!==m?(r=(0,a.jsx)("p",{className:"p-2 text-sm whitespace-pre-wrap text-muted-foreground","data-testid":"dashboards-text",children:m}),e[0]=m,e[1]=r):r=e[1];let o;return e[2]!==t||e[3]!==n||e[4]!==l||e[5]!==d||e[6]!==s||e[7]!==i||e[8]!==h||e[9]!==r||e[10]!==x?(o=(0,a.jsx)(Re,{draggedRef:t,first:n,last:l,onEdit:d,onMove:s,onRemove:i,onReorder:h,widget:x,children:r}),e[2]=t,e[3]=n,e[4]=l,e[5]=d,e[6]=s,e[7]=i,e[8]=h,e[9]=r,e[10]=x,e[11]=o):o=e[11],o},"Ee"),Ae=g(f=>{let e=(0,Y.c)(52),{draggedRef:t,first:n,inferring:l,last:d,onEdit:s,onMove:i,onRemove:h,onReorder:x,onSuggest:m,widget:r}=f,o=te(),{error:v,loading:S,result:u}=qe(r.sql,r.shardKey??""),C;e[0]!==r?(C=ce(r),e[0]=r,e[1]=C):C=e[1];let k=C,E;e[2]!==m||e[3]!==u||e[4]!==r.id?(E=g(()=>{u!==void 0&&m?.(r.id,u)},"q"),e[2]=m,e[3]=u,e[4]=r.id,e[5]=E):E=e[5];let O=E,j;e[6]!==l||e[7]!==k||e[8]!==m||e[9]!==O||e[10]!==u||e[11]!==o||e[12]!==r.id?(j=k==="chart"&&m!==void 0&&u!==void 0?(0,a.jsx)(X,{"aria-label":o("Suggest chart"),"data-testid":`dashboards-widget-suggest-${r.id}`,disabled:l,onClick:O,size:"icon-xs",title:o(l?"Suggesting\u2026":"Suggest chart"),type:"button",variant:"ghost",children:(0,a.jsx)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,a.jsx)("path",{d:"m12 3 1.9 4.6L18.5 9.5 13.9 11.4 12 16l-1.9-4.6L5.5 9.5l4.6-1.9L12 3ZM18 15l.9 2.1 2.1.9-2.1.9L18 21l-.9-2.1-2.1-.9 2.1-.9L18 15Z"})})}):void 0,e[6]=l,e[7]=k,e[8]=m,e[9]=O,e[10]=u,e[11]=o,e[12]=r.id,e[13]=j):j=e[13];let T=j,w;e[14]!==v||e[15]!==r.id?(w=v!==void 0&&(0,a.jsx)(le,{className:"font-mono text-xs",testId:`dashboards-widget-error-${r.id}`,variant:"destructive",children:v}),e[14]=v,e[15]=r.id,e[16]=w):w=e[16];let K;e[17]!==v||e[18]!==S||e[19]!==u||e[20]!==o||e[21]!==r.id?(K=v===void 0&&S&&u===void 0&&(0,a.jsx)("p",{className:"p-4 text-sm text-muted-foreground","data-testid":`dashboards-widget-loading-${r.id}`,children:o("Running\u2026")}),e[17]=v,e[18]=S,e[19]=u,e[20]=o,e[21]=r.id,e[22]=K):K=e[22];let _;e[23]!==v||e[24]!==k||e[25]!==u||e[26]!==r.chartAxes||e[27]!==r.chartKind?(_=v===void 0&&u!==void 0&&k==="chart"&&(0,a.jsx)(Ce,{axes:r.chartAxes,kind:r.chartKind,result:u}),e[23]=v,e[24]=k,e[25]=u,e[26]=r.chartAxes,e[27]=r.chartKind,e[28]=_):_=e[28];let R;e[29]!==v||e[30]!==k||e[31]!==u?(R=v===void 0&&u!==void 0&&k==="kpi"&&(0,a.jsx)(je,{result:u}),e[29]=v,e[30]=k,e[31]=u,e[32]=R):R=e[32];let y;e[33]!==v||e[34]!==k||e[35]!==u?(y=v===void 0&&u!==void 0&&k==="table"&&(0,a.jsx)("div",{className:"max-h-72 overflow-auto",children:(0,a.jsx)(Ne,{result:u})}),e[33]=v,e[34]=k,e[35]=u,e[36]=y):y=e[36];let N;return e[37]!==t||e[38]!==n||e[39]!==d||e[40]!==s||e[41]!==i||e[42]!==h||e[43]!==x||e[44]!==T||e[45]!==w||e[46]!==K||e[47]!==_||e[48]!==R||e[49]!==y||e[50]!==r?(N=(0,a.jsxs)(Re,{actions:T,draggedRef:t,first:n,last:d,onEdit:s,onMove:i,onRemove:h,onReorder:x,widget:r,children:[w,K,_,R,y]}),e[37]=t,e[38]=n,e[39]=d,e[40]=s,e[41]=i,e[42]=h,e[43]=x,e[44]=T,e[45]=w,e[46]=K,e[47]=_,e[48]=R,e[49]=y,e[50]=r,e[51]=N):N=e[51],N},"Ae"),_e=g(f=>{let e=(0,Y.c)(11),{draggedRef:t,first:n,inferring:l,last:d,onEdit:s,onMove:i,onRemove:h,onReorder:x,onSuggest:m,widget:r}=f,o;return e[0]!==t||e[1]!==n||e[2]!==l||e[3]!==d||e[4]!==s||e[5]!==i||e[6]!==h||e[7]!==x||e[8]!==m||e[9]!==r?(o=ce(r)==="text"?(0,a.jsx)(ze,{draggedRef:t,first:n,last:d,onEdit:s,onMove:i,onRemove:h,onReorder:x,widget:r}):(0,a.jsx)(Ae,{draggedRef:t,first:n,inferring:l,last:d,onEdit:s,onMove:i,onRemove:h,onReorder:x,onSuggest:m,widget:r}),e[0]=t,e[1]=n,e[2]=l,e[3]=d,e[4]=s,e[5]=i,e[6]=h,e[7]=x,e[8]=m,e[9]=r,e[10]=o):o=e[10],o},"Te"),We=["bar","line","area"],$e=["chart","kpi","table","text"],Be="lunora-studio-dashboards",se={chartKind:"bar",kind:"chart",shardKey:"",sql:"",text:"",title:""},Ie=g((f,e)=>t=>t.map(n=>n.id===f?{...n,chartAxes:e,chartKind:e.kind}:n),"De"),Te=g((f,e)=>t=>{let n=t.find(s=>s.id===f),l=t.filter(s=>s.id!==f),d=l.findIndex(s=>s.id===e);return n===void 0||d===-1?t:[...l.slice(0,d),n,...l.slice(d)]},"je"),De=g((f,e)=>e(f==="line"?"Line":f==="area"?"Area":"Bar"),"ze"),Oe=g((f,e)=>e(f==="kpi"?"Single value":f==="table"?"Table":f==="text"?"Text":"Chart"),"Be"),Fe=g(f=>{let e=(0,Y.c)(82),{draft:t,editing:n,onCancel:l,onChange:d,onSubmit:s}=f,i=te(),h;e[0]!==t||e[1]!==d?(h=g(c=>{d({...t,title:c.target.value})},"c"),e[0]=t,e[1]=d,e[2]=h):h=e[2];let x=h,m;e[3]!==t||e[4]!==d?(m=g(c=>{d({...t,sql:c.target.value})},"h"),e[3]=t,e[4]=d,e[5]=m):m=e[5];let r=m,o;e[6]!==t||e[7]!==d?(o=g(c=>{d({...t,text:c.target.value})},"l"),e[6]=t,e[7]=d,e[8]=o):o=e[8];let v=o,S;e[9]!==t||e[10]!==d?(S=g(c=>{d({...t,shardKey:c.target.value})},"N"),e[9]=t,e[10]=d,e[11]=S):S=e[11];let u=S,C;e[12]!==t||e[13]!==d?(C=g(c=>{d({...t,chartKind:c.target.value})},"y"),e[12]=t,e[13]=d,e[14]=C):C=e[14];let k=C,E;e[15]!==t||e[16]!==d?(E=g(c=>{d({...t,kind:c.target.value})},"q"),e[15]=t,e[16]=d,e[17]=E):E=e[17];let O=E,j;e[18]!==s?(j=g(()=>{s()},"E"),e[18]=s,e[19]=j):j=e[19];let T=j,w=t.kind==="text",K;e[20]!==t.sql||e[21]!==t.text||e[22]!==t.title||e[23]!==w?(K=t.title.trim()!==""&&(w?t.text.trim()!=="":t.sql.trim()!==""),e[20]=t.sql,e[21]=t.text,e[22]=t.title,e[23]=w,e[24]=K):K=e[24];let _=K,R;e[25]!==i?(R=i("Widget title"),e[25]=i,e[26]=R):R=e[26];let y;e[27]!==i?(y=i("Widget title"),e[27]=i,e[28]=y):y=e[28];let N;e[29]!==t.title||e[30]!==x||e[31]!==y||e[32]!==R?(N=(0,a.jsx)("input",{"aria-label":R,className:"h-8 rounded-md border border-border bg-background px-2 text-xs outline-none focus-visible:border-ring","data-testid":"dashboards-form-title",onChange:x,placeholder:y,type:"text",value:t.title}),e[29]=t.title,e[30]=x,e[31]=y,e[32]=R,e[33]=N):N=e[33];let F;e[34]!==i?(F=i("Widget type"),e[34]=i,e[35]=F):F=e[35];let H=t.kind,D;e[36]!==i?(D=$e.map(c=>(0,a.jsx)("option",{value:c,children:Oe(c,i)},c)),e[36]=i,e[37]=D):D=e[37];let W;e[38]!==t.kind||e[39]!==O||e[40]!==F||e[41]!==D?(W=(0,a.jsx)("select",{"aria-label":F,className:"h-8 rounded-md border border-border bg-background px-2 text-xs outline-none focus-visible:border-ring","data-testid":"dashboards-form-widget-kind",onChange:O,value:H,children:D}),e[38]=t.kind,e[39]=O,e[40]=F,e[41]=D,e[42]=W):W=e[42];let L;e[43]!==t.sql||e[44]!==t.text||e[45]!==w||e[46]!==r||e[47]!==v||e[48]!==i?(L=w?(0,a.jsx)("textarea",{"aria-label":i("Text"),className:"min-h-24 resize-y rounded-md border border-border bg-background p-2 text-xs leading-5 outline-none focus-visible:border-ring","data-testid":"dashboards-form-text",onChange:v,placeholder:i("Notes for whoever reads this dashboard."),value:t.text}):(0,a.jsx)("textarea",{"aria-label":i("SQL query"),className:"min-h-24 resize-y rounded-md border border-border bg-background p-2 font-mono text-xs leading-5 outline-none focus-visible:border-ring","data-testid":"dashboards-form-sql",onChange:r,placeholder:"SELECT author, COUNT(*) AS messages FROM \u2026",spellCheck:!1,value:t.sql}),e[43]=t.sql,e[44]=t.text,e[45]=w,e[46]=r,e[47]=v,e[48]=i,e[49]=L):L=e[49];let $;e[50]!==t.chartKind||e[51]!==t.kind||e[52]!==k||e[53]!==i?($=t.kind==="chart"&&(0,a.jsx)("select",{"aria-label":i("Chart type"),className:"h-8 rounded-md border border-border bg-background px-2 text-xs outline-none focus-visible:border-ring","data-testid":"dashboards-form-kind",onChange:k,value:t.chartKind,children:We.map(c=>(0,a.jsx)("option",{value:c,children:De(c,i)},c))}),e[50]=t.chartKind,e[51]=t.kind,e[52]=k,e[53]=i,e[54]=$):$=e[54];let M;e[55]!==t.shardKey||e[56]!==w||e[57]!==u||e[58]!==i?(M=!w&&(0,a.jsx)("input",{"aria-label":i("Shard key (optional)"),className:"h-8 rounded-md border border-border bg-background px-2 font-mono text-xs outline-none focus-visible:border-ring","data-testid":"dashboards-form-shard",onChange:u,placeholder:i("Shard key (optional)"),type:"text",value:t.shardKey}),e[55]=t.shardKey,e[56]=w,e[57]=u,e[58]=i,e[59]=M):M=e[59];let z;e[60]!==i?(z=i("Cancel"),e[60]=i,e[61]=z):z=e[61];let q;e[62]!==l||e[63]!==z?(q=(0,a.jsx)(X,{"data-testid":"dashboards-form-cancel",onClick:l,size:"sm",type:"button",variant:"outline",children:z}),e[62]=l,e[63]=z,e[64]=q):q=e[64];let B=!_,I;e[65]!==n||e[66]!==i?(I=i(n?"Save widget":"Add widget"),e[65]=n,e[66]=i,e[67]=I):I=e[67];let A;e[68]!==T||e[69]!==B||e[70]!==I?(A=(0,a.jsx)(X,{"data-testid":"dashboards-form-save",disabled:B,onClick:T,size:"sm",type:"button",children:I}),e[68]=T,e[69]=B,e[70]=I,e[71]=A):A=e[71];let p;e[72]!==q||e[73]!==A?(p=(0,a.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[q,A]}),e[72]=q,e[73]=A,e[74]=p):p=e[74];let b;return e[75]!==N||e[76]!==W||e[77]!==L||e[78]!==$||e[79]!==M||e[80]!==p?(b=(0,a.jsx)(oe,{"data-testid":"dashboards-form",children:(0,a.jsxs)(ae,{className:"flex flex-col gap-3 py-4",children:[N,W,L,$,M,p]})}),e[75]=N,e[76]=W,e[77]=L,e[78]=$,e[79]=M,e[80]=p,e[81]=b):b=e[81],b},"Fe"),tt=g(f=>{let e=(0,Y.c)(53),{initialShardKey:t}=f,n=te(),[l,d]=ke(Be),[s,i]=(0,G.useState)(se),[h,x]=(0,G.useState)(null),[m,r]=(0,G.useState)(!1),o=ye(t??""),[v,S]=(0,G.useState)(null),u=(0,G.useRef)(null),C;e[0]!==t?(C=g(()=>{x(null),i({...se,shardKey:t??""}),r(!0)},"y"),e[0]=t,e[1]=C):C=e[1];let k=C,E;e[2]===Symbol.for("react.memo_cache_sentinel")?(E=g(()=>{r(!1),x(null),i(se)},"q"),e[2]=E):E=e[2];let O=E,j;e[3]!==l?(j=g(p=>{let b=l.find(c=>c.id===p);b!==void 0&&(x(p),i({chartKind:b.chartKind??"bar",kind:ce(b),shardKey:b.shardKey??"",sql:b.sql,text:b.text??"",title:b.title}),r(!0))},"E"),e[3]=l,e[4]=j):j=e[4];let T=j,w;e[5]!==o||e[6]!==d?(w=g((p,b)=>{S(p),ne((async()=>{let c=await o.inferChart({columns:b.columns,rowCount:b.rowCount});c!==void 0&&d(Ie(p,c))})().finally(()=>{S(c=>c===p?null:c)}))},"C"),e[5]=o,e[6]=d,e[7]=w):w=e[7];let K=w,_;e[8]!==d?(_=g(p=>{d(b=>b.filter(c=>c.id!==p))},"W"),e[8]=d,e[9]=_):_=e[9];let R=_,y;e[10]!==d?(y=g((p,b)=>{d(Te(p,b))},"k"),e[10]=d,e[11]=y):y=e[11];let N=y,F;e[12]!==d?(F=g((p,b)=>{d(c=>{let J=c.findIndex(P=>P.id===p),V=J+b;if(J===-1||V<0||V>=c.length)return c;let U=[...c],Q=U[J],Z=U[V];return Q===void 0||Z===void 0?c:(U[J]=Z,U[V]=Q,U)})},"_"),e[12]=d,e[13]=F):F=e[13];let H=F,D;e[14]!==s||e[15]!==h||e[16]!==d?(D=g(()=>{let p=s.title.trim(),b=s.sql.trim(),c=s.text.trim(),{chartKind:J,kind:V}=s;if(p===""||(V==="text"?c==="":b===""))return;let U={chartKind:J,kind:V,shardKey:s.shardKey.trim(),sql:b,text:c,title:p};d(h===null?Q=>[...Q,{...U,id:we("w")}]:Q=>Q.map(Z=>Z.id===h?{...Z,...U}:Z)),O()},"B"),e[14]=s,e[15]=h,e[16]=d,e[17]=D):D=e[17];let W=D,L;e[18]!==n?(L=n("Charts, values, tables, and notes. Drag a tile to reorder."),e[18]=n,e[19]=L):L=e[19];let $;e[20]!==L?($=(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:L}),e[20]=L,e[21]=$):$=e[21];let M;e[22]!==m||e[23]!==k||e[24]!==n?(M=!m&&(0,a.jsx)(X,{"data-testid":"dashboards-add",onClick:k,size:"sm",type:"button",children:n("Add widget")}),e[22]=m,e[23]=k,e[24]=n,e[25]=M):M=e[25];let z;e[26]!==$||e[27]!==M?(z=(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[$,M]}),e[26]=$,e[27]=M,e[28]=z):z=e[28];let q;e[29]!==o||e[30]!==n?(q=o.reason("chart")!==void 0&&(0,a.jsx)(le,{className:"text-xs",testId:"dashboards-suggest-error",variant:"destructive",children:n("Could not suggest a chart for that result.")}),e[29]=o,e[30]=n,e[31]=q):q=e[31];let B;e[32]!==s||e[33]!==h||e[34]!==m||e[35]!==W?(B=m&&(0,a.jsx)(Fe,{draft:s,editing:h!==null,onCancel:O,onChange:i,onSubmit:W}),e[32]=s,e[33]=h,e[34]=m,e[35]=W,e[36]=B):B=e[36];let I;e[37]!==o.unavailable||e[38]!==m||e[39]!==v||e[40]!==T||e[41]!==H||e[42]!==R||e[43]!==N||e[44]!==K||e[45]!==n||e[46]!==l?(I=l.length===0&&!m?(0,a.jsx)(me,{description:n("Add a chart, a single value, a table, or a note. Everything is saved on this browser."),testId:"dashboards-empty",title:n("No widgets yet")}):(0,a.jsx)("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-2 xl:grid-cols-3","data-testid":"dashboards-grid",children:l.map((p,b)=>(0,a.jsx)(_e,{draggedRef:u,first:b===0,inferring:v===p.id,last:b===l.length-1,onEdit:T,onMove:H,onRemove:R,onReorder:N,onSuggest:o.unavailable?void 0:K,widget:p},p.id))}),e[37]=o.unavailable,e[38]=m,e[39]=v,e[40]=T,e[41]=H,e[42]=R,e[43]=N,e[44]=K,e[45]=n,e[46]=l,e[47]=I):I=e[47];let A;return e[48]!==z||e[49]!==q||e[50]!==B||e[51]!==I?(A=(0,a.jsxs)("div",{className:"flex flex-col gap-4","data-testid":"lunora-dashboards",children:[z,q,B,I]}),e[48]=z,e[49]=q,e[50]=B,e[51]=I,e[52]=A):A=e[52],A},"it");export{tt as default};