@hienlh/ppm 0.7.4 → 0.7.6

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 (35) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/web/assets/{ai-settings-section-CBpXqM-I.js → ai-settings-section-ByRvOONz.js} +1 -1
  3. package/dist/web/assets/{chat-tab-DXtCcWg2.js → chat-tab-ChK0Oj4w.js} +6 -6
  4. package/dist/web/assets/{code-editor-CxMuSJrX.js → code-editor-Bmt1mSYa.js} +1 -1
  5. package/dist/web/assets/columns-2-fz8yNaAo.js +1 -0
  6. package/dist/web/assets/{database-viewer-C6riNG1v.js → database-viewer-Bocsej-g.js} +1 -1
  7. package/dist/web/assets/diff-viewer-BH4xWdR5.js +4 -0
  8. package/dist/web/assets/git-graph-DgzvrrL6.js +1 -0
  9. package/dist/web/assets/{index-B9ZHWVob.js → index-YO_w11fv.js} +4 -4
  10. package/dist/web/assets/{input-BpFvhpT8.js → input-P_K5CUiy.js} +1 -1
  11. package/dist/web/assets/keybindings-store-BydsAw-q.js +1 -0
  12. package/dist/web/assets/{markdown-renderer-DKVNZXEw.js → markdown-renderer-BkXmQhhX.js} +1 -1
  13. package/dist/web/assets/{postgres-viewer-DHvwHGEL.js → postgres-viewer-XQkpsAak.js} +1 -1
  14. package/dist/web/assets/{settings-store-DS-ifJ7c.js → settings-store-2NQzaOVJ.js} +1 -1
  15. package/dist/web/assets/settings-tab-C2zPIPQH.js +1 -0
  16. package/dist/web/assets/{sqlite-viewer-C5Vj_kSU.js → sqlite-viewer-BZroKOjV.js} +1 -1
  17. package/dist/web/assets/{tab-store-D7tRt0VT.js → tab-store-0CKk8cSr.js} +1 -1
  18. package/dist/web/assets/{terminal-tab-B95lVSty.js → terminal-tab-C2IQ6don.js} +2 -2
  19. package/dist/web/assets/{use-monaco-theme-M04jkKDM.js → use-monaco-theme-Bt1Lr3jH.js} +1 -1
  20. package/dist/web/index.html +8 -8
  21. package/dist/web/sw.js +1 -1
  22. package/package.json +1 -1
  23. package/src/server/routes/tunnel.ts +15 -0
  24. package/src/services/claude-usage.service.ts +75 -35
  25. package/src/services/db.service.ts +65 -1
  26. package/src/web/components/editor/diff-viewer.tsx +37 -36
  27. package/dist/web/assets/diff-viewer-CQIockZr.js +0 -4
  28. package/dist/web/assets/git-graph-D2BR2rfP.js +0 -1
  29. package/dist/web/assets/keybindings-store-fcYIcK0C.js +0 -1
  30. package/dist/web/assets/settings-tab-D_quOlcC.js +0 -1
  31. /package/dist/web/assets/{api-client-B0aMOJxF.js → api-client-TUmacMRS.js} +0 -0
  32. /package/dist/web/assets/{dist-QgqOdSYG.js → dist-D9RHR8A4.js} +0 -0
  33. /package/dist/web/assets/{react-Dk7fkoaB.js → react-rgzL83kk.js} +0 -0
  34. /package/dist/web/assets/{table-B6neW6Hr.js → table-C0oSLUYn.js} +0 -0
  35. /package/dist/web/assets/{utils-DBpa1UZX.js → utils-DC-bdPS3.js} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.7.6] - 2026-03-20
4
+
5
+ ### Fixed
6
+ - **Diff viewer toolbar**: moved expand/word-wrap buttons into a fixed header bar (hidden on mobile); fixes toolbar being rendered outside the scroll container
7
+ - **Diff viewer empty state**: handles metadata-only diffs (file mode change, rename) where `parseDiff` returns no hunks — shows "No content changes" instead of blank screen
8
+
9
+ ## [0.7.5] - 2026-03-20
10
+
11
+ ### Added
12
+ - **Usage limit history (SQLite)**: Claude 5hr/weekly limit snapshots now persisted to `claude_limit_snapshots` table (migration v4) — inserts new row only when utilization or reset-time changes, auto-cleans records older than 7 days
13
+ - **Usage polling interval**: Changed from 60s to 2min; `GET /chat/usage?refresh=1` forces an immediate API fetch and waits before returning the fresh DB snapshot
14
+ - **FE reads from DB**: `refresh=0` reads latest snapshot directly from DB (no Anthropic API call); `refresh=1` waits for fresh fetch then reads DB
15
+
3
16
  ## [0.7.4] - 2026-03-20
4
17
 
5
18
  ### Added
@@ -1 +1 @@
1
- import{i as e,t}from"./react-CYzKIDNi.js";import{C as n,E as r,S as i,_ as a,a as o,b as s,c,d as l,f as u,g as d,h as f,i as p,j as m,k as h,l as g,m as _,n as v,o as y,p as b,r as x,s as S,t as C,u as w,v as T,y as E}from"./input-BpFvhpT8.js";import{n as D,t as O}from"./jsx-runtime-wQxeESYQ.js";import{n as k}from"./utils-DBpa1UZX.js";import{t as A}from"./api-client-B0aMOJxF.js";var j=D(`bell-off`,[[`path`,{d:`M10.268 21a2 2 0 0 0 3.464 0`,key:`vwvbt9`}],[`path`,{d:`M17 17H4a1 1 0 0 1-.74-1.673C4.59 13.956 6 12.499 6 8a6 6 0 0 1 .258-1.742`,key:`178tsu`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M8.668 3.01A6 6 0 0 1 18 8c0 2.687.77 4.653 1.707 6.05`,key:`1hqiys`}]]),M=D(`check`,[[`path`,{d:`M20 6 9 17l-5-5`,key:`1gmf2c`}]]),N=D(`chevron-down`,[[`path`,{d:`m6 9 6 6 6-6`,key:`qrunsl`}]]),P=D(`chevron-up`,[[`path`,{d:`m18 15-6-6-6 6`,key:`153udz`}]]),F=e(t(),1),I=O(),L=Object.freeze({position:`absolute`,border:0,width:1,height:1,padding:0,margin:-1,overflow:`hidden`,clip:`rect(0, 0, 0, 0)`,whiteSpace:`nowrap`,wordWrap:`normal`}),R=`VisuallyHidden`,ee=F.forwardRef((e,t)=>(0,I.jsx)(n.span,{...e,ref:t,style:{...L,...e.style}}));ee.displayName=R;var z=ee;function B(e){let t=F.useRef({value:e,previous:e});return F.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}var V=`Label`,H=F.forwardRef((e,t)=>(0,I.jsx)(n.label,{...e,ref:t,onMouseDown:t=>{t.target.closest(`button, input, select, textarea`)||(e.onMouseDown?.(t),!t.defaultPrevented&&t.detail>1&&t.preventDefault())}}));H.displayName=V;var U=H,te=e(m(),1),ne=[` `,`Enter`,`ArrowUp`,`ArrowDown`],re=[` `,`Enter`],W=`Select`,[G,K,ie]=s(W),[q,ae]=i(W,[ie,S]),oe=S(),[se,J]=q(W),[ce,le]=q(W),ue=e=>{let{__scopeSelect:t,children:n,open:r,defaultOpen:i,onOpenChange:o,value:s,defaultValue:c,onValueChange:l,dir:u,name:p,autoComplete:m,disabled:h,required:g,form:_}=e,v=oe(t),[b,x]=F.useState(null),[S,C]=F.useState(null),[w,T]=F.useState(!1),E=f(u),[D,O]=a({prop:r,defaultProp:i??!1,onChange:o,caller:W}),[k,A]=a({prop:s,defaultProp:c,onChange:l,caller:W}),j=F.useRef(null),M=b?_||!!b.closest(`form`):!0,[N,P]=F.useState(new Set),L=Array.from(N).map(e=>e.props.value).join(`;`);return(0,I.jsx)(y,{...v,children:(0,I.jsxs)(se,{required:g,scope:t,trigger:b,onTriggerChange:x,valueNode:S,onValueNodeChange:C,valueNodeHasChildren:w,onValueNodeHasChildrenChange:T,contentId:d(),value:k,onValueChange:A,open:D,onOpenChange:O,dir:E,triggerPointerDownPosRef:j,disabled:h,children:[(0,I.jsx)(G.Provider,{scope:t,children:(0,I.jsx)(ce,{scope:e.__scopeSelect,onNativeOptionAdd:F.useCallback(e=>{P(t=>new Set(t).add(e))},[]),onNativeOptionRemove:F.useCallback(e=>{P(t=>{let n=new Set(t);return n.delete(e),n})},[]),children:n})}),M?(0,I.jsxs)(tt,{"aria-hidden":!0,required:g,tabIndex:-1,name:p,autoComplete:m,value:k,onChange:e=>A(e.target.value),disabled:h,form:_,children:[k===void 0?(0,I.jsx)(`option`,{value:``}):null,Array.from(N)]},L):null]})})};ue.displayName=W;var de=`SelectTrigger`,fe=F.forwardRef((e,t)=>{let{__scopeSelect:r,disabled:i=!1,...a}=e,o=oe(r),s=J(de,r),c=s.disabled||i,l=h(t,s.onTriggerChange),u=K(r),d=F.useRef(`touch`),[f,p,m]=rt(e=>{let t=u().filter(e=>!e.disabled),n=it(t,e,t.find(e=>e.value===s.value));n!==void 0&&s.onValueChange(n.value)}),g=e=>{c||(s.onOpenChange(!0),m()),e&&(s.triggerPointerDownPosRef.current={x:Math.round(e.pageX),y:Math.round(e.pageY)})};return(0,I.jsx)(x,{asChild:!0,...o,children:(0,I.jsx)(n.button,{type:`button`,role:`combobox`,"aria-controls":s.contentId,"aria-expanded":s.open,"aria-required":s.required,"aria-autocomplete":`none`,dir:s.dir,"data-state":s.open?`open`:`closed`,disabled:c,"data-disabled":c?``:void 0,"data-placeholder":nt(s.value)?``:void 0,...a,ref:l,onClick:E(a.onClick,e=>{e.currentTarget.focus(),d.current!==`mouse`&&g(e)}),onPointerDown:E(a.onPointerDown,e=>{d.current=e.pointerType;let t=e.target;t.hasPointerCapture(e.pointerId)&&t.releasePointerCapture(e.pointerId),e.button===0&&e.ctrlKey===!1&&e.pointerType===`mouse`&&(g(e),e.preventDefault())}),onKeyDown:E(a.onKeyDown,e=>{let t=f.current!==``;!(e.ctrlKey||e.altKey||e.metaKey)&&e.key.length===1&&p(e.key),!(t&&e.key===` `)&&ne.includes(e.key)&&(g(),e.preventDefault())})})})});fe.displayName=de;var pe=`SelectValue`,me=F.forwardRef((e,t)=>{let{__scopeSelect:r,className:i,style:a,children:o,placeholder:s=``,...c}=e,l=J(pe,r),{onValueNodeHasChildrenChange:u}=l,d=o!==void 0,f=h(t,l.onValueNodeChange);return T(()=>{u(d)},[u,d]),(0,I.jsx)(n.span,{...c,ref:f,style:{pointerEvents:`none`},children:nt(l.value)?(0,I.jsx)(I.Fragment,{children:s}):o})});me.displayName=pe;var he=`SelectIcon`,ge=F.forwardRef((e,t)=>{let{__scopeSelect:r,children:i,...a}=e;return(0,I.jsx)(n.span,{"aria-hidden":!0,...a,ref:t,children:i||`▼`})});ge.displayName=he;var _e=`SelectPortal`,ve=e=>(0,I.jsx)(l,{asChild:!0,...e});ve.displayName=_e;var Y=`SelectContent`,ye=F.forwardRef((e,t)=>{let n=J(Y,e.__scopeSelect),[r,i]=F.useState();if(T(()=>{i(new DocumentFragment)},[]),!n.open){let t=r;return t?te.createPortal((0,I.jsx)(be,{scope:e.__scopeSelect,children:(0,I.jsx)(G.Slot,{scope:e.__scopeSelect,children:(0,I.jsx)(`div`,{children:e.children})})}),t):null}return(0,I.jsx)(Ce,{...e,ref:t})});ye.displayName=Y;var X=10,[be,Z]=q(Y),xe=`SelectContentImpl`,Se=r(`SelectContent.RemoveScroll`),Ce=F.forwardRef((e,t)=>{let{__scopeSelect:n,position:r=`item-aligned`,onCloseAutoFocus:i,onEscapeKeyDown:a,onPointerDownOutside:o,side:s,sideOffset:l,align:d,alignOffset:f,arrowPadding:p,collisionBoundary:m,collisionPadding:_,sticky:v,hideWhenDetached:y,avoidCollisions:x,...S}=e,C=J(Y,n),[T,D]=F.useState(null),[O,k]=F.useState(null),A=h(t,e=>D(e)),[j,M]=F.useState(null),[N,P]=F.useState(null),L=K(n),[R,ee]=F.useState(!1),z=F.useRef(!1);F.useEffect(()=>{if(T)return c(T)},[T]),w();let B=F.useCallback(e=>{let[t,...n]=L().map(e=>e.ref.current),[r]=n.slice(-1),i=document.activeElement;for(let n of e)if(n===i||(n?.scrollIntoView({block:`nearest`}),n===t&&O&&(O.scrollTop=0),n===r&&O&&(O.scrollTop=O.scrollHeight),n?.focus(),document.activeElement!==i))return},[L,O]),V=F.useCallback(()=>B([j,T]),[B,j,T]);F.useEffect(()=>{R&&V()},[R,V]);let{onOpenChange:H,triggerPointerDownPosRef:U}=C;F.useEffect(()=>{if(T){let e={x:0,y:0},t=t=>{e={x:Math.abs(Math.round(t.pageX)-(U.current?.x??0)),y:Math.abs(Math.round(t.pageY)-(U.current?.y??0))}},n=n=>{e.x<=10&&e.y<=10?n.preventDefault():T.contains(n.target)||H(!1),document.removeEventListener(`pointermove`,t),U.current=null};return U.current!==null&&(document.addEventListener(`pointermove`,t),document.addEventListener(`pointerup`,n,{capture:!0,once:!0})),()=>{document.removeEventListener(`pointermove`,t),document.removeEventListener(`pointerup`,n,{capture:!0})}}},[T,H,U]),F.useEffect(()=>{let e=()=>H(!1);return window.addEventListener(`blur`,e),window.addEventListener(`resize`,e),()=>{window.removeEventListener(`blur`,e),window.removeEventListener(`resize`,e)}},[H]);let[te,ne]=rt(e=>{let t=L().filter(e=>!e.disabled),n=it(t,e,t.find(e=>e.ref.current===document.activeElement));n&&setTimeout(()=>n.ref.current.focus())}),re=F.useCallback((e,t,n)=>{let r=!z.current&&!n;(C.value!==void 0&&C.value===t||r)&&(M(e),r&&(z.current=!0))},[C.value]),W=F.useCallback(()=>T?.focus(),[T]),G=F.useCallback((e,t,n)=>{let r=!z.current&&!n;(C.value!==void 0&&C.value===t||r)&&P(e)},[C.value]),ie=r===`popper`?De:Te,q=ie===De?{side:s,sideOffset:l,align:d,alignOffset:f,arrowPadding:p,collisionBoundary:m,collisionPadding:_,sticky:v,hideWhenDetached:y,avoidCollisions:x}:{};return(0,I.jsx)(be,{scope:n,content:T,viewport:O,onViewportChange:k,itemRefCallback:re,selectedItem:j,onItemLeave:W,itemTextRefCallback:G,focusSelectedItem:V,selectedItemText:N,position:r,isPositioned:R,searchRef:te,children:(0,I.jsx)(g,{as:Se,allowPinchZoom:!0,children:(0,I.jsx)(u,{asChild:!0,trapped:C.open,onMountAutoFocus:e=>{e.preventDefault()},onUnmountAutoFocus:E(i,e=>{C.trigger?.focus({preventScroll:!0}),e.preventDefault()}),children:(0,I.jsx)(b,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:a,onPointerDownOutside:o,onFocusOutside:e=>e.preventDefault(),onDismiss:()=>C.onOpenChange(!1),children:(0,I.jsx)(ie,{role:`listbox`,id:C.contentId,"data-state":C.open?`open`:`closed`,dir:C.dir,onContextMenu:e=>e.preventDefault(),...S,...q,onPlaced:()=>ee(!0),ref:A,style:{display:`flex`,flexDirection:`column`,outline:`none`,...S.style},onKeyDown:E(S.onKeyDown,e=>{let t=e.ctrlKey||e.altKey||e.metaKey;if(e.key===`Tab`&&e.preventDefault(),!t&&e.key.length===1&&ne(e.key),[`ArrowUp`,`ArrowDown`,`Home`,`End`].includes(e.key)){let t=L().filter(e=>!e.disabled).map(e=>e.ref.current);if([`ArrowUp`,`End`].includes(e.key)&&(t=t.slice().reverse()),[`ArrowUp`,`ArrowDown`].includes(e.key)){let n=e.target,r=t.indexOf(n);t=t.slice(r+1)}setTimeout(()=>B(t)),e.preventDefault()}})})})})})})});Ce.displayName=xe;var we=`SelectItemAlignedPosition`,Te=F.forwardRef((e,t)=>{let{__scopeSelect:r,onPlaced:i,...a}=e,o=J(Y,r),s=Z(Y,r),[c,l]=F.useState(null),[u,d]=F.useState(null),f=h(t,e=>d(e)),p=K(r),m=F.useRef(!1),g=F.useRef(!0),{viewport:_,selectedItem:y,selectedItemText:b,focusSelectedItem:x}=s,S=F.useCallback(()=>{if(o.trigger&&o.valueNode&&c&&u&&_&&y&&b){let e=o.trigger.getBoundingClientRect(),t=u.getBoundingClientRect(),n=o.valueNode.getBoundingClientRect(),r=b.getBoundingClientRect();if(o.dir!==`rtl`){let i=r.left-t.left,a=n.left-i,o=e.left-a,s=e.width+o,l=Math.max(s,t.width),u=window.innerWidth-X,d=v(a,[X,Math.max(X,u-l)]);c.style.minWidth=s+`px`,c.style.left=d+`px`}else{let i=t.right-r.right,a=window.innerWidth-n.right-i,o=window.innerWidth-e.right-a,s=e.width+o,l=Math.max(s,t.width),u=window.innerWidth-X,d=v(a,[X,Math.max(X,u-l)]);c.style.minWidth=s+`px`,c.style.right=d+`px`}let a=p(),s=window.innerHeight-X*2,l=_.scrollHeight,d=window.getComputedStyle(u),f=parseInt(d.borderTopWidth,10),h=parseInt(d.paddingTop,10),g=parseInt(d.borderBottomWidth,10),x=parseInt(d.paddingBottom,10),S=f+h+l+x+g,C=Math.min(y.offsetHeight*5,S),w=window.getComputedStyle(_),T=parseInt(w.paddingTop,10),E=parseInt(w.paddingBottom,10),D=e.top+e.height/2-X,O=s-D,k=y.offsetHeight/2,A=y.offsetTop+k,j=f+h+A,M=S-j;if(j<=D){let e=a.length>0&&y===a[a.length-1].ref.current;c.style.bottom=`0px`;let t=u.clientHeight-_.offsetTop-_.offsetHeight,n=j+Math.max(O,k+(e?E:0)+t+g);c.style.height=n+`px`}else{let e=a.length>0&&y===a[0].ref.current;c.style.top=`0px`;let t=Math.max(D,f+_.offsetTop+(e?T:0)+k)+M;c.style.height=t+`px`,_.scrollTop=j-D+_.offsetTop}c.style.margin=`${X}px 0`,c.style.minHeight=C+`px`,c.style.maxHeight=s+`px`,i?.(),requestAnimationFrame(()=>m.current=!0)}},[p,o.trigger,o.valueNode,c,u,_,y,b,o.dir,i]);T(()=>S(),[S]);let[C,w]=F.useState();return T(()=>{u&&w(window.getComputedStyle(u).zIndex)},[u]),(0,I.jsx)(Oe,{scope:r,contentWrapper:c,shouldExpandOnScrollRef:m,onScrollButtonChange:F.useCallback(e=>{e&&g.current===!0&&(S(),x?.(),g.current=!1)},[S,x]),children:(0,I.jsx)(`div`,{ref:l,style:{display:`flex`,flexDirection:`column`,position:`fixed`,zIndex:C},children:(0,I.jsx)(n.div,{...a,ref:f,style:{boxSizing:`border-box`,maxHeight:`100%`,...a.style}})})})});Te.displayName=we;var Ee=`SelectPopperPosition`,De=F.forwardRef((e,t)=>{let{__scopeSelect:n,align:r=`start`,collisionPadding:i=X,...a}=e,s=oe(n);return(0,I.jsx)(o,{...s,...a,ref:t,align:r,collisionPadding:i,style:{boxSizing:`border-box`,...a.style,"--radix-select-content-transform-origin":`var(--radix-popper-transform-origin)`,"--radix-select-content-available-width":`var(--radix-popper-available-width)`,"--radix-select-content-available-height":`var(--radix-popper-available-height)`,"--radix-select-trigger-width":`var(--radix-popper-anchor-width)`,"--radix-select-trigger-height":`var(--radix-popper-anchor-height)`}})});De.displayName=Ee;var[Oe,ke]=q(Y,{}),Ae=`SelectViewport`,je=F.forwardRef((e,t)=>{let{__scopeSelect:r,nonce:i,...a}=e,o=Z(Ae,r),s=ke(Ae,r),c=h(t,o.onViewportChange),l=F.useRef(0);return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`style`,{dangerouslySetInnerHTML:{__html:`[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}`},nonce:i}),(0,I.jsx)(G.Slot,{scope:r,children:(0,I.jsx)(n.div,{"data-radix-select-viewport":``,role:`presentation`,...a,ref:c,style:{position:`relative`,flex:1,overflow:`hidden auto`,...a.style},onScroll:E(a.onScroll,e=>{let t=e.currentTarget,{contentWrapper:n,shouldExpandOnScrollRef:r}=s;if(r?.current&&n){let e=Math.abs(l.current-t.scrollTop);if(e>0){let r=window.innerHeight-X*2,i=parseFloat(n.style.minHeight),a=parseFloat(n.style.height),o=Math.max(i,a);if(o<r){let i=o+e,a=Math.min(r,i),s=i-a;n.style.height=a+`px`,n.style.bottom===`0px`&&(t.scrollTop=s>0?s:0,n.style.justifyContent=`flex-end`)}}}l.current=t.scrollTop})})})]})});je.displayName=Ae;var Me=`SelectGroup`,[Ne,Pe]=q(Me),Fe=F.forwardRef((e,t)=>{let{__scopeSelect:r,...i}=e,a=d();return(0,I.jsx)(Ne,{scope:r,id:a,children:(0,I.jsx)(n.div,{role:`group`,"aria-labelledby":a,...i,ref:t})})});Fe.displayName=Me;var Ie=`SelectLabel`,Le=F.forwardRef((e,t)=>{let{__scopeSelect:r,...i}=e,a=Pe(Ie,r);return(0,I.jsx)(n.div,{id:a.id,...i,ref:t})});Le.displayName=Ie;var Re=`SelectItem`,[ze,Be]=q(Re),Ve=F.forwardRef((e,t)=>{let{__scopeSelect:r,value:i,disabled:a=!1,textValue:o,...s}=e,c=J(Re,r),l=Z(Re,r),u=c.value===i,[f,p]=F.useState(o??``),[m,g]=F.useState(!1),_=h(t,e=>l.itemRefCallback?.(e,i,a)),v=d(),y=F.useRef(`touch`),b=()=>{a||(c.onValueChange(i),c.onOpenChange(!1))};if(i===``)throw Error(`A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.`);return(0,I.jsx)(ze,{scope:r,value:i,disabled:a,textId:v,isSelected:u,onItemTextChange:F.useCallback(e=>{p(t=>t||(e?.textContent??``).trim())},[]),children:(0,I.jsx)(G.ItemSlot,{scope:r,value:i,disabled:a,textValue:f,children:(0,I.jsx)(n.div,{role:`option`,"aria-labelledby":v,"data-highlighted":m?``:void 0,"aria-selected":u&&m,"data-state":u?`checked`:`unchecked`,"aria-disabled":a||void 0,"data-disabled":a?``:void 0,tabIndex:a?void 0:-1,...s,ref:_,onFocus:E(s.onFocus,()=>g(!0)),onBlur:E(s.onBlur,()=>g(!1)),onClick:E(s.onClick,()=>{y.current!==`mouse`&&b()}),onPointerUp:E(s.onPointerUp,()=>{y.current===`mouse`&&b()}),onPointerDown:E(s.onPointerDown,e=>{y.current=e.pointerType}),onPointerMove:E(s.onPointerMove,e=>{y.current=e.pointerType,a?l.onItemLeave?.():y.current===`mouse`&&e.currentTarget.focus({preventScroll:!0})}),onPointerLeave:E(s.onPointerLeave,e=>{e.currentTarget===document.activeElement&&l.onItemLeave?.()}),onKeyDown:E(s.onKeyDown,e=>{l.searchRef?.current!==``&&e.key===` `||(re.includes(e.key)&&b(),e.key===` `&&e.preventDefault())})})})})});Ve.displayName=Re;var Q=`SelectItemText`,He=F.forwardRef((e,t)=>{let{__scopeSelect:r,className:i,style:a,...o}=e,s=J(Q,r),c=Z(Q,r),l=Be(Q,r),u=le(Q,r),[d,f]=F.useState(null),p=h(t,e=>f(e),l.onItemTextChange,e=>c.itemTextRefCallback?.(e,l.value,l.disabled)),m=d?.textContent,g=F.useMemo(()=>(0,I.jsx)(`option`,{value:l.value,disabled:l.disabled,children:m},l.value),[l.disabled,l.value,m]),{onNativeOptionAdd:_,onNativeOptionRemove:v}=u;return T(()=>(_(g),()=>v(g)),[_,v,g]),(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(n.span,{id:l.textId,...o,ref:p}),l.isSelected&&s.valueNode&&!s.valueNodeHasChildren?te.createPortal(o.children,s.valueNode):null]})});He.displayName=Q;var Ue=`SelectItemIndicator`,We=F.forwardRef((e,t)=>{let{__scopeSelect:r,...i}=e;return Be(Ue,r).isSelected?(0,I.jsx)(n.span,{"aria-hidden":!0,...i,ref:t}):null});We.displayName=Ue;var Ge=`SelectScrollUpButton`,Ke=F.forwardRef((e,t)=>{let n=Z(Ge,e.__scopeSelect),r=ke(Ge,e.__scopeSelect),[i,a]=F.useState(!1),o=h(t,r.onScrollButtonChange);return T(()=>{if(n.viewport&&n.isPositioned){let e=function(){a(t.scrollTop>0)},t=n.viewport;return e(),t.addEventListener(`scroll`,e),()=>t.removeEventListener(`scroll`,e)}},[n.viewport,n.isPositioned]),i?(0,I.jsx)(Ye,{...e,ref:o,onAutoScroll:()=>{let{viewport:e,selectedItem:t}=n;e&&t&&(e.scrollTop-=t.offsetHeight)}}):null});Ke.displayName=Ge;var qe=`SelectScrollDownButton`,Je=F.forwardRef((e,t)=>{let n=Z(qe,e.__scopeSelect),r=ke(qe,e.__scopeSelect),[i,a]=F.useState(!1),o=h(t,r.onScrollButtonChange);return T(()=>{if(n.viewport&&n.isPositioned){let e=function(){let e=t.scrollHeight-t.clientHeight;a(Math.ceil(t.scrollTop)<e)},t=n.viewport;return e(),t.addEventListener(`scroll`,e),()=>t.removeEventListener(`scroll`,e)}},[n.viewport,n.isPositioned]),i?(0,I.jsx)(Ye,{...e,ref:o,onAutoScroll:()=>{let{viewport:e,selectedItem:t}=n;e&&t&&(e.scrollTop+=t.offsetHeight)}}):null});Je.displayName=qe;var Ye=F.forwardRef((e,t)=>{let{__scopeSelect:r,onAutoScroll:i,...a}=e,o=Z(`SelectScrollButton`,r),s=F.useRef(null),c=K(r),l=F.useCallback(()=>{s.current!==null&&(window.clearInterval(s.current),s.current=null)},[]);return F.useEffect(()=>()=>l(),[l]),T(()=>{c().find(e=>e.ref.current===document.activeElement)?.ref.current?.scrollIntoView({block:`nearest`})},[c]),(0,I.jsx)(n.div,{"aria-hidden":!0,...a,ref:t,style:{flexShrink:0,...a.style},onPointerDown:E(a.onPointerDown,()=>{s.current===null&&(s.current=window.setInterval(i,50))}),onPointerMove:E(a.onPointerMove,()=>{o.onItemLeave?.(),s.current===null&&(s.current=window.setInterval(i,50))}),onPointerLeave:E(a.onPointerLeave,()=>{l()})})}),Xe=`SelectSeparator`,Ze=F.forwardRef((e,t)=>{let{__scopeSelect:r,...i}=e;return(0,I.jsx)(n.div,{"aria-hidden":!0,...i,ref:t})});Ze.displayName=Xe;var Qe=`SelectArrow`,$e=F.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e,i=oe(n),a=J(Qe,n),o=Z(Qe,n);return a.open&&o.position===`popper`?(0,I.jsx)(p,{...i,...r,ref:t}):null});$e.displayName=Qe;var et=`SelectBubbleInput`,tt=F.forwardRef(({__scopeSelect:e,value:t,...r},i)=>{let a=F.useRef(null),o=h(i,a),s=B(t);return F.useEffect(()=>{let e=a.current;if(!e)return;let n=window.HTMLSelectElement.prototype,r=Object.getOwnPropertyDescriptor(n,`value`).set;if(s!==t&&r){let n=new Event(`change`,{bubbles:!0});r.call(e,t),e.dispatchEvent(n)}},[s,t]),(0,I.jsx)(n.select,{...r,style:{...L,...r.style},ref:o,defaultValue:t})});tt.displayName=et;function nt(e){return e===``||e===void 0}function rt(e){let t=_(e),n=F.useRef(``),r=F.useRef(0),i=F.useCallback(e=>{let i=n.current+e;t(i),(function e(t){n.current=t,window.clearTimeout(r.current),t!==``&&(r.current=window.setTimeout(()=>e(``),1e3))})(i)},[t]),a=F.useCallback(()=>{n.current=``,window.clearTimeout(r.current)},[]);return F.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,i,a]}function it(e,t,n){let r=t.length>1&&Array.from(t).every(e=>e===t[0])?t[0]:t,i=n?e.indexOf(n):-1,a=at(e,Math.max(i,0));r.length===1&&(a=a.filter(e=>e!==n));let o=a.find(e=>e.textValue.toLowerCase().startsWith(r.toLowerCase()));return o===n?void 0:o}function at(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var ot=ue,st=fe,ct=me,lt=ge,ut=ve,dt=ye,ft=je,pt=Ve,mt=He,ht=We,gt=Ke,_t=Je;function $({className:e,...t}){return(0,I.jsx)(U,{"data-slot":`label`,className:k(`flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50`,e),...t})}function vt({...e}){return(0,I.jsx)(ot,{"data-slot":`select`,...e})}function yt({...e}){return(0,I.jsx)(ct,{"data-slot":`select-value`,...e})}function bt({className:e,size:t=`default`,children:n,...r}){return(0,I.jsxs)(st,{"data-slot":`select-trigger`,"data-size":t,className:k(`flex w-fit items-center justify-between gap-2 rounded-md border border-input bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[placeholder]:text-muted-foreground data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 dark:bg-input/30 dark:hover:bg-input/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground`,e),...r,children:[n,(0,I.jsx)(lt,{asChild:!0,children:(0,I.jsx)(N,{className:`size-4 opacity-50`})})]})}function xt({className:e,children:t,position:n=`item-aligned`,align:r=`center`,...i}){return(0,I.jsx)(ut,{children:(0,I.jsxs)(dt,{"data-slot":`select-content`,className:k(`relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover text-popover-foreground shadow-md 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 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95`,n===`popper`&&`data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1`,e),position:n,align:r,...i,children:[(0,I.jsx)(Ct,{}),(0,I.jsx)(ft,{className:k(`p-1`,n===`popper`&&`h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1`),children:t}),(0,I.jsx)(wt,{})]})})}function St({className:e,children:t,...n}){return(0,I.jsxs)(pt,{"data-slot":`select-item`,className:k(`relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2`,e),...n,children:[(0,I.jsx)(`span`,{"data-slot":`select-item-indicator`,className:`absolute right-2 flex size-3.5 items-center justify-center`,children:(0,I.jsx)(ht,{children:(0,I.jsx)(M,{className:`size-4`})})}),(0,I.jsx)(mt,{children:t})]})}function Ct({className:e,...t}){return(0,I.jsx)(gt,{"data-slot":`select-scroll-up-button`,className:k(`flex cursor-default items-center justify-center py-1`,e),...t,children:(0,I.jsx)(P,{className:`size-4`})})}function wt({className:e,...t}){return(0,I.jsx)(_t,{"data-slot":`select-scroll-down-button`,className:k(`flex cursor-default items-center justify-center py-1`,e),...t,children:(0,I.jsx)(N,{className:`size-4`})})}function Tt(){return A.get(`/api/settings/ai`)}function Et(e){return A.put(`/api/settings/ai`,e)}var Dt=[{value:`claude-sonnet-4-6`,label:`Claude Sonnet 4.6`},{value:`claude-opus-4-6`,label:`Claude Opus 4.6`},{value:`claude-haiku-4-5`,label:`Claude Haiku 4.5`}],Ot=[{value:`low`,label:`Low`},{value:`medium`,label:`Medium`},{value:`high`,label:`High`}];function kt({compact:e}={}){let[t,n]=(0,F.useState)(null),[r,i]=(0,F.useState)(!1),[a,o]=(0,F.useState)(null),[s,c]=(0,F.useState)(0);(0,F.useEffect)(()=>{Tt().then(n).catch(e=>o(e.message))},[]);let l=t?.default_provider??`claude`,u=t?.providers[l],d=async(e,r)=>{if(t){i(!0),o(null);try{n(await Et({providers:{[l]:{[e]:r}}})),c(e=>e+1)}catch(e){o(e.message)}finally{i(!1)}}},f=e?`text-[11px]`:`text-sm`,p=e?`text-xs`:`text-sm`,m=e?`space-y-2`:`space-y-4`,h=e?`space-y-1.5`:`space-y-3`,g=e?`space-y-1`:`space-y-1.5`;return t?(0,I.jsxs)(`div`,{className:m,children:[(0,I.jsx)(`h3`,{className:`${p} font-medium text-text-secondary`,children:`AI Provider`}),(0,I.jsxs)(`div`,{className:h,children:[(0,I.jsxs)(`div`,{className:g,children:[(0,I.jsx)($,{htmlFor:`ai-model`,className:e?f:void 0,children:`Model`}),(0,I.jsxs)(vt,{value:u?.model??`claude-sonnet-4-6`,onValueChange:e=>d(`model`,e),children:[(0,I.jsx)(bt,{id:`ai-model`,className:`w-full ${e?`h-7 text-[11px]`:``}`,children:(0,I.jsx)(yt,{})}),(0,I.jsx)(xt,{children:Dt.map(e=>(0,I.jsx)(St,{value:e.value,children:e.label},e.value))})]})]}),(0,I.jsxs)(`div`,{className:g,children:[(0,I.jsx)($,{htmlFor:`ai-effort`,className:e?f:void 0,children:`Effort`}),(0,I.jsxs)(vt,{value:u?.effort??`high`,onValueChange:e=>d(`effort`,e),children:[(0,I.jsx)(bt,{id:`ai-effort`,className:`w-full ${e?`h-7 text-[11px]`:``}`,children:(0,I.jsx)(yt,{})}),(0,I.jsx)(xt,{children:Ot.map(e=>(0,I.jsx)(St,{value:e.value,children:e.label},e.value))})]})]}),(0,I.jsxs)(`div`,{className:g,children:[(0,I.jsx)($,{htmlFor:`ai-max-turns`,className:e?f:void 0,children:`Max Turns (1-500)`}),(0,I.jsx)(C,{id:`ai-max-turns`,type:`number`,min:1,max:500,defaultValue:u?.max_turns??100,className:e?`h-7 text-[11px]`:void 0,onBlur:e=>{let t=parseInt(e.target.value);isNaN(t)||d(`max_turns`,t)}},`turns-${s}`)]}),(0,I.jsxs)(`div`,{className:g,children:[(0,I.jsx)($,{htmlFor:`ai-budget`,className:e?f:void 0,children:`Max Budget (USD)`}),(0,I.jsx)(C,{id:`ai-budget`,type:`number`,step:.1,min:.01,max:50,defaultValue:u?.max_budget_usd??``,placeholder:`No limit`,className:e?`h-7 text-[11px]`:void 0,onBlur:e=>{let t=parseFloat(e.target.value);d(`max_budget_usd`,isNaN(t)?void 0:t)}},`budget-${s}`)]}),(0,I.jsxs)(`div`,{className:g,children:[(0,I.jsx)($,{htmlFor:`ai-thinking`,className:e?f:void 0,children:`Thinking Budget (tokens)`}),(0,I.jsx)(C,{id:`ai-thinking`,type:`number`,min:0,defaultValue:u?.thinking_budget_tokens??``,placeholder:`Disabled`,className:e?`h-7 text-[11px]`:void 0,onBlur:e=>{let t=parseInt(e.target.value);d(`thinking_budget_tokens`,isNaN(t)?void 0:t)}},`thinking-${s}`)]})]}),r&&(0,I.jsx)(`p`,{className:`text-xs text-text-subtle`,children:`Saving...`}),a&&(0,I.jsx)(`p`,{className:`text-xs text-red-500`,children:a})]}):(0,I.jsxs)(`div`,{className:h,children:[(0,I.jsx)(`h3`,{className:`${p} font-medium text-text-secondary`,children:`AI Provider`}),(0,I.jsx)(`p`,{className:`${f} text-text-subtle`,children:a?`Error: ${a}`:`Loading...`})]})}export{M as a,N as i,z as n,j as o,P as r,kt as t};
1
+ import{i as e,t}from"./react-CYzKIDNi.js";import{C as n,E as r,S as i,_ as a,a as o,b as s,c,d as l,f as u,g as d,h as f,i as p,j as m,k as h,l as g,m as _,n as v,o as y,p as b,r as x,s as S,t as C,u as w,v as T,y as E}from"./input-P_K5CUiy.js";import{n as D,t as O}from"./jsx-runtime-wQxeESYQ.js";import{n as k}from"./utils-DC-bdPS3.js";import{t as A}from"./api-client-TUmacMRS.js";var j=D(`bell-off`,[[`path`,{d:`M10.268 21a2 2 0 0 0 3.464 0`,key:`vwvbt9`}],[`path`,{d:`M17 17H4a1 1 0 0 1-.74-1.673C4.59 13.956 6 12.499 6 8a6 6 0 0 1 .258-1.742`,key:`178tsu`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M8.668 3.01A6 6 0 0 1 18 8c0 2.687.77 4.653 1.707 6.05`,key:`1hqiys`}]]),M=D(`check`,[[`path`,{d:`M20 6 9 17l-5-5`,key:`1gmf2c`}]]),N=D(`chevron-down`,[[`path`,{d:`m6 9 6 6 6-6`,key:`qrunsl`}]]),P=D(`chevron-up`,[[`path`,{d:`m18 15-6-6-6 6`,key:`153udz`}]]),F=e(t(),1),I=O(),L=Object.freeze({position:`absolute`,border:0,width:1,height:1,padding:0,margin:-1,overflow:`hidden`,clip:`rect(0, 0, 0, 0)`,whiteSpace:`nowrap`,wordWrap:`normal`}),R=`VisuallyHidden`,ee=F.forwardRef((e,t)=>(0,I.jsx)(n.span,{...e,ref:t,style:{...L,...e.style}}));ee.displayName=R;var z=ee;function B(e){let t=F.useRef({value:e,previous:e});return F.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}var V=`Label`,H=F.forwardRef((e,t)=>(0,I.jsx)(n.label,{...e,ref:t,onMouseDown:t=>{t.target.closest(`button, input, select, textarea`)||(e.onMouseDown?.(t),!t.defaultPrevented&&t.detail>1&&t.preventDefault())}}));H.displayName=V;var U=H,te=e(m(),1),ne=[` `,`Enter`,`ArrowUp`,`ArrowDown`],re=[` `,`Enter`],W=`Select`,[G,K,ie]=s(W),[q,ae]=i(W,[ie,S]),oe=S(),[se,J]=q(W),[ce,le]=q(W),ue=e=>{let{__scopeSelect:t,children:n,open:r,defaultOpen:i,onOpenChange:o,value:s,defaultValue:c,onValueChange:l,dir:u,name:p,autoComplete:m,disabled:h,required:g,form:_}=e,v=oe(t),[b,x]=F.useState(null),[S,C]=F.useState(null),[w,T]=F.useState(!1),E=f(u),[D,O]=a({prop:r,defaultProp:i??!1,onChange:o,caller:W}),[k,A]=a({prop:s,defaultProp:c,onChange:l,caller:W}),j=F.useRef(null),M=b?_||!!b.closest(`form`):!0,[N,P]=F.useState(new Set),L=Array.from(N).map(e=>e.props.value).join(`;`);return(0,I.jsx)(y,{...v,children:(0,I.jsxs)(se,{required:g,scope:t,trigger:b,onTriggerChange:x,valueNode:S,onValueNodeChange:C,valueNodeHasChildren:w,onValueNodeHasChildrenChange:T,contentId:d(),value:k,onValueChange:A,open:D,onOpenChange:O,dir:E,triggerPointerDownPosRef:j,disabled:h,children:[(0,I.jsx)(G.Provider,{scope:t,children:(0,I.jsx)(ce,{scope:e.__scopeSelect,onNativeOptionAdd:F.useCallback(e=>{P(t=>new Set(t).add(e))},[]),onNativeOptionRemove:F.useCallback(e=>{P(t=>{let n=new Set(t);return n.delete(e),n})},[]),children:n})}),M?(0,I.jsxs)(tt,{"aria-hidden":!0,required:g,tabIndex:-1,name:p,autoComplete:m,value:k,onChange:e=>A(e.target.value),disabled:h,form:_,children:[k===void 0?(0,I.jsx)(`option`,{value:``}):null,Array.from(N)]},L):null]})})};ue.displayName=W;var de=`SelectTrigger`,fe=F.forwardRef((e,t)=>{let{__scopeSelect:r,disabled:i=!1,...a}=e,o=oe(r),s=J(de,r),c=s.disabled||i,l=h(t,s.onTriggerChange),u=K(r),d=F.useRef(`touch`),[f,p,m]=rt(e=>{let t=u().filter(e=>!e.disabled),n=it(t,e,t.find(e=>e.value===s.value));n!==void 0&&s.onValueChange(n.value)}),g=e=>{c||(s.onOpenChange(!0),m()),e&&(s.triggerPointerDownPosRef.current={x:Math.round(e.pageX),y:Math.round(e.pageY)})};return(0,I.jsx)(x,{asChild:!0,...o,children:(0,I.jsx)(n.button,{type:`button`,role:`combobox`,"aria-controls":s.contentId,"aria-expanded":s.open,"aria-required":s.required,"aria-autocomplete":`none`,dir:s.dir,"data-state":s.open?`open`:`closed`,disabled:c,"data-disabled":c?``:void 0,"data-placeholder":nt(s.value)?``:void 0,...a,ref:l,onClick:E(a.onClick,e=>{e.currentTarget.focus(),d.current!==`mouse`&&g(e)}),onPointerDown:E(a.onPointerDown,e=>{d.current=e.pointerType;let t=e.target;t.hasPointerCapture(e.pointerId)&&t.releasePointerCapture(e.pointerId),e.button===0&&e.ctrlKey===!1&&e.pointerType===`mouse`&&(g(e),e.preventDefault())}),onKeyDown:E(a.onKeyDown,e=>{let t=f.current!==``;!(e.ctrlKey||e.altKey||e.metaKey)&&e.key.length===1&&p(e.key),!(t&&e.key===` `)&&ne.includes(e.key)&&(g(),e.preventDefault())})})})});fe.displayName=de;var pe=`SelectValue`,me=F.forwardRef((e,t)=>{let{__scopeSelect:r,className:i,style:a,children:o,placeholder:s=``,...c}=e,l=J(pe,r),{onValueNodeHasChildrenChange:u}=l,d=o!==void 0,f=h(t,l.onValueNodeChange);return T(()=>{u(d)},[u,d]),(0,I.jsx)(n.span,{...c,ref:f,style:{pointerEvents:`none`},children:nt(l.value)?(0,I.jsx)(I.Fragment,{children:s}):o})});me.displayName=pe;var he=`SelectIcon`,ge=F.forwardRef((e,t)=>{let{__scopeSelect:r,children:i,...a}=e;return(0,I.jsx)(n.span,{"aria-hidden":!0,...a,ref:t,children:i||`▼`})});ge.displayName=he;var _e=`SelectPortal`,ve=e=>(0,I.jsx)(l,{asChild:!0,...e});ve.displayName=_e;var Y=`SelectContent`,ye=F.forwardRef((e,t)=>{let n=J(Y,e.__scopeSelect),[r,i]=F.useState();if(T(()=>{i(new DocumentFragment)},[]),!n.open){let t=r;return t?te.createPortal((0,I.jsx)(be,{scope:e.__scopeSelect,children:(0,I.jsx)(G.Slot,{scope:e.__scopeSelect,children:(0,I.jsx)(`div`,{children:e.children})})}),t):null}return(0,I.jsx)(Ce,{...e,ref:t})});ye.displayName=Y;var X=10,[be,Z]=q(Y),xe=`SelectContentImpl`,Se=r(`SelectContent.RemoveScroll`),Ce=F.forwardRef((e,t)=>{let{__scopeSelect:n,position:r=`item-aligned`,onCloseAutoFocus:i,onEscapeKeyDown:a,onPointerDownOutside:o,side:s,sideOffset:l,align:d,alignOffset:f,arrowPadding:p,collisionBoundary:m,collisionPadding:_,sticky:v,hideWhenDetached:y,avoidCollisions:x,...S}=e,C=J(Y,n),[T,D]=F.useState(null),[O,k]=F.useState(null),A=h(t,e=>D(e)),[j,M]=F.useState(null),[N,P]=F.useState(null),L=K(n),[R,ee]=F.useState(!1),z=F.useRef(!1);F.useEffect(()=>{if(T)return c(T)},[T]),w();let B=F.useCallback(e=>{let[t,...n]=L().map(e=>e.ref.current),[r]=n.slice(-1),i=document.activeElement;for(let n of e)if(n===i||(n?.scrollIntoView({block:`nearest`}),n===t&&O&&(O.scrollTop=0),n===r&&O&&(O.scrollTop=O.scrollHeight),n?.focus(),document.activeElement!==i))return},[L,O]),V=F.useCallback(()=>B([j,T]),[B,j,T]);F.useEffect(()=>{R&&V()},[R,V]);let{onOpenChange:H,triggerPointerDownPosRef:U}=C;F.useEffect(()=>{if(T){let e={x:0,y:0},t=t=>{e={x:Math.abs(Math.round(t.pageX)-(U.current?.x??0)),y:Math.abs(Math.round(t.pageY)-(U.current?.y??0))}},n=n=>{e.x<=10&&e.y<=10?n.preventDefault():T.contains(n.target)||H(!1),document.removeEventListener(`pointermove`,t),U.current=null};return U.current!==null&&(document.addEventListener(`pointermove`,t),document.addEventListener(`pointerup`,n,{capture:!0,once:!0})),()=>{document.removeEventListener(`pointermove`,t),document.removeEventListener(`pointerup`,n,{capture:!0})}}},[T,H,U]),F.useEffect(()=>{let e=()=>H(!1);return window.addEventListener(`blur`,e),window.addEventListener(`resize`,e),()=>{window.removeEventListener(`blur`,e),window.removeEventListener(`resize`,e)}},[H]);let[te,ne]=rt(e=>{let t=L().filter(e=>!e.disabled),n=it(t,e,t.find(e=>e.ref.current===document.activeElement));n&&setTimeout(()=>n.ref.current.focus())}),re=F.useCallback((e,t,n)=>{let r=!z.current&&!n;(C.value!==void 0&&C.value===t||r)&&(M(e),r&&(z.current=!0))},[C.value]),W=F.useCallback(()=>T?.focus(),[T]),G=F.useCallback((e,t,n)=>{let r=!z.current&&!n;(C.value!==void 0&&C.value===t||r)&&P(e)},[C.value]),ie=r===`popper`?De:Te,q=ie===De?{side:s,sideOffset:l,align:d,alignOffset:f,arrowPadding:p,collisionBoundary:m,collisionPadding:_,sticky:v,hideWhenDetached:y,avoidCollisions:x}:{};return(0,I.jsx)(be,{scope:n,content:T,viewport:O,onViewportChange:k,itemRefCallback:re,selectedItem:j,onItemLeave:W,itemTextRefCallback:G,focusSelectedItem:V,selectedItemText:N,position:r,isPositioned:R,searchRef:te,children:(0,I.jsx)(g,{as:Se,allowPinchZoom:!0,children:(0,I.jsx)(u,{asChild:!0,trapped:C.open,onMountAutoFocus:e=>{e.preventDefault()},onUnmountAutoFocus:E(i,e=>{C.trigger?.focus({preventScroll:!0}),e.preventDefault()}),children:(0,I.jsx)(b,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:a,onPointerDownOutside:o,onFocusOutside:e=>e.preventDefault(),onDismiss:()=>C.onOpenChange(!1),children:(0,I.jsx)(ie,{role:`listbox`,id:C.contentId,"data-state":C.open?`open`:`closed`,dir:C.dir,onContextMenu:e=>e.preventDefault(),...S,...q,onPlaced:()=>ee(!0),ref:A,style:{display:`flex`,flexDirection:`column`,outline:`none`,...S.style},onKeyDown:E(S.onKeyDown,e=>{let t=e.ctrlKey||e.altKey||e.metaKey;if(e.key===`Tab`&&e.preventDefault(),!t&&e.key.length===1&&ne(e.key),[`ArrowUp`,`ArrowDown`,`Home`,`End`].includes(e.key)){let t=L().filter(e=>!e.disabled).map(e=>e.ref.current);if([`ArrowUp`,`End`].includes(e.key)&&(t=t.slice().reverse()),[`ArrowUp`,`ArrowDown`].includes(e.key)){let n=e.target,r=t.indexOf(n);t=t.slice(r+1)}setTimeout(()=>B(t)),e.preventDefault()}})})})})})})});Ce.displayName=xe;var we=`SelectItemAlignedPosition`,Te=F.forwardRef((e,t)=>{let{__scopeSelect:r,onPlaced:i,...a}=e,o=J(Y,r),s=Z(Y,r),[c,l]=F.useState(null),[u,d]=F.useState(null),f=h(t,e=>d(e)),p=K(r),m=F.useRef(!1),g=F.useRef(!0),{viewport:_,selectedItem:y,selectedItemText:b,focusSelectedItem:x}=s,S=F.useCallback(()=>{if(o.trigger&&o.valueNode&&c&&u&&_&&y&&b){let e=o.trigger.getBoundingClientRect(),t=u.getBoundingClientRect(),n=o.valueNode.getBoundingClientRect(),r=b.getBoundingClientRect();if(o.dir!==`rtl`){let i=r.left-t.left,a=n.left-i,o=e.left-a,s=e.width+o,l=Math.max(s,t.width),u=window.innerWidth-X,d=v(a,[X,Math.max(X,u-l)]);c.style.minWidth=s+`px`,c.style.left=d+`px`}else{let i=t.right-r.right,a=window.innerWidth-n.right-i,o=window.innerWidth-e.right-a,s=e.width+o,l=Math.max(s,t.width),u=window.innerWidth-X,d=v(a,[X,Math.max(X,u-l)]);c.style.minWidth=s+`px`,c.style.right=d+`px`}let a=p(),s=window.innerHeight-X*2,l=_.scrollHeight,d=window.getComputedStyle(u),f=parseInt(d.borderTopWidth,10),h=parseInt(d.paddingTop,10),g=parseInt(d.borderBottomWidth,10),x=parseInt(d.paddingBottom,10),S=f+h+l+x+g,C=Math.min(y.offsetHeight*5,S),w=window.getComputedStyle(_),T=parseInt(w.paddingTop,10),E=parseInt(w.paddingBottom,10),D=e.top+e.height/2-X,O=s-D,k=y.offsetHeight/2,A=y.offsetTop+k,j=f+h+A,M=S-j;if(j<=D){let e=a.length>0&&y===a[a.length-1].ref.current;c.style.bottom=`0px`;let t=u.clientHeight-_.offsetTop-_.offsetHeight,n=j+Math.max(O,k+(e?E:0)+t+g);c.style.height=n+`px`}else{let e=a.length>0&&y===a[0].ref.current;c.style.top=`0px`;let t=Math.max(D,f+_.offsetTop+(e?T:0)+k)+M;c.style.height=t+`px`,_.scrollTop=j-D+_.offsetTop}c.style.margin=`${X}px 0`,c.style.minHeight=C+`px`,c.style.maxHeight=s+`px`,i?.(),requestAnimationFrame(()=>m.current=!0)}},[p,o.trigger,o.valueNode,c,u,_,y,b,o.dir,i]);T(()=>S(),[S]);let[C,w]=F.useState();return T(()=>{u&&w(window.getComputedStyle(u).zIndex)},[u]),(0,I.jsx)(Oe,{scope:r,contentWrapper:c,shouldExpandOnScrollRef:m,onScrollButtonChange:F.useCallback(e=>{e&&g.current===!0&&(S(),x?.(),g.current=!1)},[S,x]),children:(0,I.jsx)(`div`,{ref:l,style:{display:`flex`,flexDirection:`column`,position:`fixed`,zIndex:C},children:(0,I.jsx)(n.div,{...a,ref:f,style:{boxSizing:`border-box`,maxHeight:`100%`,...a.style}})})})});Te.displayName=we;var Ee=`SelectPopperPosition`,De=F.forwardRef((e,t)=>{let{__scopeSelect:n,align:r=`start`,collisionPadding:i=X,...a}=e,s=oe(n);return(0,I.jsx)(o,{...s,...a,ref:t,align:r,collisionPadding:i,style:{boxSizing:`border-box`,...a.style,"--radix-select-content-transform-origin":`var(--radix-popper-transform-origin)`,"--radix-select-content-available-width":`var(--radix-popper-available-width)`,"--radix-select-content-available-height":`var(--radix-popper-available-height)`,"--radix-select-trigger-width":`var(--radix-popper-anchor-width)`,"--radix-select-trigger-height":`var(--radix-popper-anchor-height)`}})});De.displayName=Ee;var[Oe,ke]=q(Y,{}),Ae=`SelectViewport`,je=F.forwardRef((e,t)=>{let{__scopeSelect:r,nonce:i,...a}=e,o=Z(Ae,r),s=ke(Ae,r),c=h(t,o.onViewportChange),l=F.useRef(0);return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`style`,{dangerouslySetInnerHTML:{__html:`[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}`},nonce:i}),(0,I.jsx)(G.Slot,{scope:r,children:(0,I.jsx)(n.div,{"data-radix-select-viewport":``,role:`presentation`,...a,ref:c,style:{position:`relative`,flex:1,overflow:`hidden auto`,...a.style},onScroll:E(a.onScroll,e=>{let t=e.currentTarget,{contentWrapper:n,shouldExpandOnScrollRef:r}=s;if(r?.current&&n){let e=Math.abs(l.current-t.scrollTop);if(e>0){let r=window.innerHeight-X*2,i=parseFloat(n.style.minHeight),a=parseFloat(n.style.height),o=Math.max(i,a);if(o<r){let i=o+e,a=Math.min(r,i),s=i-a;n.style.height=a+`px`,n.style.bottom===`0px`&&(t.scrollTop=s>0?s:0,n.style.justifyContent=`flex-end`)}}}l.current=t.scrollTop})})})]})});je.displayName=Ae;var Me=`SelectGroup`,[Ne,Pe]=q(Me),Fe=F.forwardRef((e,t)=>{let{__scopeSelect:r,...i}=e,a=d();return(0,I.jsx)(Ne,{scope:r,id:a,children:(0,I.jsx)(n.div,{role:`group`,"aria-labelledby":a,...i,ref:t})})});Fe.displayName=Me;var Ie=`SelectLabel`,Le=F.forwardRef((e,t)=>{let{__scopeSelect:r,...i}=e,a=Pe(Ie,r);return(0,I.jsx)(n.div,{id:a.id,...i,ref:t})});Le.displayName=Ie;var Re=`SelectItem`,[ze,Be]=q(Re),Ve=F.forwardRef((e,t)=>{let{__scopeSelect:r,value:i,disabled:a=!1,textValue:o,...s}=e,c=J(Re,r),l=Z(Re,r),u=c.value===i,[f,p]=F.useState(o??``),[m,g]=F.useState(!1),_=h(t,e=>l.itemRefCallback?.(e,i,a)),v=d(),y=F.useRef(`touch`),b=()=>{a||(c.onValueChange(i),c.onOpenChange(!1))};if(i===``)throw Error(`A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.`);return(0,I.jsx)(ze,{scope:r,value:i,disabled:a,textId:v,isSelected:u,onItemTextChange:F.useCallback(e=>{p(t=>t||(e?.textContent??``).trim())},[]),children:(0,I.jsx)(G.ItemSlot,{scope:r,value:i,disabled:a,textValue:f,children:(0,I.jsx)(n.div,{role:`option`,"aria-labelledby":v,"data-highlighted":m?``:void 0,"aria-selected":u&&m,"data-state":u?`checked`:`unchecked`,"aria-disabled":a||void 0,"data-disabled":a?``:void 0,tabIndex:a?void 0:-1,...s,ref:_,onFocus:E(s.onFocus,()=>g(!0)),onBlur:E(s.onBlur,()=>g(!1)),onClick:E(s.onClick,()=>{y.current!==`mouse`&&b()}),onPointerUp:E(s.onPointerUp,()=>{y.current===`mouse`&&b()}),onPointerDown:E(s.onPointerDown,e=>{y.current=e.pointerType}),onPointerMove:E(s.onPointerMove,e=>{y.current=e.pointerType,a?l.onItemLeave?.():y.current===`mouse`&&e.currentTarget.focus({preventScroll:!0})}),onPointerLeave:E(s.onPointerLeave,e=>{e.currentTarget===document.activeElement&&l.onItemLeave?.()}),onKeyDown:E(s.onKeyDown,e=>{l.searchRef?.current!==``&&e.key===` `||(re.includes(e.key)&&b(),e.key===` `&&e.preventDefault())})})})})});Ve.displayName=Re;var Q=`SelectItemText`,He=F.forwardRef((e,t)=>{let{__scopeSelect:r,className:i,style:a,...o}=e,s=J(Q,r),c=Z(Q,r),l=Be(Q,r),u=le(Q,r),[d,f]=F.useState(null),p=h(t,e=>f(e),l.onItemTextChange,e=>c.itemTextRefCallback?.(e,l.value,l.disabled)),m=d?.textContent,g=F.useMemo(()=>(0,I.jsx)(`option`,{value:l.value,disabled:l.disabled,children:m},l.value),[l.disabled,l.value,m]),{onNativeOptionAdd:_,onNativeOptionRemove:v}=u;return T(()=>(_(g),()=>v(g)),[_,v,g]),(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(n.span,{id:l.textId,...o,ref:p}),l.isSelected&&s.valueNode&&!s.valueNodeHasChildren?te.createPortal(o.children,s.valueNode):null]})});He.displayName=Q;var Ue=`SelectItemIndicator`,We=F.forwardRef((e,t)=>{let{__scopeSelect:r,...i}=e;return Be(Ue,r).isSelected?(0,I.jsx)(n.span,{"aria-hidden":!0,...i,ref:t}):null});We.displayName=Ue;var Ge=`SelectScrollUpButton`,Ke=F.forwardRef((e,t)=>{let n=Z(Ge,e.__scopeSelect),r=ke(Ge,e.__scopeSelect),[i,a]=F.useState(!1),o=h(t,r.onScrollButtonChange);return T(()=>{if(n.viewport&&n.isPositioned){let e=function(){a(t.scrollTop>0)},t=n.viewport;return e(),t.addEventListener(`scroll`,e),()=>t.removeEventListener(`scroll`,e)}},[n.viewport,n.isPositioned]),i?(0,I.jsx)(Ye,{...e,ref:o,onAutoScroll:()=>{let{viewport:e,selectedItem:t}=n;e&&t&&(e.scrollTop-=t.offsetHeight)}}):null});Ke.displayName=Ge;var qe=`SelectScrollDownButton`,Je=F.forwardRef((e,t)=>{let n=Z(qe,e.__scopeSelect),r=ke(qe,e.__scopeSelect),[i,a]=F.useState(!1),o=h(t,r.onScrollButtonChange);return T(()=>{if(n.viewport&&n.isPositioned){let e=function(){let e=t.scrollHeight-t.clientHeight;a(Math.ceil(t.scrollTop)<e)},t=n.viewport;return e(),t.addEventListener(`scroll`,e),()=>t.removeEventListener(`scroll`,e)}},[n.viewport,n.isPositioned]),i?(0,I.jsx)(Ye,{...e,ref:o,onAutoScroll:()=>{let{viewport:e,selectedItem:t}=n;e&&t&&(e.scrollTop+=t.offsetHeight)}}):null});Je.displayName=qe;var Ye=F.forwardRef((e,t)=>{let{__scopeSelect:r,onAutoScroll:i,...a}=e,o=Z(`SelectScrollButton`,r),s=F.useRef(null),c=K(r),l=F.useCallback(()=>{s.current!==null&&(window.clearInterval(s.current),s.current=null)},[]);return F.useEffect(()=>()=>l(),[l]),T(()=>{c().find(e=>e.ref.current===document.activeElement)?.ref.current?.scrollIntoView({block:`nearest`})},[c]),(0,I.jsx)(n.div,{"aria-hidden":!0,...a,ref:t,style:{flexShrink:0,...a.style},onPointerDown:E(a.onPointerDown,()=>{s.current===null&&(s.current=window.setInterval(i,50))}),onPointerMove:E(a.onPointerMove,()=>{o.onItemLeave?.(),s.current===null&&(s.current=window.setInterval(i,50))}),onPointerLeave:E(a.onPointerLeave,()=>{l()})})}),Xe=`SelectSeparator`,Ze=F.forwardRef((e,t)=>{let{__scopeSelect:r,...i}=e;return(0,I.jsx)(n.div,{"aria-hidden":!0,...i,ref:t})});Ze.displayName=Xe;var Qe=`SelectArrow`,$e=F.forwardRef((e,t)=>{let{__scopeSelect:n,...r}=e,i=oe(n),a=J(Qe,n),o=Z(Qe,n);return a.open&&o.position===`popper`?(0,I.jsx)(p,{...i,...r,ref:t}):null});$e.displayName=Qe;var et=`SelectBubbleInput`,tt=F.forwardRef(({__scopeSelect:e,value:t,...r},i)=>{let a=F.useRef(null),o=h(i,a),s=B(t);return F.useEffect(()=>{let e=a.current;if(!e)return;let n=window.HTMLSelectElement.prototype,r=Object.getOwnPropertyDescriptor(n,`value`).set;if(s!==t&&r){let n=new Event(`change`,{bubbles:!0});r.call(e,t),e.dispatchEvent(n)}},[s,t]),(0,I.jsx)(n.select,{...r,style:{...L,...r.style},ref:o,defaultValue:t})});tt.displayName=et;function nt(e){return e===``||e===void 0}function rt(e){let t=_(e),n=F.useRef(``),r=F.useRef(0),i=F.useCallback(e=>{let i=n.current+e;t(i),(function e(t){n.current=t,window.clearTimeout(r.current),t!==``&&(r.current=window.setTimeout(()=>e(``),1e3))})(i)},[t]),a=F.useCallback(()=>{n.current=``,window.clearTimeout(r.current)},[]);return F.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,i,a]}function it(e,t,n){let r=t.length>1&&Array.from(t).every(e=>e===t[0])?t[0]:t,i=n?e.indexOf(n):-1,a=at(e,Math.max(i,0));r.length===1&&(a=a.filter(e=>e!==n));let o=a.find(e=>e.textValue.toLowerCase().startsWith(r.toLowerCase()));return o===n?void 0:o}function at(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var ot=ue,st=fe,ct=me,lt=ge,ut=ve,dt=ye,ft=je,pt=Ve,mt=He,ht=We,gt=Ke,_t=Je;function $({className:e,...t}){return(0,I.jsx)(U,{"data-slot":`label`,className:k(`flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50`,e),...t})}function vt({...e}){return(0,I.jsx)(ot,{"data-slot":`select`,...e})}function yt({...e}){return(0,I.jsx)(ct,{"data-slot":`select-value`,...e})}function bt({className:e,size:t=`default`,children:n,...r}){return(0,I.jsxs)(st,{"data-slot":`select-trigger`,"data-size":t,className:k(`flex w-fit items-center justify-between gap-2 rounded-md border border-input bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[placeholder]:text-muted-foreground data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 dark:bg-input/30 dark:hover:bg-input/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground`,e),...r,children:[n,(0,I.jsx)(lt,{asChild:!0,children:(0,I.jsx)(N,{className:`size-4 opacity-50`})})]})}function xt({className:e,children:t,position:n=`item-aligned`,align:r=`center`,...i}){return(0,I.jsx)(ut,{children:(0,I.jsxs)(dt,{"data-slot":`select-content`,className:k(`relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover text-popover-foreground shadow-md 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 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95`,n===`popper`&&`data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1`,e),position:n,align:r,...i,children:[(0,I.jsx)(Ct,{}),(0,I.jsx)(ft,{className:k(`p-1`,n===`popper`&&`h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1`),children:t}),(0,I.jsx)(wt,{})]})})}function St({className:e,children:t,...n}){return(0,I.jsxs)(pt,{"data-slot":`select-item`,className:k(`relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2`,e),...n,children:[(0,I.jsx)(`span`,{"data-slot":`select-item-indicator`,className:`absolute right-2 flex size-3.5 items-center justify-center`,children:(0,I.jsx)(ht,{children:(0,I.jsx)(M,{className:`size-4`})})}),(0,I.jsx)(mt,{children:t})]})}function Ct({className:e,...t}){return(0,I.jsx)(gt,{"data-slot":`select-scroll-up-button`,className:k(`flex cursor-default items-center justify-center py-1`,e),...t,children:(0,I.jsx)(P,{className:`size-4`})})}function wt({className:e,...t}){return(0,I.jsx)(_t,{"data-slot":`select-scroll-down-button`,className:k(`flex cursor-default items-center justify-center py-1`,e),...t,children:(0,I.jsx)(N,{className:`size-4`})})}function Tt(){return A.get(`/api/settings/ai`)}function Et(e){return A.put(`/api/settings/ai`,e)}var Dt=[{value:`claude-sonnet-4-6`,label:`Claude Sonnet 4.6`},{value:`claude-opus-4-6`,label:`Claude Opus 4.6`},{value:`claude-haiku-4-5`,label:`Claude Haiku 4.5`}],Ot=[{value:`low`,label:`Low`},{value:`medium`,label:`Medium`},{value:`high`,label:`High`}];function kt({compact:e}={}){let[t,n]=(0,F.useState)(null),[r,i]=(0,F.useState)(!1),[a,o]=(0,F.useState)(null),[s,c]=(0,F.useState)(0);(0,F.useEffect)(()=>{Tt().then(n).catch(e=>o(e.message))},[]);let l=t?.default_provider??`claude`,u=t?.providers[l],d=async(e,r)=>{if(t){i(!0),o(null);try{n(await Et({providers:{[l]:{[e]:r}}})),c(e=>e+1)}catch(e){o(e.message)}finally{i(!1)}}},f=e?`text-[11px]`:`text-sm`,p=e?`text-xs`:`text-sm`,m=e?`space-y-2`:`space-y-4`,h=e?`space-y-1.5`:`space-y-3`,g=e?`space-y-1`:`space-y-1.5`;return t?(0,I.jsxs)(`div`,{className:m,children:[(0,I.jsx)(`h3`,{className:`${p} font-medium text-text-secondary`,children:`AI Provider`}),(0,I.jsxs)(`div`,{className:h,children:[(0,I.jsxs)(`div`,{className:g,children:[(0,I.jsx)($,{htmlFor:`ai-model`,className:e?f:void 0,children:`Model`}),(0,I.jsxs)(vt,{value:u?.model??`claude-sonnet-4-6`,onValueChange:e=>d(`model`,e),children:[(0,I.jsx)(bt,{id:`ai-model`,className:`w-full ${e?`h-7 text-[11px]`:``}`,children:(0,I.jsx)(yt,{})}),(0,I.jsx)(xt,{children:Dt.map(e=>(0,I.jsx)(St,{value:e.value,children:e.label},e.value))})]})]}),(0,I.jsxs)(`div`,{className:g,children:[(0,I.jsx)($,{htmlFor:`ai-effort`,className:e?f:void 0,children:`Effort`}),(0,I.jsxs)(vt,{value:u?.effort??`high`,onValueChange:e=>d(`effort`,e),children:[(0,I.jsx)(bt,{id:`ai-effort`,className:`w-full ${e?`h-7 text-[11px]`:``}`,children:(0,I.jsx)(yt,{})}),(0,I.jsx)(xt,{children:Ot.map(e=>(0,I.jsx)(St,{value:e.value,children:e.label},e.value))})]})]}),(0,I.jsxs)(`div`,{className:g,children:[(0,I.jsx)($,{htmlFor:`ai-max-turns`,className:e?f:void 0,children:`Max Turns (1-500)`}),(0,I.jsx)(C,{id:`ai-max-turns`,type:`number`,min:1,max:500,defaultValue:u?.max_turns??100,className:e?`h-7 text-[11px]`:void 0,onBlur:e=>{let t=parseInt(e.target.value);isNaN(t)||d(`max_turns`,t)}},`turns-${s}`)]}),(0,I.jsxs)(`div`,{className:g,children:[(0,I.jsx)($,{htmlFor:`ai-budget`,className:e?f:void 0,children:`Max Budget (USD)`}),(0,I.jsx)(C,{id:`ai-budget`,type:`number`,step:.1,min:.01,max:50,defaultValue:u?.max_budget_usd??``,placeholder:`No limit`,className:e?`h-7 text-[11px]`:void 0,onBlur:e=>{let t=parseFloat(e.target.value);d(`max_budget_usd`,isNaN(t)?void 0:t)}},`budget-${s}`)]}),(0,I.jsxs)(`div`,{className:g,children:[(0,I.jsx)($,{htmlFor:`ai-thinking`,className:e?f:void 0,children:`Thinking Budget (tokens)`}),(0,I.jsx)(C,{id:`ai-thinking`,type:`number`,min:0,defaultValue:u?.thinking_budget_tokens??``,placeholder:`Disabled`,className:e?`h-7 text-[11px]`:void 0,onBlur:e=>{let t=parseInt(e.target.value);d(`thinking_budget_tokens`,isNaN(t)?void 0:t)}},`thinking-${s}`)]})]}),r&&(0,I.jsx)(`p`,{className:`text-xs text-text-subtle`,children:`Saving...`}),a&&(0,I.jsx)(`p`,{className:`text-xs text-red-500`,children:a})]}):(0,I.jsxs)(`div`,{className:h,children:[(0,I.jsx)(`h3`,{className:`${p} font-medium text-text-secondary`,children:`AI Provider`}),(0,I.jsx)(`p`,{className:`${f} text-text-subtle`,children:a?`Error: ${a}`:`Loading...`})]})}export{M as a,N as i,z as n,j as o,P as r,kt as t};
@@ -1,7 +1,7 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/api-client-B0aMOJxF.js","assets/react-CYzKIDNi.js"])))=>i.map(i=>d[i]);
2
- import{i as e,t}from"./react-CYzKIDNi.js";import{A as n}from"./input-BpFvhpT8.js";import{n as r,t as i}from"./jsx-runtime-wQxeESYQ.js";import{a,i as o,o as s,t as c}from"./ai-settings-section-CBpXqM-I.js";import{a as l,n as u,t as d}from"./tab-store-D7tRt0VT.js";import{n as f}from"./settings-store-DS-ifJ7c.js";import{r as p,t as m}from"./utils-DBpa1UZX.js";import{i as h,r as g,t as _}from"./api-client-B0aMOJxF.js";import{A as v,B as y,C as b,D as x,E as S,F as C,H as w,N as T,O as E,P as D,S as O,T as k,V as A,g as j,h as M,k as N,t as P}from"./index-B9ZHWVob.js";import{t as F}from"./markdown-renderer-DKVNZXEw.js";var I=r(`activity`,[[`path`,{d:`M22 12h-2.48a2 2 0 0 0-1.93 1.46l-2.35 8.36a.25.25 0 0 1-.48 0L9.24 2.18a.25.25 0 0 0-.48 0l-2.35 8.36A2 2 0 0 1 4.49 12H2`,key:`169zse`}]]),L=r(`arrow-up`,[[`path`,{d:`m5 12 7-7 7 7`,key:`hav0vg`}],[`path`,{d:`M12 19V5`,key:`x0mq9r`}]]),R=r(`bot`,[[`path`,{d:`M12 8V4H8`,key:`hb8ula`}],[`rect`,{width:`16`,height:`12`,x:`4`,y:`8`,rx:`2`,key:`enze0r`}],[`path`,{d:`M2 14h2`,key:`vft8re`}],[`path`,{d:`M20 14h2`,key:`4cs60a`}],[`path`,{d:`M15 13v2`,key:`1xurst`}],[`path`,{d:`M9 13v2`,key:`rq6x2g`}]]),z=r(`circle-x`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m15 9-6 6`,key:`1uzhvr`}],[`path`,{d:`m9 9 6 6`,key:`z0biqf`}]]),B=r(`code`,[[`path`,{d:`m16 18 6-6-6-6`,key:`eg8j8`}],[`path`,{d:`m8 6-6 6 6 6`,key:`ppft3o`}]]),V=r(`columns-2`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M12 3v18`,key:`108xh3`}]]),H=r(`globe`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20`,key:`13o1zl`}],[`path`,{d:`M2 12h20`,key:`9i4pu4`}]]),ee=r(`history`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}],[`path`,{d:`M12 7v5l4 2`,key:`1fdv2h`}]]),U=r(`image`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,ry:`2`,key:`1m3agn`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}],[`path`,{d:`m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21`,key:`1xmnt7`}]]),W=r(`list-todo`,[[`path`,{d:`M13 5h8`,key:`a7qcls`}],[`path`,{d:`M13 12h8`,key:`h98zly`}],[`path`,{d:`M13 19h8`,key:`c3s6r1`}],[`path`,{d:`m3 17 2 2 4-4`,key:`1jhpwq`}],[`rect`,{x:`3`,y:`4`,width:`6`,height:`6`,rx:`1`,key:`cif1o7`}]]),G=r(`paperclip`,[[`path`,{d:`m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551`,key:`1miecu`}]]),te=r(`settings-2`,[[`path`,{d:`M14 17H5`,key:`gfn3mx`}],[`path`,{d:`M19 7h-9`,key:`6i9tg`}],[`circle`,{cx:`17`,cy:`17`,r:`3`,key:`18b49y`}],[`circle`,{cx:`7`,cy:`7`,r:`3`,key:`dfmy0x`}]]),ne=r(`shield-alert`,[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`M12 8v4`,key:`1got3b`}],[`path`,{d:`M12 16h.01`,key:`1drbdi`}]]),re=r(`sparkles`,[[`path`,{d:`M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594z`,key:`1s2grr`}],[`path`,{d:`M20 2v4`,key:`1rf3ol`}],[`path`,{d:`M22 4h-4`,key:`gwowj6`}],[`circle`,{cx:`4`,cy:`20`,r:`2`,key:`6kqj1y`}]]),K=r(`square`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]),q=e(t(),1),J=3e4,Y=1e3,ie=class{ws=null;url;handlers=[];reconnectAttempts=0;reconnectTimer=null;intentionalClose=!1;constructor(e){this.url=e}connect(){this.intentionalClose=!1,this.cleanup();let e=window.location.protocol===`https:`?`wss:`:`ws:`,t=this.url.startsWith(`ws`)?this.url:`${e}//${window.location.host}${this.url}`;this.ws=new WebSocket(t),this.ws.onopen=()=>{this.reconnectAttempts=0;try{this.ws?.send(JSON.stringify({type:`ready`}))}catch{}},this.ws.onmessage=e=>{for(let t of this.handlers)t(e)},this.ws.onclose=()=>{this.intentionalClose||this.scheduleReconnect()},this.ws.onerror=()=>{this.ws?.close()}}disconnect(){this.intentionalClose=!0,this.cleanup(),this.reconnectTimer&&=(clearTimeout(this.reconnectTimer),null)}send(e){this.ws?.readyState===WebSocket.OPEN&&this.ws.send(e)}onMessage(e){return this.handlers.push(e),()=>{this.handlers=this.handlers.filter(t=>t!==e)}}get isConnected(){return this.ws?.readyState===WebSocket.OPEN}cleanup(){this.ws&&=(this.ws.onopen=null,this.ws.onclose=null,this.ws.onmessage=null,this.ws.onerror=null,(this.ws.readyState===WebSocket.OPEN||this.ws.readyState===WebSocket.CONNECTING)&&this.ws.close(),null)}scheduleReconnect(){let e=Math.min(Y*2**this.reconnectAttempts,J);this.reconnectAttempts++,this.reconnectTimer=setTimeout(()=>this.connect(),e)}};function ae({url:e,onMessage:t,autoConnect:n=!0}){let r=(0,q.useRef)(null);return(0,q.useEffect)(()=>{let i=new ie(e);return r.current=i,t&&i.onMessage(t),n&&i.connect(),()=>{i.disconnect(),r.current=null}},[e,n]),{send:(0,q.useCallback)(e=>{r.current?.send(e)},[]),connect:(0,q.useCallback)(()=>{r.current?.connect()},[]),disconnect:(0,q.useCallback)(()=>{r.current?.disconnect()},[])}}var oe=null;function X(){return oe||=new AudioContext,oe}function Z(e,t,n,r,i=`sine`){let a=X(),o=a.createOscillator(),s=a.createGain();o.type=i,o.frequency.value=e,s.gain.setValueAtTime(r,n),s.gain.exponentialRampToValueAtTime(.001,n+t),o.connect(s),s.connect(a.destination),o.start(n),o.stop(n+t)}function se(){let e=X().currentTime;Z(523,.15,e,.15),Z(659,.2,e+.12,.15)}function ce(){let e=X().currentTime;Z(880,.12,e,.18,`square`),Z(698,.12,e+.15,.18,`square`),Z(880,.15,e+.3,.15,`square`)}function le(){let e=X().currentTime;Z(440,.12,e,.12),Z(523,.12,e+.1,.12),Z(659,.18,e+.2,.12)}var ue={done:se,approval_request:ce,question:le};function de(e){try{ue[e]?.()}catch{}}function fe(e){if(document.hidden)return!1;let{panels:t,focusedPanelId:n}=u.getState(),r=t[n];if(!r)return!1;let i=r.tabs.find(e=>e.id===r.activeTabId);return i?.type===`chat`&&i.metadata?.sessionId===e}function pe(e,t=`claude`,n=``){let[r,i]=(0,q.useState)([]),[a,o]=(0,q.useState)(!1),[s,c]=(0,q.useState)(!1),[l,u]=(0,q.useState)(`idle`),[d,f]=(0,q.useState)(0),[p,m]=(0,q.useState)(15),[_,v]=(0,q.useState)(null),[y,b]=(0,q.useState)(null),[x,S]=(0,q.useState)(null),[C,w]=(0,q.useState)(!1),T=(0,q.useRef)(``),E=(0,q.useRef)([]),D=(0,q.useRef)(!1),O=(0,q.useRef)(null),k=(0,q.useRef)(()=>{}),A=(0,q.useRef)(null),M=(0,q.useRef)(e);M.current=e;let N=(0,q.useRef)(n);N.current=n;let P=(0,q.useCallback)(e=>{let t;try{t=JSON.parse(e.data)}catch{return}if(t.type===`ping`)return;if(t.type===`title_updated`){S(t.title??null);return}if(t.type===`streaming_status`){let e=t.status??`idle`;if(u(e),f(e===`connecting`?t.elapsed??0:0),e===`connecting`){let e=t.effort,n=t.thinkingBudget,r=15;n&&n>0?r=Math.max(15,Math.round(n/500)):e===`high`?r=30:e===`low`&&(r=10),m(r)}return}if(t.type===`connected`){w(!0),t.sessionTitle&&S(t.sessionTitle);return}if(t.type===`status`){w(!0);let e=t;e.sessionTitle&&S(e.sessionTitle),e.isStreaming&&(D.current=!0,c(!0)),e.pendingApproval&&v({requestId:e.pendingApproval.requestId,tool:e.pendingApproval.tool,input:e.pendingApproval.input}),A.current?.();return}let n=(e,t)=>{let n=E.current.findIndex(e=>e.type===`tool_use`&&(e.tool===`Agent`||e.tool===`Task`)&&e.toolUseId===t);if(n===-1)return!1;let r=E.current[n];if(r.type!==`tool_use`)return!1;let i=[...r.children??[],e];return E.current[n]={...r,children:i},!0},r=()=>{let e=T.current,t=[...E.current];i(n=>{let r=n[n.length-1];return r?.role===`assistant`&&!r.id.startsWith(`final-`)?[...n.slice(0,-1),{...r,content:e,events:t}]:[...n,{id:`streaming-${Date.now()}`,role:`assistant`,content:e,events:t,timestamp:new Date().toISOString()}]})};switch(t.type){case`text`:{let e=t.parentToolUseId;if(e&&n(t,e)){r();break}T.current+=t.content,E.current.push(t),r();break}case`thinking`:{let e=t.parentToolUseId;if(e&&n(t,e)){r();break}E.current.push(t),r();break}case`tool_use`:{let e=t.parentToolUseId;if(e&&n(t,e)){r();break}E.current.push(t),r();break}case`tool_result`:{let e=t.parentToolUseId;if(e&&n(t,e)){r();break}E.current.push(t),r();break}case`approval_request`:if(E.current.push(t),v({requestId:t.requestId,tool:t.tool,input:t.input}),M.current&&!fe(M.current)){let e=t.tool===`AskUserQuestion`?`question`:`approval_request`;j.getState().addNotification(M.current,e,N.current),de(e)}break;case`error`:{E.current.push(t);let e=[...E.current];i(n=>{let r=n[n.length-1];return r?.role===`assistant`?[...n.slice(0,-1),{...r,events:e}]:[...n,{id:`error-${Date.now()}`,role:`system`,content:t.message,events:[t],timestamp:new Date().toISOString()}]}),D.current=!1,c(!1),u(`idle`);break}case`done`:{if(!D.current)break;t.contextWindowPct!=null&&b(t.contextWindowPct),M.current&&!fe(M.current)&&(j.getState().addNotification(M.current,`done`,N.current),de(`done`));let e=T.current,n=[...E.current];i(t=>{let r=t[t.length-1];return r?.role===`assistant`?[...t.slice(0,-1),{...r,id:`final-${Date.now()}`,content:e||r.content,events:n.length>0?n:r.events}]:t}),T.current=``,E.current=[],D.current=!1,c(!1),u(`idle`);break}}},[]),{send:F,connect:I}=ae({url:e&&n?`/ws/project/${encodeURIComponent(n)}/chat/${e}`:``,onMessage:P,autoConnect:!!e&&!!n});k.current=F,(0,q.useEffect)(()=>{let r=!1;return c(!1),v(null),T.current=``,E.current=[],w(!1),e&&n?(o(!0),fetch(`${h(n)}/chat/sessions/${e}/messages?providerId=${t}`,{headers:{Authorization:`Bearer ${g()}`}}).then(e=>e.json()).then(e=>{r||D.current||(e.ok&&Array.isArray(e.data)&&e.data.length>0?i(e.data):i([]))}).catch(()=>{!r&&!D.current&&i([])}).finally(()=>{r||o(!1)})):i([]),()=>{r=!0}},[e,t,n]);let L=(0,q.useCallback)(e=>{if(e.trim()){if(D.current){let e=T.current,t=[...E.current];i(n=>{let r=n[n.length-1];return r?.role===`assistant`?[...n.slice(0,-1),{...r,id:`final-${Date.now()}`,content:e||r.content,events:t.length>0?t:r.events}]:n}),F(JSON.stringify({type:`cancel`}))}i(t=>[...t,{id:`user-${Date.now()}`,role:`user`,content:e,timestamp:new Date().toISOString()}]),T.current=``,E.current=[],O.current=null,D.current=!0,c(!0),u(`connecting`),v(null),F(JSON.stringify({type:`message`,content:e}))}},[F]),R=(0,q.useCallback)((e,t,n)=>{if(F(JSON.stringify({type:`approval_response`,requestId:e,approved:t,data:n})),t&&n){let t=E.current.find(t=>t.type===`approval_request`&&t.requestId===e&&t.tool===`AskUserQuestion`);if(t){let e=t.input;e&&typeof e==`object`&&(e.answers=n)}i(e=>[...e])}v(null)},[F]),z=(0,q.useCallback)(()=>{if(!D.current)return;F(JSON.stringify({type:`cancel`}));let e=T.current,t=[...E.current];i(n=>{let r=n[n.length-1];return r?.role===`assistant`?[...n.slice(0,-1),{...r,id:`final-${Date.now()}`,content:e||r.content,events:t.length>0?t:r.events}]:n}),T.current=``,E.current=[],O.current=null,D.current=!1,c(!1),v(null)},[F]),B=(0,q.useCallback)(()=>{w(!1),I(),A.current?.()},[I]),V=(0,q.useCallback)(()=>{!e||!n||(o(!0),fetch(`${h(n)}/chat/sessions/${e}/messages?providerId=${t}`,{headers:{Authorization:`Bearer ${g()}`}}).then(e=>e.json()).then(e=>{e.ok&&Array.isArray(e.data)&&e.data.length>0&&(i(e.data),T.current=``,E.current=[])}).catch(()=>{}).finally(()=>o(!1)))},[e,t,n]);return A.current=V,{messages:r,messagesLoading:a,isStreaming:s,streamingStatus:l,connectingElapsed:d,thinkingWarningThreshold:p,pendingApproval:_,contextWindowPct:y,sessionTitle:x,sendMessage:L,respondToApproval:R,cancelStreaming:z,reconnect:B,refetchMessages:V,isConnected:C}}var me=3e4;function he(e,t=`claude`){let[n,r]=(0,q.useState)({}),[i,a]=(0,q.useState)(!1),[o,s]=(0,q.useState)(null),c=(0,q.useRef)(null),l=(0,q.useCallback)((n=!1)=>{if(!e)return;a(!0);let i=n?`&refresh=1`:``;fetch(`${h(e)}/chat/usage?providerId=${t}${i}`,{headers:{Authorization:`Bearer ${g()}`}}).then(e=>e.json()).then(e=>{e.ok&&e.data&&(r(t=>({...t,...e.data})),e.data.lastFetchedAt&&s(e.data.lastFetchedAt))}).catch(()=>{}).finally(()=>a(!1))},[e,t]);return(0,q.useEffect)(()=>(l(),c.current=setInterval(()=>l(),me),()=>{c.current&&clearInterval(c.current)}),[l]),{usageInfo:n,usageLoading:i,lastFetchedAt:o,refreshUsage:(0,q.useCallback)(()=>l(!0),[l])}}var ge={damping:.7,stiffness:.05,mass:1.25},_e=70,ve=1e3/60,ye=350,be=!1;globalThis.document?.addEventListener(`mousedown`,()=>{be=!0}),globalThis.document?.addEventListener(`mouseup`,()=>{be=!1}),globalThis.document?.addEventListener(`click`,()=>{be=!1});var xe=(e={})=>{let[t,n]=(0,q.useState)(!1),[r,i]=(0,q.useState)(e.initial!==!1),[a,o]=(0,q.useState)(!1),s=(0,q.useRef)(null);s.current=e;let c=(0,q.useCallback)(()=>{if(!be)return!1;let e=window.getSelection();if(!e||!e.rangeCount)return!1;let t=e.getRangeAt(0);return t.commonAncestorContainer.contains(g.current)||g.current?.contains(t.commonAncestorContainer)},[]),l=(0,q.useCallback)(e=>{d.isAtBottom=e,i(e)},[]),u=(0,q.useCallback)(e=>{d.escapedFromLock=e,n(e)},[]),d=(0,q.useMemo)(()=>{let n;return{escapedFromLock:t,isAtBottom:r,resizeDifference:0,accumulated:0,velocity:0,listeners:new Set,get scrollTop(){return g.current?.scrollTop??0},set scrollTop(e){g.current&&(g.current.scrollTop=e,d.ignoreScrollToTop=g.current.scrollTop)},get targetScrollTop(){return!g.current||!_.current?0:g.current.scrollHeight-1-g.current.clientHeight},get calculatedTargetScrollTop(){if(!g.current||!_.current)return 0;let{targetScrollTop:t}=this;if(!e.targetScrollTop)return t;if(n?.targetScrollTop===t)return n.calculatedScrollTop;let r=Math.max(Math.min(e.targetScrollTop(t,{scrollElement:g.current,contentElement:_.current}),t),0);return n={targetScrollTop:t,calculatedScrollTop:r},requestAnimationFrame(()=>{n=void 0}),r},get scrollDifference(){return this.calculatedTargetScrollTop-this.scrollTop},get isNearBottom(){return this.scrollDifference<=_e}}},[]),f=(0,q.useCallback)((e={})=>{typeof e==`string`&&(e={animation:e}),e.preserveScrollPosition||l(!0);let t=Date.now()+(Number(e.wait)||0),n=we(s.current,e.animation),{ignoreEscapes:r=!1}=e,i,a=d.calculatedTargetScrollTop;e.duration instanceof Promise?e.duration.finally(()=>{i=Date.now()}):i=t+(e.duration??0);let o=async()=>{let e=new Promise(requestAnimationFrame).then(()=>{if(!d.isAtBottom)return d.animation=void 0,!1;let{scrollTop:l}=d,u=performance.now(),p=(u-(d.lastTick??u))/ve;if(d.animation||={behavior:n,promise:e,ignoreEscapes:r},d.animation.behavior===n&&(d.lastTick=u),c()||t>Date.now())return o();if(l<Math.min(a,d.calculatedTargetScrollTop)){if(d.animation?.behavior===n){if(n===`instant`)return d.scrollTop=d.calculatedTargetScrollTop,o();d.velocity=(n.damping*d.velocity+n.stiffness*d.scrollDifference)/n.mass,d.accumulated+=d.velocity*p,d.scrollTop+=d.accumulated,d.scrollTop!==l&&(d.accumulated=0)}return o()}return i>Date.now()?(a=d.calculatedTargetScrollTop,o()):(d.animation=void 0,d.scrollTop<d.calculatedTargetScrollTop?f({animation:we(s.current,s.current.resize),ignoreEscapes:r,duration:Math.max(0,i-Date.now())||void 0}):d.isAtBottom)});return e.then(e=>(requestAnimationFrame(()=>{d.animation||(d.lastTick=void 0,d.velocity=0)}),e))};return e.wait!==!0&&(d.animation=void 0),d.animation?.behavior===n?d.animation.promise:o()},[l,c,d]),p=(0,q.useCallback)(()=>{u(!0),l(!1)},[u,l]),m=(0,q.useCallback)(({target:e})=>{if(e!==g.current)return;let{scrollTop:t,ignoreScrollToTop:n}=d,{lastScrollTop:r=t}=d;d.lastScrollTop=t,d.ignoreScrollToTop=void 0,n&&n>t&&(r=n),o(d.isNearBottom),setTimeout(()=>{if(d.resizeDifference||t===n)return;if(c()){u(!0),l(!1);return}let e=t>r,i=t<r;if(d.animation?.ignoreEscapes){d.scrollTop=r;return}i&&(u(!0),l(!1)),e&&u(!1),!d.escapedFromLock&&d.isNearBottom&&l(!0)},1)},[u,l,c,d]),h=(0,q.useCallback)(({target:e,deltaY:t})=>{let n=e;for(;![`scroll`,`auto`].includes(getComputedStyle(n).overflow);){if(!n.parentElement)return;n=n.parentElement}n===g.current&&t<0&&g.current.scrollHeight>g.current.clientHeight&&!d.animation?.ignoreEscapes&&(u(!0),l(!1))},[u,l,d]),g=Se(e=>{g.current?.removeEventListener(`scroll`,m),g.current?.removeEventListener(`wheel`,h),e?.addEventListener(`scroll`,m,{passive:!0}),e?.addEventListener(`wheel`,h,{passive:!0})},[]),_=Se(e=>{if(d.resizeObserver?.disconnect(),!e)return;let t;d.resizeObserver=new ResizeObserver(([e])=>{let{height:n}=e.contentRect,r=n-(t??n);if(d.resizeDifference=r,d.scrollTop>d.targetScrollTop&&(d.scrollTop=d.targetScrollTop),o(d.isNearBottom),r>=0){let e=we(s.current,t?s.current.resize:s.current.initial);f({animation:e,wait:!0,preserveScrollPosition:!0,duration:e===`instant`?void 0:ye})}else d.isNearBottom&&(u(!1),l(!0));t=n,requestAnimationFrame(()=>{setTimeout(()=>{d.resizeDifference===r&&(d.resizeDifference=0)},1)})}),d.resizeObserver?.observe(e)},[]);return{contentRef:_,scrollRef:g,scrollToBottom:f,stopScroll:p,isAtBottom:r||a,isNearBottom:a,escapedFromLock:t,state:d}};function Se(e,t){let n=(0,q.useCallback)(t=>(n.current=t,e(t)),t);return n}var Ce=new Map;function we(...e){let t={...ge},n=!1;for(let r of e){if(r===`instant`){n=!0;continue}typeof r==`object`&&(n=!1,t.damping=r.damping??t.damping,t.stiffness=r.stiffness??t.stiffness,t.mass=r.mass??t.mass)}let r=JSON.stringify(t);return Ce.has(r)||Ce.set(r,Object.freeze(t)),n?`instant`:Ce.get(r)}var Te=(0,q.createContext)(null),Ee=typeof window<`u`?q.useLayoutEffect:q.useEffect;function De({instance:e,children:t,resize:n,initial:r,mass:i,damping:a,stiffness:o,targetScrollTop:s,contextRef:c,...l}){let u=(0,q.useRef)(null),d=xe({mass:i,damping:a,stiffness:o,resize:n,initial:r,targetScrollTop:q.useCallback((e,t)=>(y?.targetScrollTop??s)?.(e,t)??e,[s])}),{scrollRef:f,contentRef:p,scrollToBottom:m,stopScroll:h,isAtBottom:g,escapedFromLock:_,state:v}=e??d,y=(0,q.useMemo)(()=>({scrollToBottom:m,stopScroll:h,scrollRef:f,isAtBottom:g,escapedFromLock:_,contentRef:p,state:v,get targetScrollTop(){return u.current},set targetScrollTop(e){u.current=e}}),[m,g,p,f,h,_,v]);return(0,q.useImperativeHandle)(c,()=>y,[y]),Ee(()=>{f.current&&getComputedStyle(f.current).overflow===`visible`&&(f.current.style.overflow=`auto`)},[]),q.createElement(Te.Provider,{value:y},q.createElement(`div`,{...l},typeof t==`function`?t(y):t))}(function(e){function t({children:e,scrollClassName:t,...n}){let r=Oe();return q.createElement(`div`,{ref:r.scrollRef,style:{height:`100%`,width:`100%`,scrollbarGutter:`stable both-edges`},className:t},q.createElement(`div`,{...n,ref:r.contentRef},typeof e==`function`?e(r):e))}e.Content=t})(De||={});function Oe(){let e=(0,q.useContext)(Te);if(!e)throw Error(`use-stick-to-bottom component context must be used within a StickToBottom component`);return e}var Q=i();function ke(e){let t=e.type===`approval_request`;return{toolName:e.type===`tool_use`?e.tool:t?e.tool??`Tool`:`Tool`,input:e.type===`tool_use`?e.input:t?e.input??{}:{}}}function Ae({tool:e,result:t,completed:n,projectName:r}){let[i,a]=(0,q.useState)(!1);if(e.type===`error`)return(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 rounded bg-red-500/10 border border-red-500/20 px-2 py-1.5 text-xs text-red-400`,children:[(0,Q.jsx)(A,{className:`size-3`}),(0,Q.jsx)(`span`,{children:e.message})]});let{toolName:s,input:c}=ke(e),l=t?.type===`tool_result`,u=l&&!!t.isError,d=s===`AskUserQuestion`&&!!c?.answers,f=(s===`Agent`||s===`Task`)&&e.type===`tool_use`,p=f?e.children:void 0,m=p&&p.length>0;return(0,Q.jsxs)(`div`,{className:`rounded border text-xs ${f?`border-accent/30 bg-accent/5`:`border-border bg-background`}`,children:[(0,Q.jsxs)(`button`,{onClick:()=>a(!i),className:`flex items-center gap-2 px-2 py-1.5 w-full text-left hover:bg-surface transition-colors min-w-0`,children:[i?(0,Q.jsx)(o,{className:`size-3 shrink-0`}):(0,Q.jsx)(w,{className:`size-3 shrink-0`}),u?(0,Q.jsx)(z,{className:`size-3 text-red-400 shrink-0`}):l||d||n?(0,Q.jsx)(y,{className:`size-3 text-green-400 shrink-0`}):(0,Q.jsx)(v,{className:`size-3 text-yellow-400 shrink-0 animate-spin`}),(0,Q.jsx)(`span`,{className:`truncate text-text-primary`,children:(0,Q.jsx)(je,{name:s,input:c})}),m&&(0,Q.jsxs)(`span`,{className:`ml-auto text-[10px] text-text-subtle shrink-0`,children:[p.length,` steps`]})]}),i&&(0,Q.jsxs)(`div`,{className:`px-2 pb-2 space-y-1.5`,children:[(e.type===`tool_use`||e.type===`approval_request`)&&(0,Q.jsx)(Me,{name:s,input:c,projectName:r}),m&&(0,Q.jsx)(Ie,{events:p,projectName:r}),l&&(0,Q.jsx)(Pe,{toolName:s,output:t.output})]})]})}function je({name:e,input:t}){let n=e=>String(e??``);switch(e){case`Read`:case`Write`:case`Edit`:case`MultiEdit`:case`NotebookEdit`:return(0,Q.jsxs)(Q.Fragment,{children:[e,` `,(0,Q.jsx)(`span`,{className:`text-text-subtle`,children:m(n(t.file_path))})]});case`Bash`:return(0,Q.jsxs)(Q.Fragment,{children:[e,` `,(0,Q.jsx)(`span`,{className:`font-mono text-text-subtle`,children:$(n(t.command),60)})]});case`Glob`:return(0,Q.jsxs)(Q.Fragment,{children:[e,` `,(0,Q.jsx)(`span`,{className:`font-mono text-text-subtle`,children:n(t.pattern)})]});case`Grep`:return(0,Q.jsxs)(Q.Fragment,{children:[e,` `,(0,Q.jsx)(`span`,{className:`font-mono text-text-subtle`,children:$(n(t.pattern),40)})]});case`WebSearch`:return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(S,{className:`size-3 inline`}),` `,e,` `,(0,Q.jsx)(`span`,{className:`text-text-subtle`,children:$(n(t.query),50)})]});case`WebFetch`:return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(H,{className:`size-3 inline`}),` `,e,` `,(0,Q.jsx)(`span`,{className:`text-text-subtle`,children:$(n(t.url),50)})]});case`ToolSearch`:return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(S,{className:`size-3 inline`}),` `,e,` `,(0,Q.jsx)(`span`,{className:`text-text-subtle`,children:$(n(t.query),50)})]});case`Agent`:case`Task`:return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(R,{className:`size-3 inline`}),` `,e,` `,(0,Q.jsx)(`span`,{className:`text-text-subtle`,children:$(n(t.description||t.prompt),60)})]});case`TodoWrite`:{let n=Array.isArray(t.todos)?t.todos:[],r=n.filter(e=>e.status===`completed`).length;return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(W,{className:`size-3 inline`}),` `,e,` `,(0,Q.jsxs)(`span`,{className:`text-text-subtle`,children:[r,`/`,n.length,` done`]})]})}case`AskUserQuestion`:{let n=Array.isArray(t.questions)?t.questions:[],r=!!t.answers;return(0,Q.jsxs)(Q.Fragment,{children:[e,` `,(0,Q.jsxs)(`span`,{className:`text-text-subtle`,children:[n.length,` question`,n.length===1?``:`s`,r?` ✓`:``]})]})}default:return(0,Q.jsx)(Q.Fragment,{children:e})}}function Me({name:e,input:t,projectName:n}){let r=e=>String(e??``),{openTab:i}=d(),a=e=>{n&&i({type:`editor`,title:m(e),metadata:{filePath:e,projectName:n},projectId:n,closable:!0})},o=(e,t,r)=>{i({type:`git-diff`,title:`Diff ${m(e)}`,metadata:{filePath:e,projectName:n,original:t,modified:r},projectId:n??null,closable:!0})};switch(e){case`Bash`:return(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[!!t.description&&(0,Q.jsx)(`p`,{className:`text-text-subtle italic`,children:r(t.description)}),(0,Q.jsx)(`pre`,{className:`font-mono text-text-secondary overflow-x-auto whitespace-pre-wrap break-all`,children:r(t.command)})]});case`Read`:case`Write`:case`Edit`:case`MultiEdit`:case`NotebookEdit`:{let n=r(t.file_path);return(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsxs)(`button`,{type:`button`,className:`font-mono text-text-secondary break-all hover:text-primary hover:underline text-left flex items-center gap-1`,onClick:()=>a(n),title:`Open file in editor`,children:[(0,Q.jsx)(l,{className:`size-3 shrink-0`}),n]}),e===`Edit`&&(!!t.old_string||!!t.new_string)&&(0,Q.jsxs)(`button`,{type:`button`,className:`text-text-subtle hover:text-primary hover:underline text-left flex items-center gap-1`,onClick:()=>o(n,r(t.old_string),r(t.new_string)),title:`View diff in new tab`,children:[(0,Q.jsx)(V,{className:`size-3 shrink-0`}),`View Diff`]}),e===`Write`&&!!t.content&&(0,Q.jsx)(`pre`,{className:`font-mono text-text-subtle overflow-x-auto max-h-32 whitespace-pre-wrap`,children:$(r(t.content),300)})]})}case`Glob`:return(0,Q.jsxs)(`p`,{className:`font-mono text-text-secondary`,children:[r(t.pattern),t.path?` in ${r(t.path)}`:``]});case`Grep`:return(0,Q.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,Q.jsxs)(`p`,{className:`font-mono text-text-secondary`,children:[`/`,r(t.pattern),`/`]}),!!t.path&&(0,Q.jsxs)(`p`,{className:`text-text-subtle`,children:[`in `,r(t.path)]})]});case`TodoWrite`:return(0,Q.jsx)(Ne,{todos:t.todos??[]});case`Agent`:case`Task`:return(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[!!t.description&&(0,Q.jsx)(`p`,{className:`text-text-secondary font-medium`,children:r(t.description)}),!!t.subagent_type&&(0,Q.jsxs)(`p`,{className:`text-text-subtle`,children:[`Type: `,r(t.subagent_type)]}),!!t.prompt&&(0,Q.jsx)(Le,{content:r(t.prompt),maxHeight:`max-h-48`})]});case`ToolSearch`:return(0,Q.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,Q.jsx)(`p`,{className:`font-mono text-text-secondary`,children:r(t.query)}),!!t.max_results&&(0,Q.jsxs)(`p`,{className:`text-text-subtle`,children:[`Max results: `,r(t.max_results)]})]});case`WebFetch`:return(0,Q.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,Q.jsxs)(`a`,{href:r(t.url),target:`_blank`,rel:`noopener noreferrer`,className:`font-mono text-primary hover:underline break-all flex items-center gap-1`,children:[(0,Q.jsx)(H,{className:`size-3 shrink-0`}),r(t.url)]}),!!t.prompt&&(0,Q.jsx)(`p`,{className:`text-text-subtle`,children:$(r(t.prompt),100)})]});case`AskUserQuestion`:{let e=t.questions??[],n=t.answers??{};return(0,Q.jsx)(`div`,{className:`space-y-2`,children:e.map((e,t)=>(0,Q.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,Q.jsxs)(`p`,{className:`text-text-primary font-medium`,children:[e.header?`${e.header}: `:``,e.question]}),(0,Q.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:e.options.map((t,r)=>(0,Q.jsx)(`span`,{className:`inline-block rounded px-1.5 py-0.5 text-xs border ${(n[e.question]??``).split(`, `).includes(t.label)?`border-accent bg-accent/20 text-text-primary`:`border-border text-text-subtle`}`,children:t.label},r))}),n[e.question]&&(0,Q.jsxs)(`p`,{className:`text-accent text-xs`,children:[`Answer: `,n[e.question]]})]},t))})}default:return(0,Q.jsx)(`pre`,{className:`overflow-x-auto text-text-secondary font-mono whitespace-pre-wrap break-all`,children:JSON.stringify(t,null,2)})}}function Ne({todos:e}){return(0,Q.jsx)(`div`,{className:`space-y-0.5`,children:e.map((e,t)=>(0,Q.jsxs)(`div`,{className:`flex items-start gap-1.5`,children:[(0,Q.jsx)(`span`,{className:`shrink-0 mt-0.5 ${e.status===`completed`?`text-green-400`:e.status===`in_progress`?`text-yellow-400`:`text-text-subtle`}`,children:e.status===`completed`?`✓`:e.status===`in_progress`?`▶`:`○`}),(0,Q.jsx)(`span`,{className:e.status===`completed`?`line-through text-text-subtle`:`text-text-secondary`,children:e.content})]},t))})}function Pe({toolName:e,output:t}){let[n,r]=(0,q.useState)(!1),i=(0,q.useMemo)(()=>{if(e!==`Agent`&&e!==`Task`)return null;try{let e=JSON.parse(t);if(Array.isArray(e)){let t=e.filter(e=>e.type===`text`&&e.text).map(e=>e.text).join(`
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/api-client-TUmacMRS.js","assets/react-CYzKIDNi.js"])))=>i.map(i=>d[i]);
2
+ import{i as e,t}from"./react-CYzKIDNi.js";import{A as n}from"./input-P_K5CUiy.js";import{n as r,t as i}from"./jsx-runtime-wQxeESYQ.js";import{a,i as o,o as s,t as c}from"./ai-settings-section-ByRvOONz.js";import{t as l}from"./columns-2-fz8yNaAo.js";import{a as u,n as d,t as f}from"./tab-store-0CKk8cSr.js";import{n as p}from"./settings-store-2NQzaOVJ.js";import{r as m,t as h}from"./utils-DC-bdPS3.js";import{i as g,r as _,t as v}from"./api-client-TUmacMRS.js";import{A as y,C as b,D as x,E as S,F as C,H as w,I as T,O as E,P as D,S as O,T as k,U as A,V as j,g as M,h as N,j as P,t as F}from"./index-YO_w11fv.js";import{t as I}from"./markdown-renderer-BkXmQhhX.js";var L=r(`activity`,[[`path`,{d:`M22 12h-2.48a2 2 0 0 0-1.93 1.46l-2.35 8.36a.25.25 0 0 1-.48 0L9.24 2.18a.25.25 0 0 0-.48 0l-2.35 8.36A2 2 0 0 1 4.49 12H2`,key:`169zse`}]]),R=r(`arrow-up`,[[`path`,{d:`m5 12 7-7 7 7`,key:`hav0vg`}],[`path`,{d:`M12 19V5`,key:`x0mq9r`}]]),z=r(`bot`,[[`path`,{d:`M12 8V4H8`,key:`hb8ula`}],[`rect`,{width:`16`,height:`12`,x:`4`,y:`8`,rx:`2`,key:`enze0r`}],[`path`,{d:`M2 14h2`,key:`vft8re`}],[`path`,{d:`M20 14h2`,key:`4cs60a`}],[`path`,{d:`M15 13v2`,key:`1xurst`}],[`path`,{d:`M9 13v2`,key:`rq6x2g`}]]),B=r(`circle-x`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m15 9-6 6`,key:`1uzhvr`}],[`path`,{d:`m9 9 6 6`,key:`z0biqf`}]]),V=r(`code`,[[`path`,{d:`m16 18 6-6-6-6`,key:`eg8j8`}],[`path`,{d:`m8 6-6 6 6 6`,key:`ppft3o`}]]),H=r(`globe`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20`,key:`13o1zl`}],[`path`,{d:`M2 12h20`,key:`9i4pu4`}]]),ee=r(`history`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}],[`path`,{d:`M12 7v5l4 2`,key:`1fdv2h`}]]),U=r(`image`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,ry:`2`,key:`1m3agn`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}],[`path`,{d:`m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21`,key:`1xmnt7`}]]),W=r(`list-todo`,[[`path`,{d:`M13 5h8`,key:`a7qcls`}],[`path`,{d:`M13 12h8`,key:`h98zly`}],[`path`,{d:`M13 19h8`,key:`c3s6r1`}],[`path`,{d:`m3 17 2 2 4-4`,key:`1jhpwq`}],[`rect`,{x:`3`,y:`4`,width:`6`,height:`6`,rx:`1`,key:`cif1o7`}]]),G=r(`paperclip`,[[`path`,{d:`m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551`,key:`1miecu`}]]),te=r(`settings-2`,[[`path`,{d:`M14 17H5`,key:`gfn3mx`}],[`path`,{d:`M19 7h-9`,key:`6i9tg`}],[`circle`,{cx:`17`,cy:`17`,r:`3`,key:`18b49y`}],[`circle`,{cx:`7`,cy:`7`,r:`3`,key:`dfmy0x`}]]),ne=r(`shield-alert`,[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`M12 8v4`,key:`1got3b`}],[`path`,{d:`M12 16h.01`,key:`1drbdi`}]]),re=r(`sparkles`,[[`path`,{d:`M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594z`,key:`1s2grr`}],[`path`,{d:`M20 2v4`,key:`1rf3ol`}],[`path`,{d:`M22 4h-4`,key:`gwowj6`}],[`circle`,{cx:`4`,cy:`20`,r:`2`,key:`6kqj1y`}]]),K=r(`square`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]),q=e(t(),1),J=3e4,Y=1e3,ie=class{ws=null;url;handlers=[];reconnectAttempts=0;reconnectTimer=null;intentionalClose=!1;constructor(e){this.url=e}connect(){this.intentionalClose=!1,this.cleanup();let e=window.location.protocol===`https:`?`wss:`:`ws:`,t=this.url.startsWith(`ws`)?this.url:`${e}//${window.location.host}${this.url}`;this.ws=new WebSocket(t),this.ws.onopen=()=>{this.reconnectAttempts=0;try{this.ws?.send(JSON.stringify({type:`ready`}))}catch{}},this.ws.onmessage=e=>{for(let t of this.handlers)t(e)},this.ws.onclose=()=>{this.intentionalClose||this.scheduleReconnect()},this.ws.onerror=()=>{this.ws?.close()}}disconnect(){this.intentionalClose=!0,this.cleanup(),this.reconnectTimer&&=(clearTimeout(this.reconnectTimer),null)}send(e){this.ws?.readyState===WebSocket.OPEN&&this.ws.send(e)}onMessage(e){return this.handlers.push(e),()=>{this.handlers=this.handlers.filter(t=>t!==e)}}get isConnected(){return this.ws?.readyState===WebSocket.OPEN}cleanup(){this.ws&&=(this.ws.onopen=null,this.ws.onclose=null,this.ws.onmessage=null,this.ws.onerror=null,(this.ws.readyState===WebSocket.OPEN||this.ws.readyState===WebSocket.CONNECTING)&&this.ws.close(),null)}scheduleReconnect(){let e=Math.min(Y*2**this.reconnectAttempts,J);this.reconnectAttempts++,this.reconnectTimer=setTimeout(()=>this.connect(),e)}};function ae({url:e,onMessage:t,autoConnect:n=!0}){let r=(0,q.useRef)(null);return(0,q.useEffect)(()=>{let i=new ie(e);return r.current=i,t&&i.onMessage(t),n&&i.connect(),()=>{i.disconnect(),r.current=null}},[e,n]),{send:(0,q.useCallback)(e=>{r.current?.send(e)},[]),connect:(0,q.useCallback)(()=>{r.current?.connect()},[]),disconnect:(0,q.useCallback)(()=>{r.current?.disconnect()},[])}}var oe=null;function X(){return oe||=new AudioContext,oe}function Z(e,t,n,r,i=`sine`){let a=X(),o=a.createOscillator(),s=a.createGain();o.type=i,o.frequency.value=e,s.gain.setValueAtTime(r,n),s.gain.exponentialRampToValueAtTime(.001,n+t),o.connect(s),s.connect(a.destination),o.start(n),o.stop(n+t)}function se(){let e=X().currentTime;Z(523,.15,e,.15),Z(659,.2,e+.12,.15)}function ce(){let e=X().currentTime;Z(880,.12,e,.18,`square`),Z(698,.12,e+.15,.18,`square`),Z(880,.15,e+.3,.15,`square`)}function le(){let e=X().currentTime;Z(440,.12,e,.12),Z(523,.12,e+.1,.12),Z(659,.18,e+.2,.12)}var ue={done:se,approval_request:ce,question:le};function de(e){try{ue[e]?.()}catch{}}function fe(e){if(document.hidden)return!1;let{panels:t,focusedPanelId:n}=d.getState(),r=t[n];if(!r)return!1;let i=r.tabs.find(e=>e.id===r.activeTabId);return i?.type===`chat`&&i.metadata?.sessionId===e}function pe(e,t=`claude`,n=``){let[r,i]=(0,q.useState)([]),[a,o]=(0,q.useState)(!1),[s,c]=(0,q.useState)(!1),[l,u]=(0,q.useState)(`idle`),[d,f]=(0,q.useState)(0),[p,m]=(0,q.useState)(15),[h,v]=(0,q.useState)(null),[y,b]=(0,q.useState)(null),[x,S]=(0,q.useState)(null),[C,w]=(0,q.useState)(!1),T=(0,q.useRef)(``),E=(0,q.useRef)([]),D=(0,q.useRef)(!1),O=(0,q.useRef)(null),k=(0,q.useRef)(()=>{}),A=(0,q.useRef)(null),j=(0,q.useRef)(e);j.current=e;let N=(0,q.useRef)(n);N.current=n;let P=(0,q.useCallback)(e=>{let t;try{t=JSON.parse(e.data)}catch{return}if(t.type===`ping`)return;if(t.type===`title_updated`){S(t.title??null);return}if(t.type===`streaming_status`){let e=t.status??`idle`;if(u(e),f(e===`connecting`?t.elapsed??0:0),e===`connecting`){let e=t.effort,n=t.thinkingBudget,r=15;n&&n>0?r=Math.max(15,Math.round(n/500)):e===`high`?r=30:e===`low`&&(r=10),m(r)}return}if(t.type===`connected`){w(!0),t.sessionTitle&&S(t.sessionTitle);return}if(t.type===`status`){w(!0);let e=t;e.sessionTitle&&S(e.sessionTitle),e.isStreaming&&(D.current=!0,c(!0)),e.pendingApproval&&v({requestId:e.pendingApproval.requestId,tool:e.pendingApproval.tool,input:e.pendingApproval.input}),A.current?.();return}let n=(e,t)=>{let n=E.current.findIndex(e=>e.type===`tool_use`&&(e.tool===`Agent`||e.tool===`Task`)&&e.toolUseId===t);if(n===-1)return!1;let r=E.current[n];if(r.type!==`tool_use`)return!1;let i=[...r.children??[],e];return E.current[n]={...r,children:i},!0},r=()=>{let e=T.current,t=[...E.current];i(n=>{let r=n[n.length-1];return r?.role===`assistant`&&!r.id.startsWith(`final-`)?[...n.slice(0,-1),{...r,content:e,events:t}]:[...n,{id:`streaming-${Date.now()}`,role:`assistant`,content:e,events:t,timestamp:new Date().toISOString()}]})};switch(t.type){case`text`:{let e=t.parentToolUseId;if(e&&n(t,e)){r();break}T.current+=t.content,E.current.push(t),r();break}case`thinking`:{let e=t.parentToolUseId;if(e&&n(t,e)){r();break}E.current.push(t),r();break}case`tool_use`:{let e=t.parentToolUseId;if(e&&n(t,e)){r();break}E.current.push(t),r();break}case`tool_result`:{let e=t.parentToolUseId;if(e&&n(t,e)){r();break}E.current.push(t),r();break}case`approval_request`:if(E.current.push(t),v({requestId:t.requestId,tool:t.tool,input:t.input}),j.current&&!fe(j.current)){let e=t.tool===`AskUserQuestion`?`question`:`approval_request`;M.getState().addNotification(j.current,e,N.current),de(e)}break;case`error`:{E.current.push(t);let e=[...E.current];i(n=>{let r=n[n.length-1];return r?.role===`assistant`?[...n.slice(0,-1),{...r,events:e}]:[...n,{id:`error-${Date.now()}`,role:`system`,content:t.message,events:[t],timestamp:new Date().toISOString()}]}),D.current=!1,c(!1),u(`idle`);break}case`done`:{if(!D.current)break;t.contextWindowPct!=null&&b(t.contextWindowPct),j.current&&!fe(j.current)&&(M.getState().addNotification(j.current,`done`,N.current),de(`done`));let e=T.current,n=[...E.current];i(t=>{let r=t[t.length-1];return r?.role===`assistant`?[...t.slice(0,-1),{...r,id:`final-${Date.now()}`,content:e||r.content,events:n.length>0?n:r.events}]:t}),T.current=``,E.current=[],D.current=!1,c(!1),u(`idle`);break}}},[]),{send:F,connect:I}=ae({url:e&&n?`/ws/project/${encodeURIComponent(n)}/chat/${e}`:``,onMessage:P,autoConnect:!!e&&!!n});k.current=F,(0,q.useEffect)(()=>{let r=!1;return c(!1),v(null),T.current=``,E.current=[],w(!1),e&&n?(o(!0),fetch(`${g(n)}/chat/sessions/${e}/messages?providerId=${t}`,{headers:{Authorization:`Bearer ${_()}`}}).then(e=>e.json()).then(e=>{r||D.current||(e.ok&&Array.isArray(e.data)&&e.data.length>0?i(e.data):i([]))}).catch(()=>{!r&&!D.current&&i([])}).finally(()=>{r||o(!1)})):i([]),()=>{r=!0}},[e,t,n]);let L=(0,q.useCallback)(e=>{if(e.trim()){if(D.current){let e=T.current,t=[...E.current];i(n=>{let r=n[n.length-1];return r?.role===`assistant`?[...n.slice(0,-1),{...r,id:`final-${Date.now()}`,content:e||r.content,events:t.length>0?t:r.events}]:n}),F(JSON.stringify({type:`cancel`}))}i(t=>[...t,{id:`user-${Date.now()}`,role:`user`,content:e,timestamp:new Date().toISOString()}]),T.current=``,E.current=[],O.current=null,D.current=!0,c(!0),u(`connecting`),v(null),F(JSON.stringify({type:`message`,content:e}))}},[F]),R=(0,q.useCallback)((e,t,n)=>{if(F(JSON.stringify({type:`approval_response`,requestId:e,approved:t,data:n})),t&&n){let t=E.current.find(t=>t.type===`approval_request`&&t.requestId===e&&t.tool===`AskUserQuestion`);if(t){let e=t.input;e&&typeof e==`object`&&(e.answers=n)}i(e=>[...e])}v(null)},[F]),z=(0,q.useCallback)(()=>{if(!D.current)return;F(JSON.stringify({type:`cancel`}));let e=T.current,t=[...E.current];i(n=>{let r=n[n.length-1];return r?.role===`assistant`?[...n.slice(0,-1),{...r,id:`final-${Date.now()}`,content:e||r.content,events:t.length>0?t:r.events}]:n}),T.current=``,E.current=[],O.current=null,D.current=!1,c(!1),v(null)},[F]),B=(0,q.useCallback)(()=>{w(!1),I(),A.current?.()},[I]),V=(0,q.useCallback)(()=>{!e||!n||(o(!0),fetch(`${g(n)}/chat/sessions/${e}/messages?providerId=${t}`,{headers:{Authorization:`Bearer ${_()}`}}).then(e=>e.json()).then(e=>{e.ok&&Array.isArray(e.data)&&e.data.length>0&&(i(e.data),T.current=``,E.current=[])}).catch(()=>{}).finally(()=>o(!1)))},[e,t,n]);return A.current=V,{messages:r,messagesLoading:a,isStreaming:s,streamingStatus:l,connectingElapsed:d,thinkingWarningThreshold:p,pendingApproval:h,contextWindowPct:y,sessionTitle:x,sendMessage:L,respondToApproval:R,cancelStreaming:z,reconnect:B,refetchMessages:V,isConnected:C}}var me=3e4;function he(e,t=`claude`){let[n,r]=(0,q.useState)({}),[i,a]=(0,q.useState)(!1),[o,s]=(0,q.useState)(null),c=(0,q.useRef)(null),l=(0,q.useCallback)((n=!1)=>{if(!e)return;a(!0);let i=n?`&refresh=1`:``;fetch(`${g(e)}/chat/usage?providerId=${t}${i}`,{headers:{Authorization:`Bearer ${_()}`}}).then(e=>e.json()).then(e=>{e.ok&&e.data&&(r(t=>({...t,...e.data})),e.data.lastFetchedAt&&s(e.data.lastFetchedAt))}).catch(()=>{}).finally(()=>a(!1))},[e,t]);return(0,q.useEffect)(()=>(l(),c.current=setInterval(()=>l(),me),()=>{c.current&&clearInterval(c.current)}),[l]),{usageInfo:n,usageLoading:i,lastFetchedAt:o,refreshUsage:(0,q.useCallback)(()=>l(!0),[l])}}var ge={damping:.7,stiffness:.05,mass:1.25},_e=70,ve=1e3/60,ye=350,be=!1;globalThis.document?.addEventListener(`mousedown`,()=>{be=!0}),globalThis.document?.addEventListener(`mouseup`,()=>{be=!1}),globalThis.document?.addEventListener(`click`,()=>{be=!1});var xe=(e={})=>{let[t,n]=(0,q.useState)(!1),[r,i]=(0,q.useState)(e.initial!==!1),[a,o]=(0,q.useState)(!1),s=(0,q.useRef)(null);s.current=e;let c=(0,q.useCallback)(()=>{if(!be)return!1;let e=window.getSelection();if(!e||!e.rangeCount)return!1;let t=e.getRangeAt(0);return t.commonAncestorContainer.contains(g.current)||g.current?.contains(t.commonAncestorContainer)},[]),l=(0,q.useCallback)(e=>{d.isAtBottom=e,i(e)},[]),u=(0,q.useCallback)(e=>{d.escapedFromLock=e,n(e)},[]),d=(0,q.useMemo)(()=>{let n;return{escapedFromLock:t,isAtBottom:r,resizeDifference:0,accumulated:0,velocity:0,listeners:new Set,get scrollTop(){return g.current?.scrollTop??0},set scrollTop(e){g.current&&(g.current.scrollTop=e,d.ignoreScrollToTop=g.current.scrollTop)},get targetScrollTop(){return!g.current||!_.current?0:g.current.scrollHeight-1-g.current.clientHeight},get calculatedTargetScrollTop(){if(!g.current||!_.current)return 0;let{targetScrollTop:t}=this;if(!e.targetScrollTop)return t;if(n?.targetScrollTop===t)return n.calculatedScrollTop;let r=Math.max(Math.min(e.targetScrollTop(t,{scrollElement:g.current,contentElement:_.current}),t),0);return n={targetScrollTop:t,calculatedScrollTop:r},requestAnimationFrame(()=>{n=void 0}),r},get scrollDifference(){return this.calculatedTargetScrollTop-this.scrollTop},get isNearBottom(){return this.scrollDifference<=_e}}},[]),f=(0,q.useCallback)((e={})=>{typeof e==`string`&&(e={animation:e}),e.preserveScrollPosition||l(!0);let t=Date.now()+(Number(e.wait)||0),n=we(s.current,e.animation),{ignoreEscapes:r=!1}=e,i,a=d.calculatedTargetScrollTop;e.duration instanceof Promise?e.duration.finally(()=>{i=Date.now()}):i=t+(e.duration??0);let o=async()=>{let e=new Promise(requestAnimationFrame).then(()=>{if(!d.isAtBottom)return d.animation=void 0,!1;let{scrollTop:l}=d,u=performance.now(),p=(u-(d.lastTick??u))/ve;if(d.animation||={behavior:n,promise:e,ignoreEscapes:r},d.animation.behavior===n&&(d.lastTick=u),c()||t>Date.now())return o();if(l<Math.min(a,d.calculatedTargetScrollTop)){if(d.animation?.behavior===n){if(n===`instant`)return d.scrollTop=d.calculatedTargetScrollTop,o();d.velocity=(n.damping*d.velocity+n.stiffness*d.scrollDifference)/n.mass,d.accumulated+=d.velocity*p,d.scrollTop+=d.accumulated,d.scrollTop!==l&&(d.accumulated=0)}return o()}return i>Date.now()?(a=d.calculatedTargetScrollTop,o()):(d.animation=void 0,d.scrollTop<d.calculatedTargetScrollTop?f({animation:we(s.current,s.current.resize),ignoreEscapes:r,duration:Math.max(0,i-Date.now())||void 0}):d.isAtBottom)});return e.then(e=>(requestAnimationFrame(()=>{d.animation||(d.lastTick=void 0,d.velocity=0)}),e))};return e.wait!==!0&&(d.animation=void 0),d.animation?.behavior===n?d.animation.promise:o()},[l,c,d]),p=(0,q.useCallback)(()=>{u(!0),l(!1)},[u,l]),m=(0,q.useCallback)(({target:e})=>{if(e!==g.current)return;let{scrollTop:t,ignoreScrollToTop:n}=d,{lastScrollTop:r=t}=d;d.lastScrollTop=t,d.ignoreScrollToTop=void 0,n&&n>t&&(r=n),o(d.isNearBottom),setTimeout(()=>{if(d.resizeDifference||t===n)return;if(c()){u(!0),l(!1);return}let e=t>r,i=t<r;if(d.animation?.ignoreEscapes){d.scrollTop=r;return}i&&(u(!0),l(!1)),e&&u(!1),!d.escapedFromLock&&d.isNearBottom&&l(!0)},1)},[u,l,c,d]),h=(0,q.useCallback)(({target:e,deltaY:t})=>{let n=e;for(;![`scroll`,`auto`].includes(getComputedStyle(n).overflow);){if(!n.parentElement)return;n=n.parentElement}n===g.current&&t<0&&g.current.scrollHeight>g.current.clientHeight&&!d.animation?.ignoreEscapes&&(u(!0),l(!1))},[u,l,d]),g=Se(e=>{g.current?.removeEventListener(`scroll`,m),g.current?.removeEventListener(`wheel`,h),e?.addEventListener(`scroll`,m,{passive:!0}),e?.addEventListener(`wheel`,h,{passive:!0})},[]),_=Se(e=>{if(d.resizeObserver?.disconnect(),!e)return;let t;d.resizeObserver=new ResizeObserver(([e])=>{let{height:n}=e.contentRect,r=n-(t??n);if(d.resizeDifference=r,d.scrollTop>d.targetScrollTop&&(d.scrollTop=d.targetScrollTop),o(d.isNearBottom),r>=0){let e=we(s.current,t?s.current.resize:s.current.initial);f({animation:e,wait:!0,preserveScrollPosition:!0,duration:e===`instant`?void 0:ye})}else d.isNearBottom&&(u(!1),l(!0));t=n,requestAnimationFrame(()=>{setTimeout(()=>{d.resizeDifference===r&&(d.resizeDifference=0)},1)})}),d.resizeObserver?.observe(e)},[]);return{contentRef:_,scrollRef:g,scrollToBottom:f,stopScroll:p,isAtBottom:r||a,isNearBottom:a,escapedFromLock:t,state:d}};function Se(e,t){let n=(0,q.useCallback)(t=>(n.current=t,e(t)),t);return n}var Ce=new Map;function we(...e){let t={...ge},n=!1;for(let r of e){if(r===`instant`){n=!0;continue}typeof r==`object`&&(n=!1,t.damping=r.damping??t.damping,t.stiffness=r.stiffness??t.stiffness,t.mass=r.mass??t.mass)}let r=JSON.stringify(t);return Ce.has(r)||Ce.set(r,Object.freeze(t)),n?`instant`:Ce.get(r)}var Te=(0,q.createContext)(null),Ee=typeof window<`u`?q.useLayoutEffect:q.useEffect;function De({instance:e,children:t,resize:n,initial:r,mass:i,damping:a,stiffness:o,targetScrollTop:s,contextRef:c,...l}){let u=(0,q.useRef)(null),d=xe({mass:i,damping:a,stiffness:o,resize:n,initial:r,targetScrollTop:q.useCallback((e,t)=>(y?.targetScrollTop??s)?.(e,t)??e,[s])}),{scrollRef:f,contentRef:p,scrollToBottom:m,stopScroll:h,isAtBottom:g,escapedFromLock:_,state:v}=e??d,y=(0,q.useMemo)(()=>({scrollToBottom:m,stopScroll:h,scrollRef:f,isAtBottom:g,escapedFromLock:_,contentRef:p,state:v,get targetScrollTop(){return u.current},set targetScrollTop(e){u.current=e}}),[m,g,p,f,h,_,v]);return(0,q.useImperativeHandle)(c,()=>y,[y]),Ee(()=>{f.current&&getComputedStyle(f.current).overflow===`visible`&&(f.current.style.overflow=`auto`)},[]),q.createElement(Te.Provider,{value:y},q.createElement(`div`,{...l},typeof t==`function`?t(y):t))}(function(e){function t({children:e,scrollClassName:t,...n}){let r=Oe();return q.createElement(`div`,{ref:r.scrollRef,style:{height:`100%`,width:`100%`,scrollbarGutter:`stable both-edges`},className:t},q.createElement(`div`,{...n,ref:r.contentRef},typeof e==`function`?e(r):e))}e.Content=t})(De||={});function Oe(){let e=(0,q.useContext)(Te);if(!e)throw Error(`use-stick-to-bottom component context must be used within a StickToBottom component`);return e}var Q=i();function ke(e){let t=e.type===`approval_request`;return{toolName:e.type===`tool_use`?e.tool:t?e.tool??`Tool`:`Tool`,input:e.type===`tool_use`?e.input:t?e.input??{}:{}}}function Ae({tool:e,result:t,completed:n,projectName:r}){let[i,a]=(0,q.useState)(!1);if(e.type===`error`)return(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 rounded bg-red-500/10 border border-red-500/20 px-2 py-1.5 text-xs text-red-400`,children:[(0,Q.jsx)(w,{className:`size-3`}),(0,Q.jsx)(`span`,{children:e.message})]});let{toolName:s,input:c}=ke(e),l=t?.type===`tool_result`,u=l&&!!t.isError,d=s===`AskUserQuestion`&&!!c?.answers,f=(s===`Agent`||s===`Task`)&&e.type===`tool_use`,p=f?e.children:void 0,m=p&&p.length>0;return(0,Q.jsxs)(`div`,{className:`rounded border text-xs ${f?`border-accent/30 bg-accent/5`:`border-border bg-background`}`,children:[(0,Q.jsxs)(`button`,{onClick:()=>a(!i),className:`flex items-center gap-2 px-2 py-1.5 w-full text-left hover:bg-surface transition-colors min-w-0`,children:[i?(0,Q.jsx)(o,{className:`size-3 shrink-0`}):(0,Q.jsx)(A,{className:`size-3 shrink-0`}),u?(0,Q.jsx)(B,{className:`size-3 text-red-400 shrink-0`}):l||d||n?(0,Q.jsx)(j,{className:`size-3 text-green-400 shrink-0`}):(0,Q.jsx)(P,{className:`size-3 text-yellow-400 shrink-0 animate-spin`}),(0,Q.jsx)(`span`,{className:`truncate text-text-primary`,children:(0,Q.jsx)(je,{name:s,input:c})}),m&&(0,Q.jsxs)(`span`,{className:`ml-auto text-[10px] text-text-subtle shrink-0`,children:[p.length,` steps`]})]}),i&&(0,Q.jsxs)(`div`,{className:`px-2 pb-2 space-y-1.5`,children:[(e.type===`tool_use`||e.type===`approval_request`)&&(0,Q.jsx)(Me,{name:s,input:c,projectName:r}),m&&(0,Q.jsx)(Ie,{events:p,projectName:r}),l&&(0,Q.jsx)(Pe,{toolName:s,output:t.output})]})]})}function je({name:e,input:t}){let n=e=>String(e??``);switch(e){case`Read`:case`Write`:case`Edit`:case`MultiEdit`:case`NotebookEdit`:return(0,Q.jsxs)(Q.Fragment,{children:[e,` `,(0,Q.jsx)(`span`,{className:`text-text-subtle`,children:h(n(t.file_path))})]});case`Bash`:return(0,Q.jsxs)(Q.Fragment,{children:[e,` `,(0,Q.jsx)(`span`,{className:`font-mono text-text-subtle`,children:$(n(t.command),60)})]});case`Glob`:return(0,Q.jsxs)(Q.Fragment,{children:[e,` `,(0,Q.jsx)(`span`,{className:`font-mono text-text-subtle`,children:n(t.pattern)})]});case`Grep`:return(0,Q.jsxs)(Q.Fragment,{children:[e,` `,(0,Q.jsx)(`span`,{className:`font-mono text-text-subtle`,children:$(n(t.pattern),40)})]});case`WebSearch`:return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(S,{className:`size-3 inline`}),` `,e,` `,(0,Q.jsx)(`span`,{className:`text-text-subtle`,children:$(n(t.query),50)})]});case`WebFetch`:return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(H,{className:`size-3 inline`}),` `,e,` `,(0,Q.jsx)(`span`,{className:`text-text-subtle`,children:$(n(t.url),50)})]});case`ToolSearch`:return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(S,{className:`size-3 inline`}),` `,e,` `,(0,Q.jsx)(`span`,{className:`text-text-subtle`,children:$(n(t.query),50)})]});case`Agent`:case`Task`:return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(z,{className:`size-3 inline`}),` `,e,` `,(0,Q.jsx)(`span`,{className:`text-text-subtle`,children:$(n(t.description||t.prompt),60)})]});case`TodoWrite`:{let n=Array.isArray(t.todos)?t.todos:[],r=n.filter(e=>e.status===`completed`).length;return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(W,{className:`size-3 inline`}),` `,e,` `,(0,Q.jsxs)(`span`,{className:`text-text-subtle`,children:[r,`/`,n.length,` done`]})]})}case`AskUserQuestion`:{let n=Array.isArray(t.questions)?t.questions:[],r=!!t.answers;return(0,Q.jsxs)(Q.Fragment,{children:[e,` `,(0,Q.jsxs)(`span`,{className:`text-text-subtle`,children:[n.length,` question`,n.length===1?``:`s`,r?` ✓`:``]})]})}default:return(0,Q.jsx)(Q.Fragment,{children:e})}}function Me({name:e,input:t,projectName:n}){let r=e=>String(e??``),{openTab:i}=f(),a=e=>{n&&i({type:`editor`,title:h(e),metadata:{filePath:e,projectName:n},projectId:n,closable:!0})},o=(e,t,r)=>{i({type:`git-diff`,title:`Diff ${h(e)}`,metadata:{filePath:e,projectName:n,original:t,modified:r},projectId:n??null,closable:!0})};switch(e){case`Bash`:return(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[!!t.description&&(0,Q.jsx)(`p`,{className:`text-text-subtle italic`,children:r(t.description)}),(0,Q.jsx)(`pre`,{className:`font-mono text-text-secondary overflow-x-auto whitespace-pre-wrap break-all`,children:r(t.command)})]});case`Read`:case`Write`:case`Edit`:case`MultiEdit`:case`NotebookEdit`:{let n=r(t.file_path);return(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsxs)(`button`,{type:`button`,className:`font-mono text-text-secondary break-all hover:text-primary hover:underline text-left flex items-center gap-1`,onClick:()=>a(n),title:`Open file in editor`,children:[(0,Q.jsx)(u,{className:`size-3 shrink-0`}),n]}),e===`Edit`&&(!!t.old_string||!!t.new_string)&&(0,Q.jsxs)(`button`,{type:`button`,className:`text-text-subtle hover:text-primary hover:underline text-left flex items-center gap-1`,onClick:()=>o(n,r(t.old_string),r(t.new_string)),title:`View diff in new tab`,children:[(0,Q.jsx)(l,{className:`size-3 shrink-0`}),`View Diff`]}),e===`Write`&&!!t.content&&(0,Q.jsx)(`pre`,{className:`font-mono text-text-subtle overflow-x-auto max-h-32 whitespace-pre-wrap`,children:$(r(t.content),300)})]})}case`Glob`:return(0,Q.jsxs)(`p`,{className:`font-mono text-text-secondary`,children:[r(t.pattern),t.path?` in ${r(t.path)}`:``]});case`Grep`:return(0,Q.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,Q.jsxs)(`p`,{className:`font-mono text-text-secondary`,children:[`/`,r(t.pattern),`/`]}),!!t.path&&(0,Q.jsxs)(`p`,{className:`text-text-subtle`,children:[`in `,r(t.path)]})]});case`TodoWrite`:return(0,Q.jsx)(Ne,{todos:t.todos??[]});case`Agent`:case`Task`:return(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[!!t.description&&(0,Q.jsx)(`p`,{className:`text-text-secondary font-medium`,children:r(t.description)}),!!t.subagent_type&&(0,Q.jsxs)(`p`,{className:`text-text-subtle`,children:[`Type: `,r(t.subagent_type)]}),!!t.prompt&&(0,Q.jsx)(Le,{content:r(t.prompt),maxHeight:`max-h-48`})]});case`ToolSearch`:return(0,Q.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,Q.jsx)(`p`,{className:`font-mono text-text-secondary`,children:r(t.query)}),!!t.max_results&&(0,Q.jsxs)(`p`,{className:`text-text-subtle`,children:[`Max results: `,r(t.max_results)]})]});case`WebFetch`:return(0,Q.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,Q.jsxs)(`a`,{href:r(t.url),target:`_blank`,rel:`noopener noreferrer`,className:`font-mono text-primary hover:underline break-all flex items-center gap-1`,children:[(0,Q.jsx)(H,{className:`size-3 shrink-0`}),r(t.url)]}),!!t.prompt&&(0,Q.jsx)(`p`,{className:`text-text-subtle`,children:$(r(t.prompt),100)})]});case`AskUserQuestion`:{let e=t.questions??[],n=t.answers??{};return(0,Q.jsx)(`div`,{className:`space-y-2`,children:e.map((e,t)=>(0,Q.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,Q.jsxs)(`p`,{className:`text-text-primary font-medium`,children:[e.header?`${e.header}: `:``,e.question]}),(0,Q.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:e.options.map((t,r)=>(0,Q.jsx)(`span`,{className:`inline-block rounded px-1.5 py-0.5 text-xs border ${(n[e.question]??``).split(`, `).includes(t.label)?`border-accent bg-accent/20 text-text-primary`:`border-border text-text-subtle`}`,children:t.label},r))}),n[e.question]&&(0,Q.jsxs)(`p`,{className:`text-accent text-xs`,children:[`Answer: `,n[e.question]]})]},t))})}default:return(0,Q.jsx)(`pre`,{className:`overflow-x-auto text-text-secondary font-mono whitespace-pre-wrap break-all`,children:JSON.stringify(t,null,2)})}}function Ne({todos:e}){return(0,Q.jsx)(`div`,{className:`space-y-0.5`,children:e.map((e,t)=>(0,Q.jsxs)(`div`,{className:`flex items-start gap-1.5`,children:[(0,Q.jsx)(`span`,{className:`shrink-0 mt-0.5 ${e.status===`completed`?`text-green-400`:e.status===`in_progress`?`text-yellow-400`:`text-text-subtle`}`,children:e.status===`completed`?`✓`:e.status===`in_progress`?`▶`:`○`}),(0,Q.jsx)(`span`,{className:e.status===`completed`?`line-through text-text-subtle`:`text-text-secondary`,children:e.content})]},t))})}function Pe({toolName:e,output:t}){let[n,r]=(0,q.useState)(!1),i=(0,q.useMemo)(()=>{if(e!==`Agent`&&e!==`Task`)return null;try{let e=JSON.parse(t);if(Array.isArray(e)){let t=e.filter(e=>e.type===`text`&&e.text).map(e=>e.text).join(`
3
3
 
4
- `);if(t)return t}if(typeof e==`string`)return e}catch{if(t&&!t.startsWith(`[{`))return t}return null},[e,t]);return i?(0,Q.jsxs)(`div`,{className:`border-t border-border pt-1.5 space-y-1`,children:[(0,Q.jsx)(Le,{content:i,maxHeight:`max-h-60`}),(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>r(!n),className:`flex items-center gap-1 text-[10px] text-text-subtle hover:text-text-secondary transition-colors`,children:[(0,Q.jsx)(B,{className:`size-3`}),n?`Hide`:`Show`,` raw`]}),n&&(0,Q.jsx)(`pre`,{className:`overflow-x-auto text-text-subtle font-mono max-h-40 whitespace-pre-wrap break-all text-[10px]`,children:t})]}):(0,Q.jsx)(Fe,{output:t})}function Fe({output:e}){let t=e.split(`
5
- `).length,n=t>3||e.length>200,[r,i]=(0,q.useState)(n);return(0,Q.jsxs)(`div`,{className:`border-t border-border pt-1.5`,children:[n&&(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>i(!r),className:`flex items-center gap-1 text-[10px] text-text-subtle hover:text-text-secondary transition-colors mb-1`,children:[r?(0,Q.jsx)(w,{className:`size-3`}):(0,Q.jsx)(o,{className:`size-3`}),`Output (`,t,` lines)`]}),(0,Q.jsx)(`pre`,{className:`overflow-x-auto text-text-subtle font-mono whitespace-pre-wrap break-all ${r?`max-h-16 overflow-hidden`:`max-h-60`}`,children:e})]})}function Ie({events:e,projectName:t}){let n=[],r=``;for(let t of e)if(t.type===`text`)r+=t.content;else if(t.type===`tool_use`)r&&=(n.push({kind:`text`,content:r}),``),n.push({kind:`tool`,tool:t});else if(t.type===`tool_result`){let e=t.toolUseId,r=e?n.find(t=>t.kind===`tool`&&t.tool.type===`tool_use`&&t.tool.toolUseId===e&&!t.result):n.findLast(e=>e.kind===`tool`&&!e.result);r&&(r.result=t)}return r&&n.push({kind:`text`,content:r}),(0,Q.jsx)(`div`,{className:`border-l-2 border-accent/20 pl-2 space-y-1 mt-1`,children:n.map((e,n)=>e.kind===`text`?(0,Q.jsx)(`div`,{className:`text-text-secondary text-[11px]`,children:(0,Q.jsx)(Le,{content:e.content,maxHeight:`max-h-24`})},`st-${n}`):(0,Q.jsx)(Ae,{tool:e.tool,result:e.result,completed:!!e.result,projectName:t},`sc-${n}`))})}function Le({content:e,maxHeight:t=`max-h-48`}){return(0,Q.jsx)(F,{content:e,className:`text-text-secondary overflow-auto ${t}`})}function $(e,t=50){return e?e.length>t?e.slice(0,t)+`…`:e:``}function Re(e){let[t,n]=(0,q.useState)({}),[r,i]=(0,q.useState)({}),[a,o]=(0,q.useState)(0),s=(0,q.useCallback)((e,t)=>{n(n=>({...n,[e]:[t]})),i(t=>({...t,[e]:``}))},[]),c=(0,q.useCallback)((e,t)=>{n(n=>{let r=n[e]||[];return{...n,[e]:r.includes(t)?r.filter(e=>e!==t):[...r,t]}})},[]),l=(0,q.useCallback)((e,t)=>{i(n=>({...n,[e]:t})),t&&n(t=>({...t,[e]:[]}))},[]),u=(0,q.useCallback)(e=>(t[e]?.length??0)>0||(r[e]?.trim().length??0)>0,[t,r]);return{answers:t,customInputs:r,activeTab:a,setActiveTab:o,handleSingleSelect:s,handleMultiSelect:c,handleCustomInput:l,hasAnswer:u,allAnswered:(0,q.useMemo)(()=>e.every((e,t)=>u(t)),[e,u]),getFinalAnswer:(0,q.useCallback)(e=>r[e]?.trim()||(t[e]??[]).join(`, `),[t,r]),goToNextTab:(0,q.useCallback)(()=>o(t=>Math.min(t+1,e.length-1)),[e.length]),goToPrevTab:(0,q.useCallback)(()=>o(e=>Math.max(e-1,0)),[])}}function ze(e){let[t,n]=(0,q.useState)(0),r=(0,q.useRef)(null);return(0,q.useEffect)(()=>n(0),[e.activeTab]),(0,q.useEffect)(()=>{if(!e.enabled)return;let i=r=>{let i=document.activeElement===e.customInputRef.current;if(!i&&r.key>=`1`&&r.key<=`9`){r.preventDefault();let t=parseInt(r.key)-1;t<e.totalOptions-1&&(n(t),e.onSelectOption(t));return}if(!i&&(r.key===`o`||r.key===`O`||r.key===`0`)){r.preventDefault(),e.customInputRef.current?.focus(),n(e.totalOptions-1);return}if(r.key===`Tab`&&e.questions.length>1){r.preventDefault(),r.shiftKey?e.goToPrevTab():e.goToNextTab();return}if(!i){if(r.key===`ArrowLeft`){r.preventDefault(),e.goToPrevTab();return}if(r.key===`ArrowRight`){r.preventDefault(),e.goToNextTab();return}if(r.key===`ArrowUp`){r.preventDefault(),n(e=>Math.max(0,e-1));return}if(r.key===`ArrowDown`){r.preventDefault(),n(t=>Math.min(e.totalOptions-1,t+1));return}if(r.key===` `){r.preventDefault(),e.onSelectOption(t);return}}if(r.key===`Enter`){r.preventDefault(),e.allAnswered?e.onSubmit():e.hasAnswer(e.activeTab)&&e.goToNextTab();return}r.key===`Escape`&&i&&e.customInputRef.current?.blur()},a=r.current;return a&&(a.addEventListener(`keydown`,i),a.setAttribute(`tabindex`,`0`),a.contains(document.activeElement)||a.focus()),()=>{a?.removeEventListener(`keydown`,i)}},[e,t]),{focusedOption:t,setFocusedOption:n,containerRef:r}}function Be({questions:e,onSubmit:t,onSkip:n}){let r=(0,q.useRef)(null),i=Re(e),a=e[i.activeTab],o=a?a.options.length+1:0,s=e.length>1,c=(0,q.useCallback)(()=>{if(!i.allAnswered)return;let n={};e.forEach((e,t)=>{n[e.question]=i.getFinalAnswer(t)}),t(n)},[i.allAnswered,i.getFinalAnswer,e,t]),l=(0,q.useCallback)(e=>{if(!(!a||e<0))if(e<a.options.length){let t=a.options[e]?.label;if(!t)return;a.multiSelect?i.handleMultiSelect(i.activeTab,t):i.handleSingleSelect(i.activeTab,t)}else e===a.options.length&&r.current?.focus()},[a,i]),u=ze({questions:e,activeTab:i.activeTab,totalOptions:o,allAnswered:i.allAnswered,hasAnswer:i.hasAnswer,onSelectOption:l,goToNextTab:i.goToNextTab,goToPrevTab:i.goToPrevTab,onSubmit:c,customInputRef:r,enabled:!0}),d=(0,q.useCallback)(e=>{l(e),u.setFocusedOption(e)},[l,u.setFocusedOption]);return(0,Q.jsxs)(`div`,{ref:u.containerRef,className:`rounded-lg border-2 border-primary/30 bg-primary/5 p-3 space-y-3 outline-none animate-in slide-in-from-bottom-2`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between text-sm font-medium text-text-primary`,children:[(0,Q.jsxs)(`span`,{children:[`AI has `,s?`${e.length} questions`:`a question`]}),(0,Q.jsxs)(`span`,{className:`text-[10px] text-text-secondary font-normal`,children:[s?`←→ tabs · `:``,`↑↓ options · 1-`,Math.min(o-1,9),` select · Enter submit`]})]}),s&&(0,Q.jsx)(`div`,{className:`flex gap-1 p-1 bg-background rounded-md overflow-x-auto border border-border`,children:e.map((e,t)=>(0,Q.jsxs)(`button`,{className:`flex items-center gap-1.5 px-3 py-1.5 rounded text-xs whitespace-nowrap transition-all ${i.activeTab===t?`bg-primary text-primary-foreground`:i.hasAnswer(t)?`text-primary bg-transparent`:`text-text-secondary hover:bg-surface-elevated`}`,onClick:()=>{i.setActiveTab(t),u.setFocusedOption(0)},tabIndex:-1,children:[(0,Q.jsx)(`span`,{className:`flex items-center justify-center w-4 h-4 rounded-full text-[10px] font-semibold ${i.activeTab===t?`bg-white/20`:i.hasAnswer(t)?`bg-primary/20 text-primary`:`bg-surface-elevated text-text-secondary`}`,children:i.hasAnswer(t)?`✓`:t+1}),(0,Q.jsx)(`span`,{className:`max-w-[100px] overflow-hidden text-ellipsis`,children:e.header||`Q${t+1}`})]},t))}),a&&(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[!s&&a.header&&(0,Q.jsx)(`div`,{className:`text-[11px] font-semibold uppercase tracking-wide text-text-secondary`,children:a.header}),(0,Q.jsx)(`div`,{className:`text-sm text-text-primary`,children:a.question}),a.multiSelect&&(0,Q.jsx)(`div`,{className:`text-[11px] text-text-secondary`,children:`Select multiple`}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[a.options.map((e,t)=>{let n=(i.answers[i.activeTab]||[]).includes(e.label),r=u.focusedOption===t;return(0,Q.jsxs)(`button`,{onClick:()=>d(t),className:`text-left flex items-start gap-2.5 rounded px-2.5 py-2 text-xs border transition-all ${n?`border-primary bg-primary/10 text-text-primary`:`border-border bg-background text-text-secondary hover:border-primary/40 hover:bg-primary/5`} ${r?`ring-2 ring-primary/40 ring-offset-1 ring-offset-background`:``}`,children:[(0,Q.jsx)(`span`,{className:`flex items-center justify-center w-4.5 h-4.5 rounded text-[10px] font-semibold shrink-0 mt-px ${n?`bg-primary/20 text-primary`:`bg-surface-elevated text-text-secondary`}`,children:t+1}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-0.5 flex-1`,children:[(0,Q.jsx)(`span`,{className:`font-medium text-text-primary`,children:e.label}),e.description&&(0,Q.jsx)(`span`,{className:`text-[11px] text-text-secondary`,children:e.description})]})]},t)}),(0,Q.jsxs)(`div`,{className:`flex items-start gap-2.5 rounded px-2.5 py-2 text-xs border border-dashed transition-all border-border bg-transparent ${u.focusedOption===o-1?`ring-2 ring-primary/40 ring-offset-1 ring-offset-background`:``}`,children:[(0,Q.jsx)(`span`,{className:`flex items-center justify-center w-4.5 h-4.5 rounded bg-surface-elevated text-text-secondary text-[10px] font-semibold shrink-0 mt-px`,children:`O`}),(0,Q.jsx)(`input`,{ref:r,type:`text`,className:`flex-1 px-2 py-1 text-xs bg-surface border border-border rounded text-text-primary outline-none placeholder:text-text-subtle focus:border-primary`,placeholder:`Other (press O to type)...`,value:i.customInputs[i.activeTab]||``,onChange:e=>i.handleCustomInput(i.activeTab,e.target.value),onFocus:()=>u.setFocusedOption(o-1)})]})]})]}),(0,Q.jsxs)(`div`,{className:`flex gap-2 justify-end pt-1`,children:[s&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`button`,{className:`px-3 py-1.5 text-xs rounded border border-border bg-background text-text-primary hover:bg-surface-elevated disabled:opacity-40 disabled:cursor-not-allowed transition-colors`,onClick:i.goToPrevTab,disabled:i.activeTab===0,tabIndex:-1,children:`← Prev`}),(0,Q.jsx)(`button`,{className:`px-3 py-1.5 text-xs rounded border border-border bg-background text-text-primary hover:bg-surface-elevated disabled:opacity-40 disabled:cursor-not-allowed transition-colors`,onClick:i.goToNextTab,disabled:i.activeTab===e.length-1,tabIndex:-1,children:`Next →`})]}),(0,Q.jsx)(`button`,{onClick:n,className:`px-4 py-1.5 rounded border border-border bg-background text-text-secondary text-xs hover:bg-surface-elevated transition-colors`,tabIndex:-1,children:`Skip`}),(0,Q.jsxs)(`button`,{onClick:c,disabled:!i.allAnswered,className:`px-4 py-1.5 rounded bg-primary text-primary-foreground text-xs font-medium hover:bg-primary/80 transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,tabIndex:-1,children:[`Submit `,i.allAnswered?`✓`:`(${e.filter((e,t)=>i.hasAnswer(t)).length}/${e.length})`]})]})]})}function Ve({messages:e,messagesLoading:t,pendingApproval:n,onApprovalResponse:r,isStreaming:i,streamingStatus:a,connectingElapsed:o,thinkingWarningThreshold:s,projectName:c,onFork:l}){return t?(0,Q.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,Q.jsx)(R,{className:`size-10 text-text-subtle animate-pulse`}),(0,Q.jsx)(`p`,{className:`text-sm`,children:`Loading messages...`})]}):e.length===0&&!i?(0,Q.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,Q.jsx)(R,{className:`size-10 text-text-subtle`}),(0,Q.jsx)(`p`,{className:`text-sm`,children:`Send a message to start the conversation`})]}):(0,Q.jsxs)(De,{className:`flex-1 overflow-y-auto`,resize:`smooth`,initial:`instant`,children:[(0,Q.jsxs)(De.Content,{className:`p-4 space-y-4`,children:[e.filter(e=>{let t=e.content&&e.content.trim().length>0,n=e.events&&e.events.length>0;return t||n}).map(e=>(0,Q.jsx)(Ue,{message:e,isStreaming:i&&e.id.startsWith(`streaming-`),projectName:c,onFork:e.role===`user`&&l?()=>l(e.content):void 0},e.id)),n&&(n.tool===`AskUserQuestion`?(0,Q.jsx)(it,{approval:n,onRespond:r}):(0,Q.jsx)(rt,{approval:n,onRespond:r})),i&&(0,Q.jsx)(tt,{lastMessage:e[e.length-1],streamingStatus:a,elapsed:o,warningThreshold:s})]}),(0,Q.jsx)(He,{})]})}function He(){let{isAtBottom:e,scrollToBottom:t}=Oe();return e?null:(0,Q.jsxs)(`button`,{onClick:()=>t(),className:`absolute bottom-2 left-1/2 -translate-x-1/2 flex items-center gap-1 px-3 py-1 rounded-full bg-surface-elevated border border-border text-xs text-text-secondary hover:text-foreground shadow-lg transition-all`,children:[(0,Q.jsx)(o,{className:`size-3`}),`Scroll to bottom`]})}function Ue({message:e,isStreaming:t,projectName:n,onFork:r}){return e.role===`user`?(0,Q.jsx)(Ye,{content:e.content,projectName:n,onFork:r}):e.role===`system`?(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg bg-red-500/10 border border-red-500/20 px-3 py-2 text-sm text-red-400`,children:[(0,Q.jsx)(A,{className:`size-4 shrink-0`}),(0,Q.jsx)(`p`,{children:e.content})]}):(0,Q.jsx)(`div`,{className:`flex flex-col gap-2`,children:e.events&&e.events.length>0?(0,Q.jsx)(Qe,{events:e.events,isStreaming:t,projectName:n}):e.content&&(0,Q.jsx)(`div`,{className:`text-sm text-text-primary`,children:(0,Q.jsx)(nt,{content:e.content,projectName:n})})})}var We=new Set([`.png`,`.jpg`,`.jpeg`,`.gif`,`.webp`]);function Ge(e){let t=e.match(/^\[Attached file: (.+?)\]\n\n?/);if(t)return{files:[t[1]],text:e.slice(t[0].length)};let n=e.match(/^\[Attached files:\n([\s\S]+?)\]\n\n?/);return n?{files:n[1].split(`
6
- `).map(e=>e.trim()).filter(Boolean),text:e.slice(n[0].length)}:{files:[],text:e}}function Ke(e,t){let n=m(e);return`/api/project/${encodeURIComponent(t??`_`)}/chat/uploads/${encodeURIComponent(n)}`}function qe(e){let t=e.lastIndexOf(`.`);return t===-1?!1:We.has(e.slice(t).toLowerCase())}function Je(e){return e.toLowerCase().endsWith(`.pdf`)}function Ye({content:e,projectName:t,onFork:r}){let{files:i,text:a}=(0,q.useMemo)(()=>Ge(e),[e]);return(0,Q.jsx)(`div`,{className:`flex justify-end group/user`,children:(0,Q.jsxs)(`div`,{className:`rounded-lg bg-primary/10 px-3 py-2 text-sm text-text-primary max-w-[85%] space-y-2 relative`,children:[i.length>0&&(0,Q.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:i.map((e,n)=>qe(e)?(0,Q.jsx)(Xe,{src:Ke(e,t),alt:m(e)||`image`},n):Je(e)?(0,Q.jsx)(Ze,{src:Ke(e,t),filename:m(e)||`document.pdf`,mimeType:`application/pdf`},n):(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5 rounded-md border border-border bg-background/50 px-2 py-1 text-xs text-text-secondary`,children:[(0,Q.jsx)(C,{className:`size-3.5 shrink-0`}),(0,Q.jsx)(`span`,{className:`truncate max-w-40`,children:m(e)})]},n))}),a&&(0,Q.jsx)(`p`,{className:`whitespace-pre-wrap break-words`,children:a}),r&&(0,Q.jsx)(`button`,{onClick:r,title:`Retry from this message (fork session)`,className:`absolute -left-8 top-1/2 -translate-y-1/2 opacity-0 group-hover/user:opacity-100 transition-opacity size-6 flex items-center justify-center rounded bg-surface border border-border text-text-subtle hover:text-text-primary hover:bg-surface-elevated`,children:(0,Q.jsx)(n,{className:`size-3`})})]})})}function Xe({src:e,alt:t}){let[n,r]=(0,q.useState)(null),[i,a]=(0,q.useState)(!1);return(0,q.useEffect)(()=>{let t,n=g();return fetch(e,{headers:n?{Authorization:`Bearer ${n}`}:{}}).then(e=>{if(!e.ok)throw Error(`Failed to load`);return e.blob()}).then(e=>{let n=URL.createObjectURL(e);t=n,r(n)}).catch(()=>a(!0)),()=>{t&&URL.revokeObjectURL(t)}},[e]),i?(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5 rounded-md border border-border bg-background/50 px-2 py-1 text-xs text-text-secondary`,children:[(0,Q.jsx)(U,{className:`size-3.5 shrink-0`}),(0,Q.jsx)(`span`,{className:`truncate max-w-40`,children:t})]}):n?(0,Q.jsx)(`a`,{href:n,target:`_blank`,rel:`noopener noreferrer`,className:`block`,children:(0,Q.jsx)(`img`,{src:n,alt:t,className:`rounded-md max-h-48 max-w-full object-contain border border-border`})}):(0,Q.jsx)(`div`,{className:`rounded-md bg-surface border border-border h-24 w-32 animate-pulse`})}function Ze({src:e,filename:t,mimeType:n}){let[r,i]=(0,q.useState)(!1);return(0,Q.jsxs)(`button`,{type:`button`,onClick:(0,q.useCallback)(async()=>{i(!0);try{let t=g(),r=await fetch(e,{headers:t?{Authorization:`Bearer ${t}`}:{}});if(!r.ok)throw Error(`Failed to load`);let i=await r.blob(),a=URL.createObjectURL(new Blob([i],{type:n}));window.open(a,`_blank`),setTimeout(()=>URL.revokeObjectURL(a),6e4)}catch{window.open(e,`_blank`)}finally{i(!1)}},[e,n]),disabled:r,className:`flex items-center gap-1.5 rounded-md border border-border bg-background/50 px-2 py-1 text-xs text-text-secondary hover:bg-surface hover:text-text-primary transition-colors cursor-pointer disabled:opacity-50`,children:[(0,Q.jsx)(C,{className:`size-3.5 shrink-0 text-red-400`}),(0,Q.jsx)(`span`,{className:`truncate max-w-40`,children:t}),r&&(0,Q.jsx)(`span`,{className:`animate-spin text-[10px]`,children:`...`})]})}function Qe({events:e,isStreaming:t,projectName:n}){let r=[],i=``,a=``;for(let t=0;t<e.length;t++){let n=e[t];if(n.type===`thinking`){i&&=(r.push({kind:`text`,content:i}),``),a+=n.content;continue}a&&=(r.push({kind:`thinking`,content:a}),``),n.type===`text`?i+=n.content:n.type===`tool_use`?(i&&=(r.push({kind:`text`,content:i}),``),r.push({kind:`tool`,tool:n})):n.type===`tool_result`||(i&&=(r.push({kind:`text`,content:i}),``),r.push({kind:`tool`,tool:n}))}a&&r.push({kind:`thinking`,content:a}),i&&r.push({kind:`text`,content:i});let o=e.filter(e=>e.type===`tool_result`);for(let e of o){let t=e.toolUseId;if(t){let n=r.find(e=>e.kind===`tool`&&e.tool.type===`tool_use`&&e.tool.toolUseId===t);if(n){n.result=e;continue}}let n=r.find(e=>e.kind===`tool`&&!e.result);n&&(n.result=e)}for(let e=0;e<r.length;e++){let n=r[e];if(n.kind===`tool`&&!n.result){let i=!1;if(n.tool.type===`tool_use`&&n.tool.tool===`Read`){let t=n.tool.input?.file_path;t&&(i=r.slice(e+1).some(e=>e.kind===`tool`&&e.result&&e.tool.type===`tool_use`&&e.tool.tool===`Edit`&&e.tool.input?.file_path===t))}n.completed=i||!t}}return(0,Q.jsx)(Q.Fragment,{children:r.map((e,i)=>{if(e.kind===`thinking`)return(0,Q.jsx)($e,{content:e.content,isStreaming:t&&i===r.length-1},`think-${i}`);if(e.kind===`text`){let a=t&&i===r.length-1;return(0,Q.jsx)(`div`,{className:`text-sm text-text-primary`,children:(0,Q.jsx)(et,{content:e.content,animate:a,projectName:n})},`text-${i}`)}return(0,Q.jsx)(Ae,{tool:e.tool,result:e.result,completed:e.completed,projectName:n},`tool-${i}`)})})}function $e({content:e,isStreaming:t}){let[n,r]=(0,q.useState)(t);return(0,q.useEffect)(()=>{!t&&e.length>0&&r(!1)},[t,e.length]),(0,Q.jsxs)(`div`,{className:`rounded border border-border/50 bg-surface/30 text-xs`,children:[(0,Q.jsxs)(`button`,{onClick:()=>r(!n),className:`flex items-center gap-2 px-2 py-1.5 w-full text-left hover:bg-surface transition-colors text-text-subtle`,children:[t?(0,Q.jsx)(v,{className:`size-3 animate-spin`}):(0,Q.jsx)(w,{className:`size-3 transition-transform ${n?`rotate-90`:``}`}),(0,Q.jsxs)(`span`,{children:[`Thinking`,t?`...`:``]}),!t&&(0,Q.jsx)(`span`,{className:`text-text-subtle/50 ml-auto`,children:e.length>100?`${Math.round(e.length/4)} tokens`:``})]}),n&&(0,Q.jsx)(`div`,{className:`px-2 pb-2 text-text-subtle/80 whitespace-pre-wrap max-h-60 overflow-y-auto text-[11px] leading-relaxed`,children:e})]})}function et({content:e,animate:t,projectName:n}){return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(nt,{content:e,projectName:n}),t&&(0,Q.jsx)(`span`,{className:`text-text-subtle text-sm animate-pulse`,children:`Thinking...`})]})}function tt({lastMessage:e,streamingStatus:t,elapsed:n,warningThreshold:r=15}){let i=!e||e.role!==`assistant`,a=e?.events?.length?e.events[e.events.length-1].type===`tool_result`:!1;return!i&&!a?null:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1 text-sm`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-text-subtle`,children:[(0,Q.jsx)(v,{className:`size-3 animate-spin`}),(0,Q.jsxs)(`span`,{children:[`Thinking`,i&&(n??0)>0&&(0,Q.jsxs)(`span`,{className:`text-text-subtle/60`,children:[`... (`,n,`s)`]})]})]}),i&&(n??0)>=r&&(0,Q.jsx)(`p`,{className:`text-xs text-yellow-500/80 ml-5`,children:`Taking longer than usual — may be rate-limited or API slow. Try sending a new message to retry.`})]})}function nt({content:e,projectName:t}){return(0,Q.jsx)(F,{content:e,projectName:t,codeActions:!0})}function rt({approval:e,onRespond:t}){return(0,Q.jsxs)(`div`,{className:`rounded-lg border-2 border-yellow-500/40 bg-yellow-500/10 p-3 space-y-2`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-yellow-400 text-sm font-medium`,children:[(0,Q.jsx)(ne,{className:`size-4`}),(0,Q.jsx)(`span`,{children:`Tool Approval Required`})]}),(0,Q.jsx)(`div`,{className:`text-xs text-text-primary`,children:(0,Q.jsx)(`span`,{className:`font-medium`,children:e.tool})}),(0,Q.jsx)(`pre`,{className:`text-xs font-mono text-text-secondary overflow-x-auto bg-background rounded p-2 border border-border`,children:JSON.stringify(e.input,null,2)}),(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(`button`,{onClick:()=>t(e.requestId,!0),className:`px-4 py-1.5 rounded bg-green-600 text-white text-xs font-medium hover:bg-green-500 transition-colors`,children:`Allow`}),(0,Q.jsx)(`button`,{onClick:()=>t(e.requestId,!1),className:`px-4 py-1.5 rounded bg-red-600 text-white text-xs font-medium hover:bg-red-500 transition-colors`,children:`Deny`})]})]})}function it({approval:e,onRespond:t}){return(0,Q.jsx)(Be,{questions:e.input.questions??[],onSubmit:n=>t(e.requestId,!0,n),onSkip:()=>t(e.requestId,!1)})}var at=new Set([`image/png`,`image/jpeg`,`image/gif`,`image/webp`]),ot=new Set([`application/pdf`]),st=[`text/`,`application/json`,`application/xml`,`application/javascript`,`application/typescript`,`application/x-yaml`,`application/toml`,`application/x-sh`],ct=new Set(`.ts,.tsx,.js,.jsx,.mjs,.cjs,.py,.rb,.go,.rs,.java,.kt,.swift,.c,.cpp,.h,.hpp,.cs,.json,.yaml,.yml,.toml,.xml,.md,.mdx,.txt,.csv,.tsv,.html,.css,.scss,.less,.sass,.sh,.bash,.zsh,.fish,.sql,.graphql,.gql,.env,.ini,.cfg,.conf,.dockerfile,.makefile,.vue,.svelte,.astro,.ipynb`.split(`,`));function lt(e){return at.has(e.type)}function ut(e){if(at.has(e.type)||ot.has(e.type)||st.some(t=>e.type.startsWith(t)))return!0;let t=dt(e.name);return!!(t&&ct.has(t))}function dt(e){let t=e.lastIndexOf(`.`);return t===-1?``:e.slice(t).toLowerCase()}function ft({attachments:e,onRemove:t}){return e.length===0?null:(0,Q.jsx)(`div`,{className:`flex flex-wrap gap-1.5 px-2 md:px-4 pt-2`,children:e.map(e=>(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5 rounded-md border border-border bg-surface px-2 py-1 text-xs text-text-secondary max-w-48`,children:[e.previewUrl?(0,Q.jsx)(`img`,{src:e.previewUrl,alt:e.name,className:`size-5 rounded object-cover shrink-0`}):e.isImage?(0,Q.jsx)(U,{className:`size-3.5 shrink-0 text-text-subtle`}):(0,Q.jsx)(C,{className:`size-3.5 shrink-0 text-text-subtle`}),(0,Q.jsx)(`span`,{className:`truncate`,children:e.name}),e.status===`uploading`?(0,Q.jsx)(v,{className:`size-3 shrink-0 animate-spin text-text-subtle`}):e.status===`error`?(0,Q.jsx)(`span`,{className:`text-red-500 shrink-0`,title:`Upload failed`,children:`!`}):null,(0,Q.jsx)(`button`,{type:`button`,onClick:()=>t(e.id),className:`shrink-0 rounded-sm p-0.5 hover:bg-border/50 transition-colors`,"aria-label":`Remove ${e.name}`,children:(0,Q.jsx)(O,{className:`size-3`})})]},e.id))})}function pt(e){let t=[];function n(e){for(let r of e)t.push(r),r.children&&n(r.children)}return n(e),t}function mt({items:e,filter:t,onSelect:n,onClose:r,visible:i}){let[a,o]=(0,q.useState)(0),s=(0,q.useRef)(null),c=(()=>{if(!t)return e.slice(0,50);let n=t.toLowerCase();return e.filter(e=>e.path.toLowerCase().includes(n)||e.name.toLowerCase().includes(n)).slice(0,50)})();(0,q.useEffect)(()=>{o(0)},[t]),(0,q.useEffect)(()=>{let e=s.current;e&&e.children[a]?.scrollIntoView({block:`nearest`})},[a]);let l=(0,q.useCallback)(e=>{if(!i||c.length===0)return!1;switch(e.key){case`ArrowUp`:return e.preventDefault(),o(e=>e>0?e-1:c.length-1),!0;case`ArrowDown`:return e.preventDefault(),o(e=>e<c.length-1?e+1:0),!0;case`Enter`:case`Tab`:return e.preventDefault(),c[a]&&n(c[a]),!0;case`Escape`:return e.preventDefault(),r(),!0}return!1},[i,c,a,n,r]);return(0,q.useEffect)(()=>{if(!i)return;let e=e=>{l(e)&&e.stopPropagation()};return document.addEventListener(`keydown`,e,!0),()=>document.removeEventListener(`keydown`,e,!0)},[i,l]),!i||c.length===0?null:(0,Q.jsx)(`div`,{className:`max-h-52 overflow-y-auto border-b border-border bg-surface`,children:(0,Q.jsx)(`div`,{ref:s,className:`py-1`,children:c.map((e,t)=>(0,Q.jsxs)(`button`,{className:`flex items-center gap-2 w-full px-3 py-1.5 text-left transition-colors ${t===a?`bg-primary/10 text-primary`:`hover:bg-surface-hover text-text-primary`}`,onMouseEnter:()=>o(t),onClick:()=>n(e),children:[(0,Q.jsx)(`span`,{className:`shrink-0`,children:e.type===`directory`?(0,Q.jsx)(T,{className:`size-4 text-amber-500`}):(0,Q.jsx)(D,{className:`size-4 text-blue-400`})}),(0,Q.jsx)(`span`,{className:`text-sm truncate`,children:e.path})]},e.path))})})}function ht({onSend:e,isStreaming:t,onCancel:n,disabled:r,projectName:i,onSlashStateChange:a,onSlashItemsLoaded:o,slashSelected:s,onFileStateChange:c,onFileItemsLoaded:l,fileSelected:u,externalFiles:d,initialValue:f}){let[m,v]=(0,q.useState)(f??``),[y,b]=(0,q.useState)([]),x=(0,q.useRef)(null),S=(0,q.useRef)(null),C=(0,q.useRef)(null),w=(0,q.useRef)([]),T=(0,q.useRef)([]);(0,q.useEffect)(()=>{f&&(v(f),setTimeout(()=>{let e=x.current;e&&(e.focus(),e.selectionStart=e.selectionEnd=e.value.length)},50))},[f]),(0,q.useEffect)(()=>{if(!i){w.current=[],o?.([]);return}_.get(`${h(i)}/chat/slash-items`).then(e=>{w.current=e,o?.(e)}).catch(()=>{w.current=[],o?.([])})},[i]),(0,q.useEffect)(()=>{if(!i){T.current=[],l?.([]);return}_.get(`${h(i)}/files/tree?depth=5`).then(e=>{let t=pt(e);T.current=t,l?.(t)}).catch(()=>{T.current=[],l?.([])})},[i]),(0,q.useEffect)(()=>{if(!s)return;let e=x.current,t=e?.selectionStart??m.length,n=m.slice(0,t),r=m.slice(t),i=n.replace(/(?:^|\s)\/\S*$/,e=>`${e.startsWith(`/`)?``:e[0]}/${s.name} `);v(i+r),a?.(!1,``),c?.(!1,``),e&&(e.focus(),setTimeout(()=>{e.selectionStart=e.selectionEnd=i.length},0))},[s]),(0,q.useEffect)(()=>{if(!u)return;let e=x.current;if(!e)return;let t=e.selectionStart,n=m.slice(0,t),r=m.slice(t),i=n.match(/@(\S*)$/);if(i){let t=n.length-i[0].length;v(n.slice(0,t)+`@${u.path} `+r);let a=t+u.path.length+2;setTimeout(()=>{e.selectionStart=e.selectionEnd=a,e.focus()},0)}else{let t=m+`@${u.path} `;v(t),setTimeout(()=>{e.selectionStart=e.selectionEnd=t.length,e.focus()},0)}c?.(!1,``)},[u]),(0,q.useEffect)(()=>{!d||d.length===0||D(d)},[d]);let E=(0,q.useCallback)(async e=>{if(!i)return null;try{let t=new FormData;t.append(`files`,e);let n={},r=g();r&&(n.Authorization=`Bearer ${r}`);let a=await(await fetch(`${h(i)}/chat/upload`,{method:`POST`,headers:n,body:t})).json();return a.ok&&Array.isArray(a.data)&&a.data.length>0?a.data[0].path:null}catch{return null}},[i]),D=(0,q.useCallback)(e=>{for(let t of e){if(!ut(t)){v(e=>e+(e.length>0&&!e.endsWith(` `)?` `:``)+t.name);continue}let e=p(),n=lt(t),r=n?URL.createObjectURL(t):void 0,i={id:e,name:t.name,file:t,isImage:n,previewUrl:r,status:`uploading`};b(e=>[...e,i]),E(t).then(t=>{b(n=>n.map(n=>n.id===e?{...n,serverPath:t??void 0,status:t?`ready`:`error`}:n))})}(S.current??x.current)?.focus()},[E]),O=(0,q.useCallback)(e=>{b(t=>{let n=t.find(t=>t.id===e);return n?.previewUrl&&URL.revokeObjectURL(n.previewUrl),t.filter(t=>t.id!==e)})},[]),k=(0,q.useCallback)(()=>{let t=m.trim(),n=y.filter(e=>e.status===`ready`);if(!(!t&&n.length===0)&&!r){a?.(!1,``),c?.(!1,``),e(t,n),v(``);for(let e of y)e.previewUrl&&URL.revokeObjectURL(e.previewUrl);b([]),x.current&&(x.current.style.height=`auto`),S.current&&(S.current.style.height=`auto`)}},[m,y,r,e,a,c]),A=(0,q.useCallback)(e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),k())},[k]),j=(0,q.useCallback)((e,t)=>{let n=e.slice(0,t),r=n.match(/(?:^|\s)\/(\S*)$/);if(r&&w.current.length>0){a?.(!0,r[1]??``),c?.(!1,``);return}let i=n.match(/@(\S*)$/);if(i&&T.current.length>0){c?.(!0,i[1]??``),a?.(!1,``);return}a?.(!1,``),c?.(!1,``)},[a,c]),M=(0,q.useCallback)(e=>{v(e),setTimeout(()=>{j(e,x.current?.selectionStart??e.length)},0)},[j]),N=(0,q.useCallback)(e=>{let t=e?.target??x.current;t&&(t.style.height=`auto`,t.style.height=Math.min(t.scrollHeight,160)+`px`)},[]),P=(0,q.useCallback)(e=>{let t=e.clipboardData?.items;if(!t)return;let n=[];for(let e of t)if(e.kind===`file`){let t=e.getAsFile();t&&n.push(t)}n.length>0&&(e.preventDefault(),D(n))},[D]),F=(0,q.useCallback)(e=>{e.preventDefault();let t=Array.from(e.dataTransfer.files);t.length>0&&D(t)},[D]),I=(0,q.useCallback)(e=>{e.preventDefault()},[]),R=(0,q.useCallback)(()=>{C.current?.click()},[]),z=(0,q.useCallback)(e=>{let t=Array.from(e.target.files??[]);t.length>0&&D(t),e.target.value=``},[D]),B=m.trim().length>0||y.some(e=>e.status===`ready`),V=t&&!B;return(0,Q.jsxs)(`div`,{className:`p-2 md:p-3 bg-background`,children:[(0,Q.jsxs)(`div`,{className:`border border-border rounded-xl md:rounded-2xl bg-surface shadow-sm cursor-text`,onClick:()=>!r&&(S.current??x.current)?.focus(),children:[(0,Q.jsx)(ft,{attachments:y,onRemove:O}),(0,Q.jsxs)(`div`,{className:`flex items-end gap-1 md:hidden px-2 py-2`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),R()},disabled:r,className:`flex items-center justify-center size-7 shrink-0 rounded-full text-text-subtle hover:text-text-primary transition-colors disabled:opacity-50`,"aria-label":`Attach file`,children:(0,Q.jsx)(G,{className:`size-4`})}),(0,Q.jsx)(`textarea`,{ref:S,value:m,onChange:e=>{M(e.target.value),N(e)},onKeyDown:A,onPaste:P,onDrop:F,onDragOver:I,placeholder:t?`Follow-up...`:`Ask anything...`,disabled:r,rows:1,className:`flex-1 resize-none bg-transparent py-1.5 text-sm text-foreground placeholder:text-text-subtle focus:outline-none disabled:opacity-50 max-h-20`}),V?(0,Q.jsx)(`button`,{onClick:e=>{e.stopPropagation(),n?.()},className:`flex items-center justify-center size-7 shrink-0 rounded-full bg-red-600 text-white hover:bg-red-500 transition-colors`,"aria-label":`Stop`,children:(0,Q.jsx)(K,{className:`size-3`})}):(0,Q.jsx)(`button`,{onClick:e=>{e.stopPropagation(),k()},disabled:r||!B,className:`flex items-center justify-center size-7 shrink-0 rounded-full bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-30 transition-colors`,"aria-label":`Send`,children:(0,Q.jsx)(L,{className:`size-3.5`})})]}),(0,Q.jsxs)(`div`,{className:`hidden md:block`,children:[(0,Q.jsx)(`textarea`,{ref:x,value:m,onChange:e=>{M(e.target.value),N(e)},onKeyDown:A,onPaste:P,onDrop:F,onDragOver:I,placeholder:t?`Follow-up or Stop...`:`Ask anything...`,disabled:r,rows:1,className:`w-full resize-none bg-transparent px-4 pt-3 pb-1 text-sm text-foreground placeholder:text-text-subtle focus:outline-none disabled:opacity-50 max-h-40`}),(0,Q.jsxs)(`div`,{className:`flex items-center justify-between px-3 pb-2`,children:[(0,Q.jsx)(`div`,{className:`flex items-center gap-1`,children:(0,Q.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),R()},disabled:r,className:`flex items-center justify-center size-8 rounded-full text-text-subtle hover:text-text-primary hover:bg-surface-elevated transition-colors disabled:opacity-50`,"aria-label":`Attach file`,children:(0,Q.jsx)(G,{className:`size-4`})})}),(0,Q.jsx)(`div`,{className:`flex items-center gap-1`,children:V?(0,Q.jsx)(`button`,{onClick:e=>{e.stopPropagation(),n?.()},className:`flex items-center justify-center size-8 rounded-full bg-red-600 text-white hover:bg-red-500 transition-colors`,"aria-label":`Stop response`,children:(0,Q.jsx)(K,{className:`size-3.5`})}):(0,Q.jsx)(`button`,{onClick:e=>{e.stopPropagation(),k()},disabled:r||!B,className:`flex items-center justify-center size-8 rounded-full bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,"aria-label":`Send message`,children:(0,Q.jsx)(L,{className:`size-4`})})})]})]})]}),(0,Q.jsx)(`input`,{ref:C,type:`file`,multiple:!0,className:`hidden`,onChange:z})]})}function gt({items:e,filter:t,onSelect:n,onClose:r,visible:i}){let[a,o]=(0,q.useState)(0),s=(0,q.useRef)(null),c=e.filter(e=>{let n=t.toLowerCase();return e.name.toLowerCase().includes(n)||e.description.toLowerCase().includes(n)});(0,q.useEffect)(()=>{o(0)},[t]),(0,q.useEffect)(()=>{let e=s.current;e&&e.children[a]?.scrollIntoView({block:`nearest`})},[a]);let l=(0,q.useCallback)(e=>{if(!i||c.length===0)return!1;switch(e.key){case`ArrowUp`:return e.preventDefault(),o(e=>e>0?e-1:c.length-1),!0;case`ArrowDown`:return e.preventDefault(),o(e=>e<c.length-1?e+1:0),!0;case`Enter`:case`Tab`:return e.preventDefault(),c[a]&&n(c[a]),!0;case`Escape`:return e.preventDefault(),r(),!0}return!1},[i,c,a,n,r]);return(0,q.useEffect)(()=>{if(!i)return;let e=e=>{l(e)&&e.stopPropagation()};return document.addEventListener(`keydown`,e,!0),()=>document.removeEventListener(`keydown`,e,!0)},[i,l]),!i||c.length===0?null:(0,Q.jsx)(`div`,{className:`max-h-52 overflow-y-auto border-b border-border bg-surface`,children:(0,Q.jsx)(`div`,{ref:s,className:`py-1`,children:c.map((e,t)=>(0,Q.jsxs)(`button`,{className:`flex items-start gap-3 w-full px-3 py-2 text-left transition-colors ${t===a?`bg-primary/10 text-primary`:`hover:bg-surface-hover text-text-primary`}`,onMouseEnter:()=>o(t),onClick:()=>n(e),children:[(0,Q.jsx)(`span`,{className:`shrink-0 mt-0.5`,children:e.type===`skill`?(0,Q.jsx)(re,{className:`size-4 text-amber-500`}):(0,Q.jsx)(k,{className:`size-4 text-blue-500`})}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,Q.jsxs)(`span`,{className:`font-medium text-sm`,children:[`/`,e.name]}),e.argumentHint&&(0,Q.jsx)(`span`,{className:`text-xs text-text-subtle`,children:e.argumentHint}),(0,Q.jsx)(`span`,{className:`text-xs text-text-subtle capitalize ml-auto`,children:e.scope===`user`?`global`:e.type})]}),e.description&&(0,Q.jsx)(`p`,{className:`text-xs text-text-subtle mt-0.5 line-clamp-2`,children:e.description})]})]},`${e.type}-${e.name}`))})})}function _t(e){return e>=90?`text-red-500`:e>=70?`text-amber-500`:`text-green-500`}function vt(e){return e>=90?`bg-red-500`:e>=70?`bg-amber-500`:`bg-green-500`}function yt(e){if(!e)return null;let t=null;if(e.resetsInMinutes!=null)t=e.resetsInMinutes;else if(e.resetsInHours!=null)t=Math.round(e.resetsInHours*60);else if(e.resetsAt){let n=new Date(e.resetsAt).getTime()-Date.now();t=n>0?Math.ceil(n/6e4):0}if(t==null)return null;if(t<=0)return`now`;let n=Math.floor(t/1440),r=Math.floor(t%1440/60),i=t%60;return n>0?i>0?`${n}d ${r}h ${i}m`:r>0?`${n}d ${r}h`:`${n}d`:r>0?i>0?`${r}h ${i}m`:`${r}h`:`${i}m`}function bt({label:e,bucket:t}){if(!t)return null;let n=Math.round(t.utilization*100),r=yt(t);return(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsx)(`span`,{className:`text-xs font-medium text-text-primary`,children:e}),r&&(0,Q.jsxs)(`span`,{className:`text-[10px] text-text-subtle`,children:[`↻ `,r]})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`div`,{className:`flex-1 h-2 rounded-full bg-border overflow-hidden`,children:(0,Q.jsx)(`div`,{className:`h-full rounded-full transition-all ${vt(n)}`,style:{width:`${Math.min(n,100)}%`}})}),(0,Q.jsxs)(`span`,{className:`text-xs font-medium tabular-nums w-10 text-right ${_t(n)}`,children:[n,`%`]})]})]})}function xt(e){if(!e)return null;let t=Math.round((Date.now()-e)/1e3);return t<5?`just now`:t<60?`${t}s ago`:`${Math.floor(t/60)}m ago`}function St({usage:e,visible:t,onClose:n,onReload:r,loading:i,lastFetchedAt:a}){if(!t)return null;let o=e.queryCostUsd!=null||e.totalCostUsd!=null,s=e.session||e.weekly||e.weeklyOpus||e.weeklySonnet;return(0,Q.jsxs)(`div`,{className:`border-b border-border bg-surface px-3 py-2.5 space-y-2.5`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`text-xs font-semibold text-text-primary`,children:`Usage Limits`}),a&&(0,Q.jsx)(`span`,{className:`text-[10px] text-text-subtle`,children:xt(new Date(a).getTime())})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[r&&(0,Q.jsx)(`button`,{onClick:r,disabled:i,className:`text-xs text-text-subtle hover:text-text-primary px-1 disabled:opacity-50`,title:`Refresh usage data`,children:(0,Q.jsx)(x,{className:`size-3 ${i?`animate-spin`:``}`})}),(0,Q.jsx)(`button`,{onClick:n,className:`text-xs text-text-subtle hover:text-text-primary px-1`,children:`✕`})]})]}),s?(0,Q.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,Q.jsx)(bt,{label:`5-Hour Session`,bucket:e.session}),(0,Q.jsx)(bt,{label:`Weekly`,bucket:e.weekly}),(0,Q.jsx)(bt,{label:`Weekly (Opus)`,bucket:e.weeklyOpus}),(0,Q.jsx)(bt,{label:`Weekly (Sonnet)`,bucket:e.weeklySonnet})]}):(0,Q.jsxs)(`p`,{className:`text-xs text-text-subtle`,children:[`No data — run `,(0,Q.jsx)(`code`,{className:`bg-surface-elevated px-1 rounded`,children:`bun install`})]}),o&&(0,Q.jsxs)(`div`,{className:`border-t border-border pt-2 space-y-1`,children:[e.queryCostUsd!=null&&(0,Q.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,Q.jsx)(`span`,{className:`text-text-subtle`,children:`Last query`}),(0,Q.jsxs)(`span`,{className:`text-text-primary font-medium tabular-nums`,children:[`$`,e.queryCostUsd.toFixed(4)]})]}),e.totalCostUsd!=null&&(0,Q.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,Q.jsx)(`span`,{className:`text-text-subtle`,children:`Session total`}),(0,Q.jsxs)(`span`,{className:`text-text-primary font-medium tabular-nums`,children:[`$`,e.totalCostUsd.toFixed(4)]})]})]})]})}function Ct(e){try{return new Date(e).toLocaleDateString(void 0,{month:`short`,day:`numeric`})}catch{return``}}function wt(e){return e>=90?`text-red-500`:e>=70?`text-amber-500`:`text-green-500`}function Tt({projectName:e,usageInfo:t,contextWindowPct:n,usageLoading:r,refreshUsage:i,lastFetchedAt:o,sessionId:l,onSelectSession:u,onBugReport:f,isConnected:p,onReconnect:m}){let[g,y]=(0,q.useState)(null),[b,C]=(0,q.useState)([]),[w,T]=(0,q.useState)(!1),D=j(e=>l?e.notifications.has(l):!1),k=j(e=>e.clearForSession),[A,M]=(0,q.useState)(``),[P,F]=(0,q.useState)(null),[L,R]=(0,q.useState)(``),z=(0,q.useRef)(null),B=d(e=>e.openTab),V=e=>{y(t=>t===e?null:e)},H=(0,q.useCallback)(async()=>{if(e){T(!0);try{C(await _.get(`${h(e)}/chat/sessions`))}catch{}finally{T(!1)}}},[e]);(0,q.useEffect)(()=>{g===`history`&&b.length===0&&H()},[g]);function U(t){u?(u(t),y(null)):B({type:`chat`,title:t.title||`Chat`,projectId:e??null,metadata:{projectName:e,sessionId:t.id},closable:!0})}let W=(0,q.useCallback)((e,t)=>{t.stopPropagation(),F(e.id),R(e.title||``),setTimeout(()=>z.current?.select(),0)},[]),G=(0,q.useCallback)(async()=>{if(!P||!L.trim()||!e){F(null);return}try{await _.patch(`${h(e)}/chat/sessions/${P}`,{title:L.trim()}),C(e=>e.map(e=>e.id===P?{...e,title:L.trim()}:e))}catch{}F(null)},[P,L,e]),ne=(0,q.useCallback)(()=>F(null),[]),re=A.trim()?b.filter(e=>(e.title||``).toLowerCase().includes(A.toLowerCase())):b,K=t.fiveHour==null?null:Math.round(t.fiveHour*100),J=t.sevenDay==null?null:Math.round(t.sevenDay*100),Y=K!=null||J!=null?wt(Math.max(K??0,J??0)):`text-text-subtle`;return(0,Q.jsxs)(`div`,{className:`border-b border-border/50`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1 px-2 py-1`,children:[(0,Q.jsxs)(`button`,{onClick:()=>V(`history`),className:`flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] transition-colors ${g===`history`?`text-primary bg-primary/10`:`text-text-secondary hover:text-foreground hover:bg-surface-elevated`}`,children:[(0,Q.jsx)(ee,{className:`size-3`}),(0,Q.jsx)(`span`,{children:`History`})]}),(0,Q.jsx)(`button`,{onClick:()=>V(`config`),className:`p-1 rounded transition-colors ${g===`config`?`text-primary bg-primary/10`:`text-text-subtle hover:text-text-secondary hover:bg-surface-elevated`}`,title:`AI Settings`,children:(0,Q.jsx)(te,{className:`size-3`})}),(0,Q.jsxs)(`button`,{onClick:()=>V(`usage`),className:`flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] font-medium tabular-nums transition-colors hover:bg-surface-elevated ${g===`usage`?`bg-primary/10`:``} ${Y}`,title:`Usage limits`,children:[(0,Q.jsx)(I,{className:`size-3`}),(0,Q.jsxs)(`span`,{children:[`5h:`,K==null?`--%`:`${K}%`]}),(0,Q.jsx)(`span`,{className:`text-text-subtle`,children:`·`}),(0,Q.jsxs)(`span`,{children:[`Wk:`,J==null?`--%`:`${J}%`]}),n!=null&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{className:`text-text-subtle`,children:`·`}),(0,Q.jsxs)(`span`,{className:wt(n),children:[`Ctx:`,n,`%`]})]})]}),(0,Q.jsx)(`div`,{className:`flex-1`}),D&&l&&(0,Q.jsx)(`button`,{onClick:()=>k(l),className:`p-1 rounded text-amber-500 hover:text-amber-400 hover:bg-surface-elevated transition-colors`,title:`Mark as read`,children:(0,Q.jsx)(s,{className:`size-3`})}),m&&(0,Q.jsx)(`button`,{onClick:m,className:`size-4 flex items-center justify-center`,title:p?`Connected`:`Disconnected — click to reconnect`,children:(0,Q.jsx)(`span`,{className:`size-2 rounded-full ${p?`bg-green-500`:`bg-red-500 animate-pulse`}`})})]}),g===`history`&&(0,Q.jsxs)(`div`,{className:`border-t border-border/30 bg-surface`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5 px-2 py-1 border-b border-border/30`,children:[(0,Q.jsx)(S,{className:`size-3 text-text-subtle shrink-0`}),(0,Q.jsx)(`input`,{type:`text`,value:A,onChange:e=>M(e.target.value),placeholder:`Search sessions...`,className:`flex-1 bg-transparent text-[11px] text-text-primary outline-none placeholder:text-text-subtle`}),(0,Q.jsx)(`button`,{onClick:H,disabled:w,className:`p-0.5 rounded text-text-subtle hover:text-text-secondary transition-colors disabled:opacity-50`,title:`Refresh`,children:(0,Q.jsx)(x,{className:`size-3 ${w?`animate-spin`:``}`})})]}),(0,Q.jsx)(`div`,{className:`max-h-[200px] overflow-y-auto`,children:w&&b.length===0?(0,Q.jsx)(`div`,{className:`flex items-center justify-center py-3`,children:(0,Q.jsx)(v,{className:`size-3.5 animate-spin text-text-subtle`})}):re.length===0?(0,Q.jsx)(`div`,{className:`flex items-center justify-center py-3 text-[11px] text-text-subtle`,children:A?`No matching sessions`:`No sessions yet`}):re.map(e=>(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 w-full px-3 py-1.5 text-left hover:bg-surface-elevated transition-colors group`,children:[(0,Q.jsx)(N,{className:`size-3 shrink-0 text-text-subtle`}),P===e.id?(0,Q.jsxs)(`form`,{className:`flex items-center gap-1 flex-1 min-w-0`,onSubmit:e=>{e.preventDefault(),G()},children:[(0,Q.jsx)(`input`,{ref:z,value:L,onChange:e=>R(e.target.value),onBlur:G,onKeyDown:e=>{e.key===`Escape`&&ne()},className:`flex-1 min-w-0 bg-surface-elevated text-[11px] text-text-primary px-1 py-0.5 rounded border border-border outline-none focus:border-primary`,autoFocus:!0}),(0,Q.jsx)(`button`,{type:`submit`,className:`p-0.5 text-green-500 hover:text-green-400`,onClick:e=>e.stopPropagation(),children:(0,Q.jsx)(a,{className:`size-3`})}),(0,Q.jsx)(`button`,{type:`button`,className:`p-0.5 text-text-subtle hover:text-text-secondary`,onClick:e=>{e.stopPropagation(),ne()},children:(0,Q.jsx)(O,{className:`size-3`})})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`button`,{onClick:()=>U(e),className:`text-[11px] truncate flex-1 text-left`,children:e.title||`Untitled`}),(0,Q.jsx)(`button`,{onClick:t=>W(e,t),className:`p-0.5 rounded text-text-subtle hover:text-text-secondary opacity-0 group-hover:opacity-100 transition-opacity`,title:`Rename session`,children:(0,Q.jsx)(E,{className:`size-3`})})]}),P!==e.id&&e.updatedAt&&(0,Q.jsx)(`span`,{className:`text-[10px] text-text-subtle shrink-0`,children:Ct(e.updatedAt)})]},e.id))})]}),g===`config`&&(0,Q.jsx)(`div`,{className:`border-t border-border/30 bg-surface px-3 py-2 max-h-[280px] overflow-y-auto`,children:(0,Q.jsx)(c,{compact:!0})}),g===`usage`&&(0,Q.jsx)(St,{usage:t,visible:!0,onClose:()=>y(null),onReload:i,loading:r,lastFetchedAt:o})]})}function Et({metadata:e,tabId:t}){let[n,r]=(0,q.useState)(e?.sessionId??null),[i,a]=(0,q.useState)(e?.providerId??`claude`),[o,s]=(0,q.useState)([]),[c,l]=(0,q.useState)(!1),[p,m]=(0,q.useState)(``),[g,v]=(0,q.useState)(null),[y,x]=(0,q.useState)([]),[S,C]=(0,q.useState)(!1),[w,T]=(0,q.useState)(``),[E,D]=(0,q.useState)(null),[O,k]=(0,q.useState)(!1),[A,N]=(0,q.useState)(null),F=(0,q.useRef)(0),I=e?.projectName??``,L=d(e=>e.updateTab),R=f(e=>e.version),{usageInfo:z,usageLoading:B,lastFetchedAt:V,refreshUsage:H}=he(I,i);(0,q.useEffect)(()=>{!t||!n||L(t,{metadata:{...e,sessionId:n,providerId:i}})},[n,i]);let{messages:ee,messagesLoading:U,isStreaming:W,streamingStatus:G,connectingElapsed:te,thinkingWarningThreshold:ne,pendingApproval:re,contextWindowPct:K,sessionTitle:J,sendMessage:Y,respondToApproval:ie,cancelStreaming:ae,reconnect:oe,refetchMessages:X,isConnected:Z}=pe(n,i,I);(0,q.useEffect)(()=>{if(!n||!t)return;let e=()=>{if(document.hidden)return;let{panels:e,focusedPanelId:r}=u.getState();e[r]?.activeTabId===t&&j.getState().clearForSession(n)};e(),document.addEventListener(`visibilitychange`,e);let r=u.subscribe(e);return()=>{document.removeEventListener(`visibilitychange`,e),r()}},[n,t]),(0,q.useEffect)(()=>{t&&J&&L(t,{title:J})},[J]);let se=(0,q.useRef)(e?.pendingMessage);(0,q.useEffect)(()=>{if(se.current&&Z&&n){let n=se.current;se.current=void 0,t&&L(t,{metadata:{...e,pendingMessage:void 0}}),setTimeout(()=>Y(n),100)}},[Z,n]),(0,q.useCallback)(()=>{d.getState().openTab({type:`chat`,title:`AI Chat`,metadata:{projectName:I},projectId:I||null,closable:!0})},[I]);let ce=(0,q.useCallback)(e=>{r(e.id),a(e.providerId),t&&L(t,{title:e.title||`Chat`})},[t,L]),le=(0,q.useCallback)(async e=>{if(!(!n||!I))try{let{api:t,projectUrl:r}=await M(async()=>{let{api:e,projectUrl:t}=await import(`./api-client-B0aMOJxF.js`).then(e=>e.n);return{api:e,projectUrl:t}},__vite__mapDeps([0,1])),a=await t.post(`${r(I)}/chat/sessions/${n}/fork?providerId=${i}`);d.getState().openTab({type:`chat`,title:`Fork: ${e.slice(0,30)}`,metadata:{projectName:I,sessionId:a.id,providerId:i,pendingMessage:e},projectId:I||null,closable:!0})}catch(e){console.error(`Fork failed:`,e)}},[n,I,i]),ue=(0,q.useCallback)((e,t)=>{if(t.length===0)return e;let n=t.filter(e=>e.serverPath).map(e=>e.serverPath).join(`
7
- `);return n?(t.length===1?`[Attached file: ${n}]\n\n`:`[Attached files:\n${n}\n]\n\n`)+e:e},[]),de=(0,q.useCallback)(async(e,t=[])=>{let o=ue(e,t);if(o.trim()){if(!n)try{let t=I,n=await _.post(`${h(t)}/chat/sessions`,{providerId:i,title:e.slice(0,50)});r(n.id),a(n.providerId),setTimeout(()=>{Y(o)},500);return}catch(e){console.error(`Failed to create session:`,e);return}Y(o)}},[n,i,I,Y,ue]),fe=(0,q.useCallback)((e,t)=>{l(e),m(t)},[]),me=(0,q.useCallback)(e=>{v(e),l(!1),m(``),setTimeout(()=>v(null),50)},[]),ge=(0,q.useCallback)(()=>{l(!1),m(``)},[]),_e=(0,q.useCallback)((e,t)=>{C(e),T(t)},[]),ve=(0,q.useCallback)(e=>{D(e),C(!1),T(``),setTimeout(()=>D(null),50)},[]),ye=(0,q.useCallback)(()=>{C(!1),T(``)},[]);return(0,Q.jsxs)(`div`,{className:`flex flex-col h-full relative`,onDragEnter:(0,q.useCallback)(e=>{e.preventDefault(),F.current++,e.dataTransfer.types.includes(`Files`)&&k(!0)},[]),onDragLeave:(0,q.useCallback)(e=>{e.preventDefault(),F.current--,F.current===0&&k(!1)},[]),onDragOver:(0,q.useCallback)(e=>{e.preventDefault()},[]),onDrop:(0,q.useCallback)(e=>{e.preventDefault(),F.current=0,k(!1);let t=Array.from(e.dataTransfer.files);t.length>0&&(N(t),setTimeout(()=>N(null),100))},[]),children:[O&&(0,Q.jsx)(`div`,{className:`absolute inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm border-2 border-dashed border-primary rounded-lg pointer-events-none`,children:(0,Q.jsxs)(`div`,{className:`flex flex-col items-center gap-2 text-primary`,children:[(0,Q.jsx)(b,{className:`size-8`}),(0,Q.jsx)(`span`,{className:`text-sm font-medium`,children:`Drop files to attach`})]})}),(0,Q.jsx)(Ve,{messages:ee,messagesLoading:U,pendingApproval:re,onApprovalResponse:ie,isStreaming:W,streamingStatus:G,connectingElapsed:te,thinkingWarningThreshold:ne,projectName:I,onFork:W?void 0:le}),(0,Q.jsxs)(`div`,{className:`border-t border-border bg-background shrink-0`,children:[(0,Q.jsx)(Tt,{projectName:I,usageInfo:z,contextWindowPct:K,usageLoading:B,refreshUsage:H,lastFetchedAt:V,sessionId:n,onSelectSession:ce,onBugReport:n?()=>P(R,{sessionId:n,projectName:I}):void 0,isConnected:Z,onReconnect:()=>{Z||oe(),X()}}),(0,Q.jsx)(gt,{items:o,filter:p,onSelect:me,onClose:ge,visible:c}),(0,Q.jsx)(mt,{items:y,filter:w,onSelect:ve,onClose:ye,visible:S}),(0,Q.jsx)(ht,{onSend:de,isStreaming:W,onCancel:ae,projectName:I,onSlashStateChange:fe,onSlashItemsLoaded:s,slashSelected:g,onFileStateChange:_e,onFileItemsLoaded:x,fileSelected:E,externalFiles:A})]})]})}export{Et as ChatTab};
4
+ `);if(t)return t}if(typeof e==`string`)return e}catch{if(t&&!t.startsWith(`[{`))return t}return null},[e,t]);return i?(0,Q.jsxs)(`div`,{className:`border-t border-border pt-1.5 space-y-1`,children:[(0,Q.jsx)(Le,{content:i,maxHeight:`max-h-60`}),(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>r(!n),className:`flex items-center gap-1 text-[10px] text-text-subtle hover:text-text-secondary transition-colors`,children:[(0,Q.jsx)(V,{className:`size-3`}),n?`Hide`:`Show`,` raw`]}),n&&(0,Q.jsx)(`pre`,{className:`overflow-x-auto text-text-subtle font-mono max-h-40 whitespace-pre-wrap break-all text-[10px]`,children:t})]}):(0,Q.jsx)(Fe,{output:t})}function Fe({output:e}){let t=e.split(`
5
+ `).length,n=t>3||e.length>200,[r,i]=(0,q.useState)(n);return(0,Q.jsxs)(`div`,{className:`border-t border-border pt-1.5`,children:[n&&(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>i(!r),className:`flex items-center gap-1 text-[10px] text-text-subtle hover:text-text-secondary transition-colors mb-1`,children:[r?(0,Q.jsx)(A,{className:`size-3`}):(0,Q.jsx)(o,{className:`size-3`}),`Output (`,t,` lines)`]}),(0,Q.jsx)(`pre`,{className:`overflow-x-auto text-text-subtle font-mono whitespace-pre-wrap break-all ${r?`max-h-16 overflow-hidden`:`max-h-60`}`,children:e})]})}function Ie({events:e,projectName:t}){let n=[],r=``;for(let t of e)if(t.type===`text`)r+=t.content;else if(t.type===`tool_use`)r&&=(n.push({kind:`text`,content:r}),``),n.push({kind:`tool`,tool:t});else if(t.type===`tool_result`){let e=t.toolUseId,r=e?n.find(t=>t.kind===`tool`&&t.tool.type===`tool_use`&&t.tool.toolUseId===e&&!t.result):n.findLast(e=>e.kind===`tool`&&!e.result);r&&(r.result=t)}return r&&n.push({kind:`text`,content:r}),(0,Q.jsx)(`div`,{className:`border-l-2 border-accent/20 pl-2 space-y-1 mt-1`,children:n.map((e,n)=>e.kind===`text`?(0,Q.jsx)(`div`,{className:`text-text-secondary text-[11px]`,children:(0,Q.jsx)(Le,{content:e.content,maxHeight:`max-h-24`})},`st-${n}`):(0,Q.jsx)(Ae,{tool:e.tool,result:e.result,completed:!!e.result,projectName:t},`sc-${n}`))})}function Le({content:e,maxHeight:t=`max-h-48`}){return(0,Q.jsx)(I,{content:e,className:`text-text-secondary overflow-auto ${t}`})}function $(e,t=50){return e?e.length>t?e.slice(0,t)+`…`:e:``}function Re(e){let[t,n]=(0,q.useState)({}),[r,i]=(0,q.useState)({}),[a,o]=(0,q.useState)(0),s=(0,q.useCallback)((e,t)=>{n(n=>({...n,[e]:[t]})),i(t=>({...t,[e]:``}))},[]),c=(0,q.useCallback)((e,t)=>{n(n=>{let r=n[e]||[];return{...n,[e]:r.includes(t)?r.filter(e=>e!==t):[...r,t]}})},[]),l=(0,q.useCallback)((e,t)=>{i(n=>({...n,[e]:t})),t&&n(t=>({...t,[e]:[]}))},[]),u=(0,q.useCallback)(e=>(t[e]?.length??0)>0||(r[e]?.trim().length??0)>0,[t,r]);return{answers:t,customInputs:r,activeTab:a,setActiveTab:o,handleSingleSelect:s,handleMultiSelect:c,handleCustomInput:l,hasAnswer:u,allAnswered:(0,q.useMemo)(()=>e.every((e,t)=>u(t)),[e,u]),getFinalAnswer:(0,q.useCallback)(e=>r[e]?.trim()||(t[e]??[]).join(`, `),[t,r]),goToNextTab:(0,q.useCallback)(()=>o(t=>Math.min(t+1,e.length-1)),[e.length]),goToPrevTab:(0,q.useCallback)(()=>o(e=>Math.max(e-1,0)),[])}}function ze(e){let[t,n]=(0,q.useState)(0),r=(0,q.useRef)(null);return(0,q.useEffect)(()=>n(0),[e.activeTab]),(0,q.useEffect)(()=>{if(!e.enabled)return;let i=r=>{let i=document.activeElement===e.customInputRef.current;if(!i&&r.key>=`1`&&r.key<=`9`){r.preventDefault();let t=parseInt(r.key)-1;t<e.totalOptions-1&&(n(t),e.onSelectOption(t));return}if(!i&&(r.key===`o`||r.key===`O`||r.key===`0`)){r.preventDefault(),e.customInputRef.current?.focus(),n(e.totalOptions-1);return}if(r.key===`Tab`&&e.questions.length>1){r.preventDefault(),r.shiftKey?e.goToPrevTab():e.goToNextTab();return}if(!i){if(r.key===`ArrowLeft`){r.preventDefault(),e.goToPrevTab();return}if(r.key===`ArrowRight`){r.preventDefault(),e.goToNextTab();return}if(r.key===`ArrowUp`){r.preventDefault(),n(e=>Math.max(0,e-1));return}if(r.key===`ArrowDown`){r.preventDefault(),n(t=>Math.min(e.totalOptions-1,t+1));return}if(r.key===` `){r.preventDefault(),e.onSelectOption(t);return}}if(r.key===`Enter`){r.preventDefault(),e.allAnswered?e.onSubmit():e.hasAnswer(e.activeTab)&&e.goToNextTab();return}r.key===`Escape`&&i&&e.customInputRef.current?.blur()},a=r.current;return a&&(a.addEventListener(`keydown`,i),a.setAttribute(`tabindex`,`0`),a.contains(document.activeElement)||a.focus()),()=>{a?.removeEventListener(`keydown`,i)}},[e,t]),{focusedOption:t,setFocusedOption:n,containerRef:r}}function Be({questions:e,onSubmit:t,onSkip:n}){let r=(0,q.useRef)(null),i=Re(e),a=e[i.activeTab],o=a?a.options.length+1:0,s=e.length>1,c=(0,q.useCallback)(()=>{if(!i.allAnswered)return;let n={};e.forEach((e,t)=>{n[e.question]=i.getFinalAnswer(t)}),t(n)},[i.allAnswered,i.getFinalAnswer,e,t]),l=(0,q.useCallback)(e=>{if(!(!a||e<0))if(e<a.options.length){let t=a.options[e]?.label;if(!t)return;a.multiSelect?i.handleMultiSelect(i.activeTab,t):i.handleSingleSelect(i.activeTab,t)}else e===a.options.length&&r.current?.focus()},[a,i]),u=ze({questions:e,activeTab:i.activeTab,totalOptions:o,allAnswered:i.allAnswered,hasAnswer:i.hasAnswer,onSelectOption:l,goToNextTab:i.goToNextTab,goToPrevTab:i.goToPrevTab,onSubmit:c,customInputRef:r,enabled:!0}),d=(0,q.useCallback)(e=>{l(e),u.setFocusedOption(e)},[l,u.setFocusedOption]);return(0,Q.jsxs)(`div`,{ref:u.containerRef,className:`rounded-lg border-2 border-primary/30 bg-primary/5 p-3 space-y-3 outline-none animate-in slide-in-from-bottom-2`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between text-sm font-medium text-text-primary`,children:[(0,Q.jsxs)(`span`,{children:[`AI has `,s?`${e.length} questions`:`a question`]}),(0,Q.jsxs)(`span`,{className:`text-[10px] text-text-secondary font-normal`,children:[s?`←→ tabs · `:``,`↑↓ options · 1-`,Math.min(o-1,9),` select · Enter submit`]})]}),s&&(0,Q.jsx)(`div`,{className:`flex gap-1 p-1 bg-background rounded-md overflow-x-auto border border-border`,children:e.map((e,t)=>(0,Q.jsxs)(`button`,{className:`flex items-center gap-1.5 px-3 py-1.5 rounded text-xs whitespace-nowrap transition-all ${i.activeTab===t?`bg-primary text-primary-foreground`:i.hasAnswer(t)?`text-primary bg-transparent`:`text-text-secondary hover:bg-surface-elevated`}`,onClick:()=>{i.setActiveTab(t),u.setFocusedOption(0)},tabIndex:-1,children:[(0,Q.jsx)(`span`,{className:`flex items-center justify-center w-4 h-4 rounded-full text-[10px] font-semibold ${i.activeTab===t?`bg-white/20`:i.hasAnswer(t)?`bg-primary/20 text-primary`:`bg-surface-elevated text-text-secondary`}`,children:i.hasAnswer(t)?`✓`:t+1}),(0,Q.jsx)(`span`,{className:`max-w-[100px] overflow-hidden text-ellipsis`,children:e.header||`Q${t+1}`})]},t))}),a&&(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[!s&&a.header&&(0,Q.jsx)(`div`,{className:`text-[11px] font-semibold uppercase tracking-wide text-text-secondary`,children:a.header}),(0,Q.jsx)(`div`,{className:`text-sm text-text-primary`,children:a.question}),a.multiSelect&&(0,Q.jsx)(`div`,{className:`text-[11px] text-text-secondary`,children:`Select multiple`}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[a.options.map((e,t)=>{let n=(i.answers[i.activeTab]||[]).includes(e.label),r=u.focusedOption===t;return(0,Q.jsxs)(`button`,{onClick:()=>d(t),className:`text-left flex items-start gap-2.5 rounded px-2.5 py-2 text-xs border transition-all ${n?`border-primary bg-primary/10 text-text-primary`:`border-border bg-background text-text-secondary hover:border-primary/40 hover:bg-primary/5`} ${r?`ring-2 ring-primary/40 ring-offset-1 ring-offset-background`:``}`,children:[(0,Q.jsx)(`span`,{className:`flex items-center justify-center w-4.5 h-4.5 rounded text-[10px] font-semibold shrink-0 mt-px ${n?`bg-primary/20 text-primary`:`bg-surface-elevated text-text-secondary`}`,children:t+1}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-0.5 flex-1`,children:[(0,Q.jsx)(`span`,{className:`font-medium text-text-primary`,children:e.label}),e.description&&(0,Q.jsx)(`span`,{className:`text-[11px] text-text-secondary`,children:e.description})]})]},t)}),(0,Q.jsxs)(`div`,{className:`flex items-start gap-2.5 rounded px-2.5 py-2 text-xs border border-dashed transition-all border-border bg-transparent ${u.focusedOption===o-1?`ring-2 ring-primary/40 ring-offset-1 ring-offset-background`:``}`,children:[(0,Q.jsx)(`span`,{className:`flex items-center justify-center w-4.5 h-4.5 rounded bg-surface-elevated text-text-secondary text-[10px] font-semibold shrink-0 mt-px`,children:`O`}),(0,Q.jsx)(`input`,{ref:r,type:`text`,className:`flex-1 px-2 py-1 text-xs bg-surface border border-border rounded text-text-primary outline-none placeholder:text-text-subtle focus:border-primary`,placeholder:`Other (press O to type)...`,value:i.customInputs[i.activeTab]||``,onChange:e=>i.handleCustomInput(i.activeTab,e.target.value),onFocus:()=>u.setFocusedOption(o-1)})]})]})]}),(0,Q.jsxs)(`div`,{className:`flex gap-2 justify-end pt-1`,children:[s&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`button`,{className:`px-3 py-1.5 text-xs rounded border border-border bg-background text-text-primary hover:bg-surface-elevated disabled:opacity-40 disabled:cursor-not-allowed transition-colors`,onClick:i.goToPrevTab,disabled:i.activeTab===0,tabIndex:-1,children:`← Prev`}),(0,Q.jsx)(`button`,{className:`px-3 py-1.5 text-xs rounded border border-border bg-background text-text-primary hover:bg-surface-elevated disabled:opacity-40 disabled:cursor-not-allowed transition-colors`,onClick:i.goToNextTab,disabled:i.activeTab===e.length-1,tabIndex:-1,children:`Next →`})]}),(0,Q.jsx)(`button`,{onClick:n,className:`px-4 py-1.5 rounded border border-border bg-background text-text-secondary text-xs hover:bg-surface-elevated transition-colors`,tabIndex:-1,children:`Skip`}),(0,Q.jsxs)(`button`,{onClick:c,disabled:!i.allAnswered,className:`px-4 py-1.5 rounded bg-primary text-primary-foreground text-xs font-medium hover:bg-primary/80 transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,tabIndex:-1,children:[`Submit `,i.allAnswered?`✓`:`(${e.filter((e,t)=>i.hasAnswer(t)).length}/${e.length})`]})]})]})}function Ve({messages:e,messagesLoading:t,pendingApproval:n,onApprovalResponse:r,isStreaming:i,streamingStatus:a,connectingElapsed:o,thinkingWarningThreshold:s,projectName:c,onFork:l}){return t?(0,Q.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,Q.jsx)(z,{className:`size-10 text-text-subtle animate-pulse`}),(0,Q.jsx)(`p`,{className:`text-sm`,children:`Loading messages...`})]}):e.length===0&&!i?(0,Q.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,Q.jsx)(z,{className:`size-10 text-text-subtle`}),(0,Q.jsx)(`p`,{className:`text-sm`,children:`Send a message to start the conversation`})]}):(0,Q.jsxs)(De,{className:`flex-1 overflow-y-auto`,resize:`smooth`,initial:`instant`,children:[(0,Q.jsxs)(De.Content,{className:`p-4 space-y-4`,children:[e.filter(e=>{let t=e.content&&e.content.trim().length>0,n=e.events&&e.events.length>0;return t||n}).map(e=>(0,Q.jsx)(Ue,{message:e,isStreaming:i&&e.id.startsWith(`streaming-`),projectName:c,onFork:e.role===`user`&&l?()=>l(e.content):void 0},e.id)),n&&(n.tool===`AskUserQuestion`?(0,Q.jsx)(it,{approval:n,onRespond:r}):(0,Q.jsx)(rt,{approval:n,onRespond:r})),i&&(0,Q.jsx)(tt,{lastMessage:e[e.length-1],streamingStatus:a,elapsed:o,warningThreshold:s})]}),(0,Q.jsx)(He,{})]})}function He(){let{isAtBottom:e,scrollToBottom:t}=Oe();return e?null:(0,Q.jsxs)(`button`,{onClick:()=>t(),className:`absolute bottom-2 left-1/2 -translate-x-1/2 flex items-center gap-1 px-3 py-1 rounded-full bg-surface-elevated border border-border text-xs text-text-secondary hover:text-foreground shadow-lg transition-all`,children:[(0,Q.jsx)(o,{className:`size-3`}),`Scroll to bottom`]})}function Ue({message:e,isStreaming:t,projectName:n,onFork:r}){return e.role===`user`?(0,Q.jsx)(Ye,{content:e.content,projectName:n,onFork:r}):e.role===`system`?(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg bg-red-500/10 border border-red-500/20 px-3 py-2 text-sm text-red-400`,children:[(0,Q.jsx)(w,{className:`size-4 shrink-0`}),(0,Q.jsx)(`p`,{children:e.content})]}):(0,Q.jsx)(`div`,{className:`flex flex-col gap-2`,children:e.events&&e.events.length>0?(0,Q.jsx)(Qe,{events:e.events,isStreaming:t,projectName:n}):e.content&&(0,Q.jsx)(`div`,{className:`text-sm text-text-primary`,children:(0,Q.jsx)(nt,{content:e.content,projectName:n})})})}var We=new Set([`.png`,`.jpg`,`.jpeg`,`.gif`,`.webp`]);function Ge(e){let t=e.match(/^\[Attached file: (.+?)\]\n\n?/);if(t)return{files:[t[1]],text:e.slice(t[0].length)};let n=e.match(/^\[Attached files:\n([\s\S]+?)\]\n\n?/);return n?{files:n[1].split(`
6
+ `).map(e=>e.trim()).filter(Boolean),text:e.slice(n[0].length)}:{files:[],text:e}}function Ke(e,t){let n=h(e);return`/api/project/${encodeURIComponent(t??`_`)}/chat/uploads/${encodeURIComponent(n)}`}function qe(e){let t=e.lastIndexOf(`.`);return t===-1?!1:We.has(e.slice(t).toLowerCase())}function Je(e){return e.toLowerCase().endsWith(`.pdf`)}function Ye({content:e,projectName:t,onFork:r}){let{files:i,text:a}=(0,q.useMemo)(()=>Ge(e),[e]);return(0,Q.jsx)(`div`,{className:`flex justify-end group/user`,children:(0,Q.jsxs)(`div`,{className:`rounded-lg bg-primary/10 px-3 py-2 text-sm text-text-primary max-w-[85%] space-y-2 relative`,children:[i.length>0&&(0,Q.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:i.map((e,n)=>qe(e)?(0,Q.jsx)(Xe,{src:Ke(e,t),alt:h(e)||`image`},n):Je(e)?(0,Q.jsx)(Ze,{src:Ke(e,t),filename:h(e)||`document.pdf`,mimeType:`application/pdf`},n):(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5 rounded-md border border-border bg-background/50 px-2 py-1 text-xs text-text-secondary`,children:[(0,Q.jsx)(T,{className:`size-3.5 shrink-0`}),(0,Q.jsx)(`span`,{className:`truncate max-w-40`,children:h(e)})]},n))}),a&&(0,Q.jsx)(`p`,{className:`whitespace-pre-wrap break-words`,children:a}),r&&(0,Q.jsx)(`button`,{onClick:r,title:`Retry from this message (fork session)`,className:`absolute -left-8 top-1/2 -translate-y-1/2 opacity-0 group-hover/user:opacity-100 transition-opacity size-6 flex items-center justify-center rounded bg-surface border border-border text-text-subtle hover:text-text-primary hover:bg-surface-elevated`,children:(0,Q.jsx)(n,{className:`size-3`})})]})})}function Xe({src:e,alt:t}){let[n,r]=(0,q.useState)(null),[i,a]=(0,q.useState)(!1);return(0,q.useEffect)(()=>{let t,n=_();return fetch(e,{headers:n?{Authorization:`Bearer ${n}`}:{}}).then(e=>{if(!e.ok)throw Error(`Failed to load`);return e.blob()}).then(e=>{let n=URL.createObjectURL(e);t=n,r(n)}).catch(()=>a(!0)),()=>{t&&URL.revokeObjectURL(t)}},[e]),i?(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5 rounded-md border border-border bg-background/50 px-2 py-1 text-xs text-text-secondary`,children:[(0,Q.jsx)(U,{className:`size-3.5 shrink-0`}),(0,Q.jsx)(`span`,{className:`truncate max-w-40`,children:t})]}):n?(0,Q.jsx)(`a`,{href:n,target:`_blank`,rel:`noopener noreferrer`,className:`block`,children:(0,Q.jsx)(`img`,{src:n,alt:t,className:`rounded-md max-h-48 max-w-full object-contain border border-border`})}):(0,Q.jsx)(`div`,{className:`rounded-md bg-surface border border-border h-24 w-32 animate-pulse`})}function Ze({src:e,filename:t,mimeType:n}){let[r,i]=(0,q.useState)(!1);return(0,Q.jsxs)(`button`,{type:`button`,onClick:(0,q.useCallback)(async()=>{i(!0);try{let t=_(),r=await fetch(e,{headers:t?{Authorization:`Bearer ${t}`}:{}});if(!r.ok)throw Error(`Failed to load`);let i=await r.blob(),a=URL.createObjectURL(new Blob([i],{type:n}));window.open(a,`_blank`),setTimeout(()=>URL.revokeObjectURL(a),6e4)}catch{window.open(e,`_blank`)}finally{i(!1)}},[e,n]),disabled:r,className:`flex items-center gap-1.5 rounded-md border border-border bg-background/50 px-2 py-1 text-xs text-text-secondary hover:bg-surface hover:text-text-primary transition-colors cursor-pointer disabled:opacity-50`,children:[(0,Q.jsx)(T,{className:`size-3.5 shrink-0 text-red-400`}),(0,Q.jsx)(`span`,{className:`truncate max-w-40`,children:t}),r&&(0,Q.jsx)(`span`,{className:`animate-spin text-[10px]`,children:`...`})]})}function Qe({events:e,isStreaming:t,projectName:n}){let r=[],i=``,a=``;for(let t=0;t<e.length;t++){let n=e[t];if(n.type===`thinking`){i&&=(r.push({kind:`text`,content:i}),``),a+=n.content;continue}a&&=(r.push({kind:`thinking`,content:a}),``),n.type===`text`?i+=n.content:n.type===`tool_use`?(i&&=(r.push({kind:`text`,content:i}),``),r.push({kind:`tool`,tool:n})):n.type===`tool_result`||(i&&=(r.push({kind:`text`,content:i}),``),r.push({kind:`tool`,tool:n}))}a&&r.push({kind:`thinking`,content:a}),i&&r.push({kind:`text`,content:i});let o=e.filter(e=>e.type===`tool_result`);for(let e of o){let t=e.toolUseId;if(t){let n=r.find(e=>e.kind===`tool`&&e.tool.type===`tool_use`&&e.tool.toolUseId===t);if(n){n.result=e;continue}}let n=r.find(e=>e.kind===`tool`&&!e.result);n&&(n.result=e)}for(let e=0;e<r.length;e++){let n=r[e];if(n.kind===`tool`&&!n.result){let i=!1;if(n.tool.type===`tool_use`&&n.tool.tool===`Read`){let t=n.tool.input?.file_path;t&&(i=r.slice(e+1).some(e=>e.kind===`tool`&&e.result&&e.tool.type===`tool_use`&&e.tool.tool===`Edit`&&e.tool.input?.file_path===t))}n.completed=i||!t}}return(0,Q.jsx)(Q.Fragment,{children:r.map((e,i)=>{if(e.kind===`thinking`)return(0,Q.jsx)($e,{content:e.content,isStreaming:t&&i===r.length-1},`think-${i}`);if(e.kind===`text`){let a=t&&i===r.length-1;return(0,Q.jsx)(`div`,{className:`text-sm text-text-primary`,children:(0,Q.jsx)(et,{content:e.content,animate:a,projectName:n})},`text-${i}`)}return(0,Q.jsx)(Ae,{tool:e.tool,result:e.result,completed:e.completed,projectName:n},`tool-${i}`)})})}function $e({content:e,isStreaming:t}){let[n,r]=(0,q.useState)(t);return(0,q.useEffect)(()=>{!t&&e.length>0&&r(!1)},[t,e.length]),(0,Q.jsxs)(`div`,{className:`rounded border border-border/50 bg-surface/30 text-xs`,children:[(0,Q.jsxs)(`button`,{onClick:()=>r(!n),className:`flex items-center gap-2 px-2 py-1.5 w-full text-left hover:bg-surface transition-colors text-text-subtle`,children:[t?(0,Q.jsx)(P,{className:`size-3 animate-spin`}):(0,Q.jsx)(A,{className:`size-3 transition-transform ${n?`rotate-90`:``}`}),(0,Q.jsxs)(`span`,{children:[`Thinking`,t?`...`:``]}),!t&&(0,Q.jsx)(`span`,{className:`text-text-subtle/50 ml-auto`,children:e.length>100?`${Math.round(e.length/4)} tokens`:``})]}),n&&(0,Q.jsx)(`div`,{className:`px-2 pb-2 text-text-subtle/80 whitespace-pre-wrap max-h-60 overflow-y-auto text-[11px] leading-relaxed`,children:e})]})}function et({content:e,animate:t,projectName:n}){return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(nt,{content:e,projectName:n}),t&&(0,Q.jsx)(`span`,{className:`text-text-subtle text-sm animate-pulse`,children:`Thinking...`})]})}function tt({lastMessage:e,streamingStatus:t,elapsed:n,warningThreshold:r=15}){let i=!e||e.role!==`assistant`,a=e?.events?.length?e.events[e.events.length-1].type===`tool_result`:!1;return!i&&!a?null:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1 text-sm`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-text-subtle`,children:[(0,Q.jsx)(P,{className:`size-3 animate-spin`}),(0,Q.jsxs)(`span`,{children:[`Thinking`,i&&(n??0)>0&&(0,Q.jsxs)(`span`,{className:`text-text-subtle/60`,children:[`... (`,n,`s)`]})]})]}),i&&(n??0)>=r&&(0,Q.jsx)(`p`,{className:`text-xs text-yellow-500/80 ml-5`,children:`Taking longer than usual — may be rate-limited or API slow. Try sending a new message to retry.`})]})}function nt({content:e,projectName:t}){return(0,Q.jsx)(I,{content:e,projectName:t,codeActions:!0})}function rt({approval:e,onRespond:t}){return(0,Q.jsxs)(`div`,{className:`rounded-lg border-2 border-yellow-500/40 bg-yellow-500/10 p-3 space-y-2`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-yellow-400 text-sm font-medium`,children:[(0,Q.jsx)(ne,{className:`size-4`}),(0,Q.jsx)(`span`,{children:`Tool Approval Required`})]}),(0,Q.jsx)(`div`,{className:`text-xs text-text-primary`,children:(0,Q.jsx)(`span`,{className:`font-medium`,children:e.tool})}),(0,Q.jsx)(`pre`,{className:`text-xs font-mono text-text-secondary overflow-x-auto bg-background rounded p-2 border border-border`,children:JSON.stringify(e.input,null,2)}),(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(`button`,{onClick:()=>t(e.requestId,!0),className:`px-4 py-1.5 rounded bg-green-600 text-white text-xs font-medium hover:bg-green-500 transition-colors`,children:`Allow`}),(0,Q.jsx)(`button`,{onClick:()=>t(e.requestId,!1),className:`px-4 py-1.5 rounded bg-red-600 text-white text-xs font-medium hover:bg-red-500 transition-colors`,children:`Deny`})]})]})}function it({approval:e,onRespond:t}){return(0,Q.jsx)(Be,{questions:e.input.questions??[],onSubmit:n=>t(e.requestId,!0,n),onSkip:()=>t(e.requestId,!1)})}var at=new Set([`image/png`,`image/jpeg`,`image/gif`,`image/webp`]),ot=new Set([`application/pdf`]),st=[`text/`,`application/json`,`application/xml`,`application/javascript`,`application/typescript`,`application/x-yaml`,`application/toml`,`application/x-sh`],ct=new Set(`.ts,.tsx,.js,.jsx,.mjs,.cjs,.py,.rb,.go,.rs,.java,.kt,.swift,.c,.cpp,.h,.hpp,.cs,.json,.yaml,.yml,.toml,.xml,.md,.mdx,.txt,.csv,.tsv,.html,.css,.scss,.less,.sass,.sh,.bash,.zsh,.fish,.sql,.graphql,.gql,.env,.ini,.cfg,.conf,.dockerfile,.makefile,.vue,.svelte,.astro,.ipynb`.split(`,`));function lt(e){return at.has(e.type)}function ut(e){if(at.has(e.type)||ot.has(e.type)||st.some(t=>e.type.startsWith(t)))return!0;let t=dt(e.name);return!!(t&&ct.has(t))}function dt(e){let t=e.lastIndexOf(`.`);return t===-1?``:e.slice(t).toLowerCase()}function ft({attachments:e,onRemove:t}){return e.length===0?null:(0,Q.jsx)(`div`,{className:`flex flex-wrap gap-1.5 px-2 md:px-4 pt-2`,children:e.map(e=>(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5 rounded-md border border-border bg-surface px-2 py-1 text-xs text-text-secondary max-w-48`,children:[e.previewUrl?(0,Q.jsx)(`img`,{src:e.previewUrl,alt:e.name,className:`size-5 rounded object-cover shrink-0`}):e.isImage?(0,Q.jsx)(U,{className:`size-3.5 shrink-0 text-text-subtle`}):(0,Q.jsx)(T,{className:`size-3.5 shrink-0 text-text-subtle`}),(0,Q.jsx)(`span`,{className:`truncate`,children:e.name}),e.status===`uploading`?(0,Q.jsx)(P,{className:`size-3 shrink-0 animate-spin text-text-subtle`}):e.status===`error`?(0,Q.jsx)(`span`,{className:`text-red-500 shrink-0`,title:`Upload failed`,children:`!`}):null,(0,Q.jsx)(`button`,{type:`button`,onClick:()=>t(e.id),className:`shrink-0 rounded-sm p-0.5 hover:bg-border/50 transition-colors`,"aria-label":`Remove ${e.name}`,children:(0,Q.jsx)(O,{className:`size-3`})})]},e.id))})}function pt(e){let t=[];function n(e){for(let r of e)t.push(r),r.children&&n(r.children)}return n(e),t}function mt({items:e,filter:t,onSelect:n,onClose:r,visible:i}){let[a,o]=(0,q.useState)(0),s=(0,q.useRef)(null),c=(()=>{if(!t)return e.slice(0,50);let n=t.toLowerCase();return e.filter(e=>e.path.toLowerCase().includes(n)||e.name.toLowerCase().includes(n)).slice(0,50)})();(0,q.useEffect)(()=>{o(0)},[t]),(0,q.useEffect)(()=>{let e=s.current;e&&e.children[a]?.scrollIntoView({block:`nearest`})},[a]);let l=(0,q.useCallback)(e=>{if(!i||c.length===0)return!1;switch(e.key){case`ArrowUp`:return e.preventDefault(),o(e=>e>0?e-1:c.length-1),!0;case`ArrowDown`:return e.preventDefault(),o(e=>e<c.length-1?e+1:0),!0;case`Enter`:case`Tab`:return e.preventDefault(),c[a]&&n(c[a]),!0;case`Escape`:return e.preventDefault(),r(),!0}return!1},[i,c,a,n,r]);return(0,q.useEffect)(()=>{if(!i)return;let e=e=>{l(e)&&e.stopPropagation()};return document.addEventListener(`keydown`,e,!0),()=>document.removeEventListener(`keydown`,e,!0)},[i,l]),!i||c.length===0?null:(0,Q.jsx)(`div`,{className:`max-h-52 overflow-y-auto border-b border-border bg-surface`,children:(0,Q.jsx)(`div`,{ref:s,className:`py-1`,children:c.map((e,t)=>(0,Q.jsxs)(`button`,{className:`flex items-center gap-2 w-full px-3 py-1.5 text-left transition-colors ${t===a?`bg-primary/10 text-primary`:`hover:bg-surface-hover text-text-primary`}`,onMouseEnter:()=>o(t),onClick:()=>n(e),children:[(0,Q.jsx)(`span`,{className:`shrink-0`,children:e.type===`directory`?(0,Q.jsx)(D,{className:`size-4 text-amber-500`}):(0,Q.jsx)(C,{className:`size-4 text-blue-400`})}),(0,Q.jsx)(`span`,{className:`text-sm truncate`,children:e.path})]},e.path))})})}function ht({onSend:e,isStreaming:t,onCancel:n,disabled:r,projectName:i,onSlashStateChange:a,onSlashItemsLoaded:o,slashSelected:s,onFileStateChange:c,onFileItemsLoaded:l,fileSelected:u,externalFiles:d,initialValue:f}){let[p,h]=(0,q.useState)(f??``),[y,b]=(0,q.useState)([]),x=(0,q.useRef)(null),S=(0,q.useRef)(null),C=(0,q.useRef)(null),w=(0,q.useRef)([]),T=(0,q.useRef)([]);(0,q.useEffect)(()=>{f&&(h(f),setTimeout(()=>{let e=x.current;e&&(e.focus(),e.selectionStart=e.selectionEnd=e.value.length)},50))},[f]),(0,q.useEffect)(()=>{if(!i){w.current=[],o?.([]);return}v.get(`${g(i)}/chat/slash-items`).then(e=>{w.current=e,o?.(e)}).catch(()=>{w.current=[],o?.([])})},[i]),(0,q.useEffect)(()=>{if(!i){T.current=[],l?.([]);return}v.get(`${g(i)}/files/tree?depth=5`).then(e=>{let t=pt(e);T.current=t,l?.(t)}).catch(()=>{T.current=[],l?.([])})},[i]),(0,q.useEffect)(()=>{if(!s)return;let e=x.current,t=e?.selectionStart??p.length,n=p.slice(0,t),r=p.slice(t),i=n.replace(/(?:^|\s)\/\S*$/,e=>`${e.startsWith(`/`)?``:e[0]}/${s.name} `);h(i+r),a?.(!1,``),c?.(!1,``),e&&(e.focus(),setTimeout(()=>{e.selectionStart=e.selectionEnd=i.length},0))},[s]),(0,q.useEffect)(()=>{if(!u)return;let e=x.current;if(!e)return;let t=e.selectionStart,n=p.slice(0,t),r=p.slice(t),i=n.match(/@(\S*)$/);if(i){let t=n.length-i[0].length;h(n.slice(0,t)+`@${u.path} `+r);let a=t+u.path.length+2;setTimeout(()=>{e.selectionStart=e.selectionEnd=a,e.focus()},0)}else{let t=p+`@${u.path} `;h(t),setTimeout(()=>{e.selectionStart=e.selectionEnd=t.length,e.focus()},0)}c?.(!1,``)},[u]),(0,q.useEffect)(()=>{!d||d.length===0||D(d)},[d]);let E=(0,q.useCallback)(async e=>{if(!i)return null;try{let t=new FormData;t.append(`files`,e);let n={},r=_();r&&(n.Authorization=`Bearer ${r}`);let a=await(await fetch(`${g(i)}/chat/upload`,{method:`POST`,headers:n,body:t})).json();return a.ok&&Array.isArray(a.data)&&a.data.length>0?a.data[0].path:null}catch{return null}},[i]),D=(0,q.useCallback)(e=>{for(let t of e){if(!ut(t)){h(e=>e+(e.length>0&&!e.endsWith(` `)?` `:``)+t.name);continue}let e=m(),n=lt(t),r=n?URL.createObjectURL(t):void 0,i={id:e,name:t.name,file:t,isImage:n,previewUrl:r,status:`uploading`};b(e=>[...e,i]),E(t).then(t=>{b(n=>n.map(n=>n.id===e?{...n,serverPath:t??void 0,status:t?`ready`:`error`}:n))})}(S.current??x.current)?.focus()},[E]),O=(0,q.useCallback)(e=>{b(t=>{let n=t.find(t=>t.id===e);return n?.previewUrl&&URL.revokeObjectURL(n.previewUrl),t.filter(t=>t.id!==e)})},[]),k=(0,q.useCallback)(()=>{let t=p.trim(),n=y.filter(e=>e.status===`ready`);if(!(!t&&n.length===0)&&!r){a?.(!1,``),c?.(!1,``),e(t,n),h(``);for(let e of y)e.previewUrl&&URL.revokeObjectURL(e.previewUrl);b([]),x.current&&(x.current.style.height=`auto`),S.current&&(S.current.style.height=`auto`)}},[p,y,r,e,a,c]),A=(0,q.useCallback)(e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),k())},[k]),j=(0,q.useCallback)((e,t)=>{let n=e.slice(0,t),r=n.match(/(?:^|\s)\/(\S*)$/);if(r&&w.current.length>0){a?.(!0,r[1]??``),c?.(!1,``);return}let i=n.match(/@(\S*)$/);if(i&&T.current.length>0){c?.(!0,i[1]??``),a?.(!1,``);return}a?.(!1,``),c?.(!1,``)},[a,c]),M=(0,q.useCallback)(e=>{h(e),setTimeout(()=>{j(e,x.current?.selectionStart??e.length)},0)},[j]),N=(0,q.useCallback)(e=>{let t=e?.target??x.current;t&&(t.style.height=`auto`,t.style.height=Math.min(t.scrollHeight,160)+`px`)},[]),P=(0,q.useCallback)(e=>{let t=e.clipboardData?.items;if(!t)return;let n=[];for(let e of t)if(e.kind===`file`){let t=e.getAsFile();t&&n.push(t)}n.length>0&&(e.preventDefault(),D(n))},[D]),F=(0,q.useCallback)(e=>{e.preventDefault();let t=Array.from(e.dataTransfer.files);t.length>0&&D(t)},[D]),I=(0,q.useCallback)(e=>{e.preventDefault()},[]),L=(0,q.useCallback)(()=>{C.current?.click()},[]),z=(0,q.useCallback)(e=>{let t=Array.from(e.target.files??[]);t.length>0&&D(t),e.target.value=``},[D]),B=p.trim().length>0||y.some(e=>e.status===`ready`),V=t&&!B;return(0,Q.jsxs)(`div`,{className:`p-2 md:p-3 bg-background`,children:[(0,Q.jsxs)(`div`,{className:`border border-border rounded-xl md:rounded-2xl bg-surface shadow-sm cursor-text`,onClick:()=>!r&&(S.current??x.current)?.focus(),children:[(0,Q.jsx)(ft,{attachments:y,onRemove:O}),(0,Q.jsxs)(`div`,{className:`flex items-end gap-1 md:hidden px-2 py-2`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),L()},disabled:r,className:`flex items-center justify-center size-7 shrink-0 rounded-full text-text-subtle hover:text-text-primary transition-colors disabled:opacity-50`,"aria-label":`Attach file`,children:(0,Q.jsx)(G,{className:`size-4`})}),(0,Q.jsx)(`textarea`,{ref:S,value:p,onChange:e=>{M(e.target.value),N(e)},onKeyDown:A,onPaste:P,onDrop:F,onDragOver:I,placeholder:t?`Follow-up...`:`Ask anything...`,disabled:r,rows:1,className:`flex-1 resize-none bg-transparent py-1.5 text-sm text-foreground placeholder:text-text-subtle focus:outline-none disabled:opacity-50 max-h-20`}),V?(0,Q.jsx)(`button`,{onClick:e=>{e.stopPropagation(),n?.()},className:`flex items-center justify-center size-7 shrink-0 rounded-full bg-red-600 text-white hover:bg-red-500 transition-colors`,"aria-label":`Stop`,children:(0,Q.jsx)(K,{className:`size-3`})}):(0,Q.jsx)(`button`,{onClick:e=>{e.stopPropagation(),k()},disabled:r||!B,className:`flex items-center justify-center size-7 shrink-0 rounded-full bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-30 transition-colors`,"aria-label":`Send`,children:(0,Q.jsx)(R,{className:`size-3.5`})})]}),(0,Q.jsxs)(`div`,{className:`hidden md:block`,children:[(0,Q.jsx)(`textarea`,{ref:x,value:p,onChange:e=>{M(e.target.value),N(e)},onKeyDown:A,onPaste:P,onDrop:F,onDragOver:I,placeholder:t?`Follow-up or Stop...`:`Ask anything...`,disabled:r,rows:1,className:`w-full resize-none bg-transparent px-4 pt-3 pb-1 text-sm text-foreground placeholder:text-text-subtle focus:outline-none disabled:opacity-50 max-h-40`}),(0,Q.jsxs)(`div`,{className:`flex items-center justify-between px-3 pb-2`,children:[(0,Q.jsx)(`div`,{className:`flex items-center gap-1`,children:(0,Q.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),L()},disabled:r,className:`flex items-center justify-center size-8 rounded-full text-text-subtle hover:text-text-primary hover:bg-surface-elevated transition-colors disabled:opacity-50`,"aria-label":`Attach file`,children:(0,Q.jsx)(G,{className:`size-4`})})}),(0,Q.jsx)(`div`,{className:`flex items-center gap-1`,children:V?(0,Q.jsx)(`button`,{onClick:e=>{e.stopPropagation(),n?.()},className:`flex items-center justify-center size-8 rounded-full bg-red-600 text-white hover:bg-red-500 transition-colors`,"aria-label":`Stop response`,children:(0,Q.jsx)(K,{className:`size-3.5`})}):(0,Q.jsx)(`button`,{onClick:e=>{e.stopPropagation(),k()},disabled:r||!B,className:`flex items-center justify-center size-8 rounded-full bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,"aria-label":`Send message`,children:(0,Q.jsx)(R,{className:`size-4`})})})]})]})]}),(0,Q.jsx)(`input`,{ref:C,type:`file`,multiple:!0,className:`hidden`,onChange:z})]})}function gt({items:e,filter:t,onSelect:n,onClose:r,visible:i}){let[a,o]=(0,q.useState)(0),s=(0,q.useRef)(null),c=e.filter(e=>{let n=t.toLowerCase();return e.name.toLowerCase().includes(n)||e.description.toLowerCase().includes(n)});(0,q.useEffect)(()=>{o(0)},[t]),(0,q.useEffect)(()=>{let e=s.current;e&&e.children[a]?.scrollIntoView({block:`nearest`})},[a]);let l=(0,q.useCallback)(e=>{if(!i||c.length===0)return!1;switch(e.key){case`ArrowUp`:return e.preventDefault(),o(e=>e>0?e-1:c.length-1),!0;case`ArrowDown`:return e.preventDefault(),o(e=>e<c.length-1?e+1:0),!0;case`Enter`:case`Tab`:return e.preventDefault(),c[a]&&n(c[a]),!0;case`Escape`:return e.preventDefault(),r(),!0}return!1},[i,c,a,n,r]);return(0,q.useEffect)(()=>{if(!i)return;let e=e=>{l(e)&&e.stopPropagation()};return document.addEventListener(`keydown`,e,!0),()=>document.removeEventListener(`keydown`,e,!0)},[i,l]),!i||c.length===0?null:(0,Q.jsx)(`div`,{className:`max-h-52 overflow-y-auto border-b border-border bg-surface`,children:(0,Q.jsx)(`div`,{ref:s,className:`py-1`,children:c.map((e,t)=>(0,Q.jsxs)(`button`,{className:`flex items-start gap-3 w-full px-3 py-2 text-left transition-colors ${t===a?`bg-primary/10 text-primary`:`hover:bg-surface-hover text-text-primary`}`,onMouseEnter:()=>o(t),onClick:()=>n(e),children:[(0,Q.jsx)(`span`,{className:`shrink-0 mt-0.5`,children:e.type===`skill`?(0,Q.jsx)(re,{className:`size-4 text-amber-500`}):(0,Q.jsx)(k,{className:`size-4 text-blue-500`})}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,Q.jsxs)(`span`,{className:`font-medium text-sm`,children:[`/`,e.name]}),e.argumentHint&&(0,Q.jsx)(`span`,{className:`text-xs text-text-subtle`,children:e.argumentHint}),(0,Q.jsx)(`span`,{className:`text-xs text-text-subtle capitalize ml-auto`,children:e.scope===`user`?`global`:e.type})]}),e.description&&(0,Q.jsx)(`p`,{className:`text-xs text-text-subtle mt-0.5 line-clamp-2`,children:e.description})]})]},`${e.type}-${e.name}`))})})}function _t(e){return e>=90?`text-red-500`:e>=70?`text-amber-500`:`text-green-500`}function vt(e){return e>=90?`bg-red-500`:e>=70?`bg-amber-500`:`bg-green-500`}function yt(e){if(!e)return null;let t=null;if(e.resetsInMinutes!=null)t=e.resetsInMinutes;else if(e.resetsInHours!=null)t=Math.round(e.resetsInHours*60);else if(e.resetsAt){let n=new Date(e.resetsAt).getTime()-Date.now();t=n>0?Math.ceil(n/6e4):0}if(t==null)return null;if(t<=0)return`now`;let n=Math.floor(t/1440),r=Math.floor(t%1440/60),i=t%60;return n>0?i>0?`${n}d ${r}h ${i}m`:r>0?`${n}d ${r}h`:`${n}d`:r>0?i>0?`${r}h ${i}m`:`${r}h`:`${i}m`}function bt({label:e,bucket:t}){if(!t)return null;let n=Math.round(t.utilization*100),r=yt(t);return(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsx)(`span`,{className:`text-xs font-medium text-text-primary`,children:e}),r&&(0,Q.jsxs)(`span`,{className:`text-[10px] text-text-subtle`,children:[`↻ `,r]})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`div`,{className:`flex-1 h-2 rounded-full bg-border overflow-hidden`,children:(0,Q.jsx)(`div`,{className:`h-full rounded-full transition-all ${vt(n)}`,style:{width:`${Math.min(n,100)}%`}})}),(0,Q.jsxs)(`span`,{className:`text-xs font-medium tabular-nums w-10 text-right ${_t(n)}`,children:[n,`%`]})]})]})}function xt(e){if(!e)return null;let t=Math.round((Date.now()-e)/1e3);return t<5?`just now`:t<60?`${t}s ago`:`${Math.floor(t/60)}m ago`}function St({usage:e,visible:t,onClose:n,onReload:r,loading:i,lastFetchedAt:a}){if(!t)return null;let o=e.queryCostUsd!=null||e.totalCostUsd!=null,s=e.session||e.weekly||e.weeklyOpus||e.weeklySonnet;return(0,Q.jsxs)(`div`,{className:`border-b border-border bg-surface px-3 py-2.5 space-y-2.5`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`text-xs font-semibold text-text-primary`,children:`Usage Limits`}),a&&(0,Q.jsx)(`span`,{className:`text-[10px] text-text-subtle`,children:xt(new Date(a).getTime())})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[r&&(0,Q.jsx)(`button`,{onClick:r,disabled:i,className:`text-xs text-text-subtle hover:text-text-primary px-1 disabled:opacity-50`,title:`Refresh usage data`,children:(0,Q.jsx)(x,{className:`size-3 ${i?`animate-spin`:``}`})}),(0,Q.jsx)(`button`,{onClick:n,className:`text-xs text-text-subtle hover:text-text-primary px-1`,children:`✕`})]})]}),s?(0,Q.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,Q.jsx)(bt,{label:`5-Hour Session`,bucket:e.session}),(0,Q.jsx)(bt,{label:`Weekly`,bucket:e.weekly}),(0,Q.jsx)(bt,{label:`Weekly (Opus)`,bucket:e.weeklyOpus}),(0,Q.jsx)(bt,{label:`Weekly (Sonnet)`,bucket:e.weeklySonnet})]}):(0,Q.jsxs)(`p`,{className:`text-xs text-text-subtle`,children:[`No data — run `,(0,Q.jsx)(`code`,{className:`bg-surface-elevated px-1 rounded`,children:`bun install`})]}),o&&(0,Q.jsxs)(`div`,{className:`border-t border-border pt-2 space-y-1`,children:[e.queryCostUsd!=null&&(0,Q.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,Q.jsx)(`span`,{className:`text-text-subtle`,children:`Last query`}),(0,Q.jsxs)(`span`,{className:`text-text-primary font-medium tabular-nums`,children:[`$`,e.queryCostUsd.toFixed(4)]})]}),e.totalCostUsd!=null&&(0,Q.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,Q.jsx)(`span`,{className:`text-text-subtle`,children:`Session total`}),(0,Q.jsxs)(`span`,{className:`text-text-primary font-medium tabular-nums`,children:[`$`,e.totalCostUsd.toFixed(4)]})]})]})]})}function Ct(e){try{return new Date(e).toLocaleDateString(void 0,{month:`short`,day:`numeric`})}catch{return``}}function wt(e){return e>=90?`text-red-500`:e>=70?`text-amber-500`:`text-green-500`}function Tt({projectName:e,usageInfo:t,contextWindowPct:n,usageLoading:r,refreshUsage:i,lastFetchedAt:o,sessionId:l,onSelectSession:u,onBugReport:d,isConnected:p,onReconnect:m}){let[h,_]=(0,q.useState)(null),[b,C]=(0,q.useState)([]),[w,T]=(0,q.useState)(!1),D=M(e=>l?e.notifications.has(l):!1),k=M(e=>e.clearForSession),[A,j]=(0,q.useState)(``),[N,F]=(0,q.useState)(null),[I,R]=(0,q.useState)(``),z=(0,q.useRef)(null),B=f(e=>e.openTab),V=e=>{_(t=>t===e?null:e)},H=(0,q.useCallback)(async()=>{if(e){T(!0);try{C(await v.get(`${g(e)}/chat/sessions`))}catch{}finally{T(!1)}}},[e]);(0,q.useEffect)(()=>{h===`history`&&b.length===0&&H()},[h]);function U(t){u?(u(t),_(null)):B({type:`chat`,title:t.title||`Chat`,projectId:e??null,metadata:{projectName:e,sessionId:t.id},closable:!0})}let W=(0,q.useCallback)((e,t)=>{t.stopPropagation(),F(e.id),R(e.title||``),setTimeout(()=>z.current?.select(),0)},[]),G=(0,q.useCallback)(async()=>{if(!N||!I.trim()||!e){F(null);return}try{await v.patch(`${g(e)}/chat/sessions/${N}`,{title:I.trim()}),C(e=>e.map(e=>e.id===N?{...e,title:I.trim()}:e))}catch{}F(null)},[N,I,e]),ne=(0,q.useCallback)(()=>F(null),[]),re=A.trim()?b.filter(e=>(e.title||``).toLowerCase().includes(A.toLowerCase())):b,K=t.fiveHour==null?null:Math.round(t.fiveHour*100),J=t.sevenDay==null?null:Math.round(t.sevenDay*100),Y=K!=null||J!=null?wt(Math.max(K??0,J??0)):`text-text-subtle`;return(0,Q.jsxs)(`div`,{className:`border-b border-border/50`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1 px-2 py-1`,children:[(0,Q.jsxs)(`button`,{onClick:()=>V(`history`),className:`flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] transition-colors ${h===`history`?`text-primary bg-primary/10`:`text-text-secondary hover:text-foreground hover:bg-surface-elevated`}`,children:[(0,Q.jsx)(ee,{className:`size-3`}),(0,Q.jsx)(`span`,{children:`History`})]}),(0,Q.jsx)(`button`,{onClick:()=>V(`config`),className:`p-1 rounded transition-colors ${h===`config`?`text-primary bg-primary/10`:`text-text-subtle hover:text-text-secondary hover:bg-surface-elevated`}`,title:`AI Settings`,children:(0,Q.jsx)(te,{className:`size-3`})}),(0,Q.jsxs)(`button`,{onClick:()=>V(`usage`),className:`flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] font-medium tabular-nums transition-colors hover:bg-surface-elevated ${h===`usage`?`bg-primary/10`:``} ${Y}`,title:`Usage limits`,children:[(0,Q.jsx)(L,{className:`size-3`}),(0,Q.jsxs)(`span`,{children:[`5h:`,K==null?`--%`:`${K}%`]}),(0,Q.jsx)(`span`,{className:`text-text-subtle`,children:`·`}),(0,Q.jsxs)(`span`,{children:[`Wk:`,J==null?`--%`:`${J}%`]}),n!=null&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{className:`text-text-subtle`,children:`·`}),(0,Q.jsxs)(`span`,{className:wt(n),children:[`Ctx:`,n,`%`]})]})]}),(0,Q.jsx)(`div`,{className:`flex-1`}),D&&l&&(0,Q.jsx)(`button`,{onClick:()=>k(l),className:`p-1 rounded text-amber-500 hover:text-amber-400 hover:bg-surface-elevated transition-colors`,title:`Mark as read`,children:(0,Q.jsx)(s,{className:`size-3`})}),m&&(0,Q.jsx)(`button`,{onClick:m,className:`size-4 flex items-center justify-center`,title:p?`Connected`:`Disconnected — click to reconnect`,children:(0,Q.jsx)(`span`,{className:`size-2 rounded-full ${p?`bg-green-500`:`bg-red-500 animate-pulse`}`})})]}),h===`history`&&(0,Q.jsxs)(`div`,{className:`border-t border-border/30 bg-surface`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5 px-2 py-1 border-b border-border/30`,children:[(0,Q.jsx)(S,{className:`size-3 text-text-subtle shrink-0`}),(0,Q.jsx)(`input`,{type:`text`,value:A,onChange:e=>j(e.target.value),placeholder:`Search sessions...`,className:`flex-1 bg-transparent text-[11px] text-text-primary outline-none placeholder:text-text-subtle`}),(0,Q.jsx)(`button`,{onClick:H,disabled:w,className:`p-0.5 rounded text-text-subtle hover:text-text-secondary transition-colors disabled:opacity-50`,title:`Refresh`,children:(0,Q.jsx)(x,{className:`size-3 ${w?`animate-spin`:``}`})})]}),(0,Q.jsx)(`div`,{className:`max-h-[200px] overflow-y-auto`,children:w&&b.length===0?(0,Q.jsx)(`div`,{className:`flex items-center justify-center py-3`,children:(0,Q.jsx)(P,{className:`size-3.5 animate-spin text-text-subtle`})}):re.length===0?(0,Q.jsx)(`div`,{className:`flex items-center justify-center py-3 text-[11px] text-text-subtle`,children:A?`No matching sessions`:`No sessions yet`}):re.map(e=>(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 w-full px-3 py-1.5 text-left hover:bg-surface-elevated transition-colors group`,children:[(0,Q.jsx)(y,{className:`size-3 shrink-0 text-text-subtle`}),N===e.id?(0,Q.jsxs)(`form`,{className:`flex items-center gap-1 flex-1 min-w-0`,onSubmit:e=>{e.preventDefault(),G()},children:[(0,Q.jsx)(`input`,{ref:z,value:I,onChange:e=>R(e.target.value),onBlur:G,onKeyDown:e=>{e.key===`Escape`&&ne()},className:`flex-1 min-w-0 bg-surface-elevated text-[11px] text-text-primary px-1 py-0.5 rounded border border-border outline-none focus:border-primary`,autoFocus:!0}),(0,Q.jsx)(`button`,{type:`submit`,className:`p-0.5 text-green-500 hover:text-green-400`,onClick:e=>e.stopPropagation(),children:(0,Q.jsx)(a,{className:`size-3`})}),(0,Q.jsx)(`button`,{type:`button`,className:`p-0.5 text-text-subtle hover:text-text-secondary`,onClick:e=>{e.stopPropagation(),ne()},children:(0,Q.jsx)(O,{className:`size-3`})})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`button`,{onClick:()=>U(e),className:`text-[11px] truncate flex-1 text-left`,children:e.title||`Untitled`}),(0,Q.jsx)(`button`,{onClick:t=>W(e,t),className:`p-0.5 rounded text-text-subtle hover:text-text-secondary opacity-0 group-hover:opacity-100 transition-opacity`,title:`Rename session`,children:(0,Q.jsx)(E,{className:`size-3`})})]}),N!==e.id&&e.updatedAt&&(0,Q.jsx)(`span`,{className:`text-[10px] text-text-subtle shrink-0`,children:Ct(e.updatedAt)})]},e.id))})]}),h===`config`&&(0,Q.jsx)(`div`,{className:`border-t border-border/30 bg-surface px-3 py-2 max-h-[280px] overflow-y-auto`,children:(0,Q.jsx)(c,{compact:!0})}),h===`usage`&&(0,Q.jsx)(St,{usage:t,visible:!0,onClose:()=>_(null),onReload:i,loading:r,lastFetchedAt:o})]})}function Et({metadata:e,tabId:t}){let[n,r]=(0,q.useState)(e?.sessionId??null),[i,a]=(0,q.useState)(e?.providerId??`claude`),[o,s]=(0,q.useState)([]),[c,l]=(0,q.useState)(!1),[u,m]=(0,q.useState)(``),[h,_]=(0,q.useState)(null),[y,x]=(0,q.useState)([]),[S,C]=(0,q.useState)(!1),[w,T]=(0,q.useState)(``),[E,D]=(0,q.useState)(null),[O,k]=(0,q.useState)(!1),[A,j]=(0,q.useState)(null),P=(0,q.useRef)(0),I=e?.projectName??``,L=f(e=>e.updateTab),R=p(e=>e.version),{usageInfo:z,usageLoading:B,lastFetchedAt:V,refreshUsage:H}=he(I,i);(0,q.useEffect)(()=>{!t||!n||L(t,{metadata:{...e,sessionId:n,providerId:i}})},[n,i]);let{messages:ee,messagesLoading:U,isStreaming:W,streamingStatus:G,connectingElapsed:te,thinkingWarningThreshold:ne,pendingApproval:re,contextWindowPct:K,sessionTitle:J,sendMessage:Y,respondToApproval:ie,cancelStreaming:ae,reconnect:oe,refetchMessages:X,isConnected:Z}=pe(n,i,I);(0,q.useEffect)(()=>{if(!n||!t)return;let e=()=>{if(document.hidden)return;let{panels:e,focusedPanelId:r}=d.getState();e[r]?.activeTabId===t&&M.getState().clearForSession(n)};e(),document.addEventListener(`visibilitychange`,e);let r=d.subscribe(e);return()=>{document.removeEventListener(`visibilitychange`,e),r()}},[n,t]),(0,q.useEffect)(()=>{t&&J&&L(t,{title:J})},[J]);let se=(0,q.useRef)(e?.pendingMessage);(0,q.useEffect)(()=>{if(se.current&&Z&&n){let n=se.current;se.current=void 0,t&&L(t,{metadata:{...e,pendingMessage:void 0}}),setTimeout(()=>Y(n),100)}},[Z,n]),(0,q.useCallback)(()=>{f.getState().openTab({type:`chat`,title:`AI Chat`,metadata:{projectName:I},projectId:I||null,closable:!0})},[I]);let ce=(0,q.useCallback)(e=>{r(e.id),a(e.providerId),t&&L(t,{title:e.title||`Chat`})},[t,L]),le=(0,q.useCallback)(async e=>{if(!(!n||!I))try{let{api:t,projectUrl:r}=await N(async()=>{let{api:e,projectUrl:t}=await import(`./api-client-TUmacMRS.js`).then(e=>e.n);return{api:e,projectUrl:t}},__vite__mapDeps([0,1])),a=await t.post(`${r(I)}/chat/sessions/${n}/fork?providerId=${i}`);f.getState().openTab({type:`chat`,title:`Fork: ${e.slice(0,30)}`,metadata:{projectName:I,sessionId:a.id,providerId:i,pendingMessage:e},projectId:I||null,closable:!0})}catch(e){console.error(`Fork failed:`,e)}},[n,I,i]),ue=(0,q.useCallback)((e,t)=>{if(t.length===0)return e;let n=t.filter(e=>e.serverPath).map(e=>e.serverPath).join(`
7
+ `);return n?(t.length===1?`[Attached file: ${n}]\n\n`:`[Attached files:\n${n}\n]\n\n`)+e:e},[]),de=(0,q.useCallback)(async(e,t=[])=>{let o=ue(e,t);if(o.trim()){if(!n)try{let t=I,n=await v.post(`${g(t)}/chat/sessions`,{providerId:i,title:e.slice(0,50)});r(n.id),a(n.providerId),setTimeout(()=>{Y(o)},500);return}catch(e){console.error(`Failed to create session:`,e);return}Y(o)}},[n,i,I,Y,ue]),fe=(0,q.useCallback)((e,t)=>{l(e),m(t)},[]),me=(0,q.useCallback)(e=>{_(e),l(!1),m(``),setTimeout(()=>_(null),50)},[]),ge=(0,q.useCallback)(()=>{l(!1),m(``)},[]),_e=(0,q.useCallback)((e,t)=>{C(e),T(t)},[]),ve=(0,q.useCallback)(e=>{D(e),C(!1),T(``),setTimeout(()=>D(null),50)},[]),ye=(0,q.useCallback)(()=>{C(!1),T(``)},[]);return(0,Q.jsxs)(`div`,{className:`flex flex-col h-full relative`,onDragEnter:(0,q.useCallback)(e=>{e.preventDefault(),P.current++,e.dataTransfer.types.includes(`Files`)&&k(!0)},[]),onDragLeave:(0,q.useCallback)(e=>{e.preventDefault(),P.current--,P.current===0&&k(!1)},[]),onDragOver:(0,q.useCallback)(e=>{e.preventDefault()},[]),onDrop:(0,q.useCallback)(e=>{e.preventDefault(),P.current=0,k(!1);let t=Array.from(e.dataTransfer.files);t.length>0&&(j(t),setTimeout(()=>j(null),100))},[]),children:[O&&(0,Q.jsx)(`div`,{className:`absolute inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm border-2 border-dashed border-primary rounded-lg pointer-events-none`,children:(0,Q.jsxs)(`div`,{className:`flex flex-col items-center gap-2 text-primary`,children:[(0,Q.jsx)(b,{className:`size-8`}),(0,Q.jsx)(`span`,{className:`text-sm font-medium`,children:`Drop files to attach`})]})}),(0,Q.jsx)(Ve,{messages:ee,messagesLoading:U,pendingApproval:re,onApprovalResponse:ie,isStreaming:W,streamingStatus:G,connectingElapsed:te,thinkingWarningThreshold:ne,projectName:I,onFork:W?void 0:le}),(0,Q.jsxs)(`div`,{className:`border-t border-border bg-background shrink-0`,children:[(0,Q.jsx)(Tt,{projectName:I,usageInfo:z,contextWindowPct:K,usageLoading:B,refreshUsage:H,lastFetchedAt:V,sessionId:n,onSelectSession:ce,onBugReport:n?()=>F(R,{sessionId:n,projectName:I}):void 0,isConnected:Z,onReconnect:()=>{Z||oe(),X()}}),(0,Q.jsx)(gt,{items:o,filter:u,onSelect:me,onClose:ge,visible:c}),(0,Q.jsx)(mt,{items:y,filter:w,onSelect:ve,onClose:ye,visible:S}),(0,Q.jsx)(ht,{onSend:de,isStreaming:W,onCancel:ae,projectName:I,onSlashStateChange:fe,onSlashItemsLoaded:s,slashSelected:h,onFileStateChange:_e,onFileItemsLoaded:x,fileSelected:E,externalFiles:A})]})]})}export{Et as ChatTab};
@@ -1 +1 @@
1
- import{i as e,t}from"./react-CYzKIDNi.js";import{n,t as r}from"./jsx-runtime-wQxeESYQ.js";import{a as i,t as a}from"./tab-store-D7tRt0VT.js";import{n as o}from"./settings-store-DS-ifJ7c.js";import{t as s}from"./utils-DBpa1UZX.js";import{i as c,r as l,t as u}from"./api-client-B0aMOJxF.js";import{A as d}from"./index-B9ZHWVob.js";import{t as f}from"./markdown-renderer-DKVNZXEw.js";import{n as p,t as m}from"./use-monaco-theme-M04jkKDM.js";var h=n(`file-exclamation-point`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M12 9v4`,key:`juzpu7`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),g=e(t(),1),_=r(),v=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`ico`]),y=new Set([`db`,`sqlite`,`sqlite3`]);function b(e){return e.split(`.`).pop()?.toLowerCase()??``}function x(e){return{js:`javascript`,jsx:`javascript`,ts:`typescript`,tsx:`typescript`,py:`python`,html:`html`,css:`css`,scss:`scss`,json:`json`,md:`markdown`,mdx:`markdown`,yaml:`yaml`,yml:`yaml`,sh:`shell`,bash:`shell`}[b(e)]??`plaintext`}function S({metadata:e,tabId:t}){let n=e?.filePath,r=e?.projectName,[i,l]=(0,g.useState)(null),[f,S]=(0,g.useState)(`utf-8`),[E,D]=(0,g.useState)(!0),[O,k]=(0,g.useState)(null),[A,j]=(0,g.useState)(!1),M=(0,g.useRef)(null),N=(0,g.useRef)(``),P=(0,g.useRef)(null),{tabs:F,updateTab:I}=a(),{wordWrap:L,toggleWordWrap:R}=o(),z=m(),B=F.find(e=>e.id===t),V=n?b(n):``,H=v.has(V),U=V===`pdf`,W=y.has(V),G=V===`md`||V===`mdx`,[K,q]=(0,g.useState)(`preview`);(0,g.useEffect)(()=>{W&&t&&I(t,{type:`sqlite`})},[W,t,I]);let J=n?/^(\/|[A-Za-z]:[/\\])/.test(n):!1;(0,g.useEffect)(()=>{if(!n||!J&&!r)return;if(H||U){D(!1);return}D(!0),k(null);let e=J?`/api/fs/read?path=${encodeURIComponent(n)}`:`${c(r)}/files/read?path=${encodeURIComponent(n)}`;return u.get(e).then(e=>{l(e.content),e.encoding&&S(e.encoding),N.current=e.content,D(!1)}).catch(e=>{k(e instanceof Error?e.message:`Failed to load file`),D(!1)}),()=>{M.current&&clearTimeout(M.current)}},[n,r,H,U,J]),(0,g.useEffect)(()=>{if(!B)return;let e=n?s(n):`Untitled`,t=A?`${e} \u25CF`:e;B.title!==t&&I(B.id,{title:t})},[A]);let Y=(0,g.useCallback)(async e=>{if(n&&!(!J&&!r))try{J?await u.put(`/api/fs/write`,{path:n,content:e}):await u.put(`${c(r)}/files/write`,{path:n,content:e}),j(!1)}catch{}},[n,r,J]);function X(e){let t=e??``;l(t),N.current=t,j(!0),M.current&&clearTimeout(M.current),M.current=setTimeout(()=>Y(N.current),1e3)}let Z=e?.lineNumber,Q=(0,g.useCallback)((e,t)=>{P.current=e,Z&&Z>0&&setTimeout(()=>{e.revealLineInCenter(Z),e.setPosition({lineNumber:Z,column:1}),e.focus()},100),e.addCommand(t.KeyMod.Alt|t.KeyCode.KeyZ,()=>o.getState().toggleWordWrap()),t.languages.typescript.typescriptDefaults.setDiagnosticsOptions({noSemanticValidation:!0,noSyntaxValidation:!0,noSuggestionDiagnostics:!0}),t.languages.typescript.javascriptDefaults.setDiagnosticsOptions({noSemanticValidation:!0,noSyntaxValidation:!0,noSuggestionDiagnostics:!0})},[]);return!n||!J&&!r?(0,_.jsx)(`div`,{className:`flex items-center justify-center h-full text-text-secondary text-sm`,children:`No file selected.`}):E?(0,_.jsxs)(`div`,{className:`flex items-center justify-center h-full gap-2 text-text-secondary`,children:[(0,_.jsx)(d,{className:`size-5 animate-spin`}),(0,_.jsx)(`span`,{className:`text-sm`,children:`Loading file...`})]}):O?(0,_.jsx)(`div`,{className:`flex items-center justify-center h-full text-error text-sm`,children:O}):H?(0,_.jsx)(w,{filePath:n,projectName:r}):U?(0,_.jsx)(T,{filePath:n,projectName:r}):f===`base64`?(0,_.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,_.jsx)(h,{className:`size-10 text-text-subtle`}),(0,_.jsx)(`p`,{className:`text-sm`,children:`This file is a binary format and cannot be displayed.`}),(0,_.jsx)(`p`,{className:`text-xs text-text-subtle`,children:n})]}):(0,_.jsx)(`div`,{className:`flex flex-col h-full w-full overflow-hidden`,children:G&&K===`preview`?(0,_.jsx)(C,{content:i??``}):(0,_.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:(0,_.jsx)(p,{height:`100%`,language:x(n),value:i??``,onChange:X,onMount:Q,theme:z,options:{fontSize:13,fontFamily:`Menlo, Monaco, Consolas, monospace`,wordWrap:L?`on`:`off`,minimap:{enabled:!1},scrollBeyondLastLine:!1,automaticLayout:!0,lineNumbers:`on`,folding:!0,bracketPairColorization:{enabled:!0}},loading:(0,_.jsx)(d,{className:`size-5 animate-spin text-text-subtle`})})})})}function C({content:e}){return(0,_.jsx)(f,{content:e,className:`flex-1 overflow-auto p-4`})}function w({filePath:e,projectName:t}){let[n,r]=(0,g.useState)(null),[i,a]=(0,g.useState)(!1);return(0,g.useEffect)(()=>{let n,i=`${c(t)}/files/raw?path=${encodeURIComponent(e)}`,o=l();return fetch(i,{headers:o?{Authorization:`Bearer ${o}`}:{}}).then(e=>{if(!e.ok)throw Error(`Failed`);return e.blob()}).then(e=>{let t=URL.createObjectURL(e);n=t,r(t)}).catch(()=>a(!0)),()=>{n&&URL.revokeObjectURL(n)}},[e,t]),i?(0,_.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,_.jsx)(h,{className:`size-10 text-text-subtle`}),(0,_.jsx)(`p`,{className:`text-sm`,children:`Failed to load image.`})]}):n?(0,_.jsx)(`div`,{className:`flex items-center justify-center h-full p-4 bg-surface overflow-auto`,children:(0,_.jsx)(`img`,{src:n,alt:e,className:`max-w-full max-h-full object-contain`})}):(0,_.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,_.jsx)(d,{className:`size-5 animate-spin text-text-subtle`})})}function T({filePath:e,projectName:t}){let[n,r]=(0,g.useState)(null),[a,o]=(0,g.useState)(!1);(0,g.useEffect)(()=>{let n,i=`${c(t)}/files/raw?path=${encodeURIComponent(e)}`,a=l();return fetch(i,{headers:a?{Authorization:`Bearer ${a}`}:{}}).then(e=>{if(!e.ok)throw Error(`Failed`);return e.blob()}).then(e=>{let t=URL.createObjectURL(new Blob([e],{type:`application/pdf`}));n=t,r(t)}).catch(()=>o(!0)),()=>{n&&URL.revokeObjectURL(n)}},[e,t]);let s=(0,g.useCallback)(()=>{n&&window.open(n,`_blank`)},[n]);return a?(0,_.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,_.jsx)(h,{className:`size-10 text-text-subtle`}),(0,_.jsx)(`p`,{className:`text-sm`,children:`Failed to load PDF.`})]}):n?(0,_.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,_.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-1.5 border-b border-border bg-background shrink-0`,children:[(0,_.jsx)(`span`,{className:`text-xs text-text-secondary truncate`,children:e}),(0,_.jsxs)(`button`,{onClick:s,className:`flex items-center gap-1 text-xs text-text-secondary hover:text-text-primary transition-colors`,children:[(0,_.jsx)(i,{className:`size-3`}),` Open in new tab`]})]}),(0,_.jsx)(`iframe`,{src:n,title:e,className:`flex-1 w-full border-none`})]}):(0,_.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,_.jsx)(d,{className:`size-5 animate-spin text-text-subtle`})})}export{S as CodeEditor};
1
+ import{i as e,t}from"./react-CYzKIDNi.js";import{n,t as r}from"./jsx-runtime-wQxeESYQ.js";import{a as i,t as a}from"./tab-store-0CKk8cSr.js";import{n as o}from"./settings-store-2NQzaOVJ.js";import{t as s}from"./utils-DC-bdPS3.js";import{i as c,r as l,t as u}from"./api-client-TUmacMRS.js";import{j as d}from"./index-YO_w11fv.js";import{t as f}from"./markdown-renderer-BkXmQhhX.js";import{n as p,t as m}from"./use-monaco-theme-Bt1Lr3jH.js";var h=n(`file-exclamation-point`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M12 9v4`,key:`juzpu7`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),g=e(t(),1),_=r(),v=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`ico`]),y=new Set([`db`,`sqlite`,`sqlite3`]);function b(e){return e.split(`.`).pop()?.toLowerCase()??``}function x(e){return{js:`javascript`,jsx:`javascript`,ts:`typescript`,tsx:`typescript`,py:`python`,html:`html`,css:`css`,scss:`scss`,json:`json`,md:`markdown`,mdx:`markdown`,yaml:`yaml`,yml:`yaml`,sh:`shell`,bash:`shell`}[b(e)]??`plaintext`}function S({metadata:e,tabId:t}){let n=e?.filePath,r=e?.projectName,[i,l]=(0,g.useState)(null),[f,S]=(0,g.useState)(`utf-8`),[E,D]=(0,g.useState)(!0),[O,k]=(0,g.useState)(null),[A,j]=(0,g.useState)(!1),M=(0,g.useRef)(null),N=(0,g.useRef)(``),P=(0,g.useRef)(null),{tabs:F,updateTab:I}=a(),{wordWrap:L,toggleWordWrap:R}=o(),z=m(),B=F.find(e=>e.id===t),V=n?b(n):``,H=v.has(V),U=V===`pdf`,W=y.has(V),G=V===`md`||V===`mdx`,[K,q]=(0,g.useState)(`preview`);(0,g.useEffect)(()=>{W&&t&&I(t,{type:`sqlite`})},[W,t,I]);let J=n?/^(\/|[A-Za-z]:[/\\])/.test(n):!1;(0,g.useEffect)(()=>{if(!n||!J&&!r)return;if(H||U){D(!1);return}D(!0),k(null);let e=J?`/api/fs/read?path=${encodeURIComponent(n)}`:`${c(r)}/files/read?path=${encodeURIComponent(n)}`;return u.get(e).then(e=>{l(e.content),e.encoding&&S(e.encoding),N.current=e.content,D(!1)}).catch(e=>{k(e instanceof Error?e.message:`Failed to load file`),D(!1)}),()=>{M.current&&clearTimeout(M.current)}},[n,r,H,U,J]),(0,g.useEffect)(()=>{if(!B)return;let e=n?s(n):`Untitled`,t=A?`${e} \u25CF`:e;B.title!==t&&I(B.id,{title:t})},[A]);let Y=(0,g.useCallback)(async e=>{if(n&&!(!J&&!r))try{J?await u.put(`/api/fs/write`,{path:n,content:e}):await u.put(`${c(r)}/files/write`,{path:n,content:e}),j(!1)}catch{}},[n,r,J]);function X(e){let t=e??``;l(t),N.current=t,j(!0),M.current&&clearTimeout(M.current),M.current=setTimeout(()=>Y(N.current),1e3)}let Z=e?.lineNumber,Q=(0,g.useCallback)((e,t)=>{P.current=e,Z&&Z>0&&setTimeout(()=>{e.revealLineInCenter(Z),e.setPosition({lineNumber:Z,column:1}),e.focus()},100),e.addCommand(t.KeyMod.Alt|t.KeyCode.KeyZ,()=>o.getState().toggleWordWrap()),t.languages.typescript.typescriptDefaults.setDiagnosticsOptions({noSemanticValidation:!0,noSyntaxValidation:!0,noSuggestionDiagnostics:!0}),t.languages.typescript.javascriptDefaults.setDiagnosticsOptions({noSemanticValidation:!0,noSyntaxValidation:!0,noSuggestionDiagnostics:!0})},[]);return!n||!J&&!r?(0,_.jsx)(`div`,{className:`flex items-center justify-center h-full text-text-secondary text-sm`,children:`No file selected.`}):E?(0,_.jsxs)(`div`,{className:`flex items-center justify-center h-full gap-2 text-text-secondary`,children:[(0,_.jsx)(d,{className:`size-5 animate-spin`}),(0,_.jsx)(`span`,{className:`text-sm`,children:`Loading file...`})]}):O?(0,_.jsx)(`div`,{className:`flex items-center justify-center h-full text-error text-sm`,children:O}):H?(0,_.jsx)(w,{filePath:n,projectName:r}):U?(0,_.jsx)(T,{filePath:n,projectName:r}):f===`base64`?(0,_.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,_.jsx)(h,{className:`size-10 text-text-subtle`}),(0,_.jsx)(`p`,{className:`text-sm`,children:`This file is a binary format and cannot be displayed.`}),(0,_.jsx)(`p`,{className:`text-xs text-text-subtle`,children:n})]}):(0,_.jsx)(`div`,{className:`flex flex-col h-full w-full overflow-hidden`,children:G&&K===`preview`?(0,_.jsx)(C,{content:i??``}):(0,_.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:(0,_.jsx)(p,{height:`100%`,language:x(n),value:i??``,onChange:X,onMount:Q,theme:z,options:{fontSize:13,fontFamily:`Menlo, Monaco, Consolas, monospace`,wordWrap:L?`on`:`off`,minimap:{enabled:!1},scrollBeyondLastLine:!1,automaticLayout:!0,lineNumbers:`on`,folding:!0,bracketPairColorization:{enabled:!0}},loading:(0,_.jsx)(d,{className:`size-5 animate-spin text-text-subtle`})})})})}function C({content:e}){return(0,_.jsx)(f,{content:e,className:`flex-1 overflow-auto p-4`})}function w({filePath:e,projectName:t}){let[n,r]=(0,g.useState)(null),[i,a]=(0,g.useState)(!1);return(0,g.useEffect)(()=>{let n,i=`${c(t)}/files/raw?path=${encodeURIComponent(e)}`,o=l();return fetch(i,{headers:o?{Authorization:`Bearer ${o}`}:{}}).then(e=>{if(!e.ok)throw Error(`Failed`);return e.blob()}).then(e=>{let t=URL.createObjectURL(e);n=t,r(t)}).catch(()=>a(!0)),()=>{n&&URL.revokeObjectURL(n)}},[e,t]),i?(0,_.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,_.jsx)(h,{className:`size-10 text-text-subtle`}),(0,_.jsx)(`p`,{className:`text-sm`,children:`Failed to load image.`})]}):n?(0,_.jsx)(`div`,{className:`flex items-center justify-center h-full p-4 bg-surface overflow-auto`,children:(0,_.jsx)(`img`,{src:n,alt:e,className:`max-w-full max-h-full object-contain`})}):(0,_.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,_.jsx)(d,{className:`size-5 animate-spin text-text-subtle`})})}function T({filePath:e,projectName:t}){let[n,r]=(0,g.useState)(null),[a,o]=(0,g.useState)(!1);(0,g.useEffect)(()=>{let n,i=`${c(t)}/files/raw?path=${encodeURIComponent(e)}`,a=l();return fetch(i,{headers:a?{Authorization:`Bearer ${a}`}:{}}).then(e=>{if(!e.ok)throw Error(`Failed`);return e.blob()}).then(e=>{let t=URL.createObjectURL(new Blob([e],{type:`application/pdf`}));n=t,r(t)}).catch(()=>o(!0)),()=>{n&&URL.revokeObjectURL(n)}},[e,t]);let s=(0,g.useCallback)(()=>{n&&window.open(n,`_blank`)},[n]);return a?(0,_.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,_.jsx)(h,{className:`size-10 text-text-subtle`}),(0,_.jsx)(`p`,{className:`text-sm`,children:`Failed to load PDF.`})]}):n?(0,_.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,_.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-1.5 border-b border-border bg-background shrink-0`,children:[(0,_.jsx)(`span`,{className:`text-xs text-text-secondary truncate`,children:e}),(0,_.jsxs)(`button`,{onClick:s,className:`flex items-center gap-1 text-xs text-text-secondary hover:text-text-primary transition-colors`,children:[(0,_.jsx)(i,{className:`size-3`}),` Open in new tab`]})]}),(0,_.jsx)(`iframe`,{src:n,title:e,className:`flex-1 w-full border-none`})]}):(0,_.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,_.jsx)(d,{className:`size-5 animate-spin text-text-subtle`})})}export{S as CodeEditor};
@@ -0,0 +1 @@
1
+ import{n as e}from"./jsx-runtime-wQxeESYQ.js";var t=e(`columns-2`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M12 3v18`,key:`108xh3`}]]);export{t};