@lunora/studio 1.0.0-alpha.95 → 1.0.0-alpha.97

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 (160) hide show
  1. package/dist/index.js +1 -1
  2. package/dist/mount.js +1 -1
  3. package/dist/packem_chunks/AdvisorHealthPanel.js +1 -1
  4. package/dist/packem_chunks/AuditPanel.js +1 -1
  5. package/dist/packem_chunks/DeploymentHealthPanel.js +1 -1
  6. package/dist/packem_chunks/ExportImportPanel.js +1 -1
  7. package/dist/packem_chunks/FileBrowser.js +1 -1
  8. package/dist/packem_chunks/FunctionStatsPanel.js +1 -1
  9. package/dist/packem_chunks/HealthPanel.js +1 -1
  10. package/dist/packem_chunks/InsightsPanel.js +1 -1
  11. package/dist/packem_chunks/LogsPanel.js +1 -1
  12. package/dist/packem_chunks/MailPanel.js +1 -1
  13. package/dist/packem_chunks/MetricsPanel.js +1 -1
  14. package/dist/packem_chunks/NotificationsPanel.js +1 -1
  15. package/dist/packem_chunks/SchemaViewer.js +1 -1
  16. package/dist/packem_chunks/SecurityAdvisorPanel.js +1 -1
  17. package/dist/packem_chunks/SettingsPanel.js +1 -1
  18. package/dist/packem_chunks/SqlEditorPanel.js +6 -6
  19. package/dist/packem_chunks/TableEditor.js +1 -1
  20. package/dist/packem_chunks/agents-panel.js +1 -1
  21. package/dist/packem_chunks/analytics-panel.js +1 -1
  22. package/dist/packem_chunks/auth-audit-panel.js +1 -1
  23. package/dist/packem_chunks/auth-config-panel.js +1 -1
  24. package/dist/packem_chunks/auth-sessions-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 +2 -2
  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/schedule-panel.js +1 -1
  39. package/dist/packem_chunks/sparkline.js +1 -1
  40. package/dist/packem_chunks/storage-rules-panel.js +1 -1
  41. package/dist/packem_chunks/subscriptions-panel.js +1 -1
  42. package/dist/packem_chunks/sync-client-panel.js +1 -1
  43. package/dist/packem_chunks/traces-panel.js +1 -1
  44. package/dist/packem_chunks/users-panel.js +1 -1
  45. package/dist/packem_chunks/vector-browser.js +1 -1
  46. package/dist/packem_chunks/workflows-panel.js +1 -1
  47. package/dist/packem_shared/{DataBrowser-H4oUFkPJ.js → DataBrowser-CPNKM0KZ.js} +1 -1
  48. package/dist/packem_shared/{GlobalDataBrowser-CeA8bDjX.js → GlobalDataBrowser-BSmyOO0n.js} +1 -1
  49. package/dist/packem_shared/{HomePanel-DLP1nQdC.js → HomePanel-BUO6BcYQ.js} +1 -1
  50. package/dist/packem_shared/{MigrationsPanel-dm_M75mR.js → MigrationsPanel-BAnvY79E.js} +1 -1
  51. package/dist/packem_shared/{ScheduledJobs-DDJG9Je7.js → ScheduledJobs-pHVlh2xU.js} +1 -1
  52. package/dist/packem_shared/{Studio-BYg65qWq.js → Studio-DG_n-8Pc.js} +1 -1
  53. package/dist/packem_shared/{StudioApp-D0UOg0a_.js → StudioApp-bavavhpe.js} +1 -1
  54. package/dist/packem_shared/advisor-view-CGcwvlMo.js +1 -0
  55. package/dist/packem_shared/bar-chart-B8oDHgnw.js +6 -0
  56. package/dist/packem_shared/{card-CIDGUN6K.js → card-BMKx5UdA.js} +1 -1
  57. package/dist/packem_shared/{dropdown-menu-C3RQ_HlW.js → dropdown-menu-BgS2zw1i.js} +1 -1
  58. package/dist/packem_shared/error-alert-_2q2VtVG.js +1 -0
  59. package/dist/packem_shared/{grid-features-Db_BNYRo.js → grid-features-Y2YSjhCf.js} +2 -2
  60. package/dist/packem_shared/home-panel-Ir3YHReO.js +3 -0
  61. package/dist/packem_shared/result-chart-0VgP_3FP.js +1 -0
  62. package/dist/packem_shared/schema-diagram-GVgnLWTf.js +2 -0
  63. package/dist/packem_shared/{select-Bul-DeII.js → select-BssZMiFY.js} +1 -1
  64. package/dist/packem_shared/{sparkline-CgjeUU2I.js → sparkline-BNvxiJj_.js} +1 -1
  65. package/dist/packem_shared/{stat-card-fm_TF1mo.js → stat-card-BGJdhfm6.js} +1 -1
  66. package/dist/packem_shared/studio-C9Qvg13j.js +2 -0
  67. package/dist/packem_shared/{table-DdJBrClo.js → table-DZAB8cs3.js} +1 -1
  68. package/dist/packem_shared/{trace-handoff-Dw7mwjxu.js → trace-handoff-CuZ6WGgo.js} +1 -1
  69. package/dist/packem_shared/use-async-submit-B32whHJO.js +1 -0
  70. package/dist/standalone/{chunk-BN4CIAXU.js → chunk-2KRXOCZ2.js} +1 -1
  71. package/dist/standalone/{chunk-D62SDRMM.js → chunk-3626PHEZ.js} +1 -1
  72. package/dist/standalone/{chunk-TITX6XEA.js → chunk-3IF75YS7.js} +1 -1
  73. package/dist/standalone/chunk-3SCGCJYS.js +1 -0
  74. package/dist/standalone/{chunk-2OUIHY7G.js → chunk-3SGYSFRC.js} +1 -1
  75. package/dist/standalone/{chunk-7YJNH3RB.js → chunk-4EHNOASW.js} +1 -1
  76. package/dist/standalone/{chunk-YD5O2NWK.js → chunk-5A7NIX77.js} +1 -1
  77. package/dist/standalone/{chunk-UIGAA3GV.js → chunk-5L2VKBAJ.js} +1 -1
  78. package/dist/standalone/{chunk-NNKN2XEZ.js → chunk-5L63KFHD.js} +1 -1
  79. package/dist/standalone/{chunk-ZNAGZU6H.js → chunk-6F7KP54M.js} +1 -1
  80. package/dist/standalone/{chunk-3FIN5PH4.js → chunk-6V27P65N.js} +2 -2
  81. package/dist/standalone/{chunk-2T22UR7E.js → chunk-73B3T2SA.js} +1 -1
  82. package/dist/standalone/chunk-7CWPU3LW.js +1 -0
  83. package/dist/standalone/{chunk-PE7TI4TQ.js → chunk-A6NAMYVS.js} +1 -1
  84. package/dist/standalone/{chunk-RNOSWEMO.js → chunk-AB5WGAX6.js} +2 -2
  85. package/dist/standalone/{chunk-IBVBIKUI.js → chunk-ATLV7KWK.js} +1 -1
  86. package/dist/standalone/{chunk-IUUSMC2R.js → chunk-BLHSTFG3.js} +1 -1
  87. package/dist/standalone/chunk-C2ZFQARQ.js +11 -0
  88. package/dist/standalone/chunk-CXBXUT5A.js +3 -0
  89. package/dist/standalone/chunk-CZZWYUTR.js +1 -0
  90. package/dist/standalone/{chunk-LZKU262J.js → chunk-D264UAKY.js} +1 -1
  91. package/dist/standalone/{chunk-VVNQP4CI.js → chunk-DDO5EGID.js} +1 -1
  92. package/dist/standalone/{chunk-DMJDUC4L.js → chunk-E3Z4QXAD.js} +1 -1
  93. package/dist/standalone/{chunk-WI4XINU2.js → chunk-EZKBI7SZ.js} +1 -1
  94. package/dist/standalone/{chunk-BNAMPDZ2.js → chunk-FHZ5WDTU.js} +1 -1
  95. package/dist/standalone/{chunk-TMNKNTC4.js → chunk-FXBBFE7Y.js} +1 -1
  96. package/dist/standalone/{chunk-JYLYJT27.js → chunk-G2O3XP7Y.js} +5 -5
  97. package/dist/standalone/{chunk-SCKKQIAE.js → chunk-H5ZYPSLB.js} +1 -1
  98. package/dist/standalone/{chunk-Z4AX76YZ.js → chunk-HH5CZ6KD.js} +1 -1
  99. package/dist/standalone/{chunk-UGU5GYDV.js → chunk-I7V54EDS.js} +1 -1
  100. package/dist/standalone/{chunk-6K46XGR5.js → chunk-II64XEZV.js} +1 -1
  101. package/dist/standalone/{chunk-U6KDYJJC.js → chunk-IZFPJXB3.js} +1 -1
  102. package/dist/standalone/{chunk-QNHU4SKL.js → chunk-J4UYSDWF.js} +1 -1
  103. package/dist/standalone/{chunk-JWXKUXYA.js → chunk-JNY7CFF4.js} +1 -1
  104. package/dist/standalone/{chunk-DYMO6MDG.js → chunk-KP6VHTO4.js} +1 -1
  105. package/dist/standalone/{chunk-SKYFKPJC.js → chunk-LAEO6D34.js} +1 -1
  106. package/dist/standalone/{chunk-VNQB6HY4.js → chunk-LHAHIDNT.js} +1 -1
  107. package/dist/standalone/{chunk-4LCY5XUR.js → chunk-M2M3RYJU.js} +1 -1
  108. package/dist/standalone/{chunk-3KXDX76D.js → chunk-M3Z2YAHD.js} +1 -1
  109. package/dist/standalone/{chunk-YTWBHPAT.js → chunk-MW5YIENZ.js} +1 -1
  110. package/dist/standalone/chunk-NBANYYGB.js +1 -0
  111. package/dist/standalone/{chunk-465RIA2L.js → chunk-NCKRVNF2.js} +1 -1
  112. package/dist/standalone/{chunk-A3DBEJLO.js → chunk-NDO6YSEG.js} +1 -1
  113. package/dist/standalone/{chunk-O3UMJLO3.js → chunk-NJRW66LJ.js} +1 -1
  114. package/dist/standalone/{chunk-AQ4JNJF3.js → chunk-OKZP3YY3.js} +1 -1
  115. package/dist/standalone/{chunk-2O65JEMI.js → chunk-ON2FIVI2.js} +1 -1
  116. package/dist/standalone/chunk-OQIGV6FX.js +59 -0
  117. package/dist/standalone/{chunk-QXECM52Z.js → chunk-OZA2RA45.js} +1 -1
  118. package/dist/standalone/{chunk-XNGYYOLS.js → chunk-P33WK7YI.js} +4 -4
  119. package/dist/standalone/{chunk-KEVIGWKP.js → chunk-PKWJ7UOG.js} +1 -1
  120. package/dist/standalone/chunk-PLFTCTMX.js +1 -0
  121. package/dist/standalone/{chunk-7ONX5YGW.js → chunk-PMGTIUU2.js} +1 -1
  122. package/dist/standalone/{chunk-ABYJC3LS.js → chunk-QC4T2L6I.js} +1 -1
  123. package/dist/standalone/{chunk-3DJ3IUUG.js → chunk-QEVFPILV.js} +1 -1
  124. package/dist/standalone/{chunk-PGVJE5F5.js → chunk-QQYX5WN4.js} +1 -1
  125. package/dist/standalone/{chunk-G6GX5TVB.js → chunk-S7ZOM3NK.js} +1 -1
  126. package/dist/standalone/{chunk-M7AWSDGY.js → chunk-SPE3AB54.js} +1 -1
  127. package/dist/standalone/{chunk-OM36OEHZ.js → chunk-STESBRLN.js} +1 -1
  128. package/dist/standalone/{chunk-QM4EXWKF.js → chunk-SZXVX6PY.js} +1 -1
  129. package/dist/standalone/{chunk-EQZTSISX.js → chunk-TMGHRD6W.js} +1 -1
  130. package/dist/standalone/{chunk-ZA5YIHZM.js → chunk-UYPXC3OO.js} +1 -1
  131. package/dist/standalone/{chunk-ZVAGD3FT.js → chunk-VH2IO643.js} +1 -1
  132. package/dist/standalone/{chunk-5TDGHWYU.js → chunk-WLXH4ECM.js} +1 -1
  133. package/dist/standalone/{chunk-UZERI5YC.js → chunk-WQH3LT2P.js} +1 -1
  134. package/dist/standalone/{chunk-DBMFI2HC.js → chunk-XPOUF2XH.js} +1 -1
  135. package/dist/standalone/{chunk-JEZDJ7D6.js → chunk-YP7WZ6YM.js} +1 -1
  136. package/dist/standalone/chunk-YZIR7PL5.js +1 -0
  137. package/dist/standalone/studio.js +1 -1
  138. package/dist/styles.css +1 -1
  139. package/package.json +6 -6
  140. package/dist/packem_shared/advisor-view-Coipc04R.js +0 -1
  141. package/dist/packem_shared/bar-chart-DraN_srt.js +0 -9
  142. package/dist/packem_shared/error-alert--Ie7ofJ0.js +0 -1
  143. package/dist/packem_shared/home-panel-BtxdqXDe.js +0 -3
  144. package/dist/packem_shared/result-chart-Gywg9DOk.js +0 -1
  145. package/dist/packem_shared/schema-diagram-DTRaCp6Y.js +0 -2
  146. package/dist/packem_shared/studio-Drf4en3j.js +0 -2
  147. package/dist/packem_shared/use-async-submit-BFIMhRqh.js +0 -1
  148. package/dist/standalone/chunk-5KCULF7S.js +0 -11
  149. package/dist/standalone/chunk-GZMKPBTJ.js +0 -1
  150. package/dist/standalone/chunk-ILNELDFC.js +0 -1
  151. package/dist/standalone/chunk-MV4A2PAK.js +0 -1
  152. package/dist/standalone/chunk-Q2Q7FR3R.js +0 -1
  153. package/dist/standalone/chunk-S3DWUXGY.js +0 -62
  154. package/dist/standalone/chunk-UBIPFCOZ.js +0 -1
  155. package/dist/standalone/chunk-ZQPWVALL.js +0 -3
  156. package/dist/standalone/chunk-ZZJ7VUVZ.js +0 -1
  157. /package/dist/standalone/{chunk-7H7LZRLP.js → chunk-4KIQ5RLS.js} +0 -0
  158. /package/dist/standalone/{chunk-UU2QJMGJ.js → chunk-MKYEFQCA.js} +0 -0
  159. /package/dist/standalone/{chunk-KUVMORDQ.js → chunk-PKSAWP56.js} +0 -0
  160. /package/dist/standalone/{chunk-MIQTKZAR.js → chunk-WJQLNYGX.js} +0 -0
@@ -1,6 +1,6 @@
1
- import{c as K}from"react/compiler-runtime";import{useLunora as Oe}from"@lunora/react";import{useState as re,useMemo as Be,useCallback as Ze,useEffect as qe,useRef as ye,useId as et}from"react";import{ADMIN_FUNCTIONS as $e}from"../packem_shared/ADMIN_FUNCTIONS-4aE59aDq.js";import{u as _e,n as je,b as We}from"../packem_shared/browser-storage-xjTyMKY0.js";import{d as ke,f as de,g as Te,b as ze}from"../packem_shared/internal-zkEvTqy8.js";import{r as tt}from"../packem_shared/shard-history-DMEW5VBE.js";import{k as nt}from"../packem_shared/use-sql-assistant-Dtw55kKM.js";import ot from"../packem_shared/useDebounced-CU-uftxO.js";import{useT as le}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{c as ue}from"../packem_shared/utils-bhneXptQ.js";import{jsx as u,jsxs as A,Fragment as Ee}from"react/jsx-runtime";import{u as rt}from"../packem_shared/input-JHu63lTv.js";import{I as lt}from"../packem_shared/result-chart-Gywg9DOk.js";import{ShardInput as st}from"../packem_shared/ShardInput-BVn2iCU0.js";import{A as at}from"../packem_shared/alert-CVcOFuDR.js";import{K as it}from"../packem_shared/grid-features-Db_BNYRo.js";import{d as ct,m as He,f as dt,n as ut,p as mt,u as ft}from"../packem_shared/table-DdJBrClo.js";import{g as ht}from"../packem_shared/data-grid-Ci4-tZkk.js";const pt=["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"],bt=["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),gt=new RegExp(`${Ce}${String.raw`(\d+)`}${Ce}`,"gu"),xt=pt.map(l=>({pattern:new RegExp(String.raw`\b${l.replaceAll(" ",String.raw`\s+`)}\b`,"giu"),replacement:l})),vt=bt.map(l=>({pattern:new RegExp(String.raw`\s+${l.replaceAll(" ",String.raw`\s+`)}\b`,"gu"),replacement:`
2
- ${l}`})),yt=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 xt)t=t.replaceAll(n,r);for(const{pattern:n,replacement:r}of vt)t=t.replaceAll(n,r);return t=t.replaceAll(gt,(n,r)=>e[Number(r)]??""),t},wt=/^(?:explain\s+(?:query\s+plan\s+)?)?(?:select|with)\b/iu,St=/\b(?:alter|attach|create|delete|detach|drop|insert|pragma|reindex|replace|truncate|update|vacuum)\b/iu,Nt=/^\w+/u,kt=/;\s*$/u,Ct=/\s/u,qt=(l,e)=>{let t=e+2;for(;t<l.length&&l[t]!==`
3
- `;)t+=1;return t},$t=(l,e)=>{const t=l.indexOf("*/",e+2);return t===-1?-1:t+2},Tt=l=>{let e=0;for(;e<l.length;){const t=l[e];if(t!==void 0&&Ct.test(t))e+=1;else if(t==="-"&&l[e+1]==="-")e=qt(l,e);else if(t==="/"&&l[e+1]==="*"){const n=$t(l,e);if(n===-1)break;e=n}else break}return e},Rt=l=>{const e=Tt(l),t=l.slice(e).trimEnd();if(t==="")return{code:"SQL_EMPTY",message:"the query is empty"};const n=t.replace(kt,""),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(!wt.test(n))return{code:"SQL_NOT_READONLY",length:Nt.exec(n)?.[0].length??1,message:o,offset:e};const s=St.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}},It=/\b(?:from|join)\s+([a-z_][\w$]*)(?:\s+(?:as\s+)?([a-z_][\w$]*))?/giu,Et=/(?:\bwith\s+(?:recursive\s+)?|,\s*)([a-z_][\w$]*)\s+as\s*\(/giu,Lt=new Set(["cross","full","group","having","inner","join","left","limit","offset","on","order","right","union","using","where","window"]),_t=/[^\n]/gu,Ot=(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},Mt=l=>{let e="",t=0;for(;t<l.length;){const n=Ot(l,t);n===-1?(e+=l.slice(t,t+1),t+=1):(e+=l.slice(t,n).replaceAll(_t," "),t=n)}return e},Dt=l=>{const e=new Set;for(const t of l.matchAll(Et))e.add((t[1]??"").toLowerCase());return e},At=(l,e)=>{const t=new Map;for(const n of l.matchAll(It)){const r=(n[1]??"").toLowerCase(),o=(n[2]??"").toLowerCase();e.has(r)&&(t.set(r,r),o!==""&&!Lt.has(o)&&t.set(o,r))}return t},Ke=(l,e)=>{const t=Mt(l),n=new Set(e.map(r=>r.toLowerCase()));return{ctes:Dt(t),masked:t,targets:At(t,n)}},Bt=/^(?:__lunora|sqlite_)/iu,zt=/\b(?:from|join)\s+([a-z_][\w$]*)/giu,Ht=/\b([a-z_][\w$]*)\.([a-z_][\w$]*)/giu,Pt=new Set(["cross","full","group","having","inner","join","lateral","left","limit","offset","order","right","select","union","where","window"]),Ft=(l,e,t)=>{const n=[];for(const r of l.matchAll(zt)){const o=r[1]??"",s=o.toLowerCase();!e.has(s)&&!t.has(s)&&!Pt.has(s)&&!Bt.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},Qt=(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(Ht)){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},jt=(l,e)=>{if(l.trim()==="")return[];const t=Rt(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}=Ke(l,e.tables),s=new Set(e.tables.map(d=>d.toLowerCase()));return[...Ft(r,s,n),...Qt(r,e,o)]},Wt=Te($e.lintSql),Kt=600,Ut=(l,e,t)=>{const n=Oe(),[r,o]=re([]),s=Be(()=>jt(l,e),[l,e]),d=ot(l,Kt),a=s.some(h=>h.source==="gate")||d.trim()==="",i=Ze(async h=>{try{const p=await n.query(Wt,{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 Be(()=>f?[...s,...r]:s,[s,r,f])},Se=8,Yt=["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"],Jt=new Set(["AND","BY","HAVING","ON","OR","SELECT","WHERE"]),Gt=/[\w$]/,Ue=l=>l!==void 0&&Gt.test(l),Ye=l=>{let e=l.length;for(;e>0&&Ue(l[e-1]);)e-=1;return l.slice(e)},Je=(l,e)=>{let t=e;for(;t>0&&Ue(l[t-1]);)t-=1;return{end:e,start:t,text:l.slice(t,e)}},Pe=(l,e)=>{const t=l.slice(0,e).trimEnd();return t.endsWith(".")||Jt.has(Ye(t).toUpperCase())},Vt=(l,e,t)=>{const n=l.slice(0,e);if(!n.endsWith("."))return;const r=Ye(n.slice(0,-1));if(r!=="")return Ke(l,t).targets.get(r.toLowerCase())??r},Me=(l,e)=>l.toLowerCase().startsWith(e.toLowerCase()),Fe=(l,e,t,n)=>{const r=[];for(const o of l)if(Me(o,e)&&(r.push(n(o)),r.length>=t))break;return r},Xt=(l,e,t)=>{const n=new Map;for(const[r,o]of Object.entries(l.columns))for(const s of o)if(Me(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}))},Zt=(l,e,t)=>{const n=Je(l,e),r=Vt(l,n.start,t.tables);if(r!==void 0){const a=t.columns[r]??t.columns[r.toLowerCase()]??[];return Fe(a,n.text,Se,i=>({detail:r,kind:"column",label:i}))}if(n.text===""&&!Pe(l,n.start))return[];const o=Fe(t.tables,n.text,Se,a=>({kind:"table",label:a})),s=Xt(t,n.text,Se),d=Yt.flatMap(a=>n.text!==""&&Me(a,n.text)&&a.toLowerCase()!==n.text.toLowerCase()?[{kind:"keyword",label:a}]:[]);return(Pe(l,n.start)?[...s,...o,...d]:[...o,...s,...d]).slice(0,Se)},en=(l,e,t)=>{const n=Je(l,e),r=l.slice(0,n.start)+t.label+l.slice(n.end);return{caret:n.start+t.label.length,value:r}},tn=["boxSizing","borderBottomWidth","borderLeftWidth","borderRightWidth","borderTopWidth","fontFamily","fontSize","fontStyle","fontWeight","letterSpacing","lineHeight","paddingBottom","paddingLeft","paddingRight","paddingTop","tabSize","textIndent","textTransform","width","wordSpacing"],nn=(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 tn)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}},on=(l,e,t)=>{const n=K(16),[r,o]=re(null);let s;n[0]!==l||n[1]!==e?(s=(y,b)=>{const m=Zt(y,b,l);if(m.length===0){o(null);return}const w=e.current,{left:N,top:S}=w===null?{left:0,top:0}:nn(w,b);o(k=>k!==null&&k.active===0&&k.left===N&&k.top===S&&k.suggestions.length===m.length&&k.suggestions.every((R,T)=>{const I=m.at(T);return R.kind===I?.kind&&R.label===I.label&&R.detail===I.detail})?k:{active:0,left:N,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=en(b.value,b.selectionStart,m);return t(w.value),o(null),requestAnimationFrame(()=>{const N=e.current;N!==null&&(N.focus(),N.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},rn={column:"column",keyword:"keyword",table:"table"},ln=20,sn=l=>{const e=K(17),{listboxId:t,onPick:n,state:r}=l,o=le();let s;e[0]!==r?(s=r===null?void 0:{left:r.left,top:r.top+ln},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)=>A("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(rn[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},an=Te($e.listTables),cn=Te($e.readTablePage),dn=l=>{const e=K(16),t=Oe();let n;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=[],e[0]=n):n=e[0];const[r,o]=re(n);let s;e[1]===Symbol.for("react.memo_cache_sentinel")?(s={},e[1]=s):s=e[1];const[d,a]=re(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(an,{},ke(l));b.cancelled||(o(m.map(mn)),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(cn,{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},Le=/\b(?:from|join|update|into)\s+([a-z_][\w$]*)|\b([a-z_][\w$]*)\s*\./gi,un=l=>{const e=new Set;Le.lastIndex=0;let t=Le.exec(l);for(;t!==null;)e.add(t[1]??t[2]),t=Le.exec(l);return[...e]};function mn(l){return l.name}const fn=l=>{const e=K(34),{onSubmit:t,probe:n,schema:r,setDraft:o}=l,s=et(),d=ye(null),a=ye(null),i=ye(null),f=on(r,i,o),{close:h,commit:p,commitAt:x,move:c,refresh:g,state:v}=f;let y;e[0]!==x?(y=$=>{x($)},e[0]=x,e[1]=y):y=e[1];const b=y;let m;e[2]!==g?(m=()=>{const $=i.current;$!==null&&$===document.activeElement&&g($.value,$.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 N;e[7]!==n||e[8]!==g||e[9]!==o?(N=$=>{const{selectionStart:B,value:F}=$.target;o(F);for(const P of un(F))n(P);g(F,B)},e[7]=n,e[8]=g,e[9]=o,e[10]=N):N=e[10];const S=N;let k;e[11]!==g?(k=$=>{const B=$.currentTarget;g(B.value,B.selectionStart)},e[11]=g,e[12]=k):k=e[12];const R=k;let T;e[13]!==v||e[14]!==h||e[15]!==p||e[16]!==c||e[17]!==t?(T=$=>{if(v!==null){if($.key==="ArrowDown"){$.preventDefault(),c(1);return}if($.key==="ArrowUp"){$.preventDefault(),c(-1);return}if($.key==="Escape"){$.preventDefault(),h();return}if(($.key==="Enter"||$.key==="Tab")&&!$.metaKey&&!$.ctrlKey&&p()){$.preventDefault();return}}($.metaKey||$.ctrlKey)&&$.key==="Enter"&&($.preventDefault(),t())},e[13]=v,e[14]=h,e[15]=p,e[16]=c,e[17]=t,e[18]=T):T=e[18];const I=T;let C;e[19]!==h?(C=()=>{requestAnimationFrame(()=>{h()})},e[19]=h,e[20]=C):C=e[20];const L=C;let _;e[21]===Symbol.for("react.memo_cache_sentinel")?(_=$=>{const{scrollLeft:B,scrollTop:F}=$.currentTarget;d.current!==null&&(d.current.scrollTop=F),a.current!==null&&(a.current.scrollTop=F,a.current.scrollLeft=B)},e[21]=_):_=e[21];const O=_;let q;e[22]===Symbol.for("react.memo_cache_sentinel")?(q=$=>{const B=i.current;B===null||$.offset===void 0||(B.focus(),B.setSelectionRange($.offset,$.offset+($.length??0)))},e[22]=q):q=e[22];const E=q;let M;e[23]!==S||e[24]!==L||e[25]!==I||e[26]!==R?(M={onBlur:L,onChange:S,onKeyDown:I,onScroll:O,onSelect:R},e[23]=S,e[24]=L,e[25]=I,e[26]=R,e[27]=M):M=e[27];let D;return e[28]!==v||e[29]!==h||e[30]!==s||e[31]!==b||e[32]!==M?(D={autocompleteState:v,closeAutocomplete:h,handlers:M,listboxId:s,onPickSuggestion:b,editorRef:i,gutterRef:d,overlayRef:a,revealDiagnostic:E},e[28]=v,e[29]=h,e[30]=s,e[31]=b,e[32]=M,e[33]=D):D=e[33],D},hn="lunora-studio-sql-tabs",pn="lunora-studio-sql-active-tab",De=12,ve=(l="",e="")=>({activeId:null,id:je("tab"),name:e,sql:l}),bn=()=>We(pn,""),gn=l=>{const e=K(16),[t,n]=_e(hn),[r,o]=bn(),[s]=re(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},Ge=l=>l.activeId===null&&l.sql.trim()!=="",xn=(l,e)=>[...l,e].slice(-De),vn=(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}},yn=(l,e)=>{const t=l.filter(n=>n.id===e);return t.length===0?{activeId:l[0]?.id??"",tabs:[...l]}:{activeId:e,tabs:t}},wn=(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}},Sn=l=>{const e=l();return{activeId:e.id,tabs:[e]}},Nn=(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]},Qe={error:null,pane:"results",result:null,running:!1},kn=l=>{const e=K(66),{activeId:t,setActiveId:n,setTabs:r,tabs:o}=gn(l);let s;e[0]===Symbol.for("react.memo_cache_sentinel")?(s={},e[0]=s):s=e[0];const[d,a]=re(s),[i,f]=re(null),[h,p]=re(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]??Qe;let v;e[4]!==c.id||e[5]!==r?(v=H=>{r(j=>j.map(U=>U.id===c.id?{...U,...H}:U))},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(j=>{const U=j[c.id]??Qe;return{...j,[c.id]:{...U,...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>=De)return;const H=ve();r(j=>xn(j,H)),n(H.id)},e[9]=n,e[10]=r,e[11]=o.length,e[12]=w):w=e[12];const N=w;let S;e[13]!==n||e[14]!==r?(S=H=>{f(null),p(null),r(H.tabs),n(H.activeId);const j=new Set(H.tabs.map(Cn));a(U=>Object.fromEntries(Object.entries(U).filter(ae=>{const[xe]=ae;return j.has(xe)})))},e[13]=n,e[14]=r,e[15]=S):S=e[15];const k=S;let R;e[16]!==k||e[17]!==o?(R=H=>{k(vn(o,H,ve))},e[16]=k,e[17]=o,e[18]=R):R=e[18];const T=R;let I;e[19]!==t||e[20]!==k||e[21]!==o?(I=(H,j)=>{k(H==="others"?yn(o,j):H==="right"?wn(o,j,t):Sn(ve))},e[19]=t,e[20]=k,e[21]=o,e[22]=I):I=e[22];const C=I;let L;e[23]!==C||e[24]!==i||e[25]!==o?(L=H=>{i!==null&&(Nn(H,o,i.id).some(qn)?p(H):C(H,i.id))},e[23]=C,e[24]=i,e[25]=o,e[26]=L):L=e[26];const _=L;let O;e[27]===Symbol.for("react.memo_cache_sentinel")?(O=(H,j)=>{j.preventDefault(),p(null),f({id:H,x:j.clientX,y:j.clientY})},e[27]=O):O=e[27];const q=O;let E;e[28]===Symbol.for("react.memo_cache_sentinel")?(E=()=>{f(null),p(null)},e[28]=E):E=e[28];const M=E;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 $=D;let B;e[30]!==_?(B=()=>{_("others")},e[30]=_,e[31]=B):B=e[31];const F=B;let P;e[32]!==_?(P=()=>{_("right")},e[32]=_,e[33]=P):P=e[33];const W=P;let Q;e[34]!==_?(Q=()=>{_("all")},e[34]=_,e[35]=Q):Q=e[35];const Y=Q;let J;e[36]!==C||e[37]!==h||e[38]!==i?(J=()=>{i!==null&&h!==null&&C(h,i.id),p(null)},e[36]=C,e[37]=h,e[38]=i,e[39]=J):J=e[39];const z=J;let G;e[40]===Symbol.for("react.memo_cache_sentinel")?(G=()=>{p(null)},e[40]=G):G=e[40];const ne=G;let V;e[41]!==i?(V=i===null?void 0:{left:i.x,top:i.y},e[41]=i,e[42]=V):V=e[42];const X=V;let Z;e[43]!==r?(Z=H=>{r(j=>j.map(U=>U.activeId===H?{...U,activeId:null}:U))},e[43]=r,e[44]=Z):Z=e[44];const ee=Z;let te;e[45]!==r?(te=(H,j)=>{r(U=>U.map(ae=>ae.id===H?{...ae,name:j}:ae))},e[45]=r,e[46]=te):te=e[46];const oe=te;let ie;return e[47]!==c||e[48]!==t||e[49]!==N||e[50]!==T||e[51]!==z||e[52]!==Y||e[53]!==F||e[54]!==W||e[55]!==g||e[56]!==m||e[57]!==y||e[58]!==h||e[59]!==oe||e[60]!==n||e[61]!==i||e[62]!==X||e[63]!==o||e[64]!==ee?(ie={activeTab:c,activeTabId:t,addEditorTab:N,cancelBulk:ne,closeEditorTab:T,closeTabMenu:M,confirmBulk:z,menuStyle:X,onBackdropContextMenu:$,onCloseAll:Y,onCloseOthers:F,onCloseToRight:W,openTabMenu:q,output:g,patchActiveOutput:m,patchActiveTab:y,pendingBulk:h,renameTab:oe,setActiveTabId:n,tabMenu:i,tabs:o,unlinkQuery:ee},e[47]=c,e[48]=t,e[49]=N,e[50]=T,e[51]=z,e[52]=Y,e[53]=F,e[54]=W,e[55]=g,e[56]=m,e[57]=y,e[58]=h,e[59]=oe,e[60]=n,e[61]=i,e[62]=X,e[63]=o,e[64]=ee,e[65]=ie):ie=e[65],ie};function Cn(l){return l.id}function qn(l){return Ge(l)}const $n="lunora-studio-sql-queries",Tn="lunora-studio-sql-history",Rn=25,In=l=>{const e=K(33),{loadIntoActiveTab:t,unlinkQuery:n}=l,r=le(),[o,s]=_e($n),[d,a]=_e(Tn),[i,f]=re(""),h=ye(null);let p;e[0]!==a?(p=q=>{a(E=>E[0]?.sql===q?E:[{at:Date.now(),sql:q},...E.filter(M=>M.sql!==q)].slice(0,Rn))},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 q={id:je("q"),name:r("Untitled query"),sql:""};s(E=>[q,...E]),t("",q.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=q=>{const E=o.find(M=>M.id===q);E!==void 0&&(t(E.sql,q),h.current?.querySelector(`[data-testid="sql-query-${q}"]`)?.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=q=>{s(E=>E.filter(M=>M.id!==q)),n(q)},e[9]=s,e[10]=n,e[11]=b):b=e[11];const m=b;let w;e[12]!==t?(w=q=>{t(q.currentTarget.dataset.sql??"",null)},e[12]=t,e[13]=w):w=e[13];const N=w;let S;e[14]!==t?(S=q=>{t(q.currentTarget.dataset.sql??"",null)},e[14]=t,e[15]=S):S=e[15];const k=S;let R;e[16]!==a?(R=()=>{a([])},e[16]=a,e[17]=R):R=e[17];const T=R;let I;e[18]===Symbol.for("react.memo_cache_sentinel")?(I=q=>{f(q.target.value)},e[18]=I):I=e[18];const C=I;let L;e[19]!==s?(L=(q,E)=>{s(M=>M.map(D=>D.id===q?{...D,sql:E}:D))},e[19]=s,e[20]=L):L=e[20];const _=L;let O;return e[21]!==T||e[22]!==m||e[23]!==d||e[24]!==k||e[25]!==N||e[26]!==g||e[27]!==o||e[28]!==x||e[29]!==i||e[30]!==y||e[31]!==_?(O={clearHistory:T,deleteQuery:m,history:d,listRef:h,loadFromHistory:k,loadTemplate:N,newQuery:g,onSearchChange:C,queries:o,recordHistory:x,search:i,selectQuery:y,updateQuerySql:_},e[21]=T,e[22]=m,e[23]=d,e[24]=k,e[25]=N,e[26]=g,e[27]=o,e[28]=x,e[29]=i,e[30]=y,e[31]=_,e[32]=O):O=e[32],O},Ve="p-3 font-mono text-xs leading-5 whitespace-pre-wrap break-words",En=(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},Ln=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.",_n=l=>{const e=K(51),{assistant:t,failed:n,onGenerated:r}=l,o=le(),[s,d]=re("");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=C=>{const L=s.trim();L===""&&!C||de((async()=>{const _=await t.generate(L===""?"fix the failing statement":L,C?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=C=>{d(C.target.value)},e[16]=g):g=e[16];let v;e[17]!==x?(v=C=>{C.key==="Enter"&&(C.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(rt,{"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 N;e[29]!==i||e[30]!==s?(N=i||s.trim()==="",e[29]=i,e[30]=s,e[31]=N):N=e[31];let S;e[32]!==x?(S=()=>{x(!1)},e[32]=x,e[33]=S):S=e[33];let k;e[34]!==i||e[35]!==o?(k=o(i?"Thinking…":"Draft SQL"),e[34]=i,e[35]=o,e[36]=k):k=e[36];let R;e[37]!==w||e[38]!==N||e[39]!==S||e[40]!==k?(R=u("button",{className:w,"data-testid":"sql-assistant-generate",disabled:N,onClick:S,type:"button",children:k}),e[37]=w,e[38]=N,e[39]=S,e[40]=k,e[41]=R):R=e[41];let T;e[42]!==n||e[43]!==i||e[44]!==x||e[45]!==o?(T=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]=T):T=e[46];let I;e[47]!==R||e[48]!==T||e[49]!==b?(I=A("div",{className:"flex items-center gap-2",children:[b,R,T]}),e[47]=R,e[48]=T,e[49]=b,e[50]=I):I=e[50],f=A("div",{className:"flex flex-col gap-1 border-b border-border px-3 py-2","data-testid":"sql-assistant",children:[I,h!==void 0&&u("p",{className:"text-[11px] text-muted-foreground","data-testid":"sql-assistant-reason",role:"status",children:Ln(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},On=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=En(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",Ve),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},Mn={gate:"read-only",plan:"plan",schema:"schema",syntax:"syntax"},Dn=l=>{const e=K(10),{diagnostics:t,onSelect:n}=l,r=le();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:A("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:Mn[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},An={minWidth:"2.75rem",paddingInline:"0.5rem"},Bn=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=le();let v,y,b,m,w,N,S,k;if(e[0]!==t||e[1]!==o||e[2]!==s||e[3]!==i||e[4]!==h){const B=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?(k=u(_n,{assistant:t,failed:s,onGenerated:h}),e[13]=t,e[14]=s,e[15]=h,e[16]=k):k=e[16],N="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=An,w=Array.from({length:B},zn),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]=N,e[11]=S,e[12]=k}else v=e[5],y=e[6],b=e[7],m=e[8],w=e[9],N=e[10],S=e[11],k=e[12];let R;e[17]!==v||e[18]!==y||e[19]!==b||e[20]!==m||e[21]!==w?(R=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]=R):R=e[22];let T;e[23]!==r||e[24]!==o||e[25]!==c?(T=u(On,{diagnostics:r,draft:o,scrollRef:c}),e[23]=r,e[24]=o,e[25]=c,e[26]=T):T=e[26];let I;e[27]!==n||e[28]!==f?(I=n===null?void 0:`${f}-opt-${n.active.toString()}`,e[27]=n,e[28]=f,e[29]=I):I=e[29];const C=n===null?void 0:f,L=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]!==I||e[40]!==C||e[41]!==L||e[42]!==_?(O=u("textarea",{"aria-activedescendant":I,"aria-autocomplete":"list","aria-controls":C,"aria-expanded":L,"aria-label":_,className:`relative size-full resize-none bg-transparent outline-none ${Ve}`,"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]=I,e[40]=C,e[41]=L,e[42]=_,e[43]=O):O=e[43];let q;e[44]!==n||e[45]!==f||e[46]!==p?(q=u(sn,{listboxId:f,onPick:p,state:n}),e[44]=n,e[45]=f,e[46]=p,e[47]=q):q=e[47];let E;e[48]!==T||e[49]!==O||e[50]!==q?(E=A("div",{className:"relative min-w-0 flex-1 bg-background",children:[T,O,q]}),e[48]=T,e[49]=O,e[50]=q,e[51]=E):E=e[51];let M;e[52]!==E||e[53]!==N||e[54]!==R?(M=A("div",{className:N,children:[R,E]}),e[52]=E,e[53]=N,e[54]=R,e[55]=M):M=e[55];let D;e[56]!==r||e[57]!==x?(D=u(Dn,{diagnostics:r,onSelect:x}),e[56]=r,e[57]=x,e[58]=D):D=e[58];let $;return e[59]!==M||e[60]!==D||e[61]!==S||e[62]!==k?($=A("div",{className:S,children:[k,M,D]}),e[59]=M,e[60]=D,e[61]=S,e[62]=k,e[63]=$):$=e[63],$};function zn(l,e){return u("div",{children:e+1},e)}const Xe=[{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;"}],Hn=l=>{const e=K(29),{active:t,onDelete:n,onSelect:r,query:o}=l,s=le();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=A("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 N;return e[26]!==w||e[27]!==v?(N=A("li",{className:"group/q flex items-center",children:[v,w]}),e[26]=w,e[27]=v,e[28]=N):N=e[28],N},Pn=(l,e)=>{const t=e.trim().toLowerCase();return t===""?[...l]:l.filter(n=>n.name.toLowerCase().includes(t))},Fn=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=le();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 C=Pn(p,x);v="flex h-full w-64 shrink-0 flex-col border-e border-border bg-sidebar";let L;e[13]!==c?(L=c("Search queries…"),e[13]=c,e[14]=L):L=e[14];let _;e[15]!==f||e[16]!==x||e[17]!==L?(_=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:L,type:"text",value:x}),e[15]=f,e[16]=x,e[17]=L,e[18]=_):_=e[18];let O;e[19]!==c?(O=c("New query"),e[19]=c,e[20]=O):O=e[20];let q;e[21]!==c?(q=c("New query"),e[21]=c,e[22]=q):q=e[22];let E;e[23]===Symbol.for("react.memo_cache_sentinel")?(E=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]=E):E=e[23];let M;e[24]!==i||e[25]!==O||e[26]!==q?(M=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:q,type:"button",children:E}),e[24]=i,e[25]=O,e[26]=q,e[27]=M):M=e[27],e[28]!==M||e[29]!==_?(y=A("div",{className:"flex shrink-0 items-center gap-2 border-b border-border p-2",children:[_,M]}),e[28]=M,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 $;e[33]!==D?($=u("p",{className:"px-1 pb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:D}),e[33]=D,e[34]=$):$=e[34],b=A("div",{children:[$,C.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:C.map(B=>u(Hn,{active:t===B.id,onDelete:s,onSelect:h,query:B},B.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 N;e[39]!==a?(N=Xe.map(C=>u("li",{children:A("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":C.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"})}),C.label]})},C.label)),e[39]=a,e[40]=N):N=e[40];let S;e[41]!==N?(S=u("ul",{className:"flex flex-col gap-px",children:N}),e[41]=N,e[42]=S):S=e[42];let k;e[43]!==w||e[44]!==S?(k=A("div",{children:[w,S]}),e[43]=w,e[44]=S,e[45]=k):k=e[45];let R;e[46]!==n||e[47]!==o||e[48]!==d||e[49]!==c?(R=n.length>0&&A("div",{children:[A("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(C=>u("li",{children:A("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":C.sql,"data-testid":"sql-history-item",onClick:d,title:C.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:C.sql})]})},`${C.at.toString()}:${C.sql}`))})]}),e[46]=n,e[47]=o,e[48]=d,e[49]=c,e[50]=R):R=e[50];let T;e[51]!==g||e[52]!==R||e[53]!==b||e[54]!==k?(T=A("div",{className:g,children:[b,k,R]}),e[51]=g,e[52]=R,e[53]=b,e[54]=k,e[55]=T):T=e[55];let I;return e[56]!==T||e[57]!==v||e[58]!==y?(I=A("aside",{className:v,children:[y,T]}),e[56]=T,e[57]=v,e[58]=y,e[59]=I):I=e[59],I},Qn=l=>{const e=K(19),{result:t}=l,n=le();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(jn),e[5]=t.columns,e[6]=r):r=e[6];let o;e[7]!==r?(o=u(ct,{className:"sticky top-0 z-10 bg-muted",children:u(He,{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(He,{"data-testid":"sql-row",children:t.columns.map(p=>u(ft,{className:"max-w-md truncate font-mono text-xs",children:u(ht,{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(dt,{children:s}),e[14]=s,e[15]=d):d=e[15];let a;return e[16]!==o||e[17]!==d?(a=A(ut,{"data-testid":"sql-rows",children:[o,d]}),e[16]=o,e[17]=d,e[18]=a):a=e[18],a};function jn(l){return u(mt,{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"}`,Wn=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=le(),w=c==="results";let N;e[0]!==w?(N=Ne(w),e[0]=w,e[1]=N):N=e[1];let S;e[2]!==m?(S=m("Results"),e[2]=m,e[3]=S):S=e[3];let k;e[4]!==p||e[5]!==N||e[6]!==S?(k=u("button",{className:N,"data-testid":"sql-tab-results",onClick:p,type:"button",children:S}),e[4]=p,e[5]=N,e[6]=S,e[7]=k):k=e[7];const R=c==="chart";let T;e[8]!==R?(T=Ne(R),e[8]=R,e[9]=T):T=e[9];let I;e[10]!==m?(I=m("Chart"),e[10]=m,e[11]=I):I=e[11];let C;e[12]!==f||e[13]!==T||e[14]!==I?(C=u("button",{className:T,"data-testid":"sql-tab-chart",onClick:f,type:"button",children:I}),e[12]=f,e[13]=T,e[14]=I,e[15]=C):C=e[15];let L;e[16]!==t||e[17]!==d||e[18]!==c||e[19]!==g||e[20]!==m?(L=!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]=L):L=e[21];const _=c==="explain";let O;e[22]!==_?(O=Ne(_),e[22]=_,e[23]=O):O=e[23];let q;e[24]!==m?(q=m("Explain"),e[24]=m,e[25]=q):q=e[25];let E;e[26]!==h||e[27]!==O||e[28]!==q?(E=u("button",{className:O,"data-testid":"sql-tab-explain",onClick:h,type:"button",children:q}),e[26]=h,e[27]=O,e[28]=q,e[29]=E):E=e[29];let M;e[30]!==m?(M=m("Split editor and results"),e[30]=m,e[31]=M):M=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 $;e[32]!==m?($=m("Split editor and results"),e[32]=m,e[33]=$):$=e[33];let B;e[34]===Symbol.for("react.memo_cache_sentinel")?(B=A("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]=B):B=e[34];let F;e[35]!==x||e[36]!==b||e[37]!==M||e[38]!==D||e[39]!==$?(F=u("button",{"aria-label":M,"aria-pressed":b,className:D,"data-testid":"sql-split-toggle",onClick:x,title:$,type:"button",children:B}),e[35]=x,e[36]=b,e[37]=M,e[38]=D,e[39]=$,e[40]=F):F=e[40];let P;e[41]!==g?(P=g!==null&&g.columns.length>0&&u(it,{columns:g.columns,name:"query-result",rows:g.rows}),e[41]=g,e[42]=P):P=e[42];let W;e[43]!==m?(W=m("Format"),e[43]=m,e[44]=W):W=e[44];let Q;e[45]!==s||e[46]!==v||e[47]!==W?(Q=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:W}),e[45]=s,e[46]=v,e[47]=W,e[48]=Q):Q=e[48];let Y;e[49]!==i||e[50]!==y?(Y=u(st,{onChange:i,testId:"sql-shard-input",value:y}),e[49]=i,e[50]=y,e[51]=Y):Y=e[51];let J;e[52]!==v||e[53]!==m?(J=m(v?"Running…":"Run"),e[52]=v,e[53]=m,e[54]=J):J=e[54];let z;e[55]===Symbol.for("react.memo_cache_sentinel")?(z=u("kbd",{className:"rounded border border-primary-foreground/30 px-1 font-sans text-[10px]",children:"⌘↵"}),e[55]=z):z=e[55];let G;e[56]!==a||e[57]!==v||e[58]!==J?(G=A("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:[J,z]}),e[56]=a,e[57]=v,e[58]=J,e[59]=G):G=e[59];let ne;e[60]!==F||e[61]!==P||e[62]!==Q||e[63]!==Y||e[64]!==G?(ne=A("div",{className:"ms-auto flex items-center gap-2",children:[F,P,Q,Y,G]}),e[60]=F,e[61]=P,e[62]=Q,e[63]=Y,e[64]=G,e[65]=ne):ne=e[65];let V;e[66]!==E||e[67]!==ne||e[68]!==k||e[69]!==C||e[70]!==L?(V=A("div",{className:"flex shrink-0 items-center gap-2 border-b border-border pe-2",children:[k,C,L,E,ne]}),e[66]=E,e[67]=ne,e[68]=k,e[69]=C,e[70]=L,e[71]=V):V=e[71];let X;e[72]!==o?(X=o!==null&&u(at,{className:"m-3 font-mono text-xs",testId:"sql-error",variant:"destructive",children:o}),e[72]=o,e[73]=X):X=e[73];let Z;e[74]!==o||e[75]!==g||e[76]!==m?(Z=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]=Z):Z=e[77];let ee;e[78]!==n||e[79]!==o||e[80]!==c||e[81]!==g||e[82]!==m?(ee=o===null&&g!==null&&A("div",{"data-testid":"sql-result",children:[c==="chart"?u(lt,{axes:n,result:g}):u(Qn,{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 te;e[84]!==X||e[85]!==Z||e[86]!==ee?(te=A("div",{className:"min-h-0 flex-1 overflow-auto",children:[X,Z,ee]}),e[84]=X,e[85]=Z,e[86]=ee,e[87]=te):te=e[87];let oe;return e[88]!==r||e[89]!==V||e[90]!==te?(oe=A("div",{className:r,children:[V,te]}),e[88]=r,e[89]=V,e[90]=te,e[91]=oe):oe=e[91],oe},Kn=(l,e)=>l.trim()===""?e:(l.split(`
6
- `)[0]??l).slice(0,24),Un=l=>{l?.focus(),l?.select()},Yn=l=>{const e=K(14),{initial:t,onCancel:n,onCommit:r,placeholder:o,testId:s}=l,d=le();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:Un,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},Jn=l=>{const e=K(29),{idBase:t,onDiscard:n,onKeep:r}=l,o=le(),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=A("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},Gn=l=>{const e=K(47),{active:t,canClose:n,onClose:r,onMenu:o,onRename:s,onSelect:d,tab:a}=l,i=le(),[f,h]=re(!1),[p,x]=re(!1);let c;e[0]!==o||e[1]!==a.id?(c=Q=>{o(a.id,Q)},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=Q=>{Q.stopPropagation(),Ge(a)?x(!0):r(a.id)},e[7]=r,e[8]=a,e[9]=w):w=e[9];const N=w;let S;e[10]!==r||e[11]!==a.id?(S=Q=>{Q.stopPropagation(),x(!1),r(a.id)},e[10]=r,e[11]=a.id,e[12]=S):S=e[12];const k=S;let R;e[13]===Symbol.for("react.memo_cache_sentinel")?(R=Q=>{Q.stopPropagation(),x(!1)},e[13]=R):R=e[13];const T=R;let I;e[14]!==s||e[15]!==a.id?(I=Q=>{s(a.id,Q),h(!1)},e[14]=s,e[15]=a.id,e[16]=I):I=e[16];const C=I;let L;e[17]===Symbol.for("react.memo_cache_sentinel")?(L=()=>{h(!1)},e[17]=L):L=e[17];const _=L;let O;e[18]!==a.name?(O=a.name.trim(),e[18]=a.name,e[19]=O):O=e[19];const q=O;let E;e[20]!==i||e[21]!==a.sql?(E=Kn(a.sql,i("Untitled")),e[20]=i,e[21]=a.sql,e[22]=E):E=e[22];const M=E,D=t?"bg-background text-foreground":"bg-muted/40 text-muted-foreground hover:text-foreground";let $;e[23]!==D?($=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]=$):$=e[24];const B=`sql-tab-${a.id}`;let F;e[25]!==t||e[26]!==C||e[27]!==q||e[28]!==M||e[29]!==f||e[30]!==y||e[31]!==i||e[32]!==a.id?(F=f?u(Yn,{initial:q,onCancel:_,onCommit:C,placeholder:M,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:q===""?M:q}),e[25]=t,e[26]=C,e[27]=q,e[28]=M,e[29]=f,e[30]=y,e[31]=i,e[32]=a.id,e[33]=F):F=e[33];let P;e[34]!==n||e[35]!==k||e[36]!==p||e[37]!==N||e[38]!==i||e[39]!==a.id?(P=n&&(p?u(Jn,{idBase:a.id,onDiscard:k,onKeep:T}):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:N,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]=k,e[36]=p,e[37]=N,e[38]=i,e[39]=a.id,e[40]=P):P=e[40];let W;return e[41]!==g||e[42]!==$||e[43]!==B||e[44]!==F||e[45]!==P?(W=A("div",{className:$,"data-testid":B,onContextMenu:g,children:[F,P]}),e[41]=g,e[42]=$,e[43]=B,e[44]=F,e[45]=P,e[46]=W):W=e[46],W},Vn=l=>{const e=K(43),{model:t,onSelect:n}=l,r=le(),{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 N;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=q=>u(Gn,{active:q.id===o.id,canClose:w.length>1,onClose:a,onMenu:v,onRename:b,onSelect:n,tab:q},q.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],N=w.map(O),e[0]=o,e[1]=a,e[2]=n,e[3]=v,e[4]=b,e[5]=w,e[6]=N}else N=e[6];let S;e[14]!==r?(S=r("New tab"),e[14]=r,e[15]=S):S=e[15];const k=w.length>=De;let R;e[16]!==r?(R=r("New tab"),e[16]=r,e[17]=R):R=e[17];let T;e[18]===Symbol.for("react.memo_cache_sentinel")?(T=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]=T):T=e[18];let I;e[19]!==s||e[20]!==S||e[21]!==k||e[22]!==R?(I=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:k,onClick:s,title:R,type:"button",children:T}),e[19]=s,e[20]=S,e[21]=k,e[22]=R,e[23]=I):I=e[23];let C;e[24]!==N||e[25]!==I?(C=A("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:[N,I]}),e[24]=N,e[25]=I,e[26]=C):C=e[26];let L;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?(L=m!==null&&A(Ee,{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?A(Ee,{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")})]}):A("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?")}),A("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]=L):L=e[39];let _;return e[40]!==C||e[41]!==L?(_=A(Ee,{children:[C,L]}),e[40]=C,e[41]=L,e[42]=_):_=e[42],_},Xn=Te($e.runSql),Zn="lunora-studio-sql-split-view",eo=()=>ve(Xe[0]?.sql??""),wo=l=>{const e=K(102),{initialShardKey:t}=l,n=Oe(),r=kn(eo),{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=In(x),{recordHistory:g,updateQuerySql:v}=c,y=o.sql,{activeId:b}=o,{chart:m,error:w,failed:N,result:S,running:k}=s,R=s.pane,[T,I]=re(t??""),[C,L]=We(Zn,!1),{probe:_,schema:O}=dn(T);let q;e[6]!==b||e[7]!==a||e[8]!==v?(q=se=>{a({sql:se}),b!==null&&v(b,se)},e[6]=b,e[7]=a,e[8]=v,e[9]=q):q=e[9];const E=q,M=Ut(y,O,T),D=nt(T);let $;e[10]!==D||e[11]!==d||e[12]!==S?($=()=>{S!==null&&de((async()=>{const se=await D.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]=D,e[11]=d,e[12]=S,e[13]=$):$=e[13];const B=$;let F;e[14]!==n||e[15]!==y||e[16]!==d||e[17]!==g||e[18]!==T?(F=async se=>{if(y.trim()==="")return;d({running:!0});const ce=se==="explain"?`EXPLAIN QUERY PLAN ${y}`:y;try{const Ie=await n.query(Xn,{sql:ce},ke(T));d({chart:void 0,error:null,failed:void 0,pane:se,result:Ie,running:!1}),tt(T),g(ce)}catch(Ie){const Ae=Ie;d({chart:void 0,error:ze(Ae),failed:{error:ze(Ae),sql:ce},pane:se,result:null,running:!1})}},e[14]=n,e[15]=y,e[16]=d,e[17]=g,e[18]=T,e[19]=F):F=e[19];const P=F;let W;e[20]!==P?(W=()=>{de(P("results"))},e[20]=P,e[21]=W):W=e[21];const Q=W;let Y;e[22]!==s.pane||e[23]!==P?(Y=()=>{de(P(s.pane))},e[22]=s.pane,e[23]=P,e[24]=Y):Y=e[24];let J;e[25]!==_||e[26]!==O||e[27]!==E||e[28]!==Y?(J={onSubmit:Y,probe:_,schema:O,setDraft:E},e[25]=_,e[26]=O,e[27]=E,e[28]=Y,e[29]=J):J=e[29];const z=fn(J),{closeAutocomplete:G}=z;let ne;e[30]!==y||e[31]!==E?(ne=()=>{E(yt(y))},e[30]=y,e[31]=E,e[32]=ne):ne=e[32];const V=ne;let X;e[33]!==G||e[34]!==i?(X=se=>{G(),i(se)},e[33]=G,e[34]=i,e[35]=X):X=e[35];const Z=X;let ee;e[36]!==d?(ee=()=>{d({pane:"results"})},e[36]=d,e[37]=ee):ee=e[37];const te=ee;let oe;e[38]!==P?(oe=()=>{de(P("explain"))},e[38]=P,e[39]=oe):oe=e[39];const ie=oe;let H;e[40]!==d?(H=()=>{d({pane:"chart"})},e[40]=d,e[41]=H):H=e[41];const j=H;let U;e[42]!==L||e[43]!==C?(U=()=>{L(!C)},e[42]=L,e[43]=C,e[44]=U):U=e[44];const ae=U,xe=C?"flex min-h-0 flex-1 flex-row":"flex min-h-0 flex-1 flex-col",Re=C?"flex w-2/5 min-h-0 min-w-0 shrink-0 flex-col border-s border-border":"flex h-2/5 min-h-0 shrink-0 flex-col border-t border-border";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(Fn,{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]!==Z?(fe=u(Vn,{model:r,onSelect:Z}),e[58]=r,e[59]=Z,e[60]=fe):fe=e[60];let he;e[61]!==D||e[62]!==M||e[63]!==y||e[64]!==N||e[65]!==E||e[66]!==z.autocompleteState||e[67]!==z.editorRef||e[68]!==z.gutterRef||e[69]!==z.handlers||e[70]!==z.listboxId||e[71]!==z.onPickSuggestion||e[72]!==z.overlayRef||e[73]!==z.revealDiagnostic?(he=u(Bn,{assistant:D,autocomplete:z.autocompleteState,diagnostics:M,draft:y,editorRef:z.editorRef,failed:N,gutterRef:z.gutterRef,handlers:z.handlers,listboxId:z.listboxId,onGenerated:E,onPickSuggestion:z.onPickSuggestion,onRevealDiagnostic:z.revealDiagnostic,overlayRef:z.overlayRef}),e[61]=D,e[62]=M,e[63]=y,e[64]=N,e[65]=E,e[66]=z.autocompleteState,e[67]=z.editorRef,e[68]=z.gutterRef,e[69]=z.handlers,e[70]=z.listboxId,e[71]=z.onPickSuggestion,e[72]=z.overlayRef,e[73]=z.revealDiagnostic,e[74]=he):he=e[74];let pe;e[75]!==D||e[76]!==w||e[77]!==V||e[78]!==B||e[79]!==m||e[80]!==Q||e[81]!==S||e[82]!==Re||e[83]!==k||e[84]!==T||e[85]!==j||e[86]!==ie||e[87]!==te||e[88]!==C||e[89]!==R||e[90]!==ae?(pe=u(Wn,{assistant:D,chart:m,className:Re,error:w,onFormat:V,onInferChart:B,onRun:Q,onShardKeyChange:I,onShowChart:j,onShowExplain:ie,onShowResults:te,onToggleSplit:ae,pane:R,result:S,running:k,shardKey:T,splitView:C}),e[75]=D,e[76]=w,e[77]=V,e[78]=B,e[79]=m,e[80]=Q,e[81]=S,e[82]=Re,e[83]=k,e[84]=T,e[85]=j,e[86]=ie,e[87]=te,e[88]=C,e[89]=R,e[90]=ae,e[91]=pe):pe=e[91];let be;e[92]!==he||e[93]!==pe||e[94]!==xe?(be=A("div",{className:xe,children:[he,pe]}),e[92]=he,e[93]=pe,e[94]=xe,e[95]=be):be=e[95];let ge;e[96]!==fe||e[97]!==be?(ge=A("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=A("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{wo as SqlEditorPanel};
1
+ import{c as K}from"react/compiler-runtime";import{useLunora as Oe}from"@lunora/react";import{useState as re,useMemo as Be,useCallback as Ze,useEffect as $e,useRef as ye,useId as et}from"react";import{ADMIN_FUNCTIONS as qe}from"../packem_shared/ADMIN_FUNCTIONS-4aE59aDq.js";import{u as _e,n as je,b as We}from"../packem_shared/browser-storage-xjTyMKY0.js";import{d as ke,f as de,g as Te,b as ze}from"../packem_shared/internal-zkEvTqy8.js";import{r as tt}from"../packem_shared/shard-history-DMEW5VBE.js";import{k as nt}from"../packem_shared/use-sql-assistant-Dtw55kKM.js";import ot from"../packem_shared/useDebounced-CU-uftxO.js";import{useT as le}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{c as ue}from"../packem_shared/utils-bhneXptQ.js";import{jsx as u,jsxs as A,Fragment as Ee}from"react/jsx-runtime";import{u as rt}from"../packem_shared/input-JHu63lTv.js";import{I as lt}from"../packem_shared/result-chart-0VgP_3FP.js";import{ShardInput as st}from"../packem_shared/ShardInput-BVn2iCU0.js";import{A as at}from"../packem_shared/alert-CVcOFuDR.js";import{K as it}from"../packem_shared/grid-features-Y2YSjhCf.js";import{n as ct,f as He,b as dt,d as ut,m as mt,p as ft}from"../packem_shared/table-DZAB8cs3.js";import{g as ht}from"../packem_shared/data-grid-Ci4-tZkk.js";const pt=["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"],bt=["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),gt=new RegExp(`${Ce}${String.raw`(\d+)`}${Ce}`,"gu"),xt=pt.map(l=>({pattern:new RegExp(String.raw`\b${l.replaceAll(" ",String.raw`\s+`)}\b`,"giu"),replacement:l})),vt=bt.map(l=>({pattern:new RegExp(String.raw`\s+${l.replaceAll(" ",String.raw`\s+`)}\b`,"gu"),replacement:`
2
+ ${l}`})),yt=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 xt)t=t.replaceAll(n,r);for(const{pattern:n,replacement:r}of vt)t=t.replaceAll(n,r);return t=t.replaceAll(gt,(n,r)=>e[Number(r)]??""),t},wt=/^(?:explain\s+(?:query\s+plan\s+)?)?(?:select|with)\b/iu,St=/\b(?:alter|attach|create|delete|detach|drop|insert|pragma|reindex|replace|truncate|update|vacuum)\b/iu,Nt=/^\w+/u,kt=/;\s*$/u,Ct=/\s/u,$t=(l,e)=>{let t=e+2;for(;t<l.length&&l[t]!==`
3
+ `;)t+=1;return t},qt=(l,e)=>{const t=l.indexOf("*/",e+2);return t===-1?-1:t+2},Tt=l=>{let e=0;for(;e<l.length;){const t=l[e];if(t!==void 0&&Ct.test(t))e+=1;else if(t==="-"&&l[e+1]==="-")e=$t(l,e);else if(t==="/"&&l[e+1]==="*"){const n=qt(l,e);if(n===-1)break;e=n}else break}return e},Rt=l=>{const e=Tt(l),t=l.slice(e).trimEnd();if(t==="")return{code:"SQL_EMPTY",message:"the query is empty"};const n=t.replace(kt,""),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(!wt.test(n))return{code:"SQL_NOT_READONLY",length:Nt.exec(n)?.[0].length??1,message:o,offset:e};const s=St.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}},It=/\b(?:from|join)\s+([a-z_][\w$]*)(?:\s+(?:as\s+)?([a-z_][\w$]*))?/giu,Et=/(?:\bwith\s+(?:recursive\s+)?|,\s*)([a-z_][\w$]*)\s+as\s*\(/giu,Lt=new Set(["cross","full","group","having","inner","join","left","limit","offset","on","order","right","union","using","where","window"]),_t=/[^\n]/gu,Ot=(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},Mt=l=>{let e="",t=0;for(;t<l.length;){const n=Ot(l,t);n===-1?(e+=l.slice(t,t+1),t+=1):(e+=l.slice(t,n).replaceAll(_t," "),t=n)}return e},Dt=l=>{const e=new Set;for(const t of l.matchAll(Et))e.add((t[1]??"").toLowerCase());return e},At=(l,e)=>{const t=new Map;for(const n of l.matchAll(It)){const r=(n[1]??"").toLowerCase(),o=(n[2]??"").toLowerCase();e.has(r)&&(t.set(r,r),o!==""&&!Lt.has(o)&&t.set(o,r))}return t},Ke=(l,e)=>{const t=Mt(l),n=new Set(e.map(r=>r.toLowerCase()));return{ctes:Dt(t),masked:t,targets:At(t,n)}},Bt=/^(?:__lunora|sqlite_)/iu,zt=/\b(?:from|join)\s+([a-z_][\w$]*)/giu,Ht=/\b([a-z_][\w$]*)\.([a-z_][\w$]*)/giu,Pt=new Set(["cross","full","group","having","inner","join","lateral","left","limit","offset","order","right","select","union","where","window"]),Ft=(l,e,t)=>{const n=[];for(const r of l.matchAll(zt)){const o=r[1]??"",s=o.toLowerCase();!e.has(s)&&!t.has(s)&&!Pt.has(s)&&!Bt.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},Qt=(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(Ht)){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},jt=(l,e)=>{if(l.trim()==="")return[];const t=Rt(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}=Ke(l,e.tables),s=new Set(e.tables.map(d=>d.toLowerCase()));return[...Ft(r,s,n),...Qt(r,e,o)]},Wt=Te(qe.lintSql),Kt=600,Ut=(l,e,t)=>{const n=Oe(),[r,o]=re([]),s=Be(()=>jt(l,e),[l,e]),d=ot(l,Kt),a=s.some(h=>h.source==="gate")||d.trim()==="",i=Ze(async h=>{try{const p=await n.query(Wt,{sql:d},ke(t));h.cancelled||o(p.diagnostics??[])}catch{h.cancelled||o([])}},[n,d,t]);$e(()=>{if(a){o([]);return}const h={cancelled:!1};return de(i(h)),()=>{h.cancelled=!0}},[i,a]);const f=d===l;return Be(()=>f?[...s,...r]:s,[s,r,f])},Se=8,Yt=["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"],Jt=new Set(["AND","BY","HAVING","ON","OR","SELECT","WHERE"]),Gt=/[\w$]/,Ue=l=>l!==void 0&&Gt.test(l),Ye=l=>{let e=l.length;for(;e>0&&Ue(l[e-1]);)e-=1;return l.slice(e)},Je=(l,e)=>{let t=e;for(;t>0&&Ue(l[t-1]);)t-=1;return{end:e,start:t,text:l.slice(t,e)}},Pe=(l,e)=>{const t=l.slice(0,e).trimEnd();return t.endsWith(".")||Jt.has(Ye(t).toUpperCase())},Vt=(l,e,t)=>{const n=l.slice(0,e);if(!n.endsWith("."))return;const r=Ye(n.slice(0,-1));if(r!=="")return Ke(l,t).targets.get(r.toLowerCase())??r},Me=(l,e)=>l.toLowerCase().startsWith(e.toLowerCase()),Fe=(l,e,t,n)=>{const r=[];for(const o of l)if(Me(o,e)&&(r.push(n(o)),r.length>=t))break;return r},Xt=(l,e,t)=>{const n=new Map;for(const[r,o]of Object.entries(l.columns))for(const s of o)if(Me(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}))},Zt=(l,e,t)=>{const n=Je(l,e),r=Vt(l,n.start,t.tables);if(r!==void 0){const a=t.columns[r]??t.columns[r.toLowerCase()]??[];return Fe(a,n.text,Se,i=>({detail:r,kind:"column",label:i}))}if(n.text===""&&!Pe(l,n.start))return[];const o=Fe(t.tables,n.text,Se,a=>({kind:"table",label:a})),s=Xt(t,n.text,Se),d=Yt.flatMap(a=>n.text!==""&&Me(a,n.text)&&a.toLowerCase()!==n.text.toLowerCase()?[{kind:"keyword",label:a}]:[]);return(Pe(l,n.start)?[...s,...o,...d]:[...o,...s,...d]).slice(0,Se)},en=(l,e,t)=>{const n=Je(l,e),r=l.slice(0,n.start)+t.label+l.slice(n.end);return{caret:n.start+t.label.length,value:r}},tn=["boxSizing","borderBottomWidth","borderLeftWidth","borderRightWidth","borderTopWidth","fontFamily","fontSize","fontStyle","fontWeight","letterSpacing","lineHeight","paddingBottom","paddingLeft","paddingRight","paddingTop","tabSize","textIndent","textTransform","width","wordSpacing"],nn=(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 tn)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}},on=(l,e,t)=>{const n=K(16),[r,o]=re(null);let s;n[0]!==l||n[1]!==e?(s=(y,b)=>{const m=Zt(y,b,l);if(m.length===0){o(null);return}const w=e.current,{left:N,top:S}=w===null?{left:0,top:0}:nn(w,b);o(k=>k!==null&&k.active===0&&k.left===N&&k.top===S&&k.suggestions.length===m.length&&k.suggestions.every((R,T)=>{const I=m.at(T);return R.kind===I?.kind&&R.label===I.label&&R.detail===I.detail})?k:{active:0,left:N,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=en(b.value,b.selectionStart,m);return t(w.value),o(null),requestAnimationFrame(()=>{const N=e.current;N!==null&&(N.focus(),N.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},rn={column:"column",keyword:"keyword",table:"table"},ln=20,sn=l=>{const e=K(17),{listboxId:t,onPick:n,state:r}=l,o=le();let s;e[0]!==r?(s=r===null?void 0:{left:r.left,top:r.top+ln},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)=>A("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(rn[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},an=Te(qe.listTables),cn=Te(qe.readTablePage),dn=l=>{const e=K(16),t=Oe();let n;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=[],e[0]=n):n=e[0];const[r,o]=re(n);let s;e[1]===Symbol.for("react.memo_cache_sentinel")?(s={},e[1]=s):s=e[1];const[d,a]=re(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(an,{},ke(l));b.cancelled||(o(m.map(mn)),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]),$e(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(cn,{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},Le=/\b(?:from|join|update|into)\s+([a-z_][\w$]*)|\b([a-z_][\w$]*)\s*\./gi,un=l=>{const e=new Set;Le.lastIndex=0;let t=Le.exec(l);for(;t!==null;)e.add(t[1]??t[2]),t=Le.exec(l);return[...e]};function mn(l){return l.name}const fn=l=>{const e=K(34),{onSubmit:t,probe:n,schema:r,setDraft:o}=l,s=et(),d=ye(null),a=ye(null),i=ye(null),f=on(r,i,o),{close:h,commit:p,commitAt:x,move:c,refresh:g,state:v}=f;let y;e[0]!==x?(y=q=>{x(q)},e[0]=x,e[1]=y):y=e[1];const b=y;let m;e[2]!==g?(m=()=>{const q=i.current;q!==null&&q===document.activeElement&&g(q.value,q.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],$e(m,w);let N;e[7]!==n||e[8]!==g||e[9]!==o?(N=q=>{const{selectionStart:B,value:F}=q.target;o(F);for(const P of un(F))n(P);g(F,B)},e[7]=n,e[8]=g,e[9]=o,e[10]=N):N=e[10];const S=N;let k;e[11]!==g?(k=q=>{const B=q.currentTarget;g(B.value,B.selectionStart)},e[11]=g,e[12]=k):k=e[12];const R=k;let T;e[13]!==v||e[14]!==h||e[15]!==p||e[16]!==c||e[17]!==t?(T=q=>{if(v!==null){if(q.key==="ArrowDown"){q.preventDefault(),c(1);return}if(q.key==="ArrowUp"){q.preventDefault(),c(-1);return}if(q.key==="Escape"){q.preventDefault(),h();return}if((q.key==="Enter"||q.key==="Tab")&&!q.metaKey&&!q.ctrlKey&&p()){q.preventDefault();return}}(q.metaKey||q.ctrlKey)&&q.key==="Enter"&&(q.preventDefault(),t())},e[13]=v,e[14]=h,e[15]=p,e[16]=c,e[17]=t,e[18]=T):T=e[18];const I=T;let C;e[19]!==h?(C=()=>{requestAnimationFrame(()=>{h()})},e[19]=h,e[20]=C):C=e[20];const L=C;let _;e[21]===Symbol.for("react.memo_cache_sentinel")?(_=q=>{const{scrollLeft:B,scrollTop:F}=q.currentTarget;d.current!==null&&(d.current.scrollTop=F),a.current!==null&&(a.current.scrollTop=F,a.current.scrollLeft=B)},e[21]=_):_=e[21];const O=_;let $;e[22]===Symbol.for("react.memo_cache_sentinel")?($=q=>{const B=i.current;B===null||q.offset===void 0||(B.focus(),B.setSelectionRange(q.offset,q.offset+(q.length??0)))},e[22]=$):$=e[22];const E=$;let M;e[23]!==S||e[24]!==L||e[25]!==I||e[26]!==R?(M={onBlur:L,onChange:S,onKeyDown:I,onScroll:O,onSelect:R},e[23]=S,e[24]=L,e[25]=I,e[26]=R,e[27]=M):M=e[27];let D;return e[28]!==v||e[29]!==h||e[30]!==s||e[31]!==b||e[32]!==M?(D={autocompleteState:v,closeAutocomplete:h,handlers:M,listboxId:s,onPickSuggestion:b,editorRef:i,gutterRef:d,overlayRef:a,revealDiagnostic:E},e[28]=v,e[29]=h,e[30]=s,e[31]=b,e[32]=M,e[33]=D):D=e[33],D},hn="lunora-studio-sql-tabs",pn="lunora-studio-sql-active-tab",De=12,ve=(l="",e="")=>({activeId:null,id:je("tab"),name:e,sql:l}),bn=()=>We(pn,""),gn=l=>{const e=K(16),[t,n]=_e(hn),[r,o]=bn(),[s]=re(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]),$e(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},Ge=l=>l.activeId===null&&l.sql.trim()!=="",xn=(l,e)=>[...l,e].slice(-De),vn=(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}},yn=(l,e)=>{const t=l.filter(n=>n.id===e);return t.length===0?{activeId:l[0]?.id??"",tabs:[...l]}:{activeId:e,tabs:t}},wn=(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}},Sn=l=>{const e=l();return{activeId:e.id,tabs:[e]}},Nn=(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]},Qe={error:null,pane:"results",result:null,running:!1},kn=l=>{const e=K(66),{activeId:t,setActiveId:n,setTabs:r,tabs:o}=gn(l);let s;e[0]===Symbol.for("react.memo_cache_sentinel")?(s={},e[0]=s):s=e[0];const[d,a]=re(s),[i,f]=re(null),[h,p]=re(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]??Qe;let v;e[4]!==c.id||e[5]!==r?(v=H=>{r(j=>j.map(U=>U.id===c.id?{...U,...H}:U))},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(j=>{const U=j[c.id]??Qe;return{...j,[c.id]:{...U,...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>=De)return;const H=ve();r(j=>xn(j,H)),n(H.id)},e[9]=n,e[10]=r,e[11]=o.length,e[12]=w):w=e[12];const N=w;let S;e[13]!==n||e[14]!==r?(S=H=>{f(null),p(null),r(H.tabs),n(H.activeId);const j=new Set(H.tabs.map(Cn));a(U=>Object.fromEntries(Object.entries(U).filter(ae=>{const[xe]=ae;return j.has(xe)})))},e[13]=n,e[14]=r,e[15]=S):S=e[15];const k=S;let R;e[16]!==k||e[17]!==o?(R=H=>{k(vn(o,H,ve))},e[16]=k,e[17]=o,e[18]=R):R=e[18];const T=R;let I;e[19]!==t||e[20]!==k||e[21]!==o?(I=(H,j)=>{k(H==="others"?yn(o,j):H==="right"?wn(o,j,t):Sn(ve))},e[19]=t,e[20]=k,e[21]=o,e[22]=I):I=e[22];const C=I;let L;e[23]!==C||e[24]!==i||e[25]!==o?(L=H=>{i!==null&&(Nn(H,o,i.id).some($n)?p(H):C(H,i.id))},e[23]=C,e[24]=i,e[25]=o,e[26]=L):L=e[26];const _=L;let O;e[27]===Symbol.for("react.memo_cache_sentinel")?(O=(H,j)=>{j.preventDefault(),p(null),f({id:H,x:j.clientX,y:j.clientY})},e[27]=O):O=e[27];const $=O;let E;e[28]===Symbol.for("react.memo_cache_sentinel")?(E=()=>{f(null),p(null)},e[28]=E):E=e[28];const M=E;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 q=D;let B;e[30]!==_?(B=()=>{_("others")},e[30]=_,e[31]=B):B=e[31];const F=B;let P;e[32]!==_?(P=()=>{_("right")},e[32]=_,e[33]=P):P=e[33];const W=P;let Q;e[34]!==_?(Q=()=>{_("all")},e[34]=_,e[35]=Q):Q=e[35];const Y=Q;let J;e[36]!==C||e[37]!==h||e[38]!==i?(J=()=>{i!==null&&h!==null&&C(h,i.id),p(null)},e[36]=C,e[37]=h,e[38]=i,e[39]=J):J=e[39];const z=J;let G;e[40]===Symbol.for("react.memo_cache_sentinel")?(G=()=>{p(null)},e[40]=G):G=e[40];const ne=G;let V;e[41]!==i?(V=i===null?void 0:{left:i.x,top:i.y},e[41]=i,e[42]=V):V=e[42];const X=V;let Z;e[43]!==r?(Z=H=>{r(j=>j.map(U=>U.activeId===H?{...U,activeId:null}:U))},e[43]=r,e[44]=Z):Z=e[44];const ee=Z;let te;e[45]!==r?(te=(H,j)=>{r(U=>U.map(ae=>ae.id===H?{...ae,name:j}:ae))},e[45]=r,e[46]=te):te=e[46];const oe=te;let ie;return e[47]!==c||e[48]!==t||e[49]!==N||e[50]!==T||e[51]!==z||e[52]!==Y||e[53]!==F||e[54]!==W||e[55]!==g||e[56]!==m||e[57]!==y||e[58]!==h||e[59]!==oe||e[60]!==n||e[61]!==i||e[62]!==X||e[63]!==o||e[64]!==ee?(ie={activeTab:c,activeTabId:t,addEditorTab:N,cancelBulk:ne,closeEditorTab:T,closeTabMenu:M,confirmBulk:z,menuStyle:X,onBackdropContextMenu:q,onCloseAll:Y,onCloseOthers:F,onCloseToRight:W,openTabMenu:$,output:g,patchActiveOutput:m,patchActiveTab:y,pendingBulk:h,renameTab:oe,setActiveTabId:n,tabMenu:i,tabs:o,unlinkQuery:ee},e[47]=c,e[48]=t,e[49]=N,e[50]=T,e[51]=z,e[52]=Y,e[53]=F,e[54]=W,e[55]=g,e[56]=m,e[57]=y,e[58]=h,e[59]=oe,e[60]=n,e[61]=i,e[62]=X,e[63]=o,e[64]=ee,e[65]=ie):ie=e[65],ie};function Cn(l){return l.id}function $n(l){return Ge(l)}const qn="lunora-studio-sql-queries",Tn="lunora-studio-sql-history",Rn=25,In=l=>{const e=K(33),{loadIntoActiveTab:t,unlinkQuery:n}=l,r=le(),[o,s]=_e(qn),[d,a]=_e(Tn),[i,f]=re(""),h=ye(null);let p;e[0]!==a?(p=$=>{a(E=>E[0]?.sql===$?E:[{at:Date.now(),sql:$},...E.filter(M=>M.sql!==$)].slice(0,Rn))},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:je("q"),name:r("Untitled query"),sql:""};s(E=>[$,...E]),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 E=o.find(M=>M.id===$);E!==void 0&&(t(E.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(E=>E.filter(M=>M.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 N=w;let S;e[14]!==t?(S=$=>{t($.currentTarget.dataset.sql??"",null)},e[14]=t,e[15]=S):S=e[15];const k=S;let R;e[16]!==a?(R=()=>{a([])},e[16]=a,e[17]=R):R=e[17];const T=R;let I;e[18]===Symbol.for("react.memo_cache_sentinel")?(I=$=>{f($.target.value)},e[18]=I):I=e[18];const C=I;let L;e[19]!==s?(L=($,E)=>{s(M=>M.map(D=>D.id===$?{...D,sql:E}:D))},e[19]=s,e[20]=L):L=e[20];const _=L;let O;return e[21]!==T||e[22]!==m||e[23]!==d||e[24]!==k||e[25]!==N||e[26]!==g||e[27]!==o||e[28]!==x||e[29]!==i||e[30]!==y||e[31]!==_?(O={clearHistory:T,deleteQuery:m,history:d,listRef:h,loadFromHistory:k,loadTemplate:N,newQuery:g,onSearchChange:C,queries:o,recordHistory:x,search:i,selectQuery:y,updateQuerySql:_},e[21]=T,e[22]=m,e[23]=d,e[24]=k,e[25]=N,e[26]=g,e[27]=o,e[28]=x,e[29]=i,e[30]=y,e[31]=_,e[32]=O):O=e[32],O},Ve="p-3 font-mono text-xs leading-5 whitespace-pre-wrap break-words",En=(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},Ln=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.",_n=l=>{const e=K(51),{assistant:t,failed:n,onGenerated:r}=l,o=le(),[s,d]=re("");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=C=>{const L=s.trim();L===""&&!C||de((async()=>{const _=await t.generate(L===""?"fix the failing statement":L,C?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=C=>{d(C.target.value)},e[16]=g):g=e[16];let v;e[17]!==x?(v=C=>{C.key==="Enter"&&(C.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(rt,{"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 N;e[29]!==i||e[30]!==s?(N=i||s.trim()==="",e[29]=i,e[30]=s,e[31]=N):N=e[31];let S;e[32]!==x?(S=()=>{x(!1)},e[32]=x,e[33]=S):S=e[33];let k;e[34]!==i||e[35]!==o?(k=o(i?"Thinking…":"Draft SQL"),e[34]=i,e[35]=o,e[36]=k):k=e[36];let R;e[37]!==w||e[38]!==N||e[39]!==S||e[40]!==k?(R=u("button",{className:w,"data-testid":"sql-assistant-generate",disabled:N,onClick:S,type:"button",children:k}),e[37]=w,e[38]=N,e[39]=S,e[40]=k,e[41]=R):R=e[41];let T;e[42]!==n||e[43]!==i||e[44]!==x||e[45]!==o?(T=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]=T):T=e[46];let I;e[47]!==R||e[48]!==T||e[49]!==b?(I=A("div",{className:"flex items-center gap-2",children:[b,R,T]}),e[47]=R,e[48]=T,e[49]=b,e[50]=I):I=e[50],f=A("div",{className:"flex flex-col gap-1 border-b border-border px-3 py-2","data-testid":"sql-assistant",children:[I,h!==void 0&&u("p",{className:"text-[11px] text-muted-foreground","data-testid":"sql-assistant-reason",role:"status",children:Ln(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},On=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=En(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",Ve),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},Mn={gate:"read-only",plan:"plan",schema:"schema",syntax:"syntax"},Dn=l=>{const e=K(10),{diagnostics:t,onSelect:n}=l,r=le();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:A("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:Mn[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},An={minWidth:"2.75rem",paddingInline:"0.5rem"},Bn=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=le();let v,y,b,m,w,N,S,k;if(e[0]!==t||e[1]!==o||e[2]!==s||e[3]!==i||e[4]!==h){const B=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?(k=u(_n,{assistant:t,failed:s,onGenerated:h}),e[13]=t,e[14]=s,e[15]=h,e[16]=k):k=e[16],N="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=An,w=Array.from({length:B},zn),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]=N,e[11]=S,e[12]=k}else v=e[5],y=e[6],b=e[7],m=e[8],w=e[9],N=e[10],S=e[11],k=e[12];let R;e[17]!==v||e[18]!==y||e[19]!==b||e[20]!==m||e[21]!==w?(R=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]=R):R=e[22];let T;e[23]!==r||e[24]!==o||e[25]!==c?(T=u(On,{diagnostics:r,draft:o,scrollRef:c}),e[23]=r,e[24]=o,e[25]=c,e[26]=T):T=e[26];let I;e[27]!==n||e[28]!==f?(I=n===null?void 0:`${f}-opt-${n.active.toString()}`,e[27]=n,e[28]=f,e[29]=I):I=e[29];const C=n===null?void 0:f,L=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]!==I||e[40]!==C||e[41]!==L||e[42]!==_?(O=u("textarea",{"aria-activedescendant":I,"aria-autocomplete":"list","aria-controls":C,"aria-expanded":L,"aria-label":_,className:`relative size-full resize-none bg-transparent outline-none ${Ve}`,"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]=I,e[40]=C,e[41]=L,e[42]=_,e[43]=O):O=e[43];let $;e[44]!==n||e[45]!==f||e[46]!==p?($=u(sn,{listboxId:f,onPick:p,state:n}),e[44]=n,e[45]=f,e[46]=p,e[47]=$):$=e[47];let E;e[48]!==T||e[49]!==O||e[50]!==$?(E=A("div",{className:"relative min-w-0 flex-1 bg-background",children:[T,O,$]}),e[48]=T,e[49]=O,e[50]=$,e[51]=E):E=e[51];let M;e[52]!==E||e[53]!==N||e[54]!==R?(M=A("div",{className:N,children:[R,E]}),e[52]=E,e[53]=N,e[54]=R,e[55]=M):M=e[55];let D;e[56]!==r||e[57]!==x?(D=u(Dn,{diagnostics:r,onSelect:x}),e[56]=r,e[57]=x,e[58]=D):D=e[58];let q;return e[59]!==M||e[60]!==D||e[61]!==S||e[62]!==k?(q=A("div",{className:S,children:[k,M,D]}),e[59]=M,e[60]=D,e[61]=S,e[62]=k,e[63]=q):q=e[63],q};function zn(l,e){return u("div",{children:e+1},e)}const Xe=[{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;"}],Hn=l=>{const e=K(29),{active:t,onDelete:n,onSelect:r,query:o}=l,s=le();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=A("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 N;return e[26]!==w||e[27]!==v?(N=A("li",{className:"group/q flex items-center",children:[v,w]}),e[26]=w,e[27]=v,e[28]=N):N=e[28],N},Pn=(l,e)=>{const t=e.trim().toLowerCase();return t===""?[...l]:l.filter(n=>n.name.toLowerCase().includes(t))},Fn=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=le();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 C=Pn(p,x);v="flex h-full w-64 shrink-0 flex-col border-e border-border bg-sidebar";let L;e[13]!==c?(L=c("Search queries…"),e[13]=c,e[14]=L):L=e[14];let _;e[15]!==f||e[16]!==x||e[17]!==L?(_=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:L,type:"text",value:x}),e[15]=f,e[16]=x,e[17]=L,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 E;e[23]===Symbol.for("react.memo_cache_sentinel")?(E=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]=E):E=e[23];let M;e[24]!==i||e[25]!==O||e[26]!==$?(M=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:E}),e[24]=i,e[25]=O,e[26]=$,e[27]=M):M=e[27],e[28]!==M||e[29]!==_?(y=A("div",{className:"flex shrink-0 items-center gap-2 border-b border-border p-2",children:[_,M]}),e[28]=M,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 q;e[33]!==D?(q=u("p",{className:"px-1 pb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:D}),e[33]=D,e[34]=q):q=e[34],b=A("div",{children:[q,C.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:C.map(B=>u(Hn,{active:t===B.id,onDelete:s,onSelect:h,query:B},B.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 N;e[39]!==a?(N=Xe.map(C=>u("li",{children:A("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":C.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"})}),C.label]})},C.label)),e[39]=a,e[40]=N):N=e[40];let S;e[41]!==N?(S=u("ul",{className:"flex flex-col gap-px",children:N}),e[41]=N,e[42]=S):S=e[42];let k;e[43]!==w||e[44]!==S?(k=A("div",{children:[w,S]}),e[43]=w,e[44]=S,e[45]=k):k=e[45];let R;e[46]!==n||e[47]!==o||e[48]!==d||e[49]!==c?(R=n.length>0&&A("div",{children:[A("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(C=>u("li",{children:A("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":C.sql,"data-testid":"sql-history-item",onClick:d,title:C.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:C.sql})]})},`${C.at.toString()}:${C.sql}`))})]}),e[46]=n,e[47]=o,e[48]=d,e[49]=c,e[50]=R):R=e[50];let T;e[51]!==g||e[52]!==R||e[53]!==b||e[54]!==k?(T=A("div",{className:g,children:[b,k,R]}),e[51]=g,e[52]=R,e[53]=b,e[54]=k,e[55]=T):T=e[55];let I;return e[56]!==T||e[57]!==v||e[58]!==y?(I=A("aside",{className:v,children:[y,T]}),e[56]=T,e[57]=v,e[58]=y,e[59]=I):I=e[59],I},Qn=l=>{const e=K(19),{result:t}=l,n=le();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(jn),e[5]=t.columns,e[6]=r):r=e[6];let o;e[7]!==r?(o=u(ct,{className:"sticky top-0 z-10 bg-muted",children:u(He,{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(He,{"data-testid":"sql-row",children:t.columns.map(p=>u(ft,{className:"max-w-md truncate font-mono text-xs",children:u(ht,{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(dt,{children:s}),e[14]=s,e[15]=d):d=e[15];let a;return e[16]!==o||e[17]!==d?(a=A(ut,{"data-testid":"sql-rows",children:[o,d]}),e[16]=o,e[17]=d,e[18]=a):a=e[18],a};function jn(l){return u(mt,{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"}`,Wn=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=le(),w=c==="results";let N;e[0]!==w?(N=Ne(w),e[0]=w,e[1]=N):N=e[1];let S;e[2]!==m?(S=m("Results"),e[2]=m,e[3]=S):S=e[3];let k;e[4]!==p||e[5]!==N||e[6]!==S?(k=u("button",{className:N,"data-testid":"sql-tab-results",onClick:p,type:"button",children:S}),e[4]=p,e[5]=N,e[6]=S,e[7]=k):k=e[7];const R=c==="chart";let T;e[8]!==R?(T=Ne(R),e[8]=R,e[9]=T):T=e[9];let I;e[10]!==m?(I=m("Chart"),e[10]=m,e[11]=I):I=e[11];let C;e[12]!==f||e[13]!==T||e[14]!==I?(C=u("button",{className:T,"data-testid":"sql-tab-chart",onClick:f,type:"button",children:I}),e[12]=f,e[13]=T,e[14]=I,e[15]=C):C=e[15];let L;e[16]!==t||e[17]!==d||e[18]!==c||e[19]!==g||e[20]!==m?(L=!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]=L):L=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 E;e[26]!==h||e[27]!==O||e[28]!==$?(E=u("button",{className:O,"data-testid":"sql-tab-explain",onClick:h,type:"button",children:$}),e[26]=h,e[27]=O,e[28]=$,e[29]=E):E=e[29];let M;e[30]!==m?(M=m("Split editor and results"),e[30]=m,e[31]=M):M=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 q;e[32]!==m?(q=m("Split editor and results"),e[32]=m,e[33]=q):q=e[33];let B;e[34]===Symbol.for("react.memo_cache_sentinel")?(B=A("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]=B):B=e[34];let F;e[35]!==x||e[36]!==b||e[37]!==M||e[38]!==D||e[39]!==q?(F=u("button",{"aria-label":M,"aria-pressed":b,className:D,"data-testid":"sql-split-toggle",onClick:x,title:q,type:"button",children:B}),e[35]=x,e[36]=b,e[37]=M,e[38]=D,e[39]=q,e[40]=F):F=e[40];let P;e[41]!==g?(P=g!==null&&g.columns.length>0&&u(it,{columns:g.columns,name:"query-result",rows:g.rows}),e[41]=g,e[42]=P):P=e[42];let W;e[43]!==m?(W=m("Format"),e[43]=m,e[44]=W):W=e[44];let Q;e[45]!==s||e[46]!==v||e[47]!==W?(Q=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:W}),e[45]=s,e[46]=v,e[47]=W,e[48]=Q):Q=e[48];let Y;e[49]!==i||e[50]!==y?(Y=u(st,{onChange:i,testId:"sql-shard-input",value:y}),e[49]=i,e[50]=y,e[51]=Y):Y=e[51];let J;e[52]!==v||e[53]!==m?(J=m(v?"Running…":"Run"),e[52]=v,e[53]=m,e[54]=J):J=e[54];let z;e[55]===Symbol.for("react.memo_cache_sentinel")?(z=u("kbd",{className:"rounded border border-primary-foreground/30 px-1 font-sans text-[10px]",children:"⌘↵"}),e[55]=z):z=e[55];let G;e[56]!==a||e[57]!==v||e[58]!==J?(G=A("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:[J,z]}),e[56]=a,e[57]=v,e[58]=J,e[59]=G):G=e[59];let ne;e[60]!==F||e[61]!==P||e[62]!==Q||e[63]!==Y||e[64]!==G?(ne=A("div",{className:"ms-auto flex items-center gap-2",children:[F,P,Q,Y,G]}),e[60]=F,e[61]=P,e[62]=Q,e[63]=Y,e[64]=G,e[65]=ne):ne=e[65];let V;e[66]!==E||e[67]!==ne||e[68]!==k||e[69]!==C||e[70]!==L?(V=A("div",{className:"flex shrink-0 items-center gap-2 border-b border-border pe-2",children:[k,C,L,E,ne]}),e[66]=E,e[67]=ne,e[68]=k,e[69]=C,e[70]=L,e[71]=V):V=e[71];let X;e[72]!==o?(X=o!==null&&u(at,{className:"m-3 font-mono text-xs",testId:"sql-error",variant:"destructive",children:o}),e[72]=o,e[73]=X):X=e[73];let Z;e[74]!==o||e[75]!==g||e[76]!==m?(Z=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]=Z):Z=e[77];let ee;e[78]!==n||e[79]!==o||e[80]!==c||e[81]!==g||e[82]!==m?(ee=o===null&&g!==null&&A("div",{"data-testid":"sql-result",children:[c==="chart"?u(lt,{axes:n,result:g}):u(Qn,{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 te;e[84]!==X||e[85]!==Z||e[86]!==ee?(te=A("div",{className:"min-h-0 flex-1 overflow-auto",children:[X,Z,ee]}),e[84]=X,e[85]=Z,e[86]=ee,e[87]=te):te=e[87];let oe;return e[88]!==r||e[89]!==V||e[90]!==te?(oe=A("div",{className:r,children:[V,te]}),e[88]=r,e[89]=V,e[90]=te,e[91]=oe):oe=e[91],oe},Kn=(l,e)=>l.trim()===""?e:(l.split(`
6
+ `)[0]??l).slice(0,24),Un=l=>{l?.focus(),l?.select()},Yn=l=>{const e=K(14),{initial:t,onCancel:n,onCommit:r,placeholder:o,testId:s}=l,d=le();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:Un,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},Jn=l=>{const e=K(29),{idBase:t,onDiscard:n,onKeep:r}=l,o=le(),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=A("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},Gn=l=>{const e=K(47),{active:t,canClose:n,onClose:r,onMenu:o,onRename:s,onSelect:d,tab:a}=l,i=le(),[f,h]=re(!1),[p,x]=re(!1);let c;e[0]!==o||e[1]!==a.id?(c=Q=>{o(a.id,Q)},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=Q=>{Q.stopPropagation(),Ge(a)?x(!0):r(a.id)},e[7]=r,e[8]=a,e[9]=w):w=e[9];const N=w;let S;e[10]!==r||e[11]!==a.id?(S=Q=>{Q.stopPropagation(),x(!1),r(a.id)},e[10]=r,e[11]=a.id,e[12]=S):S=e[12];const k=S;let R;e[13]===Symbol.for("react.memo_cache_sentinel")?(R=Q=>{Q.stopPropagation(),x(!1)},e[13]=R):R=e[13];const T=R;let I;e[14]!==s||e[15]!==a.id?(I=Q=>{s(a.id,Q),h(!1)},e[14]=s,e[15]=a.id,e[16]=I):I=e[16];const C=I;let L;e[17]===Symbol.for("react.memo_cache_sentinel")?(L=()=>{h(!1)},e[17]=L):L=e[17];const _=L;let O;e[18]!==a.name?(O=a.name.trim(),e[18]=a.name,e[19]=O):O=e[19];const $=O;let E;e[20]!==i||e[21]!==a.sql?(E=Kn(a.sql,i("Untitled")),e[20]=i,e[21]=a.sql,e[22]=E):E=e[22];const M=E,D=t?"bg-background text-foreground":"bg-muted/40 text-muted-foreground hover:text-foreground";let q;e[23]!==D?(q=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]=q):q=e[24];const B=`sql-tab-${a.id}`;let F;e[25]!==t||e[26]!==C||e[27]!==$||e[28]!==M||e[29]!==f||e[30]!==y||e[31]!==i||e[32]!==a.id?(F=f?u(Yn,{initial:$,onCancel:_,onCommit:C,placeholder:M,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:$===""?M:$}),e[25]=t,e[26]=C,e[27]=$,e[28]=M,e[29]=f,e[30]=y,e[31]=i,e[32]=a.id,e[33]=F):F=e[33];let P;e[34]!==n||e[35]!==k||e[36]!==p||e[37]!==N||e[38]!==i||e[39]!==a.id?(P=n&&(p?u(Jn,{idBase:a.id,onDiscard:k,onKeep:T}):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:N,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]=k,e[36]=p,e[37]=N,e[38]=i,e[39]=a.id,e[40]=P):P=e[40];let W;return e[41]!==g||e[42]!==q||e[43]!==B||e[44]!==F||e[45]!==P?(W=A("div",{className:q,"data-testid":B,onContextMenu:g,children:[F,P]}),e[41]=g,e[42]=q,e[43]=B,e[44]=F,e[45]=P,e[46]=W):W=e[46],W},Vn=l=>{const e=K(43),{model:t,onSelect:n}=l,r=le(),{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 N;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(Gn,{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],N=w.map(O),e[0]=o,e[1]=a,e[2]=n,e[3]=v,e[4]=b,e[5]=w,e[6]=N}else N=e[6];let S;e[14]!==r?(S=r("New tab"),e[14]=r,e[15]=S):S=e[15];const k=w.length>=De;let R;e[16]!==r?(R=r("New tab"),e[16]=r,e[17]=R):R=e[17];let T;e[18]===Symbol.for("react.memo_cache_sentinel")?(T=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]=T):T=e[18];let I;e[19]!==s||e[20]!==S||e[21]!==k||e[22]!==R?(I=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:k,onClick:s,title:R,type:"button",children:T}),e[19]=s,e[20]=S,e[21]=k,e[22]=R,e[23]=I):I=e[23];let C;e[24]!==N||e[25]!==I?(C=A("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:[N,I]}),e[24]=N,e[25]=I,e[26]=C):C=e[26];let L;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?(L=m!==null&&A(Ee,{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?A(Ee,{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")})]}):A("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?")}),A("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]=L):L=e[39];let _;return e[40]!==C||e[41]!==L?(_=A(Ee,{children:[C,L]}),e[40]=C,e[41]=L,e[42]=_):_=e[42],_},Xn=Te(qe.runSql),Zn="lunora-studio-sql-split-view",eo=()=>ve(Xe[0]?.sql??""),wo=l=>{const e=K(102),{initialShardKey:t}=l,n=Oe(),r=kn(eo),{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=In(x),{recordHistory:g,updateQuerySql:v}=c,y=o.sql,{activeId:b}=o,{chart:m,error:w,failed:N,result:S,running:k}=s,R=s.pane,[T,I]=re(t??""),[C,L]=We(Zn,!1),{probe:_,schema:O}=dn(T);let $;e[6]!==b||e[7]!==a||e[8]!==v?($=se=>{a({sql:se}),b!==null&&v(b,se)},e[6]=b,e[7]=a,e[8]=v,e[9]=$):$=e[9];const E=$,M=Ut(y,O,T),D=nt(T);let q;e[10]!==D||e[11]!==d||e[12]!==S?(q=()=>{S!==null&&de((async()=>{const se=await D.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]=D,e[11]=d,e[12]=S,e[13]=q):q=e[13];const B=q;let F;e[14]!==n||e[15]!==y||e[16]!==d||e[17]!==g||e[18]!==T?(F=async se=>{if(y.trim()==="")return;d({running:!0});const ce=se==="explain"?`EXPLAIN QUERY PLAN ${y}`:y;try{const Ie=await n.query(Xn,{sql:ce},ke(T));d({chart:void 0,error:null,failed:void 0,pane:se,result:Ie,running:!1}),tt(T),g(ce)}catch(Ie){const Ae=Ie;d({chart:void 0,error:ze(Ae),failed:{error:ze(Ae),sql:ce},pane:se,result:null,running:!1})}},e[14]=n,e[15]=y,e[16]=d,e[17]=g,e[18]=T,e[19]=F):F=e[19];const P=F;let W;e[20]!==P?(W=()=>{de(P("results"))},e[20]=P,e[21]=W):W=e[21];const Q=W;let Y;e[22]!==s.pane||e[23]!==P?(Y=()=>{de(P(s.pane))},e[22]=s.pane,e[23]=P,e[24]=Y):Y=e[24];let J;e[25]!==_||e[26]!==O||e[27]!==E||e[28]!==Y?(J={onSubmit:Y,probe:_,schema:O,setDraft:E},e[25]=_,e[26]=O,e[27]=E,e[28]=Y,e[29]=J):J=e[29];const z=fn(J),{closeAutocomplete:G}=z;let ne;e[30]!==y||e[31]!==E?(ne=()=>{E(yt(y))},e[30]=y,e[31]=E,e[32]=ne):ne=e[32];const V=ne;let X;e[33]!==G||e[34]!==i?(X=se=>{G(),i(se)},e[33]=G,e[34]=i,e[35]=X):X=e[35];const Z=X;let ee;e[36]!==d?(ee=()=>{d({pane:"results"})},e[36]=d,e[37]=ee):ee=e[37];const te=ee;let oe;e[38]!==P?(oe=()=>{de(P("explain"))},e[38]=P,e[39]=oe):oe=e[39];const ie=oe;let H;e[40]!==d?(H=()=>{d({pane:"chart"})},e[40]=d,e[41]=H):H=e[41];const j=H;let U;e[42]!==L||e[43]!==C?(U=()=>{L(!C)},e[42]=L,e[43]=C,e[44]=U):U=e[44];const ae=U,xe=C?"flex min-h-0 flex-1 flex-row":"flex min-h-0 flex-1 flex-col",Re=C?"flex w-2/5 min-h-0 min-w-0 shrink-0 flex-col border-s border-border":"flex h-2/5 min-h-0 shrink-0 flex-col border-t border-border";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(Fn,{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]!==Z?(fe=u(Vn,{model:r,onSelect:Z}),e[58]=r,e[59]=Z,e[60]=fe):fe=e[60];let he;e[61]!==D||e[62]!==M||e[63]!==y||e[64]!==N||e[65]!==E||e[66]!==z.autocompleteState||e[67]!==z.editorRef||e[68]!==z.gutterRef||e[69]!==z.handlers||e[70]!==z.listboxId||e[71]!==z.onPickSuggestion||e[72]!==z.overlayRef||e[73]!==z.revealDiagnostic?(he=u(Bn,{assistant:D,autocomplete:z.autocompleteState,diagnostics:M,draft:y,editorRef:z.editorRef,failed:N,gutterRef:z.gutterRef,handlers:z.handlers,listboxId:z.listboxId,onGenerated:E,onPickSuggestion:z.onPickSuggestion,onRevealDiagnostic:z.revealDiagnostic,overlayRef:z.overlayRef}),e[61]=D,e[62]=M,e[63]=y,e[64]=N,e[65]=E,e[66]=z.autocompleteState,e[67]=z.editorRef,e[68]=z.gutterRef,e[69]=z.handlers,e[70]=z.listboxId,e[71]=z.onPickSuggestion,e[72]=z.overlayRef,e[73]=z.revealDiagnostic,e[74]=he):he=e[74];let pe;e[75]!==D||e[76]!==w||e[77]!==V||e[78]!==B||e[79]!==m||e[80]!==Q||e[81]!==S||e[82]!==Re||e[83]!==k||e[84]!==T||e[85]!==j||e[86]!==ie||e[87]!==te||e[88]!==C||e[89]!==R||e[90]!==ae?(pe=u(Wn,{assistant:D,chart:m,className:Re,error:w,onFormat:V,onInferChart:B,onRun:Q,onShardKeyChange:I,onShowChart:j,onShowExplain:ie,onShowResults:te,onToggleSplit:ae,pane:R,result:S,running:k,shardKey:T,splitView:C}),e[75]=D,e[76]=w,e[77]=V,e[78]=B,e[79]=m,e[80]=Q,e[81]=S,e[82]=Re,e[83]=k,e[84]=T,e[85]=j,e[86]=ie,e[87]=te,e[88]=C,e[89]=R,e[90]=ae,e[91]=pe):pe=e[91];let be;e[92]!==he||e[93]!==pe||e[94]!==xe?(be=A("div",{className:xe,children:[he,pe]}),e[92]=he,e[93]=pe,e[94]=xe,e[95]=be):be=e[95];let ge;e[96]!==fe||e[97]!==be?(ge=A("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=A("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{wo 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-fz0m_4I4.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-zkEvTqy8.js";import{l as z,s as O}from"../packem_shared/browser-storage-xjTyMKY0.js";import{DataBrowser as R}from"../packem_shared/DataBrowser-H4oUFkPJ.js";import{GlobalDataBrowser as H}from"../packem_shared/GlobalDataBrowser-CeA8bDjX.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-fz0m_4I4.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-zkEvTqy8.js";import{l as z,s as O}from"../packem_shared/browser-storage-xjTyMKY0.js";import{DataBrowser as R}from"../packem_shared/DataBrowser-CPNKM0KZ.js";import{GlobalDataBrowser as H}from"../packem_shared/GlobalDataBrowser-BSmyOO0n.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--Ie7ofJ0.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-CnnyWJXM.js";import{useT as R}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as N}from"../packem_shared/ADMIN_FUNCTIONS-4aE59aDq.js";import{i as V}from"../packem_shared/internal-zkEvTqy8.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{U as S}from"../packem_shared/error-alert-_2q2VtVG.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,f as K}from"../packem_shared/card-BMKx5UdA.js";import{E as U}from"../packem_shared/empty-state-Cg7t_8qu.js";import{d as q,n as E,f as g,m as o,b as _,p as i}from"../packem_shared/table-DZAB8cs3.js";import{N as y}from"../packem_shared/use-admin-query-CnnyWJXM.js";import{useT as R}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as N}from"../packem_shared/ADMIN_FUNCTIONS-4aE59aDq.js";import{i as V}from"../packem_shared/internal-zkEvTqy8.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},l=(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}),B=p!==void 0,m=Array.isArray(p)&&p.some(r=>r.name===M),{data:A,error:D,errorSource:L,liveError:O}=y(N.readTablePage,Q,{enabled:m,live:!0,shardKey:s}),P={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,P,{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=>l(r,"key")===a);let u;return B&&!m?u=e(U,{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(U,{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(E,{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 d=l(r,"key")??"",c=l(r,"status"),h=z(r);return n(g,{"data-active":d===a?"":void 0,"data-testid":`agents-thread-${d}`,children:[e(i,{className:"font-mono text-xs",children:l(r,"agent")??"—"}),e(i,{className:"font-mono text-xs text-muted-foreground",children:d}),e(i,{children:e(C,{"data-testid":`agents-thread-status-${d}`,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-${d}`,onClick:()=>{w(d)},size:"sm",type:"button",variant:"outline",children:t("Timeline")})})]},d)})})]})})}),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(E,{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,d)=>{const c=l(r,"role")??"—",h=ee(r),H=l(r,"toolName"),x=l(r,"status"),v=b(r,"seq")??d;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:l(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})})]},l(r,"messageKey")??`${c}:${String(v)}`)})})]})]})})]}),n("div",{className:"flex flex-col gap-6","data-testid":"lunora-agents-panel",children:[D!==null&&e(S,{error:L,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.")}),O!==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 default};
@@ -1 +1 @@
1
- import{c as k}from"react/compiler-runtime";import{createAnalyticsSqlClient as C}from"@lunora/bindings/analytics";import{useState as L,useMemo as v,useCallback as O,useEffect as I}from"react";import{c as N}from"../packem_shared/card-CIDGUN6K.js";import{E as T}from"../packem_shared/empty-state-Cg7t_8qu.js";import{n as M,d as _,m as x,f as q,u as D,p as $}from"../packem_shared/table-DdJBrClo.js";import{useT as R}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{b as Y,f as w,h as B}from"../packem_shared/internal-zkEvTqy8.js";import{jsx as n,jsxs as E}from"react/jsx-runtime";const F="ANALYTICS",b=[{key:"volume",sql:a=>`SELECT blob2 AS fn, count() AS calls FROM ${a} WHERE blob1 = 'function_call' GROUP BY fn ORDER BY calls DESC LIMIT 25`,title:"Request volume per function"},{key:"latency",sql:a=>`SELECT blob2 AS fn, quantileWeighted(0.50)(double1, _sample_interval) AS p50, quantileWeighted(0.95)(double1, _sample_interval) AS p95 FROM ${a} WHERE blob1 = 'function_call' GROUP BY fn ORDER BY p95 DESC LIMIT 25`,title:"Latency p50 / p95 per function"},{key:"hotShards",sql:a=>`SELECT blob3 AS shard, count() AS calls FROM ${a} WHERE blob1 = 'function_call' GROUP BY shard ORDER BY calls DESC LIMIT 25`,title:"Hot shards"}],W={error:null,loading:!0,result:null},U=a=>{const e=k(27),{state:y,title:u}=a,c=R(),{error:r,loading:t,result:o}=y,l=`analytics-panel-${u}`;let s;e[0]!==c||e[1]!==u?(s=c(u),e[0]=c,e[1]=u,e[2]=s):s=e[2];let i;e[3]!==s?(i=n("header",{className:"border-b border-border px-4 py-3",children:n("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:s})}),e[3]=s,e[4]=i):i=e[4];let d;e[5]!==t||e[6]!==c?(d=t&&n("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground","data-testid":"analytics-loading",children:c("Loading…")}),e[5]=t,e[6]=c,e[7]=d):d=e[7];let m;e[8]!==r||e[9]!==t?(m=!t&&r!==null&&n("p",{className:"px-4 py-8 text-center text-sm text-destructive","data-testid":"analytics-error",role:"alert",children:r}),e[8]=r,e[9]=t,e[10]=m):m=e[10];let p;e[11]!==r||e[12]!==t||e[13]!==o||e[14]!==c?(p=!t&&r===null&&o!==null&&o.rows.length===0&&n("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground","data-testid":"analytics-empty-rows",children:c("No data points yet.")}),e[11]=r,e[12]=t,e[13]=o,e[14]=c,e[15]=p):p=e[15];let f;e[16]!==r||e[17]!==t||e[18]!==o?(f=!t&&r===null&&o!==null&&o.rows.length>0&&E(M,{children:[n(_,{children:n(x,{children:o.columns.map(H)})}),n(q,{children:o.rows.map((S,A)=>n(x,{children:o.columns.map(g=>n(D,{className:"font-mono text-xs",children:B(S[g.name])},g.name))},A))})]}),e[16]=r,e[17]=t,e[18]=o,e[19]=f):f=e[19];let h;return e[20]!==l||e[21]!==i||e[22]!==d||e[23]!==m||e[24]!==p||e[25]!==f?(h=E(N,{className:"gap-0 py-0","data-testid":l,children:[i,d,m,p,f]}),e[20]=l,e[21]=i,e[22]=d,e[23]=m,e[24]=p,e[25]=f,e[26]=h):h=e[26],h},Z=({config:a,dataset:e=F,runQuery:y}={})=>{const u=R(),[c,r]=L({}),t=v(()=>{if(y!==void 0)return y;if(a===void 0)return null;const l=C({accountId:a.accountId,apiToken:a.apiToken});return s=>l.query(s)},[a,y]),o=O(async l=>{if(t!==null)for(const s of b){if(l.cancelled)return;r(i=>({...i,[s.key]:{error:null,loading:!0,result:null}}));try{const i=await t(s.sql(e));l.cancelled||r(d=>({...d,[s.key]:{error:null,loading:!1,result:i}}))}catch(i){l.cancelled||r(d=>({...d,[s.key]:{error:Y(i),loading:!1,result:null}}))}}},[t,e]);return I(()=>{const l={cancelled:!1};return w(o(l)),()=>{l.cancelled=!0}},[o]),t===null?n(T,{description:u("Set CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_API_TOKEN (Analytics Read) in your .dev.vars to enable usage panels."),icon:n("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:n("path",{d:"M5 20V10m6.5 10V4M18 20v-7M3 20h18"})}),testId:"analytics-not-configured",title:u("Analytics is not configured.")}):n("div",{className:"flex flex-col gap-4","data-testid":"lunora-analytics-panel",children:b.map(l=>n(U,{state:c[l.key]??W,title:l.title},l.key))})};function H(a){return n($,{children:a.name},a.name)}export{Z as AnalyticsPanel};
1
+ import{c as k}from"react/compiler-runtime";import{createAnalyticsSqlClient as C}from"@lunora/bindings/analytics";import{useState as L,useMemo as v,useCallback as O,useEffect as I}from"react";import{c as N}from"../packem_shared/card-BMKx5UdA.js";import{E as T}from"../packem_shared/empty-state-Cg7t_8qu.js";import{d as M,n as _,f as x,b as q,p as D,m as Y}from"../packem_shared/table-DZAB8cs3.js";import{useT as R}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{b as $,f as w,h as B}from"../packem_shared/internal-zkEvTqy8.js";import{jsx as n,jsxs as E}from"react/jsx-runtime";const F="ANALYTICS",b=[{key:"volume",sql:a=>`SELECT blob2 AS fn, count() AS calls FROM ${a} WHERE blob1 = 'function_call' GROUP BY fn ORDER BY calls DESC LIMIT 25`,title:"Request volume per function"},{key:"latency",sql:a=>`SELECT blob2 AS fn, quantileWeighted(0.50)(double1, _sample_interval) AS p50, quantileWeighted(0.95)(double1, _sample_interval) AS p95 FROM ${a} WHERE blob1 = 'function_call' GROUP BY fn ORDER BY p95 DESC LIMIT 25`,title:"Latency p50 / p95 per function"},{key:"hotShards",sql:a=>`SELECT blob3 AS shard, count() AS calls FROM ${a} WHERE blob1 = 'function_call' GROUP BY shard ORDER BY calls DESC LIMIT 25`,title:"Hot shards"}],W={error:null,loading:!0,result:null},U=a=>{const e=k(27),{state:y,title:u}=a,c=R(),{error:r,loading:t,result:o}=y,l=`analytics-panel-${u}`;let s;e[0]!==c||e[1]!==u?(s=c(u),e[0]=c,e[1]=u,e[2]=s):s=e[2];let i;e[3]!==s?(i=n("header",{className:"border-b border-border px-4 py-3",children:n("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:s})}),e[3]=s,e[4]=i):i=e[4];let d;e[5]!==t||e[6]!==c?(d=t&&n("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground","data-testid":"analytics-loading",children:c("Loading…")}),e[5]=t,e[6]=c,e[7]=d):d=e[7];let m;e[8]!==r||e[9]!==t?(m=!t&&r!==null&&n("p",{className:"px-4 py-8 text-center text-sm text-destructive","data-testid":"analytics-error",role:"alert",children:r}),e[8]=r,e[9]=t,e[10]=m):m=e[10];let p;e[11]!==r||e[12]!==t||e[13]!==o||e[14]!==c?(p=!t&&r===null&&o!==null&&o.rows.length===0&&n("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground","data-testid":"analytics-empty-rows",children:c("No data points yet.")}),e[11]=r,e[12]=t,e[13]=o,e[14]=c,e[15]=p):p=e[15];let f;e[16]!==r||e[17]!==t||e[18]!==o?(f=!t&&r===null&&o!==null&&o.rows.length>0&&E(M,{children:[n(_,{children:n(x,{children:o.columns.map(H)})}),n(q,{children:o.rows.map((S,A)=>n(x,{children:o.columns.map(g=>n(D,{className:"font-mono text-xs",children:B(S[g.name])},g.name))},A))})]}),e[16]=r,e[17]=t,e[18]=o,e[19]=f):f=e[19];let h;return e[20]!==l||e[21]!==i||e[22]!==d||e[23]!==m||e[24]!==p||e[25]!==f?(h=E(N,{className:"gap-0 py-0","data-testid":l,children:[i,d,m,p,f]}),e[20]=l,e[21]=i,e[22]=d,e[23]=m,e[24]=p,e[25]=f,e[26]=h):h=e[26],h},Z=({config:a,dataset:e=F,runQuery:y}={})=>{const u=R(),[c,r]=L({}),t=v(()=>{if(y!==void 0)return y;if(a===void 0)return null;const l=C({accountId:a.accountId,apiToken:a.apiToken});return s=>l.query(s)},[a,y]),o=O(async l=>{if(t!==null)for(const s of b){if(l.cancelled)return;r(i=>({...i,[s.key]:{error:null,loading:!0,result:null}}));try{const i=await t(s.sql(e));l.cancelled||r(d=>({...d,[s.key]:{error:null,loading:!1,result:i}}))}catch(i){l.cancelled||r(d=>({...d,[s.key]:{error:$(i),loading:!1,result:null}}))}}},[t,e]);return I(()=>{const l={cancelled:!1};return w(o(l)),()=>{l.cancelled=!0}},[o]),t===null?n(T,{description:u("Set CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_API_TOKEN (Analytics Read) in your .dev.vars to enable usage panels."),icon:n("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:n("path",{d:"M5 20V10m6.5 10V4M18 20v-7M3 20h18"})}),testId:"analytics-not-configured",title:u("Analytics is not configured.")}):n("div",{className:"flex flex-col gap-4","data-testid":"lunora-analytics-panel",children:b.map(l=>n(U,{state:c[l.key]??W,title:l.title},l.key))})};function H(a){return n(Y,{children:a.name},a.name)}export{Z as AnalyticsPanel};
@@ -1 +1 @@
1
- import{c as P}from"react/compiler-runtime";import{useState as k}from"react";import{E as q}from"../packem_shared/error-alert--Ie7ofJ0.js";import{g as _}from"../packem_shared/badge-BbuuAio7.js";import{u as z}from"../packem_shared/button-BkCrNcAs.js";import{c as D,u as H}from"../packem_shared/card-CIDGUN6K.js";import{E as M}from"../packem_shared/empty-state-Cg7t_8qu.js";import{u as O}from"../packem_shared/input-JHu63lTv.js";import{n as R,d as U,m as T,p as w,f as W,u as $}from"../packem_shared/table-DdJBrClo.js";import{N as B}from"../packem_shared/use-admin-query-CnnyWJXM.js";import{useT as G}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as J}from"../packem_shared/ADMIN_FUNCTIONS-4aE59aDq.js";import{i as K}from"../packem_shared/internal-zkEvTqy8.js";import{jsx as r,jsxs as i}from"react/jsx-runtime";const ce=()=>{const e=P(39),t=G(),[l,j]=k("");let y;e[0]===Symbol.for("react.memo_cache_sentinel")?(y={},e[0]=y):y=e[0];const{data:b,error:s,errorSource:E,isLoading:S,refetch:A}=B(J.getAuthAuditLog,y);let C;if(e[1]!==b?.entries||e[2]!==l){const a=b?.entries??[],x=l.trim().toLowerCase();C=x===""?a:a.filter(N=>N.event.toLowerCase().includes(x)||(N.actorId??"").toLowerCase().includes(x)||(N.actorEmail??"").toLowerCase().includes(x)||(N.ip??"").toLowerCase().includes(x)||N.outcome.toLowerCase().includes(x)),e[1]=b?.entries,e[2]=l,e[3]=C}else C=e[3];const o=C;let I;e[4]===Symbol.for("react.memo_cache_sentinel")?(I=a=>{j(a.target.value)},e[4]=I):I=e[4];const F=I;let n;e[5]!==t?(n=t("Filter security events"),e[5]=t,e[6]=n):n=e[6];let c;e[7]!==t?(c=t("filter event, actor, IP"),e[7]=t,e[8]=c):c=e[8];let d;e[9]!==l||e[10]!==n||e[11]!==c?(d=r(O,{"aria-label":n,className:"h-8 w-56","data-testid":"aa-search",onChange:F,placeholder:c,value:l}),e[9]=l,e[10]=n,e[11]=c,e[12]=d):d=e[12];let m;e[13]!==A?(m=()=>{A()},e[13]=A,e[14]=m):m=e[14];let u;e[15]!==t?(u=t("Refresh"),e[15]=t,e[16]=u):u=e[16];let h;e[17]!==m||e[18]!==u?(h=r(z,{"data-testid":"aa-refresh",onClick:m,size:"xs",type:"button",variant:"ghost",children:u}),e[17]=m,e[18]=u,e[19]=h):h=e[19];let f;e[20]!==d||e[21]!==h?(f=i("div",{className:"flex flex-wrap items-center gap-2",children:[d,h]}),e[20]=d,e[21]=h,e[22]=f):f=e[22];let p;e[23]!==s||e[24]!==E?(p=s!==null&&r(q,{error:E,testId:"aa-error"}),e[23]=s,e[24]=E,e[25]=p):p=e[25];let g;e[26]!==s||e[27]!==o.length||e[28]!==S||e[29]!==t?(g=s===null&&!S&&o.length===0&&r(M,{description:t("Authentication and security events are recorded here."),testId:"aa-empty",title:t("No security events.")}),e[26]=s,e[27]=o.length,e[28]=S,e[29]=t,e[30]=g):g=e[30];let v;e[31]!==o||e[32]!==t?(v=o.length>0&&r(D,{className:"overflow-hidden py-0",children:r(H,{className:"max-h-[30rem] overflow-auto px-0",children:i(R,{"data-testid":"aa-table",children:[r(U,{children:i(T,{children:[r(w,{children:t("time")}),r(w,{children:t("event")}),r(w,{children:t("actor")}),r(w,{children:t("ip / user agent")}),r(w,{children:t("outcome")})]})}),r(W,{children:o.map(a=>i(T,{"data-testid":"aa-row",children:[r($,{className:"text-muted-foreground tabular-nums",children:K(a.ts,"—")}),r($,{children:r(_,{variant:"secondary",children:a.event})}),r($,{className:"max-w-[24ch] truncate font-mono text-xs",title:a.actorId??void 0,children:a.actorEmail??a.actorId??r("span",{className:"text-muted-foreground",children:"—"})}),i($,{className:"max-w-[28ch] truncate text-xs text-muted-foreground",title:a.userAgent??void 0,children:[a.ip??r("span",{className:"text-muted-foreground",children:"—"}),a.userAgent!==void 0&&i("span",{className:"ml-1 opacity-70",children:["· ",a.userAgent]})]}),r($,{children:r(_,{variant:a.outcome==="failure"?"destructive":"outline",children:t(a.outcome)})})]},a.seq))})]})})}),e[31]=o,e[32]=t,e[33]=v):v=e[33];let L;return e[34]!==p||e[35]!==g||e[36]!==v||e[37]!==f?(L=i("div",{className:"flex flex-col gap-4","data-testid":"lunora-auth-audit",children:[f,p,g,v]}),e[34]=p,e[35]=g,e[36]=v,e[37]=f,e[38]=L):L=e[38],L};export{ce as AuthAuditPanel};
1
+ import{c as U}from"react/compiler-runtime";import{useState as k}from"react";import{U as q}from"../packem_shared/error-alert-_2q2VtVG.js";import{g as T}from"../packem_shared/badge-BbuuAio7.js";import{u as z}from"../packem_shared/button-BkCrNcAs.js";import{c as D,f as H}from"../packem_shared/card-BMKx5UdA.js";import{E as M}from"../packem_shared/empty-state-Cg7t_8qu.js";import{u as O}from"../packem_shared/input-JHu63lTv.js";import{d as P,n as R,f as j,m as w,b as W,p as $}from"../packem_shared/table-DZAB8cs3.js";import{N as B}from"../packem_shared/use-admin-query-CnnyWJXM.js";import{useT as G}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as J}from"../packem_shared/ADMIN_FUNCTIONS-4aE59aDq.js";import{i as K}from"../packem_shared/internal-zkEvTqy8.js";import{jsx as r,jsxs as i}from"react/jsx-runtime";const ce=()=>{const e=U(39),t=G(),[l,A]=k("");let y;e[0]===Symbol.for("react.memo_cache_sentinel")?(y={},e[0]=y):y=e[0];const{data:b,error:s,errorSource:S,isLoading:E,refetch:_}=B(J.getAuthAuditLog,y);let C;if(e[1]!==b?.entries||e[2]!==l){const a=b?.entries??[],x=l.trim().toLowerCase();C=x===""?a:a.filter(N=>N.event.toLowerCase().includes(x)||(N.actorId??"").toLowerCase().includes(x)||(N.actorEmail??"").toLowerCase().includes(x)||(N.ip??"").toLowerCase().includes(x)||N.outcome.toLowerCase().includes(x)),e[1]=b?.entries,e[2]=l,e[3]=C}else C=e[3];const o=C;let I;e[4]===Symbol.for("react.memo_cache_sentinel")?(I=a=>{A(a.target.value)},e[4]=I):I=e[4];const F=I;let n;e[5]!==t?(n=t("Filter security events"),e[5]=t,e[6]=n):n=e[6];let c;e[7]!==t?(c=t("filter event, actor, IP"),e[7]=t,e[8]=c):c=e[8];let d;e[9]!==l||e[10]!==n||e[11]!==c?(d=r(O,{"aria-label":n,className:"h-8 w-56","data-testid":"aa-search",onChange:F,placeholder:c,value:l}),e[9]=l,e[10]=n,e[11]=c,e[12]=d):d=e[12];let m;e[13]!==_?(m=()=>{_()},e[13]=_,e[14]=m):m=e[14];let u;e[15]!==t?(u=t("Refresh"),e[15]=t,e[16]=u):u=e[16];let h;e[17]!==m||e[18]!==u?(h=r(z,{"data-testid":"aa-refresh",onClick:m,size:"xs",type:"button",variant:"ghost",children:u}),e[17]=m,e[18]=u,e[19]=h):h=e[19];let f;e[20]!==d||e[21]!==h?(f=i("div",{className:"flex flex-wrap items-center gap-2",children:[d,h]}),e[20]=d,e[21]=h,e[22]=f):f=e[22];let p;e[23]!==s||e[24]!==S?(p=s!==null&&r(q,{error:S,testId:"aa-error"}),e[23]=s,e[24]=S,e[25]=p):p=e[25];let g;e[26]!==s||e[27]!==o.length||e[28]!==E||e[29]!==t?(g=s===null&&!E&&o.length===0&&r(M,{description:t("Authentication and security events are recorded here."),testId:"aa-empty",title:t("No security events.")}),e[26]=s,e[27]=o.length,e[28]=E,e[29]=t,e[30]=g):g=e[30];let v;e[31]!==o||e[32]!==t?(v=o.length>0&&r(D,{className:"overflow-hidden py-0",children:r(H,{className:"max-h-[30rem] overflow-auto px-0",children:i(P,{"data-testid":"aa-table",children:[r(R,{children:i(j,{children:[r(w,{children:t("time")}),r(w,{children:t("event")}),r(w,{children:t("actor")}),r(w,{children:t("ip / user agent")}),r(w,{children:t("outcome")})]})}),r(W,{children:o.map(a=>i(j,{"data-testid":"aa-row",children:[r($,{className:"text-muted-foreground tabular-nums",children:K(a.ts,"—")}),r($,{children:r(T,{variant:"secondary",children:a.event})}),r($,{className:"max-w-[24ch] truncate font-mono text-xs",title:a.actorId??void 0,children:a.actorEmail??a.actorId??r("span",{className:"text-muted-foreground",children:"—"})}),i($,{className:"max-w-[28ch] truncate text-xs text-muted-foreground",title:a.userAgent??void 0,children:[a.ip??r("span",{className:"text-muted-foreground",children:"—"}),a.userAgent!==void 0&&i("span",{className:"ml-1 opacity-70",children:["· ",a.userAgent]})]}),r($,{children:r(T,{variant:a.outcome==="failure"?"destructive":"outline",children:t(a.outcome)})})]},a.seq))})]})})}),e[31]=o,e[32]=t,e[33]=v):v=e[33];let L;return e[34]!==p||e[35]!==g||e[36]!==v||e[37]!==f?(L=i("div",{className:"flex flex-col gap-4","data-testid":"lunora-auth-audit",children:[f,p,g,v]}),e[34]=p,e[35]=g,e[36]=v,e[37]=f,e[38]=L):L=e[38],L};export{ce as default};
@@ -1 +1 @@
1
- import{c as N}from"react/compiler-runtime";import{useLunora as $}from"@lunora/react";import{g as x}from"../packem_shared/badge-BbuuAio7.js";import{c as w,u as I}from"../packem_shared/card-CIDGUN6K.js";import{O as S}from"../packem_shared/use-admin-query-CnnyWJXM.js";import{useT as A}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{jsx as t,jsxs as o,Fragment as y}from"react/jsx-runtime";const j=[{key:"accounts",label:"Accounts"},{key:"admin",label:"Admin"},{key:"organization",label:"Organizations"},{key:"passkey",label:"Passkeys"},{key:"twoFactor",label:"Two-factor"}],v=e=>{if(e===void 0)return"—";const i=[[86400,"d"],[3600,"h"],[60,"m"]];for(const[a,d]of i)if(e>=a&&e%a===0)return`${String(e/a)}${d}`;return`${String(e)}s`},h=e=>{const i=N(8),{children:a,heading:d,testId:s}=e;let l;i[0]!==d?(l=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:d})}),i[0]=d,i[1]=l):l=i[1];let n;i[2]!==a?(n=t(I,{className:"p-3",children:a}),i[2]=a,i[3]=n):n=i[3];let u;return i[4]!==l||i[5]!==n||i[6]!==s?(u=o(w,{className:"gap-0 py-0","data-testid":s,children:[l,n]}),i[4]=l,i[5]=n,i[6]=s,i[7]=u):u=i[7],u},c=e=>{const i=N(7),{label:a,value:d}=e;let s;i[0]!==a?(s=t("span",{className:"text-sm",children:a}),i[0]=a,i[1]=s):s=i[1];let l;i[2]!==d?(l=t("span",{className:"text-sm text-muted-foreground tabular-nums",children:d}),i[2]=d,i[3]=l):l=i[3];let n;return i[4]!==s||i[5]!==l?(n=o("div",{className:"flex items-center justify-between gap-2 rounded-xl border border-border bg-card p-2 shadow-xs",children:[s,l]}),i[4]=s,i[5]=l,i[6]=n):n=i[6],n},M=()=>{const e=N(20),i=$(),a=A();let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d=["lunora-auth-config"],e[0]=d):d=e[0];let s;e[1]!==i?(s=()=>i.getAuthConfig(),e[1]=i,e[2]=s):s=e[2];const{data:l,error:n}=S(d,s);let u;e[3]!==a?(u=r=>t(x,{variant:r?"success":"outline",children:a(r?"Enabled":"Disabled")}),e[3]=a,e[4]=u):u=e[4];const m=u;let g;e[5]!==n?(g=n!==null&&t("p",{className:"px-4 py-8 text-center text-sm text-destructive","data-testid":"auth-config-error",role:"alert",children:n}),e[5]=n,e[6]=g):g=e[6];let p;e[7]!==l||e[8]!==n||e[9]!==a?(p=n===null&&l===void 0&&t("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground","data-testid":"auth-config-loading",children:a("Loading auth configuration…")}),e[7]=l,e[8]=n,e[9]=a,e[10]=p):p=e[10];let f;e[11]!==l||e[12]!==n||e[13]!==m||e[14]!==a?(f=n===null&&l!==void 0&&o(y,{children:[t(h,{heading:a("Enabled capabilities"),testId:"auth-config-capabilities",children:t("ul",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2",children:j.map(r=>{const k=l.capabilities[r.key];return o("li",{className:"flex items-center justify-between gap-2 rounded-xl border border-border bg-card p-2 shadow-xs","data-testid":`auth-config-cap-${r.key}`,children:[t("span",{className:"text-sm",children:a(r.label)}),m(k)]},r.key)})})}),t(h,{heading:a("Plugins"),testId:"auth-config-plugins",children:l.plugins.length===0?t("p",{className:"text-sm text-muted-foreground",children:a("No plugins enabled.")}):t("div",{className:"flex flex-wrap gap-2",children:l.plugins.map(P)})}),t(h,{heading:a("Sign-in methods"),testId:"auth-config-signin",children:o("div",{className:"flex flex-col gap-2",children:[t(c,{label:a("Email & password"),value:m(l.emailAndPassword)}),t(c,{label:a("Social providers"),value:l.socialProviders.length===0?a("None"):t("span",{className:"flex flex-wrap justify-end gap-1",children:l.socialProviders.map(z)})})]})}),l.organization.enabled&&t(h,{heading:a("Organizations"),testId:"auth-config-org",children:o("div",{className:"flex flex-col gap-2",children:[t(c,{label:a("Teams"),value:m(l.organization.teams)}),t(c,{label:a("Custom roles"),value:m(l.organization.roles)})]})}),t(h,{heading:a("Session policy"),testId:"auth-config-session",children:o("div",{className:"flex flex-col gap-2",children:[t(c,{label:a("Expires in"),value:v(l.session.expiresIn)}),t(c,{label:a("Refresh after"),value:v(l.session.updateAge)}),t(c,{label:a("Fresh window"),value:v(l.session.freshAge)}),t(c,{label:a("Cookie cache"),value:m(l.session.cookieCache===!0)})]})}),t(h,{heading:a("Rate limit"),testId:"auth-config-ratelimit",children:o("div",{className:"flex flex-col gap-2",children:[t(c,{label:a("Status"),value:m(l.rateLimit.enabled)}),l.rateLimit.enabled&&o(y,{children:[t(c,{label:a("Max requests"),value:l.rateLimit.max??"—"}),t(c,{label:a("Window"),value:v(l.rateLimit.window)})]})]})}),l.userFields.length>0&&t(h,{heading:a("Plugin user fields"),testId:"auth-config-user-fields",children:t("ul",{className:"flex flex-col gap-2",children:l.userFields.map(r=>o("li",{className:"flex items-center justify-between gap-2 rounded-xl border border-border bg-card p-2 shadow-xs","data-testid":`auth-config-user-field-${r.name}`,children:[o("span",{className:"flex flex-col",children:[t("span",{className:"font-mono text-xs",children:r.name}),r.plugin!==void 0&&t("span",{className:"text-[11px] text-muted-foreground",children:r.plugin})]}),o("span",{className:"flex items-center gap-1",children:[t(x,{variant:"outline",children:r.type}),r.required&&t(x,{variant:"secondary",children:a("required")}),r.unique&&t(x,{variant:"secondary",children:a("unique")})]})]},r.name))})}),t(w,{className:"gap-0 py-0",children:t("p",{className:"px-4 py-3 text-xs text-muted-foreground","data-testid":"auth-config-note",children:a("OAuth providers, email templates, and rate limits are configured at deploy time in the better-auth setup and aren't editable here. See the Mail tab for email output.")})})]}),e[11]=l,e[12]=n,e[13]=m,e[14]=a,e[15]=f):f=e[15];let b;return e[16]!==g||e[17]!==p||e[18]!==f?(b=o("div",{className:"flex flex-col gap-4","data-testid":"auth-config",children:[g,p,f]}),e[16]=g,e[17]=p,e[18]=f,e[19]=b):b=e[19],b};function P(e){return t(x,{"data-testid":`auth-config-plugin-${e}`,variant:"outline",children:e},e)}function z(e){return t(x,{"data-testid":`auth-config-provider-${e}`,variant:"outline",children:e},e)}export{M as AuthConfigPanel};
1
+ import{c as N}from"react/compiler-runtime";import{useLunora as $}from"@lunora/react";import{g as x}from"../packem_shared/badge-BbuuAio7.js";import{c as w,f as I}from"../packem_shared/card-BMKx5UdA.js";import{O as S}from"../packem_shared/use-admin-query-CnnyWJXM.js";import{useT as j}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{jsx as t,jsxs as o,Fragment as y}from"react/jsx-runtime";const A=[{key:"accounts",label:"Accounts"},{key:"admin",label:"Admin"},{key:"organization",label:"Organizations"},{key:"passkey",label:"Passkeys"},{key:"twoFactor",label:"Two-factor"}],v=e=>{if(e===void 0)return"—";const i=[[86400,"d"],[3600,"h"],[60,"m"]];for(const[a,d]of i)if(e>=a&&e%a===0)return`${String(e/a)}${d}`;return`${String(e)}s`},h=e=>{const i=N(8),{children:a,heading:d,testId:s}=e;let l;i[0]!==d?(l=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:d})}),i[0]=d,i[1]=l):l=i[1];let n;i[2]!==a?(n=t(I,{className:"p-3",children:a}),i[2]=a,i[3]=n):n=i[3];let u;return i[4]!==l||i[5]!==n||i[6]!==s?(u=o(w,{className:"gap-0 py-0","data-testid":s,children:[l,n]}),i[4]=l,i[5]=n,i[6]=s,i[7]=u):u=i[7],u},c=e=>{const i=N(7),{label:a,value:d}=e;let s;i[0]!==a?(s=t("span",{className:"text-sm",children:a}),i[0]=a,i[1]=s):s=i[1];let l;i[2]!==d?(l=t("span",{className:"text-sm text-muted-foreground tabular-nums",children:d}),i[2]=d,i[3]=l):l=i[3];let n;return i[4]!==s||i[5]!==l?(n=o("div",{className:"flex items-center justify-between gap-2 rounded-xl border border-border bg-card p-2 shadow-xs",children:[s,l]}),i[4]=s,i[5]=l,i[6]=n):n=i[6],n},M=()=>{const e=N(20),i=$(),a=j();let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d=["lunora-auth-config"],e[0]=d):d=e[0];let s;e[1]!==i?(s=()=>i.getAuthConfig(),e[1]=i,e[2]=s):s=e[2];const{data:l,error:n}=S(d,s);let u;e[3]!==a?(u=r=>t(x,{variant:r?"success":"outline",children:a(r?"Enabled":"Disabled")}),e[3]=a,e[4]=u):u=e[4];const m=u;let g;e[5]!==n?(g=n!==null&&t("p",{className:"px-4 py-8 text-center text-sm text-destructive","data-testid":"auth-config-error",role:"alert",children:n}),e[5]=n,e[6]=g):g=e[6];let p;e[7]!==l||e[8]!==n||e[9]!==a?(p=n===null&&l===void 0&&t("p",{className:"px-4 py-8 text-center text-sm text-muted-foreground","data-testid":"auth-config-loading",children:a("Loading auth configuration…")}),e[7]=l,e[8]=n,e[9]=a,e[10]=p):p=e[10];let f;e[11]!==l||e[12]!==n||e[13]!==m||e[14]!==a?(f=n===null&&l!==void 0&&o(y,{children:[t(h,{heading:a("Enabled capabilities"),testId:"auth-config-capabilities",children:t("ul",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2",children:A.map(r=>{const k=l.capabilities[r.key];return o("li",{className:"flex items-center justify-between gap-2 rounded-xl border border-border bg-card p-2 shadow-xs","data-testid":`auth-config-cap-${r.key}`,children:[t("span",{className:"text-sm",children:a(r.label)}),m(k)]},r.key)})})}),t(h,{heading:a("Plugins"),testId:"auth-config-plugins",children:l.plugins.length===0?t("p",{className:"text-sm text-muted-foreground",children:a("No plugins enabled.")}):t("div",{className:"flex flex-wrap gap-2",children:l.plugins.map(P)})}),t(h,{heading:a("Sign-in methods"),testId:"auth-config-signin",children:o("div",{className:"flex flex-col gap-2",children:[t(c,{label:a("Email & password"),value:m(l.emailAndPassword)}),t(c,{label:a("Social providers"),value:l.socialProviders.length===0?a("None"):t("span",{className:"flex flex-wrap justify-end gap-1",children:l.socialProviders.map(z)})})]})}),l.organization.enabled&&t(h,{heading:a("Organizations"),testId:"auth-config-org",children:o("div",{className:"flex flex-col gap-2",children:[t(c,{label:a("Teams"),value:m(l.organization.teams)}),t(c,{label:a("Custom roles"),value:m(l.organization.roles)})]})}),t(h,{heading:a("Session policy"),testId:"auth-config-session",children:o("div",{className:"flex flex-col gap-2",children:[t(c,{label:a("Expires in"),value:v(l.session.expiresIn)}),t(c,{label:a("Refresh after"),value:v(l.session.updateAge)}),t(c,{label:a("Fresh window"),value:v(l.session.freshAge)}),t(c,{label:a("Cookie cache"),value:m(l.session.cookieCache===!0)})]})}),t(h,{heading:a("Rate limit"),testId:"auth-config-ratelimit",children:o("div",{className:"flex flex-col gap-2",children:[t(c,{label:a("Status"),value:m(l.rateLimit.enabled)}),l.rateLimit.enabled&&o(y,{children:[t(c,{label:a("Max requests"),value:l.rateLimit.max??"—"}),t(c,{label:a("Window"),value:v(l.rateLimit.window)})]})]})}),l.userFields.length>0&&t(h,{heading:a("Plugin user fields"),testId:"auth-config-user-fields",children:t("ul",{className:"flex flex-col gap-2",children:l.userFields.map(r=>o("li",{className:"flex items-center justify-between gap-2 rounded-xl border border-border bg-card p-2 shadow-xs","data-testid":`auth-config-user-field-${r.name}`,children:[o("span",{className:"flex flex-col",children:[t("span",{className:"font-mono text-xs",children:r.name}),r.plugin!==void 0&&t("span",{className:"text-[11px] text-muted-foreground",children:r.plugin})]}),o("span",{className:"flex items-center gap-1",children:[t(x,{variant:"outline",children:r.type}),r.required&&t(x,{variant:"secondary",children:a("required")}),r.unique&&t(x,{variant:"secondary",children:a("unique")})]})]},r.name))})}),t(w,{className:"gap-0 py-0",children:t("p",{className:"px-4 py-3 text-xs text-muted-foreground","data-testid":"auth-config-note",children:a("OAuth providers, email templates, and rate limits are configured at deploy time in the better-auth setup and aren't editable here. See the Mail tab for email output.")})})]}),e[11]=l,e[12]=n,e[13]=m,e[14]=a,e[15]=f):f=e[15];let b;return e[16]!==g||e[17]!==p||e[18]!==f?(b=o("div",{className:"flex flex-col gap-4","data-testid":"auth-config",children:[g,p,f]}),e[16]=g,e[17]=p,e[18]=f,e[19]=b):b=e[19],b};function P(e){return t(x,{"data-testid":`auth-config-plugin-${e}`,variant:"outline",children:e},e)}function z(e){return t(x,{"data-testid":`auth-config-provider-${e}`,variant:"outline",children:e},e)}export{M as default};
@@ -1 +1 @@
1
- import{c as y}from"react/compiler-runtime";import{useLunora as b}from"@lunora/react";import{u as S}from"../packem_shared/button-BkCrNcAs.js";import{c as k,u as w}from"../packem_shared/card-CIDGUN6K.js";import{E as I}from"../packem_shared/empty-state-Cg7t_8qu.js";import{n as j,d as E,m as g,p as c,f as R,u as m}from"../packem_shared/table-DdJBrClo.js";import{O as T}from"../packem_shared/use-admin-query-CnnyWJXM.js";import{useAutoRefresh as _}from"../packem_shared/DEFAULT_AUTO_REFRESH_MS-BCC8_4BQ.js";import{useT as z}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{i as B,f as C}from"../packem_shared/internal-zkEvTqy8.js";import{jsx as s,jsxs as A}from"react/jsx-runtime";const v=200,Q=()=>{const e=y(21),a=b(),t=z();let h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h=["lunora-auth-sessions",v],e[0]=h):h=e[0];let u;e[1]!==a?(u=()=>a.listAuthSessions({limit:v}),e[1]=a,e[2]=u):u=e[2];const o=T(h,u),{error:p}=o,r=o.data?.rows??null;let f;e[3]!==o?(f=()=>{o.refetch()},e[3]=o,e[4]=f):f=e[4],_(f,!0);let x;e[5]!==a||e[6]!==o?(x=i=>{C((async()=>{await a.revokeAuthSession({sessionId:i}),o.refetch()})())},e[5]=a,e[6]=o,e[7]=x):x=e[7];const N=x;let n;e[8]!==p?(n=p!==null&&s("p",{className:"text-sm text-destructive","data-testid":"auth-sessions-error",role:"alert",children:p}),e[8]=p,e[9]=n):n=e[9];let l;e[10]!==r||e[11]!==t?(l=r!==null&&r.length===0&&s(I,{testId:"auth-sessions-empty",title:t("No active sessions.")}),e[10]=r,e[11]=t,e[12]=l):l=e[12];let d;e[13]!==N||e[14]!==r||e[15]!==t?(d=r!==null&&r.length>0&&s(k,{className:"overflow-hidden py-0",children:s(w,{className:"px-0",children:A(j,{"data-testid":"auth-sessions-table",children:[s(E,{children:A(g,{children:[s(c,{children:t("user")}),s(c,{children:t("expires")}),s(c,{children:t("ip")}),s(c,{children:t("user agent")}),s(c,{children:t("impersonated by")}),s(c,{"aria-label":t("Actions")})]})}),s(R,{children:r.map(i=>A(g,{"data-testid":`auth-session-${i.id}`,children:[s(m,{className:"font-mono text-xs",children:i.userId}),s(m,{className:"text-muted-foreground tabular-nums",children:B(i.expiresAt)}),s(m,{children:i.ipAddress??""}),s(m,{className:"max-w-40 truncate",children:i.userAgent??""}),s(m,{className:"font-mono text-xs",children:i.impersonatedBy??""}),s(m,{children:s(S,{"data-testid":`auth-session-revoke-${i.id}`,onClick:()=>{N(i.id)},size:"xs",type:"button",variant:"ghost",children:t("Revoke")})})]},i.id))})]})})}),e[13]=N,e[14]=r,e[15]=t,e[16]=d):d=e[16];let $;return e[17]!==n||e[18]!==l||e[19]!==d?($=A("div",{className:"flex flex-col gap-4","data-testid":"auth-sessions",children:[n,l,d]}),e[17]=n,e[18]=l,e[19]=d,e[20]=$):$=e[20],$};export{Q as AuthSessionsPanel};
1
+ import{c as v}from"react/compiler-runtime";import{useLunora as y}from"@lunora/react";import{u as k}from"../packem_shared/button-BkCrNcAs.js";import{c as w,f as S}from"../packem_shared/card-BMKx5UdA.js";import{E as I}from"../packem_shared/empty-state-Cg7t_8qu.js";import{d as j,n as E,f as b,m as c,b as L,p as m}from"../packem_shared/table-DZAB8cs3.js";import{O as R}from"../packem_shared/use-admin-query-CnnyWJXM.js";import{useAutoRefresh as T}from"../packem_shared/DEFAULT_AUTO_REFRESH_MS-BCC8_4BQ.js";import{useT as _}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{i as z,f as B}from"../packem_shared/internal-zkEvTqy8.js";import{jsx as t,jsxs as N}from"react/jsx-runtime";const g=200,Q=()=>{const e=v(21),o=y(),s=_();let h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h=["lunora-auth-sessions",g],e[0]=h):h=e[0];let u;e[1]!==o?(u=()=>o.listAuthSessions({limit:g}),e[1]=o,e[2]=u):u=e[2];const a=R(h,u),{error:f}=a,r=a.data?.rows??null;let p;e[3]!==a?(p=()=>{a.refetch()},e[3]=a,e[4]=p):p=e[4],T(p,!0);let x;e[5]!==o||e[6]!==a?(x=i=>{B((async()=>{await o.revokeAuthSession({sessionId:i}),a.refetch()})())},e[5]=o,e[6]=a,e[7]=x):x=e[7];const A=x;let n;e[8]!==f?(n=f!==null&&t("p",{className:"text-sm text-destructive","data-testid":"auth-sessions-error",role:"alert",children:f}),e[8]=f,e[9]=n):n=e[9];let l;e[10]!==r||e[11]!==s?(l=r!==null&&r.length===0&&t(I,{testId:"auth-sessions-empty",title:s("No active sessions.")}),e[10]=r,e[11]=s,e[12]=l):l=e[12];let d;e[13]!==A||e[14]!==r||e[15]!==s?(d=r!==null&&r.length>0&&t(w,{className:"overflow-hidden py-0",children:t(S,{className:"px-0",children:N(j,{"data-testid":"auth-sessions-table",children:[t(E,{children:N(b,{children:[t(c,{children:s("user")}),t(c,{children:s("expires")}),t(c,{children:s("ip")}),t(c,{children:s("user agent")}),t(c,{children:s("impersonated by")}),t(c,{"aria-label":s("Actions")})]})}),t(L,{children:r.map(i=>N(b,{"data-testid":`auth-session-${i.id}`,children:[t(m,{className:"font-mono text-xs",children:i.userId}),t(m,{className:"text-muted-foreground tabular-nums",children:z(i.expiresAt)}),t(m,{children:i.ipAddress??""}),t(m,{className:"max-w-40 truncate",children:i.userAgent??""}),t(m,{className:"font-mono text-xs",children:i.impersonatedBy??""}),t(m,{children:t(k,{"data-testid":`auth-session-revoke-${i.id}`,onClick:()=>{A(i.id)},size:"xs",type:"button",variant:"ghost",children:s("Revoke")})})]},i.id))})]})})}),e[13]=A,e[14]=r,e[15]=s,e[16]=d):d=e[16];let $;return e[17]!==n||e[18]!==l||e[19]!==d?($=N("div",{className:"flex flex-col gap-4","data-testid":"auth-sessions",children:[n,l,d]}),e[17]=n,e[18]=l,e[19]=d,e[20]=$):$=e[20],$};export{Q as default};
@@ -1 +1 @@
1
- import{c as $}from"react/compiler-runtime";import{L as w}from"../packem_shared/live-status-CmuRLFKf.js";import{g as C}from"../packem_shared/badge-BbuuAio7.js";import{c as S,u as b}from"../packem_shared/card-CIDGUN6K.js";import{E}from"../packem_shared/empty-state-Cg7t_8qu.js";import{n as I,d as L,m as y,p as l,f as D,u as m}from"../packem_shared/table-DdJBrClo.js";import{N as k}from"../packem_shared/use-admin-query-CnnyWJXM.js";import{useT as A}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as O}from"../packem_shared/ADMIN_FUNCTIONS-4aE59aDq.js";import{jsx as n,jsxs as h}from"react/jsx-runtime";const N="container:",T={error:"error",sleep:"sleeping",start:"running",stop:"stopped"},_=e=>{const t=e.indexOf(":");if(t===-1)return{event:e.trim()};const r=e.slice(t+1).trim(),a=e.slice(0,t).trim();return r===""?{event:a}:{detail:r,event:a}},j=e=>{const t=new Map;for(const r of e){const a=r.functionPath??"";if(!a.startsWith(N))continue;const i=a.slice(N.length);if(i==="")continue;const s=JSON.stringify([i,r.instance??""]),o=t.get(s);if(o!==void 0&&o.timestamp>=r.timestamp)continue;const{detail:p,event:c}=_(r.message);t.set(s,{detail:p,event:c,exitCode:r.exitCode,instance:r.instance,level:r.level,name:i,state:T[c]??"unknown",timestamp:r.timestamp})}return[...t.values()].toSorted((r,a)=>r.name.localeCompare(a.name)||(r.instance??"").localeCompare(a.instance??""))},M={error:"destructive",running:"success",sleeping:"info",stopped:"outline",unknown:"secondary"},P=e=>{const{entries:t}=e??{};return Array.isArray(t)?t:[]},H=()=>{const e=$(19),t=A();let r,a;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={},a={live:!0,shardKey:""},e[0]=r,e[1]=a):(r=e[0],a=e[1]);const{data:i,error:s,liveError:o}=k(O.getLogs,r,a),p=i!==void 0;let c;if(e[2]!==i||e[3]!==s||e[4]!==o||e[5]!==p||e[6]!==t){const g=j(P(i));let x;e[8]!==s?(x=s!==null&&n("p",{className:"text-sm text-destructive","data-testid":"containers-error",role:"alert",children:s}),e[8]=s,e[9]=x):x=e[9];let d;e[10]!==t?(d=t("Cloudflare Containers are observed from their lifecycle log stream. This shows the current state per instance — ports and health checks aren't carried in that stream."),e[10]=t,e[11]=d):d=e[11];let u;e[12]!==d?(u=n("p",{className:"text-sm text-muted-foreground",children:d}),e[12]=d,e[13]=u):u=e[13];let f;e[14]!==o?(f=n(w,{message:o,prefix:"containers"}),e[14]=o,e[15]=f):f=e[15];let v;e[16]!==u||e[17]!==f?(v=h("div",{className:"flex flex-wrap items-center gap-2",children:[u,f]}),e[16]=u,e[17]=f,e[18]=v):v=e[18],c=h("div",{className:"flex flex-col gap-6","data-testid":"lunora-containers-panel",children:[x,v,p&&g.length===0?n(E,{description:t("No container lifecycle activity yet. Instances declared with defineContainer show up here once they start, sleep, stop, or error."),testId:"containers-empty",title:t("No container activity")}):n(S,{className:"overflow-hidden py-0",children:n(b,{className:"px-0",children:h(I,{"data-testid":"containers-table",children:[n(L,{children:h(y,{children:[n(l,{children:t("Container")}),n(l,{children:t("Instance")}),n(l,{children:t("State")}),n(l,{children:t("Last event")}),n(l,{children:t("Detail")}),n(l,{children:t("Exit")}),n(l,{children:t("When")})]})}),n(D,{children:g.map(W)})]})})})]}),e[2]=i,e[3]=s,e[4]=o,e[5]=p,e[6]=t,e[7]=c}else c=e[7];return c};function W(e){return h(y,{"data-testid":`containers-row-${e.name}${e.instance===void 0?"":`-${e.instance}`}`,children:[n(m,{className:"font-mono text-xs",children:e.name}),n(m,{className:"max-w-40 truncate font-mono text-xs text-muted-foreground",title:e.instance,children:e.instance??"—"}),n(m,{children:n(C,{variant:M[e.state],children:e.state})}),n(m,{className:"font-mono text-xs text-muted-foreground",children:e.event}),n(m,{className:"max-w-64 truncate text-xs text-muted-foreground",title:e.detail,children:e.detail??"—"}),n(m,{className:"font-mono text-xs tabular-nums text-muted-foreground",children:e.exitCode??"—"}),n(m,{className:"text-xs tabular-nums text-muted-foreground",children:new Date(e.timestamp).toLocaleString()})]},`${e.name}/${e.instance??""}`)}export{H as ContainersPanel};
1
+ import{c as $}from"react/compiler-runtime";import{L as w}from"../packem_shared/live-status-CmuRLFKf.js";import{g as C}from"../packem_shared/badge-BbuuAio7.js";import{c as S,f as b}from"../packem_shared/card-BMKx5UdA.js";import{E}from"../packem_shared/empty-state-Cg7t_8qu.js";import{d as I,n as L,f as y,m as l,b as D,p as m}from"../packem_shared/table-DZAB8cs3.js";import{N as k}from"../packem_shared/use-admin-query-CnnyWJXM.js";import{useT as A}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as O}from"../packem_shared/ADMIN_FUNCTIONS-4aE59aDq.js";import{jsx as n,jsxs as u}from"react/jsx-runtime";const N="container:",T={error:"error",sleep:"sleeping",start:"running",stop:"stopped"},_=e=>{const t=e.indexOf(":");if(t===-1)return{event:e.trim()};const r=e.slice(t+1).trim(),a=e.slice(0,t).trim();return r===""?{event:a}:{detail:r,event:a}},j=e=>{const t=new Map;for(const r of e){const a=r.functionPath??"";if(!a.startsWith(N))continue;const i=a.slice(N.length);if(i==="")continue;const s=JSON.stringify([i,r.instance??""]),o=t.get(s);if(o!==void 0&&o.timestamp>=r.timestamp)continue;const{detail:h,event:c}=_(r.message);t.set(s,{detail:h,event:c,exitCode:r.exitCode,instance:r.instance,level:r.level,name:i,state:T[c]??"unknown",timestamp:r.timestamp})}return[...t.values()].toSorted((r,a)=>r.name.localeCompare(a.name)||(r.instance??"").localeCompare(a.instance??""))},M={error:"destructive",running:"success",sleeping:"info",stopped:"outline",unknown:"secondary"},W=e=>{const{entries:t}=e??{};return Array.isArray(t)?t:[]},H=()=>{const e=$(19),t=A();let r,a;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={},a={live:!0,shardKey:""},e[0]=r,e[1]=a):(r=e[0],a=e[1]);const{data:i,error:s,liveError:o}=k(O.getLogs,r,a),h=i!==void 0;let c;if(e[2]!==i||e[3]!==s||e[4]!==o||e[5]!==h||e[6]!==t){const g=j(W(i));let x;e[8]!==s?(x=s!==null&&n("p",{className:"text-sm text-destructive","data-testid":"containers-error",role:"alert",children:s}),e[8]=s,e[9]=x):x=e[9];let d;e[10]!==t?(d=t("Cloudflare Containers are observed from their lifecycle log stream. This shows the current state per instance — ports and health checks aren't carried in that stream."),e[10]=t,e[11]=d):d=e[11];let f;e[12]!==d?(f=n("p",{className:"text-sm text-muted-foreground",children:d}),e[12]=d,e[13]=f):f=e[13];let p;e[14]!==o?(p=n(w,{message:o,prefix:"containers"}),e[14]=o,e[15]=p):p=e[15];let v;e[16]!==f||e[17]!==p?(v=u("div",{className:"flex flex-wrap items-center gap-2",children:[f,p]}),e[16]=f,e[17]=p,e[18]=v):v=e[18],c=u("div",{className:"flex flex-col gap-6","data-testid":"lunora-containers-panel",children:[x,v,h&&g.length===0?n(E,{description:t("No container lifecycle activity yet. Instances declared with defineContainer show up here once they start, sleep, stop, or error."),testId:"containers-empty",title:t("No container activity")}):n(S,{className:"overflow-hidden py-0",children:n(b,{className:"px-0",children:u(I,{"data-testid":"containers-table",children:[n(L,{children:u(y,{children:[n(l,{children:t("Container")}),n(l,{children:t("Instance")}),n(l,{children:t("State")}),n(l,{children:t("Last event")}),n(l,{children:t("Detail")}),n(l,{children:t("Exit")}),n(l,{children:t("When")})]})}),n(D,{children:g.map(B)})]})})})]}),e[2]=i,e[3]=s,e[4]=o,e[5]=h,e[6]=t,e[7]=c}else c=e[7];return c};function B(e){return u(y,{"data-testid":`containers-row-${e.name}${e.instance===void 0?"":`-${e.instance}`}`,children:[n(m,{className:"font-mono text-xs",children:e.name}),n(m,{className:"max-w-40 truncate font-mono text-xs text-muted-foreground",title:e.instance,children:e.instance??"—"}),n(m,{children:n(C,{variant:M[e.state],children:e.state})}),n(m,{className:"font-mono text-xs text-muted-foreground",children:e.event}),n(m,{className:"max-w-64 truncate text-xs text-muted-foreground",title:e.detail,children:e.detail??"—"}),n(m,{className:"font-mono text-xs tabular-nums text-muted-foreground",children:e.exitCode??"—"}),n(m,{className:"text-xs tabular-nums text-muted-foreground",children:new Date(e.timestamp).toLocaleString()})]},`${e.name}/${e.instance??""}`)}export{H as default};