openfox 1.6.100 → 1.6.101

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 (28) hide show
  1. package/dist/{auto-compaction-NLUAT562.js → auto-compaction-JSXVY2CJ.js} +5 -5
  2. package/dist/{chat-handler-5KT442LF.js → chat-handler-45TB6QWI.js} +8 -8
  3. package/dist/{chunk-PFSOVCEN.js → chunk-5LYWA56Z.js} +18 -10
  4. package/dist/{chunk-MEOKWBXX.js → chunk-C5U6NRAY.js} +10 -6
  5. package/dist/{chunk-VMRDLSNP.js → chunk-L6LTCUCO.js} +3 -3
  6. package/dist/{chunk-BZBT5VJL.js → chunk-MBLZSLPH.js} +1 -1
  7. package/dist/{chunk-Y532ULQ2.js → chunk-NASF624P.js} +3 -3
  8. package/dist/{chunk-IB3TCZF7.js → chunk-SBQ36AOQ.js} +3 -3
  9. package/dist/{chunk-KOQOPNE5.js → chunk-SCAFZ75C.js} +28 -34
  10. package/dist/{chunk-X3GA33UG.js → chunk-UTBDR6KM.js} +1 -1
  11. package/dist/cli/dev.js +1 -1
  12. package/dist/cli/index.js +1 -1
  13. package/dist/{events-QBKF32WS.js → events-JP746DV3.js} +2 -2
  14. package/dist/{orchestrator-4GHZFEGT.js → orchestrator-RRO2XLYZ.js} +6 -6
  15. package/dist/package.json +1 -1
  16. package/dist/{processor-I3WKCUAE.js → processor-C4KLV5SV.js} +6 -6
  17. package/dist/{protocol-eKAFeMXn.d.ts → protocol-BkFgSJVU.d.ts} +1 -0
  18. package/dist/{protocol-GKGDN64O.js → protocol-SVQYBN2X.js} +3 -3
  19. package/dist/{serve-CJEAHPPU.js → serve-5B36ZPK3.js} +7 -7
  20. package/dist/server/index.d.ts +1 -1
  21. package/dist/server/index.js +6 -6
  22. package/dist/shared/index.d.ts +2 -2
  23. package/dist/shared/index.js +1 -1
  24. package/dist/{tools-UBURWNND.js → tools-AGVKG553.js} +5 -5
  25. package/dist/web/assets/{index-DzlTckHS.js → index-Du9Uz0qZ.js} +1 -1
  26. package/dist/web/index.html +1 -1
  27. package/dist/web/sw.js +1 -1
  28. package/package.json +1 -1
@@ -55,7 +55,7 @@ Error generating stack: `+g.message+`
55
55
  *
56
56
  * This source code is licensed under the MIT license found in the
57
57
  * LICENSE file in the root directory of this source tree.
58
- */var uv;function d2(){if(uv)return Sf;uv=1;var e=ku();function t(m,x){return m===x&&(m!==0||1/m===1/x)||m!==m&&x!==x}var n=typeof Object.is=="function"?Object.is:t,s=e.useState,a=e.useEffect,o=e.useLayoutEffect,c=e.useDebugValue;function l(m,x){var _=x(),w=s({inst:{value:_,getSnapshot:x}}),k=w[0].inst,v=w[1];return o(function(){k.value=_,k.getSnapshot=x,h(k)&&v({inst:k})},[m,_,x]),a(function(){return h(k)&&v({inst:k}),m(function(){h(k)&&v({inst:k})})},[m]),c(_),_}function h(m){var x=m.getSnapshot;m=m.value;try{var _=x();return!n(m,_)}catch{return!0}}function f(m,x){return x()}var p=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?f:l;return Sf.useSyncExternalStore=e.useSyncExternalStore!==void 0?e.useSyncExternalStore:p,Sf}var dv;function h2(){return dv||(dv=1,bf.exports=d2()),bf.exports}var f2=h2();const m2=QE.useInsertionEffect,p2=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",g2=p2?M.useLayoutEffect:M.useEffect,x2=m2||g2,X0=e=>{const t=M.useRef([e,(...n)=>t[0](...n)]).current;return x2(()=>{t[0]=e}),t[1]},_2="popstate",Xm="pushState",Qm="replaceState",y2="hashchange",hv=[_2,Xm,Qm,y2],v2=e=>{for(const t of hv)addEventListener(t,e);return()=>{for(const t of hv)removeEventListener(t,e)}},Q0=(e,t)=>f2.useSyncExternalStore(v2,e,t),fv=()=>location.search,b2=({ssrSearch:e}={})=>Q0(fv,e!=null?()=>e:fv),mv=()=>location.pathname,S2=({ssrPath:e}={})=>Q0(mv,e!=null?()=>e:mv),w2=(e,{replace:t=!1,state:n=null}={})=>history[t?Qm:Xm](n,"",e),C2=(e={})=>[S2(e),w2],pv=Symbol.for("wouter_v3");if(typeof history<"u"&&typeof window[pv]>"u"){for(const e of[Xm,Qm]){const t=history[e];history[e]=function(){const n=t.apply(this,arguments),s=new Event(e);return s.arguments=arguments,dispatchEvent(s),n}}Object.defineProperty(window,pv,{value:!0})}const k2=(e,t)=>t.toLowerCase().indexOf(e.toLowerCase())?"~"+t:t.slice(e.length)||"/",J0=(e="")=>e==="/"?"":e,E2=(e,t)=>e[0]==="~"?e.slice(1):J0(t)+e,j2=(e="",t)=>k2(gv(J0(e)),gv(t)),gv=e=>{try{return decodeURI(e)}catch{return e}},Z0={hook:C2,searchHook:b2,parser:u2,base:"",ssrPath:void 0,ssrSearch:void 0,ssrContext:void 0,hrefs:e=>e,aroundNav:(e,t,n)=>e(t,n)},eS=M.createContext(Z0),Oa=()=>M.useContext(eS),tS={},nS=M.createContext(tS),T2=()=>M.useContext(nS),ju=e=>{const[t,n]=e.hook(e);return[j2(e.base,t),X0((s,a)=>e.aroundNav(n,E2(s,e.base),a))]},gr=()=>ju(Oa()),Jm=(e,t,n,s)=>{const{pattern:a,keys:o}=t instanceof RegExp?{keys:!1,pattern:t}:e(t||"*",s),c=a.exec(n)||[],[l,...h]=c;return l!==void 0?[!0,(()=>{const f=o!==!1?Object.fromEntries(o.map((m,x)=>[m,h[x]])):c.groups;let p={...h};return f&&Object.assign(p,f),p})(),...s?[l]:[]]:[!1,null]},Zm=e=>Jm(Oa().parser,e,gr()[0]),N2=({children:e,...t})=>{var p,m,x;const n=Oa(),s=t.hook?Z0:n;let a=s;const[o,c=t.ssrSearch??""]=((p=t.ssrPath)==null?void 0:p.split("?"))??[];o&&(t.ssrSearch=c,t.ssrPath=o),t.hrefs=t.hrefs??((m=t.hook)==null?void 0:m.hrefs),t.searchHook=t.searchHook??((x=t.hook)==null?void 0:x.searchHook);let l=M.useRef({}),h=l.current,f=h;for(let _ in s){const w=_==="base"?s[_]+(t[_]??""):t[_]??s[_];h===f&&w!==f[_]&&(l.current=f={...f}),f[_]=w,(w!==s[_]||w!==a[_])&&(a=f)}return M.createElement(eS.Provider,{value:a,children:e})},xv=({children:e,component:t},n)=>t?M.createElement(t,{params:n}):typeof e=="function"?e(n):e,A2=e=>{let t=M.useRef(tS);const n=t.current;return t.current=Object.keys(e).length!==Object.keys(n).length||Object.entries(e).some(([s,a])=>a!==n[s])?e:n},Ro=({path:e,nest:t,match:n,...s})=>{const a=Oa(),[o]=ju(a),[c,l,h]=n??Jm(a.parser,e,o,t),f=A2({...T2(),...l});if(!c)return null;const p=h?M.createElement(N2,{base:h},xv(s,f)):xv(s,f);return M.createElement(nS.Provider,{value:f,children:p})},Fn=M.forwardRef((e,t)=>{const n=Oa(),[s,a]=ju(n),{to:o="",href:c=o,onClick:l,asChild:h,children:f,className:p,replace:m,state:x,transition:_,...w}=e,k=X0(b=>{b.ctrlKey||b.metaKey||b.altKey||b.shiftKey||b.button!==0||(l==null||l(b),b.defaultPrevented||(b.preventDefault(),a(c,e)))}),v=n.hrefs(c[0]==="~"?c.slice(1):n.base+c,n);return h&&M.isValidElement(f)?M.cloneElement(f,{onClick:k,href:v}):M.createElement("a",{...w,onClick:k,href:v,className:p!=null&&p.call?p(s===c):p,children:f,ref:t})}),rS=e=>Array.isArray(e)?e.flatMap(t=>rS(t&&t.type===M.Fragment?t.props.children:t)):[e],L2=({children:e,location:t})=>{const n=Oa(),[s]=ju(n);for(const a of rS(e)){let o=0;if(M.isValidElement(a)&&(o=Jm(n.parser,a.props.path,t||s,a.props.nest))[0])return M.cloneElement(a,{match:o})}return null};function D2(e){return typeof e=="object"&&e!==null&&"type"in e&&"payload"in e}function sS(){if(typeof crypto<"u"&&crypto.randomUUID)try{return crypto.randomUUID()}catch{}return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){const t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}class R2{constructor(t){he(this,"ws",null);he(this,"handlers",new Set);he(this,"statusHandler",null);he(this,"baseUrl");he(this,"isReconnecting",!1);he(this,"connectingPromise",null);he(this,"lastCloseCode",0);he(this,"reconnectAttempts",0);he(this,"manualReconnectScheduled",!1);this.baseUrl=t}getUrl(){const t=localStorage.getItem("openfox_token");if(t){const n=this.baseUrl.includes("?")?"&":"?";return`${this.baseUrl}${n}token=${encodeURIComponent(t)}`}return this.baseUrl}setToken(t){localStorage.setItem("openfox_token",t)}clearToken(){localStorage.removeItem("openfox_token")}hasToken(){return!!localStorage.getItem("openfox_token")}getLastCloseCode(){return this.lastCloseCode}onStatusChange(t){this.statusHandler=t}connect(){var t,n,s;return((t=this.ws)==null?void 0:t.readyState)===WebSocket.OPEN?Promise.resolve():(this.lastCloseCode=0,this.isReconnecting=!1,this.connectingPromise&&((n=this.ws)==null?void 0:n.readyState)===WebSocket.CONNECTING?this.connectingPromise:(this.lastCloseCode=0,this.isReconnecting=!1,this.connectingPromise&&((s=this.ws)==null?void 0:s.readyState)===WebSocket.CONNECTING?(console.warn("[WS CLIENT] Connection already in progress, returning existing promise"),this.connectingPromise):(this.connectingPromise=new Promise((a,o)=>{try{const c=this.getUrl();this.ws=new WebSocket(c);const l=setTimeout(()=>{var h;((h=this.ws)==null?void 0:h.readyState)===WebSocket.CONNECTING&&(this.ws.close(),o(new Error("Connection timeout")))},5e3);this.ws.onopen=()=>{var h;clearTimeout(l),this.isReconnecting=!1,this.connectingPromise=null,(h=this.statusHandler)==null||h.call(this,"connected"),a()},this.ws.onclose=h=>{var f,p,m;clearTimeout(l),this.lastCloseCode=h.code,((f=this.ws)==null?void 0:f.readyState)===WebSocket.CONNECTING?(this.connectingPromise=null,(p=this.statusHandler)==null||p.call(this,"disconnected"),o(new Error(`Connection closed: ${h.code}`))):(this.connectingPromise=null,(m=this.statusHandler)==null||m.call(this,"disconnected"),this.attemptReconnect())},this.ws.onerror=h=>{clearTimeout(l),console.error("WebSocket error:",h),this.connectingPromise=null,o(h)},this.ws.onmessage=h=>{try{const f=JSON.parse(h.data);D2(f)&&this.handlers.forEach(p=>p(f))}catch(f){console.error("Failed to parse WebSocket message:",f)}}}catch(c){this.connectingPromise=null,o(c)}}),this.connectingPromise)))}attemptReconnect(){var a;if(([1e3,1005,1006,4e3].includes(this.lastCloseCode)||this.lastCloseCode===0)&&this.hasToken()){console.warn("[WS] Auth failure or initial failure with token - not auto-reconnecting, awaiting user action");return}if(this.isReconnecting||this.manualReconnectScheduled)return;this.isReconnecting=!0,(a=this.statusHandler)==null||a.call(this,"reconnecting");const s=Math.min(1e3*Math.pow(2,this.reconnectAttempts||0),3e4);this.reconnectAttempts=(this.reconnectAttempts||0)+1,setTimeout(()=>{this.isReconnecting=!1,this.manualReconnectScheduled=!1,this.connect().catch(()=>{})},s)}reconnect(){this.manualReconnectScheduled=!0,this.isReconnecting=!1,this.lastCloseCode=0,this.connectingPromise=null,this.connect().catch(()=>{})}disconnect(){this.isReconnecting=!1,this.reconnectAttempts=0,this.ws&&(this.ws.close(),this.ws=null)}resetReconnectAttempts(){this.reconnectAttempts=0}send(t,n){if(!this.ws||this.ws.readyState!==WebSocket.OPEN)throw new Error("WebSocket not connected");const s=sS(),a={id:s,type:t,payload:n};return this.ws.send(JSON.stringify(a)),s}subscribe(t){return this.handlers.add(t),()=>this.handlers.delete(t)}get isConnected(){var t;return((t=this.ws)==null?void 0:t.readyState)===WebSocket.OPEN}}const O2=window.location.protocol==="https:"?"wss:":"ws:";let fm=window.location.port;fm||(fm=window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"?"10469":window.location.protocol==="https:"?"443":"80");const M2=`${O2}//${window.location.hostname}:${fm}/ws`,Kt=new R2(M2);function I2(e){return{...e.temperature!=null&&{temperature:e.temperature},...e.topP!=null&&{topP:e.topP},...e.topK!=null&&{topK:e.topK},...e.maxTokens!=null&&{maxTokens:e.maxTokens}}}async function _v(e,t,n){const s=await je(`/api/providers/${e}/models/${encodeURIComponent(t)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(!s.ok){const a=await s.json();throw new Error(a.error??"Failed to update model")}return s.json()}function yv(e,t,n,s){return e.map(a=>a.id===t?{...a,models:a.models.map(o=>o.id===n?{...o,...s,source:"user"}:o)}:a)}const P2=3e4;function mm(e){switch(e){case"vllm":return"vLLM";case"sglang":return"SGLang";case"ollama":return"Ollama";case"llamacpp":return"llama.cpp";case"openai":return"OpenAI";case"anthropic":return"Anthropic";case"opencode-go":return"OpenCode Go";case"auto":return"Auto";case"unknown":return""}}const jt=Gn((e,t)=>({version:null,model:null,maxContext:2e5,llmUrl:null,llmStatus:"unknown",backend:"unknown",providers:[],activeProviderId:null,defaultModelSelection:null,loading:!1,activating:!1,error:null,autoRefreshInterval:null,fetchConfig:async()=>{e({loading:!0,error:null});try{const n=await je("/api/config");if(!n.ok)throw new Error("Failed to fetch config");const s=await n.json();e({version:s.version,model:s.model,maxContext:s.maxContext,llmUrl:s.llmUrl,llmStatus:s.llmStatus,backend:s.backend,providers:s.providers??[],activeProviderId:s.activeProviderId??null,defaultModelSelection:s.defaultModelSelection??null,loading:!1})}catch(n){e({error:n instanceof Error?n.message:"Unknown error",loading:!1})}},refreshModel:async()=>{try{const n=await je("/api/model/refresh",{method:"POST"});if(!n.ok)throw new Error("Failed to refresh model");const s=await n.json(),o=we.getState().currentSession;if(o!=null&&o.providerId&&o.providerModel){e({llmStatus:s.llmStatus,backend:s.backend});return}e({model:s.model,llmStatus:s.llmStatus,backend:s.backend})}catch(n){console.error("Failed to refresh model:",n)}},activateProvider:async n=>{const{activeProviderId:s,providers:a}=t();if(n===s)return!0;e({activating:!0,error:null});try{const o=await je(`/api/providers/${n}/activate`,{method:"POST"});if(!o.ok){const l=await o.json();throw new Error(l.error??"Failed to activate provider")}const c=await o.json();return e({activeProviderId:c.activeProviderId,model:c.model,backend:c.backend,providers:a.map(l=>({...l,isActive:l.id===c.activeProviderId})),activating:!1}),!0}catch(o){return e({error:o instanceof Error?o.message:"Failed to switch provider",activating:!1}),!1}},syncFromSession:(n,s)=>{var l;const{providers:a,defaultModelSelection:o}=t();let c=s;if(!c){const h=o?o.split("/"):[],f=h[0],p=h.slice(1).join("/")??"";if(f===n&&p)c=p;else{const m=a.find(x=>x.id===n);c=((l=m==null?void 0:m.models[0])==null?void 0:l.id)??""}}e({activeProviderId:n,model:c,defaultModelSelection:`${n}/${c}`,providers:a.map(h=>({...h,isActive:h.id===n}))})},updateModelContext:async(n,s,a)=>{e({activating:!0,error:null});try{const o=await _v(n,s,{contextWindow:a}),{providers:c}=t();return e({providers:yv(c,n,s,{contextWindow:a}),activating:!1}),o.contextState&&we.getState().updateContextState(o.contextState),!0}catch(o){return e({error:o instanceof Error?o.message:"Failed to update model context",activating:!1}),!1}},updateModelSettings:async(n,s,a)=>{e({activating:!0,error:null});try{const o=await _v(n,s,a),{providers:c}=t(),l={...a.contextWindow!==void 0&&{contextWindow:a.contextWindow},...I2({temperature:a.temperature??void 0,topP:a.topP??void 0,topK:a.topK??void 0,maxTokens:a.maxTokens??void 0}),...a.supportsVision!==void 0&&{supportsVision:a.supportsVision}};return e({providers:yv(c,n,s,l),activating:!1}),o.contextState&&we.getState().updateContextState(o.contextState),!0}catch(o){return e({error:o instanceof Error?o.message:"Failed to update model settings",activating:!1}),!1}},refreshProviderModels:async n=>{e({activating:!0,error:null});try{const s=await je(`/api/providers/${n}/refresh`,{method:"POST"});if(!s.ok){const c=await s.json();throw new Error(c.error??"Failed to refresh models")}const a=await s.json(),{providers:o}=t();return e({providers:o.map(c=>c.id===n?{...c,models:a.models,status:a.status}:c),activating:!1}),!0}catch(s){return e({error:s instanceof Error?s.message:"Failed to refresh models",activating:!1}),!1}},startAutoRefresh:()=>{const{autoRefreshInterval:n,refreshModel:s}=t();if(n)return;const a=setInterval(()=>{s()},P2);e({autoRefreshInterval:a})},stopAutoRefresh:()=>{const{autoRefreshInterval:n}=t();n&&(clearInterval(n),e({autoRefreshInterval:null}))},getActiveProvider:()=>{const{providers:n,activeProviderId:s}=t();return n.find(a=>a.id===s)},getModelContext:n=>{const{providers:s,activeProviderId:a}=t(),o=s.find(l=>l.id===a);if(!o)return 2e5;const c=o.models.find(l=>l.id===n);return(c==null?void 0:c.contextWindow)??2e5}})),Lt=Gn((e,t)=>({projects:[],currentProject:null,loading:!1,listProjects:async()=>{e({loading:!0});try{const s=await(await je("/api/projects")).json();e({projects:s.projects??[],loading:!1})}catch(n){console.error("Failed to load projects:",n),e({loading:!1})}},createProject:async(n,s)=>{try{const a=await je("/api/projects",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:n,workdir:s})});if(!a.ok){const c=await a.json().catch(()=>({}));return{error:{code:c.code||"UNKNOWN",path:c.path,message:c.error}}}const o=await a.json();return await t().listProjects(),o.project}catch{return null}},loadProject:async n=>{try{const s=await je(`/api/projects/${n}`);if(!s.ok)return null;const a=await s.json();return e({currentProject:a.project}),t().projects.length===0&&await t().listProjects(),a.project}catch{return null}},updateProject:async(n,s)=>{var a;try{const o=await je(`/api/projects/${n}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});if(!o.ok)return null;const c=await o.json();return((a=t().currentProject)==null?void 0:a.id)===n&&e({currentProject:c.project}),await t().listProjects(),c.project}catch{return null}},deleteProject:async n=>{var s;try{return(await je(`/api/projects/${n}`,{method:"DELETE"})).ok?(await t().listProjects(),((s=t().currentProject)==null?void 0:s.id)===n&&e({currentProject:null}),!0):!1}catch{return!1}},toggleStar:async(n,s)=>{var a;try{const o=await je(`/api/projects/${n}/star`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({isStarred:s})});if(!o.ok)return!1;if(((a=t().currentProject)==null?void 0:a.id)===n){const c=await o.json();e({currentProject:c.project})}return await t().listProjects(),!0}catch{return!1}},clearProject:()=>{e({currentProject:null})}})),Us=async(e,t,n)=>{try{const s=await je(t,{method:e,headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});return s.ok?{success:!0}:{success:!1,error:(await s.json()).error}}catch{return{success:!1,error:"Network error"}}},Tu=async(e,t,n)=>{try{const s=await je(e,{method:"POST",body:n?JSON.stringify({destination:n}):void 0,headers:n?{"Content-Type":"application/json"}:void 0}),a=await s.json();return s.ok?(await t(),{success:!0}):{success:!1,error:a.error??"Failed to duplicate"}}catch{return{success:!1,error:"Network error"}}};function iS(e){let t=null;function n(){t===null&&(t=requestAnimationFrame(()=>{t=null,e()}))}return n}let Oc=[];const Ko=Gn()((e,t)=>{function n(){if(Oc.length===0)return;const a=Oc;Oc=[],e(o=>{const c={...o.logs};for(const l of a){const h=c[l.processId]??[];c[l.processId]=[...h,{offset:h.length,content:l.content,timestamp:Date.now(),stream:l.stream}]}return{logs:c}})}const s=iS(n);return{processes:[],logs:{},loading:!1,setProcesses:a=>e({processes:a}),addProcess:a=>e(o=>({processes:[...o.processes,a]})),updateProcess:(a,o)=>e(c=>({processes:c.processes.map(l=>l.id===a?{...l,...o}:l)})),removeProcess:a=>e(o=>({processes:o.processes.filter(c=>c.id!==a),logs:Object.fromEntries(Object.entries(o.logs).filter(([c])=>c!==a))})),stopProcess:async(a,o)=>{try{(await je(`/api/sessions/${o}/background-process/${a}/stop`,{method:"POST"})).ok&&t().removeProcess(a)}catch{}},appendLog:(a,o,c)=>{Oc.push({processId:a,stream:o,content:c}),s()},setLogs:(a,o)=>e(c=>({logs:{...c.logs,[a]:o}})),clearLogs:a=>e(o=>({logs:{...o.logs,[a]:[]}})),handleMessage:(a,o)=>{switch(a){case"backgroundProcess.started":{const{processId:c,name:l,pid:h,status:f}=o;e(p=>({processes:[...p.processes,{id:c,sessionId:"",name:l,command:"",cwd:"",pid:h,status:f,exitCode:null,createdAt:Date.now(),startedAt:Date.now(),endedAt:null}]}));break}case"backgroundProcess.output":{const c=o.processId,l=o.stream,h=o.content;t().appendLog(c,l,h);break}case"backgroundProcess.exited":{const c=o.processId,l=o.exitCode;e(h=>({processes:h.processes.map(f=>f.id===c?{...f,status:"exited",exitCode:l}:f)}));break}case"backgroundProcess.removed":{const c=o.processId;t().removeProcess(c);break}}}}}),B2={messageId:null,deltaContent:"",thinkingContent:"",toolOutput:[]};let Ea=null,Jc=null;function z2(e){Jc=e}function fi(){return B2}function wf(){Ea===null&&(Ea=requestAnimationFrame(()=>{Ea=null,Jc==null||Jc()}))}function xi(){Ea!==null&&(cancelAnimationFrame(Ea),Ea=null)}let Mc=[];const jr=Gn()((e,t)=>{function n(){if(Mc.length===0)return;const a=Mc;Mc=[],e(o=>({logs:[...o.logs,...a]}))}const s=iS(n);return{workdir:null,status:null,logs:[],config:null,loading:!1,setWorkdir:a=>{t().workdir!==a&&(e({workdir:a,status:null,logs:[],config:null,loading:!0}),a&&(t().fetchStatus(),t().fetchConfig()))},fetchStatus:async()=>{const a=t().workdir;if(a)try{const c=await(await je(`/api/dev-server?workdir=${encodeURIComponent(a)}`)).json();e({status:c,loading:!1})}catch{e({loading:!1})}},fetchConfig:async()=>{const a=t().workdir;if(a)try{const c=await(await je(`/api/dev-server/config?workdir=${encodeURIComponent(a)}`)).json();e({config:c.config??null})}catch{}},fetchLogs:async()=>{const a=t().workdir;if(a)try{const l=(await(await je(`/api/dev-server/logs?workdir=${encodeURIComponent(a)}`)).json()).logs.map(h=>({stream:h.stream,content:h.content}));e({logs:l})}catch{}},start:async()=>{const a=t().workdir;if(a)try{const c=await(await je(`/api/dev-server/start?workdir=${encodeURIComponent(a)}`,{method:"POST"})).json();e({status:c,logs:[]})}catch{}},stop:async()=>{const a=t().workdir;if(a)try{const c=await(await je(`/api/dev-server/stop?workdir=${encodeURIComponent(a)}`,{method:"POST"})).json();e({status:c})}catch{}},restart:async()=>{const a=t().workdir;if(a)try{const c=await(await je(`/api/dev-server/restart?workdir=${encodeURIComponent(a)}`,{method:"POST"})).json();e({status:c,logs:[]})}catch{}},saveConfig:async a=>{const o=t().workdir;if(o)try{const l=await(await je(`/api/dev-server/config?workdir=${encodeURIComponent(o)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)})).json();e({config:l.config??a}),t().fetchStatus()}catch{}},handleMessage:a=>{const o=t().workdir;if(o)switch(a.type){case"devServer.output":{const c=a.payload;if(c.workdir!==o)return;Mc.push({stream:c.stream,content:c.content}),s();break}case"devServer.state":{const c=a.payload;if(c.workdir!==o)return;e(l=>({status:l.status?{...l.status,state:c.state,errorMessage:c.errorMessage}:l.status}));break}}}}}),H2=[{key:"complete",label:"Task Complete",description:"When an agent finishes its work"},{key:"waiting_for_user",label:"Waiting for Input",description:"When the agent needs your input"},{key:"phase_done",label:"Phase Done",description:"When a build phase completes successfully"},{key:"phase_blocked",label:"Phase Blocked",description:"When a build phase is blocked and needs intervention"},{key:"new_message",label:"New Message",description:"When a new assistant message starts arriving"}],$2=[{url:"/sounds/notification.mp3",label:"Notification"},{url:"/sounds/waiting-for-user.mp3",label:"Waiting for User"},{url:"/sounds/achievement.mp3",label:"Achievement"},{url:"/sounds/intervention.mp3",label:"Intervention"},{url:"/sounds/typing.mp3",label:"Typing"}],aS={complete:"/sounds/notification.mp3",waiting_for_user:"/sounds/waiting-for-user.mp3",phase_done:"/sounds/achievement.mp3",phase_blocked:"/sounds/intervention.mp3",new_message:"/sounds/typing.mp3"},Bs={soundEnabled:!0,browserNotification:!1,customSoundUrl:null},oS={soundEnabled:!1,browserNotification:!1,customSoundUrl:null},pm={soundEnabled:!0,browserNotificationEnabled:!1,events:{complete:{...Bs},waiting_for_user:{...Bs},phase_done:{...Bs},phase_blocked:{...Bs},new_message:{...oS}},agentOverrides:{}};function lS(e,t,n){var o;const s=e.events[t];if(!n)return s;const a=(o=e.agentOverrides[n])==null?void 0:o[t];return a?{soundEnabled:a.soundEnabled??s.soundEnabled,browserNotification:a.browserNotification??s.browserNotification,customSoundUrl:a.customSoundUrl!==void 0?a.customSoundUrl:s.customSoundUrl}:s}const pi=Gn((e,t)=>({settings:pm,loaded:!1,load:()=>{$t.getState().getSetting(Pe.NOTIFICATION_SETTINGS);const s=$t.subscribe(o=>{const c=o.settings[Pe.NOTIFICATION_SETTINGS];if(c!==void 0)try{const l=JSON.parse(c);e({settings:vv(l),loaded:!0})}catch{e({loaded:!0})}}),a=$t.getState().settings[Pe.NOTIFICATION_SETTINGS];if(a)try{const o=JSON.parse(a);e({settings:vv(o),loaded:!0})}catch{e({loaded:!0})}return s},update:n=>{e({settings:n}),Cf(n)},updateEvent:(n,s)=>{const a=t().settings,o={...a,events:{...a.events,[n]:{...a.events[n],...s}}};e({settings:o}),Cf(o)},updateAgentOverride:(n,s,a)=>{var h;const o=t().settings,c={...o.agentOverrides};if(a===null){if(c[n]){const f={...c[n]};delete f[s],Object.keys(f).length===0?delete c[n]:c[n]=f}}else c[n]={...c[n],[s]:{...((h=c[n])==null?void 0:h[s])??{},...a}};const l={...o,agentOverrides:c};e({settings:l}),Cf(l)}}));function Cf(e){$t.getState().setSetting(Pe.NOTIFICATION_SETTINGS,JSON.stringify(e))}function vv(e){var t,n,s,a,o;return{soundEnabled:e.soundEnabled??pm.soundEnabled,browserNotificationEnabled:e.browserNotificationEnabled??pm.browserNotificationEnabled,events:{complete:{...Bs,...(t=e.events)==null?void 0:t.complete},waiting_for_user:{...Bs,...(n=e.events)==null?void 0:n.waiting_for_user},phase_done:{...Bs,...(s=e.events)==null?void 0:s.phase_done},phase_blocked:{...Bs,...(a=e.events)==null?void 0:a.phase_blocked},new_message:{...oS,...(o=e.events)==null?void 0:o.new_message}},agentOverrides:e.agentOverrides??{}}}const bv=new Map;function U2(e){let t=bv.get(e);return t||(t=new Audio(e),t.volume=.5,bv.set(e,t)),t}let cS=typeof Notification<"u"?Notification.permission:"denied";function F2(){return typeof Notification>"u"?Promise.resolve("denied"):Notification.requestPermission().then(e=>(cS=e,e))}const V2={complete:"Task Complete",waiting_for_user:"Waiting for Input",phase_done:"Phase Complete",phase_blocked:"Phase Blocked",new_message:"New Message"},G2={complete:"The agent has finished its work.",waiting_for_user:"The agent needs your input to continue.",phase_done:"The build phase completed successfully.",phase_blocked:"The build phase is blocked and needs intervention.",new_message:"A new assistant message is arriving."};function W2(e){typeof Notification>"u"||cS==="granted"&&(document.hasFocus()||new Notification(V2[e],{body:G2[e],icon:"/fox.svg",tag:`openfox-${e}`}))}function ul(e,t){const{settings:n}=pi.getState(),s=lS(n,e,t);if(n.soundEnabled&&s.soundEnabled){const a=s.customSoundUrl??aS[e],o=U2(a);o.currentTime=0,o.play().catch(()=>{})}n.browserNotificationEnabled&&s.browserNotification&&W2(e)}const q2=e=>ul("complete",e),K2=e=>ul("phase_done",e),Y2=e=>ul("phase_blocked",e),Sv=e=>ul("waiting_for_user",e),X2=e=>ul("new_message",e),wv=new Map;function Go(e,t){var o;const n=t===((o=e.currentSession)==null?void 0:o.id)?e.currentSession:null,s=e.sessions.find(c=>c.id===t),a=(n==null?void 0:n.mode)??(s==null?void 0:s.mode);return a==="planner"?"planner":a==="builder"?"build":"planner"}function Q2(e,t){if(e.type==="chat.done"){const n=e.payload,s=Go(t,e.sessionId),a=n.agentType??s;n.reason==="complete"&&q2(a),n.reason==="waiting_for_user"&&Sv(a);return}if(e.type==="chat.path_confirmation"){const n=Go(t,e.sessionId);Sv(n);return}if(e.type==="task.completed"){const n=Go(t,e.sessionId);K2(n);return}if(e.type==="phase.changed"&&e.sessionId){const n=e.payload,s=wv.get(e.sessionId)??null;if(wv.set(e.sessionId,n.phase),s===n.phase)return;const a=Go(t,e.sessionId);n.phase==="blocked"&&Y2(a)}}const kf=new Set;function qt(e,t){return t!==null&&e.sessionId===t}function J2(e,t,n){return e.id!==void 0||qt(e,t)||n===!0&&e.sessionId!==void 0}function Z2(e,t){return e.includes(t)?e:[...e,t]}function Cv(e,t){return e.filter(n=>n!==t)}function ej(e,t){const n=e.find(o=>o.id===t.id),s=t.messageCount??t.messages.length,a=n?{...n,projectId:t.projectId,workdir:t.workdir,mode:t.mode,phase:t.phase,isRunning:t.isRunning&&n.isRunning!==!1,messageCount:s,criteriaCount:t.criteria.length,criteriaCompleted:t.criteria.filter(o=>o.status.type==="passed").length}:{id:t.id,projectId:t.projectId,workdir:t.workdir,mode:t.mode,phase:t.phase,isRunning:t.isRunning,createdAt:"",updatedAt:"",criteriaCount:t.criteria.length,criteriaCompleted:t.criteria.filter(o=>o.status.type==="passed").length,messageCount:s};return n?e.map(o=>o.id===t.id?a:o):[a,...e]}function tj(e,t,n){return e.map(s=>{const a=(n==null?void 0:n.id)===s.id?n:null,o=t.find(c=>c.id===s.id);return{...s,title:s.title??(o==null?void 0:o.title),mode:(a==null?void 0:a.mode)??(o==null?void 0:o.mode)??s.mode,phase:(a==null?void 0:a.phase)??(o==null?void 0:o.phase)??s.phase,isRunning:s.isRunning&&(o==null?void 0:o.isRunning)!==!1,messageCount:s.messageCount,recentUserPrompts:s.recentUserPrompts}})}function kv(e,t,n,s){var l;const a=e.sessionId,o=(l=n().currentSession)==null?void 0:l.id,c=a&&a!==o;if(t(h=>({sessions:h.sessions.map(f=>f.id===a?s(f):f)})),!c){const h=n().currentSession;if(h){const f=s(h);t(()=>({currentSession:f}))}}}function Ev(e,t,n){var c,l,h,f,p,m,x,_,w,k,v,b,y,S,E,N,T,L,A,P,R,$;const s=n();Q2(e,s);const a=((c=s.currentSession)==null?void 0:c.id)??null,o=()=>{const D=e.sessionId;!D||D===a||t(H=>({unreadSessionIds:Z2(H.unreadSessionIds,D)}))};switch(e.type){case"session.state":{const D=e.payload;if(!J2(e,a,s.pendingSessionCreate))break;xi();const H=D.messages.find(U=>U.isStreaming)??null,K=n().pendingSessionCreate===!0;if(t({currentSession:D.session,sessions:ej(n().sessions,D.session),unreadSessionIds:Cv(n().unreadSessionIds,D.session.id),messages:D.messages,streamingMessageId:(H==null?void 0:H.id)??null,streamingMessage:H,currentTodos:[],pendingPathConfirmations:D.pendingConfirmations??[],error:null,...K?{pendingSessionCreate:D.session.id}:{}}),D.session.providerId){const U=jt.getState();U.providers.find(J=>J.id===D.session.providerId)&&U.syncFromSession(D.session.providerId,D.session.providerModel??"")}break}case"session.list":{const D=e.payload;t(H=>({sessions:tj(D.sessions,H.sessions,H.currentSession)}));break}case"session.deleted":{const D=e.payload;t(H=>({unreadSessionIds:Cv(H.unreadSessionIds,D.sessionId)})),n().listSessions();break}case"session.deletedAll":{n().listSessions();break}case"session.running":{const D=e.payload;kv(e,t,n,H=>({...H,isRunning:D.isRunning})),D.isRunning||t({abortInProgress:!1,queuedMessages:[]});break}case"chat.message":{if(!qt(e,((l=n().currentSession)==null?void 0:l.id)??null)){o();break}const D=e.payload;t(H=>{if(H.messages.some(U=>U.id===D.message.id))return H;const K=D.message.role==="user";return{messages:[...H.messages,D.message],sessions:H.sessions.map(U=>U.id===e.sessionId&&K?{...U,messageCount:U.messageCount+1}:U),streamingMessageId:D.message.isStreaming?D.message.id:H.streamingMessageId,streamingMessage:D.message.isStreaming?D.message:H.streamingMessage}});break}case"chat.message_updated":{if(!qt(e,((h=n().currentSession)==null?void 0:h.id)??null)){o();break}const D=e.payload,H=D.updates.isStreaming===!1&&n().streamingMessageId===D.messageId;H&&xi(),t(K=>{const U=K.streamingMessage;if(U&&U.id===D.messageId){const F={...U,...D.updates};return{messages:K.messages.map(J=>J.id===D.messageId?F:J),streamingMessageId:H?null:K.streamingMessageId,streamingMessage:H?null:{...U,...D.updates}}}return{messages:K.messages.map(F=>F.id===D.messageId?{...F,...D.updates}:F),streamingMessageId:H?null:K.streamingMessageId}});break}case"chat.delta":{if(!qt(e,((f=n().currentSession)==null?void 0:f.id)??null)){o();break}const D=e.payload;if(!kf.has(D.messageId)){kf.add(D.messageId);const K=Go(n(),e.sessionId);X2(K)}const H=fi();H.messageId=D.messageId,H.deltaContent+=D.content,wf();break}case"chat.thinking":{if(!qt(e,((p=n().currentSession)==null?void 0:p.id)??null)){o();break}const D=e.payload,H=fi();H.messageId=D.messageId,H.thinkingContent+=D.content,wf();break}case"chat.tool_preparing":{if(!qt(e,((m=n().currentSession)==null?void 0:m.id)??null)){o();break}const D=e.payload,H=n().streamingMessage;if(!H||H.id!==D.messageId||((x=H.toolCalls)==null?void 0:x.find((U,F)=>F===D.index)))return;t(U=>{const F=U.streamingMessage.preparingToolCalls??[],J=F.findIndex(B=>B.index===D.index);let Q;return J>=0?Q=F.map((B,O)=>O===J?{...B,arguments:D.arguments}:B):Q=[...F,{index:D.index,name:D.name,...D.arguments?{arguments:D.arguments}:{}}],{streamingMessage:{...U.streamingMessage,preparingToolCalls:Q}}});break}case"chat.tool_call":{if(!qt(e,((_=n().currentSession)==null?void 0:_.id)??null)){o();break}const D=e.payload,H=K=>{var Q;const U=(Q=K.preparingToolCalls)==null?void 0:Q.filter((B,O)=>{var z;return B.name===D.tool?(z=K.preparingToolCalls)==null?void 0:z.slice(0,O).some(V=>V.name===D.tool):!0}),F=fi(),J=F.toolOutput.filter(B=>B.callId===D.callId);return J.length>0&&(F.toolOutput=F.toolOutput.filter(B=>B.callId!==D.callId)),{...K,toolCalls:[...K.toolCalls??[],{id:D.callId,name:D.tool,arguments:D.args,startedAt:Date.now(),...J.length>0?{streamingOutput:J.map(B=>({stream:B.stream,content:B.content,timestamp:Date.now()}))}:{}}],...U&&U.length>0?{preparingToolCalls:U}:{preparingToolCalls:void 0}}};t(K=>{const U=K.streamingMessage;return U&&U.id===D.messageId?{streamingMessage:H(U)}:{messages:K.messages.map(F=>F.id===D.messageId?H(F):F)}});break}case"chat.tool_output":{if(!qt(e,((w=n().currentSession)==null?void 0:w.id)??null)){o();break}const D=e.payload,H=fi();H.messageId=D.messageId,H.toolOutput.push({messageId:D.messageId,callId:D.callId,stream:D.stream,content:D.output}),wf();break}case"chat.tool_result":{if(!qt(e,((k=n().currentSession)==null?void 0:k.id)??null)){o();break}const D=e.payload,H=K=>{var F;const U=(F=K.toolCalls)==null?void 0:F.map(J=>J.id===D.callId?{...J,result:D.result}:J);return{...K,toolCalls:U}};t(K=>{const U=K.streamingMessage;return U&&U.id===D.messageId?{streamingMessage:H(U)}:{messages:K.messages.map(F=>F.id===D.messageId?H(F):F)}});break}case"chat.vision_fallback":{if(!qt(e,((v=n().currentSession)==null?void 0:v.id)??null)){o();break}const D=e.payload;t(H=>{const K=`${D.messageId}-${D.attachmentId}`,U={...H.visionFallbackByMessage};return U[K]={type:D.type,attachmentId:D.attachmentId,filename:D.filename,description:D.description},{visionFallbackByMessage:U}});break}case"chat.todo":{if(!qt(e,((b=n().currentSession)==null?void 0:b.id)??null)){o();break}const D=e.payload;t({currentTodos:D.todos});break}case"chat.progress":{if(!qt(e,((y=n().currentSession)==null?void 0:y.id)??null)){o();break}const D=e.payload;console.warn("Progress:",D.message,D.phase);break}case"chat.format_retry":{if(!qt(e,((S=n().currentSession)==null?void 0:S.id)??null)){o();break}const D=e.payload;console.warn("Format retry:",D.attempt,"/",D.maxAttempts);break}case"chat.done":{if(!qt(e,((E=n().currentSession)==null?void 0:E.id)??null)){o();break}xi();const D=fi();D.messageId=null,D.deltaContent="",D.thinkingContent="",D.toolOutput=[],kf.delete(e.payload.messageId);const H=e.payload,K=H.stats;t(U=>{const F=U.streamingMessage,J=F&&F.id===H.messageId?{...F,isStreaming:!1,stats:K??F.stats}:null;return{messages:U.messages.map(Q=>Q.id===H.messageId?J??{...Q,isStreaming:!1,stats:K??Q.stats,completeReason:H.reason}:Q),streamingMessageId:null,streamingMessage:null,visionFallbackByMessage:{}}});break}case"chat.error":{if(!qt(e,((N=n().currentSession)==null?void 0:N.id)??null)){o();break}xi();const D=fi(),H=e.payload;console.error("Chat error:",H.error,"recoverable:",H.recoverable),H.recoverable||(D.messageId=null,D.deltaContent="",D.thinkingContent="",D.toolOutput=[]),t(K=>({error:{code:"CHAT_ERROR",message:H.error},streamingMessageId:H.recoverable?K.streamingMessageId:null,...H.recoverable?{}:{messages:K.streamingMessage?K.messages.map(U=>U.id===K.streamingMessage.id?K.streamingMessage:U):K.messages,streamingMessage:null}}));break}case"chat.path_confirmation":{if(!qt(e,((T=n().currentSession)==null?void 0:T.id)??null)){o();break}const D=e.payload,H={callId:D.callId,tool:D.tool,paths:D.paths,workdir:D.workdir,reason:D.reason};t(K=>({pendingPathConfirmations:[...K.pendingPathConfirmations,H]}));break}case"chat.ask_user":{if(!qt(e,((L=n().currentSession)==null?void 0:L.id)??null)){o();return}const D=e.payload;t({pendingQuestion:{callId:D.callId,question:D.question}});break}case"mode.changed":{if(!qt(e,((A=n().currentSession)==null?void 0:A.id)??null)){o();break}const D=e.payload;t(H=>({currentSession:H.currentSession?{...H.currentSession,mode:D.mode}:null}));break}case"phase.changed":{const D=e.payload;kv(e,t,n,H=>({...H,phase:D.phase}));break}case"criteria.updated":{if(!qt(e,((P=n().currentSession)==null?void 0:P.id)??null)){o();break}const D=e.payload;t(H=>({currentSession:H.currentSession?{...H.currentSession,criteria:D.criteria}:null}));break}case"context.state":{const D=e.payload,H=qt(e,((R=n().currentSession)==null?void 0:R.id)??null);D.subAgentId?H&&n().updateSubAgentContextState(D.subAgentId,D.context):H?t({contextState:D.context}):o();break}case"session.name_generated":{const D=e.payload,H=e.sessionId,K=($=n().currentSession)==null?void 0:$.id;t(U=>{const F=U.sessions.map(Q=>Q.id===H?{...Q,title:D.name,updatedAt:new Date().toISOString()}:Q),J=K===H?U.currentSession?{...U.currentSession,title:D.name,updatedAt:new Date().toISOString()}:null:U.currentSession;return{sessions:F,currentSession:J}});break}case"queue.state":{const D=e.payload;t({queuedMessages:D.messages??[]});break}case"git.status":{const D=e.payload;t({gitStatus:{branch:D.branch,diff:D.diff}});break}case"devServer.output":case"devServer.state":{jr.getState().handleMessage(e);break}case"backgroundProcess.started":case"backgroundProcess.output":case"backgroundProcess.exited":case"backgroundProcess.removed":{Ko.getState().handleMessage(e.type,e.payload);break}case"error":{const D=e.payload;console.error("Server error:",D),t({error:{code:D.code,message:D.message},streamingMessageId:null});break}}}let Oo=!1,Sr=null;const Ef=new Set,Ic=new Map;function jv(e,t,n){return e==null?void 0:e.map(s=>{const a=t.filter(o=>o.callId===s.id);return a.length===0?s:(n.add(s.id),{...s,streamingOutput:[...s.streamingOutput??[],...a.map(o=>({stream:o.stream,content:o.content,timestamp:Date.now()}))]})})}async function Tv(e,t,n,s,a){try{const c=await(await je(`/api/sessions/${e}/message`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:t,attachments:n,messageKind:s})})).json();c.queueState&&a({queuedMessages:c.queueState})}catch(o){console.error("Error queueing message:",o)}}const we=Gn((e,t)=>(z2(()=>{const n=fi();if(!n.messageId)return;const s=n.deltaContent.length>0,a=n.thinkingContent.length>0,o=n.toolOutput.length>0;if(!s&&!a&&!o)return;const c=n.deltaContent,l=n.thinkingContent,h=n.toolOutput;n.deltaContent="",n.thinkingContent="",n.toolOutput=[],e(f=>{const p=f.streamingMessage;if(p&&p.id===n.messageId){const m={...p};if(s&&(m.content=m.content+c),a&&(m.thinkingContent=(m.thinkingContent??"")+l),o){const x=new Set;m.toolCalls=jv(m.toolCalls,h,x);const _=h.filter(w=>!x.has(w.callId));_.length>0&&n.toolOutput.push(..._)}return{streamingMessage:m}}if(o){const m=new Set,x=f.messages.map(w=>w.id!==n.messageId?w:{...w,toolCalls:jv(w.toolCalls,h,m)}),_=h.filter(w=>!m.has(w.callId));return _.length>0&&n.toolOutput.push(..._),{messages:x}}return f})}),{connectionStatus:"disconnected",showPasswordModal:!1,passwordModalRetry:!1,sessions:[],currentSession:null,unreadSessionIds:[],messages:[],streamingMessageId:null,streamingMessage:null,currentTodos:[],contextState:null,subAgentContextStates:{},pendingPathConfirmations:[],pendingQuestion:null,visionFallbackByMessage:{},gitStatus:null,queuedMessages:[],abortInProgress:!1,error:null,sessionsHasMore:!0,sessionsPaginationLoading:!1,pendingSessionCreate:!1,connect:async()=>{if(t().connectionStatus==="connected")return;e({connectionStatus:"reconnecting"});let s=!1;try{s=(await(await je("/api/auth")).json()).requiresAuth}catch{}if(s&&!Kt.hasToken()){e({showPasswordModal:!0,passwordModalRetry:!1,connectionStatus:"reconnecting"});return}Kt.onStatusChange(a=>{var o;if(e({connectionStatus:a}),a==="connected"){t().listSessions(void 0),Lt.getState().listProjects();const c=(o=t().currentSession)==null?void 0:o.id;c&&t().loadSession(c)}});try{await Kt.connect(),Oo||(Oo=!0,Sr=Kt.subscribe(a=>{Ev(a,e,t)}))}catch(a){console.error("Failed to connect:",a);const o=Kt.getLastCloseCode();if(!Kt.hasToken()&&(o===1006||o===4e3)){e({showPasswordModal:!0,passwordModalRetry:!0,connectionStatus:"reconnecting"});return}Sr&&(Sr(),Sr=null),Oo=!1,e({connectionStatus:"disconnected"})}},reconnect:()=>{Kt.disconnect(),Sr&&(Sr(),Sr=null),Oo=!1,e({connectionStatus:"disconnected"}),t().connect()},disconnect:()=>{Kt.disconnect(),Sr&&(Sr(),Sr=null),Oo=!1,e({connectionStatus:"disconnected",showPasswordModal:!1})},submitPassword:async n=>{try{const s=await fetch("/api/auth/login",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({password:n})});if(!s.ok){e({showPasswordModal:!0,passwordModalRetry:!0,connectionStatus:"reconnecting"});return}const{token:a}=await s.json();Kt.setToken(a),e({showPasswordModal:!1}),t().connect();const{listProjects:o}=Lt.getState(),{fetchConfig:c}=jt.getState();o(),c(),t().connect()}catch{e({showPasswordModal:!0,passwordModalRetry:!0,connectionStatus:"reconnecting"})}},cancelPassword:()=>{Kt.clearToken(),e({showPasswordModal:!1,connectionStatus:"disconnected"})},createSession:async(n,s)=>{if(t().pendingSessionCreate)return null;try{e({pendingSessionCreate:!0});const o=await je("/api/sessions",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({projectId:n,title:s})});if(!o.ok)return e({pendingSessionCreate:!1}),null;const c=await o.json();try{Kt.send("session.load",{sessionId:c.session.id})}catch{}return c.session}catch{return e({pendingSessionCreate:!1}),null}},loadSession:async n=>{if(!Ef.has(n)){Ef.add(n);try{const s=t().currentSession;!s||s.id!==n?(xi(),e({currentSession:null,unreadSessionIds:t().unreadSessionIds.filter(c=>c!==n),subAgentContextStates:{},messages:[],streamingMessageId:null,streamingMessage:null,currentTodos:[],contextState:null,pendingPathConfirmations:[],queuedMessages:[],abortInProgress:!1,error:null,pendingSessionCreate:!1})):e({unreadSessionIds:t().unreadSessionIds.filter(c=>c!==n)});const a=await je(`/api/sessions/${n}`);if(!a.ok)return;const o=await a.json();e({currentSession:o.session,messages:o.messages??[],contextState:o.contextState,queuedMessages:o.queueState??[]}),Kt.send("session.load",{sessionId:n});try{const c=await je(`/api/sessions/${n}/background-processes`);if(c.ok){const l=await c.json();Ko.getState().setProcesses(l.processes??[])}}catch{}}catch{}finally{Ef.delete(n)}}},listSessions:async(n,s=20)=>{const a=n??"global";if(Ic.has(a))return Ic.get(a);const o=(async()=>{try{const c=new URLSearchParams;c.set("limit",String(s)),n&&c.set("projectId",n);const h=await(await je(`/api/sessions?${c.toString()}`)).json(),f=h.sessions??[];e(p=>({sessions:f.map(m=>{var _,w;const x=p.sessions.find(k=>k.id===m.id);return{...m,title:m.title??(x==null?void 0:x.title),mode:((_=p.currentSession)==null?void 0:_.id)===m.id?p.currentSession.mode:(x==null?void 0:x.mode)??m.mode,phase:((w=p.currentSession)==null?void 0:w.id)===m.id?p.currentSession.phase:(x==null?void 0:x.phase)??m.phase,isRunning:m.isRunning&&(x==null?void 0:x.isRunning)!==!1,messageCount:m.messageCount,recentUserPrompts:m.recentUserPrompts}}),sessionsHasMore:n?h.hasMore??!1:!0}))}catch{}finally{Ic.delete(a)}})();return Ic.set(a,o),o},loadMoreSessions:async n=>{const s=t();if(!(s.sessionsPaginationLoading||!s.sessionsHasMore)){e({sessionsPaginationLoading:!0});try{const a=new URLSearchParams;a.set("limit","20"),a.set("offset",String(s.sessions.length)),a.set("projectId",n);const c=await(await je(`/api/sessions?${a.toString()}`)).json(),l=c.sessions??[];e(h=>({sessions:[...h.sessions,...l.map(f=>{const p=h.sessions.find(m=>m.id===f.id);return(p==null?void 0:p.isRunning)===!1?{...f,isRunning:!1}:f})],sessionsHasMore:c.hasMore??!1,sessionsPaginationLoading:!1}))}catch{e({sessionsPaginationLoading:!1})}}},deleteSession:async n=>{var s;try{return(await je(`/api/sessions/${n}`,{method:"DELETE"})).ok?(await t().listSessions(),((s=t().currentSession)==null?void 0:s.id)===n&&t().clearSession(),!0):!1}catch{return!1}},renameSession:async(n,s)=>{var a;try{const o=await je(`/api/sessions/${n}/title`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({title:s})});if(!o.ok)return!1;if(await t().listSessions(),((a=t().currentSession)==null?void 0:a.id)===n){const l=await o.json();l.session&&e({currentSession:l.session})}return!0}catch{return!1}},deleteAllSessions:async n=>{try{return(await je(`/api/projects/${n}/sessions`,{method:"DELETE"})).ok?(await t().listSessions(),!0):!1}catch{return!1}},clearSession:()=>{xi(),e(n=>({currentSession:null,messages:[],streamingMessageId:null,streamingMessage:null,currentTodos:[],contextState:null,pendingSessionCreate:!1,unreadSessionIds:n.currentSession?n.unreadSessionIds.filter(s=>s!==n.currentSession.id):n.unreadSessionIds}))},sendMessage:async(n,s,a)=>{var c;const o=(c=t().currentSession)==null?void 0:c.id;if(o){e({streamingMessageId:null});try{const h=await(await je(`/api/sessions/${o}/message`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:n,attachments:s,messageKind:a==null?void 0:a.messageKind})})).json();h.queueState&&e({queuedMessages:h.queueState})}catch(l){console.error("Error sending message:",l)}}},stopGeneration:async()=>{var s;const n=(s=t().currentSession)==null?void 0:s.id;if(n&&!t().abortInProgress){xi(),e({abortInProgress:!0});try{await je(`/api/sessions/${n}/stop`,{method:"POST"})}catch(a){console.error("Error stopping generation:",a)}}},continueGeneration:async()=>{var s;const n=(s=t().currentSession)==null?void 0:s.id;if(n){e({streamingMessageId:null});try{await je(`/api/sessions/${n}/continue`,{method:"POST"})}catch(a){console.error("Error continuing generation:",a)}}},launchRunner:(n,s,a)=>{e({streamingMessageId:null});const o={};n!=null&&n.trim()&&(o.content=n),s&&s.length>0&&(o.attachments=s),a&&(o.workflowId=a),Kt.send("runner.launch",o)},switchMode:async n=>{var a;const s=(a=t().currentSession)==null?void 0:a.id;if(s)try{const o=await je(`/api/sessions/${s}/mode`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({mode:n})});if(!o.ok){console.error("Failed to switch mode:",await o.json());return}const c=await o.json();c.session&&e({currentSession:c.session})}catch(o){console.error("Error switching mode:",o)}},switchDangerLevel:async n=>{var a;const s=(a=t().currentSession)==null?void 0:a.id;if(s)try{const o=await je(`/api/sessions/${s}/danger-level`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({dangerLevel:n})});if(!o.ok){console.error("Failed to switch danger level:",await o.json());return}const c=await o.json();c.session&&e({currentSession:c.session})}catch(o){console.error("Error switching danger level:",o)}},acceptAndBuild:(n,s,a)=>{var l;e({streamingMessageId:null});const o={};n&&(o.workflowId=n),s!=null&&s.trim()&&(o.content=s),a&&a.length>0&&(o.attachments=a);const c=(l=t().currentSession)==null?void 0:l.id;c&&je(`/api/sessions/${c}/mode`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({mode:"builder"})}).then(()=>{Kt.send("runner.launch",o)})},editCriteria:async n=>{var a;const s=(a=t().currentSession)==null?void 0:a.id;if(s)try{const o=await je(`/api/sessions/${s}/criteria`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({criteria:n})});o.ok||console.error("Failed to update criteria:",await o.json())}catch(o){console.error("Error updating criteria:",o)}},compactContext:()=>{Kt.send("context.compact",{})},setSessionProvider:async(n,s)=>{var a,o;try{const c=(a=t().currentSession)==null?void 0:a.id;if(!c)return null;const l=await je(`/api/sessions/${c}/provider`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({providerId:n,...s?{model:s}:{}})});if(!l.ok)return null;const h=await l.json();if(e({currentSession:h.session,messages:h.messages??[],contextState:h.contextState}),(o=h.session)!=null&&o.providerId){const f=jt.getState();f.providers.find(m=>m.id===h.session.providerId)&&f.syncFromSession(h.session.providerId,h.session.providerModel??"")}return h.session}catch{return null}},updateContextState:n=>{e({contextState:n})},updateSubAgentContextState:(n,s)=>{e(a=>({subAgentContextStates:{...a.subAgentContextStates,[n]:s}}))},clearSubAgentContextState:n=>{e(s=>{const a={...s.subAgentContextStates};return delete a[n],{subAgentContextStates:a}})},confirmPath:async(n,s,a=!1)=>{var c;const o=(c=t().currentSession)==null?void 0:c.id;if(o)try{await je(`/api/sessions/${o}/confirm-path`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({callId:n,approved:s,alwaysAllow:a})})}catch(l){console.error("Error confirming path:",l)}},answerQuestion:async(n,s)=>{var o;const a=(o=t().currentSession)==null?void 0:o.id;if(a){try{await je(`/api/sessions/${a}/answer`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({callId:n,answer:s})})}catch(c){console.error("Error answering question:",c)}e({pendingQuestion:null})}},queueAsap:async(n,s,a)=>{var c;const o=(c=t().currentSession)==null?void 0:c.id;o&&await Tv(o,n,s,a,e)},queueCompletion:async(n,s,a)=>{var c;const o=(c=t().currentSession)==null?void 0:c.id;o&&await Tv(o,n,s,a,e)},cancelQueued:async n=>{var a;const s=(a=t().currentSession)==null?void 0:a.id;if(s)try{const c=await(await je(`/api/sessions/${s}/queue/${n}`,{method:"DELETE"})).json();c.queueState&&e({queuedMessages:c.queueState})}catch(o){console.error("Error canceling queued message:",o)}},clearError:()=>{e({error:null})},resetPendingSessionCreate:()=>{e({pendingSessionCreate:!1})},handleServerMessage:n=>{Ev(n,e,t)}}));function Nu(){return we(e=>{var t;return((t=e.currentSession)==null?void 0:t.isRunning)??!1})}function nj(){return we(e=>e.abortInProgress)}function rj(){const e=we(s=>s.connect),t=we(s=>s.connectionStatus),n=pi(s=>s.load);return M.useEffect(()=>{e()},[e]),M.useEffect(()=>{t==="connected"&&n()},[t,n]),{connectionStatus:t}}const sj="modulepreload",ij=function(e){return"/"+e},Nv={},Y=function(t,n,s){let a=Promise.resolve();if(n&&n.length>0){let c=function(f){return Promise.all(f.map(p=>Promise.resolve(p).then(m=>({status:"fulfilled",value:m}),m=>({status:"rejected",reason:m}))))};document.getElementsByTagName("link");const l=document.querySelector("meta[property=csp-nonce]"),h=(l==null?void 0:l.nonce)||(l==null?void 0:l.getAttribute("nonce"));a=c(n.map(f=>{if(f=ij(f),f in Nv)return;Nv[f]=!0;const p=f.endsWith(".css"),m=p?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${f}"]${m}`))return;const x=document.createElement("link");if(x.rel=p?"stylesheet":sj,p||(x.as="script"),x.crossOrigin="",x.href=f,h&&x.setAttribute("nonce",h),document.head.appendChild(x),p)return new Promise((_,w)=>{x.addEventListener("load",_),x.addEventListener("error",()=>w(new Error(`Unable to preload CSS for ${f}`)))})}))}function o(c){const l=new Event("vite:preloadError",{cancelable:!0});if(l.payload=c,window.dispatchEvent(l),!l.defaultPrevented)throw c}return a.then(c=>{for(const l of c||[])l.status==="rejected"&&o(l.reason);return t().catch(o)})},uS=[{key:"color-bg-primary",category:"background",label:"Primary Background",defaultValue:"13 17 23"},{key:"color-bg-secondary",category:"background",label:"Secondary Background",defaultValue:"22 27 34"},{key:"color-bg-tertiary",category:"background",label:"Tertiary Background",defaultValue:"33 38 45"},{key:"color-primary",category:"surface",label:"Primary Surface",defaultValue:"10 10 10"},{key:"color-secondary",category:"surface",label:"Secondary Surface",defaultValue:"20 20 20"},{key:"color-text-primary",category:"text",label:"Primary Text",defaultValue:"139 148 158"},{key:"color-text-secondary",category:"text",label:"Secondary Text",defaultValue:"139 148 158"},{key:"color-text-muted",category:"text",label:"Muted Text",defaultValue:"72 79 88"},{key:"color-accent-primary",category:"accent",label:"Primary Accent",defaultValue:"88 166 255"},{key:"color-accent-success",category:"accent",label:"Success Accent",defaultValue:"63 185 80"},{key:"color-accent-warning",category:"accent",label:"Warning Accent",defaultValue:"210 153 34"},{key:"color-accent-error",category:"accent",label:"Error Accent",defaultValue:"248 81 73"},{key:"color-border",category:"border",label:"Border",defaultValue:"48 53 60"}],Tr=[{id:"dark",name:"Dark",tokens:{"color-bg-primary":"13 17 23","color-bg-secondary":"22 27 34","color-bg-tertiary":"33 38 45","color-primary":"10 10 10","color-secondary":"20 20 20","color-text-primary":"255 255 255","color-text-secondary":"139 148 158","color-text-muted":"72 79 88","color-accent-primary":"88 166 255","color-accent-success":"63 185 80","color-accent-warning":"210 153 34","color-accent-error":"248 81 73","color-border":"48 53 60"}},{id:"light",name:"Light",tokens:{"color-bg-primary":"255 255 255","color-bg-secondary":"250 251 252","color-bg-tertiary":"243 244 246","color-primary":"245 245 245","color-secondary":"229 229 229","color-text-primary":"15 23 42","color-text-secondary":"30 41 59","color-text-muted":"100 116 139","color-accent-primary":"37 99 235","color-accent-success":"22 163 74","color-accent-warning":"217 119 6","color-accent-error":"220 38 38","color-border":"203 213 225"}},{id:"monokai",name:"Monokai",tokens:{"color-bg-primary":"39 40 34","color-bg-secondary":"30 31 28","color-bg-tertiary":"62 61 50","color-primary":"30 31 28","color-secondary":"45 46 39","color-text-primary":"248 248 242","color-text-secondary":"207 207 194","color-text-muted":"117 113 94","color-accent-primary":"102 217 239","color-accent-success":"166 226 46","color-accent-warning":"230 219 116","color-accent-error":"249 38 114","color-border":"73 72 62"}},{id:"dracula",name:"Dracula",tokens:{"color-bg-primary":"40 42 54","color-bg-secondary":"33 34 44","color-bg-tertiary":"68 71 90","color-primary":"30 31 41","color-secondary":"44 46 61","color-text-primary":"248 248 242","color-text-secondary":"230 230 230","color-text-muted":"98 114 164","color-accent-primary":"189 147 249","color-accent-success":"80 250 123","color-accent-warning":"255 184 108","color-accent-error":"255 85 85","color-border":"68 71 90"}},{id:"nord",name:"Nord",tokens:{"color-bg-primary":"46 52 64","color-bg-secondary":"59 66 82","color-bg-tertiary":"67 76 94","color-primary":"46 52 64","color-secondary":"59 66 82","color-text-primary":"236 239 244","color-text-secondary":"229 233 240","color-text-muted":"76 86 106","color-accent-primary":"129 161 193","color-accent-success":"163 190 140","color-accent-warning":"235 203 139","color-accent-error":"191 97 106","color-border":"76 86 106"}}];function Av(){try{const e=localStorage.getItem("openfox:userPresets");if(e)return JSON.parse(e)}catch{}return[]}const Mt=Gn((e,t)=>({currentPreset:"dark",basePreset:"",customTokens:{},isCustom:!1,isCustomizing:!1,userPresets:Av(),followSystemTheme:!0,applySavedTheme:()=>{const{getSavedTheme:n,applyPreset:s,applyTokens:a}=t(),o=n();if(o)try{const c=JSON.parse(o);c.preset&&c.tokens?(s(c.preset),e({basePreset:c.preset}),a(c.tokens)):c.preset?s(c.preset):c.tokens&&a(c.tokens)}catch{s("dark")}else s("dark")},applyPreset:n=>{Tr.find(a=>a.id===n)&&(e({currentPreset:n,basePreset:"",customTokens:{},isCustom:!1,isCustomizing:!1}),t().applyTheme())},startCustomizing:()=>{var a;const{currentPreset:n}=t(),s=((a=Tr.find(o=>o.id===n))==null?void 0:a.tokens)??{};e({basePreset:n,customTokens:{...s},isCustom:!0,isCustomizing:!0})},setCustomToken:(n,s)=>{e(a=>({customTokens:{...a.customTokens,[n]:s}})),t().applyTheme()},cancelCustomizing:()=>{t().applyPreset(t().basePreset||t().currentPreset)},saveCustomTheme:()=>{const{customTokens:n}=t();t().saveTheme(JSON.stringify({tokens:n})).catch(()=>{}),e({isCustomizing:!1})},applyTokens:n=>{e({customTokens:n,isCustom:!0,isCustomizing:!1}),t().applyTheme()},getActiveTheme:()=>{var c,l;const{basePreset:n,customTokens:s,isCustom:a}=t();if(a&&n)return{...((c=Tr.find(f=>f.id===n))==null?void 0:c.tokens)??{},...s};if(a)return{...uS.reduce((h,f)=>({...h,[f.key]:f.defaultValue}),{}),...s};const o=Tr.find(h=>h.id===t().currentPreset);return(o==null?void 0:o.tokens)??((l=Tr[0])==null?void 0:l.tokens)??{}},applyTheme:()=>{if(typeof document>"u")return;const n=t().getActiveTheme(),s=document.documentElement;Object.entries(n).forEach(([a,o])=>{s.style.setProperty(`--${a}`,o)})},getSavedTheme:()=>{try{const n=localStorage.getItem("openfox:theme");if(!n)return null;if(n[0]!=="{")return JSON.stringify({preset:n});const s=JSON.parse(n);if(s.preset)return JSON.stringify({preset:s.preset});if(s.tokens)return JSON.stringify({tokens:s.tokens})}catch{return null}return null},saveTheme:async n=>{localStorage.setItem("openfox:theme",n);const{useSettingsStore:s}=await Y(async()=>{const{useSettingsStore:a}=await Promise.resolve().then(()=>vf);return{useSettingsStore:a}},void 0);await s.getState().setSetting(Pe.DISPLAY_THEME,n)},clearCustomTheme:()=>{localStorage.removeItem("openfox:theme"),e({isCustom:!1,isCustomizing:!1,basePreset:""})},setFollowSystemTheme:n=>{e({followSystemTheme:n}),Y(async()=>{const{useSettingsStore:s,SETTINGS_KEYS:a}=await Promise.resolve().then(()=>vf);return{useSettingsStore:s,SETTINGS_KEYS:a}},void 0).then(({useSettingsStore:s,SETTINGS_KEYS:a})=>{s.getState().setSetting(a.DISPLAY_FOLLOW_SYSTEM_THEME,String(n))})},initSystemThemeListener:()=>{if(typeof window>"u")return()=>{};const n=window.matchMedia("(prefers-color-scheme: dark)"),s=o=>{const{followSystemTheme:c}=t();c&&(t().applyPreset(o?"dark":"light"),t().saveTheme(JSON.stringify({preset:o?"dark":"light"})))};s(n.matches);const a=o=>s(o.matches);return n.addEventListener("change",a),()=>n.removeEventListener("change",a)},reset:()=>{e({currentPreset:"dark",basePreset:"",customTokens:{},isCustom:!1,isCustomizing:!1,userPresets:[],followSystemTheme:!0})},addUserPreset:n=>{const{basePreset:s,customTokens:a,currentPreset:o}=t(),c={id:"custom-"+Date.now(),name:n,basePreset:s||o,tokens:{...a}},l=[...t().userPresets,c];e({userPresets:l}),t().saveUserPresets()},applyUserPreset:n=>{const s=t().userPresets[n];s&&(e({currentPreset:s.basePreset,basePreset:s.basePreset,customTokens:{...s.tokens},isCustom:!0,isCustomizing:!1}),t().applyTheme(),t().saveTheme(JSON.stringify({preset:s.basePreset,tokens:s.tokens})).catch(()=>{}))},deleteUserPreset:n=>{const s=t().userPresets.filter((a,o)=>o!==n);e({userPresets:s}),t().saveUserPresets()},loadUserPresets:()=>{e({userPresets:Av()})},saveUserPresets:()=>{localStorage.setItem("openfox:userPresets",JSON.stringify(t().userPresets)),Y(async()=>{const{useSettingsStore:n}=await Promise.resolve().then(()=>vf);return{useSettingsStore:n}},void 0).then(({useSettingsStore:n})=>{n.getState().setSetting(Pe.DISPLAY_USER_PRESETS,JSON.stringify(t().userPresets)).catch(()=>{})})}}));function aj({canLoad:e,projectId:t,currentProjectId:n}){const s=Lt(c=>c.loadProject),a=we(c=>c.listSessions),o=we(c=>c.clearSession);M.useEffect(()=>{e&&t&&(n!==t&&s(t),a(t),o())},[e,t,n,s,a,o])}function oj({canLoad:e,projectId:t,sessionId:n,currentProjectId:s,currentSessionId:a}){const o=we(f=>f.loadSession),c=Lt(f=>f.loadProject),l=we(f=>f.listSessions),h=we(f=>f.pendingSessionCreate);M.useEffect(()=>{e&&t&&s!==t&&c(t)},[e,t,s,c]),M.useEffect(()=>{e&&n&&a!==n&&o(n),e&&t&&l(t)},[e,n,a,o,l,h,t])}function lj({className:e="w-5 h-5"}){return u.jsx("svg",{className:e,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 19l-7-7 7-7"})})}function dS({className:e="w-3.5 h-3.5"}){return u.jsx("svg",{className:e,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M14 5l7 7m0 0l-7 7m7-7H3"})})}function cj({className:e="w-5 h-5"}){return u.jsx("svg",{className:e,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15.172 7l-6.586 6.586a2 2 0 102.828 2.828l6.414-6.586a4 4 0 00-5.656-5.656l-6.415 6.585a6 6 0 108.486 8.486L20.5 13"})})}function uj({className:e="w-3 h-3 text-text-muted"}){return u.jsx("svg",{className:e,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"})})}function dj({className:e="w-4 h-4"}){return u.jsx("svg",{className:e,viewBox:"0 0 16 16",fill:"currentColor",children:u.jsx("path",{d:"M9.5 3.25a2.25 2.25 0 1 1 3 2.122V6A2.5 2.5 0 0 1 10 8.5H6a1 1 0 0 0-1 1v1.128a2.251 2.251 0 1 1-1.5 0V5.372a2.25 2.25 0 1 1 1.5 0v1.836A2.493 2.493 0 0 1 6 7h4a1 1 0 0 0 1-1v-.628A2.25 2.25 0 0 1 9.5 3.25Zm-6 0a.75.75 0 1 0 1.5 0 .75.75 0 0 0-1.5 0Zm8.25-.75a.75.75 0 1 0 0 1.5.75.75 0 0 0 0-1.5ZM4.25 12a.75.75 0 1 0 0 1.5.75.75 0 0 0 0-1.5Z"})})}function Nr({className:e="w-3.5 h-3.5 text-text-muted"}){return u.jsx("svg",{className:e,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})}function Ar({className:e="w-3 h-3 text-text-muted",rotate:t}){return u.jsx("svg",{className:e,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,style:t!==void 0?{transform:`rotate(${t}deg)`}:void 0,children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19 9l-7 7-7-7"})})}function hj({className:e="w-4 h-4"}){return u.jsxs("svg",{className:e,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[u.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",strokeWidth:"2"}),u.jsx("path",{d:"M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1",strokeWidth:"2"})]})}function ep({className:e="w-3.5 h-3.5"}){return u.jsx("svg",{className:e,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}function fj({className:e="w-3 h-3"}){return u.jsx("svg",{className:e,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})})}function tp({className:e="w-4 h-4"}){return u.jsxs("svg",{className:e,fill:"currentColor",viewBox:"0 0 24 24",children:[u.jsx("circle",{cx:"12",cy:"5",r:"2"}),u.jsx("circle",{cx:"12",cy:"12",r:"2"}),u.jsx("circle",{cx:"12",cy:"19",r:"2"})]})}function el({className:e="w-3.5 h-3.5"}){return u.jsx("svg",{className:e,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"})})}function np({className:e="w-5 h-5 text-accent-primary"}){return u.jsx("svg",{className:e,fill:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{d:"M10 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2h-8l-2-2z"})})}function mj({className:e="w-4 h-4"}){return u.jsx("svg",{className:e,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 9V4.5M9 9H4.5M9 9L3.75 3.75M9 15v4.5M9 15H4.5M9 15l-5.25 5.25M15 9h4.5M15 9V4.5M15 9l5.25-5.25M15 15h4.5M15 15v4.5m0-4.5l5.25 5.25"})})}function pj({className:e="w-4 h-4"}){return u.jsx("svg",{className:e,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5l-5-5m5 5v-4m0 4h-4"})})}function gj({className:e="w-4 h-4"}){return u.jsx("svg",{className:e,viewBox:"0 0 16 16",fill:"currentColor",children:u.jsx("path",{d:"M8 0a8.2 8.2 0 0 1 .701.031C9.444.095 9.99.645 10.16 1.29l.288 1.107c.018.066.079.158.212.224.231.114.454.243.668.386.123.082.233.09.299.071l1.1-.303c.652-.18 1.37.008 1.755.653a8.043 8.043 0 0 1 .683 1.18c.227.568.096 1.26-.378 1.726l-.812.804a.312.312 0 0 0-.081.283c.024.166.04.335.04.507s-.016.341-.04.507a.312.312 0 0 0 .08.283l.813.804c.474.466.605 1.158.378 1.726a8.07 8.07 0 0 1-.683 1.18c-.385.645-1.103.833-1.755.653l-1.1-.303c-.066-.019-.176-.011-.299.071a5.1 5.1 0 0 1-.668.386c-.133.066-.194.158-.211.224l-.29 1.107c-.168.645-.714 1.196-1.458 1.26a8.094 8.094 0 0 1-1.402 0c-.744-.064-1.29-.615-1.458-1.26l-.29-1.107a.426.426 0 0 0-.211-.224 5.11 5.11 0 0 1-.668-.386c-.123-.082-.233-.09-.299-.071l-1.1.303c-.652.18-1.37-.008-1.755-.653a8.044 8.044 0 0 1-.683-1.18c-.227-.568-.096-1.26.378-1.726l.812-.804a.312.312 0 0 0 .081-.283A5.18 5.18 0 0 1 2.3 8c0-.172.016-.341.04-.507a.312.312 0 0 0-.08-.283l-.813-.804C.973 5.94.842 5.248 1.069 4.68c.181-.452.395-.882.683-1.18.385-.645 1.103-.833 1.755-.653l1.1.303c.066.019.176.011.299-.071.214-.143.437-.272.668-.386a.426.426 0 0 0 .211-.224l.29-1.107C6.009.645 6.556.095 7.299.03 7.53.01 7.764 0 8 0Zm0 5.5a2.5 2.5 0 1 0 0 5 2.5 2.5 0 0 0 0-5Z"})})}function xj({className:e="w-3 h-3"}){return u.jsx("svg",{className:e,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})})}function _j({className:e="w-4 h-4"}){return u.jsx("svg",{className:e,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M17 16l4-4m0 0l-4-4m4 4H7m6 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h4a3 3 0 013 3v1"})})}function Lv({className:e="w-4 h-4"}){return u.jsx("svg",{className:e,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 6h16M4 12h16M4 18h16"})})}function hS({className:e="w-[18px] h-[18px]"}){return u.jsxs("svg",{className:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[u.jsx("circle",{cx:"12",cy:"5",r:"1.5",fill:"currentColor",stroke:"none"}),u.jsx("circle",{cx:"12",cy:"12",r:"1.5",fill:"currentColor",stroke:"none"}),u.jsx("circle",{cx:"12",cy:"19",r:"1.5",fill:"currentColor",stroke:"none"})]})}function yj({className:e="w-4 h-4"}){return u.jsxs("svg",{className:e,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[u.jsx("path",{d:"M6.5 3.5H3a1 1 0 0 0-1 1V13a1 1 0 0 0 1 1h8.5a1 1 0 0 0 1-1V9.5"}),u.jsx("path",{d:"M9.5 2h4.5v4.5"}),u.jsx("path",{d:"M14 2L7.5 8.5"})]})}function vj({className:e="w-3 h-3",color:t}){return u.jsx("svg",{className:e,fill:t??"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{d:"M8 5v14l11-7z"})})}function Aa({className:e="w-3 h-3 text-accent-primary"}){return u.jsx("svg",{className:e,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})})}function bj({className:e="w-5 h-5"}){return u.jsx("svg",{className:e,viewBox:"0 0 20 20",fill:"currentColor",children:u.jsx("path",{fillRule:"evenodd",d:"M10 3a1 1 0 011 1v5h5a1 1 0 110 2h-5v5a1 1 0 11-2 0v-5H4a1 1 0 110-2h5V4a1 1 0 011-1z",clipRule:"evenodd"})})}function rp({className:e="w-4 h-4"}){return u.jsx("svg",{className:e,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})})}function Sj({className:e="w-4 h-4"}){return u.jsxs("svg",{className:e,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"}),u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"})]})}function wj({className:e="w-3 h-3 text-blue-400 animate-spin flex-shrink-0"}){return u.jsxs("svg",{"aria-label":"Session running",className:e,viewBox:"0 0 24 24",fill:"none",children:[u.jsx("title",{children:"Running"}),u.jsx("circle",{className:"opacity-30",cx:"12",cy:"12",r:"9",stroke:"currentColor",strokeWidth:"3"}),u.jsx("path",{d:"M21 12a9 9 0 00-9-9",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round"})]})}function Cj({className:e="w-3.5 h-3.5 text-text-muted"}){return u.jsx("svg",{className:e,fill:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{d:"M10.788 3.21c.448-1.077 1.976-1.077 2.424 0l2.082 5.007 5.404.433c1.164.093 1.636 1.545.749 2.305l-4.117 3.527 1.257 5.273c.271 1.136-.964 2.033-1.96 1.425L12 18.354 7.373 21.18c-.996.608-2.231-.29-1.96-1.425l1.257-5.273-4.117-3.527c-.887-.76-.415-2.212.749-2.305l5.404-.433 2.082-5.006z"})})}function kj({className:e="w-3.5 h-3.5 text-text-muted"}){return u.jsx("svg",{className:e,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11.049 2.927c.3-.921 1.603-.921 1.902 0l1.519 4.674a1 1 0 00.95.69h4.915c.969 0 1.371 1.24.588 1.81l-3.976 2.888a1 1 0 00-.363 1.118l1.518 4.674c.3.922-.755 1.688-1.538 1.118l-3.976-2.888a1 1 0 00-1.176 0l-3.976 2.888c-.783.57-1.838-.197-1.538-1.118l1.518-4.674a1 1 0 00-.363-1.118l-3.976-2.888c-.784-.57-.38-1.81.588-1.81h4.914a1 1 0 00.951-.69l1.519-4.674z"})})}function fS({className:e="w-4 h-4"}){return u.jsx("svg",{className:e,viewBox:"0 0 16 16",fill:"currentColor",children:u.jsx("rect",{x:"3",y:"3",width:"10",height:"10",rx:"1"})})}function Ej({className:e="w-3.5 h-3.5 shrink-0",color:t}){return u.jsx("svg",{className:e,fill:"none",stroke:t,viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"})})}function jj({className:e="w-4 h-4"}){return u.jsxs("svg",{className:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[u.jsx("polyline",{points:"4 17 10 11 4 5"}),u.jsx("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]})}function Au({className:e="w-3.5 h-3.5"}){return u.jsx("svg",{className:e,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})})}function sp(){return u.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})})}function Tj({className:e="w-4 h-4"}){return u.jsx("svg",{className:e,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})})}function gm({className:e="w-2.5 h-2.5"}){return u.jsx("svg",{className:e,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})})}function ip({className:e="w-4 h-4"}){return u.jsx("svg",{className:e,viewBox:"0 0 20 20",fill:"currentColor",children:u.jsx("path",{fillRule:"evenodd",d:"M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z",clipRule:"evenodd"})})}function mS({className:e="w-4 h-4"}){return u.jsx("svg",{className:e,viewBox:"0 0 16 16",fill:"currentColor",children:u.jsx("path",{d:"M4.646 4.646a.5.5 0 0 1 .708 0L8 7.293l2.646-2.647a.5.5 0 0 1 .708.708L8.707 8l2.647 2.646a.5.5 0 0 1-.708.708L8 8.707l-2.646 2.647a.5.5 0 0 1-.708-.708L7.293 8 4.646 5.354a.55.55 0 0 1 0-.708z"})})}function Nj({className:e="w-3.5 h-3.5 text-text-muted"}){return u.jsx("svg",{className:e,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"})})}function Aj({className:e="w-3.5 h-3.5 text-text-muted"}){return u.jsx("svg",{className:e,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9.663 17h4.673M12 3v1m6.364 1.636l-.707.707M21 12h-1M4 12H3m3.343-5.657l-.707-.707m2.828 9.9a5 5 0 117.072 0l-.548.547A3.374 3.374 0 0014 18.469V19a2 2 0 11-4 0v-.531c0-.895-.356-1.754-.988-2.386l-.548-.547z"})})}function Dv({className:e="w-3.5 h-3.5 text-text-muted"}){return u.jsx("svg",{className:e,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9.75 17L9 20l-1 1h8l-1-1-.75-3M3 13h18M5 17h14a2 2 0 002-2V5a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"})})}function xm(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}function Rv(e,t){const n=Kt.ws;!n||n.readyState!==WebSocket.OPEN||n.send(JSON.stringify({id:xm(),type:e,payload:t}))}const hr=Gn((e,t)=>({isOpen:!1,sessions:[],workdir:null,setOpen:n=>e({isOpen:n}),toggleOpen:()=>e(n=>({isOpen:!n.isOpen})),setWorkdir:n=>e({workdir:n}),fetchSessions:async n=>{if(!n){e({sessions:[]});return}try{const s=await je(`/api/terminals?projectId=${encodeURIComponent(n)}`);if(s.ok){const a=await s.json();e({sessions:a});const o=Kt.ws;if(o&&o.readyState===WebSocket.OPEN)for(const c of a)o.send(JSON.stringify({id:xm(),type:"terminal.subscribe",payload:{sessionId:c.id}}))}}catch(s){console.error("Failed to fetch terminals:",s)}},createSession:async(n,s)=>{try{const a=await je("/api/terminals",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({workdir:n??t().workdir??void 0,projectId:s})});if(a.ok){const o=await a.json();e(l=>({sessions:[...l.sessions,o]}));const c=Kt.ws;c&&c.readyState===WebSocket.OPEN&&c.send(JSON.stringify({id:xm(),type:"terminal.subscribe",payload:{sessionId:o.id}}))}}catch(a){console.error("Failed to create terminal:",a)}},writeSession:(n,s)=>{Rv("terminal.write",{sessionId:n,data:s})},resizeSession:(n,s,a)=>{Rv("terminal.resize",{sessionId:n,cols:s,rows:a})},killSession:async n=>{try{(await je(`/api/terminals/${n}`,{method:"DELETE"})).ok&&e(a=>({sessions:a.sessions.filter(o=>o.id!==n)}))}catch(s){console.error("Failed to kill terminal:",s)}},handleMessage:n=>{switch(n.type){case"terminal.exit":{const{sessionId:s}=n.payload||{};s&&e(a=>{const o=a.sessions.filter(c=>c.id!==s);return o.length===0&&a.isOpen?{sessions:[],isOpen:!1}:{sessions:o}});break}}}}));Kt.subscribe(e=>{var t;(t=e.type)!=null&&t.startsWith("terminal.")&&hr.getState().handleMessage(e)});const Sa={terminalToggle:{type:"double-press",key:"Control",threshold:300},quickAction:{type:"double-press",key:"Shift",threshold:300},agentSwitching:[{type:"chord",key:"1",modifiers:["ctrl"]},{type:"chord",key:"2",modifiers:["ctrl"]},{type:"chord",key:"3",modifiers:["ctrl"]},{type:"chord",key:"4",modifiers:["ctrl"]}]};function _m(e){if(!e)return structuredClone(Sa);try{const t=JSON.parse(e);return{terminalToggle:t.terminalToggle??structuredClone(Sa.terminalToggle),quickAction:t.quickAction??structuredClone(Sa.quickAction),agentSwitching:t.agentSwitching??structuredClone(Sa.agentSwitching)}}catch{return structuredClone(Sa)}}function Ov(e){return e.code.startsWith("Digit")?e.code.slice(-1):e.code.startsWith("Key")?e.code.slice(3).toLowerCase():e.key}function pS(e){if(e.type==="double-press")return`Double ${e.key==="Control"?"Ctrl":e.key==="Shift"?"Shift":e.key==="Alt"?"Alt":e.key==="Meta"?"Meta":e.key}`;const t=e.modifiers.map(s=>{switch(s){case"ctrl":return"Ctrl";case"meta":return"⌘";case"alt":return"Alt";case"shift":return"Shift"}}),n=e.key.length===1?e.key.toUpperCase():e.key;return[...t,n].join("+")}function Lj(e){return e.type==="double-press"}function gS(e){return e.type==="chord"}function Dj(e,t){return t.length===1&&/^[a-z]$/i.test(t)?e.code===`Key${t.toUpperCase()}`:t.length===1&&/^[0-9]$/.test(t)?e.code===`Digit${t}`:e.key.toLowerCase()===t.toLowerCase()}function xS(e,t){const n=t.modifiers.includes("ctrl"),s=t.modifiers.includes("meta"),a=t.modifiers.includes("alt"),o=t.modifiers.includes("shift");return Dj(e,t.key)&&e.ctrlKey===n&&e.metaKey===s&&e.altKey===a&&e.shiftKey===o}function ap(){const e=$t(t=>t.settings[Pe.KEYBINDINGS]);return _m(e)}function Rj(e,t,n){const s=M.useRef(0),a=M.useRef(t);a.current=t,M.useEffect(()=>{if(!e)return;const o=e.threshold??300,c=l=>{if(l.key!==e.key)return;const h=e.key==="Control",f=e.key==="Shift",p=e.key==="Alt",m=e.key==="Meta";if(!h&&l.ctrlKey||!f&&l.shiftKey||!p&&l.altKey||!m&&l.metaKey)return;const x=Date.now();x-s.current<o?(l.preventDefault(),l.stopPropagation(),a.current(),s.current=0):s.current=x};return window.addEventListener("keydown",c,n!=null&&n.capture?!0:void 0),()=>window.removeEventListener("keydown",c,n!=null&&n.capture?!0:void 0)},[e,n==null?void 0:n.capture])}function Oj(e,t){const n=M.useRef(t);n.current=t,M.useEffect(()=>{if(!e)return;const s=a=>{xS(a,e)&&(a.preventDefault(),n.current())};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[e])}function _S(e,t,n){Rj(e&&Lj(e)?e:void 0,t,n),Oj(e&&gS(e)?e:void 0,t)}function Mj(e,t,n){const s=M.useRef(n);s.current=n,M.useEffect(()=>{const a=o=>{for(let c=0;c<e.length;c++){const l=e[c];if(!l)continue;const h=t[c];if(h&&gS(l)&&xS(o,l)){o.preventDefault(),s.current(h.id);return}}};return window.addEventListener("keydown",a),()=>window.removeEventListener("keydown",a)},[e,t])}var Ma=K0();const Lu=M.forwardRef(({icon:e,iconSize:t="w-3.5 h-3.5",className:n="",...s},a)=>u.jsx("button",{ref:a,type:"button",className:`p-1 rounded text-text-muted hover:text-text-primary hover:bg-bg-primary transition-colors ${n}`,...s,children:u.jsx("svg",{className:t,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:e})})}));Lu.displayName="IconButton";const Ij="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z",zs=M.forwardRef((e,t)=>u.jsx(Lu,{ref:t,icon:Ij,title:"Edit",...e}));zs.displayName="EditButton";const Pj="M6 18L18 6M6 6l12 12",op=M.forwardRef((e,t)=>u.jsx(Lu,{ref:t,icon:Pj,...e}));op.displayName="CloseButton";const Bj={sm:"max-w-sm",md:"max-w-md",lg:"max-w-2xl",xl:"max-w-4xl",full:"max-w-[95vw] h-[90vh] flex-1"};function Ct({label:e,title:t,size:n="md",minHeight:s,children:a,footer:o,className:c,onClose:l,isOpen:h,closeOnBackdropClick:f=!0,closeOnEscape:p=!0,showCloseButton:m=!0}){const[x,_]=M.useState(!1),w=h!==void 0,k=w?h:x,v=M.useCallback(()=>{w||_(!0)},[w]),b=M.useCallback(()=>{w||_(!1),l==null||l()},[w,l]);M.useEffect(()=>{if(!k||!p)return;const S=E=>{E.key==="Escape"&&(E.stopPropagation(),b())};return document.addEventListener("keydown",S),()=>document.removeEventListener("keydown",S)},[k,b,p]);const y=e&&(typeof e=="string"?u.jsx("button",{type:"button",onClick:v,className:c,children:e}):u.jsx("span",{onClick:v,className:c,style:{cursor:"pointer"},children:e}));return u.jsxs(u.Fragment,{children:[y,k&&(typeof document<"u"?Ma.createPortal(u.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[u.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:f?b:void 0}),u.jsxs("div",{className:`relative w-full ${Bj[n]} max-h-[90vh] bg-bg-secondary border border-border rounded shadow-xl flex flex-col`,children:[(t||m)&&u.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[t&&u.jsx("h2",{className:"text-lg font-semibold text-text-primary",children:t}),m&&u.jsx(op,{onClick:b,className:"ml-auto","aria-label":"Close"})]}),u.jsx("div",{className:"p-4 overflow-y-auto flex-1 min-h-0",style:s?{minHeight:s}:void 0,children:a}),o&&u.jsx("div",{className:"px-4 py-3 border-t border-border",children:o})]})]}),document.body):null)]})}function zj({value:e,defaultUrl:t,disabled:n,onChange:s}){const a=e??t;return u.jsxs("div",{className:"relative",children:[u.jsx("select",{value:a,disabled:n,onChange:o=>{const c=o.target.value;s(c===t?null:c)},className:"appearance-none bg-bg-tertiary border border-border rounded px-1.5 pr-5 text-xs focus:outline-none focus:ring-1 focus:ring-accent-primary disabled:opacity-40 cursor-pointer",style:{width:"60px"},children:$2.map(({url:o,label:c})=>u.jsx("option",{value:o,title:c,children:c.split(" ")[0]},o))}),u.jsx(Ar,{className:"absolute right-0.5 top-1/2 -translate-y-1/2 w-3 h-3 pointer-events-none text-text-muted"})]})}const Mv=[{key:"general",label:"General"},{key:"build",label:"Agent"},{key:"sub-agent",label:"Sub-agent"}];function Hj(){const e=pi(h=>h.settings),t=pi(h=>h.update),n=pi(h=>h.updateEvent),s=pi(h=>h.updateAgentOverride),a=pi(h=>h.load);M.useEffect(()=>{a()},[a]);const o=async()=>{await F2()==="granted"&&t({...e,browserNotificationEnabled:!0})},c=(h,f,p,m)=>{h==="general"?n(f,{[p]:m}):s(h,f,{[p]:m})},l=(h,f,p)=>{h==="general"?n(f,{customSoundUrl:p}):s(h,f,{customSoundUrl:p})};return u.jsxs("div",{className:"space-y-6",children:[u.jsxs("div",{className:"space-y-3",children:[u.jsx("h3",{className:"text-sm font-medium text-text-primary",children:"Master Controls"}),u.jsx(Iv,{label:"Sound notifications",description:"Play sounds when events occur",checked:e.soundEnabled,onChange:h=>t({...e,soundEnabled:h})}),u.jsx(Iv,{label:"Browser notifications",description:"Show desktop notifications when the window is not focused",checked:e.browserNotificationEnabled,onChange:h=>{h&&typeof Notification<"u"&&Notification.permission!=="granted"?o():t({...e,browserNotificationEnabled:h})}}),typeof Notification<"u"&&Notification.permission==="denied"&&e.browserNotificationEnabled&&u.jsx("p",{className:"text-xs text-accent-error ml-6",children:"Browser notifications are blocked. Please enable them in your browser settings."})]}),u.jsxs("div",{className:"space-y-3",children:[u.jsx("h3",{className:"text-sm font-medium text-text-primary",children:"Notification Settings"}),u.jsx("div",{className:"border border-border rounded overflow-hidden",children:u.jsxs("table",{className:"w-full text-sm",children:[u.jsx("thead",{className:"sticky top-0 bg-bg-tertiary",children:u.jsxs("tr",{className:"border-b border-border",children:[u.jsx("th",{className:"text-left px-3 py-2 text-text-primary font-medium w-40",children:"Event"}),Mv.map(h=>u.jsx("th",{className:"text-center px-2 py-2 text-text-primary font-medium",children:h.label},h.key))]})}),u.jsx("tbody",{children:H2.map(h=>u.jsxs("tr",{className:"border-b border-border last:border-b-0 hover:bg-bg-secondary/50",children:[u.jsx("td",{className:"px-3 py-2",children:u.jsx("div",{className:"text-text-primary text-xs",children:h.label})}),Mv.map(f=>{const p=lS(e,h.key,f.key==="general"?void 0:f.key),m=aS[h.key];return u.jsx("td",{className:"px-2 py-2 align-top",children:u.jsxs("div",{className:"flex flex-col items-center gap-1",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("label",{className:"flex items-center gap-1 text-text-secondary",children:u.jsx("input",{type:"checkbox",checked:p.soundEnabled,onChange:x=>c(f.key,h.key,"soundEnabled",x.target.checked),disabled:!e.soundEnabled,className:"rounded border-border",title:"Sound"})}),u.jsx("label",{className:"flex items-center gap-1 text-text-secondary",children:u.jsx("input",{type:"checkbox",checked:p.browserNotification,onChange:x=>c(f.key,h.key,"browserNotification",x.target.checked),disabled:!e.browserNotificationEnabled,className:"rounded border-border",title:"Browser"})})]}),p.soundEnabled&&e.soundEnabled&&u.jsx(zj,{value:p.customSoundUrl,defaultUrl:m,disabled:!e.soundEnabled,onChange:x=>l(f.key,h.key,x)})]})},f.key)})]},h.key))})]})})]})]})}function Iv({label:e,description:t,checked:n,onChange:s}){return u.jsxs("label",{className:"flex items-start gap-3 cursor-pointer group",children:[u.jsx("div",{className:"pt-0.5",children:u.jsx("div",{className:`relative w-9 h-5 rounded-full transition-colors ${n?"bg-accent-primary":"bg-bg-tertiary border border-border"}`,onClick:a=>{a.preventDefault(),s(!n)},children:u.jsx("div",{className:`absolute top-0.5 w-4 h-4 rounded-full bg-white shadow transition-transform ${n?"translate-x-4":"translate-x-0.5"}`})})}),u.jsxs("div",{children:[u.jsx("div",{className:"text-sm text-text-primary group-hover:text-accent-primary transition-colors",children:e}),u.jsx("div",{className:"text-xs text-text-muted",children:t})]})]})}const Je=M.forwardRef(({variant:e="secondary",size:t="md",className:n="",children:s,...a},o)=>{const c="rounded font-medium transition-colors disabled:opacity-50 disabled:cursor-not-allowed",l={primary:"bg-accent-primary/25 text-text-primary hover:bg-accent-primary/40",secondary:"bg-bg-tertiary text-text-primary hover:bg-border",danger:"bg-accent-error text-white hover:bg-accent-error/80"},h={sm:"px-1.5 py-1 text-xs",md:"px-3 py-1.5 text-sm",lg:"px-4 py-2 text-base"};return u.jsx("button",{ref:o,className:`${c} ${l[e]} ${h[t]} ${n}`,...a,children:s})});Je.displayName="Button";async function lp(e,t,n){t({loading:!0});try{const a=await(await je(e)).json();t({defaults:a.defaults??[],userItems:a.userItems??[],...n?{projectItems:a.projectItems??[]}:{},loading:!1})}catch{t({loading:!1})}}const wr=Gn((e,t)=>({defaults:[],userItems:[],projectItems:[],loading:!1,fetchSkills:async()=>{await lp("/api/skills",e,!0)},toggleSkill:async n=>{try{const a=await(await je(`/api/skills/${n}/toggle`,{method:"POST"})).json();e(o=>({defaults:o.defaults.map(c=>c.id===n?{...c,enabled:a.enabled}:c),userItems:o.userItems.map(c=>c.id===n?{...c,enabled:a.enabled}:c)}))}catch{}},fetchSkill:async n=>{try{const s=await je(`/api/skills/${n}`);return s.ok?await s.json():null}catch{return null}},fetchDefaultContent:async n=>{try{const s=await je(`/api/skills/defaults/${n}`);return s.ok?await s.json():null}catch{return null}},createSkill:async(n,s)=>{const a=await Us("POST","/api/skills",{...n,destination:s});return a.success&&await t().fetchSkills(),a},updateSkill:async(n,s)=>{const a=await Us("PUT",`/api/skills/${n}`,s);return a.success&&await t().fetchSkills(),a},deleteSkill:async n=>{try{const s=await je(`/api/skills/${n}`,{method:"DELETE"}),a=await s.json();return s.ok?(e(o=>({userItems:o.userItems.filter(c=>c.id!==n)})),{success:!0}):{success:!1,error:a.error??"Failed to delete"}}catch{return{success:!1,error:"Network error"}}},duplicateSkill:async(n,s)=>Tu(`/api/skills/${n}/duplicate`,()=>t().fetchSkills(),s)}));function cp(){const[e,t]=M.useState({id:null,type:null}),n=M.useCallback(o=>t({id:o,type:"delete"}),[]),s=M.useCallback(()=>t({id:null,type:null}),[]),a=M.useCallback((o,c)=>e.id===o&&e.type===c,[e.id,e.type]);return{requestDelete:n,clearConfirm:s,isConfirming:a}}function up({onConfirm:e,onCancel:t}){return u.jsxs("div",{className:"flex items-center gap-1",children:[u.jsx("button",{onClick:e,className:"px-1.5 py-0.5 rounded text-xs hover:opacity-90 transition-colors bg-accent-error/20 text-accent-error hover:bg-accent-error/30",children:"Delete"}),u.jsx("button",{onClick:t,className:"px-1.5 py-0.5 rounded text-text-muted text-xs hover:bg-bg-primary transition-colors",children:"Cancel"})]})}function dp({onClick:e}){return u.jsx("button",{onClick:e,className:"p-1.5 rounded hover:bg-bg-primary text-text-muted hover:text-accent-error transition-colors",title:"Delete",children:u.jsx(Au,{})})}function tl({onClick:e}){return u.jsx("button",{onClick:e,className:"p-1.5 rounded hover:bg-bg-primary text-text-muted hover:text-text-primary transition-colors",title:"Duplicate",children:u.jsx(ep,{})})}function Si({label:e,value:t,onChange:n,placeholder:s,readOnly:a,hint:o,mono:c}){return u.jsxs("div",{children:[u.jsxs("label",{className:"block text-xs text-text-secondary mb-1",children:[e,o&&u.jsx("span",{className:"text-text-muted ml-1",children:o})]}),u.jsx("input",{value:t,onChange:l=>n(l.target.value),readOnly:a,placeholder:s,className:`w-full px-2 py-1.5 bg-bg-tertiary border border-border rounded text-sm focus:outline-none focus:ring-1 focus:ring-accent-primary ${c?"font-mono":""} ${a?"opacity-60":""}`})]})}function $j({onCancel:e,onSave:t,saving:n,saveDisabled:s}){return u.jsxs("div",{className:"flex justify-end gap-2 pt-2 border-t border-border",children:[u.jsx(Je,{variant:"secondary",onClick:e,children:"Cancel"}),u.jsx(Je,{variant:"primary",onClick:t,disabled:n||s,children:n?"Saving...":"Save"})]})}function hp({message:e}){return u.jsx("div",{className:"text-accent-error text-sm px-3 py-2 bg-accent-error/10 rounded",children:e})}function yS({description:e,onNew:t,loading:n,hasItems:s,children:a}){return u.jsxs(u.Fragment,{children:[u.jsxs("div",{className:"flex items-center justify-between mb-4",children:[u.jsx("p",{className:"text-text-secondary text-sm",children:e}),u.jsx("div",{className:"flex items-center gap-2 flex-shrink-0 ml-3",children:u.jsx(Je,{variant:"primary",size:"sm",onClick:t,children:"+ New"})})]}),n&&!s?u.jsx("div",{className:"text-text-muted text-sm",children:"Loading..."}):s?a:u.jsx("div",{className:"text-text-muted text-sm",children:"No items defined."})]})}function vS({label:e="Custom",children:t}){return u.jsxs("div",{children:[u.jsx("h3",{className:"text-xs font-medium text-text-secondary mb-2 uppercase tracking-wide",children:e}),u.jsx("div",{className:"space-y-2",children:t})]})}function bS({description:e,onNew:t,newLabel:n="+ New"}){return u.jsxs("div",{className:"flex items-center justify-between mb-4",children:[u.jsx("p",{className:"text-text-secondary text-sm",children:e}),u.jsx("div",{className:"flex items-center gap-2 flex-shrink-0 ml-3",children:u.jsx(Je,{variant:"primary",size:"sm",onClick:t,children:n})})]})}function SS({isBuiltIn:e,isConfirmingDelete:t,onView:n,onEdit:s,onDuplicate:a,onDelete:o,children:c}){return u.jsxs("div",{className:"flex items-center justify-between p-3 rounded border border-border bg-bg-tertiary",children:[u.jsx("div",{className:"min-w-0 flex-1 mr-3",children:c}),u.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[e&&n&&u.jsx("button",{onClick:n,className:"p-1.5 rounded text-text-muted hover:text-text-primary hover:bg-bg-primary transition-colors",title:"View",children:u.jsx(el,{})}),u.jsx(tl,{onClick:a}),!e&&s&&u.jsx(zs,{onClick:s}),!e&&(t?u.jsx(up,{onConfirm:()=>{o==null||o()},onCancel:()=>{}}):u.jsx(dp,{onClick:()=>o==null?void 0:o()}))]})]})}function Uj({id:e,name:t,description:n,isBuiltIn:s,isConfirmingDelete:a,onView:o,onEdit:c,onDuplicate:l,onDelete:h}){return u.jsxs(SS,{isBuiltIn:s,isConfirmingDelete:a,onView:o,onEdit:c,onDuplicate:l,onDelete:h,children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("span",{className:"text-text-primary text-sm font-medium",children:t}),u.jsx("span",{className:"text-text-muted text-xs font-mono",children:e})]}),n&&u.jsx("p",{className:"text-text-muted text-xs truncate",children:n})]})}function wS({loading:e,hasItems:t,loadingLabel:n,emptyLabel:s,children:a}){return e&&!t?u.jsx("div",{className:"text-text-muted text-sm",children:n}):t?u.jsx("div",{className:"space-y-4",children:a}):s?u.jsx("div",{className:"text-text-muted text-sm",children:s}):null}function CS({name:e,id:t,nameLabel:n="Name",idLabel:s="ID",namePlaceholder:a="My Item",idPlaceholder:o="my-item",nameHint:c,readOnlyId:l=!1,readOnlyHint:h="(read-only)",onNameChange:f,onIdChange:p}){return u.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[u.jsx(Si,{label:n,value:e,onChange:f,placeholder:a,hint:c}),u.jsx(Si,{label:s,value:t,onChange:p,readOnly:l,placeholder:o,hint:l?h:void 0,mono:!0})]})}function kS(e={}){const{initialData:t={}}=e,[n,s]=M.useState("list"),[a,o]=M.useState(null),[c,l]=M.useState(""),[h,f]=M.useState(!1),[p,m]=M.useState(t),x=M.useCallback(()=>{m(t),l(""),o(null)},[t]),_=M.useCallback(b=>{s(b),b==="list"&&x()},[x]),w=M.useCallback(b=>{m(y=>typeof b=="function"?b(y):b)},[]),k=M.useCallback((b,y={})=>{o(b),s("edit"),m({...y}),l("")},[]),v=M.useCallback(()=>{o(null),s("edit"),m(t),l("")},[t]);return{view:n,editingId:a,formError:c,saving:h,formData:p,setView:_,setEditingId:o,setFormError:l,setFormData:w,setSaving:f,resetForm:x,startEditing:k,startNew:v}}function fp(){return u.jsxs("div",{className:"flex items-start gap-2 px-3 py-2 bg-accent-warning/10 border border-accent-warning/30 rounded text-xs",children:[u.jsx("span",{children:"⚠️"}),u.jsx("p",{className:"text-text-secondary",children:"Editing this value now will have the side-effect of invalidating KV-cache, causing your next message in current sessions to take a long time to process. Consider doing this between sessions."})]})}function Pv({skill:e,isBuiltIn:t,isConfirmingDelete:n,onView:s,onEdit:a,onDuplicate:o,onDelete:c}){return u.jsx(Uj,{id:e.id,name:e.name,description:e.description,isBuiltIn:t,isConfirmingDelete:n,onView:s,onEdit:a,onDuplicate:o,onDelete:c})}function Fj({isOpen:e}){const t=wr(F=>F.defaults),n=wr(F=>F.userItems),s=wr(F=>F.projectItems),a=wr(F=>F.loading),o=wr(F=>F.fetchSkills),c=wr(F=>F.fetchSkill),l=wr(F=>F.fetchDefaultContent),h=wr(F=>F.createSkill),f=wr(F=>F.updateSkill),p=wr(F=>F.deleteSkill),{view:m,editingId:x,formError:_,saving:w,formData:k,setView:v,setEditingId:b,setFormError:y,setFormData:S,setSaving:E}=kS(),{clearConfirm:N}=cp();M.useEffect(()=>{e&&(o(),v("list"),b(null),N())},[e,o,N]);const T=(F,J,Q,B)=>{S({name:B??F.metadata.name,id:Q??F.metadata.id,description:F.metadata.description??"",version:F.metadata.version??"1.0.0",prompt:F.prompt,isReadOnly:J,destination:"user"})},L=async F=>{if(t.some(Q=>Q.id===F)){const Q=await l(F);if(!Q)return;T(Q,!0),b(F),y(""),v("edit")}else{const Q=await c(F);if(!Q)return;T(Q,!0),b(F),y(""),v("edit")}},A=async F=>{const Q=t.some(O=>O.id===F)?await l(F):await c(F);if(!Q)return;const B=`${F}-copy-${Date.now()}`;T(Q,!1,B,`${Q.metadata.name} (copy)`),b(null),y(""),v("edit")},P=()=>{S({name:"",id:"",description:"",version:"1.0.0",prompt:"",isReadOnly:!1,destination:"user"}),v("edit")},R=async F=>{const J=await c(F);J&&(T(J,!1),b(F),y(""),v("edit"))},$=async F=>{await p(F),N()},D=async()=>{const F=x??k.id;if(!F||!k.name||!k.prompt){y("Name, ID, and prompt are required.");return}E(!0),y("");const J={metadata:{id:F,name:k.name,description:k.description,version:k.version},prompt:k.prompt},Q=x?await f(x,J):await h(J,k.destination);if(E(!1),!Q.success){y(Q.error??"Failed to save skill.");return}v("list")},H=F=>{S(J=>({...J,name:F})),x||S(J=>({...J,id:F.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")}))},K=k.isReadOnly;if(m==="edit")return u.jsxs("div",{className:"flex flex-col h-full",children:[u.jsxs("div",{className:"flex justify-between items-center mb-3",children:[u.jsx("h2",{className:"text-lg font-semibold text-text-primary",children:K?k.name:x?"Edit Skill":"New Skill"}),u.jsx("button",{onClick:()=>v("list"),className:"text-text-muted hover:text-text-primary",children:"Cancel"})]}),_&&u.jsx(hp,{message:_}),u.jsxs("div",{className:"space-y-3 mb-3",children:[u.jsx(CS,{name:k.name,id:k.id,nameLabel:"Name",idLabel:"ID",namePlaceholder:"My Skill",idPlaceholder:"my-skill",readOnlyId:!0,onNameChange:H,onIdChange:()=>{}}),u.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[u.jsx(Si,{label:"Description",value:k.description,onChange:F=>S(J=>({...J,description:F})),placeholder:"What this skill does...",readOnly:K}),u.jsx(Si,{label:"Version",value:k.version,onChange:F=>S(J=>({...J,version:F})),placeholder:"1.0.0",readOnly:K})]})]}),u.jsxs("div",{className:"flex-1 min-h-[120px] border-t border-border pt-3 flex flex-col",children:[u.jsx("label",{className:"block text-xs text-text-secondary mb-1",children:"Prompt"}),u.jsx("textarea",{value:k.prompt,onChange:F=>S(J=>({...J,prompt:F.target.value})),readOnly:K,placeholder:"The system prompt for this skill...",className:"h-80 w-full px-3 py-2 bg-bg-tertiary border border-border rounded text-sm font-mono resize-y focus:outline-none focus:ring-1 focus:ring-accent-primary"})]}),!x&&u.jsxs("div",{className:"flex items-center gap-2 pt-2",children:[u.jsx("label",{className:"text-xs text-text-secondary",children:"Save to:"}),u.jsxs("select",{value:k.destination,onChange:F=>S(J=>({...J,destination:F.target.value})),className:"px-2 py-1 bg-bg-tertiary border border-border rounded text-xs focus:outline-none focus:ring-1 focus:ring-accent-primary",children:[u.jsx("option",{value:"user",children:"Global config"}),u.jsx("option",{value:"project",children:"Project (.openfox/)"})]})]}),u.jsx(fp,{}),u.jsxs("div",{className:"flex justify-end gap-2 pt-3 border-t border-border flex-shrink-0",children:[u.jsx(Je,{variant:"secondary",onClick:()=>v("list"),children:"Cancel"}),K?u.jsx(Je,{variant:"primary",onClick:()=>{S(F=>({...F,name:F.name+" (copy)",id:`${x}-copy-${Date.now()}`,isReadOnly:!1})),b(null)},children:"Duplicate & Customize"}):u.jsx(Je,{variant:"primary",onClick:D,disabled:w||!k.name||!k.id||!k.prompt,children:w?"Saving...":"Save"})]})]});function U({items:F}){return F.map(J=>u.jsx(Pv,{skill:J,isBuiltIn:!1,isConfirmingDelete:!1,onView:()=>L(J.id),onEdit:()=>R(J.id),onDuplicate:()=>A(J.id),onDelete:()=>$(J.id)},J.id))}return u.jsxs("div",{children:[u.jsx(bS,{description:"Skills provide domain-specific knowledge that agents can load on demand.",onNew:P}),u.jsxs(wS,{loading:a,hasItems:t.length>0||n.length>0,loadingLabel:"Loading skills...",emptyLabel:"No skills created yet.",children:[t.length>0&&u.jsxs("div",{children:[u.jsx("h3",{className:"text-xs font-medium text-text-secondary mb-2 uppercase tracking-wide",children:"Built-in"}),u.jsx("div",{className:"space-y-2",children:t.map(F=>u.jsx(Pv,{skill:F,isBuiltIn:!0,isConfirmingDelete:!1,onView:()=>L(F.id),onDuplicate:()=>A(F.id)},F.id))})]}),n.length>0&&u.jsx(vS,{children:u.jsx(U,{items:n})}),s.length>0&&u.jsxs("div",{className:"mt-4",children:[u.jsx("h3",{className:"text-xs font-medium text-text-secondary mb-2 uppercase tracking-wide",children:"Project"}),u.jsx("div",{className:"space-y-2",children:u.jsx(U,{items:s})})]})]})]})}function Du(){const e=$t(a=>a.settings),t=$t(a=>a.loading),n=$t(a=>a.getSetting),s=$t(a=>a.setSetting);return{settings:e,loading:t,getSetting:n,setSetting:s}}function Vj({isOpen:e}){const{settings:t,loading:n,getSetting:s,setSetting:a}=Du(),o=t[Pe.GLOBAL_INSTRUCTIONS]??"",c=n[Pe.GLOBAL_INSTRUCTIONS]??!1,[l,h]=M.useState(o),[f,p]=M.useState(!1),[m,x]=M.useState(!1);M.useEffect(()=>{e&&s(Pe.GLOBAL_INSTRUCTIONS)},[e,s]),M.useEffect(()=>{h(o),p(!1)},[o]);const _=async()=>{x(!0),await a(Pe.GLOBAL_INSTRUCTIONS,l),x(!1),p(!1)},w=()=>{h(o),p(!1)},k=c||m;return u.jsxs("div",{className:"space-y-4",children:[u.jsxs("div",{children:[u.jsx("label",{className:"block text-sm font-medium text-text-primary mb-2",children:"Global Instructions"}),u.jsx("p",{className:"text-sm text-text-muted mb-2",children:"These instructions are injected into every prompt, regardless of project."}),u.jsx("textarea",{value:l,onChange:v=>{h(v.target.value),p(!0)},placeholder:"Enter global instructions that apply to all projects...",className:"w-full min-h-80 px-3 py-2 bg-bg-tertiary border border-border rounded text-sm font-mono resize-y focus:outline-none focus:ring-1 focus:ring-accent-primary",disabled:k})]}),f&&u.jsx(fp,{}),u.jsxs("div",{className:"flex justify-end gap-2",children:[u.jsx(Je,{variant:"secondary",onClick:w,disabled:!f,children:"Discard"}),u.jsx(Je,{variant:"primary",onClick:_,disabled:!f||k,children:m?"Saving...":"Save"})]})]})}function Gj(e){const t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);if(t){const n=parseInt(t[1]??"0",16),s=parseInt(t[2]??"0",16),a=parseInt(t[3]??"0",16);return`${n} ${s} ${a}`}return e}function mi(e){const t=e.split(" ").map(n=>parseInt(n,10));return t.length===3&&t.every(n=>!isNaN(n))?`#${t.map(n=>(n??0).toString(16).padStart(2,"0")).join("")}`:e}function Wj({isOpen:e,isNew:t,basePresetId:n,presetName:s,initialTokens:a,onClose:o,onSave:c}){const[l,h]=M.useState(a),[f,p]=M.useState(s);M.useEffect(()=>{h(a),p(s)},[a,s]);const m=(v,b)=>{const y=b.startsWith("#")?Gj(b):b;h(S=>({...S,[v]:y}))},x=()=>{c(f.trim()||"Untitled",{...l})},_=uS.reduce((v,b)=>{const y=b.category;return v[y]||(v[y]=[]),v[y].push(b),v},{}),w={background:"Backgrounds",surface:"Surfaces",text:"Text",accent:"Accents",border:"Border"},k=Tr.find(v=>v.id===n);return u.jsx(Ct,{isOpen:e,onClose:o,size:"lg",title:t?"New Theme":"Edit Theme",closeOnBackdropClick:!0,closeOnEscape:!0,footer:u.jsxs("div",{className:"flex gap-2 justify-end",children:[u.jsx("button",{type:"button",onClick:o,className:"px-4 py-2 border border-border rounded text-sm text-text-primary hover:bg-bg-tertiary transition-colors",children:"Cancel"}),u.jsx("button",{type:"button",onClick:x,className:"px-4 py-2 bg-accent-primary text-white rounded hover:bg-accent-primary/80 transition-colors text-sm",children:"Save"})]}),children:u.jsxs("div",{className:"space-y-4",children:[u.jsxs("div",{children:[u.jsx("label",{className:"text-xs text-text-muted block mb-1",children:"Name"}),u.jsx("input",{type:"text",value:f,onChange:v=>p(v.target.value),className:"w-full px-3 py-2 bg-bg-tertiary border border-border rounded text-sm text-text-primary focus:outline-none focus:ring-1 focus:ring-accent-primary"})]}),!t&&u.jsxs("div",{className:"text-xs text-text-muted",children:["Based on ",u.jsx("span",{className:"text-text-primary",children:k==null?void 0:k.name})]}),Object.entries(_).map(([v,b])=>u.jsxs("div",{className:"space-y-3",children:[u.jsx("h4",{className:"text-xs font-medium text-text-muted uppercase",children:w[v]??v}),u.jsx("div",{className:"grid grid-cols-2 gap-3",children:b.map(y=>u.jsxs("div",{className:"flex flex-col gap-1",children:[u.jsx("label",{htmlFor:y.key,className:"text-xs text-text-muted",children:y.label}),u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("input",{type:"color",id:y.key,value:mi(l[y.key]??y.defaultValue),onChange:S=>m(y.key,S.target.value),className:"w-8 h-8 rounded cursor-pointer border border-border bg-transparent"}),u.jsx("input",{type:"text",value:l[y.key]??y.defaultValue,onChange:S=>m(y.key,S.target.value),className:"flex-1 px-2 py-1 bg-bg-tertiary border border-border rounded text-xs text-text-primary font-mono focus:outline-none focus:ring-1 focus:ring-accent-primary"})]})]},y.key))})]},v))]})})}function qj(){const[e,t]=M.useState(null),n=Mt(E=>E.currentPreset),s=Mt(E=>E.isCustom),a=Mt(E=>E.basePreset),o=Mt(E=>E.userPresets),c=Mt(E=>E.applyPreset),l=Mt(E=>E.applyUserPreset),h=Mt(E=>E.deleteUserPreset),f=Mt(E=>E.saveTheme),p=Mt(E=>E.followSystemTheme),m=Mt(E=>E.setFollowSystemTheme),x=E=>{c(E),f(JSON.stringify({preset:E})).catch(()=>{})},_=E=>{l(E)},w=E=>{const N=Tr.find(T=>T.id===E);N&&t({type:"new",presetIndex:o.length,basePresetId:E,presetName:N.name+" Copy",tokens:{...N.tokens}})},k=E=>{const N=o[E];if(!N)return;const T=Tr.find(A=>A.id===N.basePreset),L=T?{...T.tokens,...N.tokens}:N.tokens;t({type:"edit",presetIndex:E,basePresetId:N.basePreset,presetName:N.name,tokens:L})},v=(E,N)=>{if(!e)return;const T=[...o];if(e.type==="new"){const L={id:"custom-"+Date.now(),name:E,basePreset:e.basePresetId,tokens:N};T.push(L);const A=T.length-1;Mt.setState({userPresets:T}),Mt.getState().saveUserPresets(),Mt.getState().applyUserPreset(A)}else{const L=T[e.presetIndex];L&&(T[e.presetIndex]={...L,name:E,tokens:N}),Mt.setState({userPresets:T}),Mt.getState().saveUserPresets(),Mt.getState().applyUserPreset(e.presetIndex)}t(null)},b=()=>{t(null)},y=(E,N)=>{E.stopPropagation(),h(N)},S=s?a:n;return u.jsxs("div",{className:"space-y-4",children:[u.jsx("h3",{className:"text-sm font-medium text-text-primary",children:"Theme"}),u.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[u.jsx("button",{type:"button",role:"switch","aria-checked":p,onClick:()=>m(!p),className:`relative w-10 h-5 rounded-full transition-colors ${p?"bg-accent-primary":"bg-bg-tertiary border border-border"}`,children:u.jsx("span",{className:`absolute top-0.5 left-0.5 w-4 h-4 rounded-full bg-white transition-transform ${p?"translate-x-5":"translate-x-0"}`})}),u.jsx("span",{className:"text-sm text-text-secondary",children:"Follow system theme"})]}),u.jsx("div",{className:"grid grid-cols-5 gap-2",children:Tr.map(E=>u.jsxs("div",{className:"relative group",children:[u.jsxs("button",{type:"button",onClick:()=>x(E.id),className:`w-full flex flex-col items-center gap-2 px-3 py-3 rounded-lg border transition-colors ${S===E.id&&!s?"border-accent-primary bg-bg-tertiary text-text-primary":"border-border bg-bg-secondary text-text-muted hover:border-text-muted"}`,children:[u.jsx("div",{className:"w-8 h-8 rounded border flex items-center justify-center",style:{backgroundColor:mi(E.tokens["color-bg-primary"]??"#000"),borderColor:mi(E.tokens["color-border"]??"#000")},children:u.jsx("div",{className:"w-3 h-3 rounded-full",style:{backgroundColor:mi(E.tokens["color-text-primary"]??"#fff")}})}),u.jsx("span",{className:"text-xs",children:E.name})]}),u.jsx("button",{type:"button",onClick:N=>{N.stopPropagation(),w(E.id)},className:"absolute top-1 right-1 w-6 h-6 rounded bg-bg-tertiary border border-border flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity z-10 hover:border-text-muted",title:"Create custom theme based on this",children:u.jsx("span",{className:"text-xs",children:"✎"})})]},E.id))}),o.length>0&&u.jsxs(u.Fragment,{children:[u.jsx("h4",{className:"text-xs font-medium text-text-muted uppercase",children:"My Themes"}),u.jsx("div",{className:"grid grid-cols-5 gap-2",children:o.map((E,N)=>{const T=Tr.find(A=>A.id===E.basePreset),L=T?{...T.tokens,...E.tokens}:E.tokens;return u.jsxs("div",{className:"relative group",children:[u.jsxs("button",{type:"button",onClick:()=>_(N),className:`w-full flex flex-col items-center gap-2 px-3 py-3 rounded-lg border transition-colors ${s&&a===E.basePreset&&S===E.basePreset?"border-accent-primary bg-bg-tertiary text-text-primary":"border-border bg-bg-secondary text-text-muted hover:border-text-muted"}`,children:[u.jsx("div",{className:"w-8 h-8 rounded border flex items-center justify-center",style:{backgroundColor:mi(L["color-bg-primary"]??"#000"),borderColor:mi(L["color-border"]??"#000")},children:u.jsx("div",{className:"w-3 h-3 rounded-full",style:{backgroundColor:mi(L["color-text-primary"]??"#fff")}})}),u.jsx("span",{className:"text-xs truncate w-full text-center",children:E.name})]}),u.jsx("button",{type:"button",onClick:A=>{A.stopPropagation(),k(N)},className:"absolute top-1 right-1 w-6 h-6 rounded bg-bg-tertiary border border-border flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity z-10 hover:border-text-muted",title:"Edit",children:u.jsx("span",{className:"text-xs",children:"✎"})}),u.jsx("button",{type:"button",onClick:A=>y(A,N),className:"absolute -top-1 -left-1 w-5 h-5 rounded-full bg-accent-error text-white flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity z-20",children:u.jsx(ip,{className:"w-3 h-3"})})]},E.id)})})]}),e&&u.jsx(Wj,{isOpen:!0,isNew:e.type==="new",presetIndex:e.presetIndex,basePresetId:e.basePresetId,presetName:e.presetName,initialTokens:e.tokens,onClose:b,onSave:v})]})}function Kj(){return u.jsx(qj,{})}function Yj(){const{settings:e,loading:t,getSetting:n,setSetting:s}=Du(),a=t[Pe.DISPLAY_SHOW_THINKING]??!1,o=[{key:Pe.DISPLAY_SHOW_THINKING,label:"Show thinking blocks",description:"Display AI reasoning content in the feed"},{key:Pe.DISPLAY_SHOW_VERBOSE_TOOL_OUTPUT,label:"Show expanded tool output",description:"Always show full tool call details instead of compact view"},{key:Pe.DISPLAY_SHOW_STATS,label:"Show stats bar",description:"Display model, tokens, and timing information"},{key:Pe.DISPLAY_SHOW_AGENT_DEFINITIONS,label:"Show agent definitions",description:"Display agent definition injections in the feed"},{key:Pe.DISPLAY_SHOW_WORKFLOW_BARS,label:"Show workflow bars",description:"Display workflow start and end markers"},{key:Pe.DISPLAY_SHOW_SYNTAX_HIGHLIGHTING,label:"Show syntax highlighting",description:"Nicer formatting, but very slow - does not affect red/green diff coloring"}],c=Object.fromEntries(o.map(p=>[p.key,e[p.key]??"true"])),[l,h]=M.useState(()=>Object.fromEntries(o.map(p=>[p.key,c[p.key]==="true"])));M.useEffect(()=>{o.forEach(p=>n(p.key))},[n]),M.useEffect(()=>{h(Object.fromEntries(o.map(p=>[p.key,c[p.key]==="true"])))},[JSON.stringify(c)]);const f=async p=>{const m=String(!l[p]);h(x=>({...x,[p]:!x[p]})),await s(p,m)};return a?u.jsx("div",{className:"text-sm text-text-muted",children:"Loading..."}):u.jsxs("div",{className:"space-y-6",children:[u.jsx(Kj,{}),u.jsxs("div",{children:[u.jsx("h3",{className:"text-sm font-medium text-text-primary mb-4",children:"Feed Display"}),u.jsx("div",{className:"space-y-4",children:o.map(({key:p,label:m,description:x})=>u.jsxs("label",{className:"flex items-center justify-between cursor-pointer",children:[u.jsxs("div",{children:[u.jsx("div",{className:"text-sm text-text-primary",children:m}),u.jsx("div",{className:"text-xs text-text-muted",children:x})]}),u.jsx("button",{type:"button",onClick:()=>f(p),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${l[p]?"bg-accent-primary":"bg-bg-tertiary"}`,children:u.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${l[p]?"translate-x-6":"translate-x-1"}`})})]},p))})]})]})}function Xj({label:e,binding:t,isRecording:n,onStartRecording:s,onBindingRecorded:a,onCancelRecording:o}){const c=M.useRef(null),l=M.useRef(0),h=M.useRef("");return M.useEffect(()=>{if(!n)return;const f=new Set(["Control","Shift","Alt","Meta"]);let p=[];const m=_=>{if(_.preventDefault(),_.stopPropagation(),_.key==="Escape"){o();return}if(f.has(_.key)){_.ctrlKey&&!p.includes("ctrl")&&p.push("ctrl"),_.metaKey&&!p.includes("meta")&&p.push("meta"),_.altKey&&!p.includes("alt")&&p.push("alt"),_.shiftKey&&!p.includes("shift")&&p.push("shift");return}if(p.length>0||_.ctrlKey||_.metaKey||_.altKey||_.shiftKey){const v=[...p];_.ctrlKey&&!v.includes("ctrl")&&v.push("ctrl"),_.metaKey&&!v.includes("meta")&&v.push("meta"),_.altKey&&!v.includes("alt")&&v.push("alt"),_.shiftKey&&!v.includes("shift")&&v.push("shift"),a({type:"chord",key:Ov(_),modifiers:v});return}const w=Date.now(),k=Ov(_);if(k===h.current&&w-l.current<400){a({type:"double-press",key:k,threshold:300});return}l.current=w,h.current=k},x=_=>{_.key==="Control"&&(p=p.filter(w=>w!=="ctrl")),_.key==="Shift"&&(p=p.filter(w=>w!=="shift")),_.key==="Alt"&&(p=p.filter(w=>w!=="alt")),_.key==="Meta"&&(p=p.filter(w=>w!=="meta"))};return window.addEventListener("keydown",m,!0),window.addEventListener("keyup",x,!0),()=>{window.removeEventListener("keydown",m,!0),window.removeEventListener("keyup",x,!0)}},[n,a,o]),u.jsxs("div",{ref:c,className:`flex items-center justify-between px-3 py-2 rounded transition-colors ${n?"bg-accent-primary/10 ring-1 ring-accent-primary":"hover:bg-bg-tertiary"}`,children:[u.jsx("span",{className:"text-sm text-text-primary",children:e}),u.jsx("div",{className:"flex items-center gap-2",children:n?u.jsx("span",{className:"text-xs text-accent-primary font-medium animate-pulse",children:"Press shortcut..."}):u.jsx("button",{type:"button",onClick:s,className:"px-2 py-0.5 text-xs font-mono bg-bg-tertiary text-text-secondary rounded border border-border hover:border-accent-primary hover:text-accent-primary transition-colors",children:pS(t)})})]})}function Qj(){const{settings:e,loading:t,getSetting:n,setSetting:s}=Du(),a=e[Pe.KEYBINDINGS],o=t[Pe.KEYBINDINGS]??!1,c=_m(a),[l,h]=M.useState(null);M.useEffect(()=>{n(Pe.KEYBINDINGS)},[n]);const f=[{id:"terminalToggle",label:"Toggle Terminal",binding:c.terminalToggle},{id:"quickAction",label:"Quick Action",binding:c.quickAction},...c.agentSwitching.map((_,w)=>({id:`agentSwitching.${w}`,label:`Switch to Agent ${w+1}`,binding:_}))],p=_=>{h(_)},m=M.useCallback(_=>{if(!l)return;const w=_m(a),k=structuredClone(w);if(l.startsWith("agentSwitching.")){const v=parseInt(l.split(".")[1],10);k.agentSwitching[v]=_}else l==="terminalToggle"?k.terminalToggle=_:l==="quickAction"&&(k.quickAction=_);h(null),s(Pe.KEYBINDINGS,JSON.stringify(k))},[l,a,s]),x=()=>{s(Pe.KEYBINDINGS,JSON.stringify(Sa))};return u.jsxs("div",{className:"space-y-4",children:[u.jsxs("div",{className:"flex items-center justify-between mb-2",children:[u.jsx("h3",{className:"text-sm font-medium text-text-primary",children:"Keyboard Shortcuts"}),u.jsx("button",{type:"button",onClick:x,disabled:o,className:"text-xs text-text-muted hover:text-text-primary px-2 py-1 rounded hover:bg-bg-tertiary transition-colors disabled:opacity-30",children:"Reset to defaults"})]}),o?u.jsx("div",{className:"text-sm text-text-muted",children:"Loading..."}):u.jsx("div",{className:"space-y-1",children:f.map(_=>u.jsx(Xj,{label:_.label,binding:_.binding,isRecording:l===_.id,onStartRecording:()=>p(_.id),onBindingRecorded:m,onCancelRecording:()=>h(null)},_.id))})]})}function Bv({enabled:e,onClick:t}){return u.jsx("button",{type:"button",onClick:t,className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${e?"bg-accent-primary":"bg-bg-tertiary"}`,children:u.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${e?"translate-x-6":"translate-x-1"}`})})}function Jj({onClose:e}){const[,t]=gr(),{settings:n,loading:s,getSetting:a,setSetting:o}=Du(),c=n[Pe.LLM_DISABLE_XML_PROTECTION]==="true",l=n[Pe.DISPLAY_SHOW_OPEN_IN_EDITOR]==="true",h=s[Pe.LLM_DISABLE_XML_PROTECTION]??!1;M.useEffect(()=>{a(Pe.LLM_DISABLE_XML_PROTECTION),a(Pe.DISPLAY_SHOW_OPEN_IN_EDITOR)},[a]);const f=async()=>{const x=String(!c);await o(Pe.LLM_DISABLE_XML_PROTECTION,x)},p=async()=>{const x=String(!l);await o(Pe.DISPLAY_SHOW_OPEN_IN_EDITOR,x)};function m(){e(),t("/onboarding")}return h?u.jsx("div",{className:"text-sm text-text-muted",children:"Loading..."}):u.jsxs("div",{className:"space-y-6",children:[u.jsx("div",{children:u.jsxs("label",{className:"flex items-center justify-between cursor-pointer",children:[u.jsxs("div",{children:[u.jsx("div",{className:"text-sm font-medium text-text-primary",children:"Disable XML Tool Call Protection"}),u.jsx("div",{className:"text-xs text-text-muted mt-0.5",children:"Allow the model to output XML tool call format instead of JSON function calls. Some third-party providers may require this."})]}),u.jsx(Bv,{enabled:c,onClick:f})]})}),u.jsx("hr",{className:"border-border"}),u.jsxs("div",{children:[u.jsx("h3",{className:"text-sm font-medium text-text-primary mb-3",children:"Integrations"}),u.jsxs("label",{className:"flex items-center justify-between cursor-pointer",children:[u.jsxs("div",{children:[u.jsx("div",{className:"text-sm text-text-primary",children:'Show "Open in VSCode" links'}),u.jsx("div",{className:"text-xs text-text-muted mt-0.5",children:"Display a link on file reads to open the file directly in VS Code."})]}),u.jsx(Bv,{enabled:l,onClick:p})]})]}),u.jsx("hr",{className:"border-border"}),u.jsxs("div",{children:[u.jsx("h3",{className:"text-sm font-medium text-text-primary mb-1",children:"Onboarding"}),u.jsx("p",{className:"text-sm text-text-muted mb-4",children:"Reset your OpenFox setup and go through the initial configuration again."}),u.jsx(Je,{variant:"secondary",onClick:m,children:"Launch Onboarding"})]})]})}function pa({label:e,active:t,onClick:n}){return u.jsx("button",{onClick:n,className:`px-4 py-2 text-sm font-medium border-b-2 transition-colors ${t?"border-accent-primary text-accent-primary":"border-transparent text-text-muted hover:text-text-secondary hover:border-border"}`,children:e})}function Zj({isOpen:e,onClose:t}){const[n,s]=M.useState("instructions");return u.jsx(Ct,{isOpen:e,onClose:t,title:"Settings",size:"xl",minHeight:"500px",children:u.jsxs("div",{className:"flex flex-col h-full",children:[u.jsxs("div",{className:"flex border-b border-border mb-4 -mt-1",children:[u.jsx(pa,{label:"Instructions",active:n==="instructions",onClick:()=>s("instructions")}),u.jsx(pa,{label:"Skills",active:n==="skills",onClick:()=>s("skills")}),u.jsx(pa,{label:"Notifications",active:n==="notifications",onClick:()=>s("notifications")}),u.jsx(pa,{label:"Display",active:n==="display",onClick:()=>s("display")}),u.jsx(pa,{label:"Shortcuts",active:n==="keybindings",onClick:()=>s("keybindings")}),u.jsx(pa,{label:"Advanced",active:n==="advanced",onClick:()=>s("advanced")})]}),n==="instructions"&&u.jsx(Vj,{isOpen:e}),n==="skills"&&u.jsx(Fj,{isOpen:e}),n==="notifications"&&u.jsx("div",{className:"max-h-[60vh] overflow-y-auto",children:u.jsx(Hj,{})}),n==="display"&&u.jsx(Yj,{}),n==="keybindings"&&u.jsx(Qj,{}),n==="advanced"&&u.jsx(Jj,{onClose:t})]})})}var jf={exports:{}},zv;function eT(){return zv||(zv=1,(function(e,t){(function(n,s){e.exports=s()})(globalThis,(()=>(()=>{var n={4567:function(c,l,h){var f=this&&this.__decorate||function(y,S,E,N){var T,L=arguments.length,A=L<3?S:N===null?N=Object.getOwnPropertyDescriptor(S,E):N;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")A=Reflect.decorate(y,S,E,N);else for(var P=y.length-1;P>=0;P--)(T=y[P])&&(A=(L<3?T(A):L>3?T(S,E,A):T(S,E))||A);return L>3&&A&&Object.defineProperty(S,E,A),A},p=this&&this.__param||function(y,S){return function(E,N){S(E,N,y)}};Object.defineProperty(l,"__esModule",{value:!0}),l.AccessibilityManager=void 0;const m=h(9042),x=h(9924),_=h(844),w=h(4725),k=h(2585),v=h(3656);let b=l.AccessibilityManager=class extends _.Disposable{constructor(y,S,E,N){super(),this._terminal=y,this._coreBrowserService=E,this._renderService=N,this._rowColumns=new WeakMap,this._liveRegionLineCount=0,this._charsToConsume=[],this._charsToAnnounce="",this._accessibilityContainer=this._coreBrowserService.mainDocument.createElement("div"),this._accessibilityContainer.classList.add("xterm-accessibility"),this._rowContainer=this._coreBrowserService.mainDocument.createElement("div"),this._rowContainer.setAttribute("role","list"),this._rowContainer.classList.add("xterm-accessibility-tree"),this._rowElements=[];for(let T=0;T<this._terminal.rows;T++)this._rowElements[T]=this._createAccessibilityTreeNode(),this._rowContainer.appendChild(this._rowElements[T]);if(this._topBoundaryFocusListener=T=>this._handleBoundaryFocus(T,0),this._bottomBoundaryFocusListener=T=>this._handleBoundaryFocus(T,1),this._rowElements[0].addEventListener("focus",this._topBoundaryFocusListener),this._rowElements[this._rowElements.length-1].addEventListener("focus",this._bottomBoundaryFocusListener),this._refreshRowsDimensions(),this._accessibilityContainer.appendChild(this._rowContainer),this._liveRegion=this._coreBrowserService.mainDocument.createElement("div"),this._liveRegion.classList.add("live-region"),this._liveRegion.setAttribute("aria-live","assertive"),this._accessibilityContainer.appendChild(this._liveRegion),this._liveRegionDebouncer=this.register(new x.TimeBasedDebouncer(this._renderRows.bind(this))),!this._terminal.element)throw new Error("Cannot enable accessibility before Terminal.open");this._terminal.element.insertAdjacentElement("afterbegin",this._accessibilityContainer),this.register(this._terminal.onResize((T=>this._handleResize(T.rows)))),this.register(this._terminal.onRender((T=>this._refreshRows(T.start,T.end)))),this.register(this._terminal.onScroll((()=>this._refreshRows()))),this.register(this._terminal.onA11yChar((T=>this._handleChar(T)))),this.register(this._terminal.onLineFeed((()=>this._handleChar(`
58
+ */var uv;function d2(){if(uv)return Sf;uv=1;var e=ku();function t(m,x){return m===x&&(m!==0||1/m===1/x)||m!==m&&x!==x}var n=typeof Object.is=="function"?Object.is:t,s=e.useState,a=e.useEffect,o=e.useLayoutEffect,c=e.useDebugValue;function l(m,x){var _=x(),w=s({inst:{value:_,getSnapshot:x}}),k=w[0].inst,v=w[1];return o(function(){k.value=_,k.getSnapshot=x,h(k)&&v({inst:k})},[m,_,x]),a(function(){return h(k)&&v({inst:k}),m(function(){h(k)&&v({inst:k})})},[m]),c(_),_}function h(m){var x=m.getSnapshot;m=m.value;try{var _=x();return!n(m,_)}catch{return!0}}function f(m,x){return x()}var p=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?f:l;return Sf.useSyncExternalStore=e.useSyncExternalStore!==void 0?e.useSyncExternalStore:p,Sf}var dv;function h2(){return dv||(dv=1,bf.exports=d2()),bf.exports}var f2=h2();const m2=QE.useInsertionEffect,p2=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",g2=p2?M.useLayoutEffect:M.useEffect,x2=m2||g2,X0=e=>{const t=M.useRef([e,(...n)=>t[0](...n)]).current;return x2(()=>{t[0]=e}),t[1]},_2="popstate",Xm="pushState",Qm="replaceState",y2="hashchange",hv=[_2,Xm,Qm,y2],v2=e=>{for(const t of hv)addEventListener(t,e);return()=>{for(const t of hv)removeEventListener(t,e)}},Q0=(e,t)=>f2.useSyncExternalStore(v2,e,t),fv=()=>location.search,b2=({ssrSearch:e}={})=>Q0(fv,e!=null?()=>e:fv),mv=()=>location.pathname,S2=({ssrPath:e}={})=>Q0(mv,e!=null?()=>e:mv),w2=(e,{replace:t=!1,state:n=null}={})=>history[t?Qm:Xm](n,"",e),C2=(e={})=>[S2(e),w2],pv=Symbol.for("wouter_v3");if(typeof history<"u"&&typeof window[pv]>"u"){for(const e of[Xm,Qm]){const t=history[e];history[e]=function(){const n=t.apply(this,arguments),s=new Event(e);return s.arguments=arguments,dispatchEvent(s),n}}Object.defineProperty(window,pv,{value:!0})}const k2=(e,t)=>t.toLowerCase().indexOf(e.toLowerCase())?"~"+t:t.slice(e.length)||"/",J0=(e="")=>e==="/"?"":e,E2=(e,t)=>e[0]==="~"?e.slice(1):J0(t)+e,j2=(e="",t)=>k2(gv(J0(e)),gv(t)),gv=e=>{try{return decodeURI(e)}catch{return e}},Z0={hook:C2,searchHook:b2,parser:u2,base:"",ssrPath:void 0,ssrSearch:void 0,ssrContext:void 0,hrefs:e=>e,aroundNav:(e,t,n)=>e(t,n)},eS=M.createContext(Z0),Oa=()=>M.useContext(eS),tS={},nS=M.createContext(tS),T2=()=>M.useContext(nS),ju=e=>{const[t,n]=e.hook(e);return[j2(e.base,t),X0((s,a)=>e.aroundNav(n,E2(s,e.base),a))]},gr=()=>ju(Oa()),Jm=(e,t,n,s)=>{const{pattern:a,keys:o}=t instanceof RegExp?{keys:!1,pattern:t}:e(t||"*",s),c=a.exec(n)||[],[l,...h]=c;return l!==void 0?[!0,(()=>{const f=o!==!1?Object.fromEntries(o.map((m,x)=>[m,h[x]])):c.groups;let p={...h};return f&&Object.assign(p,f),p})(),...s?[l]:[]]:[!1,null]},Zm=e=>Jm(Oa().parser,e,gr()[0]),N2=({children:e,...t})=>{var p,m,x;const n=Oa(),s=t.hook?Z0:n;let a=s;const[o,c=t.ssrSearch??""]=((p=t.ssrPath)==null?void 0:p.split("?"))??[];o&&(t.ssrSearch=c,t.ssrPath=o),t.hrefs=t.hrefs??((m=t.hook)==null?void 0:m.hrefs),t.searchHook=t.searchHook??((x=t.hook)==null?void 0:x.searchHook);let l=M.useRef({}),h=l.current,f=h;for(let _ in s){const w=_==="base"?s[_]+(t[_]??""):t[_]??s[_];h===f&&w!==f[_]&&(l.current=f={...f}),f[_]=w,(w!==s[_]||w!==a[_])&&(a=f)}return M.createElement(eS.Provider,{value:a,children:e})},xv=({children:e,component:t},n)=>t?M.createElement(t,{params:n}):typeof e=="function"?e(n):e,A2=e=>{let t=M.useRef(tS);const n=t.current;return t.current=Object.keys(e).length!==Object.keys(n).length||Object.entries(e).some(([s,a])=>a!==n[s])?e:n},Ro=({path:e,nest:t,match:n,...s})=>{const a=Oa(),[o]=ju(a),[c,l,h]=n??Jm(a.parser,e,o,t),f=A2({...T2(),...l});if(!c)return null;const p=h?M.createElement(N2,{base:h},xv(s,f)):xv(s,f);return M.createElement(nS.Provider,{value:f,children:p})},Fn=M.forwardRef((e,t)=>{const n=Oa(),[s,a]=ju(n),{to:o="",href:c=o,onClick:l,asChild:h,children:f,className:p,replace:m,state:x,transition:_,...w}=e,k=X0(b=>{b.ctrlKey||b.metaKey||b.altKey||b.shiftKey||b.button!==0||(l==null||l(b),b.defaultPrevented||(b.preventDefault(),a(c,e)))}),v=n.hrefs(c[0]==="~"?c.slice(1):n.base+c,n);return h&&M.isValidElement(f)?M.cloneElement(f,{onClick:k,href:v}):M.createElement("a",{...w,onClick:k,href:v,className:p!=null&&p.call?p(s===c):p,children:f,ref:t})}),rS=e=>Array.isArray(e)?e.flatMap(t=>rS(t&&t.type===M.Fragment?t.props.children:t)):[e],L2=({children:e,location:t})=>{const n=Oa(),[s]=ju(n);for(const a of rS(e)){let o=0;if(M.isValidElement(a)&&(o=Jm(n.parser,a.props.path,t||s,a.props.nest))[0])return M.cloneElement(a,{match:o})}return null};function D2(e){return typeof e=="object"&&e!==null&&"type"in e&&"payload"in e}function sS(){if(typeof crypto<"u"&&crypto.randomUUID)try{return crypto.randomUUID()}catch{}return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){const t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}class R2{constructor(t){he(this,"ws",null);he(this,"handlers",new Set);he(this,"statusHandler",null);he(this,"baseUrl");he(this,"isReconnecting",!1);he(this,"connectingPromise",null);he(this,"lastCloseCode",0);he(this,"reconnectAttempts",0);he(this,"manualReconnectScheduled",!1);this.baseUrl=t}getUrl(){const t=localStorage.getItem("openfox_token");if(t){const n=this.baseUrl.includes("?")?"&":"?";return`${this.baseUrl}${n}token=${encodeURIComponent(t)}`}return this.baseUrl}setToken(t){localStorage.setItem("openfox_token",t)}clearToken(){localStorage.removeItem("openfox_token")}hasToken(){return!!localStorage.getItem("openfox_token")}getLastCloseCode(){return this.lastCloseCode}onStatusChange(t){this.statusHandler=t}connect(){var t,n,s;return((t=this.ws)==null?void 0:t.readyState)===WebSocket.OPEN?Promise.resolve():(this.lastCloseCode=0,this.isReconnecting=!1,this.connectingPromise&&((n=this.ws)==null?void 0:n.readyState)===WebSocket.CONNECTING?this.connectingPromise:(this.lastCloseCode=0,this.isReconnecting=!1,this.connectingPromise&&((s=this.ws)==null?void 0:s.readyState)===WebSocket.CONNECTING?(console.warn("[WS CLIENT] Connection already in progress, returning existing promise"),this.connectingPromise):(this.connectingPromise=new Promise((a,o)=>{try{const c=this.getUrl();this.ws=new WebSocket(c);const l=setTimeout(()=>{var h;((h=this.ws)==null?void 0:h.readyState)===WebSocket.CONNECTING&&(this.ws.close(),o(new Error("Connection timeout")))},5e3);this.ws.onopen=()=>{var h;clearTimeout(l),this.isReconnecting=!1,this.connectingPromise=null,(h=this.statusHandler)==null||h.call(this,"connected"),a()},this.ws.onclose=h=>{var f,p,m;clearTimeout(l),this.lastCloseCode=h.code,((f=this.ws)==null?void 0:f.readyState)===WebSocket.CONNECTING?(this.connectingPromise=null,(p=this.statusHandler)==null||p.call(this,"disconnected"),o(new Error(`Connection closed: ${h.code}`))):(this.connectingPromise=null,(m=this.statusHandler)==null||m.call(this,"disconnected"),this.attemptReconnect())},this.ws.onerror=h=>{clearTimeout(l),console.error("WebSocket error:",h),this.connectingPromise=null,o(h)},this.ws.onmessage=h=>{try{const f=JSON.parse(h.data);D2(f)&&this.handlers.forEach(p=>p(f))}catch(f){console.error("Failed to parse WebSocket message:",f)}}}catch(c){this.connectingPromise=null,o(c)}}),this.connectingPromise)))}attemptReconnect(){var a;if(([1e3,1005,1006,4e3].includes(this.lastCloseCode)||this.lastCloseCode===0)&&this.hasToken()){console.warn("[WS] Auth failure or initial failure with token - not auto-reconnecting, awaiting user action");return}if(this.isReconnecting||this.manualReconnectScheduled)return;this.isReconnecting=!0,(a=this.statusHandler)==null||a.call(this,"reconnecting");const s=Math.min(1e3*Math.pow(2,this.reconnectAttempts||0),3e4);this.reconnectAttempts=(this.reconnectAttempts||0)+1,setTimeout(()=>{this.isReconnecting=!1,this.manualReconnectScheduled=!1,this.connect().catch(()=>{})},s)}reconnect(){this.manualReconnectScheduled=!0,this.isReconnecting=!1,this.lastCloseCode=0,this.connectingPromise=null,this.connect().catch(()=>{})}disconnect(){this.isReconnecting=!1,this.reconnectAttempts=0,this.ws&&(this.ws.close(),this.ws=null)}resetReconnectAttempts(){this.reconnectAttempts=0}send(t,n){if(!this.ws||this.ws.readyState!==WebSocket.OPEN)throw new Error("WebSocket not connected");const s=sS(),a={id:s,type:t,payload:n};return this.ws.send(JSON.stringify(a)),s}subscribe(t){return this.handlers.add(t),()=>this.handlers.delete(t)}get isConnected(){var t;return((t=this.ws)==null?void 0:t.readyState)===WebSocket.OPEN}}const O2=window.location.protocol==="https:"?"wss:":"ws:";let fm=window.location.port;fm||(fm=window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"?"10469":window.location.protocol==="https:"?"443":"80");const M2=`${O2}//${window.location.hostname}:${fm}/ws`,Kt=new R2(M2);function I2(e){return{...e.temperature!=null&&{temperature:e.temperature},...e.topP!=null&&{topP:e.topP},...e.topK!=null&&{topK:e.topK},...e.maxTokens!=null&&{maxTokens:e.maxTokens}}}async function _v(e,t,n){const s=await je(`/api/providers/${e}/models/${encodeURIComponent(t)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});if(!s.ok){const a=await s.json();throw new Error(a.error??"Failed to update model")}return s.json()}function yv(e,t,n,s){return e.map(a=>a.id===t?{...a,models:a.models.map(o=>o.id===n?{...o,...s,source:"user"}:o)}:a)}const P2=3e4;function mm(e){switch(e){case"vllm":return"vLLM";case"sglang":return"SGLang";case"ollama":return"Ollama";case"llamacpp":return"llama.cpp";case"openai":return"OpenAI";case"anthropic":return"Anthropic";case"opencode-go":return"OpenCode Go";case"auto":return"Auto";case"unknown":return""}}const jt=Gn((e,t)=>({version:null,model:null,maxContext:2e5,llmUrl:null,llmStatus:"unknown",backend:"unknown",providers:[],activeProviderId:null,defaultModelSelection:null,loading:!1,activating:!1,error:null,autoRefreshInterval:null,fetchConfig:async()=>{e({loading:!0,error:null});try{const n=await je("/api/config");if(!n.ok)throw new Error("Failed to fetch config");const s=await n.json();e({version:s.version,model:s.model,maxContext:s.maxContext,llmUrl:s.llmUrl,llmStatus:s.llmStatus,backend:s.backend,providers:s.providers??[],activeProviderId:s.activeProviderId??null,defaultModelSelection:s.defaultModelSelection??null,loading:!1})}catch(n){e({error:n instanceof Error?n.message:"Unknown error",loading:!1})}},refreshModel:async()=>{try{const n=await je("/api/model/refresh",{method:"POST"});if(!n.ok)throw new Error("Failed to refresh model");const s=await n.json(),o=we.getState().currentSession;if(o!=null&&o.providerId&&o.providerModel){e({llmStatus:s.llmStatus,backend:s.backend});return}e({model:s.model,llmStatus:s.llmStatus,backend:s.backend})}catch(n){console.error("Failed to refresh model:",n)}},activateProvider:async n=>{const{activeProviderId:s,providers:a}=t();if(n===s)return!0;e({activating:!0,error:null});try{const o=await je(`/api/providers/${n}/activate`,{method:"POST"});if(!o.ok){const l=await o.json();throw new Error(l.error??"Failed to activate provider")}const c=await o.json();return e({activeProviderId:c.activeProviderId,model:c.model,backend:c.backend,providers:a.map(l=>({...l,isActive:l.id===c.activeProviderId})),activating:!1}),!0}catch(o){return e({error:o instanceof Error?o.message:"Failed to switch provider",activating:!1}),!1}},syncFromSession:(n,s)=>{var l;const{providers:a,defaultModelSelection:o}=t();let c=s;if(!c){const h=o?o.split("/"):[],f=h[0],p=h.slice(1).join("/")??"";if(f===n&&p)c=p;else{const m=a.find(x=>x.id===n);c=((l=m==null?void 0:m.models[0])==null?void 0:l.id)??""}}e({activeProviderId:n,model:c,defaultModelSelection:`${n}/${c}`,providers:a.map(h=>({...h,isActive:h.id===n}))})},updateModelContext:async(n,s,a)=>{e({activating:!0,error:null});try{const o=await _v(n,s,{contextWindow:a}),{providers:c}=t();return e({providers:yv(c,n,s,{contextWindow:a}),activating:!1}),o.contextState&&we.getState().updateContextState(o.contextState),!0}catch(o){return e({error:o instanceof Error?o.message:"Failed to update model context",activating:!1}),!1}},updateModelSettings:async(n,s,a)=>{e({activating:!0,error:null});try{const o=await _v(n,s,a),{providers:c}=t(),l={...a.contextWindow!==void 0&&{contextWindow:a.contextWindow},...I2({temperature:a.temperature??void 0,topP:a.topP??void 0,topK:a.topK??void 0,maxTokens:a.maxTokens??void 0}),...a.supportsVision!==void 0&&{supportsVision:a.supportsVision}};return e({providers:yv(c,n,s,l),activating:!1}),o.contextState&&we.getState().updateContextState(o.contextState),!0}catch(o){return e({error:o instanceof Error?o.message:"Failed to update model settings",activating:!1}),!1}},refreshProviderModels:async n=>{e({activating:!0,error:null});try{const s=await je(`/api/providers/${n}/refresh`,{method:"POST"});if(!s.ok){const c=await s.json();throw new Error(c.error??"Failed to refresh models")}const a=await s.json(),{providers:o}=t();return e({providers:o.map(c=>c.id===n?{...c,models:a.models,status:a.status}:c),activating:!1}),!0}catch(s){return e({error:s instanceof Error?s.message:"Failed to refresh models",activating:!1}),!1}},startAutoRefresh:()=>{const{autoRefreshInterval:n,refreshModel:s}=t();if(n)return;const a=setInterval(()=>{s()},P2);e({autoRefreshInterval:a})},stopAutoRefresh:()=>{const{autoRefreshInterval:n}=t();n&&(clearInterval(n),e({autoRefreshInterval:null}))},getActiveProvider:()=>{const{providers:n,activeProviderId:s}=t();return n.find(a=>a.id===s)},getModelContext:n=>{const{providers:s,activeProviderId:a}=t(),o=s.find(l=>l.id===a);if(!o)return 2e5;const c=o.models.find(l=>l.id===n);return(c==null?void 0:c.contextWindow)??2e5}})),Lt=Gn((e,t)=>({projects:[],currentProject:null,loading:!1,listProjects:async()=>{e({loading:!0});try{const s=await(await je("/api/projects")).json();e({projects:s.projects??[],loading:!1})}catch(n){console.error("Failed to load projects:",n),e({loading:!1})}},createProject:async(n,s)=>{try{const a=await je("/api/projects",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:n,workdir:s})});if(!a.ok){const c=await a.json().catch(()=>({}));return{error:{code:c.code||"UNKNOWN",path:c.path,message:c.error}}}const o=await a.json();return await t().listProjects(),o.project}catch{return null}},loadProject:async n=>{try{const s=await je(`/api/projects/${n}`);if(!s.ok)return null;const a=await s.json();return e({currentProject:a.project}),t().projects.length===0&&await t().listProjects(),a.project}catch{return null}},updateProject:async(n,s)=>{var a;try{const o=await je(`/api/projects/${n}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});if(!o.ok)return null;const c=await o.json();return((a=t().currentProject)==null?void 0:a.id)===n&&e({currentProject:c.project}),await t().listProjects(),c.project}catch{return null}},deleteProject:async n=>{var s;try{return(await je(`/api/projects/${n}`,{method:"DELETE"})).ok?(await t().listProjects(),((s=t().currentProject)==null?void 0:s.id)===n&&e({currentProject:null}),!0):!1}catch{return!1}},toggleStar:async(n,s)=>{var a;try{const o=await je(`/api/projects/${n}/star`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({isStarred:s})});if(!o.ok)return!1;if(((a=t().currentProject)==null?void 0:a.id)===n){const c=await o.json();e({currentProject:c.project})}return await t().listProjects(),!0}catch{return!1}},clearProject:()=>{e({currentProject:null})}})),Us=async(e,t,n)=>{try{const s=await je(t,{method:e,headers:{"Content-Type":"application/json"},body:JSON.stringify(n)});return s.ok?{success:!0}:{success:!1,error:(await s.json()).error}}catch{return{success:!1,error:"Network error"}}},Tu=async(e,t,n)=>{try{const s=await je(e,{method:"POST",body:n?JSON.stringify({destination:n}):void 0,headers:n?{"Content-Type":"application/json"}:void 0}),a=await s.json();return s.ok?(await t(),{success:!0}):{success:!1,error:a.error??"Failed to duplicate"}}catch{return{success:!1,error:"Network error"}}};function iS(e){let t=null;function n(){t===null&&(t=requestAnimationFrame(()=>{t=null,e()}))}return n}let Oc=[];const Ko=Gn()((e,t)=>{function n(){if(Oc.length===0)return;const a=Oc;Oc=[],e(o=>{const c={...o.logs};for(const l of a){const h=c[l.processId]??[];c[l.processId]=[...h,{offset:h.length,content:l.content,timestamp:Date.now(),stream:l.stream}]}return{logs:c}})}const s=iS(n);return{processes:[],logs:{},loading:!1,setProcesses:a=>e({processes:a}),addProcess:a=>e(o=>({processes:[...o.processes,a]})),updateProcess:(a,o)=>e(c=>({processes:c.processes.map(l=>l.id===a?{...l,...o}:l)})),removeProcess:a=>e(o=>({processes:o.processes.filter(c=>c.id!==a),logs:Object.fromEntries(Object.entries(o.logs).filter(([c])=>c!==a))})),stopProcess:async(a,o)=>{try{(await je(`/api/sessions/${o}/background-process/${a}/stop`,{method:"POST"})).ok&&t().removeProcess(a)}catch{}},appendLog:(a,o,c)=>{Oc.push({processId:a,stream:o,content:c}),s()},setLogs:(a,o)=>e(c=>({logs:{...c.logs,[a]:o}})),clearLogs:a=>e(o=>({logs:{...o.logs,[a]:[]}})),handleMessage:(a,o)=>{switch(a){case"backgroundProcess.started":{const{processId:c,name:l,pid:h,status:f}=o;e(p=>({processes:[...p.processes,{id:c,sessionId:"",name:l,command:"",cwd:"",pid:h,status:f,exitCode:null,createdAt:Date.now(),startedAt:Date.now(),endedAt:null}]}));break}case"backgroundProcess.output":{const c=o.processId,l=o.stream,h=o.content;t().appendLog(c,l,h);break}case"backgroundProcess.exited":{const c=o.processId,l=o.exitCode;e(h=>({processes:h.processes.map(f=>f.id===c?{...f,status:"exited",exitCode:l}:f)}));break}case"backgroundProcess.removed":{const c=o.processId;t().removeProcess(c);break}}}}}),B2={messageId:null,deltaContent:"",thinkingContent:"",toolOutput:[]};let Ea=null,Jc=null;function z2(e){Jc=e}function fi(){return B2}function wf(){Ea===null&&(Ea=requestAnimationFrame(()=>{Ea=null,Jc==null||Jc()}))}function xi(){Ea!==null&&(cancelAnimationFrame(Ea),Ea=null)}let Mc=[];const jr=Gn()((e,t)=>{function n(){if(Mc.length===0)return;const a=Mc;Mc=[],e(o=>({logs:[...o.logs,...a]}))}const s=iS(n);return{workdir:null,status:null,logs:[],config:null,loading:!1,setWorkdir:a=>{t().workdir!==a&&(e({workdir:a,status:null,logs:[],config:null,loading:!0}),a&&(t().fetchStatus(),t().fetchConfig()))},fetchStatus:async()=>{const a=t().workdir;if(a)try{const c=await(await je(`/api/dev-server?workdir=${encodeURIComponent(a)}`)).json();e({status:c,loading:!1})}catch{e({loading:!1})}},fetchConfig:async()=>{const a=t().workdir;if(a)try{const c=await(await je(`/api/dev-server/config?workdir=${encodeURIComponent(a)}`)).json();e({config:c.config??null})}catch{}},fetchLogs:async()=>{const a=t().workdir;if(a)try{const l=(await(await je(`/api/dev-server/logs?workdir=${encodeURIComponent(a)}`)).json()).logs.map(h=>({stream:h.stream,content:h.content}));e({logs:l})}catch{}},start:async()=>{const a=t().workdir;if(a)try{const c=await(await je(`/api/dev-server/start?workdir=${encodeURIComponent(a)}`,{method:"POST"})).json();e({status:c,logs:[]})}catch{}},stop:async()=>{const a=t().workdir;if(a)try{const c=await(await je(`/api/dev-server/stop?workdir=${encodeURIComponent(a)}`,{method:"POST"})).json();e({status:c})}catch{}},restart:async()=>{const a=t().workdir;if(a)try{const c=await(await je(`/api/dev-server/restart?workdir=${encodeURIComponent(a)}`,{method:"POST"})).json();e({status:c,logs:[]})}catch{}},saveConfig:async a=>{const o=t().workdir;if(o)try{const l=await(await je(`/api/dev-server/config?workdir=${encodeURIComponent(o)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)})).json();e({config:l.config??a}),t().fetchStatus()}catch{}},handleMessage:a=>{const o=t().workdir;if(o)switch(a.type){case"devServer.output":{const c=a.payload;if(c.workdir!==o)return;Mc.push({stream:c.stream,content:c.content}),s();break}case"devServer.state":{const c=a.payload;if(c.workdir!==o)return;e(l=>({status:l.status?{...l.status,state:c.state,errorMessage:c.errorMessage}:l.status}));break}}}}}),H2=[{key:"complete",label:"Task Complete",description:"When an agent finishes its work"},{key:"waiting_for_user",label:"Waiting for Input",description:"When the agent needs your input"},{key:"phase_done",label:"Phase Done",description:"When a build phase completes successfully"},{key:"phase_blocked",label:"Phase Blocked",description:"When a build phase is blocked and needs intervention"},{key:"new_message",label:"New Message",description:"When a new assistant message starts arriving"}],$2=[{url:"/sounds/notification.mp3",label:"Notification"},{url:"/sounds/waiting-for-user.mp3",label:"Waiting for User"},{url:"/sounds/achievement.mp3",label:"Achievement"},{url:"/sounds/intervention.mp3",label:"Intervention"},{url:"/sounds/typing.mp3",label:"Typing"}],aS={complete:"/sounds/notification.mp3",waiting_for_user:"/sounds/waiting-for-user.mp3",phase_done:"/sounds/achievement.mp3",phase_blocked:"/sounds/intervention.mp3",new_message:"/sounds/typing.mp3"},Bs={soundEnabled:!0,browserNotification:!1,customSoundUrl:null},oS={soundEnabled:!1,browserNotification:!1,customSoundUrl:null},pm={soundEnabled:!0,browserNotificationEnabled:!1,events:{complete:{...Bs},waiting_for_user:{...Bs},phase_done:{...Bs},phase_blocked:{...Bs},new_message:{...oS}},agentOverrides:{}};function lS(e,t,n){var o;const s=e.events[t];if(!n)return s;const a=(o=e.agentOverrides[n])==null?void 0:o[t];return a?{soundEnabled:a.soundEnabled??s.soundEnabled,browserNotification:a.browserNotification??s.browserNotification,customSoundUrl:a.customSoundUrl!==void 0?a.customSoundUrl:s.customSoundUrl}:s}const pi=Gn((e,t)=>({settings:pm,loaded:!1,load:()=>{$t.getState().getSetting(Pe.NOTIFICATION_SETTINGS);const s=$t.subscribe(o=>{const c=o.settings[Pe.NOTIFICATION_SETTINGS];if(c!==void 0)try{const l=JSON.parse(c);e({settings:vv(l),loaded:!0})}catch{e({loaded:!0})}}),a=$t.getState().settings[Pe.NOTIFICATION_SETTINGS];if(a)try{const o=JSON.parse(a);e({settings:vv(o),loaded:!0})}catch{e({loaded:!0})}return s},update:n=>{e({settings:n}),Cf(n)},updateEvent:(n,s)=>{const a=t().settings,o={...a,events:{...a.events,[n]:{...a.events[n],...s}}};e({settings:o}),Cf(o)},updateAgentOverride:(n,s,a)=>{var h;const o=t().settings,c={...o.agentOverrides};if(a===null){if(c[n]){const f={...c[n]};delete f[s],Object.keys(f).length===0?delete c[n]:c[n]=f}}else c[n]={...c[n],[s]:{...((h=c[n])==null?void 0:h[s])??{},...a}};const l={...o,agentOverrides:c};e({settings:l}),Cf(l)}}));function Cf(e){$t.getState().setSetting(Pe.NOTIFICATION_SETTINGS,JSON.stringify(e))}function vv(e){var t,n,s,a,o;return{soundEnabled:e.soundEnabled??pm.soundEnabled,browserNotificationEnabled:e.browserNotificationEnabled??pm.browserNotificationEnabled,events:{complete:{...Bs,...(t=e.events)==null?void 0:t.complete},waiting_for_user:{...Bs,...(n=e.events)==null?void 0:n.waiting_for_user},phase_done:{...Bs,...(s=e.events)==null?void 0:s.phase_done},phase_blocked:{...Bs,...(a=e.events)==null?void 0:a.phase_blocked},new_message:{...oS,...(o=e.events)==null?void 0:o.new_message}},agentOverrides:e.agentOverrides??{}}}const bv=new Map;function U2(e){let t=bv.get(e);return t||(t=new Audio(e),t.volume=.5,bv.set(e,t)),t}let cS=typeof Notification<"u"?Notification.permission:"denied";function F2(){return typeof Notification>"u"?Promise.resolve("denied"):Notification.requestPermission().then(e=>(cS=e,e))}const V2={complete:"Task Complete",waiting_for_user:"Waiting for Input",phase_done:"Phase Complete",phase_blocked:"Phase Blocked",new_message:"New Message"},G2={complete:"The agent has finished its work.",waiting_for_user:"The agent needs your input to continue.",phase_done:"The build phase completed successfully.",phase_blocked:"The build phase is blocked and needs intervention.",new_message:"A new assistant message is arriving."};function W2(e){typeof Notification>"u"||cS==="granted"&&(document.hasFocus()||new Notification(V2[e],{body:G2[e],icon:"/fox.svg",tag:`openfox-${e}`}))}function ul(e,t){const{settings:n}=pi.getState(),s=lS(n,e,t);if(n.soundEnabled&&s.soundEnabled){const a=s.customSoundUrl??aS[e],o=U2(a);o.currentTime=0,o.play().catch(()=>{})}n.browserNotificationEnabled&&s.browserNotification&&W2(e)}const q2=e=>ul("complete",e),K2=e=>ul("phase_done",e),Y2=e=>ul("phase_blocked",e),Sv=e=>ul("waiting_for_user",e),X2=e=>ul("new_message",e),wv=new Map;function Go(e,t){var o;const n=t===((o=e.currentSession)==null?void 0:o.id)?e.currentSession:null,s=e.sessions.find(c=>c.id===t),a=(n==null?void 0:n.mode)??(s==null?void 0:s.mode);return a==="planner"?"planner":a==="builder"?"build":"planner"}function Q2(e,t){if(e.type==="chat.done"){const n=e.payload,s=Go(t,e.sessionId),a=n.agentType??s;n.reason==="complete"&&q2(a),n.reason==="waiting_for_user"&&Sv(a);return}if(e.type==="chat.path_confirmation"){const n=Go(t,e.sessionId);Sv(n);return}if(e.type==="task.completed"){const n=Go(t,e.sessionId);K2(n);return}if(e.type==="phase.changed"&&e.sessionId){const n=e.payload,s=wv.get(e.sessionId)??null;if(wv.set(e.sessionId,n.phase),s===n.phase)return;const a=Go(t,e.sessionId);n.phase==="blocked"&&Y2(a)}}const kf=new Set;function qt(e,t){return t!==null&&e.sessionId===t}function J2(e,t,n){return e.id!==void 0||qt(e,t)||n===!0&&e.sessionId!==void 0}function Z2(e,t){return e.includes(t)?e:[...e,t]}function Cv(e,t){return e.filter(n=>n!==t)}function ej(e,t){const n=e.find(o=>o.id===t.id),s=t.messageCount??t.messages.length,a=n?{...n,projectId:t.projectId,workdir:t.workdir,mode:t.mode,phase:t.phase,isRunning:t.isRunning&&n.isRunning!==!1,messageCount:s,criteriaCount:t.criteria.length,criteriaCompleted:t.criteria.filter(o=>o.status.type==="passed").length}:{id:t.id,projectId:t.projectId,workdir:t.workdir,mode:t.mode,phase:t.phase,isRunning:t.isRunning,createdAt:"",updatedAt:"",criteriaCount:t.criteria.length,criteriaCompleted:t.criteria.filter(o=>o.status.type==="passed").length,messageCount:s};return n?e.map(o=>o.id===t.id?a:o):[a,...e]}function tj(e,t,n){return e.map(s=>{const a=(n==null?void 0:n.id)===s.id?n:null,o=t.find(c=>c.id===s.id);return{...s,title:s.title??(o==null?void 0:o.title),mode:(a==null?void 0:a.mode)??(o==null?void 0:o.mode)??s.mode,phase:(a==null?void 0:a.phase)??(o==null?void 0:o.phase)??s.phase,isRunning:s.isRunning&&(o==null?void 0:o.isRunning)!==!1,messageCount:s.messageCount,recentUserPrompts:s.recentUserPrompts}})}function kv(e,t,n,s){var l;const a=e.sessionId,o=(l=n().currentSession)==null?void 0:l.id,c=a&&a!==o;if(t(h=>({sessions:h.sessions.map(f=>f.id===a?s(f):f)})),!c){const h=n().currentSession;if(h){const f=s(h);t(()=>({currentSession:f}))}}}function Ev(e,t,n){var c,l,h,f,p,m,x,_,w,k,v,b,y,S,E,N,T,L,A,P,R,$;const s=n();Q2(e,s);const a=((c=s.currentSession)==null?void 0:c.id)??null,o=()=>{const D=e.sessionId;!D||D===a||t(H=>({unreadSessionIds:Z2(H.unreadSessionIds,D)}))};switch(e.type){case"session.state":{const D=e.payload;if(!J2(e,a,s.pendingSessionCreate))break;xi();const H=D.messages.find(U=>U.isStreaming)??null,K=n().pendingSessionCreate===!0;if(t({currentSession:D.session,sessions:ej(n().sessions,D.session),unreadSessionIds:Cv(n().unreadSessionIds,D.session.id),messages:D.messages,streamingMessageId:(H==null?void 0:H.id)??null,streamingMessage:H,currentTodos:[],pendingPathConfirmations:D.pendingConfirmations??[],error:null,...K?{pendingSessionCreate:D.session.id}:{}}),D.session.providerId){const U=jt.getState();U.providers.find(J=>J.id===D.session.providerId)&&U.syncFromSession(D.session.providerId,D.session.providerModel??"")}break}case"session.list":{const D=e.payload;t(H=>({sessions:tj(D.sessions,H.sessions,H.currentSession)}));break}case"session.deleted":{const D=e.payload;t(H=>({unreadSessionIds:Cv(H.unreadSessionIds,D.sessionId)})),n().listSessions();break}case"session.deletedAll":{n().listSessions();break}case"session.running":{const D=e.payload;kv(e,t,n,H=>({...H,isRunning:D.isRunning})),D.isRunning||t({abortInProgress:!1,queuedMessages:[]});break}case"chat.message":{if(!qt(e,((l=n().currentSession)==null?void 0:l.id)??null)){o();break}const D=e.payload;t(H=>{if(H.messages.some(U=>U.id===D.message.id))return H;const K=D.message.role==="user";return{messages:[...H.messages,D.message],sessions:H.sessions.map(U=>U.id===e.sessionId&&K?{...U,messageCount:U.messageCount+1}:U),streamingMessageId:D.message.isStreaming?D.message.id:H.streamingMessageId,streamingMessage:D.message.isStreaming?D.message:H.streamingMessage}});break}case"chat.message_updated":{if(!qt(e,((h=n().currentSession)==null?void 0:h.id)??null)){o();break}const D=e.payload,H=D.updates.isStreaming===!1&&n().streamingMessageId===D.messageId;H&&xi(),t(K=>{const U=K.streamingMessage;if(U&&U.id===D.messageId){const F={...U,...D.updates};return{messages:K.messages.map(J=>J.id===D.messageId?F:J),streamingMessageId:H?null:K.streamingMessageId,streamingMessage:H?null:{...U,...D.updates}}}return{messages:K.messages.map(F=>F.id===D.messageId?{...F,...D.updates}:F),streamingMessageId:H?null:K.streamingMessageId}});break}case"chat.delta":{if(!qt(e,((f=n().currentSession)==null?void 0:f.id)??null)){o();break}const D=e.payload;if(!kf.has(D.messageId)){kf.add(D.messageId);const K=D.subAgentType?"sub-agent":Go(n(),e.sessionId);X2(K)}const H=fi();H.messageId=D.messageId,H.deltaContent+=D.content,wf();break}case"chat.thinking":{if(!qt(e,((p=n().currentSession)==null?void 0:p.id)??null)){o();break}const D=e.payload,H=fi();H.messageId=D.messageId,H.thinkingContent+=D.content,wf();break}case"chat.tool_preparing":{if(!qt(e,((m=n().currentSession)==null?void 0:m.id)??null)){o();break}const D=e.payload,H=n().streamingMessage;if(!H||H.id!==D.messageId||((x=H.toolCalls)==null?void 0:x.find((U,F)=>F===D.index)))return;t(U=>{const F=U.streamingMessage.preparingToolCalls??[],J=F.findIndex(B=>B.index===D.index);let Q;return J>=0?Q=F.map((B,O)=>O===J?{...B,arguments:D.arguments}:B):Q=[...F,{index:D.index,name:D.name,...D.arguments?{arguments:D.arguments}:{}}],{streamingMessage:{...U.streamingMessage,preparingToolCalls:Q}}});break}case"chat.tool_call":{if(!qt(e,((_=n().currentSession)==null?void 0:_.id)??null)){o();break}const D=e.payload,H=K=>{var Q;const U=(Q=K.preparingToolCalls)==null?void 0:Q.filter((B,O)=>{var z;return B.name===D.tool?(z=K.preparingToolCalls)==null?void 0:z.slice(0,O).some(V=>V.name===D.tool):!0}),F=fi(),J=F.toolOutput.filter(B=>B.callId===D.callId);return J.length>0&&(F.toolOutput=F.toolOutput.filter(B=>B.callId!==D.callId)),{...K,toolCalls:[...K.toolCalls??[],{id:D.callId,name:D.tool,arguments:D.args,startedAt:Date.now(),...J.length>0?{streamingOutput:J.map(B=>({stream:B.stream,content:B.content,timestamp:Date.now()}))}:{}}],...U&&U.length>0?{preparingToolCalls:U}:{preparingToolCalls:void 0}}};t(K=>{const U=K.streamingMessage;return U&&U.id===D.messageId?{streamingMessage:H(U)}:{messages:K.messages.map(F=>F.id===D.messageId?H(F):F)}});break}case"chat.tool_output":{if(!qt(e,((w=n().currentSession)==null?void 0:w.id)??null)){o();break}const D=e.payload,H=fi();H.messageId=D.messageId,H.toolOutput.push({messageId:D.messageId,callId:D.callId,stream:D.stream,content:D.output}),wf();break}case"chat.tool_result":{if(!qt(e,((k=n().currentSession)==null?void 0:k.id)??null)){o();break}const D=e.payload,H=K=>{var F;const U=(F=K.toolCalls)==null?void 0:F.map(J=>J.id===D.callId?{...J,result:D.result}:J);return{...K,toolCalls:U}};t(K=>{const U=K.streamingMessage;return U&&U.id===D.messageId?{streamingMessage:H(U)}:{messages:K.messages.map(F=>F.id===D.messageId?H(F):F)}});break}case"chat.vision_fallback":{if(!qt(e,((v=n().currentSession)==null?void 0:v.id)??null)){o();break}const D=e.payload;t(H=>{const K=`${D.messageId}-${D.attachmentId}`,U={...H.visionFallbackByMessage};return U[K]={type:D.type,attachmentId:D.attachmentId,filename:D.filename,description:D.description},{visionFallbackByMessage:U}});break}case"chat.todo":{if(!qt(e,((b=n().currentSession)==null?void 0:b.id)??null)){o();break}const D=e.payload;t({currentTodos:D.todos});break}case"chat.progress":{if(!qt(e,((y=n().currentSession)==null?void 0:y.id)??null)){o();break}const D=e.payload;console.warn("Progress:",D.message,D.phase);break}case"chat.format_retry":{if(!qt(e,((S=n().currentSession)==null?void 0:S.id)??null)){o();break}const D=e.payload;console.warn("Format retry:",D.attempt,"/",D.maxAttempts);break}case"chat.done":{if(!qt(e,((E=n().currentSession)==null?void 0:E.id)??null)){o();break}xi();const D=fi();D.messageId=null,D.deltaContent="",D.thinkingContent="",D.toolOutput=[],kf.delete(e.payload.messageId);const H=e.payload,K=H.stats;t(U=>{const F=U.streamingMessage,J=F&&F.id===H.messageId?{...F,isStreaming:!1,stats:K??F.stats}:null;return{messages:U.messages.map(Q=>Q.id===H.messageId?J??{...Q,isStreaming:!1,stats:K??Q.stats,completeReason:H.reason}:Q),streamingMessageId:null,streamingMessage:null,visionFallbackByMessage:{}}});break}case"chat.error":{if(!qt(e,((N=n().currentSession)==null?void 0:N.id)??null)){o();break}xi();const D=fi(),H=e.payload;console.error("Chat error:",H.error,"recoverable:",H.recoverable),H.recoverable||(D.messageId=null,D.deltaContent="",D.thinkingContent="",D.toolOutput=[]),t(K=>({error:{code:"CHAT_ERROR",message:H.error},streamingMessageId:H.recoverable?K.streamingMessageId:null,...H.recoverable?{}:{messages:K.streamingMessage?K.messages.map(U=>U.id===K.streamingMessage.id?K.streamingMessage:U):K.messages,streamingMessage:null}}));break}case"chat.path_confirmation":{if(!qt(e,((T=n().currentSession)==null?void 0:T.id)??null)){o();break}const D=e.payload,H={callId:D.callId,tool:D.tool,paths:D.paths,workdir:D.workdir,reason:D.reason};t(K=>({pendingPathConfirmations:[...K.pendingPathConfirmations,H]}));break}case"chat.ask_user":{if(!qt(e,((L=n().currentSession)==null?void 0:L.id)??null)){o();return}const D=e.payload;t({pendingQuestion:{callId:D.callId,question:D.question}});break}case"mode.changed":{if(!qt(e,((A=n().currentSession)==null?void 0:A.id)??null)){o();break}const D=e.payload;t(H=>({currentSession:H.currentSession?{...H.currentSession,mode:D.mode}:null}));break}case"phase.changed":{const D=e.payload;kv(e,t,n,H=>({...H,phase:D.phase}));break}case"criteria.updated":{if(!qt(e,((P=n().currentSession)==null?void 0:P.id)??null)){o();break}const D=e.payload;t(H=>({currentSession:H.currentSession?{...H.currentSession,criteria:D.criteria}:null}));break}case"context.state":{const D=e.payload,H=qt(e,((R=n().currentSession)==null?void 0:R.id)??null);D.subAgentId?H&&n().updateSubAgentContextState(D.subAgentId,D.context):H?t({contextState:D.context}):o();break}case"session.name_generated":{const D=e.payload,H=e.sessionId,K=($=n().currentSession)==null?void 0:$.id;t(U=>{const F=U.sessions.map(Q=>Q.id===H?{...Q,title:D.name,updatedAt:new Date().toISOString()}:Q),J=K===H?U.currentSession?{...U.currentSession,title:D.name,updatedAt:new Date().toISOString()}:null:U.currentSession;return{sessions:F,currentSession:J}});break}case"queue.state":{const D=e.payload;t({queuedMessages:D.messages??[]});break}case"git.status":{const D=e.payload;t({gitStatus:{branch:D.branch,diff:D.diff}});break}case"devServer.output":case"devServer.state":{jr.getState().handleMessage(e);break}case"backgroundProcess.started":case"backgroundProcess.output":case"backgroundProcess.exited":case"backgroundProcess.removed":{Ko.getState().handleMessage(e.type,e.payload);break}case"error":{const D=e.payload;console.error("Server error:",D),t({error:{code:D.code,message:D.message},streamingMessageId:null});break}}}let Oo=!1,Sr=null;const Ef=new Set,Ic=new Map;function jv(e,t,n){return e==null?void 0:e.map(s=>{const a=t.filter(o=>o.callId===s.id);return a.length===0?s:(n.add(s.id),{...s,streamingOutput:[...s.streamingOutput??[],...a.map(o=>({stream:o.stream,content:o.content,timestamp:Date.now()}))]})})}async function Tv(e,t,n,s,a){try{const c=await(await je(`/api/sessions/${e}/message`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:t,attachments:n,messageKind:s})})).json();c.queueState&&a({queuedMessages:c.queueState})}catch(o){console.error("Error queueing message:",o)}}const we=Gn((e,t)=>(z2(()=>{const n=fi();if(!n.messageId)return;const s=n.deltaContent.length>0,a=n.thinkingContent.length>0,o=n.toolOutput.length>0;if(!s&&!a&&!o)return;const c=n.deltaContent,l=n.thinkingContent,h=n.toolOutput;n.deltaContent="",n.thinkingContent="",n.toolOutput=[],e(f=>{const p=f.streamingMessage;if(p&&p.id===n.messageId){const m={...p};if(s&&(m.content=m.content+c),a&&(m.thinkingContent=(m.thinkingContent??"")+l),o){const x=new Set;m.toolCalls=jv(m.toolCalls,h,x);const _=h.filter(w=>!x.has(w.callId));_.length>0&&n.toolOutput.push(..._)}return{streamingMessage:m}}if(o){const m=new Set,x=f.messages.map(w=>w.id!==n.messageId?w:{...w,toolCalls:jv(w.toolCalls,h,m)}),_=h.filter(w=>!m.has(w.callId));return _.length>0&&n.toolOutput.push(..._),{messages:x}}return f})}),{connectionStatus:"disconnected",showPasswordModal:!1,passwordModalRetry:!1,sessions:[],currentSession:null,unreadSessionIds:[],messages:[],streamingMessageId:null,streamingMessage:null,currentTodos:[],contextState:null,subAgentContextStates:{},pendingPathConfirmations:[],pendingQuestion:null,visionFallbackByMessage:{},gitStatus:null,queuedMessages:[],abortInProgress:!1,error:null,sessionsHasMore:!0,sessionsPaginationLoading:!1,pendingSessionCreate:!1,connect:async()=>{if(t().connectionStatus==="connected")return;e({connectionStatus:"reconnecting"});let s=!1;try{s=(await(await je("/api/auth")).json()).requiresAuth}catch{}if(s&&!Kt.hasToken()){e({showPasswordModal:!0,passwordModalRetry:!1,connectionStatus:"reconnecting"});return}Kt.onStatusChange(a=>{var o;if(e({connectionStatus:a}),a==="connected"){t().listSessions(void 0),Lt.getState().listProjects();const c=(o=t().currentSession)==null?void 0:o.id;c&&t().loadSession(c)}});try{await Kt.connect(),Oo||(Oo=!0,Sr=Kt.subscribe(a=>{Ev(a,e,t)}))}catch(a){console.error("Failed to connect:",a);const o=Kt.getLastCloseCode();if(!Kt.hasToken()&&(o===1006||o===4e3)){e({showPasswordModal:!0,passwordModalRetry:!0,connectionStatus:"reconnecting"});return}Sr&&(Sr(),Sr=null),Oo=!1,e({connectionStatus:"disconnected"})}},reconnect:()=>{Kt.disconnect(),Sr&&(Sr(),Sr=null),Oo=!1,e({connectionStatus:"disconnected"}),t().connect()},disconnect:()=>{Kt.disconnect(),Sr&&(Sr(),Sr=null),Oo=!1,e({connectionStatus:"disconnected",showPasswordModal:!1})},submitPassword:async n=>{try{const s=await fetch("/api/auth/login",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({password:n})});if(!s.ok){e({showPasswordModal:!0,passwordModalRetry:!0,connectionStatus:"reconnecting"});return}const{token:a}=await s.json();Kt.setToken(a),e({showPasswordModal:!1}),t().connect();const{listProjects:o}=Lt.getState(),{fetchConfig:c}=jt.getState();o(),c(),t().connect()}catch{e({showPasswordModal:!0,passwordModalRetry:!0,connectionStatus:"reconnecting"})}},cancelPassword:()=>{Kt.clearToken(),e({showPasswordModal:!1,connectionStatus:"disconnected"})},createSession:async(n,s)=>{if(t().pendingSessionCreate)return null;try{e({pendingSessionCreate:!0});const o=await je("/api/sessions",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({projectId:n,title:s})});if(!o.ok)return e({pendingSessionCreate:!1}),null;const c=await o.json();try{Kt.send("session.load",{sessionId:c.session.id})}catch{}return c.session}catch{return e({pendingSessionCreate:!1}),null}},loadSession:async n=>{if(!Ef.has(n)){Ef.add(n);try{const s=t().currentSession;!s||s.id!==n?(xi(),e({currentSession:null,unreadSessionIds:t().unreadSessionIds.filter(c=>c!==n),subAgentContextStates:{},messages:[],streamingMessageId:null,streamingMessage:null,currentTodos:[],contextState:null,pendingPathConfirmations:[],queuedMessages:[],abortInProgress:!1,error:null,pendingSessionCreate:!1})):e({unreadSessionIds:t().unreadSessionIds.filter(c=>c!==n)});const a=await je(`/api/sessions/${n}`);if(!a.ok)return;const o=await a.json();e({currentSession:o.session,messages:o.messages??[],contextState:o.contextState,queuedMessages:o.queueState??[]}),Kt.send("session.load",{sessionId:n});try{const c=await je(`/api/sessions/${n}/background-processes`);if(c.ok){const l=await c.json();Ko.getState().setProcesses(l.processes??[])}}catch{}}catch{}finally{Ef.delete(n)}}},listSessions:async(n,s=20)=>{const a=n??"global";if(Ic.has(a))return Ic.get(a);const o=(async()=>{try{const c=new URLSearchParams;c.set("limit",String(s)),n&&c.set("projectId",n);const h=await(await je(`/api/sessions?${c.toString()}`)).json(),f=h.sessions??[];e(p=>({sessions:f.map(m=>{var _,w;const x=p.sessions.find(k=>k.id===m.id);return{...m,title:m.title??(x==null?void 0:x.title),mode:((_=p.currentSession)==null?void 0:_.id)===m.id?p.currentSession.mode:(x==null?void 0:x.mode)??m.mode,phase:((w=p.currentSession)==null?void 0:w.id)===m.id?p.currentSession.phase:(x==null?void 0:x.phase)??m.phase,isRunning:m.isRunning&&(x==null?void 0:x.isRunning)!==!1,messageCount:m.messageCount,recentUserPrompts:m.recentUserPrompts}}),sessionsHasMore:n?h.hasMore??!1:!0}))}catch{}finally{Ic.delete(a)}})();return Ic.set(a,o),o},loadMoreSessions:async n=>{const s=t();if(!(s.sessionsPaginationLoading||!s.sessionsHasMore)){e({sessionsPaginationLoading:!0});try{const a=new URLSearchParams;a.set("limit","20"),a.set("offset",String(s.sessions.length)),a.set("projectId",n);const c=await(await je(`/api/sessions?${a.toString()}`)).json(),l=c.sessions??[];e(h=>({sessions:[...h.sessions,...l.map(f=>{const p=h.sessions.find(m=>m.id===f.id);return(p==null?void 0:p.isRunning)===!1?{...f,isRunning:!1}:f})],sessionsHasMore:c.hasMore??!1,sessionsPaginationLoading:!1}))}catch{e({sessionsPaginationLoading:!1})}}},deleteSession:async n=>{var s;try{return(await je(`/api/sessions/${n}`,{method:"DELETE"})).ok?(await t().listSessions(),((s=t().currentSession)==null?void 0:s.id)===n&&t().clearSession(),!0):!1}catch{return!1}},renameSession:async(n,s)=>{var a;try{const o=await je(`/api/sessions/${n}/title`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({title:s})});if(!o.ok)return!1;if(await t().listSessions(),((a=t().currentSession)==null?void 0:a.id)===n){const l=await o.json();l.session&&e({currentSession:l.session})}return!0}catch{return!1}},deleteAllSessions:async n=>{try{return(await je(`/api/projects/${n}/sessions`,{method:"DELETE"})).ok?(await t().listSessions(),!0):!1}catch{return!1}},clearSession:()=>{xi(),e(n=>({currentSession:null,messages:[],streamingMessageId:null,streamingMessage:null,currentTodos:[],contextState:null,pendingSessionCreate:!1,unreadSessionIds:n.currentSession?n.unreadSessionIds.filter(s=>s!==n.currentSession.id):n.unreadSessionIds}))},sendMessage:async(n,s,a)=>{var c;const o=(c=t().currentSession)==null?void 0:c.id;if(o){e({streamingMessageId:null});try{const h=await(await je(`/api/sessions/${o}/message`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:n,attachments:s,messageKind:a==null?void 0:a.messageKind})})).json();h.queueState&&e({queuedMessages:h.queueState})}catch(l){console.error("Error sending message:",l)}}},stopGeneration:async()=>{var s;const n=(s=t().currentSession)==null?void 0:s.id;if(n&&!t().abortInProgress){xi(),e({abortInProgress:!0});try{await je(`/api/sessions/${n}/stop`,{method:"POST"})}catch(a){console.error("Error stopping generation:",a)}}},continueGeneration:async()=>{var s;const n=(s=t().currentSession)==null?void 0:s.id;if(n){e({streamingMessageId:null});try{await je(`/api/sessions/${n}/continue`,{method:"POST"})}catch(a){console.error("Error continuing generation:",a)}}},launchRunner:(n,s,a)=>{e({streamingMessageId:null});const o={};n!=null&&n.trim()&&(o.content=n),s&&s.length>0&&(o.attachments=s),a&&(o.workflowId=a),Kt.send("runner.launch",o)},switchMode:async n=>{var a;const s=(a=t().currentSession)==null?void 0:a.id;if(s)try{const o=await je(`/api/sessions/${s}/mode`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({mode:n})});if(!o.ok){console.error("Failed to switch mode:",await o.json());return}const c=await o.json();c.session&&e({currentSession:c.session})}catch(o){console.error("Error switching mode:",o)}},switchDangerLevel:async n=>{var a;const s=(a=t().currentSession)==null?void 0:a.id;if(s)try{const o=await je(`/api/sessions/${s}/danger-level`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({dangerLevel:n})});if(!o.ok){console.error("Failed to switch danger level:",await o.json());return}const c=await o.json();c.session&&e({currentSession:c.session})}catch(o){console.error("Error switching danger level:",o)}},acceptAndBuild:(n,s,a)=>{var l;e({streamingMessageId:null});const o={};n&&(o.workflowId=n),s!=null&&s.trim()&&(o.content=s),a&&a.length>0&&(o.attachments=a);const c=(l=t().currentSession)==null?void 0:l.id;c&&je(`/api/sessions/${c}/mode`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({mode:"builder"})}).then(()=>{Kt.send("runner.launch",o)})},editCriteria:async n=>{var a;const s=(a=t().currentSession)==null?void 0:a.id;if(s)try{const o=await je(`/api/sessions/${s}/criteria`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({criteria:n})});o.ok||console.error("Failed to update criteria:",await o.json())}catch(o){console.error("Error updating criteria:",o)}},compactContext:()=>{Kt.send("context.compact",{})},setSessionProvider:async(n,s)=>{var a,o;try{const c=(a=t().currentSession)==null?void 0:a.id;if(!c)return null;const l=await je(`/api/sessions/${c}/provider`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({providerId:n,...s?{model:s}:{}})});if(!l.ok)return null;const h=await l.json();if(e({currentSession:h.session,messages:h.messages??[],contextState:h.contextState}),(o=h.session)!=null&&o.providerId){const f=jt.getState();f.providers.find(m=>m.id===h.session.providerId)&&f.syncFromSession(h.session.providerId,h.session.providerModel??"")}return h.session}catch{return null}},updateContextState:n=>{e({contextState:n})},updateSubAgentContextState:(n,s)=>{e(a=>({subAgentContextStates:{...a.subAgentContextStates,[n]:s}}))},clearSubAgentContextState:n=>{e(s=>{const a={...s.subAgentContextStates};return delete a[n],{subAgentContextStates:a}})},confirmPath:async(n,s,a=!1)=>{var c;const o=(c=t().currentSession)==null?void 0:c.id;if(o)try{await je(`/api/sessions/${o}/confirm-path`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({callId:n,approved:s,alwaysAllow:a})})}catch(l){console.error("Error confirming path:",l)}},answerQuestion:async(n,s)=>{var o;const a=(o=t().currentSession)==null?void 0:o.id;if(a){try{await je(`/api/sessions/${a}/answer`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({callId:n,answer:s})})}catch(c){console.error("Error answering question:",c)}e({pendingQuestion:null})}},queueAsap:async(n,s,a)=>{var c;const o=(c=t().currentSession)==null?void 0:c.id;o&&await Tv(o,n,s,a,e)},queueCompletion:async(n,s,a)=>{var c;const o=(c=t().currentSession)==null?void 0:c.id;o&&await Tv(o,n,s,a,e)},cancelQueued:async n=>{var a;const s=(a=t().currentSession)==null?void 0:a.id;if(s)try{const c=await(await je(`/api/sessions/${s}/queue/${n}`,{method:"DELETE"})).json();c.queueState&&e({queuedMessages:c.queueState})}catch(o){console.error("Error canceling queued message:",o)}},clearError:()=>{e({error:null})},resetPendingSessionCreate:()=>{e({pendingSessionCreate:!1})},handleServerMessage:n=>{Ev(n,e,t)}}));function Nu(){return we(e=>{var t;return((t=e.currentSession)==null?void 0:t.isRunning)??!1})}function nj(){return we(e=>e.abortInProgress)}function rj(){const e=we(s=>s.connect),t=we(s=>s.connectionStatus),n=pi(s=>s.load);return M.useEffect(()=>{e()},[e]),M.useEffect(()=>{t==="connected"&&n()},[t,n]),{connectionStatus:t}}const sj="modulepreload",ij=function(e){return"/"+e},Nv={},Y=function(t,n,s){let a=Promise.resolve();if(n&&n.length>0){let c=function(f){return Promise.all(f.map(p=>Promise.resolve(p).then(m=>({status:"fulfilled",value:m}),m=>({status:"rejected",reason:m}))))};document.getElementsByTagName("link");const l=document.querySelector("meta[property=csp-nonce]"),h=(l==null?void 0:l.nonce)||(l==null?void 0:l.getAttribute("nonce"));a=c(n.map(f=>{if(f=ij(f),f in Nv)return;Nv[f]=!0;const p=f.endsWith(".css"),m=p?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${f}"]${m}`))return;const x=document.createElement("link");if(x.rel=p?"stylesheet":sj,p||(x.as="script"),x.crossOrigin="",x.href=f,h&&x.setAttribute("nonce",h),document.head.appendChild(x),p)return new Promise((_,w)=>{x.addEventListener("load",_),x.addEventListener("error",()=>w(new Error(`Unable to preload CSS for ${f}`)))})}))}function o(c){const l=new Event("vite:preloadError",{cancelable:!0});if(l.payload=c,window.dispatchEvent(l),!l.defaultPrevented)throw c}return a.then(c=>{for(const l of c||[])l.status==="rejected"&&o(l.reason);return t().catch(o)})},uS=[{key:"color-bg-primary",category:"background",label:"Primary Background",defaultValue:"13 17 23"},{key:"color-bg-secondary",category:"background",label:"Secondary Background",defaultValue:"22 27 34"},{key:"color-bg-tertiary",category:"background",label:"Tertiary Background",defaultValue:"33 38 45"},{key:"color-primary",category:"surface",label:"Primary Surface",defaultValue:"10 10 10"},{key:"color-secondary",category:"surface",label:"Secondary Surface",defaultValue:"20 20 20"},{key:"color-text-primary",category:"text",label:"Primary Text",defaultValue:"139 148 158"},{key:"color-text-secondary",category:"text",label:"Secondary Text",defaultValue:"139 148 158"},{key:"color-text-muted",category:"text",label:"Muted Text",defaultValue:"72 79 88"},{key:"color-accent-primary",category:"accent",label:"Primary Accent",defaultValue:"88 166 255"},{key:"color-accent-success",category:"accent",label:"Success Accent",defaultValue:"63 185 80"},{key:"color-accent-warning",category:"accent",label:"Warning Accent",defaultValue:"210 153 34"},{key:"color-accent-error",category:"accent",label:"Error Accent",defaultValue:"248 81 73"},{key:"color-border",category:"border",label:"Border",defaultValue:"48 53 60"}],Tr=[{id:"dark",name:"Dark",tokens:{"color-bg-primary":"13 17 23","color-bg-secondary":"22 27 34","color-bg-tertiary":"33 38 45","color-primary":"10 10 10","color-secondary":"20 20 20","color-text-primary":"255 255 255","color-text-secondary":"139 148 158","color-text-muted":"72 79 88","color-accent-primary":"88 166 255","color-accent-success":"63 185 80","color-accent-warning":"210 153 34","color-accent-error":"248 81 73","color-border":"48 53 60"}},{id:"light",name:"Light",tokens:{"color-bg-primary":"255 255 255","color-bg-secondary":"250 251 252","color-bg-tertiary":"243 244 246","color-primary":"245 245 245","color-secondary":"229 229 229","color-text-primary":"15 23 42","color-text-secondary":"30 41 59","color-text-muted":"100 116 139","color-accent-primary":"37 99 235","color-accent-success":"22 163 74","color-accent-warning":"217 119 6","color-accent-error":"220 38 38","color-border":"203 213 225"}},{id:"monokai",name:"Monokai",tokens:{"color-bg-primary":"39 40 34","color-bg-secondary":"30 31 28","color-bg-tertiary":"62 61 50","color-primary":"30 31 28","color-secondary":"45 46 39","color-text-primary":"248 248 242","color-text-secondary":"207 207 194","color-text-muted":"117 113 94","color-accent-primary":"102 217 239","color-accent-success":"166 226 46","color-accent-warning":"230 219 116","color-accent-error":"249 38 114","color-border":"73 72 62"}},{id:"dracula",name:"Dracula",tokens:{"color-bg-primary":"40 42 54","color-bg-secondary":"33 34 44","color-bg-tertiary":"68 71 90","color-primary":"30 31 41","color-secondary":"44 46 61","color-text-primary":"248 248 242","color-text-secondary":"230 230 230","color-text-muted":"98 114 164","color-accent-primary":"189 147 249","color-accent-success":"80 250 123","color-accent-warning":"255 184 108","color-accent-error":"255 85 85","color-border":"68 71 90"}},{id:"nord",name:"Nord",tokens:{"color-bg-primary":"46 52 64","color-bg-secondary":"59 66 82","color-bg-tertiary":"67 76 94","color-primary":"46 52 64","color-secondary":"59 66 82","color-text-primary":"236 239 244","color-text-secondary":"229 233 240","color-text-muted":"76 86 106","color-accent-primary":"129 161 193","color-accent-success":"163 190 140","color-accent-warning":"235 203 139","color-accent-error":"191 97 106","color-border":"76 86 106"}}];function Av(){try{const e=localStorage.getItem("openfox:userPresets");if(e)return JSON.parse(e)}catch{}return[]}const Mt=Gn((e,t)=>({currentPreset:"dark",basePreset:"",customTokens:{},isCustom:!1,isCustomizing:!1,userPresets:Av(),followSystemTheme:!0,applySavedTheme:()=>{const{getSavedTheme:n,applyPreset:s,applyTokens:a}=t(),o=n();if(o)try{const c=JSON.parse(o);c.preset&&c.tokens?(s(c.preset),e({basePreset:c.preset}),a(c.tokens)):c.preset?s(c.preset):c.tokens&&a(c.tokens)}catch{s("dark")}else s("dark")},applyPreset:n=>{Tr.find(a=>a.id===n)&&(e({currentPreset:n,basePreset:"",customTokens:{},isCustom:!1,isCustomizing:!1}),t().applyTheme())},startCustomizing:()=>{var a;const{currentPreset:n}=t(),s=((a=Tr.find(o=>o.id===n))==null?void 0:a.tokens)??{};e({basePreset:n,customTokens:{...s},isCustom:!0,isCustomizing:!0})},setCustomToken:(n,s)=>{e(a=>({customTokens:{...a.customTokens,[n]:s}})),t().applyTheme()},cancelCustomizing:()=>{t().applyPreset(t().basePreset||t().currentPreset)},saveCustomTheme:()=>{const{customTokens:n}=t();t().saveTheme(JSON.stringify({tokens:n})).catch(()=>{}),e({isCustomizing:!1})},applyTokens:n=>{e({customTokens:n,isCustom:!0,isCustomizing:!1}),t().applyTheme()},getActiveTheme:()=>{var c,l;const{basePreset:n,customTokens:s,isCustom:a}=t();if(a&&n)return{...((c=Tr.find(f=>f.id===n))==null?void 0:c.tokens)??{},...s};if(a)return{...uS.reduce((h,f)=>({...h,[f.key]:f.defaultValue}),{}),...s};const o=Tr.find(h=>h.id===t().currentPreset);return(o==null?void 0:o.tokens)??((l=Tr[0])==null?void 0:l.tokens)??{}},applyTheme:()=>{if(typeof document>"u")return;const n=t().getActiveTheme(),s=document.documentElement;Object.entries(n).forEach(([a,o])=>{s.style.setProperty(`--${a}`,o)})},getSavedTheme:()=>{try{const n=localStorage.getItem("openfox:theme");if(!n)return null;if(n[0]!=="{")return JSON.stringify({preset:n});const s=JSON.parse(n);if(s.preset)return JSON.stringify({preset:s.preset});if(s.tokens)return JSON.stringify({tokens:s.tokens})}catch{return null}return null},saveTheme:async n=>{localStorage.setItem("openfox:theme",n);const{useSettingsStore:s}=await Y(async()=>{const{useSettingsStore:a}=await Promise.resolve().then(()=>vf);return{useSettingsStore:a}},void 0);await s.getState().setSetting(Pe.DISPLAY_THEME,n)},clearCustomTheme:()=>{localStorage.removeItem("openfox:theme"),e({isCustom:!1,isCustomizing:!1,basePreset:""})},setFollowSystemTheme:n=>{e({followSystemTheme:n}),Y(async()=>{const{useSettingsStore:s,SETTINGS_KEYS:a}=await Promise.resolve().then(()=>vf);return{useSettingsStore:s,SETTINGS_KEYS:a}},void 0).then(({useSettingsStore:s,SETTINGS_KEYS:a})=>{s.getState().setSetting(a.DISPLAY_FOLLOW_SYSTEM_THEME,String(n))})},initSystemThemeListener:()=>{if(typeof window>"u")return()=>{};const n=window.matchMedia("(prefers-color-scheme: dark)"),s=o=>{const{followSystemTheme:c}=t();c&&(t().applyPreset(o?"dark":"light"),t().saveTheme(JSON.stringify({preset:o?"dark":"light"})))};s(n.matches);const a=o=>s(o.matches);return n.addEventListener("change",a),()=>n.removeEventListener("change",a)},reset:()=>{e({currentPreset:"dark",basePreset:"",customTokens:{},isCustom:!1,isCustomizing:!1,userPresets:[],followSystemTheme:!0})},addUserPreset:n=>{const{basePreset:s,customTokens:a,currentPreset:o}=t(),c={id:"custom-"+Date.now(),name:n,basePreset:s||o,tokens:{...a}},l=[...t().userPresets,c];e({userPresets:l}),t().saveUserPresets()},applyUserPreset:n=>{const s=t().userPresets[n];s&&(e({currentPreset:s.basePreset,basePreset:s.basePreset,customTokens:{...s.tokens},isCustom:!0,isCustomizing:!1}),t().applyTheme(),t().saveTheme(JSON.stringify({preset:s.basePreset,tokens:s.tokens})).catch(()=>{}))},deleteUserPreset:n=>{const s=t().userPresets.filter((a,o)=>o!==n);e({userPresets:s}),t().saveUserPresets()},loadUserPresets:()=>{e({userPresets:Av()})},saveUserPresets:()=>{localStorage.setItem("openfox:userPresets",JSON.stringify(t().userPresets)),Y(async()=>{const{useSettingsStore:n}=await Promise.resolve().then(()=>vf);return{useSettingsStore:n}},void 0).then(({useSettingsStore:n})=>{n.getState().setSetting(Pe.DISPLAY_USER_PRESETS,JSON.stringify(t().userPresets)).catch(()=>{})})}}));function aj({canLoad:e,projectId:t,currentProjectId:n}){const s=Lt(c=>c.loadProject),a=we(c=>c.listSessions),o=we(c=>c.clearSession);M.useEffect(()=>{e&&t&&(n!==t&&s(t),a(t),o())},[e,t,n,s,a,o])}function oj({canLoad:e,projectId:t,sessionId:n,currentProjectId:s,currentSessionId:a}){const o=we(f=>f.loadSession),c=Lt(f=>f.loadProject),l=we(f=>f.listSessions),h=we(f=>f.pendingSessionCreate);M.useEffect(()=>{e&&t&&s!==t&&c(t)},[e,t,s,c]),M.useEffect(()=>{e&&n&&a!==n&&o(n),e&&t&&l(t)},[e,n,a,o,l,h,t])}function lj({className:e="w-5 h-5"}){return u.jsx("svg",{className:e,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 19l-7-7 7-7"})})}function dS({className:e="w-3.5 h-3.5"}){return u.jsx("svg",{className:e,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M14 5l7 7m0 0l-7 7m7-7H3"})})}function cj({className:e="w-5 h-5"}){return u.jsx("svg",{className:e,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15.172 7l-6.586 6.586a2 2 0 102.828 2.828l6.414-6.586a4 4 0 00-5.656-5.656l-6.415 6.585a6 6 0 108.486 8.486L20.5 13"})})}function uj({className:e="w-3 h-3 text-text-muted"}){return u.jsx("svg",{className:e,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10"})})}function dj({className:e="w-4 h-4"}){return u.jsx("svg",{className:e,viewBox:"0 0 16 16",fill:"currentColor",children:u.jsx("path",{d:"M9.5 3.25a2.25 2.25 0 1 1 3 2.122V6A2.5 2.5 0 0 1 10 8.5H6a1 1 0 0 0-1 1v1.128a2.251 2.251 0 1 1-1.5 0V5.372a2.25 2.25 0 1 1 1.5 0v1.836A2.493 2.493 0 0 1 6 7h4a1 1 0 0 0 1-1v-.628A2.25 2.25 0 0 1 9.5 3.25Zm-6 0a.75.75 0 1 0 1.5 0 .75.75 0 0 0-1.5 0Zm8.25-.75a.75.75 0 1 0 0 1.5.75.75 0 0 0 0-1.5ZM4.25 12a.75.75 0 1 0 0 1.5.75.75 0 0 0 0-1.5Z"})})}function Nr({className:e="w-3.5 h-3.5 text-text-muted"}){return u.jsx("svg",{className:e,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})}function Ar({className:e="w-3 h-3 text-text-muted",rotate:t}){return u.jsx("svg",{className:e,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,style:t!==void 0?{transform:`rotate(${t}deg)`}:void 0,children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19 9l-7 7-7-7"})})}function hj({className:e="w-4 h-4"}){return u.jsxs("svg",{className:e,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[u.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",strokeWidth:"2"}),u.jsx("path",{d:"M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1",strokeWidth:"2"})]})}function ep({className:e="w-3.5 h-3.5"}){return u.jsx("svg",{className:e,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"})})}function fj({className:e="w-3 h-3"}){return u.jsx("svg",{className:e,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})})}function tp({className:e="w-4 h-4"}){return u.jsxs("svg",{className:e,fill:"currentColor",viewBox:"0 0 24 24",children:[u.jsx("circle",{cx:"12",cy:"5",r:"2"}),u.jsx("circle",{cx:"12",cy:"12",r:"2"}),u.jsx("circle",{cx:"12",cy:"19",r:"2"})]})}function el({className:e="w-3.5 h-3.5"}){return u.jsx("svg",{className:e,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"})})}function np({className:e="w-5 h-5 text-accent-primary"}){return u.jsx("svg",{className:e,fill:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{d:"M10 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2h-8l-2-2z"})})}function mj({className:e="w-4 h-4"}){return u.jsx("svg",{className:e,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 9V4.5M9 9H4.5M9 9L3.75 3.75M9 15v4.5M9 15H4.5M9 15l-5.25 5.25M15 9h4.5M15 9V4.5M15 9l5.25-5.25M15 15h4.5M15 15v4.5m0-4.5l5.25 5.25"})})}function pj({className:e="w-4 h-4"}){return u.jsx("svg",{className:e,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5l-5-5m5 5v-4m0 4h-4"})})}function gj({className:e="w-4 h-4"}){return u.jsx("svg",{className:e,viewBox:"0 0 16 16",fill:"currentColor",children:u.jsx("path",{d:"M8 0a8.2 8.2 0 0 1 .701.031C9.444.095 9.99.645 10.16 1.29l.288 1.107c.018.066.079.158.212.224.231.114.454.243.668.386.123.082.233.09.299.071l1.1-.303c.652-.18 1.37.008 1.755.653a8.043 8.043 0 0 1 .683 1.18c.227.568.096 1.26-.378 1.726l-.812.804a.312.312 0 0 0-.081.283c.024.166.04.335.04.507s-.016.341-.04.507a.312.312 0 0 0 .08.283l.813.804c.474.466.605 1.158.378 1.726a8.07 8.07 0 0 1-.683 1.18c-.385.645-1.103.833-1.755.653l-1.1-.303c-.066-.019-.176-.011-.299.071a5.1 5.1 0 0 1-.668.386c-.133.066-.194.158-.211.224l-.29 1.107c-.168.645-.714 1.196-1.458 1.26a8.094 8.094 0 0 1-1.402 0c-.744-.064-1.29-.615-1.458-1.26l-.29-1.107a.426.426 0 0 0-.211-.224 5.11 5.11 0 0 1-.668-.386c-.123-.082-.233-.09-.299-.071l-1.1.303c-.652.18-1.37-.008-1.755-.653a8.044 8.044 0 0 1-.683-1.18c-.227-.568-.096-1.26.378-1.726l.812-.804a.312.312 0 0 0 .081-.283A5.18 5.18 0 0 1 2.3 8c0-.172.016-.341.04-.507a.312.312 0 0 0-.08-.283l-.813-.804C.973 5.94.842 5.248 1.069 4.68c.181-.452.395-.882.683-1.18.385-.645 1.103-.833 1.755-.653l1.1.303c.066.019.176.011.299-.071.214-.143.437-.272.668-.386a.426.426 0 0 0 .211-.224l.29-1.107C6.009.645 6.556.095 7.299.03 7.53.01 7.764 0 8 0Zm0 5.5a2.5 2.5 0 1 0 0 5 2.5 2.5 0 0 0 0-5Z"})})}function xj({className:e="w-3 h-3"}){return u.jsx("svg",{className:e,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})})}function _j({className:e="w-4 h-4"}){return u.jsx("svg",{className:e,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M17 16l4-4m0 0l-4-4m4 4H7m6 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h4a3 3 0 013 3v1"})})}function Lv({className:e="w-4 h-4"}){return u.jsx("svg",{className:e,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 6h16M4 12h16M4 18h16"})})}function hS({className:e="w-[18px] h-[18px]"}){return u.jsxs("svg",{className:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[u.jsx("circle",{cx:"12",cy:"5",r:"1.5",fill:"currentColor",stroke:"none"}),u.jsx("circle",{cx:"12",cy:"12",r:"1.5",fill:"currentColor",stroke:"none"}),u.jsx("circle",{cx:"12",cy:"19",r:"1.5",fill:"currentColor",stroke:"none"})]})}function yj({className:e="w-4 h-4"}){return u.jsxs("svg",{className:e,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[u.jsx("path",{d:"M6.5 3.5H3a1 1 0 0 0-1 1V13a1 1 0 0 0 1 1h8.5a1 1 0 0 0 1-1V9.5"}),u.jsx("path",{d:"M9.5 2h4.5v4.5"}),u.jsx("path",{d:"M14 2L7.5 8.5"})]})}function vj({className:e="w-3 h-3",color:t}){return u.jsx("svg",{className:e,fill:t??"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{d:"M8 5v14l11-7z"})})}function Aa({className:e="w-3 h-3 text-accent-primary"}){return u.jsx("svg",{className:e,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v16m8-8H4"})})}function bj({className:e="w-5 h-5"}){return u.jsx("svg",{className:e,viewBox:"0 0 20 20",fill:"currentColor",children:u.jsx("path",{fillRule:"evenodd",d:"M10 3a1 1 0 011 1v5h5a1 1 0 110 2h-5v5a1 1 0 11-2 0v-5H4a1 1 0 110-2h5V4a1 1 0 011-1z",clipRule:"evenodd"})})}function rp({className:e="w-4 h-4"}){return u.jsx("svg",{className:e,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})})}function Sj({className:e="w-4 h-4"}){return u.jsxs("svg",{className:e,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"}),u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"})]})}function wj({className:e="w-3 h-3 text-blue-400 animate-spin flex-shrink-0"}){return u.jsxs("svg",{"aria-label":"Session running",className:e,viewBox:"0 0 24 24",fill:"none",children:[u.jsx("title",{children:"Running"}),u.jsx("circle",{className:"opacity-30",cx:"12",cy:"12",r:"9",stroke:"currentColor",strokeWidth:"3"}),u.jsx("path",{d:"M21 12a9 9 0 00-9-9",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round"})]})}function Cj({className:e="w-3.5 h-3.5 text-text-muted"}){return u.jsx("svg",{className:e,fill:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{d:"M10.788 3.21c.448-1.077 1.976-1.077 2.424 0l2.082 5.007 5.404.433c1.164.093 1.636 1.545.749 2.305l-4.117 3.527 1.257 5.273c.271 1.136-.964 2.033-1.96 1.425L12 18.354 7.373 21.18c-.996.608-2.231-.29-1.96-1.425l1.257-5.273-4.117-3.527c-.887-.76-.415-2.212.749-2.305l5.404-.433 2.082-5.006z"})})}function kj({className:e="w-3.5 h-3.5 text-text-muted"}){return u.jsx("svg",{className:e,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11.049 2.927c.3-.921 1.603-.921 1.902 0l1.519 4.674a1 1 0 00.95.69h4.915c.969 0 1.371 1.24.588 1.81l-3.976 2.888a1 1 0 00-.363 1.118l1.518 4.674c.3.922-.755 1.688-1.538 1.118l-3.976-2.888a1 1 0 00-1.176 0l-3.976 2.888c-.783.57-1.838-.197-1.538-1.118l1.518-4.674a1 1 0 00-.363-1.118l-3.976-2.888c-.784-.57-.38-1.81.588-1.81h4.914a1 1 0 00.951-.69l1.519-4.674z"})})}function fS({className:e="w-4 h-4"}){return u.jsx("svg",{className:e,viewBox:"0 0 16 16",fill:"currentColor",children:u.jsx("rect",{x:"3",y:"3",width:"10",height:"10",rx:"1"})})}function Ej({className:e="w-3.5 h-3.5 shrink-0",color:t}){return u.jsx("svg",{className:e,fill:"none",stroke:t,viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"})})}function jj({className:e="w-4 h-4"}){return u.jsxs("svg",{className:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[u.jsx("polyline",{points:"4 17 10 11 4 5"}),u.jsx("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]})}function Au({className:e="w-3.5 h-3.5"}){return u.jsx("svg",{className:e,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})})}function sp(){return u.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})})}function Tj({className:e="w-4 h-4"}){return u.jsx("svg",{className:e,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})})}function gm({className:e="w-2.5 h-2.5"}){return u.jsx("svg",{className:e,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})})}function ip({className:e="w-4 h-4"}){return u.jsx("svg",{className:e,viewBox:"0 0 20 20",fill:"currentColor",children:u.jsx("path",{fillRule:"evenodd",d:"M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z",clipRule:"evenodd"})})}function mS({className:e="w-4 h-4"}){return u.jsx("svg",{className:e,viewBox:"0 0 16 16",fill:"currentColor",children:u.jsx("path",{d:"M4.646 4.646a.5.5 0 0 1 .708 0L8 7.293l2.646-2.647a.5.5 0 0 1 .708.708L8.707 8l2.647 2.646a.5.5 0 0 1-.708.708L8 8.707l-2.646 2.647a.5.5 0 0 1-.708-.708L7.293 8 4.646 5.354a.55.55 0 0 1 0-.708z"})})}function Nj({className:e="w-3.5 h-3.5 text-text-muted"}){return u.jsx("svg",{className:e,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"})})}function Aj({className:e="w-3.5 h-3.5 text-text-muted"}){return u.jsx("svg",{className:e,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9.663 17h4.673M12 3v1m6.364 1.636l-.707.707M21 12h-1M4 12H3m3.343-5.657l-.707-.707m2.828 9.9a5 5 0 117.072 0l-.548.547A3.374 3.374 0 0014 18.469V19a2 2 0 11-4 0v-.531c0-.895-.356-1.754-.988-2.386l-.548-.547z"})})}function Dv({className:e="w-3.5 h-3.5 text-text-muted"}){return u.jsx("svg",{className:e,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9.75 17L9 20l-1 1h8l-1-1-.75-3M3 13h18M5 17h14a2 2 0 002-2V5a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"})})}function xm(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}function Rv(e,t){const n=Kt.ws;!n||n.readyState!==WebSocket.OPEN||n.send(JSON.stringify({id:xm(),type:e,payload:t}))}const hr=Gn((e,t)=>({isOpen:!1,sessions:[],workdir:null,setOpen:n=>e({isOpen:n}),toggleOpen:()=>e(n=>({isOpen:!n.isOpen})),setWorkdir:n=>e({workdir:n}),fetchSessions:async n=>{if(!n){e({sessions:[]});return}try{const s=await je(`/api/terminals?projectId=${encodeURIComponent(n)}`);if(s.ok){const a=await s.json();e({sessions:a});const o=Kt.ws;if(o&&o.readyState===WebSocket.OPEN)for(const c of a)o.send(JSON.stringify({id:xm(),type:"terminal.subscribe",payload:{sessionId:c.id}}))}}catch(s){console.error("Failed to fetch terminals:",s)}},createSession:async(n,s)=>{try{const a=await je("/api/terminals",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({workdir:n??t().workdir??void 0,projectId:s})});if(a.ok){const o=await a.json();e(l=>({sessions:[...l.sessions,o]}));const c=Kt.ws;c&&c.readyState===WebSocket.OPEN&&c.send(JSON.stringify({id:xm(),type:"terminal.subscribe",payload:{sessionId:o.id}}))}}catch(a){console.error("Failed to create terminal:",a)}},writeSession:(n,s)=>{Rv("terminal.write",{sessionId:n,data:s})},resizeSession:(n,s,a)=>{Rv("terminal.resize",{sessionId:n,cols:s,rows:a})},killSession:async n=>{try{(await je(`/api/terminals/${n}`,{method:"DELETE"})).ok&&e(a=>({sessions:a.sessions.filter(o=>o.id!==n)}))}catch(s){console.error("Failed to kill terminal:",s)}},handleMessage:n=>{switch(n.type){case"terminal.exit":{const{sessionId:s}=n.payload||{};s&&e(a=>{const o=a.sessions.filter(c=>c.id!==s);return o.length===0&&a.isOpen?{sessions:[],isOpen:!1}:{sessions:o}});break}}}}));Kt.subscribe(e=>{var t;(t=e.type)!=null&&t.startsWith("terminal.")&&hr.getState().handleMessage(e)});const Sa={terminalToggle:{type:"double-press",key:"Control",threshold:300},quickAction:{type:"double-press",key:"Shift",threshold:300},agentSwitching:[{type:"chord",key:"1",modifiers:["ctrl"]},{type:"chord",key:"2",modifiers:["ctrl"]},{type:"chord",key:"3",modifiers:["ctrl"]},{type:"chord",key:"4",modifiers:["ctrl"]}]};function _m(e){if(!e)return structuredClone(Sa);try{const t=JSON.parse(e);return{terminalToggle:t.terminalToggle??structuredClone(Sa.terminalToggle),quickAction:t.quickAction??structuredClone(Sa.quickAction),agentSwitching:t.agentSwitching??structuredClone(Sa.agentSwitching)}}catch{return structuredClone(Sa)}}function Ov(e){return e.code.startsWith("Digit")?e.code.slice(-1):e.code.startsWith("Key")?e.code.slice(3).toLowerCase():e.key}function pS(e){if(e.type==="double-press")return`Double ${e.key==="Control"?"Ctrl":e.key==="Shift"?"Shift":e.key==="Alt"?"Alt":e.key==="Meta"?"Meta":e.key}`;const t=e.modifiers.map(s=>{switch(s){case"ctrl":return"Ctrl";case"meta":return"⌘";case"alt":return"Alt";case"shift":return"Shift"}}),n=e.key.length===1?e.key.toUpperCase():e.key;return[...t,n].join("+")}function Lj(e){return e.type==="double-press"}function gS(e){return e.type==="chord"}function Dj(e,t){return t.length===1&&/^[a-z]$/i.test(t)?e.code===`Key${t.toUpperCase()}`:t.length===1&&/^[0-9]$/.test(t)?e.code===`Digit${t}`:e.key.toLowerCase()===t.toLowerCase()}function xS(e,t){const n=t.modifiers.includes("ctrl"),s=t.modifiers.includes("meta"),a=t.modifiers.includes("alt"),o=t.modifiers.includes("shift");return Dj(e,t.key)&&e.ctrlKey===n&&e.metaKey===s&&e.altKey===a&&e.shiftKey===o}function ap(){const e=$t(t=>t.settings[Pe.KEYBINDINGS]);return _m(e)}function Rj(e,t,n){const s=M.useRef(0),a=M.useRef(t);a.current=t,M.useEffect(()=>{if(!e)return;const o=e.threshold??300,c=l=>{if(l.key!==e.key)return;const h=e.key==="Control",f=e.key==="Shift",p=e.key==="Alt",m=e.key==="Meta";if(!h&&l.ctrlKey||!f&&l.shiftKey||!p&&l.altKey||!m&&l.metaKey)return;const x=Date.now();x-s.current<o?(l.preventDefault(),l.stopPropagation(),a.current(),s.current=0):s.current=x};return window.addEventListener("keydown",c,n!=null&&n.capture?!0:void 0),()=>window.removeEventListener("keydown",c,n!=null&&n.capture?!0:void 0)},[e,n==null?void 0:n.capture])}function Oj(e,t){const n=M.useRef(t);n.current=t,M.useEffect(()=>{if(!e)return;const s=a=>{xS(a,e)&&(a.preventDefault(),n.current())};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[e])}function _S(e,t,n){Rj(e&&Lj(e)?e:void 0,t,n),Oj(e&&gS(e)?e:void 0,t)}function Mj(e,t,n){const s=M.useRef(n);s.current=n,M.useEffect(()=>{const a=o=>{for(let c=0;c<e.length;c++){const l=e[c];if(!l)continue;const h=t[c];if(h&&gS(l)&&xS(o,l)){o.preventDefault(),s.current(h.id);return}}};return window.addEventListener("keydown",a),()=>window.removeEventListener("keydown",a)},[e,t])}var Ma=K0();const Lu=M.forwardRef(({icon:e,iconSize:t="w-3.5 h-3.5",className:n="",...s},a)=>u.jsx("button",{ref:a,type:"button",className:`p-1 rounded text-text-muted hover:text-text-primary hover:bg-bg-primary transition-colors ${n}`,...s,children:u.jsx("svg",{className:t,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:u.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:e})})}));Lu.displayName="IconButton";const Ij="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z",zs=M.forwardRef((e,t)=>u.jsx(Lu,{ref:t,icon:Ij,title:"Edit",...e}));zs.displayName="EditButton";const Pj="M6 18L18 6M6 6l12 12",op=M.forwardRef((e,t)=>u.jsx(Lu,{ref:t,icon:Pj,...e}));op.displayName="CloseButton";const Bj={sm:"max-w-sm",md:"max-w-md",lg:"max-w-2xl",xl:"max-w-4xl",full:"max-w-[95vw] h-[90vh] flex-1"};function Ct({label:e,title:t,size:n="md",minHeight:s,children:a,footer:o,className:c,onClose:l,isOpen:h,closeOnBackdropClick:f=!0,closeOnEscape:p=!0,showCloseButton:m=!0}){const[x,_]=M.useState(!1),w=h!==void 0,k=w?h:x,v=M.useCallback(()=>{w||_(!0)},[w]),b=M.useCallback(()=>{w||_(!1),l==null||l()},[w,l]);M.useEffect(()=>{if(!k||!p)return;const S=E=>{E.key==="Escape"&&(E.stopPropagation(),b())};return document.addEventListener("keydown",S),()=>document.removeEventListener("keydown",S)},[k,b,p]);const y=e&&(typeof e=="string"?u.jsx("button",{type:"button",onClick:v,className:c,children:e}):u.jsx("span",{onClick:v,className:c,style:{cursor:"pointer"},children:e}));return u.jsxs(u.Fragment,{children:[y,k&&(typeof document<"u"?Ma.createPortal(u.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[u.jsx("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm",onClick:f?b:void 0}),u.jsxs("div",{className:`relative w-full ${Bj[n]} max-h-[90vh] bg-bg-secondary border border-border rounded shadow-xl flex flex-col`,children:[(t||m)&&u.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[t&&u.jsx("h2",{className:"text-lg font-semibold text-text-primary",children:t}),m&&u.jsx(op,{onClick:b,className:"ml-auto","aria-label":"Close"})]}),u.jsx("div",{className:"p-4 overflow-y-auto flex-1 min-h-0",style:s?{minHeight:s}:void 0,children:a}),o&&u.jsx("div",{className:"px-4 py-3 border-t border-border",children:o})]})]}),document.body):null)]})}function zj({value:e,defaultUrl:t,disabled:n,onChange:s}){const a=e??t;return u.jsxs("div",{className:"relative",children:[u.jsx("select",{value:a,disabled:n,onChange:o=>{const c=o.target.value;s(c===t?null:c)},className:"appearance-none bg-bg-tertiary border border-border rounded px-1.5 pr-5 text-xs focus:outline-none focus:ring-1 focus:ring-accent-primary disabled:opacity-40 cursor-pointer",style:{width:"60px"},children:$2.map(({url:o,label:c})=>u.jsx("option",{value:o,title:c,children:c.split(" ")[0]},o))}),u.jsx(Ar,{className:"absolute right-0.5 top-1/2 -translate-y-1/2 w-3 h-3 pointer-events-none text-text-muted"})]})}const Mv=[{key:"general",label:"General"},{key:"build",label:"Agent"},{key:"sub-agent",label:"Sub-agent"}];function Hj(){const e=pi(h=>h.settings),t=pi(h=>h.update),n=pi(h=>h.updateEvent),s=pi(h=>h.updateAgentOverride),a=pi(h=>h.load);M.useEffect(()=>{a()},[a]);const o=async()=>{await F2()==="granted"&&t({...e,browserNotificationEnabled:!0})},c=(h,f,p,m)=>{h==="general"?n(f,{[p]:m}):s(h,f,{[p]:m})},l=(h,f,p)=>{h==="general"?n(f,{customSoundUrl:p}):s(h,f,{customSoundUrl:p})};return u.jsxs("div",{className:"space-y-6",children:[u.jsxs("div",{className:"space-y-3",children:[u.jsx("h3",{className:"text-sm font-medium text-text-primary",children:"Master Controls"}),u.jsx(Iv,{label:"Sound notifications",description:"Play sounds when events occur",checked:e.soundEnabled,onChange:h=>t({...e,soundEnabled:h})}),u.jsx(Iv,{label:"Browser notifications",description:"Show desktop notifications when the window is not focused",checked:e.browserNotificationEnabled,onChange:h=>{h&&typeof Notification<"u"&&Notification.permission!=="granted"?o():t({...e,browserNotificationEnabled:h})}}),typeof Notification<"u"&&Notification.permission==="denied"&&e.browserNotificationEnabled&&u.jsx("p",{className:"text-xs text-accent-error ml-6",children:"Browser notifications are blocked. Please enable them in your browser settings."})]}),u.jsxs("div",{className:"space-y-3",children:[u.jsx("h3",{className:"text-sm font-medium text-text-primary",children:"Notification Settings"}),u.jsx("div",{className:"border border-border rounded overflow-hidden",children:u.jsxs("table",{className:"w-full text-sm",children:[u.jsx("thead",{className:"sticky top-0 bg-bg-tertiary",children:u.jsxs("tr",{className:"border-b border-border",children:[u.jsx("th",{className:"text-left px-3 py-2 text-text-primary font-medium w-40",children:"Event"}),Mv.map(h=>u.jsx("th",{className:"text-center px-2 py-2 text-text-primary font-medium",children:h.label},h.key))]})}),u.jsx("tbody",{children:H2.map(h=>u.jsxs("tr",{className:"border-b border-border last:border-b-0 hover:bg-bg-secondary/50",children:[u.jsx("td",{className:"px-3 py-2",children:u.jsx("div",{className:"text-text-primary text-xs",children:h.label})}),Mv.map(f=>{const p=lS(e,h.key,f.key==="general"?void 0:f.key),m=aS[h.key];return u.jsx("td",{className:"px-2 py-2 align-top",children:u.jsxs("div",{className:"flex flex-col items-center gap-1",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("label",{className:"flex items-center gap-1 text-text-secondary",children:u.jsx("input",{type:"checkbox",checked:p.soundEnabled,onChange:x=>c(f.key,h.key,"soundEnabled",x.target.checked),disabled:!e.soundEnabled,className:"rounded border-border",title:"Sound"})}),u.jsx("label",{className:"flex items-center gap-1 text-text-secondary",children:u.jsx("input",{type:"checkbox",checked:p.browserNotification,onChange:x=>c(f.key,h.key,"browserNotification",x.target.checked),disabled:!e.browserNotificationEnabled,className:"rounded border-border",title:"Browser"})})]}),p.soundEnabled&&e.soundEnabled&&u.jsx(zj,{value:p.customSoundUrl,defaultUrl:m,disabled:!e.soundEnabled,onChange:x=>l(f.key,h.key,x)})]})},f.key)})]},h.key))})]})})]})]})}function Iv({label:e,description:t,checked:n,onChange:s}){return u.jsxs("label",{className:"flex items-start gap-3 cursor-pointer group",children:[u.jsx("div",{className:"pt-0.5",children:u.jsx("div",{className:`relative w-9 h-5 rounded-full transition-colors ${n?"bg-accent-primary":"bg-bg-tertiary border border-border"}`,onClick:a=>{a.preventDefault(),s(!n)},children:u.jsx("div",{className:`absolute top-0.5 w-4 h-4 rounded-full bg-white shadow transition-transform ${n?"translate-x-4":"translate-x-0.5"}`})})}),u.jsxs("div",{children:[u.jsx("div",{className:"text-sm text-text-primary group-hover:text-accent-primary transition-colors",children:e}),u.jsx("div",{className:"text-xs text-text-muted",children:t})]})]})}const Je=M.forwardRef(({variant:e="secondary",size:t="md",className:n="",children:s,...a},o)=>{const c="rounded font-medium transition-colors disabled:opacity-50 disabled:cursor-not-allowed",l={primary:"bg-accent-primary/25 text-text-primary hover:bg-accent-primary/40",secondary:"bg-bg-tertiary text-text-primary hover:bg-border",danger:"bg-accent-error text-white hover:bg-accent-error/80"},h={sm:"px-1.5 py-1 text-xs",md:"px-3 py-1.5 text-sm",lg:"px-4 py-2 text-base"};return u.jsx("button",{ref:o,className:`${c} ${l[e]} ${h[t]} ${n}`,...a,children:s})});Je.displayName="Button";async function lp(e,t,n){t({loading:!0});try{const a=await(await je(e)).json();t({defaults:a.defaults??[],userItems:a.userItems??[],...n?{projectItems:a.projectItems??[]}:{},loading:!1})}catch{t({loading:!1})}}const wr=Gn((e,t)=>({defaults:[],userItems:[],projectItems:[],loading:!1,fetchSkills:async()=>{await lp("/api/skills",e,!0)},toggleSkill:async n=>{try{const a=await(await je(`/api/skills/${n}/toggle`,{method:"POST"})).json();e(o=>({defaults:o.defaults.map(c=>c.id===n?{...c,enabled:a.enabled}:c),userItems:o.userItems.map(c=>c.id===n?{...c,enabled:a.enabled}:c)}))}catch{}},fetchSkill:async n=>{try{const s=await je(`/api/skills/${n}`);return s.ok?await s.json():null}catch{return null}},fetchDefaultContent:async n=>{try{const s=await je(`/api/skills/defaults/${n}`);return s.ok?await s.json():null}catch{return null}},createSkill:async(n,s)=>{const a=await Us("POST","/api/skills",{...n,destination:s});return a.success&&await t().fetchSkills(),a},updateSkill:async(n,s)=>{const a=await Us("PUT",`/api/skills/${n}`,s);return a.success&&await t().fetchSkills(),a},deleteSkill:async n=>{try{const s=await je(`/api/skills/${n}`,{method:"DELETE"}),a=await s.json();return s.ok?(e(o=>({userItems:o.userItems.filter(c=>c.id!==n)})),{success:!0}):{success:!1,error:a.error??"Failed to delete"}}catch{return{success:!1,error:"Network error"}}},duplicateSkill:async(n,s)=>Tu(`/api/skills/${n}/duplicate`,()=>t().fetchSkills(),s)}));function cp(){const[e,t]=M.useState({id:null,type:null}),n=M.useCallback(o=>t({id:o,type:"delete"}),[]),s=M.useCallback(()=>t({id:null,type:null}),[]),a=M.useCallback((o,c)=>e.id===o&&e.type===c,[e.id,e.type]);return{requestDelete:n,clearConfirm:s,isConfirming:a}}function up({onConfirm:e,onCancel:t}){return u.jsxs("div",{className:"flex items-center gap-1",children:[u.jsx("button",{onClick:e,className:"px-1.5 py-0.5 rounded text-xs hover:opacity-90 transition-colors bg-accent-error/20 text-accent-error hover:bg-accent-error/30",children:"Delete"}),u.jsx("button",{onClick:t,className:"px-1.5 py-0.5 rounded text-text-muted text-xs hover:bg-bg-primary transition-colors",children:"Cancel"})]})}function dp({onClick:e}){return u.jsx("button",{onClick:e,className:"p-1.5 rounded hover:bg-bg-primary text-text-muted hover:text-accent-error transition-colors",title:"Delete",children:u.jsx(Au,{})})}function tl({onClick:e}){return u.jsx("button",{onClick:e,className:"p-1.5 rounded hover:bg-bg-primary text-text-muted hover:text-text-primary transition-colors",title:"Duplicate",children:u.jsx(ep,{})})}function Si({label:e,value:t,onChange:n,placeholder:s,readOnly:a,hint:o,mono:c}){return u.jsxs("div",{children:[u.jsxs("label",{className:"block text-xs text-text-secondary mb-1",children:[e,o&&u.jsx("span",{className:"text-text-muted ml-1",children:o})]}),u.jsx("input",{value:t,onChange:l=>n(l.target.value),readOnly:a,placeholder:s,className:`w-full px-2 py-1.5 bg-bg-tertiary border border-border rounded text-sm focus:outline-none focus:ring-1 focus:ring-accent-primary ${c?"font-mono":""} ${a?"opacity-60":""}`})]})}function $j({onCancel:e,onSave:t,saving:n,saveDisabled:s}){return u.jsxs("div",{className:"flex justify-end gap-2 pt-2 border-t border-border",children:[u.jsx(Je,{variant:"secondary",onClick:e,children:"Cancel"}),u.jsx(Je,{variant:"primary",onClick:t,disabled:n||s,children:n?"Saving...":"Save"})]})}function hp({message:e}){return u.jsx("div",{className:"text-accent-error text-sm px-3 py-2 bg-accent-error/10 rounded",children:e})}function yS({description:e,onNew:t,loading:n,hasItems:s,children:a}){return u.jsxs(u.Fragment,{children:[u.jsxs("div",{className:"flex items-center justify-between mb-4",children:[u.jsx("p",{className:"text-text-secondary text-sm",children:e}),u.jsx("div",{className:"flex items-center gap-2 flex-shrink-0 ml-3",children:u.jsx(Je,{variant:"primary",size:"sm",onClick:t,children:"+ New"})})]}),n&&!s?u.jsx("div",{className:"text-text-muted text-sm",children:"Loading..."}):s?a:u.jsx("div",{className:"text-text-muted text-sm",children:"No items defined."})]})}function vS({label:e="Custom",children:t}){return u.jsxs("div",{children:[u.jsx("h3",{className:"text-xs font-medium text-text-secondary mb-2 uppercase tracking-wide",children:e}),u.jsx("div",{className:"space-y-2",children:t})]})}function bS({description:e,onNew:t,newLabel:n="+ New"}){return u.jsxs("div",{className:"flex items-center justify-between mb-4",children:[u.jsx("p",{className:"text-text-secondary text-sm",children:e}),u.jsx("div",{className:"flex items-center gap-2 flex-shrink-0 ml-3",children:u.jsx(Je,{variant:"primary",size:"sm",onClick:t,children:n})})]})}function SS({isBuiltIn:e,isConfirmingDelete:t,onView:n,onEdit:s,onDuplicate:a,onDelete:o,children:c}){return u.jsxs("div",{className:"flex items-center justify-between p-3 rounded border border-border bg-bg-tertiary",children:[u.jsx("div",{className:"min-w-0 flex-1 mr-3",children:c}),u.jsxs("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[e&&n&&u.jsx("button",{onClick:n,className:"p-1.5 rounded text-text-muted hover:text-text-primary hover:bg-bg-primary transition-colors",title:"View",children:u.jsx(el,{})}),u.jsx(tl,{onClick:a}),!e&&s&&u.jsx(zs,{onClick:s}),!e&&(t?u.jsx(up,{onConfirm:()=>{o==null||o()},onCancel:()=>{}}):u.jsx(dp,{onClick:()=>o==null?void 0:o()}))]})]})}function Uj({id:e,name:t,description:n,isBuiltIn:s,isConfirmingDelete:a,onView:o,onEdit:c,onDuplicate:l,onDelete:h}){return u.jsxs(SS,{isBuiltIn:s,isConfirmingDelete:a,onView:o,onEdit:c,onDuplicate:l,onDelete:h,children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("span",{className:"text-text-primary text-sm font-medium",children:t}),u.jsx("span",{className:"text-text-muted text-xs font-mono",children:e})]}),n&&u.jsx("p",{className:"text-text-muted text-xs truncate",children:n})]})}function wS({loading:e,hasItems:t,loadingLabel:n,emptyLabel:s,children:a}){return e&&!t?u.jsx("div",{className:"text-text-muted text-sm",children:n}):t?u.jsx("div",{className:"space-y-4",children:a}):s?u.jsx("div",{className:"text-text-muted text-sm",children:s}):null}function CS({name:e,id:t,nameLabel:n="Name",idLabel:s="ID",namePlaceholder:a="My Item",idPlaceholder:o="my-item",nameHint:c,readOnlyId:l=!1,readOnlyHint:h="(read-only)",onNameChange:f,onIdChange:p}){return u.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[u.jsx(Si,{label:n,value:e,onChange:f,placeholder:a,hint:c}),u.jsx(Si,{label:s,value:t,onChange:p,readOnly:l,placeholder:o,hint:l?h:void 0,mono:!0})]})}function kS(e={}){const{initialData:t={}}=e,[n,s]=M.useState("list"),[a,o]=M.useState(null),[c,l]=M.useState(""),[h,f]=M.useState(!1),[p,m]=M.useState(t),x=M.useCallback(()=>{m(t),l(""),o(null)},[t]),_=M.useCallback(b=>{s(b),b==="list"&&x()},[x]),w=M.useCallback(b=>{m(y=>typeof b=="function"?b(y):b)},[]),k=M.useCallback((b,y={})=>{o(b),s("edit"),m({...y}),l("")},[]),v=M.useCallback(()=>{o(null),s("edit"),m(t),l("")},[t]);return{view:n,editingId:a,formError:c,saving:h,formData:p,setView:_,setEditingId:o,setFormError:l,setFormData:w,setSaving:f,resetForm:x,startEditing:k,startNew:v}}function fp(){return u.jsxs("div",{className:"flex items-start gap-2 px-3 py-2 bg-accent-warning/10 border border-accent-warning/30 rounded text-xs",children:[u.jsx("span",{children:"⚠️"}),u.jsx("p",{className:"text-text-secondary",children:"Editing this value now will have the side-effect of invalidating KV-cache, causing your next message in current sessions to take a long time to process. Consider doing this between sessions."})]})}function Pv({skill:e,isBuiltIn:t,isConfirmingDelete:n,onView:s,onEdit:a,onDuplicate:o,onDelete:c}){return u.jsx(Uj,{id:e.id,name:e.name,description:e.description,isBuiltIn:t,isConfirmingDelete:n,onView:s,onEdit:a,onDuplicate:o,onDelete:c})}function Fj({isOpen:e}){const t=wr(F=>F.defaults),n=wr(F=>F.userItems),s=wr(F=>F.projectItems),a=wr(F=>F.loading),o=wr(F=>F.fetchSkills),c=wr(F=>F.fetchSkill),l=wr(F=>F.fetchDefaultContent),h=wr(F=>F.createSkill),f=wr(F=>F.updateSkill),p=wr(F=>F.deleteSkill),{view:m,editingId:x,formError:_,saving:w,formData:k,setView:v,setEditingId:b,setFormError:y,setFormData:S,setSaving:E}=kS(),{clearConfirm:N}=cp();M.useEffect(()=>{e&&(o(),v("list"),b(null),N())},[e,o,N]);const T=(F,J,Q,B)=>{S({name:B??F.metadata.name,id:Q??F.metadata.id,description:F.metadata.description??"",version:F.metadata.version??"1.0.0",prompt:F.prompt,isReadOnly:J,destination:"user"})},L=async F=>{if(t.some(Q=>Q.id===F)){const Q=await l(F);if(!Q)return;T(Q,!0),b(F),y(""),v("edit")}else{const Q=await c(F);if(!Q)return;T(Q,!0),b(F),y(""),v("edit")}},A=async F=>{const Q=t.some(O=>O.id===F)?await l(F):await c(F);if(!Q)return;const B=`${F}-copy-${Date.now()}`;T(Q,!1,B,`${Q.metadata.name} (copy)`),b(null),y(""),v("edit")},P=()=>{S({name:"",id:"",description:"",version:"1.0.0",prompt:"",isReadOnly:!1,destination:"user"}),v("edit")},R=async F=>{const J=await c(F);J&&(T(J,!1),b(F),y(""),v("edit"))},$=async F=>{await p(F),N()},D=async()=>{const F=x??k.id;if(!F||!k.name||!k.prompt){y("Name, ID, and prompt are required.");return}E(!0),y("");const J={metadata:{id:F,name:k.name,description:k.description,version:k.version},prompt:k.prompt},Q=x?await f(x,J):await h(J,k.destination);if(E(!1),!Q.success){y(Q.error??"Failed to save skill.");return}v("list")},H=F=>{S(J=>({...J,name:F})),x||S(J=>({...J,id:F.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")}))},K=k.isReadOnly;if(m==="edit")return u.jsxs("div",{className:"flex flex-col h-full",children:[u.jsxs("div",{className:"flex justify-between items-center mb-3",children:[u.jsx("h2",{className:"text-lg font-semibold text-text-primary",children:K?k.name:x?"Edit Skill":"New Skill"}),u.jsx("button",{onClick:()=>v("list"),className:"text-text-muted hover:text-text-primary",children:"Cancel"})]}),_&&u.jsx(hp,{message:_}),u.jsxs("div",{className:"space-y-3 mb-3",children:[u.jsx(CS,{name:k.name,id:k.id,nameLabel:"Name",idLabel:"ID",namePlaceholder:"My Skill",idPlaceholder:"my-skill",readOnlyId:!0,onNameChange:H,onIdChange:()=>{}}),u.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[u.jsx(Si,{label:"Description",value:k.description,onChange:F=>S(J=>({...J,description:F})),placeholder:"What this skill does...",readOnly:K}),u.jsx(Si,{label:"Version",value:k.version,onChange:F=>S(J=>({...J,version:F})),placeholder:"1.0.0",readOnly:K})]})]}),u.jsxs("div",{className:"flex-1 min-h-[120px] border-t border-border pt-3 flex flex-col",children:[u.jsx("label",{className:"block text-xs text-text-secondary mb-1",children:"Prompt"}),u.jsx("textarea",{value:k.prompt,onChange:F=>S(J=>({...J,prompt:F.target.value})),readOnly:K,placeholder:"The system prompt for this skill...",className:"h-80 w-full px-3 py-2 bg-bg-tertiary border border-border rounded text-sm font-mono resize-y focus:outline-none focus:ring-1 focus:ring-accent-primary"})]}),!x&&u.jsxs("div",{className:"flex items-center gap-2 pt-2",children:[u.jsx("label",{className:"text-xs text-text-secondary",children:"Save to:"}),u.jsxs("select",{value:k.destination,onChange:F=>S(J=>({...J,destination:F.target.value})),className:"px-2 py-1 bg-bg-tertiary border border-border rounded text-xs focus:outline-none focus:ring-1 focus:ring-accent-primary",children:[u.jsx("option",{value:"user",children:"Global config"}),u.jsx("option",{value:"project",children:"Project (.openfox/)"})]})]}),u.jsx(fp,{}),u.jsxs("div",{className:"flex justify-end gap-2 pt-3 border-t border-border flex-shrink-0",children:[u.jsx(Je,{variant:"secondary",onClick:()=>v("list"),children:"Cancel"}),K?u.jsx(Je,{variant:"primary",onClick:()=>{S(F=>({...F,name:F.name+" (copy)",id:`${x}-copy-${Date.now()}`,isReadOnly:!1})),b(null)},children:"Duplicate & Customize"}):u.jsx(Je,{variant:"primary",onClick:D,disabled:w||!k.name||!k.id||!k.prompt,children:w?"Saving...":"Save"})]})]});function U({items:F}){return F.map(J=>u.jsx(Pv,{skill:J,isBuiltIn:!1,isConfirmingDelete:!1,onView:()=>L(J.id),onEdit:()=>R(J.id),onDuplicate:()=>A(J.id),onDelete:()=>$(J.id)},J.id))}return u.jsxs("div",{children:[u.jsx(bS,{description:"Skills provide domain-specific knowledge that agents can load on demand.",onNew:P}),u.jsxs(wS,{loading:a,hasItems:t.length>0||n.length>0,loadingLabel:"Loading skills...",emptyLabel:"No skills created yet.",children:[t.length>0&&u.jsxs("div",{children:[u.jsx("h3",{className:"text-xs font-medium text-text-secondary mb-2 uppercase tracking-wide",children:"Built-in"}),u.jsx("div",{className:"space-y-2",children:t.map(F=>u.jsx(Pv,{skill:F,isBuiltIn:!0,isConfirmingDelete:!1,onView:()=>L(F.id),onDuplicate:()=>A(F.id)},F.id))})]}),n.length>0&&u.jsx(vS,{children:u.jsx(U,{items:n})}),s.length>0&&u.jsxs("div",{className:"mt-4",children:[u.jsx("h3",{className:"text-xs font-medium text-text-secondary mb-2 uppercase tracking-wide",children:"Project"}),u.jsx("div",{className:"space-y-2",children:u.jsx(U,{items:s})})]})]})]})}function Du(){const e=$t(a=>a.settings),t=$t(a=>a.loading),n=$t(a=>a.getSetting),s=$t(a=>a.setSetting);return{settings:e,loading:t,getSetting:n,setSetting:s}}function Vj({isOpen:e}){const{settings:t,loading:n,getSetting:s,setSetting:a}=Du(),o=t[Pe.GLOBAL_INSTRUCTIONS]??"",c=n[Pe.GLOBAL_INSTRUCTIONS]??!1,[l,h]=M.useState(o),[f,p]=M.useState(!1),[m,x]=M.useState(!1);M.useEffect(()=>{e&&s(Pe.GLOBAL_INSTRUCTIONS)},[e,s]),M.useEffect(()=>{h(o),p(!1)},[o]);const _=async()=>{x(!0),await a(Pe.GLOBAL_INSTRUCTIONS,l),x(!1),p(!1)},w=()=>{h(o),p(!1)},k=c||m;return u.jsxs("div",{className:"space-y-4",children:[u.jsxs("div",{children:[u.jsx("label",{className:"block text-sm font-medium text-text-primary mb-2",children:"Global Instructions"}),u.jsx("p",{className:"text-sm text-text-muted mb-2",children:"These instructions are injected into every prompt, regardless of project."}),u.jsx("textarea",{value:l,onChange:v=>{h(v.target.value),p(!0)},placeholder:"Enter global instructions that apply to all projects...",className:"w-full min-h-80 px-3 py-2 bg-bg-tertiary border border-border rounded text-sm font-mono resize-y focus:outline-none focus:ring-1 focus:ring-accent-primary",disabled:k})]}),f&&u.jsx(fp,{}),u.jsxs("div",{className:"flex justify-end gap-2",children:[u.jsx(Je,{variant:"secondary",onClick:w,disabled:!f,children:"Discard"}),u.jsx(Je,{variant:"primary",onClick:_,disabled:!f||k,children:m?"Saving...":"Save"})]})]})}function Gj(e){const t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);if(t){const n=parseInt(t[1]??"0",16),s=parseInt(t[2]??"0",16),a=parseInt(t[3]??"0",16);return`${n} ${s} ${a}`}return e}function mi(e){const t=e.split(" ").map(n=>parseInt(n,10));return t.length===3&&t.every(n=>!isNaN(n))?`#${t.map(n=>(n??0).toString(16).padStart(2,"0")).join("")}`:e}function Wj({isOpen:e,isNew:t,basePresetId:n,presetName:s,initialTokens:a,onClose:o,onSave:c}){const[l,h]=M.useState(a),[f,p]=M.useState(s);M.useEffect(()=>{h(a),p(s)},[a,s]);const m=(v,b)=>{const y=b.startsWith("#")?Gj(b):b;h(S=>({...S,[v]:y}))},x=()=>{c(f.trim()||"Untitled",{...l})},_=uS.reduce((v,b)=>{const y=b.category;return v[y]||(v[y]=[]),v[y].push(b),v},{}),w={background:"Backgrounds",surface:"Surfaces",text:"Text",accent:"Accents",border:"Border"},k=Tr.find(v=>v.id===n);return u.jsx(Ct,{isOpen:e,onClose:o,size:"lg",title:t?"New Theme":"Edit Theme",closeOnBackdropClick:!0,closeOnEscape:!0,footer:u.jsxs("div",{className:"flex gap-2 justify-end",children:[u.jsx("button",{type:"button",onClick:o,className:"px-4 py-2 border border-border rounded text-sm text-text-primary hover:bg-bg-tertiary transition-colors",children:"Cancel"}),u.jsx("button",{type:"button",onClick:x,className:"px-4 py-2 bg-accent-primary text-white rounded hover:bg-accent-primary/80 transition-colors text-sm",children:"Save"})]}),children:u.jsxs("div",{className:"space-y-4",children:[u.jsxs("div",{children:[u.jsx("label",{className:"text-xs text-text-muted block mb-1",children:"Name"}),u.jsx("input",{type:"text",value:f,onChange:v=>p(v.target.value),className:"w-full px-3 py-2 bg-bg-tertiary border border-border rounded text-sm text-text-primary focus:outline-none focus:ring-1 focus:ring-accent-primary"})]}),!t&&u.jsxs("div",{className:"text-xs text-text-muted",children:["Based on ",u.jsx("span",{className:"text-text-primary",children:k==null?void 0:k.name})]}),Object.entries(_).map(([v,b])=>u.jsxs("div",{className:"space-y-3",children:[u.jsx("h4",{className:"text-xs font-medium text-text-muted uppercase",children:w[v]??v}),u.jsx("div",{className:"grid grid-cols-2 gap-3",children:b.map(y=>u.jsxs("div",{className:"flex flex-col gap-1",children:[u.jsx("label",{htmlFor:y.key,className:"text-xs text-text-muted",children:y.label}),u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("input",{type:"color",id:y.key,value:mi(l[y.key]??y.defaultValue),onChange:S=>m(y.key,S.target.value),className:"w-8 h-8 rounded cursor-pointer border border-border bg-transparent"}),u.jsx("input",{type:"text",value:l[y.key]??y.defaultValue,onChange:S=>m(y.key,S.target.value),className:"flex-1 px-2 py-1 bg-bg-tertiary border border-border rounded text-xs text-text-primary font-mono focus:outline-none focus:ring-1 focus:ring-accent-primary"})]})]},y.key))})]},v))]})})}function qj(){const[e,t]=M.useState(null),n=Mt(E=>E.currentPreset),s=Mt(E=>E.isCustom),a=Mt(E=>E.basePreset),o=Mt(E=>E.userPresets),c=Mt(E=>E.applyPreset),l=Mt(E=>E.applyUserPreset),h=Mt(E=>E.deleteUserPreset),f=Mt(E=>E.saveTheme),p=Mt(E=>E.followSystemTheme),m=Mt(E=>E.setFollowSystemTheme),x=E=>{c(E),f(JSON.stringify({preset:E})).catch(()=>{})},_=E=>{l(E)},w=E=>{const N=Tr.find(T=>T.id===E);N&&t({type:"new",presetIndex:o.length,basePresetId:E,presetName:N.name+" Copy",tokens:{...N.tokens}})},k=E=>{const N=o[E];if(!N)return;const T=Tr.find(A=>A.id===N.basePreset),L=T?{...T.tokens,...N.tokens}:N.tokens;t({type:"edit",presetIndex:E,basePresetId:N.basePreset,presetName:N.name,tokens:L})},v=(E,N)=>{if(!e)return;const T=[...o];if(e.type==="new"){const L={id:"custom-"+Date.now(),name:E,basePreset:e.basePresetId,tokens:N};T.push(L);const A=T.length-1;Mt.setState({userPresets:T}),Mt.getState().saveUserPresets(),Mt.getState().applyUserPreset(A)}else{const L=T[e.presetIndex];L&&(T[e.presetIndex]={...L,name:E,tokens:N}),Mt.setState({userPresets:T}),Mt.getState().saveUserPresets(),Mt.getState().applyUserPreset(e.presetIndex)}t(null)},b=()=>{t(null)},y=(E,N)=>{E.stopPropagation(),h(N)},S=s?a:n;return u.jsxs("div",{className:"space-y-4",children:[u.jsx("h3",{className:"text-sm font-medium text-text-primary",children:"Theme"}),u.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[u.jsx("button",{type:"button",role:"switch","aria-checked":p,onClick:()=>m(!p),className:`relative w-10 h-5 rounded-full transition-colors ${p?"bg-accent-primary":"bg-bg-tertiary border border-border"}`,children:u.jsx("span",{className:`absolute top-0.5 left-0.5 w-4 h-4 rounded-full bg-white transition-transform ${p?"translate-x-5":"translate-x-0"}`})}),u.jsx("span",{className:"text-sm text-text-secondary",children:"Follow system theme"})]}),u.jsx("div",{className:"grid grid-cols-5 gap-2",children:Tr.map(E=>u.jsxs("div",{className:"relative group",children:[u.jsxs("button",{type:"button",onClick:()=>x(E.id),className:`w-full flex flex-col items-center gap-2 px-3 py-3 rounded-lg border transition-colors ${S===E.id&&!s?"border-accent-primary bg-bg-tertiary text-text-primary":"border-border bg-bg-secondary text-text-muted hover:border-text-muted"}`,children:[u.jsx("div",{className:"w-8 h-8 rounded border flex items-center justify-center",style:{backgroundColor:mi(E.tokens["color-bg-primary"]??"#000"),borderColor:mi(E.tokens["color-border"]??"#000")},children:u.jsx("div",{className:"w-3 h-3 rounded-full",style:{backgroundColor:mi(E.tokens["color-text-primary"]??"#fff")}})}),u.jsx("span",{className:"text-xs",children:E.name})]}),u.jsx("button",{type:"button",onClick:N=>{N.stopPropagation(),w(E.id)},className:"absolute top-1 right-1 w-6 h-6 rounded bg-bg-tertiary border border-border flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity z-10 hover:border-text-muted",title:"Create custom theme based on this",children:u.jsx("span",{className:"text-xs",children:"✎"})})]},E.id))}),o.length>0&&u.jsxs(u.Fragment,{children:[u.jsx("h4",{className:"text-xs font-medium text-text-muted uppercase",children:"My Themes"}),u.jsx("div",{className:"grid grid-cols-5 gap-2",children:o.map((E,N)=>{const T=Tr.find(A=>A.id===E.basePreset),L=T?{...T.tokens,...E.tokens}:E.tokens;return u.jsxs("div",{className:"relative group",children:[u.jsxs("button",{type:"button",onClick:()=>_(N),className:`w-full flex flex-col items-center gap-2 px-3 py-3 rounded-lg border transition-colors ${s&&a===E.basePreset&&S===E.basePreset?"border-accent-primary bg-bg-tertiary text-text-primary":"border-border bg-bg-secondary text-text-muted hover:border-text-muted"}`,children:[u.jsx("div",{className:"w-8 h-8 rounded border flex items-center justify-center",style:{backgroundColor:mi(L["color-bg-primary"]??"#000"),borderColor:mi(L["color-border"]??"#000")},children:u.jsx("div",{className:"w-3 h-3 rounded-full",style:{backgroundColor:mi(L["color-text-primary"]??"#fff")}})}),u.jsx("span",{className:"text-xs truncate w-full text-center",children:E.name})]}),u.jsx("button",{type:"button",onClick:A=>{A.stopPropagation(),k(N)},className:"absolute top-1 right-1 w-6 h-6 rounded bg-bg-tertiary border border-border flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity z-10 hover:border-text-muted",title:"Edit",children:u.jsx("span",{className:"text-xs",children:"✎"})}),u.jsx("button",{type:"button",onClick:A=>y(A,N),className:"absolute -top-1 -left-1 w-5 h-5 rounded-full bg-accent-error text-white flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity z-20",children:u.jsx(ip,{className:"w-3 h-3"})})]},E.id)})})]}),e&&u.jsx(Wj,{isOpen:!0,isNew:e.type==="new",presetIndex:e.presetIndex,basePresetId:e.basePresetId,presetName:e.presetName,initialTokens:e.tokens,onClose:b,onSave:v})]})}function Kj(){return u.jsx(qj,{})}function Yj(){const{settings:e,loading:t,getSetting:n,setSetting:s}=Du(),a=t[Pe.DISPLAY_SHOW_THINKING]??!1,o=[{key:Pe.DISPLAY_SHOW_THINKING,label:"Show thinking blocks",description:"Display AI reasoning content in the feed"},{key:Pe.DISPLAY_SHOW_VERBOSE_TOOL_OUTPUT,label:"Show expanded tool output",description:"Always show full tool call details instead of compact view"},{key:Pe.DISPLAY_SHOW_STATS,label:"Show stats bar",description:"Display model, tokens, and timing information"},{key:Pe.DISPLAY_SHOW_AGENT_DEFINITIONS,label:"Show agent definitions",description:"Display agent definition injections in the feed"},{key:Pe.DISPLAY_SHOW_WORKFLOW_BARS,label:"Show workflow bars",description:"Display workflow start and end markers"},{key:Pe.DISPLAY_SHOW_SYNTAX_HIGHLIGHTING,label:"Show syntax highlighting",description:"Nicer formatting, but very slow - does not affect red/green diff coloring"}],c=Object.fromEntries(o.map(p=>[p.key,e[p.key]??"true"])),[l,h]=M.useState(()=>Object.fromEntries(o.map(p=>[p.key,c[p.key]==="true"])));M.useEffect(()=>{o.forEach(p=>n(p.key))},[n]),M.useEffect(()=>{h(Object.fromEntries(o.map(p=>[p.key,c[p.key]==="true"])))},[JSON.stringify(c)]);const f=async p=>{const m=String(!l[p]);h(x=>({...x,[p]:!x[p]})),await s(p,m)};return a?u.jsx("div",{className:"text-sm text-text-muted",children:"Loading..."}):u.jsxs("div",{className:"space-y-6",children:[u.jsx(Kj,{}),u.jsxs("div",{children:[u.jsx("h3",{className:"text-sm font-medium text-text-primary mb-4",children:"Feed Display"}),u.jsx("div",{className:"space-y-4",children:o.map(({key:p,label:m,description:x})=>u.jsxs("label",{className:"flex items-center justify-between cursor-pointer",children:[u.jsxs("div",{children:[u.jsx("div",{className:"text-sm text-text-primary",children:m}),u.jsx("div",{className:"text-xs text-text-muted",children:x})]}),u.jsx("button",{type:"button",onClick:()=>f(p),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${l[p]?"bg-accent-primary":"bg-bg-tertiary"}`,children:u.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${l[p]?"translate-x-6":"translate-x-1"}`})})]},p))})]})]})}function Xj({label:e,binding:t,isRecording:n,onStartRecording:s,onBindingRecorded:a,onCancelRecording:o}){const c=M.useRef(null),l=M.useRef(0),h=M.useRef("");return M.useEffect(()=>{if(!n)return;const f=new Set(["Control","Shift","Alt","Meta"]);let p=[];const m=_=>{if(_.preventDefault(),_.stopPropagation(),_.key==="Escape"){o();return}if(f.has(_.key)){_.ctrlKey&&!p.includes("ctrl")&&p.push("ctrl"),_.metaKey&&!p.includes("meta")&&p.push("meta"),_.altKey&&!p.includes("alt")&&p.push("alt"),_.shiftKey&&!p.includes("shift")&&p.push("shift");return}if(p.length>0||_.ctrlKey||_.metaKey||_.altKey||_.shiftKey){const v=[...p];_.ctrlKey&&!v.includes("ctrl")&&v.push("ctrl"),_.metaKey&&!v.includes("meta")&&v.push("meta"),_.altKey&&!v.includes("alt")&&v.push("alt"),_.shiftKey&&!v.includes("shift")&&v.push("shift"),a({type:"chord",key:Ov(_),modifiers:v});return}const w=Date.now(),k=Ov(_);if(k===h.current&&w-l.current<400){a({type:"double-press",key:k,threshold:300});return}l.current=w,h.current=k},x=_=>{_.key==="Control"&&(p=p.filter(w=>w!=="ctrl")),_.key==="Shift"&&(p=p.filter(w=>w!=="shift")),_.key==="Alt"&&(p=p.filter(w=>w!=="alt")),_.key==="Meta"&&(p=p.filter(w=>w!=="meta"))};return window.addEventListener("keydown",m,!0),window.addEventListener("keyup",x,!0),()=>{window.removeEventListener("keydown",m,!0),window.removeEventListener("keyup",x,!0)}},[n,a,o]),u.jsxs("div",{ref:c,className:`flex items-center justify-between px-3 py-2 rounded transition-colors ${n?"bg-accent-primary/10 ring-1 ring-accent-primary":"hover:bg-bg-tertiary"}`,children:[u.jsx("span",{className:"text-sm text-text-primary",children:e}),u.jsx("div",{className:"flex items-center gap-2",children:n?u.jsx("span",{className:"text-xs text-accent-primary font-medium animate-pulse",children:"Press shortcut..."}):u.jsx("button",{type:"button",onClick:s,className:"px-2 py-0.5 text-xs font-mono bg-bg-tertiary text-text-secondary rounded border border-border hover:border-accent-primary hover:text-accent-primary transition-colors",children:pS(t)})})]})}function Qj(){const{settings:e,loading:t,getSetting:n,setSetting:s}=Du(),a=e[Pe.KEYBINDINGS],o=t[Pe.KEYBINDINGS]??!1,c=_m(a),[l,h]=M.useState(null);M.useEffect(()=>{n(Pe.KEYBINDINGS)},[n]);const f=[{id:"terminalToggle",label:"Toggle Terminal",binding:c.terminalToggle},{id:"quickAction",label:"Quick Action",binding:c.quickAction},...c.agentSwitching.map((_,w)=>({id:`agentSwitching.${w}`,label:`Switch to Agent ${w+1}`,binding:_}))],p=_=>{h(_)},m=M.useCallback(_=>{if(!l)return;const w=_m(a),k=structuredClone(w);if(l.startsWith("agentSwitching.")){const v=parseInt(l.split(".")[1],10);k.agentSwitching[v]=_}else l==="terminalToggle"?k.terminalToggle=_:l==="quickAction"&&(k.quickAction=_);h(null),s(Pe.KEYBINDINGS,JSON.stringify(k))},[l,a,s]),x=()=>{s(Pe.KEYBINDINGS,JSON.stringify(Sa))};return u.jsxs("div",{className:"space-y-4",children:[u.jsxs("div",{className:"flex items-center justify-between mb-2",children:[u.jsx("h3",{className:"text-sm font-medium text-text-primary",children:"Keyboard Shortcuts"}),u.jsx("button",{type:"button",onClick:x,disabled:o,className:"text-xs text-text-muted hover:text-text-primary px-2 py-1 rounded hover:bg-bg-tertiary transition-colors disabled:opacity-30",children:"Reset to defaults"})]}),o?u.jsx("div",{className:"text-sm text-text-muted",children:"Loading..."}):u.jsx("div",{className:"space-y-1",children:f.map(_=>u.jsx(Xj,{label:_.label,binding:_.binding,isRecording:l===_.id,onStartRecording:()=>p(_.id),onBindingRecorded:m,onCancelRecording:()=>h(null)},_.id))})]})}function Bv({enabled:e,onClick:t}){return u.jsx("button",{type:"button",onClick:t,className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${e?"bg-accent-primary":"bg-bg-tertiary"}`,children:u.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${e?"translate-x-6":"translate-x-1"}`})})}function Jj({onClose:e}){const[,t]=gr(),{settings:n,loading:s,getSetting:a,setSetting:o}=Du(),c=n[Pe.LLM_DISABLE_XML_PROTECTION]==="true",l=n[Pe.DISPLAY_SHOW_OPEN_IN_EDITOR]==="true",h=s[Pe.LLM_DISABLE_XML_PROTECTION]??!1;M.useEffect(()=>{a(Pe.LLM_DISABLE_XML_PROTECTION),a(Pe.DISPLAY_SHOW_OPEN_IN_EDITOR)},[a]);const f=async()=>{const x=String(!c);await o(Pe.LLM_DISABLE_XML_PROTECTION,x)},p=async()=>{const x=String(!l);await o(Pe.DISPLAY_SHOW_OPEN_IN_EDITOR,x)};function m(){e(),t("/onboarding")}return h?u.jsx("div",{className:"text-sm text-text-muted",children:"Loading..."}):u.jsxs("div",{className:"space-y-6",children:[u.jsx("div",{children:u.jsxs("label",{className:"flex items-center justify-between cursor-pointer",children:[u.jsxs("div",{children:[u.jsx("div",{className:"text-sm font-medium text-text-primary",children:"Disable XML Tool Call Protection"}),u.jsx("div",{className:"text-xs text-text-muted mt-0.5",children:"Allow the model to output XML tool call format instead of JSON function calls. Some third-party providers may require this."})]}),u.jsx(Bv,{enabled:c,onClick:f})]})}),u.jsx("hr",{className:"border-border"}),u.jsxs("div",{children:[u.jsx("h3",{className:"text-sm font-medium text-text-primary mb-3",children:"Integrations"}),u.jsxs("label",{className:"flex items-center justify-between cursor-pointer",children:[u.jsxs("div",{children:[u.jsx("div",{className:"text-sm text-text-primary",children:'Show "Open in VSCode" links'}),u.jsx("div",{className:"text-xs text-text-muted mt-0.5",children:"Display a link on file reads to open the file directly in VS Code."})]}),u.jsx(Bv,{enabled:l,onClick:p})]})]}),u.jsx("hr",{className:"border-border"}),u.jsxs("div",{children:[u.jsx("h3",{className:"text-sm font-medium text-text-primary mb-1",children:"Onboarding"}),u.jsx("p",{className:"text-sm text-text-muted mb-4",children:"Reset your OpenFox setup and go through the initial configuration again."}),u.jsx(Je,{variant:"secondary",onClick:m,children:"Launch Onboarding"})]})]})}function pa({label:e,active:t,onClick:n}){return u.jsx("button",{onClick:n,className:`px-4 py-2 text-sm font-medium border-b-2 transition-colors ${t?"border-accent-primary text-accent-primary":"border-transparent text-text-muted hover:text-text-secondary hover:border-border"}`,children:e})}function Zj({isOpen:e,onClose:t}){const[n,s]=M.useState("instructions");return u.jsx(Ct,{isOpen:e,onClose:t,title:"Settings",size:"xl",minHeight:"500px",children:u.jsxs("div",{className:"flex flex-col h-full",children:[u.jsxs("div",{className:"flex border-b border-border mb-4 -mt-1",children:[u.jsx(pa,{label:"Instructions",active:n==="instructions",onClick:()=>s("instructions")}),u.jsx(pa,{label:"Skills",active:n==="skills",onClick:()=>s("skills")}),u.jsx(pa,{label:"Notifications",active:n==="notifications",onClick:()=>s("notifications")}),u.jsx(pa,{label:"Display",active:n==="display",onClick:()=>s("display")}),u.jsx(pa,{label:"Shortcuts",active:n==="keybindings",onClick:()=>s("keybindings")}),u.jsx(pa,{label:"Advanced",active:n==="advanced",onClick:()=>s("advanced")})]}),n==="instructions"&&u.jsx(Vj,{isOpen:e}),n==="skills"&&u.jsx(Fj,{isOpen:e}),n==="notifications"&&u.jsx("div",{className:"max-h-[60vh] overflow-y-auto",children:u.jsx(Hj,{})}),n==="display"&&u.jsx(Yj,{}),n==="keybindings"&&u.jsx(Qj,{}),n==="advanced"&&u.jsx(Jj,{onClose:t})]})})}var jf={exports:{}},zv;function eT(){return zv||(zv=1,(function(e,t){(function(n,s){e.exports=s()})(globalThis,(()=>(()=>{var n={4567:function(c,l,h){var f=this&&this.__decorate||function(y,S,E,N){var T,L=arguments.length,A=L<3?S:N===null?N=Object.getOwnPropertyDescriptor(S,E):N;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")A=Reflect.decorate(y,S,E,N);else for(var P=y.length-1;P>=0;P--)(T=y[P])&&(A=(L<3?T(A):L>3?T(S,E,A):T(S,E))||A);return L>3&&A&&Object.defineProperty(S,E,A),A},p=this&&this.__param||function(y,S){return function(E,N){S(E,N,y)}};Object.defineProperty(l,"__esModule",{value:!0}),l.AccessibilityManager=void 0;const m=h(9042),x=h(9924),_=h(844),w=h(4725),k=h(2585),v=h(3656);let b=l.AccessibilityManager=class extends _.Disposable{constructor(y,S,E,N){super(),this._terminal=y,this._coreBrowserService=E,this._renderService=N,this._rowColumns=new WeakMap,this._liveRegionLineCount=0,this._charsToConsume=[],this._charsToAnnounce="",this._accessibilityContainer=this._coreBrowserService.mainDocument.createElement("div"),this._accessibilityContainer.classList.add("xterm-accessibility"),this._rowContainer=this._coreBrowserService.mainDocument.createElement("div"),this._rowContainer.setAttribute("role","list"),this._rowContainer.classList.add("xterm-accessibility-tree"),this._rowElements=[];for(let T=0;T<this._terminal.rows;T++)this._rowElements[T]=this._createAccessibilityTreeNode(),this._rowContainer.appendChild(this._rowElements[T]);if(this._topBoundaryFocusListener=T=>this._handleBoundaryFocus(T,0),this._bottomBoundaryFocusListener=T=>this._handleBoundaryFocus(T,1),this._rowElements[0].addEventListener("focus",this._topBoundaryFocusListener),this._rowElements[this._rowElements.length-1].addEventListener("focus",this._bottomBoundaryFocusListener),this._refreshRowsDimensions(),this._accessibilityContainer.appendChild(this._rowContainer),this._liveRegion=this._coreBrowserService.mainDocument.createElement("div"),this._liveRegion.classList.add("live-region"),this._liveRegion.setAttribute("aria-live","assertive"),this._accessibilityContainer.appendChild(this._liveRegion),this._liveRegionDebouncer=this.register(new x.TimeBasedDebouncer(this._renderRows.bind(this))),!this._terminal.element)throw new Error("Cannot enable accessibility before Terminal.open");this._terminal.element.insertAdjacentElement("afterbegin",this._accessibilityContainer),this.register(this._terminal.onResize((T=>this._handleResize(T.rows)))),this.register(this._terminal.onRender((T=>this._refreshRows(T.start,T.end)))),this.register(this._terminal.onScroll((()=>this._refreshRows()))),this.register(this._terminal.onA11yChar((T=>this._handleChar(T)))),this.register(this._terminal.onLineFeed((()=>this._handleChar(`
59
59
  `)))),this.register(this._terminal.onA11yTab((T=>this._handleTab(T)))),this.register(this._terminal.onKey((T=>this._handleKey(T.key)))),this.register(this._terminal.onBlur((()=>this._clearLiveRegion()))),this.register(this._renderService.onDimensionsChange((()=>this._refreshRowsDimensions()))),this.register((0,v.addDisposableDomListener)(document,"selectionchange",(()=>this._handleSelectionChange()))),this.register(this._coreBrowserService.onDprChange((()=>this._refreshRowsDimensions()))),this._refreshRows(),this.register((0,_.toDisposable)((()=>{this._accessibilityContainer.remove(),this._rowElements.length=0})))}_handleTab(y){for(let S=0;S<y;S++)this._handleChar(" ")}_handleChar(y){this._liveRegionLineCount<21&&(this._charsToConsume.length>0?this._charsToConsume.shift()!==y&&(this._charsToAnnounce+=y):this._charsToAnnounce+=y,y===`
60
60
  `&&(this._liveRegionLineCount++,this._liveRegionLineCount===21&&(this._liveRegion.textContent+=m.tooMuchOutput)))}_clearLiveRegion(){this._liveRegion.textContent="",this._liveRegionLineCount=0}_handleKey(y){this._clearLiveRegion(),new RegExp("\\p{Control}","u").test(y)||this._charsToConsume.push(y)}_refreshRows(y,S){this._liveRegionDebouncer.refresh(y,S,this._terminal.rows)}_renderRows(y,S){const E=this._terminal.buffer,N=E.lines.length.toString();for(let T=y;T<=S;T++){const L=E.lines.get(E.ydisp+T),A=[],P=(L==null?void 0:L.translateToString(!0,void 0,void 0,A))||"",R=(E.ydisp+T+1).toString(),$=this._rowElements[T];$&&(P.length===0?($.innerText=" ",this._rowColumns.set($,[0,1])):($.textContent=P,this._rowColumns.set($,A)),$.setAttribute("aria-posinset",R),$.setAttribute("aria-setsize",N))}this._announceCharacters()}_announceCharacters(){this._charsToAnnounce.length!==0&&(this._liveRegion.textContent+=this._charsToAnnounce,this._charsToAnnounce="")}_handleBoundaryFocus(y,S){const E=y.target,N=this._rowElements[S===0?1:this._rowElements.length-2];if(E.getAttribute("aria-posinset")===(S===0?"1":`${this._terminal.buffer.lines.length}`)||y.relatedTarget!==N)return;let T,L;if(S===0?(T=E,L=this._rowElements.pop(),this._rowContainer.removeChild(L)):(T=this._rowElements.shift(),L=E,this._rowContainer.removeChild(T)),T.removeEventListener("focus",this._topBoundaryFocusListener),L.removeEventListener("focus",this._bottomBoundaryFocusListener),S===0){const A=this._createAccessibilityTreeNode();this._rowElements.unshift(A),this._rowContainer.insertAdjacentElement("afterbegin",A)}else{const A=this._createAccessibilityTreeNode();this._rowElements.push(A),this._rowContainer.appendChild(A)}this._rowElements[0].addEventListener("focus",this._topBoundaryFocusListener),this._rowElements[this._rowElements.length-1].addEventListener("focus",this._bottomBoundaryFocusListener),this._terminal.scrollLines(S===0?-1:1),this._rowElements[S===0?1:this._rowElements.length-2].focus(),y.preventDefault(),y.stopImmediatePropagation()}_handleSelectionChange(){var P;if(this._rowElements.length===0)return;const y=document.getSelection();if(!y)return;if(y.isCollapsed)return void(this._rowContainer.contains(y.anchorNode)&&this._terminal.clearSelection());if(!y.anchorNode||!y.focusNode)return void console.error("anchorNode and/or focusNode are null");let S={node:y.anchorNode,offset:y.anchorOffset},E={node:y.focusNode,offset:y.focusOffset};if((S.node.compareDocumentPosition(E.node)&Node.DOCUMENT_POSITION_PRECEDING||S.node===E.node&&S.offset>E.offset)&&([S,E]=[E,S]),S.node.compareDocumentPosition(this._rowElements[0])&(Node.DOCUMENT_POSITION_CONTAINED_BY|Node.DOCUMENT_POSITION_FOLLOWING)&&(S={node:this._rowElements[0].childNodes[0],offset:0}),!this._rowContainer.contains(S.node))return;const N=this._rowElements.slice(-1)[0];if(E.node.compareDocumentPosition(N)&(Node.DOCUMENT_POSITION_CONTAINED_BY|Node.DOCUMENT_POSITION_PRECEDING)&&(E={node:N,offset:((P=N.textContent)==null?void 0:P.length)??0}),!this._rowContainer.contains(E.node))return;const T=({node:R,offset:$})=>{const D=R instanceof Text?R.parentNode:R;let H=parseInt(D==null?void 0:D.getAttribute("aria-posinset"),10)-1;if(isNaN(H))return console.warn("row is invalid. Race condition?"),null;const K=this._rowColumns.get(D);if(!K)return console.warn("columns is null. Race condition?"),null;let U=$<K.length?K[$]:K.slice(-1)[0]+1;return U>=this._terminal.cols&&(++H,U=0),{row:H,column:U}},L=T(S),A=T(E);if(L&&A){if(L.row>A.row||L.row===A.row&&L.column>=A.column)throw new Error("invalid range");this._terminal.select(L.column,L.row,(A.row-L.row)*this._terminal.cols-L.column+A.column)}}_handleResize(y){this._rowElements[this._rowElements.length-1].removeEventListener("focus",this._bottomBoundaryFocusListener);for(let S=this._rowContainer.children.length;S<this._terminal.rows;S++)this._rowElements[S]=this._createAccessibilityTreeNode(),this._rowContainer.appendChild(this._rowElements[S]);for(;this._rowElements.length>y;)this._rowContainer.removeChild(this._rowElements.pop());this._rowElements[this._rowElements.length-1].addEventListener("focus",this._bottomBoundaryFocusListener),this._refreshRowsDimensions()}_createAccessibilityTreeNode(){const y=this._coreBrowserService.mainDocument.createElement("div");return y.setAttribute("role","listitem"),y.tabIndex=-1,this._refreshRowDimensions(y),y}_refreshRowsDimensions(){if(this._renderService.dimensions.css.cell.height){this._accessibilityContainer.style.width=`${this._renderService.dimensions.css.canvas.width}px`,this._rowElements.length!==this._terminal.rows&&this._handleResize(this._terminal.rows);for(let y=0;y<this._terminal.rows;y++)this._refreshRowDimensions(this._rowElements[y])}}_refreshRowDimensions(y){y.style.height=`${this._renderService.dimensions.css.cell.height}px`}};l.AccessibilityManager=b=f([p(1,k.IInstantiationService),p(2,w.ICoreBrowserService),p(3,w.IRenderService)],b)},3614:(c,l)=>{function h(x){return x.replace(/\r?\n/g,"\r")}function f(x,_){return _?"\x1B[200~"+x+"\x1B[201~":x}function p(x,_,w,k){x=f(x=h(x),w.decPrivateModes.bracketedPasteMode&&k.rawOptions.ignoreBracketedPasteMode!==!0),w.triggerDataEvent(x,!0),_.value=""}function m(x,_,w){const k=w.getBoundingClientRect(),v=x.clientX-k.left-10,b=x.clientY-k.top-10;_.style.width="20px",_.style.height="20px",_.style.left=`${v}px`,_.style.top=`${b}px`,_.style.zIndex="1000",_.focus()}Object.defineProperty(l,"__esModule",{value:!0}),l.rightClickHandler=l.moveTextAreaUnderMouseCursor=l.paste=l.handlePasteEvent=l.copyHandler=l.bracketTextForPaste=l.prepareTextForTerminal=void 0,l.prepareTextForTerminal=h,l.bracketTextForPaste=f,l.copyHandler=function(x,_){x.clipboardData&&x.clipboardData.setData("text/plain",_.selectionText),x.preventDefault()},l.handlePasteEvent=function(x,_,w,k){x.stopPropagation(),x.clipboardData&&p(x.clipboardData.getData("text/plain"),_,w,k)},l.paste=p,l.moveTextAreaUnderMouseCursor=m,l.rightClickHandler=function(x,_,w,k,v){m(x,_,w),v&&k.rightClickSelect(x),_.value=k.selectionText,_.select()}},7239:(c,l,h)=>{Object.defineProperty(l,"__esModule",{value:!0}),l.ColorContrastCache=void 0;const f=h(1505);l.ColorContrastCache=class{constructor(){this._color=new f.TwoKeyMap,this._css=new f.TwoKeyMap}setCss(p,m,x){this._css.set(p,m,x)}getCss(p,m){return this._css.get(p,m)}setColor(p,m,x){this._color.set(p,m,x)}getColor(p,m){return this._color.get(p,m)}clear(){this._color.clear(),this._css.clear()}}},3656:(c,l)=>{Object.defineProperty(l,"__esModule",{value:!0}),l.addDisposableDomListener=void 0,l.addDisposableDomListener=function(h,f,p,m){h.addEventListener(f,p,m);let x=!1;return{dispose:()=>{x||(x=!0,h.removeEventListener(f,p,m))}}}},3551:function(c,l,h){var f=this&&this.__decorate||function(b,y,S,E){var N,T=arguments.length,L=T<3?y:E===null?E=Object.getOwnPropertyDescriptor(y,S):E;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")L=Reflect.decorate(b,y,S,E);else for(var A=b.length-1;A>=0;A--)(N=b[A])&&(L=(T<3?N(L):T>3?N(y,S,L):N(y,S))||L);return T>3&&L&&Object.defineProperty(y,S,L),L},p=this&&this.__param||function(b,y){return function(S,E){y(S,E,b)}};Object.defineProperty(l,"__esModule",{value:!0}),l.Linkifier=void 0;const m=h(3656),x=h(8460),_=h(844),w=h(2585),k=h(4725);let v=l.Linkifier=class extends _.Disposable{get currentLink(){return this._currentLink}constructor(b,y,S,E,N){super(),this._element=b,this._mouseService=y,this._renderService=S,this._bufferService=E,this._linkProviderService=N,this._linkCacheDisposables=[],this._isMouseOut=!0,this._wasResized=!1,this._activeLine=-1,this._onShowLinkUnderline=this.register(new x.EventEmitter),this.onShowLinkUnderline=this._onShowLinkUnderline.event,this._onHideLinkUnderline=this.register(new x.EventEmitter),this.onHideLinkUnderline=this._onHideLinkUnderline.event,this.register((0,_.getDisposeArrayDisposable)(this._linkCacheDisposables)),this.register((0,_.toDisposable)((()=>{var T;this._lastMouseEvent=void 0,(T=this._activeProviderReplies)==null||T.clear()}))),this.register(this._bufferService.onResize((()=>{this._clearCurrentLink(),this._wasResized=!0}))),this.register((0,m.addDisposableDomListener)(this._element,"mouseleave",(()=>{this._isMouseOut=!0,this._clearCurrentLink()}))),this.register((0,m.addDisposableDomListener)(this._element,"mousemove",this._handleMouseMove.bind(this))),this.register((0,m.addDisposableDomListener)(this._element,"mousedown",this._handleMouseDown.bind(this))),this.register((0,m.addDisposableDomListener)(this._element,"mouseup",this._handleMouseUp.bind(this)))}_handleMouseMove(b){this._lastMouseEvent=b;const y=this._positionFromMouseEvent(b,this._element,this._mouseService);if(!y)return;this._isMouseOut=!1;const S=b.composedPath();for(let E=0;E<S.length;E++){const N=S[E];if(N.classList.contains("xterm"))break;if(N.classList.contains("xterm-hover"))return}this._lastBufferCell&&y.x===this._lastBufferCell.x&&y.y===this._lastBufferCell.y||(this._handleHover(y),this._lastBufferCell=y)}_handleHover(b){if(this._activeLine!==b.y||this._wasResized)return this._clearCurrentLink(),this._askForLink(b,!1),void(this._wasResized=!1);this._currentLink&&this._linkAtPosition(this._currentLink.link,b)||(this._clearCurrentLink(),this._askForLink(b,!0))}_askForLink(b,y){var E,N;this._activeProviderReplies&&y||((E=this._activeProviderReplies)==null||E.forEach((T=>{T==null||T.forEach((L=>{L.link.dispose&&L.link.dispose()}))})),this._activeProviderReplies=new Map,this._activeLine=b.y);let S=!1;for(const[T,L]of this._linkProviderService.linkProviders.entries())y?(N=this._activeProviderReplies)!=null&&N.get(T)&&(S=this._checkLinkProviderResult(T,b,S)):L.provideLinks(b.y,(A=>{var R,$;if(this._isMouseOut)return;const P=A==null?void 0:A.map((D=>({link:D})));(R=this._activeProviderReplies)==null||R.set(T,P),S=this._checkLinkProviderResult(T,b,S),(($=this._activeProviderReplies)==null?void 0:$.size)===this._linkProviderService.linkProviders.length&&this._removeIntersectingLinks(b.y,this._activeProviderReplies)}))}_removeIntersectingLinks(b,y){const S=new Set;for(let E=0;E<y.size;E++){const N=y.get(E);if(N)for(let T=0;T<N.length;T++){const L=N[T],A=L.link.range.start.y<b?0:L.link.range.start.x,P=L.link.range.end.y>b?this._bufferService.cols:L.link.range.end.x;for(let R=A;R<=P;R++){if(S.has(R)){N.splice(T--,1);break}S.add(R)}}}}_checkLinkProviderResult(b,y,S){var T;if(!this._activeProviderReplies)return S;const E=this._activeProviderReplies.get(b);let N=!1;for(let L=0;L<b;L++)this._activeProviderReplies.has(L)&&!this._activeProviderReplies.get(L)||(N=!0);if(!N&&E){const L=E.find((A=>this._linkAtPosition(A.link,y)));L&&(S=!0,this._handleNewLink(L))}if(this._activeProviderReplies.size===this._linkProviderService.linkProviders.length&&!S)for(let L=0;L<this._activeProviderReplies.size;L++){const A=(T=this._activeProviderReplies.get(L))==null?void 0:T.find((P=>this._linkAtPosition(P.link,y)));if(A){S=!0,this._handleNewLink(A);break}}return S}_handleMouseDown(){this._mouseDownLink=this._currentLink}_handleMouseUp(b){if(!this._currentLink)return;const y=this._positionFromMouseEvent(b,this._element,this._mouseService);y&&this._mouseDownLink===this._currentLink&&this._linkAtPosition(this._currentLink.link,y)&&this._currentLink.link.activate(b,this._currentLink.link.text)}_clearCurrentLink(b,y){this._currentLink&&this._lastMouseEvent&&(!b||!y||this._currentLink.link.range.start.y>=b&&this._currentLink.link.range.end.y<=y)&&(this._linkLeave(this._element,this._currentLink.link,this._lastMouseEvent),this._currentLink=void 0,(0,_.disposeArray)(this._linkCacheDisposables))}_handleNewLink(b){if(!this._lastMouseEvent)return;const y=this._positionFromMouseEvent(this._lastMouseEvent,this._element,this._mouseService);y&&this._linkAtPosition(b.link,y)&&(this._currentLink=b,this._currentLink.state={decorations:{underline:b.link.decorations===void 0||b.link.decorations.underline,pointerCursor:b.link.decorations===void 0||b.link.decorations.pointerCursor},isHovered:!0},this._linkHover(this._element,b.link,this._lastMouseEvent),b.link.decorations={},Object.defineProperties(b.link.decorations,{pointerCursor:{get:()=>{var S,E;return(E=(S=this._currentLink)==null?void 0:S.state)==null?void 0:E.decorations.pointerCursor},set:S=>{var E;(E=this._currentLink)!=null&&E.state&&this._currentLink.state.decorations.pointerCursor!==S&&(this._currentLink.state.decorations.pointerCursor=S,this._currentLink.state.isHovered&&this._element.classList.toggle("xterm-cursor-pointer",S))}},underline:{get:()=>{var S,E;return(E=(S=this._currentLink)==null?void 0:S.state)==null?void 0:E.decorations.underline},set:S=>{var E,N,T;(E=this._currentLink)!=null&&E.state&&((T=(N=this._currentLink)==null?void 0:N.state)==null?void 0:T.decorations.underline)!==S&&(this._currentLink.state.decorations.underline=S,this._currentLink.state.isHovered&&this._fireUnderlineEvent(b.link,S))}}}),this._linkCacheDisposables.push(this._renderService.onRenderedViewportChange((S=>{if(!this._currentLink)return;const E=S.start===0?0:S.start+1+this._bufferService.buffer.ydisp,N=this._bufferService.buffer.ydisp+1+S.end;if(this._currentLink.link.range.start.y>=E&&this._currentLink.link.range.end.y<=N&&(this._clearCurrentLink(E,N),this._lastMouseEvent)){const T=this._positionFromMouseEvent(this._lastMouseEvent,this._element,this._mouseService);T&&this._askForLink(T,!1)}}))))}_linkHover(b,y,S){var E;(E=this._currentLink)!=null&&E.state&&(this._currentLink.state.isHovered=!0,this._currentLink.state.decorations.underline&&this._fireUnderlineEvent(y,!0),this._currentLink.state.decorations.pointerCursor&&b.classList.add("xterm-cursor-pointer")),y.hover&&y.hover(S,y.text)}_fireUnderlineEvent(b,y){const S=b.range,E=this._bufferService.buffer.ydisp,N=this._createLinkUnderlineEvent(S.start.x-1,S.start.y-E-1,S.end.x,S.end.y-E-1,void 0);(y?this._onShowLinkUnderline:this._onHideLinkUnderline).fire(N)}_linkLeave(b,y,S){var E;(E=this._currentLink)!=null&&E.state&&(this._currentLink.state.isHovered=!1,this._currentLink.state.decorations.underline&&this._fireUnderlineEvent(y,!1),this._currentLink.state.decorations.pointerCursor&&b.classList.remove("xterm-cursor-pointer")),y.leave&&y.leave(S,y.text)}_linkAtPosition(b,y){const S=b.range.start.y*this._bufferService.cols+b.range.start.x,E=b.range.end.y*this._bufferService.cols+b.range.end.x,N=y.y*this._bufferService.cols+y.x;return S<=N&&N<=E}_positionFromMouseEvent(b,y,S){const E=S.getCoords(b,y,this._bufferService.cols,this._bufferService.rows);if(E)return{x:E[0],y:E[1]+this._bufferService.buffer.ydisp}}_createLinkUnderlineEvent(b,y,S,E,N){return{x1:b,y1:y,x2:S,y2:E,cols:this._bufferService.cols,fg:N}}};l.Linkifier=v=f([p(1,k.IMouseService),p(2,k.IRenderService),p(3,w.IBufferService),p(4,k.ILinkProviderService)],v)},9042:(c,l)=>{Object.defineProperty(l,"__esModule",{value:!0}),l.tooMuchOutput=l.promptLabel=void 0,l.promptLabel="Terminal input",l.tooMuchOutput="Too much output to announce, navigate to rows manually to read"},3730:function(c,l,h){var f=this&&this.__decorate||function(k,v,b,y){var S,E=arguments.length,N=E<3?v:y===null?y=Object.getOwnPropertyDescriptor(v,b):y;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")N=Reflect.decorate(k,v,b,y);else for(var T=k.length-1;T>=0;T--)(S=k[T])&&(N=(E<3?S(N):E>3?S(v,b,N):S(v,b))||N);return E>3&&N&&Object.defineProperty(v,b,N),N},p=this&&this.__param||function(k,v){return function(b,y){v(b,y,k)}};Object.defineProperty(l,"__esModule",{value:!0}),l.OscLinkProvider=void 0;const m=h(511),x=h(2585);let _=l.OscLinkProvider=class{constructor(k,v,b){this._bufferService=k,this._optionsService=v,this._oscLinkService=b}provideLinks(k,v){var P;const b=this._bufferService.buffer.lines.get(k-1);if(!b)return void v(void 0);const y=[],S=this._optionsService.rawOptions.linkHandler,E=new m.CellData,N=b.getTrimmedLength();let T=-1,L=-1,A=!1;for(let R=0;R<N;R++)if(L!==-1||b.hasContent(R)){if(b.loadCell(R,E),E.hasExtendedAttrs()&&E.extended.urlId){if(L===-1){L=R,T=E.extended.urlId;continue}A=E.extended.urlId!==T}else L!==-1&&(A=!0);if(A||L!==-1&&R===N-1){const $=(P=this._oscLinkService.getLinkData(T))==null?void 0:P.uri;if($){const D={start:{x:L+1,y:k},end:{x:R+(A||R!==N-1?0:1),y:k}};let H=!1;if(!(S!=null&&S.allowNonHttpProtocols))try{const K=new URL($);["http:","https:"].includes(K.protocol)||(H=!0)}catch{H=!0}H||y.push({text:$,range:D,activate:(K,U)=>S?S.activate(K,U,D):w(0,U),hover:(K,U)=>{var F;return(F=S==null?void 0:S.hover)==null?void 0:F.call(S,K,U,D)},leave:(K,U)=>{var F;return(F=S==null?void 0:S.leave)==null?void 0:F.call(S,K,U,D)}})}A=!1,E.hasExtendedAttrs()&&E.extended.urlId?(L=R,T=E.extended.urlId):(L=-1,T=-1)}}v(y)}};function w(k,v){if(confirm(`Do you want to navigate to ${v}?
61
61