@lunora/studio 1.0.0-alpha.371 → 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-64WVI7AU.js → chunk-25WEL5RI.js} +1 -1
- package/dist/standalone/{chunk-QY5JC5H6.js → chunk-2CPMCEHD.js} +1 -1
- package/dist/standalone/{chunk-ZYARVDS6.js → chunk-2IOS27FL.js} +1 -1
- package/dist/standalone/{chunk-KGURUUEC.js → chunk-2MZLFQR5.js} +1 -1
- package/dist/standalone/{chunk-PD56UWVC.js → chunk-2U6Z7A6C.js} +1 -1
- package/dist/standalone/{chunk-2WELEPUX.js → chunk-3BQD5ITB.js} +1 -1
- package/dist/standalone/{chunk-4AJML27P.js → chunk-42RZZFLX.js} +1 -1
- package/dist/standalone/{chunk-23TGXTY3.js → chunk-4ADB7TWC.js} +1 -1
- package/dist/standalone/{chunk-43VARWUD.js → chunk-4B54WP4R.js} +1 -1
- package/dist/standalone/{chunk-3NC6JA7A.js → chunk-4EQAUONF.js} +1 -1
- package/dist/standalone/{chunk-RLSKEGNK.js → chunk-4RGKUS3H.js} +1 -1
- package/dist/standalone/{chunk-HRH5FYV6.js → chunk-52ULLZJX.js} +1 -1
- package/dist/standalone/{chunk-PRTIYJFL.js → chunk-645S7KRU.js} +1 -1
- package/dist/standalone/{chunk-O4D6HJOQ.js → chunk-6IRGBPDN.js} +1 -1
- package/dist/standalone/{chunk-LRQTVCUX.js → chunk-6VOBO5QL.js} +1 -1
- package/dist/standalone/{chunk-G2BUKFAD.js → chunk-6YBEKVUG.js} +1 -1
- package/dist/standalone/{chunk-3HR74V73.js → chunk-7SNL633X.js} +1 -1
- package/dist/standalone/{chunk-G6IFVCSL.js → chunk-ACWAMBGT.js} +1 -1
- package/dist/standalone/{chunk-UQZUK6MO.js → chunk-AERXMIND.js} +1 -1
- package/dist/standalone/{chunk-J7NEJGZW.js → chunk-ASD6UAND.js} +1 -1
- package/dist/standalone/{chunk-HAVIBMMB.js → chunk-B76HLC52.js} +1 -1
- package/dist/standalone/{chunk-JW3TXMEF.js → chunk-BQS3C5V3.js} +1 -1
- package/dist/standalone/{chunk-OYBBHQRO.js → chunk-C4BS3LHQ.js} +1 -1
- package/dist/standalone/{chunk-CHJYRPLL.js → chunk-CAEJQOMU.js} +1 -1
- package/dist/standalone/{chunk-72PNA5CK.js → chunk-CBACG4XF.js} +1 -1
- package/dist/standalone/{chunk-I2EFWZXX.js → chunk-CGXIERYO.js} +1 -1
- package/dist/standalone/{chunk-SY7AVD6C.js → chunk-D3DZZHZA.js} +1 -1
- package/dist/standalone/{chunk-SEPNNN6O.js → chunk-D6CDIHHL.js} +1 -1
- package/dist/standalone/{chunk-OLI3R5ZJ.js → chunk-DDTWGWM4.js} +1 -1
- package/dist/standalone/{chunk-ZYGPKYEU.js → chunk-DHH7WHXQ.js} +1 -1
- package/dist/standalone/{chunk-QCWPTLPV.js → chunk-EAPNLM2Q.js} +1 -1
- package/dist/standalone/{chunk-RPKPLAT2.js → chunk-ELUYMLPL.js} +1 -1
- package/dist/standalone/{chunk-QTEJHIZD.js → chunk-EX2DUBRT.js} +1 -1
- package/dist/standalone/{chunk-TDYA6E3G.js → chunk-F5WJCL3F.js} +1 -1
- package/dist/standalone/{chunk-C724GMPR.js → chunk-FGZ73BFG.js} +1 -1
- package/dist/standalone/{chunk-X7TFLK6L.js → chunk-FK2S7VR4.js} +1 -1
- package/dist/standalone/{chunk-STHN562E.js → chunk-FT3BWJVP.js} +1 -1
- package/dist/standalone/{chunk-MY7J2X2Y.js → chunk-FWOOA2ZR.js} +1 -1
- package/dist/standalone/{chunk-FWJ7VSGQ.js → chunk-G5REMLEG.js} +1 -1
- package/dist/standalone/{chunk-YEMTJB7N.js → chunk-GH6CI2P2.js} +1 -1
- package/dist/standalone/{chunk-ALXTADCX.js → chunk-HCWB4UDT.js} +1 -1
- package/dist/standalone/{chunk-Z4VISCXI.js → chunk-HPD2PZP2.js} +1 -1
- package/dist/standalone/{chunk-HG3MXWXT.js → chunk-HZU4WF4X.js} +1 -1
- package/dist/standalone/{chunk-LHAYLYCA.js → chunk-IELLWQGA.js} +1 -1
- package/dist/standalone/{chunk-CKK227GJ.js → chunk-IJNP6YSD.js} +1 -1
- package/dist/standalone/{chunk-HDBRX5CX.js → chunk-ILSJ22BK.js} +1 -1
- package/dist/standalone/{chunk-5Y67VCSW.js → chunk-JAAXDIR5.js} +1 -1
- package/dist/standalone/chunk-JB3DZ2PJ.js +1 -0
- package/dist/standalone/{chunk-WMF3KFRB.js → chunk-JPCVFWR5.js} +1 -1
- package/dist/standalone/{chunk-KSFVO6OB.js → chunk-KBYFBEG2.js} +1 -1
- package/dist/standalone/{chunk-73GEDGFE.js → chunk-KYN4A72O.js} +1 -1
- package/dist/standalone/{chunk-P2JJ33X3.js → chunk-LA76GGAT.js} +1 -1
- package/dist/standalone/{chunk-GN3GGVCY.js → chunk-LCIDEYA4.js} +1 -1
- package/dist/standalone/{chunk-RPHIAYMR.js → chunk-LFKKTGEF.js} +1 -1
- package/dist/standalone/{chunk-URNEEX2Q.js → chunk-LR2FBYCC.js} +1 -1
- package/dist/standalone/{chunk-BWT5ANXC.js → chunk-M4TCBPSY.js} +1 -1
- package/dist/standalone/{chunk-IJAZY2M7.js → chunk-MGFELY5Q.js} +1 -1
- package/dist/standalone/{chunk-UTE2SZQY.js → chunk-MJWIIV2C.js} +1 -1
- package/dist/standalone/{chunk-PYK4VXG6.js → chunk-MTX62MQ7.js} +1 -1
- package/dist/standalone/{chunk-74WS3GUC.js → chunk-MWYGLPDV.js} +1 -1
- package/dist/standalone/{chunk-ZN6LJWXV.js → chunk-N7EIHD3H.js} +1 -1
- package/dist/standalone/{chunk-UMDBJGZH.js → chunk-NGGTRLCC.js} +1 -1
- package/dist/standalone/chunk-ODLNNVP2.js +7 -0
- package/dist/standalone/{chunk-KQQOOBL5.js → chunk-OODTH4NA.js} +1 -1
- package/dist/standalone/{chunk-2BN5NW34.js → chunk-OSHODLMU.js} +1 -1
- package/dist/standalone/{chunk-QNJJIVLQ.js → chunk-OVEOTKK5.js} +1 -1
- package/dist/standalone/{chunk-S6RKBBI5.js → chunk-PGJOTPWC.js} +1 -1
- package/dist/standalone/{chunk-RXGN7E4K.js → chunk-PIOHOROI.js} +1 -1
- package/dist/standalone/{chunk-IOMK34E4.js → chunk-PIQ4A4BZ.js} +1 -1
- package/dist/standalone/{chunk-6DU2UW57.js → chunk-PUK3H4RN.js} +2 -2
- package/dist/standalone/{chunk-XIJQY7MK.js → chunk-QHKR5JW4.js} +1 -1
- package/dist/standalone/{chunk-PLLNOYT6.js → chunk-QMULO5AP.js} +1 -1
- package/dist/standalone/{chunk-K3LRNI56.js → chunk-QN66FO5B.js} +1 -1
- package/dist/standalone/{chunk-Y23CK77V.js → chunk-QNY5EEBN.js} +1 -1
- package/dist/standalone/{chunk-AHANHVFC.js → chunk-R52GVSS2.js} +1 -1
- package/dist/standalone/{chunk-WUJWIBTQ.js → chunk-RDS46R5R.js} +1 -1
- package/dist/standalone/{chunk-J4KHSWXK.js → chunk-RDS72J4I.js} +1 -1
- package/dist/standalone/{chunk-4M223MUW.js → chunk-RHYQB4RH.js} +1 -1
- package/dist/standalone/{chunk-2STFVRP6.js → chunk-RKPVI2PI.js} +1 -1
- package/dist/standalone/{chunk-XAI64L2D.js → chunk-RUQTILJN.js} +1 -1
- package/dist/standalone/{chunk-N77FOL5Q.js → chunk-SKZNH5QQ.js} +1 -1
- package/dist/standalone/{chunk-DFOIQN5E.js → chunk-SUUBCPUD.js} +1 -1
- package/dist/standalone/{chunk-EDN4JTLK.js → chunk-TDJQ7HQM.js} +1 -1
- package/dist/standalone/{chunk-34E6NNQZ.js → chunk-TUFOWHEF.js} +1 -1
- package/dist/standalone/{chunk-U2E36H6V.js → chunk-USVLFLZL.js} +1 -1
- package/dist/standalone/{chunk-5IXKYP7I.js → chunk-VDSTHVWZ.js} +1 -1
- package/dist/standalone/{chunk-AXKOMM2J.js → chunk-VXZAS5VS.js} +1 -1
- package/dist/standalone/{chunk-KSLMSLWZ.js → chunk-WFXS3YRM.js} +16 -15
- package/dist/standalone/{chunk-5W5XLOZO.js → chunk-WJA2IGZC.js} +1 -1
- package/dist/standalone/{chunk-VHRWGZVT.js → chunk-WSG35SRF.js} +1 -1
- package/dist/standalone/{chunk-5REEK2HD.js → chunk-XITLHKKR.js} +1 -1
- package/dist/standalone/{chunk-QK46WKIS.js → chunk-XWVFKYZV.js} +1 -1
- package/dist/standalone/{chunk-FVITJ4Q4.js → chunk-XZHTVLDG.js} +1 -1
- package/dist/standalone/{chunk-KRWSRKJ3.js → chunk-Z6WEYWT7.js} +1 -1
- package/dist/standalone/{chunk-VCLCELNQ.js → chunk-Z7ZGAQ5J.js} +1 -1
- package/dist/standalone/{chunk-MYRTLPF5.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-35IQT6SS.js +0 -7
- package/dist/standalone/chunk-BO35TSLE.js +0 -1
- /package/dist/standalone/{chunk-P6VNMPWR.js → chunk-R6NJ4ER6.js} +0 -0
|
@@ -1,25 +1,26 @@
|
|
|
1
|
-
import{c as G}from"react/compiler-runtime";import{useState as te,useMemo as
|
|
2
|
-
`;)
|
|
1
|
+
import{c as G}from"react/compiler-runtime";import{useState as te,useMemo as je,useCallback as Ze,useEffect as ue,useRef as de,useId as ht}from"react";import{u as bt}from"../packem_shared/assistant-provider-BQG7QZAu.mjs";import{u as gt}from"../packem_shared/use-assistant-rpc-DCC6ph2u.mjs";import{u as $e}from"../packem_shared/use-studio-client-DCA50tF2.mjs";import{useT as Z}from"../packem_shared/DEFAULT_LOCALE-BQ3jRT74.mjs";import{ADMIN_FUNCTIONS as qe}from"../packem_shared/ADMIN_FUNCTIONS-C6U-ugro.mjs";import{u as Oe,n as et,b as Be,r as Ce,s as xt}from"../packem_shared/browser-storage-BH1MxLZs.mjs";import{d as Re,f as ie,c as Ie,l as vt,b as yt}from"../packem_shared/internal-hIuTpSbx.mjs";import{r as St}from"../packem_shared/shard-history-CaO3C4KQ.mjs";import wt from"../packem_shared/useDebounced-DVeQ5-oW.mjs";import{c as ae}from"../packem_shared/utils-bhneXptQ.mjs";import{jsxs as W,jsx as u,Fragment as xe}from"react/jsx-runtime";import{I as Le}from"../packem_shared/input-CXhxesPC.mjs";import{a as tt}from"../packem_shared/assistant-reason-D6EwMCxT.mjs";import{diffLines as Ct}from"diff";import{S as Et,a as Nt}from"../packem_shared/sql-result-table-DCwooMGW.mjs";import{ShardInput as kt}from"../packem_shared/ShardInput-CoySruKZ.mjs";import{A as Tt}from"../packem_shared/alert-PB5W11MM.mjs";import{E as Rt}from"../packem_shared/grid-features-Drvfswwy.mjs";const Lt="x",ze=" ",_t={'"':'"',"'":"'","[":"]","`":"`"},nt=(l,e)=>{let n=e+2;for(;n<l.length&&l[n]!==`
|
|
2
|
+
`;)n+=1;return n},st=(l,e)=>{const n=l.indexOf("*/",e+2);return n===-1?-1:n+2},ot=l=>{const e=l.split("");let n=0;for(;n<l.length;){const t=l[n]??"",s=_t[t];if(t==="-"&&l[n+1]==="-"){const o=nt(l,n);e.fill(ze,n,o),n=o}else if(t==="/"&&l[n+1]==="*"){const o=st(l,n);if(o===-1)return;e.fill(ze,n,o),n=o}else if(s!==void 0){let o=n+1;for(;o<l.length;)if(l[o]!==s)o+=1;else if(s!=="]"&&l[o+1]===s)o+=2;else break;if(o>=l.length)return;e.fill(Lt,n,o+1),n=o+1}else n+=1}for(let t=0;t<l.length;t+=1)l[t]===`
|
|
3
3
|
`&&(e[t]=`
|
|
4
|
-
`);return e.join("")},
|
|
5
|
-
|
|
6
|
-
`,e);return t===-1?r.length:t}if(s==="/"&&r[e+1]==="*"){const t=r.indexOf("*/",e+2);return t===-1?r.length:t+2}return-1},jt=r=>{let e="",s=0;for(;s<r.length;){const t=Qt(r,s);t===-1?(e+=r.slice(s,s+1),s+=1):(e+=r.slice(s,t).replaceAll(Ft," "),s=t)}return e},zt=r=>{const e=new Set;for(const s of r.matchAll(Wt))e.add((s[1]??"").toLowerCase());return e},Kt=(r,e)=>{const s=new Map;for(const t of r.matchAll(Pt)){const o=(t[1]??"").toLowerCase(),n=(t[2]??"").toLowerCase();e.has(o)&&(s.set(o,o),n!==""&&!Ht.has(n)&&s.set(n,o))}return s},nt=(r,e)=>{const s=jt(r),t=new Set(e.map(o=>o.toLowerCase()));return{ctes:zt(s),masked:s,targets:Kt(s,t)}},Ut=/^(?:__lunora|sqlite_)/iu,Yt=/\b(?:from|join)\s+([a-z_][\w$]*)/giu,Gt=/\b([a-z_][\w$]*)\.([a-z_][\w$]*)/giu,Vt=new Set(["cross","full","group","having","inner","join","lateral","left","limit","offset","order","right","select","union","where","window"]),Jt=(r,e,s)=>{const t=[];for(const o of r.matchAll(Yt)){const n=o[1]??"",l=n.toLowerCase();!e.has(l)&&!s.has(l)&&!Vt.has(l)&&!Ut.test(n)&&t.push({length:n.length,message:`unknown table \`${n}\``,offset:o.index+o[0].length-n.length,severity:"error",source:"schema"})}return t},Xt=(r,e,s)=>{const t=[],o=new Map;for(const[n,l]of Object.entries(e.columns))o.set(n.toLowerCase(),new Set(l.map(i=>i.toLowerCase())));for(const n of r.matchAll(Gt)){const l=(n[1]??"").toLowerCase(),i=n[2]??"",c=s.get(l),a=c===void 0?void 0:o.get(c);a!==void 0&&!a.has(i.toLowerCase())&&t.push({length:i.length,message:`\`${c??""}\` has no column \`${i}\``,offset:n.index+n[0].length-i.length,severity:"error",source:"schema"})}return t},Zt=/(?<![\w$."])(?:"([a-z_][\w$]*)"|([a-z_][\w$]*))(?![.(])/giu,en=/\bas\s+"?([a-z_][\w$]*)"?/giu,tn=(r,e,s,t)=>{const o=[...new Set(s.values())],n=new Map,l=new Set;for(const a of o){for(const d of e.columns[a]??[])l.add(d.toLowerCase());for(const d of e.docFields?.[a]??[])n.set(d.toLowerCase(),d)}if(n.size===0)return[];const i=new Set([...r.matchAll(en)].map(a=>(a[1]??"").toLowerCase())),c=[];for(const a of r.matchAll(Zt)){const d=a[1],m=d??a[2]??"",f=m.toLowerCase(),h=n.get(f);h===void 0||l.has(f)||i.has(f)||t.has(f)||s.has(f)||c.push({length:m.length,message:`\`${h}\` is a \`__doc__\` field, not a column — use \`json_extract(__doc__, '$.${h}')\``,offset:a.index+(d===void 0?0:1),severity:"error",source:"schema"})}return c},nn=(r,e)=>{if(r.trim()==="")return[];const s=tt(r),t=new Set(e.tables.map(n=>n.toLowerCase())),o=[];for(const n of s){const{offset:l,rejection:i}=n;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}const{ctes:c,masked:a,targets:d}=nt(n.sql,e.tables);o.push(...[...Jt(a,t,c),...Xt(a,e,d),...tn(a,e,d,c)].map(m=>({...m,offset:m.offset===void 0?l:l+m.offset})))}return o},sn=Ae(Le.lintSql),on=600,ln=(r,e,s)=>{const t=Me(),[o,n]=te([]),l=Fe(()=>nn(r,e),[r,e]),i=bt(r,on),a=l.some(f=>f.source==="gate")||i.trim()==="",d=Ye(async f=>{try{const h=await t.query(sn,{sql:i},qe(s));f.cancelled||n(h.diagnostics??[])}catch{f.cancelled||n([])}},[t,i,s]);ue(()=>{if(a){n([]);return}const f={cancelled:!1};return ie(d(f)),()=>{f.cancelled=!0}},[d,a]);const m=i===r;return Fe(()=>m?[...l,...o]:l,[l,o,m])},ke=8,rn=["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"],an=new Set(["AND","BY","HAVING","ON","OR","SELECT","WHERE"]),cn=/[\w$]/,st=r=>r!==void 0&&cn.test(r),ot=r=>{let e=r.length;for(;e>0&&st(r[e-1]);)e-=1;return r.slice(e)},lt=(r,e)=>{let s=e;for(;s>0&&st(r[s-1]);)s-=1;return{end:e,start:s,text:r.slice(s,e)}},je=(r,e)=>{const s=r.slice(0,e).trimEnd();return s.endsWith(".")||an.has(ot(s).toUpperCase())},dn=(r,e,s)=>{const t=r.slice(0,e);if(!t.endsWith("."))return;const o=ot(t.slice(0,-1));if(o!=="")return nt(r,s).targets.get(o.toLowerCase())??o},Be=(r,e)=>r.toLowerCase().startsWith(e.toLowerCase()),ze=(r,e,s,t)=>{const o=[];for(const n of r)if(Be(n,e)&&(o.push(t(n)),o.length>=s))break;return o},un=(r,e,s)=>{const t=new Map;for(const[o,n]of Object.entries(r.columns))for(const l of n)if(Be(l,e)&&!t.has(l)&&(t.set(l,o),t.size>=s))return[...t].map(([i,c])=>({detail:c,kind:"column",label:i}));return[...t].map(([o,n])=>({detail:n,kind:"column",label:o}))},fn=(r,e,s)=>{const t=lt(r,e),o=dn(r,t.start,s.tables);if(o!==void 0){const a=s.columns[o]??s.columns[o.toLowerCase()]??[];return ze(a,t.text,ke,d=>({detail:o,kind:"column",label:d}))}if(t.text===""&&!je(r,t.start))return[];const n=ze(s.tables,t.text,ke,a=>({kind:"table",label:a})),l=un(s,t.text,ke),i=rn.flatMap(a=>t.text!==""&&Be(a,t.text)&&a.toLowerCase()!==t.text.toLowerCase()?[{kind:"keyword",label:a}]:[]);return(je(r,t.start)?[...l,...n,...i]:[...n,...l,...i]).slice(0,ke)},mn=(r,e,s)=>{const t=lt(r,e),o=r.slice(0,t.start)+s.label+r.slice(t.end);return{caret:t.start+s.label.length,value:o}},pn=["boxSizing","borderBottomWidth","borderLeftWidth","borderRightWidth","borderTopWidth","fontFamily","fontSize","fontStyle","fontWeight","letterSpacing","lineHeight","paddingBottom","paddingLeft","paddingRight","paddingTop","tabSize","textIndent","textTransform","width","wordSpacing"],hn=(r,e)=>{const s=globalThis.getComputedStyle(r),t=globalThis.document.createElement("div"),{style:o}=t;o.position="absolute",o.visibility="hidden",o.whiteSpace="pre-wrap",o.overflowWrap="break-word";for(const c of pn)o[c]=s[c];t.textContent=r.value.slice(0,Math.max(0,e));const n=globalThis.document.createElement("span");n.textContent=r.value.slice(Math.max(0,e))||".",t.append(n),globalThis.document.body.append(t);const l=n.offsetLeft-r.scrollLeft,i=n.offsetTop-r.scrollTop;return t.remove(),{left:l,top:i}},bn=(r,e,s)=>{const t=G(16),[o,n]=te(null);let l;t[0]!==r||t[1]!==e?(l=(S,p)=>{const N=fn(S,p,r);if(N.length===0){n(null);return}const x=e.current,{left:b,top:y}=x===null?{left:0,top:0}:hn(x,p);n(C=>C!==null&&C.active===0&&C.left===b&&C.top===y&&C.suggestions.length===N.length&&C.suggestions.every((I,q)=>{const T=N.at(q);return I.kind===T?.kind&&I.label===T.label&&I.detail===T.detail})?C:{active:0,left:b,suggestions:N,top:y})},t[0]=r,t[1]=e,t[2]=l):l=t[2];const i=l;let c;t[3]===Symbol.for("react.memo_cache_sentinel")?(c=()=>{n(null)},t[3]=c):c=t[3];const a=c;let d;t[4]===Symbol.for("react.memo_cache_sentinel")?(d=S=>{n(p=>{if(p===null)return p;const N=p.suggestions.length,x=(p.active+S+N)%N;return{...p,active:x}})},t[4]=d):d=t[4];const m=d;let f;t[5]!==s||t[6]!==o||t[7]!==e?(f=S=>{const p=e.current;if(o===null||p===null)return!1;const N=o.suggestions[S??o.active];if(N===void 0)return!1;const x=mn(p.value,p.selectionStart,N);return s(x.value),n(null),requestAnimationFrame(()=>{const b=e.current;b!==null&&(b.focus(),b.setSelectionRange(x.caret,x.caret))}),!0},t[5]=s,t[6]=o,t[7]=e,t[8]=f):f=t[8];const h=f;let g;t[9]!==h?(g=()=>h(),t[9]=h,t[10]=g):g=t[10];const R=g;let v;return t[11]!==R||t[12]!==h||t[13]!==i||t[14]!==o?(v={close:a,commit:R,commitAt:h,move:m,refresh:i,state:o},t[11]=R,t[12]=h,t[13]=i,t[14]=o,t[15]=v):v=t[15],v},gn={column:"column",keyword:"keyword",table:"table"},xn=20,vn=r=>{const e=G(17),{listboxId:s,onPick:t,state:o}=r,n=Z();let l;e[0]!==o?(l=o===null?void 0:{left:o.left,top:o.top+xn},e[0]=o,e[1]=l):l=e[1];const i=l;if(o===null)return null;let c;if(e[2]!==s||e[3]!==t||e[4]!==o.active||e[5]!==o.suggestions||e[6]!==n){let d;e[8]!==s||e[9]!==t||e[10]!==o.active||e[11]!==n?(d=(m,f)=>W("li",{"aria-selected":f===o.active,className:ae("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:`${s}-opt-${f.toString()}`,onMouseDown:h=>{h.preventDefault(),t(f)},role:"option",children:[u("span",{className:"truncate font-mono",children:m.label}),m.detail!==void 0&&u("span",{className:"ms-auto truncate text-xs text-muted-foreground",children:m.detail}),u("span",{className:"shrink-0 font-mono text-[10px] tracking-wide text-muted-foreground/70 uppercase",children:n(gn[m.kind])})]},`${m.kind}:${m.label}`),e[8]=s,e[9]=t,e[10]=o.active,e[11]=n,e[12]=d):d=e[12],c=o.suggestions.map(d),e[2]=s,e[3]=t,e[4]=o.active,e[5]=o.suggestions,e[6]=n,e[7]=c}else c=e[7];let a;return e[13]!==s||e[14]!==i||e[15]!==c?(a=u("ul",{className:"absolute z-30 max-h-56 w-72 overflow-auto rounded-md border border-border bg-popover py-1 text-popover-foreground shadow-md","data-testid":"sql-autocomplete",id:s,role:"listbox",style:i,children:c}),e[13]=s,e[14]=i,e[15]=c,e[16]=a):a=e[16],a},yn=Ae(Le.listTables),Sn=Ae(Le.readTablePage),wn=r=>{const e=G(18),s=Me();let t;e[0]===Symbol.for("react.memo_cache_sentinel")?(t=[],e[0]=t):t=e[0];const[o,n]=te(t);let l;e[1]===Symbol.for("react.memo_cache_sentinel")?(l={},e[1]=l):l=e[1];const[i,c]=te(l);let a;e[2]===Symbol.for("react.memo_cache_sentinel")?(a={},e[2]=a):a=e[2];const[d,m]=te(a);let f;e[3]===Symbol.for("react.memo_cache_sentinel")?(f=new Set,e[3]=f):f=e[3];const h=de(f);let g,R;e[4]!==s||e[5]!==r?(g=()=>{const b={cancelled:!1};return ie((async()=>{try{const C=await s.query(yn,{},qe(r));b.cancelled||(n(C.map(kn)),c({}),m({}),h.current=new Set)}catch{b.cancelled||(n([]),c({}),m({}),h.current=new Set)}})()),()=>{b.cancelled=!0}},R=[s,r],e[4]=s,e[5]=r,e[6]=g,e[7]=R):(g=e[6],R=e[7]),ue(g,R);let v;e[8]!==s||e[9]!==r?(v=b=>{if(h.current.has(b))return;h.current.add(b),ie((async()=>{try{const C=await s.query(Sn,{limit:1,offset:0,table:b},qe(r)),{sqlColumns:w}=C;if(w===void 0){h.current.delete(b);return}const I=new Set(w),q=C.columns.filter(T=>!I.has(T));c(T=>({...T,[b]:w})),m(T=>({...T,[b]:q}))}catch{h.current.delete(b)}})())},e[8]=s,e[9]=r,e[10]=v):v=e[10];const S=v;let p;e[11]!==i||e[12]!==d||e[13]!==o?(p={columns:i,docFields:d,tables:o},e[11]=i,e[12]=d,e[13]=o,e[14]=p):p=e[14];const N=p;let x;return e[15]!==S||e[16]!==N?(x={probe:S,schema:N},e[15]=S,e[16]=N,e[17]=x):x=e[17],x},_e=/\b(?:from|join|update|into)\s+([a-z_][\w$]*)|\b([a-z_][\w$]*)\s*\./gi,Cn=r=>{const e=new Set;_e.lastIndex=0;let s=_e.exec(r);for(;s!==null;)e.add(s[1]??s[2]),s=_e.exec(r);return[...e]};function kn(r){return r.name}const Nn=r=>(r.metaKey||r.ctrlKey)&&!r.shiftKey&&!r.altKey&&r.key.toLowerCase()==="i",En=r=>{const e=G(44),{inlineEditEnabled:s,onSubmit:t,probe:o,schema:n,setDraft:l}=r,i=ct(),[c,a]=te(null),d=de(null),m=de(null),f=de(null),h=bn(n,f,l),{close:g,commit:R,commitAt:v,move:S,refresh:p,state:N}=h;let x;e[0]!==v?(x=O=>{v(O)},e[0]=v,e[1]=x):x=e[1];const b=x;let y;e[2]!==p?(y=()=>{const O=f.current;O!==null&&O===document.activeElement&&p(O.value,O.selectionStart)},e[2]=p,e[3]=y):y=e[3];let C;e[4]!==p||e[5]!==n?(C=[p,n],e[4]=p,e[5]=n,e[6]=C):C=e[6],ue(y,C);let w;e[7]!==o||e[8]!==p||e[9]!==l?(w=O=>{const{selectionStart:U,value:X}=O.target;l(X),a(null);for(const Y of Cn(X))o(Y);p(X,U)},e[7]=o,e[8]=p,e[9]=l,e[10]=w):w=e[10];const I=w;let q;e[11]!==p?(q=O=>{const U=O.currentTarget;p(U.value,U.selectionStart)},e[11]=p,e[12]=q):q=e[12];const T=q;let E;e[13]!==g||e[14]!==R||e[15]!==S?(E=O=>O.key==="ArrowDown"?(O.preventDefault(),S(1),!0):O.key==="ArrowUp"?(O.preventDefault(),S(-1),!0):O.key==="Escape"?(O.preventDefault(),g(),!0):(O.key==="Enter"||O.key==="Tab")&&!O.metaKey&&!O.ctrlKey&&R()?(O.preventDefault(),!0):!1,e[13]=g,e[14]=R,e[15]=S,e[16]=E):E=e[16];const k=E;let L;e[17]!==N||e[18]!==g||e[19]!==s||e[20]!==k||e[21]!==t?(L=O=>{if(!(N!==null&&k(O))){if((O.metaKey||O.ctrlKey)&&O.key==="Enter"){O.preventDefault(),t();return}if(s&&Nn(O)){O.preventDefault(),g();const{selectionEnd:U,selectionStart:X,value:Y}=O.currentTarget,[oe,re]=X===U?[0,Y.length]:[X,U];a({end:re,start:oe,text:Y.slice(oe,re)})}}},e[17]=N,e[18]=g,e[19]=s,e[20]=k,e[21]=t,e[22]=L):L=e[22];const _=L;let $;e[23]!==g?($=()=>{requestAnimationFrame(()=>{g()})},e[23]=g,e[24]=$):$=e[24];const F=$;let B;e[25]===Symbol.for("react.memo_cache_sentinel")?(B=O=>{const{scrollLeft:U,scrollTop:X}=O.currentTarget;d.current!==null&&(d.current.scrollTop=X),m.current!==null&&(m.current.scrollTop=X,m.current.scrollLeft=U)},e[25]=B):B=e[25];const H=B;let P;e[26]===Symbol.for("react.memo_cache_sentinel")?(P=O=>{const U=f.current;U===null||O.offset===void 0||(U.focus(),U.setSelectionRange(O.offset,O.offset+(O.length??0)))},e[26]=P):P=e[26];const Q=P;let M;e[27]===Symbol.for("react.memo_cache_sentinel")?(M=()=>{a(null),f.current?.focus()},e[27]=M):M=e[27];const A=M;let D;e[28]!==c||e[29]!==l?(D=O=>{const U=f.current;if(c===null||U===null)return;const{end:X,start:Y,text:oe}=c;if(U.value.slice(Y,X)!==oe){a(null);return}l(U.value.slice(0,Y)+O+U.value.slice(X)),a(null),U.focus(),requestAnimationFrame(()=>{U.setSelectionRange(Y,Y+O.length)})},e[28]=c,e[29]=l,e[30]=D):D=e[30];const z=D;let j;e[31]!==I||e[32]!==F||e[33]!==_||e[34]!==T?(j={onBlur:F,onChange:I,onKeyDown:_,onScroll:H,onSelect:T},e[31]=I,e[32]=F,e[33]=_,e[34]=T,e[35]=j):j=e[35];let K;return e[36]!==z||e[37]!==N||e[38]!==g||e[39]!==c||e[40]!==i||e[41]!==b||e[42]!==j?(K={acceptInlineEdit:z,autocompleteState:N,closeAutocomplete:g,closeInlineEdit:A,inlineEdit:c,handlers:j,listboxId:i,onPickSuggestion:b,editorRef:f,gutterRef:d,overlayRef:m,revealDiagnostic:Q},e[36]=z,e[37]=N,e[38]=g,e[39]=c,e[40]=i,e[41]=b,e[42]=j,e[43]=K):K=e[43],K},Tn="lunora-studio-sql-tabs",qn="lunora-studio-sql-active-tab",Pe=12,Se=(r="",e="")=>({activeId:null,id:Ge("tab"),name:e,sql:r}),Rn=()=>$e(qn,""),In=r=>{const e=G(16),[s,t]=De(Tn),[o,n]=Rn(),[l]=te(r);let i,c;e[0]!==l||e[1]!==t||e[2]!==s.length?(i=()=>{s.length===0&&t([l])},c=[l,t,s.length],e[0]=l,e[1]=t,e[2]=s.length,e[3]=i,e[4]=c):(i=e[3],c=e[4]),ue(i,c);let a;e[5]!==l||e[6]!==s?(a=s.length===0?[l]:s,e[5]=l,e[6]=s,e[7]=a):a=e[7];const d=a;let m;e[8]!==o||e[9]!==d?(m=d.some(g=>g.id===o)?o:d[0]?.id??"",e[8]=o,e[9]=d,e[10]=m):m=e[10];const f=m;let h;return e[11]!==f||e[12]!==n||e[13]!==t||e[14]!==d?(h={activeId:f,setActiveId:n,setTabs:t,tabs:d},e[11]=f,e[12]=n,e[13]=t,e[14]=d,e[15]=h):h=e[15],h},rt=r=>r.activeId===null&&r.sql.trim()!=="",Ln=(r,e)=>[...r,e].slice(-Pe),An=(r,e,s)=>{const t=r.findIndex(l=>l.id===e);if(t===-1)return{activeId:r[0]?.id??"",tabs:[...r]};const o=r.filter(l=>l.id!==e);if(o.length===0){const l=s();return{activeId:l.id,tabs:[l]}}return{activeId:o[Math.min(t,o.length-1)].id,tabs:o}},_n=(r,e)=>{const s=r.filter(t=>t.id===e);return s.length===0?{activeId:r[0]?.id??"",tabs:[...r]}:{activeId:e,tabs:s}},Dn=(r,e,s)=>{const t=r.findIndex(n=>n.id===e);if(t===-1)return{activeId:s,tabs:[...r]};const o=r.slice(0,t+1);return{activeId:o.some(n=>n.id===s)?s:e,tabs:o}},On=r=>{const e=r();return{activeId:e.id,tabs:[e]}},Mn=(r,e,s)=>{if(r==="others")return e.filter(t=>t.id!==s);if(r==="right"){const t=e.findIndex(o=>o.id===s);return t===-1?[]:e.slice(t+1)}return[...e]},Ke={error:null,pane:"results",result:null,running:!1},$n=r=>{const e=G(69),{activeId:s,setActiveId:t,setTabs:o,tabs:n}=In(r);let l;e[0]===Symbol.for("react.memo_cache_sentinel")?(l={},e[0]=l):l=e[0];const[i,c]=te(l),[a,d]=te(null),[m,f]=te(null);let h;e[1]!==s||e[2]!==n?(h=n.find(V=>V.id===s)??n[0]??Se(),e[1]=s,e[2]=n,e[3]=h):h=e[3];const g=h,R=i[g.id]??Ke;let v;e[4]!==g.id||e[5]!==o?(v=V=>{o(ee=>ee.map(se=>se.id===g.id?{...se,...V}:se))},e[4]=g.id,e[5]=o,e[6]=v):v=e[6];const S=v;let p;e[7]!==g.id?(p=V=>{c(ee=>{const se=ee[g.id]??Ke;return{...ee,[g.id]:{...se,...V}}})},e[7]=g.id,e[8]=p):p=e[8];const N=p;let x;e[9]!==t||e[10]!==o||e[11]!==n.length?(x=V=>{if(n.length>=Pe)return!1;const ee=Se(V);return o(se=>Ln(se,ee)),t(ee.id),!0},e[9]=t,e[10]=o,e[11]=n.length,e[12]=x):x=e[12];const b=x;let y;e[13]!==b?(y=()=>{b("")},e[13]=b,e[14]=y):y=e[14];const C=y;let w;e[15]!==t||e[16]!==o?(w=V=>{d(null),f(null),o(V.tabs),t(V.activeId);const ee=new Set(V.tabs.map(Bn));c(se=>Object.fromEntries(Object.entries(se).filter(fe=>{const[J]=fe;return ee.has(J)})))},e[15]=t,e[16]=o,e[17]=w):w=e[17];const I=w;let q;e[18]!==I||e[19]!==n?(q=V=>{I(An(n,V,Se))},e[18]=I,e[19]=n,e[20]=q):q=e[20];const T=q;let E;e[21]!==s||e[22]!==I||e[23]!==n?(E=(V,ee)=>{I(V==="others"?_n(n,ee):V==="right"?Dn(n,ee,s):On(Se))},e[21]=s,e[22]=I,e[23]=n,e[24]=E):E=e[24];const k=E;let L;e[25]!==k||e[26]!==a||e[27]!==n?(L=V=>{a!==null&&(Mn(V,n,a.id).some(Pn)?f(V):k(V,a.id))},e[25]=k,e[26]=a,e[27]=n,e[28]=L):L=e[28];const _=L;let $;e[29]===Symbol.for("react.memo_cache_sentinel")?($=(V,ee)=>{ee.preventDefault(),f(null),d({id:V,x:ee.clientX,y:ee.clientY})},e[29]=$):$=e[29];const F=$;let B;e[30]===Symbol.for("react.memo_cache_sentinel")?(B=()=>{d(null),f(null)},e[30]=B):B=e[30];const H=B;let P;e[31]===Symbol.for("react.memo_cache_sentinel")?(P=V=>{V.preventDefault(),d(null),f(null)},e[31]=P):P=e[31];const Q=P;let M;e[32]!==_?(M=()=>{_("others")},e[32]=_,e[33]=M):M=e[33];const A=M;let D;e[34]!==_?(D=()=>{_("right")},e[34]=_,e[35]=D):D=e[35];const z=D;let j;e[36]!==_?(j=()=>{_("all")},e[36]=_,e[37]=j):j=e[37];const K=j;let O;e[38]!==k||e[39]!==m||e[40]!==a?(O=()=>{a!==null&&m!==null&&k(m,a.id),f(null)},e[38]=k,e[39]=m,e[40]=a,e[41]=O):O=e[41];const U=O;let X;e[42]===Symbol.for("react.memo_cache_sentinel")?(X=()=>{f(null)},e[42]=X):X=e[42];const Y=X;let oe;e[43]!==a?(oe=a===null?void 0:{left:a.x,top:a.y},e[43]=a,e[44]=oe):oe=e[44];const re=oe;let pe;e[45]!==o?(pe=V=>{o(ee=>ee.map(se=>se.activeId===V?{...se,activeId:null}:se))},e[45]=o,e[46]=pe):pe=e[46];const ve=pe;let he;e[47]!==o?(he=(V,ee)=>{o(se=>se.map(fe=>fe.id===V?{...fe,name:ee}:fe))},e[47]=o,e[48]=he):he=e[48];const ye=he;let be;return e[49]!==g||e[50]!==s||e[51]!==C||e[52]!==T||e[53]!==U||e[54]!==K||e[55]!==A||e[56]!==z||e[57]!==b||e[58]!==R||e[59]!==N||e[60]!==S||e[61]!==m||e[62]!==ye||e[63]!==t||e[64]!==a||e[65]!==re||e[66]!==n||e[67]!==ve?(be={activeTab:g,activeTabId:s,addEditorTab:C,cancelBulk:Y,closeEditorTab:T,closeTabMenu:H,confirmBulk:U,menuStyle:re,onBackdropContextMenu:Q,onCloseAll:K,onCloseOthers:A,onCloseToRight:z,openEditorTab:b,openTabMenu:F,output:R,patchActiveOutput:N,patchActiveTab:S,pendingBulk:m,renameTab:ye,setActiveTabId:t,tabMenu:a,tabs:n,unlinkQuery:ve},e[49]=g,e[50]=s,e[51]=C,e[52]=T,e[53]=U,e[54]=K,e[55]=A,e[56]=z,e[57]=b,e[58]=R,e[59]=N,e[60]=S,e[61]=m,e[62]=ye,e[63]=t,e[64]=a,e[65]=re,e[66]=n,e[67]=ve,e[68]=be):be=e[68],be};function Bn(r){return r.id}function Pn(r){return rt(r)}const Wn="lunora-studio-sql-queries",ge="lunora-studio-sql-history",Hn="lunora-studio-sql-remember-history",Fn=25,Qn=r=>{const e=G(44),{loadIntoActiveTab:s,unlinkQuery:t}=r,o=Z(),[n,l]=De(Wn),[i,c]=$e(Hn,!1),[a,d]=De(ge,i?"local":"session");let m,f;e[0]!==i?(m=()=>{i||Ce(ge,"local")},f=[i],e[0]=i,e[1]=m,e[2]=f):(m=e[1],f=e[2]),ue(m,f);const[h,g]=te(""),R=de(null);let v;e[3]!==d?(v=A=>{d(D=>D[0]?.sql===A?D:[{at:Date.now(),sql:A},...D.filter(j=>j.sql!==A)].slice(0,Fn))},e[3]=d,e[4]=v):v=e[4];const S=v;let p;e[5]!==s||e[6]!==l||e[7]!==o?(p=()=>{const A={id:Ge("q"),name:o("Untitled query"),sql:""};l(D=>[A,...D]),s("",A.id)},e[5]=s,e[6]=l,e[7]=o,e[8]=p):p=e[8];const N=p;let x;e[9]!==s||e[10]!==n?(x=A=>{const D=n.find(z=>z.id===A);D!==void 0&&(s(D.sql,A),R.current?.querySelector(`[data-testid="sql-query-${A}"]`)?.scrollIntoView({block:"nearest"}))},e[9]=s,e[10]=n,e[11]=x):x=e[11];const b=x;let y;e[12]!==l||e[13]!==t?(y=A=>{l(D=>D.filter(z=>z.id!==A)),t(A)},e[12]=l,e[13]=t,e[14]=y):y=e[14];const C=y;let w;e[15]!==s?(w=A=>{s(A.currentTarget.dataset.sql??"",null)},e[15]=s,e[16]=w):w=e[16];const I=w;let q;e[17]!==s?(q=A=>{s(A.currentTarget.dataset.sql??"",null)},e[17]=s,e[18]=q):q=e[18];const T=q;let E;e[19]!==d?(E=()=>{d([]),Ce(ge,"local"),Ce(ge,"session")},e[19]=d,e[20]=E):E=e[20];const k=E;let L;e[21]!==a||e[22]!==c?(L=A=>{ft(ge,a,A?"local":"session"),A||Ce(ge,"local"),c(A)},e[21]=a,e[22]=c,e[23]=L):L=e[23];const _=L;let $;e[24]===Symbol.for("react.memo_cache_sentinel")?($=A=>{g(A.target.value)},e[24]=$):$=e[24];const F=$;let B;e[25]!==l?(B=(A,D,z)=>{l(j=>j.map(K=>K.id===A?{id:K.id,name:D,sql:K.sql,...z===""?{}:{description:z}}:K))},e[25]=l,e[26]=B):B=e[26];const H=B;let P;e[27]!==l?(P=(A,D)=>{l(z=>z.map(j=>j.id===A?{...j,sql:D}:j))},e[27]=l,e[28]=P):P=e[28];const Q=P;let M;return e[29]!==k||e[30]!==C||e[31]!==a||e[32]!==T||e[33]!==I||e[34]!==N||e[35]!==n||e[36]!==S||e[37]!==i||e[38]!==H||e[39]!==h||e[40]!==b||e[41]!==_||e[42]!==Q?(M={clearHistory:k,deleteQuery:C,history:a,listRef:R,loadFromHistory:T,loadTemplate:I,newQuery:N,onSearchChange:F,queries:n,recordHistory:S,rememberHistory:i,renameQuery:H,search:h,selectQuery:b,setRememberHistory:_,updateQuerySql:Q},e[29]=k,e[30]=C,e[31]=a,e[32]=T,e[33]=I,e[34]=N,e[35]=n,e[36]=S,e[37]=i,e[38]=H,e[39]=h,e[40]=b,e[41]=_,e[42]=Q,e[43]=M):M=e[43],M},We="p-3 font-mono text-xs leading-5 whitespace-pre-wrap break-words",jn=(r,e)=>{const s=[];for(const o of r){if(o.offset===void 0||o.length===void 0||o.length<=0)continue;const n=Math.max(0,Math.min(o.offset,e)),l=Math.max(n,Math.min(o.offset+o.length,e));n!==l&&s.push({end:l,severity:o.severity,start:n})}s.sort((o,n)=>o.start-n.start);const t=[];for(const o of s)o.start>=(t.at(-1)?.end??0)&&t.push(o);return t},zn=r=>{const e=G(51),{rpc:s,failed:t,onGenerated:o}=r,n=Z(),[l,i]=te("");if(s.unavailable)return null;let c;e[0]!==s?(c=s.pending("sql"),e[0]=s,e[1]=c):c=e[1];const a=c;let d;if(e[2]!==t||e[3]!==o||e[4]!==a||e[5]!==l||e[6]!==s||e[7]!==n){const m=s.reason("sql");let f;e[9]!==t||e[10]!==o||e[11]!==l||e[12]!==s?(f=T=>{const E=l.trim();if(E===""&&!T)return;ie((async()=>{const L=await s.generate(E===""?"fix the failing statement":E,T?t:void 0);L!==void 0&&o(L)})())},e[9]=t,e[10]=o,e[11]=l,e[12]=s,e[13]=f):f=e[13];const h=f;let g;e[14]!==n?(g=n("Describe the query you want"),e[14]=n,e[15]=g):g=e[15];let R;e[16]===Symbol.for("react.memo_cache_sentinel")?(R=T=>{i(T.target.value)},e[16]=R):R=e[16];let v;e[17]!==h?(v=T=>{T.key==="Enter"&&(T.preventDefault(),h(!1))},e[17]=h,e[18]=v):v=e[18];let S;e[19]!==n?(S=n("Describe the query you want"),e[19]=n,e[20]=S):S=e[20];let p;e[21]!==a||e[22]!==l||e[23]!==g||e[24]!==v||e[25]!==S?(p=u(Re,{"aria-label":g,className:"h-7 flex-1 text-xs","data-testid":"sql-assistant-prompt",disabled:a,onChange:R,onKeyDown:v,placeholder:S,value:l}),e[21]=a,e[22]=l,e[23]=g,e[24]=v,e[25]=S,e[26]=p):p=e[26];const N=a&&"opacity-60";let x;e[27]!==N?(x=ae("rounded-md border border-border px-2 py-1 text-xs outline-none transition-colors hover:bg-accent focus-visible:bg-accent",N),e[27]=N,e[28]=x):x=e[28];let b;e[29]!==a||e[30]!==l?(b=a||l.trim()==="",e[29]=a,e[30]=l,e[31]=b):b=e[31];let y;e[32]!==h?(y=()=>{h(!1)},e[32]=h,e[33]=y):y=e[33];let C;e[34]!==a||e[35]!==n?(C=n(a?"Thinking…":"Draft SQL"),e[34]=a,e[35]=n,e[36]=C):C=e[36];let w;e[37]!==x||e[38]!==b||e[39]!==y||e[40]!==C?(w=u("button",{className:x,"data-testid":"sql-assistant-generate",disabled:b,onClick:y,type:"button",children:C}),e[37]=x,e[38]=b,e[39]=y,e[40]=C,e[41]=w):w=e[41];let I;e[42]!==t||e[43]!==a||e[44]!==h||e[45]!==n?(I=t!==void 0&&u("button",{className:"rounded-md border border-border px-2 py-1 text-xs outline-none transition-colors hover:bg-accent focus-visible:bg-accent","data-testid":"sql-assistant-fix",disabled:a,onClick:()=>{h(!0)},type:"button",children:n("Fix this")}),e[42]=t,e[43]=a,e[44]=h,e[45]=n,e[46]=I):I=e[46];let q;e[47]!==w||e[48]!==I||e[49]!==p?(q=W("div",{className:"flex items-center gap-2",children:[p,w,I]}),e[47]=w,e[48]=I,e[49]=p,e[50]=q):q=e[50],d=W("div",{className:"flex flex-col gap-1 border-b border-border px-3 py-2","data-testid":"sql-assistant",children:[q,m!==void 0&&u("p",{className:"text-[11px] text-muted-foreground","data-testid":"sql-assistant-reason",role:"status",children:Ve(m,n)})]}),e[2]=t,e[3]=o,e[4]=a,e[5]=l,e[6]=s,e[7]=n,e[8]=d}else d=e[8];return d},Kn=r=>{const e=G(8),{diagnostics:s,draft:t,scrollRef:o}=r;let n,l;if(e[0]!==s||e[1]!==t){l=Symbol.for("react.early_return_sentinel");e:{const a=jn(s,t.length);if(a.length===0){l=null;break e}n=[];let d=0;for(const[m,f]of a.entries())f.start>d&&n.push(t.slice(d,f.start)),n.push(u("span",{className:ae("decoration-wavy underline underline-offset-4",f.severity==="error"?"decoration-destructive":"decoration-amber-500"),children:t.slice(f.start,f.end)},`${f.start.toString()}-${m.toString()}`)),d=f.end;n.push(t.slice(d))}e[0]=s,e[1]=t,e[2]=n,e[3]=l}else n=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=ae("pointer-events-none absolute inset-0 overflow-hidden text-transparent",We),e[4]=i):i=e[4];let c;return e[5]!==n||e[6]!==o?(c=u("div",{"aria-hidden":"true",className:i,"data-testid":"sql-diagnostics-overlay",ref:o,children:n}),e[5]=n,e[6]=o,e[7]=c):c=e[7],c},Un={gate:"read-only",plan:"plan",schema:"schema",syntax:"syntax"},Yn=r=>{const e=G(10),{diagnostics:s,onSelect:t}=r,o=Z();if(s.length===0)return null;let n;e[0]!==o?(n=o("SQL problems"),e[0]=o,e[1]=n):n=e[1];let l;if(e[2]!==s||e[3]!==t){let c;e[5]!==t?(c=(a,d)=>u("li",{children:W("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:()=>{t(a)},type:"button",children:[u("span",{className:ae("mt-px shrink-0 rounded px-1 font-mono text-[10px] uppercase",a.severity==="error"?"bg-destructive/15 text-destructive":"bg-amber-500/15 text-amber-600"),children:Un[a.source]}),u("span",{className:"min-w-0 text-muted-foreground",children:a.message})]})},`${a.source}-${(a.offset??d).toString()}-${d.toString()}`),e[5]=t,e[6]=c):c=e[6],l=s.map(c),e[2]=s,e[3]=t,e[4]=l}else l=e[4];let i;return e[7]!==n||e[8]!==l?(i=u("ul",{"aria-label":n,className:"max-h-24 shrink-0 overflow-y-auto border-t border-border bg-muted/30","data-testid":"sql-problems",children:l}),e[7]=n,e[8]=l,e[9]=i):i=e[9],i},Gn=r=>(r.endsWith(`
|
|
7
|
-
`)?r.slice(0,-1):r).split(`
|
|
8
|
-
`)
|
|
9
|
-
`).length;I="flex min-h-0 min-w-0 flex-1 flex-col",e[17]!==l||e[18]!==g||e[19]!==s?(q=u(zn,{failed:l,onGenerated:g,rpc:s}),e[17]=l,e[18]=g,e[19]=s,e[20]=q):q=e[20],e[21]!==n.length||e[22]!==d||e[23]!==f||e[24]!==h||e[25]!==s?(T=d!==null&&u(es,{onAccept:f,onCancel:h,rpc:s,source:d.text,whole:d.start===0&&d.end===n.length},`${d.start.toString()}-${d.end.toString()}`),e[21]=n.length,e[22]=d,e[23]=f,e[24]=h,e[25]=s,e[26]=T):T=e[26],w="flex min-h-0 min-w-0 flex-1",N="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",b=a,y=ts,C=Array.from({length:D},ss),e[0]=n,e[1]=l,e[2]=a,e[3]=d,e[4]=f,e[5]=h,e[6]=g,e[7]=s,e[8]=N,e[9]=x,e[10]=b,e[11]=y,e[12]=C,e[13]=w,e[14]=I,e[15]=q,e[16]=T}else N=e[8],x=e[9],b=e[10],y=e[11],C=e[12],w=e[13],I=e[14],q=e[15],T=e[16];let E;e[27]!==N||e[28]!==x||e[29]!==b||e[30]!==y||e[31]!==C?(E=u("div",{"aria-hidden":N,className:x,ref:b,style:y,children:C}),e[27]=N,e[28]=x,e[29]=b,e[30]=y,e[31]=C,e[32]=E):E=e[32];let k;e[33]!==o||e[34]!==n||e[35]!==S?(k=u(Kn,{diagnostics:o,draft:n,scrollRef:S}),e[33]=o,e[34]=n,e[35]=S,e[36]=k):k=e[36];let L;e[37]!==t||e[38]!==m?(L=t===null?void 0:`${m}-opt-${t.active.toString()}`,e[37]=t,e[38]=m,e[39]=L):L=e[39];const _=t===null?void 0:m,$=t!==null;let F;e[40]!==p?(F=p("SQL query"),e[40]=p,e[41]=F):F=e[41];let B;e[42]!==n||e[43]!==c||e[44]!==i.onBlur||e[45]!==i.onChange||e[46]!==i.onKeyDown||e[47]!==i.onScroll||e[48]!==i.onSelect||e[49]!==L||e[50]!==_||e[51]!==$||e[52]!==F?(B=u("textarea",{"aria-activedescendant":L,"aria-autocomplete":"list","aria-controls":_,"aria-expanded":$,"aria-label":F,className:`relative size-full resize-none bg-transparent outline-none ${We}`,"data-testid":"sql-input",onBlur:i.onBlur,onChange:i.onChange,onKeyDown:i.onKeyDown,onScroll:i.onScroll,onSelect:i.onSelect,placeholder:"SELECT * FROM …",ref:c,role:"combobox",spellCheck:!1,value:n}),e[42]=n,e[43]=c,e[44]=i.onBlur,e[45]=i.onChange,e[46]=i.onKeyDown,e[47]=i.onScroll,e[48]=i.onSelect,e[49]=L,e[50]=_,e[51]=$,e[52]=F,e[53]=B):B=e[53];let H;e[54]!==t||e[55]!==m||e[56]!==R?(H=u(vn,{listboxId:m,onPick:R,state:t}),e[54]=t,e[55]=m,e[56]=R,e[57]=H):H=e[57];let P;e[58]!==k||e[59]!==B||e[60]!==H?(P=W("div",{className:"relative min-w-0 flex-1 bg-background",children:[k,B,H]}),e[58]=k,e[59]=B,e[60]=H,e[61]=P):P=e[61];let Q;e[62]!==E||e[63]!==P||e[64]!==w?(Q=W("div",{className:w,children:[E,P]}),e[62]=E,e[63]=P,e[64]=w,e[65]=Q):Q=e[65];let M;e[66]!==o||e[67]!==v?(M=u(Yn,{diagnostics:o,onSelect:v}),e[66]=o,e[67]=v,e[68]=M):M=e[68];let A;return e[69]!==Q||e[70]!==M||e[71]!==I||e[72]!==q||e[73]!==T?(A=W("div",{className:I,children:[q,T,Q,M]}),e[69]=Q,e[70]=M,e[71]=I,e[72]=q,e[73]=T,e[74]=A):A=e[74],A};function ss(r,e){return u("div",{children:e+1},e)}const os=r=>{const e=G(62),{onCancel:s,onSave:t,query:o,rpc:n}=r,l=Z(),[i,c]=te(o.name),[a,d]=te(o.description??"");let m;e[0]!==o.sql||e[1]!==n?(m=n!==void 0&&!n.unavailable&&o.sql.trim()!=="",e[0]=o.sql,e[1]=n,e[2]=m):m=e[2];const f=m;let h;e[3]!==n?(h=n?.pending("name"),e[3]=n,e[4]=h):h=e[4];const g=h===!0;let R;e[5]!==n?(R=n?.reason("name"),e[5]=n,e[6]=R):R=e[6];const v=R;let S;e[7]!==a||e[8]!==i||e[9]!==o.sql||e[10]!==n?(S=()=>{if(n===void 0)return;const M=i,A=a;ie((async()=>{const z=await n.nameQuery(o.sql);z!==void 0&&(c(j=>j===M?z.title:j),d(j=>j===A?z.description:j))})())},e[7]=a,e[8]=i,e[9]=o.sql,e[10]=n,e[11]=S):S=e[11];const p=S;let N;e[12]!==a||e[13]!==i||e[14]!==t?(N=M=>{M.preventDefault();const A=i.trim();A!==""&&t(A,a.trim())},e[12]=a,e[13]=i,e[14]=t,e[15]=N):N=e[15];const x=N,b=`sql-query-rename-${o.id}`;let y;e[16]!==l?(y=l("Query name"),e[16]=l,e[17]=y):y=e[17];let C;e[18]===Symbol.for("react.memo_cache_sentinel")?(C=M=>{c(M.target.value)},e[18]=C):C=e[18];let w;e[19]!==l?(w=l("Query name"),e[19]=l,e[20]=w):w=e[20];let I;e[21]!==i||e[22]!==y||e[23]!==w?(I=u(Re,{"aria-label":y,autoFocus:!0,className:"h-7 text-xs","data-testid":"sql-query-name",onChange:C,placeholder:w,value:i}),e[21]=i,e[22]=y,e[23]=w,e[24]=I):I=e[24];let q;e[25]!==l?(q=l("Query description"),e[25]=l,e[26]=q):q=e[26];let T;e[27]===Symbol.for("react.memo_cache_sentinel")?(T=M=>{d(M.target.value)},e[27]=T):T=e[27];let E;e[28]!==l?(E=l("Query description"),e[28]=l,e[29]=E):E=e[29];let k;e[30]!==a||e[31]!==q||e[32]!==E?(k=u(Re,{"aria-label":q,className:"h-7 text-xs","data-testid":"sql-query-description",onChange:T,placeholder:E,value:a}),e[30]=a,e[31]=q,e[32]=E,e[33]=k):k=e[33];let L;e[34]!==l?(L=l("Save"),e[34]=l,e[35]=L):L=e[35];let _;e[36]!==L?(_=u("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:L}),e[36]=L,e[37]=_):_=e[37];let $;e[38]!==l?($=l("Cancel"),e[38]=l,e[39]=$):$=e[39];let F;e[40]!==s||e[41]!==$?(F=u("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:s,type:"button",children:$}),e[40]=s,e[41]=$,e[42]=F):F=e[42];let B;e[43]!==f||e[44]!==g||e[45]!==p||e[46]!==l?(B=f&&u("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:p,type:"button",children:l(g?"Thinking…":"Suggest")}),e[43]=f,e[44]=g,e[45]=p,e[46]=l,e[47]=B):B=e[47];let H;e[48]!==_||e[49]!==F||e[50]!==B?(H=W("div",{className:"flex items-center gap-1",children:[_,F,B]}),e[48]=_,e[49]=F,e[50]=B,e[51]=H):H=e[51];let P;e[52]!==v||e[53]!==l?(P=v!==void 0&&u("p",{className:"text-[11px] text-muted-foreground","data-testid":"sql-query-name-reason",role:"status",children:l(v==="ai-error"?"The model could not be reached.":"The model returned nothing usable.")}),e[52]=v,e[53]=l,e[54]=P):P=e[54];let Q;return e[55]!==x||e[56]!==I||e[57]!==k||e[58]!==H||e[59]!==P||e[60]!==b?(Q=W("form",{className:"flex flex-col gap-1 rounded-md bg-sidebar-accent p-1.5","data-testid":b,onSubmit:x,children:[I,k,H,P]}),e[55]=x,e[56]=I,e[57]=k,e[58]=H,e[59]=P,e[60]=b,e[61]=Q):Q=e[61],Q},it=[{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;"}],ls=r=>{const e=G(44),{active:s,onDelete:t,onRename:o,onSelect:n,query:l}=r,i=Z();let c;e[0]!==n||e[1]!==l.id?(c=()=>{n(l.id)},e[0]=n,e[1]=l.id,e[2]=c):c=e[2];const a=c;let d;e[3]!==t||e[4]!==l.id?(d=L=>{L.stopPropagation(),t(l.id)},e[3]=t,e[4]=l.id,e[5]=d):d=e[5];const m=d;let f;e[6]!==o||e[7]!==l.id?(f=L=>{L.stopPropagation(),o(l.id)},e[6]=o,e[7]=l.id,e[8]=f):f=e[8];const h=f,g=s?"bg-sidebar-accent font-medium text-foreground":"text-muted-foreground";let R;e[9]!==g?(R=ae("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]=R):R=e[10];const v=`sql-query-${l.id}`;let S;e[11]===Symbol.for("react.memo_cache_sentinel")?(S=u("svg",{"aria-hidden":"true",className:"size-3.5 shrink-0 opacity-70",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:u("path",{d:"M4 6h16M4 12h10M4 18h7"})}),e[11]=S):S=e[11];let p;e[12]!==l.name?(p=u("span",{className:"truncate",children:l.name}),e[12]=l.name,e[13]=p):p=e[13];let N;e[14]!==s||e[15]!==a||e[16]!==l.description||e[17]!==R||e[18]!==v||e[19]!==p?(N=W("button",{"aria-pressed":s,className:R,"data-testid":v,onClick:a,title:l.description,type:"button",children:[S,p]}),e[14]=s,e[15]=a,e[16]=l.description,e[17]=R,e[18]=v,e[19]=p,e[20]=N):N=e[20];let x;e[21]!==i?(x=i("Rename query"),e[21]=i,e[22]=x):x=e[22];const b=`sql-query-rename-open-${l.id}`;let y;e[23]!==i?(y=i("Rename query"),e[23]=i,e[24]=y):y=e[24];let C;e[25]===Symbol.for("react.memo_cache_sentinel")?(C=u("svg",{"aria-hidden":"true",className:"size-3.5",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:u("path",{d:"M4 20h4L19 9l-4-4L4 16zM14 6l4 4"})}),e[25]=C):C=e[25];let w;e[26]!==h||e[27]!==x||e[28]!==b||e[29]!==y?(w=u("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":b,onClick:h,title:y,type:"button",children:C}),e[26]=h,e[27]=x,e[28]=b,e[29]=y,e[30]=w):w=e[30];let I;e[31]!==i?(I=i("Delete query"),e[31]=i,e[32]=I):I=e[32];let q;e[33]!==i?(q=i("Delete query"),e[33]=i,e[34]=q):q=e[34];let T;e[35]===Symbol.for("react.memo_cache_sentinel")?(T=u("svg",{"aria-hidden":"true",className:"size-3.5",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:u("path",{d:"M5 7h14M9 7V5h6v2m-1 0v12H10V7M7 7v13h10V7"})}),e[35]=T):T=e[35];let E;e[36]!==m||e[37]!==I||e[38]!==q?(E=u("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:m,title:q,type:"button",children:T}),e[36]=m,e[37]=I,e[38]=q,e[39]=E):E=e[39];let k;return e[40]!==w||e[41]!==E||e[42]!==N?(k=W("li",{className:"group/q flex items-center",children:[N,w,E]}),e[40]=w,e[41]=E,e[42]=N,e[43]=k):k=e[43],k},Ue="sql-history-remember",rs=(r,e)=>{const s=e.trim().toLowerCase();return s===""?[...r]:r.filter(t=>t.name.toLowerCase().includes(s))},is=r=>{const e=G(53),{activeId:s,history:t,listRef:o,onClearHistory:n,onDelete:l,onLoadHistory:i,onLoadTemplate:c,onNew:a,onRename:d,onSearchChange:m,onSelect:f,onToggleRememberHistory:h,queries:g,rememberHistory:R,rpc:v,search:S}=r,p=Z(),N=rs(g,S),[x,b]=te(null);let y;e[0]===Symbol.for("react.memo_cache_sentinel")?(y=()=>{b(null)},e[0]=y):y=e[0];const C=y;let w;e[1]!==h?(w=Y=>{h(Y.target.checked)},e[1]=h,e[2]=w):w=e[2];const I=w,q="flex h-full w-64 shrink-0 flex-col border-e border-border bg-sidebar";let T;e[3]!==p?(T=p("Search queries…"),e[3]=p,e[4]=T):T=e[4];let E;e[5]!==m||e[6]!==S||e[7]!==T?(E=u("input",{className:"h-8 min-w-0 flex-1 rounded-md border border-border bg-background px-2 text-xs outline-none focus-visible:border-ring","data-testid":"sql-search",onChange:m,placeholder:T,type:"text",value:S}),e[5]=m,e[6]=S,e[7]=T,e[8]=E):E=e[8];let k;e[9]!==p?(k=p("New query"),e[9]=p,e[10]=k):k=e[10];let L;e[11]!==p?(L=p("New query"),e[11]=p,e[12]=L):L=e[12];let _;e[13]===Symbol.for("react.memo_cache_sentinel")?(_=u("svg",{"aria-hidden":"true",className:"size-4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.7,viewBox:"0 0 24 24",children:u("path",{d:"M12 5v14M5 12h14"})}),e[13]=_):_=e[13];let $;e[14]!==a||e[15]!==k||e[16]!==L?($=u("button",{"aria-label":k,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:a,title:L,type:"button",children:_}),e[14]=a,e[15]=k,e[16]=L,e[17]=$):$=e[17];let F;e[18]!==E||e[19]!==$?(F=W("div",{className:"flex shrink-0 items-center gap-2 border-b border-border p-2",children:[E,$]}),e[18]=E,e[19]=$,e[20]=F):F=e[20];const B="flex flex-1 flex-col gap-4 overflow-y-auto p-2";let H;e[21]!==p?(H=p("Private"),e[21]=p,e[22]=H):H=e[22];let P;e[23]!==H?(P=u("p",{className:"px-1 pb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:H}),e[23]=H,e[24]=P):P=e[24];const Q=N.length===0?u("p",{className:"px-1 py-2 text-xs text-muted-foreground","data-testid":"sql-private-empty",children:p("No saved queries yet — they save to this browser as you type.")}):u("ul",{className:"flex flex-col gap-px","data-testid":"sql-private",ref:o,children:N.map(Y=>x===Y.id?u("li",{children:u(os,{onCancel:C,onSave:(oe,re)=>{d(Y.id,oe,re),C()},query:Y,rpc:v})},Y.id):u(ls,{active:s===Y.id,onDelete:l,onRename:b,onSelect:f,query:Y},Y.id))});let M;e[25]!==P||e[26]!==Q?(M=W("div",{children:[P,Q]}),e[25]=P,e[26]=Q,e[27]=M):M=e[27];let A;e[28]!==p?(A=p("Reference"),e[28]=p,e[29]=A):A=e[29];let D;e[30]!==A?(D=u("p",{className:"px-1 pb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:A}),e[30]=A,e[31]=D):D=e[31];let z;e[32]!==c?(z=it.map(Y=>u("li",{children:W("button",{className:"flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-start text-[13px] text-muted-foreground outline-none transition-colors hover:bg-sidebar-accent hover:text-foreground focus-visible:bg-sidebar-accent","data-sql":Y.sql,onClick:c,type:"button",children:[u("svg",{"aria-hidden":"true",className:"size-3.5 shrink-0 opacity-70",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:u("path",{d:"M7 4h7l4 4v12H7zM14 4v4h4"})}),Y.label]})},Y.label)),e[32]=c,e[33]=z):z=e[33];let j;e[34]!==z?(j=u("ul",{className:"flex flex-col gap-px",children:z}),e[34]=z,e[35]=j):j=e[35];let K;e[36]!==D||e[37]!==j?(K=W("div",{children:[D,j]}),e[36]=D,e[37]=j,e[38]=K):K=e[38];let O;e[39]!==t||e[40]!==n||e[41]!==i||e[42]!==I||e[43]!==R||e[44]!==p?(O=t.length>0&&W("div",{children:[W("div",{className:"flex items-center justify-between px-1 pb-1",children:[u("p",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:p("History")}),u("button",{className:"rounded px-1 text-[11px] text-muted-foreground outline-none transition-colors hover:text-foreground focus-visible:text-foreground","data-testid":"sql-history-clear",onClick:n,type:"button",children:p("Clear history")})]}),W("label",{className:"flex cursor-pointer items-center gap-1.5 px-1 pb-1.5 text-[11px] text-muted-foreground",htmlFor:Ue,children:[u("input",{checked:R,"data-testid":"sql-history-remember",id:Ue,onChange:I,type:"checkbox"}),p("Keep history on this browser")]}),u("ul",{className:"flex flex-col gap-px","data-testid":"sql-history",children:t.map(Y=>u("li",{children:W("button",{className:"flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-start text-[13px] text-muted-foreground outline-none transition-colors hover:bg-sidebar-accent hover:text-foreground focus-visible:bg-sidebar-accent","data-sql":Y.sql,"data-testid":"sql-history-item",onClick:i,title:Y.sql,type:"button",children:[u("svg",{"aria-hidden":"true",className:"size-3.5 shrink-0 opacity-70",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:u("path",{d:"M12 8v4l3 2M12 21a9 9 0 1 1 0-18 9 9 0 0 1 0 18Z"})}),u("span",{className:"truncate font-mono",children:Y.sql})]})},`${Y.at.toString()}:${Y.sql}`))})]}),e[39]=t,e[40]=n,e[41]=i,e[42]=I,e[43]=R,e[44]=p,e[45]=O):O=e[45];let U;e[46]!==M||e[47]!==K||e[48]!==O?(U=W("div",{className:B,children:[M,K,O]}),e[46]=M,e[47]=K,e[48]=O,e[49]=U):U=e[49];let X;return e[50]!==F||e[51]!==U?(X=W("aside",{className:q,children:[F,U]}),e[50]=F,e[51]=U,e[52]=X):X=e[52],X},Ee=r=>`border-b-2 px-3 py-2 text-sm outline-none transition-colors ${r?"border-foreground font-medium text-foreground":"border-transparent text-muted-foreground hover:text-foreground"}`,as=r=>{const e=G(16),{chatOpen:s,onToggle:t}=r,o=Z();let n;e[0]!==o?(n=o("Ask about your data"),e[0]=o,e[1]=n):n=e[1];const 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 ${s?"bg-accent text-foreground":"text-muted-foreground"}`;let i;e[2]!==o?(i=o("Ask about your data"),e[2]=o,e[3]=i):i=e[3];let c;e[4]===Symbol.for("react.memo_cache_sentinel")?(c=u("svg",{"aria-hidden":"true",className:"size-4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:u("path",{d:"M21 12a8 8 0 0 1-8 8H7l-4 3 1.2-4.2A8 8 0 1 1 21 12Z"})}),e[4]=c):c=e[4];let a;e[5]!==o?(a=o("Assistant"),e[5]=o,e[6]=a):a=e[6];let d;e[7]!==a?(d=u("span",{className:"text-xs",children:a}),e[7]=a,e[8]=d):d=e[8];let m;return e[9]!==s||e[10]!==t||e[11]!==n||e[12]!==l||e[13]!==i||e[14]!==d?(m=W("button",{"aria-label":n,"aria-pressed":s,className:l,"data-testid":"sql-chat-toggle",onClick:t,title:i,type:"button",children:[c,d]}),e[9]=s,e[10]=t,e[11]=n,e[12]=l,e[13]=i,e[14]=d,e[15]=m):m=e[15],m},cs=r=>{const e=G(11),{onToggle:s,splitView:t}=r,o=Z();let n;e[0]!==o?(n=o("Split editor and results"),e[0]=o,e[1]=n):n=e[1];const 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"}`;let i;e[2]!==o?(i=o("Split editor and results"),e[2]=o,e[3]=i):i=e[3];let c;e[4]===Symbol.for("react.memo_cache_sentinel")?(c=W("svg",{"aria-hidden":"true",className:"size-4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.7,viewBox:"0 0 24 24",children:[u("rect",{height:"16",rx:"2",width:"18",x:"3",y:"4"}),u("path",{d:"M12 4v16"})]}),e[4]=c):c=e[4];let a;return e[5]!==s||e[6]!==t||e[7]!==n||e[8]!==l||e[9]!==i?(a=u("button",{"aria-label":n,"aria-pressed":t,className:l,"data-testid":"sql-split-toggle",onClick:s,title:i,type:"button",children:c}),e[5]=s,e[6]=t,e[7]=n,e[8]=l,e[9]=i,e[10]=a):a=e[10],a},ds=r=>{const e=G(8),{disabled:s,onExplainPlan:t,onExplainSql:o,pane:n}=r,l=Z();if(n==="explain"){let c;return e[0]!==s||e[1]!==t||e[2]!==l?(c=t===void 0?null:u("button",{className:"inline-flex items-center rounded-md border border-border px-3 py-1.5 text-xs font-medium text-foreground outline-none transition-colors hover:bg-accent focus-visible:bg-accent disabled:pointer-events-none disabled:opacity-50","data-testid":"sql-explain-plan",disabled:s,onClick:t,type:"button",children:l("Read this plan")}),e[0]=s,e[1]=t,e[2]=l,e[3]=c):c=e[3],c}let i;return e[4]!==s||e[5]!==o||e[6]!==l?(i=o===void 0?null:u("button",{className:"inline-flex items-center rounded-md border border-border px-3 py-1.5 text-xs font-medium text-foreground outline-none transition-colors hover:bg-accent focus-visible:bg-accent disabled:pointer-events-none disabled:opacity-50","data-testid":"sql-explain-query",disabled:s,onClick:o,type:"button",children:l("Explain this query")}),e[4]=s,e[5]=o,e[6]=l,e[7]=i):i=e[7],i},us=r=>{const e=G(8),{onRun:s,running:t}=r,o=Z();let n;e[0]!==t||e[1]!==o?(n=o(t?"Running…":"Run"),e[0]=t,e[1]=o,e[2]=n):n=e[2];let l;e[3]===Symbol.for("react.memo_cache_sentinel")?(l=u("kbd",{className:"rounded border border-primary-foreground/30 px-1 font-sans text-[10px]",children:"⌘↵"}),e[3]=l):l=e[3];let i;return e[4]!==s||e[5]!==t||e[6]!==n?(i=W("button",{className:"inline-flex items-center gap-1.5 rounded-md bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground outline-none transition-colors hover:bg-primary/90 focus-visible:bg-primary/90 disabled:pointer-events-none disabled:opacity-50","data-testid":"sql-run",disabled:t,onClick:s,type:"button",children:[n,l]}),e[4]=s,e[5]=t,e[6]=n,e[7]=i):i=e[7],i},fs=r=>{const e=G(35),{onInferChart:s,onShowChart:t,onShowExplain:o,onShowResults:n,pane:l,result:i,rpc:c}=r,a=Z(),d=l==="results";let m;e[0]!==d?(m=Ee(d),e[0]=d,e[1]=m):m=e[1];let f;e[2]!==a?(f=a("Results"),e[2]=a,e[3]=f):f=e[3];let h;e[4]!==n||e[5]!==m||e[6]!==f?(h=u("button",{className:m,"data-testid":"sql-tab-results",onClick:n,type:"button",children:f}),e[4]=n,e[5]=m,e[6]=f,e[7]=h):h=e[7];const g=l==="chart";let R;e[8]!==g?(R=Ee(g),e[8]=g,e[9]=R):R=e[9];let v;e[10]!==a?(v=a("Chart"),e[10]=a,e[11]=v):v=e[11];let S;e[12]!==t||e[13]!==R||e[14]!==v?(S=u("button",{className:R,"data-testid":"sql-tab-chart",onClick:t,type:"button",children:v}),e[12]=t,e[13]=R,e[14]=v,e[15]=S):S=e[15];let p;e[16]!==s||e[17]!==l||e[18]!==i||e[19]!==c||e[20]!==a?(p=!c.unavailable&&l==="chart"&&i!==null&&u("button",{className:Ee(!1),"data-testid":"sql-infer-chart",disabled:c.pending("chart"),onClick:s,type:"button",children:c.pending("chart")?a("Thinking…"):a("Suggest chart")}),e[16]=s,e[17]=l,e[18]=i,e[19]=c,e[20]=a,e[21]=p):p=e[21];const N=l==="explain";let x;e[22]!==N?(x=Ee(N),e[22]=N,e[23]=x):x=e[23];let b;e[24]!==a?(b=a("Explain"),e[24]=a,e[25]=b):b=e[25];let y;e[26]!==o||e[27]!==x||e[28]!==b?(y=u("button",{className:x,"data-testid":"sql-tab-explain",onClick:o,type:"button",children:b}),e[26]=o,e[27]=x,e[28]=b,e[29]=y):y=e[29];let C;return e[30]!==y||e[31]!==h||e[32]!==S||e[33]!==p?(C=W(xe,{children:[h,S,p,y]}),e[30]=y,e[31]=h,e[32]=S,e[33]=p,e[34]=C):C=e[34],C},ms=r=>{const e=G(9),{onSelectStatement:s,script:t}=r;let o;if(e[0]!==s||e[1]!==t.runs||e[2]!==t.selected){let l;e[4]!==s||e[5]!==t.selected?(l=(i,c)=>u("button",{"aria-pressed":c===t.selected,className:`rounded-md border px-2 py-0.5 font-mono text-[11px] outline-none transition-colors ${c===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-${c.toString()}`,onClick:()=>{s(c)},title:i.sql,type:"button",children:c+1},`${c.toString()}:${i.sql}`),e[4]=s,e[5]=t.selected,e[6]=l):l=e[6],o=t.runs.map(l),e[0]=s,e[1]=t.runs,e[2]=t.selected,e[3]=o}else o=e[3];let n;return e[7]!==o?(n=u("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]=n):n=e[8],n},ps=r=>{const e=G(9),{error:s,onDebugError:t,rpc:o}=r,n=Z();let l;e[0]!==s?(l=u(St,{className:"w-full font-mono text-xs",testId:"sql-error",variant:"destructive",children:s}),e[0]=s,e[1]=l):l=e[1];let i;e[2]!==t||e[3]!==o||e[4]!==n?(i=!o.unavailable&&t!==void 0&&W("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:[u("svg",{"aria-hidden":"true",className:"size-3.5",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:u("path",{d:"M21 12a8 8 0 0 1-8 8H7l-4 3 1.2-4.2A8 8 0 1 1 21 12Z"})}),o.pending("chat")?n("Thinking…"):n("Debug with AI")]}),e[2]=t,e[3]=o,e[4]=n,e[5]=i):i=e[5];let c;return e[6]!==l||e[7]!==i?(c=W("div",{className:"m-3 flex flex-col items-start gap-2",children:[l,i]}),e[6]=l,e[7]=i,e[8]=c):c=e[8],c},hs=r=>{const e=G(18),{chart:s,durationMs:t,pane:o,result:n}=r,l=Z();let i;e[0]!==s||e[1]!==o||e[2]!==n?(i=o==="chart"?u(xt,{axes:s,result:n}):u(vt,{result:n}),e[0]=s,e[1]=o,e[2]=n,e[3]=i):i=e[3];let c;e[4]!==n.rowCount||e[5]!==n.rows||e[6]!==n.truncated||e[7]!==l?(c=n.truncated?l("Showing the first {max} rows.",{max:n.rows.length}):l("{count} rows",{count:n.rowCount}),e[4]=n.rowCount,e[5]=n.rows,e[6]=n.truncated,e[7]=l,e[8]=c):c=e[8];let a;e[9]!==t||e[10]!==l?(a=t!==void 0&&` · ${l("{ms} ms",{ms:Math.round(t)})}`,e[9]=t,e[10]=l,e[11]=a):a=e[11];let d;e[12]!==c||e[13]!==a?(d=W("p",{className:"border-t border-border px-3 py-1.5 text-xs text-muted-foreground","data-testid":"sql-count",children:[c,a]}),e[12]=c,e[13]=a,e[14]=d):d=e[14];let m;return e[15]!==i||e[16]!==d?(m=W("div",{"data-testid":"sql-result",children:[i,d]}),e[15]=i,e[16]=d,e[17]=m):m=e[17],m},bs=r=>{const e=G(13),{chart:s,durationMs:t,error:o,onDebugError:n,pane:l,result:i,rpc:c}=r,a=Z();if(o!==null){let m;return e[0]!==o||e[1]!==n||e[2]!==c?(m=u(ps,{error:o,onDebugError:n,rpc:c}),e[0]=o,e[1]=n,e[2]=c,e[3]=m):m=e[3],m}if(i===null){let m;e[4]!==a?(m=a("Click Run to execute your query."),e[4]=a,e[5]=m):m=e[5];let f;return e[6]!==m?(f=u("p",{className:"p-4 text-sm text-muted-foreground","data-testid":"sql-empty",children:m}),e[6]=m,e[7]=f):f=e[7],f}let d;return e[8]!==s||e[9]!==t||e[10]!==l||e[11]!==i?(d=u(hs,{chart:s,durationMs:t,pane:l,result:i}),e[8]=s,e[9]=t,e[10]=l,e[11]=i,e[12]=d):d=e[12],d},gs=r=>{const e=G(63),{rpc:s,chart:t,className:o,durationMs:n,error:l,onFormat:i,onInferChart:c,onRun:a,onSelectStatement:d,onShardKeyChange:m,onShowChart:f,onShowExplain:h,onShowResults:g,chatOpen:R,onDebugError:v,onExplainPlan:S,onExplainSql:p,onToggleChat:N,onToggleSplit:x,pane:b,result:y,running:C,script:w,shardKey:I,splitView:q}=r,T=Z();let E;e[0]!==c||e[1]!==f||e[2]!==h||e[3]!==g||e[4]!==b||e[5]!==y||e[6]!==s?(E=u(fs,{onInferChart:c,onShowChart:f,onShowExplain:h,onShowResults:g,pane:b,result:y,rpc:s}),e[0]=c,e[1]=f,e[2]=h,e[3]=g,e[4]=b,e[5]=y,e[6]=s,e[7]=E):E=e[7];let k;e[8]!==R||e[9]!==N?(k=N!==void 0&&u(as,{chatOpen:R,onToggle:N}),e[8]=R,e[9]=N,e[10]=k):k=e[10];let L;e[11]!==x||e[12]!==q?(L=u(cs,{onToggle:x,splitView:q}),e[11]=x,e[12]=q,e[13]=L):L=e[13];let _;e[14]!==y?(_=y!==null&&y.columns.length>0&&u(wt,{columns:y.columns,name:"query-result",rows:y.rows}),e[14]=y,e[15]=_):_=e[15];let $;e[16]!==T?($=T("Format"),e[16]=T,e[17]=$):$=e[17];let F;e[18]!==i||e[19]!==C||e[20]!==$?(F=u("button",{className:"inline-flex items-center rounded-md border border-border px-3 py-1.5 text-xs font-medium text-foreground outline-none transition-colors hover:bg-accent focus-visible:bg-accent disabled:pointer-events-none disabled:opacity-50","data-testid":"sql-format",disabled:C,onClick:i,type:"button",children:$}),e[18]=i,e[19]=C,e[20]=$,e[21]=F):F=e[21];let B;e[22]!==s||e[23]!==C?(B=C||s.pending("chat"),e[22]=s,e[23]=C,e[24]=B):B=e[24];let H;e[25]!==S||e[26]!==p||e[27]!==b||e[28]!==B?(H=u(ds,{disabled:B,onExplainPlan:S,onExplainSql:p,pane:b}),e[25]=S,e[26]=p,e[27]=b,e[28]=B,e[29]=H):H=e[29];let P;e[30]!==m||e[31]!==I?(P=u(yt,{onChange:m,testId:"sql-shard-input",value:I}),e[30]=m,e[31]=I,e[32]=P):P=e[32];let Q;e[33]!==a||e[34]!==C?(Q=u(us,{onRun:a,running:C}),e[33]=a,e[34]=C,e[35]=Q):Q=e[35];let M;e[36]!==Q||e[37]!==k||e[38]!==L||e[39]!==_||e[40]!==F||e[41]!==H||e[42]!==P?(M=W("div",{className:"ms-auto flex items-center gap-2",children:[k,L,_,F,H,P,Q]}),e[36]=Q,e[37]=k,e[38]=L,e[39]=_,e[40]=F,e[41]=H,e[42]=P,e[43]=M):M=e[43];let A;e[44]!==E||e[45]!==M?(A=W("div",{className:"flex shrink-0 items-center gap-2 border-b border-border pe-2",children:[E,M]}),e[44]=E,e[45]=M,e[46]=A):A=e[46];let D;e[47]!==d||e[48]!==w?(D=w!==void 0&&u(ms,{onSelectStatement:d,script:w}),e[47]=d,e[48]=w,e[49]=D):D=e[49];let z;e[50]!==t||e[51]!==n||e[52]!==l||e[53]!==v||e[54]!==b||e[55]!==y||e[56]!==s?(z=u("div",{className:"min-h-0 flex-1 overflow-auto",children:u(bs,{chart:t,durationMs:n,error:l,onDebugError:v,pane:b,result:y,rpc:s})}),e[50]=t,e[51]=n,e[52]=l,e[53]=v,e[54]=b,e[55]=y,e[56]=s,e[57]=z):z=e[57];let j;return e[58]!==o||e[59]!==A||e[60]!==D||e[61]!==z?(j=W("div",{className:o,children:[A,D,z]}),e[58]=o,e[59]=A,e[60]=D,e[61]=z,e[62]=j):j=e[62],j},xs=(r,e)=>r.trim()===""?e:(r.split(`
|
|
10
|
-
`)[0]??r).slice(0,24),vs=r=>{r?.focus(),r?.select()},ys=r=>{const e=G(14),{initial:s,onCancel:t,onCommit:o,placeholder:n,testId:l}=r,i=Z();let c;e[0]!==o?(c=g=>{o(g.currentTarget.value.trim())},e[0]=o,e[1]=c):c=e[1];const a=c;let d;e[2]!==t||e[3]!==o?(d=g=>{g.key==="Enter"?o(g.currentTarget.value.trim()):g.key==="Escape"&&t()},e[2]=t,e[3]=o,e[4]=d):d=e[4];const m=d;let f;e[5]!==i?(f=i("Tab title"),e[5]=i,e[6]=f):f=e[6];let h;return e[7]!==s||e[8]!==a||e[9]!==m||e[10]!==n||e[11]!==f||e[12]!==l?(h=u("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:s,onBlur:a,onKeyDown:m,placeholder:n,ref:vs,type:"text"}),e[7]=s,e[8]=a,e[9]=m,e[10]=n,e[11]=f,e[12]=l,e[13]=h):h=e[13],h},Ss=r=>{const e=G(29),{idBase:s,onDiscard:t,onKeep:o}=r,n=Z(),l=`sql-tab-close-prompt-${s}`;let i;e[0]!==n?(i=n("Discard?"),e[0]=n,e[1]=i):i=e[1];let c;e[2]!==i?(c=u("span",{className:"text-[11px] text-muted-foreground",children:i}),e[2]=i,e[3]=c):c=e[3];let a;e[4]!==n?(a=n("Discard changes"),e[4]=n,e[5]=a):a=e[5];const d=`sql-tab-close-confirm-${s}`;let m;e[6]!==n?(m=n("Discard changes"),e[6]=n,e[7]=m):m=e[7];let f;e[8]===Symbol.for("react.memo_cache_sentinel")?(f=u("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2.4,viewBox:"0 0 24 24",children:u("path",{d:"M5 13l4 4L19 7"})}),e[8]=f):f=e[8];let h;e[9]!==t||e[10]!==a||e[11]!==d||e[12]!==m?(h=u("button",{"aria-label":a,className:"flex size-5 items-center justify-center rounded text-destructive hover:bg-destructive/10","data-testid":d,onClick:t,title:m,type:"button",children:f}),e[9]=t,e[10]=a,e[11]=d,e[12]=m,e[13]=h):h=e[13];let g;e[14]!==n?(g=n("Keep editing"),e[14]=n,e[15]=g):g=e[15];const R=`sql-tab-close-cancel-${s}`;let v;e[16]!==n?(v=n("Keep editing"),e[16]=n,e[17]=v):v=e[17];let S;e[18]===Symbol.for("react.memo_cache_sentinel")?(S=u("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2.4,viewBox:"0 0 24 24",children:u("path",{d:"M6 6l12 12M18 6 6 18"})}),e[18]=S):S=e[18];let p;e[19]!==o||e[20]!==R||e[21]!==v||e[22]!==g?(p=u("button",{"aria-label":g,className:"flex size-5 items-center justify-center rounded text-muted-foreground hover:bg-accent","data-testid":R,onClick:o,title:v,type:"button",children:S}),e[19]=o,e[20]=R,e[21]=v,e[22]=g,e[23]=p):p=e[23];let N;return e[24]!==l||e[25]!==p||e[26]!==c||e[27]!==h?(N=W("span",{className:"flex shrink-0 items-center gap-1","data-testid":l,role:"group",children:[c,h,p]}),e[24]=l,e[25]=p,e[26]=c,e[27]=h,e[28]=N):N=e[28],N},ws=r=>{const e=G(47),{active:s,canClose:t,onClose:o,onMenu:n,onRename:l,onSelect:i,tab:c}=r,a=Z(),[d,m]=te(!1),[f,h]=te(!1);let g;e[0]!==n||e[1]!==c.id?(g=D=>{n(c.id,D)},e[0]=n,e[1]=c.id,e[2]=g):g=e[2];const R=g;let v;e[3]!==i||e[4]!==c.id?(v=()=>{i(c.id)},e[3]=i,e[4]=c.id,e[5]=v):v=e[5];const S=v;let p;e[6]===Symbol.for("react.memo_cache_sentinel")?(p=()=>{m(!0)},e[6]=p):p=e[6];const N=p;let x;e[7]!==o||e[8]!==c?(x=D=>{D.stopPropagation(),rt(c)?h(!0):o(c.id)},e[7]=o,e[8]=c,e[9]=x):x=e[9];const b=x;let y;e[10]!==o||e[11]!==c.id?(y=D=>{D.stopPropagation(),h(!1),o(c.id)},e[10]=o,e[11]=c.id,e[12]=y):y=e[12];const C=y;let w;e[13]===Symbol.for("react.memo_cache_sentinel")?(w=D=>{D.stopPropagation(),h(!1)},e[13]=w):w=e[13];const I=w;let q;e[14]!==l||e[15]!==c.id?(q=D=>{l(c.id,D),m(!1)},e[14]=l,e[15]=c.id,e[16]=q):q=e[16];const T=q;let E;e[17]===Symbol.for("react.memo_cache_sentinel")?(E=()=>{m(!1)},e[17]=E):E=e[17];const k=E;let L;e[18]!==c.name?(L=c.name.trim(),e[18]=c.name,e[19]=L):L=e[19];const _=L;let $;e[20]!==a||e[21]!==c.sql?($=xs(c.sql,a("Untitled")),e[20]=a,e[21]=c.sql,e[22]=$):$=e[22];const F=$,B=s?"bg-background text-foreground":"bg-muted/40 text-muted-foreground hover:text-foreground";let H;e[23]!==B?(H=ae("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]=H):H=e[24];const P=`sql-tab-${c.id}`;let Q;e[25]!==s||e[26]!==T||e[27]!==_||e[28]!==F||e[29]!==d||e[30]!==S||e[31]!==a||e[32]!==c.id?(Q=d?u(ys,{initial:_,onCancel:k,onCommit:T,placeholder:F,testId:`sql-tab-rename-${c.id}`}):u("button",{"aria-pressed":s,className:"max-w-40 truncate py-1.5 outline-none","data-testid":`sql-tab-select-${c.id}`,onClick:S,onDoubleClick:N,title:a("Double-click to rename"),type:"button",children:_===""?F:_}),e[25]=s,e[26]=T,e[27]=_,e[28]=F,e[29]=d,e[30]=S,e[31]=a,e[32]=c.id,e[33]=Q):Q=e[33];let M;e[34]!==t||e[35]!==C||e[36]!==f||e[37]!==b||e[38]!==a||e[39]!==c.id?(M=t&&(f?u(Ss,{idBase:c.id,onDiscard:C,onKeep:I}):u("button",{"aria-label":a("Close tab"),className:"flex size-5 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-destructive/10 hover:text-destructive","data-testid":`sql-tab-close-${c.id}`,onClick:b,title:a("Close tab"),type:"button",children:u("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,viewBox:"0 0 24 24",children:u("path",{d:"M6 6l12 12M18 6 6 18"})})})),e[34]=t,e[35]=C,e[36]=f,e[37]=b,e[38]=a,e[39]=c.id,e[40]=M):M=e[40];let A;return e[41]!==R||e[42]!==H||e[43]!==P||e[44]!==Q||e[45]!==M?(A=W("div",{className:H,"data-testid":P,onContextMenu:R,children:[Q,M]}),e[41]=R,e[42]=H,e[43]=P,e[44]=Q,e[45]=M,e[46]=A):A=e[46],A},Cs=r=>{const e=G(43),{model:s,onSelect:t}=r,o=Z(),{activeTab:n,addEditorTab:l,cancelBulk:i,closeEditorTab:c,closeTabMenu:a,confirmBulk:d,menuStyle:m,onBackdropContextMenu:f,onCloseAll:h,onCloseOthers:g,onCloseToRight:R,openTabMenu:v,pendingBulk:S,renameTab:p,tabMenu:N,tabs:x}=s;let b;if(e[0]!==n||e[1]!==c||e[2]!==t||e[3]!==v||e[4]!==p||e[5]!==x){let L;e[7]!==n||e[8]!==c||e[9]!==t||e[10]!==v||e[11]!==p||e[12]!==x.length?(L=_=>u(ws,{active:_.id===n.id,canClose:x.length>1,onClose:c,onMenu:v,onRename:p,onSelect:t,tab:_},_.id),e[7]=n,e[8]=c,e[9]=t,e[10]=v,e[11]=p,e[12]=x.length,e[13]=L):L=e[13],b=x.map(L),e[0]=n,e[1]=c,e[2]=t,e[3]=v,e[4]=p,e[5]=x,e[6]=b}else b=e[6];let y;e[14]!==o?(y=o("New tab"),e[14]=o,e[15]=y):y=e[15];const C=x.length>=Pe;let w;e[16]!==o?(w=o("New tab"),e[16]=o,e[17]=w):w=e[17];let I;e[18]===Symbol.for("react.memo_cache_sentinel")?(I=u("svg",{"aria-hidden":"true",className:"size-4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.7,viewBox:"0 0 24 24",children:u("path",{d:"M12 5v14M5 12h14"})}),e[18]=I):I=e[18];let q;e[19]!==l||e[20]!==y||e[21]!==C||e[22]!==w?(q=u("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:C,onClick:l,title:w,type:"button",children:I}),e[19]=l,e[20]=y,e[21]=C,e[22]=w,e[23]=q):q=e[23];let T;e[24]!==b||e[25]!==q?(T=W("div",{className:"flex shrink-0 items-stretch overflow-x-auto border-b border-border bg-muted/30","data-testid":"sql-tab-strip",role:"tablist",children:[b,q]}),e[24]=b,e[25]=q,e[26]=T):T=e[26];let E;e[27]!==i||e[28]!==a||e[29]!==d||e[30]!==m||e[31]!==f||e[32]!==h||e[33]!==g||e[34]!==R||e[35]!==S||e[36]!==o||e[37]!==N||e[38]!==x?(E=N!==null&&W(xe,{children:[u("div",{className:"fixed inset-0 z-40","data-testid":"sql-tab-menu-backdrop",onClick:a,onContextMenu:f,role:"presentation"}),u("div",{className:"fixed z-50 min-w-44 rounded-md border border-border bg-popover py-1 text-popover-foreground shadow-md","data-testid":"sql-tab-menu",role:"menu",style:m,children:S===null?W(xe,{children:[u("button",{className:"flex w-full items-center px-3 py-1.5 text-start text-xs outline-none hover:bg-accent focus-visible:bg-accent disabled:pointer-events-none disabled:opacity-40","data-testid":"sql-tab-menu-close-others",disabled:x.length<=1,onClick:g,role:"menuitem",type:"button",children:o("Close other tabs")}),u("button",{className:"flex w-full items-center px-3 py-1.5 text-start text-xs outline-none hover:bg-accent focus-visible:bg-accent disabled:pointer-events-none disabled:opacity-40","data-testid":"sql-tab-menu-close-right",disabled:x.findIndex(L=>L.id===N.id)>=x.length-1,onClick:R,role:"menuitem",type:"button",children:o("Close tabs to the right")}),u("button",{className:"flex w-full items-center px-3 py-1.5 text-start text-xs outline-none hover:bg-accent focus-visible:bg-accent","data-testid":"sql-tab-menu-close-all",onClick:h,role:"menuitem",type:"button",children:o("Close all tabs")})]}):W("div",{className:"px-3 py-1.5","data-testid":"sql-tab-menu-confirm",children:[u("p",{className:"pb-1.5 text-xs text-muted-foreground",children:o("Discard unsaved tabs?")}),W("div",{className:"flex items-center gap-1.5",children:[u("button",{className:"rounded px-2 py-1 text-xs font-medium text-destructive outline-none hover:bg-destructive/10 focus-visible:bg-destructive/10","data-testid":"sql-tab-menu-confirm-discard",onClick:d,type:"button",children:o("Discard")}),u("button",{className:"rounded px-2 py-1 text-xs text-muted-foreground outline-none hover:bg-accent focus-visible:bg-accent","data-testid":"sql-tab-menu-confirm-cancel",onClick:i,type:"button",children:o("Cancel")})]})]})})]}),e[27]=i,e[28]=a,e[29]=d,e[30]=m,e[31]=f,e[32]=h,e[33]=g,e[34]=R,e[35]=S,e[36]=o,e[37]=N,e[38]=x,e[39]=E):E=e[39];let k;return e[40]!==T||e[41]!==E?(k=W(xe,{children:[T,E]}),e[40]=T,e[41]=E,e[42]=k):k=e[42],k},ks=Ae(Le.runSql),Ns="lunora-studio-sql-split-view",Es=()=>Se(it[0]?.sql??""),Ts=()=>performance.now(),qs=()=>{const r=G(2);let e;r[0]===Symbol.for("react.memo_cache_sentinel")?(e=new Map,r[0]=e):e=r[0];const s=de(e);let t;return r[1]===Symbol.for("react.memo_cache_sentinel")?(t={advance:o=>{s.current.set(o,(s.current.get(o)??0)+1)},begin:o=>{const n=s.current.get(o)??0;return()=>(s.current.get(o)??0)===n}},r[1]=t):t=r[1],t},Rs=(r,e)=>{const s=r.tables[0];return s===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:s}),e("Is anything wrong with my schema?")]},Te=r=>r.tables.map(e=>({columns:[...r.columns[e]??[]],table:e})),Vs=({initialShardKey:r,now:e=Ts})=>{const s=Me(),t=$n(Es),{activeTab:o,openEditorTab:n,output:l,patchActiveOutput:i,patchActiveTab:c,setActiveTabId:a,unlinkQuery:d}=t,m=qs(),h=Qn({loadIntoActiveTab:(J,le)=>{m.advance(o.id),c({activeId:le,sql:J}),i({chart:void 0,durationMs:void 0,error:null,failed:void 0,result:null,running:!1,script:void 0})},unlinkQuery:d}),{recordHistory:g,updateQuerySql:R}=h,v=o.sql,{activeId:S}=o,{chart:p,error:N,failed:x,result:b,running:y}=l,C=l.pane,[w,I]=te(r??""),[q,T]=$e(Ns,!1),E=Z(),k=dt(),{probe:L,schema:_}=wn(w),$=Ye(J=>{c({sql:J}),S!==null&&R(S,J)},[S,c,R]),F=k?.setHasEditor;ue(()=>{if(F!==void 0)return F(!0),()=>{F(!1)}},[F]);const B=k?.insertRequest,H=k?.takeInsert;ue(()=>{B===void 0||H===void 0||(H(B.id),v.trim()===""&&S===null?$(B.sql):n(B.sql)||c({activeId:null,sql:v.trim()===""?B.sql:`${v.trimEnd()}
|
|
4
|
+
`);return e.join("")},qt="__lunora_admin_tokens__",Pe=new Set([qt,"dbstat","sqlite_dbpage"]),lt="pragma_",It=l=>/[\p{L}_]/u.test(l)||(l.codePointAt(0)??0)>127,At=l=>/[\p{L}\p{N}_$]/u.test(l)||(l.codePointAt(0)??0)>127,Dt=/^pragma_\w+$/u,Ot=l=>Pe.has(l)||Dt.test(l)?l:void 0,Ke=l=>{if(Pe.has(l)||l.startsWith(lt))return l},Ue=(l,e,n)=>{let t="",s=e+1;for(;s<l.length;){const o=l[s];if(o===n){if(n!=="]"&&l[s+1]===n){t+=n,s+=2;continue}return{end:s+1,text:t}}t+=o,s+=1}},Ye={'"':'"',"`":"`","[":"]"},Ae=l=>{const e=l.toLowerCase().replaceAll(/["'`[\]]/gu,"");for(const n of Pe)if(e.includes(n))return n;return/\bpragma_/u.test(e)?lt:void 0},Mt=l=>{let e=0;for(;e<l.length;){const n=l[e];if(/\s/u.test(n))e+=1;else if(n==="-"&&l[e+1]==="-"){const t=l.indexOf(`
|
|
5
|
+
`,e);e=t===-1?l.length:t+1}else if(n==="/"&&l[e+1]==="*"){const t=l.indexOf("*/",e+2);if(t===-1)return Ae(l.slice(e+2));e=t+2}else if(n==="'"){const t=Ue(l,e,"'");if(t===void 0)return Ae(l.slice(e+1));const s=Ot(t.text.trim().toLowerCase());if(s!==void 0)return s;e=t.end}else if(n in Ye){const t=Ue(l,e,Ye[n]);if(t===void 0)return Ae(l.slice(e+1));const s=Ke(t.text.toLowerCase());if(s!==void 0)return s;e=t.end}else if(It(n)){let t=e+1;for(;t<l.length&&At(l[t]);)t+=1;const s=l.slice(e,t).toLowerCase(),o=Ke(s);if(o!==void 0)return o;e=t}else e+=1}},$t=/^(?:explain\s+(?:query\s+plan\s+)?)?(?:select|with)\b/iu,Bt=/\b(?:alter|attach|create|delete|detach|drop|insert|pragma|reindex|truncate|update|vacuum)\b|\breplace\b(?!\s*\()/iu,Pt=/^\w+/u,Wt=/;\s*$/u,Ht=/\s/u,rt=l=>{let e=0;for(;e<l.length;){const n=l[e];if(n!==void 0&&Ht.test(n))e+=1;else if(n==="-"&&l[e+1]==="-")e=nt(l,e);else if(n==="/"&&l[e+1]==="*"){const t=st(l,e);if(t===-1)break;e=t}else break}return e},Ft=l=>{const e=rt(l),n=l.slice(e).trimEnd();if(n==="")return{code:"SQL_EMPTY",message:"the query is empty"};const s=(ot(n)??n).replace(Wt,""),o=n.slice(0,s.length),r=s.indexOf(";");if(r!==-1)return{code:"SQL_MULTIPLE_STATEMENTS",length:1,message:"only a single statement may be run",offset:e+r};const i="the SQL editor is read-only — only SELECT / WITH / EXPLAIN queries are allowed";if(!$t.test(o))return{code:"SQL_NOT_READONLY",length:Pt.exec(o)?.[0].length??1,message:i,offset:e};const c=Bt.exec(o);if(c!==null)return{code:"SQL_NOT_READONLY",length:c[0].length,message:`${i} (\`${c[0].toUpperCase()}\` is not allowed)`,offset:e+c.index};const a=Mt(o);if(a!==void 0)return{code:"SQL_NOT_READONLY",message:`\`${a}\` is reserved framework storage and cannot be queried`}},Qt=/^explain\b/iu,jt=l=>Qt.test(l.slice(rt(l)))?l:`EXPLAIN QUERY PLAN ${l}`,Me=(l,e)=>{const n=l.trim();if(n==="")return[];const t=e+l.indexOf(n),s=Ft(n);return s?.code==="SQL_EMPTY"?[]:[s===void 0?{offset:t,sql:n}:{offset:t,rejection:s,sql:n}]},it=l=>{const e=ot(l);if(e===void 0)return Me(l,0);const n=[];let t=0;for(let s=0;s<=e.length;s+=1)s!==e.length&&e[s]!==";"||(n.push(...Me(l.slice(t,s),t)),t=s+1);return n},zt=["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"],Kt=["FROM","WHERE","ORDER BY","GROUP BY","HAVING","LIMIT","OFFSET","UNION","JOIN","LEFT JOIN","RIGHT JOIN","INNER JOIN","OUTER JOIN","CROSS JOIN"],_e=String.fromCodePoint(0),Ut=new RegExp(`${_e}${String.raw`(\d+)`}${_e}`,"gu"),Yt=zt.map(l=>({pattern:new RegExp(String.raw`\b${l.replaceAll(" ",String.raw`\s+`)}\b`,"giu"),replacement:l})),Gt=Kt.map(l=>({pattern:new RegExp(String.raw`\s+${l.replaceAll(" ",String.raw`\s+`)}\b`,"gu"),replacement:`
|
|
6
|
+
${l}`})),Vt=l=>{const e=[];let t=l.replaceAll(/'(?:[^']|'')*'/gu,s=>(e.push(s),`${_e}${(e.length-1).toString()}${_e}`)).replaceAll(/\s+/gu," ").trim();for(const{pattern:s,replacement:o}of Yt)t=t.replaceAll(s,o);for(const{pattern:s,replacement:o}of Gt)t=t.replaceAll(s,o);return t=t.replaceAll(Ut,(s,o)=>e[Number(o)]??""),t},Jt=/\b(?:from|join)\s+([a-z_][\w$]*)(?:\s+(?:as\s+)?([a-z_][\w$]*))?/giu,Xt=/(?:\bwith\s+(?:recursive\s+)?|,\s*)([a-z_][\w$]*)\s+as\s*\(/giu,Zt=new Set(["cross","full","group","having","inner","join","left","limit","offset","on","order","right","union","using","where","window"]),en=/[^\n]/gu,tn=(l,e)=>{const n=l[e];if(n==="'"){let t=e+1;for(;t<l.length&&l[t]!=="'";)t+=1;return Math.min(t+1,l.length)}if(n==="-"&&l[e+1]==="-"){const t=l.indexOf(`
|
|
7
|
+
`,e);return t===-1?l.length:t}if(n==="/"&&l[e+1]==="*"){const t=l.indexOf("*/",e+2);return t===-1?l.length:t+2}return-1},nn=l=>{let e="",n=0;for(;n<l.length;){const t=tn(l,n);t===-1?(e+=l.slice(n,n+1),n+=1):(e+=l.slice(n,t).replaceAll(en," "),n=t)}return e},sn=l=>{const e=new Set;for(const n of l.matchAll(Xt))e.add((n[1]??"").toLowerCase());return e},on=(l,e)=>{const n=new Map;for(const t of l.matchAll(Jt)){const s=(t[1]??"").toLowerCase(),o=(t[2]??"").toLowerCase();e.has(s)&&(n.set(s,s),o!==""&&!Zt.has(o)&&n.set(o,s))}return n},at=(l,e)=>{const n=nn(l),t=new Set(e.map(s=>s.toLowerCase()));return{ctes:sn(n),masked:n,targets:on(n,t)}},ln=/^(?:__lunora|sqlite_)/iu,rn=/\b(?:from|join)\s+([a-z_][\w$]*)/giu,an=/\b([a-z_][\w$]*)\.([a-z_][\w$]*)/giu,cn=new Set(["cross","full","group","having","inner","join","lateral","left","limit","offset","order","right","select","union","where","window"]),dn=(l,e,n)=>{const t=[];for(const s of l.matchAll(rn)){const o=s[1]??"",r=o.toLowerCase();!e.has(r)&&!n.has(r)&&!cn.has(r)&&!ln.test(o)&&t.push({length:o.length,message:`unknown table \`${o}\``,offset:s.index+s[0].length-o.length,severity:"error",source:"schema"})}return t},un=(l,e,n)=>{const t=[],s=new Map;for(const[o,r]of Object.entries(e.columns))s.set(o.toLowerCase(),new Set(r.map(i=>i.toLowerCase())));for(const o of l.matchAll(an)){const r=(o[1]??"").toLowerCase(),i=o[2]??"",c=n.get(r),a=c===void 0?void 0:s.get(c);a!==void 0&&!a.has(i.toLowerCase())&&t.push({length:i.length,message:`\`${c??""}\` has no column \`${i}\``,offset:o.index+o[0].length-i.length,severity:"error",source:"schema"})}return t},fn=/(?<![\w$."])(?:"([a-z_][\w$]*)"|([a-z_][\w$]*))(?![.(])/giu,mn=/\bas\s+"?([a-z_][\w$]*)"?/giu,pn=(l,e,n,t)=>{const s=[...new Set(n.values())],o=new Map,r=new Set;for(const a of s){for(const d of e.columns[a]??[])r.add(d.toLowerCase());for(const d of e.docFields?.[a]??[])o.set(d.toLowerCase(),d)}if(o.size===0)return[];const i=new Set([...l.matchAll(mn)].map(a=>(a[1]??"").toLowerCase())),c=[];for(const a of l.matchAll(fn)){const d=a[1],m=d??a[2]??"",f=m.toLowerCase(),h=o.get(f);h===void 0||r.has(f)||i.has(f)||t.has(f)||n.has(f)||c.push({length:m.length,message:`\`${h}\` is a \`__doc__\` field, not a column — use \`json_extract(__doc__, '$.${h}')\``,offset:a.index+(d===void 0?0:1),severity:"error",source:"schema"})}return c},hn=(l,e)=>{if(l.trim()==="")return[];const n=it(l),t=new Set(e.tables.map(o=>o.toLowerCase())),s=[];for(const o of n){const{offset:r,rejection:i}=o;if(i!==void 0){s.push({length:i.length,message:i.message,offset:i.offset===void 0?r:r+i.offset,severity:"error",source:"gate"});continue}const{ctes:c,masked:a,targets:d}=at(o.sql,e.tables);s.push(...[...dn(a,t,c),...un(a,e,d),...pn(a,e,d,c)].map(m=>({...m,offset:m.offset===void 0?r:r+m.offset})))}return s},bn=Ie(qe.lintSql),gn=600,xn=(l,e,n)=>{const t=$e(),[s,o]=te([]),r=je(()=>hn(l,e),[l,e]),i=wt(l,gn),a=r.some(f=>f.source==="gate")||i.trim()==="",d=Ze(async f=>{try{const h=await t.query(bn,{sql:i},Re(n));f.cancelled||o(h.diagnostics??[])}catch{f.cancelled||o([])}},[t,i,n]);ue(()=>{if(a){o([]);return}const f={cancelled:!1};return ie(d(f)),()=>{f.cancelled=!0}},[d,a]);const m=i===l;return je(()=>m?[...r,...s]:r,[r,s,m])},Ee=8,vn=["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"],yn=new Set(["AND","BY","HAVING","ON","OR","SELECT","WHERE"]),Sn=/[\w$]/,ct=l=>l!==void 0&&Sn.test(l),dt=l=>{let e=l.length;for(;e>0&&ct(l[e-1]);)e-=1;return l.slice(e)},ut=(l,e)=>{let n=e;for(;n>0&&ct(l[n-1]);)n-=1;return{end:e,start:n,text:l.slice(n,e)}},Ge=(l,e)=>{const n=l.slice(0,e).trimEnd();return n.endsWith(".")||yn.has(dt(n).toUpperCase())},wn=(l,e,n)=>{const t=l.slice(0,e);if(!t.endsWith("."))return;const s=dt(t.slice(0,-1));if(s!=="")return at(l,n).targets.get(s.toLowerCase())??s},We=(l,e)=>l.toLowerCase().startsWith(e.toLowerCase()),Ve=(l,e,n,t)=>{const s=[];for(const o of l)if(We(o,e)&&(s.push(t(o)),s.length>=n))break;return s},Cn=(l,e,n)=>{const t=new Map;for(const[s,o]of Object.entries(l.columns))for(const r of o)if(We(r,e)&&!t.has(r)&&(t.set(r,s),t.size>=n))return[...t].map(([i,c])=>({detail:c,kind:"column",label:i}));return[...t].map(([s,o])=>({detail:o,kind:"column",label:s}))},En=(l,e,n)=>{const t=ut(l,e),s=wn(l,t.start,n.tables);if(s!==void 0){const a=n.columns[s]??n.columns[s.toLowerCase()]??[];return Ve(a,t.text,Ee,d=>({detail:s,kind:"column",label:d}))}if(t.text===""&&!Ge(l,t.start))return[];const o=Ve(n.tables,t.text,Ee,a=>({kind:"table",label:a})),r=Cn(n,t.text,Ee),i=vn.flatMap(a=>t.text!==""&&We(a,t.text)&&a.toLowerCase()!==t.text.toLowerCase()?[{kind:"keyword",label:a}]:[]);return(Ge(l,t.start)?[...r,...o,...i]:[...o,...r,...i]).slice(0,Ee)},Nn=(l,e,n)=>{const t=ut(l,e),s=l.slice(0,t.start)+n.label+l.slice(t.end);return{caret:t.start+n.label.length,value:s}},kn=["boxSizing","borderBottomWidth","borderLeftWidth","borderRightWidth","borderTopWidth","fontFamily","fontSize","fontStyle","fontWeight","letterSpacing","lineHeight","paddingBottom","paddingLeft","paddingRight","paddingTop","tabSize","textIndent","textTransform","width","wordSpacing"],Tn=(l,e)=>{const n=globalThis.getComputedStyle(l),t=globalThis.document.createElement("div"),{style:s}=t;s.position="absolute",s.visibility="hidden",s.whiteSpace="pre-wrap",s.overflowWrap="break-word";for(const c of kn)s[c]=n[c];t.textContent=l.value.slice(0,Math.max(0,e));const o=globalThis.document.createElement("span");o.textContent=l.value.slice(Math.max(0,e))||".",t.append(o),globalThis.document.body.append(t);const r=o.offsetLeft-l.scrollLeft,i=o.offsetTop-l.scrollTop;return t.remove(),{left:r,top:i}},Rn=(l,e,n)=>{const t=G(16),[s,o]=te(null);let r;t[0]!==l||t[1]!==e?(r=(S,p)=>{const N=En(S,p,l);if(N.length===0){o(null);return}const x=e.current,{left:b,top:y}=x===null?{left:0,top:0}:Tn(x,p);o(C=>C!==null&&C.active===0&&C.left===b&&C.top===y&&C.suggestions.length===N.length&&C.suggestions.every((_,R)=>{const T=N.at(R);return _.kind===T?.kind&&_.label===T.label&&_.detail===T.detail})?C:{active:0,left:b,suggestions:N,top:y})},t[0]=l,t[1]=e,t[2]=r):r=t[2];const i=r;let c;t[3]===Symbol.for("react.memo_cache_sentinel")?(c=()=>{o(null)},t[3]=c):c=t[3];const a=c;let d;t[4]===Symbol.for("react.memo_cache_sentinel")?(d=S=>{o(p=>{if(p===null)return p;const N=p.suggestions.length,x=(p.active+S+N)%N;return{...p,active:x}})},t[4]=d):d=t[4];const m=d;let f;t[5]!==n||t[6]!==s||t[7]!==e?(f=S=>{const p=e.current;if(s===null||p===null)return!1;const N=s.suggestions[S??s.active];if(N===void 0)return!1;const x=Nn(p.value,p.selectionStart,N);return n(x.value),o(null),requestAnimationFrame(()=>{const b=e.current;b!==null&&(b.focus(),b.setSelectionRange(x.caret,x.caret))}),!0},t[5]=n,t[6]=s,t[7]=e,t[8]=f):f=t[8];const h=f;let g;t[9]!==h?(g=()=>h(),t[9]=h,t[10]=g):g=t[10];const L=g;let v;return t[11]!==L||t[12]!==h||t[13]!==i||t[14]!==s?(v={close:a,commit:L,commitAt:h,move:m,refresh:i,state:s},t[11]=L,t[12]=h,t[13]=i,t[14]=s,t[15]=v):v=t[15],v},Ln={column:"column",keyword:"keyword",table:"table"},_n=20,qn=l=>{const e=G(17),{listboxId:n,onPick:t,state:s}=l,o=Z();let r;e[0]!==s?(r=s===null?void 0:{left:s.left,top:s.top+_n},e[0]=s,e[1]=r):r=e[1];const i=r;if(s===null)return null;let c;if(e[2]!==n||e[3]!==t||e[4]!==s.active||e[5]!==s.suggestions||e[6]!==o){let d;e[8]!==n||e[9]!==t||e[10]!==s.active||e[11]!==o?(d=(m,f)=>W("li",{"aria-selected":f===s.active,className:ae("flex cursor-pointer items-center gap-2 px-2 py-1 text-[13px]",f===s.active?"bg-accent text-accent-foreground":"text-foreground"),"data-testid":"sql-autocomplete-item",id:`${n}-opt-${f.toString()}`,onMouseDown:h=>{h.preventDefault(),t(f)},role:"option",children:[u("span",{className:"truncate font-mono",children:m.label}),m.detail!==void 0&&u("span",{className:"ms-auto truncate text-xs text-muted-foreground",children:m.detail}),u("span",{className:"shrink-0 font-mono text-[10px] tracking-wide text-muted-foreground/70 uppercase",children:o(Ln[m.kind])})]},`${m.kind}:${m.label}`),e[8]=n,e[9]=t,e[10]=s.active,e[11]=o,e[12]=d):d=e[12],c=s.suggestions.map(d),e[2]=n,e[3]=t,e[4]=s.active,e[5]=s.suggestions,e[6]=o,e[7]=c}else c=e[7];let a;return e[13]!==n||e[14]!==i||e[15]!==c?(a=u("ul",{className:"absolute z-30 max-h-56 w-72 overflow-auto rounded-md border border-border bg-popover py-1 text-popover-foreground shadow-md","data-testid":"sql-autocomplete",id:n,role:"listbox",style:i,children:c}),e[13]=n,e[14]=i,e[15]=c,e[16]=a):a=e[16],a},In=Ie(qe.listTables),An=Ie(qe.readTablePage),Dn=l=>{const e=G(18),n=$e();let t;e[0]===Symbol.for("react.memo_cache_sentinel")?(t=[],e[0]=t):t=e[0];const[s,o]=te(t);let r;e[1]===Symbol.for("react.memo_cache_sentinel")?(r={},e[1]=r):r=e[1];const[i,c]=te(r);let a;e[2]===Symbol.for("react.memo_cache_sentinel")?(a={},e[2]=a):a=e[2];const[d,m]=te(a);let f;e[3]===Symbol.for("react.memo_cache_sentinel")?(f=new Set,e[3]=f):f=e[3];const h=de(f);let g,L;e[4]!==n||e[5]!==l?(g=()=>{const b={cancelled:!1};return ie((async()=>{try{const C=await n.query(In,{},Re(l));b.cancelled||(o(C.map(Mn)),c({}),m({}),h.current=new Set)}catch{b.cancelled||(o([]),c({}),m({}),h.current=new Set)}})()),()=>{b.cancelled=!0}},L=[n,l],e[4]=n,e[5]=l,e[6]=g,e[7]=L):(g=e[6],L=e[7]),ue(g,L);let v;e[8]!==n||e[9]!==l?(v=b=>{if(h.current.has(b))return;h.current.add(b),ie((async()=>{try{const C=await n.query(An,{limit:1,offset:0,table:b},Re(l)),{sqlColumns:w}=C;if(w===void 0){h.current.delete(b);return}const _=new Set(w),R=C.columns.filter(T=>!_.has(T));c(T=>({...T,[b]:w})),m(T=>({...T,[b]:R}))}catch{h.current.delete(b)}})())},e[8]=n,e[9]=l,e[10]=v):v=e[10];const S=v;let p;e[11]!==i||e[12]!==d||e[13]!==s?(p={columns:i,docFields:d,tables:s},e[11]=i,e[12]=d,e[13]=s,e[14]=p):p=e[14];const N=p;let x;return e[15]!==S||e[16]!==N?(x={probe:S,schema:N},e[15]=S,e[16]=N,e[17]=x):x=e[17],x},De=/\b(?:from|join|update|into)\s+([a-z_][\w$]*)|\b([a-z_][\w$]*)\s*\./gi,On=l=>{const e=new Set;De.lastIndex=0;let n=De.exec(l);for(;n!==null;)e.add(n[1]??n[2]),n=De.exec(l);return[...e]};function Mn(l){return l.name}const $n=l=>(l.metaKey||l.ctrlKey)&&!l.shiftKey&&!l.altKey&&l.key.toLowerCase()==="i",Bn=l=>{const e=G(44),{inlineEditEnabled:n,onSubmit:t,probe:s,schema:o,setDraft:r}=l,i=ht(),[c,a]=te(null),d=de(null),m=de(null),f=de(null),h=Rn(o,f,r),{close:g,commit:L,commitAt:v,move:S,refresh:p,state:N}=h;let x;e[0]!==v?(x=O=>{v(O)},e[0]=v,e[1]=x):x=e[1];const b=x;let y;e[2]!==p?(y=()=>{const O=f.current;O!==null&&O===document.activeElement&&p(O.value,O.selectionStart)},e[2]=p,e[3]=y):y=e[3];let C;e[4]!==p||e[5]!==o?(C=[p,o],e[4]=p,e[5]=o,e[6]=C):C=e[6],ue(y,C);let w;e[7]!==s||e[8]!==p||e[9]!==r?(w=O=>{const{selectionStart:U,value:X}=O.target;r(X),a(null);for(const Y of On(X))s(Y);p(X,U)},e[7]=s,e[8]=p,e[9]=r,e[10]=w):w=e[10];const _=w;let R;e[11]!==p?(R=O=>{const U=O.currentTarget;p(U.value,U.selectionStart)},e[11]=p,e[12]=R):R=e[12];const T=R;let k;e[13]!==g||e[14]!==L||e[15]!==S?(k=O=>O.key==="ArrowDown"?(O.preventDefault(),S(1),!0):O.key==="ArrowUp"?(O.preventDefault(),S(-1),!0):O.key==="Escape"?(O.preventDefault(),g(),!0):(O.key==="Enter"||O.key==="Tab")&&!O.metaKey&&!O.ctrlKey&&L()?(O.preventDefault(),!0):!1,e[13]=g,e[14]=L,e[15]=S,e[16]=k):k=e[16];const E=k;let q;e[17]!==N||e[18]!==g||e[19]!==n||e[20]!==E||e[21]!==t?(q=O=>{if(!(N!==null&&E(O))){if((O.metaKey||O.ctrlKey)&&O.key==="Enter"){O.preventDefault(),t();return}if(n&&$n(O)){O.preventDefault(),g();const{selectionEnd:U,selectionStart:X,value:Y}=O.currentTarget,[oe,re]=X===U?[0,Y.length]:[X,U];a({end:re,start:oe,text:Y.slice(oe,re)})}}},e[17]=N,e[18]=g,e[19]=n,e[20]=E,e[21]=t,e[22]=q):q=e[22];const A=q;let $;e[23]!==g?($=()=>{requestAnimationFrame(()=>{g()})},e[23]=g,e[24]=$):$=e[24];const F=$;let B;e[25]===Symbol.for("react.memo_cache_sentinel")?(B=O=>{const{scrollLeft:U,scrollTop:X}=O.currentTarget;d.current!==null&&(d.current.scrollTop=X),m.current!==null&&(m.current.scrollTop=X,m.current.scrollLeft=U)},e[25]=B):B=e[25];const H=B;let P;e[26]===Symbol.for("react.memo_cache_sentinel")?(P=O=>{const U=f.current;U===null||O.offset===void 0||(U.focus(),U.setSelectionRange(O.offset,O.offset+(O.length??0)))},e[26]=P):P=e[26];const Q=P;let M;e[27]===Symbol.for("react.memo_cache_sentinel")?(M=()=>{a(null),f.current?.focus()},e[27]=M):M=e[27];const I=M;let D;e[28]!==c||e[29]!==r?(D=O=>{const U=f.current;if(c===null||U===null)return;const{end:X,start:Y,text:oe}=c;if(U.value.slice(Y,X)!==oe){a(null);return}r(U.value.slice(0,Y)+O+U.value.slice(X)),a(null),U.focus(),requestAnimationFrame(()=>{U.setSelectionRange(Y,Y+O.length)})},e[28]=c,e[29]=r,e[30]=D):D=e[30];const z=D;let j;e[31]!==_||e[32]!==F||e[33]!==A||e[34]!==T?(j={onBlur:F,onChange:_,onKeyDown:A,onScroll:H,onSelect:T},e[31]=_,e[32]=F,e[33]=A,e[34]=T,e[35]=j):j=e[35];let K;return e[36]!==z||e[37]!==N||e[38]!==g||e[39]!==c||e[40]!==i||e[41]!==b||e[42]!==j?(K={acceptInlineEdit:z,autocompleteState:N,closeAutocomplete:g,closeInlineEdit:I,inlineEdit:c,handlers:j,listboxId:i,onPickSuggestion:b,editorRef:f,gutterRef:d,overlayRef:m,revealDiagnostic:Q},e[36]=z,e[37]=N,e[38]=g,e[39]=c,e[40]=i,e[41]=b,e[42]=j,e[43]=K):K=e[43],K},Pn="lunora-studio-sql-tabs",Wn="lunora-studio-sql-active-tab",He=12,Se=(l="",e="")=>({activeId:null,id:et("tab"),name:e,sql:l}),Hn=()=>Be(Wn,""),Fn=l=>{const e=G(16),[n,t]=Oe(Pn),[s,o]=Hn(),[r]=te(l);let i,c;e[0]!==r||e[1]!==t||e[2]!==n.length?(i=()=>{n.length===0&&t([r])},c=[r,t,n.length],e[0]=r,e[1]=t,e[2]=n.length,e[3]=i,e[4]=c):(i=e[3],c=e[4]),ue(i,c);let a;e[5]!==r||e[6]!==n?(a=n.length===0?[r]:n,e[5]=r,e[6]=n,e[7]=a):a=e[7];const d=a;let m;e[8]!==s||e[9]!==d?(m=d.some(g=>g.id===s)?s:d[0]?.id??"",e[8]=s,e[9]=d,e[10]=m):m=e[10];const f=m;let h;return e[11]!==f||e[12]!==o||e[13]!==t||e[14]!==d?(h={activeId:f,setActiveId:o,setTabs:t,tabs:d},e[11]=f,e[12]=o,e[13]=t,e[14]=d,e[15]=h):h=e[15],h},ft=l=>l.activeId===null&&l.sql.trim()!=="",Qn=(l,e)=>[...l,e].slice(-He),jn=(l,e,n)=>{const t=l.findIndex(r=>r.id===e);if(t===-1)return{activeId:l[0]?.id??"",tabs:[...l]};const s=l.filter(r=>r.id!==e);if(s.length===0){const r=n();return{activeId:r.id,tabs:[r]}}return{activeId:s[Math.min(t,s.length-1)].id,tabs:s}},zn=(l,e)=>{const n=l.filter(t=>t.id===e);return n.length===0?{activeId:l[0]?.id??"",tabs:[...l]}:{activeId:e,tabs:n}},Kn=(l,e,n)=>{const t=l.findIndex(o=>o.id===e);if(t===-1)return{activeId:n,tabs:[...l]};const s=l.slice(0,t+1);return{activeId:s.some(o=>o.id===n)?n:e,tabs:s}},Un=l=>{const e=l();return{activeId:e.id,tabs:[e]}},Yn=(l,e,n)=>{if(l==="others")return e.filter(t=>t.id!==n);if(l==="right"){const t=e.findIndex(s=>s.id===n);return t===-1?[]:e.slice(t+1)}return[...e]},Je={error:null,pane:"results",result:null,running:!1},Gn=l=>{const e=G(69),{activeId:n,setActiveId:t,setTabs:s,tabs:o}=Fn(l);let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={},e[0]=r):r=e[0];const[i,c]=te(r),[a,d]=te(null),[m,f]=te(null);let h;e[1]!==n||e[2]!==o?(h=o.find(V=>V.id===n)??o[0]??Se(),e[1]=n,e[2]=o,e[3]=h):h=e[3];const g=h,L=i[g.id]??Je;let v;e[4]!==g.id||e[5]!==s?(v=V=>{s(ee=>ee.map(se=>se.id===g.id?{...se,...V}:se))},e[4]=g.id,e[5]=s,e[6]=v):v=e[6];const S=v;let p;e[7]!==g.id?(p=V=>{c(ee=>{const se=ee[g.id]??Je;return{...ee,[g.id]:{...se,...V}}})},e[7]=g.id,e[8]=p):p=e[8];const N=p;let x;e[9]!==t||e[10]!==s||e[11]!==o.length?(x=V=>{if(o.length>=He)return!1;const ee=Se(V);return s(se=>Qn(se,ee)),t(ee.id),!0},e[9]=t,e[10]=s,e[11]=o.length,e[12]=x):x=e[12];const b=x;let y;e[13]!==b?(y=()=>{b("")},e[13]=b,e[14]=y):y=e[14];const C=y;let w;e[15]!==t||e[16]!==s?(w=V=>{d(null),f(null),s(V.tabs),t(V.activeId);const ee=new Set(V.tabs.map(Vn));c(se=>Object.fromEntries(Object.entries(se).filter(fe=>{const[J]=fe;return ee.has(J)})))},e[15]=t,e[16]=s,e[17]=w):w=e[17];const _=w;let R;e[18]!==_||e[19]!==o?(R=V=>{_(jn(o,V,Se))},e[18]=_,e[19]=o,e[20]=R):R=e[20];const T=R;let k;e[21]!==n||e[22]!==_||e[23]!==o?(k=(V,ee)=>{_(V==="others"?zn(o,ee):V==="right"?Kn(o,ee,n):Un(Se))},e[21]=n,e[22]=_,e[23]=o,e[24]=k):k=e[24];const E=k;let q;e[25]!==E||e[26]!==a||e[27]!==o?(q=V=>{a!==null&&(Yn(V,o,a.id).some(Jn)?f(V):E(V,a.id))},e[25]=E,e[26]=a,e[27]=o,e[28]=q):q=e[28];const A=q;let $;e[29]===Symbol.for("react.memo_cache_sentinel")?($=(V,ee)=>{ee.preventDefault(),f(null),d({id:V,x:ee.clientX,y:ee.clientY})},e[29]=$):$=e[29];const F=$;let B;e[30]===Symbol.for("react.memo_cache_sentinel")?(B=()=>{d(null),f(null)},e[30]=B):B=e[30];const H=B;let P;e[31]===Symbol.for("react.memo_cache_sentinel")?(P=V=>{V.preventDefault(),d(null),f(null)},e[31]=P):P=e[31];const Q=P;let M;e[32]!==A?(M=()=>{A("others")},e[32]=A,e[33]=M):M=e[33];const I=M;let D;e[34]!==A?(D=()=>{A("right")},e[34]=A,e[35]=D):D=e[35];const z=D;let j;e[36]!==A?(j=()=>{A("all")},e[36]=A,e[37]=j):j=e[37];const K=j;let O;e[38]!==E||e[39]!==m||e[40]!==a?(O=()=>{a!==null&&m!==null&&E(m,a.id),f(null)},e[38]=E,e[39]=m,e[40]=a,e[41]=O):O=e[41];const U=O;let X;e[42]===Symbol.for("react.memo_cache_sentinel")?(X=()=>{f(null)},e[42]=X):X=e[42];const Y=X;let oe;e[43]!==a?(oe=a===null?void 0:{left:a.x,top:a.y},e[43]=a,e[44]=oe):oe=e[44];const re=oe;let pe;e[45]!==s?(pe=V=>{s(ee=>ee.map(se=>se.activeId===V?{...se,activeId:null}:se))},e[45]=s,e[46]=pe):pe=e[46];const ve=pe;let he;e[47]!==s?(he=(V,ee)=>{s(se=>se.map(fe=>fe.id===V?{...fe,name:ee}:fe))},e[47]=s,e[48]=he):he=e[48];const ye=he;let be;return e[49]!==g||e[50]!==n||e[51]!==C||e[52]!==T||e[53]!==U||e[54]!==K||e[55]!==I||e[56]!==z||e[57]!==b||e[58]!==L||e[59]!==N||e[60]!==S||e[61]!==m||e[62]!==ye||e[63]!==t||e[64]!==a||e[65]!==re||e[66]!==o||e[67]!==ve?(be={activeTab:g,activeTabId:n,addEditorTab:C,cancelBulk:Y,closeEditorTab:T,closeTabMenu:H,confirmBulk:U,menuStyle:re,onBackdropContextMenu:Q,onCloseAll:K,onCloseOthers:I,onCloseToRight:z,openEditorTab:b,openTabMenu:F,output:L,patchActiveOutput:N,patchActiveTab:S,pendingBulk:m,renameTab:ye,setActiveTabId:t,tabMenu:a,tabs:o,unlinkQuery:ve},e[49]=g,e[50]=n,e[51]=C,e[52]=T,e[53]=U,e[54]=K,e[55]=I,e[56]=z,e[57]=b,e[58]=L,e[59]=N,e[60]=S,e[61]=m,e[62]=ye,e[63]=t,e[64]=a,e[65]=re,e[66]=o,e[67]=ve,e[68]=be):be=e[68],be};function Vn(l){return l.id}function Jn(l){return ft(l)}const Xn="lunora-studio-sql-queries",ge="lunora-studio-sql-history",Zn="lunora-studio-sql-remember-history",es=25,ts=l=>{const e=G(44),{loadIntoActiveTab:n,unlinkQuery:t}=l,s=Z(),[o,r]=Oe(Xn),[i,c]=Be(Zn,!1),[a,d]=Oe(ge,i?"local":"session");let m,f;e[0]!==i?(m=()=>{i||Ce(ge,"local")},f=[i],e[0]=i,e[1]=m,e[2]=f):(m=e[1],f=e[2]),ue(m,f);const[h,g]=te(""),L=de(null);let v;e[3]!==d?(v=I=>{d(D=>D[0]?.sql===I?D:[{at:Date.now(),sql:I},...D.filter(j=>j.sql!==I)].slice(0,es))},e[3]=d,e[4]=v):v=e[4];const S=v;let p;e[5]!==n||e[6]!==r||e[7]!==s?(p=()=>{const I={id:et("q"),name:s("Untitled query"),sql:""};r(D=>[I,...D]),n("",I.id)},e[5]=n,e[6]=r,e[7]=s,e[8]=p):p=e[8];const N=p;let x;e[9]!==n||e[10]!==o?(x=I=>{const D=o.find(z=>z.id===I);D!==void 0&&(n(D.sql,I),L.current?.querySelector(`[data-testid="sql-query-${I}"]`)?.scrollIntoView({block:"nearest"}))},e[9]=n,e[10]=o,e[11]=x):x=e[11];const b=x;let y;e[12]!==r||e[13]!==t?(y=I=>{r(D=>D.filter(z=>z.id!==I)),t(I)},e[12]=r,e[13]=t,e[14]=y):y=e[14];const C=y;let w;e[15]!==n?(w=I=>{n(I.currentTarget.dataset.sql??"",null)},e[15]=n,e[16]=w):w=e[16];const _=w;let R;e[17]!==n?(R=I=>{n(I.currentTarget.dataset.sql??"",null)},e[17]=n,e[18]=R):R=e[18];const T=R;let k;e[19]!==d?(k=()=>{d([]),Ce(ge,"local"),Ce(ge,"session")},e[19]=d,e[20]=k):k=e[20];const E=k;let q;e[21]!==a||e[22]!==c?(q=I=>{xt(ge,a,I?"local":"session"),I||Ce(ge,"local"),c(I)},e[21]=a,e[22]=c,e[23]=q):q=e[23];const A=q;let $;e[24]===Symbol.for("react.memo_cache_sentinel")?($=I=>{g(I.target.value)},e[24]=$):$=e[24];const F=$;let B;e[25]!==r?(B=(I,D,z)=>{r(j=>j.map(K=>K.id===I?{id:K.id,name:D,sql:K.sql,...z===""?{}:{description:z}}:K))},e[25]=r,e[26]=B):B=e[26];const H=B;let P;e[27]!==r?(P=(I,D)=>{r(z=>z.map(j=>j.id===I?{...j,sql:D}:j))},e[27]=r,e[28]=P):P=e[28];const Q=P;let M;return e[29]!==E||e[30]!==C||e[31]!==a||e[32]!==T||e[33]!==_||e[34]!==N||e[35]!==o||e[36]!==S||e[37]!==i||e[38]!==H||e[39]!==h||e[40]!==b||e[41]!==A||e[42]!==Q?(M={clearHistory:E,deleteQuery:C,history:a,listRef:L,loadFromHistory:T,loadTemplate:_,newQuery:N,onSearchChange:F,queries:o,recordHistory:S,rememberHistory:i,renameQuery:H,search:h,selectQuery:b,setRememberHistory:A,updateQuerySql:Q},e[29]=E,e[30]=C,e[31]=a,e[32]=T,e[33]=_,e[34]=N,e[35]=o,e[36]=S,e[37]=i,e[38]=H,e[39]=h,e[40]=b,e[41]=A,e[42]=Q,e[43]=M):M=e[43],M},Fe="p-3 font-mono text-xs leading-5 whitespace-pre-wrap break-words",ns=(l,e)=>{const n=[];for(const s of l){if(s.offset===void 0||s.length===void 0||s.length<=0)continue;const o=Math.max(0,Math.min(s.offset,e)),r=Math.max(o,Math.min(s.offset+s.length,e));o!==r&&n.push({end:r,severity:s.severity,start:o})}n.sort((s,o)=>s.start-o.start);const t=[];for(const s of n)s.start>=(t.at(-1)?.end??0)&&t.push(s);return t},ss=l=>{const e=G(51),{rpc:n,failed:t,onGenerated:s}=l,o=Z(),[r,i]=te("");if(n.unavailable)return null;let c;e[0]!==n?(c=n.pending("sql"),e[0]=n,e[1]=c):c=e[1];const a=c;let d;if(e[2]!==t||e[3]!==s||e[4]!==a||e[5]!==r||e[6]!==n||e[7]!==o){const m=n.reason("sql");let f;e[9]!==t||e[10]!==s||e[11]!==r||e[12]!==n?(f=T=>{const k=r.trim();if(k===""&&!T)return;ie((async()=>{const q=await n.generate(k===""?"fix the failing statement":k,T?t:void 0);q!==void 0&&s(q)})())},e[9]=t,e[10]=s,e[11]=r,e[12]=n,e[13]=f):f=e[13];const h=f;let g;e[14]!==o?(g=o("Describe the query you want"),e[14]=o,e[15]=g):g=e[15];let L;e[16]===Symbol.for("react.memo_cache_sentinel")?(L=T=>{i(T.target.value)},e[16]=L):L=e[16];let v;e[17]!==h?(v=T=>{T.key==="Enter"&&(T.preventDefault(),h(!1))},e[17]=h,e[18]=v):v=e[18];let S;e[19]!==o?(S=o("Describe the query you want"),e[19]=o,e[20]=S):S=e[20];let p;e[21]!==a||e[22]!==r||e[23]!==g||e[24]!==v||e[25]!==S?(p=u(Le,{"aria-label":g,className:"h-7 flex-1 text-xs","data-testid":"sql-assistant-prompt",disabled:a,onChange:L,onKeyDown:v,placeholder:S,value:r}),e[21]=a,e[22]=r,e[23]=g,e[24]=v,e[25]=S,e[26]=p):p=e[26];const N=a&&"opacity-60";let x;e[27]!==N?(x=ae("rounded-md border border-border px-2 py-1 text-xs outline-none transition-colors hover:bg-accent focus-visible:bg-accent",N),e[27]=N,e[28]=x):x=e[28];let b;e[29]!==a||e[30]!==r?(b=a||r.trim()==="",e[29]=a,e[30]=r,e[31]=b):b=e[31];let y;e[32]!==h?(y=()=>{h(!1)},e[32]=h,e[33]=y):y=e[33];let C;e[34]!==a||e[35]!==o?(C=o(a?"Thinking…":"Draft SQL"),e[34]=a,e[35]=o,e[36]=C):C=e[36];let w;e[37]!==x||e[38]!==b||e[39]!==y||e[40]!==C?(w=u("button",{className:x,"data-testid":"sql-assistant-generate",disabled:b,onClick:y,type:"button",children:C}),e[37]=x,e[38]=b,e[39]=y,e[40]=C,e[41]=w):w=e[41];let _;e[42]!==t||e[43]!==a||e[44]!==h||e[45]!==o?(_=t!==void 0&&u("button",{className:"rounded-md border border-border px-2 py-1 text-xs outline-none transition-colors hover:bg-accent focus-visible:bg-accent","data-testid":"sql-assistant-fix",disabled:a,onClick:()=>{h(!0)},type:"button",children:o("Fix this")}),e[42]=t,e[43]=a,e[44]=h,e[45]=o,e[46]=_):_=e[46];let R;e[47]!==w||e[48]!==_||e[49]!==p?(R=W("div",{className:"flex items-center gap-2",children:[p,w,_]}),e[47]=w,e[48]=_,e[49]=p,e[50]=R):R=e[50],d=W("div",{className:"flex flex-col gap-1 border-b border-border px-3 py-2","data-testid":"sql-assistant",children:[R,m!==void 0&&u("p",{className:"text-[11px] text-muted-foreground","data-testid":"sql-assistant-reason",role:"status",children:tt(m,o)})]}),e[2]=t,e[3]=s,e[4]=a,e[5]=r,e[6]=n,e[7]=o,e[8]=d}else d=e[8];return d},os=l=>{const e=G(8),{diagnostics:n,draft:t,scrollRef:s}=l;let o,r;if(e[0]!==n||e[1]!==t){r=Symbol.for("react.early_return_sentinel");e:{const a=ns(n,t.length);if(a.length===0){r=null;break e}o=[];let d=0;for(const[m,f]of a.entries())f.start>d&&o.push(t.slice(d,f.start)),o.push(u("span",{className:ae("decoration-wavy underline underline-offset-4",f.severity==="error"?"decoration-destructive":"decoration-amber-500"),children:t.slice(f.start,f.end)},`${f.start.toString()}-${m.toString()}`)),d=f.end;o.push(t.slice(d))}e[0]=n,e[1]=t,e[2]=o,e[3]=r}else o=e[2],r=e[3];if(r!==Symbol.for("react.early_return_sentinel"))return r;let i;e[4]===Symbol.for("react.memo_cache_sentinel")?(i=ae("pointer-events-none absolute inset-0 overflow-hidden text-transparent",Fe),e[4]=i):i=e[4];let c;return e[5]!==o||e[6]!==s?(c=u("div",{"aria-hidden":"true",className:i,"data-testid":"sql-diagnostics-overlay",ref:s,children:o}),e[5]=o,e[6]=s,e[7]=c):c=e[7],c},ls={gate:"read-only",plan:"plan",schema:"schema",syntax:"syntax"},rs=l=>{const e=G(10),{diagnostics:n,onSelect:t}=l,s=Z();if(n.length===0)return null;let o;e[0]!==s?(o=s("SQL problems"),e[0]=s,e[1]=o):o=e[1];let r;if(e[2]!==n||e[3]!==t){let c;e[5]!==t?(c=(a,d)=>u("li",{children:W("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:()=>{t(a)},type:"button",children:[u("span",{className:ae("mt-px shrink-0 rounded px-1 font-mono text-[10px] uppercase",a.severity==="error"?"bg-destructive/15 text-destructive":"bg-amber-500/15 text-amber-600"),children:ls[a.source]}),u("span",{className:"min-w-0 text-muted-foreground",children:a.message})]})},`${a.source}-${(a.offset??d).toString()}-${d.toString()}`),e[5]=t,e[6]=c):c=e[6],r=n.map(c),e[2]=n,e[3]=t,e[4]=r}else r=e[4];let i;return e[7]!==o||e[8]!==r?(i=u("ul",{"aria-label":o,className:"max-h-24 shrink-0 overflow-y-auto border-t border-border bg-muted/30","data-testid":"sql-problems",children:r}),e[7]=o,e[8]=r,e[9]=i):i=e[9],i},is=l=>(l.endsWith(`
|
|
8
|
+
`)?l.slice(0,-1):l).split(`
|
|
9
|
+
`),as=(l,e)=>{const n=[];let t=1,s=1;for(const o of Ct(l,e,{ignoreNewlineAtEof:!0}))for(const r of is(o.value))o.added?(n.push({after:s,kind:"added",text:r}),s+=1):o.removed?(n.push({before:t,kind:"removed",text:r}),t+=1):(n.push({after:s,before:t,kind:"context",text:r}),t+=1,s+=1);return n},cs={added:"bg-emerald-500/10 text-emerald-700 dark:text-emerald-400",context:"text-muted-foreground",removed:"bg-destructive/10 text-destructive"},ds={added:"+",context:" ",removed:"-"},us=l=>{const e=G(11),{lines:n}=l,t=Z();let s;e[0]!==t?(s=t("Proposed edit"),e[0]=t,e[1]=s):s=e[1];let o;e[2]===Symbol.for("react.memo_cache_sentinel")?(o=ae("max-h-48 overflow-auto rounded-md border border-border bg-background",Fe),e[2]=o):o=e[2];let r;if(e[3]!==n||e[4]!==t){let c;e[6]!==t?(c=a=>W("li",{className:ae("flex gap-2",cs[a.kind]),"data-kind":a.kind,children:[u("span",{"aria-hidden":"true",className:"shrink-0 select-none opacity-60",children:ds[a.kind]}),a.kind!=="context"&&u("span",{className:"sr-only",children:a.kind==="added"?t("Added"):t("Removed")}),u("span",{className:"min-w-0",children:a.text===""?" ":a.text})]},`${String(a.before)}:${String(a.after)}`),e[6]=t,e[7]=c):c=e[7],r=n.map(c),e[3]=n,e[4]=t,e[5]=r}else r=e[5];let i;return e[8]!==s||e[9]!==r?(i=u("ul",{"aria-label":s,className:o,"data-testid":"sql-inline-diff",children:r}),e[8]=s,e[9]=r,e[10]=i):i=e[10],i},Ne="rounded-md border border-border px-2 py-1 text-xs outline-none transition-colors hover:bg-accent focus-visible:bg-accent",fs=l=>{const e=G(41),{onAccept:n,onCancel:t,rpc:s,source:o,whole:r}=l,i=Z(),c=de(null),a=de(null),[d,m]=te(""),[f,h]=te(null);let g,L;if(e[0]!==f?(g=()=>{f===null?c.current?.focus():a.current?.focus()},L=[f],e[0]=f,e[1]=g,e[2]=L):(g=e[1],L=e[2]),ue(g,L),s.unavailable)return null;let v;e[3]!==s?(v=s.pending("sql"),e[3]=s,e[4]=v):v=e[4];const S=v;let p;if(e[5]!==d||e[6]!==n||e[7]!==t||e[8]!==S||e[9]!==f||e[10]!==s||e[11]!==o||e[12]!==i||e[13]!==r){const N=s.reason("sql");let x;e[15]!==d||e[16]!==s||e[17]!==o?(x=()=>{const E=d.trim();if(E===""||o.trim()==="")return;ie((async()=>{const A=await s.rewrite(E,o);A!==void 0&&h(A)})())},e[15]=d,e[16]=s,e[17]=o,e[18]=x):x=e[18];const b=x;let y;e[19]!==t?(y=E=>{E.key==="Escape"&&(E.preventDefault(),t())},e[19]=t,e[20]=y):y=e[20];const C=y;let w;e[21]!==i||e[22]!==r?(w=i(r?"Whole query":"Selection"),e[21]=i,e[22]=r,e[23]=w):w=e[23];let _;e[24]!==w?(_=u("span",{className:"shrink-0 rounded bg-muted px-1 font-mono text-[10px] uppercase text-muted-foreground","data-testid":"sql-inline-edit-scope",children:w}),e[24]=w,e[25]=_):_=e[25];let R;e[26]!==d||e[27]!==n||e[28]!==t||e[29]!==C||e[30]!==S||e[31]!==f||e[32]!==b||e[33]!==i?(R=f===null?W(xe,{children:[u(Le,{"aria-label":i("Tell the model what to change"),className:"h-7 flex-1 text-xs","data-testid":"sql-inline-edit-prompt",disabled:S,onChange:E=>{m(E.target.value)},onKeyDown:E=>{if(E.key==="Enter"){E.preventDefault(),b();return}C(E)},placeholder:i("Tell the model what to change"),ref:c,value:d}),u("button",{className:ae(Ne,S&&"opacity-60"),"data-testid":"sql-inline-edit-submit",disabled:S||d.trim()==="",onClick:b,onKeyDown:C,type:"button",children:i(S?"Thinking…":"Rewrite")}),u("button",{className:Ne,"data-testid":"sql-inline-edit-cancel",onClick:t,onKeyDown:C,type:"button",children:i("Cancel")})]}):W(xe,{children:[u("span",{className:"flex-1 text-xs text-muted-foreground",children:i("Proposed edit")}),u("button",{className:Ne,"data-testid":"sql-inline-edit-accept",onClick:()=>{n(f)},onKeyDown:C,ref:a,type:"button",children:i("Accept")}),u("button",{className:Ne,"data-testid":"sql-inline-edit-reject",onClick:()=>{h(null)},onKeyDown:C,type:"button",children:i("Reject")})]}),e[26]=d,e[27]=n,e[28]=t,e[29]=C,e[30]=S,e[31]=f,e[32]=b,e[33]=i,e[34]=R):R=e[34];let T;e[35]!==_||e[36]!==R?(T=W("div",{className:"flex items-center gap-2",children:[_,R]}),e[35]=_,e[36]=R,e[37]=T):T=e[37];let k;e[38]!==f||e[39]!==o?(k=f!==null&&u(us,{lines:as(o,f)}),e[38]=f,e[39]=o,e[40]=k):k=e[40],p=W("div",{className:"flex flex-col gap-1 border-b border-border bg-muted/20 px-3 py-2","data-testid":"sql-inline-edit",children:[T,k,N!==void 0&&u("p",{className:"text-[11px] text-muted-foreground","data-testid":"sql-inline-edit-reason",role:"status",children:tt(N,i)})]}),e[5]=d,e[6]=n,e[7]=t,e[8]=S,e[9]=f,e[10]=s,e[11]=o,e[12]=i,e[13]=r,e[14]=p}else p=e[14];return p},ms={minWidth:"2.75rem",paddingInline:"0.5rem"},ps=l=>{const e=G(75),{rpc:n,autocomplete:t,diagnostics:s,draft:o,failed:r,handlers:i,editorRef:c,gutterRef:a,inlineEdit:d,listboxId:m,onAcceptInlineEdit:f,onCancelInlineEdit:h,onGenerated:g,onPickSuggestion:L,onRevealDiagnostic:v,overlayRef:S}=l,p=Z();let N,x,b,y,C,w,_,R,T;if(e[0]!==o||e[1]!==r||e[2]!==a||e[3]!==d||e[4]!==f||e[5]!==h||e[6]!==g||e[7]!==n){const D=o.split(`
|
|
10
|
+
`).length;_="flex min-h-0 min-w-0 flex-1 flex-col",e[17]!==r||e[18]!==g||e[19]!==n?(R=u(ss,{failed:r,onGenerated:g,rpc:n}),e[17]=r,e[18]=g,e[19]=n,e[20]=R):R=e[20],e[21]!==o.length||e[22]!==d||e[23]!==f||e[24]!==h||e[25]!==n?(T=d!==null&&u(fs,{onAccept:f,onCancel:h,rpc:n,source:d.text,whole:d.start===0&&d.end===o.length},`${d.start.toString()}-${d.end.toString()}`),e[21]=o.length,e[22]=d,e[23]=f,e[24]=h,e[25]=n,e[26]=T):T=e[26],w="flex min-h-0 min-w-0 flex-1",N="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",b=a,y=ms,C=Array.from({length:D},hs),e[0]=o,e[1]=r,e[2]=a,e[3]=d,e[4]=f,e[5]=h,e[6]=g,e[7]=n,e[8]=N,e[9]=x,e[10]=b,e[11]=y,e[12]=C,e[13]=w,e[14]=_,e[15]=R,e[16]=T}else N=e[8],x=e[9],b=e[10],y=e[11],C=e[12],w=e[13],_=e[14],R=e[15],T=e[16];let k;e[27]!==N||e[28]!==x||e[29]!==b||e[30]!==y||e[31]!==C?(k=u("div",{"aria-hidden":N,className:x,ref:b,style:y,children:C}),e[27]=N,e[28]=x,e[29]=b,e[30]=y,e[31]=C,e[32]=k):k=e[32];let E;e[33]!==s||e[34]!==o||e[35]!==S?(E=u(os,{diagnostics:s,draft:o,scrollRef:S}),e[33]=s,e[34]=o,e[35]=S,e[36]=E):E=e[36];let q;e[37]!==t||e[38]!==m?(q=t===null?void 0:`${m}-opt-${t.active.toString()}`,e[37]=t,e[38]=m,e[39]=q):q=e[39];const A=t===null?void 0:m,$=t!==null;let F;e[40]!==p?(F=p("SQL query"),e[40]=p,e[41]=F):F=e[41];let B;e[42]!==o||e[43]!==c||e[44]!==i.onBlur||e[45]!==i.onChange||e[46]!==i.onKeyDown||e[47]!==i.onScroll||e[48]!==i.onSelect||e[49]!==q||e[50]!==A||e[51]!==$||e[52]!==F?(B=u("textarea",{"aria-activedescendant":q,"aria-autocomplete":"list","aria-controls":A,"aria-expanded":$,"aria-label":F,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 …",ref:c,role:"combobox",spellCheck:!1,value:o}),e[42]=o,e[43]=c,e[44]=i.onBlur,e[45]=i.onChange,e[46]=i.onKeyDown,e[47]=i.onScroll,e[48]=i.onSelect,e[49]=q,e[50]=A,e[51]=$,e[52]=F,e[53]=B):B=e[53];let H;e[54]!==t||e[55]!==m||e[56]!==L?(H=u(qn,{listboxId:m,onPick:L,state:t}),e[54]=t,e[55]=m,e[56]=L,e[57]=H):H=e[57];let P;e[58]!==E||e[59]!==B||e[60]!==H?(P=W("div",{className:"relative min-w-0 flex-1 bg-background",children:[E,B,H]}),e[58]=E,e[59]=B,e[60]=H,e[61]=P):P=e[61];let Q;e[62]!==k||e[63]!==P||e[64]!==w?(Q=W("div",{className:w,children:[k,P]}),e[62]=k,e[63]=P,e[64]=w,e[65]=Q):Q=e[65];let M;e[66]!==s||e[67]!==v?(M=u(rs,{diagnostics:s,onSelect:v}),e[66]=s,e[67]=v,e[68]=M):M=e[68];let I;return e[69]!==Q||e[70]!==M||e[71]!==_||e[72]!==R||e[73]!==T?(I=W("div",{className:_,children:[R,T,Q,M]}),e[69]=Q,e[70]=M,e[71]=_,e[72]=R,e[73]=T,e[74]=I):I=e[74],I};function hs(l,e){return u("div",{children:e+1},e)}const bs=l=>{const e=G(62),{onCancel:n,onSave:t,query:s,rpc:o}=l,r=Z(),[i,c]=te(s.name),[a,d]=te(s.description??"");let m;e[0]!==s.sql||e[1]!==o?(m=o!==void 0&&!o.unavailable&&s.sql.trim()!=="",e[0]=s.sql,e[1]=o,e[2]=m):m=e[2];const f=m;let h;e[3]!==o?(h=o?.pending("name"),e[3]=o,e[4]=h):h=e[4];const g=h===!0;let L;e[5]!==o?(L=o?.reason("name"),e[5]=o,e[6]=L):L=e[6];const v=L;let S;e[7]!==a||e[8]!==i||e[9]!==s.sql||e[10]!==o?(S=()=>{if(o===void 0)return;const M=i,I=a;ie((async()=>{const z=await o.nameQuery(s.sql);z!==void 0&&(c(j=>j===M?z.title:j),d(j=>j===I?z.description:j))})())},e[7]=a,e[8]=i,e[9]=s.sql,e[10]=o,e[11]=S):S=e[11];const p=S;let N;e[12]!==a||e[13]!==i||e[14]!==t?(N=M=>{M.preventDefault();const I=i.trim();I!==""&&t(I,a.trim())},e[12]=a,e[13]=i,e[14]=t,e[15]=N):N=e[15];const x=N,b=`sql-query-rename-${s.id}`;let y;e[16]!==r?(y=r("Query name"),e[16]=r,e[17]=y):y=e[17];let C;e[18]===Symbol.for("react.memo_cache_sentinel")?(C=M=>{c(M.target.value)},e[18]=C):C=e[18];let w;e[19]!==r?(w=r("Query name"),e[19]=r,e[20]=w):w=e[20];let _;e[21]!==i||e[22]!==y||e[23]!==w?(_=u(Le,{"aria-label":y,autoFocus:!0,className:"h-7 text-xs","data-testid":"sql-query-name",onChange:C,placeholder:w,value:i}),e[21]=i,e[22]=y,e[23]=w,e[24]=_):_=e[24];let R;e[25]!==r?(R=r("Query description"),e[25]=r,e[26]=R):R=e[26];let T;e[27]===Symbol.for("react.memo_cache_sentinel")?(T=M=>{d(M.target.value)},e[27]=T):T=e[27];let k;e[28]!==r?(k=r("Query description"),e[28]=r,e[29]=k):k=e[29];let E;e[30]!==a||e[31]!==R||e[32]!==k?(E=u(Le,{"aria-label":R,className:"h-7 text-xs","data-testid":"sql-query-description",onChange:T,placeholder:k,value:a}),e[30]=a,e[31]=R,e[32]=k,e[33]=E):E=e[33];let q;e[34]!==r?(q=r("Save"),e[34]=r,e[35]=q):q=e[35];let A;e[36]!==q?(A=u("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:q}),e[36]=q,e[37]=A):A=e[37];let $;e[38]!==r?($=r("Cancel"),e[38]=r,e[39]=$):$=e[39];let F;e[40]!==n||e[41]!==$?(F=u("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:$}),e[40]=n,e[41]=$,e[42]=F):F=e[42];let B;e[43]!==f||e[44]!==g||e[45]!==p||e[46]!==r?(B=f&&u("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:p,type:"button",children:r(g?"Thinking…":"Suggest")}),e[43]=f,e[44]=g,e[45]=p,e[46]=r,e[47]=B):B=e[47];let H;e[48]!==A||e[49]!==F||e[50]!==B?(H=W("div",{className:"flex items-center gap-1",children:[A,F,B]}),e[48]=A,e[49]=F,e[50]=B,e[51]=H):H=e[51];let P;e[52]!==v||e[53]!==r?(P=v!==void 0&&u("p",{className:"text-[11px] text-muted-foreground","data-testid":"sql-query-name-reason",role:"status",children:r(v==="ai-error"?"The model could not be reached.":"The model returned nothing usable.")}),e[52]=v,e[53]=r,e[54]=P):P=e[54];let Q;return e[55]!==x||e[56]!==_||e[57]!==E||e[58]!==H||e[59]!==P||e[60]!==b?(Q=W("form",{className:"flex flex-col gap-1 rounded-md bg-sidebar-accent p-1.5","data-testid":b,onSubmit:x,children:[_,E,H,P]}),e[55]=x,e[56]=_,e[57]=E,e[58]=H,e[59]=P,e[60]=b,e[61]=Q):Q=e[61],Q},mt=[{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;"}],gs=l=>{const e=G(44),{active:n,onDelete:t,onRename:s,onSelect:o,query:r}=l,i=Z();let c;e[0]!==o||e[1]!==r.id?(c=()=>{o(r.id)},e[0]=o,e[1]=r.id,e[2]=c):c=e[2];const a=c;let d;e[3]!==t||e[4]!==r.id?(d=q=>{q.stopPropagation(),t(r.id)},e[3]=t,e[4]=r.id,e[5]=d):d=e[5];const m=d;let f;e[6]!==s||e[7]!==r.id?(f=q=>{q.stopPropagation(),s(r.id)},e[6]=s,e[7]=r.id,e[8]=f):f=e[8];const h=f,g=n?"bg-sidebar-accent font-medium text-foreground":"text-muted-foreground";let L;e[9]!==g?(L=ae("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]=L):L=e[10];const v=`sql-query-${r.id}`;let S;e[11]===Symbol.for("react.memo_cache_sentinel")?(S=u("svg",{"aria-hidden":"true",className:"size-3.5 shrink-0 opacity-70",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:u("path",{d:"M4 6h16M4 12h10M4 18h7"})}),e[11]=S):S=e[11];let p;e[12]!==r.name?(p=u("span",{className:"truncate",children:r.name}),e[12]=r.name,e[13]=p):p=e[13];let N;e[14]!==n||e[15]!==a||e[16]!==r.description||e[17]!==L||e[18]!==v||e[19]!==p?(N=W("button",{"aria-pressed":n,className:L,"data-testid":v,onClick:a,title:r.description,type:"button",children:[S,p]}),e[14]=n,e[15]=a,e[16]=r.description,e[17]=L,e[18]=v,e[19]=p,e[20]=N):N=e[20];let x;e[21]!==i?(x=i("Rename query"),e[21]=i,e[22]=x):x=e[22];const b=`sql-query-rename-open-${r.id}`;let y;e[23]!==i?(y=i("Rename query"),e[23]=i,e[24]=y):y=e[24];let C;e[25]===Symbol.for("react.memo_cache_sentinel")?(C=u("svg",{"aria-hidden":"true",className:"size-3.5",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:u("path",{d:"M4 20h4L19 9l-4-4L4 16zM14 6l4 4"})}),e[25]=C):C=e[25];let w;e[26]!==h||e[27]!==x||e[28]!==b||e[29]!==y?(w=u("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":b,onClick:h,title:y,type:"button",children:C}),e[26]=h,e[27]=x,e[28]=b,e[29]=y,e[30]=w):w=e[30];let _;e[31]!==i?(_=i("Delete query"),e[31]=i,e[32]=_):_=e[32];let R;e[33]!==i?(R=i("Delete query"),e[33]=i,e[34]=R):R=e[34];let T;e[35]===Symbol.for("react.memo_cache_sentinel")?(T=u("svg",{"aria-hidden":"true",className:"size-3.5",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:u("path",{d:"M5 7h14M9 7V5h6v2m-1 0v12H10V7M7 7v13h10V7"})}),e[35]=T):T=e[35];let k;e[36]!==m||e[37]!==_||e[38]!==R?(k=u("button",{"aria-label":_,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:m,title:R,type:"button",children:T}),e[36]=m,e[37]=_,e[38]=R,e[39]=k):k=e[39];let E;return e[40]!==w||e[41]!==k||e[42]!==N?(E=W("li",{className:"group/q flex items-center",children:[N,w,k]}),e[40]=w,e[41]=k,e[42]=N,e[43]=E):E=e[43],E},Xe="sql-history-remember",xs=(l,e)=>{const n=e.trim().toLowerCase();return n===""?[...l]:l.filter(t=>t.name.toLowerCase().includes(n))},vs=l=>{const e=G(53),{activeId:n,history:t,listRef:s,onClearHistory:o,onDelete:r,onLoadHistory:i,onLoadTemplate:c,onNew:a,onRename:d,onSearchChange:m,onSelect:f,onToggleRememberHistory:h,queries:g,rememberHistory:L,rpc:v,search:S}=l,p=Z(),N=xs(g,S),[x,b]=te(null);let y;e[0]===Symbol.for("react.memo_cache_sentinel")?(y=()=>{b(null)},e[0]=y):y=e[0];const C=y;let w;e[1]!==h?(w=Y=>{h(Y.target.checked)},e[1]=h,e[2]=w):w=e[2];const _=w,R="flex h-full w-64 shrink-0 flex-col border-e border-border bg-sidebar";let T;e[3]!==p?(T=p("Search queries…"),e[3]=p,e[4]=T):T=e[4];let k;e[5]!==m||e[6]!==S||e[7]!==T?(k=u("input",{className:"h-8 min-w-0 flex-1 rounded-md border border-border bg-background px-2 text-xs outline-none focus-visible:border-ring","data-testid":"sql-search",onChange:m,placeholder:T,type:"text",value:S}),e[5]=m,e[6]=S,e[7]=T,e[8]=k):k=e[8];let E;e[9]!==p?(E=p("New query"),e[9]=p,e[10]=E):E=e[10];let q;e[11]!==p?(q=p("New query"),e[11]=p,e[12]=q):q=e[12];let A;e[13]===Symbol.for("react.memo_cache_sentinel")?(A=u("svg",{"aria-hidden":"true",className:"size-4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.7,viewBox:"0 0 24 24",children:u("path",{d:"M12 5v14M5 12h14"})}),e[13]=A):A=e[13];let $;e[14]!==a||e[15]!==E||e[16]!==q?($=u("button",{"aria-label":E,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:a,title:q,type:"button",children:A}),e[14]=a,e[15]=E,e[16]=q,e[17]=$):$=e[17];let F;e[18]!==k||e[19]!==$?(F=W("div",{className:"flex shrink-0 items-center gap-2 border-b border-border p-2",children:[k,$]}),e[18]=k,e[19]=$,e[20]=F):F=e[20];const B="flex flex-1 flex-col gap-4 overflow-y-auto p-2";let H;e[21]!==p?(H=p("Private"),e[21]=p,e[22]=H):H=e[22];let P;e[23]!==H?(P=u("p",{className:"px-1 pb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:H}),e[23]=H,e[24]=P):P=e[24];const Q=N.length===0?u("p",{className:"px-1 py-2 text-xs text-muted-foreground","data-testid":"sql-private-empty",children:p("No saved queries yet — they save to this browser as you type.")}):u("ul",{className:"flex flex-col gap-px","data-testid":"sql-private",ref:s,children:N.map(Y=>x===Y.id?u("li",{children:u(bs,{onCancel:C,onSave:(oe,re)=>{d(Y.id,oe,re),C()},query:Y,rpc:v})},Y.id):u(gs,{active:n===Y.id,onDelete:r,onRename:b,onSelect:f,query:Y},Y.id))});let M;e[25]!==P||e[26]!==Q?(M=W("div",{children:[P,Q]}),e[25]=P,e[26]=Q,e[27]=M):M=e[27];let I;e[28]!==p?(I=p("Reference"),e[28]=p,e[29]=I):I=e[29];let D;e[30]!==I?(D=u("p",{className:"px-1 pb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:I}),e[30]=I,e[31]=D):D=e[31];let z;e[32]!==c?(z=mt.map(Y=>u("li",{children:W("button",{className:"flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-start text-[13px] text-muted-foreground outline-none transition-colors hover:bg-sidebar-accent hover:text-foreground focus-visible:bg-sidebar-accent","data-sql":Y.sql,onClick:c,type:"button",children:[u("svg",{"aria-hidden":"true",className:"size-3.5 shrink-0 opacity-70",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:u("path",{d:"M7 4h7l4 4v12H7zM14 4v4h4"})}),Y.label]})},Y.label)),e[32]=c,e[33]=z):z=e[33];let j;e[34]!==z?(j=u("ul",{className:"flex flex-col gap-px",children:z}),e[34]=z,e[35]=j):j=e[35];let K;e[36]!==D||e[37]!==j?(K=W("div",{children:[D,j]}),e[36]=D,e[37]=j,e[38]=K):K=e[38];let O;e[39]!==t||e[40]!==o||e[41]!==i||e[42]!==_||e[43]!==L||e[44]!==p?(O=t.length>0&&W("div",{children:[W("div",{className:"flex items-center justify-between px-1 pb-1",children:[u("p",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:p("History")}),u("button",{className:"rounded px-1 text-[11px] text-muted-foreground outline-none transition-colors hover:text-foreground focus-visible:text-foreground","data-testid":"sql-history-clear",onClick:o,type:"button",children:p("Clear history")})]}),W("label",{className:"flex cursor-pointer items-center gap-1.5 px-1 pb-1.5 text-[11px] text-muted-foreground",htmlFor:Xe,children:[u("input",{checked:L,"data-testid":"sql-history-remember",id:Xe,onChange:_,type:"checkbox"}),p("Keep history on this browser")]}),u("ul",{className:"flex flex-col gap-px","data-testid":"sql-history",children:t.map(Y=>u("li",{children:W("button",{className:"flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-start text-[13px] text-muted-foreground outline-none transition-colors hover:bg-sidebar-accent hover:text-foreground focus-visible:bg-sidebar-accent","data-sql":Y.sql,"data-testid":"sql-history-item",onClick:i,title:Y.sql,type:"button",children:[u("svg",{"aria-hidden":"true",className:"size-3.5 shrink-0 opacity-70",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:u("path",{d:"M12 8v4l3 2M12 21a9 9 0 1 1 0-18 9 9 0 0 1 0 18Z"})}),u("span",{className:"truncate font-mono",children:Y.sql})]})},`${Y.at.toString()}:${Y.sql}`))})]}),e[39]=t,e[40]=o,e[41]=i,e[42]=_,e[43]=L,e[44]=p,e[45]=O):O=e[45];let U;e[46]!==M||e[47]!==K||e[48]!==O?(U=W("div",{className:B,children:[M,K,O]}),e[46]=M,e[47]=K,e[48]=O,e[49]=U):U=e[49];let X;return e[50]!==F||e[51]!==U?(X=W("aside",{className:R,children:[F,U]}),e[50]=F,e[51]=U,e[52]=X):X=e[52],X},ke=l=>`border-b-2 px-3 py-2 text-sm outline-none transition-colors ${l?"border-foreground font-medium text-foreground":"border-transparent text-muted-foreground hover:text-foreground"}`,ys=l=>{const e=G(16),{chatOpen:n,onToggle:t}=l,s=Z();let o;e[0]!==s?(o=s("Ask about your data"),e[0]=s,e[1]=o):o=e[1];const r=`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"}`;let i;e[2]!==s?(i=s("Ask about your data"),e[2]=s,e[3]=i):i=e[3];let c;e[4]===Symbol.for("react.memo_cache_sentinel")?(c=u("svg",{"aria-hidden":"true",className:"size-4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:u("path",{d:"M21 12a8 8 0 0 1-8 8H7l-4 3 1.2-4.2A8 8 0 1 1 21 12Z"})}),e[4]=c):c=e[4];let a;e[5]!==s?(a=s("Assistant"),e[5]=s,e[6]=a):a=e[6];let d;e[7]!==a?(d=u("span",{className:"text-xs",children:a}),e[7]=a,e[8]=d):d=e[8];let m;return e[9]!==n||e[10]!==t||e[11]!==o||e[12]!==r||e[13]!==i||e[14]!==d?(m=W("button",{"aria-label":o,"aria-pressed":n,className:r,"data-testid":"sql-chat-toggle",onClick:t,title:i,type:"button",children:[c,d]}),e[9]=n,e[10]=t,e[11]=o,e[12]=r,e[13]=i,e[14]=d,e[15]=m):m=e[15],m},Ss=l=>{const e=G(11),{onToggle:n,splitView:t}=l,s=Z();let o;e[0]!==s?(o=s("Split editor and results"),e[0]=s,e[1]=o):o=e[1];const r=`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"}`;let i;e[2]!==s?(i=s("Split editor and results"),e[2]=s,e[3]=i):i=e[3];let c;e[4]===Symbol.for("react.memo_cache_sentinel")?(c=W("svg",{"aria-hidden":"true",className:"size-4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.7,viewBox:"0 0 24 24",children:[u("rect",{height:"16",rx:"2",width:"18",x:"3",y:"4"}),u("path",{d:"M12 4v16"})]}),e[4]=c):c=e[4];let a;return e[5]!==n||e[6]!==t||e[7]!==o||e[8]!==r||e[9]!==i?(a=u("button",{"aria-label":o,"aria-pressed":t,className:r,"data-testid":"sql-split-toggle",onClick:n,title:i,type:"button",children:c}),e[5]=n,e[6]=t,e[7]=o,e[8]=r,e[9]=i,e[10]=a):a=e[10],a},ws=l=>{const e=G(8),{disabled:n,onExplainPlan:t,onExplainSql:s,pane:o}=l,r=Z();if(o==="explain"){let c;return e[0]!==n||e[1]!==t||e[2]!==r?(c=t===void 0?null:u("button",{className:"inline-flex items-center rounded-md border border-border px-3 py-1.5 text-xs font-medium text-foreground outline-none transition-colors hover:bg-accent focus-visible:bg-accent disabled:pointer-events-none disabled:opacity-50","data-testid":"sql-explain-plan",disabled:n,onClick:t,type:"button",children:r("Read this plan")}),e[0]=n,e[1]=t,e[2]=r,e[3]=c):c=e[3],c}let i;return e[4]!==n||e[5]!==s||e[6]!==r?(i=s===void 0?null:u("button",{className:"inline-flex items-center rounded-md border border-border px-3 py-1.5 text-xs font-medium text-foreground outline-none transition-colors hover:bg-accent focus-visible:bg-accent disabled:pointer-events-none disabled:opacity-50","data-testid":"sql-explain-query",disabled:n,onClick:s,type:"button",children:r("Explain this query")}),e[4]=n,e[5]=s,e[6]=r,e[7]=i):i=e[7],i},Cs=l=>{const e=G(8),{onRun:n,running:t}=l,s=Z();let o;e[0]!==t||e[1]!==s?(o=s(t?"Running…":"Run"),e[0]=t,e[1]=s,e[2]=o):o=e[2];let r;e[3]===Symbol.for("react.memo_cache_sentinel")?(r=u("kbd",{className:"rounded border border-primary-foreground/30 px-1 font-sans text-[10px]",children:"⌘↵"}),e[3]=r):r=e[3];let i;return e[4]!==n||e[5]!==t||e[6]!==o?(i=W("button",{className:"inline-flex items-center gap-1.5 rounded-md bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground outline-none transition-colors hover:bg-primary/90 focus-visible:bg-primary/90 disabled:pointer-events-none disabled:opacity-50","data-testid":"sql-run",disabled:t,onClick:n,type:"button",children:[o,r]}),e[4]=n,e[5]=t,e[6]=o,e[7]=i):i=e[7],i},Es=l=>{const e=G(35),{onInferChart:n,onShowChart:t,onShowExplain:s,onShowResults:o,pane:r,result:i,rpc:c}=l,a=Z(),d=r==="results";let m;e[0]!==d?(m=ke(d),e[0]=d,e[1]=m):m=e[1];let f;e[2]!==a?(f=a("Results"),e[2]=a,e[3]=f):f=e[3];let h;e[4]!==o||e[5]!==m||e[6]!==f?(h=u("button",{className:m,"data-testid":"sql-tab-results",onClick:o,type:"button",children:f}),e[4]=o,e[5]=m,e[6]=f,e[7]=h):h=e[7];const g=r==="chart";let L;e[8]!==g?(L=ke(g),e[8]=g,e[9]=L):L=e[9];let v;e[10]!==a?(v=a("Chart"),e[10]=a,e[11]=v):v=e[11];let S;e[12]!==t||e[13]!==L||e[14]!==v?(S=u("button",{className:L,"data-testid":"sql-tab-chart",onClick:t,type:"button",children:v}),e[12]=t,e[13]=L,e[14]=v,e[15]=S):S=e[15];let p;e[16]!==n||e[17]!==r||e[18]!==i||e[19]!==c||e[20]!==a?(p=!c.unavailable&&r==="chart"&&i!==null&&u("button",{className:ke(!1),"data-testid":"sql-infer-chart",disabled:c.pending("chart"),onClick:n,type:"button",children:c.pending("chart")?a("Thinking…"):a("Suggest chart")}),e[16]=n,e[17]=r,e[18]=i,e[19]=c,e[20]=a,e[21]=p):p=e[21];const N=r==="explain";let x;e[22]!==N?(x=ke(N),e[22]=N,e[23]=x):x=e[23];let b;e[24]!==a?(b=a("Explain"),e[24]=a,e[25]=b):b=e[25];let y;e[26]!==s||e[27]!==x||e[28]!==b?(y=u("button",{className:x,"data-testid":"sql-tab-explain",onClick:s,type:"button",children:b}),e[26]=s,e[27]=x,e[28]=b,e[29]=y):y=e[29];let C;return e[30]!==y||e[31]!==h||e[32]!==S||e[33]!==p?(C=W(xe,{children:[h,S,p,y]}),e[30]=y,e[31]=h,e[32]=S,e[33]=p,e[34]=C):C=e[34],C},Ns=l=>{const e=G(9),{onSelectStatement:n,script:t}=l;let s;if(e[0]!==n||e[1]!==t.runs||e[2]!==t.selected){let r;e[4]!==n||e[5]!==t.selected?(r=(i,c)=>u("button",{"aria-pressed":c===t.selected,className:`rounded-md border px-2 py-0.5 font-mono text-[11px] outline-none transition-colors ${c===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-${c.toString()}`,onClick:()=>{n(c)},title:i.sql,type:"button",children:c+1},`${c.toString()}:${i.sql}`),e[4]=n,e[5]=t.selected,e[6]=r):r=e[6],s=t.runs.map(r),e[0]=n,e[1]=t.runs,e[2]=t.selected,e[3]=s}else s=e[3];let o;return e[7]!==s?(o=u("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:s}),e[7]=s,e[8]=o):o=e[8],o},ks=l=>{const e=G(9),{error:n,onDebugError:t,rpc:s}=l,o=Z();let r;e[0]!==n?(r=u(Tt,{className:"w-full font-mono text-xs",testId:"sql-error",variant:"destructive",children:n}),e[0]=n,e[1]=r):r=e[1];let i;e[2]!==t||e[3]!==s||e[4]!==o?(i=!s.unavailable&&t!==void 0&&W("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:s.pending("chat"),onClick:t,type:"button",children:[u("svg",{"aria-hidden":"true",className:"size-3.5",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:u("path",{d:"M21 12a8 8 0 0 1-8 8H7l-4 3 1.2-4.2A8 8 0 1 1 21 12Z"})}),s.pending("chat")?o("Thinking…"):o("Debug with AI")]}),e[2]=t,e[3]=s,e[4]=o,e[5]=i):i=e[5];let c;return e[6]!==r||e[7]!==i?(c=W("div",{className:"m-3 flex flex-col items-start gap-2",children:[r,i]}),e[6]=r,e[7]=i,e[8]=c):c=e[8],c},Ts=l=>{const e=G(18),{chart:n,durationMs:t,pane:s,result:o}=l,r=Z();let i;e[0]!==n||e[1]!==s||e[2]!==o?(i=s==="chart"?u(Et,{axes:n,result:o}):u(Nt,{result:o}),e[0]=n,e[1]=s,e[2]=o,e[3]=i):i=e[3];let c;e[4]!==o.rowCount||e[5]!==o.rows||e[6]!==o.truncated||e[7]!==r?(c=o.truncated?r("Showing the first {max} rows.",{max:o.rows.length}):r("{count} rows",{count:o.rowCount}),e[4]=o.rowCount,e[5]=o.rows,e[6]=o.truncated,e[7]=r,e[8]=c):c=e[8];let a;e[9]!==t||e[10]!==r?(a=t!==void 0&&` · ${r("{ms} ms",{ms:Math.round(t)})}`,e[9]=t,e[10]=r,e[11]=a):a=e[11];let d;e[12]!==c||e[13]!==a?(d=W("p",{className:"border-t border-border px-3 py-1.5 text-xs text-muted-foreground","data-testid":"sql-count",children:[c,a]}),e[12]=c,e[13]=a,e[14]=d):d=e[14];let m;return e[15]!==i||e[16]!==d?(m=W("div",{"data-testid":"sql-result",children:[i,d]}),e[15]=i,e[16]=d,e[17]=m):m=e[17],m},Rs=l=>{const e=G(13),{chart:n,durationMs:t,error:s,onDebugError:o,pane:r,result:i,rpc:c}=l,a=Z();if(s!==null){let m;return e[0]!==s||e[1]!==o||e[2]!==c?(m=u(ks,{error:s,onDebugError:o,rpc:c}),e[0]=s,e[1]=o,e[2]=c,e[3]=m):m=e[3],m}if(i===null){let m;e[4]!==a?(m=a("Click Run to execute your query."),e[4]=a,e[5]=m):m=e[5];let f;return e[6]!==m?(f=u("p",{className:"p-4 text-sm text-muted-foreground","data-testid":"sql-empty",children:m}),e[6]=m,e[7]=f):f=e[7],f}let d;return e[8]!==n||e[9]!==t||e[10]!==r||e[11]!==i?(d=u(Ts,{chart:n,durationMs:t,pane:r,result:i}),e[8]=n,e[9]=t,e[10]=r,e[11]=i,e[12]=d):d=e[12],d},Ls=l=>{const e=G(63),{rpc:n,chart:t,className:s,durationMs:o,error:r,onFormat:i,onInferChart:c,onRun:a,onSelectStatement:d,onShardKeyChange:m,onShowChart:f,onShowExplain:h,onShowResults:g,chatOpen:L,onDebugError:v,onExplainPlan:S,onExplainSql:p,onToggleChat:N,onToggleSplit:x,pane:b,result:y,running:C,script:w,shardKey:_,splitView:R}=l,T=Z();let k;e[0]!==c||e[1]!==f||e[2]!==h||e[3]!==g||e[4]!==b||e[5]!==y||e[6]!==n?(k=u(Es,{onInferChart:c,onShowChart:f,onShowExplain:h,onShowResults:g,pane:b,result:y,rpc:n}),e[0]=c,e[1]=f,e[2]=h,e[3]=g,e[4]=b,e[5]=y,e[6]=n,e[7]=k):k=e[7];let E;e[8]!==L||e[9]!==N?(E=N!==void 0&&u(ys,{chatOpen:L,onToggle:N}),e[8]=L,e[9]=N,e[10]=E):E=e[10];let q;e[11]!==x||e[12]!==R?(q=u(Ss,{onToggle:x,splitView:R}),e[11]=x,e[12]=R,e[13]=q):q=e[13];let A;e[14]!==y?(A=y!==null&&y.columns.length>0&&u(Rt,{columns:y.columns,name:"query-result",rows:y.rows}),e[14]=y,e[15]=A):A=e[15];let $;e[16]!==T?($=T("Format"),e[16]=T,e[17]=$):$=e[17];let F;e[18]!==i||e[19]!==C||e[20]!==$?(F=u("button",{className:"inline-flex items-center rounded-md border border-border px-3 py-1.5 text-xs font-medium text-foreground outline-none transition-colors hover:bg-accent focus-visible:bg-accent disabled:pointer-events-none disabled:opacity-50","data-testid":"sql-format",disabled:C,onClick:i,type:"button",children:$}),e[18]=i,e[19]=C,e[20]=$,e[21]=F):F=e[21];let B;e[22]!==n||e[23]!==C?(B=C||n.pending("chat"),e[22]=n,e[23]=C,e[24]=B):B=e[24];let H;e[25]!==S||e[26]!==p||e[27]!==b||e[28]!==B?(H=u(ws,{disabled:B,onExplainPlan:S,onExplainSql:p,pane:b}),e[25]=S,e[26]=p,e[27]=b,e[28]=B,e[29]=H):H=e[29];let P;e[30]!==m||e[31]!==_?(P=u(kt,{onChange:m,testId:"sql-shard-input",value:_}),e[30]=m,e[31]=_,e[32]=P):P=e[32];let Q;e[33]!==a||e[34]!==C?(Q=u(Cs,{onRun:a,running:C}),e[33]=a,e[34]=C,e[35]=Q):Q=e[35];let M;e[36]!==Q||e[37]!==E||e[38]!==q||e[39]!==A||e[40]!==F||e[41]!==H||e[42]!==P?(M=W("div",{className:"ms-auto flex items-center gap-2",children:[E,q,A,F,H,P,Q]}),e[36]=Q,e[37]=E,e[38]=q,e[39]=A,e[40]=F,e[41]=H,e[42]=P,e[43]=M):M=e[43];let I;e[44]!==k||e[45]!==M?(I=W("div",{className:"flex shrink-0 items-center gap-2 border-b border-border pe-2",children:[k,M]}),e[44]=k,e[45]=M,e[46]=I):I=e[46];let D;e[47]!==d||e[48]!==w?(D=w!==void 0&&u(Ns,{onSelectStatement:d,script:w}),e[47]=d,e[48]=w,e[49]=D):D=e[49];let z;e[50]!==t||e[51]!==o||e[52]!==r||e[53]!==v||e[54]!==b||e[55]!==y||e[56]!==n?(z=u("div",{className:"min-h-0 flex-1 overflow-auto",children:u(Rs,{chart:t,durationMs:o,error:r,onDebugError:v,pane:b,result:y,rpc:n})}),e[50]=t,e[51]=o,e[52]=r,e[53]=v,e[54]=b,e[55]=y,e[56]=n,e[57]=z):z=e[57];let j;return e[58]!==s||e[59]!==I||e[60]!==D||e[61]!==z?(j=W("div",{className:s,children:[I,D,z]}),e[58]=s,e[59]=I,e[60]=D,e[61]=z,e[62]=j):j=e[62],j},_s=(l,e)=>l.trim()===""?e:(l.split(`
|
|
11
|
+
`)[0]??l).slice(0,24),qs=l=>{l?.focus(),l?.select()},Is=l=>{const e=G(14),{initial:n,onCancel:t,onCommit:s,placeholder:o,testId:r}=l,i=Z();let c;e[0]!==s?(c=g=>{s(g.currentTarget.value.trim())},e[0]=s,e[1]=c):c=e[1];const a=c;let d;e[2]!==t||e[3]!==s?(d=g=>{g.key==="Enter"?s(g.currentTarget.value.trim()):g.key==="Escape"&&t()},e[2]=t,e[3]=s,e[4]=d):d=e[4];const m=d;let f;e[5]!==i?(f=i("Tab title"),e[5]=i,e[6]=f):f=e[6];let h;return e[7]!==n||e[8]!==a||e[9]!==m||e[10]!==o||e[11]!==f||e[12]!==r?(h=u("input",{"aria-label":f,className:"w-40 rounded border border-ring bg-background px-1 py-0.5 text-xs outline-none","data-testid":r,defaultValue:n,onBlur:a,onKeyDown:m,placeholder:o,ref:qs,type:"text"}),e[7]=n,e[8]=a,e[9]=m,e[10]=o,e[11]=f,e[12]=r,e[13]=h):h=e[13],h},As=l=>{const e=G(29),{idBase:n,onDiscard:t,onKeep:s}=l,o=Z(),r=`sql-tab-close-prompt-${n}`;let i;e[0]!==o?(i=o("Discard?"),e[0]=o,e[1]=i):i=e[1];let c;e[2]!==i?(c=u("span",{className:"text-[11px] text-muted-foreground",children:i}),e[2]=i,e[3]=c):c=e[3];let a;e[4]!==o?(a=o("Discard changes"),e[4]=o,e[5]=a):a=e[5];const d=`sql-tab-close-confirm-${n}`;let m;e[6]!==o?(m=o("Discard changes"),e[6]=o,e[7]=m):m=e[7];let f;e[8]===Symbol.for("react.memo_cache_sentinel")?(f=u("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2.4,viewBox:"0 0 24 24",children:u("path",{d:"M5 13l4 4L19 7"})}),e[8]=f):f=e[8];let h;e[9]!==t||e[10]!==a||e[11]!==d||e[12]!==m?(h=u("button",{"aria-label":a,className:"flex size-5 items-center justify-center rounded text-destructive hover:bg-destructive/10","data-testid":d,onClick:t,title:m,type:"button",children:f}),e[9]=t,e[10]=a,e[11]=d,e[12]=m,e[13]=h):h=e[13];let g;e[14]!==o?(g=o("Keep editing"),e[14]=o,e[15]=g):g=e[15];const L=`sql-tab-close-cancel-${n}`;let v;e[16]!==o?(v=o("Keep editing"),e[16]=o,e[17]=v):v=e[17];let S;e[18]===Symbol.for("react.memo_cache_sentinel")?(S=u("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2.4,viewBox:"0 0 24 24",children:u("path",{d:"M6 6l12 12M18 6 6 18"})}),e[18]=S):S=e[18];let p;e[19]!==s||e[20]!==L||e[21]!==v||e[22]!==g?(p=u("button",{"aria-label":g,className:"flex size-5 items-center justify-center rounded text-muted-foreground hover:bg-accent","data-testid":L,onClick:s,title:v,type:"button",children:S}),e[19]=s,e[20]=L,e[21]=v,e[22]=g,e[23]=p):p=e[23];let N;return e[24]!==r||e[25]!==p||e[26]!==c||e[27]!==h?(N=W("span",{className:"flex shrink-0 items-center gap-1","data-testid":r,role:"group",children:[c,h,p]}),e[24]=r,e[25]=p,e[26]=c,e[27]=h,e[28]=N):N=e[28],N},Ds=l=>{const e=G(47),{active:n,canClose:t,onClose:s,onMenu:o,onRename:r,onSelect:i,tab:c}=l,a=Z(),[d,m]=te(!1),[f,h]=te(!1);let g;e[0]!==o||e[1]!==c.id?(g=D=>{o(c.id,D)},e[0]=o,e[1]=c.id,e[2]=g):g=e[2];const L=g;let v;e[3]!==i||e[4]!==c.id?(v=()=>{i(c.id)},e[3]=i,e[4]=c.id,e[5]=v):v=e[5];const S=v;let p;e[6]===Symbol.for("react.memo_cache_sentinel")?(p=()=>{m(!0)},e[6]=p):p=e[6];const N=p;let x;e[7]!==s||e[8]!==c?(x=D=>{D.stopPropagation(),ft(c)?h(!0):s(c.id)},e[7]=s,e[8]=c,e[9]=x):x=e[9];const b=x;let y;e[10]!==s||e[11]!==c.id?(y=D=>{D.stopPropagation(),h(!1),s(c.id)},e[10]=s,e[11]=c.id,e[12]=y):y=e[12];const C=y;let w;e[13]===Symbol.for("react.memo_cache_sentinel")?(w=D=>{D.stopPropagation(),h(!1)},e[13]=w):w=e[13];const _=w;let R;e[14]!==r||e[15]!==c.id?(R=D=>{r(c.id,D),m(!1)},e[14]=r,e[15]=c.id,e[16]=R):R=e[16];const T=R;let k;e[17]===Symbol.for("react.memo_cache_sentinel")?(k=()=>{m(!1)},e[17]=k):k=e[17];const E=k;let q;e[18]!==c.name?(q=c.name.trim(),e[18]=c.name,e[19]=q):q=e[19];const A=q;let $;e[20]!==a||e[21]!==c.sql?($=_s(c.sql,a("Untitled")),e[20]=a,e[21]=c.sql,e[22]=$):$=e[22];const F=$,B=n?"bg-background text-foreground":"bg-muted/40 text-muted-foreground hover:text-foreground";let H;e[23]!==B?(H=ae("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]=H):H=e[24];const P=`sql-tab-${c.id}`;let Q;e[25]!==n||e[26]!==T||e[27]!==A||e[28]!==F||e[29]!==d||e[30]!==S||e[31]!==a||e[32]!==c.id?(Q=d?u(Is,{initial:A,onCancel:E,onCommit:T,placeholder:F,testId:`sql-tab-rename-${c.id}`}):u("button",{"aria-pressed":n,className:"max-w-40 truncate py-1.5 outline-none","data-testid":`sql-tab-select-${c.id}`,onClick:S,onDoubleClick:N,title:a("Double-click to rename"),type:"button",children:A===""?F:A}),e[25]=n,e[26]=T,e[27]=A,e[28]=F,e[29]=d,e[30]=S,e[31]=a,e[32]=c.id,e[33]=Q):Q=e[33];let M;e[34]!==t||e[35]!==C||e[36]!==f||e[37]!==b||e[38]!==a||e[39]!==c.id?(M=t&&(f?u(As,{idBase:c.id,onDiscard:C,onKeep:_}):u("button",{"aria-label":a("Close tab"),className:"flex size-5 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-destructive/10 hover:text-destructive","data-testid":`sql-tab-close-${c.id}`,onClick:b,title:a("Close tab"),type:"button",children:u("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,viewBox:"0 0 24 24",children:u("path",{d:"M6 6l12 12M18 6 6 18"})})})),e[34]=t,e[35]=C,e[36]=f,e[37]=b,e[38]=a,e[39]=c.id,e[40]=M):M=e[40];let I;return e[41]!==L||e[42]!==H||e[43]!==P||e[44]!==Q||e[45]!==M?(I=W("div",{className:H,"data-testid":P,onContextMenu:L,children:[Q,M]}),e[41]=L,e[42]=H,e[43]=P,e[44]=Q,e[45]=M,e[46]=I):I=e[46],I},Os=l=>{const e=G(43),{model:n,onSelect:t}=l,s=Z(),{activeTab:o,addEditorTab:r,cancelBulk:i,closeEditorTab:c,closeTabMenu:a,confirmBulk:d,menuStyle:m,onBackdropContextMenu:f,onCloseAll:h,onCloseOthers:g,onCloseToRight:L,openTabMenu:v,pendingBulk:S,renameTab:p,tabMenu:N,tabs:x}=n;let b;if(e[0]!==o||e[1]!==c||e[2]!==t||e[3]!==v||e[4]!==p||e[5]!==x){let q;e[7]!==o||e[8]!==c||e[9]!==t||e[10]!==v||e[11]!==p||e[12]!==x.length?(q=A=>u(Ds,{active:A.id===o.id,canClose:x.length>1,onClose:c,onMenu:v,onRename:p,onSelect:t,tab:A},A.id),e[7]=o,e[8]=c,e[9]=t,e[10]=v,e[11]=p,e[12]=x.length,e[13]=q):q=e[13],b=x.map(q),e[0]=o,e[1]=c,e[2]=t,e[3]=v,e[4]=p,e[5]=x,e[6]=b}else b=e[6];let y;e[14]!==s?(y=s("New tab"),e[14]=s,e[15]=y):y=e[15];const C=x.length>=He;let w;e[16]!==s?(w=s("New tab"),e[16]=s,e[17]=w):w=e[17];let _;e[18]===Symbol.for("react.memo_cache_sentinel")?(_=u("svg",{"aria-hidden":"true",className:"size-4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.7,viewBox:"0 0 24 24",children:u("path",{d:"M12 5v14M5 12h14"})}),e[18]=_):_=e[18];let R;e[19]!==r||e[20]!==y||e[21]!==C||e[22]!==w?(R=u("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:C,onClick:r,title:w,type:"button",children:_}),e[19]=r,e[20]=y,e[21]=C,e[22]=w,e[23]=R):R=e[23];let T;e[24]!==b||e[25]!==R?(T=W("div",{className:"flex shrink-0 items-stretch overflow-x-auto border-b border-border bg-muted/30","data-testid":"sql-tab-strip",role:"tablist",children:[b,R]}),e[24]=b,e[25]=R,e[26]=T):T=e[26];let k;e[27]!==i||e[28]!==a||e[29]!==d||e[30]!==m||e[31]!==f||e[32]!==h||e[33]!==g||e[34]!==L||e[35]!==S||e[36]!==s||e[37]!==N||e[38]!==x?(k=N!==null&&W(xe,{children:[u("div",{className:"fixed inset-0 z-40","data-testid":"sql-tab-menu-backdrop",onClick:a,onContextMenu:f,role:"presentation"}),u("div",{className:"fixed z-50 min-w-44 rounded-md border border-border bg-popover py-1 text-popover-foreground shadow-md","data-testid":"sql-tab-menu",role:"menu",style:m,children:S===null?W(xe,{children:[u("button",{className:"flex w-full items-center px-3 py-1.5 text-start text-xs outline-none hover:bg-accent focus-visible:bg-accent disabled:pointer-events-none disabled:opacity-40","data-testid":"sql-tab-menu-close-others",disabled:x.length<=1,onClick:g,role:"menuitem",type:"button",children:s("Close other tabs")}),u("button",{className:"flex w-full items-center px-3 py-1.5 text-start text-xs outline-none hover:bg-accent focus-visible:bg-accent disabled:pointer-events-none disabled:opacity-40","data-testid":"sql-tab-menu-close-right",disabled:x.findIndex(q=>q.id===N.id)>=x.length-1,onClick:L,role:"menuitem",type:"button",children:s("Close tabs to the right")}),u("button",{className:"flex w-full items-center px-3 py-1.5 text-start text-xs outline-none hover:bg-accent focus-visible:bg-accent","data-testid":"sql-tab-menu-close-all",onClick:h,role:"menuitem",type:"button",children:s("Close all tabs")})]}):W("div",{className:"px-3 py-1.5","data-testid":"sql-tab-menu-confirm",children:[u("p",{className:"pb-1.5 text-xs text-muted-foreground",children:s("Discard unsaved tabs?")}),W("div",{className:"flex items-center gap-1.5",children:[u("button",{className:"rounded px-2 py-1 text-xs font-medium text-destructive outline-none hover:bg-destructive/10 focus-visible:bg-destructive/10","data-testid":"sql-tab-menu-confirm-discard",onClick:d,type:"button",children:s("Discard")}),u("button",{className:"rounded px-2 py-1 text-xs text-muted-foreground outline-none hover:bg-accent focus-visible:bg-accent","data-testid":"sql-tab-menu-confirm-cancel",onClick:i,type:"button",children:s("Cancel")})]})]})})]}),e[27]=i,e[28]=a,e[29]=d,e[30]=m,e[31]=f,e[32]=h,e[33]=g,e[34]=L,e[35]=S,e[36]=s,e[37]=N,e[38]=x,e[39]=k):k=e[39];let E;return e[40]!==T||e[41]!==k?(E=W(xe,{children:[T,k]}),e[40]=T,e[41]=k,e[42]=E):E=e[42],E},Ms=Ie(qe.runSql),$s="lunora-studio-sql-split-view",Bs=()=>Se(mt[0]?.sql??""),Ps=()=>performance.now(),Ws=()=>{const l=G(2);let e;l[0]===Symbol.for("react.memo_cache_sentinel")?(e=new Map,l[0]=e):e=l[0];const n=de(e);let t;return l[1]===Symbol.for("react.memo_cache_sentinel")?(t={advance:s=>{n.current.set(s,(n.current.get(s)??0)+1)},begin:s=>{const o=n.current.get(s)??0;return()=>(n.current.get(s)??0)===o}},l[1]=t):t=l[1],t},Hs=(l,e)=>{const n=l.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?")]},Te=l=>l.tables.map(e=>({columns:[...l.columns[e]??[]],table:e})),ao=({initialShardKey:l,now:e=Ps})=>{const n=$e(),t=Gn(Bs),{activeTab:s,openEditorTab:o,output:r,patchActiveOutput:i,patchActiveTab:c,setActiveTabId:a,unlinkQuery:d}=t,m=Ws(),h=ts({loadIntoActiveTab:(J,le)=>{m.advance(s.id),c({activeId:le,sql:J}),i({chart:void 0,durationMs:void 0,error:null,failed:void 0,result:null,running:!1,script:void 0})},unlinkQuery:d}),{recordHistory:g,updateQuerySql:L}=h,v=s.sql,{activeId:S}=s,{chart:p,error:N,failed:x,result:b,running:y}=r,C=r.pane,[w,_]=te(l??""),[R,T]=Be($s,!1),k=Z(),E=bt(),{probe:q,schema:A}=Dn(w),$=Ze(J=>{c({sql:J}),S!==null&&L(S,J)},[S,c,L]),F=E?.setHasEditor;ue(()=>{if(F!==void 0)return F(!0),()=>{F(!1)}},[F]);const B=E?.insertRequest,H=E?.takeInsert;ue(()=>{B===void 0||H===void 0||(H(B.id),v.trim()===""&&S===null?$(B.sql):o(B.sql)||c({activeId:null,sql:v.trim()===""?B.sql:`${v.trimEnd()}
|
|
11
12
|
|
|
12
|
-
${B.sql}`}))},[S,v,B,
|
|
13
|
+
${B.sql}`}))},[S,v,B,o,c,H,$]);const P=xn(v,A,w),Q=gt(w),M=()=>{if(b===null)return;ie((async()=>{const le=await Q.inferChart({columns:b.columns,rowCount:b.rowCount,types:Object.fromEntries(b.columns.map(ne=>[ne,typeof(b.rows[0]?.[ne]??"")]))});i({chart:le})})())},I=async J=>{const le=e();try{const ne=await n.query(Ms,{sql:J},Re(w)),ce=e()-le;return g(J),{durationMs:ce,error:null,result:ne,sql:J}}catch(ne){return{error:yt(ne),result:null,sql:J}}},D=async J=>{if(v.trim()==="")return;const le=m.begin(s.id);i({running:!0,...J==="explain"?{explained:v.trim()}:{}});const ne=J==="explain"?Me(jt(v),0):it(v),ce=[];for(const we of ne){const pt={error:we.rejection?.message??"",result:null,sql:we.sql};ce.push(we.rejection===void 0?await I(we.sql):pt)}if(St(w),!le())return;const Qe=Math.max(ce.length-1,0),me=ce[Qe];i({chart:void 0,durationMs:me?.durationMs,error:me?.error??null,failed:me?.error===null||me===void 0?void 0:{error:me.error,sql:me.sql},pane:J,result:me?.result??null,running:!1,script:ce.length>1?{runs:ce,selected:Qe}:void 0})},z=J=>{const le=r.script?.runs,ne=le?.[J];le===void 0||ne===void 0||i({chart:void 0,durationMs:ne.durationMs,error:ne.error,failed:ne.error===null?void 0:{error:ne.error,sql:ne.sql},result:ne.result,script:{runs:le,selected:J}})},j=()=>{ie(D("results"))},K=Bn({inlineEditEnabled:!Q.unavailable,onSubmit:()=>{ie(D(r.pane))},probe:q,schema:A,setDraft:$}),{closeAutocomplete:O,closeInlineEdit:U}=K,X=()=>{$(Vt(v))},Y=J=>{O(),U(),a(J)},oe=()=>{i({pane:"results"})},re=()=>{ie(D("explain"))},pe=()=>{i({pane:"chart"})},ve=()=>{T(!R)},he=()=>{if(E!==void 0){if(E.open){E.close();return}E.openAssistant({schema:Te(A),shardKey:w,suggestions:Hs(A,k),title:k("SQL console")})}},ye=J=>{E?.rebindShard(w,J),_(J)},be=()=>{x!==void 0&&E?.openAssistant({ask:k(`This statement failed:
|
|
13
14
|
{sql}
|
|
14
15
|
|
|
15
16
|
The database said: {error}
|
|
16
17
|
|
|
17
|
-
Why, and what should it be?`,{error:x.error,sql:x.sql}),schema:Te(
|
|
18
|
-
{statement}`,{statement:J}),schema:Te(
|
|
19
|
-
`);
|
|
18
|
+
Why, and what should it be?`,{error:x.error,sql:x.sql}),schema:Te(A),shardKey:w,title:k("Debug query")})},V=()=>{const J=v.trim();J!==""&&E?.openAssistant({ask:k(`Explain what this query does, step by step:
|
|
19
|
+
{statement}`,{statement:J}),schema:Te(A),shardKey:w,title:k("Explain query")})},ee=()=>{const J=r.explained;if(b===null||b.rows.length===0||J===void 0)return;const le=b.rows.map(ne=>b.columns.map(ce=>vt(ne[ce])).join(" | ")).join(`
|
|
20
|
+
`);E?.openAssistant({ask:k(`SQLite planned this query:
|
|
20
21
|
{statement}
|
|
21
22
|
|
|
22
23
|
as:
|
|
23
24
|
{plan}
|
|
24
25
|
|
|
25
|
-
What is it doing, and is anything here slow?`,{plan:le,statement:J}),schema:Te(
|
|
26
|
+
What is it doing, and is anything here slow?`,{plan:le,statement:J}),schema:Te(A),shardKey:w,title:k("Read plan")})},se=R?"flex min-h-0 flex-1 flex-row":"flex min-h-0 flex-1 flex-col",fe=R?"flex w-2/5 min-h-0 min-w-0 shrink-0 flex-col border-s border-border":"flex h-2/5 min-h-0 shrink-0 flex-col border-t border-border";return W("div",{className:"flex h-full min-w-0","data-testid":"lunora-sql-editor",children:[u(vs,{activeId:S,history:h.history,listRef:h.listRef,onClearHistory:h.clearHistory,onDelete:h.deleteQuery,onLoadHistory:h.loadFromHistory,onLoadTemplate:h.loadTemplate,onNew:h.newQuery,onRename:h.renameQuery,onSearchChange:h.onSearchChange,onSelect:h.selectQuery,onToggleRememberHistory:h.setRememberHistory,queries:h.queries,rememberHistory:h.rememberHistory,rpc:Q,search:h.search}),W("div",{className:"flex min-w-0 flex-1 flex-col",children:[u(Os,{model:t,onSelect:Y}),W("div",{className:se,children:[u(ps,{autocomplete:K.autocompleteState,diagnostics:P,draft:v,editorRef:K.editorRef,failed:x,gutterRef:K.gutterRef,handlers:K.handlers,inlineEdit:K.inlineEdit,listboxId:K.listboxId,onAcceptInlineEdit:K.acceptInlineEdit,onCancelInlineEdit:K.closeInlineEdit,onGenerated:$,onPickSuggestion:K.onPickSuggestion,onRevealDiagnostic:K.revealDiagnostic,overlayRef:K.overlayRef,rpc:Q}),u(Ls,{chart:p,chatOpen:E?.open===!0,className:fe,durationMs:r.durationMs,error:N,onDebugError:x===void 0?void 0:be,onExplainPlan:E===void 0||E.unavailable||C!=="explain"?void 0:ee,onExplainSql:E===void 0||E.unavailable?void 0:V,onFormat:X,onInferChart:M,onRun:j,onSelectStatement:z,onShardKeyChange:ye,onShowChart:pe,onShowExplain:re,onShowResults:oe,onToggleChat:E===void 0||E.unavailable?void 0:he,onToggleSplit:ve,pane:C,result:b,rpc:Q,running:y,script:r.script,shardKey:w,splitView:R})]})]})]})};export{ao as SqlEditorPanel};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as k}from"react/compiler-runtime";import{useNavigate as F,useRouter as M,useSearch as P}from"@tanstack/react-router";import{useState as Q,useEffect as A}from"react";import{T as w}from"../packem_shared/storage-tier-C2mKwYRj.mjs";import{u as q}from"../packem_shared/use-mirrored-ref-CVDf2z1M.mjs";import{u as J}from"../packem_shared/use-studio-client-DCA50tF2.mjs";import{useT as K}from"../packem_shared/DEFAULT_LOCALE-BQ3jRT74.mjs";import{s as L,d as D}from"../packem_shared/data-view-params-C-_G-biH.mjs";import{f as m}from"../packem_shared/internal-hIuTpSbx.mjs";import{l as O,s as I}from"../packem_shared/browser-storage-BH1MxLZs.mjs";import{DataBrowser as X}from"../packem_shared/DataBrowser-BrRWqnCr.mjs";import{GlobalDataBrowser as Y}from"../packem_shared/GlobalDataBrowser-
|
|
1
|
+
import{c as k}from"react/compiler-runtime";import{useNavigate as F,useRouter as M,useSearch as P}from"@tanstack/react-router";import{useState as Q,useEffect as A}from"react";import{T as w}from"../packem_shared/storage-tier-C2mKwYRj.mjs";import{u as q}from"../packem_shared/use-mirrored-ref-CVDf2z1M.mjs";import{u as J}from"../packem_shared/use-studio-client-DCA50tF2.mjs";import{useT as K}from"../packem_shared/DEFAULT_LOCALE-BQ3jRT74.mjs";import{s as L,d as D}from"../packem_shared/data-view-params-C-_G-biH.mjs";import{f as m}from"../packem_shared/internal-hIuTpSbx.mjs";import{l as O,s as I}from"../packem_shared/browser-storage-BH1MxLZs.mjs";import{DataBrowser as X}from"../packem_shared/DataBrowser-BrRWqnCr.mjs";import{GlobalDataBrowser as Y}from"../packem_shared/GlobalDataBrowser-DB1B-WAN.mjs";import{jsx as v,jsxs as E}from"react/jsx-runtime";const N="lunora-studio-saved-queries",$=50,z=r=>r!==null&&typeof r=="object"&&typeof r.name=="string"&&typeof r.view=="object"&&r.view!==null,y=()=>O(N).filter(z),B=r=>{I(N,r)},H=(r,e)=>{const l=r.trim();if(l==="")return y();const n=[{name:l,view:e},...y().filter(o=>o.name!==l)].slice(0,$);return B(n),n},U=r=>{const e=y().filter(l=>l.name!==r);return B(e),e},W=r=>{const e=k(15),{onChange:l,tier:n}=r,o=K();let p;e[0]!==l?(p=S=>{l(S.target.value)},e[0]=l,e[1]=p):p=e[1];const u=p;let s;e[2]!==o?(s=o("Storage tier"),e[2]=o,e[3]=s):s=e[3];let d;e[4]!==s?(d=v("span",{className:"font-mono text-[11px] tracking-wide uppercase text-muted-foreground",children:s}),e[4]=s,e[5]=d):d=e[5];const g=w[n];let c,i;e[6]===Symbol.for("react.memo_cache_sentinel")?(c=v("option",{value:"shard",children:w.shard.label}),i=v("option",{value:"global",children:w.global.label}),e[6]=c,e[7]=i):(c=e[6],i=e[7]);let h;e[8]!==u||e[9]!==g.title||e[10]!==n?(h=E("select",{className:"h-8 w-full rounded-md border border-border bg-background px-2 text-sm outline-none focus-visible:border-ring","data-testid":"table-editor-schema",id:"table-editor-schema",onChange:u,title:g.title,value:n,children:[c,i]}),e[8]=u,e[9]=g.title,e[10]=n,e[11]=h):h=e[11];let f;return e[12]!==d||e[13]!==h?(f=E("label",{className:"flex w-full flex-col gap-1",htmlFor:"table-editor-schema",children:[d,h]}),e[12]=d,e[13]=h,e[14]=f):f=e[14],f},Z=()=>{try{m(globalThis.navigator.clipboard.writeText(globalThis.location.href))}catch{}},ge=({canGenerateRows:r=!1,editable:e=!1,initialShardKey:l})=>{const n=J(),o=F(),p=M(),u=P({strict:!1}),s=L(u),d=q(u),g=()=>p.state.location.pathname.split("/").findLast(Boolean)==="data",c=s.tier??"shard",i=s.table,[h,f]=Q(()=>y()),[S,C]=Q(()=>new Set);A(()=>{m((async()=>{try{const a=await n.listGlobalTables();C(new Set(a.map(t=>t.name)))}catch{}})())},[n]),A(()=>{c==="shard"&&i!==void 0&&S.has(i)&&m(o({replace:!0,search:a=>({...a,schema:"global"}),to:"/data"}))},[S,o,i,c]);const R=a=>{m(o({search:t=>({...t,schema:a==="global"?"global":void 0,table:void 0}),to:"/data"}))},T=(a,t)=>{g()&&m(o({search:b=>({schema:b.schema,search:t?.search,shard:b.shard,table:a}),to:"/data"}))},G=a=>{m(o({search:t=>({...t,schema:"global",table:a}),to:"/data"}))},_=a=>{const t=D(a),{current:b}=d;(b.filters??void 0)===t.filters&&(b.order??void 0)===t.order&&(b.search??void 0)===t.search&&(b.shard??void 0)===t.shard||!g()||m(o({replace:!0,search:V=>({...V,filters:t.filters,order:t.order,search:t.search,shard:t.shard}),to:"/data"}))},j={onApplyQuery:a=>{const t=D(a.view);m(o({search:()=>({filters:t.filters,order:t.order,schema:t.schema,search:t.search,shard:t.shard,table:t.table}),to:"/data"}))},onCopyLink:Z,onDeleteQuery:a=>{f(U(a))},onSaveQuery:(a,t)=>{f(H(a,t))},saved:h},x=v(W,{onChange:R,tier:c});return c==="global"?v(Y,{initialTable:i,onSelectTable:T,schemaSwitch:x}):v(X,{canGenerateRows:r,editable:e,globalTableNames:S,initialFilters:s.filters,initialOrderBy:s.orderBy,initialPins:u.pins,initialSearch:s.search,initialShardKey:s.shard??l,onNavigateToGlobal:G,onSelectTable:T,onViewChange:_,queryBar:j,schemaSwitch:x,tableParam:i})};export{ge as TableEditor};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{c as ie}from"react/compiler-runtime";import{useState as te}from"react";import{B as oe}from"../packem_shared/button-q0UYSmrn.mjs";import{C as re,a as ne}from"../packem_shared/card-By2O8ULa.mjs";import{I as pe}from"../packem_shared/input-CXhxesPC.mjs";import{useT as ae}from"../packem_shared/DEFAULT_LOCALE-BQ3jRT74.mjs";import{C as ue}from"../packem_shared/cf-links-
|
|
1
|
+
import{c as ie}from"react/compiler-runtime";import{useState as te}from"react";import{B as oe}from"../packem_shared/button-q0UYSmrn.mjs";import{C as re,a as ne}from"../packem_shared/card-By2O8ULa.mjs";import{I as pe}from"../packem_shared/input-CXhxesPC.mjs";import{useT as ae}from"../packem_shared/DEFAULT_LOCALE-BQ3jRT74.mjs";import{C as ue}from"../packem_shared/cf-links-BPy1pJRO.mjs";import{g as he,b as ge,f as xe}from"../packem_shared/internal-hIuTpSbx.mjs";import{jsx as l,jsxs as g}from"react/jsx-runtime";const be=e=>{const t=ie(23),{destination:s}=e,u=ae();let x;t[0]!==s.snippet?(x=()=>{he(s.snippet)},t[0]=s.snippet,t[1]=x):x=t[1];const m=x;let i;t[2]!==s.title?(i=l("h4",{className:"text-sm font-semibold",children:s.title}),t[2]=s.title,t[3]=i):i=t[3];let o;t[4]!==s.description?(o=l("p",{className:"text-sm text-muted-foreground",children:s.description}),t[4]=s.description,t[5]=o):o=t[5];let c;t[6]!==i||t[7]!==o?(c=g("div",{children:[i,o]}),t[6]=i,t[7]=o,t[8]=c):c=t[8];const P=`drain-copy-${s.id}`;let r;t[9]!==u?(r=u("Copy"),t[9]=u,t[10]=r):r=t[10];let n;t[11]!==m||t[12]!==P||t[13]!==r?(n=l(oe,{"data-testid":P,onClick:m,size:"sm",variant:"outline",children:r}),t[11]=m,t[12]=P,t[13]=r,t[14]=n):n=t[14];let a;t[15]!==c||t[16]!==n?(a=g("div",{className:"flex items-start justify-between gap-3",children:[c,n]}),t[15]=c,t[16]=n,t[17]=a):a=t[17];let f;t[18]!==s.snippet?(f=l("pre",{className:"mt-2 overflow-x-auto rounded bg-muted p-2 font-mono text-xs",children:s.snippet}),t[18]=s.snippet,t[19]=f):f=t[19];let b;return t[20]!==a||t[21]!==f?(b=l(re,{className:"py-0","data-testid":"drain-card",children:g(ne,{className:"p-3",children:[a,f]})}),t[20]=a,t[21]=f,t[22]=b):b=t[22],b},je=()=>{const e=ie(93),t=ae();let s;e[0]!==t?(s=t("Stream every request log to R2, a SIEM, or a third-party log service."),e[0]=t,e[1]=s):s=e[1];let u;e[2]===Symbol.for("react.memo_cache_sentinel")?(u=["{",' "logpush": true',"}"],e[2]=u):u=e[2];const x=u.join(`
|
|
2
2
|
`);let m;e[3]!==t?(m=t("Logpush"),e[3]=t,e[4]=m):m=e[4];let i;e[5]!==s||e[6]!==m?(i={description:s,id:"logpush",snippet:x,title:m},e[5]=s,e[6]=m,e[7]=i):i=e[7];let o;e[8]!==t?(o=t("Send logs programmatically to a Worker for custom capture and forwarding."),e[8]=t,e[9]=o):o=e[9];let c;e[10]===Symbol.for("react.memo_cache_sentinel")?(c=["{",' "tail_consumers": [{ "service": "my-log-forwarder" }]',"}"],e[10]=c):c=e[10];const P=c.join(`
|
|
3
3
|
`);let r;e[11]!==t?(r=t("Tail Workers"),e[11]=t,e[12]=r):r=e[12];let n;e[13]!==o||e[14]!==r?(n={description:o,id:"tail-worker",snippet:P,title:r},e[13]=o,e[14]=r,e[15]=n):n=e[15];let a;e[16]!==t?(a=t("Retain and query recent request logs directly in Cloudflare's dashboard."),e[16]=t,e[17]=a):a=e[17];let f;e[18]===Symbol.for("react.memo_cache_sentinel")?(f=["{",' "observability": { "enabled": true }',"}"],e[18]=f):f=e[18];const b=f.join(`
|
|
4
4
|
`);let y;e[19]!==t?(y=t("Workers Logs"),e[19]=t,e[20]=y):y=e[20];let k;e[21]!==a||e[22]!==y?(k={description:a,id:"workers-logs",snippet:b,title:y},e[21]=a,e[22]=y,e[23]=k):k=e[23];let $;e[24]!==k||e[25]!==i||e[26]!==n?($=[i,n,k],e[24]=k,e[25]=i,e[26]=n,e[27]=$):$=e[27];const Q=$,[d,de]=te(""),[v,se]=te(!1),[z,J]=te(null);let V;e[28]!==t||e[29]!==d?(V=async()=>{const h=d.trim();if(h==="")return;const le="fetch"in globalThis?globalThis.fetch:void 0;if(le===void 0){J({kind:"error",message:t("fetch is unavailable in this environment."),url:h});return}const fe={durationMs:12,function:"messages:list",outcome:"ok",shard:"root",source:"lunora",tablesRead:["messages"],tablesWritten:[],ts:new Date().toISOString(),type:"request"};se(!0),J(null);const me=performance.now();try{const ee=await le(h,{body:JSON.stringify(fe),headers:{"Content-Type":"application/json"},method:"POST"});J({kind:"success",latencyMs:Math.round(performance.now()-me),status:ee.status,url:h})}catch(ee){J({kind:"error",message:ge(ee),url:h})}se(!1)},e[28]=t,e[29]=d,e[30]=V):V=e[30];const X=V;let Y;e[31]!==z||e[32]!==d?(Y=z?.url===d.trim()?z:null,e[31]=z,e[32]=d,e[33]=Y):Y=e[33];const p=Y;let G;e[34]!==X?(G=()=>{xe(X())},e[34]=X,e[35]=G):G=e[35];const Z=G;let H;e[36]===Symbol.for("react.memo_cache_sentinel")?(H=h=>{de(h.target.value)},e[36]=H):H=e[36];const ce=H;let w;e[37]!==t?(w=t("Open in Cloudflare"),e[37]=t,e[38]=w):w=e[38];let N;e[39]!==w?(N=l("div",{className:"flex flex-wrap items-center gap-3",children:l("a",{className:"text-sm text-primary underline-offset-4 hover:underline","data-testid":"drain-cf-link",href:ue,rel:"noreferrer",target:"_blank",children:w})}),e[39]=w,e[40]=N):N=e[40];let C;e[41]!==t?(C=t("Lunora does not ship logs itself — forwarding is handled by Cloudflare. Configure a destination below, then test your collector."),e[41]=t,e[42]=C):C=e[42];let S;e[43]!==C?(S=l("p",{className:"text-sm text-muted-foreground","data-testid":"drain-readonly-note",children:C}),e[43]=C,e[44]=S):S=e[44];let _;e[45]!==t?(_=t("Cloudflare destinations"),e[45]=t,e[46]=_):_=e[46];let T;e[47]!==_?(T=l("h3",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:_}),e[47]=_,e[48]=T):T=e[48];let L;e[49]!==Q?(L=Q.map(ye),e[49]=Q,e[50]=L):L=e[50];let R;e[51]!==T||e[52]!==L?(R=g("section",{className:"flex flex-col gap-3","data-testid":"drain-destinations",children:[T,L]}),e[51]=T,e[52]=L,e[53]=R):R=e[53];let j;e[54]!==t?(j=t("Webhook test"),e[54]=t,e[55]=j):j=e[55];let O;e[56]!==j?(O=l("h3",{className:"mb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:j}),e[56]=j,e[57]=O):O=e[57];let W;e[58]!==t?(W=t("POST a sample Lunora request-log envelope to your collector to confirm it is reachable."),e[58]=t,e[59]=W):W=e[59];let I;e[60]!==W?(I=l("p",{className:"mb-2 text-sm text-muted-foreground",children:W}),e[60]=W,e[61]=I):I=e[61];let M;e[62]!==t?(M=t("https://example.com/logs"),e[62]=t,e[63]=M):M=e[63];let q;e[64]!==M||e[65]!==d?(q=l(pe,{className:"min-w-[20rem] flex-1","data-testid":"drain-webhook-url",onChange:ce,placeholder:M,type:"url",value:d}),e[64]=M,e[65]=d,e[66]=q):q=e[66];let D;e[67]!==v||e[68]!==d?(D=v||d.trim()==="",e[67]=v,e[68]=d,e[69]=D):D=e[69];let U;e[70]!==v||e[71]!==t?(U=t(v?"Sending…":"Send test event"),e[70]=v,e[71]=t,e[72]=U):U=e[72];let A;e[73]!==Z||e[74]!==D||e[75]!==U?(A=l(oe,{"data-testid":"drain-webhook-test",disabled:D,onClick:Z,children:U}),e[73]=Z,e[74]=D,e[75]=U,e[76]=A):A=e[76];let B;e[77]!==q||e[78]!==A?(B=g("div",{className:"flex flex-wrap items-center gap-2",children:[q,A]}),e[77]=q,e[78]=A,e[79]=B):B=e[79];let E;e[80]!==p||e[81]!==t?(E=p!==null&&l("p",{className:p.kind==="success"?"mt-2 text-sm text-muted-foreground":"mt-2 text-sm text-destructive","data-testid":"drain-webhook-result",role:p.kind==="error"?"alert":void 0,children:p.kind==="success"?t("Delivered — status {status} in {latency}ms",{latency:p.latencyMs,status:p.status}):t("Failed: {message}",{message:p.message})}),e[80]=p,e[81]=t,e[82]=E):E=e[82];let F;e[83]!==O||e[84]!==I||e[85]!==B||e[86]!==E?(F=l(re,{className:"py-0",children:l(ne,{className:"p-3",children:g("section",{"data-testid":"drain-webhook",children:[O,I,B,E]})})}),e[83]=O,e[84]=I,e[85]=B,e[86]=E,e[87]=F):F=e[87];let K;return e[88]!==N||e[89]!==S||e[90]!==R||e[91]!==F?(K=g("div",{className:"flex flex-col gap-4","data-testid":"log-drains",children:[N,S,R,F]}),e[88]=N,e[89]=S,e[90]=R,e[91]=F,e[92]=K):K=e[92],K};function ye(e){return l(be,{destination:e},e.id)}export{je as default};
|
package/dist/packem_shared/{GlobalDataBrowser-D8ZheGwm.mjs → GlobalDataBrowser-DB1B-WAN.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useState as A,useRef as I,useEffect as J}from"react";import{a as Q}from"./use-admin-query-CaOm4JS3.mjs";import{useAutoRefresh as B}from"./DEFAULT_AUTO_REFRESH_MS-Py5Yx7rP.mjs";import{u as me}from"./use-mirrored-ref-CVDf2z1M.mjs";import{u as ue}from"./use-studio-client-DCA50tF2.mjs";import{useT as _}from"./DEFAULT_LOCALE-BQ3jRT74.mjs";import{
|
|
1
|
+
import{useState as A,useRef as I,useEffect as J}from"react";import{a as Q}from"./use-admin-query-CaOm4JS3.mjs";import{useAutoRefresh as B}from"./DEFAULT_AUTO_REFRESH_MS-Py5Yx7rP.mjs";import{u as me}from"./use-mirrored-ref-CVDf2z1M.mjs";import{u as ue}from"./use-studio-client-DCA50tF2.mjs";import{useT as _}from"./DEFAULT_LOCALE-BQ3jRT74.mjs";import{a as fe}from"./cf-links-BPy1pJRO.mjs";import{l as pe,o as ge,f as be}from"./internal-hIuTpSbx.mjs";import{m as Z,u as he,a as xe,T as ke,D as ve}from"./table-list-sidebar-DUnCjFL7.mjs";import{c as X}from"react/compiler-runtime";import{c as Ne,a as ye,b as q,e as we,d as Te,T as Se}from"./table-D0SBiDu-.mjs";import{a as Ce}from"./control-button-BOZ5K-FC.mjs";import{C as K,G as Fe}from"./data-grid-B5m1OosL.mjs";import{G as Pe}from"./grid-pagination-DY2erU65.mjs";import{jsx as r,jsxs as P}from"react/jsx-runtime";import{E as Ee}from"./empty-state-D7jEML_T.mjs";const Me=(t,e)=>{const n=t._id;return typeof n=="string"||typeof n=="number"?String(n):`row-${e.toString()}`},Ge=t=>t==null?"∅":t===""?"(empty)":pe(t),Re=t=>{const e=X(45),{filters:n,hasMaskedColumns:f,mask:s,maskOn:u,onChangePageSize:o,onJumpToPage:O,onNext:d,onPrevious:T,onRemoveFilter:p,onToggleMask:L,page:c,pageSize:E,pagination:S}=t,C=_(),{hasNext:z,hasPrevious:D,rangeEnd:$,rangeStart:F,total:k}=S;let v;e[0]!==f||e[1]!==u||e[2]!==L||e[3]!==C?(v=f&&r("div",{className:"flex shrink-0 flex-wrap items-center gap-1.5 border-b border-border px-4 py-2",children:r("button",{"aria-pressed":u,className:Ce,"data-testid":"gdb-mask-toggle",onClick:L,type:"button",children:C("Mask sensitive columns")})}),e[0]=f,e[1]=u,e[2]=L,e[3]=C,e[4]=v):v=e[4];let g;e[5]!==n||e[6]!==s||e[7]!==p||e[8]!==C?(g=n.length>0&&r("div",{className:"flex shrink-0 flex-wrap items-center gap-1.5 border-b border-border px-4 py-2 text-xs","data-testid":"gdb-filters",children:n.map((i,m)=>{const G=Ge(Z(i.value,i.column,s));return P("span",{className:"inline-flex items-center gap-1 rounded border border-border bg-muted px-1.5 py-0.5","data-testid":"gdb-filter-chip",children:[r("span",{className:"font-medium text-foreground",children:i.column}),r("span",{className:"text-muted-foreground",children:"="}),r("span",{className:"font-mono text-foreground",children:G}),r("button",{"aria-label":C("Remove filter"),className:"ml-0.5 text-muted-foreground hover:text-foreground","data-testid":"gdb-filter-remove",onClick:()=>{p(m)},type:"button",children:"✕"})]},`${i.column}:${G}`)})}),e[5]=n,e[6]=s,e[7]=p,e[8]=C,e[9]=g):g=e[9];let a;if(e[10]!==s||e[11]!==c.columns){let i;e[13]!==s?(i=m=>P(Ne,{children:[m,s.columns.has(m)&&r("span",{className:"ms-1 inline-flex items-center rounded-sm bg-warning/15 px-1 text-[0.625rem] font-medium uppercase text-warning","data-testid":`gdb-mask-chip-${m}`,title:"This column is masked by a mask() policy",children:"masked"})]},m),e[13]=s,e[14]=i):i=e[14],a=c.columns.map(i),e[10]=s,e[11]=c.columns,e[12]=a}else a=e[12];let b;e[15]!==a?(b=r(ye,{children:r(q,{children:a})}),e[15]=a,e[16]=b):b=e[16];let N;if(e[17]!==s||e[18]!==c.columns||e[19]!==c.rows){let i;e[21]!==s||e[22]!==c.columns?(i=(m,G)=>r(q,{"data-testid":"gdb-row",children:c.columns.map(w=>r(we,{className:"max-w-xs truncate font-mono text-xs",children:s.enabled&&s.columns.has(w)?r("span",{className:"text-muted-foreground italic","data-testid":`gdb-masked-${w}`,title:"Masked (preview)",children:r(K,{value:Z(m[w],w,s)})}):r(K,{value:m[w]})},w))},Me(m,G)),e[21]=s,e[22]=c.columns,e[23]=i):i=e[23],N=c.rows.map(i),e[17]=s,e[18]=c.columns,e[19]=c.rows,e[20]=N}else N=e[20];let y;e[24]!==N?(y=r(Te,{children:N}),e[24]=N,e[25]=y):y=e[25];let h;e[26]!==b||e[27]!==y?(h=r(Fe,{layout:"fill",children:r("div",{className:"min-h-0 flex-1 overflow-auto",children:P(Se,{"data-testid":"gdb-rows",children:[b,y]})})}),e[26]=b,e[27]=y,e[28]=h):h=e[28];let x;e[29]!==z||e[30]!==D||e[31]!==o||e[32]!==O||e[33]!==d||e[34]!==T||e[35]!==E||e[36]!==$||e[37]!==F||e[38]!==k?(x=r("div",{className:"flex shrink-0 items-center border-t border-border px-4 py-2",children:r(Pe,{hasNext:z,hasPrevious:D,onJumpToPage:O,onNext:d,onPageSizeChange:o,onPrevious:T,pageSize:E,prefix:"gdb",rangeEnd:$,rangeStart:F,total:k})}),e[29]=z,e[30]=D,e[31]=o,e[32]=O,e[33]=d,e[34]=T,e[35]=E,e[36]=$,e[37]=F,e[38]=k,e[39]=x):x=e[39];let M;return e[40]!==v||e[41]!==g||e[42]!==h||e[43]!==x?(M=P("div",{className:"flex min-h-0 flex-1 flex-col","data-testid":"gdb-page",children:[v,g,h,x]}),e[40]=v,e[41]=g,e[42]=h,e[43]=x,e[44]=M):M=e[44],M},Oe=()=>{const t=X(8),e=_();let n;t[0]!==e?(n=e("Tables marked .global() (D1-backed, region-replicated) will appear here."),t[0]=e,t[1]=n):n=t[1];let f;t[2]===Symbol.for("react.memo_cache_sentinel")?(f=P("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:[r("circle",{cx:"12",cy:"12",r:"9"}),r("path",{d:"M3 12h18M12 3a14 14 0 0 1 0 18 14 14 0 0 1 0-18Z"})]}),t[2]=f):f=t[2];let s;t[3]!==e?(s=e("No global tables."),t[3]=e,t[4]=s):s=t[4];let u;return t[5]!==n||t[6]!==s?(u=r("div",{className:"flex flex-1 items-center justify-center p-6",children:r(Ee,{description:n,icon:f,testId:"gdb-empty",title:s})}),t[5]=n,t[6]=s,t[7]=u):u=t[7],u},Le=50,ze=[],W=[],Xe=({initialTable:t,onSelectTable:e,pageSize:n=Le,schemaSwitch:f}={})=>{const s=ue(),u=_(),[o,O]=A(t??null),[d,T]=A(0),[p,L]=A(n),[c,E]=A([]),S=me(c),{clearFacets:C,facets:z,refetchFacets:D,toggleFacet:$}=he(),F=Q(["lunora-global-tables"],()=>s.listGlobalTables()),k=F.data??null,v=F.error,g=Q(["lunora-global-page",o??"",d,p,JSON.stringify(c)],()=>s.readGlobalTablePage({filters:c,limit:p,offset:d,table:o??""}),{enabled:o!==null,keepPreviousData:!1}),a=g.data??null,b=g.error,N=(l,R)=>j=>s.facetGlobalColumn({column:j,filters:R,table:l}),y=(l,R)=>D(N(l,R));B(()=>F.poll(),!0),B(()=>g.poll(),o!==null),B(()=>o===null?void 0:y(o,S.current),o!==null);const h=I(void 0),x=l=>{O(l),h.current=l,E([]),S.current=[],C(),T(0),e?.(l)},M=l=>{$(l,o===null?null:N(o,S.current))},i=l=>{E(l),S.current=l,T(0),o!==null&&be(y(o,l))},m=(l,R)=>{i([...S.current.filter(j=>j.column!==l),{column:l,value:ge(R)}])},G=l=>{i(S.current.filter((R,j)=>j!==l))},w=I(x);J(()=>{w.current=x}),J(()=>{if(t===void 0||t===""||h.current===t)return;h.current=t;const l=t;queueMicrotask(()=>{w.current(l)})},[t]);const V=l=>{o!==null&&T(Math.max(0,l))},{maskColumns:Y,maskOn:ee,maskView:U,onToggleMask:te}=xe({columns:a?.columns??W,selectedTable:o}),H=a?.total??0,re=d>0,se=a!==null&&d+a.rows.length<H,le=a===null||a.rows.length===0?0:d+1,ae=a===null?0:d+a.rows.length,oe=()=>{F.refetch()},ne=()=>{V(d-p)},ie=()=>{V(d+p)},ce=l=>{V(Math.max(0,(l-1)*p))},de=l=>{L(l),T(0)};return P("div",{className:"flex h-full min-w-0","data-testid":"lunora-global-data-browser",children:[r(ke,{header:P("div",{className:"flex shrink-0 flex-col items-stretch gap-2 border-b border-border p-3",children:[f,r("a",{className:"text-sm text-primary underline-offset-4 hover:underline","data-testid":"gdb-cf-link",href:fe,rel:"noreferrer",target:"_blank",children:u("Open in Cloudflare")})]}),onReload:oe,onSelect:x,prefix:"gdb",selected:o,tables:k??ze}),P("div",{className:"flex min-w-0 flex-1 flex-col overflow-hidden",children:[v!==null&&r("p",{className:"shrink-0 border-b border-border px-4 py-2 text-sm text-destructive","data-testid":"gdb-tables-error",role:"alert",children:v}),k!==null&&k.length===0&&r(Oe,{}),b!==null&&r("p",{className:"shrink-0 border-b border-border px-4 py-2 text-sm text-destructive","data-testid":"gdb-page-error",role:"alert",children:b}),k!==null&&k.length>0&&a===null&&b===null&&r("div",{className:"flex flex-1 items-center justify-center p-6",children:r("p",{className:"text-sm text-muted-foreground",children:u("Select a table to browse its rows.")})}),a!==null&&r(Re,{filters:c,hasMaskedColumns:Y.size>0,mask:U,maskOn:ee,onChangePageSize:de,onJumpToPage:ce,onNext:ie,onPrevious:ne,onRemoveFilter:G,onToggleMask:te,page:a,pageSize:p,pagination:{hasNext:se,hasPrevious:re,rangeEnd:ae,rangeStart:le,total:H}})]}),r(ve,{columns:a?.columns??W,facets:z,mask:U,onFacetFilter:m,onToggleFacet:M})]})};export{Xe as GlobalDataBrowser};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const s="https://dash.cloudflare.com/?to=/:account",L=`${s}/workers-and-pages/observability`,o=`${s}/workers-and-pages`,R=`${s}/r2`,a=`${s}/workers/d1`,r=`${s}/workers/durable-objects`;export{L as C,
|
|
1
|
+
const s="https://dash.cloudflare.com/?to=/:account",L=`${s}/workers-and-pages/observability`,o=`${s}/workers-and-pages`,R=`${s}/r2`,a=`${s}/workers/d1`,r=`${s}/workers/durable-objects`;export{L as C,a,o as b,r as c,R as d};
|