@lunora/studio 1.0.0-alpha.372 → 1.0.0-alpha.373
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.
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/packem_chunks/FileBrowser.mjs +1 -1
- package/dist/packem_chunks/LogsPanel.mjs +1 -1
- package/dist/packem_chunks/MetricsPanel.mjs +1 -1
- package/dist/packem_chunks/SettingsPanel.mjs +1 -1
- package/dist/packem_chunks/SqlEditorPanel.mjs +15 -14
- package/dist/packem_chunks/TableEditor.mjs +1 -1
- package/dist/packem_chunks/log-drains-panel.mjs +1 -1
- package/dist/packem_shared/{GlobalDataBrowser-D8ZheGwm.mjs → GlobalDataBrowser-DB1B-WAN.mjs} +1 -1
- package/dist/packem_shared/{cf-links-C4DVTr8A.mjs → cf-links-BPy1pJRO.mjs} +1 -1
- package/dist/standalone/{chunk-IYX53XCW.js → chunk-25WEL5RI.js} +1 -1
- package/dist/standalone/{chunk-DVQVIQBT.js → chunk-2CPMCEHD.js} +1 -1
- package/dist/standalone/{chunk-FHASF32O.js → chunk-2IOS27FL.js} +1 -1
- package/dist/standalone/{chunk-HOK6O3US.js → chunk-2MZLFQR5.js} +1 -1
- package/dist/standalone/{chunk-XICMCBFN.js → chunk-2U6Z7A6C.js} +1 -1
- package/dist/standalone/{chunk-3DBV6QGB.js → chunk-3BQD5ITB.js} +1 -1
- package/dist/standalone/{chunk-DWFXPFDT.js → chunk-42RZZFLX.js} +1 -1
- package/dist/standalone/{chunk-BPNGCNB2.js → chunk-4ADB7TWC.js} +1 -1
- package/dist/standalone/{chunk-AVHCLWWI.js → chunk-4B54WP4R.js} +1 -1
- package/dist/standalone/{chunk-INTNKBFO.js → chunk-4EQAUONF.js} +1 -1
- package/dist/standalone/{chunk-SBFFTOVT.js → chunk-4RGKUS3H.js} +1 -1
- package/dist/standalone/{chunk-3LPWFZNJ.js → chunk-52ULLZJX.js} +1 -1
- package/dist/standalone/{chunk-IVISXJR4.js → chunk-645S7KRU.js} +1 -1
- package/dist/standalone/{chunk-YX3H4WA3.js → chunk-6IRGBPDN.js} +1 -1
- package/dist/standalone/{chunk-MZJY3N7N.js → chunk-6VOBO5QL.js} +1 -1
- package/dist/standalone/{chunk-ATN6HPYI.js → chunk-6YBEKVUG.js} +1 -1
- package/dist/standalone/{chunk-7K3VSMEZ.js → chunk-7SNL633X.js} +1 -1
- package/dist/standalone/{chunk-R7363SOB.js → chunk-ACWAMBGT.js} +1 -1
- package/dist/standalone/{chunk-S5IY62X6.js → chunk-AERXMIND.js} +1 -1
- package/dist/standalone/{chunk-6ALZ2WSG.js → chunk-ASD6UAND.js} +1 -1
- package/dist/standalone/{chunk-HAK3FCOV.js → chunk-B76HLC52.js} +1 -1
- package/dist/standalone/{chunk-YR5RQPV4.js → chunk-BQS3C5V3.js} +1 -1
- package/dist/standalone/{chunk-S4PIGHQL.js → chunk-C4BS3LHQ.js} +1 -1
- package/dist/standalone/{chunk-4R3EKQ2A.js → chunk-CAEJQOMU.js} +1 -1
- package/dist/standalone/{chunk-H5CTBNMP.js → chunk-CBACG4XF.js} +1 -1
- package/dist/standalone/{chunk-2Z4FB527.js → chunk-CGXIERYO.js} +1 -1
- package/dist/standalone/{chunk-AJIXOUOQ.js → chunk-D3DZZHZA.js} +1 -1
- package/dist/standalone/{chunk-7LMMVPE3.js → chunk-D6CDIHHL.js} +1 -1
- package/dist/standalone/{chunk-EHJ2IIDG.js → chunk-DDTWGWM4.js} +1 -1
- package/dist/standalone/{chunk-YPEYNYYK.js → chunk-DHH7WHXQ.js} +1 -1
- package/dist/standalone/{chunk-E3PLSEDK.js → chunk-EAPNLM2Q.js} +1 -1
- package/dist/standalone/{chunk-IXV3EMNQ.js → chunk-ELUYMLPL.js} +1 -1
- package/dist/standalone/{chunk-WWVOUPO3.js → chunk-EX2DUBRT.js} +1 -1
- package/dist/standalone/{chunk-KXFU34K6.js → chunk-F5WJCL3F.js} +1 -1
- package/dist/standalone/{chunk-PRPZCRYY.js → chunk-FGZ73BFG.js} +1 -1
- package/dist/standalone/{chunk-CHIGIVHM.js → chunk-FK2S7VR4.js} +1 -1
- package/dist/standalone/{chunk-AR5HF7G5.js → chunk-FT3BWJVP.js} +1 -1
- package/dist/standalone/{chunk-YK66QDSW.js → chunk-FWOOA2ZR.js} +1 -1
- package/dist/standalone/{chunk-IBCJ4VGA.js → chunk-G5REMLEG.js} +1 -1
- package/dist/standalone/{chunk-2ENIONNZ.js → chunk-GH6CI2P2.js} +1 -1
- package/dist/standalone/{chunk-TA3D6GCA.js → chunk-HCWB4UDT.js} +1 -1
- package/dist/standalone/{chunk-LM344LXC.js → chunk-HPD2PZP2.js} +1 -1
- package/dist/standalone/{chunk-VOM5M3GA.js → chunk-HZU4WF4X.js} +1 -1
- package/dist/standalone/{chunk-LBPNDQST.js → chunk-IELLWQGA.js} +1 -1
- package/dist/standalone/{chunk-DCWSHHUX.js → chunk-IJNP6YSD.js} +1 -1
- package/dist/standalone/{chunk-GVROUDAI.js → chunk-ILSJ22BK.js} +1 -1
- package/dist/standalone/{chunk-G2ER6ZFN.js → chunk-JAAXDIR5.js} +1 -1
- package/dist/standalone/chunk-JB3DZ2PJ.js +1 -0
- package/dist/standalone/{chunk-BUDP4EJL.js → chunk-JPCVFWR5.js} +1 -1
- package/dist/standalone/{chunk-PZMCBA23.js → chunk-KBYFBEG2.js} +1 -1
- package/dist/standalone/{chunk-SCGQXYRJ.js → chunk-KYN4A72O.js} +1 -1
- package/dist/standalone/{chunk-IRC3PGZV.js → chunk-LA76GGAT.js} +1 -1
- package/dist/standalone/{chunk-WVMJYTWY.js → chunk-LCIDEYA4.js} +1 -1
- package/dist/standalone/{chunk-F5YWZPEQ.js → chunk-LFKKTGEF.js} +1 -1
- package/dist/standalone/{chunk-4KCL4VXL.js → chunk-LR2FBYCC.js} +1 -1
- package/dist/standalone/{chunk-DH6BG54K.js → chunk-M4TCBPSY.js} +1 -1
- package/dist/standalone/{chunk-KBAJLVHY.js → chunk-MGFELY5Q.js} +1 -1
- package/dist/standalone/{chunk-Z3PS37OB.js → chunk-MJWIIV2C.js} +1 -1
- package/dist/standalone/{chunk-R5Y2LHHL.js → chunk-MTX62MQ7.js} +1 -1
- package/dist/standalone/{chunk-OFMI2ROE.js → chunk-MWYGLPDV.js} +1 -1
- package/dist/standalone/{chunk-T6CRFQVI.js → chunk-N7EIHD3H.js} +1 -1
- package/dist/standalone/{chunk-TUFZY4AM.js → chunk-NGGTRLCC.js} +1 -1
- package/dist/standalone/chunk-ODLNNVP2.js +7 -0
- package/dist/standalone/{chunk-3SD5I425.js → chunk-OODTH4NA.js} +1 -1
- package/dist/standalone/{chunk-MYSRHHC4.js → chunk-OSHODLMU.js} +1 -1
- package/dist/standalone/{chunk-WBLJB5GM.js → chunk-OVEOTKK5.js} +1 -1
- package/dist/standalone/{chunk-VYGJX3UB.js → chunk-PGJOTPWC.js} +1 -1
- package/dist/standalone/{chunk-XSJHOZY3.js → chunk-PIOHOROI.js} +1 -1
- package/dist/standalone/{chunk-I3AJWD67.js → chunk-PIQ4A4BZ.js} +1 -1
- package/dist/standalone/{chunk-HYNCYK4O.js → chunk-PUK3H4RN.js} +1 -1
- package/dist/standalone/{chunk-XWXZPKL2.js → chunk-QHKR5JW4.js} +1 -1
- package/dist/standalone/{chunk-O4YNHJSC.js → chunk-QMULO5AP.js} +1 -1
- package/dist/standalone/{chunk-XIV3Q3NC.js → chunk-QN66FO5B.js} +1 -1
- package/dist/standalone/{chunk-RGER5Q3A.js → chunk-QNY5EEBN.js} +1 -1
- package/dist/standalone/{chunk-U76UITHC.js → chunk-R52GVSS2.js} +1 -1
- package/dist/standalone/{chunk-P3JNXC5P.js → chunk-RDS46R5R.js} +1 -1
- package/dist/standalone/{chunk-XXH2XHDM.js → chunk-RDS72J4I.js} +1 -1
- package/dist/standalone/{chunk-SKVT5IO6.js → chunk-RHYQB4RH.js} +1 -1
- package/dist/standalone/{chunk-4R3JFKEL.js → chunk-RKPVI2PI.js} +1 -1
- package/dist/standalone/{chunk-DM3YNFK3.js → chunk-RUQTILJN.js} +1 -1
- package/dist/standalone/{chunk-2USDHESR.js → chunk-SKZNH5QQ.js} +1 -1
- package/dist/standalone/{chunk-O3ZVMZSA.js → chunk-SUUBCPUD.js} +1 -1
- package/dist/standalone/{chunk-YQCQZXJH.js → chunk-TDJQ7HQM.js} +1 -1
- package/dist/standalone/{chunk-F6JSRYQT.js → chunk-TUFOWHEF.js} +1 -1
- package/dist/standalone/{chunk-WEHLWY2J.js → chunk-USVLFLZL.js} +1 -1
- package/dist/standalone/{chunk-4E35ZI3H.js → chunk-VDSTHVWZ.js} +1 -1
- package/dist/standalone/{chunk-TOWZ7WYZ.js → chunk-VXZAS5VS.js} +1 -1
- package/dist/standalone/{chunk-I4EHU6GZ.js → chunk-WFXS3YRM.js} +16 -15
- package/dist/standalone/{chunk-Y6N2MJKJ.js → chunk-WJA2IGZC.js} +1 -1
- package/dist/standalone/{chunk-3H2ATHKG.js → chunk-WSG35SRF.js} +1 -1
- package/dist/standalone/{chunk-JLGY2EV4.js → chunk-XITLHKKR.js} +1 -1
- package/dist/standalone/{chunk-O2U7PWU2.js → chunk-XWVFKYZV.js} +1 -1
- package/dist/standalone/{chunk-T43I73OA.js → chunk-XZHTVLDG.js} +1 -1
- package/dist/standalone/{chunk-NS3LKZU2.js → chunk-Z6WEYWT7.js} +1 -1
- package/dist/standalone/{chunk-5YL3SK5T.js → chunk-Z7ZGAQ5J.js} +1 -1
- package/dist/standalone/{chunk-Y5N4LSAB.js → chunk-ZCOMJH2I.js} +1 -1
- package/dist/standalone/studio.js +1 -1
- package/dist/styles.css +1 -1
- package/package.json +5 -5
- package/dist/standalone/chunk-6TPZKFPG.js +0 -1
- package/dist/standalone/chunk-A4AUTJPE.js +0 -7
- /package/dist/standalone/{chunk-P6VNMPWR.js → chunk-R6NJ4ER6.js} +0 -0
|
@@ -1,30 +1,31 @@
|
|
|
1
|
-
import{a as
|
|
1
|
+
import{a as nt,b as ot}from"./chunk-42RZZFLX.js";import"./chunk-BQS3C5V3.js";import"./chunk-IJNP6YSD.js";import{d as tt}from"./chunk-CAEJQOMU.js";import"./chunk-D3DZZHZA.js";import{a as Ae}from"./chunk-CVSIFPI5.js";import{a as Ze}from"./chunk-QMULO5AP.js";import"./chunk-Y2YLTUMD.js";import"./chunk-OVEOTKK5.js";import"./chunk-UBX5ZPLV.js";import"./chunk-VNH4OBJS.js";import{a as et}from"./chunk-2DT3QG6Q.js";import"./chunk-KTK4NDWQ.js";import"./chunk-XLYFGUEF.js";import"./chunk-D65UVZIA.js";import"./chunk-NGVP66OH.js";import"./chunk-QAOZXPLU.js";import"./chunk-BG2CJOVS.js";import{a as Ye}from"./chunk-645S7KRU.js";import{b as Ve}from"./chunk-3D67ZJRW.js";import"./chunk-6YBEKVUG.js";import{c as Xe,d as we,e as Ne,f as Ee,g as Me}from"./chunk-ZSWW2UGP.js";import"./chunk-QRA7AKYO.js";import{i as ye}from"./chunk-MWYGLPDV.js";import"./chunk-HFBSWKJS.js";import"./chunk-4EPW63HS.js";import"./chunk-KBYFBEG2.js";import"./chunk-JMZT3CEW.js";import"./chunk-VUOEJJUH.js";import"./chunk-YUVGMKHG.js";import{a as Je}from"./chunk-F5WJCL3F.js";import"./chunk-VXZAS5VS.js";import{b as Ge}from"./chunk-RUQTILJN.js";import{a as ve}from"./chunk-6A6AELDJ.js";import"./chunk-TUFOWHEF.js";import{n as Ce}from"./chunk-ODLNNVP2.js";import"./chunk-ZPQBVYNN.js";import{B as J,h as ge,i as xe,j as Ke,r as Ue,s as le,x as ie}from"./chunk-PUK3H4RN.js";import"./chunk-PDBW6GTJ.js";import{a as Et}from"./chunk-GWNGVKLG.js";import{a as Nt,b as Lt}from"./chunk-6G3E4PJ2.js";import{a as d,d as De}from"./chunk-5PEAXTYQ.js";var V=De(Et(),1),j=De(Nt(),1);var u=De(Lt(),1);var Se=class{static{d(this,"Diff")}diff(e,n,t={}){let o;typeof t=="function"?(o=t,t={}):"callback"in t&&(o=t.callback);let r=this.castInput(e,t),l=this.castInput(n,t),i=this.removeEmpty(this.tokenize(r,t)),a=this.removeEmpty(this.tokenize(l,t));return this.diffWithOptionsObj(i,a,t,o)}diffWithOptionsObj(e,n,t,o){var r;let l=d(h=>{if(h=this.postProcess(h,t),o){setTimeout(function(){o(h)},0);return}else return h},"done"),i=n.length,a=e.length,c=1,m=i+a;t.maxEditLength!=null&&(m=Math.min(m,t.maxEditLength));let p=(r=t.timeout)!==null&&r!==void 0?r:1/0,f=Date.now()+p,b=[{oldPos:-1,lastComponent:void 0}],g=this.extractCommon(b[0],n,e,0,t);if(b[0].oldPos+1>=a&&g+1>=i)return l(this.buildValues(b[0].lastComponent,n,e));let k=-1/0,q=1/0,N=d(()=>{for(let h=Math.max(k,-c);h<=Math.min(q,c);h+=2){let S,x=b[h-1],v=b[h+1];x&&(b[h-1]=void 0);let y=!1;if(v){let E=v.oldPos-h;y=v&&0<=E&&E<i}let w=x&&x.oldPos+1<a;if(!y&&!w){b[h]=void 0;continue}if(!w||y&&x.oldPos<v.oldPos?S=this.addToPath(v,!0,!1,0,t):S=this.addToPath(x,!1,!0,1,t),g=this.extractCommon(S,n,e,h,t),S.oldPos+1>=a&&g+1>=i)return l(this.buildValues(S.lastComponent,n,e))||!0;b[h]=S,S.oldPos+1>=a&&(q=Math.min(q,h-1)),g+1>=i&&(k=Math.max(k,h+1))}c++},"execEditLength");if(o)d(function h(){setTimeout(function(){if(c>m||Date.now()>f)return o(void 0);N()||h()},0)},"exec")();else for(;c<=m&&Date.now()<=f;){let h=N();if(h)return h}}addToPath(e,n,t,o,r){let l=e.lastComponent;return l&&!r.oneChangePerToken&&l.added===n&&l.removed===t?{oldPos:e.oldPos+o,lastComponent:{count:l.count+1,added:n,removed:t,previousComponent:l.previousComponent}}:{oldPos:e.oldPos+o,lastComponent:{count:1,added:n,removed:t,previousComponent:l}}}extractCommon(e,n,t,o,r){let l=n.length,i=t.length,a=e.oldPos,c=a-o,m=0;for(;c+1<l&&a+1<i&&this.equals(t[a+1],n[c+1],r);)c++,a++,m++,r.oneChangePerToken&&(e.lastComponent={count:1,previousComponent:e.lastComponent,added:!1,removed:!1});return m&&!r.oneChangePerToken&&(e.lastComponent={count:m,previousComponent:e.lastComponent,added:!1,removed:!1}),e.oldPos=a,c}equals(e,n,t){return t.comparator?t.comparator(e,n):e===n||!!t.ignoreCase&&e.toLowerCase()===n.toLowerCase()}removeEmpty(e){let n=[];for(let t=0;t<e.length;t++)e[t]&&n.push(e[t]);return n}castInput(e,n){return e}tokenize(e,n){return Array.from(e)}join(e){return e.join("")}postProcess(e,n){return e}get useLongestToken(){return!1}buildValues(e,n,t){let o=[],r;for(;e;)o.push(e),r=e.previousComponent,delete e.previousComponent,e=r;o.reverse();let l=o.length,i=0,a=0,c=0;for(;i<l;i++){let m=o[i];if(m.removed)m.value=this.join(t.slice(c,c+m.count)),c+=m.count;else{if(!m.added&&this.useLongestToken){let p=n.slice(a,a+m.count);p=p.map(function(f,b){let g=t[c+b];return g.length>f.length?g:f}),m.value=this.join(p)}else m.value=this.join(n.slice(a,a+m.count));a+=m.count,m.added||(c+=m.count)}}return o}};var $e=class extends Se{static{d(this,"LineDiff")}constructor(){super(...arguments),this.tokenize=_t}equals(e,n,t){return t.ignoreWhitespace?((!t.newlineIsToken||!e.includes(`
|
|
2
2
|
`))&&(e=e.trim()),(!t.newlineIsToken||!n.includes(`
|
|
3
3
|
`))&&(n=n.trim())):t.ignoreNewlineAtEof&&!t.newlineIsToken&&(e.endsWith(`
|
|
4
4
|
`)&&(e=e.slice(0,-1)),n.endsWith(`
|
|
5
|
-
`)&&(n=n.slice(0,-1))),super.equals(e,n,t)}},
|
|
6
|
-
`));let n=[],t=s.split(/(\n|\r\n)/);t[t.length-1]||t.pop();for(let o=0;o<t.length;o++){let r=t[o];o%2&&!e.newlineIsToken?n[n.length-1]+=r:n.push(r)}return n}d(
|
|
7
|
-
`;)n+=1;return n},"
|
|
5
|
+
`)&&(n=n.slice(0,-1))),super.equals(e,n,t)}},rt=new $e;function Pe(s,e,n){return rt.diff(s,e,n)}d(Pe,"diffLines");function _t(s,e){e.stripTrailingCr&&(s=s.replace(/\r\n/g,`
|
|
6
|
+
`));let n=[],t=s.split(/(\n|\r\n)/);t[t.length-1]||t.pop();for(let o=0;o<t.length;o++){let r=t[o];o%2&&!e.newlineIsToken?n[n.length-1]+=r:n.push(r)}return n}d(_t,"tokenize");var Tt="x",st=" ",It={'"':'"',"'":"'","[":"]","`":"`"},ft=d((s,e)=>{let n=e+2;for(;n<s.length&&s[n]!==`
|
|
7
|
+
`;)n+=1;return n},"nt"),ht=d((s,e)=>{let n=s.indexOf("*/",e+2);return n===-1?-1:n+2},"st"),pt=d(s=>{let e=s.split(""),n=0;for(;n<s.length;){let t=s[n]??"",o=It[t];if(t==="-"&&s[n+1]==="-"){let r=ft(s,n);e.fill(st,n,r),n=r}else if(t==="/"&&s[n+1]==="*"){let r=ht(s,n);if(r===-1)return;e.fill(st,n,r),n=r}else if(o!==void 0){let r=n+1;for(;r<s.length;)if(s[r]!==o)r+=1;else if(o!=="]"&&s[r+1]===o)r+=2;else break;if(r>=s.length)return;e.fill(Tt,n,r+1),n=r+1}else n+=1}for(let t=0;t<s.length;t+=1)s[t]===`
|
|
8
8
|
`&&(e[t]=`
|
|
9
|
-
`);return e.join("")},"
|
|
10
|
-
|
|
11
|
-
`,e);return t===-1?s.length:t}if(n==="/"&&s[e+1]==="*"){let t=s.indexOf("*/",e+2);return t===-1?s.length:t+2}return-1},"Qt"),Qt=d(s=>{let e="",n=0;for(;n<s.length;){let t=Ft(s,n);t===-1?(e+=s.slice(n,n+1),n+=1):(e+=s.slice(n,t).replaceAll(Wt," "),n=t)}return e},"jt"),Kt=d(s=>{let e=new Set;for(let n of s.matchAll(Ht))e.add((n[1]??"").toLowerCase());return e},"zt"),Ut=d((s,e)=>{let n=new Map;for(let t of s.matchAll(jt)){let o=(t[1]??"").toLowerCase(),r=(t[2]??"").toLowerCase();e.has(o)&&(n.set(o,o),r!==""&&!Bt.has(r)&&n.set(r,o))}return n},"Kt"),ft=d((s,e)=>{let n=Qt(s),t=new Set(e.map(o=>o.toLowerCase()));return{ctes:Kt(n),masked:n,targets:Ut(n,t)}},"nt"),Gt=/^(?:__lunora|sqlite_)/iu,Vt=/\b(?:from|join)\s+([a-z_][\w$]*)/giu,Xt=/\b([a-z_][\w$]*)\.([a-z_][\w$]*)/giu,Yt=new Set(["cross","full","group","having","inner","join","lateral","left","limit","offset","order","right","select","union","where","window"]),Jt=d((s,e,n)=>{let t=[];for(let o of s.matchAll(Vt)){let r=o[1]??"",l=r.toLowerCase();!e.has(l)&&!n.has(l)&&!Yt.has(l)&&!Gt.test(r)&&t.push({length:r.length,message:`unknown table \`${r}\``,offset:o.index+o[0].length-r.length,severity:"error",source:"schema"})}return t},"Jt"),Zt=d((s,e,n)=>{let t=[],o=new Map;for(let[r,l]of Object.entries(e.columns))o.set(r.toLowerCase(),new Set(l.map(i=>i.toLowerCase())));for(let r of s.matchAll(Xt)){let l=(r[1]??"").toLowerCase(),i=r[2]??"",a=n.get(l),c=a===void 0?void 0:o.get(a);c!==void 0&&!c.has(i.toLowerCase())&&t.push({length:i.length,message:`\`${a??""}\` has no column \`${i}\``,offset:r.index+r[0].length-i.length,severity:"error",source:"schema"})}return t},"Xt"),en=/(?<![\w$."])(?:"([a-z_][\w$]*)"|([a-z_][\w$]*))(?![.(])/giu,tn=/\bas\s+"?([a-z_][\w$]*)"?/giu,nn=d((s,e,n,t)=>{let o=[...new Set(n.values())],r=new Map,l=new Set;for(let c of o){for(let m of e.columns[c]??[])l.add(m.toLowerCase());for(let m of e.docFields?.[c]??[])r.set(m.toLowerCase(),m)}if(r.size===0)return[];let i=new Set([...s.matchAll(tn)].map(c=>(c[1]??"").toLowerCase())),a=[];for(let c of s.matchAll(en)){let m=c[1],p=m??c[2]??"",f=p.toLowerCase(),b=r.get(f);b===void 0||l.has(f)||i.has(f)||t.has(f)||n.has(f)||a.push({length:p.length,message:`\`${b}\` is a \`__doc__\` field, not a column \u2014 use \`json_extract(__doc__, '$.${b}')\``,offset:c.index+(m===void 0?0:1),severity:"error",source:"schema"})}return a},"tn"),on=d((s,e)=>{if(s.trim()==="")return[];let n=mt(s),t=new Set(e.tables.map(r=>r.toLowerCase())),o=[];for(let r of n){let{offset:l,rejection:i}=r;if(i!==void 0){o.push({length:i.length,message:i.message,offset:i.offset===void 0?l:l+i.offset,severity:"error",source:"gate"});continue}let{ctes:a,masked:c,targets:m}=ft(r.sql,e.tables);o.push(...[...Jt(c,t,a),...Zt(c,e,m),...nn(c,e,m,a)].map(p=>({...p,offset:p.offset===void 0?l:l+p.offset})))}return o},"nn"),rn=ge(ve.lintSql),ln=600,sn=d((s,e,n)=>{let t=Ce(),[o,r]=(0,H.useState)([]),l=(0,H.useMemo)(()=>on(s,e),[s,e]),i=Je(s,ln),a=l.some(p=>p.source==="gate")||i.trim()==="",c=(0,H.useCallback)(async p=>{try{let f=await t.query(rn,{sql:i},xe(n));p.cancelled||r(f.diagnostics??[])}catch{p.cancelled||r([])}},[t,i,n]);(0,H.useEffect)(()=>{if(a){r([]);return}let p={cancelled:!1};return se(c(p)),()=>{p.cancelled=!0}},[c,a]);let m=i===s;return(0,H.useMemo)(()=>m?[...l,...o]:l,[l,o,m])},"ln"),Te=8,an=["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"],cn=new Set(["AND","BY","HAVING","ON","OR","SELECT","WHERE"]),dn=/[\w$]/,ht=d(s=>s!==void 0&&dn.test(s),"st"),pt=d(s=>{let e=s.length;for(;e>0&&ht(s[e-1]);)e-=1;return s.slice(e)},"ot"),bt=d((s,e)=>{let n=e;for(;n>0&&ht(s[n-1]);)n-=1;return{end:e,start:n,text:s.slice(n,e)}},"lt"),rt=d((s,e)=>{let n=s.slice(0,e).trimEnd();return n.endsWith(".")||cn.has(pt(n).toUpperCase())},"je"),un=d((s,e,n)=>{let t=s.slice(0,e);if(!t.endsWith("."))return;let o=pt(t.slice(0,-1));if(o!=="")return ft(s,n).targets.get(o.toLowerCase())??o},"dn"),je=d((s,e)=>s.toLowerCase().startsWith(e.toLowerCase()),"Be"),lt=d((s,e,n,t)=>{let o=[];for(let r of s)if(je(r,e)&&(o.push(t(r)),o.length>=n))break;return o},"ze"),mn=d((s,e,n)=>{let t=new Map;for(let[o,r]of Object.entries(s.columns))for(let l of r)if(je(l,e)&&!t.has(l)&&(t.set(l,o),t.size>=n))return[...t].map(([i,a])=>({detail:a,kind:"column",label:i}));return[...t].map(([o,r])=>({detail:r,kind:"column",label:o}))},"un"),fn=d((s,e,n)=>{let t=bt(s,e),o=un(s,t.start,n.tables);if(o!==void 0){let a=n.columns[o]??n.columns[o.toLowerCase()]??[];return lt(a,t.text,Te,c=>({detail:o,kind:"column",label:c}))}if(t.text===""&&!rt(s,t.start))return[];let r=lt(n.tables,t.text,Te,a=>({kind:"table",label:a})),l=mn(n,t.text,Te),i=an.flatMap(a=>t.text!==""&&je(a,t.text)&&a.toLowerCase()!==t.text.toLowerCase()?[{kind:"keyword",label:a}]:[]);return(rt(s,t.start)?[...l,...r,...i]:[...r,...l,...i]).slice(0,Te)},"fn"),hn=d((s,e,n)=>{let t=bt(s,e),o=s.slice(0,t.start)+n.label+s.slice(t.end);return{caret:t.start+n.label.length,value:o}},"mn"),pn=["boxSizing","borderBottomWidth","borderLeftWidth","borderRightWidth","borderTopWidth","fontFamily","fontSize","fontStyle","fontWeight","letterSpacing","lineHeight","paddingBottom","paddingLeft","paddingRight","paddingTop","tabSize","textIndent","textTransform","width","wordSpacing"],bn=d((s,e)=>{let n=globalThis.getComputedStyle(s),t=globalThis.document.createElement("div"),{style:o}=t;o.position="absolute",o.visibility="hidden",o.whiteSpace="pre-wrap",o.overflowWrap="break-word";for(let a of pn)o[a]=n[a];t.textContent=s.value.slice(0,Math.max(0,e));let r=globalThis.document.createElement("span");r.textContent=s.value.slice(Math.max(0,e))||".",t.append(r),globalThis.document.body.append(t);let l=r.offsetLeft-s.scrollLeft,i=r.offsetTop-s.scrollTop;return t.remove(),{left:l,top:i}},"hn"),gn=d((s,e,n)=>{let t=(0,X.c)(16),[o,r]=(0,H.useState)(null),l;t[0]!==s||t[1]!==e?(l=d((N,h)=>{let S=fn(N,h,s);if(S.length===0){r(null);return}let x=e.current,{left:v,top:y}=x===null?{left:0,top:0}:bn(x,h);r(w=>w!==null&&w.active===0&&w.left===v&&w.top===y&&w.suggestions.length===S.length&&w.suggestions.every((E,I)=>{let T=S.at(I);return E.kind===T?.kind&&E.label===T.label&&E.detail===T.detail})?w:{active:0,left:v,suggestions:S,top:y})},"l"),t[0]=s,t[1]=e,t[2]=l):l=t[2];let i=l,a;t[3]===Symbol.for("react.memo_cache_sentinel")?(a=d(()=>{r(null)},"c"),t[3]=a):a=t[3];let c=a,m;t[4]===Symbol.for("react.memo_cache_sentinel")?(m=d(N=>{r(h=>{if(h===null)return h;let S=h.suggestions.length,x=(h.active+N+S)%S;return{...h,active:x}})},"d"),t[4]=m):m=t[4];let p=m,f;t[5]!==n||t[6]!==o||t[7]!==e?(f=d(N=>{let h=e.current;if(o===null||h===null)return!1;let S=o.suggestions[N??o.active];if(S===void 0)return!1;let x=hn(h.value,h.selectionStart,S);return n(x.value),r(null),requestAnimationFrame(()=>{let v=e.current;v!==null&&(v.focus(),v.setSelectionRange(x.caret,x.caret))}),!0},"f"),t[5]=n,t[6]=o,t[7]=e,t[8]=f):f=t[8];let b=f,g;t[9]!==b?(g=d(()=>b(),"g"),t[9]=b,t[10]=g):g=t[10];let k=g,q;return t[11]!==k||t[12]!==b||t[13]!==i||t[14]!==o?(q={close:c,commit:k,commitAt:b,move:p,refresh:i,state:o},t[11]=k,t[12]=b,t[13]=i,t[14]=o,t[15]=q):q=t[15],q},"bn"),xn={column:"column",keyword:"keyword",table:"table"},vn=20,yn=d(s=>{let e=(0,X.c)(17),{listboxId:n,onPick:t,state:o}=s,r=J(),l;e[0]!==o?(l=o===null?void 0:{left:o.left,top:o.top+vn},e[0]=o,e[1]=l):l=e[1];let i=l;if(o===null)return null;let a;if(e[2]!==n||e[3]!==t||e[4]!==o.active||e[5]!==o.suggestions||e[6]!==r){let m;e[8]!==n||e[9]!==t||e[10]!==o.active||e[11]!==r?(m=d((p,f)=>(0,u.jsxs)("li",{"aria-selected":f===o.active,className:ie("flex cursor-pointer items-center gap-2 px-2 py-1 text-[13px]",f===o.active?"bg-accent text-accent-foreground":"text-foreground"),"data-testid":"sql-autocomplete-item",id:`${n}-opt-${f.toString()}`,onMouseDown:d(b=>{b.preventDefault(),t(f)},"onMouseDown"),role:"option",children:[(0,u.jsx)("span",{className:"truncate font-mono",children:p.label}),p.detail!==void 0&&(0,u.jsx)("span",{className:"ms-auto truncate text-xs text-muted-foreground",children:p.detail}),(0,u.jsx)("span",{className:"shrink-0 font-mono text-[10px] tracking-wide text-muted-foreground/70 uppercase",children:r(xn[p.kind])})]},`${p.kind}:${p.label}`),"d"),e[8]=n,e[9]=t,e[10]=o.active,e[11]=r,e[12]=m):m=e[12],a=o.suggestions.map(m),e[2]=n,e[3]=t,e[4]=o.active,e[5]=o.suggestions,e[6]=r,e[7]=a}else a=e[7];let c;return e[13]!==n||e[14]!==i||e[15]!==a?(c=(0,u.jsx)("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:n,role:"listbox",style:i,children:a}),e[13]=n,e[14]=i,e[15]=a,e[16]=c):c=e[16],c},"vn"),wn=ge(ve.listTables),Sn=ge(ve.readTablePage),qn=d(s=>{let e=(0,X.c)(18),n=Ce(),t;e[0]===Symbol.for("react.memo_cache_sentinel")?(t=[],e[0]=t):t=e[0];let[o,r]=(0,H.useState)(t),l;e[1]===Symbol.for("react.memo_cache_sentinel")?(l={},e[1]=l):l=e[1];let[i,a]=(0,H.useState)(l),c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c={},e[2]=c):c=e[2];let[m,p]=(0,H.useState)(c),f;e[3]===Symbol.for("react.memo_cache_sentinel")?(f=new Set,e[3]=f):f=e[3];let b=(0,H.useRef)(f),g,k;e[4]!==n||e[5]!==s?(g=d(()=>{let v={cancelled:!1};return se((async()=>{try{let y=await n.query(wn,{},xe(s));v.cancelled||(r(y.map(Cn)),a({}),p({}),b.current=new Set)}catch{v.cancelled||(r([]),a({}),p({}),b.current=new Set)}})()),()=>{v.cancelled=!0}},"g"),k=[n,s],e[4]=n,e[5]=s,e[6]=g,e[7]=k):(g=e[6],k=e[7]),(0,H.useEffect)(g,k);let q;e[8]!==n||e[9]!==s?(q=d(v=>{b.current.has(v)||(b.current.add(v),se((async()=>{try{let y=await n.query(Sn,{limit:1,offset:0,table:v},xe(s)),{sqlColumns:w}=y;if(w===void 0){b.current.delete(v);return}let E=new Set(w),I=y.columns.filter(T=>!E.has(T));a(T=>({...T,[v]:w})),p(T=>({...T,[v]:I}))}catch{b.current.delete(v)}})()))},"v"),e[8]=n,e[9]=s,e[10]=q):q=e[10];let N=q,h;e[11]!==i||e[12]!==m||e[13]!==o?(h={columns:i,docFields:m,tables:o},e[11]=i,e[12]=m,e[13]=o,e[14]=h):h=e[14];let S=h,x;return e[15]!==N||e[16]!==S?(x={probe:N,schema:S},e[15]=N,e[16]=S,e[17]=x):x=e[17],x},"wn"),Oe=/\b(?:from|join|update|into)\s+([a-z_][\w$]*)|\b([a-z_][\w$]*)\s*\./gi,kn=d(s=>{let e=new Set;Oe.lastIndex=0;let n=Oe.exec(s);for(;n!==null;)e.add(n[1]??n[2]),n=Oe.exec(s);return[...e]},"Cn");function Cn(s){return s.name}d(Cn,"kn");var Nn=d(s=>(s.metaKey||s.ctrlKey)&&!s.shiftKey&&!s.altKey&&s.key.toLowerCase()==="i","Nn"),En=d(s=>{let e=(0,X.c)(44),{inlineEditEnabled:n,onSubmit:t,probe:o,schema:r,setDraft:l}=s,i=(0,H.useId)(),[a,c]=(0,H.useState)(null),m=(0,H.useRef)(null),p=(0,H.useRef)(null),f=(0,H.useRef)(null),b=gn(r,f,l),{close:g,commit:k,commitAt:q,move:N,refresh:h,state:S}=b,x;e[0]!==q?(x=d(P=>{q(P)},"x"),e[0]=q,e[1]=x):x=e[1];let v=x,y;e[2]!==h?(y=d(()=>{let P=f.current;P!==null&&P===document.activeElement&&h(P.value,P.selectionStart)},"y"),e[2]=h,e[3]=y):y=e[3];let w;e[4]!==h||e[5]!==r?(w=[h,r],e[4]=h,e[5]=r,e[6]=w):w=e[6],(0,H.useEffect)(y,w);let E;e[7]!==o||e[8]!==h||e[9]!==l?(E=d(P=>{let{selectionStart:G,value:Z}=P.target;l(Z),c(null);for(let V of kn(Z))o(V);h(Z,G)},"w"),e[7]=o,e[8]=h,e[9]=l,e[10]=E):E=e[10];let I=E,T;e[11]!==h?(T=d(P=>{let G=P.currentTarget;h(G.value,G.selectionStart)},"q"),e[11]=h,e[12]=T):T=e[12];let L=T,C;e[13]!==g||e[14]!==k||e[15]!==N?(C=d(P=>P.key==="ArrowDown"?(P.preventDefault(),N(1),!0):P.key==="ArrowUp"?(P.preventDefault(),N(-1),!0):P.key==="Escape"?(P.preventDefault(),g(),!0):(P.key==="Enter"||P.key==="Tab")&&!P.metaKey&&!P.ctrlKey&&k()?(P.preventDefault(),!0):!1,"E"),e[13]=g,e[14]=k,e[15]=N,e[16]=C):C=e[16];let R=C,_;e[17]!==S||e[18]!==g||e[19]!==n||e[20]!==R||e[21]!==t?(_=d(P=>{if(!(S!==null&&R(P))){if((P.metaKey||P.ctrlKey)&&P.key==="Enter"){P.preventDefault(),t();return}if(n&&Nn(P)){P.preventDefault(),g();let{selectionEnd:G,selectionStart:Z,value:V}=P.currentTarget,[le,ae]=Z===G?[0,V.length]:[Z,G];c({end:ae,start:le,text:V.slice(le,ae)})}}},"L"),e[17]=S,e[18]=g,e[19]=n,e[20]=R,e[21]=t,e[22]=_):_=e[22];let M=_,z;e[23]!==g?(z=d(()=>{requestAnimationFrame(()=>{g()})},"$"),e[23]=g,e[24]=z):z=e[24];let j=z,B;e[25]===Symbol.for("react.memo_cache_sentinel")?(B=d(P=>{let{scrollLeft:G,scrollTop:Z}=P.currentTarget;m.current!==null&&(m.current.scrollTop=Z),p.current!==null&&(p.current.scrollTop=Z,p.current.scrollLeft=G)},"B"),e[25]=B):B=e[25];let W=B,$;e[26]===Symbol.for("react.memo_cache_sentinel")?($=d(P=>{let G=f.current;G===null||P.offset===void 0||(G.focus(),G.setSelectionRange(P.offset,P.offset+(P.length??0)))},"P"),e[26]=$):$=e[26];let K=$,O;e[27]===Symbol.for("react.memo_cache_sentinel")?(O=d(()=>{c(null),f.current?.focus()},"M"),e[27]=O):O=e[27];let D=O,A;e[28]!==a||e[29]!==l?(A=d(P=>{let G=f.current;if(a===null||G===null)return;let{end:Z,start:V,text:le}=a;if(G.value.slice(V,Z)!==le){c(null);return}l(G.value.slice(0,V)+P+G.value.slice(Z)),c(null),G.focus(),requestAnimationFrame(()=>{G.setSelectionRange(V,V+P.length)})},"D"),e[28]=a,e[29]=l,e[30]=A):A=e[30];let Q=A,F;e[31]!==I||e[32]!==j||e[33]!==M||e[34]!==L?(F={onBlur:j,onChange:I,onKeyDown:M,onScroll:W,onSelect:L},e[31]=I,e[32]=j,e[33]=M,e[34]=L,e[35]=F):F=e[35];let ee;return e[36]!==Q||e[37]!==S||e[38]!==g||e[39]!==a||e[40]!==i||e[41]!==v||e[42]!==F?(ee={acceptInlineEdit:Q,autocompleteState:S,closeAutocomplete:g,closeInlineEdit:D,inlineEdit:a,handlers:F,listboxId:i,onPickSuggestion:v,editorRef:f,gutterRef:m,overlayRef:p,revealDiagnostic:K},e[36]=Q,e[37]=S,e[38]=g,e[39]=a,e[40]=i,e[41]=v,e[42]=F,e[43]=ee):ee=e[43],ee},"En"),Tn="lunora-studio-sql-tabs",Ln="lunora-studio-sql-active-tab",He=12,qe=d((s="",e="")=>({activeId:null,id:Me("tab"),name:e,sql:s}),"Se"),In=d(()=>Ee(Ln,""),"Rn"),Rn=d(s=>{let e=(0,X.c)(16),[n,t]=Ne(Tn),[o,r]=In(),[l]=(0,H.useState)(s),i,a;e[0]!==l||e[1]!==t||e[2]!==n.length?(i=d(()=>{n.length===0&&t([l])},"i"),a=[l,t,n.length],e[0]=l,e[1]=t,e[2]=n.length,e[3]=i,e[4]=a):(i=e[3],a=e[4]),(0,H.useEffect)(i,a);let c;e[5]!==l||e[6]!==n?(c=n.length===0?[l]:n,e[5]=l,e[6]=n,e[7]=c):c=e[7];let m=c,p;e[8]!==o||e[9]!==m?(p=m.some(g=>g.id===o)?o:m[0]?.id??"",e[8]=o,e[9]=m,e[10]=p):p=e[10];let f=p,b;return e[11]!==f||e[12]!==r||e[13]!==t||e[14]!==m?(b={activeId:f,setActiveId:r,setTabs:t,tabs:m},e[11]=f,e[12]=r,e[13]=t,e[14]=m,e[15]=b):b=e[15],b},"In"),gt=d(s=>s.activeId===null&&s.sql.trim()!=="","rt"),_n=d((s,e)=>[...s,e].slice(-He),"Ln"),Dn=d((s,e,n)=>{let t=s.findIndex(r=>r.id===e);if(t===-1)return{activeId:s[0]?.id??"",tabs:[...s]};let o=s.filter(r=>r.id!==e);if(o.length===0){let r=n();return{activeId:r.id,tabs:[r]}}return{activeId:o[Math.min(t,o.length-1)].id,tabs:o}},"An"),Mn=d((s,e)=>{let n=s.filter(t=>t.id===e);return n.length===0?{activeId:s[0]?.id??"",tabs:[...s]}:{activeId:e,tabs:n}},"_n"),An=d((s,e,n)=>{let t=s.findIndex(r=>r.id===e);if(t===-1)return{activeId:n,tabs:[...s]};let o=s.slice(0,t+1);return{activeId:o.some(r=>r.id===n)?n:e,tabs:o}},"Dn"),Pn=d(s=>{let e=s();return{activeId:e.id,tabs:[e]}},"On"),$n=d((s,e,n)=>{if(s==="others")return e.filter(t=>t.id!==n);if(s==="right"){let t=e.findIndex(o=>o.id===n);return t===-1?[]:e.slice(t+1)}return[...e]},"Mn"),st={error:null,pane:"results",result:null,running:!1},On=d(s=>{let e=(0,X.c)(69),{activeId:n,setActiveId:t,setTabs:o,tabs:r}=Rn(s),l;e[0]===Symbol.for("react.memo_cache_sentinel")?(l={},e[0]=l):l=e[0];let[i,a]=(0,H.useState)(l),[c,m]=(0,H.useState)(null),[p,f]=(0,H.useState)(null),b;e[1]!==n||e[2]!==r?(b=r.find(Y=>Y.id===n)??r[0]??qe(),e[1]=n,e[2]=r,e[3]=b):b=e[3];let g=b,k=i[g.id]??st,q;e[4]!==g.id||e[5]!==o?(q=d(Y=>{o(te=>te.map(ne=>ne.id===g.id?{...ne,...Y}:ne))},"v"),e[4]=g.id,e[5]=o,e[6]=q):q=e[6];let N=q,h;e[7]!==g.id?(h=d(Y=>{a(te=>{let ne=te[g.id]??st;return{...te,[g.id]:{...ne,...Y}}})},"p"),e[7]=g.id,e[8]=h):h=e[8];let S=h,x;e[9]!==t||e[10]!==o||e[11]!==r.length?(x=d(Y=>{if(r.length>=He)return!1;let te=qe(Y);return o(ne=>_n(ne,te)),t(te.id),!0},"x"),e[9]=t,e[10]=o,e[11]=r.length,e[12]=x):x=e[12];let v=x,y;e[13]!==v?(y=d(()=>{v("")},"y"),e[13]=v,e[14]=y):y=e[14];let w=y,E;e[15]!==t||e[16]!==o?(E=d(Y=>{m(null),f(null),o(Y.tabs),t(Y.activeId);let te=new Set(Y.tabs.map(zn));a(ne=>Object.fromEntries(Object.entries(ne).filter(U=>{let[oe]=U;return te.has(oe)})))},"w"),e[15]=t,e[16]=o,e[17]=E):E=e[17];let I=E,T;e[18]!==I||e[19]!==r?(T=d(Y=>{I(Dn(r,Y,qe))},"q"),e[18]=I,e[19]=r,e[20]=T):T=e[20];let L=T,C;e[21]!==n||e[22]!==I||e[23]!==r?(C=d((Y,te)=>{I(Y==="others"?Mn(r,te):Y==="right"?An(r,te,n):Pn(qe))},"E"),e[21]=n,e[22]=I,e[23]=r,e[24]=C):C=e[24];let R=C,_;e[25]!==R||e[26]!==c||e[27]!==r?(_=d(Y=>{c!==null&&($n(Y,r,c.id).some(jn)?f(Y):R(Y,c.id))},"L"),e[25]=R,e[26]=c,e[27]=r,e[28]=_):_=e[28];let M=_,z;e[29]===Symbol.for("react.memo_cache_sentinel")?(z=d((Y,te)=>{te.preventDefault(),f(null),m({id:Y,x:te.clientX,y:te.clientY})},"$"),e[29]=z):z=e[29];let j=z,B;e[30]===Symbol.for("react.memo_cache_sentinel")?(B=d(()=>{m(null),f(null)},"B"),e[30]=B):B=e[30];let W=B,$;e[31]===Symbol.for("react.memo_cache_sentinel")?($=d(Y=>{Y.preventDefault(),m(null),f(null)},"P"),e[31]=$):$=e[31];let K=$,O;e[32]!==M?(O=d(()=>{M("others")},"M"),e[32]=M,e[33]=O):O=e[33];let D=O,A;e[34]!==M?(A=d(()=>{M("right")},"D"),e[34]=M,e[35]=A):A=e[35];let Q=A,F;e[36]!==M?(F=d(()=>{M("all")},"j"),e[36]=M,e[37]=F):F=e[37];let ee=F,P;e[38]!==R||e[39]!==p||e[40]!==c?(P=d(()=>{c!==null&&p!==null&&R(p,c.id),f(null)},"O"),e[38]=R,e[39]=p,e[40]=c,e[41]=P):P=e[41];let G=P,Z;e[42]===Symbol.for("react.memo_cache_sentinel")?(Z=d(()=>{f(null)},"X"),e[42]=Z):Z=e[42];let V=Z,le;e[43]!==c?(le=c===null?void 0:{left:c.x,top:c.y},e[43]=c,e[44]=le):le=e[44];let ae=le,ue;e[45]!==o?(ue=d(Y=>{o(te=>te.map(ne=>ne.activeId===Y?{...ne,activeId:null}:ne))},"pe"),e[45]=o,e[46]=ue):ue=e[46];let pe=ue,me;e[47]!==o?(me=d((Y,te)=>{o(ne=>ne.map(U=>U.id===Y?{...U,name:te}:U))},"he"),e[47]=o,e[48]=me):me=e[48];let be=me,fe;return e[49]!==g||e[50]!==n||e[51]!==w||e[52]!==L||e[53]!==G||e[54]!==ee||e[55]!==D||e[56]!==Q||e[57]!==v||e[58]!==k||e[59]!==S||e[60]!==N||e[61]!==p||e[62]!==be||e[63]!==t||e[64]!==c||e[65]!==ae||e[66]!==r||e[67]!==pe?(fe={activeTab:g,activeTabId:n,addEditorTab:w,cancelBulk:V,closeEditorTab:L,closeTabMenu:W,confirmBulk:G,menuStyle:ae,onBackdropContextMenu:K,onCloseAll:ee,onCloseOthers:D,onCloseToRight:Q,openEditorTab:v,openTabMenu:j,output:k,patchActiveOutput:S,patchActiveTab:N,pendingBulk:p,renameTab:be,setActiveTabId:t,tabMenu:c,tabs:r,unlinkQuery:pe},e[49]=g,e[50]=n,e[51]=w,e[52]=L,e[53]=G,e[54]=ee,e[55]=D,e[56]=Q,e[57]=v,e[58]=k,e[59]=S,e[60]=N,e[61]=p,e[62]=be,e[63]=t,e[64]=c,e[65]=ae,e[66]=r,e[67]=pe,e[68]=fe):fe=e[68],fe},"$n");function zn(s){return s.id}d(zn,"Bn");function jn(s){return gt(s)}d(jn,"Pn");var Hn="lunora-studio-sql-queries",he="lunora-studio-sql-history",Bn="lunora-studio-sql-remember-history",Wn=25,Fn=d(s=>{let e=(0,X.c)(44),{loadIntoActiveTab:n,unlinkQuery:t}=s,o=J(),[r,l]=Ne(Hn),[i,a]=Ee(Bn,!1),[c,m]=Ne(he,i?"local":"session"),p,f;e[0]!==i?(p=d(()=>{i||we(he,"local")},"m"),f=[i],e[0]=i,e[1]=p,e[2]=f):(p=e[1],f=e[2]),(0,H.useEffect)(p,f);let[b,g]=(0,H.useState)(""),k=(0,H.useRef)(null),q;e[3]!==m?(q=d(D=>{m(A=>A[0]?.sql===D?A:[{at:Date.now(),sql:D},...A.filter(Q=>Q.sql!==D)].slice(0,Wn))},"v"),e[3]=m,e[4]=q):q=e[4];let N=q,h;e[5]!==n||e[6]!==l||e[7]!==o?(h=d(()=>{let D={id:Me("q"),name:o("Untitled query"),sql:""};l(A=>[D,...A]),n("",D.id)},"p"),e[5]=n,e[6]=l,e[7]=o,e[8]=h):h=e[8];let S=h,x;e[9]!==n||e[10]!==r?(x=d(D=>{let A=r.find(Q=>Q.id===D);A!==void 0&&(n(A.sql,D),k.current?.querySelector(`[data-testid="sql-query-${D}"]`)?.scrollIntoView({block:"nearest"}))},"x"),e[9]=n,e[10]=r,e[11]=x):x=e[11];let v=x,y;e[12]!==l||e[13]!==t?(y=d(D=>{l(A=>A.filter(Q=>Q.id!==D)),t(D)},"y"),e[12]=l,e[13]=t,e[14]=y):y=e[14];let w=y,E;e[15]!==n?(E=d(D=>{n(D.currentTarget.dataset.sql??"",null)},"w"),e[15]=n,e[16]=E):E=e[16];let I=E,T;e[17]!==n?(T=d(D=>{n(D.currentTarget.dataset.sql??"",null)},"q"),e[17]=n,e[18]=T):T=e[18];let L=T,C;e[19]!==m?(C=d(()=>{m([]),we(he,"local"),we(he,"session")},"E"),e[19]=m,e[20]=C):C=e[20];let R=C,_;e[21]!==c||e[22]!==a?(_=d(D=>{Ue(he,c,D?"local":"session"),D||we(he,"local"),a(D)},"L"),e[21]=c,e[22]=a,e[23]=_):_=e[23];let M=_,z;e[24]===Symbol.for("react.memo_cache_sentinel")?(z=d(D=>{g(D.target.value)},"$"),e[24]=z):z=e[24];let j=z,B;e[25]!==l?(B=d((D,A,Q)=>{l(F=>F.map(ee=>ee.id===D?{id:ee.id,name:A,sql:ee.sql,...Q===""?{}:{description:Q}}:ee))},"B"),e[25]=l,e[26]=B):B=e[26];let W=B,$;e[27]!==l?($=d((D,A)=>{l(Q=>Q.map(F=>F.id===D?{...F,sql:A}:F))},"P"),e[27]=l,e[28]=$):$=e[28];let K=$,O;return e[29]!==R||e[30]!==w||e[31]!==c||e[32]!==L||e[33]!==I||e[34]!==S||e[35]!==r||e[36]!==N||e[37]!==i||e[38]!==W||e[39]!==b||e[40]!==v||e[41]!==M||e[42]!==K?(O={clearHistory:R,deleteQuery:w,history:c,listRef:k,loadFromHistory:L,loadTemplate:I,newQuery:S,onSearchChange:j,queries:r,recordHistory:N,rememberHistory:i,renameQuery:W,search:b,selectQuery:v,setRememberHistory:M,updateQuerySql:K},e[29]=R,e[30]=w,e[31]=c,e[32]=L,e[33]=I,e[34]=S,e[35]=r,e[36]=N,e[37]=i,e[38]=W,e[39]=b,e[40]=v,e[41]=M,e[42]=K,e[43]=O):O=e[43],O},"Qn"),Be="p-3 font-mono text-xs leading-5 whitespace-pre-wrap break-words",Qn=d((s,e)=>{let n=[];for(let o of s){if(o.offset===void 0||o.length===void 0||o.length<=0)continue;let r=Math.max(0,Math.min(o.offset,e)),l=Math.max(r,Math.min(o.offset+o.length,e));r!==l&&n.push({end:l,severity:o.severity,start:r})}n.sort((o,r)=>o.start-r.start);let t=[];for(let o of n)o.start>=(t.at(-1)?.end??0)&&t.push(o);return t},"jn"),Kn=d(s=>{let e=(0,X.c)(51),{rpc:n,failed:t,onGenerated:o}=s,r=J(),[l,i]=(0,H.useState)("");if(n.unavailable)return null;let a;e[0]!==n?(a=n.pending("sql"),e[0]=n,e[1]=a):a=e[1];let c=a,m;if(e[2]!==t||e[3]!==o||e[4]!==c||e[5]!==l||e[6]!==n||e[7]!==r){let p=n.reason("sql"),f;e[9]!==t||e[10]!==o||e[11]!==l||e[12]!==n?(f=d(L=>{let C=l.trim();C===""&&!L||se((async()=>{let R=await n.generate(C===""?"fix the failing statement":C,L?t:void 0);R!==void 0&&o(R)})())},"f"),e[9]=t,e[10]=o,e[11]=l,e[12]=n,e[13]=f):f=e[13];let b=f,g;e[14]!==r?(g=r("Describe the query you want"),e[14]=r,e[15]=g):g=e[15];let k;e[16]===Symbol.for("react.memo_cache_sentinel")?(k=d(L=>{i(L.target.value)},"R"),e[16]=k):k=e[16];let q;e[17]!==b?(q=d(L=>{L.key==="Enter"&&(L.preventDefault(),b(!1))},"v"),e[17]=b,e[18]=q):q=e[18];let N;e[19]!==r?(N=r("Describe the query you want"),e[19]=r,e[20]=N):N=e[20];let h;e[21]!==c||e[22]!==l||e[23]!==g||e[24]!==q||e[25]!==N?(h=(0,u.jsx)(ye,{"aria-label":g,className:"h-7 flex-1 text-xs","data-testid":"sql-assistant-prompt",disabled:c,onChange:k,onKeyDown:q,placeholder:N,value:l}),e[21]=c,e[22]=l,e[23]=g,e[24]=q,e[25]=N,e[26]=h):h=e[26];let S=c&&"opacity-60",x;e[27]!==S?(x=ie("rounded-md border border-border px-2 py-1 text-xs outline-none transition-colors hover:bg-accent focus-visible:bg-accent",S),e[27]=S,e[28]=x):x=e[28];let v;e[29]!==c||e[30]!==l?(v=c||l.trim()==="",e[29]=c,e[30]=l,e[31]=v):v=e[31];let y;e[32]!==b?(y=d(()=>{b(!1)},"y"),e[32]=b,e[33]=y):y=e[33];let w;e[34]!==c||e[35]!==r?(w=r(c?"Thinking\u2026":"Draft SQL"),e[34]=c,e[35]=r,e[36]=w):w=e[36];let E;e[37]!==x||e[38]!==v||e[39]!==y||e[40]!==w?(E=(0,u.jsx)("button",{className:x,"data-testid":"sql-assistant-generate",disabled:v,onClick:y,type:"button",children:w}),e[37]=x,e[38]=v,e[39]=y,e[40]=w,e[41]=E):E=e[41];let I;e[42]!==t||e[43]!==c||e[44]!==b||e[45]!==r?(I=t!==void 0&&(0,u.jsx)("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:d(()=>{b(!0)},"onClick"),type:"button",children:r("Fix this")}),e[42]=t,e[43]=c,e[44]=b,e[45]=r,e[46]=I):I=e[46];let T;e[47]!==E||e[48]!==I||e[49]!==h?(T=(0,u.jsxs)("div",{className:"flex items-center gap-2",children:[h,E,I]}),e[47]=E,e[48]=I,e[49]=h,e[50]=T):T=e[50],m=(0,u.jsxs)("div",{className:"flex flex-col gap-1 border-b border-border px-3 py-2","data-testid":"sql-assistant",children:[T,p!==void 0&&(0,u.jsx)("p",{className:"text-[11px] text-muted-foreground","data-testid":"sql-assistant-reason",role:"status",children:Ae(p,r)})]}),e[2]=t,e[3]=o,e[4]=c,e[5]=l,e[6]=n,e[7]=r,e[8]=m}else m=e[8];return m},"zn"),Un=d(s=>{let e=(0,X.c)(8),{diagnostics:n,draft:t,scrollRef:o}=s,r,l;if(e[0]!==n||e[1]!==t){l=Symbol.for("react.early_return_sentinel");e:{let c=Qn(n,t.length);if(c.length===0){l=null;break e}r=[];let m=0;for(let[p,f]of c.entries())f.start>m&&r.push(t.slice(m,f.start)),r.push((0,u.jsx)("span",{className:ie("decoration-wavy underline underline-offset-4",f.severity==="error"?"decoration-destructive":"decoration-amber-500"),children:t.slice(f.start,f.end)},`${f.start.toString()}-${p.toString()}`)),m=f.end;r.push(t.slice(m))}e[0]=n,e[1]=t,e[2]=r,e[3]=l}else r=e[2],l=e[3];if(l!==Symbol.for("react.early_return_sentinel"))return l;let i;e[4]===Symbol.for("react.memo_cache_sentinel")?(i=ie("pointer-events-none absolute inset-0 overflow-hidden text-transparent",Be),e[4]=i):i=e[4];let a;return e[5]!==r||e[6]!==o?(a=(0,u.jsx)("div",{"aria-hidden":"true",className:i,"data-testid":"sql-diagnostics-overlay",ref:o,children:r}),e[5]=r,e[6]=o,e[7]=a):a=e[7],a},"Kn"),Gn={gate:"read-only",plan:"plan",schema:"schema",syntax:"syntax"},Vn=d(s=>{let e=(0,X.c)(10),{diagnostics:n,onSelect:t}=s,o=J();if(n.length===0)return null;let r;e[0]!==o?(r=o("SQL problems"),e[0]=o,e[1]=r):r=e[1];let l;if(e[2]!==n||e[3]!==t){let a;e[5]!==t?(a=d((c,m)=>(0,u.jsx)("li",{children:(0,u.jsxs)("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:d(()=>{t(c)},"onClick"),type:"button",children:[(0,u.jsx)("span",{className:ie("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:Gn[c.source]}),(0,u.jsx)("span",{className:"min-w-0 text-muted-foreground",children:c.message})]})},`${c.source}-${(c.offset??m).toString()}-${m.toString()}`),"c"),e[5]=t,e[6]=a):a=e[6],l=n.map(a),e[2]=n,e[3]=t,e[4]=l}else l=e[4];let i;return e[7]!==r||e[8]!==l?(i=(0,u.jsx)("ul",{"aria-label":r,className:"max-h-24 shrink-0 overflow-y-auto border-t border-border bg-muted/30","data-testid":"sql-problems",children:l}),e[7]=r,e[8]=l,e[9]=i):i=e[9],i},"Yn"),Xn=d(s=>(s.endsWith(`
|
|
9
|
+
`);return e.join("")},"ot"),Rt="__lunora_admin_tokens__",je=new Set([Rt,"dbstat","sqlite_dbpage"]),bt="pragma_",Dt=d(s=>/[\p{L}_]/u.test(s)||(s.codePointAt(0)??0)>127,"It"),Mt=d(s=>/[\p{L}\p{N}_$]/u.test(s)||(s.codePointAt(0)??0)>127,"At"),At=/^pragma_\w+$/u,$t=d(s=>je.has(s)||At.test(s)?s:void 0,"Ot"),lt=d(s=>{if(je.has(s)||s.startsWith(bt))return s},"Ke"),it=d((s,e,n)=>{let t="",o=e+1;for(;o<s.length;){let r=s[o];if(r===n){if(n!=="]"&&s[o+1]===n){t+=n,o+=2;continue}return{end:o+1,text:t}}t+=r,o+=1}},"Ue"),at={'"':'"',"`":"`","[":"]"},Oe=d(s=>{let e=s.toLowerCase().replaceAll(/["'`[\]]/gu,"");for(let n of je)if(e.includes(n))return n;return/\bpragma_/u.test(e)?bt:void 0},"Ae"),Pt=d(s=>{let e=0;for(;e<s.length;){let n=s[e];if(/\s/u.test(n))e+=1;else if(n==="-"&&s[e+1]==="-"){let t=s.indexOf(`
|
|
10
|
+
`,e);e=t===-1?s.length:t+1}else if(n==="/"&&s[e+1]==="*"){let t=s.indexOf("*/",e+2);if(t===-1)return Oe(s.slice(e+2));e=t+2}else if(n==="'"){let t=it(s,e,"'");if(t===void 0)return Oe(s.slice(e+1));let o=$t(t.text.trim().toLowerCase());if(o!==void 0)return o;e=t.end}else if(n in at){let t=it(s,e,at[n]);if(t===void 0)return Oe(s.slice(e+1));let o=lt(t.text.toLowerCase());if(o!==void 0)return o;e=t.end}else if(Dt(n)){let t=e+1;for(;t<s.length&&Mt(s[t]);)t+=1;let o=s.slice(e,t).toLowerCase(),r=lt(o);if(r!==void 0)return r;e=t}else e+=1}},"Mt"),Ot=/^(?:explain\s+(?:query\s+plan\s+)?)?(?:select|with)\b/iu,zt=/\b(?:alter|attach|create|delete|detach|drop|insert|pragma|reindex|truncate|update|vacuum)\b|\breplace\b(?!\s*\()/iu,Ht=/^\w+/u,jt=/;\s*$/u,Wt=/\s/u,gt=d(s=>{let e=0;for(;e<s.length;){let n=s[e];if(n!==void 0&&Wt.test(n))e+=1;else if(n==="-"&&s[e+1]==="-")e=ft(s,e);else if(n==="/"&&s[e+1]==="*"){let t=ht(s,e);if(t===-1)break;e=t}else break}return e},"rt"),Bt=d(s=>{let e=gt(s),n=s.slice(e).trimEnd();if(n==="")return{code:"SQL_EMPTY",message:"the query is empty"};let t=(pt(n)??n).replace(jt,""),o=n.slice(0,t.length),r=t.indexOf(";");if(r!==-1)return{code:"SQL_MULTIPLE_STATEMENTS",length:1,message:"only a single statement may be run",offset:e+r};let l="the SQL editor is read-only \u2014 only SELECT / WITH / EXPLAIN queries are allowed";if(!Ot.test(o))return{code:"SQL_NOT_READONLY",length:Ht.exec(o)?.[0].length??1,message:l,offset:e};let i=zt.exec(o);if(i!==null)return{code:"SQL_NOT_READONLY",length:i[0].length,message:`${l} (\`${i[0].toUpperCase()}\` is not allowed)`,offset:e+i.index};let a=Pt(o);if(a!==void 0)return{code:"SQL_NOT_READONLY",message:`\`${a}\` is reserved framework storage and cannot be queried`}},"Ft"),Ft=/^explain\b/iu,Qt=d(s=>Ft.test(s.slice(gt(s)))?s:`EXPLAIN QUERY PLAN ${s}`,"jt"),He=d((s,e)=>{let n=s.trim();if(n==="")return[];let t=e+s.indexOf(n),o=Bt(n);return o?.code==="SQL_EMPTY"?[]:[o===void 0?{offset:t,sql:n}:{offset:t,rejection:o,sql:n}]},"Me"),xt=d(s=>{let e=pt(s);if(e===void 0)return He(s,0);let n=[],t=0;for(let o=0;o<=e.length;o+=1)o!==e.length&&e[o]!==";"||(n.push(...He(s.slice(t,o),t)),t=o+1);return n},"it"),Kt=["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"],Ut=["FROM","WHERE","ORDER BY","GROUP BY","HAVING","LIMIT","OFFSET","UNION","JOIN","LEFT JOIN","RIGHT JOIN","INNER JOIN","OUTER JOIN","CROSS JOIN"],Re=String.fromCodePoint(0),Gt=new RegExp(`${Re}${String.raw`(\d+)`}${Re}`,"gu"),Xt=Kt.map(s=>({pattern:new RegExp(String.raw`\b${s.replaceAll(" ",String.raw`\s+`)}\b`,"giu"),replacement:s})),Vt=Ut.map(s=>({pattern:new RegExp(String.raw`\s+${s.replaceAll(" ",String.raw`\s+`)}\b`,"gu"),replacement:`
|
|
11
|
+
${s}`})),Yt=d(s=>{let e=[],n=s.replaceAll(/'(?:[^']|'')*'/gu,t=>(e.push(t),`${Re}${(e.length-1).toString()}${Re}`)).replaceAll(/\s+/gu," ").trim();for(let{pattern:t,replacement:o}of Xt)n=n.replaceAll(t,o);for(let{pattern:t,replacement:o}of Vt)n=n.replaceAll(t,o);return n=n.replaceAll(Gt,(t,o)=>e[Number(o)]??""),n},"Vt"),Jt=/\b(?:from|join)\s+([a-z_][\w$]*)(?:\s+(?:as\s+)?([a-z_][\w$]*))?/giu,Zt=/(?:\bwith\s+(?:recursive\s+)?|,\s*)([a-z_][\w$]*)\s+as\s*\(/giu,en=new Set(["cross","full","group","having","inner","join","left","limit","offset","on","order","right","union","using","where","window"]),tn=/[^\n]/gu,nn=d((s,e)=>{let n=s[e];if(n==="'"){let t=e+1;for(;t<s.length&&s[t]!=="'";)t+=1;return Math.min(t+1,s.length)}if(n==="-"&&s[e+1]==="-"){let t=s.indexOf(`
|
|
12
|
+
`,e);return t===-1?s.length:t}if(n==="/"&&s[e+1]==="*"){let t=s.indexOf("*/",e+2);return t===-1?s.length:t+2}return-1},"tn"),on=d(s=>{let e="",n=0;for(;n<s.length;){let t=nn(s,n);t===-1?(e+=s.slice(n,n+1),n+=1):(e+=s.slice(n,t).replaceAll(tn," "),n=t)}return e},"nn"),rn=d(s=>{let e=new Set;for(let n of s.matchAll(Zt))e.add((n[1]??"").toLowerCase());return e},"sn"),sn=d((s,e)=>{let n=new Map;for(let t of s.matchAll(Jt)){let o=(t[1]??"").toLowerCase(),r=(t[2]??"").toLowerCase();e.has(o)&&(n.set(o,o),r!==""&&!en.has(r)&&n.set(r,o))}return n},"on"),vt=d((s,e)=>{let n=on(s),t=new Set(e.map(o=>o.toLowerCase()));return{ctes:rn(n),masked:n,targets:sn(n,t)}},"at"),ln=/^(?:__lunora|sqlite_)/iu,an=/\b(?:from|join)\s+([a-z_][\w$]*)/giu,cn=/\b([a-z_][\w$]*)\.([a-z_][\w$]*)/giu,dn=new Set(["cross","full","group","having","inner","join","lateral","left","limit","offset","order","right","select","union","where","window"]),un=d((s,e,n)=>{let t=[];for(let o of s.matchAll(an)){let r=o[1]??"",l=r.toLowerCase();!e.has(l)&&!n.has(l)&&!dn.has(l)&&!ln.test(r)&&t.push({length:r.length,message:`unknown table \`${r}\``,offset:o.index+o[0].length-r.length,severity:"error",source:"schema"})}return t},"dn"),mn=d((s,e,n)=>{let t=[],o=new Map;for(let[r,l]of Object.entries(e.columns))o.set(r.toLowerCase(),new Set(l.map(i=>i.toLowerCase())));for(let r of s.matchAll(cn)){let l=(r[1]??"").toLowerCase(),i=r[2]??"",a=n.get(l),c=a===void 0?void 0:o.get(a);c!==void 0&&!c.has(i.toLowerCase())&&t.push({length:i.length,message:`\`${a??""}\` has no column \`${i}\``,offset:r.index+r[0].length-i.length,severity:"error",source:"schema"})}return t},"un"),fn=/(?<![\w$."])(?:"([a-z_][\w$]*)"|([a-z_][\w$]*))(?![.(])/giu,hn=/\bas\s+"?([a-z_][\w$]*)"?/giu,pn=d((s,e,n,t)=>{let o=[...new Set(n.values())],r=new Map,l=new Set;for(let c of o){for(let m of e.columns[c]??[])l.add(m.toLowerCase());for(let m of e.docFields?.[c]??[])r.set(m.toLowerCase(),m)}if(r.size===0)return[];let i=new Set([...s.matchAll(hn)].map(c=>(c[1]??"").toLowerCase())),a=[];for(let c of s.matchAll(fn)){let m=c[1],p=m??c[2]??"",f=p.toLowerCase(),b=r.get(f);b===void 0||l.has(f)||i.has(f)||t.has(f)||n.has(f)||a.push({length:p.length,message:`\`${b}\` is a \`__doc__\` field, not a column \u2014 use \`json_extract(__doc__, '$.${b}')\``,offset:c.index+(m===void 0?0:1),severity:"error",source:"schema"})}return a},"pn"),bn=d((s,e)=>{if(s.trim()==="")return[];let n=xt(s),t=new Set(e.tables.map(r=>r.toLowerCase())),o=[];for(let r of n){let{offset:l,rejection:i}=r;if(i!==void 0){o.push({length:i.length,message:i.message,offset:i.offset===void 0?l:l+i.offset,severity:"error",source:"gate"});continue}let{ctes:a,masked:c,targets:m}=vt(r.sql,e.tables);o.push(...[...un(c,t,a),...mn(c,e,m),...pn(c,e,m,a)].map(p=>({...p,offset:p.offset===void 0?l:l+p.offset})))}return o},"hn"),gn=ge(ve.lintSql),xn=600,vn=d((s,e,n)=>{let t=Ce(),[o,r]=(0,j.useState)([]),l=(0,j.useMemo)(()=>bn(s,e),[s,e]),i=et(s,xn),a=l.some(p=>p.source==="gate")||i.trim()==="",c=(0,j.useCallback)(async p=>{try{let f=await t.query(gn,{sql:i},xe(n));p.cancelled||r(f.diagnostics??[])}catch{p.cancelled||r([])}},[t,i,n]);(0,j.useEffect)(()=>{if(a){r([]);return}let p={cancelled:!1};return le(c(p)),()=>{p.cancelled=!0}},[c,a]);let m=i===s;return(0,j.useMemo)(()=>m?[...l,...o]:l,[l,o,m])},"xn"),Le=8,yn=["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"],wn=new Set(["AND","BY","HAVING","ON","OR","SELECT","WHERE"]),Sn=/[\w$]/,yt=d(s=>s!==void 0&&Sn.test(s),"ct"),wt=d(s=>{let e=s.length;for(;e>0&&yt(s[e-1]);)e-=1;return s.slice(e)},"dt"),St=d((s,e)=>{let n=e;for(;n>0&&yt(s[n-1]);)n-=1;return{end:e,start:n,text:s.slice(n,e)}},"ut"),ct=d((s,e)=>{let n=s.slice(0,e).trimEnd();return n.endsWith(".")||wn.has(wt(n).toUpperCase())},"Ge"),qn=d((s,e,n)=>{let t=s.slice(0,e);if(!t.endsWith("."))return;let o=wt(t.slice(0,-1));if(o!=="")return vt(s,n).targets.get(o.toLowerCase())??o},"wn"),We=d((s,e)=>s.toLowerCase().startsWith(e.toLowerCase()),"We"),dt=d((s,e,n,t)=>{let o=[];for(let r of s)if(We(r,e)&&(o.push(t(r)),o.length>=n))break;return o},"Ve"),kn=d((s,e,n)=>{let t=new Map;for(let[o,r]of Object.entries(s.columns))for(let l of r)if(We(l,e)&&!t.has(l)&&(t.set(l,o),t.size>=n))return[...t].map(([i,a])=>({detail:a,kind:"column",label:i}));return[...t].map(([o,r])=>({detail:r,kind:"column",label:o}))},"Cn"),Cn=d((s,e,n)=>{let t=St(s,e),o=qn(s,t.start,n.tables);if(o!==void 0){let a=n.columns[o]??n.columns[o.toLowerCase()]??[];return dt(a,t.text,Le,c=>({detail:o,kind:"column",label:c}))}if(t.text===""&&!ct(s,t.start))return[];let r=dt(n.tables,t.text,Le,a=>({kind:"table",label:a})),l=kn(n,t.text,Le),i=yn.flatMap(a=>t.text!==""&&We(a,t.text)&&a.toLowerCase()!==t.text.toLowerCase()?[{kind:"keyword",label:a}]:[]);return(ct(s,t.start)?[...l,...r,...i]:[...r,...l,...i]).slice(0,Le)},"En"),Nn=d((s,e,n)=>{let t=St(s,e),o=s.slice(0,t.start)+n.label+s.slice(t.end);return{caret:t.start+n.label.length,value:o}},"Nn"),En=["boxSizing","borderBottomWidth","borderLeftWidth","borderRightWidth","borderTopWidth","fontFamily","fontSize","fontStyle","fontWeight","letterSpacing","lineHeight","paddingBottom","paddingLeft","paddingRight","paddingTop","tabSize","textIndent","textTransform","width","wordSpacing"],Ln=d((s,e)=>{let n=globalThis.getComputedStyle(s),t=globalThis.document.createElement("div"),{style:o}=t;o.position="absolute",o.visibility="hidden",o.whiteSpace="pre-wrap",o.overflowWrap="break-word";for(let a of En)o[a]=n[a];t.textContent=s.value.slice(0,Math.max(0,e));let r=globalThis.document.createElement("span");r.textContent=s.value.slice(Math.max(0,e))||".",t.append(r),globalThis.document.body.append(t);let l=r.offsetLeft-s.scrollLeft,i=r.offsetTop-s.scrollTop;return t.remove(),{left:l,top:i}},"Tn"),_n=d((s,e,n)=>{let t=(0,V.c)(16),[o,r]=(0,j.useState)(null),l;t[0]!==s||t[1]!==e?(l=d((N,h)=>{let S=Cn(N,h,s);if(S.length===0){r(null);return}let x=e.current,{left:v,top:y}=x===null?{left:0,top:0}:Ln(x,h);r(w=>w!==null&&w.active===0&&w.left===v&&w.top===y&&w.suggestions.length===S.length&&w.suggestions.every((E,T)=>{let L=S.at(T);return E.kind===L?.kind&&E.label===L.label&&E.detail===L.detail})?w:{active:0,left:v,suggestions:S,top:y})},"r"),t[0]=s,t[1]=e,t[2]=l):l=t[2];let i=l,a;t[3]===Symbol.for("react.memo_cache_sentinel")?(a=d(()=>{r(null)},"c"),t[3]=a):a=t[3];let c=a,m;t[4]===Symbol.for("react.memo_cache_sentinel")?(m=d(N=>{r(h=>{if(h===null)return h;let S=h.suggestions.length,x=(h.active+N+S)%S;return{...h,active:x}})},"d"),t[4]=m):m=t[4];let p=m,f;t[5]!==n||t[6]!==o||t[7]!==e?(f=d(N=>{let h=e.current;if(o===null||h===null)return!1;let S=o.suggestions[N??o.active];if(S===void 0)return!1;let x=Nn(h.value,h.selectionStart,S);return n(x.value),r(null),requestAnimationFrame(()=>{let v=e.current;v!==null&&(v.focus(),v.setSelectionRange(x.caret,x.caret))}),!0},"f"),t[5]=n,t[6]=o,t[7]=e,t[8]=f):f=t[8];let b=f,g;t[9]!==b?(g=d(()=>b(),"g"),t[9]=b,t[10]=g):g=t[10];let k=g,q;return t[11]!==k||t[12]!==b||t[13]!==i||t[14]!==o?(q={close:c,commit:k,commitAt:b,move:p,refresh:i,state:o},t[11]=k,t[12]=b,t[13]=i,t[14]=o,t[15]=q):q=t[15],q},"Rn"),Tn={column:"column",keyword:"keyword",table:"table"},In=20,Rn=d(s=>{let e=(0,V.c)(17),{listboxId:n,onPick:t,state:o}=s,r=J(),l;e[0]!==o?(l=o===null?void 0:{left:o.left,top:o.top+In},e[0]=o,e[1]=l):l=e[1];let i=l;if(o===null)return null;let a;if(e[2]!==n||e[3]!==t||e[4]!==o.active||e[5]!==o.suggestions||e[6]!==r){let m;e[8]!==n||e[9]!==t||e[10]!==o.active||e[11]!==r?(m=d((p,f)=>(0,u.jsxs)("li",{"aria-selected":f===o.active,className:ie("flex cursor-pointer items-center gap-2 px-2 py-1 text-[13px]",f===o.active?"bg-accent text-accent-foreground":"text-foreground"),"data-testid":"sql-autocomplete-item",id:`${n}-opt-${f.toString()}`,onMouseDown:d(b=>{b.preventDefault(),t(f)},"onMouseDown"),role:"option",children:[(0,u.jsx)("span",{className:"truncate font-mono",children:p.label}),p.detail!==void 0&&(0,u.jsx)("span",{className:"ms-auto truncate text-xs text-muted-foreground",children:p.detail}),(0,u.jsx)("span",{className:"shrink-0 font-mono text-[10px] tracking-wide text-muted-foreground/70 uppercase",children:r(Tn[p.kind])})]},`${p.kind}:${p.label}`),"d"),e[8]=n,e[9]=t,e[10]=o.active,e[11]=r,e[12]=m):m=e[12],a=o.suggestions.map(m),e[2]=n,e[3]=t,e[4]=o.active,e[5]=o.suggestions,e[6]=r,e[7]=a}else a=e[7];let c;return e[13]!==n||e[14]!==i||e[15]!==a?(c=(0,u.jsx)("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:n,role:"listbox",style:i,children:a}),e[13]=n,e[14]=i,e[15]=a,e[16]=c):c=e[16],c},"qn"),Dn=ge(ve.listTables),Mn=ge(ve.readTablePage),An=d(s=>{let e=(0,V.c)(18),n=Ce(),t;e[0]===Symbol.for("react.memo_cache_sentinel")?(t=[],e[0]=t):t=e[0];let[o,r]=(0,j.useState)(t),l;e[1]===Symbol.for("react.memo_cache_sentinel")?(l={},e[1]=l):l=e[1];let[i,a]=(0,j.useState)(l),c;e[2]===Symbol.for("react.memo_cache_sentinel")?(c={},e[2]=c):c=e[2];let[m,p]=(0,j.useState)(c),f;e[3]===Symbol.for("react.memo_cache_sentinel")?(f=new Set,e[3]=f):f=e[3];let b=(0,j.useRef)(f),g,k;e[4]!==n||e[5]!==s?(g=d(()=>{let v={cancelled:!1};return le((async()=>{try{let y=await n.query(Dn,{},xe(s));v.cancelled||(r(y.map(Pn)),a({}),p({}),b.current=new Set)}catch{v.cancelled||(r([]),a({}),p({}),b.current=new Set)}})()),()=>{v.cancelled=!0}},"g"),k=[n,s],e[4]=n,e[5]=s,e[6]=g,e[7]=k):(g=e[6],k=e[7]),(0,j.useEffect)(g,k);let q;e[8]!==n||e[9]!==s?(q=d(v=>{b.current.has(v)||(b.current.add(v),le((async()=>{try{let y=await n.query(Mn,{limit:1,offset:0,table:v},xe(s)),{sqlColumns:w}=y;if(w===void 0){b.current.delete(v);return}let E=new Set(w),T=y.columns.filter(L=>!E.has(L));a(L=>({...L,[v]:w})),p(L=>({...L,[v]:T}))}catch{b.current.delete(v)}})()))},"v"),e[8]=n,e[9]=s,e[10]=q):q=e[10];let N=q,h;e[11]!==i||e[12]!==m||e[13]!==o?(h={columns:i,docFields:m,tables:o},e[11]=i,e[12]=m,e[13]=o,e[14]=h):h=e[14];let S=h,x;return e[15]!==N||e[16]!==S?(x={probe:N,schema:S},e[15]=N,e[16]=S,e[17]=x):x=e[17],x},"Dn"),ze=/\b(?:from|join|update|into)\s+([a-z_][\w$]*)|\b([a-z_][\w$]*)\s*\./gi,$n=d(s=>{let e=new Set;ze.lastIndex=0;let n=ze.exec(s);for(;n!==null;)e.add(n[1]??n[2]),n=ze.exec(s);return[...e]},"On");function Pn(s){return s.name}d(Pn,"Mn");var On=d(s=>(s.metaKey||s.ctrlKey)&&!s.shiftKey&&!s.altKey&&s.key.toLowerCase()==="i","$n"),zn=d(s=>{let e=(0,V.c)(44),{inlineEditEnabled:n,onSubmit:t,probe:o,schema:r,setDraft:l}=s,i=(0,j.useId)(),[a,c]=(0,j.useState)(null),m=(0,j.useRef)(null),p=(0,j.useRef)(null),f=(0,j.useRef)(null),b=_n(r,f,l),{close:g,commit:k,commitAt:q,move:N,refresh:h,state:S}=b,x;e[0]!==q?(x=d($=>{q($)},"x"),e[0]=q,e[1]=x):x=e[1];let v=x,y;e[2]!==h?(y=d(()=>{let $=f.current;$!==null&&$===document.activeElement&&h($.value,$.selectionStart)},"y"),e[2]=h,e[3]=y):y=e[3];let w;e[4]!==h||e[5]!==r?(w=[h,r],e[4]=h,e[5]=r,e[6]=w):w=e[6],(0,j.useEffect)(y,w);let E;e[7]!==o||e[8]!==h||e[9]!==l?(E=d($=>{let{selectionStart:G,value:Z}=$.target;l(Z),c(null);for(let X of $n(Z))o(X);h(Z,G)},"w"),e[7]=o,e[8]=h,e[9]=l,e[10]=E):E=e[10];let T=E,L;e[11]!==h?(L=d($=>{let G=$.currentTarget;h(G.value,G.selectionStart)},"R"),e[11]=h,e[12]=L):L=e[12];let _=L,C;e[13]!==g||e[14]!==k||e[15]!==N?(C=d($=>$.key==="ArrowDown"?($.preventDefault(),N(1),!0):$.key==="ArrowUp"?($.preventDefault(),N(-1),!0):$.key==="Escape"?($.preventDefault(),g(),!0):($.key==="Enter"||$.key==="Tab")&&!$.metaKey&&!$.ctrlKey&&k()?($.preventDefault(),!0):!1,"k"),e[13]=g,e[14]=k,e[15]=N,e[16]=C):C=e[16];let I=C,R;e[17]!==S||e[18]!==g||e[19]!==n||e[20]!==I||e[21]!==t?(R=d($=>{if(!(S!==null&&I($))){if(($.metaKey||$.ctrlKey)&&$.key==="Enter"){$.preventDefault(),t();return}if(n&&On($)){$.preventDefault(),g();let{selectionEnd:G,selectionStart:Z,value:X}=$.currentTarget,[se,ae]=Z===G?[0,X.length]:[Z,G];c({end:ae,start:se,text:X.slice(se,ae)})}}},"q"),e[17]=S,e[18]=g,e[19]=n,e[20]=I,e[21]=t,e[22]=R):R=e[22];let M=R,z;e[23]!==g?(z=d(()=>{requestAnimationFrame(()=>{g()})},"$"),e[23]=g,e[24]=z):z=e[24];let H=z,W;e[25]===Symbol.for("react.memo_cache_sentinel")?(W=d($=>{let{scrollLeft:G,scrollTop:Z}=$.currentTarget;m.current!==null&&(m.current.scrollTop=Z),p.current!==null&&(p.current.scrollTop=Z,p.current.scrollLeft=G)},"B"),e[25]=W):W=e[25];let B=W,P;e[26]===Symbol.for("react.memo_cache_sentinel")?(P=d($=>{let G=f.current;G===null||$.offset===void 0||(G.focus(),G.setSelectionRange($.offset,$.offset+($.length??0)))},"P"),e[26]=P):P=e[26];let K=P,O;e[27]===Symbol.for("react.memo_cache_sentinel")?(O=d(()=>{c(null),f.current?.focus()},"M"),e[27]=O):O=e[27];let D=O,A;e[28]!==a||e[29]!==l?(A=d($=>{let G=f.current;if(a===null||G===null)return;let{end:Z,start:X,text:se}=a;if(G.value.slice(X,Z)!==se){c(null);return}l(G.value.slice(0,X)+$+G.value.slice(Z)),c(null),G.focus(),requestAnimationFrame(()=>{G.setSelectionRange(X,X+$.length)})},"D"),e[28]=a,e[29]=l,e[30]=A):A=e[30];let Q=A,F;e[31]!==T||e[32]!==H||e[33]!==M||e[34]!==_?(F={onBlur:H,onChange:T,onKeyDown:M,onScroll:B,onSelect:_},e[31]=T,e[32]=H,e[33]=M,e[34]=_,e[35]=F):F=e[35];let ee;return e[36]!==Q||e[37]!==S||e[38]!==g||e[39]!==a||e[40]!==i||e[41]!==v||e[42]!==F?(ee={acceptInlineEdit:Q,autocompleteState:S,closeAutocomplete:g,closeInlineEdit:D,inlineEdit:a,handlers:F,listboxId:i,onPickSuggestion:v,editorRef:f,gutterRef:m,overlayRef:p,revealDiagnostic:K},e[36]=Q,e[37]=S,e[38]=g,e[39]=a,e[40]=i,e[41]=v,e[42]=F,e[43]=ee):ee=e[43],ee},"Bn"),Hn="lunora-studio-sql-tabs",jn="lunora-studio-sql-active-tab",Be=12,qe=d((s="",e="")=>({activeId:null,id:Me("tab"),name:e,sql:s}),"Se"),Wn=d(()=>Ee(jn,""),"Hn"),Bn=d(s=>{let e=(0,V.c)(16),[n,t]=Ne(Hn),[o,r]=Wn(),[l]=(0,j.useState)(s),i,a;e[0]!==l||e[1]!==t||e[2]!==n.length?(i=d(()=>{n.length===0&&t([l])},"i"),a=[l,t,n.length],e[0]=l,e[1]=t,e[2]=n.length,e[3]=i,e[4]=a):(i=e[3],a=e[4]),(0,j.useEffect)(i,a);let c;e[5]!==l||e[6]!==n?(c=n.length===0?[l]:n,e[5]=l,e[6]=n,e[7]=c):c=e[7];let m=c,p;e[8]!==o||e[9]!==m?(p=m.some(g=>g.id===o)?o:m[0]?.id??"",e[8]=o,e[9]=m,e[10]=p):p=e[10];let f=p,b;return e[11]!==f||e[12]!==r||e[13]!==t||e[14]!==m?(b={activeId:f,setActiveId:r,setTabs:t,tabs:m},e[11]=f,e[12]=r,e[13]=t,e[14]=m,e[15]=b):b=e[15],b},"Fn"),qt=d(s=>s.activeId===null&&s.sql.trim()!=="","ft"),Fn=d((s,e)=>[...s,e].slice(-Be),"Qn"),Qn=d((s,e,n)=>{let t=s.findIndex(r=>r.id===e);if(t===-1)return{activeId:s[0]?.id??"",tabs:[...s]};let o=s.filter(r=>r.id!==e);if(o.length===0){let r=n();return{activeId:r.id,tabs:[r]}}return{activeId:o[Math.min(t,o.length-1)].id,tabs:o}},"jn"),Kn=d((s,e)=>{let n=s.filter(t=>t.id===e);return n.length===0?{activeId:s[0]?.id??"",tabs:[...s]}:{activeId:e,tabs:n}},"zn"),Un=d((s,e,n)=>{let t=s.findIndex(r=>r.id===e);if(t===-1)return{activeId:n,tabs:[...s]};let o=s.slice(0,t+1);return{activeId:o.some(r=>r.id===n)?n:e,tabs:o}},"Kn"),Gn=d(s=>{let e=s();return{activeId:e.id,tabs:[e]}},"Un"),Xn=d((s,e,n)=>{if(s==="others")return e.filter(t=>t.id!==n);if(s==="right"){let t=e.findIndex(o=>o.id===n);return t===-1?[]:e.slice(t+1)}return[...e]},"Yn"),ut={error:null,pane:"results",result:null,running:!1},Vn=d(s=>{let e=(0,V.c)(69),{activeId:n,setActiveId:t,setTabs:o,tabs:r}=Bn(s),l;e[0]===Symbol.for("react.memo_cache_sentinel")?(l={},e[0]=l):l=e[0];let[i,a]=(0,j.useState)(l),[c,m]=(0,j.useState)(null),[p,f]=(0,j.useState)(null),b;e[1]!==n||e[2]!==r?(b=r.find(Y=>Y.id===n)??r[0]??qe(),e[1]=n,e[2]=r,e[3]=b):b=e[3];let g=b,k=i[g.id]??ut,q;e[4]!==g.id||e[5]!==o?(q=d(Y=>{o(te=>te.map(ne=>ne.id===g.id?{...ne,...Y}:ne))},"v"),e[4]=g.id,e[5]=o,e[6]=q):q=e[6];let N=q,h;e[7]!==g.id?(h=d(Y=>{a(te=>{let ne=te[g.id]??ut;return{...te,[g.id]:{...ne,...Y}}})},"p"),e[7]=g.id,e[8]=h):h=e[8];let S=h,x;e[9]!==t||e[10]!==o||e[11]!==r.length?(x=d(Y=>{if(r.length>=Be)return!1;let te=qe(Y);return o(ne=>Fn(ne,te)),t(te.id),!0},"x"),e[9]=t,e[10]=o,e[11]=r.length,e[12]=x):x=e[12];let v=x,y;e[13]!==v?(y=d(()=>{v("")},"y"),e[13]=v,e[14]=y):y=e[14];let w=y,E;e[15]!==t||e[16]!==o?(E=d(Y=>{m(null),f(null),o(Y.tabs),t(Y.activeId);let te=new Set(Y.tabs.map(Yn));a(ne=>Object.fromEntries(Object.entries(ne).filter(U=>{let[oe]=U;return te.has(oe)})))},"w"),e[15]=t,e[16]=o,e[17]=E):E=e[17];let T=E,L;e[18]!==T||e[19]!==r?(L=d(Y=>{T(Qn(r,Y,qe))},"R"),e[18]=T,e[19]=r,e[20]=L):L=e[20];let _=L,C;e[21]!==n||e[22]!==T||e[23]!==r?(C=d((Y,te)=>{T(Y==="others"?Kn(r,te):Y==="right"?Un(r,te,n):Gn(qe))},"k"),e[21]=n,e[22]=T,e[23]=r,e[24]=C):C=e[24];let I=C,R;e[25]!==I||e[26]!==c||e[27]!==r?(R=d(Y=>{c!==null&&(Xn(Y,r,c.id).some(Jn)?f(Y):I(Y,c.id))},"q"),e[25]=I,e[26]=c,e[27]=r,e[28]=R):R=e[28];let M=R,z;e[29]===Symbol.for("react.memo_cache_sentinel")?(z=d((Y,te)=>{te.preventDefault(),f(null),m({id:Y,x:te.clientX,y:te.clientY})},"$"),e[29]=z):z=e[29];let H=z,W;e[30]===Symbol.for("react.memo_cache_sentinel")?(W=d(()=>{m(null),f(null)},"B"),e[30]=W):W=e[30];let B=W,P;e[31]===Symbol.for("react.memo_cache_sentinel")?(P=d(Y=>{Y.preventDefault(),m(null),f(null)},"P"),e[31]=P):P=e[31];let K=P,O;e[32]!==M?(O=d(()=>{M("others")},"M"),e[32]=M,e[33]=O):O=e[33];let D=O,A;e[34]!==M?(A=d(()=>{M("right")},"D"),e[34]=M,e[35]=A):A=e[35];let Q=A,F;e[36]!==M?(F=d(()=>{M("all")},"j"),e[36]=M,e[37]=F):F=e[37];let ee=F,$;e[38]!==I||e[39]!==p||e[40]!==c?($=d(()=>{c!==null&&p!==null&&I(p,c.id),f(null)},"O"),e[38]=I,e[39]=p,e[40]=c,e[41]=$):$=e[41];let G=$,Z;e[42]===Symbol.for("react.memo_cache_sentinel")?(Z=d(()=>{f(null)},"X"),e[42]=Z):Z=e[42];let X=Z,se;e[43]!==c?(se=c===null?void 0:{left:c.x,top:c.y},e[43]=c,e[44]=se):se=e[44];let ae=se,ue;e[45]!==o?(ue=d(Y=>{o(te=>te.map(ne=>ne.activeId===Y?{...ne,activeId:null}:ne))},"pe"),e[45]=o,e[46]=ue):ue=e[46];let pe=ue,me;e[47]!==o?(me=d((Y,te)=>{o(ne=>ne.map(U=>U.id===Y?{...U,name:te}:U))},"he"),e[47]=o,e[48]=me):me=e[48];let be=me,fe;return e[49]!==g||e[50]!==n||e[51]!==w||e[52]!==_||e[53]!==G||e[54]!==ee||e[55]!==D||e[56]!==Q||e[57]!==v||e[58]!==k||e[59]!==S||e[60]!==N||e[61]!==p||e[62]!==be||e[63]!==t||e[64]!==c||e[65]!==ae||e[66]!==r||e[67]!==pe?(fe={activeTab:g,activeTabId:n,addEditorTab:w,cancelBulk:X,closeEditorTab:_,closeTabMenu:B,confirmBulk:G,menuStyle:ae,onBackdropContextMenu:K,onCloseAll:ee,onCloseOthers:D,onCloseToRight:Q,openEditorTab:v,openTabMenu:H,output:k,patchActiveOutput:S,patchActiveTab:N,pendingBulk:p,renameTab:be,setActiveTabId:t,tabMenu:c,tabs:r,unlinkQuery:pe},e[49]=g,e[50]=n,e[51]=w,e[52]=_,e[53]=G,e[54]=ee,e[55]=D,e[56]=Q,e[57]=v,e[58]=k,e[59]=S,e[60]=N,e[61]=p,e[62]=be,e[63]=t,e[64]=c,e[65]=ae,e[66]=r,e[67]=pe,e[68]=fe):fe=e[68],fe},"Gn");function Yn(s){return s.id}d(Yn,"Vn");function Jn(s){return qt(s)}d(Jn,"Jn");var Zn="lunora-studio-sql-queries",he="lunora-studio-sql-history",eo="lunora-studio-sql-remember-history",to=25,no=d(s=>{let e=(0,V.c)(44),{loadIntoActiveTab:n,unlinkQuery:t}=s,o=J(),[r,l]=Ne(Zn),[i,a]=Ee(eo,!1),[c,m]=Ne(he,i?"local":"session"),p,f;e[0]!==i?(p=d(()=>{i||we(he,"local")},"m"),f=[i],e[0]=i,e[1]=p,e[2]=f):(p=e[1],f=e[2]),(0,j.useEffect)(p,f);let[b,g]=(0,j.useState)(""),k=(0,j.useRef)(null),q;e[3]!==m?(q=d(D=>{m(A=>A[0]?.sql===D?A:[{at:Date.now(),sql:D},...A.filter(Q=>Q.sql!==D)].slice(0,to))},"v"),e[3]=m,e[4]=q):q=e[4];let N=q,h;e[5]!==n||e[6]!==l||e[7]!==o?(h=d(()=>{let D={id:Me("q"),name:o("Untitled query"),sql:""};l(A=>[D,...A]),n("",D.id)},"p"),e[5]=n,e[6]=l,e[7]=o,e[8]=h):h=e[8];let S=h,x;e[9]!==n||e[10]!==r?(x=d(D=>{let A=r.find(Q=>Q.id===D);A!==void 0&&(n(A.sql,D),k.current?.querySelector(`[data-testid="sql-query-${D}"]`)?.scrollIntoView({block:"nearest"}))},"x"),e[9]=n,e[10]=r,e[11]=x):x=e[11];let v=x,y;e[12]!==l||e[13]!==t?(y=d(D=>{l(A=>A.filter(Q=>Q.id!==D)),t(D)},"y"),e[12]=l,e[13]=t,e[14]=y):y=e[14];let w=y,E;e[15]!==n?(E=d(D=>{n(D.currentTarget.dataset.sql??"",null)},"w"),e[15]=n,e[16]=E):E=e[16];let T=E,L;e[17]!==n?(L=d(D=>{n(D.currentTarget.dataset.sql??"",null)},"R"),e[17]=n,e[18]=L):L=e[18];let _=L,C;e[19]!==m?(C=d(()=>{m([]),we(he,"local"),we(he,"session")},"k"),e[19]=m,e[20]=C):C=e[20];let I=C,R;e[21]!==c||e[22]!==a?(R=d(D=>{Xe(he,c,D?"local":"session"),D||we(he,"local"),a(D)},"q"),e[21]=c,e[22]=a,e[23]=R):R=e[23];let M=R,z;e[24]===Symbol.for("react.memo_cache_sentinel")?(z=d(D=>{g(D.target.value)},"$"),e[24]=z):z=e[24];let H=z,W;e[25]!==l?(W=d((D,A,Q)=>{l(F=>F.map(ee=>ee.id===D?{id:ee.id,name:A,sql:ee.sql,...Q===""?{}:{description:Q}}:ee))},"B"),e[25]=l,e[26]=W):W=e[26];let B=W,P;e[27]!==l?(P=d((D,A)=>{l(Q=>Q.map(F=>F.id===D?{...F,sql:A}:F))},"P"),e[27]=l,e[28]=P):P=e[28];let K=P,O;return e[29]!==I||e[30]!==w||e[31]!==c||e[32]!==_||e[33]!==T||e[34]!==S||e[35]!==r||e[36]!==N||e[37]!==i||e[38]!==B||e[39]!==b||e[40]!==v||e[41]!==M||e[42]!==K?(O={clearHistory:I,deleteQuery:w,history:c,listRef:k,loadFromHistory:_,loadTemplate:T,newQuery:S,onSearchChange:H,queries:r,recordHistory:N,rememberHistory:i,renameQuery:B,search:b,selectQuery:v,setRememberHistory:M,updateQuerySql:K},e[29]=I,e[30]=w,e[31]=c,e[32]=_,e[33]=T,e[34]=S,e[35]=r,e[36]=N,e[37]=i,e[38]=B,e[39]=b,e[40]=v,e[41]=M,e[42]=K,e[43]=O):O=e[43],O},"ts"),Fe="p-3 font-mono text-xs leading-5 whitespace-pre-wrap break-words",oo=d((s,e)=>{let n=[];for(let o of s){if(o.offset===void 0||o.length===void 0||o.length<=0)continue;let r=Math.max(0,Math.min(o.offset,e)),l=Math.max(r,Math.min(o.offset+o.length,e));r!==l&&n.push({end:l,severity:o.severity,start:r})}n.sort((o,r)=>o.start-r.start);let t=[];for(let o of n)o.start>=(t.at(-1)?.end??0)&&t.push(o);return t},"ns"),ro=d(s=>{let e=(0,V.c)(51),{rpc:n,failed:t,onGenerated:o}=s,r=J(),[l,i]=(0,j.useState)("");if(n.unavailable)return null;let a;e[0]!==n?(a=n.pending("sql"),e[0]=n,e[1]=a):a=e[1];let c=a,m;if(e[2]!==t||e[3]!==o||e[4]!==c||e[5]!==l||e[6]!==n||e[7]!==r){let p=n.reason("sql"),f;e[9]!==t||e[10]!==o||e[11]!==l||e[12]!==n?(f=d(_=>{let C=l.trim();C===""&&!_||le((async()=>{let I=await n.generate(C===""?"fix the failing statement":C,_?t:void 0);I!==void 0&&o(I)})())},"f"),e[9]=t,e[10]=o,e[11]=l,e[12]=n,e[13]=f):f=e[13];let b=f,g;e[14]!==r?(g=r("Describe the query you want"),e[14]=r,e[15]=g):g=e[15];let k;e[16]===Symbol.for("react.memo_cache_sentinel")?(k=d(_=>{i(_.target.value)},"L"),e[16]=k):k=e[16];let q;e[17]!==b?(q=d(_=>{_.key==="Enter"&&(_.preventDefault(),b(!1))},"v"),e[17]=b,e[18]=q):q=e[18];let N;e[19]!==r?(N=r("Describe the query you want"),e[19]=r,e[20]=N):N=e[20];let h;e[21]!==c||e[22]!==l||e[23]!==g||e[24]!==q||e[25]!==N?(h=(0,u.jsx)(ye,{"aria-label":g,className:"h-7 flex-1 text-xs","data-testid":"sql-assistant-prompt",disabled:c,onChange:k,onKeyDown:q,placeholder:N,value:l}),e[21]=c,e[22]=l,e[23]=g,e[24]=q,e[25]=N,e[26]=h):h=e[26];let S=c&&"opacity-60",x;e[27]!==S?(x=ie("rounded-md border border-border px-2 py-1 text-xs outline-none transition-colors hover:bg-accent focus-visible:bg-accent",S),e[27]=S,e[28]=x):x=e[28];let v;e[29]!==c||e[30]!==l?(v=c||l.trim()==="",e[29]=c,e[30]=l,e[31]=v):v=e[31];let y;e[32]!==b?(y=d(()=>{b(!1)},"y"),e[32]=b,e[33]=y):y=e[33];let w;e[34]!==c||e[35]!==r?(w=r(c?"Thinking\u2026":"Draft SQL"),e[34]=c,e[35]=r,e[36]=w):w=e[36];let E;e[37]!==x||e[38]!==v||e[39]!==y||e[40]!==w?(E=(0,u.jsx)("button",{className:x,"data-testid":"sql-assistant-generate",disabled:v,onClick:y,type:"button",children:w}),e[37]=x,e[38]=v,e[39]=y,e[40]=w,e[41]=E):E=e[41];let T;e[42]!==t||e[43]!==c||e[44]!==b||e[45]!==r?(T=t!==void 0&&(0,u.jsx)("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:d(()=>{b(!0)},"onClick"),type:"button",children:r("Fix this")}),e[42]=t,e[43]=c,e[44]=b,e[45]=r,e[46]=T):T=e[46];let L;e[47]!==E||e[48]!==T||e[49]!==h?(L=(0,u.jsxs)("div",{className:"flex items-center gap-2",children:[h,E,T]}),e[47]=E,e[48]=T,e[49]=h,e[50]=L):L=e[50],m=(0,u.jsxs)("div",{className:"flex flex-col gap-1 border-b border-border px-3 py-2","data-testid":"sql-assistant",children:[L,p!==void 0&&(0,u.jsx)("p",{className:"text-[11px] text-muted-foreground","data-testid":"sql-assistant-reason",role:"status",children:Ae(p,r)})]}),e[2]=t,e[3]=o,e[4]=c,e[5]=l,e[6]=n,e[7]=r,e[8]=m}else m=e[8];return m},"ss"),so=d(s=>{let e=(0,V.c)(8),{diagnostics:n,draft:t,scrollRef:o}=s,r,l;if(e[0]!==n||e[1]!==t){l=Symbol.for("react.early_return_sentinel");e:{let c=oo(n,t.length);if(c.length===0){l=null;break e}r=[];let m=0;for(let[p,f]of c.entries())f.start>m&&r.push(t.slice(m,f.start)),r.push((0,u.jsx)("span",{className:ie("decoration-wavy underline underline-offset-4",f.severity==="error"?"decoration-destructive":"decoration-amber-500"),children:t.slice(f.start,f.end)},`${f.start.toString()}-${p.toString()}`)),m=f.end;r.push(t.slice(m))}e[0]=n,e[1]=t,e[2]=r,e[3]=l}else r=e[2],l=e[3];if(l!==Symbol.for("react.early_return_sentinel"))return l;let i;e[4]===Symbol.for("react.memo_cache_sentinel")?(i=ie("pointer-events-none absolute inset-0 overflow-hidden text-transparent",Fe),e[4]=i):i=e[4];let a;return e[5]!==r||e[6]!==o?(a=(0,u.jsx)("div",{"aria-hidden":"true",className:i,"data-testid":"sql-diagnostics-overlay",ref:o,children:r}),e[5]=r,e[6]=o,e[7]=a):a=e[7],a},"os"),lo={gate:"read-only",plan:"plan",schema:"schema",syntax:"syntax"},io=d(s=>{let e=(0,V.c)(10),{diagnostics:n,onSelect:t}=s,o=J();if(n.length===0)return null;let r;e[0]!==o?(r=o("SQL problems"),e[0]=o,e[1]=r):r=e[1];let l;if(e[2]!==n||e[3]!==t){let a;e[5]!==t?(a=d((c,m)=>(0,u.jsx)("li",{children:(0,u.jsxs)("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:d(()=>{t(c)},"onClick"),type:"button",children:[(0,u.jsx)("span",{className:ie("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:lo[c.source]}),(0,u.jsx)("span",{className:"min-w-0 text-muted-foreground",children:c.message})]})},`${c.source}-${(c.offset??m).toString()}-${m.toString()}`),"c"),e[5]=t,e[6]=a):a=e[6],l=n.map(a),e[2]=n,e[3]=t,e[4]=l}else l=e[4];let i;return e[7]!==r||e[8]!==l?(i=(0,u.jsx)("ul",{"aria-label":r,className:"max-h-24 shrink-0 overflow-y-auto border-t border-border bg-muted/30","data-testid":"sql-problems",children:l}),e[7]=r,e[8]=l,e[9]=i):i=e[9],i},"rs"),ao=d(s=>(s.endsWith(`
|
|
12
13
|
`)?s.slice(0,-1):s).split(`
|
|
13
|
-
`),"
|
|
14
|
-
`).length;I="flex min-h-0 min-w-0 flex-1 flex-col",e[17]!==l||e[18]!==g||e[19]!==n?(T=(0,u.jsx)(Kn,{failed:l,onGenerated:g,rpc:n}),e[17]=l,e[18]=g,e[19]=n,e[20]=T):T=e[20],e[21]!==r.length||e[22]!==m||e[23]!==f||e[24]!==b||e[25]!==n?(L=m!==null&&(0,u.jsx)(to,{onAccept:f,onCancel:b,rpc:n,source:m.text,whole:m.start===0&&m.end===r.length},`${m.start.toString()}-${m.end.toString()}`),e[21]=r.length,e[22]=m,e[23]=f,e[24]=b,e[25]=n,e[26]=L):L=e[26],E="flex min-h-0 min-w-0 flex-1",S="true",x="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",v=c,y=no,w=Array.from({length:A},ro),e[0]=r,e[1]=l,e[2]=c,e[3]=m,e[4]=f,e[5]=b,e[6]=g,e[7]=n,e[8]=S,e[9]=x,e[10]=v,e[11]=y,e[12]=w,e[13]=E,e[14]=I,e[15]=T,e[16]=L}else S=e[8],x=e[9],v=e[10],y=e[11],w=e[12],E=e[13],I=e[14],T=e[15],L=e[16];let C;e[27]!==S||e[28]!==x||e[29]!==v||e[30]!==y||e[31]!==w?(C=(0,u.jsx)("div",{"aria-hidden":S,className:x,ref:v,style:y,children:w}),e[27]=S,e[28]=x,e[29]=v,e[30]=y,e[31]=w,e[32]=C):C=e[32];let R;e[33]!==o||e[34]!==r||e[35]!==N?(R=(0,u.jsx)(Un,{diagnostics:o,draft:r,scrollRef:N}),e[33]=o,e[34]=r,e[35]=N,e[36]=R):R=e[36];let _;e[37]!==t||e[38]!==p?(_=t===null?void 0:`${p}-opt-${t.active.toString()}`,e[37]=t,e[38]=p,e[39]=_):_=e[39];let M=t===null?void 0:p,z=t!==null,j;e[40]!==h?(j=h("SQL query"),e[40]=h,e[41]=j):j=e[41];let B;e[42]!==r||e[43]!==a||e[44]!==i.onBlur||e[45]!==i.onChange||e[46]!==i.onKeyDown||e[47]!==i.onScroll||e[48]!==i.onSelect||e[49]!==_||e[50]!==M||e[51]!==z||e[52]!==j?(B=(0,u.jsx)("textarea",{"aria-activedescendant":_,"aria-autocomplete":"list","aria-controls":M,"aria-expanded":z,"aria-label":j,className:`relative size-full resize-none bg-transparent outline-none ${Be}`,"data-testid":"sql-input",onBlur:i.onBlur,onChange:i.onChange,onKeyDown:i.onKeyDown,onScroll:i.onScroll,onSelect:i.onSelect,placeholder:"SELECT * FROM \u2026",ref:a,role:"combobox",spellCheck:!1,value:r}),e[42]=r,e[43]=a,e[44]=i.onBlur,e[45]=i.onChange,e[46]=i.onKeyDown,e[47]=i.onScroll,e[48]=i.onSelect,e[49]=_,e[50]=M,e[51]=z,e[52]=j,e[53]=B):B=e[53];let W;e[54]!==t||e[55]!==p||e[56]!==k?(W=(0,u.jsx)(yn,{listboxId:p,onPick:k,state:t}),e[54]=t,e[55]=p,e[56]=k,e[57]=W):W=e[57];let $;e[58]!==R||e[59]!==B||e[60]!==W?($=(0,u.jsxs)("div",{className:"relative min-w-0 flex-1 bg-background",children:[R,B,W]}),e[58]=R,e[59]=B,e[60]=W,e[61]=$):$=e[61];let K;e[62]!==C||e[63]!==$||e[64]!==E?(K=(0,u.jsxs)("div",{className:E,children:[C,$]}),e[62]=C,e[63]=$,e[64]=E,e[65]=K):K=e[65];let O;e[66]!==o||e[67]!==q?(O=(0,u.jsx)(Vn,{diagnostics:o,onSelect:q}),e[66]=o,e[67]=q,e[68]=O):O=e[68];let D;return e[69]!==K||e[70]!==O||e[71]!==I||e[72]!==T||e[73]!==L?(D=(0,u.jsxs)("div",{className:I,children:[T,L,K,O]}),e[69]=K,e[70]=O,e[71]=I,e[72]=T,e[73]=L,e[74]=D):D=e[74],D},"ns");function ro(s,e){return(0,u.jsx)("div",{children:e+1},e)}d(ro,"ss");var lo=d(s=>{let e=(0,X.c)(62),{onCancel:n,onSave:t,query:o,rpc:r}=s,l=J(),[i,a]=(0,H.useState)(o.name),[c,m]=(0,H.useState)(o.description??""),p;e[0]!==o.sql||e[1]!==r?(p=r!==void 0&&!r.unavailable&&o.sql.trim()!=="",e[0]=o.sql,e[1]=r,e[2]=p):p=e[2];let f=p,b;e[3]!==r?(b=r?.pending("name"),e[3]=r,e[4]=b):b=e[4];let g=b===!0,k;e[5]!==r?(k=r?.reason("name"),e[5]=r,e[6]=k):k=e[6];let q=k,N;e[7]!==c||e[8]!==i||e[9]!==o.sql||e[10]!==r?(N=d(()=>{if(r===void 0)return;let O=i,D=c;se((async()=>{let A=await r.nameQuery(o.sql);A!==void 0&&(a(Q=>Q===O?A.title:Q),m(Q=>Q===D?A.description:Q))})())},"S"),e[7]=c,e[8]=i,e[9]=o.sql,e[10]=r,e[11]=N):N=e[11];let h=N,S;e[12]!==c||e[13]!==i||e[14]!==t?(S=d(O=>{O.preventDefault();let D=i.trim();D!==""&&t(D,c.trim())},"N"),e[12]=c,e[13]=i,e[14]=t,e[15]=S):S=e[15];let x=S,v=`sql-query-rename-${o.id}`,y;e[16]!==l?(y=l("Query name"),e[16]=l,e[17]=y):y=e[17];let w;e[18]===Symbol.for("react.memo_cache_sentinel")?(w=d(O=>{a(O.target.value)},"C"),e[18]=w):w=e[18];let E;e[19]!==l?(E=l("Query name"),e[19]=l,e[20]=E):E=e[20];let I;e[21]!==i||e[22]!==y||e[23]!==E?(I=(0,u.jsx)(ye,{"aria-label":y,autoFocus:!0,className:"h-7 text-xs","data-testid":"sql-query-name",onChange:w,placeholder:E,value:i}),e[21]=i,e[22]=y,e[23]=E,e[24]=I):I=e[24];let T;e[25]!==l?(T=l("Query description"),e[25]=l,e[26]=T):T=e[26];let L;e[27]===Symbol.for("react.memo_cache_sentinel")?(L=d(O=>{m(O.target.value)},"T"),e[27]=L):L=e[27];let C;e[28]!==l?(C=l("Query description"),e[28]=l,e[29]=C):C=e[29];let R;e[30]!==c||e[31]!==T||e[32]!==C?(R=(0,u.jsx)(ye,{"aria-label":T,className:"h-7 text-xs","data-testid":"sql-query-description",onChange:L,placeholder:C,value:c}),e[30]=c,e[31]=T,e[32]=C,e[33]=R):R=e[33];let _;e[34]!==l?(_=l("Save"),e[34]=l,e[35]=_):_=e[35];let M;e[36]!==_?(M=(0,u.jsx)("button",{className:"rounded-md border border-border px-2 py-0.5 text-[11px] outline-none transition-colors hover:bg-accent focus-visible:bg-accent","data-testid":"sql-query-rename-save",type:"submit",children:_}),e[36]=_,e[37]=M):M=e[37];let z;e[38]!==l?(z=l("Cancel"),e[38]=l,e[39]=z):z=e[39];let j;e[40]!==n||e[41]!==z?(j=(0,u.jsx)("button",{className:"rounded-md px-2 py-0.5 text-[11px] text-muted-foreground outline-none transition-colors hover:text-foreground focus-visible:text-foreground","data-testid":"sql-query-rename-cancel",onClick:n,type:"button",children:z}),e[40]=n,e[41]=z,e[42]=j):j=e[42];let B;e[43]!==f||e[44]!==g||e[45]!==h||e[46]!==l?(B=f&&(0,u.jsx)("button",{className:"ms-auto rounded-md border border-border px-2 py-0.5 text-[11px] outline-none transition-colors hover:bg-accent focus-visible:bg-accent","data-testid":"sql-query-suggest-name",disabled:g,onClick:h,type:"button",children:l(g?"Thinking\u2026":"Suggest")}),e[43]=f,e[44]=g,e[45]=h,e[46]=l,e[47]=B):B=e[47];let W;e[48]!==M||e[49]!==j||e[50]!==B?(W=(0,u.jsxs)("div",{className:"flex items-center gap-1",children:[M,j,B]}),e[48]=M,e[49]=j,e[50]=B,e[51]=W):W=e[51];let $;e[52]!==q||e[53]!==l?($=q!==void 0&&(0,u.jsx)("p",{className:"text-[11px] text-muted-foreground","data-testid":"sql-query-name-reason",role:"status",children:l(q==="ai-error"?"The model could not be reached.":"The model returned nothing usable.")}),e[52]=q,e[53]=l,e[54]=$):$=e[54];let K;return e[55]!==x||e[56]!==I||e[57]!==R||e[58]!==W||e[59]!==$||e[60]!==v?(K=(0,u.jsxs)("form",{className:"flex flex-col gap-1 rounded-md bg-sidebar-accent p-1.5","data-testid":v,onSubmit:x,children:[I,R,W,$]}),e[55]=x,e[56]=I,e[57]=R,e[58]=W,e[59]=$,e[60]=v,e[61]=K):K=e[61],K},"os"),xt=[{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;"}],so=d(s=>{let e=(0,X.c)(44),{active:n,onDelete:t,onRename:o,onSelect:r,query:l}=s,i=J(),a;e[0]!==r||e[1]!==l.id?(a=d(()=>{r(l.id)},"c"),e[0]=r,e[1]=l.id,e[2]=a):a=e[2];let c=a,m;e[3]!==t||e[4]!==l.id?(m=d(_=>{_.stopPropagation(),t(l.id)},"d"),e[3]=t,e[4]=l.id,e[5]=m):m=e[5];let p=m,f;e[6]!==o||e[7]!==l.id?(f=d(_=>{_.stopPropagation(),o(l.id)},"f"),e[6]=o,e[7]=l.id,e[8]=f):f=e[8];let b=f,g=n?"bg-sidebar-accent font-medium text-foreground":"text-muted-foreground",k;e[9]!==g?(k=ie("flex min-w-0 flex-1 items-center gap-2 rounded-md px-2 py-1.5 text-start text-[13px] outline-none transition-colors hover:bg-sidebar-accent focus-visible:bg-sidebar-accent",g),e[9]=g,e[10]=k):k=e[10];let q=`sql-query-${l.id}`,N;e[11]===Symbol.for("react.memo_cache_sentinel")?(N=(0,u.jsx)("svg",{"aria-hidden":"true",className:"size-3.5 shrink-0 opacity-70",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,u.jsx)("path",{d:"M4 6h16M4 12h10M4 18h7"})}),e[11]=N):N=e[11];let h;e[12]!==l.name?(h=(0,u.jsx)("span",{className:"truncate",children:l.name}),e[12]=l.name,e[13]=h):h=e[13];let S;e[14]!==n||e[15]!==c||e[16]!==l.description||e[17]!==k||e[18]!==q||e[19]!==h?(S=(0,u.jsxs)("button",{"aria-pressed":n,className:k,"data-testid":q,onClick:c,title:l.description,type:"button",children:[N,h]}),e[14]=n,e[15]=c,e[16]=l.description,e[17]=k,e[18]=q,e[19]=h,e[20]=S):S=e[20];let x;e[21]!==i?(x=i("Rename query"),e[21]=i,e[22]=x):x=e[22];let v=`sql-query-rename-open-${l.id}`,y;e[23]!==i?(y=i("Rename query"),e[23]=i,e[24]=y):y=e[24];let w;e[25]===Symbol.for("react.memo_cache_sentinel")?(w=(0,u.jsx)("svg",{"aria-hidden":"true",className:"size-3.5",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,u.jsx)("path",{d:"M4 20h4L19 9l-4-4L4 16zM14 6l4 4"})}),e[25]=w):w=e[25];let E;e[26]!==b||e[27]!==x||e[28]!==v||e[29]!==y?(E=(0,u.jsx)("button",{"aria-label":x,className:"hidden size-6 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-accent hover:text-foreground group-hover/q:flex","data-testid":v,onClick:b,title:y,type:"button",children:w}),e[26]=b,e[27]=x,e[28]=v,e[29]=y,e[30]=E):E=e[30];let I;e[31]!==i?(I=i("Delete query"),e[31]=i,e[32]=I):I=e[32];let T;e[33]!==i?(T=i("Delete query"),e[33]=i,e[34]=T):T=e[34];let L;e[35]===Symbol.for("react.memo_cache_sentinel")?(L=(0,u.jsx)("svg",{"aria-hidden":"true",className:"size-3.5",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,u.jsx)("path",{d:"M5 7h14M9 7V5h6v2m-1 0v12H10V7M7 7v13h10V7"})}),e[35]=L):L=e[35];let C;e[36]!==p||e[37]!==I||e[38]!==T?(C=(0,u.jsx)("button",{"aria-label":I,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:T,type:"button",children:L}),e[36]=p,e[37]=I,e[38]=T,e[39]=C):C=e[39];let R;return e[40]!==E||e[41]!==C||e[42]!==S?(R=(0,u.jsxs)("li",{className:"group/q flex items-center",children:[S,E,C]}),e[40]=E,e[41]=C,e[42]=S,e[43]=R):R=e[43],R},"ls"),it="sql-history-remember",io=d((s,e)=>{let n=e.trim().toLowerCase();return n===""?[...s]:s.filter(t=>t.name.toLowerCase().includes(n))},"rs"),ao=d(s=>{let e=(0,X.c)(53),{activeId:n,history:t,listRef:o,onClearHistory:r,onDelete:l,onLoadHistory:i,onLoadTemplate:a,onNew:c,onRename:m,onSearchChange:p,onSelect:f,onToggleRememberHistory:b,queries:g,rememberHistory:k,rpc:q,search:N}=s,h=J(),S=io(g,N),[x,v]=(0,H.useState)(null),y;e[0]===Symbol.for("react.memo_cache_sentinel")?(y=d(()=>{v(null)},"y"),e[0]=y):y=e[0];let w=y,E;e[1]!==b?(E=d(V=>{b(V.target.checked)},"w"),e[1]=b,e[2]=E):E=e[2];let I=E,T="flex h-full w-64 shrink-0 flex-col border-e border-border bg-sidebar",L;e[3]!==h?(L=h("Search queries\u2026"),e[3]=h,e[4]=L):L=e[4];let C;e[5]!==p||e[6]!==N||e[7]!==L?(C=(0,u.jsx)("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:L,type:"text",value:N}),e[5]=p,e[6]=N,e[7]=L,e[8]=C):C=e[8];let R;e[9]!==h?(R=h("New query"),e[9]=h,e[10]=R):R=e[10];let _;e[11]!==h?(_=h("New query"),e[11]=h,e[12]=_):_=e[12];let M;e[13]===Symbol.for("react.memo_cache_sentinel")?(M=(0,u.jsx)("svg",{"aria-hidden":"true",className:"size-4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.7,viewBox:"0 0 24 24",children:(0,u.jsx)("path",{d:"M12 5v14M5 12h14"})}),e[13]=M):M=e[13];let z;e[14]!==c||e[15]!==R||e[16]!==_?(z=(0,u.jsx)("button",{"aria-label":R,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:_,type:"button",children:M}),e[14]=c,e[15]=R,e[16]=_,e[17]=z):z=e[17];let j;e[18]!==C||e[19]!==z?(j=(0,u.jsxs)("div",{className:"flex shrink-0 items-center gap-2 border-b border-border p-2",children:[C,z]}),e[18]=C,e[19]=z,e[20]=j):j=e[20];let B="flex flex-1 flex-col gap-4 overflow-y-auto p-2",W;e[21]!==h?(W=h("Private"),e[21]=h,e[22]=W):W=e[22];let $;e[23]!==W?($=(0,u.jsx)("p",{className:"px-1 pb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:W}),e[23]=W,e[24]=$):$=e[24];let K=S.length===0?(0,u.jsx)("p",{className:"px-1 py-2 text-xs text-muted-foreground","data-testid":"sql-private-empty",children:h("No saved queries yet \u2014 they save to this browser as you type.")}):(0,u.jsx)("ul",{className:"flex flex-col gap-px","data-testid":"sql-private",ref:o,children:S.map(V=>x===V.id?(0,u.jsx)("li",{children:(0,u.jsx)(lo,{onCancel:w,onSave:d((le,ae)=>{m(V.id,le,ae),w()},"onSave"),query:V,rpc:q})},V.id):(0,u.jsx)(so,{active:n===V.id,onDelete:l,onRename:v,onSelect:f,query:V},V.id))}),O;e[25]!==$||e[26]!==K?(O=(0,u.jsxs)("div",{children:[$,K]}),e[25]=$,e[26]=K,e[27]=O):O=e[27];let D;e[28]!==h?(D=h("Reference"),e[28]=h,e[29]=D):D=e[29];let A;e[30]!==D?(A=(0,u.jsx)("p",{className:"px-1 pb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:D}),e[30]=D,e[31]=A):A=e[31];let Q;e[32]!==a?(Q=xt.map(V=>(0,u.jsx)("li",{children:(0,u.jsxs)("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":V.sql,onClick:a,type:"button",children:[(0,u.jsx)("svg",{"aria-hidden":"true",className:"size-3.5 shrink-0 opacity-70",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,u.jsx)("path",{d:"M7 4h7l4 4v12H7zM14 4v4h4"})}),V.label]})},V.label)),e[32]=a,e[33]=Q):Q=e[33];let F;e[34]!==Q?(F=(0,u.jsx)("ul",{className:"flex flex-col gap-px",children:Q}),e[34]=Q,e[35]=F):F=e[35];let ee;e[36]!==A||e[37]!==F?(ee=(0,u.jsxs)("div",{children:[A,F]}),e[36]=A,e[37]=F,e[38]=ee):ee=e[38];let P;e[39]!==t||e[40]!==r||e[41]!==i||e[42]!==I||e[43]!==k||e[44]!==h?(P=t.length>0&&(0,u.jsxs)("div",{children:[(0,u.jsxs)("div",{className:"flex items-center justify-between px-1 pb-1",children:[(0,u.jsx)("p",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:h("History")}),(0,u.jsx)("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:r,type:"button",children:h("Clear history")})]}),(0,u.jsxs)("label",{className:"flex cursor-pointer items-center gap-1.5 px-1 pb-1.5 text-[11px] text-muted-foreground",htmlFor:it,children:[(0,u.jsx)("input",{checked:k,"data-testid":"sql-history-remember",id:it,onChange:I,type:"checkbox"}),h("Keep history on this browser")]}),(0,u.jsx)("ul",{className:"flex flex-col gap-px","data-testid":"sql-history",children:t.map(V=>(0,u.jsx)("li",{children:(0,u.jsxs)("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":V.sql,"data-testid":"sql-history-item",onClick:i,title:V.sql,type:"button",children:[(0,u.jsx)("svg",{"aria-hidden":"true",className:"size-3.5 shrink-0 opacity-70",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,u.jsx)("path",{d:"M12 8v4l3 2M12 21a9 9 0 1 1 0-18 9 9 0 0 1 0 18Z"})}),(0,u.jsx)("span",{className:"truncate font-mono",children:V.sql})]})},`${V.at.toString()}:${V.sql}`))})]}),e[39]=t,e[40]=r,e[41]=i,e[42]=I,e[43]=k,e[44]=h,e[45]=P):P=e[45];let G;e[46]!==O||e[47]!==ee||e[48]!==P?(G=(0,u.jsxs)("div",{className:B,children:[O,ee,P]}),e[46]=O,e[47]=ee,e[48]=P,e[49]=G):G=e[49];let Z;return e[50]!==j||e[51]!==G?(Z=(0,u.jsxs)("aside",{className:T,children:[j,G]}),e[50]=j,e[51]=G,e[52]=Z):Z=e[52],Z},"is"),Ie=d(s=>`border-b-2 px-3 py-2 text-sm outline-none transition-colors ${s?"border-foreground font-medium text-foreground":"border-transparent text-muted-foreground hover:text-foreground"}`,"Ee"),co=d(s=>{let e=(0,X.c)(16),{chatOpen:n,onToggle:t}=s,o=J(),r;e[0]!==o?(r=o("Ask about your data"),e[0]=o,e[1]=r):r=e[1];let l=`inline-flex items-center gap-1.5 rounded-md border border-border px-2 py-1.5 outline-none transition-colors hover:bg-accent focus-visible:bg-accent ${n?"bg-accent text-foreground":"text-muted-foreground"}`,i;e[2]!==o?(i=o("Ask about your data"),e[2]=o,e[3]=i):i=e[3];let a;e[4]===Symbol.for("react.memo_cache_sentinel")?(a=(0,u.jsx)("svg",{"aria-hidden":"true",className:"size-4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,u.jsx)("path",{d:"M21 12a8 8 0 0 1-8 8H7l-4 3 1.2-4.2A8 8 0 1 1 21 12Z"})}),e[4]=a):a=e[4];let c;e[5]!==o?(c=o("Assistant"),e[5]=o,e[6]=c):c=e[6];let m;e[7]!==c?(m=(0,u.jsx)("span",{className:"text-xs",children:c}),e[7]=c,e[8]=m):m=e[8];let p;return e[9]!==n||e[10]!==t||e[11]!==r||e[12]!==l||e[13]!==i||e[14]!==m?(p=(0,u.jsxs)("button",{"aria-label":r,"aria-pressed":n,className:l,"data-testid":"sql-chat-toggle",onClick:t,title:i,type:"button",children:[a,m]}),e[9]=n,e[10]=t,e[11]=r,e[12]=l,e[13]=i,e[14]=m,e[15]=p):p=e[15],p},"as"),uo=d(s=>{let e=(0,X.c)(11),{onToggle:n,splitView:t}=s,o=J(),r;e[0]!==o?(r=o("Split editor and results"),e[0]=o,e[1]=r):r=e[1];let l=`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 ${t?"bg-accent text-foreground":"text-muted-foreground"}`,i;e[2]!==o?(i=o("Split editor and results"),e[2]=o,e[3]=i):i=e[3];let a;e[4]===Symbol.for("react.memo_cache_sentinel")?(a=(0,u.jsxs)("svg",{"aria-hidden":"true",className:"size-4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.7,viewBox:"0 0 24 24",children:[(0,u.jsx)("rect",{height:"16",rx:"2",width:"18",x:"3",y:"4"}),(0,u.jsx)("path",{d:"M12 4v16"})]}),e[4]=a):a=e[4];let c;return e[5]!==n||e[6]!==t||e[7]!==r||e[8]!==l||e[9]!==i?(c=(0,u.jsx)("button",{"aria-label":r,"aria-pressed":t,className:l,"data-testid":"sql-split-toggle",onClick:n,title:i,type:"button",children:a}),e[5]=n,e[6]=t,e[7]=r,e[8]=l,e[9]=i,e[10]=c):c=e[10],c},"cs"),mo=d(s=>{let e=(0,X.c)(8),{disabled:n,onExplainPlan:t,onExplainSql:o,pane:r}=s,l=J();if(r==="explain"){let a;return e[0]!==n||e[1]!==t||e[2]!==l?(a=t===void 0?null:(0,u.jsx)("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-explain-plan",disabled:n,onClick:t,type:"button",children:l("Read this plan")}),e[0]=n,e[1]=t,e[2]=l,e[3]=a):a=e[3],a}let i;return e[4]!==n||e[5]!==o||e[6]!==l?(i=o===void 0?null:(0,u.jsx)("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-explain-query",disabled:n,onClick:o,type:"button",children:l("Explain this query")}),e[4]=n,e[5]=o,e[6]=l,e[7]=i):i=e[7],i},"ds"),fo=d(s=>{let e=(0,X.c)(8),{onRun:n,running:t}=s,o=J(),r;e[0]!==t||e[1]!==o?(r=o(t?"Running\u2026":"Run"),e[0]=t,e[1]=o,e[2]=r):r=e[2];let l;e[3]===Symbol.for("react.memo_cache_sentinel")?(l=(0,u.jsx)("kbd",{className:"rounded border border-primary-foreground/30 px-1 font-sans text-[10px]",children:"\u2318\u21B5"}),e[3]=l):l=e[3];let i;return e[4]!==n||e[5]!==t||e[6]!==r?(i=(0,u.jsxs)("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:t,onClick:n,type:"button",children:[r,l]}),e[4]=n,e[5]=t,e[6]=r,e[7]=i):i=e[7],i},"us"),ho=d(s=>{let e=(0,X.c)(35),{onInferChart:n,onShowChart:t,onShowExplain:o,onShowResults:r,pane:l,result:i,rpc:a}=s,c=J(),m=l==="results",p;e[0]!==m?(p=Ie(m),e[0]=m,e[1]=p):p=e[1];let f;e[2]!==c?(f=c("Results"),e[2]=c,e[3]=f):f=e[3];let b;e[4]!==r||e[5]!==p||e[6]!==f?(b=(0,u.jsx)("button",{className:p,"data-testid":"sql-tab-results",onClick:r,type:"button",children:f}),e[4]=r,e[5]=p,e[6]=f,e[7]=b):b=e[7];let g=l==="chart",k;e[8]!==g?(k=Ie(g),e[8]=g,e[9]=k):k=e[9];let q;e[10]!==c?(q=c("Chart"),e[10]=c,e[11]=q):q=e[11];let N;e[12]!==t||e[13]!==k||e[14]!==q?(N=(0,u.jsx)("button",{className:k,"data-testid":"sql-tab-chart",onClick:t,type:"button",children:q}),e[12]=t,e[13]=k,e[14]=q,e[15]=N):N=e[15];let h;e[16]!==n||e[17]!==l||e[18]!==i||e[19]!==a||e[20]!==c?(h=!a.unavailable&&l==="chart"&&i!==null&&(0,u.jsx)("button",{className:Ie(!1),"data-testid":"sql-infer-chart",disabled:a.pending("chart"),onClick:n,type:"button",children:a.pending("chart")?c("Thinking\u2026"):c("Suggest chart")}),e[16]=n,e[17]=l,e[18]=i,e[19]=a,e[20]=c,e[21]=h):h=e[21];let S=l==="explain",x;e[22]!==S?(x=Ie(S),e[22]=S,e[23]=x):x=e[23];let v;e[24]!==c?(v=c("Explain"),e[24]=c,e[25]=v):v=e[25];let y;e[26]!==o||e[27]!==x||e[28]!==v?(y=(0,u.jsx)("button",{className:x,"data-testid":"sql-tab-explain",onClick:o,type:"button",children:v}),e[26]=o,e[27]=x,e[28]=v,e[29]=y):y=e[29];let w;return e[30]!==y||e[31]!==b||e[32]!==N||e[33]!==h?(w=(0,u.jsxs)(u.Fragment,{children:[b,N,h,y]}),e[30]=y,e[31]=b,e[32]=N,e[33]=h,e[34]=w):w=e[34],w},"fs"),po=d(s=>{let e=(0,X.c)(9),{onSelectStatement:n,script:t}=s,o;if(e[0]!==n||e[1]!==t.runs||e[2]!==t.selected){let l;e[4]!==n||e[5]!==t.selected?(l=d((i,a)=>(0,u.jsx)("button",{"aria-pressed":a===t.selected,className:`rounded-md border px-2 py-0.5 font-mono text-[11px] outline-none transition-colors ${a===t.selected?"border-foreground text-foreground":"border-border text-muted-foreground hover:text-foreground"} ${i.error===null?"":"border-destructive/50 text-destructive"}`,"data-testid":`sql-statement-${a.toString()}`,onClick:d(()=>{n(a)},"onClick"),title:i.sql,type:"button",children:a+1},`${a.toString()}:${i.sql}`),"l"),e[4]=n,e[5]=t.selected,e[6]=l):l=e[6],o=t.runs.map(l),e[0]=n,e[1]=t.runs,e[2]=t.selected,e[3]=o}else o=e[3];let r;return e[7]!==o?(r=(0,u.jsx)("div",{className:"flex shrink-0 flex-wrap items-center gap-1 border-b border-border px-3 py-1.5","data-testid":"sql-statements",children:o}),e[7]=o,e[8]=r):r=e[8],r},"ms"),bo=d(s=>{let e=(0,X.c)(9),{error:n,onDebugError:t,rpc:o}=s,r=J(),l;e[0]!==n?(l=(0,u.jsx)(Xe,{className:"w-full font-mono text-xs",testId:"sql-error",variant:"destructive",children:n}),e[0]=n,e[1]=l):l=e[1];let i;e[2]!==t||e[3]!==o||e[4]!==r?(i=!o.unavailable&&t!==void 0&&(0,u.jsxs)("button",{className:"inline-flex items-center gap-1.5 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-debug-error",disabled:o.pending("chat"),onClick:t,type:"button",children:[(0,u.jsx)("svg",{"aria-hidden":"true",className:"size-3.5",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,u.jsx)("path",{d:"M21 12a8 8 0 0 1-8 8H7l-4 3 1.2-4.2A8 8 0 1 1 21 12Z"})}),o.pending("chat")?r("Thinking\u2026"):r("Debug with AI")]}),e[2]=t,e[3]=o,e[4]=r,e[5]=i):i=e[5];let a;return e[6]!==l||e[7]!==i?(a=(0,u.jsxs)("div",{className:"m-3 flex flex-col items-start gap-2",children:[l,i]}),e[6]=l,e[7]=i,e[8]=a):a=e[8],a},"ps"),go=d(s=>{let e=(0,X.c)(18),{chart:n,durationMs:t,pane:o,result:r}=s,l=J(),i;e[0]!==n||e[1]!==o||e[2]!==r?(i=o==="chart"?(0,u.jsx)(et,{axes:n,result:r}):(0,u.jsx)(tt,{result:r}),e[0]=n,e[1]=o,e[2]=r,e[3]=i):i=e[3];let a;e[4]!==r.rowCount||e[5]!==r.rows||e[6]!==r.truncated||e[7]!==l?(a=r.truncated?l("Showing the first {max} rows.",{max:r.rows.length}):l("{count} rows",{count:r.rowCount}),e[4]=r.rowCount,e[5]=r.rows,e[6]=r.truncated,e[7]=l,e[8]=a):a=e[8];let c;e[9]!==t||e[10]!==l?(c=t!==void 0&&` \xB7 ${l("{ms} ms",{ms:Math.round(t)})}`,e[9]=t,e[10]=l,e[11]=c):c=e[11];let m;e[12]!==a||e[13]!==c?(m=(0,u.jsxs)("p",{className:"border-t border-border px-3 py-1.5 text-xs text-muted-foreground","data-testid":"sql-count",children:[a,c]}),e[12]=a,e[13]=c,e[14]=m):m=e[14];let p;return e[15]!==i||e[16]!==m?(p=(0,u.jsxs)("div",{"data-testid":"sql-result",children:[i,m]}),e[15]=i,e[16]=m,e[17]=p):p=e[17],p},"hs"),xo=d(s=>{let e=(0,X.c)(13),{chart:n,durationMs:t,error:o,onDebugError:r,pane:l,result:i,rpc:a}=s,c=J();if(o!==null){let p;return e[0]!==o||e[1]!==r||e[2]!==a?(p=(0,u.jsx)(bo,{error:o,onDebugError:r,rpc:a}),e[0]=o,e[1]=r,e[2]=a,e[3]=p):p=e[3],p}if(i===null){let p;e[4]!==c?(p=c("Click Run to execute your query."),e[4]=c,e[5]=p):p=e[5];let f;return e[6]!==p?(f=(0,u.jsx)("p",{className:"p-4 text-sm text-muted-foreground","data-testid":"sql-empty",children:p}),e[6]=p,e[7]=f):f=e[7],f}let m;return e[8]!==n||e[9]!==t||e[10]!==l||e[11]!==i?(m=(0,u.jsx)(go,{chart:n,durationMs:t,pane:l,result:i}),e[8]=n,e[9]=t,e[10]=l,e[11]=i,e[12]=m):m=e[12],m},"bs"),vo=d(s=>{let e=(0,X.c)(63),{rpc:n,chart:t,className:o,durationMs:r,error:l,onFormat:i,onInferChart:a,onRun:c,onSelectStatement:m,onShardKeyChange:p,onShowChart:f,onShowExplain:b,onShowResults:g,chatOpen:k,onDebugError:q,onExplainPlan:N,onExplainSql:h,onToggleChat:S,onToggleSplit:x,pane:v,result:y,running:w,script:E,shardKey:I,splitView:T}=s,L=J(),C;e[0]!==a||e[1]!==f||e[2]!==b||e[3]!==g||e[4]!==v||e[5]!==y||e[6]!==n?(C=(0,u.jsx)(ho,{onInferChart:a,onShowChart:f,onShowExplain:b,onShowResults:g,pane:v,result:y,rpc:n}),e[0]=a,e[1]=f,e[2]=b,e[3]=g,e[4]=v,e[5]=y,e[6]=n,e[7]=C):C=e[7];let R;e[8]!==k||e[9]!==S?(R=S!==void 0&&(0,u.jsx)(co,{chatOpen:k,onToggle:S}),e[8]=k,e[9]=S,e[10]=R):R=e[10];let _;e[11]!==x||e[12]!==T?(_=(0,u.jsx)(uo,{onToggle:x,splitView:T}),e[11]=x,e[12]=T,e[13]=_):_=e[13];let M;e[14]!==y?(M=y!==null&&y.columns.length>0&&(0,u.jsx)(Ze,{columns:y.columns,name:"query-result",rows:y.rows}),e[14]=y,e[15]=M):M=e[15];let z;e[16]!==L?(z=L("Format"),e[16]=L,e[17]=z):z=e[17];let j;e[18]!==i||e[19]!==w||e[20]!==z?(j=(0,u.jsx)("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:w,onClick:i,type:"button",children:z}),e[18]=i,e[19]=w,e[20]=z,e[21]=j):j=e[21];let B;e[22]!==n||e[23]!==w?(B=w||n.pending("chat"),e[22]=n,e[23]=w,e[24]=B):B=e[24];let W;e[25]!==N||e[26]!==h||e[27]!==v||e[28]!==B?(W=(0,u.jsx)(mo,{disabled:B,onExplainPlan:N,onExplainSql:h,pane:v}),e[25]=N,e[26]=h,e[27]=v,e[28]=B,e[29]=W):W=e[29];let $;e[30]!==p||e[31]!==I?($=(0,u.jsx)(Ve,{onChange:p,testId:"sql-shard-input",value:I}),e[30]=p,e[31]=I,e[32]=$):$=e[32];let K;e[33]!==c||e[34]!==w?(K=(0,u.jsx)(fo,{onRun:c,running:w}),e[33]=c,e[34]=w,e[35]=K):K=e[35];let O;e[36]!==K||e[37]!==R||e[38]!==_||e[39]!==M||e[40]!==j||e[41]!==W||e[42]!==$?(O=(0,u.jsxs)("div",{className:"ms-auto flex items-center gap-2",children:[R,_,M,j,W,$,K]}),e[36]=K,e[37]=R,e[38]=_,e[39]=M,e[40]=j,e[41]=W,e[42]=$,e[43]=O):O=e[43];let D;e[44]!==C||e[45]!==O?(D=(0,u.jsxs)("div",{className:"flex shrink-0 items-center gap-2 border-b border-border pe-2",children:[C,O]}),e[44]=C,e[45]=O,e[46]=D):D=e[46];let A;e[47]!==m||e[48]!==E?(A=E!==void 0&&(0,u.jsx)(po,{onSelectStatement:m,script:E}),e[47]=m,e[48]=E,e[49]=A):A=e[49];let Q;e[50]!==t||e[51]!==r||e[52]!==l||e[53]!==q||e[54]!==v||e[55]!==y||e[56]!==n?(Q=(0,u.jsx)("div",{className:"min-h-0 flex-1 overflow-auto",children:(0,u.jsx)(xo,{chart:t,durationMs:r,error:l,onDebugError:q,pane:v,result:y,rpc:n})}),e[50]=t,e[51]=r,e[52]=l,e[53]=q,e[54]=v,e[55]=y,e[56]=n,e[57]=Q):Q=e[57];let F;return e[58]!==o||e[59]!==D||e[60]!==A||e[61]!==Q?(F=(0,u.jsxs)("div",{className:o,children:[D,A,Q]}),e[58]=o,e[59]=D,e[60]=A,e[61]=Q,e[62]=F):F=e[62],F},"gs"),yo=d((s,e)=>s.trim()===""?e:(s.split(`
|
|
15
|
-
`)[0]??s).slice(0,24),"xs"),wo=d(s=>{s?.focus(),s?.select()},"vs"),So=d(s=>{let e=(0,X.c)(14),{initial:n,onCancel:t,onCommit:o,placeholder:r,testId:l}=s,i=J(),a;e[0]!==o?(a=d(g=>{o(g.currentTarget.value.trim())},"c"),e[0]=o,e[1]=a):a=e[1];let c=a,m;e[2]!==t||e[3]!==o?(m=d(g=>{g.key==="Enter"?o(g.currentTarget.value.trim()):g.key==="Escape"&&t()},"d"),e[2]=t,e[3]=o,e[4]=m):m=e[4];let p=m,f;e[5]!==i?(f=i("Tab title"),e[5]=i,e[6]=f):f=e[6];let b;return e[7]!==n||e[8]!==c||e[9]!==p||e[10]!==r||e[11]!==f||e[12]!==l?(b=(0,u.jsx)("input",{"aria-label":f,className:"w-40 rounded border border-ring bg-background px-1 py-0.5 text-xs outline-none","data-testid":l,defaultValue:n,onBlur:c,onKeyDown:p,placeholder:r,ref:wo,type:"text"}),e[7]=n,e[8]=c,e[9]=p,e[10]=r,e[11]=f,e[12]=l,e[13]=b):b=e[13],b},"ys"),qo=d(s=>{let e=(0,X.c)(29),{idBase:n,onDiscard:t,onKeep:o}=s,r=J(),l=`sql-tab-close-prompt-${n}`,i;e[0]!==r?(i=r("Discard?"),e[0]=r,e[1]=i):i=e[1];let a;e[2]!==i?(a=(0,u.jsx)("span",{className:"text-[11px] text-muted-foreground",children:i}),e[2]=i,e[3]=a):a=e[3];let c;e[4]!==r?(c=r("Discard changes"),e[4]=r,e[5]=c):c=e[5];let m=`sql-tab-close-confirm-${n}`,p;e[6]!==r?(p=r("Discard changes"),e[6]=r,e[7]=p):p=e[7];let f;e[8]===Symbol.for("react.memo_cache_sentinel")?(f=(0,u.jsx)("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2.4,viewBox:"0 0 24 24",children:(0,u.jsx)("path",{d:"M5 13l4 4L19 7"})}),e[8]=f):f=e[8];let b;e[9]!==t||e[10]!==c||e[11]!==m||e[12]!==p?(b=(0,u.jsx)("button",{"aria-label":c,className:"flex size-5 items-center justify-center rounded text-destructive hover:bg-destructive/10","data-testid":m,onClick:t,title:p,type:"button",children:f}),e[9]=t,e[10]=c,e[11]=m,e[12]=p,e[13]=b):b=e[13];let g;e[14]!==r?(g=r("Keep editing"),e[14]=r,e[15]=g):g=e[15];let k=`sql-tab-close-cancel-${n}`,q;e[16]!==r?(q=r("Keep editing"),e[16]=r,e[17]=q):q=e[17];let N;e[18]===Symbol.for("react.memo_cache_sentinel")?(N=(0,u.jsx)("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2.4,viewBox:"0 0 24 24",children:(0,u.jsx)("path",{d:"M6 6l12 12M18 6 6 18"})}),e[18]=N):N=e[18];let h;e[19]!==o||e[20]!==k||e[21]!==q||e[22]!==g?(h=(0,u.jsx)("button",{"aria-label":g,className:"flex size-5 items-center justify-center rounded text-muted-foreground hover:bg-accent","data-testid":k,onClick:o,title:q,type:"button",children:N}),e[19]=o,e[20]=k,e[21]=q,e[22]=g,e[23]=h):h=e[23];let S;return e[24]!==l||e[25]!==h||e[26]!==a||e[27]!==b?(S=(0,u.jsxs)("span",{className:"flex shrink-0 items-center gap-1","data-testid":l,role:"group",children:[a,b,h]}),e[24]=l,e[25]=h,e[26]=a,e[27]=b,e[28]=S):S=e[28],S},"Ss"),ko=d(s=>{let e=(0,X.c)(47),{active:n,canClose:t,onClose:o,onMenu:r,onRename:l,onSelect:i,tab:a}=s,c=J(),[m,p]=(0,H.useState)(!1),[f,b]=(0,H.useState)(!1),g;e[0]!==r||e[1]!==a.id?(g=d(A=>{r(a.id,A)},"g"),e[0]=r,e[1]=a.id,e[2]=g):g=e[2];let k=g,q;e[3]!==i||e[4]!==a.id?(q=d(()=>{i(a.id)},"v"),e[3]=i,e[4]=a.id,e[5]=q):q=e[5];let N=q,h;e[6]===Symbol.for("react.memo_cache_sentinel")?(h=d(()=>{p(!0)},"p"),e[6]=h):h=e[6];let S=h,x;e[7]!==o||e[8]!==a?(x=d(A=>{A.stopPropagation(),gt(a)?b(!0):o(a.id)},"x"),e[7]=o,e[8]=a,e[9]=x):x=e[9];let v=x,y;e[10]!==o||e[11]!==a.id?(y=d(A=>{A.stopPropagation(),b(!1),o(a.id)},"y"),e[10]=o,e[11]=a.id,e[12]=y):y=e[12];let w=y,E;e[13]===Symbol.for("react.memo_cache_sentinel")?(E=d(A=>{A.stopPropagation(),b(!1)},"w"),e[13]=E):E=e[13];let I=E,T;e[14]!==l||e[15]!==a.id?(T=d(A=>{l(a.id,A),p(!1)},"q"),e[14]=l,e[15]=a.id,e[16]=T):T=e[16];let L=T,C;e[17]===Symbol.for("react.memo_cache_sentinel")?(C=d(()=>{p(!1)},"E"),e[17]=C):C=e[17];let R=C,_;e[18]!==a.name?(_=a.name.trim(),e[18]=a.name,e[19]=_):_=e[19];let M=_,z;e[20]!==c||e[21]!==a.sql?(z=yo(a.sql,c("Untitled")),e[20]=c,e[21]=a.sql,e[22]=z):z=e[22];let j=z,B=n?"bg-background text-foreground":"bg-muted/40 text-muted-foreground hover:text-foreground",W;e[23]!==B?(W=ie("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];let $=`sql-tab-${a.id}`,K;e[25]!==n||e[26]!==L||e[27]!==M||e[28]!==j||e[29]!==m||e[30]!==N||e[31]!==c||e[32]!==a.id?(K=m?(0,u.jsx)(So,{initial:M,onCancel:R,onCommit:L,placeholder:j,testId:`sql-tab-rename-${a.id}`}):(0,u.jsx)("button",{"aria-pressed":n,className:"max-w-40 truncate py-1.5 outline-none","data-testid":`sql-tab-select-${a.id}`,onClick:N,onDoubleClick:S,title:c("Double-click to rename"),type:"button",children:M===""?j:M}),e[25]=n,e[26]=L,e[27]=M,e[28]=j,e[29]=m,e[30]=N,e[31]=c,e[32]=a.id,e[33]=K):K=e[33];let O;e[34]!==t||e[35]!==w||e[36]!==f||e[37]!==v||e[38]!==c||e[39]!==a.id?(O=t&&(f?(0,u.jsx)(qo,{idBase:a.id,onDiscard:w,onKeep:I}):(0,u.jsx)("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-${a.id}`,onClick:v,title:c("Close tab"),type:"button",children:(0,u.jsx)("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,viewBox:"0 0 24 24",children:(0,u.jsx)("path",{d:"M6 6l12 12M18 6 6 18"})})})),e[34]=t,e[35]=w,e[36]=f,e[37]=v,e[38]=c,e[39]=a.id,e[40]=O):O=e[40];let D;return e[41]!==k||e[42]!==W||e[43]!==$||e[44]!==K||e[45]!==O?(D=(0,u.jsxs)("div",{className:W,"data-testid":$,onContextMenu:k,children:[K,O]}),e[41]=k,e[42]=W,e[43]=$,e[44]=K,e[45]=O,e[46]=D):D=e[46],D},"ws"),Co=d(s=>{let e=(0,X.c)(43),{model:n,onSelect:t}=s,o=J(),{activeTab:r,addEditorTab:l,cancelBulk:i,closeEditorTab:a,closeTabMenu:c,confirmBulk:m,menuStyle:p,onBackdropContextMenu:f,onCloseAll:b,onCloseOthers:g,onCloseToRight:k,openTabMenu:q,pendingBulk:N,renameTab:h,tabMenu:S,tabs:x}=n,v;if(e[0]!==r||e[1]!==a||e[2]!==t||e[3]!==q||e[4]!==h||e[5]!==x){let _;e[7]!==r||e[8]!==a||e[9]!==t||e[10]!==q||e[11]!==h||e[12]!==x.length?(_=d(M=>(0,u.jsx)(ko,{active:M.id===r.id,canClose:x.length>1,onClose:a,onMenu:q,onRename:h,onSelect:t,tab:M},M.id),"L"),e[7]=r,e[8]=a,e[9]=t,e[10]=q,e[11]=h,e[12]=x.length,e[13]=_):_=e[13],v=x.map(_),e[0]=r,e[1]=a,e[2]=t,e[3]=q,e[4]=h,e[5]=x,e[6]=v}else v=e[6];let y;e[14]!==o?(y=o("New tab"),e[14]=o,e[15]=y):y=e[15];let w=x.length>=He,E;e[16]!==o?(E=o("New tab"),e[16]=o,e[17]=E):E=e[17];let I;e[18]===Symbol.for("react.memo_cache_sentinel")?(I=(0,u.jsx)("svg",{"aria-hidden":"true",className:"size-4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.7,viewBox:"0 0 24 24",children:(0,u.jsx)("path",{d:"M12 5v14M5 12h14"})}),e[18]=I):I=e[18];let T;e[19]!==l||e[20]!==y||e[21]!==w||e[22]!==E?(T=(0,u.jsx)("button",{"aria-label":y,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:w,onClick:l,title:E,type:"button",children:I}),e[19]=l,e[20]=y,e[21]=w,e[22]=E,e[23]=T):T=e[23];let L;e[24]!==v||e[25]!==T?(L=(0,u.jsxs)("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:[v,T]}),e[24]=v,e[25]=T,e[26]=L):L=e[26];let C;e[27]!==i||e[28]!==c||e[29]!==m||e[30]!==p||e[31]!==f||e[32]!==b||e[33]!==g||e[34]!==k||e[35]!==N||e[36]!==o||e[37]!==S||e[38]!==x?(C=S!==null&&(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)("div",{className:"fixed inset-0 z-40","data-testid":"sql-tab-menu-backdrop",onClick:c,onContextMenu:f,role:"presentation"}),(0,u.jsx)("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:p,children:N===null?(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)("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:x.length<=1,onClick:g,role:"menuitem",type:"button",children:o("Close other tabs")}),(0,u.jsx)("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:x.findIndex(_=>_.id===S.id)>=x.length-1,onClick:k,role:"menuitem",type:"button",children:o("Close tabs to the right")}),(0,u.jsx)("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:b,role:"menuitem",type:"button",children:o("Close all tabs")})]}):(0,u.jsxs)("div",{className:"px-3 py-1.5","data-testid":"sql-tab-menu-confirm",children:[(0,u.jsx)("p",{className:"pb-1.5 text-xs text-muted-foreground",children:o("Discard unsaved tabs?")}),(0,u.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,u.jsx)("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:m,type:"button",children:o("Discard")}),(0,u.jsx)("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:i,type:"button",children:o("Cancel")})]})]})})]}),e[27]=i,e[28]=c,e[29]=m,e[30]=p,e[31]=f,e[32]=b,e[33]=g,e[34]=k,e[35]=N,e[36]=o,e[37]=S,e[38]=x,e[39]=C):C=e[39];let R;return e[40]!==L||e[41]!==C?(R=(0,u.jsxs)(u.Fragment,{children:[L,C]}),e[40]=L,e[41]=C,e[42]=R):R=e[42],R},"Cs"),No=ge(ve.runSql),Eo="lunora-studio-sql-split-view",To=d(()=>qe(xt[0]?.sql??""),"Es"),Lo=d(()=>performance.now(),"Ts"),Io=d(()=>{let s=(0,X.c)(2),e;s[0]===Symbol.for("react.memo_cache_sentinel")?(e=new Map,s[0]=e):e=s[0];let n=(0,H.useRef)(e),t;return s[1]===Symbol.for("react.memo_cache_sentinel")?(t={advance:d(o=>{n.current.set(o,(n.current.get(o)??0)+1)},"advance"),begin:d(o=>{let r=n.current.get(o)??0;return()=>(n.current.get(o)??0)===r},"begin")},s[1]=t):t=s[1],t},"qs"),Ro=d((s,e)=>{let n=s.tables[0];return n===void 0?[e("What tables does this app have?")]:[e("What tables does this app have?"),e("Show me the most recent rows in {table}",{table:n}),e("Is anything wrong with my schema?")]},"Rs"),Re=d(s=>s.tables.map(e=>({columns:[...s.columns[e]??[]],table:e})),"Te"),or=d(({initialShardKey:s,now:e=Lo})=>{let n=Ce(),t=On(To),{activeTab:o,openEditorTab:r,output:l,patchActiveOutput:i,patchActiveTab:a,setActiveTabId:c,unlinkQuery:m}=t,p=Io(),f=Fn({loadIntoActiveTab:d((U,oe)=>{p.advance(o.id),a({activeId:oe,sql:U}),i({chart:void 0,durationMs:void 0,error:null,failed:void 0,result:null,running:!1,script:void 0})},"loadIntoActiveTab"),unlinkQuery:m}),{recordHistory:b,updateQuerySql:g}=f,k=o.sql,{activeId:q}=o,{chart:N,error:h,failed:S,result:x,running:v}=l,y=l.pane,[w,E]=(0,H.useState)(s??""),[I,T]=Ee(Eo,!1),L=J(),C=Ke(),{probe:R,schema:_}=qn(w),M=(0,H.useCallback)(U=>{a({sql:U}),q!==null&&g(q,U)},[q,a,g]),z=C?.setHasEditor;(0,H.useEffect)(()=>{if(z!==void 0)return z(!0),()=>{z(!1)}},[z]);let j=C?.insertRequest,B=C?.takeInsert;(0,H.useEffect)(()=>{j===void 0||B===void 0||(B(j.id),k.trim()===""&&q===null?M(j.sql):r(j.sql)||a({activeId:null,sql:k.trim()===""?j.sql:`${k.trimEnd()}
|
|
14
|
+
`),"is"),co=d((s,e)=>{let n=[],t=1,o=1;for(let r of Pe(s,e,{ignoreNewlineAtEof:!0}))for(let l of ao(r.value))r.added?(n.push({after:o,kind:"added",text:l}),o+=1):r.removed?(n.push({before:t,kind:"removed",text:l}),t+=1):(n.push({after:o,before:t,kind:"context",text:l}),t+=1,o+=1);return n},"as"),uo={added:"bg-emerald-500/10 text-emerald-700 dark:text-emerald-400",context:"text-muted-foreground",removed:"bg-destructive/10 text-destructive"},mo={added:"+",context:" ",removed:"-"},fo=d(s=>{let e=(0,V.c)(11),{lines:n}=s,t=J(),o;e[0]!==t?(o=t("Proposed edit"),e[0]=t,e[1]=o):o=e[1];let r;e[2]===Symbol.for("react.memo_cache_sentinel")?(r=ie("max-h-48 overflow-auto rounded-md border border-border bg-background",Fe),e[2]=r):r=e[2];let l;if(e[3]!==n||e[4]!==t){let a;e[6]!==t?(a=d(c=>(0,u.jsxs)("li",{className:ie("flex gap-2",uo[c.kind]),"data-kind":c.kind,children:[(0,u.jsx)("span",{"aria-hidden":"true",className:"shrink-0 select-none opacity-60",children:mo[c.kind]}),c.kind!=="context"&&(0,u.jsx)("span",{className:"sr-only",children:c.kind==="added"?t("Added"):t("Removed")}),(0,u.jsx)("span",{className:"min-w-0",children:c.text===""?"\xA0":c.text})]},`${String(c.before)}:${String(c.after)}`),"c"),e[6]=t,e[7]=a):a=e[7],l=n.map(a),e[3]=n,e[4]=t,e[5]=l}else l=e[5];let i;return e[8]!==o||e[9]!==l?(i=(0,u.jsx)("ul",{"aria-label":o,className:r,"data-testid":"sql-inline-diff",children:l}),e[8]=o,e[9]=l,e[10]=i):i=e[10],i},"us"),_e="rounded-md border border-border px-2 py-1 text-xs outline-none transition-colors hover:bg-accent focus-visible:bg-accent",ho=d(s=>{let e=(0,V.c)(41),{onAccept:n,onCancel:t,rpc:o,source:r,whole:l}=s,i=J(),a=(0,j.useRef)(null),c=(0,j.useRef)(null),[m,p]=(0,j.useState)(""),[f,b]=(0,j.useState)(null),g,k;if(e[0]!==f?(g=d(()=>{f===null?a.current?.focus():c.current?.focus()},"g"),k=[f],e[0]=f,e[1]=g,e[2]=k):(g=e[1],k=e[2]),(0,j.useEffect)(g,k),o.unavailable)return null;let q;e[3]!==o?(q=o.pending("sql"),e[3]=o,e[4]=q):q=e[4];let N=q,h;if(e[5]!==m||e[6]!==n||e[7]!==t||e[8]!==N||e[9]!==f||e[10]!==o||e[11]!==r||e[12]!==i||e[13]!==l){let S=o.reason("sql"),x;e[15]!==m||e[16]!==o||e[17]!==r?(x=d(()=>{let I=m.trim();I===""||r.trim()===""||le((async()=>{let R=await o.rewrite(I,r);R!==void 0&&b(R)})())},"x"),e[15]=m,e[16]=o,e[17]=r,e[18]=x):x=e[18];let v=x,y;e[19]!==t?(y=d(I=>{I.key==="Escape"&&(I.preventDefault(),t())},"y"),e[19]=t,e[20]=y):y=e[20];let w=y,E;e[21]!==i||e[22]!==l?(E=i(l?"Whole query":"Selection"),e[21]=i,e[22]=l,e[23]=E):E=e[23];let T;e[24]!==E?(T=(0,u.jsx)("span",{className:"shrink-0 rounded bg-muted px-1 font-mono text-[10px] uppercase text-muted-foreground","data-testid":"sql-inline-edit-scope",children:E}),e[24]=E,e[25]=T):T=e[25];let L;e[26]!==m||e[27]!==n||e[28]!==t||e[29]!==w||e[30]!==N||e[31]!==f||e[32]!==v||e[33]!==i?(L=f===null?(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(ye,{"aria-label":i("Tell the model what to change"),className:"h-7 flex-1 text-xs","data-testid":"sql-inline-edit-prompt",disabled:N,onChange:d(I=>{p(I.target.value)},"onChange"),onKeyDown:d(I=>{if(I.key==="Enter"){I.preventDefault(),v();return}w(I)},"onKeyDown"),placeholder:i("Tell the model what to change"),ref:a,value:m}),(0,u.jsx)("button",{className:ie(_e,N&&"opacity-60"),"data-testid":"sql-inline-edit-submit",disabled:N||m.trim()==="",onClick:v,onKeyDown:w,type:"button",children:i(N?"Thinking\u2026":"Rewrite")}),(0,u.jsx)("button",{className:_e,"data-testid":"sql-inline-edit-cancel",onClick:t,onKeyDown:w,type:"button",children:i("Cancel")})]}):(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)("span",{className:"flex-1 text-xs text-muted-foreground",children:i("Proposed edit")}),(0,u.jsx)("button",{className:_e,"data-testid":"sql-inline-edit-accept",onClick:d(()=>{n(f)},"onClick"),onKeyDown:w,ref:c,type:"button",children:i("Accept")}),(0,u.jsx)("button",{className:_e,"data-testid":"sql-inline-edit-reject",onClick:d(()=>{b(null)},"onClick"),onKeyDown:w,type:"button",children:i("Reject")})]}),e[26]=m,e[27]=n,e[28]=t,e[29]=w,e[30]=N,e[31]=f,e[32]=v,e[33]=i,e[34]=L):L=e[34];let _;e[35]!==T||e[36]!==L?(_=(0,u.jsxs)("div",{className:"flex items-center gap-2",children:[T,L]}),e[35]=T,e[36]=L,e[37]=_):_=e[37];let C;e[38]!==f||e[39]!==r?(C=f!==null&&(0,u.jsx)(fo,{lines:co(r,f)}),e[38]=f,e[39]=r,e[40]=C):C=e[40],h=(0,u.jsxs)("div",{className:"flex flex-col gap-1 border-b border-border bg-muted/20 px-3 py-2","data-testid":"sql-inline-edit",children:[_,C,S!==void 0&&(0,u.jsx)("p",{className:"text-[11px] text-muted-foreground","data-testid":"sql-inline-edit-reason",role:"status",children:Ae(S,i)})]}),e[5]=m,e[6]=n,e[7]=t,e[8]=N,e[9]=f,e[10]=o,e[11]=r,e[12]=i,e[13]=l,e[14]=h}else h=e[14];return h},"fs"),po={minWidth:"2.75rem",paddingInline:"0.5rem"},bo=d(s=>{let e=(0,V.c)(75),{rpc:n,autocomplete:t,diagnostics:o,draft:r,failed:l,handlers:i,editorRef:a,gutterRef:c,inlineEdit:m,listboxId:p,onAcceptInlineEdit:f,onCancelInlineEdit:b,onGenerated:g,onPickSuggestion:k,onRevealDiagnostic:q,overlayRef:N}=s,h=J(),S,x,v,y,w,E,T,L,_;if(e[0]!==r||e[1]!==l||e[2]!==c||e[3]!==m||e[4]!==f||e[5]!==b||e[6]!==g||e[7]!==n){let A=r.split(`
|
|
15
|
+
`).length;T="flex min-h-0 min-w-0 flex-1 flex-col",e[17]!==l||e[18]!==g||e[19]!==n?(L=(0,u.jsx)(ro,{failed:l,onGenerated:g,rpc:n}),e[17]=l,e[18]=g,e[19]=n,e[20]=L):L=e[20],e[21]!==r.length||e[22]!==m||e[23]!==f||e[24]!==b||e[25]!==n?(_=m!==null&&(0,u.jsx)(ho,{onAccept:f,onCancel:b,rpc:n,source:m.text,whole:m.start===0&&m.end===r.length},`${m.start.toString()}-${m.end.toString()}`),e[21]=r.length,e[22]=m,e[23]=f,e[24]=b,e[25]=n,e[26]=_):_=e[26],E="flex min-h-0 min-w-0 flex-1",S="true",x="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",v=c,y=po,w=Array.from({length:A},go),e[0]=r,e[1]=l,e[2]=c,e[3]=m,e[4]=f,e[5]=b,e[6]=g,e[7]=n,e[8]=S,e[9]=x,e[10]=v,e[11]=y,e[12]=w,e[13]=E,e[14]=T,e[15]=L,e[16]=_}else S=e[8],x=e[9],v=e[10],y=e[11],w=e[12],E=e[13],T=e[14],L=e[15],_=e[16];let C;e[27]!==S||e[28]!==x||e[29]!==v||e[30]!==y||e[31]!==w?(C=(0,u.jsx)("div",{"aria-hidden":S,className:x,ref:v,style:y,children:w}),e[27]=S,e[28]=x,e[29]=v,e[30]=y,e[31]=w,e[32]=C):C=e[32];let I;e[33]!==o||e[34]!==r||e[35]!==N?(I=(0,u.jsx)(so,{diagnostics:o,draft:r,scrollRef:N}),e[33]=o,e[34]=r,e[35]=N,e[36]=I):I=e[36];let R;e[37]!==t||e[38]!==p?(R=t===null?void 0:`${p}-opt-${t.active.toString()}`,e[37]=t,e[38]=p,e[39]=R):R=e[39];let M=t===null?void 0:p,z=t!==null,H;e[40]!==h?(H=h("SQL query"),e[40]=h,e[41]=H):H=e[41];let W;e[42]!==r||e[43]!==a||e[44]!==i.onBlur||e[45]!==i.onChange||e[46]!==i.onKeyDown||e[47]!==i.onScroll||e[48]!==i.onSelect||e[49]!==R||e[50]!==M||e[51]!==z||e[52]!==H?(W=(0,u.jsx)("textarea",{"aria-activedescendant":R,"aria-autocomplete":"list","aria-controls":M,"aria-expanded":z,"aria-label":H,className:`relative size-full resize-none bg-transparent outline-none ${Fe}`,"data-testid":"sql-input",onBlur:i.onBlur,onChange:i.onChange,onKeyDown:i.onKeyDown,onScroll:i.onScroll,onSelect:i.onSelect,placeholder:"SELECT * FROM \u2026",ref:a,role:"combobox",spellCheck:!1,value:r}),e[42]=r,e[43]=a,e[44]=i.onBlur,e[45]=i.onChange,e[46]=i.onKeyDown,e[47]=i.onScroll,e[48]=i.onSelect,e[49]=R,e[50]=M,e[51]=z,e[52]=H,e[53]=W):W=e[53];let B;e[54]!==t||e[55]!==p||e[56]!==k?(B=(0,u.jsx)(Rn,{listboxId:p,onPick:k,state:t}),e[54]=t,e[55]=p,e[56]=k,e[57]=B):B=e[57];let P;e[58]!==I||e[59]!==W||e[60]!==B?(P=(0,u.jsxs)("div",{className:"relative min-w-0 flex-1 bg-background",children:[I,W,B]}),e[58]=I,e[59]=W,e[60]=B,e[61]=P):P=e[61];let K;e[62]!==C||e[63]!==P||e[64]!==E?(K=(0,u.jsxs)("div",{className:E,children:[C,P]}),e[62]=C,e[63]=P,e[64]=E,e[65]=K):K=e[65];let O;e[66]!==o||e[67]!==q?(O=(0,u.jsx)(io,{diagnostics:o,onSelect:q}),e[66]=o,e[67]=q,e[68]=O):O=e[68];let D;return e[69]!==K||e[70]!==O||e[71]!==T||e[72]!==L||e[73]!==_?(D=(0,u.jsxs)("div",{className:T,children:[L,_,K,O]}),e[69]=K,e[70]=O,e[71]=T,e[72]=L,e[73]=_,e[74]=D):D=e[74],D},"ps");function go(s,e){return(0,u.jsx)("div",{children:e+1},e)}d(go,"hs");var xo=d(s=>{let e=(0,V.c)(62),{onCancel:n,onSave:t,query:o,rpc:r}=s,l=J(),[i,a]=(0,j.useState)(o.name),[c,m]=(0,j.useState)(o.description??""),p;e[0]!==o.sql||e[1]!==r?(p=r!==void 0&&!r.unavailable&&o.sql.trim()!=="",e[0]=o.sql,e[1]=r,e[2]=p):p=e[2];let f=p,b;e[3]!==r?(b=r?.pending("name"),e[3]=r,e[4]=b):b=e[4];let g=b===!0,k;e[5]!==r?(k=r?.reason("name"),e[5]=r,e[6]=k):k=e[6];let q=k,N;e[7]!==c||e[8]!==i||e[9]!==o.sql||e[10]!==r?(N=d(()=>{if(r===void 0)return;let O=i,D=c;le((async()=>{let A=await r.nameQuery(o.sql);A!==void 0&&(a(Q=>Q===O?A.title:Q),m(Q=>Q===D?A.description:Q))})())},"S"),e[7]=c,e[8]=i,e[9]=o.sql,e[10]=r,e[11]=N):N=e[11];let h=N,S;e[12]!==c||e[13]!==i||e[14]!==t?(S=d(O=>{O.preventDefault();let D=i.trim();D!==""&&t(D,c.trim())},"N"),e[12]=c,e[13]=i,e[14]=t,e[15]=S):S=e[15];let x=S,v=`sql-query-rename-${o.id}`,y;e[16]!==l?(y=l("Query name"),e[16]=l,e[17]=y):y=e[17];let w;e[18]===Symbol.for("react.memo_cache_sentinel")?(w=d(O=>{a(O.target.value)},"C"),e[18]=w):w=e[18];let E;e[19]!==l?(E=l("Query name"),e[19]=l,e[20]=E):E=e[20];let T;e[21]!==i||e[22]!==y||e[23]!==E?(T=(0,u.jsx)(ye,{"aria-label":y,autoFocus:!0,className:"h-7 text-xs","data-testid":"sql-query-name",onChange:w,placeholder:E,value:i}),e[21]=i,e[22]=y,e[23]=E,e[24]=T):T=e[24];let L;e[25]!==l?(L=l("Query description"),e[25]=l,e[26]=L):L=e[26];let _;e[27]===Symbol.for("react.memo_cache_sentinel")?(_=d(O=>{m(O.target.value)},"T"),e[27]=_):_=e[27];let C;e[28]!==l?(C=l("Query description"),e[28]=l,e[29]=C):C=e[29];let I;e[30]!==c||e[31]!==L||e[32]!==C?(I=(0,u.jsx)(ye,{"aria-label":L,className:"h-7 text-xs","data-testid":"sql-query-description",onChange:_,placeholder:C,value:c}),e[30]=c,e[31]=L,e[32]=C,e[33]=I):I=e[33];let R;e[34]!==l?(R=l("Save"),e[34]=l,e[35]=R):R=e[35];let M;e[36]!==R?(M=(0,u.jsx)("button",{className:"rounded-md border border-border px-2 py-0.5 text-[11px] outline-none transition-colors hover:bg-accent focus-visible:bg-accent","data-testid":"sql-query-rename-save",type:"submit",children:R}),e[36]=R,e[37]=M):M=e[37];let z;e[38]!==l?(z=l("Cancel"),e[38]=l,e[39]=z):z=e[39];let H;e[40]!==n||e[41]!==z?(H=(0,u.jsx)("button",{className:"rounded-md px-2 py-0.5 text-[11px] text-muted-foreground outline-none transition-colors hover:text-foreground focus-visible:text-foreground","data-testid":"sql-query-rename-cancel",onClick:n,type:"button",children:z}),e[40]=n,e[41]=z,e[42]=H):H=e[42];let W;e[43]!==f||e[44]!==g||e[45]!==h||e[46]!==l?(W=f&&(0,u.jsx)("button",{className:"ms-auto rounded-md border border-border px-2 py-0.5 text-[11px] outline-none transition-colors hover:bg-accent focus-visible:bg-accent","data-testid":"sql-query-suggest-name",disabled:g,onClick:h,type:"button",children:l(g?"Thinking\u2026":"Suggest")}),e[43]=f,e[44]=g,e[45]=h,e[46]=l,e[47]=W):W=e[47];let B;e[48]!==M||e[49]!==H||e[50]!==W?(B=(0,u.jsxs)("div",{className:"flex items-center gap-1",children:[M,H,W]}),e[48]=M,e[49]=H,e[50]=W,e[51]=B):B=e[51];let P;e[52]!==q||e[53]!==l?(P=q!==void 0&&(0,u.jsx)("p",{className:"text-[11px] text-muted-foreground","data-testid":"sql-query-name-reason",role:"status",children:l(q==="ai-error"?"The model could not be reached.":"The model returned nothing usable.")}),e[52]=q,e[53]=l,e[54]=P):P=e[54];let K;return e[55]!==x||e[56]!==T||e[57]!==I||e[58]!==B||e[59]!==P||e[60]!==v?(K=(0,u.jsxs)("form",{className:"flex flex-col gap-1 rounded-md bg-sidebar-accent p-1.5","data-testid":v,onSubmit:x,children:[T,I,B,P]}),e[55]=x,e[56]=T,e[57]=I,e[58]=B,e[59]=P,e[60]=v,e[61]=K):K=e[61],K},"bs"),kt=[{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;"}],vo=d(s=>{let e=(0,V.c)(44),{active:n,onDelete:t,onRename:o,onSelect:r,query:l}=s,i=J(),a;e[0]!==r||e[1]!==l.id?(a=d(()=>{r(l.id)},"c"),e[0]=r,e[1]=l.id,e[2]=a):a=e[2];let c=a,m;e[3]!==t||e[4]!==l.id?(m=d(R=>{R.stopPropagation(),t(l.id)},"d"),e[3]=t,e[4]=l.id,e[5]=m):m=e[5];let p=m,f;e[6]!==o||e[7]!==l.id?(f=d(R=>{R.stopPropagation(),o(l.id)},"f"),e[6]=o,e[7]=l.id,e[8]=f):f=e[8];let b=f,g=n?"bg-sidebar-accent font-medium text-foreground":"text-muted-foreground",k;e[9]!==g?(k=ie("flex min-w-0 flex-1 items-center gap-2 rounded-md px-2 py-1.5 text-start text-[13px] outline-none transition-colors hover:bg-sidebar-accent focus-visible:bg-sidebar-accent",g),e[9]=g,e[10]=k):k=e[10];let q=`sql-query-${l.id}`,N;e[11]===Symbol.for("react.memo_cache_sentinel")?(N=(0,u.jsx)("svg",{"aria-hidden":"true",className:"size-3.5 shrink-0 opacity-70",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,u.jsx)("path",{d:"M4 6h16M4 12h10M4 18h7"})}),e[11]=N):N=e[11];let h;e[12]!==l.name?(h=(0,u.jsx)("span",{className:"truncate",children:l.name}),e[12]=l.name,e[13]=h):h=e[13];let S;e[14]!==n||e[15]!==c||e[16]!==l.description||e[17]!==k||e[18]!==q||e[19]!==h?(S=(0,u.jsxs)("button",{"aria-pressed":n,className:k,"data-testid":q,onClick:c,title:l.description,type:"button",children:[N,h]}),e[14]=n,e[15]=c,e[16]=l.description,e[17]=k,e[18]=q,e[19]=h,e[20]=S):S=e[20];let x;e[21]!==i?(x=i("Rename query"),e[21]=i,e[22]=x):x=e[22];let v=`sql-query-rename-open-${l.id}`,y;e[23]!==i?(y=i("Rename query"),e[23]=i,e[24]=y):y=e[24];let w;e[25]===Symbol.for("react.memo_cache_sentinel")?(w=(0,u.jsx)("svg",{"aria-hidden":"true",className:"size-3.5",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,u.jsx)("path",{d:"M4 20h4L19 9l-4-4L4 16zM14 6l4 4"})}),e[25]=w):w=e[25];let E;e[26]!==b||e[27]!==x||e[28]!==v||e[29]!==y?(E=(0,u.jsx)("button",{"aria-label":x,className:"hidden size-6 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-accent hover:text-foreground group-hover/q:flex","data-testid":v,onClick:b,title:y,type:"button",children:w}),e[26]=b,e[27]=x,e[28]=v,e[29]=y,e[30]=E):E=e[30];let T;e[31]!==i?(T=i("Delete query"),e[31]=i,e[32]=T):T=e[32];let L;e[33]!==i?(L=i("Delete query"),e[33]=i,e[34]=L):L=e[34];let _;e[35]===Symbol.for("react.memo_cache_sentinel")?(_=(0,u.jsx)("svg",{"aria-hidden":"true",className:"size-3.5",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,u.jsx)("path",{d:"M5 7h14M9 7V5h6v2m-1 0v12H10V7M7 7v13h10V7"})}),e[35]=_):_=e[35];let C;e[36]!==p||e[37]!==T||e[38]!==L?(C=(0,u.jsx)("button",{"aria-label":T,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:L,type:"button",children:_}),e[36]=p,e[37]=T,e[38]=L,e[39]=C):C=e[39];let I;return e[40]!==E||e[41]!==C||e[42]!==S?(I=(0,u.jsxs)("li",{className:"group/q flex items-center",children:[S,E,C]}),e[40]=E,e[41]=C,e[42]=S,e[43]=I):I=e[43],I},"gs"),mt="sql-history-remember",yo=d((s,e)=>{let n=e.trim().toLowerCase();return n===""?[...s]:s.filter(t=>t.name.toLowerCase().includes(n))},"xs"),wo=d(s=>{let e=(0,V.c)(53),{activeId:n,history:t,listRef:o,onClearHistory:r,onDelete:l,onLoadHistory:i,onLoadTemplate:a,onNew:c,onRename:m,onSearchChange:p,onSelect:f,onToggleRememberHistory:b,queries:g,rememberHistory:k,rpc:q,search:N}=s,h=J(),S=yo(g,N),[x,v]=(0,j.useState)(null),y;e[0]===Symbol.for("react.memo_cache_sentinel")?(y=d(()=>{v(null)},"y"),e[0]=y):y=e[0];let w=y,E;e[1]!==b?(E=d(X=>{b(X.target.checked)},"w"),e[1]=b,e[2]=E):E=e[2];let T=E,L="flex h-full w-64 shrink-0 flex-col border-e border-border bg-sidebar",_;e[3]!==h?(_=h("Search queries\u2026"),e[3]=h,e[4]=_):_=e[4];let C;e[5]!==p||e[6]!==N||e[7]!==_?(C=(0,u.jsx)("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:_,type:"text",value:N}),e[5]=p,e[6]=N,e[7]=_,e[8]=C):C=e[8];let I;e[9]!==h?(I=h("New query"),e[9]=h,e[10]=I):I=e[10];let R;e[11]!==h?(R=h("New query"),e[11]=h,e[12]=R):R=e[12];let M;e[13]===Symbol.for("react.memo_cache_sentinel")?(M=(0,u.jsx)("svg",{"aria-hidden":"true",className:"size-4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.7,viewBox:"0 0 24 24",children:(0,u.jsx)("path",{d:"M12 5v14M5 12h14"})}),e[13]=M):M=e[13];let z;e[14]!==c||e[15]!==I||e[16]!==R?(z=(0,u.jsx)("button",{"aria-label":I,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:R,type:"button",children:M}),e[14]=c,e[15]=I,e[16]=R,e[17]=z):z=e[17];let H;e[18]!==C||e[19]!==z?(H=(0,u.jsxs)("div",{className:"flex shrink-0 items-center gap-2 border-b border-border p-2",children:[C,z]}),e[18]=C,e[19]=z,e[20]=H):H=e[20];let W="flex flex-1 flex-col gap-4 overflow-y-auto p-2",B;e[21]!==h?(B=h("Private"),e[21]=h,e[22]=B):B=e[22];let P;e[23]!==B?(P=(0,u.jsx)("p",{className:"px-1 pb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:B}),e[23]=B,e[24]=P):P=e[24];let K=S.length===0?(0,u.jsx)("p",{className:"px-1 py-2 text-xs text-muted-foreground","data-testid":"sql-private-empty",children:h("No saved queries yet \u2014 they save to this browser as you type.")}):(0,u.jsx)("ul",{className:"flex flex-col gap-px","data-testid":"sql-private",ref:o,children:S.map(X=>x===X.id?(0,u.jsx)("li",{children:(0,u.jsx)(xo,{onCancel:w,onSave:d((se,ae)=>{m(X.id,se,ae),w()},"onSave"),query:X,rpc:q})},X.id):(0,u.jsx)(vo,{active:n===X.id,onDelete:l,onRename:v,onSelect:f,query:X},X.id))}),O;e[25]!==P||e[26]!==K?(O=(0,u.jsxs)("div",{children:[P,K]}),e[25]=P,e[26]=K,e[27]=O):O=e[27];let D;e[28]!==h?(D=h("Reference"),e[28]=h,e[29]=D):D=e[29];let A;e[30]!==D?(A=(0,u.jsx)("p",{className:"px-1 pb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:D}),e[30]=D,e[31]=A):A=e[31];let Q;e[32]!==a?(Q=kt.map(X=>(0,u.jsx)("li",{children:(0,u.jsxs)("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":X.sql,onClick:a,type:"button",children:[(0,u.jsx)("svg",{"aria-hidden":"true",className:"size-3.5 shrink-0 opacity-70",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,u.jsx)("path",{d:"M7 4h7l4 4v12H7zM14 4v4h4"})}),X.label]})},X.label)),e[32]=a,e[33]=Q):Q=e[33];let F;e[34]!==Q?(F=(0,u.jsx)("ul",{className:"flex flex-col gap-px",children:Q}),e[34]=Q,e[35]=F):F=e[35];let ee;e[36]!==A||e[37]!==F?(ee=(0,u.jsxs)("div",{children:[A,F]}),e[36]=A,e[37]=F,e[38]=ee):ee=e[38];let $;e[39]!==t||e[40]!==r||e[41]!==i||e[42]!==T||e[43]!==k||e[44]!==h?($=t.length>0&&(0,u.jsxs)("div",{children:[(0,u.jsxs)("div",{className:"flex items-center justify-between px-1 pb-1",children:[(0,u.jsx)("p",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:h("History")}),(0,u.jsx)("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:r,type:"button",children:h("Clear history")})]}),(0,u.jsxs)("label",{className:"flex cursor-pointer items-center gap-1.5 px-1 pb-1.5 text-[11px] text-muted-foreground",htmlFor:mt,children:[(0,u.jsx)("input",{checked:k,"data-testid":"sql-history-remember",id:mt,onChange:T,type:"checkbox"}),h("Keep history on this browser")]}),(0,u.jsx)("ul",{className:"flex flex-col gap-px","data-testid":"sql-history",children:t.map(X=>(0,u.jsx)("li",{children:(0,u.jsxs)("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":X.sql,"data-testid":"sql-history-item",onClick:i,title:X.sql,type:"button",children:[(0,u.jsx)("svg",{"aria-hidden":"true",className:"size-3.5 shrink-0 opacity-70",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,u.jsx)("path",{d:"M12 8v4l3 2M12 21a9 9 0 1 1 0-18 9 9 0 0 1 0 18Z"})}),(0,u.jsx)("span",{className:"truncate font-mono",children:X.sql})]})},`${X.at.toString()}:${X.sql}`))})]}),e[39]=t,e[40]=r,e[41]=i,e[42]=T,e[43]=k,e[44]=h,e[45]=$):$=e[45];let G;e[46]!==O||e[47]!==ee||e[48]!==$?(G=(0,u.jsxs)("div",{className:W,children:[O,ee,$]}),e[46]=O,e[47]=ee,e[48]=$,e[49]=G):G=e[49];let Z;return e[50]!==H||e[51]!==G?(Z=(0,u.jsxs)("aside",{className:L,children:[H,G]}),e[50]=H,e[51]=G,e[52]=Z):Z=e[52],Z},"vs"),Te=d(s=>`border-b-2 px-3 py-2 text-sm outline-none transition-colors ${s?"border-foreground font-medium text-foreground":"border-transparent text-muted-foreground hover:text-foreground"}`,"ke"),So=d(s=>{let e=(0,V.c)(16),{chatOpen:n,onToggle:t}=s,o=J(),r;e[0]!==o?(r=o("Ask about your data"),e[0]=o,e[1]=r):r=e[1];let l=`inline-flex items-center gap-1.5 rounded-md border border-border px-2 py-1.5 outline-none transition-colors hover:bg-accent focus-visible:bg-accent ${n?"bg-accent text-foreground":"text-muted-foreground"}`,i;e[2]!==o?(i=o("Ask about your data"),e[2]=o,e[3]=i):i=e[3];let a;e[4]===Symbol.for("react.memo_cache_sentinel")?(a=(0,u.jsx)("svg",{"aria-hidden":"true",className:"size-4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,u.jsx)("path",{d:"M21 12a8 8 0 0 1-8 8H7l-4 3 1.2-4.2A8 8 0 1 1 21 12Z"})}),e[4]=a):a=e[4];let c;e[5]!==o?(c=o("Assistant"),e[5]=o,e[6]=c):c=e[6];let m;e[7]!==c?(m=(0,u.jsx)("span",{className:"text-xs",children:c}),e[7]=c,e[8]=m):m=e[8];let p;return e[9]!==n||e[10]!==t||e[11]!==r||e[12]!==l||e[13]!==i||e[14]!==m?(p=(0,u.jsxs)("button",{"aria-label":r,"aria-pressed":n,className:l,"data-testid":"sql-chat-toggle",onClick:t,title:i,type:"button",children:[a,m]}),e[9]=n,e[10]=t,e[11]=r,e[12]=l,e[13]=i,e[14]=m,e[15]=p):p=e[15],p},"ys"),qo=d(s=>{let e=(0,V.c)(11),{onToggle:n,splitView:t}=s,o=J(),r;e[0]!==o?(r=o("Split editor and results"),e[0]=o,e[1]=r):r=e[1];let l=`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 ${t?"bg-accent text-foreground":"text-muted-foreground"}`,i;e[2]!==o?(i=o("Split editor and results"),e[2]=o,e[3]=i):i=e[3];let a;e[4]===Symbol.for("react.memo_cache_sentinel")?(a=(0,u.jsxs)("svg",{"aria-hidden":"true",className:"size-4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.7,viewBox:"0 0 24 24",children:[(0,u.jsx)("rect",{height:"16",rx:"2",width:"18",x:"3",y:"4"}),(0,u.jsx)("path",{d:"M12 4v16"})]}),e[4]=a):a=e[4];let c;return e[5]!==n||e[6]!==t||e[7]!==r||e[8]!==l||e[9]!==i?(c=(0,u.jsx)("button",{"aria-label":r,"aria-pressed":t,className:l,"data-testid":"sql-split-toggle",onClick:n,title:i,type:"button",children:a}),e[5]=n,e[6]=t,e[7]=r,e[8]=l,e[9]=i,e[10]=c):c=e[10],c},"Ss"),ko=d(s=>{let e=(0,V.c)(8),{disabled:n,onExplainPlan:t,onExplainSql:o,pane:r}=s,l=J();if(r==="explain"){let a;return e[0]!==n||e[1]!==t||e[2]!==l?(a=t===void 0?null:(0,u.jsx)("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-explain-plan",disabled:n,onClick:t,type:"button",children:l("Read this plan")}),e[0]=n,e[1]=t,e[2]=l,e[3]=a):a=e[3],a}let i;return e[4]!==n||e[5]!==o||e[6]!==l?(i=o===void 0?null:(0,u.jsx)("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-explain-query",disabled:n,onClick:o,type:"button",children:l("Explain this query")}),e[4]=n,e[5]=o,e[6]=l,e[7]=i):i=e[7],i},"ws"),Co=d(s=>{let e=(0,V.c)(8),{onRun:n,running:t}=s,o=J(),r;e[0]!==t||e[1]!==o?(r=o(t?"Running\u2026":"Run"),e[0]=t,e[1]=o,e[2]=r):r=e[2];let l;e[3]===Symbol.for("react.memo_cache_sentinel")?(l=(0,u.jsx)("kbd",{className:"rounded border border-primary-foreground/30 px-1 font-sans text-[10px]",children:"\u2318\u21B5"}),e[3]=l):l=e[3];let i;return e[4]!==n||e[5]!==t||e[6]!==r?(i=(0,u.jsxs)("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:t,onClick:n,type:"button",children:[r,l]}),e[4]=n,e[5]=t,e[6]=r,e[7]=i):i=e[7],i},"Cs"),No=d(s=>{let e=(0,V.c)(35),{onInferChart:n,onShowChart:t,onShowExplain:o,onShowResults:r,pane:l,result:i,rpc:a}=s,c=J(),m=l==="results",p;e[0]!==m?(p=Te(m),e[0]=m,e[1]=p):p=e[1];let f;e[2]!==c?(f=c("Results"),e[2]=c,e[3]=f):f=e[3];let b;e[4]!==r||e[5]!==p||e[6]!==f?(b=(0,u.jsx)("button",{className:p,"data-testid":"sql-tab-results",onClick:r,type:"button",children:f}),e[4]=r,e[5]=p,e[6]=f,e[7]=b):b=e[7];let g=l==="chart",k;e[8]!==g?(k=Te(g),e[8]=g,e[9]=k):k=e[9];let q;e[10]!==c?(q=c("Chart"),e[10]=c,e[11]=q):q=e[11];let N;e[12]!==t||e[13]!==k||e[14]!==q?(N=(0,u.jsx)("button",{className:k,"data-testid":"sql-tab-chart",onClick:t,type:"button",children:q}),e[12]=t,e[13]=k,e[14]=q,e[15]=N):N=e[15];let h;e[16]!==n||e[17]!==l||e[18]!==i||e[19]!==a||e[20]!==c?(h=!a.unavailable&&l==="chart"&&i!==null&&(0,u.jsx)("button",{className:Te(!1),"data-testid":"sql-infer-chart",disabled:a.pending("chart"),onClick:n,type:"button",children:a.pending("chart")?c("Thinking\u2026"):c("Suggest chart")}),e[16]=n,e[17]=l,e[18]=i,e[19]=a,e[20]=c,e[21]=h):h=e[21];let S=l==="explain",x;e[22]!==S?(x=Te(S),e[22]=S,e[23]=x):x=e[23];let v;e[24]!==c?(v=c("Explain"),e[24]=c,e[25]=v):v=e[25];let y;e[26]!==o||e[27]!==x||e[28]!==v?(y=(0,u.jsx)("button",{className:x,"data-testid":"sql-tab-explain",onClick:o,type:"button",children:v}),e[26]=o,e[27]=x,e[28]=v,e[29]=y):y=e[29];let w;return e[30]!==y||e[31]!==b||e[32]!==N||e[33]!==h?(w=(0,u.jsxs)(u.Fragment,{children:[b,N,h,y]}),e[30]=y,e[31]=b,e[32]=N,e[33]=h,e[34]=w):w=e[34],w},"Es"),Eo=d(s=>{let e=(0,V.c)(9),{onSelectStatement:n,script:t}=s,o;if(e[0]!==n||e[1]!==t.runs||e[2]!==t.selected){let l;e[4]!==n||e[5]!==t.selected?(l=d((i,a)=>(0,u.jsx)("button",{"aria-pressed":a===t.selected,className:`rounded-md border px-2 py-0.5 font-mono text-[11px] outline-none transition-colors ${a===t.selected?"border-foreground text-foreground":"border-border text-muted-foreground hover:text-foreground"} ${i.error===null?"":"border-destructive/50 text-destructive"}`,"data-testid":`sql-statement-${a.toString()}`,onClick:d(()=>{n(a)},"onClick"),title:i.sql,type:"button",children:a+1},`${a.toString()}:${i.sql}`),"r"),e[4]=n,e[5]=t.selected,e[6]=l):l=e[6],o=t.runs.map(l),e[0]=n,e[1]=t.runs,e[2]=t.selected,e[3]=o}else o=e[3];let r;return e[7]!==o?(r=(0,u.jsx)("div",{className:"flex shrink-0 flex-wrap items-center gap-1 border-b border-border px-3 py-1.5","data-testid":"sql-statements",children:o}),e[7]=o,e[8]=r):r=e[8],r},"Ns"),Lo=d(s=>{let e=(0,V.c)(9),{error:n,onDebugError:t,rpc:o}=s,r=J(),l;e[0]!==n?(l=(0,u.jsx)(Je,{className:"w-full font-mono text-xs",testId:"sql-error",variant:"destructive",children:n}),e[0]=n,e[1]=l):l=e[1];let i;e[2]!==t||e[3]!==o||e[4]!==r?(i=!o.unavailable&&t!==void 0&&(0,u.jsxs)("button",{className:"inline-flex items-center gap-1.5 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-debug-error",disabled:o.pending("chat"),onClick:t,type:"button",children:[(0,u.jsx)("svg",{"aria-hidden":"true",className:"size-3.5",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:(0,u.jsx)("path",{d:"M21 12a8 8 0 0 1-8 8H7l-4 3 1.2-4.2A8 8 0 1 1 21 12Z"})}),o.pending("chat")?r("Thinking\u2026"):r("Debug with AI")]}),e[2]=t,e[3]=o,e[4]=r,e[5]=i):i=e[5];let a;return e[6]!==l||e[7]!==i?(a=(0,u.jsxs)("div",{className:"m-3 flex flex-col items-start gap-2",children:[l,i]}),e[6]=l,e[7]=i,e[8]=a):a=e[8],a},"ks"),_o=d(s=>{let e=(0,V.c)(18),{chart:n,durationMs:t,pane:o,result:r}=s,l=J(),i;e[0]!==n||e[1]!==o||e[2]!==r?(i=o==="chart"?(0,u.jsx)(nt,{axes:n,result:r}):(0,u.jsx)(ot,{result:r}),e[0]=n,e[1]=o,e[2]=r,e[3]=i):i=e[3];let a;e[4]!==r.rowCount||e[5]!==r.rows||e[6]!==r.truncated||e[7]!==l?(a=r.truncated?l("Showing the first {max} rows.",{max:r.rows.length}):l("{count} rows",{count:r.rowCount}),e[4]=r.rowCount,e[5]=r.rows,e[6]=r.truncated,e[7]=l,e[8]=a):a=e[8];let c;e[9]!==t||e[10]!==l?(c=t!==void 0&&` \xB7 ${l("{ms} ms",{ms:Math.round(t)})}`,e[9]=t,e[10]=l,e[11]=c):c=e[11];let m;e[12]!==a||e[13]!==c?(m=(0,u.jsxs)("p",{className:"border-t border-border px-3 py-1.5 text-xs text-muted-foreground","data-testid":"sql-count",children:[a,c]}),e[12]=a,e[13]=c,e[14]=m):m=e[14];let p;return e[15]!==i||e[16]!==m?(p=(0,u.jsxs)("div",{"data-testid":"sql-result",children:[i,m]}),e[15]=i,e[16]=m,e[17]=p):p=e[17],p},"Ts"),To=d(s=>{let e=(0,V.c)(13),{chart:n,durationMs:t,error:o,onDebugError:r,pane:l,result:i,rpc:a}=s,c=J();if(o!==null){let p;return e[0]!==o||e[1]!==r||e[2]!==a?(p=(0,u.jsx)(Lo,{error:o,onDebugError:r,rpc:a}),e[0]=o,e[1]=r,e[2]=a,e[3]=p):p=e[3],p}if(i===null){let p;e[4]!==c?(p=c("Click Run to execute your query."),e[4]=c,e[5]=p):p=e[5];let f;return e[6]!==p?(f=(0,u.jsx)("p",{className:"p-4 text-sm text-muted-foreground","data-testid":"sql-empty",children:p}),e[6]=p,e[7]=f):f=e[7],f}let m;return e[8]!==n||e[9]!==t||e[10]!==l||e[11]!==i?(m=(0,u.jsx)(_o,{chart:n,durationMs:t,pane:l,result:i}),e[8]=n,e[9]=t,e[10]=l,e[11]=i,e[12]=m):m=e[12],m},"Rs"),Io=d(s=>{let e=(0,V.c)(63),{rpc:n,chart:t,className:o,durationMs:r,error:l,onFormat:i,onInferChart:a,onRun:c,onSelectStatement:m,onShardKeyChange:p,onShowChart:f,onShowExplain:b,onShowResults:g,chatOpen:k,onDebugError:q,onExplainPlan:N,onExplainSql:h,onToggleChat:S,onToggleSplit:x,pane:v,result:y,running:w,script:E,shardKey:T,splitView:L}=s,_=J(),C;e[0]!==a||e[1]!==f||e[2]!==b||e[3]!==g||e[4]!==v||e[5]!==y||e[6]!==n?(C=(0,u.jsx)(No,{onInferChart:a,onShowChart:f,onShowExplain:b,onShowResults:g,pane:v,result:y,rpc:n}),e[0]=a,e[1]=f,e[2]=b,e[3]=g,e[4]=v,e[5]=y,e[6]=n,e[7]=C):C=e[7];let I;e[8]!==k||e[9]!==S?(I=S!==void 0&&(0,u.jsx)(So,{chatOpen:k,onToggle:S}),e[8]=k,e[9]=S,e[10]=I):I=e[10];let R;e[11]!==x||e[12]!==L?(R=(0,u.jsx)(qo,{onToggle:x,splitView:L}),e[11]=x,e[12]=L,e[13]=R):R=e[13];let M;e[14]!==y?(M=y!==null&&y.columns.length>0&&(0,u.jsx)(tt,{columns:y.columns,name:"query-result",rows:y.rows}),e[14]=y,e[15]=M):M=e[15];let z;e[16]!==_?(z=_("Format"),e[16]=_,e[17]=z):z=e[17];let H;e[18]!==i||e[19]!==w||e[20]!==z?(H=(0,u.jsx)("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:w,onClick:i,type:"button",children:z}),e[18]=i,e[19]=w,e[20]=z,e[21]=H):H=e[21];let W;e[22]!==n||e[23]!==w?(W=w||n.pending("chat"),e[22]=n,e[23]=w,e[24]=W):W=e[24];let B;e[25]!==N||e[26]!==h||e[27]!==v||e[28]!==W?(B=(0,u.jsx)(ko,{disabled:W,onExplainPlan:N,onExplainSql:h,pane:v}),e[25]=N,e[26]=h,e[27]=v,e[28]=W,e[29]=B):B=e[29];let P;e[30]!==p||e[31]!==T?(P=(0,u.jsx)(Ye,{onChange:p,testId:"sql-shard-input",value:T}),e[30]=p,e[31]=T,e[32]=P):P=e[32];let K;e[33]!==c||e[34]!==w?(K=(0,u.jsx)(Co,{onRun:c,running:w}),e[33]=c,e[34]=w,e[35]=K):K=e[35];let O;e[36]!==K||e[37]!==I||e[38]!==R||e[39]!==M||e[40]!==H||e[41]!==B||e[42]!==P?(O=(0,u.jsxs)("div",{className:"ms-auto flex items-center gap-2",children:[I,R,M,H,B,P,K]}),e[36]=K,e[37]=I,e[38]=R,e[39]=M,e[40]=H,e[41]=B,e[42]=P,e[43]=O):O=e[43];let D;e[44]!==C||e[45]!==O?(D=(0,u.jsxs)("div",{className:"flex shrink-0 items-center gap-2 border-b border-border pe-2",children:[C,O]}),e[44]=C,e[45]=O,e[46]=D):D=e[46];let A;e[47]!==m||e[48]!==E?(A=E!==void 0&&(0,u.jsx)(Eo,{onSelectStatement:m,script:E}),e[47]=m,e[48]=E,e[49]=A):A=e[49];let Q;e[50]!==t||e[51]!==r||e[52]!==l||e[53]!==q||e[54]!==v||e[55]!==y||e[56]!==n?(Q=(0,u.jsx)("div",{className:"min-h-0 flex-1 overflow-auto",children:(0,u.jsx)(To,{chart:t,durationMs:r,error:l,onDebugError:q,pane:v,result:y,rpc:n})}),e[50]=t,e[51]=r,e[52]=l,e[53]=q,e[54]=v,e[55]=y,e[56]=n,e[57]=Q):Q=e[57];let F;return e[58]!==o||e[59]!==D||e[60]!==A||e[61]!==Q?(F=(0,u.jsxs)("div",{className:o,children:[D,A,Q]}),e[58]=o,e[59]=D,e[60]=A,e[61]=Q,e[62]=F):F=e[62],F},"Ls"),Ro=d((s,e)=>s.trim()===""?e:(s.split(`
|
|
16
|
+
`)[0]??s).slice(0,24),"_s"),Do=d(s=>{s?.focus(),s?.select()},"qs"),Mo=d(s=>{let e=(0,V.c)(14),{initial:n,onCancel:t,onCommit:o,placeholder:r,testId:l}=s,i=J(),a;e[0]!==o?(a=d(g=>{o(g.currentTarget.value.trim())},"c"),e[0]=o,e[1]=a):a=e[1];let c=a,m;e[2]!==t||e[3]!==o?(m=d(g=>{g.key==="Enter"?o(g.currentTarget.value.trim()):g.key==="Escape"&&t()},"d"),e[2]=t,e[3]=o,e[4]=m):m=e[4];let p=m,f;e[5]!==i?(f=i("Tab title"),e[5]=i,e[6]=f):f=e[6];let b;return e[7]!==n||e[8]!==c||e[9]!==p||e[10]!==r||e[11]!==f||e[12]!==l?(b=(0,u.jsx)("input",{"aria-label":f,className:"w-40 rounded border border-ring bg-background px-1 py-0.5 text-xs outline-none","data-testid":l,defaultValue:n,onBlur:c,onKeyDown:p,placeholder:r,ref:Do,type:"text"}),e[7]=n,e[8]=c,e[9]=p,e[10]=r,e[11]=f,e[12]=l,e[13]=b):b=e[13],b},"Is"),Ao=d(s=>{let e=(0,V.c)(29),{idBase:n,onDiscard:t,onKeep:o}=s,r=J(),l=`sql-tab-close-prompt-${n}`,i;e[0]!==r?(i=r("Discard?"),e[0]=r,e[1]=i):i=e[1];let a;e[2]!==i?(a=(0,u.jsx)("span",{className:"text-[11px] text-muted-foreground",children:i}),e[2]=i,e[3]=a):a=e[3];let c;e[4]!==r?(c=r("Discard changes"),e[4]=r,e[5]=c):c=e[5];let m=`sql-tab-close-confirm-${n}`,p;e[6]!==r?(p=r("Discard changes"),e[6]=r,e[7]=p):p=e[7];let f;e[8]===Symbol.for("react.memo_cache_sentinel")?(f=(0,u.jsx)("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2.4,viewBox:"0 0 24 24",children:(0,u.jsx)("path",{d:"M5 13l4 4L19 7"})}),e[8]=f):f=e[8];let b;e[9]!==t||e[10]!==c||e[11]!==m||e[12]!==p?(b=(0,u.jsx)("button",{"aria-label":c,className:"flex size-5 items-center justify-center rounded text-destructive hover:bg-destructive/10","data-testid":m,onClick:t,title:p,type:"button",children:f}),e[9]=t,e[10]=c,e[11]=m,e[12]=p,e[13]=b):b=e[13];let g;e[14]!==r?(g=r("Keep editing"),e[14]=r,e[15]=g):g=e[15];let k=`sql-tab-close-cancel-${n}`,q;e[16]!==r?(q=r("Keep editing"),e[16]=r,e[17]=q):q=e[17];let N;e[18]===Symbol.for("react.memo_cache_sentinel")?(N=(0,u.jsx)("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2.4,viewBox:"0 0 24 24",children:(0,u.jsx)("path",{d:"M6 6l12 12M18 6 6 18"})}),e[18]=N):N=e[18];let h;e[19]!==o||e[20]!==k||e[21]!==q||e[22]!==g?(h=(0,u.jsx)("button",{"aria-label":g,className:"flex size-5 items-center justify-center rounded text-muted-foreground hover:bg-accent","data-testid":k,onClick:o,title:q,type:"button",children:N}),e[19]=o,e[20]=k,e[21]=q,e[22]=g,e[23]=h):h=e[23];let S;return e[24]!==l||e[25]!==h||e[26]!==a||e[27]!==b?(S=(0,u.jsxs)("span",{className:"flex shrink-0 items-center gap-1","data-testid":l,role:"group",children:[a,b,h]}),e[24]=l,e[25]=h,e[26]=a,e[27]=b,e[28]=S):S=e[28],S},"As"),$o=d(s=>{let e=(0,V.c)(47),{active:n,canClose:t,onClose:o,onMenu:r,onRename:l,onSelect:i,tab:a}=s,c=J(),[m,p]=(0,j.useState)(!1),[f,b]=(0,j.useState)(!1),g;e[0]!==r||e[1]!==a.id?(g=d(A=>{r(a.id,A)},"g"),e[0]=r,e[1]=a.id,e[2]=g):g=e[2];let k=g,q;e[3]!==i||e[4]!==a.id?(q=d(()=>{i(a.id)},"v"),e[3]=i,e[4]=a.id,e[5]=q):q=e[5];let N=q,h;e[6]===Symbol.for("react.memo_cache_sentinel")?(h=d(()=>{p(!0)},"p"),e[6]=h):h=e[6];let S=h,x;e[7]!==o||e[8]!==a?(x=d(A=>{A.stopPropagation(),qt(a)?b(!0):o(a.id)},"x"),e[7]=o,e[8]=a,e[9]=x):x=e[9];let v=x,y;e[10]!==o||e[11]!==a.id?(y=d(A=>{A.stopPropagation(),b(!1),o(a.id)},"y"),e[10]=o,e[11]=a.id,e[12]=y):y=e[12];let w=y,E;e[13]===Symbol.for("react.memo_cache_sentinel")?(E=d(A=>{A.stopPropagation(),b(!1)},"w"),e[13]=E):E=e[13];let T=E,L;e[14]!==l||e[15]!==a.id?(L=d(A=>{l(a.id,A),p(!1)},"R"),e[14]=l,e[15]=a.id,e[16]=L):L=e[16];let _=L,C;e[17]===Symbol.for("react.memo_cache_sentinel")?(C=d(()=>{p(!1)},"k"),e[17]=C):C=e[17];let I=C,R;e[18]!==a.name?(R=a.name.trim(),e[18]=a.name,e[19]=R):R=e[19];let M=R,z;e[20]!==c||e[21]!==a.sql?(z=Ro(a.sql,c("Untitled")),e[20]=c,e[21]=a.sql,e[22]=z):z=e[22];let H=z,W=n?"bg-background text-foreground":"bg-muted/40 text-muted-foreground hover:text-foreground",B;e[23]!==W?(B=ie("group/tab flex shrink-0 items-center gap-1 border-e border-border ps-3 pe-1.5 text-xs",W),e[23]=W,e[24]=B):B=e[24];let P=`sql-tab-${a.id}`,K;e[25]!==n||e[26]!==_||e[27]!==M||e[28]!==H||e[29]!==m||e[30]!==N||e[31]!==c||e[32]!==a.id?(K=m?(0,u.jsx)(Mo,{initial:M,onCancel:I,onCommit:_,placeholder:H,testId:`sql-tab-rename-${a.id}`}):(0,u.jsx)("button",{"aria-pressed":n,className:"max-w-40 truncate py-1.5 outline-none","data-testid":`sql-tab-select-${a.id}`,onClick:N,onDoubleClick:S,title:c("Double-click to rename"),type:"button",children:M===""?H:M}),e[25]=n,e[26]=_,e[27]=M,e[28]=H,e[29]=m,e[30]=N,e[31]=c,e[32]=a.id,e[33]=K):K=e[33];let O;e[34]!==t||e[35]!==w||e[36]!==f||e[37]!==v||e[38]!==c||e[39]!==a.id?(O=t&&(f?(0,u.jsx)(Ao,{idBase:a.id,onDiscard:w,onKeep:T}):(0,u.jsx)("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-${a.id}`,onClick:v,title:c("Close tab"),type:"button",children:(0,u.jsx)("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,viewBox:"0 0 24 24",children:(0,u.jsx)("path",{d:"M6 6l12 12M18 6 6 18"})})})),e[34]=t,e[35]=w,e[36]=f,e[37]=v,e[38]=c,e[39]=a.id,e[40]=O):O=e[40];let D;return e[41]!==k||e[42]!==B||e[43]!==P||e[44]!==K||e[45]!==O?(D=(0,u.jsxs)("div",{className:B,"data-testid":P,onContextMenu:k,children:[K,O]}),e[41]=k,e[42]=B,e[43]=P,e[44]=K,e[45]=O,e[46]=D):D=e[46],D},"Ds"),Po=d(s=>{let e=(0,V.c)(43),{model:n,onSelect:t}=s,o=J(),{activeTab:r,addEditorTab:l,cancelBulk:i,closeEditorTab:a,closeTabMenu:c,confirmBulk:m,menuStyle:p,onBackdropContextMenu:f,onCloseAll:b,onCloseOthers:g,onCloseToRight:k,openTabMenu:q,pendingBulk:N,renameTab:h,tabMenu:S,tabs:x}=n,v;if(e[0]!==r||e[1]!==a||e[2]!==t||e[3]!==q||e[4]!==h||e[5]!==x){let R;e[7]!==r||e[8]!==a||e[9]!==t||e[10]!==q||e[11]!==h||e[12]!==x.length?(R=d(M=>(0,u.jsx)($o,{active:M.id===r.id,canClose:x.length>1,onClose:a,onMenu:q,onRename:h,onSelect:t,tab:M},M.id),"q"),e[7]=r,e[8]=a,e[9]=t,e[10]=q,e[11]=h,e[12]=x.length,e[13]=R):R=e[13],v=x.map(R),e[0]=r,e[1]=a,e[2]=t,e[3]=q,e[4]=h,e[5]=x,e[6]=v}else v=e[6];let y;e[14]!==o?(y=o("New tab"),e[14]=o,e[15]=y):y=e[15];let w=x.length>=Be,E;e[16]!==o?(E=o("New tab"),e[16]=o,e[17]=E):E=e[17];let T;e[18]===Symbol.for("react.memo_cache_sentinel")?(T=(0,u.jsx)("svg",{"aria-hidden":"true",className:"size-4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.7,viewBox:"0 0 24 24",children:(0,u.jsx)("path",{d:"M12 5v14M5 12h14"})}),e[18]=T):T=e[18];let L;e[19]!==l||e[20]!==y||e[21]!==w||e[22]!==E?(L=(0,u.jsx)("button",{"aria-label":y,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:w,onClick:l,title:E,type:"button",children:T}),e[19]=l,e[20]=y,e[21]=w,e[22]=E,e[23]=L):L=e[23];let _;e[24]!==v||e[25]!==L?(_=(0,u.jsxs)("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:[v,L]}),e[24]=v,e[25]=L,e[26]=_):_=e[26];let C;e[27]!==i||e[28]!==c||e[29]!==m||e[30]!==p||e[31]!==f||e[32]!==b||e[33]!==g||e[34]!==k||e[35]!==N||e[36]!==o||e[37]!==S||e[38]!==x?(C=S!==null&&(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)("div",{className:"fixed inset-0 z-40","data-testid":"sql-tab-menu-backdrop",onClick:c,onContextMenu:f,role:"presentation"}),(0,u.jsx)("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:p,children:N===null?(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)("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:x.length<=1,onClick:g,role:"menuitem",type:"button",children:o("Close other tabs")}),(0,u.jsx)("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:x.findIndex(R=>R.id===S.id)>=x.length-1,onClick:k,role:"menuitem",type:"button",children:o("Close tabs to the right")}),(0,u.jsx)("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:b,role:"menuitem",type:"button",children:o("Close all tabs")})]}):(0,u.jsxs)("div",{className:"px-3 py-1.5","data-testid":"sql-tab-menu-confirm",children:[(0,u.jsx)("p",{className:"pb-1.5 text-xs text-muted-foreground",children:o("Discard unsaved tabs?")}),(0,u.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,u.jsx)("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:m,type:"button",children:o("Discard")}),(0,u.jsx)("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:i,type:"button",children:o("Cancel")})]})]})})]}),e[27]=i,e[28]=c,e[29]=m,e[30]=p,e[31]=f,e[32]=b,e[33]=g,e[34]=k,e[35]=N,e[36]=o,e[37]=S,e[38]=x,e[39]=C):C=e[39];let I;return e[40]!==_||e[41]!==C?(I=(0,u.jsxs)(u.Fragment,{children:[_,C]}),e[40]=_,e[41]=C,e[42]=I):I=e[42],I},"Os"),Oo=ge(ve.runSql),zo="lunora-studio-sql-split-view",Ho=d(()=>qe(kt[0]?.sql??""),"Bs"),jo=d(()=>performance.now(),"Ps"),Wo=d(()=>{let s=(0,V.c)(2),e;s[0]===Symbol.for("react.memo_cache_sentinel")?(e=new Map,s[0]=e):e=s[0];let n=(0,j.useRef)(e),t;return s[1]===Symbol.for("react.memo_cache_sentinel")?(t={advance:d(o=>{n.current.set(o,(n.current.get(o)??0)+1)},"advance"),begin:d(o=>{let r=n.current.get(o)??0;return()=>(n.current.get(o)??0)===r},"begin")},s[1]=t):t=s[1],t},"Ws"),Bo=d((s,e)=>{let n=s.tables[0];return n===void 0?[e("What tables does this app have?")]:[e("What tables does this app have?"),e("Show me the most recent rows in {table}",{table:n}),e("Is anything wrong with my schema?")]},"Hs"),Ie=d(s=>s.tables.map(e=>({columns:[...s.columns[e]??[]],table:e})),"Te"),pr=d(({initialShardKey:s,now:e=jo})=>{let n=Ce(),t=Vn(Ho),{activeTab:o,openEditorTab:r,output:l,patchActiveOutput:i,patchActiveTab:a,setActiveTabId:c,unlinkQuery:m}=t,p=Wo(),f=no({loadIntoActiveTab:d((U,oe)=>{p.advance(o.id),a({activeId:oe,sql:U}),i({chart:void 0,durationMs:void 0,error:null,failed:void 0,result:null,running:!1,script:void 0})},"loadIntoActiveTab"),unlinkQuery:m}),{recordHistory:b,updateQuerySql:g}=f,k=o.sql,{activeId:q}=o,{chart:N,error:h,failed:S,result:x,running:v}=l,y=l.pane,[w,E]=(0,j.useState)(s??""),[T,L]=Ee(zo,!1),_=J(),C=Ge(),{probe:I,schema:R}=An(w),M=(0,j.useCallback)(U=>{a({sql:U}),q!==null&&g(q,U)},[q,a,g]),z=C?.setHasEditor;(0,j.useEffect)(()=>{if(z!==void 0)return z(!0),()=>{z(!1)}},[z]);let H=C?.insertRequest,W=C?.takeInsert;(0,j.useEffect)(()=>{H===void 0||W===void 0||(W(H.id),k.trim()===""&&q===null?M(H.sql):r(H.sql)||a({activeId:null,sql:k.trim()===""?H.sql:`${k.trimEnd()}
|
|
16
17
|
|
|
17
|
-
${
|
|
18
|
+
${H.sql}`}))},[q,k,H,r,a,W,M]);let B=vn(k,R,w),P=Ze(w),K=d(()=>{x!==null&&le((async()=>{let U=await P.inferChart({columns:x.columns,rowCount:x.rowCount,types:Object.fromEntries(x.columns.map(oe=>[oe,typeof(x.rows[0]?.[oe]??"")]))});i({chart:U})})())},"M"),O=d(async U=>{let oe=e();try{let re=await n.query(Oo,{sql:U},xe(w)),ce=e()-oe;return b(U),{durationMs:ce,error:null,result:re,sql:U}}catch(re){return{error:Ke(re),result:null,sql:U}}},"I"),D=d(async U=>{if(k.trim()==="")return;let oe=p.begin(o.id);i({running:!0,...U==="explain"?{explained:k.trim()}:{}});let re=U==="explain"?He(Qt(k),0):xt(k),ce=[];for(let ke of re){let Ct={error:ke.rejection?.message??"",result:null,sql:ke.sql};ce.push(ke.rejection===void 0?await O(ke.sql):Ct)}if(Ve(w),!oe())return;let Qe=Math.max(ce.length-1,0),de=ce[Qe];i({chart:void 0,durationMs:de?.durationMs,error:de?.error??null,failed:de?.error===null||de===void 0?void 0:{error:de.error,sql:de.sql},pane:U,result:de?.result??null,running:!1,script:ce.length>1?{runs:ce,selected:Qe}:void 0})},"D"),A=d(U=>{let oe=l.script?.runs,re=oe?.[U];oe===void 0||re===void 0||i({chart:void 0,durationMs:re.durationMs,error:re.error,failed:re.error===null?void 0:{error:re.error,sql:re.sql},result:re.result,script:{runs:oe,selected:U}})},"z"),Q=d(()=>{le(D("results"))},"j"),F=zn({inlineEditEnabled:!P.unavailable,onSubmit:d(()=>{le(D(l.pane))},"onSubmit"),probe:I,schema:R,setDraft:M}),{closeAutocomplete:ee,closeInlineEdit:$}=F,G=d(()=>{M(Yt(k))},"X"),Z=d(U=>{ee(),$(),c(U)},"Y"),X=d(()=>{i({pane:"results"})},"oe"),se=d(()=>{le(D("explain"))},"re"),ae=d(()=>{i({pane:"chart"})},"pe"),ue=d(()=>{L(!T)},"ve"),pe=d(()=>{if(C!==void 0){if(C.open){C.close();return}C.openAssistant({schema:Ie(R),shardKey:w,suggestions:Bo(R,_),title:_("SQL console")})}},"he"),me=d(U=>{C?.rebindShard(w,U),E(U)},"ye"),be=d(()=>{S!==void 0&&C?.openAssistant({ask:_(`This statement failed:
|
|
18
19
|
{sql}
|
|
19
20
|
|
|
20
21
|
The database said: {error}
|
|
21
22
|
|
|
22
|
-
Why, and what should it be?`,{error:S.error,sql:S.sql}),schema:
|
|
23
|
-
{statement}`,{statement:U}),schema:
|
|
24
|
-
`);C?.openAssistant({ask:
|
|
23
|
+
Why, and what should it be?`,{error:S.error,sql:S.sql}),schema:Ie(R),shardKey:w,title:_("Debug query")})},"be"),fe=d(()=>{let U=k.trim();U!==""&&C?.openAssistant({ask:_(`Explain what this query does, step by step:
|
|
24
|
+
{statement}`,{statement:U}),schema:Ie(R),shardKey:w,title:_("Explain query")})},"V"),Y=d(()=>{let U=l.explained;if(x===null||x.rows.length===0||U===void 0)return;let oe=x.rows.map(re=>x.columns.map(ce=>Ue(re[ce])).join(" | ")).join(`
|
|
25
|
+
`);C?.openAssistant({ask:_(`SQLite planned this query:
|
|
25
26
|
{statement}
|
|
26
27
|
|
|
27
28
|
as:
|
|
28
29
|
{plan}
|
|
29
30
|
|
|
30
|
-
What is it doing, and is anything here slow?`,{plan:oe,statement:U}),schema:
|
|
31
|
+
What is it doing, and is anything here slow?`,{plan:oe,statement:U}),schema:Ie(R),shardKey:w,title:_("Read plan")})},"ee"),te=T?"flex min-h-0 flex-1 flex-row":"flex min-h-0 flex-1 flex-col",ne=T?"flex w-2/5 min-h-0 min-w-0 shrink-0 flex-col border-s border-border":"flex h-2/5 min-h-0 shrink-0 flex-col border-t border-border";return(0,u.jsxs)("div",{className:"flex h-full min-w-0","data-testid":"lunora-sql-editor",children:[(0,u.jsx)(wo,{activeId:q,history:f.history,listRef:f.listRef,onClearHistory:f.clearHistory,onDelete:f.deleteQuery,onLoadHistory:f.loadFromHistory,onLoadTemplate:f.loadTemplate,onNew:f.newQuery,onRename:f.renameQuery,onSearchChange:f.onSearchChange,onSelect:f.selectQuery,onToggleRememberHistory:f.setRememberHistory,queries:f.queries,rememberHistory:f.rememberHistory,rpc:P,search:f.search}),(0,u.jsxs)("div",{className:"flex min-w-0 flex-1 flex-col",children:[(0,u.jsx)(Po,{model:t,onSelect:Z}),(0,u.jsxs)("div",{className:te,children:[(0,u.jsx)(bo,{autocomplete:F.autocompleteState,diagnostics:B,draft:k,editorRef:F.editorRef,failed:S,gutterRef:F.gutterRef,handlers:F.handlers,inlineEdit:F.inlineEdit,listboxId:F.listboxId,onAcceptInlineEdit:F.acceptInlineEdit,onCancelInlineEdit:F.closeInlineEdit,onGenerated:M,onPickSuggestion:F.onPickSuggestion,onRevealDiagnostic:F.revealDiagnostic,overlayRef:F.overlayRef,rpc:P}),(0,u.jsx)(Io,{chart:N,chatOpen:C?.open===!0,className:ne,durationMs:l.durationMs,error:h,onDebugError:S===void 0?void 0:be,onExplainPlan:C===void 0||C.unavailable||y!=="explain"?void 0:Y,onExplainSql:C===void 0||C.unavailable?void 0:fe,onFormat:G,onInferChart:K,onRun:Q,onSelectStatement:A,onShardKeyChange:me,onShowChart:ae,onShowExplain:se,onShowResults:X,onToggleChat:C===void 0||C.unavailable?void 0:pe,onToggleSplit:ue,pane:y,result:x,rpc:P,running:v,script:l.script,shardKey:w,splitView:T})]})]})]})},"ao");export{pr as SqlEditorPanel};
|