@lunora/studio 1.0.0-alpha.80 → 1.0.0-alpha.82

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 (134) hide show
  1. package/dist/index.d.ts +35 -6
  2. package/dist/index.js +1 -1
  3. package/dist/mount.js +1 -1
  4. package/dist/packem_chunks/AdvisorHealthPanel.js +1 -0
  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 +2 -2
  15. package/dist/packem_chunks/MetricsPanel.js +1 -1
  16. package/dist/packem_chunks/NotificationsPanel.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 +6 -6
  22. package/dist/packem_chunks/TableEditor.js +1 -1
  23. package/dist/packem_chunks/agents-panel.js +1 -1
  24. package/dist/packem_chunks/auth-audit-panel.js +1 -1
  25. package/dist/packem_chunks/containers-panel.js +1 -1
  26. package/dist/packem_chunks/dashboards-panel.js +1 -1
  27. package/dist/packem_chunks/fanout-panel.js +1 -1
  28. package/dist/packem_chunks/flags-panel.js +1 -1
  29. package/dist/packem_chunks/issues-panel.js +1 -1
  30. package/dist/packem_chunks/kv-browser.js +1 -1
  31. package/dist/packem_chunks/log-drains-panel.js +1 -1
  32. package/dist/packem_chunks/migrations-route.js +1 -1
  33. package/dist/packem_chunks/organizations-panel.js +1 -1
  34. package/dist/packem_chunks/payments-panel.js +1 -1
  35. package/dist/packem_chunks/permissions-panel.js +1 -1
  36. package/dist/packem_chunks/queues-panel.js +1 -1
  37. package/dist/packem_chunks/rls-panel.js +1 -1
  38. package/dist/packem_chunks/storage-rules-panel.js +1 -1
  39. package/dist/packem_chunks/subscriptions-panel.js +1 -1
  40. package/dist/packem_chunks/traces-panel.js +1 -1
  41. package/dist/packem_chunks/workflows-panel.js +1 -1
  42. package/dist/packem_shared/ADMIN_FUNCTIONS-CZESgd10.js +1 -0
  43. package/dist/packem_shared/{ApiDocsPanel-DfUQ1ZAF.js → ApiDocsPanel-fYS9NiLg.js} +1 -1
  44. package/dist/packem_shared/DataBrowser-C4J4gVUu.js +1 -0
  45. package/dist/packem_shared/GlobalDataBrowser-CSttudUx.js +1 -0
  46. package/dist/packem_shared/{HomePanel-Dcs4a3Ax.js → HomePanel-BYsfMhKh.js} +1 -1
  47. package/dist/packem_shared/{MigrationsPanel-C2OnsqRb.js → MigrationsPanel-2JbQ2HwG.js} +1 -1
  48. package/dist/packem_shared/{Studio-B26_pT8J.js → Studio-Ba9x0dG_.js} +1 -1
  49. package/dist/packem_shared/{StudioApp-bXhJeLlZ.js → StudioApp-B_PRdg4h.js} +1 -1
  50. package/dist/packem_shared/{cf-links-gbDy51nR.js → cf-links-Dmg86v1D.js} +1 -1
  51. package/dist/packem_shared/{home-panel-CU6MWLHG.js → home-panel-B60-5YfI.js} +1 -1
  52. package/dist/packem_shared/stat-card-fm_TF1mo.js +1 -0
  53. package/dist/packem_shared/studio-CPuoAmjh.js +2 -0
  54. package/dist/packem_shared/table-list-sidebar-BRv3hTLX.js +1 -0
  55. package/dist/packem_shared/{use-sql-assistant-CHEu2-Rk.js → use-sql-assistant-BLG9unQN.js} +1 -1
  56. package/dist/standalone/{chunk-RQ7AFLIV.js → chunk-2QSHLBCO.js} +1 -1
  57. package/dist/standalone/{chunk-33CL6OHR.js → chunk-5SQRE3VR.js} +1 -1
  58. package/dist/standalone/{chunk-5CVJS7ON.js → chunk-6QP5N57V.js} +1 -1
  59. package/dist/standalone/chunk-73GRNONE.js +1 -0
  60. package/dist/standalone/{chunk-JRMMYIAF.js → chunk-74DN6HIE.js} +1 -1
  61. package/dist/standalone/{chunk-KZ3ALMMP.js → chunk-7H7LZRLP.js} +1 -1
  62. package/dist/standalone/{chunk-FOBRNWBG.js → chunk-7YKWP4QK.js} +1 -1
  63. package/dist/standalone/{chunk-T7IUZIF4.js → chunk-7ZUQE3KU.js} +1 -1
  64. package/dist/standalone/{chunk-P4YLIBCN.js → chunk-A3KUNMU6.js} +1 -1
  65. package/dist/standalone/{chunk-S2VVR7HI.js → chunk-B2H5DK55.js} +1 -1
  66. package/dist/standalone/{chunk-FNPJ7GJZ.js → chunk-BDJCCVB6.js} +1 -1
  67. package/dist/standalone/{chunk-KJB7YAKB.js → chunk-C7EOC2WS.js} +1 -1
  68. package/dist/standalone/{chunk-KLQYC6CC.js → chunk-CGLS2ILT.js} +1 -1
  69. package/dist/standalone/chunk-CPSGJSHY.js +1 -0
  70. package/dist/standalone/{chunk-RJP3WBZ4.js → chunk-CU6SCYQ7.js} +1 -1
  71. package/dist/standalone/chunk-DGBJE7YF.js +4 -0
  72. package/dist/standalone/{chunk-G6PSMGLD.js → chunk-DOZAODYC.js} +1 -1
  73. package/dist/standalone/chunk-EQZTSISX.js +1 -0
  74. package/dist/standalone/chunk-ERMTJYQF.js +1 -0
  75. package/dist/standalone/{chunk-QZGTH6WH.js → chunk-GB6LP6UJ.js} +1 -1
  76. package/dist/standalone/{chunk-GYKVBKT5.js → chunk-GM67EQJU.js} +1 -1
  77. package/dist/standalone/chunk-GN567L2T.js +1 -0
  78. package/dist/standalone/{chunk-L7R74G63.js → chunk-GWHM4C4N.js} +1 -1
  79. package/dist/standalone/{chunk-JLOWAJRR.js → chunk-GWQIPIYA.js} +1 -1
  80. package/dist/standalone/{chunk-6YTSSIEJ.js → chunk-HEB6GQQ6.js} +1 -1
  81. package/dist/standalone/chunk-HOR3JLUY.js +6 -0
  82. package/dist/standalone/{chunk-7LWMHTJ3.js → chunk-I6A5C46N.js} +1 -1
  83. package/dist/standalone/{chunk-H6YOWRFB.js → chunk-KAPSM6AI.js} +1 -1
  84. package/dist/standalone/{chunk-6NY7SPDL.js → chunk-KSRP7GZV.js} +1 -1
  85. package/dist/standalone/chunk-LLF5KWDZ.js +2 -0
  86. package/dist/standalone/chunk-NRCXRCJX.js +1 -0
  87. package/dist/standalone/chunk-OE465DVY.js +1 -0
  88. package/dist/standalone/{chunk-HJ3E4YF5.js → chunk-PXYWCZ7T.js} +1 -1
  89. package/dist/standalone/{chunk-PZVU2QMX.js → chunk-Q7QTRX2E.js} +1 -1
  90. package/dist/standalone/{chunk-E3NMX2VU.js → chunk-S4ILMYP5.js} +1 -1
  91. package/dist/standalone/{chunk-KC44QCN6.js → chunk-SDQBPFLO.js} +1 -1
  92. package/dist/standalone/chunk-SV52HB7D.js +1 -0
  93. package/dist/standalone/{chunk-WBYSSCV2.js → chunk-T242WITF.js} +1 -1
  94. package/dist/standalone/{chunk-VHWOCPRK.js → chunk-TBRZQICB.js} +1 -1
  95. package/dist/standalone/{chunk-6LNCYDZO.js → chunk-TQXZ7LG4.js} +1 -1
  96. package/dist/standalone/chunk-U457LHCO.js +1 -0
  97. package/dist/standalone/chunk-UBPYN4DU.js +1 -0
  98. package/dist/standalone/{chunk-34D36UCW.js → chunk-UDVB4URN.js} +1 -1
  99. package/dist/standalone/{chunk-6IKEW5LG.js → chunk-UETNCBWU.js} +1 -1
  100. package/dist/standalone/{chunk-OY2RVUZL.js → chunk-UU2QJMGJ.js} +1 -1
  101. package/dist/standalone/chunk-VC5SSRUP.js +1 -0
  102. package/dist/standalone/{chunk-GXSZH7VJ.js → chunk-VCXH5V3Z.js} +1 -1
  103. package/dist/standalone/{chunk-RNRJKBY3.js → chunk-VTLYN3CX.js} +1 -1
  104. package/dist/standalone/{chunk-3O3HAXW7.js → chunk-WDG4WFUV.js} +1 -1
  105. package/dist/standalone/{chunk-3STOIE7Q.js → chunk-WJGOI3FZ.js} +1 -1
  106. package/dist/standalone/{chunk-W6SAOXGH.js → chunk-WLZ7YPBH.js} +1 -1
  107. package/dist/standalone/{chunk-2VDFV5TD.js → chunk-WQVVA5NB.js} +1 -1
  108. package/dist/standalone/{chunk-TTGOOYLF.js → chunk-WZ3B3MEV.js} +1 -1
  109. package/dist/standalone/{chunk-SKW6J4VW.js → chunk-Y7A5NCXT.js} +1 -1
  110. package/dist/standalone/{chunk-IHQC7J35.js → chunk-YSRW5RNU.js} +1 -1
  111. package/dist/standalone/{chunk-GAX5IZYG.js → chunk-YTA2HGRD.js} +1 -1
  112. package/dist/standalone/chunk-ZHBIKP5G.js +1 -0
  113. package/dist/standalone/{chunk-CCVXYYPJ.js → chunk-ZK3XKFCI.js} +1 -1
  114. package/dist/standalone/studio.js +1 -1
  115. package/dist/styles.css +1 -1
  116. package/package.json +5 -5
  117. package/dist/packem_shared/ADMIN_FUNCTIONS-BnD4aovm.js +0 -1
  118. package/dist/packem_shared/DataBrowser-CuRlztBz.js +0 -1
  119. package/dist/packem_shared/GlobalDataBrowser-DB-vQ2_H.js +0 -1
  120. package/dist/packem_shared/studio-q-C-acL7.js +0 -2
  121. package/dist/packem_shared/table-list-sidebar-BFkSQwlB.js +0 -1
  122. package/dist/standalone/chunk-2GA4SHO7.js +0 -1
  123. package/dist/standalone/chunk-2WOIRKEI.js +0 -1
  124. package/dist/standalone/chunk-6PNPIW6I.js +0 -2
  125. package/dist/standalone/chunk-6YI4WJO4.js +0 -1
  126. package/dist/standalone/chunk-A74VSSA2.js +0 -4
  127. package/dist/standalone/chunk-CT5MMH4O.js +0 -1
  128. package/dist/standalone/chunk-GB6U2BPU.js +0 -1
  129. package/dist/standalone/chunk-GEDMLM4A.js +0 -6
  130. package/dist/standalone/chunk-S252DAFP.js +0 -1
  131. package/dist/standalone/chunk-XS5LDR52.js +0 -1
  132. package/dist/standalone/chunk-YJYTMQJI.js +0 -1
  133. package/dist/standalone/chunk-Z2V42P7J.js +0 -1
  134. /package/dist/standalone/{chunk-SKHEGARW.js → chunk-XF2B7P5A.js} +0 -0
@@ -1 +1 @@
1
- import{c as Xe}from"react/compiler-runtime";import{useLunora as It}from"@lunora/react";import{useState as g,useEffect as it,useRef as $t}from"react";import{ShardInput as zt}from"../packem_shared/ShardInput-BVn2iCU0.js";import{g as gt,d as dt}from"../packem_shared/storage-tier-DznqOf-q.js";import{g as nt}from"../packem_shared/badge-BbuuAio7.js";import{f as ct,m as mt,n as ut,u as ht,c as pt}from"../packem_shared/card-CIDGUN6K.js";import{E as At}from"../packem_shared/empty-state-Cg7t_8qu.js";import{u as We}from"../packem_shared/input-JHu63lTv.js";import Ot from"../packem_shared/useDebounced-Ihdiid_k.js";import{useT as wt}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as st}from"../packem_shared/ADMIN_FUNCTIONS-BnD4aovm.js";import{f as Z,d as lt,b as at,g as rt}from"../packem_shared/internal-BSIsQVC6.js";import{r as jt}from"../packem_shared/shard-history-DMEW5VBE.js";import{c as kt}from"../packem_shared/utils-bhneXptQ.js";import{S as Ft}from"../packem_shared/schema-diagram-cg-bz_VL.js";import{useNavigate as qt}from"@tanstack/react-router";import{u as X}from"../packem_shared/button-BkCrNcAs.js";import{p as ze}from"../packem_shared/label-6uP1obNF.js";import{jsx as l,jsxs as c}from"react/jsx-runtime";const Et="/__lunora/schema-edit",Pt=async s=>{const e=await fetch(Et,{body:JSON.stringify(s),headers:{"Content-Type":"application/json","X-Lunora-Studio":"1"},method:"POST"}),u=await e.json();return u.needsMigration===!0?{kind:"needs-migration",message:u.message??"This edit needs a migration."}:e.ok&&u.tables!==void 0?{diagnostics:u.diagnostics??[],kind:"ok",tables:u.tables}:{kind:"error",message:u.error??`schema edit failed (${String(e.status)})`}},Lt=[{label:"string",validator:"v.string()"},{label:"number",validator:"v.number()"},{label:"boolean",validator:"v.boolean()"},{label:"bigint",validator:"v.int64()"},{label:"bytes",validator:"v.bytes()"},{label:"any",validator:"v.any()"}],Gt="v.string()",Dt=s=>s.split(",").map(e=>e.trim()).filter(e=>e!==""),Mt=s=>{const e=Xe(116),{onApplied:u,tableNames:o}=s,t=wt(),r=qt(),[n,m]=g(null),[p,i]=g(!1),[y,f]=g(null),[w,d]=g(""),[C,G]=g(""),[Q,Le]=g(Gt),[N,Ye]=g(o[0]??""),[q,Ge]=g(""),[W,ce]=g(""),[Y,Ae]=g(!1);let ee;e[0]===Symbol.for("react.memo_cache_sentinel")?(ee=()=>{m(null),d(""),G(""),Ge(""),ce(""),Ae(!1)},e[0]=ee):ee=e[0];const Oe=ee;let me;e[1]!==u?(me=async v=>{i(!0),f(null);try{const P=await Pt(v);f(P),P.kind==="ok"&&(u(P.tables),Oe())}catch(P){const ie=P;f({kind:"error",message:ie instanceof Error?ie.message:String(ie)})}i(!1)},e[1]=u,e[2]=me):me=e[2];const S=me;let je;e[3]!==S||e[4]!==w?(je=()=>{Z(S({kind:"addTable",table:w.trim()}))},e[3]=S,e[4]=w,e[5]=je):je=e[5];const x=je;let Fe;e[6]!==C||e[7]!==S||e[8]!==N||e[9]!==Q?(Fe=()=>{Z(S({column:C.trim(),kind:"addOptionalColumn",table:N,validator:Q}))},e[6]=C,e[7]=S,e[8]=N,e[9]=Q,e[10]=Fe):Fe=e[10];const k=Fe;let ke;e[11]!==W||e[12]!==q||e[13]!==S||e[14]!==N||e[15]!==Y?(ke=()=>{Z(S({fields:Dt(W),kind:"addIndex",name:q.trim(),table:N,unique:Y}))},e[11]=W,e[12]=q,e[13]=S,e[14]=N,e[15]=Y,e[16]=ke):ke=e[16];const Ce=ke;let D;e[17]===Symbol.for("react.memo_cache_sentinel")?(D=()=>{f(null),m("addTable")},e[17]=D):D=e[17];const ot=D;let M;e[18]===Symbol.for("react.memo_cache_sentinel")?(M=()=>{f(null),m("addColumn")},e[18]=M):M=e[18];const et=M;let ue;e[19]===Symbol.for("react.memo_cache_sentinel")?(ue=()=>{f(null),m("addIndex")},e[19]=ue):ue=e[19];const he=ue;let pe;e[20]!==t?(pe=()=>{m("destructive"),f({kind:"needs-migration",message:t("This edit changes stored data and must go through a migration. Review the migration before applying.")})},e[20]=t,e[21]=pe):pe=e[21];const _e=pe;let fe;e[22]===Symbol.for("react.memo_cache_sentinel")?(fe=v=>{d(v.target.value)},e[22]=fe):fe=e[22];const De=fe;let ge;e[23]===Symbol.for("react.memo_cache_sentinel")?(ge=v=>{G(v.target.value)},e[23]=ge):ge=e[23];const Me=ge;let be;e[24]===Symbol.for("react.memo_cache_sentinel")?(be=v=>{Le(v.target.value)},e[24]=be):be=e[24];const xe=be;let ve;e[25]===Symbol.for("react.memo_cache_sentinel")?(ve=v=>{Ye(v.target.value)},e[25]=ve):ve=e[25];const Re=ve;let qe;e[26]===Symbol.for("react.memo_cache_sentinel")?(qe=v=>{Ge(v.target.value)},e[26]=qe):qe=e[26];const Be=qe;let ye;e[27]===Symbol.for("react.memo_cache_sentinel")?(ye=v=>{ce(v.target.value)},e[27]=ye):ye=e[27];const Ue=ye;let Ne;e[28]===Symbol.for("react.memo_cache_sentinel")?(Ne=v=>{Ae(v.target.checked)},e[28]=Ne):Ne=e[28];const Ve=Ne;let we;e[29]!==r?(we=()=>{Z(r({to:"/migrations"}))},e[29]=r,e[30]=we):we=e[30];const E=we;let R;e[31]!==t?(R=t("Edit schema"),e[31]=t,e[32]=R):R=e[32];let te;e[33]!==R?(te=l(ct,{children:R}),e[33]=R,e[34]=te):te=e[34];let B;e[35]!==t?(B=t("Adds a table, column, or index to lunora/schema.ts and reruns codegen."),e[35]=t,e[36]=B):B=e[36];let T;e[37]!==B?(T=l(mt,{children:B}),e[37]=B,e[38]=T):T=e[38];let U;e[39]!==te||e[40]!==T?(U=c(ut,{children:[te,T]}),e[39]=te,e[40]=T,e[41]=U):U=e[41];const le=n==="addTable"?"default":"outline";let V;e[42]!==t?(V=t("Add table"),e[42]=t,e[43]=V):V=e[43];let Se;e[44]!==le||e[45]!==V?(Se=l(X,{"data-testid":"sc-editor-add-table",onClick:ot,size:"xs",type:"button",variant:le,children:V}),e[44]=le,e[45]=V,e[46]=Se):Se=e[46];const Te=o.length===0,Ze=n==="addColumn"?"default":"outline";let K;e[47]!==t?(K=t("Add column"),e[47]=t,e[48]=K):K=e[48];let Ie;e[49]!==Te||e[50]!==Ze||e[51]!==K?(Ie=l(X,{"data-testid":"sc-editor-add-column",disabled:Te,onClick:et,size:"xs",type:"button",variant:Ze,children:K}),e[49]=Te,e[50]=Ze,e[51]=K,e[52]=Ie):Ie=e[52];const $e=o.length===0,Ee=n==="addIndex"?"default":"outline";let I;e[53]!==t?(I=t("Add index"),e[53]=t,e[54]=I):I=e[54];let H;e[55]!==$e||e[56]!==Ee||e[57]!==I?(H=l(X,{"data-testid":"sc-editor-add-index",disabled:$e,onClick:he,size:"xs",type:"button",variant:Ee,children:I}),e[55]=$e,e[56]=Ee,e[57]=I,e[58]=H):H=e[58];const Pe=o.length===0,ae=n==="destructive"?"default":"ghost";let $;e[59]!==t?($=t("Rename / drop / change type…"),e[59]=t,e[60]=$):$=e[60];let ne;e[61]!==_e||e[62]!==Pe||e[63]!==ae||e[64]!==$?(ne=l(X,{"data-testid":"sc-editor-destructive",disabled:Pe,onClick:_e,size:"xs",type:"button",variant:ae,children:$}),e[61]=_e,e[62]=Pe,e[63]=ae,e[64]=$,e[65]=ne):ne=e[65];let se;e[66]!==Se||e[67]!==Ie||e[68]!==H||e[69]!==ne?(se=c("div",{className:"flex flex-wrap gap-2",children:[Se,Ie,H,ne]}),e[66]=Se,e[67]=Ie,e[68]=H,e[69]=ne,e[70]=se):se=e[70];let z;e[71]!==p||e[72]!==n||e[73]!==x||e[74]!==t||e[75]!==w?(z=n==="addTable"&&c("div",{className:"mt-3 flex flex-wrap items-end gap-2","data-testid":"sc-editor-table-form",children:[c("div",{className:"flex flex-col gap-1 text-xs",children:[l(ze,{htmlFor:"sc-editor-table-name",children:t("Table name")}),l(We,{"data-testid":"sc-editor-table-name",id:"sc-editor-table-name",onChange:De,value:w})]}),l(X,{"data-testid":"sc-editor-table-apply",disabled:p||w.trim()==="",onClick:x,size:"xs",type:"button",children:t(p?"Applying…":"Apply")}),l(X,{onClick:Oe,size:"xs",type:"button",variant:"ghost",children:t("Cancel")})]}),e[71]=p,e[72]=n,e[73]=x,e[74]=t,e[75]=w,e[76]=z):z=e[76];let A;e[77]!==p||e[78]!==C||e[79]!==n||e[80]!==k||e[81]!==t||e[82]!==o||e[83]!==N||e[84]!==Q?(A=n==="addColumn"&&c("div",{className:"mt-3 flex flex-wrap items-end gap-2","data-testid":"sc-editor-column-form",children:[c("div",{className:"flex flex-col gap-1 text-xs",children:[l(ze,{htmlFor:"sc-editor-column-table",children:t("Table name")}),l("select",{className:"h-8 rounded-md border border-input bg-transparent px-2 text-xs","data-testid":"sc-editor-column-table",id:"sc-editor-column-table",onChange:Re,value:N,children:o.map(Rt)})]}),c("div",{className:"flex flex-col gap-1 text-xs",children:[l(ze,{htmlFor:"sc-editor-column-name",children:t("Column name")}),l(We,{"data-testid":"sc-editor-column-name",id:"sc-editor-column-name",onChange:Me,value:C})]}),c("div",{className:"flex flex-col gap-1 text-xs",children:[l(ze,{htmlFor:"sc-editor-column-type",children:t("Column type")}),l("select",{className:"h-8 rounded-md border border-input bg-transparent px-2 text-xs","data-testid":"sc-editor-column-type",id:"sc-editor-column-type",onChange:xe,value:Q,children:Lt.map(Bt)})]}),l("span",{className:"text-[11px] text-muted-foreground",children:t("Optional")}),l(X,{"data-testid":"sc-editor-column-apply",disabled:p||C.trim()===""||N==="",onClick:k,size:"xs",type:"button",children:t(p?"Applying…":"Apply")}),l(X,{onClick:Oe,size:"xs",type:"button",variant:"ghost",children:t("Cancel")})]}),e[77]=p,e[78]=C,e[79]=n,e[80]=k,e[81]=t,e[82]=o,e[83]=N,e[84]=Q,e[85]=A):A=e[85];let O;e[86]!==p||e[87]!==W||e[88]!==q||e[89]!==n||e[90]!==Ce||e[91]!==t||e[92]!==o||e[93]!==N||e[94]!==Y?(O=n==="addIndex"&&c("div",{className:"mt-3 flex flex-wrap items-end gap-2","data-testid":"sc-editor-index-form",children:[c("div",{className:"flex flex-col gap-1 text-xs",children:[l(ze,{htmlFor:"sc-editor-index-table",children:t("Table name")}),l("select",{className:"h-8 rounded-md border border-input bg-transparent px-2 text-xs","data-testid":"sc-editor-index-table",id:"sc-editor-index-table",onChange:Re,value:N,children:o.map(Ut)})]}),c("div",{className:"flex flex-col gap-1 text-xs",children:[l(ze,{htmlFor:"sc-editor-index-name",children:t("Index name")}),l(We,{"data-testid":"sc-editor-index-name",id:"sc-editor-index-name",onChange:Be,value:q})]}),c("div",{className:"flex flex-col gap-1 text-xs",children:[l(ze,{htmlFor:"sc-editor-index-fields",children:t("Index fields (comma-separated)")}),l(We,{"data-testid":"sc-editor-index-fields",id:"sc-editor-index-fields",onChange:Ue,value:W})]}),c(ze,{className:"flex items-center gap-1 text-xs",htmlFor:"sc-editor-index-unique",children:[l("input",{checked:Y,"data-testid":"sc-editor-index-unique",id:"sc-editor-index-unique",onChange:Ve,type:"checkbox"}),l("span",{className:"text-muted-foreground",children:t("Unique")})]}),l(X,{"data-testid":"sc-editor-index-apply",disabled:p||q.trim()===""||W.trim()==="",onClick:Ce,size:"xs",type:"button",children:t(p?"Applying…":"Apply")}),l(X,{onClick:Oe,size:"xs",type:"button",variant:"ghost",children:t("Cancel")})]}),e[86]=p,e[87]=W,e[88]=q,e[89]=n,e[90]=Ce,e[91]=t,e[92]=o,e[93]=N,e[94]=Y,e[95]=O):O=e[95];let re;e[96]!==y?(re=y?.kind==="error"&&l("p",{className:"mt-3 text-sm text-destructive","data-testid":"sc-editor-error",role:"alert",children:y.message}),e[96]=y,e[97]=re):re=e[97];let oe;e[98]!==E||e[99]!==y?.kind||e[100]!==t?(oe=y?.kind==="needs-migration"&&c("div",{className:"mt-3 flex flex-col gap-2","data-testid":"sc-editor-needs-migration",children:[l("p",{className:"text-sm text-warning",role:"alert",children:t("This edit changes stored data and must go through a migration. Review the migration before applying.")}),l(X,{className:"self-start","data-testid":"sc-editor-open-migrations",onClick:E,size:"xs",type:"button",variant:"outline",children:t("Open Migrations")})]}),e[98]=E,e[99]=y?.kind,e[100]=t,e[101]=oe):oe=e[101];let j;e[102]!==y||e[103]!==t?(j=y?.kind==="ok"&&y.diagnostics.length>0&&c("div",{className:"mt-3 flex flex-col gap-1","data-testid":"sc-editor-diagnostics",children:[l("p",{className:"text-sm text-destructive",role:"alert",children:t("Codegen reported diagnostics:")}),l("ul",{className:"flex flex-col gap-0.5",children:y.diagnostics.map(Vt)})]}),e[102]=y,e[103]=t,e[104]=j):j=e[104];let F;e[105]!==se||e[106]!==z||e[107]!==A||e[108]!==O||e[109]!==re||e[110]!==oe||e[111]!==j?(F=c(ht,{children:[se,z,A,O,re,oe,j]}),e[105]=se,e[106]=z,e[107]=A,e[108]=O,e[109]=re,e[110]=oe,e[111]=j,e[112]=F):F=e[112];let J;return e[113]!==U||e[114]!==F?(J=c(pt,{"data-testid":"sc-editor",size:"sm",children:[U,F]}),e[113]=U,e[114]=F,e[115]=J):J=e[115],J};function Rt(s){return l("option",{value:s,children:s},s)}function Bt(s){return l("option",{value:s.validator,children:s.label},s.validator)}function Ut(s){return l("option",{value:s,children:s},s)}function Vt(s){return l("li",{className:"font-mono text-[11px] text-destructive",children:s},s)}const Kt=rt(st.listTables),Ht=rt(st.listTableIndexes),Jt=rt(st.readTablePage),Xt=rt(st.describeTables),Zt={},bt=[],xt=[],Qt=s=>{const e=Xe(5),{open:u}=s,o=u&&"rotate-90";let t;e[0]!==o?(t=kt("size-3.5 shrink-0 text-muted-foreground transition-transform duration-150",o),e[0]=o,e[1]=t):t=e[1];let r;e[2]===Symbol.for("react.memo_cache_sentinel")?(r=l("path",{d:"m9 6 6 6-6 6"}),e[2]=r):r=e[2];let n;return e[3]!==t?(n=l("svg",{"aria-hidden":"true",className:t,fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.8,viewBox:"0 0 24 24",children:r}),e[3]=t,e[4]=n):n=e[4],n},vt=s=>{const e=Xe(20),{children:u,expanded:o,name:t,onToggle:r,rowCount:n,rowTestId:m,toggleTestId:p}=s;let i;e[0]!==o?(i=l(Qt,{open:o}),e[0]=o,e[1]=i):i=e[1];let y;e[2]!==t?(y=l("span",{className:"truncate font-mono text-xs text-foreground",title:t,children:t}),e[2]=t,e[3]=y):y=e[3];let f;e[4]!==n?(f=c("span",{className:"ms-auto shrink-0 text-xs text-muted-foreground tabular-nums",children:["(",n,")"]}),e[4]=n,e[5]=f):f=e[5];let w;e[6]!==o||e[7]!==r||e[8]!==i||e[9]!==y||e[10]!==f||e[11]!==p?(w=c("button",{"aria-expanded":o,className:"flex w-full items-center gap-2 px-3 py-2 text-start transition-colors hover:bg-muted/50 aria-expanded:bg-muted/40","data-testid":p,onClick:r,type:"button",children:[i,y," ",f]}),e[6]=o,e[7]=r,e[8]=i,e[9]=y,e[10]=f,e[11]=p,e[12]=w):w=e[12];let d;e[13]!==u||e[14]!==o?(d=o&&l("div",{className:"px-3 pb-3 ps-8",children:u}),e[13]=u,e[14]=o,e[15]=d):d=e[15];let C;return e[16]!==m||e[17]!==w||e[18]!==d?(C=c("li",{className:"border-t border-border/60 first:border-t-0","data-testid":m,children:[w,d]}),e[16]=m,e[17]=w,e[18]=d,e[19]=C):C=e[19],C},yt=s=>{const e=Xe(5),{columns:u,testId:o}=s;let t;e[0]!==u?(t=u.map(Yt),e[0]=u,e[1]=t):t=e[1];let r;return e[2]!==t||e[3]!==o?(r=l("ul",{className:"flex flex-wrap gap-1.5 pt-1","data-testid":o,children:t}),e[2]=t,e[3]=o,e[4]=r):r=e[4],r},Wt=s=>{const e=Xe(10),{heading:u,indexes:o,testId:t}=s;let r;e[0]!==u?(r=l("p",{className:"mb-1.5 font-mono text-[10px] tracking-wide text-muted-foreground uppercase",children:u}),e[0]=u,e[1]=r):r=e[1];let n;e[2]!==o?(n=o.map(el),e[2]=o,e[3]=n):n=e[3];let m;e[4]!==n||e[5]!==t?(m=l("ul",{className:"flex flex-col gap-1","data-testid":t,children:n}),e[4]=n,e[5]=t,e[6]=m):m=e[6];let p;return e[7]!==r||e[8]!==m?(p=c("div",{className:"pt-3",children:[r,m]}),e[7]=r,e[8]=m,e[9]=p):p=e[9],p},Nt=s=>kt("border-b-2 px-3 py-2 font-mono text-[11px] tracking-widest uppercase outline-none transition-colors",s?"border-foreground text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),_l=s=>{const e=Xe(130),{initialShardKey:u,initialTable:o,schemaEditable:t}=s,r=It(),n=wt(),[m,p]=g("graph"),[i,y]=g(u??""),[f,w]=g(""),[d,C]=g(null),[G,Q]=g(null);let Le;e[0]===Symbol.for("react.memo_cache_sentinel")?(Le={},e[0]=Le):Le=e[0];const[N,Ye]=g(Le);let q;e[1]===Symbol.for("react.memo_cache_sentinel")?(q={},e[1]=q):q=e[1];const[Ge,W]=g(q),[ce,Y]=g(null);let Ae;e[2]===Symbol.for("react.memo_cache_sentinel")?(Ae={},e[2]=Ae):Ae=e[2];const[ee,Oe]=g(Ae);let me;e[3]===Symbol.for("react.memo_cache_sentinel")?(me={},e[3]=me):me=e[3];const[S,je]=g(me),[x,Fe]=g(null),[k,ke]=g(null);let Ce;e[4]===Symbol.for("react.memo_cache_sentinel")?(Ce={},e[4]=Ce):Ce=e[4];const[D,ot]=g(Ce),[M,et]=g(null);let ue;e[5]!==r?(ue=async a=>{Q(null);try{const h=await r.query(Kt,{},lt(a));jt(a),C(h),Ye({}),W({}),Y(null),Oe(b=>Object.fromEntries(Object.entries(b).filter(L=>{const[_]=L;return _!==a}))),je(b=>Object.fromEntries(Object.entries(b).filter(L=>{const[_]=L;return _!==a})))}catch(h){const b=h;C(null),Q(at(b))}},e[5]=r,e[6]=ue):ue=e[6];const he=ue;let pe;e[7]!==r?(pe=async()=>{ke(null);try{Fe(await r.listGlobalTables())}catch(a){const h=a;Fe(null),ke(at(h))}},e[7]=r,e[8]=pe):pe=e[8];const _e=pe;let fe;e[9]!==i?(fe=i.trim(),e[9]=i,e[10]=fe):fe=e[10];const De=Ot(fe,400);let ge,Me;e[11]!==De||e[12]!==he||e[13]!==_e?(Me=()=>{Z(he(De)),Z(_e())},ge=[he,_e,De],e[11]=De,e[12]=he,e[13]=_e,e[14]=ge,e[15]=Me):(ge=e[14],Me=e[15]),it(Me,ge);let be;e[16]!==r||e[17]!==N||e[18]!==ce||e[19]!==i?(be=async a=>{if(ce===a){Y(null);return}Y(a);const h=`${i}:${a}`;if(N[h]!==void 0)return;const[b,L]=await Promise.allSettled([r.query(Jt,{limit:1,offset:0,table:a},lt(i)),r.query(Ht,{table:a},lt(i))]);b.status==="fulfilled"?Ye(_=>({..._,[h]:b.value.columns})):Q(at(b.reason)),L.status==="fulfilled"&&W(_=>({..._,[h]:L.value.indexes}))},e[16]=r,e[17]=N,e[18]=ce,e[19]=i,e[20]=be):be=e[20];const xe=be;let ve;e[21]!==r||e[22]!==D||e[23]!==M?(ve=async a=>{if(M===a){et(null);return}if(et(a),D[a]===void 0)try{const h=await r.readGlobalTablePage({limit:1,offset:0,table:a});ot(b=>({...b,[a]:h.columns}))}catch(h){ke(at(h))}},e[21]=r,e[22]=D,e[23]=M,e[24]=ve):ve=e[24];const Re=ve,qe=$t(void 0);let Be,ye;e[25]!==o||e[26]!==d||e[27]!==xe?(Be=()=>{o===void 0||d===null||qe.current===o||d.some(a=>a.name===o)&&(qe.current=o,Z(xe(o)))},ye=[o,d,xe],e[25]=o,e[26]=d,e[27]=xe,e[28]=Be,e[29]=ye):(Be=e[28],ye=e[29]),it(Be,ye);let Ue;e[30]!==r?(Ue=async(a,h,b)=>{const[L,_]=await Promise.all([Promise.allSettled([r.query(Xt,{tables:[...h,...b]},lt(a))]),Promise.all(b.map(async de=>{const Qe=await Promise.allSettled([r.readGlobalTablePage({limit:1,offset:0,table:de})]),ft=Qe[0].status==="fulfilled"?Qe[0].value:void 0;return{columns:ft?.columns??[],refs:ft?.refs??{},table:de}}))]),Ct=L[0].status==="fulfilled"?L[0].value?.columnsByTable??{}:{},_t=L[0].status==="rejected",St=new Map(_.map(tl)),Tt=[...h,...b].map(de=>{const Qe=Ct[de]??[];return[de,Qe.length>0?Qe:St.get(de)??[]]});Oe(de=>({...de,[a]:Object.fromEntries(Tt)})),je(de=>({...de,[a]:_t}))},e[30]=r,e[31]=Ue):Ue=e[31];const Ne=Ue;let Ve,we;e[32]!==k||e[33]!==x||e[34]!==Ne||e[35]!==ee||e[36]!==i||e[37]!==d||e[38]!==m?(Ve=()=>{m!=="graph"||d===null||x===null&&k===null||ee[i]!==void 0||Z(Ne(i,d.map(ll),(x??[]).map(al)))},we=[m,d,x,k,i,ee,Ne],e[32]=k,e[33]=x,e[34]=Ne,e[35]=ee,e[36]=i,e[37]=d,e[38]=m,e[39]=Ve,e[40]=we):(Ve=e[39],we=e[40]),it(Ve,we);const E=ee[i]??Zt;let R;if(e[41]!==E||e[42]!==x||e[43]!==d){let a;e[45]!==E?(a=_=>({columns:E[_.name]??xt,name:_.name,tier:"shard"}),e[45]=E,e[46]=a):a=e[46];const h=(d??[]).map(a);let b;e[47]!==E?(b=_=>({columns:E[_.name]??xt,name:_.name,tier:"global"}),e[47]=E,e[48]=b):b=e[48];const L=(x??[]).map(b);R=[...h,...L],e[41]=E,e[42]=x,e[43]=d,e[44]=R}else R=e[44];const te=R;let B;if(e[49]!==f||e[50]!==d){const a=f.trim().toLowerCase();B=(d??[]).filter(h=>h.name.toLowerCase().includes(a)),e[49]=f,e[50]=d,e[51]=B}else B=e[51];const T=B;let U;if(e[52]!==x||e[53]!==f){const a=f.trim().toLowerCase();U=(x??[]).filter(h=>h.name.toLowerCase().includes(a)),e[52]=x,e[53]=f,e[54]=U}else U=e[54];const le=U;let V;e[55]===Symbol.for("react.memo_cache_sentinel")?(V=()=>{p("list")},e[55]=V):V=e[55];const Se=V;let Te;e[56]===Symbol.for("react.memo_cache_sentinel")?(Te=()=>{p("graph")},e[56]=Te):Te=e[56];const Ze=Te;let K;e[57]===Symbol.for("react.memo_cache_sentinel")?(K=a=>{w(a.target.value)},e[57]=K):K=e[57];const Ie=K;let $e;e[58]!==he||e[59]!==i?($e=a=>{Z(he(i))},e[58]=he,e[59]=i,e[60]=$e):$e=e[60];const Ee=$e;let I;e[61]!==d?(I=d??[],e[61]=d,e[62]=I):I=e[62];let H;e[63]!==I?(H=I.map(nl),e[63]=I,e[64]=H):H=e[64];const Pe=H;let ae;e[65]!==i?(ae=l(zt,{onChange:y,testId:"sc-shard-input",value:i}),e[65]=i,e[66]=ae):ae=e[66];let $;e[67]!==n?($=n("Schema view"),e[67]=n,e[68]=$):$=e[68];const ne=m==="graph",se=m==="graph";let z;e[69]!==se?(z=Nt(se),e[69]=se,e[70]=z):z=e[70];let A;e[71]!==n?(A=n("Graph"),e[71]=n,e[72]=A):A=e[72];let O;e[73]!==ne||e[74]!==z||e[75]!==A?(O=l("button",{"aria-selected":ne,className:z,"data-testid":"sc-view-graph",onClick:Ze,role:"tab",type:"button",children:A}),e[73]=ne,e[74]=z,e[75]=A,e[76]=O):O=e[76];const re=m==="list",oe=m==="list";let j;e[77]!==oe?(j=Nt(oe),e[77]=oe,e[78]=j):j=e[78];let F;e[79]!==n?(F=n("Table list"),e[79]=n,e[80]=F):F=e[80];let J;e[81]!==re||e[82]!==j||e[83]!==F?(J=l("button",{"aria-selected":re,className:j,"data-testid":"sc-view-list",onClick:Se,role:"tab",type:"button",children:F}),e[81]=re,e[82]=j,e[83]=F,e[84]=J):J=e[84];let v;e[85]!==$||e[86]!==O||e[87]!==J?(v=c("div",{"aria-label":$,className:"flex items-center gap-1","data-testid":"sc-view-toggle",role:"tablist",children:[O,J]}),e[85]=$,e[86]=O,e[87]=J,e[88]=v):v=e[88];let P;e[89]!==ae||e[90]!==v?(P=c("div",{className:"flex flex-wrap items-center gap-3",children:[ae,v]}),e[89]=ae,e[90]=v,e[91]=P):P=e[91];let ie;e[92]!==Ee||e[93]!==t||e[94]!==Pe?(ie=t===!0&&l(Mt,{onApplied:Ee,tableNames:Pe}),e[92]=Ee,e[93]=t,e[94]=Pe,e[95]=ie):ie=e[95];let Ke;e[96]!==n||e[97]!==f||e[98]!==m?(Ke=m==="list"&&l(We,{"aria-label":n("Filter tables"),className:"h-8 max-w-xs","data-testid":"sc-filter",onChange:Ie,placeholder:n("Filter tables"),value:f}),e[96]=n,e[97]=f,e[98]=m,e[99]=Ke):Ke=e[99];let He;e[100]!==te||e[101]!==G||e[102]!==k||e[103]!==S||e[104]!==i||e[105]!==m?(He=m==="graph"&&c("div",{className:"flex flex-col gap-2","data-testid":"sc-graph-view",children:[G!==null&&l("p",{className:"text-sm text-destructive","data-testid":"sc-error",role:"alert",children:G}),k!==null&&l("p",{className:"text-sm text-destructive","data-testid":"sc-global-error",role:"alert",children:k}),l(Ft,{columnsError:S[i]===!0,tables:te,testIdPrefix:"sc-graph"})]}),e[100]=te,e[101]=G,e[102]=k,e[103]=S,e[104]=i,e[105]=m,e[106]=He):He=e[106];let Je;e[107]!==N||e[108]!==G||e[109]!==ce||e[110]!==le||e[111]!==T||e[112]!==D||e[113]!==k||e[114]!==M||e[115]!==x||e[116]!==Ge||e[117]!==i||e[118]!==n||e[119]!==d||e[120]!==xe||e[121]!==Re||e[122]!==m?(Je=m==="list"&&c("div",{className:"flex flex-col gap-4",children:[c(pt,{"data-testid":"sc-shard-section",size:"sm",children:[c(ut,{children:[c("div",{className:"flex items-center gap-2",children:[l(gt,{tier:"shard"}),l(ct,{children:n("Shard tables")}),d!==null&&l(nt,{className:"ms-auto tabular-nums",variant:"outline",children:T.length})]}),l(mt,{children:dt.shard.hint})]}),c(ht,{children:[G!==null&&l("p",{className:"text-sm text-destructive","data-testid":"sc-error",role:"alert",children:G}),d!==null&&d.length===0&&l("p",{className:"text-sm text-muted-foreground","data-testid":"sc-empty",children:n("No tables in this shard.")}),d!==null&&d.length>0&&T.length===0&&l("p",{className:"text-sm text-muted-foreground","data-testid":"sc-no-match",children:n("No tables match your filter.")}),T.length>0&&l("ul",{className:"-mx-3 overflow-hidden border-t border-border","data-testid":"sc-table-list",children:T.map(a=>{const h=`${i}:${a.name}`,b=Ge[h]??[];return c(vt,{expanded:ce===a.name,name:a.name,onToggle:()=>{Z(xe(a.name))},rowCount:a.rowCount,rowTestId:`sc-table-${a.name}`,toggleTestId:`sc-toggle-${a.name}`,children:[l(yt,{columns:N[h]??bt,testId:`sc-columns-${a.name}`}),b.length>0&&l(Wt,{heading:n("Indexes"),indexes:b,testId:`sc-indexes-${a.name}`})]},a.name)})})]})]}),c(pt,{"data-testid":"sc-global-section",size:"sm",children:[c(ut,{children:[c("div",{className:"flex items-center gap-2",children:[l(gt,{tier:"global"}),l(ct,{children:n("Global tables (D1)")}),x!==null&&l(nt,{className:"ms-auto tabular-nums",variant:"outline",children:le.length})]}),l(mt,{children:dt.global.hint})]}),c(ht,{children:[k!==null&&l("p",{className:"text-sm text-destructive","data-testid":"sc-global-error",role:"alert",children:k}),x!==null&&x.length===0&&l(At,{description:dt.global.hint,testId:"sc-global-empty",title:n("No global tables.")}),x!==null&&x.length>0&&le.length===0&&l("p",{className:"text-sm text-muted-foreground","data-testid":"sc-global-no-match",children:n("No tables match your filter.")}),le.length>0&&l("ul",{className:"-mx-3 overflow-hidden border-t border-border","data-testid":"sc-global-table-list",children:le.map(a=>l(vt,{expanded:M===a.name,name:a.name,onToggle:()=>{Z(Re(a.name))},rowCount:a.rowCount,rowTestId:`sc-global-table-${a.name}`,toggleTestId:`sc-global-toggle-${a.name}`,children:l(yt,{columns:D[a.name]??bt,testId:`sc-global-columns-${a.name}`})},a.name))})]})]})]}),e[107]=N,e[108]=G,e[109]=ce,e[110]=le,e[111]=T,e[112]=D,e[113]=k,e[114]=M,e[115]=x,e[116]=Ge,e[117]=i,e[118]=n,e[119]=d,e[120]=xe,e[121]=Re,e[122]=m,e[123]=Je):Je=e[123];let tt;return e[124]!==P||e[125]!==ie||e[126]!==Ke||e[127]!==He||e[128]!==Je?(tt=c("div",{className:"flex flex-col gap-4","data-testid":"lunora-schema",children:[P,ie,Ke,He,Je]}),e[124]=P,e[125]=ie,e[126]=Ke,e[127]=He,e[128]=Je,e[129]=tt):tt=e[129],tt};function Yt(s){return l("li",{className:"rounded bg-muted px-1.5 py-0.5 font-mono text-[11px] text-muted-foreground",children:s},s)}function el(s){return c("li",{className:"flex flex-wrap items-center gap-1.5 text-xs",children:[l("span",{className:"font-mono",children:s.name}),l(nt,{variant:"outline",children:s.type}),s.unique===!0&&l(nt,{variant:"secondary",children:"unique"}),l("span",{className:"text-muted-foreground",children:s.fields.join(", ")})]},`${s.type}:${s.name}`)}function tl(s){const{columns:e,refs:u,table:o}=s;return[o,e.map(t=>{const r=u[t];return r===void 0?{name:t,optional:!1,type:""}:{name:t,optional:!1,ref:r,type:"id"}})]}function ll(s){return s.name}function al(s){return s.name}function nl(s){return s.name}export{_l as SchemaViewer};
1
+ import{c as we}from"react/compiler-runtime";import{ShardInput as Qe}from"../packem_shared/ShardInput-BVn2iCU0.js";import{g as Ve,d as qe}from"../packem_shared/storage-tier-DznqOf-q.js";import{g as Fe}from"../packem_shared/badge-BbuuAio7.js";import{f as Ge,m as Le,n as Ke,u as Me,c as De}from"../packem_shared/card-CIDGUN6K.js";import{E as Ze}from"../packem_shared/empty-state-Cg7t_8qu.js";import{u as Ie}from"../packem_shared/input-JHu63lTv.js";import{useT as ze}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{d as Ae,b as Ee,f as ye,g as je}from"../packem_shared/internal-BSIsQVC6.js";import{c as We}from"../packem_shared/utils-bhneXptQ.js";import{useLunora as et}from"@lunora/react";import{useState as S,useEffect as Pe,useRef as tt}from"react";import lt from"../packem_shared/useDebounced-Ihdiid_k.js";import{ADMIN_FUNCTIONS as Oe}from"../packem_shared/ADMIN_FUNCTIONS-CZESgd10.js";import{r as at}from"../packem_shared/shard-history-DMEW5VBE.js";import{S as nt}from"../packem_shared/schema-diagram-cg-bz_VL.js";import{useNavigate as st}from"@tanstack/react-router";import{u as ve}from"../packem_shared/button-BkCrNcAs.js";import{p as $e}from"../packem_shared/label-6uP1obNF.js";import{jsx as l,jsxs as g,Fragment as Be}from"react/jsx-runtime";const rt=je(Oe.listTables),ot=je(Oe.listTableIndexes),it=je(Oe.readTablePage),dt=je(Oe.describeTables),ct={},Ue=[],mt=s=>{const e=we(75),{initialShardKey:m,initialTable:n}=s,t=et(),[a,d]=S("graph"),[o,i]=S(m??""),[u,c]=S(""),[r,b]=S(null),[N,h]=S(null);let F;e[0]===Symbol.for("react.memo_cache_sentinel")?(F={},e[0]=F):F=e[0];const[w,ce]=S(F);let x;e[1]===Symbol.for("react.memo_cache_sentinel")?(x={},e[1]=x):x=e[1];const[q,z]=S(x),[A,_]=S(null);let C;e[2]===Symbol.for("react.memo_cache_sentinel")?(C={},e[2]=C):C=e[2];const[k,P]=S(C);let Z;e[3]===Symbol.for("react.memo_cache_sentinel")?(Z={},e[3]=Z):Z=e[3];const[me,I]=S(Z),[v,ge]=S(null),[G,ue]=S(null);let ee;e[4]===Symbol.for("react.memo_cache_sentinel")?(ee={},e[4]=ee):ee=e[4];const[U,Ne]=S(ee),[X,be]=S(null);let Y;e[5]!==t?(Y=async p=>{h(null);try{const y=await t.query(rt,{},Ae(p));at(p),b(y),ce({}),z({}),_(null),P(T=>Object.fromEntries(Object.entries(T).filter(E=>{const[$]=E;return $!==p}))),I(T=>Object.fromEntries(Object.entries(T).filter(E=>{const[$]=E;return $!==p})))}catch(y){const T=y;b(null),h(Ee(T))}},e[5]=t,e[6]=Y):Y=e[6];const te=Y;let L;e[7]!==t?(L=async()=>{ue(null);try{ge(await t.listGlobalTables())}catch(p){const y=p;ge(null),ue(Ee(y))}},e[7]=t,e[8]=L):L=e[8];const le=L;let ae;e[9]!==o?(ae=o.trim(),e[9]=o,e[10]=ae):ae=e[10];const he=lt(ae,400);let K,ne;e[11]!==he||e[12]!==te||e[13]!==le?(ne=()=>{ye(te(he)),ye(le())},K=[te,le,he],e[11]=he,e[12]=te,e[13]=le,e[14]=K,e[15]=ne):(K=e[14],ne=e[15]),Pe(ne,K);let M;e[16]!==t||e[17]!==w||e[18]!==A||e[19]!==o?(M=async p=>{if(A===p){_(null);return}_(p);const y=`${o}:${p}`;if(w[y]!==void 0)return;const[T,E]=await Promise.allSettled([t.query(it,{limit:1,offset:0,table:p},Ae(o)),t.query(ot,{table:p},Ae(o))]);T.status==="fulfilled"?ce($=>({...$,[y]:T.value.columns})):h(Ee(T.reason)),E.status==="fulfilled"&&z($=>({...$,[y]:E.value.indexes}))},e[16]=t,e[17]=w,e[18]=A,e[19]=o,e[20]=M):M=e[20];const se=M;let re;e[21]!==t||e[22]!==U||e[23]!==X?(re=async p=>{if(X===p){be(null);return}if(be(p),U[p]===void 0)try{const y=await t.readGlobalTablePage({limit:1,offset:0,table:p});Ne(T=>({...T,[p]:y.columns}))}catch(y){ue(Ee(y))}},e[21]=t,e[22]=U,e[23]=X,e[24]=re):re=e[24];const pe=re,H=tt(void 0);let J,D;e[25]!==n||e[26]!==r||e[27]!==se?(J=()=>{n===void 0||r===null||H.current===n||r.some(p=>p.name===n)&&(H.current=n,ye(se(n)))},D=[n,r,se],e[25]=n,e[26]=r,e[27]=se,e[28]=J,e[29]=D):(J=e[28],D=e[29]),Pe(J,D);let oe;e[30]!==t?(oe=async(p,y,T)=>{const[E,$]=await Promise.all([Promise.allSettled([t.query(dt,{tables:[...y,...T]},Ae(p))]),Promise.all(T.map(async B=>{const Te=await Promise.allSettled([t.readGlobalTablePage({limit:1,offset:0,table:B})]),Re=Te[0].status==="fulfilled"?Te[0].value:void 0;return{columns:Re?.columns??[],refs:Re?.refs??{},table:B}}))]),Se=E[0].status==="fulfilled"?E[0].value?.columnsByTable??{}:{},_e=E[0].status==="rejected",ke=new Map($.map(ut)),O=[...y,...T].map(B=>{const Te=Se[B]??[];return[B,Te.length>0?Te:ke.get(B)??[]]});P(B=>({...B,[p]:Object.fromEntries(O)})),I(B=>({...B,[p]:_e}))},e[30]=t,e[31]=oe):oe=e[31];const R=oe;let ie,V;e[32]!==G||e[33]!==v||e[34]!==R||e[35]!==k||e[36]!==o||e[37]!==r||e[38]!==a?(ie=()=>{a!=="graph"||r===null||v===null&&G===null||k[o]!==void 0||ye(R(o,r.map(ht),(v??[]).map(pt)))},V=[a,r,v,G,o,k,R],e[32]=G,e[33]=v,e[34]=R,e[35]=k,e[36]=o,e[37]=r,e[38]=a,e[39]=ie,e[40]=V):(ie=e[39],V=e[40]),Pe(ie,V);const j=k[o]??ct;let W;if(e[41]!==j||e[42]!==v||e[43]!==r){let p;e[45]!==j?(p=$=>({columns:j[$.name]??Ue,name:$.name,tier:"shard"}),e[45]=j,e[46]=p):p=e[46];const y=(r??[]).map(p);let T;e[47]!==j?(T=$=>({columns:j[$.name]??Ue,name:$.name,tier:"global"}),e[47]=j,e[48]=T):T=e[48];const E=(v??[]).map(T);W=[...y,...E],e[41]=j,e[42]=v,e[43]=r,e[44]=W}else W=e[44];const f=W;let Q;if(e[49]!==u||e[50]!==r){const p=u.trim().toLowerCase();Q=(r??[]).filter(y=>y.name.toLowerCase().includes(p)),e[49]=u,e[50]=r,e[51]=Q}else Q=e[51];const de=Q;let fe;if(e[52]!==v||e[53]!==u){const p=u.trim().toLowerCase();fe=(v??[]).filter(y=>y.name.toLowerCase().includes(p)),e[52]=v,e[53]=u,e[54]=fe}else fe=e[54];const Ce=fe;let xe;return e[55]!==w||e[56]!==f||e[57]!==N||e[58]!==A||e[59]!==Ce||e[60]!==de||e[61]!==U||e[62]!==G||e[63]!==X||e[64]!==v||e[65]!==q||e[66]!==te||e[67]!==me||e[68]!==o||e[69]!==u||e[70]!==r||e[71]!==se||e[72]!==pe||e[73]!==a?(xe={columns:w,diagramTables:f,error:N,expanded:A,filteredGlobalTables:Ce,filteredTables:de,globalColumns:U,globalError:G,globalExpanded:X,globalTables:v,indexes:q,refresh:te,setShardKey:i,setTableFilter:c,setView:d,shardColumnsError:me,shardKey:o,tableFilter:u,tables:r,toggle:se,toggleGlobal:pe,view:a},e[55]=w,e[56]=f,e[57]=N,e[58]=A,e[59]=Ce,e[60]=de,e[61]=U,e[62]=G,e[63]=X,e[64]=v,e[65]=q,e[66]=te,e[67]=me,e[68]=o,e[69]=u,e[70]=r,e[71]=se,e[72]=pe,e[73]=a,e[74]=xe):xe=e[74],xe};function ut(s){const{columns:e,refs:m,table:n}=s;return[n,e.map(t=>{const a=m[t];return a===void 0?{name:t,optional:!1,type:""}:{name:t,optional:!1,ref:a,type:"id"}})]}function ht(s){return s.name}function pt(s){return s.name}const gt="/__lunora/schema-edit",bt=async s=>{const e=await fetch(gt,{body:JSON.stringify(s),headers:{"Content-Type":"application/json","X-Lunora-Studio":"1"},method:"POST"}),m=await e.json();return m.needsMigration===!0?{kind:"needs-migration",message:m.message??"This edit needs a migration."}:e.ok&&m.tables!==void 0?{diagnostics:m.diagnostics??[],kind:"ok",tables:m.tables}:{kind:"error",message:m.error??`schema edit failed (${String(e.status)})`}},ft=s=>{const e=we(32),{hasTables:m,mode:n,onAddColumn:t,onAddIndex:a,onAddTable:d,onDestructive:o}=s,i=ze(),u=n==="addTable"?"default":"outline";let c;e[0]!==i?(c=i("Add table"),e[0]=i,e[1]=c):c=e[1];let r;e[2]!==d||e[3]!==u||e[4]!==c?(r=l(ve,{"data-testid":"sc-editor-add-table",onClick:d,size:"xs",type:"button",variant:u,children:c}),e[2]=d,e[3]=u,e[4]=c,e[5]=r):r=e[5];const b=!m,N=n==="addColumn"?"default":"outline";let h;e[6]!==i?(h=i("Add column"),e[6]=i,e[7]=h):h=e[7];let F;e[8]!==t||e[9]!==b||e[10]!==N||e[11]!==h?(F=l(ve,{"data-testid":"sc-editor-add-column",disabled:b,onClick:t,size:"xs",type:"button",variant:N,children:h}),e[8]=t,e[9]=b,e[10]=N,e[11]=h,e[12]=F):F=e[12];const w=!m,ce=n==="addIndex"?"default":"outline";let x;e[13]!==i?(x=i("Add index"),e[13]=i,e[14]=x):x=e[14];let q;e[15]!==a||e[16]!==x||e[17]!==w||e[18]!==ce?(q=l(ve,{"data-testid":"sc-editor-add-index",disabled:w,onClick:a,size:"xs",type:"button",variant:ce,children:x}),e[15]=a,e[16]=x,e[17]=w,e[18]=ce,e[19]=q):q=e[19];const z=!m,A=n==="destructive"?"default":"ghost";let _;e[20]!==i?(_=i("Rename / drop / change type…"),e[20]=i,e[21]=_):_=e[21];let C;e[22]!==o||e[23]!==z||e[24]!==A||e[25]!==_?(C=l(ve,{"data-testid":"sc-editor-destructive",disabled:z,onClick:o,size:"xs",type:"button",variant:A,children:_}),e[22]=o,e[23]=z,e[24]=A,e[25]=_,e[26]=C):C=e[26];let k;return e[27]!==q||e[28]!==C||e[29]!==r||e[30]!==F?(k=g("div",{className:"flex flex-wrap gap-2",children:[r,F,q,C]}),e[27]=q,e[28]=C,e[29]=r,e[30]=F,e[31]=k):k=e[31],k},xt=s=>{const e=we(28),{onOpenMigrations:m,result:n}=s,t=ze();if(n===null){let c;return e[0]===Symbol.for("react.memo_cache_sentinel")?(c=l(Be,{}),e[0]=c):c=e[0],c}if(n.kind==="error"){let c;return e[1]!==n.message?(c=l("p",{className:"mt-3 text-sm text-destructive","data-testid":"sc-editor-error",role:"alert",children:n.message}),e[1]=n.message,e[2]=c):c=e[2],c}if(n.kind==="needs-migration"){let c;e[3]!==n.message||e[4]!==t?(c=n.message===""?t("This edit changes stored data and must go through a migration. Review the migration before applying."):n.message,e[3]=n.message,e[4]=t,e[5]=c):c=e[5];let r;e[6]!==c?(r=l("p",{className:"text-sm text-warning",role:"alert",children:c}),e[6]=c,e[7]=r):r=e[7];let b;e[8]!==t?(b=t("Open Migrations"),e[8]=t,e[9]=b):b=e[9];let N;e[10]!==m||e[11]!==b?(N=l(ve,{className:"self-start","data-testid":"sc-editor-open-migrations",onClick:m,size:"xs",type:"button",variant:"outline",children:b}),e[10]=m,e[11]=b,e[12]=N):N=e[12];let h;return e[13]!==r||e[14]!==N?(h=g("div",{className:"mt-3 flex flex-col gap-2","data-testid":"sc-editor-needs-migration",children:[r,N]}),e[13]=r,e[14]=N,e[15]=h):h=e[15],h}if(n.diagnostics.length===0){let c;return e[16]===Symbol.for("react.memo_cache_sentinel")?(c=l(Be,{}),e[16]=c):c=e[16],c}let a;e[17]!==t?(a=t("Codegen reported diagnostics:"),e[17]=t,e[18]=a):a=e[18];let d;e[19]!==a?(d=l("p",{className:"text-sm text-destructive",role:"alert",children:a}),e[19]=a,e[20]=d):d=e[20];let o;e[21]!==n.diagnostics?(o=n.diagnostics.map(vt),e[21]=n.diagnostics,e[22]=o):o=e[22];let i;e[23]!==o?(i=l("ul",{className:"flex flex-col gap-0.5",children:o}),e[23]=o,e[24]=i):i=e[24];let u;return e[25]!==d||e[26]!==i?(u=g("div",{className:"mt-3 flex flex-col gap-1","data-testid":"sc-editor-diagnostics",children:[d,i]}),e[25]=d,e[26]=i,e[27]=u):u=e[27],u};function vt(s){return l("li",{className:"font-mono text-[11px] text-destructive",children:s},s)}const yt=[{label:"string",validator:"v.string()"},{label:"number",validator:"v.number()"},{label:"boolean",validator:"v.boolean()"},{label:"bigint",validator:"v.int64()"},{label:"bytes",validator:"v.bytes()"},{label:"any",validator:"v.any()"}],Nt="v.string()",Ct=s=>s.split(",").map(e=>e.trim()).filter(e=>e!==""),Tt=s=>{const e=we(83),{onApplied:m,tableNames:n}=s,t=ze(),a=st(),[d,o]=S(null),[i,u]=S(!1),[c,r]=S(null),[b,N]=S(""),[h,F]=S(""),[w,ce]=S(Nt),[x,q]=S(n[0]??""),[z,A]=S(""),[_,C]=S(""),[k,P]=S(!1);let Z;e[0]===Symbol.for("react.memo_cache_sentinel")?(Z=()=>{o(null),N(""),F(""),A(""),C(""),P(!1)},e[0]=Z):Z=e[0];const me=Z;let I;e[1]!==m?(I=async O=>{u(!0),r(null);try{const B=await bt(O);r(B),B.kind==="ok"&&(m(B.tables),me())}catch(B){const Te=B;r({kind:"error",message:Te instanceof Error?Te.message:String(Te)})}u(!1)},e[1]=m,e[2]=I):I=e[2];const v=I;let ge;e[3]!==v||e[4]!==b?(ge=()=>{ye(v({kind:"addTable",table:b.trim()}))},e[3]=v,e[4]=b,e[5]=ge):ge=e[5];const G=ge;let ue;e[6]!==h||e[7]!==v||e[8]!==x||e[9]!==w?(ue=()=>{ye(v({column:h.trim(),kind:"addOptionalColumn",table:x,validator:w}))},e[6]=h,e[7]=v,e[8]=x,e[9]=w,e[10]=ue):ue=e[10];const ee=ue;let U;e[11]!==_||e[12]!==z||e[13]!==v||e[14]!==x||e[15]!==k?(U=()=>{ye(v({fields:Ct(_),kind:"addIndex",name:z.trim(),table:x,unique:k}))},e[11]=_,e[12]=z,e[13]=v,e[14]=x,e[15]=k,e[16]=U):U=e[16];const Ne=U;let X;e[17]===Symbol.for("react.memo_cache_sentinel")?(X=()=>{r(null),o("addTable")},e[17]=X):X=e[17];const be=X;let Y;e[18]===Symbol.for("react.memo_cache_sentinel")?(Y=()=>{r(null),o("addColumn")},e[18]=Y):Y=e[18];const te=Y;let L;e[19]===Symbol.for("react.memo_cache_sentinel")?(L=()=>{r(null),o("addIndex")},e[19]=L):L=e[19];const le=L;let ae;e[20]!==t?(ae=()=>{o("destructive"),r({kind:"needs-migration",message:t("This edit changes stored data and must go through a migration. Review the migration before applying.")})},e[20]=t,e[21]=ae):ae=e[21];const he=ae;let K;e[22]===Symbol.for("react.memo_cache_sentinel")?(K=O=>{N(O.target.value)},e[22]=K):K=e[22];const ne=K;let M;e[23]===Symbol.for("react.memo_cache_sentinel")?(M=O=>{F(O.target.value)},e[23]=M):M=e[23];const se=M;let re;e[24]===Symbol.for("react.memo_cache_sentinel")?(re=O=>{ce(O.target.value)},e[24]=re):re=e[24];const pe=re;let H;e[25]===Symbol.for("react.memo_cache_sentinel")?(H=O=>{q(O.target.value)},e[25]=H):H=e[25];const J=H;let D;e[26]===Symbol.for("react.memo_cache_sentinel")?(D=O=>{A(O.target.value)},e[26]=D):D=e[26];const oe=D;let R;e[27]===Symbol.for("react.memo_cache_sentinel")?(R=O=>{C(O.target.value)},e[27]=R):R=e[27];const ie=R;let V;e[28]===Symbol.for("react.memo_cache_sentinel")?(V=O=>{P(O.target.checked)},e[28]=V):V=e[28];const j=V;let W;e[29]!==a?(W=()=>{ye(a({to:"/migrations"}))},e[29]=a,e[30]=W):W=e[30];const f=W;let Q;e[31]!==t?(Q=t("Edit schema"),e[31]=t,e[32]=Q):Q=e[32];let de;e[33]!==Q?(de=l(Ge,{children:Q}),e[33]=Q,e[34]=de):de=e[34];let fe;e[35]!==t?(fe=t("Adds a table, column, or index to lunora/schema.ts and reruns codegen."),e[35]=t,e[36]=fe):fe=e[36];let Ce;e[37]!==fe?(Ce=l(Le,{children:fe}),e[37]=fe,e[38]=Ce):Ce=e[38];let xe;e[39]!==de||e[40]!==Ce?(xe=g(Ke,{children:[de,Ce]}),e[39]=de,e[40]=Ce,e[41]=xe):xe=e[41];const p=n.length>0;let y;e[42]!==d||e[43]!==he||e[44]!==p?(y=l(ft,{hasTables:p,mode:d,onAddColumn:te,onAddIndex:le,onAddTable:be,onDestructive:he}),e[42]=d,e[43]=he,e[44]=p,e[45]=y):y=e[45];let T;e[46]!==i||e[47]!==d||e[48]!==G||e[49]!==t||e[50]!==b?(T=d==="addTable"&&g("div",{className:"mt-3 flex flex-wrap items-end gap-2","data-testid":"sc-editor-table-form",children:[g("div",{className:"flex flex-col gap-1 text-xs",children:[l($e,{htmlFor:"sc-editor-table-name",children:t("Table name")}),l(Ie,{"data-testid":"sc-editor-table-name",id:"sc-editor-table-name",onChange:ne,value:b})]}),l(ve,{"data-testid":"sc-editor-table-apply",disabled:i||b.trim()==="",onClick:G,size:"xs",type:"button",children:t(i?"Applying…":"Apply")}),l(ve,{onClick:me,size:"xs",type:"button",variant:"ghost",children:t("Cancel")})]}),e[46]=i,e[47]=d,e[48]=G,e[49]=t,e[50]=b,e[51]=T):T=e[51];let E;e[52]!==i||e[53]!==h||e[54]!==d||e[55]!==ee||e[56]!==t||e[57]!==n||e[58]!==x||e[59]!==w?(E=d==="addColumn"&&g("div",{className:"mt-3 flex flex-wrap items-end gap-2","data-testid":"sc-editor-column-form",children:[g("div",{className:"flex flex-col gap-1 text-xs",children:[l($e,{htmlFor:"sc-editor-column-table",children:t("Table name")}),l("select",{className:"h-8 rounded-md border border-input bg-transparent px-2 text-xs","data-testid":"sc-editor-column-table",id:"sc-editor-column-table",onChange:J,value:x,children:n.map(wt)})]}),g("div",{className:"flex flex-col gap-1 text-xs",children:[l($e,{htmlFor:"sc-editor-column-name",children:t("Column name")}),l(Ie,{"data-testid":"sc-editor-column-name",id:"sc-editor-column-name",onChange:se,value:h})]}),g("div",{className:"flex flex-col gap-1 text-xs",children:[l($e,{htmlFor:"sc-editor-column-type",children:t("Column type")}),l("select",{className:"h-8 rounded-md border border-input bg-transparent px-2 text-xs","data-testid":"sc-editor-column-type",id:"sc-editor-column-type",onChange:pe,value:w,children:yt.map(St)})]}),l("span",{className:"text-[11px] text-muted-foreground",children:t("Optional")}),l(ve,{"data-testid":"sc-editor-column-apply",disabled:i||h.trim()===""||x==="",onClick:ee,size:"xs",type:"button",children:t(i?"Applying…":"Apply")}),l(ve,{onClick:me,size:"xs",type:"button",variant:"ghost",children:t("Cancel")})]}),e[52]=i,e[53]=h,e[54]=d,e[55]=ee,e[56]=t,e[57]=n,e[58]=x,e[59]=w,e[60]=E):E=e[60];let $;e[61]!==i||e[62]!==_||e[63]!==z||e[64]!==d||e[65]!==Ne||e[66]!==t||e[67]!==n||e[68]!==x||e[69]!==k?($=d==="addIndex"&&g("div",{className:"mt-3 flex flex-wrap items-end gap-2","data-testid":"sc-editor-index-form",children:[g("div",{className:"flex flex-col gap-1 text-xs",children:[l($e,{htmlFor:"sc-editor-index-table",children:t("Table name")}),l("select",{className:"h-8 rounded-md border border-input bg-transparent px-2 text-xs","data-testid":"sc-editor-index-table",id:"sc-editor-index-table",onChange:J,value:x,children:n.map(_t)})]}),g("div",{className:"flex flex-col gap-1 text-xs",children:[l($e,{htmlFor:"sc-editor-index-name",children:t("Index name")}),l(Ie,{"data-testid":"sc-editor-index-name",id:"sc-editor-index-name",onChange:oe,value:z})]}),g("div",{className:"flex flex-col gap-1 text-xs",children:[l($e,{htmlFor:"sc-editor-index-fields",children:t("Index fields (comma-separated)")}),l(Ie,{"data-testid":"sc-editor-index-fields",id:"sc-editor-index-fields",onChange:ie,value:_})]}),g($e,{className:"flex items-center gap-1 text-xs",htmlFor:"sc-editor-index-unique",children:[l("input",{checked:k,"data-testid":"sc-editor-index-unique",id:"sc-editor-index-unique",onChange:j,type:"checkbox"}),l("span",{className:"text-muted-foreground",children:t("Unique")})]}),l(ve,{"data-testid":"sc-editor-index-apply",disabled:i||z.trim()===""||_.trim()==="",onClick:Ne,size:"xs",type:"button",children:t(i?"Applying…":"Apply")}),l(ve,{onClick:me,size:"xs",type:"button",variant:"ghost",children:t("Cancel")})]}),e[61]=i,e[62]=_,e[63]=z,e[64]=d,e[65]=Ne,e[66]=t,e[67]=n,e[68]=x,e[69]=k,e[70]=$):$=e[70];let Se;e[71]!==f||e[72]!==c?(Se=l(xt,{onOpenMigrations:f,result:c}),e[71]=f,e[72]=c,e[73]=Se):Se=e[73];let _e;e[74]!==y||e[75]!==T||e[76]!==E||e[77]!==$||e[78]!==Se?(_e=g(Me,{children:[y,T,E,$,Se]}),e[74]=y,e[75]=T,e[76]=E,e[77]=$,e[78]=Se,e[79]=_e):_e=e[79];let ke;return e[80]!==xe||e[81]!==_e?(ke=g(De,{"data-testid":"sc-editor",size:"sm",children:[xe,_e]}),e[80]=xe,e[81]=_e,e[82]=ke):ke=e[82],ke};function wt(s){return l("option",{value:s,children:s},s)}function St(s){return l("option",{value:s.validator,children:s.label},s.validator)}function _t(s){return l("option",{value:s,children:s},s)}const Xe=[],$t=s=>{const e=we(5),{open:m}=s,n=m&&"rotate-90";let t;e[0]!==n?(t=We("size-3.5 shrink-0 text-muted-foreground transition-transform duration-150",n),e[0]=n,e[1]=t):t=e[1];let a;e[2]===Symbol.for("react.memo_cache_sentinel")?(a=l("path",{d:"m9 6 6 6-6 6"}),e[2]=a):a=e[2];let d;return e[3]!==t?(d=l("svg",{"aria-hidden":"true",className:t,fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.8,viewBox:"0 0 24 24",children:a}),e[3]=t,e[4]=d):d=e[4],d},Ye=s=>{const e=we(20),{children:m,expanded:n,name:t,onToggle:a,rowCount:d,rowTestId:o,toggleTestId:i}=s;let u;e[0]!==n?(u=l($t,{open:n}),e[0]=n,e[1]=u):u=e[1];let c;e[2]!==t?(c=l("span",{className:"truncate font-mono text-xs text-foreground",title:t,children:t}),e[2]=t,e[3]=c):c=e[3];let r;e[4]!==d?(r=g("span",{className:"ms-auto shrink-0 text-xs text-muted-foreground tabular-nums",children:["(",d,")"]}),e[4]=d,e[5]=r):r=e[5];let b;e[6]!==n||e[7]!==a||e[8]!==u||e[9]!==c||e[10]!==r||e[11]!==i?(b=g("button",{"aria-expanded":n,className:"flex w-full items-center gap-2 px-3 py-2 text-start transition-colors hover:bg-muted/50 aria-expanded:bg-muted/40","data-testid":i,onClick:a,type:"button",children:[u,c," ",r]}),e[6]=n,e[7]=a,e[8]=u,e[9]=c,e[10]=r,e[11]=i,e[12]=b):b=e[12];let N;e[13]!==m||e[14]!==n?(N=n&&l("div",{className:"px-3 pb-3 ps-8",children:m}),e[13]=m,e[14]=n,e[15]=N):N=e[15];let h;return e[16]!==o||e[17]!==b||e[18]!==N?(h=g("li",{className:"border-t border-border/60 first:border-t-0","data-testid":o,children:[b,N]}),e[16]=o,e[17]=b,e[18]=N,e[19]=h):h=e[19],h},He=s=>{const e=we(5),{columns:m,testId:n}=s;let t;e[0]!==m?(t=m.map(It),e[0]=m,e[1]=t):t=e[1];let a;return e[2]!==t||e[3]!==n?(a=l("ul",{className:"flex flex-wrap gap-1.5 pt-1","data-testid":n,children:t}),e[2]=t,e[3]=n,e[4]=a):a=e[4],a},kt=s=>{const e=we(10),{heading:m,indexes:n,testId:t}=s;let a;e[0]!==m?(a=l("p",{className:"mb-1.5 font-mono text-[10px] tracking-wide text-muted-foreground uppercase",children:m}),e[0]=m,e[1]=a):a=e[1];let d;e[2]!==n?(d=n.map(At),e[2]=n,e[3]=d):d=e[3];let o;e[4]!==d||e[5]!==t?(o=l("ul",{className:"flex flex-col gap-1","data-testid":t,children:d}),e[4]=d,e[5]=t,e[6]=o):o=e[6];let i;return e[7]!==a||e[8]!==o?(i=g("div",{className:"pt-3",children:[a,o]}),e[7]=a,e[8]=o,e[9]=i):i=e[9],i},Je=s=>We("border-b-2 px-3 py-2 font-mono text-[11px] tracking-widest uppercase outline-none transition-colors",s?"border-foreground text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),Qt=s=>{const e=we(85),{initialShardKey:m,initialTable:n,schemaEditable:t}=s,a=ze();let d;e[0]!==m||e[1]!==n?(d={initialShardKey:m,initialTable:n},e[0]=m,e[1]=n,e[2]=d):d=e[2];const{columns:o,diagramTables:i,error:u,expanded:c,filteredGlobalTables:r,filteredTables:b,globalColumns:N,globalError:h,globalExpanded:F,globalTables:w,indexes:ce,refresh:x,setShardKey:q,setTableFilter:z,setView:A,shardColumnsError:_,shardKey:C,tableFilter:k,tables:P,toggle:Z,toggleGlobal:me,view:I}=mt(d);let v;e[3]!==A?(v=()=>{A("list")},e[3]=A,e[4]=v):v=e[4];const ge=v;let G;e[5]!==A?(G=()=>{A("graph")},e[5]=A,e[6]=G):G=e[6];const ue=G;let ee;e[7]!==z?(ee=f=>{z(f.target.value)},e[7]=z,e[8]=ee):ee=e[8];const U=ee;let Ne;e[9]!==x||e[10]!==C?(Ne=f=>{ye(x(C))},e[9]=x,e[10]=C,e[11]=Ne):Ne=e[11];const X=Ne;let be;e[12]!==P?(be=P??[],e[12]=P,e[13]=be):be=e[13];let Y;e[14]!==be?(Y=be.map(Et),e[14]=be,e[15]=Y):Y=e[15];const te=Y;let L;e[16]!==q||e[17]!==C?(L=l(Qe,{onChange:q,testId:"sc-shard-input",value:C}),e[16]=q,e[17]=C,e[18]=L):L=e[18];let le;e[19]!==a?(le=a("Schema view"),e[19]=a,e[20]=le):le=e[20];const ae=I==="graph",he=I==="graph";let K;e[21]!==he?(K=Je(he),e[21]=he,e[22]=K):K=e[22];let ne;e[23]!==a?(ne=a("Graph"),e[23]=a,e[24]=ne):ne=e[24];let M;e[25]!==ue||e[26]!==ae||e[27]!==K||e[28]!==ne?(M=l("button",{"aria-selected":ae,className:K,"data-testid":"sc-view-graph",onClick:ue,role:"tab",type:"button",children:ne}),e[25]=ue,e[26]=ae,e[27]=K,e[28]=ne,e[29]=M):M=e[29];const se=I==="list",re=I==="list";let pe;e[30]!==re?(pe=Je(re),e[30]=re,e[31]=pe):pe=e[31];let H;e[32]!==a?(H=a("Table list"),e[32]=a,e[33]=H):H=e[33];let J;e[34]!==ge||e[35]!==se||e[36]!==pe||e[37]!==H?(J=l("button",{"aria-selected":se,className:pe,"data-testid":"sc-view-list",onClick:ge,role:"tab",type:"button",children:H}),e[34]=ge,e[35]=se,e[36]=pe,e[37]=H,e[38]=J):J=e[38];let D;e[39]!==M||e[40]!==J||e[41]!==le?(D=g("div",{"aria-label":le,className:"flex items-center gap-1","data-testid":"sc-view-toggle",role:"tablist",children:[M,J]}),e[39]=M,e[40]=J,e[41]=le,e[42]=D):D=e[42];let oe;e[43]!==D||e[44]!==L?(oe=g("div",{className:"flex flex-wrap items-center gap-3",children:[L,D]}),e[43]=D,e[44]=L,e[45]=oe):oe=e[45];let R;e[46]!==X||e[47]!==t||e[48]!==te?(R=t===!0&&l(Tt,{onApplied:X,tableNames:te}),e[46]=X,e[47]=t,e[48]=te,e[49]=R):R=e[49];let ie;e[50]!==U||e[51]!==a||e[52]!==k||e[53]!==I?(ie=I==="list"&&l(Ie,{"aria-label":a("Filter tables"),className:"h-8 max-w-xs","data-testid":"sc-filter",onChange:U,placeholder:a("Filter tables"),value:k}),e[50]=U,e[51]=a,e[52]=k,e[53]=I,e[54]=ie):ie=e[54];let V;e[55]!==i||e[56]!==u||e[57]!==h||e[58]!==_||e[59]!==C||e[60]!==I?(V=I==="graph"&&g("div",{className:"flex flex-col gap-2","data-testid":"sc-graph-view",children:[u!==null&&l("p",{className:"text-sm text-destructive","data-testid":"sc-error",role:"alert",children:u}),h!==null&&l("p",{className:"text-sm text-destructive","data-testid":"sc-global-error",role:"alert",children:h}),l(nt,{columnsError:_[C]===!0,tables:i,testIdPrefix:"sc-graph"})]}),e[55]=i,e[56]=u,e[57]=h,e[58]=_,e[59]=C,e[60]=I,e[61]=V):V=e[61];let j;e[62]!==o||e[63]!==u||e[64]!==c||e[65]!==r||e[66]!==b||e[67]!==N||e[68]!==h||e[69]!==F||e[70]!==w||e[71]!==ce||e[72]!==C||e[73]!==a||e[74]!==P||e[75]!==Z||e[76]!==me||e[77]!==I?(j=I==="list"&&g("div",{className:"flex flex-col gap-4",children:[g(De,{"data-testid":"sc-shard-section",size:"sm",children:[g(Ke,{children:[g("div",{className:"flex items-center gap-2",children:[l(Ve,{tier:"shard"}),l(Ge,{children:a("Shard tables")}),P!==null&&l(Fe,{className:"ms-auto tabular-nums",variant:"outline",children:b.length})]}),l(Le,{children:qe.shard.hint})]}),g(Me,{children:[u!==null&&l("p",{className:"text-sm text-destructive","data-testid":"sc-error",role:"alert",children:u}),P!==null&&P.length===0&&l("p",{className:"text-sm text-muted-foreground","data-testid":"sc-empty",children:a("No tables in this shard.")}),P!==null&&P.length>0&&b.length===0&&l("p",{className:"text-sm text-muted-foreground","data-testid":"sc-no-match",children:a("No tables match your filter.")}),b.length>0&&l("ul",{className:"-mx-3 overflow-hidden border-t border-border","data-testid":"sc-table-list",children:b.map(f=>{const Q=`${C}:${f.name}`,de=ce[Q]??[];return g(Ye,{expanded:c===f.name,name:f.name,onToggle:()=>{ye(Z(f.name))},rowCount:f.rowCount,rowTestId:`sc-table-${f.name}`,toggleTestId:`sc-toggle-${f.name}`,children:[l(He,{columns:o[Q]??Xe,testId:`sc-columns-${f.name}`}),de.length>0&&l(kt,{heading:a("Indexes"),indexes:de,testId:`sc-indexes-${f.name}`})]},f.name)})})]})]}),g(De,{"data-testid":"sc-global-section",size:"sm",children:[g(Ke,{children:[g("div",{className:"flex items-center gap-2",children:[l(Ve,{tier:"global"}),l(Ge,{children:a("Global tables (D1)")}),w!==null&&l(Fe,{className:"ms-auto tabular-nums",variant:"outline",children:r.length})]}),l(Le,{children:qe.global.hint})]}),g(Me,{children:[h!==null&&l("p",{className:"text-sm text-destructive","data-testid":"sc-global-error",role:"alert",children:h}),w!==null&&w.length===0&&l(Ze,{description:qe.global.hint,testId:"sc-global-empty",title:a("No global tables.")}),w!==null&&w.length>0&&r.length===0&&l("p",{className:"text-sm text-muted-foreground","data-testid":"sc-global-no-match",children:a("No tables match your filter.")}),r.length>0&&l("ul",{className:"-mx-3 overflow-hidden border-t border-border","data-testid":"sc-global-table-list",children:r.map(f=>l(Ye,{expanded:F===f.name,name:f.name,onToggle:()=>{ye(me(f.name))},rowCount:f.rowCount,rowTestId:`sc-global-table-${f.name}`,toggleTestId:`sc-global-toggle-${f.name}`,children:l(He,{columns:N[f.name]??Xe,testId:`sc-global-columns-${f.name}`})},f.name))})]})]})]}),e[62]=o,e[63]=u,e[64]=c,e[65]=r,e[66]=b,e[67]=N,e[68]=h,e[69]=F,e[70]=w,e[71]=ce,e[72]=C,e[73]=a,e[74]=P,e[75]=Z,e[76]=me,e[77]=I,e[78]=j):j=e[78];let W;return e[79]!==oe||e[80]!==R||e[81]!==ie||e[82]!==V||e[83]!==j?(W=g("div",{className:"flex flex-col gap-4","data-testid":"lunora-schema",children:[oe,R,ie,V,j]}),e[79]=oe,e[80]=R,e[81]=ie,e[82]=V,e[83]=j,e[84]=W):W=e[84],W};function It(s){return l("li",{className:"rounded bg-muted px-1.5 py-0.5 font-mono text-[11px] text-muted-foreground",children:s},s)}function At(s){return g("li",{className:"flex flex-wrap items-center gap-1.5 text-xs",children:[l("span",{className:"font-mono",children:s.name}),l(Fe,{variant:"outline",children:s.type}),s.unique===!0&&l(Fe,{variant:"secondary",children:"unique"}),l("span",{className:"text-muted-foreground",children:s.fields.join(", ")})]},`${s.type}:${s.name}`)}function Et(s){return s.name}export{Qt as SchemaViewer};
@@ -1 +1 @@
1
- import{c as u}from"react/compiler-runtime";import{N as m}from"../packem_shared/use-admin-query-QJ-ibl5u.js";import{useT as h}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as f}from"../packem_shared/ADMIN_FUNCTIONS-BnD4aovm.js";import{A as g}from"../packem_shared/advisor-view-Pa8HLtBv.js";import{jsx as p}from"react/jsx-runtime";const R=(e,s)=>({"admin-token-weak":e("Weak admin token"),"auth-secret-weak":e("Weak auth secret"),"cookies-insecure":e("Session cookies are not Secure"),"cors-wildcard-credentials":e("Wildcard CORS with credentials"),"csrf-disabled":e("CSRF/origin guard is off"),"dev-args-unredacted":e("Request log keeps un-redacted args"),"security-headers-disabled":e("Security headers are off"),"ws-gate-open":e("Live admin subscriptions are ungated")})[s.kind],k=e=>Array.isArray(e.findings)?e.findings:[],S=e=>({"admin-token-weak":"LUNORA_ADMIN_TOKEN","auth-secret-weak":"AUTH_SECRET","cookies-insecure":"BETTER_AUTH_URL","cors-wildcard-credentials":"LUNORA_ALLOWED_ORIGINS","csrf-disabled":"LUNORA_SECURITY_CSRF","dev-args-unredacted":"request log","security-headers-disabled":"LUNORA_SECURITY_HEADERS","ws-gate-open":"LUNORA_WS_BEARER"})[e.kind],A=(e,s)=>({"admin-token-weak":e("Your admin token is {length} characters — use at least {min} for a brute-force-resistant secret.",{length:s.detail?.length,min:s.detail?.min}),"auth-secret-weak":e("Your auth secret is {length} characters — use at least {min} (e.g. `openssl rand -hex 32`) to sign sessions safely.",{length:s.detail?.length,min:s.detail?.min}),"cookies-insecure":e("BETTER_AUTH_URL is a plaintext http:// origin, so session cookies cannot be Secure and ride in cleartext. Serve auth over https:// in production."),"cors-wildcard-credentials":e("LUNORA_ALLOWED_ORIGINS includes a wildcard while credentials are allowed — browsers reject this and it defeats the allowlist. Name explicit origins instead of *."),"csrf-disabled":e("LUNORA_SECURITY_CSRF is off, so cross-origin state-changing cookie requests are not blocked. Re-enable it in production to keep mutations un-forgeable."),"dev-args-unredacted":e("This worker reports a development environment, so the request log stores raw args and identity. Confirm it isn't a mislabeled production deploy."),"security-headers-disabled":e("LUNORA_SECURITY_HEADERS is off, so HSTS, CSP, nosniff, and frame-options are not applied. Re-enable the baseline headers in production."),"ws-gate-open":e("LUNORA_WS_BEARER is unset, so the WebSocket upgrade gate is open: live admin subscriptions need no credential. Set it to gate them like the HTTP admin RPCs.")})[s.kind],N=()=>{const e=u(8),s=h();let t;e[0]===Symbol.for("react.memo_cache_sentinel")?(t={},e[0]=t):t=e[0];const{data:i,error:n,errorSource:d}=m(f.getSecurityAudit,t);let a;if(e[1]!==i||e[2]!==s){const l=i===void 0?null:k(i);a=l===null?null:l.map(r=>({description:A(s,r),entity:S(r),issueType:R(s,r),key:r.kind,level:r.level})),e[1]=i,e[2]=s,e[3]=a}else a=e[3];const c=a;let o;return e[4]!==n||e[5]!==d||e[6]!==c?(o=p(g,{error:n,errorSource:d,rows:c,testId:"lunora-security-advisor"}),e[4]=n,e[5]=d,e[6]=c,e[7]=o):o=e[7],o};export{N as default};
1
+ import{c as u}from"react/compiler-runtime";import{N as m}from"../packem_shared/use-admin-query-QJ-ibl5u.js";import{useT as h}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as f}from"../packem_shared/ADMIN_FUNCTIONS-CZESgd10.js";import{A as g}from"../packem_shared/advisor-view-Pa8HLtBv.js";import{jsx as p}from"react/jsx-runtime";const R=(e,s)=>({"admin-token-weak":e("Weak admin token"),"auth-secret-weak":e("Weak auth secret"),"cookies-insecure":e("Session cookies are not Secure"),"cors-wildcard-credentials":e("Wildcard CORS with credentials"),"csrf-disabled":e("CSRF/origin guard is off"),"dev-args-unredacted":e("Request log keeps un-redacted args"),"security-headers-disabled":e("Security headers are off"),"ws-gate-open":e("Live admin subscriptions are ungated")})[s.kind],k=e=>Array.isArray(e.findings)?e.findings:[],S=e=>({"admin-token-weak":"LUNORA_ADMIN_TOKEN","auth-secret-weak":"AUTH_SECRET","cookies-insecure":"BETTER_AUTH_URL","cors-wildcard-credentials":"LUNORA_ALLOWED_ORIGINS","csrf-disabled":"LUNORA_SECURITY_CSRF","dev-args-unredacted":"request log","security-headers-disabled":"LUNORA_SECURITY_HEADERS","ws-gate-open":"LUNORA_WS_BEARER"})[e.kind],A=(e,s)=>({"admin-token-weak":e("Your admin token is {length} characters — use at least {min} for a brute-force-resistant secret.",{length:s.detail?.length,min:s.detail?.min}),"auth-secret-weak":e("Your auth secret is {length} characters — use at least {min} (e.g. `openssl rand -hex 32`) to sign sessions safely.",{length:s.detail?.length,min:s.detail?.min}),"cookies-insecure":e("BETTER_AUTH_URL is a plaintext http:// origin, so session cookies cannot be Secure and ride in cleartext. Serve auth over https:// in production."),"cors-wildcard-credentials":e("LUNORA_ALLOWED_ORIGINS includes a wildcard while credentials are allowed — browsers reject this and it defeats the allowlist. Name explicit origins instead of *."),"csrf-disabled":e("LUNORA_SECURITY_CSRF is off, so cross-origin state-changing cookie requests are not blocked. Re-enable it in production to keep mutations un-forgeable."),"dev-args-unredacted":e("This worker reports a development environment, so the request log stores raw args and identity. Confirm it isn't a mislabeled production deploy."),"security-headers-disabled":e("LUNORA_SECURITY_HEADERS is off, so HSTS, CSP, nosniff, and frame-options are not applied. Re-enable the baseline headers in production."),"ws-gate-open":e("LUNORA_WS_BEARER is unset, so the WebSocket upgrade gate is open: live admin subscriptions need no credential. Set it to gate them like the HTTP admin RPCs.")})[s.kind],N=()=>{const e=u(8),s=h();let t;e[0]===Symbol.for("react.memo_cache_sentinel")?(t={},e[0]=t):t=e[0];const{data:i,error:n,errorSource:d}=m(f.getSecurityAudit,t);let a;if(e[1]!==i||e[2]!==s){const l=i===void 0?null:k(i);a=l===null?null:l.map(r=>({description:A(s,r),entity:S(r),issueType:R(s,r),key:r.kind,level:r.level})),e[1]=i,e[2]=s,e[3]=a}else a=e[3];const c=a;let o;return e[4]!==n||e[5]!==d||e[6]!==c?(o=p(g,{error:n,errorSource:d,rows:c,testId:"lunora-security-advisor"}),e[4]=n,e[5]=d,e[6]=c,e[7]=o):o=e[7],o};export{N as default};
@@ -1 +1 @@
1
- import{c as O}from"react/compiler-runtime";import{E as A}from"../packem_shared/error-alert-t6cpEi0z.js";import{g as K}from"../packem_shared/badge-BbuuAio7.js";import{c as I,u as L}from"../packem_shared/card-CIDGUN6K.js";import{n as j,d as F,m as C,p as T,f as V,u as U}from"../packem_shared/table-DdJBrClo.js";import{N as W}from"../packem_shared/use-admin-query-QJ-ibl5u.js";import{useT as q}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as z}from"../packem_shared/ADMIN_FUNCTIONS-BnD4aovm.js";import{a as M}from"../packem_shared/cf-links-gbDy51nR.js";import{jsx as t,jsxs as m}from"react/jsx-runtime";const P={binding:"outline",secret:"destructive",var:"secondary"},B=(r,e)=>{if(r===void 0)return[];const c=[];return r.workerUrl!==void 0&&c.push({label:e("URL"),value:r.workerUrl}),r.environment!==void 0&&c.push({label:e("Environment"),value:r.environment}),r.deploymentId!==void 0&&c.push({label:e("Deployment"),value:r.deploymentId}),r.versionTag!==void 0&&c.push({label:e("Version"),value:r.versionTag}),c},le=r=>{const e=O(52),{initialShardKey:c}=r,n=q();let w;e[0]===Symbol.for("react.memo_cache_sentinel")?(w={},e[0]=w):w=e[0];const _=c??"";let $;e[1]!==_?($={shardKey:_},e[1]=_,e[2]=$):$=e[2];const{data:l,error:s,errorSource:k,isLoading:R}=W(z.getSettings,w,$);let a,p,u,d,o,i,h;if(e[3]!==s||e[4]!==k||e[5]!==l?.deploy||e[6]!==l?.settings||e[7]!==n){const D=B(l?.deploy,n);let S;e[15]!==l?.settings?(S=l?.settings??[],e[15]=l?.settings,e[16]=S):S=e[16],a=S,p="flex flex-col gap-4",u="lunora-settings";let N;e[17]!==n?(N=n("Open in Cloudflare"),e[17]=n,e[18]=N):N=e[18],e[19]!==N?(d=t("div",{className:"flex flex-wrap items-center gap-3",children:t("a",{className:"text-sm text-primary underline-offset-4 hover:underline","data-testid":"set-cf-link",href:M,rel:"noreferrer",target:"_blank",children:N})}),e[19]=N,e[20]=d):d=e[20];let b;e[21]!==n?(b=n("View-only — values are masked. Edit vars, secrets, and bindings in wrangler or the Cloudflare dashboard."),e[21]=n,e[22]=b):b=e[22],e[23]!==b?(o=t("p",{className:"text-sm text-muted-foreground","data-testid":"set-readonly-note",children:b}),e[23]=b,e[24]=o):o=e[24],e[25]!==s||e[26]!==k?(i=s!==null&&t(A,{error:k,testId:"set-error"}),e[25]=s,e[26]=k,e[27]=i):i=e[27],h=D.length>0&&m(I,{className:"py-0","data-testid":"set-deploy",children:[t("header",{className:"border-b border-border px-4 py-3",children:t("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:n("Deployment")})}),t(L,{className:"py-3",children:t("dl",{className:"grid grid-cols-[8rem_minmax(0,1fr)] gap-x-4 gap-y-1 text-sm",children:D.map(G)})})]}),e[3]=s,e[4]=k,e[5]=l?.deploy,e[6]=l?.settings,e[7]=n,e[8]=a,e[9]=p,e[10]=u,e[11]=d,e[12]=o,e[13]=i,e[14]=h}else a=e[8],p=e[9],u=e[10],d=e[11],o=e[12],i=e[13],h=e[14];let f;e[28]!==n?(f=n("Environment & bindings"),e[28]=n,e[29]=f):f=e[29];let g;e[30]!==f?(g=t("header",{className:"border-b border-border px-4 py-3",children:t("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:f})}),e[30]=f,e[31]=g):g=e[31];let x;e[32]!==s||e[33]!==R||e[34]!==a.length||e[35]!==n?(x=s===null&&!R&&a.length===0&&t("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground","data-testid":"set-empty",children:n("No environment variables or bindings.")}),e[32]=s,e[33]=R,e[34]=a.length,e[35]=n,e[36]=x):x=e[36];let v;e[37]!==a||e[38]!==n?(v=a.length>0&&t(L,{className:"px-0 py-0",children:m(j,{"data-testid":"set-table",children:[t(F,{children:m(C,{children:[t(T,{children:n("name")}),t(T,{children:n("kind")}),t(T,{children:n("value")})]})}),t(V,{children:a.map(H)})]})}),e[37]=a,e[38]=n,e[39]=v):v=e[39];let y;e[40]!==g||e[41]!==x||e[42]!==v?(y=m(I,{className:"py-0",children:[g,x,v]}),e[40]=g,e[41]=x,e[42]=v,e[43]=y):y=e[43];let E;return e[44]!==y||e[45]!==p||e[46]!==u||e[47]!==d||e[48]!==o||e[49]!==i||e[50]!==h?(E=m("div",{className:p,"data-testid":u,children:[d,o,i,h,y]}),e[44]=y,e[45]=p,e[46]=u,e[47]=d,e[48]=o,e[49]=i,e[50]=h,e[51]=E):E=e[51],E};function G(r){return m("div",{className:"contents","data-testid":"set-deploy-row",children:[t("dt",{className:"text-muted-foreground",children:r.label}),t("dd",{className:"truncate font-mono text-xs",title:r.value,children:r.value})]},r.label)}function H(r){return m(C,{"data-testid":"set-row",children:[t(U,{className:"font-mono text-xs font-medium",children:r.name}),t(U,{children:t(K,{variant:P[r.kind],children:r.bindingType??r.kind})}),t(U,{className:"max-w-[28ch] truncate font-mono text-xs text-muted-foreground",children:r.value??t("span",{className:"text-muted-foreground",children:"—"})})]},r.name)}export{le as SettingsPanel};
1
+ import{c as O}from"react/compiler-runtime";import{E as A}from"../packem_shared/error-alert-t6cpEi0z.js";import{g as K}from"../packem_shared/badge-BbuuAio7.js";import{c as D,u as I}from"../packem_shared/card-CIDGUN6K.js";import{n as j,d as F,m as L,p as T,f as V,u as U}from"../packem_shared/table-DdJBrClo.js";import{N as W}from"../packem_shared/use-admin-query-QJ-ibl5u.js";import{useT as q}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as z}from"../packem_shared/ADMIN_FUNCTIONS-CZESgd10.js";import{C as M}from"../packem_shared/cf-links-Dmg86v1D.js";import{jsx as t,jsxs as m}from"react/jsx-runtime";const P={binding:"outline",secret:"destructive",var:"secondary"},B=(r,e)=>{if(r===void 0)return[];const c=[];return r.workerUrl!==void 0&&c.push({label:e("URL"),value:r.workerUrl}),r.environment!==void 0&&c.push({label:e("Environment"),value:r.environment}),r.deploymentId!==void 0&&c.push({label:e("Deployment"),value:r.deploymentId}),r.versionTag!==void 0&&c.push({label:e("Version"),value:r.versionTag}),c},le=r=>{const e=O(52),{initialShardKey:c}=r,n=q();let w;e[0]===Symbol.for("react.memo_cache_sentinel")?(w={},e[0]=w):w=e[0];const _=c??"";let $;e[1]!==_?($={shardKey:_},e[1]=_,e[2]=$):$=e[2];const{data:l,error:s,errorSource:k,isLoading:R}=W(z.getSettings,w,$);let a,p,u,d,o,i,h;if(e[3]!==s||e[4]!==k||e[5]!==l?.deploy||e[6]!==l?.settings||e[7]!==n){const C=B(l?.deploy,n);let S;e[15]!==l?.settings?(S=l?.settings??[],e[15]=l?.settings,e[16]=S):S=e[16],a=S,p="flex flex-col gap-4",u="lunora-settings";let N;e[17]!==n?(N=n("Open in Cloudflare"),e[17]=n,e[18]=N):N=e[18],e[19]!==N?(d=t("div",{className:"flex flex-wrap items-center gap-3",children:t("a",{className:"text-sm text-primary underline-offset-4 hover:underline","data-testid":"set-cf-link",href:M,rel:"noreferrer",target:"_blank",children:N})}),e[19]=N,e[20]=d):d=e[20];let b;e[21]!==n?(b=n("View-only — values are masked. Edit vars, secrets, and bindings in wrangler or the Cloudflare dashboard."),e[21]=n,e[22]=b):b=e[22],e[23]!==b?(o=t("p",{className:"text-sm text-muted-foreground","data-testid":"set-readonly-note",children:b}),e[23]=b,e[24]=o):o=e[24],e[25]!==s||e[26]!==k?(i=s!==null&&t(A,{error:k,testId:"set-error"}),e[25]=s,e[26]=k,e[27]=i):i=e[27],h=C.length>0&&m(D,{className:"py-0","data-testid":"set-deploy",children:[t("header",{className:"border-b border-border px-4 py-3",children:t("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:n("Deployment")})}),t(I,{className:"py-3",children:t("dl",{className:"grid grid-cols-[8rem_minmax(0,1fr)] gap-x-4 gap-y-1 text-sm",children:C.map(G)})})]}),e[3]=s,e[4]=k,e[5]=l?.deploy,e[6]=l?.settings,e[7]=n,e[8]=a,e[9]=p,e[10]=u,e[11]=d,e[12]=o,e[13]=i,e[14]=h}else a=e[8],p=e[9],u=e[10],d=e[11],o=e[12],i=e[13],h=e[14];let f;e[28]!==n?(f=n("Environment & bindings"),e[28]=n,e[29]=f):f=e[29];let g;e[30]!==f?(g=t("header",{className:"border-b border-border px-4 py-3",children:t("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:f})}),e[30]=f,e[31]=g):g=e[31];let x;e[32]!==s||e[33]!==R||e[34]!==a.length||e[35]!==n?(x=s===null&&!R&&a.length===0&&t("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground","data-testid":"set-empty",children:n("No environment variables or bindings.")}),e[32]=s,e[33]=R,e[34]=a.length,e[35]=n,e[36]=x):x=e[36];let v;e[37]!==a||e[38]!==n?(v=a.length>0&&t(I,{className:"px-0 py-0",children:m(j,{"data-testid":"set-table",children:[t(F,{children:m(L,{children:[t(T,{children:n("name")}),t(T,{children:n("kind")}),t(T,{children:n("value")})]})}),t(V,{children:a.map(H)})]})}),e[37]=a,e[38]=n,e[39]=v):v=e[39];let y;e[40]!==g||e[41]!==x||e[42]!==v?(y=m(D,{className:"py-0",children:[g,x,v]}),e[40]=g,e[41]=x,e[42]=v,e[43]=y):y=e[43];let E;return e[44]!==y||e[45]!==p||e[46]!==u||e[47]!==d||e[48]!==o||e[49]!==i||e[50]!==h?(E=m("div",{className:p,"data-testid":u,children:[d,o,i,h,y]}),e[44]=y,e[45]=p,e[46]=u,e[47]=d,e[48]=o,e[49]=i,e[50]=h,e[51]=E):E=e[51],E};function G(r){return m("div",{className:"contents","data-testid":"set-deploy-row",children:[t("dt",{className:"text-muted-foreground",children:r.label}),t("dd",{className:"truncate font-mono text-xs",title:r.value,children:r.value})]},r.label)}function H(r){return m(L,{"data-testid":"set-row",children:[t(U,{className:"font-mono text-xs font-medium",children:r.name}),t(U,{children:t(K,{variant:P[r.kind],children:r.bindingType??r.kind})}),t(U,{className:"max-w-[28ch] truncate font-mono text-xs text-muted-foreground",children:r.value??t("span",{className:"text-muted-foreground",children:"—"})})]},r.name)}export{le as SettingsPanel};
@@ -1,6 +1,6 @@
1
- import{c as J}from"react/compiler-runtime";import{useLunora as ul}from"@lunora/react";import{useState as Q,useMemo as fl,useCallback as Dl,useEffect as An,useRef as Dt,useId as Al}from"react";import{I as zl}from"../packem_shared/result-chart-DzJOVsaw.js";import{ShardInput as jl}from"../packem_shared/ShardInput-BVn2iCU0.js";import{A as Bl}from"../packem_shared/alert-CVcOFuDR.js";import{d as Wl,m as hl,f as Fl,n as Pl,p as Hl,u as Ul}from"../packem_shared/table-DdJBrClo.js";import{useT as se}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as zn}from"../packem_shared/ADMIN_FUNCTIONS-BnD4aovm.js";import{u as cl,n as yl,b as wl}from"../packem_shared/browser-storage-xjTyMKY0.js";import{d as Mn,f as fe,g as jn,b as pl}from"../packem_shared/internal-BSIsQVC6.js";import{r as Yl}from"../packem_shared/shard-history-DMEW5VBE.js";import{g as Kl}from"../packem_shared/data-grid-DcxyIXwG.js";import{K as Ql}from"../packem_shared/grid-features-jnrD0SpX.js";import{k as Jl}from"../packem_shared/use-sql-assistant-CHEu2-Rk.js";import Gl from"../packem_shared/useDebounced-Ihdiid_k.js";import{u as Vl}from"../packem_shared/input-JHu63lTv.js";import{c as ve}from"../packem_shared/utils-bhneXptQ.js";import{jsx as i,jsxs as $,Fragment as bl}from"react/jsx-runtime";const Nl="p-3 font-mono text-xs leading-5 whitespace-pre-wrap break-words",Xl=(r,e)=>{const l=[];for(const t of r){if(t.offset===void 0||t.length===void 0||t.length<=0)continue;const o=Math.max(0,Math.min(t.offset,e)),a=Math.max(o,Math.min(t.offset+t.length,e));o!==a&&l.push({end:a,severity:t.severity,start:o})}l.sort((t,o)=>t.start-o.start);const n=[];for(const t of l)t.start>=(n.at(-1)?.end??0)&&n.push(t);return n},Zl=["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"],er=["FROM","WHERE","ORDER BY","GROUP BY","HAVING","LIMIT","OFFSET","UNION","JOIN","LEFT JOIN","RIGHT JOIN","INNER JOIN","OUTER JOIN","CROSS JOIN"],Dn=String.fromCodePoint(0),tr=new RegExp(`${Dn}${String.raw`(\d+)`}${Dn}`,"gu"),nr=Zl.map(r=>({pattern:new RegExp(String.raw`\b${r.replaceAll(" ",String.raw`\s+`)}\b`,"giu"),replacement:r})),lr=er.map(r=>({pattern:new RegExp(String.raw`\s+${r.replaceAll(" ",String.raw`\s+`)}\b`,"gu"),replacement:`
2
- ${r}`})),rr=r=>{const e=[];let l=r.replaceAll(/'(?:[^']|'')*'/gu,n=>(e.push(n),`${Dn}${(e.length-1).toString()}${Dn}`)).replaceAll(/\s+/gu," ").trim();for(const{pattern:n,replacement:t}of nr)l=l.replaceAll(n,t);for(const{pattern:n,replacement:t}of lr)l=l.replaceAll(n,t);return l=l.replaceAll(tr,(n,t)=>e[Number(t)]??""),l},or=/^(?:explain\s+(?:query\s+plan\s+)?)?(?:select|with)\b/iu,sr=/\b(?:alter|attach|create|delete|detach|drop|insert|pragma|reindex|replace|truncate|update|vacuum)\b/iu,ar=/^\w+/u,ir=/;\s*$/u,cr=/\s/u,dr=(r,e)=>{let l=e+2;for(;l<r.length&&r[l]!==`
3
- `;)l+=1;return l},ur=(r,e)=>{const l=r.indexOf("*/",e+2);return l===-1?-1:l+2},mr=r=>{let e=0;for(;e<r.length;){const l=r[e];if(l!==void 0&&cr.test(l))e+=1;else if(l==="-"&&r[e+1]==="-")e=dr(r,e);else if(l==="/"&&r[e+1]==="*"){const n=ur(r,e);if(n===-1)break;e=n}else break}return e},fr=r=>{const e=mr(r),l=r.slice(e).trimEnd();if(l==="")return{code:"SQL_EMPTY",message:"the query is empty"};const n=l.replace(ir,""),t=n.indexOf(";");if(t!==-1)return{code:"SQL_MULTIPLE_STATEMENTS",length:1,message:"only a single statement may be run",offset:e+t};const o="the SQL editor is read-only — only SELECT / WITH / EXPLAIN queries are allowed";if(!or.test(n))return{code:"SQL_NOT_READONLY",length:ar.exec(n)?.[0].length??1,message:o,offset:e};const a=sr.exec(n);if(a!==null)return{code:"SQL_NOT_READONLY",length:a[0].length,message:`${o} (\`${a[0].toUpperCase()}\` is not allowed)`,offset:e+a.index}},hr=/\b(?:from|join)\s+([a-z_][\w$]*)(?:\s+(?:as\s+)?([a-z_][\w$]*))?/giu,pr=/(?:\bwith\s+(?:recursive\s+)?|,\s*)([a-z_][\w$]*)\s+as\s*\(/giu,br=new Set(["cross","full","group","having","inner","join","left","limit","offset","on","order","right","union","using","where","window"]),gr=/[^\n]/gu,xr=(r,e)=>{const l=r[e];if(l==="'"){let n=e+1;for(;n<r.length&&r[n]!=="'";)n+=1;return Math.min(n+1,r.length)}if(l==="-"&&r[e+1]==="-"){const n=r.indexOf(`
4
- `,e);return n===-1?r.length:n}if(l==="/"&&r[e+1]==="*"){const n=r.indexOf("*/",e+2);return n===-1?r.length:n+2}return-1},vr=r=>{let e="",l=0;for(;l<r.length;){const n=xr(r,l);n===-1?(e+=r.slice(l,l+1),l+=1):(e+=r.slice(l,n).replaceAll(gr," "),l=n)}return e},yr=r=>{const e=new Set;for(const l of r.matchAll(pr))e.add((l[1]??"").toLowerCase());return e},wr=(r,e)=>{const l=new Map;for(const n of r.matchAll(hr)){const t=(n[1]??"").toLowerCase(),o=(n[2]??"").toLowerCase();e.has(t)&&(l.set(t,t),o!==""&&!br.has(o)&&l.set(o,t))}return l},kl=(r,e)=>{const l=vr(r),n=new Set(e.map(t=>t.toLowerCase()));return{ctes:yr(l),masked:l,targets:wr(l,n)}},Nr=/^(?:__lunora|sqlite_)/iu,kr=/\b(?:from|join)\s+([a-z_][\w$]*)/giu,Sr=/\b([a-z_][\w$]*)\.([a-z_][\w$]*)/giu,qr=new Set(["cross","full","group","having","inner","join","lateral","left","limit","offset","order","right","select","union","where","window"]),$r=(r,e,l)=>{const n=[];for(const t of r.matchAll(kr)){const o=t[1]??"",a=o.toLowerCase();!e.has(a)&&!l.has(a)&&!qr.has(a)&&!Nr.test(o)&&n.push({length:o.length,message:`unknown table \`${o}\``,offset:t.index+t[0].length-o.length,severity:"error",source:"schema"})}return n},Cr=(r,e,l)=>{const n=[],t=new Map;for(const[o,a]of Object.entries(e.columns))t.set(o.toLowerCase(),new Set(a.map(m=>m.toLowerCase())));for(const o of r.matchAll(Sr)){const a=(o[1]??"").toLowerCase(),m=o[2]??"",s=l.get(a),c=s===void 0?void 0:t.get(s);c!==void 0&&!c.has(m.toLowerCase())&&n.push({length:m.length,message:`\`${s??""}\` has no column \`${m}\``,offset:o.index+o[0].length-m.length,severity:"error",source:"schema"})}return n},Lr=(r,e)=>{if(r.trim()==="")return[];const l=fr(r);if(l!==void 0)return l.code==="SQL_EMPTY"?[]:[{length:l.length,message:l.message,offset:l.offset,severity:"error",source:"gate"}];const{ctes:n,masked:t,targets:o}=kl(r,e.tables),a=new Set(e.tables.map(m=>m.toLowerCase()));return[...$r(t,a,n),...Cr(t,e,o)]},Er=jn(zn.lintSql),_r=600,Ir=(r,e,l)=>{const n=ul(),[t,o]=Q([]),a=fl(()=>Lr(r,e),[r,e]),m=Gl(r,_r),s=a.some(b=>b.source==="gate")||m.trim()==="",c=Dl(async b=>{try{const h=await n.query(Er,{sql:m},Mn(l));b.cancelled||o(h.diagnostics??[])}catch{b.cancelled||o([])}},[n,m,l]);An(()=>{if(s){o([]);return}const b={cancelled:!1};return fe(c(b)),()=>{b.cancelled=!0}},[c,s]);const p=m===r;return fl(()=>p?[...a,...t]:a,[a,t,p])},Tr=r=>r==="unsafe-response"?"The model returned a statement that is not read-only, so it was discarded.":r==="empty-response"?"The model returned nothing usable.":"The model could not be reached.",Rr=r=>{const e=J(51),{assistant:l,failed:n,onGenerated:t}=r,o=se(),[a,m]=Q("");if(l.unavailable)return null;let s;e[0]!==l?(s=l.pending("sql"),e[0]=l,e[1]=s):s=e[1];const c=s;let p;if(e[2]!==l||e[3]!==n||e[4]!==t||e[5]!==c||e[6]!==a||e[7]!==o){const b=l.reason("sql");let h;e[9]!==l||e[10]!==n||e[11]!==t||e[12]!==a?(h=L=>{const D=a.trim();D===""&&!L||fe((async()=>{const z=await l.generate(D===""?"fix the failing statement":D,L?n:void 0);z!==void 0&&t(z)})())},e[9]=l,e[10]=n,e[11]=t,e[12]=a,e[13]=h):h=e[13];const f=h;let d;e[14]!==o?(d=o("Describe the query you want"),e[14]=o,e[15]=d):d=e[15];let w;e[16]===Symbol.for("react.memo_cache_sentinel")?(w=L=>{m(L.target.value)},e[16]=w):w=e[16];let y;e[17]!==f?(y=L=>{L.key==="Enter"&&(L.preventDefault(),f(!1))},e[17]=f,e[18]=y):y=e[18];let v;e[19]!==o?(v=o("Describe the query you want"),e[19]=o,e[20]=v):v=e[20];let g;e[21]!==c||e[22]!==a||e[23]!==d||e[24]!==y||e[25]!==v?(g=i(Vl,{"aria-label":d,className:"h-7 flex-1 text-xs","data-testid":"sql-assistant-prompt",disabled:c,onChange:w,onKeyDown:y,placeholder:v,value:a}),e[21]=c,e[22]=a,e[23]=d,e[24]=y,e[25]=v,e[26]=g):g=e[26];const E=c&&"opacity-60";let k;e[27]!==E?(k=ve("rounded-md border border-border px-2 py-1 text-xs outline-none transition-colors hover:bg-accent focus-visible:bg-accent",E),e[27]=E,e[28]=k):k=e[28];let C;e[29]!==c||e[30]!==a?(C=c||a.trim()==="",e[29]=c,e[30]=a,e[31]=C):C=e[31];let q;e[32]!==f?(q=()=>{f(!1)},e[32]=f,e[33]=q):q=e[33];let O;e[34]!==c||e[35]!==o?(O=o(c?"Thinking…":"Draft SQL"),e[34]=c,e[35]=o,e[36]=O):O=e[36];let N;e[37]!==k||e[38]!==C||e[39]!==q||e[40]!==O?(N=i("button",{className:k,"data-testid":"sql-assistant-generate",disabled:C,onClick:q,type:"button",children:O}),e[37]=k,e[38]=C,e[39]=q,e[40]=O,e[41]=N):N=e[41];let M;e[42]!==n||e[43]!==c||e[44]!==f||e[45]!==o?(M=n!==void 0&&i("button",{className:"rounded-md border border-border px-2 py-1 text-xs outline-none transition-colors hover:bg-accent focus-visible:bg-accent","data-testid":"sql-assistant-fix",disabled:c,onClick:()=>{f(!0)},type:"button",children:o("Fix this")}),e[42]=n,e[43]=c,e[44]=f,e[45]=o,e[46]=M):M=e[46];let R;e[47]!==N||e[48]!==M||e[49]!==g?(R=$("div",{className:"flex items-center gap-2",children:[g,N,M]}),e[47]=N,e[48]=M,e[49]=g,e[50]=R):R=e[50],p=$("div",{className:"flex flex-col gap-1 border-b border-border px-3 py-2","data-testid":"sql-assistant",children:[R,b!==void 0&&i("p",{className:"text-[11px] text-muted-foreground","data-testid":"sql-assistant-reason",role:"status",children:Tr(b)})]}),e[2]=l,e[3]=n,e[4]=t,e[5]=c,e[6]=a,e[7]=o,e[8]=p}else p=e[8];return p},Rn=8,Or=["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"],Mr=new Set(["AND","BY","HAVING","ON","OR","SELECT","WHERE"]),Dr=/[\w$]/,Sl=r=>r!==void 0&&Dr.test(r),ql=r=>{let e=r.length;for(;e>0&&Sl(r[e-1]);)e-=1;return r.slice(e)},$l=(r,e)=>{let l=e;for(;l>0&&Sl(r[l-1]);)l-=1;return{end:e,start:l,text:r.slice(l,e)}},gl=(r,e)=>{const l=r.slice(0,e).trimEnd();return l.endsWith(".")||Mr.has(ql(l).toUpperCase())},Ar=(r,e,l)=>{const n=r.slice(0,e);if(!n.endsWith("."))return;const t=ql(n.slice(0,-1));if(t!=="")return kl(r,l).targets.get(t.toLowerCase())??t},ml=(r,e)=>r.toLowerCase().startsWith(e.toLowerCase()),xl=(r,e,l,n)=>{const t=[];for(const o of r)if(ml(o,e)&&(t.push(n(o)),t.length>=l))break;return t},zr=(r,e,l)=>{const n=new Map;for(const[t,o]of Object.entries(r.columns))for(const a of o)if(ml(a,e)&&!n.has(a)&&(n.set(a,t),n.size>=l))return[...n].map(([m,s])=>({detail:s,kind:"column",label:m}));return[...n].map(([t,o])=>({detail:o,kind:"column",label:t}))},jr=(r,e,l)=>{const n=$l(r,e),t=Ar(r,n.start,l.tables);if(t!==void 0){const s=l.columns[t]??l.columns[t.toLowerCase()]??[];return xl(s,n.text,Rn,c=>({detail:t,kind:"column",label:c}))}if(n.text===""&&!gl(r,n.start))return[];const o=xl(l.tables,n.text,Rn,s=>({kind:"table",label:s})),a=zr(l,n.text,Rn),m=Or.flatMap(s=>n.text!==""&&ml(s,n.text)&&s.toLowerCase()!==n.text.toLowerCase()?[{kind:"keyword",label:s}]:[]);return(gl(r,n.start)?[...a,...o,...m]:[...o,...a,...m]).slice(0,Rn)},Br=(r,e,l)=>{const n=$l(r,e),t=r.slice(0,n.start)+l.label+r.slice(n.end);return{caret:n.start+l.label.length,value:t}},Wr=["boxSizing","borderBottomWidth","borderLeftWidth","borderRightWidth","borderTopWidth","fontFamily","fontSize","fontStyle","fontWeight","letterSpacing","lineHeight","paddingBottom","paddingLeft","paddingRight","paddingTop","tabSize","textIndent","textTransform","width","wordSpacing"],Fr=(r,e)=>{const l=globalThis.getComputedStyle(r),n=globalThis.document.createElement("div"),{style:t}=n;t.position="absolute",t.visibility="hidden",t.whiteSpace="pre-wrap",t.overflowWrap="break-word";for(const s of Wr)t[s]=l[s];n.textContent=r.value.slice(0,Math.max(0,e));const o=globalThis.document.createElement("span");o.textContent=r.value.slice(Math.max(0,e))||".",n.append(o),globalThis.document.body.append(n);const a=o.offsetLeft-r.scrollLeft,m=o.offsetTop-r.scrollTop;return n.remove(),{left:a,top:m}},Pr=(r,e,l)=>{const n=J(13),[t,o]=Q(null);let a;n[0]!==r||n[1]!==e?(a=(w,y)=>{const v=jr(w,y,r);if(v.length===0){o(null);return}const g=e.current,{left:E,top:k}=g===null?{left:0,top:0}:Fr(g,y);o(C=>C!==null&&C.active===0&&C.left===E&&C.top===k&&C.suggestions.length===v.length&&C.suggestions.every((q,O)=>{const N=v.at(O);return q.kind===N?.kind&&q.label===N.label&&q.detail===N.detail})?C:{active:0,left:E,suggestions:v,top:k})},n[0]=r,n[1]=e,n[2]=a):a=n[2];const m=a;let s;n[3]===Symbol.for("react.memo_cache_sentinel")?(s=()=>{o(null)},n[3]=s):s=n[3];const c=s;let p;n[4]===Symbol.for("react.memo_cache_sentinel")?(p=w=>{o(y=>{if(y===null)return y;const v=y.suggestions.length,g=(y.active+w+v)%v;return{...y,active:g}})},n[4]=p):p=n[4];const b=p;let h;n[5]!==l||n[6]!==t||n[7]!==e?(h=()=>{const w=e.current;if(t===null||w===null)return!1;const y=t.suggestions[t.active];if(y===void 0)return!1;const v=Br(w.value,w.selectionStart,y);return l(v.value),o(null),requestAnimationFrame(()=>{const g=e.current;g!==null&&(g.focus(),g.setSelectionRange(v.caret,v.caret))}),!0},n[5]=l,n[6]=t,n[7]=e,n[8]=h):h=n[8];const f=h;let d;return n[9]!==f||n[10]!==m||n[11]!==t?(d={close:c,commit:f,move:b,refresh:m,state:t},n[9]=f,n[10]=m,n[11]=t,n[12]=d):d=n[12],d},Hr={column:"column",keyword:"keyword",table:"table"},Ur=20,Yr=r=>{const e=J(17),{listboxId:l,onPick:n,state:t}=r,o=se();let a;e[0]!==t?(a=t===null?void 0:{left:t.left,top:t.top+Ur},e[0]=t,e[1]=a):a=e[1];const m=a;if(t===null)return null;let s;if(e[2]!==l||e[3]!==n||e[4]!==t.active||e[5]!==t.suggestions||e[6]!==o){let p;e[8]!==l||e[9]!==n||e[10]!==t.active||e[11]!==o?(p=(b,h)=>$("li",{"aria-selected":h===t.active,className:ve("flex cursor-pointer items-center gap-2 px-2 py-1 text-[13px]",h===t.active?"bg-accent text-accent-foreground":"text-foreground"),"data-testid":"sql-autocomplete-item",id:`${l}-opt-${h.toString()}`,onMouseDown:f=>{f.preventDefault(),n(h)},role:"option",children:[i("span",{className:"truncate font-mono",children:b.label}),b.detail!==void 0&&i("span",{className:"ms-auto truncate text-xs text-muted-foreground",children:b.detail}),i("span",{className:"shrink-0 font-mono text-[10px] tracking-wide text-muted-foreground/70 uppercase",children:o(Hr[b.kind])})]},`${b.kind}:${b.label}`),e[8]=l,e[9]=n,e[10]=t.active,e[11]=o,e[12]=p):p=e[12],s=t.suggestions.map(p),e[2]=l,e[3]=n,e[4]=t.active,e[5]=t.suggestions,e[6]=o,e[7]=s}else s=e[7];let c;return e[13]!==l||e[14]!==m||e[15]!==s?(c=i("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:l,role:"listbox",style:m,children:s}),e[13]=l,e[14]=m,e[15]=s,e[16]=c):c=e[16],c},Kr=r=>{const e=J(8),{diagnostics:l,draft:n,scrollRef:t}=r;let o,a;if(e[0]!==l||e[1]!==n){a=Symbol.for("react.early_return_sentinel");e:{const c=Xl(l,n.length);if(c.length===0){a=null;break e}o=[];let p=0;for(const[b,h]of c.entries())h.start>p&&o.push(n.slice(p,h.start)),o.push(i("span",{className:ve("decoration-wavy underline underline-offset-4",h.severity==="error"?"decoration-destructive":"decoration-amber-500"),children:n.slice(h.start,h.end)},`${h.start.toString()}-${b.toString()}`)),p=h.end;o.push(n.slice(p))}e[0]=l,e[1]=n,e[2]=o,e[3]=a}else o=e[2],a=e[3];if(a!==Symbol.for("react.early_return_sentinel"))return a;let m;e[4]===Symbol.for("react.memo_cache_sentinel")?(m=ve("pointer-events-none absolute inset-0 overflow-hidden text-transparent",Nl),e[4]=m):m=e[4];let s;return e[5]!==o||e[6]!==t?(s=i("div",{"aria-hidden":"true",className:m,"data-testid":"sql-diagnostics-overlay",ref:t,children:o}),e[5]=o,e[6]=t,e[7]=s):s=e[7],s},Qr={gate:"read-only",plan:"plan",schema:"schema",syntax:"syntax"},Jr=r=>{const e=J(10),{diagnostics:l,onSelect:n}=r,t=se();if(l.length===0)return null;let o;e[0]!==t?(o=t("SQL problems"),e[0]=t,e[1]=o):o=e[1];let a;if(e[2]!==l||e[3]!==n){let s;e[5]!==n?(s=(c,p)=>i("li",{children:$("button",{className:"flex w-full items-start gap-2 px-3 py-1 text-start text-xs outline-none hover:bg-accent focus-visible:bg-accent","data-testid":"sql-problem",onClick:()=>{n(c)},type:"button",children:[i("span",{className:ve("mt-px shrink-0 rounded px-1 font-mono text-[10px] uppercase",c.severity==="error"?"bg-destructive/15 text-destructive":"bg-amber-500/15 text-amber-600"),children:Qr[c.source]}),i("span",{className:"min-w-0 text-muted-foreground",children:c.message})]})},`${c.source}-${(c.offset??p).toString()}-${p.toString()}`),e[5]=n,e[6]=s):s=e[6],a=l.map(s),e[2]=l,e[3]=n,e[4]=a}else a=e[4];let m;return e[7]!==o||e[8]!==a?(m=i("ul",{"aria-label":o,className:"max-h-24 shrink-0 overflow-y-auto border-t border-border bg-muted/30","data-testid":"sql-problems",children:a}),e[7]=o,e[8]=a,e[9]=m):m=e[9],m},Cl=[{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;"}],Gr=r=>{const e=J(29),{active:l,onDelete:n,onSelect:t,query:o}=r,a=se();let m;e[0]!==t||e[1]!==o.id?(m=()=>{t(o.id)},e[0]=t,e[1]=o.id,e[2]=m):m=e[2];const s=m;let c;e[3]!==n||e[4]!==o.id?(c=q=>{q.stopPropagation(),n(o.id)},e[3]=n,e[4]=o.id,e[5]=c):c=e[5];const p=c,b=l?"bg-sidebar-accent font-medium text-foreground":"text-muted-foreground";let h;e[6]!==b?(h=ve("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",b),e[6]=b,e[7]=h):h=e[7];const f=`sql-query-${o.id}`;let d;e[8]===Symbol.for("react.memo_cache_sentinel")?(d=i("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:i("path",{d:"M4 6h16M4 12h10M4 18h7"})}),e[8]=d):d=e[8];let w;e[9]!==o.name?(w=i("span",{className:"truncate",children:o.name}),e[9]=o.name,e[10]=w):w=e[10];let y;e[11]!==l||e[12]!==s||e[13]!==h||e[14]!==f||e[15]!==w?(y=$("button",{"aria-pressed":l,className:h,"data-testid":f,onClick:s,type:"button",children:[d,w]}),e[11]=l,e[12]=s,e[13]=h,e[14]=f,e[15]=w,e[16]=y):y=e[16];let v;e[17]!==a?(v=a("Delete query"),e[17]=a,e[18]=v):v=e[18];let g;e[19]!==a?(g=a("Delete query"),e[19]=a,e[20]=g):g=e[20];let E;e[21]===Symbol.for("react.memo_cache_sentinel")?(E=i("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:i("path",{d:"M5 7h14M9 7V5h6v2m-1 0v12H10V7M7 7v13h10V7"})}),e[21]=E):E=e[21];let k;e[22]!==p||e[23]!==g||e[24]!==v?(k=i("button",{"aria-label":v,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:p,title:g,type:"button",children:E}),e[22]=p,e[23]=g,e[24]=v,e[25]=k):k=e[25];let C;return e[26]!==k||e[27]!==y?(C=$("li",{className:"group/q flex items-center",children:[y,k]}),e[26]=k,e[27]=y,e[28]=C):C=e[28],C},Vr=(r,e)=>{const l=e.trim().toLowerCase();return l===""?[...r]:r.filter(n=>n.name.toLowerCase().includes(l))},Xr=r=>{const e=J(60),{activeId:l,history:n,listRef:t,onClearHistory:o,onDelete:a,onLoadHistory:m,onLoadTemplate:s,onNew:c,onSearchChange:p,onSelect:b,queries:h,search:f}=r,d=se();let w,y,v,g;if(e[0]!==l||e[1]!==t||e[2]!==a||e[3]!==c||e[4]!==p||e[5]!==b||e[6]!==h||e[7]!==f||e[8]!==d){const L=Vr(h,f);y="flex h-full w-64 shrink-0 flex-col border-e border-border bg-sidebar";let D;e[13]!==d?(D=d("Search queries…"),e[13]=d,e[14]=D):D=e[14];let z;e[15]!==p||e[16]!==f||e[17]!==D?(z=i("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:p,placeholder:D,type:"text",value:f}),e[15]=p,e[16]=f,e[17]=D,e[18]=z):z=e[18];let j;e[19]!==d?(j=d("New query"),e[19]=d,e[20]=j):j=e[20];let U;e[21]!==d?(U=d("New query"),e[21]=d,e[22]=U):U=e[22];let A;e[23]===Symbol.for("react.memo_cache_sentinel")?(A=i("svg",{"aria-hidden":"true",className:"size-4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.7,viewBox:"0 0 24 24",children:i("path",{d:"M12 5v14M5 12h14"})}),e[23]=A):A=e[23];let Y;e[24]!==c||e[25]!==j||e[26]!==U?(Y=i("button",{"aria-label":j,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:c,title:U,type:"button",children:A}),e[24]=c,e[25]=j,e[26]=U,e[27]=Y):Y=e[27],e[28]!==Y||e[29]!==z?(v=$("div",{className:"flex shrink-0 items-center gap-2 border-b border-border p-2",children:[z,Y]}),e[28]=Y,e[29]=z,e[30]=v):v=e[30],w="flex flex-1 flex-col gap-4 overflow-y-auto p-2";let B;e[31]!==d?(B=d("Private"),e[31]=d,e[32]=B):B=e[32];let W;e[33]!==B?(W=i("p",{className:"px-1 pb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:B}),e[33]=B,e[34]=W):W=e[34],g=$("div",{children:[W,L.length===0?i("p",{className:"px-1 py-2 text-xs text-muted-foreground","data-testid":"sql-private-empty",children:d("No saved queries yet — they save to this browser as you type.")}):i("ul",{className:"flex flex-col gap-px","data-testid":"sql-private",ref:t,children:L.map(_=>i(Gr,{active:l===_.id,onDelete:a,onSelect:b,query:_},_.id))})]}),e[0]=l,e[1]=t,e[2]=a,e[3]=c,e[4]=p,e[5]=b,e[6]=h,e[7]=f,e[8]=d,e[9]=w,e[10]=y,e[11]=v,e[12]=g}else w=e[9],y=e[10],v=e[11],g=e[12];let E;e[35]!==d?(E=d("Reference"),e[35]=d,e[36]=E):E=e[36];let k;e[37]!==E?(k=i("p",{className:"px-1 pb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:E}),e[37]=E,e[38]=k):k=e[38];let C;e[39]!==s?(C=Cl.map(L=>i("li",{children:$("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":L.sql,onClick:s,type:"button",children:[i("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:i("path",{d:"M7 4h7l4 4v12H7zM14 4v4h4"})}),L.label]})},L.label)),e[39]=s,e[40]=C):C=e[40];let q;e[41]!==C?(q=i("ul",{className:"flex flex-col gap-px",children:C}),e[41]=C,e[42]=q):q=e[42];let O;e[43]!==k||e[44]!==q?(O=$("div",{children:[k,q]}),e[43]=k,e[44]=q,e[45]=O):O=e[45];let N;e[46]!==n||e[47]!==o||e[48]!==m||e[49]!==d?(N=n.length>0&&$("div",{children:[$("div",{className:"flex items-center justify-between px-1 pb-1",children:[i("p",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:d("History")}),i("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:o,type:"button",children:d("Clear history")})]}),i("ul",{className:"flex flex-col gap-px","data-testid":"sql-history",children:n.map(L=>i("li",{children:$("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":L.sql,"data-testid":"sql-history-item",onClick:m,title:L.sql,type:"button",children:[i("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:i("path",{d:"M12 8v4l3 2M12 21a9 9 0 1 1 0-18 9 9 0 0 1 0 18Z"})}),i("span",{className:"truncate font-mono",children:L.sql})]})},`${L.at.toString()}:${L.sql}`))})]}),e[46]=n,e[47]=o,e[48]=m,e[49]=d,e[50]=N):N=e[50];let M;e[51]!==w||e[52]!==N||e[53]!==g||e[54]!==O?(M=$("div",{className:w,children:[g,O,N]}),e[51]=w,e[52]=N,e[53]=g,e[54]=O,e[55]=M):M=e[55];let R;return e[56]!==M||e[57]!==y||e[58]!==v?(R=$("aside",{className:y,children:[v,M]}),e[56]=M,e[57]=y,e[58]=v,e[59]=R):R=e[59],R},Zr=jn(zn.listTables),eo=jn(zn.readTablePage),to=r=>{const e=J(16),l=ul();let n;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=[],e[0]=n):n=e[0];const[t,o]=Q(n);let a;e[1]===Symbol.for("react.memo_cache_sentinel")?(a={},e[1]=a):a=e[1];const[m,s]=Q(a);let c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c=new Set,e[2]=c):c=e[2];const p=Dt(c);let b,h;e[3]!==l||e[4]!==r?(b=()=>{const g={cancelled:!1};return fe((async()=>{try{const E=await l.query(Zr,{},Mn(r));g.cancelled||(o(E.map(lo)),s({}),p.current=new Set)}catch{g.cancelled||(o([]),s({}),p.current=new Set)}})()),()=>{g.cancelled=!0}},h=[l,r],e[3]=l,e[4]=r,e[5]=b,e[6]=h):(b=e[5],h=e[6]),An(b,h);let f;e[7]!==l||e[8]!==r?(f=g=>{p.current.has(g)||(p.current.add(g),fe((async()=>{try{const E=await l.query(eo,{limit:1,offset:0,table:g},Mn(r));s(k=>({...k,[g]:E.columns}))}catch{p.current.delete(g)}})()))},e[7]=l,e[8]=r,e[9]=f):f=e[9];const d=f;let w;e[10]!==m||e[11]!==t?(w={columns:m,tables:t},e[10]=m,e[11]=t,e[12]=w):w=e[12];const y=w;let v;return e[13]!==d||e[14]!==y?(v={probe:d,schema:y},e[13]=d,e[14]=y,e[15]=v):v=e[15],v},il=/\b(?:from|join|update|into)\s+([a-z_][\w$]*)|\b([a-z_][\w$]*)\s*\./gi,no=r=>{const e=new Set;il.lastIndex=0;let l=il.exec(r);for(;l!==null;)e.add(l[1]??l[2]),l=il.exec(r);return[...e]};function lo(r){return r.name}const ro="lunora-studio-sql-tabs",oo="lunora-studio-sql-active-tab",dl=12,At=(r="",e="")=>({activeId:null,id:yl("tab"),name:e,sql:r}),so=()=>wl(oo,""),ao=r=>{const e=J(16),[l,n]=cl(ro),[t,o]=so(),[a]=Q(r);let m,s;e[0]!==a||e[1]!==n||e[2]!==l.length?(m=()=>{l.length===0&&n([a])},s=[a,n,l.length],e[0]=a,e[1]=n,e[2]=l.length,e[3]=m,e[4]=s):(m=e[3],s=e[4]),An(m,s);let c;e[5]!==a||e[6]!==l?(c=l.length===0?[a]:l,e[5]=a,e[6]=l,e[7]=c):c=e[7];const p=c;let b;e[8]!==t||e[9]!==p?(b=p.some(d=>d.id===t)?t:p[0]?.id??"",e[8]=t,e[9]=p,e[10]=b):b=e[10];const h=b;let f;return e[11]!==h||e[12]!==o||e[13]!==n||e[14]!==p?(f={activeId:h,setActiveId:o,setTabs:n,tabs:p},e[11]=h,e[12]=o,e[13]=n,e[14]=p,e[15]=f):f=e[15],f},Ll=r=>r.activeId===null&&r.sql.trim()!=="",io=(r,e)=>[...r,e].slice(-dl),co=(r,e,l)=>{const n=r.findIndex(o=>o.id===e);if(n===-1)return{activeId:r[0]?.id??"",tabs:[...r]};const t=r.filter(o=>o.id!==e);if(t.length===0){const o=l();return{activeId:o.id,tabs:[o]}}return{activeId:t[Math.min(n,t.length-1)].id,tabs:t}},uo=(r,e)=>{const l=r.filter(n=>n.id===e);return l.length===0?{activeId:r[0]?.id??"",tabs:[...r]}:{activeId:e,tabs:l}},mo=(r,e,l)=>{const n=r.findIndex(o=>o.id===e);if(n===-1)return{activeId:l,tabs:[...r]};const t=r.slice(0,n+1);return{activeId:t.some(o=>o.id===l)?l:e,tabs:t}},fo=r=>{const e=r();return{activeId:e.id,tabs:[e]}},ho=(r,e,l)=>{if(r==="others")return e.filter(n=>n.id!==l);if(r==="right"){const n=e.findIndex(t=>t.id===l);return n===-1?[]:e.slice(n+1)}return[...e]},po=(r,e)=>r.trim()===""?e:(r.split(`
5
- `)[0]??r).slice(0,24),bo=r=>{r?.focus(),r?.select()},go=r=>{const e=J(14),{initial:l,onCancel:n,onCommit:t,placeholder:o,testId:a}=r,m=se();let s;e[0]!==t?(s=d=>{t(d.currentTarget.value.trim())},e[0]=t,e[1]=s):s=e[1];const c=s;let p;e[2]!==n||e[3]!==t?(p=d=>{d.key==="Enter"?t(d.currentTarget.value.trim()):d.key==="Escape"&&n()},e[2]=n,e[3]=t,e[4]=p):p=e[4];const b=p;let h;e[5]!==m?(h=m("Tab title"),e[5]=m,e[6]=h):h=e[6];let f;return e[7]!==l||e[8]!==c||e[9]!==b||e[10]!==o||e[11]!==h||e[12]!==a?(f=i("input",{"aria-label":h,className:"w-40 rounded border border-ring bg-background px-1 py-0.5 text-xs outline-none","data-testid":a,defaultValue:l,onBlur:c,onKeyDown:b,placeholder:o,ref:bo,type:"text"}),e[7]=l,e[8]=c,e[9]=b,e[10]=o,e[11]=h,e[12]=a,e[13]=f):f=e[13],f},xo=r=>{const e=J(29),{idBase:l,onDiscard:n,onKeep:t}=r,o=se(),a=`sql-tab-close-prompt-${l}`;let m;e[0]!==o?(m=o("Discard?"),e[0]=o,e[1]=m):m=e[1];let s;e[2]!==m?(s=i("span",{className:"text-[11px] text-muted-foreground",children:m}),e[2]=m,e[3]=s):s=e[3];let c;e[4]!==o?(c=o("Discard changes"),e[4]=o,e[5]=c):c=e[5];const p=`sql-tab-close-confirm-${l}`;let b;e[6]!==o?(b=o("Discard changes"),e[6]=o,e[7]=b):b=e[7];let h;e[8]===Symbol.for("react.memo_cache_sentinel")?(h=i("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2.4,viewBox:"0 0 24 24",children:i("path",{d:"M5 13l4 4L19 7"})}),e[8]=h):h=e[8];let f;e[9]!==n||e[10]!==c||e[11]!==p||e[12]!==b?(f=i("button",{"aria-label":c,className:"flex size-5 items-center justify-center rounded text-destructive hover:bg-destructive/10","data-testid":p,onClick:n,title:b,type:"button",children:h}),e[9]=n,e[10]=c,e[11]=p,e[12]=b,e[13]=f):f=e[13];let d;e[14]!==o?(d=o("Keep editing"),e[14]=o,e[15]=d):d=e[15];const w=`sql-tab-close-cancel-${l}`;let y;e[16]!==o?(y=o("Keep editing"),e[16]=o,e[17]=y):y=e[17];let v;e[18]===Symbol.for("react.memo_cache_sentinel")?(v=i("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2.4,viewBox:"0 0 24 24",children:i("path",{d:"M6 6l12 12M18 6 6 18"})}),e[18]=v):v=e[18];let g;e[19]!==t||e[20]!==w||e[21]!==y||e[22]!==d?(g=i("button",{"aria-label":d,className:"flex size-5 items-center justify-center rounded text-muted-foreground hover:bg-accent","data-testid":w,onClick:t,title:y,type:"button",children:v}),e[19]=t,e[20]=w,e[21]=y,e[22]=d,e[23]=g):g=e[23];let E;return e[24]!==a||e[25]!==g||e[26]!==s||e[27]!==f?(E=$("span",{className:"flex shrink-0 items-center gap-1","data-testid":a,role:"group",children:[s,f,g]}),e[24]=a,e[25]=g,e[26]=s,e[27]=f,e[28]=E):E=e[28],E},vo=r=>{const e=J(47),{active:l,canClose:n,onClose:t,onMenu:o,onRename:a,onSelect:m,tab:s}=r,c=se(),[p,b]=Q(!1),[h,f]=Q(!1);let d;e[0]!==o||e[1]!==s.id?(d=G=>{o(s.id,G)},e[0]=o,e[1]=s.id,e[2]=d):d=e[2];const w=d;let y;e[3]!==m||e[4]!==s.id?(y=()=>{m(s.id)},e[3]=m,e[4]=s.id,e[5]=y):y=e[5];const v=y;let g;e[6]===Symbol.for("react.memo_cache_sentinel")?(g=()=>{b(!0)},e[6]=g):g=e[6];const E=g;let k;e[7]!==t||e[8]!==s?(k=G=>{G.stopPropagation(),Ll(s)?f(!0):t(s.id)},e[7]=t,e[8]=s,e[9]=k):k=e[9];const C=k;let q;e[10]!==t||e[11]!==s.id?(q=G=>{G.stopPropagation(),f(!1),t(s.id)},e[10]=t,e[11]=s.id,e[12]=q):q=e[12];const O=q;let N;e[13]===Symbol.for("react.memo_cache_sentinel")?(N=G=>{G.stopPropagation(),f(!1)},e[13]=N):N=e[13];const M=N;let R;e[14]!==a||e[15]!==s.id?(R=G=>{a(s.id,G),b(!1)},e[14]=a,e[15]=s.id,e[16]=R):R=e[16];const L=R;let D;e[17]===Symbol.for("react.memo_cache_sentinel")?(D=()=>{b(!1)},e[17]=D):D=e[17];const z=D;let j;e[18]!==s.name?(j=s.name.trim(),e[18]=s.name,e[19]=j):j=e[19];const U=j;let A;e[20]!==c||e[21]!==s.sql?(A=po(s.sql,c("Untitled")),e[20]=c,e[21]=s.sql,e[22]=A):A=e[22];const Y=A,B=l?"bg-background text-foreground":"bg-muted/40 text-muted-foreground hover:text-foreground";let W;e[23]!==B?(W=ve("group/tab flex shrink-0 items-center gap-1 border-e border-border ps-3 pe-1.5 text-xs",B),e[23]=B,e[24]=W):W=e[24];const _=`sql-tab-${s.id}`;let T;e[25]!==l||e[26]!==L||e[27]!==U||e[28]!==Y||e[29]!==p||e[30]!==v||e[31]!==c||e[32]!==s.id?(T=p?i(go,{initial:U,onCancel:z,onCommit:L,placeholder:Y,testId:`sql-tab-rename-${s.id}`}):i("button",{"aria-pressed":l,className:"max-w-40 truncate py-1.5 outline-none","data-testid":`sql-tab-select-${s.id}`,onClick:v,onDoubleClick:E,title:c("Double-click to rename"),type:"button",children:U===""?Y:U}),e[25]=l,e[26]=L,e[27]=U,e[28]=Y,e[29]=p,e[30]=v,e[31]=c,e[32]=s.id,e[33]=T):T=e[33];let F;e[34]!==n||e[35]!==O||e[36]!==h||e[37]!==C||e[38]!==c||e[39]!==s.id?(F=n&&(h?i(xo,{idBase:s.id,onDiscard:O,onKeep:M}):i("button",{"aria-label":c("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-${s.id}`,onClick:C,title:c("Close tab"),type:"button",children:i("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,viewBox:"0 0 24 24",children:i("path",{d:"M6 6l12 12M18 6 6 18"})})})),e[34]=n,e[35]=O,e[36]=h,e[37]=C,e[38]=c,e[39]=s.id,e[40]=F):F=e[40];let he;return e[41]!==w||e[42]!==W||e[43]!==_||e[44]!==T||e[45]!==F?(he=$("div",{className:W,"data-testid":_,onContextMenu:w,children:[T,F]}),e[41]=w,e[42]=W,e[43]=_,e[44]=T,e[45]=F,e[46]=he):he=e[46],he},yo=jn(zn.runSql),wo="lunora-studio-sql-queries",No="lunora-studio-sql-history",ko="lunora-studio-sql-split-view",So=25,qo={minWidth:"2.75rem",paddingInline:"0.5rem"},vl={error:null,pane:"results",result:null},$o=r=>{const e=J(16),{result:l}=r;if(l.columns.length===0){const s=l.rowCount===0?"0 rows":"";let c;return e[0]!==s?(c=i("p",{className:"p-4 text-sm text-muted-foreground",children:s}),e[0]=s,e[1]=c):c=e[1],c}let n;e[2]!==l.columns?(n=l.columns.map(Lo),e[2]=l.columns,e[3]=n):n=e[3];let t;e[4]!==n?(t=i(Wl,{className:"sticky top-0 z-10 bg-muted",children:i(hl,{children:n})}),e[4]=n,e[5]=t):t=e[5];let o;if(e[6]!==l.columns||e[7]!==l.rows){let s;e[9]!==l.columns?(s=(c,p)=>i(hl,{"data-testid":"sql-row",children:l.columns.map(b=>i(Ul,{className:"max-w-md truncate font-mono text-xs",children:i(Kl,{value:c[b]})},b))},p),e[9]=l.columns,e[10]=s):s=e[10],o=l.rows.map(s),e[6]=l.columns,e[7]=l.rows,e[8]=o}else o=e[8];let a;e[11]!==o?(a=i(Fl,{children:o}),e[11]=o,e[12]=a):a=e[12];let m;return e[13]!==t||e[14]!==a?(m=$(Pl,{"data-testid":"sql-rows",children:[t,a]}),e[13]=t,e[14]=a,e[15]=m):m=e[15],m},On=r=>`border-b-2 px-3 py-2 text-sm outline-none transition-colors ${r?"border-foreground font-medium text-foreground":"border-transparent text-muted-foreground hover:text-foreground"}`,Co=()=>At(Cl[0]?.sql??""),Vo=r=>{const e=J(368),{initialShardKey:l}=r,n=ul(),t=se(),[o,a]=cl(wo),[m,s]=cl(No),[c,p]=Q(""),{activeId:b,setActiveId:h,setTabs:f,tabs:d}=ao(Co);let w;e[0]===Symbol.for("react.memo_cache_sentinel")?(w={},e[0]=w):w=e[0];const[y,v]=Q(w),[g,E]=Q(l??""),[k,C]=Q(!1),[q,O]=wl(ko,!1),[N,M]=Q(null),[R,L]=Q(null),D=Dt(null),z=Dt(null),j=Dt(null),U=Dt(null),A=Al(),{probe:Y,schema:B}=to(g);let W;e[1]!==b||e[2]!==d?(W=d.find(u=>u.id===b)??d[0]??At(),e[1]=b,e[2]=d,e[3]=W):W=e[3];const _=W,T=_.sql,{activeId:F}=_,he=y[_.id]??vl,{chart:G,error:ne,failed:kt,result:I}=he,X=he.pane;let zt;e[4]!==_.id||e[5]!==f?(zt=u=>{f(x=>x.map(S=>S.id===_.id?{...S,...u}:S))},e[4]=_.id,e[5]=f,e[6]=zt):zt=e[6];const Bn=zt;let jt;e[7]!==_.id?(jt=u=>{v(x=>{const S=x[_.id]??vl;return{...x,[_.id]:{...S,...u}}})},e[7]=_.id,e[8]=jt):jt=e[8];const P=jt;let Bt;e[9]!==F||e[10]!==Bn||e[11]!==a?(Bt=u=>{Bn({sql:u}),F!==null&&a(x=>x.map(S=>S.id===F?{...S,sql:u}:S))},e[9]=F,e[10]=Bn,e[11]=a,e[12]=Bt):Bt=e[12];const Z=Bt,ye=Ir(T,B,g),V=Jl(g);let Wt;e[13]!==V||e[14]!==P||e[15]!==I?(Wt=()=>{I!==null&&fe((async()=>{const u=await V.inferChart({columns:I.columns,rowCount:I.rowCount,types:Object.fromEntries(I.columns.map(x=>[x,typeof(I.rows[0]?.[x]??"")]))});P({chart:u})})())},e[13]=V,e[14]=P,e[15]=I,e[16]=Wt):Wt=e[16];const Wn=Wt,El=Pr(B,j,Z),{close:le,commit:we,move:pe,refresh:ee,state:K}=El;let Ft;e[17]!==K?.active||e[18]!==we||e[19]!==pe?(Ft=u=>{pe(u-(K?.active??0)),we()},e[17]=K?.active,e[18]=we,e[19]=pe,e[20]=Ft):Ft=e[20];const Fn=Ft;let Pt;e[21]!==ee?(Pt=()=>{const u=j.current;u!==null&&u===document.activeElement&&ee(u.value,u.selectionStart)},e[21]=ee,e[22]=Pt):Pt=e[22];let Ht;e[23]!==ee||e[24]!==B?(Ht=[ee,B],e[23]=ee,e[24]=B,e[25]=Ht):Ht=e[25],An(Pt,Ht);let Ut;e[26]!==s?(Ut=u=>{s(x=>x[0]?.sql===u?x:[{at:Date.now(),sql:u},...x.filter(S=>S.sql!==u)].slice(0,So))},e[26]=s,e[27]=Ut):Ut=e[27];const Pn=Ut;let Yt;e[28]!==n||e[29]!==T||e[30]!==P||e[31]!==Pn||e[32]!==g?(Yt=async u=>{if(T.trim()==="")return;C(!0);const x=u==="explain"?`EXPLAIN QUERY PLAN ${T}`:T;try{const S=await n.query(yo,{sql:x},Mn(g));P({chart:void 0,error:null,failed:void 0,pane:u,result:S}),Yl(g),Pn(x)}catch(S){const H=S;P({chart:void 0,error:pl(H),failed:{error:pl(H),sql:x},pane:u,result:null})}C(!1)},e[28]=n,e[29]=T,e[30]=P,e[31]=Pn,e[32]=g,e[33]=Yt):Yt=e[33];const re=Yt;let Kt;e[34]!==re?(Kt=()=>{fe(re("results"))},e[34]=re,e[35]=Kt):Kt=e[35];const Hn=Kt;let Qt;e[36]!==Y||e[37]!==ee||e[38]!==Z?(Qt=u=>{const{selectionStart:x,value:S}=u.target;Z(S);for(const H of no(S))Y(H);ee(S,x)},e[36]=Y,e[37]=ee,e[38]=Z,e[39]=Qt):Qt=e[39];const Un=Qt;let Jt;e[40]!==ee?(Jt=u=>{const x=u.currentTarget;ee(x.value,x.selectionStart)},e[40]=ee,e[41]=Jt):Jt=e[41];const Yn=Jt;let Gt;e[42]!==K||e[43]!==le||e[44]!==we||e[45]!==pe||e[46]!==re||e[47]!==X?(Gt=u=>{if(K!==null){if(u.key==="ArrowDown"){u.preventDefault(),pe(1);return}if(u.key==="ArrowUp"){u.preventDefault(),pe(-1);return}if(u.key==="Escape"){u.preventDefault(),le();return}if((u.key==="Enter"||u.key==="Tab")&&!u.metaKey&&!u.ctrlKey&&we()){u.preventDefault();return}}(u.metaKey||u.ctrlKey)&&u.key==="Enter"&&(u.preventDefault(),fe(re(X)))},e[42]=K,e[43]=le,e[44]=we,e[45]=pe,e[46]=re,e[47]=X,e[48]=Gt):Gt=e[48];const Kn=Gt;let Vt;e[49]!==le?(Vt=()=>{requestAnimationFrame(()=>{le()})},e[49]=le,e[50]=Vt):Vt=e[50];const Qn=Vt;let Xt;e[51]===Symbol.for("react.memo_cache_sentinel")?(Xt=u=>{const{scrollLeft:x,scrollTop:S}=u.currentTarget;D.current!==null&&(D.current.scrollTop=S),z.current!==null&&(z.current.scrollTop=S,z.current.scrollLeft=x)},e[51]=Xt):Xt=e[51];const _l=Xt;let Zt;e[52]===Symbol.for("react.memo_cache_sentinel")?(Zt=u=>{const x=j.current;x===null||u.offset===void 0||(x.focus(),x.setSelectionRange(u.offset,u.offset+(u.length??0)))},e[52]=Zt):Zt=e[52];const Il=Zt;let en;e[53]!==_.id||e[54]!==P||e[55]!==f?(en=(u,x)=>{f(S=>S.map(H=>H.id===_.id?{...H,activeId:x,sql:u}:H)),P({chart:void 0,error:null,failed:void 0,result:null})},e[53]=_.id,e[54]=P,e[55]=f,e[56]=en):en=e[56];const te=en;let tn;e[57]!==te||e[58]!==a||e[59]!==t?(tn=()=>{const u={id:yl("q"),name:t("Untitled query"),sql:""};a(x=>[u,...x]),te("",u.id)},e[57]=te,e[58]=a,e[59]=t,e[60]=tn):tn=e[60];const St=tn;let nn;e[61]!==te||e[62]!==o?(nn=u=>{const x=o.find(S=>S.id===u);x!==void 0&&(te(x.sql,u),U.current?.querySelector(`[data-testid="sql-query-${u}"]`)?.scrollIntoView({block:"nearest"}))},e[61]=te,e[62]=o,e[63]=nn):nn=e[63];const qt=nn;let ln;e[64]!==a||e[65]!==f?(ln=u=>{a(x=>x.filter(S=>S.id!==u)),f(x=>x.map(S=>S.activeId===u?{...S,activeId:null}:S))},e[64]=a,e[65]=f,e[66]=ln):ln=e[66];const $t=ln;let rn;e[67]!==te?(rn=u=>{te(u.currentTarget.dataset.sql??"",null)},e[67]=te,e[68]=rn):rn=e[68];const Ct=rn;let on;e[69]!==te?(on=u=>{te(u.currentTarget.dataset.sql??"",null)},e[69]=te,e[70]=on):on=e[70];const Lt=on;let sn;e[71]!==s?(sn=()=>{s([])},e[71]=s,e[72]=sn):sn=e[72];const Et=sn;let an;e[73]!==T||e[74]!==Z?(an=()=>{Z(rr(T))},e[73]=T,e[74]=Z,e[75]=an):an=e[75];const Jn=an;let cn;e[76]!==h||e[77]!==f||e[78]!==d.length?(cn=()=>{if(d.length>=dl)return;const u=At();f(x=>io(x,u)),h(u.id)},e[76]=h,e[77]=f,e[78]=d.length,e[79]=cn):cn=e[79];const _t=cn;let dn;e[80]!==h||e[81]!==f?(dn=u=>{M(null),L(null),f(u.tabs),h(u.activeId);const x=new Set(u.tabs.map(Eo));v(S=>Object.fromEntries(Object.entries(S).filter(H=>{const[ue]=H;return x.has(ue)})))},e[80]=h,e[81]=f,e[82]=dn):dn=e[82];const Ne=dn;let un;e[83]!==Ne||e[84]!==d?(un=u=>{Ne(co(d,u,At))},e[83]=Ne,e[84]=d,e[85]=un):un=e[85];const be=un;let mn;e[86]!==b||e[87]!==Ne||e[88]!==d?(mn=(u,x)=>{Ne(u==="others"?uo(d,x):u==="right"?mo(d,x,b):fo(At))},e[86]=b,e[87]=Ne,e[88]=d,e[89]=mn):mn=e[89];const ke=mn;let fn;e[90]!==ke||e[91]!==N||e[92]!==d?(fn=u=>{N!==null&&(ho(u,d,N.id).some(_o)?L(u):ke(u,N.id))},e[90]=ke,e[91]=N,e[92]=d,e[93]=fn):fn=e[93];const oe=fn;let hn;e[94]===Symbol.for("react.memo_cache_sentinel")?(hn=(u,x)=>{x.preventDefault(),L(null),M({id:u,x:x.clientX,y:x.clientY})},e[94]=hn):hn=e[94];const Tl=hn;let pn;e[95]===Symbol.for("react.memo_cache_sentinel")?(pn=()=>{M(null),L(null)},e[95]=pn):pn=e[95];const Rl=pn;let bn;e[96]===Symbol.for("react.memo_cache_sentinel")?(bn=u=>{u.preventDefault(),M(null),L(null)},e[96]=bn):bn=e[96];const Ol=bn;let gn;e[97]!==oe?(gn=()=>{oe("others")},e[97]=oe,e[98]=gn):gn=e[98];const It=gn;let xn;e[99]!==oe?(xn=()=>{oe("right")},e[99]=oe,e[100]=xn):xn=e[100];const Tt=xn;let vn;e[101]!==oe?(vn=()=>{oe("all")},e[101]=oe,e[102]=vn):vn=e[102];const Rt=vn;let yn;e[103]!==ke||e[104]!==R||e[105]!==N?(yn=()=>{N!==null&&R!==null&&ke(R,N.id),L(null)},e[103]=ke,e[104]=R,e[105]=N,e[106]=yn):yn=e[106];const Ot=yn;let wn;e[107]===Symbol.for("react.memo_cache_sentinel")?(wn=()=>{L(null)},e[107]=wn):wn=e[107];const Ml=wn;let Nn;e[108]!==N?(Nn=N===null?void 0:{left:N.x,top:N.y},e[108]=N,e[109]=Nn):Nn=e[109];const Mt=Nn;let kn;e[110]!==le||e[111]!==h?(kn=u=>{le(),h(u)},e[110]=le,e[111]=h,e[112]=kn):kn=e[112];const ge=kn;let Sn;e[113]!==f?(Sn=(u,x)=>{f(S=>S.map(H=>H.id===u?{...H,name:x}:H))},e[113]=f,e[114]=Sn):Sn=e[114];const xe=Sn;let qn;e[115]!==P?(qn=()=>{P({pane:"results"})},e[115]=P,e[116]=qn):qn=e[116];const Gn=qn;let $n;e[117]!==re?($n=()=>{fe(re("explain"))},e[117]=re,e[118]=$n):$n=e[118];const Vn=$n;let Cn;e[119]!==P?(Cn=()=>{P({pane:"chart"})},e[119]=P,e[120]=Cn):Cn=e[120];const Xn=Cn;let Ln;e[121]!==O||e[122]!==q?(Ln=()=>{O(!q)},e[121]=O,e[122]=q,e[123]=Ln):Ln=e[123];const Zn=Ln;let Se,qe,$e,Ce,Le,Ee,_e,Ie,ae,Te,Re,ie,ce,Oe,Me,de;if(e[124]!==F||e[125]!==_.id||e[126]!==_t||e[127]!==V||e[128]!==Et||e[129]!==be||e[130]!==Ot||e[131]!==$t||e[132]!==T||e[133]!==kt||e[134]!==m||e[135]!==Lt||e[136]!==Ct||e[137]!==St||e[138]!==Rt||e[139]!==It||e[140]!==Tt||e[141]!==R||e[142]!==o||e[143]!==xe||e[144]!==c||e[145]!==qt||e[146]!==ge||e[147]!==Z||e[148]!==q||e[149]!==t||e[150]!==N||e[151]!==Mt||e[152]!==d){const u=T.split(`
6
- `).length;let x;e[169]===Symbol.for("react.memo_cache_sentinel")?(x=me=>{p(me.target.value)},e[169]=x):x=e[169];const S=x,H=q?"flex min-h-0 flex-1 flex-row":"flex min-h-0 flex-1 flex-col";Se=q?"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",Oe="flex h-full min-w-0",Me="lunora-sql-editor",e[170]!==F||e[171]!==Et||e[172]!==$t||e[173]!==m||e[174]!==Lt||e[175]!==Ct||e[176]!==St||e[177]!==o||e[178]!==c||e[179]!==qt?(de=i(Xr,{activeId:F,history:m,listRef:U,onClearHistory:Et,onDelete:$t,onLoadHistory:Lt,onLoadTemplate:Ct,onNew:St,onSearchChange:S,onSelect:qt,queries:o,search:c}),e[170]=F,e[171]=Et,e[172]=$t,e[173]=m,e[174]=Lt,e[175]=Ct,e[176]=St,e[177]=o,e[178]=c,e[179]=qt,e[180]=de):de=e[180],Re="flex min-w-0 flex-1 flex-col";let ue;if(e[181]!==_.id||e[182]!==be||e[183]!==xe||e[184]!==ge||e[185]!==d){let me;e[187]!==_.id||e[188]!==be||e[189]!==xe||e[190]!==ge||e[191]!==d.length?(me=al=>i(vo,{active:al.id===_.id,canClose:d.length>1,onClose:be,onMenu:Tl,onRename:xe,onSelect:ge,tab:al},al.id),e[187]=_.id,e[188]=be,e[189]=xe,e[190]=ge,e[191]=d.length,e[192]=me):me=e[192],ue=d.map(me),e[181]=_.id,e[182]=be,e[183]=xe,e[184]=ge,e[185]=d,e[186]=ue}else ue=e[186];let yt;e[193]!==t?(yt=t("New tab"),e[193]=t,e[194]=yt):yt=e[194];const sl=d.length>=dl;let wt;e[195]!==t?(wt=t("New tab"),e[195]=t,e[196]=wt):wt=e[196];let Tn;e[197]===Symbol.for("react.memo_cache_sentinel")?(Tn=i("svg",{"aria-hidden":"true",className:"size-4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.7,viewBox:"0 0 24 24",children:i("path",{d:"M12 5v14M5 12h14"})}),e[197]=Tn):Tn=e[197];let Nt;e[198]!==_t||e[199]!==yt||e[200]!==sl||e[201]!==wt?(Nt=i("button",{"aria-label":yt,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:sl,onClick:_t,title:wt,type:"button",children:Tn}),e[198]=_t,e[199]=yt,e[200]=sl,e[201]=wt,e[202]=Nt):Nt=e[202],e[203]!==ue||e[204]!==Nt?(ie=$("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:[ue,Nt]}),e[203]=ue,e[204]=Nt,e[205]=ie):ie=e[205],e[206]!==Ot||e[207]!==Rt||e[208]!==It||e[209]!==Tt||e[210]!==R||e[211]!==t||e[212]!==N||e[213]!==Mt||e[214]!==d?(ce=N!==null&&$(bl,{children:[i("div",{className:"fixed inset-0 z-40","data-testid":"sql-tab-menu-backdrop",onClick:Rl,onContextMenu:Ol,role:"presentation"}),i("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:Mt,children:R===null?$(bl,{children:[i("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:d.length<=1,onClick:It,role:"menuitem",type:"button",children:t("Close other tabs")}),i("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:d.findIndex(me=>me.id===N.id)>=d.length-1,onClick:Tt,role:"menuitem",type:"button",children:t("Close tabs to the right")}),i("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:Rt,role:"menuitem",type:"button",children:t("Close all tabs")})]}):$("div",{className:"px-3 py-1.5","data-testid":"sql-tab-menu-confirm",children:[i("p",{className:"pb-1.5 text-xs text-muted-foreground",children:t("Discard unsaved tabs?")}),$("div",{className:"flex items-center gap-1.5",children:[i("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:Ot,type:"button",children:t("Discard")}),i("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:Ml,type:"button",children:t("Cancel")})]})]})})]}),e[206]=Ot,e[207]=Rt,e[208]=It,e[209]=Tt,e[210]=R,e[211]=t,e[212]=N,e[213]=Mt,e[214]=d,e[215]=ce):ce=e[215],Te=H,Ie="flex min-h-0 min-w-0 flex-1 flex-col",e[216]!==V||e[217]!==kt||e[218]!==Z?(ae=i(Rr,{assistant:V,failed:kt,onGenerated:Z}),e[216]=V,e[217]=kt,e[218]=Z,e[219]=ae):ae=e[219],_e="flex min-h-0 min-w-0 flex-1",qe="true",$e="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",Ce=D,Le=qo,Ee=Array.from({length:u},Io),e[124]=F,e[125]=_.id,e[126]=_t,e[127]=V,e[128]=Et,e[129]=be,e[130]=Ot,e[131]=$t,e[132]=T,e[133]=kt,e[134]=m,e[135]=Lt,e[136]=Ct,e[137]=St,e[138]=Rt,e[139]=It,e[140]=Tt,e[141]=R,e[142]=o,e[143]=xe,e[144]=c,e[145]=qt,e[146]=ge,e[147]=Z,e[148]=q,e[149]=t,e[150]=N,e[151]=Mt,e[152]=d,e[153]=Se,e[154]=qe,e[155]=$e,e[156]=Ce,e[157]=Le,e[158]=Ee,e[159]=_e,e[160]=Ie,e[161]=ae,e[162]=Te,e[163]=Re,e[164]=ie,e[165]=ce,e[166]=Oe,e[167]=Me,e[168]=de}else Se=e[153],qe=e[154],$e=e[155],Ce=e[156],Le=e[157],Ee=e[158],_e=e[159],Ie=e[160],ae=e[161],Te=e[162],Re=e[163],ie=e[164],ce=e[165],Oe=e[166],Me=e[167],de=e[168];let De;e[220]!==qe||e[221]!==$e||e[222]!==Ce||e[223]!==Le||e[224]!==Ee?(De=i("div",{"aria-hidden":qe,className:$e,ref:Ce,style:Le,children:Ee}),e[220]=qe,e[221]=$e,e[222]=Ce,e[223]=Le,e[224]=Ee,e[225]=De):De=e[225];let Ae;e[226]!==ye||e[227]!==T?(Ae=i(Kr,{diagnostics:ye,draft:T,scrollRef:z}),e[226]=ye,e[227]=T,e[228]=Ae):Ae=e[228];let ze;e[229]!==K||e[230]!==A?(ze=K===null?void 0:`${A}-opt-${K.active.toString()}`,e[229]=K,e[230]=A,e[231]=ze):ze=e[231];const el=K===null?void 0:A,tl=K!==null;let je;e[232]!==t?(je=t("SQL query"),e[232]=t,e[233]=je):je=e[233];let Be;e[234]!==T||e[235]!==Un||e[236]!==Qn||e[237]!==Kn||e[238]!==Yn||e[239]!==ze||e[240]!==el||e[241]!==tl||e[242]!==je?(Be=i("textarea",{"aria-activedescendant":ze,"aria-autocomplete":"list","aria-controls":el,"aria-expanded":tl,"aria-label":je,className:`relative size-full resize-none bg-transparent outline-none ${Nl}`,"data-testid":"sql-input",onBlur:Qn,onChange:Un,onKeyDown:Kn,onScroll:_l,onSelect:Yn,placeholder:"SELECT * FROM …",ref:j,role:"combobox",spellCheck:!1,value:T}),e[234]=T,e[235]=Un,e[236]=Qn,e[237]=Kn,e[238]=Yn,e[239]=ze,e[240]=el,e[241]=tl,e[242]=je,e[243]=Be):Be=e[243];let We;e[244]!==K||e[245]!==A||e[246]!==Fn?(We=i(Yr,{listboxId:A,onPick:Fn,state:K}),e[244]=K,e[245]=A,e[246]=Fn,e[247]=We):We=e[247];let Fe;e[248]!==Ae||e[249]!==Be||e[250]!==We?(Fe=$("div",{className:"relative min-w-0 flex-1 bg-background",children:[Ae,Be,We]}),e[248]=Ae,e[249]=Be,e[250]=We,e[251]=Fe):Fe=e[251];let Pe;e[252]!==_e||e[253]!==De||e[254]!==Fe?(Pe=$("div",{className:_e,children:[De,Fe]}),e[252]=_e,e[253]=De,e[254]=Fe,e[255]=Pe):Pe=e[255];let He;e[256]!==ye?(He=i(Jr,{diagnostics:ye,onSelect:Il}),e[256]=ye,e[257]=He):He=e[257];let Ue;e[258]!==Ie||e[259]!==ae||e[260]!==Pe||e[261]!==He?(Ue=$("div",{className:Ie,children:[ae,Pe,He]}),e[258]=Ie,e[259]=ae,e[260]=Pe,e[261]=He,e[262]=Ue):Ue=e[262];const nl=X==="results";let Ye;e[263]!==nl?(Ye=On(nl),e[263]=nl,e[264]=Ye):Ye=e[264];let Ke;e[265]!==t?(Ke=t("Results"),e[265]=t,e[266]=Ke):Ke=e[266];let Qe;e[267]!==Gn||e[268]!==Ye||e[269]!==Ke?(Qe=i("button",{className:Ye,"data-testid":"sql-tab-results",onClick:Gn,type:"button",children:Ke}),e[267]=Gn,e[268]=Ye,e[269]=Ke,e[270]=Qe):Qe=e[270];const ll=X==="chart";let Je;e[271]!==ll?(Je=On(ll),e[271]=ll,e[272]=Je):Je=e[272];let Ge;e[273]!==t?(Ge=t("Chart"),e[273]=t,e[274]=Ge):Ge=e[274];let Ve;e[275]!==Xn||e[276]!==Je||e[277]!==Ge?(Ve=i("button",{className:Je,"data-testid":"sql-tab-chart",onClick:Xn,type:"button",children:Ge}),e[275]=Xn,e[276]=Je,e[277]=Ge,e[278]=Ve):Ve=e[278];let Xe;e[279]!==V||e[280]!==Wn||e[281]!==I||e[282]!==t||e[283]!==X?(Xe=!V.unavailable&&X==="chart"&&I!==null&&i("button",{className:On(!1),"data-testid":"sql-infer-chart",disabled:V.pending("chart"),onClick:Wn,type:"button",children:V.pending("chart")?t("Thinking…"):t("Suggest chart")}),e[279]=V,e[280]=Wn,e[281]=I,e[282]=t,e[283]=X,e[284]=Xe):Xe=e[284];const rl=X==="explain";let Ze;e[285]!==rl?(Ze=On(rl),e[285]=rl,e[286]=Ze):Ze=e[286];let et;e[287]!==t?(et=t("Explain"),e[287]=t,e[288]=et):et=e[288];let tt;e[289]!==Vn||e[290]!==Ze||e[291]!==et?(tt=i("button",{className:Ze,"data-testid":"sql-tab-explain",onClick:Vn,type:"button",children:et}),e[289]=Vn,e[290]=Ze,e[291]=et,e[292]=tt):tt=e[292];let nt;e[293]!==t?(nt=t("Split editor and results"),e[293]=t,e[294]=nt):nt=e[294];const ol=`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 ${q?"bg-accent text-foreground":"text-muted-foreground"}`;let lt;e[295]!==t?(lt=t("Split editor and results"),e[295]=t,e[296]=lt):lt=e[296];let En;e[297]===Symbol.for("react.memo_cache_sentinel")?(En=$("svg",{"aria-hidden":"true",className:"size-4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.7,viewBox:"0 0 24 24",children:[i("rect",{height:"16",rx:"2",width:"18",x:"3",y:"4"}),i("path",{d:"M12 4v16"})]}),e[297]=En):En=e[297];let rt;e[298]!==q||e[299]!==nt||e[300]!==ol||e[301]!==lt||e[302]!==Zn?(rt=i("button",{"aria-label":nt,"aria-pressed":q,className:ol,"data-testid":"sql-split-toggle",onClick:Zn,title:lt,type:"button",children:En}),e[298]=q,e[299]=nt,e[300]=ol,e[301]=lt,e[302]=Zn,e[303]=rt):rt=e[303];let ot;e[304]!==I?(ot=I!==null&&I.columns.length>0&&i(Ql,{columns:I.columns,name:"query-result",rows:I.rows}),e[304]=I,e[305]=ot):ot=e[305];let st;e[306]!==t?(st=t("Format"),e[306]=t,e[307]=st):st=e[307];let at;e[308]!==Jn||e[309]!==k||e[310]!==st?(at=i("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:k,onClick:Jn,type:"button",children:st}),e[308]=Jn,e[309]=k,e[310]=st,e[311]=at):at=e[311];let it;e[312]!==g?(it=i(jl,{onChange:E,testId:"sql-shard-input",value:g}),e[312]=g,e[313]=it):it=e[313];let ct;e[314]!==k||e[315]!==t?(ct=t(k?"Running…":"Run"),e[314]=k,e[315]=t,e[316]=ct):ct=e[316];let _n;e[317]===Symbol.for("react.memo_cache_sentinel")?(_n=i("kbd",{className:"rounded border border-primary-foreground/30 px-1 font-sans text-[10px]",children:"⌘↵"}),e[317]=_n):_n=e[317];let dt;e[318]!==Hn||e[319]!==k||e[320]!==ct?(dt=$("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:k,onClick:Hn,type:"button",children:[ct,_n]}),e[318]=Hn,e[319]=k,e[320]=ct,e[321]=dt):dt=e[321];let ut;e[322]!==rt||e[323]!==ot||e[324]!==at||e[325]!==it||e[326]!==dt?(ut=$("div",{className:"ms-auto flex items-center gap-2",children:[rt,ot,at,it,dt]}),e[322]=rt,e[323]=ot,e[324]=at,e[325]=it,e[326]=dt,e[327]=ut):ut=e[327];let mt;e[328]!==Qe||e[329]!==Ve||e[330]!==Xe||e[331]!==tt||e[332]!==ut?(mt=$("div",{className:"flex shrink-0 items-center gap-2 border-b border-border pe-2",children:[Qe,Ve,Xe,tt,ut]}),e[328]=Qe,e[329]=Ve,e[330]=Xe,e[331]=tt,e[332]=ut,e[333]=mt):mt=e[333];let ft;e[334]!==ne?(ft=ne!==null&&i(Bl,{className:"m-3 font-mono text-xs",testId:"sql-error",variant:"destructive",children:ne}),e[334]=ne,e[335]=ft):ft=e[335];let ht;e[336]!==ne||e[337]!==I||e[338]!==t?(ht=ne===null&&I===null&&i("p",{className:"p-4 text-sm text-muted-foreground","data-testid":"sql-empty",children:t("Click Run to execute your query.")}),e[336]=ne,e[337]=I,e[338]=t,e[339]=ht):ht=e[339];let pt;e[340]!==ne||e[341]!==G||e[342]!==I||e[343]!==t||e[344]!==X?(pt=ne===null&&I!==null&&$("div",{"data-testid":"sql-result",children:[X==="chart"?i(zl,{axes:G,result:I}):i($o,{result:I}),i("p",{className:"border-t border-border px-3 py-1.5 text-xs text-muted-foreground","data-testid":"sql-count",children:I.truncated?t("Showing the first {max} of {count} rows.",{count:I.rowCount,max:I.rows.length}):t("{count} rows",{count:I.rowCount})})]}),e[340]=ne,e[341]=G,e[342]=I,e[343]=t,e[344]=X,e[345]=pt):pt=e[345];let bt;e[346]!==ft||e[347]!==ht||e[348]!==pt?(bt=$("div",{className:"min-h-0 flex-1 overflow-auto",children:[ft,ht,pt]}),e[346]=ft,e[347]=ht,e[348]=pt,e[349]=bt):bt=e[349];let gt;e[350]!==Se||e[351]!==mt||e[352]!==bt?(gt=$("div",{className:Se,children:[mt,bt]}),e[350]=Se,e[351]=mt,e[352]=bt,e[353]=gt):gt=e[353];let xt;e[354]!==gt||e[355]!==Te||e[356]!==Ue?(xt=$("div",{className:Te,children:[Ue,gt]}),e[354]=gt,e[355]=Te,e[356]=Ue,e[357]=xt):xt=e[357];let vt;e[358]!==xt||e[359]!==Re||e[360]!==ie||e[361]!==ce?(vt=$("div",{className:Re,children:[ie,ce,xt]}),e[358]=xt,e[359]=Re,e[360]=ie,e[361]=ce,e[362]=vt):vt=e[362];let In;return e[363]!==vt||e[364]!==Oe||e[365]!==Me||e[366]!==de?(In=$("div",{className:Oe,"data-testid":Me,children:[de,vt]}),e[363]=vt,e[364]=Oe,e[365]=Me,e[366]=de,e[367]=In):In=e[367],In};function Lo(r){return i(Hl,{children:r},r)}function Eo(r){return r.id}function _o(r){return Ll(r)}function Io(r,e){return i("div",{children:e+1},e)}export{Vo as SqlEditorPanel};
1
+ import{c as K}from"react/compiler-runtime";import{useLunora as Me}from"@lunora/react";import{useState as te,useMemo as ze,useCallback as et,useEffect as qe,useRef as ye,useId as tt}from"react";import{ADMIN_FUNCTIONS as $e}from"../packem_shared/ADMIN_FUNCTIONS-CZESgd10.js";import{u as Oe,n as We,b as Ke}from"../packem_shared/browser-storage-xjTyMKY0.js";import{d as ke,f as de,g as Te,b as He}from"../packem_shared/internal-BSIsQVC6.js";import{r as nt}from"../packem_shared/shard-history-DMEW5VBE.js";import{k as ot}from"../packem_shared/use-sql-assistant-BLG9unQN.js";import rt from"../packem_shared/useDebounced-Ihdiid_k.js";import{useT as oe}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{c as ue}from"../packem_shared/utils-bhneXptQ.js";import{jsx as u,jsxs as B,Fragment as Le}from"react/jsx-runtime";import{u as lt}from"../packem_shared/input-JHu63lTv.js";import{I as st}from"../packem_shared/result-chart-DzJOVsaw.js";import{ShardInput as at}from"../packem_shared/ShardInput-BVn2iCU0.js";import{A as it}from"../packem_shared/alert-CVcOFuDR.js";import{K as ct}from"../packem_shared/grid-features-jnrD0SpX.js";import{d as dt,m as Pe,f as ut,n as mt,p as ft,u as ht}from"../packem_shared/table-DdJBrClo.js";import{g as pt}from"../packem_shared/data-grid-DcxyIXwG.js";const bt=["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"],gt=["FROM","WHERE","ORDER BY","GROUP BY","HAVING","LIMIT","OFFSET","UNION","JOIN","LEFT JOIN","RIGHT JOIN","INNER JOIN","OUTER JOIN","CROSS JOIN"],Ce=String.fromCodePoint(0),xt=new RegExp(`${Ce}${String.raw`(\d+)`}${Ce}`,"gu"),vt=bt.map(l=>({pattern:new RegExp(String.raw`\b${l.replaceAll(" ",String.raw`\s+`)}\b`,"giu"),replacement:l})),yt=gt.map(l=>({pattern:new RegExp(String.raw`\s+${l.replaceAll(" ",String.raw`\s+`)}\b`,"gu"),replacement:`
2
+ ${l}`})),wt=l=>{const e=[];let t=l.replaceAll(/'(?:[^']|'')*'/gu,n=>(e.push(n),`${Ce}${(e.length-1).toString()}${Ce}`)).replaceAll(/\s+/gu," ").trim();for(const{pattern:n,replacement:r}of vt)t=t.replaceAll(n,r);for(const{pattern:n,replacement:r}of yt)t=t.replaceAll(n,r);return t=t.replaceAll(xt,(n,r)=>e[Number(r)]??""),t},St=/^(?:explain\s+(?:query\s+plan\s+)?)?(?:select|with)\b/iu,Nt=/\b(?:alter|attach|create|delete|detach|drop|insert|pragma|reindex|replace|truncate|update|vacuum)\b/iu,kt=/^\w+/u,Ct=/;\s*$/u,qt=/\s/u,$t=(l,e)=>{let t=e+2;for(;t<l.length&&l[t]!==`
3
+ `;)t+=1;return t},Tt=(l,e)=>{const t=l.indexOf("*/",e+2);return t===-1?-1:t+2},Rt=l=>{let e=0;for(;e<l.length;){const t=l[e];if(t!==void 0&&qt.test(t))e+=1;else if(t==="-"&&l[e+1]==="-")e=$t(l,e);else if(t==="/"&&l[e+1]==="*"){const n=Tt(l,e);if(n===-1)break;e=n}else break}return e},It=l=>{const e=Rt(l),t=l.slice(e).trimEnd();if(t==="")return{code:"SQL_EMPTY",message:"the query is empty"};const n=t.replace(Ct,""),r=n.indexOf(";");if(r!==-1)return{code:"SQL_MULTIPLE_STATEMENTS",length:1,message:"only a single statement may be run",offset:e+r};const o="the SQL editor is read-only — only SELECT / WITH / EXPLAIN queries are allowed";if(!St.test(n))return{code:"SQL_NOT_READONLY",length:kt.exec(n)?.[0].length??1,message:o,offset:e};const s=Nt.exec(n);if(s!==null)return{code:"SQL_NOT_READONLY",length:s[0].length,message:`${o} (\`${s[0].toUpperCase()}\` is not allowed)`,offset:e+s.index}},Et=/\b(?:from|join)\s+([a-z_][\w$]*)(?:\s+(?:as\s+)?([a-z_][\w$]*))?/giu,Lt=/(?:\bwith\s+(?:recursive\s+)?|,\s*)([a-z_][\w$]*)\s+as\s*\(/giu,_t=new Set(["cross","full","group","having","inner","join","left","limit","offset","on","order","right","union","using","where","window"]),Ot=/[^\n]/gu,Mt=(l,e)=>{const t=l[e];if(t==="'"){let n=e+1;for(;n<l.length&&l[n]!=="'";)n+=1;return Math.min(n+1,l.length)}if(t==="-"&&l[e+1]==="-"){const n=l.indexOf(`
4
+ `,e);return n===-1?l.length:n}if(t==="/"&&l[e+1]==="*"){const n=l.indexOf("*/",e+2);return n===-1?l.length:n+2}return-1},Dt=l=>{let e="",t=0;for(;t<l.length;){const n=Mt(l,t);n===-1?(e+=l.slice(t,t+1),t+=1):(e+=l.slice(t,n).replaceAll(Ot," "),t=n)}return e},At=l=>{const e=new Set;for(const t of l.matchAll(Lt))e.add((t[1]??"").toLowerCase());return e},Bt=(l,e)=>{const t=new Map;for(const n of l.matchAll(Et)){const r=(n[1]??"").toLowerCase(),o=(n[2]??"").toLowerCase();e.has(r)&&(t.set(r,r),o!==""&&!_t.has(o)&&t.set(o,r))}return t},Ue=(l,e)=>{const t=Dt(l),n=new Set(e.map(r=>r.toLowerCase()));return{ctes:At(t),masked:t,targets:Bt(t,n)}},zt=/^(?:__lunora|sqlite_)/iu,Ht=/\b(?:from|join)\s+([a-z_][\w$]*)/giu,Pt=/\b([a-z_][\w$]*)\.([a-z_][\w$]*)/giu,Ft=new Set(["cross","full","group","having","inner","join","lateral","left","limit","offset","order","right","select","union","where","window"]),Qt=(l,e,t)=>{const n=[];for(const r of l.matchAll(Ht)){const o=r[1]??"",s=o.toLowerCase();!e.has(s)&&!t.has(s)&&!Ft.has(s)&&!zt.test(o)&&n.push({length:o.length,message:`unknown table \`${o}\``,offset:r.index+r[0].length-o.length,severity:"error",source:"schema"})}return n},jt=(l,e,t)=>{const n=[],r=new Map;for(const[o,s]of Object.entries(e.columns))r.set(o.toLowerCase(),new Set(s.map(d=>d.toLowerCase())));for(const o of l.matchAll(Pt)){const s=(o[1]??"").toLowerCase(),d=o[2]??"",a=t.get(s),i=a===void 0?void 0:r.get(a);i!==void 0&&!i.has(d.toLowerCase())&&n.push({length:d.length,message:`\`${a??""}\` has no column \`${d}\``,offset:o.index+o[0].length-d.length,severity:"error",source:"schema"})}return n},Wt=(l,e)=>{if(l.trim()==="")return[];const t=It(l);if(t!==void 0)return t.code==="SQL_EMPTY"?[]:[{length:t.length,message:t.message,offset:t.offset,severity:"error",source:"gate"}];const{ctes:n,masked:r,targets:o}=Ue(l,e.tables),s=new Set(e.tables.map(d=>d.toLowerCase()));return[...Qt(r,s,n),...jt(r,e,o)]},Kt=Te($e.lintSql),Ut=600,Yt=(l,e,t)=>{const n=Me(),[r,o]=te([]),s=ze(()=>Wt(l,e),[l,e]),d=rt(l,Ut),a=s.some(h=>h.source==="gate")||d.trim()==="",i=et(async h=>{try{const p=await n.query(Kt,{sql:d},ke(t));h.cancelled||o(p.diagnostics??[])}catch{h.cancelled||o([])}},[n,d,t]);qe(()=>{if(a){o([]);return}const h={cancelled:!1};return de(i(h)),()=>{h.cancelled=!0}},[i,a]);const f=d===l;return ze(()=>f?[...s,...r]:s,[s,r,f])},Se=8,Jt=["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"],Gt=new Set(["AND","BY","HAVING","ON","OR","SELECT","WHERE"]),Vt=/[\w$]/,Ye=l=>l!==void 0&&Vt.test(l),Je=l=>{let e=l.length;for(;e>0&&Ye(l[e-1]);)e-=1;return l.slice(e)},Ge=(l,e)=>{let t=e;for(;t>0&&Ye(l[t-1]);)t-=1;return{end:e,start:t,text:l.slice(t,e)}},Fe=(l,e)=>{const t=l.slice(0,e).trimEnd();return t.endsWith(".")||Gt.has(Je(t).toUpperCase())},Xt=(l,e,t)=>{const n=l.slice(0,e);if(!n.endsWith("."))return;const r=Je(n.slice(0,-1));if(r!=="")return Ue(l,t).targets.get(r.toLowerCase())??r},De=(l,e)=>l.toLowerCase().startsWith(e.toLowerCase()),Qe=(l,e,t,n)=>{const r=[];for(const o of l)if(De(o,e)&&(r.push(n(o)),r.length>=t))break;return r},Zt=(l,e,t)=>{const n=new Map;for(const[r,o]of Object.entries(l.columns))for(const s of o)if(De(s,e)&&!n.has(s)&&(n.set(s,r),n.size>=t))return[...n].map(([d,a])=>({detail:a,kind:"column",label:d}));return[...n].map(([r,o])=>({detail:o,kind:"column",label:r}))},en=(l,e,t)=>{const n=Ge(l,e),r=Xt(l,n.start,t.tables);if(r!==void 0){const a=t.columns[r]??t.columns[r.toLowerCase()]??[];return Qe(a,n.text,Se,i=>({detail:r,kind:"column",label:i}))}if(n.text===""&&!Fe(l,n.start))return[];const o=Qe(t.tables,n.text,Se,a=>({kind:"table",label:a})),s=Zt(t,n.text,Se),d=Jt.flatMap(a=>n.text!==""&&De(a,n.text)&&a.toLowerCase()!==n.text.toLowerCase()?[{kind:"keyword",label:a}]:[]);return(Fe(l,n.start)?[...s,...o,...d]:[...o,...s,...d]).slice(0,Se)},tn=(l,e,t)=>{const n=Ge(l,e),r=l.slice(0,n.start)+t.label+l.slice(n.end);return{caret:n.start+t.label.length,value:r}},nn=["boxSizing","borderBottomWidth","borderLeftWidth","borderRightWidth","borderTopWidth","fontFamily","fontSize","fontStyle","fontWeight","letterSpacing","lineHeight","paddingBottom","paddingLeft","paddingRight","paddingTop","tabSize","textIndent","textTransform","width","wordSpacing"],on=(l,e)=>{const t=globalThis.getComputedStyle(l),n=globalThis.document.createElement("div"),{style:r}=n;r.position="absolute",r.visibility="hidden",r.whiteSpace="pre-wrap",r.overflowWrap="break-word";for(const a of nn)r[a]=t[a];n.textContent=l.value.slice(0,Math.max(0,e));const o=globalThis.document.createElement("span");o.textContent=l.value.slice(Math.max(0,e))||".",n.append(o),globalThis.document.body.append(n);const s=o.offsetLeft-l.scrollLeft,d=o.offsetTop-l.scrollTop;return n.remove(),{left:s,top:d}},rn=(l,e,t)=>{const n=K(16),[r,o]=te(null);let s;n[0]!==l||n[1]!==e?(s=(y,b)=>{const m=en(y,b,l);if(m.length===0){o(null);return}const w=e.current,{left:k,top:S}=w===null?{left:0,top:0}:on(w,b);o(C=>C!==null&&C.active===0&&C.left===k&&C.top===S&&C.suggestions.length===m.length&&C.suggestions.every((q,L)=>{const R=m.at(L);return q.kind===R?.kind&&q.label===R.label&&q.detail===R.detail})?C:{active:0,left:k,suggestions:m,top:S})},n[0]=l,n[1]=e,n[2]=s):s=n[2];const d=s;let a;n[3]===Symbol.for("react.memo_cache_sentinel")?(a=()=>{o(null)},n[3]=a):a=n[3];const i=a;let f;n[4]===Symbol.for("react.memo_cache_sentinel")?(f=y=>{o(b=>{if(b===null)return b;const m=b.suggestions.length,w=(b.active+y+m)%m;return{...b,active:w}})},n[4]=f):f=n[4];const h=f;let p;n[5]!==t||n[6]!==r||n[7]!==e?(p=y=>{const b=e.current;if(r===null||b===null)return!1;const m=r.suggestions[y??r.active];if(m===void 0)return!1;const w=tn(b.value,b.selectionStart,m);return t(w.value),o(null),requestAnimationFrame(()=>{const k=e.current;k!==null&&(k.focus(),k.setSelectionRange(w.caret,w.caret))}),!0},n[5]=t,n[6]=r,n[7]=e,n[8]=p):p=n[8];const x=p;let c;n[9]!==x?(c=()=>x(),n[9]=x,n[10]=c):c=n[10];const g=c;let v;return n[11]!==g||n[12]!==x||n[13]!==d||n[14]!==r?(v={close:i,commit:g,commitAt:x,move:h,refresh:d,state:r},n[11]=g,n[12]=x,n[13]=d,n[14]=r,n[15]=v):v=n[15],v},ln={column:"column",keyword:"keyword",table:"table"},sn=20,an=l=>{const e=K(17),{listboxId:t,onPick:n,state:r}=l,o=oe();let s;e[0]!==r?(s=r===null?void 0:{left:r.left,top:r.top+sn},e[0]=r,e[1]=s):s=e[1];const d=s;if(r===null)return null;let a;if(e[2]!==t||e[3]!==n||e[4]!==r.active||e[5]!==r.suggestions||e[6]!==o){let f;e[8]!==t||e[9]!==n||e[10]!==r.active||e[11]!==o?(f=(h,p)=>B("li",{"aria-selected":p===r.active,className:ue("flex cursor-pointer items-center gap-2 px-2 py-1 text-[13px]",p===r.active?"bg-accent text-accent-foreground":"text-foreground"),"data-testid":"sql-autocomplete-item",id:`${t}-opt-${p.toString()}`,onMouseDown:x=>{x.preventDefault(),n(p)},role:"option",children:[u("span",{className:"truncate font-mono",children:h.label}),h.detail!==void 0&&u("span",{className:"ms-auto truncate text-xs text-muted-foreground",children:h.detail}),u("span",{className:"shrink-0 font-mono text-[10px] tracking-wide text-muted-foreground/70 uppercase",children:o(ln[h.kind])})]},`${h.kind}:${h.label}`),e[8]=t,e[9]=n,e[10]=r.active,e[11]=o,e[12]=f):f=e[12],a=r.suggestions.map(f),e[2]=t,e[3]=n,e[4]=r.active,e[5]=r.suggestions,e[6]=o,e[7]=a}else a=e[7];let i;return e[13]!==t||e[14]!==d||e[15]!==a?(i=u("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:d,children:a}),e[13]=t,e[14]=d,e[15]=a,e[16]=i):i=e[16],i},cn=Te($e.listTables),dn=Te($e.readTablePage),un=l=>{const e=K(16),t=Me();let n;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=[],e[0]=n):n=e[0];const[r,o]=te(n);let s;e[1]===Symbol.for("react.memo_cache_sentinel")?(s={},e[1]=s):s=e[1];const[d,a]=te(s);let i;e[2]===Symbol.for("react.memo_cache_sentinel")?(i=new Set,e[2]=i):i=e[2];const f=ye(i);let h,p;e[3]!==t||e[4]!==l?(h=()=>{const b={cancelled:!1};return de((async()=>{try{const m=await t.query(cn,{},ke(l));b.cancelled||(o(m.map(fn)),a({}),f.current=new Set)}catch{b.cancelled||(o([]),a({}),f.current=new Set)}})()),()=>{b.cancelled=!0}},p=[t,l],e[3]=t,e[4]=l,e[5]=h,e[6]=p):(h=e[5],p=e[6]),qe(h,p);let x;e[7]!==t||e[8]!==l?(x=b=>{f.current.has(b)||(f.current.add(b),de((async()=>{try{const m=await t.query(dn,{limit:1,offset:0,table:b},ke(l));a(w=>({...w,[b]:m.columns}))}catch{f.current.delete(b)}})()))},e[7]=t,e[8]=l,e[9]=x):x=e[9];const c=x;let g;e[10]!==d||e[11]!==r?(g={columns:d,tables:r},e[10]=d,e[11]=r,e[12]=g):g=e[12];const v=g;let y;return e[13]!==c||e[14]!==v?(y={probe:c,schema:v},e[13]=c,e[14]=v,e[15]=y):y=e[15],y},_e=/\b(?:from|join|update|into)\s+([a-z_][\w$]*)|\b([a-z_][\w$]*)\s*\./gi,mn=l=>{const e=new Set;_e.lastIndex=0;let t=_e.exec(l);for(;t!==null;)e.add(t[1]??t[2]),t=_e.exec(l);return[...e]};function fn(l){return l.name}const hn=l=>{const e=K(34),{onSubmit:t,probe:n,schema:r,setDraft:o}=l,s=tt(),d=ye(null),a=ye(null),i=ye(null),f=rn(r,i,o),{close:h,commit:p,commitAt:x,move:c,refresh:g,state:v}=f;let y;e[0]!==x?(y=N=>{x(N)},e[0]=x,e[1]=y):y=e[1];const b=y;let m;e[2]!==g?(m=()=>{const N=i.current;N!==null&&N===document.activeElement&&g(N.value,N.selectionStart)},e[2]=g,e[3]=m):m=e[3];let w;e[4]!==g||e[5]!==r?(w=[g,r],e[4]=g,e[5]=r,e[6]=w):w=e[6],qe(m,w);let k;e[7]!==n||e[8]!==g||e[9]!==o?(k=N=>{const{selectionStart:z,value:P}=N.target;o(P);for(const Q of mn(P))n(Q);g(P,z)},e[7]=n,e[8]=g,e[9]=o,e[10]=k):k=e[10];const S=k;let C;e[11]!==g?(C=N=>{const z=N.currentTarget;g(z.value,z.selectionStart)},e[11]=g,e[12]=C):C=e[12];const q=C;let L;e[13]!==v||e[14]!==h||e[15]!==p||e[16]!==c||e[17]!==t?(L=N=>{if(v!==null){if(N.key==="ArrowDown"){N.preventDefault(),c(1);return}if(N.key==="ArrowUp"){N.preventDefault(),c(-1);return}if(N.key==="Escape"){N.preventDefault(),h();return}if((N.key==="Enter"||N.key==="Tab")&&!N.metaKey&&!N.ctrlKey&&p()){N.preventDefault();return}}(N.metaKey||N.ctrlKey)&&N.key==="Enter"&&(N.preventDefault(),t())},e[13]=v,e[14]=h,e[15]=p,e[16]=c,e[17]=t,e[18]=L):L=e[18];const R=L;let T;e[19]!==h?(T=()=>{requestAnimationFrame(()=>{h()})},e[19]=h,e[20]=T):T=e[20];const I=T;let _;e[21]===Symbol.for("react.memo_cache_sentinel")?(_=N=>{const{scrollLeft:z,scrollTop:P}=N.currentTarget;d.current!==null&&(d.current.scrollTop=P),a.current!==null&&(a.current.scrollTop=P,a.current.scrollLeft=z)},e[21]=_):_=e[21];const O=_;let $;e[22]===Symbol.for("react.memo_cache_sentinel")?($=N=>{const z=i.current;z===null||N.offset===void 0||(z.focus(),z.setSelectionRange(N.offset,N.offset+(N.length??0)))},e[22]=$):$=e[22];const M=$;let E;e[23]!==S||e[24]!==I||e[25]!==R||e[26]!==q?(E={onBlur:I,onChange:S,onKeyDown:R,onScroll:O,onSelect:q},e[23]=S,e[24]=I,e[25]=R,e[26]=q,e[27]=E):E=e[27];let D;return e[28]!==v||e[29]!==h||e[30]!==s||e[31]!==b||e[32]!==E?(D={autocompleteState:v,closeAutocomplete:h,handlers:E,listboxId:s,onPickSuggestion:b,editorRef:i,gutterRef:d,overlayRef:a,revealDiagnostic:M},e[28]=v,e[29]=h,e[30]=s,e[31]=b,e[32]=E,e[33]=D):D=e[33],D},pn="lunora-studio-sql-tabs",bn="lunora-studio-sql-active-tab",Ae=12,ve=(l="",e="")=>({activeId:null,id:We("tab"),name:e,sql:l}),gn=()=>Ke(bn,""),xn=l=>{const e=K(16),[t,n]=Oe(pn),[r,o]=gn(),[s]=te(l);let d,a;e[0]!==s||e[1]!==n||e[2]!==t.length?(d=()=>{t.length===0&&n([s])},a=[s,n,t.length],e[0]=s,e[1]=n,e[2]=t.length,e[3]=d,e[4]=a):(d=e[3],a=e[4]),qe(d,a);let i;e[5]!==s||e[6]!==t?(i=t.length===0?[s]:t,e[5]=s,e[6]=t,e[7]=i):i=e[7];const f=i;let h;e[8]!==r||e[9]!==f?(h=f.some(c=>c.id===r)?r:f[0]?.id??"",e[8]=r,e[9]=f,e[10]=h):h=e[10];const p=h;let x;return e[11]!==p||e[12]!==o||e[13]!==n||e[14]!==f?(x={activeId:p,setActiveId:o,setTabs:n,tabs:f},e[11]=p,e[12]=o,e[13]=n,e[14]=f,e[15]=x):x=e[15],x},Ve=l=>l.activeId===null&&l.sql.trim()!=="",vn=(l,e)=>[...l,e].slice(-Ae),yn=(l,e,t)=>{const n=l.findIndex(o=>o.id===e);if(n===-1)return{activeId:l[0]?.id??"",tabs:[...l]};const r=l.filter(o=>o.id!==e);if(r.length===0){const o=t();return{activeId:o.id,tabs:[o]}}return{activeId:r[Math.min(n,r.length-1)].id,tabs:r}},wn=(l,e)=>{const t=l.filter(n=>n.id===e);return t.length===0?{activeId:l[0]?.id??"",tabs:[...l]}:{activeId:e,tabs:t}},Sn=(l,e,t)=>{const n=l.findIndex(o=>o.id===e);if(n===-1)return{activeId:t,tabs:[...l]};const r=l.slice(0,n+1);return{activeId:r.some(o=>o.id===t)?t:e,tabs:r}},Nn=l=>{const e=l();return{activeId:e.id,tabs:[e]}},kn=(l,e,t)=>{if(l==="others")return e.filter(n=>n.id!==t);if(l==="right"){const n=e.findIndex(r=>r.id===t);return n===-1?[]:e.slice(n+1)}return[...e]},je={error:null,pane:"results",result:null},Cn=l=>{const e=K(66),{activeId:t,setActiveId:n,setTabs:r,tabs:o}=xn(l);let s;e[0]===Symbol.for("react.memo_cache_sentinel")?(s={},e[0]=s):s=e[0];const[d,a]=te(s),[i,f]=te(null),[h,p]=te(null);let x;e[1]!==t||e[2]!==o?(x=o.find(H=>H.id===t)??o[0]??ve(),e[1]=t,e[2]=o,e[3]=x):x=e[3];const c=x,g=d[c.id]??je;let v;e[4]!==c.id||e[5]!==r?(v=H=>{r(W=>W.map(Y=>Y.id===c.id?{...Y,...H}:Y))},e[4]=c.id,e[5]=r,e[6]=v):v=e[6];const y=v;let b;e[7]!==c.id?(b=H=>{a(W=>{const Y=W[c.id]??je;return{...W,[c.id]:{...Y,...H}}})},e[7]=c.id,e[8]=b):b=e[8];const m=b;let w;e[9]!==n||e[10]!==r||e[11]!==o.length?(w=()=>{if(o.length>=Ae)return;const H=ve();r(W=>vn(W,H)),n(H.id)},e[9]=n,e[10]=r,e[11]=o.length,e[12]=w):w=e[12];const k=w;let S;e[13]!==n||e[14]!==r?(S=H=>{f(null),p(null),r(H.tabs),n(H.activeId);const W=new Set(H.tabs.map(qn));a(Y=>Object.fromEntries(Object.entries(Y).filter(ae=>{const[xe]=ae;return W.has(xe)})))},e[13]=n,e[14]=r,e[15]=S):S=e[15];const C=S;let q;e[16]!==C||e[17]!==o?(q=H=>{C(yn(o,H,ve))},e[16]=C,e[17]=o,e[18]=q):q=e[18];const L=q;let R;e[19]!==t||e[20]!==C||e[21]!==o?(R=(H,W)=>{C(H==="others"?wn(o,W):H==="right"?Sn(o,W,t):Nn(ve))},e[19]=t,e[20]=C,e[21]=o,e[22]=R):R=e[22];const T=R;let I;e[23]!==T||e[24]!==i||e[25]!==o?(I=H=>{i!==null&&(kn(H,o,i.id).some($n)?p(H):T(H,i.id))},e[23]=T,e[24]=i,e[25]=o,e[26]=I):I=e[26];const _=I;let O;e[27]===Symbol.for("react.memo_cache_sentinel")?(O=(H,W)=>{W.preventDefault(),p(null),f({id:H,x:W.clientX,y:W.clientY})},e[27]=O):O=e[27];const $=O;let M;e[28]===Symbol.for("react.memo_cache_sentinel")?(M=()=>{f(null),p(null)},e[28]=M):M=e[28];const E=M;let D;e[29]===Symbol.for("react.memo_cache_sentinel")?(D=H=>{H.preventDefault(),f(null),p(null)},e[29]=D):D=e[29];const N=D;let z;e[30]!==_?(z=()=>{_("others")},e[30]=_,e[31]=z):z=e[31];const P=z;let Q;e[32]!==_?(Q=()=>{_("right")},e[32]=_,e[33]=Q):Q=e[33];const j=Q;let F;e[34]!==_?(F=()=>{_("all")},e[34]=_,e[35]=F):F=e[35];const X=F;let U;e[36]!==T||e[37]!==h||e[38]!==i?(U=()=>{i!==null&&h!==null&&T(h,i.id),p(null)},e[36]=T,e[37]=h,e[38]=i,e[39]=U):U=e[39];const ne=U;let A;e[40]===Symbol.for("react.memo_cache_sentinel")?(A=()=>{p(null)},e[40]=A):A=e[40];const re=A;let J;e[41]!==i?(J=i===null?void 0:{left:i.x,top:i.y},e[41]=i,e[42]=J):J=e[42];const Z=J;let G;e[43]!==r?(G=H=>{r(W=>W.map(Y=>Y.activeId===H?{...Y,activeId:null}:Y))},e[43]=r,e[44]=G):G=e[44];const ee=G;let V;e[45]!==r?(V=(H,W)=>{r(Y=>Y.map(ae=>ae.id===H?{...ae,name:W}:ae))},e[45]=r,e[46]=V):V=e[46];const le=V;let ie;return e[47]!==c||e[48]!==t||e[49]!==k||e[50]!==L||e[51]!==ne||e[52]!==X||e[53]!==P||e[54]!==j||e[55]!==g||e[56]!==m||e[57]!==y||e[58]!==h||e[59]!==le||e[60]!==n||e[61]!==i||e[62]!==Z||e[63]!==o||e[64]!==ee?(ie={activeTab:c,activeTabId:t,addEditorTab:k,cancelBulk:re,closeEditorTab:L,closeTabMenu:E,confirmBulk:ne,menuStyle:Z,onBackdropContextMenu:N,onCloseAll:X,onCloseOthers:P,onCloseToRight:j,openTabMenu:$,output:g,patchActiveOutput:m,patchActiveTab:y,pendingBulk:h,renameTab:le,setActiveTabId:n,tabMenu:i,tabs:o,unlinkQuery:ee},e[47]=c,e[48]=t,e[49]=k,e[50]=L,e[51]=ne,e[52]=X,e[53]=P,e[54]=j,e[55]=g,e[56]=m,e[57]=y,e[58]=h,e[59]=le,e[60]=n,e[61]=i,e[62]=Z,e[63]=o,e[64]=ee,e[65]=ie):ie=e[65],ie};function qn(l){return l.id}function $n(l){return Ve(l)}const Tn="lunora-studio-sql-queries",Rn="lunora-studio-sql-history",In=25,En=l=>{const e=K(33),{loadIntoActiveTab:t,unlinkQuery:n}=l,r=oe(),[o,s]=Oe(Tn),[d,a]=Oe(Rn),[i,f]=te(""),h=ye(null);let p;e[0]!==a?(p=$=>{a(M=>M[0]?.sql===$?M:[{at:Date.now(),sql:$},...M.filter(E=>E.sql!==$)].slice(0,In))},e[0]=a,e[1]=p):p=e[1];const x=p;let c;e[2]!==t||e[3]!==s||e[4]!==r?(c=()=>{const $={id:We("q"),name:r("Untitled query"),sql:""};s(M=>[$,...M]),t("",$.id)},e[2]=t,e[3]=s,e[4]=r,e[5]=c):c=e[5];const g=c;let v;e[6]!==t||e[7]!==o?(v=$=>{const M=o.find(E=>E.id===$);M!==void 0&&(t(M.sql,$),h.current?.querySelector(`[data-testid="sql-query-${$}"]`)?.scrollIntoView({block:"nearest"}))},e[6]=t,e[7]=o,e[8]=v):v=e[8];const y=v;let b;e[9]!==s||e[10]!==n?(b=$=>{s(M=>M.filter(E=>E.id!==$)),n($)},e[9]=s,e[10]=n,e[11]=b):b=e[11];const m=b;let w;e[12]!==t?(w=$=>{t($.currentTarget.dataset.sql??"",null)},e[12]=t,e[13]=w):w=e[13];const k=w;let S;e[14]!==t?(S=$=>{t($.currentTarget.dataset.sql??"",null)},e[14]=t,e[15]=S):S=e[15];const C=S;let q;e[16]!==a?(q=()=>{a([])},e[16]=a,e[17]=q):q=e[17];const L=q;let R;e[18]===Symbol.for("react.memo_cache_sentinel")?(R=$=>{f($.target.value)},e[18]=R):R=e[18];const T=R;let I;e[19]!==s?(I=($,M)=>{s(E=>E.map(D=>D.id===$?{...D,sql:M}:D))},e[19]=s,e[20]=I):I=e[20];const _=I;let O;return e[21]!==L||e[22]!==m||e[23]!==d||e[24]!==C||e[25]!==k||e[26]!==g||e[27]!==o||e[28]!==x||e[29]!==i||e[30]!==y||e[31]!==_?(O={clearHistory:L,deleteQuery:m,history:d,listRef:h,loadFromHistory:C,loadTemplate:k,newQuery:g,onSearchChange:T,queries:o,recordHistory:x,search:i,selectQuery:y,updateQuerySql:_},e[21]=L,e[22]=m,e[23]=d,e[24]=C,e[25]=k,e[26]=g,e[27]=o,e[28]=x,e[29]=i,e[30]=y,e[31]=_,e[32]=O):O=e[32],O},Xe="p-3 font-mono text-xs leading-5 whitespace-pre-wrap break-words",Ln=(l,e)=>{const t=[];for(const r of l){if(r.offset===void 0||r.length===void 0||r.length<=0)continue;const o=Math.max(0,Math.min(r.offset,e)),s=Math.max(o,Math.min(r.offset+r.length,e));o!==s&&t.push({end:s,severity:r.severity,start:o})}t.sort((r,o)=>r.start-o.start);const n=[];for(const r of t)r.start>=(n.at(-1)?.end??0)&&n.push(r);return n},_n=l=>l==="unsafe-response"?"The model returned a statement that is not read-only, so it was discarded.":l==="empty-response"?"The model returned nothing usable.":"The model could not be reached.",On=l=>{const e=K(51),{assistant:t,failed:n,onGenerated:r}=l,o=oe(),[s,d]=te("");if(t.unavailable)return null;let a;e[0]!==t?(a=t.pending("sql"),e[0]=t,e[1]=a):a=e[1];const i=a;let f;if(e[2]!==t||e[3]!==n||e[4]!==r||e[5]!==i||e[6]!==s||e[7]!==o){const h=t.reason("sql");let p;e[9]!==t||e[10]!==n||e[11]!==r||e[12]!==s?(p=T=>{const I=s.trim();I===""&&!T||de((async()=>{const _=await t.generate(I===""?"fix the failing statement":I,T?n:void 0);_!==void 0&&r(_)})())},e[9]=t,e[10]=n,e[11]=r,e[12]=s,e[13]=p):p=e[13];const x=p;let c;e[14]!==o?(c=o("Describe the query you want"),e[14]=o,e[15]=c):c=e[15];let g;e[16]===Symbol.for("react.memo_cache_sentinel")?(g=T=>{d(T.target.value)},e[16]=g):g=e[16];let v;e[17]!==x?(v=T=>{T.key==="Enter"&&(T.preventDefault(),x(!1))},e[17]=x,e[18]=v):v=e[18];let y;e[19]!==o?(y=o("Describe the query you want"),e[19]=o,e[20]=y):y=e[20];let b;e[21]!==i||e[22]!==s||e[23]!==c||e[24]!==v||e[25]!==y?(b=u(lt,{"aria-label":c,className:"h-7 flex-1 text-xs","data-testid":"sql-assistant-prompt",disabled:i,onChange:g,onKeyDown:v,placeholder:y,value:s}),e[21]=i,e[22]=s,e[23]=c,e[24]=v,e[25]=y,e[26]=b):b=e[26];const m=i&&"opacity-60";let w;e[27]!==m?(w=ue("rounded-md border border-border px-2 py-1 text-xs outline-none transition-colors hover:bg-accent focus-visible:bg-accent",m),e[27]=m,e[28]=w):w=e[28];let k;e[29]!==i||e[30]!==s?(k=i||s.trim()==="",e[29]=i,e[30]=s,e[31]=k):k=e[31];let S;e[32]!==x?(S=()=>{x(!1)},e[32]=x,e[33]=S):S=e[33];let C;e[34]!==i||e[35]!==o?(C=o(i?"Thinking…":"Draft SQL"),e[34]=i,e[35]=o,e[36]=C):C=e[36];let q;e[37]!==w||e[38]!==k||e[39]!==S||e[40]!==C?(q=u("button",{className:w,"data-testid":"sql-assistant-generate",disabled:k,onClick:S,type:"button",children:C}),e[37]=w,e[38]=k,e[39]=S,e[40]=C,e[41]=q):q=e[41];let L;e[42]!==n||e[43]!==i||e[44]!==x||e[45]!==o?(L=n!==void 0&&u("button",{className:"rounded-md border border-border px-2 py-1 text-xs outline-none transition-colors hover:bg-accent focus-visible:bg-accent","data-testid":"sql-assistant-fix",disabled:i,onClick:()=>{x(!0)},type:"button",children:o("Fix this")}),e[42]=n,e[43]=i,e[44]=x,e[45]=o,e[46]=L):L=e[46];let R;e[47]!==q||e[48]!==L||e[49]!==b?(R=B("div",{className:"flex items-center gap-2",children:[b,q,L]}),e[47]=q,e[48]=L,e[49]=b,e[50]=R):R=e[50],f=B("div",{className:"flex flex-col gap-1 border-b border-border px-3 py-2","data-testid":"sql-assistant",children:[R,h!==void 0&&u("p",{className:"text-[11px] text-muted-foreground","data-testid":"sql-assistant-reason",role:"status",children:_n(h)})]}),e[2]=t,e[3]=n,e[4]=r,e[5]=i,e[6]=s,e[7]=o,e[8]=f}else f=e[8];return f},Mn=l=>{const e=K(8),{diagnostics:t,draft:n,scrollRef:r}=l;let o,s;if(e[0]!==t||e[1]!==n){s=Symbol.for("react.early_return_sentinel");e:{const i=Ln(t,n.length);if(i.length===0){s=null;break e}o=[];let f=0;for(const[h,p]of i.entries())p.start>f&&o.push(n.slice(f,p.start)),o.push(u("span",{className:ue("decoration-wavy underline underline-offset-4",p.severity==="error"?"decoration-destructive":"decoration-amber-500"),children:n.slice(p.start,p.end)},`${p.start.toString()}-${h.toString()}`)),f=p.end;o.push(n.slice(f))}e[0]=t,e[1]=n,e[2]=o,e[3]=s}else o=e[2],s=e[3];if(s!==Symbol.for("react.early_return_sentinel"))return s;let d;e[4]===Symbol.for("react.memo_cache_sentinel")?(d=ue("pointer-events-none absolute inset-0 overflow-hidden text-transparent",Xe),e[4]=d):d=e[4];let a;return e[5]!==o||e[6]!==r?(a=u("div",{"aria-hidden":"true",className:d,"data-testid":"sql-diagnostics-overlay",ref:r,children:o}),e[5]=o,e[6]=r,e[7]=a):a=e[7],a},Dn={gate:"read-only",plan:"plan",schema:"schema",syntax:"syntax"},An=l=>{const e=K(10),{diagnostics:t,onSelect:n}=l,r=oe();if(t.length===0)return null;let o;e[0]!==r?(o=r("SQL problems"),e[0]=r,e[1]=o):o=e[1];let s;if(e[2]!==t||e[3]!==n){let a;e[5]!==n?(a=(i,f)=>u("li",{children:B("button",{className:"flex w-full items-start gap-2 px-3 py-1 text-start text-xs outline-none hover:bg-accent focus-visible:bg-accent","data-testid":"sql-problem",onClick:()=>{n(i)},type:"button",children:[u("span",{className:ue("mt-px shrink-0 rounded px-1 font-mono text-[10px] uppercase",i.severity==="error"?"bg-destructive/15 text-destructive":"bg-amber-500/15 text-amber-600"),children:Dn[i.source]}),u("span",{className:"min-w-0 text-muted-foreground",children:i.message})]})},`${i.source}-${(i.offset??f).toString()}-${f.toString()}`),e[5]=n,e[6]=a):a=e[6],s=t.map(a),e[2]=t,e[3]=n,e[4]=s}else s=e[4];let d;return e[7]!==o||e[8]!==s?(d=u("ul",{"aria-label":o,className:"max-h-24 shrink-0 overflow-y-auto border-t border-border bg-muted/30","data-testid":"sql-problems",children:s}),e[7]=o,e[8]=s,e[9]=d):d=e[9],d},Bn={minWidth:"2.75rem",paddingInline:"0.5rem"},zn=l=>{const e=K(64),{assistant:t,autocomplete:n,diagnostics:r,draft:o,failed:s,handlers:d,editorRef:a,gutterRef:i,listboxId:f,onGenerated:h,onPickSuggestion:p,onRevealDiagnostic:x,overlayRef:c}=l,g=oe();let v,y,b,m,w,k,S,C;if(e[0]!==t||e[1]!==o||e[2]!==s||e[3]!==i||e[4]!==h){const z=o.split(`
5
+ `).length;S="flex min-h-0 min-w-0 flex-1 flex-col",e[13]!==t||e[14]!==s||e[15]!==h?(C=u(On,{assistant:t,failed:s,onGenerated:h}),e[13]=t,e[14]=s,e[15]=h,e[16]=C):C=e[16],k="flex min-h-0 min-w-0 flex-1",v="true",y="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",b=i,m=Bn,w=Array.from({length:z},Hn),e[0]=t,e[1]=o,e[2]=s,e[3]=i,e[4]=h,e[5]=v,e[6]=y,e[7]=b,e[8]=m,e[9]=w,e[10]=k,e[11]=S,e[12]=C}else v=e[5],y=e[6],b=e[7],m=e[8],w=e[9],k=e[10],S=e[11],C=e[12];let q;e[17]!==v||e[18]!==y||e[19]!==b||e[20]!==m||e[21]!==w?(q=u("div",{"aria-hidden":v,className:y,ref:b,style:m,children:w}),e[17]=v,e[18]=y,e[19]=b,e[20]=m,e[21]=w,e[22]=q):q=e[22];let L;e[23]!==r||e[24]!==o||e[25]!==c?(L=u(Mn,{diagnostics:r,draft:o,scrollRef:c}),e[23]=r,e[24]=o,e[25]=c,e[26]=L):L=e[26];let R;e[27]!==n||e[28]!==f?(R=n===null?void 0:`${f}-opt-${n.active.toString()}`,e[27]=n,e[28]=f,e[29]=R):R=e[29];const T=n===null?void 0:f,I=n!==null;let _;e[30]!==g?(_=g("SQL query"),e[30]=g,e[31]=_):_=e[31];let O;e[32]!==o||e[33]!==a||e[34]!==d.onBlur||e[35]!==d.onChange||e[36]!==d.onKeyDown||e[37]!==d.onScroll||e[38]!==d.onSelect||e[39]!==R||e[40]!==T||e[41]!==I||e[42]!==_?(O=u("textarea",{"aria-activedescendant":R,"aria-autocomplete":"list","aria-controls":T,"aria-expanded":I,"aria-label":_,className:`relative size-full resize-none bg-transparent outline-none ${Xe}`,"data-testid":"sql-input",onBlur:d.onBlur,onChange:d.onChange,onKeyDown:d.onKeyDown,onScroll:d.onScroll,onSelect:d.onSelect,placeholder:"SELECT * FROM …",ref:a,role:"combobox",spellCheck:!1,value:o}),e[32]=o,e[33]=a,e[34]=d.onBlur,e[35]=d.onChange,e[36]=d.onKeyDown,e[37]=d.onScroll,e[38]=d.onSelect,e[39]=R,e[40]=T,e[41]=I,e[42]=_,e[43]=O):O=e[43];let $;e[44]!==n||e[45]!==f||e[46]!==p?($=u(an,{listboxId:f,onPick:p,state:n}),e[44]=n,e[45]=f,e[46]=p,e[47]=$):$=e[47];let M;e[48]!==L||e[49]!==O||e[50]!==$?(M=B("div",{className:"relative min-w-0 flex-1 bg-background",children:[L,O,$]}),e[48]=L,e[49]=O,e[50]=$,e[51]=M):M=e[51];let E;e[52]!==M||e[53]!==k||e[54]!==q?(E=B("div",{className:k,children:[q,M]}),e[52]=M,e[53]=k,e[54]=q,e[55]=E):E=e[55];let D;e[56]!==r||e[57]!==x?(D=u(An,{diagnostics:r,onSelect:x}),e[56]=r,e[57]=x,e[58]=D):D=e[58];let N;return e[59]!==E||e[60]!==D||e[61]!==S||e[62]!==C?(N=B("div",{className:S,children:[C,E,D]}),e[59]=E,e[60]=D,e[61]=S,e[62]=C,e[63]=N):N=e[63],N};function Hn(l,e){return u("div",{children:e+1},e)}const Ze=[{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;"}],Pn=l=>{const e=K(29),{active:t,onDelete:n,onSelect:r,query:o}=l,s=oe();let d;e[0]!==r||e[1]!==o.id?(d=()=>{r(o.id)},e[0]=r,e[1]=o.id,e[2]=d):d=e[2];const a=d;let i;e[3]!==n||e[4]!==o.id?(i=S=>{S.stopPropagation(),n(o.id)},e[3]=n,e[4]=o.id,e[5]=i):i=e[5];const f=i,h=t?"bg-sidebar-accent font-medium text-foreground":"text-muted-foreground";let p;e[6]!==h?(p=ue("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",h),e[6]=h,e[7]=p):p=e[7];const x=`sql-query-${o.id}`;let c;e[8]===Symbol.for("react.memo_cache_sentinel")?(c=u("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:u("path",{d:"M4 6h16M4 12h10M4 18h7"})}),e[8]=c):c=e[8];let g;e[9]!==o.name?(g=u("span",{className:"truncate",children:o.name}),e[9]=o.name,e[10]=g):g=e[10];let v;e[11]!==t||e[12]!==a||e[13]!==p||e[14]!==x||e[15]!==g?(v=B("button",{"aria-pressed":t,className:p,"data-testid":x,onClick:a,type:"button",children:[c,g]}),e[11]=t,e[12]=a,e[13]=p,e[14]=x,e[15]=g,e[16]=v):v=e[16];let y;e[17]!==s?(y=s("Delete query"),e[17]=s,e[18]=y):y=e[18];let b;e[19]!==s?(b=s("Delete query"),e[19]=s,e[20]=b):b=e[20];let m;e[21]===Symbol.for("react.memo_cache_sentinel")?(m=u("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:u("path",{d:"M5 7h14M9 7V5h6v2m-1 0v12H10V7M7 7v13h10V7"})}),e[21]=m):m=e[21];let w;e[22]!==f||e[23]!==b||e[24]!==y?(w=u("button",{"aria-label":y,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:f,title:b,type:"button",children:m}),e[22]=f,e[23]=b,e[24]=y,e[25]=w):w=e[25];let k;return e[26]!==w||e[27]!==v?(k=B("li",{className:"group/q flex items-center",children:[v,w]}),e[26]=w,e[27]=v,e[28]=k):k=e[28],k},Fn=(l,e)=>{const t=e.trim().toLowerCase();return t===""?[...l]:l.filter(n=>n.name.toLowerCase().includes(t))},Qn=l=>{const e=K(60),{activeId:t,history:n,listRef:r,onClearHistory:o,onDelete:s,onLoadHistory:d,onLoadTemplate:a,onNew:i,onSearchChange:f,onSelect:h,queries:p,search:x}=l,c=oe();let g,v,y,b;if(e[0]!==t||e[1]!==r||e[2]!==s||e[3]!==i||e[4]!==f||e[5]!==h||e[6]!==p||e[7]!==x||e[8]!==c){const T=Fn(p,x);v="flex h-full w-64 shrink-0 flex-col border-e border-border bg-sidebar";let I;e[13]!==c?(I=c("Search queries…"),e[13]=c,e[14]=I):I=e[14];let _;e[15]!==f||e[16]!==x||e[17]!==I?(_=u("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:f,placeholder:I,type:"text",value:x}),e[15]=f,e[16]=x,e[17]=I,e[18]=_):_=e[18];let O;e[19]!==c?(O=c("New query"),e[19]=c,e[20]=O):O=e[20];let $;e[21]!==c?($=c("New query"),e[21]=c,e[22]=$):$=e[22];let M;e[23]===Symbol.for("react.memo_cache_sentinel")?(M=u("svg",{"aria-hidden":"true",className:"size-4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.7,viewBox:"0 0 24 24",children:u("path",{d:"M12 5v14M5 12h14"})}),e[23]=M):M=e[23];let E;e[24]!==i||e[25]!==O||e[26]!==$?(E=u("button",{"aria-label":O,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:i,title:$,type:"button",children:M}),e[24]=i,e[25]=O,e[26]=$,e[27]=E):E=e[27],e[28]!==E||e[29]!==_?(y=B("div",{className:"flex shrink-0 items-center gap-2 border-b border-border p-2",children:[_,E]}),e[28]=E,e[29]=_,e[30]=y):y=e[30],g="flex flex-1 flex-col gap-4 overflow-y-auto p-2";let D;e[31]!==c?(D=c("Private"),e[31]=c,e[32]=D):D=e[32];let N;e[33]!==D?(N=u("p",{className:"px-1 pb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:D}),e[33]=D,e[34]=N):N=e[34],b=B("div",{children:[N,T.length===0?u("p",{className:"px-1 py-2 text-xs text-muted-foreground","data-testid":"sql-private-empty",children:c("No saved queries yet — they save to this browser as you type.")}):u("ul",{className:"flex flex-col gap-px","data-testid":"sql-private",ref:r,children:T.map(z=>u(Pn,{active:t===z.id,onDelete:s,onSelect:h,query:z},z.id))})]}),e[0]=t,e[1]=r,e[2]=s,e[3]=i,e[4]=f,e[5]=h,e[6]=p,e[7]=x,e[8]=c,e[9]=g,e[10]=v,e[11]=y,e[12]=b}else g=e[9],v=e[10],y=e[11],b=e[12];let m;e[35]!==c?(m=c("Reference"),e[35]=c,e[36]=m):m=e[36];let w;e[37]!==m?(w=u("p",{className:"px-1 pb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:m}),e[37]=m,e[38]=w):w=e[38];let k;e[39]!==a?(k=Ze.map(T=>u("li",{children:B("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:a,type:"button",children:[u("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:u("path",{d:"M7 4h7l4 4v12H7zM14 4v4h4"})}),T.label]})},T.label)),e[39]=a,e[40]=k):k=e[40];let S;e[41]!==k?(S=u("ul",{className:"flex flex-col gap-px",children:k}),e[41]=k,e[42]=S):S=e[42];let C;e[43]!==w||e[44]!==S?(C=B("div",{children:[w,S]}),e[43]=w,e[44]=S,e[45]=C):C=e[45];let q;e[46]!==n||e[47]!==o||e[48]!==d||e[49]!==c?(q=n.length>0&&B("div",{children:[B("div",{className:"flex items-center justify-between px-1 pb-1",children:[u("p",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:c("History")}),u("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:o,type:"button",children:c("Clear history")})]}),u("ul",{className:"flex flex-col gap-px","data-testid":"sql-history",children:n.map(T=>u("li",{children:B("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:d,title:T.sql,type:"button",children:[u("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:u("path",{d:"M12 8v4l3 2M12 21a9 9 0 1 1 0-18 9 9 0 0 1 0 18Z"})}),u("span",{className:"truncate font-mono",children:T.sql})]})},`${T.at.toString()}:${T.sql}`))})]}),e[46]=n,e[47]=o,e[48]=d,e[49]=c,e[50]=q):q=e[50];let L;e[51]!==g||e[52]!==q||e[53]!==b||e[54]!==C?(L=B("div",{className:g,children:[b,C,q]}),e[51]=g,e[52]=q,e[53]=b,e[54]=C,e[55]=L):L=e[55];let R;return e[56]!==L||e[57]!==v||e[58]!==y?(R=B("aside",{className:v,children:[y,L]}),e[56]=L,e[57]=v,e[58]=y,e[59]=R):R=e[59],R},jn=l=>{const e=K(19),{result:t}=l,n=oe();if(t.columns.length===0){let i;e[0]!==t.rowCount||e[1]!==n?(i=n("{count} rows",{count:t.rowCount}),e[0]=t.rowCount,e[1]=n,e[2]=i):i=e[2];let f;return e[3]!==i?(f=u("p",{className:"p-4 text-sm text-muted-foreground",children:i}),e[3]=i,e[4]=f):f=e[4],f}let r;e[5]!==t.columns?(r=t.columns.map(Wn),e[5]=t.columns,e[6]=r):r=e[6];let o;e[7]!==r?(o=u(dt,{className:"sticky top-0 z-10 bg-muted",children:u(Pe,{children:r})}),e[7]=r,e[8]=o):o=e[8];let s;if(e[9]!==t.columns||e[10]!==t.rows){let i;e[12]!==t.columns?(i=(f,h)=>u(Pe,{"data-testid":"sql-row",children:t.columns.map(p=>u(ht,{className:"max-w-md truncate font-mono text-xs",children:u(pt,{value:f[p]})},p))},h),e[12]=t.columns,e[13]=i):i=e[13],s=t.rows.map(i),e[9]=t.columns,e[10]=t.rows,e[11]=s}else s=e[11];let d;e[14]!==s?(d=u(ut,{children:s}),e[14]=s,e[15]=d):d=e[15];let a;return e[16]!==o||e[17]!==d?(a=B(mt,{"data-testid":"sql-rows",children:[o,d]}),e[16]=o,e[17]=d,e[18]=a):a=e[18],a};function Wn(l){return u(ft,{children:l},l)}const Ne=l=>`border-b-2 px-3 py-2 text-sm outline-none transition-colors ${l?"border-foreground font-medium text-foreground":"border-transparent text-muted-foreground hover:text-foreground"}`,Kn=l=>{const e=K(92),{assistant:t,chart:n,className:r,error:o,onFormat:s,onInferChart:d,onRun:a,onShardKeyChange:i,onShowChart:f,onShowExplain:h,onShowResults:p,onToggleSplit:x,pane:c,result:g,running:v,shardKey:y,splitView:b}=l,m=oe(),w=c==="results";let k;e[0]!==w?(k=Ne(w),e[0]=w,e[1]=k):k=e[1];let S;e[2]!==m?(S=m("Results"),e[2]=m,e[3]=S):S=e[3];let C;e[4]!==p||e[5]!==k||e[6]!==S?(C=u("button",{className:k,"data-testid":"sql-tab-results",onClick:p,type:"button",children:S}),e[4]=p,e[5]=k,e[6]=S,e[7]=C):C=e[7];const q=c==="chart";let L;e[8]!==q?(L=Ne(q),e[8]=q,e[9]=L):L=e[9];let R;e[10]!==m?(R=m("Chart"),e[10]=m,e[11]=R):R=e[11];let T;e[12]!==f||e[13]!==L||e[14]!==R?(T=u("button",{className:L,"data-testid":"sql-tab-chart",onClick:f,type:"button",children:R}),e[12]=f,e[13]=L,e[14]=R,e[15]=T):T=e[15];let I;e[16]!==t||e[17]!==d||e[18]!==c||e[19]!==g||e[20]!==m?(I=!t.unavailable&&c==="chart"&&g!==null&&u("button",{className:Ne(!1),"data-testid":"sql-infer-chart",disabled:t.pending("chart"),onClick:d,type:"button",children:t.pending("chart")?m("Thinking…"):m("Suggest chart")}),e[16]=t,e[17]=d,e[18]=c,e[19]=g,e[20]=m,e[21]=I):I=e[21];const _=c==="explain";let O;e[22]!==_?(O=Ne(_),e[22]=_,e[23]=O):O=e[23];let $;e[24]!==m?($=m("Explain"),e[24]=m,e[25]=$):$=e[25];let M;e[26]!==h||e[27]!==O||e[28]!==$?(M=u("button",{className:O,"data-testid":"sql-tab-explain",onClick:h,type:"button",children:$}),e[26]=h,e[27]=O,e[28]=$,e[29]=M):M=e[29];let E;e[30]!==m?(E=m("Split editor and results"),e[30]=m,e[31]=E):E=e[31];const D=`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 ${b?"bg-accent text-foreground":"text-muted-foreground"}`;let N;e[32]!==m?(N=m("Split editor and results"),e[32]=m,e[33]=N):N=e[33];let z;e[34]===Symbol.for("react.memo_cache_sentinel")?(z=B("svg",{"aria-hidden":"true",className:"size-4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.7,viewBox:"0 0 24 24",children:[u("rect",{height:"16",rx:"2",width:"18",x:"3",y:"4"}),u("path",{d:"M12 4v16"})]}),e[34]=z):z=e[34];let P;e[35]!==x||e[36]!==b||e[37]!==E||e[38]!==D||e[39]!==N?(P=u("button",{"aria-label":E,"aria-pressed":b,className:D,"data-testid":"sql-split-toggle",onClick:x,title:N,type:"button",children:z}),e[35]=x,e[36]=b,e[37]=E,e[38]=D,e[39]=N,e[40]=P):P=e[40];let Q;e[41]!==g?(Q=g!==null&&g.columns.length>0&&u(ct,{columns:g.columns,name:"query-result",rows:g.rows}),e[41]=g,e[42]=Q):Q=e[42];let j;e[43]!==m?(j=m("Format"),e[43]=m,e[44]=j):j=e[44];let F;e[45]!==s||e[46]!==v||e[47]!==j?(F=u("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:v,onClick:s,type:"button",children:j}),e[45]=s,e[46]=v,e[47]=j,e[48]=F):F=e[48];let X;e[49]!==i||e[50]!==y?(X=u(at,{onChange:i,testId:"sql-shard-input",value:y}),e[49]=i,e[50]=y,e[51]=X):X=e[51];let U;e[52]!==v||e[53]!==m?(U=m(v?"Running…":"Run"),e[52]=v,e[53]=m,e[54]=U):U=e[54];let ne;e[55]===Symbol.for("react.memo_cache_sentinel")?(ne=u("kbd",{className:"rounded border border-primary-foreground/30 px-1 font-sans text-[10px]",children:"⌘↵"}),e[55]=ne):ne=e[55];let A;e[56]!==a||e[57]!==v||e[58]!==U?(A=B("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:v,onClick:a,type:"button",children:[U,ne]}),e[56]=a,e[57]=v,e[58]=U,e[59]=A):A=e[59];let re;e[60]!==P||e[61]!==Q||e[62]!==F||e[63]!==X||e[64]!==A?(re=B("div",{className:"ms-auto flex items-center gap-2",children:[P,Q,F,X,A]}),e[60]=P,e[61]=Q,e[62]=F,e[63]=X,e[64]=A,e[65]=re):re=e[65];let J;e[66]!==M||e[67]!==re||e[68]!==C||e[69]!==T||e[70]!==I?(J=B("div",{className:"flex shrink-0 items-center gap-2 border-b border-border pe-2",children:[C,T,I,M,re]}),e[66]=M,e[67]=re,e[68]=C,e[69]=T,e[70]=I,e[71]=J):J=e[71];let Z;e[72]!==o?(Z=o!==null&&u(it,{className:"m-3 font-mono text-xs",testId:"sql-error",variant:"destructive",children:o}),e[72]=o,e[73]=Z):Z=e[73];let G;e[74]!==o||e[75]!==g||e[76]!==m?(G=o===null&&g===null&&u("p",{className:"p-4 text-sm text-muted-foreground","data-testid":"sql-empty",children:m("Click Run to execute your query.")}),e[74]=o,e[75]=g,e[76]=m,e[77]=G):G=e[77];let ee;e[78]!==n||e[79]!==o||e[80]!==c||e[81]!==g||e[82]!==m?(ee=o===null&&g!==null&&B("div",{"data-testid":"sql-result",children:[c==="chart"?u(st,{axes:n,result:g}):u(jn,{result:g}),u("p",{className:"border-t border-border px-3 py-1.5 text-xs text-muted-foreground","data-testid":"sql-count",children:g.truncated?m("Showing the first {max} of {count} rows.",{count:g.rowCount,max:g.rows.length}):m("{count} rows",{count:g.rowCount})})]}),e[78]=n,e[79]=o,e[80]=c,e[81]=g,e[82]=m,e[83]=ee):ee=e[83];let V;e[84]!==Z||e[85]!==G||e[86]!==ee?(V=B("div",{className:"min-h-0 flex-1 overflow-auto",children:[Z,G,ee]}),e[84]=Z,e[85]=G,e[86]=ee,e[87]=V):V=e[87];let le;return e[88]!==r||e[89]!==J||e[90]!==V?(le=B("div",{className:r,children:[J,V]}),e[88]=r,e[89]=J,e[90]=V,e[91]=le):le=e[91],le},Un=(l,e)=>l.trim()===""?e:(l.split(`
6
+ `)[0]??l).slice(0,24),Yn=l=>{l?.focus(),l?.select()},Jn=l=>{const e=K(14),{initial:t,onCancel:n,onCommit:r,placeholder:o,testId:s}=l,d=oe();let a;e[0]!==r?(a=c=>{r(c.currentTarget.value.trim())},e[0]=r,e[1]=a):a=e[1];const i=a;let f;e[2]!==n||e[3]!==r?(f=c=>{c.key==="Enter"?r(c.currentTarget.value.trim()):c.key==="Escape"&&n()},e[2]=n,e[3]=r,e[4]=f):f=e[4];const h=f;let p;e[5]!==d?(p=d("Tab title"),e[5]=d,e[6]=p):p=e[6];let x;return e[7]!==t||e[8]!==i||e[9]!==h||e[10]!==o||e[11]!==p||e[12]!==s?(x=u("input",{"aria-label":p,className:"w-40 rounded border border-ring bg-background px-1 py-0.5 text-xs outline-none","data-testid":s,defaultValue:t,onBlur:i,onKeyDown:h,placeholder:o,ref:Yn,type:"text"}),e[7]=t,e[8]=i,e[9]=h,e[10]=o,e[11]=p,e[12]=s,e[13]=x):x=e[13],x},Gn=l=>{const e=K(29),{idBase:t,onDiscard:n,onKeep:r}=l,o=oe(),s=`sql-tab-close-prompt-${t}`;let d;e[0]!==o?(d=o("Discard?"),e[0]=o,e[1]=d):d=e[1];let a;e[2]!==d?(a=u("span",{className:"text-[11px] text-muted-foreground",children:d}),e[2]=d,e[3]=a):a=e[3];let i;e[4]!==o?(i=o("Discard changes"),e[4]=o,e[5]=i):i=e[5];const f=`sql-tab-close-confirm-${t}`;let h;e[6]!==o?(h=o("Discard changes"),e[6]=o,e[7]=h):h=e[7];let p;e[8]===Symbol.for("react.memo_cache_sentinel")?(p=u("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2.4,viewBox:"0 0 24 24",children:u("path",{d:"M5 13l4 4L19 7"})}),e[8]=p):p=e[8];let x;e[9]!==n||e[10]!==i||e[11]!==f||e[12]!==h?(x=u("button",{"aria-label":i,className:"flex size-5 items-center justify-center rounded text-destructive hover:bg-destructive/10","data-testid":f,onClick:n,title:h,type:"button",children:p}),e[9]=n,e[10]=i,e[11]=f,e[12]=h,e[13]=x):x=e[13];let c;e[14]!==o?(c=o("Keep editing"),e[14]=o,e[15]=c):c=e[15];const g=`sql-tab-close-cancel-${t}`;let v;e[16]!==o?(v=o("Keep editing"),e[16]=o,e[17]=v):v=e[17];let y;e[18]===Symbol.for("react.memo_cache_sentinel")?(y=u("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2.4,viewBox:"0 0 24 24",children:u("path",{d:"M6 6l12 12M18 6 6 18"})}),e[18]=y):y=e[18];let b;e[19]!==r||e[20]!==g||e[21]!==v||e[22]!==c?(b=u("button",{"aria-label":c,className:"flex size-5 items-center justify-center rounded text-muted-foreground hover:bg-accent","data-testid":g,onClick:r,title:v,type:"button",children:y}),e[19]=r,e[20]=g,e[21]=v,e[22]=c,e[23]=b):b=e[23];let m;return e[24]!==s||e[25]!==b||e[26]!==a||e[27]!==x?(m=B("span",{className:"flex shrink-0 items-center gap-1","data-testid":s,role:"group",children:[a,x,b]}),e[24]=s,e[25]=b,e[26]=a,e[27]=x,e[28]=m):m=e[28],m},Vn=l=>{const e=K(47),{active:t,canClose:n,onClose:r,onMenu:o,onRename:s,onSelect:d,tab:a}=l,i=oe(),[f,h]=te(!1),[p,x]=te(!1);let c;e[0]!==o||e[1]!==a.id?(c=F=>{o(a.id,F)},e[0]=o,e[1]=a.id,e[2]=c):c=e[2];const g=c;let v;e[3]!==d||e[4]!==a.id?(v=()=>{d(a.id)},e[3]=d,e[4]=a.id,e[5]=v):v=e[5];const y=v;let b;e[6]===Symbol.for("react.memo_cache_sentinel")?(b=()=>{h(!0)},e[6]=b):b=e[6];const m=b;let w;e[7]!==r||e[8]!==a?(w=F=>{F.stopPropagation(),Ve(a)?x(!0):r(a.id)},e[7]=r,e[8]=a,e[9]=w):w=e[9];const k=w;let S;e[10]!==r||e[11]!==a.id?(S=F=>{F.stopPropagation(),x(!1),r(a.id)},e[10]=r,e[11]=a.id,e[12]=S):S=e[12];const C=S;let q;e[13]===Symbol.for("react.memo_cache_sentinel")?(q=F=>{F.stopPropagation(),x(!1)},e[13]=q):q=e[13];const L=q;let R;e[14]!==s||e[15]!==a.id?(R=F=>{s(a.id,F),h(!1)},e[14]=s,e[15]=a.id,e[16]=R):R=e[16];const T=R;let I;e[17]===Symbol.for("react.memo_cache_sentinel")?(I=()=>{h(!1)},e[17]=I):I=e[17];const _=I;let O;e[18]!==a.name?(O=a.name.trim(),e[18]=a.name,e[19]=O):O=e[19];const $=O;let M;e[20]!==i||e[21]!==a.sql?(M=Un(a.sql,i("Untitled")),e[20]=i,e[21]=a.sql,e[22]=M):M=e[22];const E=M,D=t?"bg-background text-foreground":"bg-muted/40 text-muted-foreground hover:text-foreground";let N;e[23]!==D?(N=ue("group/tab flex shrink-0 items-center gap-1 border-e border-border ps-3 pe-1.5 text-xs",D),e[23]=D,e[24]=N):N=e[24];const z=`sql-tab-${a.id}`;let P;e[25]!==t||e[26]!==T||e[27]!==$||e[28]!==E||e[29]!==f||e[30]!==y||e[31]!==i||e[32]!==a.id?(P=f?u(Jn,{initial:$,onCancel:_,onCommit:T,placeholder:E,testId:`sql-tab-rename-${a.id}`}):u("button",{"aria-pressed":t,className:"max-w-40 truncate py-1.5 outline-none","data-testid":`sql-tab-select-${a.id}`,onClick:y,onDoubleClick:m,title:i("Double-click to rename"),type:"button",children:$===""?E:$}),e[25]=t,e[26]=T,e[27]=$,e[28]=E,e[29]=f,e[30]=y,e[31]=i,e[32]=a.id,e[33]=P):P=e[33];let Q;e[34]!==n||e[35]!==C||e[36]!==p||e[37]!==k||e[38]!==i||e[39]!==a.id?(Q=n&&(p?u(Gn,{idBase:a.id,onDiscard:C,onKeep:L}):u("button",{"aria-label":i("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-${a.id}`,onClick:k,title:i("Close tab"),type:"button",children:u("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,viewBox:"0 0 24 24",children:u("path",{d:"M6 6l12 12M18 6 6 18"})})})),e[34]=n,e[35]=C,e[36]=p,e[37]=k,e[38]=i,e[39]=a.id,e[40]=Q):Q=e[40];let j;return e[41]!==g||e[42]!==N||e[43]!==z||e[44]!==P||e[45]!==Q?(j=B("div",{className:N,"data-testid":z,onContextMenu:g,children:[P,Q]}),e[41]=g,e[42]=N,e[43]=z,e[44]=P,e[45]=Q,e[46]=j):j=e[46],j},Xn=l=>{const e=K(43),{model:t,onSelect:n}=l,r=oe(),{activeTab:o,addEditorTab:s,cancelBulk:d,closeEditorTab:a,closeTabMenu:i,confirmBulk:f,menuStyle:h,onBackdropContextMenu:p,onCloseAll:x,onCloseOthers:c,onCloseToRight:g,openTabMenu:v,pendingBulk:y,renameTab:b,tabMenu:m,tabs:w}=t;let k;if(e[0]!==o||e[1]!==a||e[2]!==n||e[3]!==v||e[4]!==b||e[5]!==w){let O;e[7]!==o||e[8]!==a||e[9]!==n||e[10]!==v||e[11]!==b||e[12]!==w.length?(O=$=>u(Vn,{active:$.id===o.id,canClose:w.length>1,onClose:a,onMenu:v,onRename:b,onSelect:n,tab:$},$.id),e[7]=o,e[8]=a,e[9]=n,e[10]=v,e[11]=b,e[12]=w.length,e[13]=O):O=e[13],k=w.map(O),e[0]=o,e[1]=a,e[2]=n,e[3]=v,e[4]=b,e[5]=w,e[6]=k}else k=e[6];let S;e[14]!==r?(S=r("New tab"),e[14]=r,e[15]=S):S=e[15];const C=w.length>=Ae;let q;e[16]!==r?(q=r("New tab"),e[16]=r,e[17]=q):q=e[17];let L;e[18]===Symbol.for("react.memo_cache_sentinel")?(L=u("svg",{"aria-hidden":"true",className:"size-4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.7,viewBox:"0 0 24 24",children:u("path",{d:"M12 5v14M5 12h14"})}),e[18]=L):L=e[18];let R;e[19]!==s||e[20]!==S||e[21]!==C||e[22]!==q?(R=u("button",{"aria-label":S,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:C,onClick:s,title:q,type:"button",children:L}),e[19]=s,e[20]=S,e[21]=C,e[22]=q,e[23]=R):R=e[23];let T;e[24]!==k||e[25]!==R?(T=B("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:[k,R]}),e[24]=k,e[25]=R,e[26]=T):T=e[26];let I;e[27]!==d||e[28]!==i||e[29]!==f||e[30]!==h||e[31]!==p||e[32]!==x||e[33]!==c||e[34]!==g||e[35]!==y||e[36]!==r||e[37]!==m||e[38]!==w?(I=m!==null&&B(Le,{children:[u("div",{className:"fixed inset-0 z-40","data-testid":"sql-tab-menu-backdrop",onClick:i,onContextMenu:p,role:"presentation"}),u("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:h,children:y===null?B(Le,{children:[u("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:w.length<=1,onClick:c,role:"menuitem",type:"button",children:r("Close other tabs")}),u("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:w.findIndex(O=>O.id===m.id)>=w.length-1,onClick:g,role:"menuitem",type:"button",children:r("Close tabs to the right")}),u("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:x,role:"menuitem",type:"button",children:r("Close all tabs")})]}):B("div",{className:"px-3 py-1.5","data-testid":"sql-tab-menu-confirm",children:[u("p",{className:"pb-1.5 text-xs text-muted-foreground",children:r("Discard unsaved tabs?")}),B("div",{className:"flex items-center gap-1.5",children:[u("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:f,type:"button",children:r("Discard")}),u("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:d,type:"button",children:r("Cancel")})]})]})})]}),e[27]=d,e[28]=i,e[29]=f,e[30]=h,e[31]=p,e[32]=x,e[33]=c,e[34]=g,e[35]=y,e[36]=r,e[37]=m,e[38]=w,e[39]=I):I=e[39];let _;return e[40]!==T||e[41]!==I?(_=B(Le,{children:[T,I]}),e[40]=T,e[41]=I,e[42]=_):_=e[42],_},Zn=Te($e.runSql),eo="lunora-studio-sql-split-view",to=()=>ve(Ze[0]?.sql??""),So=l=>{const e=K(102),{initialShardKey:t}=l,n=Me(),r=Cn(to),{activeTab:o,output:s,patchActiveOutput:d,patchActiveTab:a,setActiveTabId:i,unlinkQuery:f}=r;let h;e[0]!==d||e[1]!==a?(h=(se,ce)=>{a({activeId:ce,sql:se}),d({chart:void 0,error:null,failed:void 0,result:null})},e[0]=d,e[1]=a,e[2]=h):h=e[2];const p=h;let x;e[3]!==p||e[4]!==f?(x={loadIntoActiveTab:p,unlinkQuery:f},e[3]=p,e[4]=f,e[5]=x):x=e[5];const c=En(x),{recordHistory:g,updateQuerySql:v}=c,y=o.sql,{activeId:b}=o,{chart:m,error:w,failed:k,result:S}=s,C=s.pane,[q,L]=te(t??""),[R,T]=te(!1),[I,_]=Ke(eo,!1),{probe:O,schema:$}=un(q);let M;e[6]!==b||e[7]!==a||e[8]!==v?(M=se=>{a({sql:se}),b!==null&&v(b,se)},e[6]=b,e[7]=a,e[8]=v,e[9]=M):M=e[9];const E=M,D=Yt(y,$,q),N=ot(q);let z;e[10]!==N||e[11]!==d||e[12]!==S?(z=()=>{S!==null&&de((async()=>{const se=await N.inferChart({columns:S.columns,rowCount:S.rowCount,types:Object.fromEntries(S.columns.map(ce=>[ce,typeof(S.rows[0]?.[ce]??"")]))});d({chart:se})})())},e[10]=N,e[11]=d,e[12]=S,e[13]=z):z=e[13];const P=z;let Q;e[14]!==n||e[15]!==y||e[16]!==d||e[17]!==g||e[18]!==q?(Q=async se=>{if(y.trim()==="")return;T(!0);const ce=se==="explain"?`EXPLAIN QUERY PLAN ${y}`:y;try{const Ee=await n.query(Zn,{sql:ce},ke(q));d({chart:void 0,error:null,failed:void 0,pane:se,result:Ee}),nt(q),g(ce)}catch(Ee){const Be=Ee;d({chart:void 0,error:He(Be),failed:{error:He(Be),sql:ce},pane:se,result:null})}T(!1)},e[14]=n,e[15]=y,e[16]=d,e[17]=g,e[18]=q,e[19]=Q):Q=e[19];const j=Q;let F;e[20]!==j?(F=()=>{de(j("results"))},e[20]=j,e[21]=F):F=e[21];const X=F;let U;e[22]!==s.pane||e[23]!==j?(U=()=>{de(j(s.pane))},e[22]=s.pane,e[23]=j,e[24]=U):U=e[24];let ne;e[25]!==O||e[26]!==$||e[27]!==E||e[28]!==U?(ne={onSubmit:U,probe:O,schema:$,setDraft:E},e[25]=O,e[26]=$,e[27]=E,e[28]=U,e[29]=ne):ne=e[29];const A=hn(ne),{closeAutocomplete:re}=A;let J;e[30]!==y||e[31]!==E?(J=()=>{E(wt(y))},e[30]=y,e[31]=E,e[32]=J):J=e[32];const Z=J;let G;e[33]!==re||e[34]!==i?(G=se=>{re(),i(se)},e[33]=re,e[34]=i,e[35]=G):G=e[35];const ee=G;let V;e[36]!==d?(V=()=>{d({pane:"results"})},e[36]=d,e[37]=V):V=e[37];const le=V;let ie;e[38]!==j?(ie=()=>{de(j("explain"))},e[38]=j,e[39]=ie):ie=e[39];const H=ie;let W;e[40]!==d?(W=()=>{d({pane:"chart"})},e[40]=d,e[41]=W):W=e[41];const Y=W;let ae;e[42]!==_||e[43]!==I?(ae=()=>{_(!I)},e[42]=_,e[43]=I,e[44]=ae):ae=e[44];const xe=ae,Re=I?"flex min-h-0 flex-1 flex-row":"flex min-h-0 flex-1 flex-col",Ie=I?"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";let me;e[45]!==b||e[46]!==c.clearHistory||e[47]!==c.deleteQuery||e[48]!==c.history||e[49]!==c.listRef||e[50]!==c.loadFromHistory||e[51]!==c.loadTemplate||e[52]!==c.newQuery||e[53]!==c.onSearchChange||e[54]!==c.queries||e[55]!==c.search||e[56]!==c.selectQuery?(me=u(Qn,{activeId:b,history:c.history,listRef:c.listRef,onClearHistory:c.clearHistory,onDelete:c.deleteQuery,onLoadHistory:c.loadFromHistory,onLoadTemplate:c.loadTemplate,onNew:c.newQuery,onSearchChange:c.onSearchChange,onSelect:c.selectQuery,queries:c.queries,search:c.search}),e[45]=b,e[46]=c.clearHistory,e[47]=c.deleteQuery,e[48]=c.history,e[49]=c.listRef,e[50]=c.loadFromHistory,e[51]=c.loadTemplate,e[52]=c.newQuery,e[53]=c.onSearchChange,e[54]=c.queries,e[55]=c.search,e[56]=c.selectQuery,e[57]=me):me=e[57];let fe;e[58]!==r||e[59]!==ee?(fe=u(Xn,{model:r,onSelect:ee}),e[58]=r,e[59]=ee,e[60]=fe):fe=e[60];let he;e[61]!==N||e[62]!==D||e[63]!==y||e[64]!==k||e[65]!==E||e[66]!==A.autocompleteState||e[67]!==A.editorRef||e[68]!==A.gutterRef||e[69]!==A.handlers||e[70]!==A.listboxId||e[71]!==A.onPickSuggestion||e[72]!==A.overlayRef||e[73]!==A.revealDiagnostic?(he=u(zn,{assistant:N,autocomplete:A.autocompleteState,diagnostics:D,draft:y,editorRef:A.editorRef,failed:k,gutterRef:A.gutterRef,handlers:A.handlers,listboxId:A.listboxId,onGenerated:E,onPickSuggestion:A.onPickSuggestion,onRevealDiagnostic:A.revealDiagnostic,overlayRef:A.overlayRef}),e[61]=N,e[62]=D,e[63]=y,e[64]=k,e[65]=E,e[66]=A.autocompleteState,e[67]=A.editorRef,e[68]=A.gutterRef,e[69]=A.handlers,e[70]=A.listboxId,e[71]=A.onPickSuggestion,e[72]=A.overlayRef,e[73]=A.revealDiagnostic,e[74]=he):he=e[74];let pe;e[75]!==N||e[76]!==w||e[77]!==Z||e[78]!==P||e[79]!==m||e[80]!==X||e[81]!==S||e[82]!==Ie||e[83]!==R||e[84]!==q||e[85]!==Y||e[86]!==H||e[87]!==le||e[88]!==I||e[89]!==C||e[90]!==xe?(pe=u(Kn,{assistant:N,chart:m,className:Ie,error:w,onFormat:Z,onInferChart:P,onRun:X,onShardKeyChange:L,onShowChart:Y,onShowExplain:H,onShowResults:le,onToggleSplit:xe,pane:C,result:S,running:R,shardKey:q,splitView:I}),e[75]=N,e[76]=w,e[77]=Z,e[78]=P,e[79]=m,e[80]=X,e[81]=S,e[82]=Ie,e[83]=R,e[84]=q,e[85]=Y,e[86]=H,e[87]=le,e[88]=I,e[89]=C,e[90]=xe,e[91]=pe):pe=e[91];let be;e[92]!==he||e[93]!==pe||e[94]!==Re?(be=B("div",{className:Re,children:[he,pe]}),e[92]=he,e[93]=pe,e[94]=Re,e[95]=be):be=e[95];let ge;e[96]!==fe||e[97]!==be?(ge=B("div",{className:"flex min-w-0 flex-1 flex-col",children:[fe,be]}),e[96]=fe,e[97]=be,e[98]=ge):ge=e[98];let we;return e[99]!==me||e[100]!==ge?(we=B("div",{className:"flex h-full min-w-0","data-testid":"lunora-sql-editor",children:[me,ge]}),e[99]=me,e[100]=ge,e[101]=we):we=e[101],we};export{So as SqlEditorPanel};
@@ -1 +1 @@
1
- import{c as G}from"react/compiler-runtime";import{useLunora as L}from"@lunora/react";import{useNavigate as Q,useRouter as q,useSearch as J}from"@tanstack/react-router";import{useState as N,useEffect as $}from"react";import{d as S}from"../packem_shared/storage-tier-DznqOf-q.js";import{i as K}from"../packem_shared/table-list-sidebar-BFkSQwlB.js";import{useT as P}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{s as _,d as B}from"../packem_shared/data-view-params-ClrV7XgF.js";import{f}from"../packem_shared/internal-BSIsQVC6.js";import{l as z,s as O}from"../packem_shared/browser-storage-xjTyMKY0.js";import{DataBrowser as R}from"../packem_shared/DataBrowser-CuRlztBz.js";import{GlobalDataBrowser as H}from"../packem_shared/GlobalDataBrowser-DB-vQ2_H.js";import{jsx as v,jsxs as C}from"react/jsx-runtime";const j="lunora-studio-saved-queries",I=50,M=r=>r!==null&&typeof r=="object"&&typeof r.name=="string"&&typeof r.view=="object"&&r.view!==null,w=()=>z(j).filter(M),k=r=>{O(j,r)},U=(r,e)=>{const l=r.trim();if(l==="")return w();const o=[{name:l,view:e},...w().filter(u=>u.name!==l)].slice(0,I);return k(o),o},W=r=>{const e=w().filter(l=>l.name!==r);return k(e),e},X=r=>{const e=G(15),{onChange:l,tier:o}=r,u=P();let d;e[0]!==l?(d=y=>{l(y.target.value)},e[0]=l,e[1]=d):d=e[1];const s=d;let h;e[2]!==u?(h=u("Storage tier"),e[2]=u,e[3]=h):h=e[3];let n;e[4]!==h?(n=v("span",{className:"font-mono text-[11px] tracking-wide uppercase text-muted-foreground",children:h}),e[4]=h,e[5]=n):n=e[5];const m=S[o];let i,g;e[6]===Symbol.for("react.memo_cache_sentinel")?(i=v("option",{value:"shard",children:S.shard.label}),g=v("option",{value:"global",children:S.global.label}),e[6]=i,e[7]=g):(i=e[6],g=e[7]);let c;e[8]!==s||e[9]!==m.title||e[10]!==o?(c=C("select",{className:"h-8 w-full rounded-md border border-border bg-background px-2 text-sm outline-none focus-visible:border-ring","data-testid":"table-editor-schema",id:"table-editor-schema",onChange:s,title:m.title,value:o,children:[i,g]}),e[8]=s,e[9]=m.title,e[10]=o,e[11]=c):c=e[11];let b;return e[12]!==n||e[13]!==c?(b=C("label",{className:"flex w-full flex-col gap-1",htmlFor:"table-editor-schema",children:[n,c]}),e[12]=n,e[13]=c,e[14]=b):b=e[14],b},Y=()=>{try{f(globalThis.navigator.clipboard.writeText(globalThis.location.href))}catch{}},me=({editable:r=!1,initialShardKey:e})=>{const l=L(),o=Q(),u=q(),d=J({strict:!1}),s=_(d),h=K(d),n=()=>u.state.location.pathname.split("/").findLast(Boolean)==="data",m=s.tier??"shard",i=s.table,[g,c]=N(()=>w()),[b,y]=N(()=>new Set);$(()=>{f((async()=>{try{const t=await l.listGlobalTables();y(new Set(t.map(a=>a.name)))}catch{}})())},[l]),$(()=>{m==="shard"&&i!==void 0&&b.has(i)&&f(o({replace:!0,search:t=>({...t,schema:"global"}),to:"/data"}))},[b,o,i,m]);const D=t=>{f(o({search:a=>({...a,schema:t==="global"?"global":void 0,table:void 0}),to:"/data"}))},T=(t,a)=>{n()&&f(o({search:p=>({schema:p.schema,search:a?.search,shard:p.shard,table:t}),to:"/data"}))},V=t=>{f(o({search:a=>({...a,schema:"global",table:t}),to:"/data"}))},A=t=>{const a=B(t),{current:p}=h;(p.filters??void 0)===a.filters&&(p.order??void 0)===a.order&&(p.search??void 0)===a.search&&(p.shard??void 0)===a.shard||!n()||f(o({replace:!0,search:F=>({...F,filters:a.filters,order:a.order,search:a.search,shard:a.shard}),to:"/data"}))},E={onApplyQuery:t=>{const a=B(t.view);f(o({search:()=>({filters:a.filters,order:a.order,schema:a.schema,search:a.search,shard:a.shard,table:a.table}),to:"/data"}))},onCopyLink:Y,onDeleteQuery:t=>{c(W(t))},onSaveQuery:(t,a)=>{c(U(t,a))},saved:g},x=v(X,{onChange:D,tier:m});return m==="global"?v(H,{initialTable:i,onSelectTable:T,schemaSwitch:x}):v(R,{editable:r,globalTableNames:b,initialFilters:s.filters,initialOrderBy:s.orderBy,initialPins:d.pins,initialSearch:s.search,initialShardKey:s.shard??e,onNavigateToGlobal:V,onSelectTable:T,onViewChange:A,queryBar:E,schemaSwitch:x,tableParam:i})};export{me as TableEditor};
1
+ import{c as G}from"react/compiler-runtime";import{useLunora as L}from"@lunora/react";import{useNavigate as Q,useRouter as q,useSearch as J}from"@tanstack/react-router";import{useState as N,useEffect as $}from"react";import{d as S}from"../packem_shared/storage-tier-DznqOf-q.js";import{i as K}from"../packem_shared/table-list-sidebar-BRv3hTLX.js";import{useT as P}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{s as _,d as B}from"../packem_shared/data-view-params-ClrV7XgF.js";import{f}from"../packem_shared/internal-BSIsQVC6.js";import{l as z,s as O}from"../packem_shared/browser-storage-xjTyMKY0.js";import{DataBrowser as R}from"../packem_shared/DataBrowser-C4J4gVUu.js";import{GlobalDataBrowser as H}from"../packem_shared/GlobalDataBrowser-CSttudUx.js";import{jsx as v,jsxs as C}from"react/jsx-runtime";const j="lunora-studio-saved-queries",I=50,M=r=>r!==null&&typeof r=="object"&&typeof r.name=="string"&&typeof r.view=="object"&&r.view!==null,w=()=>z(j).filter(M),k=r=>{O(j,r)},U=(r,e)=>{const l=r.trim();if(l==="")return w();const o=[{name:l,view:e},...w().filter(u=>u.name!==l)].slice(0,I);return k(o),o},W=r=>{const e=w().filter(l=>l.name!==r);return k(e),e},X=r=>{const e=G(15),{onChange:l,tier:o}=r,u=P();let d;e[0]!==l?(d=y=>{l(y.target.value)},e[0]=l,e[1]=d):d=e[1];const s=d;let h;e[2]!==u?(h=u("Storage tier"),e[2]=u,e[3]=h):h=e[3];let n;e[4]!==h?(n=v("span",{className:"font-mono text-[11px] tracking-wide uppercase text-muted-foreground",children:h}),e[4]=h,e[5]=n):n=e[5];const m=S[o];let i,g;e[6]===Symbol.for("react.memo_cache_sentinel")?(i=v("option",{value:"shard",children:S.shard.label}),g=v("option",{value:"global",children:S.global.label}),e[6]=i,e[7]=g):(i=e[6],g=e[7]);let c;e[8]!==s||e[9]!==m.title||e[10]!==o?(c=C("select",{className:"h-8 w-full rounded-md border border-border bg-background px-2 text-sm outline-none focus-visible:border-ring","data-testid":"table-editor-schema",id:"table-editor-schema",onChange:s,title:m.title,value:o,children:[i,g]}),e[8]=s,e[9]=m.title,e[10]=o,e[11]=c):c=e[11];let b;return e[12]!==n||e[13]!==c?(b=C("label",{className:"flex w-full flex-col gap-1",htmlFor:"table-editor-schema",children:[n,c]}),e[12]=n,e[13]=c,e[14]=b):b=e[14],b},Y=()=>{try{f(globalThis.navigator.clipboard.writeText(globalThis.location.href))}catch{}},me=({editable:r=!1,initialShardKey:e})=>{const l=L(),o=Q(),u=q(),d=J({strict:!1}),s=_(d),h=K(d),n=()=>u.state.location.pathname.split("/").findLast(Boolean)==="data",m=s.tier??"shard",i=s.table,[g,c]=N(()=>w()),[b,y]=N(()=>new Set);$(()=>{f((async()=>{try{const t=await l.listGlobalTables();y(new Set(t.map(a=>a.name)))}catch{}})())},[l]),$(()=>{m==="shard"&&i!==void 0&&b.has(i)&&f(o({replace:!0,search:t=>({...t,schema:"global"}),to:"/data"}))},[b,o,i,m]);const D=t=>{f(o({search:a=>({...a,schema:t==="global"?"global":void 0,table:void 0}),to:"/data"}))},T=(t,a)=>{n()&&f(o({search:p=>({schema:p.schema,search:a?.search,shard:p.shard,table:t}),to:"/data"}))},V=t=>{f(o({search:a=>({...a,schema:"global",table:t}),to:"/data"}))},A=t=>{const a=B(t),{current:p}=h;(p.filters??void 0)===a.filters&&(p.order??void 0)===a.order&&(p.search??void 0)===a.search&&(p.shard??void 0)===a.shard||!n()||f(o({replace:!0,search:F=>({...F,filters:a.filters,order:a.order,search:a.search,shard:a.shard}),to:"/data"}))},E={onApplyQuery:t=>{const a=B(t.view);f(o({search:()=>({filters:a.filters,order:a.order,schema:a.schema,search:a.search,shard:a.shard,table:a.table}),to:"/data"}))},onCopyLink:Y,onDeleteQuery:t=>{c(W(t))},onSaveQuery:(t,a)=>{c(U(t,a))},saved:g},x=v(X,{onChange:D,tier:m});return m==="global"?v(H,{initialTable:i,onSelectTable:T,schemaSwitch:x}):v(R,{editable:r,globalTableNames:b,initialFilters:s.filters,initialOrderBy:s.orderBy,initialPins:d.pins,initialSearch:s.search,initialShardKey:s.shard??e,onNavigateToGlobal:V,onSelectTable:T,onViewChange:A,queryBar:E,schemaSwitch:x,tableParam:i})};export{me as TableEditor};
@@ -1 +1 @@
1
- import{useState as J}from"react";import{E as S}from"../packem_shared/error-alert-t6cpEi0z.js";import{g as C}from"../packem_shared/badge-BbuuAio7.js";import{u as j}from"../packem_shared/button-BkCrNcAs.js";import{c as I,u as K}from"../packem_shared/card-CIDGUN6K.js";import{E}from"../packem_shared/empty-state-Cg7t_8qu.js";import{n as q,d as U,m as g,p as o,f as _,u as i}from"../packem_shared/table-DdJBrClo.js";import{N as y}from"../packem_shared/use-admin-query-QJ-ibl5u.js";import{useT as R}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as N}from"../packem_shared/ADMIN_FUNCTIONS-BnD4aovm.js";import{i as V}from"../packem_shared/internal-BSIsQVC6.js";import{jsx as e,jsxs as n}from"react/jsx-runtime";const M="agent_threads",W="agent_messages",X=100,Y=250,Z={},Q={filters:[],limit:X,offset:0,orderBy:{column:"updatedAt",direction:"desc"},skipCount:!0,table:M},d=(s,t)=>{const a=s[t];return typeof a=="string"?a:void 0},b=(s,t)=>{const a=s[t];return typeof a=="number"?a:void 0},z=s=>{const{usage:t}=s;if(t===null||typeof t!="object")return;const{totalTokens:a}=t;return typeof a=="number"?a:void 0},ee=s=>{const{toolCalls:t}=s;return Array.isArray(t)?t.map(a=>a!==null&&typeof a=="object"?a.name:void 0).filter(a=>typeof a=="string"):[]},te=s=>{switch(s){case"awaiting_input":return"warning";case"cancelled":return"warning";case"error":return"destructive";case"running":return"info";default:return"outline"}},ae=s=>{switch(s){case"approved":return"success";case"rejected":return"destructive";default:return"warning"}},pe=({initialShardKey:s=""})=>{const t=R(),[a,w]=J(void 0),{data:p}=y(N.listTables,Z,{live:!0,shardKey:s}),P=p!==void 0,m=Array.isArray(p)&&p.some(r=>r.name===M),{data:A,error:B,errorSource:D,liveError:L}=y(N.readTablePage,Q,{enabled:m,live:!0,shardKey:s}),O={filters:[{column:"threadKey",operator:"eq",value:a??""}],limit:Y,offset:0,orderBy:{column:"seq",direction:"asc"},skipCount:!0,table:W},{data:$,error:F,errorSource:G}=y(N.readTablePage,O,{enabled:m&&a!==void 0,live:!0,shardKey:s}),f=Array.isArray(A?.rows)?A.rows:[],k=Array.isArray($?.rows)?$.rows:[],T=f.find(r=>d(r,"key")===a);let u;return P&&!m?u=e(E,{description:t("No @lunora/agent tables found in this deployment. Add lunora/agents.ts with defineAgent(...) and merge the agent schema extension to run durable AI agents."),testId:"agents-unconfigured",title:t("No agents configured")}):m&&f.length===0?u=e(E,{description:t("No agent has run yet. Start a run with ctx.agents.<name>.run(...) and its thread appears here."),testId:"agents-empty",title:t("No agent threads yet")}):u=n("div",{className:"flex flex-col gap-6",children:[e(I,{className:"overflow-hidden py-0",children:e(K,{className:"px-0",children:n(q,{"data-testid":"agents-threads-table",children:[e(U,{children:n(g,{children:[e(o,{children:t("Agent")}),e(o,{children:t("Key")}),e(o,{children:t("Status")}),e(o,{children:t("Messages")}),e(o,{children:t("Tokens")}),e(o,{children:t("Updated")}),e(o,{"aria-label":t("Actions")})]})}),e(_,{children:f.map(r=>{const l=d(r,"key")??"",c=d(r,"status"),h=z(r);return n(g,{"data-active":l===a?"":void 0,"data-testid":`agents-thread-${l}`,children:[e(i,{className:"font-mono text-xs",children:d(r,"agent")??"—"}),e(i,{className:"font-mono text-xs text-muted-foreground",children:l}),e(i,{children:e(C,{"data-testid":`agents-thread-status-${l}`,variant:te(c),children:c??"—"})}),e(i,{className:"tabular-nums",children:b(r,"messageCount")??"—"}),e(i,{className:"tabular-nums text-muted-foreground",children:h??"—"}),e(i,{className:"text-muted-foreground tabular-nums",children:V(b(r,"updatedAt"),"—")}),e(i,{className:"text-right",children:e(j,{"data-testid":`agents-thread-open-${l}`,onClick:()=>{w(l)},size:"sm",type:"button",variant:"outline",children:t("Timeline")})})]},l)})})]})})}),F!==null&&e(S,{error:G,testId:"agents-messages-error"}),a!==void 0&&e(I,{className:"overflow-hidden py-0","data-testid":"agents-thread-detail",children:n(K,{className:"flex flex-col gap-3 px-4 py-3",children:[n("div",{className:"flex items-center justify-between gap-2",children:[n("span",{className:"font-mono text-xs",children:[t("Timeline")," · ",a,T!==void 0&&n("span",{className:"text-muted-foreground",children:[" · ",t("Usage"),": ",z(T)??0," ",t("Tokens")]})]}),e(j,{"data-testid":"agents-thread-detail-close",onClick:()=>{w(void 0)},size:"xs",type:"button",variant:"ghost",children:t("Close")})]}),k.length===0?e("p",{className:"text-xs text-muted-foreground",children:t("This thread has no messages yet.")}):n(q,{"data-testid":"agents-messages-table",children:[e(U,{children:n(g,{children:[e(o,{children:t("Role")}),e(o,{children:t("Content")}),e(o,{children:t("Tool")}),e(o,{children:t("Approval")})]})}),e(_,{children:k.map((r,l)=>{const c=d(r,"role")??"—",h=ee(r),H=d(r,"toolName"),x=d(r,"status"),v=b(r,"seq")??l;return n(g,{"data-testid":`agents-message-${String(v)}`,children:[e(i,{className:"font-mono text-xs align-top text-muted-foreground",children:c}),e(i,{className:"max-w-md font-mono text-xs whitespace-pre-wrap break-words",children:d(r,"content")??"—"}),e(i,{className:"font-mono text-xs align-top text-muted-foreground",children:H??(h.length>0?h.join(", "):"—")}),e(i,{className:"align-top",children:x===void 0?e("span",{className:"text-xs text-muted-foreground",children:"—"}):e(C,{"data-testid":`agents-message-approval-${String(v)}`,variant:ae(x),children:x})})]},d(r,"messageKey")??`${c}:${String(v)}`)})})]})]})})]}),n("div",{className:"flex flex-col gap-6","data-testid":"lunora-agents-panel",children:[B!==null&&e(S,{error:D,testId:"agents-error"}),e("p",{className:"text-sm text-muted-foreground",children:t("Agents run as durable workflows. Each run persists a thread of assistant and tool messages; select a thread to inspect its timeline, tool calls, approvals, and token usage.")}),L!==void 0&&e("p",{className:"text-xs text-amber-600 dark:text-amber-500","data-testid":"agents-live-error",role:"alert",children:t("Live updates unavailable; showing the last evaluation.")}),u]})};export{pe as AgentsPanel};
1
+ import{useState as J}from"react";import{E as S}from"../packem_shared/error-alert-t6cpEi0z.js";import{g as C}from"../packem_shared/badge-BbuuAio7.js";import{u as j}from"../packem_shared/button-BkCrNcAs.js";import{c as I,u as K}from"../packem_shared/card-CIDGUN6K.js";import{E}from"../packem_shared/empty-state-Cg7t_8qu.js";import{n as q,d as U,m as g,p as o,f as _,u as i}from"../packem_shared/table-DdJBrClo.js";import{N as y}from"../packem_shared/use-admin-query-QJ-ibl5u.js";import{useT as R}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as N}from"../packem_shared/ADMIN_FUNCTIONS-CZESgd10.js";import{i as V}from"../packem_shared/internal-BSIsQVC6.js";import{jsx as e,jsxs as n}from"react/jsx-runtime";const M="agent_threads",W="agent_messages",X=100,Y=250,Z={},Q={filters:[],limit:X,offset:0,orderBy:{column:"updatedAt",direction:"desc"},skipCount:!0,table:M},d=(s,t)=>{const a=s[t];return typeof a=="string"?a:void 0},b=(s,t)=>{const a=s[t];return typeof a=="number"?a:void 0},z=s=>{const{usage:t}=s;if(t===null||typeof t!="object")return;const{totalTokens:a}=t;return typeof a=="number"?a:void 0},ee=s=>{const{toolCalls:t}=s;return Array.isArray(t)?t.map(a=>a!==null&&typeof a=="object"?a.name:void 0).filter(a=>typeof a=="string"):[]},te=s=>{switch(s){case"awaiting_input":return"warning";case"cancelled":return"warning";case"error":return"destructive";case"running":return"info";default:return"outline"}},ae=s=>{switch(s){case"approved":return"success";case"rejected":return"destructive";default:return"warning"}},pe=({initialShardKey:s=""})=>{const t=R(),[a,w]=J(void 0),{data:p}=y(N.listTables,Z,{live:!0,shardKey:s}),P=p!==void 0,m=Array.isArray(p)&&p.some(r=>r.name===M),{data:A,error:B,errorSource:D,liveError:L}=y(N.readTablePage,Q,{enabled:m,live:!0,shardKey:s}),O={filters:[{column:"threadKey",operator:"eq",value:a??""}],limit:Y,offset:0,orderBy:{column:"seq",direction:"asc"},skipCount:!0,table:W},{data:$,error:F,errorSource:G}=y(N.readTablePage,O,{enabled:m&&a!==void 0,live:!0,shardKey:s}),f=Array.isArray(A?.rows)?A.rows:[],k=Array.isArray($?.rows)?$.rows:[],T=f.find(r=>d(r,"key")===a);let u;return P&&!m?u=e(E,{description:t("No @lunora/agent tables found in this deployment. Add lunora/agents.ts with defineAgent(...) and merge the agent schema extension to run durable AI agents."),testId:"agents-unconfigured",title:t("No agents configured")}):m&&f.length===0?u=e(E,{description:t("No agent has run yet. Start a run with ctx.agents.<name>.run(...) and its thread appears here."),testId:"agents-empty",title:t("No agent threads yet")}):u=n("div",{className:"flex flex-col gap-6",children:[e(I,{className:"overflow-hidden py-0",children:e(K,{className:"px-0",children:n(q,{"data-testid":"agents-threads-table",children:[e(U,{children:n(g,{children:[e(o,{children:t("Agent")}),e(o,{children:t("Key")}),e(o,{children:t("Status")}),e(o,{children:t("Messages")}),e(o,{children:t("Tokens")}),e(o,{children:t("Updated")}),e(o,{"aria-label":t("Actions")})]})}),e(_,{children:f.map(r=>{const l=d(r,"key")??"",c=d(r,"status"),h=z(r);return n(g,{"data-active":l===a?"":void 0,"data-testid":`agents-thread-${l}`,children:[e(i,{className:"font-mono text-xs",children:d(r,"agent")??"—"}),e(i,{className:"font-mono text-xs text-muted-foreground",children:l}),e(i,{children:e(C,{"data-testid":`agents-thread-status-${l}`,variant:te(c),children:c??"—"})}),e(i,{className:"tabular-nums",children:b(r,"messageCount")??"—"}),e(i,{className:"tabular-nums text-muted-foreground",children:h??"—"}),e(i,{className:"text-muted-foreground tabular-nums",children:V(b(r,"updatedAt"),"—")}),e(i,{className:"text-right",children:e(j,{"data-testid":`agents-thread-open-${l}`,onClick:()=>{w(l)},size:"sm",type:"button",variant:"outline",children:t("Timeline")})})]},l)})})]})})}),F!==null&&e(S,{error:G,testId:"agents-messages-error"}),a!==void 0&&e(I,{className:"overflow-hidden py-0","data-testid":"agents-thread-detail",children:n(K,{className:"flex flex-col gap-3 px-4 py-3",children:[n("div",{className:"flex items-center justify-between gap-2",children:[n("span",{className:"font-mono text-xs",children:[t("Timeline")," · ",a,T!==void 0&&n("span",{className:"text-muted-foreground",children:[" · ",t("Usage"),": ",z(T)??0," ",t("Tokens")]})]}),e(j,{"data-testid":"agents-thread-detail-close",onClick:()=>{w(void 0)},size:"xs",type:"button",variant:"ghost",children:t("Close")})]}),k.length===0?e("p",{className:"text-xs text-muted-foreground",children:t("This thread has no messages yet.")}):n(q,{"data-testid":"agents-messages-table",children:[e(U,{children:n(g,{children:[e(o,{children:t("Role")}),e(o,{children:t("Content")}),e(o,{children:t("Tool")}),e(o,{children:t("Approval")})]})}),e(_,{children:k.map((r,l)=>{const c=d(r,"role")??"—",h=ee(r),H=d(r,"toolName"),x=d(r,"status"),v=b(r,"seq")??l;return n(g,{"data-testid":`agents-message-${String(v)}`,children:[e(i,{className:"font-mono text-xs align-top text-muted-foreground",children:c}),e(i,{className:"max-w-md font-mono text-xs whitespace-pre-wrap break-words",children:d(r,"content")??"—"}),e(i,{className:"font-mono text-xs align-top text-muted-foreground",children:H??(h.length>0?h.join(", "):"—")}),e(i,{className:"align-top",children:x===void 0?e("span",{className:"text-xs text-muted-foreground",children:"—"}):e(C,{"data-testid":`agents-message-approval-${String(v)}`,variant:ae(x),children:x})})]},d(r,"messageKey")??`${c}:${String(v)}`)})})]})]})})]}),n("div",{className:"flex flex-col gap-6","data-testid":"lunora-agents-panel",children:[B!==null&&e(S,{error:D,testId:"agents-error"}),e("p",{className:"text-sm text-muted-foreground",children:t("Agents run as durable workflows. Each run persists a thread of assistant and tool messages; select a thread to inspect its timeline, tool calls, approvals, and token usage.")}),L!==void 0&&e("p",{className:"text-xs text-amber-600 dark:text-amber-500","data-testid":"agents-live-error",role:"alert",children:t("Live updates unavailable; showing the last evaluation.")}),u]})};export{pe as AgentsPanel};