@hienlh/ppm 0.2.19 → 0.2.20

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 (33) hide show
  1. package/dist/web/assets/api-client-DzH9zCD7.js +1 -0
  2. package/dist/web/assets/{button-CvHWF07y.js → button-CQ5h5gxS.js} +1 -1
  3. package/dist/web/assets/{chat-tab-DJvME48K.js → chat-tab-Cfw__7vJ.js} +3 -3
  4. package/dist/web/assets/code-editor-D8Pz69sx.js +2 -0
  5. package/dist/web/assets/{dialog-Cn5zGuid.js → dialog-BL9i7XEo.js} +1 -1
  6. package/dist/web/assets/diff-viewer-CWS5n7ur.js +4 -0
  7. package/dist/web/assets/dist-Ca3N8Xbh.js +46 -0
  8. package/dist/web/assets/{git-graph-CWI6hxtE.js → git-graph-DwA62J8-.js} +1 -1
  9. package/dist/web/assets/git-status-panel-DaB-zzSF.js +1 -0
  10. package/dist/web/assets/index-BYIXPY6U.css +2 -0
  11. package/dist/web/assets/index-DbTCLiox.js +17 -0
  12. package/dist/web/assets/{project-list-MAvAY2K3.js → project-list-Z4lhtp6P.js} +1 -1
  13. package/dist/web/assets/{settings-tab-zeZrAFld.js → settings-tab-BW6MGcir.js} +1 -1
  14. package/dist/web/assets/{terminal-tab-DlRo-KzS.js → terminal-tab-sGlqTp7k.js} +1 -1
  15. package/dist/web/index.html +8 -9
  16. package/dist/web/sw.js +1 -1
  17. package/package.json +1 -1
  18. package/src/web/components/editor/code-editor.tsx +55 -8
  19. package/src/web/components/editor/diff-viewer.tsx +14 -2
  20. package/src/web/components/git/git-status-panel.tsx +4 -11
  21. package/src/web/stores/settings-store.ts +21 -1
  22. package/dist/web/assets/api-client-B_eCZViO.js +0 -1
  23. package/dist/web/assets/code-editor-81Tzd5aV.js +0 -2
  24. package/dist/web/assets/diff-viewer-pieRctzs.js +0 -4
  25. package/dist/web/assets/dist-CBiGQxfr.js +0 -46
  26. package/dist/web/assets/git-status-panel-CAjReViM.js +0 -1
  27. package/dist/web/assets/index-BdUoflYx.css +0 -2
  28. package/dist/web/assets/index-CqpLusQd.js +0 -17
  29. package/dist/web/assets/react-C32bf_ch.js +0 -1
  30. /package/dist/web/assets/{dist-B6sG2GPc.js → dist-0XHv8Vwc.js} +0 -0
  31. /package/dist/web/assets/{trash-2-Dc17nbCE.js → trash-2-CGlFXde_.js} +0 -0
  32. /package/dist/web/assets/{utils-61GRB9Cb.js → utils-D6me7KDg.js} +0 -0
  33. /package/dist/web/assets/{x-Bpqyw40Y.js → x-C0Rw5Giw.js} +0 -0
@@ -0,0 +1 @@
1
+ import{a as e,r as t}from"./jsx-runtime-BFALxl05.js";var n=e=>{let t,n=new Set,r=(e,r)=>{let i=typeof e==`function`?e(t):e;if(!Object.is(i,t)){let e=t;t=r??(typeof i!=`object`||!i)?i:Object.assign({},t,i),n.forEach(n=>n(t,e))}},i=()=>t,a={setState:r,getState:i,getInitialState:()=>o,subscribe:e=>(n.add(e),()=>n.delete(e))},o=t=e(r,i,a);return a},r=(e=>e?n(e):n),i=e(t(),1),a=e=>e;function o(e,t=a){let n=i.useSyncExternalStore(e.subscribe,i.useCallback(()=>t(e.getState()),[e,t]),i.useCallback(()=>t(e.getInitialState()),[e,t]));return i.useDebugValue(n),n}var s=e=>{let t=r(e),n=e=>o(t,e);return Object.assign(n,t),n},c=(e=>e?s(e):s),l=`ppm-auth-token`,u=new class{baseUrl;constructor(e=``){this.baseUrl=e}getToken(){return localStorage.getItem(l)}headers(){let e={"Content-Type":`application/json`},t=this.getToken();return t&&(e.Authorization=`Bearer ${t}`),e}async get(e){let t=await fetch(`${this.baseUrl}${e}`,{headers:this.headers()});return this.handleResponse(t)}async post(e,t){let n=await fetch(`${this.baseUrl}${e}`,{method:`POST`,headers:this.headers(),body:t==null?void 0:JSON.stringify(t)});return this.handleResponse(n)}async put(e,t){let n=await fetch(`${this.baseUrl}${e}`,{method:`PUT`,headers:this.headers(),body:t==null?void 0:JSON.stringify(t)});return this.handleResponse(n)}async patch(e,t){let n=await fetch(`${this.baseUrl}${e}`,{method:`PATCH`,headers:this.headers(),body:t==null?void 0:JSON.stringify(t)});return this.handleResponse(n)}async del(e,t){let n=await fetch(`${this.baseUrl}${e}`,{method:`DELETE`,headers:this.headers(),body:t==null?void 0:JSON.stringify(t)});await this.handleResponse(n)}async handleResponse(e){if(e.status===401)throw localStorage.removeItem(l),window.location.reload(),Error(`Unauthorized`);let t=await e.json();if(t.ok===!1)throw Error(t.error??`HTTP ${e.status}`);return t.data}};function d(e){return`/api/project/${encodeURIComponent(e)}`}function f(e){localStorage.setItem(l,e)}function p(){return localStorage.getItem(l)}export{c as a,f as i,p as n,d as r,u as t};
@@ -1,4 +1,4 @@
1
- import{a as e,i as t,r as n,t as r}from"./jsx-runtime-BFALxl05.js";import{r as i,t as a}from"./utils-61GRB9Cb.js";var o=t((e=>{var t=n();function r(e){var t=`https://react.dev/errors/`+e;if(1<arguments.length){t+=`?args[]=`+encodeURIComponent(arguments[1]);for(var n=2;n<arguments.length;n++)t+=`&args[]=`+encodeURIComponent(arguments[n])}return`Minified React error #`+e+`; visit `+t+` for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`}function i(){}var a={d:{f:i,r:function(){throw Error(r(522))},D:i,C:i,L:i,m:i,X:i,S:i,M:i},p:0,findDOMNode:null},o=Symbol.for(`react.portal`);function s(e,t,n){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:o,key:r==null?null:``+r,children:e,containerInfo:t,implementation:n}}var c=t.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;function l(e,t){if(e===`font`)return``;if(typeof t==`string`)return t===`use-credentials`?t:``}e.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=a,e.createPortal=function(e,t){var n=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!t||t.nodeType!==1&&t.nodeType!==9&&t.nodeType!==11)throw Error(r(299));return s(e,t,null,n)},e.flushSync=function(e){var t=c.T,n=a.p;try{if(c.T=null,a.p=2,e)return e()}finally{c.T=t,a.p=n,a.d.f()}},e.preconnect=function(e,t){typeof e==`string`&&(t?(t=t.crossOrigin,t=typeof t==`string`?t===`use-credentials`?t:``:void 0):t=null,a.d.C(e,t))},e.prefetchDNS=function(e){typeof e==`string`&&a.d.D(e)},e.preinit=function(e,t){if(typeof e==`string`&&t&&typeof t.as==`string`){var n=t.as,r=l(n,t.crossOrigin),i=typeof t.integrity==`string`?t.integrity:void 0,o=typeof t.fetchPriority==`string`?t.fetchPriority:void 0;n===`style`?a.d.S(e,typeof t.precedence==`string`?t.precedence:void 0,{crossOrigin:r,integrity:i,fetchPriority:o}):n===`script`&&a.d.X(e,{crossOrigin:r,integrity:i,fetchPriority:o,nonce:typeof t.nonce==`string`?t.nonce:void 0})}},e.preinitModule=function(e,t){if(typeof e==`string`)if(typeof t==`object`&&t){if(t.as==null||t.as===`script`){var n=l(t.as,t.crossOrigin);a.d.M(e,{crossOrigin:n,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0})}}else t??a.d.M(e)},e.preload=function(e,t){if(typeof e==`string`&&typeof t==`object`&&t&&typeof t.as==`string`){var n=t.as,r=l(n,t.crossOrigin);a.d.L(e,n,{crossOrigin:r,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0,type:typeof t.type==`string`?t.type:void 0,fetchPriority:typeof t.fetchPriority==`string`?t.fetchPriority:void 0,referrerPolicy:typeof t.referrerPolicy==`string`?t.referrerPolicy:void 0,imageSrcSet:typeof t.imageSrcSet==`string`?t.imageSrcSet:void 0,imageSizes:typeof t.imageSizes==`string`?t.imageSizes:void 0,media:typeof t.media==`string`?t.media:void 0})}},e.preloadModule=function(e,t){if(typeof e==`string`)if(t){var n=l(t.as,t.crossOrigin);a.d.m(e,{as:typeof t.as==`string`&&t.as!==`script`?t.as:void 0,crossOrigin:n,integrity:typeof t.integrity==`string`?t.integrity:void 0})}else a.d.m(e)},e.requestFormReset=function(e){a.d.r(e)},e.unstable_batchedUpdates=function(e,t){return e(t)},e.useFormState=function(e,t,n){return c.H.useFormState(e,t,n)},e.useFormStatus=function(){return c.H.useHostTransitionStatus()},e.version=`19.2.4`})),s=t(((e,t)=>{function n(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>`u`||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!=`function`))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(n)}catch(e){console.error(e)}}n(),t.exports=o()})),c=e(n(),1);function l(e,t){if(typeof e==`function`)return e(t);e!=null&&(e.current=t)}function u(...e){return t=>{let n=!1,r=e.map(e=>{let r=l(e,t);return!n&&typeof r==`function`&&(n=!0),r});if(n)return()=>{for(let t=0;t<r.length;t++){let n=r[t];typeof n==`function`?n():l(e[t],null)}}}}function d(...e){return c.useCallback(u(...e),e)}var f=r();function p(e){let t=h(e),n=c.forwardRef((e,n)=>{let{children:r,...i}=e,a=c.Children.toArray(r),o=a.find(v);if(o){let e=o.props.children,r=a.map(t=>t===o?c.Children.count(e)>1?c.Children.only(null):c.isValidElement(e)?e.props.children:null:t);return(0,f.jsx)(t,{...i,ref:n,children:c.isValidElement(e)?c.cloneElement(e,void 0,r):null})}return(0,f.jsx)(t,{...i,ref:n,children:r})});return n.displayName=`${e}.Slot`,n}var m=p(`Slot`);function h(e){let t=c.forwardRef((e,t)=>{let{children:n,...r}=e;if(c.isValidElement(n)){let e=b(n),i=y(r,n.props);return n.type!==c.Fragment&&(i.ref=t?u(t,e):e),c.cloneElement(n,i)}return c.Children.count(n)>1?c.Children.only(null):null});return t.displayName=`${e}.SlotClone`,t}var g=Symbol(`radix.slottable`);function _(e){let t=({children:e})=>(0,f.jsx)(f.Fragment,{children:e});return t.displayName=`${e}.Slottable`,t.__radixId=g,t}function v(e){return c.isValidElement(e)&&typeof e.type==`function`&&`__radixId`in e.type&&e.type.__radixId===g}function y(e,t){let n={...t};for(let r in t){let i=e[r],a=t[r];/^on[A-Z]/.test(r)?i&&a?n[r]=(...e)=>{let t=a(...e);return i(...e),t}:i&&(n[r]=i):r===`style`?n[r]={...i,...a}:r===`className`&&(n[r]=[i,a].filter(Boolean).join(` `))}return{...e,...n}}function b(e){let t=Object.getOwnPropertyDescriptor(e.props,`ref`)?.get,n=t&&`isReactWarning`in t&&t.isReactWarning;return n?e.ref:(t=Object.getOwnPropertyDescriptor(e,`ref`)?.get,n=t&&`isReactWarning`in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}var x=e(s(),1),S=[`a`,`button`,`div`,`form`,`h2`,`h3`,`img`,`input`,`label`,`li`,`nav`,`ol`,`p`,`select`,`span`,`svg`,`ul`].reduce((e,t)=>{let n=p(`Primitive.${t}`),r=c.forwardRef((e,r)=>{let{asChild:i,...a}=e,o=i?n:t;return typeof window<`u`&&(window[Symbol.for(`radix-ui`)]=!0),(0,f.jsx)(o,{...a,ref:r})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function C(e,t){e&&x.flushSync(()=>e.dispatchEvent(t))}function w(e,t){let n=c.createContext(t),r=e=>{let{children:t,...r}=e,i=c.useMemo(()=>r,Object.values(r));return(0,f.jsx)(n.Provider,{value:i,children:t})};r.displayName=e+`Provider`;function i(r){let i=c.useContext(n);if(i)return i;if(t!==void 0)return t;throw Error(`\`${r}\` must be used within \`${e}\``)}return[r,i]}function ee(e,t=[]){let n=[];function r(t,r){let i=c.createContext(r),a=n.length;n=[...n,r];let o=t=>{let{scope:n,children:r,...o}=t,s=n?.[e]?.[a]||i,l=c.useMemo(()=>o,Object.values(o));return(0,f.jsx)(s.Provider,{value:l,children:r})};o.displayName=t+`Provider`;function s(n,o){let s=o?.[e]?.[a]||i,l=c.useContext(s);if(l)return l;if(r!==void 0)return r;throw Error(`\`${n}\` must be used within \`${t}\``)}return[o,s]}let i=()=>{let t=n.map(e=>c.createContext(e));return function(n){let r=n?.[e]||t;return c.useMemo(()=>({[`__scope${e}`]:{...n,[e]:r}}),[n,r])}};return i.scopeName=e,[r,T(i,...t)]}function T(...e){let t=e[0];if(e.length===1)return t;let n=()=>{let n=e.map(e=>({useScope:e(),scopeName:e.scopeName}));return function(e){let r=n.reduce((t,{useScope:n,scopeName:r})=>{let i=n(e)[`__scope${r}`];return{...t,...i}},{});return c.useMemo(()=>({[`__scope${t.scopeName}`]:r}),[r])}};return n.scopeName=t.scopeName,n}typeof window<`u`&&window.document&&window.document.createElement;function E(e,t,{checkForDefaultPrevented:n=!0}={}){return function(r){if(e?.(r),n===!1||!r.defaultPrevented)return t?.(r)}}var D=globalThis?.document?c.useLayoutEffect:()=>{},te=c.useInsertionEffect||D;function ne({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){let[i,a,o]=re({defaultProp:t,onChange:n}),s=e!==void 0,l=s?e:i;{let t=c.useRef(e!==void 0);c.useEffect(()=>{let e=t.current;if(e!==s){let t=e?`controlled`:`uncontrolled`,n=s?`controlled`:`uncontrolled`;console.warn(`${r} is changing from ${t} to ${n}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`)}t.current=s},[s,r])}return[l,c.useCallback(t=>{if(s){let n=ie(t)?t(e):t;n!==e&&o.current?.(n)}else a(t)},[s,e,a,o])]}function re({defaultProp:e,onChange:t}){let[n,r]=c.useState(e),i=c.useRef(n),a=c.useRef(t);return te(()=>{a.current=t},[t]),c.useEffect(()=>{i.current!==n&&(a.current?.(n),i.current=n)},[n,i]),[n,r,a]}function ie(e){return typeof e==`function`}var ae=c.useId||(()=>void 0),oe=0;function se(e){let[t,n]=c.useState(ae());return D(()=>{e||n(e=>e??String(oe++))},[e]),e||(t?`radix-${t}`:``)}function O(e){let t=c.useRef(e);return c.useEffect(()=>{t.current=e}),c.useMemo(()=>(...e)=>t.current?.(...e),[])}function ce(e,t=globalThis?.document){let n=O(e);c.useEffect(()=>{let e=e=>{e.key===`Escape`&&n(e)};return t.addEventListener(`keydown`,e,{capture:!0}),()=>t.removeEventListener(`keydown`,e,{capture:!0})},[n,t])}var le=`DismissableLayer`,k=`dismissableLayer.update`,ue=`dismissableLayer.pointerDownOutside`,de=`dismissableLayer.focusOutside`,fe,pe=c.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),me=c.forwardRef((e,t)=>{let{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:i,onFocusOutside:a,onInteractOutside:o,onDismiss:s,...l}=e,u=c.useContext(pe),[p,m]=c.useState(null),h=p?.ownerDocument??globalThis?.document,[,g]=c.useState({}),_=d(t,e=>m(e)),v=Array.from(u.layers),[y]=[...u.layersWithOutsidePointerEventsDisabled].slice(-1),b=v.indexOf(y),x=p?v.indexOf(p):-1,C=u.layersWithOutsidePointerEventsDisabled.size>0,w=x>=b,ee=_e(e=>{let t=e.target,n=[...u.branches].some(e=>e.contains(t));!w||n||(i?.(e),o?.(e),e.defaultPrevented||s?.())},h),T=ve(e=>{let t=e.target;[...u.branches].some(e=>e.contains(t))||(a?.(e),o?.(e),e.defaultPrevented||s?.())},h);return ce(e=>{x===u.layers.size-1&&(r?.(e),!e.defaultPrevented&&s&&(e.preventDefault(),s()))},h),c.useEffect(()=>{if(p)return n&&(u.layersWithOutsidePointerEventsDisabled.size===0&&(fe=h.body.style.pointerEvents,h.body.style.pointerEvents=`none`),u.layersWithOutsidePointerEventsDisabled.add(p)),u.layers.add(p),ye(),()=>{n&&u.layersWithOutsidePointerEventsDisabled.size===1&&(h.body.style.pointerEvents=fe)}},[p,h,n,u]),c.useEffect(()=>()=>{p&&(u.layers.delete(p),u.layersWithOutsidePointerEventsDisabled.delete(p),ye())},[p,u]),c.useEffect(()=>{let e=()=>g({});return document.addEventListener(k,e),()=>document.removeEventListener(k,e)},[]),(0,f.jsx)(S.div,{...l,ref:_,style:{pointerEvents:C?w?`auto`:`none`:void 0,...e.style},onFocusCapture:E(e.onFocusCapture,T.onFocusCapture),onBlurCapture:E(e.onBlurCapture,T.onBlurCapture),onPointerDownCapture:E(e.onPointerDownCapture,ee.onPointerDownCapture)})});me.displayName=le;var he=`DismissableLayerBranch`,ge=c.forwardRef((e,t)=>{let n=c.useContext(pe),r=c.useRef(null),i=d(t,r);return c.useEffect(()=>{let e=r.current;if(e)return n.branches.add(e),()=>{n.branches.delete(e)}},[n.branches]),(0,f.jsx)(S.div,{...e,ref:i})});ge.displayName=he;function _e(e,t=globalThis?.document){let n=O(e),r=c.useRef(!1),i=c.useRef(()=>{});return c.useEffect(()=>{let e=e=>{if(e.target&&!r.current){let r=function(){be(ue,n,a,{discrete:!0})},a={originalEvent:e};e.pointerType===`touch`?(t.removeEventListener(`click`,i.current),i.current=r,t.addEventListener(`click`,i.current,{once:!0})):r()}else t.removeEventListener(`click`,i.current);r.current=!1},a=window.setTimeout(()=>{t.addEventListener(`pointerdown`,e)},0);return()=>{window.clearTimeout(a),t.removeEventListener(`pointerdown`,e),t.removeEventListener(`click`,i.current)}},[t,n]),{onPointerDownCapture:()=>r.current=!0}}function ve(e,t=globalThis?.document){let n=O(e),r=c.useRef(!1);return c.useEffect(()=>{let e=e=>{e.target&&!r.current&&be(de,n,{originalEvent:e},{discrete:!1})};return t.addEventListener(`focusin`,e),()=>t.removeEventListener(`focusin`,e)},[t,n]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function ye(){let e=new CustomEvent(k);document.dispatchEvent(e)}function be(e,t,n,{discrete:r}){let i=n.originalEvent.target,a=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:n});t&&i.addEventListener(e,t,{once:!0}),r?C(i,a):i.dispatchEvent(a)}var A=`focusScope.autoFocusOnMount`,j=`focusScope.autoFocusOnUnmount`,M={bubbles:!1,cancelable:!0},xe=`FocusScope`,N=c.forwardRef((e,t)=>{let{loop:n=!1,trapped:r=!1,onMountAutoFocus:i,onUnmountAutoFocus:a,...o}=e,[s,l]=c.useState(null),u=O(i),p=O(a),m=c.useRef(null),h=d(t,e=>l(e)),g=c.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;c.useEffect(()=>{if(r){let e=function(e){if(g.paused||!s)return;let t=e.target;s.contains(t)?m.current=t:P(m.current,{select:!0})},t=function(e){if(g.paused||!s)return;let t=e.relatedTarget;t!==null&&(s.contains(t)||P(m.current,{select:!0}))},n=function(e){if(document.activeElement===document.body)for(let t of e)t.removedNodes.length>0&&P(s)};document.addEventListener(`focusin`,e),document.addEventListener(`focusout`,t);let r=new MutationObserver(n);return s&&r.observe(s,{childList:!0,subtree:!0}),()=>{document.removeEventListener(`focusin`,e),document.removeEventListener(`focusout`,t),r.disconnect()}}},[r,s,g.paused]),c.useEffect(()=>{if(s){Oe.add(g);let e=document.activeElement;if(!s.contains(e)){let t=new CustomEvent(A,M);s.addEventListener(A,u),s.dispatchEvent(t),t.defaultPrevented||(Se(je(we(s)),{select:!0}),document.activeElement===e&&P(s))}return()=>{s.removeEventListener(A,u),setTimeout(()=>{let t=new CustomEvent(j,M);s.addEventListener(j,p),s.dispatchEvent(t),t.defaultPrevented||P(e??document.body,{select:!0}),s.removeEventListener(j,p),Oe.remove(g)},0)}}},[s,u,p,g]);let _=c.useCallback(e=>{if(!n&&!r||g.paused)return;let t=e.key===`Tab`&&!e.altKey&&!e.ctrlKey&&!e.metaKey,i=document.activeElement;if(t&&i){let t=e.currentTarget,[r,a]=Ce(t);r&&a?!e.shiftKey&&i===a?(e.preventDefault(),n&&P(r,{select:!0})):e.shiftKey&&i===r&&(e.preventDefault(),n&&P(a,{select:!0})):i===t&&e.preventDefault()}},[n,r,g.paused]);return(0,f.jsx)(S.div,{tabIndex:-1,...o,ref:h,onKeyDown:_})});N.displayName=xe;function Se(e,{select:t=!1}={}){let n=document.activeElement;for(let r of e)if(P(r,{select:t}),document.activeElement!==n)return}function Ce(e){let t=we(e);return[Te(t,e),Te(t.reverse(),e)]}function we(e){let t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:e=>{let t=e.tagName===`INPUT`&&e.type===`hidden`;return e.disabled||e.hidden||t?NodeFilter.FILTER_SKIP:e.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)t.push(n.currentNode);return t}function Te(e,t){for(let n of e)if(!Ee(n,{upTo:t}))return n}function Ee(e,{upTo:t}){if(getComputedStyle(e).visibility===`hidden`)return!0;for(;e;){if(t!==void 0&&e===t)return!1;if(getComputedStyle(e).display===`none`)return!0;e=e.parentElement}return!1}function De(e){return e instanceof HTMLInputElement&&`select`in e}function P(e,{select:t=!1}={}){if(e&&e.focus){let n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&De(e)&&t&&e.select()}}var Oe=ke();function ke(){let e=[];return{add(t){let n=e[0];t!==n&&n?.pause(),e=Ae(e,t),e.unshift(t)},remove(t){e=Ae(e,t),e[0]?.resume()}}}function Ae(e,t){let n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function je(e){return e.filter(e=>e.tagName!==`A`)}var Me=`Portal`,Ne=c.forwardRef((e,t)=>{let{container:n,...r}=e,[i,a]=c.useState(!1);D(()=>a(!0),[]);let o=n||i&&globalThis?.document?.body;return o?x.createPortal((0,f.jsx)(S.div,{...r,ref:t}),o):null});Ne.displayName=Me;var F=0;function Pe(){c.useEffect(()=>{let e=document.querySelectorAll(`[data-radix-focus-guard]`);return document.body.insertAdjacentElement(`afterbegin`,e[0]??Fe()),document.body.insertAdjacentElement(`beforeend`,e[1]??Fe()),F++,()=>{F===1&&document.querySelectorAll(`[data-radix-focus-guard]`).forEach(e=>e.remove()),F--}},[])}function Fe(){let e=document.createElement(`span`);return e.setAttribute(`data-radix-focus-guard`,``),e.tabIndex=0,e.style.outline=`none`,e.style.opacity=`0`,e.style.position=`fixed`,e.style.pointerEvents=`none`,e}var I=function(){return I=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n],t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},I.apply(this,arguments)};function Ie(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols==`function`)for(var i=0,r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]]);return n}function Le(e,t,n){if(n||arguments.length===2)for(var r=0,i=t.length,a;r<i;r++)(a||!(r in t))&&(a||=Array.prototype.slice.call(t,0,r),a[r]=t[r]);return e.concat(a||Array.prototype.slice.call(t))}var L=`right-scroll-bar-position`,R=`width-before-scroll-bar`,Re=`with-scroll-bars-hidden`,ze=`--removed-body-scroll-bar-size`;function z(e,t){return typeof e==`function`?e(t):e&&(e.current=t),e}function Be(e,t){var n=(0,c.useState)(function(){return{value:e,callback:t,facade:{get current(){return n.value},set current(e){var t=n.value;t!==e&&(n.value=e,n.callback(e,t))}}}})[0];return n.callback=t,n.facade}var Ve=typeof window<`u`?c.useLayoutEffect:c.useEffect,He=new WeakMap;function Ue(e,t){var n=Be(t||null,function(t){return e.forEach(function(e){return z(e,t)})});return Ve(function(){var t=He.get(n);if(t){var r=new Set(t),i=new Set(e),a=n.current;r.forEach(function(e){i.has(e)||z(e,null)}),i.forEach(function(e){r.has(e)||z(e,a)})}He.set(n,e)},[e]),n}function We(e){return e}function Ge(e,t){t===void 0&&(t=We);var n=[],r=!1;return{read:function(){if(r)throw Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return n.length?n[n.length-1]:e},useMedium:function(e){var i=t(e,r);return n.push(i),function(){n=n.filter(function(e){return e!==i})}},assignSyncMedium:function(e){for(r=!0;n.length;){var t=n;n=[],t.forEach(e)}n={push:function(t){return e(t)},filter:function(){return n}}},assignMedium:function(e){r=!0;var t=[];if(n.length){var i=n;n=[],i.forEach(e),t=n}var a=function(){var n=t;t=[],n.forEach(e)},o=function(){return Promise.resolve().then(a)};o(),n={push:function(e){t.push(e),o()},filter:function(e){return t=t.filter(e),n}}}}}function Ke(e){e===void 0&&(e={});var t=Ge(null);return t.options=I({async:!0,ssr:!1},e),t}var qe=function(e){var t=e.sideCar,n=Ie(e,[`sideCar`]);if(!t)throw Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw Error(`Sidecar medium not found`);return c.createElement(r,I({},n))};qe.isSideCarExport=!0;function Je(e,t){return e.useMedium(t),qe}var Ye=Ke(),B=function(){},V=c.forwardRef(function(e,t){var n=c.useRef(null),r=c.useState({onScrollCapture:B,onWheelCapture:B,onTouchMoveCapture:B}),i=r[0],a=r[1],o=e.forwardProps,s=e.children,l=e.className,u=e.removeScrollBar,d=e.enabled,f=e.shards,p=e.sideCar,m=e.noRelative,h=e.noIsolation,g=e.inert,_=e.allowPinchZoom,v=e.as,y=v===void 0?`div`:v,b=e.gapMode,x=Ie(e,[`forwardProps`,`children`,`className`,`removeScrollBar`,`enabled`,`shards`,`sideCar`,`noRelative`,`noIsolation`,`inert`,`allowPinchZoom`,`as`,`gapMode`]),S=p,C=Ue([n,t]),w=I(I({},x),i);return c.createElement(c.Fragment,null,d&&c.createElement(S,{sideCar:Ye,removeScrollBar:u,shards:f,noRelative:m,noIsolation:h,inert:g,setCallbacks:a,allowPinchZoom:!!_,lockRef:n,gapMode:b}),o?c.cloneElement(c.Children.only(s),I(I({},w),{ref:C})):c.createElement(y,I({},w,{className:l,ref:C}),s))});V.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},V.classNames={fullWidth:R,zeroRight:L};var Xe,Ze=function(){if(Xe)return Xe;if(typeof __webpack_nonce__<`u`)return __webpack_nonce__};function Qe(){if(!document)return null;var e=document.createElement(`style`);e.type=`text/css`;var t=Ze();return t&&e.setAttribute(`nonce`,t),e}function $e(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function et(e){(document.head||document.getElementsByTagName(`head`)[0]).appendChild(e)}var tt=function(){var e=0,t=null;return{add:function(n){e==0&&(t=Qe())&&($e(t,n),et(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},nt=function(){var e=tt();return function(t,n){c.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},rt=function(){var e=nt();return function(t){var n=t.styles,r=t.dynamic;return e(n,r),null}},it={left:0,top:0,right:0,gap:0},H=function(e){return parseInt(e||``,10)||0},at=function(e){var t=window.getComputedStyle(document.body),n=t[e===`padding`?`paddingLeft`:`marginLeft`],r=t[e===`padding`?`paddingTop`:`marginTop`],i=t[e===`padding`?`paddingRight`:`marginRight`];return[H(n),H(r),H(i)]},ot=function(e){if(e===void 0&&(e=`margin`),typeof window>`u`)return it;var t=at(e),n=document.documentElement.clientWidth,r=window.innerWidth;return{left:t[0],top:t[1],right:t[2],gap:Math.max(0,r-n+t[2]-t[0])}},st=rt(),U=`data-scroll-locked`,ct=function(e,t,n,r){var i=e.left,a=e.top,o=e.right,s=e.gap;return n===void 0&&(n=`margin`),`
1
+ import{a as e,i as t,r as n,t as r}from"./jsx-runtime-BFALxl05.js";import{r as i,t as a}from"./utils-D6me7KDg.js";var o=t((e=>{var t=n();function r(e){var t=`https://react.dev/errors/`+e;if(1<arguments.length){t+=`?args[]=`+encodeURIComponent(arguments[1]);for(var n=2;n<arguments.length;n++)t+=`&args[]=`+encodeURIComponent(arguments[n])}return`Minified React error #`+e+`; visit `+t+` for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`}function i(){}var a={d:{f:i,r:function(){throw Error(r(522))},D:i,C:i,L:i,m:i,X:i,S:i,M:i},p:0,findDOMNode:null},o=Symbol.for(`react.portal`);function s(e,t,n){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:o,key:r==null?null:``+r,children:e,containerInfo:t,implementation:n}}var c=t.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;function l(e,t){if(e===`font`)return``;if(typeof t==`string`)return t===`use-credentials`?t:``}e.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE=a,e.createPortal=function(e,t){var n=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!t||t.nodeType!==1&&t.nodeType!==9&&t.nodeType!==11)throw Error(r(299));return s(e,t,null,n)},e.flushSync=function(e){var t=c.T,n=a.p;try{if(c.T=null,a.p=2,e)return e()}finally{c.T=t,a.p=n,a.d.f()}},e.preconnect=function(e,t){typeof e==`string`&&(t?(t=t.crossOrigin,t=typeof t==`string`?t===`use-credentials`?t:``:void 0):t=null,a.d.C(e,t))},e.prefetchDNS=function(e){typeof e==`string`&&a.d.D(e)},e.preinit=function(e,t){if(typeof e==`string`&&t&&typeof t.as==`string`){var n=t.as,r=l(n,t.crossOrigin),i=typeof t.integrity==`string`?t.integrity:void 0,o=typeof t.fetchPriority==`string`?t.fetchPriority:void 0;n===`style`?a.d.S(e,typeof t.precedence==`string`?t.precedence:void 0,{crossOrigin:r,integrity:i,fetchPriority:o}):n===`script`&&a.d.X(e,{crossOrigin:r,integrity:i,fetchPriority:o,nonce:typeof t.nonce==`string`?t.nonce:void 0})}},e.preinitModule=function(e,t){if(typeof e==`string`)if(typeof t==`object`&&t){if(t.as==null||t.as===`script`){var n=l(t.as,t.crossOrigin);a.d.M(e,{crossOrigin:n,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0})}}else t??a.d.M(e)},e.preload=function(e,t){if(typeof e==`string`&&typeof t==`object`&&t&&typeof t.as==`string`){var n=t.as,r=l(n,t.crossOrigin);a.d.L(e,n,{crossOrigin:r,integrity:typeof t.integrity==`string`?t.integrity:void 0,nonce:typeof t.nonce==`string`?t.nonce:void 0,type:typeof t.type==`string`?t.type:void 0,fetchPriority:typeof t.fetchPriority==`string`?t.fetchPriority:void 0,referrerPolicy:typeof t.referrerPolicy==`string`?t.referrerPolicy:void 0,imageSrcSet:typeof t.imageSrcSet==`string`?t.imageSrcSet:void 0,imageSizes:typeof t.imageSizes==`string`?t.imageSizes:void 0,media:typeof t.media==`string`?t.media:void 0})}},e.preloadModule=function(e,t){if(typeof e==`string`)if(t){var n=l(t.as,t.crossOrigin);a.d.m(e,{as:typeof t.as==`string`&&t.as!==`script`?t.as:void 0,crossOrigin:n,integrity:typeof t.integrity==`string`?t.integrity:void 0})}else a.d.m(e)},e.requestFormReset=function(e){a.d.r(e)},e.unstable_batchedUpdates=function(e,t){return e(t)},e.useFormState=function(e,t,n){return c.H.useFormState(e,t,n)},e.useFormStatus=function(){return c.H.useHostTransitionStatus()},e.version=`19.2.4`})),s=t(((e,t)=>{function n(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>`u`||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!=`function`))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(n)}catch(e){console.error(e)}}n(),t.exports=o()})),c=e(n(),1);function l(e,t){if(typeof e==`function`)return e(t);e!=null&&(e.current=t)}function u(...e){return t=>{let n=!1,r=e.map(e=>{let r=l(e,t);return!n&&typeof r==`function`&&(n=!0),r});if(n)return()=>{for(let t=0;t<r.length;t++){let n=r[t];typeof n==`function`?n():l(e[t],null)}}}}function d(...e){return c.useCallback(u(...e),e)}var f=r();function p(e){let t=h(e),n=c.forwardRef((e,n)=>{let{children:r,...i}=e,a=c.Children.toArray(r),o=a.find(v);if(o){let e=o.props.children,r=a.map(t=>t===o?c.Children.count(e)>1?c.Children.only(null):c.isValidElement(e)?e.props.children:null:t);return(0,f.jsx)(t,{...i,ref:n,children:c.isValidElement(e)?c.cloneElement(e,void 0,r):null})}return(0,f.jsx)(t,{...i,ref:n,children:r})});return n.displayName=`${e}.Slot`,n}var m=p(`Slot`);function h(e){let t=c.forwardRef((e,t)=>{let{children:n,...r}=e;if(c.isValidElement(n)){let e=b(n),i=y(r,n.props);return n.type!==c.Fragment&&(i.ref=t?u(t,e):e),c.cloneElement(n,i)}return c.Children.count(n)>1?c.Children.only(null):null});return t.displayName=`${e}.SlotClone`,t}var g=Symbol(`radix.slottable`);function _(e){let t=({children:e})=>(0,f.jsx)(f.Fragment,{children:e});return t.displayName=`${e}.Slottable`,t.__radixId=g,t}function v(e){return c.isValidElement(e)&&typeof e.type==`function`&&`__radixId`in e.type&&e.type.__radixId===g}function y(e,t){let n={...t};for(let r in t){let i=e[r],a=t[r];/^on[A-Z]/.test(r)?i&&a?n[r]=(...e)=>{let t=a(...e);return i(...e),t}:i&&(n[r]=i):r===`style`?n[r]={...i,...a}:r===`className`&&(n[r]=[i,a].filter(Boolean).join(` `))}return{...e,...n}}function b(e){let t=Object.getOwnPropertyDescriptor(e.props,`ref`)?.get,n=t&&`isReactWarning`in t&&t.isReactWarning;return n?e.ref:(t=Object.getOwnPropertyDescriptor(e,`ref`)?.get,n=t&&`isReactWarning`in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}var x=e(s(),1),S=[`a`,`button`,`div`,`form`,`h2`,`h3`,`img`,`input`,`label`,`li`,`nav`,`ol`,`p`,`select`,`span`,`svg`,`ul`].reduce((e,t)=>{let n=p(`Primitive.${t}`),r=c.forwardRef((e,r)=>{let{asChild:i,...a}=e,o=i?n:t;return typeof window<`u`&&(window[Symbol.for(`radix-ui`)]=!0),(0,f.jsx)(o,{...a,ref:r})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function C(e,t){e&&x.flushSync(()=>e.dispatchEvent(t))}function w(e,t){let n=c.createContext(t),r=e=>{let{children:t,...r}=e,i=c.useMemo(()=>r,Object.values(r));return(0,f.jsx)(n.Provider,{value:i,children:t})};r.displayName=e+`Provider`;function i(r){let i=c.useContext(n);if(i)return i;if(t!==void 0)return t;throw Error(`\`${r}\` must be used within \`${e}\``)}return[r,i]}function ee(e,t=[]){let n=[];function r(t,r){let i=c.createContext(r),a=n.length;n=[...n,r];let o=t=>{let{scope:n,children:r,...o}=t,s=n?.[e]?.[a]||i,l=c.useMemo(()=>o,Object.values(o));return(0,f.jsx)(s.Provider,{value:l,children:r})};o.displayName=t+`Provider`;function s(n,o){let s=o?.[e]?.[a]||i,l=c.useContext(s);if(l)return l;if(r!==void 0)return r;throw Error(`\`${n}\` must be used within \`${t}\``)}return[o,s]}let i=()=>{let t=n.map(e=>c.createContext(e));return function(n){let r=n?.[e]||t;return c.useMemo(()=>({[`__scope${e}`]:{...n,[e]:r}}),[n,r])}};return i.scopeName=e,[r,T(i,...t)]}function T(...e){let t=e[0];if(e.length===1)return t;let n=()=>{let n=e.map(e=>({useScope:e(),scopeName:e.scopeName}));return function(e){let r=n.reduce((t,{useScope:n,scopeName:r})=>{let i=n(e)[`__scope${r}`];return{...t,...i}},{});return c.useMemo(()=>({[`__scope${t.scopeName}`]:r}),[r])}};return n.scopeName=t.scopeName,n}typeof window<`u`&&window.document&&window.document.createElement;function E(e,t,{checkForDefaultPrevented:n=!0}={}){return function(r){if(e?.(r),n===!1||!r.defaultPrevented)return t?.(r)}}var D=globalThis?.document?c.useLayoutEffect:()=>{},te=c.useInsertionEffect||D;function ne({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){let[i,a,o]=re({defaultProp:t,onChange:n}),s=e!==void 0,l=s?e:i;{let t=c.useRef(e!==void 0);c.useEffect(()=>{let e=t.current;if(e!==s){let t=e?`controlled`:`uncontrolled`,n=s?`controlled`:`uncontrolled`;console.warn(`${r} is changing from ${t} to ${n}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`)}t.current=s},[s,r])}return[l,c.useCallback(t=>{if(s){let n=ie(t)?t(e):t;n!==e&&o.current?.(n)}else a(t)},[s,e,a,o])]}function re({defaultProp:e,onChange:t}){let[n,r]=c.useState(e),i=c.useRef(n),a=c.useRef(t);return te(()=>{a.current=t},[t]),c.useEffect(()=>{i.current!==n&&(a.current?.(n),i.current=n)},[n,i]),[n,r,a]}function ie(e){return typeof e==`function`}var ae=c.useId||(()=>void 0),oe=0;function se(e){let[t,n]=c.useState(ae());return D(()=>{e||n(e=>e??String(oe++))},[e]),e||(t?`radix-${t}`:``)}function O(e){let t=c.useRef(e);return c.useEffect(()=>{t.current=e}),c.useMemo(()=>(...e)=>t.current?.(...e),[])}function ce(e,t=globalThis?.document){let n=O(e);c.useEffect(()=>{let e=e=>{e.key===`Escape`&&n(e)};return t.addEventListener(`keydown`,e,{capture:!0}),()=>t.removeEventListener(`keydown`,e,{capture:!0})},[n,t])}var le=`DismissableLayer`,k=`dismissableLayer.update`,ue=`dismissableLayer.pointerDownOutside`,de=`dismissableLayer.focusOutside`,fe,pe=c.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),me=c.forwardRef((e,t)=>{let{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:i,onFocusOutside:a,onInteractOutside:o,onDismiss:s,...l}=e,u=c.useContext(pe),[p,m]=c.useState(null),h=p?.ownerDocument??globalThis?.document,[,g]=c.useState({}),_=d(t,e=>m(e)),v=Array.from(u.layers),[y]=[...u.layersWithOutsidePointerEventsDisabled].slice(-1),b=v.indexOf(y),x=p?v.indexOf(p):-1,C=u.layersWithOutsidePointerEventsDisabled.size>0,w=x>=b,ee=_e(e=>{let t=e.target,n=[...u.branches].some(e=>e.contains(t));!w||n||(i?.(e),o?.(e),e.defaultPrevented||s?.())},h),T=ve(e=>{let t=e.target;[...u.branches].some(e=>e.contains(t))||(a?.(e),o?.(e),e.defaultPrevented||s?.())},h);return ce(e=>{x===u.layers.size-1&&(r?.(e),!e.defaultPrevented&&s&&(e.preventDefault(),s()))},h),c.useEffect(()=>{if(p)return n&&(u.layersWithOutsidePointerEventsDisabled.size===0&&(fe=h.body.style.pointerEvents,h.body.style.pointerEvents=`none`),u.layersWithOutsidePointerEventsDisabled.add(p)),u.layers.add(p),ye(),()=>{n&&u.layersWithOutsidePointerEventsDisabled.size===1&&(h.body.style.pointerEvents=fe)}},[p,h,n,u]),c.useEffect(()=>()=>{p&&(u.layers.delete(p),u.layersWithOutsidePointerEventsDisabled.delete(p),ye())},[p,u]),c.useEffect(()=>{let e=()=>g({});return document.addEventListener(k,e),()=>document.removeEventListener(k,e)},[]),(0,f.jsx)(S.div,{...l,ref:_,style:{pointerEvents:C?w?`auto`:`none`:void 0,...e.style},onFocusCapture:E(e.onFocusCapture,T.onFocusCapture),onBlurCapture:E(e.onBlurCapture,T.onBlurCapture),onPointerDownCapture:E(e.onPointerDownCapture,ee.onPointerDownCapture)})});me.displayName=le;var he=`DismissableLayerBranch`,ge=c.forwardRef((e,t)=>{let n=c.useContext(pe),r=c.useRef(null),i=d(t,r);return c.useEffect(()=>{let e=r.current;if(e)return n.branches.add(e),()=>{n.branches.delete(e)}},[n.branches]),(0,f.jsx)(S.div,{...e,ref:i})});ge.displayName=he;function _e(e,t=globalThis?.document){let n=O(e),r=c.useRef(!1),i=c.useRef(()=>{});return c.useEffect(()=>{let e=e=>{if(e.target&&!r.current){let r=function(){be(ue,n,a,{discrete:!0})},a={originalEvent:e};e.pointerType===`touch`?(t.removeEventListener(`click`,i.current),i.current=r,t.addEventListener(`click`,i.current,{once:!0})):r()}else t.removeEventListener(`click`,i.current);r.current=!1},a=window.setTimeout(()=>{t.addEventListener(`pointerdown`,e)},0);return()=>{window.clearTimeout(a),t.removeEventListener(`pointerdown`,e),t.removeEventListener(`click`,i.current)}},[t,n]),{onPointerDownCapture:()=>r.current=!0}}function ve(e,t=globalThis?.document){let n=O(e),r=c.useRef(!1);return c.useEffect(()=>{let e=e=>{e.target&&!r.current&&be(de,n,{originalEvent:e},{discrete:!1})};return t.addEventListener(`focusin`,e),()=>t.removeEventListener(`focusin`,e)},[t,n]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function ye(){let e=new CustomEvent(k);document.dispatchEvent(e)}function be(e,t,n,{discrete:r}){let i=n.originalEvent.target,a=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:n});t&&i.addEventListener(e,t,{once:!0}),r?C(i,a):i.dispatchEvent(a)}var A=`focusScope.autoFocusOnMount`,j=`focusScope.autoFocusOnUnmount`,M={bubbles:!1,cancelable:!0},xe=`FocusScope`,N=c.forwardRef((e,t)=>{let{loop:n=!1,trapped:r=!1,onMountAutoFocus:i,onUnmountAutoFocus:a,...o}=e,[s,l]=c.useState(null),u=O(i),p=O(a),m=c.useRef(null),h=d(t,e=>l(e)),g=c.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;c.useEffect(()=>{if(r){let e=function(e){if(g.paused||!s)return;let t=e.target;s.contains(t)?m.current=t:P(m.current,{select:!0})},t=function(e){if(g.paused||!s)return;let t=e.relatedTarget;t!==null&&(s.contains(t)||P(m.current,{select:!0}))},n=function(e){if(document.activeElement===document.body)for(let t of e)t.removedNodes.length>0&&P(s)};document.addEventListener(`focusin`,e),document.addEventListener(`focusout`,t);let r=new MutationObserver(n);return s&&r.observe(s,{childList:!0,subtree:!0}),()=>{document.removeEventListener(`focusin`,e),document.removeEventListener(`focusout`,t),r.disconnect()}}},[r,s,g.paused]),c.useEffect(()=>{if(s){Oe.add(g);let e=document.activeElement;if(!s.contains(e)){let t=new CustomEvent(A,M);s.addEventListener(A,u),s.dispatchEvent(t),t.defaultPrevented||(Se(je(we(s)),{select:!0}),document.activeElement===e&&P(s))}return()=>{s.removeEventListener(A,u),setTimeout(()=>{let t=new CustomEvent(j,M);s.addEventListener(j,p),s.dispatchEvent(t),t.defaultPrevented||P(e??document.body,{select:!0}),s.removeEventListener(j,p),Oe.remove(g)},0)}}},[s,u,p,g]);let _=c.useCallback(e=>{if(!n&&!r||g.paused)return;let t=e.key===`Tab`&&!e.altKey&&!e.ctrlKey&&!e.metaKey,i=document.activeElement;if(t&&i){let t=e.currentTarget,[r,a]=Ce(t);r&&a?!e.shiftKey&&i===a?(e.preventDefault(),n&&P(r,{select:!0})):e.shiftKey&&i===r&&(e.preventDefault(),n&&P(a,{select:!0})):i===t&&e.preventDefault()}},[n,r,g.paused]);return(0,f.jsx)(S.div,{tabIndex:-1,...o,ref:h,onKeyDown:_})});N.displayName=xe;function Se(e,{select:t=!1}={}){let n=document.activeElement;for(let r of e)if(P(r,{select:t}),document.activeElement!==n)return}function Ce(e){let t=we(e);return[Te(t,e),Te(t.reverse(),e)]}function we(e){let t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:e=>{let t=e.tagName===`INPUT`&&e.type===`hidden`;return e.disabled||e.hidden||t?NodeFilter.FILTER_SKIP:e.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)t.push(n.currentNode);return t}function Te(e,t){for(let n of e)if(!Ee(n,{upTo:t}))return n}function Ee(e,{upTo:t}){if(getComputedStyle(e).visibility===`hidden`)return!0;for(;e;){if(t!==void 0&&e===t)return!1;if(getComputedStyle(e).display===`none`)return!0;e=e.parentElement}return!1}function De(e){return e instanceof HTMLInputElement&&`select`in e}function P(e,{select:t=!1}={}){if(e&&e.focus){let n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&De(e)&&t&&e.select()}}var Oe=ke();function ke(){let e=[];return{add(t){let n=e[0];t!==n&&n?.pause(),e=Ae(e,t),e.unshift(t)},remove(t){e=Ae(e,t),e[0]?.resume()}}}function Ae(e,t){let n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function je(e){return e.filter(e=>e.tagName!==`A`)}var Me=`Portal`,Ne=c.forwardRef((e,t)=>{let{container:n,...r}=e,[i,a]=c.useState(!1);D(()=>a(!0),[]);let o=n||i&&globalThis?.document?.body;return o?x.createPortal((0,f.jsx)(S.div,{...r,ref:t}),o):null});Ne.displayName=Me;var F=0;function Pe(){c.useEffect(()=>{let e=document.querySelectorAll(`[data-radix-focus-guard]`);return document.body.insertAdjacentElement(`afterbegin`,e[0]??Fe()),document.body.insertAdjacentElement(`beforeend`,e[1]??Fe()),F++,()=>{F===1&&document.querySelectorAll(`[data-radix-focus-guard]`).forEach(e=>e.remove()),F--}},[])}function Fe(){let e=document.createElement(`span`);return e.setAttribute(`data-radix-focus-guard`,``),e.tabIndex=0,e.style.outline=`none`,e.style.opacity=`0`,e.style.position=`fixed`,e.style.pointerEvents=`none`,e}var I=function(){return I=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n],t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},I.apply(this,arguments)};function Ie(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols==`function`)for(var i=0,r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]]);return n}function Le(e,t,n){if(n||arguments.length===2)for(var r=0,i=t.length,a;r<i;r++)(a||!(r in t))&&(a||=Array.prototype.slice.call(t,0,r),a[r]=t[r]);return e.concat(a||Array.prototype.slice.call(t))}var L=`right-scroll-bar-position`,R=`width-before-scroll-bar`,Re=`with-scroll-bars-hidden`,ze=`--removed-body-scroll-bar-size`;function z(e,t){return typeof e==`function`?e(t):e&&(e.current=t),e}function Be(e,t){var n=(0,c.useState)(function(){return{value:e,callback:t,facade:{get current(){return n.value},set current(e){var t=n.value;t!==e&&(n.value=e,n.callback(e,t))}}}})[0];return n.callback=t,n.facade}var Ve=typeof window<`u`?c.useLayoutEffect:c.useEffect,He=new WeakMap;function Ue(e,t){var n=Be(t||null,function(t){return e.forEach(function(e){return z(e,t)})});return Ve(function(){var t=He.get(n);if(t){var r=new Set(t),i=new Set(e),a=n.current;r.forEach(function(e){i.has(e)||z(e,null)}),i.forEach(function(e){r.has(e)||z(e,a)})}He.set(n,e)},[e]),n}function We(e){return e}function Ge(e,t){t===void 0&&(t=We);var n=[],r=!1;return{read:function(){if(r)throw Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return n.length?n[n.length-1]:e},useMedium:function(e){var i=t(e,r);return n.push(i),function(){n=n.filter(function(e){return e!==i})}},assignSyncMedium:function(e){for(r=!0;n.length;){var t=n;n=[],t.forEach(e)}n={push:function(t){return e(t)},filter:function(){return n}}},assignMedium:function(e){r=!0;var t=[];if(n.length){var i=n;n=[],i.forEach(e),t=n}var a=function(){var n=t;t=[],n.forEach(e)},o=function(){return Promise.resolve().then(a)};o(),n={push:function(e){t.push(e),o()},filter:function(e){return t=t.filter(e),n}}}}}function Ke(e){e===void 0&&(e={});var t=Ge(null);return t.options=I({async:!0,ssr:!1},e),t}var qe=function(e){var t=e.sideCar,n=Ie(e,[`sideCar`]);if(!t)throw Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw Error(`Sidecar medium not found`);return c.createElement(r,I({},n))};qe.isSideCarExport=!0;function Je(e,t){return e.useMedium(t),qe}var Ye=Ke(),B=function(){},V=c.forwardRef(function(e,t){var n=c.useRef(null),r=c.useState({onScrollCapture:B,onWheelCapture:B,onTouchMoveCapture:B}),i=r[0],a=r[1],o=e.forwardProps,s=e.children,l=e.className,u=e.removeScrollBar,d=e.enabled,f=e.shards,p=e.sideCar,m=e.noRelative,h=e.noIsolation,g=e.inert,_=e.allowPinchZoom,v=e.as,y=v===void 0?`div`:v,b=e.gapMode,x=Ie(e,[`forwardProps`,`children`,`className`,`removeScrollBar`,`enabled`,`shards`,`sideCar`,`noRelative`,`noIsolation`,`inert`,`allowPinchZoom`,`as`,`gapMode`]),S=p,C=Ue([n,t]),w=I(I({},x),i);return c.createElement(c.Fragment,null,d&&c.createElement(S,{sideCar:Ye,removeScrollBar:u,shards:f,noRelative:m,noIsolation:h,inert:g,setCallbacks:a,allowPinchZoom:!!_,lockRef:n,gapMode:b}),o?c.cloneElement(c.Children.only(s),I(I({},w),{ref:C})):c.createElement(y,I({},w,{className:l,ref:C}),s))});V.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},V.classNames={fullWidth:R,zeroRight:L};var Xe,Ze=function(){if(Xe)return Xe;if(typeof __webpack_nonce__<`u`)return __webpack_nonce__};function Qe(){if(!document)return null;var e=document.createElement(`style`);e.type=`text/css`;var t=Ze();return t&&e.setAttribute(`nonce`,t),e}function $e(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function et(e){(document.head||document.getElementsByTagName(`head`)[0]).appendChild(e)}var tt=function(){var e=0,t=null;return{add:function(n){e==0&&(t=Qe())&&($e(t,n),et(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},nt=function(){var e=tt();return function(t,n){c.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},rt=function(){var e=nt();return function(t){var n=t.styles,r=t.dynamic;return e(n,r),null}},it={left:0,top:0,right:0,gap:0},H=function(e){return parseInt(e||``,10)||0},at=function(e){var t=window.getComputedStyle(document.body),n=t[e===`padding`?`paddingLeft`:`marginLeft`],r=t[e===`padding`?`paddingTop`:`marginTop`],i=t[e===`padding`?`paddingRight`:`marginRight`];return[H(n),H(r),H(i)]},ot=function(e){if(e===void 0&&(e=`margin`),typeof window>`u`)return it;var t=at(e),n=document.documentElement.clientWidth,r=window.innerWidth;return{left:t[0],top:t[1],right:t[2],gap:Math.max(0,r-n+t[2]-t[0])}},st=rt(),U=`data-scroll-locked`,ct=function(e,t,n,r){var i=e.left,a=e.top,o=e.right,s=e.gap;return n===void 0&&(n=`margin`),`
2
2
  .${Re} {
3
3
  overflow: hidden ${r};
4
4
  padding-right: ${s}px ${r};
@@ -1,6 +1,6 @@
1
- import{a as e,n as t,r as n,t as r}from"./jsx-runtime-BFALxl05.js";import{n as i,t as a}from"./marked.esm-Cv8mjgnt.js";import{t as o}from"./columns-2-DsiY76NQ.js";import{t as s}from"./copy-D_Q54D-v.js";import{t as c}from"./external-link-C6Y-D528.js";import{t as l}from"./refresh-cw-S6I91MHO.js";import{t as u}from"./trash-2-Dc17nbCE.js";import{t as d}from"./x-Bpqyw40Y.js";import{n as f}from"./utils-61GRB9Cb.js";import{n as p,r as m,t as h}from"./api-client-B_eCZViO.js";import{A as g,B as _,C as v,D as y,E as b,F as x,I as S,L as C,M as w,N as T,R as E,S as D,d as O,f as k,i as A,n as ee,r as te,w as j,x as ne}from"./index-CqpLusQd.js";var M=t(`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`}]]),N=t(`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`}]]),P=t(`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`}]]),F=t(`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`}]]),I=t(`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`}]]),re=t(`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`}]]),L=t(`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`}]]),ie=t(`send`,[[`path`,{d:`M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z`,key:`1ffxy3`}],[`path`,{d:`m21.854 2.147-10.94 10.939`,key:`12cjpa`}]]),R=t(`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`}]]),z=t(`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`}]]),B=t(`square`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]),ae=t(`upload`,[[`path`,{d:`M12 3v12`,key:`1x0j5s`}],[`path`,{d:`m17 8-5-5-5 5`,key:`7q97r8`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}]]),V=e(n(),1),H=3e4,oe=1e3,U=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},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(oe*2**this.reconnectAttempts,H);this.reconnectAttempts++,this.reconnectTimer=setTimeout(()=>this.connect(),e)}};function W({url:e,onMessage:t,autoConnect:n=!0}){let r=(0,V.useRef)(null);return(0,V.useEffect)(()=>{let i=new U(e);return r.current=i,t&&i.onMessage(t),n&&i.connect(),()=>{i.disconnect(),r.current=null}},[e,n]),{send:(0,V.useCallback)(e=>{r.current?.send(e)},[]),connect:(0,V.useCallback)(()=>{r.current?.connect()},[]),disconnect:(0,V.useCallback)(()=>{r.current?.disconnect()},[])}}function se(e,t=`claude-sdk`,n=``,r){let[i,a]=(0,V.useState)([]),[o,s]=(0,V.useState)(!1),[c,l]=(0,V.useState)(!1),[u,d]=(0,V.useState)(null),[f,h]=(0,V.useState)(!1),g=(0,V.useRef)(r?.onUsageEvent);g.current=r?.onUsageEvent;let _=(0,V.useRef)(``),v=(0,V.useRef)([]),y=(0,V.useRef)(!1),b=(0,V.useRef)(null),x=(0,V.useRef)(()=>{}),S=(0,V.useRef)(null),C=(0,V.useCallback)(e=>{let t;try{t=JSON.parse(e.data)}catch{return}if(t.type!==`ping`){if(t.type===`connected`){h(!0);return}if(t.type===`status`){h(!0);let e=t;e.isStreaming&&(y.current=!0,l(!0)),e.pendingApproval&&d({requestId:e.pendingApproval.requestId,tool:e.pendingApproval.tool,input:e.pendingApproval.input}),S.current?.();return}switch(t.type){case`text`:{_.current+=t.content,v.current.push(t);let e=_.current,n=[...v.current];a(t=>{let r=t[t.length-1];return r?.role===`assistant`&&!r.id.startsWith(`final-`)?[...t.slice(0,-1),{...r,content:e,events:n}]:[...t,{id:`streaming-${Date.now()}`,role:`assistant`,content:e,events:n,timestamp:new Date().toISOString()}]});break}case`tool_use`:{v.current.push(t);let e=_.current,n=[...v.current];a(t=>{let r=t[t.length-1];return r?.role===`assistant`?[...t.slice(0,-1),{...r,events:n}]:[...t,{id:`streaming-${Date.now()}`,role:`assistant`,content:e,events:n,timestamp:new Date().toISOString()}]});break}case`tool_result`:{v.current.push(t);let e=[...v.current];a(t=>{let n=t[t.length-1];return n?.role===`assistant`?[...t.slice(0,-1),{...n,events:e}]:t});break}case`approval_request`:v.current.push(t),d({requestId:t.requestId,tool:t.tool,input:t.input});break;case`usage`:g.current?.(t.usage);break;case`error`:{v.current.push(t);let e=[...v.current];a(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()}]}),y.current=!1,l(!1);break}case`done`:{let e=_.current,t=[...v.current];a(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}),_.current=``,v.current=[];let n=b.current;n?(b.current=null,a(e=>[...e,{id:`user-${Date.now()}`,role:`user`,content:n,timestamp:new Date().toISOString()}]),_.current=``,v.current=[],y.current=!0,l(!0),x.current(JSON.stringify({type:`message`,content:n}))):(y.current=!1,l(!1));break}}}},[]),{send:w,connect:T}=W({url:e&&n?`/ws/project/${encodeURIComponent(n)}/chat/${e}`:``,onMessage:C,autoConnect:!!e&&!!n});x.current=w,(0,V.useEffect)(()=>{let r=!1;return l(!1),d(null),_.current=``,v.current=[],h(!1),e&&n?(s(!0),fetch(`${m(n)}/chat/sessions/${e}/messages?providerId=${t}`,{headers:{Authorization:`Bearer ${p()}`}}).then(e=>e.json()).then(e=>{r||y.current||(e.ok&&Array.isArray(e.data)&&e.data.length>0?a(e.data):a([]))}).catch(()=>{!r&&!y.current&&a([])}).finally(()=>{r||s(!1)})):a([]),()=>{r=!0}},[e,t,n]);let E=(0,V.useCallback)(e=>{if(e.trim()){if(c){b.current=e;return}a(t=>[...t,{id:`user-${Date.now()}`,role:`user`,content:e,timestamp:new Date().toISOString()}]),_.current=``,v.current=[],y.current=!0,l(!0),w(JSON.stringify({type:`message`,content:e}))}},[w,c]),D=(0,V.useCallback)((e,t,n)=>{if(w(JSON.stringify({type:`approval_response`,requestId:e,approved:t,data:n})),t&&n){let t=v.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)}a(e=>[...e])}d(null)},[w]),O=(0,V.useCallback)(()=>{if(!y.current)return;w(JSON.stringify({type:`cancel`}));let e=_.current,t=[...v.current];a(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}),_.current=``,v.current=[],b.current=null,y.current=!1,l(!1),d(null)},[w]),k=(0,V.useCallback)(()=>{h(!1),T(),S.current?.()},[T]),A=(0,V.useCallback)(()=>{!e||!n||(s(!0),fetch(`${m(n)}/chat/sessions/${e}/messages?providerId=${t}`,{headers:{Authorization:`Bearer ${p()}`}}).then(e=>e.json()).then(e=>{e.ok&&Array.isArray(e.data)&&e.data.length>0&&(a(e.data),_.current=``,v.current=[])}).catch(()=>{}).finally(()=>s(!1)))},[e,t,n]);return S.current=A,{messages:i,messagesLoading:o,isStreaming:c,pendingApproval:u,sendMessage:E,respondToApproval:D,cancelStreaming:O,reconnect:k,refetchMessages:A,isConnected:f}}var ce=6e4;function le(e,t=`claude-sdk`){let[n,r]=(0,V.useState)({}),[i,a]=(0,V.useState)(!1),[o,s]=(0,V.useState)(null),c=(0,V.useRef)(null),l=(0,V.useCallback)((n=!1)=>{if(!e)return;a(!0);let i=n?`&_t=${Date.now()}`:``;fetch(`${m(e)}/chat/usage?providerId=${t}${i}`,{headers:{Authorization:`Bearer ${p()}`}}).then(e=>e.json()).then(e=>{e.ok&&e.data&&(r(t=>({...t,...e.data})),s(Date.now()))}).catch(()=>{}).finally(()=>a(!1))},[e,t]);return(0,V.useEffect)(()=>(l(),c.current=setInterval(()=>l(!0),ce),()=>{c.current&&clearInterval(c.current)}),[l]),{usageInfo:n,usageLoading:i,lastUpdatedAt:o,refreshUsage:(0,V.useCallback)(()=>{l(!0)},[l]),mergeUsage:(0,V.useCallback)(e=>{r(t=>{let n={...t,...e};return e.totalCostUsd!=null&&(n.queryCostUsd=e.totalCostUsd,n.totalCostUsd=(t.totalCostUsd??0)+e.totalCostUsd),n})},[])}}var G=r();function ue(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 de({tool:e,result:t,completed:n,projectName:r}){let[i,a]=(0,V.useState)(!1);if(e.type===`error`)return(0,G.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,G.jsx)(S,{className:`size-3`}),(0,G.jsx)(`span`,{children:e.message})]});let{toolName:o,input:s}=ue(e),c=t?.type===`tool_result`,l=c&&!!t.isError,u=o===`AskUserQuestion`&&!!s?.answers;return(0,G.jsxs)(`div`,{className:`rounded border border-border bg-background text-xs`,children:[(0,G.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,G.jsx)(E,{className:`size-3 shrink-0`}):(0,G.jsx)(C,{className:`size-3 shrink-0`}),l?(0,G.jsx)(P,{className:`size-3 text-red-400 shrink-0`}):c||u||n?(0,G.jsx)(x,{className:`size-3 text-green-400 shrink-0`}):(0,G.jsx)(y,{className:`size-3 text-yellow-400 shrink-0 animate-spin`}),(0,G.jsx)(`span`,{className:`truncate text-text-primary`,children:(0,G.jsx)(fe,{name:o,input:s})})]}),i&&(0,G.jsxs)(`div`,{className:`px-2 pb-2 space-y-1.5`,children:[(e.type===`tool_use`||e.type===`approval_request`)&&(0,G.jsx)(pe,{name:o,input:s,projectName:r}),c&&(0,G.jsx)(me,{toolName:o,output:t.output})]})]})}function fe({name:e,input:t}){let n=e=>String(e??``);switch(e){case`Read`:case`Write`:case`Edit`:case`MultiEdit`:case`NotebookEdit`:return(0,G.jsxs)(G.Fragment,{children:[e,` `,(0,G.jsx)(`span`,{className:`text-text-subtle`,children:he(n(t.file_path))})]});case`Bash`:return(0,G.jsxs)(G.Fragment,{children:[e,` `,(0,G.jsx)(`span`,{className:`font-mono text-text-subtle`,children:Y(n(t.command),60)})]});case`Glob`:return(0,G.jsxs)(G.Fragment,{children:[e,` `,(0,G.jsx)(`span`,{className:`font-mono text-text-subtle`,children:n(t.pattern)})]});case`Grep`:return(0,G.jsxs)(G.Fragment,{children:[e,` `,(0,G.jsx)(`span`,{className:`font-mono text-text-subtle`,children:Y(n(t.pattern),40)})]});case`WebSearch`:return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(v,{className:`size-3 inline`}),` `,e,` `,(0,G.jsx)(`span`,{className:`text-text-subtle`,children:Y(n(t.query),50)})]});case`WebFetch`:return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(F,{className:`size-3 inline`}),` `,e,` `,(0,G.jsx)(`span`,{className:`text-text-subtle`,children:Y(n(t.url),50)})]});case`ToolSearch`:return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(v,{className:`size-3 inline`}),` `,e,` `,(0,G.jsx)(`span`,{className:`text-text-subtle`,children:Y(n(t.query),50)})]});case`Agent`:case`Task`:return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(N,{className:`size-3 inline`}),` `,e,` `,(0,G.jsx)(`span`,{className:`text-text-subtle`,children:Y(n(t.description||t.prompt),60)})]});case`TodoWrite`:{let n=t.todos??[],r=n.filter(e=>e.status===`completed`).length;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(re,{className:`size-3 inline`}),` `,e,` `,(0,G.jsxs)(`span`,{className:`text-text-subtle`,children:[r,`/`,n.length,` done`]})]})}case`AskUserQuestion`:{let n=t.questions??[],r=!!t.answers;return(0,G.jsxs)(G.Fragment,{children:[e,` `,(0,G.jsxs)(`span`,{className:`text-text-subtle`,children:[n.length,` question`,n.length===1?``:`s`,r?` ✓`:``]})]})}default:return(0,G.jsx)(G.Fragment,{children:e})}}function pe({name:e,input:t,projectName:n}){let r=e=>String(e??``),{openTab:i}=k(),a=e=>{n&&i({type:`editor`,title:e.split(`/`).pop()??e,metadata:{filePath:e,projectName:n},projectId:n,closable:!0})},s=(e,t,r)=>{i({type:`git-diff`,title:`Diff ${e.split(`/`).pop()??e}`,metadata:{filePath:e,projectName:n,original:t,modified:r},projectId:n??null,closable:!0})};switch(e){case`Bash`:return(0,G.jsxs)(`div`,{className:`space-y-1`,children:[!!t.description&&(0,G.jsx)(`p`,{className:`text-text-subtle italic`,children:r(t.description)}),(0,G.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,G.jsxs)(`div`,{className:`space-y-1`,children:[(0,G.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,G.jsx)(c,{className:`size-3 shrink-0`}),n]}),e===`Edit`&&(!!t.old_string||!!t.new_string)&&(0,G.jsxs)(`button`,{type:`button`,className:`text-text-subtle hover:text-primary hover:underline text-left flex items-center gap-1`,onClick:()=>s(n,r(t.old_string),r(t.new_string)),title:`View diff in new tab`,children:[(0,G.jsx)(o,{className:`size-3 shrink-0`}),`View Diff`]}),e===`Write`&&!!t.content&&(0,G.jsx)(`pre`,{className:`font-mono text-text-subtle overflow-x-auto max-h-32 whitespace-pre-wrap`,children:Y(r(t.content),300)})]})}case`Glob`:return(0,G.jsxs)(`p`,{className:`font-mono text-text-secondary`,children:[r(t.pattern),t.path?` in ${r(t.path)}`:``]});case`Grep`:return(0,G.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,G.jsxs)(`p`,{className:`font-mono text-text-secondary`,children:[`/`,r(t.pattern),`/`]}),!!t.path&&(0,G.jsxs)(`p`,{className:`text-text-subtle`,children:[`in `,r(t.path)]})]});case`TodoWrite`:return(0,G.jsx)(K,{todos:t.todos??[]});case`Agent`:case`Task`:return(0,G.jsxs)(`div`,{className:`space-y-1`,children:[!!t.description&&(0,G.jsx)(`p`,{className:`text-text-secondary font-medium`,children:r(t.description)}),!!t.subagent_type&&(0,G.jsxs)(`p`,{className:`text-text-subtle`,children:[`Type: `,r(t.subagent_type)]}),!!t.prompt&&(0,G.jsx)(J,{content:r(t.prompt),maxHeight:`max-h-48`})]});case`ToolSearch`:return(0,G.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,G.jsx)(`p`,{className:`font-mono text-text-secondary`,children:r(t.query)}),!!t.max_results&&(0,G.jsxs)(`p`,{className:`text-text-subtle`,children:[`Max results: `,r(t.max_results)]})]});case`WebFetch`:return(0,G.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,G.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,G.jsx)(F,{className:`size-3 shrink-0`}),r(t.url)]}),!!t.prompt&&(0,G.jsx)(`p`,{className:`text-text-subtle`,children:Y(r(t.prompt),100)})]});case`AskUserQuestion`:{let e=t.questions??[],n=t.answers??{};return(0,G.jsx)(`div`,{className:`space-y-2`,children:e.map((e,t)=>(0,G.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,G.jsxs)(`p`,{className:`text-text-primary font-medium`,children:[e.header?`${e.header}: `:``,e.question]}),(0,G.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:e.options.map((t,r)=>(0,G.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,G.jsxs)(`p`,{className:`text-accent text-xs`,children:[`Answer: `,n[e.question]]})]},t))})}default:return(0,G.jsx)(`pre`,{className:`overflow-x-auto text-text-secondary font-mono whitespace-pre-wrap break-all`,children:JSON.stringify(t,null,2)})}}function K({todos:e}){return(0,G.jsx)(`div`,{className:`space-y-0.5`,children:e.map((e,t)=>(0,G.jsxs)(`div`,{className:`flex items-start gap-1.5`,children:[(0,G.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,G.jsx)(`span`,{className:e.status===`completed`?`line-through text-text-subtle`:`text-text-secondary`,children:e.content})]},t))})}function me({toolName:e,output:t}){let[n,r]=(0,V.useState)(!1),a=(0,V.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
+ import{a as e,n as t,r as n,t as r}from"./jsx-runtime-BFALxl05.js";import{n as i,t as a}from"./marked.esm-Cv8mjgnt.js";import{t as o}from"./columns-2-DsiY76NQ.js";import{t as s}from"./copy-D_Q54D-v.js";import{t as c}from"./external-link-C6Y-D528.js";import{t as l}from"./refresh-cw-S6I91MHO.js";import{t as u}from"./trash-2-CGlFXde_.js";import{t as d}from"./x-C0Rw5Giw.js";import{n as f,r as p,t as m}from"./api-client-DzH9zCD7.js";import{n as h}from"./utils-D6me7KDg.js";import{A as g,B as _,C as v,D as y,E as b,F as x,I as S,L as C,M as w,N as T,R as E,S as D,d as O,f as k,i as A,n as ee,r as te,w as j,x as ne}from"./index-DbTCLiox.js";var M=t(`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`}]]),N=t(`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`}]]),P=t(`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`}]]),F=t(`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`}]]),I=t(`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`}]]),re=t(`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`}]]),L=t(`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`}]]),ie=t(`send`,[[`path`,{d:`M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z`,key:`1ffxy3`}],[`path`,{d:`m21.854 2.147-10.94 10.939`,key:`12cjpa`}]]),R=t(`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`}]]),z=t(`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`}]]),B=t(`square`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]),ae=t(`upload`,[[`path`,{d:`M12 3v12`,key:`1x0j5s`}],[`path`,{d:`m17 8-5-5-5 5`,key:`7q97r8`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}]]),V=e(n(),1),H=3e4,oe=1e3,U=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},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(oe*2**this.reconnectAttempts,H);this.reconnectAttempts++,this.reconnectTimer=setTimeout(()=>this.connect(),e)}};function W({url:e,onMessage:t,autoConnect:n=!0}){let r=(0,V.useRef)(null);return(0,V.useEffect)(()=>{let i=new U(e);return r.current=i,t&&i.onMessage(t),n&&i.connect(),()=>{i.disconnect(),r.current=null}},[e,n]),{send:(0,V.useCallback)(e=>{r.current?.send(e)},[]),connect:(0,V.useCallback)(()=>{r.current?.connect()},[]),disconnect:(0,V.useCallback)(()=>{r.current?.disconnect()},[])}}function se(e,t=`claude-sdk`,n=``,r){let[i,a]=(0,V.useState)([]),[o,s]=(0,V.useState)(!1),[c,l]=(0,V.useState)(!1),[u,d]=(0,V.useState)(null),[m,h]=(0,V.useState)(!1),g=(0,V.useRef)(r?.onUsageEvent);g.current=r?.onUsageEvent;let _=(0,V.useRef)(``),v=(0,V.useRef)([]),y=(0,V.useRef)(!1),b=(0,V.useRef)(null),x=(0,V.useRef)(()=>{}),S=(0,V.useRef)(null),C=(0,V.useCallback)(e=>{let t;try{t=JSON.parse(e.data)}catch{return}if(t.type!==`ping`){if(t.type===`connected`){h(!0);return}if(t.type===`status`){h(!0);let e=t;e.isStreaming&&(y.current=!0,l(!0)),e.pendingApproval&&d({requestId:e.pendingApproval.requestId,tool:e.pendingApproval.tool,input:e.pendingApproval.input}),S.current?.();return}switch(t.type){case`text`:{_.current+=t.content,v.current.push(t);let e=_.current,n=[...v.current];a(t=>{let r=t[t.length-1];return r?.role===`assistant`&&!r.id.startsWith(`final-`)?[...t.slice(0,-1),{...r,content:e,events:n}]:[...t,{id:`streaming-${Date.now()}`,role:`assistant`,content:e,events:n,timestamp:new Date().toISOString()}]});break}case`tool_use`:{v.current.push(t);let e=_.current,n=[...v.current];a(t=>{let r=t[t.length-1];return r?.role===`assistant`?[...t.slice(0,-1),{...r,events:n}]:[...t,{id:`streaming-${Date.now()}`,role:`assistant`,content:e,events:n,timestamp:new Date().toISOString()}]});break}case`tool_result`:{v.current.push(t);let e=[...v.current];a(t=>{let n=t[t.length-1];return n?.role===`assistant`?[...t.slice(0,-1),{...n,events:e}]:t});break}case`approval_request`:v.current.push(t),d({requestId:t.requestId,tool:t.tool,input:t.input});break;case`usage`:g.current?.(t.usage);break;case`error`:{v.current.push(t);let e=[...v.current];a(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()}]}),y.current=!1,l(!1);break}case`done`:{let e=_.current,t=[...v.current];a(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}),_.current=``,v.current=[];let n=b.current;n?(b.current=null,a(e=>[...e,{id:`user-${Date.now()}`,role:`user`,content:n,timestamp:new Date().toISOString()}]),_.current=``,v.current=[],y.current=!0,l(!0),x.current(JSON.stringify({type:`message`,content:n}))):(y.current=!1,l(!1));break}}}},[]),{send:w,connect:T}=W({url:e&&n?`/ws/project/${encodeURIComponent(n)}/chat/${e}`:``,onMessage:C,autoConnect:!!e&&!!n});x.current=w,(0,V.useEffect)(()=>{let r=!1;return l(!1),d(null),_.current=``,v.current=[],h(!1),e&&n?(s(!0),fetch(`${p(n)}/chat/sessions/${e}/messages?providerId=${t}`,{headers:{Authorization:`Bearer ${f()}`}}).then(e=>e.json()).then(e=>{r||y.current||(e.ok&&Array.isArray(e.data)&&e.data.length>0?a(e.data):a([]))}).catch(()=>{!r&&!y.current&&a([])}).finally(()=>{r||s(!1)})):a([]),()=>{r=!0}},[e,t,n]);let E=(0,V.useCallback)(e=>{if(e.trim()){if(c){b.current=e;return}a(t=>[...t,{id:`user-${Date.now()}`,role:`user`,content:e,timestamp:new Date().toISOString()}]),_.current=``,v.current=[],y.current=!0,l(!0),w(JSON.stringify({type:`message`,content:e}))}},[w,c]),D=(0,V.useCallback)((e,t,n)=>{if(w(JSON.stringify({type:`approval_response`,requestId:e,approved:t,data:n})),t&&n){let t=v.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)}a(e=>[...e])}d(null)},[w]),O=(0,V.useCallback)(()=>{if(!y.current)return;w(JSON.stringify({type:`cancel`}));let e=_.current,t=[...v.current];a(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}),_.current=``,v.current=[],b.current=null,y.current=!1,l(!1),d(null)},[w]),k=(0,V.useCallback)(()=>{h(!1),T(),S.current?.()},[T]),A=(0,V.useCallback)(()=>{!e||!n||(s(!0),fetch(`${p(n)}/chat/sessions/${e}/messages?providerId=${t}`,{headers:{Authorization:`Bearer ${f()}`}}).then(e=>e.json()).then(e=>{e.ok&&Array.isArray(e.data)&&e.data.length>0&&(a(e.data),_.current=``,v.current=[])}).catch(()=>{}).finally(()=>s(!1)))},[e,t,n]);return S.current=A,{messages:i,messagesLoading:o,isStreaming:c,pendingApproval:u,sendMessage:E,respondToApproval:D,cancelStreaming:O,reconnect:k,refetchMessages:A,isConnected:m}}var ce=6e4;function le(e,t=`claude-sdk`){let[n,r]=(0,V.useState)({}),[i,a]=(0,V.useState)(!1),[o,s]=(0,V.useState)(null),c=(0,V.useRef)(null),l=(0,V.useCallback)((n=!1)=>{if(!e)return;a(!0);let i=n?`&_t=${Date.now()}`:``;fetch(`${p(e)}/chat/usage?providerId=${t}${i}`,{headers:{Authorization:`Bearer ${f()}`}}).then(e=>e.json()).then(e=>{e.ok&&e.data&&(r(t=>({...t,...e.data})),s(Date.now()))}).catch(()=>{}).finally(()=>a(!1))},[e,t]);return(0,V.useEffect)(()=>(l(),c.current=setInterval(()=>l(!0),ce),()=>{c.current&&clearInterval(c.current)}),[l]),{usageInfo:n,usageLoading:i,lastUpdatedAt:o,refreshUsage:(0,V.useCallback)(()=>{l(!0)},[l]),mergeUsage:(0,V.useCallback)(e=>{r(t=>{let n={...t,...e};return e.totalCostUsd!=null&&(n.queryCostUsd=e.totalCostUsd,n.totalCostUsd=(t.totalCostUsd??0)+e.totalCostUsd),n})},[])}}var G=r();function ue(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 de({tool:e,result:t,completed:n,projectName:r}){let[i,a]=(0,V.useState)(!1);if(e.type===`error`)return(0,G.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,G.jsx)(S,{className:`size-3`}),(0,G.jsx)(`span`,{children:e.message})]});let{toolName:o,input:s}=ue(e),c=t?.type===`tool_result`,l=c&&!!t.isError,u=o===`AskUserQuestion`&&!!s?.answers;return(0,G.jsxs)(`div`,{className:`rounded border border-border bg-background text-xs`,children:[(0,G.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,G.jsx)(E,{className:`size-3 shrink-0`}):(0,G.jsx)(C,{className:`size-3 shrink-0`}),l?(0,G.jsx)(P,{className:`size-3 text-red-400 shrink-0`}):c||u||n?(0,G.jsx)(x,{className:`size-3 text-green-400 shrink-0`}):(0,G.jsx)(y,{className:`size-3 text-yellow-400 shrink-0 animate-spin`}),(0,G.jsx)(`span`,{className:`truncate text-text-primary`,children:(0,G.jsx)(fe,{name:o,input:s})})]}),i&&(0,G.jsxs)(`div`,{className:`px-2 pb-2 space-y-1.5`,children:[(e.type===`tool_use`||e.type===`approval_request`)&&(0,G.jsx)(pe,{name:o,input:s,projectName:r}),c&&(0,G.jsx)(me,{toolName:o,output:t.output})]})]})}function fe({name:e,input:t}){let n=e=>String(e??``);switch(e){case`Read`:case`Write`:case`Edit`:case`MultiEdit`:case`NotebookEdit`:return(0,G.jsxs)(G.Fragment,{children:[e,` `,(0,G.jsx)(`span`,{className:`text-text-subtle`,children:he(n(t.file_path))})]});case`Bash`:return(0,G.jsxs)(G.Fragment,{children:[e,` `,(0,G.jsx)(`span`,{className:`font-mono text-text-subtle`,children:Y(n(t.command),60)})]});case`Glob`:return(0,G.jsxs)(G.Fragment,{children:[e,` `,(0,G.jsx)(`span`,{className:`font-mono text-text-subtle`,children:n(t.pattern)})]});case`Grep`:return(0,G.jsxs)(G.Fragment,{children:[e,` `,(0,G.jsx)(`span`,{className:`font-mono text-text-subtle`,children:Y(n(t.pattern),40)})]});case`WebSearch`:return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(v,{className:`size-3 inline`}),` `,e,` `,(0,G.jsx)(`span`,{className:`text-text-subtle`,children:Y(n(t.query),50)})]});case`WebFetch`:return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(F,{className:`size-3 inline`}),` `,e,` `,(0,G.jsx)(`span`,{className:`text-text-subtle`,children:Y(n(t.url),50)})]});case`ToolSearch`:return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(v,{className:`size-3 inline`}),` `,e,` `,(0,G.jsx)(`span`,{className:`text-text-subtle`,children:Y(n(t.query),50)})]});case`Agent`:case`Task`:return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(N,{className:`size-3 inline`}),` `,e,` `,(0,G.jsx)(`span`,{className:`text-text-subtle`,children:Y(n(t.description||t.prompt),60)})]});case`TodoWrite`:{let n=t.todos??[],r=n.filter(e=>e.status===`completed`).length;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(re,{className:`size-3 inline`}),` `,e,` `,(0,G.jsxs)(`span`,{className:`text-text-subtle`,children:[r,`/`,n.length,` done`]})]})}case`AskUserQuestion`:{let n=t.questions??[],r=!!t.answers;return(0,G.jsxs)(G.Fragment,{children:[e,` `,(0,G.jsxs)(`span`,{className:`text-text-subtle`,children:[n.length,` question`,n.length===1?``:`s`,r?` ✓`:``]})]})}default:return(0,G.jsx)(G.Fragment,{children:e})}}function pe({name:e,input:t,projectName:n}){let r=e=>String(e??``),{openTab:i}=k(),a=e=>{n&&i({type:`editor`,title:e.split(`/`).pop()??e,metadata:{filePath:e,projectName:n},projectId:n,closable:!0})},s=(e,t,r)=>{i({type:`git-diff`,title:`Diff ${e.split(`/`).pop()??e}`,metadata:{filePath:e,projectName:n,original:t,modified:r},projectId:n??null,closable:!0})};switch(e){case`Bash`:return(0,G.jsxs)(`div`,{className:`space-y-1`,children:[!!t.description&&(0,G.jsx)(`p`,{className:`text-text-subtle italic`,children:r(t.description)}),(0,G.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,G.jsxs)(`div`,{className:`space-y-1`,children:[(0,G.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,G.jsx)(c,{className:`size-3 shrink-0`}),n]}),e===`Edit`&&(!!t.old_string||!!t.new_string)&&(0,G.jsxs)(`button`,{type:`button`,className:`text-text-subtle hover:text-primary hover:underline text-left flex items-center gap-1`,onClick:()=>s(n,r(t.old_string),r(t.new_string)),title:`View diff in new tab`,children:[(0,G.jsx)(o,{className:`size-3 shrink-0`}),`View Diff`]}),e===`Write`&&!!t.content&&(0,G.jsx)(`pre`,{className:`font-mono text-text-subtle overflow-x-auto max-h-32 whitespace-pre-wrap`,children:Y(r(t.content),300)})]})}case`Glob`:return(0,G.jsxs)(`p`,{className:`font-mono text-text-secondary`,children:[r(t.pattern),t.path?` in ${r(t.path)}`:``]});case`Grep`:return(0,G.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,G.jsxs)(`p`,{className:`font-mono text-text-secondary`,children:[`/`,r(t.pattern),`/`]}),!!t.path&&(0,G.jsxs)(`p`,{className:`text-text-subtle`,children:[`in `,r(t.path)]})]});case`TodoWrite`:return(0,G.jsx)(K,{todos:t.todos??[]});case`Agent`:case`Task`:return(0,G.jsxs)(`div`,{className:`space-y-1`,children:[!!t.description&&(0,G.jsx)(`p`,{className:`text-text-secondary font-medium`,children:r(t.description)}),!!t.subagent_type&&(0,G.jsxs)(`p`,{className:`text-text-subtle`,children:[`Type: `,r(t.subagent_type)]}),!!t.prompt&&(0,G.jsx)(J,{content:r(t.prompt),maxHeight:`max-h-48`})]});case`ToolSearch`:return(0,G.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,G.jsx)(`p`,{className:`font-mono text-text-secondary`,children:r(t.query)}),!!t.max_results&&(0,G.jsxs)(`p`,{className:`text-text-subtle`,children:[`Max results: `,r(t.max_results)]})]});case`WebFetch`:return(0,G.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,G.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,G.jsx)(F,{className:`size-3 shrink-0`}),r(t.url)]}),!!t.prompt&&(0,G.jsx)(`p`,{className:`text-text-subtle`,children:Y(r(t.prompt),100)})]});case`AskUserQuestion`:{let e=t.questions??[],n=t.answers??{};return(0,G.jsx)(`div`,{className:`space-y-2`,children:e.map((e,t)=>(0,G.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,G.jsxs)(`p`,{className:`text-text-primary font-medium`,children:[e.header?`${e.header}: `:``,e.question]}),(0,G.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:e.options.map((t,r)=>(0,G.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,G.jsxs)(`p`,{className:`text-accent text-xs`,children:[`Answer: `,n[e.question]]})]},t))})}default:return(0,G.jsx)(`pre`,{className:`overflow-x-auto text-text-secondary font-mono whitespace-pre-wrap break-all`,children:JSON.stringify(t,null,2)})}}function K({todos:e}){return(0,G.jsx)(`div`,{className:`space-y-0.5`,children:e.map((e,t)=>(0,G.jsxs)(`div`,{className:`flex items-start gap-1.5`,children:[(0,G.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,G.jsx)(`span`,{className:e.status===`completed`?`line-through text-text-subtle`:`text-text-secondary`,children:e.content})]},t))})}function me({toolName:e,output:t}){let[n,r]=(0,V.useState)(!1),a=(0,V.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(`
2
2
 
3
3
  `);if(t)return t}if(typeof e==`string`)return e}catch{if(t&&!t.startsWith(`[{`))return t}return null},[e,t]);return a?(0,G.jsxs)(`div`,{className:`border-t border-border pt-1.5 space-y-1`,children:[(0,G.jsx)(J,{content:a,maxHeight:`max-h-60`}),(0,G.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,G.jsx)(i,{className:`size-3`}),n?`Hide`:`Show`,` raw`]}),n&&(0,G.jsx)(`pre`,{className:`overflow-x-auto text-text-subtle font-mono max-h-40 whitespace-pre-wrap break-all text-[10px]`,children:t})]}):(0,G.jsx)(q,{output:t})}function q({output:e}){let t=e.split(`
4
4
  `).length,n=t>3||e.length>200,[r,i]=(0,V.useState)(n);return(0,G.jsxs)(`div`,{className:`border-t border-border pt-1.5`,children:[n&&(0,G.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,G.jsx)(C,{className:`size-3`}):(0,G.jsx)(E,{className:`size-3`}),`Output (`,t,` lines)`]}),(0,G.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 J({content:e,maxHeight:t=`max-h-48`}){let n=(0,V.useMemo)(()=>{try{return a.parse(e,{gfm:!0,breaks:!0})}catch{return e}},[e]);return(0,G.jsx)(`div`,{className:`markdown-content prose-sm text-text-secondary overflow-auto ${t}`,dangerouslySetInnerHTML:{__html:n}})}function he(e){return e?e.split(`/`).pop()??e:``}function Y(e,t=50){return e?e.length>t?e.slice(0,t)+`…`:e:``}function ge({messages:e,messagesLoading:t,pendingApproval:n,onApprovalResponse:r,isStreaming:i,projectName:a}){let o=(0,V.useRef)(null),s=(0,V.useRef)(!0);return(0,V.useEffect)(()=>{let t=s.current?`instant`:`smooth`;o.current?.scrollIntoView({behavior:t}),s.current&&e.length>0&&(s.current=!1)},[e,n]),t?(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,G.jsx)(N,{className:`size-10 text-text-subtle animate-pulse`}),(0,G.jsx)(`p`,{className:`text-sm`,children:`Loading messages...`})]}):e.length===0&&!i?(0,G.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,G.jsx)(N,{className:`size-10 text-text-subtle`}),(0,G.jsx)(`p`,{className:`text-sm`,children:`Send a message to start the conversation`})]}):(0,G.jsxs)(`div`,{className:`flex-1 overflow-y-auto 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,G.jsx)(_e,{message:e,isStreaming:i&&e.id.startsWith(`streaming-`),projectName:a},e.id)),n&&(n.tool===`AskUserQuestion`?(0,G.jsx)(Oe,{approval:n,onRespond:r}):(0,G.jsx)(De,{approval:n,onRespond:r})),i&&(0,G.jsx)(Te,{lastMessage:e[e.length-1]}),(0,G.jsx)(`div`,{ref:o})]})}function _e({message:e,isStreaming:t,projectName:n}){return e.role===`user`?(0,G.jsx)(be,{content:e.content,projectName:n}):e.role===`system`?(0,G.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,G.jsx)(S,{className:`size-4 shrink-0`}),(0,G.jsx)(`p`,{children:e.content})]}):(0,G.jsx)(`div`,{className:`flex flex-col gap-2`,children:e.events&&e.events.length>0?(0,G.jsx)(Ce,{events:e.events,isStreaming:t,projectName:n}):e.content&&(0,G.jsx)(`div`,{className:`text-sm text-text-primary`,children:(0,G.jsx)(Ee,{content:e.content,projectName:n})})})}var X=new Set([`.png`,`.jpg`,`.jpeg`,`.gif`,`.webp`]);function ve(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(`
5
- `).map(e=>e.trim()).filter(Boolean),text:e.slice(n[0].length)}:{files:[],text:e}}function Z(e,t){let n=e.split(`/`).pop()??``;return`/api/project/${encodeURIComponent(t??`_`)}/chat/uploads/${encodeURIComponent(n)}`}function Q(e){let t=e.lastIndexOf(`.`);return t===-1?!1:X.has(e.slice(t).toLowerCase())}function ye(e){return e.toLowerCase().endsWith(`.pdf`)}function be({content:e,projectName:t}){let{files:n,text:r}=(0,V.useMemo)(()=>ve(e),[e]);return(0,G.jsx)(`div`,{className:`flex justify-end`,children:(0,G.jsxs)(`div`,{className:`rounded-lg bg-primary/10 px-3 py-2 text-sm text-text-primary max-w-[85%] space-y-2`,children:[n.length>0&&(0,G.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:n.map((e,n)=>Q(e)?(0,G.jsx)(xe,{src:Z(e,t),alt:e.split(`/`).pop()??`image`},n):ye(e)?(0,G.jsx)(Se,{src:Z(e,t),filename:e.split(`/`).pop()??`document.pdf`,mimeType:`application/pdf`},n):(0,G.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,G.jsx)(T,{className:`size-3.5 shrink-0`}),(0,G.jsx)(`span`,{className:`truncate max-w-40`,children:e.split(`/`).pop()})]},n))}),r&&(0,G.jsx)(`p`,{className:`whitespace-pre-wrap break-words`,children:r})]})})}function xe({src:e,alt:t}){let[n,r]=(0,V.useState)(null),[i,a]=(0,V.useState)(!1);return(0,V.useEffect)(()=>{let t,n=p();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,G.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,G.jsx)(I,{className:`size-3.5 shrink-0`}),(0,G.jsx)(`span`,{className:`truncate max-w-40`,children:t})]}):n?(0,G.jsx)(`a`,{href:n,target:`_blank`,rel:`noopener noreferrer`,className:`block`,children:(0,G.jsx)(`img`,{src:n,alt:t,className:`rounded-md max-h-48 max-w-full object-contain border border-border`})}):(0,G.jsx)(`div`,{className:`rounded-md bg-surface border border-border h-24 w-32 animate-pulse`})}function Se({src:e,filename:t,mimeType:n}){let[r,i]=(0,V.useState)(!1);return(0,G.jsxs)(`button`,{type:`button`,onClick:(0,V.useCallback)(async()=>{i(!0);try{let t=p(),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,G.jsx)(T,{className:`size-3.5 shrink-0 text-red-400`}),(0,G.jsx)(`span`,{className:`truncate max-w-40`,children:t}),r&&(0,G.jsx)(`span`,{className:`animate-spin text-[10px]`,children:`...`})]})}function Ce({events:e,isStreaming:t,projectName:n}){let r=[],i=``;for(let t=0;t<e.length;t++){let n=e[t];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}))}i&&r.push({kind:`text`,content:i});let a=e.filter(e=>e.type===`tool_result`);for(let e of a){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,G.jsx)(G.Fragment,{children:r.map((e,i)=>{if(e.kind===`text`){let a=t&&i===r.length-1;return(0,G.jsx)(`div`,{className:`text-sm text-text-primary`,children:(0,G.jsx)(we,{content:e.content,animate:a,projectName:n})},`text-${i}`)}return(0,G.jsx)(de,{tool:e.tool,result:e.result,completed:e.completed,projectName:n},`tool-${i}`)})})}function we({content:e,animate:t,projectName:n}){return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Ee,{content:e,projectName:n}),t&&(0,G.jsx)(`span`,{className:`text-text-subtle text-sm animate-pulse`,children:`Thinking...`})]})}function Te({lastMessage:e}){if(!e||e.role!==`assistant`)return(0,G.jsx)(`div`,{className:`flex items-center gap-2 text-text-subtle text-sm`,children:(0,G.jsx)(`span`,{className:`animate-pulse`,children:`Thinking...`})});let t=e.events;if(t&&t.length>0){let e=t[t.length-1];if(e?.type===`tool_use`||e?.type===`tool_result`)return(0,G.jsx)(`div`,{className:`flex items-center gap-2 text-text-subtle text-sm`,children:(0,G.jsx)(`span`,{className:`animate-pulse`,children:`Thinking...`})})}return null}a.setOptions({gfm:!0,breaks:!0});function Ee({content:e,projectName:t}){let n=(0,V.useMemo)(()=>{try{return a.parse(e)}catch{return e}},[e]),r=(0,V.useRef)(null),{openTab:i}=k();return(0,V.useEffect)(()=>{let e=r.current;if(!e)return;e.querySelectorAll(`pre`).forEach(e=>{if(e.querySelector(`.code-actions`))return;let n=e.querySelector(`code`),r=n?.textContent??e.textContent??``,a=n?.className??``,o=/language-(bash|sh|shell|zsh)/.test(a)||!a.includes(`language-`)&&r.startsWith(`$`);e.style.position=`relative`;let s=document.createElement(`div`);s.className=`code-actions absolute top-1 right-1 flex gap-1 opacity-0 group-hover:opacity-100 transition-opacity`,e.classList.add(`group`);let c=document.createElement(`button`);if(c.className=`flex items-center justify-center size-6 rounded bg-surface-elevated/80 hover:bg-surface-elevated text-text-secondary hover:text-text-primary transition-colors border border-border/50`,c.title=`Copy`,c.innerHTML=`<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="14" height="14" x="8" y="8" rx="2" ry="2"/><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"/></svg>`,c.addEventListener(`click`,()=>{navigator.clipboard.writeText(r),c.innerHTML=`<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg>`,setTimeout(()=>{c.innerHTML=`<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="14" height="14" x="8" y="8" rx="2" ry="2"/><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"/></svg>`},2e3)}),s.appendChild(c),o){let e=document.createElement(`button`);e.className=`flex items-center justify-center size-6 rounded bg-surface-elevated/80 hover:bg-surface-elevated text-text-secondary hover:text-text-primary transition-colors border border-border/50`,e.title=`Run in terminal`,e.innerHTML=`<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="4 17 10 11 4 5"/><line x1="12" y1="19" x2="20" y2="19"/></svg>`,e.addEventListener(`click`,()=>{navigator.clipboard.writeText(r.replace(/^\$\s*/gm,``)),t&&i({type:`terminal`,title:`Terminal`,metadata:{projectName:t},projectId:t,closable:!0})}),s.appendChild(e)}e.appendChild(s)});let n=n=>{let r=n.target.closest(`a`);if(!r||!e.contains(r))return;let a=r.getAttribute(`href`)??``;(/^(\/|\.\/|\.\.\/)/.test(a)||/\.(ts|tsx|js|jsx|py|json|md|yaml|yml|toml|css|html|sh|go|rs|sql)$/i.test(a))&&t&&(n.preventDefault(),i({type:`editor`,title:a.split(`/`).pop()??a,metadata:{filePath:a,projectName:t},projectId:t,closable:!0}))};return e.addEventListener(`click`,n),()=>e.removeEventListener(`click`,n)},[n,t,i]),(0,G.jsx)(`div`,{ref:r,className:`markdown-content prose-sm`,dangerouslySetInnerHTML:{__html:n}})}function De({approval:e,onRespond:t}){return(0,G.jsxs)(`div`,{className:`rounded-lg border-2 border-yellow-500/40 bg-yellow-500/10 p-3 space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-yellow-400 text-sm font-medium`,children:[(0,G.jsx)(R,{className:`size-4`}),(0,G.jsx)(`span`,{children:`Tool Approval Required`})]}),(0,G.jsx)(`div`,{className:`text-xs text-text-primary`,children:(0,G.jsx)(`span`,{className:`font-medium`,children:e.tool})}),(0,G.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,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.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,G.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 Oe({approval:e,onRespond:t}){let n=e.input.questions??[],[r,i]=(0,V.useState)({}),[a,o]=(0,V.useState)({}),s=(e,t,n)=>{o(t=>({...t,[e]:!1})),i(r=>{if(!n)return{...r,[e]:t};let i=r[e]??``,a=i?i.split(`, `):[],o=a.indexOf(t);return o>=0?a.splice(o,1):a.push(t),{...r,[e]:a.join(`, `)}})},c=e=>{o(t=>({...t,[e]:!0})),i(t=>({...t,[e]:``}))},l=(e,t)=>{i(n=>({...n,[e]:t}))},u=n.every(e=>r[e.question]?.trim());return(0,G.jsxs)(`div`,{className:`rounded-lg border-2 border-accent/40 bg-accent/5 p-3 space-y-3`,children:[n.map((e,t)=>(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsxs)(`p`,{className:`text-sm text-text-primary font-medium`,children:[e.header?`${e.header}: `:``,e.question]}),e.multiSelect&&(0,G.jsx)(`p`,{className:`text-xs text-text-subtle`,children:`Select multiple`}),(0,G.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[e.options.map((t,n)=>(0,G.jsxs)(`button`,{onClick:()=>s(e.question,t.label,e.multiSelect),className:`text-left rounded px-2.5 py-1.5 text-xs border transition-colors ${!a[e.question]&&(r[e.question]??``).split(`, `).includes(t.label)?`border-accent bg-accent/20 text-text-primary`:`border-border bg-background text-text-secondary hover:bg-surface-elevated`}`,children:[(0,G.jsx)(`span`,{className:`font-medium`,children:t.label}),t.description&&(0,G.jsxs)(`span`,{className:`text-text-subtle ml-1.5`,children:[`— `,t.description]})]},n)),a[e.question]?(0,G.jsx)(`input`,{type:`text`,autoFocus:!0,placeholder:`Type your answer...`,value:r[e.question]??``,onChange:t=>l(e.question,t.target.value),className:`rounded px-2.5 py-1.5 text-xs border border-accent bg-accent/10 text-text-primary outline-none placeholder:text-text-subtle`}):(0,G.jsx)(`button`,{onClick:()=>c(e.question),className:`text-left rounded px-2.5 py-1.5 text-xs border border-dashed border-border text-text-subtle hover:bg-surface-elevated transition-colors`,children:`Other — type your own answer`})]})]},t)),(0,G.jsxs)(`div`,{className:`flex gap-2 pt-1`,children:[(0,G.jsx)(`button`,{onClick:()=>t(e.requestId,!0,r),disabled:!u,className:`px-4 py-1.5 rounded bg-accent text-white text-xs font-medium hover:bg-accent/80 transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,children:`Submit`}),(0,G.jsx)(`button`,{onClick:()=>t(e.requestId,!1),className:`px-4 py-1.5 rounded bg-surface-elevated text-text-secondary text-xs hover:bg-surface transition-colors`,children:`Skip`})]})]})}var ke=new Set([`image/png`,`image/jpeg`,`image/gif`,`image/webp`]),Ae=new Set([`application/pdf`]),je=[`text/`,`application/json`,`application/xml`,`application/javascript`,`application/typescript`,`application/x-yaml`,`application/toml`,`application/x-sh`],Me=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 Ne(e){return ke.has(e.type)}function Pe(e){if(ke.has(e.type)||Ae.has(e.type)||je.some(t=>e.type.startsWith(t)))return!0;let t=Fe(e.name);return!!(t&&Me.has(t))}function Fe(e){let t=e.lastIndexOf(`.`);return t===-1?``:e.slice(t).toLowerCase()}function Ie({attachments:e,onRemove:t}){return e.length===0?null:(0,G.jsx)(`div`,{className:`flex flex-wrap gap-1.5 px-3 pt-2`,children:e.map(e=>(0,G.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,G.jsx)(`img`,{src:e.previewUrl,alt:e.name,className:`size-5 rounded object-cover shrink-0`}):e.isImage?(0,G.jsx)(I,{className:`size-3.5 shrink-0 text-text-subtle`}):(0,G.jsx)(T,{className:`size-3.5 shrink-0 text-text-subtle`}),(0,G.jsx)(`span`,{className:`truncate`,children:e.name}),e.status===`uploading`?(0,G.jsx)(y,{className:`size-3 shrink-0 animate-spin text-text-subtle`}):e.status===`error`?(0,G.jsx)(`span`,{className:`text-red-500 shrink-0`,title:`Upload failed`,children:`!`}):null,(0,G.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,G.jsx)(d,{className:`size-3`})})]},e.id))})}function Le(e){let t=[];function n(e){for(let r of e)t.push(r),r.children&&n(r.children)}return n(e),t}function Re({items:e,filter:t,onSelect:n,onClose:r,visible:i}){let[a,o]=(0,V.useState)(0),s=(0,V.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,V.useEffect)(()=>{o(0)},[t]),(0,V.useEffect)(()=>{let e=s.current;e&&e.children[a]?.scrollIntoView({block:`nearest`})},[a]);let l=(0,V.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,V.useEffect)(()=>{if(!i)return;let e=e=>{l(e)};return document.addEventListener(`keydown`,e,!0),()=>document.removeEventListener(`keydown`,e,!0)},[i,l]),!i||c.length===0?null:(0,G.jsx)(`div`,{className:`max-h-52 overflow-y-auto border-b border-border bg-surface`,children:(0,G.jsx)(`div`,{ref:s,className:`py-1`,children:c.map((e,t)=>(0,G.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,G.jsx)(`span`,{className:`shrink-0`,children:e.type===`directory`?(0,G.jsx)(g,{className:`size-4 text-amber-500`}):(0,G.jsx)(w,{className:`size-4 text-blue-400`})}),(0,G.jsx)(`span`,{className:`text-sm truncate`,children:e.path})]},e.path))})})}function ze({onSend:e,isStreaming:t,onCancel:n,disabled:r,projectName:i,onSlashStateChange:a,onSlashItemsLoaded:o,slashSelected:s,onFileStateChange:c,onFileItemsLoaded:l,fileSelected:u,externalFiles:d}){let[g,_]=(0,V.useState)(``),[v,y]=(0,V.useState)([]),b=(0,V.useRef)(null),x=(0,V.useRef)(null),S=(0,V.useRef)([]),C=(0,V.useRef)([]);(0,V.useEffect)(()=>{if(!i){S.current=[],o?.([]);return}h.get(`${m(i)}/chat/slash-items`).then(e=>{S.current=e,o?.(e)}).catch(()=>{S.current=[],o?.([])})},[i]),(0,V.useEffect)(()=>{if(!i){C.current=[],l?.([]);return}h.get(`${m(i)}/files/tree?depth=5`).then(e=>{let t=Le(e);C.current=t,l?.(t)}).catch(()=>{C.current=[],l?.([])})},[i]),(0,V.useEffect)(()=>{if(!s)return;let e=b.current,t=e?.selectionStart??g.length,n=g.slice(0,t),r=g.slice(t),i=n.replace(/(?:^|\s)\/\S*$/,e=>`${e.startsWith(`/`)?``:e[0]}/${s.name} `);_(i+r),a?.(!1,``),c?.(!1,``),e&&(e.focus(),setTimeout(()=>{e.selectionStart=e.selectionEnd=i.length},0))},[s]),(0,V.useEffect)(()=>{if(!u)return;let e=b.current;if(!e)return;let t=e.selectionStart,n=g.slice(0,t),r=g.slice(t),i=n.match(/@(\S*)$/);if(i){let t=n.length-i[0].length;_(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=g+`@${u.path} `;_(t),setTimeout(()=>{e.selectionStart=e.selectionEnd=t.length,e.focus()},0)}c?.(!1,``)},[u]),(0,V.useEffect)(()=>{!d||d.length===0||T(d)},[d]);let w=(0,V.useCallback)(async e=>{if(!i)return null;try{let t=new FormData;t.append(`files`,e);let n={},r=p();r&&(n.Authorization=`Bearer ${r}`);let a=await(await fetch(`${m(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]),T=(0,V.useCallback)(e=>{for(let t of e){if(!Pe(t)){_(e=>e+(e.length>0&&!e.endsWith(` `)?` `:``)+t.name);continue}let e=f(),n=Ne(t),r=n?URL.createObjectURL(t):void 0,i={id:e,name:t.name,file:t,isImage:n,previewUrl:r,status:`uploading`};y(e=>[...e,i]),w(t).then(t=>{y(n=>n.map(n=>n.id===e?{...n,serverPath:t??void 0,status:t?`ready`:`error`}:n))})}b.current?.focus()},[w]),E=(0,V.useCallback)(e=>{y(t=>{let n=t.find(t=>t.id===e);return n?.previewUrl&&URL.revokeObjectURL(n.previewUrl),t.filter(t=>t.id!==e)})},[]),D=(0,V.useCallback)(()=>{let t=g.trim(),n=v.filter(e=>e.status===`ready`);if(!(!t&&n.length===0)&&!r){a?.(!1,``),c?.(!1,``),e(t,n),_(``);for(let e of v)e.previewUrl&&URL.revokeObjectURL(e.previewUrl);y([]),b.current&&(b.current.style.height=`auto`)}},[g,v,r,e,a,c]),O=(0,V.useCallback)(e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),D())},[D]),k=(0,V.useCallback)((e,t)=>{let n=e.slice(0,t),r=n.match(/(?:^|\s)\/(\S*)$/);if(r&&S.current.length>0){a?.(!0,r[1]??``),c?.(!1,``);return}let i=n.match(/@(\S*)$/);if(i&&C.current.length>0){c?.(!0,i[1]??``),a?.(!1,``);return}a?.(!1,``),c?.(!1,``)},[a,c]),A=(0,V.useCallback)(e=>{_(e),setTimeout(()=>{k(e,b.current?.selectionStart??e.length)},0)},[k]),ee=(0,V.useCallback)(()=>{let e=b.current;e&&(e.style.height=`auto`,e.style.height=Math.min(e.scrollHeight,160)+`px`)},[]),te=(0,V.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(),T(n))},[T]),j=(0,V.useCallback)(e=>{e.preventDefault();let t=Array.from(e.dataTransfer.files);t.length>0&&T(t)},[T]),ne=(0,V.useCallback)(e=>{e.preventDefault()},[]),M=(0,V.useCallback)(()=>{x.current?.click()},[]),N=(0,V.useCallback)(e=>{let t=Array.from(e.target.files??[]);t.length>0&&T(t),e.target.value=``},[T]),P=g.trim().length>0||v.some(e=>e.status===`ready`),F=t&&!P;return(0,G.jsxs)(`div`,{className:`border-t border-border bg-background`,children:[(0,G.jsx)(Ie,{attachments:v,onRemove:E}),(0,G.jsxs)(`div`,{className:`flex items-end gap-2 p-3`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:M,disabled:r,className:`flex items-center justify-center rounded-lg p-2 text-text-subtle hover:text-text-primary hover:bg-surface transition-colors shrink-0 disabled:opacity-50`,"aria-label":`Attach file`,children:(0,G.jsx)(L,{className:`size-4`})}),(0,G.jsx)(`input`,{ref:x,type:`file`,multiple:!0,className:`hidden`,onChange:N}),(0,G.jsx)(`textarea`,{ref:b,value:g,onChange:e=>{A(e.target.value),ee()},onKeyDown:O,onPaste:te,onDrop:j,onDragOver:ne,placeholder:t?`Follow-up or Stop...`:`Message... (↵ to send)`,disabled:r,rows:1,className:`flex-1 resize-none rounded-lg border border-border bg-surface px-3 py-2 text-base md:text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:border-ring disabled:opacity-50 max-h-40`}),F?(0,G.jsx)(`button`,{onClick:n,className:`flex items-center justify-center rounded-lg bg-red-600 p-2 text-white hover:bg-red-500 transition-colors shrink-0`,"aria-label":`Stop response`,children:(0,G.jsx)(B,{className:`size-4`})}):(0,G.jsx)(`button`,{onClick:D,disabled:r||!P,className:`flex items-center justify-center rounded-lg bg-primary p-2 text-white hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors shrink-0`,"aria-label":`Send message`,children:(0,G.jsx)(ie,{className:`size-4`})})]})]})}function Be({currentSessionId:e,onSelectSession:t,onNewSession:n,projectName:r}){let[i,a]=(0,V.useState)([]),[o,s]=(0,V.useState)(!1),[c,l]=(0,V.useState)(!1),d=(0,V.useCallback)(async()=>{if(r){l(!0);try{a(await h.get(`${m(r)}/chat/sessions`))}catch{}finally{l(!1)}}},[r]);(0,V.useEffect)(()=>{d()},[d]),(0,V.useEffect)(()=>{o&&d()},[o,d]);let f=i.find(t=>t.id===e),p=async(e,t)=>{e.stopPropagation();try{if(!r)return;await h.del(`${m(r)}/chat/sessions/${t.id}?providerId=${t.providerId}`),a(e=>e.filter(e=>e.id!==t.id))}catch{}};return(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsxs)(`button`,{onClick:()=>s(!o),className:`flex items-center gap-1.5 text-sm text-text-secondary hover:text-text-primary transition-colors px-2 py-1 rounded hover:bg-surface-elevated`,children:[(0,G.jsx)(b,{className:`size-3.5`}),(0,G.jsx)(`span`,{className:`truncate max-w-[150px]`,children:f?.title??`Select chat`}),(0,G.jsx)(E,{className:`size-3`})]}),o&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>s(!1)}),(0,G.jsxs)(`div`,{className:`absolute bottom-full left-0 mb-1 z-50 w-64 rounded-lg border border-border bg-surface shadow-lg overflow-hidden`,children:[(0,G.jsxs)(`button`,{onClick:()=>{n(),s(!1)},className:`flex items-center gap-2 w-full px-3 py-2 text-sm text-primary hover:bg-surface-elevated transition-colors border-b border-border`,children:[(0,G.jsx)(j,{className:`size-4`}),(0,G.jsx)(`span`,{children:`New Chat`})]}),(0,G.jsxs)(`div`,{className:`max-h-60 overflow-y-auto`,children:[c&&(0,G.jsx)(`p`,{className:`px-3 py-2 text-xs text-text-subtle animate-pulse`,children:`Loading sessions...`}),!c&&i.length===0&&(0,G.jsx)(`p`,{className:`px-3 py-2 text-xs text-text-subtle`,children:`No sessions yet`}),i.map(n=>(0,G.jsxs)(`div`,{onClick:()=>{t(n),s(!1)},className:`flex items-center justify-between px-3 py-2 text-sm cursor-pointer hover:bg-surface-elevated transition-colors ${n.id===e?`bg-surface-elevated text-text-primary`:`text-text-secondary`}`,children:[(0,G.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1`,children:[(0,G.jsx)(`span`,{className:`truncate text-xs font-medium`,children:n.title}),(0,G.jsx)(`span`,{className:`text-xs text-text-subtle`,children:new Date(n.createdAt).toLocaleDateString()})]}),(0,G.jsx)(`button`,{onClick:e=>p(e,n),className:`p-1 rounded hover:bg-red-500/20 text-text-subtle hover:text-red-400 transition-colors shrink-0`,"aria-label":`Delete session`,children:(0,G.jsx)(u,{className:`size-3`})})]},n.id))]})]})]})]})}function Ve({items:e,filter:t,onSelect:n,onClose:r,visible:i}){let[a,o]=(0,V.useState)(0),s=(0,V.useRef)(null),c=e.filter(e=>{let n=t.toLowerCase();return e.name.toLowerCase().includes(n)||e.description.toLowerCase().includes(n)});(0,V.useEffect)(()=>{o(0)},[t]),(0,V.useEffect)(()=>{let e=s.current;e&&e.children[a]?.scrollIntoView({block:`nearest`})},[a]);let l=(0,V.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,V.useEffect)(()=>{if(!i)return;let e=e=>{l(e)};return document.addEventListener(`keydown`,e,!0),()=>document.removeEventListener(`keydown`,e,!0)},[i,l]),!i||c.length===0?null:(0,G.jsx)(`div`,{className:`max-h-52 overflow-y-auto border-b border-border bg-surface`,children:(0,G.jsx)(`div`,{ref:s,className:`py-1`,children:c.map((e,t)=>(0,G.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,G.jsx)(`span`,{className:`shrink-0 mt-0.5`,children:e.type===`skill`?(0,G.jsx)(z,{className:`size-4 text-amber-500`}):(0,G.jsx)(D,{className:`size-4 text-blue-500`})}),(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,G.jsxs)(`span`,{className:`font-medium text-sm`,children:[`/`,e.name]}),e.argumentHint&&(0,G.jsx)(`span`,{className:`text-xs text-text-subtle`,children:e.argumentHint}),(0,G.jsx)(`span`,{className:`text-xs text-text-subtle capitalize ml-auto`,children:e.scope===`user`?`global`:e.type})]}),e.description&&(0,G.jsx)(`p`,{className:`text-xs text-text-subtle mt-0.5 line-clamp-2`,children:e.description})]})]},`${e.type}-${e.name}`))})})}function He(e){return e>=90?`text-red-500`:e>=70?`text-amber-500`:`text-green-500`}function Ue(e){return e>=90?`bg-red-500`:e>=70?`bg-amber-500`:`bg-green-500`}function We({usage:e,loading:t,onClick:n}){let r=e.fiveHour==null?null:Math.round(e.fiveHour*100),i=e.sevenDay==null?null:Math.round(e.sevenDay*100),a=r==null?`--%`:`${r}%`,o=i==null?`--%`:`${i}%`;return(0,G.jsxs)(`button`,{onClick:n,className:`flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] font-medium tabular-nums transition-colors hover:bg-surface-hover ${r!=null||i!=null?He(Math.max(r??0,i??0)):`text-text-subtle`}`,title:`Click for usage details`,children:[t?(0,G.jsx)(l,{className:`size-3 animate-spin`}):(0,G.jsx)(M,{className:`size-3`}),(0,G.jsxs)(`span`,{children:[`5h:`,a]}),(0,G.jsx)(`span`,{className:`text-text-subtle`,children:`·`}),(0,G.jsxs)(`span`,{children:[`Wk:`,o]})]})}function Ge(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 $({label:e,bucket:t}){if(!t)return null;let n=Math.round(t.utilization*100),r=Ge(t);return(0,G.jsxs)(`div`,{className:`space-y-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`span`,{className:`text-xs font-medium text-text-primary`,children:e}),r&&(0,G.jsxs)(`span`,{className:`text-[10px] text-text-subtle`,children:[`↻ `,r]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`div`,{className:`flex-1 h-2 rounded-full bg-border overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-full rounded-full transition-all ${Ue(n)}`,style:{width:`${Math.min(n,100)}%`}})}),(0,G.jsxs)(`span`,{className:`text-xs font-medium tabular-nums w-10 text-right ${He(n)}`,children:[n,`%`]})]})]})}function Ke(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 qe({usage:e,visible:t,onClose:n,onReload:r,loading:i,lastUpdatedAt:a}){if(!t)return null;let o=e.queryCostUsd!=null||e.totalCostUsd!=null,s=e.session||e.weekly||e.weeklyOpus||e.weeklySonnet;return(0,G.jsxs)(`div`,{className:`border-b border-border bg-surface px-3 py-2.5 space-y-2.5`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-xs font-semibold text-text-primary`,children:`Usage Limits`}),a&&(0,G.jsx)(`span`,{className:`text-[10px] text-text-subtle`,children:Ke(a)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[r&&(0,G.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,G.jsx)(l,{className:`size-3 ${i?`animate-spin`:``}`})}),(0,G.jsx)(`button`,{onClick:n,className:`text-xs text-text-subtle hover:text-text-primary px-1`,children:`✕`})]})]}),s?(0,G.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,G.jsx)($,{label:`5-Hour Session`,bucket:e.session}),(0,G.jsx)($,{label:`Weekly`,bucket:e.weekly}),(0,G.jsx)($,{label:`Weekly (Opus)`,bucket:e.weeklyOpus}),(0,G.jsx)($,{label:`Weekly (Sonnet)`,bucket:e.weeklySonnet})]}):(0,G.jsxs)(`p`,{className:`text-xs text-text-subtle`,children:[`No data — run `,(0,G.jsx)(`code`,{className:`bg-surface-elevated px-1 rounded`,children:`bun install`})]}),o&&(0,G.jsxs)(`div`,{className:`border-t border-border pt-2 space-y-1`,children:[e.queryCostUsd!=null&&(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,G.jsx)(`span`,{className:`text-text-subtle`,children:`Last query`}),(0,G.jsxs)(`span`,{className:`text-text-primary font-medium tabular-nums`,children:[`$`,e.queryCostUsd.toFixed(4)]})]}),e.totalCostUsd!=null&&(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,G.jsx)(`span`,{className:`text-text-subtle`,children:`Session total`}),(0,G.jsxs)(`span`,{className:`text-text-primary font-medium tabular-nums`,children:[`$`,e.totalCostUsd.toFixed(4)]})]})]})]})}function Je({metadata:e,tabId:t}){let[n,r]=(0,V.useState)(e?.sessionId??null),[i,a]=(0,V.useState)(e?.providerId??`claude-sdk`),[o,l]=(0,V.useState)([]),[u,f]=(0,V.useState)(!1),[p,g]=(0,V.useState)(``),[v,y]=(0,V.useState)(null),[b,x]=(0,V.useState)([]),[S,C]=(0,V.useState)(!1),[w,T]=(0,V.useState)(``),[E,D]=(0,V.useState)(null),[j,M]=(0,V.useState)(!1),[N,P]=(0,V.useState)(null),[F,I]=(0,V.useState)(!1),[re,L]=(0,V.useState)(!1),[ie,R]=(0,V.useState)(null),z=(0,V.useRef)(0),B=O(e=>e.activeProject),H=k(e=>e.updateTab),oe=ne(e=>e.version),{usageInfo:U,usageLoading:W,lastUpdatedAt:ce,refreshUsage:ue,mergeUsage:de}=le(B?.name??``,i);(0,V.useEffect)(()=>{!t||!n||H(t,{metadata:{...e,sessionId:n,providerId:i}})},[n,i]);let{messages:fe,messagesLoading:pe,isStreaming:K,pendingApproval:me,sendMessage:q,respondToApproval:J,cancelStreaming:he,reconnect:Y,refetchMessages:_e,isConnected:X}=se(n,i,B?.name??``,{onUsageEvent:de}),ve=(0,V.useCallback)(()=>{let e=B?.name??null;k.getState().openTab({type:`chat`,title:`AI Chat`,metadata:{projectName:e},projectId:e,closable:!0})},[B?.name]),Z=(0,V.useCallback)(e=>{r(e.id),a(e.providerId)},[]),Q=(0,V.useCallback)((e,t)=>{if(t.length===0)return e;let n=t.filter(e=>e.serverPath).map(e=>e.serverPath).join(`
6
- `);return n?(t.length===1?`[Attached file: ${n}]\n\n`:`[Attached files:\n${n}\n]\n\n`)+e:e},[]),ye=(0,V.useCallback)(async(t,o=[])=>{let s=Q(t,o);if(s.trim()){if(!n)try{let n=B?.name??e?.project??``,o=await h.post(`${m(n)}/chat/sessions`,{providerId:i,title:t.slice(0,50)});r(o.id),a(o.providerId),setTimeout(()=>{q(s)},500);return}catch(e){console.error(`Failed to create session:`,e);return}q(s)}},[n,i,e?.project,q,Q,B?.name]),be=(0,V.useCallback)((e,t)=>{f(e),g(t)},[]),xe=(0,V.useCallback)(e=>{y(e),f(!1),g(``),setTimeout(()=>y(null),50)},[]),Se=(0,V.useCallback)(()=>{f(!1),g(``)},[]),Ce=(0,V.useCallback)((e,t)=>{C(e),T(t)},[]),we=(0,V.useCallback)(e=>{D(e),C(!1),T(``),setTimeout(()=>D(null),50)},[]),Te=(0,V.useCallback)(()=>{C(!1),T(``)},[]);return(0,G.jsxs)(`div`,{className:`flex flex-col h-full relative`,onDragEnter:(0,V.useCallback)(e=>{e.preventDefault(),z.current++,e.dataTransfer.types.includes(`Files`)&&L(!0)},[]),onDragLeave:(0,V.useCallback)(e=>{e.preventDefault(),z.current--,z.current===0&&L(!1)},[]),onDragOver:(0,V.useCallback)(e=>{e.preventDefault()},[]),onDrop:(0,V.useCallback)(e=>{e.preventDefault(),z.current=0,L(!1);let t=Array.from(e.dataTransfer.files);t.length>0&&(R(t),setTimeout(()=>R(null),100))},[]),children:[re&&(0,G.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,G.jsxs)(`div`,{className:`flex flex-col items-center gap-2 text-primary`,children:[(0,G.jsx)(ae,{className:`size-8`}),(0,G.jsx)(`span`,{className:`text-sm font-medium`,children:`Drop files to attach`})]})}),(0,G.jsx)(ge,{messages:fe,messagesLoading:pe,pendingApproval:me,onApprovalResponse:J,isStreaming:K,projectName:B?.name}),(0,G.jsxs)(`div`,{className:`border-t border-border bg-background shrink-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-1.5 border-b border-border/50`,children:[(0,G.jsx)(Be,{currentSessionId:n,onSelectSession:Z,onNewSession:ve,projectName:B?.name}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(We,{usage:U,loading:W,onClick:()=>M(e=>!e)}),n&&(0,G.jsx)(`button`,{onClick:async()=>{P(await ee(oe,{sessionId:n,projectName:B?.name})),I(!1)},className:`p-0.5 rounded hover:bg-surface-elevated text-text-subtle hover:text-text-secondary transition-colors`,title:`Report bug for this chat session`,children:(0,G.jsx)(_,{className:`size-3.5`})}),(0,G.jsx)(`button`,{onClick:()=>{X||Y(),_e()},className:`group relative size-4 flex items-center justify-center rounded-full hover:bg-surface-hover transition-colors`,title:X?`Connected — click to refetch messages`:`Disconnected — click to reconnect`,children:(0,G.jsx)(`span`,{className:`size-2 rounded-full transition-colors ${X?`bg-green-500`:`bg-red-500 animate-pulse`}`})})]})]}),(0,G.jsx)(qe,{usage:U,visible:j,onClose:()=>M(!1),onReload:ue,loading:W,lastUpdatedAt:ce}),(0,G.jsx)(Ve,{items:o,filter:p,onSelect:xe,onClose:Se,visible:u}),(0,G.jsx)(Re,{items:b,filter:w,onSelect:we,onClose:Te,visible:S}),(0,G.jsx)(ze,{onSend:ye,isStreaming:K,onCancel:he,projectName:B?.name,onSlashStateChange:be,onSlashItemsLoaded:l,slashSelected:v,onFileStateChange:Ce,onFileItemsLoaded:x,fileSelected:E,externalFiles:ie})]}),N&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/50`,onClick:()=>P(null)}),(0,G.jsxs)(`div`,{className:`fixed inset-x-4 top-[10%] bottom-[10%] z-50 mx-auto max-w-lg flex flex-col rounded-lg border border-border bg-background shadow-xl`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b border-border`,children:[(0,G.jsx)(`span`,{className:`text-sm font-medium`,children:`Bug Report`}),(0,G.jsx)(`button`,{onClick:()=>P(null),className:`p-1 rounded hover:bg-surface-elevated`,children:(0,G.jsx)(d,{className:`size-4`})})]}),(0,G.jsx)(`pre`,{className:`flex-1 overflow-auto px-4 py-2 text-xs font-mono whitespace-pre-wrap break-all`,children:N}),(0,G.jsxs)(`div`,{className:`flex gap-2 px-4 py-3 border-t border-border`,children:[(0,G.jsxs)(`button`,{onClick:async()=>{await te(N)&&I(!0)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 text-sm rounded-lg bg-surface hover:bg-surface-elevated border border-border transition-colors`,children:[(0,G.jsx)(s,{className:`size-4`}),F?`Copied!`:`Copy`]}),(0,G.jsxs)(`button`,{onClick:()=>{A(N),P(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 text-sm rounded-lg bg-primary text-white hover:bg-primary/90 transition-colors`,children:[(0,G.jsx)(c,{className:`size-4`}),`GitHub Issue`]})]})]})]})]})}export{Je as ChatTab};
5
+ `).map(e=>e.trim()).filter(Boolean),text:e.slice(n[0].length)}:{files:[],text:e}}function Z(e,t){let n=e.split(`/`).pop()??``;return`/api/project/${encodeURIComponent(t??`_`)}/chat/uploads/${encodeURIComponent(n)}`}function Q(e){let t=e.lastIndexOf(`.`);return t===-1?!1:X.has(e.slice(t).toLowerCase())}function ye(e){return e.toLowerCase().endsWith(`.pdf`)}function be({content:e,projectName:t}){let{files:n,text:r}=(0,V.useMemo)(()=>ve(e),[e]);return(0,G.jsx)(`div`,{className:`flex justify-end`,children:(0,G.jsxs)(`div`,{className:`rounded-lg bg-primary/10 px-3 py-2 text-sm text-text-primary max-w-[85%] space-y-2`,children:[n.length>0&&(0,G.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:n.map((e,n)=>Q(e)?(0,G.jsx)(xe,{src:Z(e,t),alt:e.split(`/`).pop()??`image`},n):ye(e)?(0,G.jsx)(Se,{src:Z(e,t),filename:e.split(`/`).pop()??`document.pdf`,mimeType:`application/pdf`},n):(0,G.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,G.jsx)(T,{className:`size-3.5 shrink-0`}),(0,G.jsx)(`span`,{className:`truncate max-w-40`,children:e.split(`/`).pop()})]},n))}),r&&(0,G.jsx)(`p`,{className:`whitespace-pre-wrap break-words`,children:r})]})})}function xe({src:e,alt:t}){let[n,r]=(0,V.useState)(null),[i,a]=(0,V.useState)(!1);return(0,V.useEffect)(()=>{let t,n=f();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,G.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,G.jsx)(I,{className:`size-3.5 shrink-0`}),(0,G.jsx)(`span`,{className:`truncate max-w-40`,children:t})]}):n?(0,G.jsx)(`a`,{href:n,target:`_blank`,rel:`noopener noreferrer`,className:`block`,children:(0,G.jsx)(`img`,{src:n,alt:t,className:`rounded-md max-h-48 max-w-full object-contain border border-border`})}):(0,G.jsx)(`div`,{className:`rounded-md bg-surface border border-border h-24 w-32 animate-pulse`})}function Se({src:e,filename:t,mimeType:n}){let[r,i]=(0,V.useState)(!1);return(0,G.jsxs)(`button`,{type:`button`,onClick:(0,V.useCallback)(async()=>{i(!0);try{let t=f(),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,G.jsx)(T,{className:`size-3.5 shrink-0 text-red-400`}),(0,G.jsx)(`span`,{className:`truncate max-w-40`,children:t}),r&&(0,G.jsx)(`span`,{className:`animate-spin text-[10px]`,children:`...`})]})}function Ce({events:e,isStreaming:t,projectName:n}){let r=[],i=``;for(let t=0;t<e.length;t++){let n=e[t];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}))}i&&r.push({kind:`text`,content:i});let a=e.filter(e=>e.type===`tool_result`);for(let e of a){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,G.jsx)(G.Fragment,{children:r.map((e,i)=>{if(e.kind===`text`){let a=t&&i===r.length-1;return(0,G.jsx)(`div`,{className:`text-sm text-text-primary`,children:(0,G.jsx)(we,{content:e.content,animate:a,projectName:n})},`text-${i}`)}return(0,G.jsx)(de,{tool:e.tool,result:e.result,completed:e.completed,projectName:n},`tool-${i}`)})})}function we({content:e,animate:t,projectName:n}){return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Ee,{content:e,projectName:n}),t&&(0,G.jsx)(`span`,{className:`text-text-subtle text-sm animate-pulse`,children:`Thinking...`})]})}function Te({lastMessage:e}){if(!e||e.role!==`assistant`)return(0,G.jsx)(`div`,{className:`flex items-center gap-2 text-text-subtle text-sm`,children:(0,G.jsx)(`span`,{className:`animate-pulse`,children:`Thinking...`})});let t=e.events;if(t&&t.length>0){let e=t[t.length-1];if(e?.type===`tool_use`||e?.type===`tool_result`)return(0,G.jsx)(`div`,{className:`flex items-center gap-2 text-text-subtle text-sm`,children:(0,G.jsx)(`span`,{className:`animate-pulse`,children:`Thinking...`})})}return null}a.setOptions({gfm:!0,breaks:!0});function Ee({content:e,projectName:t}){let n=(0,V.useMemo)(()=>{try{return a.parse(e)}catch{return e}},[e]),r=(0,V.useRef)(null),{openTab:i}=k();return(0,V.useEffect)(()=>{let e=r.current;if(!e)return;e.querySelectorAll(`pre`).forEach(e=>{if(e.querySelector(`.code-actions`))return;let n=e.querySelector(`code`),r=n?.textContent??e.textContent??``,a=n?.className??``,o=/language-(bash|sh|shell|zsh)/.test(a)||!a.includes(`language-`)&&r.startsWith(`$`);e.style.position=`relative`;let s=document.createElement(`div`);s.className=`code-actions absolute top-1 right-1 flex gap-1 opacity-0 group-hover:opacity-100 transition-opacity`,e.classList.add(`group`);let c=document.createElement(`button`);if(c.className=`flex items-center justify-center size-6 rounded bg-surface-elevated/80 hover:bg-surface-elevated text-text-secondary hover:text-text-primary transition-colors border border-border/50`,c.title=`Copy`,c.innerHTML=`<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="14" height="14" x="8" y="8" rx="2" ry="2"/><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"/></svg>`,c.addEventListener(`click`,()=>{navigator.clipboard.writeText(r),c.innerHTML=`<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg>`,setTimeout(()=>{c.innerHTML=`<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="14" height="14" x="8" y="8" rx="2" ry="2"/><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"/></svg>`},2e3)}),s.appendChild(c),o){let e=document.createElement(`button`);e.className=`flex items-center justify-center size-6 rounded bg-surface-elevated/80 hover:bg-surface-elevated text-text-secondary hover:text-text-primary transition-colors border border-border/50`,e.title=`Run in terminal`,e.innerHTML=`<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="4 17 10 11 4 5"/><line x1="12" y1="19" x2="20" y2="19"/></svg>`,e.addEventListener(`click`,()=>{navigator.clipboard.writeText(r.replace(/^\$\s*/gm,``)),t&&i({type:`terminal`,title:`Terminal`,metadata:{projectName:t},projectId:t,closable:!0})}),s.appendChild(e)}e.appendChild(s)});let n=n=>{let r=n.target.closest(`a`);if(!r||!e.contains(r))return;let a=r.getAttribute(`href`)??``;(/^(\/|\.\/|\.\.\/)/.test(a)||/\.(ts|tsx|js|jsx|py|json|md|yaml|yml|toml|css|html|sh|go|rs|sql)$/i.test(a))&&t&&(n.preventDefault(),i({type:`editor`,title:a.split(`/`).pop()??a,metadata:{filePath:a,projectName:t},projectId:t,closable:!0}))};return e.addEventListener(`click`,n),()=>e.removeEventListener(`click`,n)},[n,t,i]),(0,G.jsx)(`div`,{ref:r,className:`markdown-content prose-sm`,dangerouslySetInnerHTML:{__html:n}})}function De({approval:e,onRespond:t}){return(0,G.jsxs)(`div`,{className:`rounded-lg border-2 border-yellow-500/40 bg-yellow-500/10 p-3 space-y-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-yellow-400 text-sm font-medium`,children:[(0,G.jsx)(R,{className:`size-4`}),(0,G.jsx)(`span`,{children:`Tool Approval Required`})]}),(0,G.jsx)(`div`,{className:`text-xs text-text-primary`,children:(0,G.jsx)(`span`,{className:`font-medium`,children:e.tool})}),(0,G.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,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.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,G.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 Oe({approval:e,onRespond:t}){let n=e.input.questions??[],[r,i]=(0,V.useState)({}),[a,o]=(0,V.useState)({}),s=(e,t,n)=>{o(t=>({...t,[e]:!1})),i(r=>{if(!n)return{...r,[e]:t};let i=r[e]??``,a=i?i.split(`, `):[],o=a.indexOf(t);return o>=0?a.splice(o,1):a.push(t),{...r,[e]:a.join(`, `)}})},c=e=>{o(t=>({...t,[e]:!0})),i(t=>({...t,[e]:``}))},l=(e,t)=>{i(n=>({...n,[e]:t}))},u=n.every(e=>r[e.question]?.trim());return(0,G.jsxs)(`div`,{className:`rounded-lg border-2 border-accent/40 bg-accent/5 p-3 space-y-3`,children:[n.map((e,t)=>(0,G.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,G.jsxs)(`p`,{className:`text-sm text-text-primary font-medium`,children:[e.header?`${e.header}: `:``,e.question]}),e.multiSelect&&(0,G.jsx)(`p`,{className:`text-xs text-text-subtle`,children:`Select multiple`}),(0,G.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[e.options.map((t,n)=>(0,G.jsxs)(`button`,{onClick:()=>s(e.question,t.label,e.multiSelect),className:`text-left rounded px-2.5 py-1.5 text-xs border transition-colors ${!a[e.question]&&(r[e.question]??``).split(`, `).includes(t.label)?`border-accent bg-accent/20 text-text-primary`:`border-border bg-background text-text-secondary hover:bg-surface-elevated`}`,children:[(0,G.jsx)(`span`,{className:`font-medium`,children:t.label}),t.description&&(0,G.jsxs)(`span`,{className:`text-text-subtle ml-1.5`,children:[`— `,t.description]})]},n)),a[e.question]?(0,G.jsx)(`input`,{type:`text`,autoFocus:!0,placeholder:`Type your answer...`,value:r[e.question]??``,onChange:t=>l(e.question,t.target.value),className:`rounded px-2.5 py-1.5 text-xs border border-accent bg-accent/10 text-text-primary outline-none placeholder:text-text-subtle`}):(0,G.jsx)(`button`,{onClick:()=>c(e.question),className:`text-left rounded px-2.5 py-1.5 text-xs border border-dashed border-border text-text-subtle hover:bg-surface-elevated transition-colors`,children:`Other — type your own answer`})]})]},t)),(0,G.jsxs)(`div`,{className:`flex gap-2 pt-1`,children:[(0,G.jsx)(`button`,{onClick:()=>t(e.requestId,!0,r),disabled:!u,className:`px-4 py-1.5 rounded bg-accent text-white text-xs font-medium hover:bg-accent/80 transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,children:`Submit`}),(0,G.jsx)(`button`,{onClick:()=>t(e.requestId,!1),className:`px-4 py-1.5 rounded bg-surface-elevated text-text-secondary text-xs hover:bg-surface transition-colors`,children:`Skip`})]})]})}var ke=new Set([`image/png`,`image/jpeg`,`image/gif`,`image/webp`]),Ae=new Set([`application/pdf`]),je=[`text/`,`application/json`,`application/xml`,`application/javascript`,`application/typescript`,`application/x-yaml`,`application/toml`,`application/x-sh`],Me=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 Ne(e){return ke.has(e.type)}function Pe(e){if(ke.has(e.type)||Ae.has(e.type)||je.some(t=>e.type.startsWith(t)))return!0;let t=Fe(e.name);return!!(t&&Me.has(t))}function Fe(e){let t=e.lastIndexOf(`.`);return t===-1?``:e.slice(t).toLowerCase()}function Ie({attachments:e,onRemove:t}){return e.length===0?null:(0,G.jsx)(`div`,{className:`flex flex-wrap gap-1.5 px-3 pt-2`,children:e.map(e=>(0,G.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,G.jsx)(`img`,{src:e.previewUrl,alt:e.name,className:`size-5 rounded object-cover shrink-0`}):e.isImage?(0,G.jsx)(I,{className:`size-3.5 shrink-0 text-text-subtle`}):(0,G.jsx)(T,{className:`size-3.5 shrink-0 text-text-subtle`}),(0,G.jsx)(`span`,{className:`truncate`,children:e.name}),e.status===`uploading`?(0,G.jsx)(y,{className:`size-3 shrink-0 animate-spin text-text-subtle`}):e.status===`error`?(0,G.jsx)(`span`,{className:`text-red-500 shrink-0`,title:`Upload failed`,children:`!`}):null,(0,G.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,G.jsx)(d,{className:`size-3`})})]},e.id))})}function Le(e){let t=[];function n(e){for(let r of e)t.push(r),r.children&&n(r.children)}return n(e),t}function Re({items:e,filter:t,onSelect:n,onClose:r,visible:i}){let[a,o]=(0,V.useState)(0),s=(0,V.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,V.useEffect)(()=>{o(0)},[t]),(0,V.useEffect)(()=>{let e=s.current;e&&e.children[a]?.scrollIntoView({block:`nearest`})},[a]);let l=(0,V.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,V.useEffect)(()=>{if(!i)return;let e=e=>{l(e)};return document.addEventListener(`keydown`,e,!0),()=>document.removeEventListener(`keydown`,e,!0)},[i,l]),!i||c.length===0?null:(0,G.jsx)(`div`,{className:`max-h-52 overflow-y-auto border-b border-border bg-surface`,children:(0,G.jsx)(`div`,{ref:s,className:`py-1`,children:c.map((e,t)=>(0,G.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,G.jsx)(`span`,{className:`shrink-0`,children:e.type===`directory`?(0,G.jsx)(g,{className:`size-4 text-amber-500`}):(0,G.jsx)(w,{className:`size-4 text-blue-400`})}),(0,G.jsx)(`span`,{className:`text-sm truncate`,children:e.path})]},e.path))})})}function ze({onSend:e,isStreaming:t,onCancel:n,disabled:r,projectName:i,onSlashStateChange:a,onSlashItemsLoaded:o,slashSelected:s,onFileStateChange:c,onFileItemsLoaded:l,fileSelected:u,externalFiles:d}){let[g,_]=(0,V.useState)(``),[v,y]=(0,V.useState)([]),b=(0,V.useRef)(null),x=(0,V.useRef)(null),S=(0,V.useRef)([]),C=(0,V.useRef)([]);(0,V.useEffect)(()=>{if(!i){S.current=[],o?.([]);return}m.get(`${p(i)}/chat/slash-items`).then(e=>{S.current=e,o?.(e)}).catch(()=>{S.current=[],o?.([])})},[i]),(0,V.useEffect)(()=>{if(!i){C.current=[],l?.([]);return}m.get(`${p(i)}/files/tree?depth=5`).then(e=>{let t=Le(e);C.current=t,l?.(t)}).catch(()=>{C.current=[],l?.([])})},[i]),(0,V.useEffect)(()=>{if(!s)return;let e=b.current,t=e?.selectionStart??g.length,n=g.slice(0,t),r=g.slice(t),i=n.replace(/(?:^|\s)\/\S*$/,e=>`${e.startsWith(`/`)?``:e[0]}/${s.name} `);_(i+r),a?.(!1,``),c?.(!1,``),e&&(e.focus(),setTimeout(()=>{e.selectionStart=e.selectionEnd=i.length},0))},[s]),(0,V.useEffect)(()=>{if(!u)return;let e=b.current;if(!e)return;let t=e.selectionStart,n=g.slice(0,t),r=g.slice(t),i=n.match(/@(\S*)$/);if(i){let t=n.length-i[0].length;_(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=g+`@${u.path} `;_(t),setTimeout(()=>{e.selectionStart=e.selectionEnd=t.length,e.focus()},0)}c?.(!1,``)},[u]),(0,V.useEffect)(()=>{!d||d.length===0||T(d)},[d]);let w=(0,V.useCallback)(async e=>{if(!i)return null;try{let t=new FormData;t.append(`files`,e);let n={},r=f();r&&(n.Authorization=`Bearer ${r}`);let a=await(await fetch(`${p(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]),T=(0,V.useCallback)(e=>{for(let t of e){if(!Pe(t)){_(e=>e+(e.length>0&&!e.endsWith(` `)?` `:``)+t.name);continue}let e=h(),n=Ne(t),r=n?URL.createObjectURL(t):void 0,i={id:e,name:t.name,file:t,isImage:n,previewUrl:r,status:`uploading`};y(e=>[...e,i]),w(t).then(t=>{y(n=>n.map(n=>n.id===e?{...n,serverPath:t??void 0,status:t?`ready`:`error`}:n))})}b.current?.focus()},[w]),E=(0,V.useCallback)(e=>{y(t=>{let n=t.find(t=>t.id===e);return n?.previewUrl&&URL.revokeObjectURL(n.previewUrl),t.filter(t=>t.id!==e)})},[]),D=(0,V.useCallback)(()=>{let t=g.trim(),n=v.filter(e=>e.status===`ready`);if(!(!t&&n.length===0)&&!r){a?.(!1,``),c?.(!1,``),e(t,n),_(``);for(let e of v)e.previewUrl&&URL.revokeObjectURL(e.previewUrl);y([]),b.current&&(b.current.style.height=`auto`)}},[g,v,r,e,a,c]),O=(0,V.useCallback)(e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),D())},[D]),k=(0,V.useCallback)((e,t)=>{let n=e.slice(0,t),r=n.match(/(?:^|\s)\/(\S*)$/);if(r&&S.current.length>0){a?.(!0,r[1]??``),c?.(!1,``);return}let i=n.match(/@(\S*)$/);if(i&&C.current.length>0){c?.(!0,i[1]??``),a?.(!1,``);return}a?.(!1,``),c?.(!1,``)},[a,c]),A=(0,V.useCallback)(e=>{_(e),setTimeout(()=>{k(e,b.current?.selectionStart??e.length)},0)},[k]),ee=(0,V.useCallback)(()=>{let e=b.current;e&&(e.style.height=`auto`,e.style.height=Math.min(e.scrollHeight,160)+`px`)},[]),te=(0,V.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(),T(n))},[T]),j=(0,V.useCallback)(e=>{e.preventDefault();let t=Array.from(e.dataTransfer.files);t.length>0&&T(t)},[T]),ne=(0,V.useCallback)(e=>{e.preventDefault()},[]),M=(0,V.useCallback)(()=>{x.current?.click()},[]),N=(0,V.useCallback)(e=>{let t=Array.from(e.target.files??[]);t.length>0&&T(t),e.target.value=``},[T]),P=g.trim().length>0||v.some(e=>e.status===`ready`),F=t&&!P;return(0,G.jsxs)(`div`,{className:`border-t border-border bg-background`,children:[(0,G.jsx)(Ie,{attachments:v,onRemove:E}),(0,G.jsxs)(`div`,{className:`flex items-end gap-2 p-3`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:M,disabled:r,className:`flex items-center justify-center rounded-lg p-2 text-text-subtle hover:text-text-primary hover:bg-surface transition-colors shrink-0 disabled:opacity-50`,"aria-label":`Attach file`,children:(0,G.jsx)(L,{className:`size-4`})}),(0,G.jsx)(`input`,{ref:x,type:`file`,multiple:!0,className:`hidden`,onChange:N}),(0,G.jsx)(`textarea`,{ref:b,value:g,onChange:e=>{A(e.target.value),ee()},onKeyDown:O,onPaste:te,onDrop:j,onDragOver:ne,placeholder:t?`Follow-up or Stop...`:`Message... (↵ to send)`,disabled:r,rows:1,className:`flex-1 resize-none rounded-lg border border-border bg-surface px-3 py-2 text-base md:text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:border-ring disabled:opacity-50 max-h-40`}),F?(0,G.jsx)(`button`,{onClick:n,className:`flex items-center justify-center rounded-lg bg-red-600 p-2 text-white hover:bg-red-500 transition-colors shrink-0`,"aria-label":`Stop response`,children:(0,G.jsx)(B,{className:`size-4`})}):(0,G.jsx)(`button`,{onClick:D,disabled:r||!P,className:`flex items-center justify-center rounded-lg bg-primary p-2 text-white hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors shrink-0`,"aria-label":`Send message`,children:(0,G.jsx)(ie,{className:`size-4`})})]})]})}function Be({currentSessionId:e,onSelectSession:t,onNewSession:n,projectName:r}){let[i,a]=(0,V.useState)([]),[o,s]=(0,V.useState)(!1),[c,l]=(0,V.useState)(!1),d=(0,V.useCallback)(async()=>{if(r){l(!0);try{a(await m.get(`${p(r)}/chat/sessions`))}catch{}finally{l(!1)}}},[r]);(0,V.useEffect)(()=>{d()},[d]),(0,V.useEffect)(()=>{o&&d()},[o,d]);let f=i.find(t=>t.id===e),h=async(e,t)=>{e.stopPropagation();try{if(!r)return;await m.del(`${p(r)}/chat/sessions/${t.id}?providerId=${t.providerId}`),a(e=>e.filter(e=>e.id!==t.id))}catch{}};return(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsxs)(`button`,{onClick:()=>s(!o),className:`flex items-center gap-1.5 text-sm text-text-secondary hover:text-text-primary transition-colors px-2 py-1 rounded hover:bg-surface-elevated`,children:[(0,G.jsx)(b,{className:`size-3.5`}),(0,G.jsx)(`span`,{className:`truncate max-w-[150px]`,children:f?.title??`Select chat`}),(0,G.jsx)(E,{className:`size-3`})]}),o&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 z-40`,onClick:()=>s(!1)}),(0,G.jsxs)(`div`,{className:`absolute bottom-full left-0 mb-1 z-50 w-64 rounded-lg border border-border bg-surface shadow-lg overflow-hidden`,children:[(0,G.jsxs)(`button`,{onClick:()=>{n(),s(!1)},className:`flex items-center gap-2 w-full px-3 py-2 text-sm text-primary hover:bg-surface-elevated transition-colors border-b border-border`,children:[(0,G.jsx)(j,{className:`size-4`}),(0,G.jsx)(`span`,{children:`New Chat`})]}),(0,G.jsxs)(`div`,{className:`max-h-60 overflow-y-auto`,children:[c&&(0,G.jsx)(`p`,{className:`px-3 py-2 text-xs text-text-subtle animate-pulse`,children:`Loading sessions...`}),!c&&i.length===0&&(0,G.jsx)(`p`,{className:`px-3 py-2 text-xs text-text-subtle`,children:`No sessions yet`}),i.map(n=>(0,G.jsxs)(`div`,{onClick:()=>{t(n),s(!1)},className:`flex items-center justify-between px-3 py-2 text-sm cursor-pointer hover:bg-surface-elevated transition-colors ${n.id===e?`bg-surface-elevated text-text-primary`:`text-text-secondary`}`,children:[(0,G.jsxs)(`div`,{className:`flex flex-col min-w-0 flex-1`,children:[(0,G.jsx)(`span`,{className:`truncate text-xs font-medium`,children:n.title}),(0,G.jsx)(`span`,{className:`text-xs text-text-subtle`,children:new Date(n.createdAt).toLocaleDateString()})]}),(0,G.jsx)(`button`,{onClick:e=>h(e,n),className:`p-1 rounded hover:bg-red-500/20 text-text-subtle hover:text-red-400 transition-colors shrink-0`,"aria-label":`Delete session`,children:(0,G.jsx)(u,{className:`size-3`})})]},n.id))]})]})]})]})}function Ve({items:e,filter:t,onSelect:n,onClose:r,visible:i}){let[a,o]=(0,V.useState)(0),s=(0,V.useRef)(null),c=e.filter(e=>{let n=t.toLowerCase();return e.name.toLowerCase().includes(n)||e.description.toLowerCase().includes(n)});(0,V.useEffect)(()=>{o(0)},[t]),(0,V.useEffect)(()=>{let e=s.current;e&&e.children[a]?.scrollIntoView({block:`nearest`})},[a]);let l=(0,V.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,V.useEffect)(()=>{if(!i)return;let e=e=>{l(e)};return document.addEventListener(`keydown`,e,!0),()=>document.removeEventListener(`keydown`,e,!0)},[i,l]),!i||c.length===0?null:(0,G.jsx)(`div`,{className:`max-h-52 overflow-y-auto border-b border-border bg-surface`,children:(0,G.jsx)(`div`,{ref:s,className:`py-1`,children:c.map((e,t)=>(0,G.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,G.jsx)(`span`,{className:`shrink-0 mt-0.5`,children:e.type===`skill`?(0,G.jsx)(z,{className:`size-4 text-amber-500`}):(0,G.jsx)(D,{className:`size-4 text-blue-500`})}),(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,G.jsxs)(`span`,{className:`font-medium text-sm`,children:[`/`,e.name]}),e.argumentHint&&(0,G.jsx)(`span`,{className:`text-xs text-text-subtle`,children:e.argumentHint}),(0,G.jsx)(`span`,{className:`text-xs text-text-subtle capitalize ml-auto`,children:e.scope===`user`?`global`:e.type})]}),e.description&&(0,G.jsx)(`p`,{className:`text-xs text-text-subtle mt-0.5 line-clamp-2`,children:e.description})]})]},`${e.type}-${e.name}`))})})}function He(e){return e>=90?`text-red-500`:e>=70?`text-amber-500`:`text-green-500`}function Ue(e){return e>=90?`bg-red-500`:e>=70?`bg-amber-500`:`bg-green-500`}function We({usage:e,loading:t,onClick:n}){let r=e.fiveHour==null?null:Math.round(e.fiveHour*100),i=e.sevenDay==null?null:Math.round(e.sevenDay*100),a=r==null?`--%`:`${r}%`,o=i==null?`--%`:`${i}%`;return(0,G.jsxs)(`button`,{onClick:n,className:`flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] font-medium tabular-nums transition-colors hover:bg-surface-hover ${r!=null||i!=null?He(Math.max(r??0,i??0)):`text-text-subtle`}`,title:`Click for usage details`,children:[t?(0,G.jsx)(l,{className:`size-3 animate-spin`}):(0,G.jsx)(M,{className:`size-3`}),(0,G.jsxs)(`span`,{children:[`5h:`,a]}),(0,G.jsx)(`span`,{className:`text-text-subtle`,children:`·`}),(0,G.jsxs)(`span`,{children:[`Wk:`,o]})]})}function Ge(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 $({label:e,bucket:t}){if(!t)return null;let n=Math.round(t.utilization*100),r=Ge(t);return(0,G.jsxs)(`div`,{className:`space-y-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsx)(`span`,{className:`text-xs font-medium text-text-primary`,children:e}),r&&(0,G.jsxs)(`span`,{className:`text-[10px] text-text-subtle`,children:[`↻ `,r]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`div`,{className:`flex-1 h-2 rounded-full bg-border overflow-hidden`,children:(0,G.jsx)(`div`,{className:`h-full rounded-full transition-all ${Ue(n)}`,style:{width:`${Math.min(n,100)}%`}})}),(0,G.jsxs)(`span`,{className:`text-xs font-medium tabular-nums w-10 text-right ${He(n)}`,children:[n,`%`]})]})]})}function Ke(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 qe({usage:e,visible:t,onClose:n,onReload:r,loading:i,lastUpdatedAt:a}){if(!t)return null;let o=e.queryCostUsd!=null||e.totalCostUsd!=null,s=e.session||e.weekly||e.weeklyOpus||e.weeklySonnet;return(0,G.jsxs)(`div`,{className:`border-b border-border bg-surface px-3 py-2.5 space-y-2.5`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-xs font-semibold text-text-primary`,children:`Usage Limits`}),a&&(0,G.jsx)(`span`,{className:`text-[10px] text-text-subtle`,children:Ke(a)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[r&&(0,G.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,G.jsx)(l,{className:`size-3 ${i?`animate-spin`:``}`})}),(0,G.jsx)(`button`,{onClick:n,className:`text-xs text-text-subtle hover:text-text-primary px-1`,children:`✕`})]})]}),s?(0,G.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,G.jsx)($,{label:`5-Hour Session`,bucket:e.session}),(0,G.jsx)($,{label:`Weekly`,bucket:e.weekly}),(0,G.jsx)($,{label:`Weekly (Opus)`,bucket:e.weeklyOpus}),(0,G.jsx)($,{label:`Weekly (Sonnet)`,bucket:e.weeklySonnet})]}):(0,G.jsxs)(`p`,{className:`text-xs text-text-subtle`,children:[`No data — run `,(0,G.jsx)(`code`,{className:`bg-surface-elevated px-1 rounded`,children:`bun install`})]}),o&&(0,G.jsxs)(`div`,{className:`border-t border-border pt-2 space-y-1`,children:[e.queryCostUsd!=null&&(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,G.jsx)(`span`,{className:`text-text-subtle`,children:`Last query`}),(0,G.jsxs)(`span`,{className:`text-text-primary font-medium tabular-nums`,children:[`$`,e.queryCostUsd.toFixed(4)]})]}),e.totalCostUsd!=null&&(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,G.jsx)(`span`,{className:`text-text-subtle`,children:`Session total`}),(0,G.jsxs)(`span`,{className:`text-text-primary font-medium tabular-nums`,children:[`$`,e.totalCostUsd.toFixed(4)]})]})]})]})}function Je({metadata:e,tabId:t}){let[n,r]=(0,V.useState)(e?.sessionId??null),[i,a]=(0,V.useState)(e?.providerId??`claude-sdk`),[o,l]=(0,V.useState)([]),[u,f]=(0,V.useState)(!1),[h,g]=(0,V.useState)(``),[v,y]=(0,V.useState)(null),[b,x]=(0,V.useState)([]),[S,C]=(0,V.useState)(!1),[w,T]=(0,V.useState)(``),[E,D]=(0,V.useState)(null),[j,M]=(0,V.useState)(!1),[N,P]=(0,V.useState)(null),[F,I]=(0,V.useState)(!1),[re,L]=(0,V.useState)(!1),[ie,R]=(0,V.useState)(null),z=(0,V.useRef)(0),B=O(e=>e.activeProject),H=k(e=>e.updateTab),oe=ne(e=>e.version),{usageInfo:U,usageLoading:W,lastUpdatedAt:ce,refreshUsage:ue,mergeUsage:de}=le(B?.name??``,i);(0,V.useEffect)(()=>{!t||!n||H(t,{metadata:{...e,sessionId:n,providerId:i}})},[n,i]);let{messages:fe,messagesLoading:pe,isStreaming:K,pendingApproval:me,sendMessage:q,respondToApproval:J,cancelStreaming:he,reconnect:Y,refetchMessages:_e,isConnected:X}=se(n,i,B?.name??``,{onUsageEvent:de}),ve=(0,V.useCallback)(()=>{let e=B?.name??null;k.getState().openTab({type:`chat`,title:`AI Chat`,metadata:{projectName:e},projectId:e,closable:!0})},[B?.name]),Z=(0,V.useCallback)(e=>{r(e.id),a(e.providerId)},[]),Q=(0,V.useCallback)((e,t)=>{if(t.length===0)return e;let n=t.filter(e=>e.serverPath).map(e=>e.serverPath).join(`
6
+ `);return n?(t.length===1?`[Attached file: ${n}]\n\n`:`[Attached files:\n${n}\n]\n\n`)+e:e},[]),ye=(0,V.useCallback)(async(t,o=[])=>{let s=Q(t,o);if(s.trim()){if(!n)try{let n=B?.name??e?.project??``,o=await m.post(`${p(n)}/chat/sessions`,{providerId:i,title:t.slice(0,50)});r(o.id),a(o.providerId),setTimeout(()=>{q(s)},500);return}catch(e){console.error(`Failed to create session:`,e);return}q(s)}},[n,i,e?.project,q,Q,B?.name]),be=(0,V.useCallback)((e,t)=>{f(e),g(t)},[]),xe=(0,V.useCallback)(e=>{y(e),f(!1),g(``),setTimeout(()=>y(null),50)},[]),Se=(0,V.useCallback)(()=>{f(!1),g(``)},[]),Ce=(0,V.useCallback)((e,t)=>{C(e),T(t)},[]),we=(0,V.useCallback)(e=>{D(e),C(!1),T(``),setTimeout(()=>D(null),50)},[]),Te=(0,V.useCallback)(()=>{C(!1),T(``)},[]);return(0,G.jsxs)(`div`,{className:`flex flex-col h-full relative`,onDragEnter:(0,V.useCallback)(e=>{e.preventDefault(),z.current++,e.dataTransfer.types.includes(`Files`)&&L(!0)},[]),onDragLeave:(0,V.useCallback)(e=>{e.preventDefault(),z.current--,z.current===0&&L(!1)},[]),onDragOver:(0,V.useCallback)(e=>{e.preventDefault()},[]),onDrop:(0,V.useCallback)(e=>{e.preventDefault(),z.current=0,L(!1);let t=Array.from(e.dataTransfer.files);t.length>0&&(R(t),setTimeout(()=>R(null),100))},[]),children:[re&&(0,G.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,G.jsxs)(`div`,{className:`flex flex-col items-center gap-2 text-primary`,children:[(0,G.jsx)(ae,{className:`size-8`}),(0,G.jsx)(`span`,{className:`text-sm font-medium`,children:`Drop files to attach`})]})}),(0,G.jsx)(ge,{messages:fe,messagesLoading:pe,pendingApproval:me,onApprovalResponse:J,isStreaming:K,projectName:B?.name}),(0,G.jsxs)(`div`,{className:`border-t border-border bg-background shrink-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-1.5 border-b border-border/50`,children:[(0,G.jsx)(Be,{currentSessionId:n,onSelectSession:Z,onNewSession:ve,projectName:B?.name}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(We,{usage:U,loading:W,onClick:()=>M(e=>!e)}),n&&(0,G.jsx)(`button`,{onClick:async()=>{P(await ee(oe,{sessionId:n,projectName:B?.name})),I(!1)},className:`p-0.5 rounded hover:bg-surface-elevated text-text-subtle hover:text-text-secondary transition-colors`,title:`Report bug for this chat session`,children:(0,G.jsx)(_,{className:`size-3.5`})}),(0,G.jsx)(`button`,{onClick:()=>{X||Y(),_e()},className:`group relative size-4 flex items-center justify-center rounded-full hover:bg-surface-hover transition-colors`,title:X?`Connected — click to refetch messages`:`Disconnected — click to reconnect`,children:(0,G.jsx)(`span`,{className:`size-2 rounded-full transition-colors ${X?`bg-green-500`:`bg-red-500 animate-pulse`}`})})]})]}),(0,G.jsx)(qe,{usage:U,visible:j,onClose:()=>M(!1),onReload:ue,loading:W,lastUpdatedAt:ce}),(0,G.jsx)(Ve,{items:o,filter:h,onSelect:xe,onClose:Se,visible:u}),(0,G.jsx)(Re,{items:b,filter:w,onSelect:we,onClose:Te,visible:S}),(0,G.jsx)(ze,{onSend:ye,isStreaming:K,onCancel:he,projectName:B?.name,onSlashStateChange:be,onSlashItemsLoaded:l,slashSelected:v,onFileStateChange:Ce,onFileItemsLoaded:x,fileSelected:E,externalFiles:ie})]}),N&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/50`,onClick:()=>P(null)}),(0,G.jsxs)(`div`,{className:`fixed inset-x-4 top-[10%] bottom-[10%] z-50 mx-auto max-w-lg flex flex-col rounded-lg border border-border bg-background shadow-xl`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b border-border`,children:[(0,G.jsx)(`span`,{className:`text-sm font-medium`,children:`Bug Report`}),(0,G.jsx)(`button`,{onClick:()=>P(null),className:`p-1 rounded hover:bg-surface-elevated`,children:(0,G.jsx)(d,{className:`size-4`})})]}),(0,G.jsx)(`pre`,{className:`flex-1 overflow-auto px-4 py-2 text-xs font-mono whitespace-pre-wrap break-all`,children:N}),(0,G.jsxs)(`div`,{className:`flex gap-2 px-4 py-3 border-t border-border`,children:[(0,G.jsxs)(`button`,{onClick:async()=>{await te(N)&&I(!0)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 text-sm rounded-lg bg-surface hover:bg-surface-elevated border border-border transition-colors`,children:[(0,G.jsx)(s,{className:`size-4`}),F?`Copied!`:`Copy`]}),(0,G.jsxs)(`button`,{onClick:()=>{A(N),P(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 text-sm rounded-lg bg-primary text-white hover:bg-primary/90 transition-colors`,children:[(0,G.jsx)(c,{className:`size-4`}),`GitHub Issue`]})]})]})]})]})}export{Je as ChatTab};
@@ -0,0 +1,2 @@
1
+ import{a as e,n as t,r as n,t as r}from"./jsx-runtime-BFALxl05.js";import{n as i,t as a}from"./marked.esm-Cv8mjgnt.js";import{t as o}from"./external-link-C6Y-D528.js";import{$ as s,A as c,B as l,C as u,D as d,E as f,F as p,G as m,H as h,J as g,K as ee,L as _,M as v,N as y,O as b,P as te,Q as x,R as S,S as C,T as w,U as T,V as E,W as D,X as O,Z as k,_ as ne,_t as A,a as re,b as j,c as ie,ct as ae,d as oe,dt as se,f as ce,ft as le,g as ue,gt as de,h as fe,ht as M,i as pe,it as me,j as he,l as ge,lt as _e,m as ve,mt as ye,n as be,nt as xe,o as Se,ot as Ce,p as we,pt as Te,q as Ee,r as De,rt as N,s as Oe,st as P,t as ke,tt as F,u as Ae,ut as je,v as Me,w as Ne,x as Pe,y as Fe,z as Ie}from"./dist-Ca3N8Xbh.js";import{n as Le,r as Re,t as ze}from"./api-client-DzH9zCD7.js";import{D as Be,f as Ve,x as He}from"./index-DbTCLiox.js";var Ue=t(`eye`,[[`path`,{d:`M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0`,key:`1nclc0`}],[`circle`,{cx:`12`,cy:`12`,r:`3`,key:`1v7zrd`}]]),We=t(`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`}]]),I=e(n());function Ge(){return Ge=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},Ge.apply(null,arguments)}function Ke(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}var qe=e=>{let{state:t}=e,n=t.doc.lineAt(t.selection.main.from),r=Qe(e.state,n.from);return r.line?Ye(e):r.block?Ze(e):!1};function Je(e,t){return({state:n,dispatch:r})=>{if(n.readOnly)return!1;let i=e(t,n);return i?(r(n.update(i)),!0):!1}}var Ye=Je(rt,0),Xe=Je(nt,0),Ze=Je((e,t)=>nt(e,t,tt(t)),0);function Qe(e,t){let n=e.languageDataAt(`commentTokens`,t,1);return n.length?n[0]:{}}var $e=50;function et(e,{open:t,close:n},r,i){let a=e.sliceDoc(r-$e,r),o=e.sliceDoc(i,i+$e),s=/\s*$/.exec(a)[0].length,c=/^\s*/.exec(o)[0].length,l=a.length-s;if(a.slice(l-t.length,l)==t&&o.slice(c,c+n.length)==n)return{open:{pos:r-s,margin:s&&1},close:{pos:i+c,margin:c&&1}};let u,d;i-r<=2*$e?u=d=e.sliceDoc(r,i):(u=e.sliceDoc(r,r+$e),d=e.sliceDoc(i-$e,i));let f=/^\s*/.exec(u)[0].length,p=/\s*$/.exec(d)[0].length,m=d.length-p-n.length;return u.slice(f,f+t.length)==t&&d.slice(m,m+n.length)==n?{open:{pos:r+f+t.length,margin:/\s/.test(u.charAt(f+t.length))?1:0},close:{pos:i-p-n.length,margin:/\s/.test(d.charAt(m-1))?1:0}}:null}function tt(e){let t=[];for(let n of e.selection.ranges){let r=e.doc.lineAt(n.from),i=n.to<=r.to?r:e.doc.lineAt(n.to);i.from>r.from&&i.from==n.to&&(i=n.to==r.to+1?r:e.doc.lineAt(n.to-1));let a=t.length-1;a>=0&&t[a].to>r.from?t[a].to=i.to:t.push({from:r.from+/^\s*/.exec(r.text)[0].length,to:i.to})}return t}function nt(e,t,n=t.selection.ranges){let r=n.map(e=>Qe(t,e.from).block);if(!r.every(e=>e))return null;let i=n.map((e,n)=>et(t,r[n],e.from,e.to));if(e!=2&&!i.every(e=>e))return{changes:t.changes(n.map((e,t)=>i[t]?[]:[{from:e.from,insert:r[t].open+` `},{from:e.to,insert:` `+r[t].close}]))};if(e!=1&&i.some(e=>e)){let e=[];for(let t=0,n;t<i.length;t++)if(n=i[t]){let i=r[t],{open:a,close:o}=n;e.push({from:a.pos-i.open.length,to:a.pos+a.margin},{from:o.pos-o.margin,to:o.pos+i.close.length})}return{changes:e}}return null}function rt(e,t,n=t.selection.ranges){let r=[],i=-1;ranges:for(let{from:e,to:a}of n){let n=r.length,o=1e9,s;for(let n=e;n<=a;){let c=t.doc.lineAt(n);if(s==null&&(s=Qe(t,c.from).line,!s))continue ranges;if(c.from>i&&(e==a||a>c.from)){i=c.from;let e=/^\s*/.exec(c.text)[0].length,t=e==c.length,n=c.text.slice(e,e+s.length)==s?e:-1;e<c.text.length&&e<o&&(o=e),r.push({line:c,comment:n,token:s,indent:e,empty:t,single:!1})}n=c.to+1}if(o<1e9)for(let e=n;e<r.length;e++)r[e].indent<r[e].line.text.length&&(r[e].indent=o);r.length==n+1&&(r[n].single=!0)}if(e!=2&&r.some(e=>e.comment<0&&(!e.empty||e.single))){let e=[];for(let{line:t,token:n,indent:i,empty:a,single:o}of r)(o||!a)&&e.push({from:t.from+i,insert:n+` `});let n=t.changes(e);return{changes:n,selection:t.selection.map(n,1)}}else if(e!=1&&r.some(e=>e.comment>=0)){let e=[];for(let{line:t,comment:n,token:i}of r)if(n>=0){let r=t.from+n,a=r+i.length;t.text[a-t.from]==` `&&a++,e.push({from:r,to:a})}return{changes:e}}return null}var it=O.define(),at=O.define(),ot=N.define(),st=N.define({combine(e){return Te(e,{minDepth:100,newGroupDelay:500,joinToEvent:(e,t)=>t},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(e,t)=>(n,r)=>e(n,r)||t(n,r)})}}),ct=ae.define({create(){return Tt.empty},update(e,t){let n=t.state.facet(st),r=t.annotation(it);if(r){let i=L.fromTransaction(t,r.selection),a=r.side,o=a==0?e.undone:e.done;return o=i?ht(o,o.length,n.minDepth,i):bt(o,t.startState.selection),new Tt(a==0?r.rest:o,a==0?o:r.rest)}let i=t.annotation(at);if((i==`full`||i==`before`)&&(e=e.isolate()),t.annotation(je.addToHistory)===!1)return t.changes.empty?e:e.addMapping(t.changes.desc);let a=L.fromTransaction(t),o=t.annotation(je.time),s=t.annotation(je.userEvent);return a?e=e.addChanges(a,o,s,n,t):t.selection&&(e=e.addSelection(t.startState.selection,o,s,n.newGroupDelay)),(i==`full`||i==`after`)&&(e=e.isolate()),e},toJSON(e){return{done:e.done.map(e=>e.toJSON()),undone:e.undone.map(e=>e.toJSON())}},fromJSON(e){return new Tt(e.done.map(L.fromJSON),e.undone.map(L.fromJSON))}});function lt(e={}){return[ct,st.of(e),b.domEventHandlers({beforeinput(e,t){let n=e.inputType==`historyUndo`?dt:e.inputType==`historyRedo`?ft:null;return n?(e.preventDefault(),n(t)):!1}})]}function ut(e,t){return function({state:n,dispatch:r}){if(!t&&n.readOnly)return!1;let i=n.field(ct,!1);if(!i)return!1;let a=i.pop(e,n,t);return a?(r(a),!0):!1}}var dt=ut(0,!1),ft=ut(1,!1),pt=ut(0,!0),mt=ut(1,!0),L=class e{constructor(e,t,n,r,i){this.changes=e,this.effects=t,this.mapped=n,this.startSelection=r,this.selectionsAfter=i}setSelAfter(t){return new e(this.changes,this.effects,this.mapped,this.startSelection,t)}toJSON(){return{changes:this.changes?.toJSON(),mapped:this.mapped?.toJSON(),startSelection:this.startSelection?.toJSON(),selectionsAfter:this.selectionsAfter.map(e=>e.toJSON())}}static fromJSON(t){return new e(t.changes&&x.fromJSON(t.changes),[],t.mapped&&k.fromJSON(t.mapped),t.startSelection&&F.fromJSON(t.startSelection),t.selectionsAfter.map(F.fromJSON))}static fromTransaction(t,n){let r=R;for(let e of t.startState.facet(ot)){let n=e(t);n.length&&(r=r.concat(n))}return!r.length&&t.changes.empty?null:new e(t.changes.invert(t.startState.doc),r,void 0,n||t.startState.selection,R)}static selection(t){return new e(void 0,R,void 0,void 0,t)}};function ht(e,t,n,r){let i=t+1>n+20?t-n-1:0,a=e.slice(i,t);return a.push(r),a}function gt(e,t){let n=[],r=!1;return e.iterChangedRanges((e,t)=>n.push(e,t)),t.iterChangedRanges((e,t,i,a)=>{for(let e=0;e<n.length;){let t=n[e++],o=n[e++];a>=t&&i<=o&&(r=!0)}}),r}function _t(e,t){return e.ranges.length==t.ranges.length&&e.ranges.filter((e,n)=>e.empty!=t.ranges[n].empty).length===0}function vt(e,t){return e.length?t.length?e.concat(t):e:t}var R=[],yt=200;function bt(e,t){if(e.length){let n=e[e.length-1],r=n.selectionsAfter.slice(Math.max(0,n.selectionsAfter.length-yt));return r.length&&r[r.length-1].eq(t)?e:(r.push(t),ht(e,e.length-1,1e9,n.setSelAfter(r)))}else return[L.selection([t])]}function xt(e){let t=e[e.length-1],n=e.slice();return n[e.length-1]=t.setSelAfter(t.selectionsAfter.slice(0,t.selectionsAfter.length-1)),n}function St(e,t){if(!e.length)return e;let n=e.length,r=R;for(;n;){let i=Ct(e[n-1],t,r);if(i.changes&&!i.changes.empty||i.effects.length){let t=e.slice(0,n);return t[n-1]=i,t}else t=i.mapped,n--,r=i.selectionsAfter}return r.length?[L.selection(r)]:R}function Ct(e,t,n){let r=vt(e.selectionsAfter.length?e.selectionsAfter.map(e=>e.map(t)):R,n);if(!e.changes)return L.selection(r);let i=e.changes.map(t),a=t.mapDesc(e.changes,!0),o=e.mapped?e.mapped.composeDesc(a):a;return new L(i,P.mapEffects(e.effects,t),o,e.startSelection.map(a),r)}var wt=/^(input\.type|delete)($|\.)/,Tt=class e{constructor(e,t,n=0,r=void 0){this.done=e,this.undone=t,this.prevTime=n,this.prevUserEvent=r}isolate(){return this.prevTime?new e(this.done,this.undone):this}addChanges(t,n,r,i,a){let o=this.done,s=o[o.length-1];return o=s&&s.changes&&!s.changes.empty&&t.changes&&(!r||wt.test(r))&&(!s.selectionsAfter.length&&n-this.prevTime<i.newGroupDelay&&i.joinToEvent(a,gt(s.changes,t.changes))||r==`input.type.compose`)?ht(o,o.length-1,i.minDepth,new L(t.changes.compose(s.changes),vt(P.mapEffects(t.effects,s.changes),s.effects),s.mapped,s.startSelection,R)):ht(o,o.length,i.minDepth,t),new e(o,R,n,r)}addSelection(t,n,r,i){let a=this.done.length?this.done[this.done.length-1].selectionsAfter:R;return a.length>0&&n-this.prevTime<i&&r==this.prevUserEvent&&r&&/^select($|\.)/.test(r)&&_t(a[a.length-1],t)?this:new e(bt(this.done,t),this.undone,n,r)}addMapping(t){return new e(St(this.done,t),St(this.undone,t),this.prevTime,this.prevUserEvent)}pop(e,t,n){let r=e==0?this.done:this.undone;if(r.length==0)return null;let i=r[r.length-1],a=i.selectionsAfter[0]||(i.startSelection?i.startSelection.map(i.changes.invertedDesc,1):t.selection);if(n&&i.selectionsAfter.length)return t.update({selection:i.selectionsAfter[i.selectionsAfter.length-1],annotations:it.of({side:e,rest:xt(r),selection:a}),userEvent:e==0?`select.undo`:`select.redo`,scrollIntoView:!0});if(i.changes){let n=r.length==1?R:r.slice(0,r.length-1);return i.mapped&&(n=St(n,i.mapped)),t.update({changes:i.changes,selection:i.startSelection,effects:i.effects,annotations:it.of({side:e,rest:n,selection:a}),filter:!1,userEvent:e==0?`undo`:`redo`,scrollIntoView:!0})}else return null}};Tt.empty=new Tt(R,R);var Et=[{key:`Mod-z`,run:dt,preventDefault:!0},{key:`Mod-y`,mac:`Mod-Shift-z`,run:ft,preventDefault:!0},{linux:`Ctrl-Shift-z`,run:ft,preventDefault:!0},{key:`Mod-u`,run:pt,preventDefault:!0},{key:`Alt-u`,mac:`Mod-Shift-u`,run:mt,preventDefault:!0}];function z(e,t){return F.create(e.ranges.map(t),e.mainIndex)}function B(e,t){return e.update({selection:t,scrollIntoView:!0,userEvent:`select`})}function V({state:e,dispatch:t},n){let r=z(e.selection,n);return r.eq(e.selection,!0)?!1:(t(B(e,r)),!0)}function Dt(e,t){return F.cursor(t?e.to:e.from)}function Ot(e,t){return V(e,n=>n.empty?e.moveByChar(n,t):Dt(n,t))}function H(e){return e.textDirectionAt(e.state.selection.main.head)==d.LTR}var kt=e=>Ot(e,!H(e)),At=e=>Ot(e,H(e));function jt(e,t){return V(e,n=>n.empty?e.moveByGroup(n,t):Dt(n,t))}var Mt=e=>jt(e,!H(e)),Nt=e=>jt(e,H(e));typeof Intl<`u`&&Intl.Segmenter&&new Intl.Segmenter(void 0,{granularity:`word`});function Pt(e,t,n){if(t.type.prop(n))return!0;let r=t.to-t.from;return r&&(r>2||/[^\s,.;:]/.test(e.sliceDoc(t.from,t.to)))||t.firstChild}function Ft(e,t,n){let r=Ne(e).resolveInner(t.head),i=n?w.closedBy:w.openedBy;for(let a=t.head;;){let t=n?r.childAfter(a):r.childBefore(a);if(!t)break;Pt(e,t,i)?r=t:a=n?t.to:t.from}let a=r.type.prop(i),o,s;return s=a&&(o=n?C(e,r.from,1):C(e,r.to,-1))&&o.matched?n?o.end.to:o.end.from:n?r.to:r.from,F.cursor(s,n?-1:1)}var It=e=>V(e,t=>Ft(e.state,t,!H(e))),Lt=e=>V(e,t=>Ft(e.state,t,H(e)));function Rt(e,t){return V(e,n=>{if(!n.empty)return Dt(n,t);let r=e.moveVertically(n,t);return r.head==n.head?e.moveToLineBoundary(n,t):r})}var zt=e=>Rt(e,!1),Bt=e=>Rt(e,!0);function Vt(e){let t=e.scrollDOM.clientHeight<e.scrollDOM.scrollHeight-2,n=0,r=0,i;if(t){for(let t of e.state.facet(b.scrollMargins)){let i=t(e);i?.top&&(n=Math.max(i?.top,n)),i?.bottom&&(r=Math.max(i?.bottom,r))}i=e.scrollDOM.clientHeight-n-r}else i=(e.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:n,marginBottom:r,selfScroll:t,height:Math.max(e.defaultLineHeight,i-5)}}function Ht(e,t){let n=Vt(e),{state:r}=e,i=z(r.selection,r=>r.empty?e.moveVertically(r,t,n.height):Dt(r,t));if(i.eq(r.selection))return!1;let a;if(n.selfScroll){let t=e.coordsAtPos(r.selection.main.head),o=e.scrollDOM.getBoundingClientRect(),s=o.top+n.marginTop,c=o.bottom-n.marginBottom;t&&t.top>s&&t.bottom<c&&(a=b.scrollIntoView(i.main.head,{y:`start`,yMargin:t.top-s}))}return e.dispatch(B(r,i),{effects:a}),!0}var Ut=e=>Ht(e,!1),Wt=e=>Ht(e,!0);function U(e,t,n){let r=e.lineBlockAt(t.head),i=e.moveToLineBoundary(t,n);if(i.head==t.head&&i.head!=(n?r.to:r.from)&&(i=e.moveToLineBoundary(t,n,!1)),!n&&i.head==r.from&&r.length){let n=/^\s*/.exec(e.state.sliceDoc(r.from,Math.min(r.from+100,r.to)))[0].length;n&&t.head!=r.from+n&&(i=F.cursor(r.from+n))}return i}var Gt=e=>V(e,t=>U(e,t,!0)),Kt=e=>V(e,t=>U(e,t,!1)),qt=e=>V(e,t=>U(e,t,!H(e))),Jt=e=>V(e,t=>U(e,t,H(e))),Yt=e=>V(e,t=>F.cursor(e.lineBlockAt(t.head).from,1)),Xt=e=>V(e,t=>F.cursor(e.lineBlockAt(t.head).to,-1));function Zt(e,t,n){let r=!1,i=z(e.selection,t=>{let i=C(e,t.head,-1)||C(e,t.head,1)||t.head>0&&C(e,t.head-1,1)||t.head<e.doc.length&&C(e,t.head+1,-1);if(!i||!i.end)return t;r=!0;let a=i.start.from==t.head?i.end.to:i.end.from;return n?F.range(t.anchor,a):F.cursor(a)});return r?(t(B(e,i)),!0):!1}var Qt=({state:e,dispatch:t})=>Zt(e,t,!1);function W(e,t){let n=z(e.state.selection,e=>{let n=t(e);return F.range(e.anchor,n.head,n.goalColumn,n.bidiLevel||void 0,n.assoc)});return n.eq(e.state.selection)?!1:(e.dispatch(B(e.state,n)),!0)}function $t(e,t){return W(e,n=>e.moveByChar(n,t))}var en=e=>$t(e,!H(e)),tn=e=>$t(e,H(e));function nn(e,t){return W(e,n=>e.moveByGroup(n,t))}var rn=e=>nn(e,!H(e)),an=e=>nn(e,H(e)),on=e=>W(e,t=>Ft(e.state,t,!H(e))),sn=e=>W(e,t=>Ft(e.state,t,H(e)));function cn(e,t){return W(e,n=>e.moveVertically(n,t))}var ln=e=>cn(e,!1),un=e=>cn(e,!0);function dn(e,t){return W(e,n=>e.moveVertically(n,t,Vt(e).height))}var fn=e=>dn(e,!1),pn=e=>dn(e,!0),mn=e=>W(e,t=>U(e,t,!0)),hn=e=>W(e,t=>U(e,t,!1)),gn=e=>W(e,t=>U(e,t,!H(e))),_n=e=>W(e,t=>U(e,t,H(e))),vn=e=>W(e,t=>F.cursor(e.lineBlockAt(t.head).from)),yn=e=>W(e,t=>F.cursor(e.lineBlockAt(t.head).to)),bn=({state:e,dispatch:t})=>(t(B(e,{anchor:0})),!0),xn=({state:e,dispatch:t})=>(t(B(e,{anchor:e.doc.length})),!0),Sn=({state:e,dispatch:t})=>(t(B(e,{anchor:e.selection.main.anchor,head:0})),!0),Cn=({state:e,dispatch:t})=>(t(B(e,{anchor:e.selection.main.anchor,head:e.doc.length})),!0),wn=({state:e,dispatch:t})=>(t(e.update({selection:{anchor:0,head:e.doc.length},userEvent:`select`})),!0),Tn=({state:e,dispatch:t})=>{let n=Wn(e).map(({from:t,to:n})=>F.range(t,Math.min(n+1,e.doc.length)));return t(e.update({selection:F.create(n),userEvent:`select`})),!0},En=({state:e,dispatch:t})=>{let n=z(e.selection,t=>{let n=Ne(e),r=n.resolveStack(t.from,1);if(t.empty){let e=n.resolveStack(t.from,-1);e.node.from>=r.node.from&&e.node.to<=r.node.to&&(r=e)}for(let e=r;e;e=e.next){let{node:n}=e;if((n.from<t.from&&n.to>=t.to||n.to>t.to&&n.from<=t.from)&&e.next)return F.range(n.to,n.from)}return t});return n.eq(e.selection)?!1:(t(B(e,n)),!0)};function Dn(e,t){let{state:n}=e,r=n.selection,i=n.selection.ranges.slice();for(let r of n.selection.ranges){let a=n.doc.lineAt(r.head);if(t?a.to<e.state.doc.length:a.from>0)for(let n=r;;){let r=e.moveVertically(n,t);if(r.head<a.from||r.head>a.to){i.some(e=>e.head==r.head)||i.push(r);break}else if(r.head==n.head)break;else n=r}}return i.length==r.ranges.length?!1:(e.dispatch(B(n,F.create(i,i.length-1))),!0)}var On=e=>Dn(e,!1),kn=e=>Dn(e,!0),An=({state:e,dispatch:t})=>{let n=e.selection,r=null;return n.ranges.length>1?r=F.create([n.main]):n.main.empty||(r=F.create([F.cursor(n.main.head)])),r?(t(B(e,r)),!0):!1};function jn(e,t){if(e.state.readOnly)return!1;let n=`delete.selection`,{state:r}=e,i=r.changeByRange(r=>{let{from:i,to:a}=r;if(i==a){let o=t(r);o<i?(n=`delete.backward`,o=Mn(e,o,!1)):o>i&&(n=`delete.forward`,o=Mn(e,o,!0)),i=Math.min(i,o),a=Math.max(a,o)}else i=Mn(e,i,!1),a=Mn(e,a,!0);return i==a?{range:r}:{changes:{from:i,to:a},range:F.cursor(i,i<r.head?-1:1)}});return i.changes.empty?!1:(e.dispatch(r.update(i,{scrollIntoView:!0,userEvent:n,effects:n==`delete.selection`?b.announce.of(r.phrase(`Selection deleted`)):void 0})),!0)}function Mn(e,t,n){if(e instanceof b)for(let r of e.state.facet(b.atomicRanges).map(t=>t(e)))r.between(t,t,(e,r)=>{e<t&&r>t&&(t=n?r:e)});return t}var Nn=(e,t,n)=>jn(e,r=>{let i=r.from,{state:a}=e,o=a.doc.lineAt(i),s,c;if(n&&!t&&i>o.from&&i<o.from+200&&!/[^ \t]/.test(s=o.text.slice(0,i-o.from))){if(s[s.length-1]==` `)return i-1;let e=ye(s,a.tabSize)%ne(a)||ne(a);for(let t=0;t<e&&s[s.length-1-t]==` `;t++)i--;c=i}else c=M(o.text,i-o.from,t,t)+o.from,c==i&&o.number!=(t?a.doc.lines:1)?c+=t?1:-1:!t&&/[\ufe00-\ufe0f]/.test(o.text.slice(c-o.from,i-o.from))&&(c=M(o.text,c-o.from,!1,!1)+o.from);return c}),Pn=e=>Nn(e,!1,!0),Fn=e=>Nn(e,!0,!1),In=(e,t)=>jn(e,n=>{let r=n.head,{state:i}=e,a=i.doc.lineAt(r),o=i.charCategorizer(r);for(let e=null;;){if(r==(t?a.to:a.from)){r==n.head&&a.number!=(t?i.doc.lines:1)&&(r+=t?1:-1);break}let s=M(a.text,r-a.from,t)+a.from,c=a.text.slice(Math.min(r,s)-a.from,Math.max(r,s)-a.from),l=o(c);if(e!=null&&l!=e)break;(c!=` `||r!=n.head)&&(e=l),r=s}return r}),Ln=e=>In(e,!1),Rn=e=>In(e,!0),zn=e=>jn(e,t=>{let n=e.lineBlockAt(t.head).to;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}),Bn=e=>jn(e,t=>{let n=e.moveToLineBoundary(t,!1).head;return t.head>n?n:Math.max(0,t.head-1)}),Vn=e=>jn(e,t=>{let n=e.moveToLineBoundary(t,!0).head;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}),Hn=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(e=>({changes:{from:e.from,to:e.to,insert:_e.of([``,``])},range:F.cursor(e.from)}));return t(e.update(n,{scrollIntoView:!0,userEvent:`input`})),!0},Un=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(t=>{if(!t.empty||t.from==0||t.from==e.doc.length)return{range:t};let n=t.from,r=e.doc.lineAt(n),i=n==r.from?n-1:M(r.text,n-r.from,!1)+r.from,a=n==r.to?n+1:M(r.text,n-r.from,!0)+r.from;return{changes:{from:i,to:a,insert:e.doc.slice(n,a).append(e.doc.slice(i,n))},range:F.cursor(a)}});return n.changes.empty?!1:(t(e.update(n,{scrollIntoView:!0,userEvent:`move.character`})),!0)};function Wn(e){let t=[],n=-1;for(let r of e.selection.ranges){let i=e.doc.lineAt(r.from),a=e.doc.lineAt(r.to);if(!r.empty&&r.to==a.from&&(a=e.doc.lineAt(r.to-1)),n>=i.number){let e=t[t.length-1];e.to=a.to,e.ranges.push(r)}else t.push({from:i.from,to:a.to,ranges:[r]});n=a.number+1}return t}function Gn(e,t,n){if(e.readOnly)return!1;let r=[],i=[];for(let t of Wn(e)){if(n?t.to==e.doc.length:t.from==0)continue;let a=e.doc.lineAt(n?t.to+1:t.from-1),o=a.length+1;if(n){r.push({from:t.to,to:a.to},{from:t.from,insert:a.text+e.lineBreak});for(let n of t.ranges)i.push(F.range(Math.min(e.doc.length,n.anchor+o),Math.min(e.doc.length,n.head+o)))}else{r.push({from:a.from,to:t.from},{from:t.to,insert:e.lineBreak+a.text});for(let e of t.ranges)i.push(F.range(e.anchor-o,e.head-o))}}return r.length?(t(e.update({changes:r,scrollIntoView:!0,selection:F.create(i,e.selection.mainIndex),userEvent:`move.line`})),!0):!1}var Kn=({state:e,dispatch:t})=>Gn(e,t,!1),qn=({state:e,dispatch:t})=>Gn(e,t,!0);function Jn(e,t,n){if(e.readOnly)return!1;let r=[];for(let t of Wn(e))n?r.push({from:t.from,insert:e.doc.slice(t.from,t.to)+e.lineBreak}):r.push({from:t.to,insert:e.lineBreak+e.doc.slice(t.from,t.to)});let i=e.changes(r);return t(e.update({changes:i,selection:e.selection.map(i,n?1:-1),scrollIntoView:!0,userEvent:`input.copyline`})),!0}var Yn=({state:e,dispatch:t})=>Jn(e,t,!1),Xn=({state:e,dispatch:t})=>Jn(e,t,!0),Zn=e=>{if(e.state.readOnly)return!1;let{state:t}=e,n=t.changes(Wn(t).map(({from:e,to:n})=>(e>0?e--:n<t.doc.length&&n++,{from:e,to:n}))),r=z(t.selection,t=>{let n;if(e.lineWrapping){let r=e.lineBlockAt(t.head),i=e.coordsAtPos(t.head,t.assoc||1);i&&(n=r.bottom+e.documentTop-i.bottom+e.defaultLineHeight/2)}return e.moveVertically(t,!0,n)}).map(n);return e.dispatch({changes:n,selection:r,scrollIntoView:!0,userEvent:`delete.line`}),!0};function Qn(e,t){if(/\(\)|\[\]|\{\}/.test(e.sliceDoc(t-1,t+1)))return{from:t,to:t};let n=Ne(e).resolveInner(t),r=n.childBefore(t),i=n.childAfter(t),a;return r&&i&&r.to<=t&&i.from>=t&&(a=r.type.prop(w.closedBy))&&a.indexOf(i.name)>-1&&e.doc.lineAt(r.to).from==e.doc.lineAt(i.from).from&&!/\S/.test(e.sliceDoc(r.to,i.from))?{from:r.to,to:i.from}:null}var $n=tr(!1),er=tr(!0);function tr(e){return({state:t,dispatch:n})=>{if(t.readOnly)return!1;let r=t.changeByRange(n=>{let{from:r,to:i}=n,a=t.doc.lineAt(r),o=!e&&r==i&&Qn(t,r);e&&(r=i=(i<=a.to?a:t.doc.lineAt(i)).to);let s=new ce(t,{simulateBreak:r,simulateDoubleBreak:!!o}),c=Me(s,r);for(c??=ye(/^\s*/.exec(t.doc.lineAt(r).text)[0],t.tabSize);i<a.to&&/\s/.test(a.text[i-a.from]);)i++;o?{from:r,to:i}=o:r>a.from&&r<a.from+100&&!/\S/.test(a.text.slice(0,r))&&(r=a.from);let l=[``,j(t,c)];return o&&l.push(j(t,s.lineIndent(a.from,-1))),{changes:{from:r,to:i,insert:_e.of(l)},range:F.cursor(r+1+l[1].length)}});return n(t.update(r,{scrollIntoView:!0,userEvent:`input`})),!0}}function nr(e,t){let n=-1;return e.changeByRange(r=>{let i=[];for(let a=r.from;a<=r.to;){let o=e.doc.lineAt(a);o.number>n&&(r.empty||r.to>o.from)&&(t(o,i,r),n=o.number),a=o.to+1}let a=e.changes(i);return{changes:i,range:F.range(a.mapPos(r.anchor,1),a.mapPos(r.head,1))}})}var rr=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=Object.create(null),r=new ce(e,{overrideIndentation:e=>n[e]??-1}),i=nr(e,(t,i,a)=>{let o=Me(r,t.from);if(o==null)return;/\S/.test(t.text)||(o=0);let s=/^\s*/.exec(t.text)[0],c=j(e,o);(s!=c||a.from<t.from+s.length)&&(n[t.from]=o,i.push({from:t.from,to:t.from+s.length,insert:c}))});return i.changes.empty||t(e.update(i,{userEvent:`indent`})),!0},ir=({state:e,dispatch:t})=>e.readOnly?!1:(t(e.update(nr(e,(t,n)=>{n.push({from:t.from,insert:e.facet(Pe)})}),{userEvent:`input.indent`})),!0),ar=({state:e,dispatch:t})=>e.readOnly?!1:(t(e.update(nr(e,(t,n)=>{let r=/^\s*/.exec(t.text)[0];if(!r)return;let i=ye(r,e.tabSize),a=0,o=j(e,Math.max(0,i-ne(e)));for(;a<r.length&&a<o.length&&r.charCodeAt(a)==o.charCodeAt(a);)a++;n.push({from:t.from+a,to:t.from+r.length,insert:o.slice(a)})}),{userEvent:`delete.dedent`})),!0),or=e=>(e.setTabFocusMode(),!0),sr=[{key:`Ctrl-b`,run:kt,shift:en,preventDefault:!0},{key:`Ctrl-f`,run:At,shift:tn},{key:`Ctrl-p`,run:zt,shift:ln},{key:`Ctrl-n`,run:Bt,shift:un},{key:`Ctrl-a`,run:Yt,shift:vn},{key:`Ctrl-e`,run:Xt,shift:yn},{key:`Ctrl-d`,run:Fn},{key:`Ctrl-h`,run:Pn},{key:`Ctrl-k`,run:zn},{key:`Ctrl-Alt-h`,run:Ln},{key:`Ctrl-o`,run:Hn},{key:`Ctrl-t`,run:Un},{key:`Ctrl-v`,run:Wt}],cr=[{key:`ArrowLeft`,run:kt,shift:en,preventDefault:!0},{key:`Mod-ArrowLeft`,mac:`Alt-ArrowLeft`,run:Mt,shift:rn,preventDefault:!0},{mac:`Cmd-ArrowLeft`,run:qt,shift:gn,preventDefault:!0},{key:`ArrowRight`,run:At,shift:tn,preventDefault:!0},{key:`Mod-ArrowRight`,mac:`Alt-ArrowRight`,run:Nt,shift:an,preventDefault:!0},{mac:`Cmd-ArrowRight`,run:Jt,shift:_n,preventDefault:!0},{key:`ArrowUp`,run:zt,shift:ln,preventDefault:!0},{mac:`Cmd-ArrowUp`,run:bn,shift:Sn},{mac:`Ctrl-ArrowUp`,run:Ut,shift:fn},{key:`ArrowDown`,run:Bt,shift:un,preventDefault:!0},{mac:`Cmd-ArrowDown`,run:xn,shift:Cn},{mac:`Ctrl-ArrowDown`,run:Wt,shift:pn},{key:`PageUp`,run:Ut,shift:fn},{key:`PageDown`,run:Wt,shift:pn},{key:`Home`,run:Kt,shift:hn,preventDefault:!0},{key:`Mod-Home`,run:bn,shift:Sn},{key:`End`,run:Gt,shift:mn,preventDefault:!0},{key:`Mod-End`,run:xn,shift:Cn},{key:`Enter`,run:$n,shift:$n},{key:`Mod-a`,run:wn},{key:`Backspace`,run:Pn,shift:Pn,preventDefault:!0},{key:`Delete`,run:Fn,preventDefault:!0},{key:`Mod-Backspace`,mac:`Alt-Backspace`,run:Ln,preventDefault:!0},{key:`Mod-Delete`,mac:`Alt-Delete`,run:Rn,preventDefault:!0},{mac:`Mod-Backspace`,run:Bn,preventDefault:!0},{mac:`Mod-Delete`,run:Vn,preventDefault:!0}].concat(sr.map(e=>({mac:e.key,run:e.run,shift:e.shift}))),lr=[{key:`Alt-ArrowLeft`,mac:`Ctrl-ArrowLeft`,run:It,shift:on},{key:`Alt-ArrowRight`,mac:`Ctrl-ArrowRight`,run:Lt,shift:sn},{key:`Alt-ArrowUp`,run:Kn},{key:`Shift-Alt-ArrowUp`,run:Yn},{key:`Alt-ArrowDown`,run:qn},{key:`Shift-Alt-ArrowDown`,run:Xn},{key:`Mod-Alt-ArrowUp`,run:On},{key:`Mod-Alt-ArrowDown`,run:kn},{key:`Escape`,run:An},{key:`Mod-Enter`,run:er},{key:`Alt-l`,mac:`Ctrl-l`,run:Tn},{key:`Mod-i`,run:En,preventDefault:!0},{key:`Mod-[`,run:ar},{key:`Mod-]`,run:ir},{key:`Mod-Alt-\\`,run:rr},{key:`Shift-Mod-k`,run:Zn},{key:`Shift-Mod-\\`,run:Qt},{key:`Mod-/`,run:qe},{key:`Alt-A`,run:Xe},{key:`Ctrl-m`,mac:`Shift-Alt-m`,run:or}].concat(cr),ur={key:`Tab`,run:ir,shift:ar},dr=typeof String.prototype.normalize==`function`?e=>e.normalize(`NFKD`):e=>e,G=class{constructor(e,t,n=0,r=e.length,i,a){this.test=a,this.value={from:0,to:0},this.done=!1,this.matches=[],this.buffer=``,this.bufferPos=0,this.iter=e.iterRange(n,r),this.bufferStart=n,this.normalize=i?e=>i(dr(e)):dr,this.query=this.normalize(t)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return se(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let e=this.peek();if(e<0)return this.done=!0,this;let t=de(e),n=this.bufferStart+this.bufferPos;this.bufferPos+=le(e);let r=this.normalize(t);if(r.length)for(let e=0,i=n;;e++){let a=r.charCodeAt(e),o=this.match(a,i,this.bufferPos+this.bufferStart);if(e==r.length-1){if(o)return this.value=o,this;break}i==n&&e<t.length&&t.charCodeAt(e)==a&&i++}}}match(e,t,n){let r=null;for(let t=0;t<this.matches.length;t+=2){let i=this.matches[t],a=!1;this.query.charCodeAt(i)==e&&(i==this.query.length-1?r={from:this.matches[t+1],to:n}:(this.matches[t]++,a=!0)),a||(this.matches.splice(t,2),t-=2)}return this.query.charCodeAt(0)==e&&(this.query.length==1?r={from:t,to:n}:this.matches.push(1,t)),r&&this.test&&!this.test(r.from,r.to,this.buffer,this.bufferStart)&&(r=null),r}};typeof Symbol<`u`&&(G.prototype[Symbol.iterator]=function(){return this});var fr={from:-1,to:-1,match:/.*/.exec(``)},pr=`gm`+(/x/.unicode==null?``:`u`),mr=class{constructor(e,t,n,r=0,i=e.length){if(this.text=e,this.to=i,this.curLine=``,this.done=!1,this.value=fr,/\\[sWDnr]|\n|\r|\[\^/.test(t))return new _r(e,t,n,r,i);this.re=new RegExp(t,pr+(n?.ignoreCase?`i`:``)),this.test=n?.test,this.iter=e.iter(),this.curLineStart=e.lineAt(r).from,this.matchPos=yr(e,r),this.getLine(this.curLineStart)}getLine(e){this.iter.next(e),this.iter.lineBreak?this.curLine=``:(this.curLine=this.iter.value,this.curLineStart+this.curLine.length>this.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart)),this.iter.next())}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1,this.curLineStart>this.to?this.curLine=``:this.getLine(0)}next(){for(let e=this.matchPos-this.curLineStart;;){this.re.lastIndex=e;let t=this.matchPos<=this.to&&this.re.exec(this.curLine);if(t){let n=this.curLineStart+t.index,r=n+t[0].length;if(this.matchPos=yr(this.text,r+(n==r?1:0)),n==this.curLineStart+this.curLine.length&&this.nextLine(),(n<r||n>this.value.to)&&(!this.test||this.test(n,r,t)))return this.value={from:n,to:r,match:t},this;e=this.matchPos-this.curLineStart}else if(this.curLineStart+this.curLine.length<this.to)this.nextLine(),e=0;else return this.done=!0,this}}},hr=new WeakMap,gr=class e{constructor(e,t){this.from=e,this.text=t}get to(){return this.from+this.text.length}static get(t,n,r){let i=hr.get(t);if(!i||i.from>=r||i.to<=n){let i=new e(n,t.sliceString(n,r));return hr.set(t,i),i}if(i.from==n&&i.to==r)return i;let{text:a,from:o}=i;return o>n&&(a=t.sliceString(n,o)+a,o=n),i.to<r&&(a+=t.sliceString(i.to,r)),hr.set(t,new e(o,a)),new e(n,a.slice(n-o,r-o))}},_r=class{constructor(e,t,n,r,i){this.text=e,this.to=i,this.done=!1,this.value=fr,this.matchPos=yr(e,r),this.re=new RegExp(t,pr+(n?.ignoreCase?`i`:``)),this.test=n?.test,this.flat=gr.get(e,r,this.chunkEnd(r+5e3))}chunkEnd(e){return e>=this.to?this.to:this.text.lineAt(e).to}next(){for(;;){let e=this.re.lastIndex=this.matchPos-this.flat.from,t=this.re.exec(this.flat.text);if(t&&!t[0]&&t.index==e&&(this.re.lastIndex=e+1,t=this.re.exec(this.flat.text)),t){let e=this.flat.from+t.index,n=e+t[0].length;if((this.flat.to>=this.to||t.index+t[0].length<=this.flat.text.length-10)&&(!this.test||this.test(e,n,t)))return this.value={from:e,to:n,match:t},this.matchPos=yr(this.text,n+(e==n?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=gr.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}};typeof Symbol<`u`&&(mr.prototype[Symbol.iterator]=_r.prototype[Symbol.iterator]=function(){return this});function vr(e){try{return new RegExp(e,pr),!0}catch{return!1}}function yr(e,t){if(t>=e.length)return t;let n=e.lineAt(t),r;for(;t<n.to&&(r=n.text.charCodeAt(t-n.from))>=56320&&r<57344;)t++;return t}var br=e=>{let{state:t}=e,n=String(t.doc.lineAt(e.state.selection.main.head).number),{close:r,result:i}=ee(e,{label:t.phrase(`Go to line`),input:{type:`text`,name:`line`,value:n},focus:!0,submitLabel:t.phrase(`go`)});return i.then(n=>{let i=n&&/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(n.elements.line.value);if(!i){e.dispatch({effects:r});return}let a=t.doc.lineAt(t.selection.main.head),[,o,s,c,l]=i,u=c?+c.slice(1):0,d=s?+s:a.number;if(s&&l){let e=d/100;o&&(e=e*(o==`-`?-1:1)+a.number/t.doc.lines),d=Math.round(t.doc.lines*e)}else s&&o&&(d=d*(o==`-`?-1:1)+a.number);let f=t.doc.line(Math.max(1,Math.min(t.doc.lines,d))),p=F.cursor(f.from+Math.max(0,Math.min(u,f.length)));e.dispatch({effects:[r,b.scrollIntoView(p.from,{y:`center`})],selection:p})}),!0},xr={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},Sr=N.define({combine(e){return Te(e,xr,{highlightWordAroundCursor:(e,t)=>e||t,minSelectionLength:Math.min,maxMatches:Math.min})}});function Cr(e){let t=[kr,Or];return e&&t.push(Sr.of(e)),t}var wr=f.mark({class:`cm-selectionMatch`}),Tr=f.mark({class:`cm-selectionMatch cm-selectionMatch-main`});function Er(e,t,n,r){return(n==0||e(t.sliceDoc(n-1,n))!=s.Word)&&(r==t.doc.length||e(t.sliceDoc(r,r+1))!=s.Word)}function Dr(e,t,n,r){return e(t.sliceDoc(n,n+1))==s.Word&&e(t.sliceDoc(r-1,r))==s.Word}var Or=c.fromClass(class{constructor(e){this.decorations=this.getDeco(e)}update(e){(e.selectionSet||e.docChanged||e.viewportChanged)&&(this.decorations=this.getDeco(e.view))}getDeco(e){let t=e.state.facet(Sr),{state:n}=e,r=n.selection;if(r.ranges.length>1)return f.none;let i=r.main,a,o=null;if(i.empty){if(!t.highlightWordAroundCursor)return f.none;let e=n.wordAt(i.head);if(!e)return f.none;o=n.charCategorizer(i.head),a=n.sliceDoc(e.from,e.to)}else{let e=i.to-i.from;if(e<t.minSelectionLength||e>200)return f.none;if(t.wholeWords){if(a=n.sliceDoc(i.from,i.to),o=n.charCategorizer(i.head),!(Er(o,n,i.from,i.to)&&Dr(o,n,i.from,i.to)))return f.none}else if(a=n.sliceDoc(i.from,i.to),!a)return f.none}let s=[];for(let r of e.visibleRanges){let e=new G(n.doc,a,r.from,r.to);for(;!e.next().done;){let{from:r,to:a}=e.value;if((!o||Er(o,n,r,a))&&(i.empty&&r<=i.from&&a>=i.to?s.push(Tr.range(r,a)):(r>=i.to||a<=i.from)&&s.push(wr.range(r,a)),s.length>t.maxMatches))return f.none}}return f.set(s)}},{decorations:e=>e.decorations}),kr=b.baseTheme({".cm-selectionMatch":{backgroundColor:`#99ff7780`},".cm-searchMatch .cm-selectionMatch":{backgroundColor:`transparent`}}),Ar=({state:e,dispatch:t})=>{let{selection:n}=e,r=F.create(n.ranges.map(t=>e.wordAt(t.head)||F.cursor(t.head)),n.mainIndex);return r.eq(n)?!1:(t(e.update({selection:r})),!0)};function jr(e,t){let{main:n,ranges:r}=e.selection,i=e.wordAt(n.head),a=i&&i.from==n.from&&i.to==n.to;for(let n=!1,i=new G(e.doc,t,r[r.length-1].to);;)if(i.next(),i.done){if(n)return null;i=new G(e.doc,t,0,Math.max(0,r[r.length-1].from-1)),n=!0}else{if(n&&r.some(e=>e.from==i.value.from))continue;if(a){let t=e.wordAt(i.value.from);if(!t||t.from!=i.value.from||t.to!=i.value.to)continue}return i.value}}var Mr=({state:e,dispatch:t})=>{let{ranges:n}=e.selection;if(n.some(e=>e.from===e.to))return Ar({state:e,dispatch:t});let r=e.sliceDoc(n[0].from,n[0].to);if(e.selection.ranges.some(t=>e.sliceDoc(t.from,t.to)!=r))return!1;let i=jr(e,r);return i?(t(e.update({selection:e.selection.addRange(F.range(i.from,i.to),!1),effects:b.scrollIntoView(i.to)})),!0):!1},K=N.define({combine(e){return Te(e,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:e=>new li(e),scrollToMatch:e=>b.scrollIntoView(e)})}}),Nr=class{constructor(e){this.search=e.search,this.caseSensitive=!!e.caseSensitive,this.literal=!!e.literal,this.regexp=!!e.regexp,this.replace=e.replace||``,this.valid=!!this.search&&(!this.regexp||vr(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!e.wholeWord,this.test=e.test}unquote(e){return this.literal?e:e.replace(/\\([nrt\\])/g,(e,t)=>t==`n`?`
2
+ `:t==`r`?`\r`:t==`t`?` `:`\\`)}eq(e){return this.search==e.search&&this.replace==e.replace&&this.caseSensitive==e.caseSensitive&&this.regexp==e.regexp&&this.wholeWord==e.wholeWord&&this.test==e.test}create(){return this.regexp?new Hr(this):new Lr(this)}getCursor(e,t=0,n){let r=e.doc?e:xe.create({doc:e});return n??=r.doc.length,this.regexp?J(this,r,t,n):q(this,r,t,n)}},Pr=class{constructor(e){this.spec=e}};function Fr(e,t,n){return(r,i,a,o)=>n&&!n(r,i,a,o)?!1:e(r>=o&&i<=o+a.length?a.slice(r-o,i-o):t.doc.sliceString(r,i),t,r,i)}function q(e,t,n,r){let i;return e.wholeWord&&(i=Ir(t.doc,t.charCategorizer(t.selection.main.head))),e.test&&(i=Fr(e.test,t,i)),new G(t.doc,e.unquoted,n,r,e.caseSensitive?void 0:e=>e.toLowerCase(),i)}function Ir(e,t){return(n,r,i,a)=>((a>n||a+i.length<r)&&(a=Math.max(0,n-2),i=e.sliceString(a,Math.min(e.length,r+2))),(t(zr(i,n-a))!=s.Word||t(Br(i,n-a))!=s.Word)&&(t(Br(i,r-a))!=s.Word||t(zr(i,r-a))!=s.Word))}var Lr=class extends Pr{constructor(e){super(e)}nextMatch(e,t,n){let r=q(this.spec,e,n,e.doc.length).nextOverlapping();if(r.done){let n=Math.min(e.doc.length,t+this.spec.unquoted.length);r=q(this.spec,e,0,n).nextOverlapping()}return r.done||r.value.from==t&&r.value.to==n?null:r.value}prevMatchInRange(e,t,n){for(let r=n;;){let n=Math.max(t,r-1e4-this.spec.unquoted.length),i=q(this.spec,e,n,r),a=null;for(;!i.nextOverlapping().done;)a=i.value;if(a)return a;if(n==t)return null;r-=1e4}}prevMatch(e,t,n){let r=this.prevMatchInRange(e,0,t);return r||=this.prevMatchInRange(e,Math.max(0,n-this.spec.unquoted.length),e.doc.length),r&&(r.from!=t||r.to!=n)?r:null}getReplacement(e){return this.spec.unquote(this.spec.replace)}matchAll(e,t){let n=q(this.spec,e,0,e.doc.length),r=[];for(;!n.next().done;){if(r.length>=t)return null;r.push(n.value)}return r}highlight(e,t,n,r){let i=q(this.spec,e,Math.max(0,t-this.spec.unquoted.length),Math.min(n+this.spec.unquoted.length,e.doc.length));for(;!i.next().done;)r(i.value.from,i.value.to)}};function Rr(e,t,n){return(r,i,a)=>(!n||n(r,i,a))&&e(a[0],t,r,i)}function J(e,t,n,r){let i;return e.wholeWord&&(i=Vr(t.charCategorizer(t.selection.main.head))),e.test&&(i=Rr(e.test,t,i)),new mr(t.doc,e.search,{ignoreCase:!e.caseSensitive,test:i},n,r)}function zr(e,t){return e.slice(M(e,t,!1),t)}function Br(e,t){return e.slice(t,M(e,t))}function Vr(e){return(t,n,r)=>!r[0].length||(e(zr(r.input,r.index))!=s.Word||e(Br(r.input,r.index))!=s.Word)&&(e(Br(r.input,r.index+r[0].length))!=s.Word||e(zr(r.input,r.index+r[0].length))!=s.Word)}var Hr=class extends Pr{nextMatch(e,t,n){let r=J(this.spec,e,n,e.doc.length).next();return r.done&&(r=J(this.spec,e,0,t).next()),r.done?null:r.value}prevMatchInRange(e,t,n){for(let r=1;;r++){let i=Math.max(t,n-r*1e4),a=J(this.spec,e,i,n),o=null;for(;!a.next().done;)o=a.value;if(o&&(i==t||o.from>i+10))return o;if(i==t)return null}}prevMatch(e,t,n){return this.prevMatchInRange(e,0,t)||this.prevMatchInRange(e,n,e.doc.length)}getReplacement(e){return this.spec.unquote(this.spec.replace).replace(/\$([$&]|\d+)/g,(t,n)=>{if(n==`&`)return e.match[0];if(n==`$`)return`$`;for(let t=n.length;t>0;t--){let r=+n.slice(0,t);if(r>0&&r<e.match.length)return e.match[r]+n.slice(t)}return t})}matchAll(e,t){let n=J(this.spec,e,0,e.doc.length),r=[];for(;!n.next().done;){if(r.length>=t)return null;r.push(n.value)}return r}highlight(e,t,n,r){let i=J(this.spec,e,Math.max(0,t-250),Math.min(n+250,e.doc.length));for(;!i.next().done;)r(i.value.from,i.value.to)}},Ur=P.define(),Wr=P.define(),Y=ae.define({create(e){return new Gr(ri(e).create(),null)},update(e,t){for(let n of t.effects)n.is(Ur)?e=new Gr(n.value.create(),e.panel):n.is(Wr)&&(e=new Gr(e.query,n.value?ni:null));return e},provide:e=>Ee.from(e,e=>e.panel)}),Gr=class{constructor(e,t){this.query=e,this.panel=t}},Kr=f.mark({class:`cm-searchMatch`}),qr=f.mark({class:`cm-searchMatch cm-searchMatch-selected`}),Jr=c.fromClass(class{constructor(e){this.view=e,this.decorations=this.highlight(e.state.field(Y))}update(e){let t=e.state.field(Y);(t!=e.startState.field(Y)||e.docChanged||e.selectionSet||e.viewportChanged)&&(this.decorations=this.highlight(t))}highlight({query:e,panel:t}){if(!t||!e.spec.valid)return f.none;let{view:n}=this,r=new Ce;for(let t=0,i=n.visibleRanges,a=i.length;t<a;t++){let{from:o,to:s}=i[t];for(;t<a-1&&s>i[t+1].from-500;)s=i[++t].to;e.highlight(n.state,o,s,(e,t)=>{let i=n.state.selection.ranges.some(n=>n.from==e&&n.to==t);r.add(e,t,i?qr:Kr)})}return r.finish()}},{decorations:e=>e.decorations});function Yr(e){return t=>{let n=t.state.field(Y,!1);return n&&n.query.spec.valid?e(t,n):oi(t)}}var Xr=Yr((e,{query:t})=>{let{to:n}=e.state.selection.main,r=t.nextMatch(e.state,n,n);if(!r)return!1;let i=F.single(r.from,r.to),a=e.state.facet(K);return e.dispatch({selection:i,effects:[fi(e,r),a.scrollToMatch(i.main,e)],userEvent:`select.search`}),ai(e),!0}),Zr=Yr((e,{query:t})=>{let{state:n}=e,{from:r}=n.selection.main,i=t.prevMatch(n,r,r);if(!i)return!1;let a=F.single(i.from,i.to),o=e.state.facet(K);return e.dispatch({selection:a,effects:[fi(e,i),o.scrollToMatch(a.main,e)],userEvent:`select.search`}),ai(e),!0}),Qr=Yr((e,{query:t})=>{let n=t.matchAll(e.state,1e3);return!n||!n.length?!1:(e.dispatch({selection:F.create(n.map(e=>F.range(e.from,e.to))),userEvent:`select.search.matches`}),!0)}),$r=({state:e,dispatch:t})=>{let n=e.selection;if(n.ranges.length>1||n.main.empty)return!1;let{from:r,to:i}=n.main,a=[],o=0;for(let t=new G(e.doc,e.sliceDoc(r,i));!t.next().done;){if(a.length>1e3)return!1;t.value.from==r&&(o=a.length),a.push(F.range(t.value.from,t.value.to))}return t(e.update({selection:F.create(a,o),userEvent:`select.search.matches`})),!0},ei=Yr((e,{query:t})=>{let{state:n}=e,{from:r,to:i}=n.selection.main;if(n.readOnly)return!1;let a=t.nextMatch(n,r,r);if(!a)return!1;let o=a,s=[],c,l,u=[];o.from==r&&o.to==i&&(l=n.toText(t.getReplacement(o)),s.push({from:o.from,to:o.to,insert:l}),o=t.nextMatch(n,o.from,o.to),u.push(b.announce.of(n.phrase(`replaced match on line $`,n.doc.lineAt(r).number)+`.`)));let d=e.state.changes(s);return o&&(c=F.single(o.from,o.to).map(d),u.push(fi(e,o)),u.push(n.facet(K).scrollToMatch(c.main,e))),e.dispatch({changes:d,selection:c,effects:u,userEvent:`input.replace`}),!0}),ti=Yr((e,{query:t})=>{if(e.state.readOnly)return!1;let n=t.matchAll(e.state,1e9).map(e=>{let{from:n,to:r}=e;return{from:n,to:r,insert:t.getReplacement(e)}});if(!n.length)return!1;let r=e.state.phrase(`replaced $ matches`,n.length)+`.`;return e.dispatch({changes:n,effects:b.announce.of(r),userEvent:`input.replace.all`}),!0});function ni(e){return e.state.facet(K).createPanel(e)}function ri(e,t){let n=e.selection.main,r=n.empty||n.to>n.from+100?``:e.sliceDoc(n.from,n.to);if(t&&!r)return t;let i=e.facet(K);return new Nr({search:t?.literal??i.literal?r:r.replace(/\n/g,`\\n`),caseSensitive:t?.caseSensitive??i.caseSensitive,literal:t?.literal??i.literal,regexp:t?.regexp??i.regexp,wholeWord:t?.wholeWord??i.wholeWord})}function ii(e){let t=p(e,ni);return t&&t.dom.querySelector(`[main-field]`)}function ai(e){let t=ii(e);t&&t==e.root.activeElement&&t.select()}var oi=e=>{let t=e.state.field(Y,!1);if(t&&t.panel){let n=ii(e);if(n&&n!=e.root.activeElement){let r=ri(e.state,t.query.spec);r.valid&&e.dispatch({effects:Ur.of(r)}),n.focus(),n.select()}}else e.dispatch({effects:[Wr.of(!0),t?Ur.of(ri(e.state,t.query.spec)):P.appendConfig.of(mi)]});return!0},si=e=>{let t=e.state.field(Y,!1);if(!t||!t.panel)return!1;let n=p(e,ni);return n&&n.dom.contains(e.root.activeElement)&&e.focus(),e.dispatch({effects:Wr.of(!1)}),!0},ci=[{key:`Mod-f`,run:oi,scope:`editor search-panel`},{key:`F3`,run:Xr,shift:Zr,scope:`editor search-panel`,preventDefault:!0},{key:`Mod-g`,run:Xr,shift:Zr,scope:`editor search-panel`,preventDefault:!0},{key:`Escape`,run:si,scope:`editor search-panel`},{key:`Mod-Shift-l`,run:$r},{key:`Mod-Alt-g`,run:br},{key:`Mod-d`,run:Mr,preventDefault:!0}],li=class{constructor(e){this.view=e;let t=this.query=e.state.field(Y).query.spec;this.commit=this.commit.bind(this),this.searchField=g(`input`,{value:t.search,placeholder:X(e,`Find`),"aria-label":X(e,`Find`),class:`cm-textfield`,name:`search`,form:``,"main-field":`true`,onchange:this.commit,onkeyup:this.commit}),this.replaceField=g(`input`,{value:t.replace,placeholder:X(e,`Replace`),"aria-label":X(e,`Replace`),class:`cm-textfield`,name:`replace`,form:``,onchange:this.commit,onkeyup:this.commit}),this.caseField=g(`input`,{type:`checkbox`,name:`case`,form:``,checked:t.caseSensitive,onchange:this.commit}),this.reField=g(`input`,{type:`checkbox`,name:`re`,form:``,checked:t.regexp,onchange:this.commit}),this.wordField=g(`input`,{type:`checkbox`,name:`word`,form:``,checked:t.wholeWord,onchange:this.commit});function n(e,t,n){return g(`button`,{class:`cm-button`,name:e,onclick:t,type:`button`},n)}this.dom=g(`div`,{onkeydown:e=>this.keydown(e),class:`cm-search`},[this.searchField,n(`next`,()=>Xr(e),[X(e,`next`)]),n(`prev`,()=>Zr(e),[X(e,`previous`)]),n(`select`,()=>Qr(e),[X(e,`all`)]),g(`label`,null,[this.caseField,X(e,`match case`)]),g(`label`,null,[this.reField,X(e,`regexp`)]),g(`label`,null,[this.wordField,X(e,`by word`)]),...e.state.readOnly?[]:[g(`br`),this.replaceField,n(`replace`,()=>ei(e),[X(e,`replace`)]),n(`replaceAll`,()=>ti(e),[X(e,`replace all`)])],g(`button`,{name:`close`,onclick:()=>si(e),"aria-label":X(e,`close`),type:`button`},[`×`])])}commit(){let e=new Nr({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,wholeWord:this.wordField.checked,replace:this.replaceField.value});e.eq(this.query)||(this.query=e,this.view.dispatch({effects:Ur.of(e)}))}keydown(e){m(this.view,e,`search-panel`)?e.preventDefault():e.keyCode==13&&e.target==this.searchField?(e.preventDefault(),(e.shiftKey?Zr:Xr)(this.view)):e.keyCode==13&&e.target==this.replaceField&&(e.preventDefault(),ei(this.view))}update(e){for(let t of e.transactions)for(let e of t.effects)e.is(Ur)&&!e.value.eq(this.query)&&this.setQuery(e.value)}setQuery(e){this.query=e,this.searchField.value=e.search,this.replaceField.value=e.replace,this.caseField.checked=e.caseSensitive,this.reField.checked=e.regexp,this.wordField.checked=e.wholeWord}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(K).top}};function X(e,t){return e.state.phrase(t)}var ui=30,di=/[\s\.,:;?!]/;function fi(e,{from:t,to:n}){let r=e.state.doc.lineAt(t),i=e.state.doc.lineAt(n).to,a=Math.max(r.from,t-ui),o=Math.min(i,n+ui),s=e.state.sliceDoc(a,o);if(a!=r.from){for(let e=0;e<ui;e++)if(!di.test(s[e+1])&&di.test(s[e])){s=s.slice(e);break}}if(o!=i){for(let e=s.length-1;e>s.length-ui;e--)if(!di.test(s[e-1])&&di.test(s[e])){s=s.slice(0,e);break}}return b.announce.of(`${e.state.phrase(`current match`)}. ${s} ${e.state.phrase(`on line`)} ${r.number}.`)}var pi=b.baseTheme({".cm-panel.cm-search":{padding:`2px 6px 4px`,position:`relative`,"& [name=close]":{position:`absolute`,top:`0`,right:`4px`,backgroundColor:`inherit`,border:`none`,font:`inherit`,padding:0,margin:0},"& input, & button, & label":{margin:`.2em .6em .2em 0`},"& input[type=checkbox]":{marginRight:`.2em`},"& label":{fontSize:`80%`,whiteSpace:`pre`}},"&light .cm-searchMatch":{backgroundColor:`#ffff0054`},"&dark .cm-searchMatch":{backgroundColor:`#00ffff8a`},"&light .cm-searchMatch-selected":{backgroundColor:`#ff6a0054`},"&dark .cm-searchMatch-selected":{backgroundColor:`#ff00ff8a`}}),mi=[Y,me.low(Jr),pi],hi=class{constructor(e,t,n){this.from=e,this.to=t,this.diagnostic=n}},gi=class e{constructor(e,t,n){this.diagnostics=e,this.panel=t,this.selected=n}static init(t,n,r){let i=r.facet(Oi).markerFilter;i&&(t=i(t,r));let a=t.slice().sort((e,t)=>e.from-t.from||e.to-t.to),o=new Ce,s=[],c=0,l=r.doc.iter(),u=0,d=r.doc.length;for(let e=0;;){let t=e==a.length?null:a[e];if(!t&&!s.length)break;let n,r;if(s.length)n=c,r=s.reduce((e,t)=>Math.min(e,t.to),t&&t.from>n?t.from:1e8);else{if(n=t.from,n>d)break;r=t.to,s.push(t),e++}for(;e<a.length;){let t=a[e];if(t.from==n&&(t.to>t.from||t.to==n))s.push(t),e++,r=Math.min(t.to,r);else{r=Math.min(t.from,r);break}}r=Math.min(r,d);let i=!1;if(s.some(e=>e.from==n&&(e.to==r||r==d))&&(i=n==r,!i&&r-n<10)){let e=n-(u+l.value.length);e>0&&(l.next(e),u=n);for(let e=n;;){if(e>=r){i=!0;break}if(!l.lineBreak&&u+l.value.length>e)break;e=u+l.value.length,u+=l.value.length,l.next()}}let p=zi(s);if(i)o.add(n,n,f.widget({widget:new Mi(p),diagnostics:s.slice()}));else{let e=s.reduce((e,t)=>t.markClass?e+` `+t.markClass:e,``);o.add(n,r,f.mark({class:`cm-lintRange cm-lintRange-`+p+e,diagnostics:s.slice(),inclusiveEnd:s.some(e=>e.to>r)}))}if(c=r,c==d)break;for(let e=0;e<s.length;e++)s[e].to<=c&&s.splice(e--,1)}let p=o.finish();return new e(p,n,Z(p))}};function Z(e,t=null,n=0){let r=null;return e.between(n,1e9,(e,n,{spec:i})=>{if(!(t&&i.diagnostics.indexOf(t)<0))if(!r)r=new hi(e,n,t||i.diagnostics[0]);else if(i.diagnostics.indexOf(r.diagnostic)<0)return!1;else r=new hi(r.from,n,r.diagnostic)}),r}function _i(e,t){let n=t.pos,r=t.end||n,i=e.state.facet(Oi).hideOn(e,n,r);if(i!=null)return i;let a=e.startState.doc.lineAt(t.pos);return!!(e.effects.some(e=>e.is(yi))||e.changes.touchesRange(a.from,Math.max(a.to,r)))}function vi(e,t){return e.field(Q,!1)?t:t.concat(P.appendConfig.of(Bi))}var yi=P.define(),bi=P.define(),xi=P.define(),Q=ae.define({create(){return new gi(f.none,null,null)},update(e,t){if(t.docChanged&&e.diagnostics.size){let n=e.diagnostics.map(t.changes),r=null,i=e.panel;if(e.selected){let i=t.changes.mapPos(e.selected.from,1);r=Z(n,e.selected.diagnostic,i)||Z(n,null,i)}!n.size&&i&&t.state.facet(Oi).autoPanel&&(i=null),e=new gi(n,i,r)}for(let n of t.effects)if(n.is(yi)){let r=t.state.facet(Oi).autoPanel?n.value.length?Pi.open:null:e.panel;e=gi.init(n.value,r,t.state)}else n.is(bi)?e=new gi(e.diagnostics,n.value?Pi.open:null,e.selected):n.is(xi)&&(e=new gi(e.diagnostics,e.panel,n.value));return e},provide:e=>[Ee.from(e,e=>e.panel),b.decorations.from(e,e=>e.diagnostics)]}),Si=f.mark({class:`cm-lintRange cm-lintRange-active`});function Ci(e,t,n){let{diagnostics:r}=e.state.field(Q),i,a=-1,o=-1;r.between(t-(n<0?1:0),t+(n>0?1:0),(e,r,{spec:s})=>{if(t>=e&&t<=r&&(e==r||(t>e||n>0)&&(t<r||n<0)))return i=s.diagnostics,a=e,o=r,!1});let s=e.state.facet(Oi).tooltipFilter;return i&&s&&(i=s(i,e.state)),i?{pos:a,end:o,above:e.state.doc.lineAt(a).to<o,create(){return{dom:wi(e,i)}}}:null}function wi(e,t){return g(`ul`,{class:`cm-tooltip-lint`},t.map(t=>ji(e,t,!1)))}var Ti=e=>{let t=e.state.field(Q,!1);(!t||!t.panel)&&e.dispatch({effects:vi(e.state,[bi.of(!0)])});let n=p(e,Pi.open);return n&&n.dom.querySelector(`.cm-panel-lint ul`).focus(),!0},Ei=e=>{let t=e.state.field(Q,!1);return!t||!t.panel?!1:(e.dispatch({effects:bi.of(!1)}),!0)},Di=[{key:`Mod-Shift-m`,run:Ti,preventDefault:!0},{key:`F8`,run:e=>{let t=e.state.field(Q,!1);if(!t)return!1;let n=e.state.selection.main,r=Z(t.diagnostics,null,n.to+1);return!r&&(r=Z(t.diagnostics,null,0),!r||r.from==n.from&&r.to==n.to)?!1:(e.dispatch({selection:{anchor:r.from,head:r.to},scrollIntoView:!0}),!0)}}],Oi=N.define({combine(e){return{sources:e.map(e=>e.source).filter(e=>e!=null),...Te(e.map(e=>e.config),{delay:750,markerFilter:null,tooltipFilter:null,needsRefresh:null,hideOn:()=>null},{delay:Math.max,markerFilter:ki,tooltipFilter:ki,needsRefresh:(e,t)=>e?t?n=>e(n)||t(n):e:t,hideOn:(e,t)=>e?t?(n,r,i)=>e(n,r,i)||t(n,r,i):e:t,autoPanel:(e,t)=>e||t})}}});function ki(e,t){return e?t?(n,r)=>t(e(n,r),r):e:t}function Ai(e){let t=[];if(e)actions:for(let{name:n}of e){for(let e=0;e<n.length;e++){let r=n[e];if(/[a-zA-Z]/.test(r)&&!t.some(e=>e.toLowerCase()==r.toLowerCase())){t.push(r);continue actions}}t.push(``)}return t}function ji(e,t,n){let r=n?Ai(t.actions):[];return g(`li`,{class:`cm-diagnostic cm-diagnostic-`+t.severity},g(`span`,{class:`cm-diagnosticText`},t.renderMessage?t.renderMessage(e):t.message),t.actions?.map((n,i)=>{let a=!1,o=r=>{if(r.preventDefault(),a)return;a=!0;let i=Z(e.state.field(Q).diagnostics,t);i&&n.apply(e,i.from,i.to)},{name:s}=n,c=r[i]?s.indexOf(r[i]):-1,l=c<0?s:[s.slice(0,c),g(`u`,s.slice(c,c+1)),s.slice(c+1)];return g(`button`,{type:`button`,class:`cm-diagnosticAction`+(n.markClass?` `+n.markClass:``),onclick:o,onmousedown:o,"aria-label":` Action: ${s}${c<0?``:` (access key "${r[i]})"`}.`},l)}),t.source&&g(`div`,{class:`cm-diagnosticSource`},t.source))}var Mi=class extends he{constructor(e){super(),this.sev=e}eq(e){return e.sev==this.sev}toDOM(){return g(`span`,{class:`cm-lintPoint cm-lintPoint-`+this.sev})}},Ni=class{constructor(e,t){this.diagnostic=t,this.id=`item_`+Math.floor(Math.random()*4294967295).toString(16),this.dom=ji(e,t,!0),this.dom.id=this.id,this.dom.setAttribute(`role`,`option`)}},Pi=class e{constructor(e){this.view=e,this.items=[];let t=t=>{if(!(t.ctrlKey||t.altKey||t.metaKey)){if(t.keyCode==27)Ei(this.view),this.view.focus();else if(t.keyCode==38||t.keyCode==33)this.moveSelection((this.selectedIndex-1+this.items.length)%this.items.length);else if(t.keyCode==40||t.keyCode==34)this.moveSelection((this.selectedIndex+1)%this.items.length);else if(t.keyCode==36)this.moveSelection(0);else if(t.keyCode==35)this.moveSelection(this.items.length-1);else if(t.keyCode==13)this.view.focus();else if(t.keyCode>=65&&t.keyCode<=90&&this.selectedIndex>=0){let{diagnostic:n}=this.items[this.selectedIndex],r=Ai(n.actions);for(let i=0;i<r.length;i++)if(r[i].toUpperCase().charCodeAt(0)==t.keyCode){let t=Z(this.view.state.field(Q).diagnostics,n);t&&n.actions[i].apply(e,t.from,t.to)}}else return;t.preventDefault()}},n=e=>{for(let t=0;t<this.items.length;t++)this.items[t].dom.contains(e.target)&&this.moveSelection(t)};this.list=g(`ul`,{tabIndex:0,role:`listbox`,"aria-label":this.view.state.phrase(`Diagnostics`),onkeydown:t,onclick:n}),this.dom=g(`div`,{class:`cm-panel-lint`},this.list,g(`button`,{type:`button`,name:`close`,"aria-label":this.view.state.phrase(`close`),onclick:()=>Ei(this.view)},`×`)),this.update()}get selectedIndex(){let e=this.view.state.field(Q).selected;if(!e)return-1;for(let t=0;t<this.items.length;t++)if(this.items[t].diagnostic==e.diagnostic)return t;return-1}update(){let{diagnostics:e,selected:t}=this.view.state.field(Q),n=0,r=!1,i=null,a=new Set;for(e.between(0,this.view.state.doc.length,(e,o,{spec:s})=>{for(let e of s.diagnostics){if(a.has(e))continue;a.add(e);let o=-1,s;for(let t=n;t<this.items.length;t++)if(this.items[t].diagnostic==e){o=t;break}o<0?(s=new Ni(this.view,e),this.items.splice(n,0,s),r=!0):(s=this.items[o],o>n&&(this.items.splice(n,o-n),r=!0)),t&&s.diagnostic==t.diagnostic?s.dom.hasAttribute(`aria-selected`)||(s.dom.setAttribute(`aria-selected`,`true`),i=s):s.dom.hasAttribute(`aria-selected`)&&s.dom.removeAttribute(`aria-selected`),n++}});n<this.items.length&&!(this.items.length==1&&this.items[0].diagnostic.from<0);)r=!0,this.items.pop();this.items.length==0&&(this.items.push(new Ni(this.view,{from:-1,to:-1,severity:`info`,message:this.view.state.phrase(`No diagnostics`)})),r=!0),i?(this.list.setAttribute(`aria-activedescendant`,i.id),this.view.requestMeasure({key:this,read:()=>({sel:i.dom.getBoundingClientRect(),panel:this.list.getBoundingClientRect()}),write:({sel:e,panel:t})=>{let n=t.height/this.list.offsetHeight;e.top<t.top?this.list.scrollTop-=(t.top-e.top)/n:e.bottom>t.bottom&&(this.list.scrollTop+=(e.bottom-t.bottom)/n)}})):this.selectedIndex<0&&this.list.removeAttribute(`aria-activedescendant`),r&&this.sync()}sync(){let e=this.list.firstChild;function t(){let t=e;e=t.nextSibling,t.remove()}for(let n of this.items)if(n.dom.parentNode==this.list){for(;e!=n.dom;)t();e=n.dom.nextSibling}else this.list.insertBefore(n.dom,e);for(;e;)t()}moveSelection(e){if(this.selectedIndex<0)return;let t=Z(this.view.state.field(Q).diagnostics,this.items[e].diagnostic);t&&this.view.dispatch({selection:{anchor:t.from,head:t.to},scrollIntoView:!0,effects:xi.of(t)})}static open(t){return new e(t)}};function Fi(e,t=`viewBox="0 0 40 40"`){return`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" ${t}>${encodeURIComponent(e)}</svg>')`}function Ii(e){return Fi(`<path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="${e}" fill="none" stroke-width=".7"/>`,`width="6" height="3"`)}var Li=b.baseTheme({".cm-diagnostic":{padding:`3px 6px 3px 8px`,marginLeft:`-1px`,display:`block`,whiteSpace:`pre-wrap`},".cm-diagnostic-error":{borderLeft:`5px solid #d11`},".cm-diagnostic-warning":{borderLeft:`5px solid orange`},".cm-diagnostic-info":{borderLeft:`5px solid #999`},".cm-diagnostic-hint":{borderLeft:`5px solid #66d`},".cm-diagnosticAction":{font:`inherit`,border:`none`,padding:`2px 4px`,backgroundColor:`#444`,color:`white`,borderRadius:`3px`,marginLeft:`8px`,cursor:`pointer`},".cm-diagnosticSource":{fontSize:`70%`,opacity:.7},".cm-lintRange":{backgroundPosition:`left bottom`,backgroundRepeat:`repeat-x`,paddingBottom:`0.7px`},".cm-lintRange-error":{backgroundImage:Ii(`#d11`)},".cm-lintRange-warning":{backgroundImage:Ii(`orange`)},".cm-lintRange-info":{backgroundImage:Ii(`#999`)},".cm-lintRange-hint":{backgroundImage:Ii(`#66d`)},".cm-lintRange-active":{backgroundColor:`#ffdd9980`},".cm-tooltip-lint":{padding:0,margin:0},".cm-lintPoint":{position:`relative`,"&:after":{content:`""`,position:`absolute`,bottom:0,left:`-2px`,borderLeft:`3px solid transparent`,borderRight:`3px solid transparent`,borderBottom:`4px solid #d11`}},".cm-lintPoint-warning":{"&:after":{borderBottomColor:`orange`}},".cm-lintPoint-info":{"&:after":{borderBottomColor:`#999`}},".cm-lintPoint-hint":{"&:after":{borderBottomColor:`#66d`}},".cm-panel.cm-panel-lint":{position:`relative`,"& ul":{maxHeight:`100px`,overflowY:`auto`,"& [aria-selected]":{backgroundColor:`#ddd`,"& u":{textDecoration:`underline`}},"&:focus [aria-selected]":{background_fallback:`#bdf`,backgroundColor:`Highlight`,color_fallback:`white`,color:`HighlightText`},"& u":{textDecoration:`none`},padding:0,margin:0},"& [name=close]":{position:`absolute`,top:`0`,right:`2px`,background:`inherit`,border:`none`,font:`inherit`,padding:0,margin:0}},"&dark .cm-lintRange-active":{backgroundColor:`#86714a80`},"&dark .cm-panel.cm-panel-lint ul":{"& [aria-selected]":{backgroundColor:`#2e343e`}}});function Ri(e){return e==`error`?4:e==`warning`?3:e==`info`?2:1}function zi(e){let t=`hint`,n=1;for(let r of e){let e=Ri(r.severity);e>n&&(n=e,t=r.severity)}return t}var Bi=[Q,b.decorations.compute([Q],e=>{let{selected:t,panel:n}=e.field(Q);return!t||!n||t.from==t.to?f.none:f.set([Si.range(t.from,t.to)])}),l(Ci,{hideOn:_i}),Li],Vi=function(e){e===void 0&&(e={});var{crosshairCursor:t=!1}=e,n=[];e.closeBracketsKeymap!==!1&&(n=n.concat(Ae)),e.defaultKeymap!==!1&&(n=n.concat(lr)),e.searchKeymap!==!1&&(n=n.concat(ci)),e.historyKeymap!==!1&&(n=n.concat(Et)),e.foldKeymap!==!1&&(n=n.concat(ue)),e.completionKeymap!==!1&&(n=n.concat(oe)),e.lintKeymap!==!1&&(n=n.concat(Di));var r=[];return e.lineNumbers!==!1&&r.push(h()),e.highlightActiveLineGutter!==!1&&r.push(S()),e.highlightSpecialChars!==!1&&r.push(Ie()),e.history!==!1&&r.push(lt()),e.foldGutter!==!1&&r.push(fe()),e.drawSelection!==!1&&r.push(y()),e.dropCursor!==!1&&r.push(te()),e.allowMultipleSelections!==!1&&r.push(xe.allowMultipleSelections.of(!0)),e.indentOnInput!==!1&&r.push(Fe()),e.syntaxHighlighting!==!1&&r.push(u(ve,{fallback:!0})),e.bracketMatching!==!1&&r.push(we()),e.closeBrackets!==!1&&r.push(ge()),e.autocompletion!==!1&&r.push(ie()),e.rectangularSelection!==!1&&r.push(D()),t!==!1&&r.push(v()),e.highlightActiveLine!==!1&&r.push(_()),e.highlightSelectionMatches!==!1&&r.push(Cr()),e.tabSize&&typeof e.tabSize==`number`&&r.push(Pe.of(` `.repeat(e.tabSize))),r.concat([E.of(n.flat())]).filter(Boolean)},Hi=b.theme({"&":{backgroundColor:`#fff`}},{dark:!1}),Ui=function(e){e===void 0&&(e={});var{indentWithTab:t=!0,editable:n=!0,readOnly:r=!1,theme:i=`light`,placeholder:a=``,basicSetup:o=!0}=e,s=[];switch(t&&s.unshift(E.of([ur])),o&&(typeof o==`boolean`?s.unshift(Vi()):s.unshift(Vi(o))),a&&s.unshift(T(a)),i){case`light`:s.push(Hi);break;case`dark`:s.push(Oe);break;case`none`:break;default:s.push(i);break}return n===!1&&s.push(b.editable.of(!1)),r&&s.push(xe.readOnly.of(!0)),[...s]},Wi=e=>({line:e.state.doc.lineAt(e.state.selection.main.from),lineCount:e.state.doc.lines,lineBreak:e.state.lineBreak,length:e.state.doc.length,readOnly:e.state.readOnly,tabSize:e.state.tabSize,selection:e.state.selection,selectionAsSingle:e.state.selection.asSingle().main,ranges:e.state.selection.ranges,selectionCode:e.state.sliceDoc(e.state.selection.main.from,e.state.selection.main.to),selections:e.state.selection.ranges.map(t=>e.state.sliceDoc(t.from,t.to)),selectedText:e.state.selection.ranges.some(e=>!e.empty)}),Gi=class{constructor(e,t){this.timeLeftMS=void 0,this.timeoutMS=void 0,this.isCancelled=!1,this.isTimeExhausted=!1,this.callbacks=[],this.timeLeftMS=t,this.timeoutMS=t,this.callbacks.push(e)}tick(){if(!this.isCancelled&&!this.isTimeExhausted&&(this.timeLeftMS--,this.timeLeftMS<=0)){this.isTimeExhausted=!0;var e=this.callbacks.slice();this.callbacks.length=0,e.forEach(e=>{try{e()}catch(e){console.error(`TimeoutLatch callback error:`,e)}})}}cancel(){this.isCancelled=!0,this.callbacks.length=0}reset(){this.timeLeftMS=this.timeoutMS,this.isCancelled=!1,this.isTimeExhausted=!1}get isDone(){return this.isCancelled||this.isTimeExhausted}},Ki=class{constructor(){this.interval=null,this.latches=new Set}add(e){this.latches.add(e),this.start()}remove(e){this.latches.delete(e),this.latches.size===0&&this.stop()}start(){this.interval===null&&(this.interval=setInterval(()=>{this.latches.forEach(e=>{e.tick(),e.isDone&&this.remove(e)})},1))}stop(){this.interval!==null&&(clearInterval(this.interval),this.interval=null)}},qi=null,Ji=()=>typeof window>`u`?new Ki:(qi||=new Ki,qi),Yi=O.define(),Xi=200,Zi=[];function Qi(e){var{value:t,selection:n,onChange:r,onStatistics:i,onCreateEditor:a,onUpdate:o,extensions:s=Zi,autoFocus:c,theme:l=`light`,height:u=null,minHeight:d=null,maxHeight:f=null,width:p=null,minWidth:m=null,maxWidth:h=null,placeholder:g=``,editable:ee=!0,readOnly:_=!1,indentWithTab:v=!0,basicSetup:y=!0,root:te,initialState:x}=e,[S,C]=(0,I.useState)(),[w,T]=(0,I.useState)(),[E,D]=(0,I.useState)(),O=(0,I.useState)(()=>({current:null}))[0],k=(0,I.useState)(()=>({current:null}))[0],ne=b.theme({"&":{height:u,minHeight:d,maxHeight:f,width:p,minWidth:m,maxWidth:h},"& .cm-scroller":{height:`100% !important`}}),A=[b.updateListener.of(e=>{e.docChanged&&typeof r==`function`&&!e.transactions.some(e=>e.annotation(Yi))&&(O.current?O.current.reset():(O.current=new Gi(()=>{if(k.current){var e=k.current;k.current=null,e()}O.current=null},Xi),Ji().add(O.current)),r(e.state.doc.toString(),e)),i&&i(Wi(e))}),ne,...Ui({theme:l,editable:ee,readOnly:_,placeholder:g,indentWithTab:v,basicSetup:y})];return o&&typeof o==`function`&&A.push(b.updateListener.of(o)),A=A.concat(s),(0,I.useLayoutEffect)(()=>{if(S&&!E){var e={doc:t,selection:n,extensions:A},r=x?xe.fromJSON(x.json,e,x.fields):xe.create(e);if(D(r),!w){var i=new b({state:r,parent:S,root:te});T(i),a&&a(i,r)}}return()=>{w&&(D(void 0),T(void 0))}},[S,E]),(0,I.useEffect)(()=>{e.container&&C(e.container)},[e.container]),(0,I.useEffect)(()=>()=>{w&&(w.destroy(),T(void 0)),O.current&&=(O.current.cancel(),null)},[w]),(0,I.useEffect)(()=>{c&&w&&w.focus()},[c,w]),(0,I.useEffect)(()=>{w&&w.dispatch({effects:P.reconfigure.of(A)})},[l,s,u,d,f,p,m,h,g,ee,_,v,y,r,o]),(0,I.useEffect)(()=>{if(t!==void 0){var e=w?w.state.doc.toString():``;if(w&&t!==e){var n=O.current&&!O.current.isDone,r=()=>{w&&t!==w.state.doc.toString()&&w.dispatch({changes:{from:0,to:w.state.doc.toString().length,insert:t||``},annotations:[Yi.of(!0)]})};n?k.current=r:r()}}},[t,w]),{state:E,setState:D,view:w,setView:T,container:S,setContainer:C}}var $=r(),$i=[`className`,`value`,`selection`,`extensions`,`onChange`,`onStatistics`,`onCreateEditor`,`onUpdate`,`autoFocus`,`theme`,`height`,`minHeight`,`maxHeight`,`width`,`minWidth`,`maxWidth`,`basicSetup`,`placeholder`,`indentWithTab`,`editable`,`readOnly`,`root`,`initialState`],ea=(0,I.forwardRef)((e,t)=>{var{className:n,value:r=``,selection:i,extensions:a=[],onChange:o,onStatistics:s,onCreateEditor:c,onUpdate:l,autoFocus:u,theme:d=`light`,height:f,minHeight:p,maxHeight:m,width:h,minWidth:g,maxWidth:ee,basicSetup:_,placeholder:v,indentWithTab:y,editable:b,readOnly:te,root:x,initialState:S}=e,C=Ke(e,$i),w=(0,I.useRef)(null),{state:T,view:E,container:D,setContainer:O}=Qi({root:x,value:r,autoFocus:u,theme:d,height:f,minHeight:p,maxHeight:m,width:h,minWidth:g,maxWidth:ee,basicSetup:_,placeholder:v,indentWithTab:y,editable:b,readOnly:te,selection:i,onChange:o,onStatistics:s,onCreateEditor:c,onUpdate:l,extensions:a,initialState:S});(0,I.useImperativeHandle)(t,()=>({editor:w.current,state:T,view:E}),[w,D,T,E]);var k=(0,I.useCallback)(e=>{w.current=e,O(e)},[O]);if(typeof r!=`string`)throw Error(`value must be typeof string but got `+typeof r);return(0,$.jsx)(`div`,Ge({ref:k,className:(typeof d==`string`?`cm-theme-`+d:`cm-theme`)+(n?` `+n:``)},C))});ea.displayName=`CodeMirror`;var ta=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`ico`]),na=`pdf`;function ra(e){return e.split(`.`).pop()?.toLowerCase()??``}function ia(e){switch(ra(e)){case`js`:case`jsx`:return Se({jsx:!0});case`ts`:case`tsx`:return Se({jsx:!0,typescript:!0});case`py`:return re();case`html`:return De();case`css`:case`scss`:return pe();case`json`:return be();case`md`:case`mdx`:return ke();default:return null}}function aa({metadata:e,tabId:t}){let n=e?.filePath,r=e?.projectName,[a,o]=(0,I.useState)(null),[s,c]=(0,I.useState)(`utf-8`),[l,u]=(0,I.useState)(!0),[d,f]=(0,I.useState)(null),[p,m]=(0,I.useState)(!1),h=(0,I.useRef)(null),g=(0,I.useRef)(``),{tabs:ee,updateTab:_}=Ve(),{wordWrap:v,toggleWordWrap:y}=He(),te=(0,I.useRef)(y);(0,I.useEffect)(()=>{te.current=y},[y]);let x=(0,I.useMemo)(()=>b.domEventHandlers({keydown(e){return e.altKey&&(e.key===`z`||e.key===`Z`)?(e.preventDefault(),te.current(),!0):!1},beforeinput(e){return e.data===`Ω`?(e.preventDefault(),!0):!1}}),[]),S=ee.find(e=>e.id===t),C=n?ra(n):``,w=ta.has(C),T=C===na,E=C===`md`||C===`mdx`,[D,O]=(0,I.useState)(`preview`);(0,I.useEffect)(()=>{if(!(!n||!r)){if(w||T){u(!1);return}return u(!0),f(null),ze.get(`${Re(r)}/files/read?path=${encodeURIComponent(n)}`).then(e=>{o(e.content),c(e.encoding),g.current=e.content,u(!1)}).catch(e=>{f(e instanceof Error?e.message:`Failed to load file`),u(!1)}),()=>{h.current&&clearTimeout(h.current)}}},[n,r,w,T]),(0,I.useEffect)(()=>{if(!S)return;let e=n?.split(`/`).pop()??`Untitled`,t=p?`${e} \u25CF`:e;S.title!==t&&_(S.id,{title:t})},[p]);let k=(0,I.useCallback)(async e=>{if(!(!n||!r))try{await ze.put(`${Re(r)}/files/write`,{path:n,content:e}),m(!1)}catch{}},[n,r]);function ne(e){o(e),g.current=e,m(!0),h.current&&clearTimeout(h.current),h.current=setTimeout(()=>{k(g.current)},1e3)}if(!n||!r)return(0,$.jsx)(`div`,{className:`flex items-center justify-center h-full text-text-secondary text-sm`,children:`No file selected.`});if(l)return(0,$.jsxs)(`div`,{className:`flex items-center justify-center h-full gap-2 text-text-secondary`,children:[(0,$.jsx)(Be,{className:`size-5 animate-spin`}),(0,$.jsx)(`span`,{className:`text-sm`,children:`Loading file...`})]});if(d)return(0,$.jsx)(`div`,{className:`flex items-center justify-center h-full text-error text-sm`,children:d});if(w)return(0,$.jsx)(sa,{filePath:n,projectName:r});if(T)return(0,$.jsx)(ca,{filePath:n,projectName:r});if(s===`base64`)return(0,$.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,$.jsx)(We,{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})]});let re=[],j=ia(n);j&&re.push(j),v&&re.push(b.lineWrapping),re.push(x);let ie=E?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>O(`edit`),className:`flex items-center gap-1 px-2 py-1 rounded text-xs transition-colors ${D===`edit`?`bg-muted text-foreground`:`text-muted-foreground hover:text-foreground`}`,children:[(0,$.jsx)(i,{className:`size-3`}),`Edit`]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>O(`preview`),className:`flex items-center gap-1 px-2 py-1 rounded text-xs transition-colors ${D===`preview`?`bg-muted text-foreground`:`text-muted-foreground hover:text-foreground`}`,children:[(0,$.jsx)(Ue,{className:`size-3`}),`Preview`]})]}):null,ae=(0,$.jsxs)(`button`,{type:`button`,onClick:y,title:`Toggle word wrap (Alt+Z)`,className:`flex items-center gap-1 px-2 py-1 rounded text-xs transition-colors ${v?`bg-muted text-foreground`:`text-muted-foreground hover:text-foreground`}`,children:[(0,$.jsx)(A,{className:`size-3`}),(0,$.jsx)(`span`,{className:`hidden sm:inline`,children:`Wrap`})]});return(0,$.jsxs)(`div`,{className:`flex flex-col h-full w-full overflow-hidden`,children:[(0,$.jsxs)(`div`,{className:`hidden md:flex items-center gap-1 px-2 py-1 border-b shrink-0 bg-background`,children:[ie,(0,$.jsx)(`div`,{className:`flex-1`}),ae]}),E&&D===`preview`?(0,$.jsx)(oa,{content:a??``}):(0,$.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:(0,$.jsx)(ea,{value:a??``,onChange:ne,extensions:re,theme:Oe,height:`100%`,style:{height:`100%`,fontSize:`13px`,fontFamily:`var(--font-mono)`},basicSetup:{lineNumbers:!0,foldGutter:!0,autocompletion:!0,bracketMatching:!0,closeBrackets:!0,highlightActiveLine:!0,indentOnInput:!0}})}),(0,$.jsxs)(`div`,{className:`md:hidden flex items-center gap-1 px-2 py-1 border-t shrink-0 bg-background`,children:[ie,(0,$.jsx)(`div`,{className:`flex-1`}),ae]})]})}function oa({content:e}){return(0,$.jsx)(`div`,{className:`flex-1 overflow-auto p-4 markdown-content prose-sm`,dangerouslySetInnerHTML:{__html:(0,I.useMemo)(()=>{try{return a.parse(e,{gfm:!0,breaks:!0})}catch{return e}},[e])}})}function sa({filePath:e,projectName:t}){let[n,r]=(0,I.useState)(null),[i,a]=(0,I.useState)(!1);return(0,I.useEffect)(()=>{let n,i=`${Re(t)}/files/raw?path=${encodeURIComponent(e)}`,o=Le();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)(We,{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)(Be,{className:`size-5 animate-spin text-text-subtle`})})}function ca({filePath:e,projectName:t}){let[n,r]=(0,I.useState)(null),[i,a]=(0,I.useState)(!1);(0,I.useEffect)(()=>{let n,i=`${Re(t)}/files/raw?path=${encodeURIComponent(e)}`,o=Le();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(new Blob([e],{type:`application/pdf`}));n=t,r(t)}).catch(()=>a(!0)),()=>{n&&URL.revokeObjectURL(n)}},[e,t]);let s=(0,I.useCallback)(()=>{n&&window.open(n,`_blank`)},[n]);return i?(0,$.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,$.jsx)(We,{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)(o,{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)(Be,{className:`size-5 animate-spin text-text-subtle`})})}export{aa as CodeEditor};