@turmind/halo 0.2.5 → 1.0.0

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 (44) hide show
  1. package/README.md +5 -5
  2. package/admin-out/404.html +1 -1
  3. package/admin-out/_next/static/chunks/212-e217e00ce6cc2bdc.js +1 -0
  4. package/admin-out/_next/static/chunks/397-fc5a406d80d46ca7.js +1 -0
  5. package/admin-out/_next/static/chunks/app/page-635d9668d47a2b9e.js +1 -0
  6. package/admin-out/_next/static/css/57622245d7724ee0.css +3 -0
  7. package/admin-out/index.html +1 -1
  8. package/admin-out/index.txt +5 -5
  9. package/bundled-docs/design/agent.md +12 -2
  10. package/bundled-docs/design/cron.md +16 -3
  11. package/bundled-docs/design/goal-mode.md +141 -0
  12. package/bundled-docs/design/session.md +25 -0
  13. package/bundled-docs/design/ws.md +34 -3
  14. package/bundled-docs/dev/add-model-provider.md +17 -9
  15. package/bundled-docs/dev/api.md +27 -1
  16. package/bundled-docs/dev/deploy.md +4 -8
  17. package/bundled-docs/dev/desktop-packaging.md +20 -0
  18. package/bundled-docs/dev/env.md +10 -5
  19. package/bundled-docs/dev/tools.md +60 -4
  20. package/bundled-docs/guide/cli.md +3 -2
  21. package/bundled-docs/requirements/chat.md +9 -0
  22. package/bundled-docs/requirements/command.md +12 -1
  23. package/dist/index.js +2371 -1254
  24. package/package.json +1 -1
  25. package/templates/agents/goal/AGENT.md +165 -0
  26. package/templates/agents/goal/agent.yaml +34 -0
  27. package/templates/models/anthropic.yaml +1 -0
  28. package/templates/models/aws-bedrock-claude-invoke.yaml +7 -0
  29. package/templates/models/aws-bedrock-mantle.yaml +51 -11
  30. package/templates/models/deepseek.yaml +2 -0
  31. package/templates/models/doubao.yaml +4 -0
  32. package/templates/models/hunyuan.yaml +1 -0
  33. package/templates/models/kimi.yaml +49 -13
  34. package/templates/models/mimo-token-plan-china.yaml +2 -0
  35. package/templates/models/minimax.yaml +37 -5
  36. package/templates/models/openai.yaml +1 -0
  37. package/templates/models/qwen.yaml +2 -0
  38. package/templates/schema.sql +3 -1
  39. package/admin-out/_next/static/chunks/212-170855bed19f67f3.js +0 -1
  40. package/admin-out/_next/static/chunks/307-d7a99f9a4a436ec3.js +0 -1
  41. package/admin-out/_next/static/chunks/app/page-96fce52cfe97cc9b.js +0 -1
  42. package/admin-out/_next/static/css/6f53bae6f1952300.css +0 -3
  43. /package/admin-out/_next/static/{P60h_WmaPcXYhIabUg6I2 → gzvax-Lg7K157j0rQJHje}/_buildManifest.js +0 -0
  44. /package/admin-out/_next/static/{P60h_WmaPcXYhIabUg6I2 → gzvax-Lg7K157j0rQJHje}/_ssgManifest.js +0 -0
@@ -1 +0,0 @@
1
- (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[974],{11704:(e,t,r)=>{"use strict";r.r(t),r.d(t,{default:()=>sN});var a,n,s=r(69625),l=r(43853),o=r(52992),i=r(10842),c=r(48476);let d=1;function u(){return"g".concat(d++)}function x(e){let t=e.groups[e.activeGroupIdx];if(!t)return{tabs:[],activeTab:null};let r=[];for(let a of t.tabs){let t=e.buffers[a];t&&r.push(t)}return{tabs:r,activeTab:t.activeTab}}function m(){return(0,c.v)((e,t)=>({buffers:{},groups:[{id:u(),tabs:[],activeTab:null}],activeGroupIdx:0,tabs:[],activeTab:null,fileTree:null,modifiedPaths:new Set,rejectedFile:null,bottomTab:"chat",maximized:"true"===localStorage.getItem("halo_editor_maximized"),bottomFloating:"true"===sessionStorage.getItem("halo_bottom_floating"),bottomMaximized:!1,bottomFloatRect:(()=>{let e=sessionStorage.getItem("halo_bottom_float_rect");if(e)try{return JSON.parse(e)}catch(e){}return{x:Math.max(0,window.innerWidth-480-24),y:Math.max(0,window.innerHeight-640-24),w:480,h:640}})(),selectedText:null,selectedRange:null,contextEnabled:"false"!==localStorage.getItem("halo_context_enabled"),setSelectedText(t,r){e({selectedText:t||null,selectedRange:null!=r?r:null})},setContextEnabled(t){e({contextEnabled:t}),localStorage.setItem("halo_context_enabled",String(t))},openFile(t,r,a,n,s){e(e=>{let l=e.buffers[t]?e.buffers:{...e.buffers,[t]:{path:t,content:r,originalContent:r,language:a,mtime:n,size:null==s?void 0:s.size,createdAt:null==s?void 0:s.createdAt}},o=e.activeGroupIdx,i=e.groups[o],c=i.tabs.includes(t)?i.tabs:[...i.tabs,t],d=e.groups.map((e,r)=>r===o?{...e,tabs:c,activeTab:t}:e),u={...e,buffers:l,groups:d};return{buffers:l,groups:d,...x(u)}})},openPreview(t,r,a,n){e(e=>{let s=e.buffers[t]?e.buffers:{...e.buffers,[t]:{path:t,content:"",originalContent:"",language:"",preview:{downloadUrl:r,viewUrl:a},size:null==n?void 0:n.size,mtime:null==n?void 0:n.mtime,createdAt:null==n?void 0:n.createdAt}},l=e.activeGroupIdx,o=e.groups[l],i=o.tabs.includes(t)?o.tabs:[...o.tabs,t],c=e.groups.map((e,r)=>r===l?{...e,tabs:i,activeTab:t}:e),d={...e,buffers:s,groups:c};return{buffers:s,groups:c,...x(d)}})},openFileInGroup(t,r,a,n,s,l){e(e=>{if(t<0||t>=e.groups.length)return e;let o=e.buffers[r]?e.buffers:{...e.buffers,[r]:{path:r,content:a,originalContent:a,language:n,mtime:s,size:null==l?void 0:l.size,createdAt:null==l?void 0:l.createdAt}},i=e.groups[t],c=i.tabs.includes(r)?i.tabs:[...i.tabs,r],d=e.groups.map((e,a)=>a===t?{...e,tabs:c,activeTab:r}:e),u={...e,buffers:o,groups:d,activeGroupIdx:t};return{buffers:o,groups:d,activeGroupIdx:t,...x(u)}})},closeTab(t){e(e=>{let r=e.groups.map(e=>{if(!e.tabs.includes(t))return e;let r=e.tabs.filter(e=>e!==t),a=e.activeTab;if(a===t){var n;a=null!=(n=r[Math.min(e.tabs.indexOf(t),r.length-1)])?n:null}return{...e,tabs:r,activeTab:a}}),a=r.some(e=>e.tabs.includes(t)),n=a?e.buffers:(()=>{let{[t]:r,...a}=e.buffers;return a})(),s=a?e.modifiedPaths:(()=>{if(!e.modifiedPaths.has(t))return e.modifiedPaths;let r=new Set(e.modifiedPaths);return r.delete(t),r})(),l=r.length>1&&0===r[1].tabs.length?{groups:[r[0]],activeGroupIdx:0}:{groups:r,activeGroupIdx:Math.min(e.activeGroupIdx,r.length-1)},o={...e,buffers:n,modifiedPaths:s,...l};return{buffers:n,modifiedPaths:s,...l,...x(o)}})},closeTabIn(t,r){e(e=>{if(t<0||t>=e.groups.length)return e;let a=e.groups[t];if(!a.tabs.includes(r))return e;let n=a.tabs.filter(e=>e!==r),s=a.activeTab;if(s===r){var l;s=null!=(l=n[Math.min(a.tabs.indexOf(r),n.length-1)])?l:null}let o=e.groups.map((e,r)=>r===t?{...e,tabs:n,activeTab:s}:e),i=e.activeGroupIdx;o.length>1&&0===o[1].tabs.length&&(o=[o[0]],i=0);let c=o.some(e=>e.tabs.includes(r)),d=c?e.buffers:(()=>{let{[r]:t,...a}=e.buffers;return a})(),u=c?e.modifiedPaths:(()=>{if(!e.modifiedPaths.has(r))return e.modifiedPaths;let t=new Set(e.modifiedPaths);return t.delete(r),t})(),m={...e,groups:o,activeGroupIdx:i,buffers:d,modifiedPaths:u};return{groups:o,activeGroupIdx:i,buffers:d,modifiedPaths:u,...x(m)}})},setActiveTab(t,r){e(e=>{let a=null!=r?r:-1;if(a<0){let r=e.groups[e.activeGroupIdx];a=(null==r?void 0:r.tabs.includes(t))?e.activeGroupIdx:e.groups.findIndex(e=>e.tabs.includes(t))}if(a<0||!e.groups[a].tabs.includes(t))return e;let n=e.groups.map((e,r)=>r===a?{...e,activeTab:t}:e),s=a,l={...e,groups:n,activeGroupIdx:s};return{groups:n,activeGroupIdx:s,...x(l)}})},updateContent(t,r){e(e=>{let a=e.buffers[t];if(!a)return e;let n=r!==a.originalContent,s={...e.buffers,[t]:{...a,content:r,modified:n}},l=new Set(e.modifiedPaths);n?l.add(t):l.delete(t);let o={...e,buffers:s,modifiedPaths:l};return{buffers:s,modifiedPaths:l,...x(o)}})},setActiveGroup(t){e(e=>{if(t<0||t>=e.groups.length||t===e.activeGroupIdx)return e;let r={...e,activeGroupIdx:t};return{activeGroupIdx:t,...x(r)}})},splitToRight(t){e(e=>{var r,a;if(e.groups.length>=2)return e;let n=null!=(a=null!=t?t:null==(r=e.groups[e.activeGroupIdx])?void 0:r.activeTab)?a:null;if(!n||!e.buffers[n])return e;let s={id:u(),tabs:[n],activeTab:n},l=[e.groups[0],s],o={...e,groups:l,activeGroupIdx:1};return{groups:l,activeGroupIdx:1,...x(o)}})},closeGroup(t){e(e=>{if(e.groups.length<=1||t<0||t>=e.groups.length)return e;e.groups[t];let r=e.groups.filter((e,r)=>r!==t),a=new Set;for(let e of r)for(let t of e.tabs)a.add(t);let n={};for(let[t,r]of Object.entries(e.buffers))a.has(t)&&(n[t]=r);let s=new Set;for(let t of e.modifiedPaths)a.has(t)&&s.add(t);let l=Math.max(0,Math.min(e.activeGroupIdx,r.length-1)),o={...e,groups:r,activeGroupIdx:l,buffers:n,modifiedPaths:s};return{groups:r,activeGroupIdx:l,buffers:n,modifiedPaths:s,...x(o)}})},moveTabToGroup(t,r,a,n){e(e=>{if(t===a){if(t<0||t>=e.groups.length)return e;let a=e.groups[t],s=a.tabs.indexOf(r);if(s<0)return e;let l=null==n?a.tabs.length-1:Math.max(0,Math.min(n,a.tabs.length-1));if(s===l)return e;let o=function(e,t,r){let a=[...e],[n]=a.splice(t,1);return a.splice(r,0,n),a}(a.tabs,s,l),i=e.groups.map((e,a)=>a===t?{...e,tabs:o,activeTab:r}:e),c={...e,groups:i};return{groups:i,...x(c)}}if(t<0||t>=e.groups.length||a<0||a>e.groups.length)return e;let s=e.groups[t];if(!s.tabs.includes(r))return e;let l=s.tabs.filter(e=>e!==r),o=s.activeTab;if(o===r){var i;o=null!=(i=l[Math.min(s.tabs.indexOf(r),l.length-1)])?i:null}let c=e.groups.slice();if(a===e.groups.length){if(e.groups.length>=2)return e;c[t]={...s,tabs:l,activeTab:o},c.push({id:u(),tabs:[r],activeTab:r})}else{let e=c[a],i=e.tabs.includes(r)?e.tabs:(()=>{let t=[...e.tabs];return null==n||n>=t.length?t.push(r):t.splice(Math.max(0,n),0,r),t})();c[t]={...s,tabs:l,activeTab:o},c[a]={...e,tabs:i,activeTab:r}}let d=a;0===c[t].tabs.length&&c.length>1&&(c=c.filter((e,r)=>r!==t),d=Math.max(0,Math.min(a>t?a-1:a,c.length-1)));let m={...e,groups:c,activeGroupIdx:d};return{groups:c,activeGroupIdx:d,...x(m)}})},setFileTree(t){e({fileTree:t})},setDirChildren(t,r){e(e=>{if(!e.fileTree)return e;let a=[...r].sort((e,t)=>e.type!==t.type?"directory"===e.type?-1:1:e.name.localeCompare(t.name)),n=JSON.parse(JSON.stringify(e.fileTree));if(!t)return n.children=a,n.hasChildren=a.length>0,{fileTree:n};let s=t.split("/").filter(Boolean),l=n;for(let t of s)if(!(null==l?void 0:l.children)||!(l=l.children.find(e=>e.name===t&&"directory"===e.type)))return e;return l.children=a,l.hasChildren=a.length>0,{fileTree:n}})},markModified(t){e(e=>{let r=e.buffers[t];if(!r)return e;let a=new Set(e.modifiedPaths);a.add(t);let n={...e.buffers,[t]:{...r,modified:!0}},s={...e,buffers:n,modifiedPaths:a};return{buffers:n,modifiedPaths:a,...x(s)}})},clearModified(t){e(e=>{let r=e.buffers[t];if(!r)return e;let a=new Set(e.modifiedPaths);a.delete(t);let n={...e.buffers,[t]:{...r,modified:!1}},s={...e,buffers:n,modifiedPaths:a};return{buffers:n,modifiedPaths:a,...x(s)}})},markSaved(t,r){e(e=>{let a=e.buffers[t];if(!a)return e;let n=new Set(e.modifiedPaths);n.delete(t);let s={...e.buffers,[t]:{...a,originalContent:a.content,modified:!1,mtime:null!=r?r:a.mtime}},l={...e,buffers:s,modifiedPaths:n};return{buffers:s,modifiedPaths:n,...x(l)}})},setRejectedFile(t){e({rejectedFile:t})},setBottomTab(t){e({bottomTab:t})},pendingTerminalCwd:null,requestTerminalSpawn(t){e({pendingTerminalCwd:t})},consumeTerminalSpawn(){let r=t().pendingTerminalCwd;return null!=r&&e({pendingTerminalCwd:null}),r},toggleMaximized(){e(e=>{let t=!e.maximized;return localStorage.setItem("halo_editor_maximized",String(t)),{maximized:t}})},setMaximized(t){localStorage.setItem("halo_editor_maximized",String(t)),e({maximized:t})},setBottomFloating(t){sessionStorage.setItem("halo_bottom_floating",String(t)),e({bottomFloating:t})},setBottomMaximized(t){e({bottomMaximized:t})},setBottomFloatRect(t){sessionStorage.setItem("halo_bottom_float_rect",JSON.stringify(t)),e({bottomFloatRect:t})},insertFileNode(t){let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"file";e(e=>{if(!e.fileTree)return e;let a=t.split("/").filter(Boolean);if(0===a.length)return e;let n=JSON.parse(JSON.stringify(e.fileTree)),s=n;for(let e=0;e<a.length-1;e++){var l;let t=null==(l=s.children)?void 0:l.find(t=>t.name===a[e]&&"directory"===t.type);if(!t)return void 0===s.children&&(s.hasChildren=!0),{fileTree:n};s=t}if(void 0===s.children)return s.hasChildren=!0,{fileTree:n};let o=a[a.length-1];if(s.children.some(e=>e.name===o))return{fileTree:n};let i="directory"===r?{name:o,path:t,type:"directory",hasChildren:!1,children:[]}:{name:o,path:t,type:"file"};return s.children.push(i),s.children.sort((e,t)=>e.type!==t.type?"directory"===e.type?-1:1:e.name.localeCompare(t.name)),{fileTree:n}})},removeFileNode(t){e(e=>{if(!e.fileTree)return e;let r=t.split("/").filter(Boolean);if(0===r.length)return e;let a=JSON.parse(JSON.stringify(e.fileTree)),n=a;for(let t=0;t<r.length-1;t++){var s;let a=null==(s=n.children)?void 0:s.find(e=>e.name===r[t]&&"directory"===e.type);if(!a)return e;n=a}let l=r[r.length-1];if(!n.children)return e;let o=n.children.findIndex(e=>e.name===l);return -1===o?e:(n.children.splice(o,1),{fileTree:a})})},async checkAndRefresh(r,a,n){let s=t().buffers[r];if(!s||s.preview||s.mtime&&a<=s.mtime||s.modified)return!1;let l=await n();return e(e=>{var t,a;let n=e.buffers[r];if(!n)return e;let s={...e.buffers,[r]:{...n,content:l.content,originalContent:l.content,mtime:l.modifiedAt,size:null!=(t=l.size)?t:n.size,createdAt:null!=(a=l.createdAt)?a:n.createdAt}},o={...e,buffers:s};return{buffers:s,...x(o)}}),!0}}))}let p=m(),h=(0,l.createContext)(null);function f(e){let{children:t}=e,r=(0,l.useRef)(null);return r.current||(r.current=m()),(0,l.createElement)(h.Provider,{value:r.current},t)}function g(){let e=(0,l.useContext)(h);return null!=e?e:p}var v=r(17246);class b{connect(e){if(!this.ws||this.ws.readyState!==WebSocket.OPEN&&this.ws.readyState!==WebSocket.CONNECTING){this.url=null!=e?e:this.getDefaultUrl(),this.intentionalClose=!1,this.connectStartedAt=Date.now(),this.startLiveness();try{let e=!1;this.ws=new WebSocket(this.url),this.ws.onopen=()=>{for(let t of(console.log("[WsClient] Connected"),e=!0,this.reconnectDelay=1e3,this.lastReceiveTs=Date.now(),this.pendingQueue))this.ws.send(JSON.stringify(t));this.pendingQueue=[],this.emit("_connected",{})},this.ws.onmessage=e=>{this.lastReceiveTs=Date.now();try{let t=JSON.parse(e.data),r=t.type;r&&this.emit(r,t)}catch(e){console.error("[WsClient] Failed to parse message:",e)}},this.ws.onclose=()=>{console.log("[WsClient] Disconnected"),this.ws=null,this.emit("_disconnected",{}),this.intentionalClose||(e?this.reconnect():this.checkAuthThenReconnect())},this.ws.onerror=e=>{console.error("[WsClient] Error:",e)}}catch(e){console.error("[WsClient] Failed to connect:",e),this.reconnect()}}}disconnect(){this.intentionalClose=!0,this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this.stopLiveness(),this.ws&&(this.ws.close(),this.ws=null)}startLiveness(){this.stopLiveness(),this.livenessTimer=setInterval(()=>{if(!this.ws||this.intentionalClose)return;let e=this.ws.readyState;if(e===WebSocket.CONNECTING){if(Date.now()-this.connectStartedAt>1e4){console.log("[WsClient] CONNECTING for >10s, forcing reconnect");try{this.ws.close()}catch(e){}}return}if(e===WebSocket.CLOSING||e===WebSocket.CLOSED){console.log("[WsClient] readyState=CLOSED with no onclose, forcing reconnect"),this.ws=null,this.emit("_disconnected",{}),this.reconnect();return}try{let e=this.ws.bufferedAmount;if(this.ws.send(JSON.stringify({type:"__ping__"})),e>0&&this.ws.bufferedAmount>=e){console.log("[WsClient] bufferedAmount stuck (".concat(e," → ").concat(this.ws.bufferedAmount,"), forcing reconnect"));try{this.ws.close()}catch(e){}}}catch(e){console.log("[WsClient] send threw on liveness probe, forcing reconnect:",e);try{this.ws.close()}catch(e){}}},15e3)}stopLiveness(){this.livenessTimer&&(clearInterval(this.livenessTimer),this.livenessTimer=null)}send(e){if(this.ws&&this.ws.readyState===WebSocket.OPEN)return void this.ws.send(JSON.stringify(e));let t=e.type;"__ping__"!==t&&"terminal:input"!==t&&"terminal:resize"!==t&&(this.pendingQueue.length>=100&&this.pendingQueue.shift(),this.pendingQueue.push(e))}on(e,t){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(t),()=>{let r=this.listeners.get(e);r&&(r.delete(t),0===r.size&&this.listeners.delete(e))}}get connected(){var e;return(null==(e=this.ws)?void 0:e.readyState)===WebSocket.OPEN}reconnectIfStale(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:5e3;if(!this.ws)return void this.connect(this.url);if(0===e&&this.ws.readyState===WebSocket.CONNECTING){console.log("[WsClient] Network back online; tearing down stalled CONNECTING socket");try{this.ws.close()}catch(e){}return}if(this.ws.readyState===WebSocket.OPEN&&!(Date.now()-this.lastReceiveTs<e)){console.log("[WsClient] Connection looks stale, forcing reconnect");try{this.ws.close()}catch(e){}}}emit(e,t){let r=this.listeners.get(e);r&&r.forEach(r=>{try{r(t)}catch(t){console.error('[WsClient] Error in handler for "'.concat(e,'":'),t)}})}reconnect(){this.reconnectTimer||(console.log("[WsClient] Reconnecting in ".concat(this.reconnectDelay,"ms...")),this.reconnectTimer=setTimeout(()=>{this.reconnectTimer=null,this.reconnectDelay=Math.min(2*this.reconnectDelay,this.maxReconnectDelay),this.connect(this.url)},this.reconnectDelay))}async checkAuthThenReconnect(){try{let e=await fetch("/api/auth/check",{credentials:"include"});if(401===e.status){console.log("[WsClient] Auth expired — stopping reconnect, login required"),this.stopLiveness(),this.emit("_auth_expired",{});return}}catch(e){}this.intentionalClose||this.reconnect()}getDefaultUrl(){let e="https:"===window.location.protocol?"wss:":"ws:";return"".concat(e,"//").concat(window.location.host,"/ws")}constructor(){this.ws=null,this.listeners=new Map,this.reconnectTimer=null,this.reconnectDelay=1e3,this.maxReconnectDelay=3e4,this.url="",this.intentionalClose=!1,this.pendingQueue=[],this.lastReceiveTs=0,this.connectStartedAt=0,this.livenessTimer=null}}let j=new b;function y(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:p;v.F.files.tree(e).then(r=>{var a,n;let s={name:null!=(n=null!=(a=r.root)?a:e.split("/").filter(Boolean).pop())?n:"root",path:"",type:"directory",hasChildren:r.tree.length>0,children:r.tree};t.getState().setFileTree(s)}).catch(e=>{console.error("[Explorer] Failed to load file tree:",e)})}async function w(e,t){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:p;try{let a=await v.F.files.tree(e,t);r.getState().setDirChildren(t,a.tree)}catch(e){console.error("[Explorer] Failed to load directory:",t,e)}}let N={M:{letter:"M",color:"#1B81A8",label:"Modified"},A:{letter:"A",color:"#487E02",label:"Added"},D:{letter:"D",color:"#F48771",label:"Deleted"},R:{letter:"R",color:"#2090D3",label:"Renamed"},C:{letter:"C",color:"#2090D3",label:"Copied"},U:{letter:"C",color:"#E4676B",label:"Conflict"},"?":{letter:"U",color:"#487E02",label:"Untracked"}},k={letter:"?",color:"#487E02",label:"Untracked"};function S(e){var t;return null!=(t=N[e])?t:k}function C(e){return""!==e&&" "!==e&&"?"!==e}function A(e){return""!==e&&" "!==e}let I={files:new Map,dirs:new Map,ignored:new Set},E=(0,c.v)(e=>({byProject:{},repoStatus:{},setForProject:(t,r)=>e(e=>({byProject:{...e.byProject,[t]:r}})),clearProject:t=>e(e=>{if(!e.byProject[t])return e;let r={...e.byProject};return delete r[t],{byProject:r}}),setRepoStatus:(t,r)=>e(e=>e.repoStatus[t]===r?e:{repoStatus:{...e.repoStatus,[t]:r}}),clearRepoStatus:t=>e(e=>{if(!(t in e.repoStatus))return e;let r={...e.repoStatus};return delete r[t],{repoStatus:r}})}));var T=r(10666),F=r(1833);function D(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];return(0,F.QP)((0,T.$)(t))}function M(){return Math.random().toString(36).substring(2,10)+Date.now().toString(36)}function P(e){return!!e&&!!(e.startsWith("/")||/^[a-zA-Z]:[\\/]/.test(e)||e.startsWith("\\\\"))}function L(e,t){let r=window;return"function"==typeof r.haloPrompt?r.haloPrompt(e,t):Promise.resolve(window.prompt(e,t))}function R(e){let t=window;return"function"==typeof t.haloConfirm?t.haloConfirm(e):Promise.resolve(window.confirm(e))}function z(e){var t,r,a;return null!=(a=({ts:"typescript",tsx:"typescript",js:"javascript",jsx:"javascript",json:"json",md:"markdown",css:"css",html:"html",yaml:"yaml",yml:"yaml",py:"python",rs:"rust",go:"go",sh:"shell",bash:"shell",sql:"sql",toml:"toml",xml:"xml",svg:"xml",env:"plaintext",gitignore:"plaintext",dockerfile:"dockerfile"})[null!=(r=null==(t=e.split(".").pop())?void 0:t.toLowerCase())?r:""])?a:"plaintext"}var _=r(51332),O=r(23028),W=r(62186),U=r(98844),B=r(98299),H=r(53298),K=r(24604),G=r(91531),J=r(1813),q=r(61031),Z=r(378),V=r(17317),Y=r(80037),$=r(67508),Q=r(26205),X=r(59800),ee=r(5276),et=r(48550),er=r(79464),ea=r(68301),en=r(71473),es=r(27153),el=r(44242);let eo={ts:K.A,tsx:K.A,mts:K.A,cts:K.A,js:K.A,jsx:K.A,mjs:K.A,cjs:K.A,json:G.A,jsonc:G.A,html:J.A,htm:J.A,svg:J.A,xml:J.A,css:q.A,scss:q.A,sass:q.A,less:q.A,md:Z.A,mdx:Z.A,txt:Z.A,rst:Z.A,log:Z.A,csv:V.A,tsv:V.A,xlsx:V.A,xls:V.A,sql:Y.A,sh:$.A,bash:$.A,zsh:$.A,yaml:Q.A,yml:Q.A,toml:Q.A,ini:Q.A,env:Q.A,py:X.A,go:ee.A,rs:ee.A,c:ee.A,cpp:ee.A,h:ee.A,hpp:ee.A,java:ee.A,kt:ee.A,scala:ee.A,cs:ee.A,swift:ee.A,dart:ee.A,rb:ee.A,php:ee.A,lua:ee.A,r:ee.A,png:et.A,jpg:et.A,jpeg:et.A,gif:et.A,webp:et.A,bmp:et.A,ico:et.A,avif:et.A,mp4:er.A,webm:er.A,mov:er.A,avi:er.A,mkv:er.A,ogg:er.A,mp3:ea.A,wav:ea.A,flac:ea.A,aac:ea.A,m4a:ea.A,wma:ea.A,zip:en.A,tar:en.A,gz:en.A,"7z":en.A,rar:en.A,pdf:es.A,docx:es.A,doc:es.A,pptx:es.A,ppt:es.A},ei={ts:"text-blue-400",tsx:"text-blue-400",mts:"text-blue-400",cts:"text-blue-400",js:"text-yellow-400",jsx:"text-yellow-400",mjs:"text-yellow-400",cjs:"text-yellow-400",json:"text-yellow-300",jsonc:"text-yellow-300",html:"text-orange-400",htm:"text-orange-400",css:"text-blue-300",scss:"text-pink-400",sass:"text-pink-400",less:"text-blue-300",md:"text-sky-300",mdx:"text-sky-300",py:"text-green-400",go:"text-cyan-400",rs:"text-orange-400",java:"text-red-400",rb:"text-red-300",php:"text-indigo-300",sh:"text-green-300",bash:"text-green-300",svg:"text-orange-300",xml:"text-orange-300",yaml:"text-red-300",yml:"text-red-300",sql:"text-cyan-300",png:"text-purple-300",jpg:"text-purple-300",jpeg:"text-purple-300",gif:"text-purple-300",webp:"text-purple-300",avif:"text-purple-300",mp4:"text-pink-300",webm:"text-pink-300",mov:"text-pink-300",mp3:"text-emerald-300",wav:"text-emerald-300",flac:"text-emerald-300",pdf:"text-red-400",docx:"text-blue-400",doc:"text-blue-400",pptx:"text-orange-400",ppt:"text-orange-400",zip:"text-amber-400",tar:"text-amber-400",gz:"text-amber-400"};function ec(e){var t,r,a,n,s,l;let o=null!=(a=null==(t=e.split(".").pop())?void 0:t.toLowerCase())?a:"",i=null!=(n=null==(r=e.split("/").pop())?void 0:r.toLowerCase())?n:"";return"dockerfile"===i||i.startsWith("dockerfile.")?{Icon:$.A,color:"text-cyan-400"}:".gitignore"===i||".gitattributes"===i?{Icon:Q.A,color:"text-[var(--muted-foreground)]"}:".env"===i||i.startsWith(".env.")?{Icon:Q.A,color:"text-yellow-300"}:"makefile"===i||"cmake"===i?{Icon:$.A,color:"text-[var(--muted-foreground)]"}:{Icon:null!=(s=eo[o])?s:el.A,color:null!=(l=ei[o])?l:"text-[var(--muted-foreground)]"}}let ed="halo:file-tree:expanded",eu=null,ex=new Map;function em(){if(eu)return eu;try{let e=localStorage.getItem(ed);eu=e?new Set(JSON.parse(e)):new Set}catch(e){eu=new Set}return eu}let ep=null;function eh(e,t){let r=em(),a=r.has(e);if(t?r.add(e):r.delete(e),ep&&clearTimeout(ep),ep=setTimeout(()=>{try{let e=em();localStorage.setItem(ed,JSON.stringify([...e]))}catch(e){}},300),a!==t){let r=ex.get(e);if(r)for(let e of r)e(t)}}let ef="application/x-halo-path";function eg(e){let{depth:t,initialValue:r,iconKind:a,onCommit:n,onCancel:o}=e,i=(0,l.useRef)(null),[c,d]=(0,l.useState)(r),u=(0,l.useRef)(!1);(0,l.useEffect)(()=>{let e=i.current;if(!e)return;e.focus();let t=r.lastIndexOf(".");"file"===a&&t>0?e.setSelectionRange(0,t):e.select()},[r,a]);let x="folder"===a?_.A:O.A;return(0,s.jsxs)("div",{className:"flex w-full items-center gap-1 py-1 text-xs",style:{paddingLeft:"".concat(12*t+8,"px")},children:[(0,s.jsx)("span",{className:"w-3.5 shrink-0"}),(0,s.jsx)(x,{className:D("h-3.5 w-3.5 shrink-0","folder"===a?"text-blue-400":"fill-[var(--muted-foreground)] text-[var(--muted-foreground)]")}),(0,s.jsx)("input",{ref:i,type:"text",value:c,onChange:e=>d(e.target.value),onKeyDown:e=>{"Enter"===e.key?(e.preventDefault(),u.current=!0,n(c)):"Escape"===e.key&&(e.preventDefault(),u.current=!0,o()),e.stopPropagation()},onBlur:()=>{u.current||(""===c.trim()?o():n(c))},className:"min-w-0 flex-1 rounded border border-[var(--primary)] bg-[var(--background)] px-1 py-0 text-xs text-[var(--foreground)] outline-none"})]})}async function ev(e){let t=e.items;if(t&&t.length>0){let e=[];for(let n=0;n<t.length;n++){var r,a;let s=null==(r=(a=t[n]).webkitGetAsEntry)?void 0:r.call(a);s&&e.push(s)}if(e.some(e=>e.isDirectory)){let t=[];async function n(e,r){if(e.isFile){let a=await new Promise((t,r)=>e.file(t,r)),n=r?"".concat(r,"/").concat(e.name):e.name;t.push(new File([a],n,{type:a.type,lastModified:a.lastModified}))}else if(e.isDirectory){let t,a=e.createReader(),s=r?"".concat(r,"/").concat(e.name):e.name;do for(let e of t=await function(e){return new Promise((t,r)=>e.readEntries(t,r))}(a))await n(e,s);while(t.length>0)}}for(let t of e)await n(t,"");return t}}return Array.from(e.files)}function eb(e){var t,r,a,n,o;let{node:i,projectId:c,onSelect:d,onContextMenu:u,onDropFiles:x,onMoveFile:m,selectedPaths:p,onSelectionChange:h,lastAnchor:f,visiblePaths:v,depth:b,pendingEdit:j,onCommitEdit:y,onCancelEdit:N}=e,k=g(),[C,A]=(0,l.useState)(()=>{var e;return!!i.path&&(e=i.path,em().has(e))}),[T,F]=(0,l.useState)(!1),[M,P]=(0,l.useState)(!1),L=(0,l.useRef)(null),R=(0,l.useRef)(null),z="directory"===i.type,K=z&&!1!==i.hasChildren&&void 0===i.children,G=(0,l.useRef)(C),J=(0,l.useCallback)(e=>{A(e),i.path&&eh(i.path,e)},[i.path]);(0,l.useEffect)(()=>{if(i.path){var e,t;let r;return e=i.path,t=e=>A(e),(r=ex.get(e))||(r=new Set,ex.set(e,r)),r.add(t),()=>{let r=ex.get(e);r&&(r.delete(t),0===r.size&&ex.delete(e))}}},[i.path]),(0,l.useEffect)(()=>{let e=G.current;G.current=C,C&&!M&&i.path&&(K||!e)&&(P(!0),w(c,i.path,k).finally(()=>P(!1)))},[C,K,M,i.path,c,k]);let q=k(e=>e.modifiedPaths),Z=k(e=>e.activeTab),V=E(e=>{var t;return null!=(t=c?e.byProject[c]:void 0)?t:I});if(0===b&&!i.path){let e=(0,l.useCallback)(()=>(function e(t){var r,a;let n=[];if(t.path&&n.push(t.path),"directory"===t.type&&t.children&&(!t.path||(r=t.path,em().has(r))))for(let r of[...null!=(a=t.children)?a:[]].sort((e,t)=>e.type!==t.type?"directory"===e.type?-1:1:e.name.localeCompare(t.name)))n.push(...e(r));return n})(i),[i])(),t=async e=>{e.preventDefault(),e.stopPropagation(),F(!1);let t=e.dataTransfer.getData(ef);if(t){null==m||m(t,"");return}let r=await ev(e.dataTransfer);r.length>0&&(null==x||x(r,""))},a=j&&""===j.parentDir&&"rename"!==j.mode;return(0,s.jsxs)("div",{"data-file-tree-root":"true",onClick:e=>{e.target===e.currentTarget&&h&&h(new Set,"")},onContextMenu:e=>{e.target===e.currentTarget&&(e.preventDefault(),null==u||u({x:e.clientX,y:e.clientY,path:"",name:"/",isDir:!0}))},onDragOver:e=>{(e.dataTransfer.types.includes("Files")||e.dataTransfer.types.includes(ef))&&(e.preventDefault(),e.stopPropagation(),F(!0))},onDragLeave:e=>{e.currentTarget===e.target&&F(!1)},onDrop:t,className:D("min-h-full",T&&"bg-[var(--accent)]/30"),children:[a&&j&&(0,s.jsx)(eg,{depth:0,initialValue:"",iconKind:"create-folder"===j.mode?"folder":"file",onCommit:e=>null==y?void 0:y(e),onCancel:()=>null==N?void 0:N()}),null==(r=i.children)?void 0:r.sort((e,t)=>e.type!==t.type?"directory"===e.type?-1:1:e.name.localeCompare(t.name)).map(t=>(0,s.jsx)(eb,{node:t,projectId:c,onSelect:d,onContextMenu:u,onDropFiles:x,onMoveFile:m,selectedPaths:p,onSelectionChange:h,lastAnchor:f,visiblePaths:e,depth:0,pendingEdit:j,onCommitEdit:y,onCancelEdit:N},t.path))]})}let Y=q.has(i.path),$=Z===i.path,Q=null!=(a=null==p?void 0:p.has(i.path))&&a,{Icon:X,color:ee}=ec(i.path),et=z?V.dirs.get(i.path):V.files.get(i.path),er=et&&"*"!==et?S(et):null,ea="*"===et?"#8C8C8C":null==er?void 0:er.color,en=!et&&function(e,t){if(0===e.size)return!1;if(e.has(t))return!0;for(let r of e)if(t.startsWith(r+"/"))return!0;return!1}(V.ignored,i.path),es=()=>{R.current&&(clearTimeout(R.current),R.current=null)},el=async e=>{if(!z)return;e.preventDefault(),e.stopPropagation(),F(!1),es(),C||J(!0);let t=e.dataTransfer.getData(ef);if(t){try{for(let e of JSON.parse(t))e===i.path||e.startsWith(i.path+"/")||null==m||m(e,i.path)}catch(e){t===i.path||t.startsWith(i.path+"/")||null==m||m(t,i.path)}return}let r=await ev(e.dataTransfer);r.length>0&&(null==x||x(r,i.path))},eo=z&&(null==(t=i.children)?void 0:t.some(e=>{let t=e=>{var r,a;return!!q.has(e.path)||null!=(a=null==(r=e.children)?void 0:r.some(t))&&a};return t(e)})),ei=j&&"rename"===j.mode&&j.originalPath===i.path,ed=j&&"rename"!==j.mode&&j.parentDir===i.path&&z;return ei&&j?(0,s.jsx)(eg,{depth:b,initialValue:null!=(n=j.originalName)?n:i.name,iconKind:z?"folder":"file",onCommit:e=>null==y?void 0:y(e),onCancel:()=>null==N?void 0:N()}):(0,s.jsxs)("div",{children:[(0,s.jsxs)("button",{draggable:!0,onClick:e=>{if(e.stopPropagation(),z&&!e.ctrlKey&&!e.metaKey&&!e.shiftKey){h&&h(new Set([i.path]),i.path),J(!C);return}if(e.shiftKey&&h&&v&&f){let e=v.indexOf(f),t=v.indexOf(i.path);if(e>=0&&t>=0){let r=Math.min(e,t),a=Math.max(e,t);h(new Set(v.slice(r,a+1)),f)}return}if((e.ctrlKey||e.metaKey)&&h){let e=new Set(p);e.has(i.path)?e.delete(i.path):e.add(i.path),h(e,i.path);return}z||(h&&h(new Set([i.path]),i.path),L.current&&clearTimeout(L.current),L.current=setTimeout(()=>{L.current=null,d(i.path)},300))},onDoubleClick:e=>{e.stopPropagation(),L.current&&(clearTimeout(L.current),L.current=null),z?J(!C):d(i.path)},onDragStart:e=>{p&&p.size>1&&p.has(i.path)?e.dataTransfer.setData(ef,JSON.stringify([...p])):e.dataTransfer.setData(ef,JSON.stringify([i.path])),e.dataTransfer.effectAllowed="move"},onContextMenu:e=>{e.preventDefault(),e.stopPropagation(),!Q&&h&&h(new Set([i.path]),i.path),null==u||u({x:e.clientX,y:e.clientY,path:i.path,name:i.name,isDir:z})},onDragOver:e=>{z&&(e.dataTransfer.types.includes("Files")||e.dataTransfer.types.includes(ef))&&(e.preventDefault(),e.stopPropagation(),e.dataTransfer.dropEffect="move",F(!0),C||R.current||(R.current=setTimeout(()=>{R.current=null,J(!0)},600)))},onDragLeave:()=>{F(!1),es()},onDrop:el,className:D("flex w-full items-center gap-1 py-1 text-left text-xs transition-colors hover:bg-[var(--secondary)]",Q&&"bg-[var(--primary)]/20 text-[var(--foreground)]",!Q&&$&&"bg-[var(--accent)] text-[var(--accent-foreground)]",!Q&&!$&&"text-[var(--foreground)]",T&&z&&"bg-[var(--accent)] ring-1 ring-[var(--primary)]"),style:{paddingLeft:"".concat(12*b+8,"px")},children:[z&&(0,s.jsx)("span",{className:"shrink-0 text-[var(--muted-foreground)]",children:C?(0,s.jsx)(W.A,{className:"h-3.5 w-3.5"}):(0,s.jsx)(U.A,{className:"h-3.5 w-3.5"})}),!z&&(0,s.jsx)("span",{className:"w-3.5 shrink-0"}),z?C?(0,s.jsx)(B.A,{className:D("h-3.5 w-3.5 shrink-0 text-blue-400",en&&"opacity-60")}):(0,s.jsx)(_.A,{className:D("h-3.5 w-3.5 shrink-0 text-blue-400",en&&"opacity-60")}):(0,s.jsx)(X,{className:D("h-3.5 w-3.5 shrink-0",ee,en&&"opacity-60")}),(0,s.jsx)("span",{className:D("truncate",en&&"text-[var(--muted-foreground)] opacity-60"),style:ea?{color:ea}:void 0,children:i.name}),(0,s.jsxs)("span",{className:"ml-auto flex shrink-0 items-center gap-1 pl-1 pr-2",children:[(Y||eo)&&(0,s.jsx)(O.A,{className:"h-1.5 w-1.5 shrink-0 fill-amber-400 text-amber-400"}),z?ea&&(0,s.jsx)(O.A,{className:"h-1.5 w-1.5 shrink-0",style:{fill:ea,color:ea}}):er&&(0,s.jsx)("span",{className:"w-3 text-center font-mono text-[11px] font-semibold",style:{color:er.color},title:er.label,children:er.letter})]})]}),z&&C&&M&&!i.children&&(0,s.jsxs)("div",{className:"flex items-center gap-1.5 py-1 text-[10px] text-[var(--muted-foreground)]",style:{paddingLeft:"".concat((b+1)*12+8,"px")},children:[(0,s.jsx)(H.A,{className:"h-3 w-3 animate-spin"}),(0,s.jsx)("span",{children:"Loading..."})]}),z&&C&&(i.children||ed)&&(0,s.jsxs)("div",{children:[ed&&j&&(0,s.jsx)(eg,{depth:b+1,initialValue:"",iconKind:"create-folder"===j.mode?"folder":"file",onCommit:e=>null==y?void 0:y(e),onCancel:()=>null==N?void 0:N()}),(null!=(o=i.children)?o:[]).sort((e,t)=>e.type!==t.type?"directory"===e.type?-1:1:e.name.localeCompare(t.name)).map(e=>(0,s.jsx)(eb,{node:e,projectId:c,onSelect:d,onContextMenu:u,onDropFiles:x,onMoveFile:m,selectedPaths:p,onSelectionChange:h,lastAnchor:f,visiblePaths:v,depth:b+1,pendingEdit:j,onCommitEdit:y,onCancelEdit:N},e.path))]})]})}var ej=r(90429),ey=r(93717),ew=r(93247),eN=r(35179),ek=r(34633),eS=r(17612),eC=r(19869);function eA(e){let{x:t,y:r,path:a,name:n,isDir:o,selectedCount:i,onAction:c,onClose:d}=e,u=(0,l.useRef)(null),[x,m]=(0,l.useState)({x:t,y:r});(0,l.useEffect)(()=>{function e(e){u.current&&!u.current.contains(e.target)&&d()}function t(e){"Escape"===e.key&&d()}return document.addEventListener("mousedown",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",t)}},[d]),(0,l.useLayoutEffect)(()=>{let e=u.current;if(!e)return;let a=e.getBoundingClientRect(),n=window.innerWidth,s=window.innerHeight,l=t+a.width+4>n?Math.max(4,n-a.width-4):t,o=r+a.height+4>s?Math.max(4,s-a.height-4):r;(l!==x.x||o!==x.y)&&m({x:l,y:o})},[t,r,x.x,x.y]);let p={position:"fixed",left:x.x,top:x.y,zIndex:9999};if(void 0!==i&&i>1)return(0,s.jsxs)("div",{ref:u,style:p,className:"min-w-[140px] rounded-md border border-[var(--border)] bg-[var(--card)] py-1 shadow-lg",children:[(0,s.jsxs)("div",{className:"truncate border-b border-[var(--border)] px-3 py-1.5 text-[10px] text-[var(--muted-foreground)]",children:[i," items selected"]}),(0,s.jsxs)("button",{onClick:()=>{c({type:"delete",path:a,isDir:o}),d()},className:"flex w-full items-center gap-2 px-3 py-1.5 text-xs text-red-400 transition-colors hover:bg-[var(--secondary)] hover:text-red-300",children:[(0,s.jsx)(ej.A,{className:"h-3.5 w-3.5"}),"Delete ",i," items"]})]});let h=""===a&&o,f=!!window.haloReveal,g=h?[{icon:ey.A,label:"New File...",type:"new-file"},{icon:ew.A,label:"New Folder...",type:"new-folder"},{icon:$.A,label:"Open in Integrated Terminal",type:"open-terminal"},...f?[{icon:eN.A,label:"Reveal in File Manager",type:"reveal-in-file-manager"}]:[]]:[{icon:ey.A,label:"New File...",type:"new-file",separatorAfter:!1},{icon:ew.A,label:"New Folder...",type:"new-folder",separatorAfter:!1},{icon:$.A,label:"Open in Integrated Terminal",type:"open-terminal",separatorAfter:!f},...f?[{icon:eN.A,label:"Reveal in File Manager",type:"reveal-in-file-manager",separatorAfter:!0}]:[],...o?[]:[{icon:ek.A,label:"Open to the Side",type:"open-to-side",separatorAfter:!1},{icon:eS.A,label:"Download",type:"download"}],{icon:eC.A,label:"Rename",type:"rename"},{icon:ej.A,label:"Delete",type:"delete",danger:!0,separatorAfter:o},...o?[{icon:B.A,label:"Open as Workspace",type:"open-as-workspace"}]:[]];return(0,s.jsxs)("div",{ref:u,style:p,className:"min-w-[140px] rounded-md border border-[var(--border)] bg-[var(--card)] py-1 shadow-lg",children:[(0,s.jsx)("div",{className:"truncate border-b border-[var(--border)] px-3 py-1.5 text-[10px] text-[var(--muted-foreground)]",children:n}),g.map(e=>{let t=e.icon;return(0,s.jsxs)("div",{children:[(0,s.jsxs)("button",{onClick:()=>{c({type:e.type,path:a,isDir:o}),d()},className:"flex w-full items-center gap-2 px-3 py-1.5 text-xs transition-colors hover:bg-[var(--secondary)] ".concat(e.danger?"text-red-400 hover:text-red-300":"text-[var(--foreground)]"),children:[(0,s.jsx)(t,{className:"h-3.5 w-3.5"}),e.label]}),e.separatorAfter&&(0,s.jsx)("div",{className:"my-1 border-t border-[var(--border)]"})]},e.type)})]})}var eI=r(70812);eI.wG.config({paths:{vs:"/monaco/vs"}});var eE=r(59391);let eT={dark:"vs-dark",light:"vs",midnight:"halo-midnight",warm:"halo-warm"},eF=!1;function eD(e){eF||(eF=!0,e.editor.defineTheme("halo-midnight",{base:"vs-dark",inherit:!0,rules:[],colors:{"editor.background":"#0b1220","editor.foreground":"#dbe4f3","editor.lineHighlightBackground":"#111a2e","editorLineNumber.foreground":"#3d4f78"}}),e.editor.defineTheme("halo-warm",{base:"vs",inherit:!0,rules:[],colors:{"editor.background":"#f6f1e7","editor.foreground":"#3d3427","editor.lineHighlightBackground":"#efe7d8","editorLineNumber.foreground":"#a89878"}}))}function eM(e){let{path:t,content:r,language:a,onChange:n,onSave:o,onClose:i}=e,c=g(),d=(0,l.useRef)(null),{theme:u}=(0,eE.useTheme)(),x=(0,l.useRef)(o),m=(0,l.useRef)(i),p=(0,l.useRef)(r);(0,l.useEffect)(()=>{x.current=o,m.current=i,p.current=r},[o,i,r]),(0,l.useEffect)(()=>()=>{c.getState().setSelectedText(null,null)},[t]);let h=(0,l.useCallback)(e=>{void 0!==e&&n&&n(e)},[n]),f=(0,l.useCallback)((e,t)=>{d.current=e;let r=e.getModel();r&&r.getValue()!==p.current&&r.setValue(p.current),e.onDidChangeCursorSelection(t=>{var r,a;let n=e.getSelection();if(!n||n.isEmpty())return void c.getState().setSelectedText(null,null);let s=null!=(a=null==(r=e.getModel())?void 0:r.getValueInRange(n))?a:null;s&&c.getState().setSelectedText(s,{startLine:n.startLineNumber,endLine:n.endLineNumber})}),e.addAction({id:"halo-save",label:"Save File",keybindings:[t.KeyMod.CtrlCmd|t.KeyCode.KeyS],run:()=>{var e;null==(e=x.current)||e.call(x)}}),e.addAction({id:"halo-close-tab",label:"Close Tab",keybindings:[t.KeyMod.Alt|t.KeyCode.KeyW],run:()=>{var e;null==(e=m.current)||e.call(m)}})},[]);return(0,s.jsx)(eI.Ay,{path:t,keepCurrentModel:!0,height:"100%",language:a,value:r,onChange:h,beforeMount:eD,onMount:f,theme:eT[u],options:{fontSize:13,lineHeight:20,fontFamily:"'JetBrains Mono', 'Fira Code', 'Cascadia Code', Menlo, Monaco, monospace",minimap:{enabled:!1},scrollBeyondLastLine:!1,wordWrap:"on",tabSize:2,renderLineHighlight:"line",cursorBlinking:"smooth",smoothScrolling:!0,padding:{top:12,bottom:12},bracketPairColorization:{enabled:!0},automaticLayout:!0,overviewRulerLanes:0,hideCursorInOverviewRuler:!0,overviewRulerBorder:!1,scrollbar:{verticalScrollbarSize:6,horizontalScrollbarSize:6}},loading:(0,s.jsx)("div",{className:"flex h-full items-center justify-center bg-[var(--background)]",children:(0,s.jsx)("span",{className:"text-sm text-[var(--muted-foreground)]",children:"Loading editor..."})})})}var eP=r(40549),eL=r(29978),eR=r(87917),ez=r(28687);function e_(e){let{content:t,filePath:r,projectId:a}=e,n=g(),o=(0,l.useRef)(null),i=(0,l.useMemo)(()=>(function(e){let t=[],r=new Map,a=!1;for(let s of e.split("\n")){var n;let e=s.trimEnd();if(/^\s*(```|~~~)/.test(e)){a=!a;continue}if(a)continue;let l=/^(#{1,6})\s+(.+?)\s*#*$/.exec(e);if(!l)continue;let o=l[1].length,i=l[2].trim(),c=i.trim().toLowerCase().replace(/[^\w一-鿿\s-]/g,"").replace(/\s+/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"")||"section",d=null!=(n=r.get(c))?n:0;r.set(c,d+1),d>0&&(c="".concat(c,"-").concat(d)),t.push({level:o,text:i,slug:c})}return t})(t),[t]),c=0,d=e=>{let t=o.current;if(!t)return;let r=t.querySelector("#".concat(CSS.escape(e)));r&&r.scrollIntoView({behavior:"smooth",block:"start"})},[u,x]=(0,l.useState)(()=>{try{return"1"===localStorage.getItem("halo.mdOutlineHidden")}catch(e){return!1}}),m=()=>{x(e=>{let t=!e;try{localStorage.setItem("halo.mdOutlineHidden",t?"1":"0")}catch(e){}return t})};(0,l.useEffect)(()=>{let e=o.current;if(!e)return;let t=n.getState().setSelectedText;function r(){let r=window.getSelection();if(!r||0===r.rangeCount)return;let a=r.getRangeAt(0);if(!(e&&e.contains(a.commonAncestorContainer)))return;if(r.isCollapsed)return void t(null,null);let n=r.toString();if(!n.trim())return void t(null,null);t(n,null)}return document.addEventListener("selectionchange",r),()=>{document.removeEventListener("selectionchange",r),t(null,null)}},[n]);let p=e=>function(t){var r;let{children:a}=t;return(0,s.jsx)(e,{id:null==(r=i[c++])?void 0:r.slug,children:a})};return(0,s.jsxs)("div",{className:"flex h-full bg-[var(--background)]",children:[i.length>1&&!u&&(0,s.jsxs)("nav",{className:"hidden w-56 shrink-0 flex-col overflow-y-auto border-r border-[var(--border)] py-4 md:flex",children:[(0,s.jsxs)("div",{className:"flex shrink-0 items-center justify-between px-3 pb-2",children:[(0,s.jsx)("span",{className:"text-[10px] font-medium uppercase tracking-wide text-[var(--muted-foreground)]",children:"Outline"}),(0,s.jsx)("button",{onClick:m,title:"Hide outline",className:"text-[var(--muted-foreground)] hover:text-[var(--foreground)]",children:(0,s.jsx)(eR.A,{className:"h-3.5 w-3.5"})})]}),i.map((e,t)=>(0,s.jsx)("button",{onClick:()=>d(e.slug),title:e.text,className:"block w-full shrink-0 truncate px-3 py-1 text-left text-xs text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",style:{paddingLeft:"".concat(.75+(e.level-1)*.75,"rem")},children:e.text},"".concat(e.slug,"-").concat(t)))]}),(0,s.jsxs)("div",{ref:o,className:"relative flex-1 overflow-y-auto px-8 py-6",children:[i.length>1&&u&&(0,s.jsx)("button",{onClick:m,title:"Show outline",className:"absolute left-2 top-2 z-10 hidden rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)] md:block",children:(0,s.jsx)(ez.A,{className:"h-4 w-4"})}),(0,s.jsx)("article",{className:"prose prose-invert prose-sm max-w-none prose-headings:text-[var(--foreground)] prose-headings:font-semibold prose-headings:scroll-mt-4 prose-h1:text-2xl prose-h1:border-b prose-h1:border-[var(--border)] prose-h1:pb-2 prose-h2:text-xl prose-h2:border-b prose-h2:border-[var(--border)] prose-h2:pb-1.5 prose-h3:text-lg prose-p:text-[var(--foreground)] prose-p:leading-relaxed prose-a:text-blue-400 prose-a:no-underline hover:prose-a:underline prose-strong:text-[var(--foreground)] prose-code:text-amber-300 prose-code:bg-[var(--secondary)] prose-code:px-1.5 prose-code:py-0.5 prose-code:rounded prose-code:text-xs prose-code:before:content-none prose-code:after:content-none prose-pre:bg-[var(--secondary)] prose-pre:border prose-pre:border-[var(--border)] prose-pre:rounded-lg prose-blockquote:border-l-blue-500 prose-blockquote:text-[var(--muted-foreground)] prose-li:text-[var(--foreground)] prose-th:text-[var(--foreground)] prose-td:text-[var(--foreground)] prose-table:border-collapse prose-th:border prose-th:border-[var(--border)] prose-th:px-3 prose-th:py-1.5 prose-th:bg-[var(--secondary)] prose-td:border prose-td:border-[var(--border)] prose-td:px-3 prose-td:py-1.5 prose-hr:border-[var(--border)] prose-img:rounded-lg ",children:(0,s.jsx)(eP.oz,{remarkPlugins:[eL.A],components:{h1:p("h1"),h2:p("h2"),h3:p("h3"),h4:p("h4"),h5:p("h5"),h6:p("h6"),a(e){let{href:t,children:r,node:a,...n}=e;return(null==t?void 0:t.startsWith("#"))?(0,s.jsx)("a",{href:t,onClick:e=>{e.preventDefault();let r=t.slice(1);try{r=decodeURIComponent(r)}catch(e){}d(r)},...n,children:r}):(0,s.jsx)("a",{href:t,target:"_blank",rel:"noopener noreferrer",...n,children:r})},img(e){let{src:t,alt:n,node:l,...o}=e,i=function(e,t,r){let a;if(!e)return null;if(/^(https?:|data:|blob:)/i.test(e))return e;if(!r)return null;if(e.startsWith("/"))a=e;else{if(!t)return null;let n=t.includes("/")?t.slice(0,t.lastIndexOf("/")):"",s=n?"".concat(n,"/").concat(e):e,l=[];for(let e of s.split("/"))""!==e&&"."!==e&&(".."===e?l.pop():l.push(e));a="".concat(r.replace(/\/$/,""),"/").concat(l.join("/"))}let n=new URLSearchParams;return n.set("path",a),n.set("projectId",r),n.set("inline","1"),"/api/files/download?".concat(n.toString())}("string"==typeof t?t:"",r,a);return i?(0,s.jsx)("img",{src:i,alt:null!=n?n:"",...o}):(0,s.jsxs)("span",{className:"rounded border border-[var(--border)] bg-[var(--secondary)]/30 px-2 py-1 text-xs text-[var(--muted-foreground)]",children:["[image unavailable: ",n||String(t),"]"]})}},children:t})})]})]})}let eO=new Set;function eW(e){for(let r of eO)try{var t;null==(t=r.contentWindow)||t.postMessage({haloFace:e},"*")}catch(e){}}function eU(e){let{url:t,name:r}=e,a=(0,l.useRef)(null);return(0,l.useEffect)(()=>{if(a.current){var e;return e=a.current,eO.add(e),()=>{eO.delete(e)}}},[]),(0,s.jsx)("iframe",{ref:a,src:t,title:r,className:"h-full w-full border-0 bg-white",sandbox:"allow-scripts allow-same-origin",allow:"autoplay"})}function eB(e){let{original:t,modified:r,path:a}=e,n=z(a),{theme:l}=(0,eE.useTheme)();return(0,s.jsx)(eI.zC,{height:"100%",language:n,original:t,modified:r,beforeMount:eD,theme:eT[l],options:{fontSize:13,lineHeight:20,fontFamily:"'JetBrains Mono', 'Fira Code', 'Cascadia Code', Menlo, Monaco, monospace",minimap:{enabled:!1},scrollBeyondLastLine:!1,readOnly:!0,renderSideBySide:!0,padding:{top:12,bottom:12},automaticLayout:!0,overviewRulerLanes:0,scrollbar:{verticalScrollbarSize:6,horizontalScrollbarSize:6}},loading:(0,s.jsx)("div",{className:"flex h-full items-center justify-center bg-[var(--background)]",children:(0,s.jsx)("span",{className:"text-sm text-[var(--muted-foreground)]",children:"Loading diff..."})})})}var eH=r(38067),eK=r(61648),eG=r(30865),eJ=r(84099);function eq(e){var t,r;let{x:a,y:n,path:o,groupIdx:i,onClose:c,onCloseTab:d}=e,u=g(),x=(0,l.useRef)(null);(0,l.useEffect)(()=>{function e(e){x.current&&!x.current.contains(e.target)&&c()}return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[c]);let m=u.getState(),p=(null!=(r=null==(t=m.groups[i])?void 0:t.tabs)?r:[]).map(e=>m.buffers[e]).filter(e=>!!e),h=p.findIndex(e=>e.path===o),f=[{label:"Close",action:()=>d(o)},{label:"Close Others",action:()=>{p.forEach(e=>{e.path!==o&&d(e.path)})},disabled:p.length<=1},{label:"Close to the Right",action:()=>{p.slice(h+1).forEach(e=>d(e.path))},disabled:h>=p.length-1},{label:"Close Saved",action:()=>{p.forEach(e=>{e.modified||d(e.path)})}},{label:"Close All",action:()=>{p.forEach(e=>d(e.path))}}];return(0,s.jsx)("div",{ref:x,className:"fixed z-50 min-w-[160px] rounded-md border border-[var(--border)] bg-[var(--card)] py-1 shadow-lg",style:{left:a,top:n},children:f.map((e,t)=>(0,s.jsx)("button",{disabled:e.disabled,onClick:()=>{e.action(),c()},className:D("w-full px-3 py-1.5 text-left text-xs transition-colors",e.disabled?"text-[var(--muted-foreground)]/40 cursor-default":"text-[var(--foreground)] hover:bg-[var(--secondary)]"),children:e.label},t))})}let eZ="application/x-halo-tab";function eV(e){let{tabs:t,activeTab:r,groupIdx:a,canSplit:n,onCloseTab:o,renderMode:i,onToggleRenderMode:c,showDiffButton:d,onToggleDiff:u}=e,x=g(),m=(0,l.useRef)(null),[p,h]=(0,l.useState)(!1),[f,v]=(0,l.useState)(!1),[b,j]=(0,l.useState)(null),[y,w]=(0,l.useState)(null),[N,k]=(0,l.useState)(!1),[S,C]=(0,l.useState)(null),A=function(e){var t,r,a,n;let s=new Map,l=new Map;for(let a of e){let e=null!=(t=a.path.split("/").pop())?t:a.path;l.set(e,(null!=(r=l.get(e))?r:0)+1)}for(let t of e){let e=t.path.split("/"),r=null!=(a=e.pop())?a:t.path;(null!=(n=l.get(r))?n:0)>1&&e.length>0?s.set(t.path,"".concat(e[e.length-1],"/").concat(r)):s.set(t.path,r)}return s}(t),I=(0,l.useCallback)(()=>{let e=m.current;e&&(h(e.scrollLeft>0),v(e.scrollLeft+e.clientWidth<e.scrollWidth-1))},[]);(0,l.useEffect)(()=>{I();let e=m.current;if(!e)return;e.addEventListener("scroll",I);let t=new ResizeObserver(I);return t.observe(e),()=>{e.removeEventListener("scroll",I),t.disconnect()}},[I,t.length]);let E=e=>{var t;null==(t=m.current)||t.scrollBy({left:e,behavior:"smooth"})},T=()=>{j(null),w(null),k(!1)},F=x(e=>e.activeGroupIdx);return(0,s.jsxs)("div",{className:D("relative flex shrink-0 items-center border-b border-[var(--border)] bg-[var(--card)]",N&&"ring-1 ring-[var(--primary)]"),onDragOver:e=>{if(!eY(e))return;let t=e.dataTransfer.types.includes(eZ)?{srcGroupIdx:-1,path:""}:null;t&&t.srcGroupIdx!==a&&(e.preventDefault(),e.dataTransfer.dropEffect="move",k(!0))},onDragLeave:e=>{e.currentTarget===e.target&&k(!1)},onDrop:e=>{if(!eY(e))return;e.preventDefault();let t=e$(e);t&&t.srcGroupIdx!==a&&x.getState().moveTabToGroup(t.srcGroupIdx,t.path,a),j(null),w(null),k(!1)},onMouseDown:()=>x.getState().setActiveGroup(a),children:[p&&(0,s.jsx)("button",{onClick:()=>E(-150),className:"sticky left-0 z-10 flex h-full w-6 shrink-0 items-center justify-center bg-[var(--card)] text-[var(--muted-foreground)] hover:text-[var(--foreground)] border-r border-[var(--border)]",children:(0,s.jsx)(eH.A,{className:"h-3.5 w-3.5"})}),(0,s.jsx)("div",{ref:m,className:"flex flex-1 overflow-x-hidden",children:t.map((e,t)=>{var n;let{Icon:l,color:i}=ec(e.path),c=e.path===r&&a===F,d=e.path===r&&a!==F;return(0,s.jsxs)("div",{draggable:!0,onDragStart:r=>{var n;return n=e.path,j(t),r.dataTransfer.effectAllowed="move",r.dataTransfer.setData("text/plain",String(t)),void r.dataTransfer.setData(eZ,JSON.stringify({srcGroupIdx:a,path:n}))},onDragOver:e=>{eY(e)&&(e.preventDefault(),e.dataTransfer.dropEffect="move",w(t))},onDrop:e=>((e,t)=>{if(!eY(e))return;e.preventDefault();let r=e$(e);r&&x.getState().moveTabToGroup(r.srcGroupIdx,r.path,a,t),j(null),w(null),k(!1)})(e,t),onDragEnd:T,onContextMenu:t=>{t.preventDefault(),C({x:t.clientX,y:t.clientY,path:e.path})},className:D("group relative flex items-center gap-1.5 border-r border-[var(--border)] px-3 py-1.5 text-xs cursor-pointer transition-colors select-none",c?"bg-[var(--background)] text-[var(--foreground)]":d?"bg-[var(--background)]/50 text-[var(--muted-foreground)]":"text-[var(--muted-foreground)] hover:bg-[var(--secondary)]",b===t&&"opacity-40"),onClick:()=>{x.getState().setActiveTab(e.path,a),x.getState().setRejectedFile(null)},children:[y===t&&null!==b&&b>t&&(0,s.jsx)("div",{className:"absolute left-0 top-1 bottom-1 w-0.5 bg-[var(--primary)]"}),y===t&&null!==b&&b<t&&(0,s.jsx)("div",{className:"absolute right-0 top-1 bottom-1 w-0.5 bg-[var(--primary)]"}),(0,s.jsx)(l,{className:D("h-3.5 w-3.5 shrink-0",i)}),(0,s.jsx)("span",{className:"max-w-40 truncate",children:null!=(n=A.get(e.path))?n:e.path.split("/").pop()}),e.modified?(0,s.jsx)(O.A,{className:"h-2 w-2 fill-amber-400 text-amber-400 shrink-0"}):(0,s.jsx)("button",{onClick:t=>{t.stopPropagation(),o(e.path)},className:"ml-0.5 rounded p-0.5 opacity-0 transition-opacity group-hover:opacity-100 hover:bg-[var(--secondary)]",children:(0,s.jsx)(eK.A,{className:"h-3 w-3"})}),e.modified&&(0,s.jsx)("button",{onClick:t=>{t.stopPropagation(),o(e.path)},className:"ml-0.5 rounded p-0.5 opacity-0 transition-opacity group-hover:opacity-100 hover:bg-[var(--secondary)]",children:(0,s.jsx)(eK.A,{className:"h-3 w-3"})})]},e.path)})}),f&&(0,s.jsx)("button",{onClick:()=>E(150),className:"sticky right-0 z-10 flex h-full w-6 shrink-0 items-center justify-center bg-[var(--card)] text-[var(--muted-foreground)] hover:text-[var(--foreground)] border-l border-[var(--border)]",children:(0,s.jsx)(U.A,{className:"h-3.5 w-3.5"})}),(()=>{let e=t.find(e=>e.path===r),a=(null==e?void 0:e.language)==="markdown"||(null==e?void 0:e.language)==="html";return(0,s.jsxs)("div",{className:"flex items-center gap-0.5 mr-1",children:[a&&(0,s.jsxs)("button",{onClick:c,title:i?"Switch to source view":"Switch to rendered view",className:D("flex items-center gap-1 rounded px-1.5 py-1 text-[11px] transition-colors",i?"bg-[var(--secondary)] text-[var(--foreground)]":"text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]"),children:[i?(0,s.jsx)(eC.A,{className:"h-3 w-3"}):(0,s.jsx)(eG.A,{className:"h-3 w-3"}),(0,s.jsx)("span",{children:i?"Edit":"Preview"})]}),d&&(0,s.jsxs)("button",{onClick:u,title:"View unsaved diff",className:"flex items-center gap-1 rounded px-1.5 py-1 text-[11px] text-[var(--muted-foreground)] transition-colors hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:[(0,s.jsx)(eJ.A,{className:"h-3 w-3"}),(0,s.jsx)("span",{children:"Diff"})]})]})})(),n&&(0,s.jsx)("button",{title:"Split editor right",onClick:()=>x.getState().splitToRight(),className:"ml-1 mr-1 shrink-0 rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,s.jsx)(ek.A,{className:"h-3.5 w-3.5"})}),S&&(0,s.jsx)(eq,{x:S.x,y:S.y,path:S.path,groupIdx:a,onClose:()=>C(null),onCloseTab:o})]})}function eY(e){return e.dataTransfer.types.includes(eZ)}function e$(e){try{let t=e.dataTransfer.getData(eZ);if(!t)return null;return JSON.parse(t)}catch(e){return null}}let eQ=new Map;function eX(e){for(let t of e.extensions)eQ.set(t.toLowerCase(),e)}let e0={id:"pdf",extensions:["pdf"],Component:(0,l.lazy)(()=>r.e(65).then(r.bind(r,50065)).then(e=>({default:e.PdfPreview})))},e1={id:"docx",extensions:["docx","doc"],Component:(0,l.lazy)(()=>r.e(579).then(r.bind(r,37579)).then(e=>({default:e.DocxPreview})))},e5={id:"xlsx",extensions:["xlsx","xls","csv"],Component:(0,l.lazy)(()=>r.e(442).then(r.bind(r,36442)).then(e=>({default:e.XlsxPreview})))},e3={id:"pptx",extensions:["pptx","ppt"],Component:(0,l.lazy)(()=>Promise.all([r.e(819),r.e(868),r.e(533),r.e(525)]).then(r.bind(r,78525)).then(e=>({default:e.PptxPreview}))),heavy:!0};var e2=r(89759);function e4(){return(0,s.jsx)("div",{className:"flex h-full items-center justify-center text-sm text-[var(--muted-foreground)]",children:"Loading preview..."})}function e8(e){var t,r,a;let n=(a=null!=(r=null==(t=e.name.split(".").pop())?void 0:t.toLowerCase())?r:"",eQ.get(a.toLowerCase()));if(!n)return(0,s.jsx)(e6,{...e});let{Component:o}=n;return(0,s.jsx)(l.Suspense,{fallback:(0,s.jsx)(e4,{}),children:(0,s.jsx)(o,{...e})})}function e6(e){let{name:t,downloadUrl:r,onOpenAsText:a}=e;return(0,s.jsxs)("div",{className:"flex h-full flex-col items-center justify-center gap-4 bg-[var(--background)] p-8",children:[(0,s.jsx)("div",{className:"flex h-16 w-16 items-center justify-center rounded-full bg-[var(--secondary)]",children:(0,s.jsx)(el.A,{className:"h-8 w-8 text-[var(--muted-foreground)]"})}),(0,s.jsx)("p",{className:"text-sm font-medium text-[var(--foreground)]",children:t}),(0,s.jsx)("p",{className:"text-xs text-[var(--muted-foreground)]",children:"This file type does not support preview"}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[a&&(0,s.jsx)("button",{onClick:a,className:"inline-flex items-center gap-1.5 rounded-md border border-[var(--border)] bg-[var(--secondary)] px-4 py-2 text-xs font-medium text-[var(--foreground)] transition-colors hover:opacity-90",children:"Open as Text"}),(0,s.jsx)("a",{href:r,download:!0,className:"inline-flex items-center gap-1.5 rounded-md bg-[var(--primary)] px-4 py-2 text-xs font-medium text-[var(--primary-foreground)] transition-colors hover:opacity-90",children:"Download"})]})]})}eX(e0),eX(e1),eX(e5),eX(e3),eX(e2.SQ);let e9=(0,c.v)((e,t)=>({projects:[],activeProject:null,folderPath:"",setProjects(t){e({projects:t})},setActiveProject(t){e({activeProject:t})},setFolderPath(t){e({folderPath:t})},openFolder(r,a){var n;let s=r.trim();if(!s)return;let l=null!=(n=s.split("/").filter(Boolean).pop())?n:s,o={id:s,name:l,path:s,workspaceId:a,createdAt:Date.now()},i=t().projects;i.find(e=>e.path===s)||e({projects:[...i,o]}),e({activeProject:o,folderPath:s})}}));var e7=r(29241),te=r(97095),tt=r(98413),tr=r(8808);r(38045);var ta=r(87826);function tn(e){return new Date(e).toLocaleString(void 0,{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})}r(26967);let ts=new Set([...eQ.keys(),"tiff","tif","zip","tar","gz","bz2","xz","7z","rar","woff","woff2","ttf","otf","eot","exe","dll","so","dylib","o","a","class","pyc","wasm"]);function tl(e){var t;let{projectId:r,mode:a="full",showMaximize:n=!0}=e,o=(0,tr.useT)(),c=g(),d=c(e=>e.tabs),u=c(e=>e.activeTab),x=c(e=>e.buffers),m=c(e=>e.groups),h=c(e=>e.activeGroupIdx),f=c(e=>e.maximized),b="editor-only"===a,[w,N]=(0,l.useState)(!0),[k,S]=(0,l.useState)({}),[C,A]=(0,l.useState)({});function I(e){var t;return null==(t=C[e])||t}let[E,T]=(0,l.useState)(null),[F,M]=(0,l.useState)(new Set),[P,L]=(0,l.useState)(null),[_,O]=(0,l.useState)(null),[W,U]=(0,l.useState)(null),{tree:B,loading:H}=function(e){let t=g(),[r,a]=(0,l.useState)(!1),[n,s]=(0,l.useState)(null),o=t(e=>e.fileTree),i=(0,l.useCallback)(async()=>{if(e){a(!0),s(null);try{var r,n;let a=await v.F.files.tree(e),s={name:null!=(n=null!=(r=a.root)?r:e.split("/").filter(Boolean).pop())?n:"root",path:"",type:"directory",hasChildren:a.tree.length>0,children:a.tree};t.getState().setFileTree(s)}catch(e){s(e instanceof Error?e.message:"Failed to load file tree"),console.error("[useFileTree] Error:",e)}finally{a(!1)}}},[e,t]);return(0,l.useEffect)(()=>{e&&i()},[e,i]),(0,l.useEffect)(()=>{if(e)return j.on("file:changed",e=>{"add"===e.action||"addDir"===e.action?t.getState().insertFileNode(e.path,"addDir"===e.action?"directory":"file"):("unlink"===e.action||"unlinkDir"===e.action)&&t.getState().removeFileNode(e.path)})},[e,t]),{tree:o,loading:r,error:n,refresh:i}}(r),[K,G]=(0,l.useState)(!1),J=(0,l.useRef)(null),q=(0,l.useCallback)(e=>{var t,r,a,n;return a=null!=(r=null==(t=e.split(".").pop())?void 0:t.toLowerCase())?r:"",!!(null==(n=eQ.get(a.toLowerCase()))?void 0:n.heavy)},[]),[Z,V]=(0,l.useState)([]);(0,l.useEffect)(()=>{let e=[];for(let t of m){let r=t.activeTab;if(!r)continue;let a=x[r];(null==a?void 0:a.preview)&&(q(r)||e.push(r))}0!==e.length&&V(t=>{let r=t.slice();for(let t=e.length-1;t>=0;t--){let a=e[t];r=[a,...r.filter(e=>e!==a)]}return(r=r.slice(0,5),t.length===r.length&&t.every((e,t)=>e===r[t]))?t:r})},[m,x,q]),(0,l.useEffect)(()=>{V(e=>{let t=new Set;for(let e of m)for(let r of e.tabs)t.add(r);let r=e.filter(e=>t.has(e));return r.length===e.length?e:r})},[m]),(0,l.useEffect)(()=>{if(!r)return;J.current&&J.current!==r&&(c.setState(e=>{var t,r;return{buffers:{},groups:[{id:null!=(r=null==(t=e.groups[0])?void 0:t.id)?r:"g0",tabs:[],activeTab:null}],activeGroupIdx:0,tabs:[],activeTab:null,modifiedPaths:new Set}}),G(!1)),J.current=r;let e="halo_tabs:".concat(r),t=localStorage.getItem(e);if(!t)return void G(!0);let a=!1;return async function(){try{var e,n,s;let l=JSON.parse(t),o=null!=(n=l.groups)?n:l.tabs?[{tabs:l.tabs,activeTab:null!=(e=l.activeTab)?e:null}]:[],i=null!=(s=l.activeGroupIdx)?s:0;if(0===o.length)return void G(!0);let d=Array.from(new Set(o.flatMap(e=>e.tabs.map(e=>e.path)))),u=new Map;for(let e of o)for(let t of e.tabs)u.has(t.path)||u.set(t.path,t.language);let x=await Promise.all(d.map(async e=>{var t,a;let n=null!=(a=null==(t=e.split(".").pop())?void 0:t.toLowerCase())?a:"";if(ts.has(n))try{let t=await v.F.files.stat(e,r);return{path:e,content:"",originalContent:"",language:"",size:t.size,mtime:t.modifiedAt,createdAt:t.createdAt,preview:{downloadUrl:v.F.files.downloadUrl(e,r),viewUrl:v.F.files.viewUrl(e,r)}}}catch(e){return null}try{let t=await v.F.files.read(e,r);return{path:e,content:t.content,originalContent:t.content,language:u.get(e)||z(e),mtime:t.modifiedAt,size:t.size,createdAt:t.createdAt}}catch(e){return null}}));if(a)return;let m={};for(let e of x)e&&(m[e.path]=e);let p=o.map((e,t)=>{var r;let a=e.tabs.map(e=>e.path).filter(e=>m[e]),n=e.activeTab&&a.includes(e.activeTab)?e.activeTab:null!=(r=a[0])?r:null;return{id:"g_restored_".concat(t,"_").concat(Date.now().toString(36)),tabs:a,activeTab:n}}).filter(e=>e.tabs.length>0);if(0===p.length)c.setState(e=>{var t,r;return{buffers:{},groups:[{id:null!=(r=null==(t=e.groups[0])?void 0:t.id)?r:"g0",tabs:[],activeTab:null}],activeGroupIdx:0,tabs:[],activeTab:null}});else{let e=Math.max(0,Math.min(i,p.length-1)),t=p[e],r=t.tabs.map(e=>m[e]).filter(e=>!!e);c.setState({buffers:m,groups:p,activeGroupIdx:e,tabs:r,activeTab:t.activeTab})}}catch(e){}a||G(!0)}(),()=>{a=!0}},[r]),(0,l.useEffect)(()=>{if(!r||!K)return;let e=m.map(e=>({tabs:e.tabs.map(e=>{let t=x[e];return{path:e,isPreview:!!(null==t?void 0:t.preview),language:null==t?void 0:t.language}}),activeTab:e.activeTab}));localStorage.setItem("halo_tabs:".concat(r),JSON.stringify({groups:e,activeGroupIdx:h}))},[m,h,x,r,K]);let Y=d.find(e=>e.path===u),$=(0,l.useCallback)(()=>{let e=c.getState().activeTab;if(!e||!r)return;let t=c.getState().tabs.find(t=>t.path===e);t&&!t.preview&&v.F.files.stat(e,r).then(t=>{c.getState().checkAndRefresh(e,t.modifiedAt,()=>v.F.files.read(e,r))}).catch(()=>{})},[r]);(0,l.useEffect)(()=>{K&&$()},[u,$,K]);let Q=e9(e=>{var t;return null==(t=e.activeProject)?void 0:t.path});(0,l.useEffect)(()=>{if(r&&Q)return j.on("file:changed",e=>{if("change"!==e.action)return;let t="".concat(Q,"/").concat(e.path),a=r.endsWith("/")?r:"".concat(r,"/");if(!t.startsWith(a))return;let n=t.slice(a.length),s=c.getState().tabs.find(e=>e.path===n);!s||s.preview||s.modified||v.F.files.read(n,r).then(e=>{c.getState().checkAndRefresh(n,e.modifiedAt,async()=>({content:e.content,modifiedAt:e.modifiedAt}))}).catch(()=>{})})},[r,Q,c]),(0,l.useEffect)(()=>{let e=()=>$();return window.addEventListener("focus",e),()=>window.removeEventListener("focus",e)},[$]);let X=(0,l.useCallback)(async e=>{var t,a,n;if(!r)return;let s=null!=(a=null==(t=e.split(".").pop())?void 0:t.toLowerCase())?a:"";if(ts.has(s)){let t,a=v.F.files.downloadUrl(e,r),n=v.F.files.viewUrl(e,r);try{let a=await v.F.files.stat(e,r);t={size:a.size,mtime:a.modifiedAt,createdAt:a.createdAt}}catch(e){}c.getState().openPreview(e,a,n,t);return}if(c.getState().tabs.find(t=>t.path===e))return void c.getState().setActiveTab(e);try{let t=await v.F.files.read(e,r),a=z(e);c.getState().openFile(e,t.content,a,t.modifiedAt,{size:t.size,createdAt:t.createdAt})}catch(r){console.error("[EditorPanel] Failed to read file:",r);let t=r instanceof Error?r.message:String(r);if(t.includes("413")||t.includes("too large")){let t=null!=(n=e.split("/").pop())?n:e;alert('"'.concat(t,'" is too large to open in the editor (max 10MB).'))}}},[r]),ee=(0,l.useCallback)(async(e,t)=>{let r=c.getState(),a=r.buffers[t],n=r.groups.some((r,a)=>a!==e&&r.tabs.includes(t));(null==a||!a.modified||n||await R('"'.concat(t.split("/").pop(),'" has unsaved changes. Close anyway?')))&&c.getState().closeTabIn(e,t)},[]),et=(0,l.useCallback)(async e=>{if(r)try{let t=await v.F.files.read(e,r),a=z(e);c.getState().closeTab(e),c.getState().openFile(e,t.content,a,t.modifiedAt,{size:t.size,createdAt:t.createdAt})}catch(e){console.error("[EditorPanel] Failed to open as text:",e)}},[r]),er=(0,l.useCallback)((e,t)=>{c.getState().updateContent(e,t)},[]),ea=(0,l.useCallback)(async e=>{let t=null!=e?e:u;if(!t||!r)return;let a=c.getState().tabs.find(e=>e.path===t);if(a&&a.modified)try{let e=await v.F.files.save(t,a.content,r);c.getState().markSaved(t,e.modifiedAt)}catch(e){console.error("[EditorPanel] Failed to save file:",e)}},[r,u]),en=(0,l.useCallback)((e,t)=>{let r=c.getState().buffers[t];r&&S(a=>({...a,[e]:{original:r.originalContent,modified:r.content,path:t}}))},[]),es=(0,l.useCallback)(e=>{S(t=>({...t,[e]:null}))},[]),el=(0,l.useCallback)(async(e,t)=>{if(r){U({count:e.length,progress:0});try{await v.F.files.upload(e,r,t||void 0,(e,t)=>{t>0&&U(r=>r?{...r,progress:e/t*100}:null)}),U(e=>e?{...e,progress:100}:null),setTimeout(()=>U(null),400),y(r,c)}catch(e){U(null),console.error("[EditorPanel] Upload failed:",e),window.alert(e instanceof Error?e.message:"Upload failed")}}},[r]),eo=(0,l.useCallback)(async(e,t)=>{var a;if(!r)return;let n=null!=(a=e.split("/").pop())?a:"",s=t?"".concat(t,"/").concat(n):n;if(e!==s)try{await v.F.files.rename(e,s,r);let t=c.getState();t.tabs.find(t=>t.path===e)&&t.closeTab(e),y(r,c)}catch(e){console.error("[EditorPanel] Move failed:",e),window.alert(e instanceof Error?e.message:"Move failed")}},[r]),ei=(0,l.useCallback)((e,t)=>{M(e),t&&L(t)},[]),ec=(0,l.useCallback)(e=>{T(e)},[]),ed=(0,l.useCallback)(async e=>{var t,a,n,s,l;if(!r)return;let o=""===e.path&&e.isDir,i=(()=>{if(!o)return{path:e.path,isDir:e.isDir};if(0===F.size)return{path:"",isDir:!0};let t=F.values().next().value;return{path:t,isDir:function(e,t){if(!e||!t)return!0;let r=t.split("/").filter(Boolean),a=e;for(let e of r){var n;if(!(a=null==a||null==(n=a.children)?void 0:n.find(t=>t.name===e)))return!1}return"directory"===a.type}(B,t)}})(),d=i.isDir?i.path:i.path.includes("/")?i.path.substring(0,i.path.lastIndexOf("/")):"";if("new-file"===e.type||"new-folder"===e.type){d&&eh(d,!0),O({mode:"new-file"===e.type?"create-file":"create-folder",parentDir:d});return}if("open-to-side"===e.type){if(e.isDir)return;try{let s=null!=(a=null==(t=e.path.split(".").pop())?void 0:t.toLowerCase())?a:"",l=ts.has(s),o=c.getState();1===o.groups.length&&o.splitToRight(null!=(n=o.groups[0].activeTab)?n:e.path);let i=+(c.getState().groups.length>1);if(l){let t=await v.F.files.stat(e.path,r);c.getState().openFileInGroup(i,e.path,"","",t.modifiedAt,{size:t.size,createdAt:t.createdAt}),c.setState(t=>({buffers:{...t.buffers,[e.path]:{...t.buffers[e.path],preview:{downloadUrl:v.F.files.downloadUrl(e.path,r),viewUrl:v.F.files.viewUrl(e.path,r)}}}}))}else{let t=await v.F.files.read(e.path,r),a=z(e.path);c.getState().openFileInGroup(i,e.path,t.content,a,t.modifiedAt,{size:t.size,createdAt:t.createdAt})}}catch(e){console.error("[EditorPanel] Open to the side failed:",e),window.alert(e instanceof Error?e.message:"Open to the side failed")}return}if("open-terminal"===e.type){if(!Q)return;let e=d?"".concat(Q,"/").concat(d):Q;p.getState().requestTerminalSpawn(e),p.getState().setBottomTab("terminal");return}if("open-as-workspace"===e.type){if(!e.isDir||!Q)return;let t=e.path?"".concat(Q,"/").concat(e.path):Q;window.dispatchEvent(new CustomEvent("halo:open-workspace",{detail:{path:t}}));return}if("reveal-in-file-manager"===e.type){if(!Q)return;let t=window.haloReveal;if(!t)return;let r=e.path?"".concat(Q,"/").concat(e.path):Q;t.reveal(r,e.isDir);return}if("download"===e.type){let t=v.F.files.downloadUrl(e.path,r),a=document.createElement("a");a.href=t,a.download=null!=(s=e.path.split("/").pop())?s:"file",document.body.appendChild(a),a.click(),a.remove();return}if("rename"===e.type){let t=null!=(l=e.path.split("/").pop())?l:"";O({mode:"rename",parentDir:e.path.includes("/")?e.path.substring(0,e.path.lastIndexOf("/")):"",originalPath:e.path,originalName:t});return}if("delete"===e.type){let t=F.size>1&&F.has(e.path)?Array.from(F):[e.path];if(t.length>1){if(!await R("Delete ".concat(t.length," items?")))return}else{let t=e.isDir?"folder":"file";if(!await R("Delete ".concat(t,' "').concat(e.path.split("/").pop(),'"?')))return}try{for(let e of t)await v.F.files.remove(e,r),c.getState().closeTab(e);M(new Set),y(r,c)}catch(e){console.error("[EditorPanel] Delete failed:",e),window.alert(e instanceof Error?e.message:"Delete failed"),y(r,c)}}},[r,F]),eu=(0,l.useCallback)(()=>{O(null)},[]),ex=(0,l.useCallback)(async e=>{if(!r||!_)return;let t=e.trim();if(""===t)return void O(null);let{mode:a,parentDir:n,originalPath:s,originalName:l}=_;if("rename"===a){if(!s||t===l)return void O(null);let e=n?"".concat(n,"/").concat(t):t;try{await v.F.files.rename(s,e,r),c.getState().closeTab(s),y(r,c)}catch(e){console.error("[EditorPanel] Rename failed:",e),window.alert(e instanceof Error?e.message:"Rename failed")}return void O(null)}let o=n?"".concat(n,"/").concat(t):t;try{"create-file"===a?await v.F.files.create(o,r):await v.F.files.mkdir(o,r),y(r,c)}catch(e){console.error("[EditorPanel] Create failed:",e),window.alert(e instanceof Error?e.message:"Create failed")}O(null)},[r,_,c]);(0,l.useEffect)(()=>{function e(e){var t,r;if("Enter"!==e.key||_||1!==F.size)return;let a=e.target;if(!(null==a||null==(t=a.closest)?void 0:t.call(a,"[data-file-tree-root]")))return;let n=F.values().next().value,s=null!=(r=n.split("/").pop())?r:"";O({mode:"rename",parentDir:n.includes("/")?n.substring(0,n.lastIndexOf("/")):"",originalPath:n,originalName:s})}return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[F,_]);let em=W&&(0,s.jsxs)("div",{className:"shrink-0 border-b border-[var(--border)] bg-[var(--card)] px-3 py-1.5",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between text-[10px] text-[var(--muted-foreground)]",children:[(0,s.jsxs)("span",{children:["Uploading ",W.count," file",W.count>1?"s":"","..."]}),(0,s.jsxs)("span",{children:[Math.round(W.progress),"%"]})]}),(0,s.jsx)("div",{className:"mt-1 h-1 overflow-hidden rounded-full bg-[var(--secondary)]",children:(0,s.jsx)("div",{className:"h-full rounded-full bg-[var(--primary)] transition-all duration-150",style:{width:"".concat(W.progress,"%")}})})]});if("tree-only"===a)return(0,s.jsxs)("div",{className:"flex h-full flex-col",children:[em,F.size>0&&(0,s.jsxs)("div",{className:"flex shrink-0 items-center justify-between border-b border-[var(--border)] bg-[var(--secondary)]/50 px-3 py-1.5",children:[(0,s.jsxs)("span",{className:"text-[10px] text-[var(--muted-foreground)]",children:[F.size," selected"]}),(0,s.jsx)("button",{onClick:()=>M(new Set),className:"rounded px-1.5 py-0.5 text-[10px] text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,s.jsx)(eK.A,{className:"h-3 w-3"})})]}),(0,s.jsx)("div",{className:"flex-1 overflow-y-auto",children:H?(0,s.jsx)("div",{className:"p-3 text-xs text-[var(--muted-foreground)]",children:"Loading..."}):B?(0,s.jsx)(eb,{node:B,projectId:r,onSelect:X,onContextMenu:ec,onDropFiles:el,onMoveFile:eo,selectedPaths:F,onSelectionChange:ei,lastAnchor:P,depth:0,pendingEdit:_,onCommitEdit:ex,onCancelEdit:eu}):(0,s.jsx)("div",{className:"p-3 text-xs text-[var(--muted-foreground)]",children:"No files"})}),E&&(0,s.jsx)(eA,{x:E.x,y:E.y,path:E.path,name:E.name,isDir:E.isDir,selectedCount:F.size>1&&F.has(E.path)?F.size:void 0,onAction:ed,onClose:()=>T(null)})]});let ep="full"===a&&w;return(0,s.jsxs)("div",{className:"flex h-full flex-col bg-[var(--background)]",children:[(0,s.jsxs)("div",{className:"flex h-10 shrink-0 items-center justify-between border-b border-[var(--border)] px-3",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:["full"===a&&(0,s.jsx)("button",{onClick:()=>N(!w),className:"rounded p-1 text-[var(--muted-foreground)] transition-colors hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:w?(0,s.jsx)(eR.A,{className:"h-4 w-4"}):(0,s.jsx)(ez.A,{className:"h-4 w-4"})}),(0,s.jsx)(e7.A,{className:"h-4 w-4 text-[var(--muted-foreground)]"}),(0,s.jsx)("span",{className:"text-sm font-medium text-[var(--foreground)]",children:o("nav.canvas")}),Y&&(null!=Y.size||null!=Y.mtime)&&(0,s.jsxs)("span",{className:"text-[10px] text-[var(--muted-foreground)]",children:["(",[null!=Y.size?(t=Y.size)<1024?"".concat(t," B"):t<1048576?"".concat((t/1024).toFixed(1)," KB"):"".concat((t/1048576).toFixed(1)," MB"):"",null!=Y.createdAt?"Created ".concat(tn(Y.createdAt)):"",null!=Y.mtime?"Modified ".concat(tn(Y.mtime)):""].filter(Boolean).join(" \xb7 "),")"]})]}),(0,s.jsx)("div",{className:"flex items-center gap-1",children:n&&(0,s.jsx)("button",{onClick:()=>c.getState().toggleMaximized(),title:f?"Exit full screen":"Maximize editor",className:"rounded p-1 text-[var(--muted-foreground)] transition-colors hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:f?(0,s.jsx)(te.A,{className:"h-4 w-4"}):(0,s.jsx)(tt.A,{className:"h-4 w-4"})})})]}),(0,s.jsxs)(i.YZ,{direction:"horizontal",autoSaveId:ep?"halo-editor-tree":void 0,children:[ep&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(i.Zk,{defaultSize:20,minSize:10,maxSize:40,children:(0,s.jsxs)("div",{className:"flex h-full flex-col bg-[var(--card)]",children:[em,(0,s.jsx)("div",{className:"flex-1 overflow-y-auto",children:r?H?(0,s.jsx)("div",{className:"p-3 text-xs text-[var(--muted-foreground)]",children:"Loading..."}):B?(0,s.jsx)(eb,{node:B,projectId:r,onSelect:X,onContextMenu:ec,onDropFiles:el,onMoveFile:eo,selectedPaths:F,onSelectionChange:ei,lastAnchor:P,depth:0,pendingEdit:_,onCommitEdit:ex,onCancelEdit:eu}):(0,s.jsx)("div",{className:"p-3 text-xs text-[var(--muted-foreground)]",children:"No files"}):(0,s.jsx)("div",{className:"p-3 text-xs text-[var(--muted-foreground)]",children:"Open a folder to view files"})})]})}),(0,s.jsx)(i.TW,{className:"w-px bg-[var(--border)] hover:w-1 hover:bg-[var(--primary)] transition-colors"})]}),(0,s.jsx)(i.Zk,{defaultSize:80,minSize:40,children:(0,s.jsx)(i.YZ,{direction:"horizontal",autoSaveId:"halo-editor-panes",children:m.map((e,t)=>{var a;let n=e.tabs.map(e=>x[e]).filter(e=>!!e),l=e.activeTab,o=n.find(e=>e.path===l),d=t===h;return(0,s.jsx)(i.Zk,{defaultSize:100/m.length,minSize:20,children:(0,s.jsxs)("div",{className:D("flex h-full flex-col overflow-hidden",d&&m.length>1&&"ring-1 ring-inset ring-[var(--primary)]/30"),onMouseDown:()=>c.getState().setActiveGroup(t),children:[n.length>0&&(()=>{let r=I(e.id),a=k[e.id],i=!!(null==o?void 0:o.modified)&&!o.preview;return(0,s.jsx)(eV,{tabs:n,activeTab:l,groupIdx:t,canSplit:b&&1===m.length,onCloseTab:e=>ee(t,e),renderMode:r,onToggleRenderMode:()=>A(t=>({...t,[e.id]:!r})),showDiffButton:i,onToggleDiff:()=>{a?es(e.id):o&&en(e.id,o.path)}})})(),(0,s.jsxs)("div",{className:"flex-1 overflow-hidden",children:[Z.map(e=>n.find(t=>t.path===e&&t.preview)).filter(e=>!!e).map(e=>{var t;return(0,s.jsx)("div",{className:D("h-full",(null==o?void 0:o.path)!==e.path&&"hidden"),children:(0,s.jsx)(e8,{path:e.path,name:null!=(t=e.path.split("/").pop())?t:"",downloadUrl:e.preview.downloadUrl,viewUrl:e.preview.viewUrl,onOpenAsText:()=>et(e.path)})},e.path)}),(null==o?void 0:o.preview)&&q(o.path)&&(0,s.jsx)("div",{className:"h-full",children:(0,s.jsx)(e8,{path:o.path,name:null!=(a=o.path.split("/").pop())?a:"",downloadUrl:o.preview.downloadUrl,viewUrl:o.preview.viewUrl,onOpenAsText:()=>et(o.path)})}),(()=>{let a=k[e.id],n=I(e.id);if(null==o?void 0:o.preview)return null;if(a)return(0,s.jsxs)("div",{className:"h-full flex flex-col",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between border-b border-[var(--border)] bg-[var(--card)] px-3 py-1.5",children:[(0,s.jsxs)("span",{className:"text-xs text-[var(--muted-foreground)]",children:["Diff: ",a.path]}),(0,s.jsx)("button",{onClick:()=>es(e.id),className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,s.jsx)(eK.A,{className:"h-3.5 w-3.5"})})]}),(0,s.jsx)("div",{className:"flex-1",children:(0,s.jsx)(eB,{original:a.original,modified:a.modified,path:a.path})})]});if(o){var l;let e=n&&"markdown"===o.language,a=n&&"html"===o.language&&!!r;return(0,s.jsxs)(s.Fragment,{children:[e&&(0,s.jsx)(e_,{content:o.content,filePath:o.path,projectId:r}),a&&(0,s.jsx)(eU,{url:v.F.files.viewUrl(o.path,r),name:null!=(l=o.path.split("/").pop())?l:""}),(0,s.jsx)("div",{className:D("h-full",(e||a)&&"hidden"),children:(0,s.jsx)(eM,{path:"".concat(null!=r?r:"","/").concat(o.path),content:o.content,language:o.language,onChange:e=>er(o.path,e),onSave:()=>ea(o.path),onClose:()=>ee(t,o.path)})})]})}return(0,s.jsx)("div",{className:"flex h-full items-center justify-center",children:(0,s.jsxs)("div",{className:"text-center",children:[(0,s.jsx)(e7.A,{className:"mx-auto h-8 w-8 text-[var(--muted-foreground)]"}),(0,s.jsx)("p",{className:"mt-2 text-sm text-[var(--muted-foreground)]",children:"Open a file to start editing"})]})})})()]})]})},e.id)}).flatMap((e,t,r)=>t<r.length-1?[e,(0,s.jsx)(i.TW,{className:"w-px bg-[var(--border)] hover:w-1 hover:bg-[var(--primary)] transition-colors"},"rh-".concat(t))]:[e])},m.length)})]}),E&&(0,s.jsx)(eA,{x:E.x,y:E.y,path:E.path,name:E.name,isDir:E.isDir,selectedCount:F.size>1&&F.has(E.path)?F.size:void 0,onAction:ed,onClose:()=>T(null)})]})}function to(e){return e.type?e.type:"user"===e.role?"user":"assistant"===e.role?"assistant":e.toolName?"tool_call":void 0===e.toolOutput||e.toolName?e.usage?"usage":e.systemPrompt?"context":"notification":"tool_result"}function ti(e){if(e.taskId)return!1;let t=to(e);return"user"===t||"assistant"===t||"notification"===t}var tc=r(22813),td=r(80685),tu=r(92387),tx=r(13277),tm=r(99484),tp=r(76042);let th={pending:{icon:O.A,color:"text-[var(--muted-foreground)]",label:"Pending"},running:{icon:H.A,color:"text-blue-400",label:"Running"},completed:{icon:tc.A,color:"text-emerald-400",label:"Done"},failed:{icon:td.A,color:"text-red-400",label:"Failed"},skipped:{icon:tu.A,color:"text-[var(--muted-foreground)]",label:"Skipped"}};function tf(e){let{plan:t}=e,[r,a]=(0,l.useState)(!0),[n,o]=(0,l.useState)(!1),[i,c]=(0,l.useState)(""),d="pending_approval"===t.status,u=t.tasks.filter(e=>"completed"===e.status).length,x=t.tasks.length,m=(0,l.useCallback)(()=>{j.send({type:"approve",planId:t.id})},[t.id]),p=(0,l.useCallback)(()=>{i.trim()&&(j.send({type:"reject",planId:t.id,feedback:i.trim()}),o(!1),c(""))},[t.id,i]);return(0,s.jsxs)("div",{className:"rounded-lg border border-[var(--border)] bg-[var(--card)] overflow-hidden",children:[(0,s.jsxs)("button",{onClick:()=>a(!r),className:"flex w-full items-center justify-between px-3 py-2.5 text-left transition-colors hover:bg-[var(--secondary)]",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[r?(0,s.jsx)(W.A,{className:"h-4 w-4 text-[var(--muted-foreground)]"}):(0,s.jsx)(U.A,{className:"h-4 w-4 text-[var(--muted-foreground)]"}),(0,s.jsx)("span",{className:"text-sm font-medium text-[var(--foreground)]",children:"Task Plan"}),(0,s.jsxs)("span",{className:"text-xs text-[var(--muted-foreground)]",children:["(",u,"/",x,")"]})]}),(0,s.jsx)(tv,{status:t.status})]}),r&&(0,s.jsxs)("div",{className:"border-t border-[var(--border)]",children:[(0,s.jsx)("div",{className:"px-3 py-2 text-xs text-[var(--muted-foreground)]",children:t.description}),(0,s.jsx)("div",{className:"px-3 pb-2",children:t.tasks.map(e=>(0,s.jsx)(tg,{task:e,allTasks:t.tasks},e.id))}),d&&(0,s.jsx)("div",{className:"border-t border-[var(--border)] px-3 py-2.5",children:n?(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsx)("textarea",{value:i,onChange:e=>c(e.target.value),placeholder:"Explain what should be changed...",rows:2,className:"w-full resize-none rounded-md border border-[var(--border)] bg-[var(--secondary)] px-2.5 py-1.5 text-xs text-[var(--foreground)] placeholder-[var(--muted-foreground)] outline-none focus:border-[var(--primary)]"}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("button",{onClick:p,disabled:!i.trim(),className:D("rounded-md px-3 py-1.5 text-xs font-medium transition-colors",i.trim()?"bg-[var(--destructive)] text-white hover:bg-red-500":"bg-[var(--secondary)] text-[var(--muted-foreground)] cursor-not-allowed"),children:"Send Feedback"}),(0,s.jsx)("button",{onClick:()=>{o(!1),c("")},className:"rounded-md px-3 py-1.5 text-xs text-[var(--muted-foreground)] transition-colors hover:text-[var(--foreground)]",children:"Cancel"})]})]}):(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsxs)("button",{onClick:m,className:"flex items-center gap-1.5 rounded-md bg-emerald-600 px-3 py-1.5 text-xs font-medium text-white transition-colors hover:bg-emerald-500",children:[(0,s.jsx)(tx.A,{className:"h-3.5 w-3.5"}),"Approve"]}),(0,s.jsxs)("button",{onClick:()=>o(!0),className:"flex items-center gap-1.5 rounded-md border border-[var(--border)] bg-[var(--secondary)] px-3 py-1.5 text-xs font-medium text-[var(--secondary-foreground)] transition-colors hover:bg-[var(--accent)]",children:[(0,s.jsx)(tm.A,{className:"h-3.5 w-3.5"}),"Reject"]})]})})]})]})}function tg(e){let{task:t,allTasks:r}=e,a=th[t.status],n=a.icon,l=t.dependencies.map(e=>{var t;return null==(t=r.find(t=>t.id===e))?void 0:t.name}).filter(Boolean);return(0,s.jsxs)("div",{className:"flex items-start gap-2 py-1.5",children:[(0,s.jsx)(n,{className:D("mt-0.5 h-4 w-4 shrink-0",a.color,"running"===t.status&&"animate-spin")}),(0,s.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:"text-xs font-medium text-[var(--foreground)]",children:t.name}),t.agentId&&(0,s.jsx)("span",{className:"rounded bg-[var(--secondary)] px-1.5 py-0.5 text-[10px] text-[var(--muted-foreground)]",children:t.agentId})]}),t.description&&(0,s.jsx)("p",{className:"mt-0.5 text-[11px] leading-relaxed text-[var(--muted-foreground)]",children:t.description}),l.length>0&&(0,s.jsxs)("div",{className:"mt-0.5 flex items-center gap-1 text-[10px] text-[var(--muted-foreground)]",children:[(0,s.jsx)(tp.A,{className:"h-3 w-3"}),(0,s.jsxs)("span",{children:["after: ",l.join(", ")]})]})]})]})}function tv(e){var t,r;let{status:a}=e;return(0,s.jsx)("span",{className:D("rounded-full border px-2 py-0.5 text-[10px] font-medium",null!=(t=({pending_approval:"bg-amber-900/50 text-amber-300 border-amber-700",approved:"bg-blue-900/50 text-blue-300 border-blue-700",running:"bg-blue-900/50 text-blue-300 border-blue-700",completed:"bg-emerald-900/50 text-emerald-300 border-emerald-700",failed:"bg-red-900/50 text-red-300 border-red-700",rejected:"bg-[var(--secondary)] text-[var(--muted-foreground)] border-[var(--border)]"})[a])?t:"bg-[var(--secondary)] text-[var(--muted-foreground)] border-[var(--border)]"),children:null!=(r=({pending_approval:"Needs Approval",approved:"Approved",running:"Running",completed:"Completed",failed:"Failed",rejected:"Rejected"})[a])?r:a})}var tb=r(10509),tj=r(93099),ty=r(13523);let tw=/\.(png|jpe?g|gif|webp|bmp|svg)$/i,tN=/\.(mp4|webm|mov|m4v|ogv)$/i,tk=/\.(mp3|wav|flac|aac|m4a|ogg|opus|amr|silk)$/i;function tS(e){return tw.test(e)?"image":tN.test(e)?"video":tk.test(e)?"audio":"file"}function tC(e){let t=[],r=e.replace(/\[(图片|视频|语音消息(?:\s*[^\s]+)?|文件(?:\s*"[^"]*")?)\s*已保存:\s*([^,\]]+)(?:,\s*服务端转写:\s*([^\]]+))?\]/g,(e,r,a,n)=>{let s,l=a.trim();s=r.startsWith("图片")?"image":r.startsWith("视频")?"video":r.startsWith("语音")?"audio":r.startsWith("文件")?"file":tS(l);let o=r.match(/"([^"]+)"/),i=o?o[1]:n?n.trim():void 0;return t.push({path:l,kind:s,label:i}),""});return{text:r=(r=r.replace(/^[ \t]*MEDIA:\s*(\S.*?)\s*$/gm,(e,r)=>{let a=r.trim();return t.push({path:a,kind:tS(a)}),""})).replace(/\n{3,}/g,"\n\n").trim(),media:t}}function tA(e){let{media:t}=e,[r,a]=(0,l.useState)(null);return 0===t.length?null:(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:t.map((e,t)=>(0,s.jsx)(tE,{media:e,onOpen:()=>a(e)},"".concat(e.path,"-").concat(t)))}),r&&(0,s.jsx)(tF,{media:r,onClose:()=>a(null)})]})}function tI(e,t){if(!t)return null;let r=e=>e.replace(/\\/g,"/").toLowerCase(),a=r(e),n=r(t).replace(/\/$/,""),s=a===n||a.startsWith(n+"/"),l=/(^|\/)(tmp|temp)\//.test(a);if(!s&&!l)return null;let o=new URLSearchParams;return o.set("path",e),o.set("projectId",t),o.set("inline","1"),"/api/files/download?".concat(o.toString())}function tE(e){var t;let{media:r,onOpen:a}=e,n=e9(e=>{var t,r;return null!=(r=null==(t=e.activeProject)?void 0:t.path)?r:null}),l=tI(r.path,n),o=null!=(t=r.path.split("/").pop())?t:r.path;return l?(0,s.jsxs)("button",{onClick:a,className:"inline-flex items-center gap-1.5 rounded border border-[var(--border)] bg-[var(--secondary)]/30 px-2 py-1 text-[11px] text-[var(--foreground)] cursor-pointer hover:ring-1 hover:ring-[var(--primary)]/40 transition-all no-underline",title:o,children:[(0,s.jsx)(tT,{kind:r.kind}),(0,s.jsx)("span",{className:"truncate max-w-[240px] font-mono",children:r.label||o})]}):(0,s.jsxs)("span",{className:"inline-flex items-center gap-1.5 rounded border border-[var(--border)] bg-[var(--secondary)]/30 px-2 py-1 font-mono text-[10px] text-[var(--muted-foreground)]",children:[(0,s.jsx)(tT,{kind:r.kind}),o]})}function tT(e){let{kind:t}=e,r="h-3 w-3";return"image"===t?(0,s.jsx)(tb.A,{className:r}):"video"===t?(0,s.jsx)(tj.A,{className:r}):"audio"===t?(0,s.jsx)(ty.A,{className:r}):(0,s.jsx)(Z.A,{className:r})}function tF(e){var t;let{media:r,onClose:a}=e,n=e9(e=>{var t,r;return null!=(r=null==(t=e.activeProject)?void 0:t.path)?r:null}),o=tI(r.path,n);return((0,l.useEffect)(()=>{let e=e=>{"Escape"===e.key&&a()};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[a]),o)?(0,s.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/80 p-6",onClick:a,children:[(0,s.jsx)("button",{onClick:a,className:"absolute right-4 top-4 rounded p-2 text-white/80 hover:bg-white/10 hover:text-white","aria-label":"Close",children:(0,s.jsx)(eK.A,{className:"h-5 w-5"})}),(0,s.jsxs)("div",{className:"flex max-h-full max-w-full flex-col items-center gap-3",onClick:e=>e.stopPropagation(),children:["image"===r.kind&&(0,s.jsx)("img",{src:o,alt:r.path,className:"max-h-[85vh] max-w-[90vw] object-contain"}),"video"===r.kind&&(0,s.jsx)("video",{src:o,controls:!0,autoPlay:!0,className:"max-h-[85vh] max-w-[90vw]"}),"audio"===r.kind&&(0,s.jsx)("audio",{src:o,controls:!0,autoPlay:!0,className:"w-[min(80vw,480px)]"}),"file"===r.kind&&(0,s.jsxs)("a",{href:o.replace("&inline=1",""),download:null!=(t=r.path.split("/").pop())?t:"file",className:"rounded bg-white/10 px-4 py-2 text-sm text-white hover:bg-white/20 no-underline",children:["Download ",r.path.split("/").pop()]}),(0,s.jsx)("div",{className:"max-w-[90vw] truncate font-mono text-[11px] text-white/60",children:r.path})]})]}):null}var tD=r(72140),tM=r(68709);function tP(e){let{messages:t,debugMode:r}=e;return(0,s.jsx)(tL,{messages:t,debugMode:r})}function tL(e){let{messages:t,debugMode:r}=e,a=(0,l.useMemo)(()=>(function(e){let t=[],r=null;for(let a of e)"user"===a.role?(r&&t.push(r),r={user:a,responses:[]}):r?r.responses.push(a):t.push({user:a,responses:[]});return r&&t.push(r),t})(t),[t]);return(0,s.jsx)("div",{className:"flex flex-col",children:a.map(e=>(0,s.jsx)(tR,{user:e.user,responses:e.responses,debugMode:r},e.user.id))})}let tR=(0,l.memo)(function(e){let{user:t,responses:r,debugMode:a}=e;return(0,s.jsxs)("div",{className:"border-b border-[var(--border)]/50 last:border-b-0",children:["user"===t.role?tz(t.content)?(0,s.jsx)(t_,{content:t.content}):tO(t.content)?(0,s.jsx)(tW,{content:t.content}):(0,s.jsx)(tG,{content:t.content,localImages:t.localImages}):(0,s.jsx)("div",{className:"px-3 py-2",children:(0,s.jsx)(tH,{message:t,debugMode:a})}),r.length>0&&(0,s.jsx)(tU,{responses:r,debugMode:a})]})},(e,t)=>e.user===t.user&&e.debugMode===t.debugMode&&e.responses.length===t.responses.length&&e.responses.every((e,r)=>e===t.responses[r]));function tz(e){let t=e.match(/^\(from: session ([^)]+)\)\n([\s\S]*)$/);return t?{sessionId:t[1],body:t[2]}:null}function t_(e){var t;let{content:r}=e,a=tz(r),n=null!=(t=a.sessionId.split(">").pop())?t:a.sessionId;return(0,s.jsxs)("div",{className:"sticky top-0 z-10 px-3 py-2 border-b border-[var(--border)] border-l-2 border-l-emerald-500/70 bg-emerald-950/40 backdrop-blur-sm shadow-sm",children:[(0,s.jsxs)("div",{className:"mb-1 flex items-center gap-2 text-[10px] font-medium text-emerald-400",children:[(0,s.jsx)("span",{children:"Report from sub-session"}),(0,s.jsx)("span",{className:"rounded bg-emerald-900/40 px-1 py-0.5 font-mono text-emerald-300/80",children:n})]}),(0,s.jsx)(tQ,{maxLines:4,children:(0,s.jsx)("div",{className:"text-xs text-[var(--foreground)] whitespace-pre-wrap leading-relaxed",children:a.body})})]})}function tO(e){let t=e.match(/^\[Conversation Summary — (\d+) messages compacted\]\n([\s\S]*)$/);return t?{olderCount:parseInt(t[1],10),body:t[2]}:null}function tW(e){let{content:t}=e,r=tO(t),[a,n]=(0,l.useState)(!1);return(0,s.jsxs)("div",{className:"sticky top-0 z-10 border-l-2 border-l-purple-500/70 bg-purple-950/40 backdrop-blur-sm shadow-sm",children:[(0,s.jsxs)("button",{onClick:()=>n(!a),className:"flex w-full items-center gap-2 px-3 py-2 text-[10px] font-medium text-purple-400 hover:bg-purple-900/30 transition-colors",children:[a?(0,s.jsx)(W.A,{className:"h-3 w-3"}):(0,s.jsx)(U.A,{className:"h-3 w-3"}),(0,s.jsx)("span",{children:"Conversation summary sent to LLM"}),(0,s.jsxs)("span",{className:"rounded bg-purple-900/40 px-1 py-0.5 font-mono text-purple-300/80",children:[r.olderCount," messages compacted"]})]}),a&&(0,s.jsx)("div",{className:"px-3 pb-2 text-xs text-[var(--foreground)] whitespace-pre-wrap leading-relaxed max-h-[40vh] overflow-y-auto",children:r.body})]})}function tU(e){let{responses:t,debugMode:r}=e,a=(0,l.useMemo)(()=>{var e,a;let n=new Map;if(!r)return n;let s=t.filter(e=>"usage"===to(e)&&e.usage);if(0===s.length)return n;let l=new Map;for(let e of t)if("assistant"===to(e)&&e.contentBlocks)for(let t of e.contentBlocks)t.turnId&&l.set(t.turnId,e.id);let o=[];for(let t of s){let r=t.turnId?l.get(t.turnId):void 0;if(r){let a=null!=(e=n.get(r))?e:[];a.push(t),n.set(r,a)}else o.push(t)}if(o.length>0){let e=[...t].reverse().find(e=>"assistant"===to(e));if(e){let t=null!=(a=n.get(e.id))?a:[];t.push(...o),n.set(e.id,t)}}return n},[r,t]);return(0,s.jsx)("div",{className:"px-3 py-2",children:t.map(e=>(0,s.jsx)(tH,{message:e,debugMode:r,usages:a.get(e.id)},e.id))})}function tB(e){var t,r,a,n,l,o,i,c;let{message:d}=e,u=d.usage;if(!u)return null;let x=null!=(r=null==(t=d.modelId)?void 0:t.replace(/^global\.anthropic\./,""))?r:"",m=u.inputTokens+(null!=(a=u.cacheReadInputTokens)?a:0)+(null!=(n=u.cacheWriteInputTokens)?n:0),p=m+u.outputTokens,h=m>0?Math.round(u.cacheReadInputTokens/m*100):0,f=e=>e>=1e3?"".concat((e/1e3).toFixed(1),"s"):"".concat(e,"ms"),g=new Date(d.timestamp),v="".concat(g.getHours().toString().padStart(2,"0"),":").concat(g.getMinutes().toString().padStart(2,"0"),":").concat(g.getSeconds().toString().padStart(2,"0"));return(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-1 py-0.5 text-[10px] font-mono text-[var(--muted-foreground)]",children:[(0,s.jsx)("span",{className:"inline-flex items-center gap-0.5 rounded bg-[var(--secondary)] px-1 py-px opacity-70",title:g.toLocaleString(),children:v}),(0,s.jsxs)("span",{className:"inline-flex items-center gap-0.5 rounded bg-[var(--secondary)] px-1 py-px",children:[(0,s.jsx)("span",{className:"opacity-60",children:"in"}),(u.inputTokens/1e3).toFixed(1),"K"]}),(0,s.jsxs)("span",{className:"inline-flex items-center gap-0.5 rounded bg-[var(--secondary)] px-1 py-px",children:[(0,s.jsx)("span",{className:"opacity-60",children:"out"}),(u.outputTokens/1e3).toFixed(1),"K"]}),(0,s.jsxs)("span",{className:"inline-flex items-center gap-0.5 rounded bg-[var(--secondary)] px-1 py-px",children:[(0,s.jsx)("span",{className:"opacity-60",children:"ctx"}),(p/1e3).toFixed(1),"K"]}),(null!=(l=u.cacheReadInputTokens)?l:0)>0&&(0,s.jsxs)("span",{className:"inline-flex items-center gap-0.5 rounded bg-emerald-900/30 px-1 py-px text-emerald-400",children:[(0,s.jsx)("span",{className:"opacity-60",children:"read"}),((null!=(o=u.cacheReadInputTokens)?o:0)/1e3).toFixed(1),"K"]}),(null!=(i=u.cacheWriteInputTokens)?i:0)>0&&(0,s.jsxs)("span",{className:"inline-flex items-center gap-0.5 rounded bg-amber-900/30 px-1 py-px text-amber-400",children:[(0,s.jsx)("span",{className:"opacity-60",children:"write"}),((null!=(c=u.cacheWriteInputTokens)?c:0)/1e3).toFixed(1),"K"]}),h>0&&(0,s.jsxs)("span",{className:"inline-flex items-center gap-0.5 rounded bg-emerald-900/30 px-1 py-px text-emerald-400",children:[(0,s.jsx)("span",{className:"opacity-60",children:"cache"}),h,"%"]}),null!=u.ttftMs&&(0,s.jsxs)("span",{className:"inline-flex items-center gap-0.5 rounded bg-[var(--secondary)] px-1 py-px",children:[(0,s.jsx)("span",{className:"opacity-60",children:"ttft"}),f(u.ttftMs)]}),null!=u.e2eMs&&(0,s.jsxs)("span",{className:"inline-flex items-center gap-0.5 rounded bg-[var(--secondary)] px-1 py-px",children:[(0,s.jsx)("span",{className:"opacity-60",children:"e2e"}),f(u.e2eMs)]}),u.thinkingEffort&&"off"!==u.thinkingEffort&&(0,s.jsxs)("span",{className:"inline-flex items-center gap-0.5 rounded bg-purple-900/30 px-1 py-px text-purple-400",children:[(0,s.jsx)("span",{className:"opacity-60",children:"think"}),u.thinkingEffort]}),"off"===u.thinkingEffort&&(0,s.jsx)("span",{className:"inline-flex items-center gap-0.5 rounded bg-[var(--secondary)] px-1 py-px opacity-50",children:"think off"}),x&&(0,s.jsx)("span",{className:"inline-flex items-center gap-0.5 rounded bg-blue-900/30 px-1 py-px text-blue-400",children:x})]})}function tH(e){var t,r,a,n,o;let{message:i,debugMode:c,usages:d}=e,u=to(i),x="assistant"===u,m=(0,l.useMemo)(()=>{if(!c||!x||!(null==d?void 0:d.length))return null;let e=new Map;for(let t of d)t.turnId&&e.set(t.turnId,t);return e.size>0?e:null},[c,x,d]);if("tool_call"===u||"tool_result"===u||"usage"===u||"context"===u)return null;if("agent_start"===u||"agent_done"===u)return c?(0,s.jsx)("div",{className:"my-0.5 px-1",children:(0,s.jsxs)("span",{className:D("inline-block rounded px-1.5 py-0.5 text-[9px]","agent_start"===u?"bg-blue-900/40 text-blue-400":"bg-emerald-900/40 text-emerald-400"),children:[null!=(r=i.agentName)?r:"Agent",": ",i.content||("agent_start"===u?"started":"done")]})}):null;let p=x&&i.contentBlocks&&i.contentBlocks.length>0;if(i.streaming&&!i.content&&!(null==(t=i.toolCalls)?void 0:t.length))return(0,s.jsxs)("div",{className:"flex items-center gap-1.5 py-1",children:[(0,s.jsx)(H.A,{className:"h-3 w-3 animate-spin text-[var(--primary)]"}),(0,s.jsx)("span",{className:"text-xs text-[var(--muted-foreground)]",children:"Thinking..."})]});let h=[];if(p){let e=i.contentBlocks;for(let t=0;t<e.length;t++){let r=e[t];if("thinking"===r.type&&r.text.trim()&&c)h.push((0,s.jsx)(tK,{text:r.text},"b".concat(t)));else if("text"===r.type&&r.text.trim())h.push((0,s.jsx)(tJ,{text:r.text},"b".concat(t)));else if("tool_call"===r.type){let l=e.slice(0,t+1).filter(e=>"tool_call"===e.type).length-1==(null!=(n=null==(a=i.toolCalls)?void 0:a.length)?n:0)-1;h.push((0,s.jsx)(t$,{call:r.toolCall,isStreaming:i.streaming,isLast:l},"b".concat(t)))}if(m&&r.turnId){let a=null==(o=e[t+1])?void 0:o.turnId;if(!a||a!==r.turnId){let e=m.get(r.turnId);e&&h.push((0,s.jsx)(tB,{message:e},"u".concat(r.turnId)))}}}if(m){let t=new Set(e.map(e=>e.turnId).filter(Boolean));for(let[e,r]of m)t.has(e)||h.push((0,s.jsx)(tB,{message:r},"u".concat(e)))}}else{if(x&&i.toolCalls&&i.toolCalls.length>0&&i.toolCalls.forEach((e,t)=>{h.push((0,s.jsx)(t$,{call:e,isStreaming:i.streaming,isLast:t===i.toolCalls.length-1},"tc".concat(t)))}),m)for(let[e,t]of m)h.push((0,s.jsx)(tB,{message:t},"u".concat(e)));if(i.content){let e=!x&&/^Compacting context /.test(i.content);h.push(x?(0,s.jsx)(tJ,{text:i.content},"txt"):e?(0,s.jsxs)("span",{className:"inline-flex items-center gap-1.5 text-xs text-[var(--muted-foreground)]",children:[(0,s.jsx)(H.A,{className:"h-3 w-3 animate-spin shrink-0"}),(0,s.jsx)("span",{className:"whitespace-pre-wrap",children:i.content})]},"txt"):(0,s.jsx)("span",{className:"text-xs text-[var(--muted-foreground)] whitespace-pre-wrap",children:i.content},"txt"))}}return i.plan&&h.push((0,s.jsx)("div",{className:"mt-2",children:(0,s.jsx)(tf,{plan:i.plan})},"plan")),(0,s.jsx)("div",{className:"py-1",children:h})}function tK(e){let{text:t}=e,[r,a]=(0,l.useState)(!1);return(0,s.jsxs)("div",{className:"my-1 rounded border border-purple-900/50 bg-purple-950/20",children:[(0,s.jsxs)("button",{onClick:()=>a(!r),className:"flex w-full items-center gap-1.5 px-2 py-1 text-left text-[11px] text-purple-400 hover:bg-purple-900/20 transition-colors",children:[r?(0,s.jsx)(W.A,{className:"h-3 w-3"}):(0,s.jsx)(U.A,{className:"h-3 w-3"}),(0,s.jsx)("span",{className:"font-medium",children:"Thinking"}),(0,s.jsxs)("span",{className:"text-[10px] text-purple-400/60",children:[t.length.toLocaleString()," chars"]})]}),r&&(0,s.jsx)("pre",{className:"px-2 pb-2 text-[11px] text-[var(--foreground)] whitespace-pre-wrap break-words leading-relaxed max-h-[50vh] overflow-y-auto",children:t})]})}function tG(e){let{content:t,localImages:r}=e,{text:a,media:n}=(0,l.useMemo)(()=>tC(t),[t]),[o,i]=(0,l.useState)(null);return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"sticky top-0 z-10 bg-[var(--accent)] border-b border-[var(--border)] border-l-2 border-l-blue-500 px-4 py-2.5 shadow-sm",children:(0,s.jsx)(tQ,{maxLines:2,children:(0,s.jsx)("div",{className:"text-xs text-[var(--accent-foreground)] leading-relaxed whitespace-pre-wrap",children:a||(n.length>0||(null==r?void 0:r.length)?"(attachment)":"")})})}),r&&r.length>0&&(0,s.jsx)("div",{className:"flex flex-wrap gap-2 px-4 py-2 border-b border-[var(--border)]/30",children:r.map((e,t)=>(0,s.jsx)("img",{src:e,alt:"screenshot",onClick:()=>i(e),className:"max-h-40 max-w-[240px] cursor-pointer rounded border border-[var(--border)] object-contain hover:ring-1 hover:ring-[var(--primary)]/40"},t))}),n.length>0&&(0,s.jsx)("div",{className:"px-4 py-2 border-b border-[var(--border)]/30",children:(0,s.jsx)(tA,{media:n})}),o&&(0,s.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/80 p-6",onClick:()=>i(null),children:(0,s.jsx)("img",{src:o,alt:"screenshot",className:"max-h-[90vh] max-w-[92vw] object-contain"})})]})}function tJ(e){let{text:t}=e,{text:r,media:a}=(0,l.useMemo)(()=>tC(t),[t]),n=(0,l.useMemo)(()=>r.replace(/<<<CAPTURE>>>/g,"").replace(/<<<SHOW:[\s\S]*?>>>/g,"").trim(),[r]);return(0,s.jsxs)("div",{className:"prose prose-sm prose-invert max-w-none prose-p:my-1.5 prose-headings:my-2 prose-ul:my-1.5 prose-ol:my-1.5 prose-li:my-0.5 prose-pre:my-2 prose-code:text-amber-300 prose-code:before:content-none prose-code:after:content-none prose-pre:bg-[var(--secondary)] prose-pre:border prose-pre:border-[var(--border)] prose-a:text-[var(--primary)] prose-code:bg-[var(--secondary)] prose-code:px-1 prose-code:py-0.5 prose-code:rounded prose-code:text-xs prose-th:border prose-th:border-[var(--border)] prose-th:px-2 prose-th:py-1 prose-th:bg-[var(--secondary)] prose-td:border prose-td:border-[var(--border)] prose-td:px-2 prose-td:py-1",children:[n&&(0,s.jsx)(eP.oz,{remarkPlugins:[eL.A],components:{a(e){let{href:t,children:r,node:a,...n}=e;return(0,s.jsx)("a",{href:t,target:"_blank",rel:"noopener noreferrer",...n,children:r})},pre(e){let{children:t}=e;return(0,s.jsx)("pre",{className:"overflow-x-auto",children:t})},code(e){let{className:t,children:r,node:a,...n}=e;return(null==t?void 0:t.startsWith("language-"))||String(r).includes("\n")?(0,s.jsx)(tX,{className:t,children:r}):(0,s.jsx)("code",{className:t,...n,children:r})}},children:n}),(0,s.jsx)(tA,{media:a})]})}function tq(e){try{let t=JSON.parse(e);return"object"==typeof t&&null!==t?t:null}catch(e){return null}}let tZ="__TOOL_ERROR__",tV="__TOOL_WARN__",tY={running:"bg-amber-400 animate-pulse",success:"bg-emerald-400",warn:"bg-yellow-400",error:"bg-red-400"};function t$(e){let{call:t,isStreaming:r,isLast:a}=e,[n,o]=(0,l.useState)(!1),i=function(e,t,r){var a;if(!e.output&&""!==e.output)return"running";let n=null!=(a=e.output)?a:"";return n.startsWith(tZ)?"error":n.startsWith(tV)?"warn":"success"}(t,r,0),c=void 0!==t.output&&""!==t.output,{summary:d}=(0,l.useMemo)(()=>(function(e,t){let r=tq(t);if(r){var a,n,s,l,o,i,c,d,u,x,m,p,h,f,g,v,b,j,y,w,N,k,S;switch(e){case"shell_exec":return{summary:String(null!=(n=null!=(a=r.command)?a:r.cmd)?n:"")||t};case"file_read":return{summary:String(null!=(o=null!=(l=null!=(s=r.path)?s:r.file)?l:r.filePath)?o:"")||t};case"file_write":{let e=String(null!=(d=null!=(c=null!=(i=r.path)?i:r.file)?c:r.filePath)?d:""),t=String(null!=(u=r.content)?u:"");return{summary:e,detail:t?"".concat(t.length," chars"):void 0}}case"file_edit":return{summary:String(null!=(p=null!=(m=null!=(x=r.path)?x:r.file)?m:r.filePath)?p:"")};case"file_list":return{summary:String(null!=(g=null!=(f=null!=(h=r.path)?h:r.directory)?f:r.dir)?g:".")};case"grep":{let e=String(null!=(b=null!=(v=r.pattern)?v:r.query)?b:""),t=r.path?" in ".concat(r.path):"",a=r.include?" (".concat(r.include,")"):"";return{summary:'"'.concat(e,'"').concat(t).concat(a)}}case"glob":{let e=String(null!=(y=null!=(j=r.pattern)?j:r.glob)?y:""),t=r.path?" in ".concat(r.path):"";return{summary:"".concat(e).concat(t)}}case"web_fetch":return{summary:String(null!=(w=r.url)?w:"")};case"delegate_task":{let e=String(null!=(N=r.agent_id)?N:""),t=String(null!=(S=null!=(k=r.task)?k:r.input)?S:""),a=t.length>100?t.slice(0,100)+"...":t;return{summary:e?"→ ".concat(e,": ").concat(a):a}}}}return{summary:t}})(t.name,t.input),[t.name,t.input]),u=(0,l.useMemo)(()=>{var e;return c?function(e,t){let r=tq(t);if(r){let e=r.toolResult;if(null==e?void 0:e.content){let t=e.content;if(Array.isArray(t)&&t.length>0&&t[0].text)return t[0].text}if("string"==typeof r.text)return r.text;if("string"==typeof r.result)return r.result;if("string"==typeof r.output)return r.output}return t}(t.name,(e=t.output).startsWith(tZ+"\n")?e.slice(tZ.length+1):e.startsWith(tV+"\n")?e.slice(tV.length+1):e):""},[t.name,t.output,c]),x=u.length>120?u.slice(0,120)+"...":u;return(0,s.jsxs)("div",{className:"my-0.5 text-[12px] font-mono",children:[(0,s.jsxs)("button",{onClick:()=>o(!n),className:"flex w-full items-center gap-1.5 rounded px-1 py-0.5 hover:bg-[var(--secondary)]/60 transition-colors text-left group",children:[(0,s.jsx)("span",{className:D("h-2 w-2 shrink-0 rounded-full",tY[i])}),n?(0,s.jsx)(W.A,{className:"h-3 w-3 shrink-0 text-[var(--muted-foreground)]"}):(0,s.jsx)(U.A,{className:"h-3 w-3 shrink-0 text-[var(--muted-foreground)]"}),(0,s.jsx)("span",{className:"shrink-0 font-semibold text-[var(--foreground)]",children:t.name}),(0,s.jsx)("span",{className:"truncate text-[var(--muted-foreground)]",children:d})]}),n&&(0,s.jsxs)("div",{className:"ml-[22px] mt-0.5 mb-1 rounded border border-[var(--border)] bg-[var(--card)] overflow-hidden",children:[(0,s.jsxs)("div",{className:"border-b border-[var(--border)] px-2.5 py-1.5",children:[(0,s.jsx)("div",{className:"text-[10px] uppercase tracking-wider text-[var(--muted-foreground)] opacity-60 mb-0.5",children:"IN"}),(0,s.jsx)("pre",{className:"text-[11px] text-[var(--foreground)] whitespace-pre-wrap break-all leading-relaxed",children:d})]}),c&&(0,s.jsxs)("div",{className:"px-2.5 py-1.5",children:[(0,s.jsx)("div",{className:"text-[10px] uppercase tracking-wider text-[var(--muted-foreground)] opacity-60 mb-0.5",children:"OUT"}),(0,s.jsx)("pre",{className:D("text-[11px] whitespace-pre-wrap break-all leading-relaxed max-h-[200px] overflow-y-auto","error"===i?"text-red-400":"warn"===i?"text-yellow-300":"text-[var(--foreground)]"),children:u})]}),"running"===i&&(0,s.jsxs)("div",{className:"px-2.5 py-1.5 flex items-center gap-1.5",children:[(0,s.jsx)(H.A,{className:"h-3 w-3 animate-spin text-amber-400"}),(0,s.jsx)("span",{className:"text-[11px] text-[var(--muted-foreground)]",children:"Running..."})]})]}),!n&&c&&x&&(0,s.jsx)("div",{className:"ml-[22px] text-[11px] text-[var(--muted-foreground)] truncate",children:x})]})}function tQ(e){let{children:t,maxLines:r=2,className:a}=e,n=(0,l.useRef)(null),[o,i]=(0,l.useState)(!1),[c,d]=(0,l.useState)(!1);return(0,l.useEffect)(()=>{let e=n.current;if(!e)return;let t=20*r+4,a=new ResizeObserver(()=>{let r=e.scrollHeight>t;i(e=>e===r?e:r)});return a.observe(e),()=>a.disconnect()},[r]),(0,s.jsxs)("div",{className:D("relative",a),children:[o&&(0,s.jsx)("button",{onClick:()=>d(!c),className:"absolute top-0 right-0 text-[11px] text-[var(--primary)] hover:underline z-10",children:c?"Show less":"Show more"}),(0,s.jsx)("div",{ref:n,style:!c&&o?{maxHeight:"".concat(20*r,"px"),overflow:"hidden"}:void 0,children:t})]})}function tX(e){let{children:t,className:r}=e,[a,n]=(0,l.useState)(!1),o=String(t).replace(/\n$/,""),i=(null==r?void 0:r.replace("language-",""))||"";return(0,s.jsxs)("div",{className:"relative group",children:[i&&(0,s.jsx)("span",{className:"absolute top-1 left-2 text-[9px] text-[var(--muted-foreground)] opacity-60",children:i}),(0,s.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(o).then(()=>{n(!0),setTimeout(()=>n(!1),2e3)})},className:"absolute top-1 right-1 rounded p-1 text-[var(--muted-foreground)] opacity-0 group-hover:opacity-100 hover:bg-[var(--accent)] transition-opacity",children:a?(0,s.jsx)(tD.A,{className:"h-3 w-3 text-emerald-400"}):(0,s.jsx)(tM.A,{className:"h-3 w-3"})}),(0,s.jsx)("code",{className:r,children:t})]})}var t0=r(62783),t1=r(14307),t5=r(51456),t3=r(93436),t2=r(48931),t4=r(56838);function t8(e,t,r,a){if(!a)return e;for(let s=e.length-1;s>=0;s--){var n;let l=e[s];if(l.taskId!==r||"assistant"!==l.role||!l.streaming||t&&l.agentName&&l.agentName.toLowerCase()!==t.toLowerCase())continue;let o=null!=(n=l.contentBlocks)?n:[],i=o.length>0?o[o.length-1].turnId:void 0;if(!i||i===a)return e;let c=[...e];return c[s]={...l,streaming:!1},c.push({id:M(),role:"assistant",content:"",timestamp:Date.now(),streaming:!0,agentName:t,taskId:r}),c}return[...e,{id:M(),role:"assistant",content:"",timestamp:Date.now(),streaming:!0,agentName:t,taskId:r}]}let t6=(0,c.v)((e,t)=>({messages:[],isStreaming:!1,sessionId:null,pendingMessages:[],contextTokens:0,outputTokens:0,maxContextTokens:0,isCompacting:!1,selectedAgentId:"default",usableAgentCount:-1,captureSource:null,addMessage(t){var r,a;let n={id:null!=(r=t.id)?r:M(),type:t.type,role:t.role,content:t.content,timestamp:null!=(a=t.timestamp)?a:Date.now(),plan:t.plan,streaming:t.streaming,agentName:t.agentName,taskId:t.taskId,contentBlocks:t.contentBlocks,toolName:t.toolName,toolInput:t.toolInput,toolOutput:t.toolOutput,systemPrompt:t.systemPrompt,usage:t.usage,turnId:t.turnId,modelId:t.modelId,durationMs:t.durationMs,localImages:t.localImages};e(e=>{var r,a;let s=e.messages.filter(ti).length;return console.log("[ChatStore:addMessage] role=".concat(n.role," type=").concat(null!=(r=n.type)?r:"-"," streaming=").concat(!!n.streaming," taskId=").concat(null!=(a=n.taskId)?a:"-"," main=").concat(s,"+").concat(+!!ti(n))),{messages:[...e.messages,n],isStreaming:!!t.streaming&&!t.taskId||e.isStreaming}})},appendThinking(t,r,a,n){e(e=>{let s=[...t8(e.messages,r,a,n)];for(let e=s.length-1;e>=0;e--){let r=s[e];if("assistant"===r.role&&r.streaming){var l;if(r.taskId!==a)continue;let o=[...null!=(l=r.contentBlocks)?l:[]],i=o[o.length-1];i&&"thinking"===i.type&&(!n||i.turnId===n)?o[o.length-1]={type:"thinking",text:i.text+t,turnId:null!=n?n:i.turnId}:o.push({type:"thinking",text:t,turnId:n}),s[e]={...r,contentBlocks:o};break}}return{messages:s}})},updateLastAssistant(t,r,a,n){e(e=>{let s=[...t8(e.messages,r,a,n)],l=!1;for(let e=s.length-1;e>=0;e--){let r=s[e];if("assistant"===r.role&&r.streaming){var o;if(r.taskId!==a)continue;let i=[...null!=(o=r.contentBlocks)?o:[]],c=i[i.length-1];c&&"text"===c.type&&(!n||c.turnId===n)?i[i.length-1]={type:"text",text:c.text+t,turnId:null!=n?n:c.turnId}:i.push({type:"text",text:t,turnId:n}),s[e]={...r,content:r.content+t,contentBlocks:i},l=!0;break}}return l&&!a?{messages:s,isStreaming:!0}:{messages:s}})},addToolCallToLastAssistant(t,r,a,n){e(e=>{let s=[...t8(e.messages,r,a,n)];for(let e=s.length-1;e>=0;e--){let r=s[e];if("assistant"===r.role&&r.streaming){var l,o;if(r.taskId!==a)continue;let i=[...null!=(l=r.contentBlocks)?l:[]];i.push({type:"tool_call",toolCall:t,turnId:n}),s[e]={...r,toolCalls:[...null!=(o=r.toolCalls)?o:[],t],contentBlocks:i};break}}return{messages:s}})},updateLastToolCallResult(t,r,a){e(e=>{let r=[...e.messages];for(let e=r.length-1;e>=0;e--){var n,s;let l=r[e];if("assistant"===l.role&&l.streaming&&(null==(n=l.toolCalls)?void 0:n.length)){if(l.taskId!==a)continue;let n=[...l.toolCalls],o=n[n.length-1];n[n.length-1]={...o,output:t};let i=[...null!=(s=l.contentBlocks)?s:[]];for(let e=i.length-1;e>=0;e--){let r=i[e];if("tool_call"===r.type&&!r.toolCall.output){i[e]={type:"tool_call",toolCall:{...r.toolCall,output:t},turnId:r.turnId};break}}r[e]={...l,toolCalls:n,contentBlocks:i};break}}return{messages:r}})},completeStreaming(){e(e=>({messages:e.messages.map(e=>e.streaming?{...e,streaming:!1}:e),isStreaming:!1}))},completeAgentStreaming(t,r){e(e=>{let a=e.messages.filter(ti).length,n=e.messages.map(e=>e.streaming?(!r||e.taskId!==r)&&(r||e.taskId)?e:{...e,streaming:!1}:e),s=n.filter(ti).length,l=n.some(e=>e.streaming&&!e.taskId);return a!==s&&console.warn("[ChatStore:completeAgentStreaming] main msgs changed ".concat(a," -> ").concat(s,", agentName=").concat(t,", taskId=").concat(r)),{messages:n,isStreaming:l}})},setSessionId(t){e({sessionId:t})},setMessages(r){var a;let n=t().messages;console.log("[ChatStore:setMessages] ".concat(n.length," -> ").concat(r.length),null==(a=Error().stack)?void 0:a.split("\n").slice(1,4).join(" <- ")),e({messages:r})},setTokenUsage(t,r){e({contextTokens:t,outputTokens:r})},setMaxContextTokens(t){t>0&&e({maxContextTokens:t})},setCompacting(t){e({isCompacting:t})},setSelectedAgentId(t){e({selectedAgentId:t})},setUsableAgentCount(t){e({usableAgentCount:t})},setCaptureSource(t){e({captureSource:t})},addPendingMessage(t){e(e=>({pendingMessages:[...e.pendingMessages,t]}))},removePendingMessage(t){e(e=>({pendingMessages:e.pendingMessages.filter((e,r)=>r!==t)}))},shiftPendingMessage(){let r=t().pendingMessages;if(0===r.length)return;let[a,...n]=r;return e({pendingMessages:n}),a},clear(){var r;console.log("[ChatStore:clear] dropping ".concat(t().messages.length," messages"),null==(r=Error().stack)?void 0:r.split("\n").slice(1,4).join(" <- ")),e({messages:[],isStreaming:!1,pendingMessages:[],sessionId:null,contextTokens:0,outputTokens:0})}})),t9=[{name:"/session",description:"Manage sessions (new/list/switch/stop/interrupt/compact/context)",type:"server",argHint:"<verb>"},{name:"/clear",description:"Clear chat (alias for /session new)",type:"client"},{name:"/help",description:"Show available commands",type:"client"}],t7=[];async function re(e,t,r){try{t7=(await v.F.commands.list(e,t,r)).commands.map(e=>({name:e.slashName,description:e.description,type:e.type,argHint:e.argHint,source:e.source,skillId:e.skillId,verbs:e.verbs}))}catch(e){t7=[]}}function rt(){return t7.length>0?t7:t9}function rr(e){let{commands:t,selectedIndex:r,onSelect:a}=e,n=(0,l.useRef)(null);return((0,l.useEffect)(()=>{var e;let t=null==(e=n.current)?void 0:e.children[r];null==t||t.scrollIntoView({block:"nearest"})},[r]),0===t.length)?null:(0,s.jsx)("div",{ref:n,className:"absolute bottom-full left-3 right-3 mb-1 max-h-48 overflow-y-auto rounded-lg border border-[var(--border)] bg-[var(--background)] shadow-lg z-20",children:t.map((e,t)=>(0,s.jsxs)("button",{onMouseDown:t=>{t.preventDefault(),a(e)},className:"flex w-full items-center gap-3 px-3 py-2 text-left text-sm transition-colors ".concat(t===r?"bg-[var(--accent)] text-[var(--foreground)]":"text-[var(--muted-foreground)] hover:bg-[var(--secondary)]"),children:[(0,s.jsx)("span",{className:"font-mono font-medium text-[var(--primary)]",children:e.name}),e.argHint&&(0,s.jsx)("span",{className:"text-xs text-[var(--muted-foreground)]",children:e.argHint}),(0,s.jsx)("span",{className:"flex-1 truncate text-xs",children:e.description})]},e.name))})}function ra(e){let{matches:t,selectedIndex:r,onSelect:a,dirs:n=!1}=e,o=(0,l.useRef)(null);return((0,l.useEffect)(()=>{var e;let t=null==(e=o.current)?void 0:e.children[r];null==t||t.scrollIntoView({block:"nearest"})},[r]),0===t.length)?null:(0,s.jsx)("div",{ref:o,className:"absolute bottom-full left-3 right-3 mb-1 max-h-48 overflow-y-auto rounded-lg border border-[var(--border)] bg-[var(--background)] shadow-lg z-20",children:t.map((e,t)=>{var l;let o=ec(e),i=n?_.A:o.Icon,c=n?"text-amber-500":o.color,d=null!=(l=e.split("/").pop())?l:e,u=e.includes("/")?e.slice(0,e.lastIndexOf("/")):"";return(0,s.jsxs)("button",{onMouseDown:t=>{t.preventDefault(),a(e)},className:D("flex w-full items-center gap-2 px-3 py-1.5 text-left text-sm transition-colors",t===r?"bg-[var(--accent)] text-[var(--foreground)]":"text-[var(--muted-foreground)] hover:bg-[var(--secondary)]"),children:[(0,s.jsx)(i,{className:D("h-3.5 w-3.5 shrink-0",c)}),(0,s.jsx)("span",{className:"truncate font-medium",children:d}),u&&(0,s.jsx)("span",{className:"ml-auto truncate text-xs text-[var(--muted-foreground)] opacity-60",children:u})]},e)})})}function rn(e){return new Promise((t,r)=>{let a=new FileReader;a.onload=()=>t(a.result.split(",")[1]),a.onerror=r,a.readAsDataURL(e)})}async function rs(e){if(!e.type.startsWith("image/"))return{base64:await rn(e),mimeType:e.type||"application/octet-stream"};try{let t=await createImageBitmap(e),r=Math.min(1,1568/Math.max(t.width,t.height)),a=Math.max(1,Math.round(t.width*r)),n=Math.max(1,Math.round(t.height*r)),s=document.createElement("canvas");s.width=a,s.height=n;let l=s.getContext("2d");if(!l)throw Error("no 2d context");l.drawImage(t,0,0,a,n),t.close();let o=s.toDataURL("image/jpeg",.85).split(",")[1];if(!o)throw Error("encode failed");return{base64:o,mimeType:"image/jpeg"}}catch(t){return{base64:await rn(e),mimeType:e.type||"image/png"}}}let rl=null,ro=null,ri=".halo/canvas/self.html";function rc(){let e=(0,tr.useT)(),t=e9(e=>e.activeProject);if(!t)return null;let r=async()=>{let e=t.id;try{let t=await v.F.files.read(ri,e);window.dispatchEvent(new CustomEvent("halo:navigate",{detail:{tab:"explorer"}})),p.getState().openFile(ri,t.content,z(ri),t.modifiedAt,{size:t.size,createdAt:t.createdAt}),setTimeout(()=>eW("self.intro()"),400)}catch(e){}};return(0,s.jsx)("button",{onClick:r,title:e("face.button"),className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-lg text-[var(--muted-foreground)] transition-colors hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,s.jsx)(t0.A,{className:"h-4 w-4"})})}function rd(e){var t;let{cameras:r,activeId:a,onPick:n,onTurnOff:o,onClose:i}=e,c=(0,tr.useT)(),[d,u]=(0,l.useState)(a||(null==(t=r[0])?void 0:t.deviceId)||""),x=(0,l.useRef)(null),m=(0,l.useRef)(null);return(0,l.useEffect)(()=>{let e=!1,t=()=>{if(m.current){for(let e of m.current.getTracks())e.stop();m.current=null}};return t(),navigator.mediaDevices.getUserMedia({video:!d||{deviceId:{exact:d}},audio:!1}).then(t=>{if(e){for(let e of t.getTracks())e.stop();return}m.current=t,x.current&&(x.current.srcObject=t,x.current.play().catch(()=>{}))}).catch(()=>{}),()=>{e=!0,t()}},[d]),(0,s.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/70 p-3",onClick:i,children:(0,s.jsxs)("div",{className:"flex w-[640px] max-w-[94vw] flex-col overflow-hidden rounded-xl border border-[var(--border)] bg-[var(--background)] shadow-2xl",onClick:e=>e.stopPropagation(),children:[(0,s.jsxs)("div",{className:"flex items-center justify-between border-b border-[var(--border)] px-4 py-3",children:[(0,s.jsx)("span",{className:"text-sm font-medium text-[var(--foreground)]",children:c("capture.cameraPick")}),(0,s.jsx)("button",{onClick:i,className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,s.jsx)(eK.A,{className:"h-4 w-4"})})]}),(0,s.jsx)("video",{ref:x,muted:!0,playsInline:!0,className:"aspect-video w-full bg-black object-contain"}),(0,s.jsx)("div",{className:"flex flex-col gap-1 p-2",children:r.map(e=>(0,s.jsxs)("button",{onClick:()=>u(e.deviceId),title:e.label,className:D("flex items-center gap-2 rounded px-2 py-1.5 text-left text-xs hover:bg-[var(--secondary)]",d===e.deviceId?"text-[var(--primary)]":"text-[var(--foreground)]"),children:[(0,s.jsx)(t1.A,{className:"h-3.5 w-3.5 shrink-0"}),(0,s.jsx)("span",{className:"min-w-0 flex-1 truncate",children:e.label}),a===e.deviceId&&(0,s.jsx)("span",{className:"shrink-0 text-[10px]",children:c("capture.cameraCurrent")})]},e.deviceId))}),(0,s.jsxs)("div",{className:"flex items-center justify-between gap-2 border-t border-[var(--border)] px-4 py-3",children:[o?(0,s.jsx)("button",{onClick:o,className:"text-xs text-[var(--muted-foreground)] hover:text-[var(--foreground)]",children:c("capture.cameraBound")}):(0,s.jsx)("span",{}),(0,s.jsx)("button",{onClick:()=>{let e=r.find(e=>e.deviceId===d);e&&n(e)},className:"rounded-md bg-[var(--primary)] px-3 py-1.5 text-xs font-medium text-white hover:opacity-90",children:c("capture.cameraUse")})]})]})})}function ru(){let e=(0,tr.useT)(),t=t6(e=>e.captureSource),r=t6(e=>e.setCaptureSource),[a,n]=(0,l.useState)(!1),[o,i]=(0,l.useState)([]),[c,d]=(0,l.useState)(!1),[u,x]=(0,l.useState)(!1),[m,p]=(0,l.useState)(!1),[h,f]=(0,l.useState)(!1),[g,b]=(0,l.useState)([]),[j,y]=(0,l.useState)(!1),w=(0,l.useRef)(null),N=window.haloCapture,k=window.haloCamera,S=function(){let e=t6(e=>e.selectedAgentId),t=e9(e=>{var t;return null==(t=e.activeProject)?void 0:t.path}),[r,a]=(0,l.useState)(!0);return(0,l.useEffect)(()=>{if(!t)return;let r=!1;return Promise.all([v.F.agentConfigs.list(t),rl?Promise.resolve(rl):(!ro&&(ro=v.F.agentConfigs.models().then(e=>{let t={};for(let a of e.providers){var r;for(let e of a.models)t[e.id]=!!(null==(r=e.capabilities)?void 0:r.image)}return rl=t,t}).catch(()=>({}))),ro)]).then(t=>{var n;let[s,l]=t;if(r)return;let o=null!=(n=s.agents.find(t=>t.id===e))?n:s.agents[0],i=null==o?void 0:o.model;if(!i||!(i in l))return void a(!0);a(l[i])}).catch(()=>{r||a(!0)}),()=>{r=!0}},[e,t]),r}();if((0,l.useEffect)(()=>{!S&&t&&r(null)},[S,t,r]),(0,l.useEffect)(()=>{if(!k||!S)return void p(!1);let e=!1;return k.has().then(t=>{e||p(t)}).catch(()=>{}),()=>{e=!0}},[k,S]),(0,l.useEffect)(()=>{if(!a&&!j)return;let e=e=>{w.current&&!w.current.contains(e.target)&&(n(!1),y(!1))},t=e=>{"Escape"===e.key&&(n(!1),y(!1))};return document.addEventListener("mousedown",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",t)}},[a,j]),!N&&!k||!S)return null;let C=async()=>{if(a)return void n(!1);n(!0),x(!0);try{let e=await N.list();i(e);let t=e.filter(e=>e.id.startsWith("screen:"));d(t.length>0&&t.every(e=>e.blank))}catch(e){i([])}finally{x(!1)}},A=(t,a)=>{if(f(!1),y(!1),t)try{localStorage.setItem("halo.cameraId",t)}catch(e){}r({id:t,name:a||e("capture.cameraName"),thumb:"",kind:"camera"})},I=async()=>{if((null==t?void 0:t.kind)==="camera")return void y(e=>!e);if(!await k.requestPermission())return void f(!0);let e=await k.list();if(0===e.length)return void A("",void 0);b(e),y(!0)};return(0,s.jsxs)("div",{ref:w,className:"relative flex items-center gap-1",children:[N&&(0,s.jsx)("button",{onClick:C,title:(null==t?void 0:t.kind)==="screen"?e("capture.bound",{name:t.name}):e("capture.button"),className:D("flex h-8 w-8 shrink-0 items-center justify-center rounded-lg transition-colors hover:bg-[var(--secondary)]",(null==t?void 0:t.kind)==="screen"?"text-[var(--primary)]":"text-[var(--muted-foreground)] hover:text-[var(--foreground)]"),children:(0,s.jsx)(t5.A,{className:"h-4 w-4"})}),k&&m&&(0,s.jsx)("button",{onClick:I,title:(null==t?void 0:t.kind)==="camera"?e("capture.cameraBound"):e("capture.cameraButton"),className:D("flex h-8 w-8 shrink-0 items-center justify-center rounded-lg transition-colors hover:bg-[var(--secondary)]",(null==t?void 0:t.kind)==="camera"?"text-[var(--primary)]":"text-[var(--muted-foreground)] hover:text-[var(--foreground)]"),children:(0,s.jsx)(t1.A,{className:"h-4 w-4"})}),t&&(0,s.jsxs)("div",{className:"flex items-center gap-1 rounded-full border border-[var(--primary)]/30 bg-[var(--primary)]/10 px-1.5 py-0.5 text-[10px] text-[var(--primary)]",children:["camera"===t.kind?(0,s.jsx)(t1.A,{className:"h-3.5 w-3.5"}):t.thumb?(0,s.jsx)("img",{src:t.thumb,alt:"",className:"h-3.5 w-3.5 rounded-sm object-cover"}):(0,s.jsx)(t5.A,{className:"h-3.5 w-3.5"}),(0,s.jsx)("span",{className:"max-w-24 truncate",children:t.name}),(0,s.jsx)("button",{onClick:()=>r(null),title:e("capture.unbind"),className:"ml-0.5 rounded-full p-0.5 hover:bg-[var(--primary)]/20",children:(0,s.jsx)(eK.A,{className:"h-2.5 w-2.5"})})]}),h&&(0,s.jsxs)("div",{className:"absolute bottom-full left-0 z-50 mb-1 w-64 rounded-md border border-amber-500/30 bg-[var(--background)] p-2.5 text-xs text-amber-300 shadow-lg",children:[(0,s.jsx)("div",{children:e("capture.cameraPermissionHint")}),(0,s.jsxs)("div",{className:"mt-1.5 flex items-center gap-3",children:[(0,s.jsx)("button",{onClick:()=>k.openSettings(),className:"underline hover:text-amber-200",children:e("capture.openSettings")}),(0,s.jsx)("button",{onClick:()=>f(!1),className:"text-[var(--muted-foreground)] hover:text-[var(--foreground)]",children:e("capture.dismiss")})]})]}),j&&g.length>=1&&(0,s.jsx)(rd,{cameras:g,activeId:(null==t?void 0:t.kind)==="camera"?t.id:null,onPick:e=>A(e.deviceId,e.label),onTurnOff:(null==t?void 0:t.kind)==="camera"?()=>{r(null),y(!1)}:void 0,onClose:()=>y(!1)}),a&&(0,s.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/70 p-3",onClick:()=>n(!1),children:(0,s.jsxs)("div",{className:"flex h-[92vh] w-[96vw] flex-col overflow-hidden rounded-xl border border-[var(--border)] bg-[var(--background)] shadow-2xl",onClick:e=>e.stopPropagation(),children:[(0,s.jsxs)("div",{className:"flex items-center justify-between border-b border-[var(--border)] px-4 py-3",children:[(0,s.jsx)("span",{className:"text-sm font-medium text-[var(--foreground)]",children:e("capture.pickTitle")}),(0,s.jsx)("button",{onClick:()=>n(!1),className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,s.jsx)(eK.A,{className:"h-4 w-4"})})]}),(0,s.jsxs)("div",{className:"flex-1 overflow-y-auto p-4",children:[c&&(0,s.jsxs)("div",{className:"mb-3 rounded-md border border-amber-500/30 bg-amber-500/10 p-3 text-xs text-amber-300",children:[(0,s.jsx)("div",{children:e("capture.permissionHint")}),(0,s.jsx)("button",{onClick:()=>N.openSettings(),className:"mt-1.5 underline hover:text-amber-200",children:e("capture.openSettings")})]}),u?(0,s.jsx)("div",{className:"py-8 text-center text-xs text-[var(--muted-foreground)]",children:e("capture.loading")}):0===o.length?(0,s.jsx)("div",{className:"py-8 text-center text-xs text-[var(--muted-foreground)]",children:e("capture.empty")}):(0,s.jsx)("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(220px,1fr))] gap-3",children:o.map(t=>(0,s.jsxs)("button",{onClick:()=>{var e;r({id:t.id,name:t.name,thumb:null!=(e=t.thumb)?e:"",kind:"screen"}),n(!1)},title:t.name,className:"flex min-w-0 flex-col gap-1.5 overflow-hidden rounded-lg border border-[var(--border)] p-2 text-left transition-colors hover:border-[var(--primary)] hover:bg-[var(--secondary)]",children:[t.thumb?(0,s.jsx)("img",{src:t.thumb,alt:t.name,className:"aspect-video w-full rounded object-cover bg-black/20"}):(0,s.jsx)("div",{className:"flex aspect-video w-full items-center justify-center rounded bg-black/20 text-[10px] text-[var(--muted-foreground)]",children:e("capture.noPreview")}),(0,s.jsxs)("div",{className:"flex min-w-0 items-center gap-1.5",children:[t.icon&&(0,s.jsx)("img",{src:t.icon,alt:"",className:"h-4 w-4 shrink-0"}),(0,s.jsx)("span",{className:"min-w-0 flex-1 truncate text-xs text-[var(--foreground)]",children:t.name})]})]},t.id))})]})]})})]})}function rx(e){let{onCompact:t}=e,r=t6(e=>e.messages),a=t6(e=>e.contextTokens),n=t6(e=>e.maxContextTokens),o=t6(e=>e.isCompacting),i=t6(e=>e.isStreaming),c=(0,l.useMemo)(()=>a>0?a:0,[a]);if(0===c||0===r.length||0===n)return null;let d=Math.min(c/n*100,100),u=(c/1e3).toFixed(2),x=2*Math.PI*8,m=r.length>5&&t&&!o&&!i;return(0,s.jsx)("div",{className:D("flex h-8 w-8 shrink-0 items-center justify-center rounded-lg",m&&"cursor-pointer hover:bg-[var(--secondary)]"),title:o?"Compacting...":"~".concat(u,"K / ").concat(n/1e3,"K tokens (").concat(Math.round(d),"%)").concat(m?"\nClick to compact context":""),onClick:m?t:void 0,children:(0,s.jsxs)("svg",{width:"22",height:"22",viewBox:"0 0 22 22",className:D("transform -rotate-90",o&&"animate-pulse"),children:[(0,s.jsx)("circle",{cx:"11",cy:"11",r:8,fill:"none",stroke:"var(--muted-foreground)",strokeWidth:"2.5",opacity:"0.3"}),(0,s.jsx)("circle",{cx:"11",cy:"11",r:8,fill:"none",stroke:o?"#3b82f6":d<50?"#22c55e":d<70?"#eab308":d<85?"#f97316":"#ef4444",strokeWidth:"2.5",strokeDasharray:x,strokeDashoffset:x-d/100*x,strokeLinecap:"round",className:"transition-all duration-300"})]})})}function rm(e){let{onSend:t,disabled:r,isStreaming:a,onStop:n,onInterrupt:o,pendingMessages:i,onRemovePending:c,onCommand:d,onCompact:u,renderLeftControls:x}=e,m=p(e=>e.selectedText),h=p(e=>e.selectedRange),f=p(e=>e.activeTab),g=p(e=>e.contextEnabled),b=p(e=>e.setContextEnabled),[j,y]=(0,l.useState)(""),[w,N]=(0,l.useState)([]),[k,S]=(0,l.useState)(!1),[C,A]=(0,l.useState)(0),[I,E]=(0,l.useState)([]),[T,F]=(0,l.useState)(0),[M,P]=(0,l.useState)(0),[L,R]=(0,l.useState)(!1),z=(0,l.useRef)(null),_=(0,l.useRef)(null),O=e9(e=>e.activeProject),W=0===t6(e=>e.usableAgentCount),U=(0,l.useMemo)(()=>{var e,t;if(m&&f){let t=null!=(e=f.split("/").pop())?e:f,r=h?":".concat(h.startLine,"-").concat(h.endLine):"";return"".concat(t).concat(r," (").concat(m.length," chars)")}return f?null!=(t=f.split("/").pop())?t:f:null},[m,h,f]),B=(0,l.useMemo)(()=>{if(!j.startsWith("/")||/\s/.test(j))return[];if(!j.startsWith("/"))return[];let e=j.toLowerCase();return rt().filter(t=>t.name.startsWith(e))},[j]),H=(0,l.useMemo)(()=>(function(e){var t;let r=e.match(/^(\/\S+)\s+(\S*)$/);if(!r)return[];let a=rt().find(e=>e.name===r[1].toLowerCase());if(!(null==a||null==(t=a.verbs)?void 0:t.length))return[];let n=r[2].toLowerCase();return a.verbs.filter(e=>e.name.startsWith(n)&&e.name!==n).map(e=>({cmd:a,verb:e}))})(j),[j]),[K,G]=(0,l.useState)(0);(0,l.useEffect)(()=>{G(0)},[H.length]);let J=(0,l.useCallback)(e=>{var t;y("".concat(e.cmd.name," ").concat(e.verb.name," ")),null==(t=z.current)||t.focus()},[]),q=(0,l.useMemo)(()=>{let e=j.slice(0,M).match(/(^|\s)@scope\s+(\S*)$/);return e?{startIdx:e.index+e[1].length,query:e[2]}:null},[j,M]),Z=(0,l.useMemo)(()=>{if(q)return null;let e=j.slice(0,M).match(/(^|\s)@(\S*)$/);return e?{startIdx:e.index+e[1].length,query:e[2]}:null},[j,M,q]),[V,Y]=(0,l.useState)([]);(0,l.useEffect)(()=>{if(!Z||L||!O)return void Y([]);let e=!1,t=setTimeout(()=>{v.F.files.search(O.id,Z.query,15).then(t=>{e||Y(t.matches.map(e=>e.path))}).catch(()=>{e||Y([])})},120);return()=>{e=!0,clearTimeout(t)}},[Z,L,O]);let $=(0,l.useCallback)(e=>{if(!Z)return;let t=j.slice(0,Z.startIdx);y(t+j.slice(Z.startIdx+1+Z.query.length)),E(t=>t.includes(e)?t:[...t,e]),F(0),R(!1),requestAnimationFrame(()=>{if(z.current){let e=t.length;z.current.selectionStart=e,z.current.selectionEnd=e,z.current.focus(),P(e)}})},[j,Z]),[Q,X]=(0,l.useState)([]),[ee,et]=(0,l.useState)(0);(0,l.useEffect)(()=>{if(!q||!O)return void X([]);let e=!1,t=setTimeout(()=>{v.F.files.search(O.id,q.query,15,!0).then(t=>{e||X(t.matches.map(e=>e.path))}).catch(()=>{e||X([])})},120);return()=>{e=!0,clearTimeout(t)}},[q,O]);let er=(0,l.useCallback)(e=>{if(!q)return;let t=j.slice(0,q.startIdx),r=j.slice(M),a="@scope ".concat(e," ");y(t+a+r),et(0),requestAnimationFrame(()=>{if(z.current){let e=t.length+a.length;z.current.selectionStart=e,z.current.selectionEnd=e,z.current.focus(),P(e)}})},[j,q,M]),ea=(0,l.useCallback)(e=>{E(t=>t.filter(t=>t!==e))},[]),en=(0,l.useCallback)(e=>{var t,r;let a=j.split(/\s+/),n=null!=(t=a[0])?t:"",s=a.slice(1).join(" ");if(e.argHint&&!s&&n!==e.name){y(e.name+" "),A(0),null==(r=z.current)||r.focus();return}null==d||d(e,s),y(""),A(0),z.current&&(z.current.style.height="auto")},[j,d]),es=(0,l.useCallback)(e=>{let t=Array.from(e).filter(e=>e.type.startsWith("image/")).map(e=>({file:e,preview:URL.createObjectURL(e)}));N(e=>[...e,...t])},[]),eo=(0,l.useCallback)(e=>{N(t=>{let r=t[e];return(null==r?void 0:r.preview)&&URL.revokeObjectURL(r.preview),t.filter((t,r)=>r!==e)})},[]),ei=(0,l.useCallback)(async()=>{var e,r;let a=j.trim();if(!a&&0===w.length||W)return;if(H.length>0)return void J(null!=(e=H[K])?e:H[0]);if(a.startsWith("/")){if(B.length>0)return void en(null!=(r=B[C])?r:B[0]);let e=rt().find(e=>{var t;return e.name===(null==(t=a.split(/\s+/)[0])?void 0:t.toLowerCase())});if(e)return void en(e)}let n=[];for(let e of w)try{let{base64:t,mimeType:r}=await rs(e.file);n.push({data:t,mimeType:r})}catch(e){console.error("[MessageInput] Image conversion failed:",e)}(a||n.length>0)&&t(a||"(image)",n.length>0?n:void 0,I.length>0?I:void 0),w.forEach(e=>{e.preview&&URL.revokeObjectURL(e.preview)}),N([]),E([]),y(""),z.current&&(z.current.style.height="auto")},[j,w,t,B,C,en,I,H,K,J,W]),ec=(0,l.useCallback)(e=>{if(Q.length>0){if("ArrowDown"===e.key){e.preventDefault(),et(e=>Math.min(e+1,Q.length-1));return}if("ArrowUp"===e.key){e.preventDefault(),et(e=>Math.max(e-1,0));return}if("Tab"===e.key||"Enter"===e.key&&!e.nativeEvent.isComposing){e.preventDefault();let t=Q[ee];t&&er(t);return}if("Escape"===e.key){e.preventDefault(),X([]);return}}if(V.length>0){if("ArrowDown"===e.key){e.preventDefault(),F(e=>Math.min(e+1,V.length-1));return}if("ArrowUp"===e.key){e.preventDefault(),F(e=>Math.max(e-1,0));return}if("Tab"===e.key||"Enter"===e.key&&!e.nativeEvent.isComposing){e.preventDefault();let t=V[T];t&&$(t);return}if("Escape"===e.key){e.preventDefault(),R(!0);return}}if(H.length>0){if("ArrowDown"===e.key){e.preventDefault(),G(e=>Math.min(e+1,H.length-1));return}if("ArrowUp"===e.key){e.preventDefault(),G(e=>Math.max(e-1,0));return}if("Tab"===e.key){e.preventDefault();let t=H[K];t&&J(t);return}if("Escape"===e.key){e.preventDefault(),G(0);return}}if(B.length>0){if("ArrowDown"===e.key){e.preventDefault(),A(e=>Math.min(e+1,B.length-1));return}if("ArrowUp"===e.key){e.preventDefault(),A(e=>Math.max(e-1,0));return}if("Escape"===e.key){e.preventDefault(),y(""),A(0);return}if("Tab"===e.key){e.preventDefault();let t=B[C];t&&y(t.name+" ");return}}if("Escape"===e.key&&a&&!j.trim()&&o){e.preventDefault(),o();return}"Enter"!==e.key||e.nativeEvent.isComposing||e.shiftKey||e.metaKey||e.ctrlKey||(e.preventDefault(),ei())},[ei,B,C,H,K,J,V,T,$,Q,ee,er,a,j,o]),ed=(0,l.useCallback)(e=>{y(e.target.value),P(e.target.selectionStart),A(0),R(!1),F(0),et(0);let t=e.target;t.style.height="auto",t.style.height=Math.min(t.scrollHeight,200)+"px"},[]),eu=(0,l.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),S(!0)},[]),ex=(0,l.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),S(!1)},[]),em=(0,l.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),S(!1),e.dataTransfer.files.length>0&&es(e.dataTransfer.files)},[es]),ep=(0,l.useCallback)(e=>{let t=e.clipboardData.items,r=[];for(let e=0;e<t.length;e++){let a=t[e];if("file"===a.kind){let e=a.getAsFile();e&&r.push(e)}}r.length>0&&(e.preventDefault(),es(r))},[es]);return(0,s.jsxs)("div",{className:D("relative px-3 pb-3 pt-1 transition-colors",k&&"bg-[var(--accent)]"),onDragOver:eu,onDragLeave:ex,onDrop:em,children:[(0,s.jsx)(rr,{commands:B,selectedIndex:C,onSelect:en}),(0,s.jsx)(rr,{commands:H.map(e=>{var t;return{name:"".concat(e.cmd.name," ").concat(e.verb.name),description:null!=(t=e.verb.desc)?t:"",type:"server"}}),selectedIndex:K,onSelect:e=>{var t;y(e.name+" "),null==(t=z.current)||t.focus()}}),(0,s.jsx)(ra,{matches:V,selectedIndex:T,onSelect:$}),(0,s.jsx)(ra,{matches:Q,selectedIndex:ee,onSelect:er,dirs:!0}),k&&(0,s.jsx)("div",{className:"absolute inset-0 z-10 flex items-center justify-center rounded-xl bg-[var(--accent)]/80 border-2 border-dashed border-[var(--primary)]",children:(0,s.jsx)("p",{className:"text-sm text-[var(--primary)]",children:"Drop images here"})}),(0,s.jsx)("input",{ref:_,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:e=>{e.target.files&&es(e.target.files),e.target.value=""}}),(0,s.jsxs)("div",{className:D("rounded-2xl border border-[var(--border)] bg-[var(--secondary)] transition-colors","focus-within:border-[var(--primary)] focus-within:ring-1 focus-within:ring-[var(--primary)]"),children:[(0,s.jsx)("textarea",{ref:z,value:j,onChange:ed,onKeyDown:ec,onPaste:ep,onSelect:e=>P(e.target.selectionStart),placeholder:W?"All agents are disabled — enable one in the Agents tab to chat":a?"Send to interrupt current response...":"Type @ to reference files...",rows:1,className:"w-full resize-none bg-transparent px-3.5 pt-3 pb-1 text-sm text-[var(--foreground)] placeholder-[var(--muted-foreground)] outline-none max-h-[200px]"}),(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-1 px-2 pb-2",children:[(0,s.jsx)("button",{onClick:()=>{var e;return null==(e=_.current)?void 0:e.click()},disabled:r,title:"Attach images",className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-lg text-[var(--muted-foreground)] transition-colors hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,s.jsx)(t3.A,{className:"h-4 w-4"})}),(0,s.jsx)(ru,{}),(0,s.jsx)(rc,{}),(0,s.jsx)(rx,{onCompact:u}),null==x?void 0:x(),null==i?void 0:i.map((e,t)=>(0,s.jsxs)("div",{className:"flex items-center gap-1 rounded-full border border-[var(--border)] bg-[var(--background)] px-2 py-0.5 text-[10px] text-[var(--muted-foreground)]",children:[(0,s.jsx)("span",{className:"max-w-32 truncate",children:e}),(0,s.jsx)("button",{onClick:()=>null==c?void 0:c(t),className:"ml-0.5 rounded-full p-0.5 hover:bg-[var(--accent)] hover:text-[var(--foreground)]",children:(0,s.jsx)(eK.A,{className:"h-2.5 w-2.5"})})]},"q-".concat(t))),U&&(0,s.jsx)("button",{onClick:()=>b(!g),title:g?"Click to exclude context":"Click to include context",className:D("flex items-center gap-1 rounded-full border px-2 py-0.5 text-[10px] transition-colors",g?"bg-blue-500/10 border-blue-500/20 text-blue-400":"bg-[var(--background)] border-[var(--border)] text-[var(--muted-foreground)] line-through opacity-60"),children:(0,s.jsx)("span",{className:"max-w-36 truncate",children:U})}),I.map(e=>(0,s.jsxs)("div",{className:"flex items-center gap-1 rounded-full border border-green-500/20 bg-green-500/10 px-2 py-0.5 text-[10px] text-green-400",children:[(0,s.jsxs)("span",{className:"max-w-32 truncate",children:["@",e.split("/").pop()]}),(0,s.jsx)("button",{onClick:()=>ea(e),className:"ml-0.5 rounded-full p-0.5 hover:bg-green-500/20 hover:text-green-300",children:(0,s.jsx)(eK.A,{className:"h-2.5 w-2.5"})})]},"@".concat(e))),w.map((e,t)=>(0,s.jsxs)("div",{className:"flex items-center gap-1 rounded-lg border border-[var(--border)] bg-[var(--background)] px-2 py-0.5",children:[e.preview?(0,s.jsx)("img",{src:e.preview,alt:e.file.name,className:"h-5 w-5 rounded object-cover"}):(0,s.jsx)(el.A,{className:"h-3.5 w-3.5 text-[var(--muted-foreground)]"}),(0,s.jsx)("span",{className:"max-w-20 truncate text-[10px] text-[var(--muted-foreground)]",children:e.file.name}),(0,s.jsx)("button",{onClick:()=>eo(t),className:"ml-0.5 rounded p-0.5 text-[var(--muted-foreground)] hover:bg-[var(--accent)] hover:text-[var(--foreground)]",children:(0,s.jsx)(eK.A,{className:"h-2.5 w-2.5"})})]},"f-".concat(t))),(0,s.jsx)("div",{className:"flex-1"}),a&&!j.trim()&&0===w.length?(0,s.jsx)("button",{onClick:n,title:"Stop generation",className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-red-600 text-white transition-colors hover:bg-red-700",children:(0,s.jsx)(t2.A,{className:"h-3.5 w-3.5 fill-current"})}):(0,s.jsx)("button",{onClick:ei,disabled:W||!j.trim()&&0===w.length,title:W?"All agents are disabled — enable one to chat":a&&j.trim()?"Send (interrupts current response)":"Send (Enter)",className:D("flex h-8 w-8 shrink-0 items-center justify-center rounded-lg transition-colors",!W&&(j.trim()||w.length>0)?a?"bg-orange-600 text-white hover:bg-orange-700":"bg-[var(--primary)] text-[var(--primary-foreground)] hover:bg-blue-600":"text-[var(--muted-foreground)] cursor-not-allowed"),children:(0,s.jsx)(t4.A,{className:"h-4 w-4"})})]})]})]})}function rp(e){return"halo_session_".concat(e)}let rh="halo_session_id";function rf(e){let t=localStorage.getItem(rp(e));if(t)return t;let r=localStorage.getItem(rh);return r?(localStorage.setItem(rp(e),r),localStorage.removeItem(rh),r):null}function rg(e,t){localStorage.setItem(rp(e),t)}function rv(e){localStorage.removeItem(rp(e))}let rb=(0,c.v)(e=>({version:0,bump:()=>e(e=>({version:e.version+1}))}));function rj(){rb.getState().bump()}var ry=r(57580);function rw(e){let t="number"==typeof e?e:new Date(e).getTime(),r=Math.floor((Date.now()-t)/1e3);if(r<60)return"just now";let a=Math.floor(r/60);if(a<60)return"".concat(a,"m ago");let n=Math.floor(a/60);if(n<24)return"".concat(n,"h ago");let s=Math.floor(n/24);return s<30?"".concat(s,"d ago"):new Date(t).toLocaleDateString()}function rN(e){let{sessions:t,currentSessionId:r,onSelect:a,onDelete:n,onNew:o,onLoadMore:i,hasMore:c=!1,loadingMore:d=!1,open:u,onToggle:x,direction:m="down"}=e,[p,h]=(0,l.useState)(!1),f=null!=u?u:p,g=()=>x?x():h(!1),v=(0,l.useRef)(null);return((0,l.useEffect)(()=>{let e=v.current;if(!e||!f||!i||"undefined"==typeof IntersectionObserver)return;let t=new IntersectionObserver(e=>{var t;(null==(t=e[0])?void 0:t.isIntersecting)&&i()},{rootMargin:"48px"});return t.observe(e),()=>t.disconnect()},[f,i,t.length]),0!==t.length||o)?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("button",{onClick:null!=x?x:()=>h(e=>!e),title:"Session history",className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-lg text-[var(--muted-foreground)] transition-colors hover:bg-[var(--secondary)] hover:text-[var(--foreground)] relative",children:[(0,s.jsx)(ry.A,{className:"h-4 w-4"}),(0,s.jsx)("span",{className:"absolute -top-0.5 -right-0.5 flex h-3.5 min-w-[14px] items-center justify-center rounded-full bg-[var(--muted-foreground)] px-0.5 text-[8px] font-medium text-[var(--background)]",children:t.length})]}),f&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"fixed inset-0 z-20",onClick:g}),(0,s.jsxs)("div",{className:D("absolute z-30 max-h-64 overflow-y-auto border border-[var(--border)] bg-[var(--background)] shadow-lg","up"===m?"bottom-full left-0 mb-0.5 min-w-[280px] rounded-t-lg border-b-0":"top-full left-0 right-0 mt-0.5 rounded-b-lg border-t-0"),children:[(0,s.jsxs)("div",{className:"flex items-center justify-between px-3 py-1.5 border-b border-[var(--border)]",children:[(0,s.jsx)("span",{className:"text-[10px] font-medium text-[var(--muted-foreground)] uppercase tracking-wider",children:"Recent Sessions"}),o&&(0,s.jsx)("button",{onClick:()=>{o(),g()},className:"text-[10px] text-[var(--primary)] hover:underline",children:"+ New"})]}),0===t.length?(0,s.jsx)("div",{className:"px-3 py-4 text-center text-[10px] text-[var(--muted-foreground)]",children:"No sessions yet"}):t.map(e=>{var t;return(0,s.jsxs)("div",{onClick:()=>{a(e.id),g()},className:D("group flex items-center gap-2 px-3 py-2 cursor-pointer transition-colors hover:bg-[var(--secondary)]/50",r===e.id&&"bg-[var(--secondary)]"),children:[(0,s.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,s.jsx)("p",{className:"text-[11px] text-[var(--foreground)] truncate",children:e.title}),(0,s.jsxs)("p",{className:"text-[9px] text-[var(--muted-foreground)]",children:[e.messageCount," msgs \xb7 ",rw(e.updatedAt),"string"==typeof(null==(t=e.agentSnapshot)?void 0:t.model)&&(0,s.jsxs)("span",{className:"ml-1 opacity-60",children:["\xb7 ",e.agentSnapshot.model.split(".").pop()]})]})]}),(0,s.jsx)("button",{onClick:t=>{t.stopPropagation(),n(e.id,t)},className:"shrink-0 rounded p-0.5 text-[var(--muted-foreground)] opacity-0 group-hover:opacity-100 hover:text-red-400 transition-opacity",children:(0,s.jsx)(ej.A,{className:"h-3 w-3"})})]},e.id)}),c&&(0,s.jsx)("div",{ref:v,className:"flex items-center justify-center py-2 text-[9px] text-[var(--muted-foreground)]",children:d?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(H.A,{className:"h-2.5 w-2.5 animate-spin mr-1"})," Loading…"]}):(0,s.jsx)("span",{className:"opacity-50",children:"scroll for more"})})]})]})]}):null}function rk(e){let{count:t,onClick:r}=e;return 0===t?null:(0,s.jsxs)("button",{onClick:r,className:"flex items-center gap-1 text-[10px] text-[var(--primary)] hover:underline",children:[(0,s.jsx)(ry.A,{className:"h-3 w-3"}),t," previous session",t>1?"s":""]})}var rS=r(63865),rC=r(87097),rA=r(28968);let rI=(0,c.v)(e=>({version:0,bump:()=>e(e=>({version:e.version+1}))}));function rE(){rI.getState().bump()}function rT(){var e,t;let r=t6(e=>e.selectedAgentId),a=t6(e=>e.sessionId),n=t6(e=>e.isStreaming),o=e9(e=>e.activeProject),[i,c]=(0,l.useState)([]),[d,u]=(0,l.useState)(!1),x=(0,l.useRef)(null),m=rI(e=>e.version);(0,l.useEffect)(()=>{(null==o?void 0:o.path)&&(v.F.agentConfigs.list(o.path).then(e=>{let t=e.agents.filter(e=>!e.overridden&&!e.disabled&&!e.internal).map(e=>{var t;return{id:e.id,name:e.name,scope:e.scope,priority:null!=(t=e.priority)?t:0}}).sort((e,t)=>t.priority-e.priority||e.name.localeCompare(t.name));c(t),t6.getState().setUsableAgentCount(t.length);let r=t6.getState();!r.sessionId&&"default"===r.selectedAgentId&&t[0]&&"default"!==t[0].id&&r.setSelectedAgentId(t[0].id)}).catch(()=>{}),re(o.path,null!=a?a:void 0,null!=r?r:void 0).catch(()=>{}))},[null==o?void 0:o.path,a,r,m]),(0,l.useEffect)(()=>{if(!d)return;let e=e=>{x.current&&!x.current.contains(e.target)&&u(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[d]);let p=!!a,h=null!=(e=i.find(e=>e.id===r))?e:i[0],f=null!=(t=null==h?void 0:h.name)?t:r;return i.length<=1?null:(0,s.jsxs)("div",{ref:x,className:"relative",children:[(0,s.jsxs)("button",{onClick:()=>!p&&!n&&u(!d),disabled:p||n,title:p?"Agent is locked to current session. Start a new session to switch.":"Select agent",className:D("flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10px] font-medium transition-colors",p?"text-[var(--muted-foreground)] opacity-50 cursor-default":"text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]"),children:[(0,s.jsx)(rS.A,{className:"h-3 w-3"}),(0,s.jsx)("span",{className:"max-w-[80px] truncate",children:f}),!p&&(0,s.jsx)(W.A,{className:"h-2.5 w-2.5"})]}),d&&(0,s.jsx)("div",{className:"absolute bottom-full left-0 mb-1 min-w-[160px] max-h-60 overflow-y-auto rounded-lg border border-[var(--border)] bg-[var(--background)] shadow-lg z-30",children:i.map(e=>(0,s.jsxs)("button",{onClick:()=>{t6.getState().setSelectedAgentId(e.id),u(!1)},className:D("flex w-full items-center gap-2 px-3 py-1.5 text-left text-xs transition-colors",e.id===r?"bg-[var(--accent)] text-[var(--foreground)]":"text-[var(--muted-foreground)] hover:bg-[var(--secondary)]"),children:[(0,s.jsx)(rS.A,{className:"h-3 w-3 shrink-0"}),(0,s.jsx)("span",{className:"truncate",children:e.name})]},"".concat(e.id,":").concat(e.scope)))})]})}function rF(){let{messages:e,sendMessage:t,isStreaming:r,clearSession:a,deleteSession:n,stopGeneration:o,interruptGeneration:i,pendingMessages:c,removePendingMessage:d,handleCommand:u,sessionId:x}=function(){let e=(0,tr.useT)(),t=t6(e=>e.messages),r=t6(e=>e.isStreaming),a=t6(e=>e.sessionId),n=t6(e=>e.pendingMessages),s=e9(e=>e.activeProject);(0,l.useEffect)(()=>{if(!s)return;let e=s.id,t=rf(e),r=t6.getState().sessionId;t&&t!==r?(t6.getState().setSessionId(t),t6.getState().setMessages([])):!t&&r&&t6.getState().clear();let a=()=>{let t=t6.getState().sessionId;t&&j.connected&&j.send({type:"subscribe",sessionId:t,projectId:e})};a();let n=j.on("_connected",()=>a());return()=>n()},[null==s?void 0:s.id]);let o=(0,l.useCallback)(()=>{let{activeTab:e,selectedText:t,selectedRange:r,tabs:a,contextEnabled:n}=p.getState();if(!n)return"";let s=[];if(e&&s.push("[Currently viewing: ".concat(e,"]")),t&&t.trim()&&e){let a=r?":".concat(r.startLine,"-").concat(r.endLine):"";s.push("[Selected text in ".concat(e).concat(a,"]\n```\n").concat(t,"\n```"))}return s.length>0?s.join("\n")+"\n\n":""},[]),i=(0,l.useCallback)((t,r,n)=>{var l;if(!s)return;let i=null!=(l=null!=a?a:rf(s.id))?l:M();a&&a===i||(t6.getState().setSessionId(i),rg(s.id,i));let c=o(),d=[];c&&d.push(c.trim()),(null==n?void 0:n.length)&&d.push("[Referenced files:\n".concat(n.map(e=>" - ".concat(e)).join("\n"),"]"));let u=t6.getState().captureSource,x=window;u&&x&&("camera"===u.kind&&x.haloCamera?d.push(e("capture.cameraLlmPrompt")):"screen"===u.kind&&x.haloCapture&&d.push(e("capture.llmPrompt",{name:u.name})));let m=(d.length>0?d.join("\n")+"\n\n":"")+t.trim(),p=t6.getState(),h=t.trim();if(null==n?void 0:n.length){let e=n.map(e=>"@".concat(e.split("/").pop())).join(" ");h="".concat(e," ").concat(h)}if(null==r?void 0:r.length){let t=e("chat.imageSent",{n:r.length});h=h?"".concat(t,"\n").concat(h):t}p.addMessage({id:M(),role:"user",content:h,timestamp:Date.now(),...(null==r?void 0:r.length)?{localImages:r.map(e=>"data:".concat(e.mimeType,";base64,").concat(e.data))}:{}}),p.messages.some(e=>e.streaming&&"assistant"===e.role&&!e.taskId)||p.addMessage({id:M(),role:"assistant",content:"",timestamp:Date.now(),streaming:!0});let f=t6.getState().selectedAgentId;j.send({type:"chat",sessionId:i,projectId:s.id,message:m,..."default"!==f?{agentId:f}:{},...(null==r?void 0:r.length)?{images:r}:{}})},[a,s,o]),c=(0,l.useCallback)((e,t,r)=>{if(e.trim()||(null==t?void 0:t.length)){if(!s)return void console.warn("[useChat] No active project selected");i(e,t,r)}},[s,i,a]),d=(0,l.useCallback)(()=>{j.send({type:"chat:stop",sessionId:a})},[a]),u=(0,l.useCallback)(()=>{j.send({type:"chat:interrupt",sessionId:a})},[a]),x=(0,l.useCallback)(e=>{t6.getState().removePendingMessage(e)},[]);(0,l.useEffect)(()=>{if(r)return;let e=t6.getState().shiftPendingMessage();if(e){let t=setTimeout(()=>i(e),100);return()=>clearTimeout(t)}},[r,i]);let m=(0,l.useCallback)(()=>{if(!s)return;let e=null!=a?a:rf(s.id);e&&j.send({type:"session:clear",sessionId:e}),rv(s.id),t6.getState().clear()},[s,a]),h=(0,l.useCallback)(e=>{s&&(j.send({type:"session:delete",sessionId:e,projectId:s.path}),e===(null!=a?a:rf(s.id))&&(rv(s.id),t6.getState().clear()))},[s,a]),f=(0,l.useCallback)((e,t)=>{var r;if(!s)return;let n=null!=(r=null!=a?a:rf(s.id))?r:M();a&&a===n||(t6.getState().setSessionId(n),rg(s.id,n));let l=e.name.slice(1),o={type:"command:".concat(l),sessionId:n,projectId:s.id};t.trim()&&(o.message=t.trim()),j.send(o),t6.getState().addMessage({id:M(),role:"system",content:"Executing ".concat(e.name).concat(t.trim()?" ".concat(t.trim()):"","..."),timestamp:Date.now()})},[s,a]);return{messages:t,sendMessage:c,isStreaming:r,sessionId:a,clearSession:m,deleteSession:h,stopGeneration:d,interruptGeneration:u,pendingMessages:n,removePendingMessage:x,handleCommand:f}}(),m=(0,l.useRef)(null),h=e9(e=>e.activeProject),[f,g]=(0,l.useState)(!1),[b,y]=(0,l.useState)(!1),{sessions:w,refresh:N,remove:k,loadMore:S,hasMore:C,loadingMore:A}=function(){let e=e9(e=>e.activeProject);return function(e){let[t,r]=(0,l.useState)([]),[a,n]=(0,l.useState)(null),[s,o]=(0,l.useState)(!1),i=rb(e=>e.version),c=(0,l.useCallback)(async()=>{if(!e){r([]),n(null);return}try{let t=await v.F.sessionLogs.list(e,{rootOnly:!0,limit:30});r(t.sessions),n(t.nextCursor)}catch(e){r([]),n(null)}},[e]);(0,l.useEffect)(()=>{c()},[c,i]);let d=(0,l.useCallback)(async()=>{if(null!==a&&!s){o(!0);try{if(!e)return;let t=await v.F.sessionLogs.list(e,{rootOnly:!0,limit:30,cursor:a}),s=t.sessions;r(e=>{let t=new Set(e.map(e=>e.id));return[...e,...s.filter(e=>!t.has(e.id))]}),n(t.nextCursor)}catch(e){console.error("[SessionList] loadMore failed:",e)}finally{o(!1)}}},[e,a,s]);return{sessions:t,refresh:c,remove:(0,l.useCallback)(async t=>{try{await v.F.sessionLogs.delete(t,e),r(e=>e.filter(e=>e.id!==t)),rj()}catch(e){console.error("[SessionList] Delete failed:",e)}},[e]),loadMore:d,hasMore:null!==a,loadingMore:s}}(null==e?void 0:e.path)}(),I=(0,l.useCallback)(e=>{h&&(g(!0),t6.getState().setSessionId(e),t6.getState().setMessages([]),j.send({type:"subscribe",sessionId:e,projectId:h.id}),localStorage.setItem("halo_session_".concat(h.id),e),setTimeout(()=>g(!1),2e3))},[h]),E=(0,l.useCallback)(()=>{a(),setTimeout(()=>{N(),rj()},300)},[a,N]),T=(0,l.useCallback)(async(e,t)=>{t.stopPropagation(),n(e),await k(e)},[n,k]),F=(0,l.useRef)(r);(0,l.useEffect)(()=>{F.current&&!r&&setTimeout(()=>N(),500),F.current=r},[r,N]);let D=(0,l.useMemo)(()=>e.filter(ti),[e]);(0,l.useEffect)(()=>{f&&D.length>0&&g(!1)},[f,D.length]);let P=(0,l.useRef)(!1);return(0,l.useEffect)(()=>{let e=m.current;if(!e)return;let t=()=>{P.current=!(e.scrollHeight-e.scrollTop-e.clientHeight<80)};return e.addEventListener("scroll",t),()=>e.removeEventListener("scroll",t)},[]),(0,l.useEffect)(()=>{m.current&&!P.current&&(m.current.scrollTop=m.current.scrollHeight)},[D]),(0,l.useEffect)(()=>{let e=m.current;if(!e||"undefined"==typeof ResizeObserver)return;let t=new ResizeObserver(()=>{P.current||(e.scrollTop=e.scrollHeight)});return t.observe(e),()=>t.disconnect()},[]),(0,s.jsxs)("div",{className:"flex h-full flex-col bg-[var(--background)]",children:[(0,s.jsx)("div",{ref:m,className:"flex-1 min-h-0 overflow-y-auto",children:f?(0,s.jsxs)("div",{className:"flex items-center justify-center py-8 text-xs text-[var(--muted-foreground)]",children:[(0,s.jsx)(H.A,{className:"h-3.5 w-3.5 animate-spin mr-1.5"})," Loading session..."]}):0===D.length?(0,s.jsxs)("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center",children:[(0,s.jsx)("div",{className:"rounded-full bg-[var(--secondary)] p-3",children:(0,s.jsx)(rC.A,{className:"h-6 w-6 text-[var(--muted-foreground)]"})}),(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"text-sm font-medium text-[var(--foreground)]",children:"Start a conversation"}),(0,s.jsx)("p",{className:"mt-1 text-xs text-[var(--muted-foreground)]",children:"Describe what you want to build, and agents will work together to deliver it."})]}),(0,s.jsx)(rk,{count:w.length,onClick:()=>y(!0)})]}):(0,s.jsx)(tP,{messages:D})}),(0,s.jsx)("div",{className:"shrink-0",children:(0,s.jsx)(rm,{onSend:t,isStreaming:r,onStop:o,onInterrupt:i,pendingMessages:c,onRemovePending:d,onCommand:u,onCompact:()=>u({name:"/session",description:"",type:"server"},"compact"),renderLeftControls:()=>(0,s.jsxs)("div",{className:"relative flex items-center gap-0.5",children:[(w.length>0||D.length>0)&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(rN,{sessions:w,currentSessionId:x,onSelect:I,onDelete:T,onNew:E,onLoadMore:S,hasMore:C,loadingMore:A,open:b,onToggle:()=>y(!b),direction:"up"}),(0,s.jsx)("button",{onClick:E,title:"New session",className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-lg text-[var(--muted-foreground)] transition-colors hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,s.jsx)(rA.A,{className:"h-4 w-4"})})]}),(0,s.jsx)(rT,{})]})})})]})}var rD=r(55499),rM=r(93345);let rP="halo_browser_id";function rL(){return"undefined"!=typeof crypto&&"function"==typeof crypto.randomUUID?crypto.randomUUID():"b-".concat(Date.now().toString(36),"-").concat(Math.random().toString(36).slice(2,12))}let rR=null;function rz(){if(rR)return rR;try{let e=window.localStorage.getItem(rP);return e||(e=rL(),window.localStorage.setItem(rP,e)),rR=e,e}catch(e){return rR=rL()}}r(14113);let r_=0,rO={dark:{background:"#0a0a0a",foreground:"#e4e4e7",cursor:"#e4e4e7",cursorAccent:"#0a0a0a",selectionBackground:"#27272a",black:"#18181b",red:"#f87171",green:"#4ade80",yellow:"#facc15",blue:"#60a5fa",magenta:"#c084fc",cyan:"#22d3ee",white:"#e4e4e7",brightBlack:"#52525b",brightRed:"#fca5a5",brightGreen:"#86efac",brightYellow:"#fde68a",brightBlue:"#93c5fd",brightMagenta:"#d8b4fe",brightCyan:"#67e8f9",brightWhite:"#fafafa"},light:{background:"#ffffff",foreground:"#171717",cursor:"#171717",cursorAccent:"#ffffff",selectionBackground:"#bfdbfe",black:"#262626",red:"#b91c1c",green:"#15803d",yellow:"#a16207",blue:"#1d4ed8",magenta:"#7e22ce",cyan:"#0e7490",white:"#525252",brightBlack:"#737373",brightRed:"#dc2626",brightGreen:"#16a34a",brightYellow:"#ca8a04",brightBlue:"#2563eb",brightMagenta:"#9333ea",brightCyan:"#0891b2",brightWhite:"#a3a3a3"},midnight:{background:"#0b1220",foreground:"#dbe4f3",cursor:"#dbe4f3",cursorAccent:"#0b1220",selectionBackground:"#1e2a47",black:"#16213a",red:"#f87171",green:"#4ade80",yellow:"#facc15",blue:"#60a5fa",magenta:"#c084fc",cyan:"#22d3ee",white:"#dbe4f3",brightBlack:"#64769b",brightRed:"#fca5a5",brightGreen:"#86efac",brightYellow:"#fde68a",brightBlue:"#93c5fd",brightMagenta:"#d8b4fe",brightCyan:"#67e8f9",brightWhite:"#f1f5fb"},warm:{background:"#f6f1e7",foreground:"#3d3427",cursor:"#3d3427",cursorAccent:"#f6f1e7",selectionBackground:"#e6dabf",black:"#292524",red:"#b91c1c",green:"#15803d",yellow:"#a16207",blue:"#1d4ed8",magenta:"#7e22ce",cyan:"#0e7490",white:"#57534e",brightBlack:"#78716c",brightRed:"#dc2626",brightGreen:"#16a34a",brightYellow:"#ca8a04",brightBlue:"#2563eb",brightMagenta:"#9333ea",brightCyan:"#0891b2",brightWhite:"#a8a29e"}},rW={fontFamily:"'JetBrains Mono', 'Fira Code', Menlo, Monaco, monospace",fontSize:13,lineHeight:1.4,cursorBlink:!0,scrollback:1e4};function rU(){let{headerless:e,cwd:t}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=(0,l.useRef)(null),a=(0,l.useRef)(new Map),[n,o]=(0,l.useState)([]),[i,c]=(0,l.useState)(null),d=e9(e=>e.activeProject),{theme:u}=(0,eE.useTheme)(),x=(0,l.useRef)(u);(0,l.useEffect)(()=>{for(let e of(x.current=u,a.current.values()))e.term.options.theme=rO[u]},[u]);let m=(0,l.useCallback)(e=>{var s,l,i,u;let m=r.current;if(!m)return;r_++;let p="term_".concat(Date.now().toString(36),"_").concat(r_),h=0===n.length?"bash":"bash (".concat(r_,")"),f=document.createElement("div");f.className="absolute inset-0",f.style.display="none",m.appendChild(f);let g=new rD.B({...rW,theme:rO[x.current]}),v=new rM.Y;g.loadAddon(v),g.open(f),v.fit(),g.onData(e=>{j.send({type:"terminal:input",data:e,terminalId:p})}),a.current.set(p,{id:p,name:h,term:g,fit:v,container:f,ready:!1,exited:!1});let b=null;new ResizeObserver(()=>{v.fit(),b&&clearTimeout(b),b=setTimeout(()=>{j.send({type:"terminal:resize",cols:g.cols,rows:g.rows,terminalId:p})},150)}).observe(f);let y=new URLSearchParams(window.location.search).get("folder"),w=null!=(i=null!=(l=null!=(s=null!=e?e:t)?s:null==d?void 0:d.path)?l:y)?i:"~";return j.send({type:"terminal:start",terminalId:p,cwd:w,cols:g.cols,rows:g.rows,browserId:rz(),workspacePath:null!=(u=null==d?void 0:d.path)?u:""}),o(e=>[...e,{id:p,name:h}]),c(p),p},[d,n.length,t]),h=(0,l.useCallback)(e=>{let t=a.current.get(e);t&&(j.send({type:"terminal:close",terminalId:e}),t.term.dispose(),t.container.remove(),a.current.delete(e),o(t=>{let r=t.filter(t=>t.id!==e);return c(a=>{if(a===e){var n,s;return null!=(s=null==(n=r[Math.min(t.findIndex(t=>t.id===e),r.length-1)])?void 0:n.id)?s:null}return a}),r}))},[]),f=(0,l.useCallback)(e=>{c(e)},[]);(0,l.useEffect)(()=>{for(let[e,t]of a.current){let r=e===i;t.container.style.display=r?"block":"none",r&&(t.fit.fit(),t.term.focus())}},[i]),(0,l.useEffect)(()=>{let e=[];return e.push(j.on("terminal:output",e=>{let{terminalId:t,data:r}=e;if(t){var n;null==(n=a.current.get(t))||n.term.write(r)}else{let e=a.current.values().next().value;null==e||e.term.write(r)}})),e.push(j.on("terminal:ready",e=>{let{terminalId:t}=e;if(t){let e=a.current.get(t);e&&(e.ready=!0)}})),e.push(j.on("terminal:exit",e=>{let{terminalId:t}=e;if(t){let e=a.current.get(t);e&&(e.exited=!0,e.term.writeln("\r\n\x1b[90m[Process exited]\x1b[0m"))}})),()=>e.forEach(e=>e())},[]);let g=(0,l.useRef)(!1);return(0,l.useEffect)(()=>{if(g.current)return;g.current=!0;let e=j.on("terminal:reattached",e=>{let t=e.terminalIds,n=r.current,s=0;for(let e of t){if(a.current.has(e)){let t=a.current.get(e);j.send({type:"terminal:resize",cols:t.term.cols,rows:t.term.rows,terminalId:e});continue}if(!n)continue;r_++;let t=0===s&&0===a.current.size?"bash":"bash (".concat(r_,")");s++;let r=document.createElement("div");r.className="absolute inset-0",r.style.display="none",n.appendChild(r);let l=new rD.B({...rW,theme:rO[x.current]}),i=new rM.Y;l.loadAddon(i),l.open(r),i.fit(),l.write("\x1b[?2004h"),l.onData(t=>{j.send({type:"terminal:input",data:t,terminalId:e})});let d=null;new ResizeObserver(()=>{i.fit(),d&&clearTimeout(d),d=setTimeout(()=>{j.send({type:"terminal:resize",cols:l.cols,rows:l.rows,terminalId:e})},150)}).observe(r);let u={id:e,name:t,term:l,fit:i,container:r,ready:!0,exited:!1};a.current.set(e,u),o(r=>[...r,{id:e,name:t}]),c(t=>null!=t?t:e),j.send({type:"terminal:resize",cols:l.cols,rows:l.rows,terminalId:e})}0===t.length&&0===a.current.size&&m()}),t=()=>{var e;j.send({type:"terminal:reattach",browserId:rz(),workspacePath:null!=(e=null==d?void 0:d.path)?e:""})};t();let n=j.on("_connected",t),s=setTimeout(()=>{0===a.current.size&&m()},2e3);return()=>{clearTimeout(s),e(),n()}},[m]),(0,l.useEffect)(()=>{let e=p.getState().pendingTerminalCwd;return p.subscribe(t=>{let r=t.pendingTerminalCwd;if(r&&r!==e){e=r;let a=t.consumeTerminalSpawn();a&&m(a)}else e=r})},[m]),(0,s.jsxs)("div",{className:"flex h-full min-h-0 bg-[var(--background)]",children:[(0,s.jsx)("div",{ref:r,className:"relative min-h-0 flex-1 overflow-hidden"}),(0,s.jsxs)("div",{className:"flex w-[160px] shrink-0 flex-col border-l border-[var(--border)] bg-[var(--card)]",children:[(0,s.jsx)("div",{className:"flex-1 overflow-y-auto",children:n.map(e=>(0,s.jsxs)("div",{onClick:()=>f(e.id),className:D("group flex items-center gap-1.5 px-2 py-1.5 text-[11px] cursor-pointer select-none",e.id===i?"bg-[var(--secondary)] text-[var(--foreground)]":"text-[var(--muted-foreground)] hover:text-[var(--foreground)] hover:bg-[var(--secondary)]/50"),children:[(0,s.jsx)($.A,{className:"h-3 w-3 shrink-0"}),(0,s.jsx)("span",{className:"flex-1 truncate",children:e.name}),n.length>1&&(0,s.jsx)("button",{onClick:t=>{t.stopPropagation(),h(e.id)},className:"rounded p-0.5 opacity-0 group-hover:opacity-100 hover:bg-[var(--accent)]",children:(0,s.jsx)(eK.A,{className:"h-2.5 w-2.5"})})]},e.id))}),(0,s.jsxs)("button",{onClick:()=>m(),className:"flex items-center gap-1.5 border-t border-[var(--border)] px-2 py-1.5 text-[11px] text-[var(--muted-foreground)] hover:text-[var(--foreground)] hover:bg-[var(--secondary)]/50",title:"New Terminal",children:[(0,s.jsx)(rA.A,{className:"h-3 w-3"}),(0,s.jsx)("span",{children:"New Terminal"})]})]})]})}var rB=r(90590);function rH(){let{cwd:e,floating:t=!1,dragHandleRef:r}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},a=(0,tr.useT)(),n=p(e=>e.bottomTab),o=p(e=>e.setBottomTab),i=p(e=>e.setBottomFloating),c=p(e=>e.bottomMaximized),d=p(e=>e.setBottomMaximized),[u,x]=(0,l.useState)("terminal"===n);(0,l.useEffect)(()=>{"terminal"===n&&x(!0)},[n]);let[m,h]=(0,l.useState)(0);return(0,l.useEffect)(()=>j.on("_disconnected",()=>h(e=>e+1)),[]),(0,s.jsxs)("div",{className:"flex h-full flex-col bg-[var(--background)]",children:[(0,s.jsxs)("div",{ref:r,className:D("flex h-[35px] shrink-0 items-center gap-0 border-b border-[var(--border)] bg-[var(--card)] px-2",t&&"cursor-move select-none"),children:[(0,s.jsx)(rK,{label:a("nav.chat"),active:"chat"===n,onClick:()=>o("chat")}),(0,s.jsx)(rK,{label:a("nav.terminal"),active:"terminal"===n,onClick:()=>o("terminal")}),(0,s.jsx)("div",{className:"flex-1"}),(0,s.jsx)("button",{onMouseDown:e=>e.stopPropagation(),onClick:()=>d(!c),title:c?"Restore panel":"Maximize panel",className:"rounded p-1 text-[var(--muted-foreground)] transition-colors hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:c?(0,s.jsx)(te.A,{className:"h-3.5 w-3.5"}):(0,s.jsx)(tt.A,{className:"h-3.5 w-3.5"})}),(0,s.jsx)("button",{onMouseDown:e=>e.stopPropagation(),onClick:()=>i(!t),title:t?"Dock back":"Float panel",className:"rounded p-1 text-[var(--muted-foreground)] transition-colors hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:t?(0,s.jsx)(eK.A,{className:"h-3.5 w-3.5"}):(0,s.jsx)(rB.A,{className:"h-3.5 w-3.5"})})]}),(0,s.jsxs)("div",{className:"min-h-0 flex-1",children:[(0,s.jsx)("div",{className:"chat"===n?"h-full":"hidden",children:(0,s.jsx)(rF,{})}),(0,s.jsx)("div",{className:"terminal"===n?"h-full":"hidden",children:u&&(0,s.jsx)(rU,{headerless:!0,cwd:e},m)})]})]})}function rK(e){let{label:t,active:r,onClick:a}=e;return(0,s.jsxs)("button",{onClick:a,className:D("relative px-3 py-2 text-[11px] font-medium tracking-wide transition-colors",r?"text-[var(--foreground)]":"text-[var(--muted-foreground)] hover:text-[var(--foreground)]"),children:[t,r&&(0,s.jsx)("div",{className:"absolute bottom-0 left-2 right-2 h-px bg-[var(--foreground)]"})]})}function rG(e){let{slotRef:t,dragHandleRef:r}=e,a=p(e=>e.bottomFloatRect),n=p(e=>e.setBottomFloatRect),o=p(e=>e.bottomMaximized),i=(0,l.useRef)(a);(0,l.useEffect)(()=>{i.current=a}),(0,l.useEffect)(()=>{let e=r.current;if(e&&!o)return e.addEventListener("mousedown",t),()=>e.removeEventListener("mousedown",t);function t(e){if(e.target.closest("button"))return;e.preventDefault();let t=e.clientX,r=e.clientY,a={...i.current};function s(e){let s=e.clientX-t,l=e.clientY-r;n({x:rJ(a.x+s,0,window.innerWidth-a.w),y:rJ(a.y+l,0,window.innerHeight-a.h),w:a.w,h:a.h})}window.addEventListener("mousemove",s),window.addEventListener("mouseup",function e(){window.removeEventListener("mousemove",s),window.removeEventListener("mouseup",e)})}},[n,o,r]),(0,l.useEffect)(()=>{function e(){let e=i.current,t=rJ(e.x,0,Math.max(0,window.innerWidth-e.w)),r=rJ(e.y,0,Math.max(0,window.innerHeight-e.h));(t!==e.x||r!==e.y)&&n({...e,x:t,y:r})}return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[n]);let c=(0,l.useRef)(null);(0,l.useEffect)(()=>{let e=c.current;if(e&&!o)return e.addEventListener("mousedown",t),()=>e.removeEventListener("mousedown",t);function t(e){var t;let r=e.target.closest("[data-edges]");if(!r)return;let a=null!=(t=r.getAttribute("data-edges"))?t:"",s={top:a.includes("top"),bottom:a.includes("bottom"),left:a.includes("left"),right:a.includes("right")};e.preventDefault(),e.stopPropagation();let l=e.clientX,o=e.clientY,c={...i.current},d=c.x+c.w,u=c.y+c.h;function x(e){let t=e.clientX-l,r=e.clientY-o,{x:a,y:i,w:x,h:m}=c;if(s.right&&(x=rJ(c.w+t,320,window.innerWidth-c.x)),s.bottom&&(m=rJ(c.h+r,240,window.innerHeight-c.y)),s.left){let e=rJ(c.x+t,0,d-320);a=e,x=d-e}if(s.top){let e=rJ(c.y+r,0,u-240);i=e,m=u-e}n({x:a,y:i,w:x,h:m})}window.addEventListener("mousemove",x),window.addEventListener("mouseup",function e(){window.removeEventListener("mousemove",x),window.removeEventListener("mouseup",e)})}},[n,o]);let d=o?{left:0,top:0,width:"100vw",height:"100vh"}:{left:a.x,top:a.y,width:a.w,height:a.h};return(0,s.jsxs)("div",{className:"fixed z-50 flex flex-col rounded-md border border-[var(--border)] bg-[var(--background)] shadow-2xl",style:d,children:[(0,s.jsx)("div",{ref:t,className:"min-h-0 flex-1 overflow-hidden rounded-md"}),!o&&(0,s.jsxs)("div",{ref:c,children:[(0,s.jsx)("div",{"data-edges":"top",className:"absolute -top-1 left-3 right-3 h-2 cursor-ns-resize"}),(0,s.jsx)("div",{"data-edges":"bottom",className:"absolute -bottom-1 left-3 right-3 h-2 cursor-ns-resize"}),(0,s.jsx)("div",{"data-edges":"left",className:"absolute -left-1 top-3 bottom-3 w-2 cursor-ew-resize"}),(0,s.jsx)("div",{"data-edges":"right",className:"absolute -right-1 top-3 bottom-3 w-2 cursor-ew-resize"}),(0,s.jsx)("div",{"data-edges":"top left",className:"absolute -top-1 -left-1 h-3 w-3 cursor-nwse-resize"}),(0,s.jsx)("div",{"data-edges":"top right",className:"absolute -top-1 -right-1 h-3 w-3 cursor-nesw-resize"}),(0,s.jsx)("div",{"data-edges":"bottom left",className:"absolute -bottom-1 -left-1 h-3 w-3 cursor-nesw-resize"}),(0,s.jsx)("div",{"data-edges":"bottom right",className:"absolute -bottom-1 -right-1 h-3 w-3 cursor-nwse-resize"})]})]})}function rJ(e,t,r){return Math.max(t,Math.min(r,e))}let rq={ts:ee.A,tsx:ee.A,js:ee.A,jsx:ee.A,json:G.A,md:Z.A};function rZ(e){let{onSelect:t,onClose:r}=e,a=e9(e=>{var t,r;return null!=(r=null==(t=e.activeProject)?void 0:t.id)?r:null}),[n,o]=(0,l.useState)(""),[i,c]=(0,l.useState)(0),[d,u]=(0,l.useState)([]),[x,m]=(0,l.useState)(!1),p=(0,l.useRef)(null),h=(0,l.useRef)(null);(0,l.useEffect)(()=>{var e;null==(e=p.current)||e.focus()},[]),(0,l.useEffect)(()=>{c(0)},[n]),(0,l.useEffect)(()=>{if(!a)return;let e=n.trim();if(!e){u([]),m(!1);return}m(!0);let t=!1,r=setTimeout(()=>{v.F.files.search(a,e,50).then(e=>{t||u(e.matches)}).catch(e=>{t||(console.error("[QuickOpen] Search failed:",e),u([]))}).finally(()=>{t||m(!1)})},150);return()=>{t=!0,clearTimeout(r)}},[a,n]),(0,l.useEffect)(()=>{var e;let t=null==(e=h.current)?void 0:e.children[i];null==t||t.scrollIntoView({block:"nearest"})},[i]);let f=(0,l.useCallback)(e=>{if("Escape"===e.key)return void r();if("ArrowDown"===e.key){e.preventDefault(),c(e=>Math.min(e+1,d.length-1));return}if("ArrowUp"===e.key){e.preventDefault(),c(e=>Math.max(e-1,0));return}"Enter"===e.key&&(e.preventDefault(),d[i]&&(t(d[i].path),r()))},[d,i,t,r]);return(0,l.useEffect)(()=>{function e(e){e.target.closest("[data-quick-open]")||r()}return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[r]),(0,s.jsxs)("div",{className:"fixed inset-0 z-50 flex justify-center pt-[15vh]",children:[(0,s.jsx)("div",{className:"fixed inset-0 bg-black/40"}),(0,s.jsxs)("div",{"data-quick-open":!0,className:"relative w-full max-w-lg",children:[(0,s.jsx)("input",{ref:p,value:n,onChange:e=>o(e.target.value),onKeyDown:f,placeholder:"Search files by name...",className:"w-full rounded-t-md border border-[var(--border)] bg-[var(--card)] px-4 py-3 text-sm text-[var(--foreground)] placeholder-[var(--muted-foreground)] outline-none"}),(0,s.jsx)("div",{ref:h,className:"max-h-[40vh] overflow-y-auto rounded-b-md border border-t-0 border-[var(--border)] bg-[var(--card)]",children:0===d.length?(0,s.jsx)("div",{className:"px-4 py-6 text-center text-xs text-[var(--muted-foreground)]",children:x?"Searching...":"No files found"}):d.map((e,a)=>{var n,l,o;let c=null!=(o=rq[null!=(l=null==(n=e.name.split(".").pop())?void 0:n.toLowerCase())?l:""])?o:el.A;return(0,s.jsxs)("button",{onClick:()=>{t(e.path),r()},className:D("flex w-full items-center gap-2 px-4 py-2 text-left text-xs transition-colors",a===i?"bg-[var(--accent)] text-[var(--accent-foreground)]":"text-[var(--foreground)] hover:bg-[var(--secondary)]"),children:[(0,s.jsx)(c,{className:"h-3.5 w-3.5 shrink-0 text-[var(--muted-foreground)]"}),(0,s.jsx)("span",{className:"truncate font-medium",children:e.name}),(0,s.jsx)("span",{className:"ml-auto truncate text-[10px] text-[var(--muted-foreground)]",children:e.path})]},e.path)})})]})]})}var rV=r(49353),rY=r(24284);function r$(e){let{initialPath:t,onSelect:r,onClose:a}=e,[n,o]=(0,l.useState)(null!=t?t:""),[i,c]=(0,l.useState)(""),[d,u]=(0,l.useState)([]),[x,m]=(0,l.useState)(!1),[p,h]=(0,l.useState)(null),f=(0,l.useCallback)(async e=>{m(!0),h(null);try{let t=await v.F.fs.browse(e);o(t.path),c(t.parent),u(t.entries)}catch(e){h(e instanceof Error?e.message:"Failed to load directory")}finally{m(!1)}},[]);return(0,l.useEffect)(()=>{t?f(t):v.F.fs.home().then(e=>{let{home:t}=e;return f(t)}).catch(e=>h(String(e)))},[t,f]),(0,s.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",onClick:a,children:(0,s.jsxs)("div",{className:"w-[560px] max-h-[70vh] flex flex-col rounded-lg border border-[var(--border)] bg-[var(--background)] shadow-xl",onClick:e=>e.stopPropagation(),children:[(0,s.jsxs)("div",{className:"flex items-center justify-between border-b border-[var(--border)] px-4 py-2.5",children:[(0,s.jsx)("h3",{className:"text-sm font-medium text-[var(--foreground)]",children:"Open Workspace"}),(0,s.jsx)("button",{onClick:a,className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)]",children:(0,s.jsx)(eK.A,{className:"h-4 w-4"})})]}),(0,s.jsxs)("div",{className:"flex items-center gap-1 border-b border-[var(--border)] px-3 py-2",children:[(0,s.jsx)("button",{onClick:()=>f(i),disabled:x||!i||i===n,title:"Parent directory",className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)] disabled:opacity-30",children:(0,s.jsx)(rV.A,{className:"h-3.5 w-3.5"})}),(0,s.jsx)("button",{onClick:()=>v.F.fs.home().then(e=>{let{home:t}=e;return f(t)}),disabled:x,title:"Home directory",className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)] disabled:opacity-30",children:(0,s.jsx)(rY.A,{className:"h-3.5 w-3.5"})}),(0,s.jsx)("input",{type:"text",value:n,onChange:e=>o(e.target.value),onKeyDown:e=>{"Enter"===e.key&&f(n)},className:"flex-1 rounded border border-[var(--border)] bg-[var(--secondary)] px-2 py-1 text-xs text-[var(--foreground)] outline-none focus:border-[var(--primary)]"})]}),(0,s.jsxs)("div",{className:"flex-1 min-h-0 overflow-y-auto",children:[p&&(0,s.jsx)("p",{className:"px-4 py-3 text-xs text-red-400",children:p}),x&&!p&&(0,s.jsx)("p",{className:"px-4 py-3 text-xs text-[var(--muted-foreground)]",children:"Loading..."}),!x&&!p&&0===d.length&&(0,s.jsx)("p",{className:"px-4 py-3 text-xs text-[var(--muted-foreground)]",children:"(empty)"}),!x&&d.map(e=>(0,s.jsxs)("button",{onDoubleClick:()=>f(e.path),onClick:()=>o(e.path),className:D("flex w-full items-center gap-2 px-4 py-1.5 text-xs text-left transition-colors",n===e.path?"bg-[var(--primary)]/20 text-[var(--foreground)]":"text-[var(--foreground)] hover:bg-[var(--secondary)]"),children:[(0,s.jsx)(_.A,{className:"h-3.5 w-3.5 text-[var(--muted-foreground)]"}),e.name]},e.path))]}),(0,s.jsxs)("div",{className:"flex items-center justify-end gap-2 border-t border-[var(--border)] px-3 py-2.5",children:[(0,s.jsx)("button",{onClick:a,className:"rounded px-3 py-1 text-xs font-medium text-[var(--muted-foreground)] hover:bg-[var(--secondary)]",children:"Cancel"}),(0,s.jsx)("button",{onClick:()=>r(n),disabled:!n,className:"rounded bg-[var(--primary)] px-3 py-1 text-xs font-medium text-[var(--primary-foreground)] hover:opacity-90 disabled:opacity-30",children:"Open"})]})]})})}let rQ="halo_recent_workspaces";function rX(){try{let e=localStorage.getItem(rQ),t=e?JSON.parse(e):[];return Array.isArray(t)?t.filter(e=>"string"==typeof e):[]}catch(e){return[]}}function r0(e){try{localStorage.setItem(rQ,JSON.stringify(e))}catch(e){}}var r1=r(12143),r5=r(76688),r3=r(59821);function r2(e){var t,r;let{projectId:a,pathInput:n,onPathInputChange:o,onOpenFolder:i,onOpenPath:c,activeProject:d}=e,u=(0,tr.useT)(),x=t6(e=>e.isStreaming),[m,p]=(0,l.useState)(!1),[h,f]=(0,l.useState)(!1),g=(0,l.useRef)(null),{recent:b,remove:j}=function(){let[e,t]=(0,l.useState)([]);return(0,l.useEffect)(()=>{t(rX())},[]),{recent:e,remove:(0,l.useCallback)(e=>{t(t=>{let r=t.filter(t=>t!==e);return r0(r),r})},[])}}(),[w,N]=(0,l.useState)(!1),[k,S]=(0,l.useState)(!1),C=(0,l.useRef)(null);(0,l.useEffect)(()=>{if(w)return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e);function e(e){C.current&&!C.current.contains(e.target)&&N(!1)}},[w]);let A=k?n.trim().toLowerCase():"",I=b.filter(e=>e!==(null==d?void 0:d.path)&&(!A||e.toLowerCase().includes(A)));async function E(){if(!a)return;let e=await L("New file name (relative path, e.g. src/hello.ts):");if(null==e?void 0:e.trim())try{await v.F.files.create(e.trim(),a),y(a)}catch(e){console.error("[Explorer] Failed to create file:",e),window.alert(e instanceof Error?e.message:"Failed to create file")}}async function T(){if(!a)return;let e=await L("New folder name (relative path, e.g. src/utils):");if(null==e?void 0:e.trim())try{await v.F.files.mkdir(e.trim(),a),y(a)}catch(e){console.error("[Explorer] Failed to create folder:",e),window.alert(e instanceof Error?e.message:"Failed to create folder")}}async function F(e){var t;if(!a||!(null==(t=e.target.files)?void 0:t.length))return;let r=Array.from(e.target.files);try{await v.F.files.upload(r,a),y(a)}catch(e){console.error("[Explorer] Upload failed:",e),window.alert(e instanceof Error?e.message:"Upload failed")}e.target.value=""}let M=null!=(r=null==d||null==(t=d.path.split("/").filter(Boolean).pop())?void 0:t.toUpperCase())?r:"EXPLORER";return(0,s.jsxs)("div",{className:"flex h-full flex-col bg-[var(--background)]",children:[(0,s.jsxs)("div",{className:"flex h-10 shrink-0 items-center border-b border-[var(--border)] px-3",children:[(0,s.jsx)(r1.A,{className:"h-4 w-4 text-[var(--muted-foreground)]"}),(0,s.jsx)("span",{className:"ml-2 text-sm font-medium text-[var(--foreground)]",children:u("nav.explorer")}),(0,s.jsx)("div",{className:"flex-1"}),a&&(0,s.jsx)("button",{onClick:function(){a&&(p(!0),y(a),setTimeout(()=>p(!1),500))},disabled:m,title:"Refresh",className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)] transition-colors disabled:opacity-50",children:(0,s.jsx)(r5.A,{className:D("h-3.5 w-3.5",m&&"animate-spin")})})]}),(0,s.jsxs)("div",{className:"flex items-center gap-1 border-b border-[var(--border)] p-3",children:[(0,s.jsxs)("div",{ref:C,className:"relative min-w-0 flex-1",children:[(0,s.jsx)("input",{type:"text",value:n,onChange:e=>{o(e.target.value),S(!0),N(!0)},onFocus:()=>{S(!1),N(!0)},onKeyDown:e=>{"Enter"===e.key?(N(!1),i()):"Escape"===e.key&&N(!1)},placeholder:"Enter folder path, press Enter",className:"w-full rounded border border-[var(--border)] bg-[var(--secondary)] px-2 py-1.5 text-xs text-[var(--foreground)] placeholder-[var(--muted-foreground)] outline-none focus:border-[var(--primary)]"}),w&&I.length>0&&(0,s.jsx)("div",{className:"absolute left-0 right-0 top-full z-20 mt-1 max-h-64 overflow-y-auto rounded border border-[var(--border)] bg-[var(--background)] py-1 shadow-lg",children:I.map(e=>(0,s.jsxs)("div",{onClick:()=>{N(!1),c(e)},className:"group flex cursor-pointer items-center gap-2 px-2 py-1.5 hover:bg-[var(--secondary)]",children:[(0,s.jsx)(ry.A,{className:"h-3.5 w-3.5 shrink-0 text-[var(--muted-foreground)]"}),(0,s.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,s.jsx)("div",{className:"truncate text-xs text-[var(--foreground)]",children:e.split(/[/\\]/).filter(Boolean).pop()||e}),(0,s.jsx)("div",{className:"truncate text-[10px] text-[var(--muted-foreground)]",children:e})]}),(0,s.jsx)("button",{onClick:t=>{t.stopPropagation(),j(e)},title:"Remove from recent",className:"shrink-0 rounded p-0.5 text-[var(--muted-foreground)] opacity-0 hover:bg-[var(--border)] hover:text-[var(--foreground)] group-hover:opacity-100",children:(0,s.jsx)(eK.A,{className:"h-3 w-3"})})]},e))})]}),(0,s.jsx)("button",{onClick:()=>f(!0),title:"Browse for folder",className:"shrink-0 rounded border border-[var(--border)] p-1.5 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,s.jsx)(eN.A,{className:"h-3.5 w-3.5"})})]}),h&&(0,s.jsx)(r$,{initialPath:null==d?void 0:d.path,onSelect:e=>{f(!1),c(e)},onClose:()=>f(!1)}),a&&(0,s.jsxs)("div",{className:"flex shrink-0 items-center justify-between border-b border-[var(--border)] px-3 py-1.5",children:[(0,s.jsxs)("div",{className:"flex min-w-0 items-center gap-1.5",children:[(0,s.jsx)("span",{title:u(x?"status.busy":"status.idle"),className:D("inline-block h-2 w-2 shrink-0 rounded-full",x?"bg-amber-400 animate-pulse":"bg-emerald-500")}),(0,s.jsx)("span",{className:"truncate text-[10px] font-semibold uppercase tracking-wider text-[var(--muted-foreground)]",children:M})]}),(0,s.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,s.jsx)("button",{onClick:E,title:"New File",className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,s.jsx)(ey.A,{className:"h-3.5 w-3.5"})}),(0,s.jsx)("button",{onClick:T,title:"New Folder",className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,s.jsx)(ew.A,{className:"h-3.5 w-3.5"})}),(0,s.jsx)("button",{onClick:()=>{var e;return null==(e=g.current)?void 0:e.click()},title:"Upload Files",className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,s.jsx)(r3.A,{className:"h-3.5 w-3.5"})}),(0,s.jsx)("input",{ref:g,type:"file",multiple:!0,className:"hidden",onChange:F})]})]}),(0,s.jsx)("div",{className:"flex-1 overflow-y-auto",children:a?(0,s.jsx)(tl,{projectId:a,mode:"tree-only"}):(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center gap-2 p-6 text-center",children:[(0,s.jsx)(B.A,{className:"h-8 w-8 text-[var(--muted-foreground)]"}),(0,s.jsx)("p",{className:"text-xs text-[var(--muted-foreground)]",children:"Enter a folder path to explore files"})]})})]})}var r4=r(89983),r8=r(66926);let r6=(0,c.v)(e=>({selectedAgent:null,selectedSessionId:null,selectedSession:null,loadedMessages:null,loading:!1,setSelectedSession:t=>e({selectedAgent:t.agentName||t.agentId,selectedSessionId:t.id,selectedSession:t,loadedMessages:null}),setLoadedMessages:t=>e({loadedMessages:t,loading:!1}),setLoading:t=>e({loading:t}),clearSelection:()=>e({selectedAgent:null,selectedSessionId:null,selectedSession:null,loadedMessages:null,loading:!1})}));function r9(e){let t=new Map;for(let r of e)t.set(r.id,{...r,children:[]});let r=[];for(let e of t.values())e.parentSessionId&&t.has(e.parentSessionId)?t.get(e.parentSessionId).children.push(e):r.push(e);for(let e of t.values())e.children.sort((e,t)=>t.updatedAt-e.updatedAt);return r}function r7(e){let t=0;for(let r of e)t+=1+r7(r.children);return t}function ae(e){let{nodes:t,depth:r,expanded:a,selectedSessionId:n,onToggle:l,onSelect:o,editingId:i,editingTitle:c,setEditingTitle:d,onStartRename:u,onCommitRename:x,onCancelRename:m}=e,p=12+16*r;return(0,s.jsx)(s.Fragment,{children:t.map(e=>{let t=n===e.id,h=!!e.stoppedAt,f=!!e.archivedAt,g=e.children.length>0,v=a.has(e.id);return(0,s.jsxs)("div",{children:[(0,s.jsxs)("button",{onClick:()=>o(e),title:"Click to preview sub-agent session",className:D("group flex w-full items-center gap-1.5 pr-3 py-1.5 text-left transition-colors border-b border-[var(--border)]/10",t?"bg-[var(--secondary)]":"hover:bg-[var(--secondary)]/40",f&&"opacity-50"),style:{paddingLeft:"".concat(p,"px")},children:[g?(0,s.jsx)("span",{onClick:t=>{t.stopPropagation(),l(e.id)},className:"shrink-0 flex items-center justify-center w-4 h-4 -ml-0.5 cursor-pointer rounded hover:bg-[var(--muted)]/50",children:(0,s.jsx)(U.A,{className:D("h-2.5 w-2.5 text-[var(--muted-foreground)] transition-transform",v&&"rotate-90")})}):(0,s.jsx)("span",{className:"w-4 shrink-0 -ml-0.5"}),(0,s.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,s.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,s.jsx)("span",{className:"shrink-0 rounded bg-purple-900/50 px-1 py-0.5 text-[8px] text-purple-400",children:e.agentName||e.agentId}),i===e.id?(0,s.jsx)("input",{autoFocus:!0,value:c,onChange:e=>d(e.target.value),onClick:e=>e.stopPropagation(),onDoubleClick:e=>e.stopPropagation(),onKeyDown:t=>{"Enter"===t.key?(t.preventDefault(),x(e.id)):"Escape"===t.key&&(t.preventDefault(),m())},onBlur:()=>x(e.id),className:"min-w-0 flex-1 rounded border border-[var(--border)] bg-[var(--background)] px-1 py-0.5 text-[10px] text-[var(--foreground)] outline-none focus:border-blue-500"}):(0,s.jsx)("p",{className:"truncate text-[10px] text-[var(--foreground)]",children:e.title||"Untitled"}),h&&(0,s.jsx)("span",{title:"Stopped",children:(0,s.jsx)(r4.A,{className:"h-2.5 w-2.5 shrink-0 text-[var(--muted-foreground)]"})}),f&&(0,s.jsx)("span",{title:"Archived",children:(0,s.jsx)(r8.A,{className:"h-2.5 w-2.5 shrink-0 text-amber-500"})}),g&&(0,s.jsxs)("span",{className:"text-[9px] text-[var(--muted-foreground)]",children:["+",r7(e.children)]})]}),(0,s.jsxs)("p",{className:"text-[9px] text-[var(--muted-foreground)]",children:[e.messageCount," msgs \xb7 ",rw(e.updatedAt)]})]}),i!==e.id&&(0,s.jsx)("span",{onClick:t=>u(t,e),title:"Rename",className:"shrink-0 rounded p-0.5 text-[var(--muted-foreground)] opacity-0 group-hover:opacity-100 hover:text-blue-400 transition-opacity",children:(0,s.jsx)(eC.A,{className:"h-2.5 w-2.5"})})]}),v&&g&&(0,s.jsx)(ae,{nodes:e.children,depth:r+1,expanded:a,selectedSessionId:n,onToggle:l,onSelect:o,editingId:i,editingTitle:c,setEditingTitle:d,onStartRename:u,onCommitRename:x,onCancelRename:m})]},e.id)})})}let at=e=>"halo_selected_session_".concat(e);function ar(e){let t=[];return!function e(r){for(let a of r)t.push(a),e(a.children)}(e),t}function aa(){let e=t6(e=>e.isStreaming),t=t6(e=>e.sessionId),r=e9(e=>e.activeProject),{selectedSessionId:a,setSelectedSession:n,clearSelection:o,setLoadedMessages:i,setLoading:c}=r6(),[d,u]=(0,l.useState)([]),[x,m]=(0,l.useState)(null),p=(0,l.useRef)(0),[h,f]=(0,l.useState)(new Set),[g,b]=(0,l.useState)(!0),[y,w]=(0,l.useState)(!1),N=(0,l.useRef)(null),[k,S]=(0,l.useState)(null),[C,A]=(0,l.useState)(""),I=(0,l.useRef)(""),E=(0,l.useRef)(null),T=(0,l.useRef)(!1);(0,l.useEffect)(()=>{(null==r?void 0:r.id)&&N.current&&N.current!==r.id&&(o(),N.current=null)},[null==r?void 0:r.id,o]);let F=(0,l.useCallback)(async function(){let{showSpinner:e}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{showSpinner:!0};if(!(null==r?void 0:r.path)){u([]),m(null),b(!1);return}if(null!==E.current){T.current=!0;return}T.current=!1,e&&b(!0);let t=Math.min(300,Math.max(30,p.current)),a=Date.now();try{let e=await v.F.sessionLogs.list(r.path,{includeArchived:!0,limit:t}),a=e.sessions;u(r9(a)),m(e.nextCursor)}catch(e){console.error("[Sessions] Failed to fetch:",e),u([]),m(null)}finally{e?setTimeout(()=>b(!1),Math.max(0,350-(Date.now()-a))):b(!1)}},[null==r?void 0:r.path]),M=(0,l.useCallback)(async()=>{if((null==r?void 0:r.path)&&null!==x&&!y){w(!0);try{let e=await v.F.sessionLogs.list(r.path,{includeArchived:!0,limit:30,cursor:x}),t=e.sessions;u(e=>{let r=ar(e),a=new Set(r.map(e=>e.id)),n=[...r,...t.filter(e=>!a.has(e.id))];return r9(n)}),m(e.nextCursor)}catch(e){console.error("[Sessions] loadMore failed:",e)}finally{w(!1)}}},[null==r?void 0:r.path,x,y]);(0,l.useEffect)(()=>{p.current=d.length,d.length>=300&&m(null)},[d.length]);let P=rb(e=>e.version),L=(0,l.useRef)(!0);(0,l.useEffect)(()=>{F({showSpinner:L.current}),L.current=!1},[F,P]),(0,l.useEffect)(()=>{a&&!g&&!new Set(ar(d).map(e=>e.id)).has(a)&&(o(),(null==r?void 0:r.id)&&localStorage.removeItem(at(r.id)))},[d,a,g,o,null==r?void 0:r.id]);let R=(0,l.useRef)(e);(0,l.useEffect)(()=>{R.current&&!e&&setTimeout(()=>F({showSpinner:!1}),500),R.current=e},[e,F]);let z=(0,l.useCallback)(e=>{f(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),_=(0,l.useCallback)(async e=>{if(n(e),c(!0),(null==r?void 0:r.id)&&localStorage.setItem(at(r.id),e.id),e.id===t)return void i(t6.getState().messages);try{var a;let t=await v.F.sessionLogs.get(e.id,null==r?void 0:r.path);i(null!=(a=t.messages)?a:[])}catch(e){console.error("[Sessions] Load failed:",e),i([])}},[t,null==r?void 0:r.id,null==r?void 0:r.path,n,i,c]);(0,l.useEffect)(()=>{if(!(null==r?void 0:r.id)||g||0===d.length||N.current===r.id)return;N.current=r.id;let e=localStorage.getItem(at(r.id));if(!e)return;let t=ar(d),a=t.find(t=>t.id===e);if(!a)return;let n=new Map(t.map(e=>[e.id,e])),s=[],l=a;for(;null==l?void 0:l.parentSessionId;)s.push(l.parentSessionId),l=n.get(l.parentSessionId);s.length>0&&f(e=>{let t=new Set(e);for(let e of s)t.add(e);return t}),_(a)},[null==r?void 0:r.id,g,d,_]);let O=(0,l.useCallback)(e=>{r&&(t6.getState().setSessionId(e.id),t6.getState().setMessages([]),j.send({type:"subscribe",sessionId:e.id,projectId:r.id}),localStorage.setItem("halo_session_".concat(r.id),e.id))},[r]),W=(0,l.useCallback)(async(e,n)=>{if(e.stopPropagation(),null==r?void 0:r.path)try{u(e=>e.filter(e=>e.id!==n)),n===t&&((null==r?void 0:r.id)&&localStorage.removeItem("halo_session_".concat(r.id)),t6.getState().clear()),a===n&&(o(),(null==r?void 0:r.id)&&localStorage.removeItem(at(r.id))),await v.F.sessionLogs.delete(n,r.path),rj()}catch(e){console.error("[Sessions] Delete failed:",e),rj()}},[t,null==r?void 0:r.path,null==r?void 0:r.id,a,o]),B=(0,l.useCallback)((e,t)=>{e.stopPropagation(),E.current=t.id,I.current=t.title||"",S(t.id),A(t.title||"")},[]),K=(0,l.useCallback)(()=>{E.current=null,S(null),A(""),T.current&&F({showSpinner:!1})},[F]),G=(0,l.useCallback)(async e=>{if(E.current!==e)return;let t=C.trim();if(!t||t===I.current||!(null==r?void 0:r.path))return void K();E.current=null,S(null),u(r=>(function e(t,r,a){return t.map(t=>t.id===r?{...t,title:a}:{...t,children:e(t.children,r,a)})})(r,e,t));try{await v.F.sessionLogs.rename(e,t,r.path),rj()}catch(e){console.error("[Sessions] Rename failed:",e),rj()}},[C,null==r?void 0:r.path,K]),J=d.length,q=(0,l.useRef)(null);return(0,l.useEffect)(()=>{let e=q.current;if(!e||"undefined"==typeof IntersectionObserver)return;let t=new IntersectionObserver(e=>{var t;(null==(t=e[0])?void 0:t.isIntersecting)&&M()},{rootMargin:"64px"});return t.observe(e),()=>t.disconnect()},[M,d.length]),(0,s.jsxs)("div",{className:"flex h-full flex-col bg-[var(--background)]",children:[(0,s.jsxs)("div",{className:"flex h-10 shrink-0 items-center gap-2 border-b border-[var(--border)] px-3",children:[(0,s.jsx)(rS.A,{className:"h-4 w-4 text-[var(--muted-foreground)]"}),(0,s.jsx)("span",{className:"text-sm font-medium text-[var(--foreground)]",children:"Sessions"}),J>0&&(0,s.jsxs)("span",{className:"text-[10px] text-[var(--muted-foreground)]",children:["(",J,null!==x?"+":"",")"]}),(0,s.jsx)("div",{className:"flex-1"}),(0,s.jsx)("button",{onClick:()=>F(),disabled:g,className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)] transition-colors disabled:opacity-50",title:"Refresh sessions",children:(0,s.jsx)(r5.A,{className:D("h-3.5 w-3.5",g&&"animate-spin")})}),e&&(0,s.jsx)("span",{className:"rounded bg-blue-900/50 px-1.5 py-0.5 text-[9px] text-blue-400 animate-pulse",children:"running"})]}),(0,s.jsx)("div",{className:"flex-1 overflow-y-auto",children:g?(0,s.jsxs)("div",{className:"flex items-center justify-center py-8 text-xs text-[var(--muted-foreground)]",children:[(0,s.jsx)(H.A,{className:"h-3.5 w-3.5 animate-spin mr-1.5"})," Loading..."]}):0===d.length?(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center gap-2 p-6 text-center",children:[(0,s.jsx)(rS.A,{className:"h-8 w-8 text-[var(--muted-foreground)]"}),(0,s.jsx)("p",{className:"text-xs text-[var(--muted-foreground)]",children:"No session history yet"}),(0,s.jsx)("p",{className:"text-[10px] text-[var(--muted-foreground)]",children:"Start a conversation in the Chat panel"})]}):(0,s.jsxs)(s.Fragment,{children:[d.map(e=>{let r=e.children,n=h.has(e.id),l=e.id===t,o=a===e.id,i=!!e.archivedAt,c=r.length>0,d=r7(r);return(0,s.jsxs)("div",{children:[(0,s.jsxs)("button",{onClick:()=>_(e),onDoubleClick:()=>O(e),title:"Click to preview, double-click to load into chat",className:D("group flex w-full items-center gap-1.5 px-3 py-2 text-left border-b border-[var(--border)]/30 transition-colors",o?"bg-[var(--secondary)]":"hover:bg-[var(--secondary)]/50",i&&"opacity-50"),children:[c?(0,s.jsx)("span",{onClick:t=>{t.stopPropagation(),z(e.id)},className:"shrink-0 flex items-center justify-center w-5 h-5 -ml-1 cursor-pointer rounded hover:bg-[var(--muted)]/50",children:(0,s.jsx)(U.A,{className:D("h-3 w-3 text-[var(--muted-foreground)] transition-transform",n&&"rotate-90")})}):(0,s.jsx)("span",{className:"w-5 shrink-0 -ml-1"}),(0,s.jsx)(rC.A,{className:D("h-3.5 w-3.5 shrink-0",l?"text-blue-400":"text-[var(--muted-foreground)]")}),(0,s.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,s.jsxs)("div",{className:"flex items-center gap-1.5",children:[k===e.id?(0,s.jsx)("input",{autoFocus:!0,value:C,onChange:e=>A(e.target.value),onClick:e=>e.stopPropagation(),onDoubleClick:e=>e.stopPropagation(),onKeyDown:t=>{"Enter"===t.key?(t.preventDefault(),G(e.id)):"Escape"===t.key&&(t.preventDefault(),K())},onBlur:()=>G(e.id),className:"min-w-0 flex-1 rounded border border-[var(--border)] bg-[var(--background)] px-1 py-0.5 text-[11px] text-[var(--foreground)] outline-none focus:border-blue-500"}):(0,s.jsx)("p",{className:"truncate text-[11px] font-medium text-[var(--foreground)]",children:e.title||"Untitled"}),l&&(0,s.jsx)("span",{className:"shrink-0 rounded bg-blue-900/50 px-1 py-0.5 text-[8px] text-blue-400",children:"active"}),i&&(0,s.jsx)("span",{title:"Archived",children:(0,s.jsx)(r8.A,{className:"h-2.5 w-2.5 shrink-0 text-amber-500"})}),c&&(0,s.jsxs)("span",{className:"text-[9px] text-[var(--muted-foreground)]",children:["+",d]})]}),(0,s.jsxs)("p",{className:"text-[9px] text-[var(--muted-foreground)]",children:[e.messageCount," msgs \xb7 ",rw(e.updatedAt)]})]}),k!==e.id&&(0,s.jsx)("button",{onClick:t=>B(t,e),title:"Rename",className:"shrink-0 rounded p-0.5 text-[var(--muted-foreground)] opacity-0 group-hover:opacity-100 hover:text-blue-400 transition-opacity",children:(0,s.jsx)(eC.A,{className:"h-3 w-3"})}),(0,s.jsx)("button",{onClick:t=>W(t,e.id),className:"shrink-0 rounded p-0.5 text-[var(--muted-foreground)] opacity-0 group-hover:opacity-100 hover:text-red-400 transition-opacity",children:(0,s.jsx)(ej.A,{className:"h-3 w-3"})})]}),n&&c&&(0,s.jsx)(ae,{nodes:r,depth:1,expanded:h,selectedSessionId:a,onToggle:z,onSelect:_,editingId:k,editingTitle:C,setEditingTitle:A,onStartRename:B,onCommitRename:G,onCancelRename:K})]},e.id)}),null!==x&&(0,s.jsx)("div",{ref:q,className:"flex items-center justify-center py-2 text-[10px] text-[var(--muted-foreground)]",children:y?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(H.A,{className:"h-3 w-3 animate-spin mr-1"})," Loading more…"]}):(0,s.jsx)("span",{className:"opacity-50",children:"scroll for more"})})]})})]})}let an=(0,c.v)(e=>({version:0,bump:()=>e(e=>({version:e.version+1}))}));function as(){an.getState().bump()}var al=r(9747),ao=r(36822),ai=r(58271);function ac(e){return"".concat(e.id,":").concat(e.scope)}let ad="halo_skills_selectedKey",au="halo_skills_expandedScopes";function ax(){try{let e=localStorage.getItem(au);if(e)return new Set(JSON.parse(e))}catch(e){}return new Set(["global","workspace"])}let am=(0,c.v)(e=>({skills:[],selectedKey:localStorage.getItem(ad),setSkills:t=>e({skills:t}),setSelectedKey:t=>{t?localStorage.setItem(ad,t):localStorage.removeItem(ad),e({selectedKey:t})},addSkill:t=>e(e=>({skills:[...e.skills,t]})),removeSkill:t=>e(e=>{let r=e.skills.filter(e=>ac(e)!==t),[a,n]=t.split(":"),s="workspace"===n?r.map(e=>e.id===a&&"global"===e.scope?{...e,overridden:!1}:e):r,l=e.selectedKey===t?null:e.selectedKey;return e.selectedKey===t&&localStorage.removeItem(ad),{skills:s,selectedKey:l}})}));function ap(){let e=(0,tr.useT)(),{skills:t,selectedKey:r,setSkills:a,setSelectedKey:n,addSkill:o,removeSkill:i}=am(),c=e9(e=>e.activeProject),d=null==c?void 0:c.path,[u,x]=(0,l.useState)(ax),[m,p]=(0,l.useState)(!1),h=an(e=>e.version);async function f(e){if("workspace"===e&&!d)return;let r=await L("New ".concat(e," skill name:"));if(!(null==r?void 0:r.trim()))return;let s=r.trim().toLowerCase().replace(/[^a-z0-9一-鿿]+/g,"-").replace(/^-|-$/g,""),l="workspace"===e?"global":"workspace",i=t.find(e=>e.id===s&&e.scope===l);if(i){let t="workspace"===e?'Global skill "'.concat(i.name,'" has the same ID.\nWorkspace version will override it at runtime.\n\nContinue?'):'Workspace skill "'.concat(i.name,'" has the same ID.\nIt will override this global skill in that project.\n\nContinue?');if(!await R(t))return}try{let s=(await v.F.skills.create({name:r.trim(),scope:e,projectId:"workspace"===e?d:void 0})).skill;"workspace"===e&&i?a(t.map(e=>e.id===s.id&&"global"===e.scope?{...e,overridden:!0}:e).concat(s)):o(s),x(t=>new Set(t).add(e)),n(ac(s)),as()}catch(e){console.error("[SkillsSidebar] Create failed:",e)}}async function g(e,t){if(e.stopPropagation(),await R('Delete skill "'.concat(t.name,'"?')))try{await v.F.skills.remove(t.id,"workspace"===t.scope?{scope:"workspace",projectId:d}:void 0),i(ac(t)),as()}catch(e){console.error("[SkillsSidebar] Delete failed:",e)}}async function b(e,r){e.stopPropagation();try{let e=await v.F.skills.toggle(r.id,{scope:r.scope,projectId:d});a(t.map(t=>ac(t)===ac(r)?{...t,disabled:e.disabled}:t)),as()}catch(e){console.error("[SkillsSidebar] Toggle failed:",e)}}(0,l.useEffect)(()=>{localStorage.setItem(au,JSON.stringify([...u]))},[u]),(0,l.useEffect)(()=>{p(!0),v.F.skills.list(d).then(e=>a(e.skills)).catch(()=>{}).finally(()=>p(!1))},[d,h,a]),(0,l.useEffect)(()=>{if(d)return j.on("file:changed",e=>{("add"===e.action||"unlink"===e.action||"addDir"===e.action||"unlinkDir"===e.action)&&e.path.startsWith(".halo/skills/")&&as()})},[d]),(0,l.useEffect)(()=>{let e=()=>as();return window.addEventListener("focus",e),()=>window.removeEventListener("focus",e)},[]);let y=t.filter(e=>"global"===e.scope),w=t.filter(e=>"workspace"===e.scope),N=(e,t,a,l)=>{let o=u.has(e);return(0,s.jsxs)("div",{children:[(0,s.jsxs)("div",{className:"flex items-center h-8 px-2 hover:bg-[var(--secondary)]/50 transition-colors",children:[(0,s.jsxs)("button",{onClick:()=>{x(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},className:"flex items-center gap-1.5 flex-1 min-w-0",children:[(0,s.jsx)(U.A,{className:D("h-3 w-3 shrink-0 text-[var(--muted-foreground)] transition-transform",o&&"rotate-90")}),(0,s.jsx)(t,{className:"h-3 w-3 shrink-0 text-[var(--muted-foreground)]"}),(0,s.jsx)("span",{className:"text-[11px] font-medium text-[var(--foreground)] truncate",children:a}),(0,s.jsx)("span",{className:"text-[10px] text-[var(--muted-foreground)] ml-auto",children:l.length})]}),(0,s.jsx)("button",{onClick:t=>{t.stopPropagation(),f(e)},title:"New ".concat(e," skill"),className:"shrink-0 rounded p-0.5 text-[var(--muted-foreground)] hover:text-[var(--foreground)] hover:bg-[var(--secondary)]",children:(0,s.jsx)(rA.A,{className:"h-3 w-3"})})]}),o&&l.map(e=>{let t=ac(e);return(0,s.jsxs)("div",{onClick:()=>n(t),className:D("group flex w-full items-center gap-2 pl-7 pr-2 py-1.5 cursor-pointer transition-colors",r===t?"bg-[var(--secondary)]":"hover:bg-[var(--secondary)]/50",(e.overridden||e.disabled)&&"opacity-40"),children:[(0,s.jsx)(al.A,{className:"h-3 w-3 shrink-0 text-amber-500"}),(0,s.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,s.jsx)("p",{className:"text-[11px] font-medium text-[var(--foreground)] truncate",children:e.name}),(e.disabled||e.overridden||e.description)&&(0,s.jsx)("p",{className:"text-[10px] text-[var(--muted-foreground)] truncate",children:e.disabled?"disabled":e.overridden?"overridden":e.description})]}),(0,s.jsx)("button",{onClick:t=>b(t,e),className:D("shrink-0 rounded p-0.5 text-[var(--muted-foreground)] transition-opacity hover:text-[var(--foreground)]",e.disabled?"opacity-100":"opacity-0 group-hover:opacity-100"),title:e.disabled?"Enable skill":"Disable skill",children:e.disabled?(0,s.jsx)(ao.A,{className:"h-4.5 w-4.5"}):(0,s.jsx)(ai.A,{className:"h-4.5 w-4.5 text-blue-500"})}),(0,s.jsx)("button",{onClick:t=>g(t,e),className:"shrink-0 rounded p-0.5 text-[var(--muted-foreground)] opacity-0 transition-opacity group-hover:opacity-100 hover:text-red-400",title:"Delete skill",children:(0,s.jsx)(ej.A,{className:"h-3 w-3"})})]},t)})]},e)};return(0,s.jsxs)("div",{className:"flex h-full flex-col bg-[var(--background)]",children:[(0,s.jsxs)("div",{className:"flex h-10 shrink-0 items-center border-b border-[var(--border)] px-3",children:[(0,s.jsx)(al.A,{className:"h-4 w-4 text-[var(--muted-foreground)]"}),(0,s.jsx)("span",{className:"ml-2 text-sm font-medium text-[var(--foreground)]",children:e("skill.skills")}),(0,s.jsx)("div",{className:"flex-1"}),(0,s.jsx)("button",{onClick:()=>as(),disabled:m,title:"Refresh skills",className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)] transition-colors disabled:opacity-50",children:(0,s.jsx)(r5.A,{className:D("h-3.5 w-3.5",m&&"animate-spin")})})]}),(0,s.jsxs)("div",{className:"flex-1 overflow-y-auto py-1",children:[N("global",J.A,e("common.global"),y),d&&N("workspace",B.A,e("common.workspace"),w),0===t.length&&(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center gap-2 p-6 text-center",children:[(0,s.jsx)(al.A,{className:"h-8 w-8 text-[var(--muted-foreground)]"}),(0,s.jsx)("p",{className:"text-xs text-[var(--muted-foreground)]",children:e("skill.noSkills")})]})]})]})}var ah=r(1247),af=r(71611),ag=r(41601),av=r(30042);function ab(e){let{value:t,disabled:r,presets:a,placeholder:n,onCommit:o,minWidth:i=240,className:c}=e,[d,u]=(0,l.useState)(t),[x,m]=(0,l.useState)(!1),[p,h]=(0,l.useState)(""),[f,g]=(0,l.useState)(0),v=(0,l.useRef)(null),b=(0,l.useRef)(null);(0,l.useEffect)(()=>{u(t)},[t]),(0,l.useEffect)(()=>{x&&(h(""),g(0),setTimeout(()=>{var e;return null==(e=b.current)?void 0:e.focus()},0))},[x]);let j=(0,l.useMemo)(()=>{if(!p)return a;let e=p.toLowerCase();return a.filter(t=>t.id.toLowerCase().includes(e)||t.label.toLowerCase().includes(e))},[p,a]);function y(e){u(e),m(!1),e!==t&&o(e)}function w(){d!==t&&o(d)}return(0,l.useEffect)(()=>{f>=j.length&&g(0)},[j.length,f]),(0,l.useEffect)(()=>{if(x)return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e);function e(e){v.current&&!v.current.contains(e.target)&&m(!1)}},[x]),(0,s.jsxs)("div",{ref:v,className:"relative ".concat(null!=c?c:""),style:{minWidth:i},children:[(0,s.jsx)("input",{value:d,disabled:r,onFocus:()=>m(!0),onChange:e=>u(e.target.value),onBlur:()=>{setTimeout(()=>{x||w()},120)},onKeyDown:e=>{"ArrowDown"!==e.key||x?"Enter"===e.key?(e.preventDefault(),w()):"Escape"===e.key&&m(!1):(e.preventDefault(),m(!0))},placeholder:n,className:"h-7 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 pr-6 text-xs text-[var(--foreground)] outline-none focus:border-[var(--primary)]"}),(0,s.jsx)("span",{className:"pointer-events-none absolute right-2 top-1/2 -translate-y-1/2 text-[10px] opacity-50",children:"▾"}),x&&(0,s.jsxs)("div",{className:"absolute left-0 right-0 top-[calc(100%+2px)] z-20 max-h-72 overflow-hidden rounded border border-[var(--border)] bg-[var(--card)] shadow-lg",children:[(0,s.jsx)("div",{className:"border-b border-[var(--border)] p-1",children:(0,s.jsx)("input",{ref:b,value:p,onChange:e=>{h(e.target.value),g(0)},onKeyDown:e=>{if("ArrowDown"===e.key)e.preventDefault(),g(e=>Math.min(j.length-1,e+1));else if("ArrowUp"===e.key)e.preventDefault(),g(e=>Math.max(0,e-1));else if("Enter"===e.key){e.preventDefault();let t=j[f];t&&y(t.id)}else"Escape"===e.key&&m(!1)},placeholder:"Filter…",className:"h-6 w-full rounded border border-[var(--border)] bg-[var(--background)] px-2 text-xs text-[var(--foreground)] outline-none focus:border-[var(--primary)]"})}),(0,s.jsx)("div",{className:"max-h-56 overflow-auto",children:0===j.length?(0,s.jsx)("div",{className:"px-2 py-2 text-xs text-[var(--muted-foreground)]",children:"No matches"}):j.map((e,t)=>(0,s.jsxs)("div",{onMouseDown:t=>{t.preventDefault(),y(e.id)},onMouseEnter:()=>g(t),className:"cursor-pointer px-2 py-1 text-xs ".concat(t===f?"bg-[var(--primary)] text-[var(--primary-foreground)]":"text-[var(--foreground)] hover:bg-[var(--secondary)]"),children:[(0,s.jsx)("div",{className:"font-medium",children:e.label}),e.label!==e.id&&(0,s.jsx)("div",{className:"text-[10px] ".concat(t===f?"opacity-80":"opacity-60"),children:e.id})]},e.id))})]})]})}let aj={promptCaching:{ttlPresets:[{value:"5m",label:"5min"},{value:"1h",label:"1hour"}]},thinking:{effortPresets:[{value:"low",label:"Low"},{value:"medium",label:"Medium"},{value:"high",label:"High"},{value:"max",label:"Max"}]},verbosity:{presets:[{value:"low",label:"Low"},{value:"medium",label:"Medium"},{value:"high",label:"High"}]}};function ay(e,t){var r,a,n,s,l,o,i,c,d,u;let x=null==e?void 0:e.capabilities,m={},p=null==x?void 0:x.thinking,h=t.thinking;if(p||h){let e=null!=(r=null==p?void 0:p.mode)?r:"adaptive";if(h?!h.enabled:!(null==p?void 0:p.defaultEnabled))m.thinking=void 0;else if("manual"===e){let e=null==h?void 0:h.budget_tokens;m.thinking={enabled:!0,budget_tokens:null!=(a=null!=e?e:null==p?void 0:p.defaultBudgetTokens)?a:8192}}else{let e=null==p?void 0:p.effortPresets,t=null!=(s=null==h?void 0:h.effort)?s:null==h?void 0:h.budget,r=t&&(null==e?void 0:e.some(e=>e.value===t)),a=null!=(o=null!=(l=null==p?void 0:p.default)?l:null==e||null==(n=e[0])?void 0:n.value)?o:"medium";m.thinking={enabled:!0,effort:r?t:a}}}let f=null==x?void 0:x.promptCaching,g=null==f?void 0:f.ttlPresets;if(null==g?void 0:g.length){let e=t.promptCaching,r="string"==typeof e?e:void 0;r&&g.some(e=>e.value===r)?m.promptCaching=r:r?m.promptCaching=null!=(i=null==f?void 0:f.default)?i:g[0].value:m.promptCaching=null==(c=null==f?void 0:f.defaultEnabled)||c?null!=(d=null==f?void 0:f.default)?d:g[0].value:void 0}else m.promptCaching=void 0;let v=null==x?void 0:x.verbosity,b=null==v?void 0:v.presets,j="string"==typeof t.verbosity?t.verbosity:void 0;return(null==b?void 0:b.length)?j&&b.some(e=>e.value===j)?m.verbosity=j:m.verbosity=null!=(u=null==v?void 0:v.default)?u:void 0:m.verbosity=void 0,m}let aw="h-7 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 text-xs text-[var(--foreground)] outline-none focus:border-[var(--primary)]",aN="text-[11px] font-medium text-[var(--foreground)]",ak="text-[10px] text-[var(--muted-foreground)]";function aS(e){let{label:t,enabled:r,value:a,defaultValue:n,presets:l,onChange:o}=e;return(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsxs)("label",{className:"flex items-center gap-1.5 cursor-pointer",children:[(0,s.jsx)("input",{type:"checkbox",checked:r,onChange:e=>o(e.target.checked?a||n:void 0),className:"rounded border-[var(--border)] bg-[var(--card)] text-[var(--primary)] focus:ring-[var(--primary)] h-3.5 w-3.5 cursor-pointer"}),(0,s.jsx)("span",{className:aN,children:t})]}),r&&(0,s.jsx)(ab,{value:a||n,presets:l.map(e=>({id:e.value,label:e.label})),onCommit:e=>o(e||void 0),minWidth:110,className:"h-7"})]})}function aC(e){var t,r,a,n,l,o,i,c,d,u,x,m;let{data:p,availableSkills:h,availableTools:f,allAgents:g,selfId:v,modelsRegistry:b,onUpdate:j,onUpdateNested:y,onToggleArrayItem:w}=e,N=(0,tr.useT)(),k=null!=(a=p.model)?a:{},S=null!=(n=p.context)?n:{},C=Array.isArray(p.skills)?p.skills:[],A=Array.isArray(p.tools)?p.tools:[],I=Array.isArray(p.team)?p.team:void 0,E=null!=(l=null==b||null==(t=b.providers)?void 0:t.flatMap(e=>e.models))?l:[],T=String(null!=(o=k.id)?o:""),F=E.find(e=>e.id===T);return(0,s.jsxs)("div",{className:"h-full overflow-y-auto p-5 space-y-5",children:[(0,s.jsxs)("section",{className:"space-y-3",children:[(0,s.jsx)("h3",{className:"text-xs font-semibold uppercase tracking-wider text-[var(--muted-foreground)]",children:N("agent.basic")}),(0,s.jsxs)("div",{className:"grid grid-cols-[1fr_1fr_80px] gap-4",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:aN,children:N("agent.name")}),(0,s.jsx)("input",{value:String(null!=(i=p.name)?i:""),onChange:e=>j("name",e.target.value),className:D(aw,"mt-1")})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:aN,children:N("agent.description")}),(0,s.jsx)("input",{value:String(null!=(c=p.description)?c:""),onChange:e=>j("description",e.target.value),className:D(aw,"mt-1")})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:aN,children:N("agent.priority")}),(0,s.jsx)("input",{type:"number",value:null!=p.priority?String(p.priority):"",onChange:e=>j("priority",e.target.value?Number(e.target.value):void 0),className:D(aw,"mt-1"),placeholder:"0"})]})]})]}),(0,s.jsxs)("section",{className:"space-y-3",children:[(0,s.jsx)("h3",{className:"text-xs font-semibold uppercase tracking-wider text-[var(--muted-foreground)]",children:N("agent.model")}),(0,s.jsxs)("div",{className:"grid grid-cols-4 gap-4",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:aN,children:N("agent.provider")}),b&&b.providers.length>0?(0,s.jsx)("select",{value:String(null!=(u=k.provider)?u:null!=(d=null==(r=b.providers[0])?void 0:r.id)?d:""),onChange:e=>{var t,r,a,n,s;let l=b.providers.find(t=>t.id===e.target.value),o=String(null!=(t=k.id)?t:""),i=null==l?void 0:l.models.some(e=>e.id===o),c=null!=(a=null!=(r=null==l?void 0:l.models.find(e=>e.id===l.defaultModelId))?r:i?l.models.find(e=>e.id===o):void 0)?a:null==l?void 0:l.models[0];j("model",{...k,provider:e.target.value,id:null!=(n=null==c?void 0:c.id)?n:"",endpoint:null!=(s=null==l?void 0:l.defaultEndpoint)?s:"",...ay(c,k)})},className:D("h-7 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 text-xs text-[var(--foreground)] outline-none focus:border-[var(--primary)] appearance-none cursor-pointer","mt-1"),children:b.providers.map(e=>{var t;return(0,s.jsx)("option",{value:e.id,title:e.description,children:null!=(t=e.displayName)?t:e.id},e.id)})}):(0,s.jsx)("input",{value:String(null!=(x=k.provider)?x:""),onChange:e=>y("model","provider",e.target.value),className:D(aw,"mt-1")})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:aN,children:N("agent.modelId")}),(()=>{var e,t,r,a,n;let l=String(null!=(a=k.provider)?a:null!=(r=null==b||null==(e=b.providers[0])?void 0:e.id)?r:""),o=null!=(n=null==b||null==(t=b.providers.find(e=>e.id===l))?void 0:t.models)?n:[];return(0,s.jsx)(ab,{value:T,presets:o.map(e=>{var t;return{id:e.id,label:null!=(t=e.displayName)?t:e.id}}),placeholder:"model id",onCommit:e=>(function(e){let t=o.find(t=>t.id===e);j("model",{...k,id:e,...ay(t,k)})})(e),className:"mt-1"})})()]}),(()=>{var e,t,r,a,n;let l=String(null!=(r=k.provider)?r:null!=(t=null==b||null==(e=b.providers[0])?void 0:e.id)?t:""),o=null==b?void 0:b.providers.find(e=>e.id===l),i=null!=(a=null==o?void 0:o.defaultEndpoint)?a:"",c=null==o?void 0:o.endpointPresets;return(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:aN,children:N("agent.endpoint")}),(0,s.jsx)(ab,{value:String(null!=(n=k.endpoint)?n:""),presets:(null!=c?c:[]).map(e=>({id:e,label:e})),placeholder:i||"https://...",onCommit:e=>y("model","endpoint",e),className:"mt-1"}),i&&!k.endpoint&&(0,s.jsxs)("p",{className:D(ak,"mt-0.5"),children:["Default: ",i]})]})})(),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:aN,children:N("agent.maxTokens")}),(0,s.jsx)("input",{type:"number",value:null!=k.maxTokens?String(k.maxTokens):"",onChange:e=>y("model","maxTokens",e.target.value?Number(e.target.value):void 0),className:D(aw,"mt-1"),placeholder:(null==F?void 0:F.maxOutputTokens)?String(F.maxOutputTokens):"auto"}),(0,s.jsx)("p",{className:D(ak,"mt-0.5"),children:(null==F?void 0:F.maxOutputTokens)?N("agent.maxTokensDefault",{max:F.maxOutputTokens.toLocaleString()}):N("agent.maxTokensAuto")})]})]}),(()=>{var e,t,r,a,n,l,o,i;let c=null!=(l=null==F?void 0:F.capabilities)?l:T?aj:null;if(!c)return null;let d=null==(e=c.promptCaching)?void 0:e.ttlPresets,u=null==(t=c.thinking)?void 0:t.effortPresets;return(0,s.jsxs)("div",{className:"flex flex-wrap gap-6 pt-1",children:[d&&(0,s.jsx)(aS,{label:"Prompt Caching",enabled:!!k.promptCaching,value:"string"==typeof k.promptCaching?k.promptCaching:"",defaultValue:null!=(o=null==(r=c.promptCaching)?void 0:r.default)?o:d[0].value,presets:d,onChange:e=>y("model","promptCaching",e)}),(null==(n=c.verbosity)||null==(a=n.presets)?void 0:a.length)&&(0,s.jsx)(aS,{label:"Verbosity",enabled:"string"==typeof k.verbosity,value:"string"==typeof k.verbosity?k.verbosity:"",defaultValue:null!=(i=c.verbosity.default)?i:c.verbosity.presets[0].value,presets:c.verbosity.presets,onChange:e=>y("model","verbosity",e)}),(()=>{let e=!F&&""!==T,t=k.image,r=k.video,a=k.audio;if(e){let e=e=>{let{field:t,label:r,value:a}=e;return(0,s.jsx)("button",{type:"button",onClick:()=>y("model",t,!a||void 0),className:D("rounded px-2 py-0.5 text-[10px] font-medium transition-colors cursor-pointer",a?"bg-[var(--primary)] text-[var(--primary-foreground)]":"bg-[var(--secondary)] text-[var(--muted-foreground)] hover:text-[var(--foreground)]"),children:r})};return(0,s.jsxs)("div",{className:"flex items-center gap-1",children:[(0,s.jsx)(e,{field:"image",label:"Image",value:t}),(0,s.jsx)(e,{field:"video",label:"Video",value:r}),(0,s.jsx)(e,{field:"audio",label:"Audio",value:a})]})}return void 0===c.image&&void 0===c.video&&void 0===c.audio?null:(0,s.jsxs)("div",{className:"flex items-center gap-1",children:[void 0!==c.image&&(0,s.jsx)("span",{className:D("rounded px-2 py-0.5 text-[10px] font-medium",c.image?"bg-emerald-500/15 text-emerald-600":"bg-[var(--secondary)] text-[var(--muted-foreground)]"),children:"Image"}),void 0!==c.video&&(0,s.jsx)("span",{className:D("rounded px-2 py-0.5 text-[10px] font-medium",c.video?"bg-emerald-500/15 text-emerald-600":"bg-[var(--secondary)] text-[var(--muted-foreground)]"),children:"Video"}),void 0!==c.audio&&(0,s.jsx)("span",{className:D("rounded px-2 py-0.5 text-[10px] font-medium",c.audio?"bg-emerald-500/15 text-emerald-600":"bg-[var(--secondary)] text-[var(--muted-foreground)]"),children:"Audio"})]})})(),(u||c.thinking)&&(()=>{var e,t,r,a,n,l,o,i,d;let x=k.thinking,m=!!(null==x?void 0:x.enabled),p=!F&&""!==T,h=null!=(a=null==(e=c.thinking)?void 0:e.mode)?a:"adaptive",f=p?(null==x?void 0:x.budget_tokens)!=null?"manual":"adaptive":h,g=null!=(l=null!=(n=null==(t=c.thinking)?void 0:t.default)?n:null==u||null==(r=u[0])?void 0:r.value)?l:"medium",v="manual"===f?{enabled:!0,budget_tokens:8192}:{enabled:!0,effort:g};return(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsxs)("label",{className:"flex items-center gap-1.5 cursor-pointer",children:[(0,s.jsx)("input",{type:"checkbox",checked:m,onChange:e=>{y("model","thinking",e.target.checked?v:void 0)},className:"rounded border-[var(--border)] bg-[var(--card)] text-[var(--primary)] focus:ring-[var(--primary)] h-3.5 w-3.5 cursor-pointer"}),(0,s.jsx)("span",{className:aN,children:"Thinking"})]}),m&&"adaptive"===f&&u&&(0,s.jsx)(ab,{value:null!=(i=null!=(o=null==x?void 0:x.effort)?o:null==x?void 0:x.budget)?i:g,presets:u.map(e=>({id:e.value,label:e.label})),onCommit:e=>y("model","thinking",{enabled:!0,effort:e}),minWidth:110,className:"h-7"}),m&&"manual"===f&&(0,s.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,s.jsx)("span",{className:ak,children:"budget"}),(0,s.jsx)("input",{type:"number",min:1024,step:1024,value:null!=(d=null==x?void 0:x.budget_tokens)?d:8192,onChange:e=>{let t=parseInt(e.target.value,10);Number.isFinite(t)&&t>0&&y("model","thinking",{enabled:!0,budget_tokens:t})},className:"h-6 w-24 rounded border border-[var(--border)] bg-[var(--card)] px-2 text-[10px] text-[var(--foreground)] outline-none focus:border-[var(--primary)]"}),(0,s.jsx)("span",{className:ak,children:"tokens"})]}),m&&p&&(0,s.jsx)("button",{type:"button",onClick:()=>{"adaptive"===f?y("model","thinking",{enabled:!0,budget_tokens:8192}):y("model","thinking",{enabled:!0,effort:g})},className:"text-[10px] text-[var(--muted-foreground)] hover:text-[var(--foreground)] underline cursor-pointer",children:"adaptive"===f?"use budget":"use effort"})]})})()]})})(),Object.keys(S).length>0&&(0,s.jsx)("div",{className:"grid grid-cols-2 gap-4 pt-1",children:Object.entries(S).map(e=>{let[t,r]=e;return(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:aN,children:"context.".concat(t)}),(0,s.jsx)("input",{type:"number"==typeof r?"number":"text",step:"number"==typeof r&&r<1?"0.1":void 0,value:String(null!=r?r:""),onChange:e=>y("context",t,"number"==typeof r?Number(e.target.value):e.target.value),className:D(aw,"mt-1")})]},t)})})]}),(0,s.jsxs)("section",{className:"space-y-3",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("h3",{className:"text-xs font-semibold uppercase tracking-wider text-[var(--muted-foreground)]",children:N("agent.systemPrompt")}),(0,s.jsx)("span",{className:"text-[9px] text-[var(--muted-foreground)] opacity-60",children:N("agent.systemPromptHint")})]}),(0,s.jsx)("textarea",{value:String(null!=(m=p.system_prompt)?m:""),onChange:e=>j("system_prompt",e.target.value),rows:8,className:"w-full rounded border border-[var(--border)] bg-[var(--card)] px-3 py-2 text-xs leading-relaxed text-[var(--foreground)] outline-none focus:border-[var(--primary)] resize-y font-mono",placeholder:N("agent.systemPromptPlaceholder")})]}),(0,s.jsxs)("section",{className:"space-y-3",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("h3",{className:"text-xs font-semibold uppercase tracking-wider text-[var(--muted-foreground)]",children:N("agent.team")}),(0,s.jsx)("span",{className:"text-[9px] text-[var(--muted-foreground)] opacity-60",children:N("agent.teamHint")})]}),(0,s.jsx)("div",{className:"flex flex-wrap gap-2",children:g.map(e=>{let t=void 0!==I&&I.includes(e.id);return(0,s.jsxs)("button",{type:"button",title:e.id,onClick:()=>{let t=null!=I?I:[],r=t.includes(e.id)?t.filter(t=>t!==e.id):[...t,e.id];j("team",0===r.length?void 0:r)},className:D("rounded-full px-3 py-1 text-xs font-medium transition-colors cursor-pointer",t?"bg-[var(--primary)] text-[var(--primary-foreground)]":"bg-[var(--secondary)] text-[var(--muted-foreground)] hover:bg-[var(--secondary)]/80 hover:text-[var(--foreground)]"),children:[e.name,e.id===v?" (you)":""]},e.id)})})]}),(0,s.jsxs)("section",{className:"space-y-3",children:[(0,s.jsx)("h3",{className:"text-xs font-semibold uppercase tracking-wider text-[var(--muted-foreground)]",children:"Tools"}),0===f.length?(0,s.jsx)("p",{className:ak,children:N("agent.loadingTools")}):(()=>{var e;let t=new Set(f.map(e=>e.name)),r=new Set(["query_agent","start_session","session_list","get_session_output","query_session","interrupt_session","stop_session","archive_session"]),a=A.filter(e=>!t.has(e)&&!r.has(e)),n=k.image,l=null!=n?n:null==F||null==(e=F.capabilities)?void 0:e.image;return(0,s.jsxs)("div",{className:"flex flex-wrap gap-2",children:[f.map(e=>{let t=A.includes(e.name),r="view_image"===e.name&&""!==T&&!0!==l,a=r?"".concat(e.description,"\n\nNote: the selected model does not declare capabilities.image: true — view_image will be dropped from this agent's tool list at runtime."):e.description;return(0,s.jsxs)("button",{type:"button",title:a,onClick:()=>w("tools",e.name),className:D("rounded-full px-3 py-1 text-xs font-medium transition-colors cursor-pointer",t?"bg-[var(--primary)] text-[var(--primary-foreground)]":"bg-[var(--secondary)] text-[var(--muted-foreground)] hover:bg-[var(--secondary)]/80 hover:text-[var(--foreground)]",r&&"opacity-50"),children:[e.name,r&&(0,s.jsx)("span",{className:"ml-1",children:"⊘"})]},e.name)}),a.map(e=>(0,s.jsxs)("button",{type:"button",title:'Tool "'.concat(e,'" is not available in this server. Click to remove from this agent.'),onClick:()=>w("tools",e),className:"rounded-full px-3 py-1 text-xs font-medium transition-colors cursor-pointer border border-[var(--destructive)] bg-[var(--destructive)]/10 text-[var(--destructive)] hover:bg-[var(--destructive)]/20",children:["⚠ ",e]},"missing-".concat(e)))]})})()]}),(0,s.jsxs)("section",{className:"space-y-3",children:[(0,s.jsx)("h3",{className:"text-xs font-semibold uppercase tracking-wider text-[var(--muted-foreground)]",children:"Skills"}),(()=>{let e=h.filter(e=>!e.disabled),t=new Set(e.map(e=>e.id)),r=C.filter(e=>!t.has(e));return 0===e.length&&0===r.length?(0,s.jsx)("p",{className:ak,children:N("agent.noSkills")}):(0,s.jsxs)("div",{className:"flex flex-wrap gap-2",children:[e.map(e=>{let t=C.includes(e.id);return(0,s.jsx)("button",{type:"button",title:[e.description,"(".concat(e.scope,")")].filter(Boolean).join(" "),onClick:()=>w("skills",e.id),className:D("rounded-full px-3 py-1 text-xs font-medium transition-colors cursor-pointer",t?"bg-[var(--primary)] text-[var(--primary-foreground)]":"bg-[var(--secondary)] text-[var(--muted-foreground)] hover:bg-[var(--secondary)]/80 hover:text-[var(--foreground)]"),children:e.name},e.id)}),r.map(e=>(0,s.jsxs)("button",{type:"button",title:'Skill "'.concat(e,'" is not installed. Add it to ~/.halo/global/skills/ or ',"<workspace>","/.halo/skills/, or click to remove from this agent."),onClick:()=>w("skills",e),className:"rounded-full px-3 py-1 text-xs font-medium transition-colors cursor-pointer border border-[var(--destructive)] bg-[var(--destructive)]/10 text-[var(--destructive)] hover:bg-[var(--destructive)]/20",children:["⚠ ",e]},"missing-".concat(e)))]})})()]})]})}function aA(e){return"".concat(e.id,":").concat(e.scope)}let aI="halo_agents_selectedKey",aE="halo_agents_expandedScopes";function aT(){try{let e=localStorage.getItem(aE);if(e)return new Set(JSON.parse(e))}catch(e){}return new Set(["global","workspace"])}function aF(){var e,t;let r=(0,tr.useT)(),a=e9(e=>e.activeProject),n=null!=(e=null==a?void 0:a.path)?e:void 0,[o,c]=(0,l.useState)([]),[d,u]=(0,l.useState)(()=>localStorage.getItem(aI)),[x,m]=(0,l.useState)(aT),{skills:p,setSkills:h}=am(),[f,g]=(0,l.useState)(null),[b,y]=(0,l.useState)(!1);(0,l.useEffect)(()=>{d?localStorage.setItem(aI,d):localStorage.removeItem(aI)},[d]),(0,l.useEffect)(()=>{localStorage.setItem(aE,JSON.stringify([...x]))},[x]),(0,l.useEffect)(()=>{v.F.agentConfigs.models().then(g).catch(()=>{})},[]);let w=(0,l.useCallback)(async()=>{y(!0);try{let e=await v.F.agentConfigs.list(n);c(e.agents),!d&&e.agents.length>0&&u(aA(e.agents[0]))}catch(e){console.error("[AgentManagement] Load failed:",e)}finally{y(!1)}},[n,d]),N=rI(e=>e.version);(0,l.useEffect)(()=>{w()},[w,N]),(0,l.useEffect)(()=>{if(n)return j.on("file:changed",e=>{("add"===e.action||"unlink"===e.action||"addDir"===e.action||"unlinkDir"===e.action)&&e.path.startsWith(".halo/agents/")&&rE()})},[n]),(0,l.useEffect)(()=>{let e=()=>rE();return window.addEventListener("focus",e),()=>window.removeEventListener("focus",e)},[]),(0,l.useEffect)(()=>{p.length>0||v.F.skills.list(null==a?void 0:a.path).then(e=>{h(e.skills)}).catch(()=>{})},[null==a?void 0:a.path,p.length,h]);let k=null!=(t=o.find(e=>aA(e)===d))?t:null;async function S(e){var t;if("workspace"===e&&!n)return;let r=await L("Agent name:");if(!(null==r?void 0:r.trim()))return;let a=null!=(t=await L("Agent description (optional):"))?t:"",s=r.trim().toLowerCase().replace(/[^a-z0-9\u4e00-\u9fff]+/g,"-").replace(/^-|-$/g,""),l="workspace"===e?"global":"workspace",i=o.find(e=>e.id===s&&e.scope===l);if(i){let t="workspace"===e?'Global agent "'.concat(i.name,'" has the same ID.\nWorkspace version will override it at runtime.\n\nContinue?'):'Workspace agent "'.concat(i.name,'" has the same ID.\nIt will override this global agent in that project.\n\nContinue?');if(!await R(t))return}try{let t=(await v.F.agentConfigs.create({name:r.trim(),description:a.trim(),scope:e,projectId:"workspace"===e?n:void 0})).agent;c(r=>[..."workspace"===e?r.map(e=>e.id===t.id&&"global"===e.scope?{...e,overridden:!0}:e):r,t]),m(t=>new Set(t).add(e)),u(aA(t)),rE()}catch(e){console.error("[AgentManagement] Create failed:",e)}}async function C(e){if(await R('Delete agent "'.concat(e.name,'"?')))try{await v.F.agentConfigs.remove(e.id,{scope:e.scope,projectId:n}),c(t=>{let r=t.filter(t=>aA(t)!==aA(e));return"workspace"===e.scope?r.map(t=>t.id===e.id&&"global"===t.scope?{...t,overridden:!1}:t):r}),d===aA(e)&&u(null),rE()}catch(e){console.error("[AgentManagement] Delete failed:",e)}}async function A(e){try{let{disabled:t}=await v.F.agentConfigs.toggle(e.id,{scope:e.scope,projectId:n});c(r=>r.map(r=>aA(r)===aA(e)?{...r,disabled:t}:r)),rE()}catch(e){console.error("[AgentManagement] Toggle failed:",e)}}let I=o.filter(e=>e.internal),E=o.filter(e=>"global"===e.scope&&!e.internal),T=o.filter(e=>"workspace"===e.scope&&!e.internal),F=(()=>{let e=new Map;for(let t of[...E,...T])t.overridden||t.disabled||e.set(t.id,{id:t.id,name:t.name});return[...e.values()]})(),M=function(e,t,r,a){let l=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{allowCreate:!0},o=x.has(e);return(0,s.jsxs)("div",{children:[(0,s.jsxs)("div",{className:"flex items-center h-8 px-2 hover:bg-[var(--secondary)]/50 transition-colors",children:[(0,s.jsxs)("button",{onClick:()=>{m(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},className:"flex items-center gap-1.5 flex-1 min-w-0",children:[(0,s.jsx)(U.A,{className:D("h-3 w-3 shrink-0 text-[var(--muted-foreground)] transition-transform",o&&"rotate-90")}),(0,s.jsx)(t,{className:"h-3 w-3 shrink-0 text-[var(--muted-foreground)]"}),(0,s.jsx)("span",{className:"text-[11px] font-medium text-[var(--foreground)] truncate",children:r}),(0,s.jsx)("span",{className:"text-[10px] text-[var(--muted-foreground)] ml-auto",children:a.length})]}),l.allowCreate&&"internal"!==e&&(0,s.jsx)("button",{onClick:t=>{t.stopPropagation(),S(e)},title:"New ".concat(e," agent"),className:"shrink-0 rounded p-0.5 text-[var(--muted-foreground)] hover:text-[var(--foreground)] hover:bg-[var(--secondary)]",children:(0,s.jsx)(rA.A,{className:"h-3 w-3"})})]}),o&&a.map(t=>{let r=aA(t);return(0,s.jsxs)("div",{className:D("group flex w-full items-center gap-2 pl-7 pr-2 py-1.5 cursor-pointer transition-colors",d===r?"bg-[var(--secondary)]":"hover:bg-[var(--secondary)]/50",(t.overridden||t.disabled)&&"opacity-40"),onClick:()=>u(r),children:[(0,s.jsx)(rS.A,{className:"h-3 w-3 shrink-0 text-[var(--muted-foreground)]"}),(0,s.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,s.jsx)("p",{className:"text-[11px] font-medium text-[var(--foreground)] truncate",children:t.name}),(t.overridden||t.disabled||t.description)&&(0,s.jsx)("p",{className:"text-[10px] text-[var(--muted-foreground)] truncate",children:t.overridden?"overridden":t.disabled?"disabled":t.description})]}),"internal"!==e&&n&&(0,s.jsx)("button",{onClick:e=>{e.stopPropagation(),A(t)},title:t.disabled?"Enable (show in roster)":"Disable (hide from roster)",className:D("shrink-0 rounded p-0.5 text-[var(--muted-foreground)] transition-opacity hover:text-[var(--foreground)]",t.disabled?"opacity-100":"opacity-0 group-hover:opacity-100"),children:t.disabled?(0,s.jsx)(ao.A,{className:"h-4.5 w-4.5"}):(0,s.jsx)(ai.A,{className:"h-4.5 w-4.5 text-blue-500"})}),"global"===t.scope?(0,s.jsx)("span",{title:"Global agent (cannot delete)",children:(0,s.jsx)(ah.A,{className:"h-3 w-3 shrink-0 text-amber-500"})}):(0,s.jsx)("button",{onClick:e=>{e.stopPropagation(),C(t)},className:"shrink-0 rounded p-0.5 text-[var(--muted-foreground)] opacity-0 transition-opacity group-hover:opacity-100 hover:text-red-400",children:(0,s.jsx)(ej.A,{className:"h-3 w-3"})})]},r)})]},e)};return(0,s.jsxs)(i.YZ,{direction:"horizontal",autoSaveId:"halo-agent-mgmt",className:"h-full",children:[(0,s.jsx)(i.Zk,{defaultSize:22,minSize:12,maxSize:40,children:(0,s.jsxs)("div",{className:"h-full flex flex-col bg-[var(--background)]",children:[(0,s.jsxs)("div",{className:"flex h-10 items-center border-b border-[var(--border)] px-3",children:[(0,s.jsx)("span",{className:"text-sm font-medium text-[var(--foreground)]",children:r("agent.agents")}),(0,s.jsx)("div",{className:"flex-1"}),(0,s.jsx)("button",{onClick:()=>w(),disabled:b,className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)] transition-colors disabled:opacity-50",title:"Refresh agents",children:(0,s.jsx)(r5.A,{className:D("h-3.5 w-3.5",b&&"animate-spin")})})]}),(0,s.jsxs)("div",{className:"flex-1 overflow-y-auto py-1",children:[M("global",J.A,r("common.global"),E),n&&M("workspace",B.A,r("common.workspace"),T),I.length>0&&M("internal",af.A,"Internal",I,{allowCreate:!1})]})]})}),(0,s.jsx)(i.TW,{className:"w-px bg-[var(--border)] hover:w-1 hover:bg-[var(--primary)] transition-colors"}),(0,s.jsx)(i.Zk,{defaultSize:78,minSize:40,children:k?(0,s.jsx)(aD,{agent:k,allAgents:F,modelsRegistry:f,onSaved:e=>{c(t=>t.map(t=>aA(t)===aA(e)?e:t))}},aA(k)):(0,s.jsxs)("div",{className:"flex h-full flex-col items-center justify-center gap-3 text-center",children:[(0,s.jsx)(rS.A,{className:"h-10 w-10 text-[var(--muted-foreground)]"}),(0,s.jsx)("p",{className:"text-sm text-[var(--muted-foreground)]",children:r("agent.selectToEdit")})]})})]})}function aD(e){let{agent:t,allAgents:a,modelsRegistry:n,onSaved:o}=e,i=(0,tr.useT)(),{skills:c}=am(),d=e9(e=>e.activeProject),[u,x]=(0,l.useState)({}),m="halo_agent_view:".concat(aA(t)),[p,h]=(0,l.useState)(()=>{var e;return null!=(e=localStorage.getItem(m))?e:"form"}),g=(0,l.useCallback)(e=>{localStorage.setItem(m,e),h(e)},[m]),[b,y]=(0,l.useState)(!0),[w,N]=(0,l.useState)(!1),[k,S]=(0,l.useState)([]),[C,A]=(0,l.useState)("");(0,l.useEffect)(()=>{v.F.agentConfigs.tools().then(e=>S(e.tools)).catch(()=>{})},[]);let I=(0,l.useRef)(o);(0,l.useEffect)(()=>{I.current=o});let E=(0,l.useRef)(null),T=(0,l.useCallback)(async()=>{y(!0);let e="workspace"===t.scope?null==d?void 0:d.path:void 0;try{let a=await v.F.agentConfigs.getYaml(t.id,{scope:t.scope,projectId:e}),{parse:n,stringify:s}=await r.e(443).then(r.bind(r,51443)),l={};try{l=n(a.yaml)}catch(e){}let o=l&&"object"==typeof l?l:{};x(o),E.current=s(o,{lineWidth:120})}catch(e){console.error("[AgentEditor] Load YAML failed:",e),x({}),E.current=null}try{var a,n;let r=await v.F.agentConfigs.getMdAll(t.id,{scope:t.scope,projectId:e});A(null!=(n=null==(a=r.files["AGENT.md"])?void 0:a.content)?n:"")}catch(e){A("")}y(!1)},[t.id,t.scope,null==d?void 0:d.path]);(0,l.useEffect)(()=>{T()},[T]);let F=(0,l.useRef)(p);return(0,l.useEffect)(()=>{"edit"===F.current&&"form"===p&&T(),F.current=p},[p,T]),(0,l.useEffect)(()=>{if(b)return;let e=setTimeout(async()=>{try{let{stringify:e}=await r.e(443).then(r.bind(r,51443)),a=e(u,{lineWidth:120});if(E.current===a)return;N(!0);let n="workspace"===t.scope?null==d?void 0:d.path:void 0,s=await v.F.agentConfigs.saveYaml(t.id,a,{scope:t.scope,projectId:n});E.current=a,I.current(s.agent)}catch(e){console.error("[AgentEditor] Auto-save failed:",e)}finally{N(!1)}},500);return()=>clearTimeout(e)},[u,t.id,t.scope,null==d?void 0:d.path,b]),(0,l.useEffect)(()=>{E.current=null},[t.id,t.scope]),(0,s.jsxs)("div",{className:"flex h-full flex-col",children:[(0,s.jsxs)("div",{className:"flex h-10 items-center justify-between border-b border-[var(--border)] bg-[var(--card)] px-3",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:["edit"===p&&(0,s.jsxs)("button",{onClick:()=>g("form"),className:"flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",title:"Back to form",children:[(0,s.jsx)(ag.A,{className:"h-3 w-3"}),i("agent.back")]}),(0,s.jsx)("span",{className:"text-xs font-medium text-[var(--foreground)]",children:t.name}),(0,s.jsx)("span",{className:"rounded bg-[var(--secondary)] px-1.5 py-0.5 text-[9px] text-[var(--muted-foreground)]",children:t.scope}),"form"===p&&w&&(0,s.jsx)("span",{className:"text-[9px] text-[var(--muted-foreground)]",children:i("agent.saving")})]}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[!t.internal&&(0,s.jsxs)("button",{onClick:()=>(function(e,t){let r=t6.getState().sessionId;r&&j.send({type:"session:clear",sessionId:r}),t&&localStorage.removeItem("halo_session_".concat(t)),t6.getState().clear(),t6.getState().setSelectedAgentId(e),window.dispatchEvent(new CustomEvent("halo:navigate",{detail:{tab:"explorer"}}))})(t.id,null==d?void 0:d.id),className:"flex items-center gap-1.5 rounded bg-[var(--secondary)] px-2.5 py-1 text-xs font-medium text-[var(--foreground)] transition-colors hover:bg-[var(--secondary)]/80",children:[(0,s.jsx)(av.A,{className:"h-3 w-3"}),i("agent.test")]}),"form"===p&&(0,s.jsxs)("button",{onClick:()=>g("edit"),className:"flex items-center gap-1.5 rounded bg-[var(--primary)] px-3 py-1 text-xs font-medium text-[var(--primary-foreground)] transition-colors hover:opacity-90",title:i("agent.editHint"),children:[(0,s.jsx)(eC.A,{className:"h-3 w-3"}),i("agent.edit")]})]})]}),(0,s.jsx)("div",{className:"flex-1 min-h-0 overflow-hidden",children:"edit"===p?(0,s.jsx)(f,{children:(0,s.jsx)(tl,{projectId:t.path,mode:"full",showMaximize:!1})},"".concat(t.id,":").concat(t.scope)):b?(0,s.jsx)("div",{className:"flex h-full items-center justify-center text-sm text-[var(--muted-foreground)]",children:i("agent.loading")}):(0,s.jsxs)("div",{className:"h-full overflow-y-auto",children:[(0,s.jsx)(aC,{data:u,availableSkills:c,availableTools:k,allAgents:a,selfId:t.id,modelsRegistry:n,onUpdate:function(e,t){x(r=>({...r,[e]:t}))},onUpdateNested:function(e,t,r){x(a=>{var n;let s=null!=(n=a[e])?n:{};return{...a,[e]:{...s,[t]:r}}})},onToggleArrayItem:function(e,t){x(r=>{let a=Array.isArray(r[e])?[...r[e]]:[],n=a.indexOf(t);return n>=0?a.splice(n,1):a.push(t),{...r,[e]:a}})}}),C.trim()&&(0,s.jsxs)("div",{className:"border-t border-[var(--border)]",children:[(0,s.jsxs)("div",{className:"flex items-center gap-1.5 px-8 pt-6 text-[10px] uppercase tracking-wide text-[var(--muted-foreground)]",children:[(0,s.jsx)("span",{className:"rounded bg-[var(--secondary)] px-1.5 py-0.5",children:"AGENT.md"}),(0,s.jsx)("span",{children:i("agent.mdPreviewHint")})]}),(0,s.jsx)(e_,{content:C})]})]})})]})}function aM(){var e;let{skills:t,selectedKey:r}=am(),a=null!=(e=t.find(e=>"".concat(e.id,":").concat(e.scope)===r))?e:null;return a?(0,s.jsx)(f,{children:(0,s.jsx)(tl,{projectId:a.path,mode:"full",showMaximize:!1})},"".concat(a.id,":").concat(a.scope)):(0,s.jsxs)("div",{className:"flex h-full flex-col items-center justify-center gap-3 text-center bg-[var(--background)]",children:[(0,s.jsx)(al.A,{className:"h-10 w-10 text-[var(--muted-foreground)]"}),(0,s.jsx)("p",{className:"text-sm text-[var(--muted-foreground)]",children:"Select a skill to edit, or create a new one"})]})}var aP=r(34409),aL=r(68654);function aR(){let e=t6(e=>e.messages),t=t6(e=>e.sessionId),r=t6(e=>e.isStreaming),a=r6(e=>e.selectedSessionId),n=r6(e=>e.selectedSession),o=r6(e=>e.loadedMessages),i=r6(e=>e.loading),c=e9(e=>e.activeProject),d=(0,l.useRef)(null),[u,x]=(0,l.useState)(!1),[m,p]=(0,l.useState)(()=>"1"===localStorage.getItem("halo_session_debug")),[h,f]=(0,l.useState)(()=>"1"===localStorage.getItem("halo_session_prompt"));(0,l.useEffect)(()=>{localStorage.setItem("halo_session_debug",m?"1":"0")},[m]),(0,l.useEffect)(()=>{localStorage.setItem("halo_session_prompt",h?"1":"0")},[h]);let g=r6(e=>e.setLoadedMessages);(0,l.useEffect)(()=>{var e;if(!a||!(null==c?void 0:c.path)||a===t)return;let r=null!=(e=a.split(">").pop())?e:a;return j.on("file:changed",e=>{("change"===e.action||"add"===e.action)&&e.path.startsWith(".halo/sessions/")&&e.path.endsWith("/".concat(r,".json"))&&v.F.sessionLogs.get(a,c.path).then(e=>{var t;let r=null!=(t=e.messages)?t:[],a=r6.getState().loadedMessages,n=function(e,t){if(!e||0===e.length)return t;let r=e.length===t.length,a=t.map((t,a)=>{let n=e[a];return n&&JSON.stringify(n)===JSON.stringify(t)?n:(r=!1,t)});return r?e:a}(a,r);n!==a&&g(n)}).catch(()=>{})})},[a,t,null==c?void 0:c.path,g]);let b=(0,l.useMemo)(()=>{if(!a)return[];if(a===t){let t=e.filter(e=>!e.taskId);return m?t:t.filter(ti)}let r=null!=o?o:[];return m?r:r.filter(e=>!function(e){let t=to(e);return"tool_call"===t||"tool_result"===t||"usage"===t||"context"===t||"agent_start"===t||"agent_done"===t}(e))},[a,t,e,o,m]),y=(0,l.useMemo)(()=>{for(let r of a===t?e:null!=o?o:[])if("context"===to(r)&&r.systemPrompt)return r.systemPrompt;return null},[a,t,e,o]),w=(0,l.useRef)(!0);return(0,l.useEffect)(()=>{let e=d.current;if(!e)return;let t=()=>{w.current=e.scrollHeight-e.scrollTop-e.clientHeight<60};return e.addEventListener("scroll",t,{passive:!0}),()=>e.removeEventListener("scroll",t)},[]),(0,l.useEffect)(()=>{w.current&&d.current&&(d.current.scrollTop=d.current.scrollHeight)},[b]),(0,s.jsxs)("div",{className:"flex h-full flex-col bg-[var(--background)]",children:[(0,s.jsxs)("div",{className:"flex h-10 shrink-0 items-center gap-2 border-b border-[var(--border)] px-3 min-w-0",children:[a?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(aP.A,{className:"h-4 w-4 shrink-0 text-[var(--muted-foreground)]"}),(null==n?void 0:n.agentName)&&(0,s.jsx)("span",{className:"shrink-0 rounded bg-purple-900/50 px-1.5 py-0.5 text-[10px] text-purple-400",children:n.agentName}),(0,s.jsx)("span",{className:"truncate text-xs font-medium text-[var(--foreground)]",title:(null==n?void 0:n.title)||"Untitled",children:(null==n?void 0:n.title)||"Untitled"}),(0,s.jsxs)("span",{className:"shrink-0 text-[10px] text-[var(--muted-foreground)]",children:["(",b.length,")"]}),a===t&&(0,s.jsx)("span",{className:"shrink-0 rounded bg-blue-900/50 px-1.5 py-0.5 text-[8px] text-blue-400",children:"live"}),(null==n?void 0:n.parentSessionId)&&(0,s.jsx)("span",{className:"shrink-0 rounded bg-[var(--secondary)] px-1 py-0.5 text-[8px] text-[var(--muted-foreground)]",title:"Sub-session",children:"sub"}),(null==n?void 0:n.stoppedAt)&&(0,s.jsx)("span",{className:"shrink-0 rounded bg-[var(--secondary)] px-1 py-0.5 text-[8px] text-[var(--muted-foreground)]",children:"stopped"}),(null==n?void 0:n.archivedAt)&&(0,s.jsx)("span",{className:"shrink-0 rounded bg-amber-900/50 px-1 py-0.5 text-[8px] text-amber-400",title:"Archived: ".concat(new Date(n.archivedAt).toLocaleString()),children:"archived"}),(null==n?void 0:n.createdAt)&&(0,s.jsx)("span",{className:"shrink-0 text-[10px] text-[var(--muted-foreground)]",title:"Created: ".concat(new Date(n.createdAt).toLocaleString()),children:rw(n.createdAt)}),(0,s.jsxs)("button",{onClick:()=>{a&&navigator.clipboard.writeText(a).then(()=>{x(!0),setTimeout(()=>x(!1),1200)}).catch(()=>{})},title:"Session ID: ".concat(a),className:"shrink-0 flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-mono text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)] transition-colors",children:[u?(0,s.jsx)(tD.A,{className:"h-2.5 w-2.5 text-green-400"}):(0,s.jsx)(tM.A,{className:"h-2.5 w-2.5"}),a.slice(0,8)]})]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(rS.A,{className:"h-4 w-4 text-[var(--muted-foreground)]"}),(0,s.jsx)("span",{className:"text-sm font-medium text-[var(--foreground)]",children:"Session Viewer"})]}),a&&(0,s.jsxs)("div",{className:"ml-auto flex items-center gap-1",children:[y&&(0,s.jsxs)("button",{onClick:()=>f(!h),className:D("flex items-center gap-1 rounded px-1.5 py-0.5 text-[9px] transition-colors",h?"bg-purple-900/50 text-purple-400":"text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]"),title:"View system prompt",children:[(0,s.jsx)(Z.A,{className:"h-3 w-3"}),"Prompt"]}),(0,s.jsxs)("button",{onClick:()=>p(!m),className:D("flex items-center gap-1 rounded px-1.5 py-0.5 text-[9px] transition-colors",m?"bg-amber-900/50 text-amber-400":"text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]"),title:"Debug mode: show all messages including sub-agent tool calls",children:[(0,s.jsx)(aL.A,{className:"h-3 w-3"}),"Debug"]})]}),r&&a===t&&(0,s.jsx)("span",{className:"rounded bg-blue-900/50 px-1.5 py-0.5 text-[9px] text-blue-400 animate-pulse",children:"streaming"})]}),(0,s.jsxs)("div",{ref:d,className:"relative flex-1 overflow-y-auto",children:[h&&y&&(0,s.jsxs)("div",{className:"sticky top-2 right-2 z-10 float-right ml-2 mb-2 mr-2 w-[min(520px,80%)] rounded-md border border-purple-900/60 bg-[var(--background)] shadow-lg",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between border-b border-purple-900/50 bg-purple-950/40 px-3 py-1.5 rounded-t-md",children:[(0,s.jsx)("span",{className:"text-[10px] font-semibold text-purple-400",children:"System Prompt"}),(0,s.jsx)("button",{onClick:()=>f(!1),title:"Close",className:"rounded p-0.5 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,s.jsx)(eK.A,{className:"h-3 w-3"})})]}),(0,s.jsx)("pre",{className:"px-3 py-2 text-[11px] text-[var(--foreground)] whitespace-pre-wrap break-words leading-relaxed max-h-[60vh] overflow-y-auto",children:y})]}),i?(0,s.jsxs)("div",{className:"flex items-center justify-center py-8 text-xs text-[var(--muted-foreground)]",children:[(0,s.jsx)(H.A,{className:"h-3.5 w-3.5 animate-spin mr-1.5"})," Loading session..."]}):a?0===b.length?(0,s.jsxs)("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center",children:[(0,s.jsx)(rS.A,{className:"h-8 w-8 text-[var(--muted-foreground)]"}),(0,s.jsx)("p",{className:"text-sm text-[var(--muted-foreground)]",children:"No messages in this session"})]}):(0,s.jsx)(tP,{messages:b,debugMode:m}):(0,s.jsxs)("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center",children:[(0,s.jsx)(rS.A,{className:"h-8 w-8 text-[var(--muted-foreground)]"}),(0,s.jsx)("p",{className:"text-sm text-[var(--muted-foreground)]",children:"Select a session from the sidebar to view messages"})]})]})]})}var az=r(53762),a_=r(51334),aO=r(46565),aW=r(6653);function aU(){var e,t,r;let{t:a,refreshFromServer:n}=(0,tr.useI18n)(),{refreshFromServer:o}=(0,eE.useTheme)(),i=e9(e=>e.activeProject),[c,d]=(0,l.useState)("global"),[u,x]=(0,l.useState)(null),[m,p]=(0,l.useState)("general"),[h,f]=(0,l.useState)(!1),[g,b]=(0,l.useState)(!1),[j,y]=(0,l.useState)(null),w="workspace"===c?null==i?void 0:i.path:void 0,N=(0,l.useCallback)(()=>{b(!0),v.F.settings.getSchema(w).then(e=>{x(e),p(t=>"__orphans"===t||e.sections.find(e=>e.namespaceId===t)?t:"general")}).catch(e=>{console.error("[Settings] schema load failed:",e)}).finally(()=>b(!1))},[w]);async function k(e,t,r){f(!0);try{let a="general"===e?"general.".concat(t.key):"".concat(e,".").concat(t.kind,"s.").concat(t.key);if(""===r)await v.F.settings.remove(c,a,w);else{let e=function(e,t){switch(e){case"int":{let e=parseInt(t,10);return Number.isFinite(e)?e:t}case"float":{let e=parseFloat(t);return Number.isFinite(e)?e:t}case"boolean":return"true"===t;default:return t}}(t.type,r);await v.F.settings.patch(c,a,e,w)}N(),n(),o()}catch(e){console.error("[Settings] save failed:",e)}finally{f(!1)}}async function S(e,t){f(!0);try{let r="general"===e?"general.".concat(t.key):"".concat(e,".").concat(t.kind,"s.").concat(t.key);await v.F.settings.remove(c,r,w),N(),n(),o()}catch(e){console.error("[Settings] reset failed:",e)}finally{f(!1)}}async function C(e){let t="".concat(e.namespaceId,".").concat(e.kind,"s.").concat(e.key);if(confirm(a("settings.orphans.confirm",{key:t}))){f(!0);try{await v.F.settings.remove(c,t,w),N()}catch(e){console.error("[Settings] orphan remove failed:",e)}finally{f(!1)}}}(0,l.useEffect)(()=>{N()},[N]),(0,l.useEffect)(()=>{v.F.health().then(e=>y("string"==typeof(null==e?void 0:e.version)?e.version:null)).catch(()=>y(null))},[]);let A=null!=(e=null==u?void 0:u.sections)?e:[],I=null!=(t=null==u?void 0:u.orphans)?t:[],E=(0,l.useMemo)(()=>A.find(e=>e.namespaceId===m),[A,m]);return(0,s.jsxs)("div",{className:"flex h-full bg-[var(--background)]",children:[(0,s.jsxs)("div",{className:"flex w-[220px] shrink-0 flex-col border-r border-[var(--border)]",children:[(0,s.jsxs)("div",{className:"flex h-10 items-center gap-2 border-b border-[var(--border)] px-3",children:[(0,s.jsx)(az.A,{className:"h-4 w-4 text-[var(--muted-foreground)]"}),(0,s.jsx)("span",{className:"text-sm font-medium text-[var(--foreground)]",children:a("nav.settings")}),(0,s.jsx)("div",{className:"flex-1"}),(0,s.jsx)("button",{onClick:N,disabled:g,title:"Refresh",className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)] transition-colors disabled:opacity-50",children:(0,s.jsx)(r5.A,{className:D("h-3.5 w-3.5",g&&"animate-spin")})})]}),(0,s.jsxs)("div",{className:"min-h-0 flex-1 overflow-y-auto",children:[(0,s.jsxs)("div",{className:"border-b border-[var(--border)] p-2",children:[(0,s.jsxs)("div",{className:"flex rounded-md bg-[var(--card)] p-0.5",children:[(0,s.jsxs)("button",{onClick:()=>d("global"),className:D("flex flex-1 items-center justify-center gap-1 rounded-sm px-2 py-1 text-[10px] font-medium transition-colors","global"===c?"bg-[var(--secondary)] text-[var(--foreground)]":"text-[var(--muted-foreground)] hover:text-[var(--foreground)]"),children:[(0,s.jsx)(J.A,{className:"h-3 w-3"}),a("common.global")]}),(0,s.jsxs)("button",{onClick:()=>d("workspace"),disabled:!i,className:D("flex flex-1 items-center justify-center gap-1 rounded-sm px-2 py-1 text-[10px] font-medium transition-colors","workspace"===c?"bg-[var(--secondary)] text-[var(--foreground)]":"text-[var(--muted-foreground)] hover:text-[var(--foreground)]",!i&&"cursor-not-allowed opacity-40"),children:[(0,s.jsx)(a_.A,{className:"h-3 w-3"}),a("common.workspace")]})]}),"workspace"===c&&i&&(0,s.jsx)("p",{className:"mt-1 truncate text-[9px] text-[var(--muted-foreground)]",children:i.path})]}),(0,s.jsx)(aB,{sections:A,orphans:I,active:m,onPick:p})]}),j&&(0,s.jsxs)("div",{className:"shrink-0 border-t border-[var(--border)] px-3 py-2 text-[10px] text-[var(--muted-foreground)]",children:["Halo v",j]})]}),(0,s.jsxs)("div",{className:"flex min-w-0 flex-1 flex-col",children:[(0,s.jsx)("div",{className:"flex h-10 shrink-0 items-center justify-between border-b border-[var(--border)] px-4",children:(0,s.jsxs)("span",{className:"text-[11px] text-[var(--muted-foreground)]",children:["global"===c?"~/.halo/secrets/settings.yaml":"".concat(null!=(r=null==i?void 0:i.path)?r:"...","/.halo/settings.yaml")," ","→ ",(0,s.jsx)("code",{className:"text-[var(--foreground)]",children:m})]})}),(0,s.jsx)("div",{className:"min-h-0 flex-1 overflow-y-auto",children:"__orphans"===m?(0,s.jsx)(aX,{orphans:I,onRemove:C,saving:h}):E?(0,s.jsx)(aK,{section:E,scope:c,saving:h,onSave:(e,t)=>k(E.namespaceId,e,t),onReset:e=>S(E.namespaceId,e)}):(0,s.jsx)("div",{className:"p-10 text-center text-xs text-[var(--muted-foreground)]",children:u?a("settings.empty"):a("settings.loading")})})]})]})}function aB(e){let{sections:t,orphans:r,active:a,onPick:n}=e,{t:o}=(0,tr.useI18n)(),i=(0,l.useMemo)(()=>{let e=t.filter(e=>"general"===e.source),r=t.filter(e=>"provider"===e.source);return{general:e,providers:r,skills:t.filter(e=>"skill"===e.source),agents:t.filter(e=>"agent"===e.source)}},[t]);return(0,s.jsxs)("div",{className:"py-1",children:[(0,s.jsx)(aH,{label:o("settings.nav.system"),items:i.general,active:a,onPick:n}),(0,s.jsx)(aH,{label:o("settings.nav.providers"),items:i.providers,active:a,onPick:n}),(0,s.jsx)(aH,{label:o("settings.nav.agents"),items:i.agents,active:a,onPick:n}),(0,s.jsx)(aH,{label:o("settings.nav.skills"),items:i.skills,active:a,onPick:n}),r.length>0&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"mt-2 px-3 pb-1 pt-2 text-[9px] font-semibold uppercase tracking-wider text-[var(--muted-foreground)]",children:o("settings.nav.orphans")}),(0,s.jsxs)("button",{onClick:()=>n("__orphans"),className:D("flex w-full cursor-pointer items-center gap-2 px-3 py-1.5 text-[11px] transition-colors","__orphans"===a?"bg-[var(--secondary)] text-[var(--foreground)]":"text-[var(--foreground)]/80 hover:bg-[var(--secondary)] hover:text-[var(--foreground)]"),children:[(0,s.jsx)(ej.A,{className:"h-3 w-3"}),(0,s.jsx)("span",{children:o("settings.nav.unclaimed")}),(0,s.jsx)("span",{className:"ml-auto rounded bg-[var(--card)] px-1 py-0 text-[9px]",children:r.length})]})]})]})}function aH(e){let{label:t,items:r,active:a,onPick:n}=e,{lang:l}=(0,tr.useI18n)();return 0===r.length?null:(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"px-3 pb-1 pt-2 text-[9px] font-semibold uppercase tracking-wider text-[var(--muted-foreground)]",children:t}),r.map(e=>{let t="zh"===l&&e.displayName_zh||e.displayName,r="zh"===l&&e.description_zh||e.description;return(0,s.jsx)("button",{onClick:()=>n(e.namespaceId),className:D("flex w-full cursor-pointer items-center gap-2 px-3 py-1.5 text-[11px] transition-colors",a===e.namespaceId?"bg-[var(--secondary)] text-[var(--foreground)]":"text-[var(--foreground)]/80 hover:bg-[var(--secondary)] hover:text-[var(--foreground)]"),title:null!=r?r:e.namespaceId,children:(0,s.jsx)("span",{className:"truncate",children:t})},e.namespaceId)})]})}function aK(e){let{section:t,scope:r,saving:a,onSave:n,onReset:l}=e,{t:o,lang:i}=(0,tr.useI18n)(),c=t.fields.filter(e=>"param"===e.kind),d=t.fields.filter(e=>"secret"===e.kind),u="zh"===i&&t.displayName_zh||t.displayName,x="zh"===i&&t.description_zh||t.description,[m,p]=o("settings.section.secretsHint",{placeholder:"\0"}).split("\0");return(0,s.jsxs)("div",{className:"space-y-6 p-6",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("h2",{className:"text-sm font-semibold text-[var(--foreground)]",children:u}),x&&(0,s.jsx)("p",{className:"mt-0.5 text-[10px] text-[var(--muted-foreground)]",children:x}),(0,s.jsxs)("p",{className:"mt-0.5 text-[10px] text-[var(--muted-foreground)]",children:[o("settings.section.namespace"),": ",(0,s.jsx)("code",{className:"text-[var(--foreground)]",children:t.namespaceId})," \xb7 ",o("settings.section.declaredBy"),": ",(0,s.jsx)("span",{children:o("settings.section.declaredBy.".concat(t.source))})]})]}),c.length>0&&(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsx)("h3",{className:"text-[11px] font-semibold uppercase tracking-wider text-[var(--muted-foreground)]",children:o("general"===t.namespaceId?"settings.section.settings":"settings.section.params")}),c.map(e=>(0,s.jsx)(aG,{namespaceId:t.namespaceId,field:e,scope:r,saving:a,onSave:t=>n(e,t),onReset:()=>l(e)},e.key))]}),d.length>0&&(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsx)("h3",{className:"text-[11px] font-semibold uppercase tracking-wider text-[var(--muted-foreground)]",children:o("settings.section.secrets")}),(0,s.jsxs)("p",{className:"text-[10px] text-[var(--muted-foreground)]",children:[m,(0,s.jsx)("code",{className:"rounded bg-[var(--card)] px-1 py-0.5",children:"<<ENV_NAME>>"}),p]}),d.map(e=>(0,s.jsx)(aG,{namespaceId:t.namespaceId,field:e,scope:r,saving:a,onSave:t=>n(e,t),onReset:()=>l(e)},e.key))]})]})}function aG(e){var t,r;let{namespaceId:a,field:n,scope:l,saving:o,onSave:i,onReset:c}=e,{lang:d,t:u}=(0,tr.useI18n)(),x="zh"===d&&n.description_zh||n.description||"",m="general"===a?"general.".concat(n.key):"".concat(a,".").concat(n.kind,"s.").concat(n.key),p="workspace"===l&&n.inheritedFromGlobal,h="workspace"===l&&!0===n.globalOnly,f=!h&&n.source===l&&("workspace"===l||(null!=(t=n.value)?t:"")!==(null!=(r=n.default)?r:""));return(0,s.jsxs)("div",{children:[(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,s.jsx)("label",{className:"text-xs font-medium text-[var(--foreground)]",children:n.key}),(0,s.jsx)("code",{className:"text-[10px] text-[var(--muted-foreground)]",children:m}),(0,s.jsx)(aJ,{source:n.source,inherited:p}),n.globalOnly&&(0,s.jsx)("span",{className:"rounded bg-[var(--secondary)] px-1.5 py-px text-[10px] uppercase text-[var(--muted-foreground)]",title:"zh"===d?"只在全局生效;workspace 级覆盖会被忽略":"Honored only at the global layer; workspace overrides are ignored",children:"global only"}),f&&(0,s.jsxs)("button",{onClick:c,disabled:o,className:"flex cursor-pointer items-center gap-1 text-[10px] text-blue-400 hover:text-blue-300",title:u("workspace"===l?"settings.field.resetTitleWorkspace":"settings.field.resetTitleGlobal"),children:[(0,s.jsx)(aO.A,{className:"h-2.5 w-2.5"}),u("settings.field.reset")]})]}),x&&(0,s.jsx)("p",{className:"mt-0.5 text-[10px] text-[var(--muted-foreground)]",children:x}),(0,s.jsx)("div",{className:D("mt-1.5",h&&"opacity-60 pointer-events-none"),children:function(e,t,r){var a,n,l,o,i,c,d,u;if(e.secret)return(0,s.jsx)(aQ,{initial:null!=(a=e.value)?a:"",placeholder:null!=(n=e.default)?n:"",saving:t,onCommit:r});switch(e.type){case"int":case"float":return(0,s.jsx)(aV,{initial:null!=(l=e.value)?l:"",placeholder:null!=(o=e.default)?o:"",step:"int"===e.type?1:.1,saving:t,onCommit:r});case"boolean":return(0,s.jsx)(aY,{value:e.value,saving:t,onCommit:r});case"enum":return(0,s.jsx)(a$,{value:e.value,options:null!=(i=e.options)?i:[],optionLabels:e.optionLabels,placeholder:null!=(c=e.default)?c:"",saving:t,onCommit:r});default:return(0,s.jsx)(aZ,{initial:null!=(d=e.value)?d:"",placeholder:null!=(u=e.default)?u:"",saving:t,onCommit:r})}}(n,o||h,i)})]})}function aJ(e){let{source:t,inherited:r}=e,{t:a}=(0,tr.useI18n)();return(0,s.jsx)("span",{className:D("rounded px-1.5 py-0 text-[9px] font-medium",{workspace:"bg-blue-500/20 text-blue-300",global:r?"bg-[var(--secondary)] text-[var(--muted-foreground)]":"bg-emerald-500/20 text-emerald-300",unset:"bg-[var(--secondary)] text-[var(--muted-foreground)] opacity-60"}[t]),children:a("unset"===t?"settings.source.unset":r?"settings.source.inherited":"settings.source.".concat(t))})}let aq=/^<<[A-Z_][A-Z0-9_]*>>$/;function aZ(e){let{initial:t,placeholder:r,saving:a,onCommit:n}=e,o=""===t&&!!r,[i,c]=(0,l.useState)(t),[d,u]=(0,l.useState)(!1),x=(0,l.useRef)(t);function m(){u(!1),i!==x.current&&(x.current=i,n(i))}(0,l.useEffect)(()=>{c(t),x.current=t,u(!1)},[t]);let p=o&&!d?null!=r?r:"":i;return(0,s.jsx)("input",{type:"text",value:p,placeholder:r,onFocus:()=>{o&&c(""),u(!0)},onChange:e=>{c(e.target.value),u(!0)},onBlur:m,onKeyDown:e=>{"Enter"===e.key&&m()},disabled:a,className:D("h-7 w-full max-w-md rounded border border-[var(--border)] bg-[var(--card)] px-2 text-xs outline-none focus:border-[var(--primary)]",o&&!d?"text-[var(--muted-foreground)] italic":"text-[var(--foreground)]")})}function aV(e){let{initial:t,placeholder:r,step:a,saving:n,onCommit:o}=e,i=""===t&&!!r,[c,d]=(0,l.useState)(t),[u,x]=(0,l.useState)(!1),m=(0,l.useRef)(t);function p(){x(!1),c!==m.current&&(m.current=c,o(c))}(0,l.useEffect)(()=>{d(t),m.current=t,x(!1)},[t]);let h=i&&!u?null!=r?r:"":c;return(0,s.jsx)("input",{type:"number",step:a,value:h,placeholder:r,onFocus:()=>{i&&d(""),x(!0)},onChange:e=>{d(e.target.value),x(!0)},onBlur:p,onKeyDown:e=>{"Enter"===e.key&&p()},disabled:n,className:D("h-7 w-full max-w-md rounded border border-[var(--border)] bg-[var(--card)] px-2 text-xs outline-none focus:border-[var(--primary)]",i&&!u?"text-[var(--muted-foreground)] italic":"text-[var(--foreground)]")})}function aY(e){let{value:t,saving:r,onCommit:a}=e,n="true"===t||"1"===t;return(0,s.jsxs)("label",{className:"inline-flex cursor-pointer items-center gap-2",children:[(0,s.jsx)("input",{type:"checkbox",checked:n,disabled:r,onChange:e=>a(e.target.checked?"true":"false"),className:"h-3.5 w-3.5 cursor-pointer rounded border-[var(--border)] bg-[var(--card)] text-[var(--primary)] focus:ring-[var(--primary)]"}),(0,s.jsx)("span",{className:"text-xs text-[var(--muted-foreground)]",children:n?"on":"off"})]})}function a$(e){var t,r;let{value:a,options:n,optionLabels:l,placeholder:o,saving:i,onCommit:c}=e,d=null!=(r=null!=(t=null!=a?a:o)?t:n[0])?r:"";return(0,s.jsx)("select",{value:d,disabled:i,onChange:e=>c(e.target.value),className:"h-7 w-full max-w-md cursor-pointer rounded border border-[var(--border)] bg-[var(--card)] px-2 text-xs text-[var(--foreground)] outline-none focus:border-[var(--primary)]",children:n.map((e,t)=>{var r;return(0,s.jsx)("option",{value:e,children:null!=(r=null==l?void 0:l[t])?r:e},e)})})}function aQ(e){let{initial:t,placeholder:r,saving:a,onCommit:n}=e,o=aq.test(t),[i,c]=(0,l.useState)(t),[d,u]=(0,l.useState)(!1),[x,m]=(0,l.useState)(o),p=(0,l.useRef)(t);function h(){if(d){if(i===p.current)return void u(!1);p.current=i,n(i),u(!1)}}return(0,l.useEffect)(()=>{c(t),p.current=t,u(!1),m(aq.test(t))},[t]),(0,s.jsxs)("div",{className:"relative w-full max-w-md",children:[(0,s.jsx)("input",{type:x||d?"text":"password",value:d?i:t||"",placeholder:r,onFocus:()=>{d||!t||aq.test(t)||c(""),u(!0)},onChange:e=>c(e.target.value),onBlur:h,onKeyDown:e=>{"Enter"===e.key&&h()},disabled:a,className:"h-7 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 pr-7 text-xs text-[var(--foreground)] outline-none focus:border-[var(--primary)]"}),!o&&(0,s.jsx)("button",{type:"button",onClick:()=>m(e=>!e),className:"absolute right-1.5 top-1/2 -translate-y-1/2 text-[var(--muted-foreground)] hover:text-[var(--foreground)]",tabIndex:-1,children:x?(0,s.jsx)(aW.A,{className:"h-3.5 w-3.5"}):(0,s.jsx)(eG.A,{className:"h-3.5 w-3.5"})})]})}function aX(e){let{orphans:t,onRemove:r,saving:a}=e,{t:n}=(0,tr.useI18n)(),o=(0,l.useMemo)(()=>{let e=new Map;for(let a of t){var r;let t=null!=(r=e.get(a.namespaceId))?r:[];t.push(a),e.set(a.namespaceId,t)}return Array.from(e.entries())},[t]);return 0===t.length?null:(0,s.jsxs)("div",{className:"space-y-6 p-6",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("h2",{className:"text-sm font-semibold text-[var(--foreground)]",children:n("settings.orphans.title")}),(0,s.jsx)("p",{className:"mt-0.5 text-[10px] text-[var(--muted-foreground)]",children:n("settings.orphans.intro")})]}),o.map(e=>{let[t,l]=e;return(0,s.jsxs)("div",{className:"space-y-2 rounded border border-[var(--border)] p-3",children:[(0,s.jsx)("h3",{className:"text-[11px] font-semibold text-[var(--foreground)]",children:t}),(0,s.jsx)("ul",{className:"space-y-1",children:l.map(e=>(0,s.jsxs)("li",{className:"flex items-center justify-between text-[11px]",children:[(0,s.jsxs)("code",{className:"text-[var(--muted-foreground)]",children:[t,".",e.kind,"s.",e.key]}),(0,s.jsxs)("button",{onClick:()=>r(e),disabled:a,className:"flex cursor-pointer items-center gap-1 rounded px-2 py-0.5 text-[10px] text-red-400 hover:bg-red-500/10 hover:text-red-300",children:[(0,s.jsx)(ej.A,{className:"h-3 w-3"}),n("settings.orphans.remove")]})]},"".concat(e.kind,".").concat(e.key)))})]},t)})]})}var a0=r(76966);let a1=(0,c.v)(e=>({version:0,bump:()=>e(e=>({version:e.version+1}))}));var a5=r(32400),a3=r(10561),a2=r(2573),a4=r(25843),a8=r(70764);function a6(e){let t=(0,tr.useT)(),{account:r,editing:a,onEdit:n,onCancelEdit:o,onSaved:i,onDeleted:c,onToggled:d,onRescan:u}=e,[x,m]=(0,l.useState)(r.label),[p,h]=(0,l.useState)(r.workspacePath),[f,g]=(0,l.useState)(r.accessLevel),[b,j]=(0,l.useState)(r.language),[y,w]=(0,l.useState)(!1);async function N(){w(!0);try{await v.F.weixin.updateAccount(r.accountId,{label:x,workspacePath:p,accessLevel:f,language:b}),i()}catch(e){alert(t("wx.saveFailed",{error:e instanceof Error?e.message:String(e)}))}finally{w(!1)}}async function k(){w(!0);try{await v.F.weixin.updateAccount(r.accountId,{enabled:!r.enabled}),d()}catch(e){alert(t("wx.switchFailed",{error:e instanceof Error?e.message:String(e)}))}finally{w(!1)}}async function S(){if(await R(t("wx.confirmDelete",{name:r.label}))){w(!0);try{await v.F.weixin.deleteAccount(r.accountId),c()}catch(e){alert(t("wx.deleteFailed",{error:e instanceof Error?e.message:String(e)}))}finally{w(!1)}}}return((0,l.useEffect)(()=>{a&&(m(r.label),h(r.workspacePath),g(r.accessLevel),j(r.language))},[a,r]),a)?(0,s.jsx)("li",{className:"px-4 py-3",children:(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-[10px] text-[var(--muted-foreground)]",children:t("wx.label")}),(0,s.jsx)("input",{value:x,onChange:e=>m(e.target.value),className:"mt-0.5 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1 text-xs",placeholder:t("wx.labelPlaceholder")})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-[10px] text-[var(--muted-foreground)]",children:t("wx.workspace")}),(0,s.jsx)("input",{value:p,onChange:e=>h(e.target.value),className:"mt-0.5 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1 font-mono text-xs",placeholder:"/home/user/project"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-[10px] text-[var(--muted-foreground)]",children:t("wx.accessLevel")}),(0,s.jsxs)("select",{value:f,onChange:e=>g(e.target.value),className:"mt-0.5 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1 text-xs",children:[(0,s.jsx)("option",{value:"readonly",children:t("wx.readonly")}),(0,s.jsx)("option",{value:"workspace",children:t("wx.wsWrite")}),(0,s.jsx)("option",{value:"full",children:t("wx.full")})]}),(0,s.jsx)("p",{className:"mt-1 text-[10px] text-[var(--muted-foreground)]",children:t("wx.readonlyHint")})]}),(0,s.jsx)(ta.LanguageSelect,{value:b,onChange:j}),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsxs)("button",{onClick:N,disabled:y||!P(p),className:"flex items-center gap-1 rounded bg-[var(--primary)] px-2 py-1 text-[11px] text-white disabled:opacity-50",children:[(0,s.jsx)(tD.A,{className:"h-3 w-3"})," ",t("wx.save")]}),(0,s.jsxs)("button",{onClick:o,disabled:y,className:"flex items-center gap-1 rounded border border-[var(--border)] px-2 py-1 text-[11px]",children:[(0,s.jsx)(eK.A,{className:"h-3 w-3"})," ",t("wx.cancel")]})]})]})}):(0,s.jsxs)("li",{className:"flex items-center gap-3 px-4 py-3",children:[(0,s.jsx)("div",{className:D("h-2 w-2 rounded-full",r.enabled?"bg-emerald-500":"bg-[var(--muted-foreground)]")}),(0,s.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:"text-xs font-medium text-[var(--foreground)]",children:r.label||r.accountId}),(0,s.jsx)("span",{className:D("rounded px-1.5 py-0.5 text-[9px] font-medium","readonly"===r.accessLevel?"bg-emerald-500/15 text-emerald-300":"workspace"===r.accessLevel?"bg-blue-500/15 text-blue-300":"bg-amber-500/15 text-amber-300"),children:"readonly"===r.accessLevel?"Readonly":"workspace"===r.accessLevel?"Workspace":"Full"}),(0,s.jsx)("span",{className:"font-mono text-[10px] text-[var(--muted-foreground)]",children:r.accountId})]}),(0,s.jsx)("p",{className:"mt-0.5 truncate font-mono text-[10px] text-[var(--muted-foreground)]",children:r.workspacePath})]}),(0,s.jsxs)("div",{className:"flex items-center gap-1",children:[(0,s.jsx)("button",{onClick:k,disabled:y,title:r.enabled?t("wx.disable"):t("wx.enable"),className:"rounded p-1.5 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:r.enabled?(0,s.jsx)(a3.A,{className:"h-3.5 w-3.5"}):(0,s.jsx)(a2.A,{className:"h-3.5 w-3.5"})}),(0,s.jsx)("button",{onClick:u,disabled:y,title:t("wx.rescan"),className:"rounded p-1.5 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,s.jsx)(a4.A,{className:"h-3.5 w-3.5"})}),(0,s.jsx)("button",{onClick:n,disabled:y,title:t("wx.edit"),className:"rounded p-1.5 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,s.jsx)(a8.A,{className:"h-3.5 w-3.5"})}),(0,s.jsx)("button",{onClick:S,disabled:y,title:t("wx.delete"),className:"rounded p-1.5 text-[var(--muted-foreground)] hover:bg-red-500/20 hover:text-red-400",children:(0,s.jsx)(ej.A,{className:"h-3.5 w-3.5"})})]})]})}function a9(e){let t=(0,tr.useT)(),{intent:r,onClose:a,onDone:n}=e,o=e9(e=>e.activeProject),[i,c]=(0,l.useState)(null),[d,u]=(0,l.useState)(null),[x,m]=(0,l.useState)("loading"),[p,h]=(0,l.useState)(t("wx.generatingQr")),[f,g]=(0,l.useState)(r.workspacePath||(null==o?void 0:o.path)||""),[b,j]=(0,l.useState)(r.label||""),[y,w]=(0,l.useState)(r.accessLevel),[N,k]=(0,l.useState)(r.language),[S,C]=(0,l.useState)(r.skipConfig?"scan":"config"),A=(0,l.useRef)(!1),I=r.skipConfig;async function E(){if(!P(f))return void h(t("wx.pathRequired"));C("scan"),m("loading"),h(t("wx.generatingQr"));try{let{qrcodeUrl:r,sessionKey:a}=await v.F.weixin.startLogin();if(A.current)return;if(!r){m("error"),h(t("wx.qrFailed"));return}c(a);let s=await a5.toDataURL(r,{width:256,margin:2});if(A.current)return;u(s),m("waiting"),h(t("wx.scanPrompt"));let l=await v.F.weixin.waitLogin({sessionKey:a,workspacePath:f,label:b||void 0,accessLevel:y,language:N});if(A.current)return;if(l.connected){var e;m("success"),h(t("wx.connected",{id:null!=(e=l.accountId)?e:""})),setTimeout(n,1200)}else m("error"),h(l.message||t("wx.loginFailed"))}catch(e){if(A.current)return;m("error"),h(e instanceof Error?e.message:String(e))}}return(0,l.useEffect)(()=>()=>{A.current=!0},[]),(0,l.useEffect)(()=>{r.skipConfig&&E()},[]),(0,s.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",onClick:a,children:(0,s.jsxs)("div",{className:"w-[400px] rounded-lg border border-[var(--border)] bg-[var(--background)] p-5 shadow-xl",onClick:e=>e.stopPropagation(),children:[(0,s.jsxs)("div",{className:"mb-4 flex items-center justify-between",children:[(0,s.jsx)("h3",{className:"text-sm font-medium text-[var(--foreground)]",children:I?t("wx.rescanBtn"):t("wx.addTitle")}),(0,s.jsx)("button",{onClick:a,className:"text-[var(--muted-foreground)] hover:text-[var(--foreground)]",children:(0,s.jsx)(eK.A,{className:"h-4 w-4"})})]}),"config"===S?(0,s.jsxs)("div",{className:"space-y-3",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-[11px] text-[var(--muted-foreground)]",children:t("wx.bindWorkspace")}),(0,s.jsx)("input",{value:f,onChange:e=>g(e.target.value),className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1.5 font-mono text-xs",placeholder:"/home/user/project"}),(0,s.jsx)("p",{className:"mt-1 text-[10px] text-[var(--muted-foreground)]",children:t("wx.bindHint")})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-[11px] text-[var(--muted-foreground)]",children:t("wx.nameOptional")}),(0,s.jsx)("input",{value:b,onChange:e=>j(e.target.value),className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1.5 text-xs",placeholder:t("wx.namePlaceholder")})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-[11px] text-[var(--muted-foreground)]",children:t("wx.accessLevel")}),(0,s.jsxs)("select",{value:y,onChange:e=>w(e.target.value),className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1.5 text-xs",children:[(0,s.jsx)("option",{value:"readonly",children:t("wx.readonly")}),(0,s.jsx)("option",{value:"workspace",children:t("wx.wsWrite")}),(0,s.jsx)("option",{value:"full",children:t("wx.full")})]}),(0,s.jsx)("p",{className:"mt-1 text-[10px] text-[var(--muted-foreground)]",children:t("wx.readonlyShareHint")})]}),(0,s.jsx)(ta.LanguageSelect,{value:N,onChange:k}),(0,s.jsxs)("div",{className:"flex justify-end gap-2 pt-2",children:[(0,s.jsx)("button",{onClick:a,className:"rounded border border-[var(--border)] px-3 py-1.5 text-xs",children:t("wx.cancel")}),(0,s.jsx)("button",{onClick:E,disabled:!P(f),className:"rounded bg-[var(--primary)] px-3 py-1.5 text-xs text-white disabled:opacity-50",children:t("wx.nextStep")})]})]}):(0,s.jsxs)("div",{className:"flex flex-col items-center gap-3",children:[d?(0,s.jsx)("img",{src:d,alt:t("wx.scanTitle"),className:"rounded border border-[var(--border)]"}):(0,s.jsx)("div",{className:"flex h-64 w-64 items-center justify-center rounded border border-[var(--border)] bg-[var(--card)]",children:(0,s.jsx)(H.A,{className:"h-6 w-6 animate-spin text-[var(--muted-foreground)]"})}),(0,s.jsx)("p",{className:D("text-center text-xs","success"===x&&"text-emerald-400","error"===x&&"text-red-400","success"!==x&&"error"!==x&&"text-[var(--muted-foreground)]"),children:p}),(0,s.jsxs)("p",{className:"text-[10px] text-[var(--muted-foreground)]",children:[t("wx.bindTo")," ",(0,s.jsx)("code",{className:"text-[var(--foreground)]",children:f})]}),"error"===x&&(0,s.jsx)("button",{onClick:()=>{C("config")},className:"rounded border border-[var(--border)] px-3 py-1.5 text-xs",children:t("wx.restart")})]}),i&&(0,s.jsx)("input",{type:"hidden",value:i,readOnly:!0})]})})}let a7={id:"weixin",label:"channels.weixin",Icon:a0.A,Component:function(){let e=(0,tr.useT)(),{lang:t}=(0,tr.useI18n)(),[r,a]=(0,l.useState)([]),[n,o]=(0,l.useState)(!0),[i,c]=(0,l.useState)(null),[d,u]=(0,l.useState)(null),x=(0,l.useCallback)(()=>{o(!0),v.F.weixin.listAccounts().then(e=>a(e.accounts)).catch(e=>{console.error("[weixin] list failed:",e)}).finally(()=>o(!1))},[]);(0,l.useEffect)(()=>{x()},[x]);let m=a1(e=>e.version);return(0,l.useEffect)(()=>{m>0&&x()},[m,x]),(0,s.jsxs)("div",{className:"flex h-full flex-col",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between border-b border-[var(--border)] px-4 py-3",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("h2",{className:"text-sm font-medium text-[var(--foreground)]",children:e("wx.title")}),(0,s.jsx)("p",{className:"text-[11px] text-[var(--muted-foreground)]",children:e("wx.desc")})]}),(0,s.jsxs)("button",{onClick:()=>c({workspacePath:"",label:"",accessLevel:"readonly",language:t,skipConfig:!1}),className:"flex items-center gap-1.5 rounded-md bg-[var(--primary)] px-3 py-1.5 text-xs font-medium text-white hover:opacity-90",children:[(0,s.jsx)(rA.A,{className:"h-3.5 w-3.5"}),e("wx.add")]})]}),(0,s.jsx)("div",{className:"min-h-0 flex-1 overflow-y-auto",children:n?(0,s.jsxs)("div",{className:"flex items-center justify-center py-8 text-xs text-[var(--muted-foreground)]",children:[(0,s.jsx)(H.A,{className:"mr-2 h-3.5 w-3.5 animate-spin"}),e("wx.loading")]}):0===r.length?(0,s.jsx)("div",{className:"p-8 text-center text-xs text-[var(--muted-foreground)]",children:e("wx.empty")}):(0,s.jsx)("ul",{className:"divide-y divide-[var(--border)]",children:r.map(e=>(0,s.jsx)(a6,{account:e,editing:d===e.accountId,onEdit:()=>u(e.accountId),onCancelEdit:()=>u(null),onSaved:()=>{u(null),x()},onDeleted:x,onToggled:x,onRescan:()=>c({workspacePath:e.workspacePath,label:e.label,accessLevel:e.accessLevel,language:e.language,skipConfig:!0})},e.accountId))})}),i&&(0,s.jsx)(a9,{intent:i,onClose:()=>c(null),onDone:()=>{c(null),x()}})]})}};function ne(e){let t=(0,tr.useT)(),{account:r,editing:a,onEdit:n,onCancelEdit:o,onSaved:i,onDeleted:c,onToggled:d}=e,[u,x]=(0,l.useState)(r.label),[m,p]=(0,l.useState)(r.workspacePath),[h,f]=(0,l.useState)(r.accessLevel),[g,b]=(0,l.useState)(r.allowedUsers),[j,y]=(0,l.useState)(r.language||"en"),[w,N]=(0,l.useState)(!1);async function k(){N(!0);try{await v.F.telegram.updateAccount(r.accountId,{label:u,workspacePath:m,accessLevel:h,allowedUsers:g,language:j}),i()}catch(e){alert(t("tg.saveFailed",{error:e instanceof Error?e.message:String(e)}))}finally{N(!1)}}async function S(){N(!0);try{await v.F.telegram.updateAccount(r.accountId,{enabled:!r.enabled}),d()}catch(e){alert(t("tg.switchFailed",{error:e instanceof Error?e.message:String(e)}))}finally{N(!1)}}async function C(){if(await R(t("tg.confirmDelete",{name:r.botUsername}))){N(!0);try{await v.F.telegram.deleteAccount(r.accountId),c()}catch(e){alert(t("tg.deleteFailed",{error:e instanceof Error?e.message:String(e)}))}finally{N(!1)}}}return((0,l.useEffect)(()=>{a&&(x(r.label),p(r.workspacePath),f(r.accessLevel),b(r.allowedUsers),y(r.language||"en"))},[a,r]),a)?(0,s.jsx)("li",{className:"px-4 py-3",children:(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-[10px] text-[var(--muted-foreground)]",children:t("tg.label")}),(0,s.jsx)("input",{value:u,onChange:e=>x(e.target.value),className:"mt-0.5 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1 text-xs",placeholder:t("tg.labelPlaceholder")})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-[10px] text-[var(--muted-foreground)]",children:t("tg.workspace")}),(0,s.jsx)("input",{value:m,onChange:e=>p(e.target.value),className:"mt-0.5 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1 font-mono text-xs",placeholder:"/home/user/project"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-[10px] text-[var(--muted-foreground)]",children:t("tg.accessLevel")}),(0,s.jsxs)("select",{value:h,onChange:e=>f(e.target.value),className:"mt-0.5 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1 text-xs",children:[(0,s.jsx)("option",{value:"readonly",children:t("tg.readonly")}),(0,s.jsx)("option",{value:"workspace",children:t("tg.wsWrite")}),(0,s.jsx)("option",{value:"full",children:t("tg.full")})]})]}),(0,s.jsx)(ta.LanguageSelect,{value:j,onChange:y}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-[10px] text-[var(--muted-foreground)]",children:t("tg.allowedUsers")}),(0,s.jsx)("input",{value:g,onChange:e=>b(e.target.value),className:"mt-0.5 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1 font-mono text-xs",placeholder:"123456789,@username"})]}),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsxs)("button",{onClick:k,disabled:w||!P(m),className:"flex items-center gap-1 rounded bg-[var(--primary)] px-2 py-1 text-[11px] text-white disabled:opacity-50",children:[(0,s.jsx)(tD.A,{className:"h-3 w-3"})," ",t("tg.save")]}),(0,s.jsxs)("button",{onClick:o,disabled:w,className:"flex items-center gap-1 rounded border border-[var(--border)] px-2 py-1 text-[11px]",children:[(0,s.jsx)(eK.A,{className:"h-3 w-3"})," ",t("tg.cancel")]})]})]})}):(0,s.jsxs)("li",{className:"flex items-center gap-3 px-4 py-3",children:[(0,s.jsx)("div",{className:D("h-2 w-2 rounded-full",r.enabled?"bg-emerald-500":"bg-[var(--muted-foreground)]")}),(0,s.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:"text-xs font-medium text-[var(--foreground)]",children:r.label||"@".concat(r.botUsername)}),(0,s.jsx)("span",{className:D("rounded px-1.5 py-0.5 text-[9px] font-medium","readonly"===r.accessLevel?"bg-emerald-500/15 text-emerald-300":"workspace"===r.accessLevel?"bg-blue-500/15 text-blue-300":"bg-amber-500/15 text-amber-300"),children:"readonly"===r.accessLevel?"Readonly":"workspace"===r.accessLevel?"Workspace":"Full"}),r.allowedUsers&&(0,s.jsx)("span",{className:"rounded bg-blue-500/15 px-1.5 py-0.5 text-[9px] font-medium text-blue-300",children:t("tg.whitelist")})]}),(0,s.jsxs)("p",{className:"mt-0.5 truncate font-mono text-[10px] text-[var(--muted-foreground)]",children:["@",r.botUsername," → ",r.workspacePath,r.workspaceMissing&&(0,s.jsx)("span",{className:"ml-1 text-red-400",children:t("tg.pathMissing")})]})]}),(0,s.jsxs)("div",{className:"flex items-center gap-1",children:[(0,s.jsx)("button",{onClick:S,disabled:w,title:r.enabled?t("tg.disable"):t("tg.enable"),className:"rounded p-1.5 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:r.enabled?(0,s.jsx)(a3.A,{className:"h-3.5 w-3.5"}):(0,s.jsx)(a2.A,{className:"h-3.5 w-3.5"})}),(0,s.jsx)("button",{onClick:n,disabled:w,title:t("tg.edit"),className:"rounded p-1.5 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,s.jsx)(a8.A,{className:"h-3.5 w-3.5"})}),(0,s.jsx)("button",{onClick:C,disabled:w,title:t("tg.delete"),className:"rounded p-1.5 text-[var(--muted-foreground)] hover:bg-red-500/20 hover:text-red-400",children:(0,s.jsx)(ej.A,{className:"h-3.5 w-3.5"})})]})]})}function nt(e){let t=(0,tr.useT)(),{lang:r}=(0,tr.useI18n)(),{onClose:a,onDone:n}=e,o=e9(e=>e.activeProject),[i,c]=(0,l.useState)(""),[d,u]=(0,l.useState)((null==o?void 0:o.path)||""),[x,m]=(0,l.useState)(""),[p,h]=(0,l.useState)("readonly"),[f,g]=(0,l.useState)(""),[b,j]=(0,l.useState)(r),[y,w]=(0,l.useState)(!1),[N,k]=(0,l.useState)("");async function S(){k(""),w(!0);try{await v.F.telegram.createAccount({botToken:i,workspacePath:d,label:x||void 0,accessLevel:p,allowedUsers:f||void 0,language:b}),n()}catch(e){k(e instanceof Error?e.message:String(e))}finally{w(!1)}}return(0,s.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",onClick:a,children:(0,s.jsxs)("div",{className:"w-[420px] rounded-lg border border-[var(--border)] bg-[var(--background)] p-5 shadow-xl",onClick:e=>e.stopPropagation(),children:[(0,s.jsxs)("div",{className:"mb-4 flex items-center justify-between",children:[(0,s.jsx)("h3",{className:"text-sm font-medium text-[var(--foreground)]",children:t("tg.addTitle")}),(0,s.jsx)("button",{onClick:a,className:"text-[var(--muted-foreground)] hover:text-[var(--foreground)]",children:(0,s.jsx)(eK.A,{className:"h-4 w-4"})})]}),(0,s.jsxs)("div",{className:"space-y-3",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-[11px] text-[var(--muted-foreground)]",children:t("tg.tokenLabel")}),(0,s.jsx)("input",{value:i,onChange:e=>c(e.target.value),className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1.5 font-mono text-xs",placeholder:"123456:ABC-DEF..."})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-[11px] text-[var(--muted-foreground)]",children:t("tg.bindWorkspace")}),(0,s.jsx)("input",{value:d,onChange:e=>u(e.target.value),className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1.5 font-mono text-xs",placeholder:"/home/user/project"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-[11px] text-[var(--muted-foreground)]",children:t("tg.nameOptional")}),(0,s.jsx)("input",{value:x,onChange:e=>m(e.target.value),className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1.5 text-xs",placeholder:t("tg.namePlaceholder")})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-[11px] text-[var(--muted-foreground)]",children:t("tg.accessLevel")}),(0,s.jsxs)("select",{value:p,onChange:e=>h(e.target.value),className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1.5 text-xs",children:[(0,s.jsx)("option",{value:"readonly",children:t("tg.readonly")}),(0,s.jsx)("option",{value:"workspace",children:t("tg.wsWrite")}),(0,s.jsx)("option",{value:"full",children:t("tg.full")})]})]}),(0,s.jsx)(ta.LanguageSelect,{value:b,onChange:j}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-[11px] text-[var(--muted-foreground)]",children:t("tg.allowedUsersOptional")}),(0,s.jsx)("input",{value:f,onChange:e=>g(e.target.value),className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1.5 font-mono text-xs",placeholder:t("tg.allowedUsersHint")})]}),N&&(0,s.jsx)("p",{className:"text-xs text-red-400",children:N}),(0,s.jsxs)("div",{className:"flex justify-end gap-2 pt-2",children:[(0,s.jsx)("button",{onClick:a,className:"rounded border border-[var(--border)] px-3 py-1.5 text-xs",children:t("tg.cancel")}),(0,s.jsxs)("button",{onClick:S,disabled:y||!i.trim()||!P(d),className:"flex items-center gap-1.5 rounded bg-[var(--primary)] px-3 py-1.5 text-xs text-white disabled:opacity-50",children:[y&&(0,s.jsx)(H.A,{className:"h-3 w-3 animate-spin"}),t("tg.addBtn")]})]})]})]})})}let nr={id:"telegram",label:"Telegram",Icon:t4.A,Component:function(){let e=(0,tr.useT)(),[t,r]=(0,l.useState)([]),[a,n]=(0,l.useState)(!0),[o,i]=(0,l.useState)(!1),[c,d]=(0,l.useState)(null),u=(0,l.useCallback)(()=>{n(!0),v.F.telegram.listAccounts().then(e=>r(e.accounts)).catch(e=>{console.error("[telegram] list failed:",e)}).finally(()=>n(!1))},[]);(0,l.useEffect)(()=>{u()},[u]);let x=a1(e=>e.version);return(0,l.useEffect)(()=>{x>0&&u()},[x,u]),(0,s.jsxs)("div",{className:"flex h-full flex-col",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between border-b border-[var(--border)] px-4 py-3",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("h2",{className:"text-sm font-medium text-[var(--foreground)]",children:e("tg.title")}),(0,s.jsx)("p",{className:"text-[11px] text-[var(--muted-foreground)]",children:e("tg.desc")})]}),(0,s.jsxs)("button",{onClick:()=>i(!0),className:"flex items-center gap-1.5 rounded-md bg-[var(--primary)] px-3 py-1.5 text-xs font-medium text-white hover:opacity-90",children:[(0,s.jsx)(rA.A,{className:"h-3.5 w-3.5"}),e("tg.add")]})]}),(0,s.jsx)("div",{className:"min-h-0 flex-1 overflow-y-auto",children:a?(0,s.jsxs)("div",{className:"flex items-center justify-center py-8 text-xs text-[var(--muted-foreground)]",children:[(0,s.jsx)(H.A,{className:"mr-2 h-3.5 w-3.5 animate-spin"}),e("tg.loading")]}):0===t.length?(0,s.jsx)("div",{className:"p-8 text-center text-xs text-[var(--muted-foreground)]",children:e("tg.empty")}):(0,s.jsx)("ul",{className:"divide-y divide-[var(--border)]",children:t.map(e=>(0,s.jsx)(ne,{account:e,editing:c===e.accountId,onEdit:()=>d(e.accountId),onCancelEdit:()=>d(null),onSaved:()=>{d(null),u()},onDeleted:u,onToggled:u},e.accountId))})}),o&&(0,s.jsx)(nt,{onClose:()=>i(!1),onDone:()=>{i(!1),u()}})]})}};function na(e){let{account:t,editing:r,onEdit:a,onCancelEdit:n,onSaved:o,onDeleted:i,onToggled:c}=e,d=(0,tr.useT)(),[u,x]=(0,l.useState)(t.label),[m,p]=(0,l.useState)(t.workspacePath),[h,f]=(0,l.useState)(t.accessLevel),[g,b]=(0,l.useState)(t.language||"en"),[j,y]=(0,l.useState)(!1),[w,N]=(0,l.useState)(!1);async function k(){y(!0);try{await v.F.web.updateAccount(t.accountId,{label:u,workspacePath:m,accessLevel:h,language:g}),o()}catch(e){alert(d("web.saveFailed",{error:e instanceof Error?e.message:String(e)}))}finally{y(!1)}}async function S(){y(!0);try{await v.F.web.updateAccount(t.accountId,{enabled:!t.enabled}),c()}catch(e){alert(d("web.switchFailed",{error:e instanceof Error?e.message:String(e)}))}finally{y(!1)}}async function C(){if(await R(d("web.confirmDelete"))){y(!0);try{await v.F.web.deleteAccount(t.accountId),i()}catch(e){alert(d("web.deleteFailed",{error:e instanceof Error?e.message:String(e)}))}finally{y(!1)}}}return((0,l.useEffect)(()=>{r&&(x(t.label),p(t.workspacePath),f(t.accessLevel),b(t.language||"en"))},[r,t]),r)?(0,s.jsx)("li",{className:"px-4 py-3",children:(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-[10px] text-[var(--muted-foreground)]",children:d("web.label")}),(0,s.jsx)("input",{value:u,onChange:e=>x(e.target.value),className:"mt-0.5 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1 text-xs",placeholder:d("web.labelPlaceholder")})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-[10px] text-[var(--muted-foreground)]",children:d("web.workspace")}),(0,s.jsx)("input",{value:m,onChange:e=>p(e.target.value),className:"mt-0.5 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1 font-mono text-xs",placeholder:"/home/user/project"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-[10px] text-[var(--muted-foreground)]",children:d("web.accessLevel")}),(0,s.jsxs)("select",{value:h,onChange:e=>f(e.target.value),className:"mt-0.5 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1 text-xs",children:[(0,s.jsx)("option",{value:"readonly",children:d("web.readonly")}),(0,s.jsx)("option",{value:"observer",children:d("web.observer")}),(0,s.jsx)("option",{value:"workspace",children:d("web.wsWrite")}),(0,s.jsx)("option",{value:"full",children:d("web.full")})]})]}),(0,s.jsx)(ta.LanguageSelect,{value:g,onChange:b}),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsxs)("button",{onClick:k,disabled:j||!P(m),className:"flex items-center gap-1 rounded bg-[var(--primary)] px-2 py-1 text-[11px] text-white disabled:opacity-50",children:[(0,s.jsx)(tD.A,{className:"h-3 w-3"})," ",d("web.save")]}),(0,s.jsxs)("button",{onClick:n,disabled:j,className:"flex items-center gap-1 rounded border border-[var(--border)] px-2 py-1 text-[11px]",children:[(0,s.jsx)(eK.A,{className:"h-3 w-3"})," ",d("web.cancel")]})]})]})}):(0,s.jsxs)("li",{className:"flex items-center gap-3 px-4 py-3",children:[(0,s.jsx)("div",{className:D("h-2 w-2 rounded-full",t.enabled?"bg-emerald-500":"bg-[var(--muted-foreground)]")}),(0,s.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:"text-xs font-medium text-[var(--foreground)]",children:t.label||t.accountId}),(0,s.jsx)("span",{className:D("rounded px-1.5 py-0.5 text-[9px] font-medium","readonly"===t.accessLevel?"bg-emerald-500/15 text-emerald-300":"observer"===t.accessLevel?"bg-teal-500/15 text-teal-300":"workspace"===t.accessLevel?"bg-blue-500/15 text-blue-300":"bg-amber-500/15 text-amber-300"),children:"readonly"===t.accessLevel?"Readonly":"observer"===t.accessLevel?"Observer":"workspace"===t.accessLevel?"Workspace":"Full"})]}),(0,s.jsx)("div",{className:"mt-0.5 flex items-center gap-2",children:(0,s.jsxs)("p",{className:"truncate font-mono text-[10px] text-[var(--muted-foreground)]",children:[t.workspacePath,t.workspaceMissing&&(0,s.jsx)("span",{className:"ml-1 text-red-400",children:d("web.pathMissing")})]})}),(0,s.jsxs)("div",{className:"mt-1 flex items-center gap-2",children:[(0,s.jsxs)("code",{className:"rounded bg-[var(--secondary)] px-1.5 py-0.5 font-mono text-[9px] text-[var(--muted-foreground)]",children:[t.token.slice(0,12),"..."]}),(0,s.jsx)("button",{onClick:function(){navigator.clipboard.writeText(t.token),N(!0),setTimeout(()=>N(!1),2e3)},className:"text-[10px] text-[var(--primary)] hover:underline",children:w?d("web.copied"):d("web.copyToken")})]})]}),(0,s.jsxs)("div",{className:"flex items-center gap-1",children:[(0,s.jsx)("button",{onClick:S,disabled:j,title:t.enabled?d("web.disable"):d("web.enable"),className:"rounded p-1.5 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:t.enabled?(0,s.jsx)(a3.A,{className:"h-3.5 w-3.5"}):(0,s.jsx)(a2.A,{className:"h-3.5 w-3.5"})}),(0,s.jsx)("button",{onClick:a,disabled:j,title:d("web.edit"),className:"rounded p-1.5 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,s.jsx)(a8.A,{className:"h-3.5 w-3.5"})}),(0,s.jsx)("button",{onClick:C,disabled:j,title:d("web.delete"),className:"rounded p-1.5 text-[var(--muted-foreground)] hover:bg-red-500/20 hover:text-red-400",children:(0,s.jsx)(ej.A,{className:"h-3.5 w-3.5"})})]})]})}function nn(e){let{onClose:t,onDone:r}=e,a=(0,tr.useT)(),{lang:n}=(0,tr.useI18n)(),o=e9(e=>e.activeProject),[i,c]=(0,l.useState)((null==o?void 0:o.path)||""),[d,u]=(0,l.useState)(""),[x,m]=(0,l.useState)("readonly"),[p,h]=(0,l.useState)(n),[f,g]=(0,l.useState)(!1),[b,j]=(0,l.useState)(""),[y,w]=(0,l.useState)(null);async function N(){j(""),g(!0);try{let e=await v.F.web.createAccount({workspacePath:i,label:d||void 0,accessLevel:x,language:p});w({token:e.token})}catch(e){j(e instanceof Error?e.message:String(e))}finally{g(!1)}}return y?(0,s.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",onClick:r,children:(0,s.jsxs)("div",{className:"w-[420px] rounded-lg border border-[var(--border)] bg-[var(--background)] p-5 shadow-xl",onClick:e=>e.stopPropagation(),children:[(0,s.jsx)("h3",{className:"mb-3 text-sm font-medium text-[var(--foreground)]",children:a("web.createSuccess")}),(0,s.jsx)("p",{className:"mb-2 text-xs text-[var(--muted-foreground)]",children:a("web.tokenNotice")}),(0,s.jsxs)("div",{className:"flex items-center gap-2 rounded border border-[var(--border)] bg-[var(--card)] p-2",children:[(0,s.jsx)("code",{className:"flex-1 break-all font-mono text-xs text-[var(--foreground)]",children:y.token}),(0,s.jsx)("button",{onClick:()=>navigator.clipboard.writeText(y.token),className:"rounded p-1 text-[var(--muted-foreground)] hover:text-[var(--foreground)]",children:(0,s.jsx)(tM.A,{className:"h-3.5 w-3.5"})})]}),(0,s.jsx)("div",{className:"mt-4 flex justify-end",children:(0,s.jsx)("button",{onClick:r,className:"rounded bg-[var(--primary)] px-3 py-1.5 text-xs text-white",children:a("web.done")})})]})}):(0,s.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",onClick:t,children:(0,s.jsxs)("div",{className:"w-[420px] rounded-lg border border-[var(--border)] bg-[var(--background)] p-5 shadow-xl",onClick:e=>e.stopPropagation(),children:[(0,s.jsxs)("div",{className:"mb-4 flex items-center justify-between",children:[(0,s.jsx)("h3",{className:"text-sm font-medium text-[var(--foreground)]",children:a("web.createTitle")}),(0,s.jsx)("button",{onClick:t,className:"text-[var(--muted-foreground)] hover:text-[var(--foreground)]",children:(0,s.jsx)(eK.A,{className:"h-4 w-4"})})]}),(0,s.jsxs)("div",{className:"space-y-3",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-[11px] text-[var(--muted-foreground)]",children:a("web.bindWorkspace")}),(0,s.jsx)("input",{value:i,onChange:e=>c(e.target.value),className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1.5 font-mono text-xs",placeholder:"/home/user/project"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-[11px] text-[var(--muted-foreground)]",children:a("web.nameOptional")}),(0,s.jsx)("input",{value:d,onChange:e=>u(e.target.value),className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1.5 text-xs",placeholder:a("web.namePlaceholder")})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-[11px] text-[var(--muted-foreground)]",children:a("web.accessLevel")}),(0,s.jsxs)("select",{value:x,onChange:e=>m(e.target.value),className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1.5 text-xs",children:[(0,s.jsx)("option",{value:"readonly",children:a("web.readonly")}),(0,s.jsx)("option",{value:"observer",children:a("web.observer")}),(0,s.jsx)("option",{value:"workspace",children:a("web.wsWrite")}),(0,s.jsx)("option",{value:"full",children:a("web.full")})]})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-[11px] text-[var(--muted-foreground)]",children:a("common.language")}),(0,s.jsxs)("select",{value:p,onChange:e=>h(e.target.value),className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1.5 text-xs",children:[(0,s.jsx)("option",{value:"en",children:"English"}),(0,s.jsx)("option",{value:"zh",children:"中文"})]})]}),b&&(0,s.jsx)("p",{className:"text-xs text-red-400",children:b}),(0,s.jsxs)("div",{className:"flex justify-end gap-2 pt-2",children:[(0,s.jsx)("button",{onClick:t,className:"rounded border border-[var(--border)] px-3 py-1.5 text-xs",children:a("web.cancel")}),(0,s.jsxs)("button",{onClick:N,disabled:f||!P(i),className:"flex items-center gap-1.5 rounded bg-[var(--primary)] px-3 py-1.5 text-xs text-white disabled:opacity-50",children:[f&&(0,s.jsx)(H.A,{className:"h-3 w-3 animate-spin"}),a("web.createBtn")]})]})]})]})})}let ns={id:"web_demo",label:"Web",Icon:J.A,Component:function(){let e=(0,tr.useT)(),[t,r]=(0,l.useState)([]),[a,n]=(0,l.useState)(!0),[o,i]=(0,l.useState)(!1),[c,d]=(0,l.useState)(null),u=(0,l.useCallback)(()=>{n(!0),v.F.web.listAccounts().then(e=>r(e.accounts)).catch(e=>{console.error("[web] list failed:",e)}).finally(()=>n(!1))},[]);(0,l.useEffect)(()=>{u()},[u]);let x=a1(e=>e.version);return(0,l.useEffect)(()=>{x>0&&u()},[x,u]),(0,s.jsxs)("div",{className:"flex h-full flex-col",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between border-b border-[var(--border)] px-4 py-3",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("h2",{className:"text-sm font-medium text-[var(--foreground)]",children:e("web.title")}),(0,s.jsx)("p",{className:"text-[11px] text-[var(--muted-foreground)]",children:e("web.desc")})]}),(0,s.jsxs)("button",{onClick:()=>i(!0),className:"flex items-center gap-1.5 rounded-md bg-[var(--primary)] px-3 py-1.5 text-xs font-medium text-white hover:opacity-90",children:[(0,s.jsx)(rA.A,{className:"h-3.5 w-3.5"}),e("web.create")]})]}),(0,s.jsx)("div",{className:"min-h-0 flex-1 overflow-y-auto",children:a?(0,s.jsxs)("div",{className:"flex items-center justify-center py-8 text-xs text-[var(--muted-foreground)]",children:[(0,s.jsx)(H.A,{className:"mr-2 h-3.5 w-3.5 animate-spin"}),e("web.loading")]}):0===t.length?(0,s.jsx)("div",{className:"p-8 text-center text-xs text-[var(--muted-foreground)]",children:e("web.empty")}):(0,s.jsx)("ul",{className:"divide-y divide-[var(--border)]",children:t.map(e=>(0,s.jsx)(na,{account:e,editing:c===e.accountId,onEdit:()=>d(e.accountId),onCancelEdit:()=>d(null),onSaved:()=>{d(null),u()},onDeleted:u,onToggled:u},e.accountId))})}),o&&(0,s.jsx)(nn,{onClose:()=>i(!1),onDone:()=>{i(!1),u()}})]})}};function nl(e){let t=(0,tr.useT)(),{account:r,editing:a,onEdit:n,onCancelEdit:o,onSaved:i,onDeleted:c,onToggled:d}=e,[u,x]=(0,l.useState)(r.label),[m,p]=(0,l.useState)(r.workspacePath),[h,f]=(0,l.useState)(r.accessLevel),[g,b]=(0,l.useState)(r.language||"en"),[j,y]=(0,l.useState)(!1);async function w(){y(!0);try{await v.F.slack.updateAccount(r.accountId,{label:u,workspacePath:m,accessLevel:h,language:g}),i()}catch(e){alert(t("slack.saveFailed",{error:e instanceof Error?e.message:String(e)}))}finally{y(!1)}}async function N(){y(!0);try{await v.F.slack.updateAccount(r.accountId,{enabled:!r.enabled}),d()}catch(e){alert(t("slack.switchFailed",{error:e instanceof Error?e.message:String(e)}))}finally{y(!1)}}async function k(){if(await R(t("slack.confirmDelete",{name:r.teamId}))){y(!0);try{await v.F.slack.deleteAccount(r.accountId),c()}catch(e){alert(t("slack.deleteFailed",{error:e instanceof Error?e.message:String(e)}))}finally{y(!1)}}}return((0,l.useEffect)(()=>{a&&(x(r.label),p(r.workspacePath),f(r.accessLevel),b(r.language||"en"))},[a,r]),a)?(0,s.jsx)("li",{className:"px-4 py-3",children:(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-[10px] text-[var(--muted-foreground)]",children:t("slack.label")}),(0,s.jsx)("input",{value:u,onChange:e=>x(e.target.value),className:"mt-0.5 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1 text-xs",placeholder:t("slack.labelPlaceholder")})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-[10px] text-[var(--muted-foreground)]",children:t("slack.workspace")}),(0,s.jsx)("input",{value:m,onChange:e=>p(e.target.value),className:"mt-0.5 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1 font-mono text-xs",placeholder:"/home/user/project"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-[10px] text-[var(--muted-foreground)]",children:t("slack.accessLevel")}),(0,s.jsxs)("select",{value:h,onChange:e=>f(e.target.value),className:"mt-0.5 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1 text-xs",children:[(0,s.jsx)("option",{value:"readonly",children:t("slack.readonly")}),(0,s.jsx)("option",{value:"workspace",children:t("slack.wsWrite")}),(0,s.jsx)("option",{value:"full",children:t("slack.full")})]})]}),(0,s.jsx)(ta.LanguageSelect,{value:g,onChange:b}),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsxs)("button",{onClick:w,disabled:j||!P(m),className:"flex items-center gap-1 rounded bg-[var(--primary)] px-2 py-1 text-[11px] text-white disabled:opacity-50",children:[(0,s.jsx)(tD.A,{className:"h-3 w-3"})," ",t("slack.save")]}),(0,s.jsxs)("button",{onClick:o,disabled:j,className:"flex items-center gap-1 rounded border border-[var(--border)] px-2 py-1 text-[11px]",children:[(0,s.jsx)(eK.A,{className:"h-3 w-3"})," ",t("slack.cancel")]})]})]})}):(0,s.jsxs)("li",{className:"flex items-center gap-3 px-4 py-3",children:[(0,s.jsx)("div",{className:D("h-2 w-2 rounded-full",r.enabled?"bg-emerald-500":"bg-[var(--muted-foreground)]")}),(0,s.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:"text-xs font-medium text-[var(--foreground)]",children:r.label||r.teamId}),(0,s.jsx)("span",{className:D("rounded px-1.5 py-0.5 text-[9px] font-medium","readonly"===r.accessLevel?"bg-emerald-500/15 text-emerald-300":"workspace"===r.accessLevel?"bg-blue-500/15 text-blue-300":"bg-amber-500/15 text-amber-300"),children:"readonly"===r.accessLevel?"Readonly":"workspace"===r.accessLevel?"Workspace":"Full"})]}),(0,s.jsxs)("p",{className:"mt-0.5 truncate font-mono text-[10px] text-[var(--muted-foreground)]",children:["team:",r.teamId," bot:",r.botUserId," → ",r.workspacePath,r.workspaceMissing&&(0,s.jsx)("span",{className:"ml-1 text-red-400",children:t("slack.pathMissing")})]})]}),(0,s.jsxs)("div",{className:"flex items-center gap-1",children:[(0,s.jsx)("button",{onClick:N,disabled:j,title:r.enabled?t("slack.disable"):t("slack.enable"),className:"rounded p-1.5 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:r.enabled?(0,s.jsx)(a3.A,{className:"h-3.5 w-3.5"}):(0,s.jsx)(a2.A,{className:"h-3.5 w-3.5"})}),(0,s.jsx)("button",{onClick:n,disabled:j,title:t("slack.edit"),className:"rounded p-1.5 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,s.jsx)(a8.A,{className:"h-3.5 w-3.5"})}),(0,s.jsx)("button",{onClick:k,disabled:j,title:t("slack.delete"),className:"rounded p-1.5 text-[var(--muted-foreground)] hover:bg-red-500/20 hover:text-red-400",children:(0,s.jsx)(ej.A,{className:"h-3.5 w-3.5"})})]})]})}function no(e){let t=(0,tr.useT)(),{lang:r}=(0,tr.useI18n)(),{onClose:a,onDone:n}=e,o=e9(e=>e.activeProject),[i,c]=(0,l.useState)(""),[d,u]=(0,l.useState)(""),[x,m]=(0,l.useState)((null==o?void 0:o.path)||""),[p,h]=(0,l.useState)(""),[f,g]=(0,l.useState)("readonly"),[b,j]=(0,l.useState)(r),[y,w]=(0,l.useState)(!1),[N,k]=(0,l.useState)("");async function S(){k(""),w(!0);try{await v.F.slack.createAccount({botToken:i,appToken:d,workspacePath:x,label:p||void 0,accessLevel:f,language:b}),n()}catch(e){k(e instanceof Error?e.message:String(e))}finally{w(!1)}}return(0,s.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",onClick:a,children:(0,s.jsxs)("div",{className:"w-[480px] rounded-lg border border-[var(--border)] bg-[var(--background)] p-5 shadow-xl",onClick:e=>e.stopPropagation(),children:[(0,s.jsxs)("div",{className:"mb-4 flex items-center justify-between",children:[(0,s.jsx)("h3",{className:"text-sm font-medium text-[var(--foreground)]",children:t("slack.addTitle")}),(0,s.jsx)("button",{onClick:a,className:"text-[var(--muted-foreground)] hover:text-[var(--foreground)]",children:(0,s.jsx)(eK.A,{className:"h-4 w-4"})})]}),(0,s.jsxs)("div",{className:"space-y-3",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-[11px] text-[var(--muted-foreground)]",children:t("slack.botTokenLabel")}),(0,s.jsx)("input",{value:i,onChange:e=>c(e.target.value),className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1.5 font-mono text-xs",placeholder:"xoxb-..."}),(0,s.jsx)("p",{className:"mt-1 text-[10px] text-[var(--muted-foreground)]",children:t("slack.botTokenHint")})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-[11px] text-[var(--muted-foreground)]",children:t("slack.appTokenLabel")}),(0,s.jsx)("input",{value:d,onChange:e=>u(e.target.value),className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1.5 font-mono text-xs",placeholder:"xapp-..."}),(0,s.jsx)("p",{className:"mt-1 text-[10px] text-[var(--muted-foreground)]",children:t("slack.appTokenHint")})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-[11px] text-[var(--muted-foreground)]",children:t("slack.bindWorkspace")}),(0,s.jsx)("input",{value:x,onChange:e=>m(e.target.value),className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1.5 font-mono text-xs",placeholder:"/home/user/project"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-[11px] text-[var(--muted-foreground)]",children:t("slack.nameOptional")}),(0,s.jsx)("input",{value:p,onChange:e=>h(e.target.value),className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1.5 text-xs",placeholder:t("slack.namePlaceholder")})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-[11px] text-[var(--muted-foreground)]",children:t("slack.accessLevel")}),(0,s.jsxs)("select",{value:f,onChange:e=>g(e.target.value),className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1.5 text-xs",children:[(0,s.jsx)("option",{value:"readonly",children:t("slack.readonly")}),(0,s.jsx)("option",{value:"workspace",children:t("slack.wsWrite")}),(0,s.jsx)("option",{value:"full",children:t("slack.full")})]})]}),(0,s.jsx)(ta.LanguageSelect,{value:b,onChange:j}),N&&(0,s.jsx)("p",{className:"text-xs text-red-400",children:N}),(0,s.jsxs)("div",{className:"flex justify-end gap-2 pt-2",children:[(0,s.jsx)("button",{onClick:a,className:"rounded border border-[var(--border)] px-3 py-1.5 text-xs",children:t("slack.cancel")}),(0,s.jsxs)("button",{onClick:S,disabled:y||!i.trim()||!d.trim()||!P(x),className:"flex items-center gap-1.5 rounded bg-[var(--primary)] px-3 py-1.5 text-xs text-white disabled:opacity-50",children:[y&&(0,s.jsx)(H.A,{className:"h-3 w-3 animate-spin"}),t("slack.addBtn")]})]})]})]})})}function ni(e){let t=(0,tr.useT)(),{account:r,editing:a,onEdit:n,onCancelEdit:o,onSaved:i,onDeleted:c,onToggled:d}=e,[u,x]=(0,l.useState)(r.label),[m,p]=(0,l.useState)(r.workspacePath),[h,f]=(0,l.useState)(r.accessLevel),[g,b]=(0,l.useState)(r.language||"en"),[j,y]=(0,l.useState)(!1);async function w(){y(!0);try{await v.F.feishu.updateAccount(r.accountId,{label:u,workspacePath:m,accessLevel:h,language:g}),i()}catch(e){alert(t("feishu.saveFailed",{error:e instanceof Error?e.message:String(e)}))}finally{y(!1)}}async function N(){y(!0);try{await v.F.feishu.updateAccount(r.accountId,{enabled:!r.enabled}),d()}catch(e){alert(t("feishu.switchFailed",{error:e instanceof Error?e.message:String(e)}))}finally{y(!1)}}async function k(){if(await R(t("feishu.confirmDelete",{name:r.appId}))){y(!0);try{await v.F.feishu.deleteAccount(r.accountId),c()}catch(e){alert(t("feishu.deleteFailed",{error:e instanceof Error?e.message:String(e)}))}finally{y(!1)}}}return((0,l.useEffect)(()=>{a&&(x(r.label),p(r.workspacePath),f(r.accessLevel),b(r.language||"en"))},[a,r]),a)?(0,s.jsx)("li",{className:"px-4 py-3",children:(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-[10px] text-[var(--muted-foreground)]",children:t("feishu.label")}),(0,s.jsx)("input",{value:u,onChange:e=>x(e.target.value),className:"mt-0.5 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1 text-xs",placeholder:t("feishu.labelPlaceholder")})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-[10px] text-[var(--muted-foreground)]",children:t("feishu.workspace")}),(0,s.jsx)("input",{value:m,onChange:e=>p(e.target.value),className:"mt-0.5 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1 font-mono text-xs",placeholder:"/home/user/project"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-[10px] text-[var(--muted-foreground)]",children:t("feishu.accessLevel")}),(0,s.jsxs)("select",{value:h,onChange:e=>f(e.target.value),className:"mt-0.5 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1 text-xs",children:[(0,s.jsx)("option",{value:"readonly",children:t("feishu.readonly")}),(0,s.jsx)("option",{value:"workspace",children:t("feishu.wsWrite")}),(0,s.jsx)("option",{value:"full",children:t("feishu.full")})]})]}),(0,s.jsx)(ta.LanguageSelect,{value:g,onChange:b}),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsxs)("button",{onClick:w,disabled:j||!P(m),className:"flex items-center gap-1 rounded bg-[var(--primary)] px-2 py-1 text-[11px] text-white disabled:opacity-50",children:[(0,s.jsx)(tD.A,{className:"h-3 w-3"})," ",t("feishu.save")]}),(0,s.jsxs)("button",{onClick:o,disabled:j,className:"flex items-center gap-1 rounded border border-[var(--border)] px-2 py-1 text-[11px]",children:[(0,s.jsx)(eK.A,{className:"h-3 w-3"})," ",t("feishu.cancel")]})]})]})}):(0,s.jsxs)("li",{className:"flex items-center gap-3 px-4 py-3",children:[(0,s.jsx)("div",{className:D("h-2 w-2 rounded-full",r.enabled?"bg-emerald-500":"bg-[var(--muted-foreground)]")}),(0,s.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:"text-xs font-medium text-[var(--foreground)]",children:r.label||r.appId}),(0,s.jsx)("span",{className:D("rounded px-1.5 py-0.5 text-[9px] font-medium","readonly"===r.accessLevel?"bg-emerald-500/15 text-emerald-300":"workspace"===r.accessLevel?"bg-blue-500/15 text-blue-300":"bg-amber-500/15 text-amber-300"),children:"readonly"===r.accessLevel?"Readonly":"workspace"===r.accessLevel?"Workspace":"Full"})]}),(0,s.jsxs)("p",{className:"mt-0.5 truncate font-mono text-[10px] text-[var(--muted-foreground)]",children:["app:",r.appId," bot:",r.botOpenId," → ",r.workspacePath,r.workspaceMissing&&(0,s.jsx)("span",{className:"ml-1 text-red-400",children:t("feishu.pathMissing")})]})]}),(0,s.jsxs)("div",{className:"flex items-center gap-1",children:[(0,s.jsx)("button",{onClick:N,disabled:j,title:r.enabled?t("feishu.disable"):t("feishu.enable"),className:"rounded p-1.5 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:r.enabled?(0,s.jsx)(a3.A,{className:"h-3.5 w-3.5"}):(0,s.jsx)(a2.A,{className:"h-3.5 w-3.5"})}),(0,s.jsx)("button",{onClick:n,disabled:j,title:t("feishu.edit"),className:"rounded p-1.5 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,s.jsx)(a8.A,{className:"h-3.5 w-3.5"})}),(0,s.jsx)("button",{onClick:k,disabled:j,title:t("feishu.delete"),className:"rounded p-1.5 text-[var(--muted-foreground)] hover:bg-red-500/20 hover:text-red-400",children:(0,s.jsx)(ej.A,{className:"h-3.5 w-3.5"})})]})]})}function nc(e){let t=(0,tr.useT)(),{lang:r}=(0,tr.useI18n)(),{onClose:a,onDone:n}=e,o=e9(e=>e.activeProject),[i,c]=(0,l.useState)(""),[d,u]=(0,l.useState)(""),[x,m]=(0,l.useState)(""),[p,h]=(0,l.useState)(""),[f,g]=(0,l.useState)((null==o?void 0:o.path)||""),[b,j]=(0,l.useState)(""),[y,w]=(0,l.useState)("readonly"),[N,k]=(0,l.useState)(r),[S,C]=(0,l.useState)(!1),[A,I]=(0,l.useState)("");async function E(){I(""),C(!0);try{await v.F.feishu.createAccount({appId:i,appSecret:d,verificationToken:x||void 0,encryptKey:p||void 0,workspacePath:f,label:b||void 0,accessLevel:y,language:N}),n()}catch(e){I(e instanceof Error?e.message:String(e))}finally{C(!1)}}return(0,s.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",onClick:a,children:(0,s.jsxs)("div",{className:"w-[480px] max-h-[90vh] overflow-y-auto rounded-lg border border-[var(--border)] bg-[var(--background)] p-5 shadow-xl",onClick:e=>e.stopPropagation(),children:[(0,s.jsxs)("div",{className:"mb-4 flex items-center justify-between",children:[(0,s.jsx)("h3",{className:"text-sm font-medium text-[var(--foreground)]",children:t("feishu.addTitle")}),(0,s.jsx)("button",{onClick:a,className:"text-[var(--muted-foreground)] hover:text-[var(--foreground)]",children:(0,s.jsx)(eK.A,{className:"h-4 w-4"})})]}),(0,s.jsxs)("div",{className:"space-y-3",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-[11px] text-[var(--muted-foreground)]",children:t("feishu.appIdLabel")}),(0,s.jsx)("input",{value:i,onChange:e=>c(e.target.value),className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1.5 font-mono text-xs",placeholder:"cli_xxxxxxx"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-[11px] text-[var(--muted-foreground)]",children:t("feishu.appSecretLabel")}),(0,s.jsx)("input",{type:"password",value:d,onChange:e=>u(e.target.value),className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1.5 font-mono text-xs",placeholder:"****************"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-[11px] text-[var(--muted-foreground)]",children:t("feishu.verificationTokenLabel")}),(0,s.jsx)("input",{value:x,onChange:e=>m(e.target.value),className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1.5 font-mono text-xs",placeholder:""})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-[11px] text-[var(--muted-foreground)]",children:t("feishu.encryptKeyLabel")}),(0,s.jsx)("input",{type:"password",value:p,onChange:e=>h(e.target.value),className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1.5 font-mono text-xs",placeholder:""})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-[11px] text-[var(--muted-foreground)]",children:t("feishu.bindWorkspace")}),(0,s.jsx)("input",{value:f,onChange:e=>g(e.target.value),className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1.5 font-mono text-xs",placeholder:"/home/user/project"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-[11px] text-[var(--muted-foreground)]",children:t("feishu.nameOptional")}),(0,s.jsx)("input",{value:b,onChange:e=>j(e.target.value),className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1.5 text-xs",placeholder:t("feishu.namePlaceholder")})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"text-[11px] text-[var(--muted-foreground)]",children:t("feishu.accessLevel")}),(0,s.jsxs)("select",{value:y,onChange:e=>w(e.target.value),className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--card)] px-2 py-1.5 text-xs",children:[(0,s.jsx)("option",{value:"readonly",children:t("feishu.readonly")}),(0,s.jsx)("option",{value:"workspace",children:t("feishu.wsWrite")}),(0,s.jsx)("option",{value:"full",children:t("feishu.full")})]})]}),(0,s.jsx)(ta.LanguageSelect,{value:N,onChange:k}),A&&(0,s.jsx)("p",{className:"text-xs text-red-400",children:A}),(0,s.jsxs)("div",{className:"flex justify-end gap-2 pt-2",children:[(0,s.jsx)("button",{onClick:a,className:"rounded border border-[var(--border)] px-3 py-1.5 text-xs",children:t("feishu.cancel")}),(0,s.jsxs)("button",{onClick:E,disabled:S||!i.trim()||!d.trim()||!P(f),className:"flex items-center gap-1.5 rounded bg-[var(--primary)] px-3 py-1.5 text-xs text-white disabled:opacity-50",children:[S&&(0,s.jsx)(H.A,{className:"h-3 w-3 animate-spin"}),t("feishu.addBtn")]})]})]})]})})}let nd=[a7,nr,ns,{id:"slack",label:"Slack",Icon:X.A,Component:function(){let e=(0,tr.useT)(),[t,r]=(0,l.useState)([]),[a,n]=(0,l.useState)(!0),[o,i]=(0,l.useState)(!1),[c,d]=(0,l.useState)(null),u=(0,l.useCallback)(()=>{n(!0),v.F.slack.listAccounts().then(e=>r(e.accounts)).catch(e=>{console.error("[slack] list failed:",e)}).finally(()=>n(!1))},[]);(0,l.useEffect)(()=>{u()},[u]);let x=a1(e=>e.version);return(0,l.useEffect)(()=>{x>0&&u()},[x,u]),(0,s.jsxs)("div",{className:"flex h-full flex-col",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between border-b border-[var(--border)] px-4 py-3",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("h2",{className:"text-sm font-medium text-[var(--foreground)]",children:e("slack.title")}),(0,s.jsx)("p",{className:"text-[11px] text-[var(--muted-foreground)]",children:e("slack.desc")})]}),(0,s.jsxs)("button",{onClick:()=>i(!0),className:"flex items-center gap-1.5 rounded-md bg-[var(--primary)] px-3 py-1.5 text-xs font-medium text-white hover:opacity-90",children:[(0,s.jsx)(rA.A,{className:"h-3.5 w-3.5"}),e("slack.add")]})]}),(0,s.jsx)("div",{className:"min-h-0 flex-1 overflow-y-auto",children:a?(0,s.jsxs)("div",{className:"flex items-center justify-center py-8 text-xs text-[var(--muted-foreground)]",children:[(0,s.jsx)(H.A,{className:"mr-2 h-3.5 w-3.5 animate-spin"}),e("slack.loading")]}):0===t.length?(0,s.jsx)("div",{className:"p-8 text-center text-xs text-[var(--muted-foreground)]",children:e("slack.empty")}):(0,s.jsx)("ul",{className:"divide-y divide-[var(--border)]",children:t.map(e=>(0,s.jsx)(nl,{account:e,editing:c===e.accountId,onEdit:()=>d(e.accountId),onCancelEdit:()=>d(null),onSaved:()=>{d(null),u()},onDeleted:u,onToggled:u},e.accountId))})}),o&&(0,s.jsx)(no,{onClose:()=>i(!1),onDone:()=>{i(!1),u()}})]})}},{id:"feishu",label:"Feishu",Icon:r(29659).A,Component:function(){let e=(0,tr.useT)(),[t,r]=(0,l.useState)([]),[a,n]=(0,l.useState)(!0),[o,i]=(0,l.useState)(!1),[c,d]=(0,l.useState)(null),u=(0,l.useCallback)(()=>{n(!0),v.F.feishu.listAccounts().then(e=>r(e.accounts)).catch(e=>{console.error("[feishu] list failed:",e)}).finally(()=>n(!1))},[]);(0,l.useEffect)(()=>{u()},[u]);let x=a1(e=>e.version);return(0,l.useEffect)(()=>{x>0&&u()},[x,u]),(0,s.jsxs)("div",{className:"flex h-full flex-col",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between border-b border-[var(--border)] px-4 py-3",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("h2",{className:"text-sm font-medium text-[var(--foreground)]",children:e("feishu.title")}),(0,s.jsx)("p",{className:"text-[11px] text-[var(--muted-foreground)]",children:e("feishu.desc")})]}),(0,s.jsxs)("button",{onClick:()=>i(!0),className:"flex items-center gap-1.5 rounded-md bg-[var(--primary)] px-3 py-1.5 text-xs font-medium text-white hover:opacity-90",children:[(0,s.jsx)(rA.A,{className:"h-3.5 w-3.5"}),e("feishu.add")]})]}),(0,s.jsx)("div",{className:"min-h-0 flex-1 overflow-y-auto",children:a?(0,s.jsxs)("div",{className:"flex items-center justify-center py-8 text-xs text-[var(--muted-foreground)]",children:[(0,s.jsx)(H.A,{className:"mr-2 h-3.5 w-3.5 animate-spin"}),e("feishu.loading")]}):0===t.length?(0,s.jsx)("div",{className:"p-8 text-center text-xs text-[var(--muted-foreground)]",children:e("feishu.empty")}):(0,s.jsx)("ul",{className:"divide-y divide-[var(--border)]",children:t.map(e=>(0,s.jsx)(ni,{account:e,editing:c===e.accountId,onEdit:()=>d(e.accountId),onCancelEdit:()=>d(null),onSaved:()=>{d(null),u()},onDeleted:u,onToggled:u},e.accountId))})}),o&&(0,s.jsx)(nc,{onClose:()=>i(!1),onDone:()=>{i(!1),u()}})]})}}],nu="halo_channel_active",nx=new Set(nd.map(e=>e.id)),nm=null!=(n=null==(a=nd[0])?void 0:a.id)?n:"",np=(0,c.v)(e=>({active:function(){try{let e=localStorage.getItem(nu);if(e&&nx.has(e))return e}catch(e){}return nm}(),setActive(t){if(nx.has(t)){try{localStorage.setItem(nu,t)}catch(e){}e({active:t})}}}));function nh(){let e=(0,tr.useT)(),t=np(e=>e.active),r=np(e=>e.setActive);return(0,s.jsxs)("div",{className:"flex h-full flex-col",children:[(0,s.jsxs)("div",{className:"flex h-10 items-center gap-2 border-b border-[var(--border)] px-3",children:[(0,s.jsx)(a0.A,{className:"h-4 w-4 text-[var(--muted-foreground)]"}),(0,s.jsx)("span",{className:"text-sm font-medium text-[var(--foreground)]",children:"Channels"}),(0,s.jsx)("div",{className:"flex-1"}),(0,s.jsx)("button",{onClick:()=>void a1.getState().bump(),title:"Refresh",className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)] transition-colors",children:(0,s.jsx)(r5.A,{className:"h-3.5 w-3.5"})})]}),(0,s.jsx)("div",{className:"min-h-0 flex-1 overflow-y-auto py-1",children:nd.map(a=>{if(!1===a.enabled)return null;let n=a.Icon,l=e(a.label),o=l===a.label?a.label:l;return(0,s.jsxs)("button",{onClick:()=>r(a.id),className:D("flex w-full items-center gap-2 px-3 py-2 text-xs transition-colors",t===a.id?"bg-[var(--secondary)] text-[var(--foreground)]":"text-[var(--muted-foreground)] hover:bg-[var(--secondary)]/50 hover:text-[var(--foreground)]"),children:[(0,s.jsx)(n,{className:"h-3.5 w-3.5"}),o]},a.id)})})]})}function nf(){let e=np(e=>e.active),t=nd.find(t=>t.id===e);if(!t)return null;let r=t.Component;return(0,s.jsx)(r,{})}var ng=r(23704);let nv=(0,c.v)(e=>({selectedId:null,filter:"all",refreshTick:0,setSelectedId:t=>e({selectedId:t}),setFilter:t=>e({filter:t}),bumpRefresh:()=>e(e=>({refreshTick:e.refreshTick+1}))}));function nb(){let e=(0,tr.useT)(),t=nv(e=>e.selectedId);return t?(0,s.jsx)(nN,{id:t}):(0,s.jsx)(nj,{label:e("evolution.list.pickRun")})}function nj(e){let{label:t}=e;return(0,s.jsx)("div",{className:"flex h-full items-center justify-center p-6 text-sm text-[var(--muted-foreground)]",children:t})}function ny(e){var t;let{status:r}=e,a=null!=(t=nw[r])?t:"bg-[var(--accent)] text-[var(--foreground)]";return(0,s.jsx)("span",{className:D("rounded px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide",a),children:r.replace("_"," ")})}let nw={pending:"bg-[var(--accent)] text-[var(--foreground)]",running:"bg-blue-700 text-blue-100",awaiting_review:"bg-amber-600 text-amber-50",approved:"bg-emerald-700 text-emerald-50",applied:"bg-emerald-800 text-emerald-100",skipped:"bg-[var(--accent)] text-[var(--foreground)]",rejected:"bg-red-700 text-red-50",failed:"bg-red-800 text-red-100",timeout:"bg-orange-700 text-orange-100"};function nN(e){var t,r,a,n;let{id:o}=e,i=(0,tr.useT)(),c=nv(e=>e.refreshTick),d=nv(e=>e.setSelectedId),[u,x]=(0,l.useState)(null),[m,p]=(0,l.useState)(!0),[h,f]=(0,l.useState)(null),[g,b]=(0,l.useState)(!1),[y,w]=(0,l.useState)(""),[N,k]=(0,l.useState)(""),[S,C]=(0,l.useState)(!1),[A,I]=(0,l.useState)(!1),[E,T]=(0,l.useState)(!1),[F,D]=(0,l.useState)(""),M=(0,l.useCallback)(async()=>{p(!0);try{let e=await v.F.evolution.getRun(o);x(e),f(null)}catch(e){f(e instanceof Error?e.message:String(e))}finally{p(!1)}},[o]);if((0,l.useEffect)(()=>{x(null),C(!1),I(!1),w(""),k(""),M()},[o,M]),(0,l.useEffect)(()=>{0!==c&&M()},[c,M]),(0,l.useEffect)(()=>j.on("evolution:run_changed",e=>{e.id===o&&("deleted"===e.kind?d(null):M())}),[o,M,d]),m&&!u)return(0,s.jsx)(nj,{label:i("evolution.list.loading")});if(h)return(0,s.jsx)(nj,{label:i("cron.error",{error:h})});if(!u)return(0,s.jsx)(nj,{label:i("evolution.list.noRun")});let{run:P,patchMd:L,scoreJson:z,skipReasonMd:_,snapshotSummary:O,wrapperLog:W,subCliLog:U}=u,B="awaiting_review"===P.status,H="approved"===P.status&&("failed"===P.applyStatus||"timeout"===P.applyStatus),K=async()=>{b(!0);try{await v.F.evolution.approve(o,y.trim()||void 0),C(!1),w(""),await M()}catch(e){alert(e instanceof Error?e.message:String(e))}finally{b(!1)}},G=async()=>{if(await R(i("evolution.action.confirmReject"))){b(!0);try{await v.F.evolution.reject(o),await M()}catch(e){alert(e instanceof Error?e.message:String(e))}finally{b(!1)}}},J=async()=>{let e=N.trim();if(e){b(!0);try{await v.F.evolution.addHint(o,e),k(""),I(!1),await M()}catch(e){alert(e instanceof Error?e.message:String(e))}finally{b(!1)}}},q=async()=>{let e=F.trim();if(!e)return void alert(i("evolution.action.retryNeedsHint"));b(!0);try{await v.F.evolution.retry(o,e),D(""),T(!1),await M()}catch(e){alert(e instanceof Error?e.message:String(e))}finally{b(!1)}},Z=async()=>{if(await R(i("evolution.action.confirmDelete"))){b(!0);try{await v.F.evolution.delete(o),d(null)}catch(e){alert(e instanceof Error?e.message:String(e)),b(!1)}}};return(0,s.jsxs)("div",{className:"flex h-full flex-col",children:[(0,s.jsxs)("div",{className:"border-b border-[var(--border)] px-4 py-3",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(ny,{status:P.status}),(0,s.jsx)("span",{className:"text-sm text-[var(--muted-foreground)]",children:P.triggerKind}),(0,s.jsx)("span",{className:"ml-auto text-xs text-[var(--muted-foreground)]",children:P.id}),"pending"!==P.status&&"running"!==P.status&&"approved"!==P.status&&(0,s.jsx)("button",{disabled:g,onClick:()=>{Z()},className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-red-700/80 hover:text-white disabled:opacity-50",title:i("evolution.action.delete"),children:(0,s.jsx)(ej.A,{className:"h-3.5 w-3.5"})})]}),(0,s.jsxs)("div",{className:"mt-2 text-xs text-[var(--muted-foreground)]",children:[i("evolution.detail.workspace")," ",(0,s.jsx)("span",{className:"font-mono",children:P.workspacePath})]}),P.userHint&&(0,s.jsxs)("div",{className:"mt-2 rounded bg-[var(--accent)] p-2 text-xs",children:[(0,s.jsx)("div",{className:"font-medium text-[var(--foreground)]",children:i("evolution.detail.hint")}),(0,s.jsx)("div",{className:"mt-1 whitespace-pre-wrap text-[var(--muted-foreground)]",children:P.userHint})]}),P.failureReason&&(0,s.jsx)("div",{className:"mt-2 rounded bg-red-900/30 p-2 text-xs text-red-200",children:i("evolution.detail.failure",{reason:P.failureReason})}),"skipped"===P.status&&(0,s.jsx)("div",{className:"mt-2 rounded bg-[var(--accent)] p-2 text-xs text-[var(--muted-foreground)]",children:i("evolution.detail.skipped")}),H&&(0,s.jsxs)("div",{className:"mt-2 rounded bg-red-900/30 p-2 text-xs text-red-200",children:[(0,s.jsx)("div",{className:"font-medium",children:i("evolution.detail.applyFailed")}),P.applyFailureReason&&(0,s.jsx)("div",{className:"mt-1 whitespace-pre-wrap",children:P.applyFailureReason})]})]}),B&&(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-2 border-b border-[var(--border)] bg-amber-950/20 px-4 py-2",children:[(0,s.jsxs)("button",{disabled:g,onClick:()=>C(e=>!e),className:"flex items-center gap-1 rounded bg-emerald-700 px-2 py-1 text-xs text-emerald-50 hover:bg-emerald-600 disabled:opacity-50",children:[(0,s.jsx)(tD.A,{className:"h-3.5 w-3.5"})," ",i("evolution.action.approve")]}),(0,s.jsxs)("button",{disabled:g,onClick:()=>{G()},className:"flex items-center gap-1 rounded bg-red-700 px-2 py-1 text-xs text-red-50 hover:bg-red-600 disabled:opacity-50",children:[(0,s.jsx)(eK.A,{className:"h-3.5 w-3.5"})," ",i("evolution.action.reject")]}),(0,s.jsxs)("button",{disabled:g,onClick:()=>I(e=>!e),className:"flex items-center gap-1 rounded bg-[var(--accent)] px-2 py-1 text-xs text-[var(--foreground)] hover:bg-[var(--accent)]/80 disabled:opacity-50",children:[(0,s.jsx)(ng.A,{className:"h-3.5 w-3.5"})," ",i("evolution.action.addHint")]}),(0,s.jsxs)("button",{disabled:g,onClick:()=>T(e=>!e),className:"flex items-center gap-1 rounded bg-sky-700 px-2 py-1 text-xs text-sky-50 hover:bg-sky-600 disabled:opacity-50",title:i("evolution.retry.tooltip"),children:[(0,s.jsx)(r5.A,{className:"h-3.5 w-3.5"})," ",i("evolution.action.retry")]})]}),!B&&("failed"===P.status||"timeout"===P.status||"skipped"===P.status||"rejected"===P.status||H)&&(0,s.jsx)("div",{className:"flex flex-wrap items-center gap-2 border-b border-[var(--border)] bg-sky-950/20 px-4 py-2",children:(0,s.jsxs)("button",{disabled:g,onClick:()=>T(e=>!e),className:"flex items-center gap-1 rounded bg-sky-700 px-2 py-1 text-xs text-sky-50 hover:bg-sky-600 disabled:opacity-50",title:i("evolution.retry.tooltip"),children:[(0,s.jsx)(r5.A,{className:"h-3.5 w-3.5"})," ",i("evolution.action.retryWithHint")]})}),E&&(0,s.jsxs)("div",{className:"border-b border-[var(--border)] bg-sky-950/20 px-4 py-2",children:[(0,s.jsx)("div",{className:"text-xs text-[var(--muted-foreground)]",children:i("evolution.retry.title")}),(0,s.jsx)("textarea",{value:F,onChange:e=>D(e.target.value),rows:2,className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--background)] p-2 text-xs",placeholder:i("evolution.retry.placeholder"),autoFocus:!0}),(0,s.jsxs)("div",{className:"mt-1 flex gap-2",children:[(0,s.jsx)("button",{disabled:g||!F.trim(),onClick:()=>{q()},className:"rounded bg-sky-700 px-2 py-1 text-xs text-sky-50 hover:bg-sky-600 disabled:opacity-50",children:i("evolution.action.confirmRetry")}),(0,s.jsx)("button",{disabled:g,onClick:()=>{T(!1),D("")},className:"rounded bg-[var(--accent)] px-2 py-1 text-xs text-[var(--foreground)] hover:bg-[var(--accent)]/80 disabled:opacity-50",children:i("evolution.action.cancel")})]})]}),B&&S&&(0,s.jsxs)("div",{className:"border-b border-[var(--border)] bg-emerald-950/20 px-4 py-2",children:[(0,s.jsx)("div",{className:"text-xs text-[var(--muted-foreground)]",children:i("evolution.approve.title")}),(0,s.jsx)("textarea",{value:y,onChange:e=>w(e.target.value),rows:2,className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--background)] p-2 text-xs",placeholder:i("evolution.approve.placeholder")}),(0,s.jsxs)("div",{className:"mt-1 flex gap-2",children:[(0,s.jsx)("button",{disabled:g,onClick:()=>{K()},className:"rounded bg-emerald-700 px-2 py-1 text-xs text-emerald-50 hover:bg-emerald-600 disabled:opacity-50",children:i("evolution.action.confirmApprove")}),(0,s.jsx)("button",{disabled:g,onClick:()=>{C(!1),w("")},className:"rounded bg-[var(--accent)] px-2 py-1 text-xs text-[var(--foreground)] hover:bg-[var(--accent)]/80 disabled:opacity-50",children:i("evolution.action.cancel")})]})]}),B&&A&&(0,s.jsxs)("div",{className:"border-b border-[var(--border)] bg-[var(--background)]/40 px-4 py-2",children:[(0,s.jsx)("div",{className:"text-xs text-[var(--muted-foreground)]",children:i("evolution.hint.title")}),(0,s.jsx)("textarea",{value:N,onChange:e=>k(e.target.value),rows:2,className:"mt-1 w-full rounded border border-[var(--border)] bg-[var(--background)] p-2 text-xs",placeholder:i("evolution.hint.placeholder")}),(0,s.jsxs)("div",{className:"mt-1 flex gap-2",children:[(0,s.jsx)("button",{disabled:g||!N.trim(),onClick:()=>{J()},className:"rounded bg-[var(--accent)] px-2 py-1 text-xs text-[var(--foreground)] hover:bg-[var(--accent)]/80 disabled:opacity-50",children:i("evolution.action.add")}),(0,s.jsx)("button",{disabled:g,onClick:()=>{I(!1),k("")},className:"rounded bg-[var(--accent)] px-2 py-1 text-xs text-[var(--foreground)] hover:bg-[var(--accent)]/80 disabled:opacity-50",children:i("evolution.action.cancel")})]})]}),z&&(0,s.jsxs)("div",{className:"border-b border-[var(--border)] px-4 py-3",children:[(0,s.jsx)("div",{className:"mb-2 text-sm font-medium",children:i("evolution.score.title")}),(0,s.jsxs)("div",{className:"grid grid-cols-4 gap-3 text-xs",children:[(0,s.jsx)(nS,{label:i("evolution.score.lint"),value:z.lint}),(0,s.jsx)(nS,{label:i("evolution.score.behavior"),value:z.behavior}),(0,s.jsx)(nS,{label:i("evolution.score.scope"),value:z.scope}),(0,s.jsx)(nS,{label:i("evolution.score.avg"),value:z.avg,highlight:!0})]}),(0,s.jsxs)("div",{className:"mt-2 flex items-center gap-2 text-xs text-[var(--muted-foreground)]",children:[(0,s.jsx)("span",{children:i("evolution.score.confidence")}),(0,s.jsx)("span",{className:"font-medium text-[var(--foreground)]",children:null!=(t=z.confidence)?t:"—"})]}),"string"==typeof z.notes&&(0,s.jsx)("div",{className:"mt-2 whitespace-pre-wrap rounded bg-[var(--accent)] p-2 text-xs text-[var(--foreground)]",children:z.notes})]}),O&&(0,s.jsxs)("div",{className:"border-b border-[var(--border)] px-4 py-3 text-xs",children:[(0,s.jsx)("div",{className:"mb-1 font-medium",children:i("evolution.snapshot.title",{n:null!=(r=O.messageCount)?r:0})}),O.firstUser&&(0,s.jsxs)("div",{className:"mb-1",children:[(0,s.jsxs)("span",{className:"text-[var(--muted-foreground)]",children:[i("evolution.snapshot.firstUser")," "]}),(0,s.jsx)("span",{className:"line-clamp-2 whitespace-pre-wrap",children:O.firstUser})]}),O.firstAssistant&&(0,s.jsxs)("div",{children:[(0,s.jsxs)("span",{className:"text-[var(--muted-foreground)]",children:[i("evolution.snapshot.firstAssistant")," "]}),(0,s.jsx)("span",{className:"line-clamp-3 whitespace-pre-wrap",children:(a=O.firstAssistant,n=400,a.length<=400?a:a.slice(0,n)+"…")})]})]}),(0,s.jsxs)("div",{className:"flex-1 overflow-y-auto px-4 py-3",children:[_&&(0,s.jsxs)("div",{className:"mb-4",children:[(0,s.jsx)("div",{className:"mb-2 text-sm font-medium",children:i("evolution.skip.title")}),(0,s.jsx)("pre",{className:"whitespace-pre-wrap rounded border border-[var(--border)]/40 bg-[var(--secondary)]/40 p-3 text-xs leading-relaxed",children:_})]}),(0,s.jsx)("div",{className:"mb-2 text-sm font-medium",children:i("evolution.patch.title")}),L?(0,s.jsx)("pre",{className:"whitespace-pre-wrap rounded bg-[var(--accent)] p-3 text-xs leading-relaxed",children:L}):(0,s.jsx)("div",{className:"text-xs italic text-[var(--muted-foreground)]",children:i("evolution.patch.empty")}),(W||U)&&(0,s.jsxs)("div",{className:"mt-6 space-y-4 border-t border-[var(--border)] pt-4",children:[(0,s.jsx)("div",{className:"text-xs uppercase tracking-wide text-[var(--muted-foreground)]",children:i("evolution.logs.title")}),W&&(0,s.jsx)(nk,{title:i("evolution.logs.wrapper"),body:W}),U&&(0,s.jsx)(nk,{title:i("evolution.logs.subCli"),body:U})]})]})]})}function nk(e){let{title:t,body:r}=e,[a,n]=(0,l.useState)(r.length<4e3);return(0,s.jsxs)("div",{children:[(0,s.jsxs)("button",{type:"button",className:"flex items-center gap-2 text-sm font-medium text-[var(--foreground)] hover:text-[var(--primary)]",onClick:()=>n(e=>!e),children:[(0,s.jsx)("span",{children:a?"▼":"▶"}),(0,s.jsx)("span",{children:t}),(0,s.jsxs)("span",{className:"text-xs text-[var(--muted-foreground)]",children:["(",(r.length/1024).toFixed(1)," KB)"]})]}),a&&(0,s.jsx)("pre",{className:"mt-2 whitespace-pre-wrap break-words rounded border border-[var(--border)]/40 bg-[var(--background)]/40 p-3 font-mono text-[11px] leading-relaxed",children:r})]})}function nS(e){let{label:t,value:r,highlight:a}=e;return(0,s.jsxs)("div",{className:D("rounded p-2",a?"bg-[var(--primary)]/10":"bg-[var(--accent)]"),children:[(0,s.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-[var(--muted-foreground)]",children:t}),(0,s.jsx)("div",{className:D("text-lg font-medium",a&&"text-[var(--primary)]"),children:"number"==typeof r?r:"—"})]})}let nC=["all","awaiting_review","pending","running","approved","applied","skipped","rejected","failed","timeout","archived"];function nA(){let e=(0,tr.useT)(),t=nv(e=>e.filter),r=nv(e=>e.setFilter),a=nv(e=>e.selectedId),n=nv(e=>e.setSelectedId),o=nv(e=>e.bumpRefresh),[i,c]=(0,l.useState)([]),[d,u]=(0,l.useState)(!0),[x,m]=(0,l.useState)(null),[p,h]=(0,l.useState)(!1),[f,g]=(0,l.useState)(null),[b,y]=(0,l.useState)(!1),w=(0,l.useRef)(0);(0,l.useEffect)(()=>{w.current=i.length,i.length>=300&&g(null)},[i.length]);let N=(0,l.useCallback)(async()=>{let e=Math.min(300,Math.max(20,w.current));try{let r=await v.F.evolution.listRuns({archived:"archived"===t,limit:e});c(r.runs),g(r.hasMore?r.nextCursor:null),m(null)}catch(e){m(e instanceof Error?e.message:String(e))}finally{u(!1)}},[t]),k=(0,l.useCallback)(async()=>{if(f&&!b){y(!0);try{let e=await v.F.evolution.listRuns({archived:"archived"===t,limit:20,before:f});c(t=>[...t,...e.runs]),g(e.hasMore?e.nextCursor:null)}catch(e){console.error("evolution.listRuns more",e)}finally{y(!1)}}},[t,f,b]);(0,l.useEffect)(()=>{N()},[N]);let S=(0,l.useRef)(null);(0,l.useEffect)(()=>{let e=S.current;if(!e||"undefined"==typeof IntersectionObserver)return;let t=new IntersectionObserver(e=>{var t;(null==(t=e[0])?void 0:t.isIntersecting)&&k()},{rootMargin:"64px"});return t.observe(e),()=>t.disconnect()},[k,i.length]),(0,l.useEffect)(()=>{let e=j.on("evolution:run_changed",()=>{N()}),t=j.on("evolution:apply_changed",()=>{N()});return()=>{e(),t()}},[N]);let C=(0,l.useMemo)(()=>"all"===t||"archived"===t?i:i.filter(e=>e.status===t),[i,t]);return(0,l.useEffect)(()=>{var e;if(a)return;let t=null!=(e=i.find(e=>"awaiting_review"===e.status))?e:i[0];t&&n(t.id)},[i,a,n]),(0,s.jsxs)("div",{className:"flex h-full flex-col border-r border-[var(--border)] bg-[var(--background)]",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between gap-2 border-b border-[var(--border)] px-3 py-2",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 text-sm font-medium text-[var(--foreground)]",children:[(0,s.jsx)(t0.A,{className:"h-4 w-4"}),e("evolution.title")]}),(0,s.jsx)("button",{onClick:async()=>{h(!0),o();let e=new Promise(e=>setTimeout(e,400));await Promise.all([N(),e]),h(!1)},disabled:p,className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--accent)] hover:text-[var(--foreground)] disabled:cursor-default",title:e("evolution.refresh"),children:(0,s.jsx)(r5.A,{className:D("h-3.5 w-3.5",p&&"animate-spin")})})]}),(0,s.jsx)("div",{className:"flex flex-wrap gap-1 border-b border-[var(--border)] px-2 py-2",children:nC.map(a=>(0,s.jsx)("button",{onClick:()=>r(a),className:D("w-16 shrink-0 rounded px-2 py-0.5 text-xs text-center",t===a?"bg-[var(--primary)] text-[var(--primary-foreground)]":"text-[var(--muted-foreground)] hover:bg-[var(--accent)] hover:text-[var(--foreground)]"),children:e("evolution.filter.".concat(a))},a))}),(0,s.jsxs)("div",{className:"flex-1 overflow-y-auto",children:[d&&(0,s.jsx)(nI,{label:e("evolution.list.loading")}),x&&(0,s.jsx)(nI,{label:e("cron.error",{error:x})}),!d&&!x&&0===C.length&&(0,s.jsx)(nI,{label:e("evolution.list.empty")}),C.map(e=>(0,s.jsx)(nE,{run:e,selected:e.id===a,onClick:()=>n(e.id)},e.id)),f&&(0,s.jsx)("div",{ref:S,className:"px-3 py-3 text-center text-[10px] text-[var(--muted-foreground)]",children:b?e("evolution.list.loading"):e("cron.loadOlder")})]})]})}function nI(e){let{label:t}=e;return(0,s.jsx)("div",{className:"flex h-full items-center justify-center p-6 text-sm text-[var(--muted-foreground)]",children:t})}function nE(e){var t;let{run:r,selected:a,onClick:n}=e,l=(0,tr.useT)();return(0,s.jsxs)("button",{onClick:n,className:D("flex w-full flex-col gap-1 border-b border-[var(--border)] px-3 py-2 text-left text-sm transition-colors",a?"bg-[var(--accent)] text-[var(--foreground)]":"text-[var(--muted-foreground)] hover:bg-[var(--accent)] hover:text-[var(--foreground)]"),children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(nT,{status:r.status}),"approved"===r.status&&("failed"===r.applyStatus||"timeout"===r.applyStatus)&&(0,s.jsx)("span",{className:"rounded bg-red-800 px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide text-red-100",children:l("evolution.list.applyFailed")}),(0,s.jsx)("span",{className:"text-xs",children:r.triggerKind})]}),(0,s.jsx)("div",{className:"truncate text-xs text-[var(--muted-foreground)]",children:null!=(t=r.userHint)?t:(0,s.jsx)("span",{className:"italic",children:l("evolution.list.noHint")})}),(0,s.jsxs)("div",{className:"flex items-center gap-2 text-[10px] text-[var(--muted-foreground)]",children:[(0,s.jsx)("span",{children:function(e,t){let r=Math.floor((Date.now()-e)/6e4);if(r<1)return t("evolution.time.justNow");if(r<60)return t("evolution.time.minutes",{n:r});let a=Math.floor(r/60);return a<24?t("evolution.time.hours",{n:a}):t("evolution.time.days",{n:Math.floor(a/24)})}(r.createdAt,l)}),(0,s.jsx)("span",{children:"•"}),(0,s.jsx)("span",{title:r.workspacePath,className:"truncate",children:r.workspacePath.split("/").pop()}),r.attempts>1&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("span",{children:"•"}),(0,s.jsx)("span",{children:l("evolution.list.attempts",{n:r.attempts})})]})]})]})}function nT(e){var t;let{status:r}=e,a=null!=(t=nF[r])?t:"bg-[var(--accent)] text-[var(--foreground)]";return(0,s.jsx)("span",{className:D("rounded px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide",a),children:r.replace("_"," ")})}let nF={pending:"bg-[var(--accent)] text-[var(--foreground)]",running:"bg-blue-700 text-blue-100",awaiting_review:"bg-amber-600 text-amber-50",approved:"bg-emerald-700 text-emerald-50",applied:"bg-emerald-800 text-emerald-100",skipped:"bg-[var(--accent)] text-[var(--foreground)]",rejected:"bg-red-700 text-red-50",failed:"bg-red-800 text-red-100",timeout:"bg-orange-700 text-orange-100"};var nD=r(97016),nM=r.n(nD),nP=r(97482);let nL=(0,c.v)(e=>({selectedId:null,formMode:null,setSelectedId:t=>e({selectedId:t,formMode:null}),openCreate:()=>e({formMode:"create"}),openEdit:()=>e({formMode:"edit"}),closeForm:()=>e({formMode:null})}));function nR(e,t){return e?e.includes("ret=-2")?t("cron.err.wechat.noInbound"):e:"?"}function nz(){let e=(0,tr.useT)(),t=nL(e=>e.selectedId),r=nL(e=>e.setSelectedId),a=nL(e=>e.formMode),n=nL(e=>e.closeForm),[o,i]=(0,l.useState)(null),c=(0,l.useCallback)(async()=>{if(!t)return void i(null);try{var e;let{jobs:r}=await v.F.cron.listJobs();i(null!=(e=r.find(e=>e.id===t))?e:null)}catch(e){console.error("cron.listJobs",e)}},[t]);(0,l.useEffect)(()=>{c()},[c]),(0,l.useEffect)(()=>j.on("cron:job_changed",()=>{c()}),[c]);let d=(0,l.useCallback)(async a=>{if(await R(e("cron.confirmDelete")))try{await v.F.cron.deleteJob(a),t===a&&r(null)}catch(e){alert(e instanceof Error?e.message:String(e))}},[t,r,e]),u=(0,l.useCallback)(async e=>{try{await v.F.cron.runNow(e)}catch(e){alert(e instanceof Error?e.message:String(e))}},[]);return"create"===a?(0,s.jsx)(nW,{onClose:n,onSaved:n}):"edit"===a&&o?(0,s.jsx)(nW,{initial:o,onClose:n,onSaved:n}):o?(0,s.jsx)(n_,{job:o,onEdit:()=>nL.getState().openEdit(),onDelete:()=>d(o.id),onRunNow:()=>u(o.id)},o.id):(0,s.jsx)("div",{className:"flex h-full items-center justify-center text-xs text-[var(--muted-foreground)]",children:e("cron.pickJob")})}function n_(e){let{job:t,onEdit:r,onDelete:a,onRunNow:n}=e,o=(0,tr.useT)(),[i,c]=(0,l.useState)([]),[d,u]=(0,l.useState)(null),[x,m]=(0,l.useState)(null),[p,h]=(0,l.useState)(!1),[f,g]=(0,l.useState)(null),[b,y]=(0,l.useState)(!1),w=(0,l.useCallback)(async()=>{try{let e=await v.F.cron.listRuns(t.id,{limit:20});c(e.runs),g(e.hasMore?e.nextCursor:null)}catch(e){console.error("listRuns",e)}},[t.id]),N=(0,l.useCallback)(async()=>{if(f&&!b){y(!0);try{let e=await v.F.cron.listRuns(t.id,{limit:20,before:f});c(t=>[...t,...e.runs]),g(e.hasMore?e.nextCursor:null)}catch(e){console.error("listRuns more",e)}finally{y(!1)}}},[t.id,f,b]);(0,l.useEffect)(()=>{w()},[w]);let k=(0,l.useRef)(null);(0,l.useEffect)(()=>{let e=k.current;if(!e||"undefined"==typeof IntersectionObserver)return;let t=new IntersectionObserver(e=>{var t;(null==(t=e[0])?void 0:t.isIntersecting)&&N()},{rootMargin:"64px"});return t.observe(e),()=>t.disconnect()},[N,i.length]),(0,l.useEffect)(()=>j.on("cron:run_changed",e=>{e.jobId===t.id&&w()}),[t.id,w]);let S=(0,l.useCallback)(async e=>{u(e),m(null),h(!0);try{let{log:t}=await v.F.cron.getRunLog(e);m(null!=t?t:"(log file not available — retention or never written)")}catch(e){m("error: ".concat(e instanceof Error?e.message:String(e)))}finally{h(!1)}},[]);return(0,s.jsxs)("div",{className:"flex h-full flex-col",children:[(0,s.jsxs)("div",{className:"border-b border-[var(--border)] px-4 py-3",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,s.jsxs)("div",{className:"flex flex-1 items-center gap-2 text-sm font-medium text-[var(--foreground)]",children:[(0,s.jsx)(nP.A,{className:"h-4 w-4"}),(0,s.jsx)("span",{children:t.label||t.id}),0===t.enabled&&(0,s.jsx)("span",{className:"rounded bg-[var(--accent)] px-1.5 py-0.5 text-[10px] uppercase",children:o("cron.disabled")})]}),(0,s.jsxs)("div",{className:"flex items-center gap-1",children:[(0,s.jsxs)("button",{onClick:n,className:"flex items-center gap-1 rounded bg-emerald-600 px-2 py-1 text-xs text-white hover:opacity-90",title:o("cron.runNow"),children:[(0,s.jsx)(av.A,{className:"h-3 w-3"})," ",o("cron.runNow")]}),(0,s.jsxs)("button",{onClick:r,className:"flex items-center gap-1 rounded bg-[var(--accent)] px-2 py-1 text-xs text-[var(--foreground)] hover:opacity-90",title:o("cron.edit"),children:[(0,s.jsx)(a8.A,{className:"h-3 w-3"})," ",o("cron.edit")]}),(0,s.jsx)("button",{onClick:a,className:"flex items-center gap-1 rounded bg-red-700/80 px-2 py-1 text-xs text-white hover:opacity-90",title:o("cron.delete"),children:(0,s.jsx)(ej.A,{className:"h-3 w-3"})})]})]}),(0,s.jsxs)("div",{className:"mt-3 grid grid-cols-2 gap-2 text-xs text-[var(--muted-foreground)]",children:[t.runAt?(0,s.jsxs)("div",{children:[(0,s.jsx)("span",{className:"text-[var(--foreground)]",children:o("cron.field.runAt")})," ",(0,s.jsxs)("span",{className:"font-mono",children:[new Date(t.runAt).toLocaleString(),t.timezone?" (".concat(t.timezone,")"):""]})]}):(0,s.jsxs)("div",{children:[(0,s.jsx)("span",{className:"text-[var(--foreground)]",children:o("cron.field.schedule")})," ",(0,s.jsxs)("span",{className:"font-mono",children:[t.schedule,t.timezone?" (".concat(t.timezone,")"):""]})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("span",{className:"text-[var(--foreground)]",children:o("cron.field.agent")})," ",t.agentId]}),(0,s.jsxs)("div",{className:"col-span-2 truncate",children:[(0,s.jsx)("span",{className:"text-[var(--foreground)]",children:o("cron.field.workspace")})," ",t.workspacePath]}),(0,s.jsxs)("div",{className:"col-span-2",children:[(0,s.jsx)("span",{className:"text-[var(--foreground)]",children:o("cron.field.targets")})," ",0===t.targets.length?o("cron.field.targetsLogOnly"):t.targets.map(e=>"".concat(e.channelType,":").concat(e.accountId).concat(e.chatId?"/"+e.chatId:"")).join(", ")]})]}),(0,s.jsxs)("div",{className:"mt-2",children:[(0,s.jsx)("div",{className:"text-xs font-medium text-[var(--foreground)]",children:o("cron.field.prompt")}),(0,s.jsx)("pre",{className:"mt-1 whitespace-pre-wrap rounded bg-[var(--accent)] p-2 text-xs",children:t.userPrompt})]})]}),(0,s.jsxs)("div",{className:"flex-1 overflow-y-auto px-4 py-3",children:[(0,s.jsx)("div",{className:"mb-2 text-xs font-medium text-[var(--foreground)]",children:o("cron.runHistory")}),0===i.length?(0,s.jsx)("div",{className:"text-xs italic text-[var(--muted-foreground)]",children:o("cron.noRuns")}):(0,s.jsx)(s.Fragment,{children:(0,s.jsxs)("ul",{className:"divide-y divide-[var(--border)] text-xs",children:[i.map(e=>(0,s.jsxs)("li",{className:"py-2",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:D("rounded px-1.5 py-0.5 text-[10px] uppercase","succeeded"===e.status?"bg-emerald-700 text-emerald-50":"running"===e.status?"bg-amber-700 text-amber-50":"skipped"===e.status?"bg-[var(--accent)] text-[var(--foreground)]":"bg-red-700 text-red-50"),children:e.status}),(0,s.jsx)("span",{className:"text-[var(--muted-foreground)]",children:new Date(e.startedAt).toLocaleString()}),(0,s.jsx)("span",{className:"text-[var(--muted-foreground)]",children:"\xb7"}),(0,s.jsx)("span",{className:"text-[var(--muted-foreground)]",children:e.triggerKind})]}),(0,s.jsx)("button",{onClick:()=>{S(e.id)},className:"rounded bg-[var(--accent)] px-2 py-0.5 text-[10px] hover:opacity-90",children:"Log"})]}),e.failureReason&&(0,s.jsx)("div",{className:"mt-1 text-red-400",children:nR(e.failureReason,o)}),e.dispatchResults&&e.dispatchResults.length>0&&(0,s.jsxs)("div",{className:"mt-1 text-[var(--muted-foreground)]",children:[o("cron.dispatch")," ",e.dispatchResults.map(e=>{let t=e.chatId?"".concat(e.channelType,":").concat(e.accountId,"/").concat(e.chatId):"".concat(e.channelType,":").concat(e.accountId);return"".concat(t," ").concat(e.ok?"✓":"✗ (".concat(nR(e.error,o),")"))}).join(" \xb7 ")]}),e.output&&(0,s.jsx)("pre",{className:"mt-1 line-clamp-3 whitespace-pre-wrap rounded bg-[var(--accent)] p-2 text-[11px]",children:e.output})]},e.id)),f&&(0,s.jsx)("li",{ref:k,className:"py-3 text-center text-[10px] text-[var(--muted-foreground)]",children:b?o("cron.loading"):o("cron.loadOlder")})]})})]}),d&&(0,s.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4",onClick:()=>u(null),children:(0,s.jsxs)("div",{className:"flex h-[80vh] w-[800px] max-w-full flex-col overflow-hidden rounded border border-[var(--border)] bg-[var(--background)]",onClick:e=>e.stopPropagation(),children:[(0,s.jsxs)("div",{className:"flex items-center justify-between border-b border-[var(--border)] px-3 py-2 text-xs",children:[(0,s.jsx)("span",{children:o("cron.log.title",{id:d})}),(0,s.jsx)("button",{onClick:()=>u(null),className:"rounded px-2 py-0.5 text-[var(--muted-foreground)] hover:bg-[var(--accent)]",children:o("cron.log.close")})]}),(0,s.jsx)("pre",{className:"flex-1 overflow-auto whitespace-pre-wrap p-3 font-mono text-[11px] leading-relaxed",children:p?o("cron.loading"):null!=x?x:""})]})})]})}function nO(e){let t=e=>e.toString().padStart(2,"0");return"".concat(e.getFullYear(),"-").concat(t(e.getMonth()+1),"-").concat(t(e.getDate()),"T").concat(t(e.getHours()),":").concat(t(e.getMinutes()))}function nW(e){var t,r,a,n,o,i;let{initial:c,onClose:d,onSaved:u}=e,x=(0,tr.useT)(),m=e9(e=>e.activeProject),[p,h]=(0,l.useState)(null!=(t=null==c?void 0:c.label)?t:""),[f,g]=(0,l.useState)(null!=(a=null!=(r=null==c?void 0:c.workspacePath)?r:null==m?void 0:m.path)?a:""),[b,j]=(0,l.useState)(null!=(n=null==c?void 0:c.agentId)?n:"default"),[y,w]=(0,l.useState)([]),[N,k]=(0,l.useState)((null==c?void 0:c.runAt)?"oneShot":"recurring"),[S,C]=(0,l.useState)((null==c?void 0:c.schedule)||"0 9 * * *"),[A,I]=(0,l.useState)(()=>(null==c?void 0:c.runAt)?nO(new Date(c.runAt)):nO(new Date(Date.now()+36e5))),[E,T]=(0,l.useState)(()=>(function(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC"}catch(e){return"UTC"}})());(0,l.useEffect)(()=>{let e=!0;return v.F.cron.meta().then(t=>{let{hostTimezone:r}=t;e&&r&&T(r)}).catch(e=>console.error("cron.meta",e)),()=>{e=!1}},[]);let F=(0,l.useMemo)(()=>{let e=function(){let e=Intl;if("function"==typeof e.supportedValuesOf)try{return e.supportedValuesOf("timeZone")}catch(e){}return["UTC","Asia/Shanghai","Asia/Tokyo","Asia/Singapore","Europe/London","Europe/Paris","America/New_York","America/Los_Angeles"]}(),t=e.includes(E)?E:e[0];return[{id:t,label:"".concat(t," (default)")},...e.filter(e=>e!==t).map(e=>({id:e,label:e}))]},[E]),[M,P]=(0,l.useState)(null!=(o=null==c?void 0:c.timezone)?o:""),[L,R]=(0,l.useState)(null!=(i=null==c?void 0:c.userPrompt)?i:""),[z,_]=(0,l.useState)((null==c?void 0:c.enabled)!==0),[O,W]=(0,l.useState)([]),[U,B]=(0,l.useState)(()=>{var e;let t=new Set;for(let r of null!=(e=null==c?void 0:c.targets)?e:[])t.add("".concat(r.channelType,":").concat(r.accountId));return t}),[H,K]=(0,l.useState)(()=>{var e;let t={};for(let r of null!=(e=null==c?void 0:c.targets)?e:[]){let e="".concat(r.channelType,":").concat(r.accountId);r.chatId&&(t[e]=t[e]?"".concat(t[e],", ").concat(r.chatId):r.chatId)}return t}),[G,J]=(0,l.useState)(!1),[q,Z]=(0,l.useState)(null);(0,l.useEffect)(()=>{let e=!0,t=async()=>{try{let{agents:t}=await v.F.agentConfigs.list(f||void 0);if(!e)return;let r=t.filter(e=>!e.id.startsWith("__")&&!e.overridden&&!e.disabled).map(e=>({id:e.id,name:e.name||e.id}));w(r),r.length>0&&!r.some(e=>e.id===b)&&j(r[0].id)}catch(e){console.error("agentConfigs.list",e)}};return f&&t(),()=>{e=!1}},[f,b]),(0,l.useEffect)(()=>{let e=!0;return v.F.cron.listChannelTargets().then(t=>{let{targets:r}=t;e&&W(r)}).catch(e=>console.error("listChannelTargets",e)),()=>{e=!1}},[]);let V=(0,l.useCallback)(e=>{B(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},[]),Y=(0,l.useCallback)((e,t)=>{let r=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})$/.exec(e);if(!r)return Date.parse(e);let[,a,n,s,l,o]=r,i=Date.UTC(+a,n-1,+s,+l,+o),c=Object.fromEntries(new Intl.DateTimeFormat("en-US",{timeZone:t,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1}).formatToParts(new Date(i)).filter(e=>"literal"!==e.type).map(e=>[e.type,e.value]));return i-(Date.UTC(+c.year,c.month-1,+c.day,24==+c.hour?0:+c.hour,+c.minute,+c.second)-i)},[]),$=(0,l.useCallback)(async()=>{if(Z(null),!f.trim())return void Z(x("cron.form.err.workspace"));if(!b.trim())return void Z(x("cron.form.err.agent"));if("recurring"===N&&!S.trim())return void Z(x("cron.form.err.schedule"));if("oneShot"===N&&!A)return void Z(x("cron.form.err.runAt"));if(!L.trim())return void Z(x("cron.form.err.prompt"));let e=M||E,t="oneShot"===N?Y(A,e):void 0;if("oneShot"===N&&void 0!==t&&t<=Date.now())return void Z(x("cron.form.err.runAtPast"));let r=[];for(let e of U){var a;let[t,n]=e.split(":"),s=(null!=(a=H[e])?a:"").trim(),l=s?s.split(",").map(e=>e.trim()).filter(Boolean):[],o=e=>"slack"!==t||/^[DCG][A-Z0-9]+(:[\d.]+)?$/.test(e)?"feishu"!==t||/^oc_[a-zA-Z0-9]+(:[a-zA-Z0-9_-]+)?$/.test(e)?"telegram"!==t||/^-?\d+$/.test(e)?null:"Telegram chatId 必须是数字(私聊 = user id)。「".concat(e,"」无效。"):"飞书 chatId 格式错误:「".concat(e,"」。应该是 oc_…。请用搜索后点击建议项填入。"):"Slack chatId 格式错误:「".concat(e,"」。应该是 D…(DM) / C…(频道) / G…(私有频道)。请用搜索后点击建议项填入,或从 Slack URL 复制。");for(let e of l){let t=o(e);if(t)return void Z(t)}if(0===l.length)r.push({channelType:t,accountId:n});else for(let e of l)r.push({channelType:t,accountId:n,chatId:e})}J(!0);try{let e={label:p||void 0,workspacePath:f,agentId:b,userPrompt:L,timezone:M||void 0,targets:r,enabled:z};c?await v.F.cron.updateJob(c.id,{...e,schedule:"recurring"===N?S:"",runAt:"oneShot"===N?t:null}):await v.F.cron.createJob({...e,schedule:"recurring"===N?S:"",runAt:"oneShot"===N?t:void 0}),u()}catch(e){Z(e instanceof Error?e.message:String(e))}finally{J(!1)}},[c,p,f,b,L,N,S,A,M,E,Y,U,H,z,u,x]);return(0,s.jsxs)("div",{className:"jsx-8283b0ed0bcf6928 flex h-full flex-col",children:[(0,s.jsxs)("div",{className:"jsx-8283b0ed0bcf6928 flex items-center justify-between border-b border-[var(--border)] px-4 py-3",children:[(0,s.jsx)("div",{className:"jsx-8283b0ed0bcf6928 text-sm font-medium",children:c?x("cron.form.edit"):x("cron.form.create")}),(0,s.jsx)("button",{onClick:d,className:"jsx-8283b0ed0bcf6928 rounded px-2 py-1 text-xs text-[var(--muted-foreground)] hover:bg-[var(--accent)]",children:x("cron.form.cancel")})]}),(0,s.jsxs)("div",{className:"jsx-8283b0ed0bcf6928 flex-1 space-y-3 overflow-y-auto p-4 text-xs",children:[(0,s.jsx)(nU,{label:x("cron.form.label"),children:(0,s.jsx)("input",{value:p,onChange:e=>h(e.target.value),placeholder:x("cron.form.label.placeholder"),className:"jsx-8283b0ed0bcf6928 input-base"})}),(0,s.jsx)(nU,{label:x("cron.form.workspace"),children:(0,s.jsx)("input",{value:f,onChange:e=>g(e.target.value),placeholder:x("cron.form.workspace.placeholder"),className:"jsx-8283b0ed0bcf6928 input-base font-mono"})}),(0,s.jsx)(nU,{label:x("cron.form.agent"),children:(0,s.jsxs)("select",{value:b,onChange:e=>j(e.target.value),className:"jsx-8283b0ed0bcf6928 input-base",children:[0===y.length&&(0,s.jsx)("option",{value:"default",className:"jsx-8283b0ed0bcf6928",children:"default"}),y.map(e=>(0,s.jsxs)("option",{value:e.id,className:"jsx-8283b0ed0bcf6928",children:[e.name," (",e.id,")"]},e.id))]})}),(0,s.jsx)(nU,{label:x("cron.form.mode"),children:(0,s.jsxs)("div",{className:"jsx-8283b0ed0bcf6928 flex gap-3",children:[(0,s.jsxs)("label",{className:"jsx-8283b0ed0bcf6928 flex cursor-pointer items-center gap-1",children:[(0,s.jsx)("input",{type:"radio",name:"cron-mode",value:"recurring",checked:"recurring"===N,onChange:()=>k("recurring"),className:"jsx-8283b0ed0bcf6928"}),(0,s.jsx)("span",{className:"jsx-8283b0ed0bcf6928",children:x("cron.form.mode.recurring")})]}),(0,s.jsxs)("label",{className:"jsx-8283b0ed0bcf6928 flex cursor-pointer items-center gap-1",children:[(0,s.jsx)("input",{type:"radio",name:"cron-mode",value:"oneShot",checked:"oneShot"===N,onChange:()=>k("oneShot"),className:"jsx-8283b0ed0bcf6928"}),(0,s.jsx)("span",{className:"jsx-8283b0ed0bcf6928",children:x("cron.form.mode.oneShot")})]})]})}),"recurring"===N?(0,s.jsxs)(nU,{label:x("cron.form.schedule"),children:[(0,s.jsx)("input",{value:S,onChange:e=>C(e.target.value),placeholder:x("cron.form.schedule.placeholder"),className:"jsx-8283b0ed0bcf6928 input-base font-mono"}),(0,s.jsx)("div",{className:"jsx-8283b0ed0bcf6928 mt-1 text-[10px] text-[var(--muted-foreground)]",children:x("cron.form.schedule.hint")})]}):(0,s.jsxs)(nU,{label:x("cron.form.runAt"),children:[(0,s.jsx)("input",{type:"datetime-local",value:A,onChange:e=>I(e.target.value),className:"jsx-8283b0ed0bcf6928 input-base font-mono"}),(0,s.jsx)("div",{className:"jsx-8283b0ed0bcf6928 mt-1 text-[10px] text-[var(--muted-foreground)]",children:x("cron.form.runAt.hint")})]}),(0,s.jsx)(nU,{label:x("cron.form.timezone"),children:(0,s.jsx)(ab,{value:M||E,placeholder:x("cron.form.timezone.hostDefault",{tz:E}),presets:F,onCommit:e=>{P(e===E?"":e)},minWidth:280})}),(0,s.jsx)(nU,{label:x("cron.form.userPrompt"),children:(0,s.jsx)("textarea",{value:L,onChange:e=>R(e.target.value),rows:5,placeholder:x("cron.form.userPrompt.placeholder"),className:"jsx-8283b0ed0bcf6928 input-base"})}),(0,s.jsx)(nU,{label:x("cron.form.targets"),children:(0,s.jsxs)("div",{className:"jsx-8283b0ed0bcf6928 space-y-1 rounded border border-[var(--border)] p-2",children:[0===O.length?(0,s.jsx)("div",{className:"jsx-8283b0ed0bcf6928 text-[var(--muted-foreground)]",children:x("cron.form.targets.empty")}):O.map(e=>{var t;let r="".concat(e.channelType,":").concat(e.accountId),a=U.has(r),n="wechat"!==e.channelType,l="slack"===e.channelType?"D… (DM) / C… (channel) / C…:1700.0 (thread)":"telegram"===e.channelType?"数字 chat id(私聊 = user id)":"feishu"===e.channelType?"oc_… 聊天 id":"";return(0,s.jsxs)("div",{className:"jsx-8283b0ed0bcf6928 "+(D("rounded px-1 py-0.5",a&&"bg-[var(--accent)]")||""),children:[(0,s.jsxs)("label",{className:"jsx-8283b0ed0bcf6928 flex cursor-pointer items-center gap-2",children:[(0,s.jsx)("input",{type:"checkbox",checked:a,onChange:()=>V(r),disabled:!e.enabled,className:"jsx-8283b0ed0bcf6928"}),(0,s.jsx)("span",{className:"jsx-8283b0ed0bcf6928 font-medium",children:e.channelType}),(0,s.jsx)("span",{className:"jsx-8283b0ed0bcf6928",children:e.label}),!e.enabled&&(0,s.jsx)("span",{className:"jsx-8283b0ed0bcf6928 text-[10px] text-[var(--muted-foreground)]",children:x("cron.form.targets.disabled")}),!e.hasActiveChat&&(0,s.jsx)("span",{title:x("cron.form.targets.noActiveChat"),className:"jsx-8283b0ed0bcf6928 text-[10px] text-amber-400",children:x("cron.form.targets.noActiveChatLabel")})]}),a&&n&&(0,s.jsxs)("div",{className:"jsx-8283b0ed0bcf6928 mt-1 ml-6",children:[(0,s.jsx)(nB,{channelType:e.channelType,accountId:e.accountId,value:null!=(t=H[r])?t:"",onChange:e=>K(t=>({...t,[r]:e})),placeholder:l}),(0,s.jsx)("div",{className:"jsx-8283b0ed0bcf6928 mt-0.5 text-[10px] text-[var(--muted-foreground)]",children:"多个 chat 用逗号分隔。留空则不推送(仅写日志)。"})]})]},r)}),(0,s.jsx)("div",{className:"jsx-8283b0ed0bcf6928 mt-1 text-[10px] text-[var(--muted-foreground)]",children:x("cron.form.targets.hint")})]})}),(0,s.jsxs)("label",{className:"jsx-8283b0ed0bcf6928 flex items-center gap-2",children:[(0,s.jsx)("input",{type:"checkbox",checked:z,onChange:e=>_(e.target.checked),className:"jsx-8283b0ed0bcf6928"}),(0,s.jsx)("span",{className:"jsx-8283b0ed0bcf6928",children:x("cron.form.enabled")})]}),q&&(0,s.jsx)("div",{className:"jsx-8283b0ed0bcf6928 rounded border border-red-500/50 bg-red-950/40 p-2 text-red-300",children:q})]}),(0,s.jsxs)("div",{className:"jsx-8283b0ed0bcf6928 flex justify-end gap-2 border-t border-[var(--border)] px-4 py-3",children:[(0,s.jsx)("button",{onClick:d,className:"jsx-8283b0ed0bcf6928 rounded bg-[var(--accent)] px-3 py-1 text-xs",children:x("cron.form.cancel")}),(0,s.jsx)("button",{onClick:()=>{$()},disabled:G,className:"jsx-8283b0ed0bcf6928 rounded bg-[var(--primary)] px-3 py-1 text-xs text-[var(--primary-foreground)] disabled:opacity-50",children:G?x("cron.form.saving"):c?x("cron.form.save"):x("cron.form.create.btn")})]}),(0,s.jsx)(nM(),{id:"8283b0ed0bcf6928",children:".input-base{width:100%;background:var(--background);color:var(--foreground);border:1px solid var(--border);border-radius:.25rem;padding:.375rem .5rem;font-size:.75rem}"})]})}function nU(e){let{label:t,children:r}=e;return(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"mb-1 block text-[var(--foreground)]",children:t}),r]})}function nB(e){let{channelType:t,accountId:r,value:a,onChange:n,placeholder:o}=e,[i,c]=(0,l.useState)(""),[d,u]=(0,l.useState)([]),[x,m]=(0,l.useState)(!1),[p,h]=(0,l.useState)(!1),f="slack"===t||"feishu"===t;return(0,l.useEffect)(()=>{if(!f||!i.trim())return void u([]);let e=!1;h(!0);let a=setTimeout(async()=>{try{let a="slack"===t?await v.F.slack.searchTargets(r,i):await v.F.feishu.searchTargets(r,i);if(e)return;let n=a.hits.map(e=>{var t,r;let a=null!=(r=null!=(t=e.realName)?t:e.email)?r:"";return{id:e.id,name:e.name,chatId:e.chatId,kind:e.kind,subtitle:a}});u(n)}catch(t){e||u([]),console.error("[cron-form] target search failed:",t)}finally{e||h(!1)}},300);return()=>{e=!0,clearTimeout(a)}},[i,t,r,f]),(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsx)("input",{value:a,onChange:e=>(function(e){var t,r;if(n(e),!f)return;let a=null!=(r=null==(t=e.split(",").pop())?void 0:t.trim())?r:"";c(a),m(a.length>0)})(e.target.value),onFocus:()=>{i&&m(!0)},onBlur:()=>setTimeout(()=>m(!1),150),placeholder:o,className:"input-base font-mono text-[11px]"}),f&&x&&(p||d.length>0)&&(0,s.jsxs)("div",{className:"absolute z-10 mt-1 max-h-60 w-full overflow-y-auto rounded border border-[var(--border)] bg-[var(--background)] shadow-lg",children:[p&&(0,s.jsx)("div",{className:"px-2 py-1 text-[10px] text-[var(--muted-foreground)]",children:"搜索中…"}),!p&&d.map(e=>(0,s.jsxs)("button",{type:"button",onMouseDown:e=>e.preventDefault(),onClick:()=>(function(e){let t=a.split(",").map(e=>e.trim()).filter(Boolean);t.length>0?t[t.length-1]=e:t.push(e),n(t.join(", ")),c(""),u([]),m(!1)})(e.chatId),className:"flex w-full items-center gap-2 px-2 py-1 text-left text-[11px] hover:bg-[var(--accent)]",children:[(0,s.jsx)("span",{className:"text-[var(--muted-foreground)]",children:function(e){switch(e){case"user":return"@";case"channel":case"chat":return"#";case"group":return"\uD83D\uDD12";case"mpim":return"\uD83D\uDC65";case"im":case"p2p":return"\uD83D\uDCAC";default:return"\xb7"}}(e.kind)}),(0,s.jsxs)("span",{className:"flex-1 truncate",children:[e.name,e.subtitle&&(0,s.jsx)("span",{className:"ml-1 text-[10px] text-[var(--muted-foreground)]",children:e.subtitle})]}),(0,s.jsx)("span",{className:"font-mono text-[10px] text-[var(--muted-foreground)]",children:e.chatId})]},e.kind+":"+e.id))]})]})}function nH(){let e=(0,tr.useT)(),[t,r]=(0,l.useState)([]),[a,n]=(0,l.useState)(!0),[o,i]=(0,l.useState)(null),[c,d]=(0,l.useState)(!1),[u,x]=(0,l.useState)(null),[m,p]=(0,l.useState)(!1),h=nL(e=>e.selectedId),f=nL(e=>e.setSelectedId),g=nL(e=>e.openCreate),b=(0,l.useCallback)(async()=>{try{let e=await v.F.cron.listJobs({limit:20});r(e.jobs),x(e.hasMore?e.nextCursor:null),i(null)}catch(e){i(e instanceof Error?e.message:String(e))}finally{n(!1)}},[]),y=(0,l.useCallback)(async()=>{if(u&&!m){p(!0);try{let e=await v.F.cron.listJobs({limit:20,before:u});r(t=>[...t,...e.jobs]),x(e.hasMore?e.nextCursor:null)}catch(e){console.error("cron.listJobs more",e)}finally{p(!1)}}},[u,m]),w=(0,l.useRef)(null);(0,l.useEffect)(()=>{let e=w.current;if(!e||"undefined"==typeof IntersectionObserver)return;let t=new IntersectionObserver(e=>{var t;(null==(t=e[0])?void 0:t.isIntersecting)&&y()},{rootMargin:"64px"});return t.observe(e),()=>t.disconnect()},[y,t.length]);let N=(0,l.useCallback)(async()=>{d(!0);let e=new Promise(e=>setTimeout(e,400));await Promise.all([b(),e]),d(!1)},[b]);return(0,l.useEffect)(()=>{b()},[b]),(0,l.useEffect)(()=>{let e=j.on("cron:job_changed",()=>{b()}),t=j.on("cron:run_changed",()=>{b()});return()=>{e(),t()}},[b]),(0,l.useEffect)(()=>{!h&&t[0]&&f(t[0].id)},[t,h,f]),(0,s.jsxs)("div",{className:"flex h-full flex-col border-r border-[var(--border)] bg-[var(--background)]",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between gap-2 border-b border-[var(--border)] px-3 py-2",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 text-sm font-medium text-[var(--foreground)]",children:[(0,s.jsx)(nP.A,{className:"h-4 w-4"}),e("cron.title")]}),(0,s.jsxs)("div",{className:"flex items-center gap-1",children:[(0,s.jsxs)("button",{onClick:g,className:"flex items-center gap-1 rounded bg-[var(--primary)] px-2 py-1 text-xs text-[var(--primary-foreground)] hover:opacity-90",title:e("cron.new"),children:[(0,s.jsx)(rA.A,{className:"h-3 w-3"})," ",e("cron.new")]}),(0,s.jsx)("button",{onClick:()=>{N()},disabled:c,className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--accent)] hover:text-[var(--foreground)] disabled:cursor-default",title:e("cron.refresh"),children:(0,s.jsx)(r5.A,{className:D("h-3.5 w-3.5",c&&"animate-spin")})})]})]}),(0,s.jsx)("div",{className:"flex-1 overflow-y-auto",children:a&&0===t.length?(0,s.jsx)("div",{className:"px-3 py-4 text-xs text-[var(--muted-foreground)]",children:e("cron.loading")}):o?(0,s.jsx)("div",{className:"px-3 py-4 text-xs text-red-400",children:e("cron.error",{error:o})}):0===t.length?(0,s.jsx)("div",{className:"px-3 py-4 text-xs text-[var(--muted-foreground)]",children:e("cron.empty")}):(0,s.jsxs)("ul",{className:"divide-y divide-[var(--border)]",children:[t.map(t=>{let r=h===t.id,a=t.lastRunStatus;return(0,s.jsxs)("li",{className:D("cursor-pointer px-3 py-2 text-xs hover:bg-[var(--accent)]",r&&"bg-[var(--accent)]"),onClick:()=>f(t.id),children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:D("inline-block h-2 w-2 rounded-full",0===t.enabled?"bg-[var(--muted-foreground)]":"succeeded"===a?"bg-emerald-500":"running"===a?"bg-amber-400 animate-pulse":"failed"===a||"timeout"===a?"bg-red-500":"bg-[var(--muted-foreground)]")}),(0,s.jsx)("span",{className:"truncate font-medium text-[var(--foreground)]",children:t.label||t.id})]}),(0,s.jsxs)("div",{className:"mt-1 flex items-center justify-between gap-2 text-[var(--muted-foreground)]",children:[(0,s.jsx)("span",{className:"font-mono",children:t.runAt?new Date(t.runAt).toLocaleString():t.schedule}),(0,s.jsx)("span",{children:t.agentId})]}),(0,s.jsx)("div",{className:"mt-0.5 truncate text-[var(--muted-foreground)]",children:t.workspacePath}),t.nextRunAt&&1===t.enabled&&(0,s.jsxs)("div",{className:"mt-0.5 text-[var(--muted-foreground)]",children:[e("cron.next")," ",new Date(t.nextRunAt).toLocaleString()]})]},t.id)}),u&&(0,s.jsx)("li",{ref:e=>{w.current=e},className:"px-3 py-3 text-center text-[10px] text-[var(--muted-foreground)]",children:m?e("cron.loading"):e("cron.loadOlder")})]})})]})}var nK=r(9207),nG=r(16374),nJ=r(48403),nq=r(16981),nZ=r(81616),nV=r(71008);let nY=(0,c.v)(e=>({selected:null,select:t=>e({selected:t}),clear:()=>e({selected:null})}));function n$(e){let{files:t,group:r,selectedPath:a,onSelect:n,onAction:o}=e,[i,c]=(0,l.useState)(new Set),d=function(e,t){let r={type:"dir",name:"",path:"",children:[]};for(let a of e){let e=a.path.split("/"),n=r;for(let t=0;t<e.length-1;t++){let r=e[t],a=n.path?"".concat(n.path,"/").concat(r):r,s=n.children.find(e=>"dir"===e.type&&e.name===r);s||(s={type:"dir",name:r,path:a,children:[]},n.children.push(s)),n=s}n.children.push({type:"file",name:e[e.length-1],file:a,char:t(a)})}return function e(t){for(let r of t.children)"dir"===r.type&&e(r);for(;1===t.children.length&&"dir"===t.children[0].type&&""!==t.name;){let e=t.children[0];t.name="".concat(t.name,"/").concat(e.name),t.path=e.path,t.children=e.children}}(r),function e(t){for(let r of(t.children.sort((e,t)=>e.type!==t.type?"dir"===e.type?-1:1:e.name.localeCompare(t.name)),t.children))"dir"===r.type&&e(r)}(r),r.children}(t,e=>"staged"===r?e.index:e.workingDir);return(0,s.jsx)("div",{children:d.map(e=>(function e(t,l){let d=12*l+8;if("dir"===t.type){let r=i.has(t.path);return(0,s.jsxs)("div",{children:[(0,s.jsxs)("button",{onClick:()=>{var e;return e=t.path,void c(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},className:"flex w-full items-center gap-1 py-0.5 text-xs text-[var(--muted-foreground)] hover:text-[var(--foreground)]",style:{paddingLeft:"".concat(d,"px")},children:[r?(0,s.jsx)(U.A,{className:"h-3.5 w-3.5 shrink-0"}):(0,s.jsx)(W.A,{className:"h-3.5 w-3.5 shrink-0"}),(0,s.jsx)("span",{className:"truncate",children:t.name})]}),!r&&t.children.map(t=>e(t,l+1))]},"d:".concat(t.path))}let u=S(t.char),x=a===t.file.path,m="staged"===r?nV.A:rA.A,{Icon:p,color:h}=ec(t.file.path);return(0,s.jsxs)("div",{onClick:()=>n(t.file),className:D("group flex w-full cursor-pointer items-center gap-1.5 py-0.5 pr-2 text-xs",x?"bg-[var(--accent)]":"hover:bg-[var(--accent)]"),style:{paddingLeft:"".concat(d+16,"px")},children:[(0,s.jsx)(p,{className:D("h-3.5 w-3.5 shrink-0",h)}),(0,s.jsx)("span",{className:"truncate text-[var(--foreground)]",style:{color:u.color},children:t.name}),(0,s.jsx)("div",{className:"flex-1"}),(0,s.jsx)("button",{onClick:e=>{e.stopPropagation(),o([t.file.path])},title:"staged"===r?"Unstage":"Stage",className:"hidden shrink-0 rounded p-0.5 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)] group-hover:block",children:(0,s.jsx)(m,{className:"h-3.5 w-3.5"})}),(0,s.jsx)("span",{className:"w-4 shrink-0 text-center font-mono text-[11px] font-semibold",style:{color:u.color},title:u.label,children:u.letter})]},"f:".concat(t.file.path))})(e,0))})}var nQ=r(35930),nX=r(77271),n0=r(93374);function n1(e){let{projectId:t,onClose:r,onSaved:a}=e,n=(0,tr.useT)(),[o,i]=(0,l.useState)("https");return(0,s.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60",onClick:r,children:(0,s.jsxs)("div",{className:"w-[460px] rounded-lg border border-[var(--border)] bg-[var(--background)] shadow-xl",onClick:e=>e.stopPropagation(),children:[(0,s.jsxs)("div",{className:"flex items-center justify-between border-b border-[var(--border)] px-4 py-2.5",children:[(0,s.jsx)("h3",{className:"text-sm font-medium text-[var(--foreground)]",children:n("sc.cred.title")}),(0,s.jsx)("button",{onClick:r,className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)]",children:(0,s.jsx)(eK.A,{className:"h-4 w-4"})})]}),(0,s.jsx)("div",{className:"flex gap-1 border-b border-[var(--border)] px-4 pt-3",children:["https","ssh"].map(e=>(0,s.jsx)("button",{onClick:()=>i(e),className:D("rounded-t px-3 py-1.5 text-xs font-medium",o===e?"bg-[var(--secondary)] text-[var(--foreground)]":"text-[var(--muted-foreground)] hover:text-[var(--foreground)]"),children:"https"===e?n("sc.cred.tabHttps"):n("sc.cred.tabSsh")},e))}),"https"===o?(0,s.jsx)(n3,{onClose:r,onSaved:a}):(0,s.jsx)(n2,{projectId:t,onClose:r})]})})}let n5="rounded border border-[var(--border)] bg-[var(--secondary)] px-2 py-1.5 text-xs text-[var(--foreground)] outline-none focus:border-[var(--primary)]";function n3(e){let{onClose:t,onSaved:r}=e,a=(0,tr.useT)(),[n,o]=(0,l.useState)([]),[i,c]=(0,l.useState)(null),[d,u]=(0,l.useState)("github.com"),[x,m]=(0,l.useState)(""),[p,h]=(0,l.useState)(""),[f,g]=(0,l.useState)(!1),[b,j]=(0,l.useState)(null),y=(0,l.useCallback)(()=>{v.F.git.getCredentials().then(e=>o(e.credentials)).catch(()=>o([]))},[]);async function w(){if(!d.trim()||!x.trim()||!p)return void j(a("sc.cred.required"));g(!0),j(null);try{await v.F.git.saveCredentials({host:d.trim(),username:x.trim(),token:p}),h(""),y(),r()}catch(e){j(e instanceof Error?e.message:String(e))}finally{g(!1)}}async function N(e){j(null);try{await v.F.git.deleteCredential(e),y()}catch(e){j(e instanceof Error?e.message:String(e))}finally{c(null)}}return(0,l.useEffect)(()=>{y()},[y]),(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:"flex max-h-[420px] flex-col gap-3 overflow-y-auto px-4 py-4",children:[(0,s.jsx)("p",{className:"text-xs text-[var(--muted-foreground)]",children:a("sc.cred.httpsDesc")}),(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,s.jsx)("span",{className:"text-xs text-[var(--muted-foreground)]",children:a("sc.cred.configuredList")}),0===n.length?(0,s.jsx)("p",{className:"rounded border border-dashed border-[var(--border)] px-2 py-3 text-center text-[10px] text-[var(--muted-foreground)]",children:a("sc.cred.noCredsYet")}):n.map(e=>(0,s.jsxs)("div",{className:"flex items-center gap-2 rounded border border-[var(--border)] px-2.5 py-1.5 text-xs",children:[(0,s.jsx)("span",{className:"h-2 w-2 shrink-0 rounded-full bg-emerald-400"}),(0,s.jsxs)("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[(0,s.jsx)("span",{className:"truncate text-[var(--foreground)]",children:e.host}),(0,s.jsx)("span",{className:"truncate text-[10px] text-[var(--muted-foreground)]",children:e.username})]}),i===e.host?(0,s.jsx)("button",{onClick:()=>N(e.host),className:"shrink-0 rounded bg-red-500/15 px-2 py-0.5 text-[10px] font-medium text-red-400 hover:bg-red-500/25",children:a("sc.cred.confirmDelete")}):(0,s.jsx)("button",{onClick:()=>c(e.host),title:a("sc.cred.delete"),className:"shrink-0 rounded p-1 text-[var(--muted-foreground)] hover:text-red-400",children:(0,s.jsx)(ej.A,{className:"h-3 w-3"})})]},e.host))]}),(0,s.jsx)("div",{className:"border-t border-[var(--border)]"}),(0,s.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,s.jsx)("span",{className:"text-xs text-[var(--muted-foreground)]",children:a("sc.cred.addNew")}),(0,s.jsxs)("label",{className:"flex flex-col gap-1",children:[(0,s.jsx)("span",{className:"text-xs text-[var(--muted-foreground)]",children:a("sc.cred.host")}),(0,s.jsx)("input",{type:"text",value:d,onChange:e=>u(e.target.value),placeholder:"github.com",className:n5})]}),(0,s.jsxs)("label",{className:"flex flex-col gap-1",children:[(0,s.jsx)("span",{className:"text-xs text-[var(--muted-foreground)]",children:a("sc.cred.username")}),(0,s.jsx)("input",{type:"text",value:x,onChange:e=>m(e.target.value),autoComplete:"off",className:n5})]}),(0,s.jsxs)("label",{className:"flex flex-col gap-1",children:[(0,s.jsx)("span",{className:"text-xs text-[var(--muted-foreground)]",children:a("sc.cred.token")}),(0,s.jsx)("input",{type:"password",value:p,onChange:e=>h(e.target.value),autoComplete:"new-password",className:n5}),(0,s.jsxs)("span",{className:"text-[10px] text-[var(--muted-foreground)]",children:[a("sc.cred.tokenHint")," ",(0,s.jsxs)("a",{href:"https://github.com/settings/tokens",target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-0.5 text-[var(--primary)] hover:underline",children:[a("sc.cred.tokenLink"),(0,s.jsx)(nQ.A,{className:"h-2.5 w-2.5"})]})]})]})]}),b&&(0,s.jsx)("p",{className:"text-xs text-red-400",children:b})]}),(0,s.jsxs)("div",{className:"flex items-center justify-end gap-2 border-t border-[var(--border)] px-3 py-2.5",children:[(0,s.jsx)("button",{onClick:t,className:"rounded px-3 py-1 text-xs font-medium text-[var(--muted-foreground)] hover:bg-[var(--secondary)]",children:a("sc.cred.cancel")}),(0,s.jsx)("button",{onClick:w,disabled:f,className:"rounded bg-[var(--primary)] px-3 py-1 text-xs font-medium text-[var(--primary-foreground)] hover:opacity-90 disabled:opacity-40",children:f?a("sc.cred.saving"):a("sc.cred.save")})]})]})}function n2(e){let{projectId:t,onClose:r}=e,a=(0,tr.useT)(),[n,o]=(0,l.useState)([]),[i,c]=(0,l.useState)(!1),[d,u]=(0,l.useState)([]),[x,m]=(0,l.useState)("other"),[p,h]=(0,l.useState)(""),[f,g]=(0,l.useState)(!1),[b,j]=(0,l.useState)(null),[y,w]=(0,l.useState)(null),[N,k]=(0,l.useState)(""),[S,C]=(0,l.useState)(!1),[A,I]=(0,l.useState)(null),E=(0,l.useCallback)(()=>{v.F.git.sshKeys().then(e=>o(e.keys)).catch(()=>o([])),v.F.git.sshAgent().then(e=>{c(e.agentRunning),u(e.loadedKeys)}).catch(()=>{}),v.F.git.getRemoteProtocol(t).then(e=>{m(e.protocol),h(e.url)}).catch(()=>{})},[t]);function T(){w(null),k(""),I(null)}async function F(e){C(!0),I(null);try{let r=await v.F.git.unlockSshKey({keyPath:e.path,passphrase:N});if(r.ok)T(),E();else{var t;I(null!=(t=r.error)?t:a("sc.cred.sshUnlockFailed"))}}catch(e){I(e instanceof Error?e.message:String(e))}finally{C(!1)}}async function M(e){g(!0),j(null);try{let r=await v.F.git.setRemoteProtocol(t,e);m(e),h(r.url)}catch(e){j(e instanceof Error?e.message:String(e))}finally{g(!1)}}return(0,l.useEffect)(()=>{E()},[E]),(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:"flex max-h-[420px] flex-col gap-3 overflow-y-auto px-4 py-4",children:[(0,s.jsx)("p",{className:"text-xs text-[var(--muted-foreground)]",children:a("sc.cred.sshDesc")}),(0,s.jsxs)("div",{className:"flex items-center gap-2 rounded bg-[var(--secondary)] px-2.5 py-1.5 text-xs",children:[(0,s.jsx)("span",{className:D("h-2 w-2 rounded-full",i?"bg-emerald-400":"bg-[var(--muted-foreground)]")}),(0,s.jsx)("span",{className:"text-[var(--muted-foreground)]",children:i?a("sc.cred.sshAgentOn",{count:String(d.length)}):a("sc.cred.sshAgentOff")}),(0,s.jsx)("button",{onClick:E,className:"ml-auto rounded p-0.5 text-[var(--muted-foreground)] hover:text-[var(--foreground)]",title:a("sc.cred.sshRefresh"),children:(0,s.jsx)(r5.A,{className:"h-3 w-3"})})]}),(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,s.jsx)("span",{className:"text-xs text-[var(--muted-foreground)]",children:a("sc.cred.sshKeys")}),0===n.length?(0,s.jsx)("p",{className:"rounded border border-dashed border-[var(--border)] px-2 py-3 text-center text-[10px] text-[var(--muted-foreground)]",children:a("sc.cred.sshNoKeys")}):n.map(e=>{let t=d.some(t=>t.includes(e.path)||t.includes(e.name)),r=y===e.path;return(0,s.jsxs)("div",{className:"rounded border border-[var(--border)]",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 px-2.5 py-1.5 text-xs",children:[e.encrypted?(0,s.jsx)(nX.A,{className:"h-3 w-3 shrink-0 text-amber-400"}):(0,s.jsx)(n0.A,{className:"h-3 w-3 shrink-0 text-[var(--muted-foreground)]"}),(0,s.jsx)("span",{className:"truncate text-[var(--foreground)]",children:e.name}),t?(0,s.jsx)("span",{className:"ml-auto text-[10px] text-emerald-400",children:a("sc.cred.sshLoaded")}):!r&&(0,s.jsx)("button",{onClick:()=>{w(e.path),k(""),I(null)},className:"ml-auto shrink-0 rounded bg-[var(--secondary)] px-2 py-0.5 text-[10px] font-medium text-[var(--foreground)] hover:opacity-90",children:a("sc.cred.sshUnlock")})]}),!t&&r&&(0,s.jsxs)("div",{className:"flex flex-col gap-1.5 border-t border-[var(--border)] px-2.5 py-2",children:[(0,s.jsx)("span",{className:"text-[10px] leading-relaxed text-[var(--muted-foreground)]",children:a("sc.cred.sshUnlockHint")}),(0,s.jsx)("input",{type:"password",autoFocus:!0,autoComplete:"off",value:N,onChange:e=>k(e.target.value),onKeyDown:t=>{"Enter"!==t.key||S||F(e)},placeholder:a("sc.cred.sshPassphrase"),className:n5}),A&&(0,s.jsx)("span",{className:"text-[10px] leading-relaxed text-red-400",children:A}),(0,s.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[(0,s.jsx)("button",{onClick:T,disabled:S,className:"rounded px-2 py-0.5 text-[10px] font-medium text-[var(--muted-foreground)] hover:bg-[var(--secondary)] disabled:opacity-40",children:a("sc.cred.cancel")}),(0,s.jsx)("button",{onClick:()=>F(e),disabled:S,className:"rounded bg-[var(--primary)] px-2 py-0.5 text-[10px] font-medium text-[var(--primary-foreground)] hover:opacity-90 disabled:opacity-40",children:S?a("sc.cred.sshUnlocking"):a("sc.cred.sshUnlock")})]})]})]},e.path)})]}),(0,s.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,s.jsx)("span",{className:"text-xs text-[var(--muted-foreground)]",children:a("sc.cred.sshRemote")}),(0,s.jsxs)("div",{className:"flex items-center gap-2 rounded bg-[var(--secondary)] px-2.5 py-1.5",children:[(0,s.jsx)("span",{className:"truncate text-[10px] text-[var(--muted-foreground)]",title:p,children:p||"—"}),(0,s.jsx)("div",{className:"ml-auto flex shrink-0 overflow-hidden rounded border border-[var(--border)]",children:["https","ssh"].map(e=>(0,s.jsx)("button",{onClick:()=>M(e),disabled:f||x===e,className:D("px-2 py-0.5 text-[10px] font-medium",x===e?"bg-[var(--primary)] text-[var(--primary-foreground)]":"text-[var(--muted-foreground)] hover:text-[var(--foreground)] disabled:opacity-40"),children:e.toUpperCase()},e))})]})]}),(0,s.jsx)("p",{className:"text-[10px] leading-relaxed text-[var(--muted-foreground)]",children:a("sc.cred.sshRestartNote")}),b&&(0,s.jsx)("p",{className:"text-xs text-red-400",children:b})]}),(0,s.jsx)("div",{className:"flex items-center justify-end gap-2 border-t border-[var(--border)] px-3 py-2.5",children:(0,s.jsx)("button",{onClick:r,className:"rounded px-3 py-1 text-xs font-medium text-[var(--muted-foreground)] hover:bg-[var(--secondary)]",children:a("sc.cred.close")})})]})}var n4=r(81540);function n8(e){return e.startsWith("HEAD -> ")?{kind:"head",label:e.slice(8)}:"HEAD"===e?{kind:"head",label:"HEAD"}:e.startsWith("tag: ")?{kind:"tag",label:e.slice(5)}:e.endsWith("/HEAD")?null:e.includes("/")?{kind:"remote",label:e}:{kind:"branch",label:e}}function n6(e){let{info:t}=e,r="tag"===t.kind?n4.A:nK.A,a="head"===t.kind?"bg-[var(--primary)] text-[var(--primary-foreground)] font-medium":"tag"===t.kind?"bg-amber-400/10 text-amber-300 ring-1 ring-inset ring-amber-400/30":"remote"===t.kind?"text-[var(--muted-foreground)] ring-1 ring-inset ring-[var(--border)]":"bg-[var(--secondary)] text-[var(--foreground)] ring-1 ring-inset ring-[var(--border)]";return(0,s.jsxs)("span",{className:D("inline-flex items-center gap-1 rounded px-1.5 py-px text-[10px] leading-tight",a),children:[(0,s.jsx)(r,{className:"h-2.5 w-2.5 shrink-0"}),(0,s.jsx)("span",{className:"truncate",children:t.label})]})}function n9(e){let{file:t,active:r,onSelect:a}=e,n=S(t.status),{Icon:l,color:o}=ec(t.path),{name:i,dir:c}=function(e){let t=e.lastIndexOf("/");return -1===t?{name:e,dir:""}:{name:e.slice(t+1),dir:e.slice(0,t)}}(t.path);return(0,s.jsxs)("button",{onClick:a,className:D("flex w-full items-center gap-1.5 py-0.5 pr-2 text-left text-xs",r?"bg-[var(--accent)]":"hover:bg-[var(--accent)]"),children:[(0,s.jsx)(l,{className:D("h-3.5 w-3.5 shrink-0",o)}),(0,s.jsx)("span",{className:"shrink-0 truncate",style:{color:n.color},children:i}),c&&(0,s.jsx)("span",{className:"truncate text-[10px] text-[var(--muted-foreground)]",children:c}),(0,s.jsx)("span",{className:"flex-1"}),(0,s.jsx)("span",{className:"w-4 shrink-0 text-center font-mono text-[11px] font-semibold",style:{color:n.color},title:n.label,children:n.letter})]})}function n7(e){let{projectId:t}=e,r=(0,tr.useT)(),a=nY(e=>e.select),n=nY(e=>e.selected),[o,i]=(0,l.useState)([]),[c,d]=(0,l.useState)(null),[u,x]=(0,l.useState)(!1),[m,p]=(0,l.useState)(null),[h,f]=(0,l.useState)(50),[g,b]=(0,l.useState)(!1),[y,w]=(0,l.useState)({}),N=(0,l.useRef)(null),k=(0,l.useCallback)(async()=>{try{let e=await v.F.git.log(t,h);i(e.commits),b(e.commits.length>=h),d(null)}catch(e){d(e instanceof Error?e.message:String(e))}finally{x(!0)}},[t,h]);(0,l.useEffect)(()=>{k()},[k]),(0,l.useEffect)(()=>{let e=null,t=j.on("file:changed",()=>{e&&clearTimeout(e),e=setTimeout(()=>{k()},400)});return()=>{e&&clearTimeout(e),t()}},[k]),(0,l.useEffect)(()=>{let e=N.current;if(!e||!g)return;let t=new IntersectionObserver(e=>{var t;(null==(t=e[0])?void 0:t.isIntersecting)&&f(e=>e+50)});return t.observe(e),()=>t.disconnect()},[g]);let S=(0,l.useCallback)(e=>{p(t=>t===e?null:e),w(r=>(r[e]||v.F.git.commitFiles(t,e).then(t=>w(r=>({...r,[e]:t.files}))).catch(()=>w(t=>({...t,[e]:[]}))),r))},[t]);return c?(0,s.jsx)("div",{className:"px-3 py-4 text-xs text-red-400",children:c}):u&&0===o.length?(0,s.jsx)("div",{className:"px-3 py-4 text-xs text-[var(--muted-foreground)]",children:r("sc.noCommits")}):(0,s.jsxs)("div",{className:"py-1",children:[o.map((e,t)=>{let l=0===t,o=m===e.hash,i=e.pushed?"var(--muted-foreground)":"var(--primary)",c=y[e.hash],d=e.refs?e.refs.split(",").map(e=>e.trim()).filter(Boolean).map(n8).filter(e=>null!==e):[];return(0,s.jsxs)("div",{className:"flex px-3",children:[(0,s.jsxs)("div",{className:"relative shrink-0",style:{width:24},children:[!l&&(0,s.jsx)("div",{className:"absolute left-1/2 w-px -translate-x-1/2 bg-[var(--primary)] opacity-30",style:{top:0,height:16}}),(0,s.jsx)("div",{className:"absolute left-1/2 w-px -translate-x-1/2 bg-[var(--primary)] opacity-30",style:{top:16,bottom:0}}),(0,s.jsx)("div",{className:D("absolute left-1/2 z-10 -translate-x-1/2 rounded-full",l&&"border-2 bg-[var(--background)]"),style:{top:11,width:10,height:10,...l?{borderColor:i}:{backgroundColor:i}},title:e.pushed?r("sc.pushed"):r("sc.unpushed")})]}),(0,s.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,s.jsxs)("div",{onClick:()=>S(e.hash),className:D("cursor-pointer rounded-sm py-2",o?"bg-[var(--accent)]":"hover:bg-[var(--accent)]"),children:[(0,s.jsx)("div",{className:"truncate text-xs leading-4 text-[var(--foreground)]",children:e.message}),(0,s.jsxs)("div",{className:"mt-1 flex items-center gap-1.5 text-[10px] text-[var(--muted-foreground)]",children:[(0,s.jsx)("span",{className:"font-mono",children:e.shortHash}),(0,s.jsx)("span",{className:"truncate",children:e.author}),(0,s.jsxs)("span",{className:"shrink-0",children:["\xb7 ",rw(e.date)]})]}),d.length>0&&(0,s.jsx)("div",{className:"mt-1 flex flex-wrap gap-1",children:d.map(e=>(0,s.jsx)(n6,{info:e},"".concat(e.kind,":").concat(e.label)))})]}),o&&(0,s.jsx)("div",{className:"mb-1 ml-1 border-l border-[var(--border)] pl-2",children:void 0===c?(0,s.jsx)("div",{className:"py-1 text-[10px] text-[var(--muted-foreground)]",children:"…"}):0===c.length?(0,s.jsx)("div",{className:"py-1 text-[10px] text-[var(--muted-foreground)]",children:r("sc.noCommitFiles")}):c.map(t=>(0,s.jsx)(n9,{file:t,active:(null==n?void 0:n.commit)===e.hash&&n.path===t.path,onSelect:()=>a({path:t.path,staged:!1,from:t.from,commit:e.hash})},t.path))})]})]},e.hash)}),g&&(0,s.jsx)("div",{ref:N,className:"h-4"})]})}function se(e){return/authentication|could not read username|permission denied|publickey|passphrase|\b401\b|\b403\b/i.test(e)}function st(){var e,t,r;let a=(0,tr.useT)(),n=e9(e=>{var t,r;return null!=(r=null==(t=e.activeProject)?void 0:t.id)?r:null}),o=nY(e=>e.selected),i=nY(e=>e.select),c=nY(e=>e.clear),[d,u]=(0,l.useState)(null),[x,m]=(0,l.useState)(null),[p,h]=(0,l.useState)(!1),[f,g]=(0,l.useState)(""),[b,y]=(0,l.useState)(!1),[w,N]=(0,l.useState)(null),[k,S]=(0,l.useState)(!1),[I,E]=(0,l.useState)(!1),[T,F]=(0,l.useState)(!1),[M,P]=(0,l.useState)("changes"),[L,R]=(0,l.useState)(null),[z,_]=(0,l.useState)(""),O=(0,l.useCallback)(async()=>{if(n)try{let e=await v.F.git.status(n);if(!1===e.isRepo){h(!0),u(null),R(null),m(null);return}u(e),h(!1),m(null);let t=await v.F.git.remotes(n);R(t.remotes)}catch(e){m(e instanceof Error?e.message:String(e))}},[n]);(0,l.useEffect)(()=>{O()},[O]),(0,l.useEffect)(()=>{if(!n)return;let e=null,t=j.on("file:changed",()=>{e&&clearTimeout(e),e=setTimeout(()=>{O()},400)});return()=>{e&&clearTimeout(e),t()}},[n,O]);let B=null!=(e=null==d?void 0:d.files)?e:[],H=B.filter(e=>C(e.index)),K=B.filter(e=>A(e.workingDir));async function G(e){y(!0),N(null);try{await e(),await O()}catch(e){N(e instanceof Error?e.message:String(e))}finally{y(!1)}}let J=(0,l.useCallback)((e,t)=>{i({path:e.path,staged:t,from:e.from})},[i]);function q(e){G(()=>v.F.git.stage(n,e))}function Z(e){G(()=>v.F.git.unstage(n,e))}async function V(){n&&f.trim()&&await G(async()=>{await v.F.git.commit(n,f),g(""),c()})}function Y(){n&&z.trim()&&G(async()=>{await v.F.git.addRemote(n,z.trim()),_("")})}let $=(null!=(t=null==L?void 0:L.length)?t:0)>0;return n?p?(0,s.jsxs)("div",{className:"flex h-full flex-col items-center justify-center gap-3 bg-[var(--background)] p-6 text-center",children:[(0,s.jsx)(nG.A,{className:"h-8 w-8 text-[var(--muted-foreground)]"}),(0,s.jsx)("p",{className:"max-w-[240px] text-xs text-[var(--muted-foreground)]",children:a("sc.initRepoDesc")}),(0,s.jsxs)("button",{onClick:function(){G(()=>v.F.git.init(n))},disabled:b,className:"flex items-center gap-1.5 rounded bg-[var(--primary)] px-3 py-1.5 text-xs font-medium text-[var(--primary-foreground)] hover:opacity-90 disabled:opacity-40",children:[(0,s.jsx)(nG.A,{className:"h-3.5 w-3.5"}),a(b?"sc.initializing":"sc.initRepo")]}),w&&(0,s.jsx)("p",{className:"max-w-[240px] text-[11px] text-red-400",children:w})]}):(0,s.jsxs)("div",{className:"flex h-full flex-col bg-[var(--background)]",children:[(0,s.jsxs)("div",{className:"flex h-10 shrink-0 items-center gap-2 border-b border-[var(--border)] px-3",children:[(0,s.jsx)(nK.A,{className:"h-4 w-4 text-[var(--muted-foreground)]"}),(0,s.jsx)("span",{className:"text-sm font-medium text-[var(--foreground)]",children:a("nav.sourceControl")}),(0,s.jsx)("div",{className:"flex-1"}),(0,s.jsxs)("div",{className:"flex items-center rounded border border-[var(--border)]",children:[(0,s.jsx)("button",{onClick:()=>P("changes"),title:a("sc.viewChanges"),className:D("rounded-l p-1","changes"===M?"bg-[var(--secondary)] text-[var(--foreground)]":"text-[var(--muted-foreground)] hover:text-[var(--foreground)]"),children:(0,s.jsx)(nJ.A,{className:"h-3.5 w-3.5"})}),(0,s.jsx)("button",{onClick:()=>P("graph"),title:a("sc.viewGraph"),className:D("rounded-r p-1","graph"===M?"bg-[var(--secondary)] text-[var(--foreground)]":"text-[var(--muted-foreground)] hover:text-[var(--foreground)]"),children:(0,s.jsx)(nq.A,{className:"h-3.5 w-3.5"})})]}),(0,s.jsx)("button",{onClick:()=>S(!0),title:a("sc.cred.title"),className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,s.jsx)(Q.A,{className:"h-3.5 w-3.5"})}),(0,s.jsx)("button",{onClick:()=>{O()},title:a("sc.refresh"),className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)]",children:(0,s.jsx)(r5.A,{className:D("h-3.5 w-3.5",b&&"animate-spin")})})]}),(0,s.jsxs)("div",{className:"flex shrink-0 items-center gap-2 border-b border-[var(--border)] px-3 py-1.5",children:[(0,s.jsx)(nK.A,{className:"h-3.5 w-3.5 shrink-0 text-[var(--muted-foreground)]"}),(0,s.jsx)("span",{className:"truncate text-xs font-medium text-[var(--foreground)]",children:null!=(r=null==d?void 0:d.branch)?r:"—"}),d&&(d.ahead>0||d.behind>0)&&(0,s.jsxs)("span",{className:"flex items-center gap-1 text-[10px] text-[var(--muted-foreground)]",children:[d.behind>0&&(0,s.jsxs)("span",{className:"flex items-center",children:[(0,s.jsx)(nZ.A,{className:"h-3 w-3"}),d.behind]}),d.ahead>0&&(0,s.jsxs)("span",{className:"flex items-center",children:[(0,s.jsx)(rV.A,{className:"h-3 w-3"}),d.ahead]})]}),(0,s.jsx)("div",{className:"flex-1"}),$&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("button",{onClick:()=>void G(()=>v.F.git.pull(n)),disabled:b,title:a("sc.pull"),className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)] disabled:opacity-40",children:(0,s.jsx)(nZ.A,{className:"h-3.5 w-3.5"})}),(0,s.jsx)("button",{onClick:()=>void G(()=>v.F.git.push(n)),disabled:b,title:a("sc.push"),className:"rounded p-1 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)] disabled:opacity-40",children:(0,s.jsx)(rV.A,{className:"h-3.5 w-3.5"})})]})]}),!$&&"changes"===M&&(0,s.jsxs)("div",{className:"flex shrink-0 flex-col gap-1.5 border-b border-[var(--border)] p-2",children:[(0,s.jsxs)("div",{className:"flex items-center gap-1.5 text-[11px] text-[var(--muted-foreground)]",children:[(0,s.jsx)(r3.A,{className:"h-3.5 w-3.5 shrink-0"}),(0,s.jsx)("span",{children:a("sc.addRemoteDesc")})]}),(0,s.jsx)("input",{type:"text",value:z,onChange:e=>_(e.target.value),onKeyDown:e=>{"Enter"===e.key&&z.trim()&&Y()},placeholder:a("sc.remotePlaceholder"),autoComplete:"off",className:"rounded border border-[var(--border)] bg-[var(--secondary)] px-2 py-1.5 font-mono text-[11px] text-[var(--foreground)] placeholder-[var(--muted-foreground)] outline-none focus:border-[var(--primary)]"}),(0,s.jsxs)("button",{onClick:Y,disabled:b||!z.trim(),className:"flex items-center justify-center gap-1.5 rounded bg-[var(--primary)] px-2 py-1 text-xs font-medium text-[var(--primary-foreground)] hover:opacity-90 disabled:opacity-40",children:[(0,s.jsx)(r3.A,{className:"h-3.5 w-3.5"})," ",a(b?"sc.adding":"sc.addRemote")]})]}),"changes"===M&&(0,s.jsxs)("div",{className:"flex shrink-0 flex-col gap-1.5 border-b border-[var(--border)] p-2",children:[(0,s.jsx)("textarea",{value:f,onChange:e=>g(e.target.value),onKeyDown:e=>{(e.metaKey||e.ctrlKey)&&"Enter"===e.key&&(e.preventDefault(),V())},placeholder:a("sc.commitPlaceholder"),rows:2,className:"resize-none rounded border border-[var(--border)] bg-[var(--secondary)] px-2 py-1.5 text-xs text-[var(--foreground)] placeholder-[var(--muted-foreground)] outline-none focus:border-[var(--primary)]"}),(0,s.jsxs)("button",{onClick:()=>void V(),disabled:b||!f.trim()||0===H.length,className:"flex items-center justify-center gap-1.5 rounded bg-[var(--primary)] px-2 py-1 text-xs font-medium text-[var(--primary-foreground)] hover:opacity-90 disabled:opacity-40",children:[(0,s.jsx)(tD.A,{className:"h-3.5 w-3.5"})," ",a("sc.commit")]})]}),w&&(0,s.jsxs)("div",{className:"shrink-0 border-b border-[var(--border)] bg-red-500/10 px-3 py-2 text-[11px] text-red-400",children:[se(w)?a("sc.authError"):w,se(w)&&(0,s.jsx)("button",{onClick:()=>S(!0),className:"ml-1 underline hover:text-red-300",children:a("sc.openCreds")})]}),(0,s.jsx)("div",{className:"flex-1 overflow-y-auto",children:"graph"===M?(0,s.jsx)(n7,{projectId:n}):x?(0,s.jsx)("div",{className:"px-3 py-4 text-xs text-red-400",children:x}):0===B.length?(0,s.jsx)("div",{className:"px-3 py-4 text-xs text-[var(--muted-foreground)]",children:a("sc.clean")}):(0,s.jsxs)(s.Fragment,{children:[H.length>0&&(0,s.jsxs)("div",{children:[(0,s.jsxs)("div",{className:"group flex items-center gap-1 px-2 py-1",children:[(0,s.jsxs)("button",{onClick:()=>E(e=>!e),className:"flex flex-1 items-center gap-1 text-[11px] font-semibold uppercase tracking-wide text-[var(--muted-foreground)] hover:text-[var(--foreground)]",children:[I?(0,s.jsx)(U.A,{className:"h-3.5 w-3.5"}):(0,s.jsx)(W.A,{className:"h-3.5 w-3.5"}),a("sc.staged")]}),(0,s.jsx)("button",{onClick:()=>Z(H.map(e=>e.path)),title:a("sc.unstageAll"),className:"hidden rounded p-0.5 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)] group-hover:block",children:(0,s.jsx)(nV.A,{className:"h-3.5 w-3.5"})}),(0,s.jsx)("span",{className:"rounded bg-[var(--secondary)] px-1.5 text-[10px] text-[var(--muted-foreground)]",children:H.length})]}),!I&&(0,s.jsx)(n$,{files:H,group:"staged",selectedPath:(null==o?void 0:o.staged)?o.path:null,onSelect:e=>J(e,!0),onAction:Z})]}),K.length>0&&(0,s.jsxs)("div",{children:[(0,s.jsxs)("div",{className:"group flex items-center gap-1 px-2 py-1",children:[(0,s.jsxs)("button",{onClick:()=>F(e=>!e),className:"flex flex-1 items-center gap-1 text-[11px] font-semibold uppercase tracking-wide text-[var(--muted-foreground)] hover:text-[var(--foreground)]",children:[T?(0,s.jsx)(U.A,{className:"h-3.5 w-3.5"}):(0,s.jsx)(W.A,{className:"h-3.5 w-3.5"}),a("sc.changes")]}),(0,s.jsx)("button",{onClick:()=>q(K.map(e=>e.path)),title:a("sc.stageAll"),className:"hidden rounded p-0.5 text-[var(--muted-foreground)] hover:bg-[var(--secondary)] hover:text-[var(--foreground)] group-hover:block",children:(0,s.jsx)(rA.A,{className:"h-3.5 w-3.5"})}),(0,s.jsx)("span",{className:"rounded bg-[var(--secondary)] px-1.5 text-[10px] text-[var(--muted-foreground)]",children:K.length})]}),!T&&(0,s.jsx)(n$,{files:K,group:"changes",selectedPath:o&&!o.staged?o.path:null,onSelect:e=>J(e,!1),onAction:q})]})]})}),k&&(0,s.jsx)(n1,{projectId:n,onClose:()=>S(!1),onSaved:()=>{}})]}):(0,s.jsxs)("div",{className:"flex h-full flex-col items-center justify-center bg-[var(--background)] p-6 text-center",children:[(0,s.jsx)(nK.A,{className:"h-8 w-8 text-[var(--muted-foreground)]"}),(0,s.jsx)("p",{className:"mt-2 text-xs text-[var(--muted-foreground)]",children:a("sc.noWorkspace")})]})}var sr=r(61754);function sa(){let e=(0,tr.useT)(),t=e9(e=>{var t,r;return null!=(r=null==(t=e.activeProject)?void 0:t.id)?r:null}),r=nY(e=>e.selected),[a,n]=(0,l.useState)(null),[o,i]=(0,l.useState)(!1),[c,d]=(0,l.useState)(null);return((0,l.useEffect)(()=>{if(!t||!r)return void n(null);let e=!1;return i(!0),d(null),v.F.git.diff(t,r.path,r.staged,r.from,r.commit).then(t=>{e||n({original:t.original,modified:t.modified,path:r.path})}).catch(t=>{e||d(t instanceof Error?t.message:String(t))}).finally(()=>{e||i(!1)}),()=>{e=!0}},[t,r]),r)?(0,s.jsxs)("div",{className:"flex h-full flex-col bg-[var(--background)]",children:[(0,s.jsxs)("div",{className:"flex h-9 shrink-0 items-center gap-2 border-b border-[var(--border)] px-3",children:[(0,s.jsx)(sr.A,{className:"h-3.5 w-3.5 text-[var(--muted-foreground)]"}),(0,s.jsx)("span",{className:"truncate text-xs text-[var(--foreground)]",children:r.path}),(0,s.jsx)("span",{className:"text-[10px] text-[var(--muted-foreground)]",children:r.commit?"(".concat(r.commit.slice(0,7),")"):e(r.staged?"sc.diffStaged":"sc.diffWorking")})]}),(0,s.jsx)("div",{className:"flex-1 overflow-hidden",children:o?(0,s.jsx)("div",{className:"flex h-full items-center justify-center text-xs text-[var(--muted-foreground)]",children:e("sc.loadingDiff")}):c?(0,s.jsx)("div",{className:"px-4 py-3 text-xs text-red-400",children:c}):a?(0,s.jsx)(eB,{original:a.original,modified:a.modified,path:a.path}):null})]}):(0,s.jsxs)("div",{className:"flex h-full flex-col items-center justify-center bg-[var(--background)] text-center",children:[(0,s.jsx)(sr.A,{className:"h-10 w-10 text-[var(--muted-foreground)]"}),(0,s.jsx)("p",{className:"mt-2 text-sm text-[var(--muted-foreground)]",children:e("sc.selectFile")})]})}var sn=r(98171),ss=r(96739),sl=r(68213),so=r(75457),si=r(20869),sc=r(20273);let sd=["explorer","source-control","sessions","skills","channels","evolution","cron"],su=null;function sx(e){var t;let{connected:r}=e,a=(0,tr.useT)(),n=e9(e=>e.activeProject),c=e9(e=>e.openFolder),d=t6(e=>e.isStreaming),u=t6(e=>e.sessionId),[x,m]=(0,l.useState)(()=>localStorage.getItem("halo_sidebar_tab")||"explorer"),[h,f]=(0,l.useState)(()=>"false"!==localStorage.getItem("halo_sidebar_open")),[g,b]=(0,l.useState)(""),[w,N]=(0,l.useState)(!1),[k,S]=(0,l.useState)(null);(0,l.useEffect)(()=>{let e=window.haloPin;e&&e.get().then(S)},[]);let I=(0,l.useCallback)(()=>{let e=window.haloPin;e&&e.toggle().then(S)},[]),T=!!window.haloNotify||"Notification"in window,[F,M]=(0,l.useState)(()=>"true"===localStorage.getItem("halo_notify_on_finish")),P=(0,l.useCallback)(async()=>{let e=!!window.haloNotify;if(!F&&!e&&"Notification"in window){let e=Notification.permission;if("default"===e&&(e=await Notification.requestPermission()),"granted"!==e)return}M(e=>{let t=!e;try{localStorage.setItem("halo_notify_on_finish",String(t))}catch(e){}return t})},[F]),L=(0,l.useRef)(d),_=(0,l.useRef)(u);(0,l.useEffect)(()=>{let e=null==n?void 0:n.name;document.title=e?"".concat(d?"● ":"","Halo — ").concat(e):"Halo";let t=L.current,r=_.current;if(L.current=d,_.current=u,F&&t&&!d&&r===u&&null!=u&&(!function(){try{let e=window.AudioContext||window.webkitAudioContext;if(!e)return;su||(su=new e);let t=su;t.resume();let r=t.currentTime;[[880,0],[1174.66,.15]].forEach(e=>{let[a,n]=e,s=t.createOscillator(),l=t.createGain();s.type="sine",s.frequency.value=a,l.gain.setValueAtTime(1e-4,r+n),l.gain.exponentialRampToValueAtTime(.2,r+n+.02),l.gain.exponentialRampToValueAtTime(1e-4,r+n+.35),s.connect(l).connect(t.destination),s.start(r+n),s.stop(r+n+.4)})}catch(e){}}(),!document.hasFocus())){let t=e?"Halo — ".concat(e):"Halo",r=a("status.notifyBody"),n=window.haloNotify;if(n)n.notify({title:t,body:r});else if("Notification"in window&&"granted"===Notification.permission){let e=new Notification(t,{body:r});e.onclick=()=>{window.focus(),e.close()}}}},[d,u,null==n?void 0:n.name,a,F]),(0,l.useEffect)(()=>{let e=new URLSearchParams(window.location.search).get("folder"),t=async(e,t)=>{try{let a=await v.F.fs.resolveWorkspace(e);c(a.path,a.id),b(a.path),y(a.path);try{localStorage.setItem("halo_last_folder",a.path)}catch(e){}var r=a.path;let n=rX().filter(e=>e!==r);if(n.unshift(r),r0(n.slice(0,8)),t||a.path!==e){let e=new URL(window.location.href);e.searchParams.set("folder",a.path),window.history.replaceState({},"",e.toString())}}catch(e){return console.error("[Workspace] Failed to resolve workspace:",e),!1}return!0};if(e)t(e,!1);else{let e=(()=>{try{return localStorage.getItem("halo_last_folder")}catch(e){return null}})(),r=()=>v.F.fs.home().then(e=>{let{home:r}=e;return t(r,!0)}).catch(e=>{console.error("[Workspace] Failed to resolve home dir:",e)});e?t(e,!0).then(e=>{e||r()}):r()}},[]),(0,l.useEffect)(()=>{function e(e){e.preventDefault()}return window.addEventListener("beforeunload",e),()=>window.removeEventListener("beforeunload",e)},[]);let O=(0,l.useCallback)(()=>{let e=p.getState(),t=e.activeTab;if(!t)return!1;let r=e.tabs.find(e=>e.path===t);return(async()=>{(null==r||!r.modified||await R('"'.concat(r.path.split("/").pop(),'" has unsaved changes. Close anyway?')))&&e.closeTab(t)})(),!0},[]);function W(e){p.getState().maximized&&p.getState().setMaximized(!1),x===e&&h?f(!1):(m(e),f(!0))}async function U(e){let t=e.trim();if(!t)return;try{let e=await v.F.fs.exists(t);if(!e.exists||!e.isDirectory)return void window.alert("Workspace not found: ".concat(t))}catch(e){window.alert(e instanceof Error?e.message:"Failed to validate path");return}try{localStorage.setItem("halo_last_folder",t)}catch(e){}let r=new URL(window.location.href);r.searchParams.set("folder",t),window.location.href=r.toString()}(0,l.useEffect)(()=>{function e(e){if((e.metaKey||e.ctrlKey)&&"p"===e.key&&(e.preventDefault(),N(e=>!e)),(e.metaKey||e.ctrlKey)&&"`"===e.key){e.preventDefault();let t=p.getState();t.setBottomTab("terminal"===t.bottomTab?"chat":"terminal")}!e.altKey||"KeyW"!==e.code||e.metaKey||e.ctrlKey||(e.preventDefault(),O())}return window.addEventListener("keydown",e,!0),()=>window.removeEventListener("keydown",e,!0)},[O]),(0,l.useEffect)(()=>{let e=window.haloCloseShortcut;e&&e.onTrigger(()=>{O()||e.closeWindow()})},[O]),(0,l.useEffect)(()=>{function e(e){if("Escape"!==e.key||!p.getState().maximized)return;let t=document.activeElement;if(t){let e=t.tagName;if("INPUT"===e||"TEXTAREA"===e||t.isContentEditable||t.closest(".monaco-editor"))return}w||p.getState().setMaximized(!1)}return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[w]),(0,l.useEffect)(()=>{let e=e=>{let t=e.detail;if(!(null==t?void 0:t.tab))return;let{bottomFloating:r}=p.getState();r&&"explorer"===t.tab||(m(t.tab),f(!0))};return window.addEventListener("halo:navigate",e),()=>window.removeEventListener("halo:navigate",e)},[]),(0,l.useEffect)(()=>{let e=e=>{var t;let r=null==(t=e.detail)?void 0:t.path;r&&U(r)};return window.addEventListener("halo:open-workspace",e),()=>window.removeEventListener("halo:open-workspace",e)},[]),(0,l.useEffect)(()=>{localStorage.setItem("halo_sidebar_tab",x),localStorage.setItem("halo_sidebar_open",String(h))},[x,h]);let B=(0,l.useCallback)(async e=>{let t=null==n?void 0:n.id;if(t){if(p.getState().tabs.find(t=>t.path===e))return void p.getState().setActiveTab(e);try{let r=await v.F.files.read(e,t),a=z(e);p.getState().openFile(e,r.content,a)}catch(e){console.error("[QuickOpen] Failed to read file:",e)}}},[n]),H=[{id:"explorer",icon:r1.A,label:a("nav.explorer")},{id:"source-control",icon:nK.A,label:a("nav.sourceControl")},{id:"sessions",icon:rC.A,label:a("nav.sessions")},{id:"skills",icon:al.A,label:"Skills"},{id:"management",icon:rS.A,label:"Agents"},{id:"channels",icon:a0.A,label:a("nav.channels")},{id:"evolution",icon:t0.A,label:"Evolution"},{id:"cron",icon:nP.A,label:"Cron"},{id:"settings",icon:az.A,label:a("nav.settings"),position:"bottom"}],K=null!=(t=null==n?void 0:n.id)?t:null;(0,l.useEffect)(()=>{if(!K)return;let{setForProject:e,clearProject:t,setRepoStatus:r,clearRepoStatus:a}=E.getState(),n=!1;async function s(){try{let[a,s]=await Promise.all([v.F.git.status(K),v.F.git.ignored(K)]);if(!1===a.isRepo){n||(t(K),r(K,!1));return}n||(e(K,function(e,t){let r=new Map,a=new Map;for(let t of e){var n,s;let e=(n=t.index,A(s=t.workingDir)?"?"===s?"?":s:C(n)?n:"");if(!e)continue;r.set(t.path,e);let l=t.path.split("/");for(let t=0;t<l.length-1;t++){let r=l.slice(0,t+1).join("/"),n=a.get(r);void 0===n?a.set(r,e):n!==e&&"*"!==n&&a.set(r,"*")}}return{files:r,dirs:a,ignored:new Set(t)}}(a.files,s.ignored)),r(K,!0))}catch(e){n||(t(K),r(K,!1))}}s();let l=null,o=j.on("file:changed",()=>{l&&clearTimeout(l),l=setTimeout(()=>{s()},400)});return()=>{n=!0,l&&clearTimeout(l),o(),t(K),a(K)}},[K]);let G=E(e=>{var t;return null!=(t=K?e.repoStatus[K]:void 0)?t:"unknown"}),J=H.filter(e=>"bottom"!==e.position).filter(e=>"source-control"!==e.id||!1!==G),q=H.filter(e=>"bottom"===e.position),Z=p(e=>e.maximized),V=p(e=>e.bottomFloating),Y=p(e=>e.bottomMaximized),$=h&&!Z,Q=sd.includes(x)&&h&&"explorer"!==x,X="explorer"===x;(0,l.useEffect)(()=>{!1===G&&"source-control"===x&&m("explorer")},[G,x]);let[ee]=(0,l.useState)(()=>{if("undefined"==typeof document)return null;let e=document.createElement("div");return e.className="h-full",e}),et=(0,l.useRef)(null),[er,ea]=(0,l.useState)(null),[en,es]=(0,l.useState)(null),[el,eo]=(0,l.useState)(null),ei=V?el:Y?en:er;return(0,l.useLayoutEffect)(()=>{ee&&ei&&ee.parentElement!==ei&&ei.appendChild(ee)},[ee,ei]),(0,s.jsxs)("div",{className:"flex h-full",children:[(0,s.jsxs)("div",{className:D("flex w-12 shrink-0 flex-col items-center border-r border-[var(--border)] bg-[var(--card)] py-2",Z&&"hidden"),children:[J.map(e=>{let t=e.icon,r=x===e.id;return(0,s.jsxs)("button",{onClick:()=>W(e.id),title:e.label,className:D("relative flex h-12 w-full items-center justify-center transition-colors hover:text-[var(--foreground)]",r?"text-[var(--foreground)]":"text-[var(--muted-foreground)]"),children:[r&&(0,s.jsx)("div",{className:"absolute left-0 top-1/2 h-6 w-0.5 -translate-y-1/2 rounded-r bg-[var(--primary)]"}),(0,s.jsx)(t,{className:"h-5 w-5"})]},e.id)}),(0,s.jsx)("div",{className:"flex-1"}),q.map(e=>{let t=e.icon,r=x===e.id;return(0,s.jsxs)("button",{onClick:()=>W(e.id),title:e.label,className:D("relative flex h-12 w-full items-center justify-center transition-colors hover:text-[var(--foreground)]",r?"text-[var(--foreground)]":"text-[var(--muted-foreground)]"),children:[r&&(0,s.jsx)("div",{className:"absolute left-0 top-1/2 h-6 w-0.5 -translate-y-1/2 rounded-r bg-[var(--primary)]"}),(0,s.jsx)(t,{className:"h-5 w-5"})]},e.id)}),null!==k&&(0,s.jsx)("button",{onClick:I,title:k?a("workspace.unpin"):a("workspace.pin"),className:D("flex h-12 w-full items-center justify-center transition-colors hover:text-[var(--foreground)]",k?"text-[var(--primary)]":"text-[var(--muted-foreground)]"),children:k?(0,s.jsx)(sn.A,{className:"h-5 w-5"}):(0,s.jsx)(ss.A,{className:"h-5 w-5"})}),T&&(0,s.jsx)("button",{onClick:P,title:F?a("workspace.notifyOn"):a("workspace.notifyOff"),className:D("flex h-12 w-full items-center justify-center transition-colors hover:text-[var(--foreground)]",F?"text-[var(--primary)]":"text-[var(--muted-foreground)]"),children:F?(0,s.jsx)(sl.A,{className:"h-5 w-5"}):(0,s.jsx)(so.A,{className:"h-5 w-5"})}),(0,s.jsx)("div",{className:"pb-2",title:r?"Connected":"Disconnected",children:r?(0,s.jsx)(si.A,{className:"h-4 w-4 text-emerald-400"}):(0,s.jsx)(sc.A,{className:"h-4 w-4 text-[var(--destructive)]"})})]}),(0,s.jsx)("div",{className:D("flex min-w-0 flex-1",!X&&"hidden",Z&&"fixed inset-0 z-40 bg-[var(--background)]"),children:(0,s.jsx)(sm,{showSidebar:$,sidebar:(0,s.jsx)(r2,{projectId:K,pathInput:g,onPathInputChange:b,onOpenFolder:function(){U(g)},onOpenPath:U,activeProject:n}),main:(0,s.jsx)(sp,{projectId:K,showBottom:!V&&!Z,bottomSlotRef:ea})})}),!X&&!Z&&(Q?(0,s.jsxs)(i.YZ,{direction:"horizontal",autoSaveId:"halo-h-sidebar",className:"flex-1",children:[(0,s.jsx)(i.Zk,{defaultSize:22,minSize:15,maxSize:40,children:(0,s.jsxs)("div",{className:"h-full overflow-hidden",children:["source-control"===x&&(0,s.jsx)(st,{}),"sessions"===x&&(0,s.jsx)(aa,{}),"skills"===x&&(0,s.jsx)(ap,{}),"channels"===x&&(0,s.jsx)(nh,{}),"evolution"===x&&(0,s.jsx)(nA,{}),"cron"===x&&(0,s.jsx)(nH,{})]})}),(0,s.jsx)(i.TW,{className:"w-px bg-[var(--border)] hover:w-1 hover:bg-[var(--primary)] transition-colors"}),(0,s.jsx)(i.Zk,{defaultSize:78,minSize:40,children:(0,s.jsx)(sh,{activeTab:x})})]}):(0,s.jsx)("div",{className:"flex-1 min-w-0 overflow-hidden",children:(0,s.jsx)(sh,{activeTab:x})})),w&&(0,s.jsx)(rZ,{onSelect:B,onClose:()=>N(!1)}),V&&(0,s.jsx)(rG,{slotRef:eo,dragHandleRef:et}),Y&&!V&&(0,s.jsx)("div",{ref:es,className:"fixed inset-0 z-50 bg-[var(--background)]"}),ee&&(0,o.createPortal)((0,s.jsx)(rH,{floating:V,dragHandleRef:et}),ee)]})}function sm(e){let{showSidebar:t,sidebar:r,main:a}=e,n=(0,l.useRef)(null),o=(0,l.useRef)([22,78]);return(0,l.useEffect)(()=>{let e=n.current;if(e)if(t)e.setLayout(o.current);else{let t=e.getLayout();t[0]>0&&(o.current=t),e.setLayout([0,100])}},[t]),(0,s.jsxs)(i.YZ,{ref:n,direction:"horizontal",autoSaveId:"halo-h-sidebar",className:"flex-1",children:[(0,s.jsx)(i.Zk,{defaultSize:22,minSize:0,maxSize:40,collapsible:!0,children:(0,s.jsx)("div",{className:D("h-full overflow-hidden",!t&&"hidden"),children:r})}),(0,s.jsx)(i.TW,{className:D("w-px bg-[var(--border)] hover:w-1 hover:bg-[var(--primary)] transition-colors",!t&&"pointer-events-none opacity-0")}),(0,s.jsx)(i.Zk,{defaultSize:78,minSize:40,children:a})]})}function sp(e){let{projectId:t,showBottom:r,bottomSlotRef:a}=e,n=(0,l.useRef)(null),o=(0,l.useRef)([65,35]);return(0,l.useEffect)(()=>{let e=n.current;if(e)if(r)e.setLayout(o.current);else{let t=e.getLayout();t[1]>0&&(o.current=t),e.setLayout([100,0])}},[r]),(0,s.jsxs)(i.YZ,{ref:n,direction:"vertical",autoSaveId:"halo-v-editor",className:"h-full",children:[(0,s.jsx)(i.Zk,{defaultSize:65,minSize:20,children:(0,s.jsx)(tl,{projectId:t,mode:"editor-only"})}),(0,s.jsx)(i.TW,{className:D("h-px bg-[var(--border)] hover:h-1 hover:bg-[var(--primary)] transition-colors",!r&&"pointer-events-none opacity-0")}),(0,s.jsx)(i.Zk,{defaultSize:35,minSize:0,collapsible:!0,children:(0,s.jsx)("div",{ref:a,className:D("h-full",!r&&"hidden")})})]})}function sh(e){let{activeTab:t}=e;return"source-control"===t?(0,s.jsx)(sa,{}):"sessions"===t?(0,s.jsx)(aR,{}):"management"===t?(0,s.jsx)(aF,{}):"skills"===t?(0,s.jsx)(aM,{}):"channels"===t?(0,s.jsx)(nf,{}):"evolution"===t?(0,s.jsx)(nb,{}):"cron"===t?(0,s.jsx)(nz,{}):"settings"===t?(0,s.jsx)(aU,{}):null}let sf=/<<<CAPTURE>>>/,sg=/<<<SHOW:([\s\S]*?)>>>/g,sv=new Set,sb=new Set;async function sj(e){let t=t6.getState(),r=window,a=t.captureSource;if(!a)return;let n="camera"===a.kind;if(!(n?r.haloCamera:r.haloCapture))return;let s=[...t.messages].reverse().find(e=>"assistant"===e.role&&!e.taskId);if(!s||sv.has(s.id)||!sf.test(s.content))return;sv.add(s.id);let l=e9.getState().activeProject,o=t.sessionId;if(!l||!o)return;let i="image/jpeg",c=null;try{c=n?await r.haloCamera.snap(a.id||void 0):await r.haloCapture.grab(a.id)}catch(e){c=null}let d=n?"[\uD83D\uDCF7 ".concat(a.name," — 拍照失败:摄像头可能被其他应用占用或权限被关闭]"):"[\uD83D\uDCF7 ".concat(a.name," — 截图失败:该窗口在后台太久被系统回收了画面,切到它再让我截一次]"),u=n?"[Could not take a photo from the camera — it may be in use by another app, or camera permission was revoked. Ask the user to check, then request the capture again.]":'[Could not capture "'.concat(a.name,'" — it was likely occluded/minimized long enough that macOS purged its rendered frame (came back blank/black). Ask the user to briefly bring that window to the foreground, then request the capture again.]');t.addMessage({id:M(),role:"user",content:c?"[\uD83D\uDCF7 ".concat(a.name,"]"):d,timestamp:Date.now(),...c?{localImages:["data:".concat(i,";base64,").concat(c)]}:{}}),t.addMessage({id:M(),role:"assistant",content:"",timestamp:Date.now(),streaming:!0});let x=t.selectedAgentId;e.send({type:"chat",sessionId:o,projectId:l.id,message:c?n?"[Photo from the camera]":'[Screenshot of "'.concat(a.name,'"]'):u,..."default"!==x?{agentId:x}:{},...c?{images:[{data:c,mimeType:i}]}:{}})}let sy=(0,c.v)(e=>({activePlan:null,agents:[],agentConfigs:[],setActivePlan(t){e({activePlan:t})},updateTaskStatus(t,r){e(e=>{if(!e.activePlan)return e;let a=e.activePlan.tasks.map(e=>e.id===t?{...e,status:r}:e);return{activePlan:{...e.activePlan,tasks:a}}})},setAgents(t){e({agents:t})},updateAgentState(t,r){e(e=>({agents:e.agents.map(e=>e.agentId===t?{...e,state:r}:e)}))},setAgentConfigs(t){e({agentConfigs:t})},clearPlan(){e({activePlan:null})}}));function sw(e){let{onSuccess:t}=e,[r,a]=(0,l.useState)(""),[n,o]=(0,l.useState)(""),[i,c]=(0,l.useState)(!1),d=(0,l.useCallback)(async e=>{if(e.preventDefault(),r.trim()){c(!0),o("");try{(await fetch("/api/auth/login",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({password:r.trim()}),credentials:"include"})).ok?t():(o("Incorrect password"),a(""))}catch(e){o("Connection failed")}finally{c(!1)}}},[r,t]);return(0,s.jsx)("div",{className:"flex h-screen w-screen items-center justify-center bg-[var(--background)]",children:(0,s.jsxs)("div",{className:"w-full max-w-sm px-6",children:[(0,s.jsxs)("div",{className:"text-center",children:[(0,s.jsx)("div",{className:"mx-auto mb-4 flex h-14 w-14 items-center justify-center rounded-xl bg-[var(--secondary)]",children:(0,s.jsx)(nX.A,{className:"h-7 w-7 text-[var(--foreground)]"})}),(0,s.jsx)("h1",{className:"text-xl font-semibold text-[var(--foreground)]",children:"Halo"}),(0,s.jsx)("p",{className:"mt-1 text-sm text-[var(--muted-foreground)]",children:"Enter password to access workspace"})]}),(0,s.jsxs)("form",{onSubmit:d,className:"mt-8",children:[(0,s.jsx)("input",{type:"password",value:r,onChange:e=>a(e.target.value),placeholder:"Password",autoFocus:!0,className:"w-full rounded-md border border-[var(--border)] bg-[var(--secondary)] px-3 py-2.5 text-sm text-[var(--foreground)] placeholder-[var(--muted-foreground)] outline-none focus:border-[var(--primary)] focus:ring-1 focus:ring-[var(--primary)]"}),n&&(0,s.jsx)("p",{className:"mt-2 text-xs text-red-400",children:n}),(0,s.jsx)("button",{type:"submit",disabled:i||!r.trim(),className:"mt-4 w-full rounded-md bg-[var(--primary)] px-3 py-2.5 text-sm font-medium text-[var(--primary-foreground)] transition-colors hover:opacity-90 disabled:opacity-50",children:i?"Verifying...":"Login"})]})]})})}function sN(){let{connected:e}=function(){let[e,t]=(0,l.useState)(!1),r=(0,l.useRef)(!1),a=e9(e=>{var t;return null==(t=e.activeProject)?void 0:t.id}),n=(0,l.useRef)(void 0);return(0,l.useEffect)(()=>{var t;if(!e||!a)return;if(void 0===n.current){n.current=a;return}if(n.current===a)return;n.current=a;let r=null!=(t=t6.getState().sessionId)?t:"";j.send({type:"subscribe",sessionId:r,projectId:a})},[e,a]),(0,l.useEffect)(()=>{if(r.current)return;r.current=!0,j.connect();let e=[j.on("_connected",()=>{t(!0);let e=t6.getState().sessionId,r=e9.getState().activeProject;(null==r?void 0:r.id)&&j.send({type:"subscribe",sessionId:null!=e?e:"",projectId:r.id})}),j.on("_disconnected",()=>{t(!1)}),function(e){let t=[];t.push(e.on("chat:thinking",e=>{t6.getState().appendThinking(e.text,e.agentName,e.taskId,e.turnId)})),t.push(e.on("chat:stream",e=>{t6.getState().updateLastAssistant(e.text,e.agentName,e.taskId,e.turnId)})),t.push(e.on("chat:complete",t=>{let r=t6.getState();t.text&&r.updateLastAssistant(t.text),r.completeAgentStreaming(),sj(e),function(){let e=[...t6.getState().messages].reverse().find(e=>"assistant"===e.role&&!e.taskId);if(!e)return;let t=0;for(let r of e.content.matchAll(sg)){let a="".concat(e.id,"#").concat(t++);if(sb.has(a))continue;sb.add(a);let n=r[1].trim();n&&eW(n)}}()})),t.push(e.on("chat:stopped",()=>{t6.getState().completeAgentStreaming()})),t.push(e.on("error",e=>{let t=t6.getState(),r=e.error?"Error: ".concat(e.error):"An unknown error occurred.";t.addMessage({id:M(),role:"system",content:r,timestamp:Date.now(),agentName:e.agentName}),e.taskId||t.completeAgentStreaming(e.agentName)})),t.push(e.on("chat:followup",e=>{let t=t6.getState();t.completeAgentStreaming(e.agentName),t.addMessage({id:M(),role:"assistant",content:"",timestamp:Date.now(),streaming:!0,agentName:e.agentName})})),t.push(e.on("chat:user",e=>{t6.getState().addMessage({id:M(),role:"user",content:e.text,timestamp:Date.now()})})),t.push(e.on("chat:usage",e=>{let t=t6.getState();t.setTokenUsage(e.contextTokens,e.outputTokens),e.usage&&t.addMessage({type:"usage",role:"system",content:"[Usage] in=".concat(e.usage.inputTokens," out=").concat(e.usage.outputTokens," cache=").concat(e.usage.cacheReadInputTokens),usage:e.usage,turnId:e.turnId,modelId:e.modelId})})),t.push(e.on("session:cleared",()=>{let e=t6.getState();(e.messages.length>0||e.sessionId)&&e.clear()})),t.push(e.on("session:switched",e=>{if(!e.sessionId)return;let t=e9.getState().activeProject;if(t)try{localStorage.setItem("halo_session_".concat(t.id),e.sessionId)}catch(e){}let r=t6.getState();r.clear(),r.setSessionId(e.sessionId)})),t.push(e.on("session:compacted",e=>{var t,r;let a=null!=(t=e.message)?t:"Context compacted",s=t6.getState();s.setCompacting(!1),n(),s.setTokenUsage(null!=(r=e.contextTokens)?r:0,s.outputTokens),s.addMessage({id:M(),role:"system",content:a,timestamp:Date.now()})}));let r=null;function a(){r&&clearTimeout(r),r=setTimeout(()=>{t6.getState().setCompacting(!1),r=null},6e4)}function n(){r&&(clearTimeout(r),r=null)}for(let r of(t.push(e.on("chat:system",e=>{let t=e.text;if(!e.taskId){let e=t.match(/^Compacting context \((\d+)K tokens\)…$/);if(e&&(t6.getState().setCompacting(!0),a(),"0"===e[1])){let e=t6.getState().contextTokens;e>0&&(t="Compacting context (~".concat(Math.round(e/1e3),"K tokens)…"))}}t6.getState().addMessage({id:M(),role:"system",content:t,timestamp:Date.now(),taskId:e.taskId,agentName:e.agentName})})),t.push(e.on("chat:queued",e=>{var t;t6.getState().addMessage({id:M(),role:"system",content:null!=(t=e.message)?t:"Message queued.",timestamp:Date.now()})})),["compact:progress","compact:started","compact:summarizing"]))t.push(e.on(r,()=>{t6.getState().setCompacting(!0),a()}));return t.push(e.on("compact:done",()=>{t6.getState().setCompacting(!1),n()})),()=>t.forEach(e=>e())}(j),function(e){let t=[];return t.push(e.on("agent:start",e=>{t6.getState().addMessage({id:M(),role:"assistant",content:"",timestamp:Date.now(),streaming:!0,agentName:e.agentName,taskId:e.taskId})})),t.push(e.on("agent:done",e=>{t6.getState().completeAgentStreaming(e.agentName,e.taskId)})),t.push(e.on("agent:context",e=>{var t;t6.getState().addMessage({id:M(),role:"system",content:"[System Prompt: ".concat(null!=(t=e.agentName)?t:"Agent","]"),timestamp:Date.now(),agentName:e.agentName,taskId:e.taskId,systemPrompt:e.systemPrompt})})),t.push(e.on("agent:tool_call",e=>{var t,r;let a=null!=(t=e.agentName)?t:"default",n="string"==typeof e.input?e.input:JSON.stringify(null!=(r=e.input)?r:{});t6.getState().addToolCallToLastAssistant({name:e.tool,input:n},a,e.taskId,e.turnId)})),t.push(e.on("agent:tool_result",e=>{var t,r;let a=null!=(t=e.agentName)?t:"default",n="string"==typeof e.result?e.result:JSON.stringify(null!=(r=e.result)?r:"");t6.getState().updateLastToolCallResult(n,a,e.taskId)})),t.push(e.on("agent:configs",e=>{sy.getState().setAgentConfigs(e.agents)})),()=>t.forEach(e=>e())}(j),function(e){let t=[];return t.push(e.on("task:plan",e=>{t6.getState().addMessage({id:M(),role:"assistant",content:"Task plan created: ".concat(e.plan.description),timestamp:Date.now(),plan:e.plan}),sy.getState().setActivePlan(e.plan)})),t.push(e.on("task:status",e=>{sy.getState().updateTaskStatus(e.taskId,e.status)})),t.push(e.on("plan:complete",e=>{t6.getState().addMessage({id:M(),role:"system",content:"Plan completed: ".concat(e.summary),timestamp:Date.now()}),t6.getState().completeStreaming()})),()=>t.forEach(e=>e())}(j),function(e){let t=[];return t.push(e.on("file:changed",e=>{let t=p.getState();"add"===e.action||"addDir"===e.action?t.insertFileNode(e.path,"addDir"===e.action?"directory":"file"):("unlink"===e.action||"unlinkDir"===e.action)&&t.removeFileNode(e.path)})),()=>t.forEach(e=>e())}(j),function(e){let t=[];return t.push(e.on("state:snapshot",e=>{let{snapshot:t}=e;t.sessionId&&t6.getState().setSessionId(t.sessionId),t.agentId&&t6.getState().setSelectedAgentId(t.agentId),t6.getState().messages.some(e=>e.streaming)?console.debug("[state-handlers] skipping snapshot replace — streaming in flight"):t.recentMessages&&t.recentMessages.length>0?t6.getState().setMessages(t.recentMessages):t.messages&&t.messages.length>0&&t6.getState().setMessages(t.messages),t.activePlan&&sy.getState().setActivePlan(t.activePlan),t.agents&&sy.getState().setAgentConfigs(t.agents),"number"==typeof t.maxContextTokens&&t.maxContextTokens>0&&t6.getState().setMaxContextTokens(t.maxContextTokens)})),t.push(e.on("session:changed",()=>rj())),()=>t.forEach(e=>e())}(j)],a=()=>j.reconnectIfStale(0);return window.addEventListener("online",a),()=>{e.forEach(e=>e()),window.removeEventListener("online",a),j.disconnect(),r.current=!1}},[]),{connected:e,send:(0,l.useCallback)(e=>{j.send(e)},[])}}(),[t,r]=(0,l.useState)("checking");(0,l.useEffect)(()=>{fetch("/api/auth/check",{credentials:"include"}).then(e=>{r(e.ok?"authenticated":"login")}).catch(()=>{r("login")})},[]),(0,l.useEffect)(()=>j.on("_auth_expired",()=>{r("login")}),[]);let a=(0,l.useCallback)(()=>{r("authenticated"),window.location.reload()},[]);return"checking"===t?(0,s.jsx)("div",{className:"flex h-screen w-screen items-center justify-center bg-[var(--background)]",children:(0,s.jsx)("div",{className:"text-sm text-[var(--muted-foreground)]",children:"Loading..."})}):"login"===t?(0,s.jsx)(sw,{onSuccess:a}):(0,s.jsx)("div",{className:"h-screen w-screen overflow-hidden bg-[var(--background)]",children:(0,s.jsx)(sx,{connected:e})})}},46601:(e,t,r)=>{Promise.resolve().then(r.bind(r,11704))},89759:(e,t,r)=>{"use strict";r.d(t,{SQ:()=>o,Tv:()=>s,_H:()=>l,dj:()=>n});var a=r(43853);let n=["png","jpg","jpeg","gif","webp","svg","bmp","ico","avif"],s=["mp4","webm","ogg","mov","avi","mkv"],l=["mp3","wav","flac","aac","m4a","wma"],o={id:"media",extensions:[...n,...s,...l],Component:(0,a.lazy)(()=>r.e(200).then(r.bind(r,21200)).then(e=>({default:e.MediaPreview})))}}},e=>{e.O(0,[372,560,307,212,489,635,358],()=>e(e.s=46601)),_N_E=e.O()}]);