@lunora/studio 1.0.0-alpha.178 → 1.0.0-alpha.180

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/dist/index.d.mts +40 -1
  2. package/dist/index.d.ts +40 -1
  3. package/dist/index.mjs +1 -1
  4. package/dist/packem_chunks/FileBrowser.mjs +1 -1
  5. package/dist/packem_chunks/SqlEditorPanel.mjs +6 -6
  6. package/dist/packem_chunks/TableEditor.mjs +1 -1
  7. package/dist/packem_chunks/permissions-panel.mjs +1 -1
  8. package/dist/packem_chunks/queues-panel.mjs +1 -1
  9. package/dist/packem_shared/DataBrowser-BUFMFvNX.mjs +4 -0
  10. package/dist/packem_shared/DataFilters-Cocu-WWE.mjs +1 -0
  11. package/dist/packem_shared/grid-features-CE8kcqsK.mjs +6 -0
  12. package/dist/standalone/{chunk-2W365SXI.js → chunk-3PZNTIBM.js} +1 -1
  13. package/dist/standalone/{chunk-TXLWUHAU.js → chunk-3TXB4AKZ.js} +1 -1
  14. package/dist/standalone/{chunk-U7A2W7UG.js → chunk-4PRXEO3C.js} +1 -1
  15. package/dist/standalone/{chunk-P4V5VRUR.js → chunk-5B6TTEP6.js} +1 -1
  16. package/dist/standalone/{chunk-QCFJKKLX.js → chunk-5LZJ5JBB.js} +1 -1
  17. package/dist/standalone/{chunk-E366YQXO.js → chunk-5MKG6RW3.js} +1 -1
  18. package/dist/standalone/{chunk-PHYKYBCE.js → chunk-66Z7ZIZZ.js} +1 -1
  19. package/dist/standalone/{chunk-MOYNBJNW.js → chunk-A6S4TULR.js} +1 -1
  20. package/dist/standalone/{chunk-KIEUFC6E.js → chunk-A7EWHGFT.js} +1 -1
  21. package/dist/standalone/{chunk-ANXXWNJG.js → chunk-AFSPF2R4.js} +1 -1
  22. package/dist/standalone/{chunk-AKG3SL2Z.js → chunk-AODYDAXY.js} +1 -1
  23. package/dist/standalone/{chunk-NLHKRU3D.js → chunk-AULH6SZB.js} +1 -1
  24. package/dist/standalone/{chunk-YRZFU7OM.js → chunk-AX24JD2G.js} +1 -1
  25. package/dist/standalone/chunk-B3JY36UV.js +5 -0
  26. package/dist/standalone/chunk-B6RRRJP5.js +11 -0
  27. package/dist/standalone/{chunk-VR3OL4A6.js → chunk-BAAPQWFF.js} +1 -1
  28. package/dist/standalone/{chunk-I3OOVU3O.js → chunk-D4ZGY3II.js} +1 -1
  29. package/dist/standalone/{chunk-D7PVLNBP.js → chunk-DAD33Q2T.js} +1 -1
  30. package/dist/standalone/{chunk-ZTA7WN4R.js → chunk-DI34YDBW.js} +1 -1
  31. package/dist/standalone/{chunk-BR64TOG4.js → chunk-E2X625P3.js} +1 -1
  32. package/dist/standalone/{chunk-5PBVNSPQ.js → chunk-EBU3TTYR.js} +1 -1
  33. package/dist/standalone/{chunk-MWUR2KP6.js → chunk-FI6N7XWP.js} +1 -1
  34. package/dist/standalone/{chunk-IUKHT5XV.js → chunk-GAPFZFIL.js} +1 -1
  35. package/dist/standalone/{chunk-D2SSRZG5.js → chunk-GP2GJRJ3.js} +1 -1
  36. package/dist/standalone/{chunk-MNQSYFV6.js → chunk-GZ6GAFM2.js} +1 -1
  37. package/dist/standalone/chunk-GZAXFXZE.js +1 -0
  38. package/dist/standalone/{chunk-WV2AW6IT.js → chunk-H43JNQM6.js} +1 -1
  39. package/dist/standalone/{chunk-V5FOHTRB.js → chunk-HGT5U6GD.js} +1 -1
  40. package/dist/standalone/{chunk-P6F4CNT5.js → chunk-I6FR5UAK.js} +1 -1
  41. package/dist/standalone/{chunk-7HFDITXH.js → chunk-INXSZE5I.js} +1 -1
  42. package/dist/standalone/{chunk-FTR6JAWG.js → chunk-IP7YCJUN.js} +1 -1
  43. package/dist/standalone/{chunk-KZDIKRZ3.js → chunk-ITMXIPQ7.js} +1 -1
  44. package/dist/standalone/{chunk-M7QQYXU4.js → chunk-IXNOQYEE.js} +1 -1
  45. package/dist/standalone/{chunk-LKKZMIZK.js → chunk-JYT34NQM.js} +1 -1
  46. package/dist/standalone/{chunk-2NYASBOP.js → chunk-L2CWAQUO.js} +1 -1
  47. package/dist/standalone/{chunk-QY4V5UOY.js → chunk-M4POCI2J.js} +1 -1
  48. package/dist/standalone/{chunk-RSULZ5QU.js → chunk-MH2NGGUC.js} +1 -1
  49. package/dist/standalone/{chunk-WHPKXZN2.js → chunk-PGMASM2T.js} +1 -1
  50. package/dist/standalone/{chunk-2ADU5FA5.js → chunk-PZVVEPIN.js} +1 -1
  51. package/dist/standalone/{chunk-GDYRC6T6.js → chunk-QDHXQ56K.js} +1 -1
  52. package/dist/standalone/{chunk-KQMWK6QZ.js → chunk-QQ3CS3FX.js} +1 -1
  53. package/dist/standalone/chunk-QWJQUQY3.js +8 -0
  54. package/dist/standalone/{chunk-YK7JO7NP.js → chunk-RM4TNBYG.js} +1 -1
  55. package/dist/standalone/{chunk-MBP4SZYB.js → chunk-SDHFSBNM.js} +1 -1
  56. package/dist/standalone/{chunk-N2VWHDGA.js → chunk-SLI7DPVW.js} +1 -1
  57. package/dist/standalone/{chunk-CXGPKEDJ.js → chunk-TIIEZS24.js} +1 -1
  58. package/dist/standalone/{chunk-MOMBFDIA.js → chunk-TK6AEV4N.js} +1 -1
  59. package/dist/standalone/{chunk-U2YJ64UT.js → chunk-TTIBDOV6.js} +1 -1
  60. package/dist/standalone/{chunk-WX6MJS7P.js → chunk-V56XORNF.js} +1 -1
  61. package/dist/standalone/{chunk-IBM6X4XI.js → chunk-V7G6YTQ5.js} +1 -1
  62. package/dist/standalone/{chunk-U3T6FYYZ.js → chunk-VWXJAY7R.js} +1 -1
  63. package/dist/standalone/{chunk-6HVFOKP5.js → chunk-WD4WHTAV.js} +1 -1
  64. package/dist/standalone/{chunk-G22LSAIH.js → chunk-WIXX2VWE.js} +1 -1
  65. package/dist/standalone/{chunk-3JDH25N2.js → chunk-WRZTTZFV.js} +1 -1
  66. package/dist/standalone/{chunk-Y5IE2W4U.js → chunk-Y2I6GYEG.js} +1 -1
  67. package/dist/standalone/{chunk-I5V3IHPF.js → chunk-YONJDNSM.js} +1 -1
  68. package/dist/standalone/chunk-Z2XS4ZOO.js +1 -0
  69. package/dist/standalone/studio.js +1 -1
  70. package/package.json +5 -5
  71. package/dist/packem_shared/DataBrowser-B_zcf3a_.mjs +0 -4
  72. package/dist/packem_shared/DataFilters-3nbW0uax.mjs +0 -1
  73. package/dist/packem_shared/grid-features-Dl7bCGRN.mjs +0 -6
  74. package/dist/standalone/chunk-KYMUE3MZ.js +0 -5
  75. package/dist/standalone/chunk-RY66ZJJQ.js +0 -1
  76. package/dist/standalone/chunk-SA5SGD3V.js +0 -8
  77. package/dist/standalone/chunk-YAAM5IKA.js +0 -1
  78. package/dist/standalone/chunk-Z7WCKAUJ.js +0 -11
@@ -1,8 +1,8 @@
1
- import{c as Y}from"react/compiler-runtime";import{useLunora as Qe}from"@lunora/react";import{useState as ce,useMemo as Ke,useCallback as ht,useEffect as Ne,useRef as Ce,useId as pt}from"react";import{ADMIN_FUNCTIONS as _e}from"../packem_shared/ADMIN_FUNCTIONS-B8yyk5BX.mjs";import{u as We,n as et,b as Ue,r as Re,s as bt}from"../packem_shared/browser-storage-BH1MxLZs.mjs";import{d as qe,f as ue,c as Oe,b as gt}from"../packem_shared/internal-B6haJbiP.mjs";import{r as xt}from"../packem_shared/shard-history-CaO3C4KQ.mjs";import{u as vt}from"../packem_shared/use-sql-assistant-BhIMDQHV.mjs";import yt from"../packem_shared/useDebounced-DVeQ5-oW.mjs";import{useT as de}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.mjs";import{c as fe}from"../packem_shared/utils-bhneXptQ.mjs";import{jsxs as F,jsx as b,Fragment as He}from"react/jsx-runtime";import{I as St}from"../packem_shared/input-CXhxesPC.mjs";import{S as wt,a as Ct}from"../packem_shared/sql-result-table-C5y0jwaK.mjs";import{ShardInput as Nt}from"../packem_shared/ShardInput-C6mjgAh4.mjs";import{A as kt}from"../packem_shared/alert-PB5W11MM.mjs";import{E as Et}from"../packem_shared/grid-features-Dl7bCGRN.mjs";const Tt="x",Ge=" ",Rt={'"':'"',"'":"'","[":"]","`":"`"},tt=(l,e)=>{let n=e+2;for(;n<l.length&&l[n]!==`
1
+ import{c as Y}from"react/compiler-runtime";import{useLunora as Qe}from"@lunora/react";import{useState as ie,useMemo as Ke,useCallback as ht,useEffect as Ne,useRef as Ce,useId as pt}from"react";import{ADMIN_FUNCTIONS as qe}from"../packem_shared/ADMIN_FUNCTIONS-B8yyk5BX.mjs";import{u as Fe,n as et,b as ze,r as Re,s as bt}from"../packem_shared/browser-storage-BH1MxLZs.mjs";import{d as _e,f as ue,c as Oe,b as gt}from"../packem_shared/internal-B6haJbiP.mjs";import{r as xt}from"../packem_shared/shard-history-CaO3C4KQ.mjs";import{u as vt}from"../packem_shared/use-sql-assistant-BhIMDQHV.mjs";import yt from"../packem_shared/useDebounced-DVeQ5-oW.mjs";import{useT as de}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.mjs";import{c as fe}from"../packem_shared/utils-bhneXptQ.mjs";import{jsxs as W,jsx as b,Fragment as He}from"react/jsx-runtime";import{I as St}from"../packem_shared/input-CXhxesPC.mjs";import{S as wt,a as Ct}from"../packem_shared/sql-result-table-C5y0jwaK.mjs";import{ShardInput as Nt}from"../packem_shared/ShardInput-C6mjgAh4.mjs";import{A as kt}from"../packem_shared/alert-PB5W11MM.mjs";import{E as Et}from"../packem_shared/grid-features-CE8kcqsK.mjs";const Tt="x",Ge=" ",Rt={'"':'"',"'":"'","[":"]","`":"`"},tt=(l,e)=>{let n=e+2;for(;n<l.length&&l[n]!==`
2
2
  `;)n+=1;return n},nt=(l,e)=>{const n=l.indexOf("*/",e+2);return n===-1?-1:n+2},st=l=>{const e=l.split("");let n=0;for(;n<l.length;){const t=l[n]??"",o=Rt[t];if(t==="-"&&l[n+1]==="-"){const s=tt(l,n);e.fill(Ge,n,s),n=s}else if(t==="/"&&l[n+1]==="*"){const s=nt(l,n);if(s===-1)return;e.fill(Ge,n,s),n=s}else if(o!==void 0){let s=n+1;for(;s<l.length;)if(l[s]!==o)s+=1;else if(o!=="]"&&l[s+1]===o)s+=2;else break;if(s>=l.length)return;e.fill(Tt,n,s+1),n=s+1}else n+=1}for(let t=0;t<l.length;t+=1)l[t]===`
3
3
  `&&(e[t]=`
4
- `);return e.join("")},Lt=/^(?:explain\s+(?:query\s+plan\s+)?)?(?:select|with)\b/iu,It=/\b(?:alter|attach|create|delete|detach|drop|insert|pragma|reindex|truncate|update|vacuum)\b|\breplace\b(?!\s*\()/iu,qt=/^\w+/u,At=/;\s*$/u,_t=/\s/u,ot=l=>{let e=0;for(;e<l.length;){const n=l[e];if(n!==void 0&&_t.test(n))e+=1;else if(n==="-"&&l[e+1]==="-")e=tt(l,e);else if(n==="/"&&l[e+1]==="*"){const t=nt(l,e);if(t===-1)break;e=t}else break}return e},Ot=l=>{const e=ot(l),n=l.slice(e).trimEnd();if(n==="")return{code:"SQL_EMPTY",message:"the query is empty"};const o=(st(n)??n).replace(At,""),s=n.slice(0,o.length),r=o.indexOf(";");if(r!==-1)return{code:"SQL_MULTIPLE_STATEMENTS",length:1,message:"only a single statement may be run",offset:e+r};const i="the SQL editor is read-only — only SELECT / WITH / EXPLAIN queries are allowed";if(!Lt.test(s))return{code:"SQL_NOT_READONLY",length:qt.exec(s)?.[0].length??1,message:i,offset:e};const c=It.exec(s);if(c!==null)return{code:"SQL_NOT_READONLY",length:c[0].length,message:`${i} (\`${c[0].toUpperCase()}\` is not allowed)`,offset:e+c.index}},Dt=/^explain\b/iu,Mt=l=>Dt.test(l.slice(ot(l)))?l:`EXPLAIN QUERY PLAN ${l}`,Fe=(l,e)=>{const n=l.trim();if(n==="")return[];const t=e+l.indexOf(n),o=Ot(n);return o?.code==="SQL_EMPTY"?[]:[o===void 0?{offset:t,sql:n}:{offset:t,rejection:o,sql:n}]},lt=l=>{const e=st(l);if(e===void 0)return Fe(l,0);const n=[];let t=0;for(let o=0;o<=e.length;o+=1)o!==e.length&&e[o]!==";"||(n.push(...Fe(l.slice(t,o),t)),t=o+1);return n},$t=["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"],Ae=String.fromCodePoint(0),Ht=new RegExp(`${Ae}${String.raw`(\d+)`}${Ae}`,"gu"),Pt=$t.map(l=>({pattern:new RegExp(String.raw`\b${l.replaceAll(" ",String.raw`\s+`)}\b`,"giu"),replacement:l})),Wt=Bt.map(l=>({pattern:new RegExp(String.raw`\s+${l.replaceAll(" ",String.raw`\s+`)}\b`,"gu"),replacement:`
5
- ${l}`})),Ft=l=>{const e=[];let t=l.replaceAll(/'(?:[^']|'')*'/gu,o=>(e.push(o),`${Ae}${(e.length-1).toString()}${Ae}`)).replaceAll(/\s+/gu," ").trim();for(const{pattern:o,replacement:s}of Pt)t=t.replaceAll(o,s);for(const{pattern:o,replacement:s}of Wt)t=t.replaceAll(o,s);return t=t.replaceAll(Ht,(o,s)=>e[Number(s)]??""),t},Qt=/\b(?:from|join)\s+([a-z_][\w$]*)(?:\s+(?:as\s+)?([a-z_][\w$]*))?/giu,Ut=/(?:\bwith\s+(?:recursive\s+)?|,\s*)([a-z_][\w$]*)\s+as\s*\(/giu,jt=new Set(["cross","full","group","having","inner","join","left","limit","offset","on","order","right","union","using","where","window"]),zt=/[^\n]/gu,Yt=(l,e)=>{const n=l[e];if(n==="'"){let t=e+1;for(;t<l.length&&l[t]!=="'";)t+=1;return Math.min(t+1,l.length)}if(n==="-"&&l[e+1]==="-"){const t=l.indexOf(`
6
- `,e);return t===-1?l.length:t}if(n==="/"&&l[e+1]==="*"){const t=l.indexOf("*/",e+2);return t===-1?l.length:t+2}return-1},Kt=l=>{let e="",n=0;for(;n<l.length;){const t=Yt(l,n);t===-1?(e+=l.slice(n,n+1),n+=1):(e+=l.slice(n,t).replaceAll(zt," "),n=t)}return e},Gt=l=>{const e=new Set;for(const n of l.matchAll(Ut))e.add((n[1]??"").toLowerCase());return e},Jt=(l,e)=>{const n=new Map;for(const t of l.matchAll(Qt)){const o=(t[1]??"").toLowerCase(),s=(t[2]??"").toLowerCase();e.has(o)&&(n.set(o,o),s!==""&&!jt.has(s)&&n.set(s,o))}return n},rt=(l,e)=>{const n=Kt(l),t=new Set(e.map(o=>o.toLowerCase()));return{ctes:Gt(n),masked:n,targets:Jt(n,t)}},Vt=/^(?:__lunora|sqlite_)/iu,Xt=/\b(?:from|join)\s+([a-z_][\w$]*)/giu,Zt=/\b([a-z_][\w$]*)\.([a-z_][\w$]*)/giu,en=new Set(["cross","full","group","having","inner","join","lateral","left","limit","offset","order","right","select","union","where","window"]),tn=(l,e,n)=>{const t=[];for(const o of l.matchAll(Xt)){const s=o[1]??"",r=s.toLowerCase();!e.has(r)&&!n.has(r)&&!en.has(r)&&!Vt.test(s)&&t.push({length:s.length,message:`unknown table \`${s}\``,offset:o.index+o[0].length-s.length,severity:"error",source:"schema"})}return t},nn=(l,e,n)=>{const t=[],o=new Map;for(const[s,r]of Object.entries(e.columns))o.set(s.toLowerCase(),new Set(r.map(i=>i.toLowerCase())));for(const s of l.matchAll(Zt)){const r=(s[1]??"").toLowerCase(),i=s[2]??"",c=n.get(r),a=c===void 0?void 0:o.get(c);a!==void 0&&!a.has(i.toLowerCase())&&t.push({length:i.length,message:`\`${c??""}\` has no column \`${i}\``,offset:s.index+s[0].length-i.length,severity:"error",source:"schema"})}return t},sn=(l,e)=>{if(l.trim()==="")return[];const n=lt(l),t=new Set(e.tables.map(s=>s.toLowerCase())),o=[];for(const s of n){const{offset:r,rejection:i}=s;if(i!==void 0){o.push({length:i.length,message:i.message,offset:i.offset===void 0?r:r+i.offset,severity:"error",source:"gate"});continue}const{ctes:c,masked:a,targets:m}=rt(s.sql,e.tables);o.push(...[...tn(a,t,c),...nn(a,e,m)].map(g=>({...g,offset:g.offset===void 0?r:r+g.offset})))}return o},on=Oe(_e.lintSql),ln=600,rn=(l,e,n)=>{const t=Qe(),[o,s]=ce([]),r=Ke(()=>sn(l,e),[l,e]),i=yt(l,ln),a=r.some(f=>f.source==="gate")||i.trim()==="",m=ht(async f=>{try{const v=await t.query(on,{sql:i},qe(n));f.cancelled||s(v.diagnostics??[])}catch{f.cancelled||s([])}},[t,i,n]);Ne(()=>{if(a){s([]);return}const f={cancelled:!1};return ue(m(f)),()=>{f.cancelled=!0}},[m,a]);const g=i===l;return Ke(()=>g?[...r,...o]:r,[r,o,g])},Le=8,an=["AND","ASC","AS","BY","COUNT","DESC","DISTINCT","EXPLAIN","FROM","GROUP","HAVING","INNER","JOIN","LEFT","LIKE","LIMIT","NOT","NULL","OFFSET","ON","ORDER","OR","QUERY","SELECT","WHERE","WITH"],cn=new Set(["AND","BY","HAVING","ON","OR","SELECT","WHERE"]),dn=/[\w$]/,it=l=>l!==void 0&&dn.test(l),at=l=>{let e=l.length;for(;e>0&&it(l[e-1]);)e-=1;return l.slice(e)},ct=(l,e)=>{let n=e;for(;n>0&&it(l[n-1]);)n-=1;return{end:e,start:n,text:l.slice(n,e)}},Je=(l,e)=>{const n=l.slice(0,e).trimEnd();return n.endsWith(".")||cn.has(at(n).toUpperCase())},un=(l,e,n)=>{const t=l.slice(0,e);if(!t.endsWith("."))return;const o=at(t.slice(0,-1));if(o!=="")return rt(l,n).targets.get(o.toLowerCase())??o},je=(l,e)=>l.toLowerCase().startsWith(e.toLowerCase()),Ve=(l,e,n,t)=>{const o=[];for(const s of l)if(je(s,e)&&(o.push(t(s)),o.length>=n))break;return o},fn=(l,e,n)=>{const t=new Map;for(const[o,s]of Object.entries(l.columns))for(const r of s)if(je(r,e)&&!t.has(r)&&(t.set(r,o),t.size>=n))return[...t].map(([i,c])=>({detail:c,kind:"column",label:i}));return[...t].map(([o,s])=>({detail:s,kind:"column",label:o}))},mn=(l,e,n)=>{const t=ct(l,e),o=un(l,t.start,n.tables);if(o!==void 0){const a=n.columns[o]??n.columns[o.toLowerCase()]??[];return Ve(a,t.text,Le,m=>({detail:o,kind:"column",label:m}))}if(t.text===""&&!Je(l,t.start))return[];const s=Ve(n.tables,t.text,Le,a=>({kind:"table",label:a})),r=fn(n,t.text,Le),i=an.flatMap(a=>t.text!==""&&je(a,t.text)&&a.toLowerCase()!==t.text.toLowerCase()?[{kind:"keyword",label:a}]:[]);return(Je(l,t.start)?[...r,...s,...i]:[...s,...r,...i]).slice(0,Le)},hn=(l,e,n)=>{const t=ct(l,e),o=l.slice(0,t.start)+n.label+l.slice(t.end);return{caret:t.start+n.label.length,value:o}},pn=["boxSizing","borderBottomWidth","borderLeftWidth","borderRightWidth","borderTopWidth","fontFamily","fontSize","fontStyle","fontWeight","letterSpacing","lineHeight","paddingBottom","paddingLeft","paddingRight","paddingTop","tabSize","textIndent","textTransform","width","wordSpacing"],bn=(l,e)=>{const n=globalThis.getComputedStyle(l),t=globalThis.document.createElement("div"),{style:o}=t;o.position="absolute",o.visibility="hidden",o.whiteSpace="pre-wrap",o.overflowWrap="break-word";for(const c of pn)o[c]=n[c];t.textContent=l.value.slice(0,Math.max(0,e));const s=globalThis.document.createElement("span");s.textContent=l.value.slice(Math.max(0,e))||".",t.append(s),globalThis.document.body.append(t);const r=s.offsetLeft-l.scrollLeft,i=s.offsetTop-l.scrollTop;return t.remove(),{left:r,top:i}},gn=(l,e,n)=>{const t=Y(16),[o,s]=ce(null);let r;t[0]!==l||t[1]!==e?(r=(x,h)=>{const C=mn(x,h,l);if(C.length===0){s(null);return}const y=e.current,{left:p,top:k}=y===null?{left:0,top:0}:bn(y,h);s(N=>N!==null&&N.active===0&&N.left===p&&N.top===k&&N.suggestions.length===C.length&&N.suggestions.every((T,q)=>{const E=C.at(q);return T.kind===E?.kind&&T.label===E.label&&T.detail===E.detail})?N:{active:0,left:p,suggestions:C,top:k})},t[0]=l,t[1]=e,t[2]=r):r=t[2];const i=r;let c;t[3]===Symbol.for("react.memo_cache_sentinel")?(c=()=>{s(null)},t[3]=c):c=t[3];const a=c;let m;t[4]===Symbol.for("react.memo_cache_sentinel")?(m=x=>{s(h=>{if(h===null)return h;const C=h.suggestions.length,y=(h.active+x+C)%C;return{...h,active:y}})},t[4]=m):m=t[4];const g=m;let f;t[5]!==n||t[6]!==o||t[7]!==e?(f=x=>{const h=e.current;if(o===null||h===null)return!1;const C=o.suggestions[x??o.active];if(C===void 0)return!1;const y=hn(h.value,h.selectionStart,C);return n(y.value),s(null),requestAnimationFrame(()=>{const p=e.current;p!==null&&(p.focus(),p.setSelectionRange(y.caret,y.caret))}),!0},t[5]=n,t[6]=o,t[7]=e,t[8]=f):f=t[8];const v=f;let d;t[9]!==v?(d=()=>v(),t[9]=v,t[10]=d):d=t[10];const S=d;let u;return t[11]!==S||t[12]!==v||t[13]!==i||t[14]!==o?(u={close:a,commit:S,commitAt:v,move:g,refresh:i,state:o},t[11]=S,t[12]=v,t[13]=i,t[14]=o,t[15]=u):u=t[15],u},xn={column:"column",keyword:"keyword",table:"table"},vn=20,yn=l=>{const e=Y(17),{listboxId:n,onPick:t,state:o}=l,s=de();let r;e[0]!==o?(r=o===null?void 0:{left:o.left,top:o.top+vn},e[0]=o,e[1]=r):r=e[1];const i=r;if(o===null)return null;let c;if(e[2]!==n||e[3]!==t||e[4]!==o.active||e[5]!==o.suggestions||e[6]!==s){let m;e[8]!==n||e[9]!==t||e[10]!==o.active||e[11]!==s?(m=(g,f)=>F("li",{"aria-selected":f===o.active,className:fe("flex cursor-pointer items-center gap-2 px-2 py-1 text-[13px]",f===o.active?"bg-accent text-accent-foreground":"text-foreground"),"data-testid":"sql-autocomplete-item",id:`${n}-opt-${f.toString()}`,onMouseDown:v=>{v.preventDefault(),t(f)},role:"option",children:[b("span",{className:"truncate font-mono",children:g.label}),g.detail!==void 0&&b("span",{className:"ms-auto truncate text-xs text-muted-foreground",children:g.detail}),b("span",{className:"shrink-0 font-mono text-[10px] tracking-wide text-muted-foreground/70 uppercase",children:s(xn[g.kind])})]},`${g.kind}:${g.label}`),e[8]=n,e[9]=t,e[10]=o.active,e[11]=s,e[12]=m):m=e[12],c=o.suggestions.map(m),e[2]=n,e[3]=t,e[4]=o.active,e[5]=o.suggestions,e[6]=s,e[7]=c}else c=e[7];let a;return e[13]!==n||e[14]!==i||e[15]!==c?(a=b("ul",{className:"absolute z-30 max-h-56 w-72 overflow-auto rounded-md border border-border bg-popover py-1 text-popover-foreground shadow-md","data-testid":"sql-autocomplete",id:n,role:"listbox",style:i,children:c}),e[13]=n,e[14]=i,e[15]=c,e[16]=a):a=e[16],a},Sn=Oe(_e.listTables),wn=Oe(_e.readTablePage),Cn=l=>{const e=Y(16),n=Qe();let t;e[0]===Symbol.for("react.memo_cache_sentinel")?(t=[],e[0]=t):t=e[0];const[o,s]=ce(t);let r;e[1]===Symbol.for("react.memo_cache_sentinel")?(r={},e[1]=r):r=e[1];const[i,c]=ce(r);let a;e[2]===Symbol.for("react.memo_cache_sentinel")?(a=new Set,e[2]=a):a=e[2];const m=Ce(a);let g,f;e[3]!==n||e[4]!==l?(g=()=>{const h={cancelled:!1};return ue((async()=>{try{const y=await n.query(Sn,{},qe(l));h.cancelled||(s(y.map(kn)),c({}),m.current=new Set)}catch{h.cancelled||(s([]),c({}),m.current=new Set)}})()),()=>{h.cancelled=!0}},f=[n,l],e[3]=n,e[4]=l,e[5]=g,e[6]=f):(g=e[5],f=e[6]),Ne(g,f);let v;e[7]!==n||e[8]!==l?(v=h=>{if(m.current.has(h))return;m.current.add(h),ue((async()=>{try{const y=await n.query(wn,{limit:1,offset:0,table:h},qe(l));c(p=>({...p,[h]:y.columns}))}catch{m.current.delete(h)}})())},e[7]=n,e[8]=l,e[9]=v):v=e[9];const d=v;let S;e[10]!==i||e[11]!==o?(S={columns:i,tables:o},e[10]=i,e[11]=o,e[12]=S):S=e[12];const u=S;let x;return e[13]!==d||e[14]!==u?(x={probe:d,schema:u},e[13]=d,e[14]=u,e[15]=x):x=e[15],x},Pe=/\b(?:from|join|update|into)\s+([a-z_][\w$]*)|\b([a-z_][\w$]*)\s*\./gi,Nn=l=>{const e=new Set;Pe.lastIndex=0;let n=Pe.exec(l);for(;n!==null;)e.add(n[1]??n[2]),n=Pe.exec(l);return[...e]};function kn(l){return l.name}const En=l=>{const e=Y(34),{onSubmit:n,probe:t,schema:o,setDraft:s}=l,r=pt(),i=Ce(null),c=Ce(null),a=Ce(null),m=gn(o,a,s),{close:g,commit:f,commitAt:v,move:d,refresh:S,state:u}=m;let x;e[0]!==v?(x=w=>{v(w)},e[0]=v,e[1]=x):x=e[1];const h=x;let C;e[2]!==S?(C=()=>{const w=a.current;w!==null&&w===document.activeElement&&S(w.value,w.selectionStart)},e[2]=S,e[3]=C):C=e[3];let y;e[4]!==S||e[5]!==o?(y=[S,o],e[4]=S,e[5]=o,e[6]=y):y=e[6],Ne(C,y);let p;e[7]!==t||e[8]!==S||e[9]!==s?(p=w=>{const{selectionStart:W,value:R}=w.target;s(R);for(const M of Nn(R))t(M);S(R,W)},e[7]=t,e[8]=S,e[9]=s,e[10]=p):p=e[10];const k=p;let N;e[11]!==S?(N=w=>{const W=w.currentTarget;S(W.value,W.selectionStart)},e[11]=S,e[12]=N):N=e[12];const L=N;let T;e[13]!==u||e[14]!==g||e[15]!==f||e[16]!==d||e[17]!==n?(T=w=>{if(u!==null){if(w.key==="ArrowDown"){w.preventDefault(),d(1);return}if(w.key==="ArrowUp"){w.preventDefault(),d(-1);return}if(w.key==="Escape"){w.preventDefault(),g();return}if((w.key==="Enter"||w.key==="Tab")&&!w.metaKey&&!w.ctrlKey&&f()){w.preventDefault();return}}(w.metaKey||w.ctrlKey)&&w.key==="Enter"&&(w.preventDefault(),n())},e[13]=u,e[14]=g,e[15]=f,e[16]=d,e[17]=n,e[18]=T):T=e[18];const q=T;let E;e[19]!==g?(E=()=>{requestAnimationFrame(()=>{g()})},e[19]=g,e[20]=E):E=e[20];const A=E;let _;e[21]===Symbol.for("react.memo_cache_sentinel")?(_=w=>{const{scrollLeft:W,scrollTop:R}=w.currentTarget;i.current!==null&&(i.current.scrollTop=R),c.current!==null&&(c.current.scrollTop=R,c.current.scrollLeft=W)},e[21]=_):_=e[21];const I=_;let B;e[22]===Symbol.for("react.memo_cache_sentinel")?(B=w=>{const W=a.current;W===null||w.offset===void 0||(W.focus(),W.setSelectionRange(w.offset,w.offset+(w.length??0)))},e[22]=B):B=e[22];const D=B;let P;e[23]!==k||e[24]!==A||e[25]!==q||e[26]!==L?(P={onBlur:A,onChange:k,onKeyDown:q,onScroll:I,onSelect:L},e[23]=k,e[24]=A,e[25]=q,e[26]=L,e[27]=P):P=e[27];let O;return e[28]!==u||e[29]!==g||e[30]!==r||e[31]!==h||e[32]!==P?(O={autocompleteState:u,closeAutocomplete:g,handlers:P,listboxId:r,onPickSuggestion:h,editorRef:a,gutterRef:i,overlayRef:c,revealDiagnostic:D},e[28]=u,e[29]=g,e[30]=r,e[31]=h,e[32]=P,e[33]=O):O=e[33],O},Tn="lunora-studio-sql-tabs",Rn="lunora-studio-sql-active-tab",ze=12,we=(l="",e="")=>({activeId:null,id:et("tab"),name:e,sql:l}),Ln=()=>Ue(Rn,""),In=l=>{const e=Y(16),[n,t]=We(Tn),[o,s]=Ln(),[r]=ce(l);let i,c;e[0]!==r||e[1]!==t||e[2]!==n.length?(i=()=>{n.length===0&&t([r])},c=[r,t,n.length],e[0]=r,e[1]=t,e[2]=n.length,e[3]=i,e[4]=c):(i=e[3],c=e[4]),Ne(i,c);let a;e[5]!==r||e[6]!==n?(a=n.length===0?[r]:n,e[5]=r,e[6]=n,e[7]=a):a=e[7];const m=a;let g;e[8]!==o||e[9]!==m?(g=m.some(d=>d.id===o)?o:m[0]?.id??"",e[8]=o,e[9]=m,e[10]=g):g=e[10];const f=g;let v;return e[11]!==f||e[12]!==s||e[13]!==t||e[14]!==m?(v={activeId:f,setActiveId:s,setTabs:t,tabs:m},e[11]=f,e[12]=s,e[13]=t,e[14]=m,e[15]=v):v=e[15],v},dt=l=>l.activeId===null&&l.sql.trim()!=="",qn=(l,e)=>[...l,e].slice(-ze),An=(l,e,n)=>{const t=l.findIndex(r=>r.id===e);if(t===-1)return{activeId:l[0]?.id??"",tabs:[...l]};const o=l.filter(r=>r.id!==e);if(o.length===0){const r=n();return{activeId:r.id,tabs:[r]}}return{activeId:o[Math.min(t,o.length-1)].id,tabs:o}},_n=(l,e)=>{const n=l.filter(t=>t.id===e);return n.length===0?{activeId:l[0]?.id??"",tabs:[...l]}:{activeId:e,tabs:n}},On=(l,e,n)=>{const t=l.findIndex(s=>s.id===e);if(t===-1)return{activeId:n,tabs:[...l]};const o=l.slice(0,t+1);return{activeId:o.some(s=>s.id===n)?n:e,tabs:o}},Dn=l=>{const e=l();return{activeId:e.id,tabs:[e]}},Mn=(l,e,n)=>{if(l==="others")return e.filter(t=>t.id!==n);if(l==="right"){const t=e.findIndex(o=>o.id===n);return t===-1?[]:e.slice(t+1)}return[...e]},Xe={error:null,pane:"results",result:null,running:!1},$n=l=>{const e=Y(66),{activeId:n,setActiveId:t,setTabs:o,tabs:s}=In(l);let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={},e[0]=r):r=e[0];const[i,c]=ce(r),[a,m]=ce(null),[g,f]=ce(null);let v;e[1]!==n||e[2]!==s?(v=s.find(H=>H.id===n)??s[0]??we(),e[1]=n,e[2]=s,e[3]=v):v=e[3];const d=v,S=i[d.id]??Xe;let u;e[4]!==d.id||e[5]!==o?(u=H=>{o(j=>j.map(z=>z.id===d.id?{...z,...H}:z))},e[4]=d.id,e[5]=o,e[6]=u):u=e[6];const x=u;let h;e[7]!==d.id?(h=H=>{c(j=>{const z=j[d.id]??Xe;return{...j,[d.id]:{...z,...H}}})},e[7]=d.id,e[8]=h):h=e[8];const C=h;let y;e[9]!==t||e[10]!==o||e[11]!==s.length?(y=()=>{if(s.length>=ze)return;const H=we();o(j=>qn(j,H)),t(H.id)},e[9]=t,e[10]=o,e[11]=s.length,e[12]=y):y=e[12];const p=y;let k;e[13]!==t||e[14]!==o?(k=H=>{m(null),f(null),o(H.tabs),t(H.activeId);const j=new Set(H.tabs.map(Bn));c(z=>Object.fromEntries(Object.entries(z).filter(J=>{const[me]=J;return j.has(me)})))},e[13]=t,e[14]=o,e[15]=k):k=e[15];const N=k;let L;e[16]!==N||e[17]!==s?(L=H=>{N(An(s,H,we))},e[16]=N,e[17]=s,e[18]=L):L=e[18];const T=L;let q;e[19]!==n||e[20]!==N||e[21]!==s?(q=(H,j)=>{N(H==="others"?_n(s,j):H==="right"?On(s,j,n):Dn(we))},e[19]=n,e[20]=N,e[21]=s,e[22]=q):q=e[22];const E=q;let A;e[23]!==E||e[24]!==a||e[25]!==s?(A=H=>{a!==null&&(Mn(H,s,a.id).some(Hn)?f(H):E(H,a.id))},e[23]=E,e[24]=a,e[25]=s,e[26]=A):A=e[26];const _=A;let I;e[27]===Symbol.for("react.memo_cache_sentinel")?(I=(H,j)=>{j.preventDefault(),f(null),m({id:H,x:j.clientX,y:j.clientY})},e[27]=I):I=e[27];const B=I;let D;e[28]===Symbol.for("react.memo_cache_sentinel")?(D=()=>{m(null),f(null)},e[28]=D):D=e[28];const P=D;let O;e[29]===Symbol.for("react.memo_cache_sentinel")?(O=H=>{H.preventDefault(),m(null),f(null)},e[29]=O):O=e[29];const w=O;let W;e[30]!==_?(W=()=>{_("others")},e[30]=_,e[31]=W):W=e[31];const R=W;let M;e[32]!==_?(M=()=>{_("right")},e[32]=_,e[33]=M):M=e[33];const U=M;let $;e[34]!==_?($=()=>{_("all")},e[34]=_,e[35]=$):$=e[35];const X=$;let Z;e[36]!==E||e[37]!==g||e[38]!==a?(Z=()=>{a!==null&&g!==null&&E(g,a.id),f(null)},e[36]=E,e[37]=g,e[38]=a,e[39]=Z):Z=e[39];const ee=Z;let te;e[40]===Symbol.for("react.memo_cache_sentinel")?(te=()=>{f(null)},e[40]=te):te=e[40];const ie=te;let G;e[41]!==a?(G=a===null?void 0:{left:a.x,top:a.y},e[41]=a,e[42]=G):G=e[42];const Q=G;let ne;e[43]!==o?(ne=H=>{o(j=>j.map(z=>z.activeId===H?{...z,activeId:null}:z))},e[43]=o,e[44]=ne):ne=e[44];const se=ne;let oe;e[45]!==o?(oe=(H,j)=>{o(z=>z.map(J=>J.id===H?{...J,name:j}:J))},e[45]=o,e[46]=oe):oe=e[46];const le=oe;let re;return e[47]!==d||e[48]!==n||e[49]!==p||e[50]!==T||e[51]!==ee||e[52]!==X||e[53]!==R||e[54]!==U||e[55]!==S||e[56]!==C||e[57]!==x||e[58]!==g||e[59]!==le||e[60]!==t||e[61]!==a||e[62]!==Q||e[63]!==s||e[64]!==se?(re={activeTab:d,activeTabId:n,addEditorTab:p,cancelBulk:ie,closeEditorTab:T,closeTabMenu:P,confirmBulk:ee,menuStyle:Q,onBackdropContextMenu:w,onCloseAll:X,onCloseOthers:R,onCloseToRight:U,openTabMenu:B,output:S,patchActiveOutput:C,patchActiveTab:x,pendingBulk:g,renameTab:le,setActiveTabId:t,tabMenu:a,tabs:s,unlinkQuery:se},e[47]=d,e[48]=n,e[49]=p,e[50]=T,e[51]=ee,e[52]=X,e[53]=R,e[54]=U,e[55]=S,e[56]=C,e[57]=x,e[58]=g,e[59]=le,e[60]=t,e[61]=a,e[62]=Q,e[63]=s,e[64]=se,e[65]=re):re=e[65],re};function Bn(l){return l.id}function Hn(l){return dt(l)}const Pn="lunora-studio-sql-queries",Se="lunora-studio-sql-history",Wn="lunora-studio-sql-remember-history",Fn=25,Qn=l=>{const e=Y(41),{loadIntoActiveTab:n,unlinkQuery:t}=l,o=de(),[s,r]=We(Pn),[i,c]=Ue(Wn,!1),[a,m]=We(Se,i?"local":"session");let g,f;e[0]!==i?(g=()=>{i||Re(Se,"local")},f=[i],e[0]=i,e[1]=g,e[2]=f):(g=e[1],f=e[2]),Ne(g,f);const[v,d]=ce(""),S=Ce(null);let u;e[3]!==m?(u=R=>{m(M=>M[0]?.sql===R?M:[{at:Date.now(),sql:R},...M.filter($=>$.sql!==R)].slice(0,Fn))},e[3]=m,e[4]=u):u=e[4];const x=u;let h;e[5]!==n||e[6]!==r||e[7]!==o?(h=()=>{const R={id:et("q"),name:o("Untitled query"),sql:""};r(M=>[R,...M]),n("",R.id)},e[5]=n,e[6]=r,e[7]=o,e[8]=h):h=e[8];const C=h;let y;e[9]!==n||e[10]!==s?(y=R=>{const M=s.find(U=>U.id===R);M!==void 0&&(n(M.sql,R),S.current?.querySelector(`[data-testid="sql-query-${R}"]`)?.scrollIntoView({block:"nearest"}))},e[9]=n,e[10]=s,e[11]=y):y=e[11];const p=y;let k;e[12]!==r||e[13]!==t?(k=R=>{r(M=>M.filter(U=>U.id!==R)),t(R)},e[12]=r,e[13]=t,e[14]=k):k=e[14];const N=k;let L;e[15]!==n?(L=R=>{n(R.currentTarget.dataset.sql??"",null)},e[15]=n,e[16]=L):L=e[16];const T=L;let q;e[17]!==n?(q=R=>{n(R.currentTarget.dataset.sql??"",null)},e[17]=n,e[18]=q):q=e[18];const E=q;let A;e[19]!==m?(A=()=>{m([]),Re(Se,"local"),Re(Se,"session")},e[19]=m,e[20]=A):A=e[20];const _=A;let I;e[21]!==a||e[22]!==c?(I=R=>{bt(Se,a,R?"local":"session"),R||Re(Se,"local"),c(R)},e[21]=a,e[22]=c,e[23]=I):I=e[23];const B=I;let D;e[24]===Symbol.for("react.memo_cache_sentinel")?(D=R=>{d(R.target.value)},e[24]=D):D=e[24];const P=D;let O;e[25]!==r?(O=(R,M)=>{r(U=>U.map($=>$.id===R?{...$,sql:M}:$))},e[25]=r,e[26]=O):O=e[26];const w=O;let W;return e[27]!==_||e[28]!==N||e[29]!==a||e[30]!==E||e[31]!==T||e[32]!==C||e[33]!==s||e[34]!==x||e[35]!==i||e[36]!==v||e[37]!==p||e[38]!==B||e[39]!==w?(W={clearHistory:_,deleteQuery:N,history:a,listRef:S,loadFromHistory:E,loadTemplate:T,newQuery:C,onSearchChange:P,queries:s,recordHistory:x,rememberHistory:i,search:v,selectQuery:p,setRememberHistory:B,updateQuerySql:w},e[27]=_,e[28]=N,e[29]=a,e[30]=E,e[31]=T,e[32]=C,e[33]=s,e[34]=x,e[35]=i,e[36]=v,e[37]=p,e[38]=B,e[39]=w,e[40]=W):W=e[40],W},ut="p-3 font-mono text-xs leading-5 whitespace-pre-wrap break-words",Un=(l,e)=>{const n=[];for(const o of l){if(o.offset===void 0||o.length===void 0||o.length<=0)continue;const s=Math.max(0,Math.min(o.offset,e)),r=Math.max(s,Math.min(o.offset+o.length,e));s!==r&&n.push({end:r,severity:o.severity,start:s})}n.sort((o,s)=>o.start-s.start);const t=[];for(const o of n)o.start>=(t.at(-1)?.end??0)&&t.push(o);return t},jn=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.",zn=l=>{const e=Y(51),{assistant:n,failed:t,onGenerated:o}=l,s=de(),[r,i]=ce("");if(n.unavailable)return null;let c;e[0]!==n?(c=n.pending("sql"),e[0]=n,e[1]=c):c=e[1];const a=c;let m;if(e[2]!==n||e[3]!==t||e[4]!==o||e[5]!==a||e[6]!==r||e[7]!==s){const g=n.reason("sql");let f;e[9]!==n||e[10]!==t||e[11]!==o||e[12]!==r?(f=E=>{const A=r.trim();if(A===""&&!E)return;ue((async()=>{const I=await n.generate(A===""?"fix the failing statement":A,E?t:void 0);I!==void 0&&o(I)})())},e[9]=n,e[10]=t,e[11]=o,e[12]=r,e[13]=f):f=e[13];const v=f;let d;e[14]!==s?(d=s("Describe the query you want"),e[14]=s,e[15]=d):d=e[15];let S;e[16]===Symbol.for("react.memo_cache_sentinel")?(S=E=>{i(E.target.value)},e[16]=S):S=e[16];let u;e[17]!==v?(u=E=>{E.key==="Enter"&&(E.preventDefault(),v(!1))},e[17]=v,e[18]=u):u=e[18];let x;e[19]!==s?(x=s("Describe the query you want"),e[19]=s,e[20]=x):x=e[20];let h;e[21]!==a||e[22]!==r||e[23]!==d||e[24]!==u||e[25]!==x?(h=b(St,{"aria-label":d,className:"h-7 flex-1 text-xs","data-testid":"sql-assistant-prompt",disabled:a,onChange:S,onKeyDown:u,placeholder:x,value:r}),e[21]=a,e[22]=r,e[23]=d,e[24]=u,e[25]=x,e[26]=h):h=e[26];const C=a&&"opacity-60";let y;e[27]!==C?(y=fe("rounded-md border border-border px-2 py-1 text-xs outline-none transition-colors hover:bg-accent focus-visible:bg-accent",C),e[27]=C,e[28]=y):y=e[28];let p;e[29]!==a||e[30]!==r?(p=a||r.trim()==="",e[29]=a,e[30]=r,e[31]=p):p=e[31];let k;e[32]!==v?(k=()=>{v(!1)},e[32]=v,e[33]=k):k=e[33];let N;e[34]!==a||e[35]!==s?(N=s(a?"Thinking…":"Draft SQL"),e[34]=a,e[35]=s,e[36]=N):N=e[36];let L;e[37]!==y||e[38]!==p||e[39]!==k||e[40]!==N?(L=b("button",{className:y,"data-testid":"sql-assistant-generate",disabled:p,onClick:k,type:"button",children:N}),e[37]=y,e[38]=p,e[39]=k,e[40]=N,e[41]=L):L=e[41];let T;e[42]!==t||e[43]!==a||e[44]!==v||e[45]!==s?(T=t!==void 0&&b("button",{className:"rounded-md border border-border px-2 py-1 text-xs outline-none transition-colors hover:bg-accent focus-visible:bg-accent","data-testid":"sql-assistant-fix",disabled:a,onClick:()=>{v(!0)},type:"button",children:s("Fix this")}),e[42]=t,e[43]=a,e[44]=v,e[45]=s,e[46]=T):T=e[46];let q;e[47]!==L||e[48]!==T||e[49]!==h?(q=F("div",{className:"flex items-center gap-2",children:[h,L,T]}),e[47]=L,e[48]=T,e[49]=h,e[50]=q):q=e[50],m=F("div",{className:"flex flex-col gap-1 border-b border-border px-3 py-2","data-testid":"sql-assistant",children:[q,g!==void 0&&b("p",{className:"text-[11px] text-muted-foreground","data-testid":"sql-assistant-reason",role:"status",children:jn(g)})]}),e[2]=n,e[3]=t,e[4]=o,e[5]=a,e[6]=r,e[7]=s,e[8]=m}else m=e[8];return m},Yn=l=>{const e=Y(8),{diagnostics:n,draft:t,scrollRef:o}=l;let s,r;if(e[0]!==n||e[1]!==t){r=Symbol.for("react.early_return_sentinel");e:{const a=Un(n,t.length);if(a.length===0){r=null;break e}s=[];let m=0;for(const[g,f]of a.entries())f.start>m&&s.push(t.slice(m,f.start)),s.push(b("span",{className:fe("decoration-wavy underline underline-offset-4",f.severity==="error"?"decoration-destructive":"decoration-amber-500"),children:t.slice(f.start,f.end)},`${f.start.toString()}-${g.toString()}`)),m=f.end;s.push(t.slice(m))}e[0]=n,e[1]=t,e[2]=s,e[3]=r}else s=e[2],r=e[3];if(r!==Symbol.for("react.early_return_sentinel"))return r;let i;e[4]===Symbol.for("react.memo_cache_sentinel")?(i=fe("pointer-events-none absolute inset-0 overflow-hidden text-transparent",ut),e[4]=i):i=e[4];let c;return e[5]!==s||e[6]!==o?(c=b("div",{"aria-hidden":"true",className:i,"data-testid":"sql-diagnostics-overlay",ref:o,children:s}),e[5]=s,e[6]=o,e[7]=c):c=e[7],c},Kn={gate:"read-only",plan:"plan",schema:"schema",syntax:"syntax"},Gn=l=>{const e=Y(10),{diagnostics:n,onSelect:t}=l,o=de();if(n.length===0)return null;let s;e[0]!==o?(s=o("SQL problems"),e[0]=o,e[1]=s):s=e[1];let r;if(e[2]!==n||e[3]!==t){let c;e[5]!==t?(c=(a,m)=>b("li",{children:F("button",{className:"flex w-full items-start gap-2 px-3 py-1 text-start text-xs outline-none hover:bg-accent focus-visible:bg-accent","data-testid":"sql-problem",onClick:()=>{t(a)},type:"button",children:[b("span",{className:fe("mt-px shrink-0 rounded px-1 font-mono text-[10px] uppercase",a.severity==="error"?"bg-destructive/15 text-destructive":"bg-amber-500/15 text-amber-600"),children:Kn[a.source]}),b("span",{className:"min-w-0 text-muted-foreground",children:a.message})]})},`${a.source}-${(a.offset??m).toString()}-${m.toString()}`),e[5]=t,e[6]=c):c=e[6],r=n.map(c),e[2]=n,e[3]=t,e[4]=r}else r=e[4];let i;return e[7]!==s||e[8]!==r?(i=b("ul",{"aria-label":s,className:"max-h-24 shrink-0 overflow-y-auto border-t border-border bg-muted/30","data-testid":"sql-problems",children:r}),e[7]=s,e[8]=r,e[9]=i):i=e[9],i},Jn={minWidth:"2.75rem",paddingInline:"0.5rem"},Vn=l=>{const e=Y(64),{assistant:n,autocomplete:t,diagnostics:o,draft:s,failed:r,handlers:i,editorRef:c,gutterRef:a,listboxId:m,onGenerated:g,onPickSuggestion:f,onRevealDiagnostic:v,overlayRef:d}=l,S=de();let u,x,h,C,y,p,k,N;if(e[0]!==n||e[1]!==s||e[2]!==r||e[3]!==a||e[4]!==g){const W=s.split(`
7
- `).length;k="flex min-h-0 min-w-0 flex-1 flex-col",e[13]!==n||e[14]!==r||e[15]!==g?(N=b(zn,{assistant:n,failed:r,onGenerated:g}),e[13]=n,e[14]=r,e[15]=g,e[16]=N):N=e[16],p="flex min-h-0 min-w-0 flex-1",u="true",x="shrink-0 select-none overflow-hidden border-e border-border bg-muted/30 py-3 text-end font-mono text-xs leading-5 text-muted-foreground/60",h=a,C=Jn,y=Array.from({length:W},Xn),e[0]=n,e[1]=s,e[2]=r,e[3]=a,e[4]=g,e[5]=u,e[6]=x,e[7]=h,e[8]=C,e[9]=y,e[10]=p,e[11]=k,e[12]=N}else u=e[5],x=e[6],h=e[7],C=e[8],y=e[9],p=e[10],k=e[11],N=e[12];let L;e[17]!==u||e[18]!==x||e[19]!==h||e[20]!==C||e[21]!==y?(L=b("div",{"aria-hidden":u,className:x,ref:h,style:C,children:y}),e[17]=u,e[18]=x,e[19]=h,e[20]=C,e[21]=y,e[22]=L):L=e[22];let T;e[23]!==o||e[24]!==s||e[25]!==d?(T=b(Yn,{diagnostics:o,draft:s,scrollRef:d}),e[23]=o,e[24]=s,e[25]=d,e[26]=T):T=e[26];let q;e[27]!==t||e[28]!==m?(q=t===null?void 0:`${m}-opt-${t.active.toString()}`,e[27]=t,e[28]=m,e[29]=q):q=e[29];const E=t===null?void 0:m,A=t!==null;let _;e[30]!==S?(_=S("SQL query"),e[30]=S,e[31]=_):_=e[31];let I;e[32]!==s||e[33]!==c||e[34]!==i.onBlur||e[35]!==i.onChange||e[36]!==i.onKeyDown||e[37]!==i.onScroll||e[38]!==i.onSelect||e[39]!==q||e[40]!==E||e[41]!==A||e[42]!==_?(I=b("textarea",{"aria-activedescendant":q,"aria-autocomplete":"list","aria-controls":E,"aria-expanded":A,"aria-label":_,className:`relative size-full resize-none bg-transparent outline-none ${ut}`,"data-testid":"sql-input",onBlur:i.onBlur,onChange:i.onChange,onKeyDown:i.onKeyDown,onScroll:i.onScroll,onSelect:i.onSelect,placeholder:"SELECT * FROM …",ref:c,role:"combobox",spellCheck:!1,value:s}),e[32]=s,e[33]=c,e[34]=i.onBlur,e[35]=i.onChange,e[36]=i.onKeyDown,e[37]=i.onScroll,e[38]=i.onSelect,e[39]=q,e[40]=E,e[41]=A,e[42]=_,e[43]=I):I=e[43];let B;e[44]!==t||e[45]!==m||e[46]!==f?(B=b(yn,{listboxId:m,onPick:f,state:t}),e[44]=t,e[45]=m,e[46]=f,e[47]=B):B=e[47];let D;e[48]!==T||e[49]!==I||e[50]!==B?(D=F("div",{className:"relative min-w-0 flex-1 bg-background",children:[T,I,B]}),e[48]=T,e[49]=I,e[50]=B,e[51]=D):D=e[51];let P;e[52]!==D||e[53]!==p||e[54]!==L?(P=F("div",{className:p,children:[L,D]}),e[52]=D,e[53]=p,e[54]=L,e[55]=P):P=e[55];let O;e[56]!==o||e[57]!==v?(O=b(Gn,{diagnostics:o,onSelect:v}),e[56]=o,e[57]=v,e[58]=O):O=e[58];let w;return e[59]!==P||e[60]!==O||e[61]!==k||e[62]!==N?(w=F("div",{className:k,children:[N,P,O]}),e[59]=P,e[60]=O,e[61]=k,e[62]=N,e[63]=w):w=e[63],w};function Xn(l,e){return b("div",{children:e+1},e)}const ft=[{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;"}],Zn=l=>{const e=Y(29),{active:n,onDelete:t,onSelect:o,query:s}=l,r=de();let i;e[0]!==o||e[1]!==s.id?(i=()=>{o(s.id)},e[0]=o,e[1]=s.id,e[2]=i):i=e[2];const c=i;let a;e[3]!==t||e[4]!==s.id?(a=k=>{k.stopPropagation(),t(s.id)},e[3]=t,e[4]=s.id,e[5]=a):a=e[5];const m=a,g=n?"bg-sidebar-accent font-medium text-foreground":"text-muted-foreground";let f;e[6]!==g?(f=fe("flex min-w-0 flex-1 items-center gap-2 rounded-md px-2 py-1.5 text-start text-[13px] outline-none transition-colors hover:bg-sidebar-accent focus-visible:bg-sidebar-accent",g),e[6]=g,e[7]=f):f=e[7];const v=`sql-query-${s.id}`;let d;e[8]===Symbol.for("react.memo_cache_sentinel")?(d=b("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:b("path",{d:"M4 6h16M4 12h10M4 18h7"})}),e[8]=d):d=e[8];let S;e[9]!==s.name?(S=b("span",{className:"truncate",children:s.name}),e[9]=s.name,e[10]=S):S=e[10];let u;e[11]!==n||e[12]!==c||e[13]!==f||e[14]!==v||e[15]!==S?(u=F("button",{"aria-pressed":n,className:f,"data-testid":v,onClick:c,type:"button",children:[d,S]}),e[11]=n,e[12]=c,e[13]=f,e[14]=v,e[15]=S,e[16]=u):u=e[16];let x;e[17]!==r?(x=r("Delete query"),e[17]=r,e[18]=x):x=e[18];let h;e[19]!==r?(h=r("Delete query"),e[19]=r,e[20]=h):h=e[20];let C;e[21]===Symbol.for("react.memo_cache_sentinel")?(C=b("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:b("path",{d:"M5 7h14M9 7V5h6v2m-1 0v12H10V7M7 7v13h10V7"})}),e[21]=C):C=e[21];let y;e[22]!==m||e[23]!==h||e[24]!==x?(y=b("button",{"aria-label":x,className:"me-1 hidden size-6 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-destructive/10 hover:text-destructive group-hover/q:flex",onClick:m,title:h,type:"button",children:C}),e[22]=m,e[23]=h,e[24]=x,e[25]=y):y=e[25];let p;return e[26]!==y||e[27]!==u?(p=F("li",{className:"group/q flex items-center",children:[u,y]}),e[26]=y,e[27]=u,e[28]=p):p=e[28],p},Ze="sql-history-remember",es=(l,e)=>{const n=e.trim().toLowerCase();return n===""?[...l]:l.filter(t=>t.name.toLowerCase().includes(n))},ts=l=>{const e=Y(66),{activeId:n,history:t,listRef:o,onClearHistory:s,onDelete:r,onLoadHistory:i,onLoadTemplate:c,onNew:a,onSearchChange:m,onSelect:g,onToggleRememberHistory:f,queries:v,rememberHistory:d,search:S}=l,u=de();let x,h,C,y,p;if(e[0]!==n||e[1]!==o||e[2]!==r||e[3]!==a||e[4]!==m||e[5]!==g||e[6]!==f||e[7]!==v||e[8]!==S||e[9]!==u){const I=es(v,S);let B;e[15]!==f?(B=$=>{f($.target.checked)},e[15]=f,e[16]=B):B=e[16],x=B,C="flex h-full w-64 shrink-0 flex-col border-e border-border bg-sidebar";let D;e[17]!==u?(D=u("Search queries…"),e[17]=u,e[18]=D):D=e[18];let P;e[19]!==m||e[20]!==S||e[21]!==D?(P=b("input",{className:"h-8 min-w-0 flex-1 rounded-md border border-border bg-background px-2 text-xs outline-none focus-visible:border-ring","data-testid":"sql-search",onChange:m,placeholder:D,type:"text",value:S}),e[19]=m,e[20]=S,e[21]=D,e[22]=P):P=e[22];let O;e[23]!==u?(O=u("New query"),e[23]=u,e[24]=O):O=e[24];let w;e[25]!==u?(w=u("New query"),e[25]=u,e[26]=w):w=e[26];let W;e[27]===Symbol.for("react.memo_cache_sentinel")?(W=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:b("path",{d:"M12 5v14M5 12h14"})}),e[27]=W):W=e[27];let R;e[28]!==a||e[29]!==O||e[30]!==w?(R=b("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:a,title:w,type:"button",children:W}),e[28]=a,e[29]=O,e[30]=w,e[31]=R):R=e[31],e[32]!==R||e[33]!==P?(y=F("div",{className:"flex shrink-0 items-center gap-2 border-b border-border p-2",children:[P,R]}),e[32]=R,e[33]=P,e[34]=y):y=e[34],h="flex flex-1 flex-col gap-4 overflow-y-auto p-2";let M;e[35]!==u?(M=u("Private"),e[35]=u,e[36]=M):M=e[36];let U;e[37]!==M?(U=b("p",{className:"px-1 pb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:M}),e[37]=M,e[38]=U):U=e[38],p=F("div",{children:[U,I.length===0?b("p",{className:"px-1 py-2 text-xs text-muted-foreground","data-testid":"sql-private-empty",children:u("No saved queries yet — they save to this browser as you type.")}):b("ul",{className:"flex flex-col gap-px","data-testid":"sql-private",ref:o,children:I.map($=>b(Zn,{active:n===$.id,onDelete:r,onSelect:g,query:$},$.id))})]}),e[0]=n,e[1]=o,e[2]=r,e[3]=a,e[4]=m,e[5]=g,e[6]=f,e[7]=v,e[8]=S,e[9]=u,e[10]=x,e[11]=h,e[12]=C,e[13]=y,e[14]=p}else x=e[10],h=e[11],C=e[12],y=e[13],p=e[14];let k;e[39]!==u?(k=u("Reference"),e[39]=u,e[40]=k):k=e[40];let N;e[41]!==k?(N=b("p",{className:"px-1 pb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:k}),e[41]=k,e[42]=N):N=e[42];let L;e[43]!==c?(L=ft.map(I=>b("li",{children:F("button",{className:"flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-start text-[13px] text-muted-foreground outline-none transition-colors hover:bg-sidebar-accent hover:text-foreground focus-visible:bg-sidebar-accent","data-sql":I.sql,onClick:c,type:"button",children:[b("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:b("path",{d:"M7 4h7l4 4v12H7zM14 4v4h4"})}),I.label]})},I.label)),e[43]=c,e[44]=L):L=e[44];let T;e[45]!==L?(T=b("ul",{className:"flex flex-col gap-px",children:L}),e[45]=L,e[46]=T):T=e[46];let q;e[47]!==N||e[48]!==T?(q=F("div",{children:[N,T]}),e[47]=N,e[48]=T,e[49]=q):q=e[49];let E;e[50]!==t||e[51]!==s||e[52]!==i||e[53]!==x||e[54]!==d||e[55]!==u?(E=t.length>0&&F("div",{children:[F("div",{className:"flex items-center justify-between px-1 pb-1",children:[b("p",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:u("History")}),b("button",{className:"rounded px-1 text-[11px] text-muted-foreground outline-none transition-colors hover:text-foreground focus-visible:text-foreground","data-testid":"sql-history-clear",onClick:s,type:"button",children:u("Clear history")})]}),F("label",{className:"flex cursor-pointer items-center gap-1.5 px-1 pb-1.5 text-[11px] text-muted-foreground",htmlFor:Ze,children:[b("input",{checked:d,"data-testid":"sql-history-remember",id:Ze,onChange:x,type:"checkbox"}),u("Keep history on this browser")]}),b("ul",{className:"flex flex-col gap-px","data-testid":"sql-history",children:t.map(I=>b("li",{children:F("button",{className:"flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-start text-[13px] text-muted-foreground outline-none transition-colors hover:bg-sidebar-accent hover:text-foreground focus-visible:bg-sidebar-accent","data-sql":I.sql,"data-testid":"sql-history-item",onClick:i,title:I.sql,type:"button",children:[b("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:b("path",{d:"M12 8v4l3 2M12 21a9 9 0 1 1 0-18 9 9 0 0 1 0 18Z"})}),b("span",{className:"truncate font-mono",children:I.sql})]})},`${I.at.toString()}:${I.sql}`))})]}),e[50]=t,e[51]=s,e[52]=i,e[53]=x,e[54]=d,e[55]=u,e[56]=E):E=e[56];let A;e[57]!==h||e[58]!==E||e[59]!==p||e[60]!==q?(A=F("div",{className:h,children:[p,q,E]}),e[57]=h,e[58]=E,e[59]=p,e[60]=q,e[61]=A):A=e[61];let _;return e[62]!==A||e[63]!==C||e[64]!==y?(_=F("aside",{className:C,children:[y,A]}),e[62]=A,e[63]=C,e[64]=y,e[65]=_):_=e[65],_},Ie=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"}`,ns=l=>{const e=Y(96),{assistant:n,chart:t,className:o,error:s,onFormat:r,onInferChart:i,onRun:c,onSelectStatement:a,onShardKeyChange:m,onShowChart:g,onShowExplain:f,onShowResults:v,onToggleSplit:d,pane:S,result:u,running:x,script:h,shardKey:C,splitView:y}=l,p=de(),k=S==="results";let N;e[0]!==k?(N=Ie(k),e[0]=k,e[1]=N):N=e[1];let L;e[2]!==p?(L=p("Results"),e[2]=p,e[3]=L):L=e[3];let T;e[4]!==v||e[5]!==N||e[6]!==L?(T=b("button",{className:N,"data-testid":"sql-tab-results",onClick:v,type:"button",children:L}),e[4]=v,e[5]=N,e[6]=L,e[7]=T):T=e[7];const q=S==="chart";let E;e[8]!==q?(E=Ie(q),e[8]=q,e[9]=E):E=e[9];let A;e[10]!==p?(A=p("Chart"),e[10]=p,e[11]=A):A=e[11];let _;e[12]!==g||e[13]!==E||e[14]!==A?(_=b("button",{className:E,"data-testid":"sql-tab-chart",onClick:g,type:"button",children:A}),e[12]=g,e[13]=E,e[14]=A,e[15]=_):_=e[15];let I;e[16]!==n||e[17]!==i||e[18]!==S||e[19]!==u||e[20]!==p?(I=!n.unavailable&&S==="chart"&&u!==null&&b("button",{className:Ie(!1),"data-testid":"sql-infer-chart",disabled:n.pending("chart"),onClick:i,type:"button",children:n.pending("chart")?p("Thinking…"):p("Suggest chart")}),e[16]=n,e[17]=i,e[18]=S,e[19]=u,e[20]=p,e[21]=I):I=e[21];const B=S==="explain";let D;e[22]!==B?(D=Ie(B),e[22]=B,e[23]=D):D=e[23];let P;e[24]!==p?(P=p("Explain"),e[24]=p,e[25]=P):P=e[25];let O;e[26]!==f||e[27]!==D||e[28]!==P?(O=b("button",{className:D,"data-testid":"sql-tab-explain",onClick:f,type:"button",children:P}),e[26]=f,e[27]=D,e[28]=P,e[29]=O):O=e[29];let w;e[30]!==p?(w=p("Split editor and results"),e[30]=p,e[31]=w):w=e[31];const W=`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 ${y?"bg-accent text-foreground":"text-muted-foreground"}`;let R;e[32]!==p?(R=p("Split editor and results"),e[32]=p,e[33]=R):R=e[33];let M;e[34]===Symbol.for("react.memo_cache_sentinel")?(M=F("svg",{"aria-hidden":"true",className:"size-4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.7,viewBox:"0 0 24 24",children:[b("rect",{height:"16",rx:"2",width:"18",x:"3",y:"4"}),b("path",{d:"M12 4v16"})]}),e[34]=M):M=e[34];let U;e[35]!==d||e[36]!==y||e[37]!==w||e[38]!==W||e[39]!==R?(U=b("button",{"aria-label":w,"aria-pressed":y,className:W,"data-testid":"sql-split-toggle",onClick:d,title:R,type:"button",children:M}),e[35]=d,e[36]=y,e[37]=w,e[38]=W,e[39]=R,e[40]=U):U=e[40];let $;e[41]!==u?($=u!==null&&u.columns.length>0&&b(Et,{columns:u.columns,name:"query-result",rows:u.rows}),e[41]=u,e[42]=$):$=e[42];let X;e[43]!==p?(X=p("Format"),e[43]=p,e[44]=X):X=e[44];let Z;e[45]!==r||e[46]!==x||e[47]!==X?(Z=b("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:x,onClick:r,type:"button",children:X}),e[45]=r,e[46]=x,e[47]=X,e[48]=Z):Z=e[48];let ee;e[49]!==m||e[50]!==C?(ee=b(Nt,{onChange:m,testId:"sql-shard-input",value:C}),e[49]=m,e[50]=C,e[51]=ee):ee=e[51];let te;e[52]!==x||e[53]!==p?(te=p(x?"Running…":"Run"),e[52]=x,e[53]=p,e[54]=te):te=e[54];let ie;e[55]===Symbol.for("react.memo_cache_sentinel")?(ie=b("kbd",{className:"rounded border border-primary-foreground/30 px-1 font-sans text-[10px]",children:"⌘↵"}),e[55]=ie):ie=e[55];let G;e[56]!==c||e[57]!==x||e[58]!==te?(G=F("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:x,onClick:c,type:"button",children:[te,ie]}),e[56]=c,e[57]=x,e[58]=te,e[59]=G):G=e[59];let Q;e[60]!==U||e[61]!==$||e[62]!==Z||e[63]!==ee||e[64]!==G?(Q=F("div",{className:"ms-auto flex items-center gap-2",children:[U,$,Z,ee,G]}),e[60]=U,e[61]=$,e[62]=Z,e[63]=ee,e[64]=G,e[65]=Q):Q=e[65];let ne;e[66]!==O||e[67]!==Q||e[68]!==T||e[69]!==_||e[70]!==I?(ne=F("div",{className:"flex shrink-0 items-center gap-2 border-b border-border pe-2",children:[T,_,I,O,Q]}),e[66]=O,e[67]=Q,e[68]=T,e[69]=_,e[70]=I,e[71]=ne):ne=e[71];let se;e[72]!==a||e[73]!==h?(se=h!==void 0&&b("div",{className:"flex shrink-0 flex-wrap items-center gap-1 border-b border-border px-3 py-1.5","data-testid":"sql-statements",children:h.runs.map((z,J)=>b("button",{"aria-pressed":J===h.selected,className:`rounded-md border px-2 py-0.5 font-mono text-[11px] outline-none transition-colors ${J===h.selected?"border-foreground text-foreground":"border-border text-muted-foreground hover:text-foreground"} ${z.error===null?"":"border-destructive/50 text-destructive"}`,"data-testid":`sql-statement-${J.toString()}`,onClick:()=>{a(J)},title:z.sql,type:"button",children:J+1},`${J.toString()}:${z.sql}`))}),e[72]=a,e[73]=h,e[74]=se):se=e[74];let oe;e[75]!==s?(oe=s!==null&&b(kt,{className:"m-3 font-mono text-xs",testId:"sql-error",variant:"destructive",children:s}),e[75]=s,e[76]=oe):oe=e[76];let le;e[77]!==s||e[78]!==u||e[79]!==p?(le=s===null&&u===null&&b("p",{className:"p-4 text-sm text-muted-foreground","data-testid":"sql-empty",children:p("Click Run to execute your query.")}),e[77]=s,e[78]=u,e[79]=p,e[80]=le):le=e[80];let re;e[81]!==t||e[82]!==s||e[83]!==S||e[84]!==u||e[85]!==p?(re=s===null&&u!==null&&F("div",{"data-testid":"sql-result",children:[S==="chart"?b(wt,{axes:t,result:u}):b(Ct,{result:u}),b("p",{className:"border-t border-border px-3 py-1.5 text-xs text-muted-foreground","data-testid":"sql-count",children:u.truncated?p("Showing the first {max} of {count} rows.",{count:u.rowCount,max:u.rows.length}):p("{count} rows",{count:u.rowCount})})]}),e[81]=t,e[82]=s,e[83]=S,e[84]=u,e[85]=p,e[86]=re):re=e[86];let H;e[87]!==oe||e[88]!==le||e[89]!==re?(H=F("div",{className:"min-h-0 flex-1 overflow-auto",children:[oe,le,re]}),e[87]=oe,e[88]=le,e[89]=re,e[90]=H):H=e[90];let j;return e[91]!==o||e[92]!==ne||e[93]!==se||e[94]!==H?(j=F("div",{className:o,children:[ne,se,H]}),e[91]=o,e[92]=ne,e[93]=se,e[94]=H,e[95]=j):j=e[95],j},ss=(l,e)=>l.trim()===""?e:(l.split(`
8
- `)[0]??l).slice(0,24),os=l=>{l?.focus(),l?.select()},ls=l=>{const e=Y(14),{initial:n,onCancel:t,onCommit:o,placeholder:s,testId:r}=l,i=de();let c;e[0]!==o?(c=d=>{o(d.currentTarget.value.trim())},e[0]=o,e[1]=c):c=e[1];const a=c;let m;e[2]!==t||e[3]!==o?(m=d=>{d.key==="Enter"?o(d.currentTarget.value.trim()):d.key==="Escape"&&t()},e[2]=t,e[3]=o,e[4]=m):m=e[4];const g=m;let f;e[5]!==i?(f=i("Tab title"),e[5]=i,e[6]=f):f=e[6];let v;return e[7]!==n||e[8]!==a||e[9]!==g||e[10]!==s||e[11]!==f||e[12]!==r?(v=b("input",{"aria-label":f,className:"w-40 rounded border border-ring bg-background px-1 py-0.5 text-xs outline-none","data-testid":r,defaultValue:n,onBlur:a,onKeyDown:g,placeholder:s,ref:os,type:"text"}),e[7]=n,e[8]=a,e[9]=g,e[10]=s,e[11]=f,e[12]=r,e[13]=v):v=e[13],v},rs=l=>{const e=Y(29),{idBase:n,onDiscard:t,onKeep:o}=l,s=de(),r=`sql-tab-close-prompt-${n}`;let i;e[0]!==s?(i=s("Discard?"),e[0]=s,e[1]=i):i=e[1];let c;e[2]!==i?(c=b("span",{className:"text-[11px] text-muted-foreground",children:i}),e[2]=i,e[3]=c):c=e[3];let a;e[4]!==s?(a=s("Discard changes"),e[4]=s,e[5]=a):a=e[5];const m=`sql-tab-close-confirm-${n}`;let g;e[6]!==s?(g=s("Discard changes"),e[6]=s,e[7]=g):g=e[7];let f;e[8]===Symbol.for("react.memo_cache_sentinel")?(f=b("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2.4,viewBox:"0 0 24 24",children:b("path",{d:"M5 13l4 4L19 7"})}),e[8]=f):f=e[8];let v;e[9]!==t||e[10]!==a||e[11]!==m||e[12]!==g?(v=b("button",{"aria-label":a,className:"flex size-5 items-center justify-center rounded text-destructive hover:bg-destructive/10","data-testid":m,onClick:t,title:g,type:"button",children:f}),e[9]=t,e[10]=a,e[11]=m,e[12]=g,e[13]=v):v=e[13];let d;e[14]!==s?(d=s("Keep editing"),e[14]=s,e[15]=d):d=e[15];const S=`sql-tab-close-cancel-${n}`;let u;e[16]!==s?(u=s("Keep editing"),e[16]=s,e[17]=u):u=e[17];let x;e[18]===Symbol.for("react.memo_cache_sentinel")?(x=b("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2.4,viewBox:"0 0 24 24",children:b("path",{d:"M6 6l12 12M18 6 6 18"})}),e[18]=x):x=e[18];let h;e[19]!==o||e[20]!==S||e[21]!==u||e[22]!==d?(h=b("button",{"aria-label":d,className:"flex size-5 items-center justify-center rounded text-muted-foreground hover:bg-accent","data-testid":S,onClick:o,title:u,type:"button",children:x}),e[19]=o,e[20]=S,e[21]=u,e[22]=d,e[23]=h):h=e[23];let C;return e[24]!==r||e[25]!==h||e[26]!==c||e[27]!==v?(C=F("span",{className:"flex shrink-0 items-center gap-1","data-testid":r,role:"group",children:[c,v,h]}),e[24]=r,e[25]=h,e[26]=c,e[27]=v,e[28]=C):C=e[28],C},is=l=>{const e=Y(47),{active:n,canClose:t,onClose:o,onMenu:s,onRename:r,onSelect:i,tab:c}=l,a=de(),[m,g]=ce(!1),[f,v]=ce(!1);let d;e[0]!==s||e[1]!==c.id?(d=$=>{s(c.id,$)},e[0]=s,e[1]=c.id,e[2]=d):d=e[2];const S=d;let u;e[3]!==i||e[4]!==c.id?(u=()=>{i(c.id)},e[3]=i,e[4]=c.id,e[5]=u):u=e[5];const x=u;let h;e[6]===Symbol.for("react.memo_cache_sentinel")?(h=()=>{g(!0)},e[6]=h):h=e[6];const C=h;let y;e[7]!==o||e[8]!==c?(y=$=>{$.stopPropagation(),dt(c)?v(!0):o(c.id)},e[7]=o,e[8]=c,e[9]=y):y=e[9];const p=y;let k;e[10]!==o||e[11]!==c.id?(k=$=>{$.stopPropagation(),v(!1),o(c.id)},e[10]=o,e[11]=c.id,e[12]=k):k=e[12];const N=k;let L;e[13]===Symbol.for("react.memo_cache_sentinel")?(L=$=>{$.stopPropagation(),v(!1)},e[13]=L):L=e[13];const T=L;let q;e[14]!==r||e[15]!==c.id?(q=$=>{r(c.id,$),g(!1)},e[14]=r,e[15]=c.id,e[16]=q):q=e[16];const E=q;let A;e[17]===Symbol.for("react.memo_cache_sentinel")?(A=()=>{g(!1)},e[17]=A):A=e[17];const _=A;let I;e[18]!==c.name?(I=c.name.trim(),e[18]=c.name,e[19]=I):I=e[19];const B=I;let D;e[20]!==a||e[21]!==c.sql?(D=ss(c.sql,a("Untitled")),e[20]=a,e[21]=c.sql,e[22]=D):D=e[22];const P=D,O=n?"bg-background text-foreground":"bg-muted/40 text-muted-foreground hover:text-foreground";let w;e[23]!==O?(w=fe("group/tab flex shrink-0 items-center gap-1 border-e border-border ps-3 pe-1.5 text-xs",O),e[23]=O,e[24]=w):w=e[24];const W=`sql-tab-${c.id}`;let R;e[25]!==n||e[26]!==E||e[27]!==B||e[28]!==P||e[29]!==m||e[30]!==x||e[31]!==a||e[32]!==c.id?(R=m?b(ls,{initial:B,onCancel:_,onCommit:E,placeholder:P,testId:`sql-tab-rename-${c.id}`}):b("button",{"aria-pressed":n,className:"max-w-40 truncate py-1.5 outline-none","data-testid":`sql-tab-select-${c.id}`,onClick:x,onDoubleClick:C,title:a("Double-click to rename"),type:"button",children:B===""?P:B}),e[25]=n,e[26]=E,e[27]=B,e[28]=P,e[29]=m,e[30]=x,e[31]=a,e[32]=c.id,e[33]=R):R=e[33];let M;e[34]!==t||e[35]!==N||e[36]!==f||e[37]!==p||e[38]!==a||e[39]!==c.id?(M=t&&(f?b(rs,{idBase:c.id,onDiscard:N,onKeep:T}):b("button",{"aria-label":a("Close tab"),className:"flex size-5 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-destructive/10 hover:text-destructive","data-testid":`sql-tab-close-${c.id}`,onClick:p,title:a("Close tab"),type:"button",children:b("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,viewBox:"0 0 24 24",children:b("path",{d:"M6 6l12 12M18 6 6 18"})})})),e[34]=t,e[35]=N,e[36]=f,e[37]=p,e[38]=a,e[39]=c.id,e[40]=M):M=e[40];let U;return e[41]!==S||e[42]!==w||e[43]!==W||e[44]!==R||e[45]!==M?(U=F("div",{className:w,"data-testid":W,onContextMenu:S,children:[R,M]}),e[41]=S,e[42]=w,e[43]=W,e[44]=R,e[45]=M,e[46]=U):U=e[46],U},as=l=>{const e=Y(43),{model:n,onSelect:t}=l,o=de(),{activeTab:s,addEditorTab:r,cancelBulk:i,closeEditorTab:c,closeTabMenu:a,confirmBulk:m,menuStyle:g,onBackdropContextMenu:f,onCloseAll:v,onCloseOthers:d,onCloseToRight:S,openTabMenu:u,pendingBulk:x,renameTab:h,tabMenu:C,tabs:y}=n;let p;if(e[0]!==s||e[1]!==c||e[2]!==t||e[3]!==u||e[4]!==h||e[5]!==y){let I;e[7]!==s||e[8]!==c||e[9]!==t||e[10]!==u||e[11]!==h||e[12]!==y.length?(I=B=>b(is,{active:B.id===s.id,canClose:y.length>1,onClose:c,onMenu:u,onRename:h,onSelect:t,tab:B},B.id),e[7]=s,e[8]=c,e[9]=t,e[10]=u,e[11]=h,e[12]=y.length,e[13]=I):I=e[13],p=y.map(I),e[0]=s,e[1]=c,e[2]=t,e[3]=u,e[4]=h,e[5]=y,e[6]=p}else p=e[6];let k;e[14]!==o?(k=o("New tab"),e[14]=o,e[15]=k):k=e[15];const N=y.length>=ze;let L;e[16]!==o?(L=o("New tab"),e[16]=o,e[17]=L):L=e[17];let T;e[18]===Symbol.for("react.memo_cache_sentinel")?(T=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:b("path",{d:"M12 5v14M5 12h14"})}),e[18]=T):T=e[18];let q;e[19]!==r||e[20]!==k||e[21]!==N||e[22]!==L?(q=b("button",{"aria-label":k,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:N,onClick:r,title:L,type:"button",children:T}),e[19]=r,e[20]=k,e[21]=N,e[22]=L,e[23]=q):q=e[23];let E;e[24]!==p||e[25]!==q?(E=F("div",{className:"flex shrink-0 items-stretch overflow-x-auto border-b border-border bg-muted/30","data-testid":"sql-tab-strip",role:"tablist",children:[p,q]}),e[24]=p,e[25]=q,e[26]=E):E=e[26];let A;e[27]!==i||e[28]!==a||e[29]!==m||e[30]!==g||e[31]!==f||e[32]!==v||e[33]!==d||e[34]!==S||e[35]!==x||e[36]!==o||e[37]!==C||e[38]!==y?(A=C!==null&&F(He,{children:[b("div",{className:"fixed inset-0 z-40","data-testid":"sql-tab-menu-backdrop",onClick:a,onContextMenu:f,role:"presentation"}),b("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:g,children:x===null?F(He,{children:[b("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:y.length<=1,onClick:d,role:"menuitem",type:"button",children:o("Close other tabs")}),b("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:y.findIndex(I=>I.id===C.id)>=y.length-1,onClick:S,role:"menuitem",type:"button",children:o("Close tabs to the right")}),b("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:v,role:"menuitem",type:"button",children:o("Close all tabs")})]}):F("div",{className:"px-3 py-1.5","data-testid":"sql-tab-menu-confirm",children:[b("p",{className:"pb-1.5 text-xs text-muted-foreground",children:o("Discard unsaved tabs?")}),F("div",{className:"flex items-center gap-1.5",children:[b("button",{className:"rounded px-2 py-1 text-xs font-medium text-destructive outline-none hover:bg-destructive/10 focus-visible:bg-destructive/10","data-testid":"sql-tab-menu-confirm-discard",onClick:m,type:"button",children:o("Discard")}),b("button",{className:"rounded px-2 py-1 text-xs text-muted-foreground outline-none hover:bg-accent focus-visible:bg-accent","data-testid":"sql-tab-menu-confirm-cancel",onClick:i,type:"button",children:o("Cancel")})]})]})})]}),e[27]=i,e[28]=a,e[29]=m,e[30]=g,e[31]=f,e[32]=v,e[33]=d,e[34]=S,e[35]=x,e[36]=o,e[37]=C,e[38]=y,e[39]=A):A=e[39];let _;return e[40]!==E||e[41]!==A?(_=F(He,{children:[E,A]}),e[40]=E,e[41]=A,e[42]=_):_=e[42],_},cs=Oe(_e.runSql),ds="lunora-studio-sql-split-view",us=()=>we(ft[0]?.sql??""),Ls=l=>{const e=Y(112),{initialShardKey:n}=l,t=Qe(),o=$n(us),{activeTab:s,output:r,patchActiveOutput:i,patchActiveTab:c,setActiveTabId:a,unlinkQuery:m}=o;let g;e[0]!==i||e[1]!==c?(g=(K,ae)=>{c({activeId:ae,sql:K}),i({chart:void 0,error:null,failed:void 0,result:null,script:void 0})},e[0]=i,e[1]=c,e[2]=g):g=e[2];const f=g;let v;e[3]!==f||e[4]!==m?(v={loadIntoActiveTab:f,unlinkQuery:m},e[3]=f,e[4]=m,e[5]=v):v=e[5];const d=Qn(v),{recordHistory:S,updateQuerySql:u}=d,x=s.sql,{activeId:h}=s,{chart:C,error:y,failed:p,result:k,running:N}=r,L=r.pane,[T,q]=ce(n??""),[E,A]=Ue(ds,!1),{probe:_,schema:I}=Cn(T);let B;e[6]!==h||e[7]!==c||e[8]!==u?(B=K=>{c({sql:K}),h!==null&&u(h,K)},e[6]=h,e[7]=c,e[8]=u,e[9]=B):B=e[9];const D=B,P=rn(x,I,T),O=vt(T);let w;e[10]!==O||e[11]!==i||e[12]!==k?(w=()=>{if(k===null)return;ue((async()=>{const ae=await O.inferChart({columns:k.columns,rowCount:k.rowCount,types:Object.fromEntries(k.columns.map(V=>[V,typeof(k.rows[0]?.[V]??"")]))});i({chart:ae})})())},e[10]=O,e[11]=i,e[12]=k,e[13]=w):w=e[13];const W=w;let R;e[14]!==t||e[15]!==S||e[16]!==T?(R=async K=>{try{const ae=await t.query(cs,{sql:K},qe(T));return S(K),{error:null,result:ae,sql:K}}catch(ae){return{error:gt(ae),result:null,sql:K}}},e[14]=t,e[15]=S,e[16]=T,e[17]=R):R=e[17];const M=R;let U;e[18]!==x||e[19]!==i||e[20]!==M||e[21]!==T?(U=async K=>{if(x.trim()==="")return;i({running:!0});const ae=K==="explain"?Fe(Mt(x),0):lt(x),V=[];for(const Te of ae){const mt={error:Te.rejection?.message??"",result:null,sql:Te.sql};V.push(Te.rejection===void 0?await M(Te.sql):mt)}xt(T);const Ye=Math.max(V.length-1,0),ye=V[Ye];i({chart:void 0,error:ye?.error??null,failed:ye?.error===null||ye===void 0?void 0:{error:ye.error,sql:ye.sql},pane:K,result:ye?.result??null,running:!1,script:V.length>1?{runs:V,selected:Ye}:void 0})},e[18]=x,e[19]=i,e[20]=M,e[21]=T,e[22]=U):U=e[22];const $=U;let X;e[23]!==r.script?.runs||e[24]!==i?(X=K=>{const ae=r.script?.runs,V=ae?.[K];ae===void 0||V===void 0||i({chart:void 0,error:V.error,failed:V.error===null?void 0:{error:V.error,sql:V.sql},result:V.result,script:{runs:ae,selected:K}})},e[23]=r.script?.runs,e[24]=i,e[25]=X):X=e[25];const Z=X;let ee;e[26]!==$?(ee=()=>{ue($("results"))},e[26]=$,e[27]=ee):ee=e[27];const te=ee;let ie;e[28]!==r.pane||e[29]!==$?(ie=()=>{ue($(r.pane))},e[28]=r.pane,e[29]=$,e[30]=ie):ie=e[30];let G;e[31]!==_||e[32]!==I||e[33]!==D||e[34]!==ie?(G={onSubmit:ie,probe:_,schema:I,setDraft:D},e[31]=_,e[32]=I,e[33]=D,e[34]=ie,e[35]=G):G=e[35];const Q=En(G),{closeAutocomplete:ne}=Q;let se;e[36]!==x||e[37]!==D?(se=()=>{D(Ft(x))},e[36]=x,e[37]=D,e[38]=se):se=e[38];const oe=se;let le;e[39]!==ne||e[40]!==a?(le=K=>{ne(),a(K)},e[39]=ne,e[40]=a,e[41]=le):le=e[41];const re=le;let H;e[42]!==i?(H=()=>{i({pane:"results"})},e[42]=i,e[43]=H):H=e[43];const j=H;let z;e[44]!==$?(z=()=>{ue($("explain"))},e[44]=$,e[45]=z):z=e[45];const J=z;let me;e[46]!==i?(me=()=>{i({pane:"chart"})},e[46]=i,e[47]=me):me=e[47];const De=me;let ke;e[48]!==A||e[49]!==E?(ke=()=>{A(!E)},e[48]=A,e[49]=E,e[50]=ke):ke=e[50];const Me=ke,$e=E?"flex min-h-0 flex-1 flex-row":"flex min-h-0 flex-1 flex-col",Be=E?"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 he;e[51]!==h||e[52]!==d.clearHistory||e[53]!==d.deleteQuery||e[54]!==d.history||e[55]!==d.listRef||e[56]!==d.loadFromHistory||e[57]!==d.loadTemplate||e[58]!==d.newQuery||e[59]!==d.onSearchChange||e[60]!==d.queries||e[61]!==d.rememberHistory||e[62]!==d.search||e[63]!==d.selectQuery||e[64]!==d.setRememberHistory?(he=b(ts,{activeId:h,history:d.history,listRef:d.listRef,onClearHistory:d.clearHistory,onDelete:d.deleteQuery,onLoadHistory:d.loadFromHistory,onLoadTemplate:d.loadTemplate,onNew:d.newQuery,onSearchChange:d.onSearchChange,onSelect:d.selectQuery,onToggleRememberHistory:d.setRememberHistory,queries:d.queries,rememberHistory:d.rememberHistory,search:d.search}),e[51]=h,e[52]=d.clearHistory,e[53]=d.deleteQuery,e[54]=d.history,e[55]=d.listRef,e[56]=d.loadFromHistory,e[57]=d.loadTemplate,e[58]=d.newQuery,e[59]=d.onSearchChange,e[60]=d.queries,e[61]=d.rememberHistory,e[62]=d.search,e[63]=d.selectQuery,e[64]=d.setRememberHistory,e[65]=he):he=e[65];let pe;e[66]!==o||e[67]!==re?(pe=b(as,{model:o,onSelect:re}),e[66]=o,e[67]=re,e[68]=pe):pe=e[68];let be;e[69]!==O||e[70]!==P||e[71]!==x||e[72]!==p||e[73]!==D||e[74]!==Q.autocompleteState||e[75]!==Q.editorRef||e[76]!==Q.gutterRef||e[77]!==Q.handlers||e[78]!==Q.listboxId||e[79]!==Q.onPickSuggestion||e[80]!==Q.overlayRef||e[81]!==Q.revealDiagnostic?(be=b(Vn,{assistant:O,autocomplete:Q.autocompleteState,diagnostics:P,draft:x,editorRef:Q.editorRef,failed:p,gutterRef:Q.gutterRef,handlers:Q.handlers,listboxId:Q.listboxId,onGenerated:D,onPickSuggestion:Q.onPickSuggestion,onRevealDiagnostic:Q.revealDiagnostic,overlayRef:Q.overlayRef}),e[69]=O,e[70]=P,e[71]=x,e[72]=p,e[73]=D,e[74]=Q.autocompleteState,e[75]=Q.editorRef,e[76]=Q.gutterRef,e[77]=Q.handlers,e[78]=Q.listboxId,e[79]=Q.onPickSuggestion,e[80]=Q.overlayRef,e[81]=Q.revealDiagnostic,e[82]=be):be=e[82];let ge;e[83]!==O||e[84]!==y||e[85]!==oe||e[86]!==W||e[87]!==C||e[88]!==te||e[89]!==Z||e[90]!==r.script||e[91]!==k||e[92]!==Be||e[93]!==N||e[94]!==T||e[95]!==De||e[96]!==J||e[97]!==j||e[98]!==E||e[99]!==L||e[100]!==Me?(ge=b(ns,{assistant:O,chart:C,className:Be,error:y,onFormat:oe,onInferChart:W,onRun:te,onSelectStatement:Z,onShardKeyChange:q,onShowChart:De,onShowExplain:J,onShowResults:j,onToggleSplit:Me,pane:L,result:k,running:N,script:r.script,shardKey:T,splitView:E}),e[83]=O,e[84]=y,e[85]=oe,e[86]=W,e[87]=C,e[88]=te,e[89]=Z,e[90]=r.script,e[91]=k,e[92]=Be,e[93]=N,e[94]=T,e[95]=De,e[96]=J,e[97]=j,e[98]=E,e[99]=L,e[100]=Me,e[101]=ge):ge=e[101];let xe;e[102]!==be||e[103]!==ge||e[104]!==$e?(xe=F("div",{className:$e,children:[be,ge]}),e[102]=be,e[103]=ge,e[104]=$e,e[105]=xe):xe=e[105];let ve;e[106]!==pe||e[107]!==xe?(ve=F("div",{className:"flex min-w-0 flex-1 flex-col",children:[pe,xe]}),e[106]=pe,e[107]=xe,e[108]=ve):ve=e[108];let Ee;return e[109]!==he||e[110]!==ve?(Ee=F("div",{className:"flex h-full min-w-0","data-testid":"lunora-sql-editor",children:[he,ve]}),e[109]=he,e[110]=ve,e[111]=Ee):Ee=e[111],Ee};export{Ls as SqlEditorPanel};
4
+ `);return e.join("")},Lt=/^(?:explain\s+(?:query\s+plan\s+)?)?(?:select|with)\b/iu,It=/\b(?:alter|attach|create|delete|detach|drop|insert|pragma|reindex|truncate|update|vacuum)\b|\breplace\b(?!\s*\()/iu,_t=/^\w+/u,At=/;\s*$/u,qt=/\s/u,ot=l=>{let e=0;for(;e<l.length;){const n=l[e];if(n!==void 0&&qt.test(n))e+=1;else if(n==="-"&&l[e+1]==="-")e=tt(l,e);else if(n==="/"&&l[e+1]==="*"){const t=nt(l,e);if(t===-1)break;e=t}else break}return e},Ot=l=>{const e=ot(l),n=l.slice(e).trimEnd();if(n==="")return{code:"SQL_EMPTY",message:"the query is empty"};const o=(st(n)??n).replace(At,""),s=n.slice(0,o.length),r=o.indexOf(";");if(r!==-1)return{code:"SQL_MULTIPLE_STATEMENTS",length:1,message:"only a single statement may be run",offset:e+r};const c="the SQL editor is read-only — only SELECT / WITH / EXPLAIN queries are allowed";if(!Lt.test(s))return{code:"SQL_NOT_READONLY",length:_t.exec(s)?.[0].length??1,message:c,offset:e};const a=It.exec(s);if(a!==null)return{code:"SQL_NOT_READONLY",length:a[0].length,message:`${c} (\`${a[0].toUpperCase()}\` is not allowed)`,offset:e+a.index}},Dt=/^explain\b/iu,Mt=l=>Dt.test(l.slice(ot(l)))?l:`EXPLAIN QUERY PLAN ${l}`,We=(l,e)=>{const n=l.trim();if(n==="")return[];const t=e+l.indexOf(n),o=Ot(n);return o?.code==="SQL_EMPTY"?[]:[o===void 0?{offset:t,sql:n}:{offset:t,rejection:o,sql:n}]},lt=l=>{const e=st(l);if(e===void 0)return We(l,0);const n=[];let t=0;for(let o=0;o<=e.length;o+=1)o!==e.length&&e[o]!==";"||(n.push(...We(l.slice(t,o),t)),t=o+1);return n},$t=["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"],Ae=String.fromCodePoint(0),Ht=new RegExp(`${Ae}${String.raw`(\d+)`}${Ae}`,"gu"),Pt=$t.map(l=>({pattern:new RegExp(String.raw`\b${l.replaceAll(" ",String.raw`\s+`)}\b`,"giu"),replacement:l})),Ft=Bt.map(l=>({pattern:new RegExp(String.raw`\s+${l.replaceAll(" ",String.raw`\s+`)}\b`,"gu"),replacement:`
5
+ ${l}`})),Wt=l=>{const e=[];let t=l.replaceAll(/'(?:[^']|'')*'/gu,o=>(e.push(o),`${Ae}${(e.length-1).toString()}${Ae}`)).replaceAll(/\s+/gu," ").trim();for(const{pattern:o,replacement:s}of Pt)t=t.replaceAll(o,s);for(const{pattern:o,replacement:s}of Ft)t=t.replaceAll(o,s);return t=t.replaceAll(Ht,(o,s)=>e[Number(s)]??""),t},Qt=/\b(?:from|join)\s+([a-z_][\w$]*)(?:\s+(?:as\s+)?([a-z_][\w$]*))?/giu,zt=/(?:\bwith\s+(?:recursive\s+)?|,\s*)([a-z_][\w$]*)\s+as\s*\(/giu,Ut=new Set(["cross","full","group","having","inner","join","left","limit","offset","on","order","right","union","using","where","window"]),jt=/[^\n]/gu,Yt=(l,e)=>{const n=l[e];if(n==="'"){let t=e+1;for(;t<l.length&&l[t]!=="'";)t+=1;return Math.min(t+1,l.length)}if(n==="-"&&l[e+1]==="-"){const t=l.indexOf(`
6
+ `,e);return t===-1?l.length:t}if(n==="/"&&l[e+1]==="*"){const t=l.indexOf("*/",e+2);return t===-1?l.length:t+2}return-1},Kt=l=>{let e="",n=0;for(;n<l.length;){const t=Yt(l,n);t===-1?(e+=l.slice(n,n+1),n+=1):(e+=l.slice(n,t).replaceAll(jt," "),n=t)}return e},Gt=l=>{const e=new Set;for(const n of l.matchAll(zt))e.add((n[1]??"").toLowerCase());return e},Jt=(l,e)=>{const n=new Map;for(const t of l.matchAll(Qt)){const o=(t[1]??"").toLowerCase(),s=(t[2]??"").toLowerCase();e.has(o)&&(n.set(o,o),s!==""&&!Ut.has(s)&&n.set(s,o))}return n},rt=(l,e)=>{const n=Kt(l),t=new Set(e.map(o=>o.toLowerCase()));return{ctes:Gt(n),masked:n,targets:Jt(n,t)}},Vt=/^(?:__lunora|sqlite_)/iu,Xt=/\b(?:from|join)\s+([a-z_][\w$]*)/giu,Zt=/\b([a-z_][\w$]*)\.([a-z_][\w$]*)/giu,en=new Set(["cross","full","group","having","inner","join","lateral","left","limit","offset","order","right","select","union","where","window"]),tn=(l,e,n)=>{const t=[];for(const o of l.matchAll(Xt)){const s=o[1]??"",r=s.toLowerCase();!e.has(r)&&!n.has(r)&&!en.has(r)&&!Vt.test(s)&&t.push({length:s.length,message:`unknown table \`${s}\``,offset:o.index+o[0].length-s.length,severity:"error",source:"schema"})}return t},nn=(l,e,n)=>{const t=[],o=new Map;for(const[s,r]of Object.entries(e.columns))o.set(s.toLowerCase(),new Set(r.map(c=>c.toLowerCase())));for(const s of l.matchAll(Zt)){const r=(s[1]??"").toLowerCase(),c=s[2]??"",a=n.get(r),i=a===void 0?void 0:o.get(a);i!==void 0&&!i.has(c.toLowerCase())&&t.push({length:c.length,message:`\`${a??""}\` has no column \`${c}\``,offset:s.index+s[0].length-c.length,severity:"error",source:"schema"})}return t},sn=/(?<![\w$."])(?:"([a-z_][\w$]*)"|([a-z_][\w$]*))(?![.(])/giu,on=/\bas\s+"?([a-z_][\w$]*)"?/giu,ln=(l,e,n,t)=>{const o=[...new Set(n.values())],s=new Map,r=new Set;for(const i of o){for(const f of e.columns[i]??[])r.add(f.toLowerCase());for(const f of e.docFields?.[i]??[])s.set(f.toLowerCase(),f)}if(s.size===0)return[];const c=new Set([...l.matchAll(on)].map(i=>(i[1]??"").toLowerCase())),a=[];for(const i of l.matchAll(sn)){const f=i[1],p=f??i[2]??"",m=p.toLowerCase(),x=s.get(m);x===void 0||r.has(m)||c.has(m)||t.has(m)||n.has(m)||a.push({length:p.length,message:`\`${x}\` is a \`__doc__\` field, not a column — use \`json_extract(__doc__, '$.${x}')\``,offset:i.index+(f===void 0?0:1),severity:"error",source:"schema"})}return a},rn=(l,e)=>{if(l.trim()==="")return[];const n=lt(l),t=new Set(e.tables.map(s=>s.toLowerCase())),o=[];for(const s of n){const{offset:r,rejection:c}=s;if(c!==void 0){o.push({length:c.length,message:c.message,offset:c.offset===void 0?r:r+c.offset,severity:"error",source:"gate"});continue}const{ctes:a,masked:i,targets:f}=rt(s.sql,e.tables);o.push(...[...tn(i,t,a),...nn(i,e,f),...ln(i,e,f,a)].map(p=>({...p,offset:p.offset===void 0?r:r+p.offset})))}return o},an=Oe(qe.lintSql),cn=600,dn=(l,e,n)=>{const t=Qe(),[o,s]=ie([]),r=Ke(()=>rn(l,e),[l,e]),c=yt(l,cn),i=r.some(m=>m.source==="gate")||c.trim()==="",f=ht(async m=>{try{const x=await t.query(an,{sql:c},_e(n));m.cancelled||s(x.diagnostics??[])}catch{m.cancelled||s([])}},[t,c,n]);Ne(()=>{if(i){s([]);return}const m={cancelled:!1};return ue(f(m)),()=>{m.cancelled=!0}},[f,i]);const p=c===l;return Ke(()=>p?[...r,...o]:r,[r,o,p])},Le=8,un=["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"],fn=new Set(["AND","BY","HAVING","ON","OR","SELECT","WHERE"]),mn=/[\w$]/,it=l=>l!==void 0&&mn.test(l),at=l=>{let e=l.length;for(;e>0&&it(l[e-1]);)e-=1;return l.slice(e)},ct=(l,e)=>{let n=e;for(;n>0&&it(l[n-1]);)n-=1;return{end:e,start:n,text:l.slice(n,e)}},Je=(l,e)=>{const n=l.slice(0,e).trimEnd();return n.endsWith(".")||fn.has(at(n).toUpperCase())},hn=(l,e,n)=>{const t=l.slice(0,e);if(!t.endsWith("."))return;const o=at(t.slice(0,-1));if(o!=="")return rt(l,n).targets.get(o.toLowerCase())??o},Ue=(l,e)=>l.toLowerCase().startsWith(e.toLowerCase()),Ve=(l,e,n,t)=>{const o=[];for(const s of l)if(Ue(s,e)&&(o.push(t(s)),o.length>=n))break;return o},pn=(l,e,n)=>{const t=new Map;for(const[o,s]of Object.entries(l.columns))for(const r of s)if(Ue(r,e)&&!t.has(r)&&(t.set(r,o),t.size>=n))return[...t].map(([c,a])=>({detail:a,kind:"column",label:c}));return[...t].map(([o,s])=>({detail:s,kind:"column",label:o}))},bn=(l,e,n)=>{const t=ct(l,e),o=hn(l,t.start,n.tables);if(o!==void 0){const i=n.columns[o]??n.columns[o.toLowerCase()]??[];return Ve(i,t.text,Le,f=>({detail:o,kind:"column",label:f}))}if(t.text===""&&!Je(l,t.start))return[];const s=Ve(n.tables,t.text,Le,i=>({kind:"table",label:i})),r=pn(n,t.text,Le),c=un.flatMap(i=>t.text!==""&&Ue(i,t.text)&&i.toLowerCase()!==t.text.toLowerCase()?[{kind:"keyword",label:i}]:[]);return(Je(l,t.start)?[...r,...s,...c]:[...s,...r,...c]).slice(0,Le)},gn=(l,e,n)=>{const t=ct(l,e),o=l.slice(0,t.start)+n.label+l.slice(t.end);return{caret:t.start+n.label.length,value:o}},xn=["boxSizing","borderBottomWidth","borderLeftWidth","borderRightWidth","borderTopWidth","fontFamily","fontSize","fontStyle","fontWeight","letterSpacing","lineHeight","paddingBottom","paddingLeft","paddingRight","paddingTop","tabSize","textIndent","textTransform","width","wordSpacing"],vn=(l,e)=>{const n=globalThis.getComputedStyle(l),t=globalThis.document.createElement("div"),{style:o}=t;o.position="absolute",o.visibility="hidden",o.whiteSpace="pre-wrap",o.overflowWrap="break-word";for(const a of xn)o[a]=n[a];t.textContent=l.value.slice(0,Math.max(0,e));const s=globalThis.document.createElement("span");s.textContent=l.value.slice(Math.max(0,e))||".",t.append(s),globalThis.document.body.append(t);const r=s.offsetLeft-l.scrollLeft,c=s.offsetTop-l.scrollTop;return t.remove(),{left:r,top:c}},yn=(l,e,n)=>{const t=Y(16),[o,s]=ie(null);let r;t[0]!==l||t[1]!==e?(r=(v,g)=>{const N=bn(v,g,l);if(N.length===0){s(null);return}const y=e.current,{left:h,top:E}=y===null?{left:0,top:0}:vn(y,g);s(w=>w!==null&&w.active===0&&w.left===h&&w.top===E&&w.suggestions.length===N.length&&w.suggestions.every((T,_)=>{const C=N.at(_);return T.kind===C?.kind&&T.label===C.label&&T.detail===C.detail})?w:{active:0,left:h,suggestions:N,top:E})},t[0]=l,t[1]=e,t[2]=r):r=t[2];const c=r;let a;t[3]===Symbol.for("react.memo_cache_sentinel")?(a=()=>{s(null)},t[3]=a):a=t[3];const i=a;let f;t[4]===Symbol.for("react.memo_cache_sentinel")?(f=v=>{s(g=>{if(g===null)return g;const N=g.suggestions.length,y=(g.active+v+N)%N;return{...g,active:y}})},t[4]=f):f=t[4];const p=f;let m;t[5]!==n||t[6]!==o||t[7]!==e?(m=v=>{const g=e.current;if(o===null||g===null)return!1;const N=o.suggestions[v??o.active];if(N===void 0)return!1;const y=gn(g.value,g.selectionStart,N);return n(y.value),s(null),requestAnimationFrame(()=>{const h=e.current;h!==null&&(h.focus(),h.setSelectionRange(y.caret,y.caret))}),!0},t[5]=n,t[6]=o,t[7]=e,t[8]=m):m=t[8];const x=m;let d;t[9]!==x?(d=()=>x(),t[9]=x,t[10]=d):d=t[10];const S=d;let u;return t[11]!==S||t[12]!==x||t[13]!==c||t[14]!==o?(u={close:i,commit:S,commitAt:x,move:p,refresh:c,state:o},t[11]=S,t[12]=x,t[13]=c,t[14]=o,t[15]=u):u=t[15],u},Sn={column:"column",keyword:"keyword",table:"table"},wn=20,Cn=l=>{const e=Y(17),{listboxId:n,onPick:t,state:o}=l,s=de();let r;e[0]!==o?(r=o===null?void 0:{left:o.left,top:o.top+wn},e[0]=o,e[1]=r):r=e[1];const c=r;if(o===null)return null;let a;if(e[2]!==n||e[3]!==t||e[4]!==o.active||e[5]!==o.suggestions||e[6]!==s){let f;e[8]!==n||e[9]!==t||e[10]!==o.active||e[11]!==s?(f=(p,m)=>W("li",{"aria-selected":m===o.active,className:fe("flex cursor-pointer items-center gap-2 px-2 py-1 text-[13px]",m===o.active?"bg-accent text-accent-foreground":"text-foreground"),"data-testid":"sql-autocomplete-item",id:`${n}-opt-${m.toString()}`,onMouseDown:x=>{x.preventDefault(),t(m)},role:"option",children:[b("span",{className:"truncate font-mono",children:p.label}),p.detail!==void 0&&b("span",{className:"ms-auto truncate text-xs text-muted-foreground",children:p.detail}),b("span",{className:"shrink-0 font-mono text-[10px] tracking-wide text-muted-foreground/70 uppercase",children:s(Sn[p.kind])})]},`${p.kind}:${p.label}`),e[8]=n,e[9]=t,e[10]=o.active,e[11]=s,e[12]=f):f=e[12],a=o.suggestions.map(f),e[2]=n,e[3]=t,e[4]=o.active,e[5]=o.suggestions,e[6]=s,e[7]=a}else a=e[7];let i;return e[13]!==n||e[14]!==c||e[15]!==a?(i=b("ul",{className:"absolute z-30 max-h-56 w-72 overflow-auto rounded-md border border-border bg-popover py-1 text-popover-foreground shadow-md","data-testid":"sql-autocomplete",id:n,role:"listbox",style:c,children:a}),e[13]=n,e[14]=c,e[15]=a,e[16]=i):i=e[16],i},Nn=Oe(qe.listTables),kn=Oe(qe.readTablePage),En=l=>{const e=Y(18),n=Qe();let t;e[0]===Symbol.for("react.memo_cache_sentinel")?(t=[],e[0]=t):t=e[0];const[o,s]=ie(t);let r;e[1]===Symbol.for("react.memo_cache_sentinel")?(r={},e[1]=r):r=e[1];const[c,a]=ie(r);let i;e[2]===Symbol.for("react.memo_cache_sentinel")?(i={},e[2]=i):i=e[2];const[f,p]=ie(i);let m;e[3]===Symbol.for("react.memo_cache_sentinel")?(m=new Set,e[3]=m):m=e[3];const x=Ce(m);let d,S;e[4]!==n||e[5]!==l?(d=()=>{const h={cancelled:!1};return ue((async()=>{try{const w=await n.query(Nn,{},_e(l));h.cancelled||(s(w.map(Rn)),a({}),p({}),x.current=new Set)}catch{h.cancelled||(s([]),a({}),p({}),x.current=new Set)}})()),()=>{h.cancelled=!0}},S=[n,l],e[4]=n,e[5]=l,e[6]=d,e[7]=S):(d=e[6],S=e[7]),Ne(d,S);let u;e[8]!==n||e[9]!==l?(u=h=>{if(x.current.has(h))return;x.current.add(h),ue((async()=>{try{const w=await n.query(kn,{limit:1,offset:0,table:h},_e(l)),{sqlColumns:R}=w;if(R===void 0){x.current.delete(h);return}const T=new Set(R),_=w.columns.filter(C=>!T.has(C));a(C=>({...C,[h]:R})),p(C=>({...C,[h]:_}))}catch{x.current.delete(h)}})())},e[8]=n,e[9]=l,e[10]=u):u=e[10];const v=u;let g;e[11]!==c||e[12]!==f||e[13]!==o?(g={columns:c,docFields:f,tables:o},e[11]=c,e[12]=f,e[13]=o,e[14]=g):g=e[14];const N=g;let y;return e[15]!==v||e[16]!==N?(y={probe:v,schema:N},e[15]=v,e[16]=N,e[17]=y):y=e[17],y},Pe=/\b(?:from|join|update|into)\s+([a-z_][\w$]*)|\b([a-z_][\w$]*)\s*\./gi,Tn=l=>{const e=new Set;Pe.lastIndex=0;let n=Pe.exec(l);for(;n!==null;)e.add(n[1]??n[2]),n=Pe.exec(l);return[...e]};function Rn(l){return l.name}const Ln=l=>{const e=Y(34),{onSubmit:n,probe:t,schema:o,setDraft:s}=l,r=pt(),c=Ce(null),a=Ce(null),i=Ce(null),f=yn(o,i,s),{close:p,commit:m,commitAt:x,move:d,refresh:S,state:u}=f;let v;e[0]!==x?(v=k=>{x(k)},e[0]=x,e[1]=v):v=e[1];const g=v;let N;e[2]!==S?(N=()=>{const k=i.current;k!==null&&k===document.activeElement&&S(k.value,k.selectionStart)},e[2]=S,e[3]=N):N=e[3];let y;e[4]!==S||e[5]!==o?(y=[S,o],e[4]=S,e[5]=o,e[6]=y):y=e[6],Ne(N,y);let h;e[7]!==t||e[8]!==S||e[9]!==s?(h=k=>{const{selectionStart:F,value:L}=k.target;s(L);for(const M of Tn(L))t(M);S(L,F)},e[7]=t,e[8]=S,e[9]=s,e[10]=h):h=e[10];const E=h;let w;e[11]!==S?(w=k=>{const F=k.currentTarget;S(F.value,F.selectionStart)},e[11]=S,e[12]=w):w=e[12];const R=w;let T;e[13]!==u||e[14]!==p||e[15]!==m||e[16]!==d||e[17]!==n?(T=k=>{if(u!==null){if(k.key==="ArrowDown"){k.preventDefault(),d(1);return}if(k.key==="ArrowUp"){k.preventDefault(),d(-1);return}if(k.key==="Escape"){k.preventDefault(),p();return}if((k.key==="Enter"||k.key==="Tab")&&!k.metaKey&&!k.ctrlKey&&m()){k.preventDefault();return}}(k.metaKey||k.ctrlKey)&&k.key==="Enter"&&(k.preventDefault(),n())},e[13]=u,e[14]=p,e[15]=m,e[16]=d,e[17]=n,e[18]=T):T=e[18];const _=T;let C;e[19]!==p?(C=()=>{requestAnimationFrame(()=>{p()})},e[19]=p,e[20]=C):C=e[20];const A=C;let q;e[21]===Symbol.for("react.memo_cache_sentinel")?(q=k=>{const{scrollLeft:F,scrollTop:L}=k.currentTarget;c.current!==null&&(c.current.scrollTop=L),a.current!==null&&(a.current.scrollTop=L,a.current.scrollLeft=F)},e[21]=q):q=e[21];const I=q;let B;e[22]===Symbol.for("react.memo_cache_sentinel")?(B=k=>{const F=i.current;F===null||k.offset===void 0||(F.focus(),F.setSelectionRange(k.offset,k.offset+(k.length??0)))},e[22]=B):B=e[22];const D=B;let P;e[23]!==E||e[24]!==A||e[25]!==_||e[26]!==R?(P={onBlur:A,onChange:E,onKeyDown:_,onScroll:I,onSelect:R},e[23]=E,e[24]=A,e[25]=_,e[26]=R,e[27]=P):P=e[27];let O;return e[28]!==u||e[29]!==p||e[30]!==r||e[31]!==g||e[32]!==P?(O={autocompleteState:u,closeAutocomplete:p,handlers:P,listboxId:r,onPickSuggestion:g,editorRef:i,gutterRef:c,overlayRef:a,revealDiagnostic:D},e[28]=u,e[29]=p,e[30]=r,e[31]=g,e[32]=P,e[33]=O):O=e[33],O},In="lunora-studio-sql-tabs",_n="lunora-studio-sql-active-tab",je=12,we=(l="",e="")=>({activeId:null,id:et("tab"),name:e,sql:l}),An=()=>ze(_n,""),qn=l=>{const e=Y(16),[n,t]=Fe(In),[o,s]=An(),[r]=ie(l);let c,a;e[0]!==r||e[1]!==t||e[2]!==n.length?(c=()=>{n.length===0&&t([r])},a=[r,t,n.length],e[0]=r,e[1]=t,e[2]=n.length,e[3]=c,e[4]=a):(c=e[3],a=e[4]),Ne(c,a);let i;e[5]!==r||e[6]!==n?(i=n.length===0?[r]:n,e[5]=r,e[6]=n,e[7]=i):i=e[7];const f=i;let p;e[8]!==o||e[9]!==f?(p=f.some(d=>d.id===o)?o:f[0]?.id??"",e[8]=o,e[9]=f,e[10]=p):p=e[10];const m=p;let x;return e[11]!==m||e[12]!==s||e[13]!==t||e[14]!==f?(x={activeId:m,setActiveId:s,setTabs:t,tabs:f},e[11]=m,e[12]=s,e[13]=t,e[14]=f,e[15]=x):x=e[15],x},dt=l=>l.activeId===null&&l.sql.trim()!=="",On=(l,e)=>[...l,e].slice(-je),Dn=(l,e,n)=>{const t=l.findIndex(r=>r.id===e);if(t===-1)return{activeId:l[0]?.id??"",tabs:[...l]};const o=l.filter(r=>r.id!==e);if(o.length===0){const r=n();return{activeId:r.id,tabs:[r]}}return{activeId:o[Math.min(t,o.length-1)].id,tabs:o}},Mn=(l,e)=>{const n=l.filter(t=>t.id===e);return n.length===0?{activeId:l[0]?.id??"",tabs:[...l]}:{activeId:e,tabs:n}},$n=(l,e,n)=>{const t=l.findIndex(s=>s.id===e);if(t===-1)return{activeId:n,tabs:[...l]};const o=l.slice(0,t+1);return{activeId:o.some(s=>s.id===n)?n:e,tabs:o}},Bn=l=>{const e=l();return{activeId:e.id,tabs:[e]}},Hn=(l,e,n)=>{if(l==="others")return e.filter(t=>t.id!==n);if(l==="right"){const t=e.findIndex(o=>o.id===n);return t===-1?[]:e.slice(t+1)}return[...e]},Xe={error:null,pane:"results",result:null,running:!1},Pn=l=>{const e=Y(66),{activeId:n,setActiveId:t,setTabs:o,tabs:s}=qn(l);let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={},e[0]=r):r=e[0];const[c,a]=ie(r),[i,f]=ie(null),[p,m]=ie(null);let x;e[1]!==n||e[2]!==s?(x=s.find(H=>H.id===n)??s[0]??we(),e[1]=n,e[2]=s,e[3]=x):x=e[3];const d=x,S=c[d.id]??Xe;let u;e[4]!==d.id||e[5]!==o?(u=H=>{o(U=>U.map(j=>j.id===d.id?{...j,...H}:j))},e[4]=d.id,e[5]=o,e[6]=u):u=e[6];const v=u;let g;e[7]!==d.id?(g=H=>{a(U=>{const j=U[d.id]??Xe;return{...U,[d.id]:{...j,...H}}})},e[7]=d.id,e[8]=g):g=e[8];const N=g;let y;e[9]!==t||e[10]!==o||e[11]!==s.length?(y=()=>{if(s.length>=je)return;const H=we();o(U=>On(U,H)),t(H.id)},e[9]=t,e[10]=o,e[11]=s.length,e[12]=y):y=e[12];const h=y;let E;e[13]!==t||e[14]!==o?(E=H=>{f(null),m(null),o(H.tabs),t(H.activeId);const U=new Set(H.tabs.map(Fn));a(j=>Object.fromEntries(Object.entries(j).filter(J=>{const[me]=J;return U.has(me)})))},e[13]=t,e[14]=o,e[15]=E):E=e[15];const w=E;let R;e[16]!==w||e[17]!==s?(R=H=>{w(Dn(s,H,we))},e[16]=w,e[17]=s,e[18]=R):R=e[18];const T=R;let _;e[19]!==n||e[20]!==w||e[21]!==s?(_=(H,U)=>{w(H==="others"?Mn(s,U):H==="right"?$n(s,U,n):Bn(we))},e[19]=n,e[20]=w,e[21]=s,e[22]=_):_=e[22];const C=_;let A;e[23]!==C||e[24]!==i||e[25]!==s?(A=H=>{i!==null&&(Hn(H,s,i.id).some(Wn)?m(H):C(H,i.id))},e[23]=C,e[24]=i,e[25]=s,e[26]=A):A=e[26];const q=A;let I;e[27]===Symbol.for("react.memo_cache_sentinel")?(I=(H,U)=>{U.preventDefault(),m(null),f({id:H,x:U.clientX,y:U.clientY})},e[27]=I):I=e[27];const B=I;let D;e[28]===Symbol.for("react.memo_cache_sentinel")?(D=()=>{f(null),m(null)},e[28]=D):D=e[28];const P=D;let O;e[29]===Symbol.for("react.memo_cache_sentinel")?(O=H=>{H.preventDefault(),f(null),m(null)},e[29]=O):O=e[29];const k=O;let F;e[30]!==q?(F=()=>{q("others")},e[30]=q,e[31]=F):F=e[31];const L=F;let M;e[32]!==q?(M=()=>{q("right")},e[32]=q,e[33]=M):M=e[33];const z=M;let $;e[34]!==q?($=()=>{q("all")},e[34]=q,e[35]=$):$=e[35];const X=$;let Z;e[36]!==C||e[37]!==p||e[38]!==i?(Z=()=>{i!==null&&p!==null&&C(p,i.id),m(null)},e[36]=C,e[37]=p,e[38]=i,e[39]=Z):Z=e[39];const ee=Z;let te;e[40]===Symbol.for("react.memo_cache_sentinel")?(te=()=>{m(null)},e[40]=te):te=e[40];const ae=te;let G;e[41]!==i?(G=i===null?void 0:{left:i.x,top:i.y},e[41]=i,e[42]=G):G=e[42];const Q=G;let ne;e[43]!==o?(ne=H=>{o(U=>U.map(j=>j.activeId===H?{...j,activeId:null}:j))},e[43]=o,e[44]=ne):ne=e[44];const se=ne;let oe;e[45]!==o?(oe=(H,U)=>{o(j=>j.map(J=>J.id===H?{...J,name:U}:J))},e[45]=o,e[46]=oe):oe=e[46];const le=oe;let re;return e[47]!==d||e[48]!==n||e[49]!==h||e[50]!==T||e[51]!==ee||e[52]!==X||e[53]!==L||e[54]!==z||e[55]!==S||e[56]!==N||e[57]!==v||e[58]!==p||e[59]!==le||e[60]!==t||e[61]!==i||e[62]!==Q||e[63]!==s||e[64]!==se?(re={activeTab:d,activeTabId:n,addEditorTab:h,cancelBulk:ae,closeEditorTab:T,closeTabMenu:P,confirmBulk:ee,menuStyle:Q,onBackdropContextMenu:k,onCloseAll:X,onCloseOthers:L,onCloseToRight:z,openTabMenu:B,output:S,patchActiveOutput:N,patchActiveTab:v,pendingBulk:p,renameTab:le,setActiveTabId:t,tabMenu:i,tabs:s,unlinkQuery:se},e[47]=d,e[48]=n,e[49]=h,e[50]=T,e[51]=ee,e[52]=X,e[53]=L,e[54]=z,e[55]=S,e[56]=N,e[57]=v,e[58]=p,e[59]=le,e[60]=t,e[61]=i,e[62]=Q,e[63]=s,e[64]=se,e[65]=re):re=e[65],re};function Fn(l){return l.id}function Wn(l){return dt(l)}const Qn="lunora-studio-sql-queries",Se="lunora-studio-sql-history",zn="lunora-studio-sql-remember-history",Un=25,jn=l=>{const e=Y(41),{loadIntoActiveTab:n,unlinkQuery:t}=l,o=de(),[s,r]=Fe(Qn),[c,a]=ze(zn,!1),[i,f]=Fe(Se,c?"local":"session");let p,m;e[0]!==c?(p=()=>{c||Re(Se,"local")},m=[c],e[0]=c,e[1]=p,e[2]=m):(p=e[1],m=e[2]),Ne(p,m);const[x,d]=ie(""),S=Ce(null);let u;e[3]!==f?(u=L=>{f(M=>M[0]?.sql===L?M:[{at:Date.now(),sql:L},...M.filter($=>$.sql!==L)].slice(0,Un))},e[3]=f,e[4]=u):u=e[4];const v=u;let g;e[5]!==n||e[6]!==r||e[7]!==o?(g=()=>{const L={id:et("q"),name:o("Untitled query"),sql:""};r(M=>[L,...M]),n("",L.id)},e[5]=n,e[6]=r,e[7]=o,e[8]=g):g=e[8];const N=g;let y;e[9]!==n||e[10]!==s?(y=L=>{const M=s.find(z=>z.id===L);M!==void 0&&(n(M.sql,L),S.current?.querySelector(`[data-testid="sql-query-${L}"]`)?.scrollIntoView({block:"nearest"}))},e[9]=n,e[10]=s,e[11]=y):y=e[11];const h=y;let E;e[12]!==r||e[13]!==t?(E=L=>{r(M=>M.filter(z=>z.id!==L)),t(L)},e[12]=r,e[13]=t,e[14]=E):E=e[14];const w=E;let R;e[15]!==n?(R=L=>{n(L.currentTarget.dataset.sql??"",null)},e[15]=n,e[16]=R):R=e[16];const T=R;let _;e[17]!==n?(_=L=>{n(L.currentTarget.dataset.sql??"",null)},e[17]=n,e[18]=_):_=e[18];const C=_;let A;e[19]!==f?(A=()=>{f([]),Re(Se,"local"),Re(Se,"session")},e[19]=f,e[20]=A):A=e[20];const q=A;let I;e[21]!==i||e[22]!==a?(I=L=>{bt(Se,i,L?"local":"session"),L||Re(Se,"local"),a(L)},e[21]=i,e[22]=a,e[23]=I):I=e[23];const B=I;let D;e[24]===Symbol.for("react.memo_cache_sentinel")?(D=L=>{d(L.target.value)},e[24]=D):D=e[24];const P=D;let O;e[25]!==r?(O=(L,M)=>{r(z=>z.map($=>$.id===L?{...$,sql:M}:$))},e[25]=r,e[26]=O):O=e[26];const k=O;let F;return e[27]!==q||e[28]!==w||e[29]!==i||e[30]!==C||e[31]!==T||e[32]!==N||e[33]!==s||e[34]!==v||e[35]!==c||e[36]!==x||e[37]!==h||e[38]!==B||e[39]!==k?(F={clearHistory:q,deleteQuery:w,history:i,listRef:S,loadFromHistory:C,loadTemplate:T,newQuery:N,onSearchChange:P,queries:s,recordHistory:v,rememberHistory:c,search:x,selectQuery:h,setRememberHistory:B,updateQuerySql:k},e[27]=q,e[28]=w,e[29]=i,e[30]=C,e[31]=T,e[32]=N,e[33]=s,e[34]=v,e[35]=c,e[36]=x,e[37]=h,e[38]=B,e[39]=k,e[40]=F):F=e[40],F},ut="p-3 font-mono text-xs leading-5 whitespace-pre-wrap break-words",Yn=(l,e)=>{const n=[];for(const o of l){if(o.offset===void 0||o.length===void 0||o.length<=0)continue;const s=Math.max(0,Math.min(o.offset,e)),r=Math.max(s,Math.min(o.offset+o.length,e));s!==r&&n.push({end:r,severity:o.severity,start:s})}n.sort((o,s)=>o.start-s.start);const t=[];for(const o of n)o.start>=(t.at(-1)?.end??0)&&t.push(o);return t},Kn=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.",Gn=l=>{const e=Y(51),{assistant:n,failed:t,onGenerated:o}=l,s=de(),[r,c]=ie("");if(n.unavailable)return null;let a;e[0]!==n?(a=n.pending("sql"),e[0]=n,e[1]=a):a=e[1];const i=a;let f;if(e[2]!==n||e[3]!==t||e[4]!==o||e[5]!==i||e[6]!==r||e[7]!==s){const p=n.reason("sql");let m;e[9]!==n||e[10]!==t||e[11]!==o||e[12]!==r?(m=C=>{const A=r.trim();if(A===""&&!C)return;ue((async()=>{const I=await n.generate(A===""?"fix the failing statement":A,C?t:void 0);I!==void 0&&o(I)})())},e[9]=n,e[10]=t,e[11]=o,e[12]=r,e[13]=m):m=e[13];const x=m;let d;e[14]!==s?(d=s("Describe the query you want"),e[14]=s,e[15]=d):d=e[15];let S;e[16]===Symbol.for("react.memo_cache_sentinel")?(S=C=>{c(C.target.value)},e[16]=S):S=e[16];let u;e[17]!==x?(u=C=>{C.key==="Enter"&&(C.preventDefault(),x(!1))},e[17]=x,e[18]=u):u=e[18];let v;e[19]!==s?(v=s("Describe the query you want"),e[19]=s,e[20]=v):v=e[20];let g;e[21]!==i||e[22]!==r||e[23]!==d||e[24]!==u||e[25]!==v?(g=b(St,{"aria-label":d,className:"h-7 flex-1 text-xs","data-testid":"sql-assistant-prompt",disabled:i,onChange:S,onKeyDown:u,placeholder:v,value:r}),e[21]=i,e[22]=r,e[23]=d,e[24]=u,e[25]=v,e[26]=g):g=e[26];const N=i&&"opacity-60";let y;e[27]!==N?(y=fe("rounded-md border border-border px-2 py-1 text-xs outline-none transition-colors hover:bg-accent focus-visible:bg-accent",N),e[27]=N,e[28]=y):y=e[28];let h;e[29]!==i||e[30]!==r?(h=i||r.trim()==="",e[29]=i,e[30]=r,e[31]=h):h=e[31];let E;e[32]!==x?(E=()=>{x(!1)},e[32]=x,e[33]=E):E=e[33];let w;e[34]!==i||e[35]!==s?(w=s(i?"Thinking…":"Draft SQL"),e[34]=i,e[35]=s,e[36]=w):w=e[36];let R;e[37]!==y||e[38]!==h||e[39]!==E||e[40]!==w?(R=b("button",{className:y,"data-testid":"sql-assistant-generate",disabled:h,onClick:E,type:"button",children:w}),e[37]=y,e[38]=h,e[39]=E,e[40]=w,e[41]=R):R=e[41];let T;e[42]!==t||e[43]!==i||e[44]!==x||e[45]!==s?(T=t!==void 0&&b("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:s("Fix this")}),e[42]=t,e[43]=i,e[44]=x,e[45]=s,e[46]=T):T=e[46];let _;e[47]!==R||e[48]!==T||e[49]!==g?(_=W("div",{className:"flex items-center gap-2",children:[g,R,T]}),e[47]=R,e[48]=T,e[49]=g,e[50]=_):_=e[50],f=W("div",{className:"flex flex-col gap-1 border-b border-border px-3 py-2","data-testid":"sql-assistant",children:[_,p!==void 0&&b("p",{className:"text-[11px] text-muted-foreground","data-testid":"sql-assistant-reason",role:"status",children:Kn(p)})]}),e[2]=n,e[3]=t,e[4]=o,e[5]=i,e[6]=r,e[7]=s,e[8]=f}else f=e[8];return f},Jn=l=>{const e=Y(8),{diagnostics:n,draft:t,scrollRef:o}=l;let s,r;if(e[0]!==n||e[1]!==t){r=Symbol.for("react.early_return_sentinel");e:{const i=Yn(n,t.length);if(i.length===0){r=null;break e}s=[];let f=0;for(const[p,m]of i.entries())m.start>f&&s.push(t.slice(f,m.start)),s.push(b("span",{className:fe("decoration-wavy underline underline-offset-4",m.severity==="error"?"decoration-destructive":"decoration-amber-500"),children:t.slice(m.start,m.end)},`${m.start.toString()}-${p.toString()}`)),f=m.end;s.push(t.slice(f))}e[0]=n,e[1]=t,e[2]=s,e[3]=r}else s=e[2],r=e[3];if(r!==Symbol.for("react.early_return_sentinel"))return r;let c;e[4]===Symbol.for("react.memo_cache_sentinel")?(c=fe("pointer-events-none absolute inset-0 overflow-hidden text-transparent",ut),e[4]=c):c=e[4];let a;return e[5]!==s||e[6]!==o?(a=b("div",{"aria-hidden":"true",className:c,"data-testid":"sql-diagnostics-overlay",ref:o,children:s}),e[5]=s,e[6]=o,e[7]=a):a=e[7],a},Vn={gate:"read-only",plan:"plan",schema:"schema",syntax:"syntax"},Xn=l=>{const e=Y(10),{diagnostics:n,onSelect:t}=l,o=de();if(n.length===0)return null;let s;e[0]!==o?(s=o("SQL problems"),e[0]=o,e[1]=s):s=e[1];let r;if(e[2]!==n||e[3]!==t){let a;e[5]!==t?(a=(i,f)=>b("li",{children:W("button",{className:"flex w-full items-start gap-2 px-3 py-1 text-start text-xs outline-none hover:bg-accent focus-visible:bg-accent","data-testid":"sql-problem",onClick:()=>{t(i)},type:"button",children:[b("span",{className:fe("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:Vn[i.source]}),b("span",{className:"min-w-0 text-muted-foreground",children:i.message})]})},`${i.source}-${(i.offset??f).toString()}-${f.toString()}`),e[5]=t,e[6]=a):a=e[6],r=n.map(a),e[2]=n,e[3]=t,e[4]=r}else r=e[4];let c;return e[7]!==s||e[8]!==r?(c=b("ul",{"aria-label":s,className:"max-h-24 shrink-0 overflow-y-auto border-t border-border bg-muted/30","data-testid":"sql-problems",children:r}),e[7]=s,e[8]=r,e[9]=c):c=e[9],c},Zn={minWidth:"2.75rem",paddingInline:"0.5rem"},es=l=>{const e=Y(64),{assistant:n,autocomplete:t,diagnostics:o,draft:s,failed:r,handlers:c,editorRef:a,gutterRef:i,listboxId:f,onGenerated:p,onPickSuggestion:m,onRevealDiagnostic:x,overlayRef:d}=l,S=de();let u,v,g,N,y,h,E,w;if(e[0]!==n||e[1]!==s||e[2]!==r||e[3]!==i||e[4]!==p){const F=s.split(`
7
+ `).length;E="flex min-h-0 min-w-0 flex-1 flex-col",e[13]!==n||e[14]!==r||e[15]!==p?(w=b(Gn,{assistant:n,failed:r,onGenerated:p}),e[13]=n,e[14]=r,e[15]=p,e[16]=w):w=e[16],h="flex min-h-0 min-w-0 flex-1",u="true",v="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",g=i,N=Zn,y=Array.from({length:F},ts),e[0]=n,e[1]=s,e[2]=r,e[3]=i,e[4]=p,e[5]=u,e[6]=v,e[7]=g,e[8]=N,e[9]=y,e[10]=h,e[11]=E,e[12]=w}else u=e[5],v=e[6],g=e[7],N=e[8],y=e[9],h=e[10],E=e[11],w=e[12];let R;e[17]!==u||e[18]!==v||e[19]!==g||e[20]!==N||e[21]!==y?(R=b("div",{"aria-hidden":u,className:v,ref:g,style:N,children:y}),e[17]=u,e[18]=v,e[19]=g,e[20]=N,e[21]=y,e[22]=R):R=e[22];let T;e[23]!==o||e[24]!==s||e[25]!==d?(T=b(Jn,{diagnostics:o,draft:s,scrollRef:d}),e[23]=o,e[24]=s,e[25]=d,e[26]=T):T=e[26];let _;e[27]!==t||e[28]!==f?(_=t===null?void 0:`${f}-opt-${t.active.toString()}`,e[27]=t,e[28]=f,e[29]=_):_=e[29];const C=t===null?void 0:f,A=t!==null;let q;e[30]!==S?(q=S("SQL query"),e[30]=S,e[31]=q):q=e[31];let I;e[32]!==s||e[33]!==a||e[34]!==c.onBlur||e[35]!==c.onChange||e[36]!==c.onKeyDown||e[37]!==c.onScroll||e[38]!==c.onSelect||e[39]!==_||e[40]!==C||e[41]!==A||e[42]!==q?(I=b("textarea",{"aria-activedescendant":_,"aria-autocomplete":"list","aria-controls":C,"aria-expanded":A,"aria-label":q,className:`relative size-full resize-none bg-transparent outline-none ${ut}`,"data-testid":"sql-input",onBlur:c.onBlur,onChange:c.onChange,onKeyDown:c.onKeyDown,onScroll:c.onScroll,onSelect:c.onSelect,placeholder:"SELECT * FROM …",ref:a,role:"combobox",spellCheck:!1,value:s}),e[32]=s,e[33]=a,e[34]=c.onBlur,e[35]=c.onChange,e[36]=c.onKeyDown,e[37]=c.onScroll,e[38]=c.onSelect,e[39]=_,e[40]=C,e[41]=A,e[42]=q,e[43]=I):I=e[43];let B;e[44]!==t||e[45]!==f||e[46]!==m?(B=b(Cn,{listboxId:f,onPick:m,state:t}),e[44]=t,e[45]=f,e[46]=m,e[47]=B):B=e[47];let D;e[48]!==T||e[49]!==I||e[50]!==B?(D=W("div",{className:"relative min-w-0 flex-1 bg-background",children:[T,I,B]}),e[48]=T,e[49]=I,e[50]=B,e[51]=D):D=e[51];let P;e[52]!==D||e[53]!==h||e[54]!==R?(P=W("div",{className:h,children:[R,D]}),e[52]=D,e[53]=h,e[54]=R,e[55]=P):P=e[55];let O;e[56]!==o||e[57]!==x?(O=b(Xn,{diagnostics:o,onSelect:x}),e[56]=o,e[57]=x,e[58]=O):O=e[58];let k;return e[59]!==P||e[60]!==O||e[61]!==E||e[62]!==w?(k=W("div",{className:E,children:[w,P,O]}),e[59]=P,e[60]=O,e[61]=E,e[62]=w,e[63]=k):k=e[63],k};function ts(l,e){return b("div",{children:e+1},e)}const ft=[{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;"}],ns=l=>{const e=Y(29),{active:n,onDelete:t,onSelect:o,query:s}=l,r=de();let c;e[0]!==o||e[1]!==s.id?(c=()=>{o(s.id)},e[0]=o,e[1]=s.id,e[2]=c):c=e[2];const a=c;let i;e[3]!==t||e[4]!==s.id?(i=E=>{E.stopPropagation(),t(s.id)},e[3]=t,e[4]=s.id,e[5]=i):i=e[5];const f=i,p=n?"bg-sidebar-accent font-medium text-foreground":"text-muted-foreground";let m;e[6]!==p?(m=fe("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",p),e[6]=p,e[7]=m):m=e[7];const x=`sql-query-${s.id}`;let d;e[8]===Symbol.for("react.memo_cache_sentinel")?(d=b("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:b("path",{d:"M4 6h16M4 12h10M4 18h7"})}),e[8]=d):d=e[8];let S;e[9]!==s.name?(S=b("span",{className:"truncate",children:s.name}),e[9]=s.name,e[10]=S):S=e[10];let u;e[11]!==n||e[12]!==a||e[13]!==m||e[14]!==x||e[15]!==S?(u=W("button",{"aria-pressed":n,className:m,"data-testid":x,onClick:a,type:"button",children:[d,S]}),e[11]=n,e[12]=a,e[13]=m,e[14]=x,e[15]=S,e[16]=u):u=e[16];let v;e[17]!==r?(v=r("Delete query"),e[17]=r,e[18]=v):v=e[18];let g;e[19]!==r?(g=r("Delete query"),e[19]=r,e[20]=g):g=e[20];let N;e[21]===Symbol.for("react.memo_cache_sentinel")?(N=b("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:b("path",{d:"M5 7h14M9 7V5h6v2m-1 0v12H10V7M7 7v13h10V7"})}),e[21]=N):N=e[21];let y;e[22]!==f||e[23]!==g||e[24]!==v?(y=b("button",{"aria-label":v,className:"me-1 hidden size-6 shrink-0 items-center justify-center rounded text-muted-foreground hover:bg-destructive/10 hover:text-destructive group-hover/q:flex",onClick:f,title:g,type:"button",children:N}),e[22]=f,e[23]=g,e[24]=v,e[25]=y):y=e[25];let h;return e[26]!==y||e[27]!==u?(h=W("li",{className:"group/q flex items-center",children:[u,y]}),e[26]=y,e[27]=u,e[28]=h):h=e[28],h},Ze="sql-history-remember",ss=(l,e)=>{const n=e.trim().toLowerCase();return n===""?[...l]:l.filter(t=>t.name.toLowerCase().includes(n))},os=l=>{const e=Y(66),{activeId:n,history:t,listRef:o,onClearHistory:s,onDelete:r,onLoadHistory:c,onLoadTemplate:a,onNew:i,onSearchChange:f,onSelect:p,onToggleRememberHistory:m,queries:x,rememberHistory:d,search:S}=l,u=de();let v,g,N,y,h;if(e[0]!==n||e[1]!==o||e[2]!==r||e[3]!==i||e[4]!==f||e[5]!==p||e[6]!==m||e[7]!==x||e[8]!==S||e[9]!==u){const I=ss(x,S);let B;e[15]!==m?(B=$=>{m($.target.checked)},e[15]=m,e[16]=B):B=e[16],v=B,N="flex h-full w-64 shrink-0 flex-col border-e border-border bg-sidebar";let D;e[17]!==u?(D=u("Search queries…"),e[17]=u,e[18]=D):D=e[18];let P;e[19]!==f||e[20]!==S||e[21]!==D?(P=b("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:D,type:"text",value:S}),e[19]=f,e[20]=S,e[21]=D,e[22]=P):P=e[22];let O;e[23]!==u?(O=u("New query"),e[23]=u,e[24]=O):O=e[24];let k;e[25]!==u?(k=u("New query"),e[25]=u,e[26]=k):k=e[26];let F;e[27]===Symbol.for("react.memo_cache_sentinel")?(F=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:b("path",{d:"M12 5v14M5 12h14"})}),e[27]=F):F=e[27];let L;e[28]!==i||e[29]!==O||e[30]!==k?(L=b("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:k,type:"button",children:F}),e[28]=i,e[29]=O,e[30]=k,e[31]=L):L=e[31],e[32]!==L||e[33]!==P?(y=W("div",{className:"flex shrink-0 items-center gap-2 border-b border-border p-2",children:[P,L]}),e[32]=L,e[33]=P,e[34]=y):y=e[34],g="flex flex-1 flex-col gap-4 overflow-y-auto p-2";let M;e[35]!==u?(M=u("Private"),e[35]=u,e[36]=M):M=e[36];let z;e[37]!==M?(z=b("p",{className:"px-1 pb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:M}),e[37]=M,e[38]=z):z=e[38],h=W("div",{children:[z,I.length===0?b("p",{className:"px-1 py-2 text-xs text-muted-foreground","data-testid":"sql-private-empty",children:u("No saved queries yet — they save to this browser as you type.")}):b("ul",{className:"flex flex-col gap-px","data-testid":"sql-private",ref:o,children:I.map($=>b(ns,{active:n===$.id,onDelete:r,onSelect:p,query:$},$.id))})]}),e[0]=n,e[1]=o,e[2]=r,e[3]=i,e[4]=f,e[5]=p,e[6]=m,e[7]=x,e[8]=S,e[9]=u,e[10]=v,e[11]=g,e[12]=N,e[13]=y,e[14]=h}else v=e[10],g=e[11],N=e[12],y=e[13],h=e[14];let E;e[39]!==u?(E=u("Reference"),e[39]=u,e[40]=E):E=e[40];let w;e[41]!==E?(w=b("p",{className:"px-1 pb-1 font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:E}),e[41]=E,e[42]=w):w=e[42];let R;e[43]!==a?(R=ft.map(I=>b("li",{children:W("button",{className:"flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-start text-[13px] text-muted-foreground outline-none transition-colors hover:bg-sidebar-accent hover:text-foreground focus-visible:bg-sidebar-accent","data-sql":I.sql,onClick:a,type:"button",children:[b("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:b("path",{d:"M7 4h7l4 4v12H7zM14 4v4h4"})}),I.label]})},I.label)),e[43]=a,e[44]=R):R=e[44];let T;e[45]!==R?(T=b("ul",{className:"flex flex-col gap-px",children:R}),e[45]=R,e[46]=T):T=e[46];let _;e[47]!==w||e[48]!==T?(_=W("div",{children:[w,T]}),e[47]=w,e[48]=T,e[49]=_):_=e[49];let C;e[50]!==t||e[51]!==s||e[52]!==c||e[53]!==v||e[54]!==d||e[55]!==u?(C=t.length>0&&W("div",{children:[W("div",{className:"flex items-center justify-between px-1 pb-1",children:[b("p",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:u("History")}),b("button",{className:"rounded px-1 text-[11px] text-muted-foreground outline-none transition-colors hover:text-foreground focus-visible:text-foreground","data-testid":"sql-history-clear",onClick:s,type:"button",children:u("Clear history")})]}),W("label",{className:"flex cursor-pointer items-center gap-1.5 px-1 pb-1.5 text-[11px] text-muted-foreground",htmlFor:Ze,children:[b("input",{checked:d,"data-testid":"sql-history-remember",id:Ze,onChange:v,type:"checkbox"}),u("Keep history on this browser")]}),b("ul",{className:"flex flex-col gap-px","data-testid":"sql-history",children:t.map(I=>b("li",{children:W("button",{className:"flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-start text-[13px] text-muted-foreground outline-none transition-colors hover:bg-sidebar-accent hover:text-foreground focus-visible:bg-sidebar-accent","data-sql":I.sql,"data-testid":"sql-history-item",onClick:c,title:I.sql,type:"button",children:[b("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:b("path",{d:"M12 8v4l3 2M12 21a9 9 0 1 1 0-18 9 9 0 0 1 0 18Z"})}),b("span",{className:"truncate font-mono",children:I.sql})]})},`${I.at.toString()}:${I.sql}`))})]}),e[50]=t,e[51]=s,e[52]=c,e[53]=v,e[54]=d,e[55]=u,e[56]=C):C=e[56];let A;e[57]!==g||e[58]!==C||e[59]!==h||e[60]!==_?(A=W("div",{className:g,children:[h,_,C]}),e[57]=g,e[58]=C,e[59]=h,e[60]=_,e[61]=A):A=e[61];let q;return e[62]!==A||e[63]!==N||e[64]!==y?(q=W("aside",{className:N,children:[y,A]}),e[62]=A,e[63]=N,e[64]=y,e[65]=q):q=e[65],q},Ie=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"}`,ls=l=>{const e=Y(96),{assistant:n,chart:t,className:o,error:s,onFormat:r,onInferChart:c,onRun:a,onSelectStatement:i,onShardKeyChange:f,onShowChart:p,onShowExplain:m,onShowResults:x,onToggleSplit:d,pane:S,result:u,running:v,script:g,shardKey:N,splitView:y}=l,h=de(),E=S==="results";let w;e[0]!==E?(w=Ie(E),e[0]=E,e[1]=w):w=e[1];let R;e[2]!==h?(R=h("Results"),e[2]=h,e[3]=R):R=e[3];let T;e[4]!==x||e[5]!==w||e[6]!==R?(T=b("button",{className:w,"data-testid":"sql-tab-results",onClick:x,type:"button",children:R}),e[4]=x,e[5]=w,e[6]=R,e[7]=T):T=e[7];const _=S==="chart";let C;e[8]!==_?(C=Ie(_),e[8]=_,e[9]=C):C=e[9];let A;e[10]!==h?(A=h("Chart"),e[10]=h,e[11]=A):A=e[11];let q;e[12]!==p||e[13]!==C||e[14]!==A?(q=b("button",{className:C,"data-testid":"sql-tab-chart",onClick:p,type:"button",children:A}),e[12]=p,e[13]=C,e[14]=A,e[15]=q):q=e[15];let I;e[16]!==n||e[17]!==c||e[18]!==S||e[19]!==u||e[20]!==h?(I=!n.unavailable&&S==="chart"&&u!==null&&b("button",{className:Ie(!1),"data-testid":"sql-infer-chart",disabled:n.pending("chart"),onClick:c,type:"button",children:n.pending("chart")?h("Thinking…"):h("Suggest chart")}),e[16]=n,e[17]=c,e[18]=S,e[19]=u,e[20]=h,e[21]=I):I=e[21];const B=S==="explain";let D;e[22]!==B?(D=Ie(B),e[22]=B,e[23]=D):D=e[23];let P;e[24]!==h?(P=h("Explain"),e[24]=h,e[25]=P):P=e[25];let O;e[26]!==m||e[27]!==D||e[28]!==P?(O=b("button",{className:D,"data-testid":"sql-tab-explain",onClick:m,type:"button",children:P}),e[26]=m,e[27]=D,e[28]=P,e[29]=O):O=e[29];let k;e[30]!==h?(k=h("Split editor and results"),e[30]=h,e[31]=k):k=e[31];const F=`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 ${y?"bg-accent text-foreground":"text-muted-foreground"}`;let L;e[32]!==h?(L=h("Split editor and results"),e[32]=h,e[33]=L):L=e[33];let M;e[34]===Symbol.for("react.memo_cache_sentinel")?(M=W("svg",{"aria-hidden":"true",className:"size-4",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.7,viewBox:"0 0 24 24",children:[b("rect",{height:"16",rx:"2",width:"18",x:"3",y:"4"}),b("path",{d:"M12 4v16"})]}),e[34]=M):M=e[34];let z;e[35]!==d||e[36]!==y||e[37]!==k||e[38]!==F||e[39]!==L?(z=b("button",{"aria-label":k,"aria-pressed":y,className:F,"data-testid":"sql-split-toggle",onClick:d,title:L,type:"button",children:M}),e[35]=d,e[36]=y,e[37]=k,e[38]=F,e[39]=L,e[40]=z):z=e[40];let $;e[41]!==u?($=u!==null&&u.columns.length>0&&b(Et,{columns:u.columns,name:"query-result",rows:u.rows}),e[41]=u,e[42]=$):$=e[42];let X;e[43]!==h?(X=h("Format"),e[43]=h,e[44]=X):X=e[44];let Z;e[45]!==r||e[46]!==v||e[47]!==X?(Z=b("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:r,type:"button",children:X}),e[45]=r,e[46]=v,e[47]=X,e[48]=Z):Z=e[48];let ee;e[49]!==f||e[50]!==N?(ee=b(Nt,{onChange:f,testId:"sql-shard-input",value:N}),e[49]=f,e[50]=N,e[51]=ee):ee=e[51];let te;e[52]!==v||e[53]!==h?(te=h(v?"Running…":"Run"),e[52]=v,e[53]=h,e[54]=te):te=e[54];let ae;e[55]===Symbol.for("react.memo_cache_sentinel")?(ae=b("kbd",{className:"rounded border border-primary-foreground/30 px-1 font-sans text-[10px]",children:"⌘↵"}),e[55]=ae):ae=e[55];let G;e[56]!==a||e[57]!==v||e[58]!==te?(G=W("button",{className:"inline-flex items-center gap-1.5 rounded-md bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground outline-none transition-colors hover:bg-primary/90 focus-visible:bg-primary/90 disabled:pointer-events-none disabled:opacity-50","data-testid":"sql-run",disabled:v,onClick:a,type:"button",children:[te,ae]}),e[56]=a,e[57]=v,e[58]=te,e[59]=G):G=e[59];let Q;e[60]!==z||e[61]!==$||e[62]!==Z||e[63]!==ee||e[64]!==G?(Q=W("div",{className:"ms-auto flex items-center gap-2",children:[z,$,Z,ee,G]}),e[60]=z,e[61]=$,e[62]=Z,e[63]=ee,e[64]=G,e[65]=Q):Q=e[65];let ne;e[66]!==O||e[67]!==Q||e[68]!==T||e[69]!==q||e[70]!==I?(ne=W("div",{className:"flex shrink-0 items-center gap-2 border-b border-border pe-2",children:[T,q,I,O,Q]}),e[66]=O,e[67]=Q,e[68]=T,e[69]=q,e[70]=I,e[71]=ne):ne=e[71];let se;e[72]!==i||e[73]!==g?(se=g!==void 0&&b("div",{className:"flex shrink-0 flex-wrap items-center gap-1 border-b border-border px-3 py-1.5","data-testid":"sql-statements",children:g.runs.map((j,J)=>b("button",{"aria-pressed":J===g.selected,className:`rounded-md border px-2 py-0.5 font-mono text-[11px] outline-none transition-colors ${J===g.selected?"border-foreground text-foreground":"border-border text-muted-foreground hover:text-foreground"} ${j.error===null?"":"border-destructive/50 text-destructive"}`,"data-testid":`sql-statement-${J.toString()}`,onClick:()=>{i(J)},title:j.sql,type:"button",children:J+1},`${J.toString()}:${j.sql}`))}),e[72]=i,e[73]=g,e[74]=se):se=e[74];let oe;e[75]!==s?(oe=s!==null&&b(kt,{className:"m-3 font-mono text-xs",testId:"sql-error",variant:"destructive",children:s}),e[75]=s,e[76]=oe):oe=e[76];let le;e[77]!==s||e[78]!==u||e[79]!==h?(le=s===null&&u===null&&b("p",{className:"p-4 text-sm text-muted-foreground","data-testid":"sql-empty",children:h("Click Run to execute your query.")}),e[77]=s,e[78]=u,e[79]=h,e[80]=le):le=e[80];let re;e[81]!==t||e[82]!==s||e[83]!==S||e[84]!==u||e[85]!==h?(re=s===null&&u!==null&&W("div",{"data-testid":"sql-result",children:[S==="chart"?b(wt,{axes:t,result:u}):b(Ct,{result:u}),b("p",{className:"border-t border-border px-3 py-1.5 text-xs text-muted-foreground","data-testid":"sql-count",children:u.truncated?h("Showing the first {max} of {count} rows.",{count:u.rowCount,max:u.rows.length}):h("{count} rows",{count:u.rowCount})})]}),e[81]=t,e[82]=s,e[83]=S,e[84]=u,e[85]=h,e[86]=re):re=e[86];let H;e[87]!==oe||e[88]!==le||e[89]!==re?(H=W("div",{className:"min-h-0 flex-1 overflow-auto",children:[oe,le,re]}),e[87]=oe,e[88]=le,e[89]=re,e[90]=H):H=e[90];let U;return e[91]!==o||e[92]!==ne||e[93]!==se||e[94]!==H?(U=W("div",{className:o,children:[ne,se,H]}),e[91]=o,e[92]=ne,e[93]=se,e[94]=H,e[95]=U):U=e[95],U},rs=(l,e)=>l.trim()===""?e:(l.split(`
8
+ `)[0]??l).slice(0,24),is=l=>{l?.focus(),l?.select()},as=l=>{const e=Y(14),{initial:n,onCancel:t,onCommit:o,placeholder:s,testId:r}=l,c=de();let a;e[0]!==o?(a=d=>{o(d.currentTarget.value.trim())},e[0]=o,e[1]=a):a=e[1];const i=a;let f;e[2]!==t||e[3]!==o?(f=d=>{d.key==="Enter"?o(d.currentTarget.value.trim()):d.key==="Escape"&&t()},e[2]=t,e[3]=o,e[4]=f):f=e[4];const p=f;let m;e[5]!==c?(m=c("Tab title"),e[5]=c,e[6]=m):m=e[6];let x;return e[7]!==n||e[8]!==i||e[9]!==p||e[10]!==s||e[11]!==m||e[12]!==r?(x=b("input",{"aria-label":m,className:"w-40 rounded border border-ring bg-background px-1 py-0.5 text-xs outline-none","data-testid":r,defaultValue:n,onBlur:i,onKeyDown:p,placeholder:s,ref:is,type:"text"}),e[7]=n,e[8]=i,e[9]=p,e[10]=s,e[11]=m,e[12]=r,e[13]=x):x=e[13],x},cs=l=>{const e=Y(29),{idBase:n,onDiscard:t,onKeep:o}=l,s=de(),r=`sql-tab-close-prompt-${n}`;let c;e[0]!==s?(c=s("Discard?"),e[0]=s,e[1]=c):c=e[1];let a;e[2]!==c?(a=b("span",{className:"text-[11px] text-muted-foreground",children:c}),e[2]=c,e[3]=a):a=e[3];let i;e[4]!==s?(i=s("Discard changes"),e[4]=s,e[5]=i):i=e[5];const f=`sql-tab-close-confirm-${n}`;let p;e[6]!==s?(p=s("Discard changes"),e[6]=s,e[7]=p):p=e[7];let m;e[8]===Symbol.for("react.memo_cache_sentinel")?(m=b("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2.4,viewBox:"0 0 24 24",children:b("path",{d:"M5 13l4 4L19 7"})}),e[8]=m):m=e[8];let x;e[9]!==t||e[10]!==i||e[11]!==f||e[12]!==p?(x=b("button",{"aria-label":i,className:"flex size-5 items-center justify-center rounded text-destructive hover:bg-destructive/10","data-testid":f,onClick:t,title:p,type:"button",children:m}),e[9]=t,e[10]=i,e[11]=f,e[12]=p,e[13]=x):x=e[13];let d;e[14]!==s?(d=s("Keep editing"),e[14]=s,e[15]=d):d=e[15];const S=`sql-tab-close-cancel-${n}`;let u;e[16]!==s?(u=s("Keep editing"),e[16]=s,e[17]=u):u=e[17];let v;e[18]===Symbol.for("react.memo_cache_sentinel")?(v=b("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2.4,viewBox:"0 0 24 24",children:b("path",{d:"M6 6l12 12M18 6 6 18"})}),e[18]=v):v=e[18];let g;e[19]!==o||e[20]!==S||e[21]!==u||e[22]!==d?(g=b("button",{"aria-label":d,className:"flex size-5 items-center justify-center rounded text-muted-foreground hover:bg-accent","data-testid":S,onClick:o,title:u,type:"button",children:v}),e[19]=o,e[20]=S,e[21]=u,e[22]=d,e[23]=g):g=e[23];let N;return e[24]!==r||e[25]!==g||e[26]!==a||e[27]!==x?(N=W("span",{className:"flex shrink-0 items-center gap-1","data-testid":r,role:"group",children:[a,x,g]}),e[24]=r,e[25]=g,e[26]=a,e[27]=x,e[28]=N):N=e[28],N},ds=l=>{const e=Y(47),{active:n,canClose:t,onClose:o,onMenu:s,onRename:r,onSelect:c,tab:a}=l,i=de(),[f,p]=ie(!1),[m,x]=ie(!1);let d;e[0]!==s||e[1]!==a.id?(d=$=>{s(a.id,$)},e[0]=s,e[1]=a.id,e[2]=d):d=e[2];const S=d;let u;e[3]!==c||e[4]!==a.id?(u=()=>{c(a.id)},e[3]=c,e[4]=a.id,e[5]=u):u=e[5];const v=u;let g;e[6]===Symbol.for("react.memo_cache_sentinel")?(g=()=>{p(!0)},e[6]=g):g=e[6];const N=g;let y;e[7]!==o||e[8]!==a?(y=$=>{$.stopPropagation(),dt(a)?x(!0):o(a.id)},e[7]=o,e[8]=a,e[9]=y):y=e[9];const h=y;let E;e[10]!==o||e[11]!==a.id?(E=$=>{$.stopPropagation(),x(!1),o(a.id)},e[10]=o,e[11]=a.id,e[12]=E):E=e[12];const w=E;let R;e[13]===Symbol.for("react.memo_cache_sentinel")?(R=$=>{$.stopPropagation(),x(!1)},e[13]=R):R=e[13];const T=R;let _;e[14]!==r||e[15]!==a.id?(_=$=>{r(a.id,$),p(!1)},e[14]=r,e[15]=a.id,e[16]=_):_=e[16];const C=_;let A;e[17]===Symbol.for("react.memo_cache_sentinel")?(A=()=>{p(!1)},e[17]=A):A=e[17];const q=A;let I;e[18]!==a.name?(I=a.name.trim(),e[18]=a.name,e[19]=I):I=e[19];const B=I;let D;e[20]!==i||e[21]!==a.sql?(D=rs(a.sql,i("Untitled")),e[20]=i,e[21]=a.sql,e[22]=D):D=e[22];const P=D,O=n?"bg-background text-foreground":"bg-muted/40 text-muted-foreground hover:text-foreground";let k;e[23]!==O?(k=fe("group/tab flex shrink-0 items-center gap-1 border-e border-border ps-3 pe-1.5 text-xs",O),e[23]=O,e[24]=k):k=e[24];const F=`sql-tab-${a.id}`;let L;e[25]!==n||e[26]!==C||e[27]!==B||e[28]!==P||e[29]!==f||e[30]!==v||e[31]!==i||e[32]!==a.id?(L=f?b(as,{initial:B,onCancel:q,onCommit:C,placeholder:P,testId:`sql-tab-rename-${a.id}`}):b("button",{"aria-pressed":n,className:"max-w-40 truncate py-1.5 outline-none","data-testid":`sql-tab-select-${a.id}`,onClick:v,onDoubleClick:N,title:i("Double-click to rename"),type:"button",children:B===""?P:B}),e[25]=n,e[26]=C,e[27]=B,e[28]=P,e[29]=f,e[30]=v,e[31]=i,e[32]=a.id,e[33]=L):L=e[33];let M;e[34]!==t||e[35]!==w||e[36]!==m||e[37]!==h||e[38]!==i||e[39]!==a.id?(M=t&&(m?b(cs,{idBase:a.id,onDiscard:w,onKeep:T}):b("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:h,title:i("Close tab"),type:"button",children:b("svg",{"aria-hidden":"true",className:"size-3",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,viewBox:"0 0 24 24",children:b("path",{d:"M6 6l12 12M18 6 6 18"})})})),e[34]=t,e[35]=w,e[36]=m,e[37]=h,e[38]=i,e[39]=a.id,e[40]=M):M=e[40];let z;return e[41]!==S||e[42]!==k||e[43]!==F||e[44]!==L||e[45]!==M?(z=W("div",{className:k,"data-testid":F,onContextMenu:S,children:[L,M]}),e[41]=S,e[42]=k,e[43]=F,e[44]=L,e[45]=M,e[46]=z):z=e[46],z},us=l=>{const e=Y(43),{model:n,onSelect:t}=l,o=de(),{activeTab:s,addEditorTab:r,cancelBulk:c,closeEditorTab:a,closeTabMenu:i,confirmBulk:f,menuStyle:p,onBackdropContextMenu:m,onCloseAll:x,onCloseOthers:d,onCloseToRight:S,openTabMenu:u,pendingBulk:v,renameTab:g,tabMenu:N,tabs:y}=n;let h;if(e[0]!==s||e[1]!==a||e[2]!==t||e[3]!==u||e[4]!==g||e[5]!==y){let I;e[7]!==s||e[8]!==a||e[9]!==t||e[10]!==u||e[11]!==g||e[12]!==y.length?(I=B=>b(ds,{active:B.id===s.id,canClose:y.length>1,onClose:a,onMenu:u,onRename:g,onSelect:t,tab:B},B.id),e[7]=s,e[8]=a,e[9]=t,e[10]=u,e[11]=g,e[12]=y.length,e[13]=I):I=e[13],h=y.map(I),e[0]=s,e[1]=a,e[2]=t,e[3]=u,e[4]=g,e[5]=y,e[6]=h}else h=e[6];let E;e[14]!==o?(E=o("New tab"),e[14]=o,e[15]=E):E=e[15];const w=y.length>=je;let R;e[16]!==o?(R=o("New tab"),e[16]=o,e[17]=R):R=e[17];let T;e[18]===Symbol.for("react.memo_cache_sentinel")?(T=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:b("path",{d:"M12 5v14M5 12h14"})}),e[18]=T):T=e[18];let _;e[19]!==r||e[20]!==E||e[21]!==w||e[22]!==R?(_=b("button",{"aria-label":E,className:"flex size-8 shrink-0 items-center justify-center text-muted-foreground outline-none transition-colors hover:bg-accent hover:text-foreground focus-visible:bg-accent disabled:pointer-events-none disabled:opacity-40","data-testid":"sql-tab-add",disabled:w,onClick:r,title:R,type:"button",children:T}),e[19]=r,e[20]=E,e[21]=w,e[22]=R,e[23]=_):_=e[23];let C;e[24]!==h||e[25]!==_?(C=W("div",{className:"flex shrink-0 items-stretch overflow-x-auto border-b border-border bg-muted/30","data-testid":"sql-tab-strip",role:"tablist",children:[h,_]}),e[24]=h,e[25]=_,e[26]=C):C=e[26];let A;e[27]!==c||e[28]!==i||e[29]!==f||e[30]!==p||e[31]!==m||e[32]!==x||e[33]!==d||e[34]!==S||e[35]!==v||e[36]!==o||e[37]!==N||e[38]!==y?(A=N!==null&&W(He,{children:[b("div",{className:"fixed inset-0 z-40","data-testid":"sql-tab-menu-backdrop",onClick:i,onContextMenu:m,role:"presentation"}),b("div",{className:"fixed z-50 min-w-44 rounded-md border border-border bg-popover py-1 text-popover-foreground shadow-md","data-testid":"sql-tab-menu",role:"menu",style:p,children:v===null?W(He,{children:[b("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:y.length<=1,onClick:d,role:"menuitem",type:"button",children:o("Close other tabs")}),b("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:y.findIndex(I=>I.id===N.id)>=y.length-1,onClick:S,role:"menuitem",type:"button",children:o("Close tabs to the right")}),b("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:o("Close all tabs")})]}):W("div",{className:"px-3 py-1.5","data-testid":"sql-tab-menu-confirm",children:[b("p",{className:"pb-1.5 text-xs text-muted-foreground",children:o("Discard unsaved tabs?")}),W("div",{className:"flex items-center gap-1.5",children:[b("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:o("Discard")}),b("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:c,type:"button",children:o("Cancel")})]})]})})]}),e[27]=c,e[28]=i,e[29]=f,e[30]=p,e[31]=m,e[32]=x,e[33]=d,e[34]=S,e[35]=v,e[36]=o,e[37]=N,e[38]=y,e[39]=A):A=e[39];let q;return e[40]!==C||e[41]!==A?(q=W(He,{children:[C,A]}),e[40]=C,e[41]=A,e[42]=q):q=e[42],q},fs=Oe(qe.runSql),ms="lunora-studio-sql-split-view",hs=()=>we(ft[0]?.sql??""),As=l=>{const e=Y(112),{initialShardKey:n}=l,t=Qe(),o=Pn(hs),{activeTab:s,output:r,patchActiveOutput:c,patchActiveTab:a,setActiveTabId:i,unlinkQuery:f}=o;let p;e[0]!==c||e[1]!==a?(p=(K,ce)=>{a({activeId:ce,sql:K}),c({chart:void 0,error:null,failed:void 0,result:null,script:void 0})},e[0]=c,e[1]=a,e[2]=p):p=e[2];const m=p;let x;e[3]!==m||e[4]!==f?(x={loadIntoActiveTab:m,unlinkQuery:f},e[3]=m,e[4]=f,e[5]=x):x=e[5];const d=jn(x),{recordHistory:S,updateQuerySql:u}=d,v=s.sql,{activeId:g}=s,{chart:N,error:y,failed:h,result:E,running:w}=r,R=r.pane,[T,_]=ie(n??""),[C,A]=ze(ms,!1),{probe:q,schema:I}=En(T);let B;e[6]!==g||e[7]!==a||e[8]!==u?(B=K=>{a({sql:K}),g!==null&&u(g,K)},e[6]=g,e[7]=a,e[8]=u,e[9]=B):B=e[9];const D=B,P=dn(v,I,T),O=vt(T);let k;e[10]!==O||e[11]!==c||e[12]!==E?(k=()=>{if(E===null)return;ue((async()=>{const ce=await O.inferChart({columns:E.columns,rowCount:E.rowCount,types:Object.fromEntries(E.columns.map(V=>[V,typeof(E.rows[0]?.[V]??"")]))});c({chart:ce})})())},e[10]=O,e[11]=c,e[12]=E,e[13]=k):k=e[13];const F=k;let L;e[14]!==t||e[15]!==S||e[16]!==T?(L=async K=>{try{const ce=await t.query(fs,{sql:K},_e(T));return S(K),{error:null,result:ce,sql:K}}catch(ce){return{error:gt(ce),result:null,sql:K}}},e[14]=t,e[15]=S,e[16]=T,e[17]=L):L=e[17];const M=L;let z;e[18]!==v||e[19]!==c||e[20]!==M||e[21]!==T?(z=async K=>{if(v.trim()==="")return;c({running:!0});const ce=K==="explain"?We(Mt(v),0):lt(v),V=[];for(const Te of ce){const mt={error:Te.rejection?.message??"",result:null,sql:Te.sql};V.push(Te.rejection===void 0?await M(Te.sql):mt)}xt(T);const Ye=Math.max(V.length-1,0),ye=V[Ye];c({chart:void 0,error:ye?.error??null,failed:ye?.error===null||ye===void 0?void 0:{error:ye.error,sql:ye.sql},pane:K,result:ye?.result??null,running:!1,script:V.length>1?{runs:V,selected:Ye}:void 0})},e[18]=v,e[19]=c,e[20]=M,e[21]=T,e[22]=z):z=e[22];const $=z;let X;e[23]!==r.script?.runs||e[24]!==c?(X=K=>{const ce=r.script?.runs,V=ce?.[K];ce===void 0||V===void 0||c({chart:void 0,error:V.error,failed:V.error===null?void 0:{error:V.error,sql:V.sql},result:V.result,script:{runs:ce,selected:K}})},e[23]=r.script?.runs,e[24]=c,e[25]=X):X=e[25];const Z=X;let ee;e[26]!==$?(ee=()=>{ue($("results"))},e[26]=$,e[27]=ee):ee=e[27];const te=ee;let ae;e[28]!==r.pane||e[29]!==$?(ae=()=>{ue($(r.pane))},e[28]=r.pane,e[29]=$,e[30]=ae):ae=e[30];let G;e[31]!==q||e[32]!==I||e[33]!==D||e[34]!==ae?(G={onSubmit:ae,probe:q,schema:I,setDraft:D},e[31]=q,e[32]=I,e[33]=D,e[34]=ae,e[35]=G):G=e[35];const Q=Ln(G),{closeAutocomplete:ne}=Q;let se;e[36]!==v||e[37]!==D?(se=()=>{D(Wt(v))},e[36]=v,e[37]=D,e[38]=se):se=e[38];const oe=se;let le;e[39]!==ne||e[40]!==i?(le=K=>{ne(),i(K)},e[39]=ne,e[40]=i,e[41]=le):le=e[41];const re=le;let H;e[42]!==c?(H=()=>{c({pane:"results"})},e[42]=c,e[43]=H):H=e[43];const U=H;let j;e[44]!==$?(j=()=>{ue($("explain"))},e[44]=$,e[45]=j):j=e[45];const J=j;let me;e[46]!==c?(me=()=>{c({pane:"chart"})},e[46]=c,e[47]=me):me=e[47];const De=me;let ke;e[48]!==A||e[49]!==C?(ke=()=>{A(!C)},e[48]=A,e[49]=C,e[50]=ke):ke=e[50];const Me=ke,$e=C?"flex min-h-0 flex-1 flex-row":"flex min-h-0 flex-1 flex-col",Be=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 he;e[51]!==g||e[52]!==d.clearHistory||e[53]!==d.deleteQuery||e[54]!==d.history||e[55]!==d.listRef||e[56]!==d.loadFromHistory||e[57]!==d.loadTemplate||e[58]!==d.newQuery||e[59]!==d.onSearchChange||e[60]!==d.queries||e[61]!==d.rememberHistory||e[62]!==d.search||e[63]!==d.selectQuery||e[64]!==d.setRememberHistory?(he=b(os,{activeId:g,history:d.history,listRef:d.listRef,onClearHistory:d.clearHistory,onDelete:d.deleteQuery,onLoadHistory:d.loadFromHistory,onLoadTemplate:d.loadTemplate,onNew:d.newQuery,onSearchChange:d.onSearchChange,onSelect:d.selectQuery,onToggleRememberHistory:d.setRememberHistory,queries:d.queries,rememberHistory:d.rememberHistory,search:d.search}),e[51]=g,e[52]=d.clearHistory,e[53]=d.deleteQuery,e[54]=d.history,e[55]=d.listRef,e[56]=d.loadFromHistory,e[57]=d.loadTemplate,e[58]=d.newQuery,e[59]=d.onSearchChange,e[60]=d.queries,e[61]=d.rememberHistory,e[62]=d.search,e[63]=d.selectQuery,e[64]=d.setRememberHistory,e[65]=he):he=e[65];let pe;e[66]!==o||e[67]!==re?(pe=b(us,{model:o,onSelect:re}),e[66]=o,e[67]=re,e[68]=pe):pe=e[68];let be;e[69]!==O||e[70]!==P||e[71]!==v||e[72]!==h||e[73]!==D||e[74]!==Q.autocompleteState||e[75]!==Q.editorRef||e[76]!==Q.gutterRef||e[77]!==Q.handlers||e[78]!==Q.listboxId||e[79]!==Q.onPickSuggestion||e[80]!==Q.overlayRef||e[81]!==Q.revealDiagnostic?(be=b(es,{assistant:O,autocomplete:Q.autocompleteState,diagnostics:P,draft:v,editorRef:Q.editorRef,failed:h,gutterRef:Q.gutterRef,handlers:Q.handlers,listboxId:Q.listboxId,onGenerated:D,onPickSuggestion:Q.onPickSuggestion,onRevealDiagnostic:Q.revealDiagnostic,overlayRef:Q.overlayRef}),e[69]=O,e[70]=P,e[71]=v,e[72]=h,e[73]=D,e[74]=Q.autocompleteState,e[75]=Q.editorRef,e[76]=Q.gutterRef,e[77]=Q.handlers,e[78]=Q.listboxId,e[79]=Q.onPickSuggestion,e[80]=Q.overlayRef,e[81]=Q.revealDiagnostic,e[82]=be):be=e[82];let ge;e[83]!==O||e[84]!==y||e[85]!==oe||e[86]!==F||e[87]!==N||e[88]!==te||e[89]!==Z||e[90]!==r.script||e[91]!==E||e[92]!==Be||e[93]!==w||e[94]!==T||e[95]!==De||e[96]!==J||e[97]!==U||e[98]!==C||e[99]!==R||e[100]!==Me?(ge=b(ls,{assistant:O,chart:N,className:Be,error:y,onFormat:oe,onInferChart:F,onRun:te,onSelectStatement:Z,onShardKeyChange:_,onShowChart:De,onShowExplain:J,onShowResults:U,onToggleSplit:Me,pane:R,result:E,running:w,script:r.script,shardKey:T,splitView:C}),e[83]=O,e[84]=y,e[85]=oe,e[86]=F,e[87]=N,e[88]=te,e[89]=Z,e[90]=r.script,e[91]=E,e[92]=Be,e[93]=w,e[94]=T,e[95]=De,e[96]=J,e[97]=U,e[98]=C,e[99]=R,e[100]=Me,e[101]=ge):ge=e[101];let xe;e[102]!==be||e[103]!==ge||e[104]!==$e?(xe=W("div",{className:$e,children:[be,ge]}),e[102]=be,e[103]=ge,e[104]=$e,e[105]=xe):xe=e[105];let ve;e[106]!==pe||e[107]!==xe?(ve=W("div",{className:"flex min-w-0 flex-1 flex-col",children:[pe,xe]}),e[106]=pe,e[107]=xe,e[108]=ve):ve=e[108];let Ee;return e[109]!==he||e[110]!==ve?(Ee=W("div",{className:"flex h-full min-w-0","data-testid":"lunora-sql-editor",children:[he,ve]}),e[109]=he,e[110]=ve,e[111]=Ee):Ee=e[111],Ee};export{As as SqlEditorPanel};
@@ -1 +1 @@
1
- import{c as V}from"react/compiler-runtime";import{useLunora as k}from"@lunora/react";import{useNavigate as F,useRouter as L,useSearch as M}from"@tanstack/react-router";import{useState as Q,useEffect as A}from"react";import{T as w}from"../packem_shared/storage-tier-C2mKwYRj.mjs";import{u as P}from"../packem_shared/table-list-sidebar-DHG1UJC4.mjs";import{useT as q}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.mjs";import{s as J,d as D}from"../packem_shared/data-view-params-qoSTqjAj.mjs";import{f}from"../packem_shared/internal-B6haJbiP.mjs";import{l as K,s as O}from"../packem_shared/browser-storage-BH1MxLZs.mjs";import{DataBrowser as I}from"../packem_shared/DataBrowser-B_zcf3a_.mjs";import{GlobalDataBrowser as X}from"../packem_shared/GlobalDataBrowser-BTbqR6Wc.mjs";import{jsx as v,jsxs as E}from"react/jsx-runtime";const N="lunora-studio-saved-queries",Y=50,$=r=>r!==null&&typeof r=="object"&&typeof r.name=="string"&&typeof r.view=="object"&&r.view!==null,S=()=>K(N).filter($),B=r=>{O(N,r)},z=(r,e)=>{const s=r.trim();if(s==="")return S();const o=[{name:s,view:e},...S().filter(b=>b.name!==s)].slice(0,Y);return B(o),o},H=r=>{const e=S().filter(s=>s.name!==r);return B(e),e},U=r=>{const e=V(15),{onChange:s,tier:o}=r,b=q();let d;e[0]!==s?(d=y=>{s(y.target.value)},e[0]=s,e[1]=d):d=e[1];const l=d;let h;e[2]!==b?(h=b("Storage tier"),e[2]=b,e[3]=h):h=e[3];let i;e[4]!==h?(i=v("span",{className:"font-mono text-[11px] tracking-wide uppercase text-muted-foreground",children:h}),e[4]=h,e[5]=i):i=e[5];const m=w[o];let n,g;e[6]===Symbol.for("react.memo_cache_sentinel")?(n=v("option",{value:"shard",children:w.shard.label}),g=v("option",{value:"global",children:w.global.label}),e[6]=n,e[7]=g):(n=e[6],g=e[7]);let c;e[8]!==l||e[9]!==m.title||e[10]!==o?(c=E("select",{className:"h-8 w-full rounded-md border border-border bg-background px-2 text-sm outline-none focus-visible:border-ring","data-testid":"table-editor-schema",id:"table-editor-schema",onChange:l,title:m.title,value:o,children:[n,g]}),e[8]=l,e[9]=m.title,e[10]=o,e[11]=c):c=e[11];let u;return e[12]!==i||e[13]!==c?(u=E("label",{className:"flex w-full flex-col gap-1",htmlFor:"table-editor-schema",children:[i,c]}),e[12]=i,e[13]=c,e[14]=u):u=e[14],u},W=()=>{try{f(globalThis.navigator.clipboard.writeText(globalThis.location.href))}catch{}},pe=({editable:r=!1,initialShardKey:e})=>{const s=k(),o=F(),b=L(),d=M({strict:!1}),l=J(d),h=P(d),i=()=>b.state.location.pathname.split("/").findLast(Boolean)==="data",m=l.tier??"shard",n=l.table,[g,c]=Q(()=>S()),[u,y]=Q(()=>new Set);A(()=>{f((async()=>{try{const a=await s.listGlobalTables();y(new Set(a.map(t=>t.name)))}catch{}})())},[s]),A(()=>{m==="shard"&&n!==void 0&&u.has(n)&&f(o({replace:!0,search:a=>({...a,schema:"global"}),to:"/data"}))},[u,o,n,m]);const R=a=>{f(o({search:t=>({...t,schema:a==="global"?"global":void 0,table:void 0}),to:"/data"}))},T=(a,t)=>{i()&&f(o({search:p=>({schema:p.schema,search:t?.search,shard:p.shard,table:a}),to:"/data"}))},C=a=>{f(o({search:t=>({...t,schema:"global",table:a}),to:"/data"}))},G=a=>{const t=D(a),{current:p}=h;(p.filters??void 0)===t.filters&&(p.order??void 0)===t.order&&(p.search??void 0)===t.search&&(p.shard??void 0)===t.shard||!i()||f(o({replace:!0,search:j=>({...j,filters:t.filters,order:t.order,search:t.search,shard:t.shard}),to:"/data"}))},_={onApplyQuery:a=>{const t=D(a.view);f(o({search:()=>({filters:t.filters,order:t.order,schema:t.schema,search:t.search,shard:t.shard,table:t.table}),to:"/data"}))},onCopyLink:W,onDeleteQuery:a=>{c(H(a))},onSaveQuery:(a,t)=>{c(z(a,t))},saved:g},x=v(U,{onChange:R,tier:m});return m==="global"?v(X,{initialTable:n,onSelectTable:T,schemaSwitch:x}):v(I,{editable:r,globalTableNames:u,initialFilters:l.filters,initialOrderBy:l.orderBy,initialPins:d.pins,initialSearch:l.search,initialShardKey:l.shard??e,onNavigateToGlobal:C,onSelectTable:T,onViewChange:G,queryBar:_,schemaSwitch:x,tableParam:n})};export{pe as TableEditor};
1
+ import{c as V}from"react/compiler-runtime";import{useLunora as k}from"@lunora/react";import{useNavigate as F,useRouter as L,useSearch as M}from"@tanstack/react-router";import{useState as Q,useEffect as A}from"react";import{T as w}from"../packem_shared/storage-tier-C2mKwYRj.mjs";import{u as P}from"../packem_shared/table-list-sidebar-DHG1UJC4.mjs";import{useT as q}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.mjs";import{s as J,d as D}from"../packem_shared/data-view-params-qoSTqjAj.mjs";import{f}from"../packem_shared/internal-B6haJbiP.mjs";import{l as K,s as O}from"../packem_shared/browser-storage-BH1MxLZs.mjs";import{DataBrowser as I}from"../packem_shared/DataBrowser-BUFMFvNX.mjs";import{GlobalDataBrowser as X}from"../packem_shared/GlobalDataBrowser-BTbqR6Wc.mjs";import{jsx as v,jsxs as E}from"react/jsx-runtime";const N="lunora-studio-saved-queries",Y=50,$=r=>r!==null&&typeof r=="object"&&typeof r.name=="string"&&typeof r.view=="object"&&r.view!==null,S=()=>K(N).filter($),B=r=>{O(N,r)},z=(r,e)=>{const s=r.trim();if(s==="")return S();const o=[{name:s,view:e},...S().filter(b=>b.name!==s)].slice(0,Y);return B(o),o},H=r=>{const e=S().filter(s=>s.name!==r);return B(e),e},U=r=>{const e=V(15),{onChange:s,tier:o}=r,b=q();let d;e[0]!==s?(d=y=>{s(y.target.value)},e[0]=s,e[1]=d):d=e[1];const l=d;let h;e[2]!==b?(h=b("Storage tier"),e[2]=b,e[3]=h):h=e[3];let i;e[4]!==h?(i=v("span",{className:"font-mono text-[11px] tracking-wide uppercase text-muted-foreground",children:h}),e[4]=h,e[5]=i):i=e[5];const m=w[o];let n,g;e[6]===Symbol.for("react.memo_cache_sentinel")?(n=v("option",{value:"shard",children:w.shard.label}),g=v("option",{value:"global",children:w.global.label}),e[6]=n,e[7]=g):(n=e[6],g=e[7]);let c;e[8]!==l||e[9]!==m.title||e[10]!==o?(c=E("select",{className:"h-8 w-full rounded-md border border-border bg-background px-2 text-sm outline-none focus-visible:border-ring","data-testid":"table-editor-schema",id:"table-editor-schema",onChange:l,title:m.title,value:o,children:[n,g]}),e[8]=l,e[9]=m.title,e[10]=o,e[11]=c):c=e[11];let u;return e[12]!==i||e[13]!==c?(u=E("label",{className:"flex w-full flex-col gap-1",htmlFor:"table-editor-schema",children:[i,c]}),e[12]=i,e[13]=c,e[14]=u):u=e[14],u},W=()=>{try{f(globalThis.navigator.clipboard.writeText(globalThis.location.href))}catch{}},pe=({editable:r=!1,initialShardKey:e})=>{const s=k(),o=F(),b=L(),d=M({strict:!1}),l=J(d),h=P(d),i=()=>b.state.location.pathname.split("/").findLast(Boolean)==="data",m=l.tier??"shard",n=l.table,[g,c]=Q(()=>S()),[u,y]=Q(()=>new Set);A(()=>{f((async()=>{try{const a=await s.listGlobalTables();y(new Set(a.map(t=>t.name)))}catch{}})())},[s]),A(()=>{m==="shard"&&n!==void 0&&u.has(n)&&f(o({replace:!0,search:a=>({...a,schema:"global"}),to:"/data"}))},[u,o,n,m]);const R=a=>{f(o({search:t=>({...t,schema:a==="global"?"global":void 0,table:void 0}),to:"/data"}))},T=(a,t)=>{i()&&f(o({search:p=>({schema:p.schema,search:t?.search,shard:p.shard,table:a}),to:"/data"}))},C=a=>{f(o({search:t=>({...t,schema:"global",table:a}),to:"/data"}))},G=a=>{const t=D(a),{current:p}=h;(p.filters??void 0)===t.filters&&(p.order??void 0)===t.order&&(p.search??void 0)===t.search&&(p.shard??void 0)===t.shard||!i()||f(o({replace:!0,search:j=>({...j,filters:t.filters,order:t.order,search:t.search,shard:t.shard}),to:"/data"}))},_={onApplyQuery:a=>{const t=D(a.view);f(o({search:()=>({filters:t.filters,order:t.order,schema:t.schema,search:t.search,shard:t.shard,table:t.table}),to:"/data"}))},onCopyLink:W,onDeleteQuery:a=>{c(H(a))},onSaveQuery:(a,t)=>{c(z(a,t))},saved:g},x=v(U,{onChange:R,tier:m});return m==="global"?v(X,{initialTable:n,onSelectTable:T,schemaSwitch:x}):v(I,{editable:r,globalTableNames:u,initialFilters:l.filters,initialOrderBy:l.orderBy,initialPins:d.pins,initialSearch:l.search,initialShardKey:l.shard??e,onNavigateToGlobal:C,onSelectTable:T,onViewChange:G,queryBar:_,schemaSwitch:x,tableParam:n})};export{pe as TableEditor};
@@ -1 +1 @@
1
- import{useState as x,useRef as he,useEffect as re}from"react";import{b as xe,d as ye,c as be,a as ce,C as de}from"../packem_shared/card--2hKx4L2.mjs";import{useT as ee}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.mjs";import{c as me}from"react/compiler-runtime";import{E as ge}from"../packem_shared/error-alert-tf5zvSLV.mjs";import{L as ve}from"../packem_shared/live-status-BuJdUZFU.mjs";import{B as z}from"../packem_shared/badge-r_5B4LHP.mjs";import{B as L}from"../packem_shared/button-q0UYSmrn.mjs";import{E as fe}from"../packem_shared/empty-state-D7jEML_T.mjs";import{T as Ne,a as ke,b as oe,c as te,d as Se,e as ae}from"../packem_shared/table-D0SBiDu-.mjs";import{u as le}from"../packem_shared/use-admin-query-BKXiqLci.mjs";import{ADMIN_FUNCTIONS as Z}from"../packem_shared/ADMIN_FUNCTIONS-B8yyk5BX.mjs";import{jsxs as i,jsx as a}from"react/jsx-runtime";import{useLunora as pe}from"@lunora/react";import{ShardInput as Ce}from"../packem_shared/ShardInput-C6mjgAh4.mjs";import{I as K}from"../packem_shared/input-CXhxesPC.mjs";import{L as M}from"../packem_shared/label-DKFzyHq6.mjs";import{T as Pe}from"../packem_shared/textarea--40GKAyz.mjs";import{d as we,c as Ae,b as Te,f as se}from"../packem_shared/internal-B6haJbiP.mjs";const ie=["read","insert","update","delete"],_e=(e,t)=>({delete:e("Delete"),insert:e("Insert"),read:e("Read"),update:e("Update")})[t],Ie=e=>{const t=new Set;for(const r of e?.advisories??[])if(r.name==="rls_uncovered_table"){const{table:n}=r.metadata;typeof n=="string"&&n!==""&&t.add(n)}return t},Ee=(e,t,r)=>{const n=new Map,l=c=>{const o=n.get(c);if(o!==void 0)return o;const f={cells:{delete:{},insert:{},read:{},update:{}},maskedColumns:new Set,table:c,uncovered:r.has(c)};return n.set(c,f),f};for(const c of e)l(c.table).cells[c.on]={procedure:c.procedure};for(const c of t)l(c.table).maskedColumns.add(c.column);for(const c of r)l(c);return[...n.values()].toSorted((c,o)=>c.table.localeCompare(o.table))},Fe=e=>{const t=me(17);let r;t[0]!==e?(r=e===void 0?{}:e,t[0]=e,t[1]=r):r=t[1];const{onProbe:n}=r,l=ee();let c,o;t[2]===Symbol.for("react.memo_cache_sentinel")?(c={},o={live:!0},t[2]=c,t[3]=o):(c=t[2],o=t[3]);const f=le(Z.rlsPolicies,c,o);let s;t[4]===Symbol.for("react.memo_cache_sentinel")?(s={},t[4]=s):s=t[4];const b=le(Z.maskPolicies,s);let h;t[5]===Symbol.for("react.memo_cache_sentinel")?(h={},t[5]=h):h=t[5];const g=le(Z.getAdvisories,h);let v;if(t[6]!==g.data||t[7]!==b.data||t[8]!==n||t[9]!==f||t[10]!==l){let N=null;f.data!==void 0&&(N=Array.isArray(f.data.policies)?f.data.policies:[]);const I=Array.isArray(b.data?.columns)?b.data.columns:[],$=g.data??null,{error:P,errorSource:k,liveError:w}=f,T=N===null?[]:Ee(N,I,Ie($));let S;t[12]!==w?(S=a("div",{className:"flex items-center justify-end",children:a(ve,{message:w,prefix:"pm"})}),t[12]=w,t[13]=S):S=t[13];let p;t[14]!==P||t[15]!==k?(p=P!==null&&a(ge,{error:k,testId:"pm-error"}),t[14]=P,t[15]=k,t[16]=p):p=t[16],v=i("div",{className:"flex flex-col gap-3","data-testid":"lunora-permissions-matrix",children:[S,p,N!==null&&T.length===0?a(fe,{description:l("Add a `definePolicy` and wire it through `.use(rls(...))` to populate this matrix."),testId:"pm-empty",title:l("No policy")}):i(Ne,{"data-testid":"pm-table",children:[a(ke,{children:i(oe,{children:[a(te,{children:l("Table")}),ie.map(d=>a(te,{children:_e(l,d)},d)),a(te,{children:l("Masked columns")})]})}),a(Se,{children:T.map(d=>i(oe,{"data-testid":`pm-row-${d.table}`,children:[a(ae,{className:"font-mono text-xs",children:i("span",{className:"flex items-center gap-1.5",children:[d.table,d.uncovered&&a(z,{"data-testid":`pm-uncovered-${d.table}`,title:l("Uncovered — reachable without a policy"),variant:"destructive",children:l("Uncovered — reachable without a policy")})]})}),ie.map(A=>{const y=d.cells[A];return a(ae,{"data-testid":`pm-cell-${d.table}-${A}`,children:y.procedure===void 0?a("span",{className:"text-xs text-muted-foreground",children:l("No policy")}):i("span",{className:"flex flex-col gap-1",children:[a(z,{variant:"secondary",children:l("Covered by {procedure}",{procedure:y.procedure})}),n!==void 0&&a(L,{className:"h-auto justify-start p-0 text-[11px]","data-testid":`pm-probe-${d.table}-${A}`,onClick:()=>{n(d.table,A,y.procedure??"")},size:"xs",type:"button",variant:"ghost",children:l("Probe this")})]})},A)}),a(ae,{children:d.maskedColumns.size===0?a("span",{"aria-hidden":"true",className:"text-muted-foreground",children:"—"}):a("span",{className:"flex flex-wrap gap-1",children:[...d.maskedColumns].map(Re)})})]},d.table))})]})]}),t[6]=g.data,t[7]=b.data,t[8]=n,t[9]=f,t[10]=l,t[11]=v}else v=t[11];return v};function Re(e){return a(z,{variant:"outline",children:e},e)}const Oe=Ae(Z.runAs),Le=()=>{const e=pe();return async({args:t,functionPath:r,shardKey:n="",userId:l})=>{if(l.trim()==="")return{kind:"invalid",message:"No identity to probe: enter the userId whose access you want to test."};const c=Oe;try{return{kind:"allowed",value:await e.query(c,{args:t,functionPath:r,userId:l},we(n))}}catch(o){return{kind:"denied",message:o instanceof Error?o.message:String(o)}}}},Me=e=>e===void 0?"undefined":JSON.stringify(e,null,2),$e=({functions:e,prefill:t,runAsIdentity:r=!1}={})=>{const n=pe(),l=ee(),c=Le(),[o,f]=x(null),[s,b]=x(null),h=e??o??[],[g,v]=x(""),[N,I]=x("{}"),[$,P]=x(""),[k,w]=x(""),[T,S]=x(!1),[p,d]=x(null),[A,y]=x(null),_=he(-1);re(()=>{if(e!==void 0)return;let m=!1;return n.listFunctions().then(u=>(m||f(u),u)).catch(u=>{m||b(Te(u))}),()=>{m=!0}},[n,e]),re(()=>{if(t===void 0||_.current===t.nonce)return;_.current=t.nonce;const m=t.functionPath;queueMicrotask(()=>{v(m),d(null)})},[t]);const C=g===""?h[0]?.path??"":g,E=async()=>{if(C==="")return;let m;try{m=N.trim()===""?{}:JSON.parse(N)}catch(u){y(l("Invalid JSON args: {message}",{message:u.message})),d(null);return}y(null),S(!0);try{const u=await c({args:m,functionPath:C,shardKey:$.trim(),userId:k.trim()});d(u)}finally{S(!1)}},F=()=>{se(E())},Y=m=>{v(m.target.value)},R=m=>{I(m.target.value)},O=m=>{w(m.target.value)};return i("div",{className:"flex flex-col gap-3","data-testid":"lunora-permissions-playground",children:[s!==null&&a("p",{className:"text-sm text-destructive","data-testid":"pp-discover-error",role:"alert",children:s}),!r&&a(fe,{description:l("Dev only: runs the selected function as this user over the admin gate so you can test auth and RLS."),testId:"pp-gate",title:l("Set `runAsIdentity` to forge an identity and probe access.")}),i("div",{className:"flex flex-col gap-3 rounded-md border border-border p-3",children:[i("div",{className:"flex flex-col gap-1.5",children:[a(M,{htmlFor:"pp-function",children:l("Function")}),a("select",{"aria-label":l("Function"),className:"flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-xs outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50","data-testid":"pp-function",id:"pp-function",onChange:Y,value:C,children:h.map(m=>i("option",{value:m.path,children:[m.path," (",m.kind,")"]},m.path))})]}),i("div",{className:"flex flex-col gap-1.5",children:[a(M,{htmlFor:"pp-args",children:l("Arguments")}),a(Pe,{"aria-label":l("Arguments"),className:"font-mono text-xs","data-testid":"pp-args",id:"pp-args",onChange:R,value:N})]}),a(Ce,{onChange:P,testId:"pp-shard",value:$}),i("div",{className:"flex flex-col gap-1.5",children:[a(M,{htmlFor:"pp-user",children:l("Run as (userId)")}),a(K,{"aria-label":l("Identity (userId) to run as"),className:"font-mono text-xs","data-testid":"pp-user",id:"pp-user",onChange:O,placeholder:l("Required — the identity to probe as"),value:k})]}),i("div",{className:"flex items-center gap-2",children:[a(L,{"data-testid":"pp-run",disabled:!r||T||C==="",onClick:F,type:"button",children:l(T?"Probing…":"Run probe")}),k.trim()!==""&&a(z,{"data-testid":"pp-as-badge",variant:"secondary",children:l("as {userId}",{userId:k.trim()})})]})]}),A!==null&&a("p",{className:"text-sm text-destructive","data-testid":"pp-args-error",role:"alert",children:A}),p!==null&&p.kind==="allowed"&&i("div",{className:"flex flex-col gap-2","data-testid":"pp-outcome-allowed",children:[a(z,{variant:"secondary",children:l("Allowed")}),a("pre",{className:"overflow-auto rounded-md border border-border bg-muted/50 p-3 font-mono text-xs","data-testid":"pp-result",children:Me(p.value)})]}),p!==null&&p.kind==="invalid"&&i("div",{className:"flex flex-col gap-2","data-testid":"pp-outcome-invalid",children:[a(z,{variant:"outline",children:l("Not run")}),a("p",{className:"text-sm text-muted-foreground","data-testid":"pp-invalid",role:"status",children:p.message})]}),p!==null&&p.kind==="denied"&&i("div",{className:"flex flex-col gap-2","data-testid":"pp-outcome-denied",children:[a(z,{variant:"destructive",children:l("Denied")}),a("pre",{className:"overflow-auto rounded-md border border-border bg-muted/50 p-3 font-mono text-xs text-destructive","data-testid":"pp-denied",role:"alert",children:p.message})]})]})},ze="/__lunora/policy-scaffold",De={"already-wired":"That procedure already has an rls(...) policy wired in.","file-exists":"A policy file with that name already exists — pick another name or edit it by hand.","invalid-identifier":"Name, table, and policy-set must be plain identifiers (letters, digits, _ or $).","unknown-procedure":"No exported procedure was found at that file path.","unsupported-procedure-shape":"That procedure uses the bare query({…}) form — convert it to the builder form (c.use(…).query(…)) before wiring RLS."},Ue=async e=>{const t=await fetch(ze,{body:JSON.stringify(e),headers:{"Content-Type":"application/json"},method:"POST"}),r=await t.json();if(r.needsManualEdit===!0)return{kind:"needs-manual-edit",message:r.message??"This change must be made by hand."};if(t.ok)return{diagnostics:r.diagnostics??[],kind:"ok",label:r.fileName??r.exportName??""};const n=r.error;return{kind:"error",message:n===void 0?`policy scaffold failed (${String(t.status)})`:De[n]??n}},ne={exportName:"",filePath:"",policyName:"",policies:"",tableName:""},je=()=>{const e=me(69),t=ee(),[r,n]=x(null),[l,c]=x(!1),[o,f]=x(null),[s,b]=x(ne);let h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h=X=>{const H=X.target.name,{value:G}=X.target;b(ue=>({...ue,[H]:G}))},e[0]=h):h=e[0];const g=h;let v;e[1]===Symbol.for("react.memo_cache_sentinel")?(v=()=>{n(null),b(ne)},e[1]=v):v=e[1];const N=v;let I;e[2]===Symbol.for("react.memo_cache_sentinel")?(I=async X=>{c(!0),f(null);try{const H=await Ue(X);f(H),H.kind==="ok"&&N()}catch(H){const G=H;f({kind:"error",message:G instanceof Error?G.message:String(G)})}c(!1)},e[2]=I):I=e[2];const $=I;let P;e[3]!==s.policyName||e[4]!==s.tableName?(P=()=>{se($({kind:"scaffoldPolicy",name:s.policyName.trim(),table:s.tableName.trim()}))},e[3]=s.policyName,e[4]=s.tableName,e[5]=P):P=e[5];const k=P;let w;e[6]!==s.exportName||e[7]!==s.filePath||e[8]!==s.policies?(w=()=>{se($({exportName:s.exportName.trim(),filePath:s.filePath.trim(),kind:"wireRls",policies:s.policies.trim()}))},e[6]=s.exportName,e[7]=s.filePath,e[8]=s.policies,e[9]=w):w=e[9];const T=w;let S;e[10]===Symbol.for("react.memo_cache_sentinel")?(S=()=>{f(null),n("scaffold")},e[10]=S):S=e[10];const p=S;let d;e[11]===Symbol.for("react.memo_cache_sentinel")?(d=()=>{f(null),n("wire")},e[11]=d):d=e[11];const A=d;let y;e[12]!==t?(y=t("Scaffold access rules"),e[12]=t,e[13]=y):y=e[13];let _;e[14]!==y?(_=a(xe,{children:y}),e[14]=y,e[15]=_):_=e[15];let C;e[16]!==t?(C=t("Writes a new deny-by-default policy file under lunora/, or wires one into a procedure, then reruns codegen. Local dev only."),e[16]=t,e[17]=C):C=e[17];let E;e[18]!==C?(E=a(ye,{children:C}),e[18]=C,e[19]=E):E=e[19];let F;e[20]!==E||e[21]!==_?(F=i(be,{children:[_,E]}),e[20]=E,e[21]=_,e[22]=F):F=e[22];const Y=r==="scaffold"?"default":"outline";let R;e[23]!==t?(R=t("New policy file"),e[23]=t,e[24]=R):R=e[24];let O;e[25]!==Y||e[26]!==R?(O=a(L,{"data-testid":"policy-scaffolder-new",onClick:p,size:"xs",type:"button",variant:Y,children:R}),e[25]=Y,e[26]=R,e[27]=O):O=e[27];const m=r==="wire"?"default":"outline";let u;e[28]!==t?(u=t("Wire into a procedure"),e[28]=t,e[29]=u):u=e[29];let D;e[30]!==m||e[31]!==u?(D=a(L,{"data-testid":"policy-scaffolder-wire",onClick:A,size:"xs",type:"button",variant:m,children:u}),e[30]=m,e[31]=u,e[32]=D):D=e[32];let U;e[33]!==O||e[34]!==D?(U=i("div",{className:"flex flex-wrap gap-2",children:[O,D]}),e[33]=O,e[34]=D,e[35]=U):U=e[35];let j;e[36]!==l||e[37]!==s.policyName||e[38]!==s.tableName||e[39]!==r||e[40]!==k||e[41]!==t?(j=r==="scaffold"&&i("div",{className:"mt-3 flex flex-wrap items-end gap-2","data-testid":"policy-scaffolder-new-form",children:[i("div",{className:"flex flex-col gap-1 text-xs",children:[a(M,{htmlFor:"policy-scaffolder-name",children:t("Policy name")}),a(K,{"data-testid":"policy-scaffolder-name",id:"policy-scaffolder-name",name:"policyName",onChange:g,value:s.policyName})]}),i("div",{className:"flex flex-col gap-1 text-xs",children:[a(M,{htmlFor:"policy-scaffolder-table",children:t("Table name")}),a(K,{"data-testid":"policy-scaffolder-table",id:"policy-scaffolder-table",name:"tableName",onChange:g,value:s.tableName})]}),a(L,{"data-testid":"policy-scaffolder-create",disabled:l||s.policyName.trim()===""||s.tableName.trim()==="",onClick:k,size:"xs",type:"button",children:t(l?"Creating…":"Create policy file")}),a(L,{onClick:N,size:"xs",type:"button",variant:"ghost",children:t("Cancel")})]}),e[36]=l,e[37]=s.policyName,e[38]=s.tableName,e[39]=r,e[40]=k,e[41]=t,e[42]=j):j=e[42];let B;e[43]!==l||e[44]!==s.exportName||e[45]!==s.filePath||e[46]!==s.policies||e[47]!==r||e[48]!==T||e[49]!==t?(B=r==="wire"&&i("div",{className:"mt-3 flex flex-wrap items-end gap-2","data-testid":"policy-scaffolder-wire-form",children:[i("div",{className:"flex flex-col gap-1 text-xs",children:[a(M,{htmlFor:"policy-scaffolder-file",children:t("Procedure file path")}),a(K,{"data-testid":"policy-scaffolder-file",id:"policy-scaffolder-file",name:"filePath",onChange:g,value:s.filePath})]}),i("div",{className:"flex flex-col gap-1 text-xs",children:[a(M,{htmlFor:"policy-scaffolder-export",children:t("Exported procedure")}),a(K,{"data-testid":"policy-scaffolder-export",id:"policy-scaffolder-export",name:"exportName",onChange:g,value:s.exportName})]}),i("div",{className:"flex flex-col gap-1 text-xs",children:[a(M,{htmlFor:"policy-scaffolder-policies",children:t("Policy set identifier")}),a(K,{"data-testid":"policy-scaffolder-policies",id:"policy-scaffolder-policies",name:"policies",onChange:g,value:s.policies})]}),a(L,{"data-testid":"policy-scaffolder-apply",disabled:l||s.filePath.trim()===""||s.exportName.trim()===""||s.policies.trim()==="",onClick:T,size:"xs",type:"button",children:t(l?"Wiring…":"Wire RLS")}),a(L,{onClick:N,size:"xs",type:"button",variant:"ghost",children:t("Cancel")})]}),e[43]=l,e[44]=s.exportName,e[45]=s.filePath,e[46]=s.policies,e[47]=r,e[48]=T,e[49]=t,e[50]=B):B=e[50];let W;e[51]!==o?(W=o?.kind==="error"&&a("p",{className:"mt-3 text-sm text-destructive","data-testid":"policy-scaffolder-error",role:"alert",children:o.message}),e[51]=o,e[52]=W):W=e[52];let q;e[53]!==o?.kind||e[54]!==t?(q=o?.kind==="needs-manual-edit"&&a("p",{className:"mt-3 text-sm text-amber-600 dark:text-amber-500","data-testid":"policy-scaffolder-manual",role:"alert",children:t("This change must be made by hand — the scaffolder only adds new, deny-by-default rules.")}),e[53]=o?.kind,e[54]=t,e[55]=q):q=e[55];let J;e[56]!==o||e[57]!==t?(J=o?.kind==="ok"&&i("div",{className:"mt-3 flex flex-col gap-1","data-testid":"policy-scaffolder-ok",children:[a("p",{className:"text-sm text-emerald-600 dark:text-emerald-500",children:t("Scaffolded {label} and reran codegen. Fill in the `when` predicates before relying on it.",{label:o.label})}),o.diagnostics.length>0&&a("ul",{className:"flex flex-col gap-0.5","data-testid":"policy-scaffolder-diagnostics",children:o.diagnostics.map(Be)})]}),e[56]=o,e[57]=t,e[58]=J):J=e[58];let Q;e[59]!==U||e[60]!==j||e[61]!==B||e[62]!==W||e[63]!==q||e[64]!==J?(Q=i(ce,{children:[U,j,B,W,q,J]}),e[59]=U,e[60]=j,e[61]=B,e[62]=W,e[63]=q,e[64]=J,e[65]=Q):Q=e[65];let V;return e[66]!==F||e[67]!==Q?(V=i(de,{"data-testid":"policy-scaffolder",size:"sm",children:[F,Q]}),e[66]=F,e[67]=Q,e[68]=V):V=e[68],V};function Be(e){return a("li",{className:"font-mono text-[11px] text-destructive",children:e},e)}const nt=({functions:e,runAsIdentity:t=!1,schemaEditable:r=!1}={})=>{const n=ee(),[l,c]=x(void 0),o=(f,s,b)=>{b!==""&&c(h=>({functionPath:b,nonce:(h?.nonce??0)+1}))};return i("div",{className:"flex flex-col gap-8","data-testid":"lunora-permissions",children:[i("section",{className:"flex flex-col gap-3",children:[a("header",{className:"border-b border-border px-4 py-3",children:a("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:n("Permissions")})}),a(Fe,{onProbe:o})]}),a("section",{className:"flex flex-col gap-3",children:i(de,{className:"gap-0 py-0",children:[a("header",{className:"border-b border-border px-4 py-3",children:a("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:n("Probe")})}),i(ce,{className:"px-4 py-4",children:[a("p",{className:"mb-3 text-sm text-muted-foreground",children:n("Pick a function and an identity, then run it to see the access outcome.")}),a($e,{functions:e,prefill:l,runAsIdentity:t})]})]})}),r&&a("section",{className:"flex flex-col gap-2",children:a(je,{})})]})};export{nt as PermissionsPanel};
1
+ import{useState as x,useRef as he,useEffect as se}from"react";import{b as xe,d as ye,c as be,a as de,C as ce}from"../packem_shared/card--2hKx4L2.mjs";import{useT as ee}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.mjs";import{c as me}from"react/compiler-runtime";import{E as ge}from"../packem_shared/error-alert-tf5zvSLV.mjs";import{L as ve}from"../packem_shared/live-status-BuJdUZFU.mjs";import{B as L}from"../packem_shared/badge-r_5B4LHP.mjs";import{B as D}from"../packem_shared/button-q0UYSmrn.mjs";import{E as fe}from"../packem_shared/empty-state-D7jEML_T.mjs";import{T as Ne,a as ke,b as oe,c as te,d as Se,e as ae}from"../packem_shared/table-D0SBiDu-.mjs";import{u as re}from"../packem_shared/use-admin-query-BKXiqLci.mjs";import{ADMIN_FUNCTIONS as X}from"../packem_shared/ADMIN_FUNCTIONS-B8yyk5BX.mjs";import{jsxs as i,jsx as a}from"react/jsx-runtime";import{useLunora as pe}from"@lunora/react";import{ShardInput as Ce}from"../packem_shared/ShardInput-C6mjgAh4.mjs";import{I as K}from"../packem_shared/input-CXhxesPC.mjs";import{L as $}from"../packem_shared/label-DKFzyHq6.mjs";import{T as we}from"../packem_shared/textarea--40GKAyz.mjs";import{d as Pe,c as Ae,b as Ee,f as le}from"../packem_shared/internal-B6haJbiP.mjs";const ie=["read","insert","update","delete"],Te=(e,t)=>({delete:e("Delete"),insert:e("Insert"),read:e("Read"),update:e("Update")})[t],_e=e=>e.file===""?e.procedure:`${e.file}:${e.procedure}`,Ie=e=>{const t=new Set;for(const s of e?.advisories??[])if(s.name==="rls_uncovered_table"){const{table:d}=s.metadata;typeof d=="string"&&d!==""&&t.add(d)}return t},Re=(e,t,s)=>{const d=new Map,r=n=>{const o=d.get(n);if(o!==void 0)return o;const f={cells:{delete:{},insert:{},read:{},update:{}},maskedColumns:new Set,table:n,uncovered:s.has(n)};return d.set(n,f),f};for(const n of e)r(n.table).cells[n.on]={path:_e(n),procedure:n.procedure};for(const n of t)r(n.table).maskedColumns.add(n.column);for(const n of s)r(n);return[...d.values()].toSorted((n,o)=>n.table.localeCompare(o.table))},Fe=e=>{const t=me(17);let s;t[0]!==e?(s=e===void 0?{}:e,t[0]=e,t[1]=s):s=t[1];const{onProbe:d}=s,r=ee();let n,o;t[2]===Symbol.for("react.memo_cache_sentinel")?(n={},o={live:!0},t[2]=n,t[3]=o):(n=t[2],o=t[3]);const f=re(X.rlsPolicies,n,o);let l;t[4]===Symbol.for("react.memo_cache_sentinel")?(l={},t[4]=l):l=t[4];const b=re(X.maskPolicies,l);let h;t[5]===Symbol.for("react.memo_cache_sentinel")?(h={},t[5]=h):h=t[5];const g=re(X.getAdvisories,h);let v;if(t[6]!==g.data||t[7]!==b.data||t[8]!==d||t[9]!==f||t[10]!==r){let N=null;f.data!==void 0&&(N=Array.isArray(f.data.policies)?f.data.policies:[]);const _=Array.isArray(b.data?.columns)?b.data.columns:[],U=g.data??null,{error:w,errorSource:k,liveError:P}=f,E=N===null?[]:Re(N,_,Ie(U));let S;t[12]!==P?(S=a("div",{className:"flex items-center justify-end",children:a(ve,{message:P,prefix:"pm"})}),t[12]=P,t[13]=S):S=t[13];let p;t[14]!==w||t[15]!==k?(p=w!==null&&a(ge,{error:k,testId:"pm-error"}),t[14]=w,t[15]=k,t[16]=p):p=t[16],v=i("div",{className:"flex flex-col gap-3","data-testid":"lunora-permissions-matrix",children:[S,p,N!==null&&E.length===0?a(fe,{description:r("Add a `definePolicy` and wire it through `.use(rls(...))` to populate this matrix."),testId:"pm-empty",title:r("No policy")}):i(Ne,{"data-testid":"pm-table",children:[a(ke,{children:i(oe,{children:[a(te,{children:r("Table")}),ie.map(c=>a(te,{children:Te(r,c)},c)),a(te,{children:r("Masked columns")})]})}),a(Se,{children:E.map(c=>i(oe,{"data-testid":`pm-row-${c.table}`,children:[a(ae,{className:"font-mono text-xs",children:i("span",{className:"flex items-center gap-1.5",children:[c.table,c.uncovered&&a(L,{"data-testid":`pm-uncovered-${c.table}`,title:r("Uncovered — reachable without a policy"),variant:"destructive",children:r("Uncovered — reachable without a policy")})]})}),ie.map(A=>{const y=c.cells[A];return a(ae,{"data-testid":`pm-cell-${c.table}-${A}`,children:y.procedure===void 0?a("span",{className:"text-xs text-muted-foreground",children:r("No policy")}):i("span",{className:"flex flex-col gap-1",children:[a(L,{variant:"secondary",children:r("Covered by {procedure}",{procedure:y.procedure})}),d!==void 0&&a(D,{className:"h-auto justify-start p-0 text-[11px]","data-testid":`pm-probe-${c.table}-${A}`,onClick:()=>{d(c.table,A,y.path??"")},size:"xs",type:"button",variant:"ghost",children:r("Probe this")})]})},A)}),a(ae,{children:c.maskedColumns.size===0?a("span",{"aria-hidden":"true",className:"text-muted-foreground",children:"—"}):a("span",{className:"flex flex-wrap gap-1",children:[...c.maskedColumns].map(Oe)})})]},c.table))})]})]}),t[6]=g.data,t[7]=b.data,t[8]=d,t[9]=f,t[10]=r,t[11]=v}else v=t[11];return v};function Oe(e){return a(L,{variant:"outline",children:e},e)}const De=Ae(X.runAs),Le=new Set(["FORBIDDEN","RLS_REQUIRED","UNAUTHORIZED"]),$e=e=>{const t=e?.code;return typeof t=="string"?t:void 0},Ue=()=>{const e=pe();return async({args:t,functionPath:s,shardKey:d="",userId:r})=>{if(r.trim()==="")return{kind:"invalid",message:"No identity to probe: enter the userId whose access you want to test."};const n=De;try{return{kind:"allowed",value:await e.query(n,{args:t,functionPath:s,userId:r},Pe(d))}}catch(o){const f=o instanceof Error?o.message:String(o),l=$e(o);return l!==void 0&&Le.has(l)?{kind:"denied",message:f}:{kind:"errored",message:f}}}},Me=e=>e===void 0?"undefined":JSON.stringify(e,null,2),ze=({functions:e,prefill:t,runAsIdentity:s=!1}={})=>{const d=pe(),r=ee(),n=Ue(),[o,f]=x(null),[l,b]=x(null),h=e??o??[],[g,v]=x(""),[N,_]=x("{}"),[U,w]=x(""),[k,P]=x(""),[E,S]=x(!1),[p,c]=x(null),[A,y]=x(null),T=he(-1);se(()=>{if(e!==void 0)return;let m=!1;return d.listFunctions().then(u=>(m||f(u),u)).catch(u=>{m||b(Ee(u))}),()=>{m=!0}},[d,e]),se(()=>{if(t===void 0||T.current===t.nonce)return;T.current=t.nonce;const m=t.functionPath;queueMicrotask(()=>{v(m),c(null)})},[t]);const C=g===""?h[0]?.path??"":g,I=async()=>{if(C==="")return;let m;try{m=N.trim()===""?{}:JSON.parse(N)}catch(u){y(r("Invalid JSON args: {message}",{message:u.message})),c(null);return}y(null),S(!0);try{const u=await n({args:m,functionPath:C,shardKey:U.trim(),userId:k.trim()});c(u)}finally{S(!1)}},R=()=>{le(I())},Y=m=>{v(m.target.value)},F=m=>{_(m.target.value)},O=m=>{P(m.target.value)};return i("div",{className:"flex flex-col gap-3","data-testid":"lunora-permissions-playground",children:[l!==null&&a("p",{className:"text-sm text-destructive","data-testid":"pp-discover-error",role:"alert",children:l}),!s&&a(fe,{description:r("Dev only: runs the selected function as this user over the admin gate so you can test auth and RLS."),testId:"pp-gate",title:r("Set `runAsIdentity` to forge an identity and probe access.")}),i("div",{className:"flex flex-col gap-3 rounded-md border border-border p-3",children:[i("div",{className:"flex flex-col gap-1.5",children:[a($,{htmlFor:"pp-function",children:r("Function")}),a("select",{"aria-label":r("Function"),className:"flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-xs outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50","data-testid":"pp-function",id:"pp-function",onChange:Y,value:C,children:h.map(m=>i("option",{value:m.path,children:[m.path," (",m.kind,")"]},m.path))})]}),i("div",{className:"flex flex-col gap-1.5",children:[a($,{htmlFor:"pp-args",children:r("Arguments")}),a(we,{"aria-label":r("Arguments"),className:"font-mono text-xs","data-testid":"pp-args",id:"pp-args",onChange:F,value:N})]}),a(Ce,{onChange:w,testId:"pp-shard",value:U}),i("div",{className:"flex flex-col gap-1.5",children:[a($,{htmlFor:"pp-user",children:r("Run as (userId)")}),a(K,{"aria-label":r("Identity (userId) to run as"),className:"font-mono text-xs","data-testid":"pp-user",id:"pp-user",onChange:O,placeholder:r("Required — the identity to probe as"),value:k})]}),i("div",{className:"flex items-center gap-2",children:[a(D,{"data-testid":"pp-run",disabled:!s||E||C==="",onClick:R,type:"button",children:r(E?"Probing…":"Run probe")}),k.trim()!==""&&a(L,{"data-testid":"pp-as-badge",variant:"secondary",children:r("as {userId}",{userId:k.trim()})})]})]}),A!==null&&a("p",{className:"text-sm text-destructive","data-testid":"pp-args-error",role:"alert",children:A}),p!==null&&p.kind==="allowed"&&i("div",{className:"flex flex-col gap-2","data-testid":"pp-outcome-allowed",children:[a(L,{variant:"secondary",children:r("Allowed")}),a("pre",{className:"overflow-auto rounded-md border border-border bg-muted/50 p-3 font-mono text-xs","data-testid":"pp-result",children:Me(p.value)})]}),p!==null&&p.kind==="invalid"&&i("div",{className:"flex flex-col gap-2","data-testid":"pp-outcome-invalid",children:[a(L,{variant:"outline",children:r("Not run")}),a("p",{className:"text-sm text-muted-foreground","data-testid":"pp-invalid",role:"status",children:p.message})]}),p!==null&&p.kind==="errored"&&i("div",{className:"flex flex-col gap-2","data-testid":"pp-outcome-errored",children:[a(L,{variant:"outline",children:r("Errored")}),a("p",{className:"text-sm text-muted-foreground",children:r("The call failed for a reason that is not an access verdict, so it says nothing about the policy.")}),a("pre",{className:"overflow-auto rounded-md border border-border bg-muted/50 p-3 font-mono text-xs","data-testid":"pp-errored",role:"alert",children:p.message})]}),p!==null&&p.kind==="denied"&&i("div",{className:"flex flex-col gap-2","data-testid":"pp-outcome-denied",children:[a(L,{variant:"destructive",children:r("Denied")}),a("pre",{className:"overflow-auto rounded-md border border-border bg-muted/50 p-3 font-mono text-xs text-destructive","data-testid":"pp-denied",role:"alert",children:p.message})]})]})},Be="/__lunora/policy-scaffold",je={"already-wired":"That procedure already has an rls(...) policy wired in.","file-exists":"A policy file with that name already exists — pick another name or edit it by hand.","invalid-identifier":"Name, table, and policy-set must be plain identifiers (letters, digits, _ or $).","unknown-procedure":"No exported procedure was found at that file path.","unsupported-procedure-shape":"That procedure uses the bare query({…}) form — convert it to the builder form (c.use(…).query(…)) before wiring RLS."},We=async e=>{const t=await fetch(Be,{body:JSON.stringify(e),headers:{"Content-Type":"application/json"},method:"POST"}),s=await t.json();if(s.needsManualEdit===!0)return{kind:"needs-manual-edit",message:s.message??"This change must be made by hand."};if(t.ok)return{diagnostics:s.diagnostics??[],kind:"ok",label:s.fileName??s.exportName??""};const d=s.error;return{kind:"error",message:d===void 0?`policy scaffold failed (${String(t.status)})`:je[d]??d}},ne={exportName:"",filePath:"",policyName:"",policies:"",tableName:""},qe=()=>{const e=me(69),t=ee(),[s,d]=x(null),[r,n]=x(!1),[o,f]=x(null),[l,b]=x(ne);let h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h=Z=>{const J=Z.target.name,{value:G}=Z.target;b(ue=>({...ue,[J]:G}))},e[0]=h):h=e[0];const g=h;let v;e[1]===Symbol.for("react.memo_cache_sentinel")?(v=()=>{d(null),b(ne)},e[1]=v):v=e[1];const N=v;let _;e[2]===Symbol.for("react.memo_cache_sentinel")?(_=async Z=>{n(!0),f(null);try{const J=await We(Z);f(J),J.kind==="ok"&&N()}catch(J){const G=J;f({kind:"error",message:G instanceof Error?G.message:String(G)})}n(!1)},e[2]=_):_=e[2];const U=_;let w;e[3]!==l.policyName||e[4]!==l.tableName?(w=()=>{le(U({kind:"scaffoldPolicy",name:l.policyName.trim(),table:l.tableName.trim()}))},e[3]=l.policyName,e[4]=l.tableName,e[5]=w):w=e[5];const k=w;let P;e[6]!==l.exportName||e[7]!==l.filePath||e[8]!==l.policies?(P=()=>{le(U({exportName:l.exportName.trim(),filePath:l.filePath.trim(),kind:"wireRls",policies:l.policies.trim()}))},e[6]=l.exportName,e[7]=l.filePath,e[8]=l.policies,e[9]=P):P=e[9];const E=P;let S;e[10]===Symbol.for("react.memo_cache_sentinel")?(S=()=>{f(null),d("scaffold")},e[10]=S):S=e[10];const p=S;let c;e[11]===Symbol.for("react.memo_cache_sentinel")?(c=()=>{f(null),d("wire")},e[11]=c):c=e[11];const A=c;let y;e[12]!==t?(y=t("Scaffold access rules"),e[12]=t,e[13]=y):y=e[13];let T;e[14]!==y?(T=a(xe,{children:y}),e[14]=y,e[15]=T):T=e[15];let C;e[16]!==t?(C=t("Writes a new deny-by-default policy file under lunora/, or wires one into a procedure, then reruns codegen. Local dev only."),e[16]=t,e[17]=C):C=e[17];let I;e[18]!==C?(I=a(ye,{children:C}),e[18]=C,e[19]=I):I=e[19];let R;e[20]!==I||e[21]!==T?(R=i(be,{children:[T,I]}),e[20]=I,e[21]=T,e[22]=R):R=e[22];const Y=s==="scaffold"?"default":"outline";let F;e[23]!==t?(F=t("New policy file"),e[23]=t,e[24]=F):F=e[24];let O;e[25]!==Y||e[26]!==F?(O=a(D,{"data-testid":"policy-scaffolder-new",onClick:p,size:"xs",type:"button",variant:Y,children:F}),e[25]=Y,e[26]=F,e[27]=O):O=e[27];const m=s==="wire"?"default":"outline";let u;e[28]!==t?(u=t("Wire into a procedure"),e[28]=t,e[29]=u):u=e[29];let M;e[30]!==m||e[31]!==u?(M=a(D,{"data-testid":"policy-scaffolder-wire",onClick:A,size:"xs",type:"button",variant:m,children:u}),e[30]=m,e[31]=u,e[32]=M):M=e[32];let z;e[33]!==O||e[34]!==M?(z=i("div",{className:"flex flex-wrap gap-2",children:[O,M]}),e[33]=O,e[34]=M,e[35]=z):z=e[35];let B;e[36]!==r||e[37]!==l.policyName||e[38]!==l.tableName||e[39]!==s||e[40]!==k||e[41]!==t?(B=s==="scaffold"&&i("div",{className:"mt-3 flex flex-wrap items-end gap-2","data-testid":"policy-scaffolder-new-form",children:[i("div",{className:"flex flex-col gap-1 text-xs",children:[a($,{htmlFor:"policy-scaffolder-name",children:t("Policy name")}),a(K,{"data-testid":"policy-scaffolder-name",id:"policy-scaffolder-name",name:"policyName",onChange:g,value:l.policyName})]}),i("div",{className:"flex flex-col gap-1 text-xs",children:[a($,{htmlFor:"policy-scaffolder-table",children:t("Table name")}),a(K,{"data-testid":"policy-scaffolder-table",id:"policy-scaffolder-table",name:"tableName",onChange:g,value:l.tableName})]}),a(D,{"data-testid":"policy-scaffolder-create",disabled:r||l.policyName.trim()===""||l.tableName.trim()==="",onClick:k,size:"xs",type:"button",children:t(r?"Creating…":"Create policy file")}),a(D,{onClick:N,size:"xs",type:"button",variant:"ghost",children:t("Cancel")})]}),e[36]=r,e[37]=l.policyName,e[38]=l.tableName,e[39]=s,e[40]=k,e[41]=t,e[42]=B):B=e[42];let j;e[43]!==r||e[44]!==l.exportName||e[45]!==l.filePath||e[46]!==l.policies||e[47]!==s||e[48]!==E||e[49]!==t?(j=s==="wire"&&i("div",{className:"mt-3 flex flex-wrap items-end gap-2","data-testid":"policy-scaffolder-wire-form",children:[i("div",{className:"flex flex-col gap-1 text-xs",children:[a($,{htmlFor:"policy-scaffolder-file",children:t("Procedure file path")}),a(K,{"data-testid":"policy-scaffolder-file",id:"policy-scaffolder-file",name:"filePath",onChange:g,value:l.filePath})]}),i("div",{className:"flex flex-col gap-1 text-xs",children:[a($,{htmlFor:"policy-scaffolder-export",children:t("Exported procedure")}),a(K,{"data-testid":"policy-scaffolder-export",id:"policy-scaffolder-export",name:"exportName",onChange:g,value:l.exportName})]}),i("div",{className:"flex flex-col gap-1 text-xs",children:[a($,{htmlFor:"policy-scaffolder-policies",children:t("Policy set identifier")}),a(K,{"data-testid":"policy-scaffolder-policies",id:"policy-scaffolder-policies",name:"policies",onChange:g,value:l.policies})]}),a(D,{"data-testid":"policy-scaffolder-apply",disabled:r||l.filePath.trim()===""||l.exportName.trim()===""||l.policies.trim()==="",onClick:E,size:"xs",type:"button",children:t(r?"Wiring…":"Wire RLS")}),a(D,{onClick:N,size:"xs",type:"button",variant:"ghost",children:t("Cancel")})]}),e[43]=r,e[44]=l.exportName,e[45]=l.filePath,e[46]=l.policies,e[47]=s,e[48]=E,e[49]=t,e[50]=j):j=e[50];let W;e[51]!==o?(W=o?.kind==="error"&&a("p",{className:"mt-3 text-sm text-destructive","data-testid":"policy-scaffolder-error",role:"alert",children:o.message}),e[51]=o,e[52]=W):W=e[52];let q;e[53]!==o?.kind||e[54]!==t?(q=o?.kind==="needs-manual-edit"&&a("p",{className:"mt-3 text-sm text-amber-600 dark:text-amber-500","data-testid":"policy-scaffolder-manual",role:"alert",children:t("This change must be made by hand — the scaffolder only adds new, deny-by-default rules.")}),e[53]=o?.kind,e[54]=t,e[55]=q):q=e[55];let Q;e[56]!==o||e[57]!==t?(Q=o?.kind==="ok"&&i("div",{className:"mt-3 flex flex-col gap-1","data-testid":"policy-scaffolder-ok",children:[a("p",{className:"text-sm text-emerald-600 dark:text-emerald-500",children:t("Scaffolded {label} and reran codegen. Fill in the `when` predicates before relying on it.",{label:o.label})}),o.diagnostics.length>0&&a("ul",{className:"flex flex-col gap-0.5","data-testid":"policy-scaffolder-diagnostics",children:o.diagnostics.map(Qe)})]}),e[56]=o,e[57]=t,e[58]=Q):Q=e[58];let H;e[59]!==z||e[60]!==B||e[61]!==j||e[62]!==W||e[63]!==q||e[64]!==Q?(H=i(de,{children:[z,B,j,W,q,Q]}),e[59]=z,e[60]=B,e[61]=j,e[62]=W,e[63]=q,e[64]=Q,e[65]=H):H=e[65];let V;return e[66]!==R||e[67]!==H?(V=i(ce,{"data-testid":"policy-scaffolder",size:"sm",children:[R,H]}),e[66]=R,e[67]=H,e[68]=V):V=e[68],V};function Qe(e){return a("li",{className:"font-mono text-[11px] text-destructive",children:e},e)}const mt=({functions:e,runAsIdentity:t=!1,schemaEditable:s=!1}={})=>{const d=ee(),[r,n]=x(void 0),o=(f,l,b)=>{b!==""&&n(h=>({functionPath:b,nonce:(h?.nonce??0)+1}))};return i("div",{className:"flex flex-col gap-8","data-testid":"lunora-permissions",children:[i("section",{className:"flex flex-col gap-3",children:[a("header",{className:"border-b border-border px-4 py-3",children:a("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:d("Permissions")})}),a(Fe,{onProbe:o})]}),a("section",{className:"flex flex-col gap-3",children:i(ce,{className:"gap-0 py-0",children:[a("header",{className:"border-b border-border px-4 py-3",children:a("span",{className:"font-mono text-[11px] tracking-wide text-muted-foreground uppercase",children:d("Probe")})}),i(de,{className:"px-4 py-4",children:[a("p",{className:"mb-3 text-sm text-muted-foreground",children:d("Pick a function and an identity, then run it to see the access outcome.")}),a(ze,{functions:e,prefill:r,runAsIdentity:t})]})]})}),s&&a("section",{className:"flex flex-col gap-2",children:a(qe,{})})]})};export{mt as PermissionsPanel};
@@ -1 +1 @@
1
- import{c as P}from"react/compiler-runtime";import{useLunora as Ve}from"@lunora/react";import{useState as M}from"react";import{ConfirmButton as Ye}from"../packem_shared/ConfirmButton-DU4p72Er.mjs";import{E as Xe}from"../packem_shared/error-alert-tf5zvSLV.mjs";import{A as Ke}from"../packem_shared/alert-PB5W11MM.mjs";import{B as ve}from"../packem_shared/badge-r_5B4LHP.mjs";import{B as Qe}from"../packem_shared/button-q0UYSmrn.mjs";import{C as $e,a as Oe}from"../packem_shared/card--2hKx4L2.mjs";import{E as we}from"../packem_shared/empty-state-D7jEML_T.mjs";import{I as Ze}from"../packem_shared/input-CXhxesPC.mjs";import{S as et}from"../packem_shared/scroll-area-CXCQH7VT.mjs";import{T as ke,a as Ue,b as oe,c as _,d as Je,e as T}from"../packem_shared/table-D0SBiDu-.mjs";import{T as tt}from"../packem_shared/textarea--40GKAyz.mjs";import{u as Be}from"../packem_shared/use-admin-query-BKXiqLci.mjs";import{useAutoRefresh as st}from"../packem_shared/DEFAULT_AUTO_REFRESH_MS-DuULO4XM.mjs";import{useT as j}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.mjs";import{ADMIN_FUNCTIONS as G}from"../packem_shared/ADMIN_FUNCTIONS-B8yyk5BX.mjs";import{d as _e,b as Te,c as Ae,f as Ce,h as at}from"../packem_shared/internal-B6haJbiP.mjs";import{jsx as s,jsxs as q,Fragment as Fe}from"react/jsx-runtime";const rt=(n,e)=>{const t=new Set(n.map(a=>a.deadLetterQueue).filter(a=>typeof a=="string"&&a!=="")),d=n.filter(a=>(a.deadLetterQueue===void 0||a.deadLetterQueue==="")&&!t.has(a.name)),l=e.filter(a=>a.deadLettered).length;return{deadLetteredCount:l,queuesWithoutDlq:d,showReliabilityWarning:d.length>0||l>0}},nt=200,ot=Ae(G.sendQueueMessage),lt=Ae(G.replayQueueMessage),dt=Ae(G.clearQueueMessages),Re=96,it=n=>{if(n===void 0)return"—";try{return JSON.stringify(n)}catch{return"[unserializable]"}},ct=n=>n.length>Re?`${n.slice(0,Re)}…`:n,ut=n=>n==="error"?"destructive":n==="retry"?"outline":"secondary",mt=(n,e)=>e(n==="messages"?"Messages":n==="send"?"Send":"Declared"),ft=n=>{const e=P(11),{loaded:t,queues:d}=n,l=j();let a;e[0]!==l?(a=l("Queues are declared in code with defineQueue. Enqueue from a mutation or action with ctx.queues.<name>.send(...); push consumers process batches in the worker."),e[0]=l,e[1]=a):a=e[1];let o;e[2]!==a?(o=s("p",{className:"text-sm text-muted-foreground",children:a}),e[2]=a,e[3]=o):o=e[3];let r;e[4]!==t||e[5]!==d||e[6]!==l?(r=t&&d.length===0?s(we,{description:l("No defineQueue is declared in lunora/queues.ts in this deployment. Add one to offload async work to a Cloudflare Queue."),testId:"queues-empty",title:l("No queues defined")}):s($e,{className:"overflow-hidden py-0",children:s(Oe,{className:"px-0",children:q(ke,{"data-testid":"queues-table",children:[s(Ue,{children:q(oe,{children:[s(_,{children:l("Export")}),s(_,{children:l("Queue")}),s(_,{children:l("Mode")}),s(_,{children:l("Binding")}),s(_,{children:l("Dead-letter")})]})}),s(Je,{children:d.map(xt)})]})})}),e[4]=t,e[5]=d,e[6]=l,e[7]=r):r=e[7];let f;return e[8]!==o||e[9]!==r?(f=q("div",{className:"flex flex-col gap-4","data-testid":"queues-declared",children:[o,r]}),e[8]=o,e[9]=r,e[10]=f):f=e[10],f},ht=n=>{const e=P(67),{message:t,onReplay:d,replayingId:l}=n,a=j();let o,r,f,u,g,y,x,i,m,p;if(e[0]!==t.attempts||e[1]!==t.body||e[2]!==t.deadLettered||e[3]!==t.exportName||e[4]!==t.id||e[5]!==t.messageId||e[6]!==t.outcome||e[7]!==t.queue||e[8]!==a){const U=it(t.body);r=oe,y=`queues-message-${t.id}`;const J=t.exportName??t.queue;e[19]!==J?(x=s(T,{className:"font-mono text-xs",children:J}),e[19]=J,e[20]=x):x=e[20],e[21]!==t.messageId?(i=s(T,{className:"max-w-[16ch] truncate font-mono text-xs text-muted-foreground",title:t.messageId,children:t.messageId}),e[21]=t.messageId,e[22]=i):i=e[22],e[23]!==t.attempts?(m=s(T,{className:"font-mono text-xs tabular-nums",children:t.attempts}),e[23]=t.attempts,e[24]=m):m=e[24];const A=`queues-outcome-${t.id}`;let I;e[25]!==t.outcome?(I=ut(t.outcome),e[25]=t.outcome,e[26]=I):I=e[26];let C;e[27]!==t.outcome||e[28]!==A||e[29]!==I?(C=s(ve,{"data-testid":A,variant:I,children:t.outcome}),e[27]=t.outcome,e[28]=A,e[29]=I,e[30]=C):C=e[30];let L;e[31]!==t.deadLettered||e[32]!==t.id||e[33]!==a?(L=t.deadLettered&&s(ve,{"data-testid":`queues-dlq-${t.id}`,variant:"destructive",children:a("DLQ")}),e[31]=t.deadLettered,e[32]=t.id,e[33]=a,e[34]=L):L=e[34],e[35]!==C||e[36]!==L?(p=s(T,{children:q("span",{className:"inline-flex items-center gap-1",children:[C,L]})}),e[35]=C,e[36]=L,e[37]=p):p=e[37],o=T,f="max-w-[32ch] truncate font-mono text-xs text-muted-foreground",u=U,g=ct(U),e[0]=t.attempts,e[1]=t.body,e[2]=t.deadLettered,e[3]=t.exportName,e[4]=t.id,e[5]=t.messageId,e[6]=t.outcome,e[7]=t.queue,e[8]=a,e[9]=o,e[10]=r,e[11]=f,e[12]=u,e[13]=g,e[14]=y,e[15]=x,e[16]=i,e[17]=m,e[18]=p}else o=e[9],r=e[10],f=e[11],u=e[12],g=e[13],y=e[14],x=e[15],i=e[16],m=e[17],p=e[18];let h;e[38]!==o||e[39]!==f||e[40]!==u||e[41]!==g?(h=s(o,{className:f,title:u,children:g}),e[38]=o,e[39]=f,e[40]=u,e[41]=g,e[42]=h):h=e[42];let N;e[43]!==t.capturedAt?(N=at(t.capturedAt,"—"),e[43]=t.capturedAt,e[44]=N):N=e[44];let b;e[45]!==N?(b=s(T,{className:"text-xs text-muted-foreground tabular-nums",children:N}),e[45]=N,e[46]=b):b=e[46];const E=`queues-replay-${t.id}`,w=l!==null;let v;e[47]!==t.id||e[48]!==l||e[49]!==a?(v=l===t.id?a("Replaying…"):a("Replay"),e[47]=t.id,e[48]=l,e[49]=a,e[50]=v):v=e[50];let Q;e[51]!==t.id||e[52]!==d||e[53]!==E||e[54]!==w||e[55]!==v?(Q=s(T,{children:s(Qe,{"data-id":t.id,"data-testid":E,disabled:w,onClick:d,size:"xs",type:"button",variant:"outline",children:v})}),e[51]=t.id,e[52]=d,e[53]=E,e[54]=w,e[55]=v,e[56]=Q):Q=e[56];let D;return e[57]!==r||e[58]!==b||e[59]!==Q||e[60]!==y||e[61]!==x||e[62]!==i||e[63]!==m||e[64]!==p||e[65]!==h?(D=q(r,{"data-testid":y,children:[x,i,m,p,h,b,Q]}),e[57]=r,e[58]=b,e[59]=Q,e[60]=y,e[61]=x,e[62]=i,e[63]=m,e[64]=p,e[65]=h,e[66]=D):D=e[66],D},pt=n=>{const e=P(30),{hasError:t,messages:d,onClear:l,onReplay:a,replayingId:o}=n,r=j();let f;e[0]!==r?(f=r("Cloudflare Queues have no peek API, so this is what push consumers actually processed — not pending depth."),e[0]=r,e[1]=f):f=e[1];let u;e[2]!==f?(u=s("p",{className:"text-sm text-muted-foreground",children:f}),e[2]=f,e[3]=u):u=e[3];let g;e[4]!==d.length||e[5]!==r?(g=r("Clear {count} messages?",{count:d.length}),e[4]=d.length,e[5]=r,e[6]=g):g=e[6];const y=d.length===0;let x;e[7]!==r?(x=r("Clear log"),e[7]=r,e[8]=x):x=e[8];let i;e[9]!==l||e[10]!==g||e[11]!==y||e[12]!==x?(i=s("div",{className:"ml-auto",children:s(Ye,{confirmLabel:g,disabled:y,onConfirm:l,testId:"queues-clear",children:x})}),e[9]=l,e[10]=g,e[11]=y,e[12]=x,e[13]=i):i=e[13];let m;e[14]!==d.length||e[15]!==r?(m=d.length>0&&s(ve,{"data-testid":"queues-count",variant:"secondary",children:r("{count} messages",{count:d.length})}),e[14]=d.length,e[15]=r,e[16]=m):m=e[16];let p;e[17]!==u||e[18]!==i||e[19]!==m?(p=q("div",{className:"flex flex-wrap items-center gap-2",children:[u,i,m]}),e[17]=u,e[18]=i,e[19]=m,e[20]=p):p=e[20];let h;e[21]!==t||e[22]!==d||e[23]!==a||e[24]!==o||e[25]!==r?(h=!t&&d.length===0?s(we,{description:r("Consumed messages appear here once a push consumer processes a batch in dev. Send one from the Send tab to see it captured."),testId:"queues-messages-empty",title:r("No consumed messages yet.")}):s($e,{className:"overflow-hidden py-0",children:s(Oe,{className:"px-0",children:s(et,{className:"max-h-[32rem]","data-testid":"queues-messages-scroll",children:q(ke,{"data-testid":"queues-messages-table",children:[s(Ue,{children:q(oe,{children:[s(_,{children:r("Export")}),s(_,{children:r("Message")}),s(_,{children:r("Attempts")}),s(_,{children:r("Outcome")}),s(_,{children:r("Body")}),s(_,{children:r("Captured")}),s(_,{})]})}),s(Je,{children:d.map(b=>s(ht,{message:b,onReplay:a,replayingId:o},b.id))})]})})})}),e[21]=t,e[22]=d,e[23]=a,e[24]=o,e[25]=r,e[26]=h):h=e[26];let N;return e[27]!==p||e[28]!==h?(N=q("div",{className:"flex flex-col gap-4","data-testid":"queues-messages",children:[p,h]}),e[27]=p,e[28]=h,e[29]=N):N=e[29],N},gt=n=>{const e=P(20),{batchMode:t,bodyText:d,delayText:l,onBatchModeChange:a,onBodyChange:o,onDelayChange:r,onSelectExport:f,onSend:u,queues:g,selectedExportName:y,sending:x}=n,i=j();let m;e[0]!==i?(m=i("Enqueue a JSON message to a declared producer to exercise its consumer. Nothing is captured until the consumer processes it."),e[0]=i,e[1]=m):m=e[1];let p;e[2]!==m?(p=s("p",{className:"text-sm text-muted-foreground",children:m}),e[2]=m,e[3]=p):p=e[3];let h;e[4]!==t||e[5]!==d||e[6]!==l||e[7]!==a||e[8]!==o||e[9]!==r||e[10]!==f||e[11]!==u||e[12]!==g||e[13]!==y||e[14]!==x||e[15]!==i?(h=g.length===0?s(we,{description:i("Declare a queue with defineQueue in lunora/queues.ts to enqueue a test message."),testId:"queues-send-empty",title:i("No queues to send to")}):q(Fe,{children:[q("div",{className:"flex flex-wrap items-center gap-2",children:[s("select",{"aria-label":i("Queue"),className:"h-8 rounded-md border border-input bg-transparent px-2.5 py-1 text-xs outline-none focus-visible:border-ring focus-visible:ring-1 focus-visible:ring-ring/50","data-testid":"queues-send-select",onChange:f,value:y,children:g.map(yt)}),s(Ze,{"aria-label":i("Delay (seconds)"),className:"max-w-36","data-testid":"queues-send-delay",min:0,onChange:r,placeholder:i("Delay (s)"),type:"number",value:l}),q("label",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",htmlFor:"queues-send-batch",children:[s("input",{checked:t,"data-testid":"queues-send-batch",id:"queues-send-batch",onChange:a,type:"checkbox"}),i("Send as batch (JSON array)")]}),s(Qe,{className:"ml-auto","data-testid":"queues-send-button",disabled:x||y==="",onClick:u,type:"button",children:i(x?"Sending…":"Send message")})]}),s(tt,{"aria-label":i("Message body (JSON)"),className:"font-mono","data-testid":"queues-send-body",onChange:o,placeholder:t?'[ { "hello": "world" } ]':'{ "hello": "world" }',value:d})]}),e[4]=t,e[5]=d,e[6]=l,e[7]=a,e[8]=o,e[9]=r,e[10]=f,e[11]=u,e[12]=g,e[13]=y,e[14]=x,e[15]=i,e[16]=h):h=e[16];let N;return e[17]!==p||e[18]!==h?(N=q("div",{className:"flex flex-col gap-3","data-testid":"queues-send",children:[p,h]}),e[17]=p,e[18]=h,e[19]=N):N=e[19],N},Ft=n=>{const e=P(59),{limit:t}=n,d=t??nt,l=Ve(),a=j(),[o,r]=M("declared"),[f,u]=M(null);let g;e[0]===Symbol.for("react.memo_cache_sentinel")?(g={},e[0]=g):g=e[0];const{data:y,error:x,errorSource:i}=Be(G.listQueues,g);let m;e[1]!==d?(m={limit:d},e[1]=d,e[2]=m):m=e[2];const{data:p,error:h,errorSource:N,refetch:b}=Be(G.getQueueMessages,m),E=Array.isArray(y?.queues)?[...y.queues].toSorted(bt):[],w=p?.entries??[],{deadLetteredCount:v,queuesWithoutDlq:Q,showReliabilityWarning:D}=rt(E,w),[U,J]=M(""),[A,I]=M(""),[C,L]=M(""),[F,We]=M(!1),[le,Ie]=M(!1),[de,Le]=M(null),z=E.some(c=>c.exportName===U)?U:E[0]?.exportName??"",Me=o==="messages"?h:x,Ge=o==="messages"?N:i,ie=Me??f,ce=Me===null?f:Ge;let H;e[3]!==b?(H=()=>{b()},e[3]=b,e[4]=H):H=e[4],st(H,o==="messages");const ue=async()=>{u(null);const c=z;if(c==="")return;let S=null;const Se=A.trim();if(Se!=="")try{S=JSON.parse(Se)}catch{u(a("Body must be valid JSON."));return}let Ee;const De=C.trim();if(De!==""){const W=Number(De);if(!Number.isFinite(W)||W<0){u(a("Delay must be a non-negative number of seconds."));return}Ee=W}if(F&&!Array.isArray(S)){u(a("Batch mode needs a JSON array body — each element is enqueued as one message."));return}Ie(!0);const He=F?{batch:S,delaySeconds:Ee,exportName:c}:{body:S,delaySeconds:Ee,exportName:c};try{await l.query(ot,He,_e("")),b()}catch(W){u(Te(W))}Ie(!1)};let V;e[5]!==l||e[6]!==b?(V=async c=>{u(null),Le(c);try{await l.query(lt,{id:c},_e("")),b()}catch(S){u(Te(S))}Le(null)},e[5]=l,e[6]=b,e[7]=V):V=e[7];const me=V;let Y;e[8]!==l||e[9]!==b?(Y=async()=>{u(null);try{await l.query(dt,{},_e("")),b()}catch(c){u(Te(c))}},e[8]=l,e[9]=b,e[10]=Y):Y=e[10];const fe=Y;let X;e[11]===Symbol.for("react.memo_cache_sentinel")?(X=c=>{const S=c.currentTarget.dataset.tab;(S==="declared"||S==="messages"||S==="send")&&r(S)},e[11]=X):X=e[11];const Pe=X;let K;e[12]===Symbol.for("react.memo_cache_sentinel")?(K=c=>{J(c.currentTarget.value)},e[12]=K):K=e[12];const he=K;let Z;e[13]===Symbol.for("react.memo_cache_sentinel")?(Z=c=>{I(c.currentTarget.value)},e[13]=Z):Z=e[13];const pe=Z;let ee;e[14]===Symbol.for("react.memo_cache_sentinel")?(ee=c=>{L(c.currentTarget.value)},e[14]=ee):ee=e[14];const ge=ee;let te;e[15]===Symbol.for("react.memo_cache_sentinel")?(te=c=>{We(c.currentTarget.checked)},e[15]=te):te=e[15];const xe=te;let se;e[16]!==ue?(se=()=>{Ce(ue())},e[16]=ue,e[17]=se):se=e[17];const ye=se;let ae;e[18]!==me?(ae=c=>{const{id:S}=c.currentTarget.dataset;S!==void 0&&Ce(me(S))},e[18]=me,e[19]=ae):ae=e[19];const be=ae;let re;e[20]!==fe?(re=()=>{Ce(fe())},e[20]=fe,e[21]=re):re=e[21];const Ne=re,je="flex flex-col gap-6",ze="lunora-queues-panel";let B;e[22]!==a||e[23]!==o?(B=s("div",{className:"flex items-center gap-1","data-testid":"queues-tabs",role:"tablist",children:["declared","messages","send"].map(c=>s(Qe,{"aria-selected":o===c,"data-tab":c,"data-testid":`queues-tab-${c}`,onClick:Pe,role:"tab",size:"sm",type:"button",variant:o===c?"secondary":"ghost",children:mt(c,a)},c))}),e[22]=a,e[23]=o,e[24]=B):B=e[24];let R;e[25]!==ie||e[26]!==ce?(R=ie!==null&&s(Xe,{error:ce,testId:"queues-error"}),e[25]=ie,e[26]=ce,e[27]=R):R=e[27];const qe=D&&s(Ke,{icon:s("span",{"aria-hidden":"true",className:"text-base leading-none",children:"⚠"}),testId:"queues-dlq-warning",variant:"warning",children:q("div",{className:"flex flex-col gap-1",children:[Q.length>0&&q(Fe,{children:[s("p",{className:"font-medium",children:a("No dead-letter queue on {queues}.",{queues:Q.map(Nt).join(", ")})}),s("p",{className:"text-muted-foreground",children:a("Exhausted messages are dropped after retries. Add a deadLetterQueue to capture them.")})]}),v>0&&s("p",{className:Q.length>0?"text-muted-foreground":"font-medium",children:v===1?a("1 message was recently dead-lettered."):a("{count} messages were recently dead-lettered.",{count:v})})]})});let $;e[28]!==E||e[29]!==y||e[30]!==o?($=o==="declared"&&s(ft,{loaded:y!==void 0,queues:E}),e[28]=E,e[29]=y,e[30]=o,e[31]=$):$=e[31];let O;e[32]!==w||e[33]!==h||e[34]!==Ne||e[35]!==be||e[36]!==de||e[37]!==o?(O=o==="messages"&&s(pt,{hasError:h!==null,messages:w,onClear:Ne,onReplay:be,replayingId:de}),e[32]=w,e[33]=h,e[34]=Ne,e[35]=be,e[36]=de,e[37]=o,e[38]=O):O=e[38];let k;e[39]!==F||e[40]!==A||e[41]!==C||e[42]!==xe||e[43]!==pe||e[44]!==ge||e[45]!==he||e[46]!==ye||e[47]!==E||e[48]!==z||e[49]!==le||e[50]!==o?(k=o==="send"&&s(gt,{batchMode:F,bodyText:A,delayText:C,onBatchModeChange:xe,onBodyChange:pe,onDelayChange:ge,onSelectExport:he,onSend:ye,queues:E,selectedExportName:z,sending:le}),e[39]=F,e[40]=A,e[41]=C,e[42]=xe,e[43]=pe,e[44]=ge,e[45]=he,e[46]=ye,e[47]=E,e[48]=z,e[49]=le,e[50]=o,e[51]=k):k=e[51];let ne;return e[52]!==B||e[53]!==R||e[54]!==qe||e[55]!==$||e[56]!==O||e[57]!==k?(ne=q("div",{className:je,"data-testid":ze,children:[B,R,qe,$,O,k]}),e[52]=B,e[53]=R,e[54]=qe,e[55]=$,e[56]=O,e[57]=k,e[58]=ne):ne=e[58],ne};function xt(n){return q(oe,{"data-testid":`queues-row-${n.exportName}`,children:[s(T,{className:"font-mono text-xs",children:n.exportName}),s(T,{className:"font-mono text-xs text-muted-foreground",children:n.name}),s(T,{className:"font-mono text-xs text-muted-foreground",children:n.mode}),s(T,{className:"font-mono text-xs text-muted-foreground",children:n.binding}),s(T,{className:"font-mono text-xs text-muted-foreground",children:n.deadLetterQueue??"—"})]},n.exportName)}function yt(n){return s("option",{value:n.exportName,children:n.exportName},n.exportName)}function bt(n,e){return n.exportName.localeCompare(e.exportName)}function Nt(n){return n.name}export{Ft as default};
1
+ import{c as P}from"react/compiler-runtime";import{useLunora as Ve}from"@lunora/react";import{useState as M}from"react";import{ConfirmButton as Ye}from"../packem_shared/ConfirmButton-DU4p72Er.mjs";import{E as Xe}from"../packem_shared/error-alert-tf5zvSLV.mjs";import{A as Ke}from"../packem_shared/alert-PB5W11MM.mjs";import{B as ve}from"../packem_shared/badge-r_5B4LHP.mjs";import{B as we}from"../packem_shared/button-q0UYSmrn.mjs";import{C as $e,a as Oe}from"../packem_shared/card--2hKx4L2.mjs";import{E as Qe}from"../packem_shared/empty-state-D7jEML_T.mjs";import{I as Ze}from"../packem_shared/input-CXhxesPC.mjs";import{S as et}from"../packem_shared/scroll-area-CXCQH7VT.mjs";import{T as ke,a as Ue,b as oe,c as _,d as Je,e as T}from"../packem_shared/table-D0SBiDu-.mjs";import{T as tt}from"../packem_shared/textarea--40GKAyz.mjs";import{u as Be}from"../packem_shared/use-admin-query-BKXiqLci.mjs";import{useAutoRefresh as st}from"../packem_shared/DEFAULT_AUTO_REFRESH_MS-DuULO4XM.mjs";import{useT as j}from"../packem_shared/DEFAULT_LOCALE-A1Yg5ORA.mjs";import{ADMIN_FUNCTIONS as G}from"../packem_shared/ADMIN_FUNCTIONS-B8yyk5BX.mjs";import{d as _e,b as Te,c as Ae,f as Ce,h as at}from"../packem_shared/internal-B6haJbiP.mjs";import{jsx as s,jsxs as q,Fragment as Fe}from"react/jsx-runtime";const rt=(n,e)=>{const t=new Set(n.map(a=>a.deadLetterQueue).filter(a=>typeof a=="string"&&a!=="")),i=n.filter(a=>(a.deadLetterQueue===void 0||a.deadLetterQueue==="")&&!t.has(a.name)),l=e.filter(a=>a.deadLettered).length;return{deadLetteredCount:l,queuesWithoutDlq:i,showReliabilityWarning:i.length>0||l>0}},nt=200,ot=Ae(G.sendQueueMessage),lt=Ae(G.replayQueueMessage),dt=Ae(G.clearQueueMessages),Re=96,it=n=>{if(n===void 0)return"—";try{return JSON.stringify(n)}catch{return"[unserializable]"}},ct=n=>n.length>Re?`${n.slice(0,Re)}…`:n,ut=n=>n==="error"?"destructive":n==="retry"?"outline":"secondary",mt=(n,e)=>e(n==="messages"?"Messages":n==="send"?"Send":"Declared"),ft=n=>{const e=P(11),{loaded:t,queues:i}=n,l=j();let a;e[0]!==l?(a=l("Queues are declared in code with defineQueue. Enqueue from a mutation or action with ctx.queues.<name>.send(...); push consumers process batches in the worker."),e[0]=l,e[1]=a):a=e[1];let o;e[2]!==a?(o=s("p",{className:"text-sm text-muted-foreground",children:a}),e[2]=a,e[3]=o):o=e[3];let r;e[4]!==t||e[5]!==i||e[6]!==l?(r=t&&i.length===0?s(Qe,{description:l("No defineQueue is declared in lunora/queues.ts in this deployment. Add one to offload async work to a Cloudflare Queue."),testId:"queues-empty",title:l("No queues defined")}):s($e,{className:"overflow-hidden py-0",children:s(Oe,{className:"px-0",children:q(ke,{"data-testid":"queues-table",children:[s(Ue,{children:q(oe,{children:[s(_,{children:l("Export")}),s(_,{children:l("Queue")}),s(_,{children:l("Mode")}),s(_,{children:l("Binding")}),s(_,{children:l("Dead-letter")})]})}),s(Je,{children:i.map(xt)})]})})}),e[4]=t,e[5]=i,e[6]=l,e[7]=r):r=e[7];let f;return e[8]!==o||e[9]!==r?(f=q("div",{className:"flex flex-col gap-4","data-testid":"queues-declared",children:[o,r]}),e[8]=o,e[9]=r,e[10]=f):f=e[10],f},ht=n=>{const e=P(67),{message:t,onReplay:i,replayingId:l}=n,a=j();let o,r,f,u,g,y,x,d,m,p;if(e[0]!==t.attempts||e[1]!==t.body||e[2]!==t.deadLettered||e[3]!==t.exportName||e[4]!==t.id||e[5]!==t.messageId||e[6]!==t.outcome||e[7]!==t.queue||e[8]!==a){const U=it(t.body);r=oe,y=`queues-message-${t.id}`;const J=t.exportName??t.queue;e[19]!==J?(x=s(T,{className:"font-mono text-xs",children:J}),e[19]=J,e[20]=x):x=e[20],e[21]!==t.messageId?(d=s(T,{className:"max-w-[16ch] truncate font-mono text-xs text-muted-foreground",title:t.messageId,children:t.messageId}),e[21]=t.messageId,e[22]=d):d=e[22],e[23]!==t.attempts?(m=s(T,{className:"font-mono text-xs tabular-nums",children:t.attempts}),e[23]=t.attempts,e[24]=m):m=e[24];const A=`queues-outcome-${t.id}`;let I;e[25]!==t.outcome?(I=ut(t.outcome),e[25]=t.outcome,e[26]=I):I=e[26];let C;e[27]!==t.outcome||e[28]!==A||e[29]!==I?(C=s(ve,{"data-testid":A,variant:I,children:t.outcome}),e[27]=t.outcome,e[28]=A,e[29]=I,e[30]=C):C=e[30];let L;e[31]!==t.deadLettered||e[32]!==t.id||e[33]!==a?(L=t.deadLettered&&s(ve,{"data-testid":`queues-dlq-${t.id}`,variant:"destructive",children:a("DLQ")}),e[31]=t.deadLettered,e[32]=t.id,e[33]=a,e[34]=L):L=e[34],e[35]!==C||e[36]!==L?(p=s(T,{children:q("span",{className:"inline-flex items-center gap-1",children:[C,L]})}),e[35]=C,e[36]=L,e[37]=p):p=e[37],o=T,f="max-w-[32ch] truncate font-mono text-xs text-muted-foreground",u=U,g=ct(U),e[0]=t.attempts,e[1]=t.body,e[2]=t.deadLettered,e[3]=t.exportName,e[4]=t.id,e[5]=t.messageId,e[6]=t.outcome,e[7]=t.queue,e[8]=a,e[9]=o,e[10]=r,e[11]=f,e[12]=u,e[13]=g,e[14]=y,e[15]=x,e[16]=d,e[17]=m,e[18]=p}else o=e[9],r=e[10],f=e[11],u=e[12],g=e[13],y=e[14],x=e[15],d=e[16],m=e[17],p=e[18];let h;e[38]!==o||e[39]!==f||e[40]!==u||e[41]!==g?(h=s(o,{className:f,title:u,children:g}),e[38]=o,e[39]=f,e[40]=u,e[41]=g,e[42]=h):h=e[42];let N;e[43]!==t.capturedAt?(N=at(t.capturedAt,"—"),e[43]=t.capturedAt,e[44]=N):N=e[44];let b;e[45]!==N?(b=s(T,{className:"text-xs text-muted-foreground tabular-nums",children:N}),e[45]=N,e[46]=b):b=e[46];const E=`queues-replay-${t.id}`,Q=l!==null;let v;e[47]!==t.id||e[48]!==l||e[49]!==a?(v=l===t.id?a("Replaying…"):a("Replay"),e[47]=t.id,e[48]=l,e[49]=a,e[50]=v):v=e[50];let w;e[51]!==t.id||e[52]!==i||e[53]!==E||e[54]!==Q||e[55]!==v?(w=s(T,{children:s(we,{"data-id":t.id,"data-testid":E,disabled:Q,onClick:i,size:"xs",type:"button",variant:"outline",children:v})}),e[51]=t.id,e[52]=i,e[53]=E,e[54]=Q,e[55]=v,e[56]=w):w=e[56];let D;return e[57]!==r||e[58]!==b||e[59]!==w||e[60]!==y||e[61]!==x||e[62]!==d||e[63]!==m||e[64]!==p||e[65]!==h?(D=q(r,{"data-testid":y,children:[x,d,m,p,h,b,w]}),e[57]=r,e[58]=b,e[59]=w,e[60]=y,e[61]=x,e[62]=d,e[63]=m,e[64]=p,e[65]=h,e[66]=D):D=e[66],D},pt=n=>{const e=P(29),{hasError:t,messages:i,onClear:l,onReplay:a,replayingId:o}=n,r=j();let f;e[0]!==r?(f=r("Cloudflare Queues have no peek API, so this is what push consumers actually processed — not pending depth."),e[0]=r,e[1]=f):f=e[1];let u;e[2]!==f?(u=s("p",{className:"text-sm text-muted-foreground",children:f}),e[2]=f,e[3]=u):u=e[3];let g;e[4]!==r?(g=r("Clear the whole message log?"),e[4]=r,e[5]=g):g=e[5];const y=i.length===0;let x;e[6]!==r?(x=r("Clear log"),e[6]=r,e[7]=x):x=e[7];let d;e[8]!==l||e[9]!==g||e[10]!==y||e[11]!==x?(d=s("div",{className:"ml-auto",children:s(Ye,{confirmLabel:g,disabled:y,onConfirm:l,testId:"queues-clear",children:x})}),e[8]=l,e[9]=g,e[10]=y,e[11]=x,e[12]=d):d=e[12];let m;e[13]!==i.length||e[14]!==r?(m=i.length>0&&s(ve,{"data-testid":"queues-count",variant:"secondary",children:r("{count} messages",{count:i.length})}),e[13]=i.length,e[14]=r,e[15]=m):m=e[15];let p;e[16]!==u||e[17]!==d||e[18]!==m?(p=q("div",{className:"flex flex-wrap items-center gap-2",children:[u,d,m]}),e[16]=u,e[17]=d,e[18]=m,e[19]=p):p=e[19];let h;e[20]!==t||e[21]!==i||e[22]!==a||e[23]!==o||e[24]!==r?(h=!t&&i.length===0?s(Qe,{description:r("Consumed messages appear here once a push consumer processes a batch in dev. Send one from the Send tab to see it captured."),testId:"queues-messages-empty",title:r("No consumed messages yet.")}):s($e,{className:"overflow-hidden py-0",children:s(Oe,{className:"px-0",children:s(et,{className:"max-h-[32rem]","data-testid":"queues-messages-scroll",children:q(ke,{"data-testid":"queues-messages-table",children:[s(Ue,{children:q(oe,{children:[s(_,{children:r("Export")}),s(_,{children:r("Message")}),s(_,{children:r("Attempts")}),s(_,{children:r("Outcome")}),s(_,{children:r("Body")}),s(_,{children:r("Captured")}),s(_,{})]})}),s(Je,{children:i.map(b=>s(ht,{message:b,onReplay:a,replayingId:o},b.id))})]})})})}),e[20]=t,e[21]=i,e[22]=a,e[23]=o,e[24]=r,e[25]=h):h=e[25];let N;return e[26]!==p||e[27]!==h?(N=q("div",{className:"flex flex-col gap-4","data-testid":"queues-messages",children:[p,h]}),e[26]=p,e[27]=h,e[28]=N):N=e[28],N},gt=n=>{const e=P(20),{batchMode:t,bodyText:i,delayText:l,onBatchModeChange:a,onBodyChange:o,onDelayChange:r,onSelectExport:f,onSend:u,queues:g,selectedExportName:y,sending:x}=n,d=j();let m;e[0]!==d?(m=d("Enqueue a JSON message to a declared producer to exercise its consumer. Nothing is captured until the consumer processes it."),e[0]=d,e[1]=m):m=e[1];let p;e[2]!==m?(p=s("p",{className:"text-sm text-muted-foreground",children:m}),e[2]=m,e[3]=p):p=e[3];let h;e[4]!==t||e[5]!==i||e[6]!==l||e[7]!==a||e[8]!==o||e[9]!==r||e[10]!==f||e[11]!==u||e[12]!==g||e[13]!==y||e[14]!==x||e[15]!==d?(h=g.length===0?s(Qe,{description:d("Declare a queue with defineQueue in lunora/queues.ts to enqueue a test message."),testId:"queues-send-empty",title:d("No queues to send to")}):q(Fe,{children:[q("div",{className:"flex flex-wrap items-center gap-2",children:[s("select",{"aria-label":d("Queue"),className:"h-8 rounded-md border border-input bg-transparent px-2.5 py-1 text-xs outline-none focus-visible:border-ring focus-visible:ring-1 focus-visible:ring-ring/50","data-testid":"queues-send-select",onChange:f,value:y,children:g.map(yt)}),s(Ze,{"aria-label":d("Delay (seconds)"),className:"max-w-36","data-testid":"queues-send-delay",min:0,onChange:r,placeholder:d("Delay (s)"),type:"number",value:l}),q("label",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",htmlFor:"queues-send-batch",children:[s("input",{checked:t,"data-testid":"queues-send-batch",id:"queues-send-batch",onChange:a,type:"checkbox"}),d("Send as batch (JSON array)")]}),s(we,{className:"ml-auto","data-testid":"queues-send-button",disabled:x||y==="",onClick:u,type:"button",children:d(x?"Sending…":"Send message")})]}),s(tt,{"aria-label":d("Message body (JSON)"),className:"font-mono","data-testid":"queues-send-body",onChange:o,placeholder:t?'[ { "hello": "world" } ]':'{ "hello": "world" }',value:i})]}),e[4]=t,e[5]=i,e[6]=l,e[7]=a,e[8]=o,e[9]=r,e[10]=f,e[11]=u,e[12]=g,e[13]=y,e[14]=x,e[15]=d,e[16]=h):h=e[16];let N;return e[17]!==p||e[18]!==h?(N=q("div",{className:"flex flex-col gap-3","data-testid":"queues-send",children:[p,h]}),e[17]=p,e[18]=h,e[19]=N):N=e[19],N},Ft=n=>{const e=P(59),{limit:t}=n,i=t??nt,l=Ve(),a=j(),[o,r]=M("declared"),[f,u]=M(null);let g;e[0]===Symbol.for("react.memo_cache_sentinel")?(g={},e[0]=g):g=e[0];const{data:y,error:x,errorSource:d}=Be(G.listQueues,g);let m;e[1]!==i?(m={limit:i},e[1]=i,e[2]=m):m=e[2];const{data:p,error:h,errorSource:N,refetch:b}=Be(G.getQueueMessages,m),E=Array.isArray(y?.queues)?[...y.queues].toSorted(bt):[],Q=p?.entries??[],{deadLetteredCount:v,queuesWithoutDlq:w,showReliabilityWarning:D}=rt(E,Q),[U,J]=M(""),[A,I]=M(""),[C,L]=M(""),[F,We]=M(!1),[le,Ie]=M(!1),[de,Le]=M(null),z=E.some(c=>c.exportName===U)?U:E[0]?.exportName??"",Me=o==="messages"?h:x,Ge=o==="messages"?N:d,ie=Me??f,ce=Me===null?f:Ge;let H;e[3]!==b?(H=()=>{b()},e[3]=b,e[4]=H):H=e[4],st(H,o==="messages");const ue=async()=>{u(null);const c=z;if(c==="")return;let S=null;const Se=A.trim();if(Se!=="")try{S=JSON.parse(Se)}catch{u(a("Body must be valid JSON."));return}let Ee;const De=C.trim();if(De!==""){const W=Number(De);if(!Number.isFinite(W)||W<0){u(a("Delay must be a non-negative number of seconds."));return}Ee=W}if(F&&!Array.isArray(S)){u(a("Batch mode needs a JSON array body — each element is enqueued as one message."));return}Ie(!0);const He=F?{batch:S,delaySeconds:Ee,exportName:c}:{body:S,delaySeconds:Ee,exportName:c};try{await l.query(ot,He,_e("")),b()}catch(W){u(Te(W))}Ie(!1)};let V;e[5]!==l||e[6]!==b?(V=async c=>{u(null),Le(c);try{await l.query(lt,{id:c},_e("")),b()}catch(S){u(Te(S))}Le(null)},e[5]=l,e[6]=b,e[7]=V):V=e[7];const me=V;let Y;e[8]!==l||e[9]!==b?(Y=async()=>{u(null);try{await l.query(dt,{},_e("")),b()}catch(c){u(Te(c))}},e[8]=l,e[9]=b,e[10]=Y):Y=e[10];const fe=Y;let X;e[11]===Symbol.for("react.memo_cache_sentinel")?(X=c=>{const S=c.currentTarget.dataset.tab;(S==="declared"||S==="messages"||S==="send")&&r(S)},e[11]=X):X=e[11];const Pe=X;let K;e[12]===Symbol.for("react.memo_cache_sentinel")?(K=c=>{J(c.currentTarget.value)},e[12]=K):K=e[12];const he=K;let Z;e[13]===Symbol.for("react.memo_cache_sentinel")?(Z=c=>{I(c.currentTarget.value)},e[13]=Z):Z=e[13];const pe=Z;let ee;e[14]===Symbol.for("react.memo_cache_sentinel")?(ee=c=>{L(c.currentTarget.value)},e[14]=ee):ee=e[14];const ge=ee;let te;e[15]===Symbol.for("react.memo_cache_sentinel")?(te=c=>{We(c.currentTarget.checked)},e[15]=te):te=e[15];const xe=te;let se;e[16]!==ue?(se=()=>{Ce(ue())},e[16]=ue,e[17]=se):se=e[17];const ye=se;let ae;e[18]!==me?(ae=c=>{const{id:S}=c.currentTarget.dataset;S!==void 0&&Ce(me(S))},e[18]=me,e[19]=ae):ae=e[19];const be=ae;let re;e[20]!==fe?(re=()=>{Ce(fe())},e[20]=fe,e[21]=re):re=e[21];const Ne=re,je="flex flex-col gap-6",ze="lunora-queues-panel";let B;e[22]!==a||e[23]!==o?(B=s("div",{className:"flex items-center gap-1","data-testid":"queues-tabs",role:"tablist",children:["declared","messages","send"].map(c=>s(we,{"aria-selected":o===c,"data-tab":c,"data-testid":`queues-tab-${c}`,onClick:Pe,role:"tab",size:"sm",type:"button",variant:o===c?"secondary":"ghost",children:mt(c,a)},c))}),e[22]=a,e[23]=o,e[24]=B):B=e[24];let R;e[25]!==ie||e[26]!==ce?(R=ie!==null&&s(Xe,{error:ce,testId:"queues-error"}),e[25]=ie,e[26]=ce,e[27]=R):R=e[27];const qe=D&&s(Ke,{icon:s("span",{"aria-hidden":"true",className:"text-base leading-none",children:"⚠"}),testId:"queues-dlq-warning",variant:"warning",children:q("div",{className:"flex flex-col gap-1",children:[w.length>0&&q(Fe,{children:[s("p",{className:"font-medium",children:a("No dead-letter queue on {queues}.",{queues:w.map(Nt).join(", ")})}),s("p",{className:"text-muted-foreground",children:a("Exhausted messages are dropped after retries. Add a deadLetterQueue to capture them.")})]}),v>0&&s("p",{className:w.length>0?"text-muted-foreground":"font-medium",children:v===1?a("1 message was recently dead-lettered."):a("{count} messages were recently dead-lettered.",{count:v})})]})});let $;e[28]!==E||e[29]!==y||e[30]!==o?($=o==="declared"&&s(ft,{loaded:y!==void 0,queues:E}),e[28]=E,e[29]=y,e[30]=o,e[31]=$):$=e[31];let O;e[32]!==Q||e[33]!==h||e[34]!==Ne||e[35]!==be||e[36]!==de||e[37]!==o?(O=o==="messages"&&s(pt,{hasError:h!==null,messages:Q,onClear:Ne,onReplay:be,replayingId:de}),e[32]=Q,e[33]=h,e[34]=Ne,e[35]=be,e[36]=de,e[37]=o,e[38]=O):O=e[38];let k;e[39]!==F||e[40]!==A||e[41]!==C||e[42]!==xe||e[43]!==pe||e[44]!==ge||e[45]!==he||e[46]!==ye||e[47]!==E||e[48]!==z||e[49]!==le||e[50]!==o?(k=o==="send"&&s(gt,{batchMode:F,bodyText:A,delayText:C,onBatchModeChange:xe,onBodyChange:pe,onDelayChange:ge,onSelectExport:he,onSend:ye,queues:E,selectedExportName:z,sending:le}),e[39]=F,e[40]=A,e[41]=C,e[42]=xe,e[43]=pe,e[44]=ge,e[45]=he,e[46]=ye,e[47]=E,e[48]=z,e[49]=le,e[50]=o,e[51]=k):k=e[51];let ne;return e[52]!==B||e[53]!==R||e[54]!==qe||e[55]!==$||e[56]!==O||e[57]!==k?(ne=q("div",{className:je,"data-testid":ze,children:[B,R,qe,$,O,k]}),e[52]=B,e[53]=R,e[54]=qe,e[55]=$,e[56]=O,e[57]=k,e[58]=ne):ne=e[58],ne};function xt(n){return q(oe,{"data-testid":`queues-row-${n.exportName}`,children:[s(T,{className:"font-mono text-xs",children:n.exportName}),s(T,{className:"font-mono text-xs text-muted-foreground",children:n.name}),s(T,{className:"font-mono text-xs text-muted-foreground",children:n.mode}),s(T,{className:"font-mono text-xs text-muted-foreground",children:n.binding}),s(T,{className:"font-mono text-xs text-muted-foreground",children:n.deadLetterQueue??"—"})]},n.exportName)}function yt(n){return s("option",{value:n.exportName,children:n.exportName},n.exportName)}function bt(n,e){return n.exportName.localeCompare(e.exportName)}function Nt(n){return n.name}export{Ft as default};