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

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 (235) hide show
  1. package/dist/index.d.ts +28 -14
  2. package/dist/index.js +1 -1
  3. package/dist/mount.d.ts +1 -1
  4. package/dist/mount.js +1 -1
  5. package/dist/packem_chunks/ApiTab.js +1 -1
  6. package/dist/packem_chunks/AuditPanel.js +1 -1
  7. package/dist/packem_chunks/DeploymentHealthPanel.js +1 -1
  8. package/dist/packem_chunks/ExportImportPanel.js +3 -3
  9. package/dist/packem_chunks/FileBrowser.js +4 -4
  10. package/dist/packem_chunks/FunctionRunner.js +1 -1
  11. package/dist/packem_chunks/FunctionStatsPanel.js +1 -1
  12. package/dist/packem_chunks/HealthPanel.js +1 -1
  13. package/dist/packem_chunks/InsightsPanel.js +1 -1
  14. package/dist/packem_chunks/LogsPanel.js +1 -1
  15. package/dist/packem_chunks/MailPanel.js +2 -2
  16. package/dist/packem_chunks/MetricsPanel.js +1 -1
  17. package/dist/packem_chunks/NotificationsPanel.js +1 -1
  18. package/dist/packem_chunks/PitrPanel.js +1 -1
  19. package/dist/packem_chunks/SchemaViewer.js +1 -2
  20. package/dist/packem_chunks/SecurityAdvisorPanel.js +1 -1
  21. package/dist/packem_chunks/SettingsPanel.js +1 -1
  22. package/dist/packem_chunks/SqlEditorPanel.js +6 -4
  23. package/dist/packem_chunks/TableEditor.js +1 -1
  24. package/dist/packem_chunks/agents-panel.js +1 -1
  25. package/dist/packem_chunks/analytics-panel.js +1 -1
  26. package/dist/packem_chunks/auth-audit-panel.js +1 -1
  27. package/dist/packem_chunks/auth-config-panel.js +1 -1
  28. package/dist/packem_chunks/auth-sessions-panel.js +1 -1
  29. package/dist/packem_chunks/containers-panel.js +1 -1
  30. package/dist/packem_chunks/dashboards-panel.js +1 -1
  31. package/dist/packem_chunks/fanout-panel.js +1 -1
  32. package/dist/packem_chunks/flags-panel.js +1 -1
  33. package/dist/packem_chunks/issues-panel.js +1 -1
  34. package/dist/packem_chunks/kv-browser.js +1 -1
  35. package/dist/packem_chunks/log-drains-panel.js +4 -4
  36. package/dist/packem_chunks/migrations-route.js +1 -0
  37. package/dist/packem_chunks/organizations-panel.js +1 -1
  38. package/dist/packem_chunks/payments-panel.js +1 -1
  39. package/dist/packem_chunks/permissions-panel.js +1 -1
  40. package/dist/packem_chunks/queues-panel.js +1 -1
  41. package/dist/packem_chunks/rls-panel.js +1 -1
  42. package/dist/packem_chunks/schedule-panel.js +1 -1
  43. package/dist/packem_chunks/sparkline.js +1 -1
  44. package/dist/packem_chunks/storage-rules-panel.js +1 -1
  45. package/dist/packem_chunks/subscriptions-panel.js +1 -1
  46. package/dist/packem_chunks/sync-client-panel.js +1 -1
  47. package/dist/packem_chunks/traces-panel.js +1 -1
  48. package/dist/packem_chunks/users-panel.js +1 -1
  49. package/dist/packem_chunks/vector-browser.js +1 -1
  50. package/dist/packem_chunks/workflows-panel.js +1 -1
  51. package/dist/packem_shared/ADMIN_FUNCTIONS-BnD4aovm.js +1 -0
  52. package/dist/packem_shared/ApiDocsPanel-DfUQ1ZAF.js +2 -0
  53. package/dist/packem_shared/{ApiReferencePanel-C42v1jr6.js → ApiReferencePanel-9q8BbJl-.js} +1 -1
  54. package/dist/packem_shared/CommandPalette--SQwfTW1.js +1 -0
  55. package/dist/packem_shared/DataBrowser-CuRlztBz.js +1 -0
  56. package/dist/packem_shared/DataFilters-B26ZeqBZ.js +1 -0
  57. package/dist/packem_shared/GlobalDataBrowser-DB-vQ2_H.js +1 -0
  58. package/dist/packem_shared/HomePanel-Dcs4a3Ax.js +1 -0
  59. package/dist/packem_shared/MigrationsPanel-C2OnsqRb.js +1 -0
  60. package/dist/packem_shared/{OpenRpcReferencePanel-sGsIgYWj.js → OpenRpcReferencePanel-qOZcWXMs.js} +1 -1
  61. package/dist/packem_shared/ScheduledJobs-D8kBZWBu.js +1 -0
  62. package/dist/packem_shared/Studio-B26_pT8J.js +1 -0
  63. package/dist/packem_shared/StudioApp-bXhJeLlZ.js +1 -0
  64. package/dist/packem_shared/advisor-view-Pa8HLtBv.js +1 -0
  65. package/dist/packem_shared/{app.d-bRPJhby-.d.ts → app.d-DW7yZsfu.d.ts} +1 -3
  66. package/dist/packem_shared/bar-chart-DraN_srt.js +9 -0
  67. package/dist/packem_shared/data-grid-DcxyIXwG.js +1 -0
  68. package/dist/packem_shared/data-view-params-ClrV7XgF.js +1 -0
  69. package/dist/packem_shared/error-alert-t6cpEi0z.js +1 -0
  70. package/dist/packem_shared/grid-features-jnrD0SpX.js +6 -0
  71. package/dist/packem_shared/{home-panel-Cm88Nvqh.js → home-panel-CU6MWLHG.js} +2 -2
  72. package/dist/packem_shared/{internal-AtZ4bTal.js → internal-BSIsQVC6.js} +1 -1
  73. package/dist/packem_shared/live-status-CmuRLFKf.js +1 -0
  74. package/dist/packem_shared/operation-console-provider-BMJNtiyB.js +1 -0
  75. package/dist/packem_shared/recording-client-DRAZEmzE.js +1 -0
  76. package/dist/packem_shared/reference-view-DnYYWr7I.js +12 -0
  77. package/dist/packem_shared/result-chart-DzJOVsaw.js +1 -0
  78. package/dist/packem_shared/schema-diagram-cg-bz_VL.js +2 -0
  79. package/dist/packem_shared/{sparkline-DtcZoU48.js → sparkline-CgjeUU2I.js} +1 -1
  80. package/dist/packem_shared/studio-q-C-acL7.js +2 -0
  81. package/dist/packem_shared/table-list-sidebar-BFkSQwlB.js +1 -0
  82. package/dist/packem_shared/use-admin-query-QJ-ibl5u.js +1 -0
  83. package/dist/packem_shared/use-async-submit-q3ymBJkD.js +1 -0
  84. package/dist/packem_shared/{use-auth-config-9S_K_W-G.js → use-auth-config-BObBpdsi.js} +1 -1
  85. package/dist/packem_shared/use-sql-assistant-CHEu2-Rk.js +1 -0
  86. package/dist/standalone/chunk-2GA4SHO7.js +1 -0
  87. package/dist/standalone/{chunk-NG6LYBPJ.js → chunk-2VDFV5TD.js} +1 -1
  88. package/dist/standalone/chunk-2WOIRKEI.js +1 -0
  89. package/dist/standalone/chunk-33CL6OHR.js +1 -0
  90. package/dist/standalone/{chunk-EIT7ERYE.js → chunk-34D36UCW.js} +1 -1
  91. package/dist/standalone/chunk-3C3CG7ZK.js +1 -0
  92. package/dist/standalone/{chunk-6CULAILE.js → chunk-3O3HAXW7.js} +1 -1
  93. package/dist/standalone/{chunk-LSEZN2ZL.js → chunk-3STOIE7Q.js} +1 -1
  94. package/dist/standalone/chunk-53WEPGUD.js +1 -0
  95. package/dist/standalone/chunk-5CVJS7ON.js +1 -0
  96. package/dist/standalone/chunk-6IKEW5LG.js +1 -0
  97. package/dist/standalone/chunk-6LNCYDZO.js +1 -0
  98. package/dist/standalone/chunk-6NY7SPDL.js +1 -0
  99. package/dist/standalone/chunk-6PNPIW6I.js +2 -0
  100. package/dist/standalone/{chunk-AVZGVZZ7.js → chunk-6VAKZALJ.js} +1 -1
  101. package/dist/standalone/chunk-6YI4WJO4.js +1 -0
  102. package/dist/standalone/{chunk-HYT2ZUNP.js → chunk-6YTSSIEJ.js} +2 -2
  103. package/dist/standalone/{chunk-KYF2E5CJ.js → chunk-7LWMHTJ3.js} +1 -1
  104. package/dist/standalone/chunk-A74VSSA2.js +4 -0
  105. package/dist/standalone/chunk-CCVXYYPJ.js +1 -0
  106. package/dist/standalone/chunk-CT5MMH4O.js +1 -0
  107. package/dist/standalone/chunk-CTNB2KIA.js +1 -0
  108. package/dist/standalone/chunk-CU55Y5TV.js +62 -0
  109. package/dist/standalone/chunk-D2RKH6JK.js +1 -0
  110. package/dist/standalone/chunk-E3NMX2VU.js +4 -0
  111. package/dist/standalone/chunk-FNPJ7GJZ.js +1 -0
  112. package/dist/standalone/chunk-FOBRNWBG.js +3 -0
  113. package/dist/standalone/chunk-G6PSMGLD.js +1 -0
  114. package/dist/standalone/chunk-GAX5IZYG.js +8 -0
  115. package/dist/standalone/chunk-GB6U2BPU.js +1 -0
  116. package/dist/standalone/chunk-GEDMLM4A.js +6 -0
  117. package/dist/standalone/chunk-GXSZH7VJ.js +13 -0
  118. package/dist/standalone/chunk-GYKVBKT5.js +1 -0
  119. package/dist/standalone/chunk-H6YOWRFB.js +1 -0
  120. package/dist/standalone/chunk-HJ3E4YF5.js +1 -0
  121. package/dist/standalone/chunk-HJD2YUQS.js +1 -0
  122. package/dist/standalone/chunk-IHQC7J35.js +1 -0
  123. package/dist/standalone/chunk-JLOWAJRR.js +1 -0
  124. package/dist/standalone/chunk-JRMMYIAF.js +1 -0
  125. package/dist/standalone/{chunk-W6TE2I2D.js → chunk-KC44QCN6.js} +1 -1
  126. package/dist/standalone/chunk-KJB7YAKB.js +1 -0
  127. package/dist/standalone/chunk-KLQYC6CC.js +1 -0
  128. package/dist/standalone/{chunk-XQGANNLS.js → chunk-KZ3ALMMP.js} +1 -1
  129. package/dist/standalone/chunk-L7R74G63.js +1 -0
  130. package/dist/standalone/{chunk-3RTTXLMU.js → chunk-OY2RVUZL.js} +1 -1
  131. package/dist/standalone/chunk-P4YLIBCN.js +1 -0
  132. package/dist/standalone/chunk-PZVU2QMX.js +1 -0
  133. package/dist/standalone/{chunk-PRJ4RJDU.js → chunk-Q7O6B7WC.js} +1 -1
  134. package/dist/standalone/chunk-QLQADHFE.js +1 -0
  135. package/dist/standalone/{chunk-7LQWFOEU.js → chunk-QXXIJAD5.js} +1 -1
  136. package/dist/standalone/chunk-QZGTH6WH.js +1 -0
  137. package/dist/standalone/chunk-RJP3WBZ4.js +1 -0
  138. package/dist/standalone/chunk-RNL6BSFM.js +1 -0
  139. package/dist/standalone/chunk-RNRJKBY3.js +4 -0
  140. package/dist/standalone/{chunk-7YEFOSPH.js → chunk-RQ7AFLIV.js} +1 -1
  141. package/dist/standalone/chunk-S252DAFP.js +1 -0
  142. package/dist/standalone/chunk-S2VVR7HI.js +1 -0
  143. package/dist/standalone/chunk-SKW6J4VW.js +1 -0
  144. package/dist/standalone/chunk-T7IUZIF4.js +1 -0
  145. package/dist/standalone/chunk-TTGOOYLF.js +1 -0
  146. package/dist/standalone/chunk-U6TNNM5U.js +1 -0
  147. package/dist/standalone/chunk-VHWOCPRK.js +1 -0
  148. package/dist/standalone/chunk-W6SAOXGH.js +6 -0
  149. package/dist/standalone/{chunk-YCRMVBPW.js → chunk-WBYSSCV2.js} +1 -1
  150. package/dist/standalone/{chunk-LFXFP4IF.js → chunk-X665E2HU.js} +1 -1
  151. package/dist/standalone/chunk-XDAT7LHC.js +1 -0
  152. package/dist/standalone/chunk-XS5LDR52.js +1 -0
  153. package/dist/standalone/chunk-Y5Y7DHFW.js +1 -0
  154. package/dist/standalone/chunk-YJYTMQJI.js +1 -0
  155. package/dist/standalone/chunk-Z2V42P7J.js +1 -0
  156. package/dist/standalone/studio.js +5 -5
  157. package/dist/styles.css +1 -1
  158. package/package.json +1 -1
  159. package/dist/packem_chunks/MigrationsPanel.js +0 -1
  160. package/dist/packem_shared/ADMIN_FUNCTIONS-CpgIo9pj.js +0 -1
  161. package/dist/packem_shared/ApiDocsPanel-CjdsxN1t.js +0 -2
  162. package/dist/packem_shared/CommandPalette-CVIaY3j8.js +0 -1
  163. package/dist/packem_shared/DataBrowser-Bfstz_au.js +0 -1
  164. package/dist/packem_shared/DataFilters-Csb30F0C.js +0 -1
  165. package/dist/packem_shared/GlobalDataBrowser-RLJ6NvOs.js +0 -1
  166. package/dist/packem_shared/HomePanel-B8EFM4u3.js +0 -1
  167. package/dist/packem_shared/ScheduledJobs-DUbo6epc.js +0 -1
  168. package/dist/packem_shared/Studio-BDtS9C5g.js +0 -1
  169. package/dist/packem_shared/StudioApp-DjLzIO9E.js +0 -1
  170. package/dist/packem_shared/advisor-view-DaCX9Jy5.js +0 -1
  171. package/dist/packem_shared/bar-chart-AryFCeoa.js +0 -9
  172. package/dist/packem_shared/data-grid-BMBKzMEJ.js +0 -1
  173. package/dist/packem_shared/data-view-params-C8T3bW1z.js +0 -1
  174. package/dist/packem_shared/error-alert-B59DnrDI.js +0 -1
  175. package/dist/packem_shared/grid-features-uZCUj955.js +0 -6
  176. package/dist/packem_shared/live-status-CGW2JHf_.js +0 -1
  177. package/dist/packem_shared/reference-view-KvhektwF.js +0 -12
  178. package/dist/packem_shared/result-chart-CwKhhKM0.js +0 -1
  179. package/dist/packem_shared/studio-BmWFd-Rz.js +0 -2
  180. package/dist/packem_shared/table-list-sidebar-CMCcNALK.js +0 -1
  181. package/dist/packem_shared/use-admin-query-Di3fLE8H.js +0 -1
  182. package/dist/packem_shared/use-async-submit-DLNCqLFq.js +0 -1
  183. package/dist/standalone/chunk-2SHUN7KF.js +0 -1
  184. package/dist/standalone/chunk-2Y36BVVM.js +0 -4
  185. package/dist/standalone/chunk-3EXLKL6V.js +0 -1
  186. package/dist/standalone/chunk-3KAERFMC.js +0 -1
  187. package/dist/standalone/chunk-4XDMVUS5.js +0 -1
  188. package/dist/standalone/chunk-5RF4QDDA.js +0 -6
  189. package/dist/standalone/chunk-5YWJNF5X.js +0 -1
  190. package/dist/standalone/chunk-66YJ3IOZ.js +0 -1
  191. package/dist/standalone/chunk-6KHEBRBB.js +0 -1
  192. package/dist/standalone/chunk-6WCIFGDW.js +0 -1
  193. package/dist/standalone/chunk-7RG3AKPY.js +0 -1
  194. package/dist/standalone/chunk-A2FPLOMJ.js +0 -1
  195. package/dist/standalone/chunk-AADXUXZO.js +0 -1
  196. package/dist/standalone/chunk-ARI4JTIH.js +0 -1
  197. package/dist/standalone/chunk-BDO4J5AP.js +0 -1
  198. package/dist/standalone/chunk-BMQJ4CAO.js +0 -1
  199. package/dist/standalone/chunk-CMUP7HPS.js +0 -1
  200. package/dist/standalone/chunk-CP7AUUOU.js +0 -1
  201. package/dist/standalone/chunk-DX3RMFQU.js +0 -8
  202. package/dist/standalone/chunk-E2CJUP53.js +0 -13
  203. package/dist/standalone/chunk-FLYO3XY5.js +0 -1
  204. package/dist/standalone/chunk-FWCKM2CU.js +0 -1
  205. package/dist/standalone/chunk-GITJXQOS.js +0 -4
  206. package/dist/standalone/chunk-GP6IRITM.js +0 -1
  207. package/dist/standalone/chunk-GXU3ATKS.js +0 -1
  208. package/dist/standalone/chunk-H5Y5NQPL.js +0 -1
  209. package/dist/standalone/chunk-HALNNKTC.js +0 -1
  210. package/dist/standalone/chunk-HK4OVYG3.js +0 -1
  211. package/dist/standalone/chunk-HQEMYD2K.js +0 -1
  212. package/dist/standalone/chunk-I4WGRDL2.js +0 -1
  213. package/dist/standalone/chunk-ISZSYNTI.js +0 -4
  214. package/dist/standalone/chunk-JWG3VRGB.js +0 -1
  215. package/dist/standalone/chunk-KDYNM3GV.js +0 -1
  216. package/dist/standalone/chunk-KP6JQSH2.js +0 -4
  217. package/dist/standalone/chunk-LLXFYRGQ.js +0 -1
  218. package/dist/standalone/chunk-LU3GW7HI.js +0 -1
  219. package/dist/standalone/chunk-M536Y2KX.js +0 -1
  220. package/dist/standalone/chunk-MVGE3JJN.js +0 -1
  221. package/dist/standalone/chunk-MXSHWB3M.js +0 -1
  222. package/dist/standalone/chunk-NL2DZKFI.js +0 -1
  223. package/dist/standalone/chunk-OGVCXKRL.js +0 -2
  224. package/dist/standalone/chunk-OPC233PZ.js +0 -1
  225. package/dist/standalone/chunk-P4CWOYFL.js +0 -1
  226. package/dist/standalone/chunk-PUY3YDXI.js +0 -1
  227. package/dist/standalone/chunk-QZMR6MUG.js +0 -1
  228. package/dist/standalone/chunk-WCWYSOCN.js +0 -62
  229. package/dist/standalone/chunk-WEO3YVP6.js +0 -3
  230. package/dist/standalone/chunk-X2FQ6B5V.js +0 -1
  231. package/dist/standalone/chunk-XIZNYKOD.js +0 -1
  232. package/dist/standalone/chunk-XS6Q6GGV.js +0 -1
  233. package/dist/standalone/chunk-Y3CQDULJ.js +0 -1
  234. package/dist/standalone/chunk-Z2JPEI2V.js +0 -1
  235. /package/dist/standalone/{chunk-4CGALXS3.js → chunk-OG4N2XHD.js} +0 -0
@@ -1,4 +1,6 @@
1
- import{c as K}from"react/compiler-runtime";import{useLunora as Ie}from"@lunora/react";import{useState as J,useRef as X,useEffect as fe,useId as gt}from"react";import{j as vt}from"../packem_shared/result-chart-CwKhhKM0.js";import{ShardInput as yt}from"../packem_shared/ShardInput-BVn2iCU0.js";import{A as Nt}from"../packem_shared/alert-CVcOFuDR.js";import{d as kt,m as we,f as wt,n as qt,p as Ct,u as St}from"../packem_shared/table-DdJBrClo.js";import{useT as V}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as be}from"../packem_shared/ADMIN_FUNCTIONS-CpgIo9pj.js";import{u as ue,n as $e,b as Ee}from"../packem_shared/browser-storage-xjTyMKY0.js";import{f as Z,c as me,a as he,e as It}from"../packem_shared/internal-AtZ4bTal.js";import{r as $t}from"../packem_shared/shard-history-DMEW5VBE.js";import{y as Et}from"../packem_shared/data-grid-BMBKzMEJ.js";import{J as Tt}from"../packem_shared/grid-features-uZCUj955.js";import{c as xe}from"../packem_shared/utils-bhneXptQ.js";import{jsx as a,jsxs as w,Fragment as qe}from"react/jsx-runtime";const Lt=["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"],Rt=["FROM","WHERE","ORDER BY","GROUP BY","HAVING","LIMIT","OFFSET","UNION","JOIN","LEFT JOIN","RIGHT JOIN","INNER JOIN","OUTER JOIN","CROSS JOIN"],ne=String.fromCodePoint(0),Ot=new RegExp(`${ne}${String.raw`(\d+)`}${ne}`,"gu"),Dt=Lt.map(r=>({pattern:new RegExp(String.raw`\b${r.replaceAll(" ",String.raw`\s+`)}\b`,"giu"),replacement:r})),Mt=Rt.map(r=>({pattern:new RegExp(String.raw`\s+${r.replaceAll(" ",String.raw`\s+`)}\b`,"gu"),replacement:`
2
- ${r}`})),_t=r=>{const e=[];let t=r.replaceAll(/'(?:[^']|'')*'/gu,n=>(e.push(n),`${ne}${(e.length-1).toString()}${ne}`)).replaceAll(/\s+/gu," ").trim();for(const{pattern:n,replacement:l}of Dt)t=t.replaceAll(n,l);for(const{pattern:n,replacement:l}of Mt)t=t.replaceAll(n,l);return t=t.replaceAll(Ot,(n,l)=>e[Number(l)]??""),t},At=["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"],zt=new Set(["AND","BY","HAVING","ON","OR","SELECT","WHERE"]),jt=/[\w$]/,Te=r=>r!==void 0&&jt.test(r),Le=r=>{let e=r.length;for(;e>0&&Te(r[e-1]);)e-=1;return r.slice(e)},Re=(r,e)=>{let t=e;for(;t>0&&Te(r[t-1]);)t-=1;return{end:e,start:t,text:r.slice(t,e)}},Ce=(r,e)=>{const t=r.slice(0,e).trimEnd();return t.endsWith(".")||zt.has(Le(t).toUpperCase())},Bt=(r,e)=>{const t=r.slice(0,e);if(!t.endsWith("."))return;const n=Le(t.slice(0,-1));return n===""?void 0:n},ge=(r,e)=>r.toLowerCase().startsWith(e.toLowerCase()),Se=(r,e,t,n)=>{const l=[];for(const s of r)if(ge(s,e)&&(l.push(n(s)),l.length>=t))break;return l},Wt=(r,e,t)=>{const n=new Map;for(const[l,s]of Object.entries(r.columns))for(const c of s)if(ge(c,e)&&!n.has(c)&&(n.set(c,l),n.size>=t))return[...n].map(([m,i])=>({detail:i,kind:"column",label:m}));return[...n].map(([l,s])=>({detail:s,kind:"column",label:l}))},Ft=(r,e,t)=>{const n=Re(r,e),l=Bt(r,n.start);if(l!==void 0){const i=t.columns[l]??t.columns[l.toLowerCase()]??[];return Se(i,n.text,8,u=>({detail:l,kind:"column",label:u}))}if(n.text===""&&!Ce(r,n.start))return[];const s=Se(t.tables,n.text,8,i=>({kind:"table",label:i})),c=Wt(t,n.text,8),m=At.filter(i=>n.text!==""&&ge(i,n.text)&&i.toLowerCase()!==n.text.toLowerCase()).map(i=>({kind:"keyword",label:i}));return(Ce(r,n.start)?[...c,...s,...m]:[...s,...c,...m]).slice(0,8)},Ht=(r,e,t)=>{const n=Re(r,e),l=r.slice(0,n.start)+t.label+r.slice(n.end);return{caret:n.start+t.label.length,value:l}},Pt=["boxSizing","borderBottomWidth","borderLeftWidth","borderRightWidth","borderTopWidth","fontFamily","fontSize","fontStyle","fontWeight","letterSpacing","lineHeight","paddingBottom","paddingLeft","paddingRight","paddingTop","tabSize","textIndent","textTransform","width","wordSpacing"],Ut=(r,e)=>{const t=globalThis.getComputedStyle(r),n=globalThis.document.createElement("div"),{style:l}=n;l.position="absolute",l.visibility="hidden",l.whiteSpace="pre-wrap",l.overflowWrap="break-word";for(const i of Pt)l[i]=t[i];n.textContent=r.value.slice(0,Math.max(0,e));const s=globalThis.document.createElement("span");s.textContent=r.value.slice(Math.max(0,e))||".",n.append(s),globalThis.document.body.append(n);const c=s.offsetLeft-r.scrollLeft,m=s.offsetTop-r.scrollTop;return n.remove(),{left:c,top:m}},Jt=(r,e,t)=>{const n=K(13),[l,s]=J(null);let c;n[0]!==r||n[1]!==e?(c=(v,g)=>{const y=Ft(v,g,r);if(y.length===0){s(null);return}const b=e.current,{left:C,top:q}=b===null?{left:0,top:0}:Ut(b,g);s($=>$!==null&&$.active===0&&$.left===C&&$.top===q&&$.suggestions.length===y.length&&$.suggestions.every((S,O)=>{const L=y.at(O);return S.kind===L?.kind&&S.label===L.label&&S.detail===L.detail})?$:{active:0,left:C,suggestions:y,top:q})},n[0]=r,n[1]=e,n[2]=c):c=n[2];const m=c;let i;n[3]===Symbol.for("react.memo_cache_sentinel")?(i=()=>{s(null)},n[3]=i):i=n[3];const u=i;let N;n[4]===Symbol.for("react.memo_cache_sentinel")?(N=v=>{s(g=>{if(g===null)return g;const y=g.suggestions.length,b=(g.active+v+y)%y;return{...g,active:b}})},n[4]=N):N=n[4];const x=N;let h;n[5]!==t||n[6]!==l||n[7]!==e?(h=()=>{const v=e.current;if(l===null||v===null)return!1;const g=l.suggestions[l.active];if(g===void 0)return!1;const y=Ht(v.value,v.selectionStart,g);return t(y.value),s(null),requestAnimationFrame(()=>{const b=e.current;b!==null&&(b.focus(),b.setSelectionRange(y.caret,y.caret))}),!0},n[5]=t,n[6]=l,n[7]=e,n[8]=h):h=n[8];const p=h;let d;return n[9]!==p||n[10]!==m||n[11]!==l?(d={close:u,commit:p,move:x,refresh:m,state:l},n[9]=p,n[10]=m,n[11]=l,n[12]=d):d=n[12],d},Kt={column:"column",keyword:"keyword",table:"table"},Yt=20,Vt=r=>{const e=K(17),{listboxId:t,onPick:n,state:l}=r,s=V();let c;e[0]!==l?(c=l===null?void 0:{left:l.left,top:l.top+Yt},e[0]=l,e[1]=c):c=e[1];const m=c;if(l===null)return null;let i;if(e[2]!==t||e[3]!==n||e[4]!==l.active||e[5]!==l.suggestions||e[6]!==s){let N;e[8]!==t||e[9]!==n||e[10]!==l.active||e[11]!==s?(N=(x,h)=>w("li",{"aria-selected":h===l.active,className:xe("flex cursor-pointer items-center gap-2 px-2 py-1 text-[13px]",h===l.active?"bg-accent text-accent-foreground":"text-foreground"),"data-testid":"sql-autocomplete-item",id:`${t}-opt-${h.toString()}`,onMouseDown:p=>{p.preventDefault(),n(h)},role:"option",children:[a("span",{className:"truncate font-mono",children:x.label}),x.detail!==void 0&&a("span",{className:"ms-auto truncate text-xs text-muted-foreground",children:x.detail}),a("span",{className:"shrink-0 font-mono text-[10px] tracking-wide text-muted-foreground/70 uppercase",children:s(Kt[x.kind])})]},`${x.kind}:${x.label}`),e[8]=t,e[9]=n,e[10]=l.active,e[11]=s,e[12]=N):N=e[12],i=l.suggestions.map(N),e[2]=t,e[3]=n,e[4]=l.active,e[5]=l.suggestions,e[6]=s,e[7]=i}else i=e[7];let u;return e[13]!==t||e[14]!==m||e[15]!==i?(u=a("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:m,children:i}),e[13]=t,e[14]=m,e[15]=i,e[16]=u):u=e[16],u},Oe=[{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;"}],Gt=r=>{const e=K(29),{active:t,onDelete:n,onSelect:l,query:s}=r,c=V();let m;e[0]!==l||e[1]!==s.id?(m=()=>{l(s.id)},e[0]=l,e[1]=s.id,e[2]=m):m=e[2];const i=m;let u;e[3]!==n||e[4]!==s.id?(u=S=>{S.stopPropagation(),n(s.id)},e[3]=n,e[4]=s.id,e[5]=u):u=e[5];const N=u,x=t?"bg-sidebar-accent font-medium text-foreground":"text-muted-foreground";let h;e[6]!==x?(h=xe("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",x),e[6]=x,e[7]=h):h=e[7];const p=`sql-query-${s.id}`;let d;e[8]===Symbol.for("react.memo_cache_sentinel")?(d=a("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:a("path",{d:"M4 6h16M4 12h10M4 18h7"})}),e[8]=d):d=e[8];let v;e[9]!==s.name?(v=a("span",{className:"truncate",children:s.name}),e[9]=s.name,e[10]=v):v=e[10];let g;e[11]!==t||e[12]!==i||e[13]!==h||e[14]!==p||e[15]!==v?(g=w("button",{"aria-pressed":t,className:h,"data-testid":p,onClick:i,type:"button",children:[d,v]}),e[11]=t,e[12]=i,e[13]=h,e[14]=p,e[15]=v,e[16]=g):g=e[16];let y;e[17]!==c?(y=c("Delete query"),e[17]=c,e[18]=y):y=e[18];let b;e[19]!==c?(b=c("Delete query"),e[19]=c,e[20]=b):b=e[20];let C;e[21]===Symbol.for("react.memo_cache_sentinel")?(C=a("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:a("path",{d:"M5 7h14M9 7V5h6v2m-1 0v12H10V7M7 7v13h10V7"})}),e[21]=C):C=e[21];let q;e[22]!==N||e[23]!==b||e[24]!==y?(q=a("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:N,title:b,type:"button",children:C}),e[22]=N,e[23]=b,e[24]=y,e[25]=q):q=e[25];let $;return e[26]!==q||e[27]!==g?($=w("li",{className:"group/q flex items-center",children:[g,q]}),e[26]=q,e[27]=g,e[28]=$):$=e[28],$},Qt=r=>{const e=K(58),{activeId:t,history:n,listRef:l,onClearHistory:s,onDelete:c,onLoadHistory:m,onLoadTemplate:i,onNew:u,onSearchChange:N,onSelect:x,queries:h,search:p}=r,d=V();let v;if(e[0]!==h||e[1]!==p){const I=p.trim().toLowerCase();v=I===""?[...h]:h.filter(T=>T.name.toLowerCase().includes(I)),e[0]=h,e[1]=p,e[2]=v}else v=e[2];const g=v;let y;e[3]!==d?(y=d("Search queries…"),e[3]=d,e[4]=y):y=e[4];let b;e[5]!==N||e[6]!==p||e[7]!==y?(b=a("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:N,placeholder:y,type:"text",value:p}),e[5]=N,e[6]=p,e[7]=y,e[8]=b):b=e[8];let C;e[9]!==d?(C=d("New query"),e[9]=d,e[10]=C):C=e[10];let q;e[11]!==d?(q=d("New query"),e[11]=d,e[12]=q):q=e[12];let $;e[13]===Symbol.for("react.memo_cache_sentinel")?($=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:a("path",{d:"M12 5v14M5 12h14"})}),e[13]=$):$=e[13];let S;e[14]!==u||e[15]!==C||e[16]!==q?(S=a("button",{"aria-label":C,className:"flex size-8 shrink-0 items-center justify-center rounded-md border border-border text-foreground outline-none transition-colors hover:bg-accent focus-visible:bg-accent","data-testid":"sql-new",onClick:u,title:q,type:"button",children:$}),e[14]=u,e[15]=C,e[16]=q,e[17]=S):S=e[17];let O;e[18]!==b||e[19]!==S?(O=w("div",{className:"flex shrink-0 items-center gap-2 border-b border-border p-2",children:[b,S]}),e[18]=b,e[19]=S,e[20]=O):O=e[20];let L;e[21]!==d?(L=d("Private"),e[21]=d,e[22]=L):L=e[22];let D;e[23]!==L?(D=a("p",{className:"px-1 pb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:L}),e[23]=L,e[24]=D):D=e[24];let M;e[25]!==t||e[26]!==g||e[27]!==l||e[28]!==c||e[29]!==x||e[30]!==d?(M=g.length===0?a("p",{className:"px-1 py-2 text-xs text-muted-foreground","data-testid":"sql-private-empty",children:d("No saved queries yet — they save to this browser as you type.")}):a("ul",{className:"flex flex-col gap-px","data-testid":"sql-private",ref:l,children:g.map(I=>a(Gt,{active:t===I.id,onDelete:c,onSelect:x,query:I},I.id))}),e[25]=t,e[26]=g,e[27]=l,e[28]=c,e[29]=x,e[30]=d,e[31]=M):M=e[31];let A;e[32]!==D||e[33]!==M?(A=w("div",{children:[D,M]}),e[32]=D,e[33]=M,e[34]=A):A=e[34];let z;e[35]!==d?(z=d("Reference"),e[35]=d,e[36]=z):z=e[36];let H;e[37]!==z?(H=a("p",{className:"px-1 pb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:z}),e[37]=z,e[38]=H):H=e[38];let W;e[39]!==i?(W=Oe.map(I=>a("li",{children:w("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":I.sql,onClick:i,type:"button",children:[a("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:a("path",{d:"M7 4h7l4 4v12H7zM14 4v4h4"})}),I.label]})},I.label)),e[39]=i,e[40]=W):W=e[40];let _;e[41]!==W?(_=a("ul",{className:"flex flex-col gap-px",children:W}),e[41]=W,e[42]=_):_=e[42];let E;e[43]!==H||e[44]!==_?(E=w("div",{children:[H,_]}),e[43]=H,e[44]=_,e[45]=E):E=e[45];let R;e[46]!==n||e[47]!==s||e[48]!==m||e[49]!==d?(R=n.length>0&&w("div",{children:[w("div",{className:"flex items-center justify-between px-1 pb-1",children:[a("p",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:d("History")}),a("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:s,type:"button",children:d("Clear history")})]}),a("ul",{className:"flex flex-col gap-px","data-testid":"sql-history",children:n.map(I=>a("li",{children:w("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":I.sql,"data-testid":"sql-history-item",onClick:m,title:I.sql,type:"button",children:[a("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:a("path",{d:"M12 8v4l3 2M12 21a9 9 0 1 1 0-18 9 9 0 0 1 0 18Z"})}),a("span",{className:"truncate font-mono",children:I.sql})]})},`${I.at.toString()}:${I.sql}`))})]}),e[46]=n,e[47]=s,e[48]=m,e[49]=d,e[50]=R):R=e[50];let j;e[51]!==A||e[52]!==E||e[53]!==R?(j=w("div",{className:"flex flex-1 flex-col gap-4 overflow-y-auto p-2",children:[A,E,R]}),e[51]=A,e[52]=E,e[53]=R,e[54]=j):j=e[54];let B;return e[55]!==j||e[56]!==O?(B=w("aside",{className:"flex h-full w-64 shrink-0 flex-col border-e border-border bg-sidebar",children:[O,j]}),e[55]=j,e[56]=O,e[57]=B):B=e[57],B},Xt=he(be.listTables),Zt=he(be.readTablePage),en=r=>{const e=K(16),t=Ie();let n;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=[],e[0]=n):n=e[0];const[l,s]=J(n);let c;e[1]===Symbol.for("react.memo_cache_sentinel")?(c={},e[1]=c):c=e[1];const[m,i]=J(c);let u;e[2]===Symbol.for("react.memo_cache_sentinel")?(u=new Set,e[2]=u):u=e[2];const N=X(u);let x,h;e[3]!==t||e[4]!==r?(x=()=>{const b={cancelled:!1};return Z((async()=>{try{const C=await t.query(Xt,{},me(r));b.cancelled||(s(C.map(nn)),i({}),N.current=new Set)}catch{b.cancelled||(s([]),i({}),N.current=new Set)}})()),()=>{b.cancelled=!0}},h=[t,r],e[3]=t,e[4]=r,e[5]=x,e[6]=h):(x=e[5],h=e[6]),fe(x,h);let p;e[7]!==t||e[8]!==r?(p=b=>{N.current.has(b)||(N.current.add(b),Z((async()=>{try{const C=await t.query(Zt,{limit:1,offset:0,table:b},me(r));i(q=>({...q,[b]:C.columns}))}catch{N.current.delete(b)}})()))},e[7]=t,e[8]=r,e[9]=p):p=e[9];const d=p;let v;e[10]!==m||e[11]!==l?(v={columns:m,tables:l},e[10]=m,e[11]=l,e[12]=v):v=e[12];const g=v;let y;return e[13]!==d||e[14]!==g?(y={probe:d,schema:g},e[13]=d,e[14]=g,e[15]=y):y=e[15],y},ce=/\b(?:from|join|update|into)\s+([a-z_][\w$]*)|\b([a-z_][\w$]*)\s*\./gi,tn=r=>{const e=new Set;ce.lastIndex=0;let t=ce.exec(r);for(;t!==null;)e.add(t[1]??t[2]),t=ce.exec(r);return[...e]};function nn(r){return r.name}const rn="lunora-studio-sql-tabs",ln="lunora-studio-sql-active-tab",pe=12,Q=(r="",e="")=>({activeId:null,id:$e("tab"),name:e,sql:r}),on=()=>Ee(ln,""),sn=r=>{const[e,t]=ue(rn),[n,l]=on(),s=X(null);e.length===0&&s.current===null&&(s.current=r()),fe(()=>{if(e.length===0&&s.current!==null){const m=s.current;t([m])}},[t,e.length]);const c=e.length===0&&s.current!==null?[s.current]:e;return{activeId:c.some(m=>m.id===n)?n:c[0]?.id??"",setActiveId:l,setTabs:t,tabs:c}},De=r=>r.activeId===null&&r.sql.trim()!=="",an=(r,e)=>[...r,e].slice(-pe),cn=(r,e,t)=>{const n=r.findIndex(s=>s.id===e);if(n===-1)return{activeId:r[0]?.id??"",tabs:[...r]};const l=r.filter(s=>s.id!==e);if(l.length===0){const s=t();return{activeId:s.id,tabs:[s]}}return{activeId:l[Math.min(n,l.length-1)].id,tabs:l}},dn=(r,e)=>{const t=r.filter(n=>n.id===e);return t.length===0?{activeId:r[0]?.id??"",tabs:[...r]}:{activeId:e,tabs:t}},un=(r,e,t)=>{const n=r.findIndex(s=>s.id===e);if(n===-1)return{activeId:t,tabs:[...r]};const l=r.slice(0,n+1);return{activeId:l.some(s=>s.id===t)?t:e,tabs:l}},mn=r=>{const e=r();return{activeId:e.id,tabs:[e]}},pn=(r,e,t)=>{if(r==="others")return e.filter(n=>n.id!==t);if(r==="right"){const n=e.findIndex(l=>l.id===t);return n===-1?[]:e.slice(n+1)}return[...e]},fn=(r,e)=>r.trim()===""?e:(r.split(`
3
- `)[0]??r).slice(0,24),bn=r=>{const e=K(14),{initial:t,onCancel:n,onCommit:l,placeholder:s,testId:c}=r,m=V(),i=gn;let u;e[0]!==l?(u=v=>{l(v.currentTarget.value.trim())},e[0]=l,e[1]=u):u=e[1];const N=u;let x;e[2]!==n||e[3]!==l?(x=v=>{v.key==="Enter"?l(v.currentTarget.value.trim()):v.key==="Escape"&&n()},e[2]=n,e[3]=l,e[4]=x):x=e[4];const h=x;let p;e[5]!==m?(p=m("Tab title"),e[5]=m,e[6]=p):p=e[6];let d;return e[7]!==t||e[8]!==N||e[9]!==h||e[10]!==s||e[11]!==p||e[12]!==c?(d=a("input",{"aria-label":p,className:"w-40 rounded border border-ring bg-background px-1 py-0.5 text-xs outline-none","data-testid":c,defaultValue:t,onBlur:N,onKeyDown:h,placeholder:s,ref:i,type:"text"}),e[7]=t,e[8]=N,e[9]=h,e[10]=s,e[11]=p,e[12]=c,e[13]=d):d=e[13],d},hn=r=>{const e=K(29),{idBase:t,onDiscard:n,onKeep:l}=r,s=V(),c=`sql-tab-close-prompt-${t}`;let m;e[0]!==s?(m=s("Discard?"),e[0]=s,e[1]=m):m=e[1];let i;e[2]!==m?(i=a("span",{className:"text-[11px] text-muted-foreground",children:m}),e[2]=m,e[3]=i):i=e[3];let u;e[4]!==s?(u=s("Discard changes"),e[4]=s,e[5]=u):u=e[5];const N=`sql-tab-close-confirm-${t}`;let x;e[6]!==s?(x=s("Discard changes"),e[6]=s,e[7]=x):x=e[7];let h;e[8]===Symbol.for("react.memo_cache_sentinel")?(h=a("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2.4,viewBox:"0 0 24 24",children:a("path",{d:"M5 13l4 4L19 7"})}),e[8]=h):h=e[8];let p;e[9]!==n||e[10]!==u||e[11]!==N||e[12]!==x?(p=a("button",{"aria-label":u,className:"flex size-5 items-center justify-center rounded text-destructive hover:bg-destructive/10","data-testid":N,onClick:n,title:x,type:"button",children:h}),e[9]=n,e[10]=u,e[11]=N,e[12]=x,e[13]=p):p=e[13];let d;e[14]!==s?(d=s("Keep editing"),e[14]=s,e[15]=d):d=e[15];const v=`sql-tab-close-cancel-${t}`;let g;e[16]!==s?(g=s("Keep editing"),e[16]=s,e[17]=g):g=e[17];let y;e[18]===Symbol.for("react.memo_cache_sentinel")?(y=a("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2.4,viewBox:"0 0 24 24",children:a("path",{d:"M6 6l12 12M18 6 6 18"})}),e[18]=y):y=e[18];let b;e[19]!==l||e[20]!==v||e[21]!==g||e[22]!==d?(b=a("button",{"aria-label":d,className:"flex size-5 items-center justify-center rounded text-muted-foreground hover:bg-accent","data-testid":v,onClick:l,title:g,type:"button",children:y}),e[19]=l,e[20]=v,e[21]=g,e[22]=d,e[23]=b):b=e[23];let C;return e[24]!==c||e[25]!==b||e[26]!==i||e[27]!==p?(C=w("span",{className:"flex shrink-0 items-center gap-1","data-testid":c,role:"group",children:[i,p,b]}),e[24]=c,e[25]=b,e[26]=i,e[27]=p,e[28]=C):C=e[28],C},xn=r=>{const e=K(47),{active:t,canClose:n,onClose:l,onMenu:s,onRename:c,onSelect:m,tab:i}=r,u=V(),[N,x]=J(!1),[h,p]=J(!1);let d;e[0]!==s||e[1]!==i.id?(d=F=>{s(i.id,F)},e[0]=s,e[1]=i.id,e[2]=d):d=e[2];const v=d;let g;e[3]!==m||e[4]!==i.id?(g=()=>{m(i.id)},e[3]=m,e[4]=i.id,e[5]=g):g=e[5];const y=g;let b;e[6]===Symbol.for("react.memo_cache_sentinel")?(b=()=>{x(!0)},e[6]=b):b=e[6];const C=b;let q;e[7]!==l||e[8]!==i?(q=F=>{F.stopPropagation(),De(i)?p(!0):l(i.id)},e[7]=l,e[8]=i,e[9]=q):q=e[9];const $=q;let S;e[10]!==l||e[11]!==i.id?(S=F=>{F.stopPropagation(),p(!1),l(i.id)},e[10]=l,e[11]=i.id,e[12]=S):S=e[12];const O=S;let L;e[13]===Symbol.for("react.memo_cache_sentinel")?(L=F=>{F.stopPropagation(),p(!1)},e[13]=L):L=e[13];const D=L;let M;e[14]!==c||e[15]!==i.id?(M=F=>{c(i.id,F),x(!1)},e[14]=c,e[15]=i.id,e[16]=M):M=e[16];const A=M;let z;e[17]===Symbol.for("react.memo_cache_sentinel")?(z=()=>{x(!1)},e[17]=z):z=e[17];const H=z;let W;e[18]!==i.name?(W=i.name.trim(),e[18]=i.name,e[19]=W):W=e[19];const _=W;let E;e[20]!==u||e[21]!==i.sql?(E=fn(i.sql,u("Untitled")),e[20]=u,e[21]=i.sql,e[22]=E):E=e[22];const R=E,j=t?"bg-background text-foreground":"bg-muted/40 text-muted-foreground hover:text-foreground";let B;e[23]!==j?(B=xe("group/tab flex shrink-0 items-center gap-1 border-e border-border ps-3 pe-1.5 text-xs",j),e[23]=j,e[24]=B):B=e[24];const I=`sql-tab-${i.id}`;let T;e[25]!==t||e[26]!==A||e[27]!==_||e[28]!==R||e[29]!==N||e[30]!==y||e[31]!==u||e[32]!==i.id?(T=N?a(bn,{initial:_,onCancel:H,onCommit:A,placeholder:R,testId:`sql-tab-rename-${i.id}`}):a("button",{"aria-pressed":t,className:"max-w-40 truncate py-1.5 outline-none","data-testid":`sql-tab-select-${i.id}`,onClick:y,onDoubleClick:C,title:u("Double-click to rename"),type:"button",children:_===""?R:_}),e[25]=t,e[26]=A,e[27]=_,e[28]=R,e[29]=N,e[30]=y,e[31]=u,e[32]=i.id,e[33]=T):T=e[33];let P;e[34]!==n||e[35]!==O||e[36]!==h||e[37]!==$||e[38]!==u||e[39]!==i.id?(P=n&&(h?a(hn,{idBase:i.id,onDiscard:O,onKeep:D}):a("button",{"aria-label":u("Close tab"),className:"flex size-5 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-destructive/10 hover:text-destructive","data-testid":`sql-tab-close-${i.id}`,onClick:$,title:u("Close tab"),type:"button",children:a("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,viewBox:"0 0 24 24",children:a("path",{d:"M6 6l12 12M18 6 6 18"})})})),e[34]=n,e[35]=O,e[36]=h,e[37]=$,e[38]=u,e[39]=i.id,e[40]=P):P=e[40];let G;return e[41]!==v||e[42]!==B||e[43]!==I||e[44]!==T||e[45]!==P?(G=w("div",{className:B,"data-testid":I,onContextMenu:v,children:[T,P]}),e[41]=v,e[42]=B,e[43]=I,e[44]=T,e[45]=P,e[46]=G):G=e[46],G};function gn(r){r?.focus(),r?.select()}const vn=he(be.runSql),yn="lunora-studio-sql-queries",Nn="lunora-studio-sql-history",kn="lunora-studio-sql-split-view",wn=25,qn={minWidth:"2.75rem",paddingInline:"0.5rem"},de={error:null,pane:"results",result:null},Cn=r=>{const e=K(16),{result:t}=r;if(t.columns.length===0){const i=t.rowCount===0?"0 rows":"";let u;return e[0]!==i?(u=a("p",{className:"p-4 text-sm text-muted-foreground",children:i}),e[0]=i,e[1]=u):u=e[1],u}let n;e[2]!==t.columns?(n=t.columns.map(Sn),e[2]=t.columns,e[3]=n):n=e[3];let l;e[4]!==n?(l=a(kt,{className:"sticky top-0 z-10 bg-muted",children:a(we,{children:n})}),e[4]=n,e[5]=l):l=e[5];let s;if(e[6]!==t.columns||e[7]!==t.rows){let i;e[9]!==t.columns?(i=(u,N)=>a(we,{"data-testid":"sql-row",children:t.columns.map(x=>a(St,{className:"max-w-md truncate font-mono text-xs",children:a(Et,{value:u[x]})},x))},N),e[9]=t.columns,e[10]=i):i=e[10],s=t.rows.map(i),e[6]=t.columns,e[7]=t.rows,e[8]=s}else s=e[8];let c;e[11]!==s?(c=a(wt,{children:s}),e[11]=s,e[12]=c):c=e[12];let m;return e[13]!==l||e[14]!==c?(m=w(qt,{"data-testid":"sql-rows",children:[l,c]}),e[13]=l,e[14]=c,e[15]=m):m=e[15],m},Hn=({initialShardKey:r})=>{const e=Ie(),t=V(),[n,l]=ue(yn),[s,c]=ue(Nn),[m,i]=J(""),u=()=>Q(Oe[0]?.sql??""),{activeId:N,setActiveId:x,setTabs:h,tabs:p}=sn(u),[d,v]=J({}),[g,y]=J(r??""),[b,C]=J(!1),[q,$]=Ee(kn,!1),[S,O]=J(null),[L,D]=J(null),M=X(null),A=X(null),z=X(null),H=gt(),{probe:W,schema:_}=en(g),E=p.find(o=>o.id===N)??p[0]??Q(),R=E.sql,{activeId:j}=E,B=d[E.id]??de,{error:I,result:T}=B,P=B.pane,G=o=>{h(f=>f.map(k=>k.id===E.id?{...k,...o}:k))},F=o=>{v(f=>{const k=f[E.id]??de;return{...f,[E.id]:{error:o.error,pane:o.pane??k.pane,result:o.result}}})},ve=o=>{v(f=>{const k=f[E.id]??de;return{...f,[E.id]:{...k,pane:o}}})},re=o=>{G({sql:o}),j!==null&&l(f=>f.map(k=>k.id===j?{...k,sql:o}:k))},Me=Jt(_,A,re),{close:le,commit:ye,move:oe,refresh:ee,state:Y}=Me,_e=o=>{oe(o-(Y?.active??0)),ye()};fe(()=>{const o=A.current;o!==null&&o===document.activeElement&&ee(o.value,o.selectionStart)},[ee,_]);const Ae=o=>{c(f=>f[0]?.sql===o?f:[{at:Date.now(),sql:o},...f.filter(k=>k.sql!==o)].slice(0,wn))},se=async o=>{if(R.trim()==="")return;C(!0);const f=o==="explain"?`EXPLAIN QUERY PLAN ${R}`:R;try{const k=await e.query(vn,{sql:f},me(g));F({error:null,pane:o,result:k}),$t(g),Ae(f)}catch(k){F({error:It(k),pane:o,result:null})}finally{C(!1)}},ze=()=>{Z(se("results"))},je=o=>{const{selectionStart:f,value:k}=o.target;re(k);for(const U of tn(k))W(U);ee(k,f)},Be=o=>{const f=o.currentTarget;ee(f.value,f.selectionStart)},We=o=>{if(Y!==null){if(o.key==="ArrowDown"){o.preventDefault(),oe(1);return}if(o.key==="ArrowUp"){o.preventDefault(),oe(-1);return}if(o.key==="Escape"){o.preventDefault(),le();return}if((o.key==="Enter"||o.key==="Tab")&&!o.metaKey&&!o.ctrlKey&&ye()){o.preventDefault();return}}(o.metaKey||o.ctrlKey)&&o.key==="Enter"&&(o.preventDefault(),Z(se(P)))},Fe=()=>{requestAnimationFrame(()=>{le()})},He=o=>{M.current!==null&&(M.current.scrollTop=o.currentTarget.scrollTop)},te=(o,f)=>{h(k=>k.map(U=>U.id===E.id?{...U,activeId:f,sql:o}:U)),F({error:null,result:null})},Pe=()=>{const o={id:$e("q"),name:t("Untitled query"),sql:""};l(f=>[o,...f]),te("",o.id)},Ue=o=>{const f=n.find(k=>k.id===o);f!==void 0&&(te(f.sql,o),z.current?.querySelector(`[data-testid="sql-query-${o}"]`)?.scrollIntoView({block:"nearest"}))},Je=o=>{l(f=>f.filter(k=>k.id!==o)),h(f=>f.map(k=>k.activeId===o?{...k,activeId:null}:k))},Ke=o=>{te(o.currentTarget.dataset.sql??"",null)},Ye=o=>{te(o.currentTarget.dataset.sql??"",null)},Ve=()=>{c([])},Ge=()=>{re(_t(R))},Qe=()=>{if(p.length>=pe)return;const o=Q();h(f=>an(f,o)),x(o.id)},Ne=o=>{O(null),D(null),h(o.tabs),x(o.activeId);const f=new Set(o.tabs.map(k=>k.id));v(k=>Object.fromEntries(Object.entries(k).filter(([U])=>f.has(U))))},Xe=o=>{Ne(cn(p,o,Q))},ke=(o,f)=>{Ne(o==="others"?dn(p,f):o==="right"?un(p,f,N):mn(Q))},ie=o=>{S!==null&&(pn(o,p,S.id).some(f=>De(f))?D(o):ke(o,S.id))},Ze=(o,f)=>{f.preventDefault(),D(null),O({id:o,x:f.clientX,y:f.clientY})},et=()=>{O(null),D(null)},tt=o=>{o.preventDefault(),O(null),D(null)},nt=()=>{ie("others")},rt=()=>{ie("right")},lt=()=>{ie("all")},ot=()=>{S!==null&&L!==null&&ke(L,S.id),D(null)},st=()=>{D(null)},it=S===null?void 0:{left:S.x,top:S.y},at=o=>{le(),x(o)},ct=(o,f)=>{h(k=>k.map(U=>U.id===o?{...U,name:f}:U))},dt=()=>{ve("results")},ut=()=>{Z(se("explain"))},mt=()=>{ve("chart")},pt=()=>{$(!q)},ft=R.split(`
4
- `).length,bt=o=>{i(o.target.value)},ae=o=>`border-b-2 px-3 py-2 text-sm outline-none transition-colors ${o?"border-foreground font-medium text-foreground":"border-transparent text-muted-foreground hover:text-foreground"}`,ht=q?"flex min-h-0 flex-1 flex-row":"flex min-h-0 flex-1 flex-col",xt=q?"flex w-2/5 min-h-0 min-w-0 shrink-0 flex-col border-s border-border":"flex h-2/5 min-h-0 shrink-0 flex-col border-t border-border";return w("div",{className:"flex h-full min-w-0","data-testid":"lunora-sql-editor",children:[a(Qt,{activeId:j,history:s,listRef:z,onClearHistory:Ve,onDelete:Je,onLoadHistory:Ye,onLoadTemplate:Ke,onNew:Pe,onSearchChange:bt,onSelect:Ue,queries:n,search:m}),w("div",{className:"flex min-w-0 flex-1 flex-col",children:[w("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:[p.map(o=>a(xn,{active:o.id===E.id,canClose:p.length>1,onClose:Xe,onMenu:Ze,onRename:ct,onSelect:at,tab:o},o.id)),a("button",{"aria-label":t("New tab"),className:"flex size-8 shrink-0 items-center justify-center text-muted-foreground outline-none transition-colors hover:bg-accent hover:text-foreground focus-visible:bg-accent disabled:pointer-events-none disabled:opacity-40","data-testid":"sql-tab-add",disabled:p.length>=pe,onClick:Qe,title:t("New tab"),type:"button",children: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:a("path",{d:"M12 5v14M5 12h14"})})})]}),S!==null&&w(qe,{children:[a("div",{className:"fixed inset-0 z-40","data-testid":"sql-tab-menu-backdrop",onClick:et,onContextMenu:tt,role:"presentation"}),a("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:it,children:L===null?w(qe,{children:[a("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:p.length<=1,onClick:nt,role:"menuitem",type:"button",children:t("Close other tabs")}),a("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:p.findIndex(o=>o.id===S.id)>=p.length-1,onClick:rt,role:"menuitem",type:"button",children:t("Close tabs to the right")}),a("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:lt,role:"menuitem",type:"button",children:t("Close all tabs")})]}):w("div",{className:"px-3 py-1.5","data-testid":"sql-tab-menu-confirm",children:[a("p",{className:"pb-1.5 text-xs text-muted-foreground",children:t("Discard unsaved tabs?")}),w("div",{className:"flex items-center gap-1.5",children:[a("button",{className:"rounded px-2 py-1 text-xs font-medium text-destructive outline-none hover:bg-destructive/10 focus-visible:bg-destructive/10","data-testid":"sql-tab-menu-confirm-discard",onClick:ot,type:"button",children:t("Discard")}),a("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:st,type:"button",children:t("Cancel")})]})]})})]}),w("div",{className:ht,children:[w("div",{className:"flex min-h-0 min-w-0 flex-1",children:[a("div",{"aria-hidden":"true",className:"shrink-0 select-none overflow-hidden border-e border-border bg-muted/30 py-3 text-end font-mono text-xs leading-5 text-muted-foreground/60",ref:M,style:qn,children:Array.from({length:ft},(o,f)=>a("div",{children:f+1},f))}),w("div",{className:"relative min-w-0 flex-1",children:[a("textarea",{"aria-activedescendant":Y===null?void 0:`${H}-opt-${Y.active.toString()}`,"aria-autocomplete":"list","aria-controls":Y===null?void 0:H,"aria-expanded":Y!==null,"aria-label":t("SQL query"),className:"size-full resize-none bg-background p-3 font-mono text-xs leading-5 outline-none","data-testid":"sql-input",onBlur:Fe,onChange:je,onKeyDown:We,onScroll:He,onSelect:Be,placeholder:"SELECT * FROM …",ref:A,role:"combobox",spellCheck:!1,value:R}),a(Vt,{listboxId:H,onPick:_e,state:Y})]})]}),w("div",{className:xt,children:[w("div",{className:"flex shrink-0 items-center gap-2 border-b border-border pe-2",children:[a("button",{className:ae(P==="results"),"data-testid":"sql-tab-results",onClick:dt,type:"button",children:t("Results")}),a("button",{className:ae(P==="chart"),"data-testid":"sql-tab-chart",onClick:mt,type:"button",children:t("Chart")}),a("button",{className:ae(P==="explain"),"data-testid":"sql-tab-explain",onClick:ut,type:"button",children:t("Explain")}),w("div",{className:"ms-auto flex items-center gap-2",children:[a("button",{"aria-label":t("Split editor and results"),"aria-pressed":q,className:`inline-flex items-center rounded-md border border-border px-2 py-1.5 outline-none transition-colors hover:bg-accent focus-visible:bg-accent ${q?"bg-accent text-foreground":"text-muted-foreground"}`,"data-testid":"sql-split-toggle",onClick:pt,title:t("Split editor and results"),type:"button",children:w("svg",{"aria-hidden":"true",className:"size-4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.7,viewBox:"0 0 24 24",children:[a("rect",{height:"16",rx:"2",width:"18",x:"3",y:"4"}),a("path",{d:"M12 4v16"})]})}),T!==null&&T.columns.length>0&&a(Tt,{columns:T.columns,name:"query-result",rows:T.rows}),a("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:b,onClick:Ge,type:"button",children:t("Format")}),a(yt,{onChange:y,testId:"sql-shard-input",value:g}),w("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:b,onClick:ze,type:"button",children:[t(b?"Running…":"Run"),a("kbd",{className:"rounded border border-primary-foreground/30 px-1 font-sans text-[10px]",children:"⌘↵"})]})]})]}),w("div",{className:"min-h-0 flex-1 overflow-auto",children:[I!==null&&a(Nt,{className:"m-3 font-mono text-xs",testId:"sql-error",variant:"destructive",children:I}),I===null&&T===null&&a("p",{className:"p-4 text-sm text-muted-foreground","data-testid":"sql-empty",children:t("Click Run to execute your query.")}),I===null&&T!==null&&w("div",{"data-testid":"sql-result",children:[P==="chart"?a(vt,{result:T}):a(Cn,{result:T}),a("p",{className:"border-t border-border px-3 py-1.5 text-xs text-muted-foreground","data-testid":"sql-count",children:T.truncated?t("Showing the first {max} of {count} rows.",{count:T.rowCount,max:T.rows.length}):t("{count} rows",{count:T.rowCount})})]})]})]})]})]})]})};function Sn(r){return a(Ct,{children:r},r)}export{Hn as SqlEditorPanel};
1
+ import{c as J}from"react/compiler-runtime";import{useLunora as ul}from"@lunora/react";import{useState as Q,useMemo as fl,useCallback as Dl,useEffect as An,useRef as Dt,useId as Al}from"react";import{I as zl}from"../packem_shared/result-chart-DzJOVsaw.js";import{ShardInput as jl}from"../packem_shared/ShardInput-BVn2iCU0.js";import{A as Bl}from"../packem_shared/alert-CVcOFuDR.js";import{d as Wl,m as hl,f as Fl,n as Pl,p as Hl,u as Ul}from"../packem_shared/table-DdJBrClo.js";import{useT as se}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as zn}from"../packem_shared/ADMIN_FUNCTIONS-BnD4aovm.js";import{u as cl,n as yl,b as wl}from"../packem_shared/browser-storage-xjTyMKY0.js";import{d as Mn,f as fe,g as jn,b as pl}from"../packem_shared/internal-BSIsQVC6.js";import{r as Yl}from"../packem_shared/shard-history-DMEW5VBE.js";import{g as Kl}from"../packem_shared/data-grid-DcxyIXwG.js";import{K as Ql}from"../packem_shared/grid-features-jnrD0SpX.js";import{k as Jl}from"../packem_shared/use-sql-assistant-CHEu2-Rk.js";import Gl from"../packem_shared/useDebounced-Ihdiid_k.js";import{u as Vl}from"../packem_shared/input-JHu63lTv.js";import{c as ve}from"../packem_shared/utils-bhneXptQ.js";import{jsx as i,jsxs as $,Fragment as bl}from"react/jsx-runtime";const Nl="p-3 font-mono text-xs leading-5 whitespace-pre-wrap break-words",Xl=(r,e)=>{const l=[];for(const t of r){if(t.offset===void 0||t.length===void 0||t.length<=0)continue;const o=Math.max(0,Math.min(t.offset,e)),a=Math.max(o,Math.min(t.offset+t.length,e));o!==a&&l.push({end:a,severity:t.severity,start:o})}l.sort((t,o)=>t.start-o.start);const n=[];for(const t of l)t.start>=(n.at(-1)?.end??0)&&n.push(t);return n},Zl=["ORDER BY","GROUP BY","LEFT JOIN","RIGHT JOIN","INNER JOIN","OUTER JOIN","CROSS JOIN","EXPLAIN QUERY PLAN","SELECT","DISTINCT","FROM","WHERE","HAVING","LIMIT","OFFSET","JOIN","ON","AND","OR","AS","ASC","DESC","WITH","UNION","EXPLAIN"],er=["FROM","WHERE","ORDER BY","GROUP BY","HAVING","LIMIT","OFFSET","UNION","JOIN","LEFT JOIN","RIGHT JOIN","INNER JOIN","OUTER JOIN","CROSS JOIN"],Dn=String.fromCodePoint(0),tr=new RegExp(`${Dn}${String.raw`(\d+)`}${Dn}`,"gu"),nr=Zl.map(r=>({pattern:new RegExp(String.raw`\b${r.replaceAll(" ",String.raw`\s+`)}\b`,"giu"),replacement:r})),lr=er.map(r=>({pattern:new RegExp(String.raw`\s+${r.replaceAll(" ",String.raw`\s+`)}\b`,"gu"),replacement:`
2
+ ${r}`})),rr=r=>{const e=[];let l=r.replaceAll(/'(?:[^']|'')*'/gu,n=>(e.push(n),`${Dn}${(e.length-1).toString()}${Dn}`)).replaceAll(/\s+/gu," ").trim();for(const{pattern:n,replacement:t}of nr)l=l.replaceAll(n,t);for(const{pattern:n,replacement:t}of lr)l=l.replaceAll(n,t);return l=l.replaceAll(tr,(n,t)=>e[Number(t)]??""),l},or=/^(?:explain\s+(?:query\s+plan\s+)?)?(?:select|with)\b/iu,sr=/\b(?:alter|attach|create|delete|detach|drop|insert|pragma|reindex|replace|truncate|update|vacuum)\b/iu,ar=/^\w+/u,ir=/;\s*$/u,cr=/\s/u,dr=(r,e)=>{let l=e+2;for(;l<r.length&&r[l]!==`
3
+ `;)l+=1;return l},ur=(r,e)=>{const l=r.indexOf("*/",e+2);return l===-1?-1:l+2},mr=r=>{let e=0;for(;e<r.length;){const l=r[e];if(l!==void 0&&cr.test(l))e+=1;else if(l==="-"&&r[e+1]==="-")e=dr(r,e);else if(l==="/"&&r[e+1]==="*"){const n=ur(r,e);if(n===-1)break;e=n}else break}return e},fr=r=>{const e=mr(r),l=r.slice(e).trimEnd();if(l==="")return{code:"SQL_EMPTY",message:"the query is empty"};const n=l.replace(ir,""),t=n.indexOf(";");if(t!==-1)return{code:"SQL_MULTIPLE_STATEMENTS",length:1,message:"only a single statement may be run",offset:e+t};const o="the SQL editor is read-only only SELECT / WITH / EXPLAIN queries are allowed";if(!or.test(n))return{code:"SQL_NOT_READONLY",length:ar.exec(n)?.[0].length??1,message:o,offset:e};const a=sr.exec(n);if(a!==null)return{code:"SQL_NOT_READONLY",length:a[0].length,message:`${o} (\`${a[0].toUpperCase()}\` is not allowed)`,offset:e+a.index}},hr=/\b(?:from|join)\s+([a-z_][\w$]*)(?:\s+(?:as\s+)?([a-z_][\w$]*))?/giu,pr=/(?:\bwith\s+(?:recursive\s+)?|,\s*)([a-z_][\w$]*)\s+as\s*\(/giu,br=new Set(["cross","full","group","having","inner","join","left","limit","offset","on","order","right","union","using","where","window"]),gr=/[^\n]/gu,xr=(r,e)=>{const l=r[e];if(l==="'"){let n=e+1;for(;n<r.length&&r[n]!=="'";)n+=1;return Math.min(n+1,r.length)}if(l==="-"&&r[e+1]==="-"){const n=r.indexOf(`
4
+ `,e);return n===-1?r.length:n}if(l==="/"&&r[e+1]==="*"){const n=r.indexOf("*/",e+2);return n===-1?r.length:n+2}return-1},vr=r=>{let e="",l=0;for(;l<r.length;){const n=xr(r,l);n===-1?(e+=r.slice(l,l+1),l+=1):(e+=r.slice(l,n).replaceAll(gr," "),l=n)}return e},yr=r=>{const e=new Set;for(const l of r.matchAll(pr))e.add((l[1]??"").toLowerCase());return e},wr=(r,e)=>{const l=new Map;for(const n of r.matchAll(hr)){const t=(n[1]??"").toLowerCase(),o=(n[2]??"").toLowerCase();e.has(t)&&(l.set(t,t),o!==""&&!br.has(o)&&l.set(o,t))}return l},kl=(r,e)=>{const l=vr(r),n=new Set(e.map(t=>t.toLowerCase()));return{ctes:yr(l),masked:l,targets:wr(l,n)}},Nr=/^(?:__lunora|sqlite_)/iu,kr=/\b(?:from|join)\s+([a-z_][\w$]*)/giu,Sr=/\b([a-z_][\w$]*)\.([a-z_][\w$]*)/giu,qr=new Set(["cross","full","group","having","inner","join","lateral","left","limit","offset","order","right","select","union","where","window"]),$r=(r,e,l)=>{const n=[];for(const t of r.matchAll(kr)){const o=t[1]??"",a=o.toLowerCase();!e.has(a)&&!l.has(a)&&!qr.has(a)&&!Nr.test(o)&&n.push({length:o.length,message:`unknown table \`${o}\``,offset:t.index+t[0].length-o.length,severity:"error",source:"schema"})}return n},Cr=(r,e,l)=>{const n=[],t=new Map;for(const[o,a]of Object.entries(e.columns))t.set(o.toLowerCase(),new Set(a.map(m=>m.toLowerCase())));for(const o of r.matchAll(Sr)){const a=(o[1]??"").toLowerCase(),m=o[2]??"",s=l.get(a),c=s===void 0?void 0:t.get(s);c!==void 0&&!c.has(m.toLowerCase())&&n.push({length:m.length,message:`\`${s??""}\` has no column \`${m}\``,offset:o.index+o[0].length-m.length,severity:"error",source:"schema"})}return n},Lr=(r,e)=>{if(r.trim()==="")return[];const l=fr(r);if(l!==void 0)return l.code==="SQL_EMPTY"?[]:[{length:l.length,message:l.message,offset:l.offset,severity:"error",source:"gate"}];const{ctes:n,masked:t,targets:o}=kl(r,e.tables),a=new Set(e.tables.map(m=>m.toLowerCase()));return[...$r(t,a,n),...Cr(t,e,o)]},Er=jn(zn.lintSql),_r=600,Ir=(r,e,l)=>{const n=ul(),[t,o]=Q([]),a=fl(()=>Lr(r,e),[r,e]),m=Gl(r,_r),s=a.some(b=>b.source==="gate")||m.trim()==="",c=Dl(async b=>{try{const h=await n.query(Er,{sql:m},Mn(l));b.cancelled||o(h.diagnostics??[])}catch{b.cancelled||o([])}},[n,m,l]);An(()=>{if(s){o([]);return}const b={cancelled:!1};return fe(c(b)),()=>{b.cancelled=!0}},[c,s]);const p=m===r;return fl(()=>p?[...a,...t]:a,[a,t,p])},Tr=r=>r==="unsafe-response"?"The model returned a statement that is not read-only, so it was discarded.":r==="empty-response"?"The model returned nothing usable.":"The model could not be reached.",Rr=r=>{const e=J(51),{assistant:l,failed:n,onGenerated:t}=r,o=se(),[a,m]=Q("");if(l.unavailable)return null;let s;e[0]!==l?(s=l.pending("sql"),e[0]=l,e[1]=s):s=e[1];const c=s;let p;if(e[2]!==l||e[3]!==n||e[4]!==t||e[5]!==c||e[6]!==a||e[7]!==o){const b=l.reason("sql");let h;e[9]!==l||e[10]!==n||e[11]!==t||e[12]!==a?(h=L=>{const D=a.trim();D===""&&!L||fe((async()=>{const z=await l.generate(D===""?"fix the failing statement":D,L?n:void 0);z!==void 0&&t(z)})())},e[9]=l,e[10]=n,e[11]=t,e[12]=a,e[13]=h):h=e[13];const f=h;let d;e[14]!==o?(d=o("Describe the query you want"),e[14]=o,e[15]=d):d=e[15];let w;e[16]===Symbol.for("react.memo_cache_sentinel")?(w=L=>{m(L.target.value)},e[16]=w):w=e[16];let y;e[17]!==f?(y=L=>{L.key==="Enter"&&(L.preventDefault(),f(!1))},e[17]=f,e[18]=y):y=e[18];let v;e[19]!==o?(v=o("Describe the query you want"),e[19]=o,e[20]=v):v=e[20];let g;e[21]!==c||e[22]!==a||e[23]!==d||e[24]!==y||e[25]!==v?(g=i(Vl,{"aria-label":d,className:"h-7 flex-1 text-xs","data-testid":"sql-assistant-prompt",disabled:c,onChange:w,onKeyDown:y,placeholder:v,value:a}),e[21]=c,e[22]=a,e[23]=d,e[24]=y,e[25]=v,e[26]=g):g=e[26];const E=c&&"opacity-60";let k;e[27]!==E?(k=ve("rounded-md border border-border px-2 py-1 text-xs outline-none transition-colors hover:bg-accent focus-visible:bg-accent",E),e[27]=E,e[28]=k):k=e[28];let C;e[29]!==c||e[30]!==a?(C=c||a.trim()==="",e[29]=c,e[30]=a,e[31]=C):C=e[31];let q;e[32]!==f?(q=()=>{f(!1)},e[32]=f,e[33]=q):q=e[33];let O;e[34]!==c||e[35]!==o?(O=o(c?"Thinking…":"Draft SQL"),e[34]=c,e[35]=o,e[36]=O):O=e[36];let N;e[37]!==k||e[38]!==C||e[39]!==q||e[40]!==O?(N=i("button",{className:k,"data-testid":"sql-assistant-generate",disabled:C,onClick:q,type:"button",children:O}),e[37]=k,e[38]=C,e[39]=q,e[40]=O,e[41]=N):N=e[41];let M;e[42]!==n||e[43]!==c||e[44]!==f||e[45]!==o?(M=n!==void 0&&i("button",{className:"rounded-md border border-border px-2 py-1 text-xs outline-none transition-colors hover:bg-accent focus-visible:bg-accent","data-testid":"sql-assistant-fix",disabled:c,onClick:()=>{f(!0)},type:"button",children:o("Fix this")}),e[42]=n,e[43]=c,e[44]=f,e[45]=o,e[46]=M):M=e[46];let R;e[47]!==N||e[48]!==M||e[49]!==g?(R=$("div",{className:"flex items-center gap-2",children:[g,N,M]}),e[47]=N,e[48]=M,e[49]=g,e[50]=R):R=e[50],p=$("div",{className:"flex flex-col gap-1 border-b border-border px-3 py-2","data-testid":"sql-assistant",children:[R,b!==void 0&&i("p",{className:"text-[11px] text-muted-foreground","data-testid":"sql-assistant-reason",role:"status",children:Tr(b)})]}),e[2]=l,e[3]=n,e[4]=t,e[5]=c,e[6]=a,e[7]=o,e[8]=p}else p=e[8];return p},Rn=8,Or=["AND","ASC","AS","BY","COUNT","DESC","DISTINCT","EXPLAIN","FROM","GROUP","HAVING","INNER","JOIN","LEFT","LIKE","LIMIT","NOT","NULL","OFFSET","ON","ORDER","OR","QUERY","SELECT","WHERE","WITH"],Mr=new Set(["AND","BY","HAVING","ON","OR","SELECT","WHERE"]),Dr=/[\w$]/,Sl=r=>r!==void 0&&Dr.test(r),ql=r=>{let e=r.length;for(;e>0&&Sl(r[e-1]);)e-=1;return r.slice(e)},$l=(r,e)=>{let l=e;for(;l>0&&Sl(r[l-1]);)l-=1;return{end:e,start:l,text:r.slice(l,e)}},gl=(r,e)=>{const l=r.slice(0,e).trimEnd();return l.endsWith(".")||Mr.has(ql(l).toUpperCase())},Ar=(r,e,l)=>{const n=r.slice(0,e);if(!n.endsWith("."))return;const t=ql(n.slice(0,-1));if(t!=="")return kl(r,l).targets.get(t.toLowerCase())??t},ml=(r,e)=>r.toLowerCase().startsWith(e.toLowerCase()),xl=(r,e,l,n)=>{const t=[];for(const o of r)if(ml(o,e)&&(t.push(n(o)),t.length>=l))break;return t},zr=(r,e,l)=>{const n=new Map;for(const[t,o]of Object.entries(r.columns))for(const a of o)if(ml(a,e)&&!n.has(a)&&(n.set(a,t),n.size>=l))return[...n].map(([m,s])=>({detail:s,kind:"column",label:m}));return[...n].map(([t,o])=>({detail:o,kind:"column",label:t}))},jr=(r,e,l)=>{const n=$l(r,e),t=Ar(r,n.start,l.tables);if(t!==void 0){const s=l.columns[t]??l.columns[t.toLowerCase()]??[];return xl(s,n.text,Rn,c=>({detail:t,kind:"column",label:c}))}if(n.text===""&&!gl(r,n.start))return[];const o=xl(l.tables,n.text,Rn,s=>({kind:"table",label:s})),a=zr(l,n.text,Rn),m=Or.flatMap(s=>n.text!==""&&ml(s,n.text)&&s.toLowerCase()!==n.text.toLowerCase()?[{kind:"keyword",label:s}]:[]);return(gl(r,n.start)?[...a,...o,...m]:[...o,...a,...m]).slice(0,Rn)},Br=(r,e,l)=>{const n=$l(r,e),t=r.slice(0,n.start)+l.label+r.slice(n.end);return{caret:n.start+l.label.length,value:t}},Wr=["boxSizing","borderBottomWidth","borderLeftWidth","borderRightWidth","borderTopWidth","fontFamily","fontSize","fontStyle","fontWeight","letterSpacing","lineHeight","paddingBottom","paddingLeft","paddingRight","paddingTop","tabSize","textIndent","textTransform","width","wordSpacing"],Fr=(r,e)=>{const l=globalThis.getComputedStyle(r),n=globalThis.document.createElement("div"),{style:t}=n;t.position="absolute",t.visibility="hidden",t.whiteSpace="pre-wrap",t.overflowWrap="break-word";for(const s of Wr)t[s]=l[s];n.textContent=r.value.slice(0,Math.max(0,e));const o=globalThis.document.createElement("span");o.textContent=r.value.slice(Math.max(0,e))||".",n.append(o),globalThis.document.body.append(n);const a=o.offsetLeft-r.scrollLeft,m=o.offsetTop-r.scrollTop;return n.remove(),{left:a,top:m}},Pr=(r,e,l)=>{const n=J(13),[t,o]=Q(null);let a;n[0]!==r||n[1]!==e?(a=(w,y)=>{const v=jr(w,y,r);if(v.length===0){o(null);return}const g=e.current,{left:E,top:k}=g===null?{left:0,top:0}:Fr(g,y);o(C=>C!==null&&C.active===0&&C.left===E&&C.top===k&&C.suggestions.length===v.length&&C.suggestions.every((q,O)=>{const N=v.at(O);return q.kind===N?.kind&&q.label===N.label&&q.detail===N.detail})?C:{active:0,left:E,suggestions:v,top:k})},n[0]=r,n[1]=e,n[2]=a):a=n[2];const m=a;let s;n[3]===Symbol.for("react.memo_cache_sentinel")?(s=()=>{o(null)},n[3]=s):s=n[3];const c=s;let p;n[4]===Symbol.for("react.memo_cache_sentinel")?(p=w=>{o(y=>{if(y===null)return y;const v=y.suggestions.length,g=(y.active+w+v)%v;return{...y,active:g}})},n[4]=p):p=n[4];const b=p;let h;n[5]!==l||n[6]!==t||n[7]!==e?(h=()=>{const w=e.current;if(t===null||w===null)return!1;const y=t.suggestions[t.active];if(y===void 0)return!1;const v=Br(w.value,w.selectionStart,y);return l(v.value),o(null),requestAnimationFrame(()=>{const g=e.current;g!==null&&(g.focus(),g.setSelectionRange(v.caret,v.caret))}),!0},n[5]=l,n[6]=t,n[7]=e,n[8]=h):h=n[8];const f=h;let d;return n[9]!==f||n[10]!==m||n[11]!==t?(d={close:c,commit:f,move:b,refresh:m,state:t},n[9]=f,n[10]=m,n[11]=t,n[12]=d):d=n[12],d},Hr={column:"column",keyword:"keyword",table:"table"},Ur=20,Yr=r=>{const e=J(17),{listboxId:l,onPick:n,state:t}=r,o=se();let a;e[0]!==t?(a=t===null?void 0:{left:t.left,top:t.top+Ur},e[0]=t,e[1]=a):a=e[1];const m=a;if(t===null)return null;let s;if(e[2]!==l||e[3]!==n||e[4]!==t.active||e[5]!==t.suggestions||e[6]!==o){let p;e[8]!==l||e[9]!==n||e[10]!==t.active||e[11]!==o?(p=(b,h)=>$("li",{"aria-selected":h===t.active,className:ve("flex cursor-pointer items-center gap-2 px-2 py-1 text-[13px]",h===t.active?"bg-accent text-accent-foreground":"text-foreground"),"data-testid":"sql-autocomplete-item",id:`${l}-opt-${h.toString()}`,onMouseDown:f=>{f.preventDefault(),n(h)},role:"option",children:[i("span",{className:"truncate font-mono",children:b.label}),b.detail!==void 0&&i("span",{className:"ms-auto truncate text-xs text-muted-foreground",children:b.detail}),i("span",{className:"shrink-0 font-mono text-[10px] tracking-wide text-muted-foreground/70 uppercase",children:o(Hr[b.kind])})]},`${b.kind}:${b.label}`),e[8]=l,e[9]=n,e[10]=t.active,e[11]=o,e[12]=p):p=e[12],s=t.suggestions.map(p),e[2]=l,e[3]=n,e[4]=t.active,e[5]=t.suggestions,e[6]=o,e[7]=s}else s=e[7];let c;return e[13]!==l||e[14]!==m||e[15]!==s?(c=i("ul",{className:"absolute z-30 max-h-56 w-72 overflow-auto rounded-md border border-border bg-popover py-1 text-popover-foreground shadow-md","data-testid":"sql-autocomplete",id:l,role:"listbox",style:m,children:s}),e[13]=l,e[14]=m,e[15]=s,e[16]=c):c=e[16],c},Kr=r=>{const e=J(8),{diagnostics:l,draft:n,scrollRef:t}=r;let o,a;if(e[0]!==l||e[1]!==n){a=Symbol.for("react.early_return_sentinel");e:{const c=Xl(l,n.length);if(c.length===0){a=null;break e}o=[];let p=0;for(const[b,h]of c.entries())h.start>p&&o.push(n.slice(p,h.start)),o.push(i("span",{className:ve("decoration-wavy underline underline-offset-4",h.severity==="error"?"decoration-destructive":"decoration-amber-500"),children:n.slice(h.start,h.end)},`${h.start.toString()}-${b.toString()}`)),p=h.end;o.push(n.slice(p))}e[0]=l,e[1]=n,e[2]=o,e[3]=a}else o=e[2],a=e[3];if(a!==Symbol.for("react.early_return_sentinel"))return a;let m;e[4]===Symbol.for("react.memo_cache_sentinel")?(m=ve("pointer-events-none absolute inset-0 overflow-hidden text-transparent",Nl),e[4]=m):m=e[4];let s;return e[5]!==o||e[6]!==t?(s=i("div",{"aria-hidden":"true",className:m,"data-testid":"sql-diagnostics-overlay",ref:t,children:o}),e[5]=o,e[6]=t,e[7]=s):s=e[7],s},Qr={gate:"read-only",plan:"plan",schema:"schema",syntax:"syntax"},Jr=r=>{const e=J(10),{diagnostics:l,onSelect:n}=r,t=se();if(l.length===0)return null;let o;e[0]!==t?(o=t("SQL problems"),e[0]=t,e[1]=o):o=e[1];let a;if(e[2]!==l||e[3]!==n){let s;e[5]!==n?(s=(c,p)=>i("li",{children:$("button",{className:"flex w-full items-start gap-2 px-3 py-1 text-start text-xs outline-none hover:bg-accent focus-visible:bg-accent","data-testid":"sql-problem",onClick:()=>{n(c)},type:"button",children:[i("span",{className:ve("mt-px shrink-0 rounded px-1 font-mono text-[10px] uppercase",c.severity==="error"?"bg-destructive/15 text-destructive":"bg-amber-500/15 text-amber-600"),children:Qr[c.source]}),i("span",{className:"min-w-0 text-muted-foreground",children:c.message})]})},`${c.source}-${(c.offset??p).toString()}-${p.toString()}`),e[5]=n,e[6]=s):s=e[6],a=l.map(s),e[2]=l,e[3]=n,e[4]=a}else a=e[4];let m;return e[7]!==o||e[8]!==a?(m=i("ul",{"aria-label":o,className:"max-h-24 shrink-0 overflow-y-auto border-t border-border bg-muted/30","data-testid":"sql-problems",children:a}),e[7]=o,e[8]=a,e[9]=m):m=e[9],m},Cl=[{label:"List tables",sql:"SELECT name FROM sqlite_master WHERE type = 'table' ORDER BY name;"},{label:"Table row count",sql:"SELECT COUNT(*) AS rows FROM messages;"},{label:"Recent rows",sql:"SELECT id, _creationTime, __doc__ FROM messages ORDER BY _creationTime DESC LIMIT 50;"},{label:"Index list",sql:"SELECT name, tbl_name FROM sqlite_master WHERE type = 'index' ORDER BY tbl_name;"}],Gr=r=>{const e=J(29),{active:l,onDelete:n,onSelect:t,query:o}=r,a=se();let m;e[0]!==t||e[1]!==o.id?(m=()=>{t(o.id)},e[0]=t,e[1]=o.id,e[2]=m):m=e[2];const s=m;let c;e[3]!==n||e[4]!==o.id?(c=q=>{q.stopPropagation(),n(o.id)},e[3]=n,e[4]=o.id,e[5]=c):c=e[5];const p=c,b=l?"bg-sidebar-accent font-medium text-foreground":"text-muted-foreground";let h;e[6]!==b?(h=ve("flex min-w-0 flex-1 items-center gap-2 rounded-md px-2 py-1.5 text-start text-[13px] outline-none transition-colors hover:bg-sidebar-accent focus-visible:bg-sidebar-accent",b),e[6]=b,e[7]=h):h=e[7];const f=`sql-query-${o.id}`;let d;e[8]===Symbol.for("react.memo_cache_sentinel")?(d=i("svg",{"aria-hidden":"true",className:"size-3.5 shrink-0 opacity-70",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:i("path",{d:"M4 6h16M4 12h10M4 18h7"})}),e[8]=d):d=e[8];let w;e[9]!==o.name?(w=i("span",{className:"truncate",children:o.name}),e[9]=o.name,e[10]=w):w=e[10];let y;e[11]!==l||e[12]!==s||e[13]!==h||e[14]!==f||e[15]!==w?(y=$("button",{"aria-pressed":l,className:h,"data-testid":f,onClick:s,type:"button",children:[d,w]}),e[11]=l,e[12]=s,e[13]=h,e[14]=f,e[15]=w,e[16]=y):y=e[16];let v;e[17]!==a?(v=a("Delete query"),e[17]=a,e[18]=v):v=e[18];let g;e[19]!==a?(g=a("Delete query"),e[19]=a,e[20]=g):g=e[20];let E;e[21]===Symbol.for("react.memo_cache_sentinel")?(E=i("svg",{"aria-hidden":"true",className:"size-3.5",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:i("path",{d:"M5 7h14M9 7V5h6v2m-1 0v12H10V7M7 7v13h10V7"})}),e[21]=E):E=e[21];let k;e[22]!==p||e[23]!==g||e[24]!==v?(k=i("button",{"aria-label":v,className:"me-1 hidden size-6 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-destructive/10 hover:text-destructive group-hover/q:flex",onClick:p,title:g,type:"button",children:E}),e[22]=p,e[23]=g,e[24]=v,e[25]=k):k=e[25];let C;return e[26]!==k||e[27]!==y?(C=$("li",{className:"group/q flex items-center",children:[y,k]}),e[26]=k,e[27]=y,e[28]=C):C=e[28],C},Vr=(r,e)=>{const l=e.trim().toLowerCase();return l===""?[...r]:r.filter(n=>n.name.toLowerCase().includes(l))},Xr=r=>{const e=J(60),{activeId:l,history:n,listRef:t,onClearHistory:o,onDelete:a,onLoadHistory:m,onLoadTemplate:s,onNew:c,onSearchChange:p,onSelect:b,queries:h,search:f}=r,d=se();let w,y,v,g;if(e[0]!==l||e[1]!==t||e[2]!==a||e[3]!==c||e[4]!==p||e[5]!==b||e[6]!==h||e[7]!==f||e[8]!==d){const L=Vr(h,f);y="flex h-full w-64 shrink-0 flex-col border-e border-border bg-sidebar";let D;e[13]!==d?(D=d("Search queries…"),e[13]=d,e[14]=D):D=e[14];let z;e[15]!==p||e[16]!==f||e[17]!==D?(z=i("input",{className:"h-8 min-w-0 flex-1 rounded-md border border-border bg-background px-2 text-xs outline-none focus-visible:border-ring","data-testid":"sql-search",onChange:p,placeholder:D,type:"text",value:f}),e[15]=p,e[16]=f,e[17]=D,e[18]=z):z=e[18];let j;e[19]!==d?(j=d("New query"),e[19]=d,e[20]=j):j=e[20];let U;e[21]!==d?(U=d("New query"),e[21]=d,e[22]=U):U=e[22];let A;e[23]===Symbol.for("react.memo_cache_sentinel")?(A=i("svg",{"aria-hidden":"true",className:"size-4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.7,viewBox:"0 0 24 24",children:i("path",{d:"M12 5v14M5 12h14"})}),e[23]=A):A=e[23];let Y;e[24]!==c||e[25]!==j||e[26]!==U?(Y=i("button",{"aria-label":j,className:"flex size-8 shrink-0 items-center justify-center rounded-md border border-border text-foreground outline-none transition-colors hover:bg-accent focus-visible:bg-accent","data-testid":"sql-new",onClick:c,title:U,type:"button",children:A}),e[24]=c,e[25]=j,e[26]=U,e[27]=Y):Y=e[27],e[28]!==Y||e[29]!==z?(v=$("div",{className:"flex shrink-0 items-center gap-2 border-b border-border p-2",children:[z,Y]}),e[28]=Y,e[29]=z,e[30]=v):v=e[30],w="flex flex-1 flex-col gap-4 overflow-y-auto p-2";let B;e[31]!==d?(B=d("Private"),e[31]=d,e[32]=B):B=e[32];let W;e[33]!==B?(W=i("p",{className:"px-1 pb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:B}),e[33]=B,e[34]=W):W=e[34],g=$("div",{children:[W,L.length===0?i("p",{className:"px-1 py-2 text-xs text-muted-foreground","data-testid":"sql-private-empty",children:d("No saved queries yet — they save to this browser as you type.")}):i("ul",{className:"flex flex-col gap-px","data-testid":"sql-private",ref:t,children:L.map(_=>i(Gr,{active:l===_.id,onDelete:a,onSelect:b,query:_},_.id))})]}),e[0]=l,e[1]=t,e[2]=a,e[3]=c,e[4]=p,e[5]=b,e[6]=h,e[7]=f,e[8]=d,e[9]=w,e[10]=y,e[11]=v,e[12]=g}else w=e[9],y=e[10],v=e[11],g=e[12];let E;e[35]!==d?(E=d("Reference"),e[35]=d,e[36]=E):E=e[36];let k;e[37]!==E?(k=i("p",{className:"px-1 pb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:E}),e[37]=E,e[38]=k):k=e[38];let C;e[39]!==s?(C=Cl.map(L=>i("li",{children:$("button",{className:"flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-start text-[13px] text-muted-foreground outline-none transition-colors hover:bg-sidebar-accent hover:text-foreground focus-visible:bg-sidebar-accent","data-sql":L.sql,onClick:s,type:"button",children:[i("svg",{"aria-hidden":"true",className:"size-3.5 shrink-0 opacity-70",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:i("path",{d:"M7 4h7l4 4v12H7zM14 4v4h4"})}),L.label]})},L.label)),e[39]=s,e[40]=C):C=e[40];let q;e[41]!==C?(q=i("ul",{className:"flex flex-col gap-px",children:C}),e[41]=C,e[42]=q):q=e[42];let O;e[43]!==k||e[44]!==q?(O=$("div",{children:[k,q]}),e[43]=k,e[44]=q,e[45]=O):O=e[45];let N;e[46]!==n||e[47]!==o||e[48]!==m||e[49]!==d?(N=n.length>0&&$("div",{children:[$("div",{className:"flex items-center justify-between px-1 pb-1",children:[i("p",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:d("History")}),i("button",{className:"rounded px-1 text-[11px] text-muted-foreground outline-none transition-colors hover:text-foreground focus-visible:text-foreground","data-testid":"sql-history-clear",onClick:o,type:"button",children:d("Clear history")})]}),i("ul",{className:"flex flex-col gap-px","data-testid":"sql-history",children:n.map(L=>i("li",{children:$("button",{className:"flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-start text-[13px] text-muted-foreground outline-none transition-colors hover:bg-sidebar-accent hover:text-foreground focus-visible:bg-sidebar-accent","data-sql":L.sql,"data-testid":"sql-history-item",onClick:m,title:L.sql,type:"button",children:[i("svg",{"aria-hidden":"true",className:"size-3.5 shrink-0 opacity-70",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:i("path",{d:"M12 8v4l3 2M12 21a9 9 0 1 1 0-18 9 9 0 0 1 0 18Z"})}),i("span",{className:"truncate font-mono",children:L.sql})]})},`${L.at.toString()}:${L.sql}`))})]}),e[46]=n,e[47]=o,e[48]=m,e[49]=d,e[50]=N):N=e[50];let M;e[51]!==w||e[52]!==N||e[53]!==g||e[54]!==O?(M=$("div",{className:w,children:[g,O,N]}),e[51]=w,e[52]=N,e[53]=g,e[54]=O,e[55]=M):M=e[55];let R;return e[56]!==M||e[57]!==y||e[58]!==v?(R=$("aside",{className:y,children:[v,M]}),e[56]=M,e[57]=y,e[58]=v,e[59]=R):R=e[59],R},Zr=jn(zn.listTables),eo=jn(zn.readTablePage),to=r=>{const e=J(16),l=ul();let n;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=[],e[0]=n):n=e[0];const[t,o]=Q(n);let a;e[1]===Symbol.for("react.memo_cache_sentinel")?(a={},e[1]=a):a=e[1];const[m,s]=Q(a);let c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c=new Set,e[2]=c):c=e[2];const p=Dt(c);let b,h;e[3]!==l||e[4]!==r?(b=()=>{const g={cancelled:!1};return fe((async()=>{try{const E=await l.query(Zr,{},Mn(r));g.cancelled||(o(E.map(lo)),s({}),p.current=new Set)}catch{g.cancelled||(o([]),s({}),p.current=new Set)}})()),()=>{g.cancelled=!0}},h=[l,r],e[3]=l,e[4]=r,e[5]=b,e[6]=h):(b=e[5],h=e[6]),An(b,h);let f;e[7]!==l||e[8]!==r?(f=g=>{p.current.has(g)||(p.current.add(g),fe((async()=>{try{const E=await l.query(eo,{limit:1,offset:0,table:g},Mn(r));s(k=>({...k,[g]:E.columns}))}catch{p.current.delete(g)}})()))},e[7]=l,e[8]=r,e[9]=f):f=e[9];const d=f;let w;e[10]!==m||e[11]!==t?(w={columns:m,tables:t},e[10]=m,e[11]=t,e[12]=w):w=e[12];const y=w;let v;return e[13]!==d||e[14]!==y?(v={probe:d,schema:y},e[13]=d,e[14]=y,e[15]=v):v=e[15],v},il=/\b(?:from|join|update|into)\s+([a-z_][\w$]*)|\b([a-z_][\w$]*)\s*\./gi,no=r=>{const e=new Set;il.lastIndex=0;let l=il.exec(r);for(;l!==null;)e.add(l[1]??l[2]),l=il.exec(r);return[...e]};function lo(r){return r.name}const ro="lunora-studio-sql-tabs",oo="lunora-studio-sql-active-tab",dl=12,At=(r="",e="")=>({activeId:null,id:yl("tab"),name:e,sql:r}),so=()=>wl(oo,""),ao=r=>{const e=J(16),[l,n]=cl(ro),[t,o]=so(),[a]=Q(r);let m,s;e[0]!==a||e[1]!==n||e[2]!==l.length?(m=()=>{l.length===0&&n([a])},s=[a,n,l.length],e[0]=a,e[1]=n,e[2]=l.length,e[3]=m,e[4]=s):(m=e[3],s=e[4]),An(m,s);let c;e[5]!==a||e[6]!==l?(c=l.length===0?[a]:l,e[5]=a,e[6]=l,e[7]=c):c=e[7];const p=c;let b;e[8]!==t||e[9]!==p?(b=p.some(d=>d.id===t)?t:p[0]?.id??"",e[8]=t,e[9]=p,e[10]=b):b=e[10];const h=b;let f;return e[11]!==h||e[12]!==o||e[13]!==n||e[14]!==p?(f={activeId:h,setActiveId:o,setTabs:n,tabs:p},e[11]=h,e[12]=o,e[13]=n,e[14]=p,e[15]=f):f=e[15],f},Ll=r=>r.activeId===null&&r.sql.trim()!=="",io=(r,e)=>[...r,e].slice(-dl),co=(r,e,l)=>{const n=r.findIndex(o=>o.id===e);if(n===-1)return{activeId:r[0]?.id??"",tabs:[...r]};const t=r.filter(o=>o.id!==e);if(t.length===0){const o=l();return{activeId:o.id,tabs:[o]}}return{activeId:t[Math.min(n,t.length-1)].id,tabs:t}},uo=(r,e)=>{const l=r.filter(n=>n.id===e);return l.length===0?{activeId:r[0]?.id??"",tabs:[...r]}:{activeId:e,tabs:l}},mo=(r,e,l)=>{const n=r.findIndex(o=>o.id===e);if(n===-1)return{activeId:l,tabs:[...r]};const t=r.slice(0,n+1);return{activeId:t.some(o=>o.id===l)?l:e,tabs:t}},fo=r=>{const e=r();return{activeId:e.id,tabs:[e]}},ho=(r,e,l)=>{if(r==="others")return e.filter(n=>n.id!==l);if(r==="right"){const n=e.findIndex(t=>t.id===l);return n===-1?[]:e.slice(n+1)}return[...e]},po=(r,e)=>r.trim()===""?e:(r.split(`
5
+ `)[0]??r).slice(0,24),bo=r=>{r?.focus(),r?.select()},go=r=>{const e=J(14),{initial:l,onCancel:n,onCommit:t,placeholder:o,testId:a}=r,m=se();let s;e[0]!==t?(s=d=>{t(d.currentTarget.value.trim())},e[0]=t,e[1]=s):s=e[1];const c=s;let p;e[2]!==n||e[3]!==t?(p=d=>{d.key==="Enter"?t(d.currentTarget.value.trim()):d.key==="Escape"&&n()},e[2]=n,e[3]=t,e[4]=p):p=e[4];const b=p;let h;e[5]!==m?(h=m("Tab title"),e[5]=m,e[6]=h):h=e[6];let f;return e[7]!==l||e[8]!==c||e[9]!==b||e[10]!==o||e[11]!==h||e[12]!==a?(f=i("input",{"aria-label":h,className:"w-40 rounded border border-ring bg-background px-1 py-0.5 text-xs outline-none","data-testid":a,defaultValue:l,onBlur:c,onKeyDown:b,placeholder:o,ref:bo,type:"text"}),e[7]=l,e[8]=c,e[9]=b,e[10]=o,e[11]=h,e[12]=a,e[13]=f):f=e[13],f},xo=r=>{const e=J(29),{idBase:l,onDiscard:n,onKeep:t}=r,o=se(),a=`sql-tab-close-prompt-${l}`;let m;e[0]!==o?(m=o("Discard?"),e[0]=o,e[1]=m):m=e[1];let s;e[2]!==m?(s=i("span",{className:"text-[11px] text-muted-foreground",children:m}),e[2]=m,e[3]=s):s=e[3];let c;e[4]!==o?(c=o("Discard changes"),e[4]=o,e[5]=c):c=e[5];const p=`sql-tab-close-confirm-${l}`;let b;e[6]!==o?(b=o("Discard changes"),e[6]=o,e[7]=b):b=e[7];let h;e[8]===Symbol.for("react.memo_cache_sentinel")?(h=i("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2.4,viewBox:"0 0 24 24",children:i("path",{d:"M5 13l4 4L19 7"})}),e[8]=h):h=e[8];let f;e[9]!==n||e[10]!==c||e[11]!==p||e[12]!==b?(f=i("button",{"aria-label":c,className:"flex size-5 items-center justify-center rounded text-destructive hover:bg-destructive/10","data-testid":p,onClick:n,title:b,type:"button",children:h}),e[9]=n,e[10]=c,e[11]=p,e[12]=b,e[13]=f):f=e[13];let d;e[14]!==o?(d=o("Keep editing"),e[14]=o,e[15]=d):d=e[15];const w=`sql-tab-close-cancel-${l}`;let y;e[16]!==o?(y=o("Keep editing"),e[16]=o,e[17]=y):y=e[17];let v;e[18]===Symbol.for("react.memo_cache_sentinel")?(v=i("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2.4,viewBox:"0 0 24 24",children:i("path",{d:"M6 6l12 12M18 6 6 18"})}),e[18]=v):v=e[18];let g;e[19]!==t||e[20]!==w||e[21]!==y||e[22]!==d?(g=i("button",{"aria-label":d,className:"flex size-5 items-center justify-center rounded text-muted-foreground hover:bg-accent","data-testid":w,onClick:t,title:y,type:"button",children:v}),e[19]=t,e[20]=w,e[21]=y,e[22]=d,e[23]=g):g=e[23];let E;return e[24]!==a||e[25]!==g||e[26]!==s||e[27]!==f?(E=$("span",{className:"flex shrink-0 items-center gap-1","data-testid":a,role:"group",children:[s,f,g]}),e[24]=a,e[25]=g,e[26]=s,e[27]=f,e[28]=E):E=e[28],E},vo=r=>{const e=J(47),{active:l,canClose:n,onClose:t,onMenu:o,onRename:a,onSelect:m,tab:s}=r,c=se(),[p,b]=Q(!1),[h,f]=Q(!1);let d;e[0]!==o||e[1]!==s.id?(d=G=>{o(s.id,G)},e[0]=o,e[1]=s.id,e[2]=d):d=e[2];const w=d;let y;e[3]!==m||e[4]!==s.id?(y=()=>{m(s.id)},e[3]=m,e[4]=s.id,e[5]=y):y=e[5];const v=y;let g;e[6]===Symbol.for("react.memo_cache_sentinel")?(g=()=>{b(!0)},e[6]=g):g=e[6];const E=g;let k;e[7]!==t||e[8]!==s?(k=G=>{G.stopPropagation(),Ll(s)?f(!0):t(s.id)},e[7]=t,e[8]=s,e[9]=k):k=e[9];const C=k;let q;e[10]!==t||e[11]!==s.id?(q=G=>{G.stopPropagation(),f(!1),t(s.id)},e[10]=t,e[11]=s.id,e[12]=q):q=e[12];const O=q;let N;e[13]===Symbol.for("react.memo_cache_sentinel")?(N=G=>{G.stopPropagation(),f(!1)},e[13]=N):N=e[13];const M=N;let R;e[14]!==a||e[15]!==s.id?(R=G=>{a(s.id,G),b(!1)},e[14]=a,e[15]=s.id,e[16]=R):R=e[16];const L=R;let D;e[17]===Symbol.for("react.memo_cache_sentinel")?(D=()=>{b(!1)},e[17]=D):D=e[17];const z=D;let j;e[18]!==s.name?(j=s.name.trim(),e[18]=s.name,e[19]=j):j=e[19];const U=j;let A;e[20]!==c||e[21]!==s.sql?(A=po(s.sql,c("Untitled")),e[20]=c,e[21]=s.sql,e[22]=A):A=e[22];const Y=A,B=l?"bg-background text-foreground":"bg-muted/40 text-muted-foreground hover:text-foreground";let W;e[23]!==B?(W=ve("group/tab flex shrink-0 items-center gap-1 border-e border-border ps-3 pe-1.5 text-xs",B),e[23]=B,e[24]=W):W=e[24];const _=`sql-tab-${s.id}`;let T;e[25]!==l||e[26]!==L||e[27]!==U||e[28]!==Y||e[29]!==p||e[30]!==v||e[31]!==c||e[32]!==s.id?(T=p?i(go,{initial:U,onCancel:z,onCommit:L,placeholder:Y,testId:`sql-tab-rename-${s.id}`}):i("button",{"aria-pressed":l,className:"max-w-40 truncate py-1.5 outline-none","data-testid":`sql-tab-select-${s.id}`,onClick:v,onDoubleClick:E,title:c("Double-click to rename"),type:"button",children:U===""?Y:U}),e[25]=l,e[26]=L,e[27]=U,e[28]=Y,e[29]=p,e[30]=v,e[31]=c,e[32]=s.id,e[33]=T):T=e[33];let F;e[34]!==n||e[35]!==O||e[36]!==h||e[37]!==C||e[38]!==c||e[39]!==s.id?(F=n&&(h?i(xo,{idBase:s.id,onDiscard:O,onKeep:M}):i("button",{"aria-label":c("Close tab"),className:"flex size-5 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-destructive/10 hover:text-destructive","data-testid":`sql-tab-close-${s.id}`,onClick:C,title:c("Close tab"),type:"button",children:i("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,viewBox:"0 0 24 24",children:i("path",{d:"M6 6l12 12M18 6 6 18"})})})),e[34]=n,e[35]=O,e[36]=h,e[37]=C,e[38]=c,e[39]=s.id,e[40]=F):F=e[40];let he;return e[41]!==w||e[42]!==W||e[43]!==_||e[44]!==T||e[45]!==F?(he=$("div",{className:W,"data-testid":_,onContextMenu:w,children:[T,F]}),e[41]=w,e[42]=W,e[43]=_,e[44]=T,e[45]=F,e[46]=he):he=e[46],he},yo=jn(zn.runSql),wo="lunora-studio-sql-queries",No="lunora-studio-sql-history",ko="lunora-studio-sql-split-view",So=25,qo={minWidth:"2.75rem",paddingInline:"0.5rem"},vl={error:null,pane:"results",result:null},$o=r=>{const e=J(16),{result:l}=r;if(l.columns.length===0){const s=l.rowCount===0?"0 rows":"";let c;return e[0]!==s?(c=i("p",{className:"p-4 text-sm text-muted-foreground",children:s}),e[0]=s,e[1]=c):c=e[1],c}let n;e[2]!==l.columns?(n=l.columns.map(Lo),e[2]=l.columns,e[3]=n):n=e[3];let t;e[4]!==n?(t=i(Wl,{className:"sticky top-0 z-10 bg-muted",children:i(hl,{children:n})}),e[4]=n,e[5]=t):t=e[5];let o;if(e[6]!==l.columns||e[7]!==l.rows){let s;e[9]!==l.columns?(s=(c,p)=>i(hl,{"data-testid":"sql-row",children:l.columns.map(b=>i(Ul,{className:"max-w-md truncate font-mono text-xs",children:i(Kl,{value:c[b]})},b))},p),e[9]=l.columns,e[10]=s):s=e[10],o=l.rows.map(s),e[6]=l.columns,e[7]=l.rows,e[8]=o}else o=e[8];let a;e[11]!==o?(a=i(Fl,{children:o}),e[11]=o,e[12]=a):a=e[12];let m;return e[13]!==t||e[14]!==a?(m=$(Pl,{"data-testid":"sql-rows",children:[t,a]}),e[13]=t,e[14]=a,e[15]=m):m=e[15],m},On=r=>`border-b-2 px-3 py-2 text-sm outline-none transition-colors ${r?"border-foreground font-medium text-foreground":"border-transparent text-muted-foreground hover:text-foreground"}`,Co=()=>At(Cl[0]?.sql??""),Vo=r=>{const e=J(368),{initialShardKey:l}=r,n=ul(),t=se(),[o,a]=cl(wo),[m,s]=cl(No),[c,p]=Q(""),{activeId:b,setActiveId:h,setTabs:f,tabs:d}=ao(Co);let w;e[0]===Symbol.for("react.memo_cache_sentinel")?(w={},e[0]=w):w=e[0];const[y,v]=Q(w),[g,E]=Q(l??""),[k,C]=Q(!1),[q,O]=wl(ko,!1),[N,M]=Q(null),[R,L]=Q(null),D=Dt(null),z=Dt(null),j=Dt(null),U=Dt(null),A=Al(),{probe:Y,schema:B}=to(g);let W;e[1]!==b||e[2]!==d?(W=d.find(u=>u.id===b)??d[0]??At(),e[1]=b,e[2]=d,e[3]=W):W=e[3];const _=W,T=_.sql,{activeId:F}=_,he=y[_.id]??vl,{chart:G,error:ne,failed:kt,result:I}=he,X=he.pane;let zt;e[4]!==_.id||e[5]!==f?(zt=u=>{f(x=>x.map(S=>S.id===_.id?{...S,...u}:S))},e[4]=_.id,e[5]=f,e[6]=zt):zt=e[6];const Bn=zt;let jt;e[7]!==_.id?(jt=u=>{v(x=>{const S=x[_.id]??vl;return{...x,[_.id]:{...S,...u}}})},e[7]=_.id,e[8]=jt):jt=e[8];const P=jt;let Bt;e[9]!==F||e[10]!==Bn||e[11]!==a?(Bt=u=>{Bn({sql:u}),F!==null&&a(x=>x.map(S=>S.id===F?{...S,sql:u}:S))},e[9]=F,e[10]=Bn,e[11]=a,e[12]=Bt):Bt=e[12];const Z=Bt,ye=Ir(T,B,g),V=Jl(g);let Wt;e[13]!==V||e[14]!==P||e[15]!==I?(Wt=()=>{I!==null&&fe((async()=>{const u=await V.inferChart({columns:I.columns,rowCount:I.rowCount,types:Object.fromEntries(I.columns.map(x=>[x,typeof(I.rows[0]?.[x]??"")]))});P({chart:u})})())},e[13]=V,e[14]=P,e[15]=I,e[16]=Wt):Wt=e[16];const Wn=Wt,El=Pr(B,j,Z),{close:le,commit:we,move:pe,refresh:ee,state:K}=El;let Ft;e[17]!==K?.active||e[18]!==we||e[19]!==pe?(Ft=u=>{pe(u-(K?.active??0)),we()},e[17]=K?.active,e[18]=we,e[19]=pe,e[20]=Ft):Ft=e[20];const Fn=Ft;let Pt;e[21]!==ee?(Pt=()=>{const u=j.current;u!==null&&u===document.activeElement&&ee(u.value,u.selectionStart)},e[21]=ee,e[22]=Pt):Pt=e[22];let Ht;e[23]!==ee||e[24]!==B?(Ht=[ee,B],e[23]=ee,e[24]=B,e[25]=Ht):Ht=e[25],An(Pt,Ht);let Ut;e[26]!==s?(Ut=u=>{s(x=>x[0]?.sql===u?x:[{at:Date.now(),sql:u},...x.filter(S=>S.sql!==u)].slice(0,So))},e[26]=s,e[27]=Ut):Ut=e[27];const Pn=Ut;let Yt;e[28]!==n||e[29]!==T||e[30]!==P||e[31]!==Pn||e[32]!==g?(Yt=async u=>{if(T.trim()==="")return;C(!0);const x=u==="explain"?`EXPLAIN QUERY PLAN ${T}`:T;try{const S=await n.query(yo,{sql:x},Mn(g));P({chart:void 0,error:null,failed:void 0,pane:u,result:S}),Yl(g),Pn(x)}catch(S){const H=S;P({chart:void 0,error:pl(H),failed:{error:pl(H),sql:x},pane:u,result:null})}C(!1)},e[28]=n,e[29]=T,e[30]=P,e[31]=Pn,e[32]=g,e[33]=Yt):Yt=e[33];const re=Yt;let Kt;e[34]!==re?(Kt=()=>{fe(re("results"))},e[34]=re,e[35]=Kt):Kt=e[35];const Hn=Kt;let Qt;e[36]!==Y||e[37]!==ee||e[38]!==Z?(Qt=u=>{const{selectionStart:x,value:S}=u.target;Z(S);for(const H of no(S))Y(H);ee(S,x)},e[36]=Y,e[37]=ee,e[38]=Z,e[39]=Qt):Qt=e[39];const Un=Qt;let Jt;e[40]!==ee?(Jt=u=>{const x=u.currentTarget;ee(x.value,x.selectionStart)},e[40]=ee,e[41]=Jt):Jt=e[41];const Yn=Jt;let Gt;e[42]!==K||e[43]!==le||e[44]!==we||e[45]!==pe||e[46]!==re||e[47]!==X?(Gt=u=>{if(K!==null){if(u.key==="ArrowDown"){u.preventDefault(),pe(1);return}if(u.key==="ArrowUp"){u.preventDefault(),pe(-1);return}if(u.key==="Escape"){u.preventDefault(),le();return}if((u.key==="Enter"||u.key==="Tab")&&!u.metaKey&&!u.ctrlKey&&we()){u.preventDefault();return}}(u.metaKey||u.ctrlKey)&&u.key==="Enter"&&(u.preventDefault(),fe(re(X)))},e[42]=K,e[43]=le,e[44]=we,e[45]=pe,e[46]=re,e[47]=X,e[48]=Gt):Gt=e[48];const Kn=Gt;let Vt;e[49]!==le?(Vt=()=>{requestAnimationFrame(()=>{le()})},e[49]=le,e[50]=Vt):Vt=e[50];const Qn=Vt;let Xt;e[51]===Symbol.for("react.memo_cache_sentinel")?(Xt=u=>{const{scrollLeft:x,scrollTop:S}=u.currentTarget;D.current!==null&&(D.current.scrollTop=S),z.current!==null&&(z.current.scrollTop=S,z.current.scrollLeft=x)},e[51]=Xt):Xt=e[51];const _l=Xt;let Zt;e[52]===Symbol.for("react.memo_cache_sentinel")?(Zt=u=>{const x=j.current;x===null||u.offset===void 0||(x.focus(),x.setSelectionRange(u.offset,u.offset+(u.length??0)))},e[52]=Zt):Zt=e[52];const Il=Zt;let en;e[53]!==_.id||e[54]!==P||e[55]!==f?(en=(u,x)=>{f(S=>S.map(H=>H.id===_.id?{...H,activeId:x,sql:u}:H)),P({chart:void 0,error:null,failed:void 0,result:null})},e[53]=_.id,e[54]=P,e[55]=f,e[56]=en):en=e[56];const te=en;let tn;e[57]!==te||e[58]!==a||e[59]!==t?(tn=()=>{const u={id:yl("q"),name:t("Untitled query"),sql:""};a(x=>[u,...x]),te("",u.id)},e[57]=te,e[58]=a,e[59]=t,e[60]=tn):tn=e[60];const St=tn;let nn;e[61]!==te||e[62]!==o?(nn=u=>{const x=o.find(S=>S.id===u);x!==void 0&&(te(x.sql,u),U.current?.querySelector(`[data-testid="sql-query-${u}"]`)?.scrollIntoView({block:"nearest"}))},e[61]=te,e[62]=o,e[63]=nn):nn=e[63];const qt=nn;let ln;e[64]!==a||e[65]!==f?(ln=u=>{a(x=>x.filter(S=>S.id!==u)),f(x=>x.map(S=>S.activeId===u?{...S,activeId:null}:S))},e[64]=a,e[65]=f,e[66]=ln):ln=e[66];const $t=ln;let rn;e[67]!==te?(rn=u=>{te(u.currentTarget.dataset.sql??"",null)},e[67]=te,e[68]=rn):rn=e[68];const Ct=rn;let on;e[69]!==te?(on=u=>{te(u.currentTarget.dataset.sql??"",null)},e[69]=te,e[70]=on):on=e[70];const Lt=on;let sn;e[71]!==s?(sn=()=>{s([])},e[71]=s,e[72]=sn):sn=e[72];const Et=sn;let an;e[73]!==T||e[74]!==Z?(an=()=>{Z(rr(T))},e[73]=T,e[74]=Z,e[75]=an):an=e[75];const Jn=an;let cn;e[76]!==h||e[77]!==f||e[78]!==d.length?(cn=()=>{if(d.length>=dl)return;const u=At();f(x=>io(x,u)),h(u.id)},e[76]=h,e[77]=f,e[78]=d.length,e[79]=cn):cn=e[79];const _t=cn;let dn;e[80]!==h||e[81]!==f?(dn=u=>{M(null),L(null),f(u.tabs),h(u.activeId);const x=new Set(u.tabs.map(Eo));v(S=>Object.fromEntries(Object.entries(S).filter(H=>{const[ue]=H;return x.has(ue)})))},e[80]=h,e[81]=f,e[82]=dn):dn=e[82];const Ne=dn;let un;e[83]!==Ne||e[84]!==d?(un=u=>{Ne(co(d,u,At))},e[83]=Ne,e[84]=d,e[85]=un):un=e[85];const be=un;let mn;e[86]!==b||e[87]!==Ne||e[88]!==d?(mn=(u,x)=>{Ne(u==="others"?uo(d,x):u==="right"?mo(d,x,b):fo(At))},e[86]=b,e[87]=Ne,e[88]=d,e[89]=mn):mn=e[89];const ke=mn;let fn;e[90]!==ke||e[91]!==N||e[92]!==d?(fn=u=>{N!==null&&(ho(u,d,N.id).some(_o)?L(u):ke(u,N.id))},e[90]=ke,e[91]=N,e[92]=d,e[93]=fn):fn=e[93];const oe=fn;let hn;e[94]===Symbol.for("react.memo_cache_sentinel")?(hn=(u,x)=>{x.preventDefault(),L(null),M({id:u,x:x.clientX,y:x.clientY})},e[94]=hn):hn=e[94];const Tl=hn;let pn;e[95]===Symbol.for("react.memo_cache_sentinel")?(pn=()=>{M(null),L(null)},e[95]=pn):pn=e[95];const Rl=pn;let bn;e[96]===Symbol.for("react.memo_cache_sentinel")?(bn=u=>{u.preventDefault(),M(null),L(null)},e[96]=bn):bn=e[96];const Ol=bn;let gn;e[97]!==oe?(gn=()=>{oe("others")},e[97]=oe,e[98]=gn):gn=e[98];const It=gn;let xn;e[99]!==oe?(xn=()=>{oe("right")},e[99]=oe,e[100]=xn):xn=e[100];const Tt=xn;let vn;e[101]!==oe?(vn=()=>{oe("all")},e[101]=oe,e[102]=vn):vn=e[102];const Rt=vn;let yn;e[103]!==ke||e[104]!==R||e[105]!==N?(yn=()=>{N!==null&&R!==null&&ke(R,N.id),L(null)},e[103]=ke,e[104]=R,e[105]=N,e[106]=yn):yn=e[106];const Ot=yn;let wn;e[107]===Symbol.for("react.memo_cache_sentinel")?(wn=()=>{L(null)},e[107]=wn):wn=e[107];const Ml=wn;let Nn;e[108]!==N?(Nn=N===null?void 0:{left:N.x,top:N.y},e[108]=N,e[109]=Nn):Nn=e[109];const Mt=Nn;let kn;e[110]!==le||e[111]!==h?(kn=u=>{le(),h(u)},e[110]=le,e[111]=h,e[112]=kn):kn=e[112];const ge=kn;let Sn;e[113]!==f?(Sn=(u,x)=>{f(S=>S.map(H=>H.id===u?{...H,name:x}:H))},e[113]=f,e[114]=Sn):Sn=e[114];const xe=Sn;let qn;e[115]!==P?(qn=()=>{P({pane:"results"})},e[115]=P,e[116]=qn):qn=e[116];const Gn=qn;let $n;e[117]!==re?($n=()=>{fe(re("explain"))},e[117]=re,e[118]=$n):$n=e[118];const Vn=$n;let Cn;e[119]!==P?(Cn=()=>{P({pane:"chart"})},e[119]=P,e[120]=Cn):Cn=e[120];const Xn=Cn;let Ln;e[121]!==O||e[122]!==q?(Ln=()=>{O(!q)},e[121]=O,e[122]=q,e[123]=Ln):Ln=e[123];const Zn=Ln;let Se,qe,$e,Ce,Le,Ee,_e,Ie,ae,Te,Re,ie,ce,Oe,Me,de;if(e[124]!==F||e[125]!==_.id||e[126]!==_t||e[127]!==V||e[128]!==Et||e[129]!==be||e[130]!==Ot||e[131]!==$t||e[132]!==T||e[133]!==kt||e[134]!==m||e[135]!==Lt||e[136]!==Ct||e[137]!==St||e[138]!==Rt||e[139]!==It||e[140]!==Tt||e[141]!==R||e[142]!==o||e[143]!==xe||e[144]!==c||e[145]!==qt||e[146]!==ge||e[147]!==Z||e[148]!==q||e[149]!==t||e[150]!==N||e[151]!==Mt||e[152]!==d){const u=T.split(`
6
+ `).length;let x;e[169]===Symbol.for("react.memo_cache_sentinel")?(x=me=>{p(me.target.value)},e[169]=x):x=e[169];const S=x,H=q?"flex min-h-0 flex-1 flex-row":"flex min-h-0 flex-1 flex-col";Se=q?"flex w-2/5 min-h-0 min-w-0 shrink-0 flex-col border-s border-border":"flex h-2/5 min-h-0 shrink-0 flex-col border-t border-border",Oe="flex h-full min-w-0",Me="lunora-sql-editor",e[170]!==F||e[171]!==Et||e[172]!==$t||e[173]!==m||e[174]!==Lt||e[175]!==Ct||e[176]!==St||e[177]!==o||e[178]!==c||e[179]!==qt?(de=i(Xr,{activeId:F,history:m,listRef:U,onClearHistory:Et,onDelete:$t,onLoadHistory:Lt,onLoadTemplate:Ct,onNew:St,onSearchChange:S,onSelect:qt,queries:o,search:c}),e[170]=F,e[171]=Et,e[172]=$t,e[173]=m,e[174]=Lt,e[175]=Ct,e[176]=St,e[177]=o,e[178]=c,e[179]=qt,e[180]=de):de=e[180],Re="flex min-w-0 flex-1 flex-col";let ue;if(e[181]!==_.id||e[182]!==be||e[183]!==xe||e[184]!==ge||e[185]!==d){let me;e[187]!==_.id||e[188]!==be||e[189]!==xe||e[190]!==ge||e[191]!==d.length?(me=al=>i(vo,{active:al.id===_.id,canClose:d.length>1,onClose:be,onMenu:Tl,onRename:xe,onSelect:ge,tab:al},al.id),e[187]=_.id,e[188]=be,e[189]=xe,e[190]=ge,e[191]=d.length,e[192]=me):me=e[192],ue=d.map(me),e[181]=_.id,e[182]=be,e[183]=xe,e[184]=ge,e[185]=d,e[186]=ue}else ue=e[186];let yt;e[193]!==t?(yt=t("New tab"),e[193]=t,e[194]=yt):yt=e[194];const sl=d.length>=dl;let wt;e[195]!==t?(wt=t("New tab"),e[195]=t,e[196]=wt):wt=e[196];let Tn;e[197]===Symbol.for("react.memo_cache_sentinel")?(Tn=i("svg",{"aria-hidden":"true",className:"size-4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.7,viewBox:"0 0 24 24",children:i("path",{d:"M12 5v14M5 12h14"})}),e[197]=Tn):Tn=e[197];let Nt;e[198]!==_t||e[199]!==yt||e[200]!==sl||e[201]!==wt?(Nt=i("button",{"aria-label":yt,className:"flex size-8 shrink-0 items-center justify-center text-muted-foreground outline-none transition-colors hover:bg-accent hover:text-foreground focus-visible:bg-accent disabled:pointer-events-none disabled:opacity-40","data-testid":"sql-tab-add",disabled:sl,onClick:_t,title:wt,type:"button",children:Tn}),e[198]=_t,e[199]=yt,e[200]=sl,e[201]=wt,e[202]=Nt):Nt=e[202],e[203]!==ue||e[204]!==Nt?(ie=$("div",{className:"flex shrink-0 items-stretch overflow-x-auto border-b border-border bg-muted/30","data-testid":"sql-tab-strip",role:"tablist",children:[ue,Nt]}),e[203]=ue,e[204]=Nt,e[205]=ie):ie=e[205],e[206]!==Ot||e[207]!==Rt||e[208]!==It||e[209]!==Tt||e[210]!==R||e[211]!==t||e[212]!==N||e[213]!==Mt||e[214]!==d?(ce=N!==null&&$(bl,{children:[i("div",{className:"fixed inset-0 z-40","data-testid":"sql-tab-menu-backdrop",onClick:Rl,onContextMenu:Ol,role:"presentation"}),i("div",{className:"fixed z-50 min-w-44 rounded-md border border-border bg-popover py-1 text-popover-foreground shadow-md","data-testid":"sql-tab-menu",role:"menu",style:Mt,children:R===null?$(bl,{children:[i("button",{className:"flex w-full items-center px-3 py-1.5 text-start text-xs outline-none hover:bg-accent focus-visible:bg-accent disabled:pointer-events-none disabled:opacity-40","data-testid":"sql-tab-menu-close-others",disabled:d.length<=1,onClick:It,role:"menuitem",type:"button",children:t("Close other tabs")}),i("button",{className:"flex w-full items-center px-3 py-1.5 text-start text-xs outline-none hover:bg-accent focus-visible:bg-accent disabled:pointer-events-none disabled:opacity-40","data-testid":"sql-tab-menu-close-right",disabled:d.findIndex(me=>me.id===N.id)>=d.length-1,onClick:Tt,role:"menuitem",type:"button",children:t("Close tabs to the right")}),i("button",{className:"flex w-full items-center px-3 py-1.5 text-start text-xs outline-none hover:bg-accent focus-visible:bg-accent","data-testid":"sql-tab-menu-close-all",onClick:Rt,role:"menuitem",type:"button",children:t("Close all tabs")})]}):$("div",{className:"px-3 py-1.5","data-testid":"sql-tab-menu-confirm",children:[i("p",{className:"pb-1.5 text-xs text-muted-foreground",children:t("Discard unsaved tabs?")}),$("div",{className:"flex items-center gap-1.5",children:[i("button",{className:"rounded px-2 py-1 text-xs font-medium text-destructive outline-none hover:bg-destructive/10 focus-visible:bg-destructive/10","data-testid":"sql-tab-menu-confirm-discard",onClick:Ot,type:"button",children:t("Discard")}),i("button",{className:"rounded px-2 py-1 text-xs text-muted-foreground outline-none hover:bg-accent focus-visible:bg-accent","data-testid":"sql-tab-menu-confirm-cancel",onClick:Ml,type:"button",children:t("Cancel")})]})]})})]}),e[206]=Ot,e[207]=Rt,e[208]=It,e[209]=Tt,e[210]=R,e[211]=t,e[212]=N,e[213]=Mt,e[214]=d,e[215]=ce):ce=e[215],Te=H,Ie="flex min-h-0 min-w-0 flex-1 flex-col",e[216]!==V||e[217]!==kt||e[218]!==Z?(ae=i(Rr,{assistant:V,failed:kt,onGenerated:Z}),e[216]=V,e[217]=kt,e[218]=Z,e[219]=ae):ae=e[219],_e="flex min-h-0 min-w-0 flex-1",qe="true",$e="shrink-0 select-none overflow-hidden border-e border-border bg-muted/30 py-3 text-end font-mono text-xs leading-5 text-muted-foreground/60",Ce=D,Le=qo,Ee=Array.from({length:u},Io),e[124]=F,e[125]=_.id,e[126]=_t,e[127]=V,e[128]=Et,e[129]=be,e[130]=Ot,e[131]=$t,e[132]=T,e[133]=kt,e[134]=m,e[135]=Lt,e[136]=Ct,e[137]=St,e[138]=Rt,e[139]=It,e[140]=Tt,e[141]=R,e[142]=o,e[143]=xe,e[144]=c,e[145]=qt,e[146]=ge,e[147]=Z,e[148]=q,e[149]=t,e[150]=N,e[151]=Mt,e[152]=d,e[153]=Se,e[154]=qe,e[155]=$e,e[156]=Ce,e[157]=Le,e[158]=Ee,e[159]=_e,e[160]=Ie,e[161]=ae,e[162]=Te,e[163]=Re,e[164]=ie,e[165]=ce,e[166]=Oe,e[167]=Me,e[168]=de}else Se=e[153],qe=e[154],$e=e[155],Ce=e[156],Le=e[157],Ee=e[158],_e=e[159],Ie=e[160],ae=e[161],Te=e[162],Re=e[163],ie=e[164],ce=e[165],Oe=e[166],Me=e[167],de=e[168];let De;e[220]!==qe||e[221]!==$e||e[222]!==Ce||e[223]!==Le||e[224]!==Ee?(De=i("div",{"aria-hidden":qe,className:$e,ref:Ce,style:Le,children:Ee}),e[220]=qe,e[221]=$e,e[222]=Ce,e[223]=Le,e[224]=Ee,e[225]=De):De=e[225];let Ae;e[226]!==ye||e[227]!==T?(Ae=i(Kr,{diagnostics:ye,draft:T,scrollRef:z}),e[226]=ye,e[227]=T,e[228]=Ae):Ae=e[228];let ze;e[229]!==K||e[230]!==A?(ze=K===null?void 0:`${A}-opt-${K.active.toString()}`,e[229]=K,e[230]=A,e[231]=ze):ze=e[231];const el=K===null?void 0:A,tl=K!==null;let je;e[232]!==t?(je=t("SQL query"),e[232]=t,e[233]=je):je=e[233];let Be;e[234]!==T||e[235]!==Un||e[236]!==Qn||e[237]!==Kn||e[238]!==Yn||e[239]!==ze||e[240]!==el||e[241]!==tl||e[242]!==je?(Be=i("textarea",{"aria-activedescendant":ze,"aria-autocomplete":"list","aria-controls":el,"aria-expanded":tl,"aria-label":je,className:`relative size-full resize-none bg-transparent outline-none ${Nl}`,"data-testid":"sql-input",onBlur:Qn,onChange:Un,onKeyDown:Kn,onScroll:_l,onSelect:Yn,placeholder:"SELECT * FROM …",ref:j,role:"combobox",spellCheck:!1,value:T}),e[234]=T,e[235]=Un,e[236]=Qn,e[237]=Kn,e[238]=Yn,e[239]=ze,e[240]=el,e[241]=tl,e[242]=je,e[243]=Be):Be=e[243];let We;e[244]!==K||e[245]!==A||e[246]!==Fn?(We=i(Yr,{listboxId:A,onPick:Fn,state:K}),e[244]=K,e[245]=A,e[246]=Fn,e[247]=We):We=e[247];let Fe;e[248]!==Ae||e[249]!==Be||e[250]!==We?(Fe=$("div",{className:"relative min-w-0 flex-1 bg-background",children:[Ae,Be,We]}),e[248]=Ae,e[249]=Be,e[250]=We,e[251]=Fe):Fe=e[251];let Pe;e[252]!==_e||e[253]!==De||e[254]!==Fe?(Pe=$("div",{className:_e,children:[De,Fe]}),e[252]=_e,e[253]=De,e[254]=Fe,e[255]=Pe):Pe=e[255];let He;e[256]!==ye?(He=i(Jr,{diagnostics:ye,onSelect:Il}),e[256]=ye,e[257]=He):He=e[257];let Ue;e[258]!==Ie||e[259]!==ae||e[260]!==Pe||e[261]!==He?(Ue=$("div",{className:Ie,children:[ae,Pe,He]}),e[258]=Ie,e[259]=ae,e[260]=Pe,e[261]=He,e[262]=Ue):Ue=e[262];const nl=X==="results";let Ye;e[263]!==nl?(Ye=On(nl),e[263]=nl,e[264]=Ye):Ye=e[264];let Ke;e[265]!==t?(Ke=t("Results"),e[265]=t,e[266]=Ke):Ke=e[266];let Qe;e[267]!==Gn||e[268]!==Ye||e[269]!==Ke?(Qe=i("button",{className:Ye,"data-testid":"sql-tab-results",onClick:Gn,type:"button",children:Ke}),e[267]=Gn,e[268]=Ye,e[269]=Ke,e[270]=Qe):Qe=e[270];const ll=X==="chart";let Je;e[271]!==ll?(Je=On(ll),e[271]=ll,e[272]=Je):Je=e[272];let Ge;e[273]!==t?(Ge=t("Chart"),e[273]=t,e[274]=Ge):Ge=e[274];let Ve;e[275]!==Xn||e[276]!==Je||e[277]!==Ge?(Ve=i("button",{className:Je,"data-testid":"sql-tab-chart",onClick:Xn,type:"button",children:Ge}),e[275]=Xn,e[276]=Je,e[277]=Ge,e[278]=Ve):Ve=e[278];let Xe;e[279]!==V||e[280]!==Wn||e[281]!==I||e[282]!==t||e[283]!==X?(Xe=!V.unavailable&&X==="chart"&&I!==null&&i("button",{className:On(!1),"data-testid":"sql-infer-chart",disabled:V.pending("chart"),onClick:Wn,type:"button",children:V.pending("chart")?t("Thinking…"):t("Suggest chart")}),e[279]=V,e[280]=Wn,e[281]=I,e[282]=t,e[283]=X,e[284]=Xe):Xe=e[284];const rl=X==="explain";let Ze;e[285]!==rl?(Ze=On(rl),e[285]=rl,e[286]=Ze):Ze=e[286];let et;e[287]!==t?(et=t("Explain"),e[287]=t,e[288]=et):et=e[288];let tt;e[289]!==Vn||e[290]!==Ze||e[291]!==et?(tt=i("button",{className:Ze,"data-testid":"sql-tab-explain",onClick:Vn,type:"button",children:et}),e[289]=Vn,e[290]=Ze,e[291]=et,e[292]=tt):tt=e[292];let nt;e[293]!==t?(nt=t("Split editor and results"),e[293]=t,e[294]=nt):nt=e[294];const ol=`inline-flex items-center rounded-md border border-border px-2 py-1.5 outline-none transition-colors hover:bg-accent focus-visible:bg-accent ${q?"bg-accent text-foreground":"text-muted-foreground"}`;let lt;e[295]!==t?(lt=t("Split editor and results"),e[295]=t,e[296]=lt):lt=e[296];let En;e[297]===Symbol.for("react.memo_cache_sentinel")?(En=$("svg",{"aria-hidden":"true",className:"size-4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.7,viewBox:"0 0 24 24",children:[i("rect",{height:"16",rx:"2",width:"18",x:"3",y:"4"}),i("path",{d:"M12 4v16"})]}),e[297]=En):En=e[297];let rt;e[298]!==q||e[299]!==nt||e[300]!==ol||e[301]!==lt||e[302]!==Zn?(rt=i("button",{"aria-label":nt,"aria-pressed":q,className:ol,"data-testid":"sql-split-toggle",onClick:Zn,title:lt,type:"button",children:En}),e[298]=q,e[299]=nt,e[300]=ol,e[301]=lt,e[302]=Zn,e[303]=rt):rt=e[303];let ot;e[304]!==I?(ot=I!==null&&I.columns.length>0&&i(Ql,{columns:I.columns,name:"query-result",rows:I.rows}),e[304]=I,e[305]=ot):ot=e[305];let st;e[306]!==t?(st=t("Format"),e[306]=t,e[307]=st):st=e[307];let at;e[308]!==Jn||e[309]!==k||e[310]!==st?(at=i("button",{className:"inline-flex items-center rounded-md border border-border px-3 py-1.5 text-xs font-medium text-foreground outline-none transition-colors hover:bg-accent focus-visible:bg-accent disabled:pointer-events-none disabled:opacity-50","data-testid":"sql-format",disabled:k,onClick:Jn,type:"button",children:st}),e[308]=Jn,e[309]=k,e[310]=st,e[311]=at):at=e[311];let it;e[312]!==g?(it=i(jl,{onChange:E,testId:"sql-shard-input",value:g}),e[312]=g,e[313]=it):it=e[313];let ct;e[314]!==k||e[315]!==t?(ct=t(k?"Running…":"Run"),e[314]=k,e[315]=t,e[316]=ct):ct=e[316];let _n;e[317]===Symbol.for("react.memo_cache_sentinel")?(_n=i("kbd",{className:"rounded border border-primary-foreground/30 px-1 font-sans text-[10px]",children:"⌘↵"}),e[317]=_n):_n=e[317];let dt;e[318]!==Hn||e[319]!==k||e[320]!==ct?(dt=$("button",{className:"inline-flex items-center gap-1.5 rounded-md bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground outline-none transition-colors hover:bg-primary/90 focus-visible:bg-primary/90 disabled:pointer-events-none disabled:opacity-50","data-testid":"sql-run",disabled:k,onClick:Hn,type:"button",children:[ct,_n]}),e[318]=Hn,e[319]=k,e[320]=ct,e[321]=dt):dt=e[321];let ut;e[322]!==rt||e[323]!==ot||e[324]!==at||e[325]!==it||e[326]!==dt?(ut=$("div",{className:"ms-auto flex items-center gap-2",children:[rt,ot,at,it,dt]}),e[322]=rt,e[323]=ot,e[324]=at,e[325]=it,e[326]=dt,e[327]=ut):ut=e[327];let mt;e[328]!==Qe||e[329]!==Ve||e[330]!==Xe||e[331]!==tt||e[332]!==ut?(mt=$("div",{className:"flex shrink-0 items-center gap-2 border-b border-border pe-2",children:[Qe,Ve,Xe,tt,ut]}),e[328]=Qe,e[329]=Ve,e[330]=Xe,e[331]=tt,e[332]=ut,e[333]=mt):mt=e[333];let ft;e[334]!==ne?(ft=ne!==null&&i(Bl,{className:"m-3 font-mono text-xs",testId:"sql-error",variant:"destructive",children:ne}),e[334]=ne,e[335]=ft):ft=e[335];let ht;e[336]!==ne||e[337]!==I||e[338]!==t?(ht=ne===null&&I===null&&i("p",{className:"p-4 text-sm text-muted-foreground","data-testid":"sql-empty",children:t("Click Run to execute your query.")}),e[336]=ne,e[337]=I,e[338]=t,e[339]=ht):ht=e[339];let pt;e[340]!==ne||e[341]!==G||e[342]!==I||e[343]!==t||e[344]!==X?(pt=ne===null&&I!==null&&$("div",{"data-testid":"sql-result",children:[X==="chart"?i(zl,{axes:G,result:I}):i($o,{result:I}),i("p",{className:"border-t border-border px-3 py-1.5 text-xs text-muted-foreground","data-testid":"sql-count",children:I.truncated?t("Showing the first {max} of {count} rows.",{count:I.rowCount,max:I.rows.length}):t("{count} rows",{count:I.rowCount})})]}),e[340]=ne,e[341]=G,e[342]=I,e[343]=t,e[344]=X,e[345]=pt):pt=e[345];let bt;e[346]!==ft||e[347]!==ht||e[348]!==pt?(bt=$("div",{className:"min-h-0 flex-1 overflow-auto",children:[ft,ht,pt]}),e[346]=ft,e[347]=ht,e[348]=pt,e[349]=bt):bt=e[349];let gt;e[350]!==Se||e[351]!==mt||e[352]!==bt?(gt=$("div",{className:Se,children:[mt,bt]}),e[350]=Se,e[351]=mt,e[352]=bt,e[353]=gt):gt=e[353];let xt;e[354]!==gt||e[355]!==Te||e[356]!==Ue?(xt=$("div",{className:Te,children:[Ue,gt]}),e[354]=gt,e[355]=Te,e[356]=Ue,e[357]=xt):xt=e[357];let vt;e[358]!==xt||e[359]!==Re||e[360]!==ie||e[361]!==ce?(vt=$("div",{className:Re,children:[ie,ce,xt]}),e[358]=xt,e[359]=Re,e[360]=ie,e[361]=ce,e[362]=vt):vt=e[362];let In;return e[363]!==vt||e[364]!==Oe||e[365]!==Me||e[366]!==de?(In=$("div",{className:Oe,"data-testid":Me,children:[de,vt]}),e[363]=vt,e[364]=Oe,e[365]=Me,e[366]=de,e[367]=In):In=e[367],In};function Lo(r){return i(Hl,{children:r},r)}function Eo(r){return r.id}function _o(r){return Ll(r)}function Io(r,e){return i("div",{children:e+1},e)}export{Vo as SqlEditorPanel};
@@ -1 +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{useRef as K,useState as N,useEffect as B}from"react";import{d as S}from"../packem_shared/storage-tier-DznqOf-q.js";import{useT as R}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{s as _,d as C}from"../packem_shared/data-view-params-C8T3bW1z.js";import{f}from"../packem_shared/internal-AtZ4bTal.js";import{l as O,s as P}from"../packem_shared/browser-storage-xjTyMKY0.js";import{DataBrowser as z}from"../packem_shared/DataBrowser-Bfstz_au.js";import{GlobalDataBrowser as H}from"../packem_shared/GlobalDataBrowser-RLJ6NvOs.js";import{jsx as v,jsxs as $}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=()=>O(j).filter(M),k=r=>{P(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=R();let h;e[0]!==l?(h=y=>{l(y.target.value)},e[0]=l,e[1]=h):h=e[1];const s=h;let c;e[2]!==u?(c=u("Storage tier"),e[2]=u,e[3]=c):c=e[3];let n;e[4]!==c?(n=v("span",{className:"font-mono text-[11px] tracking-wide uppercase text-muted-foreground",children:c}),e[4]=c,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 d;e[8]!==s||e[9]!==m.title||e[10]!==o?(d=$("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]=d):d=e[11];let b;return e[12]!==n||e[13]!==d?(b=$("label",{className:"flex w-full flex-col gap-1",htmlFor:"table-editor-schema",children:[n,d]}),e[12]=n,e[13]=d,e[14]=b):b=e[14],b},de=({editable:r=!1,initialShardKey:e})=>{const l=L(),o=Q(),u=q(),h=J({strict:!1}),s=_(h),c=K(h);c.current=h;const n=()=>u.state.location.pathname.split("/").findLast(Boolean)==="data",m=s.tier??"shard",i=s.table,[g,d]=N(()=>w()),[b,y]=N(()=>new Set);B(()=>{f((async()=>{try{const t=await l.listGlobalTables();y(new Set(t.map(a=>a.name)))}catch{}})())},[l]),B(()=>{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=C(t),{current:p}=c;(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=C(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:()=>{try{f(globalThis.navigator.clipboard.writeText(globalThis.location.href))}catch{}},onDeleteQuery:t=>{d(W(t))},onSaveQuery:(t,a)=>{d(U(t,a))},saved:g},x=v(X,{onChange:D,tier:m});return m==="global"?v(H,{initialTable:i,onSelectTable:T,schemaSwitch:x}):v(z,{editable:r,globalTableNames:b,initialFilters:s.filters,initialOrderBy:s.orderBy,initialSearch:s.search,initialShardKey:s.shard??e,onNavigateToGlobal:V,onSelectTable:T,onViewChange:A,queryBar:E,schemaSwitch:x,tableParam:i})};export{de 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-BFkSQwlB.js";import{useT as P}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{s as _,d as B}from"../packem_shared/data-view-params-ClrV7XgF.js";import{f}from"../packem_shared/internal-BSIsQVC6.js";import{l as z,s as O}from"../packem_shared/browser-storage-xjTyMKY0.js";import{DataBrowser as R}from"../packem_shared/DataBrowser-CuRlztBz.js";import{GlobalDataBrowser as H}from"../packem_shared/GlobalDataBrowser-DB-vQ2_H.js";import{jsx as v,jsxs as C}from"react/jsx-runtime";const j="lunora-studio-saved-queries",I=50,M=r=>r!==null&&typeof r=="object"&&typeof r.name=="string"&&typeof r.view=="object"&&r.view!==null,w=()=>z(j).filter(M),k=r=>{O(j,r)},U=(r,e)=>{const l=r.trim();if(l==="")return w();const o=[{name:l,view:e},...w().filter(u=>u.name!==l)].slice(0,I);return k(o),o},W=r=>{const e=w().filter(l=>l.name!==r);return k(e),e},X=r=>{const e=G(15),{onChange:l,tier:o}=r,u=P();let d;e[0]!==l?(d=y=>{l(y.target.value)},e[0]=l,e[1]=d):d=e[1];const s=d;let h;e[2]!==u?(h=u("Storage tier"),e[2]=u,e[3]=h):h=e[3];let n;e[4]!==h?(n=v("span",{className:"font-mono text-[11px] tracking-wide uppercase text-muted-foreground",children:h}),e[4]=h,e[5]=n):n=e[5];const m=S[o];let i,g;e[6]===Symbol.for("react.memo_cache_sentinel")?(i=v("option",{value:"shard",children:S.shard.label}),g=v("option",{value:"global",children:S.global.label}),e[6]=i,e[7]=g):(i=e[6],g=e[7]);let c;e[8]!==s||e[9]!==m.title||e[10]!==o?(c=C("select",{className:"h-8 w-full rounded-md border border-border bg-background px-2 text-sm outline-none focus-visible:border-ring","data-testid":"table-editor-schema",id:"table-editor-schema",onChange:s,title:m.title,value:o,children:[i,g]}),e[8]=s,e[9]=m.title,e[10]=o,e[11]=c):c=e[11];let b;return e[12]!==n||e[13]!==c?(b=C("label",{className:"flex w-full flex-col gap-1",htmlFor:"table-editor-schema",children:[n,c]}),e[12]=n,e[13]=c,e[14]=b):b=e[14],b},Y=()=>{try{f(globalThis.navigator.clipboard.writeText(globalThis.location.href))}catch{}},me=({editable:r=!1,initialShardKey:e})=>{const l=L(),o=Q(),u=q(),d=J({strict:!1}),s=_(d),h=K(d),n=()=>u.state.location.pathname.split("/").findLast(Boolean)==="data",m=s.tier??"shard",i=s.table,[g,c]=N(()=>w()),[b,y]=N(()=>new Set);$(()=>{f((async()=>{try{const t=await l.listGlobalTables();y(new Set(t.map(a=>a.name)))}catch{}})())},[l]),$(()=>{m==="shard"&&i!==void 0&&b.has(i)&&f(o({replace:!0,search:t=>({...t,schema:"global"}),to:"/data"}))},[b,o,i,m]);const D=t=>{f(o({search:a=>({...a,schema:t==="global"?"global":void 0,table:void 0}),to:"/data"}))},T=(t,a)=>{n()&&f(o({search:p=>({schema:p.schema,search:a?.search,shard:p.shard,table:t}),to:"/data"}))},V=t=>{f(o({search:a=>({...a,schema:"global",table:t}),to:"/data"}))},A=t=>{const a=B(t),{current:p}=h;(p.filters??void 0)===a.filters&&(p.order??void 0)===a.order&&(p.search??void 0)===a.search&&(p.shard??void 0)===a.shard||!n()||f(o({replace:!0,search:F=>({...F,filters:a.filters,order:a.order,search:a.search,shard:a.shard}),to:"/data"}))},E={onApplyQuery:t=>{const a=B(t.view);f(o({search:()=>({filters:a.filters,order:a.order,schema:a.schema,search:a.search,shard:a.shard,table:a.table}),to:"/data"}))},onCopyLink:Y,onDeleteQuery:t=>{c(W(t))},onSaveQuery:(t,a)=>{c(U(t,a))},saved:g},x=v(X,{onChange:D,tier:m});return m==="global"?v(H,{initialTable:i,onSelectTable:T,schemaSwitch:x}):v(R,{editable:r,globalTableNames:b,initialFilters:s.filters,initialOrderBy:s.orderBy,initialPins:d.pins,initialSearch:s.search,initialShardKey:s.shard??e,onNavigateToGlobal:V,onSelectTable:T,onViewChange:A,queryBar:E,schemaSwitch:x,tableParam:i})};export{me as TableEditor};
@@ -1 +1 @@
1
- import{useState as J}from"react";import{E as S}from"../packem_shared/error-alert-B59DnrDI.js";import{g as C}from"../packem_shared/badge-BbuuAio7.js";import{u as K}from"../packem_shared/button-BkCrNcAs.js";import{c as j,u as I}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{K as y}from"../packem_shared/use-admin-query-Di3fLE8H.js";import{useT as R}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as N}from"../packem_shared/ADMIN_FUNCTIONS-CpgIo9pj.js";import{i as V}from"../packem_shared/internal-AtZ4bTal.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(j,{className:"overflow-hidden py-0",children:e(I,{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(K,{"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(j,{className:"overflow-hidden py-0","data-testid":"agents-thread-detail",children:n(I,{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(K,{"data-testid":"agents-thread-detail-close",onClick:()=>{w(void 0)},size:"xs",type:"button",variant:"ghost",children:t("Close")})]}),k.length===0?e("p",{className:"text-xs text-muted-foreground",children:t("This thread has no messages yet.")}):n(q,{"data-testid":"agents-messages-table",children:[e(U,{children:n(g,{children:[e(o,{children:t("Role")}),e(o,{children:t("Content")}),e(o,{children:t("Tool")}),e(o,{children:t("Approval")})]})}),e(_,{children:k.map((r,l)=>{const c=d(r,"role")??"—",h=ee(r),H=d(r,"toolName"),x=d(r,"status"),v=b(r,"seq")??l;return n(g,{"data-testid":`agents-message-${String(v)}`,children:[e(i,{className:"font-mono text-xs align-top text-muted-foreground",children:c}),e(i,{className:"max-w-md font-mono text-xs whitespace-pre-wrap break-words",children:d(r,"content")??"—"}),e(i,{className:"font-mono text-xs align-top text-muted-foreground",children:H??(h.length>0?h.join(", "):"—")}),e(i,{className:"align-top",children:x===void 0?e("span",{className:"text-xs text-muted-foreground",children:"—"}):e(C,{"data-testid":`agents-message-approval-${String(v)}`,variant:ae(x),children:x})})]},d(r,"messageKey")??`${c}:${String(v)}`)})})]})]})})]}),n("div",{className:"flex flex-col gap-6","data-testid":"lunora-agents-panel",children:[B!==null&&e(S,{error:D,testId:"agents-error"}),e("p",{className:"text-sm text-muted-foreground",children:t("Agents run as durable workflows. Each run persists a thread of assistant and tool messages; select a thread to inspect its timeline, tool calls, approvals, and token usage.")}),L!==void 0&&e("p",{className:"text-xs text-amber-600 dark:text-amber-500","data-testid":"agents-live-error",role:"alert",children:t("Live updates unavailable; showing the last evaluation.")}),u]})};export{pe as AgentsPanel};
1
+ import{useState as J}from"react";import{E as S}from"../packem_shared/error-alert-t6cpEi0z.js";import{g as C}from"../packem_shared/badge-BbuuAio7.js";import{u as j}from"../packem_shared/button-BkCrNcAs.js";import{c as I,u as K}from"../packem_shared/card-CIDGUN6K.js";import{E}from"../packem_shared/empty-state-Cg7t_8qu.js";import{n as q,d as U,m as g,p as o,f as _,u as i}from"../packem_shared/table-DdJBrClo.js";import{N as y}from"../packem_shared/use-admin-query-QJ-ibl5u.js";import{useT as R}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as N}from"../packem_shared/ADMIN_FUNCTIONS-BnD4aovm.js";import{i as V}from"../packem_shared/internal-BSIsQVC6.js";import{jsx as e,jsxs as n}from"react/jsx-runtime";const M="agent_threads",W="agent_messages",X=100,Y=250,Z={},Q={filters:[],limit:X,offset:0,orderBy:{column:"updatedAt",direction:"desc"},skipCount:!0,table:M},d=(s,t)=>{const a=s[t];return typeof a=="string"?a:void 0},b=(s,t)=>{const a=s[t];return typeof a=="number"?a:void 0},z=s=>{const{usage:t}=s;if(t===null||typeof t!="object")return;const{totalTokens:a}=t;return typeof a=="number"?a:void 0},ee=s=>{const{toolCalls:t}=s;return Array.isArray(t)?t.map(a=>a!==null&&typeof a=="object"?a.name:void 0).filter(a=>typeof a=="string"):[]},te=s=>{switch(s){case"awaiting_input":return"warning";case"cancelled":return"warning";case"error":return"destructive";case"running":return"info";default:return"outline"}},ae=s=>{switch(s){case"approved":return"success";case"rejected":return"destructive";default:return"warning"}},pe=({initialShardKey:s=""})=>{const t=R(),[a,w]=J(void 0),{data:p}=y(N.listTables,Z,{live:!0,shardKey:s}),P=p!==void 0,m=Array.isArray(p)&&p.some(r=>r.name===M),{data:A,error:B,errorSource:D,liveError:L}=y(N.readTablePage,Q,{enabled:m,live:!0,shardKey:s}),O={filters:[{column:"threadKey",operator:"eq",value:a??""}],limit:Y,offset:0,orderBy:{column:"seq",direction:"asc"},skipCount:!0,table:W},{data:$,error:F,errorSource:G}=y(N.readTablePage,O,{enabled:m&&a!==void 0,live:!0,shardKey:s}),f=Array.isArray(A?.rows)?A.rows:[],k=Array.isArray($?.rows)?$.rows:[],T=f.find(r=>d(r,"key")===a);let u;return P&&!m?u=e(E,{description:t("No @lunora/agent tables found in this deployment. Add lunora/agents.ts with defineAgent(...) and merge the agent schema extension to run durable AI agents."),testId:"agents-unconfigured",title:t("No agents configured")}):m&&f.length===0?u=e(E,{description:t("No agent has run yet. Start a run with ctx.agents.<name>.run(...) and its thread appears here."),testId:"agents-empty",title:t("No agent threads yet")}):u=n("div",{className:"flex flex-col gap-6",children:[e(I,{className:"overflow-hidden py-0",children:e(K,{className:"px-0",children:n(q,{"data-testid":"agents-threads-table",children:[e(U,{children:n(g,{children:[e(o,{children:t("Agent")}),e(o,{children:t("Key")}),e(o,{children:t("Status")}),e(o,{children:t("Messages")}),e(o,{children:t("Tokens")}),e(o,{children:t("Updated")}),e(o,{"aria-label":t("Actions")})]})}),e(_,{children:f.map(r=>{const l=d(r,"key")??"",c=d(r,"status"),h=z(r);return n(g,{"data-active":l===a?"":void 0,"data-testid":`agents-thread-${l}`,children:[e(i,{className:"font-mono text-xs",children:d(r,"agent")??"—"}),e(i,{className:"font-mono text-xs text-muted-foreground",children:l}),e(i,{children:e(C,{"data-testid":`agents-thread-status-${l}`,variant:te(c),children:c??"—"})}),e(i,{className:"tabular-nums",children:b(r,"messageCount")??"—"}),e(i,{className:"tabular-nums text-muted-foreground",children:h??"—"}),e(i,{className:"text-muted-foreground tabular-nums",children:V(b(r,"updatedAt"),"—")}),e(i,{className:"text-right",children:e(j,{"data-testid":`agents-thread-open-${l}`,onClick:()=>{w(l)},size:"sm",type:"button",variant:"outline",children:t("Timeline")})})]},l)})})]})})}),F!==null&&e(S,{error:G,testId:"agents-messages-error"}),a!==void 0&&e(I,{className:"overflow-hidden py-0","data-testid":"agents-thread-detail",children:n(K,{className:"flex flex-col gap-3 px-4 py-3",children:[n("div",{className:"flex items-center justify-between gap-2",children:[n("span",{className:"font-mono text-xs",children:[t("Timeline")," · ",a,T!==void 0&&n("span",{className:"text-muted-foreground",children:[" · ",t("Usage"),": ",z(T)??0," ",t("Tokens")]})]}),e(j,{"data-testid":"agents-thread-detail-close",onClick:()=>{w(void 0)},size:"xs",type:"button",variant:"ghost",children:t("Close")})]}),k.length===0?e("p",{className:"text-xs text-muted-foreground",children:t("This thread has no messages yet.")}):n(q,{"data-testid":"agents-messages-table",children:[e(U,{children:n(g,{children:[e(o,{children:t("Role")}),e(o,{children:t("Content")}),e(o,{children:t("Tool")}),e(o,{children:t("Approval")})]})}),e(_,{children:k.map((r,l)=>{const c=d(r,"role")??"—",h=ee(r),H=d(r,"toolName"),x=d(r,"status"),v=b(r,"seq")??l;return n(g,{"data-testid":`agents-message-${String(v)}`,children:[e(i,{className:"font-mono text-xs align-top text-muted-foreground",children:c}),e(i,{className:"max-w-md font-mono text-xs whitespace-pre-wrap break-words",children:d(r,"content")??"—"}),e(i,{className:"font-mono text-xs align-top text-muted-foreground",children:H??(h.length>0?h.join(", "):"—")}),e(i,{className:"align-top",children:x===void 0?e("span",{className:"text-xs text-muted-foreground",children:"—"}):e(C,{"data-testid":`agents-message-approval-${String(v)}`,variant:ae(x),children:x})})]},d(r,"messageKey")??`${c}:${String(v)}`)})})]})]})})]}),n("div",{className:"flex flex-col gap-6","data-testid":"lunora-agents-panel",children:[B!==null&&e(S,{error:D,testId:"agents-error"}),e("p",{className:"text-sm text-muted-foreground",children:t("Agents run as durable workflows. Each run persists a thread of assistant and tool messages; select a thread to inspect its timeline, tool calls, approvals, and token usage.")}),L!==void 0&&e("p",{className:"text-xs text-amber-600 dark:text-amber-500","data-testid":"agents-live-error",role:"alert",children:t("Live updates unavailable; showing the last evaluation.")}),u]})};export{pe as AgentsPanel};
@@ -1 +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{e as Y,f as w,h as B}from"../packem_shared/internal-AtZ4bTal.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-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-BSIsQVC6.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 +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-B59DnrDI.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 K}from"../packem_shared/empty-state-Cg7t_8qu.js";import{u as M}from"../packem_shared/input-JHu63lTv.js";import{n as O,d as R,m as T,p as w,f as U,u as $}from"../packem_shared/table-DdJBrClo.js";import{K as W}from"../packem_shared/use-admin-query-Di3fLE8H.js";import{useT as B}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as G}from"../packem_shared/ADMIN_FUNCTIONS-CpgIo9pj.js";import{i as J}from"../packem_shared/internal-AtZ4bTal.js";import{jsx as r,jsxs as i}from"react/jsx-runtime";const ce=()=>{const e=P(39),t=B(),[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}=W(G.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(M,{"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(K,{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(O,{"data-testid":"aa-table",children:[r(R,{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(U,{children:o.map(a=>i(T,{"data-testid":"aa-row",children:[r($,{className:"text-muted-foreground tabular-nums",children:J(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 P}from"react/compiler-runtime";import{useState as k}from"react";import{E as q}from"../packem_shared/error-alert-t6cpEi0z.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-QJ-ibl5u.js";import{useT as G}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as J}from"../packem_shared/ADMIN_FUNCTIONS-BnD4aovm.js";import{i as K}from"../packem_shared/internal-BSIsQVC6.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 +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{T as S}from"../packem_shared/use-admin-query-Di3fLE8H.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,u as I}from"../packem_shared/card-CIDGUN6K.js";import{O as S}from"../packem_shared/use-admin-query-QJ-ibl5u.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 +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 T,d as j,m as g,p as c,f as E,u as m}from"../packem_shared/table-DdJBrClo.js";import{T as R}from"../packem_shared/use-admin-query-Di3fLE8H.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-AtZ4bTal.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=R(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(T,{"data-testid":"auth-sessions-table",children:[s(j,{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(E,{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 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-QJ-ibl5u.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-BSIsQVC6.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 +1 @@
1
- import{c as C}from"react/compiler-runtime";import"react";import{L as S}from"../packem_shared/live-status-CGW2JHf_.js";import{g as b}from"../packem_shared/badge-BbuuAio7.js";import{c as E,u as I}from"../packem_shared/card-CIDGUN6K.js";import{E as L}from"../packem_shared/empty-state-Cg7t_8qu.js";import{n as k,d as A,m as w,p as c,f as D,u as l}from"../packem_shared/table-DdJBrClo.js";import{K as M}from"../packem_shared/use-admin-query-Di3fLE8H.js";import{useT as O}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as T}from"../packem_shared/ADMIN_FUNCTIONS-CpgIo9pj.js";import{jsx as n,jsxs as g}from"react/jsx-runtime";const $="container:",_={error:"error",sleep:"sleeping",start:"running",stop:"stopped"},j=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}},K=e=>{const t=new Map;for(const r of e){const a=r.functionPath??"";if(!a.startsWith($))continue;const s=a.slice($.length);if(s==="")continue;const i=JSON.stringify([s,r.instance??""]),m=t.get(i);if(m!==void 0&&m.timestamp>=r.timestamp)continue;const{detail:v,event:o}=j(r.message);t.set(i,{detail:v,event:o,exitCode:r.exitCode,instance:r.instance,level:r.level,name:s,state:_[o]??"unknown",timestamp:r.timestamp})}return[...t.values()].toSorted((r,a)=>r.name.localeCompare(a.name)||(r.instance??"").localeCompare(a.instance??""))},P={error:"destructive",running:"success",sleeping:"info",stopped:"outline",unknown:"secondary"},W=e=>{const{entries:t}=e??{};return Array.isArray(t)?t:[]},Y=()=>{const e=C(23),t=O();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:s,error:i,liveError:m}=M(T.getLogs,r,a),v=s!==void 0;let o;e[2]!==s?(o=K(W(s)),e[2]=s,e[3]=o):o=e[3];const N=o;let d;e[4]!==i?(d=i!==null&&n("p",{className:"text-sm text-destructive","data-testid":"containers-error",role:"alert",children:i}),e[4]=i,e[5]=d):d=e[5];let p;e[6]!==t?(p=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[6]=t,e[7]=p):p=e[7];let u;e[8]!==p?(u=n("p",{className:"text-sm text-muted-foreground",children:p}),e[8]=p,e[9]=u):u=e[9];let f;e[10]!==m?(f=n(S,{message:m,prefix:"containers"}),e[10]=m,e[11]=f):f=e[11];let h;e[12]!==u||e[13]!==f?(h=g("div",{className:"flex flex-wrap items-center gap-2",children:[u,f]}),e[12]=u,e[13]=f,e[14]=h):h=e[14];let x;e[15]!==v||e[16]!==N||e[17]!==t?(x=v&&N.length===0?n(L,{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(E,{className:"overflow-hidden py-0",children:n(I,{className:"px-0",children:g(k,{"data-testid":"containers-table",children:[n(A,{children:g(w,{children:[n(c,{children:t("Container")}),n(c,{children:t("Instance")}),n(c,{children:t("State")}),n(c,{children:t("Last event")}),n(c,{children:t("Detail")}),n(c,{children:t("Exit")}),n(c,{children:t("When")})]})}),n(D,{children:N.map(B)})]})})}),e[15]=v,e[16]=N,e[17]=t,e[18]=x):x=e[18];let y;return e[19]!==d||e[20]!==h||e[21]!==x?(y=g("div",{className:"flex flex-col gap-6","data-testid":"lunora-containers-panel",children:[d,h,x]}),e[19]=d,e[20]=h,e[21]=x,e[22]=y):y=e[22],y};function B(e){return g(w,{"data-testid":`containers-row-${e.name}${e.instance===void 0?"":`-${e.instance}`}`,children:[n(l,{className:"font-mono text-xs",children:e.name}),n(l,{className:"max-w-40 truncate font-mono text-xs text-muted-foreground",title:e.instance,children:e.instance??"—"}),n(l,{children:n(b,{variant:P[e.state],children:e.state})}),n(l,{className:"font-mono text-xs text-muted-foreground",children:e.event}),n(l,{className:"max-w-64 truncate text-xs text-muted-foreground",title:e.detail,children:e.detail??"—"}),n(l,{className:"font-mono text-xs tabular-nums text-muted-foreground",children:e.exitCode??"—"}),n(l,{className:"text-xs tabular-nums text-muted-foreground",children:new Date(e.timestamp).toLocaleString()})]},`${e.name}/${e.instance??""}`)}export{Y 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,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-QJ-ibl5u.js";import{useT as A}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as O}from"../packem_shared/ADMIN_FUNCTIONS-BnD4aovm.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 +1 @@
1
- import{c as O}from"react/compiler-runtime";import{useState as j,useCallback as V,useEffect as B}from"react";import{j as D}from"../packem_shared/result-chart-CwKhhKM0.js";import{A as U}from"../packem_shared/alert-CVcOFuDR.js";import{u as z}from"../packem_shared/button-BkCrNcAs.js";import{c as F,u as Q,f as Z,n as H}from"../packem_shared/card-CIDGUN6K.js";import{E as J}from"../packem_shared/empty-state-Cg7t_8qu.js";import{useT as T}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{u as P,n as X}from"../packem_shared/browser-storage-xjTyMKY0.js";import{useLunora as G}from"@lunora/react";import{ADMIN_FUNCTIONS as Y}from"../packem_shared/ADMIN_FUNCTIONS-CpgIo9pj.js";import{c as ee,e as te,f as le,a as de}from"../packem_shared/internal-AtZ4bTal.js";import{jsx as c,jsxs as _}from"react/jsx-runtime";const re=de(Y.runSql),ie=(M,e)=>{const l=G(),[m,t]=j(void 0),[d,i]=j(void 0),[r,n]=j(!0),C=V(async s=>{n(!0);try{const w=await l.query(re,{sql:M},ee(e));s.cancelled||(t(w),i(void 0))}catch(w){s.cancelled||(t(void 0),i(te(w)))}finally{s.cancelled||n(!1)}},[l,M,e]);return B(()=>{const s={cancelled:!1};return le(C(s)),()=>{s.cancelled=!0}},[C]),{error:d,loading:r,result:m}},se="lunora-studio-dashboards",I={shardKey:"",sql:"",title:""},ae=M=>{const e=O(54),{onEdit:l,onRemove:m,widget:t}=M,d=T(),{error:i,loading:r,result:n}=ie(t.sql,t.shardKey??"");let C;e[0]!==l||e[1]!==t.id?(C=()=>{l(t.id)},e[0]=l,e[1]=t.id,e[2]=C):C=e[2];const s=C;let w;e[3]!==m||e[4]!==t.id?(w=()=>{m(t.id)},e[3]=m,e[4]=t.id,e[5]=w):w=e[5];const $=w,R=`dashboards-widget-${t.id}`;let q;e[6]!==t.title?(q=c(Z,{className:"min-w-0 truncate",title:t.title,children:t.title}),e[6]=t.title,e[7]=q):q=e[7];let K;e[8]!==d?(K=d("Edit widget"),e[8]=d,e[9]=K):K=e[9];const L=`dashboards-widget-edit-${t.id}`;let E;e[10]!==d?(E=d("Edit widget"),e[10]=d,e[11]=E):E=e[11];let k;e[12]===Symbol.for("react.memo_cache_sentinel")?(k=c("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:c("path",{d:"M4 20h4L18 10l-4-4L4 16v4ZM14 6l4 4"})}),e[12]=k):k=e[12];let x;e[13]!==s||e[14]!==K||e[15]!==L||e[16]!==E?(x=c(z,{"aria-label":K,"data-testid":L,onClick:s,size:"icon-xs",title:E,type:"button",variant:"ghost",children:k}),e[13]=s,e[14]=K,e[15]=L,e[16]=E,e[17]=x):x=e[17];let p;e[18]!==d?(p=d("Remove widget"),e[18]=d,e[19]=p):p=e[19];const S=`dashboards-widget-remove-${t.id}`;let h;e[20]!==d?(h=d("Remove widget"),e[20]=d,e[21]=h):h=e[21];let v;e[22]===Symbol.for("react.memo_cache_sentinel")?(v=c("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:c("path",{d:"M5 7h14M9 7V5h6v2m-1 0v12H10V7M7 7v13h10V7"})}),e[22]=v):v=e[22];let u;e[23]!==$||e[24]!==p||e[25]!==S||e[26]!==h?(u=c(z,{"aria-label":p,"data-testid":S,onClick:$,size:"icon-xs",title:h,type:"button",variant:"ghost",children:v}),e[23]=$,e[24]=p,e[25]=S,e[26]=h,e[27]=u):u=e[27];let f;e[28]!==u||e[29]!==x?(f=_("div",{className:"flex shrink-0 items-center gap-1",children:[x,u]}),e[28]=u,e[29]=x,e[30]=f):f=e[30];let g;e[31]!==f||e[32]!==q?(g=_(H,{className:"flex flex-row items-start justify-between gap-2 border-b pb-3",children:[q,f]}),e[31]=f,e[32]=q,e[33]=g):g=e[33];let b;e[34]!==i||e[35]!==t.id?(b=i!==void 0&&c(U,{className:"font-mono text-xs",testId:`dashboards-widget-error-${t.id}`,variant:"destructive",children:i}),e[34]=i,e[35]=t.id,e[36]=b):b=e[36];let N;e[37]!==i||e[38]!==r||e[39]!==n||e[40]!==d||e[41]!==t.id?(N=i===void 0&&r&&n===void 0&&c("p",{className:"p-4 text-sm text-muted-foreground","data-testid":`dashboards-widget-loading-${t.id}`,children:d("Running…")}),e[37]=i,e[38]=r,e[39]=n,e[40]=d,e[41]=t.id,e[42]=N):N=e[42];let a;e[43]!==i||e[44]!==n?(a=i===void 0&&n!==void 0&&c(D,{result:n}),e[43]=i,e[44]=n,e[45]=a):a=e[45];let o;e[46]!==b||e[47]!==N||e[48]!==a?(o=_(Q,{className:"min-h-32 py-2",children:[b,N,a]}),e[46]=b,e[47]=N,e[48]=a,e[49]=o):o=e[49];let y;return e[50]!==g||e[51]!==o||e[52]!==R?(y=_(F,{"data-testid":R,children:[g,o]}),e[50]=g,e[51]=o,e[52]=R,e[53]=y):y=e[53],y},oe=M=>{const e=O(58),{draft:l,editing:m,onCancel:t,onChange:d,onSubmit:i}=M,r=T();let n;e[0]!==l||e[1]!==d?(n=A=>{d({...l,title:A.target.value})},e[0]=l,e[1]=d,e[2]=n):n=e[2];const C=n;let s;e[3]!==l||e[4]!==d?(s=A=>{d({...l,sql:A.target.value})},e[3]=l,e[4]=d,e[5]=s):s=e[5];const w=s;let $;e[6]!==l||e[7]!==d?($=A=>{d({...l,shardKey:A.target.value})},e[6]=l,e[7]=d,e[8]=$):$=e[8];const R=$;let q;e[9]!==i?(q=()=>{i()},e[9]=i,e[10]=q):q=e[10];const K=q;let L;e[11]!==l.sql||e[12]!==l.title?(L=l.title.trim()!==""&&l.sql.trim()!=="",e[11]=l.sql,e[12]=l.title,e[13]=L):L=e[13];const E=L;let k;e[14]!==r?(k=r("Widget title"),e[14]=r,e[15]=k):k=e[15];let x;e[16]!==r?(x=r("Widget title"),e[16]=r,e[17]=x):x=e[17];let p;e[18]!==l.title||e[19]!==C||e[20]!==k||e[21]!==x?(p=c("input",{"aria-label":k,className:"h-8 rounded-md border border-border bg-background px-2 text-xs outline-none focus-visible:border-ring","data-testid":"dashboards-form-title",onChange:C,placeholder:x,type:"text",value:l.title}),e[18]=l.title,e[19]=C,e[20]=k,e[21]=x,e[22]=p):p=e[22];let S;e[23]!==r?(S=r("SQL query"),e[23]=r,e[24]=S):S=e[24];let h;e[25]!==l.sql||e[26]!==w||e[27]!==S?(h=c("textarea",{"aria-label":S,className:"min-h-24 resize-y rounded-md border border-border bg-background p-2 font-mono text-xs leading-5 outline-none focus-visible:border-ring","data-testid":"dashboards-form-sql",onChange:w,placeholder:"SELECT author, COUNT(*) AS messages FROM …",spellCheck:!1,value:l.sql}),e[25]=l.sql,e[26]=w,e[27]=S,e[28]=h):h=e[28];let v;e[29]!==r?(v=r("Shard key (optional)"),e[29]=r,e[30]=v):v=e[30];let u;e[31]!==r?(u=r("Shard key (optional)"),e[31]=r,e[32]=u):u=e[32];let f;e[33]!==l.shardKey||e[34]!==R||e[35]!==v||e[36]!==u?(f=c("input",{"aria-label":v,className:"h-8 rounded-md border border-border bg-background px-2 font-mono text-xs outline-none focus-visible:border-ring","data-testid":"dashboards-form-shard",onChange:R,placeholder:u,type:"text",value:l.shardKey}),e[33]=l.shardKey,e[34]=R,e[35]=v,e[36]=u,e[37]=f):f=e[37];let g;e[38]!==r?(g=r("Cancel"),e[38]=r,e[39]=g):g=e[39];let b;e[40]!==t||e[41]!==g?(b=c(z,{"data-testid":"dashboards-form-cancel",onClick:t,size:"sm",type:"button",variant:"outline",children:g}),e[40]=t,e[41]=g,e[42]=b):b=e[42];const N=!E;let a;e[43]!==m||e[44]!==r?(a=r(m?"Save widget":"Add widget"),e[43]=m,e[44]=r,e[45]=a):a=e[45];let o;e[46]!==K||e[47]!==N||e[48]!==a?(o=c(z,{"data-testid":"dashboards-form-save",disabled:N,onClick:K,size:"sm",type:"button",children:a}),e[46]=K,e[47]=N,e[48]=a,e[49]=o):o=e[49];let y;e[50]!==b||e[51]!==o?(y=_("div",{className:"flex items-center justify-end gap-2",children:[b,o]}),e[50]=b,e[51]=o,e[52]=y):y=e[52];let W;return e[53]!==h||e[54]!==f||e[55]!==y||e[56]!==p?(W=c(F,{"data-testid":"dashboards-form",children:_(Q,{className:"flex flex-col gap-3 py-4",children:[p,h,f,y]})}),e[53]=h,e[54]=f,e[55]=y,e[56]=p,e[57]=W):W=e[57],W},qe=M=>{const e=O(39),{initialShardKey:l}=M,m=T(),[t,d]=P(se),[i,r]=j(I),[n,C]=j(null),[s,w]=j(!1);let $;e[0]!==l?($=()=>{C(null),r({...I,shardKey:l??""}),w(!0)},e[0]=l,e[1]=$):$=e[1];const R=$;let q;e[2]===Symbol.for("react.memo_cache_sentinel")?(q=()=>{w(!1),C(null),r(I)},e[2]=q):q=e[2];const K=q;let L;e[3]!==t?(L=a=>{const o=t.find(y=>y.id===a);o!==void 0&&(C(a),r({shardKey:o.shardKey??"",sql:o.sql,title:o.title}),w(!0))},e[3]=t,e[4]=L):L=e[4];const E=L;let k;e[5]!==d?(k=a=>{d(o=>o.filter(y=>y.id!==a))},e[5]=d,e[6]=k):k=e[6];const x=k;let p;e[7]!==i.shardKey||e[8]!==i.sql||e[9]!==i.title||e[10]!==n||e[11]!==d?(p=()=>{const a=i.title.trim(),o=i.sql.trim();if(a===""||o==="")return;const y=i.shardKey.trim();d(n===null?W=>[...W,{id:X("w"),shardKey:y,sql:o,title:a}]:W=>W.map(A=>A.id===n?{...A,shardKey:y,sql:o,title:a}:A)),K()},e[7]=i.shardKey,e[8]=i.sql,e[9]=i.title,e[10]=n,e[11]=d,e[12]=p):p=e[12];const S=p;let h;e[13]!==m?(h=m("Chart widgets backed by saved read-only SQL queries."),e[13]=m,e[14]=h):h=e[14];let v;e[15]!==h?(v=c("p",{className:"text-sm text-muted-foreground",children:h}),e[15]=h,e[16]=v):v=e[16];let u;e[17]!==s||e[18]!==R||e[19]!==m?(u=!s&&c(z,{"data-testid":"dashboards-add",onClick:R,size:"sm",type:"button",children:m("Add widget")}),e[17]=s,e[18]=R,e[19]=m,e[20]=u):u=e[20];let f;e[21]!==v||e[22]!==u?(f=_("div",{className:"flex items-center justify-between",children:[v,u]}),e[21]=v,e[22]=u,e[23]=f):f=e[23];let g;e[24]!==i||e[25]!==n||e[26]!==s||e[27]!==S?(g=s&&c(oe,{draft:i,editing:n!==null,onCancel:K,onChange:r,onSubmit:S}),e[24]=i,e[25]=n,e[26]=s,e[27]=S,e[28]=g):g=e[28];let b;e[29]!==s||e[30]!==E||e[31]!==x||e[32]!==m||e[33]!==t?(b=t.length===0&&!s?c(J,{description:m("Add a widget to chart a saved SQL query on this browser."),testId:"dashboards-empty",title:m("No widgets yet")}):c("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-2 xl:grid-cols-3","data-testid":"dashboards-grid",children:t.map(a=>c(ae,{onEdit:E,onRemove:x,widget:a},a.id))}),e[29]=s,e[30]=E,e[31]=x,e[32]=m,e[33]=t,e[34]=b):b=e[34];let N;return e[35]!==g||e[36]!==b||e[37]!==f?(N=_("div",{className:"flex flex-col gap-4","data-testid":"lunora-dashboards",children:[f,g,b]}),e[35]=g,e[36]=b,e[37]=f,e[38]=N):N=e[38],N};export{qe as default};
1
+ import{c as j}from"react/compiler-runtime";import{useState as z,useEffect as V}from"react";import{I as B}from"../packem_shared/result-chart-DzJOVsaw.js";import{A as D}from"../packem_shared/alert-CVcOFuDR.js";import{u as I}from"../packem_shared/button-BkCrNcAs.js";import{c as F,u as Q,f as U,n as Z}from"../packem_shared/card-CIDGUN6K.js";import{E as H}from"../packem_shared/empty-state-Cg7t_8qu.js";import{useT as T}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{u as J,n as P}from"../packem_shared/browser-storage-xjTyMKY0.js";import{useLunora as X}from"@lunora/react";import{ADMIN_FUNCTIONS as G}from"../packem_shared/ADMIN_FUNCTIONS-BnD4aovm.js";import{d as Y,b as ee,f as te,g as le}from"../packem_shared/internal-BSIsQVC6.js";import{jsx as m,jsxs as _}from"react/jsx-runtime";const de=le(G.runSql),re=(A,e)=>{const t=j(11),c=X(),[l,d]=z(void 0),[s,r]=z(void 0),[a,$]=z(!0);let n;t[0]!==c||t[1]!==e||t[2]!==A?(n=async u=>{$(!0);try{const C=await c.query(de,{sql:A},Y(e));u.cancelled||(d(C),r(void 0))}catch(C){const E=C;u.cancelled||(d(void 0),r(ee(E)))}u.cancelled||$(!1)},t[0]=c,t[1]=e,t[2]=A,t[3]=n):n=t[3];const k=n;let y,S;t[4]!==k?(y=()=>{const u={cancelled:!1};return te(k(u)),()=>{u.cancelled=!0}},S=[k],t[4]=k,t[5]=y,t[6]=S):(y=t[5],S=t[6]),V(y,S);let h;return t[7]!==s||t[8]!==a||t[9]!==l?(h={error:s,loading:a,result:l},t[7]=s,t[8]=a,t[9]=l,t[10]=h):h=t[10],h},se="lunora-studio-dashboards",O={shardKey:"",sql:"",title:""},ie=A=>{const e=j(54),{onEdit:t,onRemove:c,widget:l}=A,d=T(),{error:s,loading:r,result:a}=re(l.sql,l.shardKey??"");let $;e[0]!==t||e[1]!==l.id?($=()=>{t(l.id)},e[0]=t,e[1]=l.id,e[2]=$):$=e[2];const n=$;let k;e[3]!==c||e[4]!==l.id?(k=()=>{c(l.id)},e[3]=c,e[4]=l.id,e[5]=k):k=e[5];const y=k,S=`dashboards-widget-${l.id}`;let h;e[6]!==l.title?(h=m(U,{className:"min-w-0 truncate",title:l.title,children:l.title}),e[6]=l.title,e[7]=h):h=e[7];let u;e[8]!==d?(u=d("Edit widget"),e[8]=d,e[9]=u):u=e[9];const C=`dashboards-widget-edit-${l.id}`;let E;e[10]!==d?(E=d("Edit widget"),e[10]=d,e[11]=E):E=e[11];let K;e[12]===Symbol.for("react.memo_cache_sentinel")?(K=m("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:m("path",{d:"M4 20h4L18 10l-4-4L4 16v4ZM14 6l4 4"})}),e[12]=K):K=e[12];let N;e[13]!==n||e[14]!==u||e[15]!==C||e[16]!==E?(N=m(I,{"aria-label":u,"data-testid":C,onClick:n,size:"icon-xs",title:E,type:"button",variant:"ghost",children:K}),e[13]=n,e[14]=u,e[15]=C,e[16]=E,e[17]=N):N=e[17];let x;e[18]!==d?(x=d("Remove widget"),e[18]=d,e[19]=x):x=e[19];const R=`dashboards-widget-remove-${l.id}`;let g;e[20]!==d?(g=d("Remove widget"),e[20]=d,e[21]=g):g=e[21];let w;e[22]===Symbol.for("react.memo_cache_sentinel")?(w=m("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:m("path",{d:"M5 7h14M9 7V5h6v2m-1 0v12H10V7M7 7v13h10V7"})}),e[22]=w):w=e[22];let f;e[23]!==y||e[24]!==x||e[25]!==R||e[26]!==g?(f=m(I,{"aria-label":x,"data-testid":R,onClick:y,size:"icon-xs",title:g,type:"button",variant:"ghost",children:w}),e[23]=y,e[24]=x,e[25]=R,e[26]=g,e[27]=f):f=e[27];let b;e[28]!==f||e[29]!==N?(b=_("div",{className:"flex shrink-0 items-center gap-1",children:[N,f]}),e[28]=f,e[29]=N,e[30]=b):b=e[30];let p;e[31]!==b||e[32]!==h?(p=_(Z,{className:"flex flex-row items-start justify-between gap-2 border-b pb-3",children:[h,b]}),e[31]=b,e[32]=h,e[33]=p):p=e[33];let v;e[34]!==s||e[35]!==l.id?(v=s!==void 0&&m(D,{className:"font-mono text-xs",testId:`dashboards-widget-error-${l.id}`,variant:"destructive",children:s}),e[34]=s,e[35]=l.id,e[36]=v):v=e[36];let L;e[37]!==s||e[38]!==r||e[39]!==a||e[40]!==d||e[41]!==l.id?(L=s===void 0&&r&&a===void 0&&m("p",{className:"p-4 text-sm text-muted-foreground","data-testid":`dashboards-widget-loading-${l.id}`,children:d("Running…")}),e[37]=s,e[38]=r,e[39]=a,e[40]=d,e[41]=l.id,e[42]=L):L=e[42];let i;e[43]!==s||e[44]!==a?(i=s===void 0&&a!==void 0&&m(B,{result:a}),e[43]=s,e[44]=a,e[45]=i):i=e[45];let o;e[46]!==v||e[47]!==L||e[48]!==i?(o=_(Q,{className:"min-h-32 py-2",children:[v,L,i]}),e[46]=v,e[47]=L,e[48]=i,e[49]=o):o=e[49];let q;return e[50]!==p||e[51]!==o||e[52]!==S?(q=_(F,{"data-testid":S,children:[p,o]}),e[50]=p,e[51]=o,e[52]=S,e[53]=q):q=e[53],q},ae=A=>{const e=j(58),{draft:t,editing:c,onCancel:l,onChange:d,onSubmit:s}=A,r=T();let a;e[0]!==t||e[1]!==d?(a=M=>{d({...t,title:M.target.value})},e[0]=t,e[1]=d,e[2]=a):a=e[2];const $=a;let n;e[3]!==t||e[4]!==d?(n=M=>{d({...t,sql:M.target.value})},e[3]=t,e[4]=d,e[5]=n):n=e[5];const k=n;let y;e[6]!==t||e[7]!==d?(y=M=>{d({...t,shardKey:M.target.value})},e[6]=t,e[7]=d,e[8]=y):y=e[8];const S=y;let h;e[9]!==s?(h=()=>{s()},e[9]=s,e[10]=h):h=e[10];const u=h;let C;e[11]!==t.sql||e[12]!==t.title?(C=t.title.trim()!==""&&t.sql.trim()!=="",e[11]=t.sql,e[12]=t.title,e[13]=C):C=e[13];const E=C;let K;e[14]!==r?(K=r("Widget title"),e[14]=r,e[15]=K):K=e[15];let N;e[16]!==r?(N=r("Widget title"),e[16]=r,e[17]=N):N=e[17];let x;e[18]!==t.title||e[19]!==$||e[20]!==K||e[21]!==N?(x=m("input",{"aria-label":K,className:"h-8 rounded-md border border-border bg-background px-2 text-xs outline-none focus-visible:border-ring","data-testid":"dashboards-form-title",onChange:$,placeholder:N,type:"text",value:t.title}),e[18]=t.title,e[19]=$,e[20]=K,e[21]=N,e[22]=x):x=e[22];let R;e[23]!==r?(R=r("SQL query"),e[23]=r,e[24]=R):R=e[24];let g;e[25]!==t.sql||e[26]!==k||e[27]!==R?(g=m("textarea",{"aria-label":R,className:"min-h-24 resize-y rounded-md border border-border bg-background p-2 font-mono text-xs leading-5 outline-none focus-visible:border-ring","data-testid":"dashboards-form-sql",onChange:k,placeholder:"SELECT author, COUNT(*) AS messages FROM …",spellCheck:!1,value:t.sql}),e[25]=t.sql,e[26]=k,e[27]=R,e[28]=g):g=e[28];let w;e[29]!==r?(w=r("Shard key (optional)"),e[29]=r,e[30]=w):w=e[30];let f;e[31]!==r?(f=r("Shard key (optional)"),e[31]=r,e[32]=f):f=e[32];let b;e[33]!==t.shardKey||e[34]!==S||e[35]!==w||e[36]!==f?(b=m("input",{"aria-label":w,className:"h-8 rounded-md border border-border bg-background px-2 font-mono text-xs outline-none focus-visible:border-ring","data-testid":"dashboards-form-shard",onChange:S,placeholder:f,type:"text",value:t.shardKey}),e[33]=t.shardKey,e[34]=S,e[35]=w,e[36]=f,e[37]=b):b=e[37];let p;e[38]!==r?(p=r("Cancel"),e[38]=r,e[39]=p):p=e[39];let v;e[40]!==l||e[41]!==p?(v=m(I,{"data-testid":"dashboards-form-cancel",onClick:l,size:"sm",type:"button",variant:"outline",children:p}),e[40]=l,e[41]=p,e[42]=v):v=e[42];const L=!E;let i;e[43]!==c||e[44]!==r?(i=r(c?"Save widget":"Add widget"),e[43]=c,e[44]=r,e[45]=i):i=e[45];let o;e[46]!==u||e[47]!==L||e[48]!==i?(o=m(I,{"data-testid":"dashboards-form-save",disabled:L,onClick:u,size:"sm",type:"button",children:i}),e[46]=u,e[47]=L,e[48]=i,e[49]=o):o=e[49];let q;e[50]!==v||e[51]!==o?(q=_("div",{className:"flex items-center justify-end gap-2",children:[v,o]}),e[50]=v,e[51]=o,e[52]=q):q=e[52];let W;return e[53]!==g||e[54]!==b||e[55]!==q||e[56]!==x?(W=m(F,{"data-testid":"dashboards-form",children:_(Q,{className:"flex flex-col gap-3 py-4",children:[x,g,b,q]})}),e[53]=g,e[54]=b,e[55]=q,e[56]=x,e[57]=W):W=e[57],W},we=A=>{const e=j(39),{initialShardKey:t}=A,c=T(),[l,d]=J(se),[s,r]=z(O),[a,$]=z(null),[n,k]=z(!1);let y;e[0]!==t?(y=()=>{$(null),r({...O,shardKey:t??""}),k(!0)},e[0]=t,e[1]=y):y=e[1];const S=y;let h;e[2]===Symbol.for("react.memo_cache_sentinel")?(h=()=>{k(!1),$(null),r(O)},e[2]=h):h=e[2];const u=h;let C;e[3]!==l?(C=i=>{const o=l.find(q=>q.id===i);o!==void 0&&($(i),r({shardKey:o.shardKey??"",sql:o.sql,title:o.title}),k(!0))},e[3]=l,e[4]=C):C=e[4];const E=C;let K;e[5]!==d?(K=i=>{d(o=>o.filter(q=>q.id!==i))},e[5]=d,e[6]=K):K=e[6];const N=K;let x;e[7]!==s.shardKey||e[8]!==s.sql||e[9]!==s.title||e[10]!==a||e[11]!==d?(x=()=>{const i=s.title.trim(),o=s.sql.trim();if(i===""||o==="")return;const q=s.shardKey.trim();d(a===null?W=>[...W,{id:P("w"),shardKey:q,sql:o,title:i}]:W=>W.map(M=>M.id===a?{...M,shardKey:q,sql:o,title:i}:M)),u()},e[7]=s.shardKey,e[8]=s.sql,e[9]=s.title,e[10]=a,e[11]=d,e[12]=x):x=e[12];const R=x;let g;e[13]!==c?(g=c("Chart widgets backed by saved read-only SQL queries."),e[13]=c,e[14]=g):g=e[14];let w;e[15]!==g?(w=m("p",{className:"text-sm text-muted-foreground",children:g}),e[15]=g,e[16]=w):w=e[16];let f;e[17]!==n||e[18]!==S||e[19]!==c?(f=!n&&m(I,{"data-testid":"dashboards-add",onClick:S,size:"sm",type:"button",children:c("Add widget")}),e[17]=n,e[18]=S,e[19]=c,e[20]=f):f=e[20];let b;e[21]!==w||e[22]!==f?(b=_("div",{className:"flex items-center justify-between",children:[w,f]}),e[21]=w,e[22]=f,e[23]=b):b=e[23];let p;e[24]!==s||e[25]!==a||e[26]!==n||e[27]!==R?(p=n&&m(ae,{draft:s,editing:a!==null,onCancel:u,onChange:r,onSubmit:R}),e[24]=s,e[25]=a,e[26]=n,e[27]=R,e[28]=p):p=e[28];let v;e[29]!==n||e[30]!==E||e[31]!==N||e[32]!==c||e[33]!==l?(v=l.length===0&&!n?m(H,{description:c("Add a widget to chart a saved SQL query on this browser."),testId:"dashboards-empty",title:c("No widgets yet")}):m("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-2 xl:grid-cols-3","data-testid":"dashboards-grid",children:l.map(i=>m(ie,{onEdit:E,onRemove:N,widget:i},i.id))}),e[29]=n,e[30]=E,e[31]=N,e[32]=c,e[33]=l,e[34]=v):v=e[34];let L;return e[35]!==p||e[36]!==v||e[37]!==b?(L=_("div",{className:"flex flex-col gap-4","data-testid":"lunora-dashboards",children:[b,p,v]}),e[35]=p,e[36]=v,e[37]=b,e[38]=L):L=e[38],L};export{we as default};