db-studio 1.7.6 → 1.7.9

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 (22) hide show
  1. package/dist/core-dist/assets/{_pathlessLayout-Dj-vL1ro.js → _pathlessLayout-Dh-wnEbU.js} +2 -2
  2. package/dist/core-dist/assets/{_queryId-BlmTSMat.js → _queryId-k0QvsBGf.js} +1 -1
  3. package/dist/core-dist/assets/{_table-B6EDRVAF.js → _table-BuJCKd_h.js} +3 -3
  4. package/dist/core-dist/assets/{_table-Bexe-PRD.js → _table-cCBv5kB-.js} +1 -1
  5. package/dist/core-dist/assets/{cdoe-editor-C6c3JNwJ.js → cdoe-editor-IGx3GQWB.js} +1 -1
  6. package/dist/core-dist/assets/chat-sidebar-D2GaNd69.js +2 -0
  7. package/dist/core-dist/assets/{dist-BY1hG1Ya.js → dist-ZzQZZhtF.js} +1 -1
  8. package/dist/core-dist/assets/{dist-CX0IXul5.js → dist-v6aWpqmu.js} +1 -1
  9. package/dist/core-dist/assets/{index-B7KYpPyV.js → index-BtQYs6UF.js} +11 -11
  10. package/dist/core-dist/assets/{queries.store-CwP6d13j.js → queries.store-BtuppsNj.js} +1 -1
  11. package/dist/core-dist/assets/{runner-DT89R_pW.js → runner-VSPg2lHo.js} +1 -1
  12. package/dist/core-dist/assets/{runner-tab-CJfQuLY7.js → runner-tab-BQH-lTnK.js} +3 -3
  13. package/dist/core-dist/assets/{scroll-area-A-6bIiHh.js → scroll-area-BnT9xy-y.js} +1 -1
  14. package/dist/core-dist/assets/{tooltip-BSKLiphS.js → tooltip-B3DXDN3Y.js} +1 -1
  15. package/dist/core-dist/assets/{use-delete-column-JnaJwJqm.js → use-delete-column-B-oY2CU8.js} +1 -1
  16. package/dist/core-dist/assets/use-rate-limit-BenJo7Lk.js +1 -0
  17. package/dist/core-dist/index.html +1 -1
  18. package/dist/index.js +79 -77
  19. package/dist/index.js.map +1 -1
  20. package/package.json +1 -1
  21. package/dist/core-dist/assets/chat-sidebar-A3iurUmg.js +0 -2
  22. package/dist/core-dist/assets/use-rate-limit-Bdyk6haf.js +0 -1
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "db-studio",
3
3
  "type": "module",
4
- "version": "1.7.6",
4
+ "version": "1.7.9",
5
5
  "description": "Modern database client for PostgreSQL with spreadsheet-like grid, AI-powered SQL assistance, ER diagrams, fast data browsing and editing. CLI tool, upcoming desktop & web versions.",
6
6
  "keywords": [
7
7
  "database client",
@@ -1,2 +0,0 @@
1
- import{r as ge}from"./rolldown-runtime-Bnw7wDfq.js";import{o as xe,s as ve}from"./tanstack-DyfKDo5s.js";import{G as Te,N as be,Y as je,b as Se,c as Ce,m as ye,nt as we,t as Ne,tt as ke}from"./icons-BywMJ5og.js";import{Ct as J,F as Ee,I as Re,Ot as Ae,P as Le,Tt as Be}from"./radix-ui-C0u6gLux.js";import{Et as w,G as De,J as Ie,K as Pe,_t as _e,lt as ze,q as Me,st as Fe,wt as H,x as Ue}from"./index-B7KYpPyV.js";import{r as ee}from"./chunk-BO2N2NFS-BWASkQ7r.js";import{n as Oe,t as qe}from"./scroll-area-A-6bIiHh.js";import{i as Ge,n as He,t as We}from"./tooltip-BSKLiphS.js";import{t as te}from"./use-rate-limit-Bdyk6haf.js";var Ke=["Show me all tables in my database","What columns are in the users table?","Write a query to find all active users","How many orders were placed last month?","Find top 5 customers by total spend","Write a JOIN between users and orders","Users who haven't made any purchase yet","Generate monthly revenue summary query","Suggest useful indexes for better performance","Show schema of the products / inventory table","Latest 20 orders with customer names","Help me write a safe UPDATE query"],s=ge(we(),1),Je={damping:.7,stiffness:.05,mass:1.25},Ve=70,Xe=1e3/60,Ye=350,F=!1;globalThis.document?.addEventListener("mousedown",()=>{F=!0});globalThis.document?.addEventListener("mouseup",()=>{F=!1});globalThis.document?.addEventListener("click",()=>{F=!1});var $e=(r={})=>{const[n,o]=(0,s.useState)(!1),[i,a]=(0,s.useState)(r.initial!==!1),[d,m]=(0,s.useState)(!1),x=(0,s.useRef)(null);x.current=r;const v=(0,s.useCallback)(()=>{if(!F)return!1;const l=window.getSelection();if(!l||!l.rangeCount)return!1;const c=l.getRangeAt(0);return c.commonAncestorContainer.contains(h.current)||h.current?.contains(c.commonAncestorContainer)},[]),T=(0,s.useCallback)(l=>{e.isAtBottom=l,a(l)},[]),C=(0,s.useCallback)(l=>{e.escapedFromLock=l,o(l)},[]),e=(0,s.useMemo)(()=>{let l;return{escapedFromLock:n,isAtBottom:i,resizeDifference:0,accumulated:0,velocity:0,listeners:new Set,get scrollTop(){return h.current?.scrollTop??0},set scrollTop(c){h.current&&(h.current.scrollTop=c,e.ignoreScrollToTop=h.current.scrollTop)},get targetScrollTop(){return!h.current||!S.current?0:h.current.scrollHeight-1-h.current.clientHeight},get calculatedTargetScrollTop(){if(!h.current||!S.current)return 0;const{targetScrollTop:c}=this;if(!r.targetScrollTop)return c;if(l?.targetScrollTop===c)return l.calculatedScrollTop;const g=Math.max(Math.min(r.targetScrollTop(c,{scrollElement:h.current,contentElement:S.current}),c),0);return l={targetScrollTop:c,calculatedScrollTop:g},requestAnimationFrame(()=>{l=void 0}),g},get scrollDifference(){return this.calculatedTargetScrollTop-this.scrollTop},get isNearBottom(){return this.scrollDifference<=Ve}}},[]),u=(0,s.useCallback)((l={})=>{typeof l=="string"&&(l={animation:l}),l.preserveScrollPosition||T(!0);const c=Date.now()+(Number(l.wait)||0),g=G(x.current,l.animation),{ignoreEscapes:E=!1}=l;let L,B=e.calculatedTargetScrollTop;l.duration instanceof Promise?l.duration.finally(()=>{L=Date.now()}):L=c+(l.duration??0);const R=async()=>{const _=new Promise(requestAnimationFrame).then(()=>{if(!e.isAtBottom)return e.animation=void 0,!1;const{scrollTop:D}=e,P=performance.now(),U=(P-(e.lastTick??P))/Xe;if(e.animation||(e.animation={behavior:g,promise:_,ignoreEscapes:E}),e.animation.behavior===g&&(e.lastTick=P),v()||c>Date.now())return R();if(D<Math.min(B,e.calculatedTargetScrollTop)){if(e.animation?.behavior===g){if(g==="instant")return e.scrollTop=e.calculatedTargetScrollTop,R();e.velocity=(g.damping*e.velocity+g.stiffness*e.scrollDifference)/g.mass,e.accumulated+=e.velocity*U,e.scrollTop+=e.accumulated,e.scrollTop!==D&&(e.accumulated=0)}return R()}return L>Date.now()?(B=e.calculatedTargetScrollTop,R()):(e.animation=void 0,e.scrollTop<e.calculatedTargetScrollTop?u({animation:G(x.current,x.current.resize),ignoreEscapes:E,duration:Math.max(0,L-Date.now())||void 0}):e.isAtBottom)});return _.then(D=>(requestAnimationFrame(()=>{e.animation||(e.lastTick=void 0,e.velocity=0)}),D))};return l.wait!==!0&&(e.animation=void 0),e.animation?.behavior===g?e.animation.promise:R()},[T,v,e]),N=(0,s.useCallback)(()=>{C(!0),T(!1)},[C,T]),k=(0,s.useCallback)(({target:l})=>{if(l!==h.current)return;const{scrollTop:c,ignoreScrollToTop:g}=e;let{lastScrollTop:E=c}=e;e.lastScrollTop=c,e.ignoreScrollToTop=void 0,g&&g>c&&(E=g),m(e.isNearBottom),setTimeout(()=>{if(e.resizeDifference||c===g)return;if(v()){C(!0),T(!1);return}const L=c>E,B=c<E;if(e.animation?.ignoreEscapes){e.scrollTop=E;return}B&&(C(!0),T(!1)),L&&C(!1),!e.escapedFromLock&&e.isNearBottom&&T(!0)},1)},[C,T,v,e]),f=(0,s.useCallback)(({target:l,deltaY:c})=>{let g=l;for(;!["scroll","auto"].includes(getComputedStyle(g).overflow);){if(!g.parentElement)return;g=g.parentElement}g===h.current&&c<0&&h.current.scrollHeight>h.current.clientHeight&&!e.animation?.ignoreEscapes&&(C(!0),T(!1))},[C,T,e]),h=V(l=>{h.current?.removeEventListener("scroll",k),h.current?.removeEventListener("wheel",f),l?.addEventListener("scroll",k,{passive:!0}),l?.addEventListener("wheel",f,{passive:!0})},[]),S=V(l=>{if(e.resizeObserver?.disconnect(),!l)return;let c;e.resizeObserver=new ResizeObserver(([g])=>{const{height:E}=g.contentRect,L=E-(c??E);if(e.resizeDifference=L,e.scrollTop>e.targetScrollTop&&(e.scrollTop=e.targetScrollTop),m(e.isNearBottom),L>=0){const B=G(x.current,c?x.current.resize:x.current.initial);u({animation:B,wait:!0,preserveScrollPosition:!0,duration:B==="instant"?void 0:Ye})}else e.isNearBottom&&(C(!1),T(!0));c=E,requestAnimationFrame(()=>{setTimeout(()=>{e.resizeDifference===L&&(e.resizeDifference=0)},1)})}),e.resizeObserver?.observe(l)},[]);return{contentRef:S,scrollRef:h,scrollToBottom:u,stopScroll:N,isAtBottom:i||d,isNearBottom:d,escapedFromLock:n,state:e}};function V(r,n){const o=(0,s.useCallback)(i=>(o.current=i,r(i)),n);return o}var q=new Map;function G(...r){const n={...Je};let o=!1;for(const a of r){if(a==="instant"){o=!0;continue}typeof a=="object"&&(o=!1,n.damping=a.damping??n.damping,n.stiffness=a.stiffness??n.stiffness,n.mass=a.mass??n.mass)}const i=JSON.stringify(n);return q.has(i)||q.set(i,Object.freeze(n)),o?"instant":q.get(i)}var t=Ae(),re=(0,s.createContext)(null),Qe=typeof window<"u"?s.useLayoutEffect:s.useEffect;function M({instance:r,children:n,resize:o,initial:i,mass:a,damping:d,stiffness:m,targetScrollTop:x,contextRef:v,...T}){const C=(0,s.useRef)(null),e=$e({mass:a,damping:d,stiffness:m,resize:o,initial:i,targetScrollTop:s.useCallback((g,E)=>(c?.targetScrollTop??x)?.(g,E)??g,[x])}),{scrollRef:u,contentRef:N,scrollToBottom:k,stopScroll:f,isAtBottom:h,escapedFromLock:S,state:l}=r??e,c=(0,s.useMemo)(()=>({scrollToBottom:k,stopScroll:f,scrollRef:u,isAtBottom:h,escapedFromLock:S,contentRef:N,state:l,get targetScrollTop(){return C.current},set targetScrollTop(g){C.current=g}}),[k,h,N,u,f,S,l]);return(0,s.useImperativeHandle)(v,()=>c,[c]),Qe(()=>{u.current&&getComputedStyle(u.current).overflow==="visible"&&(u.current.style.overflow="auto")},[]),(0,t.jsx)(re.Provider,{value:c,children:(0,t.jsx)("div",{...T,children:typeof n=="function"?n(c):n})})}(function(r){function n({children:o,...i}){const a=ne();return(0,t.jsx)("div",{ref:a.scrollRef,style:{height:"100%",width:"100%"},children:(0,t.jsx)("div",{...i,ref:a.contentRef,children:typeof o=="function"?o(a):o})})}r.Content=n})(M||(M={}));function ne(){const r=(0,s.useContext)(re);if(!r)throw new Error("use-stick-to-bottom component context must be used within a StickToBottom component");return r}var Ze=({className:r,...n})=>(0,t.jsx)(M,{className:w("relative flex-1 overflow-y-hidden",r),initial:"smooth",resize:"smooth",role:"log",...n}),et=({className:r,...n})=>(0,t.jsx)(M.Content,{className:w("flex flex-col gap-8 p-4",r),...n}),tt=({className:r,...n})=>{const{isAtBottom:o,scrollToBottom:i}=ne(),a=(0,s.useCallback)(()=>{i()},[i]);return!o&&(0,t.jsx)(H,{className:w("absolute bottom-4 left-[50%] translate-x-[-50%] rounded-full",r),onClick:a,size:"icon",type:"button",variant:"outline",...n,children:(0,t.jsx)(ke,{className:"size-4"})})},X=[{variant:"shine",component:({children:r,className:n,...o})=>(0,t.jsx)("span",{...o,className:w("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",n),children:r})}];function rt({variant:r="shine",className:n,...o}){const i=X.find(a=>a.variant===r)?.component||X[0].component;return(0,t.jsx)(Be,{className:w("font-medium text-sm"),children:(0,t.jsx)(i,{...o,className:n})})}var Y=({className:r,from:n,...o})=>(0,t.jsx)("div",{className:w("group flex w-full max-w-[95%] flex-col gap-2",n==="user"?"is-user ml-auto justify-end":"is-assistant",r),...o}),$=({children:r,className:n,...o})=>(0,t.jsx)("div",{className:w("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",n),...o,children:r}),se=(0,s.createContext)(null),nt=()=>{const r=(0,s.useContext)(se);if(!r)throw new Error("MessageBranch components must be used within MessageBranch");return r},Q=({defaultBranch:r=0,onBranchChange:n,className:o,...i})=>{const[a,d]=(0,s.useState)(r),[m,x]=(0,s.useState)([]),v=u=>{d(u),n?.(u)},T=()=>{v(a>0?a-1:m.length-1)},C=()=>{v(a<m.length-1?a+1:0)},e={currentBranch:a,totalBranches:m.length,goToPrevious:T,goToNext:C,branches:m,setBranches:x};return(0,t.jsx)(se.Provider,{value:e,children:(0,t.jsx)("div",{className:w("grid w-full gap-2 [&>div]:pb-0",o),...i})})},Z=({children:r,...n})=>{const{currentBranch:o,setBranches:i,branches:a}=nt(),d=Array.isArray(r)?r:[r];return(0,s.useEffect)(()=>{a.length!==d.length&&i(d)},[d,a,i]),d.map((m,x)=>(0,t.jsx)("div",{className:w("grid gap-2 overflow-hidden [&>div]:pb-0",x===o?"block":"hidden"),...n,children:m},m.key))},oe=(0,s.memo)(({className:r,...n})=>(0,t.jsx)(ee,{className:w("size-full [&>*:first-child]:mt-0 [&>*:last-child]:mb-0",r),...n}),(r,n)=>r.children===n.children);oe.displayName="MessageResponse";var st="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict",ot=(r=21)=>{let n="",o=crypto.getRandomValues(new Uint8Array(r|=0));for(;r--;)n+=st[o[r]&63];return n},at=(0,s.createContext)(null),it=(0,s.createContext)(null),ae=()=>(0,s.useContext)(at),lt=()=>(0,s.useContext)(it),ie=(0,s.createContext)(null),ct=()=>{const r=lt(),n=(0,s.useContext)(ie),o=r??n;if(!o)throw new Error("usePromptInputAttachments must be used within a PromptInput or PromptInputProvider");return o},ut=({className:r,accept:n,multiple:o,globalDrop:i,syncHiddenInput:a,maxFiles:d,maxFileSize:m,onError:x,onSubmit:v,children:T,...C})=>{const e=ae(),u=!!e,N=(0,s.useRef)(null),k=(0,s.useRef)(null),[f,h]=(0,s.useState)([]),S=u?e.attachments.files:f,l=(0,s.useRef)(S);l.current=S;const c=(0,s.useCallback)(()=>{N.current?.click()},[]),g=(0,s.useCallback)(p=>!n||n.trim()===""?!0:n.split(",").map(b=>b.trim()).filter(Boolean).some(b=>{if(b.endsWith("/*")){const j=b.slice(0,-1);return p.type.startsWith(j)}return p.type===b}),[n]),E=(0,s.useCallback)(p=>{const b=Array.from(p),j=b.filter(I=>g(I));if(b.length&&j.length===0){x?.({code:"accept",message:"No files match the accepted types."});return}const y=I=>m?I.size<=m:!0,A=j.filter(y);if(j.length>0&&A.length===0){x?.({code:"max_file_size",message:"All files exceed the maximum size."});return}h(I=>{const z=typeof d=="number"?Math.max(0,d-I.length):void 0,he=typeof z=="number"?A.slice(0,z):A;typeof z=="number"&&A.length>z&&x?.({code:"max_files",message:"Too many files. Some were not added."});const K=[];for(const O of he)K.push({id:ot(),type:"file",url:URL.createObjectURL(O),mediaType:O.type,filename:O.name});return I.concat(K)})},[g,d,m,x]),L=(0,s.useCallback)(p=>h(b=>{const j=b.find(y=>y.id===p);return j?.url&&URL.revokeObjectURL(j.url),b.filter(y=>y.id!==p)}),[]),B=(0,s.useCallback)(()=>h(p=>{for(const b of p)b.url&&URL.revokeObjectURL(b.url);return[]}),[]),R=u?e.attachments.add:E,_=u?e.attachments.remove:L,D=u?e.attachments.clear:B,P=u?e.attachments.openFileDialog:c;(0,s.useEffect)(()=>{u&&e.__registerFileInput(N,()=>N.current?.click())},[u,e]),(0,s.useEffect)(()=>{a&&N.current&&S.length===0&&(N.current.value="")},[S,a]),(0,s.useEffect)(()=>{const p=k.current;if(!p||i)return;const b=y=>{y.dataTransfer?.types?.includes("Files")&&y.preventDefault()},j=y=>{y.dataTransfer?.types?.includes("Files")&&y.preventDefault(),y.dataTransfer?.files&&y.dataTransfer.files.length>0&&R(y.dataTransfer.files)};return p.addEventListener("dragover",b),p.addEventListener("drop",j),()=>{p.removeEventListener("dragover",b),p.removeEventListener("drop",j)}},[R,i]),(0,s.useEffect)(()=>{if(!i)return;const p=j=>{j.dataTransfer?.types?.includes("Files")&&j.preventDefault()},b=j=>{j.dataTransfer?.types?.includes("Files")&&j.preventDefault(),j.dataTransfer?.files&&j.dataTransfer.files.length>0&&R(j.dataTransfer.files)};return document.addEventListener("dragover",p),document.addEventListener("drop",b),()=>{document.removeEventListener("dragover",p),document.removeEventListener("drop",b)}},[R,i]),(0,s.useEffect)(()=>()=>{if(!u)for(const p of l.current)p.url&&URL.revokeObjectURL(p.url)},[u]);const U=p=>{p.currentTarget.files&&R(p.currentTarget.files),p.currentTarget.value=""},de=async p=>{try{const b=await(await fetch(p)).blob();return new Promise(j=>{const y=new FileReader;y.onloadend=()=>j(y.result),y.onerror=()=>j(null),y.readAsDataURL(b)})}catch{return null}},me=(0,s.useMemo)(()=>({files:S.map(p=>({...p,id:p.id})),add:R,remove:_,clear:D,openFileDialog:P,fileInputRef:N}),[S,R,_,D,P]),pe=p=>{p.preventDefault();const b=p.currentTarget,j=u?e.textInput.value:new FormData(b).get("message")||"";u||b.reset(),Promise.all(S.map(async({id:y,...A})=>{if(A.url?.startsWith("blob:")){const I=await de(A.url);return{...A,url:I??A.url}}return A})).then(y=>{try{const A=v({text:j,files:y},p);A instanceof Promise?A.then(()=>{D(),u&&e.textInput.clear()}).catch(()=>{}):(D(),u&&e.textInput.clear())}catch{}}).catch(()=>{})},W=(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("input",{accept:n,"aria-label":"Upload files",className:"hidden",multiple:o,onChange:U,ref:N,title:"Upload files",type:"file"}),(0,t.jsx)("form",{className:w("w-full",r),onSubmit:pe,ref:k,...C,children:(0,t.jsx)(De,{className:"overflow-hidden",children:T})})]});return u?W:(0,t.jsx)(ie.Provider,{value:me,children:W})},ft=({className:r,...n})=>(0,t.jsx)("div",{className:w("contents",r),...n}),dt=({onChange:r,className:n,placeholder:o="What would you like to know?",...i})=>{const a=ae(),d=ct(),[m,x]=(0,s.useState)(!1),v=e=>{if(e.key==="Enter"){if(m||e.nativeEvent.isComposing||e.shiftKey)return;e.preventDefault();const u=e.currentTarget.form;if(u?.querySelector('button[type="submit"]')?.disabled)return;u?.requestSubmit()}if(e.key==="Backspace"&&e.currentTarget.value===""&&d.files.length>0){e.preventDefault();const u=d.files.at(-1);u&&d.remove(u.id)}},T=e=>{const u=e.clipboardData?.items;if(!u)return;const N=[];for(const k of u)if(k.kind==="file"){const f=k.getAsFile();f&&N.push(f)}N.length>0&&(e.preventDefault(),d.add(N))},C=a?{value:a.textInput.value,onChange:e=>{a.textInput.setInput(e.currentTarget.value),r?.(e)}}:{onChange:r};return(0,t.jsx)(Ie,{className:w("field-sizing-content max-h-48 min-h-16",n),name:"message",onCompositionEnd:()=>x(!1),onCompositionStart:()=>x(!0),onKeyDown:v,onPaste:T,placeholder:o,...i,...C})},mt=({className:r,...n})=>(0,t.jsx)(Pe,{align:"block-end",className:w("justify-between justify-end gap-1",r),...n}),pt=({className:r,variant:n="default",size:o="icon-sm",status:i,children:a,...d})=>{let m=(0,t.jsx)(be,{className:"size-4"});return i==="submitted"?m=(0,t.jsx)(Se,{className:"size-4 animate-spin"}):i==="streaming"?m=(0,t.jsx)(Ce,{className:"size-4"}):i==="error"&&(m=(0,t.jsx)(Ne,{className:"size-4"})),(0,t.jsx)(Me,{"aria-label":"Submit",className:w(r),size:o,type:"submit",variant:n,...d,children:a??m})};function ht({...r}){return(0,t.jsx)(Ee,{"data-slot":"collapsible",...r})}function gt({...r}){return(0,t.jsx)(Re,{"data-slot":"collapsible-trigger",...r})}function xt({...r}){return(0,t.jsx)(Le,{"data-slot":"collapsible-content",...r})}var vt=({children:r,as:n="p",className:o,duration:i=2,spread:a=2})=>{const d=(0,s.useMemo)(()=>(r?.length??0)*a,[r,a]);return(0,t.jsx)(n,{className:w("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",o),style:{"--spread":`${d}px`,"--duration":`${i}s`,backgroundImage:"var(--bg), linear-gradient(var(--color-muted-foreground), var(--color-muted-foreground))"},children:r})},Tt=(0,s.memo)(vt),le=(0,s.createContext)(null),bt=()=>{const r=(0,s.useContext)(le);if(!r)throw new Error("Reasoning components must be used within Reasoning");return r},jt=1e3,St=1e3,ce=(0,s.memo)(({className:r,isStreaming:n=!1,open:o,defaultOpen:i=!0,onOpenChange:a,duration:d,children:m,...x})=>{const[v,T]=J({prop:o,defaultProp:i,onChange:a}),[C,e]=J({prop:d,defaultProp:void 0}),[u,N]=(0,s.useState)(!1),[k,f]=(0,s.useState)(null);(0,s.useEffect)(()=>{n?k===null&&f(Date.now()):k!==null&&(e(Math.ceil((Date.now()-k)/St)),f(null))},[n,k,e]),(0,s.useEffect)(()=>{if(i&&!n&&v&&!u){const S=setTimeout(()=>{T(!1),N(!0)},jt);return()=>clearTimeout(S)}},[n,v,i,T,u]);const h=S=>{T(S)};return(0,t.jsx)(le.Provider,{value:{isStreaming:n,isOpen:v,setIsOpen:T,duration:C},children:(0,t.jsx)(ht,{className:w("not-prose mb-4",r),onOpenChange:h,open:v,...x,children:m})})}),Ct=(r,n)=>r||n===0?(0,t.jsx)(Tt,{duration:1,children:"Thinking..."}):n===void 0?(0,t.jsx)("p",{children:"Thought for a few seconds"}):(0,t.jsxs)("p",{children:["Thought for ",n," seconds"]}),ue=(0,s.memo)(({className:r,children:n,getThinkingMessage:o=Ct,...i})=>{const{isStreaming:a,isOpen:d,duration:m}=bt();return(0,t.jsx)(gt,{className:w("flex w-full items-center gap-2 text-muted-foreground text-sm transition-colors hover:text-foreground",r),...i,children:n??(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(je,{className:"size-4"}),o(a,m),(0,t.jsx)(Te,{className:w("size-4 transition-transform",d?"rotate-180":"rotate-0")})]})})}),fe=(0,s.memo)(({className:r,children:n,...o})=>(0,t.jsx)(xt,{className:w("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",r),...o,children:(0,t.jsx)(ee,{children:n})}));ce.displayName="Reasoning";ue.displayName="ReasoningTrigger";fe.displayName="ReasoningContent";var yt=({className:r,children:n,...o})=>(0,t.jsxs)(qe,{className:"w-full overflow-x-auto whitespace-nowrap",...o,children:[(0,t.jsx)("div",{className:w("flex w-max flex-nowrap items-center gap-2",r),children:n}),(0,t.jsx)(Oe,{className:"hidden",orientation:"horizontal"})]}),wt=({suggestion:r,onClick:n,className:o,variant:i="outline",size:a="sm",children:d,...m})=>{const x=()=>{n?.(r)};return(0,t.jsx)(H,{className:w("cursor-pointer rounded-full px-4",o),onClick:x,size:a,type:"button",variant:i,...m,children:d||r})},Nt=({db:r,onRateLimitRefetch:n,onControllerReady:o})=>{const[i,a]=(0,s.useState)(""),{rateLimit:d}=te(),{messages:m,sendMessage:x,isLoading:v,clear:T,stop:C}=xe({connection:ve(`${ze.BASE_URL}/chat`),body:{db:r},onError:f=>console.error("Error:",f.message),onResponse:f=>console.log("Response:",f),onFinish:f=>{console.log("Finish:",f),n()}});(0,s.useEffect)(()=>{o({clear:()=>{T(),a("")},isLoading:v})},[T,v,o]);const e=f=>{const h=!!f.text,S=!!f.files?.length;!(h||S)||v||(x(f.text),a(""))},u=f=>{x(f),a("")},N=()=>{C(),a("")},k=v?"streaming":"ready";return(0,t.jsxs)("div",{className:"relative flex size-full flex-col divide-y overflow-hidden",children:[(0,t.jsxs)(Ze,{children:[(0,t.jsx)(et,{children:m.length===0?(0,t.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground",children:(0,t.jsxs)("div",{className:"text-center space-y-2",children:[(0,t.jsx)("p",{className:"text-lg font-medium",children:"Start a new conversation"}),(0,t.jsx)("p",{className:"text-sm",children:"Ask me anything to get started"})]})}):(0,t.jsxs)(t.Fragment,{children:[m.map(f=>{const h=f.parts.filter(c=>c.type==="thinking"),S=f.parts.filter(c=>c.type==="text").map(c=>c.content).join(""),l=h.length>0;return(0,t.jsx)(Q,{defaultBranch:0,children:(0,t.jsx)(Z,{children:(0,t.jsx)(Y,{from:f.role==="user"?"user":"assistant",children:(0,t.jsxs)("div",{children:[l&&f.role==="assistant"&&(0,t.jsxs)(ce,{duration:0,children:[(0,t.jsx)(ue,{}),(0,t.jsx)(fe,{children:h.map(c=>c.content).join(`
2
- `)})]}),(0,t.jsx)($,{children:(0,t.jsx)(oe,{children:S})})]})})})},f.id)}),v&&(0,t.jsx)(Q,{defaultBranch:0,children:(0,t.jsx)(Z,{children:(0,t.jsx)(Y,{from:"assistant",children:(0,t.jsx)($,{children:(0,t.jsx)(rt,{children:"Thinking..."})})})})})]})}),(0,t.jsx)(tt,{})]}),(0,t.jsxs)("div",{className:"grid shrink-0 gap-4 pt-3",children:[m.length===0&&(0,t.jsx)(yt,{className:"px-4",children:Ke.map(f=>(0,t.jsx)(wt,{onClick:()=>u(f),suggestion:f,size:"lg",children:f},f))}),(0,t.jsx)("div",{className:"w-full px-4 pb-4",children:(0,t.jsxs)(ut,{globalDrop:!0,multiple:!0,onSubmit:e,children:[(0,t.jsx)(ft,{children:(0,t.jsx)(dt,{onChange:f=>a(f.target.value),value:i,placeholder:"Type a message..."})}),(0,t.jsx)(mt,{children:(0,t.jsx)(pt,{className:"h-8!",status:k,onClick:v?N:void 0,disabled:d&&d.remaining===0})})]})})]})]})},_t=()=>{const{rateLimit:r,refetchRateLimit:n}=te(),{isSheetOpen:o,closeSheet:i}=_e(),{selectedDatabase:a}=Fe(),[d,m]=(0,s.useState)(null),x=(0,s.useRef)(v=>m(v));return(0,t.jsx)(Ue,{title:"AI Assistant",cta:(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[r&&(0,t.jsxs)(We,{children:[(0,t.jsx)(Ge,{asChild:!0,children:(0,t.jsxs)("span",{className:"text-xs px-2 py-1 cursor-default text-muted-foreground",children:[r.remaining,"/",r.limit]})}),(0,t.jsx)(He,{side:"bottom",children:(0,t.jsxs)("p",{children:[r.remaining," messages remaining"]})})]}),a&&d&&(0,t.jsxs)(H,{type:"button",variant:"outline",size:"lg",onClick:d.clear,disabled:d.isLoading,children:[(0,t.jsx)(ye,{className:"h-4 w-4 mr-1"}),"New Chat"]})]}),closeButton:!1,open:o("ai-assistant"),size:"max-w-2xl!",contentClassName:"p-0 flex flex-col h-[calc(100vh-4rem)] flex-1",onOpenChange:v=>{v||i("ai-assistant")},children:a?(0,t.jsx)(Nt,{db:a,onRateLimitRefetch:n,onControllerReady:x.current},a):(0,t.jsx)("div",{className:"flex items-center justify-center h-full text-muted-foreground p-8",children:(0,t.jsxs)("div",{className:"text-center space-y-2",children:[(0,t.jsx)("p",{className:"text-lg font-medium",children:"No database selected"}),(0,t.jsx)("p",{className:"text-sm",children:"Select a database from the sidebar to start chatting."})]})})})};export{_t as ChatSidebar};
@@ -1 +0,0 @@
1
- import{y as n}from"./tanstack-DyfKDo5s.js";import{lt as s}from"./index-B7KYpPyV.js";var t={limit:999,used:0,remaining:999},m=typeof window<"u"&&window.location.hostname==="localhost",c=()=>{const{data:e,isLoading:i,error:a,refetch:o}=n({queryKey:["rate-limit"],queryFn:async()=>{if(m)return t;try{const r=await fetch(`${s.PROXY_URL}/chat/limit`);return r.ok?await r.json():t}catch{return t}}});return{rateLimit:e,isLoadingRateLimit:i,errorRateLimit:a,refetchRateLimit:o}};export{c as t};