db-studio 1.9.4 → 1.9.5

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 (23) hide show
  1. package/README.md +5 -5
  2. package/dist/index.js +1 -1
  3. package/dist/index.js.map +1 -1
  4. package/dist/web-dist/assets/{_pathlessLayout-DhK1pVQZ.js → _pathlessLayout-beFslGvE.js} +1 -1
  5. package/dist/web-dist/assets/{_pathlessLayout-DhK1pVQZ.js.map → _pathlessLayout-beFslGvE.js.map} +1 -1
  6. package/dist/web-dist/assets/{_queryId-PHL0xcKj.js → _queryId-C4zyyS64.js} +1 -1
  7. package/dist/web-dist/assets/{_queryId-PHL0xcKj.js.map → _queryId-C4zyyS64.js.map} +1 -1
  8. package/dist/web-dist/assets/{_table-CThT7wMT.js → _table-DlrGH9zB.js} +1 -1
  9. package/dist/web-dist/assets/{_table-CThT7wMT.js.map → _table-DlrGH9zB.js.map} +1 -1
  10. package/dist/web-dist/assets/{_table-Ud147_vw.js → _table-aNWwwcm1.js} +1 -1
  11. package/dist/web-dist/assets/{_table-Ud147_vw.js.map → _table-aNWwwcm1.js.map} +1 -1
  12. package/dist/web-dist/assets/index-qlp0O2jT.js +86 -0
  13. package/dist/web-dist/assets/index-qlp0O2jT.js.map +1 -0
  14. package/dist/web-dist/assets/{queries.store-DruKauzK.js → queries.store-Cbuh20_d.js} +1 -1
  15. package/dist/web-dist/assets/{queries.store-DruKauzK.js.map → queries.store-Cbuh20_d.js.map} +1 -1
  16. package/dist/web-dist/assets/{query-runner-Db56mYGQ.js → query-runner-CRvSuMh-.js} +1 -1
  17. package/dist/web-dist/assets/{query-runner-Db56mYGQ.js.map → query-runner-CRvSuMh-.js.map} +1 -1
  18. package/dist/web-dist/assets/{runner-DAA3MnAn.js → runner-CNit1IxV.js} +1 -1
  19. package/dist/web-dist/assets/{runner-DAA3MnAn.js.map → runner-CNit1IxV.js.map} +1 -1
  20. package/dist/web-dist/index.html +1 -1
  21. package/package.json +1 -1
  22. package/dist/web-dist/assets/index-GnOMl7Md.js +0 -86
  23. package/dist/web-dist/assets/index-GnOMl7Md.js.map +0 -1
@@ -1,2 +1,2 @@
1
- import{r as xt}from"./rolldown-runtime-b3L32Ng1.js";import{_ as Ve,c as ye,d as pt,g as re,h as $e,n as gt,t as vt,v as bt,y as jt}from"./tanstack-C38qytx8.js";import{A as yt,D as Ge,E as Ct,G as We,J as Nt,L as wt,M as St,N as Tt,O as Dt,P as kt,U as Re,Y as Et,_ as Ce,b as zt,c as Rt,d as Ke,g as Lt,h as At,i as Ne,j as Ft,l as Ot,m as de,nt as It,p as _t,s as Mt,t as Pt,tt as Bt,v as Qt}from"./icons-B5bSDd0r.js";import{Ot as qt,a as Ut,c as Ht,d as Vt,ht as $t,i as Gt,l as Wt,o as Kt,r as Xt,s as Yt,u as Jt,wt as Le}from"./radix-ui-DS4zDRqg.js";import{r as Zt}from"./monitoring-Dw3KwoPJ.js";import{n as P}from"./dist-m8A6NETj.js";import{B as C,F as es,L as Ae,N as ts,R as ss,S as ns,a as G,c as rs,f as U,l as L,n as W,o as B,r as K,z as as}from"./format-cell-value-DG6WpZw_.js";import{$ as we,A as os,B as ls,C as is,D as cs,E as us,F as X,G as ds,H as ms,I as Y,J as fs,K as hs,L as J,M as xs,N as Z,P as ee,Q as V,R as te,S as Xe,T as $,U as q,V as ps,W as Fe,X as Se,Y as gs,Z as Te,a as vs,at as bs,b as js,c as ys,d as Cs,et as De,f as Ns,g as me,i as ws,it as Ss,j as Ts,k as Ds,l as ks,m as Es,nt as zs,p as Rs,q as Ls,r as As,rt as Fs,s as Os,tt as ke,u as Is,w as Ye,x as se,z as ne}from"./index-GnOMl7Md.js";import{r as Je}from"./chunk-BO2N2NFS-D1cKzRy7.js";import{t as fe}from"./queries.store-DruKauzK.js";var r=xt(It(),1),Ze={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},Oe=r.createContext&&r.createContext(Ze),_s=["attr","size","title"];function Ms(t,s){if(t==null)return{};var n,a,l=Ps(t,s);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);for(a=0;a<i.length;a++)n=i[a],s.indexOf(n)===-1&&{}.propertyIsEnumerable.call(t,n)&&(l[n]=t[n])}return l}function Ps(t,s){if(t==null)return{};var n={};for(var a in t)if({}.hasOwnProperty.call(t,a)){if(s.indexOf(a)!==-1)continue;n[a]=t[a]}return n}function ie(){return ie=Object.assign?Object.assign.bind():function(t){for(var s=1;s<arguments.length;s++){var n=arguments[s];for(var a in n)({}).hasOwnProperty.call(n,a)&&(t[a]=n[a])}return t},ie.apply(null,arguments)}function Ie(t,s){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(t);s&&(a=a.filter(function(l){return Object.getOwnPropertyDescriptor(t,l).enumerable})),n.push.apply(n,a)}return n}function ce(t){for(var s=1;s<arguments.length;s++){var n=arguments[s]!=null?arguments[s]:{};s%2?Ie(Object(n),!0).forEach(function(a){Bs(t,a,n[a])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Ie(Object(n)).forEach(function(a){Object.defineProperty(t,a,Object.getOwnPropertyDescriptor(n,a))})}return t}function Bs(t,s,n){return(s=Qs(s))in t?Object.defineProperty(t,s,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[s]=n,t}function Qs(t){var s=qs(t,"string");return typeof s=="symbol"?s:s+""}function qs(t,s){if(typeof t!="object"||!t)return t;var n=t[Symbol.toPrimitive];if(n!==void 0){var a=n.call(t,s||"default");if(typeof a!="object")return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return(s==="string"?String:Number)(t)}function et(t){return t&&t.map((s,n)=>r.createElement(s.tag,ce({key:n},s.attr),et(s.child)))}function Us(t){return s=>r.createElement(Hs,ie({attr:ce({},t.attr)},s),et(t.child))}function Hs(t){var s=n=>{var{attr:a,size:l,title:i}=t,u=Ms(t,_s),c=l||n.size||"1em",h;return n.className&&(h=n.className),t.className&&(h=(h?h+" ":"")+t.className),r.createElement("svg",ie({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},n.attr,a,u,{className:h,style:ce(ce({color:t.color||n.color},n.style),t.style),height:c,width:c,xmlns:"http://www.w3.org/2000/svg"}),i&&r.createElement("title",null,i),t.children)};return Oe!==void 0?r.createElement(Oe.Consumer,null,n=>s(n)):s(Ze)}function Vs(t){return Us({tag:"svg",attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M15 22v-4a4.8 4.8 0 0 0-1-3.5c3 0 6-2 6-5.5.08-1.25-.27-2.48-1-3.5.28-1.15.28-2.35 0-3.5 0 0-1 0-3 1.5-2.64-.5-5.36-.5-8 0C6 2 5 2 5 2c-.3 1.15-.3 2.35 0 3.5A5.403 5.403 0 0 0 4 9c0 3.5 3 5.5 6 5.5-.39.49-.68 1.05-.85 1.65-.17.6-.22 1.23-.15 1.85v4"},child:[]},{tag:"path",attr:{d:"M9 18c-4.51 2-5-2-7-2"},child:[]}]})(t)}var $s={damping:.7,stiffness:.05,mass:1.25},Gs=70,Ws=1e3/60,Ks=350,he=!1;globalThis.document?.addEventListener("mousedown",()=>{he=!0});globalThis.document?.addEventListener("mouseup",()=>{he=!1});globalThis.document?.addEventListener("click",()=>{he=!1});var Xs=(t={})=>{const[s,n]=(0,r.useState)(!1),[a,l]=(0,r.useState)(t.initial!==!1),[i,u]=(0,r.useState)(!1),c=(0,r.useRef)(null);c.current=t;const h=(0,r.useCallback)(()=>{if(!he)return!1;const p=window.getSelection();if(!p||!p.rangeCount)return!1;const b=p.getRangeAt(0);return b.commonAncestorContainer.contains(m.current)||m.current?.contains(b.commonAncestorContainer)},[]),f=(0,r.useCallback)(p=>{o.isAtBottom=p,l(p)},[]),g=(0,r.useCallback)(p=>{o.escapedFromLock=p,n(p)},[]),o=(0,r.useMemo)(()=>{let p;return{escapedFromLock:s,isAtBottom:a,resizeDifference:0,accumulated:0,velocity:0,listeners:new Set,get scrollTop(){return m.current?.scrollTop??0},set scrollTop(b){if(m.current){const{scrollBehavior:v}=getComputedStyle(m.current);v!=="auto"&&(m.current.style.scrollBehavior="auto"),m.current.scrollTop=b,o.ignoreScrollToTop=m.current.scrollTop,v!=="auto"&&(m.current.style.scrollBehavior=v)}},get targetScrollTop(){return!m.current||!w.current?0:m.current.scrollHeight-1-m.current.clientHeight},get calculatedTargetScrollTop(){if(!m.current||!w.current)return 0;const{targetScrollTop:b}=this;if(!t.targetScrollTop)return b;if(p?.targetScrollTop===b)return p.calculatedScrollTop;const v=Math.max(Math.min(t.targetScrollTop(b,{scrollElement:m.current,contentElement:w.current}),b),0);return p={targetScrollTop:b,calculatedScrollTop:v},requestAnimationFrame(()=>{p=void 0}),v},get scrollDifference(){return this.calculatedTargetScrollTop-this.scrollTop},get isNearBottom(){return this.scrollDifference<=Gs}}},[]),d=(0,r.useCallback)((p={})=>{typeof p=="string"&&(p={animation:p}),p.preserveScrollPosition||f(!0);const b=Date.now()+(Number(p.wait)||0),v=be(c.current,p.animation),{ignoreEscapes:z=!1}=p;let R,y=o.calculatedTargetScrollTop;p.duration instanceof Promise?p.duration.finally(()=>{R=Date.now()}):R=b+(p.duration??0);const T=async()=>{const O=new Promise(requestAnimationFrame).then(()=>{if(!o.isAtBottom)return o.animation=void 0,!1;const{scrollTop:F}=o,_=performance.now(),M=(_-(o.lastTick??_))/Ws;if(o.animation||(o.animation={behavior:v,promise:O,ignoreEscapes:z}),o.animation.behavior===v&&(o.lastTick=_),h()||b>Date.now())return T();if(F<Math.min(y,o.calculatedTargetScrollTop)){if(o.animation?.behavior===v){if(v==="instant")return o.scrollTop=o.calculatedTargetScrollTop,T();o.velocity=(v.damping*o.velocity+v.stiffness*o.scrollDifference)/v.mass,o.accumulated+=o.velocity*M,o.scrollTop+=o.accumulated,o.scrollTop!==F&&(o.accumulated=0)}return T()}return R>Date.now()?(y=o.calculatedTargetScrollTop,T()):(o.animation=void 0,o.scrollTop<o.calculatedTargetScrollTop?d({animation:be(c.current,c.current.resize),ignoreEscapes:z,duration:Math.max(0,R-Date.now())||void 0}):o.isAtBottom)});return O.then(F=>(requestAnimationFrame(()=>{o.animation||(o.lastTick=void 0,o.velocity=0)}),F))};return p.wait!==!0&&(o.animation=void 0),o.animation?.behavior===v?o.animation.promise:T()},[f,h,o]),j=(0,r.useCallback)(()=>{g(!0),f(!1)},[g,f]),x=(0,r.useCallback)(({target:p})=>{if(p!==m.current)return;const{scrollTop:b,ignoreScrollToTop:v}=o;let{lastScrollTop:z=b}=o;o.lastScrollTop=b,o.ignoreScrollToTop=void 0,v&&v>b&&(z=v),u(o.isNearBottom),setTimeout(()=>{if(o.resizeDifference||b===v)return;if(h()){g(!0),f(!1);return}const R=b>z,y=b<z;if(o.animation?.ignoreEscapes){o.scrollTop=z;return}y&&(g(!0),f(!1)),R&&g(!1),!o.escapedFromLock&&o.isNearBottom&&f(!0)},1)},[g,f,h,o]),N=(0,r.useCallback)(({target:p,deltaY:b})=>{let v=p;for(;!["scroll","auto"].includes(getComputedStyle(v).overflow);){if(!v.parentElement)return;v=v.parentElement}v===m.current&&b<0&&m.current.scrollHeight>m.current.clientHeight&&!o.animation?.ignoreEscapes&&(g(!0),f(!1))},[g,f,o]),m=_e(p=>{m.current?.removeEventListener("scroll",x),m.current?.removeEventListener("wheel",N),p?.addEventListener("scroll",x,{passive:!0}),p?.addEventListener("wheel",N,{passive:!0})},[]),w=_e(p=>{if(o.resizeObserver?.disconnect(),!p)return;let b;o.resizeObserver=new ResizeObserver(([v])=>{const{height:z}=v.contentRect,R=z-(b??z);if(o.resizeDifference=R,o.scrollTop>o.targetScrollTop&&(o.scrollTop=o.targetScrollTop),u(o.isNearBottom),R>=0){const y=be(c.current,b?c.current.resize:c.current.initial);d({animation:y,wait:!0,preserveScrollPosition:!0,duration:y==="instant"?void 0:Ks})}else o.isNearBottom&&(g(!1),f(!0));b=z,requestAnimationFrame(()=>{setTimeout(()=>{o.resizeDifference===R&&(o.resizeDifference=0)},1)})}),o.resizeObserver?.observe(p)},[]);return{contentRef:w,scrollRef:m,scrollToBottom:d,stopScroll:j,isAtBottom:a||i,isNearBottom:i,escapedFromLock:s,state:o}};function _e(t,s){const n=(0,r.useCallback)(a=>(n.current=a,t(a)),s);return n}var ve=new Map;function be(...t){const s={...$s};let n=!1;for(const l of t){if(l==="instant"){n=!0;continue}typeof l=="object"&&(n=!1,s.damping=l.damping??s.damping,s.stiffness=l.stiffness??s.stiffness,s.mass=l.mass??s.mass)}const a=JSON.stringify(s);return ve.has(a)||ve.set(a,Object.freeze(s)),n?"instant":ve.get(a)}var tt=(0,r.createContext)(null),Ys=typeof window<"u"?r.useLayoutEffect:r.useEffect;function ue({instance:t,children:s,resize:n,initial:a,mass:l,damping:i,stiffness:u,targetScrollTop:c,contextRef:h,...f}){const g=(0,r.useRef)(null),o=Xs({mass:l,damping:i,stiffness:u,resize:n,initial:a,targetScrollTop:r.useCallback((v,z)=>(b?.targetScrollTop??c)?.(v,z)??v,[c])}),{scrollRef:d,contentRef:j,scrollToBottom:x,stopScroll:N,isAtBottom:m,escapedFromLock:w,state:p}=t??o,b=(0,r.useMemo)(()=>({scrollToBottom:x,stopScroll:N,scrollRef:d,isAtBottom:m,escapedFromLock:w,contentRef:j,state:p,get targetScrollTop(){return g.current},set targetScrollTop(v){g.current=v}}),[x,m,j,d,N,w,p]);return(0,r.useImperativeHandle)(h,()=>b,[b]),Ys(()=>{d.current&&getComputedStyle(d.current).overflow==="visible"&&(d.current.style.overflow="auto")},[]),r.createElement(tt.Provider,{value:b},r.createElement("div",{...f},typeof s=="function"?s(b):s))}(function(t){function s({children:n,scrollClassName:a,...l}){const i=st();return r.createElement("div",{ref:i.scrollRef,style:{height:"100%",width:"100%",scrollbarGutter:"stable both-edges"},className:a},r.createElement("div",{...l,ref:i.contentRef},typeof n=="function"?n(i):n))}t.Content=s})(ue||(ue={}));function st(){const t=(0,r.useContext)(tt);if(!t)throw new Error("use-stick-to-bottom component context must be used within a StickToBottom component");return t}var e=qt(),Js=({className:t,...s})=>(0,e.jsx)(ue,{className:C("relative flex-1 overflow-y-hidden",t),initial:"smooth",resize:"smooth",role:"log",...s}),Zs=({className:t,...s})=>(0,e.jsx)(ue.Content,{className:C("flex flex-col gap-8 p-4",t),...s}),en=({className:t,...s})=>{const{isAtBottom:n,scrollToBottom:a}=st(),l=(0,r.useCallback)(()=>{a()},[a]);return!n&&(0,e.jsx)(L,{className:C("absolute bottom-4 left-[50%] translate-x-[-50%] rounded-full",t),onClick:l,size:"icon",type:"button",variant:"outline",...s,children:(0,e.jsx)(Bt,{className:"size-4"})})},Me=[{variant:"shine",component:({children:t,className:s,...n})=>(0,e.jsx)("span",{...n,className:C("bg-[linear-gradient(110deg,#bfbfbf,35%,#000,50%,#bfbfbf,75%,#bfbfbf)] dark:bg-[linear-gradient(110deg,#404040,35%,#fff,50%,#404040,75%,#404040)]","bg-size-[200%_100%] bg-clip-text text-transparent","animate-shine",s),children:t})}];function tn({variant:t="shine",className:s,...n}){const a=Me.find(l=>l.variant===t)?.component||Me[0].component;return(0,e.jsx)($t,{className:C("font-medium text-sm"),children:(0,e.jsx)(a,{...n,className:s})})}var Pe=({className:t,from:s,...n})=>(0,e.jsx)("div",{className:C("group flex w-full max-w-[95%] flex-col gap-2",s==="user"?"is-user ml-auto justify-end":"is-assistant",t),...n}),Be=({children:t,className:s,...n})=>(0,e.jsx)("div",{className:C("is-user:dark flex w-fit max-w-full min-w-0 flex-col gap-2 overflow-hidden text-sm","group-[.is-user]:ml-auto group-[.is-user]:rounded-lg group-[.is-user]:bg-secondary group-[.is-user]:px-4 group-[.is-user]:py-3 group-[.is-user]:text-foreground","group-[.is-assistant]:text-foreground",s),...n,children:t}),nt=(0,r.createContext)(null),sn=()=>{const t=(0,r.use)(nt);if(!t)throw new Error("MessageBranch components must be used within MessageBranch");return t},Qe=({defaultBranch:t=0,onBranchChange:s,className:n,...a})=>{const[l,i]=(0,r.useState)(t),[u,c]=(0,r.useState)([]),h=d=>{i(d),s?.(d)},f=()=>{const d=l>0?l-1:u.length-1;h(d)},g=()=>{const d=l<u.length-1?l+1:0;h(d)},o={currentBranch:l,totalBranches:u.length,goToPrevious:f,goToNext:g,branches:u,setBranches:c};return(0,e.jsx)(nt.Provider,{value:o,children:(0,e.jsx)("div",{className:C("grid w-full gap-2 [&>div]:pb-0",n),...a})})},qe=({children:t,...s})=>{const{currentBranch:n,setBranches:a,branches:l}=sn(),i=Array.isArray(t)?t:[t];return(0,r.useEffect)(()=>{l.length!==i.length&&a(i)},[i,l,a]),i.map((u,c)=>(0,e.jsx)("div",{className:C("grid gap-2 overflow-hidden [&>div]:pb-0",c===n?"block":"hidden"),...s,children:u},u.key))},rt=(0,r.memo)(({className:t,...s})=>(0,e.jsx)(Je,{className:C("size-full [&>*:first-child]:mt-0 [&>*:last-child]:mb-0",t),...s}),(t,s)=>t.children===s.children);rt.displayName="MessageResponse";var nn="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict",rn=(t=21)=>{let s="",n=crypto.getRandomValues(new Uint8Array(t|=0));for(;t--;)s+=nn[n[t]&63];return s},an=(0,r.createContext)(null),on=(0,r.createContext)(null),at=()=>(0,r.useContext)(an),ln=()=>(0,r.useContext)(on),ot=(0,r.createContext)(null),cn=()=>{const t=ln(),s=(0,r.use)(ot),n=t??s;if(!n)throw new Error("usePromptInputAttachments must be used within a PromptInput or PromptInputProvider");return n},un=({className:t,accept:s,multiple:n,globalDrop:a,syncHiddenInput:l,maxFiles:i,maxFileSize:u,onError:c,onSubmit:h,children:f,...g})=>{const o=at(),d=!!o,j=(0,r.useRef)(null),x=(0,r.useRef)(null),[N,m]=(0,r.useState)([]),w=d?o.attachments.files:N,p=(0,r.useRef)(w);p.current=w;const b=(0,r.useCallback)(()=>{j.current?.click()},[]),v=(0,r.useCallback)(S=>!s||s.trim()===""?!0:s.split(",").map(k=>k.trim()).filter(Boolean).some(k=>{if(k.endsWith("/*")){const E=k.slice(0,-1);return S.type.startsWith(E)}return S.type===k}),[s]),z=(0,r.useCallback)(S=>{const k=Array.from(S),E=k.filter(D=>v(D));if(k.length&&E.length===0){c?.({code:"accept",message:"No files match the accepted types."});return}const A=D=>u?D.size<=u:!0,I=E.filter(A);if(E.length>0&&I.length===0){c?.({code:"max_file_size",message:"All files exceed the maximum size."});return}m(D=>{const H=typeof i=="number"?Math.max(0,i-D.length):void 0,ht=typeof H=="number"?I.slice(0,H):I;typeof H=="number"&&I.length>H&&c?.({code:"max_files",message:"Too many files. Some were not added."});const ze=[];for(const ge of ht)ze.push({id:rn(),type:"file",url:URL.createObjectURL(ge),mediaType:ge.type,filename:ge.name});return D.concat(ze)})},[v,i,u,c]),R=(0,r.useCallback)(S=>m(k=>{const E=k.find(A=>A.id===S);return E?.url&&URL.revokeObjectURL(E.url),k.filter(A=>A.id!==S)}),[]),y=(0,r.useCallback)(()=>m(S=>{for(const k of S)k.url&&URL.revokeObjectURL(k.url);return[]}),[]),T=d?o.attachments.add:z,O=d?o.attachments.remove:R,F=d?o.attachments.clear:y,_=d?o.attachments.openFileDialog:b;(0,r.useEffect)(()=>{d&&o.__registerFileInput(j,()=>j.current?.click())},[d,o]),(0,r.useEffect)(()=>{l&&j.current&&w.length===0&&(j.current.value="")},[w,l]),(0,r.useEffect)(()=>{const S=x.current;if(!S||a)return;const k=A=>{A.dataTransfer?.types?.includes("Files")&&A.preventDefault()},E=A=>{A.dataTransfer?.types?.includes("Files")&&A.preventDefault(),A.dataTransfer?.files&&A.dataTransfer.files.length>0&&T(A.dataTransfer.files)};return S.addEventListener("dragover",k),S.addEventListener("drop",E),()=>{S.removeEventListener("dragover",k),S.removeEventListener("drop",E)}},[T,a]),(0,r.useEffect)(()=>{if(!a)return;const S=E=>{E.dataTransfer?.types?.includes("Files")&&E.preventDefault()},k=E=>{E.dataTransfer?.types?.includes("Files")&&E.preventDefault(),E.dataTransfer?.files&&E.dataTransfer.files.length>0&&T(E.dataTransfer.files)};return document.addEventListener("dragover",S),document.addEventListener("drop",k),()=>{document.removeEventListener("dragover",S),document.removeEventListener("drop",k)}},[T,a]),(0,r.useEffect)(()=>()=>{if(!d)for(const S of p.current)S.url&&URL.revokeObjectURL(S.url)},[d]);const M=S=>{S.currentTarget.files&&T(S.currentTarget.files),S.currentTarget.value=""},ae=async S=>{try{const k=await(await fetch(S)).blob();return new Promise(E=>{const A=new FileReader;A.onloadend=()=>E(A.result),A.onerror=()=>E(null),A.readAsDataURL(k)})}catch{return null}},xe=(0,r.useMemo)(()=>({files:w.map(S=>({...S,id:S.id})),add:T,remove:O,clear:F,openFileDialog:_,fileInputRef:j}),[w,T,O,F,_]),pe=S=>{S.preventDefault();const k=S.currentTarget,E=d?o.textInput.value:new FormData(k).get("message")||"";d||k.reset(),Promise.all(w.map(async({id:A,...I})=>{if(I.url?.startsWith("blob:")){const D=await ae(I.url);return{...I,url:D??I.url}}return I})).then(A=>{try{const I=h({text:E,files:A},S);I instanceof Promise?I.then(()=>{F(),d&&o.textInput.clear()}).catch(()=>{}):(F(),d&&o.textInput.clear())}catch{}}).catch(()=>{})},oe=(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("input",{accept:s,"aria-label":"Upload files",className:"hidden",multiple:n,onChange:M,ref:j,title:"Upload files",type:"file"}),(0,e.jsx)("form",{className:C("w-full",t),onSubmit:pe,ref:x,...g,children:(0,e.jsx)(Ds,{className:"overflow-hidden",children:f})})]});return d?oe:(0,e.jsx)(ot.Provider,{value:xe,children:oe})},dn=({className:t,...s})=>(0,e.jsx)("div",{className:C("contents",t),...s}),mn=({onChange:t,className:s,placeholder:n="What would you like to know?",...a})=>{const l=at(),i=cn(),[u,c]=(0,r.useState)(!1),h=o=>{if(o.key==="Enter"){if(u||o.nativeEvent.isComposing||o.shiftKey)return;o.preventDefault();const d=o.currentTarget.form;if(d?.querySelector('button[type="submit"]')?.disabled)return;d?.requestSubmit()}if(o.key==="Backspace"&&o.currentTarget.value===""&&i.files.length>0){o.preventDefault();const d=i.files.at(-1);d&&i.remove(d.id)}},f=o=>{const d=o.clipboardData?.items;if(!d)return;const j=[];for(const x of d)if(x.kind==="file"){const N=x.getAsFile();N&&j.push(N)}j.length>0&&(o.preventDefault(),i.add(j))},g=l?{value:l.textInput.value,onChange:o=>{l.textInput.setInput(o.currentTarget.value),t?.(o)}}:{onChange:t};return(0,e.jsx)(xs,{className:C("field-sizing-content max-h-48 min-h-16",s),name:"message",onCompositionEnd:()=>c(!1),onCompositionStart:()=>c(!0),onKeyDown:h,onPaste:f,placeholder:n,...a,...g})},fn=({className:t,...s})=>(0,e.jsx)(os,{align:"block-end",className:C("justify-between justify-end gap-1",t),...s}),hn=({className:t,variant:s="default",size:n="icon-sm",status:a,children:l,...i})=>{let u=(0,e.jsx)(Tt,{className:"size-4"});return a==="submitted"?u=(0,e.jsx)(zt,{className:"size-4 animate-spin"}):a==="streaming"?u=(0,e.jsx)(Rt,{className:"size-4"}):a==="error"&&(u=(0,e.jsx)(Pt,{className:"size-4"})),(0,e.jsx)(Ts,{"aria-label":"Submit",className:C(t),size:n,type:"submit",variant:s,...i,children:l??u})};function xn({...t}){return(0,e.jsx)(Jt,{"data-slot":"collapsible",...t})}function pn({...t}){return(0,e.jsx)(Vt,{"data-slot":"collapsible-trigger",...t})}function gn({...t}){return(0,e.jsx)(Wt,{"data-slot":"collapsible-content",...t})}var vn=({children:t,as:s="p",className:n,duration:a=2,spread:l=2})=>{const i=(0,r.useMemo)(()=>(t?.length??0)*l,[t,l]);return(0,e.jsx)(s,{className:C("relative inline-block bg-size-[250%_100%,auto] bg-clip-text text-transparent","[--bg:linear-gradient(90deg,#0000_calc(50%-var(--spread)),var(--color-background),#0000_calc(50%+var(--spread)))] [background-repeat:no-repeat,padding-box]","animate-shimmer",n),style:{"--spread":`${i}px`,"--duration":`${a}s`,backgroundImage:"var(--bg), linear-gradient(var(--color-muted-foreground), var(--color-muted-foreground))"},children:t})},bn=(0,r.memo)(vn),lt=(0,r.createContext)(null),jn=()=>{const t=(0,r.use)(lt);if(!t)throw new Error("Reasoning components must be used within Reasoning");return t},yn=1e3,Cn=1e3,it=(0,r.memo)(({className:t,isStreaming:s=!1,open:n,defaultOpen:a=!0,onOpenChange:l,duration:i,children:u,...c})=>{const[h,f]=Le({prop:n,defaultProp:a,onChange:l}),[g,o]=Le({prop:i,defaultProp:void 0}),[d,j]=(0,r.useState)(!1),[x,N]=(0,r.useState)(null);(0,r.useEffect)(()=>{s?x===null&&N(Date.now()):x!==null&&(o(Math.ceil((Date.now()-x)/Cn)),N(null))},[s,x,o]),(0,r.useEffect)(()=>{if(a&&!s&&h&&!d){const w=setTimeout(()=>{f(!1),j(!0)},yn);return()=>clearTimeout(w)}},[s,h,a,f,d]);const m=w=>{f(w)};return(0,e.jsx)(lt.Provider,{value:{isStreaming:s,isOpen:h,setIsOpen:f,duration:g},children:(0,e.jsx)(xn,{className:C("not-prose mb-4",t),onOpenChange:m,open:h,...c,children:u})})}),Nn=(t,s)=>t||s===0?(0,e.jsx)(bn,{duration:1,children:"Thinking..."}):s===void 0?(0,e.jsx)("p",{children:"Thought for a few seconds"}):(0,e.jsxs)("p",{children:["Thought for ",s," seconds"]}),ct=(0,r.memo)(({className:t,children:s,getThinkingMessage:n=Nn,...a})=>{const{isStreaming:l,isOpen:i,duration:u}=jn();return(0,e.jsx)(pn,{className:C("flex w-full items-center gap-2 text-muted-foreground text-sm transition-colors hover:text-foreground",t),...a,children:s??(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(Et,{className:"size-4"}),n(l,u),(0,e.jsx)(We,{className:C("size-4 transition-transform",i?"rotate-180":"rotate-0")})]})})}),ut=(0,r.memo)(({className:t,children:s,...n})=>(0,e.jsx)(gn,{className:C("mt-4 text-sm","data-[state=closed]:fade-out-0 data-[state=closed]:slide-out-to-top-2 data-[state=open]:slide-in-from-top-2 text-muted-foreground outline-none data-[state=closed]:animate-out data-[state=open]:animate-in",t),...n,children:(0,e.jsx)(Je,{children:s})}));it.displayName="Reasoning";ct.displayName="ReasoningTrigger";ut.displayName="ReasoningContent";var wn=({className:t,children:s,...n})=>(0,e.jsxs)(Xe,{className:"w-full overflow-x-auto whitespace-nowrap",...n,children:[(0,e.jsx)("div",{className:C("flex w-max flex-nowrap items-center gap-2",t),children:s}),(0,e.jsx)(is,{className:"hidden",orientation:"horizontal"})]}),Sn=({suggestion:t,onClick:s,className:n,variant:a="outline",size:l="sm",children:i,...u})=>{const c=()=>{s?.(t)};return(0,e.jsx)(L,{className:C("cursor-pointer rounded-full px-4",n),onClick:c,size:l,type:"button",variant:a,...u,children:i||t})},Ee=()=>{const{data:t,isLoading:s,error:n,refetch:a}=jt({queryKey:gs.rateLimit(),queryFn:async()=>{try{return(await ts()).data}catch{return{limit:0,used:0,remaining:0}}}});return{rateLimit:t,isLoadingRateLimit:s,errorRateLimit:n,refetchRateLimit:a}},Tn=({db:t,onRateLimitRefetch:s,onControllerReady:n})=>{const[a,l]=(0,r.useState)(""),{rateLimit:i}=Ee(),{remaining:u}=i??{remaining:0,limit:0},{messages:c,sendMessage:h,isLoading:f,clear:g,stop:o}=vt({connection:gt(`${es()}/chat`),body:{db:t},onError:m=>console.error("Error:",m.message),onFinish:()=>{s()}});(0,r.useEffect)(()=>{n({clear:()=>{g(),l("")},isLoading:f})},[g,f,n]);const d=m=>{const w=!!m.text,p=!!m.files?.length;!(w||p)||f||(h(m.text),l(""))},j=m=>{h(m),l("")},x=()=>{o(),l("")},N=f?"streaming":"ready";return(0,e.jsxs)("div",{className:"relative flex size-full flex-col divide-y overflow-hidden",children:[(0,e.jsxs)(Js,{children:[(0,e.jsx)(Zs,{children:c.length===0?(0,e.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground",children:(0,e.jsxs)("div",{className:"text-center space-y-2",children:[(0,e.jsx)("p",{className:"text-lg font-medium",children:"Start a new conversation"}),(0,e.jsx)("p",{className:"text-sm",children:"Ask me anything to get started"})]})}):(0,e.jsxs)(e.Fragment,{children:[c.map(m=>{const w=m.parts.filter(v=>v.type==="thinking"),p=m.parts.reduce((v,z)=>z.type==="text"?v+(z.content??""):v,""),b=w.length>0;return(0,e.jsx)(Qe,{defaultBranch:0,children:(0,e.jsx)(qe,{children:(0,e.jsx)(Pe,{from:m.role==="user"?"user":"assistant",children:(0,e.jsxs)("div",{children:[b&&m.role==="assistant"&&(0,e.jsxs)(it,{duration:0,children:[(0,e.jsx)(ct,{}),(0,e.jsx)(ut,{children:w.map(v=>v.content).join(`
1
+ import{r as xt}from"./rolldown-runtime-b3L32Ng1.js";import{_ as Ve,c as ye,d as pt,g as re,h as $e,n as gt,t as vt,v as bt,y as jt}from"./tanstack-C38qytx8.js";import{A as yt,D as Ge,E as Ct,G as We,J as Nt,L as wt,M as St,N as Tt,O as Dt,P as kt,U as Re,Y as Et,_ as Ce,b as zt,c as Rt,d as Ke,g as Lt,h as At,i as Ne,j as Ft,l as Ot,m as de,nt as It,p as _t,s as Mt,t as Pt,tt as Bt,v as Qt}from"./icons-B5bSDd0r.js";import{Ot as qt,a as Ut,c as Ht,d as Vt,ht as $t,i as Gt,l as Wt,o as Kt,r as Xt,s as Yt,u as Jt,wt as Le}from"./radix-ui-DS4zDRqg.js";import{r as Zt}from"./monitoring-Dw3KwoPJ.js";import{n as P}from"./dist-m8A6NETj.js";import{B as C,F as es,L as Ae,N as ts,R as ss,S as ns,a as G,c as rs,f as U,l as L,n as W,o as B,r as K,z as as}from"./format-cell-value-DG6WpZw_.js";import{$ as we,A as os,B as ls,C as is,D as cs,E as us,F as X,G as ds,H as ms,I as Y,J as fs,K as hs,L as J,M as xs,N as Z,P as ee,Q as V,R as te,S as Xe,T as $,U as q,V as ps,W as Fe,X as Se,Y as gs,Z as Te,a as vs,at as bs,b as js,c as ys,d as Cs,et as De,f as Ns,g as me,i as ws,it as Ss,j as Ts,k as Ds,l as ks,m as Es,nt as zs,p as Rs,q as Ls,r as As,rt as Fs,s as Os,tt as ke,u as Is,w as Ye,x as se,z as ne}from"./index-qlp0O2jT.js";import{r as Je}from"./chunk-BO2N2NFS-D1cKzRy7.js";import{t as fe}from"./queries.store-Cbuh20_d.js";var r=xt(It(),1),Ze={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},Oe=r.createContext&&r.createContext(Ze),_s=["attr","size","title"];function Ms(t,s){if(t==null)return{};var n,a,l=Ps(t,s);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);for(a=0;a<i.length;a++)n=i[a],s.indexOf(n)===-1&&{}.propertyIsEnumerable.call(t,n)&&(l[n]=t[n])}return l}function Ps(t,s){if(t==null)return{};var n={};for(var a in t)if({}.hasOwnProperty.call(t,a)){if(s.indexOf(a)!==-1)continue;n[a]=t[a]}return n}function ie(){return ie=Object.assign?Object.assign.bind():function(t){for(var s=1;s<arguments.length;s++){var n=arguments[s];for(var a in n)({}).hasOwnProperty.call(n,a)&&(t[a]=n[a])}return t},ie.apply(null,arguments)}function Ie(t,s){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(t);s&&(a=a.filter(function(l){return Object.getOwnPropertyDescriptor(t,l).enumerable})),n.push.apply(n,a)}return n}function ce(t){for(var s=1;s<arguments.length;s++){var n=arguments[s]!=null?arguments[s]:{};s%2?Ie(Object(n),!0).forEach(function(a){Bs(t,a,n[a])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Ie(Object(n)).forEach(function(a){Object.defineProperty(t,a,Object.getOwnPropertyDescriptor(n,a))})}return t}function Bs(t,s,n){return(s=Qs(s))in t?Object.defineProperty(t,s,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[s]=n,t}function Qs(t){var s=qs(t,"string");return typeof s=="symbol"?s:s+""}function qs(t,s){if(typeof t!="object"||!t)return t;var n=t[Symbol.toPrimitive];if(n!==void 0){var a=n.call(t,s||"default");if(typeof a!="object")return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return(s==="string"?String:Number)(t)}function et(t){return t&&t.map((s,n)=>r.createElement(s.tag,ce({key:n},s.attr),et(s.child)))}function Us(t){return s=>r.createElement(Hs,ie({attr:ce({},t.attr)},s),et(t.child))}function Hs(t){var s=n=>{var{attr:a,size:l,title:i}=t,u=Ms(t,_s),c=l||n.size||"1em",h;return n.className&&(h=n.className),t.className&&(h=(h?h+" ":"")+t.className),r.createElement("svg",ie({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},n.attr,a,u,{className:h,style:ce(ce({color:t.color||n.color},n.style),t.style),height:c,width:c,xmlns:"http://www.w3.org/2000/svg"}),i&&r.createElement("title",null,i),t.children)};return Oe!==void 0?r.createElement(Oe.Consumer,null,n=>s(n)):s(Ze)}function Vs(t){return Us({tag:"svg",attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M15 22v-4a4.8 4.8 0 0 0-1-3.5c3 0 6-2 6-5.5.08-1.25-.27-2.48-1-3.5.28-1.15.28-2.35 0-3.5 0 0-1 0-3 1.5-2.64-.5-5.36-.5-8 0C6 2 5 2 5 2c-.3 1.15-.3 2.35 0 3.5A5.403 5.403 0 0 0 4 9c0 3.5 3 5.5 6 5.5-.39.49-.68 1.05-.85 1.65-.17.6-.22 1.23-.15 1.85v4"},child:[]},{tag:"path",attr:{d:"M9 18c-4.51 2-5-2-7-2"},child:[]}]})(t)}var $s={damping:.7,stiffness:.05,mass:1.25},Gs=70,Ws=1e3/60,Ks=350,he=!1;globalThis.document?.addEventListener("mousedown",()=>{he=!0});globalThis.document?.addEventListener("mouseup",()=>{he=!1});globalThis.document?.addEventListener("click",()=>{he=!1});var Xs=(t={})=>{const[s,n]=(0,r.useState)(!1),[a,l]=(0,r.useState)(t.initial!==!1),[i,u]=(0,r.useState)(!1),c=(0,r.useRef)(null);c.current=t;const h=(0,r.useCallback)(()=>{if(!he)return!1;const p=window.getSelection();if(!p||!p.rangeCount)return!1;const b=p.getRangeAt(0);return b.commonAncestorContainer.contains(m.current)||m.current?.contains(b.commonAncestorContainer)},[]),f=(0,r.useCallback)(p=>{o.isAtBottom=p,l(p)},[]),g=(0,r.useCallback)(p=>{o.escapedFromLock=p,n(p)},[]),o=(0,r.useMemo)(()=>{let p;return{escapedFromLock:s,isAtBottom:a,resizeDifference:0,accumulated:0,velocity:0,listeners:new Set,get scrollTop(){return m.current?.scrollTop??0},set scrollTop(b){if(m.current){const{scrollBehavior:v}=getComputedStyle(m.current);v!=="auto"&&(m.current.style.scrollBehavior="auto"),m.current.scrollTop=b,o.ignoreScrollToTop=m.current.scrollTop,v!=="auto"&&(m.current.style.scrollBehavior=v)}},get targetScrollTop(){return!m.current||!w.current?0:m.current.scrollHeight-1-m.current.clientHeight},get calculatedTargetScrollTop(){if(!m.current||!w.current)return 0;const{targetScrollTop:b}=this;if(!t.targetScrollTop)return b;if(p?.targetScrollTop===b)return p.calculatedScrollTop;const v=Math.max(Math.min(t.targetScrollTop(b,{scrollElement:m.current,contentElement:w.current}),b),0);return p={targetScrollTop:b,calculatedScrollTop:v},requestAnimationFrame(()=>{p=void 0}),v},get scrollDifference(){return this.calculatedTargetScrollTop-this.scrollTop},get isNearBottom(){return this.scrollDifference<=Gs}}},[]),d=(0,r.useCallback)((p={})=>{typeof p=="string"&&(p={animation:p}),p.preserveScrollPosition||f(!0);const b=Date.now()+(Number(p.wait)||0),v=be(c.current,p.animation),{ignoreEscapes:z=!1}=p;let R,y=o.calculatedTargetScrollTop;p.duration instanceof Promise?p.duration.finally(()=>{R=Date.now()}):R=b+(p.duration??0);const T=async()=>{const O=new Promise(requestAnimationFrame).then(()=>{if(!o.isAtBottom)return o.animation=void 0,!1;const{scrollTop:F}=o,_=performance.now(),M=(_-(o.lastTick??_))/Ws;if(o.animation||(o.animation={behavior:v,promise:O,ignoreEscapes:z}),o.animation.behavior===v&&(o.lastTick=_),h()||b>Date.now())return T();if(F<Math.min(y,o.calculatedTargetScrollTop)){if(o.animation?.behavior===v){if(v==="instant")return o.scrollTop=o.calculatedTargetScrollTop,T();o.velocity=(v.damping*o.velocity+v.stiffness*o.scrollDifference)/v.mass,o.accumulated+=o.velocity*M,o.scrollTop+=o.accumulated,o.scrollTop!==F&&(o.accumulated=0)}return T()}return R>Date.now()?(y=o.calculatedTargetScrollTop,T()):(o.animation=void 0,o.scrollTop<o.calculatedTargetScrollTop?d({animation:be(c.current,c.current.resize),ignoreEscapes:z,duration:Math.max(0,R-Date.now())||void 0}):o.isAtBottom)});return O.then(F=>(requestAnimationFrame(()=>{o.animation||(o.lastTick=void 0,o.velocity=0)}),F))};return p.wait!==!0&&(o.animation=void 0),o.animation?.behavior===v?o.animation.promise:T()},[f,h,o]),j=(0,r.useCallback)(()=>{g(!0),f(!1)},[g,f]),x=(0,r.useCallback)(({target:p})=>{if(p!==m.current)return;const{scrollTop:b,ignoreScrollToTop:v}=o;let{lastScrollTop:z=b}=o;o.lastScrollTop=b,o.ignoreScrollToTop=void 0,v&&v>b&&(z=v),u(o.isNearBottom),setTimeout(()=>{if(o.resizeDifference||b===v)return;if(h()){g(!0),f(!1);return}const R=b>z,y=b<z;if(o.animation?.ignoreEscapes){o.scrollTop=z;return}y&&(g(!0),f(!1)),R&&g(!1),!o.escapedFromLock&&o.isNearBottom&&f(!0)},1)},[g,f,h,o]),N=(0,r.useCallback)(({target:p,deltaY:b})=>{let v=p;for(;!["scroll","auto"].includes(getComputedStyle(v).overflow);){if(!v.parentElement)return;v=v.parentElement}v===m.current&&b<0&&m.current.scrollHeight>m.current.clientHeight&&!o.animation?.ignoreEscapes&&(g(!0),f(!1))},[g,f,o]),m=_e(p=>{m.current?.removeEventListener("scroll",x),m.current?.removeEventListener("wheel",N),p?.addEventListener("scroll",x,{passive:!0}),p?.addEventListener("wheel",N,{passive:!0})},[]),w=_e(p=>{if(o.resizeObserver?.disconnect(),!p)return;let b;o.resizeObserver=new ResizeObserver(([v])=>{const{height:z}=v.contentRect,R=z-(b??z);if(o.resizeDifference=R,o.scrollTop>o.targetScrollTop&&(o.scrollTop=o.targetScrollTop),u(o.isNearBottom),R>=0){const y=be(c.current,b?c.current.resize:c.current.initial);d({animation:y,wait:!0,preserveScrollPosition:!0,duration:y==="instant"?void 0:Ks})}else o.isNearBottom&&(g(!1),f(!0));b=z,requestAnimationFrame(()=>{setTimeout(()=>{o.resizeDifference===R&&(o.resizeDifference=0)},1)})}),o.resizeObserver?.observe(p)},[]);return{contentRef:w,scrollRef:m,scrollToBottom:d,stopScroll:j,isAtBottom:a||i,isNearBottom:i,escapedFromLock:s,state:o}};function _e(t,s){const n=(0,r.useCallback)(a=>(n.current=a,t(a)),s);return n}var ve=new Map;function be(...t){const s={...$s};let n=!1;for(const l of t){if(l==="instant"){n=!0;continue}typeof l=="object"&&(n=!1,s.damping=l.damping??s.damping,s.stiffness=l.stiffness??s.stiffness,s.mass=l.mass??s.mass)}const a=JSON.stringify(s);return ve.has(a)||ve.set(a,Object.freeze(s)),n?"instant":ve.get(a)}var tt=(0,r.createContext)(null),Ys=typeof window<"u"?r.useLayoutEffect:r.useEffect;function ue({instance:t,children:s,resize:n,initial:a,mass:l,damping:i,stiffness:u,targetScrollTop:c,contextRef:h,...f}){const g=(0,r.useRef)(null),o=Xs({mass:l,damping:i,stiffness:u,resize:n,initial:a,targetScrollTop:r.useCallback((v,z)=>(b?.targetScrollTop??c)?.(v,z)??v,[c])}),{scrollRef:d,contentRef:j,scrollToBottom:x,stopScroll:N,isAtBottom:m,escapedFromLock:w,state:p}=t??o,b=(0,r.useMemo)(()=>({scrollToBottom:x,stopScroll:N,scrollRef:d,isAtBottom:m,escapedFromLock:w,contentRef:j,state:p,get targetScrollTop(){return g.current},set targetScrollTop(v){g.current=v}}),[x,m,j,d,N,w,p]);return(0,r.useImperativeHandle)(h,()=>b,[b]),Ys(()=>{d.current&&getComputedStyle(d.current).overflow==="visible"&&(d.current.style.overflow="auto")},[]),r.createElement(tt.Provider,{value:b},r.createElement("div",{...f},typeof s=="function"?s(b):s))}(function(t){function s({children:n,scrollClassName:a,...l}){const i=st();return r.createElement("div",{ref:i.scrollRef,style:{height:"100%",width:"100%",scrollbarGutter:"stable both-edges"},className:a},r.createElement("div",{...l,ref:i.contentRef},typeof n=="function"?n(i):n))}t.Content=s})(ue||(ue={}));function st(){const t=(0,r.useContext)(tt);if(!t)throw new Error("use-stick-to-bottom component context must be used within a StickToBottom component");return t}var e=qt(),Js=({className:t,...s})=>(0,e.jsx)(ue,{className:C("relative flex-1 overflow-y-hidden",t),initial:"smooth",resize:"smooth",role:"log",...s}),Zs=({className:t,...s})=>(0,e.jsx)(ue.Content,{className:C("flex flex-col gap-8 p-4",t),...s}),en=({className:t,...s})=>{const{isAtBottom:n,scrollToBottom:a}=st(),l=(0,r.useCallback)(()=>{a()},[a]);return!n&&(0,e.jsx)(L,{className:C("absolute bottom-4 left-[50%] translate-x-[-50%] rounded-full",t),onClick:l,size:"icon",type:"button",variant:"outline",...s,children:(0,e.jsx)(Bt,{className:"size-4"})})},Me=[{variant:"shine",component:({children:t,className:s,...n})=>(0,e.jsx)("span",{...n,className:C("bg-[linear-gradient(110deg,#bfbfbf,35%,#000,50%,#bfbfbf,75%,#bfbfbf)] dark:bg-[linear-gradient(110deg,#404040,35%,#fff,50%,#404040,75%,#404040)]","bg-size-[200%_100%] bg-clip-text text-transparent","animate-shine",s),children:t})}];function tn({variant:t="shine",className:s,...n}){const a=Me.find(l=>l.variant===t)?.component||Me[0].component;return(0,e.jsx)($t,{className:C("font-medium text-sm"),children:(0,e.jsx)(a,{...n,className:s})})}var Pe=({className:t,from:s,...n})=>(0,e.jsx)("div",{className:C("group flex w-full max-w-[95%] flex-col gap-2",s==="user"?"is-user ml-auto justify-end":"is-assistant",t),...n}),Be=({children:t,className:s,...n})=>(0,e.jsx)("div",{className:C("is-user:dark flex w-fit max-w-full min-w-0 flex-col gap-2 overflow-hidden text-sm","group-[.is-user]:ml-auto group-[.is-user]:rounded-lg group-[.is-user]:bg-secondary group-[.is-user]:px-4 group-[.is-user]:py-3 group-[.is-user]:text-foreground","group-[.is-assistant]:text-foreground",s),...n,children:t}),nt=(0,r.createContext)(null),sn=()=>{const t=(0,r.use)(nt);if(!t)throw new Error("MessageBranch components must be used within MessageBranch");return t},Qe=({defaultBranch:t=0,onBranchChange:s,className:n,...a})=>{const[l,i]=(0,r.useState)(t),[u,c]=(0,r.useState)([]),h=d=>{i(d),s?.(d)},f=()=>{const d=l>0?l-1:u.length-1;h(d)},g=()=>{const d=l<u.length-1?l+1:0;h(d)},o={currentBranch:l,totalBranches:u.length,goToPrevious:f,goToNext:g,branches:u,setBranches:c};return(0,e.jsx)(nt.Provider,{value:o,children:(0,e.jsx)("div",{className:C("grid w-full gap-2 [&>div]:pb-0",n),...a})})},qe=({children:t,...s})=>{const{currentBranch:n,setBranches:a,branches:l}=sn(),i=Array.isArray(t)?t:[t];return(0,r.useEffect)(()=>{l.length!==i.length&&a(i)},[i,l,a]),i.map((u,c)=>(0,e.jsx)("div",{className:C("grid gap-2 overflow-hidden [&>div]:pb-0",c===n?"block":"hidden"),...s,children:u},u.key))},rt=(0,r.memo)(({className:t,...s})=>(0,e.jsx)(Je,{className:C("size-full [&>*:first-child]:mt-0 [&>*:last-child]:mb-0",t),...s}),(t,s)=>t.children===s.children);rt.displayName="MessageResponse";var nn="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict",rn=(t=21)=>{let s="",n=crypto.getRandomValues(new Uint8Array(t|=0));for(;t--;)s+=nn[n[t]&63];return s},an=(0,r.createContext)(null),on=(0,r.createContext)(null),at=()=>(0,r.useContext)(an),ln=()=>(0,r.useContext)(on),ot=(0,r.createContext)(null),cn=()=>{const t=ln(),s=(0,r.use)(ot),n=t??s;if(!n)throw new Error("usePromptInputAttachments must be used within a PromptInput or PromptInputProvider");return n},un=({className:t,accept:s,multiple:n,globalDrop:a,syncHiddenInput:l,maxFiles:i,maxFileSize:u,onError:c,onSubmit:h,children:f,...g})=>{const o=at(),d=!!o,j=(0,r.useRef)(null),x=(0,r.useRef)(null),[N,m]=(0,r.useState)([]),w=d?o.attachments.files:N,p=(0,r.useRef)(w);p.current=w;const b=(0,r.useCallback)(()=>{j.current?.click()},[]),v=(0,r.useCallback)(S=>!s||s.trim()===""?!0:s.split(",").map(k=>k.trim()).filter(Boolean).some(k=>{if(k.endsWith("/*")){const E=k.slice(0,-1);return S.type.startsWith(E)}return S.type===k}),[s]),z=(0,r.useCallback)(S=>{const k=Array.from(S),E=k.filter(D=>v(D));if(k.length&&E.length===0){c?.({code:"accept",message:"No files match the accepted types."});return}const A=D=>u?D.size<=u:!0,I=E.filter(A);if(E.length>0&&I.length===0){c?.({code:"max_file_size",message:"All files exceed the maximum size."});return}m(D=>{const H=typeof i=="number"?Math.max(0,i-D.length):void 0,ht=typeof H=="number"?I.slice(0,H):I;typeof H=="number"&&I.length>H&&c?.({code:"max_files",message:"Too many files. Some were not added."});const ze=[];for(const ge of ht)ze.push({id:rn(),type:"file",url:URL.createObjectURL(ge),mediaType:ge.type,filename:ge.name});return D.concat(ze)})},[v,i,u,c]),R=(0,r.useCallback)(S=>m(k=>{const E=k.find(A=>A.id===S);return E?.url&&URL.revokeObjectURL(E.url),k.filter(A=>A.id!==S)}),[]),y=(0,r.useCallback)(()=>m(S=>{for(const k of S)k.url&&URL.revokeObjectURL(k.url);return[]}),[]),T=d?o.attachments.add:z,O=d?o.attachments.remove:R,F=d?o.attachments.clear:y,_=d?o.attachments.openFileDialog:b;(0,r.useEffect)(()=>{d&&o.__registerFileInput(j,()=>j.current?.click())},[d,o]),(0,r.useEffect)(()=>{l&&j.current&&w.length===0&&(j.current.value="")},[w,l]),(0,r.useEffect)(()=>{const S=x.current;if(!S||a)return;const k=A=>{A.dataTransfer?.types?.includes("Files")&&A.preventDefault()},E=A=>{A.dataTransfer?.types?.includes("Files")&&A.preventDefault(),A.dataTransfer?.files&&A.dataTransfer.files.length>0&&T(A.dataTransfer.files)};return S.addEventListener("dragover",k),S.addEventListener("drop",E),()=>{S.removeEventListener("dragover",k),S.removeEventListener("drop",E)}},[T,a]),(0,r.useEffect)(()=>{if(!a)return;const S=E=>{E.dataTransfer?.types?.includes("Files")&&E.preventDefault()},k=E=>{E.dataTransfer?.types?.includes("Files")&&E.preventDefault(),E.dataTransfer?.files&&E.dataTransfer.files.length>0&&T(E.dataTransfer.files)};return document.addEventListener("dragover",S),document.addEventListener("drop",k),()=>{document.removeEventListener("dragover",S),document.removeEventListener("drop",k)}},[T,a]),(0,r.useEffect)(()=>()=>{if(!d)for(const S of p.current)S.url&&URL.revokeObjectURL(S.url)},[d]);const M=S=>{S.currentTarget.files&&T(S.currentTarget.files),S.currentTarget.value=""},ae=async S=>{try{const k=await(await fetch(S)).blob();return new Promise(E=>{const A=new FileReader;A.onloadend=()=>E(A.result),A.onerror=()=>E(null),A.readAsDataURL(k)})}catch{return null}},xe=(0,r.useMemo)(()=>({files:w.map(S=>({...S,id:S.id})),add:T,remove:O,clear:F,openFileDialog:_,fileInputRef:j}),[w,T,O,F,_]),pe=S=>{S.preventDefault();const k=S.currentTarget,E=d?o.textInput.value:new FormData(k).get("message")||"";d||k.reset(),Promise.all(w.map(async({id:A,...I})=>{if(I.url?.startsWith("blob:")){const D=await ae(I.url);return{...I,url:D??I.url}}return I})).then(A=>{try{const I=h({text:E,files:A},S);I instanceof Promise?I.then(()=>{F(),d&&o.textInput.clear()}).catch(()=>{}):(F(),d&&o.textInput.clear())}catch{}}).catch(()=>{})},oe=(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("input",{accept:s,"aria-label":"Upload files",className:"hidden",multiple:n,onChange:M,ref:j,title:"Upload files",type:"file"}),(0,e.jsx)("form",{className:C("w-full",t),onSubmit:pe,ref:x,...g,children:(0,e.jsx)(Ds,{className:"overflow-hidden",children:f})})]});return d?oe:(0,e.jsx)(ot.Provider,{value:xe,children:oe})},dn=({className:t,...s})=>(0,e.jsx)("div",{className:C("contents",t),...s}),mn=({onChange:t,className:s,placeholder:n="What would you like to know?",...a})=>{const l=at(),i=cn(),[u,c]=(0,r.useState)(!1),h=o=>{if(o.key==="Enter"){if(u||o.nativeEvent.isComposing||o.shiftKey)return;o.preventDefault();const d=o.currentTarget.form;if(d?.querySelector('button[type="submit"]')?.disabled)return;d?.requestSubmit()}if(o.key==="Backspace"&&o.currentTarget.value===""&&i.files.length>0){o.preventDefault();const d=i.files.at(-1);d&&i.remove(d.id)}},f=o=>{const d=o.clipboardData?.items;if(!d)return;const j=[];for(const x of d)if(x.kind==="file"){const N=x.getAsFile();N&&j.push(N)}j.length>0&&(o.preventDefault(),i.add(j))},g=l?{value:l.textInput.value,onChange:o=>{l.textInput.setInput(o.currentTarget.value),t?.(o)}}:{onChange:t};return(0,e.jsx)(xs,{className:C("field-sizing-content max-h-48 min-h-16",s),name:"message",onCompositionEnd:()=>c(!1),onCompositionStart:()=>c(!0),onKeyDown:h,onPaste:f,placeholder:n,...a,...g})},fn=({className:t,...s})=>(0,e.jsx)(os,{align:"block-end",className:C("justify-between justify-end gap-1",t),...s}),hn=({className:t,variant:s="default",size:n="icon-sm",status:a,children:l,...i})=>{let u=(0,e.jsx)(Tt,{className:"size-4"});return a==="submitted"?u=(0,e.jsx)(zt,{className:"size-4 animate-spin"}):a==="streaming"?u=(0,e.jsx)(Rt,{className:"size-4"}):a==="error"&&(u=(0,e.jsx)(Pt,{className:"size-4"})),(0,e.jsx)(Ts,{"aria-label":"Submit",className:C(t),size:n,type:"submit",variant:s,...i,children:l??u})};function xn({...t}){return(0,e.jsx)(Jt,{"data-slot":"collapsible",...t})}function pn({...t}){return(0,e.jsx)(Vt,{"data-slot":"collapsible-trigger",...t})}function gn({...t}){return(0,e.jsx)(Wt,{"data-slot":"collapsible-content",...t})}var vn=({children:t,as:s="p",className:n,duration:a=2,spread:l=2})=>{const i=(0,r.useMemo)(()=>(t?.length??0)*l,[t,l]);return(0,e.jsx)(s,{className:C("relative inline-block bg-size-[250%_100%,auto] bg-clip-text text-transparent","[--bg:linear-gradient(90deg,#0000_calc(50%-var(--spread)),var(--color-background),#0000_calc(50%+var(--spread)))] [background-repeat:no-repeat,padding-box]","animate-shimmer",n),style:{"--spread":`${i}px`,"--duration":`${a}s`,backgroundImage:"var(--bg), linear-gradient(var(--color-muted-foreground), var(--color-muted-foreground))"},children:t})},bn=(0,r.memo)(vn),lt=(0,r.createContext)(null),jn=()=>{const t=(0,r.use)(lt);if(!t)throw new Error("Reasoning components must be used within Reasoning");return t},yn=1e3,Cn=1e3,it=(0,r.memo)(({className:t,isStreaming:s=!1,open:n,defaultOpen:a=!0,onOpenChange:l,duration:i,children:u,...c})=>{const[h,f]=Le({prop:n,defaultProp:a,onChange:l}),[g,o]=Le({prop:i,defaultProp:void 0}),[d,j]=(0,r.useState)(!1),[x,N]=(0,r.useState)(null);(0,r.useEffect)(()=>{s?x===null&&N(Date.now()):x!==null&&(o(Math.ceil((Date.now()-x)/Cn)),N(null))},[s,x,o]),(0,r.useEffect)(()=>{if(a&&!s&&h&&!d){const w=setTimeout(()=>{f(!1),j(!0)},yn);return()=>clearTimeout(w)}},[s,h,a,f,d]);const m=w=>{f(w)};return(0,e.jsx)(lt.Provider,{value:{isStreaming:s,isOpen:h,setIsOpen:f,duration:g},children:(0,e.jsx)(xn,{className:C("not-prose mb-4",t),onOpenChange:m,open:h,...c,children:u})})}),Nn=(t,s)=>t||s===0?(0,e.jsx)(bn,{duration:1,children:"Thinking..."}):s===void 0?(0,e.jsx)("p",{children:"Thought for a few seconds"}):(0,e.jsxs)("p",{children:["Thought for ",s," seconds"]}),ct=(0,r.memo)(({className:t,children:s,getThinkingMessage:n=Nn,...a})=>{const{isStreaming:l,isOpen:i,duration:u}=jn();return(0,e.jsx)(pn,{className:C("flex w-full items-center gap-2 text-muted-foreground text-sm transition-colors hover:text-foreground",t),...a,children:s??(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(Et,{className:"size-4"}),n(l,u),(0,e.jsx)(We,{className:C("size-4 transition-transform",i?"rotate-180":"rotate-0")})]})})}),ut=(0,r.memo)(({className:t,children:s,...n})=>(0,e.jsx)(gn,{className:C("mt-4 text-sm","data-[state=closed]:fade-out-0 data-[state=closed]:slide-out-to-top-2 data-[state=open]:slide-in-from-top-2 text-muted-foreground outline-none data-[state=closed]:animate-out data-[state=open]:animate-in",t),...n,children:(0,e.jsx)(Je,{children:s})}));it.displayName="Reasoning";ct.displayName="ReasoningTrigger";ut.displayName="ReasoningContent";var wn=({className:t,children:s,...n})=>(0,e.jsxs)(Xe,{className:"w-full overflow-x-auto whitespace-nowrap",...n,children:[(0,e.jsx)("div",{className:C("flex w-max flex-nowrap items-center gap-2",t),children:s}),(0,e.jsx)(is,{className:"hidden",orientation:"horizontal"})]}),Sn=({suggestion:t,onClick:s,className:n,variant:a="outline",size:l="sm",children:i,...u})=>{const c=()=>{s?.(t)};return(0,e.jsx)(L,{className:C("cursor-pointer rounded-full px-4",n),onClick:c,size:l,type:"button",variant:a,...u,children:i||t})},Ee=()=>{const{data:t,isLoading:s,error:n,refetch:a}=jt({queryKey:gs.rateLimit(),queryFn:async()=>{try{return(await ts()).data}catch{return{limit:0,used:0,remaining:0}}}});return{rateLimit:t,isLoadingRateLimit:s,errorRateLimit:n,refetchRateLimit:a}},Tn=({db:t,onRateLimitRefetch:s,onControllerReady:n})=>{const[a,l]=(0,r.useState)(""),{rateLimit:i}=Ee(),{remaining:u}=i??{remaining:0,limit:0},{messages:c,sendMessage:h,isLoading:f,clear:g,stop:o}=vt({connection:gt(`${es()}/chat`),body:{db:t},onError:m=>console.error("Error:",m.message),onFinish:()=>{s()}});(0,r.useEffect)(()=>{n({clear:()=>{g(),l("")},isLoading:f})},[g,f,n]);const d=m=>{const w=!!m.text,p=!!m.files?.length;!(w||p)||f||(h(m.text),l(""))},j=m=>{h(m),l("")},x=()=>{o(),l("")},N=f?"streaming":"ready";return(0,e.jsxs)("div",{className:"relative flex size-full flex-col divide-y overflow-hidden",children:[(0,e.jsxs)(Js,{children:[(0,e.jsx)(Zs,{children:c.length===0?(0,e.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground",children:(0,e.jsxs)("div",{className:"text-center space-y-2",children:[(0,e.jsx)("p",{className:"text-lg font-medium",children:"Start a new conversation"}),(0,e.jsx)("p",{className:"text-sm",children:"Ask me anything to get started"})]})}):(0,e.jsxs)(e.Fragment,{children:[c.map(m=>{const w=m.parts.filter(v=>v.type==="thinking"),p=m.parts.reduce((v,z)=>z.type==="text"?v+(z.content??""):v,""),b=w.length>0;return(0,e.jsx)(Qe,{defaultBranch:0,children:(0,e.jsx)(qe,{children:(0,e.jsx)(Pe,{from:m.role==="user"?"user":"assistant",children:(0,e.jsxs)("div",{children:[b&&m.role==="assistant"&&(0,e.jsxs)(it,{duration:0,children:[(0,e.jsx)(ct,{}),(0,e.jsx)(ut,{children:w.map(v=>v.content).join(`
2
2
  `)})]}),(0,e.jsx)(Be,{children:(0,e.jsx)(rt,{children:p})})]})})})},m.id)}),f&&(0,e.jsx)(Qe,{defaultBranch:0,children:(0,e.jsx)(qe,{children:(0,e.jsx)(Pe,{from:"assistant",children:(0,e.jsx)(Be,{children:(0,e.jsx)(tn,{children:"Thinking..."})})})})})]})}),(0,e.jsx)(en,{})]}),(0,e.jsxs)("div",{className:"grid shrink-0 gap-4 pt-3",children:[c.length===0&&u>0&&(0,e.jsx)(wn,{className:"px-4",children:ss.map(m=>(0,e.jsx)(Sn,{onClick:()=>j(m),suggestion:m,size:"lg",children:m},m))}),(0,e.jsx)("div",{className:"w-full px-4 pb-4",children:(0,e.jsxs)(un,{globalDrop:!0,multiple:!0,onSubmit:d,children:[(0,e.jsx)(dn,{children:(0,e.jsx)(mn,{onChange:m=>l(m.target.value),value:a,placeholder:"Type a message..."})}),(0,e.jsx)(fn,{children:(0,e.jsx)(hn,{className:"h-8!",status:N,onClick:f?x:void 0,disabled:i&&i.remaining===0})})]})})]})]})},Dn=()=>{const{rateLimit:t,refetchRateLimit:s}=Ee(),{isOverlayOpen:n,closeOverlay:a}=ke(),{selectedDatabase:l}=U(),[i,u]=(0,r.useState)(null),c=(0,r.useRef)(h=>u(h));return(0,e.jsx)(zs,{title:"AI Assistant",cta:(0,e.jsxs)("div",{className:"flex items-center gap-2",children:[t&&(0,e.jsxs)(W,{children:[(0,e.jsx)(G,{asChild:!0,children:(0,e.jsxs)("span",{className:"text-xs px-2 py-1 cursor-default text-muted-foreground",children:[t.remaining,"/",t.limit]})}),(0,e.jsx)(K,{side:"bottom",children:(0,e.jsxs)("p",{children:[t.remaining," messages remaining"]})})]}),l&&i&&(0,e.jsxs)(L,{type:"button",variant:"outline",size:"lg",onClick:i.clear,disabled:i.isLoading,children:[(0,e.jsx)(de,{className:"size-4 mr-1"}),"New Chat"]})]}),closeButton:!1,open:n("chat.assistant"),size:"max-w-2xl!",contentClassName:"p-0 flex flex-col h-[calc(100vh-4rem)] flex-1",onOpenChange:h=>{h||a("chat.assistant")},children:l?(0,e.jsx)(Tn,{db:l,onRateLimitRefetch:s,onControllerReady:c.current},l):(0,e.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground p-8",children:(0,e.jsxs)("div",{className:"text-center space-y-2",children:[(0,e.jsx)("p",{className:"text-lg font-medium",children:"No database selected"}),(0,e.jsx)("p",{className:"text-sm",children:"Select a database from the sidebar to start chatting."})]})})})},kn=()=>{const{openOverlay:t}=ke(),{dbType:s}=U(),{rateLimit:n,isLoadingRateLimit:a}=Ee(),{remaining:l=0,limit:i=0}=n??{remaining:0,limit:0},c=(h=>h===0?"bg-red-500":h<=5?"bg-yellow-500":"bg-emerald-500")(l);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)(W,{children:[(0,e.jsx)(G,{asChild:!0,children:(0,e.jsxs)(L,{variant:"ghost",className:"border-r-0 border-y-0 border-l border-zinc-800 rounded-none h-full w-12 relative",onClick:()=>{t("chat.assistant"),s&&Zt.capture("chat_opened",{db_type:s})},children:[(0,e.jsx)(Ot,{className:"size-5"}),(0,e.jsx)("span",{className:C("absolute top-2 right-2 h-2 w-2 rounded-full ring-2 ring-background",c)})]})}),(0,e.jsx)(K,{side:"bottom",className:"text-xs",children:!a&&(l>0?(0,e.jsxs)("p",{children:[l,"/",i," messages remaining"]}):(0,e.jsx)("p",{children:"AI Assistant"}))})]}),(0,e.jsx)(Dn,{})]})},En=()=>{const{pathname:t}=ye(),s=t.split("/")[1]||"table";return(0,e.jsx)("div",{className:"flex h-full items-center",children:rs.map(n=>(0,e.jsx)($e,{to:`/${n}`,className:"h-full flex items-center",children:(0,e.jsx)(L,{variant:"ghost",className:C("flex-1 px-4 border-l-0 border-y-0 border-r border-zinc-800 h-full rounded-none",s===n?"bg-zinc-900 text-white":"text-zinc-400"),children:n})},n))})},zn=()=>{const{sidebar:{isOpen:t,isPinned:s},setSidebarOpen:n,setSidebarPinned:a}=me(),l=()=>{n(!t),a(!s)};return(0,e.jsx)(L,{variant:"ghost",onClick:l,className:"h-full aspect-square border-l-0 border-y-0 border-r border-zinc-800 rounded-none",children:(0,e.jsx)(Qt,{className:"size-5"})})},Rn=()=>(0,e.jsxs)("div",{className:"border-b border-zinc-800 w-full flex items-center justify-between bg-zinc-950 h-12",children:[(0,e.jsxs)("div",{className:"flex items-center h-full",children:[(0,e.jsx)(zn,{}),(0,e.jsx)(En,{})]}),(0,e.jsxs)("div",{className:"flex items-center h-full",children:[(0,e.jsx)(kn,{}),(0,e.jsxs)(W,{children:[(0,e.jsx)(G,{asChild:!0,children:(0,e.jsx)(L,{variant:"ghost",className:"border-r-0 border-y-0 border-l border-zinc-800 rounded-none h-full w-12",asChild:!0,children:(0,e.jsx)("a",{href:Ae.SITE_GITHUB_NEW_ISSUE_LINK,target:"_blank",rel:"noopener noreferrer","aria-label":"Create a new GitHub issue",children:(0,e.jsx)(Nt,{className:"size-5"})})})}),(0,e.jsx)(K,{children:(0,e.jsx)("p",{children:"Report a bug"})})]}),(0,e.jsxs)(W,{children:[(0,e.jsx)(G,{asChild:!0,children:(0,e.jsx)(L,{variant:"ghost",className:"border-r-0 border-y-0 border-l border-zinc-800 rounded-none h-full w-12",asChild:!0,children:(0,e.jsx)("a",{href:Ae.SITE_GITHUB_LINK,target:"_blank",rel:"noopener noreferrer","aria-label":"View the db-studio GitHub repository",children:(0,e.jsx)(Vs,{className:"size-5"})})})}),(0,e.jsx)(K,{children:(0,e.jsx)("p",{children:"View on GitHub"})})]})]})]});function dt({...t}){return(0,e.jsx)(Kt,{"data-slot":"context-menu",...t})}function mt({className:t,...s}){return(0,e.jsx)(Ht,{"data-slot":"context-menu-trigger",className:C("select-none",t),...s})}function ft({className:t,...s}){return(0,e.jsx)(Ut,{children:(0,e.jsx)(Xt,{"data-slot":"context-menu-content",className:C("data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 ring-foreground/10 bg-popover text-popover-foreground min-w-32 rounded-lg p-1 shadow-md ring-1 duration-100 z-50 max-h-(--radix-context-menu-content-available-height) origin-(--radix-context-menu-content-transform-origin) overflow-x-hidden overflow-y-auto",t),...s})})}function Q({className:t,inset:s,variant:n="default",...a}){return(0,e.jsx)(Gt,{"data-slot":"context-menu-item","data-inset":s,"data-variant":n,className:C("focus:bg-accent focus:text-accent-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:text-destructive not-data-[variant=destructive]:focus:**:text-accent-foreground min-h-7 gap-2 rounded-md px-2 py-1 text-xs/relaxed [&_svg:not([class*='size-'])]:size-3.5 group/context-menu-item relative flex cursor-default items-center outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0",t),...a})}function Ue({className:t,...s}){return(0,e.jsx)(Yt,{"data-slot":"context-menu-separator",className:C("bg-border/50 -mx-1 my-1 h-px",t),...s})}var je=({folderId:t,isExpanded:s,onToggle:n,count:a,name:l,showContextMenu:i=!1})=>{const u=re(),{deleteFolder:c,getQueriesByFolder:h,addQuery:f,updateFolder:g}=fe(),[o,d]=(0,r.useState)(!1),[j,x]=(0,r.useState)(""),[N,m]=(0,r.useState)(!1),w=(0,r.useCallback)(()=>{if(t){if(h(t).length>0){m(!0);return}c(t)}},[c,t,h]),p=(0,r.useCallback)(()=>{t&&(c(t),m(!1))},[c,t]),b=(0,r.useCallback)(()=>{const R=f(void 0,t);u({to:"/runner/$queryId",params:{queryId:R}})},[f,t,u]),v=(0,r.useCallback)(()=>{x(l),d(!0)},[l]),z=(0,r.useCallback)(()=>{t&&j.trim()&&(g(t,{name:j.trim()}),d(!1),x(""))},[t,j,g]);return(0,e.jsxs)(e.Fragment,{children:[i?(0,e.jsxs)(dt,{children:[(0,e.jsx)(mt,{asChild:!0,children:(0,e.jsxs)("button",{type:"button",onClick:n,className:C("w-full flex gap-2 px-4 py-2 text-sm transition-colors text-left","hover:bg-zinc-800/50 hover:text-zinc-100 focus:outline-none focus:bg-zinc-800/50","text-zinc-400 items-center"),children:[(0,e.jsx)(Re,{className:C("size-4 transition-transform duration-200",s?"rotate-90":"")}),(0,e.jsx)("span",{className:"flex-1",children:l}),(0,e.jsx)(se,{children:a})]})}),(0,e.jsxs)(ft,{children:[(0,e.jsxs)(Q,{onClick:b,children:[(0,e.jsx)(de,{className:"size-4"}),"Add a new query"]}),(0,e.jsxs)(Q,{onClick:v,children:[(0,e.jsx)(Ce,{className:"size-4"}),"Rename folder"]}),(0,e.jsxs)(Q,{onClick:w,children:[(0,e.jsx)(Ne,{className:"size-4"}),"Delete folder"]})]})]}):(0,e.jsxs)("button",{type:"button",onClick:n,className:C("w-full flex gap-2 px-4 py-2 text-sm transition-colors text-left","hover:bg-zinc-800/50 hover:text-zinc-100 focus:outline-none focus:bg-zinc-800/50","text-zinc-400 items-center"),children:[(0,e.jsx)(Re,{className:C("size-4 transition-transform duration-200",s?"rotate-90":"")}),(0,e.jsx)("span",{className:"flex-1",children:l}),(0,e.jsx)(se,{children:a})]}),(0,e.jsx)(Z,{open:o,onOpenChange:d,children:(0,e.jsxs)(ee,{children:[(0,e.jsxs)(J,{children:[(0,e.jsx)(te,{children:"Rename Folder"}),(0,e.jsx)(X,{children:"Enter a new name for this folder."})]}),(0,e.jsx)(ne,{value:j,onChange:R=>x(R.target.value),placeholder:"Folder name",onKeyDown:R=>{R.key==="Enter"&&z()},autoFocus:!0}),(0,e.jsxs)(Y,{children:[(0,e.jsx)(L,{variant:"outline",onClick:()=>{d(!1),x("")},children:"Cancel"}),(0,e.jsx)(L,{onClick:z,disabled:!j.trim(),children:"Rename"})]})]})}),(0,e.jsx)(Os,{open:N,onOpenChange:m,children:(0,e.jsxs)(Is,{children:[(0,e.jsxs)(Rs,{children:[(0,e.jsx)(Es,{children:"Delete Folder"}),(0,e.jsxs)(Cs,{children:["This folder contains ",a," ",a===1?"query":"queries",". Deleting this folder will also delete all queries inside it. This action cannot be undone."]})]}),(0,e.jsxs)(Ns,{children:[(0,e.jsx)(ks,{children:"Cancel"}),(0,e.jsx)(ys,{onClick:p,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:"Delete Folder"})]})]})})]})},le=({id:t,tableName:s,isNested:n=!1,showContextMenu:a=!0})=>{const l=re(),{deleteQuery:i,addQuery:u,getQuery:c,toggleFavorite:h,updateQuery:f,moveQuery:g,folders:o,addFolder:d}=fe(),{queryId:j}=Ve({strict:!1}),x=j===t,N=c(t),m=N?.isFavorite??!1,[w,p]=(0,r.useState)(!1),[b,v]=(0,r.useState)(""),[z,R]=(0,r.useState)(!1),[y,T]=(0,r.useState)(void 0),[O,F]=(0,r.useState)(!1),[_,M]=(0,r.useState)(""),ae=(0,r.useCallback)(()=>{l({to:"/runner/$queryId",params:{queryId:t}})},[l,t]),xe=(0,r.useCallback)(()=>{i(t),j===t&&l({to:"/runner"}),P.success("Query deleted successfully")},[i,t,l,j]),pe=(0,r.useCallback)(()=>{const D=c(t),H=u(`${D?.name} (Copy)`);l({to:"/runner/$queryId",params:{queryId:H}}),P.success("Query duplicated successfully")},[u,c,l,t]),oe=(0,r.useCallback)(()=>{h(t),P.success("Query favorited successfully")},[h,t]),S=(0,r.useCallback)(()=>{v(N?.name??""),p(!0)},[N?.name]),k=(0,r.useCallback)(()=>{b.trim()&&(f(t,{name:b.trim()}),p(!1),v(""),P.success("Query renamed successfully"))},[t,b,f]),E=(0,r.useCallback)(()=>{T(N?.folderId),F(!1),M(""),R(!0)},[N?.folderId]),A=(0,r.useCallback)(D=>{D==="__create_new__"?(F(!0),T(void 0)):(F(!1),T(D==="__none__"?void 0:D))},[]),I=(0,r.useCallback)(()=>{if(O&&_.trim()){const D=Math.random().toString(36).substring(2,15);d({id:D,name:_.trim(),isExpanded:!0,isFavorite:!1}),g(t,D),P.success("Query moved to new folder successfully")}else O||(g(t,y),P.success("Query moved to selected folder successfully"));R(!1),F(!1),M(""),T(void 0)},[O,_,y,t,d,g]);return(0,e.jsxs)("li",{className:"relative",children:[a?(0,e.jsxs)(dt,{children:[(0,e.jsx)(mt,{asChild:!0,children:(0,e.jsxs)("button",{type:"button",onClick:ae,className:C("w-full flex gap-2 py-2 text-sm transition-colors text-left","hover:text-zinc-100 focus:outline-none focus:bg-accent/10 focus:text-zinc-100 justify-start items-center",x?"text-zinc-100 bg-accent/10":"text-zinc-400",n?"px-4 pl-12":"px-4"),children:[x&&(0,e.jsx)("span",{className:"absolute left-0 top-0 bottom-0 w-1 bg-accent"}),(0,e.jsx)("span",{className:"flex-1",children:s})]})}),(0,e.jsxs)(ft,{children:[(0,e.jsxs)(Q,{onClick:S,children:[(0,e.jsx)(Ce,{className:"size-4"}),"Rename query"]}),(0,e.jsxs)(Q,{onClick:pe,children:[(0,e.jsx)(kt,{className:"size-4"}),"Duplicate query"]}),(0,e.jsxs)(Q,{onClick:oe,children:[(0,e.jsx)(Mt,{className:m?"size-4 fill-current":"size-4"}),m?"Remove from favorites":"Add to favorites"]}),(0,e.jsx)(Ue,{}),(0,e.jsxs)(Q,{onClick:E,children:[(0,e.jsx)(Ct,{className:"size-4"}),"Move to folder"]}),(0,e.jsx)(Ue,{}),(0,e.jsxs)(Q,{onClick:xe,children:[(0,e.jsx)(Ne,{className:"size-4"}),"Delete query"]})]})]}):(0,e.jsxs)("button",{type:"button",onClick:ae,className:C("w-full flex gap-2 py-2 text-sm transition-colors text-left","hover:text-zinc-100 focus:outline-none focus:bg-accent/10 focus:text-zinc-100 justify-start items-center",x?"text-zinc-100 bg-accent/10":"text-zinc-400",n?"px-4 pl-12":"px-4"),children:[x&&(0,e.jsx)("span",{className:"absolute left-0 top-0 bottom-0 w-1 bg-accent"}),(0,e.jsx)("span",{className:"flex-1",children:s})]}),(0,e.jsx)(Z,{open:w,onOpenChange:p,children:(0,e.jsxs)(ee,{children:[(0,e.jsxs)(J,{children:[(0,e.jsx)(te,{children:"Rename Query"}),(0,e.jsx)(X,{children:"Enter a new name for this query."})]}),(0,e.jsx)(ne,{value:b,onChange:D=>v(D.target.value),placeholder:"Query name",onKeyDown:D=>{D.key==="Enter"&&k()},autoFocus:!0}),(0,e.jsxs)(Y,{children:[(0,e.jsx)(L,{variant:"outline",onClick:()=>{p(!1),v("")},children:"Cancel"}),(0,e.jsx)(L,{onClick:k,disabled:!b.trim(),children:"Rename"})]})]})}),(0,e.jsx)(Z,{open:z,onOpenChange:D=>{R(D),D||(F(!1),M(""),T(void 0))},children:(0,e.jsxs)(ee,{children:[(0,e.jsxs)(J,{children:[(0,e.jsx)(te,{children:"Move to Folder"}),(0,e.jsx)(X,{children:"Select a folder to move this query to."})]}),(0,e.jsx)("div",{className:"space-y-4",children:O?(0,e.jsx)(ne,{value:_,onChange:D=>M(D.target.value),placeholder:"Folder name",onKeyDown:D=>{D.key==="Enter"&&_.trim()&&I(),D.key==="Escape"&&(F(!1),M(""))},autoFocus:!0}):(0,e.jsxs)(Se,{value:y??"__none__",onValueChange:A,children:[(0,e.jsx)(we,{className:"w-full",children:(0,e.jsx)(De,{placeholder:"Select a folder"})}),(0,e.jsxs)(Te,{children:[(0,e.jsx)(V,{value:"__none__",children:"No folder"}),o.map(D=>(0,e.jsx)(V,{value:D.id,children:D.name},D.id)),(0,e.jsx)(V,{value:"__create_new__",children:(0,e.jsxs)("div",{className:"flex items-center gap-2",children:[(0,e.jsx)(Ge,{className:"size-4"}),"Create a new folder"]})})]})]})}),(0,e.jsxs)(Y,{children:[(0,e.jsx)(L,{variant:"outline",onClick:()=>{R(!1),F(!1),M(""),T(void 0)},children:"Cancel"}),(0,e.jsx)(L,{onClick:I,disabled:O&&!_.trim(),children:O?"Create & Move":"Move"})]})]})})]})},Ln=()=>{const[t]=$(B.SIDEBAR_SEARCH,{defaultValue:""}),{folders:s,queries:n,getFavoriteQueries:a,getQueriesByFolder:l,toggleFolder:i}=fe(),[u,c]=(0,r.useState)(!0),[h,f]=(0,r.useState)(!0),g=n.filter(x=>!x.isFavorite).length,o=a(),d=o.length,j=n.filter(x=>!x.folderId&&!x.isFavorite);if(t){const x=n.filter(N=>N.name.toLowerCase().includes(t.toLowerCase()));return x.length===0?(0,e.jsx)("div",{className:"flex-1 overflow-y-auto p-4",children:"No queries found matching"}):(0,e.jsx)("div",{className:"flex-1 overflow-y-auto",children:x.map(N=>(0,e.jsx)(le,{id:N.id,tableName:N.name},N.id))})}return(0,e.jsxs)("div",{className:"flex-1 overflow-y-auto",children:[(0,e.jsx)(je,{name:"Favorites",isExpanded:u,onToggle:()=>c(!u),count:d}),u&&o.map(x=>(0,e.jsx)(le,{id:x.id,tableName:x.name},x.id)),(0,e.jsx)(vs,{className:"bg-zinc-800"}),(0,e.jsx)(je,{name:"Queries",isExpanded:h,onToggle:()=>f(!h),count:g}),h&&(0,e.jsxs)(e.Fragment,{children:[s.map(x=>{const N=l(x.id),m=N.length;return(0,e.jsxs)("div",{children:[(0,e.jsx)(je,{folderId:x.id,name:x.name,isExpanded:x.isExpanded,onToggle:()=>i(x.id),count:m,showContextMenu:!0}),x.isExpanded&&N.map(w=>(0,e.jsx)(le,{id:w.id,tableName:w.name,isNested:!0,showContextMenu:!0},w.id))]},x.id)}),j.map(x=>(0,e.jsx)(le,{id:x.id,tableName:x.name,showContextMenu:!0},x.id))]})]})},An=()=>{const{addQuery:t,addFolder:s}=fe(),n=re(),a=(0,r.useRef)(null),[l,i]=$(B.SIDEBAR_SEARCH,{defaultValue:""}),u=f=>{i(f.target.value)},c=()=>{const f=t();n({to:"/runner/$queryId",params:{queryId:f}})},h=()=>{const f=Math.random().toString(36).substring(2,15);s({id:f,name:"New Folder",isExpanded:!0,isFavorite:!1})};return(0,e.jsxs)("div",{className:"p-3 space-y-2 border-b border-zinc-800",children:[(0,e.jsxs)("div",{className:"flex gap-2",children:[(0,e.jsxs)(L,{className:"flex-1 justify-start h-8",onClick:c,children:[(0,e.jsx)(de,{className:"size-4"}),"Add Query"]}),(0,e.jsxs)(L,{className:"flex-1 justify-start h-8",onClick:h,children:[(0,e.jsx)(Ge,{className:"size-4"}),"Add Folder"]})]}),(0,e.jsxs)("div",{className:"relative",children:[(0,e.jsx)(Ke,{className:"absolute left-2 top-1/2 -translate-y-1/2 size-4 text-muted-foreground"}),(0,e.jsx)(ne,{ref:a,placeholder:"Search queries",value:l??"",onChange:u,className:"rounded-sm h-8 pl-8 pr-8"}),(0,e.jsx)(se,{className:"absolute right-2 top-1/2 -translate-y-1/2 text-xs",children:"/"})]})]})},Fn=()=>(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(An,{}),(0,e.jsx)(Ln,{})]}),On=()=>{const{selectedDatabase:t}=U(),{mutateAsync:s,isPending:n}=bt({mutationFn:async l=>{const i=(await ns(l,t)).data.data.schema;return await navigator.clipboard.writeText(i),i}});return{copyTableSchema:async l=>P.promise(s(l),{loading:"Copying table schema...",success:"Table schema copied to clipboard",error:i=>i.message||"Failed to copy table schema"}),isCopyingSchema:n}},In=({tableName:t})=>{const s=re(),{copyTableSchema:n,isCopyingSchema:a}=On(),{exportFile:l,isExportingFile:i}=us(),{deleteTable:u,forceDeleteTable:c,isDeletingTable:h}=cs(),[f,g]=(0,r.useState)(!1),[o,d]=(0,r.useState)(!1),[j,x]=(0,r.useState)([]),N=()=>{navigator.clipboard.writeText(t),P.success("Table name copied to clipboard")},m=async()=>{const b=await u(t);b.fkViolation?(x(b.relatedRecords),g(!1),d(!0)):(g(!1),s({to:"/"}))},w=async()=>{await c(t),d(!1),s({to:"/"})},p=()=>{d(!1),x([])};return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsxs)(ls,{children:[(0,e.jsx)(fs,{children:(0,e.jsx)(L,{variant:"ghost",size:"icon-sm",children:(0,e.jsx)(yt,{})})}),(0,e.jsx)(ps,{className:"w-56",align:"start",children:(0,e.jsxs)(ms,{children:[(0,e.jsxs)(q,{onClick:N,children:[(0,e.jsx)(wt,{className:"size-4"}),"Copy name"]}),(0,e.jsxs)(q,{onClick:()=>n(t),disabled:a,children:[(0,e.jsx)(Dt,{className:"size-4"}),"Copy table schema"]}),(0,e.jsx)(Fe,{}),(0,e.jsxs)(q,{onClick:()=>s({to:"/schema/$table",params:{table:t}}),children:[(0,e.jsx)(Ce,{className:"size-4"}),"Edit table"]}),(0,e.jsxs)(ds,{children:[(0,e.jsxs)(Ls,{children:[(0,e.jsx)(Ft,{className:"size-4"}),"Export data"]}),(0,e.jsxs)(hs,{children:[(0,e.jsx)(q,{onClick:()=>l({tableName:t,format:"csv"}),disabled:i,children:"Export as CSV"}),(0,e.jsx)(q,{onClick:()=>l({tableName:t,format:"json"}),disabled:i,children:"Export as JSON"}),(0,e.jsx)(q,{onClick:()=>l({tableName:t,format:"xlsx"}),disabled:i,children:"Export as Excel"})]})]}),(0,e.jsx)(Fe,{}),(0,e.jsxs)(q,{variant:"destructive",onClick:()=>g(!0),children:[(0,e.jsx)(Ne,{className:"size-4"}),"Delete table"]})]})})]}),(0,e.jsx)(_n,{isOpen:f,onOpenChange:g,tableName:t,onDelete:m,isDeleting:h}),(0,e.jsx)(Mn,{isOpen:o,onOpenChange:d,tableName:t,relatedRecords:j,onForceDelete:w,onCancel:p,isDeleting:h})]})},_n=({isOpen:t,onOpenChange:s,tableName:n,onDelete:a,isDeleting:l})=>(0,e.jsx)(Z,{open:t,onOpenChange:s,children:(0,e.jsxs)(ee,{className:"max-w-md",children:[(0,e.jsxs)(J,{children:[(0,e.jsx)(te,{children:"Delete Table"}),(0,e.jsxs)(X,{children:["Are you sure you want to delete the table"," ",(0,e.jsxs)("span",{className:"font-semibold text-foreground",children:['"',n,'"']}),"? This action cannot be undone and all data will be permanently lost."]})]}),(0,e.jsxs)(Y,{className:"gap-2",children:[(0,e.jsx)(L,{variant:"outline",onClick:()=>s(!1),disabled:l,children:"Cancel"}),(0,e.jsx)(L,{variant:"destructive",onClick:a,disabled:l,children:l?"Deleting...":"Delete Table"})]})]})}),Mn=({isOpen:t,onOpenChange:s,tableName:n,relatedRecords:a,onForceDelete:l,onCancel:i,isDeleting:u})=>(0,e.jsx)(Z,{open:t,onOpenChange:s,children:(0,e.jsxs)(ee,{className:"max-w-xl! max-h-[calc(100vh-1rem)]!",children:[(0,e.jsxs)(J,{children:[(0,e.jsx)(te,{children:"Cannot Delete - Foreign Key Constraint"}),(0,e.jsxs)(X,{children:["The table ",(0,e.jsxs)("span",{className:"font-semibold text-foreground",children:['"',n,'"']})," ","cannot be deleted because it is referenced by records in other tables. You can either cancel the operation or force delete, which will also delete all related records."]})]}),(0,e.jsx)("div",{className:"space-y-4 max-h-64 overflow-y-auto",children:a.map((c,h)=>(0,e.jsxs)("div",{className:"border border-zinc-700 rounded-md p-3",children:[(0,e.jsxs)("div",{className:"font-medium text-sm mb-2",children:["Table: ",(0,e.jsx)("span",{className:"text-primary",children:c.tableName}),(0,e.jsxs)("span",{className:"text-muted-foreground ml-2",children:["(",c.records.length," record",c.records.length!==1?"s":"",")"]})]}),(0,e.jsxs)("div",{className:"text-xs text-muted-foreground mb-2",children:["References column: ",c.columnName]}),(0,e.jsx)("div",{className:"bg-zinc-900 rounded p-2 text-xs overflow-x-auto",children:(0,e.jsxs)("pre",{className:"whitespace-pre-wrap",children:[JSON.stringify(c.records.slice(0,5),null,2),c.records.length>5&&(0,e.jsxs)("div",{className:"text-muted-foreground mt-2",children:["... and ",c.records.length-5," more"]})]})})]},`${c.tableName}-${c.columnName}-${h}`))}),(0,e.jsxs)(Y,{className:"gap-2",children:[(0,e.jsx)(L,{variant:"outline",onClick:i,disabled:u,children:"Cancel"}),(0,e.jsx)(L,{variant:"destructive",onClick:l,disabled:u,children:u?"Deleting...":"Force Delete All"})]})]})}),Pn=({tableName:t,rowCount:s,schemaName:n})=>{const a=Ve({strict:!1}),{pathname:l}=ye(),i=a.table===t;return(0,e.jsx)("li",{className:"relative",children:(0,e.jsxs)($e,{to:l.startsWith("/schema")?"/schema/$table":"/table/$table",params:{table:t},className:C("w-full flex gap-0.5 px-4 py-1.5 text-sm transition-colors text-left","hover:text-zinc-100 focus:outline-none focus:bg-accent/10 focus:text-zinc-100 justify-start items-center",i?"text-white bg-zinc-800/50":"text-zinc-400"),children:[i&&(0,e.jsx)("span",{className:"absolute left-0 top-0 bottom-0 w-1 bg-accent"}),(0,e.jsxs)("span",{className:"flex-1 truncate",children:[n&&n!=="public"?`${n}.`:"",t]}),(0,e.jsxs)("div",{className:"flex items-center gap-1 h-5",children:[i&&(0,e.jsx)(In,{tableName:t}),(0,e.jsx)(se,{children:s})]})]})})},Bn=()=>{const[t]=$(B.SIDEBAR_SEARCH,{defaultValue:""}),[s,n]=$(B.ACTIVE_SCHEMA,{defaultValue:"all"}),{dbType:a}=U(),{tablesList:l=[],isLoadingTablesList:i,errorTablesList:u}=Ye(),c=(0,r.useMemo)(()=>Array.from(new Set(l.reduce((g,o)=>(o.schemaName&&g.push(o.schemaName),g),[]))).sort(),[l]),h=a==="pg"&&c.length>1,f=l?.filter(g=>{const o=s==="all"||g.schemaName===s,d=g.tableName.toLowerCase().includes(t.toLowerCase());return o&&d});return(0,r.useEffect)(()=>{!h||s==="all"||c.includes(s)||n("all")},[c,s,n,h]),i?(0,e.jsx)("div",{className:"flex-1 h-full overflow-y-auto pb-3 flex items-center justify-center",children:(0,e.jsx)(as,{size:"size-6"})}):u?(0,e.jsxs)("div",{className:"flex-1 overflow-y-auto pb-3 h-full flex items-center justify-center",children:["Error: ",u.message]}):(0,e.jsx)("div",{className:"flex-1 overflow-y-auto pb-3",children:f&&f.length>0?(0,e.jsx)("ul",{children:f?.map(g=>(0,e.jsx)(Pn,{schemaName:g.schemaName,tableName:g.tableName,rowCount:g.rowCount},g.schemaName?`${g.schemaName}.${g.tableName}`:g.tableName))}):t?(0,e.jsx)("div",{className:"flex-1 overflow-y-auto pb-3 h-full flex items-center justify-center",children:"No tables found matching"}):(0,e.jsx)("div",{className:"flex-1 overflow-y-auto pb-3 h-full flex items-center justify-center",children:"No tables available"})})},Qn=()=>{const t=(0,r.useRef)(null),[s,n]=$(B.SIDEBAR_SEARCH,{defaultValue:""}),{openOverlay:a}=ke(),{dbType:l}=U();return js("/",i=>{i.preventDefault(),t.current&&t.current.focus()},{preventDefault:!0}),(0,e.jsxs)("div",{className:"px-3 pb-3 pt-2 space-y-2",children:[l!=="mongodb"&&(0,e.jsxs)(L,{className:"w-full justify-start h-8",onClick:()=>a("table-builder.create-table"),children:[(0,e.jsx)(de,{className:"size-4"}),"Add Table"]}),(0,e.jsxs)("div",{className:"relative",children:[(0,e.jsx)(Ke,{className:"absolute left-2 top-1/2 -translate-y-1/2 size-4 text-muted-foreground"}),(0,e.jsx)(ne,{ref:t,placeholder:"Search tables",value:s??"",onChange:i=>n(i.target.value.trim()),className:"rounded-sm h-8 pl-8 pr-8"}),(0,e.jsx)(se,{className:"absolute right-2 top-1/2 -translate-y-1/2 text-xs",children:"/"})]})]})},qn=()=>{const[t,s]=$(B.ACTIVE_SCHEMA,{defaultValue:"all"}),{dbType:n}=U(),{tablesList:a=[]}=Ye(),l=(0,r.useMemo)(()=>Array.from(new Set(a.reduce((i,u)=>(u.schemaName&&i.push(u.schemaName),i),[]))).sort(),[a]);return n==="pg"&&l.length>1?(0,e.jsx)("div",{className:"px-3 pt-3",children:(0,e.jsxs)(Se,{value:t,onValueChange:s,children:[(0,e.jsx)(we,{className:"w-full justify-between h-8",children:(0,e.jsx)(De,{placeholder:"Select schema"})}),(0,e.jsxs)(Te,{children:[(0,e.jsx)(V,{value:"all",children:"All schemas"}),l.map(i=>(0,e.jsx)(V,{value:i,children:i},i))]})]})}):null},He=()=>(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(qn,{}),(0,e.jsx)(Qn,{}),(0,e.jsx)(Xe,{className:"flex-1 overflow-y-auto pb-3 block h-full w-full",children:(0,e.jsx)(Bn,{})})]});function Un(){const{databases:t,isLoadingDatabases:s,refetchDatabases:n,isRefetchingDatabases:a}=ws(),{connectionInfo:l,isLoadingConnectionInfo:i}=As(),{selectedDatabase:u,setSelectedDatabase:c}=U(),h=re(),[f,g]=(0,r.useState)(!1),o=j=>{c(j),h({to:"/table",search:{}})},d=async()=>{await n(),P.success("Databases refreshed")};return(0,e.jsx)("div",{className:"mt-auto border-t bg-background",children:(0,e.jsxs)("div",{className:"p-4 space-y-2",children:[(0,e.jsxs)("div",{className:"space-y-2",children:[(0,e.jsxs)("div",{className:"flex items-center justify-between",children:[(0,e.jsxs)("div",{className:"flex items-center gap-2",children:[(0,e.jsx)(St,{className:"size-4 text-muted-foreground"}),(0,e.jsx)("span",{className:"text-sm font-medium",children:"Database"})]}),(0,e.jsxs)(W,{children:[(0,e.jsx)(G,{asChild:!0,children:(0,e.jsx)(L,{variant:"ghost",size:"icon",className:"size-6 hover:bg-accent",onClick:d,disabled:s||a,children:(0,e.jsx)(_t,{className:C("size-3.5",(s||a)&&"animate-spin")})})}),(0,e.jsx)(K,{children:"Refresh databases"})]})]}),(0,e.jsxs)(Se,{value:u||"",onValueChange:o,children:[(0,e.jsx)(we,{className:"h-9 text-xs font-mono w-full",disabled:s||a,children:(0,e.jsx)(De,{placeholder:"Select database..."})}),(0,e.jsx)(Te,{children:t?.map(j=>(0,e.jsx)(V,{value:j.name,className:"font-mono text-xs",children:j.name},j.name))})]})]}),(0,e.jsxs)("div",{className:"space-y-2",children:[(0,e.jsxs)(L,{variant:"ghost",className:"w-full hover:bg-accent flex items-center justify-between",onClick:()=>g(!f),disabled:i||a,children:[(0,e.jsxs)("div",{className:"flex items-center gap-2",children:[(0,e.jsx)("div",{className:"flex items-center justify-center",children:(0,e.jsxs)("div",{className:"relative flex size-2",children:[(0,e.jsx)("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-green-400 opacity-75"}),(0,e.jsx)("span",{className:"relative inline-flex rounded-full size-2 bg-green-500"})]})}),(0,e.jsx)("span",{className:"text-xs font-medium text-green-600",children:"Connected"})]}),(0,e.jsx)(We,{className:C("size-3 text-muted-foreground transition-transform",f&&"rotate-180")})]}),f&&l&&(0,e.jsxs)("div",{className:"space-y-1.5 p-2 rounded-md bg-muted/30",children:[(0,e.jsxs)("div",{className:"flex justify-between items-center",children:[(0,e.jsx)("span",{className:"text-xs text-muted-foreground",children:"Host"}),(0,e.jsxs)("span",{className:"text-xs font-mono text-foreground",children:[l.host,":",l.port]})]}),(0,e.jsxs)("div",{className:"flex justify-between items-center",children:[(0,e.jsx)("span",{className:"text-xs text-muted-foreground",children:"User"}),(0,e.jsx)("span",{className:"text-xs font-mono text-foreground",children:l.user})]}),(0,e.jsxs)("div",{className:"flex justify-between items-center",children:[(0,e.jsx)("span",{className:"text-xs text-muted-foreground",children:"Databases"}),(0,e.jsx)("span",{className:"text-xs font-mono font-medium text-foreground",children:t?.length||0})]})]})]})]})})}var Hn=()=>{const{sidebar:{isPinned:t},toggleSidebarPinned:s}=me();return(0,e.jsx)("div",{className:"flex items-center justify-between h-9 border-b border-zinc-800",children:(0,e.jsx)(L,{variant:"ghost",size:"lg",onClick:s,className:"size-9 flex items-center justify-center transition hover:bg-transparent! focus-visible:ring-0 focus-visible:ring-offset-0",title:t?"Unpin sidebar":"Pin sidebar",children:t?(0,e.jsx)(Lt,{className:"size-4"}):(0,e.jsx)(At,{className:"size-4"})})})},Vn=({children:t})=>{const{sidebar:{width:s,isOpen:n,isPinned:a},setSidebarWidth:l,setSidebarOpen:i}=me(),u=(0,r.useRef)(!1),c=(0,r.useRef)(0),h=(0,r.useRef)(0),f=(0,r.useRef)(null),g=(0,r.useRef)(null),o=(0,r.useRef)(y=>{}),d=(0,r.useRef)(()=>{}),j=(0,r.useRef)(y=>{}),x=(0,r.useRef)(()=>{}),N=(0,r.useRef)(()=>{}),m=(0,r.useCallback)(y=>{u.current&&requestAnimationFrame(()=>{const T=y.clientX-c.current,O=h.current+T;l(O)})},[l]),w=(0,r.useCallback)(()=>{u.current=!1,Object.assign(document.body.style,{cursor:"",userSelect:""});const y=document.getElementById("resize-overlay");y&&y.remove()},[]),p=(0,r.useCallback)(y=>{y.preventDefault(),u.current=!0,c.current=y.clientX,h.current=s,Object.assign(document.body.style,{cursor:"col-resize",userSelect:"none"});const T=document.createElement("div");T.id="resize-overlay",T.style.cssText="position:fixed;inset:0;z-index:9999;cursor:col-resize;",document.body.appendChild(T)},[s]),b=(0,r.useCallback)(()=>{a||i(!0)},[a,i]),v=(0,r.useCallback)(()=>{a||i(!1)},[a,i]),z=(0,r.useCallback)(y=>{a||n||u.current||(y.clientX<=B.HOVER_ZONE?(f.current&&clearTimeout(f.current),f.current=window.setTimeout(()=>{i(!0)},B.HOVER_DELAY)):y.clientX>B.HOVER_ZONE+50&&f.current&&clearTimeout(f.current))},[a,n,i]);o.current=m,d.current=w,j.current=z,x.current=b,N.current=v;const R=y=>{a||i(y)};return(0,r.useEffect)(()=>{const y=F=>o.current(F),T=()=>d.current(),O=F=>j.current(F);return document.addEventListener("mousemove",y),document.addEventListener("mouseup",T),document.addEventListener("mousemove",O),()=>{document.removeEventListener("mousemove",y),document.removeEventListener("mouseup",T),document.removeEventListener("mousemove",O),f.current&&clearTimeout(f.current)}},[]),(0,r.useEffect)(()=>{const y=g.current;if(!y)return;const T=()=>x.current(),O=()=>N.current();return y.addEventListener("mouseenter",T),y.addEventListener("mouseleave",O),()=>{y.removeEventListener("mouseenter",T),y.removeEventListener("mouseleave",O)}},[]),(0,e.jsxs)(Fs,{open:n,onOpenChange:R,modal:!1,children:[(0,e.jsx)(bs,{className:"sr-only",children:"Open Sidebar"}),(0,e.jsx)(Ss,{ref:g,side:"left",showCloseButton:!1,isPinned:a,className:C("bg-black border-r border-zinc-800 p-0","transition-transform duration-300 ease-out"),style:{width:`${s}px`},onOpenAutoFocus:y=>y.preventDefault(),children:(0,e.jsxs)("div",{className:"relative h-full flex flex-col",children:[t,(0,e.jsx)("div",{role:"button",tabIndex:0,onMouseDown:p,className:C("absolute top-0 right-0 w-2 h-full cursor-col-resize z-50","hover:bg-blue-500/50 transition-colors group"),title:"Drag to resize",children:(0,e.jsx)("div",{className:"absolute right-0 top-1/2 -translate-y-1/2 w-2 h-12 bg-blue-500 opacity-0 group-hover:opacity-100 transition-opacity rounded-full"})})]})})]})},$n=()=>{const{pathname:t}=ye(),s=t.split("/")[1],n=(0,r.useMemo)(()=>{switch(s){case"":case"table":case"schema":return(0,e.jsx)(He,{});case"runner":return(0,e.jsx)(Fn,{});default:return(0,e.jsx)(He,{})}},[s]);return(0,e.jsxs)(Vn,{children:[(0,e.jsx)(Hn,{}),n,(0,e.jsx)(Un,{})]})};function nr(){const{sidebar:{isPinned:t,width:s}}=me();return(0,e.jsxs)("div",{className:"bg-zinc-950 w-dvw flex h-dvh max-h-dvh overflow-hidden relative",children:[(0,e.jsx)($n,{}),(0,e.jsxs)("div",{className:"flex-1 flex flex-col h-full overflow-hidden ",style:{marginLeft:t?`${s}px`:"0"},children:[(0,e.jsx)(Rn,{}),(0,e.jsx)(pt,{})]})]})}export{nr as component};