@lunora/studio 1.0.0-alpha.49 → 1.0.0-alpha.50

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 (85) hide show
  1. package/dist/index.d.ts +10 -5
  2. package/dist/index.js +6 -6
  3. package/dist/mount.d.ts +1 -1
  4. package/dist/mount.js +1 -1
  5. package/dist/packem_chunks/ApiTab.js +1 -1
  6. package/dist/packem_chunks/AuditPanel.js +1 -1
  7. package/dist/packem_chunks/ExportImportPanel.js +1 -1
  8. package/dist/packem_chunks/FileBrowser.js +1 -1
  9. package/dist/packem_chunks/FunctionRunner.js +1 -1
  10. package/dist/packem_chunks/FunctionStatsPanel.js +1 -1
  11. package/dist/packem_chunks/HealthPanel.js +1 -1
  12. package/dist/packem_chunks/InsightsPanel.js +1 -1
  13. package/dist/packem_chunks/LogsPanel.js +1 -1
  14. package/dist/packem_chunks/MailPanel.js +1 -1
  15. package/dist/packem_chunks/MetricsPanel.js +1 -1
  16. package/dist/packem_chunks/MigrationsPanel.js +1 -1
  17. package/dist/packem_chunks/PitrPanel.js +1 -1
  18. package/dist/packem_chunks/SchemaViewer.js +1 -1
  19. package/dist/packem_chunks/SecurityAdvisorPanel.js +1 -1
  20. package/dist/packem_chunks/SettingsPanel.js +1 -1
  21. package/dist/packem_chunks/SqlEditorPanel.js +1 -1
  22. package/dist/packem_chunks/TableEditor.js +1 -1
  23. package/dist/packem_chunks/agents-panel.js +1 -1
  24. package/dist/packem_chunks/containers-panel.js +21 -7
  25. package/dist/packem_chunks/dashboards-panel.js +1 -1
  26. package/dist/packem_chunks/fanout-panel.js +1 -1
  27. package/dist/packem_chunks/flags-panel.js +1 -1
  28. package/dist/packem_chunks/issues-panel.js +188 -0
  29. package/dist/packem_chunks/kv-browser.js +1 -1
  30. package/dist/packem_chunks/payments-panel.js +1 -1
  31. package/dist/packem_chunks/permissions-panel.js +1 -1
  32. package/dist/packem_chunks/queues-panel.js +1 -1
  33. package/dist/packem_chunks/rls-panel.js +1 -1
  34. package/dist/packem_chunks/storage-rules-panel.js +1 -1
  35. package/dist/packem_chunks/subscriptions-panel.js +1 -1
  36. package/dist/packem_chunks/workflows-panel.js +1 -1
  37. package/dist/packem_shared/{ADMIN_FUNCTIONS-BHHJi3Gb.js → ADMIN_FUNCTIONS-DNeyYtUN.js} +1 -0
  38. package/dist/packem_shared/{ApiDocsPanel-B2Rc7nOF.js → ApiDocsPanel-_aEZxAMX.js} +1 -1
  39. package/dist/packem_shared/{DataBrowser-Cc197zke.js → DataBrowser-C8hejnub.js} +1 -1
  40. package/dist/packem_shared/{HomePanel-CjDlJzzs.js → HomePanel-Ye8PaqQL.js} +2 -2
  41. package/dist/packem_shared/{Studio-MB2VTLwI.js → Studio-xJLTlLpf.js} +2 -2
  42. package/dist/packem_shared/{StudioApp-Ds6u0iY5.js → StudioApp-oCQholCL.js} +1 -1
  43. package/dist/packem_shared/{app.d-Bly6zmWK.d.ts → app.d-CGdOmLTm.d.ts} +1 -1
  44. package/dist/packem_shared/{home-panel-BohxdqDb.js → home-panel-D62G8108.js} +1 -1
  45. package/dist/packem_shared/{studio-Bv27fj7n.js → studio-WZUOecDv.js} +578 -551
  46. package/dist/standalone/{chunk-2JUOJEKE.js → chunk-2JTPX3CV.js} +1 -1
  47. package/dist/standalone/{chunk-2O4BHAHA.js → chunk-3CPQ5IQU.js} +1 -1
  48. package/dist/standalone/{chunk-BTODL6SI.js → chunk-4AXW2ECS.js} +1 -1
  49. package/dist/standalone/chunk-4BVRLBEW.js +1 -0
  50. package/dist/standalone/{chunk-QCW4BAH5.js → chunk-6RREMPQX.js} +1 -1
  51. package/dist/standalone/{chunk-AHDVD4KF.js → chunk-6ZBU3JWR.js} +1 -1
  52. package/dist/standalone/chunk-A2DBMISD.js +1 -0
  53. package/dist/standalone/{chunk-Q7HPS6TW.js → chunk-A66LI6OV.js} +1 -1
  54. package/dist/standalone/{chunk-CDHEMVIY.js → chunk-CJXJIRSN.js} +1 -1
  55. package/dist/standalone/{chunk-R6H6DUPU.js → chunk-DR6LGPXE.js} +1 -1
  56. package/dist/standalone/{chunk-CTOOUWO4.js → chunk-FAUN4Z72.js} +1 -1
  57. package/dist/standalone/chunk-G7ZBM54M.js +1 -0
  58. package/dist/standalone/{chunk-5YPIP3G7.js → chunk-HAJSYWFT.js} +1 -1
  59. package/dist/standalone/{chunk-6U45TJXA.js → chunk-HQM6MBPS.js} +1 -1
  60. package/dist/standalone/{chunk-ECJPFPHR.js → chunk-HTQNZXDT.js} +1 -1
  61. package/dist/standalone/{chunk-W5BAQMIE.js → chunk-IO2XEI6T.js} +1 -1
  62. package/dist/standalone/{chunk-WK7VHQTQ.js → chunk-K4S652EQ.js} +1 -1
  63. package/dist/standalone/{chunk-L4UCG6XZ.js → chunk-KJFFID72.js} +1 -1
  64. package/dist/standalone/{chunk-R2HA2NVX.js → chunk-LJAAZNQ6.js} +1 -1
  65. package/dist/standalone/{chunk-UWSLX56Q.js → chunk-LX7KONE3.js} +1 -1
  66. package/dist/standalone/{chunk-XGPFWZPJ.js → chunk-NW6SZZ5O.js} +1 -1
  67. package/dist/standalone/{chunk-NH4FSHFO.js → chunk-P2ERTKMB.js} +1 -1
  68. package/dist/standalone/{chunk-N4TGVH2R.js → chunk-PS3XCCZD.js} +1 -1
  69. package/dist/standalone/{chunk-ALTQC4S5.js → chunk-RS7S7XVP.js} +1 -1
  70. package/dist/standalone/{chunk-GA6K5WS5.js → chunk-S7AB7Y75.js} +1 -1
  71. package/dist/standalone/{chunk-FFCUV3TZ.js → chunk-SHJUAHC6.js} +1 -1
  72. package/dist/standalone/{chunk-RE4LLVPN.js → chunk-TYN6SQ73.js} +1 -1
  73. package/dist/standalone/{chunk-XPLUSBKA.js → chunk-U26QNHMO.js} +1 -1
  74. package/dist/standalone/{chunk-Q6356GAQ.js → chunk-VL6HOZHF.js} +1 -1
  75. package/dist/standalone/{chunk-RYF5EUQA.js → chunk-X2TQRMQV.js} +1 -1
  76. package/dist/standalone/{chunk-ZANX3V5B.js → chunk-X4676IX6.js} +1 -1
  77. package/dist/standalone/{chunk-3JXKA6BH.js → chunk-XJU5SRNL.js} +1 -1
  78. package/dist/standalone/chunk-XWPZBZSZ.js +3 -0
  79. package/dist/standalone/{chunk-CCRVGYTN.js → chunk-YLHDKM2P.js} +1 -1
  80. package/dist/standalone/studio.js +1 -1
  81. package/dist/styles.css +1 -1
  82. package/package.json +1 -1
  83. package/dist/standalone/chunk-4TV6S6AO.js +0 -3
  84. package/dist/standalone/chunk-BOXSWNXZ.js +0 -1
  85. package/dist/standalone/chunk-ZVLQVBTM.js +0 -1
@@ -1 +1 @@
1
- import{a as H}from"./chunk-VLXV72QE.js";import{a as v}from"./chunk-JSEXCW5Q.js";import{a as q}from"./chunk-LUP4YTBS.js";import{b as V}from"./chunk-4PC7IXNY.js";import"./chunk-2MLA6WFH.js";import{R as B}from"./chunk-VL23Y44O.js";import"./chunk-HV7G6DFP.js";import{c as p}from"./chunk-UK64ZSUW.js";import"./chunk-O3NAGRTR.js";import{b as S}from"./chunk-ZPP2KOR4.js";import"./chunk-CKSHCYGC.js";import{a as z}from"./chunk-BOXSWNXZ.js";import{f as L}from"./chunk-SDMZKBTD.js";import"./chunk-ZHVTQ37P.js";import"./chunk-3OA7PECS.js";import{d as j,e as K,f as U,h as J,l as M,p as P}from"./chunk-ITQKVEP7.js";import"./chunk-22C6COGE.js";import{a,e as D,f as ne,h as ie}from"./chunk-RRCPZMC2.js";var n=D(ne(),1);var e=D(ie(),1);var de=a(r=>r.kind==="id"?r.table===void 0?"id":`id<${r.table}>`:r.kind==="array"?r.element===void 0?"array":`${r.element}[]`:r.kind,"argumentType"),le=a(r=>r===void 0||r.length===0?"()":`(${r.map(i=>`${i.name}${i.optional?"?":""}: ${de(i)}`).join(", ")})`,"formatSignature"),ce=a(r=>{switch(r){case"array":return[];case"bigint":case"number":return 0;case"boolean":return!1;case"object":case"record":return{};default:return""}},"placeholderValue"),ue=a(r=>{let i={};for(let s of r??[])s.optional||(i[s.name]=ce(s.kind));return JSON.stringify(i,void 0,2)},"argumentsTemplate"),fe=U(z.runAs),me=10,he=a(r=>r===void 0?"undefined":JSON.stringify(r,null,2),"formatResult"),Ae=a(({functions:r,runAsIdentity:i=!1}={})=>{let s=j(),u=L(),[X,Y]=(0,n.useState)(null),[w,G]=(0,n.useState)(null),g=r??X??[],[R,I]=(0,n.useState)(""),[f,x]=(0,n.useState)("{}"),[c,k]=(0,n.useState)(""),[m,Q]=(0,n.useState)(""),[b,h]=(0,n.useState)("idle"),[W,N]=(0,n.useState)(void 0),[A,y]=(0,n.useState)(null),[C,Z]=(0,n.useState)([]);(0,n.useEffect)(()=>{if(r!==void 0)return;let t=!1;return u.listFunctions().then(d=>(t||Y(d),d)).catch(d=>{t||G(J(d))}),()=>{t=!0}},[u,r]);let T=R===""?g[0]?.path??"":R,o=g.find(t=>t.path===T),_=a(async()=>{if(!o)return;let t;try{t=f.trim()===""?{}:JSON.parse(f)}catch(l){h("error"),N(void 0),y(s("Invalid JSON args: {message}",{message:l.message}));return}let d={__lunoraRef:o.path},F=c.trim()===""?{}:{shardKey:c.trim()},$=i?m.trim():"",E=a(l=>{Z(O=>[{argsText:f,at:Date.now(),id:(O[0]?.id??0)+1,kind:o.kind,path:o.path,shardKey:c,status:l},...O].slice(0,me))},"record");h("running"),y(null);try{let l=$===""?await K(u,o.kind,d,t,F):await u.query(fe,{args:t,functionPath:o.path,userId:$},F);V(c),N(l),h("success"),E("success")}catch(l){N(void 0),y(l.message),h("error"),E("error")}},"run"),ee=a(t=>{I(t.path),x(t.argsText),k(t.shardKey)},"loadRun"),te=a(t=>{I(t.target.value)},"onSelectChange"),re=a(t=>{x(t.target.value)},"onArgsChange"),se=a(t=>{Q(t.target.value)},"onRunAsChange"),ae=a(()=>{M(_())},"runOnce"),oe=a(()=>{x(ue(o?.args))},"prefillArgs");return(0,e.jsxDEV)("div",{className:"flex flex-col gap-4","data-testid":"lunora-function-runner",children:[w!==null&&(0,e.jsxDEV)("p",{className:"text-sm text-destructive","data-testid":"function-discover-error",role:"alert",children:w},void 0,!1),(0,e.jsxDEV)("div",{className:"flex flex-col gap-4 rounded-xl border border-border bg-card p-4",children:[(0,e.jsxDEV)("div",{className:"flex flex-col gap-1.5",children:[(0,e.jsxDEV)(v,{htmlFor:"function-select",children:s("Function")},void 0,!1),(0,e.jsxDEV)("select",{"aria-label":s("Function"),className:"flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-xs transition-[color,box-shadow] outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50","data-testid":"function-select",id:"function-select",onChange:te,value:T,children:g.map(t=>(0,e.jsxDEV)("option",{value:t.path,children:[t.path," (",t.kind,")"]},t.path,!0))},void 0,!1),o!==void 0&&(0,e.jsxDEV)("p",{className:"text-xs text-muted-foreground",children:[(0,e.jsxDEV)("span",{className:"mr-1.5 font-medium",children:s("Signature")},void 0,!1),(0,e.jsxDEV)("code",{className:"font-mono","data-testid":"function-signature",children:le(o.args)},void 0,!1)]},void 0,!0)]},void 0,!0),(0,e.jsxDEV)("div",{className:"flex flex-col gap-1.5",children:[(0,e.jsxDEV)("div",{className:"flex items-center justify-between gap-2",children:[(0,e.jsxDEV)(v,{htmlFor:"args-input",children:s("Arguments")},void 0,!1),(0,e.jsxDEV)(p,{"data-testid":"prefill-button",disabled:o===void 0,onClick:oe,size:"xs",type:"button",variant:"ghost",children:s("Prefill")},void 0,!1)]},void 0,!0),(0,e.jsxDEV)(H,{"aria-label":s("Arguments"),className:"font-mono text-xs","data-testid":"args-input",id:"args-input",onChange:re,value:f},void 0,!1)]},void 0,!0),(0,e.jsxDEV)(q,{onChange:k,testId:"shard-input",value:c},void 0,!1),i&&(0,e.jsxDEV)("div",{className:"flex flex-col gap-1.5","data-testid":"run-as-field",children:[(0,e.jsxDEV)(v,{htmlFor:"run-as-input",children:s("Run as identity (userId)")},void 0,!1),(0,e.jsxDEV)(B,{"aria-label":s("Run as identity (userId)"),className:"font-mono text-xs","data-testid":"run-as-input",id:"run-as-input",onChange:se,placeholder:s("Leave empty to run as admin"),value:m},void 0,!1),(0,e.jsxDEV)("p",{className:"text-[11px] text-muted-foreground",children:s("Dev only: runs the function as this user so you can test auth and RLS. Forged over the admin gate.")},void 0,!1)]},void 0,!0),(0,e.jsxDEV)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,e.jsxDEV)(p,{"data-testid":"run-button",disabled:b==="running"||o===void 0,onClick:ae,type:"button",children:s("Run")},void 0,!1),o!==void 0&&(0,e.jsxDEV)(S,{variant:"outline",children:o.kind},void 0,!1),i&&m.trim()!==""&&(0,e.jsxDEV)(S,{"data-testid":"run-as-badge",variant:"secondary",children:s("as {userId}",{userId:m.trim()})},void 0,!1)]},void 0,!0)]},void 0,!0),b==="error"&&A!==null&&(0,e.jsxDEV)("pre",{className:"overflow-auto rounded-md border border-border bg-muted/50 p-3 font-mono text-xs text-destructive","data-testid":"error",role:"alert",children:A},void 0,!1),b==="success"&&(0,e.jsxDEV)("pre",{className:"overflow-auto rounded-md border border-border bg-muted/50 p-3 font-mono text-xs","data-testid":"result",children:he(W)},void 0,!1),C.length>0&&(0,e.jsxDEV)("ul",{className:"flex flex-col overflow-hidden rounded-xl border border-border","data-testid":"fn-history",children:C.map((t,d)=>(0,e.jsxDEV)("li",{className:"flex flex-wrap items-center gap-2 border-b border-border px-3 py-2 text-sm last:border-b-0","data-testid":"fn-history-row",children:[(0,e.jsxDEV)("span",{className:t.status==="success"?"text-success":"text-destructive","data-testid":`fn-history-status-${d.toString()}`,children:t.status==="success"?"\u2713":"\u2717"},void 0,!1)," ",(0,e.jsxDEV)("span",{className:"font-mono text-xs",children:[t.path," (",t.kind,")"]},void 0,!0)," ",(0,e.jsxDEV)("time",{className:"text-xs text-muted-foreground",children:P(t.at)},void 0,!1)," ",(0,e.jsxDEV)(p,{className:"ml-auto","data-testid":`fn-history-load-${d.toString()}`,onClick:a(()=>{ee(t)},"onClick"),size:"xs",type:"button",variant:"ghost",children:s("Load")},void 0,!1)]},t.id,!0))},void 0,!1)]},void 0,!0)},"FunctionRunner");export{Ae as FunctionRunner};
1
+ import{a as H}from"./chunk-VLXV72QE.js";import{a as v}from"./chunk-JSEXCW5Q.js";import{a as q}from"./chunk-LUP4YTBS.js";import{b as V}from"./chunk-4PC7IXNY.js";import"./chunk-2MLA6WFH.js";import{R as B}from"./chunk-VL23Y44O.js";import"./chunk-HV7G6DFP.js";import{c as p}from"./chunk-UK64ZSUW.js";import"./chunk-O3NAGRTR.js";import{b as S}from"./chunk-ZPP2KOR4.js";import"./chunk-CKSHCYGC.js";import{a as z}from"./chunk-G7ZBM54M.js";import{f as L}from"./chunk-SDMZKBTD.js";import"./chunk-ZHVTQ37P.js";import"./chunk-3OA7PECS.js";import{d as j,e as K,f as U,h as J,l as M,p as P}from"./chunk-ITQKVEP7.js";import"./chunk-22C6COGE.js";import{a,e as D,f as ne,h as ie}from"./chunk-RRCPZMC2.js";var n=D(ne(),1);var e=D(ie(),1);var de=a(r=>r.kind==="id"?r.table===void 0?"id":`id<${r.table}>`:r.kind==="array"?r.element===void 0?"array":`${r.element}[]`:r.kind,"argumentType"),le=a(r=>r===void 0||r.length===0?"()":`(${r.map(i=>`${i.name}${i.optional?"?":""}: ${de(i)}`).join(", ")})`,"formatSignature"),ce=a(r=>{switch(r){case"array":return[];case"bigint":case"number":return 0;case"boolean":return!1;case"object":case"record":return{};default:return""}},"placeholderValue"),ue=a(r=>{let i={};for(let s of r??[])s.optional||(i[s.name]=ce(s.kind));return JSON.stringify(i,void 0,2)},"argumentsTemplate"),fe=U(z.runAs),me=10,he=a(r=>r===void 0?"undefined":JSON.stringify(r,null,2),"formatResult"),Ae=a(({functions:r,runAsIdentity:i=!1}={})=>{let s=j(),u=L(),[X,Y]=(0,n.useState)(null),[w,G]=(0,n.useState)(null),g=r??X??[],[R,I]=(0,n.useState)(""),[f,x]=(0,n.useState)("{}"),[c,k]=(0,n.useState)(""),[m,Q]=(0,n.useState)(""),[b,h]=(0,n.useState)("idle"),[W,N]=(0,n.useState)(void 0),[A,y]=(0,n.useState)(null),[C,Z]=(0,n.useState)([]);(0,n.useEffect)(()=>{if(r!==void 0)return;let t=!1;return u.listFunctions().then(d=>(t||Y(d),d)).catch(d=>{t||G(J(d))}),()=>{t=!0}},[u,r]);let T=R===""?g[0]?.path??"":R,o=g.find(t=>t.path===T),_=a(async()=>{if(!o)return;let t;try{t=f.trim()===""?{}:JSON.parse(f)}catch(l){h("error"),N(void 0),y(s("Invalid JSON args: {message}",{message:l.message}));return}let d={__lunoraRef:o.path},F=c.trim()===""?{}:{shardKey:c.trim()},$=i?m.trim():"",E=a(l=>{Z(O=>[{argsText:f,at:Date.now(),id:(O[0]?.id??0)+1,kind:o.kind,path:o.path,shardKey:c,status:l},...O].slice(0,me))},"record");h("running"),y(null);try{let l=$===""?await K(u,o.kind,d,t,F):await u.query(fe,{args:t,functionPath:o.path,userId:$},F);V(c),N(l),h("success"),E("success")}catch(l){N(void 0),y(l.message),h("error"),E("error")}},"run"),ee=a(t=>{I(t.path),x(t.argsText),k(t.shardKey)},"loadRun"),te=a(t=>{I(t.target.value)},"onSelectChange"),re=a(t=>{x(t.target.value)},"onArgsChange"),se=a(t=>{Q(t.target.value)},"onRunAsChange"),ae=a(()=>{M(_())},"runOnce"),oe=a(()=>{x(ue(o?.args))},"prefillArgs");return(0,e.jsxDEV)("div",{className:"flex flex-col gap-4","data-testid":"lunora-function-runner",children:[w!==null&&(0,e.jsxDEV)("p",{className:"text-sm text-destructive","data-testid":"function-discover-error",role:"alert",children:w},void 0,!1),(0,e.jsxDEV)("div",{className:"flex flex-col gap-4 rounded-xl border border-border bg-card p-4",children:[(0,e.jsxDEV)("div",{className:"flex flex-col gap-1.5",children:[(0,e.jsxDEV)(v,{htmlFor:"function-select",children:s("Function")},void 0,!1),(0,e.jsxDEV)("select",{"aria-label":s("Function"),className:"flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-xs transition-[color,box-shadow] outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50","data-testid":"function-select",id:"function-select",onChange:te,value:T,children:g.map(t=>(0,e.jsxDEV)("option",{value:t.path,children:[t.path," (",t.kind,")"]},t.path,!0))},void 0,!1),o!==void 0&&(0,e.jsxDEV)("p",{className:"text-xs text-muted-foreground",children:[(0,e.jsxDEV)("span",{className:"mr-1.5 font-medium",children:s("Signature")},void 0,!1),(0,e.jsxDEV)("code",{className:"font-mono","data-testid":"function-signature",children:le(o.args)},void 0,!1)]},void 0,!0)]},void 0,!0),(0,e.jsxDEV)("div",{className:"flex flex-col gap-1.5",children:[(0,e.jsxDEV)("div",{className:"flex items-center justify-between gap-2",children:[(0,e.jsxDEV)(v,{htmlFor:"args-input",children:s("Arguments")},void 0,!1),(0,e.jsxDEV)(p,{"data-testid":"prefill-button",disabled:o===void 0,onClick:oe,size:"xs",type:"button",variant:"ghost",children:s("Prefill")},void 0,!1)]},void 0,!0),(0,e.jsxDEV)(H,{"aria-label":s("Arguments"),className:"font-mono text-xs","data-testid":"args-input",id:"args-input",onChange:re,value:f},void 0,!1)]},void 0,!0),(0,e.jsxDEV)(q,{onChange:k,testId:"shard-input",value:c},void 0,!1),i&&(0,e.jsxDEV)("div",{className:"flex flex-col gap-1.5","data-testid":"run-as-field",children:[(0,e.jsxDEV)(v,{htmlFor:"run-as-input",children:s("Run as identity (userId)")},void 0,!1),(0,e.jsxDEV)(B,{"aria-label":s("Run as identity (userId)"),className:"font-mono text-xs","data-testid":"run-as-input",id:"run-as-input",onChange:se,placeholder:s("Leave empty to run as admin"),value:m},void 0,!1),(0,e.jsxDEV)("p",{className:"text-[11px] text-muted-foreground",children:s("Dev only: runs the function as this user so you can test auth and RLS. Forged over the admin gate.")},void 0,!1)]},void 0,!0),(0,e.jsxDEV)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,e.jsxDEV)(p,{"data-testid":"run-button",disabled:b==="running"||o===void 0,onClick:ae,type:"button",children:s("Run")},void 0,!1),o!==void 0&&(0,e.jsxDEV)(S,{variant:"outline",children:o.kind},void 0,!1),i&&m.trim()!==""&&(0,e.jsxDEV)(S,{"data-testid":"run-as-badge",variant:"secondary",children:s("as {userId}",{userId:m.trim()})},void 0,!1)]},void 0,!0)]},void 0,!0),b==="error"&&A!==null&&(0,e.jsxDEV)("pre",{className:"overflow-auto rounded-md border border-border bg-muted/50 p-3 font-mono text-xs text-destructive","data-testid":"error",role:"alert",children:A},void 0,!1),b==="success"&&(0,e.jsxDEV)("pre",{className:"overflow-auto rounded-md border border-border bg-muted/50 p-3 font-mono text-xs","data-testid":"result",children:he(W)},void 0,!1),C.length>0&&(0,e.jsxDEV)("ul",{className:"flex flex-col overflow-hidden rounded-xl border border-border","data-testid":"fn-history",children:C.map((t,d)=>(0,e.jsxDEV)("li",{className:"flex flex-wrap items-center gap-2 border-b border-border px-3 py-2 text-sm last:border-b-0","data-testid":"fn-history-row",children:[(0,e.jsxDEV)("span",{className:t.status==="success"?"text-success":"text-destructive","data-testid":`fn-history-status-${d.toString()}`,children:t.status==="success"?"\u2713":"\u2717"},void 0,!1)," ",(0,e.jsxDEV)("span",{className:"font-mono text-xs",children:[t.path," (",t.kind,")"]},void 0,!0)," ",(0,e.jsxDEV)("time",{className:"text-xs text-muted-foreground",children:P(t.at)},void 0,!1)," ",(0,e.jsxDEV)(p,{className:"ml-auto","data-testid":`fn-history-load-${d.toString()}`,onClick:a(()=>{ee(t)},"onClick"),size:"xs",type:"button",variant:"ghost",children:s("Load")},void 0,!1)]},t.id,!0))},void 0,!1)]},void 0,!0)},"FunctionRunner");export{Ae as FunctionRunner};
@@ -1,4 +1,4 @@
1
- import{a as Pe}from"./chunk-SDQE2IUJ.js";import{a as Be}from"./chunk-JM7XBQVK.js";import{a as $e}from"./chunk-TO6D2PJC.js";import"./chunk-V43BLH4J.js";import"./chunk-APSSZB6Z.js";import"./chunk-QAFAJBAW.js";import"./chunk-AHILM3ZP.js";import"./chunk-WVTPZ6CM.js";import"./chunk-SHERR7ZP.js";import"./chunk-5OIBXYZM.js";import"./chunk-L7SK4ZZD.js";import"./chunk-X4QFAAZ5.js";import"./chunk-BJGBHGK3.js";import"./chunk-ZIGWVHCS.js";import"./chunk-EEWKIQUE.js";import"./chunk-KEGAWN6Y.js";import{a as Re}from"./chunk-XNJNSCLM.js";import{a as Le,b as Ae,c as Oe,d as xe,e as Me,f as De}from"./chunk-GTM65MVX.js";import"./chunk-4QHKBC77.js";import{a as Ie}from"./chunk-LUP4YTBS.js";import{b as qe}from"./chunk-4PC7IXNY.js";import{d as re,e as ve,f as ge}from"./chunk-2MLA6WFH.js";import"./chunk-VL23Y44O.js";import"./chunk-HV7G6DFP.js";import"./chunk-UK64ZSUW.js";import"./chunk-O3NAGRTR.js";import"./chunk-CKSHCYGC.js";import{a as le}from"./chunk-BOXSWNXZ.js";import{f as he}from"./chunk-SDMZKBTD.js";import"./chunk-ZHVTQ37P.js";import"./chunk-3OA7PECS.js";import{d as G,f as ne,g as se,h as Ee,l as Q}from"./chunk-ITQKVEP7.js";import"./chunk-22C6COGE.js";import{a as r,e as be,f as It,g as Rt,h as Lt,j as oe}from"./chunk-RRCPZMC2.js";var K=be(Rt(),1);var q=be(It(),1);var n=be(Lt(),1);var At=["ORDER BY","GROUP BY","LEFT JOIN","RIGHT JOIN","INNER JOIN","OUTER JOIN","CROSS JOIN","EXPLAIN QUERY PLAN","SELECT","DISTINCT","FROM","WHERE","HAVING","LIMIT","OFFSET","JOIN","ON","AND","OR","AS","ASC","DESC","WITH","UNION","EXPLAIN"],Ot=["FROM","WHERE","ORDER BY","GROUP BY","HAVING","LIMIT","OFFSET","UNION","JOIN","LEFT JOIN","RIGHT JOIN","INNER JOIN","OUTER JOIN","CROSS JOIN"],ae=String.fromCodePoint(0),Mt=new RegExp(`${ae}${String.raw`(\d+)`}${ae}`,"gu"),Dt=At.map(s=>({pattern:new RegExp(String.raw`\b${s.replaceAll(" ",String.raw`\s+`)}\b`,"giu"),replacement:s})),Bt=Ot.map(s=>({pattern:new RegExp(String.raw`\s+${s.replaceAll(" ",String.raw`\s+`)}\b`,"gu"),replacement:`
1
+ import{a as Pe}from"./chunk-SDQE2IUJ.js";import{a as Be}from"./chunk-JM7XBQVK.js";import{a as $e}from"./chunk-TO6D2PJC.js";import"./chunk-V43BLH4J.js";import"./chunk-APSSZB6Z.js";import"./chunk-QAFAJBAW.js";import"./chunk-AHILM3ZP.js";import"./chunk-WVTPZ6CM.js";import"./chunk-SHERR7ZP.js";import"./chunk-5OIBXYZM.js";import"./chunk-L7SK4ZZD.js";import"./chunk-X4QFAAZ5.js";import"./chunk-BJGBHGK3.js";import"./chunk-ZIGWVHCS.js";import"./chunk-EEWKIQUE.js";import"./chunk-KEGAWN6Y.js";import{a as Re}from"./chunk-XNJNSCLM.js";import{a as Le,b as Ae,c as Oe,d as xe,e as Me,f as De}from"./chunk-GTM65MVX.js";import"./chunk-4QHKBC77.js";import{a as Ie}from"./chunk-LUP4YTBS.js";import{b as qe}from"./chunk-4PC7IXNY.js";import{d as re,e as ve,f as ge}from"./chunk-2MLA6WFH.js";import"./chunk-VL23Y44O.js";import"./chunk-HV7G6DFP.js";import"./chunk-UK64ZSUW.js";import"./chunk-O3NAGRTR.js";import"./chunk-CKSHCYGC.js";import{a as le}from"./chunk-G7ZBM54M.js";import{f as he}from"./chunk-SDMZKBTD.js";import"./chunk-ZHVTQ37P.js";import"./chunk-3OA7PECS.js";import{d as G,f as ne,g as se,h as Ee,l as Q}from"./chunk-ITQKVEP7.js";import"./chunk-22C6COGE.js";import{a as r,e as be,f as It,g as Rt,h as Lt,j as oe}from"./chunk-RRCPZMC2.js";var K=be(Rt(),1);var q=be(It(),1);var n=be(Lt(),1);var At=["ORDER BY","GROUP BY","LEFT JOIN","RIGHT JOIN","INNER JOIN","OUTER JOIN","CROSS JOIN","EXPLAIN QUERY PLAN","SELECT","DISTINCT","FROM","WHERE","HAVING","LIMIT","OFFSET","JOIN","ON","AND","OR","AS","ASC","DESC","WITH","UNION","EXPLAIN"],Ot=["FROM","WHERE","ORDER BY","GROUP BY","HAVING","LIMIT","OFFSET","UNION","JOIN","LEFT JOIN","RIGHT JOIN","INNER JOIN","OUTER JOIN","CROSS JOIN"],ae=String.fromCodePoint(0),Mt=new RegExp(`${ae}${String.raw`(\d+)`}${ae}`,"gu"),Dt=At.map(s=>({pattern:new RegExp(String.raw`\b${s.replaceAll(" ",String.raw`\s+`)}\b`,"giu"),replacement:s})),Bt=Ot.map(s=>({pattern:new RegExp(String.raw`\s+${s.replaceAll(" ",String.raw`\s+`)}\b`,"gu"),replacement:`
2
2
  ${s}`})),$t=r(s=>{let e=[],o=s.replaceAll(/'(?:[^']|'')*'/gu,l=>(e.push(l),`${ae}${(e.length-1).toString()}${ae}`)).replaceAll(/\s+/gu," ").trim();for(let{pattern:l,replacement:a}of Dt)o=o.replaceAll(l,a);for(let{pattern:l,replacement:a}of Bt)o=o.replaceAll(l,a);return o=o.replaceAll(Mt,(l,a)=>e[Number(a)]??""),o},"formatSql"),ie=8,Pt=["AND","ASC","AS","BY","COUNT","DESC","DISTINCT","EXPLAIN","FROM","GROUP","HAVING","INNER","JOIN","LEFT","LIKE","LIMIT","NOT","NULL","OFFSET","ON","ORDER","OR","QUERY","SELECT","WHERE","WITH"],_t=new Set(["AND","BY","HAVING","ON","OR","SELECT","WHERE"]),Wt=/[\w$]/,He=r(s=>s!==void 0&&Wt.test(s),"isWordChar"),Fe=r(s=>{let e=s.length;for(;e>0&&He(s[e-1]);)e-=1;return s.slice(e)},"trailingWord"),ze=r((s,e)=>{let t=e;for(;t>0&&He(s[t-1]);)t-=1;return{end:e,start:t,text:s.slice(t,e)}},"tokenAt"),_e=r((s,e)=>{let t=s.slice(0,e).trimEnd();return t.endsWith(".")||_t.has(Fe(t).toUpperCase())},"prefersColumns"),Ht=r((s,e)=>{let t=s.slice(0,e);if(!t.endsWith("."))return;let o=Fe(t.slice(0,-1));return o===""?void 0:o},"qualifierTable"),ke=r((s,e)=>s.toLowerCase().startsWith(e.toLowerCase()),"matches"),We=r((s,e,t,o)=>{let l=[];for(let a of s)if(ke(a,e)&&(l.push(o(a)),l.length>=t))break;return l},"takeMatches"),Ft=r((s,e,t)=>{let o=new Map;for(let[l,a]of Object.entries(s.columns))for(let d of a)if(ke(d,e)&&!o.has(d)&&(o.set(d,l),o.size>=t))return[...o].map(([p,c])=>({detail:c,kind:"column",label:p}));return[...o].map(([l,a])=>({detail:a,kind:"column",label:l}))},"takeColumnMatches"),zt=r((s,e,t)=>{let o=ze(s,e),l=Ht(s,o.start);if(l!==void 0){let u=t.columns[l]??t.columns[l.toLowerCase()]??[];return We(u,o.text,ie,y=>({detail:l,kind:"column",label:y}))}if(o.text===""&&!_e(s,o.start))return[];let a=We(t.tables,o.text,ie,u=>({kind:"table",label:u})),d=Ft(t,o.text,ie),p=Pt.filter(u=>o.text!==""&&ke(u,o.text)&&u.toLowerCase()!==o.text.toLowerCase()).map(u=>({kind:"keyword",label:u}));return(_e(s,o.start)?[...d,...a,...p]:[...a,...d,...p]).slice(0,ie)},"suggestionsFor"),Ut=r((s,e,t)=>{let o=ze(s,e),l=s.slice(0,o.start)+t.label+s.slice(o.end);return{caret:o.start+t.label.length,value:l}},"acceptSuggestion"),Yt=["boxSizing","borderBottomWidth","borderLeftWidth","borderRightWidth","borderTopWidth","fontFamily","fontSize","fontStyle","fontWeight","letterSpacing","lineHeight","paddingBottom","paddingLeft","paddingRight","paddingTop","tabSize","textIndent","textTransform","width","wordSpacing"],jt=r((s,e)=>{let t=globalThis.getComputedStyle(s),o=globalThis.document.createElement("div"),{style:l}=o;l.position="absolute",l.visibility="hidden",l.whiteSpace="pre-wrap",l.overflowWrap="break-word";for(let c of Yt)l[c]=t[c];o.textContent=s.value.slice(0,Math.max(0,e));let a=globalThis.document.createElement("span");a.textContent=s.value.slice(Math.max(0,e))||".",o.append(a),globalThis.document.body.append(o);let d=a.offsetLeft-s.scrollLeft,p=a.offsetTop-s.scrollTop;return o.remove(),{left:d,top:p}},"caretOffset"),Kt=r((s,e,t)=>{let o=(0,K.c)(13),[l,a]=(0,q.useState)(null),d;o[0]!==s||o[1]!==e?(d=r((N,x)=>{let S=zt(N,x,s);if(S.length===0){a(null);return}let h=e.current,{left:w,top:C}=h===null?{left:0,top:0}:jt(h,x);a({active:0,left:w,suggestions:S,top:C})},"t0"),o[0]=s,o[1]=e,o[2]=d):d=o[2];let p=d,c;o[3]===Symbol.for("react.memo_cache_sentinel")?(c=r(()=>{a(null)},"t1"),o[3]=c):c=o[3];let u=c,y;o[4]===Symbol.for("react.memo_cache_sentinel")?(y=r(N=>{a(x=>{if(x===null)return x;let S=x.suggestions.length,h=(x.active+N+S)%S;return{...x,active:h}})},"t2"),o[4]=y):y=o[4];let g=y,v;o[5]!==t||o[6]!==l||o[7]!==e?(v=r(()=>{let N=e.current;if(l===null||N===null)return!1;let x=l.suggestions[l.active];if(x===void 0)return!1;let S=Ut(N.value,N.selectionStart,x);return t(S.value),a(null),requestAnimationFrame(()=>{let h=e.current;h!==null&&(h.focus(),h.setSelectionRange(S.caret,S.caret))}),!0},"t3"),o[5]=t,o[6]=l,o[7]=e,o[8]=v):v=o[8];let m=v,f;return o[9]!==m||o[10]!==p||o[11]!==l?(f={close:u,commit:m,move:g,refresh:p,state:l},o[9]=m,o[10]=p,o[11]=l,o[12]=f):f=o[12],f},"useSqlAutocomplete"),Gt={column:"column",keyword:"keyword",table:"table"},Vt=20,Jt=r(s=>{let e=(0,K.c)(17),{listboxId:t,onPick:o,state:l}=s,a=G(),d;e[0]!==l?(d=l===null?void 0:{left:l.left,top:l.top+Vt},e[0]=l,e[1]=d):d=e[1];let p=d;if(l===null)return null;let c;if(e[2]!==t||e[3]!==o||e[4]!==l.active||e[5]!==l.suggestions||e[6]!==a){let y;e[8]!==t||e[9]!==o||e[10]!==l.active||e[11]!==a?(y=r((g,v)=>(0,n.jsxDEV)("li",{"aria-selected":v===l.active,className:oe("flex cursor-pointer items-center gap-2 px-2 py-1 text-[13px]",v===l.active?"bg-accent text-accent-foreground":"text-foreground"),"data-testid":"sql-autocomplete-item",id:`${t}-opt-${v.toString()}`,onMouseDown:r(m=>{m.preventDefault(),o(v)},"onMouseDown"),role:"option",children:[(0,n.jsxDEV)("span",{className:"truncate font-mono",children:g.label},void 0,!1),g.detail!==void 0&&(0,n.jsxDEV)("span",{className:"ms-auto truncate text-xs text-muted-foreground",children:g.detail},void 0,!1),(0,n.jsxDEV)("span",{className:"shrink-0 font-mono text-[10px] tracking-wide text-muted-foreground/70 uppercase",children:a(Gt[g.kind])},void 0,!1)]},`${g.kind}:${g.label}`,!0),"t32"),e[8]=t,e[9]=o,e[10]=l.active,e[11]=a,e[12]=y):y=e[12],c=l.suggestions.map(y),e[2]=t,e[3]=o,e[4]=l.active,e[5]=l.suggestions,e[6]=a,e[7]=c}else c=e[7];let u;return e[13]!==t||e[14]!==p||e[15]!==c?(u=(0,n.jsxDEV)("ul",{className:"absolute z-30 max-h-56 w-72 overflow-auto rounded-md border border-border bg-popover py-1 text-popover-foreground shadow-md","data-testid":"sql-autocomplete",id:t,role:"listbox",style:p,children:c},void 0,!1),e[13]=t,e[14]=p,e[15]=c,e[16]=u):u=e[16],u},"AutocompletePopover"),Ue=[{label:"List tables",sql:"SELECT name FROM sqlite_master WHERE type = 'table' ORDER BY name;"},{label:"Table row count",sql:"SELECT COUNT(*) AS rows FROM messages;"},{label:"Recent rows",sql:"SELECT id, _creationTime, __doc__ FROM messages ORDER BY _creationTime DESC LIMIT 50;"},{label:"Index list",sql:"SELECT name, tbl_name FROM sqlite_master WHERE type = 'index' ORDER BY tbl_name;"}],Qt=r(s=>{let e=(0,K.c)(29),{active:t,onDelete:o,onSelect:l,query:a}=s,d=G(),p;e[0]!==l||e[1]!==a.id?(p=r(()=>{l(a.id)},"t1"),e[0]=l,e[1]=a.id,e[2]=p):p=e[2];let c=p,u;e[3]!==o||e[4]!==a.id?(u=r(E=>{E.stopPropagation(),o(a.id)},"t2"),e[3]=o,e[4]=a.id,e[5]=u):u=e[5];let y=u,g=t?"bg-sidebar-accent font-medium text-foreground":"text-muted-foreground",v;e[6]!==g?(v=oe("flex min-w-0 flex-1 items-center gap-2 rounded-md px-2 py-1.5 text-start text-[13px] outline-none transition-colors hover:bg-sidebar-accent focus-visible:bg-sidebar-accent",g),e[6]=g,e[7]=v):v=e[7];let m=`sql-query-${a.id}`,f;e[8]===Symbol.for("react.memo_cache_sentinel")?(f=(0,n.jsxDEV)("svg",{"aria-hidden":"true",className:"size-3.5 shrink-0 opacity-70",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,n.jsxDEV)("path",{d:"M4 6h16M4 12h10M4 18h7"},void 0,!1)},void 0,!1),e[8]=f):f=e[8];let N;e[9]!==a.name?(N=(0,n.jsxDEV)("span",{className:"truncate",children:a.name},void 0,!1),e[9]=a.name,e[10]=N):N=e[10];let x;e[11]!==t||e[12]!==c||e[13]!==v||e[14]!==m||e[15]!==N?(x=(0,n.jsxDEV)("button",{"aria-pressed":t,className:v,"data-testid":m,onClick:c,type:"button",children:[f,N]},void 0,!0),e[11]=t,e[12]=c,e[13]=v,e[14]=m,e[15]=N,e[16]=x):x=e[16];let S;e[17]!==d?(S=d("Delete query"),e[17]=d,e[18]=S):S=e[18];let h;e[19]!==d?(h=d("Delete query"),e[19]=d,e[20]=h):h=e[20];let w;e[21]===Symbol.for("react.memo_cache_sentinel")?(w=(0,n.jsxDEV)("svg",{"aria-hidden":"true",className:"size-3.5",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,n.jsxDEV)("path",{d:"M5 7h14M9 7V5h6v2m-1 0v12H10V7M7 7v13h10V7"},void 0,!1)},void 0,!1),e[21]=w):w=e[21];let C;e[22]!==y||e[23]!==h||e[24]!==S?(C=(0,n.jsxDEV)("button",{"aria-label":S,className:"me-1 hidden size-6 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-destructive/10 hover:text-destructive group-hover/q:flex",onClick:y,title:h,type:"button",children:w},void 0,!1),e[22]=y,e[23]=h,e[24]=S,e[25]=C):C=e[25];let A;return e[26]!==C||e[27]!==x?(A=(0,n.jsxDEV)("li",{className:"group/q flex items-center",children:[x,C]},void 0,!0),e[26]=C,e[27]=x,e[28]=A):A=e[28],A},"QueryRow"),Xt=r(s=>{let e=(0,K.c)(58),{activeId:t,history:o,listRef:l,onClearHistory:a,onDelete:d,onLoadHistory:p,onLoadTemplate:c,onNew:u,onSearchChange:y,onSelect:g,queries:v,search:m}=s,f=G(),N;if(e[0]!==v||e[1]!==m){let T=m.trim().toLowerCase();N=T===""?[...v]:v.filter(R=>R.name.toLowerCase().includes(T)),e[0]=v,e[1]=m,e[2]=N}else N=e[2];let x=N,S;e[3]!==f?(S=f("Search queries\u2026"),e[3]=f,e[4]=S):S=e[4];let h;e[5]!==y||e[6]!==m||e[7]!==S?(h=(0,n.jsxDEV)("input",{className:"h-8 min-w-0 flex-1 rounded-md border border-border bg-background px-2 text-xs outline-none focus-visible:border-ring","data-testid":"sql-search",onChange:y,placeholder:S,type:"text",value:m},void 0,!1),e[5]=y,e[6]=m,e[7]=S,e[8]=h):h=e[8];let w;e[9]!==f?(w=f("New query"),e[9]=f,e[10]=w):w=e[10];let C;e[11]!==f?(C=f("New query"),e[11]=f,e[12]=C):C=e[12];let A;e[13]===Symbol.for("react.memo_cache_sentinel")?(A=(0,n.jsxDEV)("svg",{"aria-hidden":"true",className:"size-4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.7,viewBox:"0 0 24 24",children:(0,n.jsxDEV)("path",{d:"M12 5v14M5 12h14"},void 0,!1)},void 0,!1),e[13]=A):A=e[13];let E;e[14]!==u||e[15]!==w||e[16]!==C?(E=(0,n.jsxDEV)("button",{"aria-label":w,className:"flex size-8 shrink-0 items-center justify-center rounded-md border border-border text-foreground outline-none transition-colors hover:bg-accent focus-visible:bg-accent","data-testid":"sql-new",onClick:u,title:C,type:"button",children:A},void 0,!1),e[14]=u,e[15]=w,e[16]=C,e[17]=E):E=e[17];let M;e[18]!==h||e[19]!==E?(M=(0,n.jsxDEV)("div",{className:"flex shrink-0 items-center gap-2 border-b border-border p-2",children:[h,E]},void 0,!0),e[18]=h,e[19]=E,e[20]=M):M=e[20];let D;e[21]!==f?(D=f("Private"),e[21]=f,e[22]=D):D=e[22];let O;e[23]!==D?(O=(0,n.jsxDEV)("p",{className:"px-1 pb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:D},void 0,!1),e[23]=D,e[24]=O):O=e[24];let B;e[25]!==t||e[26]!==x||e[27]!==l||e[28]!==d||e[29]!==g||e[30]!==f?(B=x.length===0?(0,n.jsxDEV)("p",{className:"px-1 py-2 text-xs text-muted-foreground","data-testid":"sql-private-empty",children:f("No saved queries yet \u2014 they save to this browser as you type.")},void 0,!1):(0,n.jsxDEV)("ul",{className:"flex flex-col gap-px","data-testid":"sql-private",ref:l,children:x.map(T=>(0,n.jsxDEV)(Qt,{active:t===T.id,onDelete:d,onSelect:g,query:T},T.id,!1))},void 0,!1),e[25]=t,e[26]=x,e[27]=l,e[28]=d,e[29]=g,e[30]=f,e[31]=B):B=e[31];let P;e[32]!==O||e[33]!==B?(P=(0,n.jsxDEV)("div",{children:[O,B]},void 0,!0),e[32]=O,e[33]=B,e[34]=P):P=e[34];let _;e[35]!==f?(_=f("Reference"),e[35]=f,e[36]=_):_=e[36];let Y;e[37]!==_?(Y=(0,n.jsxDEV)("p",{className:"px-1 pb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:_},void 0,!1),e[37]=_,e[38]=Y):Y=e[38];let F;e[39]!==c?(F=Ue.map(T=>(0,n.jsxDEV)("li",{children:(0,n.jsxDEV)("button",{className:"flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-start text-[13px] text-muted-foreground outline-none transition-colors hover:bg-sidebar-accent hover:text-foreground focus-visible:bg-sidebar-accent","data-sql":T.sql,onClick:c,type:"button",children:[(0,n.jsxDEV)("svg",{"aria-hidden":"true",className:"size-3.5 shrink-0 opacity-70",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,n.jsxDEV)("path",{d:"M7 4h7l4 4v12H7zM14 4v4h4"},void 0,!1)},void 0,!1),T.label]},void 0,!0)},T.label,!1)),e[39]=c,e[40]=F):F=e[40];let $;e[41]!==F?($=(0,n.jsxDEV)("ul",{className:"flex flex-col gap-px",children:F},void 0,!1),e[41]=F,e[42]=$):$=e[42];let I;e[43]!==Y||e[44]!==$?(I=(0,n.jsxDEV)("div",{children:[Y,$]},void 0,!0),e[43]=Y,e[44]=$,e[45]=I):I=e[45];let L;e[46]!==o||e[47]!==a||e[48]!==p||e[49]!==f?(L=o.length>0&&(0,n.jsxDEV)("div",{children:[(0,n.jsxDEV)("div",{className:"flex items-center justify-between px-1 pb-1",children:[(0,n.jsxDEV)("p",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:f("History")},void 0,!1),(0,n.jsxDEV)("button",{className:"rounded px-1 text-[11px] text-muted-foreground outline-none transition-colors hover:text-foreground focus-visible:text-foreground","data-testid":"sql-history-clear",onClick:a,type:"button",children:f("Clear history")},void 0,!1)]},void 0,!0),(0,n.jsxDEV)("ul",{className:"flex flex-col gap-px","data-testid":"sql-history",children:o.map(T=>(0,n.jsxDEV)("li",{children:(0,n.jsxDEV)("button",{className:"flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-start text-[13px] text-muted-foreground outline-none transition-colors hover:bg-sidebar-accent hover:text-foreground focus-visible:bg-sidebar-accent","data-sql":T.sql,"data-testid":"sql-history-item",onClick:p,title:T.sql,type:"button",children:[(0,n.jsxDEV)("svg",{"aria-hidden":"true",className:"size-3.5 shrink-0 opacity-70",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,n.jsxDEV)("path",{d:"M12 8v4l3 2M12 21a9 9 0 1 1 0-18 9 9 0 0 1 0 18Z"},void 0,!1)},void 0,!1),(0,n.jsxDEV)("span",{className:"truncate font-mono",children:T.sql},void 0,!1)]},void 0,!0)},`${T.at.toString()}:${T.sql}`,!1))},void 0,!1)]},void 0,!0),e[46]=o,e[47]=a,e[48]=p,e[49]=f,e[50]=L):L=e[50];let W;e[51]!==P||e[52]!==I||e[53]!==L?(W=(0,n.jsxDEV)("div",{className:"flex flex-1 flex-col gap-4 overflow-y-auto p-2",children:[P,I,L]},void 0,!0),e[51]=P,e[52]=I,e[53]=L,e[54]=W):W=e[54];let H;return e[55]!==W||e[56]!==M?(H=(0,n.jsxDEV)("aside",{className:"flex h-full w-64 shrink-0 flex-col border-e border-border bg-sidebar",children:[M,W]},void 0,!0),e[55]=W,e[56]=M,e[57]=H):H=e[57],H},"SqlQuerySidebar"),Zt=ne(le.listTables),eo=ne(le.readTablePage),to=r(s=>{let e=(0,K.c)(16),t=he(),o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o=[],e[0]=o):o=e[0];let[l,a]=(0,q.useState)(o),d;e[1]===Symbol.for("react.memo_cache_sentinel")?(d={},e[1]=d):d=e[1];let[p,c]=(0,q.useState)(d),u;e[2]===Symbol.for("react.memo_cache_sentinel")?(u=new Set,e[2]=u):u=e[2];let y=(0,q.useRef)(u),g,v;e[3]!==t||e[4]!==s?(g=r(()=>{let h={cancelled:!1};return Q(r(async()=>{try{let C=await t.query(Zt,{},se(s));h.cancelled||(a(C.map(no)),c({}),y.current=new Set)}catch{h.cancelled||(a([]),c({}),y.current=new Set)}},"load")()),()=>{h.cancelled=!0}},"t3"),v=[t,s],e[3]=t,e[4]=s,e[5]=g,e[6]=v):(g=e[5],v=e[6]),(0,q.useEffect)(g,v);let m;e[7]!==t||e[8]!==s?(m=r(h=>{if(y.current.has(h))return;y.current.add(h),Q(r(async()=>{try{let C=await t.query(eo,{limit:1,offset:0,table:h},se(s));c(A=>({...A,[h]:C.columns}))}catch{y.current.delete(h)}},"fetchColumns")())},"t5"),e[7]=t,e[8]=s,e[9]=m):m=e[9];let f=m,N;e[10]!==p||e[11]!==l?(N={columns:p,tables:l},e[10]=p,e[11]=l,e[12]=N):N=e[12];let x=N,S;return e[13]!==f||e[14]!==x?(S={probe:f,schema:x},e[13]=f,e[14]=x,e[15]=S):S=e[15],S},"useSqlSchema"),ye=/\b(?:from|join|update|into)\s+([a-z_][\w$]*)|\b([a-z_][\w$]*)\s*\./gi,oo=r(s=>{let e=new Set;ye.lastIndex=0;let t=ye.exec(s);for(;t!==null;)e.add(t[1]??t[2]),t=ye.exec(s);return[...e]},"referencedTables");function no(s){return s.name}r(no,"_temp$2");var so="lunora-studio-sql-tabs",lo="lunora-studio-sql-active-tab",Se=12,X=r((s="",e="")=>({activeId:null,id:ge("tab"),name:e,sql:s}),"makeTab"),ro=r(()=>ve(lo,""),"usePersistedActive"),io=r(s=>{let[e,t]=re(so),[o,l]=ro(),a=(0,q.useRef)(null);e.length===0&&a.current===null&&(a.current=s()),(0,q.useEffect)(()=>{if(e.length===0&&a.current!==null){let c=a.current;t([c])}},[t,e.length]);let d=e.length===0&&a.current!==null?[a.current]:e;return{activeId:d.some(c=>c.id===o)?o:d[0]?.id??"",setActiveId:l,setTabs:t,tabs:d}},"usePersistedTabs"),Ye=r(s=>s.activeId===null&&s.sql.trim()!=="","isDirty"),ao=r((s,e)=>[...s,e].slice(-Se),"addTab"),co=r((s,e,t)=>{let o=s.findIndex(d=>d.id===e);if(o===-1)return{activeId:s[0]?.id??"",tabs:[...s]};let l=s.filter(d=>d.id!==e);if(l.length===0){let d=t();return{activeId:d.id,tabs:[d]}}return{activeId:l[Math.min(o,l.length-1)].id,tabs:l}},"closeTab"),uo=r((s,e)=>{let t=s.filter(o=>o.id===e);return t.length===0?{activeId:s[0]?.id??"",tabs:[...s]}:{activeId:e,tabs:t}},"closeOtherTabs"),fo=r((s,e,t)=>{let o=s.findIndex(a=>a.id===e);if(o===-1)return{activeId:t,tabs:[...s]};let l=s.slice(0,o+1);return{activeId:l.some(a=>a.id===t)?t:e,tabs:l}},"closeTabsToRight"),mo=r(s=>{let e=s();return{activeId:e.id,tabs:[e]}},"closeAllTabs"),po=r((s,e,t)=>{if(s==="others")return e.filter(o=>o.id!==t);if(s==="right"){let o=e.findIndex(l=>l.id===t);return o===-1?[]:e.slice(o+1)}return[...e]},"tabsClosedBy"),bo=r((s,e)=>s.trim()===""?e:(s.split(`
3
3
  `)[0]??s).slice(0,24),"derivedTabLabel"),ho=r(s=>{let e=(0,K.c)(14),{initial:t,onCancel:o,onCommit:l,placeholder:a,testId:d}=s,p=G(),c=xo,u;e[0]!==l?(u=r(N=>{l(N.currentTarget.value.trim())},"t1"),e[0]=l,e[1]=u):u=e[1];let y=u,g;e[2]!==o||e[3]!==l?(g=r(N=>{N.key==="Enter"?l(N.currentTarget.value.trim()):N.key==="Escape"&&o()},"t2"),e[2]=o,e[3]=l,e[4]=g):g=e[4];let v=g,m;e[5]!==p?(m=p("Tab title"),e[5]=p,e[6]=m):m=e[6];let f;return e[7]!==t||e[8]!==y||e[9]!==v||e[10]!==a||e[11]!==m||e[12]!==d?(f=(0,n.jsxDEV)("input",{"aria-label":m,className:"w-40 rounded border border-ring bg-background px-1 py-0.5 text-xs outline-none","data-testid":d,defaultValue:t,onBlur:y,onKeyDown:v,placeholder:a,ref:c,type:"text"},void 0,!1),e[7]=t,e[8]=y,e[9]=v,e[10]=a,e[11]=m,e[12]=d,e[13]=f):f=e[13],f},"TabRenameInput"),vo=r(s=>{let e=(0,K.c)(29),{idBase:t,onDiscard:o,onKeep:l}=s,a=G(),d=`sql-tab-close-prompt-${t}`,p;e[0]!==a?(p=a("Discard?"),e[0]=a,e[1]=p):p=e[1];let c;e[2]!==p?(c=(0,n.jsxDEV)("span",{className:"text-[11px] text-muted-foreground",children:p},void 0,!1),e[2]=p,e[3]=c):c=e[3];let u;e[4]!==a?(u=a("Discard changes"),e[4]=a,e[5]=u):u=e[5];let y=`sql-tab-close-confirm-${t}`,g;e[6]!==a?(g=a("Discard changes"),e[6]=a,e[7]=g):g=e[7];let v;e[8]===Symbol.for("react.memo_cache_sentinel")?(v=(0,n.jsxDEV)("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2.4,viewBox:"0 0 24 24",children:(0,n.jsxDEV)("path",{d:"M5 13l4 4L19 7"},void 0,!1)},void 0,!1),e[8]=v):v=e[8];let m;e[9]!==o||e[10]!==u||e[11]!==y||e[12]!==g?(m=(0,n.jsxDEV)("button",{"aria-label":u,className:"flex size-5 items-center justify-center rounded text-destructive hover:bg-destructive/10","data-testid":y,onClick:o,title:g,type:"button",children:v},void 0,!1),e[9]=o,e[10]=u,e[11]=y,e[12]=g,e[13]=m):m=e[13];let f;e[14]!==a?(f=a("Keep editing"),e[14]=a,e[15]=f):f=e[15];let N=`sql-tab-close-cancel-${t}`,x;e[16]!==a?(x=a("Keep editing"),e[16]=a,e[17]=x):x=e[17];let S;e[18]===Symbol.for("react.memo_cache_sentinel")?(S=(0,n.jsxDEV)("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2.4,viewBox:"0 0 24 24",children:(0,n.jsxDEV)("path",{d:"M6 6l12 12M18 6 6 18"},void 0,!1)},void 0,!1),e[18]=S):S=e[18];let h;e[19]!==l||e[20]!==N||e[21]!==x||e[22]!==f?(h=(0,n.jsxDEV)("button",{"aria-label":f,className:"flex size-5 items-center justify-center rounded text-muted-foreground hover:bg-accent","data-testid":N,onClick:l,title:x,type:"button",children:S},void 0,!1),e[19]=l,e[20]=N,e[21]=x,e[22]=f,e[23]=h):h=e[23];let w;return e[24]!==d||e[25]!==h||e[26]!==c||e[27]!==m?(w=(0,n.jsxDEV)("span",{className:"flex shrink-0 items-center gap-1","data-testid":d,role:"group",children:[c,m,h]},void 0,!0),e[24]=d,e[25]=h,e[26]=c,e[27]=m,e[28]=w):w=e[28],w},"TabCloseConfirm"),go=r(s=>{let e=(0,K.c)(47),{active:t,canClose:o,onClose:l,onMenu:a,onRename:d,onSelect:p,tab:c}=s,u=G(),[y,g]=(0,q.useState)(!1),[v,m]=(0,q.useState)(!1),f;e[0]!==a||e[1]!==c.id?(f=r(z=>{a(c.id,z)},"t1"),e[0]=a,e[1]=c.id,e[2]=f):f=e[2];let N=f,x;e[3]!==p||e[4]!==c.id?(x=r(()=>{p(c.id)},"t2"),e[3]=p,e[4]=c.id,e[5]=x):x=e[5];let S=x,h;e[6]===Symbol.for("react.memo_cache_sentinel")?(h=r(()=>{g(!0)},"t3"),e[6]=h):h=e[6];let w=h,C;e[7]!==l||e[8]!==c?(C=r(z=>{z.stopPropagation(),Ye(c)?m(!0):l(c.id)},"t4"),e[7]=l,e[8]=c,e[9]=C):C=e[9];let A=C,E;e[10]!==l||e[11]!==c.id?(E=r(z=>{z.stopPropagation(),m(!1),l(c.id)},"t5"),e[10]=l,e[11]=c.id,e[12]=E):E=e[12];let M=E,D;e[13]===Symbol.for("react.memo_cache_sentinel")?(D=r(z=>{z.stopPropagation(),m(!1)},"t6"),e[13]=D):D=e[13];let O=D,B;e[14]!==d||e[15]!==c.id?(B=r(z=>{d(c.id,z),g(!1)},"t7"),e[14]=d,e[15]=c.id,e[16]=B):B=e[16];let P=B,_;e[17]===Symbol.for("react.memo_cache_sentinel")?(_=r(()=>{g(!1)},"t8"),e[17]=_):_=e[17];let Y=_,F;e[18]!==c.name?(F=c.name.trim(),e[18]=c.name,e[19]=F):F=e[19];let $=F,I;e[20]!==u||e[21]!==c.sql?(I=bo(c.sql,u("Untitled")),e[20]=u,e[21]=c.sql,e[22]=I):I=e[22];let L=I,W=t?"bg-background text-foreground":"bg-muted/40 text-muted-foreground hover:text-foreground",H;e[23]!==W?(H=oe("group/tab flex shrink-0 items-center gap-1 border-e border-border ps-3 pe-1.5 text-xs",W),e[23]=W,e[24]=H):H=e[24];let T=`sql-tab-${c.id}`,R;e[25]!==t||e[26]!==P||e[27]!==$||e[28]!==L||e[29]!==y||e[30]!==S||e[31]!==u||e[32]!==c.id?(R=y?(0,n.jsxDEV)(ho,{initial:$,onCancel:Y,onCommit:P,placeholder:L,testId:`sql-tab-rename-${c.id}`},void 0,!1):(0,n.jsxDEV)("button",{"aria-pressed":t,className:"max-w-40 truncate py-1.5 outline-none","data-testid":`sql-tab-select-${c.id}`,onClick:S,onDoubleClick:w,title:u("Double-click to rename"),type:"button",children:$===""?L:$},void 0,!1),e[25]=t,e[26]=P,e[27]=$,e[28]=L,e[29]=y,e[30]=S,e[31]=u,e[32]=c.id,e[33]=R):R=e[33];let j;e[34]!==o||e[35]!==M||e[36]!==v||e[37]!==A||e[38]!==u||e[39]!==c.id?(j=o&&(v?(0,n.jsxDEV)(vo,{idBase:c.id,onDiscard:M,onKeep:O},void 0,!1):(0,n.jsxDEV)("button",{"aria-label":u("Close tab"),className:"flex size-5 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-destructive/10 hover:text-destructive","data-testid":`sql-tab-close-${c.id}`,onClick:A,title:u("Close tab"),type:"button",children:(0,n.jsxDEV)("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,viewBox:"0 0 24 24",children:(0,n.jsxDEV)("path",{d:"M6 6l12 12M18 6 6 18"},void 0,!1)},void 0,!1)},void 0,!1)),e[34]=o,e[35]=M,e[36]=v,e[37]=A,e[38]=u,e[39]=c.id,e[40]=j):j=e[40];let J;return e[41]!==N||e[42]!==H||e[43]!==T||e[44]!==R||e[45]!==j?(J=(0,n.jsxDEV)("div",{className:H,"data-testid":T,onContextMenu:N,children:[R,j]},void 0,!0),e[41]=N,e[42]=H,e[43]=T,e[44]=R,e[45]=j,e[46]=J):J=e[46],J},"TabButton");function xo(s){s?.focus(),s?.select()}r(xo,"_temp$1");var yo=ne(le.runSql),No="lunora-studio-sql-queries",So="lunora-studio-sql-history",ko="lunora-studio-sql-split-view",Co=25,wo={minWidth:"2.75rem",paddingInline:"0.5rem"},Ne={error:null,pane:"results",result:null},To=r(s=>{let e=(0,K.c)(16),{result:t}=s;if(t.columns.length===0){let c=t.rowCount===0?"0 rows":"",u;return e[0]!==c?(u=(0,n.jsxDEV)("p",{className:"p-4 text-sm text-muted-foreground",children:c},void 0,!1),e[0]=c,e[1]=u):u=e[1],u}let o;e[2]!==t.columns?(o=t.columns.map(Eo),e[2]=t.columns,e[3]=o):o=e[3];let l;e[4]!==o?(l=(0,n.jsxDEV)(Ae,{className:"sticky top-0 z-10 bg-muted",children:(0,n.jsxDEV)(xe,{children:o},void 0,!1)},void 0,!1),e[4]=o,e[5]=l):l=e[5];let a;if(e[6]!==t.columns||e[7]!==t.rows){let c;e[9]!==t.columns?(c=r((u,y)=>(0,n.jsxDEV)(xe,{"data-testid":"sql-row",children:t.columns.map(g=>(0,n.jsxDEV)(De,{className:"max-w-md truncate font-mono text-xs",children:(0,n.jsxDEV)(Be,{value:u[g]},void 0,!1)},g,!1))},y,!1),"t42"),e[9]=t.columns,e[10]=c):c=e[10],a=t.rows.map(c),e[6]=t.columns,e[7]=t.rows,e[8]=a}else a=e[8];let d;e[11]!==a?(d=(0,n.jsxDEV)(Oe,{children:a},void 0,!1),e[11]=a,e[12]=d):d=e[12];let p;return e[13]!==l||e[14]!==d?(p=(0,n.jsxDEV)(Le,{"data-testid":"sql-rows",children:[l,d]},void 0,!0),e[13]=l,e[14]=d,e[15]=p):p=e[15],p},"SqlResultTable"),Ho=r(({initialShardKey:s})=>{let e=he(),t=G(),[o,l]=re(No),[a,d]=re(So),[p,c]=(0,q.useState)(""),u=r(()=>X(Ue[0]?.sql??""),"seedTab"),{activeId:y,setActiveId:g,setTabs:v,tabs:m}=io(u),[f,N]=(0,q.useState)({}),[x,S]=(0,q.useState)(s??""),[h,w]=(0,q.useState)(!1),[C,A]=ve(ko,!1),[E,M]=(0,q.useState)(null),[D,O]=(0,q.useState)(null),B=(0,q.useRef)(null),P=(0,q.useRef)(null),_=(0,q.useRef)(null),Y=(0,q.useId)(),{probe:F,schema:$}=to(x),I=m.find(i=>i.id===y)??m[0]??X(),L=I.sql,{activeId:W}=I,H=f[I.id]??Ne,{error:T,result:R}=H,j=H.pane,J=r(i=>{v(b=>b.map(k=>k.id===I.id?{...k,...i}:k))},"patchActiveTab"),z=r(i=>{N(b=>{let k=b[I.id]??Ne;return{...b,[I.id]:{error:i.error,pane:i.pane??k.pane,result:i.result}}})},"setActiveOutput"),Ce=r(i=>{N(b=>{let k=b[I.id]??Ne;return{...b,[I.id]:{...k,pane:i}}})},"setActivePane"),ce=r(i=>{J({sql:i}),W!==null&&l(b=>b.map(k=>k.id===W?{...k,sql:i}:k))},"setDraft"),je=Kt($,P,ce),{close:de,commit:we,move:ue,refresh:Z,state:V}=je,Ke=r(i=>{ue(i-(V?.active??0)),we()},"onPickSuggestion");(0,q.useEffect)(()=>{let i=P.current;i!==null&&i===document.activeElement&&Z(i.value,i.selectionStart)},[Z,$]);let Ge=r(i=>{d(b=>b[0]?.sql===i?b:[{at:Date.now(),sql:i},...b.filter(U=>U.sql!==i)].slice(0,Co))},"recordHistory"),fe=r(async i=>{if(L.trim()==="")return;w(!0);let b=i==="explain"?`EXPLAIN QUERY PLAN ${L}`:L;try{let k=await e.query(yo,{sql:b},se(x));z({error:null,pane:i,result:k}),qe(x),Ge(b)}catch(k){z({error:Ee(k),pane:i,result:null})}finally{w(!1)}},"run"),Ve=r(()=>{Q(fe("results"))},"onRun"),Je=r(i=>{let{selectionStart:b,value:k}=i.target;ce(k);for(let U of oo(k))F(U);Z(k,b)},"onDraftChange"),Qe=r(i=>{let b=i.currentTarget;Z(b.value,b.selectionStart)},"onEditorSelect"),Xe=r(i=>{if(V!==null){if(i.key==="ArrowDown"){i.preventDefault(),ue(1);return}if(i.key==="ArrowUp"){i.preventDefault(),ue(-1);return}if(i.key==="Escape"){i.preventDefault(),de();return}if((i.key==="Enter"||i.key==="Tab")&&!i.metaKey&&!i.ctrlKey&&we()){i.preventDefault();return}}(i.metaKey||i.ctrlKey)&&i.key==="Enter"&&(i.preventDefault(),Q(fe(j)))},"onEditorKeyDown"),Ze=r(()=>{requestAnimationFrame(()=>{de()})},"onEditorBlur"),et=r(i=>{B.current!==null&&(B.current.scrollTop=i.currentTarget.scrollTop)},"onEditorScroll"),ee=r((i,b)=>{v(k=>k.map(U=>U.id===I.id?{...U,activeId:b,sql:i}:U)),z({error:null,result:null})},"loadIntoActiveTab"),tt=r(()=>{let i={id:ge("q"),name:t("Untitled query"),sql:""};l(b=>[i,...b]),ee("",i.id)},"newQuery"),ot=r(i=>{let b=o.find(k=>k.id===i);b!==void 0&&(ee(b.sql,i),_.current?.querySelector(`[data-testid="sql-query-${i}"]`)?.scrollIntoView({block:"nearest"}))},"selectQuery"),nt=r(i=>{l(b=>b.filter(k=>k.id!==i)),v(b=>b.map(k=>k.activeId===i?{...k,activeId:null}:k))},"deleteQuery"),st=r(i=>{ee(i.currentTarget.dataset.sql??"",null)},"loadTemplate"),lt=r(i=>{ee(i.currentTarget.dataset.sql??"",null)},"loadFromHistory"),rt=r(()=>{d([])},"clearHistory"),it=r(()=>{ce($t(L))},"formatDraft"),at=r(()=>{if(m.length>=Se)return;let i=X();v(b=>ao(b,i)),g(i.id)},"addEditorTab"),te=r(i=>{M(null),O(null),v(i.tabs),g(i.activeId);let b=new Set(i.tabs.map(k=>k.id));N(k=>Object.fromEntries(Object.entries(k).filter(([U])=>b.has(U))))},"commitTabs"),ct=r(i=>{te(co(m,i,X))},"closeEditorTab"),Te=r((i,b)=>{te(i==="others"?uo(m,b):i==="right"?fo(m,b,y):mo(X))},"applyBulk"),me=r(i=>{E!==null&&(po(i,m,E.id).some(b=>Ye(b))?O(i):Te(i,E.id))},"requestBulk"),dt=r((i,b)=>{b.preventDefault(),O(null),M({id:i,x:b.clientX,y:b.clientY})},"openTabMenu"),ut=r(()=>{M(null),O(null)},"closeTabMenu"),ft=r(i=>{i.preventDefault(),M(null),O(null)},"onBackdropContextMenu"),mt=r(()=>{me("others")},"onCloseOthers"),pt=r(()=>{me("right")},"onCloseToRight"),bt=r(()=>{me("all")},"onCloseAll"),ht=r(()=>{E!==null&&D!==null&&Te(D,E.id),O(null)},"confirmBulk"),vt=r(()=>{O(null)},"cancelBulk"),gt=E===null?void 0:{left:E.x,top:E.y},xt=r(i=>{de(),g(i)},"selectTab"),yt=r((i,b)=>{v(k=>k.map(U=>U.id===i?{...U,name:b}:U))},"renameTab"),Nt=r(()=>{Ce("results")},"showResults"),St=r(()=>{Q(fe("explain"))},"showExplain"),kt=r(()=>{Ce("chart")},"showChart"),Ct=r(()=>{A(!C)},"toggleSplit"),wt=L.split(`
4
4
  `).length,Tt=r(i=>{c(i.target.value)},"onSearchChange"),pe=r(i=>`border-b-2 px-3 py-2 text-sm outline-none transition-colors ${i?"border-foreground font-medium text-foreground":"border-transparent text-muted-foreground hover:text-foreground"}`,"tabClass"),Et=C?"flex min-h-0 flex-1 flex-row":"flex min-h-0 flex-1 flex-col",qt=C?"flex w-2/5 min-h-0 min-w-0 shrink-0 flex-col border-s border-border":"flex h-2/5 min-h-0 shrink-0 flex-col border-t border-border";return(0,n.jsxDEV)("div",{className:"flex h-full min-w-0","data-testid":"lunora-sql-editor",children:[(0,n.jsxDEV)(Xt,{activeId:W,history:a,listRef:_,onClearHistory:rt,onDelete:nt,onLoadHistory:lt,onLoadTemplate:st,onNew:tt,onSearchChange:Tt,onSelect:ot,queries:o,search:p},void 0,!1),(0,n.jsxDEV)("div",{className:"flex min-w-0 flex-1 flex-col",children:[(0,n.jsxDEV)("div",{className:"flex shrink-0 items-stretch overflow-x-auto border-b border-border bg-muted/30","data-testid":"sql-tab-strip",role:"tablist",children:[m.map(i=>(0,n.jsxDEV)(go,{active:i.id===I.id,canClose:m.length>1,onClose:ct,onMenu:dt,onRename:yt,onSelect:xt,tab:i},i.id,!1)),(0,n.jsxDEV)("button",{"aria-label":t("New tab"),className:"flex size-8 shrink-0 items-center justify-center text-muted-foreground outline-none transition-colors hover:bg-accent hover:text-foreground focus-visible:bg-accent disabled:pointer-events-none disabled:opacity-40","data-testid":"sql-tab-add",disabled:m.length>=Se,onClick:at,title:t("New tab"),type:"button",children:(0,n.jsxDEV)("svg",{"aria-hidden":"true",className:"size-4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.7,viewBox:"0 0 24 24",children:(0,n.jsxDEV)("path",{d:"M12 5v14M5 12h14"},void 0,!1)},void 0,!1)},void 0,!1)]},void 0,!0),E!==null&&(0,n.jsxDEV)(n.Fragment,{children:[(0,n.jsxDEV)("div",{className:"fixed inset-0 z-40","data-testid":"sql-tab-menu-backdrop",onClick:ut,onContextMenu:ft,role:"presentation"},void 0,!1),(0,n.jsxDEV)("div",{className:"fixed z-50 min-w-44 rounded-md border border-border bg-popover py-1 text-popover-foreground shadow-md","data-testid":"sql-tab-menu",role:"menu",style:gt,children:D===null?(0,n.jsxDEV)(n.Fragment,{children:[(0,n.jsxDEV)("button",{className:"flex w-full items-center px-3 py-1.5 text-start text-xs outline-none hover:bg-accent focus-visible:bg-accent disabled:pointer-events-none disabled:opacity-40","data-testid":"sql-tab-menu-close-others",disabled:m.length<=1,onClick:mt,role:"menuitem",type:"button",children:t("Close other tabs")},void 0,!1),(0,n.jsxDEV)("button",{className:"flex w-full items-center px-3 py-1.5 text-start text-xs outline-none hover:bg-accent focus-visible:bg-accent disabled:pointer-events-none disabled:opacity-40","data-testid":"sql-tab-menu-close-right",disabled:m.findIndex(i=>i.id===E.id)>=m.length-1,onClick:pt,role:"menuitem",type:"button",children:t("Close tabs to the right")},void 0,!1),(0,n.jsxDEV)("button",{className:"flex w-full items-center px-3 py-1.5 text-start text-xs outline-none hover:bg-accent focus-visible:bg-accent","data-testid":"sql-tab-menu-close-all",onClick:bt,role:"menuitem",type:"button",children:t("Close all tabs")},void 0,!1)]},void 0,!0):(0,n.jsxDEV)("div",{className:"px-3 py-1.5","data-testid":"sql-tab-menu-confirm",children:[(0,n.jsxDEV)("p",{className:"pb-1.5 text-xs text-muted-foreground",children:t("Discard unsaved tabs?")},void 0,!1),(0,n.jsxDEV)("div",{className:"flex items-center gap-1.5",children:[(0,n.jsxDEV)("button",{className:"rounded px-2 py-1 text-xs font-medium text-destructive outline-none hover:bg-destructive/10 focus-visible:bg-destructive/10","data-testid":"sql-tab-menu-confirm-discard",onClick:ht,type:"button",children:t("Discard")},void 0,!1),(0,n.jsxDEV)("button",{className:"rounded px-2 py-1 text-xs text-muted-foreground outline-none hover:bg-accent focus-visible:bg-accent","data-testid":"sql-tab-menu-confirm-cancel",onClick:vt,type:"button",children:t("Cancel")},void 0,!1)]},void 0,!0)]},void 0,!0)},void 0,!1)]},void 0,!0),(0,n.jsxDEV)("div",{className:Et,children:[(0,n.jsxDEV)("div",{className:"flex min-h-0 min-w-0 flex-1",children:[(0,n.jsxDEV)("div",{"aria-hidden":"true",className:"shrink-0 select-none overflow-hidden border-e border-border bg-muted/30 py-3 text-end font-mono text-xs leading-5 text-muted-foreground/60",ref:B,style:wo,children:Array.from({length:wt},(i,b)=>(0,n.jsxDEV)("div",{children:b+1},b,!1))},void 0,!1),(0,n.jsxDEV)("div",{className:"relative min-w-0 flex-1",children:[(0,n.jsxDEV)("textarea",{"aria-activedescendant":V===null?void 0:`${Y}-opt-${V.active.toString()}`,"aria-autocomplete":"list","aria-controls":V===null?void 0:Y,"aria-expanded":V!==null,"aria-label":t("SQL query"),className:"size-full resize-none bg-background p-3 font-mono text-xs leading-5 outline-none","data-testid":"sql-input",onBlur:Ze,onChange:Je,onKeyDown:Xe,onScroll:et,onSelect:Qe,placeholder:"SELECT * FROM \u2026",ref:P,role:"combobox",spellCheck:!1,value:L},void 0,!1),(0,n.jsxDEV)(Jt,{listboxId:Y,onPick:Ke,state:V},void 0,!1)]},void 0,!0)]},void 0,!0),(0,n.jsxDEV)("div",{className:qt,children:[(0,n.jsxDEV)("div",{className:"flex shrink-0 items-center gap-2 border-b border-border pe-2",children:[(0,n.jsxDEV)("button",{className:pe(j==="results"),"data-testid":"sql-tab-results",onClick:Nt,type:"button",children:t("Results")},void 0,!1),(0,n.jsxDEV)("button",{className:pe(j==="chart"),"data-testid":"sql-tab-chart",onClick:kt,type:"button",children:t("Chart")},void 0,!1),(0,n.jsxDEV)("button",{className:pe(j==="explain"),"data-testid":"sql-tab-explain",onClick:St,type:"button",children:t("Explain")},void 0,!1),(0,n.jsxDEV)("div",{className:"ms-auto flex items-center gap-2",children:[(0,n.jsxDEV)("button",{"aria-label":t("Split editor and results"),"aria-pressed":C,className:`inline-flex items-center rounded-md border border-border px-2 py-1.5 outline-none transition-colors hover:bg-accent focus-visible:bg-accent ${C?"bg-accent text-foreground":"text-muted-foreground"}`,"data-testid":"sql-split-toggle",onClick:Ct,title:t("Split editor and results"),type:"button",children:(0,n.jsxDEV)("svg",{"aria-hidden":"true",className:"size-4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.7,viewBox:"0 0 24 24",children:[(0,n.jsxDEV)("rect",{height:"16",rx:"2",width:"18",x:"3",y:"4"},void 0,!1),(0,n.jsxDEV)("path",{d:"M12 4v16"},void 0,!1)]},void 0,!0)},void 0,!1),R!==null&&R.columns.length>0&&(0,n.jsxDEV)($e,{columns:R.columns,name:"query-result",rows:R.rows},void 0,!1),(0,n.jsxDEV)("button",{className:"inline-flex items-center rounded-md border border-border px-3 py-1.5 text-xs font-medium text-foreground outline-none transition-colors hover:bg-accent focus-visible:bg-accent disabled:pointer-events-none disabled:opacity-50","data-testid":"sql-format",disabled:h,onClick:it,type:"button",children:t("Format")},void 0,!1),(0,n.jsxDEV)(Ie,{onChange:S,testId:"sql-shard-input",value:x},void 0,!1),(0,n.jsxDEV)("button",{className:"inline-flex items-center gap-1.5 rounded-md bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground outline-none transition-colors hover:bg-primary/90 focus-visible:bg-primary/90 disabled:pointer-events-none disabled:opacity-50","data-testid":"sql-run",disabled:h,onClick:Ve,type:"button",children:[t(h?"Running\u2026":"Run"),(0,n.jsxDEV)("kbd",{className:"rounded border border-primary-foreground/30 px-1 font-sans text-[10px]",children:"\u2318\u21B5"},void 0,!1)]},void 0,!0)]},void 0,!0)]},void 0,!0),(0,n.jsxDEV)("div",{className:"min-h-0 flex-1 overflow-auto",children:[T!==null&&(0,n.jsxDEV)(Re,{className:"m-3 font-mono text-xs",testId:"sql-error",variant:"destructive",children:T},void 0,!1),T===null&&R===null&&(0,n.jsxDEV)("p",{className:"p-4 text-sm text-muted-foreground","data-testid":"sql-empty",children:t("Click Run to execute your query.")},void 0,!1),T===null&&R!==null&&(0,n.jsxDEV)("div",{"data-testid":"sql-result",children:[j==="chart"?(0,n.jsxDEV)(Pe,{result:R},void 0,!1):(0,n.jsxDEV)(To,{result:R},void 0,!1),(0,n.jsxDEV)("p",{className:"border-t border-border px-3 py-1.5 text-xs text-muted-foreground","data-testid":"sql-count",children:R.truncated?t("Showing the first {max} of {count} rows.",{count:R.rowCount,max:R.rows.length}):t("{count} rows",{count:R.rowCount})},void 0,!1)]},void 0,!0)]},void 0,!0)]},void 0,!0)]},void 0,!0)]},void 0,!0)]},void 0,!0)},"SqlEditorPanel");function Eo(s){return(0,n.jsxDEV)(Me,{children:s},s,!1)}r(Eo,"_temp");export{Ho as SqlEditorPanel};
@@ -1 +1 @@
1
- import{a as be,b as ge,c as xe,d as Ne,e as Ce}from"./chunk-S5NTGHCG.js";import"./chunk-DWDILV2E.js";import"./chunk-APSSZB6Z.js";import"./chunk-QAFAJBAW.js";import{a as ue}from"./chunk-3GXGLNKW.js";import{g as me,h as ve,i as fe,j as pe}from"./chunk-4TV6S6AO.js";import"./chunk-ZPUO7FNI.js";import"./chunk-WVTPZ6CM.js";import"./chunk-SHERR7ZP.js";import"./chunk-5OIBXYZM.js";import"./chunk-L7SK4ZZD.js";import"./chunk-ZIGWVHCS.js";import"./chunk-7TJJXVSE.js";import"./chunk-WI7GWFEG.js";import"./chunk-KEGAWN6Y.js";import"./chunk-W666BB6V.js";import{a as de,b as ne,c as oe,d as q,e as Q,f as X}from"./chunk-GTM65MVX.js";import{a as re,e as se}from"./chunk-SEU5V7I6.js";import{a as ce}from"./chunk-VLXV72QE.js";import{a as W}from"./chunk-JSEXCW5Q.js";import"./chunk-KZ6INM5M.js";import"./chunk-4QHKBC77.js";import{R as le}from"./chunk-VL23Y44O.js";import"./chunk-HV7G6DFP.js";import{c as $}from"./chunk-UK64ZSUW.js";import"./chunk-O3NAGRTR.js";import{b as he}from"./chunk-ZPP2KOR4.js";import"./chunk-CKSHCYGC.js";import"./chunk-BOXSWNXZ.js";import{f as Y}from"./chunk-SDMZKBTD.js";import"./chunk-ZHVTQ37P.js";import"./chunk-3OA7PECS.js";import{a as ye}from"./chunk-TAD43CG5.js";import{d as U,h as z,l as R,n as ie,o as ke}from"./chunk-ITQKVEP7.js";import"./chunk-22C6COGE.js";import{a as n,e as ae,f as Me,g as Le,h as Be}from"./chunk-RRCPZMC2.js";var J=ae(Me(),1);var ee=ae(Le(),1);var l=ae(Be(),1);var De=n(r=>{let e=r.trim();if(e==="")return;let s=Number(e);return Number.isFinite(s)&&s>0?Math.floor(s):void 0},"parseTtl"),Oe=n(r=>r===void 0?"\u2014":new Date(r*1e3).toISOString(),"formatExpiration"),Ae=n(r=>new TextEncoder().encode(r).length,"byteLength"),Te=n(r=>{if(r.trim()!=="")try{return JSON.stringify(JSON.parse(r),void 0,2)}catch{return}},"tryFormatJson"),Ee=n(r=>{if(r.trim()==="")return!0;try{return JSON.parse(r),!0}catch{return!1}},"isJsonOrEmpty"),Fe=[{key:"seconds",seconds:1},{key:"minutes",seconds:60},{key:"hours",seconds:3600},{key:"days",seconds:86400}],Se=n((r,e)=>{let s=r.trim();if(s==="")return"";let u=Number(s),d=Fe.find(f=>f.key===e)?.seconds??1;return Number.isFinite(u)&&u>0?String(Math.round(u*d)):s},"ttlToSeconds"),Ke=n(r=>{let e=r.trim();if(e==="")return!0;let s=Number(e);return Number.isInteger(s)&&s>=60},"isTtlValid"),Ve=n((r,e,s,u)=>{let d=De(r.ttl);return{expiration:d===void 0?u:void 0,expirationTtl:d,key:e,metadata:r.metadata.trim()===""?void 0:JSON.parse(r.metadata),namespace:s,value:r.value}},"buildKvPutOptions"),Ie=n(r=>{let e=(0,ee.c)(60),{helper:s,id:u,invalid:d,onChange:f,testId:o}=r,t=U(),[a,p]=(0,J.useState)(""),[c,x]=(0,J.useState)("seconds"),b;e[0]!==f||e[1]!==c?(b=n(g=>{p(g.target.value),f(Se(g.target.value,c))},"t1"),e[0]=f,e[1]=c,e[2]=b):b=e[2];let M=b,V;e[3]!==a||e[4]!==f?(V=n(g=>{g!==null&&(x(g),f(Se(a,g)))},"t2"),e[3]=a,e[4]=f,e[5]=V):V=e[5];let L=V,h;e[6]!==t?(h=t("days"),e[6]=t,e[7]=h):h=e[7];let v;e[8]!==t?(v=t("hours"),e[8]=t,e[9]=v):v=e[9];let y;e[10]!==t?(y=t("minutes"),e[10]=t,e[11]=y):y=e[11];let N;e[12]!==t?(N=t("seconds"),e[12]=t,e[13]=N):N=e[13];let C;e[14]!==h||e[15]!==v||e[16]!==y||e[17]!==N?(C={days:h,hours:v,minutes:y,seconds:N},e[14]=h,e[15]=v,e[16]=y,e[17]=N,e[18]=C):C=e[18];let S=C,k;e[19]!==t?(k=t("Expires after"),e[19]=t,e[20]=k):k=e[20];let w;e[21]!==u||e[22]!==k?(w=(0,l.jsxDEV)(W,{className:"text-xs",htmlFor:u,children:k},void 0,!1),e[21]=u,e[22]=k,e[23]=w):w=e[23];let E;e[24]!==t?(E=t("No expiration"),e[24]=t,e[25]=E):E=e[25];let B;e[26]!==a||e[27]!==u||e[28]!==d||e[29]!==M||e[30]!==E||e[31]!==o?(B=(0,l.jsxDEV)(le,{"aria-invalid":d,className:"flex-1","data-testid":o,id:u,inputMode:"numeric",onChange:M,placeholder:E,value:a},void 0,!1),e[26]=a,e[27]=u,e[28]=d,e[29]=M,e[30]=E,e[31]=o,e[32]=B):B=e[32];let I;e[33]!==t?(I=t("TTL unit"),e[33]=t,e[34]=I):I=e[34];let O=`${o}-unit`,D;e[35]===Symbol.for("react.memo_cache_sentinel")?(D=(0,l.jsxDEV)(ge,{},void 0,!1),e[35]=D):D=e[35];let i;e[36]!==I||e[37]!==O?(i=(0,l.jsxDEV)(xe,{"aria-label":I,className:"w-[7.5rem]","data-testid":O,children:D},void 0,!1),e[36]=I,e[37]=O,e[38]=i):i=e[38];let m;e[39]!==S?(m=Fe.map(g=>(0,l.jsxDEV)(Ce,{value:g.key,children:S[g.key]},g.key,!1)),e[39]=S,e[40]=m):m=e[40];let K;e[41]!==m?(K=(0,l.jsxDEV)(Ne,{children:m},void 0,!1),e[41]=m,e[42]=K):K=e[42];let T;e[43]!==L||e[44]!==i||e[45]!==K||e[46]!==c?(T=(0,l.jsxDEV)(be,{onValueChange:L,value:c,children:[i,K]},void 0,!0),e[43]=L,e[44]=i,e[45]=K,e[46]=c,e[47]=T):T=e[47];let _;e[48]!==B||e[49]!==T?(_=(0,l.jsxDEV)("div",{className:"flex gap-2",children:[B,T]},void 0,!0),e[48]=B,e[49]=T,e[50]=_):_=e[50];let F;e[51]!==s||e[52]!==d||e[53]!==t||e[54]!==o?(F=d?(0,l.jsxDEV)("p",{className:"text-xs text-destructive","data-testid":`${o}-invalid`,children:t("TTL must be at least 60 seconds.")},void 0,!1):s!==void 0&&(0,l.jsxDEV)("p",{className:"text-xs text-muted-foreground",children:s},void 0,!1),e[51]=s,e[52]=d,e[53]=t,e[54]=o,e[55]=F):F=e[55];let A;return e[56]!==_||e[57]!==F||e[58]!==w?(A=(0,l.jsxDEV)("div",{className:"mb-3 grid gap-1",children:[w,_,F]},void 0,!0),e[56]=_,e[57]=F,e[58]=w,e[59]=A):A=e[59],A},"TtlField"),_e=n(r=>{let e=(0,ee.c)(36),{id:s,invalidTestId:u,onChange:d,testId:f,valid:o,value:t}=r,a=U(),p;e[0]!==t?(p=Te(t),e[0]=t,e[1]=p):p=e[1];let c=p,x;e[2]!==a?(x=a("Metadata (JSON)"),e[2]=a,e[3]=x):x=e[3];let b;e[4]!==s||e[5]!==x?(b=(0,l.jsxDEV)(W,{className:"text-xs",htmlFor:s,children:x},void 0,!1),e[4]=s,e[5]=x,e[6]=b):b=e[6];let M=`${f}-format`,V=c===void 0,L;e[7]!==c||e[8]!==d?(L=n(()=>{c!==void 0&&d(c)},"t6"),e[7]=c,e[8]=d,e[9]=L):L=e[9];let h;e[10]!==a?(h=a("Format JSON"),e[10]=a,e[11]=h):h=e[11];let v;e[12]!==M||e[13]!==V||e[14]!==L||e[15]!==h?(v=(0,l.jsxDEV)($,{"data-testid":M,disabled:V,onClick:L,size:"sm",variant:"outline",children:h},void 0,!1),e[12]=M,e[13]=V,e[14]=L,e[15]=h,e[16]=v):v=e[16];let y;e[17]!==b||e[18]!==v?(y=(0,l.jsxDEV)("div",{className:"flex items-center justify-between gap-2",children:[b,v]},void 0,!0),e[17]=b,e[18]=v,e[19]=y):y=e[19];let N=!o,C;e[20]!==d?(C=n(E=>{d(E.target.value)},"t11"),e[20]=d,e[21]=C):C=e[21];let S;e[22]!==s||e[23]!==N||e[24]!==C||e[25]!==f||e[26]!==t?(S=(0,l.jsxDEV)(ce,{"aria-invalid":N,className:"min-h-[4rem] font-mono text-xs","data-testid":f,id:s,onChange:C,value:t},void 0,!1),e[22]=s,e[23]=N,e[24]=C,e[25]=f,e[26]=t,e[27]=S):S=e[27];let k;e[28]!==u||e[29]!==a||e[30]!==o?(k=!o&&(0,l.jsxDEV)("p",{className:"text-xs text-destructive","data-testid":u,children:a("Metadata must be valid JSON.")},void 0,!1),e[28]=u,e[29]=a,e[30]=o,e[31]=k):k=e[31];let w;return e[32]!==S||e[33]!==k||e[34]!==y?(w=(0,l.jsxDEV)("div",{className:"mb-3 grid gap-1",children:[y,S,k]},void 0,!0),e[32]=S,e[33]=k,e[34]=y,e[35]=w):w=e[35],w},"MetadataField"),Je={busy:!1,error:null,metadata:"",name:"",ttl:"",value:""},Pe=n((r,e)=>{switch(e.type){case"setField":return{...r,[e.field]:e.value};case"submitFailed":return{...r,busy:!1,error:e.error};case"submitStart":return{...r,busy:!0,error:null};default:return r}},"createReducer"),$e=n(r=>{let e=(0,ee.c)(73),{namespace:s,onCancel:u,onCreated:d}=r,f=Y(),o=U(),[t,a]=(0,J.useReducer)(Pe,Je),p;e[0]!==t.metadata?(p=Ee(t.metadata),e[0]=t.metadata,e[1]=p):p=e[1];let c=p,x;e[2]!==t.ttl?(x=Ke(t.ttl),e[2]=t.ttl,e[3]=x):x=e[3];let b=x,M;e[4]!==c||e[5]!==t.busy||e[6]!==t.name||e[7]!==b?(M=t.name.trim()!==""&&c&&b&&!t.busy,e[4]=c,e[5]=t.busy,e[6]=t.name,e[7]=b,e[8]=M):M=e[8];let V=M,L;e[9]!==V||e[10]!==f||e[11]!==s||e[12]!==d||e[13]!==t.metadata||e[14]!==t.name||e[15]!==t.ttl||e[16]!==t.value?(L=n(()=>{V&&(a({type:"submitStart"}),R((async()=>{try{await f.putKvValue(Ve({metadata:t.metadata,ttl:t.ttl,value:t.value},t.name,s)),d()}catch(H){a({error:z(H),type:"submitFailed"})}})()))},"t4"),e[9]=V,e[10]=f,e[11]=s,e[12]=d,e[13]=t.metadata,e[14]=t.name,e[15]=t.ttl,e[16]=t.value,e[17]=L):L=e[17];let h=L,v;e[18]!==o?(v=o("Key name"),e[18]=o,e[19]=v):v=e[19];let y;e[20]!==v?(y=(0,l.jsxDEV)(W,{className:"text-xs",htmlFor:"kv-create-name",children:v},void 0,!1),e[20]=v,e[21]=y):y=e[21];let N;e[22]===Symbol.for("react.memo_cache_sentinel")?(N=n(H=>{a({field:"name",type:"setField",value:H.target.value})},"t7"),e[22]=N):N=e[22];let C;e[23]!==o?(C=o("Key name"),e[23]=o,e[24]=C):C=e[24];let S;e[25]!==t.name||e[26]!==C?(S=(0,l.jsxDEV)(le,{autoFocus:!0,"data-testid":"kv-create-name",id:"kv-create-name",onChange:N,placeholder:C,value:t.name},void 0,!1),e[25]=t.name,e[26]=C,e[27]=S):S=e[27];let k;e[28]!==y||e[29]!==S?(k=(0,l.jsxDEV)("div",{className:"grid gap-1",children:[y,S]},void 0,!0),e[28]=y,e[29]=S,e[30]=k):k=e[30];let w;e[31]!==o?(w=o("Value"),e[31]=o,e[32]=w):w=e[32];let E;e[33]!==w?(E=(0,l.jsxDEV)(W,{className:"text-xs",htmlFor:"kv-create-value",children:w},void 0,!1),e[33]=w,e[34]=E):E=e[34];let B;e[35]===Symbol.for("react.memo_cache_sentinel")?(B=n(H=>{a({field:"value",type:"setField",value:H.target.value})},"t13"),e[35]=B):B=e[35];let I;e[36]!==t.value?(I=(0,l.jsxDEV)(ce,{className:"min-h-[6rem] font-mono text-xs","data-testid":"kv-create-value",id:"kv-create-value",onChange:B,value:t.value},void 0,!1),e[36]=t.value,e[37]=I):I=e[37];let O;e[38]!==E||e[39]!==I?(O=(0,l.jsxDEV)("div",{className:"grid gap-1",children:[E,I]},void 0,!0),e[38]=E,e[39]=I,e[40]=O):O=e[40];let D=!b,i;e[41]===Symbol.for("react.memo_cache_sentinel")?(i=n(H=>{a({field:"ttl",type:"setField",value:H})},"t17"),e[41]=i):i=e[41];let m;e[42]!==D?(m=(0,l.jsxDEV)(Ie,{id:"kv-create-ttl",invalid:D,onChange:i,testId:"kv-create-ttl"},void 0,!1),e[42]=D,e[43]=m):m=e[43];let K;e[44]===Symbol.for("react.memo_cache_sentinel")?(K=n(H=>{a({field:"metadata",type:"setField",value:H})},"t19"),e[44]=K):K=e[44];let T;e[45]!==c||e[46]!==t.metadata?(T=(0,l.jsxDEV)(_e,{id:"kv-create-metadata",invalidTestId:"kv-create-metadata-invalid",onChange:K,testId:"kv-create-metadata",valid:c,value:t.metadata},void 0,!1),e[45]=c,e[46]=t.metadata,e[47]=T):T=e[47];let _=!V,F;e[48]!==t.busy||e[49]!==o?(F=t.busy?o("Creating\u2026"):o("Create key"),e[48]=t.busy,e[49]=o,e[50]=F):F=e[50];let A;e[51]!==h||e[52]!==_||e[53]!==F?(A=(0,l.jsxDEV)($,{"data-testid":"kv-create-submit",disabled:_,onClick:h,children:F},void 0,!1),e[51]=h,e[52]=_,e[53]=F,e[54]=A):A=e[54];let g=t.busy,P;e[55]!==o?(P=o("Cancel"),e[55]=o,e[56]=P):P=e[56];let j;e[57]!==u||e[58]!==t.busy||e[59]!==P?(j=(0,l.jsxDEV)($,{"data-testid":"kv-create-cancel",disabled:g,onClick:u,variant:"outline",children:P},void 0,!1),e[57]=u,e[58]=t.busy,e[59]=P,e[60]=j):j=e[60];let Z;e[61]!==A||e[62]!==j?(Z=(0,l.jsxDEV)("div",{className:"flex flex-wrap gap-2",children:[A,j]},void 0,!0),e[61]=A,e[62]=j,e[63]=Z):Z=e[63];let G;e[64]!==t.error?(G=t.error!==null&&(0,l.jsxDEV)("p",{className:"text-sm text-destructive","data-testid":"kv-create-error",role:"alert",children:t.error},void 0,!1),e[64]=t.error,e[65]=G):G=e[65];let te;return e[66]!==k||e[67]!==O||e[68]!==m||e[69]!==T||e[70]!==Z||e[71]!==G?(te=(0,l.jsxDEV)("div",{className:"grid gap-3 px-4 pb-4","data-testid":"kv-create-form",children:[k,O,m,T,Z,G]},void 0,!0),e[66]=k,e[67]=O,e[68]=m,e[69]=T,e[70]=Z,e[71]=G,e[72]=te):te=e[72],te},"KvCreateForm"),He={busy:"",editedMetadata:"",editedTtl:"",editedValue:"",loadError:null,loading:!0,value:null,writeError:null},Re=n((r,e)=>{switch(e.type){case"deleteStart":return{...r,busy:"deleting",writeError:null};case"editMetadata":return{...r,editedMetadata:e.value};case"editTtl":return{...r,editedTtl:e.value};case"editValue":return{...r,editedValue:e.value};case"loaded":return{...r,editedMetadata:e.metadata===null||e.metadata===void 0?"":JSON.stringify(e.metadata,null,2),editedValue:e.value??"",loading:!1,value:e.value};case"loadFailed":return{...r,loadError:e.error,loading:!1};case"saveOk":return{...r,busy:"",value:r.editedValue};case"saveStart":return{...r,busy:"saving",writeError:null};case"writeFailed":return{...r,busy:"",writeError:e.error};default:return r}},"valueReducer"),je=n(r=>{let e=(0,ee.c)(67),{expiration:s,keyName:u,namespace:d,onDeleted:f}=r,o=Y(),t=U(),[a,p]=(0,J.useReducer)(Re,He),c,x;e[0]!==o||e[1]!==u||e[2]!==d?(c=n(()=>{let g={cancelled:!1};return R((async()=>{try{let P=await o.getKvValue({key:u,namespace:d});g.cancelled||p({metadata:P.metadata,type:"loaded",value:P.value})}catch(P){let j=P;g.cancelled||p({error:z(j),type:"loadFailed"})}})()),()=>{g.cancelled=!0}},"t1"),x=[o,d,u],e[0]=o,e[1]=u,e[2]=d,e[3]=c,e[4]=x):(c=e[3],x=e[4]),(0,J.useEffect)(c,x);let b;e[5]===Symbol.for("react.memo_cache_sentinel")?(b=n(g=>{p({type:"editValue",value:g.target.value})},"t3"),e[5]=b):b=e[5];let M=b,V;e[6]===Symbol.for("react.memo_cache_sentinel")?(V=n(g=>{p({type:"editMetadata",value:g})},"t4"),e[6]=V):V=e[6];let L=V,h;e[7]!==a.editedValue?(h=Te(a.editedValue),e[7]=a.editedValue,e[8]=h):h=e[8];let v=h,y;e[9]!==a.editedMetadata?(y=Ee(a.editedMetadata),e[9]=a.editedMetadata,e[10]=y):y=e[10];let N=y,C;e[11]!==a.editedTtl?(C=Ke(a.editedTtl),e[11]=a.editedTtl,e[12]=C):C=e[12];let S=C,k;e[13]!==v?(k=n(()=>{v!==void 0&&p({type:"editValue",value:v})},"t8"),e[13]=v,e[14]=k):k=e[14];let w=k,E;e[15]!==o||e[16]!==s||e[17]!==u||e[18]!==N||e[19]!==d||e[20]!==a.editedMetadata||e[21]!==a.editedTtl||e[22]!==a.editedValue||e[23]!==t?(E=n(()=>{if(!N){p({error:t("Metadata must be valid JSON."),type:"writeFailed"});return}p({type:"saveStart"}),R((async()=>{try{await o.putKvValue(Ve({metadata:a.editedMetadata,ttl:a.editedTtl,value:a.editedValue},u,d,s)),p({type:"saveOk"})}catch(g){p({error:z(g),type:"writeFailed"})}})())},"t9"),e[15]=o,e[16]=s,e[17]=u,e[18]=N,e[19]=d,e[20]=a.editedMetadata,e[21]=a.editedTtl,e[22]=a.editedValue,e[23]=t,e[24]=E):E=e[24];let B=E,I;e[25]!==o||e[26]!==u||e[27]!==d||e[28]!==f?(I=n(()=>{p({type:"deleteStart"}),R((async()=>{try{await o.deleteKvKey({key:u,namespace:d}),f(u)}catch(g){p({error:z(g),type:"writeFailed"})}})())},"t10"),e[25]=o,e[26]=u,e[27]=d,e[28]=f,e[29]=I):I=e[29];let O=I,D;e[30]!==u?(D=n(()=>{ie(u)},"t11"),e[30]=u,e[31]=D):D=e[31];let i;e[32]!==t?(i=t("Copy key"),e[32]=t,e[33]=i):i=e[33];let m;e[34]!==D||e[35]!==i?(m=(0,l.jsxDEV)("div",{className:"mb-2 flex justify-end",children:(0,l.jsxDEV)($,{"data-testid":"kv-copy-key-btn",onClick:D,size:"sm",variant:"outline",children:i},void 0,!1)},void 0,!1),e[34]=D,e[35]=i,e[36]=m):m=e[36];let K;e[37]!==a.loadError?(K=a.loadError!==null&&(0,l.jsxDEV)("p",{className:"mb-2 text-sm text-destructive","data-testid":"kv-value-error",role:"alert",children:a.loadError},void 0,!1),e[37]=a.loadError,e[38]=K):K=e[38];let T;e[39]!==a.loading||e[40]!==t?(T=a.loading&&(0,l.jsxDEV)("p",{className:"text-sm text-muted-foreground","data-testid":"kv-value-loading",children:t("Loading\u2026")},void 0,!1),e[39]=a.loading,e[40]=t,e[41]=T):T=e[41];let _;e[42]!==v||e[43]!==N||e[44]!==O||e[45]!==w||e[46]!==B||e[47]!==a.busy||e[48]!==a.editedMetadata||e[49]!==a.editedValue||e[50]!==a.loading||e[51]!==a.value||e[52]!==a.writeError||e[53]!==t||e[54]!==S?(_=!a.loading&&a.value!==null&&(0,l.jsxDEV)(l.Fragment,{children:[(0,l.jsxDEV)("div",{className:"mb-1 flex flex-wrap items-center gap-2",children:[(0,l.jsxDEV)(W,{className:"text-xs",htmlFor:"kv-value-editor",children:t("Value")},void 0,!1),v!==void 0&&(0,l.jsxDEV)(he,{variant:"secondary",children:t("JSON")},void 0,!1),(0,l.jsxDEV)("span",{className:"ml-auto text-xs tabular-nums text-muted-foreground","data-testid":"kv-value-size",children:ke(Ae(a.editedValue))},void 0,!1)]},void 0,!0),(0,l.jsxDEV)("textarea",{"aria-label":t("KV value"),className:"mb-2 min-h-[8rem] w-full rounded border border-border bg-muted/30 p-2 font-mono text-xs","data-testid":"kv-value-editor",id:"kv-value-editor",onChange:M,value:a.editedValue},void 0,!1),(0,l.jsxDEV)("div",{className:"mb-3 flex flex-wrap gap-2",children:[(0,l.jsxDEV)($,{"data-testid":"kv-format-btn",disabled:v===void 0,onClick:w,size:"sm",variant:"outline",children:t("Format JSON")},void 0,!1),(0,l.jsxDEV)($,{"data-testid":"kv-copy-value-btn",onClick:n(()=>{ie(a.editedValue)},"onClick"),size:"sm",variant:"outline",children:t("Copy value")},void 0,!1)]},void 0,!0),(0,l.jsxDEV)(Ie,{helper:t("Leave blank to keep the current expiration."),id:"kv-ttl-input",invalid:!S,onChange:n(g=>{p({type:"editTtl",value:g})},"onChange"),testId:"kv-ttl-input"},void 0,!1),(0,l.jsxDEV)(_e,{id:"kv-metadata-editor",invalidTestId:"kv-metadata-invalid",onChange:L,testId:"kv-metadata-editor",valid:N,value:a.editedMetadata},void 0,!1),(0,l.jsxDEV)("div",{className:"flex flex-wrap gap-2",children:[(0,l.jsxDEV)($,{"data-testid":"kv-save-btn",disabled:a.busy!==""||!N||!S,onClick:B,children:a.busy==="saving"?t("Saving\u2026"):t("Save")},void 0,!1),(0,l.jsxDEV)($,{"data-testid":"kv-delete-btn",disabled:a.busy!=="",onClick:O,variant:"destructive",children:a.busy==="deleting"?t("Deleting\u2026"):t("Delete")},void 0,!1)]},void 0,!0),a.writeError!==null&&(0,l.jsxDEV)("p",{className:"mt-2 text-sm text-destructive","data-testid":"kv-save-error",role:"alert",children:a.writeError},void 0,!1)]},void 0,!0),e[42]=v,e[43]=N,e[44]=O,e[45]=w,e[46]=B,e[47]=a.busy,e[48]=a.editedMetadata,e[49]=a.editedValue,e[50]=a.loading,e[51]=a.value,e[52]=a.writeError,e[53]=t,e[54]=S,e[55]=_):_=e[55];let F;e[56]!==a.loadError||e[57]!==a.loading||e[58]!==a.value||e[59]!==t?(F=!a.loading&&a.value===null&&a.loadError===null&&(0,l.jsxDEV)("p",{className:"text-sm text-muted-foreground","data-testid":"kv-absent",children:t("Key is absent or has no value.")},void 0,!1),e[56]=a.loadError,e[57]=a.loading,e[58]=a.value,e[59]=t,e[60]=F):F=e[60];let A;return e[61]!==m||e[62]!==K||e[63]!==T||e[64]!==_||e[65]!==F?(A=(0,l.jsxDEV)("div",{className:"px-4 pb-4","data-testid":"kv-value-section",children:[m,K,T,_,F]},void 0,!0),e[61]=m,e[62]=K,e[63]=T,e[64]=_,e[65]=F,e[66]=A):A=e[66],A},"KvValueEditor"),we=100,ze={appliedPrefix:"",bulk:[],bulkBusy:!1,bulkError:null,cursor:null,keys:null,listComplete:!1,loadError:null,loading:!1,prefixInput:"",reloadNonce:0,selectedKey:null},Ue=n((r,e)=>{switch(e.type){case"appendPage":return{...r,cursor:e.cursor,keys:[...r.keys??[],...e.keys],listComplete:e.listComplete,loading:!1};case"applyFilter":return{...r,appliedPrefix:r.prefixInput,bulk:[],bulkError:null,cursor:null,keys:null,listComplete:!1,selectedKey:null};case"bulkDeleted":{let s=new Set(e.deleted);return{...r,bulk:r.bulk.filter(u=>!s.has(u)),bulkBusy:!1,bulkError:e.error,keys:r.keys===null?null:r.keys.filter(u=>!s.has(u.name)),selectedKey:r.selectedKey!==null&&s.has(r.selectedKey)?null:r.selectedKey}}case"bulkDeleteStart":return{...r,bulkBusy:!0,bulkError:null};case"firstPage":return{...r,cursor:e.cursor,keys:e.keys,listComplete:e.listComplete,loading:!1};case"keyDeleted":return{...r,bulk:r.bulk.filter(s=>s!==e.name),keys:r.keys===null?null:r.keys.filter(s=>s.name!==e.name),selectedKey:null};case"loadFailed":return{...r,loadError:e.error,loading:!1};case"loadStart":return{...r,loadError:null,loading:!0};case"prefixInput":return{...r,prefixInput:e.value};case"reload":return{...r,bulk:[],bulkError:null,reloadNonce:r.reloadNonce+1,selectedKey:null};case"selectKey":return{...r,selectedKey:e.name};case"toggleAllBulk":return{...r,bulk:e.names};case"toggleBulk":return{...r,bulk:r.bulk.includes(e.name)?r.bulk.filter(s=>s!==e.name):[...r.bulk,e.name]};default:return r}},"keyListReducer"),Ze=n(({namespace:r})=>{let e=Y(),s=U(),[u,d]=(0,J.useReducer)(Ue,ze),{appliedPrefix:f,bulk:o,bulkBusy:t,bulkError:a,cursor:p,keys:c,listComplete:x,loadError:b,loading:M,prefixInput:V,reloadNonce:L,selectedKey:h}=u,[v,y]=(0,J.useState)(!1);(0,J.useEffect)(()=>{let i={cancelled:!1};return R((async()=>{d({type:"loadStart"});try{let m=await e.listKvKeys({limit:we,namespace:r,prefix:f===""?void 0:f});i.cancelled||d({cursor:m.cursor??null,keys:m.keys,listComplete:m.listComplete,type:"firstPage"})}catch(m){i.cancelled||d({error:z(m),type:"loadFailed"})}})()),()=>{i.cancelled=!0}},[e,r,f,L]);let N=n(i=>{d({type:"prefixInput",value:i.target.value})},"onPrefixChange"),C=n(()=>{d({type:"applyFilter"})},"onFilter"),S=n(i=>{d({name:i.currentTarget.dataset.key??null,type:"selectKey"})},"onSelectKey"),k=n(()=>{p!==null&&(d({type:"loadStart"}),R((async()=>{try{let i=await e.listKvKeys({cursor:p,limit:we,namespace:r,prefix:f===""?void 0:f});d({cursor:i.cursor??null,keys:i.keys,listComplete:i.listComplete,type:"appendPage"})}catch(i){d({error:z(i),type:"loadFailed"})}})()))},"onLoadMore"),w=n(i=>{d({name:i,type:"keyDeleted"})},"onKeyDeleted"),E=n(i=>{d({name:i,type:"toggleBulk"})},"onToggleBulk"),B=n(i=>{d({names:i&&c!==null?c.map(m=>m.name):[],type:"toggleAllBulk"})},"onToggleAll"),I=n(()=>{if(o.length===0)return;let i=[...o];d({type:"bulkDeleteStart"}),R((async()=>{let m=await Promise.allSettled(i.map(_=>e.deleteKvKey({key:_,namespace:r}))),K=i.filter((_,F)=>m[F]?.status==="fulfilled"),T=i.length-K.length;d({deleted:K,error:T>0?s("Failed to delete {count} keys.",{count:T}):null,type:"bulkDeleted"})})())},"onBulkDelete"),O=n(()=>{y(!1),d({type:"reload"})},"onCreated"),D=c!==null&&c.length>0&&o.length===c.length;return(0,l.jsxDEV)(l.Fragment,{children:[(0,l.jsxDEV)("section",{className:"border border-border bg-card p-3","data-testid":"kv-keys-section",children:[(0,l.jsxDEV)("div",{className:"mb-3 flex flex-wrap items-center gap-2",children:[(0,l.jsxDEV)(le,{"aria-label":s("Filter keys by prefix"),className:"min-w-[16rem] flex-1","data-testid":"kv-prefix-input",onChange:N,placeholder:s("Filter by prefix\u2026"),value:V},void 0,!1),(0,l.jsxDEV)($,{"data-testid":"kv-filter-btn",disabled:M,onClick:C,children:s("Filter")},void 0,!1),(0,l.jsxDEV)($,{"data-testid":"kv-new-key-btn",onClick:n(()=>{y(i=>!i)},"onClick"),variant:"outline",children:s("New key")},void 0,!1),o.length>0&&(0,l.jsxDEV)($,{"data-testid":"kv-bulk-delete-btn",disabled:t,onClick:I,variant:"destructive",children:t?s("Deleting\u2026"):s("Delete {count}",{count:o.length})},void 0,!1)]},void 0,!0),a!==null&&(0,l.jsxDEV)("p",{className:"mb-2 text-sm text-destructive","data-testid":"kv-bulk-error",role:"alert",children:a},void 0,!1),b!==null&&(0,l.jsxDEV)("p",{className:"text-sm text-destructive","data-testid":"kv-keys-error",role:"alert",children:b},void 0,!1),c!==null&&c.length===0&&!M&&(0,l.jsxDEV)("p",{className:"text-sm text-muted-foreground","data-testid":"kv-no-keys",children:s("No keys.")},void 0,!1),c!==null&&c.length>0&&(0,l.jsxDEV)(re,{className:"overflow-hidden py-0",children:(0,l.jsxDEV)(se,{className:"px-0",children:(0,l.jsxDEV)(de,{"data-testid":"kv-key-table",children:[(0,l.jsxDEV)(ne,{children:(0,l.jsxDEV)(q,{children:[(0,l.jsxDEV)(Q,{className:"w-10",children:(0,l.jsxDEV)(ue,{"aria-label":s("Select all"),checked:D,"data-testid":"kv-select-all",onCheckedChange:B},void 0,!1)},void 0,!1),(0,l.jsxDEV)(Q,{children:s("Key")},void 0,!1),(0,l.jsxDEV)(Q,{children:s("Expiration")},void 0,!1)]},void 0,!0)},void 0,!1),(0,l.jsxDEV)(oe,{children:c.map(i=>(0,l.jsxDEV)(q,{className:i.name===h?"border-l-2 border-l-royal-amethyst bg-muted/50":"cursor-pointer","data-key":i.name,"data-testid":`kv-key-row-${i.name}`,onClick:S,children:[(0,l.jsxDEV)(X,{onClick:n(m=>{m.stopPropagation()},"onClick"),children:(0,l.jsxDEV)(ue,{"aria-label":s("Select {name}",{name:i.name}),checked:o.includes(i.name),"data-testid":`kv-select-${i.name}`,onCheckedChange:n(()=>{E(i.name)},"onCheckedChange")},void 0,!1)},void 0,!1),(0,l.jsxDEV)(X,{className:"font-mono text-xs",children:i.name},void 0,!1),(0,l.jsxDEV)(X,{className:"tabular-nums text-xs",children:Oe(i.expiration)},void 0,!1)]},i.name,!0))},void 0,!1)]},void 0,!0)},void 0,!1)},void 0,!1),!x&&p!==null&&(0,l.jsxDEV)("div",{className:"mt-2",children:(0,l.jsxDEV)($,{"data-testid":"kv-load-more",disabled:M,onClick:k,variant:"outline",children:s(M?"Loading\u2026":"Load more")},void 0,!1)},void 0,!1)]},void 0,!0),(0,l.jsxDEV)(me,{onOpenChange:n(i=>{i||y(!1)},"onOpenChange"),open:v,children:(0,l.jsxDEV)(ve,{className:"w-full gap-0 overflow-y-auto sm:max-w-md","data-testid":"kv-create-sheet",side:"right",children:[(0,l.jsxDEV)(fe,{children:(0,l.jsxDEV)(pe,{children:s("New key")},void 0,!1)},void 0,!1),(0,l.jsxDEV)($e,{namespace:r,onCancel:n(()=>{y(!1)},"onCancel"),onCreated:O},void 0,!1)]},void 0,!0)},void 0,!1),(0,l.jsxDEV)(me,{onOpenChange:n(i=>{i||d({name:null,type:"selectKey"})},"onOpenChange"),open:h!==null,children:(0,l.jsxDEV)(ve,{className:"w-full gap-0 overflow-y-auto sm:max-w-md","data-testid":"kv-editor-sheet",side:"right",children:[(0,l.jsxDEV)(fe,{children:(0,l.jsxDEV)(pe,{className:"truncate font-mono text-xs",children:h},void 0,!1)},void 0,!1),h!==null&&(0,l.jsxDEV)(je,{expiration:c?.find(i=>i.name===h)?.expiration,keyName:h,namespace:r,onDeleted:w},`${r}:${h}`,!1)]},void 0,!0)},void 0,!1)]},void 0,!0)},"KvKeyList"),ot=n(({loadNamespaces:r}={})=>{let e=Y(),s=U(),[u,d]=(0,J.useState)(null),[f,o]=(0,J.useState)(null),[t,a]=(0,J.useState)(null);(0,J.useEffect)(()=>{let c={cancelled:!1};return R((async()=>{try{let x=await(r??(()=>e.listKvNamespaces()))();c.cancelled||(d(x),o(null),a(b=>b??x[0]?.binding??null))}catch(x){c.cancelled||(d(null),o(z(x)))}})()),()=>{c.cancelled=!0}},[e,r]);let p=n(c=>{a(c.currentTarget.dataset.ns??null)},"onSelectNs");return(0,l.jsxDEV)("div",{className:"flex flex-col gap-4","data-testid":"lunora-kv-browser",children:[f!==null&&(0,l.jsxDEV)("p",{className:"text-sm text-destructive","data-testid":"kv-ns-error",role:"alert",children:f},void 0,!1),u!==null&&u.length===0&&(0,l.jsxDEV)(ye,{description:s("Add a kv_namespaces binding to wrangler.jsonc \u2014 it appears here automatically, no wiring needed."),icon:(0,l.jsxDEV)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,l.jsxDEV)("path",{d:"M5 5h14v4H5V5Zm0 5h14v4H5v-4Zm0 5h14v4H5v-4Z"},void 0,!1)},void 0,!1),testId:"kv-empty",title:s("No KV namespaces.")},void 0,!1),u!==null&&u.length>0&&(0,l.jsxDEV)(re,{className:"overflow-hidden py-0",children:(0,l.jsxDEV)(se,{className:"px-0",children:(0,l.jsxDEV)(de,{"data-testid":"kv-namespace-table",children:[(0,l.jsxDEV)(ne,{children:(0,l.jsxDEV)(q,{children:(0,l.jsxDEV)(Q,{children:s("Namespace")},void 0,!1)},void 0,!1)},void 0,!1),(0,l.jsxDEV)(oe,{children:u.map(c=>(0,l.jsxDEV)(q,{className:c.binding===t?"border-l-2 border-l-royal-amethyst bg-muted/50":"cursor-pointer","data-ns":c.binding,"data-testid":`kv-ns-row-${c.binding}`,onClick:p,children:(0,l.jsxDEV)(X,{className:"font-mono text-xs",children:c.binding},void 0,!1)},c.binding,!1))},void 0,!1)]},void 0,!0)},void 0,!1)},void 0,!1),t!==null&&(0,l.jsxDEV)(Ze,{namespace:t},t,!1)]},void 0,!0)},"KvBrowser");export{ot as KvBrowser};
1
+ import{a as be,b as ge,c as xe,d as Ne,e as Ce}from"./chunk-S5NTGHCG.js";import"./chunk-DWDILV2E.js";import"./chunk-APSSZB6Z.js";import"./chunk-QAFAJBAW.js";import{a as ue}from"./chunk-3GXGLNKW.js";import{g as me,h as ve,i as fe,j as pe}from"./chunk-XWPZBZSZ.js";import"./chunk-ZPUO7FNI.js";import"./chunk-WVTPZ6CM.js";import"./chunk-SHERR7ZP.js";import"./chunk-5OIBXYZM.js";import"./chunk-L7SK4ZZD.js";import"./chunk-ZIGWVHCS.js";import"./chunk-7TJJXVSE.js";import"./chunk-WI7GWFEG.js";import"./chunk-KEGAWN6Y.js";import"./chunk-W666BB6V.js";import{a as de,b as ne,c as oe,d as q,e as Q,f as X}from"./chunk-GTM65MVX.js";import{a as re,e as se}from"./chunk-SEU5V7I6.js";import{a as ce}from"./chunk-VLXV72QE.js";import{a as W}from"./chunk-JSEXCW5Q.js";import"./chunk-KZ6INM5M.js";import"./chunk-4QHKBC77.js";import{R as le}from"./chunk-VL23Y44O.js";import"./chunk-HV7G6DFP.js";import{c as $}from"./chunk-UK64ZSUW.js";import"./chunk-O3NAGRTR.js";import{b as he}from"./chunk-ZPP2KOR4.js";import"./chunk-CKSHCYGC.js";import"./chunk-G7ZBM54M.js";import{f as Y}from"./chunk-SDMZKBTD.js";import"./chunk-ZHVTQ37P.js";import"./chunk-3OA7PECS.js";import{a as ye}from"./chunk-TAD43CG5.js";import{d as U,h as z,l as R,n as ie,o as ke}from"./chunk-ITQKVEP7.js";import"./chunk-22C6COGE.js";import{a as n,e as ae,f as Me,g as Le,h as Be}from"./chunk-RRCPZMC2.js";var J=ae(Me(),1);var ee=ae(Le(),1);var l=ae(Be(),1);var De=n(r=>{let e=r.trim();if(e==="")return;let s=Number(e);return Number.isFinite(s)&&s>0?Math.floor(s):void 0},"parseTtl"),Oe=n(r=>r===void 0?"\u2014":new Date(r*1e3).toISOString(),"formatExpiration"),Ae=n(r=>new TextEncoder().encode(r).length,"byteLength"),Te=n(r=>{if(r.trim()!=="")try{return JSON.stringify(JSON.parse(r),void 0,2)}catch{return}},"tryFormatJson"),Ee=n(r=>{if(r.trim()==="")return!0;try{return JSON.parse(r),!0}catch{return!1}},"isJsonOrEmpty"),Fe=[{key:"seconds",seconds:1},{key:"minutes",seconds:60},{key:"hours",seconds:3600},{key:"days",seconds:86400}],Se=n((r,e)=>{let s=r.trim();if(s==="")return"";let u=Number(s),d=Fe.find(f=>f.key===e)?.seconds??1;return Number.isFinite(u)&&u>0?String(Math.round(u*d)):s},"ttlToSeconds"),Ke=n(r=>{let e=r.trim();if(e==="")return!0;let s=Number(e);return Number.isInteger(s)&&s>=60},"isTtlValid"),Ve=n((r,e,s,u)=>{let d=De(r.ttl);return{expiration:d===void 0?u:void 0,expirationTtl:d,key:e,metadata:r.metadata.trim()===""?void 0:JSON.parse(r.metadata),namespace:s,value:r.value}},"buildKvPutOptions"),Ie=n(r=>{let e=(0,ee.c)(60),{helper:s,id:u,invalid:d,onChange:f,testId:o}=r,t=U(),[a,p]=(0,J.useState)(""),[c,x]=(0,J.useState)("seconds"),b;e[0]!==f||e[1]!==c?(b=n(g=>{p(g.target.value),f(Se(g.target.value,c))},"t1"),e[0]=f,e[1]=c,e[2]=b):b=e[2];let M=b,V;e[3]!==a||e[4]!==f?(V=n(g=>{g!==null&&(x(g),f(Se(a,g)))},"t2"),e[3]=a,e[4]=f,e[5]=V):V=e[5];let L=V,h;e[6]!==t?(h=t("days"),e[6]=t,e[7]=h):h=e[7];let v;e[8]!==t?(v=t("hours"),e[8]=t,e[9]=v):v=e[9];let y;e[10]!==t?(y=t("minutes"),e[10]=t,e[11]=y):y=e[11];let N;e[12]!==t?(N=t("seconds"),e[12]=t,e[13]=N):N=e[13];let C;e[14]!==h||e[15]!==v||e[16]!==y||e[17]!==N?(C={days:h,hours:v,minutes:y,seconds:N},e[14]=h,e[15]=v,e[16]=y,e[17]=N,e[18]=C):C=e[18];let S=C,k;e[19]!==t?(k=t("Expires after"),e[19]=t,e[20]=k):k=e[20];let w;e[21]!==u||e[22]!==k?(w=(0,l.jsxDEV)(W,{className:"text-xs",htmlFor:u,children:k},void 0,!1),e[21]=u,e[22]=k,e[23]=w):w=e[23];let E;e[24]!==t?(E=t("No expiration"),e[24]=t,e[25]=E):E=e[25];let B;e[26]!==a||e[27]!==u||e[28]!==d||e[29]!==M||e[30]!==E||e[31]!==o?(B=(0,l.jsxDEV)(le,{"aria-invalid":d,className:"flex-1","data-testid":o,id:u,inputMode:"numeric",onChange:M,placeholder:E,value:a},void 0,!1),e[26]=a,e[27]=u,e[28]=d,e[29]=M,e[30]=E,e[31]=o,e[32]=B):B=e[32];let I;e[33]!==t?(I=t("TTL unit"),e[33]=t,e[34]=I):I=e[34];let O=`${o}-unit`,D;e[35]===Symbol.for("react.memo_cache_sentinel")?(D=(0,l.jsxDEV)(ge,{},void 0,!1),e[35]=D):D=e[35];let i;e[36]!==I||e[37]!==O?(i=(0,l.jsxDEV)(xe,{"aria-label":I,className:"w-[7.5rem]","data-testid":O,children:D},void 0,!1),e[36]=I,e[37]=O,e[38]=i):i=e[38];let m;e[39]!==S?(m=Fe.map(g=>(0,l.jsxDEV)(Ce,{value:g.key,children:S[g.key]},g.key,!1)),e[39]=S,e[40]=m):m=e[40];let K;e[41]!==m?(K=(0,l.jsxDEV)(Ne,{children:m},void 0,!1),e[41]=m,e[42]=K):K=e[42];let T;e[43]!==L||e[44]!==i||e[45]!==K||e[46]!==c?(T=(0,l.jsxDEV)(be,{onValueChange:L,value:c,children:[i,K]},void 0,!0),e[43]=L,e[44]=i,e[45]=K,e[46]=c,e[47]=T):T=e[47];let _;e[48]!==B||e[49]!==T?(_=(0,l.jsxDEV)("div",{className:"flex gap-2",children:[B,T]},void 0,!0),e[48]=B,e[49]=T,e[50]=_):_=e[50];let F;e[51]!==s||e[52]!==d||e[53]!==t||e[54]!==o?(F=d?(0,l.jsxDEV)("p",{className:"text-xs text-destructive","data-testid":`${o}-invalid`,children:t("TTL must be at least 60 seconds.")},void 0,!1):s!==void 0&&(0,l.jsxDEV)("p",{className:"text-xs text-muted-foreground",children:s},void 0,!1),e[51]=s,e[52]=d,e[53]=t,e[54]=o,e[55]=F):F=e[55];let A;return e[56]!==_||e[57]!==F||e[58]!==w?(A=(0,l.jsxDEV)("div",{className:"mb-3 grid gap-1",children:[w,_,F]},void 0,!0),e[56]=_,e[57]=F,e[58]=w,e[59]=A):A=e[59],A},"TtlField"),_e=n(r=>{let e=(0,ee.c)(36),{id:s,invalidTestId:u,onChange:d,testId:f,valid:o,value:t}=r,a=U(),p;e[0]!==t?(p=Te(t),e[0]=t,e[1]=p):p=e[1];let c=p,x;e[2]!==a?(x=a("Metadata (JSON)"),e[2]=a,e[3]=x):x=e[3];let b;e[4]!==s||e[5]!==x?(b=(0,l.jsxDEV)(W,{className:"text-xs",htmlFor:s,children:x},void 0,!1),e[4]=s,e[5]=x,e[6]=b):b=e[6];let M=`${f}-format`,V=c===void 0,L;e[7]!==c||e[8]!==d?(L=n(()=>{c!==void 0&&d(c)},"t6"),e[7]=c,e[8]=d,e[9]=L):L=e[9];let h;e[10]!==a?(h=a("Format JSON"),e[10]=a,e[11]=h):h=e[11];let v;e[12]!==M||e[13]!==V||e[14]!==L||e[15]!==h?(v=(0,l.jsxDEV)($,{"data-testid":M,disabled:V,onClick:L,size:"sm",variant:"outline",children:h},void 0,!1),e[12]=M,e[13]=V,e[14]=L,e[15]=h,e[16]=v):v=e[16];let y;e[17]!==b||e[18]!==v?(y=(0,l.jsxDEV)("div",{className:"flex items-center justify-between gap-2",children:[b,v]},void 0,!0),e[17]=b,e[18]=v,e[19]=y):y=e[19];let N=!o,C;e[20]!==d?(C=n(E=>{d(E.target.value)},"t11"),e[20]=d,e[21]=C):C=e[21];let S;e[22]!==s||e[23]!==N||e[24]!==C||e[25]!==f||e[26]!==t?(S=(0,l.jsxDEV)(ce,{"aria-invalid":N,className:"min-h-[4rem] font-mono text-xs","data-testid":f,id:s,onChange:C,value:t},void 0,!1),e[22]=s,e[23]=N,e[24]=C,e[25]=f,e[26]=t,e[27]=S):S=e[27];let k;e[28]!==u||e[29]!==a||e[30]!==o?(k=!o&&(0,l.jsxDEV)("p",{className:"text-xs text-destructive","data-testid":u,children:a("Metadata must be valid JSON.")},void 0,!1),e[28]=u,e[29]=a,e[30]=o,e[31]=k):k=e[31];let w;return e[32]!==S||e[33]!==k||e[34]!==y?(w=(0,l.jsxDEV)("div",{className:"mb-3 grid gap-1",children:[y,S,k]},void 0,!0),e[32]=S,e[33]=k,e[34]=y,e[35]=w):w=e[35],w},"MetadataField"),Je={busy:!1,error:null,metadata:"",name:"",ttl:"",value:""},Pe=n((r,e)=>{switch(e.type){case"setField":return{...r,[e.field]:e.value};case"submitFailed":return{...r,busy:!1,error:e.error};case"submitStart":return{...r,busy:!0,error:null};default:return r}},"createReducer"),$e=n(r=>{let e=(0,ee.c)(73),{namespace:s,onCancel:u,onCreated:d}=r,f=Y(),o=U(),[t,a]=(0,J.useReducer)(Pe,Je),p;e[0]!==t.metadata?(p=Ee(t.metadata),e[0]=t.metadata,e[1]=p):p=e[1];let c=p,x;e[2]!==t.ttl?(x=Ke(t.ttl),e[2]=t.ttl,e[3]=x):x=e[3];let b=x,M;e[4]!==c||e[5]!==t.busy||e[6]!==t.name||e[7]!==b?(M=t.name.trim()!==""&&c&&b&&!t.busy,e[4]=c,e[5]=t.busy,e[6]=t.name,e[7]=b,e[8]=M):M=e[8];let V=M,L;e[9]!==V||e[10]!==f||e[11]!==s||e[12]!==d||e[13]!==t.metadata||e[14]!==t.name||e[15]!==t.ttl||e[16]!==t.value?(L=n(()=>{V&&(a({type:"submitStart"}),R((async()=>{try{await f.putKvValue(Ve({metadata:t.metadata,ttl:t.ttl,value:t.value},t.name,s)),d()}catch(H){a({error:z(H),type:"submitFailed"})}})()))},"t4"),e[9]=V,e[10]=f,e[11]=s,e[12]=d,e[13]=t.metadata,e[14]=t.name,e[15]=t.ttl,e[16]=t.value,e[17]=L):L=e[17];let h=L,v;e[18]!==o?(v=o("Key name"),e[18]=o,e[19]=v):v=e[19];let y;e[20]!==v?(y=(0,l.jsxDEV)(W,{className:"text-xs",htmlFor:"kv-create-name",children:v},void 0,!1),e[20]=v,e[21]=y):y=e[21];let N;e[22]===Symbol.for("react.memo_cache_sentinel")?(N=n(H=>{a({field:"name",type:"setField",value:H.target.value})},"t7"),e[22]=N):N=e[22];let C;e[23]!==o?(C=o("Key name"),e[23]=o,e[24]=C):C=e[24];let S;e[25]!==t.name||e[26]!==C?(S=(0,l.jsxDEV)(le,{autoFocus:!0,"data-testid":"kv-create-name",id:"kv-create-name",onChange:N,placeholder:C,value:t.name},void 0,!1),e[25]=t.name,e[26]=C,e[27]=S):S=e[27];let k;e[28]!==y||e[29]!==S?(k=(0,l.jsxDEV)("div",{className:"grid gap-1",children:[y,S]},void 0,!0),e[28]=y,e[29]=S,e[30]=k):k=e[30];let w;e[31]!==o?(w=o("Value"),e[31]=o,e[32]=w):w=e[32];let E;e[33]!==w?(E=(0,l.jsxDEV)(W,{className:"text-xs",htmlFor:"kv-create-value",children:w},void 0,!1),e[33]=w,e[34]=E):E=e[34];let B;e[35]===Symbol.for("react.memo_cache_sentinel")?(B=n(H=>{a({field:"value",type:"setField",value:H.target.value})},"t13"),e[35]=B):B=e[35];let I;e[36]!==t.value?(I=(0,l.jsxDEV)(ce,{className:"min-h-[6rem] font-mono text-xs","data-testid":"kv-create-value",id:"kv-create-value",onChange:B,value:t.value},void 0,!1),e[36]=t.value,e[37]=I):I=e[37];let O;e[38]!==E||e[39]!==I?(O=(0,l.jsxDEV)("div",{className:"grid gap-1",children:[E,I]},void 0,!0),e[38]=E,e[39]=I,e[40]=O):O=e[40];let D=!b,i;e[41]===Symbol.for("react.memo_cache_sentinel")?(i=n(H=>{a({field:"ttl",type:"setField",value:H})},"t17"),e[41]=i):i=e[41];let m;e[42]!==D?(m=(0,l.jsxDEV)(Ie,{id:"kv-create-ttl",invalid:D,onChange:i,testId:"kv-create-ttl"},void 0,!1),e[42]=D,e[43]=m):m=e[43];let K;e[44]===Symbol.for("react.memo_cache_sentinel")?(K=n(H=>{a({field:"metadata",type:"setField",value:H})},"t19"),e[44]=K):K=e[44];let T;e[45]!==c||e[46]!==t.metadata?(T=(0,l.jsxDEV)(_e,{id:"kv-create-metadata",invalidTestId:"kv-create-metadata-invalid",onChange:K,testId:"kv-create-metadata",valid:c,value:t.metadata},void 0,!1),e[45]=c,e[46]=t.metadata,e[47]=T):T=e[47];let _=!V,F;e[48]!==t.busy||e[49]!==o?(F=t.busy?o("Creating\u2026"):o("Create key"),e[48]=t.busy,e[49]=o,e[50]=F):F=e[50];let A;e[51]!==h||e[52]!==_||e[53]!==F?(A=(0,l.jsxDEV)($,{"data-testid":"kv-create-submit",disabled:_,onClick:h,children:F},void 0,!1),e[51]=h,e[52]=_,e[53]=F,e[54]=A):A=e[54];let g=t.busy,P;e[55]!==o?(P=o("Cancel"),e[55]=o,e[56]=P):P=e[56];let j;e[57]!==u||e[58]!==t.busy||e[59]!==P?(j=(0,l.jsxDEV)($,{"data-testid":"kv-create-cancel",disabled:g,onClick:u,variant:"outline",children:P},void 0,!1),e[57]=u,e[58]=t.busy,e[59]=P,e[60]=j):j=e[60];let Z;e[61]!==A||e[62]!==j?(Z=(0,l.jsxDEV)("div",{className:"flex flex-wrap gap-2",children:[A,j]},void 0,!0),e[61]=A,e[62]=j,e[63]=Z):Z=e[63];let G;e[64]!==t.error?(G=t.error!==null&&(0,l.jsxDEV)("p",{className:"text-sm text-destructive","data-testid":"kv-create-error",role:"alert",children:t.error},void 0,!1),e[64]=t.error,e[65]=G):G=e[65];let te;return e[66]!==k||e[67]!==O||e[68]!==m||e[69]!==T||e[70]!==Z||e[71]!==G?(te=(0,l.jsxDEV)("div",{className:"grid gap-3 px-4 pb-4","data-testid":"kv-create-form",children:[k,O,m,T,Z,G]},void 0,!0),e[66]=k,e[67]=O,e[68]=m,e[69]=T,e[70]=Z,e[71]=G,e[72]=te):te=e[72],te},"KvCreateForm"),He={busy:"",editedMetadata:"",editedTtl:"",editedValue:"",loadError:null,loading:!0,value:null,writeError:null},Re=n((r,e)=>{switch(e.type){case"deleteStart":return{...r,busy:"deleting",writeError:null};case"editMetadata":return{...r,editedMetadata:e.value};case"editTtl":return{...r,editedTtl:e.value};case"editValue":return{...r,editedValue:e.value};case"loaded":return{...r,editedMetadata:e.metadata===null||e.metadata===void 0?"":JSON.stringify(e.metadata,null,2),editedValue:e.value??"",loading:!1,value:e.value};case"loadFailed":return{...r,loadError:e.error,loading:!1};case"saveOk":return{...r,busy:"",value:r.editedValue};case"saveStart":return{...r,busy:"saving",writeError:null};case"writeFailed":return{...r,busy:"",writeError:e.error};default:return r}},"valueReducer"),je=n(r=>{let e=(0,ee.c)(67),{expiration:s,keyName:u,namespace:d,onDeleted:f}=r,o=Y(),t=U(),[a,p]=(0,J.useReducer)(Re,He),c,x;e[0]!==o||e[1]!==u||e[2]!==d?(c=n(()=>{let g={cancelled:!1};return R((async()=>{try{let P=await o.getKvValue({key:u,namespace:d});g.cancelled||p({metadata:P.metadata,type:"loaded",value:P.value})}catch(P){let j=P;g.cancelled||p({error:z(j),type:"loadFailed"})}})()),()=>{g.cancelled=!0}},"t1"),x=[o,d,u],e[0]=o,e[1]=u,e[2]=d,e[3]=c,e[4]=x):(c=e[3],x=e[4]),(0,J.useEffect)(c,x);let b;e[5]===Symbol.for("react.memo_cache_sentinel")?(b=n(g=>{p({type:"editValue",value:g.target.value})},"t3"),e[5]=b):b=e[5];let M=b,V;e[6]===Symbol.for("react.memo_cache_sentinel")?(V=n(g=>{p({type:"editMetadata",value:g})},"t4"),e[6]=V):V=e[6];let L=V,h;e[7]!==a.editedValue?(h=Te(a.editedValue),e[7]=a.editedValue,e[8]=h):h=e[8];let v=h,y;e[9]!==a.editedMetadata?(y=Ee(a.editedMetadata),e[9]=a.editedMetadata,e[10]=y):y=e[10];let N=y,C;e[11]!==a.editedTtl?(C=Ke(a.editedTtl),e[11]=a.editedTtl,e[12]=C):C=e[12];let S=C,k;e[13]!==v?(k=n(()=>{v!==void 0&&p({type:"editValue",value:v})},"t8"),e[13]=v,e[14]=k):k=e[14];let w=k,E;e[15]!==o||e[16]!==s||e[17]!==u||e[18]!==N||e[19]!==d||e[20]!==a.editedMetadata||e[21]!==a.editedTtl||e[22]!==a.editedValue||e[23]!==t?(E=n(()=>{if(!N){p({error:t("Metadata must be valid JSON."),type:"writeFailed"});return}p({type:"saveStart"}),R((async()=>{try{await o.putKvValue(Ve({metadata:a.editedMetadata,ttl:a.editedTtl,value:a.editedValue},u,d,s)),p({type:"saveOk"})}catch(g){p({error:z(g),type:"writeFailed"})}})())},"t9"),e[15]=o,e[16]=s,e[17]=u,e[18]=N,e[19]=d,e[20]=a.editedMetadata,e[21]=a.editedTtl,e[22]=a.editedValue,e[23]=t,e[24]=E):E=e[24];let B=E,I;e[25]!==o||e[26]!==u||e[27]!==d||e[28]!==f?(I=n(()=>{p({type:"deleteStart"}),R((async()=>{try{await o.deleteKvKey({key:u,namespace:d}),f(u)}catch(g){p({error:z(g),type:"writeFailed"})}})())},"t10"),e[25]=o,e[26]=u,e[27]=d,e[28]=f,e[29]=I):I=e[29];let O=I,D;e[30]!==u?(D=n(()=>{ie(u)},"t11"),e[30]=u,e[31]=D):D=e[31];let i;e[32]!==t?(i=t("Copy key"),e[32]=t,e[33]=i):i=e[33];let m;e[34]!==D||e[35]!==i?(m=(0,l.jsxDEV)("div",{className:"mb-2 flex justify-end",children:(0,l.jsxDEV)($,{"data-testid":"kv-copy-key-btn",onClick:D,size:"sm",variant:"outline",children:i},void 0,!1)},void 0,!1),e[34]=D,e[35]=i,e[36]=m):m=e[36];let K;e[37]!==a.loadError?(K=a.loadError!==null&&(0,l.jsxDEV)("p",{className:"mb-2 text-sm text-destructive","data-testid":"kv-value-error",role:"alert",children:a.loadError},void 0,!1),e[37]=a.loadError,e[38]=K):K=e[38];let T;e[39]!==a.loading||e[40]!==t?(T=a.loading&&(0,l.jsxDEV)("p",{className:"text-sm text-muted-foreground","data-testid":"kv-value-loading",children:t("Loading\u2026")},void 0,!1),e[39]=a.loading,e[40]=t,e[41]=T):T=e[41];let _;e[42]!==v||e[43]!==N||e[44]!==O||e[45]!==w||e[46]!==B||e[47]!==a.busy||e[48]!==a.editedMetadata||e[49]!==a.editedValue||e[50]!==a.loading||e[51]!==a.value||e[52]!==a.writeError||e[53]!==t||e[54]!==S?(_=!a.loading&&a.value!==null&&(0,l.jsxDEV)(l.Fragment,{children:[(0,l.jsxDEV)("div",{className:"mb-1 flex flex-wrap items-center gap-2",children:[(0,l.jsxDEV)(W,{className:"text-xs",htmlFor:"kv-value-editor",children:t("Value")},void 0,!1),v!==void 0&&(0,l.jsxDEV)(he,{variant:"secondary",children:t("JSON")},void 0,!1),(0,l.jsxDEV)("span",{className:"ml-auto text-xs tabular-nums text-muted-foreground","data-testid":"kv-value-size",children:ke(Ae(a.editedValue))},void 0,!1)]},void 0,!0),(0,l.jsxDEV)("textarea",{"aria-label":t("KV value"),className:"mb-2 min-h-[8rem] w-full rounded border border-border bg-muted/30 p-2 font-mono text-xs","data-testid":"kv-value-editor",id:"kv-value-editor",onChange:M,value:a.editedValue},void 0,!1),(0,l.jsxDEV)("div",{className:"mb-3 flex flex-wrap gap-2",children:[(0,l.jsxDEV)($,{"data-testid":"kv-format-btn",disabled:v===void 0,onClick:w,size:"sm",variant:"outline",children:t("Format JSON")},void 0,!1),(0,l.jsxDEV)($,{"data-testid":"kv-copy-value-btn",onClick:n(()=>{ie(a.editedValue)},"onClick"),size:"sm",variant:"outline",children:t("Copy value")},void 0,!1)]},void 0,!0),(0,l.jsxDEV)(Ie,{helper:t("Leave blank to keep the current expiration."),id:"kv-ttl-input",invalid:!S,onChange:n(g=>{p({type:"editTtl",value:g})},"onChange"),testId:"kv-ttl-input"},void 0,!1),(0,l.jsxDEV)(_e,{id:"kv-metadata-editor",invalidTestId:"kv-metadata-invalid",onChange:L,testId:"kv-metadata-editor",valid:N,value:a.editedMetadata},void 0,!1),(0,l.jsxDEV)("div",{className:"flex flex-wrap gap-2",children:[(0,l.jsxDEV)($,{"data-testid":"kv-save-btn",disabled:a.busy!==""||!N||!S,onClick:B,children:a.busy==="saving"?t("Saving\u2026"):t("Save")},void 0,!1),(0,l.jsxDEV)($,{"data-testid":"kv-delete-btn",disabled:a.busy!=="",onClick:O,variant:"destructive",children:a.busy==="deleting"?t("Deleting\u2026"):t("Delete")},void 0,!1)]},void 0,!0),a.writeError!==null&&(0,l.jsxDEV)("p",{className:"mt-2 text-sm text-destructive","data-testid":"kv-save-error",role:"alert",children:a.writeError},void 0,!1)]},void 0,!0),e[42]=v,e[43]=N,e[44]=O,e[45]=w,e[46]=B,e[47]=a.busy,e[48]=a.editedMetadata,e[49]=a.editedValue,e[50]=a.loading,e[51]=a.value,e[52]=a.writeError,e[53]=t,e[54]=S,e[55]=_):_=e[55];let F;e[56]!==a.loadError||e[57]!==a.loading||e[58]!==a.value||e[59]!==t?(F=!a.loading&&a.value===null&&a.loadError===null&&(0,l.jsxDEV)("p",{className:"text-sm text-muted-foreground","data-testid":"kv-absent",children:t("Key is absent or has no value.")},void 0,!1),e[56]=a.loadError,e[57]=a.loading,e[58]=a.value,e[59]=t,e[60]=F):F=e[60];let A;return e[61]!==m||e[62]!==K||e[63]!==T||e[64]!==_||e[65]!==F?(A=(0,l.jsxDEV)("div",{className:"px-4 pb-4","data-testid":"kv-value-section",children:[m,K,T,_,F]},void 0,!0),e[61]=m,e[62]=K,e[63]=T,e[64]=_,e[65]=F,e[66]=A):A=e[66],A},"KvValueEditor"),we=100,ze={appliedPrefix:"",bulk:[],bulkBusy:!1,bulkError:null,cursor:null,keys:null,listComplete:!1,loadError:null,loading:!1,prefixInput:"",reloadNonce:0,selectedKey:null},Ue=n((r,e)=>{switch(e.type){case"appendPage":return{...r,cursor:e.cursor,keys:[...r.keys??[],...e.keys],listComplete:e.listComplete,loading:!1};case"applyFilter":return{...r,appliedPrefix:r.prefixInput,bulk:[],bulkError:null,cursor:null,keys:null,listComplete:!1,selectedKey:null};case"bulkDeleted":{let s=new Set(e.deleted);return{...r,bulk:r.bulk.filter(u=>!s.has(u)),bulkBusy:!1,bulkError:e.error,keys:r.keys===null?null:r.keys.filter(u=>!s.has(u.name)),selectedKey:r.selectedKey!==null&&s.has(r.selectedKey)?null:r.selectedKey}}case"bulkDeleteStart":return{...r,bulkBusy:!0,bulkError:null};case"firstPage":return{...r,cursor:e.cursor,keys:e.keys,listComplete:e.listComplete,loading:!1};case"keyDeleted":return{...r,bulk:r.bulk.filter(s=>s!==e.name),keys:r.keys===null?null:r.keys.filter(s=>s.name!==e.name),selectedKey:null};case"loadFailed":return{...r,loadError:e.error,loading:!1};case"loadStart":return{...r,loadError:null,loading:!0};case"prefixInput":return{...r,prefixInput:e.value};case"reload":return{...r,bulk:[],bulkError:null,reloadNonce:r.reloadNonce+1,selectedKey:null};case"selectKey":return{...r,selectedKey:e.name};case"toggleAllBulk":return{...r,bulk:e.names};case"toggleBulk":return{...r,bulk:r.bulk.includes(e.name)?r.bulk.filter(s=>s!==e.name):[...r.bulk,e.name]};default:return r}},"keyListReducer"),Ze=n(({namespace:r})=>{let e=Y(),s=U(),[u,d]=(0,J.useReducer)(Ue,ze),{appliedPrefix:f,bulk:o,bulkBusy:t,bulkError:a,cursor:p,keys:c,listComplete:x,loadError:b,loading:M,prefixInput:V,reloadNonce:L,selectedKey:h}=u,[v,y]=(0,J.useState)(!1);(0,J.useEffect)(()=>{let i={cancelled:!1};return R((async()=>{d({type:"loadStart"});try{let m=await e.listKvKeys({limit:we,namespace:r,prefix:f===""?void 0:f});i.cancelled||d({cursor:m.cursor??null,keys:m.keys,listComplete:m.listComplete,type:"firstPage"})}catch(m){i.cancelled||d({error:z(m),type:"loadFailed"})}})()),()=>{i.cancelled=!0}},[e,r,f,L]);let N=n(i=>{d({type:"prefixInput",value:i.target.value})},"onPrefixChange"),C=n(()=>{d({type:"applyFilter"})},"onFilter"),S=n(i=>{d({name:i.currentTarget.dataset.key??null,type:"selectKey"})},"onSelectKey"),k=n(()=>{p!==null&&(d({type:"loadStart"}),R((async()=>{try{let i=await e.listKvKeys({cursor:p,limit:we,namespace:r,prefix:f===""?void 0:f});d({cursor:i.cursor??null,keys:i.keys,listComplete:i.listComplete,type:"appendPage"})}catch(i){d({error:z(i),type:"loadFailed"})}})()))},"onLoadMore"),w=n(i=>{d({name:i,type:"keyDeleted"})},"onKeyDeleted"),E=n(i=>{d({name:i,type:"toggleBulk"})},"onToggleBulk"),B=n(i=>{d({names:i&&c!==null?c.map(m=>m.name):[],type:"toggleAllBulk"})},"onToggleAll"),I=n(()=>{if(o.length===0)return;let i=[...o];d({type:"bulkDeleteStart"}),R((async()=>{let m=await Promise.allSettled(i.map(_=>e.deleteKvKey({key:_,namespace:r}))),K=i.filter((_,F)=>m[F]?.status==="fulfilled"),T=i.length-K.length;d({deleted:K,error:T>0?s("Failed to delete {count} keys.",{count:T}):null,type:"bulkDeleted"})})())},"onBulkDelete"),O=n(()=>{y(!1),d({type:"reload"})},"onCreated"),D=c!==null&&c.length>0&&o.length===c.length;return(0,l.jsxDEV)(l.Fragment,{children:[(0,l.jsxDEV)("section",{className:"border border-border bg-card p-3","data-testid":"kv-keys-section",children:[(0,l.jsxDEV)("div",{className:"mb-3 flex flex-wrap items-center gap-2",children:[(0,l.jsxDEV)(le,{"aria-label":s("Filter keys by prefix"),className:"min-w-[16rem] flex-1","data-testid":"kv-prefix-input",onChange:N,placeholder:s("Filter by prefix\u2026"),value:V},void 0,!1),(0,l.jsxDEV)($,{"data-testid":"kv-filter-btn",disabled:M,onClick:C,children:s("Filter")},void 0,!1),(0,l.jsxDEV)($,{"data-testid":"kv-new-key-btn",onClick:n(()=>{y(i=>!i)},"onClick"),variant:"outline",children:s("New key")},void 0,!1),o.length>0&&(0,l.jsxDEV)($,{"data-testid":"kv-bulk-delete-btn",disabled:t,onClick:I,variant:"destructive",children:t?s("Deleting\u2026"):s("Delete {count}",{count:o.length})},void 0,!1)]},void 0,!0),a!==null&&(0,l.jsxDEV)("p",{className:"mb-2 text-sm text-destructive","data-testid":"kv-bulk-error",role:"alert",children:a},void 0,!1),b!==null&&(0,l.jsxDEV)("p",{className:"text-sm text-destructive","data-testid":"kv-keys-error",role:"alert",children:b},void 0,!1),c!==null&&c.length===0&&!M&&(0,l.jsxDEV)("p",{className:"text-sm text-muted-foreground","data-testid":"kv-no-keys",children:s("No keys.")},void 0,!1),c!==null&&c.length>0&&(0,l.jsxDEV)(re,{className:"overflow-hidden py-0",children:(0,l.jsxDEV)(se,{className:"px-0",children:(0,l.jsxDEV)(de,{"data-testid":"kv-key-table",children:[(0,l.jsxDEV)(ne,{children:(0,l.jsxDEV)(q,{children:[(0,l.jsxDEV)(Q,{className:"w-10",children:(0,l.jsxDEV)(ue,{"aria-label":s("Select all"),checked:D,"data-testid":"kv-select-all",onCheckedChange:B},void 0,!1)},void 0,!1),(0,l.jsxDEV)(Q,{children:s("Key")},void 0,!1),(0,l.jsxDEV)(Q,{children:s("Expiration")},void 0,!1)]},void 0,!0)},void 0,!1),(0,l.jsxDEV)(oe,{children:c.map(i=>(0,l.jsxDEV)(q,{className:i.name===h?"border-l-2 border-l-royal-amethyst bg-muted/50":"cursor-pointer","data-key":i.name,"data-testid":`kv-key-row-${i.name}`,onClick:S,children:[(0,l.jsxDEV)(X,{onClick:n(m=>{m.stopPropagation()},"onClick"),children:(0,l.jsxDEV)(ue,{"aria-label":s("Select {name}",{name:i.name}),checked:o.includes(i.name),"data-testid":`kv-select-${i.name}`,onCheckedChange:n(()=>{E(i.name)},"onCheckedChange")},void 0,!1)},void 0,!1),(0,l.jsxDEV)(X,{className:"font-mono text-xs",children:i.name},void 0,!1),(0,l.jsxDEV)(X,{className:"tabular-nums text-xs",children:Oe(i.expiration)},void 0,!1)]},i.name,!0))},void 0,!1)]},void 0,!0)},void 0,!1)},void 0,!1),!x&&p!==null&&(0,l.jsxDEV)("div",{className:"mt-2",children:(0,l.jsxDEV)($,{"data-testid":"kv-load-more",disabled:M,onClick:k,variant:"outline",children:s(M?"Loading\u2026":"Load more")},void 0,!1)},void 0,!1)]},void 0,!0),(0,l.jsxDEV)(me,{onOpenChange:n(i=>{i||y(!1)},"onOpenChange"),open:v,children:(0,l.jsxDEV)(ve,{className:"w-full gap-0 overflow-y-auto sm:max-w-md","data-testid":"kv-create-sheet",side:"right",children:[(0,l.jsxDEV)(fe,{children:(0,l.jsxDEV)(pe,{children:s("New key")},void 0,!1)},void 0,!1),(0,l.jsxDEV)($e,{namespace:r,onCancel:n(()=>{y(!1)},"onCancel"),onCreated:O},void 0,!1)]},void 0,!0)},void 0,!1),(0,l.jsxDEV)(me,{onOpenChange:n(i=>{i||d({name:null,type:"selectKey"})},"onOpenChange"),open:h!==null,children:(0,l.jsxDEV)(ve,{className:"w-full gap-0 overflow-y-auto sm:max-w-md","data-testid":"kv-editor-sheet",side:"right",children:[(0,l.jsxDEV)(fe,{children:(0,l.jsxDEV)(pe,{className:"truncate font-mono text-xs",children:h},void 0,!1)},void 0,!1),h!==null&&(0,l.jsxDEV)(je,{expiration:c?.find(i=>i.name===h)?.expiration,keyName:h,namespace:r,onDeleted:w},`${r}:${h}`,!1)]},void 0,!0)},void 0,!1)]},void 0,!0)},"KvKeyList"),ot=n(({loadNamespaces:r}={})=>{let e=Y(),s=U(),[u,d]=(0,J.useState)(null),[f,o]=(0,J.useState)(null),[t,a]=(0,J.useState)(null);(0,J.useEffect)(()=>{let c={cancelled:!1};return R((async()=>{try{let x=await(r??(()=>e.listKvNamespaces()))();c.cancelled||(d(x),o(null),a(b=>b??x[0]?.binding??null))}catch(x){c.cancelled||(d(null),o(z(x)))}})()),()=>{c.cancelled=!0}},[e,r]);let p=n(c=>{a(c.currentTarget.dataset.ns??null)},"onSelectNs");return(0,l.jsxDEV)("div",{className:"flex flex-col gap-4","data-testid":"lunora-kv-browser",children:[f!==null&&(0,l.jsxDEV)("p",{className:"text-sm text-destructive","data-testid":"kv-ns-error",role:"alert",children:f},void 0,!1),u!==null&&u.length===0&&(0,l.jsxDEV)(ye,{description:s("Add a kv_namespaces binding to wrangler.jsonc \u2014 it appears here automatically, no wiring needed."),icon:(0,l.jsxDEV)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,l.jsxDEV)("path",{d:"M5 5h14v4H5V5Zm0 5h14v4H5v-4Zm0 5h14v4H5v-4Z"},void 0,!1)},void 0,!1),testId:"kv-empty",title:s("No KV namespaces.")},void 0,!1),u!==null&&u.length>0&&(0,l.jsxDEV)(re,{className:"overflow-hidden py-0",children:(0,l.jsxDEV)(se,{className:"px-0",children:(0,l.jsxDEV)(de,{"data-testid":"kv-namespace-table",children:[(0,l.jsxDEV)(ne,{children:(0,l.jsxDEV)(q,{children:(0,l.jsxDEV)(Q,{children:s("Namespace")},void 0,!1)},void 0,!1)},void 0,!1),(0,l.jsxDEV)(oe,{children:u.map(c=>(0,l.jsxDEV)(q,{className:c.binding===t?"border-l-2 border-l-royal-amethyst bg-muted/50":"cursor-pointer","data-ns":c.binding,"data-testid":`kv-ns-row-${c.binding}`,onClick:p,children:(0,l.jsxDEV)(X,{className:"font-mono text-xs",children:c.binding},void 0,!1)},c.binding,!1))},void 0,!1)]},void 0,!0)},void 0,!1)},void 0,!1),t!==null&&(0,l.jsxDEV)(Ze,{namespace:t},t,!1)]},void 0,!0)},"KvBrowser");export{ot as KvBrowser};
@@ -1 +1 @@
1
- import{a as S}from"./chunk-WUFVFVHJ.js";import"./chunk-XNJNSCLM.js";import{b as T}from"./chunk-W666BB6V.js";import{a as w,b as A,c as E,d as m,e as s,f as l}from"./chunk-GTM65MVX.js";import{a as N,e as b}from"./chunk-SEU5V7I6.js";import{a as O}from"./chunk-VLXV72QE.js";import{a as k}from"./chunk-JSEXCW5Q.js";import{b as y}from"./chunk-ZPP2KOR4.js";import"./chunk-CKSHCYGC.js";import{a as C}from"./chunk-BOXSWNXZ.js";import"./chunk-SDMZKBTD.js";import"./chunk-ZHVTQ37P.js";import"./chunk-3OA7PECS.js";import{a as u}from"./chunk-TAD43CG5.js";import{d as h}from"./chunk-ITQKVEP7.js";import"./chunk-22C6COGE.js";import{a as d,e as p,f as D,h as H}from"./chunk-RRCPZMC2.js";var n=p(D(),1);var e=p(H(),1);var K=d(a=>{let t=a.trim();if(t.length===0)return{context:void 0,error:null};try{let o=JSON.parse(t);return o===null||typeof o!="object"||Array.isArray(o)?{context:void 0,error:"Targeting context must be a JSON object."}:{context:o,error:null}}catch{return{context:void 0,error:"Targeting context is not valid JSON."}}},"parseContext"),R='{ "targetingKey": "user-123", "plan": "premium" }',M=d(a=>a.type==="object"?JSON.stringify(a.value):String(a.value),"formatValue"),Y=d(({initialShardKey:a=""})=>{let t=h(),[o,F]=(0,n.useState)(""),{context:f,error:g}=K(o),I=(0,n.useMemo)(()=>f===void 0?{}:{context:f},[f]),{data:i,error:J,errorSource:L,liveError:j}=T(C.listFlags,I,{live:!0,shardKey:a}),v=i!==void 0,V=i?.configured??!1,x=(0,n.useMemo)(()=>Array.isArray(i?.flags)?[...i.flags].toSorted((r,B)=>r.key.localeCompare(B.key)):[],[i]),c;return v&&!V?c=(0,e.jsxDEV)(u,{description:t("No @lunora/flags provider is wired in this deployment. Add lunora/flags.ts with defineFlags({ provider }) to gate code paths on feature flags."),testId:"flags-unconfigured",title:t("No flags provider configured")},void 0,!1):v&&x.length===0?c=(0,e.jsxDEV)(u,{description:t('A flags provider is configured, but no handler reads a flag yet. Call ctx.flags.boolean("key", false) in a query, mutation, or action.'),testId:"flags-empty",title:t("No flags read")},void 0,!1):c=(0,e.jsxDEV)(N,{className:"overflow-hidden py-0",children:(0,e.jsxDEV)(b,{className:"px-0",children:(0,e.jsxDEV)(w,{"data-testid":"flags-table",children:[(0,e.jsxDEV)(A,{children:(0,e.jsxDEV)(m,{children:[(0,e.jsxDEV)(s,{children:t("Key")},void 0,!1),(0,e.jsxDEV)(s,{children:t("Type")},void 0,!1),(0,e.jsxDEV)(s,{children:t("Value")},void 0,!1),(0,e.jsxDEV)(s,{children:t("Reason")},void 0,!1),(0,e.jsxDEV)(s,{children:t("Variant")},void 0,!1)]},void 0,!0)},void 0,!1),(0,e.jsxDEV)(E,{children:x.map(r=>(0,e.jsxDEV)(m,{"data-testid":`flags-row-${r.key}`,children:[(0,e.jsxDEV)(l,{className:"font-mono text-xs",children:r.key},void 0,!1),(0,e.jsxDEV)(l,{className:"font-mono text-xs text-muted-foreground",children:r.type},void 0,!1),(0,e.jsxDEV)(l,{className:"font-mono text-xs",children:M(r)},void 0,!1),(0,e.jsxDEV)(l,{children:r.errorCode===void 0?(0,e.jsxDEV)("span",{className:"font-mono text-xs text-muted-foreground",children:r.reason??"\u2014"},void 0,!1):(0,e.jsxDEV)(y,{"data-testid":`flags-error-${r.key}`,variant:"destructive",children:r.errorCode},void 0,!1)},void 0,!1),(0,e.jsxDEV)(l,{className:"font-mono text-xs text-muted-foreground",children:r.variant??"\u2014"},void 0,!1)]},r.key,!0))},void 0,!1)]},void 0,!0)},void 0,!1)},void 0,!1),(0,e.jsxDEV)("div",{className:"flex flex-col gap-6","data-testid":"lunora-flags-panel",children:[J!==null&&(0,e.jsxDEV)(S,{error:L,testId:"flags-error"},void 0,!1),(0,e.jsxDEV)("p",{className:"text-sm text-muted-foreground",children:t('Feature flags are read in code with ctx.flags.<type>("key", default). They evaluate through the OpenFeature provider configured in lunora/flags.ts; edit the targeting context below to see how each flag resolves for a given audience.')},void 0,!1),(0,e.jsxDEV)("div",{className:"flex flex-col gap-2",children:[(0,e.jsxDEV)(k,{htmlFor:"flags-targeting-context",children:t("Targeting context (JSON)")},void 0,!1),(0,e.jsxDEV)(O,{className:"font-mono text-xs","data-testid":"flags-context-input",id:"flags-targeting-context",onChange:d(r=>{F(r.target.value)},"onChange"),placeholder:R,rows:3,value:o},void 0,!1),g!==null&&(0,e.jsxDEV)("p",{className:"text-xs text-destructive","data-testid":"flags-context-error",role:"alert",children:t(g)},void 0,!1),j!==void 0&&(0,e.jsxDEV)("p",{className:"text-xs text-amber-600 dark:text-amber-500","data-testid":"flags-live-error",role:"alert",children:t("Live updates unavailable; showing the last evaluation.")},void 0,!1)]},void 0,!0),c]},void 0,!0)},"FlagsPanel");export{Y as FlagsPanel};
1
+ import{a as S}from"./chunk-WUFVFVHJ.js";import"./chunk-XNJNSCLM.js";import{b as T}from"./chunk-W666BB6V.js";import{a as w,b as A,c as E,d as m,e as s,f as l}from"./chunk-GTM65MVX.js";import{a as N,e as b}from"./chunk-SEU5V7I6.js";import{a as O}from"./chunk-VLXV72QE.js";import{a as k}from"./chunk-JSEXCW5Q.js";import{b as y}from"./chunk-ZPP2KOR4.js";import"./chunk-CKSHCYGC.js";import{a as C}from"./chunk-G7ZBM54M.js";import"./chunk-SDMZKBTD.js";import"./chunk-ZHVTQ37P.js";import"./chunk-3OA7PECS.js";import{a as u}from"./chunk-TAD43CG5.js";import{d as h}from"./chunk-ITQKVEP7.js";import"./chunk-22C6COGE.js";import{a as d,e as p,f as D,h as H}from"./chunk-RRCPZMC2.js";var n=p(D(),1);var e=p(H(),1);var K=d(a=>{let t=a.trim();if(t.length===0)return{context:void 0,error:null};try{let o=JSON.parse(t);return o===null||typeof o!="object"||Array.isArray(o)?{context:void 0,error:"Targeting context must be a JSON object."}:{context:o,error:null}}catch{return{context:void 0,error:"Targeting context is not valid JSON."}}},"parseContext"),R='{ "targetingKey": "user-123", "plan": "premium" }',M=d(a=>a.type==="object"?JSON.stringify(a.value):String(a.value),"formatValue"),Y=d(({initialShardKey:a=""})=>{let t=h(),[o,F]=(0,n.useState)(""),{context:f,error:g}=K(o),I=(0,n.useMemo)(()=>f===void 0?{}:{context:f},[f]),{data:i,error:J,errorSource:L,liveError:j}=T(C.listFlags,I,{live:!0,shardKey:a}),v=i!==void 0,V=i?.configured??!1,x=(0,n.useMemo)(()=>Array.isArray(i?.flags)?[...i.flags].toSorted((r,B)=>r.key.localeCompare(B.key)):[],[i]),c;return v&&!V?c=(0,e.jsxDEV)(u,{description:t("No @lunora/flags provider is wired in this deployment. Add lunora/flags.ts with defineFlags({ provider }) to gate code paths on feature flags."),testId:"flags-unconfigured",title:t("No flags provider configured")},void 0,!1):v&&x.length===0?c=(0,e.jsxDEV)(u,{description:t('A flags provider is configured, but no handler reads a flag yet. Call ctx.flags.boolean("key", false) in a query, mutation, or action.'),testId:"flags-empty",title:t("No flags read")},void 0,!1):c=(0,e.jsxDEV)(N,{className:"overflow-hidden py-0",children:(0,e.jsxDEV)(b,{className:"px-0",children:(0,e.jsxDEV)(w,{"data-testid":"flags-table",children:[(0,e.jsxDEV)(A,{children:(0,e.jsxDEV)(m,{children:[(0,e.jsxDEV)(s,{children:t("Key")},void 0,!1),(0,e.jsxDEV)(s,{children:t("Type")},void 0,!1),(0,e.jsxDEV)(s,{children:t("Value")},void 0,!1),(0,e.jsxDEV)(s,{children:t("Reason")},void 0,!1),(0,e.jsxDEV)(s,{children:t("Variant")},void 0,!1)]},void 0,!0)},void 0,!1),(0,e.jsxDEV)(E,{children:x.map(r=>(0,e.jsxDEV)(m,{"data-testid":`flags-row-${r.key}`,children:[(0,e.jsxDEV)(l,{className:"font-mono text-xs",children:r.key},void 0,!1),(0,e.jsxDEV)(l,{className:"font-mono text-xs text-muted-foreground",children:r.type},void 0,!1),(0,e.jsxDEV)(l,{className:"font-mono text-xs",children:M(r)},void 0,!1),(0,e.jsxDEV)(l,{children:r.errorCode===void 0?(0,e.jsxDEV)("span",{className:"font-mono text-xs text-muted-foreground",children:r.reason??"\u2014"},void 0,!1):(0,e.jsxDEV)(y,{"data-testid":`flags-error-${r.key}`,variant:"destructive",children:r.errorCode},void 0,!1)},void 0,!1),(0,e.jsxDEV)(l,{className:"font-mono text-xs text-muted-foreground",children:r.variant??"\u2014"},void 0,!1)]},r.key,!0))},void 0,!1)]},void 0,!0)},void 0,!1)},void 0,!1),(0,e.jsxDEV)("div",{className:"flex flex-col gap-6","data-testid":"lunora-flags-panel",children:[J!==null&&(0,e.jsxDEV)(S,{error:L,testId:"flags-error"},void 0,!1),(0,e.jsxDEV)("p",{className:"text-sm text-muted-foreground",children:t('Feature flags are read in code with ctx.flags.<type>("key", default). They evaluate through the OpenFeature provider configured in lunora/flags.ts; edit the targeting context below to see how each flag resolves for a given audience.')},void 0,!1),(0,e.jsxDEV)("div",{className:"flex flex-col gap-2",children:[(0,e.jsxDEV)(k,{htmlFor:"flags-targeting-context",children:t("Targeting context (JSON)")},void 0,!1),(0,e.jsxDEV)(O,{className:"font-mono text-xs","data-testid":"flags-context-input",id:"flags-targeting-context",onChange:d(r=>{F(r.target.value)},"onChange"),placeholder:R,rows:3,value:o},void 0,!1),g!==null&&(0,e.jsxDEV)("p",{className:"text-xs text-destructive","data-testid":"flags-context-error",role:"alert",children:t(g)},void 0,!1),j!==void 0&&(0,e.jsxDEV)("p",{className:"text-xs text-amber-600 dark:text-amber-500","data-testid":"flags-live-error",role:"alert",children:t("Live updates unavailable; showing the last evaluation.")},void 0,!1)]},void 0,!0),c]},void 0,!0)},"FlagsPanel");export{Y as FlagsPanel};
@@ -1 +1 @@
1
- import{a as w}from"./chunk-WUFVFVHJ.js";import"./chunk-XNJNSCLM.js";import{b as k}from"./chunk-W666BB6V.js";import{a as C,b as $,c as A,d as v,e as n,f as c}from"./chunk-GTM65MVX.js";import{a as N,e as R}from"./chunk-SEU5V7I6.js";import{b as y}from"./chunk-ZPP2KOR4.js";import"./chunk-CKSHCYGC.js";import{a as S}from"./chunk-BOXSWNXZ.js";import"./chunk-SDMZKBTD.js";import"./chunk-ZHVTQ37P.js";import"./chunk-3OA7PECS.js";import{a as T}from"./chunk-TAD43CG5.js";import{d as b}from"./chunk-ITQKVEP7.js";import"./chunk-22C6COGE.js";import{a as p,e as x,g as O,h as B}from"./chunk-RRCPZMC2.js";var I=x(O(),1);var t=x(B(),1);var D=p((e,r)=>({delete:e("Delete"),list:e("List"),read:e("Read"),write:e("Write")})[r],"operationLabel"),E={delete:2,list:3,read:0,write:1},_=p(e=>[...e].toSorted((r,a)=>r.bucket.localeCompare(a.bucket)||E[r.on]-E[a.on]||(r.prefix??"").localeCompare(a.prefix??"")),"sortRules"),Q=p(()=>{let e=(0,I.c)(14),r=b(),a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a={},e[0]=a):a=e[0];let{data:l,error:d,errorSource:i}=k(S.storageRules,a),h=l!==void 0,f;if(e[1]!==l||e[2]!==d||e[3]!==i||e[4]!==h||e[5]!==r){let g=_(Array.isArray(l?.rules)?l.rules:[]),m;e[7]!==d||e[8]!==i?(m=d!==null&&(0,t.jsxDEV)(w,{error:i,testId:"storage-rules-error"},void 0,!1),e[7]=d,e[8]=i,e[9]=m):m=e[9];let s;e[10]!==r?(s=r("Storage rules are declared in code with defineStorageRule and gate ctx.storage access per bucket. This view is read-only."),e[10]=r,e[11]=s):s=e[11];let u;e[12]!==s?(u=(0,t.jsxDEV)("p",{className:"text-sm text-muted-foreground","data-testid":"storage-rules-note",children:s},void 0,!1),e[12]=s,e[13]=u):u=e[13],f=(0,t.jsxDEV)("div",{className:"flex flex-col gap-4","data-testid":"lunora-storage-rules-panel",children:[m,u,h&&g.length===0?(0,t.jsxDEV)(T,{description:r("No defineStorageRule is wired through .use(storageRules(...)) in this deployment. Add one to gate object access by key prefix."),testId:"storage-rules-empty",title:r("No storage rules defined")},void 0,!1):(0,t.jsxDEV)(N,{className:"overflow-hidden py-0",children:(0,t.jsxDEV)(R,{className:"px-0",children:(0,t.jsxDEV)(C,{"data-testid":"storage-rules-table",children:[(0,t.jsxDEV)($,{children:(0,t.jsxDEV)(v,{children:[(0,t.jsxDEV)(n,{children:r("Bucket")},void 0,!1),(0,t.jsxDEV)(n,{children:r("Operation")},void 0,!1),(0,t.jsxDEV)(n,{children:r("Key prefix")},void 0,!1),(0,t.jsxDEV)(n,{children:r("Guarded by")},void 0,!1)]},void 0,!0)},void 0,!1),(0,t.jsxDEV)(A,{children:g.map(o=>(0,t.jsxDEV)(v,{"data-testid":`storage-rule-${o.bucket}-${o.on}-${o.prefix??""}`,children:[(0,t.jsxDEV)(c,{className:"font-mono text-xs",children:o.bucket},void 0,!1),(0,t.jsxDEV)(c,{children:(0,t.jsxDEV)(y,{variant:"secondary",children:D(r,o.on)},void 0,!1)},void 0,!1),(0,t.jsxDEV)(c,{className:"font-mono text-xs",children:o.prefix??(0,t.jsxDEV)("span",{className:"text-muted-foreground",children:r("(whole bucket)")},void 0,!1)},void 0,!1),(0,t.jsxDEV)(c,{className:"font-mono text-xs text-muted-foreground",children:o.procedure},void 0,!1)]},`${o.bucket}:${o.on}:${o.prefix??""}:${o.procedure}`,!0))},void 0,!1)]},void 0,!0)},void 0,!1)},void 0,!1)]},void 0,!0),e[1]=l,e[2]=d,e[3]=i,e[4]=h,e[5]=r,e[6]=f}else f=e[6];return f},"StorageRulesPanel");export{Q as StorageRulesPanel};
1
+ import{a as w}from"./chunk-WUFVFVHJ.js";import"./chunk-XNJNSCLM.js";import{b as k}from"./chunk-W666BB6V.js";import{a as C,b as $,c as A,d as v,e as n,f as c}from"./chunk-GTM65MVX.js";import{a as N,e as R}from"./chunk-SEU5V7I6.js";import{b as y}from"./chunk-ZPP2KOR4.js";import"./chunk-CKSHCYGC.js";import{a as S}from"./chunk-G7ZBM54M.js";import"./chunk-SDMZKBTD.js";import"./chunk-ZHVTQ37P.js";import"./chunk-3OA7PECS.js";import{a as T}from"./chunk-TAD43CG5.js";import{d as b}from"./chunk-ITQKVEP7.js";import"./chunk-22C6COGE.js";import{a as p,e as x,g as O,h as B}from"./chunk-RRCPZMC2.js";var I=x(O(),1);var t=x(B(),1);var D=p((e,r)=>({delete:e("Delete"),list:e("List"),read:e("Read"),write:e("Write")})[r],"operationLabel"),E={delete:2,list:3,read:0,write:1},_=p(e=>[...e].toSorted((r,a)=>r.bucket.localeCompare(a.bucket)||E[r.on]-E[a.on]||(r.prefix??"").localeCompare(a.prefix??"")),"sortRules"),Q=p(()=>{let e=(0,I.c)(14),r=b(),a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a={},e[0]=a):a=e[0];let{data:l,error:d,errorSource:i}=k(S.storageRules,a),h=l!==void 0,f;if(e[1]!==l||e[2]!==d||e[3]!==i||e[4]!==h||e[5]!==r){let g=_(Array.isArray(l?.rules)?l.rules:[]),m;e[7]!==d||e[8]!==i?(m=d!==null&&(0,t.jsxDEV)(w,{error:i,testId:"storage-rules-error"},void 0,!1),e[7]=d,e[8]=i,e[9]=m):m=e[9];let s;e[10]!==r?(s=r("Storage rules are declared in code with defineStorageRule and gate ctx.storage access per bucket. This view is read-only."),e[10]=r,e[11]=s):s=e[11];let u;e[12]!==s?(u=(0,t.jsxDEV)("p",{className:"text-sm text-muted-foreground","data-testid":"storage-rules-note",children:s},void 0,!1),e[12]=s,e[13]=u):u=e[13],f=(0,t.jsxDEV)("div",{className:"flex flex-col gap-4","data-testid":"lunora-storage-rules-panel",children:[m,u,h&&g.length===0?(0,t.jsxDEV)(T,{description:r("No defineStorageRule is wired through .use(storageRules(...)) in this deployment. Add one to gate object access by key prefix."),testId:"storage-rules-empty",title:r("No storage rules defined")},void 0,!1):(0,t.jsxDEV)(N,{className:"overflow-hidden py-0",children:(0,t.jsxDEV)(R,{className:"px-0",children:(0,t.jsxDEV)(C,{"data-testid":"storage-rules-table",children:[(0,t.jsxDEV)($,{children:(0,t.jsxDEV)(v,{children:[(0,t.jsxDEV)(n,{children:r("Bucket")},void 0,!1),(0,t.jsxDEV)(n,{children:r("Operation")},void 0,!1),(0,t.jsxDEV)(n,{children:r("Key prefix")},void 0,!1),(0,t.jsxDEV)(n,{children:r("Guarded by")},void 0,!1)]},void 0,!0)},void 0,!1),(0,t.jsxDEV)(A,{children:g.map(o=>(0,t.jsxDEV)(v,{"data-testid":`storage-rule-${o.bucket}-${o.on}-${o.prefix??""}`,children:[(0,t.jsxDEV)(c,{className:"font-mono text-xs",children:o.bucket},void 0,!1),(0,t.jsxDEV)(c,{children:(0,t.jsxDEV)(y,{variant:"secondary",children:D(r,o.on)},void 0,!1)},void 0,!1),(0,t.jsxDEV)(c,{className:"font-mono text-xs",children:o.prefix??(0,t.jsxDEV)("span",{className:"text-muted-foreground",children:r("(whole bucket)")},void 0,!1)},void 0,!1),(0,t.jsxDEV)(c,{className:"font-mono text-xs text-muted-foreground",children:o.procedure},void 0,!1)]},`${o.bucket}:${o.on}:${o.prefix??""}:${o.procedure}`,!0))},void 0,!1)]},void 0,!0)},void 0,!1)},void 0,!1)]},void 0,!0),e[1]=l,e[2]=d,e[3]=i,e[4]=h,e[5]=r,e[6]=f}else f=e[6];return f},"StorageRulesPanel");export{Q as StorageRulesPanel};
@@ -1 +1 @@
1
- import{a as O}from"./chunk-J6J54MBP.js";import{a as j}from"./chunk-2K47A3P6.js";import{a as H}from"./chunk-WUFVFVHJ.js";import"./chunk-XNJNSCLM.js";import{b as K}from"./chunk-W666BB6V.js";import{a as P,b as F,c as L,d as k,e as u,f as m}from"./chunk-GTM65MVX.js";import{a as M,e as $}from"./chunk-SEU5V7I6.js";import{a as _}from"./chunk-LUP4YTBS.js";import"./chunk-4PC7IXNY.js";import"./chunk-2MLA6WFH.js";import"./chunk-VL23Y44O.js";import"./chunk-HV7G6DFP.js";import"./chunk-O3NAGRTR.js";import{b as y}from"./chunk-ZPP2KOR4.js";import"./chunk-CKSHCYGC.js";import{a as R}from"./chunk-BOXSWNXZ.js";import"./chunk-SDMZKBTD.js";import"./chunk-ZHVTQ37P.js";import"./chunk-3OA7PECS.js";import{a as B}from"./chunk-TAD43CG5.js";import{d as D}from"./chunk-ITQKVEP7.js";import"./chunk-22C6COGE.js";import{a as S,e as T,f as U,g as V,h as X}from"./chunk-RRCPZMC2.js";var G=T(V(),1),J=T(U(),1);var t=T(X(),1);var W=80,Z=S(a=>{if(a===void 0)return"";let e=JSON.stringify(a);return e.length>W?`${e.slice(0,W)}\u2026`:e},"formatArguments"),q=S(a=>{let e=[];for(let n of a){let o=n.id.toString();if(n.subscriptions.length===0){e.push({admin:n.admin,connectionId:n.id,key:`c${o}`,subscription:null});continue}n.subscriptions.forEach((s,N)=>{e.push({admin:n.admin,connectionId:n.id,key:`c${o}-s${N.toString()}`,subscription:s})})}return e},"toRows"),w=(0,t.jsxDEV)("span",{className:"text-muted-foreground",children:"\u2014"},void 0,!1),de=S(a=>{let e=(0,G.c)(22),{initialShardKey:n}=a,o=D(),[s,N]=(0,J.useState)(n??""),f;e[0]!==s?(f=s.trim(),e[0]=s,e[1]=f):f=e[1];let A=j(f,400),h;e[2]===Symbol.for("react.memo_cache_sentinel")?(h={},e[2]=h):h=e[2];let p;e[3]!==A?(p={keepPreviousData:!0,shardKey:A},e[3]=A,e[4]=p):p=e[4];let{data:i,error:r,errorSource:c,refetch:Q}=K(R.listSubscriptions,h,p);O(Q,!0);let v;if(e[5]!==r||e[6]!==c||e[7]!==i||e[8]!==s||e[9]!==o){let C=i===void 0?[]:q(i.connections),l;e[11]!==s?(l=(0,t.jsxDEV)(_,{onChange:N,testId:"subs-shard-input",value:s},void 0,!1),e[11]=s,e[12]=l):l=e[12];let d;e[13]!==i||e[14]!==o?(d=i!==void 0&&(0,t.jsxDEV)("div",{className:"ml-auto flex items-center gap-2 text-sm text-muted-foreground","data-testid":"subs-count",children:[(0,t.jsxDEV)(y,{variant:"secondary",children:o("{count} connections",{count:i.totalConnections})},void 0,!1),(0,t.jsxDEV)(y,{variant:"secondary",children:o("{count} subscriptions",{count:i.totalSubscriptions})},void 0,!1)]},void 0,!0),e[13]=i,e[14]=o,e[15]=d):d=e[15];let b;e[16]!==l||e[17]!==d?(b=(0,t.jsxDEV)("div",{className:"flex flex-wrap items-center gap-2",children:[l,d]},void 0,!0),e[16]=l,e[17]=d,e[18]=b):b=e[18];let g;e[19]!==r||e[20]!==c?(g=r!==null&&(0,t.jsxDEV)(H,{error:c,testId:"subs-error"},void 0,!1),e[19]=r,e[20]=c,e[21]=g):g=e[21],v=(0,t.jsxDEV)("div",{className:"flex flex-col gap-4","data-testid":"subs-panel",children:[b,g,r===null&&i!==void 0&&C.length===0&&(0,t.jsxDEV)(B,{description:o("Active WebSocket subscriptions on this shard."),icon:(0,t.jsxDEV)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,t.jsxDEV)("path",{d:"M5 12a7 7 0 0 1 14 0M8 12a4 4 0 0 1 8 0M12 12v8m0-8a1 1 0 1 0 0-2 1 1 0 0 0 0 2Z"},void 0,!1)},void 0,!1),testId:"subs-empty",title:o("No active subscriptions.")},void 0,!1),r===null&&C.length>0&&(0,t.jsxDEV)(M,{className:"overflow-hidden py-0",children:(0,t.jsxDEV)($,{className:"px-0",children:(0,t.jsxDEV)(P,{"data-testid":"subs-table",children:[(0,t.jsxDEV)(F,{children:(0,t.jsxDEV)(k,{children:[(0,t.jsxDEV)(u,{children:o("Connection")},void 0,!1),(0,t.jsxDEV)(u,{children:o("Function path")},void 0,!1),(0,t.jsxDEV)(u,{children:o("Table")},void 0,!1),(0,t.jsxDEV)(u,{children:o("Arguments")},void 0,!1)]},void 0,!0)},void 0,!1),(0,t.jsxDEV)(L,{children:C.map(x=>{let{subscription:I}=x,E=Z(I?.args);return(0,t.jsxDEV)(k,{"data-testid":"subs-row",children:[(0,t.jsxDEV)(m,{className:"font-medium tabular-nums",children:(0,t.jsxDEV)("span",{className:"inline-flex items-center gap-1.5",children:["#",x.connectionId,x.admin&&(0,t.jsxDEV)(y,{variant:"outline",children:o("admin")},void 0,!1)]},void 0,!0)},void 0,!1),(0,t.jsxDEV)(m,{className:"font-mono text-xs",children:I?.functionPath??w},void 0,!1),(0,t.jsxDEV)(m,{children:I?.table??w},void 0,!1),(0,t.jsxDEV)(m,{className:"max-w-[32ch] truncate font-mono text-xs text-muted-foreground",title:E||void 0,children:E||w},void 0,!1)]},x.key,!0)})},void 0,!1)]},void 0,!0)},void 0,!1)},void 0,!1)]},void 0,!0),e[5]=r,e[6]=c,e[7]=i,e[8]=s,e[9]=o,e[10]=v}else v=e[10];return v},"SubscriptionsPanel");export{de as default};
1
+ import{a as O}from"./chunk-J6J54MBP.js";import{a as j}from"./chunk-2K47A3P6.js";import{a as H}from"./chunk-WUFVFVHJ.js";import"./chunk-XNJNSCLM.js";import{b as K}from"./chunk-W666BB6V.js";import{a as P,b as F,c as L,d as k,e as u,f as m}from"./chunk-GTM65MVX.js";import{a as M,e as $}from"./chunk-SEU5V7I6.js";import{a as _}from"./chunk-LUP4YTBS.js";import"./chunk-4PC7IXNY.js";import"./chunk-2MLA6WFH.js";import"./chunk-VL23Y44O.js";import"./chunk-HV7G6DFP.js";import"./chunk-O3NAGRTR.js";import{b as y}from"./chunk-ZPP2KOR4.js";import"./chunk-CKSHCYGC.js";import{a as R}from"./chunk-G7ZBM54M.js";import"./chunk-SDMZKBTD.js";import"./chunk-ZHVTQ37P.js";import"./chunk-3OA7PECS.js";import{a as B}from"./chunk-TAD43CG5.js";import{d as D}from"./chunk-ITQKVEP7.js";import"./chunk-22C6COGE.js";import{a as S,e as T,f as U,g as V,h as X}from"./chunk-RRCPZMC2.js";var G=T(V(),1),J=T(U(),1);var t=T(X(),1);var W=80,Z=S(a=>{if(a===void 0)return"";let e=JSON.stringify(a);return e.length>W?`${e.slice(0,W)}\u2026`:e},"formatArguments"),q=S(a=>{let e=[];for(let n of a){let o=n.id.toString();if(n.subscriptions.length===0){e.push({admin:n.admin,connectionId:n.id,key:`c${o}`,subscription:null});continue}n.subscriptions.forEach((s,N)=>{e.push({admin:n.admin,connectionId:n.id,key:`c${o}-s${N.toString()}`,subscription:s})})}return e},"toRows"),w=(0,t.jsxDEV)("span",{className:"text-muted-foreground",children:"\u2014"},void 0,!1),de=S(a=>{let e=(0,G.c)(22),{initialShardKey:n}=a,o=D(),[s,N]=(0,J.useState)(n??""),f;e[0]!==s?(f=s.trim(),e[0]=s,e[1]=f):f=e[1];let A=j(f,400),h;e[2]===Symbol.for("react.memo_cache_sentinel")?(h={},e[2]=h):h=e[2];let p;e[3]!==A?(p={keepPreviousData:!0,shardKey:A},e[3]=A,e[4]=p):p=e[4];let{data:i,error:r,errorSource:c,refetch:Q}=K(R.listSubscriptions,h,p);O(Q,!0);let v;if(e[5]!==r||e[6]!==c||e[7]!==i||e[8]!==s||e[9]!==o){let C=i===void 0?[]:q(i.connections),l;e[11]!==s?(l=(0,t.jsxDEV)(_,{onChange:N,testId:"subs-shard-input",value:s},void 0,!1),e[11]=s,e[12]=l):l=e[12];let d;e[13]!==i||e[14]!==o?(d=i!==void 0&&(0,t.jsxDEV)("div",{className:"ml-auto flex items-center gap-2 text-sm text-muted-foreground","data-testid":"subs-count",children:[(0,t.jsxDEV)(y,{variant:"secondary",children:o("{count} connections",{count:i.totalConnections})},void 0,!1),(0,t.jsxDEV)(y,{variant:"secondary",children:o("{count} subscriptions",{count:i.totalSubscriptions})},void 0,!1)]},void 0,!0),e[13]=i,e[14]=o,e[15]=d):d=e[15];let b;e[16]!==l||e[17]!==d?(b=(0,t.jsxDEV)("div",{className:"flex flex-wrap items-center gap-2",children:[l,d]},void 0,!0),e[16]=l,e[17]=d,e[18]=b):b=e[18];let g;e[19]!==r||e[20]!==c?(g=r!==null&&(0,t.jsxDEV)(H,{error:c,testId:"subs-error"},void 0,!1),e[19]=r,e[20]=c,e[21]=g):g=e[21],v=(0,t.jsxDEV)("div",{className:"flex flex-col gap-4","data-testid":"subs-panel",children:[b,g,r===null&&i!==void 0&&C.length===0&&(0,t.jsxDEV)(B,{description:o("Active WebSocket subscriptions on this shard."),icon:(0,t.jsxDEV)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,t.jsxDEV)("path",{d:"M5 12a7 7 0 0 1 14 0M8 12a4 4 0 0 1 8 0M12 12v8m0-8a1 1 0 1 0 0-2 1 1 0 0 0 0 2Z"},void 0,!1)},void 0,!1),testId:"subs-empty",title:o("No active subscriptions.")},void 0,!1),r===null&&C.length>0&&(0,t.jsxDEV)(M,{className:"overflow-hidden py-0",children:(0,t.jsxDEV)($,{className:"px-0",children:(0,t.jsxDEV)(P,{"data-testid":"subs-table",children:[(0,t.jsxDEV)(F,{children:(0,t.jsxDEV)(k,{children:[(0,t.jsxDEV)(u,{children:o("Connection")},void 0,!1),(0,t.jsxDEV)(u,{children:o("Function path")},void 0,!1),(0,t.jsxDEV)(u,{children:o("Table")},void 0,!1),(0,t.jsxDEV)(u,{children:o("Arguments")},void 0,!1)]},void 0,!0)},void 0,!1),(0,t.jsxDEV)(L,{children:C.map(x=>{let{subscription:I}=x,E=Z(I?.args);return(0,t.jsxDEV)(k,{"data-testid":"subs-row",children:[(0,t.jsxDEV)(m,{className:"font-medium tabular-nums",children:(0,t.jsxDEV)("span",{className:"inline-flex items-center gap-1.5",children:["#",x.connectionId,x.admin&&(0,t.jsxDEV)(y,{variant:"outline",children:o("admin")},void 0,!1)]},void 0,!0)},void 0,!1),(0,t.jsxDEV)(m,{className:"font-mono text-xs",children:I?.functionPath??w},void 0,!1),(0,t.jsxDEV)(m,{children:I?.table??w},void 0,!1),(0,t.jsxDEV)(m,{className:"max-w-[32ch] truncate font-mono text-xs text-muted-foreground",title:E||void 0,children:E||w},void 0,!1)]},x.key,!0)})},void 0,!1)]},void 0,!0)},void 0,!1)},void 0,!1)]},void 0,!0),e[5]=r,e[6]=c,e[7]=i,e[8]=s,e[9]=o,e[10]=v}else v=e[10];return v},"SubscriptionsPanel");export{de as default};
@@ -1 +1 @@
1
- import{b as de,e as j}from"./chunk-JPILGFXT.js";import{a as ce}from"./chunk-AITOCPML.js";import"./chunk-X4QFAAZ5.js";import"./chunk-BJGBHGK3.js";import"./chunk-ZIGWVHCS.js";import"./chunk-KEGAWN6Y.js";import{b as ne}from"./chunk-W666BB6V.js";import{a as S}from"./chunk-SEU5V7I6.js";import{a as ie}from"./chunk-4PC7IXNY.js";import"./chunk-2MLA6WFH.js";import"./chunk-HV7G6DFP.js";import{b as A}from"./chunk-ZPP2KOR4.js";import"./chunk-CKSHCYGC.js";import{a as E}from"./chunk-BOXSWNXZ.js";import{f as ae,g as le}from"./chunk-SDMZKBTD.js";import"./chunk-ZHVTQ37P.js";import"./chunk-3OA7PECS.js";import{d as D,f as T,g as H,h as Q,l as F,p as oe}from"./chunk-ITQKVEP7.js";import"./chunk-22C6COGE.js";import{a as h,e as k,f as ke,g as re,h as se,j as w}from"./chunk-RRCPZMC2.js";var ve=k(re(),1);var c=k(ke(),1);var ue=k(re(),1);var W=k(se(),1);var Ae={connected:"bg-success",connecting:"bg-warning",idle:"bg-muted-foreground",offline:"bg-destructive"},fe=h(()=>{let t=(0,ue.c)(16),e=D(),a=le(),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}default:s=a}let l=Ae[a],d;t[8]!==l?(d=w("size-2 rounded-full",l),t[8]=l,t[9]=d):d=t[9];let u;t[10]!==d?(u=(0,W.jsxDEV)("span",{"aria-hidden":"true",className:d},void 0,!1),t[10]=d,t[11]=u):u=t[11];let i;return t[12]!==a||t[13]!==u||t[14]!==s?(i=(0,W.jsxDEV)("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:[u,s]},void 0,!0),t[12]=a,t[13]=u,t[14]=s,t[15]=i):i=t[15],i},"ConnectionBadge");var r=k(se(),1);var me={completed:0,failed:2,in_progress:1},Re=h(t=>{let e=0,a=0,s=0,l=0,d=[];for(let{metrics:u}of t){if(u===null){l+=1;continue}s+=1,e+=u.requests,a+=u.errors,d.push(...u.history??[])}return{errors:a,failed:l,history:d,reachable:s,requests:e}},"sumShardMetrics"),Me=h(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()]},"mergeFunctionStats"),_e=h(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 d=me[s.status]-me[l.status];(d>0||d===0&&(s.updatedAt??0)>(l.updatedAt??0))&&e.set(s.id,s)}return[...e.values()]},"dedupeMigrations"),Ie=T(E.getAuthMetrics),Le=T(E.getFunctionStats),Ce=T(E.getLogs),Oe=T(E.getMetrics),qe=T(E.migrationStatus),De=5,he=2e3,Fe=5,pe=.01,ge=.05,je=.1,Ue=.3,Pe=1,Ge=50,X=h((t,e,a)=>t>=a?"crit":t>=e?"warn":"ok","rateLevel"),Ve=h((t,e,a)=>t>=a?"crit":t>=e?"warn":"ok","countLevel"),Be={crit:"destructive",ok:"secondary",warn:"default"},U=h((t,e)=>e===0?"\u2014":`${(t/e*100).toFixed(1)}%`,"ratePercent"),Ke=h(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)}},"requestErrorSeries"),$e=h(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}},"migrationSummary"),ze=h((t,e)=>t.failed>0?e("{count} failed",{count:t.failed.toString()}):t.running>0?e("{count} running",{count:t.running.toString()}):e("OK"),"migrationTileValue"),xe={crit:"bg-destructive",ok:"bg-success",warn:"bg-warning"},Ne={crit:"text-destructive",ok:"text-foreground",warn:"text-warning"},He={crit:"bg-destructive/10 text-destructive",ok:"bg-success/10 text-success",warn:"bg-warning/10 text-warning"},Qe=h(t=>t.includes("crit")?"crit":t.includes("warn")?"warn":"ok","worstLevel"),P=h(t=>{let e=(0,ve.c)(19),{chart:a,label:s,level:l,testId:d,value:u}=t,i=xe[l],n;e[0]!==i?(n=w("size-1.5 shrink-0 rounded-full",i),e[0]=i,e[1]=n):n=e[1];let p;e[2]!==n?(p=(0,r.jsxDEV)("span",{"aria-hidden":"true",className:n},void 0,!1),e[2]=n,e[3]=p):p=e[3];let g;e[4]!==s||e[5]!==p?(g=(0,r.jsxDEV)("span",{className:"flex items-center gap-1.5 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:[p,s]},void 0,!0),e[4]=s,e[5]=p,e[6]=g):g=e[6];let b=Ne[l],m;e[7]!==b?(m=w("truncate text-2xl font-semibold tabular-nums",b),e[7]=b,e[8]=m):m=e[8];let f;e[9]!==m||e[10]!==d||e[11]!==u?(f=(0,r.jsxDEV)("span",{className:m,"data-testid":d,children:u},void 0,!1),e[9]=m,e[10]=d,e[11]=u,e[12]=f):f=e[12];let v;e[13]!==a||e[14]!==f?(v=(0,r.jsxDEV)("div",{className:"flex items-center justify-between gap-3",children:[f,a]},void 0,!0),e[13]=a,e[14]=f,e[15]=v):v=e[15];let x;return e[16]!==g||e[17]!==v?(x=(0,r.jsxDEV)(S,{className:"gap-0 py-0",children:(0,r.jsxDEV)("div",{className:"flex flex-col gap-2.5 p-4",children:[g,v]},void 0,!0)},void 0,!1),e[16]=g,e[17]=v,e[18]=x):x=e[18],x},"SloCard"),We=h(async(t,e,a)=>{let s=await Promise.all(a.map(m=>{let f=H(m);return Promise.allSettled([t.query(Oe,{},f),t.query(Le,{},f),t.query(qe,{},f)])})),l=H(e),d=typeof t.schedulerStatus=="function"?t.schedulerStatus():Promise.reject(new Error("scheduler status unavailable")),[u,i,n]=await Promise.allSettled([t.query(Ce,{},l),t.query(Ie,{},l),d]),p=s.map(([m,f,v])=>({functions:f.status==="fulfilled"?f.value.functions:[],metrics:m.status==="fulfilled"?m.value:null,migrations:v.status==="fulfilled"?v.value.migrations:[]})),g=Re(p),b=s[0]?.[0];return{auth:i.status==="fulfilled"?i.value:null,entries:u.status==="fulfilled"?u.value.entries:[],functions:Me(p.map(m=>m.functions)),logsError:u.status==="rejected"?Q(u.reason):null,metricsError:g.reachable===0&&b?.status==="rejected"?Q(b.reason):null,migrations:_e(p.map(m=>m.migrations)),scheduler:n.status==="fulfilled"?n.value:null,totals:g}},"loadSloData"),ht=h(({initialShardKey:t})=>{let e=ae(),a=D(),[s,l]=(0,c.useState)([]),[d,u]=(0,c.useState)(null),[i,n]=(0,c.useState)(null),[p,g]=(0,c.useState)(null),[b,m]=(0,c.useState)([]),[f,v]=(0,c.useState)(null),[x,be]=(0,c.useState)(null),[we,Ee]=(0,c.useState)([]),[y]=(0,c.useState)(ie),R=(0,c.useRef)(!1),G=(0,c.useRef)(!0);(0,c.useEffect)(()=>(G.current=!0,()=>{G.current=!1}),[]);let M=t??"",_=(0,c.useCallback)(async()=>{if(R.current)return;R.current=!0;let o=await We(e,M,de(M,y));if(!G.current){R.current=!1;return}n(o.totals),g(o.metricsError),m(o.functions),Ee(o.migrations),l(o.entries),u(o.logsError),v(o.auth),be(o.scheduler),R.current=!1},[e,y,M]);(0,c.useEffect)(()=>{F(_())},[_]);let V=(0,c.useRef)(0),I=(0,c.useRef)(null),Se=h(()=>{let o=Date.now()-V.current;if(o>=he){V.current=Date.now(),F(_());return}I.current??=setTimeout(()=>{I.current=null,V.current=Date.now(),F(_())},he-o)},"scheduleFanOut");(0,c.useEffect)(()=>()=>{I.current!==null&&clearTimeout(I.current)},[]);let{data:J,liveError:Te}=ne(E.getMetrics,{},{live:!0,shardKey:M});(0,c.useEffect)(()=>{J!==void 0&&Se()},[J]);let B=s.filter(o=>o.level==="error"),K=B.slice(0,De),L=Ke(i?.history),Y=(0,c.useMemo)(()=>{let o=f?.history??[];return{attempts:o.map(N=>N.attempts),failures:o.map(N=>N.failures)}},[f?.history]),Z=b.filter(o=>o.calls>0).toSorted((o,N)=>N.errors/N.calls-o.errors/o.calls||N.calls-o.calls).slice(0,Fe),$=$e(we),ye=i===null||i.requests===0?0:i.errors/i.requests,z=X(ye,pe,ge),ee=f===null?"ok":X(f.failureRate,je,Ue),te=x===null?"ok":Ve(x.backlog,Pe,Ge),C=Qe([z,ee,te,$.level]),O,q;return C==="crit"?(O=a("Critical"),q=a("One or more service levels are breached.")):C==="warn"?(O=a("Degraded"),q=a("Some service levels need attention.")):(O=a("All systems healthy"),q=a("All service levels are within target.")),(0,r.jsxDEV)("div",{className:"flex flex-col gap-6","data-testid":"lunora-health",children:[(0,r.jsxDEV)(S,{className:"gap-0 py-0",children:[(0,r.jsxDEV)("div",{className:"flex flex-wrap items-center justify-between gap-4 p-4",children:[(0,r.jsxDEV)("div",{className:"flex items-center gap-3",children:[(0,r.jsxDEV)("span",{"aria-hidden":"true",className:w("flex size-10 shrink-0 items-center justify-center rounded-full",He[C]),children:(0,r.jsxDEV)("span",{className:w("size-3 rounded-full",xe[C])},void 0,!1)},void 0,!1),(0,r.jsxDEV)("div",{className:"grid leading-tight",children:[(0,r.jsxDEV)("span",{className:"text-sm font-semibold text-foreground","data-testid":"hl-status",children:O},void 0,!1),(0,r.jsxDEV)("span",{className:"text-[13px] text-muted-foreground",children:q},void 0,!1)]},void 0,!0)]},void 0,!0),(0,r.jsxDEV)("div",{className:"flex flex-wrap items-center gap-4",children:[(0,r.jsxDEV)("div",{className:"text-end",children:[(0,r.jsxDEV)("div",{className:"font-mono text-[10px] tracking-wide text-muted-foreground uppercase",children:a("Requests")},void 0,!1),(0,r.jsxDEV)("div",{className:"flex items-center justify-end gap-2",children:[L.requests.length>=2&&(0,r.jsxDEV)(j,{ariaLabel:a("Requests over time"),className:"h-6 w-20 text-foreground",series:L.requests,testId:"hl-spark-requests"},void 0,!1),(0,r.jsxDEV)("span",{className:"text-lg font-semibold tabular-nums text-foreground","data-testid":"hl-requests",children:(i?.requests??0).toString()},void 0,!1)]},void 0,!0)]},void 0,!0),(0,r.jsxDEV)("span",{"aria-hidden":"true",className:"h-9 w-px bg-border"},void 0,!1),(0,r.jsxDEV)("div",{className:"text-end",children:[(0,r.jsxDEV)("div",{className:"font-mono text-[10px] tracking-wide text-muted-foreground uppercase",children:a("Error rate")},void 0,!1),(0,r.jsxDEV)("div",{className:w("text-lg font-semibold tabular-nums",Ne[z]),"data-testid":"hl-error-rate",children:i===null?"\u2014":U(i.errors,i.requests)},void 0,!1)]},void 0,!0),(0,r.jsxDEV)("span",{"aria-hidden":"true",className:"h-9 w-px bg-border"},void 0,!1),(0,r.jsxDEV)("div",{className:"flex items-center gap-2",children:[(0,r.jsxDEV)(fe,{},void 0,!1),(0,r.jsxDEV)(ce,{message:Te,prefix:"hl"},void 0,!1)]},void 0,!0)]},void 0,!0)]},void 0,!0),p!==null&&(0,r.jsxDEV)("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:p},void 0,!1)]},void 0,!0),(0,r.jsxDEV)("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4","data-testid":"hl-slo",children:[(0,r.jsxDEV)(P,{chart:L.errors.length>=2?(0,r.jsxDEV)(j,{ariaLabel:a("Errors over time"),className:"h-7 w-20 text-destructive",series:L.errors,testId:"hl-spark-errors"},void 0,!1):void 0,label:a("Error rate"),level:z,testId:"hl-slo-errorrate",value:i===null?"\u2014":U(i.errors,i.requests)},void 0,!1),(0,r.jsxDEV)(P,{chart:Y.failures.length>=2?(0,r.jsxDEV)(j,{ariaLabel:a("Auth failures over time"),className:"h-7 w-20 text-destructive",series:Y.failures,testId:"hl-spark-auth"},void 0,!1):void 0,label:a("Auth failures"),level:ee,testId:"hl-slo-auth",value:f===null?"\u2014":U(f.failures,f.attempts)},void 0,!1),(0,r.jsxDEV)(P,{label:a("Scheduler backlog"),level:te,testId:"hl-slo-backlog",value:x===null?"\u2014":x.backlog.toString()},void 0,!1),(0,r.jsxDEV)(P,{label:a("Migrations"),level:$.level,testId:"hl-slo-migrations",value:ze($,a)},void 0,!1)]},void 0,!0),(0,r.jsxDEV)("div",{className:"grid gap-3 lg:grid-cols-2",children:[(0,r.jsxDEV)(S,{className:"gap-0 py-0","data-testid":"hl-functions",children:[(0,r.jsxDEV)("header",{className:"border-b border-border px-4 py-3",children:(0,r.jsxDEV)("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:a("Functions by error rate")},void 0,!1)},void 0,!1),Z.length===0?(0,r.jsxDEV)("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground","data-testid":"hl-functions-empty",children:a("No function activity yet.")},void 0,!1):(0,r.jsxDEV)("ul",{className:"divide-y divide-border",children:Z.map(o=>(0,r.jsxDEV)("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.jsxDEV)("span",{className:"truncate font-mono text-foreground",children:o.path},void 0,!1),(0,r.jsxDEV)("span",{className:"flex shrink-0 items-center gap-2",children:[(0,r.jsxDEV)("span",{className:"tabular-nums text-muted-foreground",children:a("{count} calls",{count:o.calls.toString()})},void 0,!1),(0,r.jsxDEV)(A,{variant:Be[X(o.errors/o.calls,pe,ge)],children:U(o.errors,o.calls)},void 0,!1)]},void 0,!0)]},o.path,!0))},void 0,!1)]},void 0,!0),(0,r.jsxDEV)(S,{className:"gap-0 py-0",children:[(0,r.jsxDEV)("header",{className:"flex items-center justify-between gap-2 border-b border-border px-4 py-3",children:[(0,r.jsxDEV)("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:a("Recent errors")},void 0,!1),(0,r.jsxDEV)(A,{"data-testid":"hl-error-count",variant:B.length>0?"destructive":"outline",children:B.length},void 0,!1)]},void 0,!0),d!==null&&(0,r.jsxDEV)("p",{className:"px-4 py-8 text-center text-sm text-destructive","data-testid":"hl-logs-error",role:"alert",children:d},void 0,!1),d===null&&K.length===0&&(0,r.jsxDEV)("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground","data-testid":"hl-errors-empty",children:a("No recent errors.")},void 0,!1),K.length>0&&(0,r.jsxDEV)("ul",{className:"divide-y divide-border",children:K.map((o,N)=>(0,r.jsxDEV)("li",{className:"flex flex-col gap-0.5 px-4 py-2 text-xs","data-testid":"hl-error-row",children:[(0,r.jsxDEV)("span",{className:"flex items-center gap-2",children:[(0,r.jsxDEV)("time",{className:"shrink-0 text-muted-foreground",children:oe(o.timestamp)},void 0,!1),o.functionPath!==void 0&&(0,r.jsxDEV)("span",{className:"truncate font-mono text-foreground",children:o.functionPath},void 0,!1)]},void 0,!0),(0,r.jsxDEV)("span",{className:"text-destructive",children:o.message},void 0,!1)]},`${o.timestamp.toString()}-${N.toString()}`,!0))},void 0,!1)]},void 0,!0)]},void 0,!0),(0,r.jsxDEV)(S,{className:"gap-0 py-0",children:[(0,r.jsxDEV)("header",{className:"flex items-center justify-between gap-2 border-b border-border px-4 py-3",children:[(0,r.jsxDEV)("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:a("Shards seen")},void 0,!1),(0,r.jsxDEV)(A,{"data-testid":"hl-shard-count",variant:"outline",children:y.length},void 0,!1)]},void 0,!0),y.length>0&&(0,r.jsxDEV)("ul",{className:"flex flex-wrap gap-1.5 p-4",children:y.map(o=>(0,r.jsxDEV)("li",{"data-testid":"hl-shard",children:(0,r.jsxDEV)(A,{variant:"secondary",children:o},void 0,!1)},o,!1))},void 0,!1)]},void 0,!0)]},void 0,!0)},"HealthPanel");export{ht as HealthPanel};
1
+ import{b as de,e as j}from"./chunk-JPILGFXT.js";import{a as ce}from"./chunk-AITOCPML.js";import"./chunk-X4QFAAZ5.js";import"./chunk-BJGBHGK3.js";import"./chunk-ZIGWVHCS.js";import"./chunk-KEGAWN6Y.js";import{b as ne}from"./chunk-W666BB6V.js";import{a as S}from"./chunk-SEU5V7I6.js";import{a as ie}from"./chunk-4PC7IXNY.js";import"./chunk-2MLA6WFH.js";import"./chunk-HV7G6DFP.js";import{b as A}from"./chunk-ZPP2KOR4.js";import"./chunk-CKSHCYGC.js";import{a as E}from"./chunk-G7ZBM54M.js";import{f as ae,g as le}from"./chunk-SDMZKBTD.js";import"./chunk-ZHVTQ37P.js";import"./chunk-3OA7PECS.js";import{d as D,f as T,g as H,h as Q,l as F,p as oe}from"./chunk-ITQKVEP7.js";import"./chunk-22C6COGE.js";import{a as h,e as k,f as ke,g as re,h as se,j as w}from"./chunk-RRCPZMC2.js";var ve=k(re(),1);var c=k(ke(),1);var ue=k(re(),1);var W=k(se(),1);var Ae={connected:"bg-success",connecting:"bg-warning",idle:"bg-muted-foreground",offline:"bg-destructive"},fe=h(()=>{let t=(0,ue.c)(16),e=D(),a=le(),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}default:s=a}let l=Ae[a],d;t[8]!==l?(d=w("size-2 rounded-full",l),t[8]=l,t[9]=d):d=t[9];let u;t[10]!==d?(u=(0,W.jsxDEV)("span",{"aria-hidden":"true",className:d},void 0,!1),t[10]=d,t[11]=u):u=t[11];let i;return t[12]!==a||t[13]!==u||t[14]!==s?(i=(0,W.jsxDEV)("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:[u,s]},void 0,!0),t[12]=a,t[13]=u,t[14]=s,t[15]=i):i=t[15],i},"ConnectionBadge");var r=k(se(),1);var me={completed:0,failed:2,in_progress:1},Re=h(t=>{let e=0,a=0,s=0,l=0,d=[];for(let{metrics:u}of t){if(u===null){l+=1;continue}s+=1,e+=u.requests,a+=u.errors,d.push(...u.history??[])}return{errors:a,failed:l,history:d,reachable:s,requests:e}},"sumShardMetrics"),Me=h(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()]},"mergeFunctionStats"),_e=h(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 d=me[s.status]-me[l.status];(d>0||d===0&&(s.updatedAt??0)>(l.updatedAt??0))&&e.set(s.id,s)}return[...e.values()]},"dedupeMigrations"),Ie=T(E.getAuthMetrics),Le=T(E.getFunctionStats),Ce=T(E.getLogs),Oe=T(E.getMetrics),qe=T(E.migrationStatus),De=5,he=2e3,Fe=5,pe=.01,ge=.05,je=.1,Ue=.3,Pe=1,Ge=50,X=h((t,e,a)=>t>=a?"crit":t>=e?"warn":"ok","rateLevel"),Ve=h((t,e,a)=>t>=a?"crit":t>=e?"warn":"ok","countLevel"),Be={crit:"destructive",ok:"secondary",warn:"default"},U=h((t,e)=>e===0?"\u2014":`${(t/e*100).toFixed(1)}%`,"ratePercent"),Ke=h(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)}},"requestErrorSeries"),$e=h(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}},"migrationSummary"),ze=h((t,e)=>t.failed>0?e("{count} failed",{count:t.failed.toString()}):t.running>0?e("{count} running",{count:t.running.toString()}):e("OK"),"migrationTileValue"),xe={crit:"bg-destructive",ok:"bg-success",warn:"bg-warning"},Ne={crit:"text-destructive",ok:"text-foreground",warn:"text-warning"},He={crit:"bg-destructive/10 text-destructive",ok:"bg-success/10 text-success",warn:"bg-warning/10 text-warning"},Qe=h(t=>t.includes("crit")?"crit":t.includes("warn")?"warn":"ok","worstLevel"),P=h(t=>{let e=(0,ve.c)(19),{chart:a,label:s,level:l,testId:d,value:u}=t,i=xe[l],n;e[0]!==i?(n=w("size-1.5 shrink-0 rounded-full",i),e[0]=i,e[1]=n):n=e[1];let p;e[2]!==n?(p=(0,r.jsxDEV)("span",{"aria-hidden":"true",className:n},void 0,!1),e[2]=n,e[3]=p):p=e[3];let g;e[4]!==s||e[5]!==p?(g=(0,r.jsxDEV)("span",{className:"flex items-center gap-1.5 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:[p,s]},void 0,!0),e[4]=s,e[5]=p,e[6]=g):g=e[6];let b=Ne[l],m;e[7]!==b?(m=w("truncate text-2xl font-semibold tabular-nums",b),e[7]=b,e[8]=m):m=e[8];let f;e[9]!==m||e[10]!==d||e[11]!==u?(f=(0,r.jsxDEV)("span",{className:m,"data-testid":d,children:u},void 0,!1),e[9]=m,e[10]=d,e[11]=u,e[12]=f):f=e[12];let v;e[13]!==a||e[14]!==f?(v=(0,r.jsxDEV)("div",{className:"flex items-center justify-between gap-3",children:[f,a]},void 0,!0),e[13]=a,e[14]=f,e[15]=v):v=e[15];let x;return e[16]!==g||e[17]!==v?(x=(0,r.jsxDEV)(S,{className:"gap-0 py-0",children:(0,r.jsxDEV)("div",{className:"flex flex-col gap-2.5 p-4",children:[g,v]},void 0,!0)},void 0,!1),e[16]=g,e[17]=v,e[18]=x):x=e[18],x},"SloCard"),We=h(async(t,e,a)=>{let s=await Promise.all(a.map(m=>{let f=H(m);return Promise.allSettled([t.query(Oe,{},f),t.query(Le,{},f),t.query(qe,{},f)])})),l=H(e),d=typeof t.schedulerStatus=="function"?t.schedulerStatus():Promise.reject(new Error("scheduler status unavailable")),[u,i,n]=await Promise.allSettled([t.query(Ce,{},l),t.query(Ie,{},l),d]),p=s.map(([m,f,v])=>({functions:f.status==="fulfilled"?f.value.functions:[],metrics:m.status==="fulfilled"?m.value:null,migrations:v.status==="fulfilled"?v.value.migrations:[]})),g=Re(p),b=s[0]?.[0];return{auth:i.status==="fulfilled"?i.value:null,entries:u.status==="fulfilled"?u.value.entries:[],functions:Me(p.map(m=>m.functions)),logsError:u.status==="rejected"?Q(u.reason):null,metricsError:g.reachable===0&&b?.status==="rejected"?Q(b.reason):null,migrations:_e(p.map(m=>m.migrations)),scheduler:n.status==="fulfilled"?n.value:null,totals:g}},"loadSloData"),ht=h(({initialShardKey:t})=>{let e=ae(),a=D(),[s,l]=(0,c.useState)([]),[d,u]=(0,c.useState)(null),[i,n]=(0,c.useState)(null),[p,g]=(0,c.useState)(null),[b,m]=(0,c.useState)([]),[f,v]=(0,c.useState)(null),[x,be]=(0,c.useState)(null),[we,Ee]=(0,c.useState)([]),[y]=(0,c.useState)(ie),R=(0,c.useRef)(!1),G=(0,c.useRef)(!0);(0,c.useEffect)(()=>(G.current=!0,()=>{G.current=!1}),[]);let M=t??"",_=(0,c.useCallback)(async()=>{if(R.current)return;R.current=!0;let o=await We(e,M,de(M,y));if(!G.current){R.current=!1;return}n(o.totals),g(o.metricsError),m(o.functions),Ee(o.migrations),l(o.entries),u(o.logsError),v(o.auth),be(o.scheduler),R.current=!1},[e,y,M]);(0,c.useEffect)(()=>{F(_())},[_]);let V=(0,c.useRef)(0),I=(0,c.useRef)(null),Se=h(()=>{let o=Date.now()-V.current;if(o>=he){V.current=Date.now(),F(_());return}I.current??=setTimeout(()=>{I.current=null,V.current=Date.now(),F(_())},he-o)},"scheduleFanOut");(0,c.useEffect)(()=>()=>{I.current!==null&&clearTimeout(I.current)},[]);let{data:J,liveError:Te}=ne(E.getMetrics,{},{live:!0,shardKey:M});(0,c.useEffect)(()=>{J!==void 0&&Se()},[J]);let B=s.filter(o=>o.level==="error"),K=B.slice(0,De),L=Ke(i?.history),Y=(0,c.useMemo)(()=>{let o=f?.history??[];return{attempts:o.map(N=>N.attempts),failures:o.map(N=>N.failures)}},[f?.history]),Z=b.filter(o=>o.calls>0).toSorted((o,N)=>N.errors/N.calls-o.errors/o.calls||N.calls-o.calls).slice(0,Fe),$=$e(we),ye=i===null||i.requests===0?0:i.errors/i.requests,z=X(ye,pe,ge),ee=f===null?"ok":X(f.failureRate,je,Ue),te=x===null?"ok":Ve(x.backlog,Pe,Ge),C=Qe([z,ee,te,$.level]),O,q;return C==="crit"?(O=a("Critical"),q=a("One or more service levels are breached.")):C==="warn"?(O=a("Degraded"),q=a("Some service levels need attention.")):(O=a("All systems healthy"),q=a("All service levels are within target.")),(0,r.jsxDEV)("div",{className:"flex flex-col gap-6","data-testid":"lunora-health",children:[(0,r.jsxDEV)(S,{className:"gap-0 py-0",children:[(0,r.jsxDEV)("div",{className:"flex flex-wrap items-center justify-between gap-4 p-4",children:[(0,r.jsxDEV)("div",{className:"flex items-center gap-3",children:[(0,r.jsxDEV)("span",{"aria-hidden":"true",className:w("flex size-10 shrink-0 items-center justify-center rounded-full",He[C]),children:(0,r.jsxDEV)("span",{className:w("size-3 rounded-full",xe[C])},void 0,!1)},void 0,!1),(0,r.jsxDEV)("div",{className:"grid leading-tight",children:[(0,r.jsxDEV)("span",{className:"text-sm font-semibold text-foreground","data-testid":"hl-status",children:O},void 0,!1),(0,r.jsxDEV)("span",{className:"text-[13px] text-muted-foreground",children:q},void 0,!1)]},void 0,!0)]},void 0,!0),(0,r.jsxDEV)("div",{className:"flex flex-wrap items-center gap-4",children:[(0,r.jsxDEV)("div",{className:"text-end",children:[(0,r.jsxDEV)("div",{className:"font-mono text-[10px] tracking-wide text-muted-foreground uppercase",children:a("Requests")},void 0,!1),(0,r.jsxDEV)("div",{className:"flex items-center justify-end gap-2",children:[L.requests.length>=2&&(0,r.jsxDEV)(j,{ariaLabel:a("Requests over time"),className:"h-6 w-20 text-foreground",series:L.requests,testId:"hl-spark-requests"},void 0,!1),(0,r.jsxDEV)("span",{className:"text-lg font-semibold tabular-nums text-foreground","data-testid":"hl-requests",children:(i?.requests??0).toString()},void 0,!1)]},void 0,!0)]},void 0,!0),(0,r.jsxDEV)("span",{"aria-hidden":"true",className:"h-9 w-px bg-border"},void 0,!1),(0,r.jsxDEV)("div",{className:"text-end",children:[(0,r.jsxDEV)("div",{className:"font-mono text-[10px] tracking-wide text-muted-foreground uppercase",children:a("Error rate")},void 0,!1),(0,r.jsxDEV)("div",{className:w("text-lg font-semibold tabular-nums",Ne[z]),"data-testid":"hl-error-rate",children:i===null?"\u2014":U(i.errors,i.requests)},void 0,!1)]},void 0,!0),(0,r.jsxDEV)("span",{"aria-hidden":"true",className:"h-9 w-px bg-border"},void 0,!1),(0,r.jsxDEV)("div",{className:"flex items-center gap-2",children:[(0,r.jsxDEV)(fe,{},void 0,!1),(0,r.jsxDEV)(ce,{message:Te,prefix:"hl"},void 0,!1)]},void 0,!0)]},void 0,!0)]},void 0,!0),p!==null&&(0,r.jsxDEV)("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:p},void 0,!1)]},void 0,!0),(0,r.jsxDEV)("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4","data-testid":"hl-slo",children:[(0,r.jsxDEV)(P,{chart:L.errors.length>=2?(0,r.jsxDEV)(j,{ariaLabel:a("Errors over time"),className:"h-7 w-20 text-destructive",series:L.errors,testId:"hl-spark-errors"},void 0,!1):void 0,label:a("Error rate"),level:z,testId:"hl-slo-errorrate",value:i===null?"\u2014":U(i.errors,i.requests)},void 0,!1),(0,r.jsxDEV)(P,{chart:Y.failures.length>=2?(0,r.jsxDEV)(j,{ariaLabel:a("Auth failures over time"),className:"h-7 w-20 text-destructive",series:Y.failures,testId:"hl-spark-auth"},void 0,!1):void 0,label:a("Auth failures"),level:ee,testId:"hl-slo-auth",value:f===null?"\u2014":U(f.failures,f.attempts)},void 0,!1),(0,r.jsxDEV)(P,{label:a("Scheduler backlog"),level:te,testId:"hl-slo-backlog",value:x===null?"\u2014":x.backlog.toString()},void 0,!1),(0,r.jsxDEV)(P,{label:a("Migrations"),level:$.level,testId:"hl-slo-migrations",value:ze($,a)},void 0,!1)]},void 0,!0),(0,r.jsxDEV)("div",{className:"grid gap-3 lg:grid-cols-2",children:[(0,r.jsxDEV)(S,{className:"gap-0 py-0","data-testid":"hl-functions",children:[(0,r.jsxDEV)("header",{className:"border-b border-border px-4 py-3",children:(0,r.jsxDEV)("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:a("Functions by error rate")},void 0,!1)},void 0,!1),Z.length===0?(0,r.jsxDEV)("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground","data-testid":"hl-functions-empty",children:a("No function activity yet.")},void 0,!1):(0,r.jsxDEV)("ul",{className:"divide-y divide-border",children:Z.map(o=>(0,r.jsxDEV)("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.jsxDEV)("span",{className:"truncate font-mono text-foreground",children:o.path},void 0,!1),(0,r.jsxDEV)("span",{className:"flex shrink-0 items-center gap-2",children:[(0,r.jsxDEV)("span",{className:"tabular-nums text-muted-foreground",children:a("{count} calls",{count:o.calls.toString()})},void 0,!1),(0,r.jsxDEV)(A,{variant:Be[X(o.errors/o.calls,pe,ge)],children:U(o.errors,o.calls)},void 0,!1)]},void 0,!0)]},o.path,!0))},void 0,!1)]},void 0,!0),(0,r.jsxDEV)(S,{className:"gap-0 py-0",children:[(0,r.jsxDEV)("header",{className:"flex items-center justify-between gap-2 border-b border-border px-4 py-3",children:[(0,r.jsxDEV)("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:a("Recent errors")},void 0,!1),(0,r.jsxDEV)(A,{"data-testid":"hl-error-count",variant:B.length>0?"destructive":"outline",children:B.length},void 0,!1)]},void 0,!0),d!==null&&(0,r.jsxDEV)("p",{className:"px-4 py-8 text-center text-sm text-destructive","data-testid":"hl-logs-error",role:"alert",children:d},void 0,!1),d===null&&K.length===0&&(0,r.jsxDEV)("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground","data-testid":"hl-errors-empty",children:a("No recent errors.")},void 0,!1),K.length>0&&(0,r.jsxDEV)("ul",{className:"divide-y divide-border",children:K.map((o,N)=>(0,r.jsxDEV)("li",{className:"flex flex-col gap-0.5 px-4 py-2 text-xs","data-testid":"hl-error-row",children:[(0,r.jsxDEV)("span",{className:"flex items-center gap-2",children:[(0,r.jsxDEV)("time",{className:"shrink-0 text-muted-foreground",children:oe(o.timestamp)},void 0,!1),o.functionPath!==void 0&&(0,r.jsxDEV)("span",{className:"truncate font-mono text-foreground",children:o.functionPath},void 0,!1)]},void 0,!0),(0,r.jsxDEV)("span",{className:"text-destructive",children:o.message},void 0,!1)]},`${o.timestamp.toString()}-${N.toString()}`,!0))},void 0,!1)]},void 0,!0)]},void 0,!0),(0,r.jsxDEV)(S,{className:"gap-0 py-0",children:[(0,r.jsxDEV)("header",{className:"flex items-center justify-between gap-2 border-b border-border px-4 py-3",children:[(0,r.jsxDEV)("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:a("Shards seen")},void 0,!1),(0,r.jsxDEV)(A,{"data-testid":"hl-shard-count",variant:"outline",children:y.length},void 0,!1)]},void 0,!0),y.length>0&&(0,r.jsxDEV)("ul",{className:"flex flex-wrap gap-1.5 p-4",children:y.map(o=>(0,r.jsxDEV)("li",{"data-testid":"hl-shard",children:(0,r.jsxDEV)(A,{variant:"secondary",children:o},void 0,!1)},o,!1))},void 0,!1)]},void 0,!0)]},void 0,!0)},"HealthPanel");export{ht as HealthPanel};
@@ -1 +1 @@
1
- import{a as V}from"./chunk-J6J54MBP.js";import{a as L}from"./chunk-2K47A3P6.js";import{a as W}from"./chunk-WUFVFVHJ.js";import"./chunk-XNJNSCLM.js";import{b as _}from"./chunk-W666BB6V.js";import{a as O,b as Q,c as U,d as K,e as R,f as D}from"./chunk-GTM65MVX.js";import{a as E}from"./chunk-SEU5V7I6.js";import{a as j}from"./chunk-LUP4YTBS.js";import"./chunk-4PC7IXNY.js";import"./chunk-2MLA6WFH.js";import"./chunk-VL23Y44O.js";import"./chunk-HV7G6DFP.js";import"./chunk-O3NAGRTR.js";import{b as w}from"./chunk-ZPP2KOR4.js";import"./chunk-CKSHCYGC.js";import{a as H}from"./chunk-BOXSWNXZ.js";import"./chunk-SDMZKBTD.js";import"./chunk-ZHVTQ37P.js";import"./chunk-3OA7PECS.js";import{a as B}from"./chunk-TAD43CG5.js";import{d as A}from"./chunk-ITQKVEP7.js";import"./chunk-22C6COGE.js";import{a as C,e as F,f as J,g as X,h as Y}from"./chunk-RRCPZMC2.js";var P=F(X(),1),G=F(J(),1);var t=F(Y(),1);var q=C(r=>`${r.toString()} ms`,"formatMs"),Z=C(r=>r.totalConnections===0&&r.shapePoke.passes===0&&r.whisper.passes===0,"isFanoutIdle"),$=C(r=>{let e=(0,P.c)(8),{label:o,testId:s,value:i}=r,l;e[0]!==o?(l=(0,t.jsxDEV)("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:o},void 0,!1),e[0]=o,e[1]=l):l=e[1];let d;e[2]!==s||e[3]!==i?(d=(0,t.jsxDEV)("span",{className:"truncate text-2xl font-semibold tabular-nums text-foreground","data-testid":s,children:i},void 0,!1),e[2]=s,e[3]=i,e[4]=d):d=e[4];let v;return e[5]!==l||e[6]!==d?(v=(0,t.jsxDEV)(E,{className:"gap-0 py-0",children:(0,t.jsxDEV)("div",{className:"flex flex-col gap-2.5 p-4",children:[l,d]},void 0,!0)},void 0,!1),e[5]=l,e[6]=d,e[7]=v):v=e[7],v},"StatCard"),z=C(r=>{let e=(0,P.c)(48),{counters:o,includeTiming:s,prefix:i,t:l,title:d}=r,v=`${i}-section`,h;e[0]!==d?(h=(0,t.jsxDEV)("h3",{className:"text-sm font-medium text-foreground",children:d},void 0,!1),e[0]=d,e[1]=h):h=e[1];let k=`${i}-stats`,a;e[2]!==l?(a=l("Passes"),e[2]=l,e[3]=a):a=e[3];let n=`${i}-passes`,g;e[4]!==o.passes||e[5]!==a||e[6]!==n?(g=(0,t.jsxDEV)($,{label:a,testId:n,value:o.passes},void 0,!1),e[4]=o.passes,e[5]=a,e[6]=n,e[7]=g):g=e[7];let N;e[8]!==l?(N=l("Sockets iterated"),e[8]=l,e[9]=N):N=e[9];let I=`${i}-iterated`,c;e[10]!==o.socketsIterated||e[11]!==N||e[12]!==I?(c=(0,t.jsxDEV)($,{label:N,testId:I,value:o.socketsIterated},void 0,!1),e[10]=o.socketsIterated,e[11]=N,e[12]=I,e[13]=c):c=e[13];let f;e[14]!==l?(f=l("Delivered"),e[14]=l,e[15]=f):f=e[15];let y=`${i}-delivered`,u;e[16]!==o.socketsDelivered||e[17]!==f||e[18]!==y?(u=(0,t.jsxDEV)($,{label:f,testId:y,value:o.socketsDelivered},void 0,!1),e[16]=o.socketsDelivered,e[17]=f,e[18]=y,e[19]=u):u=e[19];let m;e[20]!==l?(m=l("Peak width"),e[20]=l,e[21]=m):m=e[21];let b=`${i}-peak`,p;e[22]!==o.peakSocketsIterated||e[23]!==m||e[24]!==b?(p=(0,t.jsxDEV)($,{label:m,testId:b,value:o.peakSocketsIterated},void 0,!1),e[22]=o.peakSocketsIterated,e[23]=m,e[24]=b,e[25]=p):p=e[25];let x;e[26]!==o.totalMs||e[27]!==s||e[28]!==i||e[29]!==l?(x=s&&(0,t.jsxDEV)($,{label:l("Total time"),testId:`${i}-total-ms`,value:q(o.totalMs)},void 0,!1),e[26]=o.totalMs,e[27]=s,e[28]=i,e[29]=l,e[30]=x):x=e[30];let S;e[31]!==o.maxMs||e[32]!==s||e[33]!==i||e[34]!==l?(S=s&&(0,t.jsxDEV)($,{label:l("Max time"),testId:`${i}-max-ms`,value:q(o.maxMs)},void 0,!1),e[31]=o.maxMs,e[32]=s,e[33]=i,e[34]=l,e[35]=S):S=e[35];let T;e[36]!==u||e[37]!==p||e[38]!==x||e[39]!==S||e[40]!==k||e[41]!==g||e[42]!==c?(T=(0,t.jsxDEV)("dl",{className:"grid gap-3 sm:grid-cols-2 lg:grid-cols-3","data-testid":k,children:[g,c,u,p,x,S]},void 0,!0),e[36]=u,e[37]=p,e[38]=x,e[39]=S,e[40]=k,e[41]=g,e[42]=c,e[43]=T):T=e[43];let M;return e[44]!==v||e[45]!==T||e[46]!==h?(M=(0,t.jsxDEV)("section",{className:"flex flex-col gap-2","data-testid":v,children:[h,T]},void 0,!0),e[44]=v,e[45]=T,e[46]=h,e[47]=M):M=e[47],M},"PathCounters"),ue=C(r=>{let e=(0,P.c)(32),{initialShardKey:o}=r,s=A(),[i,l]=(0,G.useState)(o??""),d;e[0]!==i?(d=i.trim(),e[0]=i,e[1]=d):d=e[1];let v=L(d,400),h;e[2]===Symbol.for("react.memo_cache_sentinel")?(h={},e[2]=h):h=e[2];let k;e[3]!==v?(k={keepPreviousData:!0,shardKey:v},e[3]=v,e[4]=k):k=e[4];let{data:a,error:n,errorSource:g,refetch:N}=_(H.getFanoutMetrics,h,k);V(N,!0);let I;e[5]!==a?(I=a!==void 0&&Z(a),e[5]=a,e[6]=I):I=e[6];let c=I,f;e[7]!==i?(f=(0,t.jsxDEV)(j,{onChange:l,testId:"fanout-shard-input",value:i},void 0,!1),e[7]=i,e[8]=f):f=e[8];let y;e[9]!==a||e[10]!==s?(y=a!==void 0&&(0,t.jsxDEV)("div",{className:"ml-auto flex items-center gap-2 text-sm text-muted-foreground","data-testid":"fanout-count",children:[a.promoted&&(0,t.jsxDEV)(w,{"data-testid":"fanout-promoted",variant:a.relayCount>=a.maxRelays?"destructive":"default",children:a.relayCount>=a.maxRelays?s("auto-scaled: {relayCount}/{maxRelays} relays (at ceiling)",{maxRelays:a.maxRelays,relayCount:a.relayCount}):s("auto-scaled: {relayCount}/{maxRelays} relays",{maxRelays:a.maxRelays,relayCount:a.relayCount})},void 0,!1),(0,t.jsxDEV)(w,{variant:"secondary",children:s("{count} connections",{count:a.totalConnections})},void 0,!1),(0,t.jsxDEV)(w,{variant:"secondary",children:s("peak {count} subscribers",{count:a.peakSubscribers})},void 0,!1)]},void 0,!0),e[9]=a,e[10]=s,e[11]=y):y=e[11];let u;e[12]!==f||e[13]!==y?(u=(0,t.jsxDEV)("div",{className:"flex flex-wrap items-center gap-2",children:[f,y]},void 0,!0),e[12]=f,e[13]=y,e[14]=u):u=e[14];let m;e[15]!==n||e[16]!==g?(m=n!==null&&(0,t.jsxDEV)(W,{error:g,testId:"fanout-error"},void 0,!1),e[15]=n,e[16]=g,e[17]=m):m=e[17];let b;e[18]!==n||e[19]!==c||e[20]!==s?(b=n===null&&c&&(0,t.jsxDEV)(B,{description:s("Realtime fan-out cost and per-topic subscriber counts for this shard."),icon:(0,t.jsxDEV)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,t.jsxDEV)("path",{d:"M4 12h4l3 7 4-14 3 7h2"},void 0,!1)},void 0,!1),testId:"fanout-empty",title:s("No fan-out activity yet.")},void 0,!1),e[18]=n,e[19]=c,e[20]=s,e[21]=b):b=e[21];let p;e[22]!==n||e[23]!==c||e[24]!==a||e[25]!==s?(p=n===null&&a!==void 0&&!c&&(0,t.jsxDEV)(t.Fragment,{children:[a.topics.length>0&&(0,t.jsxDEV)("section",{className:"flex flex-col gap-2","data-testid":"fanout-topics-section",children:[(0,t.jsxDEV)("h3",{className:"text-sm font-medium text-foreground",children:s("Hot topics")},void 0,!1),(0,t.jsxDEV)(E,{className:"overflow-hidden py-0",children:(0,t.jsxDEV)(O,{"data-testid":"fanout-topics-table",children:[(0,t.jsxDEV)(Q,{children:(0,t.jsxDEV)(K,{children:[(0,t.jsxDEV)(R,{children:s("Topic")},void 0,!1),(0,t.jsxDEV)(R,{children:s("Kind")},void 0,!1),(0,t.jsxDEV)(R,{className:"text-right",children:s("Subscribers")},void 0,!1)]},void 0,!0)},void 0,!1),(0,t.jsxDEV)(U,{children:a.topics.map(ee)},void 0,!1)]},void 0,!0)},void 0,!1)]},void 0,!0),(0,t.jsxDEV)("section",{className:"flex flex-col gap-3","data-testid":"fanout-cost",children:[(0,t.jsxDEV)("h2",{className:"text-sm font-medium text-muted-foreground",children:s("Fan-out cost since this instance woke")},void 0,!1),(0,t.jsxDEV)(z,{counters:a.shapePoke,includeTiming:!0,prefix:"fanout-poke",t:s,title:s("Shape pokes")},void 0,!1),(0,t.jsxDEV)(z,{counters:a.whisper,includeTiming:!1,prefix:"fanout-whisper",t:s,title:s("Whisper broadcasts")},void 0,!1)]},void 0,!0)]},void 0,!0),e[22]=n,e[23]=c,e[24]=a,e[25]=s,e[26]=p):p=e[26];let x;return e[27]!==p||e[28]!==u||e[29]!==m||e[30]!==b?(x=(0,t.jsxDEV)("div",{className:"flex flex-col gap-4","data-testid":"fanout-panel",children:[u,m,b,p]},void 0,!0),e[27]=p,e[28]=u,e[29]=m,e[30]=b,e[31]=x):x=e[31],x},"FanoutPanel");function ee(r){return(0,t.jsxDEV)(K,{"data-testid":"fanout-topic-row",children:[(0,t.jsxDEV)(D,{className:"font-mono text-xs",children:r.topic},void 0,!1),(0,t.jsxDEV)(D,{children:(0,t.jsxDEV)(w,{variant:"outline",children:r.kind},void 0,!1)},void 0,!1),(0,t.jsxDEV)(D,{className:"text-right font-medium tabular-nums",children:r.subscribers},void 0,!1)]},`${r.kind}:${r.topic}`,!0)}C(ee,"_temp");export{ue as default};
1
+ import{a as V}from"./chunk-J6J54MBP.js";import{a as L}from"./chunk-2K47A3P6.js";import{a as W}from"./chunk-WUFVFVHJ.js";import"./chunk-XNJNSCLM.js";import{b as _}from"./chunk-W666BB6V.js";import{a as O,b as Q,c as U,d as K,e as R,f as D}from"./chunk-GTM65MVX.js";import{a as E}from"./chunk-SEU5V7I6.js";import{a as j}from"./chunk-LUP4YTBS.js";import"./chunk-4PC7IXNY.js";import"./chunk-2MLA6WFH.js";import"./chunk-VL23Y44O.js";import"./chunk-HV7G6DFP.js";import"./chunk-O3NAGRTR.js";import{b as w}from"./chunk-ZPP2KOR4.js";import"./chunk-CKSHCYGC.js";import{a as H}from"./chunk-G7ZBM54M.js";import"./chunk-SDMZKBTD.js";import"./chunk-ZHVTQ37P.js";import"./chunk-3OA7PECS.js";import{a as B}from"./chunk-TAD43CG5.js";import{d as A}from"./chunk-ITQKVEP7.js";import"./chunk-22C6COGE.js";import{a as C,e as F,f as J,g as X,h as Y}from"./chunk-RRCPZMC2.js";var P=F(X(),1),G=F(J(),1);var t=F(Y(),1);var q=C(r=>`${r.toString()} ms`,"formatMs"),Z=C(r=>r.totalConnections===0&&r.shapePoke.passes===0&&r.whisper.passes===0,"isFanoutIdle"),$=C(r=>{let e=(0,P.c)(8),{label:o,testId:s,value:i}=r,l;e[0]!==o?(l=(0,t.jsxDEV)("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:o},void 0,!1),e[0]=o,e[1]=l):l=e[1];let d;e[2]!==s||e[3]!==i?(d=(0,t.jsxDEV)("span",{className:"truncate text-2xl font-semibold tabular-nums text-foreground","data-testid":s,children:i},void 0,!1),e[2]=s,e[3]=i,e[4]=d):d=e[4];let v;return e[5]!==l||e[6]!==d?(v=(0,t.jsxDEV)(E,{className:"gap-0 py-0",children:(0,t.jsxDEV)("div",{className:"flex flex-col gap-2.5 p-4",children:[l,d]},void 0,!0)},void 0,!1),e[5]=l,e[6]=d,e[7]=v):v=e[7],v},"StatCard"),z=C(r=>{let e=(0,P.c)(48),{counters:o,includeTiming:s,prefix:i,t:l,title:d}=r,v=`${i}-section`,h;e[0]!==d?(h=(0,t.jsxDEV)("h3",{className:"text-sm font-medium text-foreground",children:d},void 0,!1),e[0]=d,e[1]=h):h=e[1];let k=`${i}-stats`,a;e[2]!==l?(a=l("Passes"),e[2]=l,e[3]=a):a=e[3];let n=`${i}-passes`,g;e[4]!==o.passes||e[5]!==a||e[6]!==n?(g=(0,t.jsxDEV)($,{label:a,testId:n,value:o.passes},void 0,!1),e[4]=o.passes,e[5]=a,e[6]=n,e[7]=g):g=e[7];let N;e[8]!==l?(N=l("Sockets iterated"),e[8]=l,e[9]=N):N=e[9];let I=`${i}-iterated`,c;e[10]!==o.socketsIterated||e[11]!==N||e[12]!==I?(c=(0,t.jsxDEV)($,{label:N,testId:I,value:o.socketsIterated},void 0,!1),e[10]=o.socketsIterated,e[11]=N,e[12]=I,e[13]=c):c=e[13];let f;e[14]!==l?(f=l("Delivered"),e[14]=l,e[15]=f):f=e[15];let y=`${i}-delivered`,u;e[16]!==o.socketsDelivered||e[17]!==f||e[18]!==y?(u=(0,t.jsxDEV)($,{label:f,testId:y,value:o.socketsDelivered},void 0,!1),e[16]=o.socketsDelivered,e[17]=f,e[18]=y,e[19]=u):u=e[19];let m;e[20]!==l?(m=l("Peak width"),e[20]=l,e[21]=m):m=e[21];let b=`${i}-peak`,p;e[22]!==o.peakSocketsIterated||e[23]!==m||e[24]!==b?(p=(0,t.jsxDEV)($,{label:m,testId:b,value:o.peakSocketsIterated},void 0,!1),e[22]=o.peakSocketsIterated,e[23]=m,e[24]=b,e[25]=p):p=e[25];let x;e[26]!==o.totalMs||e[27]!==s||e[28]!==i||e[29]!==l?(x=s&&(0,t.jsxDEV)($,{label:l("Total time"),testId:`${i}-total-ms`,value:q(o.totalMs)},void 0,!1),e[26]=o.totalMs,e[27]=s,e[28]=i,e[29]=l,e[30]=x):x=e[30];let S;e[31]!==o.maxMs||e[32]!==s||e[33]!==i||e[34]!==l?(S=s&&(0,t.jsxDEV)($,{label:l("Max time"),testId:`${i}-max-ms`,value:q(o.maxMs)},void 0,!1),e[31]=o.maxMs,e[32]=s,e[33]=i,e[34]=l,e[35]=S):S=e[35];let T;e[36]!==u||e[37]!==p||e[38]!==x||e[39]!==S||e[40]!==k||e[41]!==g||e[42]!==c?(T=(0,t.jsxDEV)("dl",{className:"grid gap-3 sm:grid-cols-2 lg:grid-cols-3","data-testid":k,children:[g,c,u,p,x,S]},void 0,!0),e[36]=u,e[37]=p,e[38]=x,e[39]=S,e[40]=k,e[41]=g,e[42]=c,e[43]=T):T=e[43];let M;return e[44]!==v||e[45]!==T||e[46]!==h?(M=(0,t.jsxDEV)("section",{className:"flex flex-col gap-2","data-testid":v,children:[h,T]},void 0,!0),e[44]=v,e[45]=T,e[46]=h,e[47]=M):M=e[47],M},"PathCounters"),ue=C(r=>{let e=(0,P.c)(32),{initialShardKey:o}=r,s=A(),[i,l]=(0,G.useState)(o??""),d;e[0]!==i?(d=i.trim(),e[0]=i,e[1]=d):d=e[1];let v=L(d,400),h;e[2]===Symbol.for("react.memo_cache_sentinel")?(h={},e[2]=h):h=e[2];let k;e[3]!==v?(k={keepPreviousData:!0,shardKey:v},e[3]=v,e[4]=k):k=e[4];let{data:a,error:n,errorSource:g,refetch:N}=_(H.getFanoutMetrics,h,k);V(N,!0);let I;e[5]!==a?(I=a!==void 0&&Z(a),e[5]=a,e[6]=I):I=e[6];let c=I,f;e[7]!==i?(f=(0,t.jsxDEV)(j,{onChange:l,testId:"fanout-shard-input",value:i},void 0,!1),e[7]=i,e[8]=f):f=e[8];let y;e[9]!==a||e[10]!==s?(y=a!==void 0&&(0,t.jsxDEV)("div",{className:"ml-auto flex items-center gap-2 text-sm text-muted-foreground","data-testid":"fanout-count",children:[a.promoted&&(0,t.jsxDEV)(w,{"data-testid":"fanout-promoted",variant:a.relayCount>=a.maxRelays?"destructive":"default",children:a.relayCount>=a.maxRelays?s("auto-scaled: {relayCount}/{maxRelays} relays (at ceiling)",{maxRelays:a.maxRelays,relayCount:a.relayCount}):s("auto-scaled: {relayCount}/{maxRelays} relays",{maxRelays:a.maxRelays,relayCount:a.relayCount})},void 0,!1),(0,t.jsxDEV)(w,{variant:"secondary",children:s("{count} connections",{count:a.totalConnections})},void 0,!1),(0,t.jsxDEV)(w,{variant:"secondary",children:s("peak {count} subscribers",{count:a.peakSubscribers})},void 0,!1)]},void 0,!0),e[9]=a,e[10]=s,e[11]=y):y=e[11];let u;e[12]!==f||e[13]!==y?(u=(0,t.jsxDEV)("div",{className:"flex flex-wrap items-center gap-2",children:[f,y]},void 0,!0),e[12]=f,e[13]=y,e[14]=u):u=e[14];let m;e[15]!==n||e[16]!==g?(m=n!==null&&(0,t.jsxDEV)(W,{error:g,testId:"fanout-error"},void 0,!1),e[15]=n,e[16]=g,e[17]=m):m=e[17];let b;e[18]!==n||e[19]!==c||e[20]!==s?(b=n===null&&c&&(0,t.jsxDEV)(B,{description:s("Realtime fan-out cost and per-topic subscriber counts for this shard."),icon:(0,t.jsxDEV)("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,t.jsxDEV)("path",{d:"M4 12h4l3 7 4-14 3 7h2"},void 0,!1)},void 0,!1),testId:"fanout-empty",title:s("No fan-out activity yet.")},void 0,!1),e[18]=n,e[19]=c,e[20]=s,e[21]=b):b=e[21];let p;e[22]!==n||e[23]!==c||e[24]!==a||e[25]!==s?(p=n===null&&a!==void 0&&!c&&(0,t.jsxDEV)(t.Fragment,{children:[a.topics.length>0&&(0,t.jsxDEV)("section",{className:"flex flex-col gap-2","data-testid":"fanout-topics-section",children:[(0,t.jsxDEV)("h3",{className:"text-sm font-medium text-foreground",children:s("Hot topics")},void 0,!1),(0,t.jsxDEV)(E,{className:"overflow-hidden py-0",children:(0,t.jsxDEV)(O,{"data-testid":"fanout-topics-table",children:[(0,t.jsxDEV)(Q,{children:(0,t.jsxDEV)(K,{children:[(0,t.jsxDEV)(R,{children:s("Topic")},void 0,!1),(0,t.jsxDEV)(R,{children:s("Kind")},void 0,!1),(0,t.jsxDEV)(R,{className:"text-right",children:s("Subscribers")},void 0,!1)]},void 0,!0)},void 0,!1),(0,t.jsxDEV)(U,{children:a.topics.map(ee)},void 0,!1)]},void 0,!0)},void 0,!1)]},void 0,!0),(0,t.jsxDEV)("section",{className:"flex flex-col gap-3","data-testid":"fanout-cost",children:[(0,t.jsxDEV)("h2",{className:"text-sm font-medium text-muted-foreground",children:s("Fan-out cost since this instance woke")},void 0,!1),(0,t.jsxDEV)(z,{counters:a.shapePoke,includeTiming:!0,prefix:"fanout-poke",t:s,title:s("Shape pokes")},void 0,!1),(0,t.jsxDEV)(z,{counters:a.whisper,includeTiming:!1,prefix:"fanout-whisper",t:s,title:s("Whisper broadcasts")},void 0,!1)]},void 0,!0)]},void 0,!0),e[22]=n,e[23]=c,e[24]=a,e[25]=s,e[26]=p):p=e[26];let x;return e[27]!==p||e[28]!==u||e[29]!==m||e[30]!==b?(x=(0,t.jsxDEV)("div",{className:"flex flex-col gap-4","data-testid":"fanout-panel",children:[u,m,b,p]},void 0,!0),e[27]=p,e[28]=u,e[29]=m,e[30]=b,e[31]=x):x=e[31],x},"FanoutPanel");function ee(r){return(0,t.jsxDEV)(K,{"data-testid":"fanout-topic-row",children:[(0,t.jsxDEV)(D,{className:"font-mono text-xs",children:r.topic},void 0,!1),(0,t.jsxDEV)(D,{children:(0,t.jsxDEV)(w,{variant:"outline",children:r.kind},void 0,!1)},void 0,!1),(0,t.jsxDEV)(D,{className:"text-right font-medium tabular-nums",children:r.subscribers},void 0,!1)]},`${r.kind}:${r.topic}`,!0)}C(ee,"_temp");export{ue as default};