@lunora/studio 1.0.0-alpha.85 → 1.0.0-alpha.86
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.ts +18 -3
- package/dist/index.js +1 -1
- package/dist/mount.js +1 -1
- package/dist/packem_chunks/AdvisorHealthPanel.js +1 -1
- package/dist/packem_chunks/ApiTab.js +1 -1
- package/dist/packem_chunks/AuditPanel.js +1 -1
- package/dist/packem_chunks/ExportImportPanel.js +1 -1
- package/dist/packem_chunks/FileBrowser.js +1 -1
- package/dist/packem_chunks/FunctionRunner.js +1 -1
- package/dist/packem_chunks/FunctionStatsPanel.js +1 -1
- package/dist/packem_chunks/HealthPanel.js +1 -1
- package/dist/packem_chunks/InsightsPanel.js +1 -1
- package/dist/packem_chunks/LogsPanel.js +1 -1
- package/dist/packem_chunks/MailPanel.js +1 -1
- package/dist/packem_chunks/MetricsPanel.js +1 -1
- package/dist/packem_chunks/NotificationsPanel.js +1 -1
- package/dist/packem_chunks/PitrPanel.js +1 -1
- package/dist/packem_chunks/SchemaViewer.js +1 -1
- package/dist/packem_chunks/SecurityAdvisorPanel.js +1 -1
- package/dist/packem_chunks/SettingsPanel.js +1 -1
- package/dist/packem_chunks/SqlEditorPanel.js +6 -6
- package/dist/packem_chunks/TableEditor.js +1 -1
- package/dist/packem_chunks/agents-panel.js +1 -1
- package/dist/packem_chunks/auth-audit-panel.js +1 -1
- package/dist/packem_chunks/containers-panel.js +1 -1
- package/dist/packem_chunks/dashboards-panel.js +1 -1
- package/dist/packem_chunks/fanout-panel.js +1 -1
- package/dist/packem_chunks/flags-panel.js +1 -1
- package/dist/packem_chunks/issues-panel.js +1 -1
- package/dist/packem_chunks/kv-browser.js +1 -1
- package/dist/packem_chunks/migrations-route.js +1 -1
- package/dist/packem_chunks/payments-panel.js +1 -1
- package/dist/packem_chunks/permissions-panel.js +1 -1
- package/dist/packem_chunks/queues-panel.js +1 -1
- package/dist/packem_chunks/rls-panel.js +1 -1
- package/dist/packem_chunks/storage-rules-panel.js +1 -1
- package/dist/packem_chunks/subscriptions-panel.js +1 -1
- package/dist/packem_chunks/traces-panel.js +1 -1
- package/dist/packem_chunks/users-panel.js +1 -1
- package/dist/packem_chunks/workflows-panel.js +1 -1
- package/dist/packem_shared/ADMIN_FUNCTIONS-4aE59aDq.js +1 -0
- package/dist/packem_shared/{ApiDocsPanel-fYS9NiLg.js → ApiDocsPanel-DLMeLZ5-.js} +1 -1
- package/dist/packem_shared/DataBrowser-CZZ_WkJ-.js +1 -0
- package/dist/packem_shared/{GlobalDataBrowser-CSttudUx.js → GlobalDataBrowser-DpkjHfDg.js} +1 -1
- package/dist/packem_shared/{HomePanel-BYsfMhKh.js → HomePanel-3baDsDBU.js} +1 -1
- package/dist/packem_shared/MigrationsPanel-dygzHUvg.js +1 -0
- package/dist/packem_shared/{Studio-Ba9x0dG_.js → Studio-forQt-PC.js} +1 -1
- package/dist/packem_shared/{StudioApp-B_PRdg4h.js → StudioApp-B1AWsBzi.js} +1 -1
- package/dist/packem_shared/{home-panel-B60-5YfI.js → home-panel-CeeqqV0z.js} +1 -1
- package/dist/packem_shared/{studio-CPuoAmjh.js → studio-BtC7WPbz.js} +1 -1
- package/dist/packem_shared/table-list-sidebar-D9Bd4qgi.js +1 -0
- package/dist/packem_shared/use-shard-key-B2JtNa5m.js +1 -0
- package/dist/packem_shared/{use-sql-assistant-BLG9unQN.js → use-sql-assistant-C6dl2_Ty.js} +1 -1
- package/dist/packem_shared/useDebounced-CU-uftxO.js +1 -0
- package/dist/standalone/chunk-2VWWXVWK.js +1 -0
- package/dist/standalone/chunk-3CWGJYBB.js +1 -0
- package/dist/standalone/{chunk-52OYJHM7.js → chunk-4JIOFDMR.js} +1 -1
- package/dist/standalone/{chunk-MN64D74P.js → chunk-4LCY5XUR.js} +1 -1
- package/dist/standalone/{chunk-JE3WK77V.js → chunk-5KRD6F67.js} +1 -1
- package/dist/standalone/{chunk-RC3H4OP3.js → chunk-5X4OZ7OD.js} +1 -1
- package/dist/standalone/{chunk-TO45V3L6.js → chunk-6MGI5IN6.js} +1 -1
- package/dist/standalone/{chunk-HJR42BJY.js → chunk-7DNDRUMZ.js} +1 -1
- package/dist/standalone/chunk-7FO57AZY.js +1 -0
- package/dist/standalone/{chunk-YNBIW2GN.js → chunk-B5S6GSUC.js} +1 -1
- package/dist/standalone/{chunk-QZ6TCNWR.js → chunk-B5UFGO4E.js} +1 -1
- package/dist/standalone/{chunk-RFBU5RZI.js → chunk-BDNDSBYM.js} +1 -1
- package/dist/standalone/{chunk-QS4IFAFJ.js → chunk-CLNB7I3O.js} +1 -1
- package/dist/standalone/{chunk-QSFKPGK4.js → chunk-D3JTCLSF.js} +1 -1
- package/dist/standalone/chunk-DABW4OOI.js +1 -0
- package/dist/standalone/{chunk-SPT3KPV7.js → chunk-EAIUBZA5.js} +1 -1
- package/dist/standalone/{chunk-FUBR2PAD.js → chunk-EJ2CHD4G.js} +1 -1
- package/dist/standalone/chunk-EVTCXQ5D.js +1 -0
- package/dist/standalone/{chunk-OLM62NLS.js → chunk-EWDLYYJM.js} +1 -1
- package/dist/standalone/{chunk-ZOX6X2DL.js → chunk-F7NVC7YK.js} +1 -1
- package/dist/standalone/chunk-FURI47Z2.js +1 -0
- package/dist/standalone/chunk-FW75RYZU.js +1 -0
- package/dist/standalone/chunk-GE5WTIWX.js +1 -0
- package/dist/standalone/{chunk-BAAU4OTI.js → chunk-GZS3ORGS.js} +1 -1
- package/dist/standalone/chunk-HYCMT2V5.js +1 -0
- package/dist/standalone/{chunk-5YADKLAQ.js → chunk-IAKPXGTQ.js} +1 -1
- package/dist/standalone/chunk-IVCIG5J7.js +4 -0
- package/dist/standalone/chunk-KJIBL5D4.js +1 -0
- package/dist/standalone/chunk-L4RW5BFD.js +1 -0
- package/dist/standalone/{chunk-PWTURL56.js → chunk-LYRAWNV7.js} +1 -1
- package/dist/standalone/chunk-MIFLRBVS.js +11 -0
- package/dist/standalone/{chunk-OOL3FV6A.js → chunk-MV4A2PAK.js} +1 -1
- package/dist/standalone/{chunk-347H2BQO.js → chunk-NBUBAW3V.js} +1 -1
- package/dist/standalone/{chunk-232MBXB2.js → chunk-NCWUTRZB.js} +1 -1
- package/dist/standalone/{chunk-D67BVBQW.js → chunk-NMLCYY4H.js} +1 -1
- package/dist/standalone/{chunk-MDHUWMFD.js → chunk-OOWHAURL.js} +1 -1
- package/dist/standalone/{chunk-UOQ24BAY.js → chunk-ORVR33FM.js} +1 -1
- package/dist/standalone/{chunk-7AG3T4DK.js → chunk-OUCGTB3Y.js} +2 -2
- package/dist/standalone/chunk-PDMZITZZ.js +1 -0
- package/dist/standalone/{chunk-VORDESEQ.js → chunk-PNAVAJAF.js} +1 -1
- package/dist/standalone/{chunk-LVJ5IHEU.js → chunk-QJTGO4JG.js} +1 -1
- package/dist/standalone/{chunk-EDOMDMVI.js → chunk-QP7IQOKF.js} +1 -1
- package/dist/standalone/chunk-QXDMHM2V.js +1 -0
- package/dist/standalone/{chunk-VKEJTZY7.js → chunk-S2CXYDNT.js} +1 -1
- package/dist/standalone/{chunk-AQKXMWNF.js → chunk-S3DWUXGY.js} +1 -1
- package/dist/standalone/{chunk-YSMJN36P.js → chunk-SJZQPIZB.js} +1 -1
- package/dist/standalone/{chunk-ETZYJL7Z.js → chunk-SMEW3ZTU.js} +1 -1
- package/dist/standalone/chunk-SNK7TOOO.js +6 -0
- package/dist/standalone/{chunk-QI25LTPH.js → chunk-T2Q7I3V2.js} +1 -1
- package/dist/standalone/{chunk-ESKVOZLC.js → chunk-T3CGXSXO.js} +1 -1
- package/dist/standalone/{chunk-YGKR536O.js → chunk-TS6346VY.js} +1 -1
- package/dist/standalone/{chunk-ENBTOX7N.js → chunk-TVGKSIIW.js} +1 -1
- package/dist/standalone/{chunk-U5IIRHZ6.js → chunk-UNVK2VZP.js} +1 -1
- package/dist/standalone/{chunk-U44CWN7H.js → chunk-UR3X4K4T.js} +1 -1
- package/dist/standalone/chunk-VDW32UET.js +1 -0
- package/dist/standalone/chunk-VQK34A2H.js +1 -0
- package/dist/standalone/{chunk-MBVSXVTV.js → chunk-WPUINKEO.js} +1 -1
- package/dist/standalone/chunk-XNGYYOLS.js +14 -0
- package/dist/standalone/{chunk-2SC3EG5Y.js → chunk-XR7RBXKA.js} +1 -1
- package/dist/standalone/{chunk-KNHWIHC7.js → chunk-XZN645UJ.js} +1 -1
- package/dist/standalone/chunk-YFJXQUPW.js +1 -0
- package/dist/standalone/chunk-YKAO3JNJ.js +1 -0
- package/dist/standalone/{chunk-AHVDZWB3.js → chunk-YRYEZHOJ.js} +1 -1
- package/dist/standalone/{chunk-TIR6CWHO.js → chunk-ZCFDQW4U.js} +1 -1
- package/dist/standalone/studio.js +1 -1
- package/package.json +6 -6
- package/dist/packem_shared/ADMIN_FUNCTIONS-CZESgd10.js +0 -1
- package/dist/packem_shared/DataBrowser-C4J4gVUu.js +0 -1
- package/dist/packem_shared/MigrationsPanel-2JbQ2HwG.js +0 -1
- package/dist/packem_shared/table-list-sidebar-BRv3hTLX.js +0 -1
- package/dist/packem_shared/useDebounced-Ihdiid_k.js +0 -1
- package/dist/standalone/chunk-22LOWEEC.js +0 -1
- package/dist/standalone/chunk-2EJADIPC.js +0 -1
- package/dist/standalone/chunk-4I2TBTZS.js +0 -1
- package/dist/standalone/chunk-6IEBRNDW.js +0 -1
- package/dist/standalone/chunk-D3FRQZ4X.js +0 -1
- package/dist/standalone/chunk-ERMTJYQF.js +0 -1
- package/dist/standalone/chunk-JAT5ZBQK.js +0 -1
- package/dist/standalone/chunk-JOFD43OI.js +0 -1
- package/dist/standalone/chunk-LFKCLLPT.js +0 -1
- package/dist/standalone/chunk-MLULN4R2.js +0 -1
- package/dist/standalone/chunk-MUGKOGZG.js +0 -1
- package/dist/standalone/chunk-NPKNFZUW.js +0 -6
- package/dist/standalone/chunk-OV63HVE4.js +0 -4
- package/dist/standalone/chunk-QFJRZR4U.js +0 -1
- package/dist/standalone/chunk-QNRAMF4X.js +0 -1
- package/dist/standalone/chunk-QNUWWC3N.js +0 -14
- package/dist/standalone/chunk-S67SBGB3.js +0 -1
- package/dist/standalone/chunk-SHD2IWQI.js +0 -1
- package/dist/standalone/chunk-SKFZXESP.js +0 -1
- package/dist/standalone/chunk-UBR4KB6K.js +0 -11
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import{c as K}from"react/compiler-runtime";import{useLunora as
|
|
2
|
-
${l}`})),
|
|
3
|
-
`;)t+=1;return t}
|
|
4
|
-
`,e);return n===-1?l.length:n}if(t==="/"&&l[e+1]==="*"){const n=l.indexOf("*/",e+2);return n===-1?l.length:n+2}return-1},Dt=l=>{let e="",t=0;for(;t<l.length;){const n=Mt(l,t);n===-1?(e+=l.slice(t,t+1),t+=1):(e+=l.slice(t,n).replaceAll(Ot," "),t=n)}return e},At=l=>{const e=new Set;for(const t of l.matchAll(Lt))e.add((t[1]??"").toLowerCase());return e},Bt=(l,e)=>{const t=new Map;for(const n of l.matchAll(Et)){const r=(n[1]??"").toLowerCase(),o=(n[2]??"").toLowerCase();e.has(r)&&(t.set(r,r),o!==""&&!_t.has(o)&&t.set(o,r))}return t},Ue=(l,e)=>{const t=Dt(l),n=new Set(e.map(r=>r.toLowerCase()));return{ctes:At(t),masked:t,targets:Bt(t,n)}},zt=/^(?:__lunora|sqlite_)/iu,Ht=/\b(?:from|join)\s+([a-z_][\w$]*)/giu,Pt=/\b([a-z_][\w$]*)\.([a-z_][\w$]*)/giu,Ft=new Set(["cross","full","group","having","inner","join","lateral","left","limit","offset","order","right","select","union","where","window"]),Qt=(l,e,t)=>{const n=[];for(const r of l.matchAll(Ht)){const o=r[1]??"",s=o.toLowerCase();!e.has(s)&&!t.has(s)&&!Ft.has(s)&&!zt.test(o)&&n.push({length:o.length,message:`unknown table \`${o}\``,offset:r.index+r[0].length-o.length,severity:"error",source:"schema"})}return n},jt=(l,e,t)=>{const n=[],r=new Map;for(const[o,s]of Object.entries(e.columns))r.set(o.toLowerCase(),new Set(s.map(d=>d.toLowerCase())));for(const o of l.matchAll(Pt)){const s=(o[1]??"").toLowerCase(),d=o[2]??"",a=t.get(s),i=a===void 0?void 0:r.get(a);i!==void 0&&!i.has(d.toLowerCase())&&n.push({length:d.length,message:`\`${a??""}\` has no column \`${d}\``,offset:o.index+o[0].length-d.length,severity:"error",source:"schema"})}return n},Wt=(l,e)=>{if(l.trim()==="")return[];const t=It(l);if(t!==void 0)return t.code==="SQL_EMPTY"?[]:[{length:t.length,message:t.message,offset:t.offset,severity:"error",source:"gate"}];const{ctes:n,masked:r,targets:o}=Ue(l,e.tables),s=new Set(e.tables.map(d=>d.toLowerCase()));return[...Qt(r,s,n),...jt(r,e,o)]},Kt=Te($e.lintSql),Ut=600,Yt=(l,e,t)=>{const n=Me(),[r,o]=te([]),s=ze(()=>Wt(l,e),[l,e]),d=rt(l,Ut),a=s.some(h=>h.source==="gate")||d.trim()==="",i=et(async h=>{try{const p=await n.query(Kt,{sql:d},ke(t));h.cancelled||o(p.diagnostics??[])}catch{h.cancelled||o([])}},[n,d,t]);qe(()=>{if(a){o([]);return}const h={cancelled:!1};return de(i(h)),()=>{h.cancelled=!0}},[i,a]);const f=d===l;return ze(()=>f?[...s,...r]:s,[s,r,f])},Se=8,Jt=["AND","ASC","AS","BY","COUNT","DESC","DISTINCT","EXPLAIN","FROM","GROUP","HAVING","INNER","JOIN","LEFT","LIKE","LIMIT","NOT","NULL","OFFSET","ON","ORDER","OR","QUERY","SELECT","WHERE","WITH"],Gt=new Set(["AND","BY","HAVING","ON","OR","SELECT","WHERE"]),Vt=/[\w$]/,Ye=l=>l!==void 0&&Vt.test(l),Je=l=>{let e=l.length;for(;e>0&&Ye(l[e-1]);)e-=1;return l.slice(e)},Ge=(l,e)=>{let t=e;for(;t>0&&Ye(l[t-1]);)t-=1;return{end:e,start:t,text:l.slice(t,e)}},Fe=(l,e)=>{const t=l.slice(0,e).trimEnd();return t.endsWith(".")||Gt.has(Je(t).toUpperCase())},Xt=(l,e,t)=>{const n=l.slice(0,e);if(!n.endsWith("."))return;const r=Je(n.slice(0,-1));if(r!=="")return Ue(l,t).targets.get(r.toLowerCase())??r},De=(l,e)=>l.toLowerCase().startsWith(e.toLowerCase()),Qe=(l,e,t,n)=>{const r=[];for(const o of l)if(De(o,e)&&(r.push(n(o)),r.length>=t))break;return r},Zt=(l,e,t)=>{const n=new Map;for(const[r,o]of Object.entries(l.columns))for(const s of o)if(De(s,e)&&!n.has(s)&&(n.set(s,r),n.size>=t))return[...n].map(([d,a])=>({detail:a,kind:"column",label:d}));return[...n].map(([r,o])=>({detail:o,kind:"column",label:r}))},en=(l,e,t)=>{const n=Ge(l,e),r=Xt(l,n.start,t.tables);if(r!==void 0){const a=t.columns[r]??t.columns[r.toLowerCase()]??[];return Qe(a,n.text,Se,i=>({detail:r,kind:"column",label:i}))}if(n.text===""&&!Fe(l,n.start))return[];const o=Qe(t.tables,n.text,Se,a=>({kind:"table",label:a})),s=Zt(t,n.text,Se),d=Jt.flatMap(a=>n.text!==""&&De(a,n.text)&&a.toLowerCase()!==n.text.toLowerCase()?[{kind:"keyword",label:a}]:[]);return(Fe(l,n.start)?[...s,...o,...d]:[...o,...s,...d]).slice(0,Se)},tn=(l,e,t)=>{const n=Ge(l,e),r=l.slice(0,n.start)+t.label+l.slice(n.end);return{caret:n.start+t.label.length,value:r}},nn=["boxSizing","borderBottomWidth","borderLeftWidth","borderRightWidth","borderTopWidth","fontFamily","fontSize","fontStyle","fontWeight","letterSpacing","lineHeight","paddingBottom","paddingLeft","paddingRight","paddingTop","tabSize","textIndent","textTransform","width","wordSpacing"],on=(l,e)=>{const t=globalThis.getComputedStyle(l),n=globalThis.document.createElement("div"),{style:r}=n;r.position="absolute",r.visibility="hidden",r.whiteSpace="pre-wrap",r.overflowWrap="break-word";for(const a of nn)r[a]=t[a];n.textContent=l.value.slice(0,Math.max(0,e));const o=globalThis.document.createElement("span");o.textContent=l.value.slice(Math.max(0,e))||".",n.append(o),globalThis.document.body.append(n);const s=o.offsetLeft-l.scrollLeft,d=o.offsetTop-l.scrollTop;return n.remove(),{left:s,top:d}},rn=(l,e,t)=>{const n=K(16),[r,o]=te(null);let s;n[0]!==l||n[1]!==e?(s=(y,b)=>{const m=en(y,b,l);if(m.length===0){o(null);return}const w=e.current,{left:k,top:S}=w===null?{left:0,top:0}:on(w,b);o(C=>C!==null&&C.active===0&&C.left===k&&C.top===S&&C.suggestions.length===m.length&&C.suggestions.every((q,L)=>{const R=m.at(L);return q.kind===R?.kind&&q.label===R.label&&q.detail===R.detail})?C:{active:0,left:k,suggestions:m,top:S})},n[0]=l,n[1]=e,n[2]=s):s=n[2];const d=s;let a;n[3]===Symbol.for("react.memo_cache_sentinel")?(a=()=>{o(null)},n[3]=a):a=n[3];const i=a;let f;n[4]===Symbol.for("react.memo_cache_sentinel")?(f=y=>{o(b=>{if(b===null)return b;const m=b.suggestions.length,w=(b.active+y+m)%m;return{...b,active:w}})},n[4]=f):f=n[4];const h=f;let p;n[5]!==t||n[6]!==r||n[7]!==e?(p=y=>{const b=e.current;if(r===null||b===null)return!1;const m=r.suggestions[y??r.active];if(m===void 0)return!1;const w=tn(b.value,b.selectionStart,m);return t(w.value),o(null),requestAnimationFrame(()=>{const k=e.current;k!==null&&(k.focus(),k.setSelectionRange(w.caret,w.caret))}),!0},n[5]=t,n[6]=r,n[7]=e,n[8]=p):p=n[8];const x=p;let c;n[9]!==x?(c=()=>x(),n[9]=x,n[10]=c):c=n[10];const g=c;let v;return n[11]!==g||n[12]!==x||n[13]!==d||n[14]!==r?(v={close:i,commit:g,commitAt:x,move:h,refresh:d,state:r},n[11]=g,n[12]=x,n[13]=d,n[14]=r,n[15]=v):v=n[15],v},ln={column:"column",keyword:"keyword",table:"table"},sn=20,an=l=>{const e=K(17),{listboxId:t,onPick:n,state:r}=l,o=oe();let s;e[0]!==r?(s=r===null?void 0:{left:r.left,top:r.top+sn},e[0]=r,e[1]=s):s=e[1];const d=s;if(r===null)return null;let a;if(e[2]!==t||e[3]!==n||e[4]!==r.active||e[5]!==r.suggestions||e[6]!==o){let f;e[8]!==t||e[9]!==n||e[10]!==r.active||e[11]!==o?(f=(h,p)=>B("li",{"aria-selected":p===r.active,className:ue("flex cursor-pointer items-center gap-2 px-2 py-1 text-[13px]",p===r.active?"bg-accent text-accent-foreground":"text-foreground"),"data-testid":"sql-autocomplete-item",id:`${t}-opt-${p.toString()}`,onMouseDown:x=>{x.preventDefault(),n(p)},role:"option",children:[u("span",{className:"truncate font-mono",children:h.label}),h.detail!==void 0&&u("span",{className:"ms-auto truncate text-xs text-muted-foreground",children:h.detail}),u("span",{className:"shrink-0 font-mono text-[10px] tracking-wide text-muted-foreground/70 uppercase",children:o(ln[h.kind])})]},`${h.kind}:${h.label}`),e[8]=t,e[9]=n,e[10]=r.active,e[11]=o,e[12]=f):f=e[12],a=r.suggestions.map(f),e[2]=t,e[3]=n,e[4]=r.active,e[5]=r.suggestions,e[6]=o,e[7]=a}else a=e[7];let i;return e[13]!==t||e[14]!==d||e[15]!==a?(i=u("ul",{className:"absolute z-30 max-h-56 w-72 overflow-auto rounded-md border border-border bg-popover py-1 text-popover-foreground shadow-md","data-testid":"sql-autocomplete",id:t,role:"listbox",style:d,children:a}),e[13]=t,e[14]=d,e[15]=a,e[16]=i):i=e[16],i},cn=Te($e.listTables),dn=Te($e.readTablePage),un=l=>{const e=K(16),t=Me();let n;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=[],e[0]=n):n=e[0];const[r,o]=te(n);let s;e[1]===Symbol.for("react.memo_cache_sentinel")?(s={},e[1]=s):s=e[1];const[d,a]=te(s);let i;e[2]===Symbol.for("react.memo_cache_sentinel")?(i=new Set,e[2]=i):i=e[2];const f=ye(i);let h,p;e[3]!==t||e[4]!==l?(h=()=>{const b={cancelled:!1};return de((async()=>{try{const m=await t.query(cn,{},ke(l));b.cancelled||(o(m.map(fn)),a({}),f.current=new Set)}catch{b.cancelled||(o([]),a({}),f.current=new Set)}})()),()=>{b.cancelled=!0}},p=[t,l],e[3]=t,e[4]=l,e[5]=h,e[6]=p):(h=e[5],p=e[6]),qe(h,p);let x;e[7]!==t||e[8]!==l?(x=b=>{f.current.has(b)||(f.current.add(b),de((async()=>{try{const m=await t.query(dn,{limit:1,offset:0,table:b},ke(l));a(w=>({...w,[b]:m.columns}))}catch{f.current.delete(b)}})()))},e[7]=t,e[8]=l,e[9]=x):x=e[9];const c=x;let g;e[10]!==d||e[11]!==r?(g={columns:d,tables:r},e[10]=d,e[11]=r,e[12]=g):g=e[12];const v=g;let y;return e[13]!==c||e[14]!==v?(y={probe:c,schema:v},e[13]=c,e[14]=v,e[15]=y):y=e[15],y},_e=/\b(?:from|join|update|into)\s+([a-z_][\w$]*)|\b([a-z_][\w$]*)\s*\./gi,mn=l=>{const e=new Set;_e.lastIndex=0;let t=_e.exec(l);for(;t!==null;)e.add(t[1]??t[2]),t=_e.exec(l);return[...e]};function fn(l){return l.name}const hn=l=>{const e=K(34),{onSubmit:t,probe:n,schema:r,setDraft:o}=l,s=tt(),d=ye(null),a=ye(null),i=ye(null),f=rn(r,i,o),{close:h,commit:p,commitAt:x,move:c,refresh:g,state:v}=f;let y;e[0]!==x?(y=N=>{x(N)},e[0]=x,e[1]=y):y=e[1];const b=y;let m;e[2]!==g?(m=()=>{const N=i.current;N!==null&&N===document.activeElement&&g(N.value,N.selectionStart)},e[2]=g,e[3]=m):m=e[3];let w;e[4]!==g||e[5]!==r?(w=[g,r],e[4]=g,e[5]=r,e[6]=w):w=e[6],qe(m,w);let k;e[7]!==n||e[8]!==g||e[9]!==o?(k=N=>{const{selectionStart:z,value:P}=N.target;o(P);for(const Q of mn(P))n(Q);g(P,z)},e[7]=n,e[8]=g,e[9]=o,e[10]=k):k=e[10];const S=k;let C;e[11]!==g?(C=N=>{const z=N.currentTarget;g(z.value,z.selectionStart)},e[11]=g,e[12]=C):C=e[12];const q=C;let L;e[13]!==v||e[14]!==h||e[15]!==p||e[16]!==c||e[17]!==t?(L=N=>{if(v!==null){if(N.key==="ArrowDown"){N.preventDefault(),c(1);return}if(N.key==="ArrowUp"){N.preventDefault(),c(-1);return}if(N.key==="Escape"){N.preventDefault(),h();return}if((N.key==="Enter"||N.key==="Tab")&&!N.metaKey&&!N.ctrlKey&&p()){N.preventDefault();return}}(N.metaKey||N.ctrlKey)&&N.key==="Enter"&&(N.preventDefault(),t())},e[13]=v,e[14]=h,e[15]=p,e[16]=c,e[17]=t,e[18]=L):L=e[18];const R=L;let T;e[19]!==h?(T=()=>{requestAnimationFrame(()=>{h()})},e[19]=h,e[20]=T):T=e[20];const I=T;let _;e[21]===Symbol.for("react.memo_cache_sentinel")?(_=N=>{const{scrollLeft:z,scrollTop:P}=N.currentTarget;d.current!==null&&(d.current.scrollTop=P),a.current!==null&&(a.current.scrollTop=P,a.current.scrollLeft=z)},e[21]=_):_=e[21];const O=_;let $;e[22]===Symbol.for("react.memo_cache_sentinel")?($=N=>{const z=i.current;z===null||N.offset===void 0||(z.focus(),z.setSelectionRange(N.offset,N.offset+(N.length??0)))},e[22]=$):$=e[22];const M=$;let E;e[23]!==S||e[24]!==I||e[25]!==R||e[26]!==q?(E={onBlur:I,onChange:S,onKeyDown:R,onScroll:O,onSelect:q},e[23]=S,e[24]=I,e[25]=R,e[26]=q,e[27]=E):E=e[27];let D;return e[28]!==v||e[29]!==h||e[30]!==s||e[31]!==b||e[32]!==E?(D={autocompleteState:v,closeAutocomplete:h,handlers:E,listboxId:s,onPickSuggestion:b,editorRef:i,gutterRef:d,overlayRef:a,revealDiagnostic:M},e[28]=v,e[29]=h,e[30]=s,e[31]=b,e[32]=E,e[33]=D):D=e[33],D},pn="lunora-studio-sql-tabs",bn="lunora-studio-sql-active-tab",Ae=12,ve=(l="",e="")=>({activeId:null,id:We("tab"),name:e,sql:l}),gn=()=>Ke(bn,""),xn=l=>{const e=K(16),[t,n]=Oe(pn),[r,o]=gn(),[s]=te(l);let d,a;e[0]!==s||e[1]!==n||e[2]!==t.length?(d=()=>{t.length===0&&n([s])},a=[s,n,t.length],e[0]=s,e[1]=n,e[2]=t.length,e[3]=d,e[4]=a):(d=e[3],a=e[4]),qe(d,a);let i;e[5]!==s||e[6]!==t?(i=t.length===0?[s]:t,e[5]=s,e[6]=t,e[7]=i):i=e[7];const f=i;let h;e[8]!==r||e[9]!==f?(h=f.some(c=>c.id===r)?r:f[0]?.id??"",e[8]=r,e[9]=f,e[10]=h):h=e[10];const p=h;let x;return e[11]!==p||e[12]!==o||e[13]!==n||e[14]!==f?(x={activeId:p,setActiveId:o,setTabs:n,tabs:f},e[11]=p,e[12]=o,e[13]=n,e[14]=f,e[15]=x):x=e[15],x},Ve=l=>l.activeId===null&&l.sql.trim()!=="",vn=(l,e)=>[...l,e].slice(-Ae),yn=(l,e,t)=>{const n=l.findIndex(o=>o.id===e);if(n===-1)return{activeId:l[0]?.id??"",tabs:[...l]};const r=l.filter(o=>o.id!==e);if(r.length===0){const o=t();return{activeId:o.id,tabs:[o]}}return{activeId:r[Math.min(n,r.length-1)].id,tabs:r}},wn=(l,e)=>{const t=l.filter(n=>n.id===e);return t.length===0?{activeId:l[0]?.id??"",tabs:[...l]}:{activeId:e,tabs:t}},Sn=(l,e,t)=>{const n=l.findIndex(o=>o.id===e);if(n===-1)return{activeId:t,tabs:[...l]};const r=l.slice(0,n+1);return{activeId:r.some(o=>o.id===t)?t:e,tabs:r}},Nn=l=>{const e=l();return{activeId:e.id,tabs:[e]}},kn=(l,e,t)=>{if(l==="others")return e.filter(n=>n.id!==t);if(l==="right"){const n=e.findIndex(r=>r.id===t);return n===-1?[]:e.slice(n+1)}return[...e]},je={error:null,pane:"results",result:null},Cn=l=>{const e=K(66),{activeId:t,setActiveId:n,setTabs:r,tabs:o}=xn(l);let s;e[0]===Symbol.for("react.memo_cache_sentinel")?(s={},e[0]=s):s=e[0];const[d,a]=te(s),[i,f]=te(null),[h,p]=te(null);let x;e[1]!==t||e[2]!==o?(x=o.find(H=>H.id===t)??o[0]??ve(),e[1]=t,e[2]=o,e[3]=x):x=e[3];const c=x,g=d[c.id]??je;let v;e[4]!==c.id||e[5]!==r?(v=H=>{r(W=>W.map(Y=>Y.id===c.id?{...Y,...H}:Y))},e[4]=c.id,e[5]=r,e[6]=v):v=e[6];const y=v;let b;e[7]!==c.id?(b=H=>{a(W=>{const Y=W[c.id]??je;return{...W,[c.id]:{...Y,...H}}})},e[7]=c.id,e[8]=b):b=e[8];const m=b;let w;e[9]!==n||e[10]!==r||e[11]!==o.length?(w=()=>{if(o.length>=Ae)return;const H=ve();r(W=>vn(W,H)),n(H.id)},e[9]=n,e[10]=r,e[11]=o.length,e[12]=w):w=e[12];const k=w;let S;e[13]!==n||e[14]!==r?(S=H=>{f(null),p(null),r(H.tabs),n(H.activeId);const W=new Set(H.tabs.map(qn));a(Y=>Object.fromEntries(Object.entries(Y).filter(ae=>{const[xe]=ae;return W.has(xe)})))},e[13]=n,e[14]=r,e[15]=S):S=e[15];const C=S;let q;e[16]!==C||e[17]!==o?(q=H=>{C(yn(o,H,ve))},e[16]=C,e[17]=o,e[18]=q):q=e[18];const L=q;let R;e[19]!==t||e[20]!==C||e[21]!==o?(R=(H,W)=>{C(H==="others"?wn(o,W):H==="right"?Sn(o,W,t):Nn(ve))},e[19]=t,e[20]=C,e[21]=o,e[22]=R):R=e[22];const T=R;let I;e[23]!==T||e[24]!==i||e[25]!==o?(I=H=>{i!==null&&(kn(H,o,i.id).some($n)?p(H):T(H,i.id))},e[23]=T,e[24]=i,e[25]=o,e[26]=I):I=e[26];const _=I;let O;e[27]===Symbol.for("react.memo_cache_sentinel")?(O=(H,W)=>{W.preventDefault(),p(null),f({id:H,x:W.clientX,y:W.clientY})},e[27]=O):O=e[27];const $=O;let M;e[28]===Symbol.for("react.memo_cache_sentinel")?(M=()=>{f(null),p(null)},e[28]=M):M=e[28];const E=M;let D;e[29]===Symbol.for("react.memo_cache_sentinel")?(D=H=>{H.preventDefault(),f(null),p(null)},e[29]=D):D=e[29];const N=D;let z;e[30]!==_?(z=()=>{_("others")},e[30]=_,e[31]=z):z=e[31];const P=z;let Q;e[32]!==_?(Q=()=>{_("right")},e[32]=_,e[33]=Q):Q=e[33];const j=Q;let F;e[34]!==_?(F=()=>{_("all")},e[34]=_,e[35]=F):F=e[35];const X=F;let U;e[36]!==T||e[37]!==h||e[38]!==i?(U=()=>{i!==null&&h!==null&&T(h,i.id),p(null)},e[36]=T,e[37]=h,e[38]=i,e[39]=U):U=e[39];const ne=U;let A;e[40]===Symbol.for("react.memo_cache_sentinel")?(A=()=>{p(null)},e[40]=A):A=e[40];const re=A;let J;e[41]!==i?(J=i===null?void 0:{left:i.x,top:i.y},e[41]=i,e[42]=J):J=e[42];const Z=J;let G;e[43]!==r?(G=H=>{r(W=>W.map(Y=>Y.activeId===H?{...Y,activeId:null}:Y))},e[43]=r,e[44]=G):G=e[44];const ee=G;let V;e[45]!==r?(V=(H,W)=>{r(Y=>Y.map(ae=>ae.id===H?{...ae,name:W}:ae))},e[45]=r,e[46]=V):V=e[46];const le=V;let ie;return e[47]!==c||e[48]!==t||e[49]!==k||e[50]!==L||e[51]!==ne||e[52]!==X||e[53]!==P||e[54]!==j||e[55]!==g||e[56]!==m||e[57]!==y||e[58]!==h||e[59]!==le||e[60]!==n||e[61]!==i||e[62]!==Z||e[63]!==o||e[64]!==ee?(ie={activeTab:c,activeTabId:t,addEditorTab:k,cancelBulk:re,closeEditorTab:L,closeTabMenu:E,confirmBulk:ne,menuStyle:Z,onBackdropContextMenu:N,onCloseAll:X,onCloseOthers:P,onCloseToRight:j,openTabMenu:$,output:g,patchActiveOutput:m,patchActiveTab:y,pendingBulk:h,renameTab:le,setActiveTabId:n,tabMenu:i,tabs:o,unlinkQuery:ee},e[47]=c,e[48]=t,e[49]=k,e[50]=L,e[51]=ne,e[52]=X,e[53]=P,e[54]=j,e[55]=g,e[56]=m,e[57]=y,e[58]=h,e[59]=le,e[60]=n,e[61]=i,e[62]=Z,e[63]=o,e[64]=ee,e[65]=ie):ie=e[65],ie};function qn(l){return l.id}function $n(l){return Ve(l)}const Tn="lunora-studio-sql-queries",Rn="lunora-studio-sql-history",In=25,En=l=>{const e=K(33),{loadIntoActiveTab:t,unlinkQuery:n}=l,r=oe(),[o,s]=Oe(Tn),[d,a]=Oe(Rn),[i,f]=te(""),h=ye(null);let p;e[0]!==a?(p=$=>{a(M=>M[0]?.sql===$?M:[{at:Date.now(),sql:$},...M.filter(E=>E.sql!==$)].slice(0,In))},e[0]=a,e[1]=p):p=e[1];const x=p;let c;e[2]!==t||e[3]!==s||e[4]!==r?(c=()=>{const $={id:We("q"),name:r("Untitled query"),sql:""};s(M=>[$,...M]),t("",$.id)},e[2]=t,e[3]=s,e[4]=r,e[5]=c):c=e[5];const g=c;let v;e[6]!==t||e[7]!==o?(v=$=>{const M=o.find(E=>E.id===$);M!==void 0&&(t(M.sql,$),h.current?.querySelector(`[data-testid="sql-query-${$}"]`)?.scrollIntoView({block:"nearest"}))},e[6]=t,e[7]=o,e[8]=v):v=e[8];const y=v;let b;e[9]!==s||e[10]!==n?(b=$=>{s(M=>M.filter(E=>E.id!==$)),n($)},e[9]=s,e[10]=n,e[11]=b):b=e[11];const m=b;let w;e[12]!==t?(w=$=>{t($.currentTarget.dataset.sql??"",null)},e[12]=t,e[13]=w):w=e[13];const k=w;let S;e[14]!==t?(S=$=>{t($.currentTarget.dataset.sql??"",null)},e[14]=t,e[15]=S):S=e[15];const C=S;let q;e[16]!==a?(q=()=>{a([])},e[16]=a,e[17]=q):q=e[17];const L=q;let R;e[18]===Symbol.for("react.memo_cache_sentinel")?(R=$=>{f($.target.value)},e[18]=R):R=e[18];const T=R;let I;e[19]!==s?(I=($,M)=>{s(E=>E.map(D=>D.id===$?{...D,sql:M}:D))},e[19]=s,e[20]=I):I=e[20];const _=I;let O;return e[21]!==L||e[22]!==m||e[23]!==d||e[24]!==C||e[25]!==k||e[26]!==g||e[27]!==o||e[28]!==x||e[29]!==i||e[30]!==y||e[31]!==_?(O={clearHistory:L,deleteQuery:m,history:d,listRef:h,loadFromHistory:C,loadTemplate:k,newQuery:g,onSearchChange:T,queries:o,recordHistory:x,search:i,selectQuery:y,updateQuerySql:_},e[21]=L,e[22]=m,e[23]=d,e[24]=C,e[25]=k,e[26]=g,e[27]=o,e[28]=x,e[29]=i,e[30]=y,e[31]=_,e[32]=O):O=e[32],O},Xe="p-3 font-mono text-xs leading-5 whitespace-pre-wrap break-words",Ln=(l,e)=>{const t=[];for(const r of l){if(r.offset===void 0||r.length===void 0||r.length<=0)continue;const o=Math.max(0,Math.min(r.offset,e)),s=Math.max(o,Math.min(r.offset+r.length,e));o!==s&&t.push({end:s,severity:r.severity,start:o})}t.sort((r,o)=>r.start-o.start);const n=[];for(const r of t)r.start>=(n.at(-1)?.end??0)&&n.push(r);return n},_n=l=>l==="unsafe-response"?"The model returned a statement that is not read-only, so it was discarded.":l==="empty-response"?"The model returned nothing usable.":"The model could not be reached.",On=l=>{const e=K(51),{assistant:t,failed:n,onGenerated:r}=l,o=oe(),[s,d]=te("");if(t.unavailable)return null;let a;e[0]!==t?(a=t.pending("sql"),e[0]=t,e[1]=a):a=e[1];const i=a;let f;if(e[2]!==t||e[3]!==n||e[4]!==r||e[5]!==i||e[6]!==s||e[7]!==o){const h=t.reason("sql");let p;e[9]!==t||e[10]!==n||e[11]!==r||e[12]!==s?(p=T=>{const I=s.trim();I===""&&!T||de((async()=>{const _=await t.generate(I===""?"fix the failing statement":I,T?n:void 0);_!==void 0&&r(_)})())},e[9]=t,e[10]=n,e[11]=r,e[12]=s,e[13]=p):p=e[13];const x=p;let c;e[14]!==o?(c=o("Describe the query you want"),e[14]=o,e[15]=c):c=e[15];let g;e[16]===Symbol.for("react.memo_cache_sentinel")?(g=T=>{d(T.target.value)},e[16]=g):g=e[16];let v;e[17]!==x?(v=T=>{T.key==="Enter"&&(T.preventDefault(),x(!1))},e[17]=x,e[18]=v):v=e[18];let y;e[19]!==o?(y=o("Describe the query you want"),e[19]=o,e[20]=y):y=e[20];let b;e[21]!==i||e[22]!==s||e[23]!==c||e[24]!==v||e[25]!==y?(b=u(lt,{"aria-label":c,className:"h-7 flex-1 text-xs","data-testid":"sql-assistant-prompt",disabled:i,onChange:g,onKeyDown:v,placeholder:y,value:s}),e[21]=i,e[22]=s,e[23]=c,e[24]=v,e[25]=y,e[26]=b):b=e[26];const m=i&&"opacity-60";let w;e[27]!==m?(w=ue("rounded-md border border-border px-2 py-1 text-xs outline-none transition-colors hover:bg-accent focus-visible:bg-accent",m),e[27]=m,e[28]=w):w=e[28];let k;e[29]!==i||e[30]!==s?(k=i||s.trim()==="",e[29]=i,e[30]=s,e[31]=k):k=e[31];let S;e[32]!==x?(S=()=>{x(!1)},e[32]=x,e[33]=S):S=e[33];let C;e[34]!==i||e[35]!==o?(C=o(i?"Thinking…":"Draft SQL"),e[34]=i,e[35]=o,e[36]=C):C=e[36];let q;e[37]!==w||e[38]!==k||e[39]!==S||e[40]!==C?(q=u("button",{className:w,"data-testid":"sql-assistant-generate",disabled:k,onClick:S,type:"button",children:C}),e[37]=w,e[38]=k,e[39]=S,e[40]=C,e[41]=q):q=e[41];let L;e[42]!==n||e[43]!==i||e[44]!==x||e[45]!==o?(L=n!==void 0&&u("button",{className:"rounded-md border border-border px-2 py-1 text-xs outline-none transition-colors hover:bg-accent focus-visible:bg-accent","data-testid":"sql-assistant-fix",disabled:i,onClick:()=>{x(!0)},type:"button",children:o("Fix this")}),e[42]=n,e[43]=i,e[44]=x,e[45]=o,e[46]=L):L=e[46];let R;e[47]!==q||e[48]!==L||e[49]!==b?(R=B("div",{className:"flex items-center gap-2",children:[b,q,L]}),e[47]=q,e[48]=L,e[49]=b,e[50]=R):R=e[50],f=B("div",{className:"flex flex-col gap-1 border-b border-border px-3 py-2","data-testid":"sql-assistant",children:[R,h!==void 0&&u("p",{className:"text-[11px] text-muted-foreground","data-testid":"sql-assistant-reason",role:"status",children:_n(h)})]}),e[2]=t,e[3]=n,e[4]=r,e[5]=i,e[6]=s,e[7]=o,e[8]=f}else f=e[8];return f},Mn=l=>{const e=K(8),{diagnostics:t,draft:n,scrollRef:r}=l;let o,s;if(e[0]!==t||e[1]!==n){s=Symbol.for("react.early_return_sentinel");e:{const i=Ln(t,n.length);if(i.length===0){s=null;break e}o=[];let f=0;for(const[h,p]of i.entries())p.start>f&&o.push(n.slice(f,p.start)),o.push(u("span",{className:ue("decoration-wavy underline underline-offset-4",p.severity==="error"?"decoration-destructive":"decoration-amber-500"),children:n.slice(p.start,p.end)},`${p.start.toString()}-${h.toString()}`)),f=p.end;o.push(n.slice(f))}e[0]=t,e[1]=n,e[2]=o,e[3]=s}else o=e[2],s=e[3];if(s!==Symbol.for("react.early_return_sentinel"))return s;let d;e[4]===Symbol.for("react.memo_cache_sentinel")?(d=ue("pointer-events-none absolute inset-0 overflow-hidden text-transparent",Xe),e[4]=d):d=e[4];let a;return e[5]!==o||e[6]!==r?(a=u("div",{"aria-hidden":"true",className:d,"data-testid":"sql-diagnostics-overlay",ref:r,children:o}),e[5]=o,e[6]=r,e[7]=a):a=e[7],a},Dn={gate:"read-only",plan:"plan",schema:"schema",syntax:"syntax"},An=l=>{const e=K(10),{diagnostics:t,onSelect:n}=l,r=oe();if(t.length===0)return null;let o;e[0]!==r?(o=r("SQL problems"),e[0]=r,e[1]=o):o=e[1];let s;if(e[2]!==t||e[3]!==n){let a;e[5]!==n?(a=(i,f)=>u("li",{children:B("button",{className:"flex w-full items-start gap-2 px-3 py-1 text-start text-xs outline-none hover:bg-accent focus-visible:bg-accent","data-testid":"sql-problem",onClick:()=>{n(i)},type:"button",children:[u("span",{className:ue("mt-px shrink-0 rounded px-1 font-mono text-[10px] uppercase",i.severity==="error"?"bg-destructive/15 text-destructive":"bg-amber-500/15 text-amber-600"),children:Dn[i.source]}),u("span",{className:"min-w-0 text-muted-foreground",children:i.message})]})},`${i.source}-${(i.offset??f).toString()}-${f.toString()}`),e[5]=n,e[6]=a):a=e[6],s=t.map(a),e[2]=t,e[3]=n,e[4]=s}else s=e[4];let d;return e[7]!==o||e[8]!==s?(d=u("ul",{"aria-label":o,className:"max-h-24 shrink-0 overflow-y-auto border-t border-border bg-muted/30","data-testid":"sql-problems",children:s}),e[7]=o,e[8]=s,e[9]=d):d=e[9],d},Bn={minWidth:"2.75rem",paddingInline:"0.5rem"},zn=l=>{const e=K(64),{assistant:t,autocomplete:n,diagnostics:r,draft:o,failed:s,handlers:d,editorRef:a,gutterRef:i,listboxId:f,onGenerated:h,onPickSuggestion:p,onRevealDiagnostic:x,overlayRef:c}=l,g=oe();let v,y,b,m,w,k,S,C;if(e[0]!==t||e[1]!==o||e[2]!==s||e[3]!==i||e[4]!==h){const z=o.split(`
|
|
5
|
-
`).length;S="flex min-h-0 min-w-0 flex-1 flex-col",e[13]!==t||e[14]!==s||e[15]!==h?(C=u(On,{assistant:t,failed:s,onGenerated:h}),e[13]=t,e[14]=s,e[15]=h,e[16]=C):C=e[16],k="flex min-h-0 min-w-0 flex-1",v="true",y="shrink-0 select-none overflow-hidden border-e border-border bg-muted/30 py-3 text-end font-mono text-xs leading-5 text-muted-foreground/60",b=i,m=Bn,w=Array.from({length:z},Hn),e[0]=t,e[1]=o,e[2]=s,e[3]=i,e[4]=h,e[5]=v,e[6]=y,e[7]=b,e[8]=m,e[9]=w,e[10]=k,e[11]=S,e[12]=C}else v=e[5],y=e[6],b=e[7],m=e[8],w=e[9],k=e[10],S=e[11],C=e[12];let q;e[17]!==v||e[18]!==y||e[19]!==b||e[20]!==m||e[21]!==w?(q=u("div",{"aria-hidden":v,className:y,ref:b,style:m,children:w}),e[17]=v,e[18]=y,e[19]=b,e[20]=m,e[21]=w,e[22]=q):q=e[22];let L;e[23]!==r||e[24]!==o||e[25]!==c?(L=u(Mn,{diagnostics:r,draft:o,scrollRef:c}),e[23]=r,e[24]=o,e[25]=c,e[26]=L):L=e[26];let R;e[27]!==n||e[28]!==f?(R=n===null?void 0:`${f}-opt-${n.active.toString()}`,e[27]=n,e[28]=f,e[29]=R):R=e[29];const T=n===null?void 0:f,I=n!==null;let _;e[30]!==g?(_=g("SQL query"),e[30]=g,e[31]=_):_=e[31];let O;e[32]!==o||e[33]!==a||e[34]!==d.onBlur||e[35]!==d.onChange||e[36]!==d.onKeyDown||e[37]!==d.onScroll||e[38]!==d.onSelect||e[39]!==R||e[40]!==T||e[41]!==I||e[42]!==_?(O=u("textarea",{"aria-activedescendant":R,"aria-autocomplete":"list","aria-controls":T,"aria-expanded":I,"aria-label":_,className:`relative size-full resize-none bg-transparent outline-none ${Xe}`,"data-testid":"sql-input",onBlur:d.onBlur,onChange:d.onChange,onKeyDown:d.onKeyDown,onScroll:d.onScroll,onSelect:d.onSelect,placeholder:"SELECT * FROM …",ref:a,role:"combobox",spellCheck:!1,value:o}),e[32]=o,e[33]=a,e[34]=d.onBlur,e[35]=d.onChange,e[36]=d.onKeyDown,e[37]=d.onScroll,e[38]=d.onSelect,e[39]=R,e[40]=T,e[41]=I,e[42]=_,e[43]=O):O=e[43];let $;e[44]!==n||e[45]!==f||e[46]!==p?($=u(an,{listboxId:f,onPick:p,state:n}),e[44]=n,e[45]=f,e[46]=p,e[47]=$):$=e[47];let M;e[48]!==L||e[49]!==O||e[50]!==$?(M=B("div",{className:"relative min-w-0 flex-1 bg-background",children:[L,O,$]}),e[48]=L,e[49]=O,e[50]=$,e[51]=M):M=e[51];let E;e[52]!==M||e[53]!==k||e[54]!==q?(E=B("div",{className:k,children:[q,M]}),e[52]=M,e[53]=k,e[54]=q,e[55]=E):E=e[55];let D;e[56]!==r||e[57]!==x?(D=u(An,{diagnostics:r,onSelect:x}),e[56]=r,e[57]=x,e[58]=D):D=e[58];let N;return e[59]!==E||e[60]!==D||e[61]!==S||e[62]!==C?(N=B("div",{className:S,children:[C,E,D]}),e[59]=E,e[60]=D,e[61]=S,e[62]=C,e[63]=N):N=e[63],N};function Hn(l,e){return u("div",{children:e+1},e)}const Ze=[{label:"List tables",sql:"SELECT name FROM sqlite_master WHERE type = 'table' ORDER BY name;"},{label:"Table row count",sql:"SELECT COUNT(*) AS rows FROM messages;"},{label:"Recent rows",sql:"SELECT id, _creationTime, __doc__ FROM messages ORDER BY _creationTime DESC LIMIT 50;"},{label:"Index list",sql:"SELECT name, tbl_name FROM sqlite_master WHERE type = 'index' ORDER BY tbl_name;"}],Pn=l=>{const e=K(29),{active:t,onDelete:n,onSelect:r,query:o}=l,s=oe();let d;e[0]!==r||e[1]!==o.id?(d=()=>{r(o.id)},e[0]=r,e[1]=o.id,e[2]=d):d=e[2];const a=d;let i;e[3]!==n||e[4]!==o.id?(i=S=>{S.stopPropagation(),n(o.id)},e[3]=n,e[4]=o.id,e[5]=i):i=e[5];const f=i,h=t?"bg-sidebar-accent font-medium text-foreground":"text-muted-foreground";let p;e[6]!==h?(p=ue("flex min-w-0 flex-1 items-center gap-2 rounded-md px-2 py-1.5 text-start text-[13px] outline-none transition-colors hover:bg-sidebar-accent focus-visible:bg-sidebar-accent",h),e[6]=h,e[7]=p):p=e[7];const x=`sql-query-${o.id}`;let c;e[8]===Symbol.for("react.memo_cache_sentinel")?(c=u("svg",{"aria-hidden":"true",className:"size-3.5 shrink-0 opacity-70",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:u("path",{d:"M4 6h16M4 12h10M4 18h7"})}),e[8]=c):c=e[8];let g;e[9]!==o.name?(g=u("span",{className:"truncate",children:o.name}),e[9]=o.name,e[10]=g):g=e[10];let v;e[11]!==t||e[12]!==a||e[13]!==p||e[14]!==x||e[15]!==g?(v=B("button",{"aria-pressed":t,className:p,"data-testid":x,onClick:a,type:"button",children:[c,g]}),e[11]=t,e[12]=a,e[13]=p,e[14]=x,e[15]=g,e[16]=v):v=e[16];let y;e[17]!==s?(y=s("Delete query"),e[17]=s,e[18]=y):y=e[18];let b;e[19]!==s?(b=s("Delete query"),e[19]=s,e[20]=b):b=e[20];let m;e[21]===Symbol.for("react.memo_cache_sentinel")?(m=u("svg",{"aria-hidden":"true",className:"size-3.5",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:u("path",{d:"M5 7h14M9 7V5h6v2m-1 0v12H10V7M7 7v13h10V7"})}),e[21]=m):m=e[21];let w;e[22]!==f||e[23]!==b||e[24]!==y?(w=u("button",{"aria-label":y,className:"me-1 hidden size-6 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-destructive/10 hover:text-destructive group-hover/q:flex",onClick:f,title:b,type:"button",children:m}),e[22]=f,e[23]=b,e[24]=y,e[25]=w):w=e[25];let k;return e[26]!==w||e[27]!==v?(k=B("li",{className:"group/q flex items-center",children:[v,w]}),e[26]=w,e[27]=v,e[28]=k):k=e[28],k},Fn=(l,e)=>{const t=e.trim().toLowerCase();return t===""?[...l]:l.filter(n=>n.name.toLowerCase().includes(t))},Qn=l=>{const e=K(60),{activeId:t,history:n,listRef:r,onClearHistory:o,onDelete:s,onLoadHistory:d,onLoadTemplate:a,onNew:i,onSearchChange:f,onSelect:h,queries:p,search:x}=l,c=oe();let g,v,y,b;if(e[0]!==t||e[1]!==r||e[2]!==s||e[3]!==i||e[4]!==f||e[5]!==h||e[6]!==p||e[7]!==x||e[8]!==c){const T=Fn(p,x);v="flex h-full w-64 shrink-0 flex-col border-e border-border bg-sidebar";let I;e[13]!==c?(I=c("Search queries…"),e[13]=c,e[14]=I):I=e[14];let _;e[15]!==f||e[16]!==x||e[17]!==I?(_=u("input",{className:"h-8 min-w-0 flex-1 rounded-md border border-border bg-background px-2 text-xs outline-none focus-visible:border-ring","data-testid":"sql-search",onChange:f,placeholder:I,type:"text",value:x}),e[15]=f,e[16]=x,e[17]=I,e[18]=_):_=e[18];let O;e[19]!==c?(O=c("New query"),e[19]=c,e[20]=O):O=e[20];let $;e[21]!==c?($=c("New query"),e[21]=c,e[22]=$):$=e[22];let M;e[23]===Symbol.for("react.memo_cache_sentinel")?(M=u("svg",{"aria-hidden":"true",className:"size-4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.7,viewBox:"0 0 24 24",children:u("path",{d:"M12 5v14M5 12h14"})}),e[23]=M):M=e[23];let E;e[24]!==i||e[25]!==O||e[26]!==$?(E=u("button",{"aria-label":O,className:"flex size-8 shrink-0 items-center justify-center rounded-md border border-border text-foreground outline-none transition-colors hover:bg-accent focus-visible:bg-accent","data-testid":"sql-new",onClick:i,title:$,type:"button",children:M}),e[24]=i,e[25]=O,e[26]=$,e[27]=E):E=e[27],e[28]!==E||e[29]!==_?(y=B("div",{className:"flex shrink-0 items-center gap-2 border-b border-border p-2",children:[_,E]}),e[28]=E,e[29]=_,e[30]=y):y=e[30],g="flex flex-1 flex-col gap-4 overflow-y-auto p-2";let D;e[31]!==c?(D=c("Private"),e[31]=c,e[32]=D):D=e[32];let N;e[33]!==D?(N=u("p",{className:"px-1 pb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:D}),e[33]=D,e[34]=N):N=e[34],b=B("div",{children:[N,T.length===0?u("p",{className:"px-1 py-2 text-xs text-muted-foreground","data-testid":"sql-private-empty",children:c("No saved queries yet — they save to this browser as you type.")}):u("ul",{className:"flex flex-col gap-px","data-testid":"sql-private",ref:r,children:T.map(z=>u(Pn,{active:t===z.id,onDelete:s,onSelect:h,query:z},z.id))})]}),e[0]=t,e[1]=r,e[2]=s,e[3]=i,e[4]=f,e[5]=h,e[6]=p,e[7]=x,e[8]=c,e[9]=g,e[10]=v,e[11]=y,e[12]=b}else g=e[9],v=e[10],y=e[11],b=e[12];let m;e[35]!==c?(m=c("Reference"),e[35]=c,e[36]=m):m=e[36];let w;e[37]!==m?(w=u("p",{className:"px-1 pb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:m}),e[37]=m,e[38]=w):w=e[38];let k;e[39]!==a?(k=Ze.map(T=>u("li",{children:B("button",{className:"flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-start text-[13px] text-muted-foreground outline-none transition-colors hover:bg-sidebar-accent hover:text-foreground focus-visible:bg-sidebar-accent","data-sql":T.sql,onClick:a,type:"button",children:[u("svg",{"aria-hidden":"true",className:"size-3.5 shrink-0 opacity-70",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:u("path",{d:"M7 4h7l4 4v12H7zM14 4v4h4"})}),T.label]})},T.label)),e[39]=a,e[40]=k):k=e[40];let S;e[41]!==k?(S=u("ul",{className:"flex flex-col gap-px",children:k}),e[41]=k,e[42]=S):S=e[42];let C;e[43]!==w||e[44]!==S?(C=B("div",{children:[w,S]}),e[43]=w,e[44]=S,e[45]=C):C=e[45];let q;e[46]!==n||e[47]!==o||e[48]!==d||e[49]!==c?(q=n.length>0&&B("div",{children:[B("div",{className:"flex items-center justify-between px-1 pb-1",children:[u("p",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:c("History")}),u("button",{className:"rounded px-1 text-[11px] text-muted-foreground outline-none transition-colors hover:text-foreground focus-visible:text-foreground","data-testid":"sql-history-clear",onClick:o,type:"button",children:c("Clear history")})]}),u("ul",{className:"flex flex-col gap-px","data-testid":"sql-history",children:n.map(T=>u("li",{children:B("button",{className:"flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-start text-[13px] text-muted-foreground outline-none transition-colors hover:bg-sidebar-accent hover:text-foreground focus-visible:bg-sidebar-accent","data-sql":T.sql,"data-testid":"sql-history-item",onClick:d,title:T.sql,type:"button",children:[u("svg",{"aria-hidden":"true",className:"size-3.5 shrink-0 opacity-70",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:u("path",{d:"M12 8v4l3 2M12 21a9 9 0 1 1 0-18 9 9 0 0 1 0 18Z"})}),u("span",{className:"truncate font-mono",children:T.sql})]})},`${T.at.toString()}:${T.sql}`))})]}),e[46]=n,e[47]=o,e[48]=d,e[49]=c,e[50]=q):q=e[50];let L;e[51]!==g||e[52]!==q||e[53]!==b||e[54]!==C?(L=B("div",{className:g,children:[b,C,q]}),e[51]=g,e[52]=q,e[53]=b,e[54]=C,e[55]=L):L=e[55];let R;return e[56]!==L||e[57]!==v||e[58]!==y?(R=B("aside",{className:v,children:[y,L]}),e[56]=L,e[57]=v,e[58]=y,e[59]=R):R=e[59],R},jn=l=>{const e=K(19),{result:t}=l,n=oe();if(t.columns.length===0){let i;e[0]!==t.rowCount||e[1]!==n?(i=n("{count} rows",{count:t.rowCount}),e[0]=t.rowCount,e[1]=n,e[2]=i):i=e[2];let f;return e[3]!==i?(f=u("p",{className:"p-4 text-sm text-muted-foreground",children:i}),e[3]=i,e[4]=f):f=e[4],f}let r;e[5]!==t.columns?(r=t.columns.map(Wn),e[5]=t.columns,e[6]=r):r=e[6];let o;e[7]!==r?(o=u(dt,{className:"sticky top-0 z-10 bg-muted",children:u(Pe,{children:r})}),e[7]=r,e[8]=o):o=e[8];let s;if(e[9]!==t.columns||e[10]!==t.rows){let i;e[12]!==t.columns?(i=(f,h)=>u(Pe,{"data-testid":"sql-row",children:t.columns.map(p=>u(ht,{className:"max-w-md truncate font-mono text-xs",children:u(pt,{value:f[p]})},p))},h),e[12]=t.columns,e[13]=i):i=e[13],s=t.rows.map(i),e[9]=t.columns,e[10]=t.rows,e[11]=s}else s=e[11];let d;e[14]!==s?(d=u(ut,{children:s}),e[14]=s,e[15]=d):d=e[15];let a;return e[16]!==o||e[17]!==d?(a=B(mt,{"data-testid":"sql-rows",children:[o,d]}),e[16]=o,e[17]=d,e[18]=a):a=e[18],a};function Wn(l){return u(ft,{children:l},l)}const Ne=l=>`border-b-2 px-3 py-2 text-sm outline-none transition-colors ${l?"border-foreground font-medium text-foreground":"border-transparent text-muted-foreground hover:text-foreground"}`,Kn=l=>{const e=K(92),{assistant:t,chart:n,className:r,error:o,onFormat:s,onInferChart:d,onRun:a,onShardKeyChange:i,onShowChart:f,onShowExplain:h,onShowResults:p,onToggleSplit:x,pane:c,result:g,running:v,shardKey:y,splitView:b}=l,m=oe(),w=c==="results";let k;e[0]!==w?(k=Ne(w),e[0]=w,e[1]=k):k=e[1];let S;e[2]!==m?(S=m("Results"),e[2]=m,e[3]=S):S=e[3];let C;e[4]!==p||e[5]!==k||e[6]!==S?(C=u("button",{className:k,"data-testid":"sql-tab-results",onClick:p,type:"button",children:S}),e[4]=p,e[5]=k,e[6]=S,e[7]=C):C=e[7];const q=c==="chart";let L;e[8]!==q?(L=Ne(q),e[8]=q,e[9]=L):L=e[9];let R;e[10]!==m?(R=m("Chart"),e[10]=m,e[11]=R):R=e[11];let T;e[12]!==f||e[13]!==L||e[14]!==R?(T=u("button",{className:L,"data-testid":"sql-tab-chart",onClick:f,type:"button",children:R}),e[12]=f,e[13]=L,e[14]=R,e[15]=T):T=e[15];let I;e[16]!==t||e[17]!==d||e[18]!==c||e[19]!==g||e[20]!==m?(I=!t.unavailable&&c==="chart"&&g!==null&&u("button",{className:Ne(!1),"data-testid":"sql-infer-chart",disabled:t.pending("chart"),onClick:d,type:"button",children:t.pending("chart")?m("Thinking…"):m("Suggest chart")}),e[16]=t,e[17]=d,e[18]=c,e[19]=g,e[20]=m,e[21]=I):I=e[21];const _=c==="explain";let O;e[22]!==_?(O=Ne(_),e[22]=_,e[23]=O):O=e[23];let $;e[24]!==m?($=m("Explain"),e[24]=m,e[25]=$):$=e[25];let M;e[26]!==h||e[27]!==O||e[28]!==$?(M=u("button",{className:O,"data-testid":"sql-tab-explain",onClick:h,type:"button",children:$}),e[26]=h,e[27]=O,e[28]=$,e[29]=M):M=e[29];let E;e[30]!==m?(E=m("Split editor and results"),e[30]=m,e[31]=E):E=e[31];const D=`inline-flex items-center rounded-md border border-border px-2 py-1.5 outline-none transition-colors hover:bg-accent focus-visible:bg-accent ${b?"bg-accent text-foreground":"text-muted-foreground"}`;let N;e[32]!==m?(N=m("Split editor and results"),e[32]=m,e[33]=N):N=e[33];let z;e[34]===Symbol.for("react.memo_cache_sentinel")?(z=B("svg",{"aria-hidden":"true",className:"size-4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.7,viewBox:"0 0 24 24",children:[u("rect",{height:"16",rx:"2",width:"18",x:"3",y:"4"}),u("path",{d:"M12 4v16"})]}),e[34]=z):z=e[34];let P;e[35]!==x||e[36]!==b||e[37]!==E||e[38]!==D||e[39]!==N?(P=u("button",{"aria-label":E,"aria-pressed":b,className:D,"data-testid":"sql-split-toggle",onClick:x,title:N,type:"button",children:z}),e[35]=x,e[36]=b,e[37]=E,e[38]=D,e[39]=N,e[40]=P):P=e[40];let Q;e[41]!==g?(Q=g!==null&&g.columns.length>0&&u(ct,{columns:g.columns,name:"query-result",rows:g.rows}),e[41]=g,e[42]=Q):Q=e[42];let j;e[43]!==m?(j=m("Format"),e[43]=m,e[44]=j):j=e[44];let F;e[45]!==s||e[46]!==v||e[47]!==j?(F=u("button",{className:"inline-flex items-center rounded-md border border-border px-3 py-1.5 text-xs font-medium text-foreground outline-none transition-colors hover:bg-accent focus-visible:bg-accent disabled:pointer-events-none disabled:opacity-50","data-testid":"sql-format",disabled:v,onClick:s,type:"button",children:j}),e[45]=s,e[46]=v,e[47]=j,e[48]=F):F=e[48];let X;e[49]!==i||e[50]!==y?(X=u(at,{onChange:i,testId:"sql-shard-input",value:y}),e[49]=i,e[50]=y,e[51]=X):X=e[51];let U;e[52]!==v||e[53]!==m?(U=m(v?"Running…":"Run"),e[52]=v,e[53]=m,e[54]=U):U=e[54];let ne;e[55]===Symbol.for("react.memo_cache_sentinel")?(ne=u("kbd",{className:"rounded border border-primary-foreground/30 px-1 font-sans text-[10px]",children:"⌘↵"}),e[55]=ne):ne=e[55];let A;e[56]!==a||e[57]!==v||e[58]!==U?(A=B("button",{className:"inline-flex items-center gap-1.5 rounded-md bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground outline-none transition-colors hover:bg-primary/90 focus-visible:bg-primary/90 disabled:pointer-events-none disabled:opacity-50","data-testid":"sql-run",disabled:v,onClick:a,type:"button",children:[U,ne]}),e[56]=a,e[57]=v,e[58]=U,e[59]=A):A=e[59];let re;e[60]!==P||e[61]!==Q||e[62]!==F||e[63]!==X||e[64]!==A?(re=B("div",{className:"ms-auto flex items-center gap-2",children:[P,Q,F,X,A]}),e[60]=P,e[61]=Q,e[62]=F,e[63]=X,e[64]=A,e[65]=re):re=e[65];let J;e[66]!==M||e[67]!==re||e[68]!==C||e[69]!==T||e[70]!==I?(J=B("div",{className:"flex shrink-0 items-center gap-2 border-b border-border pe-2",children:[C,T,I,M,re]}),e[66]=M,e[67]=re,e[68]=C,e[69]=T,e[70]=I,e[71]=J):J=e[71];let Z;e[72]!==o?(Z=o!==null&&u(it,{className:"m-3 font-mono text-xs",testId:"sql-error",variant:"destructive",children:o}),e[72]=o,e[73]=Z):Z=e[73];let G;e[74]!==o||e[75]!==g||e[76]!==m?(G=o===null&&g===null&&u("p",{className:"p-4 text-sm text-muted-foreground","data-testid":"sql-empty",children:m("Click Run to execute your query.")}),e[74]=o,e[75]=g,e[76]=m,e[77]=G):G=e[77];let ee;e[78]!==n||e[79]!==o||e[80]!==c||e[81]!==g||e[82]!==m?(ee=o===null&&g!==null&&B("div",{"data-testid":"sql-result",children:[c==="chart"?u(st,{axes:n,result:g}):u(jn,{result:g}),u("p",{className:"border-t border-border px-3 py-1.5 text-xs text-muted-foreground","data-testid":"sql-count",children:g.truncated?m("Showing the first {max} of {count} rows.",{count:g.rowCount,max:g.rows.length}):m("{count} rows",{count:g.rowCount})})]}),e[78]=n,e[79]=o,e[80]=c,e[81]=g,e[82]=m,e[83]=ee):ee=e[83];let V;e[84]!==Z||e[85]!==G||e[86]!==ee?(V=B("div",{className:"min-h-0 flex-1 overflow-auto",children:[Z,G,ee]}),e[84]=Z,e[85]=G,e[86]=ee,e[87]=V):V=e[87];let le;return e[88]!==r||e[89]!==J||e[90]!==V?(le=B("div",{className:r,children:[J,V]}),e[88]=r,e[89]=J,e[90]=V,e[91]=le):le=e[91],le},Un=(l,e)=>l.trim()===""?e:(l.split(`
|
|
6
|
-
`)[0]??l).slice(0,24),Yn=l=>{l?.focus(),l?.select()},Jn=l=>{const e=K(14),{initial:t,onCancel:n,onCommit:r,placeholder:o,testId:s}=l,d=oe();let a;e[0]!==r?(a=c=>{r(c.currentTarget.value.trim())},e[0]=r,e[1]=a):a=e[1];const i=a;let f;e[2]!==n||e[3]!==r?(f=c=>{c.key==="Enter"?r(c.currentTarget.value.trim()):c.key==="Escape"&&n()},e[2]=n,e[3]=r,e[4]=f):f=e[4];const h=f;let p;e[5]!==d?(p=d("Tab title"),e[5]=d,e[6]=p):p=e[6];let x;return e[7]!==t||e[8]!==i||e[9]!==h||e[10]!==o||e[11]!==p||e[12]!==s?(x=u("input",{"aria-label":p,className:"w-40 rounded border border-ring bg-background px-1 py-0.5 text-xs outline-none","data-testid":s,defaultValue:t,onBlur:i,onKeyDown:h,placeholder:o,ref:Yn,type:"text"}),e[7]=t,e[8]=i,e[9]=h,e[10]=o,e[11]=p,e[12]=s,e[13]=x):x=e[13],x},Gn=l=>{const e=K(29),{idBase:t,onDiscard:n,onKeep:r}=l,o=oe(),s=`sql-tab-close-prompt-${t}`;let d;e[0]!==o?(d=o("Discard?"),e[0]=o,e[1]=d):d=e[1];let a;e[2]!==d?(a=u("span",{className:"text-[11px] text-muted-foreground",children:d}),e[2]=d,e[3]=a):a=e[3];let i;e[4]!==o?(i=o("Discard changes"),e[4]=o,e[5]=i):i=e[5];const f=`sql-tab-close-confirm-${t}`;let h;e[6]!==o?(h=o("Discard changes"),e[6]=o,e[7]=h):h=e[7];let p;e[8]===Symbol.for("react.memo_cache_sentinel")?(p=u("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2.4,viewBox:"0 0 24 24",children:u("path",{d:"M5 13l4 4L19 7"})}),e[8]=p):p=e[8];let x;e[9]!==n||e[10]!==i||e[11]!==f||e[12]!==h?(x=u("button",{"aria-label":i,className:"flex size-5 items-center justify-center rounded text-destructive hover:bg-destructive/10","data-testid":f,onClick:n,title:h,type:"button",children:p}),e[9]=n,e[10]=i,e[11]=f,e[12]=h,e[13]=x):x=e[13];let c;e[14]!==o?(c=o("Keep editing"),e[14]=o,e[15]=c):c=e[15];const g=`sql-tab-close-cancel-${t}`;let v;e[16]!==o?(v=o("Keep editing"),e[16]=o,e[17]=v):v=e[17];let y;e[18]===Symbol.for("react.memo_cache_sentinel")?(y=u("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2.4,viewBox:"0 0 24 24",children:u("path",{d:"M6 6l12 12M18 6 6 18"})}),e[18]=y):y=e[18];let b;e[19]!==r||e[20]!==g||e[21]!==v||e[22]!==c?(b=u("button",{"aria-label":c,className:"flex size-5 items-center justify-center rounded text-muted-foreground hover:bg-accent","data-testid":g,onClick:r,title:v,type:"button",children:y}),e[19]=r,e[20]=g,e[21]=v,e[22]=c,e[23]=b):b=e[23];let m;return e[24]!==s||e[25]!==b||e[26]!==a||e[27]!==x?(m=B("span",{className:"flex shrink-0 items-center gap-1","data-testid":s,role:"group",children:[a,x,b]}),e[24]=s,e[25]=b,e[26]=a,e[27]=x,e[28]=m):m=e[28],m},Vn=l=>{const e=K(47),{active:t,canClose:n,onClose:r,onMenu:o,onRename:s,onSelect:d,tab:a}=l,i=oe(),[f,h]=te(!1),[p,x]=te(!1);let c;e[0]!==o||e[1]!==a.id?(c=F=>{o(a.id,F)},e[0]=o,e[1]=a.id,e[2]=c):c=e[2];const g=c;let v;e[3]!==d||e[4]!==a.id?(v=()=>{d(a.id)},e[3]=d,e[4]=a.id,e[5]=v):v=e[5];const y=v;let b;e[6]===Symbol.for("react.memo_cache_sentinel")?(b=()=>{h(!0)},e[6]=b):b=e[6];const m=b;let w;e[7]!==r||e[8]!==a?(w=F=>{F.stopPropagation(),Ve(a)?x(!0):r(a.id)},e[7]=r,e[8]=a,e[9]=w):w=e[9];const k=w;let S;e[10]!==r||e[11]!==a.id?(S=F=>{F.stopPropagation(),x(!1),r(a.id)},e[10]=r,e[11]=a.id,e[12]=S):S=e[12];const C=S;let q;e[13]===Symbol.for("react.memo_cache_sentinel")?(q=F=>{F.stopPropagation(),x(!1)},e[13]=q):q=e[13];const L=q;let R;e[14]!==s||e[15]!==a.id?(R=F=>{s(a.id,F),h(!1)},e[14]=s,e[15]=a.id,e[16]=R):R=e[16];const T=R;let I;e[17]===Symbol.for("react.memo_cache_sentinel")?(I=()=>{h(!1)},e[17]=I):I=e[17];const _=I;let O;e[18]!==a.name?(O=a.name.trim(),e[18]=a.name,e[19]=O):O=e[19];const $=O;let M;e[20]!==i||e[21]!==a.sql?(M=Un(a.sql,i("Untitled")),e[20]=i,e[21]=a.sql,e[22]=M):M=e[22];const E=M,D=t?"bg-background text-foreground":"bg-muted/40 text-muted-foreground hover:text-foreground";let N;e[23]!==D?(N=ue("group/tab flex shrink-0 items-center gap-1 border-e border-border ps-3 pe-1.5 text-xs",D),e[23]=D,e[24]=N):N=e[24];const z=`sql-tab-${a.id}`;let P;e[25]!==t||e[26]!==T||e[27]!==$||e[28]!==E||e[29]!==f||e[30]!==y||e[31]!==i||e[32]!==a.id?(P=f?u(Jn,{initial:$,onCancel:_,onCommit:T,placeholder:E,testId:`sql-tab-rename-${a.id}`}):u("button",{"aria-pressed":t,className:"max-w-40 truncate py-1.5 outline-none","data-testid":`sql-tab-select-${a.id}`,onClick:y,onDoubleClick:m,title:i("Double-click to rename"),type:"button",children:$===""?E:$}),e[25]=t,e[26]=T,e[27]=$,e[28]=E,e[29]=f,e[30]=y,e[31]=i,e[32]=a.id,e[33]=P):P=e[33];let Q;e[34]!==n||e[35]!==C||e[36]!==p||e[37]!==k||e[38]!==i||e[39]!==a.id?(Q=n&&(p?u(Gn,{idBase:a.id,onDiscard:C,onKeep:L}):u("button",{"aria-label":i("Close tab"),className:"flex size-5 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-destructive/10 hover:text-destructive","data-testid":`sql-tab-close-${a.id}`,onClick:k,title:i("Close tab"),type:"button",children:u("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,viewBox:"0 0 24 24",children:u("path",{d:"M6 6l12 12M18 6 6 18"})})})),e[34]=n,e[35]=C,e[36]=p,e[37]=k,e[38]=i,e[39]=a.id,e[40]=Q):Q=e[40];let j;return e[41]!==g||e[42]!==N||e[43]!==z||e[44]!==P||e[45]!==Q?(j=B("div",{className:N,"data-testid":z,onContextMenu:g,children:[P,Q]}),e[41]=g,e[42]=N,e[43]=z,e[44]=P,e[45]=Q,e[46]=j):j=e[46],j},Xn=l=>{const e=K(43),{model:t,onSelect:n}=l,r=oe(),{activeTab:o,addEditorTab:s,cancelBulk:d,closeEditorTab:a,closeTabMenu:i,confirmBulk:f,menuStyle:h,onBackdropContextMenu:p,onCloseAll:x,onCloseOthers:c,onCloseToRight:g,openTabMenu:v,pendingBulk:y,renameTab:b,tabMenu:m,tabs:w}=t;let k;if(e[0]!==o||e[1]!==a||e[2]!==n||e[3]!==v||e[4]!==b||e[5]!==w){let O;e[7]!==o||e[8]!==a||e[9]!==n||e[10]!==v||e[11]!==b||e[12]!==w.length?(O=$=>u(Vn,{active:$.id===o.id,canClose:w.length>1,onClose:a,onMenu:v,onRename:b,onSelect:n,tab:$},$.id),e[7]=o,e[8]=a,e[9]=n,e[10]=v,e[11]=b,e[12]=w.length,e[13]=O):O=e[13],k=w.map(O),e[0]=o,e[1]=a,e[2]=n,e[3]=v,e[4]=b,e[5]=w,e[6]=k}else k=e[6];let S;e[14]!==r?(S=r("New tab"),e[14]=r,e[15]=S):S=e[15];const C=w.length>=Ae;let q;e[16]!==r?(q=r("New tab"),e[16]=r,e[17]=q):q=e[17];let L;e[18]===Symbol.for("react.memo_cache_sentinel")?(L=u("svg",{"aria-hidden":"true",className:"size-4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.7,viewBox:"0 0 24 24",children:u("path",{d:"M12 5v14M5 12h14"})}),e[18]=L):L=e[18];let R;e[19]!==s||e[20]!==S||e[21]!==C||e[22]!==q?(R=u("button",{"aria-label":S,className:"flex size-8 shrink-0 items-center justify-center text-muted-foreground outline-none transition-colors hover:bg-accent hover:text-foreground focus-visible:bg-accent disabled:pointer-events-none disabled:opacity-40","data-testid":"sql-tab-add",disabled:C,onClick:s,title:q,type:"button",children:L}),e[19]=s,e[20]=S,e[21]=C,e[22]=q,e[23]=R):R=e[23];let T;e[24]!==k||e[25]!==R?(T=B("div",{className:"flex shrink-0 items-stretch overflow-x-auto border-b border-border bg-muted/30","data-testid":"sql-tab-strip",role:"tablist",children:[k,R]}),e[24]=k,e[25]=R,e[26]=T):T=e[26];let I;e[27]!==d||e[28]!==i||e[29]!==f||e[30]!==h||e[31]!==p||e[32]!==x||e[33]!==c||e[34]!==g||e[35]!==y||e[36]!==r||e[37]!==m||e[38]!==w?(I=m!==null&&B(Le,{children:[u("div",{className:"fixed inset-0 z-40","data-testid":"sql-tab-menu-backdrop",onClick:i,onContextMenu:p,role:"presentation"}),u("div",{className:"fixed z-50 min-w-44 rounded-md border border-border bg-popover py-1 text-popover-foreground shadow-md","data-testid":"sql-tab-menu",role:"menu",style:h,children:y===null?B(Le,{children:[u("button",{className:"flex w-full items-center px-3 py-1.5 text-start text-xs outline-none hover:bg-accent focus-visible:bg-accent disabled:pointer-events-none disabled:opacity-40","data-testid":"sql-tab-menu-close-others",disabled:w.length<=1,onClick:c,role:"menuitem",type:"button",children:r("Close other tabs")}),u("button",{className:"flex w-full items-center px-3 py-1.5 text-start text-xs outline-none hover:bg-accent focus-visible:bg-accent disabled:pointer-events-none disabled:opacity-40","data-testid":"sql-tab-menu-close-right",disabled:w.findIndex(O=>O.id===m.id)>=w.length-1,onClick:g,role:"menuitem",type:"button",children:r("Close tabs to the right")}),u("button",{className:"flex w-full items-center px-3 py-1.5 text-start text-xs outline-none hover:bg-accent focus-visible:bg-accent","data-testid":"sql-tab-menu-close-all",onClick:x,role:"menuitem",type:"button",children:r("Close all tabs")})]}):B("div",{className:"px-3 py-1.5","data-testid":"sql-tab-menu-confirm",children:[u("p",{className:"pb-1.5 text-xs text-muted-foreground",children:r("Discard unsaved tabs?")}),B("div",{className:"flex items-center gap-1.5",children:[u("button",{className:"rounded px-2 py-1 text-xs font-medium text-destructive outline-none hover:bg-destructive/10 focus-visible:bg-destructive/10","data-testid":"sql-tab-menu-confirm-discard",onClick:f,type:"button",children:r("Discard")}),u("button",{className:"rounded px-2 py-1 text-xs text-muted-foreground outline-none hover:bg-accent focus-visible:bg-accent","data-testid":"sql-tab-menu-confirm-cancel",onClick:d,type:"button",children:r("Cancel")})]})]})})]}),e[27]=d,e[28]=i,e[29]=f,e[30]=h,e[31]=p,e[32]=x,e[33]=c,e[34]=g,e[35]=y,e[36]=r,e[37]=m,e[38]=w,e[39]=I):I=e[39];let _;return e[40]!==T||e[41]!==I?(_=B(Le,{children:[T,I]}),e[40]=T,e[41]=I,e[42]=_):_=e[42],_},Zn=Te($e.runSql),eo="lunora-studio-sql-split-view",to=()=>ve(Ze[0]?.sql??""),So=l=>{const e=K(102),{initialShardKey:t}=l,n=Me(),r=Cn(to),{activeTab:o,output:s,patchActiveOutput:d,patchActiveTab:a,setActiveTabId:i,unlinkQuery:f}=r;let h;e[0]!==d||e[1]!==a?(h=(se,ce)=>{a({activeId:ce,sql:se}),d({chart:void 0,error:null,failed:void 0,result:null})},e[0]=d,e[1]=a,e[2]=h):h=e[2];const p=h;let x;e[3]!==p||e[4]!==f?(x={loadIntoActiveTab:p,unlinkQuery:f},e[3]=p,e[4]=f,e[5]=x):x=e[5];const c=En(x),{recordHistory:g,updateQuerySql:v}=c,y=o.sql,{activeId:b}=o,{chart:m,error:w,failed:k,result:S}=s,C=s.pane,[q,L]=te(t??""),[R,T]=te(!1),[I,_]=Ke(eo,!1),{probe:O,schema:$}=un(q);let M;e[6]!==b||e[7]!==a||e[8]!==v?(M=se=>{a({sql:se}),b!==null&&v(b,se)},e[6]=b,e[7]=a,e[8]=v,e[9]=M):M=e[9];const E=M,D=Yt(y,$,q),N=ot(q);let z;e[10]!==N||e[11]!==d||e[12]!==S?(z=()=>{S!==null&&de((async()=>{const se=await N.inferChart({columns:S.columns,rowCount:S.rowCount,types:Object.fromEntries(S.columns.map(ce=>[ce,typeof(S.rows[0]?.[ce]??"")]))});d({chart:se})})())},e[10]=N,e[11]=d,e[12]=S,e[13]=z):z=e[13];const P=z;let Q;e[14]!==n||e[15]!==y||e[16]!==d||e[17]!==g||e[18]!==q?(Q=async se=>{if(y.trim()==="")return;T(!0);const ce=se==="explain"?`EXPLAIN QUERY PLAN ${y}`:y;try{const Ee=await n.query(Zn,{sql:ce},ke(q));d({chart:void 0,error:null,failed:void 0,pane:se,result:Ee}),nt(q),g(ce)}catch(Ee){const Be=Ee;d({chart:void 0,error:He(Be),failed:{error:He(Be),sql:ce},pane:se,result:null})}T(!1)},e[14]=n,e[15]=y,e[16]=d,e[17]=g,e[18]=q,e[19]=Q):Q=e[19];const j=Q;let F;e[20]!==j?(F=()=>{de(j("results"))},e[20]=j,e[21]=F):F=e[21];const X=F;let U;e[22]!==s.pane||e[23]!==j?(U=()=>{de(j(s.pane))},e[22]=s.pane,e[23]=j,e[24]=U):U=e[24];let ne;e[25]!==O||e[26]!==$||e[27]!==E||e[28]!==U?(ne={onSubmit:U,probe:O,schema:$,setDraft:E},e[25]=O,e[26]=$,e[27]=E,e[28]=U,e[29]=ne):ne=e[29];const A=hn(ne),{closeAutocomplete:re}=A;let J;e[30]!==y||e[31]!==E?(J=()=>{E(wt(y))},e[30]=y,e[31]=E,e[32]=J):J=e[32];const Z=J;let G;e[33]!==re||e[34]!==i?(G=se=>{re(),i(se)},e[33]=re,e[34]=i,e[35]=G):G=e[35];const ee=G;let V;e[36]!==d?(V=()=>{d({pane:"results"})},e[36]=d,e[37]=V):V=e[37];const le=V;let ie;e[38]!==j?(ie=()=>{de(j("explain"))},e[38]=j,e[39]=ie):ie=e[39];const H=ie;let W;e[40]!==d?(W=()=>{d({pane:"chart"})},e[40]=d,e[41]=W):W=e[41];const Y=W;let ae;e[42]!==_||e[43]!==I?(ae=()=>{_(!I)},e[42]=_,e[43]=I,e[44]=ae):ae=e[44];const xe=ae,Re=I?"flex min-h-0 flex-1 flex-row":"flex min-h-0 flex-1 flex-col",Ie=I?"flex w-2/5 min-h-0 min-w-0 shrink-0 flex-col border-s border-border":"flex h-2/5 min-h-0 shrink-0 flex-col border-t border-border";let me;e[45]!==b||e[46]!==c.clearHistory||e[47]!==c.deleteQuery||e[48]!==c.history||e[49]!==c.listRef||e[50]!==c.loadFromHistory||e[51]!==c.loadTemplate||e[52]!==c.newQuery||e[53]!==c.onSearchChange||e[54]!==c.queries||e[55]!==c.search||e[56]!==c.selectQuery?(me=u(Qn,{activeId:b,history:c.history,listRef:c.listRef,onClearHistory:c.clearHistory,onDelete:c.deleteQuery,onLoadHistory:c.loadFromHistory,onLoadTemplate:c.loadTemplate,onNew:c.newQuery,onSearchChange:c.onSearchChange,onSelect:c.selectQuery,queries:c.queries,search:c.search}),e[45]=b,e[46]=c.clearHistory,e[47]=c.deleteQuery,e[48]=c.history,e[49]=c.listRef,e[50]=c.loadFromHistory,e[51]=c.loadTemplate,e[52]=c.newQuery,e[53]=c.onSearchChange,e[54]=c.queries,e[55]=c.search,e[56]=c.selectQuery,e[57]=me):me=e[57];let fe;e[58]!==r||e[59]!==ee?(fe=u(Xn,{model:r,onSelect:ee}),e[58]=r,e[59]=ee,e[60]=fe):fe=e[60];let he;e[61]!==N||e[62]!==D||e[63]!==y||e[64]!==k||e[65]!==E||e[66]!==A.autocompleteState||e[67]!==A.editorRef||e[68]!==A.gutterRef||e[69]!==A.handlers||e[70]!==A.listboxId||e[71]!==A.onPickSuggestion||e[72]!==A.overlayRef||e[73]!==A.revealDiagnostic?(he=u(zn,{assistant:N,autocomplete:A.autocompleteState,diagnostics:D,draft:y,editorRef:A.editorRef,failed:k,gutterRef:A.gutterRef,handlers:A.handlers,listboxId:A.listboxId,onGenerated:E,onPickSuggestion:A.onPickSuggestion,onRevealDiagnostic:A.revealDiagnostic,overlayRef:A.overlayRef}),e[61]=N,e[62]=D,e[63]=y,e[64]=k,e[65]=E,e[66]=A.autocompleteState,e[67]=A.editorRef,e[68]=A.gutterRef,e[69]=A.handlers,e[70]=A.listboxId,e[71]=A.onPickSuggestion,e[72]=A.overlayRef,e[73]=A.revealDiagnostic,e[74]=he):he=e[74];let pe;e[75]!==N||e[76]!==w||e[77]!==Z||e[78]!==P||e[79]!==m||e[80]!==X||e[81]!==S||e[82]!==Ie||e[83]!==R||e[84]!==q||e[85]!==Y||e[86]!==H||e[87]!==le||e[88]!==I||e[89]!==C||e[90]!==xe?(pe=u(Kn,{assistant:N,chart:m,className:Ie,error:w,onFormat:Z,onInferChart:P,onRun:X,onShardKeyChange:L,onShowChart:Y,onShowExplain:H,onShowResults:le,onToggleSplit:xe,pane:C,result:S,running:R,shardKey:q,splitView:I}),e[75]=N,e[76]=w,e[77]=Z,e[78]=P,e[79]=m,e[80]=X,e[81]=S,e[82]=Ie,e[83]=R,e[84]=q,e[85]=Y,e[86]=H,e[87]=le,e[88]=I,e[89]=C,e[90]=xe,e[91]=pe):pe=e[91];let be;e[92]!==he||e[93]!==pe||e[94]!==Re?(be=B("div",{className:Re,children:[he,pe]}),e[92]=he,e[93]=pe,e[94]=Re,e[95]=be):be=e[95];let ge;e[96]!==fe||e[97]!==be?(ge=B("div",{className:"flex min-w-0 flex-1 flex-col",children:[fe,be]}),e[96]=fe,e[97]=be,e[98]=ge):ge=e[98];let we;return e[99]!==me||e[100]!==ge?(we=B("div",{className:"flex h-full min-w-0","data-testid":"lunora-sql-editor",children:[me,ge]}),e[99]=me,e[100]=ge,e[101]=we):we=e[101],we};export{So as SqlEditorPanel};
|
|
1
|
+
import{c as K}from"react/compiler-runtime";import{useLunora as Oe}from"@lunora/react";import{useState as re,useMemo as Be,useCallback as Ze,useEffect as qe,useRef as ye,useId as et}from"react";import{ADMIN_FUNCTIONS as $e}from"../packem_shared/ADMIN_FUNCTIONS-4aE59aDq.js";import{u as _e,n as je,b as We}from"../packem_shared/browser-storage-xjTyMKY0.js";import{d as ke,f as de,g as Te,b as ze}from"../packem_shared/internal-BSIsQVC6.js";import{r as tt}from"../packem_shared/shard-history-DMEW5VBE.js";import{k as nt}from"../packem_shared/use-sql-assistant-C6dl2_Ty.js";import ot from"../packem_shared/useDebounced-CU-uftxO.js";import{useT as le}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{c as ue}from"../packem_shared/utils-bhneXptQ.js";import{jsx as u,jsxs as A,Fragment as Ee}from"react/jsx-runtime";import{u as rt}from"../packem_shared/input-JHu63lTv.js";import{I as lt}from"../packem_shared/result-chart-DzJOVsaw.js";import{ShardInput as st}from"../packem_shared/ShardInput-BVn2iCU0.js";import{A as at}from"../packem_shared/alert-CVcOFuDR.js";import{K as it}from"../packem_shared/grid-features-jnrD0SpX.js";import{d as ct,m as He,f as dt,n as ut,p as mt,u as ft}from"../packem_shared/table-DdJBrClo.js";import{g as ht}from"../packem_shared/data-grid-DcxyIXwG.js";const pt=["ORDER BY","GROUP BY","LEFT JOIN","RIGHT JOIN","INNER JOIN","OUTER JOIN","CROSS JOIN","EXPLAIN QUERY PLAN","SELECT","DISTINCT","FROM","WHERE","HAVING","LIMIT","OFFSET","JOIN","ON","AND","OR","AS","ASC","DESC","WITH","UNION","EXPLAIN"],bt=["FROM","WHERE","ORDER BY","GROUP BY","HAVING","LIMIT","OFFSET","UNION","JOIN","LEFT JOIN","RIGHT JOIN","INNER JOIN","OUTER JOIN","CROSS JOIN"],Ce=String.fromCodePoint(0),gt=new RegExp(`${Ce}${String.raw`(\d+)`}${Ce}`,"gu"),xt=pt.map(l=>({pattern:new RegExp(String.raw`\b${l.replaceAll(" ",String.raw`\s+`)}\b`,"giu"),replacement:l})),vt=bt.map(l=>({pattern:new RegExp(String.raw`\s+${l.replaceAll(" ",String.raw`\s+`)}\b`,"gu"),replacement:`
|
|
2
|
+
${l}`})),yt=l=>{const e=[];let t=l.replaceAll(/'(?:[^']|'')*'/gu,n=>(e.push(n),`${Ce}${(e.length-1).toString()}${Ce}`)).replaceAll(/\s+/gu," ").trim();for(const{pattern:n,replacement:r}of xt)t=t.replaceAll(n,r);for(const{pattern:n,replacement:r}of vt)t=t.replaceAll(n,r);return t=t.replaceAll(gt,(n,r)=>e[Number(r)]??""),t},wt=/^(?:explain\s+(?:query\s+plan\s+)?)?(?:select|with)\b/iu,St=/\b(?:alter|attach|create|delete|detach|drop|insert|pragma|reindex|replace|truncate|update|vacuum)\b/iu,Nt=/^\w+/u,kt=/;\s*$/u,Ct=/\s/u,qt=(l,e)=>{let t=e+2;for(;t<l.length&&l[t]!==`
|
|
3
|
+
`;)t+=1;return t},$t=(l,e)=>{const t=l.indexOf("*/",e+2);return t===-1?-1:t+2},Tt=l=>{let e=0;for(;e<l.length;){const t=l[e];if(t!==void 0&&Ct.test(t))e+=1;else if(t==="-"&&l[e+1]==="-")e=qt(l,e);else if(t==="/"&&l[e+1]==="*"){const n=$t(l,e);if(n===-1)break;e=n}else break}return e},Rt=l=>{const e=Tt(l),t=l.slice(e).trimEnd();if(t==="")return{code:"SQL_EMPTY",message:"the query is empty"};const n=t.replace(kt,""),r=n.indexOf(";");if(r!==-1)return{code:"SQL_MULTIPLE_STATEMENTS",length:1,message:"only a single statement may be run",offset:e+r};const o="the SQL editor is read-only — only SELECT / WITH / EXPLAIN queries are allowed";if(!wt.test(n))return{code:"SQL_NOT_READONLY",length:Nt.exec(n)?.[0].length??1,message:o,offset:e};const s=St.exec(n);if(s!==null)return{code:"SQL_NOT_READONLY",length:s[0].length,message:`${o} (\`${s[0].toUpperCase()}\` is not allowed)`,offset:e+s.index}},It=/\b(?:from|join)\s+([a-z_][\w$]*)(?:\s+(?:as\s+)?([a-z_][\w$]*))?/giu,Et=/(?:\bwith\s+(?:recursive\s+)?|,\s*)([a-z_][\w$]*)\s+as\s*\(/giu,Lt=new Set(["cross","full","group","having","inner","join","left","limit","offset","on","order","right","union","using","where","window"]),_t=/[^\n]/gu,Ot=(l,e)=>{const t=l[e];if(t==="'"){let n=e+1;for(;n<l.length&&l[n]!=="'";)n+=1;return Math.min(n+1,l.length)}if(t==="-"&&l[e+1]==="-"){const n=l.indexOf(`
|
|
4
|
+
`,e);return n===-1?l.length:n}if(t==="/"&&l[e+1]==="*"){const n=l.indexOf("*/",e+2);return n===-1?l.length:n+2}return-1},Mt=l=>{let e="",t=0;for(;t<l.length;){const n=Ot(l,t);n===-1?(e+=l.slice(t,t+1),t+=1):(e+=l.slice(t,n).replaceAll(_t," "),t=n)}return e},Dt=l=>{const e=new Set;for(const t of l.matchAll(Et))e.add((t[1]??"").toLowerCase());return e},At=(l,e)=>{const t=new Map;for(const n of l.matchAll(It)){const r=(n[1]??"").toLowerCase(),o=(n[2]??"").toLowerCase();e.has(r)&&(t.set(r,r),o!==""&&!Lt.has(o)&&t.set(o,r))}return t},Ke=(l,e)=>{const t=Mt(l),n=new Set(e.map(r=>r.toLowerCase()));return{ctes:Dt(t),masked:t,targets:At(t,n)}},Bt=/^(?:__lunora|sqlite_)/iu,zt=/\b(?:from|join)\s+([a-z_][\w$]*)/giu,Ht=/\b([a-z_][\w$]*)\.([a-z_][\w$]*)/giu,Pt=new Set(["cross","full","group","having","inner","join","lateral","left","limit","offset","order","right","select","union","where","window"]),Ft=(l,e,t)=>{const n=[];for(const r of l.matchAll(zt)){const o=r[1]??"",s=o.toLowerCase();!e.has(s)&&!t.has(s)&&!Pt.has(s)&&!Bt.test(o)&&n.push({length:o.length,message:`unknown table \`${o}\``,offset:r.index+r[0].length-o.length,severity:"error",source:"schema"})}return n},Qt=(l,e,t)=>{const n=[],r=new Map;for(const[o,s]of Object.entries(e.columns))r.set(o.toLowerCase(),new Set(s.map(d=>d.toLowerCase())));for(const o of l.matchAll(Ht)){const s=(o[1]??"").toLowerCase(),d=o[2]??"",a=t.get(s),i=a===void 0?void 0:r.get(a);i!==void 0&&!i.has(d.toLowerCase())&&n.push({length:d.length,message:`\`${a??""}\` has no column \`${d}\``,offset:o.index+o[0].length-d.length,severity:"error",source:"schema"})}return n},jt=(l,e)=>{if(l.trim()==="")return[];const t=Rt(l);if(t!==void 0)return t.code==="SQL_EMPTY"?[]:[{length:t.length,message:t.message,offset:t.offset,severity:"error",source:"gate"}];const{ctes:n,masked:r,targets:o}=Ke(l,e.tables),s=new Set(e.tables.map(d=>d.toLowerCase()));return[...Ft(r,s,n),...Qt(r,e,o)]},Wt=Te($e.lintSql),Kt=600,Ut=(l,e,t)=>{const n=Oe(),[r,o]=re([]),s=Be(()=>jt(l,e),[l,e]),d=ot(l,Kt),a=s.some(h=>h.source==="gate")||d.trim()==="",i=Ze(async h=>{try{const p=await n.query(Wt,{sql:d},ke(t));h.cancelled||o(p.diagnostics??[])}catch{h.cancelled||o([])}},[n,d,t]);qe(()=>{if(a){o([]);return}const h={cancelled:!1};return de(i(h)),()=>{h.cancelled=!0}},[i,a]);const f=d===l;return Be(()=>f?[...s,...r]:s,[s,r,f])},Se=8,Yt=["AND","ASC","AS","BY","COUNT","DESC","DISTINCT","EXPLAIN","FROM","GROUP","HAVING","INNER","JOIN","LEFT","LIKE","LIMIT","NOT","NULL","OFFSET","ON","ORDER","OR","QUERY","SELECT","WHERE","WITH"],Jt=new Set(["AND","BY","HAVING","ON","OR","SELECT","WHERE"]),Gt=/[\w$]/,Ue=l=>l!==void 0&&Gt.test(l),Ye=l=>{let e=l.length;for(;e>0&&Ue(l[e-1]);)e-=1;return l.slice(e)},Je=(l,e)=>{let t=e;for(;t>0&&Ue(l[t-1]);)t-=1;return{end:e,start:t,text:l.slice(t,e)}},Pe=(l,e)=>{const t=l.slice(0,e).trimEnd();return t.endsWith(".")||Jt.has(Ye(t).toUpperCase())},Vt=(l,e,t)=>{const n=l.slice(0,e);if(!n.endsWith("."))return;const r=Ye(n.slice(0,-1));if(r!=="")return Ke(l,t).targets.get(r.toLowerCase())??r},Me=(l,e)=>l.toLowerCase().startsWith(e.toLowerCase()),Fe=(l,e,t,n)=>{const r=[];for(const o of l)if(Me(o,e)&&(r.push(n(o)),r.length>=t))break;return r},Xt=(l,e,t)=>{const n=new Map;for(const[r,o]of Object.entries(l.columns))for(const s of o)if(Me(s,e)&&!n.has(s)&&(n.set(s,r),n.size>=t))return[...n].map(([d,a])=>({detail:a,kind:"column",label:d}));return[...n].map(([r,o])=>({detail:o,kind:"column",label:r}))},Zt=(l,e,t)=>{const n=Je(l,e),r=Vt(l,n.start,t.tables);if(r!==void 0){const a=t.columns[r]??t.columns[r.toLowerCase()]??[];return Fe(a,n.text,Se,i=>({detail:r,kind:"column",label:i}))}if(n.text===""&&!Pe(l,n.start))return[];const o=Fe(t.tables,n.text,Se,a=>({kind:"table",label:a})),s=Xt(t,n.text,Se),d=Yt.flatMap(a=>n.text!==""&&Me(a,n.text)&&a.toLowerCase()!==n.text.toLowerCase()?[{kind:"keyword",label:a}]:[]);return(Pe(l,n.start)?[...s,...o,...d]:[...o,...s,...d]).slice(0,Se)},en=(l,e,t)=>{const n=Je(l,e),r=l.slice(0,n.start)+t.label+l.slice(n.end);return{caret:n.start+t.label.length,value:r}},tn=["boxSizing","borderBottomWidth","borderLeftWidth","borderRightWidth","borderTopWidth","fontFamily","fontSize","fontStyle","fontWeight","letterSpacing","lineHeight","paddingBottom","paddingLeft","paddingRight","paddingTop","tabSize","textIndent","textTransform","width","wordSpacing"],nn=(l,e)=>{const t=globalThis.getComputedStyle(l),n=globalThis.document.createElement("div"),{style:r}=n;r.position="absolute",r.visibility="hidden",r.whiteSpace="pre-wrap",r.overflowWrap="break-word";for(const a of tn)r[a]=t[a];n.textContent=l.value.slice(0,Math.max(0,e));const o=globalThis.document.createElement("span");o.textContent=l.value.slice(Math.max(0,e))||".",n.append(o),globalThis.document.body.append(n);const s=o.offsetLeft-l.scrollLeft,d=o.offsetTop-l.scrollTop;return n.remove(),{left:s,top:d}},on=(l,e,t)=>{const n=K(16),[r,o]=re(null);let s;n[0]!==l||n[1]!==e?(s=(y,b)=>{const m=Zt(y,b,l);if(m.length===0){o(null);return}const w=e.current,{left:N,top:S}=w===null?{left:0,top:0}:nn(w,b);o(k=>k!==null&&k.active===0&&k.left===N&&k.top===S&&k.suggestions.length===m.length&&k.suggestions.every((R,T)=>{const I=m.at(T);return R.kind===I?.kind&&R.label===I.label&&R.detail===I.detail})?k:{active:0,left:N,suggestions:m,top:S})},n[0]=l,n[1]=e,n[2]=s):s=n[2];const d=s;let a;n[3]===Symbol.for("react.memo_cache_sentinel")?(a=()=>{o(null)},n[3]=a):a=n[3];const i=a;let f;n[4]===Symbol.for("react.memo_cache_sentinel")?(f=y=>{o(b=>{if(b===null)return b;const m=b.suggestions.length,w=(b.active+y+m)%m;return{...b,active:w}})},n[4]=f):f=n[4];const h=f;let p;n[5]!==t||n[6]!==r||n[7]!==e?(p=y=>{const b=e.current;if(r===null||b===null)return!1;const m=r.suggestions[y??r.active];if(m===void 0)return!1;const w=en(b.value,b.selectionStart,m);return t(w.value),o(null),requestAnimationFrame(()=>{const N=e.current;N!==null&&(N.focus(),N.setSelectionRange(w.caret,w.caret))}),!0},n[5]=t,n[6]=r,n[7]=e,n[8]=p):p=n[8];const x=p;let c;n[9]!==x?(c=()=>x(),n[9]=x,n[10]=c):c=n[10];const g=c;let v;return n[11]!==g||n[12]!==x||n[13]!==d||n[14]!==r?(v={close:i,commit:g,commitAt:x,move:h,refresh:d,state:r},n[11]=g,n[12]=x,n[13]=d,n[14]=r,n[15]=v):v=n[15],v},rn={column:"column",keyword:"keyword",table:"table"},ln=20,sn=l=>{const e=K(17),{listboxId:t,onPick:n,state:r}=l,o=le();let s;e[0]!==r?(s=r===null?void 0:{left:r.left,top:r.top+ln},e[0]=r,e[1]=s):s=e[1];const d=s;if(r===null)return null;let a;if(e[2]!==t||e[3]!==n||e[4]!==r.active||e[5]!==r.suggestions||e[6]!==o){let f;e[8]!==t||e[9]!==n||e[10]!==r.active||e[11]!==o?(f=(h,p)=>A("li",{"aria-selected":p===r.active,className:ue("flex cursor-pointer items-center gap-2 px-2 py-1 text-[13px]",p===r.active?"bg-accent text-accent-foreground":"text-foreground"),"data-testid":"sql-autocomplete-item",id:`${t}-opt-${p.toString()}`,onMouseDown:x=>{x.preventDefault(),n(p)},role:"option",children:[u("span",{className:"truncate font-mono",children:h.label}),h.detail!==void 0&&u("span",{className:"ms-auto truncate text-xs text-muted-foreground",children:h.detail}),u("span",{className:"shrink-0 font-mono text-[10px] tracking-wide text-muted-foreground/70 uppercase",children:o(rn[h.kind])})]},`${h.kind}:${h.label}`),e[8]=t,e[9]=n,e[10]=r.active,e[11]=o,e[12]=f):f=e[12],a=r.suggestions.map(f),e[2]=t,e[3]=n,e[4]=r.active,e[5]=r.suggestions,e[6]=o,e[7]=a}else a=e[7];let i;return e[13]!==t||e[14]!==d||e[15]!==a?(i=u("ul",{className:"absolute z-30 max-h-56 w-72 overflow-auto rounded-md border border-border bg-popover py-1 text-popover-foreground shadow-md","data-testid":"sql-autocomplete",id:t,role:"listbox",style:d,children:a}),e[13]=t,e[14]=d,e[15]=a,e[16]=i):i=e[16],i},an=Te($e.listTables),cn=Te($e.readTablePage),dn=l=>{const e=K(16),t=Oe();let n;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=[],e[0]=n):n=e[0];const[r,o]=re(n);let s;e[1]===Symbol.for("react.memo_cache_sentinel")?(s={},e[1]=s):s=e[1];const[d,a]=re(s);let i;e[2]===Symbol.for("react.memo_cache_sentinel")?(i=new Set,e[2]=i):i=e[2];const f=ye(i);let h,p;e[3]!==t||e[4]!==l?(h=()=>{const b={cancelled:!1};return de((async()=>{try{const m=await t.query(an,{},ke(l));b.cancelled||(o(m.map(mn)),a({}),f.current=new Set)}catch{b.cancelled||(o([]),a({}),f.current=new Set)}})()),()=>{b.cancelled=!0}},p=[t,l],e[3]=t,e[4]=l,e[5]=h,e[6]=p):(h=e[5],p=e[6]),qe(h,p);let x;e[7]!==t||e[8]!==l?(x=b=>{f.current.has(b)||(f.current.add(b),de((async()=>{try{const m=await t.query(cn,{limit:1,offset:0,table:b},ke(l));a(w=>({...w,[b]:m.columns}))}catch{f.current.delete(b)}})()))},e[7]=t,e[8]=l,e[9]=x):x=e[9];const c=x;let g;e[10]!==d||e[11]!==r?(g={columns:d,tables:r},e[10]=d,e[11]=r,e[12]=g):g=e[12];const v=g;let y;return e[13]!==c||e[14]!==v?(y={probe:c,schema:v},e[13]=c,e[14]=v,e[15]=y):y=e[15],y},Le=/\b(?:from|join|update|into)\s+([a-z_][\w$]*)|\b([a-z_][\w$]*)\s*\./gi,un=l=>{const e=new Set;Le.lastIndex=0;let t=Le.exec(l);for(;t!==null;)e.add(t[1]??t[2]),t=Le.exec(l);return[...e]};function mn(l){return l.name}const fn=l=>{const e=K(34),{onSubmit:t,probe:n,schema:r,setDraft:o}=l,s=et(),d=ye(null),a=ye(null),i=ye(null),f=on(r,i,o),{close:h,commit:p,commitAt:x,move:c,refresh:g,state:v}=f;let y;e[0]!==x?(y=$=>{x($)},e[0]=x,e[1]=y):y=e[1];const b=y;let m;e[2]!==g?(m=()=>{const $=i.current;$!==null&&$===document.activeElement&&g($.value,$.selectionStart)},e[2]=g,e[3]=m):m=e[3];let w;e[4]!==g||e[5]!==r?(w=[g,r],e[4]=g,e[5]=r,e[6]=w):w=e[6],qe(m,w);let N;e[7]!==n||e[8]!==g||e[9]!==o?(N=$=>{const{selectionStart:B,value:F}=$.target;o(F);for(const P of un(F))n(P);g(F,B)},e[7]=n,e[8]=g,e[9]=o,e[10]=N):N=e[10];const S=N;let k;e[11]!==g?(k=$=>{const B=$.currentTarget;g(B.value,B.selectionStart)},e[11]=g,e[12]=k):k=e[12];const R=k;let T;e[13]!==v||e[14]!==h||e[15]!==p||e[16]!==c||e[17]!==t?(T=$=>{if(v!==null){if($.key==="ArrowDown"){$.preventDefault(),c(1);return}if($.key==="ArrowUp"){$.preventDefault(),c(-1);return}if($.key==="Escape"){$.preventDefault(),h();return}if(($.key==="Enter"||$.key==="Tab")&&!$.metaKey&&!$.ctrlKey&&p()){$.preventDefault();return}}($.metaKey||$.ctrlKey)&&$.key==="Enter"&&($.preventDefault(),t())},e[13]=v,e[14]=h,e[15]=p,e[16]=c,e[17]=t,e[18]=T):T=e[18];const I=T;let C;e[19]!==h?(C=()=>{requestAnimationFrame(()=>{h()})},e[19]=h,e[20]=C):C=e[20];const L=C;let _;e[21]===Symbol.for("react.memo_cache_sentinel")?(_=$=>{const{scrollLeft:B,scrollTop:F}=$.currentTarget;d.current!==null&&(d.current.scrollTop=F),a.current!==null&&(a.current.scrollTop=F,a.current.scrollLeft=B)},e[21]=_):_=e[21];const O=_;let q;e[22]===Symbol.for("react.memo_cache_sentinel")?(q=$=>{const B=i.current;B===null||$.offset===void 0||(B.focus(),B.setSelectionRange($.offset,$.offset+($.length??0)))},e[22]=q):q=e[22];const E=q;let M;e[23]!==S||e[24]!==L||e[25]!==I||e[26]!==R?(M={onBlur:L,onChange:S,onKeyDown:I,onScroll:O,onSelect:R},e[23]=S,e[24]=L,e[25]=I,e[26]=R,e[27]=M):M=e[27];let D;return e[28]!==v||e[29]!==h||e[30]!==s||e[31]!==b||e[32]!==M?(D={autocompleteState:v,closeAutocomplete:h,handlers:M,listboxId:s,onPickSuggestion:b,editorRef:i,gutterRef:d,overlayRef:a,revealDiagnostic:E},e[28]=v,e[29]=h,e[30]=s,e[31]=b,e[32]=M,e[33]=D):D=e[33],D},hn="lunora-studio-sql-tabs",pn="lunora-studio-sql-active-tab",De=12,ve=(l="",e="")=>({activeId:null,id:je("tab"),name:e,sql:l}),bn=()=>We(pn,""),gn=l=>{const e=K(16),[t,n]=_e(hn),[r,o]=bn(),[s]=re(l);let d,a;e[0]!==s||e[1]!==n||e[2]!==t.length?(d=()=>{t.length===0&&n([s])},a=[s,n,t.length],e[0]=s,e[1]=n,e[2]=t.length,e[3]=d,e[4]=a):(d=e[3],a=e[4]),qe(d,a);let i;e[5]!==s||e[6]!==t?(i=t.length===0?[s]:t,e[5]=s,e[6]=t,e[7]=i):i=e[7];const f=i;let h;e[8]!==r||e[9]!==f?(h=f.some(c=>c.id===r)?r:f[0]?.id??"",e[8]=r,e[9]=f,e[10]=h):h=e[10];const p=h;let x;return e[11]!==p||e[12]!==o||e[13]!==n||e[14]!==f?(x={activeId:p,setActiveId:o,setTabs:n,tabs:f},e[11]=p,e[12]=o,e[13]=n,e[14]=f,e[15]=x):x=e[15],x},Ge=l=>l.activeId===null&&l.sql.trim()!=="",xn=(l,e)=>[...l,e].slice(-De),vn=(l,e,t)=>{const n=l.findIndex(o=>o.id===e);if(n===-1)return{activeId:l[0]?.id??"",tabs:[...l]};const r=l.filter(o=>o.id!==e);if(r.length===0){const o=t();return{activeId:o.id,tabs:[o]}}return{activeId:r[Math.min(n,r.length-1)].id,tabs:r}},yn=(l,e)=>{const t=l.filter(n=>n.id===e);return t.length===0?{activeId:l[0]?.id??"",tabs:[...l]}:{activeId:e,tabs:t}},wn=(l,e,t)=>{const n=l.findIndex(o=>o.id===e);if(n===-1)return{activeId:t,tabs:[...l]};const r=l.slice(0,n+1);return{activeId:r.some(o=>o.id===t)?t:e,tabs:r}},Sn=l=>{const e=l();return{activeId:e.id,tabs:[e]}},Nn=(l,e,t)=>{if(l==="others")return e.filter(n=>n.id!==t);if(l==="right"){const n=e.findIndex(r=>r.id===t);return n===-1?[]:e.slice(n+1)}return[...e]},Qe={error:null,pane:"results",result:null,running:!1},kn=l=>{const e=K(66),{activeId:t,setActiveId:n,setTabs:r,tabs:o}=gn(l);let s;e[0]===Symbol.for("react.memo_cache_sentinel")?(s={},e[0]=s):s=e[0];const[d,a]=re(s),[i,f]=re(null),[h,p]=re(null);let x;e[1]!==t||e[2]!==o?(x=o.find(H=>H.id===t)??o[0]??ve(),e[1]=t,e[2]=o,e[3]=x):x=e[3];const c=x,g=d[c.id]??Qe;let v;e[4]!==c.id||e[5]!==r?(v=H=>{r(j=>j.map(U=>U.id===c.id?{...U,...H}:U))},e[4]=c.id,e[5]=r,e[6]=v):v=e[6];const y=v;let b;e[7]!==c.id?(b=H=>{a(j=>{const U=j[c.id]??Qe;return{...j,[c.id]:{...U,...H}}})},e[7]=c.id,e[8]=b):b=e[8];const m=b;let w;e[9]!==n||e[10]!==r||e[11]!==o.length?(w=()=>{if(o.length>=De)return;const H=ve();r(j=>xn(j,H)),n(H.id)},e[9]=n,e[10]=r,e[11]=o.length,e[12]=w):w=e[12];const N=w;let S;e[13]!==n||e[14]!==r?(S=H=>{f(null),p(null),r(H.tabs),n(H.activeId);const j=new Set(H.tabs.map(Cn));a(U=>Object.fromEntries(Object.entries(U).filter(ae=>{const[xe]=ae;return j.has(xe)})))},e[13]=n,e[14]=r,e[15]=S):S=e[15];const k=S;let R;e[16]!==k||e[17]!==o?(R=H=>{k(vn(o,H,ve))},e[16]=k,e[17]=o,e[18]=R):R=e[18];const T=R;let I;e[19]!==t||e[20]!==k||e[21]!==o?(I=(H,j)=>{k(H==="others"?yn(o,j):H==="right"?wn(o,j,t):Sn(ve))},e[19]=t,e[20]=k,e[21]=o,e[22]=I):I=e[22];const C=I;let L;e[23]!==C||e[24]!==i||e[25]!==o?(L=H=>{i!==null&&(Nn(H,o,i.id).some(qn)?p(H):C(H,i.id))},e[23]=C,e[24]=i,e[25]=o,e[26]=L):L=e[26];const _=L;let O;e[27]===Symbol.for("react.memo_cache_sentinel")?(O=(H,j)=>{j.preventDefault(),p(null),f({id:H,x:j.clientX,y:j.clientY})},e[27]=O):O=e[27];const q=O;let E;e[28]===Symbol.for("react.memo_cache_sentinel")?(E=()=>{f(null),p(null)},e[28]=E):E=e[28];const M=E;let D;e[29]===Symbol.for("react.memo_cache_sentinel")?(D=H=>{H.preventDefault(),f(null),p(null)},e[29]=D):D=e[29];const $=D;let B;e[30]!==_?(B=()=>{_("others")},e[30]=_,e[31]=B):B=e[31];const F=B;let P;e[32]!==_?(P=()=>{_("right")},e[32]=_,e[33]=P):P=e[33];const W=P;let Q;e[34]!==_?(Q=()=>{_("all")},e[34]=_,e[35]=Q):Q=e[35];const Y=Q;let J;e[36]!==C||e[37]!==h||e[38]!==i?(J=()=>{i!==null&&h!==null&&C(h,i.id),p(null)},e[36]=C,e[37]=h,e[38]=i,e[39]=J):J=e[39];const z=J;let G;e[40]===Symbol.for("react.memo_cache_sentinel")?(G=()=>{p(null)},e[40]=G):G=e[40];const ne=G;let V;e[41]!==i?(V=i===null?void 0:{left:i.x,top:i.y},e[41]=i,e[42]=V):V=e[42];const X=V;let Z;e[43]!==r?(Z=H=>{r(j=>j.map(U=>U.activeId===H?{...U,activeId:null}:U))},e[43]=r,e[44]=Z):Z=e[44];const ee=Z;let te;e[45]!==r?(te=(H,j)=>{r(U=>U.map(ae=>ae.id===H?{...ae,name:j}:ae))},e[45]=r,e[46]=te):te=e[46];const oe=te;let ie;return e[47]!==c||e[48]!==t||e[49]!==N||e[50]!==T||e[51]!==z||e[52]!==Y||e[53]!==F||e[54]!==W||e[55]!==g||e[56]!==m||e[57]!==y||e[58]!==h||e[59]!==oe||e[60]!==n||e[61]!==i||e[62]!==X||e[63]!==o||e[64]!==ee?(ie={activeTab:c,activeTabId:t,addEditorTab:N,cancelBulk:ne,closeEditorTab:T,closeTabMenu:M,confirmBulk:z,menuStyle:X,onBackdropContextMenu:$,onCloseAll:Y,onCloseOthers:F,onCloseToRight:W,openTabMenu:q,output:g,patchActiveOutput:m,patchActiveTab:y,pendingBulk:h,renameTab:oe,setActiveTabId:n,tabMenu:i,tabs:o,unlinkQuery:ee},e[47]=c,e[48]=t,e[49]=N,e[50]=T,e[51]=z,e[52]=Y,e[53]=F,e[54]=W,e[55]=g,e[56]=m,e[57]=y,e[58]=h,e[59]=oe,e[60]=n,e[61]=i,e[62]=X,e[63]=o,e[64]=ee,e[65]=ie):ie=e[65],ie};function Cn(l){return l.id}function qn(l){return Ge(l)}const $n="lunora-studio-sql-queries",Tn="lunora-studio-sql-history",Rn=25,In=l=>{const e=K(33),{loadIntoActiveTab:t,unlinkQuery:n}=l,r=le(),[o,s]=_e($n),[d,a]=_e(Tn),[i,f]=re(""),h=ye(null);let p;e[0]!==a?(p=q=>{a(E=>E[0]?.sql===q?E:[{at:Date.now(),sql:q},...E.filter(M=>M.sql!==q)].slice(0,Rn))},e[0]=a,e[1]=p):p=e[1];const x=p;let c;e[2]!==t||e[3]!==s||e[4]!==r?(c=()=>{const q={id:je("q"),name:r("Untitled query"),sql:""};s(E=>[q,...E]),t("",q.id)},e[2]=t,e[3]=s,e[4]=r,e[5]=c):c=e[5];const g=c;let v;e[6]!==t||e[7]!==o?(v=q=>{const E=o.find(M=>M.id===q);E!==void 0&&(t(E.sql,q),h.current?.querySelector(`[data-testid="sql-query-${q}"]`)?.scrollIntoView({block:"nearest"}))},e[6]=t,e[7]=o,e[8]=v):v=e[8];const y=v;let b;e[9]!==s||e[10]!==n?(b=q=>{s(E=>E.filter(M=>M.id!==q)),n(q)},e[9]=s,e[10]=n,e[11]=b):b=e[11];const m=b;let w;e[12]!==t?(w=q=>{t(q.currentTarget.dataset.sql??"",null)},e[12]=t,e[13]=w):w=e[13];const N=w;let S;e[14]!==t?(S=q=>{t(q.currentTarget.dataset.sql??"",null)},e[14]=t,e[15]=S):S=e[15];const k=S;let R;e[16]!==a?(R=()=>{a([])},e[16]=a,e[17]=R):R=e[17];const T=R;let I;e[18]===Symbol.for("react.memo_cache_sentinel")?(I=q=>{f(q.target.value)},e[18]=I):I=e[18];const C=I;let L;e[19]!==s?(L=(q,E)=>{s(M=>M.map(D=>D.id===q?{...D,sql:E}:D))},e[19]=s,e[20]=L):L=e[20];const _=L;let O;return e[21]!==T||e[22]!==m||e[23]!==d||e[24]!==k||e[25]!==N||e[26]!==g||e[27]!==o||e[28]!==x||e[29]!==i||e[30]!==y||e[31]!==_?(O={clearHistory:T,deleteQuery:m,history:d,listRef:h,loadFromHistory:k,loadTemplate:N,newQuery:g,onSearchChange:C,queries:o,recordHistory:x,search:i,selectQuery:y,updateQuerySql:_},e[21]=T,e[22]=m,e[23]=d,e[24]=k,e[25]=N,e[26]=g,e[27]=o,e[28]=x,e[29]=i,e[30]=y,e[31]=_,e[32]=O):O=e[32],O},Ve="p-3 font-mono text-xs leading-5 whitespace-pre-wrap break-words",En=(l,e)=>{const t=[];for(const r of l){if(r.offset===void 0||r.length===void 0||r.length<=0)continue;const o=Math.max(0,Math.min(r.offset,e)),s=Math.max(o,Math.min(r.offset+r.length,e));o!==s&&t.push({end:s,severity:r.severity,start:o})}t.sort((r,o)=>r.start-o.start);const n=[];for(const r of t)r.start>=(n.at(-1)?.end??0)&&n.push(r);return n},Ln=l=>l==="unsafe-response"?"The model returned a statement that is not read-only, so it was discarded.":l==="empty-response"?"The model returned nothing usable.":"The model could not be reached.",_n=l=>{const e=K(51),{assistant:t,failed:n,onGenerated:r}=l,o=le(),[s,d]=re("");if(t.unavailable)return null;let a;e[0]!==t?(a=t.pending("sql"),e[0]=t,e[1]=a):a=e[1];const i=a;let f;if(e[2]!==t||e[3]!==n||e[4]!==r||e[5]!==i||e[6]!==s||e[7]!==o){const h=t.reason("sql");let p;e[9]!==t||e[10]!==n||e[11]!==r||e[12]!==s?(p=C=>{const L=s.trim();L===""&&!C||de((async()=>{const _=await t.generate(L===""?"fix the failing statement":L,C?n:void 0);_!==void 0&&r(_)})())},e[9]=t,e[10]=n,e[11]=r,e[12]=s,e[13]=p):p=e[13];const x=p;let c;e[14]!==o?(c=o("Describe the query you want"),e[14]=o,e[15]=c):c=e[15];let g;e[16]===Symbol.for("react.memo_cache_sentinel")?(g=C=>{d(C.target.value)},e[16]=g):g=e[16];let v;e[17]!==x?(v=C=>{C.key==="Enter"&&(C.preventDefault(),x(!1))},e[17]=x,e[18]=v):v=e[18];let y;e[19]!==o?(y=o("Describe the query you want"),e[19]=o,e[20]=y):y=e[20];let b;e[21]!==i||e[22]!==s||e[23]!==c||e[24]!==v||e[25]!==y?(b=u(rt,{"aria-label":c,className:"h-7 flex-1 text-xs","data-testid":"sql-assistant-prompt",disabled:i,onChange:g,onKeyDown:v,placeholder:y,value:s}),e[21]=i,e[22]=s,e[23]=c,e[24]=v,e[25]=y,e[26]=b):b=e[26];const m=i&&"opacity-60";let w;e[27]!==m?(w=ue("rounded-md border border-border px-2 py-1 text-xs outline-none transition-colors hover:bg-accent focus-visible:bg-accent",m),e[27]=m,e[28]=w):w=e[28];let N;e[29]!==i||e[30]!==s?(N=i||s.trim()==="",e[29]=i,e[30]=s,e[31]=N):N=e[31];let S;e[32]!==x?(S=()=>{x(!1)},e[32]=x,e[33]=S):S=e[33];let k;e[34]!==i||e[35]!==o?(k=o(i?"Thinking…":"Draft SQL"),e[34]=i,e[35]=o,e[36]=k):k=e[36];let R;e[37]!==w||e[38]!==N||e[39]!==S||e[40]!==k?(R=u("button",{className:w,"data-testid":"sql-assistant-generate",disabled:N,onClick:S,type:"button",children:k}),e[37]=w,e[38]=N,e[39]=S,e[40]=k,e[41]=R):R=e[41];let T;e[42]!==n||e[43]!==i||e[44]!==x||e[45]!==o?(T=n!==void 0&&u("button",{className:"rounded-md border border-border px-2 py-1 text-xs outline-none transition-colors hover:bg-accent focus-visible:bg-accent","data-testid":"sql-assistant-fix",disabled:i,onClick:()=>{x(!0)},type:"button",children:o("Fix this")}),e[42]=n,e[43]=i,e[44]=x,e[45]=o,e[46]=T):T=e[46];let I;e[47]!==R||e[48]!==T||e[49]!==b?(I=A("div",{className:"flex items-center gap-2",children:[b,R,T]}),e[47]=R,e[48]=T,e[49]=b,e[50]=I):I=e[50],f=A("div",{className:"flex flex-col gap-1 border-b border-border px-3 py-2","data-testid":"sql-assistant",children:[I,h!==void 0&&u("p",{className:"text-[11px] text-muted-foreground","data-testid":"sql-assistant-reason",role:"status",children:Ln(h)})]}),e[2]=t,e[3]=n,e[4]=r,e[5]=i,e[6]=s,e[7]=o,e[8]=f}else f=e[8];return f},On=l=>{const e=K(8),{diagnostics:t,draft:n,scrollRef:r}=l;let o,s;if(e[0]!==t||e[1]!==n){s=Symbol.for("react.early_return_sentinel");e:{const i=En(t,n.length);if(i.length===0){s=null;break e}o=[];let f=0;for(const[h,p]of i.entries())p.start>f&&o.push(n.slice(f,p.start)),o.push(u("span",{className:ue("decoration-wavy underline underline-offset-4",p.severity==="error"?"decoration-destructive":"decoration-amber-500"),children:n.slice(p.start,p.end)},`${p.start.toString()}-${h.toString()}`)),f=p.end;o.push(n.slice(f))}e[0]=t,e[1]=n,e[2]=o,e[3]=s}else o=e[2],s=e[3];if(s!==Symbol.for("react.early_return_sentinel"))return s;let d;e[4]===Symbol.for("react.memo_cache_sentinel")?(d=ue("pointer-events-none absolute inset-0 overflow-hidden text-transparent",Ve),e[4]=d):d=e[4];let a;return e[5]!==o||e[6]!==r?(a=u("div",{"aria-hidden":"true",className:d,"data-testid":"sql-diagnostics-overlay",ref:r,children:o}),e[5]=o,e[6]=r,e[7]=a):a=e[7],a},Mn={gate:"read-only",plan:"plan",schema:"schema",syntax:"syntax"},Dn=l=>{const e=K(10),{diagnostics:t,onSelect:n}=l,r=le();if(t.length===0)return null;let o;e[0]!==r?(o=r("SQL problems"),e[0]=r,e[1]=o):o=e[1];let s;if(e[2]!==t||e[3]!==n){let a;e[5]!==n?(a=(i,f)=>u("li",{children:A("button",{className:"flex w-full items-start gap-2 px-3 py-1 text-start text-xs outline-none hover:bg-accent focus-visible:bg-accent","data-testid":"sql-problem",onClick:()=>{n(i)},type:"button",children:[u("span",{className:ue("mt-px shrink-0 rounded px-1 font-mono text-[10px] uppercase",i.severity==="error"?"bg-destructive/15 text-destructive":"bg-amber-500/15 text-amber-600"),children:Mn[i.source]}),u("span",{className:"min-w-0 text-muted-foreground",children:i.message})]})},`${i.source}-${(i.offset??f).toString()}-${f.toString()}`),e[5]=n,e[6]=a):a=e[6],s=t.map(a),e[2]=t,e[3]=n,e[4]=s}else s=e[4];let d;return e[7]!==o||e[8]!==s?(d=u("ul",{"aria-label":o,className:"max-h-24 shrink-0 overflow-y-auto border-t border-border bg-muted/30","data-testid":"sql-problems",children:s}),e[7]=o,e[8]=s,e[9]=d):d=e[9],d},An={minWidth:"2.75rem",paddingInline:"0.5rem"},Bn=l=>{const e=K(64),{assistant:t,autocomplete:n,diagnostics:r,draft:o,failed:s,handlers:d,editorRef:a,gutterRef:i,listboxId:f,onGenerated:h,onPickSuggestion:p,onRevealDiagnostic:x,overlayRef:c}=l,g=le();let v,y,b,m,w,N,S,k;if(e[0]!==t||e[1]!==o||e[2]!==s||e[3]!==i||e[4]!==h){const B=o.split(`
|
|
5
|
+
`).length;S="flex min-h-0 min-w-0 flex-1 flex-col",e[13]!==t||e[14]!==s||e[15]!==h?(k=u(_n,{assistant:t,failed:s,onGenerated:h}),e[13]=t,e[14]=s,e[15]=h,e[16]=k):k=e[16],N="flex min-h-0 min-w-0 flex-1",v="true",y="shrink-0 select-none overflow-hidden border-e border-border bg-muted/30 py-3 text-end font-mono text-xs leading-5 text-muted-foreground/60",b=i,m=An,w=Array.from({length:B},zn),e[0]=t,e[1]=o,e[2]=s,e[3]=i,e[4]=h,e[5]=v,e[6]=y,e[7]=b,e[8]=m,e[9]=w,e[10]=N,e[11]=S,e[12]=k}else v=e[5],y=e[6],b=e[7],m=e[8],w=e[9],N=e[10],S=e[11],k=e[12];let R;e[17]!==v||e[18]!==y||e[19]!==b||e[20]!==m||e[21]!==w?(R=u("div",{"aria-hidden":v,className:y,ref:b,style:m,children:w}),e[17]=v,e[18]=y,e[19]=b,e[20]=m,e[21]=w,e[22]=R):R=e[22];let T;e[23]!==r||e[24]!==o||e[25]!==c?(T=u(On,{diagnostics:r,draft:o,scrollRef:c}),e[23]=r,e[24]=o,e[25]=c,e[26]=T):T=e[26];let I;e[27]!==n||e[28]!==f?(I=n===null?void 0:`${f}-opt-${n.active.toString()}`,e[27]=n,e[28]=f,e[29]=I):I=e[29];const C=n===null?void 0:f,L=n!==null;let _;e[30]!==g?(_=g("SQL query"),e[30]=g,e[31]=_):_=e[31];let O;e[32]!==o||e[33]!==a||e[34]!==d.onBlur||e[35]!==d.onChange||e[36]!==d.onKeyDown||e[37]!==d.onScroll||e[38]!==d.onSelect||e[39]!==I||e[40]!==C||e[41]!==L||e[42]!==_?(O=u("textarea",{"aria-activedescendant":I,"aria-autocomplete":"list","aria-controls":C,"aria-expanded":L,"aria-label":_,className:`relative size-full resize-none bg-transparent outline-none ${Ve}`,"data-testid":"sql-input",onBlur:d.onBlur,onChange:d.onChange,onKeyDown:d.onKeyDown,onScroll:d.onScroll,onSelect:d.onSelect,placeholder:"SELECT * FROM …",ref:a,role:"combobox",spellCheck:!1,value:o}),e[32]=o,e[33]=a,e[34]=d.onBlur,e[35]=d.onChange,e[36]=d.onKeyDown,e[37]=d.onScroll,e[38]=d.onSelect,e[39]=I,e[40]=C,e[41]=L,e[42]=_,e[43]=O):O=e[43];let q;e[44]!==n||e[45]!==f||e[46]!==p?(q=u(sn,{listboxId:f,onPick:p,state:n}),e[44]=n,e[45]=f,e[46]=p,e[47]=q):q=e[47];let E;e[48]!==T||e[49]!==O||e[50]!==q?(E=A("div",{className:"relative min-w-0 flex-1 bg-background",children:[T,O,q]}),e[48]=T,e[49]=O,e[50]=q,e[51]=E):E=e[51];let M;e[52]!==E||e[53]!==N||e[54]!==R?(M=A("div",{className:N,children:[R,E]}),e[52]=E,e[53]=N,e[54]=R,e[55]=M):M=e[55];let D;e[56]!==r||e[57]!==x?(D=u(Dn,{diagnostics:r,onSelect:x}),e[56]=r,e[57]=x,e[58]=D):D=e[58];let $;return e[59]!==M||e[60]!==D||e[61]!==S||e[62]!==k?($=A("div",{className:S,children:[k,M,D]}),e[59]=M,e[60]=D,e[61]=S,e[62]=k,e[63]=$):$=e[63],$};function zn(l,e){return u("div",{children:e+1},e)}const Xe=[{label:"List tables",sql:"SELECT name FROM sqlite_master WHERE type = 'table' ORDER BY name;"},{label:"Table row count",sql:"SELECT COUNT(*) AS rows FROM messages;"},{label:"Recent rows",sql:"SELECT id, _creationTime, __doc__ FROM messages ORDER BY _creationTime DESC LIMIT 50;"},{label:"Index list",sql:"SELECT name, tbl_name FROM sqlite_master WHERE type = 'index' ORDER BY tbl_name;"}],Hn=l=>{const e=K(29),{active:t,onDelete:n,onSelect:r,query:o}=l,s=le();let d;e[0]!==r||e[1]!==o.id?(d=()=>{r(o.id)},e[0]=r,e[1]=o.id,e[2]=d):d=e[2];const a=d;let i;e[3]!==n||e[4]!==o.id?(i=S=>{S.stopPropagation(),n(o.id)},e[3]=n,e[4]=o.id,e[5]=i):i=e[5];const f=i,h=t?"bg-sidebar-accent font-medium text-foreground":"text-muted-foreground";let p;e[6]!==h?(p=ue("flex min-w-0 flex-1 items-center gap-2 rounded-md px-2 py-1.5 text-start text-[13px] outline-none transition-colors hover:bg-sidebar-accent focus-visible:bg-sidebar-accent",h),e[6]=h,e[7]=p):p=e[7];const x=`sql-query-${o.id}`;let c;e[8]===Symbol.for("react.memo_cache_sentinel")?(c=u("svg",{"aria-hidden":"true",className:"size-3.5 shrink-0 opacity-70",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:u("path",{d:"M4 6h16M4 12h10M4 18h7"})}),e[8]=c):c=e[8];let g;e[9]!==o.name?(g=u("span",{className:"truncate",children:o.name}),e[9]=o.name,e[10]=g):g=e[10];let v;e[11]!==t||e[12]!==a||e[13]!==p||e[14]!==x||e[15]!==g?(v=A("button",{"aria-pressed":t,className:p,"data-testid":x,onClick:a,type:"button",children:[c,g]}),e[11]=t,e[12]=a,e[13]=p,e[14]=x,e[15]=g,e[16]=v):v=e[16];let y;e[17]!==s?(y=s("Delete query"),e[17]=s,e[18]=y):y=e[18];let b;e[19]!==s?(b=s("Delete query"),e[19]=s,e[20]=b):b=e[20];let m;e[21]===Symbol.for("react.memo_cache_sentinel")?(m=u("svg",{"aria-hidden":"true",className:"size-3.5",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:u("path",{d:"M5 7h14M9 7V5h6v2m-1 0v12H10V7M7 7v13h10V7"})}),e[21]=m):m=e[21];let w;e[22]!==f||e[23]!==b||e[24]!==y?(w=u("button",{"aria-label":y,className:"me-1 hidden size-6 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-destructive/10 hover:text-destructive group-hover/q:flex",onClick:f,title:b,type:"button",children:m}),e[22]=f,e[23]=b,e[24]=y,e[25]=w):w=e[25];let N;return e[26]!==w||e[27]!==v?(N=A("li",{className:"group/q flex items-center",children:[v,w]}),e[26]=w,e[27]=v,e[28]=N):N=e[28],N},Pn=(l,e)=>{const t=e.trim().toLowerCase();return t===""?[...l]:l.filter(n=>n.name.toLowerCase().includes(t))},Fn=l=>{const e=K(60),{activeId:t,history:n,listRef:r,onClearHistory:o,onDelete:s,onLoadHistory:d,onLoadTemplate:a,onNew:i,onSearchChange:f,onSelect:h,queries:p,search:x}=l,c=le();let g,v,y,b;if(e[0]!==t||e[1]!==r||e[2]!==s||e[3]!==i||e[4]!==f||e[5]!==h||e[6]!==p||e[7]!==x||e[8]!==c){const C=Pn(p,x);v="flex h-full w-64 shrink-0 flex-col border-e border-border bg-sidebar";let L;e[13]!==c?(L=c("Search queries…"),e[13]=c,e[14]=L):L=e[14];let _;e[15]!==f||e[16]!==x||e[17]!==L?(_=u("input",{className:"h-8 min-w-0 flex-1 rounded-md border border-border bg-background px-2 text-xs outline-none focus-visible:border-ring","data-testid":"sql-search",onChange:f,placeholder:L,type:"text",value:x}),e[15]=f,e[16]=x,e[17]=L,e[18]=_):_=e[18];let O;e[19]!==c?(O=c("New query"),e[19]=c,e[20]=O):O=e[20];let q;e[21]!==c?(q=c("New query"),e[21]=c,e[22]=q):q=e[22];let E;e[23]===Symbol.for("react.memo_cache_sentinel")?(E=u("svg",{"aria-hidden":"true",className:"size-4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.7,viewBox:"0 0 24 24",children:u("path",{d:"M12 5v14M5 12h14"})}),e[23]=E):E=e[23];let M;e[24]!==i||e[25]!==O||e[26]!==q?(M=u("button",{"aria-label":O,className:"flex size-8 shrink-0 items-center justify-center rounded-md border border-border text-foreground outline-none transition-colors hover:bg-accent focus-visible:bg-accent","data-testid":"sql-new",onClick:i,title:q,type:"button",children:E}),e[24]=i,e[25]=O,e[26]=q,e[27]=M):M=e[27],e[28]!==M||e[29]!==_?(y=A("div",{className:"flex shrink-0 items-center gap-2 border-b border-border p-2",children:[_,M]}),e[28]=M,e[29]=_,e[30]=y):y=e[30],g="flex flex-1 flex-col gap-4 overflow-y-auto p-2";let D;e[31]!==c?(D=c("Private"),e[31]=c,e[32]=D):D=e[32];let $;e[33]!==D?($=u("p",{className:"px-1 pb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:D}),e[33]=D,e[34]=$):$=e[34],b=A("div",{children:[$,C.length===0?u("p",{className:"px-1 py-2 text-xs text-muted-foreground","data-testid":"sql-private-empty",children:c("No saved queries yet — they save to this browser as you type.")}):u("ul",{className:"flex flex-col gap-px","data-testid":"sql-private",ref:r,children:C.map(B=>u(Hn,{active:t===B.id,onDelete:s,onSelect:h,query:B},B.id))})]}),e[0]=t,e[1]=r,e[2]=s,e[3]=i,e[4]=f,e[5]=h,e[6]=p,e[7]=x,e[8]=c,e[9]=g,e[10]=v,e[11]=y,e[12]=b}else g=e[9],v=e[10],y=e[11],b=e[12];let m;e[35]!==c?(m=c("Reference"),e[35]=c,e[36]=m):m=e[36];let w;e[37]!==m?(w=u("p",{className:"px-1 pb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:m}),e[37]=m,e[38]=w):w=e[38];let N;e[39]!==a?(N=Xe.map(C=>u("li",{children:A("button",{className:"flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-start text-[13px] text-muted-foreground outline-none transition-colors hover:bg-sidebar-accent hover:text-foreground focus-visible:bg-sidebar-accent","data-sql":C.sql,onClick:a,type:"button",children:[u("svg",{"aria-hidden":"true",className:"size-3.5 shrink-0 opacity-70",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:u("path",{d:"M7 4h7l4 4v12H7zM14 4v4h4"})}),C.label]})},C.label)),e[39]=a,e[40]=N):N=e[40];let S;e[41]!==N?(S=u("ul",{className:"flex flex-col gap-px",children:N}),e[41]=N,e[42]=S):S=e[42];let k;e[43]!==w||e[44]!==S?(k=A("div",{children:[w,S]}),e[43]=w,e[44]=S,e[45]=k):k=e[45];let R;e[46]!==n||e[47]!==o||e[48]!==d||e[49]!==c?(R=n.length>0&&A("div",{children:[A("div",{className:"flex items-center justify-between px-1 pb-1",children:[u("p",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:c("History")}),u("button",{className:"rounded px-1 text-[11px] text-muted-foreground outline-none transition-colors hover:text-foreground focus-visible:text-foreground","data-testid":"sql-history-clear",onClick:o,type:"button",children:c("Clear history")})]}),u("ul",{className:"flex flex-col gap-px","data-testid":"sql-history",children:n.map(C=>u("li",{children:A("button",{className:"flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-start text-[13px] text-muted-foreground outline-none transition-colors hover:bg-sidebar-accent hover:text-foreground focus-visible:bg-sidebar-accent","data-sql":C.sql,"data-testid":"sql-history-item",onClick:d,title:C.sql,type:"button",children:[u("svg",{"aria-hidden":"true",className:"size-3.5 shrink-0 opacity-70",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:u("path",{d:"M12 8v4l3 2M12 21a9 9 0 1 1 0-18 9 9 0 0 1 0 18Z"})}),u("span",{className:"truncate font-mono",children:C.sql})]})},`${C.at.toString()}:${C.sql}`))})]}),e[46]=n,e[47]=o,e[48]=d,e[49]=c,e[50]=R):R=e[50];let T;e[51]!==g||e[52]!==R||e[53]!==b||e[54]!==k?(T=A("div",{className:g,children:[b,k,R]}),e[51]=g,e[52]=R,e[53]=b,e[54]=k,e[55]=T):T=e[55];let I;return e[56]!==T||e[57]!==v||e[58]!==y?(I=A("aside",{className:v,children:[y,T]}),e[56]=T,e[57]=v,e[58]=y,e[59]=I):I=e[59],I},Qn=l=>{const e=K(19),{result:t}=l,n=le();if(t.columns.length===0){let i;e[0]!==t.rowCount||e[1]!==n?(i=n("{count} rows",{count:t.rowCount}),e[0]=t.rowCount,e[1]=n,e[2]=i):i=e[2];let f;return e[3]!==i?(f=u("p",{className:"p-4 text-sm text-muted-foreground",children:i}),e[3]=i,e[4]=f):f=e[4],f}let r;e[5]!==t.columns?(r=t.columns.map(jn),e[5]=t.columns,e[6]=r):r=e[6];let o;e[7]!==r?(o=u(ct,{className:"sticky top-0 z-10 bg-muted",children:u(He,{children:r})}),e[7]=r,e[8]=o):o=e[8];let s;if(e[9]!==t.columns||e[10]!==t.rows){let i;e[12]!==t.columns?(i=(f,h)=>u(He,{"data-testid":"sql-row",children:t.columns.map(p=>u(ft,{className:"max-w-md truncate font-mono text-xs",children:u(ht,{value:f[p]})},p))},h),e[12]=t.columns,e[13]=i):i=e[13],s=t.rows.map(i),e[9]=t.columns,e[10]=t.rows,e[11]=s}else s=e[11];let d;e[14]!==s?(d=u(dt,{children:s}),e[14]=s,e[15]=d):d=e[15];let a;return e[16]!==o||e[17]!==d?(a=A(ut,{"data-testid":"sql-rows",children:[o,d]}),e[16]=o,e[17]=d,e[18]=a):a=e[18],a};function jn(l){return u(mt,{children:l},l)}const Ne=l=>`border-b-2 px-3 py-2 text-sm outline-none transition-colors ${l?"border-foreground font-medium text-foreground":"border-transparent text-muted-foreground hover:text-foreground"}`,Wn=l=>{const e=K(92),{assistant:t,chart:n,className:r,error:o,onFormat:s,onInferChart:d,onRun:a,onShardKeyChange:i,onShowChart:f,onShowExplain:h,onShowResults:p,onToggleSplit:x,pane:c,result:g,running:v,shardKey:y,splitView:b}=l,m=le(),w=c==="results";let N;e[0]!==w?(N=Ne(w),e[0]=w,e[1]=N):N=e[1];let S;e[2]!==m?(S=m("Results"),e[2]=m,e[3]=S):S=e[3];let k;e[4]!==p||e[5]!==N||e[6]!==S?(k=u("button",{className:N,"data-testid":"sql-tab-results",onClick:p,type:"button",children:S}),e[4]=p,e[5]=N,e[6]=S,e[7]=k):k=e[7];const R=c==="chart";let T;e[8]!==R?(T=Ne(R),e[8]=R,e[9]=T):T=e[9];let I;e[10]!==m?(I=m("Chart"),e[10]=m,e[11]=I):I=e[11];let C;e[12]!==f||e[13]!==T||e[14]!==I?(C=u("button",{className:T,"data-testid":"sql-tab-chart",onClick:f,type:"button",children:I}),e[12]=f,e[13]=T,e[14]=I,e[15]=C):C=e[15];let L;e[16]!==t||e[17]!==d||e[18]!==c||e[19]!==g||e[20]!==m?(L=!t.unavailable&&c==="chart"&&g!==null&&u("button",{className:Ne(!1),"data-testid":"sql-infer-chart",disabled:t.pending("chart"),onClick:d,type:"button",children:t.pending("chart")?m("Thinking…"):m("Suggest chart")}),e[16]=t,e[17]=d,e[18]=c,e[19]=g,e[20]=m,e[21]=L):L=e[21];const _=c==="explain";let O;e[22]!==_?(O=Ne(_),e[22]=_,e[23]=O):O=e[23];let q;e[24]!==m?(q=m("Explain"),e[24]=m,e[25]=q):q=e[25];let E;e[26]!==h||e[27]!==O||e[28]!==q?(E=u("button",{className:O,"data-testid":"sql-tab-explain",onClick:h,type:"button",children:q}),e[26]=h,e[27]=O,e[28]=q,e[29]=E):E=e[29];let M;e[30]!==m?(M=m("Split editor and results"),e[30]=m,e[31]=M):M=e[31];const D=`inline-flex items-center rounded-md border border-border px-2 py-1.5 outline-none transition-colors hover:bg-accent focus-visible:bg-accent ${b?"bg-accent text-foreground":"text-muted-foreground"}`;let $;e[32]!==m?($=m("Split editor and results"),e[32]=m,e[33]=$):$=e[33];let B;e[34]===Symbol.for("react.memo_cache_sentinel")?(B=A("svg",{"aria-hidden":"true",className:"size-4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.7,viewBox:"0 0 24 24",children:[u("rect",{height:"16",rx:"2",width:"18",x:"3",y:"4"}),u("path",{d:"M12 4v16"})]}),e[34]=B):B=e[34];let F;e[35]!==x||e[36]!==b||e[37]!==M||e[38]!==D||e[39]!==$?(F=u("button",{"aria-label":M,"aria-pressed":b,className:D,"data-testid":"sql-split-toggle",onClick:x,title:$,type:"button",children:B}),e[35]=x,e[36]=b,e[37]=M,e[38]=D,e[39]=$,e[40]=F):F=e[40];let P;e[41]!==g?(P=g!==null&&g.columns.length>0&&u(it,{columns:g.columns,name:"query-result",rows:g.rows}),e[41]=g,e[42]=P):P=e[42];let W;e[43]!==m?(W=m("Format"),e[43]=m,e[44]=W):W=e[44];let Q;e[45]!==s||e[46]!==v||e[47]!==W?(Q=u("button",{className:"inline-flex items-center rounded-md border border-border px-3 py-1.5 text-xs font-medium text-foreground outline-none transition-colors hover:bg-accent focus-visible:bg-accent disabled:pointer-events-none disabled:opacity-50","data-testid":"sql-format",disabled:v,onClick:s,type:"button",children:W}),e[45]=s,e[46]=v,e[47]=W,e[48]=Q):Q=e[48];let Y;e[49]!==i||e[50]!==y?(Y=u(st,{onChange:i,testId:"sql-shard-input",value:y}),e[49]=i,e[50]=y,e[51]=Y):Y=e[51];let J;e[52]!==v||e[53]!==m?(J=m(v?"Running…":"Run"),e[52]=v,e[53]=m,e[54]=J):J=e[54];let z;e[55]===Symbol.for("react.memo_cache_sentinel")?(z=u("kbd",{className:"rounded border border-primary-foreground/30 px-1 font-sans text-[10px]",children:"⌘↵"}),e[55]=z):z=e[55];let G;e[56]!==a||e[57]!==v||e[58]!==J?(G=A("button",{className:"inline-flex items-center gap-1.5 rounded-md bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground outline-none transition-colors hover:bg-primary/90 focus-visible:bg-primary/90 disabled:pointer-events-none disabled:opacity-50","data-testid":"sql-run",disabled:v,onClick:a,type:"button",children:[J,z]}),e[56]=a,e[57]=v,e[58]=J,e[59]=G):G=e[59];let ne;e[60]!==F||e[61]!==P||e[62]!==Q||e[63]!==Y||e[64]!==G?(ne=A("div",{className:"ms-auto flex items-center gap-2",children:[F,P,Q,Y,G]}),e[60]=F,e[61]=P,e[62]=Q,e[63]=Y,e[64]=G,e[65]=ne):ne=e[65];let V;e[66]!==E||e[67]!==ne||e[68]!==k||e[69]!==C||e[70]!==L?(V=A("div",{className:"flex shrink-0 items-center gap-2 border-b border-border pe-2",children:[k,C,L,E,ne]}),e[66]=E,e[67]=ne,e[68]=k,e[69]=C,e[70]=L,e[71]=V):V=e[71];let X;e[72]!==o?(X=o!==null&&u(at,{className:"m-3 font-mono text-xs",testId:"sql-error",variant:"destructive",children:o}),e[72]=o,e[73]=X):X=e[73];let Z;e[74]!==o||e[75]!==g||e[76]!==m?(Z=o===null&&g===null&&u("p",{className:"p-4 text-sm text-muted-foreground","data-testid":"sql-empty",children:m("Click Run to execute your query.")}),e[74]=o,e[75]=g,e[76]=m,e[77]=Z):Z=e[77];let ee;e[78]!==n||e[79]!==o||e[80]!==c||e[81]!==g||e[82]!==m?(ee=o===null&&g!==null&&A("div",{"data-testid":"sql-result",children:[c==="chart"?u(lt,{axes:n,result:g}):u(Qn,{result:g}),u("p",{className:"border-t border-border px-3 py-1.5 text-xs text-muted-foreground","data-testid":"sql-count",children:g.truncated?m("Showing the first {max} of {count} rows.",{count:g.rowCount,max:g.rows.length}):m("{count} rows",{count:g.rowCount})})]}),e[78]=n,e[79]=o,e[80]=c,e[81]=g,e[82]=m,e[83]=ee):ee=e[83];let te;e[84]!==X||e[85]!==Z||e[86]!==ee?(te=A("div",{className:"min-h-0 flex-1 overflow-auto",children:[X,Z,ee]}),e[84]=X,e[85]=Z,e[86]=ee,e[87]=te):te=e[87];let oe;return e[88]!==r||e[89]!==V||e[90]!==te?(oe=A("div",{className:r,children:[V,te]}),e[88]=r,e[89]=V,e[90]=te,e[91]=oe):oe=e[91],oe},Kn=(l,e)=>l.trim()===""?e:(l.split(`
|
|
6
|
+
`)[0]??l).slice(0,24),Un=l=>{l?.focus(),l?.select()},Yn=l=>{const e=K(14),{initial:t,onCancel:n,onCommit:r,placeholder:o,testId:s}=l,d=le();let a;e[0]!==r?(a=c=>{r(c.currentTarget.value.trim())},e[0]=r,e[1]=a):a=e[1];const i=a;let f;e[2]!==n||e[3]!==r?(f=c=>{c.key==="Enter"?r(c.currentTarget.value.trim()):c.key==="Escape"&&n()},e[2]=n,e[3]=r,e[4]=f):f=e[4];const h=f;let p;e[5]!==d?(p=d("Tab title"),e[5]=d,e[6]=p):p=e[6];let x;return e[7]!==t||e[8]!==i||e[9]!==h||e[10]!==o||e[11]!==p||e[12]!==s?(x=u("input",{"aria-label":p,className:"w-40 rounded border border-ring bg-background px-1 py-0.5 text-xs outline-none","data-testid":s,defaultValue:t,onBlur:i,onKeyDown:h,placeholder:o,ref:Un,type:"text"}),e[7]=t,e[8]=i,e[9]=h,e[10]=o,e[11]=p,e[12]=s,e[13]=x):x=e[13],x},Jn=l=>{const e=K(29),{idBase:t,onDiscard:n,onKeep:r}=l,o=le(),s=`sql-tab-close-prompt-${t}`;let d;e[0]!==o?(d=o("Discard?"),e[0]=o,e[1]=d):d=e[1];let a;e[2]!==d?(a=u("span",{className:"text-[11px] text-muted-foreground",children:d}),e[2]=d,e[3]=a):a=e[3];let i;e[4]!==o?(i=o("Discard changes"),e[4]=o,e[5]=i):i=e[5];const f=`sql-tab-close-confirm-${t}`;let h;e[6]!==o?(h=o("Discard changes"),e[6]=o,e[7]=h):h=e[7];let p;e[8]===Symbol.for("react.memo_cache_sentinel")?(p=u("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2.4,viewBox:"0 0 24 24",children:u("path",{d:"M5 13l4 4L19 7"})}),e[8]=p):p=e[8];let x;e[9]!==n||e[10]!==i||e[11]!==f||e[12]!==h?(x=u("button",{"aria-label":i,className:"flex size-5 items-center justify-center rounded text-destructive hover:bg-destructive/10","data-testid":f,onClick:n,title:h,type:"button",children:p}),e[9]=n,e[10]=i,e[11]=f,e[12]=h,e[13]=x):x=e[13];let c;e[14]!==o?(c=o("Keep editing"),e[14]=o,e[15]=c):c=e[15];const g=`sql-tab-close-cancel-${t}`;let v;e[16]!==o?(v=o("Keep editing"),e[16]=o,e[17]=v):v=e[17];let y;e[18]===Symbol.for("react.memo_cache_sentinel")?(y=u("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2.4,viewBox:"0 0 24 24",children:u("path",{d:"M6 6l12 12M18 6 6 18"})}),e[18]=y):y=e[18];let b;e[19]!==r||e[20]!==g||e[21]!==v||e[22]!==c?(b=u("button",{"aria-label":c,className:"flex size-5 items-center justify-center rounded text-muted-foreground hover:bg-accent","data-testid":g,onClick:r,title:v,type:"button",children:y}),e[19]=r,e[20]=g,e[21]=v,e[22]=c,e[23]=b):b=e[23];let m;return e[24]!==s||e[25]!==b||e[26]!==a||e[27]!==x?(m=A("span",{className:"flex shrink-0 items-center gap-1","data-testid":s,role:"group",children:[a,x,b]}),e[24]=s,e[25]=b,e[26]=a,e[27]=x,e[28]=m):m=e[28],m},Gn=l=>{const e=K(47),{active:t,canClose:n,onClose:r,onMenu:o,onRename:s,onSelect:d,tab:a}=l,i=le(),[f,h]=re(!1),[p,x]=re(!1);let c;e[0]!==o||e[1]!==a.id?(c=Q=>{o(a.id,Q)},e[0]=o,e[1]=a.id,e[2]=c):c=e[2];const g=c;let v;e[3]!==d||e[4]!==a.id?(v=()=>{d(a.id)},e[3]=d,e[4]=a.id,e[5]=v):v=e[5];const y=v;let b;e[6]===Symbol.for("react.memo_cache_sentinel")?(b=()=>{h(!0)},e[6]=b):b=e[6];const m=b;let w;e[7]!==r||e[8]!==a?(w=Q=>{Q.stopPropagation(),Ge(a)?x(!0):r(a.id)},e[7]=r,e[8]=a,e[9]=w):w=e[9];const N=w;let S;e[10]!==r||e[11]!==a.id?(S=Q=>{Q.stopPropagation(),x(!1),r(a.id)},e[10]=r,e[11]=a.id,e[12]=S):S=e[12];const k=S;let R;e[13]===Symbol.for("react.memo_cache_sentinel")?(R=Q=>{Q.stopPropagation(),x(!1)},e[13]=R):R=e[13];const T=R;let I;e[14]!==s||e[15]!==a.id?(I=Q=>{s(a.id,Q),h(!1)},e[14]=s,e[15]=a.id,e[16]=I):I=e[16];const C=I;let L;e[17]===Symbol.for("react.memo_cache_sentinel")?(L=()=>{h(!1)},e[17]=L):L=e[17];const _=L;let O;e[18]!==a.name?(O=a.name.trim(),e[18]=a.name,e[19]=O):O=e[19];const q=O;let E;e[20]!==i||e[21]!==a.sql?(E=Kn(a.sql,i("Untitled")),e[20]=i,e[21]=a.sql,e[22]=E):E=e[22];const M=E,D=t?"bg-background text-foreground":"bg-muted/40 text-muted-foreground hover:text-foreground";let $;e[23]!==D?($=ue("group/tab flex shrink-0 items-center gap-1 border-e border-border ps-3 pe-1.5 text-xs",D),e[23]=D,e[24]=$):$=e[24];const B=`sql-tab-${a.id}`;let F;e[25]!==t||e[26]!==C||e[27]!==q||e[28]!==M||e[29]!==f||e[30]!==y||e[31]!==i||e[32]!==a.id?(F=f?u(Yn,{initial:q,onCancel:_,onCommit:C,placeholder:M,testId:`sql-tab-rename-${a.id}`}):u("button",{"aria-pressed":t,className:"max-w-40 truncate py-1.5 outline-none","data-testid":`sql-tab-select-${a.id}`,onClick:y,onDoubleClick:m,title:i("Double-click to rename"),type:"button",children:q===""?M:q}),e[25]=t,e[26]=C,e[27]=q,e[28]=M,e[29]=f,e[30]=y,e[31]=i,e[32]=a.id,e[33]=F):F=e[33];let P;e[34]!==n||e[35]!==k||e[36]!==p||e[37]!==N||e[38]!==i||e[39]!==a.id?(P=n&&(p?u(Jn,{idBase:a.id,onDiscard:k,onKeep:T}):u("button",{"aria-label":i("Close tab"),className:"flex size-5 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-destructive/10 hover:text-destructive","data-testid":`sql-tab-close-${a.id}`,onClick:N,title:i("Close tab"),type:"button",children:u("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,viewBox:"0 0 24 24",children:u("path",{d:"M6 6l12 12M18 6 6 18"})})})),e[34]=n,e[35]=k,e[36]=p,e[37]=N,e[38]=i,e[39]=a.id,e[40]=P):P=e[40];let W;return e[41]!==g||e[42]!==$||e[43]!==B||e[44]!==F||e[45]!==P?(W=A("div",{className:$,"data-testid":B,onContextMenu:g,children:[F,P]}),e[41]=g,e[42]=$,e[43]=B,e[44]=F,e[45]=P,e[46]=W):W=e[46],W},Vn=l=>{const e=K(43),{model:t,onSelect:n}=l,r=le(),{activeTab:o,addEditorTab:s,cancelBulk:d,closeEditorTab:a,closeTabMenu:i,confirmBulk:f,menuStyle:h,onBackdropContextMenu:p,onCloseAll:x,onCloseOthers:c,onCloseToRight:g,openTabMenu:v,pendingBulk:y,renameTab:b,tabMenu:m,tabs:w}=t;let N;if(e[0]!==o||e[1]!==a||e[2]!==n||e[3]!==v||e[4]!==b||e[5]!==w){let O;e[7]!==o||e[8]!==a||e[9]!==n||e[10]!==v||e[11]!==b||e[12]!==w.length?(O=q=>u(Gn,{active:q.id===o.id,canClose:w.length>1,onClose:a,onMenu:v,onRename:b,onSelect:n,tab:q},q.id),e[7]=o,e[8]=a,e[9]=n,e[10]=v,e[11]=b,e[12]=w.length,e[13]=O):O=e[13],N=w.map(O),e[0]=o,e[1]=a,e[2]=n,e[3]=v,e[4]=b,e[5]=w,e[6]=N}else N=e[6];let S;e[14]!==r?(S=r("New tab"),e[14]=r,e[15]=S):S=e[15];const k=w.length>=De;let R;e[16]!==r?(R=r("New tab"),e[16]=r,e[17]=R):R=e[17];let T;e[18]===Symbol.for("react.memo_cache_sentinel")?(T=u("svg",{"aria-hidden":"true",className:"size-4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.7,viewBox:"0 0 24 24",children:u("path",{d:"M12 5v14M5 12h14"})}),e[18]=T):T=e[18];let I;e[19]!==s||e[20]!==S||e[21]!==k||e[22]!==R?(I=u("button",{"aria-label":S,className:"flex size-8 shrink-0 items-center justify-center text-muted-foreground outline-none transition-colors hover:bg-accent hover:text-foreground focus-visible:bg-accent disabled:pointer-events-none disabled:opacity-40","data-testid":"sql-tab-add",disabled:k,onClick:s,title:R,type:"button",children:T}),e[19]=s,e[20]=S,e[21]=k,e[22]=R,e[23]=I):I=e[23];let C;e[24]!==N||e[25]!==I?(C=A("div",{className:"flex shrink-0 items-stretch overflow-x-auto border-b border-border bg-muted/30","data-testid":"sql-tab-strip",role:"tablist",children:[N,I]}),e[24]=N,e[25]=I,e[26]=C):C=e[26];let L;e[27]!==d||e[28]!==i||e[29]!==f||e[30]!==h||e[31]!==p||e[32]!==x||e[33]!==c||e[34]!==g||e[35]!==y||e[36]!==r||e[37]!==m||e[38]!==w?(L=m!==null&&A(Ee,{children:[u("div",{className:"fixed inset-0 z-40","data-testid":"sql-tab-menu-backdrop",onClick:i,onContextMenu:p,role:"presentation"}),u("div",{className:"fixed z-50 min-w-44 rounded-md border border-border bg-popover py-1 text-popover-foreground shadow-md","data-testid":"sql-tab-menu",role:"menu",style:h,children:y===null?A(Ee,{children:[u("button",{className:"flex w-full items-center px-3 py-1.5 text-start text-xs outline-none hover:bg-accent focus-visible:bg-accent disabled:pointer-events-none disabled:opacity-40","data-testid":"sql-tab-menu-close-others",disabled:w.length<=1,onClick:c,role:"menuitem",type:"button",children:r("Close other tabs")}),u("button",{className:"flex w-full items-center px-3 py-1.5 text-start text-xs outline-none hover:bg-accent focus-visible:bg-accent disabled:pointer-events-none disabled:opacity-40","data-testid":"sql-tab-menu-close-right",disabled:w.findIndex(O=>O.id===m.id)>=w.length-1,onClick:g,role:"menuitem",type:"button",children:r("Close tabs to the right")}),u("button",{className:"flex w-full items-center px-3 py-1.5 text-start text-xs outline-none hover:bg-accent focus-visible:bg-accent","data-testid":"sql-tab-menu-close-all",onClick:x,role:"menuitem",type:"button",children:r("Close all tabs")})]}):A("div",{className:"px-3 py-1.5","data-testid":"sql-tab-menu-confirm",children:[u("p",{className:"pb-1.5 text-xs text-muted-foreground",children:r("Discard unsaved tabs?")}),A("div",{className:"flex items-center gap-1.5",children:[u("button",{className:"rounded px-2 py-1 text-xs font-medium text-destructive outline-none hover:bg-destructive/10 focus-visible:bg-destructive/10","data-testid":"sql-tab-menu-confirm-discard",onClick:f,type:"button",children:r("Discard")}),u("button",{className:"rounded px-2 py-1 text-xs text-muted-foreground outline-none hover:bg-accent focus-visible:bg-accent","data-testid":"sql-tab-menu-confirm-cancel",onClick:d,type:"button",children:r("Cancel")})]})]})})]}),e[27]=d,e[28]=i,e[29]=f,e[30]=h,e[31]=p,e[32]=x,e[33]=c,e[34]=g,e[35]=y,e[36]=r,e[37]=m,e[38]=w,e[39]=L):L=e[39];let _;return e[40]!==C||e[41]!==L?(_=A(Ee,{children:[C,L]}),e[40]=C,e[41]=L,e[42]=_):_=e[42],_},Xn=Te($e.runSql),Zn="lunora-studio-sql-split-view",eo=()=>ve(Xe[0]?.sql??""),wo=l=>{const e=K(102),{initialShardKey:t}=l,n=Oe(),r=kn(eo),{activeTab:o,output:s,patchActiveOutput:d,patchActiveTab:a,setActiveTabId:i,unlinkQuery:f}=r;let h;e[0]!==d||e[1]!==a?(h=(se,ce)=>{a({activeId:ce,sql:se}),d({chart:void 0,error:null,failed:void 0,result:null})},e[0]=d,e[1]=a,e[2]=h):h=e[2];const p=h;let x;e[3]!==p||e[4]!==f?(x={loadIntoActiveTab:p,unlinkQuery:f},e[3]=p,e[4]=f,e[5]=x):x=e[5];const c=In(x),{recordHistory:g,updateQuerySql:v}=c,y=o.sql,{activeId:b}=o,{chart:m,error:w,failed:N,result:S,running:k}=s,R=s.pane,[T,I]=re(t??""),[C,L]=We(Zn,!1),{probe:_,schema:O}=dn(T);let q;e[6]!==b||e[7]!==a||e[8]!==v?(q=se=>{a({sql:se}),b!==null&&v(b,se)},e[6]=b,e[7]=a,e[8]=v,e[9]=q):q=e[9];const E=q,M=Ut(y,O,T),D=nt(T);let $;e[10]!==D||e[11]!==d||e[12]!==S?($=()=>{S!==null&&de((async()=>{const se=await D.inferChart({columns:S.columns,rowCount:S.rowCount,types:Object.fromEntries(S.columns.map(ce=>[ce,typeof(S.rows[0]?.[ce]??"")]))});d({chart:se})})())},e[10]=D,e[11]=d,e[12]=S,e[13]=$):$=e[13];const B=$;let F;e[14]!==n||e[15]!==y||e[16]!==d||e[17]!==g||e[18]!==T?(F=async se=>{if(y.trim()==="")return;d({running:!0});const ce=se==="explain"?`EXPLAIN QUERY PLAN ${y}`:y;try{const Ie=await n.query(Xn,{sql:ce},ke(T));d({chart:void 0,error:null,failed:void 0,pane:se,result:Ie,running:!1}),tt(T),g(ce)}catch(Ie){const Ae=Ie;d({chart:void 0,error:ze(Ae),failed:{error:ze(Ae),sql:ce},pane:se,result:null,running:!1})}},e[14]=n,e[15]=y,e[16]=d,e[17]=g,e[18]=T,e[19]=F):F=e[19];const P=F;let W;e[20]!==P?(W=()=>{de(P("results"))},e[20]=P,e[21]=W):W=e[21];const Q=W;let Y;e[22]!==s.pane||e[23]!==P?(Y=()=>{de(P(s.pane))},e[22]=s.pane,e[23]=P,e[24]=Y):Y=e[24];let J;e[25]!==_||e[26]!==O||e[27]!==E||e[28]!==Y?(J={onSubmit:Y,probe:_,schema:O,setDraft:E},e[25]=_,e[26]=O,e[27]=E,e[28]=Y,e[29]=J):J=e[29];const z=fn(J),{closeAutocomplete:G}=z;let ne;e[30]!==y||e[31]!==E?(ne=()=>{E(yt(y))},e[30]=y,e[31]=E,e[32]=ne):ne=e[32];const V=ne;let X;e[33]!==G||e[34]!==i?(X=se=>{G(),i(se)},e[33]=G,e[34]=i,e[35]=X):X=e[35];const Z=X;let ee;e[36]!==d?(ee=()=>{d({pane:"results"})},e[36]=d,e[37]=ee):ee=e[37];const te=ee;let oe;e[38]!==P?(oe=()=>{de(P("explain"))},e[38]=P,e[39]=oe):oe=e[39];const ie=oe;let H;e[40]!==d?(H=()=>{d({pane:"chart"})},e[40]=d,e[41]=H):H=e[41];const j=H;let U;e[42]!==L||e[43]!==C?(U=()=>{L(!C)},e[42]=L,e[43]=C,e[44]=U):U=e[44];const ae=U,xe=C?"flex min-h-0 flex-1 flex-row":"flex min-h-0 flex-1 flex-col",Re=C?"flex w-2/5 min-h-0 min-w-0 shrink-0 flex-col border-s border-border":"flex h-2/5 min-h-0 shrink-0 flex-col border-t border-border";let me;e[45]!==b||e[46]!==c.clearHistory||e[47]!==c.deleteQuery||e[48]!==c.history||e[49]!==c.listRef||e[50]!==c.loadFromHistory||e[51]!==c.loadTemplate||e[52]!==c.newQuery||e[53]!==c.onSearchChange||e[54]!==c.queries||e[55]!==c.search||e[56]!==c.selectQuery?(me=u(Fn,{activeId:b,history:c.history,listRef:c.listRef,onClearHistory:c.clearHistory,onDelete:c.deleteQuery,onLoadHistory:c.loadFromHistory,onLoadTemplate:c.loadTemplate,onNew:c.newQuery,onSearchChange:c.onSearchChange,onSelect:c.selectQuery,queries:c.queries,search:c.search}),e[45]=b,e[46]=c.clearHistory,e[47]=c.deleteQuery,e[48]=c.history,e[49]=c.listRef,e[50]=c.loadFromHistory,e[51]=c.loadTemplate,e[52]=c.newQuery,e[53]=c.onSearchChange,e[54]=c.queries,e[55]=c.search,e[56]=c.selectQuery,e[57]=me):me=e[57];let fe;e[58]!==r||e[59]!==Z?(fe=u(Vn,{model:r,onSelect:Z}),e[58]=r,e[59]=Z,e[60]=fe):fe=e[60];let he;e[61]!==D||e[62]!==M||e[63]!==y||e[64]!==N||e[65]!==E||e[66]!==z.autocompleteState||e[67]!==z.editorRef||e[68]!==z.gutterRef||e[69]!==z.handlers||e[70]!==z.listboxId||e[71]!==z.onPickSuggestion||e[72]!==z.overlayRef||e[73]!==z.revealDiagnostic?(he=u(Bn,{assistant:D,autocomplete:z.autocompleteState,diagnostics:M,draft:y,editorRef:z.editorRef,failed:N,gutterRef:z.gutterRef,handlers:z.handlers,listboxId:z.listboxId,onGenerated:E,onPickSuggestion:z.onPickSuggestion,onRevealDiagnostic:z.revealDiagnostic,overlayRef:z.overlayRef}),e[61]=D,e[62]=M,e[63]=y,e[64]=N,e[65]=E,e[66]=z.autocompleteState,e[67]=z.editorRef,e[68]=z.gutterRef,e[69]=z.handlers,e[70]=z.listboxId,e[71]=z.onPickSuggestion,e[72]=z.overlayRef,e[73]=z.revealDiagnostic,e[74]=he):he=e[74];let pe;e[75]!==D||e[76]!==w||e[77]!==V||e[78]!==B||e[79]!==m||e[80]!==Q||e[81]!==S||e[82]!==Re||e[83]!==k||e[84]!==T||e[85]!==j||e[86]!==ie||e[87]!==te||e[88]!==C||e[89]!==R||e[90]!==ae?(pe=u(Wn,{assistant:D,chart:m,className:Re,error:w,onFormat:V,onInferChart:B,onRun:Q,onShardKeyChange:I,onShowChart:j,onShowExplain:ie,onShowResults:te,onToggleSplit:ae,pane:R,result:S,running:k,shardKey:T,splitView:C}),e[75]=D,e[76]=w,e[77]=V,e[78]=B,e[79]=m,e[80]=Q,e[81]=S,e[82]=Re,e[83]=k,e[84]=T,e[85]=j,e[86]=ie,e[87]=te,e[88]=C,e[89]=R,e[90]=ae,e[91]=pe):pe=e[91];let be;e[92]!==he||e[93]!==pe||e[94]!==xe?(be=A("div",{className:xe,children:[he,pe]}),e[92]=he,e[93]=pe,e[94]=xe,e[95]=be):be=e[95];let ge;e[96]!==fe||e[97]!==be?(ge=A("div",{className:"flex min-w-0 flex-1 flex-col",children:[fe,be]}),e[96]=fe,e[97]=be,e[98]=ge):ge=e[98];let we;return e[99]!==me||e[100]!==ge?(we=A("div",{className:"flex h-full min-w-0","data-testid":"lunora-sql-editor",children:[me,ge]}),e[99]=me,e[100]=ge,e[101]=we):we=e[101],we};export{wo as SqlEditorPanel};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as G}from"react/compiler-runtime";import{useLunora as L}from"@lunora/react";import{useNavigate as Q,useRouter as q,useSearch as J}from"@tanstack/react-router";import{useState as N,useEffect as $}from"react";import{d as S}from"../packem_shared/storage-tier-DznqOf-q.js";import{i as K}from"../packem_shared/table-list-sidebar-
|
|
1
|
+
import{c as G}from"react/compiler-runtime";import{useLunora as L}from"@lunora/react";import{useNavigate as Q,useRouter as q,useSearch as J}from"@tanstack/react-router";import{useState as N,useEffect as $}from"react";import{d as S}from"../packem_shared/storage-tier-DznqOf-q.js";import{i as K}from"../packem_shared/table-list-sidebar-D9Bd4qgi.js";import{useT as P}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{s as _,d as B}from"../packem_shared/data-view-params-ClrV7XgF.js";import{f}from"../packem_shared/internal-BSIsQVC6.js";import{l as z,s as O}from"../packem_shared/browser-storage-xjTyMKY0.js";import{DataBrowser as R}from"../packem_shared/DataBrowser-CZZ_WkJ-.js";import{GlobalDataBrowser as H}from"../packem_shared/GlobalDataBrowser-DpkjHfDg.js";import{jsx as v,jsxs as C}from"react/jsx-runtime";const j="lunora-studio-saved-queries",I=50,M=r=>r!==null&&typeof r=="object"&&typeof r.name=="string"&&typeof r.view=="object"&&r.view!==null,w=()=>z(j).filter(M),k=r=>{O(j,r)},U=(r,e)=>{const l=r.trim();if(l==="")return w();const o=[{name:l,view:e},...w().filter(u=>u.name!==l)].slice(0,I);return k(o),o},W=r=>{const e=w().filter(l=>l.name!==r);return k(e),e},X=r=>{const e=G(15),{onChange:l,tier:o}=r,u=P();let d;e[0]!==l?(d=y=>{l(y.target.value)},e[0]=l,e[1]=d):d=e[1];const s=d;let h;e[2]!==u?(h=u("Storage tier"),e[2]=u,e[3]=h):h=e[3];let n;e[4]!==h?(n=v("span",{className:"font-mono text-[11px] tracking-wide uppercase text-muted-foreground",children:h}),e[4]=h,e[5]=n):n=e[5];const m=S[o];let i,g;e[6]===Symbol.for("react.memo_cache_sentinel")?(i=v("option",{value:"shard",children:S.shard.label}),g=v("option",{value:"global",children:S.global.label}),e[6]=i,e[7]=g):(i=e[6],g=e[7]);let c;e[8]!==s||e[9]!==m.title||e[10]!==o?(c=C("select",{className:"h-8 w-full rounded-md border border-border bg-background px-2 text-sm outline-none focus-visible:border-ring","data-testid":"table-editor-schema",id:"table-editor-schema",onChange:s,title:m.title,value:o,children:[i,g]}),e[8]=s,e[9]=m.title,e[10]=o,e[11]=c):c=e[11];let b;return e[12]!==n||e[13]!==c?(b=C("label",{className:"flex w-full flex-col gap-1",htmlFor:"table-editor-schema",children:[n,c]}),e[12]=n,e[13]=c,e[14]=b):b=e[14],b},Y=()=>{try{f(globalThis.navigator.clipboard.writeText(globalThis.location.href))}catch{}},me=({editable:r=!1,initialShardKey:e})=>{const l=L(),o=Q(),u=q(),d=J({strict:!1}),s=_(d),h=K(d),n=()=>u.state.location.pathname.split("/").findLast(Boolean)==="data",m=s.tier??"shard",i=s.table,[g,c]=N(()=>w()),[b,y]=N(()=>new Set);$(()=>{f((async()=>{try{const t=await l.listGlobalTables();y(new Set(t.map(a=>a.name)))}catch{}})())},[l]),$(()=>{m==="shard"&&i!==void 0&&b.has(i)&&f(o({replace:!0,search:t=>({...t,schema:"global"}),to:"/data"}))},[b,o,i,m]);const D=t=>{f(o({search:a=>({...a,schema:t==="global"?"global":void 0,table:void 0}),to:"/data"}))},T=(t,a)=>{n()&&f(o({search:p=>({schema:p.schema,search:a?.search,shard:p.shard,table:t}),to:"/data"}))},V=t=>{f(o({search:a=>({...a,schema:"global",table:t}),to:"/data"}))},A=t=>{const a=B(t),{current:p}=h;(p.filters??void 0)===a.filters&&(p.order??void 0)===a.order&&(p.search??void 0)===a.search&&(p.shard??void 0)===a.shard||!n()||f(o({replace:!0,search:F=>({...F,filters:a.filters,order:a.order,search:a.search,shard:a.shard}),to:"/data"}))},E={onApplyQuery:t=>{const a=B(t.view);f(o({search:()=>({filters:a.filters,order:a.order,schema:a.schema,search:a.search,shard:a.shard,table:a.table}),to:"/data"}))},onCopyLink:Y,onDeleteQuery:t=>{c(W(t))},onSaveQuery:(t,a)=>{c(U(t,a))},saved:g},x=v(X,{onChange:D,tier:m});return m==="global"?v(H,{initialTable:i,onSelectTable:T,schemaSwitch:x}):v(R,{editable:r,globalTableNames:b,initialFilters:s.filters,initialOrderBy:s.orderBy,initialPins:d.pins,initialSearch:s.search,initialShardKey:s.shard??e,onNavigateToGlobal:V,onSelectTable:T,onViewChange:A,queryBar:E,schemaSwitch:x,tableParam:i})};export{me as TableEditor};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useState as J}from"react";import{E as S}from"../packem_shared/error-alert-t6cpEi0z.js";import{g as C}from"../packem_shared/badge-BbuuAio7.js";import{u as j}from"../packem_shared/button-BkCrNcAs.js";import{c as I,u as K}from"../packem_shared/card-CIDGUN6K.js";import{E}from"../packem_shared/empty-state-Cg7t_8qu.js";import{n as q,d as U,m as g,p as o,f as _,u as i}from"../packem_shared/table-DdJBrClo.js";import{N as y}from"../packem_shared/use-admin-query-QJ-ibl5u.js";import{useT as R}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as N}from"../packem_shared/ADMIN_FUNCTIONS-
|
|
1
|
+
import{useState as J}from"react";import{E as S}from"../packem_shared/error-alert-t6cpEi0z.js";import{g as C}from"../packem_shared/badge-BbuuAio7.js";import{u as j}from"../packem_shared/button-BkCrNcAs.js";import{c as I,u as K}from"../packem_shared/card-CIDGUN6K.js";import{E}from"../packem_shared/empty-state-Cg7t_8qu.js";import{n as q,d as U,m as g,p as o,f as _,u as i}from"../packem_shared/table-DdJBrClo.js";import{N as y}from"../packem_shared/use-admin-query-QJ-ibl5u.js";import{useT as R}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as N}from"../packem_shared/ADMIN_FUNCTIONS-4aE59aDq.js";import{i as V}from"../packem_shared/internal-BSIsQVC6.js";import{jsx as e,jsxs as n}from"react/jsx-runtime";const M="agent_threads",W="agent_messages",X=100,Y=250,Z={},Q={filters:[],limit:X,offset:0,orderBy:{column:"updatedAt",direction:"desc"},skipCount:!0,table:M},d=(s,t)=>{const a=s[t];return typeof a=="string"?a:void 0},b=(s,t)=>{const a=s[t];return typeof a=="number"?a:void 0},z=s=>{const{usage:t}=s;if(t===null||typeof t!="object")return;const{totalTokens:a}=t;return typeof a=="number"?a:void 0},ee=s=>{const{toolCalls:t}=s;return Array.isArray(t)?t.map(a=>a!==null&&typeof a=="object"?a.name:void 0).filter(a=>typeof a=="string"):[]},te=s=>{switch(s){case"awaiting_input":return"warning";case"cancelled":return"warning";case"error":return"destructive";case"running":return"info";default:return"outline"}},ae=s=>{switch(s){case"approved":return"success";case"rejected":return"destructive";default:return"warning"}},pe=({initialShardKey:s=""})=>{const t=R(),[a,w]=J(void 0),{data:p}=y(N.listTables,Z,{live:!0,shardKey:s}),P=p!==void 0,m=Array.isArray(p)&&p.some(r=>r.name===M),{data:A,error:B,errorSource:D,liveError:L}=y(N.readTablePage,Q,{enabled:m,live:!0,shardKey:s}),O={filters:[{column:"threadKey",operator:"eq",value:a??""}],limit:Y,offset:0,orderBy:{column:"seq",direction:"asc"},skipCount:!0,table:W},{data:$,error:F,errorSource:G}=y(N.readTablePage,O,{enabled:m&&a!==void 0,live:!0,shardKey:s}),f=Array.isArray(A?.rows)?A.rows:[],k=Array.isArray($?.rows)?$.rows:[],T=f.find(r=>d(r,"key")===a);let u;return P&&!m?u=e(E,{description:t("No @lunora/agent tables found in this deployment. Add lunora/agents.ts with defineAgent(...) and merge the agent schema extension to run durable AI agents."),testId:"agents-unconfigured",title:t("No agents configured")}):m&&f.length===0?u=e(E,{description:t("No agent has run yet. Start a run with ctx.agents.<name>.run(...) and its thread appears here."),testId:"agents-empty",title:t("No agent threads yet")}):u=n("div",{className:"flex flex-col gap-6",children:[e(I,{className:"overflow-hidden py-0",children:e(K,{className:"px-0",children:n(q,{"data-testid":"agents-threads-table",children:[e(U,{children:n(g,{children:[e(o,{children:t("Agent")}),e(o,{children:t("Key")}),e(o,{children:t("Status")}),e(o,{children:t("Messages")}),e(o,{children:t("Tokens")}),e(o,{children:t("Updated")}),e(o,{"aria-label":t("Actions")})]})}),e(_,{children:f.map(r=>{const l=d(r,"key")??"",c=d(r,"status"),h=z(r);return n(g,{"data-active":l===a?"":void 0,"data-testid":`agents-thread-${l}`,children:[e(i,{className:"font-mono text-xs",children:d(r,"agent")??"—"}),e(i,{className:"font-mono text-xs text-muted-foreground",children:l}),e(i,{children:e(C,{"data-testid":`agents-thread-status-${l}`,variant:te(c),children:c??"—"})}),e(i,{className:"tabular-nums",children:b(r,"messageCount")??"—"}),e(i,{className:"tabular-nums text-muted-foreground",children:h??"—"}),e(i,{className:"text-muted-foreground tabular-nums",children:V(b(r,"updatedAt"),"—")}),e(i,{className:"text-right",children:e(j,{"data-testid":`agents-thread-open-${l}`,onClick:()=>{w(l)},size:"sm",type:"button",variant:"outline",children:t("Timeline")})})]},l)})})]})})}),F!==null&&e(S,{error:G,testId:"agents-messages-error"}),a!==void 0&&e(I,{className:"overflow-hidden py-0","data-testid":"agents-thread-detail",children:n(K,{className:"flex flex-col gap-3 px-4 py-3",children:[n("div",{className:"flex items-center justify-between gap-2",children:[n("span",{className:"font-mono text-xs",children:[t("Timeline")," · ",a,T!==void 0&&n("span",{className:"text-muted-foreground",children:[" · ",t("Usage"),": ",z(T)??0," ",t("Tokens")]})]}),e(j,{"data-testid":"agents-thread-detail-close",onClick:()=>{w(void 0)},size:"xs",type:"button",variant:"ghost",children:t("Close")})]}),k.length===0?e("p",{className:"text-xs text-muted-foreground",children:t("This thread has no messages yet.")}):n(q,{"data-testid":"agents-messages-table",children:[e(U,{children:n(g,{children:[e(o,{children:t("Role")}),e(o,{children:t("Content")}),e(o,{children:t("Tool")}),e(o,{children:t("Approval")})]})}),e(_,{children:k.map((r,l)=>{const c=d(r,"role")??"—",h=ee(r),H=d(r,"toolName"),x=d(r,"status"),v=b(r,"seq")??l;return n(g,{"data-testid":`agents-message-${String(v)}`,children:[e(i,{className:"font-mono text-xs align-top text-muted-foreground",children:c}),e(i,{className:"max-w-md font-mono text-xs whitespace-pre-wrap break-words",children:d(r,"content")??"—"}),e(i,{className:"font-mono text-xs align-top text-muted-foreground",children:H??(h.length>0?h.join(", "):"—")}),e(i,{className:"align-top",children:x===void 0?e("span",{className:"text-xs text-muted-foreground",children:"—"}):e(C,{"data-testid":`agents-message-approval-${String(v)}`,variant:ae(x),children:x})})]},d(r,"messageKey")??`${c}:${String(v)}`)})})]})]})})]}),n("div",{className:"flex flex-col gap-6","data-testid":"lunora-agents-panel",children:[B!==null&&e(S,{error:D,testId:"agents-error"}),e("p",{className:"text-sm text-muted-foreground",children:t("Agents run as durable workflows. Each run persists a thread of assistant and tool messages; select a thread to inspect its timeline, tool calls, approvals, and token usage.")}),L!==void 0&&e("p",{className:"text-xs text-amber-600 dark:text-amber-500","data-testid":"agents-live-error",role:"alert",children:t("Live updates unavailable; showing the last evaluation.")}),u]})};export{pe as AgentsPanel};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as P}from"react/compiler-runtime";import{useState as k}from"react";import{E as q}from"../packem_shared/error-alert-t6cpEi0z.js";import{g as _}from"../packem_shared/badge-BbuuAio7.js";import{u as z}from"../packem_shared/button-BkCrNcAs.js";import{c as D,u as H}from"../packem_shared/card-CIDGUN6K.js";import{E as M}from"../packem_shared/empty-state-Cg7t_8qu.js";import{u as O}from"../packem_shared/input-JHu63lTv.js";import{n as R,d as U,m as T,p as w,f as W,u as $}from"../packem_shared/table-DdJBrClo.js";import{N as B}from"../packem_shared/use-admin-query-QJ-ibl5u.js";import{useT as G}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as J}from"../packem_shared/ADMIN_FUNCTIONS-
|
|
1
|
+
import{c as P}from"react/compiler-runtime";import{useState as k}from"react";import{E as q}from"../packem_shared/error-alert-t6cpEi0z.js";import{g as _}from"../packem_shared/badge-BbuuAio7.js";import{u as z}from"../packem_shared/button-BkCrNcAs.js";import{c as D,u as H}from"../packem_shared/card-CIDGUN6K.js";import{E as M}from"../packem_shared/empty-state-Cg7t_8qu.js";import{u as O}from"../packem_shared/input-JHu63lTv.js";import{n as R,d as U,m as T,p as w,f as W,u as $}from"../packem_shared/table-DdJBrClo.js";import{N as B}from"../packem_shared/use-admin-query-QJ-ibl5u.js";import{useT as G}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as J}from"../packem_shared/ADMIN_FUNCTIONS-4aE59aDq.js";import{i as K}from"../packem_shared/internal-BSIsQVC6.js";import{jsx as r,jsxs as i}from"react/jsx-runtime";const ce=()=>{const e=P(39),t=G(),[l,j]=k("");let y;e[0]===Symbol.for("react.memo_cache_sentinel")?(y={},e[0]=y):y=e[0];const{data:b,error:s,errorSource:E,isLoading:S,refetch:A}=B(J.getAuthAuditLog,y);let C;if(e[1]!==b?.entries||e[2]!==l){const a=b?.entries??[],x=l.trim().toLowerCase();C=x===""?a:a.filter(N=>N.event.toLowerCase().includes(x)||(N.actorId??"").toLowerCase().includes(x)||(N.actorEmail??"").toLowerCase().includes(x)||(N.ip??"").toLowerCase().includes(x)||N.outcome.toLowerCase().includes(x)),e[1]=b?.entries,e[2]=l,e[3]=C}else C=e[3];const o=C;let I;e[4]===Symbol.for("react.memo_cache_sentinel")?(I=a=>{j(a.target.value)},e[4]=I):I=e[4];const F=I;let n;e[5]!==t?(n=t("Filter security events"),e[5]=t,e[6]=n):n=e[6];let c;e[7]!==t?(c=t("filter event, actor, IP"),e[7]=t,e[8]=c):c=e[8];let d;e[9]!==l||e[10]!==n||e[11]!==c?(d=r(O,{"aria-label":n,className:"h-8 w-56","data-testid":"aa-search",onChange:F,placeholder:c,value:l}),e[9]=l,e[10]=n,e[11]=c,e[12]=d):d=e[12];let m;e[13]!==A?(m=()=>{A()},e[13]=A,e[14]=m):m=e[14];let u;e[15]!==t?(u=t("Refresh"),e[15]=t,e[16]=u):u=e[16];let h;e[17]!==m||e[18]!==u?(h=r(z,{"data-testid":"aa-refresh",onClick:m,size:"xs",type:"button",variant:"ghost",children:u}),e[17]=m,e[18]=u,e[19]=h):h=e[19];let f;e[20]!==d||e[21]!==h?(f=i("div",{className:"flex flex-wrap items-center gap-2",children:[d,h]}),e[20]=d,e[21]=h,e[22]=f):f=e[22];let p;e[23]!==s||e[24]!==E?(p=s!==null&&r(q,{error:E,testId:"aa-error"}),e[23]=s,e[24]=E,e[25]=p):p=e[25];let g;e[26]!==s||e[27]!==o.length||e[28]!==S||e[29]!==t?(g=s===null&&!S&&o.length===0&&r(M,{description:t("Authentication and security events are recorded here."),testId:"aa-empty",title:t("No security events.")}),e[26]=s,e[27]=o.length,e[28]=S,e[29]=t,e[30]=g):g=e[30];let v;e[31]!==o||e[32]!==t?(v=o.length>0&&r(D,{className:"overflow-hidden py-0",children:r(H,{className:"max-h-[30rem] overflow-auto px-0",children:i(R,{"data-testid":"aa-table",children:[r(U,{children:i(T,{children:[r(w,{children:t("time")}),r(w,{children:t("event")}),r(w,{children:t("actor")}),r(w,{children:t("ip / user agent")}),r(w,{children:t("outcome")})]})}),r(W,{children:o.map(a=>i(T,{"data-testid":"aa-row",children:[r($,{className:"text-muted-foreground tabular-nums",children:K(a.ts,"—")}),r($,{children:r(_,{variant:"secondary",children:a.event})}),r($,{className:"max-w-[24ch] truncate font-mono text-xs",title:a.actorId??void 0,children:a.actorEmail??a.actorId??r("span",{className:"text-muted-foreground",children:"—"})}),i($,{className:"max-w-[28ch] truncate text-xs text-muted-foreground",title:a.userAgent??void 0,children:[a.ip??r("span",{className:"text-muted-foreground",children:"—"}),a.userAgent!==void 0&&i("span",{className:"ml-1 opacity-70",children:["· ",a.userAgent]})]}),r($,{children:r(_,{variant:a.outcome==="failure"?"destructive":"outline",children:t(a.outcome)})})]},a.seq))})]})})}),e[31]=o,e[32]=t,e[33]=v):v=e[33];let L;return e[34]!==p||e[35]!==g||e[36]!==v||e[37]!==f?(L=i("div",{className:"flex flex-col gap-4","data-testid":"lunora-auth-audit",children:[f,p,g,v]}),e[34]=p,e[35]=g,e[36]=v,e[37]=f,e[38]=L):L=e[38],L};export{ce as AuthAuditPanel};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as $}from"react/compiler-runtime";import{L as w}from"../packem_shared/live-status-CmuRLFKf.js";import{g as C}from"../packem_shared/badge-BbuuAio7.js";import{c as S,u as b}from"../packem_shared/card-CIDGUN6K.js";import{E}from"../packem_shared/empty-state-Cg7t_8qu.js";import{n as I,d as L,m as y,p as l,f as D,u as m}from"../packem_shared/table-DdJBrClo.js";import{N as k}from"../packem_shared/use-admin-query-QJ-ibl5u.js";import{useT as A}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as O}from"../packem_shared/ADMIN_FUNCTIONS-
|
|
1
|
+
import{c as $}from"react/compiler-runtime";import{L as w}from"../packem_shared/live-status-CmuRLFKf.js";import{g as C}from"../packem_shared/badge-BbuuAio7.js";import{c as S,u as b}from"../packem_shared/card-CIDGUN6K.js";import{E}from"../packem_shared/empty-state-Cg7t_8qu.js";import{n as I,d as L,m as y,p as l,f as D,u as m}from"../packem_shared/table-DdJBrClo.js";import{N as k}from"../packem_shared/use-admin-query-QJ-ibl5u.js";import{useT as A}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as O}from"../packem_shared/ADMIN_FUNCTIONS-4aE59aDq.js";import{jsx as n,jsxs as h}from"react/jsx-runtime";const N="container:",T={error:"error",sleep:"sleeping",start:"running",stop:"stopped"},_=e=>{const t=e.indexOf(":");if(t===-1)return{event:e.trim()};const r=e.slice(t+1).trim(),a=e.slice(0,t).trim();return r===""?{event:a}:{detail:r,event:a}},j=e=>{const t=new Map;for(const r of e){const a=r.functionPath??"";if(!a.startsWith(N))continue;const i=a.slice(N.length);if(i==="")continue;const s=JSON.stringify([i,r.instance??""]),o=t.get(s);if(o!==void 0&&o.timestamp>=r.timestamp)continue;const{detail:p,event:c}=_(r.message);t.set(s,{detail:p,event:c,exitCode:r.exitCode,instance:r.instance,level:r.level,name:i,state:T[c]??"unknown",timestamp:r.timestamp})}return[...t.values()].toSorted((r,a)=>r.name.localeCompare(a.name)||(r.instance??"").localeCompare(a.instance??""))},M={error:"destructive",running:"success",sleeping:"info",stopped:"outline",unknown:"secondary"},P=e=>{const{entries:t}=e??{};return Array.isArray(t)?t:[]},H=()=>{const e=$(19),t=A();let r,a;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={},a={live:!0,shardKey:""},e[0]=r,e[1]=a):(r=e[0],a=e[1]);const{data:i,error:s,liveError:o}=k(O.getLogs,r,a),p=i!==void 0;let c;if(e[2]!==i||e[3]!==s||e[4]!==o||e[5]!==p||e[6]!==t){const g=j(P(i));let x;e[8]!==s?(x=s!==null&&n("p",{className:"text-sm text-destructive","data-testid":"containers-error",role:"alert",children:s}),e[8]=s,e[9]=x):x=e[9];let d;e[10]!==t?(d=t("Cloudflare Containers are observed from their lifecycle log stream. This shows the current state per instance — ports and health checks aren't carried in that stream."),e[10]=t,e[11]=d):d=e[11];let u;e[12]!==d?(u=n("p",{className:"text-sm text-muted-foreground",children:d}),e[12]=d,e[13]=u):u=e[13];let f;e[14]!==o?(f=n(w,{message:o,prefix:"containers"}),e[14]=o,e[15]=f):f=e[15];let v;e[16]!==u||e[17]!==f?(v=h("div",{className:"flex flex-wrap items-center gap-2",children:[u,f]}),e[16]=u,e[17]=f,e[18]=v):v=e[18],c=h("div",{className:"flex flex-col gap-6","data-testid":"lunora-containers-panel",children:[x,v,p&&g.length===0?n(E,{description:t("No container lifecycle activity yet. Instances declared with defineContainer show up here once they start, sleep, stop, or error."),testId:"containers-empty",title:t("No container activity")}):n(S,{className:"overflow-hidden py-0",children:n(b,{className:"px-0",children:h(I,{"data-testid":"containers-table",children:[n(L,{children:h(y,{children:[n(l,{children:t("Container")}),n(l,{children:t("Instance")}),n(l,{children:t("State")}),n(l,{children:t("Last event")}),n(l,{children:t("Detail")}),n(l,{children:t("Exit")}),n(l,{children:t("When")})]})}),n(D,{children:g.map(W)})]})})})]}),e[2]=i,e[3]=s,e[4]=o,e[5]=p,e[6]=t,e[7]=c}else c=e[7];return c};function W(e){return h(y,{"data-testid":`containers-row-${e.name}${e.instance===void 0?"":`-${e.instance}`}`,children:[n(m,{className:"font-mono text-xs",children:e.name}),n(m,{className:"max-w-40 truncate font-mono text-xs text-muted-foreground",title:e.instance,children:e.instance??"—"}),n(m,{children:n(C,{variant:M[e.state],children:e.state})}),n(m,{className:"font-mono text-xs text-muted-foreground",children:e.event}),n(m,{className:"max-w-64 truncate text-xs text-muted-foreground",title:e.detail,children:e.detail??"—"}),n(m,{className:"font-mono text-xs tabular-nums text-muted-foreground",children:e.exitCode??"—"}),n(m,{className:"text-xs tabular-nums text-muted-foreground",children:new Date(e.timestamp).toLocaleString()})]},`${e.name}/${e.instance??""}`)}export{H as ContainersPanel};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as j}from"react/compiler-runtime";import{useState as z,useEffect as V}from"react";import{I as B}from"../packem_shared/result-chart-DzJOVsaw.js";import{A as D}from"../packem_shared/alert-CVcOFuDR.js";import{u as I}from"../packem_shared/button-BkCrNcAs.js";import{c as F,u as Q,f as U,n as Z}from"../packem_shared/card-CIDGUN6K.js";import{E as H}from"../packem_shared/empty-state-Cg7t_8qu.js";import{useT as T}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{u as J,n as P}from"../packem_shared/browser-storage-xjTyMKY0.js";import{useLunora as X}from"@lunora/react";import{ADMIN_FUNCTIONS as G}from"../packem_shared/ADMIN_FUNCTIONS-
|
|
1
|
+
import{c as j}from"react/compiler-runtime";import{useState as z,useEffect as V}from"react";import{I as B}from"../packem_shared/result-chart-DzJOVsaw.js";import{A as D}from"../packem_shared/alert-CVcOFuDR.js";import{u as I}from"../packem_shared/button-BkCrNcAs.js";import{c as F,u as Q,f as U,n as Z}from"../packem_shared/card-CIDGUN6K.js";import{E as H}from"../packem_shared/empty-state-Cg7t_8qu.js";import{useT as T}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{u as J,n as P}from"../packem_shared/browser-storage-xjTyMKY0.js";import{useLunora as X}from"@lunora/react";import{ADMIN_FUNCTIONS as G}from"../packem_shared/ADMIN_FUNCTIONS-4aE59aDq.js";import{d as Y,b as ee,f as te,g as le}from"../packem_shared/internal-BSIsQVC6.js";import{jsx as m,jsxs as _}from"react/jsx-runtime";const de=le(G.runSql),re=(A,e)=>{const t=j(11),c=X(),[l,d]=z(void 0),[s,r]=z(void 0),[a,$]=z(!0);let n;t[0]!==c||t[1]!==e||t[2]!==A?(n=async u=>{$(!0);try{const C=await c.query(de,{sql:A},Y(e));u.cancelled||(d(C),r(void 0))}catch(C){const E=C;u.cancelled||(d(void 0),r(ee(E)))}u.cancelled||$(!1)},t[0]=c,t[1]=e,t[2]=A,t[3]=n):n=t[3];const k=n;let y,S;t[4]!==k?(y=()=>{const u={cancelled:!1};return te(k(u)),()=>{u.cancelled=!0}},S=[k],t[4]=k,t[5]=y,t[6]=S):(y=t[5],S=t[6]),V(y,S);let h;return t[7]!==s||t[8]!==a||t[9]!==l?(h={error:s,loading:a,result:l},t[7]=s,t[8]=a,t[9]=l,t[10]=h):h=t[10],h},se="lunora-studio-dashboards",O={shardKey:"",sql:"",title:""},ie=A=>{const e=j(54),{onEdit:t,onRemove:c,widget:l}=A,d=T(),{error:s,loading:r,result:a}=re(l.sql,l.shardKey??"");let $;e[0]!==t||e[1]!==l.id?($=()=>{t(l.id)},e[0]=t,e[1]=l.id,e[2]=$):$=e[2];const n=$;let k;e[3]!==c||e[4]!==l.id?(k=()=>{c(l.id)},e[3]=c,e[4]=l.id,e[5]=k):k=e[5];const y=k,S=`dashboards-widget-${l.id}`;let h;e[6]!==l.title?(h=m(U,{className:"min-w-0 truncate",title:l.title,children:l.title}),e[6]=l.title,e[7]=h):h=e[7];let u;e[8]!==d?(u=d("Edit widget"),e[8]=d,e[9]=u):u=e[9];const C=`dashboards-widget-edit-${l.id}`;let E;e[10]!==d?(E=d("Edit widget"),e[10]=d,e[11]=E):E=e[11];let K;e[12]===Symbol.for("react.memo_cache_sentinel")?(K=m("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:m("path",{d:"M4 20h4L18 10l-4-4L4 16v4ZM14 6l4 4"})}),e[12]=K):K=e[12];let N;e[13]!==n||e[14]!==u||e[15]!==C||e[16]!==E?(N=m(I,{"aria-label":u,"data-testid":C,onClick:n,size:"icon-xs",title:E,type:"button",variant:"ghost",children:K}),e[13]=n,e[14]=u,e[15]=C,e[16]=E,e[17]=N):N=e[17];let x;e[18]!==d?(x=d("Remove widget"),e[18]=d,e[19]=x):x=e[19];const R=`dashboards-widget-remove-${l.id}`;let g;e[20]!==d?(g=d("Remove widget"),e[20]=d,e[21]=g):g=e[21];let w;e[22]===Symbol.for("react.memo_cache_sentinel")?(w=m("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:m("path",{d:"M5 7h14M9 7V5h6v2m-1 0v12H10V7M7 7v13h10V7"})}),e[22]=w):w=e[22];let f;e[23]!==y||e[24]!==x||e[25]!==R||e[26]!==g?(f=m(I,{"aria-label":x,"data-testid":R,onClick:y,size:"icon-xs",title:g,type:"button",variant:"ghost",children:w}),e[23]=y,e[24]=x,e[25]=R,e[26]=g,e[27]=f):f=e[27];let b;e[28]!==f||e[29]!==N?(b=_("div",{className:"flex shrink-0 items-center gap-1",children:[N,f]}),e[28]=f,e[29]=N,e[30]=b):b=e[30];let p;e[31]!==b||e[32]!==h?(p=_(Z,{className:"flex flex-row items-start justify-between gap-2 border-b pb-3",children:[h,b]}),e[31]=b,e[32]=h,e[33]=p):p=e[33];let v;e[34]!==s||e[35]!==l.id?(v=s!==void 0&&m(D,{className:"font-mono text-xs",testId:`dashboards-widget-error-${l.id}`,variant:"destructive",children:s}),e[34]=s,e[35]=l.id,e[36]=v):v=e[36];let L;e[37]!==s||e[38]!==r||e[39]!==a||e[40]!==d||e[41]!==l.id?(L=s===void 0&&r&&a===void 0&&m("p",{className:"p-4 text-sm text-muted-foreground","data-testid":`dashboards-widget-loading-${l.id}`,children:d("Running…")}),e[37]=s,e[38]=r,e[39]=a,e[40]=d,e[41]=l.id,e[42]=L):L=e[42];let i;e[43]!==s||e[44]!==a?(i=s===void 0&&a!==void 0&&m(B,{result:a}),e[43]=s,e[44]=a,e[45]=i):i=e[45];let o;e[46]!==v||e[47]!==L||e[48]!==i?(o=_(Q,{className:"min-h-32 py-2",children:[v,L,i]}),e[46]=v,e[47]=L,e[48]=i,e[49]=o):o=e[49];let q;return e[50]!==p||e[51]!==o||e[52]!==S?(q=_(F,{"data-testid":S,children:[p,o]}),e[50]=p,e[51]=o,e[52]=S,e[53]=q):q=e[53],q},ae=A=>{const e=j(58),{draft:t,editing:c,onCancel:l,onChange:d,onSubmit:s}=A,r=T();let a;e[0]!==t||e[1]!==d?(a=M=>{d({...t,title:M.target.value})},e[0]=t,e[1]=d,e[2]=a):a=e[2];const $=a;let n;e[3]!==t||e[4]!==d?(n=M=>{d({...t,sql:M.target.value})},e[3]=t,e[4]=d,e[5]=n):n=e[5];const k=n;let y;e[6]!==t||e[7]!==d?(y=M=>{d({...t,shardKey:M.target.value})},e[6]=t,e[7]=d,e[8]=y):y=e[8];const S=y;let h;e[9]!==s?(h=()=>{s()},e[9]=s,e[10]=h):h=e[10];const u=h;let C;e[11]!==t.sql||e[12]!==t.title?(C=t.title.trim()!==""&&t.sql.trim()!=="",e[11]=t.sql,e[12]=t.title,e[13]=C):C=e[13];const E=C;let K;e[14]!==r?(K=r("Widget title"),e[14]=r,e[15]=K):K=e[15];let N;e[16]!==r?(N=r("Widget title"),e[16]=r,e[17]=N):N=e[17];let x;e[18]!==t.title||e[19]!==$||e[20]!==K||e[21]!==N?(x=m("input",{"aria-label":K,className:"h-8 rounded-md border border-border bg-background px-2 text-xs outline-none focus-visible:border-ring","data-testid":"dashboards-form-title",onChange:$,placeholder:N,type:"text",value:t.title}),e[18]=t.title,e[19]=$,e[20]=K,e[21]=N,e[22]=x):x=e[22];let R;e[23]!==r?(R=r("SQL query"),e[23]=r,e[24]=R):R=e[24];let g;e[25]!==t.sql||e[26]!==k||e[27]!==R?(g=m("textarea",{"aria-label":R,className:"min-h-24 resize-y rounded-md border border-border bg-background p-2 font-mono text-xs leading-5 outline-none focus-visible:border-ring","data-testid":"dashboards-form-sql",onChange:k,placeholder:"SELECT author, COUNT(*) AS messages FROM …",spellCheck:!1,value:t.sql}),e[25]=t.sql,e[26]=k,e[27]=R,e[28]=g):g=e[28];let w;e[29]!==r?(w=r("Shard key (optional)"),e[29]=r,e[30]=w):w=e[30];let f;e[31]!==r?(f=r("Shard key (optional)"),e[31]=r,e[32]=f):f=e[32];let b;e[33]!==t.shardKey||e[34]!==S||e[35]!==w||e[36]!==f?(b=m("input",{"aria-label":w,className:"h-8 rounded-md border border-border bg-background px-2 font-mono text-xs outline-none focus-visible:border-ring","data-testid":"dashboards-form-shard",onChange:S,placeholder:f,type:"text",value:t.shardKey}),e[33]=t.shardKey,e[34]=S,e[35]=w,e[36]=f,e[37]=b):b=e[37];let p;e[38]!==r?(p=r("Cancel"),e[38]=r,e[39]=p):p=e[39];let v;e[40]!==l||e[41]!==p?(v=m(I,{"data-testid":"dashboards-form-cancel",onClick:l,size:"sm",type:"button",variant:"outline",children:p}),e[40]=l,e[41]=p,e[42]=v):v=e[42];const L=!E;let i;e[43]!==c||e[44]!==r?(i=r(c?"Save widget":"Add widget"),e[43]=c,e[44]=r,e[45]=i):i=e[45];let o;e[46]!==u||e[47]!==L||e[48]!==i?(o=m(I,{"data-testid":"dashboards-form-save",disabled:L,onClick:u,size:"sm",type:"button",children:i}),e[46]=u,e[47]=L,e[48]=i,e[49]=o):o=e[49];let q;e[50]!==v||e[51]!==o?(q=_("div",{className:"flex items-center justify-end gap-2",children:[v,o]}),e[50]=v,e[51]=o,e[52]=q):q=e[52];let W;return e[53]!==g||e[54]!==b||e[55]!==q||e[56]!==x?(W=m(F,{"data-testid":"dashboards-form",children:_(Q,{className:"flex flex-col gap-3 py-4",children:[x,g,b,q]})}),e[53]=g,e[54]=b,e[55]=q,e[56]=x,e[57]=W):W=e[57],W},we=A=>{const e=j(39),{initialShardKey:t}=A,c=T(),[l,d]=J(se),[s,r]=z(O),[a,$]=z(null),[n,k]=z(!1);let y;e[0]!==t?(y=()=>{$(null),r({...O,shardKey:t??""}),k(!0)},e[0]=t,e[1]=y):y=e[1];const S=y;let h;e[2]===Symbol.for("react.memo_cache_sentinel")?(h=()=>{k(!1),$(null),r(O)},e[2]=h):h=e[2];const u=h;let C;e[3]!==l?(C=i=>{const o=l.find(q=>q.id===i);o!==void 0&&($(i),r({shardKey:o.shardKey??"",sql:o.sql,title:o.title}),k(!0))},e[3]=l,e[4]=C):C=e[4];const E=C;let K;e[5]!==d?(K=i=>{d(o=>o.filter(q=>q.id!==i))},e[5]=d,e[6]=K):K=e[6];const N=K;let x;e[7]!==s.shardKey||e[8]!==s.sql||e[9]!==s.title||e[10]!==a||e[11]!==d?(x=()=>{const i=s.title.trim(),o=s.sql.trim();if(i===""||o==="")return;const q=s.shardKey.trim();d(a===null?W=>[...W,{id:P("w"),shardKey:q,sql:o,title:i}]:W=>W.map(M=>M.id===a?{...M,shardKey:q,sql:o,title:i}:M)),u()},e[7]=s.shardKey,e[8]=s.sql,e[9]=s.title,e[10]=a,e[11]=d,e[12]=x):x=e[12];const R=x;let g;e[13]!==c?(g=c("Chart widgets backed by saved read-only SQL queries."),e[13]=c,e[14]=g):g=e[14];let w;e[15]!==g?(w=m("p",{className:"text-sm text-muted-foreground",children:g}),e[15]=g,e[16]=w):w=e[16];let f;e[17]!==n||e[18]!==S||e[19]!==c?(f=!n&&m(I,{"data-testid":"dashboards-add",onClick:S,size:"sm",type:"button",children:c("Add widget")}),e[17]=n,e[18]=S,e[19]=c,e[20]=f):f=e[20];let b;e[21]!==w||e[22]!==f?(b=_("div",{className:"flex items-center justify-between",children:[w,f]}),e[21]=w,e[22]=f,e[23]=b):b=e[23];let p;e[24]!==s||e[25]!==a||e[26]!==n||e[27]!==R?(p=n&&m(ae,{draft:s,editing:a!==null,onCancel:u,onChange:r,onSubmit:R}),e[24]=s,e[25]=a,e[26]=n,e[27]=R,e[28]=p):p=e[28];let v;e[29]!==n||e[30]!==E||e[31]!==N||e[32]!==c||e[33]!==l?(v=l.length===0&&!n?m(H,{description:c("Add a widget to chart a saved SQL query on this browser."),testId:"dashboards-empty",title:c("No widgets yet")}):m("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-2 xl:grid-cols-3","data-testid":"dashboards-grid",children:l.map(i=>m(ie,{onEdit:E,onRemove:N,widget:i},i.id))}),e[29]=n,e[30]=E,e[31]=N,e[32]=c,e[33]=l,e[34]=v):v=e[34];let L;return e[35]!==p||e[36]!==v||e[37]!==b?(L=_("div",{className:"flex flex-col gap-4","data-testid":"lunora-dashboards",children:[b,p,v]}),e[35]=p,e[36]=v,e[37]=b,e[38]=L):L=e[38],L};export{we as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as
|
|
1
|
+
import{c as P}from"react/compiler-runtime";import{E as j}from"../packem_shared/error-alert-t6cpEi0z.js";import{ShardInput as A}from"../packem_shared/ShardInput-BVn2iCU0.js";import{g as R}from"../packem_shared/stat-card-fm_TF1mo.js";import{g as M}from"../packem_shared/badge-BbuuAio7.js";import{c as _}from"../packem_shared/card-CIDGUN6K.js";import{E as L}from"../packem_shared/empty-state-Cg7t_8qu.js";import{n as W,d as q,m as E,p as K,f as B,u as T}from"../packem_shared/table-DdJBrClo.js";import{N as H}from"../packem_shared/use-admin-query-QJ-ibl5u.js";import{useAutoRefresh as J}from"../packem_shared/DEFAULT_AUTO_REFRESH_MS-BCC8_4BQ.js";import{S as O}from"../packem_shared/use-shard-key-B2JtNa5m.js";import{useT as U}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as V}from"../packem_shared/ADMIN_FUNCTIONS-4aE59aDq.js";import{jsx as a,jsxs as x,Fragment as X}from"react/jsx-runtime";const D=n=>`${n.toString()} ms`,z=n=>n.totalConnections===0&&n.shapePoke.passes===0&&n.whisper.passes===0,F=n=>{const e=P(48),{counters:r,includeTiming:s,prefix:l,t:o,title:$}=n,v=`${l}-section`;let p;e[0]!==$?(p=a("h3",{className:"text-sm font-medium text-foreground",children:$}),e[0]=$,e[1]=p):p=e[1];const t=`${l}-stats`;let i;e[2]!==o?(i=o("Passes"),e[2]=o,e[3]=i):i=e[3];const I=`${l}-passes`;let b;e[4]!==r.passes||e[5]!==i||e[6]!==I?(b=a(R,{label:i,testId:I,value:r.passes}),e[4]=r.passes,e[5]=i,e[6]=I,e[7]=b):b=e[7];let f;e[8]!==o?(f=o("Sockets iterated"),e[8]=o,e[9]=f):f=e[9];const y=`${l}-iterated`;let c;e[10]!==r.socketsIterated||e[11]!==f||e[12]!==y?(c=a(R,{label:f,testId:y,value:r.socketsIterated}),e[10]=r.socketsIterated,e[11]=f,e[12]=y,e[13]=c):c=e[13];let d;e[14]!==o?(d=o("Delivered"),e[14]=o,e[15]=d):d=e[15];const g=`${l}-delivered`;let m;e[16]!==r.socketsDelivered||e[17]!==d||e[18]!==g?(m=a(R,{label:d,testId:g,value:r.socketsDelivered}),e[16]=r.socketsDelivered,e[17]=d,e[18]=g,e[19]=m):m=e[19];let u;e[20]!==o?(u=o("Peak width"),e[20]=o,e[21]=u):u=e[21];const k=`${l}-peak`;let h;e[22]!==r.peakSocketsIterated||e[23]!==u||e[24]!==k?(h=a(R,{label:u,testId:k,value:r.peakSocketsIterated}),e[22]=r.peakSocketsIterated,e[23]=u,e[24]=k,e[25]=h):h=e[25];let N;e[26]!==r.totalMs||e[27]!==s||e[28]!==l||e[29]!==o?(N=s&&a(R,{label:o("Total time"),testId:`${l}-total-ms`,value:D(r.totalMs)}),e[26]=r.totalMs,e[27]=s,e[28]=l,e[29]=o,e[30]=N):N=e[30];let S;e[31]!==r.maxMs||e[32]!==s||e[33]!==l||e[34]!==o?(S=s&&a(R,{label:o("Max time"),testId:`${l}-max-ms`,value:D(r.maxMs)}),e[31]=r.maxMs,e[32]=s,e[33]=l,e[34]=o,e[35]=S):S=e[35];let C;e[36]!==m||e[37]!==h||e[38]!==N||e[39]!==S||e[40]!==t||e[41]!==b||e[42]!==c?(C=x("dl",{className:"grid gap-3 sm:grid-cols-2 lg:grid-cols-3","data-testid":t,children:[b,c,m,h,N,S]}),e[36]=m,e[37]=h,e[38]=N,e[39]=S,e[40]=t,e[41]=b,e[42]=c,e[43]=C):C=e[43];let w;return e[44]!==v||e[45]!==C||e[46]!==p?(w=x("section",{className:"flex flex-col gap-2","data-testid":v,children:[p,C]}),e[44]=v,e[45]=C,e[46]=p,e[47]=w):w=e[47],w},me=n=>{const e=P(31),{initialShardKey:r}=n,s=U(),{queryShardKey:l,setShardKey:o,shardKey:$}=O(r);let v;e[0]===Symbol.for("react.memo_cache_sentinel")?(v={},e[0]=v):v=e[0];let p;e[1]!==l?(p={keepPreviousData:!0,shardKey:l},e[1]=l,e[2]=p):p=e[2];const{data:t,error:i,errorSource:I,refetch:b}=H(V.getFanoutMetrics,v,p);J(b,!0);let f;e[3]!==t?(f=t!==void 0&&z(t),e[3]=t,e[4]=f):f=e[4];const y=f;let c;e[5]!==o||e[6]!==$?(c=a(A,{onChange:o,testId:"fanout-shard-input",value:$}),e[5]=o,e[6]=$,e[7]=c):c=e[7];let d;e[8]!==t||e[9]!==s?(d=t!==void 0&&x("div",{className:"ml-auto flex items-center gap-2 text-sm text-muted-foreground","data-testid":"fanout-count",children:[t.promoted&&a(M,{"data-testid":"fanout-promoted",variant:t.relayCount>=t.maxRelays?"destructive":"default",children:t.relayCount>=t.maxRelays?s("auto-scaled: {relayCount}/{maxRelays} relays (at ceiling)",{maxRelays:t.maxRelays,relayCount:t.relayCount}):s("auto-scaled: {relayCount}/{maxRelays} relays",{maxRelays:t.maxRelays,relayCount:t.relayCount})}),a(M,{variant:"secondary",children:s("{count} connections",{count:t.totalConnections})}),a(M,{variant:"secondary",children:s("peak {count} subscribers",{count:t.peakSubscribers})})]}),e[8]=t,e[9]=s,e[10]=d):d=e[10];let g;e[11]!==c||e[12]!==d?(g=x("div",{className:"flex flex-wrap items-center gap-2",children:[c,d]}),e[11]=c,e[12]=d,e[13]=g):g=e[13];let m;e[14]!==i||e[15]!==I?(m=i!==null&&a(j,{error:I,testId:"fanout-error"}),e[14]=i,e[15]=I,e[16]=m):m=e[16];let u;e[17]!==i||e[18]!==y||e[19]!==s?(u=i===null&&y&&a(L,{description:s("Realtime fan-out cost and per-topic subscriber counts for this shard."),icon:a("svg",{"aria-hidden":"true",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.6,viewBox:"0 0 24 24",children:a("path",{d:"M4 12h4l3 7 4-14 3 7h2"})}),testId:"fanout-empty",title:s("No fan-out activity yet.")}),e[17]=i,e[18]=y,e[19]=s,e[20]=u):u=e[20];let k;e[21]!==i||e[22]!==y||e[23]!==t||e[24]!==s?(k=i===null&&t!==void 0&&!y&&x(X,{children:[t.topics.length>0&&x("section",{className:"flex flex-col gap-2","data-testid":"fanout-topics-section",children:[a("h3",{className:"text-sm font-medium text-foreground",children:s("Hot topics")}),a(_,{className:"overflow-hidden py-0",children:x(W,{"data-testid":"fanout-topics-table",children:[a(q,{children:x(E,{children:[a(K,{children:s("Topic")}),a(K,{children:s("Kind")}),a(K,{className:"text-right",children:s("Subscribers")})]})}),a(B,{children:t.topics.map(G)})]})})]}),x("section",{className:"flex flex-col gap-3","data-testid":"fanout-cost",children:[a("h2",{className:"text-sm font-medium text-muted-foreground",children:s("Fan-out cost since this instance woke")}),a(F,{counters:t.shapePoke,includeTiming:!0,prefix:"fanout-poke",t:s,title:s("Shape pokes")}),a(F,{counters:t.whisper,includeTiming:!1,prefix:"fanout-whisper",t:s,title:s("Whisper broadcasts")})]})]}),e[21]=i,e[22]=y,e[23]=t,e[24]=s,e[25]=k):k=e[25];let h;return e[26]!==g||e[27]!==m||e[28]!==u||e[29]!==k?(h=x("div",{className:"flex flex-col gap-4","data-testid":"fanout-panel",children:[g,m,u,k]}),e[26]=g,e[27]=m,e[28]=u,e[29]=k,e[30]=h):h=e[30],h};function G(n){return x(E,{"data-testid":"fanout-topic-row",children:[a(T,{className:"font-mono text-xs",children:n.topic}),a(T,{children:a(M,{variant:"outline",children:n.kind})}),a(T,{className:"text-right font-medium tabular-nums",children:n.subscribers})]},`${n.kind}:${n.topic}`)}export{me as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useState as $}from"react";import{E as k}from"../packem_shared/error-alert-t6cpEi0z.js";import{g as w}from"../packem_shared/badge-BbuuAio7.js";import{c as A,u as F}from"../packem_shared/card-CIDGUN6K.js";import{E as u}from"../packem_shared/empty-state-Cg7t_8qu.js";import{p as O}from"../packem_shared/label-6uP1obNF.js";import{n as T,d as C,m as p,p as l,f as j,u as n}from"../packem_shared/table-DdJBrClo.js";import{l as E}from"../packem_shared/textarea-Bu2-jKAs.js";import{N as I}from"../packem_shared/use-admin-query-QJ-ibl5u.js";import{useT as J}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as K}from"../packem_shared/ADMIN_FUNCTIONS-
|
|
1
|
+
import{useState as $}from"react";import{E as k}from"../packem_shared/error-alert-t6cpEi0z.js";import{g as w}from"../packem_shared/badge-BbuuAio7.js";import{c as A,u as F}from"../packem_shared/card-CIDGUN6K.js";import{E as u}from"../packem_shared/empty-state-Cg7t_8qu.js";import{p as O}from"../packem_shared/label-6uP1obNF.js";import{n as T,d as C,m as p,p as l,f as j,u as n}from"../packem_shared/table-DdJBrClo.js";import{l as E}from"../packem_shared/textarea-Bu2-jKAs.js";import{N as I}from"../packem_shared/use-admin-query-QJ-ibl5u.js";import{useT as J}from"../packem_shared/DEFAULT_LOCALE-BZ4NojpD.js";import{ADMIN_FUNCTIONS as K}from"../packem_shared/ADMIN_FUNCTIONS-4aE59aDq.js";import{jsx as e,jsxs as i}from"react/jsx-runtime";const L=a=>{const t=a.trim();if(t.length===0)return{context:void 0,error:null};try{const o=JSON.parse(t);return o===null||typeof o!="object"||Array.isArray(o)?{context:void 0,error:"Targeting context must be a JSON object."}:{context:o,error:null}}catch{return{context:void 0,error:"Targeting context is not valid JSON."}}},V='{ "targetingKey": "user-123", "plan": "premium" }',_=a=>a.type==="object"?JSON.stringify(a.value):String(a.value),X=({initialShardKey:a=""})=>{const t=J(),[o,h]=$(""),{context:c,error:f}=L(o),x=c===void 0?{}:{context:c},{data:s,error:v,errorSource:y,liveError:N}=I(K.listFlags,x,{live:!0,shardKey:a}),g=s!==void 0,b=s?.configured??!1,m=Array.isArray(s?.flags)?[...s.flags].toSorted((r,S)=>r.key.localeCompare(S.key)):[];let d;return g&&!b?d=e(u,{description:t("No @lunora/flags provider is wired in this deployment. Add lunora/flags.ts with defineFlags({ provider }) to gate code paths on feature flags."),testId:"flags-unconfigured",title:t("No flags provider configured")}):g&&m.length===0?d=e(u,{description:t('A flags provider is configured, but no handler reads a flag yet. Call ctx.flags.boolean("key", false) in a query, mutation, or action.'),testId:"flags-empty",title:t("No flags read")}):d=e(A,{className:"overflow-hidden py-0",children:e(F,{className:"px-0",children:i(T,{"data-testid":"flags-table",children:[e(C,{children:i(p,{children:[e(l,{children:t("Key")}),e(l,{children:t("Type")}),e(l,{children:t("Value")}),e(l,{children:t("Reason")}),e(l,{children:t("Variant")})]})}),e(j,{children:m.map(r=>i(p,{"data-testid":`flags-row-${r.key}`,children:[e(n,{className:"font-mono text-xs",children:r.key}),e(n,{className:"font-mono text-xs text-muted-foreground",children:r.type}),e(n,{className:"font-mono text-xs",children:_(r)}),e(n,{children:r.errorCode===void 0?e("span",{className:"font-mono text-xs text-muted-foreground",children:r.reason??"—"}):e(w,{"data-testid":`flags-error-${r.key}`,variant:"destructive",children:r.errorCode})}),e(n,{className:"font-mono text-xs text-muted-foreground",children:r.variant??"—"})]},r.key))})]})})}),i("div",{className:"flex flex-col gap-6","data-testid":"lunora-flags-panel",children:[v!==null&&e(k,{error:y,testId:"flags-error"}),e("p",{className:"text-sm text-muted-foreground",children:t('Feature flags are read in code with ctx.flags.<type>("key", default). They evaluate through the OpenFeature provider configured in lunora/flags.ts; edit the targeting context below to see how each flag resolves for a given audience.')}),i("div",{className:"flex flex-col gap-2",children:[e(O,{htmlFor:"flags-targeting-context",children:t("Targeting context (JSON)")}),e(E,{className:"font-mono text-xs","data-testid":"flags-context-input",id:"flags-targeting-context",onChange:r=>{h(r.target.value)},placeholder:V,rows:3,value:o}),f!==null&&e("p",{className:"text-xs text-destructive","data-testid":"flags-context-error",role:"alert",children:t(f)}),N!==void 0&&e("p",{className:"text-xs text-amber-600 dark:text-amber-500","data-testid":"flags-live-error",role:"alert",children:t("Live updates unavailable; showing the last evaluation.")})]}),d]})};export{X as FlagsPanel};
|